@ishibashi0112/spreadsheet-grid 0.4.0 → 0.6.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/SpreadsheetGrid.d.ts +1 -1
- package/dist/index.cjs +8 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2049 -1613
- package/dist/logic/exportCsv.d.ts +11 -0
- package/dist/logic/gridState.d.ts +13 -0
- package/dist/logic/scrollTargets.d.ts +22 -0
- package/dist/model/gridActions.d.ts +7 -3
- package/dist/model/gridTypes.d.ts +56 -1
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { GridColumn } from '../model/gridTypes';
|
|
2
|
+
export type SerializeRowsToCsvParams<T> = {
|
|
3
|
+
getRow: (viewIndex: number) => T;
|
|
4
|
+
startRow: number;
|
|
5
|
+
endRow: number;
|
|
6
|
+
columns: GridColumn<T>[];
|
|
7
|
+
delimiter?: string;
|
|
8
|
+
includeHeaders?: boolean;
|
|
9
|
+
bom?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare const serializeRowsToCsv: <T>({ getRow, startRow, endRow, columns, delimiter, includeHeaders, bom, }: SerializeRowsToCsvParams<T>) => string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ColumnFilterValue, GridColumn, GridColumnState, GridFilterState, GridSortState, GridState } from '../model/gridTypes';
|
|
2
|
+
export declare const GRID_STATE_VERSION = 2;
|
|
3
|
+
export declare const cloneColumnFilterValue: (value: ColumnFilterValue) => ColumnFilterValue;
|
|
4
|
+
export declare const extractColumnState: <T>(columns: GridColumn<T>[]) => GridColumnState[];
|
|
5
|
+
export declare const buildGridState: (columnWidths: Record<string, number>, filters: GridFilterState, sort: GridSortState, columns?: GridColumnState[], version?: number) => GridState;
|
|
6
|
+
export declare const migrateGridState: (input: unknown) => GridState;
|
|
7
|
+
export declare const applyColumnState: <T>(currentColumns: GridColumn<T>[], savedColumnState: GridColumnState[], savedWidths: Record<string, number>) => GridColumn<T>[];
|
|
8
|
+
export declare const isSameGridState: (a: GridState, b: GridState) => boolean;
|
|
9
|
+
export type StateChangeDecision = {
|
|
10
|
+
emit: boolean;
|
|
11
|
+
nextLast: GridState | null;
|
|
12
|
+
};
|
|
13
|
+
export declare const decideStateChangeEmit: (prevLast: GridState | null, current: GridState, isDragging: boolean) => StateChangeDecision;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ScrollAlign } from '../model/gridTypes';
|
|
2
|
+
export type VerticalScrollTargetParams = {
|
|
3
|
+
rowTop: number;
|
|
4
|
+
rowHeight: number;
|
|
5
|
+
headerHeight: number;
|
|
6
|
+
viewportHeight: number;
|
|
7
|
+
currentScrollTop: number;
|
|
8
|
+
align: ScrollAlign;
|
|
9
|
+
maxScrollTop?: number;
|
|
10
|
+
};
|
|
11
|
+
export declare const computeVerticalScrollTarget: ({ rowTop, rowHeight, headerHeight, viewportHeight, currentScrollTop, align, maxScrollTop, }: VerticalScrollTargetParams) => number;
|
|
12
|
+
export type HorizontalScrollTargetParams = {
|
|
13
|
+
cellLeft: number;
|
|
14
|
+
cellWidth: number;
|
|
15
|
+
leftPaneWidth: number;
|
|
16
|
+
rightPaneWidth: number;
|
|
17
|
+
viewportWidth: number;
|
|
18
|
+
currentScrollLeft: number;
|
|
19
|
+
align: ScrollAlign;
|
|
20
|
+
maxScrollLeft?: number;
|
|
21
|
+
};
|
|
22
|
+
export declare const computeHorizontalScrollTarget: ({ cellLeft, cellWidth, leftPaneWidth, rightPaneWidth, viewportWidth, currentScrollLeft, align, maxScrollLeft, }: HorizontalScrollTargetParams) => number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CellCoord, ColumnFilterValue, GridSortEntry } from './gridTypes';
|
|
1
|
+
import type { CellCoord, ColumnFilterValue, GridFilterState, GridSortEntry } from './gridTypes';
|
|
2
2
|
export type GridUiAction = {
|
|
3
3
|
type: 'cell/activate';
|
|
4
4
|
cell: CellCoord | null;
|
|
@@ -35,7 +35,7 @@ export type GridUiAction = {
|
|
|
35
35
|
startX: number;
|
|
36
36
|
startWidth: number;
|
|
37
37
|
minWidth: number;
|
|
38
|
-
maxWidth
|
|
38
|
+
maxWidth?: number;
|
|
39
39
|
} | {
|
|
40
40
|
type: 'column/resizeUpdate';
|
|
41
41
|
clientX: number;
|
|
@@ -59,6 +59,9 @@ export type GridUiAction = {
|
|
|
59
59
|
columnKey: string;
|
|
60
60
|
} | {
|
|
61
61
|
type: 'filter/resetAll';
|
|
62
|
+
} | {
|
|
63
|
+
type: 'filter/setAll';
|
|
64
|
+
filters: GridFilterState;
|
|
62
65
|
} | {
|
|
63
66
|
type: 'sort/set';
|
|
64
67
|
entries: GridSortEntry[];
|
|
@@ -77,7 +80,7 @@ export declare const gridActions: {
|
|
|
77
80
|
clearSelection: () => GridUiAction;
|
|
78
81
|
startEdit: (cell: CellCoord) => GridUiAction;
|
|
79
82
|
stopEdit: () => GridUiAction;
|
|
80
|
-
startColumnResize: (columnKey: string, startX: number, startWidth: number, minWidth: number, maxWidth
|
|
83
|
+
startColumnResize: (columnKey: string, startX: number, startWidth: number, minWidth: number, maxWidth?: number) => GridUiAction;
|
|
81
84
|
updateColumnResize: (clientX: number) => GridUiAction;
|
|
82
85
|
endColumnResize: () => GridUiAction;
|
|
83
86
|
syncColumnWidths: (widths: Record<string, number>) => GridUiAction;
|
|
@@ -86,6 +89,7 @@ export declare const gridActions: {
|
|
|
86
89
|
setColumnFilter: (columnKey: string, value: ColumnFilterValue) => GridUiAction;
|
|
87
90
|
clearColumnFilter: (columnKey: string) => GridUiAction;
|
|
88
91
|
resetAllFilters: () => GridUiAction;
|
|
92
|
+
setAllFilters: (filters: GridFilterState) => GridUiAction;
|
|
89
93
|
setSort: (entries: GridSortEntry[]) => GridUiAction;
|
|
90
94
|
clearSort: () => GridUiAction;
|
|
91
95
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
1
|
+
import type { ReactNode, Ref } from 'react';
|
|
2
2
|
export type GridRowKey = string | number;
|
|
3
3
|
export type RowModel<T> = {
|
|
4
4
|
getRowCount: () => number;
|
|
@@ -148,6 +148,8 @@ export type GridColumn<T> = {
|
|
|
148
148
|
maxWidth?: number;
|
|
149
149
|
flex?: number;
|
|
150
150
|
resizable?: boolean;
|
|
151
|
+
suppressAutoSize?: boolean;
|
|
152
|
+
estimateCellWidth?: (row: T, column: GridColumn<T>) => number;
|
|
151
153
|
autoHeight?: boolean;
|
|
152
154
|
visible?: boolean;
|
|
153
155
|
editable?: boolean;
|
|
@@ -243,7 +245,60 @@ export type GridClassNames = {
|
|
|
243
245
|
rowHeaderCell?: string;
|
|
244
246
|
iconButton?: string;
|
|
245
247
|
};
|
|
248
|
+
export type ScrollAlign = 'auto' | 'start' | 'center' | 'end';
|
|
249
|
+
export type CsvExportScope = 'all' | 'selection' | 'visible';
|
|
250
|
+
export type CsvExportOptions = {
|
|
251
|
+
scope?: CsvExportScope;
|
|
252
|
+
includeHeaders?: boolean;
|
|
253
|
+
delimiter?: string;
|
|
254
|
+
bom?: boolean;
|
|
255
|
+
};
|
|
256
|
+
export type GridColumnState = {
|
|
257
|
+
key: string;
|
|
258
|
+
visible?: boolean;
|
|
259
|
+
pinned?: GridColumnPinned;
|
|
260
|
+
};
|
|
261
|
+
export type GridState = {
|
|
262
|
+
version: number;
|
|
263
|
+
columnWidths: Record<string, number>;
|
|
264
|
+
filters: GridFilterState;
|
|
265
|
+
sort: GridSortState;
|
|
266
|
+
columns?: GridColumnState[];
|
|
267
|
+
};
|
|
268
|
+
export type SpreadsheetGridHandle<T> = {
|
|
269
|
+
scrollToRow: (viewRowIndex: number, options?: {
|
|
270
|
+
align?: ScrollAlign;
|
|
271
|
+
}) => void;
|
|
272
|
+
scrollToCell: (viewRowIndex: number, colIndex: number, options?: {
|
|
273
|
+
align?: ScrollAlign;
|
|
274
|
+
}) => void;
|
|
275
|
+
scrollToTop: () => void;
|
|
276
|
+
scrollToBottom: () => void;
|
|
277
|
+
getVisibleRowRange: () => {
|
|
278
|
+
startIndex: number;
|
|
279
|
+
endIndex: number;
|
|
280
|
+
} | null;
|
|
281
|
+
getActiveCell: () => CellCoord | null;
|
|
282
|
+
setActiveCell: (cell: CellCoord | null, options?: {
|
|
283
|
+
scrollIntoView?: boolean;
|
|
284
|
+
}) => void;
|
|
285
|
+
getSelection: () => GridSelection;
|
|
286
|
+
selectCell: (viewRowIndex: number, colIndex: number, options?: {
|
|
287
|
+
scrollIntoView?: boolean;
|
|
288
|
+
}) => void;
|
|
289
|
+
selectRange: (range: CellRange, options?: {
|
|
290
|
+
scrollIntoView?: boolean;
|
|
291
|
+
}) => void;
|
|
292
|
+
clearSelection: () => void;
|
|
293
|
+
getSelectedRows: () => T[];
|
|
294
|
+
exportCsv: (options?: CsvExportOptions) => string;
|
|
295
|
+
downloadCsv: (filename?: string, options?: CsvExportOptions) => void;
|
|
296
|
+
getState: () => GridState;
|
|
297
|
+
applyState: (state: GridState) => void;
|
|
298
|
+
};
|
|
246
299
|
export type SpreadsheetGridProps<T> = {
|
|
300
|
+
ref?: Ref<SpreadsheetGridHandle<T>>;
|
|
301
|
+
onStateChange?: (state: GridState) => void;
|
|
247
302
|
rows?: T[];
|
|
248
303
|
dataSource?: ServerSideDataSource<T>;
|
|
249
304
|
serverSideRefreshToken?: number;
|