gp-grid-core 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +458 -136
- package/dist/index.js +41 -36
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -69,6 +69,81 @@ interface SlotState {
|
|
|
69
69
|
translateY: number;
|
|
70
70
|
}
|
|
71
71
|
//#endregion
|
|
72
|
+
//#region src/types/highlighting.d.ts
|
|
73
|
+
/**
|
|
74
|
+
* Minimal column info for highlighting context.
|
|
75
|
+
* Uses structural typing to avoid circular dependency with columns.ts.
|
|
76
|
+
*/
|
|
77
|
+
interface HighlightColumnInfo {
|
|
78
|
+
field: string;
|
|
79
|
+
colId?: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Unified context for row, column, and cell highlighting.
|
|
83
|
+
*
|
|
84
|
+
* - Row context: `rowIndex` is set, `colIndex` is null
|
|
85
|
+
* - Column context: `colIndex` is set, `rowIndex` is null
|
|
86
|
+
* - Cell context: both `rowIndex` and `colIndex` are set
|
|
87
|
+
*/
|
|
88
|
+
interface HighlightContext<TData = Record<string, unknown>> {
|
|
89
|
+
/** Row index. Null for column-only context. */
|
|
90
|
+
rowIndex: number | null;
|
|
91
|
+
/** Column index. Null for row-only context. */
|
|
92
|
+
colIndex: number | null;
|
|
93
|
+
/** Column definition. Present for column and cell contexts. */
|
|
94
|
+
column?: HighlightColumnInfo;
|
|
95
|
+
/** Row data. Present for row and cell contexts. */
|
|
96
|
+
rowData?: TData;
|
|
97
|
+
/** Currently hovered cell position, null if not hovering */
|
|
98
|
+
hoverPosition: CellPosition | null;
|
|
99
|
+
/** Currently active (focused) cell position */
|
|
100
|
+
activeCell: CellPosition | null;
|
|
101
|
+
/** Current selection range */
|
|
102
|
+
selectionRange: CellRange | null;
|
|
103
|
+
/** Whether this row/column/cell is hovered (respects hoverScope) */
|
|
104
|
+
isHovered: boolean;
|
|
105
|
+
/** Whether this row/column contains or is the active cell */
|
|
106
|
+
isActive: boolean;
|
|
107
|
+
/** Whether this row/column/cell overlaps or is in the selection range */
|
|
108
|
+
isSelected: boolean;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Grid-level highlighting options.
|
|
112
|
+
* Hover tracking is automatically enabled when any highlighting callback is defined.
|
|
113
|
+
* Each callback type has its own natural interpretation of `isHovered`:
|
|
114
|
+
* - computeRowClasses: isHovered = mouse is on any cell in this row
|
|
115
|
+
* - computeColumnClasses: isHovered = mouse is on any cell in this column
|
|
116
|
+
* - computeCellClasses: isHovered = mouse is on this exact cell
|
|
117
|
+
*
|
|
118
|
+
* For a crosshair effect, implement both computeRowClasses and computeColumnClasses.
|
|
119
|
+
*/
|
|
120
|
+
interface HighlightingOptions<TData = Record<string, unknown>> {
|
|
121
|
+
/**
|
|
122
|
+
* Row-level class callback.
|
|
123
|
+
* Classes returned are applied to the row container element.
|
|
124
|
+
* Context has `rowIndex` set, `colIndex` is null.
|
|
125
|
+
* `isHovered` is true when the mouse is on any cell in this row.
|
|
126
|
+
* @returns Array of CSS class names
|
|
127
|
+
*/
|
|
128
|
+
computeRowClasses?: (context: HighlightContext<TData>) => string[];
|
|
129
|
+
/**
|
|
130
|
+
* Column-level class callback.
|
|
131
|
+
* Classes returned are applied to all cells in that column (not header).
|
|
132
|
+
* Context has `colIndex` set, `rowIndex` is null.
|
|
133
|
+
* `isHovered` is true when the mouse is on any cell in this column.
|
|
134
|
+
* @returns Array of CSS class names
|
|
135
|
+
*/
|
|
136
|
+
computeColumnClasses?: (context: HighlightContext<TData>) => string[];
|
|
137
|
+
/**
|
|
138
|
+
* Cell-level class callback.
|
|
139
|
+
* Classes returned are applied to individual cells for fine-grained control.
|
|
140
|
+
* Context has both `rowIndex` and `colIndex` set.
|
|
141
|
+
* `isHovered` is true only when the mouse is on this exact cell.
|
|
142
|
+
* @returns Array of CSS class names
|
|
143
|
+
*/
|
|
144
|
+
computeCellClasses?: (context: HighlightContext<TData>) => string[];
|
|
145
|
+
}
|
|
146
|
+
//#endregion
|
|
72
147
|
//#region src/types/columns.d.ts
|
|
73
148
|
/** Column definition */
|
|
74
149
|
interface ColumnDefinition {
|
|
@@ -82,10 +157,26 @@ interface ColumnDefinition {
|
|
|
82
157
|
sortable?: boolean;
|
|
83
158
|
/** Whether column is filterable. Default: true */
|
|
84
159
|
filterable?: boolean;
|
|
160
|
+
/** Whether column is hidden. Hidden columns are not rendered but still exist in the definition. Default: false */
|
|
161
|
+
hidden?: boolean;
|
|
85
162
|
/** Renderer key for adapter lookup, or inline renderer function */
|
|
86
163
|
cellRenderer?: string;
|
|
87
164
|
editRenderer?: string;
|
|
88
165
|
headerRenderer?: string;
|
|
166
|
+
/**
|
|
167
|
+
* Per-column override for column-level highlighting.
|
|
168
|
+
* If defined, overrides grid-level computeColumnClasses for this column.
|
|
169
|
+
* Context has `colIndex` set, `rowIndex` is null.
|
|
170
|
+
* @returns Array of CSS class names to apply to all cells in this column
|
|
171
|
+
*/
|
|
172
|
+
computeColumnClasses?: (context: HighlightContext) => string[];
|
|
173
|
+
/**
|
|
174
|
+
* Per-column override for cell-level highlighting.
|
|
175
|
+
* If defined, overrides grid-level computeCellClasses for cells in this column.
|
|
176
|
+
* Context has both `rowIndex` and `colIndex` set.
|
|
177
|
+
* @returns Array of CSS class names to apply to individual cells
|
|
178
|
+
*/
|
|
179
|
+
computeCellClasses?: (context: HighlightContext) => string[];
|
|
89
180
|
}
|
|
90
181
|
//#endregion
|
|
91
182
|
//#region src/types/filters.d.ts
|
|
@@ -197,6 +288,11 @@ interface SetActiveCellInstruction {
|
|
|
197
288
|
type: "SET_ACTIVE_CELL";
|
|
198
289
|
position: CellPosition | null;
|
|
199
290
|
}
|
|
291
|
+
/** Set hover position instruction (for highlighting) */
|
|
292
|
+
interface SetHoverPositionInstruction {
|
|
293
|
+
type: "SET_HOVER_POSITION";
|
|
294
|
+
position: CellPosition | null;
|
|
295
|
+
}
|
|
200
296
|
/** Set selection range instruction */
|
|
201
297
|
interface SetSelectionRangeInstruction {
|
|
202
298
|
type: "SET_SELECTION_RANGE";
|
|
@@ -306,19 +402,20 @@ interface DataErrorInstruction {
|
|
|
306
402
|
/** Rows added instruction */
|
|
307
403
|
interface RowsAddedInstruction {
|
|
308
404
|
type: "ROWS_ADDED";
|
|
405
|
+
indices: number[];
|
|
309
406
|
count: number;
|
|
310
407
|
totalRows: number;
|
|
311
408
|
}
|
|
312
409
|
/** Rows removed instruction */
|
|
313
410
|
interface RowsRemovedInstruction {
|
|
314
411
|
type: "ROWS_REMOVED";
|
|
315
|
-
|
|
412
|
+
indices: number[];
|
|
316
413
|
totalRows: number;
|
|
317
414
|
}
|
|
318
415
|
/** Rows updated instruction */
|
|
319
416
|
interface RowsUpdatedInstruction {
|
|
320
417
|
type: "ROWS_UPDATED";
|
|
321
|
-
|
|
418
|
+
indices: number[];
|
|
322
419
|
}
|
|
323
420
|
/** Transaction processed instruction */
|
|
324
421
|
interface TransactionProcessedInstruction {
|
|
@@ -331,6 +428,7 @@ interface TransactionProcessedInstruction {
|
|
|
331
428
|
type GridInstruction = /** Slot lifecycle */
|
|
332
429
|
CreateSlotInstruction | DestroySlotInstruction | AssignSlotInstruction | MoveSlotInstruction
|
|
333
430
|
/** Selection */ | SetActiveCellInstruction | SetSelectionRangeInstruction | UpdateVisibleRangeInstruction
|
|
431
|
+
/** Highlighting */ | SetHoverPositionInstruction
|
|
334
432
|
/** Editing */ | StartEditInstruction | StopEditInstruction | CommitEditInstruction
|
|
335
433
|
/** Layout */ | SetContentSizeInstruction | UpdateHeaderInstruction
|
|
336
434
|
/** Filter popup */ | OpenFilterPopupInstruction | CloseFilterPopupInstruction
|
|
@@ -414,6 +512,8 @@ interface GridCoreOptions<TData = Row> {
|
|
|
414
512
|
transactionDebounceMs?: number;
|
|
415
513
|
/** Function to extract unique ID from row. Required for mutations. */
|
|
416
514
|
getRowId?: (row: TData) => RowId;
|
|
515
|
+
/** Row/column/cell highlighting configuration */
|
|
516
|
+
highlighting?: HighlightingOptions<TData>;
|
|
417
517
|
}
|
|
418
518
|
//#endregion
|
|
419
519
|
//#region src/types/input.d.ts
|
|
@@ -494,10 +594,16 @@ interface InputHandlerDeps {
|
|
|
494
594
|
getHeaderHeight: () => number;
|
|
495
595
|
/** Get row height */
|
|
496
596
|
getRowHeight: () => number;
|
|
497
|
-
/** Get column positions array */
|
|
597
|
+
/** Get column positions array (indexed by visible column) */
|
|
498
598
|
getColumnPositions: () => number[];
|
|
499
|
-
/** Get column count */
|
|
599
|
+
/** Get visible column count */
|
|
500
600
|
getColumnCount: () => number;
|
|
601
|
+
/**
|
|
602
|
+
* Convert visible column index to original column index.
|
|
603
|
+
* Used when columns can be hidden. Returns the original index for selection tracking.
|
|
604
|
+
* If not provided, visible index is used directly (no hidden columns).
|
|
605
|
+
*/
|
|
606
|
+
getOriginalColumnIndex?: (visibleIndex: number) => number;
|
|
501
607
|
}
|
|
502
608
|
/** Current drag state for UI rendering */
|
|
503
609
|
interface DragState {
|
|
@@ -514,6 +620,83 @@ interface DragState {
|
|
|
514
620
|
} | null;
|
|
515
621
|
}
|
|
516
622
|
//#endregion
|
|
623
|
+
//#region src/utils/positioning.d.ts
|
|
624
|
+
/**
|
|
625
|
+
* Calculate cumulative column positions (prefix sums)
|
|
626
|
+
* Returns an array where positions[i] is the left position of column i
|
|
627
|
+
* positions[columns.length] is the total width
|
|
628
|
+
*/
|
|
629
|
+
declare const calculateColumnPositions: (columns: ColumnDefinition[]) => number[];
|
|
630
|
+
/**
|
|
631
|
+
* Get total width from column positions
|
|
632
|
+
*/
|
|
633
|
+
declare const getTotalWidth: (columnPositions: number[]) => number;
|
|
634
|
+
/**
|
|
635
|
+
* Calculate scaled column positions when container is wider than total column widths.
|
|
636
|
+
* Columns expand proportionally based on their original width ratios.
|
|
637
|
+
*
|
|
638
|
+
* @param columns - Column definitions with original widths
|
|
639
|
+
* @param containerWidth - Available container width
|
|
640
|
+
* @returns Object with positions array and widths array
|
|
641
|
+
*/
|
|
642
|
+
declare const calculateScaledColumnPositions: (columns: ColumnDefinition[], containerWidth: number) => {
|
|
643
|
+
positions: number[];
|
|
644
|
+
widths: number[];
|
|
645
|
+
};
|
|
646
|
+
/**
|
|
647
|
+
* Find column index at a given X coordinate
|
|
648
|
+
*/
|
|
649
|
+
declare const findColumnAtX: (x: number, columnPositions: number[]) => number;
|
|
650
|
+
//#endregion
|
|
651
|
+
//#region src/utils/classNames.d.ts
|
|
652
|
+
/**
|
|
653
|
+
* Check if a cell is within the selection range
|
|
654
|
+
*/
|
|
655
|
+
declare const isCellSelected: (row: number, col: number, selectionRange: CellRange | null) => boolean;
|
|
656
|
+
/**
|
|
657
|
+
* Check if a cell is the active cell
|
|
658
|
+
*/
|
|
659
|
+
declare const isCellActive: (row: number, col: number, activeCell: CellPosition | null) => boolean;
|
|
660
|
+
/**
|
|
661
|
+
* Check if a row is within the visible range (not in overscan)
|
|
662
|
+
*/
|
|
663
|
+
declare const isRowVisible: (row: number, visibleRowRange: {
|
|
664
|
+
start: number;
|
|
665
|
+
end: number;
|
|
666
|
+
} | null) => boolean;
|
|
667
|
+
/**
|
|
668
|
+
* Check if a cell is being edited
|
|
669
|
+
*/
|
|
670
|
+
declare const isCellEditing: (row: number, col: number, editingCell: {
|
|
671
|
+
row: number;
|
|
672
|
+
col: number;
|
|
673
|
+
} | null) => boolean;
|
|
674
|
+
/**
|
|
675
|
+
* Check if a cell is in the fill preview range (vertical-only fill)
|
|
676
|
+
*/
|
|
677
|
+
declare const isCellInFillPreview: (row: number, col: number, isDraggingFill: boolean, fillSourceRange: CellRange | null, fillTarget: {
|
|
678
|
+
row: number;
|
|
679
|
+
col: number;
|
|
680
|
+
} | null) => boolean;
|
|
681
|
+
/**
|
|
682
|
+
* Build cell CSS classes based on state
|
|
683
|
+
*/
|
|
684
|
+
declare const buildCellClasses: (isActive: boolean, isSelected: boolean, isEditing: boolean, inFillPreview: boolean) => string;
|
|
685
|
+
/**
|
|
686
|
+
* Check if a row overlaps the selection range
|
|
687
|
+
*/
|
|
688
|
+
declare const isRowInSelectionRange: (rowIndex: number, range: CellRange | null) => boolean;
|
|
689
|
+
/**
|
|
690
|
+
* Check if a column overlaps the selection range
|
|
691
|
+
*/
|
|
692
|
+
declare const isColumnInSelectionRange: (colIndex: number, range: CellRange | null) => boolean;
|
|
693
|
+
//#endregion
|
|
694
|
+
//#region src/utils/event-emitter.d.ts
|
|
695
|
+
/**
|
|
696
|
+
* Batch instruction listener for efficient state updates
|
|
697
|
+
*/
|
|
698
|
+
type BatchInstructionListener$1 = (instructions: GridInstruction[]) => void;
|
|
699
|
+
//#endregion
|
|
517
700
|
//#region src/selection.d.ts
|
|
518
701
|
type Direction = "up" | "down" | "left" | "right";
|
|
519
702
|
interface SelectionManagerOptions {
|
|
@@ -529,10 +712,10 @@ interface SelectionManagerOptions {
|
|
|
529
712
|
declare class SelectionManager {
|
|
530
713
|
private state;
|
|
531
714
|
private options;
|
|
532
|
-
private
|
|
533
|
-
|
|
534
|
-
onInstruction(listener: InstructionListener): () => void;
|
|
715
|
+
private emitter;
|
|
716
|
+
onInstruction: (listener: InstructionListener) => () => void;
|
|
535
717
|
private emit;
|
|
718
|
+
constructor(options: SelectionManagerOptions);
|
|
536
719
|
getState(): SelectionState;
|
|
537
720
|
getActiveCell(): CellPosition | null;
|
|
538
721
|
getSelectionRange(): CellRange | null;
|
|
@@ -597,10 +780,10 @@ interface FillManagerOptions {
|
|
|
597
780
|
declare class FillManager {
|
|
598
781
|
private state;
|
|
599
782
|
private options;
|
|
600
|
-
private
|
|
601
|
-
|
|
602
|
-
onInstruction(listener: InstructionListener): () => void;
|
|
783
|
+
private emitter;
|
|
784
|
+
onInstruction: (listener: InstructionListener) => () => void;
|
|
603
785
|
private emit;
|
|
786
|
+
constructor(options: FillManagerOptions);
|
|
604
787
|
getState(): FillHandleState | null;
|
|
605
788
|
isActive(): boolean;
|
|
606
789
|
/**
|
|
@@ -657,6 +840,14 @@ declare class InputHandler<TData extends Row = Row> {
|
|
|
657
840
|
* Handle cell double click event (start editing)
|
|
658
841
|
*/
|
|
659
842
|
handleCellDoubleClick(rowIndex: number, colIndex: number): void;
|
|
843
|
+
/**
|
|
844
|
+
* Handle cell mouse enter event (for hover highlighting)
|
|
845
|
+
*/
|
|
846
|
+
handleCellMouseEnter(rowIndex: number, colIndex: number): void;
|
|
847
|
+
/**
|
|
848
|
+
* Handle cell mouse leave event (for hover highlighting)
|
|
849
|
+
*/
|
|
850
|
+
handleCellMouseLeave(): void;
|
|
660
851
|
/**
|
|
661
852
|
* Handle fill handle mouse down event
|
|
662
853
|
*/
|
|
@@ -692,16 +883,222 @@ declare class InputHandler<TData extends Row = Row> {
|
|
|
692
883
|
row: number;
|
|
693
884
|
col: number;
|
|
694
885
|
} | null, filterPopupOpen: boolean): KeyboardResult;
|
|
695
|
-
/**
|
|
696
|
-
* Find column index at a given X coordinate
|
|
697
|
-
*/
|
|
698
|
-
private findColumnAtX;
|
|
699
886
|
/**
|
|
700
887
|
* Calculate auto-scroll deltas based on mouse position
|
|
701
888
|
*/
|
|
702
889
|
private calculateAutoScroll;
|
|
703
890
|
}
|
|
704
891
|
//#endregion
|
|
892
|
+
//#region src/highlight-manager.d.ts
|
|
893
|
+
interface HighlightManagerOptions {
|
|
894
|
+
getActiveCell: () => CellPosition | null;
|
|
895
|
+
getSelectionRange: () => CellRange | null;
|
|
896
|
+
getColumn: (colIndex: number) => ColumnDefinition | undefined;
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Manages row/column/cell highlighting state and class computation.
|
|
900
|
+
* Emits SET_HOVER_POSITION instructions when hover position changes.
|
|
901
|
+
*/
|
|
902
|
+
declare class HighlightManager<TData = Record<string, unknown>> {
|
|
903
|
+
private options;
|
|
904
|
+
private highlightingOptions;
|
|
905
|
+
private hoverPosition;
|
|
906
|
+
private emitter;
|
|
907
|
+
onInstruction: (listener: InstructionListener) => () => void;
|
|
908
|
+
private emit;
|
|
909
|
+
private rowClassCache;
|
|
910
|
+
private columnClassCache;
|
|
911
|
+
private cellClassCache;
|
|
912
|
+
constructor(options: HighlightManagerOptions, highlightingOptions?: HighlightingOptions<TData>);
|
|
913
|
+
/**
|
|
914
|
+
* Check if highlighting is enabled (any callback defined).
|
|
915
|
+
* Hover tracking is automatically enabled when highlighting is enabled.
|
|
916
|
+
*/
|
|
917
|
+
isEnabled(): boolean;
|
|
918
|
+
/**
|
|
919
|
+
* Set the current hover position. Clears caches and emits instruction.
|
|
920
|
+
* Hover tracking is automatically enabled when any highlighting callback is defined.
|
|
921
|
+
*/
|
|
922
|
+
setHoverPosition(position: CellPosition | null): void;
|
|
923
|
+
/**
|
|
924
|
+
* Get the current hover position
|
|
925
|
+
*/
|
|
926
|
+
getHoverPosition(): CellPosition | null;
|
|
927
|
+
/**
|
|
928
|
+
* Called when selection changes. Clears all caches.
|
|
929
|
+
*/
|
|
930
|
+
onSelectionChange(): void;
|
|
931
|
+
/**
|
|
932
|
+
* Build context for row highlighting callback.
|
|
933
|
+
* Returns context with `rowIndex` set, `colIndex` is null.
|
|
934
|
+
* `isHovered` is true when the mouse is on any cell in this row.
|
|
935
|
+
*/
|
|
936
|
+
buildRowContext(rowIndex: number, rowData?: TData): HighlightContext<TData>;
|
|
937
|
+
/**
|
|
938
|
+
* Build context for column highlighting callback.
|
|
939
|
+
* Returns context with `colIndex` set, `rowIndex` is null.
|
|
940
|
+
* `isHovered` is true when the mouse is on any cell in this column.
|
|
941
|
+
*/
|
|
942
|
+
buildColumnContext(colIndex: number, column: ColumnDefinition): HighlightContext<TData>;
|
|
943
|
+
/**
|
|
944
|
+
* Build context for cell highlighting callback.
|
|
945
|
+
* Returns context with both `rowIndex` and `colIndex` set.
|
|
946
|
+
* `isHovered` is true only when the mouse is on this exact cell.
|
|
947
|
+
*/
|
|
948
|
+
buildCellContext(rowIndex: number, colIndex: number, column: ColumnDefinition, rowData?: TData): HighlightContext<TData>;
|
|
949
|
+
/**
|
|
950
|
+
* Compute row classes using cache and user callback
|
|
951
|
+
*/
|
|
952
|
+
computeRowClasses(rowIndex: number, rowData?: TData): string[];
|
|
953
|
+
/**
|
|
954
|
+
* Compute column classes using cache and user callback (or per-column override)
|
|
955
|
+
*/
|
|
956
|
+
computeColumnClasses(colIndex: number, column: ColumnDefinition): string[];
|
|
957
|
+
/**
|
|
958
|
+
* Compute cell classes using cache and user callback (or per-column override)
|
|
959
|
+
*/
|
|
960
|
+
computeCellClasses(rowIndex: number, colIndex: number, column: ColumnDefinition, rowData?: TData): string[];
|
|
961
|
+
/**
|
|
962
|
+
* Compute combined cell classes (column + cell classes flattened)
|
|
963
|
+
*/
|
|
964
|
+
computeCombinedCellClasses(rowIndex: number, colIndex: number, column: ColumnDefinition, rowData?: TData): string[];
|
|
965
|
+
/**
|
|
966
|
+
* Clear all caches
|
|
967
|
+
*/
|
|
968
|
+
clearAllCaches(): void;
|
|
969
|
+
/**
|
|
970
|
+
* Destroy the manager and release resources
|
|
971
|
+
*/
|
|
972
|
+
destroy(): void;
|
|
973
|
+
}
|
|
974
|
+
//#endregion
|
|
975
|
+
//#region src/sort-filter-manager.d.ts
|
|
976
|
+
interface SortFilterManagerOptions<TData> {
|
|
977
|
+
/** Get all columns */
|
|
978
|
+
getColumns: () => ColumnDefinition[];
|
|
979
|
+
/** Check if sorting is enabled globally */
|
|
980
|
+
isSortingEnabled: () => boolean;
|
|
981
|
+
/** Get cached rows for distinct value computation */
|
|
982
|
+
getCachedRows: () => Map<number, TData>;
|
|
983
|
+
/** Called when sort/filter changes to trigger data refresh */
|
|
984
|
+
onSortFilterChange: () => Promise<void>;
|
|
985
|
+
/** Called after data refresh to update UI */
|
|
986
|
+
onDataRefreshed: () => void;
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* Manages sorting and filtering state and operations.
|
|
990
|
+
*/
|
|
991
|
+
declare class SortFilterManager<TData = Record<string, unknown>> {
|
|
992
|
+
private options;
|
|
993
|
+
private emitter;
|
|
994
|
+
private sortModel;
|
|
995
|
+
private filterModel;
|
|
996
|
+
private openFilterColIndex;
|
|
997
|
+
onInstruction: (listener: InstructionListener) => () => void;
|
|
998
|
+
private emit;
|
|
999
|
+
constructor(options: SortFilterManagerOptions<TData>);
|
|
1000
|
+
setSort(colId: string, direction: SortDirection | null, addToExisting?: boolean): Promise<void>;
|
|
1001
|
+
getSortModel(): SortModel[];
|
|
1002
|
+
setFilter(colId: string, filter: ColumnFilterModel | string | null): Promise<void>;
|
|
1003
|
+
getFilterModel(): FilterModel;
|
|
1004
|
+
/**
|
|
1005
|
+
* Check if a column has an active filter
|
|
1006
|
+
*/
|
|
1007
|
+
hasActiveFilter(colId: string): boolean;
|
|
1008
|
+
/**
|
|
1009
|
+
* Check if a column is sortable
|
|
1010
|
+
*/
|
|
1011
|
+
isColumnSortable(colIndex: number): boolean;
|
|
1012
|
+
/**
|
|
1013
|
+
* Check if a column is filterable
|
|
1014
|
+
*/
|
|
1015
|
+
isColumnFilterable(colIndex: number): boolean;
|
|
1016
|
+
/**
|
|
1017
|
+
* Get distinct values for a column (for filter dropdowns)
|
|
1018
|
+
* For array-type columns (like tags), each unique array combination is returned.
|
|
1019
|
+
* Arrays are sorted internally for consistent comparison.
|
|
1020
|
+
* Limited to maxValues to avoid performance issues with large datasets.
|
|
1021
|
+
*/
|
|
1022
|
+
getDistinctValuesForColumn(colId: string, maxValues?: number): CellValue[];
|
|
1023
|
+
/**
|
|
1024
|
+
* Open filter popup for a column (toggles if already open for same column)
|
|
1025
|
+
*/
|
|
1026
|
+
openFilterPopup(colIndex: number, anchorRect: {
|
|
1027
|
+
top: number;
|
|
1028
|
+
left: number;
|
|
1029
|
+
width: number;
|
|
1030
|
+
height: number;
|
|
1031
|
+
}): void;
|
|
1032
|
+
/**
|
|
1033
|
+
* Close filter popup
|
|
1034
|
+
*/
|
|
1035
|
+
closeFilterPopup(): void;
|
|
1036
|
+
/**
|
|
1037
|
+
* Get sort info map for header rendering
|
|
1038
|
+
*/
|
|
1039
|
+
getSortInfoMap(): Map<string, {
|
|
1040
|
+
direction: SortDirection;
|
|
1041
|
+
index: number;
|
|
1042
|
+
}>;
|
|
1043
|
+
destroy(): void;
|
|
1044
|
+
}
|
|
1045
|
+
//#endregion
|
|
1046
|
+
//#region src/row-mutation-manager.d.ts
|
|
1047
|
+
interface RowMutationManagerOptions<TData> {
|
|
1048
|
+
/** Get the cached rows map */
|
|
1049
|
+
getCachedRows: () => Map<number, TData>;
|
|
1050
|
+
/** Set the cached rows map (for bulk operations) */
|
|
1051
|
+
setCachedRows: (rows: Map<number, TData>) => void;
|
|
1052
|
+
/** Get total row count */
|
|
1053
|
+
getTotalRows: () => number;
|
|
1054
|
+
/** Set total row count */
|
|
1055
|
+
setTotalRows: (count: number) => void;
|
|
1056
|
+
/** Update a single slot after row change */
|
|
1057
|
+
updateSlot: (rowIndex: number) => void;
|
|
1058
|
+
/** Refresh all slots after bulk changes */
|
|
1059
|
+
refreshAllSlots: () => void;
|
|
1060
|
+
/** Emit content size change */
|
|
1061
|
+
emitContentSize: () => void;
|
|
1062
|
+
/** Clear selection if it references invalid rows */
|
|
1063
|
+
clearSelectionIfInvalid: (maxValidRow: number) => void;
|
|
1064
|
+
}
|
|
1065
|
+
/**
|
|
1066
|
+
* Manages row CRUD operations and cache management.
|
|
1067
|
+
*/
|
|
1068
|
+
declare class RowMutationManager<TData extends Row = Row> {
|
|
1069
|
+
private options;
|
|
1070
|
+
private emitter;
|
|
1071
|
+
onInstruction: (listener: InstructionListener) => () => void;
|
|
1072
|
+
private emit;
|
|
1073
|
+
constructor(options: RowMutationManagerOptions<TData>);
|
|
1074
|
+
/**
|
|
1075
|
+
* Get a row by index.
|
|
1076
|
+
*/
|
|
1077
|
+
getRow(index: number): TData | undefined;
|
|
1078
|
+
/**
|
|
1079
|
+
* Add rows to the grid at the specified index.
|
|
1080
|
+
* If no index is provided, rows are added at the end.
|
|
1081
|
+
*/
|
|
1082
|
+
addRows(rows: TData[], index?: number): void;
|
|
1083
|
+
/**
|
|
1084
|
+
* Update existing rows with partial data.
|
|
1085
|
+
*/
|
|
1086
|
+
updateRows(updates: Array<{
|
|
1087
|
+
index: number;
|
|
1088
|
+
data: Partial<TData>;
|
|
1089
|
+
}>): void;
|
|
1090
|
+
/**
|
|
1091
|
+
* Delete rows at the specified indices.
|
|
1092
|
+
*/
|
|
1093
|
+
deleteRows(indices: number[]): void;
|
|
1094
|
+
/**
|
|
1095
|
+
* Set a complete row at the specified index.
|
|
1096
|
+
* Use this for complete row replacement. For partial updates, use updateRows.
|
|
1097
|
+
*/
|
|
1098
|
+
setRow(index: number, data: TData): void;
|
|
1099
|
+
destroy(): void;
|
|
1100
|
+
}
|
|
1101
|
+
//#endregion
|
|
705
1102
|
//#region src/grid-core.d.ts
|
|
706
1103
|
declare class GridCore<TData extends Row = Row> {
|
|
707
1104
|
private columns;
|
|
@@ -718,30 +1115,25 @@ declare class GridCore<TData extends Row = Row> {
|
|
|
718
1115
|
private totalRows;
|
|
719
1116
|
private currentPageIndex;
|
|
720
1117
|
private pageSize;
|
|
721
|
-
private sortModel;
|
|
722
|
-
private filterModel;
|
|
723
|
-
private openFilterColIndex;
|
|
724
1118
|
readonly selection: SelectionManager;
|
|
725
1119
|
readonly fill: FillManager;
|
|
726
1120
|
readonly input: InputHandler<TData>;
|
|
1121
|
+
readonly highlight: HighlightManager<TData> | null;
|
|
1122
|
+
readonly sortFilter: SortFilterManager<TData>;
|
|
1123
|
+
readonly rowMutation: RowMutationManager<TData>;
|
|
727
1124
|
private readonly slotPool;
|
|
728
1125
|
private readonly editManager;
|
|
729
1126
|
private columnPositions;
|
|
730
|
-
private
|
|
731
|
-
|
|
1127
|
+
private emitter;
|
|
1128
|
+
onInstruction: (listener: InstructionListener) => () => void;
|
|
1129
|
+
onBatchInstruction: (listener: BatchInstructionListener$1) => () => void;
|
|
1130
|
+
private emit;
|
|
1131
|
+
private emitBatch;
|
|
732
1132
|
private naturalContentHeight;
|
|
733
1133
|
private virtualContentHeight;
|
|
734
1134
|
private scrollRatio;
|
|
735
1135
|
private isDestroyed;
|
|
736
1136
|
constructor(options: GridCoreOptions<TData>);
|
|
737
|
-
onInstruction(listener: InstructionListener): () => void;
|
|
738
|
-
/**
|
|
739
|
-
* Subscribe to batched instructions for efficient React state updates.
|
|
740
|
-
* Batch listeners receive arrays of instructions instead of individual ones.
|
|
741
|
-
*/
|
|
742
|
-
onBatchInstruction(listener: BatchInstructionListener): () => void;
|
|
743
|
-
private emit;
|
|
744
|
-
private emitBatch;
|
|
745
1137
|
/**
|
|
746
1138
|
* Initialize the grid and load initial data.
|
|
747
1139
|
*/
|
|
@@ -755,37 +1147,16 @@ declare class GridCore<TData extends Row = Row> {
|
|
|
755
1147
|
private fetchAllData;
|
|
756
1148
|
setSort(colId: string, direction: SortDirection | null, addToExisting?: boolean): Promise<void>;
|
|
757
1149
|
setFilter(colId: string, filter: ColumnFilterModel | string | null): Promise<void>;
|
|
758
|
-
/**
|
|
759
|
-
* Check if a column has an active filter
|
|
760
|
-
*/
|
|
761
1150
|
hasActiveFilter(colId: string): boolean;
|
|
762
|
-
/**
|
|
763
|
-
* Check if a column is sortable
|
|
764
|
-
*/
|
|
765
1151
|
isColumnSortable(colIndex: number): boolean;
|
|
766
|
-
/**
|
|
767
|
-
* Check if a column is filterable
|
|
768
|
-
*/
|
|
769
1152
|
isColumnFilterable(colIndex: number): boolean;
|
|
770
|
-
/**
|
|
771
|
-
* Get distinct values for a column (for filter dropdowns)
|
|
772
|
-
* For array-type columns (like tags), each unique array combination is returned.
|
|
773
|
-
* Arrays are sorted internally for consistent comparison.
|
|
774
|
-
* Limited to MAX_DISTINCT_VALUES to avoid performance issues with large datasets.
|
|
775
|
-
*/
|
|
776
1153
|
getDistinctValuesForColumn(colId: string, maxValues?: number): CellValue[];
|
|
777
|
-
/**
|
|
778
|
-
* Open filter popup for a column (toggles if already open for same column)
|
|
779
|
-
*/
|
|
780
1154
|
openFilterPopup(colIndex: number, anchorRect: {
|
|
781
1155
|
top: number;
|
|
782
1156
|
left: number;
|
|
783
1157
|
width: number;
|
|
784
1158
|
height: number;
|
|
785
1159
|
}): void;
|
|
786
|
-
/**
|
|
787
|
-
* Close filter popup
|
|
788
|
-
*/
|
|
789
1160
|
closeFilterPopup(): void;
|
|
790
1161
|
getSortModel(): SortModel[];
|
|
791
1162
|
getFilterModel(): FilterModel;
|
|
@@ -796,8 +1167,6 @@ declare class GridCore<TData extends Row = Row> {
|
|
|
796
1167
|
getEditState(): EditState | null;
|
|
797
1168
|
getCellValue(row: number, col: number): CellValue;
|
|
798
1169
|
setCellValue(row: number, col: number, value: CellValue): void;
|
|
799
|
-
private getFieldValue;
|
|
800
|
-
private setFieldValue;
|
|
801
1170
|
private computeColumnPositions;
|
|
802
1171
|
private emitContentSize;
|
|
803
1172
|
private emitHeaders;
|
|
@@ -854,6 +1223,31 @@ declare class GridCore<TData extends Row = Row> {
|
|
|
854
1223
|
* Useful after in-place data modifications like fill operations.
|
|
855
1224
|
*/
|
|
856
1225
|
refreshSlotData(): void;
|
|
1226
|
+
/**
|
|
1227
|
+
* Add rows to the grid at the specified index.
|
|
1228
|
+
* If no index is provided, rows are added at the end.
|
|
1229
|
+
*/
|
|
1230
|
+
addRows(rows: TData[], index?: number): void;
|
|
1231
|
+
/**
|
|
1232
|
+
* Update existing rows with partial data.
|
|
1233
|
+
*/
|
|
1234
|
+
updateRows(updates: Array<{
|
|
1235
|
+
index: number;
|
|
1236
|
+
data: Partial<TData>;
|
|
1237
|
+
}>): void;
|
|
1238
|
+
/**
|
|
1239
|
+
* Delete rows at the specified indices.
|
|
1240
|
+
*/
|
|
1241
|
+
deleteRows(indices: number[]): void;
|
|
1242
|
+
/**
|
|
1243
|
+
* Get a row by index.
|
|
1244
|
+
*/
|
|
1245
|
+
getRow(index: number): TData | undefined;
|
|
1246
|
+
/**
|
|
1247
|
+
* Set a complete row at the specified index.
|
|
1248
|
+
* Use this for complete row replacement. For partial updates, use updateRows.
|
|
1249
|
+
*/
|
|
1250
|
+
setRow(index: number, data: TData): void;
|
|
857
1251
|
/**
|
|
858
1252
|
* Update the data source and refresh.
|
|
859
1253
|
*/
|
|
@@ -895,22 +1289,16 @@ interface SlotPoolManagerOptions {
|
|
|
895
1289
|
* Manages the slot pool for virtual scrolling.
|
|
896
1290
|
* Handles slot creation, recycling, positioning, and destruction.
|
|
897
1291
|
*/
|
|
898
|
-
/** Batch instruction listener for efficient React state updates */
|
|
899
|
-
type BatchInstructionListener$1 = (instructions: GridInstruction[]) => void;
|
|
900
1292
|
declare class SlotPoolManager {
|
|
901
1293
|
private state;
|
|
902
1294
|
private options;
|
|
903
|
-
private
|
|
904
|
-
private batchListeners;
|
|
1295
|
+
private emitter;
|
|
905
1296
|
private isDestroyed;
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
/**
|
|
909
|
-
* Subscribe to batched instructions for efficient state updates.
|
|
910
|
-
*/
|
|
911
|
-
onBatchInstruction(listener: BatchInstructionListener$1): () => void;
|
|
1297
|
+
onInstruction: (listener: InstructionListener) => () => void;
|
|
1298
|
+
onBatchInstruction: (listener: BatchInstructionListener$1) => () => void;
|
|
912
1299
|
private emit;
|
|
913
1300
|
private emitBatch;
|
|
1301
|
+
constructor(options: SlotPoolManagerOptions);
|
|
914
1302
|
/**
|
|
915
1303
|
* Get the slot ID for a given row index.
|
|
916
1304
|
*/
|
|
@@ -966,10 +1354,10 @@ interface EditManagerOptions {
|
|
|
966
1354
|
declare class EditManager {
|
|
967
1355
|
private editState;
|
|
968
1356
|
private options;
|
|
969
|
-
private
|
|
970
|
-
|
|
971
|
-
onInstruction(listener: InstructionListener): () => void;
|
|
1357
|
+
private emitter;
|
|
1358
|
+
onInstruction: (listener: InstructionListener) => () => void;
|
|
972
1359
|
private emit;
|
|
1360
|
+
constructor(options: EditManagerOptions);
|
|
973
1361
|
/**
|
|
974
1362
|
* Get the current edit state.
|
|
975
1363
|
*/
|
|
@@ -1616,79 +2004,11 @@ declare const gridStyles: string;
|
|
|
1616
2004
|
*/
|
|
1617
2005
|
declare function injectStyles(): void;
|
|
1618
2006
|
//#endregion
|
|
1619
|
-
//#region src/utils/positioning.d.ts
|
|
1620
|
-
/**
|
|
1621
|
-
* Calculate cumulative column positions (prefix sums)
|
|
1622
|
-
* Returns an array where positions[i] is the left position of column i
|
|
1623
|
-
* positions[columns.length] is the total width
|
|
1624
|
-
*/
|
|
1625
|
-
declare function calculateColumnPositions(columns: ColumnDefinition[]): number[];
|
|
1626
|
-
/**
|
|
1627
|
-
* Get total width from column positions
|
|
1628
|
-
*/
|
|
1629
|
-
declare function getTotalWidth(columnPositions: number[]): number;
|
|
1630
|
-
/**
|
|
1631
|
-
* Calculate scaled column positions when container is wider than total column widths.
|
|
1632
|
-
* Columns expand proportionally based on their original width ratios.
|
|
1633
|
-
*
|
|
1634
|
-
* @param columns - Column definitions with original widths
|
|
1635
|
-
* @param containerWidth - Available container width
|
|
1636
|
-
* @returns Object with positions array and widths array
|
|
1637
|
-
*/
|
|
1638
|
-
declare function calculateScaledColumnPositions(columns: ColumnDefinition[], containerWidth: number): {
|
|
1639
|
-
positions: number[];
|
|
1640
|
-
widths: number[];
|
|
1641
|
-
};
|
|
1642
|
-
/**
|
|
1643
|
-
* Find column index at a given X coordinate
|
|
1644
|
-
*/
|
|
1645
|
-
declare function findColumnAtX(x: number, columnPositions: number[]): number;
|
|
1646
|
-
//#endregion
|
|
1647
|
-
//#region src/utils/classNames.d.ts
|
|
1648
|
-
/**
|
|
1649
|
-
* Check if a cell is within the selection range
|
|
1650
|
-
*/
|
|
1651
|
-
declare function isCellSelected(row: number, col: number, selectionRange: CellRange | null): boolean;
|
|
1652
|
-
/**
|
|
1653
|
-
* Check if a cell is the active cell
|
|
1654
|
-
*/
|
|
1655
|
-
declare function isCellActive(row: number, col: number, activeCell: CellPosition | null): boolean;
|
|
1656
|
-
/**
|
|
1657
|
-
* Check if a row is within the visible range (not in overscan)
|
|
1658
|
-
*/
|
|
1659
|
-
declare function isRowVisible(row: number, visibleRowRange: {
|
|
1660
|
-
start: number;
|
|
1661
|
-
end: number;
|
|
1662
|
-
} | null): boolean;
|
|
1663
|
-
/**
|
|
1664
|
-
* Check if a cell is being edited
|
|
1665
|
-
*/
|
|
1666
|
-
declare function isCellEditing(row: number, col: number, editingCell: {
|
|
1667
|
-
row: number;
|
|
1668
|
-
col: number;
|
|
1669
|
-
} | null): boolean;
|
|
1670
|
-
/**
|
|
1671
|
-
* Check if a cell is in the fill preview range (vertical-only fill)
|
|
1672
|
-
*/
|
|
1673
|
-
declare function isCellInFillPreview(row: number, col: number, isDraggingFill: boolean, fillSourceRange: {
|
|
1674
|
-
startRow: number;
|
|
1675
|
-
startCol: number;
|
|
1676
|
-
endRow: number;
|
|
1677
|
-
endCol: number;
|
|
1678
|
-
} | null, fillTarget: {
|
|
1679
|
-
row: number;
|
|
1680
|
-
col: number;
|
|
1681
|
-
} | null): boolean;
|
|
1682
|
-
/**
|
|
1683
|
-
* Build cell CSS classes based on state
|
|
1684
|
-
*/
|
|
1685
|
-
declare function buildCellClasses(isActive: boolean, isSelected: boolean, isEditing: boolean, inFillPreview: boolean): string;
|
|
1686
|
-
//#endregion
|
|
1687
2007
|
//#region src/types/ui-state.d.ts
|
|
1688
|
-
interface SlotData {
|
|
2008
|
+
interface SlotData<TData = Row> {
|
|
1689
2009
|
slotId: string;
|
|
1690
2010
|
rowIndex: number;
|
|
1691
|
-
rowData:
|
|
2011
|
+
rowData: TData;
|
|
1692
2012
|
translateY: number;
|
|
1693
2013
|
}
|
|
1694
2014
|
interface HeaderData {
|
|
@@ -1712,8 +2032,8 @@ interface FilterPopupState {
|
|
|
1712
2032
|
distinctValues: CellValue[];
|
|
1713
2033
|
currentFilter?: ColumnFilterModel;
|
|
1714
2034
|
}
|
|
1715
|
-
interface GridState {
|
|
1716
|
-
slots: Map<string, SlotData
|
|
2035
|
+
interface GridState<TData = Row> {
|
|
2036
|
+
slots: Map<string, SlotData<TData>>;
|
|
1717
2037
|
activeCell: CellPosition | null;
|
|
1718
2038
|
selectionRange: CellRange | null;
|
|
1719
2039
|
editingCell: {
|
|
@@ -1735,6 +2055,8 @@ interface GridState {
|
|
|
1735
2055
|
start: number;
|
|
1736
2056
|
end: number;
|
|
1737
2057
|
} | null;
|
|
2058
|
+
/** Currently hovered cell position (for highlighting) */
|
|
2059
|
+
hoverPosition: CellPosition | null;
|
|
1738
2060
|
}
|
|
1739
2061
|
//#endregion
|
|
1740
|
-
export { type AssignSlotInstruction, type BatchInstructionListener, type CancelFillInstruction, type CellDataType, type CellPosition, type CellRange, type CellRendererParams, type CellValue, 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, 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 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, isRowVisible, isSameDay, kWayMerge, kWayMergeMultiColumn, rowPassesFilter, scrollbarStyles, setFieldValue, statesStyles, stringToSortableNumber, variablesStyles };
|
|
2062
|
+
export { type AssignSlotInstruction, type BatchInstructionListener, type CancelFillInstruction, type CellDataType, type CellPosition, type CellRange, type CellRendererParams, type CellValue, 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 };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
`);try{await navigator.clipboard.writeText(t)}catch{let e=document.createElement(`textarea`);e.value=t,e.style.position=`fixed`,e.style.left=`-9999px`,document.body.appendChild(e),e.select(),document.execCommand(`copy`),document.body.removeChild(e)}}destroy(){this.listeners=[],this.state={activeCell:null,range:null,anchor:null,selectionMode:!1}}clampPosition(e){let t=this.options.getRowCount(),n=this.options.getColumnCount();return{row:Math.max(0,Math.min(e.row,t-1)),col:Math.max(0,Math.min(e.col,n-1))}}},t=class{state=null;options;listeners=[];constructor(e){this.options=e}onInstruction(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}emit(e){for(let t of this.listeners)t(e)}getState(){return this.state?{...this.state}:null}isActive(){return this.state!==null}startFillDrag(e){this.state={sourceRange:e,targetRow:e.endRow,targetCol:e.endCol},this.emit({type:`START_FILL`,sourceRange:e})}updateFillDrag(e,t){if(!this.state)return;let n=this.options.getRowCount(),r=this.options.getColumnCount();e=Math.max(0,Math.min(e,n-1)),t=Math.max(0,Math.min(t,r-1)),this.state.targetRow=e,this.state.targetCol=t,this.emit({type:`UPDATE_FILL`,targetRow:e,targetCol:t})}commitFillDrag(){if(!this.state)return;let{sourceRange:e,targetRow:t}=this.state,n=this.calculateFilledCells(e,t);for(let{row:e,col:t,value:r}of n)this.options.setCellValue(e,t,r);this.emit({type:`COMMIT_FILL`,filledCells:n}),this.state=null}cancelFillDrag(){this.state&&(this.state=null,this.emit({type:`CANCEL_FILL`}))}destroy(){this.listeners=[],this.state=null}calculateFilledCells(e,t){let n=[],r=Math.min(e.startRow,e.endRow),i=Math.max(e.startRow,e.endRow),a=Math.min(e.startCol,e.endCol),o=Math.max(e.startCol,e.endCol),s=t>i,c=t<r;if(s||c)for(let e=a;e<=o;e++){let a=this.getSourceColumnValues(r,i,e),o=this.detectPattern(a);if(s)for(let r=i+1;r<=t;r++){let t=r-i-1,s=this.applyPattern(o,a,t);n.push({row:r,col:e,value:s})}else if(c)for(let i=r-1;i>=t;i--){let t=r-i-1,s=this.applyPattern(o,a,t,!0);n.push({row:i,col:e,value:s})}}return n}getSourceColumnValues(e,t,n){let r=[];for(let i=e;i<=t;i++)r.push(this.options.getCellValue(i,n));return r}detectPattern(e){if(e.length===0)return{type:`constant`,value:null};if(e.length===1)return{type:`constant`,value:e[0]??null};let t=e.map(e=>typeof e==`number`?e:Number(e));if(t.every(e=>!isNaN(e))){let e=[];for(let n=1;n<t.length;n++)e.push(t[n]-t[n-1]);if(e.every(t=>t===e[0])&&e[0]!==void 0)return{type:`arithmetic`,start:t[0],step:e[0]}}return{type:`repeat`,values:e}}applyPattern(e,t,n,r=!1){switch(e.type){case`constant`:return e.value;case`arithmetic`:{let i=r?-(n+1):n+1;return(r?e.start:e.start+e.step*(t.length-1))+e.step*i}case`repeat`:{let t=e.values.length;if(t===0)return null;if(r){let r=(t-1-n%t+t)%t;return e.values[r]??null}return e.values[n%t]??null}}}},n=class{state={slots:new Map,rowToSlot:new Map,nextSlotId:0};options;listeners=[];batchListeners=[];isDestroyed=!1;constructor(e){this.options=e}onInstruction(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}onBatchInstruction(e){return this.batchListeners.push(e),()=>{this.batchListeners=this.batchListeners.filter(t=>t!==e)}}emit(e){for(let t of this.listeners)t(e);for(let t of this.batchListeners)t([e])}emitBatch(e){if(e.length!==0){for(let t of this.batchListeners)t(e);for(let t of e)for(let e of this.listeners)e(t)}}getSlotForRow(e){return this.state.rowToSlot.get(e)}getSlots(){return this.state.slots}syncSlots(){let e=this.options.getScrollTop(),t=this.options.getRowHeight(),n=this.options.getViewportHeight(),r=this.options.getTotalRows(),i=this.options.getOverscan(),a=Math.max(0,Math.floor(e/t)-i),o=Math.min(r-1,Math.ceil((e+n)/t)+i);if(r===0||o<a){this.destroyAllSlots();return}let s=new Set;for(let e=a;e<=o;e++)s.add(e);let c=[],l=[];for(let[e,t]of this.state.slots)s.has(t.rowIndex)?s.delete(t.rowIndex):(l.push(e),this.state.rowToSlot.delete(t.rowIndex));let u=Array.from(s);for(let e=0;e<u.length;e++){let t=u[e],n=this.options.getRowData(t);if(e<l.length){let r=l[e],i=this.state.slots.get(r),a=this.getRowTranslateY(t);i.rowIndex=t,i.rowData=n??{},i.translateY=a,this.state.rowToSlot.set(t,r),c.push({type:`ASSIGN_SLOT`,slotId:r,rowIndex:t,rowData:n??{}}),c.push({type:`MOVE_SLOT`,slotId:r,translateY:a})}else{let e=`slot-${this.state.nextSlotId++}`,r=this.getRowTranslateY(t),i={slotId:e,rowIndex:t,rowData:n??{},translateY:r};this.state.slots.set(e,i),this.state.rowToSlot.set(t,e),c.push({type:`CREATE_SLOT`,slotId:e}),c.push({type:`ASSIGN_SLOT`,slotId:e,rowIndex:t,rowData:n??{}}),c.push({type:`MOVE_SLOT`,slotId:e,translateY:r})}}for(let e=u.length;e<l.length;e++){let t=l[e];this.state.slots.delete(t),c.push({type:`DESTROY_SLOT`,slotId:t})}for(let[e,t]of this.state.slots){let n=this.getRowTranslateY(t.rowIndex);t.translateY!==n&&(t.translateY=n,c.push({type:`MOVE_SLOT`,slotId:e,translateY:n}))}this.emitBatch(c)}destroyAllSlots(){let e=[];for(let t of this.state.slots.keys())e.push({type:`DESTROY_SLOT`,slotId:t});this.state.slots.clear(),this.state.rowToSlot.clear(),this.emitBatch(e)}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.state.slots.clear(),this.state.rowToSlot.clear(),this.listeners=[],this.batchListeners=[])}refreshAllSlots(){let e=[],t=this.options.getTotalRows();for(let[n,r]of this.state.slots)if(r.rowIndex>=0&&r.rowIndex<t){let t=this.options.getRowData(r.rowIndex),i=this.getRowTranslateY(r.rowIndex);r.rowData=t??{},r.translateY=i,e.push({type:`ASSIGN_SLOT`,slotId:n,rowIndex:r.rowIndex,rowData:t??{}}),e.push({type:`MOVE_SLOT`,slotId:n,translateY:i})}this.emitBatch(e),this.syncSlots()}updateSlot(e){let t=this.state.rowToSlot.get(e);if(t){let n=this.options.getRowData(e);n&&this.emit({type:`ASSIGN_SLOT`,slotId:t,rowIndex:e,rowData:n})}}getRowTranslateY(e){let t=this.options.getRowHeight(),n=this.options.getHeaderHeight(),r=this.options.getScrollRatio(),i=this.options.getVirtualContentHeight(),a=this.options.getScrollTop(),o=e*t+n;if(r>=1)return o;let s=a,c=o-(s-s*r);return Math.max(0,Math.min(c,i))}},r=class{editState=null;options;listeners=[];constructor(e){this.options=e}onInstruction(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}emit(e){for(let t of this.listeners)t(e)}getState(){return this.editState?{...this.editState}:null}isEditing(){return this.editState!==null}isEditingCell(e,t){return this.editState!==null&&this.editState.row===e&&this.editState.col===t}startEdit(e,t){let n=this.options.getColumn(t);if(!n||n.editable!==!0)return!1;let r=this.options.getCellValue(e,t);return this.editState={row:e,col:t,initialValue:r,currentValue:r},this.emit({type:`START_EDIT`,row:e,col:t,initialValue:r}),!0}updateValue(e){this.editState&&(this.editState.currentValue=e)}commit(){if(!this.editState)return;let{row:e,col:t,currentValue:n}=this.editState;this.options.setCellValue(e,t,n),this.emit({type:`COMMIT_EDIT`,row:e,col:t,value:n}),this.editState=null,this.emit({type:`STOP_EDIT`}),this.options.onCommit?.(e,t,n)}cancel(){this.editState=null,this.emit({type:`STOP_EDIT`})}destroy(){this.listeners=[],this.editState=null}},i=class{core;deps;isDraggingSelection=!1;isDraggingFill=!1;fillSourceRange=null;fillTarget=null;constructor(e,t){this.core=e,this.deps=t}updateDeps(e){this.deps={...this.deps,...e}}getDragState(){return{isDragging:this.isDraggingSelection||this.isDraggingFill,dragType:this.isDraggingFill?`fill`:this.isDraggingSelection?`selection`:null,fillSourceRange:this.fillSourceRange,fillTarget:this.fillTarget}}handleCellMouseDown(e,t,n){return n.button!==0||this.core.getEditState()!==null?{preventDefault:!1,stopPropagation:!1}:(this.core.selection.startSelection({row:e,col:t},{shift:n.shiftKey,ctrl:n.ctrlKey||n.metaKey}),{preventDefault:!1,stopPropagation:!1,focusContainer:!0,startDrag:n.shiftKey?void 0:`selection`})}handleCellDoubleClick(e,t){this.core.startEdit(e,t)}handleFillHandleMouseDown(e,t,n){if(!e&&!t)return{preventDefault:!1,stopPropagation:!1};let r=t??{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};return this.core.fill.startFillDrag(r),this.fillSourceRange=r,this.fillTarget={row:Math.max(r.startRow,r.endRow),col:Math.max(r.startCol,r.endCol)},this.isDraggingFill=!0,{preventDefault:!0,stopPropagation:!0,startDrag:`fill`}}handleHeaderClick(e,t){let n=this.core.getSortModel().find(t=>t.colId===e)?.direction,r=n==null?`asc`:n===`asc`?`desc`:null;this.core.setSort(e,r,t)}startSelectionDrag(){this.isDraggingSelection=!0}handleDragMove(e,t){if(!this.isDraggingSelection&&!this.isDraggingFill)return null;let{top:n,left:r,width:i,height:a,scrollTop:o,scrollLeft:s}=t,c=this.deps.getHeaderHeight(),l=this.deps.getColumnPositions(),u=this.deps.getColumnCount(),d=e.clientX-r+s,f=e.clientY-n-c,p=Math.max(0,Math.min(this.core.getRowIndexAtDisplayY(f,o),this.core.getRowCount()-1)),m=Math.max(0,Math.min(this.findColumnAtX(d,l),u-1));this.isDraggingSelection&&this.core.selection.startSelection({row:p,col:m},{shift:!0}),this.isDraggingFill&&(this.core.fill.updateFillDrag(p,m),this.fillTarget={row:p,col:m});let h=e.clientY-n,g=e.clientX-r;return{targetRow:p,targetCol:m,autoScroll:this.calculateAutoScroll(h,g,a,i,c)}}handleDragEnd(){this.isDraggingFill&&(this.core.fill.commitFillDrag(),this.core.refreshSlotData()),this.isDraggingSelection=!1,this.isDraggingFill=!1,this.fillSourceRange=null,this.fillTarget=null}handleWheel(e,t,n){return this.core.isScalingActive()?{dy:e*n,dx:t*n}:null}handleKeyDown(e,t,n,r){if(r||n&&e.key!==`Enter`&&e.key!==`Escape`&&e.key!==`Tab`)return{preventDefault:!1};let{selection:i}=this.core,a=e.shiftKey,o=e.ctrlKey||e.metaKey,s=(e=>{switch(e){case`ArrowUp`:return`up`;case`ArrowDown`:return`down`;case`ArrowLeft`:return`left`;case`ArrowRight`:return`right`;default:return null}})(e.key);if(s)return i.moveFocus(s,a),{preventDefault:!0,scrollToCell:i.getActiveCell()??void 0};switch(e.key){case`Enter`:return n?this.core.commitEdit():t&&this.core.startEdit(t.row,t.col),{preventDefault:!0};case`Escape`:return n?this.core.cancelEdit():i.clearSelection(),{preventDefault:!0};case`Tab`:return n&&this.core.commitEdit(),i.moveFocus(a?`left`:`right`,!1),{preventDefault:!0};case`a`:if(o)return i.selectAll(),{preventDefault:!0};break;case`c`:if(o)return i.copySelectionToClipboard(),{preventDefault:!0};break;case`F2`:return t&&!n&&this.core.startEdit(t.row,t.col),{preventDefault:!0};case`Delete`:case`Backspace`:if(t&&!n)return this.core.startEdit(t.row,t.col),{preventDefault:!0};break;default:t&&!n&&!o&&e.key.length===1&&this.core.startEdit(t.row,t.col);break}return{preventDefault:!1}}findColumnAtX(e,t){for(let n=0;n<t.length-1;n++)if(e>=t[n]&&e<t[n+1])return n;return e>=t[t.length-1]?t.length-2:0}calculateAutoScroll(e,t,n,r,i){let a=0,o=0;return e<40+i?o=-10:e>n-40&&(o=10),t<40?a=-10:t>r-40&&(a=10),a!==0||o!==0?{dx:a,dy:o}:null}};const a=1e7;var o=class{columns;dataSource;rowHeight;headerHeight;overscan;sortingEnabled;scrollTop=0;scrollLeft=0;viewportWidth=800;viewportHeight=600;cachedRows=new Map;totalRows=0;currentPageIndex=0;pageSize=1e6;sortModel=[];filterModel={};openFilterColIndex=null;selection;fill;input;slotPool;editManager;columnPositions=[];listeners=[];batchListeners=[];naturalContentHeight=0;virtualContentHeight=0;scrollRatio=1;isDestroyed=!1;constructor(a){this.columns=a.columns,this.dataSource=a.dataSource,this.rowHeight=a.rowHeight,this.headerHeight=a.headerHeight??a.rowHeight,this.overscan=a.overscan??3,this.sortingEnabled=a.sortingEnabled??!0,this.computeColumnPositions(),this.selection=new e({getRowCount:()=>this.totalRows,getColumnCount:()=>this.columns.length,getCellValue:(e,t)=>this.getCellValue(e,t),getRowData:e=>this.cachedRows.get(e),getColumn:e=>this.columns[e]}),this.selection.onInstruction(e=>this.emit(e)),this.fill=new t({getRowCount:()=>this.totalRows,getColumnCount:()=>this.columns.length,getCellValue:(e,t)=>this.getCellValue(e,t),getColumn:e=>this.columns[e],setCellValue:(e,t,n)=>this.setCellValue(e,t,n)}),this.fill.onInstruction(e=>this.emit(e)),this.slotPool=new n({getRowHeight:()=>this.rowHeight,getHeaderHeight:()=>this.headerHeight,getOverscan:()=>this.overscan,getScrollTop:()=>this.scrollTop,getViewportHeight:()=>this.viewportHeight,getTotalRows:()=>this.totalRows,getScrollRatio:()=>this.scrollRatio,getVirtualContentHeight:()=>this.virtualContentHeight,getRowData:e=>this.cachedRows.get(e)}),this.slotPool.onBatchInstruction(e=>this.emitBatch(e)),this.editManager=new r({getColumn:e=>this.columns[e],getCellValue:(e,t)=>this.getCellValue(e,t),setCellValue:(e,t,n)=>this.setCellValue(e,t,n),onCommit:e=>{this.slotPool.updateSlot(e)}}),this.editManager.onInstruction(e=>this.emit(e)),this.input=new i(this,{getHeaderHeight:()=>this.headerHeight,getRowHeight:()=>this.rowHeight,getColumnPositions:()=>this.columnPositions,getColumnCount:()=>this.columns.length})}onInstruction(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter(t=>t!==e)}}onBatchInstruction(e){return this.batchListeners.push(e),()=>{this.batchListeners=this.batchListeners.filter(t=>t!==e)}}emit(e){for(let t of this.listeners)t(e);for(let t of this.batchListeners)t([e])}emitBatch(e){if(e.length!==0){for(let t of this.batchListeners)t(e);for(let t of e)for(let e of this.listeners)e(t)}}async initialize(){await this.fetchData(),this.slotPool.syncSlots(),this.emitContentSize(),this.emitHeaders()}setViewport(e,t,n,r){let i=this.scrollRatio<1?e/this.scrollRatio:e,a=this.viewportWidth!==n||this.viewportHeight!==r;if(!(this.scrollTop!==i||this.scrollLeft!==t||a))return;this.scrollTop=i,this.scrollLeft=t,this.viewportWidth=n,this.viewportHeight=r,this.slotPool.syncSlots();let o=this.getVisibleRowRange();this.emit({type:`UPDATE_VISIBLE_RANGE`,start:o.start,end:o.end}),a&&this.emitContentSize()}async fetchData(){this.emit({type:`DATA_LOADING`});try{let e={pagination:{pageIndex:this.currentPageIndex,pageSize:this.pageSize},sort:this.sortModel.length>0?this.sortModel:void 0,filter:Object.keys(this.filterModel).length>0?this.filterModel:void 0},t=await this.dataSource.fetch(e);this.cachedRows.clear(),t.rows.forEach((e,t)=>{this.cachedRows.set(this.currentPageIndex*this.pageSize+t,e)}),this.totalRows=t.totalRows,t.totalRows>t.rows.length&&this.currentPageIndex===0&&await this.fetchAllData(),this.emit({type:`DATA_LOADED`,totalRows:this.totalRows})}catch(e){this.emit({type:`DATA_ERROR`,error:e instanceof Error?e.message:String(e)})}}async fetchAllData(){let e=Math.ceil(this.totalRows/this.pageSize);for(let t=1;t<e;t++){let e={pagination:{pageIndex:t,pageSize:this.pageSize},sort:this.sortModel.length>0?this.sortModel:void 0,filter:Object.keys(this.filterModel).length>0?this.filterModel:void 0};(await this.dataSource.fetch(e)).rows.forEach((e,n)=>{this.cachedRows.set(t*this.pageSize+n,e)})}}async setSort(e,t,n=!1){if(!this.sortingEnabled||this.columns.find(t=>(t.colId??t.field)===e)?.sortable===!1)return;let r=this.sortModel.findIndex(t=>t.colId===e);n?t===null?r>=0&&this.sortModel.splice(r,1):r>=0?this.sortModel[r].direction=t:this.sortModel.push({colId:e,direction:t}):this.sortModel=t===null?[]:[{colId:e,direction:t}],await this.fetchData(),this.slotPool.refreshAllSlots(),this.emitHeaders()}async setFilter(e,t){this.columns.find(t=>(t.colId??t.field)===e)?.filterable!==!1&&(t===null||typeof t==`string`&&t.trim()===``||typeof t==`object`&&t.conditions&&t.conditions.length===0?delete this.filterModel[e]:typeof t==`string`?this.filterModel[e]={conditions:[{type:`text`,operator:`contains`,value:t}],combination:`and`}:this.filterModel[e]=t,await this.fetchData(),this.slotPool.refreshAllSlots(),this.emitContentSize(),this.emitHeaders())}hasActiveFilter(e){let t=this.filterModel[e];return t?t.conditions.length>0:!1}isColumnSortable(e){return this.sortingEnabled?this.columns[e]?.sortable!==!1:!1}isColumnFilterable(e){return this.columns[e]?.filterable!==!1}getDistinctValuesForColumn(e,t=500){let n=this.columns.find(t=>(t.colId??t.field)===e);if(!n)return[];let r=new Map;for(let e of this.cachedRows.values()){let i=this.getFieldValue(e,n.field);if(Array.isArray(i)){let e=[...i].sort((e,t)=>String(e).localeCompare(String(t),void 0,{numeric:!0,sensitivity:`base`})),n=JSON.stringify(e);if(!r.has(n)&&(r.set(n,e),r.size>=t))break}else{let e=JSON.stringify(i);if(!r.has(e)&&(r.set(e,i),r.size>=t))break}}let i=Array.from(r.values());return i.sort((e,t)=>{let n=Array.isArray(e)?e.join(`, `):String(e??``),r=Array.isArray(t)?t.join(`, `):String(t??``);return n.localeCompare(r,void 0,{numeric:!0,sensitivity:`base`})}),i}openFilterPopup(e,t){if(this.openFilterColIndex===e){this.closeFilterPopup();return}let n=this.columns[e];if(!n||!this.isColumnFilterable(e))return;let r=n.colId??n.field,i=this.getDistinctValuesForColumn(r);this.openFilterColIndex=e,this.emit({type:`OPEN_FILTER_POPUP`,colIndex:e,column:n,anchorRect:t,distinctValues:i,currentFilter:this.filterModel[r]})}closeFilterPopup(){this.openFilterColIndex=null,this.emit({type:`CLOSE_FILTER_POPUP`})}getSortModel(){return[...this.sortModel]}getFilterModel(){return{...this.filterModel}}startEdit(e,t){this.editManager.startEdit(e,t)}updateEditValue(e){this.editManager.updateValue(e)}commitEdit(){this.editManager.commit()}cancelEdit(){this.editManager.cancel()}getEditState(){return this.editManager.getState()}getCellValue(e,t){let n=this.cachedRows.get(e);if(!n)return null;let r=this.columns[t];return r?this.getFieldValue(n,r.field):null}setCellValue(e,t,n){let r=this.cachedRows.get(e);if(!r||typeof r!=`object`)return;let i=this.columns[t];i&&this.setFieldValue(r,i.field,n)}getFieldValue(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return null;r=r[e]}return r??null}setFieldValue(e,t,n){let r=t.split(`.`),i=e;for(let e=0;e<r.length-1;e++){let t=r[e];t in i||(i[t]={}),i=i[t]}let a=r[r.length-1];i[a]=n}computeColumnPositions(){this.columnPositions=[0];let e=0;for(let t of this.columns)e+=t.width,this.columnPositions.push(e)}emitContentSize(){let e=this.columnPositions[this.columnPositions.length-1]??0;this.naturalContentHeight=this.totalRows*this.rowHeight+this.headerHeight,this.naturalContentHeight>a?(this.virtualContentHeight=a,this.scrollRatio=a/this.naturalContentHeight):(this.virtualContentHeight=this.naturalContentHeight,this.scrollRatio=1),this.emit({type:`SET_CONTENT_SIZE`,width:e,height:this.virtualContentHeight,viewportWidth:this.viewportWidth})}emitHeaders(){let e=new Map;this.sortModel.forEach((t,n)=>{e.set(t.colId,{direction:t.direction,index:n+1})});for(let t=0;t<this.columns.length;t++){let n=this.columns[t],r=n.colId??n.field,i=e.get(r);this.emit({type:`UPDATE_HEADER`,colIndex:t,column:n,sortDirection:i?.direction,sortIndex:i?.index,sortable:this.isColumnSortable(t),filterable:this.isColumnFilterable(t),hasFilter:this.hasActiveFilter(r)})}}getColumns(){return this.columns}getColumnPositions(){return[...this.columnPositions]}getRowCount(){return this.totalRows}getRowHeight(){return this.rowHeight}getHeaderHeight(){return this.headerHeight}getTotalWidth(){return this.columnPositions[this.columnPositions.length-1]??0}getTotalHeight(){return this.virtualContentHeight||this.totalRows*this.rowHeight+this.headerHeight}isScalingActive(){return this.scrollRatio<1}getNaturalHeight(){return this.naturalContentHeight||this.totalRows*this.rowHeight+this.headerHeight}getScrollRatio(){return this.scrollRatio}getVisibleRowRange(){let e=this.viewportHeight-this.headerHeight,t=Math.max(0,Math.floor(this.scrollTop/this.rowHeight)),n=Math.min(this.totalRows-1,Math.ceil((this.scrollTop+e)/this.rowHeight)-1);return{start:t,end:Math.max(t,n)}}getScrollTopForRow(e){return e*this.rowHeight*this.scrollRatio}getRowIndexAtDisplayY(e,t){let n=e+(this.scrollRatio<1?t/this.scrollRatio:t);return Math.floor(n/this.rowHeight)}getRowData(e){return this.cachedRows.get(e)}async refresh(){await this.fetchData(),this.slotPool.refreshAllSlots(),this.emitContentSize();let e=this.getVisibleRowRange();this.emit({type:`UPDATE_VISIBLE_RANGE`,start:e.start,end:e.end})}refreshSlotData(){this.slotPool.refreshAllSlots()}async setDataSource(e){this.dataSource=e,await this.refresh()}setColumns(e){this.columns=e,this.computeColumnPositions(),this.emitContentSize(),this.emitHeaders(),this.slotPool.syncSlots()}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.slotPool.destroy(),this.cachedRows.clear(),this.listeners=[],this.batchListeners=[],this.totalRows=0,this.sortModel=[],this.filterModel={})}},s=class{workerCode;maxWorkers;workers=[];workerUrl=null;nextRequestId=0;isTerminated=!1;constructor(e,t={}){this.workerCode=e,this.maxWorkers=t.maxWorkers??(typeof navigator<`u`?navigator.hardwareConcurrency:4)??4,t.preWarm&&this.preWarmWorkers()}getPoolSize(){return this.workers.length}getMaxWorkers(){return this.maxWorkers}isAvailable(){return!this.isTerminated&&typeof Worker<`u`}async execute(e,t){if(this.isTerminated)throw Error(`WorkerPool has been terminated`);if(typeof Worker>`u`)throw Error(`Web Workers are not available in this environment`);let n=this.getAvailableWorker(),r=this.nextRequestId++,i={...e,id:r};return new Promise((e,a)=>{n.pendingRequests.set(r,{resolve:e,reject:a}),n.busy=!0,t&&t.length>0?n.worker.postMessage(i,t):n.worker.postMessage(i)})}async executeParallel(e){if(this.isTerminated)throw Error(`WorkerPool has been terminated`);if(e.length===0)return[];let t=Math.min(e.length,this.maxWorkers);this.ensureWorkers(t);let n=e.map((e,t)=>{let n=t%this.workers.length,r=this.workers[n],i=this.nextRequestId++,a={...e.request,id:i};return new Promise((t,n)=>{r.pendingRequests.set(i,{resolve:t,reject:n}),r.busy=!0,e.transferables&&e.transferables.length>0?r.worker.postMessage(a,e.transferables):r.worker.postMessage(a)})});return Promise.all(n)}terminate(){for(let e of this.workers){e.worker.terminate();for(let[,t]of e.pendingRequests)t.reject(Error(`Worker pool terminated`));e.pendingRequests.clear()}this.workers=[],this.workerUrl&&=(URL.revokeObjectURL(this.workerUrl),null),this.isTerminated=!0}preWarmWorkers(){this.ensureWorkers(this.maxWorkers)}ensureWorkers(e){let t=Math.min(e,this.maxWorkers)-this.workers.length;for(let e=0;e<t;e++)this.createWorker()}getAvailableWorker(){return this.workers.find(e=>!e.busy)||(this.workers.length<this.maxWorkers?this.createWorker():this.workers.reduce((e,t)=>t.pendingRequests.size<e.pendingRequests.size?t:e))}createWorker(){if(!this.workerUrl){let e=new Blob([this.workerCode],{type:`application/javascript`});this.workerUrl=URL.createObjectURL(e)}let e=new Worker(this.workerUrl),t={worker:e,busy:!1,pendingRequests:new Map};return e.onmessage=e=>{let{id:n}=e.data,r=t.pendingRequests.get(n);r&&(t.pendingRequests.delete(n),t.pendingRequests.size===0&&(t.busy=!1),e.data.type===`error`?r.reject(Error(e.data.error)):r.resolve(e.data))},e.onerror=e=>{for(let[,n]of t.pendingRequests)n.reject(Error(`Worker error: ${e.message}`));t.pendingRequests.clear(),t.busy=!1,this.respawnWorker(t)},this.workers.push(t),t}respawnWorker(e){let t=this.workers.indexOf(e);if(t!==-1){try{e.worker.terminate()}catch{}this.workers.splice(t,1),this.workers.length<this.maxWorkers&&!this.isTerminated&&this.createWorker()}}};function c(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return null;r=r[e]}return r??null}function l(e,t){if(e==null&&t==null)return 0;if(e==null)return 1;if(t==null)return-1;let n=Number(e),r=Number(t);return!isNaN(n)&&!isNaN(r)?n-r:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():String(e).localeCompare(String(t))}function u(e,t){return[...e].sort((e,n)=>{for(let{colId:r,direction:i}of t){let t=l(c(e,r),c(n,r));if(t!==0)return i===`asc`?t:-t}return 0})}typeof self<`u`&&self.onmessage!==void 0&&(self.onmessage=e=>{let{type:t,id:n,data:r,sortModel:i}=e.data;if(t===`sort`)try{let e=u(r,i);self.postMessage({type:`sorted`,id:n,data:e})}catch(e){self.postMessage({type:`error`,id:n,error:String(e)})}});var d=class{heap=[];multiplier;constructor(e){this.multiplier=e===`asc`?1:-1}push(e){this.heap.push(e),this.bubbleUp(this.heap.length-1)}pop(){if(this.heap.length===0)return;let e=this.heap[0],t=this.heap.pop();return this.heap.length>0&&t&&(this.heap[0]=t,this.bubbleDown(0)),e}size(){return this.heap.length}bubbleUp(e){for(;e>0;){let t=Math.floor((e-1)/2);if(this.compare(this.heap[e],this.heap[t])>=0)break;this.swap(e,t),e=t}}bubbleDown(e){let t=this.heap.length;for(;;){let n=2*e+1,r=2*e+2,i=e;if(n<t&&this.compare(this.heap[n],this.heap[i])<0&&(i=n),r<t&&this.compare(this.heap[r],this.heap[i])<0&&(i=r),i===e)break;this.swap(e,i),e=i}}compare(e,t){return(e.value-t.value)*this.multiplier}swap(e,t){let n=this.heap[e];this.heap[e]=this.heap[t],this.heap[t]=n}},f=class{heap=[];directions;constructor(e){this.directions=e}push(e){this.heap.push(e),this.bubbleUp(this.heap.length-1)}pop(){if(this.heap.length===0)return;let e=this.heap[0],t=this.heap.pop();return this.heap.length>0&&t&&(this.heap[0]=t,this.bubbleDown(0)),e}size(){return this.heap.length}bubbleUp(e){for(;e>0;){let t=Math.floor((e-1)/2);if(this.compare(this.heap[e],this.heap[t])>=0)break;this.swap(e,t),e=t}}bubbleDown(e){let t=this.heap.length;for(;;){let n=2*e+1,r=2*e+2,i=e;if(n<t&&this.compare(this.heap[n],this.heap[i])<0&&(i=n),r<t&&this.compare(this.heap[r],this.heap[i])<0&&(i=r),i===e)break;this.swap(e,i),e=i}}compare(e,t){for(let n=0;n<this.directions.length;n++){let r=(e.values[n]-t.values[n])*this.directions[n];if(r!==0)return r}return 0}swap(e,t){let n=this.heap[e];this.heap[e]=this.heap[t],this.heap[t]=n}};function p(e,t){if(e.length===0)return new Uint32Array;if(e.length===1){let t=e[0],n=new Uint32Array(t.indices.length);for(let e=0;e<t.indices.length;e++)n[e]=t.indices[e]+t.offset;return n}let n=0;for(let t of e)n+=t.indices.length;let r=new Uint32Array(n),i=new d(t);for(let t=0;t<e.length;t++){let n=e[t];if(n.indices.length>0){let e=n.indices[0];i.push({chunkIndex:t,positionInChunk:0,value:n.values[0],globalIndex:e+n.offset})}}let a=0;for(;i.size()>0;){let t=i.pop();r[a++]=t.globalIndex;let n=e[t.chunkIndex],o=t.positionInChunk+1;if(o<n.indices.length){let e=n.indices[o];i.push({chunkIndex:t.chunkIndex,positionInChunk:o,value:n.values[o],globalIndex:e+n.offset})}}return r}function m(e){if(e.length===0)return new Uint32Array;if(e.length===1){let t=e[0],n=new Uint32Array(t.indices.length);for(let e=0;e<t.indices.length;e++)n[e]=t.indices[e]+t.offset;return n}let t=e[0].directions,n=t.length,r=0;for(let t of e)r+=t.indices.length;let i=new Uint32Array(r),a=new f(t);for(let t=0;t<e.length;t++){let r=e[t];if(r.indices.length>0){let e=r.indices[0],i=[];for(let e=0;e<n;e++)i.push(r.columns[e][0]);a.push({chunkIndex:t,positionInChunk:0,values:i,globalIndex:e+r.offset})}}let o=0;for(;a.size()>0;){let t=a.pop();i[o++]=t.globalIndex;let r=e[t.chunkIndex],s=t.positionInChunk+1;if(s<r.indices.length){let e=r.indices[s],i=[];for(let e=0;e<n;e++)i.push(r.columns[e][s]);a.push({chunkIndex:t.chunkIndex,positionInChunk:s,values:i,globalIndex:e+r.offset})}}return i}function h(e,t){if(e.length<=1)return new Uint32Array;let n=[],r=0;for(let t=0;t<e.length-1;t++){let i=e[t],a=e[t+1];if(i.indices.length===0||a.indices.length===0){r+=i.indices.length;continue}let o=i.indices.length-1,s=i.values[o],c=a.values[0];if(s===c){let e=o;for(;e>0&&i.values[e-1]===s;)e--;let t=0;for(;t<a.indices.length-1&&a.values[t+1]===c;)t++;let l=r+e,u=r+i.indices.length+t+1;n.push(l,u)}r+=i.indices.length}return new Uint32Array(n)}var g=class{pool;parallelThreshold;minChunkSize;isTerminated=!1;constructor(e={}){this.pool=new s(`
|
|
1
|
+
const e=e=>{let t=[0],n=0;for(let r of e)n+=r.width,t.push(n);return t},t=e=>e[e.length-1]??0,n=(n,r)=>{let i=e(n),a=t(i);if(r<=a||a===0)return{positions:i,widths:n.map(e=>e.width)};let o=r/a,s=n.map(e=>e.width*o),c=[0],l=0;for(let e of s)l+=e,c.push(l);return{positions:c,widths:s}},r=(e,t)=>{for(let n=0;n<t.length-1;n++)if(e>=t[n]&&e<t[n+1])return n;return e>=t[t.length-1]?t.length-2:0},i=e=>({minRow:Math.min(e.startRow,e.endRow),maxRow:Math.max(e.startRow,e.endRow),minCol:Math.min(e.startCol,e.endCol),maxCol:Math.max(e.startCol,e.endCol)}),a=(e,t,n)=>e>=n.minRow&&e<=n.maxRow&&t>=n.minCol&&t<=n.maxCol,o=(e,t,n)=>n?a(e,t,i(n)):!1,s=(e,t,n)=>n?.row===e&&n?.col===t,c=(e,t)=>!t||t.end<0||t.start>t.end?!0:e>=t.start&&e<=t.end,l=(e,t,n)=>n?.row===e&&n?.col===t,u=(e,t,n,r,a)=>{if(!n||!r||!a)return!1;let{minRow:o,maxRow:s,minCol:c,maxCol:l}=i(r),u=a.row>s,d=a.row<o;return u?e>s&&e<=a.row&&t>=c&&t<=l:d?e<o&&e>=a.row&&t>=c&&t<=l:!1},d=(e,t,n,r)=>{let i=[`gp-grid-cell`];return e&&i.push(`gp-grid-cell--active`),t&&!e&&i.push(`gp-grid-cell--selected`),n&&i.push(`gp-grid-cell--editing`),r&&i.push(`gp-grid-cell--fill-preview`),i.join(` `)},f=(e,t)=>{if(!t)return!1;let{minRow:n,maxRow:r}=i(t);return e>=n&&e<=r},p=(e,t)=>{if(!t)return!1;let{minCol:n,maxCol:r}=i(t);return e>=n&&e<=r},m=(e,t)=>{let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return null;r=r[e]}return r??null},h=(e,t,n)=>{let r=t.split(`.`),i=e;for(let e=0;e<r.length-1;e++){let t=r[e];t in i||(i[t]={}),i=i[t]}let a=r[r.length-1];i[a]=n},g=()=>{let e=[];return{onInstruction:t=>(e.push(t),()=>{e=e.filter(e=>e!==t)}),emit:t=>{for(let n of e)n(t)},clearListeners:()=>{e=[]}}},_=()=>{let e=[],t=[];return{onInstruction:t=>(e.push(t),()=>{e=e.filter(e=>e!==t)}),onBatchInstruction:e=>(t.push(e),()=>{t=t.filter(t=>t!==e)}),emit:n=>{for(let t of e)t(n);for(let e of t)e([n])},emitBatch:n=>{if(n.length!==0){for(let e of t)e(n);for(let t of n)for(let n of e)n(t)}},clearListeners:()=>{e=[],t=[]}}};var v=class{state={activeCell:null,range:null,anchor:null,selectionMode:!1};options;emitter=g();onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;constructor(e){this.options=e}getState(){return{...this.state}}getActiveCell(){return this.state.activeCell}getSelectionRange(){return this.state.range}isSelected(e,t){let{range:n}=this.state;if(!n)return!1;let{minRow:r,maxRow:a,minCol:o,maxCol:s}=i(n);return e>=r&&e<=a&&t>=o&&t<=s}isActiveCell(e,t){let{activeCell:n}=this.state;return n?.row===e&&n?.col===t}startSelection(e,t={}){let{shift:n=!1,ctrl:r=!1}=t,{row:i,col:a}=this.clampPosition(e);n&&this.state.anchor?(this.state.range={startRow:this.state.anchor.row,startCol:this.state.anchor.col,endRow:i,endCol:a},this.state.activeCell={row:i,col:a}):(this.state.activeCell={row:i,col:a},this.state.anchor={row:i,col:a},this.state.range=null),this.state.selectionMode=r,this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell}),this.emit({type:`SET_SELECTION_RANGE`,range:this.state.range})}moveFocus(e,t=!1){if(!this.state.activeCell){this.startSelection({row:0,col:0});return}let{row:n,col:r}=this.state.activeCell,i=n,a=r;switch(e){case`up`:i=Math.max(0,n-1);break;case`down`:i=Math.min(this.options.getRowCount()-1,n+1);break;case`left`:a=Math.max(0,r-1);break;case`right`:a=Math.min(this.options.getColumnCount()-1,r+1);break}t?(this.state.anchor||(this.state.anchor={row:n,col:r}),this.state.range={startRow:this.state.anchor.row,startCol:this.state.anchor.col,endRow:i,endCol:a},this.state.activeCell={row:i,col:a},this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell}),this.emit({type:`SET_SELECTION_RANGE`,range:this.state.range})):(this.state.activeCell={row:i,col:a},this.state.anchor={row:i,col:a},this.state.range=null,this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell}),this.emit({type:`SET_SELECTION_RANGE`,range:null}))}selectAll(){let e=this.options.getRowCount(),t=this.options.getColumnCount();e===0||t===0||(this.state.range={startRow:0,startCol:0,endRow:e-1,endCol:t-1},this.state.activeCell||(this.state.activeCell={row:0,col:0},this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell})),this.emit({type:`SET_SELECTION_RANGE`,range:this.state.range}))}clearSelection(){this.state.activeCell=null,this.state.range=null,this.state.anchor=null,this.state.selectionMode=!1,this.emit({type:`SET_ACTIVE_CELL`,position:null}),this.emit({type:`SET_SELECTION_RANGE`,range:null})}setActiveCell(e,t){let n=this.clampPosition({row:e,col:t});this.state.activeCell=n,this.state.anchor=n,this.state.range=null,this.emit({type:`SET_ACTIVE_CELL`,position:this.state.activeCell}),this.emit({type:`SET_SELECTION_RANGE`,range:null})}setSelectionRange(e){this.state.range=e,this.emit({type:`SET_SELECTION_RANGE`,range:this.state.range})}getSelectedData(){let{range:e,activeCell:t}=this.state;if(!e&&!t)return[];let{minRow:n,maxRow:r,minCol:a,maxCol:o}=i(e||{startRow:t.row,startCol:t.col,endRow:t.row,endCol:t.col}),s=[];for(let e=n;e<=r;e++){let t=[];for(let n=a;n<=o;n++)t.push(this.options.getCellValue(e,n));s.push(t)}return s}async copySelectionToClipboard(){if(typeof navigator>`u`||typeof document>`u`)return;let e=this.getSelectedData();if(e.length===0)return;let t=e.map(e=>e.map(e=>e==null?``:String(e)).join(` `)).join(`
|
|
2
|
+
`);try{await navigator.clipboard.writeText(t)}catch{let e=document.createElement(`textarea`);e.value=t,e.style.position=`fixed`,e.style.left=`-9999px`,document.body.appendChild(e),e.select(),document.execCommand(`copy`),document.body.removeChild(e)}}destroy(){this.emitter.clearListeners(),this.state={activeCell:null,range:null,anchor:null,selectionMode:!1}}clampPosition(e){let t=this.options.getRowCount(),n=this.options.getColumnCount();return{row:Math.max(0,Math.min(e.row,t-1)),col:Math.max(0,Math.min(e.col,n-1))}}},y=class{state=null;options;emitter=g();onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;constructor(e){this.options=e}getState(){return this.state?{...this.state}:null}isActive(){return this.state!==null}startFillDrag(e){this.state={sourceRange:e,targetRow:e.endRow,targetCol:e.endCol},this.emit({type:`START_FILL`,sourceRange:e})}updateFillDrag(e,t){if(!this.state)return;let n=this.options.getRowCount(),r=this.options.getColumnCount();e=Math.max(0,Math.min(e,n-1)),t=Math.max(0,Math.min(t,r-1)),this.state.targetRow=e,this.state.targetCol=t,this.emit({type:`UPDATE_FILL`,targetRow:e,targetCol:t})}commitFillDrag(){if(!this.state)return;let{sourceRange:e,targetRow:t}=this.state,n=this.calculateFilledCells(e,t);for(let{row:e,col:t,value:r}of n)this.options.setCellValue(e,t,r);this.emit({type:`COMMIT_FILL`,filledCells:n}),this.state=null}cancelFillDrag(){this.state&&(this.state=null,this.emit({type:`CANCEL_FILL`}))}destroy(){this.emitter.clearListeners(),this.state=null}calculateFilledCells(e,t){let n=[],{minRow:r,maxRow:a,minCol:o,maxCol:s}=i(e),c=t>a,l=t<r;if(c||l)for(let e=o;e<=s;e++){let i=this.getSourceColumnValues(r,a,e),o=this.detectPattern(i);if(c)for(let r=a+1;r<=t;r++){let t=r-a-1,s=this.applyPattern(o,i,t);n.push({row:r,col:e,value:s})}else if(l)for(let a=r-1;a>=t;a--){let t=r-a-1,s=this.applyPattern(o,i,t,!0);n.push({row:a,col:e,value:s})}}return n}getSourceColumnValues(e,t,n){let r=[];for(let i=e;i<=t;i++)r.push(this.options.getCellValue(i,n));return r}detectPattern(e){if(e.length===0)return{type:`constant`,value:null};if(e.length===1)return{type:`constant`,value:e[0]??null};let t=e.map(e=>typeof e==`number`?e:Number(e));if(t.every(e=>!isNaN(e))){let e=[];for(let n=1;n<t.length;n++)e.push(t[n]-t[n-1]);if(e.every(t=>t===e[0])&&e[0]!==void 0)return{type:`arithmetic`,start:t[0],step:e[0]}}return{type:`repeat`,values:e}}applyPattern(e,t,n,r=!1){switch(e.type){case`constant`:return e.value;case`arithmetic`:{let i=r?-(n+1):n+1;return(r?e.start:e.start+e.step*(t.length-1))+e.step*i}case`repeat`:{let t=e.values.length;if(t===0)return null;if(r){let r=(t-1-n%t+t)%t;return e.values[r]??null}return e.values[n%t]??null}}}},b=class{state={slots:new Map,rowToSlot:new Map,nextSlotId:0};options;emitter=_();isDestroyed=!1;onInstruction=this.emitter.onInstruction;onBatchInstruction=this.emitter.onBatchInstruction;emit=this.emitter.emit;emitBatch=this.emitter.emitBatch;constructor(e){this.options=e}getSlotForRow(e){return this.state.rowToSlot.get(e)}getSlots(){return this.state.slots}syncSlots(){let e=this.options.getScrollTop(),t=this.options.getRowHeight(),n=this.options.getViewportHeight(),r=this.options.getTotalRows(),i=this.options.getOverscan(),a=Math.max(0,Math.floor(e/t)-i),o=Math.min(r-1,Math.ceil((e+n)/t)+i);if(r===0||o<a){this.destroyAllSlots();return}let s=new Set;for(let e=a;e<=o;e++)s.add(e);let c=[],l=[];for(let[e,t]of this.state.slots)s.has(t.rowIndex)?s.delete(t.rowIndex):(l.push(e),this.state.rowToSlot.delete(t.rowIndex));let u=Array.from(s);for(let e=0;e<u.length;e++){let t=u[e],n=this.options.getRowData(t);if(e<l.length){let r=l[e],i=this.state.slots.get(r),a=this.getRowTranslateY(t);i.rowIndex=t,i.rowData=n??{},i.translateY=a,this.state.rowToSlot.set(t,r),c.push({type:`ASSIGN_SLOT`,slotId:r,rowIndex:t,rowData:n??{}}),c.push({type:`MOVE_SLOT`,slotId:r,translateY:a})}else{let e=`slot-${this.state.nextSlotId++}`,r=this.getRowTranslateY(t),i={slotId:e,rowIndex:t,rowData:n??{},translateY:r};this.state.slots.set(e,i),this.state.rowToSlot.set(t,e),c.push({type:`CREATE_SLOT`,slotId:e}),c.push({type:`ASSIGN_SLOT`,slotId:e,rowIndex:t,rowData:n??{}}),c.push({type:`MOVE_SLOT`,slotId:e,translateY:r})}}for(let e=u.length;e<l.length;e++){let t=l[e];this.state.slots.delete(t),c.push({type:`DESTROY_SLOT`,slotId:t})}for(let[e,t]of this.state.slots){let n=this.getRowTranslateY(t.rowIndex);t.translateY!==n&&(t.translateY=n,c.push({type:`MOVE_SLOT`,slotId:e,translateY:n}))}this.emitBatch(c)}destroyAllSlots(){let e=[];for(let t of this.state.slots.keys())e.push({type:`DESTROY_SLOT`,slotId:t});this.state.slots.clear(),this.state.rowToSlot.clear(),this.emitBatch(e)}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.state.slots.clear(),this.state.rowToSlot.clear(),this.emitter.clearListeners())}refreshAllSlots(){let e=[],t=this.options.getTotalRows();for(let[n,r]of this.state.slots)if(r.rowIndex>=0&&r.rowIndex<t){let t=this.options.getRowData(r.rowIndex),i=this.getRowTranslateY(r.rowIndex);r.rowData=t??{},r.translateY=i,e.push({type:`ASSIGN_SLOT`,slotId:n,rowIndex:r.rowIndex,rowData:t??{}}),e.push({type:`MOVE_SLOT`,slotId:n,translateY:i})}this.emitBatch(e),this.syncSlots()}updateSlot(e){let t=this.state.rowToSlot.get(e);if(t){let n=this.options.getRowData(e);n&&this.emit({type:`ASSIGN_SLOT`,slotId:t,rowIndex:e,rowData:n})}}getRowTranslateY(e){let t=this.options.getRowHeight(),n=this.options.getHeaderHeight(),r=this.options.getScrollRatio(),i=this.options.getVirtualContentHeight(),a=this.options.getScrollTop(),o=e*t+n;if(r>=1)return o;let s=a,c=o-(s-s*r);return Math.max(0,Math.min(c,i))}},x=class{editState=null;options;emitter=g();onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;constructor(e){this.options=e}getState(){return this.editState?{...this.editState}:null}isEditing(){return this.editState!==null}isEditingCell(e,t){return this.editState!==null&&this.editState.row===e&&this.editState.col===t}startEdit(e,t){let n=this.options.getColumn(t);if(!n||n.editable!==!0)return!1;let r=this.options.getCellValue(e,t);return this.editState={row:e,col:t,initialValue:r,currentValue:r},this.emit({type:`START_EDIT`,row:e,col:t,initialValue:r}),!0}updateValue(e){this.editState&&(this.editState.currentValue=e)}commit(){if(!this.editState)return;let{row:e,col:t,currentValue:n}=this.editState;this.options.setCellValue(e,t,n),this.emit({type:`COMMIT_EDIT`,row:e,col:t,value:n}),this.editState=null,this.emit({type:`STOP_EDIT`}),this.options.onCommit?.(e,t,n)}cancel(){this.editState=null,this.emit({type:`STOP_EDIT`})}destroy(){this.emitter.clearListeners(),this.editState=null}},ee=class{core;deps;isDraggingSelection=!1;isDraggingFill=!1;fillSourceRange=null;fillTarget=null;constructor(e,t){this.core=e,this.deps=t}updateDeps(e){this.deps={...this.deps,...e}}getDragState(){return{isDragging:this.isDraggingSelection||this.isDraggingFill,dragType:this.isDraggingFill?`fill`:this.isDraggingSelection?`selection`:null,fillSourceRange:this.fillSourceRange,fillTarget:this.fillTarget}}handleCellMouseDown(e,t,n){return n.button!==0||this.core.getEditState()!==null?{preventDefault:!1,stopPropagation:!1}:(this.core.selection.startSelection({row:e,col:t},{shift:n.shiftKey,ctrl:n.ctrlKey||n.metaKey}),{preventDefault:!1,stopPropagation:!1,focusContainer:!0,startDrag:n.shiftKey?void 0:`selection`})}handleCellDoubleClick(e,t){this.core.startEdit(e,t)}handleCellMouseEnter(e,t){this.core.highlight?.setHoverPosition({row:e,col:t})}handleCellMouseLeave(){this.core.highlight?.setHoverPosition(null)}handleFillHandleMouseDown(e,t,n){if(!e&&!t)return{preventDefault:!1,stopPropagation:!1};let r=t??{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};return this.core.fill.startFillDrag(r),this.fillSourceRange=r,this.fillTarget={row:Math.max(r.startRow,r.endRow),col:Math.max(r.startCol,r.endCol)},this.isDraggingFill=!0,{preventDefault:!0,stopPropagation:!0,startDrag:`fill`}}handleHeaderClick(e,t){let n=this.core.getSortModel().find(t=>t.colId===e)?.direction,r=n==null?`asc`:n===`asc`?`desc`:null;this.core.setSort(e,r,t)}startSelectionDrag(){this.isDraggingSelection=!0}handleDragMove(e,t){if(!this.isDraggingSelection&&!this.isDraggingFill)return null;let{top:n,left:i,width:a,height:o,scrollTop:s,scrollLeft:c}=t,l=this.deps.getHeaderHeight(),u=this.deps.getColumnPositions(),d=this.deps.getColumnCount(),f=e.clientX-i+c,p=e.clientY-n-l,m=Math.max(0,Math.min(this.core.getRowIndexAtDisplayY(p,s),this.core.getRowCount()-1)),h=Math.max(0,Math.min(r(f,u),d-1)),g=this.deps.getOriginalColumnIndex?this.deps.getOriginalColumnIndex(h):h;this.isDraggingSelection&&this.core.selection.startSelection({row:m,col:g},{shift:!0}),this.isDraggingFill&&(this.core.fill.updateFillDrag(m,g),this.fillTarget={row:m,col:g});let _=e.clientY-n,v=e.clientX-i;return{targetRow:m,targetCol:g,autoScroll:this.calculateAutoScroll(_,v,o,a,l)}}handleDragEnd(){this.isDraggingFill&&(this.core.fill.commitFillDrag(),this.core.refreshSlotData()),this.isDraggingSelection=!1,this.isDraggingFill=!1,this.fillSourceRange=null,this.fillTarget=null}handleWheel(e,t,n){return this.core.isScalingActive()?{dy:e*n,dx:t*n}:null}handleKeyDown(e,t,n,r){if(r||n&&e.key!==`Enter`&&e.key!==`Escape`&&e.key!==`Tab`)return{preventDefault:!1};let{selection:i}=this.core,a=e.shiftKey,o=e.ctrlKey||e.metaKey,s=(e=>{switch(e){case`ArrowUp`:return`up`;case`ArrowDown`:return`down`;case`ArrowLeft`:return`left`;case`ArrowRight`:return`right`;default:return null}})(e.key);if(s)return i.moveFocus(s,a),{preventDefault:!0,scrollToCell:i.getActiveCell()??void 0};switch(e.key){case`Enter`:return n?this.core.commitEdit():t&&this.core.startEdit(t.row,t.col),{preventDefault:!0};case`Escape`:return n?this.core.cancelEdit():i.clearSelection(),{preventDefault:!0};case`Tab`:return n&&this.core.commitEdit(),i.moveFocus(a?`left`:`right`,!1),{preventDefault:!0};case`a`:if(o)return i.selectAll(),{preventDefault:!0};break;case`c`:if(o)return i.copySelectionToClipboard(),{preventDefault:!0};break;case`F2`:return t&&!n&&this.core.startEdit(t.row,t.col),{preventDefault:!0};case`Delete`:case`Backspace`:if(t&&!n)return this.core.startEdit(t.row,t.col),{preventDefault:!0};break;default:t&&!n&&!o&&e.key.length===1&&this.core.startEdit(t.row,t.col);break}return{preventDefault:!1}}calculateAutoScroll(e,t,n,r,i){let a=0,o=0;return e<40+i?o=-10:e>n-40&&(o=10),t<40?a=-10:t>r-40&&(a=10),a!==0||o!==0?{dx:a,dy:o}:null}},S=class{options;highlightingOptions;hoverPosition=null;emitter=g();onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;rowClassCache=new Map;columnClassCache=new Map;cellClassCache=new Map;constructor(e,t={}){this.options=e,this.highlightingOptions=t}isEnabled(){return!!(this.highlightingOptions.computeRowClasses||this.highlightingOptions.computeColumnClasses||this.highlightingOptions.computeCellClasses)}setHoverPosition(e){this.isEnabled()&&(this.hoverPosition?.row===e?.row&&this.hoverPosition?.col===e?.col||(this.rowClassCache.clear(),this.columnClassCache.clear(),this.cellClassCache.clear(),this.hoverPosition=e,this.emit({type:`SET_HOVER_POSITION`,position:e})))}getHoverPosition(){return this.hoverPosition}onSelectionChange(){this.rowClassCache.clear(),this.columnClassCache.clear(),this.cellClassCache.clear()}buildRowContext(e,t){let n=this.options.getActiveCell(),r=this.options.getSelectionRange();return{rowIndex:e,colIndex:null,column:void 0,rowData:t,hoverPosition:this.hoverPosition,activeCell:n,selectionRange:r,isHovered:this.hoverPosition?.row===e,isActive:n?.row===e,isSelected:f(e,r)}}buildColumnContext(e,t){let n=this.options.getActiveCell(),r=this.options.getSelectionRange();return{rowIndex:null,colIndex:e,column:t,rowData:void 0,hoverPosition:this.hoverPosition,activeCell:n,selectionRange:r,isHovered:this.hoverPosition?.col===e,isActive:n?.col===e,isSelected:p(e,r)}}buildCellContext(e,t,n,r){let a=this.options.getActiveCell(),o=this.options.getSelectionRange(),s=this.hoverPosition?.row===e&&this.hoverPosition?.col===t,c=!1;if(o){let{minRow:n,maxRow:r,minCol:a,maxCol:s}=i(o);c=e>=n&&e<=r&&t>=a&&t<=s}return{rowIndex:e,colIndex:t,column:n,rowData:r,hoverPosition:this.hoverPosition,activeCell:a,selectionRange:o,isHovered:s,isActive:a?.row===e&&a?.col===t,isSelected:c}}computeRowClasses(e,t){let n=this.highlightingOptions.computeRowClasses;if(!n)return[];let r=this.rowClassCache.get(e);if(r!==void 0)return r;let i=n(this.buildRowContext(e,t));return this.rowClassCache.set(e,i),i}computeColumnClasses(e,t){let n=this.columnClassCache.get(e);if(n!==void 0)return n;let r=this.buildColumnContext(e,t),i;if(t.computeColumnClasses)i=t.computeColumnClasses(r);else if(this.highlightingOptions.computeColumnClasses)i=this.highlightingOptions.computeColumnClasses(r);else return[];return this.columnClassCache.set(e,i),i}computeCellClasses(e,t,n,r){let i=`${e},${t}`,a=this.cellClassCache.get(i);if(a!==void 0)return a;let o=this.buildCellContext(e,t,n,r),s;if(n.computeCellClasses)s=n.computeCellClasses(o);else if(this.highlightingOptions.computeCellClasses)s=this.highlightingOptions.computeCellClasses(o);else return[];return this.cellClassCache.set(i,s),s}computeCombinedCellClasses(e,t,n,r){let i=this.computeColumnClasses(t,n),a=this.computeCellClasses(e,t,n,r);return[...i,...a]}clearAllCaches(){this.rowClassCache.clear(),this.columnClassCache.clear(),this.cellClassCache.clear()}destroy(){this.emitter.clearListeners(),this.clearAllCaches(),this.hoverPosition=null}},te=class{options;emitter=g();sortModel=[];filterModel={};openFilterColIndex=null;onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;constructor(e){this.options=e}async setSort(e,t,n=!1){if(!this.options.isSortingEnabled()||this.options.getColumns().find(t=>(t.colId??t.field)===e)?.sortable===!1)return;let r=this.sortModel.findIndex(t=>t.colId===e);n?t===null?r>=0&&this.sortModel.splice(r,1):r>=0?this.sortModel[r].direction=t:this.sortModel.push({colId:e,direction:t}):this.sortModel=t===null?[]:[{colId:e,direction:t}],await this.options.onSortFilterChange(),this.options.onDataRefreshed()}getSortModel(){return[...this.sortModel]}async setFilter(e,t){this.options.getColumns().find(t=>(t.colId??t.field)===e)?.filterable!==!1&&(t===null||typeof t==`string`&&t.trim()===``||typeof t==`object`&&t.conditions&&t.conditions.length===0?delete this.filterModel[e]:typeof t==`string`?this.filterModel[e]={conditions:[{type:`text`,operator:`contains`,value:t}],combination:`and`}:this.filterModel[e]=t,await this.options.onSortFilterChange(),this.options.onDataRefreshed())}getFilterModel(){return{...this.filterModel}}hasActiveFilter(e){let t=this.filterModel[e];return t?t.conditions.length>0:!1}isColumnSortable(e){return this.options.isSortingEnabled()?this.options.getColumns()[e]?.sortable!==!1:!1}isColumnFilterable(e){return this.options.getColumns()[e]?.filterable!==!1}getDistinctValuesForColumn(e,t=500){let n=this.options.getColumns().find(t=>(t.colId??t.field)===e);if(!n)return[];let r=this.options.getCachedRows(),i=new Map;for(let e of r.values()){let r=m(e,n.field);if(Array.isArray(r)){let e=[...r].sort((e,t)=>String(e).localeCompare(String(t),void 0,{numeric:!0,sensitivity:`base`})),n=JSON.stringify(e);if(!i.has(n)&&(i.set(n,e),i.size>=t))break}else{let e=JSON.stringify(r);if(!i.has(e)&&(i.set(e,r),i.size>=t))break}}let a=Array.from(i.values());return a.sort((e,t)=>{let n=Array.isArray(e)?e.join(`, `):String(e??``),r=Array.isArray(t)?t.join(`, `):String(t??``);return n.localeCompare(r,void 0,{numeric:!0,sensitivity:`base`})}),a}openFilterPopup(e,t){if(this.openFilterColIndex===e){this.closeFilterPopup();return}let n=this.options.getColumns()[e];if(!n||!this.isColumnFilterable(e))return;let r=n.colId??n.field,i=this.getDistinctValuesForColumn(r);this.openFilterColIndex=e,this.emit({type:`OPEN_FILTER_POPUP`,colIndex:e,column:n,anchorRect:t,distinctValues:i,currentFilter:this.filterModel[r]})}closeFilterPopup(){this.openFilterColIndex=null,this.emit({type:`CLOSE_FILTER_POPUP`})}getSortInfoMap(){let e=new Map;return this.sortModel.forEach((t,n)=>{e.set(t.colId,{direction:t.direction,index:n+1})}),e}destroy(){this.emitter.clearListeners(),this.sortModel=[],this.filterModel={},this.openFilterColIndex=null}},ne=class{options;emitter=g();onInstruction=this.emitter.onInstruction;emit=this.emitter.emit;constructor(e){this.options=e}getRow(e){return this.options.getCachedRows().get(e)}addRows(e,t){if(e.length===0)return;let n=this.options.getCachedRows(),r=this.options.getTotalRows(),i=t??r,a=r+e.length;if(i<r){let t=new Map;for(let[r,a]of n)r>=i?t.set(r+e.length,a):t.set(r,a);this.options.setCachedRows(t)}let o=this.options.getCachedRows();e.forEach((e,t)=>{o.set(i+t,e)}),this.options.setTotalRows(a);let s=e.map((e,t)=>i+t);this.emit({type:`ROWS_ADDED`,indices:s,count:s.length,totalRows:a}),this.options.emitContentSize(),this.options.refreshAllSlots()}updateRows(e){if(e.length===0)return;let t=this.options.getCachedRows(),n=[];for(let r of e){let e=t.get(r.index);e&&(t.set(r.index,{...e,...r.data}),n.push(r.index))}if(n.length!==0){this.emit({type:`ROWS_UPDATED`,indices:n});for(let e of n)this.options.updateSlot(e)}}deleteRows(e){if(e.length===0)return;let t=this.options.getCachedRows(),n=this.options.getTotalRows(),r=[...e].sort((e,t)=>t-e);for(let e of r){if(e<0||e>=n)continue;t.delete(e);let r=new Map;for(let[n,i]of t)n>e?r.set(n-1,i):r.set(n,i);this.options.setCachedRows(r),n--}this.options.setTotalRows(n),this.options.clearSelectionIfInvalid(n),this.emit({type:`ROWS_REMOVED`,indices:r,totalRows:n}),this.options.emitContentSize(),this.options.refreshAllSlots()}setRow(e,t){let n=this.options.getTotalRows();e<0||e>=n||(this.options.getCachedRows().set(e,t),this.emit({type:`ROWS_UPDATED`,indices:[e]}),this.options.updateSlot(e))}destroy(){this.emitter.clearListeners()}};const C=1e7;var re=class{columns;dataSource;rowHeight;headerHeight;overscan;sortingEnabled;scrollTop=0;scrollLeft=0;viewportWidth=800;viewportHeight=600;cachedRows=new Map;totalRows=0;currentPageIndex=0;pageSize=1e6;selection;fill;input;highlight;sortFilter;rowMutation;slotPool;editManager;columnPositions=[];emitter=_();onInstruction=this.emitter.onInstruction;onBatchInstruction=this.emitter.onBatchInstruction;emit=this.emitter.emit;emitBatch=this.emitter.emitBatch;naturalContentHeight=0;virtualContentHeight=0;scrollRatio=1;isDestroyed=!1;constructor(e){this.columns=e.columns,this.dataSource=e.dataSource,this.rowHeight=e.rowHeight,this.headerHeight=e.headerHeight??e.rowHeight,this.overscan=e.overscan??3,this.sortingEnabled=e.sortingEnabled??!0,this.computeColumnPositions(),this.selection=new v({getRowCount:()=>this.totalRows,getColumnCount:()=>this.columns.length,getCellValue:(e,t)=>this.getCellValue(e,t),getRowData:e=>this.cachedRows.get(e),getColumn:e=>this.columns[e]}),this.selection.onInstruction(e=>{this.emit(e),this.highlight?.onSelectionChange()}),e.highlighting?(this.highlight=new S({getActiveCell:()=>this.selection.getActiveCell(),getSelectionRange:()=>this.selection.getSelectionRange(),getColumn:e=>this.columns[e]},e.highlighting),this.highlight.onInstruction(e=>this.emit(e))):this.highlight=null,this.fill=new y({getRowCount:()=>this.totalRows,getColumnCount:()=>this.columns.length,getCellValue:(e,t)=>this.getCellValue(e,t),getColumn:e=>this.columns[e],setCellValue:(e,t,n)=>this.setCellValue(e,t,n)}),this.fill.onInstruction(e=>this.emit(e)),this.slotPool=new b({getRowHeight:()=>this.rowHeight,getHeaderHeight:()=>this.headerHeight,getOverscan:()=>this.overscan,getScrollTop:()=>this.scrollTop,getViewportHeight:()=>this.viewportHeight,getTotalRows:()=>this.totalRows,getScrollRatio:()=>this.scrollRatio,getVirtualContentHeight:()=>this.virtualContentHeight,getRowData:e=>this.cachedRows.get(e)}),this.slotPool.onBatchInstruction(e=>this.emitBatch(e)),this.editManager=new x({getColumn:e=>this.columns[e],getCellValue:(e,t)=>this.getCellValue(e,t),setCellValue:(e,t,n)=>this.setCellValue(e,t,n),onCommit:e=>{this.slotPool.updateSlot(e)}}),this.editManager.onInstruction(e=>this.emit(e)),this.sortFilter=new te({getColumns:()=>this.columns,isSortingEnabled:()=>this.sortingEnabled,getCachedRows:()=>this.cachedRows,onSortFilterChange:async()=>{await this.fetchData(),this.highlight?.clearAllCaches(),this.slotPool.refreshAllSlots()},onDataRefreshed:()=>{this.emitContentSize(),this.emitHeaders()}}),this.sortFilter.onInstruction(e=>this.emit(e)),this.rowMutation=new ne({getCachedRows:()=>this.cachedRows,setCachedRows:e=>{this.cachedRows=e},getTotalRows:()=>this.totalRows,setTotalRows:e=>{this.totalRows=e},updateSlot:e=>this.slotPool.updateSlot(e),refreshAllSlots:()=>this.slotPool.refreshAllSlots(),emitContentSize:()=>this.emitContentSize(),clearSelectionIfInvalid:e=>{let t=this.selection.getActiveCell();t&&t.row>=e&&this.selection.clearSelection()}}),this.rowMutation.onInstruction(e=>this.emit(e)),this.input=new ee(this,{getHeaderHeight:()=>this.headerHeight,getRowHeight:()=>this.rowHeight,getColumnPositions:()=>this.columnPositions,getColumnCount:()=>this.columns.length})}async initialize(){await this.fetchData(),this.slotPool.syncSlots(),this.emitContentSize(),this.emitHeaders()}setViewport(e,t,n,r){let i=this.scrollRatio<1?e/this.scrollRatio:e,a=this.viewportWidth!==n||this.viewportHeight!==r;if(!(this.scrollTop!==i||this.scrollLeft!==t||a))return;this.scrollTop=i,this.scrollLeft=t,this.viewportWidth=n,this.viewportHeight=r,this.slotPool.syncSlots();let o=this.getVisibleRowRange();this.emit({type:`UPDATE_VISIBLE_RANGE`,start:o.start,end:o.end}),a&&this.emitContentSize()}async fetchData(){this.emit({type:`DATA_LOADING`});try{let e=this.sortFilter.getSortModel(),t=this.sortFilter.getFilterModel(),n={pagination:{pageIndex:this.currentPageIndex,pageSize:this.pageSize},sort:e.length>0?e:void 0,filter:Object.keys(t).length>0?t:void 0},r=await this.dataSource.fetch(n);this.cachedRows.clear(),r.rows.forEach((e,t)=>{this.cachedRows.set(this.currentPageIndex*this.pageSize+t,e)}),this.totalRows=r.totalRows,r.totalRows>r.rows.length&&this.currentPageIndex===0&&await this.fetchAllData(),this.emit({type:`DATA_LOADED`,totalRows:this.totalRows})}catch(e){this.emit({type:`DATA_ERROR`,error:e instanceof Error?e.message:String(e)})}}async fetchAllData(){let e=Math.ceil(this.totalRows/this.pageSize),t=this.sortFilter.getSortModel(),n=this.sortFilter.getFilterModel();for(let r=1;r<e;r++){let e={pagination:{pageIndex:r,pageSize:this.pageSize},sort:t.length>0?t:void 0,filter:Object.keys(n).length>0?n:void 0};(await this.dataSource.fetch(e)).rows.forEach((e,t)=>{this.cachedRows.set(r*this.pageSize+t,e)})}}async setSort(e,t,n=!1){return this.sortFilter.setSort(e,t,n)}async setFilter(e,t){return this.sortFilter.setFilter(e,t)}hasActiveFilter(e){return this.sortFilter.hasActiveFilter(e)}isColumnSortable(e){return this.sortFilter.isColumnSortable(e)}isColumnFilterable(e){return this.sortFilter.isColumnFilterable(e)}getDistinctValuesForColumn(e,t=500){return this.sortFilter.getDistinctValuesForColumn(e,t)}openFilterPopup(e,t){this.sortFilter.openFilterPopup(e,t)}closeFilterPopup(){this.sortFilter.closeFilterPopup()}getSortModel(){return this.sortFilter.getSortModel()}getFilterModel(){return this.sortFilter.getFilterModel()}startEdit(e,t){this.editManager.startEdit(e,t)}updateEditValue(e){this.editManager.updateValue(e)}commitEdit(){this.editManager.commit()}cancelEdit(){this.editManager.cancel()}getEditState(){return this.editManager.getState()}getCellValue(e,t){let n=this.cachedRows.get(e);if(!n)return null;let r=this.columns[t];return r?m(n,r.field):null}setCellValue(e,t,n){let r=this.cachedRows.get(e);if(!r||typeof r!=`object`)return;let i=this.columns[t];i&&h(r,i.field,n)}computeColumnPositions(){this.columnPositions=[0];let e=0;for(let t of this.columns)e+=t.width,this.columnPositions.push(e)}emitContentSize(){let e=this.columnPositions[this.columnPositions.length-1]??0;this.naturalContentHeight=this.totalRows*this.rowHeight+this.headerHeight,this.naturalContentHeight>C?(this.virtualContentHeight=C,this.scrollRatio=C/this.naturalContentHeight):(this.virtualContentHeight=this.naturalContentHeight,this.scrollRatio=1),this.emit({type:`SET_CONTENT_SIZE`,width:e,height:this.virtualContentHeight,viewportWidth:this.viewportWidth})}emitHeaders(){let e=this.sortFilter.getSortInfoMap();for(let t=0;t<this.columns.length;t++){let n=this.columns[t],r=n.colId??n.field,i=e.get(r);this.emit({type:`UPDATE_HEADER`,colIndex:t,column:n,sortDirection:i?.direction,sortIndex:i?.index,sortable:this.sortFilter.isColumnSortable(t),filterable:this.sortFilter.isColumnFilterable(t),hasFilter:this.sortFilter.hasActiveFilter(r)})}}getColumns(){return this.columns}getColumnPositions(){return[...this.columnPositions]}getRowCount(){return this.totalRows}getRowHeight(){return this.rowHeight}getHeaderHeight(){return this.headerHeight}getTotalWidth(){return this.columnPositions[this.columnPositions.length-1]??0}getTotalHeight(){return this.virtualContentHeight||this.totalRows*this.rowHeight+this.headerHeight}isScalingActive(){return this.scrollRatio<1}getNaturalHeight(){return this.naturalContentHeight||this.totalRows*this.rowHeight+this.headerHeight}getScrollRatio(){return this.scrollRatio}getVisibleRowRange(){let e=this.viewportHeight-this.headerHeight,t=Math.max(0,Math.floor(this.scrollTop/this.rowHeight)),n=Math.min(this.totalRows-1,Math.ceil((this.scrollTop+e)/this.rowHeight)-1);return{start:t,end:Math.max(t,n)}}getScrollTopForRow(e){return e*this.rowHeight*this.scrollRatio}getRowIndexAtDisplayY(e,t){let n=e+(this.scrollRatio<1?t/this.scrollRatio:t);return Math.floor(n/this.rowHeight)}getRowData(e){return this.cachedRows.get(e)}async refresh(){await this.fetchData(),this.highlight?.clearAllCaches(),this.slotPool.refreshAllSlots(),this.emitContentSize();let e=this.getVisibleRowRange();this.emit({type:`UPDATE_VISIBLE_RANGE`,start:e.start,end:e.end})}refreshSlotData(){this.slotPool.refreshAllSlots()}addRows(e,t){this.rowMutation.addRows(e,t)}updateRows(e){this.rowMutation.updateRows(e)}deleteRows(e){this.rowMutation.deleteRows(e)}getRow(e){return this.rowMutation.getRow(e)}setRow(e,t){this.rowMutation.setRow(e,t)}async setDataSource(e){this.dataSource=e,await this.refresh()}setColumns(e){this.columns=e,this.computeColumnPositions(),this.emitContentSize(),this.emitHeaders(),this.slotPool.syncSlots()}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.slotPool.destroy(),this.highlight?.destroy(),this.sortFilter.destroy(),this.rowMutation.destroy(),this.cachedRows.clear(),this.emitter.clearListeners(),this.totalRows=0)}},w=class{workerCode;maxWorkers;workers=[];workerUrl=null;nextRequestId=0;isTerminated=!1;constructor(e,t={}){this.workerCode=e,this.maxWorkers=t.maxWorkers??(typeof navigator<`u`?navigator.hardwareConcurrency:4)??4,t.preWarm&&this.preWarmWorkers()}getPoolSize(){return this.workers.length}getMaxWorkers(){return this.maxWorkers}isAvailable(){return!this.isTerminated&&typeof Worker<`u`}async execute(e,t){if(this.isTerminated)throw Error(`WorkerPool has been terminated`);if(typeof Worker>`u`)throw Error(`Web Workers are not available in this environment`);let n=this.getAvailableWorker(),r=this.nextRequestId++,i={...e,id:r};return new Promise((e,a)=>{n.pendingRequests.set(r,{resolve:e,reject:a}),n.busy=!0,t&&t.length>0?n.worker.postMessage(i,t):n.worker.postMessage(i)})}async executeParallel(e){if(this.isTerminated)throw Error(`WorkerPool has been terminated`);if(e.length===0)return[];let t=Math.min(e.length,this.maxWorkers);this.ensureWorkers(t);let n=e.map((e,t)=>{let n=t%this.workers.length,r=this.workers[n],i=this.nextRequestId++,a={...e.request,id:i};return new Promise((t,n)=>{r.pendingRequests.set(i,{resolve:t,reject:n}),r.busy=!0,e.transferables&&e.transferables.length>0?r.worker.postMessage(a,e.transferables):r.worker.postMessage(a)})});return Promise.all(n)}terminate(){for(let e of this.workers){e.worker.terminate();for(let[,t]of e.pendingRequests)t.reject(Error(`Worker pool terminated`));e.pendingRequests.clear()}this.workers=[],this.workerUrl&&=(URL.revokeObjectURL(this.workerUrl),null),this.isTerminated=!0}preWarmWorkers(){this.ensureWorkers(this.maxWorkers)}ensureWorkers(e){let t=Math.min(e,this.maxWorkers)-this.workers.length;for(let e=0;e<t;e++)this.createWorker()}getAvailableWorker(){return this.workers.find(e=>!e.busy)||(this.workers.length<this.maxWorkers?this.createWorker():this.workers.reduce((e,t)=>t.pendingRequests.size<e.pendingRequests.size?t:e))}createWorker(){if(!this.workerUrl){let e=new Blob([this.workerCode],{type:`application/javascript`});this.workerUrl=URL.createObjectURL(e)}let e=new Worker(this.workerUrl),t={worker:e,busy:!1,pendingRequests:new Map};return e.onmessage=e=>{let{id:n}=e.data,r=t.pendingRequests.get(n);r&&(t.pendingRequests.delete(n),t.pendingRequests.size===0&&(t.busy=!1),e.data.type===`error`?r.reject(Error(e.data.error)):r.resolve(e.data))},e.onerror=e=>{for(let[,n]of t.pendingRequests)n.reject(Error(`Worker error: ${e.message}`));t.pendingRequests.clear(),t.busy=!1,this.respawnWorker(t)},this.workers.push(t),t}respawnWorker(e){let t=this.workers.indexOf(e);if(t!==-1){try{e.worker.terminate()}catch{}this.workers.splice(t,1),this.workers.length<this.maxWorkers&&!this.isTerminated&&this.createWorker()}}};function T(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return null;r=r[e]}return r??null}function ie(e,t){if(e==null&&t==null)return 0;if(e==null)return 1;if(t==null)return-1;let n=Number(e),r=Number(t);return!isNaN(n)&&!isNaN(r)?n-r:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():String(e).localeCompare(String(t))}function ae(e,t){return[...e].sort((e,n)=>{for(let{colId:r,direction:i}of t){let t=ie(T(e,r),T(n,r));if(t!==0)return i===`asc`?t:-t}return 0})}typeof self<`u`&&self.onmessage!==void 0&&(self.onmessage=e=>{let{type:t,id:n,data:r,sortModel:i}=e.data;if(t===`sort`)try{let e=ae(r,i);self.postMessage({type:`sorted`,id:n,data:e})}catch(e){self.postMessage({type:`error`,id:n,error:String(e)})}});var oe=class{heap=[];multiplier;constructor(e){this.multiplier=e===`asc`?1:-1}push(e){this.heap.push(e),this.bubbleUp(this.heap.length-1)}pop(){if(this.heap.length===0)return;let e=this.heap[0],t=this.heap.pop();return this.heap.length>0&&t&&(this.heap[0]=t,this.bubbleDown(0)),e}size(){return this.heap.length}bubbleUp(e){for(;e>0;){let t=Math.floor((e-1)/2);if(this.compare(this.heap[e],this.heap[t])>=0)break;this.swap(e,t),e=t}}bubbleDown(e){let t=this.heap.length;for(;;){let n=2*e+1,r=2*e+2,i=e;if(n<t&&this.compare(this.heap[n],this.heap[i])<0&&(i=n),r<t&&this.compare(this.heap[r],this.heap[i])<0&&(i=r),i===e)break;this.swap(e,i),e=i}}compare(e,t){return(e.value-t.value)*this.multiplier}swap(e,t){let n=this.heap[e];this.heap[e]=this.heap[t],this.heap[t]=n}},se=class{heap=[];directions;constructor(e){this.directions=e}push(e){this.heap.push(e),this.bubbleUp(this.heap.length-1)}pop(){if(this.heap.length===0)return;let e=this.heap[0],t=this.heap.pop();return this.heap.length>0&&t&&(this.heap[0]=t,this.bubbleDown(0)),e}size(){return this.heap.length}bubbleUp(e){for(;e>0;){let t=Math.floor((e-1)/2);if(this.compare(this.heap[e],this.heap[t])>=0)break;this.swap(e,t),e=t}}bubbleDown(e){let t=this.heap.length;for(;;){let n=2*e+1,r=2*e+2,i=e;if(n<t&&this.compare(this.heap[n],this.heap[i])<0&&(i=n),r<t&&this.compare(this.heap[r],this.heap[i])<0&&(i=r),i===e)break;this.swap(e,i),e=i}}compare(e,t){for(let n=0;n<this.directions.length;n++){let r=(e.values[n]-t.values[n])*this.directions[n];if(r!==0)return r}return 0}swap(e,t){let n=this.heap[e];this.heap[e]=this.heap[t],this.heap[t]=n}};function E(e,t){if(e.length===0)return new Uint32Array;if(e.length===1){let t=e[0],n=new Uint32Array(t.indices.length);for(let e=0;e<t.indices.length;e++)n[e]=t.indices[e]+t.offset;return n}let n=0;for(let t of e)n+=t.indices.length;let r=new Uint32Array(n),i=new oe(t);for(let t=0;t<e.length;t++){let n=e[t];if(n.indices.length>0){let e=n.indices[0];i.push({chunkIndex:t,positionInChunk:0,value:n.values[0],globalIndex:e+n.offset})}}let a=0;for(;i.size()>0;){let t=i.pop();r[a++]=t.globalIndex;let n=e[t.chunkIndex],o=t.positionInChunk+1;if(o<n.indices.length){let e=n.indices[o];i.push({chunkIndex:t.chunkIndex,positionInChunk:o,value:n.values[o],globalIndex:e+n.offset})}}return r}function D(e){if(e.length===0)return new Uint32Array;if(e.length===1){let t=e[0],n=new Uint32Array(t.indices.length);for(let e=0;e<t.indices.length;e++)n[e]=t.indices[e]+t.offset;return n}let t=e[0].directions,n=t.length,r=0;for(let t of e)r+=t.indices.length;let i=new Uint32Array(r),a=new se(t);for(let t=0;t<e.length;t++){let r=e[t];if(r.indices.length>0){let e=r.indices[0],i=[];for(let e=0;e<n;e++)i.push(r.columns[e][0]);a.push({chunkIndex:t,positionInChunk:0,values:i,globalIndex:e+r.offset})}}let o=0;for(;a.size()>0;){let t=a.pop();i[o++]=t.globalIndex;let r=e[t.chunkIndex],s=t.positionInChunk+1;if(s<r.indices.length){let e=r.indices[s],i=[];for(let e=0;e<n;e++)i.push(r.columns[e][s]);a.push({chunkIndex:t.chunkIndex,positionInChunk:s,values:i,globalIndex:e+r.offset})}}return i}function ce(e,t){if(e.length<=1)return new Uint32Array;let n=[],r=0;for(let t=0;t<e.length-1;t++){let i=e[t],a=e[t+1];if(i.indices.length===0||a.indices.length===0){r+=i.indices.length;continue}let o=i.indices.length-1,s=i.values[o],c=a.values[0];if(s===c){let e=o;for(;e>0&&i.values[e-1]===s;)e--;let t=0;for(;t<a.indices.length-1&&a.values[t+1]===c;)t++;let l=r+e,u=r+i.indices.length+t+1;n.push(l,u)}r+=i.indices.length}return new Uint32Array(n)}var O=class{pool;parallelThreshold;minChunkSize;isTerminated=!1;constructor(e={}){this.pool=new w(`
|
|
3
3
|
// Inline sort worker code
|
|
4
4
|
function getFieldValue(row, field) {
|
|
5
5
|
const parts = field.split(".");
|
|
@@ -319,7 +319,7 @@ self.onmessage = function(e) {
|
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
321
|
};
|
|
322
|
-
`,{maxWorkers:e.maxWorkers??(typeof navigator<`u`?navigator.hardwareConcurrency:4)??4}),this.parallelThreshold=e.parallelThreshold??4e5,this.minChunkSize=e.minChunkSize??5e4}isAvailable(){return!this.isTerminated&&this.pool.isAvailable()}terminate(){this.pool.terminate(),this.isTerminated=!0}async sortIndices(e,t){if(this.isTerminated)throw Error(`ParallelSortManager has been terminated`);return e.length<this.parallelThreshold?this.sortIndicesSingle(e,t):this.sortIndicesParallel(e,t)}async sortStringHashes(e,t,n){if(this.isTerminated)throw Error(`ParallelSortManager has been terminated`);return(e[0]?.length??0)<this.parallelThreshold?this.sortStringHashesSingle(e,t,n):this.sortStringHashesParallel(e,t,n)}async sortMultiColumn(e,t){if(this.isTerminated)throw Error(`ParallelSortManager has been terminated`);return(e[0]?.length??0)<this.parallelThreshold?this.sortMultiColumnSingle(e,t):this.sortMultiColumnParallel(e,t)}async sortIndicesSingle(e,t){let n=new Float64Array(e),r={type:`sortIndices`,id:0,values:n,direction:t};return(await this.pool.execute(r,[n.buffer])).indices}async sortStringHashesSingle(e,t,n){let r={type:`sortStringHashes`,id:0,hashChunks:e,direction:t},i=e.map(e=>e.buffer),a=await this.pool.execute(r,i);return a.collisionRuns.length>0&&this.resolveCollisions(a.indices,a.collisionRuns,n,t),a.indices}async sortMultiColumnSingle(e,t){let n=e.map(e=>new Float64Array(e)),r=new Int8Array(t.map(e=>e===`asc`?1:-1)),i={type:`sortMultiColumn`,id:0,columns:n,directions:r},a=[...n.map(e=>e.buffer),r.buffer];return(await this.pool.execute(i,a)).indices}async sortIndicesParallel(e,t){let n=this.splitIntoChunks(e).map(e=>{let n=new Float64Array(e.data);return{request:{type:`sortChunk`,id:0,values:n,direction:t,chunkOffset:e.offset},transferables:[n.buffer]}}),r=await this.pool.executeParallel(n);return r.sort((e,t)=>e.chunkOffset-t.chunkOffset),p(r.map(e=>({indices:e.indices,values:e.sortedValues,offset:e.chunkOffset})),t)}async sortStringHashesParallel(e,t,n){let r=e[0].length,i=this.calculateChunkBoundaries(r).map(n=>{let r=e.map(e=>new Float64Array(e.buffer,n.offset*8,n.length)).map(e=>{let t=new Float64Array(e.length);return t.set(e),t});return{request:{type:`sortStringChunk`,id:0,hashChunks:r,direction:t,chunkOffset:n.offset},transferables:r.map(e=>e.buffer)}}),a=await this.pool.executeParallel(i);a.sort((e,t)=>e.chunkOffset-t.chunkOffset);let o=a.map(e=>({indices:e.indices,values:e.sortedHashes,offset:e.chunkOffset})),s=[];for(let e of a)for(let t=0;t<e.collisionRuns.length;t+=2)s.push(e.collisionRuns[t]+e.chunkOffset,e.collisionRuns[t+1]+e.chunkOffset);let c=p(o,t),l=this.detectBoundaryCollisionsForStrings(o,t),u=new Uint32Array([...s,...l]);return u.length>0&&this.resolveCollisions(c,u,n,t),c}async sortMultiColumnParallel(e,t){let n=e[0].length,r=this.calculateChunkBoundaries(n),i=new Int8Array(t.map(e=>e===`asc`?1:-1)),a=r.map(t=>{let n=e.map(e=>{let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t.offset+r];return n}),r=new Int8Array(i);return{request:{type:`sortMultiColumnChunk`,id:0,columns:n,directions:r,chunkOffset:t.offset},transferables:[...n.map(e=>e.buffer),r.buffer]}}),o=await this.pool.executeParallel(a);return o.sort((e,t)=>e.chunkOffset-t.chunkOffset),m(o.map(e=>({indices:e.indices,columns:e.sortedColumns,directions:i,offset:e.chunkOffset})))}splitIntoChunks(e){let t=e.length,n=this.pool.getMaxWorkers(),r=Math.max(this.minChunkSize,Math.ceil(t/n)),i=[];for(let n=0;n<t;n+=r){let a=Math.min(n+r,t);i.push({data:e.slice(n,a),offset:n})}return i}calculateChunkBoundaries(e){let t=this.pool.getMaxWorkers(),n=Math.max(this.minChunkSize,Math.ceil(e/t)),r=[];for(let t=0;t<e;t+=n)r.push({offset:t,length:Math.min(n,e-t)});return r}detectBoundaryCollisionsForStrings(e,t){if(e.length<=1)return[];let n=[],r=0;for(let t=0;t<e.length-1;t++){let i=e[t],a=e[t+1];if(i.indices.length===0||a.indices.length===0){r+=i.indices.length;continue}let o=i.values[i.indices.length-1],s=a.values[0];if(o===s){let e=i.indices.length-1;for(;e>0&&i.values[e-1]===o;)e--;let t=0;for(;t<a.indices.length-1&&a.values[t+1]===s;)t++;n.push(r+e,r+i.indices.length+t+1)}r+=i.indices.length}return n}resolveCollisions(e,t,n,r){let i=r===`asc`?1:-1;for(let r=0;r<t.length;r+=2){let a=t[r],o=t[r+1];if(o<=a||o>e.length)continue;let s=Array.from(e.slice(a,o)),c=n[s[0]],l=!0;for(let e=1;e<s.length;e++)if(n[s[e]]!==c){l=!1;break}if(!l){s.sort((e,t)=>i*n[e].localeCompare(n[t]));for(let t=0;t<s.length;t++)e[a+t]=s[t]}}}};function _(e){let t=e.toLowerCase(),n=Math.min(t.length,10),r=0;for(let e=0;e<n;e++){let n=t.charCodeAt(e),i;i=n>=97&&n<=122?n-97:n>=48&&n<=57?n-48+26:0,r=r*36+i}for(let e=n;e<10;e++)r*=36;return r}function v(e){let t=e.toLowerCase(),n=[];for(let e=0;e<3;e++){let r=e*10,i=0;for(let e=0;e<10;e++){let n=r+e,a=n<t.length?t.charCodeAt(n):0,o;o=a>=97&&a<=122?a-97:a>=48&&a<=57?a-48+26:0,i=i*36+o}n.push(i)}return n}function y(e){if(e==null)return Number.MAX_VALUE;if(Array.isArray(e))return e.length===0?Number.MAX_VALUE:_(e.join(`, `));if(typeof e==`number`)return e;if(e instanceof Date)return e.getTime();if(typeof e==`string`)return _(e);let t=Number(e);return isNaN(t)?0:t}function ee(e,t){let n=e==null||Array.isArray(e)&&e.length===0,r=t==null||Array.isArray(t)&&t.length===0;if(n&&r)return 0;if(n)return 1;if(r)return-1;if(Array.isArray(e)||Array.isArray(t)){let n=Array.isArray(e)?e.join(`, `):String(e??``),r=Array.isArray(t)?t.join(`, `):String(t??``);return n.localeCompare(r)}let i=Number(e),a=Number(t);return!isNaN(i)&&!isNaN(a)?i-a:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():String(e).localeCompare(String(t))}function b(e,t,n){return[...e].sort((e,r)=>{for(let{colId:i,direction:a}of t){let t=ee(n(e,i),n(r,i));if(t!==0)return a===`asc`?t:-t}return 0})}function x(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function S(e){return e==null||e===``||Array.isArray(e)&&e.length===0}function C(e,t){let n=S(e);if(t.selectedValues&&t.selectedValues.size>0){let r=t.includeBlank===!0&&n;if(Array.isArray(e)){let n=[...e].sort((e,t)=>String(e).localeCompare(String(t),void 0,{numeric:!0,sensitivity:`base`})).join(`, `);return t.selectedValues.has(n)||r}let i=String(e??``);return t.selectedValues.has(i)||r}let r=String(e??``).toLowerCase(),i=String(t.value??``).toLowerCase();switch(t.operator){case`contains`:return r.includes(i);case`notContains`:return!r.includes(i);case`equals`:return r===i;case`notEquals`:return r!==i;case`startsWith`:return r.startsWith(i);case`endsWith`:return r.endsWith(i);case`blank`:return n;case`notBlank`:return!n;default:return!0}}function w(e,t){let n=e==null||e===``;if(t.operator===`blank`)return n;if(t.operator===`notBlank`)return!n;if(n)return!1;let r=typeof e==`number`?e:Number(e);if(isNaN(r))return!1;let i=t.value??0,a=t.valueTo??0;switch(t.operator){case`=`:return r===i;case`!=`:return r!==i;case`>`:return r>i;case`<`:return r<i;case`>=`:return r>=i;case`<=`:return r<=i;case`between`:return r>=i&&r<=a;default:return!0}}function T(e,t){let n=e==null||e===``;if(t.operator===`blank`)return n;if(t.operator===`notBlank`)return!n;if(n)return!1;let r=e instanceof Date?e:new Date(String(e));if(isNaN(r.getTime()))return!1;let i=t.value instanceof Date?t.value:new Date(String(t.value??``)),a=t.valueTo instanceof Date?t.valueTo:new Date(String(t.valueTo??``)),o=r.getTime(),s=i.getTime(),c=a.getTime();switch(t.operator){case`=`:return x(r,i);case`!=`:return!x(r,i);case`>`:return o>s;case`<`:return o<s;case`between`:return o>=s&&o<=c;default:return!0}}function E(e,t){switch(t.type){case`text`:return C(e,t);case`number`:return w(e,t);case`date`:return T(e,t);default:return!0}}function D(e,t){if(!t.conditions||t.conditions.length===0)return!0;let n=t.conditions[0];if(!n)return!0;let r=E(e,n);for(let n=1;n<t.conditions.length;n++){let i=t.conditions[n-1],a=t.conditions[n],o=i.nextOperator??t.combination,s=E(e,a);o===`and`?r&&=s:r||=s}return r}function O(e,t,n){let r=Object.entries(t).filter(([,e])=>e!=null);if(r.length===0)return!0;for(let[t,i]of r)if(!D(n(e,t),i))return!1;return!0}function k(e,t,n){let r=Object.entries(t).filter(([,e])=>typeof e==`string`?e.trim()!==``:e.conditions&&e.conditions.length>0);return r.length===0?e:e.filter(e=>{for(let[t,i]of r){let r=n(e,t);if(typeof i==`string`){if(!String(r??``).toLowerCase().includes(i.toLowerCase()))return!1;continue}if(!D(r,i))return!1}return!0})}function A(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return null;r=r[e]}return r??null}function j(e,t={}){let{getFieldValue:n=A,useWorker:r=!0,parallelSort:i}=t,a=e,o=!1,s=r?new g(i===!1?{maxWorkers:1}:i):null;return{async fetch(e){let t=a?[...a]:[];if(e.filter&&Object.keys(e.filter).length>0&&(t=k(t,e.filter,n)),e.sort&&e.sort.length>0)if(s&&s.isAvailable()&&t.length>=2e5){let r;if(e.sort.length===1){let{colId:i,direction:a}=e.sort[0],o=!1;for(let e of t){let t=n(e,i);if(t!=null){o=typeof t==`string`||Array.isArray(t);break}}if(o){let e=[],o=Array.from({length:3},()=>[]);for(let r of t){let t=n(r,i),a=t==null?``:Array.isArray(t)?t.join(`, `):String(t);e.push(a);let s=v(a);for(let e=0;e<3;e++)o[e].push(s[e])}let c=o.map(e=>new Float64Array(e));r=await s.sortStringHashes(c,a,e)}else{let e=t.map(e=>y(n(e,i)));r=await s.sortIndices(e,a)}}else{let i=[],a=[];for(let{colId:r,direction:o}of e.sort){let e=t.map(e=>y(n(e,r)));i.push(e),a.push(o)}r=await s.sortMultiColumn(i,a)}let i=Array(t.length);for(let e=0;e<r.length;e++)i[e]=t[r[e]];t=i}else t=b(t,e.sort,n);let r=t.length,{pageIndex:i,pageSize:o}=e.pagination,c=i*o;return{rows:t.slice(c,c+o),totalRows:r}},destroy(){o||(o=!0,a=null,s&&s.terminate())}}}function te(e){return j(e)}function ne(e){return{async fetch(t){return e(t)}}}function M(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return null;r=r[e]}return r??null}function N(e,t,n){let r=t.split(`.`),i=e;for(let e=0;e<r.length-1;e++){let t=r[e];if(typeof i!=`object`||!i)return;i=i[t]}typeof i==`object`&&i&&(i[r[r.length-1]]=n)}function P(e){let t=e.toLowerCase(),n=Math.min(t.length,10),r=0;for(let e=0;e<n;e++){let n=t.charCodeAt(e),i;i=n>=97&&n<=122?n-97:n>=48&&n<=57?n-48+26:0,r=r*36+i}for(let e=n;e<10;e++)r*=36;return r}function F(e,t){let n=e==null||Array.isArray(e)&&e.length===0,r=t==null||Array.isArray(t)&&t.length===0;if(n&&r)return 0;if(n)return 1;if(r)return-1;if(Array.isArray(e)||Array.isArray(t)){let n=Array.isArray(e)?e.join(`, `):String(e??``),r=Array.isArray(t)?t.join(`, `):String(t??``);return n.localeCompare(r)}let i=Number(e),a=Number(t);return!isNaN(i)&&!isNaN(a)?i-a:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():String(e).localeCompare(String(t))}function I(e){if(e==null)return Number.MAX_VALUE;if(typeof e==`number`)return e;if(e instanceof Date)return e.getTime();if(typeof e==`string`)return P(e);let t=Number(e);return isNaN(t)?0:t}function L(e,t){let n=[];for(let r of t.sortModel){let i=I(t.getFieldValue(e,r.colId));n.push(i)}return n}function R(e,t,n){if(!e||!t)return null;for(let r=0;r<n.length;r++){let i=e[r]-t[r];if(i!==0)return n[r].direction===`asc`?i:-i}return 0}function z(e,t,n,r){for(let{colId:i,direction:a}of n){let n=F(r(e,i),r(t,i));if(n!==0)return a===`asc`?n:-n}return 0}var B=class{rows=[];rowById=new Map;sortedIndices=[];sortModel=[];sortModelHash=``;filterModel={};filteredIndices=new Set;distinctValues=new Map;rowSortCache=new Map;options;constructor(e=[],t){this.options={getRowId:t.getRowId,getFieldValue:t.getFieldValue??M},this.setData(e)}clear(){this.rows=[],this.rowById.clear(),this.sortedIndices=[],this.filterModel={},this.filteredIndices.clear(),this.rowSortCache.clear(),this.distinctValues.clear(),this.sortModel=[],this.sortModelHash=``}setData(e){this.rows=[...e],this.rowById.clear(),this.rowSortCache.clear(),this.distinctValues.clear();for(let e=0;e<this.rows.length;e++){let t=this.rows[e],n=this.options.getRowId(t);this.rowById.set(n,e)}this.rebuildSortedIndices(),this.rebuildFilteredIndices(),this.rebuildDistinctValues()}query(e){this.setSortModel(e.sort??[]),this.setFilterModel(e.filter??{});let t=this.getVisibleIndices(),n=t.length,{pageIndex:r,pageSize:i}=e.pagination,a=r*i,o=Math.min(a+i,n),s=[];for(let e=a;e<o;e++){let n=t[e];n!==void 0&&s.push(this.rows[n])}return{rows:s,totalRows:n}}getRowById(e){let t=this.rowById.get(e);return t===void 0?void 0:this.rows[t]}getRowByIndex(e){return this.rows[e]}getTotalRowCount(){return this.rows.length}getVisibleRowCount(){return Object.keys(this.filterModel).length===0?this.rows.length:this.filteredIndices.size}getDistinctValues(e){let t=this.distinctValues.get(e);return t?Array.from(t):[]}addRows(e){for(let t of e)this.addRow(t)}addRow(e){let t=this.options.getRowId(e);if(this.rowById.has(t)){console.warn(`Row with ID ${t} already exists. Skipping.`);return}let n=this.rows.length;if(this.rows.push(e),this.rowById.set(t,n),this.updateDistinctValuesForRow(e,`add`),this.sortModel.length>0&&this.computeRowHashes(n,e),this.sortModel.length>0){let e=this.binarySearchInsertPosition(n);this.sortedIndices.splice(e,0,n)}else this.sortedIndices.push(n);this.rowPassesFilter(e)&&this.filteredIndices.add(n)}removeRows(e){let t=[];for(let n of e){let e=this.rowById.get(n);e!==void 0&&t.push(e)}if(t.length!==0){t.sort((e,t)=>t-e);for(let e of t)this.removeRowByIndex(e)}}removeRowByIndex(e){let t=this.rows[e];if(!t)return;let n=this.options.getRowId(t);this.updateDistinctValuesForRow(t,`remove`);let r=this.sortedIndices.indexOf(e);r!==-1&&this.sortedIndices.splice(r,1),this.filteredIndices.delete(e),this.rowSortCache.delete(e),this.rowById.delete(n),this.rows.splice(e,1),this.reindexAfterRemoval(e)}reindexAfterRemoval(e){for(let[t,n]of this.rowById.entries())n>e&&this.rowById.set(t,n-1);for(let t=0;t<this.sortedIndices.length;t++)this.sortedIndices[t]>e&&this.sortedIndices[t]--;let t=new Set;for(let n of this.filteredIndices)n>e?t.add(n-1):t.add(n);this.filteredIndices=t;let n=new Map;for(let[t,r]of this.rowSortCache)t>e?n.set(t-1,r):n.set(t,r);this.rowSortCache=n}updateCell(e,t,n){let r=this.rowById.get(e);if(r===void 0){console.warn(`Row with ID ${e} not found.`);return}let i=this.rows[r],a=this.options.getFieldValue(i,t);if(N(i,t,n),this.updateDistinctValueForField(t,a,n),this.sortModel.some(e=>e.colId===t)&&this.sortModel.length>0){this.computeRowHashes(r,i);let e=this.sortedIndices.indexOf(r);e!==-1&&this.sortedIndices.splice(e,1);let t=this.binarySearchInsertPosition(r);this.sortedIndices.splice(t,0,r)}t in this.filterModel&&(this.rowPassesFilter(i)?this.filteredIndices.add(r):this.filteredIndices.delete(r))}updateRow(e,t){for(let[n,r]of Object.entries(t))this.updateCell(e,n,r)}setSortModel(e){let t=JSON.stringify(e);t!==this.sortModelHash&&(this.sortModelHash=t,this.sortModel=[...e],this.rebuildHashCache(),this.rebuildSortedIndices())}getSortModel(){return[...this.sortModel]}setFilterModel(e){JSON.stringify(e)!==JSON.stringify(this.filterModel)&&(this.filterModel={...e},this.rebuildFilteredIndices())}getFilterModel(){return{...this.filterModel}}rebuildSortedIndices(){this.sortedIndices=Array.from({length:this.rows.length},(e,t)=>t),this.sortModel.length!==0&&this.sortedIndices.sort((e,t)=>this.compareRows(e,t))}rebuildHashCache(){if(this.rowSortCache.clear(),this.sortModel.length!==0)for(let e=0;e<this.rows.length;e++)this.computeRowHashes(e,this.rows[e])}computeRowHashes(e,t){if(this.sortModel.length===0)return;let n=L(t,{sortModel:this.sortModel,sortModelHash:this.sortModelHash,getFieldValue:this.options.getFieldValue}),r=this.rowSortCache.get(e);r||(r={hashes:new Map},this.rowSortCache.set(e,r)),r.hashes.set(this.sortModelHash,n)}compareRows(e,t){let n=this.rowSortCache.get(e),r=this.rowSortCache.get(t),i=n?.hashes.get(this.sortModelHash),a=r?.hashes.get(this.sortModelHash),o=R(i,a,this.sortModel);return o===null?z(this.rows[e],this.rows[t],this.sortModel,this.options.getFieldValue):o}binarySearchInsertPosition(e){let t=0,n=this.sortedIndices.length;for(;t<n;){let r=t+n>>>1,i=this.sortedIndices[r];this.compareRows(e,i)>0?t=r+1:n=r}return t}rebuildFilteredIndices(){if(this.filteredIndices.clear(),Object.entries(this.filterModel).filter(([,e])=>e!=null).length!==0)for(let e=0;e<this.rows.length;e++)this.rowPassesFilter(this.rows[e])&&this.filteredIndices.add(e)}rowPassesFilter(e){return O(e,this.filterModel,this.options.getFieldValue)}getVisibleIndices(){return Object.entries(this.filterModel).filter(([,e])=>e!=null).length>0?this.sortedIndices.filter(e=>this.filteredIndices.has(e)):this.sortedIndices}rebuildDistinctValues(){this.distinctValues.clear();for(let e of this.rows)this.updateDistinctValuesForRow(e,`add`)}updateDistinctValuesForRow(e,t){if(!(typeof e!=`object`||!e)){for(let[n,r]of Object.entries(e))if(r!=null&&t===`add`){let e=this.distinctValues.get(n);if(e||(e=new Set,this.distinctValues.set(n,e)),Array.isArray(r))for(let t of r)t!=null&&e.add(t);else e.add(r)}}}updateDistinctValueForField(e,t,n){if(n!=null){let t=this.distinctValues.get(e);if(t||(t=new Set,this.distinctValues.set(e,t)),Array.isArray(n))for(let e of n)e!=null&&t.add(e);else t.add(n)}}},V=class{queue=[];debounceTimer=null;pendingPromise=null;options;constructor(e){this.options=e}add(e){e.length!==0&&(this.queue.push({type:`ADD`,rows:e}),this.scheduleProcessing())}remove(e){e.length!==0&&(this.queue.push({type:`REMOVE`,rowIds:e}),this.scheduleProcessing())}updateCell(e,t,n){this.queue.push({type:`UPDATE_CELL`,rowId:e,field:t,value:n}),this.scheduleProcessing()}updateRow(e,t){Object.keys(t).length!==0&&(this.queue.push({type:`UPDATE_ROW`,rowId:e,data:t}),this.scheduleProcessing())}flush(){return this.queue.length===0?Promise.resolve():(this.debounceTimer!==null&&(clearTimeout(this.debounceTimer),this.debounceTimer=null),this.pendingPromise?new Promise((e,t)=>{let n=this.pendingPromise,r=n.resolve,i=n.reject;n.resolve=()=>{r(),e()},n.reject=e=>{i(e),t(e)}}):new Promise((e,t)=>{this.pendingPromise={resolve:e,reject:t},this.processQueue()}))}hasPending(){return this.queue.length>0}getPendingCount(){return this.queue.length}clear(){this.queue=[],this.debounceTimer!==null&&(clearTimeout(this.debounceTimer),this.debounceTimer=null),this.pendingPromise&&=(this.pendingPromise.resolve(),null)}scheduleProcessing(){if(this.options.debounceMs===0){this.processQueue();return}this.debounceTimer===null&&(this.debounceTimer=setTimeout(()=>{this.debounceTimer=null,this.processQueue()},this.options.debounceMs))}processQueue(){if(this.queue.length===0){this.pendingPromise&&=(this.pendingPromise.resolve(),null);return}let e=this.queue;this.queue=[];let t={added:0,removed:0,updated:0};try{for(let n of e)switch(n.type){case`ADD`:this.options.store.addRows(n.rows),t.added+=n.rows.length;break;case`REMOVE`:this.options.store.removeRows(n.rowIds),t.removed+=n.rowIds.length;break;case`UPDATE_CELL`:this.options.store.updateCell(n.rowId,n.field,n.value),t.updated++;break;case`UPDATE_ROW`:this.options.store.updateRow(n.rowId,n.data),t.updated++;break}this.options.onProcessed&&this.options.onProcessed(t),this.pendingPromise&&=(this.pendingPromise.resolve(),null)}catch(e){this.pendingPromise&&=(this.pendingPromise.reject(e instanceof Error?e:Error(String(e))),null)}}};function re(e,t){let{getRowId:n,getFieldValue:r,debounceMs:i=50,onTransactionProcessed:a}=t,o=new B(e,{getRowId:n,getFieldValue:r}),s=new Set,c=new V({debounceMs:i,store:o,onProcessed:e=>{a?.(e);for(let t of s)t(e)}});return{async fetch(e){return c.hasPending()&&await c.flush(),o.query(e)},addRows(e){c.add(e)},removeRows(e){c.remove(e)},updateCell(e,t,n){c.updateCell(e,t,n)},updateRow(e,t){c.updateRow(e,t)},async flushTransactions(){await c.flush()},hasPendingTransactions(){return c.hasPending()},getDistinctValues(e){return o.getDistinctValues(e)},getRowById(e){return o.getRowById(e)},getTotalRowCount(){return o.getTotalRowCount()},subscribe(e){return s.add(e),()=>{s.delete(e)}},clear(){o.clear(),s.clear()}}}const H=`
|
|
322
|
+
`,{maxWorkers:e.maxWorkers??(typeof navigator<`u`?navigator.hardwareConcurrency:4)??4}),this.parallelThreshold=e.parallelThreshold??4e5,this.minChunkSize=e.minChunkSize??5e4}isAvailable(){return!this.isTerminated&&this.pool.isAvailable()}terminate(){this.pool.terminate(),this.isTerminated=!0}async sortIndices(e,t){if(this.isTerminated)throw Error(`ParallelSortManager has been terminated`);return e.length<this.parallelThreshold?this.sortIndicesSingle(e,t):this.sortIndicesParallel(e,t)}async sortStringHashes(e,t,n){if(this.isTerminated)throw Error(`ParallelSortManager has been terminated`);return(e[0]?.length??0)<this.parallelThreshold?this.sortStringHashesSingle(e,t,n):this.sortStringHashesParallel(e,t,n)}async sortMultiColumn(e,t){if(this.isTerminated)throw Error(`ParallelSortManager has been terminated`);return(e[0]?.length??0)<this.parallelThreshold?this.sortMultiColumnSingle(e,t):this.sortMultiColumnParallel(e,t)}async sortIndicesSingle(e,t){let n=new Float64Array(e),r={type:`sortIndices`,id:0,values:n,direction:t};return(await this.pool.execute(r,[n.buffer])).indices}async sortStringHashesSingle(e,t,n){let r={type:`sortStringHashes`,id:0,hashChunks:e,direction:t},i=e.map(e=>e.buffer),a=await this.pool.execute(r,i);return a.collisionRuns.length>0&&this.resolveCollisions(a.indices,a.collisionRuns,n,t),a.indices}async sortMultiColumnSingle(e,t){let n=e.map(e=>new Float64Array(e)),r=new Int8Array(t.map(e=>e===`asc`?1:-1)),i={type:`sortMultiColumn`,id:0,columns:n,directions:r},a=[...n.map(e=>e.buffer),r.buffer];return(await this.pool.execute(i,a)).indices}async sortIndicesParallel(e,t){let n=this.splitIntoChunks(e).map(e=>{let n=new Float64Array(e.data);return{request:{type:`sortChunk`,id:0,values:n,direction:t,chunkOffset:e.offset},transferables:[n.buffer]}}),r=await this.pool.executeParallel(n);return r.sort((e,t)=>e.chunkOffset-t.chunkOffset),E(r.map(e=>({indices:e.indices,values:e.sortedValues,offset:e.chunkOffset})),t)}async sortStringHashesParallel(e,t,n){let r=e[0].length,i=this.calculateChunkBoundaries(r).map(n=>{let r=e.map(e=>new Float64Array(e.buffer,n.offset*8,n.length)).map(e=>{let t=new Float64Array(e.length);return t.set(e),t});return{request:{type:`sortStringChunk`,id:0,hashChunks:r,direction:t,chunkOffset:n.offset},transferables:r.map(e=>e.buffer)}}),a=await this.pool.executeParallel(i);a.sort((e,t)=>e.chunkOffset-t.chunkOffset);let o=a.map(e=>({indices:e.indices,values:e.sortedHashes,offset:e.chunkOffset})),s=[];for(let e of a)for(let t=0;t<e.collisionRuns.length;t+=2)s.push(e.collisionRuns[t]+e.chunkOffset,e.collisionRuns[t+1]+e.chunkOffset);let c=E(o,t),l=this.detectBoundaryCollisionsForStrings(o,t),u=new Uint32Array([...s,...l]);return u.length>0&&this.resolveCollisions(c,u,n,t),c}async sortMultiColumnParallel(e,t){let n=e[0].length,r=this.calculateChunkBoundaries(n),i=new Int8Array(t.map(e=>e===`asc`?1:-1)),a=r.map(t=>{let n=e.map(e=>{let n=new Float64Array(t.length);for(let r=0;r<t.length;r++)n[r]=e[t.offset+r];return n}),r=new Int8Array(i);return{request:{type:`sortMultiColumnChunk`,id:0,columns:n,directions:r,chunkOffset:t.offset},transferables:[...n.map(e=>e.buffer),r.buffer]}}),o=await this.pool.executeParallel(a);return o.sort((e,t)=>e.chunkOffset-t.chunkOffset),D(o.map(e=>({indices:e.indices,columns:e.sortedColumns,directions:i,offset:e.chunkOffset})))}splitIntoChunks(e){let t=e.length,n=this.pool.getMaxWorkers(),r=Math.max(this.minChunkSize,Math.ceil(t/n)),i=[];for(let n=0;n<t;n+=r){let a=Math.min(n+r,t);i.push({data:e.slice(n,a),offset:n})}return i}calculateChunkBoundaries(e){let t=this.pool.getMaxWorkers(),n=Math.max(this.minChunkSize,Math.ceil(e/t)),r=[];for(let t=0;t<e;t+=n)r.push({offset:t,length:Math.min(n,e-t)});return r}detectBoundaryCollisionsForStrings(e,t){if(e.length<=1)return[];let n=[],r=0;for(let t=0;t<e.length-1;t++){let i=e[t],a=e[t+1];if(i.indices.length===0||a.indices.length===0){r+=i.indices.length;continue}let o=i.values[i.indices.length-1],s=a.values[0];if(o===s){let e=i.indices.length-1;for(;e>0&&i.values[e-1]===o;)e--;let t=0;for(;t<a.indices.length-1&&a.values[t+1]===s;)t++;n.push(r+e,r+i.indices.length+t+1)}r+=i.indices.length}return n}resolveCollisions(e,t,n,r){let i=r===`asc`?1:-1;for(let r=0;r<t.length;r+=2){let a=t[r],o=t[r+1];if(o<=a||o>e.length)continue;let s=Array.from(e.slice(a,o)),c=n[s[0]],l=!0;for(let e=1;e<s.length;e++)if(n[s[e]]!==c){l=!1;break}if(!l){s.sort((e,t)=>i*n[e].localeCompare(n[t]));for(let t=0;t<s.length;t++)e[a+t]=s[t]}}}};function k(e){let t=e.toLowerCase(),n=Math.min(t.length,10),r=0;for(let e=0;e<n;e++){let n=t.charCodeAt(e),i;i=n>=97&&n<=122?n-97:n>=48&&n<=57?n-48+26:0,r=r*36+i}for(let e=n;e<10;e++)r*=36;return r}function le(e){let t=e.toLowerCase(),n=[];for(let e=0;e<3;e++){let r=e*10,i=0;for(let e=0;e<10;e++){let n=r+e,a=n<t.length?t.charCodeAt(n):0,o;o=a>=97&&a<=122?a-97:a>=48&&a<=57?a-48+26:0,i=i*36+o}n.push(i)}return n}function A(e){if(e==null)return Number.MAX_VALUE;if(Array.isArray(e))return e.length===0?Number.MAX_VALUE:k(e.join(`, `));if(typeof e==`number`)return e;if(e instanceof Date)return e.getTime();if(typeof e==`string`)return k(e);let t=Number(e);return isNaN(t)?0:t}function ue(e,t){let n=e==null||Array.isArray(e)&&e.length===0,r=t==null||Array.isArray(t)&&t.length===0;if(n&&r)return 0;if(n)return 1;if(r)return-1;if(Array.isArray(e)||Array.isArray(t)){let n=Array.isArray(e)?e.join(`, `):String(e??``),r=Array.isArray(t)?t.join(`, `):String(t??``);return n.localeCompare(r)}let i=Number(e),a=Number(t);return!isNaN(i)&&!isNaN(a)?i-a:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():String(e).localeCompare(String(t))}function de(e,t,n){return[...e].sort((e,r)=>{for(let{colId:i,direction:a}of t){let t=ue(n(e,i),n(r,i));if(t!==0)return a===`asc`?t:-t}return 0})}function j(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function fe(e){return e==null||e===``||Array.isArray(e)&&e.length===0}function M(e,t){let n=fe(e);if(t.selectedValues&&t.selectedValues.size>0){let r=t.includeBlank===!0&&n;if(Array.isArray(e)){let n=[...e].sort((e,t)=>String(e).localeCompare(String(t),void 0,{numeric:!0,sensitivity:`base`})).join(`, `);return t.selectedValues.has(n)||r}let i=String(e??``);return t.selectedValues.has(i)||r}let r=String(e??``).toLowerCase(),i=String(t.value??``).toLowerCase();switch(t.operator){case`contains`:return r.includes(i);case`notContains`:return!r.includes(i);case`equals`:return r===i;case`notEquals`:return r!==i;case`startsWith`:return r.startsWith(i);case`endsWith`:return r.endsWith(i);case`blank`:return n;case`notBlank`:return!n;default:return!0}}function N(e,t){let n=e==null||e===``;if(t.operator===`blank`)return n;if(t.operator===`notBlank`)return!n;if(n)return!1;let r=typeof e==`number`?e:Number(e);if(isNaN(r))return!1;let i=t.value??0,a=t.valueTo??0;switch(t.operator){case`=`:return r===i;case`!=`:return r!==i;case`>`:return r>i;case`<`:return r<i;case`>=`:return r>=i;case`<=`:return r<=i;case`between`:return r>=i&&r<=a;default:return!0}}function P(e,t){let n=e==null||e===``;if(t.operator===`blank`)return n;if(t.operator===`notBlank`)return!n;if(n)return!1;let r=e instanceof Date?e:new Date(String(e));if(isNaN(r.getTime()))return!1;let i=t.value instanceof Date?t.value:new Date(String(t.value??``)),a=t.valueTo instanceof Date?t.valueTo:new Date(String(t.valueTo??``)),o=r.getTime(),s=i.getTime(),c=a.getTime();switch(t.operator){case`=`:return j(r,i);case`!=`:return!j(r,i);case`>`:return o>s;case`<`:return o<s;case`between`:return o>=s&&o<=c;default:return!0}}function F(e,t){switch(t.type){case`text`:return M(e,t);case`number`:return N(e,t);case`date`:return P(e,t);default:return!0}}function I(e,t){if(!t.conditions||t.conditions.length===0)return!0;let n=t.conditions[0];if(!n)return!0;let r=F(e,n);for(let n=1;n<t.conditions.length;n++){let i=t.conditions[n-1],a=t.conditions[n],o=i.nextOperator??t.combination,s=F(e,a);o===`and`?r&&=s:r||=s}return r}function L(e,t,n){let r=Object.entries(t).filter(([,e])=>e!=null);if(r.length===0)return!0;for(let[t,i]of r)if(!I(n(e,t),i))return!1;return!0}function pe(e,t,n){let r=Object.entries(t).filter(([,e])=>typeof e==`string`?e.trim()!==``:e.conditions&&e.conditions.length>0);return r.length===0?e:e.filter(e=>{for(let[t,i]of r){let r=n(e,t);if(typeof i==`string`){if(!String(r??``).toLowerCase().includes(i.toLowerCase()))return!1;continue}if(!I(r,i))return!1}return!0})}function me(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return null;r=r[e]}return r??null}function R(e,t={}){let{getFieldValue:n=me,useWorker:r=!0,parallelSort:i}=t,a=e,o=!1,s=r?new O(i===!1?{maxWorkers:1}:i):null;return{async fetch(e){let t=a?[...a]:[];if(e.filter&&Object.keys(e.filter).length>0&&(t=pe(t,e.filter,n)),e.sort&&e.sort.length>0)if(s&&s.isAvailable()&&t.length>=2e5){let r;if(e.sort.length===1){let{colId:i,direction:a}=e.sort[0],o=!1;for(let e of t){let t=n(e,i);if(t!=null){o=typeof t==`string`||Array.isArray(t);break}}if(o){let e=[],o=Array.from({length:3},()=>[]);for(let r of t){let t=n(r,i),a=t==null?``:Array.isArray(t)?t.join(`, `):String(t);e.push(a);let s=le(a);for(let e=0;e<3;e++)o[e].push(s[e])}let c=o.map(e=>new Float64Array(e));r=await s.sortStringHashes(c,a,e)}else{let e=t.map(e=>A(n(e,i)));r=await s.sortIndices(e,a)}}else{let i=[],a=[];for(let{colId:r,direction:o}of e.sort){let e=t.map(e=>A(n(e,r)));i.push(e),a.push(o)}r=await s.sortMultiColumn(i,a)}let i=Array(t.length);for(let e=0;e<r.length;e++)i[e]=t[r[e]];t=i}else t=de(t,e.sort,n);let r=t.length,{pageIndex:i,pageSize:o}=e.pagination,c=i*o;return{rows:t.slice(c,c+o),totalRows:r}},destroy(){o||(o=!0,a=null,s&&s.terminate())}}}function he(e){return R(e)}function ge(e){return{async fetch(t){return e(t)}}}function z(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return null;r=r[e]}return r??null}function B(e,t,n){let r=t.split(`.`),i=e;for(let e=0;e<r.length-1;e++){let t=r[e];if(typeof i!=`object`||!i)return;i=i[t]}typeof i==`object`&&i&&(i[r[r.length-1]]=n)}function V(e){let t=e.toLowerCase(),n=Math.min(t.length,10),r=0;for(let e=0;e<n;e++){let n=t.charCodeAt(e),i;i=n>=97&&n<=122?n-97:n>=48&&n<=57?n-48+26:0,r=r*36+i}for(let e=n;e<10;e++)r*=36;return r}function H(e,t){let n=e==null||Array.isArray(e)&&e.length===0,r=t==null||Array.isArray(t)&&t.length===0;if(n&&r)return 0;if(n)return 1;if(r)return-1;if(Array.isArray(e)||Array.isArray(t)){let n=Array.isArray(e)?e.join(`, `):String(e??``),r=Array.isArray(t)?t.join(`, `):String(t??``);return n.localeCompare(r)}let i=Number(e),a=Number(t);return!isNaN(i)&&!isNaN(a)?i-a:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():String(e).localeCompare(String(t))}function U(e){if(e==null)return Number.MAX_VALUE;if(typeof e==`number`)return e;if(e instanceof Date)return e.getTime();if(typeof e==`string`)return V(e);let t=Number(e);return isNaN(t)?0:t}function _e(e,t){let n=[];for(let r of t.sortModel){let i=U(t.getFieldValue(e,r.colId));n.push(i)}return n}function ve(e,t,n){if(!e||!t)return null;for(let r=0;r<n.length;r++){let i=e[r]-t[r];if(i!==0)return n[r].direction===`asc`?i:-i}return 0}function ye(e,t,n,r){for(let{colId:i,direction:a}of n){let n=H(r(e,i),r(t,i));if(n!==0)return a===`asc`?n:-n}return 0}var W=class{rows=[];rowById=new Map;sortedIndices=[];sortModel=[];sortModelHash=``;filterModel={};filteredIndices=new Set;distinctValues=new Map;rowSortCache=new Map;options;constructor(e=[],t){this.options={getRowId:t.getRowId,getFieldValue:t.getFieldValue??z},this.setData(e)}clear(){this.rows=[],this.rowById.clear(),this.sortedIndices=[],this.filterModel={},this.filteredIndices.clear(),this.rowSortCache.clear(),this.distinctValues.clear(),this.sortModel=[],this.sortModelHash=``}setData(e){this.rows=[...e],this.rowById.clear(),this.rowSortCache.clear(),this.distinctValues.clear();for(let e=0;e<this.rows.length;e++){let t=this.rows[e],n=this.options.getRowId(t);this.rowById.set(n,e)}this.rebuildSortedIndices(),this.rebuildFilteredIndices(),this.rebuildDistinctValues()}query(e){this.setSortModel(e.sort??[]),this.setFilterModel(e.filter??{});let t=this.getVisibleIndices(),n=t.length,{pageIndex:r,pageSize:i}=e.pagination,a=r*i,o=Math.min(a+i,n),s=[];for(let e=a;e<o;e++){let n=t[e];n!==void 0&&s.push(this.rows[n])}return{rows:s,totalRows:n}}getRowById(e){let t=this.rowById.get(e);return t===void 0?void 0:this.rows[t]}getRowByIndex(e){return this.rows[e]}getTotalRowCount(){return this.rows.length}getVisibleRowCount(){return Object.keys(this.filterModel).length===0?this.rows.length:this.filteredIndices.size}getDistinctValues(e){let t=this.distinctValues.get(e);return t?Array.from(t):[]}addRows(e){for(let t of e)this.addRow(t)}addRow(e){let t=this.options.getRowId(e);if(this.rowById.has(t)){console.warn(`Row with ID ${t} already exists. Skipping.`);return}let n=this.rows.length;if(this.rows.push(e),this.rowById.set(t,n),this.updateDistinctValuesForRow(e,`add`),this.sortModel.length>0&&this.computeRowHashes(n,e),this.sortModel.length>0){let e=this.binarySearchInsertPosition(n);this.sortedIndices.splice(e,0,n)}else this.sortedIndices.push(n);this.rowPassesFilter(e)&&this.filteredIndices.add(n)}removeRows(e){let t=[];for(let n of e){let e=this.rowById.get(n);e!==void 0&&t.push(e)}if(t.length!==0){t.sort((e,t)=>t-e);for(let e of t)this.removeRowByIndex(e)}}removeRowByIndex(e){let t=this.rows[e];if(!t)return;let n=this.options.getRowId(t);this.updateDistinctValuesForRow(t,`remove`);let r=this.sortedIndices.indexOf(e);r!==-1&&this.sortedIndices.splice(r,1),this.filteredIndices.delete(e),this.rowSortCache.delete(e),this.rowById.delete(n),this.rows.splice(e,1),this.reindexAfterRemoval(e)}reindexAfterRemoval(e){for(let[t,n]of this.rowById.entries())n>e&&this.rowById.set(t,n-1);for(let t=0;t<this.sortedIndices.length;t++)this.sortedIndices[t]>e&&this.sortedIndices[t]--;let t=new Set;for(let n of this.filteredIndices)n>e?t.add(n-1):t.add(n);this.filteredIndices=t;let n=new Map;for(let[t,r]of this.rowSortCache)t>e?n.set(t-1,r):n.set(t,r);this.rowSortCache=n}updateCell(e,t,n){let r=this.rowById.get(e);if(r===void 0){console.warn(`Row with ID ${e} not found.`);return}let i=this.rows[r],a=this.options.getFieldValue(i,t);if(B(i,t,n),this.updateDistinctValueForField(t,a,n),this.sortModel.some(e=>e.colId===t)&&this.sortModel.length>0){this.computeRowHashes(r,i);let e=this.sortedIndices.indexOf(r);e!==-1&&this.sortedIndices.splice(e,1);let t=this.binarySearchInsertPosition(r);this.sortedIndices.splice(t,0,r)}t in this.filterModel&&(this.rowPassesFilter(i)?this.filteredIndices.add(r):this.filteredIndices.delete(r))}updateRow(e,t){for(let[n,r]of Object.entries(t))this.updateCell(e,n,r)}setSortModel(e){let t=JSON.stringify(e);t!==this.sortModelHash&&(this.sortModelHash=t,this.sortModel=[...e],this.rebuildHashCache(),this.rebuildSortedIndices())}getSortModel(){return[...this.sortModel]}setFilterModel(e){JSON.stringify(e)!==JSON.stringify(this.filterModel)&&(this.filterModel={...e},this.rebuildFilteredIndices())}getFilterModel(){return{...this.filterModel}}rebuildSortedIndices(){this.sortedIndices=Array.from({length:this.rows.length},(e,t)=>t),this.sortModel.length!==0&&this.sortedIndices.sort((e,t)=>this.compareRows(e,t))}rebuildHashCache(){if(this.rowSortCache.clear(),this.sortModel.length!==0)for(let e=0;e<this.rows.length;e++)this.computeRowHashes(e,this.rows[e])}computeRowHashes(e,t){if(this.sortModel.length===0)return;let n=_e(t,{sortModel:this.sortModel,sortModelHash:this.sortModelHash,getFieldValue:this.options.getFieldValue}),r=this.rowSortCache.get(e);r||(r={hashes:new Map},this.rowSortCache.set(e,r)),r.hashes.set(this.sortModelHash,n)}compareRows(e,t){let n=this.rowSortCache.get(e),r=this.rowSortCache.get(t),i=n?.hashes.get(this.sortModelHash),a=r?.hashes.get(this.sortModelHash),o=ve(i,a,this.sortModel);return o===null?ye(this.rows[e],this.rows[t],this.sortModel,this.options.getFieldValue):o}binarySearchInsertPosition(e){let t=0,n=this.sortedIndices.length;for(;t<n;){let r=t+n>>>1,i=this.sortedIndices[r];this.compareRows(e,i)>0?t=r+1:n=r}return t}rebuildFilteredIndices(){if(this.filteredIndices.clear(),Object.entries(this.filterModel).filter(([,e])=>e!=null).length!==0)for(let e=0;e<this.rows.length;e++)this.rowPassesFilter(this.rows[e])&&this.filteredIndices.add(e)}rowPassesFilter(e){return L(e,this.filterModel,this.options.getFieldValue)}getVisibleIndices(){return Object.entries(this.filterModel).filter(([,e])=>e!=null).length>0?this.sortedIndices.filter(e=>this.filteredIndices.has(e)):this.sortedIndices}rebuildDistinctValues(){this.distinctValues.clear();for(let e of this.rows)this.updateDistinctValuesForRow(e,`add`)}updateDistinctValuesForRow(e,t){if(!(typeof e!=`object`||!e)){for(let[n,r]of Object.entries(e))if(r!=null&&t===`add`){let e=this.distinctValues.get(n);if(e||(e=new Set,this.distinctValues.set(n,e)),Array.isArray(r))for(let t of r)t!=null&&e.add(t);else e.add(r)}}}updateDistinctValueForField(e,t,n){if(n!=null){let t=this.distinctValues.get(e);if(t||(t=new Set,this.distinctValues.set(e,t)),Array.isArray(n))for(let e of n)e!=null&&t.add(e);else t.add(n)}}},G=class{queue=[];debounceTimer=null;pendingPromise=null;options;constructor(e){this.options=e}add(e){e.length!==0&&(this.queue.push({type:`ADD`,rows:e}),this.scheduleProcessing())}remove(e){e.length!==0&&(this.queue.push({type:`REMOVE`,rowIds:e}),this.scheduleProcessing())}updateCell(e,t,n){this.queue.push({type:`UPDATE_CELL`,rowId:e,field:t,value:n}),this.scheduleProcessing()}updateRow(e,t){Object.keys(t).length!==0&&(this.queue.push({type:`UPDATE_ROW`,rowId:e,data:t}),this.scheduleProcessing())}flush(){return this.queue.length===0?Promise.resolve():(this.debounceTimer!==null&&(clearTimeout(this.debounceTimer),this.debounceTimer=null),this.pendingPromise?new Promise((e,t)=>{let n=this.pendingPromise,r=n.resolve,i=n.reject;n.resolve=()=>{r(),e()},n.reject=e=>{i(e),t(e)}}):new Promise((e,t)=>{this.pendingPromise={resolve:e,reject:t},this.processQueue()}))}hasPending(){return this.queue.length>0}getPendingCount(){return this.queue.length}clear(){this.queue=[],this.debounceTimer!==null&&(clearTimeout(this.debounceTimer),this.debounceTimer=null),this.pendingPromise&&=(this.pendingPromise.resolve(),null)}scheduleProcessing(){if(this.options.debounceMs===0){this.processQueue();return}this.debounceTimer===null&&(this.debounceTimer=setTimeout(()=>{this.debounceTimer=null,this.processQueue()},this.options.debounceMs))}processQueue(){if(this.queue.length===0){this.pendingPromise&&=(this.pendingPromise.resolve(),null);return}let e=this.queue;this.queue=[];let t={added:0,removed:0,updated:0};try{for(let n of e)switch(n.type){case`ADD`:this.options.store.addRows(n.rows),t.added+=n.rows.length;break;case`REMOVE`:this.options.store.removeRows(n.rowIds),t.removed+=n.rowIds.length;break;case`UPDATE_CELL`:this.options.store.updateCell(n.rowId,n.field,n.value),t.updated++;break;case`UPDATE_ROW`:this.options.store.updateRow(n.rowId,n.data),t.updated++;break}this.options.onProcessed&&this.options.onProcessed(t),this.pendingPromise&&=(this.pendingPromise.resolve(),null)}catch(e){this.pendingPromise&&=(this.pendingPromise.reject(e instanceof Error?e:Error(String(e))),null)}}};function be(e,t){let{getRowId:n,getFieldValue:r,debounceMs:i=50,onTransactionProcessed:a}=t,o=new W(e,{getRowId:n,getFieldValue:r}),s=new Set,c=new G({debounceMs:i,store:o,onProcessed:e=>{a?.(e);for(let t of s)t(e)}});return{async fetch(e){return c.hasPending()&&await c.flush(),o.query(e)},addRows(e){c.add(e)},removeRows(e){c.remove(e)},updateCell(e,t,n){c.updateCell(e,t,n)},updateRow(e,t){c.updateRow(e,t)},async flushTransactions(){await c.flush()},hasPendingTransactions(){return c.hasPending()},getDistinctValues(e){return o.getDistinctValues(e)},getRowById(e){return o.getRowById(e)},getTotalRowCount(){return o.getTotalRowCount()},subscribe(e){return s.add(e),()=>{s.delete(e)}},clear(){o.clear(),s.clear()}}}const K=`
|
|
323
323
|
/* =============================================================================
|
|
324
324
|
GP Grid - CSS Variables for Theming
|
|
325
325
|
============================================================================= */
|
|
@@ -403,7 +403,7 @@ self.onmessage = function(e) {
|
|
|
403
403
|
--gp-grid-scrollbar-thumb: #373a40;
|
|
404
404
|
--gp-grid-scrollbar-thumb-hover: #4a4d52;
|
|
405
405
|
}
|
|
406
|
-
`,
|
|
406
|
+
`,q=`
|
|
407
407
|
/* =============================================================================
|
|
408
408
|
GP Grid - Clean Flat Design
|
|
409
409
|
============================================================================= */
|
|
@@ -426,7 +426,7 @@ self.onmessage = function(e) {
|
|
|
426
426
|
outline: none;
|
|
427
427
|
border-color: var(--gp-grid-primary);
|
|
428
428
|
}
|
|
429
|
-
`,
|
|
429
|
+
`,J=`
|
|
430
430
|
/* =============================================================================
|
|
431
431
|
Header
|
|
432
432
|
============================================================================= */
|
|
@@ -540,7 +540,7 @@ self.onmessage = function(e) {
|
|
|
540
540
|
color: var(--gp-grid-primary);
|
|
541
541
|
background-color: var(--gp-grid-primary-light);
|
|
542
542
|
}
|
|
543
|
-
`,
|
|
543
|
+
`,Y=`
|
|
544
544
|
/* =============================================================================
|
|
545
545
|
Data Cells
|
|
546
546
|
============================================================================= */
|
|
@@ -551,18 +551,18 @@ self.onmessage = function(e) {
|
|
|
551
551
|
left: 0;
|
|
552
552
|
}
|
|
553
553
|
|
|
554
|
+
/* Row background - :where() for zero specificity, so user highlight classes always win */
|
|
555
|
+
:where(.gp-grid-row) {
|
|
556
|
+
background-color: var(--gp-grid-bg);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/* Structural properties - required for grid layout */
|
|
554
560
|
.gp-grid-cell {
|
|
555
561
|
position: absolute;
|
|
556
562
|
top: 0;
|
|
557
563
|
box-sizing: border-box;
|
|
558
|
-
padding: 0 12px;
|
|
559
564
|
display: flex;
|
|
560
565
|
align-items: center;
|
|
561
|
-
cursor: cell;
|
|
562
|
-
color: var(--gp-grid-text);
|
|
563
|
-
border-right: 1px solid var(--gp-grid-border-light);
|
|
564
|
-
border-bottom: 1px solid var(--gp-grid-border-light);
|
|
565
|
-
background-color: var(--gp-grid-bg);
|
|
566
566
|
overflow: hidden;
|
|
567
567
|
text-overflow: ellipsis;
|
|
568
568
|
white-space: nowrap;
|
|
@@ -570,36 +570,41 @@ self.onmessage = function(e) {
|
|
|
570
570
|
-webkit-user-select: none;
|
|
571
571
|
}
|
|
572
572
|
|
|
573
|
-
/*
|
|
574
|
-
.gp-grid-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
573
|
+
/* Visual properties - :where() for zero specificity, so user highlight classes always win */
|
|
574
|
+
:where(.gp-grid-cell) {
|
|
575
|
+
padding: 0 12px;
|
|
576
|
+
cursor: cell;
|
|
577
|
+
color: var(--gp-grid-text);
|
|
578
|
+
border-right: 1px solid var(--gp-grid-border-light);
|
|
579
|
+
border-bottom: 1px solid var(--gp-grid-border-light);
|
|
580
|
+
background-color: transparent;
|
|
580
581
|
}
|
|
581
582
|
|
|
582
|
-
/* Active cell (focused) */
|
|
583
|
+
/* Active cell (focused) - structural properties stay, visual use :where() */
|
|
583
584
|
.gp-grid-cell--active {
|
|
584
|
-
background-color: var(--gp-grid-primary-light) !important;
|
|
585
|
-
border: 2px solid var(--gp-grid-primary) !important;
|
|
586
585
|
outline: none;
|
|
587
586
|
z-index: 5;
|
|
587
|
+
}
|
|
588
|
+
:where(.gp-grid-cell--active) {
|
|
589
|
+
background-color: var(--gp-grid-primary-light);
|
|
590
|
+
border: 2px solid var(--gp-grid-primary);
|
|
588
591
|
padding: 0 11px;
|
|
589
592
|
}
|
|
590
593
|
|
|
591
594
|
/* Selected cells (range selection) */
|
|
592
|
-
.gp-grid-cell--selected {
|
|
593
|
-
background-color: var(--gp-grid-primary-light)
|
|
595
|
+
:where(.gp-grid-cell--selected) {
|
|
596
|
+
background-color: var(--gp-grid-primary-light);
|
|
594
597
|
}
|
|
595
598
|
|
|
596
|
-
/* Editing cell */
|
|
599
|
+
/* Editing cell - structural properties stay, visual use :where() */
|
|
597
600
|
.gp-grid-cell--editing {
|
|
598
|
-
background-color: var(--gp-grid-bg) !important;
|
|
599
|
-
border: 2px solid var(--gp-grid-primary) !important;
|
|
600
|
-
padding: 0 !important;
|
|
601
601
|
z-index: 10;
|
|
602
602
|
}
|
|
603
|
+
:where(.gp-grid-cell--editing) {
|
|
604
|
+
background-color: var(--gp-grid-bg);
|
|
605
|
+
border: 2px solid var(--gp-grid-primary);
|
|
606
|
+
padding: 0;
|
|
607
|
+
}
|
|
603
608
|
|
|
604
609
|
/* =============================================================================
|
|
605
610
|
Fill Handle (drag to fill)
|
|
@@ -623,9 +628,9 @@ self.onmessage = function(e) {
|
|
|
623
628
|
}
|
|
624
629
|
|
|
625
630
|
/* Fill preview (cells being filled) */
|
|
626
|
-
.gp-grid-cell--fill-preview {
|
|
627
|
-
background-color: var(--gp-grid-primary-light)
|
|
628
|
-
border: 1px dashed var(--gp-grid-primary)
|
|
631
|
+
.gp-grid-cell.gp-grid-cell--fill-preview {
|
|
632
|
+
background-color: var(--gp-grid-primary-light);
|
|
633
|
+
border: 1px dashed var(--gp-grid-primary);
|
|
629
634
|
}
|
|
630
635
|
|
|
631
636
|
/* =============================================================================
|
|
@@ -646,7 +651,7 @@ self.onmessage = function(e) {
|
|
|
646
651
|
.gp-grid-edit-input:focus {
|
|
647
652
|
outline: none;
|
|
648
653
|
}
|
|
649
|
-
`,
|
|
654
|
+
`,X=`
|
|
650
655
|
/* =============================================================================
|
|
651
656
|
Loading & Error States
|
|
652
657
|
============================================================================= */
|
|
@@ -714,7 +719,7 @@ self.onmessage = function(e) {
|
|
|
714
719
|
font-size: 14px;
|
|
715
720
|
text-align: center;
|
|
716
721
|
}
|
|
717
|
-
`,
|
|
722
|
+
`,Z=`
|
|
718
723
|
/* =============================================================================
|
|
719
724
|
Scrollbar Styling
|
|
720
725
|
============================================================================= */
|
|
@@ -740,7 +745,7 @@ self.onmessage = function(e) {
|
|
|
740
745
|
.gp-grid-container::-webkit-scrollbar-corner {
|
|
741
746
|
background-color: var(--gp-grid-scrollbar-track);
|
|
742
747
|
}
|
|
743
|
-
`,
|
|
748
|
+
`,Q=`
|
|
744
749
|
/* =============================================================================
|
|
745
750
|
Filter Popup
|
|
746
751
|
============================================================================= */
|
|
@@ -1051,5 +1056,5 @@ self.onmessage = function(e) {
|
|
|
1051
1056
|
.gp-grid-filter-btn-apply:hover {
|
|
1052
1057
|
opacity: 0.9;
|
|
1053
1058
|
}
|
|
1054
|
-
`,
|
|
1055
|
-
`);let
|
|
1059
|
+
`,xe=`gp-grid-styles`,Se=[K,q,J,Y,X,Z,Q].join(`
|
|
1060
|
+
`);let $=!1;function Ce(){if($||typeof document>`u`)return;if(document.getElementById(xe)){$=!0;return}let e=document.createElement(`style`);e.id=xe,e.textContent=Se,document.head.appendChild(e),$=!0}export{x as EditManager,y as FillManager,re as GridCore,S as HighlightManager,W as IndexedDataStore,ee as InputHandler,O as ParallelSortManager,v as SelectionManager,b as SlotPoolManager,G as TransactionManager,w as WorkerPool,d as buildCellClasses,e as calculateColumnPositions,n as calculateScaledColumnPositions,Y as cellStyles,H as compareValues,U as computeValueHash,q as containerStyles,R as createClientDataSource,he as createDataSourceFromArray,be as createMutableClientDataSource,ge as createServerDataSource,ce as detectBoundaryCollisions,I as evaluateColumnFilter,P as evaluateDateCondition,N as evaluateNumberCondition,M as evaluateTextCondition,Q as filtersStyles,r as findColumnAtX,z as getFieldValue,t as getTotalWidth,Se as gridStyles,J as headerStyles,Ce as injectStyles,s as isCellActive,l as isCellEditing,u as isCellInFillPreview,o as isCellSelected,p as isColumnInSelectionRange,f as isRowInSelectionRange,c as isRowVisible,j as isSameDay,E as kWayMerge,D as kWayMergeMultiColumn,L as rowPassesFilter,Z as scrollbarStyles,B as setFieldValue,X as statesStyles,V as stringToSortableNumber,K as variablesStyles};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "gp-grid-core",
|
|
3
3
|
"description": "A high-performance, framework-agnostic TypeScript data grid core with virtual scrolling",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.7.0",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|