pixel-react 1.1.8 → 1.1.9
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/components/AddButton/AddButton.d.ts +5 -0
- package/lib/components/AddButton/AddButton.stories.d.ts +6 -0
- package/lib/components/AddButton/index.d.ts +1 -0
- package/lib/components/AddButton/types.d.ts +4 -0
- package/lib/components/ExcelFile/ChangeExcelStyles.d.ts +14 -0
- package/lib/components/ExcelFile/ColorBarSelector/ColorBarSelector.d.ts +8 -0
- package/lib/components/ExcelFile/ContextMenu/ContextMenu.d.ts +4 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/ActiveCell.d.ts +7 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/Cell.d.ts +4 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/ColumnIndicator.d.ts +5 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/Copied.d.ts +3 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/CornerIndicator.d.ts +5 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/DataEditor.d.ts +5 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/DataViewer.d.ts +8 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/FloatingRect.d.ts +10 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/HeaderRow.d.ts +3 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/Row.d.ts +3 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/RowIndicator.d.ts +5 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/Selected.d.ts +3 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/Spreadsheet.d.ts +81 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/Table.d.ts +3 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/actions.d.ts +130 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/areModelsEqual.d.ts +1 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/context.d.ts +8 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/engine.d.ts +22 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/formula.d.ts +17 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/index.d.ts +2 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-graph.d.ts +21 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-hash.d.ts +3 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-set.d.ts +24 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/index.d.ts +13 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/matrix.d.ts +67 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/point-range.d.ts +22 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/point.d.ts +11 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/reducer.d.ts +27 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/selection.d.ts +95 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/types.d.ts +215 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/use-dispatch.d.ts +3 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/use-selector.d.ts +3 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/util.d.ts +45 -0
- package/lib/components/ExcelFile/ExcelFile/ExcelFile.d.ts +3 -0
- package/lib/components/ExcelFile/ExcelFile.stories.d.ts +6 -0
- package/lib/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.d.ts +15 -0
- package/lib/components/ExcelFile/ExcelToolBar/ExcelToolBar.d.ts +3 -0
- package/lib/components/ExcelFile/ImportExcelStyles.d.ts +24 -0
- package/lib/components/ExcelFile/Types.d.ts +176 -0
- package/lib/components/ExcelFile/index.d.ts +1 -0
- package/lib/components/IconRadioGroup/IconRadioGroup.d.ts +5 -0
- package/lib/components/IconRadioGroup/IconRadioGroup.stories.d.ts +7 -0
- package/lib/components/IconRadioGroup/index.d.ts +1 -0
- package/lib/components/IconRadioGroup/type.d.ts +41 -0
- package/lib/index.d.ts +45 -1
- package/lib/index.esm.js +682 -244
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +682 -243
- package/lib/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils/find/findAndInsert.d.ts +7 -0
- package/lib/utils/find/findAndInsert.stories.d.ts +7 -0
- package/package.json +4 -2
- package/src/assets/Themes/BaseTheme.scss +1 -0
- package/src/assets/Themes/DarkTheme.scss +1 -0
- package/src/assets/icons/all_borders.svg +3 -0
- package/src/assets/icons/bold.svg +3 -0
- package/src/assets/icons/border_bottom.svg +3 -0
- package/src/assets/icons/border_left.svg +3 -0
- package/src/assets/icons/border_right.svg +3 -0
- package/src/assets/icons/border_top.svg +3 -0
- package/src/assets/icons/clone_icon.svg +3 -0
- package/src/assets/icons/double_underline.svg +5 -0
- package/src/assets/icons/fill_color.svg +7 -0
- package/src/assets/icons/formate_painter.svg +5 -0
- package/src/assets/icons/full_access_icon.svg +4 -0
- package/src/assets/icons/history_icon.svg +19 -0
- package/src/assets/icons/italic.svg +3 -0
- package/src/assets/icons/jira.svg +3 -0
- package/src/assets/icons/linked_defects.svg +11 -0
- package/src/assets/icons/move_icon.svg +5 -0
- package/src/assets/icons/no_access_icon.svg +4 -0
- package/src/assets/icons/no_border.svg +3 -0
- package/src/assets/icons/strike_through.svg +3 -0
- package/src/assets/icons/text_align_center.svg +3 -0
- package/src/assets/icons/text_align_left.svg +3 -0
- package/src/assets/icons/text_align_right.svg +3 -0
- package/src/assets/icons/text_color.svg +3 -0
- package/src/assets/icons/underline.svg +4 -0
- package/src/assets/icons/view_access_icon.svg +4 -0
- package/src/components/AppHeader/AppHeader.scss +14 -9
- package/src/components/AppHeader/AppHeader.stories.tsx +1 -0
- package/src/components/AppHeader/AppHeader.tsx +7 -5
- package/src/components/ExcelFile/ChangeExcelStyles.tsx +78 -0
- package/src/components/ExcelFile/ColorBarselector/ColorBarSelector.scss +13 -0
- package/src/components/ExcelFile/ColorBarselector/ColorBarSelector.tsx +43 -0
- package/src/components/ExcelFile/ContextMenu/ContextMenu.scss +102 -0
- package/src/components/ExcelFile/ContextMenu/ContextMenu.tsx +104 -0
- package/src/components/ExcelFile/ExcelFile/Excel/ActiveCell.tsx +131 -0
- package/src/components/ExcelFile/ExcelFile/Excel/Cell.tsx +201 -0
- package/src/components/ExcelFile/ExcelFile/Excel/ColumnIndicator.tsx +123 -0
- package/src/components/ExcelFile/ExcelFile/Excel/Copied.tsx +25 -0
- package/src/components/ExcelFile/ExcelFile/Excel/CornerIndicator.tsx +49 -0
- package/src/components/ExcelFile/ExcelFile/Excel/DataEditor.tsx +37 -0
- package/src/components/ExcelFile/ExcelFile/Excel/DataViewer.tsx +46 -0
- package/src/components/ExcelFile/ExcelFile/Excel/FloatingRect.tsx +31 -0
- package/src/components/ExcelFile/ExcelFile/Excel/HeaderRow.tsx +5 -0
- package/src/components/ExcelFile/ExcelFile/Excel/Row.tsx +5 -0
- package/src/components/ExcelFile/ExcelFile/Excel/RowIndicator.tsx +102 -0
- package/src/components/ExcelFile/ExcelFile/Excel/Selected.tsx +32 -0
- package/src/components/ExcelFile/ExcelFile/Excel/Spreadsheet.css +144 -0
- package/src/components/ExcelFile/ExcelFile/Excel/Spreadsheet.tsx +494 -0
- package/src/components/ExcelFile/ExcelFile/Excel/Table.tsx +19 -0
- package/src/components/ExcelFile/ExcelFile/Excel/actions.ts +302 -0
- package/src/components/ExcelFile/ExcelFile/Excel/areModelsEqual.ts +18 -0
- package/src/components/ExcelFile/ExcelFile/Excel/context.ts +12 -0
- package/src/components/ExcelFile/ExcelFile/Excel/engine/engine.ts +200 -0
- package/src/components/ExcelFile/ExcelFile/Excel/engine/formula.ts +137 -0
- package/src/components/ExcelFile/ExcelFile/Excel/engine/index.ts +2 -0
- package/src/components/ExcelFile/ExcelFile/Excel/engine/point-graph.ts +154 -0
- package/src/components/ExcelFile/ExcelFile/Excel/engine/point-hash.ts +10 -0
- package/src/components/ExcelFile/ExcelFile/Excel/engine/point-set.ts +69 -0
- package/src/components/ExcelFile/ExcelFile/Excel/index.ts +48 -0
- package/src/components/ExcelFile/ExcelFile/Excel/matrix.ts +388 -0
- package/src/components/ExcelFile/ExcelFile/Excel/point-range.ts +82 -0
- package/src/components/ExcelFile/ExcelFile/Excel/point.ts +15 -0
- package/src/components/ExcelFile/ExcelFile/Excel/reducer.ts +682 -0
- package/src/components/ExcelFile/ExcelFile/Excel/selection.ts +257 -0
- package/src/components/ExcelFile/ExcelFile/Excel/types.ts +269 -0
- package/src/components/ExcelFile/ExcelFile/Excel/typings/fast-formula-parser.d.ts +58 -0
- package/src/components/ExcelFile/ExcelFile/Excel/use-dispatch.ts +8 -0
- package/src/components/ExcelFile/ExcelFile/Excel/use-selector.ts +9 -0
- package/src/components/ExcelFile/ExcelFile/Excel/util.ts +173 -0
- package/src/components/ExcelFile/ExcelFile/ExcelFile.scss +27 -0
- package/src/components/ExcelFile/ExcelFile/ExcelFile.tsx +520 -0
- package/src/components/ExcelFile/ExcelFile.stories.tsx +132 -0
- package/src/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.scss +16 -0
- package/src/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.tsx +79 -0
- package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.scss +22 -0
- package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.tsx +271 -0
- package/src/components/ExcelFile/ImportExcelStyles.tsx +86 -0
- package/src/components/ExcelFile/Types.ts +241 -0
- package/src/components/ExcelFile/index.ts +1 -0
- package/src/components/Icon/Icons.scss +2 -3
- package/src/components/Icon/iconList.ts +50 -1
- package/src/components/IconRadioGroup/IconRadioGroup.scss +60 -0
- package/src/components/IconRadioGroup/IconRadioGroup.stories.tsx +108 -0
- package/src/components/IconRadioGroup/IconRadioGroup.tsx +72 -0
- package/src/components/IconRadioGroup/index.ts +1 -0
- package/src/components/IconRadioGroup/type.ts +50 -0
- package/src/index.ts +2 -0
@@ -0,0 +1,257 @@
|
|
1
|
+
import { PointRange } from "./point-range";
|
2
|
+
import * as Point from "./point";
|
3
|
+
import * as Matrix from "./matrix";
|
4
|
+
|
5
|
+
/** Selection from a spreadsheet */
|
6
|
+
export abstract class Selection {
|
7
|
+
/** Get concrete range of the selection in the given data */
|
8
|
+
abstract toRange(data: Matrix.Matrix<unknown>): PointRange | null;
|
9
|
+
|
10
|
+
/** Normalize the selection according to the given data */
|
11
|
+
abstract normalizeTo(data: Matrix.Matrix<unknown>): this;
|
12
|
+
|
13
|
+
/** Determines whether the given row is entirely selected in given selection */
|
14
|
+
abstract hasEntireRow(row: number): boolean;
|
15
|
+
|
16
|
+
/** Determines whether the given column is entirely selected in given selection */
|
17
|
+
abstract hasEntireColumn(column: number): boolean;
|
18
|
+
|
19
|
+
/** Get the number of selected points according to given data */
|
20
|
+
abstract size(data: Matrix.Matrix<unknown>): number;
|
21
|
+
|
22
|
+
/** Determines whether the given point is within the selection */
|
23
|
+
abstract has(data: Matrix.Matrix<unknown>, point: Point.Point): boolean;
|
24
|
+
|
25
|
+
/** Determines whether the given selection is equal to this selection */
|
26
|
+
abstract equals(selection: Selection): boolean;
|
27
|
+
}
|
28
|
+
|
29
|
+
/** Selection of no cells */
|
30
|
+
export class EmptySelection extends Selection {
|
31
|
+
// @ts-ignore
|
32
|
+
toRange(data: Matrix.Matrix<unknown>): PointRange | null {
|
33
|
+
return null;
|
34
|
+
}
|
35
|
+
normalizeTo(_: Matrix.Matrix<unknown>): this {
|
36
|
+
return this;
|
37
|
+
}
|
38
|
+
hasEntireRow(): boolean {
|
39
|
+
return false;
|
40
|
+
}
|
41
|
+
hasEntireColumn(): boolean {
|
42
|
+
return false;
|
43
|
+
}
|
44
|
+
size(): number {
|
45
|
+
return 0;
|
46
|
+
}
|
47
|
+
has(): boolean {
|
48
|
+
return false;
|
49
|
+
}
|
50
|
+
equals(selection: Selection): boolean {
|
51
|
+
return selection instanceof EmptySelection;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
/** Selection of a range of cells */
|
56
|
+
export class RangeSelection extends Selection {
|
57
|
+
constructor(public range: PointRange) {
|
58
|
+
super();
|
59
|
+
}
|
60
|
+
|
61
|
+
toRange(_: Matrix.Matrix<unknown>): PointRange | null {
|
62
|
+
return this.range;
|
63
|
+
}
|
64
|
+
|
65
|
+
normalizeTo(data: Matrix.Matrix<unknown>): this {
|
66
|
+
const dataRange = getMatrixRange(data);
|
67
|
+
const nextSelection = new RangeSelection(this.range.mask(dataRange));
|
68
|
+
// @ts-expect-error
|
69
|
+
return nextSelection;
|
70
|
+
}
|
71
|
+
|
72
|
+
hasEntireRow(): boolean {
|
73
|
+
return false;
|
74
|
+
}
|
75
|
+
|
76
|
+
hasEntireColumn(): boolean {
|
77
|
+
return false;
|
78
|
+
}
|
79
|
+
|
80
|
+
size(data: Matrix.Matrix<unknown>): number {
|
81
|
+
const range = this.toRange(data);
|
82
|
+
return range ? range.size() : 0;
|
83
|
+
}
|
84
|
+
|
85
|
+
has(data: Matrix.Matrix<unknown>, point: Point.Point): boolean {
|
86
|
+
const range = this.toRange(data);
|
87
|
+
return range !== null && range.has(point);
|
88
|
+
}
|
89
|
+
|
90
|
+
equals(selection: Selection): boolean {
|
91
|
+
return (
|
92
|
+
selection instanceof RangeSelection && this.range.equals(selection.range)
|
93
|
+
);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
/** Selection of an entire part of the spreadsheet */
|
98
|
+
export abstract class EntireSelection extends Selection {}
|
99
|
+
|
100
|
+
/** Selection of the entire worksheet */
|
101
|
+
export class EntireWorksheetSelection extends EntireSelection {
|
102
|
+
toRange(data: Matrix.Matrix<unknown>): PointRange {
|
103
|
+
return getMatrixRange(data);
|
104
|
+
}
|
105
|
+
|
106
|
+
normalizeTo(): this {
|
107
|
+
return this;
|
108
|
+
}
|
109
|
+
|
110
|
+
hasEntireColumn(): boolean {
|
111
|
+
return true;
|
112
|
+
}
|
113
|
+
|
114
|
+
hasEntireRow(): boolean {
|
115
|
+
return true;
|
116
|
+
}
|
117
|
+
|
118
|
+
size(data: Matrix.Matrix<unknown>): number {
|
119
|
+
return Matrix.getColumnsCount(data) * Matrix.getRowsCount(data);
|
120
|
+
}
|
121
|
+
|
122
|
+
has(): boolean {
|
123
|
+
return true;
|
124
|
+
}
|
125
|
+
|
126
|
+
equals(selection: Selection): boolean {
|
127
|
+
return selection instanceof EntireWorksheetSelection;
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
/** Selection of an entire axis in the spreadsheet */
|
132
|
+
export abstract class EntireAxisSelection extends EntireSelection {
|
133
|
+
/** Selection start index, integer */
|
134
|
+
readonly start: number;
|
135
|
+
/** Selection end index, integer */
|
136
|
+
readonly end: number;
|
137
|
+
|
138
|
+
/**
|
139
|
+
* @param start - row index where the selection starts, integer
|
140
|
+
* @param end - row index where the selection ends, integer
|
141
|
+
* @throws {@link InvalidIndexError}
|
142
|
+
*/
|
143
|
+
constructor(start: number, end: number) {
|
144
|
+
if (!isIndex(start)) {
|
145
|
+
throw new InvalidIndexError("start");
|
146
|
+
}
|
147
|
+
if (!isIndex(end)) {
|
148
|
+
throw new InvalidIndexError("end");
|
149
|
+
}
|
150
|
+
super();
|
151
|
+
this.start = Math.min(start, end);
|
152
|
+
this.end = Math.max(start, end);
|
153
|
+
}
|
154
|
+
|
155
|
+
equals(selection: Selection): boolean {
|
156
|
+
return (
|
157
|
+
selection instanceof EntireAxisSelection &&
|
158
|
+
this.constructor === selection.constructor &&
|
159
|
+
this.start === selection.start &&
|
160
|
+
this.end === selection.end
|
161
|
+
);
|
162
|
+
}
|
163
|
+
}
|
164
|
+
|
165
|
+
/** Selection of entire rows in the spreadsheet */
|
166
|
+
export class EntireRowsSelection extends EntireAxisSelection {
|
167
|
+
toRange(data: Matrix.Matrix<unknown>): PointRange {
|
168
|
+
const max = Matrix.maxPoint(data);
|
169
|
+
return new PointRange(
|
170
|
+
{ row: this.start, column: 0 },
|
171
|
+
{ row: this.end, column: max.column }
|
172
|
+
);
|
173
|
+
}
|
174
|
+
|
175
|
+
normalizeTo(data: Matrix.Matrix<unknown>): this {
|
176
|
+
const count = Matrix.getRowsCount(data);
|
177
|
+
const nextSelection = new EntireRowsSelection(
|
178
|
+
Math.max(this.start, 0),
|
179
|
+
Math.min(this.end, count - 1)
|
180
|
+
);
|
181
|
+
// @ts-expect-error
|
182
|
+
return nextSelection;
|
183
|
+
}
|
184
|
+
|
185
|
+
hasEntireRow(row: number): boolean {
|
186
|
+
return row >= this.start && row <= this.end;
|
187
|
+
}
|
188
|
+
|
189
|
+
hasEntireColumn(): boolean {
|
190
|
+
return false;
|
191
|
+
}
|
192
|
+
|
193
|
+
size(data: Matrix.Matrix<unknown>): number {
|
194
|
+
const rows = this.end - this.start + 1;
|
195
|
+
return rows * Matrix.getColumnsCount(data);
|
196
|
+
}
|
197
|
+
|
198
|
+
has(_: Matrix.Matrix<unknown>, point: Point.Point): boolean {
|
199
|
+
return point.row >= this.start && point.row <= this.end;
|
200
|
+
}
|
201
|
+
}
|
202
|
+
|
203
|
+
/** Selection of entire columns in the spreadsheet */
|
204
|
+
export class EntireColumnsSelection extends EntireAxisSelection {
|
205
|
+
toRange(data: Matrix.Matrix<unknown>): PointRange {
|
206
|
+
const max = Matrix.maxPoint(data);
|
207
|
+
return new PointRange(
|
208
|
+
{ row: 0, column: this.start },
|
209
|
+
{ row: max.row, column: this.end }
|
210
|
+
);
|
211
|
+
}
|
212
|
+
|
213
|
+
normalizeTo(data: Matrix.Matrix<unknown>): this {
|
214
|
+
const count = Matrix.getColumnsCount(data);
|
215
|
+
const nextSelection = new EntireColumnsSelection(
|
216
|
+
Math.max(this.start, 0),
|
217
|
+
Math.min(this.end, count - 1)
|
218
|
+
);
|
219
|
+
// @ts-expect-error
|
220
|
+
return nextSelection;
|
221
|
+
}
|
222
|
+
|
223
|
+
hasEntireRow(): boolean {
|
224
|
+
return false;
|
225
|
+
}
|
226
|
+
|
227
|
+
hasEntireColumn(column: number): boolean {
|
228
|
+
return column >= this.start && column <= this.end;
|
229
|
+
}
|
230
|
+
|
231
|
+
size(data: Matrix.Matrix<unknown>): number {
|
232
|
+
const columns = this.end - this.start + 1;
|
233
|
+
return columns * Matrix.getRowsCount(data);
|
234
|
+
}
|
235
|
+
|
236
|
+
has(_: Matrix.Matrix<unknown>, point: Point.Point): boolean {
|
237
|
+
return point.column >= this.start && point.column <= this.end;
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
/** Get the point range of given matrix */
|
242
|
+
export function getMatrixRange(data: Matrix.Matrix<unknown>): PointRange {
|
243
|
+
const maxPoint = Matrix.maxPoint(data);
|
244
|
+
return new PointRange(Point.ORIGIN, maxPoint);
|
245
|
+
}
|
246
|
+
|
247
|
+
/** Determines whether the given value is a valid index */
|
248
|
+
export function isIndex(value: number): boolean {
|
249
|
+
return Number.isInteger(value) && value >= 0;
|
250
|
+
}
|
251
|
+
|
252
|
+
/** Error thrown when passing a non-index value where an index value is expected */
|
253
|
+
export class InvalidIndexError extends Error {
|
254
|
+
constructor(name: string) {
|
255
|
+
super(`${name} is not a valid index. It must be 0 or a positive integer`);
|
256
|
+
}
|
257
|
+
}
|
@@ -0,0 +1,269 @@
|
|
1
|
+
import * as React from "react";
|
2
|
+
import FormulaParser from "fast-formula-parser";
|
3
|
+
import { Point } from "./point";
|
4
|
+
import { Selection } from "./selection";
|
5
|
+
import { Model } from "./engine";
|
6
|
+
import { PointRange } from "./point-range";
|
7
|
+
import { Matrix } from "./matrix";
|
8
|
+
|
9
|
+
/** The base type of cell data in Spreadsheet */
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
11
|
+
export type CellBase<Value = any> = {
|
12
|
+
/** Whether the cell should not be editable */
|
13
|
+
readOnly?: boolean;
|
14
|
+
/** Class to be given for the cell element */
|
15
|
+
className?: string;
|
16
|
+
/** The value of the cell */
|
17
|
+
value: Value;
|
18
|
+
// style?: React.CSSProperties; // or any other relevant type
|
19
|
+
style?: CellStyle;
|
20
|
+
type?: boolean; // or any other relevant type
|
21
|
+
/** Custom component to render when the cell is edited, if not defined would default to the component defined for the Spreadsheet */
|
22
|
+
DataEditor?: DataEditorComponent<CellBase<Value>>;
|
23
|
+
/** Custom component to render when the cell is viewed, if not defined would default to the component defined for the Spreadsheet */
|
24
|
+
DataViewer?: DataViewerComponent<CellBase<Value>>;
|
25
|
+
};
|
26
|
+
|
27
|
+
interface CellStyle {
|
28
|
+
/** Font name for the cell text */
|
29
|
+
name?: string;
|
30
|
+
|
31
|
+
/** Font size of the cell text */
|
32
|
+
size?: number;
|
33
|
+
|
34
|
+
position?:string;
|
35
|
+
|
36
|
+
|
37
|
+
/** Whether the text is bold */
|
38
|
+
bold?: boolean;
|
39
|
+
|
40
|
+
/** Whether the text is italicized */
|
41
|
+
italic?: boolean;
|
42
|
+
|
43
|
+
/** Text color in the cell (hex code) */
|
44
|
+
color?: string;
|
45
|
+
|
46
|
+
/** Background color of the cell (hex code) */
|
47
|
+
backgroundColor?: string;
|
48
|
+
|
49
|
+
/** Border color of the cell (hex code) */
|
50
|
+
borderColor?: string;
|
51
|
+
|
52
|
+
/** Border styles for each side of the cell */
|
53
|
+
border?: {
|
54
|
+
/** Border style for the top side of the cell */
|
55
|
+
top: string;
|
56
|
+
|
57
|
+
/** Border style for the bottom side of the cell */
|
58
|
+
bottom: string;
|
59
|
+
|
60
|
+
/** Border style for the left side of the cell */
|
61
|
+
left: string;
|
62
|
+
|
63
|
+
/** Border style for the right side of the cell */
|
64
|
+
right: string;
|
65
|
+
};
|
66
|
+
|
67
|
+
/** Text alignment and wrapping properties */
|
68
|
+
alignment?: {
|
69
|
+
/** Horizontal text alignment ('left', 'center', or 'right') */
|
70
|
+
horizontal: string;
|
71
|
+
|
72
|
+
/** Vertical text alignment ('top', 'middle', or 'bottom') */
|
73
|
+
vertical: string;
|
74
|
+
|
75
|
+
/** Whether the text is wrapped within the cell */
|
76
|
+
wrapText: boolean;
|
77
|
+
};
|
78
|
+
}
|
79
|
+
|
80
|
+
/**
|
81
|
+
* A cell with it's coordinates
|
82
|
+
* @deprecated the component does not use cell descriptors anymore. Instead it passes cell point and cell value explicitly.
|
83
|
+
*/
|
84
|
+
export type CellDescriptor<Cell extends CellBase> = {
|
85
|
+
/** The cell's data */
|
86
|
+
data: Cell | undefined;
|
87
|
+
} & Point;
|
88
|
+
|
89
|
+
/** The spreadsheet's write mode */
|
90
|
+
export type Mode = "view" | "edit";
|
91
|
+
|
92
|
+
/** Dimensions of an element */
|
93
|
+
export type Dimensions = {
|
94
|
+
/** The element's width in pixels */
|
95
|
+
width: number;
|
96
|
+
/** The element's height in pixels */
|
97
|
+
height: number;
|
98
|
+
/** The distance of the element from it's container top border in pixels */
|
99
|
+
top: number;
|
100
|
+
/** The distance of the element from it's container left border in pixels */
|
101
|
+
left: number;
|
102
|
+
};
|
103
|
+
|
104
|
+
export type StoreState<Cell extends CellBase = CellBase> = {
|
105
|
+
model: Model<Cell>;
|
106
|
+
selected: Selection;
|
107
|
+
copied: PointRange | null;
|
108
|
+
hasPasted: boolean;
|
109
|
+
cut: boolean;
|
110
|
+
active: Point | null;
|
111
|
+
mode: Mode;
|
112
|
+
rowDimensions: Record<number, Pick<Dimensions, "height" | "top"> | undefined>;
|
113
|
+
columnDimensions: Record<
|
114
|
+
number,
|
115
|
+
Pick<Dimensions, "width" | "left"> | undefined
|
116
|
+
>;
|
117
|
+
dragging: boolean;
|
118
|
+
lastChanged: Point | null;
|
119
|
+
lastCommit: null | CellChange<Cell>[];
|
120
|
+
};
|
121
|
+
|
122
|
+
export type CellChange<Cell extends CellBase = CellBase> = {
|
123
|
+
prevCell: Cell | null;
|
124
|
+
nextCell: Cell | null;
|
125
|
+
};
|
126
|
+
|
127
|
+
/** Type of Spreadsheet Cell component props */
|
128
|
+
export type CellComponentProps<Cell extends CellBase = CellBase> = {
|
129
|
+
/** The row of the cell */
|
130
|
+
row: number;
|
131
|
+
/** The column of the cell */
|
132
|
+
column: number;
|
133
|
+
/** The DataViewer component to be used by the cell */
|
134
|
+
DataViewer: DataViewerComponent<Cell>;
|
135
|
+
/** Whether the cell is selected */
|
136
|
+
selected: boolean;
|
137
|
+
/** Whether the cell is active */
|
138
|
+
active: boolean;
|
139
|
+
/** Whether the cell is copied */
|
140
|
+
copied: boolean;
|
141
|
+
/** Whether the user is dragging */
|
142
|
+
dragging: boolean;
|
143
|
+
/** The mode of the cell */
|
144
|
+
mode: Mode;
|
145
|
+
/** The data of the cell */
|
146
|
+
data: Cell | undefined;
|
147
|
+
/** The evaluated data of the cell */
|
148
|
+
evaluatedData: Cell | undefined;
|
149
|
+
/** Select the cell at the given point */
|
150
|
+
select: (point: Point) => void;
|
151
|
+
/** Activate the cell at the given point */
|
152
|
+
activate: (point: Point) => void;
|
153
|
+
/** Set the dimensions of the cell at the given point with the given dimensions */
|
154
|
+
setCellDimensions: (point: Point, dimensions: Dimensions) => void;
|
155
|
+
/** Set data of the cell */
|
156
|
+
setCellData: (cell: Cell) => void;
|
157
|
+
};
|
158
|
+
|
159
|
+
/** Type of the Spreadsheet Cell component */
|
160
|
+
export type CellComponent<Cell extends CellBase = CellBase> =
|
161
|
+
React.ComponentType<CellComponentProps<Cell>>;
|
162
|
+
|
163
|
+
type DataComponentProps<Cell extends CellBase> = {
|
164
|
+
/** The rendered cell by the component */
|
165
|
+
cell: Cell | undefined;
|
166
|
+
} & Point;
|
167
|
+
|
168
|
+
/** Type of the Spreadsheet DataViewer component props */
|
169
|
+
export type DataViewerProps<Cell extends CellBase = CellBase> =
|
170
|
+
DataComponentProps<Cell> & {
|
171
|
+
/** Set data of the cell */
|
172
|
+
setCellData: (cell: Cell) => void;
|
173
|
+
evaluatedCell: Cell | undefined;
|
174
|
+
};
|
175
|
+
|
176
|
+
/** Type of the Spreadsheet DataViewer component */
|
177
|
+
export type DataViewerComponent<Cell extends CellBase = CellBase> =
|
178
|
+
React.ComponentType<DataViewerProps<Cell>>;
|
179
|
+
|
180
|
+
/** Type of the Spreadsheet DataEditor component props */
|
181
|
+
export type DataEditorProps<Cell extends CellBase = CellBase> =
|
182
|
+
DataComponentProps<Cell> & {
|
183
|
+
/** Callback to be called when the cell's value is changed */
|
184
|
+
onChange: (cell: Cell) => void;
|
185
|
+
/** Callback to be called when edit mode should be exited */
|
186
|
+
exitEditMode: () => void;
|
187
|
+
};
|
188
|
+
|
189
|
+
/** Type of the Spreadsheet DataEditor component */
|
190
|
+
export type DataEditorComponent<Cell extends CellBase = CellBase> =
|
191
|
+
React.ComponentType<DataEditorProps<Cell>>;
|
192
|
+
|
193
|
+
/** Type of the Spreadsheet Table component props */
|
194
|
+
export type TableProps = React.PropsWithChildren<{
|
195
|
+
/** Number of columns the table should render */
|
196
|
+
columns: number;
|
197
|
+
/** Whether column indicators are hidden */
|
198
|
+
hideColumnIndicators?: boolean | null;
|
199
|
+
}>;
|
200
|
+
|
201
|
+
/** Type of the Spreadsheet Table component */
|
202
|
+
export type TableComponent = React.ComponentType<TableProps>;
|
203
|
+
|
204
|
+
/** Type of the Spreadsheet Row component props */
|
205
|
+
export type RowProps = React.PropsWithChildren<{
|
206
|
+
/** The row index of the table */
|
207
|
+
row: number;
|
208
|
+
}>;
|
209
|
+
|
210
|
+
/** Type of the Row component */
|
211
|
+
export type RowComponent = React.ComponentType<RowProps>;
|
212
|
+
|
213
|
+
/** Type of the Spreadsheet HeaderRow component props */
|
214
|
+
export type HeaderRowProps = React.PropsWithChildren<{}>;
|
215
|
+
|
216
|
+
/** Type of the HeaderRow component */
|
217
|
+
export type HeaderRowComponent = React.ComponentType<HeaderRowProps>;
|
218
|
+
|
219
|
+
/** Type of the Spreadsheet RowIndicator component props */
|
220
|
+
export type RowIndicatorProps = {
|
221
|
+
/** The row the indicator indicates */
|
222
|
+
row: number;
|
223
|
+
/** A custom label for the indicator as provided in rowLabels */
|
224
|
+
label?: React.ReactNode | null;
|
225
|
+
/** Whether the entire row is selected */
|
226
|
+
selected: boolean;
|
227
|
+
/** Callback to be called when the row is selected */
|
228
|
+
onSelect: (row: number, extend: boolean) => void;
|
229
|
+
};
|
230
|
+
|
231
|
+
/** Type of the RowIndicator component */
|
232
|
+
export type RowIndicatorComponent = React.ComponentType<RowIndicatorProps>;
|
233
|
+
|
234
|
+
/** Type of the Spreadsheet ColumnIndicator component props */
|
235
|
+
export type ColumnIndicatorProps = {
|
236
|
+
/** The column the indicator indicates */
|
237
|
+
column: number;
|
238
|
+
/** A custom label for the indicator as provided in columnLabels */
|
239
|
+
label?: React.ReactNode | null;
|
240
|
+
/** Whether the entire column in selected */
|
241
|
+
selected: boolean;
|
242
|
+
/** Whether the entire column in Fixed */
|
243
|
+
fixed?: boolean;
|
244
|
+
/** Callback to be called when the column is selected */
|
245
|
+
onSelect: (column: number, extend: boolean) => void;
|
246
|
+
};
|
247
|
+
|
248
|
+
/** Type of the ColumnIndicator component */
|
249
|
+
export type ColumnIndicatorComponent =
|
250
|
+
React.ComponentType<ColumnIndicatorProps>;
|
251
|
+
|
252
|
+
/** Type of the Spreadsheet CornerIndicator component props */
|
253
|
+
export type CornerIndicatorProps = {
|
254
|
+
/** Whether the entire table is selected */
|
255
|
+
selected: boolean;
|
256
|
+
/** Callback to select the entire table */
|
257
|
+
onSelect: () => void;
|
258
|
+
};
|
259
|
+
|
260
|
+
/** Type of the CornerIndicator component */
|
261
|
+
export type CornerIndicatorComponent =
|
262
|
+
React.ComponentType<CornerIndicatorProps>;
|
263
|
+
|
264
|
+
export type CommitChanges<Cell extends CellBase = CellBase> = Array<{
|
265
|
+
prevCell: Cell | null;
|
266
|
+
nextCell: Cell | null;
|
267
|
+
}>;
|
268
|
+
|
269
|
+
export type CreateFormulaParser = (data: Matrix<CellBase>) => FormulaParser;
|
@@ -0,0 +1,58 @@
|
|
1
|
+
declare module "fast-formula-parser" {
|
2
|
+
export type CellCoord = {
|
3
|
+
row: number;
|
4
|
+
col: number;
|
5
|
+
};
|
6
|
+
export type CellRef = CellCoord & {
|
7
|
+
sheet: string;
|
8
|
+
};
|
9
|
+
export type RangeRef = {
|
10
|
+
from: CellRef;
|
11
|
+
to: CellRef;
|
12
|
+
sheet: string;
|
13
|
+
};
|
14
|
+
export type BaseValue = number | string | boolean;
|
15
|
+
export type Value = BaseValue | BaseValue[];
|
16
|
+
export type FormulaParserConfig = {
|
17
|
+
functions?: object;
|
18
|
+
onCell?: (ref: CellRef) => Value;
|
19
|
+
onRange?: (range: RangeRef) => Value[];
|
20
|
+
onVariable?: (name: string, sheetName: string) => CellRef | RangeRef;
|
21
|
+
};
|
22
|
+
|
23
|
+
export class FormulaError extends Error {
|
24
|
+
/**
|
25
|
+
* @param error - error code, i.e. #NUM!
|
26
|
+
* @param msg - detailed error message
|
27
|
+
* @param details - additional details
|
28
|
+
*/
|
29
|
+
constructor(error: string, msg?: string, details?: object | Error);
|
30
|
+
|
31
|
+
/** Return true if two errors are same */
|
32
|
+
equals(error: Error): boolean;
|
33
|
+
|
34
|
+
/** Return the formula error in string representation. */
|
35
|
+
toString(): string;
|
36
|
+
|
37
|
+
static DIV0 = "#DIV/0!";
|
38
|
+
static NA = "#N/A";
|
39
|
+
static NAME = "#NAME?";
|
40
|
+
static NULL = "#NULL!";
|
41
|
+
static NUM = "#NUM!";
|
42
|
+
static REF = "#REF!";
|
43
|
+
static VALUE = "#VALUE!";
|
44
|
+
}
|
45
|
+
|
46
|
+
export default class FormulaParser {
|
47
|
+
constructor(config: FormulaParserConfig);
|
48
|
+
parse(
|
49
|
+
inputText: string,
|
50
|
+
position: CellRef,
|
51
|
+
allowReturnArray: boolean = false
|
52
|
+
): Value | FormulaError;
|
53
|
+
}
|
54
|
+
|
55
|
+
export class DepParser {
|
56
|
+
parse(formula: string, position: CellRef): Array<CellRef | RangeRef>;
|
57
|
+
}
|
58
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { useContextSelector } from "use-context-selector";
|
2
|
+
import context from "./context";
|
3
|
+
import * as Types from "./types";
|
4
|
+
|
5
|
+
function useSelector<T>(selector: (state: Types.StoreState) => T): T {
|
6
|
+
return useContextSelector(context, ([state]) => selector(state));
|
7
|
+
}
|
8
|
+
|
9
|
+
export default useSelector;
|