@gp-grid/core 0.8.3 → 0.9.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 (3) hide show
  1. package/dist/index.d.ts +1187 -887
  2. package/dist/index.js +136 -8
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -159,6 +159,59 @@ interface HighlightingOptions<TData = Record<string, unknown>> {
159
159
  computeCellClasses?: (context: HighlightContext<TData>) => string[];
160
160
  }
161
161
  //#endregion
162
+ //#region src/types/renderers.d.ts
163
+ /** Cell renderer params */
164
+ interface CellRendererParams<TData extends Row = Row> {
165
+ /** Cell value */
166
+ value: CellValue;
167
+ /** Row data */
168
+ rowData: TData;
169
+ /** Column definition */
170
+ column: ColumnDefinition;
171
+ /** Row index */
172
+ rowIndex: number;
173
+ /** Column index */
174
+ colIndex: number;
175
+ /** Is active cell */
176
+ isActive: boolean;
177
+ /** Is selected cell */
178
+ isSelected: boolean;
179
+ /** Is editing cell */
180
+ isEditing: boolean;
181
+ }
182
+ /** Edit renderer params */
183
+ interface EditRendererParams<TData extends Row = Row> extends CellRendererParams<TData> {
184
+ /** Initial value */
185
+ initialValue: CellValue;
186
+ /** On value change */
187
+ onValueChange: (newValue: CellValue) => void;
188
+ /** On commit */
189
+ onCommit: () => void;
190
+ /** On cancel */
191
+ onCancel: () => void;
192
+ }
193
+ /** Header renderer params */
194
+ interface HeaderRendererParams {
195
+ /** Column definition */
196
+ column: ColumnDefinition;
197
+ /** Column index */
198
+ colIndex: number;
199
+ /** Sort direction */
200
+ sortDirection?: SortDirection;
201
+ /** Sort index */
202
+ sortIndex?: number;
203
+ /** Whether column is sortable */
204
+ sortable: boolean;
205
+ /** Whether column is filterable */
206
+ filterable: boolean;
207
+ /** Whether column has an active filter */
208
+ hasFilter: boolean;
209
+ /** On sort */
210
+ onSort: (direction: SortDirection | null, addToExisting: boolean) => void;
211
+ /** On filter click */
212
+ onFilterClick: () => void;
213
+ }
214
+ //#endregion
162
215
  //#region src/types/columns.d.ts
163
216
  /** Column definition */
164
217
  interface ColumnDefinition {
@@ -174,10 +227,20 @@ interface ColumnDefinition {
174
227
  filterable?: boolean;
175
228
  /** Whether column is hidden. Hidden columns are not rendered but still exist in the definition. Default: false */
176
229
  hidden?: boolean;
230
+ /** Whether column is resizable by dragging the header edge. Default: true */
231
+ resizable?: boolean;
232
+ /** Minimum width in pixels when resizing. Default: 50 */
233
+ minWidth?: number;
234
+ /** Maximum width in pixels when resizing. Default: undefined (no limit) */
235
+ maxWidth?: number;
236
+ /** Whether column can be moved/reordered by dragging the header. Default: true */
237
+ movable?: boolean;
238
+ /** Whether this column acts as a drag handle for row dragging. Default: false */
239
+ rowDrag?: boolean;
177
240
  /** Renderer key for adapter lookup, or inline renderer function */
178
- cellRenderer?: string;
179
- editRenderer?: string;
180
- headerRenderer?: string;
241
+ cellRenderer?: string | ((params: CellRendererParams) => unknown);
242
+ editRenderer?: string | ((params: EditRendererParams) => unknown);
243
+ headerRenderer?: string | ((params: HeaderRendererParams) => unknown);
181
244
  /**
182
245
  * Per-column override for column-level highlighting.
183
246
  * If defined, overrides grid-level computeColumnClasses for this column.
@@ -362,10 +425,6 @@ interface UpdateHeaderInstruction {
362
425
  column: ColumnDefinition;
363
426
  sortDirection?: SortDirection;
364
427
  sortIndex?: number;
365
- /** Whether column is sortable */
366
- sortable: boolean;
367
- /** Whether column is filterable */
368
- filterable: boolean;
369
428
  /** Whether column has an active filter */
370
429
  hasFilter: boolean;
371
430
  }
@@ -450,65 +509,83 @@ interface TransactionProcessedInstruction {
450
509
  removed: number;
451
510
  updated: number;
452
511
  }
453
- /** Union type of all instructions */
454
- type GridInstruction = /** Slot lifecycle */CreateSlotInstruction | DestroySlotInstruction | AssignSlotInstruction | MoveSlotInstruction /** Selection */ | SetActiveCellInstruction | SetSelectionRangeInstruction | UpdateVisibleRangeInstruction /** Highlighting */ | SetHoverPositionInstruction /** Editing */ | StartEditInstruction | StopEditInstruction | CommitEditInstruction /** Layout */ | SetContentSizeInstruction | UpdateHeaderInstruction /** Filter popup */ | OpenFilterPopupInstruction | CloseFilterPopupInstruction /** Fill handle */ | StartFillInstruction | UpdateFillInstruction | CommitFillInstruction | CancelFillInstruction /** Data */ | DataLoadingInstruction | DataLoadedInstruction | DataErrorInstruction /** Transactions */ | RowsAddedInstruction | RowsRemovedInstruction | RowsUpdatedInstruction | TransactionProcessedInstruction;
455
- /** Instruction listener: Single instruction Listener that receives a single instruction, used by frameworks to update their state */
456
- type InstructionListener = (instruction: GridInstruction) => void;
457
- /** Batch instruction listener: Batch instruction Listener that receives an array of instructions, used by frameworks to update their state */
458
- type BatchInstructionListener = (instructions: GridInstruction[]) => void;
459
- //#endregion
460
- //#region src/types/renderers.d.ts
461
- /** Cell renderer params */
462
- interface CellRendererParams<TData extends Row = Row> {
463
- /** Cell value */
464
- value: CellValue;
465
- /** Row data */
466
- rowData: TData;
467
- /** Column definition */
468
- column: ColumnDefinition;
469
- /** Row index */
470
- rowIndex: number;
471
- /** Column index */
512
+ /** Columns changed (after resize, reorder, etc.) */
513
+ interface ColumnsChangedInstruction {
514
+ type: "COLUMNS_CHANGED";
515
+ columns: ColumnDefinition[];
516
+ }
517
+ /** Column resize started */
518
+ interface StartColumnResizeInstruction {
519
+ type: "START_COLUMN_RESIZE";
472
520
  colIndex: number;
473
- /** Is active cell */
474
- isActive: boolean;
475
- /** Is selected cell */
476
- isSelected: boolean;
477
- /** Is editing cell */
478
- isEditing: boolean;
521
+ initialWidth: number;
479
522
  }
480
- /** Edit renderer params */
481
- interface EditRendererParams<TData extends Row = Row> extends CellRendererParams<TData> {
482
- /** Initial value */
483
- initialValue: CellValue;
484
- /** On value change */
485
- onValueChange: (newValue: CellValue) => void;
486
- /** On commit */
487
- onCommit: () => void;
488
- /** On cancel */
489
- onCancel: () => void;
523
+ /** Column resize in progress */
524
+ interface UpdateColumnResizeInstruction {
525
+ type: "UPDATE_COLUMN_RESIZE";
526
+ colIndex: number;
527
+ currentWidth: number;
490
528
  }
491
- /** Header renderer params */
492
- interface HeaderRendererParams {
493
- /** Column definition */
494
- column: ColumnDefinition;
495
- /** Column index */
529
+ /** Column resize committed */
530
+ interface CommitColumnResizeInstruction {
531
+ type: "COMMIT_COLUMN_RESIZE";
496
532
  colIndex: number;
497
- /** Sort direction */
498
- sortDirection?: SortDirection;
499
- /** Sort index */
500
- sortIndex?: number;
501
- /** Whether column is sortable */
502
- sortable: boolean;
503
- /** Whether column is filterable */
504
- filterable: boolean;
505
- /** Whether column has an active filter */
506
- hasFilter: boolean;
507
- /** On sort */
508
- onSort: (direction: SortDirection | null, addToExisting: boolean) => void;
509
- /** On filter click */
510
- onFilterClick: () => void;
533
+ newWidth: number;
534
+ }
535
+ /** Column resize cancelled */
536
+ interface CancelColumnResizeInstruction {
537
+ type: "CANCEL_COLUMN_RESIZE";
538
+ }
539
+ /** Column move started */
540
+ interface StartColumnMoveInstruction {
541
+ type: "START_COLUMN_MOVE";
542
+ sourceColIndex: number;
543
+ }
544
+ /** Column move position updated */
545
+ interface UpdateColumnMoveInstruction {
546
+ type: "UPDATE_COLUMN_MOVE";
547
+ currentX: number;
548
+ currentY: number;
549
+ dropTargetIndex: number | null;
550
+ }
551
+ /** Column move committed */
552
+ interface CommitColumnMoveInstruction {
553
+ type: "COMMIT_COLUMN_MOVE";
554
+ sourceColIndex: number;
555
+ targetColIndex: number;
556
+ }
557
+ /** Column move cancelled */
558
+ interface CancelColumnMoveInstruction {
559
+ type: "CANCEL_COLUMN_MOVE";
560
+ }
561
+ /** Row drag started */
562
+ interface StartRowDragInstruction {
563
+ type: "START_ROW_DRAG";
564
+ sourceRowIndex: number;
565
+ }
566
+ /** Row drag position updated */
567
+ interface UpdateRowDragInstruction {
568
+ type: "UPDATE_ROW_DRAG";
569
+ currentX: number;
570
+ currentY: number;
571
+ dropTargetIndex: number | null;
572
+ }
573
+ /** Row drag committed */
574
+ interface CommitRowDragInstruction {
575
+ type: "COMMIT_ROW_DRAG";
576
+ sourceRowIndex: number;
577
+ targetRowIndex: number;
578
+ }
579
+ /** Row drag cancelled */
580
+ interface CancelRowDragInstruction {
581
+ type: "CANCEL_ROW_DRAG";
511
582
  }
583
+ /** Union type of all instructions */
584
+ type GridInstruction = /** Slot lifecycle */CreateSlotInstruction | DestroySlotInstruction | AssignSlotInstruction | MoveSlotInstruction /** Selection */ | SetActiveCellInstruction | SetSelectionRangeInstruction | UpdateVisibleRangeInstruction /** Highlighting */ | SetHoverPositionInstruction /** Editing */ | StartEditInstruction | StopEditInstruction | CommitEditInstruction /** Layout */ | SetContentSizeInstruction | UpdateHeaderInstruction /** Filter popup */ | OpenFilterPopupInstruction | CloseFilterPopupInstruction /** Fill handle */ | StartFillInstruction | UpdateFillInstruction | CommitFillInstruction | CancelFillInstruction /** Data */ | DataLoadingInstruction | DataLoadedInstruction | DataErrorInstruction /** Transactions */ | RowsAddedInstruction | RowsRemovedInstruction | RowsUpdatedInstruction | TransactionProcessedInstruction /** Column changes */ | ColumnsChangedInstruction /** Column resize */ | StartColumnResizeInstruction | UpdateColumnResizeInstruction | CommitColumnResizeInstruction | CancelColumnResizeInstruction /** Column move */ | StartColumnMoveInstruction | UpdateColumnMoveInstruction | CommitColumnMoveInstruction | CancelColumnMoveInstruction /** Row drag */ | StartRowDragInstruction | UpdateRowDragInstruction | CommitRowDragInstruction | CancelRowDragInstruction;
585
+ /** Instruction listener: Single instruction Listener that receives a single instruction, used by frameworks to update their state */
586
+ type InstructionListener = (instruction: GridInstruction) => void;
587
+ /** Batch instruction listener: Batch instruction Listener that receives an array of instructions, used by frameworks to update their state */
588
+ type BatchInstructionListener = (instructions: GridInstruction[]) => void;
512
589
  //#endregion
513
590
  //#region src/types/options.d.ts
514
591
  /** Grid core options */
@@ -533,6 +610,14 @@ interface GridCoreOptions<TData = Row> {
533
610
  highlighting?: HighlightingOptions<TData>;
534
611
  /** Called when a cell value is changed via editing or fill drag. Requires getRowId. */
535
612
  onCellValueChanged?: (event: CellValueChangedEvent<TData>) => void;
613
+ /** Whether clicking and dragging any cell in a row drags the entire row instead of starting selection. Default: false */
614
+ rowDragEntireRow?: boolean;
615
+ /** Called when a row is dropped after dragging. Consumer is responsible for data reordering. */
616
+ onRowDragEnd?: (sourceIndex: number, targetIndex: number) => void;
617
+ /** Called when a column is resized. */
618
+ onColumnResized?: (colIndex: number, newWidth: number) => void;
619
+ /** Called when a column is moved/reordered. */
620
+ onColumnMoved?: (fromIndex: number, toIndex: number) => void;
536
621
  }
537
622
  //#endregion
538
623
  //#region src/types/input.d.ts
@@ -586,7 +671,7 @@ interface InputResult {
586
671
  /** Whether framework should focus the container element */
587
672
  focusContainer?: boolean;
588
673
  /** Type of drag operation to start (framework manages global listeners) */
589
- startDrag?: "selection" | "fill";
674
+ startDrag?: "selection" | "fill" | "column-resize" | "column-move" | "row-drag";
590
675
  }
591
676
  /** Result from keyboard input handler */
592
677
  interface KeyboardResult {
@@ -623,13 +708,39 @@ interface InputHandlerDeps {
623
708
  * If not provided, visible index is used directly (no hidden columns).
624
709
  */
625
710
  getOriginalColumnIndex?: (visibleIndex: number) => number;
711
+ /** Get column widths array (indexed by visible column) */
712
+ getColumnWidths?: () => number[];
713
+ }
714
+ /** Column resize drag state */
715
+ interface ColumnResizeDragState {
716
+ colIndex: number;
717
+ initialWidth: number;
718
+ currentWidth: number;
719
+ }
720
+ /** Column move drag state */
721
+ interface ColumnMoveDragState {
722
+ sourceColIndex: number;
723
+ currentX: number;
724
+ currentY: number;
725
+ dropTargetIndex: number | null;
726
+ ghostWidth: number;
727
+ ghostHeight: number;
728
+ }
729
+ /** Row drag state */
730
+ interface RowDragState {
731
+ sourceRowIndex: number;
732
+ currentX: number;
733
+ currentY: number;
734
+ dropTargetIndex: number | null;
735
+ /** Pre-computed translateY for the drop indicator inside the rows wrapper */
736
+ dropIndicatorY: number;
626
737
  }
627
738
  /** Current drag state for UI rendering */
628
739
  interface DragState {
629
740
  /** Whether any drag operation is active */
630
741
  isDragging: boolean;
631
742
  /** Type of active drag operation */
632
- dragType: "selection" | "fill" | null;
743
+ dragType: "selection" | "fill" | "column-resize" | "column-move" | "row-drag" | null;
633
744
  /** Source range for fill operations */
634
745
  fillSourceRange: CellRange | null;
635
746
  /** Current fill target position */
@@ -637,85 +748,14 @@ interface DragState {
637
748
  row: number;
638
749
  col: number;
639
750
  } | null;
751
+ /** Column resize state (when dragType is "column-resize") */
752
+ columnResize: ColumnResizeDragState | null;
753
+ /** Column move state (when dragType is "column-move") */
754
+ columnMove: ColumnMoveDragState | null;
755
+ /** Row drag state (when dragType is "row-drag") */
756
+ rowDrag: RowDragState | null;
640
757
  }
641
758
  //#endregion
642
- //#region src/utils/positioning.d.ts
643
- /**
644
- * Calculate cumulative column positions (prefix sums)
645
- * Returns an array where positions[i] is the left position of column i
646
- * positions[columns.length] is the total width
647
- */
648
- declare const calculateColumnPositions: (columns: ColumnDefinition[]) => number[];
649
- /**
650
- * Get total width from column positions
651
- */
652
- declare const getTotalWidth: (columnPositions: number[]) => number;
653
- /**
654
- * Calculate scaled column positions when container is wider than total column widths.
655
- * Columns expand proportionally based on their original width ratios.
656
- *
657
- * @param columns - Column definitions with original widths
658
- * @param containerWidth - Available container width
659
- * @returns Object with positions array and widths array
660
- */
661
- declare const calculateScaledColumnPositions: (columns: ColumnDefinition[], containerWidth: number) => {
662
- positions: number[];
663
- widths: number[];
664
- };
665
- /**
666
- * Find column index at a given X coordinate
667
- */
668
- declare const findColumnAtX: (x: number, columnPositions: number[]) => number;
669
- //#endregion
670
- //#region src/utils/classNames.d.ts
671
- /**
672
- * Check if a cell is within the selection range
673
- */
674
- declare const isCellSelected: (row: number, col: number, selectionRange: CellRange | null) => boolean;
675
- /**
676
- * Check if a cell is the active cell
677
- */
678
- declare const isCellActive: (row: number, col: number, activeCell: CellPosition | null) => boolean;
679
- /**
680
- * Check if a row is within the visible range (not in overscan)
681
- */
682
- declare const isRowVisible: (row: number, visibleRowRange: {
683
- start: number;
684
- end: number;
685
- } | null) => boolean;
686
- /**
687
- * Check if a cell is being edited
688
- */
689
- declare const isCellEditing: (row: number, col: number, editingCell: {
690
- row: number;
691
- col: number;
692
- } | null) => boolean;
693
- /**
694
- * Check if a cell is in the fill preview range (vertical-only fill)
695
- */
696
- declare const isCellInFillPreview: (row: number, col: number, isDraggingFill: boolean, fillSourceRange: CellRange | null, fillTarget: {
697
- row: number;
698
- col: number;
699
- } | null) => boolean;
700
- /**
701
- * Build cell CSS classes based on state
702
- */
703
- declare const buildCellClasses: (isActive: boolean, isSelected: boolean, isEditing: boolean, inFillPreview: boolean) => string;
704
- /**
705
- * Check if a row overlaps the selection range
706
- */
707
- declare const isRowInSelectionRange: (rowIndex: number, range: CellRange | null) => boolean;
708
- /**
709
- * Check if a column overlaps the selection range
710
- */
711
- declare const isColumnInSelectionRange: (colIndex: number, range: CellRange | null) => boolean;
712
- //#endregion
713
- //#region src/utils/event-emitter.d.ts
714
- /**
715
- * Batch instruction listener for efficient state updates
716
- */
717
- type BatchInstructionListener$1 = (instructions: GridInstruction[]) => void;
718
- //#endregion
719
759
  //#region src/selection.d.ts
720
760
  type Direction = "up" | "down" | "left" | "right";
721
761
  interface SelectionManagerOptions {
@@ -842,6 +882,30 @@ declare class InputHandler<TData extends Row = Row> {
842
882
  private isDraggingFill;
843
883
  private fillSourceRange;
844
884
  private fillTarget;
885
+ private isDraggingColumnResize;
886
+ private resizeColIndex;
887
+ private resizeStartX;
888
+ private resizeInitialWidth;
889
+ private resizeCurrentWidth;
890
+ private isDraggingColumnMove;
891
+ private moveSourceColIndex;
892
+ private moveStartX;
893
+ private moveStartY;
894
+ private moveThresholdMet;
895
+ private moveShiftKey;
896
+ private moveGhostWidth;
897
+ private moveGhostHeight;
898
+ private moveCurrentX;
899
+ private moveCurrentY;
900
+ private moveDropTargetIndex;
901
+ private isDraggingRow;
902
+ private rowDragSourceIndex;
903
+ private rowDragStartX;
904
+ private rowDragStartY;
905
+ private rowDragThresholdMet;
906
+ private rowDragCurrentX;
907
+ private rowDragCurrentY;
908
+ private rowDragDropTargetIndex;
845
909
  constructor(core: GridCore<TData>, deps: InputHandlerDeps);
846
910
  /**
847
911
  * Update dependencies (called when options change)
@@ -875,12 +939,22 @@ declare class InputHandler<TData extends Row = Row> {
875
939
  * Handle header click event (cycle sort direction)
876
940
  */
877
941
  handleHeaderClick(colId: string, addToExisting: boolean): void;
942
+ /**
943
+ * Handle mousedown on the resize handle of a header cell.
944
+ * Returns InputResult with startDrag: "column-resize".
945
+ */
946
+ handleHeaderResizeMouseDown(colIndex: number, colWidth: number, event: PointerEventData): InputResult;
947
+ /**
948
+ * Handle mousedown on a header cell for potential column move.
949
+ * Uses a drag threshold to distinguish click (sort) vs drag (move).
950
+ */
951
+ handleHeaderMouseDown(colIndex: number, colWidth: number, colHeight: number, event: PointerEventData): InputResult;
878
952
  /**
879
953
  * Start selection drag (called by framework after handleCellMouseDown returns startDrag: 'selection')
880
954
  */
881
955
  startSelectionDrag(): void;
882
956
  /**
883
- * Handle drag move event (selection or fill)
957
+ * Handle drag move event (selection, fill, column-resize, column-move, or row-drag)
884
958
  */
885
959
  handleDragMove(event: PointerEventData, bounds: ContainerBounds): DragMoveResult | null;
886
960
  /**
@@ -908,7 +982,7 @@ declare class InputHandler<TData extends Row = Row> {
908
982
  private calculateAutoScroll;
909
983
  }
910
984
  //#endregion
911
- //#region src/highlight-manager.d.ts
985
+ //#region src/managers/highlight-manager.d.ts
912
986
  interface HighlightManagerOptions {
913
987
  getActiveCell: () => CellPosition | null;
914
988
  getSelectionRange: () => CellRange | null;
@@ -995,121 +1069,50 @@ declare class HighlightManager<TData = Record<string, unknown>> {
995
1069
  destroy(): void;
996
1070
  }
997
1071
  //#endregion
998
- //#region src/sort-filter-manager.d.ts
999
- interface SortFilterManagerOptions<TData> {
1000
- /** Get all columns */
1001
- getColumns: () => ColumnDefinition[];
1002
- /** Check if sorting is enabled globally */
1003
- isSortingEnabled: () => boolean;
1004
- /** Get cached rows for distinct value computation */
1072
+ //#region src/managers/row-mutation-manager.d.ts
1073
+ interface RowMutationManagerOptions<TData> {
1074
+ /** Get the cached rows map */
1005
1075
  getCachedRows: () => Map<number, TData>;
1006
- /** Called when sort/filter changes to trigger data refresh */
1007
- onSortFilterChange: () => Promise<void>;
1008
- /** Called after data refresh to update UI */
1009
- onDataRefreshed: () => void;
1076
+ /** Set the cached rows map (for bulk operations) */
1077
+ setCachedRows: (rows: Map<number, TData>) => void;
1078
+ /** Get total row count */
1079
+ getTotalRows: () => number;
1080
+ /** Set total row count */
1081
+ setTotalRows: (count: number) => void;
1082
+ /** Update a single slot after row change */
1083
+ updateSlot: (rowIndex: number) => void;
1084
+ /** Refresh all slots after bulk changes */
1085
+ refreshAllSlots: () => void;
1086
+ /** Emit content size change */
1087
+ emitContentSize: () => void;
1088
+ /** Clear selection if it references invalid rows */
1089
+ clearSelectionIfInvalid: (maxValidRow: number) => void;
1010
1090
  }
1011
1091
  /**
1012
- * Manages sorting and filtering state and operations.
1092
+ * Manages row CRUD operations and cache management.
1013
1093
  */
1014
- declare class SortFilterManager<TData = Record<string, unknown>> {
1094
+ declare class RowMutationManager<TData extends Row = Row> {
1015
1095
  private options;
1016
1096
  private emitter;
1017
- private sortModel;
1018
- private filterModel;
1019
- private openFilterColIndex;
1020
1097
  onInstruction: (listener: InstructionListener) => () => void;
1021
1098
  private emit;
1022
- constructor(options: SortFilterManagerOptions<TData>);
1023
- setSort(colId: string, direction: SortDirection | null, addToExisting?: boolean): Promise<void>;
1024
- getSortModel(): SortModel[];
1025
- setFilter(colId: string, filter: ColumnFilterModel | string | null): Promise<void>;
1026
- getFilterModel(): FilterModel;
1099
+ constructor(options: RowMutationManagerOptions<TData>);
1027
1100
  /**
1028
- * Check if a column has an active filter
1101
+ * Get a row by index.
1029
1102
  */
1030
- hasActiveFilter(colId: string): boolean;
1103
+ getRow(index: number): TData | undefined;
1031
1104
  /**
1032
- * Check if a column is sortable
1105
+ * Add rows to the grid at the specified index.
1106
+ * If no index is provided, rows are added at the end.
1033
1107
  */
1034
- isColumnSortable(colIndex: number): boolean;
1108
+ addRows(rows: TData[], index?: number): void;
1035
1109
  /**
1036
- * Check if a column is filterable
1110
+ * Update existing rows with partial data.
1037
1111
  */
1038
- isColumnFilterable(colIndex: number): boolean;
1039
- /**
1040
- * Get distinct values for a column (for filter dropdowns)
1041
- * For array-type columns (like tags), each unique array combination is returned.
1042
- * Arrays are sorted internally for consistent comparison.
1043
- * Limited to maxValues to avoid performance issues with large datasets.
1044
- */
1045
- getDistinctValuesForColumn(colId: string, maxValues?: number): CellValue[];
1046
- /**
1047
- * Open filter popup for a column (toggles if already open for same column)
1048
- */
1049
- openFilterPopup(colIndex: number, anchorRect: {
1050
- top: number;
1051
- left: number;
1052
- width: number;
1053
- height: number;
1054
- }): void;
1055
- /**
1056
- * Close filter popup
1057
- */
1058
- closeFilterPopup(): void;
1059
- /**
1060
- * Get sort info map for header rendering
1061
- */
1062
- getSortInfoMap(): Map<string, {
1063
- direction: SortDirection;
1064
- index: number;
1065
- }>;
1066
- destroy(): void;
1067
- }
1068
- //#endregion
1069
- //#region src/row-mutation-manager.d.ts
1070
- interface RowMutationManagerOptions<TData> {
1071
- /** Get the cached rows map */
1072
- getCachedRows: () => Map<number, TData>;
1073
- /** Set the cached rows map (for bulk operations) */
1074
- setCachedRows: (rows: Map<number, TData>) => void;
1075
- /** Get total row count */
1076
- getTotalRows: () => number;
1077
- /** Set total row count */
1078
- setTotalRows: (count: number) => void;
1079
- /** Update a single slot after row change */
1080
- updateSlot: (rowIndex: number) => void;
1081
- /** Refresh all slots after bulk changes */
1082
- refreshAllSlots: () => void;
1083
- /** Emit content size change */
1084
- emitContentSize: () => void;
1085
- /** Clear selection if it references invalid rows */
1086
- clearSelectionIfInvalid: (maxValidRow: number) => void;
1087
- }
1088
- /**
1089
- * Manages row CRUD operations and cache management.
1090
- */
1091
- declare class RowMutationManager<TData extends Row = Row> {
1092
- private options;
1093
- private emitter;
1094
- onInstruction: (listener: InstructionListener) => () => void;
1095
- private emit;
1096
- constructor(options: RowMutationManagerOptions<TData>);
1097
- /**
1098
- * Get a row by index.
1099
- */
1100
- getRow(index: number): TData | undefined;
1101
- /**
1102
- * Add rows to the grid at the specified index.
1103
- * If no index is provided, rows are added at the end.
1104
- */
1105
- addRows(rows: TData[], index?: number): void;
1106
- /**
1107
- * Update existing rows with partial data.
1108
- */
1109
- updateRows(updates: Array<{
1110
- index: number;
1111
- data: Partial<TData>;
1112
- }>): void;
1112
+ updateRows(updates: Array<{
1113
+ index: number;
1114
+ data: Partial<TData>;
1115
+ }>): void;
1113
1116
  /**
1114
1117
  * Delete rows at the specified indices.
1115
1118
  */
@@ -1122,88 +1125,29 @@ declare class RowMutationManager<TData extends Row = Row> {
1122
1125
  destroy(): void;
1123
1126
  }
1124
1127
  //#endregion
1125
- //#region src/grid-core.d.ts
1126
- declare class GridCore<TData extends Row = Row> {
1127
- private columns;
1128
- private dataSource;
1129
- private rowHeight;
1130
- private headerHeight;
1131
- private overscan;
1132
- private sortingEnabled;
1133
- private getRowId?;
1134
- private onCellValueChanged?;
1135
- private scrollTop;
1136
- private scrollLeft;
1137
- private viewportWidth;
1138
- private viewportHeight;
1139
- private cachedRows;
1140
- private totalRows;
1141
- private currentPageIndex;
1142
- private pageSize;
1143
- readonly selection: SelectionManager;
1144
- readonly fill: FillManager;
1145
- readonly input: InputHandler<TData>;
1146
- readonly highlight: HighlightManager<TData> | null;
1147
- readonly sortFilter: SortFilterManager<TData>;
1148
- readonly rowMutation: RowMutationManager<TData>;
1149
- private readonly slotPool;
1150
- private readonly editManager;
1151
- private columnPositions;
1152
- private emitter;
1153
- onInstruction: (listener: InstructionListener) => () => void;
1154
- onBatchInstruction: (listener: BatchInstructionListener$1) => () => void;
1155
- private emit;
1156
- private emitBatch;
1128
+ //#region src/managers/scroll-virtualization-manager.d.ts
1129
+ interface ScrollVirtualizationManagerOptions {
1130
+ getRowHeight: () => number;
1131
+ getHeaderHeight: () => number;
1132
+ getTotalRows: () => number;
1133
+ getScrollTop: () => number;
1134
+ getViewportHeight: () => number;
1135
+ }
1136
+ declare class ScrollVirtualizationManager {
1157
1137
  private naturalContentHeight;
1158
1138
  private virtualContentHeight;
1159
1139
  private scrollRatio;
1160
- private isDestroyed;
1161
- private _isDataLoading;
1162
- constructor(options: GridCoreOptions<TData>);
1163
- /**
1164
- * Initialize the grid and load initial data.
1165
- */
1166
- initialize(): Promise<void>;
1140
+ private readonly options;
1141
+ constructor(options: ScrollVirtualizationManagerOptions);
1167
1142
  /**
1168
- * Update viewport measurements and sync slots.
1169
- * When scroll virtualization is active, maps the DOM scroll position to the actual row position.
1143
+ * Update scroll virtualization state based on current row count.
1144
+ * Should be called whenever totalRows changes.
1170
1145
  */
1171
- setViewport(scrollTop: number, scrollLeft: number, width: number, height: number): void;
1172
- private fetchData;
1173
- private fetchAllData;
1174
- setSort(colId: string, direction: SortDirection | null, addToExisting?: boolean): Promise<void>;
1175
- setFilter(colId: string, filter: ColumnFilterModel | string | null): Promise<void>;
1176
- hasActiveFilter(colId: string): boolean;
1177
- isColumnSortable(colIndex: number): boolean;
1178
- isColumnFilterable(colIndex: number): boolean;
1179
- getDistinctValuesForColumn(colId: string, maxValues?: number): CellValue[];
1180
- openFilterPopup(colIndex: number, anchorRect: {
1181
- top: number;
1182
- left: number;
1183
- width: number;
1184
- height: number;
1185
- }): void;
1186
- closeFilterPopup(): void;
1187
- getSortModel(): SortModel[];
1188
- getFilterModel(): FilterModel;
1189
- startEdit(row: number, col: number): void;
1190
- updateEditValue(value: CellValue): void;
1191
- commitEdit(): void;
1192
- cancelEdit(): void;
1193
- getEditState(): EditState | null;
1194
- getCellValue(row: number, col: number): CellValue;
1195
- setCellValue(row: number, col: number, value: CellValue): void;
1196
- private clearSelectionIfInvalid;
1197
- private computeColumnPositions;
1198
- private emitContentSize;
1199
- private emitHeaders;
1200
- getColumns(): ColumnDefinition[];
1201
- getColumnPositions(): number[];
1202
- getRowCount(): number;
1203
- getRowHeight(): number;
1204
- getHeaderHeight(): number;
1205
- getTotalWidth(): number;
1206
- getTotalHeight(): number;
1146
+ updateContentSize(): {
1147
+ naturalHeight: number;
1148
+ virtualHeight: number;
1149
+ scrollRatio: number;
1150
+ };
1207
1151
  /**
1208
1152
  * Check if scroll scaling is active (large datasets exceeding browser scroll limits).
1209
1153
  * When scaling is active, scrollRatio < 1 and scroll positions are compressed.
@@ -1214,6 +1158,10 @@ declare class GridCore<TData extends Row = Row> {
1214
1158
  * Useful for debugging or displaying actual content size.
1215
1159
  */
1216
1160
  getNaturalHeight(): number;
1161
+ /**
1162
+ * Get the virtual (capped) content height for DOM use.
1163
+ */
1164
+ getVirtualHeight(): number;
1217
1165
  /**
1218
1166
  * Get the scroll ratio used for scroll virtualization.
1219
1167
  * Returns 1 when no virtualization is needed, < 1 when content exceeds browser limits.
@@ -1240,742 +1188,1139 @@ declare class GridCore<TData extends Row = Row> {
1240
1188
  * @param virtualScrollTop Current scroll position from container.scrollTop (virtual/scaled)
1241
1189
  */
1242
1190
  getRowIndexAtDisplayY(viewportY: number, virtualScrollTop: number): number;
1243
- getRowData(rowIndex: number): TData | undefined;
1244
- /**
1245
- * Refresh data from the data source.
1246
- */
1247
- refresh(): Promise<void>;
1248
- /**
1249
- * Fast-path refresh for transaction-based mutations.
1250
- * Only re-fetches the visible window instead of all rows.
1251
- * Use this when data was mutated via MutableDataSource transactions.
1252
- */
1253
- refreshFromTransaction(): Promise<void>;
1254
- /**
1255
- * Refresh slot display without refetching data.
1256
- * Useful after in-place data modifications like fill operations.
1257
- */
1258
- refreshSlotData(): void;
1259
1191
  /**
1260
- * Add rows to the grid at the specified index.
1261
- * If no index is provided, rows are added at the end.
1192
+ * Get the virtual content height for external use
1193
+ * @internal
1262
1194
  */
1263
- addRows(rows: TData[], index?: number): void;
1195
+ getVirtualContentHeight(): number;
1196
+ }
1197
+ //#endregion
1198
+ //#region src/managers/sort-filter-manager.d.ts
1199
+ interface SortFilterManagerOptions<TData> {
1200
+ /** Get all columns */
1201
+ getColumns: () => ColumnDefinition[];
1202
+ /** Check if sorting is enabled globally */
1203
+ isSortingEnabled: () => boolean;
1204
+ /** Get cached rows for distinct value computation */
1205
+ getCachedRows: () => Map<number, TData>;
1206
+ /** Called when sort/filter changes to trigger data refresh */
1207
+ onSortFilterChange: () => Promise<void>;
1208
+ /** Called after data refresh to update UI */
1209
+ onDataRefreshed: () => void;
1210
+ }
1211
+ /**
1212
+ * Manages sorting and filtering state and operations.
1213
+ */
1214
+ declare class SortFilterManager<TData = Record<string, unknown>> {
1215
+ private options;
1216
+ private emitter;
1217
+ private sortModel;
1218
+ private filterModel;
1219
+ private openFilterColIndex;
1220
+ onInstruction: (listener: InstructionListener) => () => void;
1221
+ private emit;
1222
+ constructor(options: SortFilterManagerOptions<TData>);
1223
+ setSort(colId: string, direction: SortDirection | null, addToExisting?: boolean): Promise<void>;
1224
+ getSortModel(): SortModel[];
1225
+ setFilter(colId: string, filter: ColumnFilterModel | string | null): Promise<void>;
1226
+ getFilterModel(): FilterModel;
1264
1227
  /**
1265
- * Update existing rows with partial data.
1228
+ * Check if a column has an active filter
1266
1229
  */
1267
- updateRows(updates: Array<{
1268
- index: number;
1269
- data: Partial<TData>;
1270
- }>): void;
1230
+ hasActiveFilter(colId: string): boolean;
1271
1231
  /**
1272
- * Delete rows at the specified indices.
1232
+ * Check if a column is sortable
1273
1233
  */
1274
- deleteRows(indices: number[]): void;
1234
+ isColumnSortable(colIndex: number): boolean;
1275
1235
  /**
1276
- * Get a row by index.
1236
+ * Check if a column is filterable
1277
1237
  */
1278
- getRow(index: number): TData | undefined;
1238
+ isColumnFilterable(colIndex: number): boolean;
1279
1239
  /**
1280
- * Set a complete row at the specified index.
1281
- * Use this for complete row replacement. For partial updates, use updateRows.
1240
+ * Get distinct values for a column (for filter dropdowns)
1241
+ * For array-type columns (like tags), each unique array combination is returned.
1242
+ * Arrays are sorted internally for consistent comparison.
1243
+ * Limited to maxValues to avoid performance issues with large datasets.
1282
1244
  */
1283
- setRow(index: number, data: TData): void;
1245
+ getDistinctValuesForColumn(colId: string, maxValues?: number): CellValue[];
1284
1246
  /**
1285
- * Update the data source and refresh.
1286
- * Preserves grid state (sort, filter, scroll position).
1287
- * Cancels any active edit and clamps selection to valid range.
1247
+ * Open filter popup for a column (toggles if already open for same column)
1288
1248
  */
1289
- setDataSource(dataSource: DataSource<TData>): Promise<void>;
1249
+ openFilterPopup(colIndex: number, anchorRect: {
1250
+ top: number;
1251
+ left: number;
1252
+ width: number;
1253
+ height: number;
1254
+ }): void;
1290
1255
  /**
1291
- * Update columns and recompute layout.
1256
+ * Close filter popup
1292
1257
  */
1293
- setColumns(columns: ColumnDefinition[]): void;
1258
+ closeFilterPopup(): void;
1294
1259
  /**
1295
- * Destroy the grid core and release all references.
1296
- * Call this before discarding the GridCore to ensure proper cleanup.
1297
- * This method is idempotent - safe to call multiple times.
1260
+ * Get sort info map for header rendering
1298
1261
  */
1262
+ getSortInfoMap(): Map<string, {
1263
+ direction: SortDirection;
1264
+ index: number;
1265
+ }>;
1299
1266
  destroy(): void;
1300
1267
  }
1301
1268
  //#endregion
1302
- //#region src/slot-pool.d.ts
1303
- interface SlotPoolManagerOptions {
1304
- /** Get current row height */
1305
- getRowHeight: () => number;
1306
- /** Get current header height */
1307
- getHeaderHeight: () => number;
1308
- /** Get overscan count */
1309
- getOverscan: () => number;
1310
- /** Get current scroll top position (natural, not virtual) */
1311
- getScrollTop: () => number;
1312
- /** Get viewport height */
1313
- getViewportHeight: () => number;
1314
- /** Get total row count */
1315
- getTotalRows: () => number;
1316
- /** Get scroll ratio for virtualization (1 = no virtualization) */
1317
- getScrollRatio: () => number;
1318
- /** Get virtual content height */
1319
- getVirtualContentHeight: () => number;
1320
- /** Get row data by index */
1321
- getRowData: (rowIndex: number) => Row | undefined;
1269
+ //#region src/indexed-data-store/indexed-data-store.d.ts
1270
+ interface IndexedDataStoreOptions<TData> {
1271
+ /** Function to extract unique ID from row. Required for mutations. */
1272
+ getRowId: (row: TData) => RowId;
1273
+ /** Custom field accessor for nested properties */
1274
+ getFieldValue?: (row: TData, field: string) => CellValue;
1275
+ }
1276
+ /** Hash cache for a single row */
1277
+ interface RowSortCache {
1278
+ /** Map: sortModelHash -> computed hashes for that sort configuration */
1279
+ hashes: Map<string, number[]>;
1322
1280
  }
1323
1281
  /**
1324
- * Manages the slot pool for virtual scrolling.
1325
- * Handles slot creation, recycling, positioning, and destruction.
1282
+ * Efficient data structure for incremental operations on grid data.
1283
+ * Supports:
1284
+ * - O(1) lookup by row ID
1285
+ * - O(log n) binary insertion to maintain sort order
1286
+ * - Filter state caching with distinct values
1287
+ * - Hash caching for fast sorted comparisons
1326
1288
  */
1327
- declare class SlotPoolManager {
1328
- private state;
1289
+ declare class IndexedDataStore<TData extends Row = Row> {
1290
+ private rows;
1291
+ private rowById;
1292
+ private sortedIndices;
1293
+ private sortModel;
1294
+ private sortModelHash;
1295
+ private filterModel;
1296
+ private filteredIndices;
1297
+ private distinctValues;
1298
+ private rowSortCache;
1329
1299
  private options;
1330
- private emitter;
1331
- private isDestroyed;
1332
- onInstruction: (listener: InstructionListener) => () => void;
1333
- onBatchInstruction: (listener: BatchInstructionListener$1) => () => void;
1334
- private emit;
1335
- private emitBatch;
1336
- constructor(options: SlotPoolManagerOptions);
1300
+ constructor(initialData: TData[] | undefined, options: IndexedDataStoreOptions<TData>);
1337
1301
  /**
1338
- * Get the slot ID for a given row index.
1302
+ * Clear all data and internal caches.
1303
+ * Used for proper memory cleanup when the store is no longer needed.
1339
1304
  */
1340
- getSlotForRow(rowIndex: number): string | undefined;
1305
+ clear(): void;
1341
1306
  /**
1342
- * Get all current slots.
1307
+ * Replace all data (used for initial load or full refresh).
1343
1308
  */
1344
- getSlots(): Map<string, SlotState>;
1309
+ setData(data: TData[]): void;
1345
1310
  /**
1346
- * Synchronize slots with current viewport position.
1347
- * This implements the slot recycling strategy.
1311
+ * Query data with sorting, filtering, and pagination.
1312
+ * Compatible with DataSource.fetch() interface.
1348
1313
  */
1349
- syncSlots(): void;
1314
+ query(request: DataSourceRequest): DataSourceResponse<TData>;
1350
1315
  /**
1351
- * Destroy all slots.
1316
+ * Get row by ID.
1352
1317
  */
1353
- destroyAllSlots(): void;
1318
+ getRowById(id: RowId): TData | undefined;
1354
1319
  /**
1355
- * Clean up resources for garbage collection.
1356
- * This method is idempotent - safe to call multiple times.
1320
+ * Get row by index.
1357
1321
  */
1358
- destroy(): void;
1322
+ getRowByIndex(index: number): TData | undefined;
1359
1323
  /**
1360
- * Refresh all slot data without changing which rows are displayed.
1361
- * Used after filtering/sorting when data changes.
1324
+ * Get total row count (unfiltered).
1362
1325
  */
1363
- refreshAllSlots(): void;
1326
+ getTotalRowCount(): number;
1364
1327
  /**
1365
- * Update a single slot's data.
1328
+ * Get all rows as a new array.
1329
+ * Used for direct data access when bypassing store's query system.
1366
1330
  */
1367
- updateSlot(rowIndex: number): void;
1331
+ getAllRows(): TData[];
1368
1332
  /**
1369
- * Calculate the translateY position for a row.
1370
- * Handles scroll virtualization for very large datasets.
1371
- *
1372
- * When virtualization is active (scrollRatio < 1), we use viewport-relative
1373
- * positioning to keep translateY values small. This prevents browser rendering
1374
- * issues that occur at extreme pixel values (millions of pixels).
1375
- *
1376
- * Note: The header is rendered outside the content sizer, so row positions
1377
- * start at 0 (not headerHeight) within the rows container.
1333
+ * Move a row from one position to another in the raw data array.
1334
+ * This reorders the underlying data; when no sort is active, the new order
1335
+ * is reflected immediately on the next fetch.
1378
1336
  */
1379
- private getRowTranslateY;
1337
+ moveRow(fromIndex: number, toIndex: number): void;
1380
1338
  /**
1381
- * Get the Y offset for the rows wrapper container.
1382
- * When virtualization is active, this positions the wrapper so rows
1383
- * with small translateY values appear at the correct scroll position.
1339
+ * Get visible row count (after filtering).
1384
1340
  */
1385
- getRowsWrapperOffset(): number;
1386
- }
1387
- //#endregion
1388
- //#region src/edit-manager.d.ts
1389
- interface EditManagerOptions {
1390
- /** Get column definition by index */
1391
- getColumn: (colIndex: number) => ColumnDefinition | undefined;
1392
- /** Get cell value */
1393
- getCellValue: (row: number, col: number) => CellValue;
1394
- /** Set cell value */
1395
- setCellValue: (row: number, col: number, value: CellValue) => void;
1396
- /** Callback when edit is committed (to update slot display) */
1397
- onCommit?: (row: number, col: number, value: CellValue) => void;
1398
- }
1399
- /**
1400
- * Manages cell editing state and operations.
1401
- */
1402
- declare class EditManager {
1403
- private editState;
1404
- private options;
1405
- private emitter;
1406
- onInstruction: (listener: InstructionListener) => () => void;
1407
- private emit;
1408
- constructor(options: EditManagerOptions);
1341
+ getVisibleRowCount(): number;
1409
1342
  /**
1410
- * Get the current edit state.
1343
+ * Get distinct values for a field (for filter UI).
1411
1344
  */
1412
- getState(): EditState | null;
1345
+ getDistinctValues(field: string): CellValue[];
1413
1346
  /**
1414
- * Check if currently editing.
1347
+ * Add rows to the store.
1348
+ * Rows are inserted at their correct sorted position.
1415
1349
  */
1416
- isEditing(): boolean;
1350
+ addRows(rows: TData[]): void;
1417
1351
  /**
1418
- * Check if a specific cell is being edited.
1352
+ * Add a single row.
1419
1353
  */
1420
- isEditingCell(row: number, col: number): boolean;
1354
+ private addRow;
1421
1355
  /**
1422
- * Start editing a cell.
1423
- * Returns true if edit was started, false if cell is not editable.
1356
+ * Remove rows by ID.
1424
1357
  */
1425
- startEdit(row: number, col: number): boolean;
1358
+ removeRows(ids: RowId[]): void;
1426
1359
  /**
1427
- * Update the current edit value.
1360
+ * Remove a single row by index.
1428
1361
  */
1429
- updateValue(value: CellValue): void;
1362
+ private removeRowByIndex;
1430
1363
  /**
1431
- * Commit the current edit.
1432
- * Saves the value and closes the editor.
1364
+ * Update indices after a row removal.
1433
1365
  */
1434
- commit(): void;
1366
+ private reindexAfterRemoval;
1435
1367
  /**
1436
- * Cancel the current edit.
1437
- * Discards changes and closes the editor.
1368
+ * Update a cell value.
1438
1369
  */
1439
- cancel(): void;
1370
+ updateCell(id: RowId, field: string, value: CellValue): void;
1440
1371
  /**
1441
- * Clean up resources for garbage collection.
1372
+ * Update multiple fields on a row.
1442
1373
  */
1443
- destroy(): void;
1444
- }
1445
- //#endregion
1446
- //#region src/sorting/parallel-sort-manager.d.ts
1447
- interface ParallelSortOptions {
1448
- /** Maximum number of workers (default: navigator.hardwareConcurrency || 4) */
1449
- maxWorkers?: number;
1450
- /** Threshold for parallel sorting (default: 400000) */
1451
- parallelThreshold?: number;
1452
- /** Minimum chunk size (default: 50000) */
1453
- minChunkSize?: number;
1454
- }
1455
- /**
1456
- * Manages parallel sorting operations using a worker pool.
1457
- * Automatically decides between single-worker and parallel sorting based on data size.
1458
- */
1459
- declare class ParallelSortManager {
1460
- private pool;
1461
- private parallelThreshold;
1462
- private minChunkSize;
1463
- private isTerminated;
1464
- constructor(options?: ParallelSortOptions);
1374
+ updateRow(id: RowId, data: Partial<TData>): void;
1465
1375
  /**
1466
- * Check if the manager is available for use.
1376
+ * Set the sort model. Triggers full re-sort if model changed.
1467
1377
  */
1468
- isAvailable(): boolean;
1378
+ setSortModel(model: SortModel[]): void;
1469
1379
  /**
1470
- * Terminate all workers and clean up resources.
1380
+ * Get current sort model.
1471
1381
  */
1472
- terminate(): void;
1382
+ getSortModel(): SortModel[];
1473
1383
  /**
1474
- * Sort indices using values array.
1475
- * Automatically uses parallel sorting for large datasets.
1384
+ * Set the filter model.
1476
1385
  */
1477
- sortIndices(values: number[], direction: SortDirection): Promise<Uint32Array>;
1386
+ setFilterModel(model: FilterModel): void;
1478
1387
  /**
1479
- * Sort string hashes with collision detection.
1480
- * Automatically uses parallel sorting for large datasets.
1388
+ * Get current filter model.
1481
1389
  */
1482
- sortStringHashes(hashChunks: Float64Array[], direction: SortDirection, originalStrings: string[]): Promise<Uint32Array>;
1390
+ getFilterModel(): FilterModel;
1483
1391
  /**
1484
- * Multi-column sort.
1485
- * Automatically uses parallel sorting for large datasets.
1392
+ * Rebuild sorted indices (full re-sort).
1486
1393
  */
1487
- sortMultiColumn(columns: number[][], directions: SortDirection[]): Promise<Uint32Array>;
1488
- private sortIndicesSingle;
1489
- private sortStringHashesSingle;
1490
- private sortMultiColumnSingle;
1491
- private sortIndicesParallel;
1492
- private sortStringHashesParallel;
1493
- private sortMultiColumnParallel;
1394
+ private rebuildSortedIndices;
1494
1395
  /**
1495
- * Split data into chunks for parallel processing.
1396
+ * Rebuild hash cache for all rows.
1496
1397
  */
1497
- private splitIntoChunks;
1398
+ private rebuildHashCache;
1498
1399
  /**
1499
- * Calculate chunk boundaries without copying data.
1400
+ * Compute and cache sort hashes for a row.
1500
1401
  */
1501
- private calculateChunkBoundaries;
1402
+ private computeRowHashes;
1502
1403
  /**
1503
- * Detect collisions at chunk boundaries for string sorting.
1404
+ * Compare two rows using cached hashes.
1504
1405
  */
1505
- private detectBoundaryCollisionsForStrings;
1406
+ private compareRows;
1506
1407
  /**
1507
- * Resolve hash collisions using localeCompare.
1408
+ * Binary search for insertion position in sortedIndices.
1508
1409
  */
1509
- private resolveCollisions;
1510
- }
1511
- //#endregion
1512
- //#region src/sorting/worker-pool.d.ts
1513
- interface WorkerPoolOptions {
1514
- /** Maximum number of workers (default: navigator.hardwareConcurrency ?? 4) */
1515
- maxWorkers?: number;
1516
- /** Whether to pre-warm workers on initialization */
1517
- preWarm?: boolean;
1518
- }
1519
- /**
1520
- * Manages a pool of Web Workers for parallel task execution.
1521
- * Workers are created lazily and reused across operations.
1522
- */
1523
- declare class WorkerPool {
1524
- private workerCode;
1525
- private maxWorkers;
1526
- private workers;
1527
- private workerUrl;
1528
- private nextRequestId;
1529
- private isTerminated;
1530
- constructor(workerCode: string, options?: WorkerPoolOptions);
1410
+ private binarySearchInsertPosition;
1531
1411
  /**
1532
- * Get the current pool size (number of active workers).
1412
+ * Rebuild filtered indices.
1533
1413
  */
1534
- getPoolSize(): number;
1414
+ private rebuildFilteredIndices;
1535
1415
  /**
1536
- * Get the maximum pool size.
1537
- */
1538
- getMaxWorkers(): number;
1539
- /**
1540
- * Check if the pool is available for use.
1541
- */
1542
- isAvailable(): boolean;
1543
- /**
1544
- * Execute a single task on an available worker.
1545
- * Returns the worker's response.
1546
- */
1547
- execute<TRequest extends {
1548
- id?: number;
1549
- }, TResponse>(request: TRequest, transferables?: Transferable[]): Promise<TResponse>;
1550
- /**
1551
- * Execute multiple tasks in parallel across available workers.
1552
- * Each task is assigned to a different worker if possible.
1553
- * Returns results in the same order as the input requests.
1554
- */
1555
- executeParallel<TRequest extends {
1556
- id?: number;
1557
- }, TResponse>(tasks: Array<{
1558
- request: TRequest;
1559
- transferables?: Transferable[];
1560
- }>): Promise<TResponse[]>;
1561
- /**
1562
- * Terminate all workers and clean up resources.
1563
- */
1564
- terminate(): void;
1565
- /**
1566
- * Pre-warm workers by creating them ahead of time.
1416
+ * Check if a row passes the current filter.
1567
1417
  */
1568
- private preWarmWorkers;
1418
+ private rowPassesFilter;
1569
1419
  /**
1570
- * Ensure at least `count` workers exist in the pool.
1420
+ * Get visible indices (filtered + sorted).
1571
1421
  */
1572
- private ensureWorkers;
1422
+ private getVisibleIndices;
1573
1423
  /**
1574
- * Get an available worker, creating one if needed.
1424
+ * Rebuild distinct values cache for all fields.
1575
1425
  */
1576
- private getAvailableWorker;
1426
+ private rebuildDistinctValues;
1577
1427
  /**
1578
- * Create a new worker and add it to the pool.
1428
+ * Update distinct values when a row is added or removed.
1579
1429
  */
1580
- private createWorker;
1430
+ private updateDistinctValuesForRow;
1581
1431
  /**
1582
- * Respawn a failed worker.
1432
+ * Update distinct value for a specific field when cell value changes.
1583
1433
  */
1584
- private respawnWorker;
1434
+ private updateDistinctValueForField;
1585
1435
  }
1586
1436
  //#endregion
1587
- //#region src/sorting/k-way-merge.d.ts
1437
+ //#region src/indexed-data-store/field-helpers.d.ts
1588
1438
  /**
1589
- * Represents a sorted chunk with its values and offset in the original array.
1439
+ * Default field value accessor supporting dot notation.
1440
+ * @example
1441
+ * getFieldValue({ user: { name: "John" } }, "user.name") // "John"
1590
1442
  */
1591
- interface SortedChunk {
1592
- /** Sorted indices (local to this chunk) */
1593
- indices: Uint32Array;
1594
- /** Values for comparison (in same order as indices) */
1595
- values: Float64Array;
1596
- /** Offset of this chunk in the original array */
1597
- offset: number;
1598
- }
1443
+ declare function getFieldValue<TData extends Row>(row: TData, field: string): CellValue;
1599
1444
  /**
1600
- * Represents a sorted chunk for multi-column sorting.
1445
+ * Set field value supporting dot notation.
1446
+ * Creates nested objects if they don't exist.
1447
+ * @example
1448
+ * const obj = { user: {} };
1449
+ * setFieldValue(obj, "user.name", "John");
1450
+ * // obj is now { user: { name: "John" } }
1601
1451
  */
1602
- interface MultiColumnSortedChunk {
1603
- /** Sorted indices (local to this chunk) */
1604
- indices: Uint32Array;
1605
- /** Values for comparison - array of columns, each in same order as indices */
1606
- columns: Float64Array[];
1607
- /** Sort directions for each column (1 = asc, -1 = desc) */
1608
- directions: Int8Array;
1609
- /** Offset of this chunk in the original array */
1610
- offset: number;
1611
- }
1452
+ declare function setFieldValue<TData extends Row>(row: TData, field: string, value: CellValue): void;
1453
+ //#endregion
1454
+ //#region src/indexed-data-store/sorting.d.ts
1612
1455
  /**
1613
- * Merge multiple sorted chunks into a single sorted result.
1614
- * Uses a min-heap for O(n log k) time complexity.
1615
- *
1616
- * @param chunks - Array of sorted chunks to merge
1617
- * @param direction - Sort direction ('asc' or 'desc')
1618
- * @returns Uint32Array of globally sorted indices
1456
+ * Convert a string to a sortable number using first 10 characters.
1457
+ * Uses base-36 encoding (a-z = 0-25, 0-9 = 26-35).
1619
1458
  */
1620
- declare function kWayMerge(chunks: SortedChunk[], direction: SortDirection): Uint32Array;
1459
+ declare function stringToSortableNumber(str: string): number;
1621
1460
  /**
1622
- * Merge multiple sorted chunks for multi-column sorting.
1623
- *
1624
- * @param chunks - Array of multi-column sorted chunks
1625
- * @returns Uint32Array of globally sorted indices
1461
+ * Compare two cell values for sorting.
1462
+ * Handles null/undefined, arrays, numbers, dates, and strings.
1626
1463
  */
1627
- declare function kWayMergeMultiColumn(chunks: MultiColumnSortedChunk[]): Uint32Array;
1464
+ declare function compareValues(a: CellValue, b: CellValue): number;
1628
1465
  /**
1629
- * Detect collision runs at chunk boundaries after merge.
1630
- * This is used for string sorting where hashes may collide across chunks.
1631
- *
1632
- * @param chunks - Original sorted chunks with their hash values
1633
- * @param _direction - Sort direction
1634
- * @returns Array of boundary collision positions [start1, end1, start2, end2, ...]
1466
+ * Compute a sortable hash for a cell value.
1467
+ * Used for fast comparisons in sorted indices.
1635
1468
  */
1636
- declare function detectBoundaryCollisions(chunks: SortedChunk[], _direction: SortDirection): Uint32Array;
1469
+ declare function computeValueHash(value: CellValue): number;
1637
1470
  //#endregion
1638
- //#region src/data-source/client-data-source.d.ts
1639
- interface ClientDataSourceOptions<TData> {
1640
- /** Custom field accessor for nested properties */
1641
- getFieldValue?: (row: TData, field: string) => CellValue;
1642
- /** Use Web Worker for sorting large datasets (default: true) */
1643
- useWorker?: boolean;
1644
- /** Options for parallel sorting (only used when useWorker is true) */
1645
- parallelSort?: ParallelSortOptions | false;
1646
- }
1471
+ //#region src/filtering/index.d.ts
1647
1472
  /**
1648
- * Creates a client-side data source that holds all data in memory.
1649
- * Sorting and filtering are performed client-side.
1650
- * For large datasets, sorting is automatically offloaded to a Web Worker.
1473
+ * Check if two dates are on the same day.
1651
1474
  */
1652
- declare function createClientDataSource<TData extends Row = Row>(data: TData[], options?: ClientDataSourceOptions<TData>): DataSource<TData>;
1475
+ declare function isSameDay(date1: Date, date2: Date): boolean;
1653
1476
  /**
1654
- * Convenience function to create a data source from an array.
1655
- * This provides backwards compatibility with the old `rowData` prop.
1477
+ * Evaluate a text filter condition against a cell value.
1656
1478
  */
1657
- declare function createDataSourceFromArray<TData extends Row = Row>(data: TData[]): DataSource<TData>;
1658
- //#endregion
1659
- //#region src/data-source/server-data-source.d.ts
1660
- type ServerFetchFunction<TData> = (request: DataSourceRequest) => Promise<DataSourceResponse<TData>>;
1479
+ declare function evaluateTextCondition(cellValue: CellValue, condition: TextFilterCondition): boolean;
1661
1480
  /**
1662
- * Creates a server-side data source that delegates all operations to the server.
1663
- * The fetch function receives sort/filter/pagination params to pass to the API.
1481
+ * Evaluate a number filter condition against a cell value.
1664
1482
  */
1665
- declare function createServerDataSource<TData extends Row = Row>(fetchFn: ServerFetchFunction<TData>): DataSource<TData>;
1483
+ declare function evaluateNumberCondition(cellValue: CellValue, condition: NumberFilterCondition): boolean;
1484
+ /**
1485
+ * Evaluate a date filter condition against a cell value.
1486
+ */
1487
+ declare function evaluateDateCondition(cellValue: CellValue, condition: DateFilterCondition): boolean;
1488
+ /**
1489
+ * Evaluate a column filter model against a cell value.
1490
+ * Uses left-to-right evaluation with per-condition operators.
1491
+ */
1492
+ declare function evaluateColumnFilter(cellValue: CellValue, filter: ColumnFilterModel): boolean;
1493
+ /**
1494
+ * Check if a row passes all filters in a filter model.
1495
+ */
1496
+ declare function rowPassesFilter<TData extends Row>(row: TData, filterModel: FilterModel, getFieldValue: (row: TData, field: string) => CellValue): boolean;
1666
1497
  //#endregion
1667
- //#region src/indexed-data-store/indexed-data-store.d.ts
1668
- interface IndexedDataStoreOptions<TData> {
1669
- /** Function to extract unique ID from row. Required for mutations. */
1670
- getRowId: (row: TData) => RowId;
1671
- /** Custom field accessor for nested properties */
1672
- getFieldValue?: (row: TData, field: string) => CellValue;
1498
+ //#region src/managers/transaction-manager.d.ts
1499
+ interface AddTransaction<TData> {
1500
+ type: "ADD";
1501
+ rows: TData[];
1673
1502
  }
1674
- /** Hash cache for a single row */
1675
- interface RowSortCache {
1676
- /** Map: sortModelHash -> computed hashes for that sort configuration */
1677
- hashes: Map<string, number[]>;
1503
+ interface RemoveTransaction {
1504
+ type: "REMOVE";
1505
+ rowIds: RowId[];
1506
+ }
1507
+ interface UpdateCellTransaction {
1508
+ type: "UPDATE_CELL";
1509
+ rowId: RowId;
1510
+ field: string;
1511
+ value: CellValue;
1512
+ }
1513
+ interface UpdateRowTransaction<TData> {
1514
+ type: "UPDATE_ROW";
1515
+ rowId: RowId;
1516
+ data: Partial<TData>;
1517
+ }
1518
+ type Transaction<TData> = AddTransaction<TData> | RemoveTransaction | UpdateCellTransaction | UpdateRowTransaction<TData>;
1519
+ interface TransactionResult {
1520
+ added: number;
1521
+ removed: number;
1522
+ updated: number;
1523
+ }
1524
+ interface TransactionManagerOptions<TData extends Row> {
1525
+ /** Debounce time in milliseconds. Default 50. Set to 0 for sync. */
1526
+ debounceMs: number;
1527
+ /** The indexed data store to apply transactions to */
1528
+ store: IndexedDataStore<TData>;
1529
+ /** Callback when transactions are processed */
1530
+ onProcessed?: (result: TransactionResult) => void;
1678
1531
  }
1679
1532
  /**
1680
- * Efficient data structure for incremental operations on grid data.
1681
- * Supports:
1682
- * - O(1) lookup by row ID
1683
- * - O(log n) binary insertion to maintain sort order
1684
- * - Filter state caching with distinct values
1685
- * - Hash caching for fast sorted comparisons
1533
+ * Manages a queue of data mutations with debounced batch processing.
1534
+ * Supports ADD, REMOVE, UPDATE_CELL, and UPDATE_ROW operations.
1686
1535
  */
1687
- declare class IndexedDataStore<TData extends Row = Row> {
1688
- private rows;
1689
- private rowById;
1690
- private sortedIndices;
1691
- private sortModel;
1692
- private sortModelHash;
1693
- private filterModel;
1694
- private filteredIndices;
1695
- private distinctValues;
1696
- private rowSortCache;
1536
+ declare class TransactionManager<TData extends Row = Row> {
1537
+ private queue;
1538
+ private debounceTimer;
1539
+ private pendingPromise;
1697
1540
  private options;
1698
- constructor(initialData: TData[] | undefined, options: IndexedDataStoreOptions<TData>);
1541
+ constructor(options: TransactionManagerOptions<TData>);
1699
1542
  /**
1700
- * Clear all data and internal caches.
1701
- * Used for proper memory cleanup when the store is no longer needed.
1543
+ * Queue rows to be added.
1702
1544
  */
1703
- clear(): void;
1545
+ add(rows: TData[]): void;
1704
1546
  /**
1705
- * Replace all data (used for initial load or full refresh).
1547
+ * Queue rows to be removed by ID.
1706
1548
  */
1707
- setData(data: TData[]): void;
1549
+ remove(rowIds: RowId[]): void;
1708
1550
  /**
1709
- * Query data with sorting, filtering, and pagination.
1710
- * Compatible with DataSource.fetch() interface.
1551
+ * Queue a cell update.
1711
1552
  */
1712
- query(request: DataSourceRequest): DataSourceResponse<TData>;
1553
+ updateCell(rowId: RowId, field: string, value: CellValue): void;
1713
1554
  /**
1714
- * Get row by ID.
1555
+ * Queue a row update (multiple fields).
1715
1556
  */
1716
- getRowById(id: RowId): TData | undefined;
1557
+ updateRow(rowId: RowId, data: Partial<TData>): void;
1717
1558
  /**
1718
- * Get row by index.
1559
+ * Force immediate processing of queued transactions.
1560
+ * Returns a promise that resolves when processing is complete.
1719
1561
  */
1720
- getRowByIndex(index: number): TData | undefined;
1562
+ flush(): Promise<void>;
1721
1563
  /**
1722
- * Get total row count (unfiltered).
1564
+ * Check if there are pending transactions.
1723
1565
  */
1724
- getTotalRowCount(): number;
1566
+ hasPending(): boolean;
1725
1567
  /**
1726
- * Get all rows as a new array.
1727
- * Used for direct data access when bypassing store's query system.
1568
+ * Get count of pending transactions.
1728
1569
  */
1729
- getAllRows(): TData[];
1570
+ getPendingCount(): number;
1730
1571
  /**
1731
- * Get visible row count (after filtering).
1572
+ * Clear all pending transactions without processing.
1732
1573
  */
1733
- getVisibleRowCount(): number;
1574
+ clear(): void;
1734
1575
  /**
1735
- * Get distinct values for a field (for filter UI).
1576
+ * Schedule processing after throttle delay.
1577
+ * Uses throttle pattern: if a timer is already pending, new transactions
1578
+ * are added to the queue but don't reset the timer. This ensures updates
1579
+ * are processed even when they arrive faster than the throttle interval.
1736
1580
  */
1737
- getDistinctValues(field: string): CellValue[];
1581
+ private scheduleProcessing;
1738
1582
  /**
1739
- * Add rows to the store.
1740
- * Rows are inserted at their correct sorted position.
1583
+ * Process all queued transactions.
1741
1584
  */
1742
- addRows(rows: TData[]): void;
1585
+ private processQueue;
1586
+ }
1587
+ //#endregion
1588
+ //#region src/grid-core.d.ts
1589
+ declare class GridCore<TData extends Row = Row> {
1590
+ private columns;
1591
+ private dataSource;
1592
+ private rowHeight;
1593
+ private headerHeight;
1594
+ private overscan;
1595
+ private sortingEnabled;
1596
+ private getRowId?;
1597
+ private onCellValueChanged?;
1598
+ private rowDragEntireRow;
1599
+ private onRowDragEnd?;
1600
+ private onColumnResized?;
1601
+ private onColumnMoved?;
1602
+ private scrollTop;
1603
+ private scrollLeft;
1604
+ private viewportWidth;
1605
+ private viewportHeight;
1606
+ private currentPageIndex;
1607
+ private pageSize;
1608
+ private cachedRows;
1609
+ private totalRows;
1610
+ readonly selection: SelectionManager;
1611
+ readonly fill: FillManager;
1612
+ readonly input: InputHandler<TData>;
1613
+ readonly highlight: HighlightManager<TData> | null;
1614
+ readonly sortFilter: SortFilterManager<TData>;
1615
+ readonly rowMutation: RowMutationManager<TData>;
1616
+ private readonly slotPool;
1617
+ private readonly editManager;
1618
+ private columnPositions;
1619
+ private batchListeners;
1620
+ private instructionBuffer;
1621
+ private readonly scrollVirtualization;
1622
+ private isDestroyed;
1623
+ private _isDataLoading;
1624
+ constructor(options: GridCoreOptions<TData>);
1743
1625
  /**
1744
- * Add a single row.
1626
+ * Subscribe to batched instructions for efficient React/Vue state updates.
1627
+ * Batch listeners receive arrays of instructions instead of individual ones.
1745
1628
  */
1746
- private addRow;
1629
+ onBatchInstruction(listener: BatchInstructionListener): () => void;
1747
1630
  /**
1748
- * Remove rows by ID.
1631
+ * Start buffering instructions. All emit/emitBatch calls will accumulate
1632
+ * into an internal buffer until flushBatch() is called.
1749
1633
  */
1750
- removeRows(ids: RowId[]): void;
1634
+ private startBatch;
1751
1635
  /**
1752
- * Remove a single row by index.
1636
+ * Flush buffered instructions to listeners as a single batch, then
1637
+ * stop buffering.
1753
1638
  */
1754
- private removeRowByIndex;
1639
+ private flushBatch;
1640
+ private emit;
1641
+ private emitBatch;
1755
1642
  /**
1756
- * Update indices after a row removal.
1643
+ * Initialize the grid and load initial data.
1757
1644
  */
1758
- private reindexAfterRemoval;
1645
+ initialize(): Promise<void>;
1759
1646
  /**
1760
- * Update a cell value.
1647
+ * Update viewport measurements and sync slots.
1648
+ * When scroll virtualization is active, maps the DOM scroll position to the actual row position.
1761
1649
  */
1762
- updateCell(id: RowId, field: string, value: CellValue): void;
1650
+ setViewport(scrollTop: number, scrollLeft: number, width: number, height: number): void;
1651
+ private fetchData;
1652
+ setSort(colId: string, direction: SortDirection | null, addToExisting?: boolean): Promise<void>;
1653
+ setFilter(colId: string, filter: ColumnFilterModel | string | null): Promise<void>;
1654
+ hasActiveFilter(colId: string): boolean;
1655
+ getDistinctValuesForColumn(colId: string, maxValues?: number): CellValue[];
1656
+ openFilterPopup(colIndex: number, anchorRect: {
1657
+ top: number;
1658
+ left: number;
1659
+ width: number;
1660
+ height: number;
1661
+ }): void;
1662
+ closeFilterPopup(): void;
1663
+ getSortModel(): SortModel[];
1664
+ getFilterModel(): FilterModel;
1665
+ startEdit(row: number, col: number): void;
1666
+ updateEditValue(value: CellValue): void;
1667
+ commitEdit(): void;
1668
+ cancelEdit(): void;
1669
+ getEditState(): EditState | null;
1670
+ getCellValue(row: number, col: number): CellValue;
1671
+ setCellValue(row: number, col: number, value: CellValue): void;
1672
+ private clearSelectionIfInvalid;
1673
+ private computeColumnPositions;
1674
+ private emitContentSize;
1675
+ private emitHeaders;
1763
1676
  /**
1764
- * Update multiple fields on a row.
1677
+ * Set the width of a column and recompute layout.
1765
1678
  */
1766
- updateRow(id: RowId, data: Partial<TData>): void;
1679
+ setColumnWidth(colIndex: number, width: number): void;
1767
1680
  /**
1768
- * Set the sort model. Triggers full re-sort if model changed.
1681
+ * Move a column from one index to another and recompute layout.
1769
1682
  */
1770
- setSortModel(model: SortModel[]): void;
1683
+ moveColumn(fromIndex: number, toIndex: number): void;
1771
1684
  /**
1772
- * Get current sort model.
1685
+ * Commit a row drag operation. Reorders data if the data source supports it,
1686
+ * then invokes the onRowDragEnd callback.
1687
+ *
1688
+ * Optimized: instead of a full refresh (fetchData + rebuild all slots), we
1689
+ * update the cachedRows map in-place to mirror the splice the data source
1690
+ * performed, then only update the affected slots.
1773
1691
  */
1774
- getSortModel(): SortModel[];
1692
+ commitRowDrag(sourceIndex: number, targetIndex: number): void;
1775
1693
  /**
1776
- * Set the filter model.
1694
+ * Whether the entire row is draggable.
1777
1695
  */
1778
- setFilterModel(model: FilterModel): void;
1696
+ isRowDragEntireRow(): boolean;
1697
+ getColumns(): ColumnDefinition[];
1698
+ getColumnPositions(): number[];
1699
+ getRowCount(): number;
1700
+ getRowHeight(): number;
1701
+ getHeaderHeight(): number;
1702
+ getTotalWidth(): number;
1703
+ getTotalHeight(): number;
1704
+ isScalingActive(): boolean;
1705
+ getNaturalHeight(): number;
1706
+ getScrollRatio(): number;
1707
+ getVisibleRowRange(): {
1708
+ start: number;
1709
+ end: number;
1710
+ };
1711
+ getScrollTopForRow(rowIndex: number): number;
1712
+ getRowIndexAtDisplayY(viewportY: number, virtualScrollTop: number): number;
1779
1713
  /**
1780
- * Get current filter model.
1714
+ * Get the translateY position for a row inside the rows wrapper.
1715
+ * Accounts for scroll virtualization (compressed coordinates).
1781
1716
  */
1782
- getFilterModel(): FilterModel;
1717
+ getRowTranslateY(rowIndex: number): number;
1718
+ getRowData(rowIndex: number): TData | undefined;
1783
1719
  /**
1784
- * Rebuild sorted indices (full re-sort).
1720
+ * Refresh data from the data source.
1785
1721
  */
1786
- private rebuildSortedIndices;
1722
+ refresh(): Promise<void>;
1787
1723
  /**
1788
- * Rebuild hash cache for all rows.
1724
+ * Fast-path refresh for transaction-based mutations.
1725
+ * Only re-fetches the visible window instead of all rows.
1726
+ * Use this when data was mutated via MutableDataSource transactions.
1789
1727
  */
1790
- private rebuildHashCache;
1728
+ refreshFromTransaction(): Promise<void>;
1791
1729
  /**
1792
- * Compute and cache sort hashes for a row.
1730
+ * Refresh slot display without refetching data.
1731
+ * Useful after in-place data modifications like fill operations.
1793
1732
  */
1794
- private computeRowHashes;
1733
+ refreshSlotData(): void;
1795
1734
  /**
1796
- * Compare two rows using cached hashes.
1735
+ * Add rows to the grid at the specified index.
1736
+ * If no index is provided, rows are added at the end.
1797
1737
  */
1798
- private compareRows;
1738
+ addRows(rows: TData[], index?: number): void;
1799
1739
  /**
1800
- * Binary search for insertion position in sortedIndices.
1740
+ * Update existing rows with partial data.
1801
1741
  */
1802
- private binarySearchInsertPosition;
1742
+ updateRows(updates: Array<{
1743
+ index: number;
1744
+ data: Partial<TData>;
1745
+ }>): void;
1803
1746
  /**
1804
- * Rebuild filtered indices.
1747
+ * Delete rows at the specified indices.
1805
1748
  */
1806
- private rebuildFilteredIndices;
1749
+ deleteRows(indices: number[]): void;
1807
1750
  /**
1808
- * Check if a row passes the current filter.
1751
+ * Get a row by index.
1809
1752
  */
1810
- private rowPassesFilter;
1753
+ getRow(index: number): TData | undefined;
1811
1754
  /**
1812
- * Get visible indices (filtered + sorted).
1755
+ * Set a complete row at the specified index.
1756
+ * Use this for complete row replacement. For partial updates, use updateRows.
1813
1757
  */
1814
- private getVisibleIndices;
1758
+ setRow(index: number, data: TData): void;
1815
1759
  /**
1816
- * Rebuild distinct values cache for all fields.
1760
+ * Update the data source and refresh.
1761
+ * Preserves grid state (sort, filter, scroll position).
1762
+ * Cancels any active edit and clamps selection to valid range.
1817
1763
  */
1818
- private rebuildDistinctValues;
1764
+ setDataSource(dataSource: DataSource<TData>): Promise<void>;
1819
1765
  /**
1820
- * Update distinct values when a row is added or removed.
1766
+ * Update columns and recompute layout.
1821
1767
  */
1822
- private updateDistinctValuesForRow;
1768
+ setColumns(columns: ColumnDefinition[]): void;
1823
1769
  /**
1824
- * Update distinct value for a specific field when cell value changes.
1770
+ * Destroy the grid core and release all references.
1771
+ * Call this before discarding the GridCore to ensure proper cleanup.
1772
+ * This method is idempotent - safe to call multiple times.
1825
1773
  */
1826
- private updateDistinctValueForField;
1774
+ destroy(): void;
1827
1775
  }
1828
1776
  //#endregion
1829
- //#region src/indexed-data-store/field-helpers.d.ts
1777
+ //#region src/utils/positioning.d.ts
1830
1778
  /**
1831
- * Default field value accessor supporting dot notation.
1832
- * @example
1833
- * getFieldValue({ user: { name: "John" } }, "user.name") // "John"
1779
+ * Calculate cumulative column positions (prefix sums)
1780
+ * Returns an array where positions[i] is the left position of column i
1781
+ * positions[columns.length] is the total width
1834
1782
  */
1835
- declare function getFieldValue<TData extends Row>(row: TData, field: string): CellValue;
1783
+ declare const calculateColumnPositions: (columns: ColumnDefinition[]) => number[];
1836
1784
  /**
1837
- * Set field value supporting dot notation.
1838
- * Creates nested objects if they don't exist.
1839
- * @example
1840
- * const obj = { user: {} };
1841
- * setFieldValue(obj, "user.name", "John");
1842
- * // obj is now { user: { name: "John" } }
1785
+ * Get total width from column positions
1843
1786
  */
1844
- declare function setFieldValue<TData extends Row>(row: TData, field: string, value: CellValue): void;
1845
- //#endregion
1846
- //#region src/indexed-data-store/sorting.d.ts
1787
+ declare const getTotalWidth: (columnPositions: number[]) => number;
1847
1788
  /**
1848
- * Convert a string to a sortable number using first 10 characters.
1849
- * Uses base-36 encoding (a-z = 0-25, 0-9 = 26-35).
1789
+ * Calculate scaled column positions when container is wider than total column widths.
1790
+ * Columns expand proportionally based on their original width ratios.
1791
+ *
1792
+ * @param columns - Column definitions with original widths
1793
+ * @param containerWidth - Available container width
1794
+ * @returns Object with positions array and widths array
1850
1795
  */
1851
- declare function stringToSortableNumber(str: string): number;
1796
+ declare const calculateScaledColumnPositions: (columns: ColumnDefinition[], containerWidth: number) => {
1797
+ positions: number[];
1798
+ widths: number[];
1799
+ };
1852
1800
  /**
1853
- * Compare two cell values for sorting.
1854
- * Handles null/undefined, arrays, numbers, dates, and strings.
1801
+ * Find column index at a given X coordinate
1855
1802
  */
1856
- declare function compareValues(a: CellValue, b: CellValue): number;
1803
+ declare const findColumnAtX: (x: number, columnPositions: number[]) => number;
1804
+ //#endregion
1805
+ //#region src/utils/classNames.d.ts
1857
1806
  /**
1858
- * Compute a sortable hash for a cell value.
1859
- * Used for fast comparisons in sorted indices.
1807
+ * Check if a cell is within the selection range
1860
1808
  */
1861
- declare function computeValueHash(value: CellValue): number;
1862
- //#endregion
1863
- //#region src/filtering/index.d.ts
1809
+ declare const isCellSelected: (row: number, col: number, selectionRange: CellRange | null) => boolean;
1864
1810
  /**
1865
- * Check if two dates are on the same day.
1811
+ * Check if a cell is the active cell
1866
1812
  */
1867
- declare function isSameDay(date1: Date, date2: Date): boolean;
1813
+ declare const isCellActive: (row: number, col: number, activeCell: CellPosition | null) => boolean;
1868
1814
  /**
1869
- * Evaluate a text filter condition against a cell value.
1815
+ * Check if a row is within the visible range (not in overscan)
1870
1816
  */
1871
- declare function evaluateTextCondition(cellValue: CellValue, condition: TextFilterCondition): boolean;
1817
+ declare const isRowVisible: (row: number, visibleRowRange: {
1818
+ start: number;
1819
+ end: number;
1820
+ } | null) => boolean;
1872
1821
  /**
1873
- * Evaluate a number filter condition against a cell value.
1822
+ * Check if a cell is being edited
1874
1823
  */
1875
- declare function evaluateNumberCondition(cellValue: CellValue, condition: NumberFilterCondition): boolean;
1824
+ declare const isCellEditing: (row: number, col: number, editingCell: {
1825
+ row: number;
1826
+ col: number;
1827
+ } | null) => boolean;
1876
1828
  /**
1877
- * Evaluate a date filter condition against a cell value.
1829
+ * Check if a cell is in the fill preview range (vertical-only fill)
1878
1830
  */
1879
- declare function evaluateDateCondition(cellValue: CellValue, condition: DateFilterCondition): boolean;
1831
+ declare const isCellInFillPreview: (row: number, col: number, isDraggingFill: boolean, fillSourceRange: CellRange | null, fillTarget: {
1832
+ row: number;
1833
+ col: number;
1834
+ } | null) => boolean;
1880
1835
  /**
1881
- * Evaluate a column filter model against a cell value.
1882
- * Uses left-to-right evaluation with per-condition operators.
1836
+ * Build cell CSS classes based on state
1883
1837
  */
1884
- declare function evaluateColumnFilter(cellValue: CellValue, filter: ColumnFilterModel): boolean;
1838
+ declare const buildCellClasses: (isActive: boolean, isSelected: boolean, isEditing: boolean, inFillPreview: boolean) => string;
1885
1839
  /**
1886
- * Check if a row passes all filters in a filter model.
1840
+ * Check if a row overlaps the selection range
1887
1841
  */
1888
- declare function rowPassesFilter<TData extends Row>(row: TData, filterModel: FilterModel, getFieldValue: (row: TData, field: string) => CellValue): boolean;
1842
+ declare const isRowInSelectionRange: (rowIndex: number, range: CellRange | null) => boolean;
1843
+ /**
1844
+ * Check if a column overlaps the selection range
1845
+ */
1846
+ declare const isColumnInSelectionRange: (colIndex: number, range: CellRange | null) => boolean;
1889
1847
  //#endregion
1890
- //#region src/transaction-manager.d.ts
1891
- interface AddTransaction<TData> {
1892
- type: "ADD";
1893
- rows: TData[];
1848
+ //#region src/utils/event-emitter.d.ts
1849
+ /**
1850
+ * Batch instruction listener for efficient state updates
1851
+ */
1852
+ type BatchInstructionListener$1 = (instructions: GridInstruction[]) => void;
1853
+ //#endregion
1854
+ //#region src/types/ui-state.d.ts
1855
+ interface SlotData<TData = Row> {
1856
+ slotId: string;
1857
+ rowIndex: number;
1858
+ rowData: TData;
1859
+ translateY: number;
1894
1860
  }
1895
- interface RemoveTransaction {
1896
- type: "REMOVE";
1897
- rowIds: RowId[];
1861
+ interface HeaderData {
1862
+ column: ColumnDefinition;
1863
+ sortDirection?: SortDirection;
1864
+ sortIndex?: number;
1865
+ hasFilter: boolean;
1898
1866
  }
1899
- interface UpdateCellTransaction {
1900
- type: "UPDATE_CELL";
1901
- rowId: RowId;
1902
- field: string;
1903
- value: CellValue;
1867
+ interface FilterPopupState {
1868
+ isOpen: boolean;
1869
+ colIndex: number;
1870
+ column: ColumnDefinition | null;
1871
+ anchorRect: {
1872
+ top: number;
1873
+ left: number;
1874
+ width: number;
1875
+ height: number;
1876
+ } | null;
1877
+ distinctValues: CellValue[];
1878
+ currentFilter?: ColumnFilterModel;
1904
1879
  }
1905
- interface UpdateRowTransaction<TData> {
1906
- type: "UPDATE_ROW";
1907
- rowId: RowId;
1908
- data: Partial<TData>;
1880
+ interface InitialStateArgs {
1881
+ initialWidth?: number;
1882
+ initialHeight?: number;
1909
1883
  }
1910
- type Transaction<TData> = AddTransaction<TData> | RemoveTransaction | UpdateCellTransaction | UpdateRowTransaction<TData>;
1911
- interface TransactionResult {
1912
- added: number;
1913
- removed: number;
1914
- updated: number;
1884
+ declare const createInitialState: <TData = Row>(args?: InitialStateArgs) => GridState<TData>;
1885
+ interface GridState<TData = Row> {
1886
+ slots: Map<string, SlotData<TData>>;
1887
+ activeCell: CellPosition | null;
1888
+ selectionRange: CellRange | null;
1889
+ editingCell: {
1890
+ row: number;
1891
+ col: number;
1892
+ initialValue: CellValue;
1893
+ } | null;
1894
+ contentWidth: number;
1895
+ contentHeight: number;
1896
+ /** Viewport width (container's visible width) for column scaling */
1897
+ viewportWidth: number;
1898
+ /** Viewport height (container's visible height) for loader positioning */
1899
+ viewportHeight: number;
1900
+ /** Y offset for rows wrapper when virtualization is active (keeps row translateY values small) */
1901
+ rowsWrapperOffset: number;
1902
+ headers: Map<number, HeaderData>;
1903
+ filterPopup: FilterPopupState | null;
1904
+ isLoading: boolean;
1905
+ error: string | null;
1906
+ totalRows: number;
1907
+ /** Visible row range (start inclusive, end inclusive). Used to prevent selection showing in overscan. */
1908
+ visibleRowRange: {
1909
+ start: number;
1910
+ end: number;
1911
+ } | null;
1912
+ /** Currently hovered cell position (for highlighting) */
1913
+ hoverPosition: CellPosition | null;
1914
+ /** Columns updated by core (after resize/reorder). Null means use props. */
1915
+ columns: ColumnDefinition[] | null;
1916
+ }
1917
+ //#endregion
1918
+ //#region src/utils/scroll-helpers.d.ts
1919
+ /**
1920
+ * Find the slot for a given row index
1921
+ */
1922
+ declare const findSlotForRow: (slots: Map<string, SlotData>, rowIndex: number) => SlotData | null;
1923
+ /**
1924
+ * Scroll a cell into view if needed
1925
+ */
1926
+ declare const scrollCellIntoView: (core: {
1927
+ getScrollTopForRow(row: number): number;
1928
+ }, container: HTMLDivElement, row: number, rowHeight: number, headerHeight: number, slots: Map<string, SlotData>) => void;
1929
+ //#endregion
1930
+ //#region src/utils/fill-helpers.d.ts
1931
+ interface VisibleColumnInfo {
1932
+ column: ColumnDefinition;
1933
+ originalIndex: number;
1934
+ }
1935
+ interface FillHandlePosition {
1936
+ top: number;
1937
+ left: number;
1938
+ }
1939
+ interface CalculateFillHandlePositionParams {
1940
+ activeCell: CellPosition | null;
1941
+ selectionRange: CellRange | null;
1942
+ slots: Map<string, SlotData>;
1943
+ columns: ColumnDefinition[];
1944
+ visibleColumnsWithIndices: VisibleColumnInfo[];
1945
+ columnPositions: number[];
1946
+ columnWidths: number[];
1947
+ rowHeight: number;
1948
+ }
1949
+ /**
1950
+ * Calculate the fill handle position (bottom-right corner of active cell or selection).
1951
+ * Returns null if no cell is active, columns are not editable, or the target is not visible.
1952
+ */
1953
+ declare const calculateFillHandlePosition: (params: CalculateFillHandlePositionParams) => FillHandlePosition | null;
1954
+ //#endregion
1955
+ //#region src/slot-pool.d.ts
1956
+ interface SlotPoolManagerOptions {
1957
+ /** Get current row height */
1958
+ getRowHeight: () => number;
1959
+ /** Get current header height */
1960
+ getHeaderHeight: () => number;
1961
+ /** Get overscan count */
1962
+ getOverscan: () => number;
1963
+ /** Get current scroll top position (natural, not virtual) */
1964
+ getScrollTop: () => number;
1965
+ /** Get viewport height */
1966
+ getViewportHeight: () => number;
1967
+ /** Get total row count */
1968
+ getTotalRows: () => number;
1969
+ /** Get scroll ratio for virtualization (1 = no virtualization) */
1970
+ getScrollRatio: () => number;
1971
+ /** Get virtual content height */
1972
+ getVirtualContentHeight: () => number;
1973
+ /** Get row data by index */
1974
+ getRowData: (rowIndex: number) => Row | undefined;
1975
+ }
1976
+ /**
1977
+ * Manages the slot pool for virtual scrolling.
1978
+ * Handles slot creation, recycling, positioning, and destruction.
1979
+ */
1980
+ declare class SlotPoolManager {
1981
+ private state;
1982
+ private options;
1983
+ private emitter;
1984
+ private isDestroyed;
1985
+ onInstruction: (listener: InstructionListener) => () => void;
1986
+ onBatchInstruction: (listener: BatchInstructionListener$1) => () => void;
1987
+ private emit;
1988
+ private emitBatch;
1989
+ constructor(options: SlotPoolManagerOptions);
1990
+ /**
1991
+ * Get the slot ID for a given row index.
1992
+ */
1993
+ getSlotForRow(rowIndex: number): string | undefined;
1994
+ /**
1995
+ * Get all current slots.
1996
+ */
1997
+ getSlots(): Map<string, SlotState>;
1998
+ /**
1999
+ * Synchronize slots with current viewport position.
2000
+ * This implements the slot recycling strategy.
2001
+ */
2002
+ syncSlots(): void;
2003
+ /**
2004
+ * Destroy all slots.
2005
+ */
2006
+ destroyAllSlots(): void;
2007
+ /**
2008
+ * Clean up resources for garbage collection.
2009
+ * This method is idempotent - safe to call multiple times.
2010
+ */
2011
+ destroy(): void;
2012
+ /**
2013
+ * Refresh all slot data without changing which rows are displayed.
2014
+ * Used after filtering/sorting when data changes.
2015
+ */
2016
+ refreshAllSlots(): void;
2017
+ /**
2018
+ * Update a single slot's data.
2019
+ */
2020
+ updateSlot(rowIndex: number): void;
2021
+ /**
2022
+ * Calculate the translateY position for a row.
2023
+ * Handles scroll virtualization for very large datasets.
2024
+ *
2025
+ * When virtualization is active (scrollRatio < 1), we use viewport-relative
2026
+ * positioning to keep translateY values small. This prevents browser rendering
2027
+ * issues that occur at extreme pixel values (millions of pixels).
2028
+ *
2029
+ * Note: The header is rendered outside the content sizer, so row positions
2030
+ * start at 0 (not headerHeight) within the rows container.
2031
+ */
2032
+ private getRowTranslateY;
2033
+ /**
2034
+ * Get the translateY position for a row inside the rows wrapper.
2035
+ * Public accessor for use by input handler (e.g., drop indicator positioning).
2036
+ */
2037
+ getRowTranslateYForIndex(rowIndex: number): number;
2038
+ /**
2039
+ * Get the Y offset for the rows wrapper container.
2040
+ * When virtualization is active, this positions the wrapper so rows
2041
+ * with small translateY values appear at the correct scroll position.
2042
+ */
2043
+ getRowsWrapperOffset(): number;
2044
+ }
2045
+ //#endregion
2046
+ //#region src/edit-manager.d.ts
2047
+ interface EditManagerOptions {
2048
+ /** Get column definition by index */
2049
+ getColumn: (colIndex: number) => ColumnDefinition | undefined;
2050
+ /** Get cell value */
2051
+ getCellValue: (row: number, col: number) => CellValue;
2052
+ /** Set cell value */
2053
+ setCellValue: (row: number, col: number, value: CellValue) => void;
2054
+ /** Callback when edit is committed (to update slot display) */
2055
+ onCommit?: (row: number, col: number, value: CellValue) => void;
2056
+ }
2057
+ /**
2058
+ * Manages cell editing state and operations.
2059
+ */
2060
+ declare class EditManager {
2061
+ private editState;
2062
+ private options;
2063
+ private emitter;
2064
+ onInstruction: (listener: InstructionListener) => () => void;
2065
+ private emit;
2066
+ constructor(options: EditManagerOptions);
2067
+ /**
2068
+ * Get the current edit state.
2069
+ */
2070
+ getState(): EditState | null;
2071
+ /**
2072
+ * Check if currently editing.
2073
+ */
2074
+ isEditing(): boolean;
2075
+ /**
2076
+ * Check if a specific cell is being edited.
2077
+ */
2078
+ isEditingCell(row: number, col: number): boolean;
2079
+ /**
2080
+ * Start editing a cell.
2081
+ * Returns true if edit was started, false if cell is not editable.
2082
+ */
2083
+ startEdit(row: number, col: number): boolean;
2084
+ /**
2085
+ * Update the current edit value.
2086
+ */
2087
+ updateValue(value: CellValue): void;
2088
+ /**
2089
+ * Commit the current edit.
2090
+ * Saves the value and closes the editor.
2091
+ */
2092
+ commit(): void;
2093
+ /**
2094
+ * Cancel the current edit.
2095
+ * Discards changes and closes the editor.
2096
+ */
2097
+ cancel(): void;
2098
+ /**
2099
+ * Clean up resources for garbage collection.
2100
+ */
2101
+ destroy(): void;
2102
+ }
2103
+ //#endregion
2104
+ //#region src/sorting/parallel-sort-manager.d.ts
2105
+ interface ParallelSortOptions {
2106
+ /** Maximum number of workers (default: navigator.hardwareConcurrency || 4) */
2107
+ maxWorkers?: number;
2108
+ /** Threshold for parallel sorting (default: 400000) */
2109
+ parallelThreshold?: number;
2110
+ /** Minimum chunk size (default: 50000) */
2111
+ minChunkSize?: number;
2112
+ }
2113
+ /**
2114
+ * Manages parallel sorting operations using a worker pool.
2115
+ * Automatically decides between single-worker and parallel sorting based on data size.
2116
+ */
2117
+ declare class ParallelSortManager {
2118
+ private pool;
2119
+ private parallelThreshold;
2120
+ private minChunkSize;
2121
+ private isTerminated;
2122
+ constructor(options?: ParallelSortOptions);
2123
+ /**
2124
+ * Check if the manager is available for use.
2125
+ */
2126
+ isAvailable(): boolean;
2127
+ /**
2128
+ * Terminate all workers and clean up resources.
2129
+ */
2130
+ terminate(): void;
2131
+ /**
2132
+ * Sort indices using values array.
2133
+ * Automatically uses parallel sorting for large datasets.
2134
+ */
2135
+ sortIndices(values: number[], direction: SortDirection): Promise<Uint32Array>;
2136
+ /**
2137
+ * Sort string hashes with collision detection.
2138
+ * Automatically uses parallel sorting for large datasets.
2139
+ */
2140
+ sortStringHashes(hashChunks: Float64Array[], direction: SortDirection, originalStrings: string[]): Promise<Uint32Array>;
2141
+ /**
2142
+ * Multi-column sort.
2143
+ * Automatically uses parallel sorting for large datasets.
2144
+ */
2145
+ sortMultiColumn(columns: number[][], directions: SortDirection[]): Promise<Uint32Array>;
2146
+ private sortIndicesSingle;
2147
+ private sortStringHashesSingle;
2148
+ private sortMultiColumnSingle;
2149
+ private sortIndicesParallel;
2150
+ private sortStringHashesParallel;
2151
+ private sortMultiColumnParallel;
2152
+ /**
2153
+ * Split data into chunks for parallel processing.
2154
+ */
2155
+ private splitIntoChunks;
2156
+ /**
2157
+ * Calculate chunk boundaries without copying data.
2158
+ */
2159
+ private calculateChunkBoundaries;
2160
+ /**
2161
+ * Detect collisions at chunk boundaries for string sorting.
2162
+ */
2163
+ private detectBoundaryCollisionsForStrings;
2164
+ /**
2165
+ * Resolve hash collisions using localeCompare.
2166
+ */
2167
+ private resolveCollisions;
1915
2168
  }
1916
- interface TransactionManagerOptions<TData extends Row> {
1917
- /** Debounce time in milliseconds. Default 50. Set to 0 for sync. */
1918
- debounceMs: number;
1919
- /** The indexed data store to apply transactions to */
1920
- store: IndexedDataStore<TData>;
1921
- /** Callback when transactions are processed */
1922
- onProcessed?: (result: TransactionResult) => void;
2169
+ //#endregion
2170
+ //#region src/sorting/worker-pool.d.ts
2171
+ interface WorkerPoolOptions {
2172
+ /** Maximum number of workers (default: navigator.hardwareConcurrency ?? 4) */
2173
+ maxWorkers?: number;
2174
+ /** Whether to pre-warm workers on initialization */
2175
+ preWarm?: boolean;
1923
2176
  }
1924
2177
  /**
1925
- * Manages a queue of data mutations with debounced batch processing.
1926
- * Supports ADD, REMOVE, UPDATE_CELL, and UPDATE_ROW operations.
2178
+ * Manages a pool of Web Workers for parallel task execution.
2179
+ * Workers are created lazily and reused across operations.
1927
2180
  */
1928
- declare class TransactionManager<TData extends Row = Row> {
1929
- private queue;
1930
- private debounceTimer;
1931
- private pendingPromise;
1932
- private options;
1933
- constructor(options: TransactionManagerOptions<TData>);
2181
+ declare class WorkerPool {
2182
+ private workerCode;
2183
+ private maxWorkers;
2184
+ private workers;
2185
+ private workerUrl;
2186
+ private nextRequestId;
2187
+ private isTerminated;
2188
+ constructor(workerCode: string, options?: WorkerPoolOptions);
1934
2189
  /**
1935
- * Queue rows to be added.
2190
+ * Get the current pool size (number of active workers).
1936
2191
  */
1937
- add(rows: TData[]): void;
2192
+ getPoolSize(): number;
1938
2193
  /**
1939
- * Queue rows to be removed by ID.
2194
+ * Get the maximum pool size.
1940
2195
  */
1941
- remove(rowIds: RowId[]): void;
2196
+ getMaxWorkers(): number;
1942
2197
  /**
1943
- * Queue a cell update.
2198
+ * Check if the pool is available for use.
1944
2199
  */
1945
- updateCell(rowId: RowId, field: string, value: CellValue): void;
2200
+ isAvailable(): boolean;
1946
2201
  /**
1947
- * Queue a row update (multiple fields).
2202
+ * Execute a single task on an available worker.
2203
+ * Returns the worker's response.
1948
2204
  */
1949
- updateRow(rowId: RowId, data: Partial<TData>): void;
2205
+ execute<TRequest extends {
2206
+ id?: number;
2207
+ }, TResponse>(request: TRequest, transferables?: Transferable[]): Promise<TResponse>;
1950
2208
  /**
1951
- * Force immediate processing of queued transactions.
1952
- * Returns a promise that resolves when processing is complete.
2209
+ * Execute multiple tasks in parallel across available workers.
2210
+ * Each task is assigned to a different worker if possible.
2211
+ * Returns results in the same order as the input requests.
1953
2212
  */
1954
- flush(): Promise<void>;
2213
+ executeParallel<TRequest extends {
2214
+ id?: number;
2215
+ }, TResponse>(tasks: Array<{
2216
+ request: TRequest;
2217
+ transferables?: Transferable[];
2218
+ }>): Promise<TResponse[]>;
1955
2219
  /**
1956
- * Check if there are pending transactions.
2220
+ * Terminate all workers and clean up resources.
1957
2221
  */
1958
- hasPending(): boolean;
2222
+ terminate(): void;
1959
2223
  /**
1960
- * Get count of pending transactions.
2224
+ * Pre-warm workers by creating them ahead of time.
1961
2225
  */
1962
- getPendingCount(): number;
2226
+ private preWarmWorkers;
1963
2227
  /**
1964
- * Clear all pending transactions without processing.
2228
+ * Ensure at least `count` workers exist in the pool.
1965
2229
  */
1966
- clear(): void;
2230
+ private ensureWorkers;
1967
2231
  /**
1968
- * Schedule processing after throttle delay.
1969
- * Uses throttle pattern: if a timer is already pending, new transactions
1970
- * are added to the queue but don't reset the timer. This ensures updates
1971
- * are processed even when they arrive faster than the throttle interval.
2232
+ * Get an available worker, creating one if needed.
1972
2233
  */
1973
- private scheduleProcessing;
2234
+ private getAvailableWorker;
1974
2235
  /**
1975
- * Process all queued transactions.
2236
+ * Create a new worker and add it to the pool.
1976
2237
  */
1977
- private processQueue;
2238
+ private createWorker;
2239
+ /**
2240
+ * Respawn a failed worker.
2241
+ */
2242
+ private respawnWorker;
2243
+ }
2244
+ //#endregion
2245
+ //#region src/sorting/k-way-merge.d.ts
2246
+ /**
2247
+ * Represents a sorted chunk with its values and offset in the original array.
2248
+ */
2249
+ interface SortedChunk {
2250
+ /** Sorted indices (local to this chunk) */
2251
+ indices: Uint32Array;
2252
+ /** Values for comparison (in same order as indices) */
2253
+ values: Float64Array;
2254
+ /** Offset of this chunk in the original array */
2255
+ offset: number;
2256
+ }
2257
+ /**
2258
+ * Represents a sorted chunk for multi-column sorting.
2259
+ */
2260
+ interface MultiColumnSortedChunk {
2261
+ /** Sorted indices (local to this chunk) */
2262
+ indices: Uint32Array;
2263
+ /** Values for comparison - array of columns, each in same order as indices */
2264
+ columns: Float64Array[];
2265
+ /** Sort directions for each column (1 = asc, -1 = desc) */
2266
+ directions: Int8Array;
2267
+ /** Offset of this chunk in the original array */
2268
+ offset: number;
2269
+ }
2270
+ /**
2271
+ * Merge multiple sorted chunks into a single sorted result.
2272
+ * Uses a min-heap for O(n log k) time complexity.
2273
+ *
2274
+ * @param chunks - Array of sorted chunks to merge
2275
+ * @param direction - Sort direction ('asc' or 'desc')
2276
+ * @returns Uint32Array of globally sorted indices
2277
+ */
2278
+ declare function kWayMerge(chunks: SortedChunk[], direction: SortDirection): Uint32Array;
2279
+ /**
2280
+ * Merge multiple sorted chunks for multi-column sorting.
2281
+ *
2282
+ * @param chunks - Array of multi-column sorted chunks
2283
+ * @returns Uint32Array of globally sorted indices
2284
+ */
2285
+ declare function kWayMergeMultiColumn(chunks: MultiColumnSortedChunk[]): Uint32Array;
2286
+ /**
2287
+ * Detect collision runs at chunk boundaries after merge.
2288
+ * This is used for string sorting where hashes may collide across chunks.
2289
+ *
2290
+ * @param chunks - Original sorted chunks with their hash values
2291
+ * @param _direction - Sort direction
2292
+ * @returns Array of boundary collision positions [start1, end1, start2, end2, ...]
2293
+ */
2294
+ declare function detectBoundaryCollisions(chunks: SortedChunk[], _direction: SortDirection): Uint32Array;
2295
+ //#endregion
2296
+ //#region src/data-source/client-data-source.d.ts
2297
+ interface ClientDataSourceOptions<TData> {
2298
+ /** Custom field accessor for nested properties */
2299
+ getFieldValue?: (row: TData, field: string) => CellValue;
2300
+ /** Use Web Worker for sorting large datasets (default: true) */
2301
+ useWorker?: boolean;
2302
+ /** Options for parallel sorting (only used when useWorker is true) */
2303
+ parallelSort?: ParallelSortOptions | false;
1978
2304
  }
2305
+ /**
2306
+ * Creates a client-side data source that holds all data in memory.
2307
+ * Sorting and filtering are performed client-side.
2308
+ * For large datasets, sorting is automatically offloaded to a Web Worker.
2309
+ */
2310
+ declare function createClientDataSource<TData extends Row = Row>(data: TData[], options?: ClientDataSourceOptions<TData>): DataSource<TData>;
2311
+ /**
2312
+ * Convenience function to create a data source from an array.
2313
+ * This provides backwards compatibility with the old `rowData` prop.
2314
+ */
2315
+ declare function createDataSourceFromArray<TData extends Row = Row>(data: TData[]): DataSource<TData>;
2316
+ //#endregion
2317
+ //#region src/data-source/server-data-source.d.ts
2318
+ type ServerFetchFunction<TData> = (request: DataSourceRequest) => Promise<DataSourceResponse<TData>>;
2319
+ /**
2320
+ * Creates a server-side data source that delegates all operations to the server.
2321
+ * The fetch function receives sort/filter/pagination params to pass to the API.
2322
+ */
2323
+ declare function createServerDataSource<TData extends Row = Row>(fetchFn: ServerFetchFunction<TData>): DataSource<TData>;
1979
2324
  //#endregion
1980
2325
  //#region src/data-source/mutable-data-source.d.ts
1981
2326
  /** Callback for data change notifications */
@@ -2007,6 +2352,8 @@ interface MutableDataSource<TData = Row> extends DataSource<TData> {
2007
2352
  subscribe(listener: DataChangeListener): () => void;
2008
2353
  /** Clear all data from the data source. */
2009
2354
  clear(): void;
2355
+ /** Move a row from one display position to another. */
2356
+ moveRow(fromIndex: number, toIndex: number): void;
2010
2357
  }
2011
2358
  interface MutableClientDataSourceOptions<TData> {
2012
2359
  /** Function to extract unique ID from row. Required. */
@@ -2050,6 +2397,9 @@ declare const scrollbarStyles: string;
2050
2397
  //#region src/styles/filters.d.ts
2051
2398
  declare const filtersStyles: string;
2052
2399
  //#endregion
2400
+ //#region src/styles/row-drag.d.ts
2401
+ declare const rowDragStyles: string;
2402
+ //#endregion
2053
2403
  //#region src/styles/index.d.ts
2054
2404
  /**
2055
2405
  * Combined grid styles from all modules
@@ -2062,63 +2412,13 @@ declare const gridStyles: string;
2062
2412
  */
2063
2413
  declare function injectStyles(): void;
2064
2414
  //#endregion
2065
- //#region src/types/ui-state.d.ts
2066
- interface SlotData<TData = Row> {
2067
- slotId: string;
2068
- rowIndex: number;
2069
- rowData: TData;
2070
- translateY: number;
2071
- }
2072
- interface HeaderData {
2073
- column: ColumnDefinition;
2074
- sortDirection?: SortDirection;
2075
- sortIndex?: number;
2076
- sortable: boolean;
2077
- filterable: boolean;
2078
- hasFilter: boolean;
2079
- }
2080
- interface FilterPopupState {
2081
- isOpen: boolean;
2082
- colIndex: number;
2083
- column: ColumnDefinition | null;
2084
- anchorRect: {
2085
- top: number;
2086
- left: number;
2087
- width: number;
2088
- height: number;
2089
- } | null;
2090
- distinctValues: CellValue[];
2091
- currentFilter?: ColumnFilterModel;
2092
- }
2093
- interface GridState<TData = Row> {
2094
- slots: Map<string, SlotData<TData>>;
2095
- activeCell: CellPosition | null;
2096
- selectionRange: CellRange | null;
2097
- editingCell: {
2098
- row: number;
2099
- col: number;
2100
- initialValue: CellValue;
2101
- } | null;
2102
- contentWidth: number;
2103
- contentHeight: number;
2104
- /** Viewport width (container's visible width) for column scaling */
2105
- viewportWidth: number;
2106
- /** Viewport height (container's visible height) for loader positioning */
2107
- viewportHeight: number;
2108
- /** Y offset for rows wrapper when virtualization is active (keeps row translateY values small) */
2109
- rowsWrapperOffset: number;
2110
- headers: Map<number, HeaderData>;
2111
- filterPopup: FilterPopupState | null;
2112
- isLoading: boolean;
2113
- error: string | null;
2114
- totalRows: number;
2115
- /** Visible row range (start inclusive, end inclusive). Used to prevent selection showing in overscan. */
2116
- visibleRowRange: {
2117
- start: number;
2118
- end: number;
2119
- } | null;
2120
- /** Currently hovered cell position (for highlighting) */
2121
- hoverPosition: CellPosition | null;
2122
- }
2415
+ //#region src/state-reducer.d.ts
2416
+ /**
2417
+ * Apply a single instruction to mutable slot/header Maps and return
2418
+ * other state changes as a partial object.
2419
+ *
2420
+ * Returns `null` when only the Maps were mutated (no primitive field changes).
2421
+ */
2422
+ declare const applyInstruction: <TData = Row>(instruction: GridInstruction, slots: Map<string, SlotData<TData>>, headers: Map<number, HeaderData>) => Partial<GridState<TData>> | null;
2123
2423
  //#endregion
2124
- export { type AssignSlotInstruction, type BatchInstructionListener, type CancelFillInstruction, type CellDataType, type CellPosition, type CellRange, type CellRendererParams, type CellValue, type CellValueChangedEvent, type CloseFilterPopupInstruction, type ColumnDefinition, type ColumnFilterModel, type CommitEditInstruction, type CommitFillInstruction, type ContainerBounds, type CreateSlotInstruction, type DataChangeListener, type DataErrorInstruction, type DataLoadedInstruction, type DataLoadingInstruction, type DataSource, type DataSourceRequest, type DataSourceResponse, type DateFilterCondition, type DateFilterOperator, type DestroySlotInstruction, type Direction, type DragMoveResult, type DragState, EditManager, type EditManagerOptions, type EditRendererParams, type EditState, type FillHandleState, FillManager, type FilterCombination, type FilterCondition, type FilterModel, type FilterPopupState, GridCore, type GridCoreOptions, type GridInstruction, type GridState, type HeaderData, type HeaderRendererParams, type HighlightContext, HighlightManager, type HighlightingOptions, IndexedDataStore, type IndexedDataStoreOptions, InputHandler, type InputHandlerDeps, type InputResult, type InstructionListener, type KeyEventData, type KeyboardResult, type MoveSlotInstruction, type MultiColumnSortedChunk, type MutableClientDataSourceOptions, type MutableDataSource, type NumberFilterCondition, type NumberFilterOperator, type OpenFilterPopupInstruction, ParallelSortManager, type ParallelSortOptions, type PointerEventData, type Row, type RowId, type RowSortCache, type RowsAddedInstruction, type RowsRemovedInstruction, type RowsUpdatedInstruction, SelectionManager, type SelectionState, type SetActiveCellInstruction, type SetContentSizeInstruction, type SetHoverPositionInstruction, type SetSelectionRangeInstruction, type SlotData, type BatchInstructionListener$1 as SlotPoolBatchListener, SlotPoolManager, type SlotPoolManagerOptions, type SlotState, type SortDirection, type SortModel, type SortedChunk, type StartEditInstruction, type StartFillInstruction, type StopEditInstruction, type TextFilterCondition, type TextFilterOperator, type Transaction, TransactionManager, type TransactionManagerOptions, type TransactionProcessedInstruction, type TransactionResult, type UpdateFillInstruction, type UpdateHeaderInstruction, WorkerPool, type WorkerPoolOptions, buildCellClasses, calculateColumnPositions, calculateScaledColumnPositions, cellStyles, compareValues, computeValueHash, containerStyles, createClientDataSource, createDataSourceFromArray, createMutableClientDataSource, createServerDataSource, detectBoundaryCollisions, evaluateColumnFilter, evaluateDateCondition, evaluateNumberCondition, evaluateTextCondition, filtersStyles, findColumnAtX, getFieldValue, getTotalWidth, gridStyles, headerStyles, injectStyles, isCellActive, isCellEditing, isCellInFillPreview, isCellSelected, isColumnInSelectionRange, isRowInSelectionRange, isRowVisible, isSameDay, kWayMerge, kWayMergeMultiColumn, rowPassesFilter, scrollbarStyles, setFieldValue, statesStyles, stringToSortableNumber, variablesStyles };
2424
+ export { type AssignSlotInstruction, type BatchInstructionListener, type CalculateFillHandlePositionParams, type CancelColumnMoveInstruction, type CancelColumnResizeInstruction, type CancelFillInstruction, type CancelRowDragInstruction, type CellDataType, type CellPosition, type CellRange, type CellRendererParams, type CellValue, type CellValueChangedEvent, type CloseFilterPopupInstruction, type ColumnDefinition, type ColumnFilterModel, type ColumnMoveDragState, type ColumnResizeDragState, type ColumnsChangedInstruction, type CommitColumnMoveInstruction, type CommitColumnResizeInstruction, type CommitEditInstruction, type CommitFillInstruction, type CommitRowDragInstruction, type ContainerBounds, type CreateSlotInstruction, type DataChangeListener, type DataErrorInstruction, type DataLoadedInstruction, type DataLoadingInstruction, type DataSource, type DataSourceRequest, type DataSourceResponse, type DateFilterCondition, type DateFilterOperator, type DestroySlotInstruction, type Direction, type DragMoveResult, type DragState, EditManager, type EditManagerOptions, type EditRendererParams, type EditState, type FillHandlePosition, type FillHandleState, FillManager, type FilterCombination, type FilterCondition, type FilterModel, type FilterPopupState, GridCore, type GridCoreOptions, type GridInstruction, type GridState, type HeaderData, type HeaderRendererParams, type HighlightContext, HighlightManager, type HighlightingOptions, IndexedDataStore, type IndexedDataStoreOptions, type InitialStateArgs, InputHandler, type InputHandlerDeps, type InputResult, type InstructionListener, type KeyEventData, type KeyboardResult, type MoveSlotInstruction, type MultiColumnSortedChunk, type MutableClientDataSourceOptions, type MutableDataSource, type NumberFilterCondition, type NumberFilterOperator, type OpenFilterPopupInstruction, ParallelSortManager, type ParallelSortOptions, type PointerEventData, type Row, type RowDragState, type RowId, RowMutationManager, type RowMutationManagerOptions, type RowSortCache, type RowsAddedInstruction, type RowsRemovedInstruction, type RowsUpdatedInstruction, ScrollVirtualizationManager, type ScrollVirtualizationManagerOptions, SelectionManager, type SelectionState, type SetActiveCellInstruction, type SetContentSizeInstruction, type SetHoverPositionInstruction, type SetSelectionRangeInstruction, type SlotData, type BatchInstructionListener$1 as SlotPoolBatchListener, SlotPoolManager, type SlotPoolManagerOptions, type SlotState, type SortDirection, SortFilterManager, type SortFilterManagerOptions, type SortModel, type SortedChunk, type StartColumnMoveInstruction, type StartColumnResizeInstruction, type StartEditInstruction, type StartFillInstruction, type StartRowDragInstruction, type StopEditInstruction, type TextFilterCondition, type TextFilterOperator, type Transaction, TransactionManager, type TransactionManagerOptions, type TransactionProcessedInstruction, type TransactionResult, type UpdateColumnMoveInstruction, type UpdateColumnResizeInstruction, type UpdateFillInstruction, type UpdateHeaderInstruction, type UpdateRowDragInstruction, type VisibleColumnInfo, WorkerPool, type WorkerPoolOptions, applyInstruction, buildCellClasses, calculateColumnPositions, calculateFillHandlePosition, calculateScaledColumnPositions, cellStyles, compareValues, computeValueHash, containerStyles, createClientDataSource, createDataSourceFromArray, createInitialState, createMutableClientDataSource, createServerDataSource, detectBoundaryCollisions, evaluateColumnFilter, evaluateDateCondition, evaluateNumberCondition, evaluateTextCondition, filtersStyles, findColumnAtX, findSlotForRow, getFieldValue, getTotalWidth, gridStyles, headerStyles, injectStyles, isCellActive, isCellEditing, isCellInFillPreview, isCellSelected, isColumnInSelectionRange, isRowInSelectionRange, isRowVisible, isSameDay, kWayMerge, kWayMergeMultiColumn, rowDragStyles, rowPassesFilter, scrollCellIntoView, scrollbarStyles, setFieldValue, statesStyles, stringToSortableNumber, variablesStyles };