@ishibashi0112/spreadsheet-grid 0.1.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/LICENSE +21 -0
- package/README.md +228 -0
- package/dist/ActiveCellOverlay.d.ts +14 -0
- package/dist/CellEditorLayer.d.ts +18 -0
- package/dist/SelectionOverlay.d.ts +14 -0
- package/dist/SpreadsheetGrid.d.ts +3 -0
- package/dist/hooks/useColumnAutosizeRunner.d.ts +16 -0
- package/dist/hooks/useColumnChooserController.d.ts +18 -0
- package/dist/hooks/useColumnHeaderDragController.d.ts +24 -0
- package/dist/hooks/useColumnMenuController.d.ts +23 -0
- package/dist/hooks/useColumnSelectOptionsCollector.d.ts +18 -0
- package/dist/hooks/useFilterPopoverController.d.ts +30 -0
- package/dist/hooks/useGridBarContext.d.ts +17 -0
- package/dist/hooks/useGridClipboardController.d.ts +22 -0
- package/dist/hooks/useGridEditController.d.ts +23 -0
- package/dist/hooks/useGridKeyboardInteractions.d.ts +21 -0
- package/dist/hooks/useGridPointerInteractions.d.ts +46 -0
- package/dist/hooks/useGridViewportSync.d.ts +21 -0
- package/dist/hooks/useServerSideRowModel.d.ts +16 -0
- package/dist/hooks/useSortManagementController.d.ts +18 -0
- package/dist/index.cjs +8 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5024 -0
- package/dist/logic/columnAutosize.d.ts +18 -0
- package/dist/logic/cx.d.ts +1 -0
- package/dist/logic/domGuards.d.ts +7 -0
- package/dist/logic/filtering.d.ts +12 -0
- package/dist/logic/geometry.d.ts +72 -0
- package/dist/logic/rowHeightStore.d.ts +13 -0
- package/dist/logic/selectOptions.d.ts +9 -0
- package/dist/logic/serverSideBlocks.d.ts +2 -0
- package/dist/logic/serverSideCache.d.ts +13 -0
- package/dist/logic/serverSideQuery.d.ts +7 -0
- package/dist/logic/sorting.d.ts +11 -0
- package/dist/logic/verticalGeometry.d.ts +50 -0
- package/dist/model/gridActions.d.ts +87 -0
- package/dist/model/gridReducer.d.ts +4 -0
- package/dist/model/gridSelectors.d.ts +40 -0
- package/dist/model/gridTypes.d.ts +267 -0
- package/dist/style.css +2 -0
- package/dist/utils/clipboard.d.ts +25 -0
- package/dist/utils/excelColumnName.d.ts +1 -0
- package/dist/utils/permissions.d.ts +4 -0
- package/dist/utils/scheduler.d.ts +1 -0
- package/dist/view/ColumnChooserPanel.d.ts +23 -0
- package/dist/view/ColumnFilterPopover.d.ts +40 -0
- package/dist/view/ColumnMenuPopover.d.ts +25 -0
- package/dist/view/DefaultGridBottomBar.d.ts +6 -0
- package/dist/view/DefaultGridTopBar.d.ts +6 -0
- package/dist/view/GridBodyLayer.d.ts +43 -0
- package/dist/view/GridHeaderRow.d.ts +41 -0
- package/dist/view/SortManagementPanel.d.ts +24 -0
- package/dist/view/gridBarHelpers.d.ts +12 -0
- package/package.json +89 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { GridColumn } from '../model/gridTypes';
|
|
2
|
+
export type ColumnAutosizeParams<T> = {
|
|
3
|
+
columns: GridColumn<T>[];
|
|
4
|
+
getRow: (viewIndex: number) => T;
|
|
5
|
+
viewRowCount: number;
|
|
6
|
+
gridRoot: HTMLElement | null;
|
|
7
|
+
currentWidths: Record<string, number>;
|
|
8
|
+
};
|
|
9
|
+
export type ColumnWidthAccumulator<T> = {
|
|
10
|
+
collect: (row: T) => void;
|
|
11
|
+
finalize: (params: {
|
|
12
|
+
gridRoot: HTMLElement | null;
|
|
13
|
+
currentWidths: Record<string, number>;
|
|
14
|
+
}) => Record<string, number>;
|
|
15
|
+
};
|
|
16
|
+
export declare function createColumnWidthAccumulator<T>(columns: GridColumn<T>[]): ColumnWidthAccumulator<T>;
|
|
17
|
+
export declare function canMeasureAutosize(): boolean;
|
|
18
|
+
export declare function computeAutosizedColumnWidths<T>({ columns, getRow, viewRowCount, gridRoot, currentWidths, }: ColumnAutosizeParams<T>): Record<string, number>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cx(...classNames: Array<string | false | null | undefined>): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ColumnFilterValue, GridColumn, NumberColumnFilterValue, ParsedNumberFilter, SetColumnFilterValue } from '../model/gridTypes';
|
|
2
|
+
export type RowOrder = Int32Array;
|
|
3
|
+
export declare const createSourceOrder: (rowCount: number) => RowOrder;
|
|
4
|
+
export declare const isSetColumnFilterValue: (value: ColumnFilterValue | undefined) => value is SetColumnFilterValue;
|
|
5
|
+
export declare const isActiveColumnFilterValue: (value: ColumnFilterValue | undefined) => boolean;
|
|
6
|
+
export declare const parseNumberFilterExpression: (rawValue: string) => ParsedNumberFilter | null;
|
|
7
|
+
export declare const isNumberColumnFilterValue: (value: ColumnFilterValue | undefined) => value is NumberColumnFilterValue;
|
|
8
|
+
export declare const buildNumberColumnFilterValue: (rawInput: string) => NumberColumnFilterValue | null;
|
|
9
|
+
export declare const columnFilterValueToDraftText: (value: ColumnFilterValue | undefined) => string;
|
|
10
|
+
export declare const applyNumberFilter: (cellValue: unknown, filterValue: unknown) => boolean;
|
|
11
|
+
export declare const filterOrderByGlobalText: <T>(rows: T[], order: RowOrder, columns: GridColumn<T>[], globalText: string) => RowOrder;
|
|
12
|
+
export declare const filterOrderByColumns: <T>(rows: T[], order: RowOrder, columns: GridColumn<T>[], columnFilters: Record<string, ColumnFilterValue>, numericKeys?: ReadonlyMap<string, Float64Array>) => RowOrder;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { GridColumn } from '../model/gridTypes';
|
|
2
|
+
export type ColumnMeasurement<T> = {
|
|
3
|
+
index: number;
|
|
4
|
+
column: GridColumn<T>;
|
|
5
|
+
start: number;
|
|
6
|
+
size: number;
|
|
7
|
+
end: number;
|
|
8
|
+
};
|
|
9
|
+
export declare const clamp: (value: number, min: number, max: number) => number;
|
|
10
|
+
export declare const buildColumnMeasurements: <T>(columns: GridColumn<T>[], columnWidths: Record<string, number>) => ColumnMeasurement<T>[];
|
|
11
|
+
export declare const findColumnIndexFromOffset: <T>(measurements: ColumnMeasurement<T>[], offset: number) => number;
|
|
12
|
+
export type ColumnPane = 'left' | 'center' | 'right';
|
|
13
|
+
export declare const getColumnPane: <T>(column: GridColumn<T>) => ColumnPane;
|
|
14
|
+
export declare const reorderColumnsByPane: <T>(columns: GridColumn<T>[]) => GridColumn<T>[];
|
|
15
|
+
export type PaneColumnEntry<T> = {
|
|
16
|
+
column: GridColumn<T>;
|
|
17
|
+
logicalIndex: number;
|
|
18
|
+
paneLocalStart: number;
|
|
19
|
+
paneLocalSize: number;
|
|
20
|
+
paneLocalEnd: number;
|
|
21
|
+
};
|
|
22
|
+
export type PaneGeometry<T> = {
|
|
23
|
+
pane: ColumnPane;
|
|
24
|
+
entries: PaneColumnEntry<T>[];
|
|
25
|
+
totalWidth: number;
|
|
26
|
+
};
|
|
27
|
+
export type GridPaneLayout<T> = {
|
|
28
|
+
left: PaneGeometry<T>;
|
|
29
|
+
center: PaneGeometry<T>;
|
|
30
|
+
right: PaneGeometry<T>;
|
|
31
|
+
};
|
|
32
|
+
export type PaneSourceColumn<T> = {
|
|
33
|
+
column: GridColumn<T>;
|
|
34
|
+
logicalIndex: number;
|
|
35
|
+
};
|
|
36
|
+
export type PaneSourceColumns<T> = {
|
|
37
|
+
left: PaneSourceColumn<T>[];
|
|
38
|
+
center: PaneSourceColumn<T>[];
|
|
39
|
+
right: PaneSourceColumn<T>[];
|
|
40
|
+
};
|
|
41
|
+
export declare const splitOrderedColumnsByPane: <T>(orderedColumns: GridColumn<T>[]) => PaneSourceColumns<T>;
|
|
42
|
+
export declare const buildPaneWidthsKey: <T>(items: PaneSourceColumn<T>[], columnWidths: Record<string, number>) => string;
|
|
43
|
+
export declare const buildPaneGeometry: <T>(pane: ColumnPane, items: PaneSourceColumn<T>[], resolvedWidths: number[]) => PaneGeometry<T>;
|
|
44
|
+
export declare const buildPaneGeometryFromWidthsKey: <T>(pane: ColumnPane, items: PaneSourceColumn<T>[], widthsKey: string) => PaneGeometry<T>;
|
|
45
|
+
export declare const buildGridPaneLayout: <T>(orderedColumns: GridColumn<T>[], columnWidths: Record<string, number>) => GridPaneLayout<T>;
|
|
46
|
+
export type PaneColumnLookupResult<T> = {
|
|
47
|
+
pane: ColumnPane;
|
|
48
|
+
entry: PaneColumnEntry<T>;
|
|
49
|
+
};
|
|
50
|
+
export declare const lookupPaneColumn: <T>(layout: GridPaneLayout<T>, logicalIndex: number) => PaneColumnLookupResult<T> | null;
|
|
51
|
+
export declare const findLogicalIndexFromPaneOffset: <T>(paneGeometry: PaneGeometry<T>, offset: number) => number;
|
|
52
|
+
export declare const findPaneDropSlot: <T>(paneGeometry: PaneGeometry<T>, paneLocalOffset: number) => number;
|
|
53
|
+
export declare const paneDropSlotBoundaryX: <T>(paneGeometry: PaneGeometry<T>, slot: number) => number;
|
|
54
|
+
export declare const countPinnedColumns: <T>(layout: GridPaneLayout<T>) => {
|
|
55
|
+
left: number;
|
|
56
|
+
center: number;
|
|
57
|
+
right: number;
|
|
58
|
+
};
|
|
59
|
+
export declare const isPlainLayout: <T>(layout: GridPaneLayout<T>) => boolean;
|
|
60
|
+
export type PaneColumnExtent = {
|
|
61
|
+
start: number;
|
|
62
|
+
end: number;
|
|
63
|
+
width: number;
|
|
64
|
+
};
|
|
65
|
+
export type PaneColumnExtentMap = Record<ColumnPane, PaneColumnExtent | null>;
|
|
66
|
+
export declare const computePaneColumnExtents: <T>(layout: GridPaneLayout<T>, startLogicalIndex: number, endLogicalIndex: number) => PaneColumnExtentMap;
|
|
67
|
+
export declare const computeFullWidthPaneExtents: <T>(layout: GridPaneLayout<T>) => PaneColumnExtentMap;
|
|
68
|
+
export type SinglePaneColumnExtent = {
|
|
69
|
+
pane: ColumnPane;
|
|
70
|
+
extent: PaneColumnExtent;
|
|
71
|
+
};
|
|
72
|
+
export declare const computeSinglePaneColumnExtent: <T>(layout: GridPaneLayout<T>, logicalIndex: number) => SinglePaneColumnExtent | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { GridRowKey } from '../model/gridTypes';
|
|
2
|
+
import type { RowMetrics } from './verticalGeometry';
|
|
3
|
+
export type RowHeightStore = {
|
|
4
|
+
rowCount: number;
|
|
5
|
+
estimate: number;
|
|
6
|
+
heights: Float64Array;
|
|
7
|
+
prefix: Float64Array;
|
|
8
|
+
measured: Map<GridRowKey, number>;
|
|
9
|
+
};
|
|
10
|
+
export declare const rebuildPrefixFrom: (store: RowHeightStore, fromIndex: number) => void;
|
|
11
|
+
export declare const buildRowHeightStore: (rowCount: number, estimate: number, getRowKey: (viewIndex: number) => GridRowKey, measured?: Map<GridRowKey, number>) => RowHeightStore;
|
|
12
|
+
export declare const setMeasuredRowHeight: (store: RowHeightStore, viewIndex: number, rowKey: GridRowKey, height: number) => boolean;
|
|
13
|
+
export declare const createAutoHeightRowMetrics: (store: RowHeightStore) => RowMetrics;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type SelectOptionEntry = {
|
|
2
|
+
label: string;
|
|
3
|
+
value: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const createSelectOptionsAccumulator: () => {
|
|
6
|
+
collect(rawValue: unknown): void;
|
|
7
|
+
finalize(): SelectOptionEntry[];
|
|
8
|
+
};
|
|
9
|
+
export declare const collectSelectOptions: (rowCount: number, getRawValueAt: (index: number) => unknown) => SelectOptionEntry[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type ServerSideRowCacheOptions = {
|
|
2
|
+
blockSize: number;
|
|
3
|
+
maxBlocks: number;
|
|
4
|
+
};
|
|
5
|
+
export type ServerSideRowCache<T> = {
|
|
6
|
+
getRow: (viewIndex: number) => T | undefined;
|
|
7
|
+
hasBlock: (blockIndex: number) => boolean;
|
|
8
|
+
setBlock: (blockIndex: number, rows: T[]) => void;
|
|
9
|
+
touchBlocks: (blockIndexes: number[]) => void;
|
|
10
|
+
clear: () => void;
|
|
11
|
+
loadedBlockIndexes: () => number[];
|
|
12
|
+
};
|
|
13
|
+
export declare function createServerSideRowCache<T>(options: ServerSideRowCacheOptions): ServerSideRowCache<T>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ColumnFilterValue, GridSortState, ServerSideQuery } from '../model/gridTypes';
|
|
2
|
+
export declare const buildServerSideQuery: (input: {
|
|
3
|
+
globalText: string;
|
|
4
|
+
columnFilters: Record<string, ColumnFilterValue>;
|
|
5
|
+
sort: GridSortState;
|
|
6
|
+
}) => ServerSideQuery;
|
|
7
|
+
export declare const serializeServerSideQuery: (query: ServerSideQuery) => string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { GridColumn, GridSortState } from '../model/gridTypes';
|
|
2
|
+
import type { RowOrder } from './filtering';
|
|
3
|
+
export declare const STRING_COLLATOR: Intl.Collator;
|
|
4
|
+
export declare const compareUnknownValues: (left: unknown, right: unknown) => number;
|
|
5
|
+
export declare const nextSortEntries: (current: GridSortState, columnKey: string, direction: "asc" | "desc", additive: boolean) => GridSortState;
|
|
6
|
+
export declare const addSortEntry: (current: GridSortState, columnKey: string, direction: "asc" | "desc") => GridSortState;
|
|
7
|
+
export declare const setSortEntryDirection: (current: GridSortState, index: number, direction: "asc" | "desc") => GridSortState;
|
|
8
|
+
export declare const setSortEntryColumn: (current: GridSortState, index: number, columnKey: string) => GridSortState;
|
|
9
|
+
export declare const removeSortEntryAt: (current: GridSortState, index: number) => GridSortState;
|
|
10
|
+
export declare const moveSortEntry: (current: GridSortState, from: number, to: number) => GridSortState;
|
|
11
|
+
export declare const sortOrder: <T>(rows: T[], order: RowOrder, columns: GridColumn<T>[], sort: GridSortState) => RowOrder;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export declare const MAX_BODY_PX = 15000000;
|
|
2
|
+
export declare const AUTO_HEIGHT_MAX_ROWS = 50000;
|
|
3
|
+
export declare const shouldUseAutoHeight: (autoHeightEnabled: boolean, hasAutoHeightColumn: boolean, viewRowCount: number, maxRows: number) => boolean;
|
|
4
|
+
export declare const WINDOW_BASE_CHUNK_PX: number;
|
|
5
|
+
export type VerticalRow = {
|
|
6
|
+
index: number;
|
|
7
|
+
start: number;
|
|
8
|
+
size?: number;
|
|
9
|
+
};
|
|
10
|
+
export type VerticalGeometry = {
|
|
11
|
+
physicalBodyHeight: number;
|
|
12
|
+
logicalBodyHeight: number;
|
|
13
|
+
scaleFactor: number;
|
|
14
|
+
translateY: number;
|
|
15
|
+
windowBaseOffsetPx: number;
|
|
16
|
+
rows: VerticalRow[];
|
|
17
|
+
rowIndexSet: Set<number>;
|
|
18
|
+
};
|
|
19
|
+
export type ComputeVerticalGeometryArgs = {
|
|
20
|
+
rowCount: number;
|
|
21
|
+
rowHeight: number;
|
|
22
|
+
headerHeight: number;
|
|
23
|
+
viewportHeight: number;
|
|
24
|
+
scrollTop: number;
|
|
25
|
+
overscan: number;
|
|
26
|
+
maxBodyPx: number;
|
|
27
|
+
};
|
|
28
|
+
export type RowMetrics = {
|
|
29
|
+
rowCount: number;
|
|
30
|
+
rowTop(index: number): number;
|
|
31
|
+
rowsHeight(startInclusive: number, endInclusive: number): number;
|
|
32
|
+
totalBodyHeight: number;
|
|
33
|
+
rowAtContentY(y: number): number;
|
|
34
|
+
};
|
|
35
|
+
export declare const createUniformRowMetrics: (rowCount: number, rowHeight: number) => RowMetrics;
|
|
36
|
+
export declare const clipRowRangeToWindow: (selStartRow: number, selEndRow: number, windowFirstRow: number, windowLastRow: number) => {
|
|
37
|
+
start: number;
|
|
38
|
+
end: number;
|
|
39
|
+
} | null;
|
|
40
|
+
export declare const physicalToLogicalScrollTop: (physical: number, scaleFactor: number) => number;
|
|
41
|
+
export declare const logicalToPhysicalScrollTop: (logical: number, scaleFactor: number) => number;
|
|
42
|
+
export declare const clientYToRowIndex: (yRelativeToBodyTop: number, scrollTop: number, scaleFactor: number, rowMetrics: RowMetrics) => number;
|
|
43
|
+
export declare const computeVerticalGeometry: ({ rowCount, rowHeight, headerHeight, viewportHeight, scrollTop, overscan, maxBodyPx, }: ComputeVerticalGeometryArgs) => VerticalGeometry;
|
|
44
|
+
export type ComputeAutoHeightVerticalGeometryArgs = {
|
|
45
|
+
headerHeight: number;
|
|
46
|
+
viewportHeight: number;
|
|
47
|
+
scrollTop: number;
|
|
48
|
+
overscan: number;
|
|
49
|
+
};
|
|
50
|
+
export declare const computeAutoHeightVerticalGeometry: ({ headerHeight, viewportHeight, scrollTop, overscan, }: ComputeAutoHeightVerticalGeometryArgs, rowMetrics: RowMetrics) => VerticalGeometry;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { CellCoord, ColumnFilterValue, GridSortEntry } from './gridTypes';
|
|
2
|
+
export type GridUiAction = {
|
|
3
|
+
type: 'cell/activate';
|
|
4
|
+
cell: CellCoord | null;
|
|
5
|
+
} | {
|
|
6
|
+
type: 'selection/start';
|
|
7
|
+
cell: CellCoord;
|
|
8
|
+
} | {
|
|
9
|
+
type: 'selection/update';
|
|
10
|
+
cell: CellCoord;
|
|
11
|
+
} | {
|
|
12
|
+
type: 'rowSelection/start';
|
|
13
|
+
row: number;
|
|
14
|
+
} | {
|
|
15
|
+
type: 'rowSelection/update';
|
|
16
|
+
row: number;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'columnSelection/start';
|
|
19
|
+
col: number;
|
|
20
|
+
} | {
|
|
21
|
+
type: 'columnSelection/update';
|
|
22
|
+
col: number;
|
|
23
|
+
} | {
|
|
24
|
+
type: 'selection/end';
|
|
25
|
+
} | {
|
|
26
|
+
type: 'selection/clear';
|
|
27
|
+
} | {
|
|
28
|
+
type: 'edit/start';
|
|
29
|
+
cell: CellCoord;
|
|
30
|
+
} | {
|
|
31
|
+
type: 'edit/stop';
|
|
32
|
+
} | {
|
|
33
|
+
type: 'column/resizeStart';
|
|
34
|
+
columnKey: string;
|
|
35
|
+
startX: number;
|
|
36
|
+
startWidth: number;
|
|
37
|
+
minWidth: number;
|
|
38
|
+
maxWidth: number;
|
|
39
|
+
} | {
|
|
40
|
+
type: 'column/resizeUpdate';
|
|
41
|
+
clientX: number;
|
|
42
|
+
} | {
|
|
43
|
+
type: 'column/resizeEnd';
|
|
44
|
+
} | {
|
|
45
|
+
type: 'columnWidths/sync';
|
|
46
|
+
widths: Record<string, number>;
|
|
47
|
+
} | {
|
|
48
|
+
type: 'filter/setGlobal';
|
|
49
|
+
value: string;
|
|
50
|
+
} | {
|
|
51
|
+
type: 'filter/setColumn';
|
|
52
|
+
columnKey: string;
|
|
53
|
+
value: ColumnFilterValue;
|
|
54
|
+
} | {
|
|
55
|
+
type: 'filter/clearColumn';
|
|
56
|
+
columnKey: string;
|
|
57
|
+
} | {
|
|
58
|
+
type: 'filter/resetAll';
|
|
59
|
+
} | {
|
|
60
|
+
type: 'sort/set';
|
|
61
|
+
entries: GridSortEntry[];
|
|
62
|
+
} | {
|
|
63
|
+
type: 'sort/clear';
|
|
64
|
+
};
|
|
65
|
+
export declare const gridActions: {
|
|
66
|
+
activateCell: (cell: CellCoord | null) => GridUiAction;
|
|
67
|
+
startSelection: (cell: CellCoord) => GridUiAction;
|
|
68
|
+
updateSelection: (cell: CellCoord) => GridUiAction;
|
|
69
|
+
startRowSelection: (row: number) => GridUiAction;
|
|
70
|
+
updateRowSelection: (row: number) => GridUiAction;
|
|
71
|
+
startColumnSelection: (col: number) => GridUiAction;
|
|
72
|
+
updateColumnSelection: (col: number) => GridUiAction;
|
|
73
|
+
endSelection: () => GridUiAction;
|
|
74
|
+
clearSelection: () => GridUiAction;
|
|
75
|
+
startEdit: (cell: CellCoord) => GridUiAction;
|
|
76
|
+
stopEdit: () => GridUiAction;
|
|
77
|
+
startColumnResize: (columnKey: string, startX: number, startWidth: number, minWidth: number, maxWidth: number) => GridUiAction;
|
|
78
|
+
updateColumnResize: (clientX: number) => GridUiAction;
|
|
79
|
+
endColumnResize: () => GridUiAction;
|
|
80
|
+
syncColumnWidths: (widths: Record<string, number>) => GridUiAction;
|
|
81
|
+
setGlobalFilter: (value: string) => GridUiAction;
|
|
82
|
+
setColumnFilter: (columnKey: string, value: ColumnFilterValue) => GridUiAction;
|
|
83
|
+
clearColumnFilter: (columnKey: string) => GridUiAction;
|
|
84
|
+
resetAllFilters: () => GridUiAction;
|
|
85
|
+
setSort: (entries: GridSortEntry[]) => GridUiAction;
|
|
86
|
+
clearSort: () => GridUiAction;
|
|
87
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { GridUiAction } from './gridActions';
|
|
2
|
+
import type { GridColumn, GridUiState } from './gridTypes';
|
|
3
|
+
export declare const createInitialGridUiState: <T>(columns: GridColumn<T>[]) => GridUiState;
|
|
4
|
+
export declare const gridUiReducer: (state: GridUiState, action: GridUiAction) => GridUiState;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { CellCoord, CellRange, GridUiState } from './gridTypes';
|
|
2
|
+
export declare const normalizeCellRange: (range: CellRange) => CellRange;
|
|
3
|
+
export declare const normalizeRowRange: (startRow: number, endRow: number) => {
|
|
4
|
+
startRow: number;
|
|
5
|
+
endRow: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const normalizeColumnRange: (startCol: number, endCol: number) => {
|
|
8
|
+
startCol: number;
|
|
9
|
+
endCol: number;
|
|
10
|
+
};
|
|
11
|
+
export declare const selectActiveCell: (state: GridUiState) => CellCoord | null;
|
|
12
|
+
export declare const selectSelection: (state: GridUiState) => import("./gridTypes").GridSelection;
|
|
13
|
+
export declare const selectEditingCell: (state: GridUiState) => CellCoord | null;
|
|
14
|
+
export declare const selectColumnWidth: (state: GridUiState, columnKey: string) => number;
|
|
15
|
+
export declare const selectGlobalFilter: (state: GridUiState) => string;
|
|
16
|
+
export declare const selectColumnFilter: (state: GridUiState, columnKey: string) => import("./gridTypes").ColumnFilterValue;
|
|
17
|
+
export declare const selectIsActiveCell: (state: GridUiState, rowIndex: number, colIndex: number) => boolean;
|
|
18
|
+
export declare const selectIsEditingCell: (state: GridUiState, rowIndex: number, colIndex: number) => boolean;
|
|
19
|
+
export declare const selectIsCellSelected: (state: GridUiState, rowIndex: number, colIndex: number) => boolean;
|
|
20
|
+
export declare const selectIsRowSelected: (state: GridUiState, rowIndex: number) => boolean;
|
|
21
|
+
export declare const selectIsColumnSelected: (state: GridUiState, colIndex: number) => boolean;
|
|
22
|
+
export type SelectionSnapshot = {
|
|
23
|
+
kind: 'none';
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'cell';
|
|
26
|
+
startRow: number;
|
|
27
|
+
endRow: number;
|
|
28
|
+
startCol: number;
|
|
29
|
+
endCol: number;
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'row';
|
|
32
|
+
startRow: number;
|
|
33
|
+
endRow: number;
|
|
34
|
+
} | {
|
|
35
|
+
kind: 'col';
|
|
36
|
+
startCol: number;
|
|
37
|
+
endCol: number;
|
|
38
|
+
};
|
|
39
|
+
export declare const buildSelectionSnapshot: (selection: GridUiState["selection"]) => SelectionSnapshot;
|
|
40
|
+
export declare const isSameCellCoord: (left: CellCoord | null, right: CellCoord | null) => boolean;
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export type GridRowKey = string | number;
|
|
3
|
+
export type RowModel<T> = {
|
|
4
|
+
getRowCount: () => number;
|
|
5
|
+
getRow: (viewIndex: number) => T;
|
|
6
|
+
getSourceIndex: (viewIndex: number) => number;
|
|
7
|
+
getRowKey: (viewIndex: number) => GridRowKey;
|
|
8
|
+
};
|
|
9
|
+
export type ServerSideQuery = {
|
|
10
|
+
globalText?: string;
|
|
11
|
+
columnFilters?: Record<string, ColumnFilterValue>;
|
|
12
|
+
sort?: GridSortState;
|
|
13
|
+
};
|
|
14
|
+
export type ServerSideGetRowsParams = {
|
|
15
|
+
startIndex: number;
|
|
16
|
+
endIndex: number;
|
|
17
|
+
query: ServerSideQuery;
|
|
18
|
+
signal: AbortSignal;
|
|
19
|
+
};
|
|
20
|
+
export type ServerSideGetRowsResult<T> = {
|
|
21
|
+
rows: T[];
|
|
22
|
+
totalRowCount: number;
|
|
23
|
+
};
|
|
24
|
+
export type ServerSideDataSource<T> = {
|
|
25
|
+
getRows: (params: ServerSideGetRowsParams) => Promise<ServerSideGetRowsResult<T>>;
|
|
26
|
+
initialRowCount?: number;
|
|
27
|
+
blockSize?: number;
|
|
28
|
+
maxCachedBlocks?: number;
|
|
29
|
+
};
|
|
30
|
+
export type CellCoord = {
|
|
31
|
+
row: number;
|
|
32
|
+
col: number;
|
|
33
|
+
};
|
|
34
|
+
export type CellRange = {
|
|
35
|
+
start: CellCoord;
|
|
36
|
+
end: CellCoord;
|
|
37
|
+
};
|
|
38
|
+
export type GridSelection = {
|
|
39
|
+
type: 'cell';
|
|
40
|
+
range: CellRange;
|
|
41
|
+
} | {
|
|
42
|
+
type: 'row';
|
|
43
|
+
startRow: number;
|
|
44
|
+
endRow: number;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'col';
|
|
47
|
+
startCol: number;
|
|
48
|
+
endCol: number;
|
|
49
|
+
} | null;
|
|
50
|
+
export type GridFilterState = {
|
|
51
|
+
globalText: string;
|
|
52
|
+
columnFilters: Record<string, ColumnFilterValue>;
|
|
53
|
+
};
|
|
54
|
+
export type GridSortDirection = 'asc' | 'desc' | null;
|
|
55
|
+
export type GridSortEntry = {
|
|
56
|
+
columnKey: string;
|
|
57
|
+
direction: 'asc' | 'desc';
|
|
58
|
+
};
|
|
59
|
+
export type GridSortState = GridSortEntry[];
|
|
60
|
+
export type GridSelectFilterOption = {
|
|
61
|
+
label: string;
|
|
62
|
+
value: string;
|
|
63
|
+
};
|
|
64
|
+
export type SetColumnFilterValue = {
|
|
65
|
+
kind: 'set';
|
|
66
|
+
mode?: 'include' | 'exclude';
|
|
67
|
+
values: string[];
|
|
68
|
+
};
|
|
69
|
+
export type ParsedNumberFilter = {
|
|
70
|
+
mode: 'comparison';
|
|
71
|
+
operator: '>' | '>=' | '<' | '<=' | '=';
|
|
72
|
+
value: number;
|
|
73
|
+
} | {
|
|
74
|
+
mode: 'range';
|
|
75
|
+
min: number;
|
|
76
|
+
max: number;
|
|
77
|
+
};
|
|
78
|
+
export type NumberColumnFilterValue = {
|
|
79
|
+
kind: 'number';
|
|
80
|
+
raw: string;
|
|
81
|
+
parsed: ParsedNumberFilter | null;
|
|
82
|
+
};
|
|
83
|
+
export type TextColumnFilterValue = {
|
|
84
|
+
kind: 'text';
|
|
85
|
+
value: string;
|
|
86
|
+
};
|
|
87
|
+
export type DateColumnFilterValue = {
|
|
88
|
+
kind: 'date';
|
|
89
|
+
value: string;
|
|
90
|
+
};
|
|
91
|
+
export type SelectColumnFilterValue = {
|
|
92
|
+
kind: 'select';
|
|
93
|
+
value: string;
|
|
94
|
+
};
|
|
95
|
+
export type CustomColumnFilterValue = {
|
|
96
|
+
kind: 'custom';
|
|
97
|
+
value: unknown;
|
|
98
|
+
};
|
|
99
|
+
export type ColumnFilterValue = SetColumnFilterValue | NumberColumnFilterValue | TextColumnFilterValue | DateColumnFilterValue | SelectColumnFilterValue | CustomColumnFilterValue;
|
|
100
|
+
export type CellRenderContext<T> = {
|
|
101
|
+
row: T;
|
|
102
|
+
rowIndex: number;
|
|
103
|
+
colIndex: number;
|
|
104
|
+
value: unknown;
|
|
105
|
+
column: GridColumn<T>;
|
|
106
|
+
isActive: boolean;
|
|
107
|
+
isSelected: boolean;
|
|
108
|
+
isEditing: boolean;
|
|
109
|
+
readOnly: boolean;
|
|
110
|
+
setValue: (value: unknown) => void;
|
|
111
|
+
};
|
|
112
|
+
export type CellStyleContext<T> = {
|
|
113
|
+
row: T;
|
|
114
|
+
rowIndex: number;
|
|
115
|
+
colIndex: number;
|
|
116
|
+
value: unknown;
|
|
117
|
+
column: GridColumn<T>;
|
|
118
|
+
isActive: boolean;
|
|
119
|
+
isSelected: boolean;
|
|
120
|
+
isEditing: boolean;
|
|
121
|
+
readOnly: boolean;
|
|
122
|
+
};
|
|
123
|
+
export type CellRenderState = {
|
|
124
|
+
isActive: boolean;
|
|
125
|
+
isSelected: boolean;
|
|
126
|
+
isEditing: boolean;
|
|
127
|
+
readOnly: boolean;
|
|
128
|
+
};
|
|
129
|
+
export type HeaderRenderContext<T> = {
|
|
130
|
+
colIndex: number;
|
|
131
|
+
width: number;
|
|
132
|
+
column: GridColumn<T>;
|
|
133
|
+
filterValue?: unknown;
|
|
134
|
+
isFiltered?: boolean;
|
|
135
|
+
};
|
|
136
|
+
export type GridColumnPinned = 'left' | 'right';
|
|
137
|
+
export type GridColumn<T> = {
|
|
138
|
+
key: string;
|
|
139
|
+
title?: string;
|
|
140
|
+
width: number;
|
|
141
|
+
minWidth?: number;
|
|
142
|
+
maxWidth?: number;
|
|
143
|
+
autoHeight?: boolean;
|
|
144
|
+
visible?: boolean;
|
|
145
|
+
editable?: boolean;
|
|
146
|
+
readOnly?: boolean;
|
|
147
|
+
pinned?: GridColumnPinned;
|
|
148
|
+
getValue?: (row: T) => unknown;
|
|
149
|
+
setValue?: (row: T, value: unknown) => T;
|
|
150
|
+
renderCell?: (ctx: CellRenderContext<T>) => ReactNode;
|
|
151
|
+
cellClassName?: string | ((ctx: CellStyleContext<T>) => string | undefined);
|
|
152
|
+
renderHeader?: (ctx: HeaderRenderContext<T>) => ReactNode;
|
|
153
|
+
filterType?: 'text' | 'number' | 'date' | 'select' | 'set' | 'custom';
|
|
154
|
+
filterOptions?: GridSelectFilterOption[];
|
|
155
|
+
filterFn?: (row: T, filterValue: unknown) => boolean;
|
|
156
|
+
parseClipboardValue?: (raw: string, row: T) => unknown;
|
|
157
|
+
formatClipboardValue?: (value: unknown, row: T) => string;
|
|
158
|
+
};
|
|
159
|
+
export type ColumnResizeDragState = {
|
|
160
|
+
type: 'columnResize';
|
|
161
|
+
columnKey: string;
|
|
162
|
+
startX: number;
|
|
163
|
+
startWidth: number;
|
|
164
|
+
minWidth: number;
|
|
165
|
+
maxWidth: number;
|
|
166
|
+
};
|
|
167
|
+
export type CellSelectionDragState = {
|
|
168
|
+
type: 'selection';
|
|
169
|
+
selectionKind: 'cell';
|
|
170
|
+
anchor: CellCoord;
|
|
171
|
+
};
|
|
172
|
+
export type RowSelectionDragState = {
|
|
173
|
+
type: 'selection';
|
|
174
|
+
selectionKind: 'row';
|
|
175
|
+
anchorRow: number;
|
|
176
|
+
};
|
|
177
|
+
export type ColumnSelectionDragState = {
|
|
178
|
+
type: 'selection';
|
|
179
|
+
selectionKind: 'col';
|
|
180
|
+
anchorCol: number;
|
|
181
|
+
};
|
|
182
|
+
export type GridUiState = {
|
|
183
|
+
activeCell: CellCoord | null;
|
|
184
|
+
selection: GridSelection;
|
|
185
|
+
editingCell: CellCoord | null;
|
|
186
|
+
dragState: CellSelectionDragState | RowSelectionDragState | ColumnSelectionDragState | ColumnResizeDragState | null;
|
|
187
|
+
columnWidths: Record<string, number>;
|
|
188
|
+
filters: GridFilterState;
|
|
189
|
+
sort: GridSortState;
|
|
190
|
+
};
|
|
191
|
+
export type SpreadsheetGridSelectionStats = {
|
|
192
|
+
selectedCellCount: number;
|
|
193
|
+
selectedRowCount: number;
|
|
194
|
+
selectedColumnCount: number;
|
|
195
|
+
};
|
|
196
|
+
export type SpreadsheetGridDerivedSummary = {
|
|
197
|
+
rowSummaryText: string;
|
|
198
|
+
columnSummaryText: string;
|
|
199
|
+
filterSummaryText: string;
|
|
200
|
+
sortSummaryText: string;
|
|
201
|
+
activeCellLabel: string;
|
|
202
|
+
selectionLabel: string;
|
|
203
|
+
selectionStatsText: string;
|
|
204
|
+
selectionStats: SpreadsheetGridSelectionStats;
|
|
205
|
+
hasGlobalFilter: boolean;
|
|
206
|
+
globalFilterPreview: string | null;
|
|
207
|
+
activeColumnFilterCount: number;
|
|
208
|
+
hasAnyFilter: boolean;
|
|
209
|
+
hasSorting: boolean;
|
|
210
|
+
sortedColumnLabel: string | null;
|
|
211
|
+
};
|
|
212
|
+
export type SpreadsheetGridSlotContext<T> = {
|
|
213
|
+
rows: T[];
|
|
214
|
+
filteredRows: T[];
|
|
215
|
+
columns: GridColumn<T>[];
|
|
216
|
+
visibleColumns: GridColumn<T>[];
|
|
217
|
+
globalFilterText: string;
|
|
218
|
+
columnFilterValues: Record<string, ColumnFilterValue>;
|
|
219
|
+
sortState: GridSortState;
|
|
220
|
+
setGlobalFilterText: (value: string) => void;
|
|
221
|
+
activeCell: CellCoord | null;
|
|
222
|
+
selection: GridSelection;
|
|
223
|
+
derivedSummary: SpreadsheetGridDerivedSummary;
|
|
224
|
+
};
|
|
225
|
+
export type GridClassNames = {
|
|
226
|
+
root?: string;
|
|
227
|
+
toolbar?: string;
|
|
228
|
+
statusBar?: string;
|
|
229
|
+
headerRow?: string;
|
|
230
|
+
headerCell?: string;
|
|
231
|
+
bodyRow?: string;
|
|
232
|
+
bodyCell?: string;
|
|
233
|
+
rowHeaderCell?: string;
|
|
234
|
+
iconButton?: string;
|
|
235
|
+
};
|
|
236
|
+
export type SpreadsheetGridProps<T> = {
|
|
237
|
+
rows?: T[];
|
|
238
|
+
dataSource?: ServerSideDataSource<T>;
|
|
239
|
+
serverSideRefreshToken?: number;
|
|
240
|
+
columns: GridColumn<T>[];
|
|
241
|
+
onRowsChange?: (nextRows: T[]) => void;
|
|
242
|
+
onColumnsChange?: (nextColumns: GridColumn<T>[]) => void;
|
|
243
|
+
rowKeyGetter?: (row: T, index: number) => GridRowKey;
|
|
244
|
+
createRow?: () => T;
|
|
245
|
+
createOverflowColumn?: (columnIndex: number) => GridColumn<T>;
|
|
246
|
+
rowHeight?: number;
|
|
247
|
+
autoHeight?: boolean;
|
|
248
|
+
estimateRowHeight?: number;
|
|
249
|
+
headerHeight?: number;
|
|
250
|
+
rowHeaderWidth?: number;
|
|
251
|
+
readOnly?: boolean;
|
|
252
|
+
canEditCell?: (rowIndex: number, colIndex: number, row: T, column: GridColumn<T>) => boolean;
|
|
253
|
+
enableRangeSelection?: boolean;
|
|
254
|
+
enableGlobalFilter?: boolean;
|
|
255
|
+
enableColumnFilter?: boolean;
|
|
256
|
+
enableSorting?: boolean;
|
|
257
|
+
enableRowHover?: boolean;
|
|
258
|
+
enableColumnHeaderHover?: boolean;
|
|
259
|
+
enableColumnMenu?: boolean;
|
|
260
|
+
noMatchingRowsText?: string;
|
|
261
|
+
noRowsText?: string;
|
|
262
|
+
renderTopBar?: (context: SpreadsheetGridSlotContext<T>) => ReactNode;
|
|
263
|
+
renderBottomBar?: (context: SpreadsheetGridSlotContext<T>) => ReactNode;
|
|
264
|
+
className?: string;
|
|
265
|
+
classNames?: GridClassNames;
|
|
266
|
+
getRowClassName?: (row: T, rowIndex: number) => string | undefined;
|
|
267
|
+
};
|