-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathtypes.ts
218 lines (190 loc) · 7.15 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import * as React from "react";
import FormulaParser from "fast-formula-parser";
import { Point } from "./point";
import { Selection } from "./selection";
import { Model } from "./engine";
import { PointRange } from "./point-range";
import { Matrix } from "./matrix";
/** The base type of cell data in Spreadsheet */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type CellBase<Value = any> = {
/** Whether the cell should not be editable */
readOnly?: boolean;
/** Class to be given for the cell element */
className?: string;
/** The value of the cell */
value: Value;
/** Custom component to render when the cell is edited, if not defined would default to the component defined for the Spreadsheet */
DataEditor?: DataEditorComponent<CellBase<Value>>;
/** Custom component to render when the cell is viewed, if not defined would default to the component defined for the Spreadsheet */
DataViewer?: DataViewerComponent<CellBase<Value>>;
};
/**
* A cell with it's coordinates
* @deprecated the component does not use cell descriptors anymore. Instead it passes cell point and cell value explicitly.
*/
export type CellDescriptor<Cell> = {
/** The cell's data */
data: Cell | undefined;
} & Point;
/** The spreadsheet's write mode */
export type Mode = "view" | "edit";
/** Dimensions of an element */
export type Dimensions = {
/** The element's width in pixels */
width: number;
/** The element's height in pixels */
height: number;
/** The distance of the element from it's container top border in pixels */
top: number;
/** The distance of the element from it's container left border in pixels */
left: number;
};
/* List of highlighted cells */
export type Highlight = {
classNames: string[];
selection: Selection;
}
export type StoreState<Cell extends CellBase = CellBase> = {
model: Model<Cell>;
selected: Selection;
highlights: Highlight[];
copied: PointRange | null;
hasPasted: boolean;
cut: boolean;
active: Point | null;
mode: Mode;
rowDimensions: Record<number, Pick<Dimensions, "height" | "top"> | undefined>;
columnDimensions: Record<
number,
Pick<Dimensions, "width" | "left"> | undefined
>;
dragging: boolean;
lastChanged: Point | null;
lastCommit: null | CellChange<Cell>[];
};
export type CellChange<Cell extends CellBase = CellBase> = {
prevCell: Cell | null;
nextCell: Cell | null;
};
/** Type of Spreadsheet Cell component props */
export type CellComponentProps<Cell extends CellBase = CellBase> = {
/** The row of the cell */
row: number;
/** The column of the cell */
column: number;
/** The DataViewer component to be used by the cell */
DataViewer: DataViewerComponent<Cell>;
/** Whether the cell is selected */
selected: boolean;
/** Whether the cell is active */
active: boolean;
/** Whether the cell is copied */
copied: boolean;
/** Whether the user is dragging */
dragging: boolean;
/** The mode of the cell */
mode: Mode;
/** The data of the cell */
data: Cell | undefined;
/** The evaluated data of the cell */
evaluatedData: Cell | undefined;
/** Select the cell at the given point */
select: (point: Point) => void;
/** Activate the cell at the given point */
activate: (point: Point) => void;
/** Set the dimensions of the cell at the given point with the given dimensions */
setCellDimensions: (point: Point, dimensions: Dimensions) => void;
/** Set data of the cell */
setCellData: (cell: Cell) => void;
};
/** Type of the Spreadsheet Cell component */
export type CellComponent<Cell extends CellBase = CellBase> =
React.ComponentType<CellComponentProps<Cell>>;
type DataComponentProps<Cell extends CellBase> = {
/** The rendered cell by the component */
cell: Cell | undefined;
} & Point;
/** Type of the Spreadsheet DataViewer component props */
export type DataViewerProps<Cell extends CellBase = CellBase> =
DataComponentProps<Cell> & {
/** Set data of the cell */
setCellData: (cell: Cell) => void;
evaluatedCell: Cell | undefined;
};
/** Type of the Spreadsheet DataViewer component */
export type DataViewerComponent<Cell extends CellBase = CellBase> =
React.ComponentType<DataViewerProps<Cell>>;
/** Type of the Spreadsheet DataEditor component props */
export type DataEditorProps<Cell extends CellBase = CellBase> =
DataComponentProps<Cell> & {
/** Callback to be called when the cell's value is changed */
onChange: (cell: Cell) => void;
/** Callback to be called when edit mode should be exited */
exitEditMode: () => void;
};
/** Type of the Spreadsheet DataEditor component */
export type DataEditorComponent<Cell extends CellBase = CellBase> =
React.ComponentType<DataEditorProps<Cell>>;
/** Type of the Spreadsheet Table component props */
export type TableProps = React.PropsWithChildren<{
/** Numebr of columns the table should render */
columns: number;
/** Whether column indicators are hidden */
hideColumnIndicators?: boolean | null;
}>;
/** Type of the Spreadsheet Table component */
export type TableComponent = React.ComponentType<TableProps>;
/** Type of the Spreadsheet Row component props */
export type RowProps = React.PropsWithChildren<{
/** The row index of the table */
row: number;
}>;
/** Type of the Row component */
export type RowComponent = React.ComponentType<RowProps>;
/** Type of the Spreadsheet HeaderRow component props */
export type HeaderRowProps = React.PropsWithChildren<{}>;
/** Type of the HeaderRow component */
export type HeaderRowComponent = React.ComponentType<HeaderRowProps>;
/** Type of the Spreadsheet RowIndicator component props */
export type RowIndicatorProps = {
/** The row the indicator indicates */
row: number;
/** A custom label for the indicator as provided in rowLabels */
label?: React.ReactNode | null;
/** Whether the entire row is selected */
selected: boolean;
/** Callback to be called when the row is selected */
onSelect: (row: number, extend: boolean) => void;
};
/** Type of the RowIndicator component */
export type RowIndicatorComponent = React.ComponentType<RowIndicatorProps>;
/** Type of the Spreadsheet ColumnIndicator component props */
export type ColumnIndicatorProps = {
/** The column the indicator indicates */
column: number;
/** A custom label for the indicator as provided in columnLabels */
label?: React.ReactNode | null;
/** Whether the entire column in selected */
selected: boolean;
/** Callback to be called when the column is selected */
onSelect: (column: number, extend: boolean) => void;
};
/** Type of the ColumnIndicator component */
export type ColumnIndicatorComponent =
React.ComponentType<ColumnIndicatorProps>;
/** Type of the Spreadsheet CornerIndicator component props */
export type CornerIndicatorProps = {
/** Whether the entire table is selected */
selected: boolean;
/** Callback to select the entire table */
onSelect: () => void;
};
/** Type of the CornerIndicator component */
export type CornerIndicatorComponent =
React.ComponentType<CornerIndicatorProps>;
export type CommitChanges<Cell extends CellBase = CellBase> = Array<{
prevCell: Cell | null;
nextCell: Cell | null;
}>;
export type CreateFormulaParser = (data: Matrix<CellBase>) => FormulaParser;