pixel-react 1.1.8 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. package/lib/components/AddButton/AddButton.d.ts +5 -0
  2. package/lib/components/AddButton/AddButton.stories.d.ts +6 -0
  3. package/lib/components/AddButton/index.d.ts +1 -0
  4. package/lib/components/AddButton/types.d.ts +4 -0
  5. package/lib/components/AppHeader/types.d.ts +7 -7
  6. package/lib/components/Drawer/Drawer.stories.d.ts +2 -0
  7. package/lib/components/Drawer/Types.d.ts +11 -0
  8. package/lib/components/ExcelFile/ChangeExcelStyles.d.ts +14 -0
  9. package/lib/components/ExcelFile/ColorBarSelector/ColorBarSelector.d.ts +8 -0
  10. package/lib/components/ExcelFile/ContextMenu/ContextMenu.d.ts +4 -0
  11. package/lib/components/ExcelFile/ExcelFile/Excel/ActiveCell.d.ts +7 -0
  12. package/lib/components/ExcelFile/ExcelFile/Excel/Cell.d.ts +4 -0
  13. package/lib/components/ExcelFile/ExcelFile/Excel/ColumnIndicator.d.ts +5 -0
  14. package/lib/components/ExcelFile/ExcelFile/Excel/Copied.d.ts +3 -0
  15. package/lib/components/ExcelFile/ExcelFile/Excel/CornerIndicator.d.ts +5 -0
  16. package/lib/components/ExcelFile/ExcelFile/Excel/DataEditor.d.ts +5 -0
  17. package/lib/components/ExcelFile/ExcelFile/Excel/DataViewer.d.ts +8 -0
  18. package/lib/components/ExcelFile/ExcelFile/Excel/FloatingRect.d.ts +10 -0
  19. package/lib/components/ExcelFile/ExcelFile/Excel/HeaderRow.d.ts +3 -0
  20. package/lib/components/ExcelFile/ExcelFile/Excel/Row.d.ts +3 -0
  21. package/lib/components/ExcelFile/ExcelFile/Excel/RowIndicator.d.ts +5 -0
  22. package/lib/components/ExcelFile/ExcelFile/Excel/Selected.d.ts +3 -0
  23. package/lib/components/ExcelFile/ExcelFile/Excel/Spreadsheet.d.ts +81 -0
  24. package/lib/components/ExcelFile/ExcelFile/Excel/Table.d.ts +3 -0
  25. package/lib/components/ExcelFile/ExcelFile/Excel/actions.d.ts +130 -0
  26. package/lib/components/ExcelFile/ExcelFile/Excel/areModelsEqual.d.ts +1 -0
  27. package/lib/components/ExcelFile/ExcelFile/Excel/context.d.ts +8 -0
  28. package/lib/components/ExcelFile/ExcelFile/Excel/engine/engine.d.ts +22 -0
  29. package/lib/components/ExcelFile/ExcelFile/Excel/engine/formula.d.ts +17 -0
  30. package/lib/components/ExcelFile/ExcelFile/Excel/engine/index.d.ts +2 -0
  31. package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-graph.d.ts +21 -0
  32. package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-hash.d.ts +3 -0
  33. package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-set.d.ts +24 -0
  34. package/lib/components/ExcelFile/ExcelFile/Excel/index.d.ts +13 -0
  35. package/lib/components/ExcelFile/ExcelFile/Excel/matrix.d.ts +67 -0
  36. package/lib/components/ExcelFile/ExcelFile/Excel/point-range.d.ts +22 -0
  37. package/lib/components/ExcelFile/ExcelFile/Excel/point.d.ts +11 -0
  38. package/lib/components/ExcelFile/ExcelFile/Excel/reducer.d.ts +27 -0
  39. package/lib/components/ExcelFile/ExcelFile/Excel/selection.d.ts +95 -0
  40. package/lib/components/ExcelFile/ExcelFile/Excel/types.d.ts +215 -0
  41. package/lib/components/ExcelFile/ExcelFile/Excel/use-dispatch.d.ts +3 -0
  42. package/lib/components/ExcelFile/ExcelFile/Excel/use-selector.d.ts +3 -0
  43. package/lib/components/ExcelFile/ExcelFile/Excel/util.d.ts +45 -0
  44. package/lib/components/ExcelFile/ExcelFile/ExcelFile.d.ts +3 -0
  45. package/lib/components/ExcelFile/ExcelFile.stories.d.ts +6 -0
  46. package/lib/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.d.ts +15 -0
  47. package/lib/components/ExcelFile/ExcelToolBar/ExcelToolBar.d.ts +3 -0
  48. package/lib/components/ExcelFile/ImportExcelStyles.d.ts +24 -0
  49. package/lib/components/ExcelFile/Types.d.ts +176 -0
  50. package/lib/components/ExcelFile/index.d.ts +1 -0
  51. package/lib/components/Icon/Icon.stories.d.ts +1 -0
  52. package/lib/components/Icon/types.d.ts +1 -0
  53. package/lib/components/IconRadioGroup/IconRadioGroup.d.ts +5 -0
  54. package/lib/components/IconRadioGroup/IconRadioGroup.stories.d.ts +7 -0
  55. package/lib/components/IconRadioGroup/index.d.ts +1 -0
  56. package/lib/components/IconRadioGroup/type.d.ts +41 -0
  57. package/lib/components/Table/Table.d.ts +1 -1
  58. package/lib/components/Table/Table.stories.d.ts +2 -0
  59. package/lib/components/Table/Types.d.ts +16 -0
  60. package/lib/index.d.ts +81 -9
  61. package/lib/index.esm.js +739 -248
  62. package/lib/index.esm.js.map +1 -1
  63. package/lib/index.js +739 -247
  64. package/lib/index.js.map +1 -1
  65. package/lib/tsconfig.tsbuildinfo +1 -1
  66. package/lib/utils/find/findAndInsert.d.ts +7 -0
  67. package/lib/utils/find/findAndInsert.stories.d.ts +7 -0
  68. package/package.json +4 -2
  69. package/src/assets/Themes/BaseTheme.scss +4 -0
  70. package/src/assets/Themes/DarkTheme.scss +4 -0
  71. package/src/assets/icons/all_borders.svg +3 -0
  72. package/src/assets/icons/bold.svg +3 -0
  73. package/src/assets/icons/border_bottom.svg +3 -0
  74. package/src/assets/icons/border_left.svg +3 -0
  75. package/src/assets/icons/border_right.svg +3 -0
  76. package/src/assets/icons/border_top.svg +3 -0
  77. package/src/assets/icons/clone_icon.svg +3 -0
  78. package/src/assets/icons/double_underline.svg +5 -0
  79. package/src/assets/icons/eye_closed.svg +3 -0
  80. package/src/assets/icons/fill_color.svg +7 -0
  81. package/src/assets/icons/formate_painter.svg +5 -0
  82. package/src/assets/icons/full_access_icon.svg +4 -0
  83. package/src/assets/icons/history_icon.svg +19 -0
  84. package/src/assets/icons/italic.svg +3 -0
  85. package/src/assets/icons/jira.svg +3 -0
  86. package/src/assets/icons/linked_defects.svg +11 -0
  87. package/src/assets/icons/move_icon.svg +5 -0
  88. package/src/assets/icons/no_access_icon.svg +4 -0
  89. package/src/assets/icons/no_border.svg +3 -0
  90. package/src/assets/icons/strike_through.svg +3 -0
  91. package/src/assets/icons/text_align_center.svg +3 -0
  92. package/src/assets/icons/text_align_left.svg +3 -0
  93. package/src/assets/icons/text_align_right.svg +3 -0
  94. package/src/assets/icons/text_color.svg +3 -0
  95. package/src/assets/icons/underline.svg +4 -0
  96. package/src/assets/icons/view_access_icon.svg +4 -0
  97. package/src/components/AppHeader/AppHeader.scss +23 -10
  98. package/src/components/AppHeader/AppHeader.stories.tsx +29 -28
  99. package/src/components/AppHeader/AppHeader.tsx +18 -16
  100. package/src/components/AppHeader/types.ts +7 -7
  101. package/src/components/Button/Button.scss +1 -0
  102. package/src/components/Checkbox/Checkbox.tsx +1 -1
  103. package/src/components/Drawer/Drawer.scss +13 -9
  104. package/src/components/Drawer/Drawer.stories.tsx +28 -0
  105. package/src/components/Drawer/Drawer.tsx +29 -6
  106. package/src/components/Drawer/Types.ts +11 -0
  107. package/src/components/ExcelFile/ChangeExcelStyles.tsx +78 -0
  108. package/src/components/ExcelFile/ColorBarselector/ColorBarSelector.scss +13 -0
  109. package/src/components/ExcelFile/ColorBarselector/ColorBarSelector.tsx +43 -0
  110. package/src/components/ExcelFile/ContextMenu/ContextMenu.scss +102 -0
  111. package/src/components/ExcelFile/ContextMenu/ContextMenu.tsx +104 -0
  112. package/src/components/ExcelFile/ExcelFile/Excel/ActiveCell.tsx +131 -0
  113. package/src/components/ExcelFile/ExcelFile/Excel/Cell.tsx +201 -0
  114. package/src/components/ExcelFile/ExcelFile/Excel/ColumnIndicator.tsx +123 -0
  115. package/src/components/ExcelFile/ExcelFile/Excel/Copied.tsx +25 -0
  116. package/src/components/ExcelFile/ExcelFile/Excel/CornerIndicator.tsx +49 -0
  117. package/src/components/ExcelFile/ExcelFile/Excel/DataEditor.tsx +37 -0
  118. package/src/components/ExcelFile/ExcelFile/Excel/DataViewer.tsx +46 -0
  119. package/src/components/ExcelFile/ExcelFile/Excel/FloatingRect.tsx +31 -0
  120. package/src/components/ExcelFile/ExcelFile/Excel/HeaderRow.tsx +5 -0
  121. package/src/components/ExcelFile/ExcelFile/Excel/Row.tsx +5 -0
  122. package/src/components/ExcelFile/ExcelFile/Excel/RowIndicator.tsx +102 -0
  123. package/src/components/ExcelFile/ExcelFile/Excel/Selected.tsx +32 -0
  124. package/src/components/ExcelFile/ExcelFile/Excel/Spreadsheet.css +144 -0
  125. package/src/components/ExcelFile/ExcelFile/Excel/Spreadsheet.tsx +494 -0
  126. package/src/components/ExcelFile/ExcelFile/Excel/Table.tsx +19 -0
  127. package/src/components/ExcelFile/ExcelFile/Excel/actions.ts +302 -0
  128. package/src/components/ExcelFile/ExcelFile/Excel/areModelsEqual.ts +18 -0
  129. package/src/components/ExcelFile/ExcelFile/Excel/context.ts +12 -0
  130. package/src/components/ExcelFile/ExcelFile/Excel/engine/engine.ts +200 -0
  131. package/src/components/ExcelFile/ExcelFile/Excel/engine/formula.ts +137 -0
  132. package/src/components/ExcelFile/ExcelFile/Excel/engine/index.ts +2 -0
  133. package/src/components/ExcelFile/ExcelFile/Excel/engine/point-graph.ts +154 -0
  134. package/src/components/ExcelFile/ExcelFile/Excel/engine/point-hash.ts +10 -0
  135. package/src/components/ExcelFile/ExcelFile/Excel/engine/point-set.ts +69 -0
  136. package/src/components/ExcelFile/ExcelFile/Excel/index.ts +48 -0
  137. package/src/components/ExcelFile/ExcelFile/Excel/matrix.ts +388 -0
  138. package/src/components/ExcelFile/ExcelFile/Excel/point-range.ts +82 -0
  139. package/src/components/ExcelFile/ExcelFile/Excel/point.ts +15 -0
  140. package/src/components/ExcelFile/ExcelFile/Excel/reducer.ts +682 -0
  141. package/src/components/ExcelFile/ExcelFile/Excel/selection.ts +257 -0
  142. package/src/components/ExcelFile/ExcelFile/Excel/types.ts +269 -0
  143. package/src/components/ExcelFile/ExcelFile/Excel/typings/fast-formula-parser.d.ts +58 -0
  144. package/src/components/ExcelFile/ExcelFile/Excel/use-dispatch.ts +8 -0
  145. package/src/components/ExcelFile/ExcelFile/Excel/use-selector.ts +9 -0
  146. package/src/components/ExcelFile/ExcelFile/Excel/util.ts +173 -0
  147. package/src/components/ExcelFile/ExcelFile/ExcelFile.scss +27 -0
  148. package/src/components/ExcelFile/ExcelFile/ExcelFile.tsx +520 -0
  149. package/src/components/ExcelFile/ExcelFile.stories.tsx +132 -0
  150. package/src/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.scss +16 -0
  151. package/src/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.tsx +79 -0
  152. package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.scss +22 -0
  153. package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.tsx +271 -0
  154. package/src/components/ExcelFile/ImportExcelStyles.tsx +86 -0
  155. package/src/components/ExcelFile/Types.ts +241 -0
  156. package/src/components/ExcelFile/index.ts +1 -0
  157. package/src/components/Icon/Icon.stories.tsx +27 -0
  158. package/src/components/Icon/Icon.tsx +5 -1
  159. package/src/components/Icon/Icons.scss +15 -5
  160. package/src/components/Icon/iconList.ts +52 -1
  161. package/src/components/Icon/types.ts +1 -0
  162. package/src/components/IconRadioGroup/IconRadioGroup.scss +60 -0
  163. package/src/components/IconRadioGroup/IconRadioGroup.stories.tsx +108 -0
  164. package/src/components/IconRadioGroup/IconRadioGroup.tsx +72 -0
  165. package/src/components/IconRadioGroup/index.ts +1 -0
  166. package/src/components/IconRadioGroup/type.ts +50 -0
  167. package/src/components/Modal/Modal.tsx +8 -1
  168. package/src/components/Modal/modal.scss +10 -2
  169. package/src/components/Table/Table.scss +16 -4
  170. package/src/components/Table/Table.stories.tsx +36 -12
  171. package/src/components/Table/Table.tsx +33 -16
  172. package/src/components/Table/Types.ts +121 -105
  173. 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,8 @@
1
+ import { useContextSelector } from "use-context-selector";
2
+ import context, { Dispatch } from "./context";
3
+
4
+ function useDispatch(): Dispatch {
5
+ return useContextSelector(context, ([, dispatch]) => dispatch);
6
+ }
7
+
8
+ export default useDispatch;
@@ -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;