forked from iddan/react-spreadsheet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
160 lines (128 loc) · 4.57 KB
/
index.d.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
declare module 'react-spreadsheet' {
import * as React from 'react';
interface IDimensions {
width: number,
height: number,
top: number,
left: number,
}
interface IPoint {
column: number,
row: number,
}
type Matrix<T> = Array<Array<T | typeof undefined>>;
type Mode = 'edit' | 'view';
// see: https://stackoverflow.com/a/50375286
type UnionToIntersection<U> =
(U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
type OnSignatures<ListenersT> =
{ [EventT in keyof ListenersT]: (event: EventT, listener: ListenersT[EventT]) => void };
type OnAll<ListenersT> =
UnionToIntersection<OnSignatures<ListenersT>[keyof ListenersT]>;
interface FormulaParserCoords { index: number }
interface FormulaParserCell {
// label: string,
row: FormulaParserCoords,
column: FormulaParserCoords,
}
type FormulaParserDone = (nextValue: any) => void;
interface FormulaParserEvents {
callCellValue: (cellCoord: FormulaParserCell, done: FormulaParserDone) => void,
callRangeValue: (startCellCoord: FormulaParserCell, endCellCoord: FormulaParserCell, done: FormulaParserDone) => void,
}
interface FormulaParserResult {
error: string | null,
result: boolean | string | number | null,
}
export interface IFormulaParser {
on: OnAll<FormulaParserEvents>,
parse: (formula: string) => FormulaParserResult,
}
interface CellDescriptor<Cell> extends IPoint {
data?: Cell,
}
type CellGetter<Cell, Value> = (cell: CellDescriptor<Cell>) => Value;
interface CellComponentProps<Cell, Value> {
cell?: Cell,
getValue: CellGetter<Cell, Value>,
}
export type DataViewerProps<Cell, Value> = CellComponentProps<Cell, Value> & {
column: number,
formulaParser: IFormulaParser,
row: number,
getValue: CellGetter<Cell, Value>,
};
export type DataEditorProps<Cell, Value> = CellComponentProps<Cell, Value> & {
onChange: (cell: Cell) => void,
};
export type CellProps<Data, Value> = {
column: number,
row: number,
DataViewer: React.ComponentType<DataViewerProps<Data, Value>>,
getValue: CellGetter<Data, Value>,
formulaParser: IFormulaParser,
// From connect()
selected: boolean,
active: boolean,
copied: boolean,
dragging: boolean,
mode: Mode,
data?: Data,
activate: (point: IPoint) => void,
select: (point: IPoint) => void,
setCellDimensions: (point: IPoint, dimensions: IDimensions) => void,
};
export type CornerIndicatorProps = {};
export type ColumnIndicatorProps = {
column: number,
label?: React.ReactNode,
};
export type RowProps = { children: React.ReactNode };
export type RowIndicatorProps = {
row: number,
label?: React.ReactNode,
};
export type TableProps = {
children: React.ReactNode,
columns: number,
hideColumnIndicators?: boolean,
};
export interface DefaultCell {
className?: string,
readOnly?: boolean,
DataViewer?: React.ComponentType<DataViewerProps<any, any>>,
DataEditor?: React.ComponentType<DataEditorProps<any, any>>,
}
export interface DefaultCellValue {
value: string | number | boolean | null,
}
export type SpreadsheetProps<Cell, Value> = {
// Spreadsheet
data: Matrix<Value>,
formulaParser?: IFormulaParser,
columnLabels?: string[]
ColumnIndicator?: React.ComponentType<ColumnIndicatorProps>,
CornerIndicator?: React.ComponentType<CornerIndicatorProps>,
rowLabels?: string[],
RowIndicator?: React.ComponentType<RowIndicatorProps>,
hideRowIndicators?: boolean,
hideColumnIndicators?: boolean,
Table?: React.ComponentType<TableProps>,
Row?: React.ComponentType<RowProps>,
Cell?: React.ComponentType<CellProps<Cell, Value>>,
DataViewer?: React.ComponentType<DataViewerProps<Cell, Value>>,
DataEditor?: React.ComponentType<DataEditorProps<Cell, Value>>,
onKeyDown?: (event: React.SyntheticEvent<HTMLElement, KeyboardEvent>) => void,
getValue?: CellGetter<Cell, Value>,
getBindingsForCell?: CellGetter<Cell, IPoint[]>,
// SpreadsheetStateProvider
onActivate?: (active: IPoint) => void,
onCellCommit?: (prevCell: Cell, nextCell: Cell, coords: IPoint) => void,
onChange?: (data: Matrix<Value>) => void,
onModeChange?: (mode: Mode) => void,
onSelect?: (selected: IPoint[]) => void,
};
export function createEmptyMatrix<T = DefaultCellValue>(rows: number, columns: number): Matrix<T>;
class Spreadsheet<Cell = DefaultCell, Value = DefaultCellValue> extends React.Component<SpreadsheetProps<Cell, Value>> {}
export default Spreadsheet;
}