pixel-react-excel-sheet 1.0.1 → 1.1.9
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/lib/components/ExcelFile/ExcelFile/Excel/ActiveCell.d.ts +2 -2
- package/lib/components/ExcelFile/ExcelFile/Excel/ColumnIndicator.d.ts +2 -2
- package/lib/components/ExcelFile/ExcelFile/Excel/Copied.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/CornerIndicator.d.ts +2 -2
- package/lib/components/ExcelFile/ExcelFile/Excel/DataEditor.d.ts +2 -2
- package/lib/components/ExcelFile/ExcelFile/Excel/DataViewer.d.ts +2 -2
- package/lib/components/ExcelFile/ExcelFile/Excel/FloatingRect.d.ts +2 -2
- package/lib/components/ExcelFile/ExcelFile/Excel/HeaderRow.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/Row.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/RowIndicator.d.ts +2 -2
- package/lib/components/ExcelFile/ExcelFile/Excel/Selected.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/Spreadsheet.d.ts +6 -6
- package/lib/components/ExcelFile/ExcelFile/Excel/Table.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/actions.d.ts +49 -5
- package/lib/components/ExcelFile/ExcelFile/Excel/context.d.ts +3 -3
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/engine.d.ts +5 -5
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/formula.d.ts +6 -6
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/index.d.ts +2 -2
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-graph.d.ts +2 -2
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-hash.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-set.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/index.d.ts +11 -11
- package/lib/components/ExcelFile/ExcelFile/Excel/matrix.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/point-range.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/reducer.d.ts +5 -5
- package/lib/components/ExcelFile/ExcelFile/Excel/selection.d.ts +3 -3
- package/lib/components/ExcelFile/ExcelFile/Excel/use-dispatch.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/use-selector.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/util.d.ts +11 -12
- package/lib/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.d.ts +0 -3
- package/lib/components/ExcelFile/ExcelToolBar/ExcelToolBar.d.ts +12 -0
- package/lib/components/ExcelFile/Types.d.ts +0 -8
- package/lib/components/Icon/Icon.stories.d.ts +1 -0
- package/lib/components/Icon/types.d.ts +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.esm.js +888 -995
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +888 -995
- package/lib/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/assets/Themes/BaseTheme.scss +1 -0
- package/src/assets/Themes/DarkTheme.scss +1 -0
- package/src/components/ExcelFile/ExcelFile/Excel/ActiveCell.tsx +13 -13
- package/src/components/ExcelFile/ExcelFile/Excel/Cell.tsx +12 -12
- package/src/components/ExcelFile/ExcelFile/Excel/ColumnIndicator.tsx +40 -32
- package/src/components/ExcelFile/ExcelFile/Excel/Copied.tsx +4 -4
- package/src/components/ExcelFile/ExcelFile/Excel/CornerIndicator.tsx +10 -10
- package/src/components/ExcelFile/ExcelFile/Excel/DataEditor.tsx +5 -5
- package/src/components/ExcelFile/ExcelFile/Excel/DataViewer.tsx +10 -10
- package/src/components/ExcelFile/ExcelFile/Excel/FloatingRect.tsx +6 -6
- package/src/components/ExcelFile/ExcelFile/Excel/HeaderRow.tsx +1 -1
- package/src/components/ExcelFile/ExcelFile/Excel/Row.tsx +1 -1
- package/src/components/ExcelFile/ExcelFile/Excel/RowIndicator.tsx +34 -27
- package/src/components/ExcelFile/ExcelFile/Excel/Selected.tsx +5 -5
- package/src/components/ExcelFile/ExcelFile/Excel/Spreadsheet.scss +127 -135
- package/src/components/ExcelFile/ExcelFile/Excel/Spreadsheet.tsx +87 -73
- package/src/components/ExcelFile/ExcelFile/Excel/Table.tsx +2 -2
- package/src/components/ExcelFile/ExcelFile/Excel/actions.ts +121 -31
- package/src/components/ExcelFile/ExcelFile/Excel/areModelsEqual.ts +1 -1
- package/src/components/ExcelFile/ExcelFile/Excel/context.ts +4 -4
- package/src/components/ExcelFile/ExcelFile/Excel/engine/engine.ts +7 -7
- package/src/components/ExcelFile/ExcelFile/Excel/engine/formula.ts +11 -11
- package/src/components/ExcelFile/ExcelFile/Excel/engine/index.ts +2 -2
- package/src/components/ExcelFile/ExcelFile/Excel/engine/point-graph.ts +3 -3
- package/src/components/ExcelFile/ExcelFile/Excel/engine/point-hash.ts +2 -2
- package/src/components/ExcelFile/ExcelFile/Excel/engine/point-set.ts +2 -2
- package/src/components/ExcelFile/ExcelFile/Excel/index.ts +12 -11
- package/src/components/ExcelFile/ExcelFile/Excel/matrix.ts +18 -24
- package/src/components/ExcelFile/ExcelFile/Excel/point-range.ts +1 -1
- package/src/components/ExcelFile/ExcelFile/Excel/reducer.ts +292 -41
- package/src/components/ExcelFile/ExcelFile/Excel/selection.ts +5 -5
- package/src/components/ExcelFile/ExcelFile/Excel/typings/fast-formula-parser.d.ts +8 -8
- package/src/components/ExcelFile/ExcelFile/Excel/use-dispatch.ts +2 -2
- package/src/components/ExcelFile/ExcelFile/Excel/use-selector.ts +3 -3
- package/src/components/ExcelFile/ExcelFile/Excel/util.ts +21 -22
- package/src/components/ExcelFile/ExcelFile/ExcelFile.tsx +27 -335
- package/src/components/ExcelFile/ExcelFile.stories.tsx +10 -9
- package/src/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.tsx +0 -11
- package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.tsx +145 -125
- package/src/components/ExcelFile/Types.ts +0 -11
- package/src/components/ExcelFile/index.ts +1 -1
- package/src/components/Icon/Icon.stories.tsx +27 -0
- package/src/components/Icon/Icon.tsx +5 -1
- package/src/components/Icon/Icons.scss +13 -2
- package/src/components/Icon/types.ts +1 -0
- package/src/components/ExcelFile/ChangeExcelStyles.tsx +0 -66
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PointRange } from
|
|
2
|
-
import * as Matrix from
|
|
3
|
-
import * as Types from
|
|
4
|
-
import * as Point from
|
|
1
|
+
import { PointRange } from './point-range';
|
|
2
|
+
import * as Matrix from './matrix';
|
|
3
|
+
import * as Types from './types';
|
|
4
|
+
import * as Point from './point';
|
|
5
5
|
import {
|
|
6
6
|
Selection,
|
|
7
7
|
EmptySelection,
|
|
@@ -9,14 +9,14 @@ import {
|
|
|
9
9
|
EntireColumnsSelection,
|
|
10
10
|
EntireRowsSelection,
|
|
11
11
|
EntireWorksheetSelection,
|
|
12
|
-
} from
|
|
13
|
-
import { isActive } from
|
|
14
|
-
import * as Actions from
|
|
15
|
-
import { Model, updateCellValue, createFormulaParser } from
|
|
12
|
+
} from './selection';
|
|
13
|
+
import { isActive } from './util';
|
|
14
|
+
import * as Actions from './actions';
|
|
15
|
+
import { Model, updateCellValue, createFormulaParser } from './engine';
|
|
16
16
|
|
|
17
17
|
export const INITIAL_STATE: Types.StoreState = {
|
|
18
18
|
active: null,
|
|
19
|
-
mode:
|
|
19
|
+
mode: 'view',
|
|
20
20
|
rowDimensions: {},
|
|
21
21
|
columnDimensions: {},
|
|
22
22
|
lastChanged: null,
|
|
@@ -34,6 +34,83 @@ export default function reducer(
|
|
|
34
34
|
action: Actions.Action
|
|
35
35
|
): Types.StoreState {
|
|
36
36
|
switch (action.type) {
|
|
37
|
+
case Actions.BOLD: {
|
|
38
|
+
const selectedRange = state.selected.toRange(state.model.data);
|
|
39
|
+
const updatedData = applyBoldToCells(
|
|
40
|
+
state.model.data,
|
|
41
|
+
selectedRange as PointRange
|
|
42
|
+
);
|
|
43
|
+
return {
|
|
44
|
+
...state,
|
|
45
|
+
model: new Model(state.model.createFormulaParser, updatedData),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
case Actions.ITALIC: {
|
|
50
|
+
const selectedRange = state.selected.toRange(state.model.data);
|
|
51
|
+
const updatedData = applyItalicToCells(
|
|
52
|
+
state.model.data,
|
|
53
|
+
selectedRange as PointRange
|
|
54
|
+
);
|
|
55
|
+
return {
|
|
56
|
+
...state,
|
|
57
|
+
model: new Model(state.model.createFormulaParser, updatedData),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
case Actions.UNDERLINE: {
|
|
62
|
+
const selectedRange = state.selected.toRange(state.model.data);
|
|
63
|
+
const updatedData = applyUnderlineToCells(
|
|
64
|
+
state.model.data,
|
|
65
|
+
selectedRange as PointRange
|
|
66
|
+
);
|
|
67
|
+
return {
|
|
68
|
+
...state,
|
|
69
|
+
model: new Model(state.model.createFormulaParser, updatedData),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
case Actions.COLOR: {
|
|
73
|
+
const { value } = action.payload;
|
|
74
|
+
const selectedRange = state.selected.toRange(state.model.data);
|
|
75
|
+
const updatedData = applyColorToCells(
|
|
76
|
+
state.model.data,
|
|
77
|
+
selectedRange as PointRange,
|
|
78
|
+
value
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
...state,
|
|
83
|
+
model: new Model(state.model.createFormulaParser, updatedData),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
case Actions.BACKGROUND_COLOR: {
|
|
88
|
+
const { value } = action.payload;
|
|
89
|
+
const selectedRange = state.selected.toRange(state.model.data);
|
|
90
|
+
const updatedData = applyBackgroundColorToCells(
|
|
91
|
+
state.model.data,
|
|
92
|
+
selectedRange as PointRange,
|
|
93
|
+
value
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
...state,
|
|
98
|
+
model: new Model(state.model.createFormulaParser, updatedData),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
case Actions.FORMATE_PAINTER: {
|
|
103
|
+
const selectedRange = state.selected.toRange(state.model.data);
|
|
104
|
+
const updatedData = applyUnderlineToCells(
|
|
105
|
+
state.model.data,
|
|
106
|
+
selectedRange as PointRange
|
|
107
|
+
);
|
|
108
|
+
return {
|
|
109
|
+
...state,
|
|
110
|
+
model: new Model(state.model.createFormulaParser, updatedData),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
37
114
|
case Actions.SET_DATA: {
|
|
38
115
|
const { data } = action.payload;
|
|
39
116
|
const nextActive =
|
|
@@ -64,7 +141,7 @@ export default function reducer(
|
|
|
64
141
|
? new EntireRowsSelection(active.row, row)
|
|
65
142
|
: new EntireRowsSelection(row, row),
|
|
66
143
|
active: extend && active ? active : { ...Point.ORIGIN, row },
|
|
67
|
-
mode:
|
|
144
|
+
mode: 'view',
|
|
68
145
|
};
|
|
69
146
|
}
|
|
70
147
|
case Actions.SELECT_ENTIRE_COLUMN: {
|
|
@@ -78,7 +155,7 @@ export default function reducer(
|
|
|
78
155
|
? new EntireColumnsSelection(active.column, column)
|
|
79
156
|
: new EntireColumnsSelection(column, column),
|
|
80
157
|
active: extend && active ? active : { ...Point.ORIGIN, column },
|
|
81
|
-
mode:
|
|
158
|
+
mode: 'view',
|
|
82
159
|
};
|
|
83
160
|
}
|
|
84
161
|
case Actions.SELECT_ENTIRE_WORKSHEET: {
|
|
@@ -86,7 +163,7 @@ export default function reducer(
|
|
|
86
163
|
...state,
|
|
87
164
|
selected: new EntireWorksheetSelection(),
|
|
88
165
|
active: Point.ORIGIN,
|
|
89
|
-
mode:
|
|
166
|
+
mode: 'view',
|
|
90
167
|
};
|
|
91
168
|
}
|
|
92
169
|
case Actions.SET_SELECTION: {
|
|
@@ -100,7 +177,7 @@ export default function reducer(
|
|
|
100
177
|
...state,
|
|
101
178
|
selected: selection,
|
|
102
179
|
active: active || null,
|
|
103
|
-
mode:
|
|
180
|
+
mode: 'view',
|
|
104
181
|
};
|
|
105
182
|
}
|
|
106
183
|
case Actions.SELECT: {
|
|
@@ -109,7 +186,7 @@ export default function reducer(
|
|
|
109
186
|
return {
|
|
110
187
|
...state,
|
|
111
188
|
selected: new RangeSelection(new PointRange(point, state.active)),
|
|
112
|
-
mode:
|
|
189
|
+
mode: 'view',
|
|
113
190
|
};
|
|
114
191
|
}
|
|
115
192
|
return state;
|
|
@@ -120,7 +197,7 @@ export default function reducer(
|
|
|
120
197
|
...state,
|
|
121
198
|
selected: new RangeSelection(new PointRange(point, point)),
|
|
122
199
|
active: point,
|
|
123
|
-
mode: isActive(state.active, point) ?
|
|
200
|
+
mode: isActive(state.active, point) ? 'edit' : 'view',
|
|
124
201
|
};
|
|
125
202
|
}
|
|
126
203
|
case Actions.SET_CELL_DATA: {
|
|
@@ -174,7 +251,7 @@ export default function reducer(
|
|
|
174
251
|
case Actions.PASTE: {
|
|
175
252
|
const { data: text } = action.payload;
|
|
176
253
|
const { active } = state;
|
|
177
|
-
|
|
254
|
+
|
|
178
255
|
if (!active) {
|
|
179
256
|
return state;
|
|
180
257
|
}
|
|
@@ -189,7 +266,7 @@ export default function reducer(
|
|
|
189
266
|
state.cut && state.copied
|
|
190
267
|
? Matrix.unset(state.copied.start, state.model.data)
|
|
191
268
|
: state.model.data;
|
|
192
|
-
const commit: Types.StoreState[
|
|
269
|
+
const commit: Types.StoreState['lastCommit'] = [];
|
|
193
270
|
for (const point of selectedRange || []) {
|
|
194
271
|
const currentCell = Matrix.get(point, state.model.data);
|
|
195
272
|
commit.push({
|
|
@@ -205,7 +282,7 @@ export default function reducer(
|
|
|
205
282
|
copied: null,
|
|
206
283
|
cut: false,
|
|
207
284
|
hasPasted: true,
|
|
208
|
-
mode:
|
|
285
|
+
mode: 'view',
|
|
209
286
|
lastCommit: commit,
|
|
210
287
|
};
|
|
211
288
|
}
|
|
@@ -217,8 +294,8 @@ export default function reducer(
|
|
|
217
294
|
const paddedData = Matrix.pad(state.model.data, requiredSize);
|
|
218
295
|
|
|
219
296
|
let acc: {
|
|
220
|
-
data: Types.StoreState[
|
|
221
|
-
commit: Types.StoreState[
|
|
297
|
+
data: Types.StoreState['model']['data'];
|
|
298
|
+
commit: Types.StoreState['lastCommit'];
|
|
222
299
|
} = { data: paddedData, commit: [] };
|
|
223
300
|
for (const [point, cell] of Matrix.entries(copied)) {
|
|
224
301
|
let commit = acc.commit || [];
|
|
@@ -275,7 +352,7 @@ export default function reducer(
|
|
|
275
352
|
copied: null,
|
|
276
353
|
cut: false,
|
|
277
354
|
hasPasted: true,
|
|
278
|
-
mode:
|
|
355
|
+
mode: 'view',
|
|
279
356
|
lastCommit: acc.commit,
|
|
280
357
|
};
|
|
281
358
|
}
|
|
@@ -301,7 +378,7 @@ export default function reducer(
|
|
|
301
378
|
if (isActiveReadOnly(state) || event.metaKey) {
|
|
302
379
|
return state;
|
|
303
380
|
}
|
|
304
|
-
if (state.mode ===
|
|
381
|
+
if (state.mode === 'view' && state.active) {
|
|
305
382
|
const selectedRange = state.selected.toRange(state.model.data);
|
|
306
383
|
if (selectedRange?.size() === 1) {
|
|
307
384
|
return edit(clear(state));
|
|
@@ -334,7 +411,7 @@ export default function reducer(
|
|
|
334
411
|
}
|
|
335
412
|
|
|
336
413
|
default:
|
|
337
|
-
throw new Error(
|
|
414
|
+
throw new Error('Unknown action');
|
|
338
415
|
}
|
|
339
416
|
}
|
|
340
417
|
|
|
@@ -350,11 +427,185 @@ export default function reducer(
|
|
|
350
427
|
|
|
351
428
|
// // Shared reducers
|
|
352
429
|
|
|
430
|
+
function applyBoldToCells(
|
|
431
|
+
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
|
432
|
+
selectedRange: PointRange
|
|
433
|
+
): Matrix.Matrix<Types.CellBase<any>> {
|
|
434
|
+
const { start, end } = selectedRange;
|
|
435
|
+
|
|
436
|
+
let updatedData = currentData;
|
|
437
|
+
|
|
438
|
+
for (let row = start.row; row <= end.row; row++) {
|
|
439
|
+
for (let col = start.column; col <= end.column; col++) {
|
|
440
|
+
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
|
441
|
+
|
|
442
|
+
if (!currentCell) {
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const updatedCell = {
|
|
447
|
+
...currentCell,
|
|
448
|
+
style: {
|
|
449
|
+
...currentCell.style,
|
|
450
|
+
fontWeight: 'bold',
|
|
451
|
+
},
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
return updatedData;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function applyItalicToCells(
|
|
462
|
+
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
|
463
|
+
selectedRange: PointRange
|
|
464
|
+
): Matrix.Matrix<Types.CellBase<any>> {
|
|
465
|
+
const { start, end } = selectedRange;
|
|
466
|
+
|
|
467
|
+
let updatedData = currentData;
|
|
468
|
+
|
|
469
|
+
for (let row = start.row; row <= end.row; row++) {
|
|
470
|
+
for (let col = start.column; col <= end.column; col++) {
|
|
471
|
+
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
|
472
|
+
|
|
473
|
+
if (!currentCell) {
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
const updatedCell = {
|
|
478
|
+
...currentCell,
|
|
479
|
+
style: {
|
|
480
|
+
...currentCell.style,
|
|
481
|
+
fontStyle: 'italic',
|
|
482
|
+
},
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
return updatedData;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
function applyUnderlineToCells(
|
|
493
|
+
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
|
494
|
+
selectedRange: PointRange
|
|
495
|
+
): Matrix.Matrix<Types.CellBase<any>> {
|
|
496
|
+
const { start, end } = selectedRange;
|
|
497
|
+
|
|
498
|
+
let updatedData = currentData;
|
|
499
|
+
|
|
500
|
+
for (let row = start.row; row <= end.row; row++) {
|
|
501
|
+
for (let col = start.column; col <= end.column; col++) {
|
|
502
|
+
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
|
503
|
+
|
|
504
|
+
if (!currentCell) {
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
const updatedCell = {
|
|
509
|
+
...currentCell,
|
|
510
|
+
style: {
|
|
511
|
+
...currentCell.style,
|
|
512
|
+
textDecoration: 'underline',
|
|
513
|
+
},
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
return updatedData;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function applyColorToCells(
|
|
524
|
+
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
|
525
|
+
selectedRange: PointRange | null,
|
|
526
|
+
color: string
|
|
527
|
+
): Matrix.Matrix<Types.CellBase<any>> {
|
|
528
|
+
if (!selectedRange) {
|
|
529
|
+
return currentData;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
const { start, end } = selectedRange;
|
|
533
|
+
|
|
534
|
+
let updatedData = currentData;
|
|
535
|
+
|
|
536
|
+
const isHexColor = (color: string) => /^#[0-9A-Fa-f]{6}$/i.test(color);
|
|
537
|
+
|
|
538
|
+
const applyColor = isHexColor(color) ? `#${color}` : color;
|
|
539
|
+
|
|
540
|
+
for (let row = start.row; row <= end.row; row++) {
|
|
541
|
+
for (let col = start.column; col <= end.column; col++) {
|
|
542
|
+
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
|
543
|
+
|
|
544
|
+
if (!currentCell) {
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
const updatedCell = {
|
|
549
|
+
...currentCell,
|
|
550
|
+
style: {
|
|
551
|
+
...currentCell.style,
|
|
552
|
+
color: applyColor,
|
|
553
|
+
},
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
return updatedData;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function applyBackgroundColorToCells(
|
|
564
|
+
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
|
565
|
+
selectedRange: PointRange | null,
|
|
566
|
+
backgroundColor: string
|
|
567
|
+
): Matrix.Matrix<Types.CellBase<any>> {
|
|
568
|
+
if (selectedRange) {
|
|
569
|
+
const { start, end } = selectedRange;
|
|
570
|
+
|
|
571
|
+
let updatedData = currentData;
|
|
572
|
+
|
|
573
|
+
for (let row = start.row; row <= end.row; row++) {
|
|
574
|
+
for (let col = start.column; col <= end.column; col++) {
|
|
575
|
+
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
|
576
|
+
|
|
577
|
+
if (!currentCell) {
|
|
578
|
+
continue;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
let HexCode = backgroundColor.length === 6;
|
|
582
|
+
|
|
583
|
+
const updatedCell = {
|
|
584
|
+
...currentCell,
|
|
585
|
+
style: {
|
|
586
|
+
...currentCell.style,
|
|
587
|
+
backgroundColor: HexCode ? `#${backgroundColor}` : backgroundColor,
|
|
588
|
+
},
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
updatedData = Matrix.set(
|
|
592
|
+
{ row, column: col },
|
|
593
|
+
updatedCell,
|
|
594
|
+
updatedData
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
return updatedData;
|
|
600
|
+
}
|
|
601
|
+
return currentData;
|
|
602
|
+
}
|
|
603
|
+
|
|
353
604
|
function edit(state: Types.StoreState): Types.StoreState {
|
|
354
605
|
if (isActiveReadOnly(state)) {
|
|
355
606
|
return state;
|
|
356
607
|
}
|
|
357
|
-
return { ...state, mode:
|
|
608
|
+
return { ...state, mode: 'edit' };
|
|
358
609
|
}
|
|
359
610
|
|
|
360
611
|
function clear(state: Types.StoreState): Types.StoreState {
|
|
@@ -398,7 +649,7 @@ function blur(state: Types.StoreState): Types.StoreState {
|
|
|
398
649
|
}
|
|
399
650
|
|
|
400
651
|
function view(state: Types.StoreState): Types.StoreState {
|
|
401
|
-
return { ...state, mode:
|
|
652
|
+
return { ...state, mode: 'view' };
|
|
402
653
|
}
|
|
403
654
|
|
|
404
655
|
function commit(changes: Types.CommitChanges): Partial<Types.StoreState> {
|
|
@@ -421,13 +672,13 @@ export const go =
|
|
|
421
672
|
column: (state.active.column + columnDelta) % size.columns,
|
|
422
673
|
};
|
|
423
674
|
if (!Matrix.has(nextActive, state.model.data)) {
|
|
424
|
-
return { ...state, mode:
|
|
675
|
+
return { ...state, mode: 'view' };
|
|
425
676
|
}
|
|
426
677
|
return {
|
|
427
678
|
...state,
|
|
428
679
|
active: nextActive,
|
|
429
680
|
selected: new RangeSelection(new PointRange(nextActive, nextActive)),
|
|
430
|
-
mode:
|
|
681
|
+
mode: 'view',
|
|
431
682
|
};
|
|
432
683
|
};
|
|
433
684
|
|
|
@@ -439,7 +690,7 @@ export type KeyDownHandler = (
|
|
|
439
690
|
) => Types.StoreState | void;
|
|
440
691
|
|
|
441
692
|
type KeyDownHandlers = {
|
|
442
|
-
[K in string]: KeyDownHandler|undefined;
|
|
693
|
+
[K in string]: KeyDownHandler | undefined;
|
|
443
694
|
};
|
|
444
695
|
|
|
445
696
|
const keyDownHandlers: KeyDownHandlers = {
|
|
@@ -465,10 +716,10 @@ const editShiftKeyDownHandlers: KeyDownHandlers = {
|
|
|
465
716
|
};
|
|
466
717
|
|
|
467
718
|
export enum Direction {
|
|
468
|
-
Left =
|
|
469
|
-
Right =
|
|
470
|
-
Top =
|
|
471
|
-
Bottom =
|
|
719
|
+
Left = 'Left',
|
|
720
|
+
Right = 'Right',
|
|
721
|
+
Top = 'Top',
|
|
722
|
+
Bottom = 'Bottom',
|
|
472
723
|
}
|
|
473
724
|
|
|
474
725
|
const shiftKeyDownHandlers: KeyDownHandlers = {
|
|
@@ -521,7 +772,7 @@ export function getKeyDownHandler(
|
|
|
521
772
|
const { key } = event;
|
|
522
773
|
let handlers;
|
|
523
774
|
// Order matters
|
|
524
|
-
if (state.mode ===
|
|
775
|
+
if (state.mode === 'edit') {
|
|
525
776
|
if (event.shiftKey) {
|
|
526
777
|
handlers = editShiftKeyDownHandlers;
|
|
527
778
|
} else {
|
|
@@ -598,18 +849,18 @@ export function modifyRangeSelectionEdge(
|
|
|
598
849
|
edge: Direction
|
|
599
850
|
): RangeSelection {
|
|
600
851
|
const field =
|
|
601
|
-
edge === Direction.Left || edge === Direction.Right ?
|
|
852
|
+
edge === Direction.Left || edge === Direction.Right ? 'column' : 'row';
|
|
602
853
|
|
|
603
854
|
const key =
|
|
604
|
-
edge === Direction.Left || edge === Direction.Top ?
|
|
605
|
-
const delta = key ===
|
|
855
|
+
edge === Direction.Left || edge === Direction.Top ? 'start' : 'end';
|
|
856
|
+
const delta = key === 'start' ? -1 : 1;
|
|
606
857
|
|
|
607
858
|
const edgeOffsets = rangeSelection.range.has({
|
|
608
859
|
...active,
|
|
609
860
|
[field]: active[field] + delta * -1,
|
|
610
861
|
});
|
|
611
862
|
|
|
612
|
-
const keyToModify = edgeOffsets ? (key ===
|
|
863
|
+
const keyToModify = edgeOffsets ? (key === 'start' ? 'end' : 'start') : key;
|
|
613
864
|
|
|
614
865
|
const nextRange = new PointRange(
|
|
615
866
|
rangeSelection.range.start,
|
|
@@ -633,8 +884,8 @@ export function modifyEntireRowsSelection(
|
|
|
633
884
|
return selection;
|
|
634
885
|
}
|
|
635
886
|
const delta = edge === Direction.Top ? -1 : 1;
|
|
636
|
-
const property = edge === Direction.Top ?
|
|
637
|
-
const oppositeProperty = property ===
|
|
887
|
+
const property = edge === Direction.Top ? 'start' : 'end';
|
|
888
|
+
const oppositeProperty = property === 'start' ? 'end' : 'start';
|
|
638
889
|
const newSelectionData = { ...selection };
|
|
639
890
|
if (
|
|
640
891
|
edge === Direction.Top
|
|
@@ -662,8 +913,8 @@ export function modifyEntireColumnsSelection(
|
|
|
662
913
|
return selection;
|
|
663
914
|
}
|
|
664
915
|
const delta = edge === Direction.Left ? -1 : 1;
|
|
665
|
-
const property = edge === Direction.Left ?
|
|
666
|
-
const oppositeProperty = property ===
|
|
916
|
+
const property = edge === Direction.Left ? 'start' : 'end';
|
|
917
|
+
const oppositeProperty = property === 'start' ? 'end' : 'start';
|
|
667
918
|
const newSelectionData = { ...selection };
|
|
668
919
|
if (
|
|
669
920
|
edge === Direction.Left
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { PointRange } from
|
|
2
|
-
import * as Point from
|
|
3
|
-
import * as Matrix from
|
|
1
|
+
import { PointRange } from './point-range';
|
|
2
|
+
import * as Point from './point';
|
|
3
|
+
import * as Matrix from './matrix';
|
|
4
4
|
|
|
5
5
|
/** Selection from a spreadsheet */
|
|
6
6
|
export abstract class Selection {
|
|
@@ -142,10 +142,10 @@ export abstract class EntireAxisSelection extends EntireSelection {
|
|
|
142
142
|
*/
|
|
143
143
|
constructor(start: number, end: number) {
|
|
144
144
|
if (!isIndex(start)) {
|
|
145
|
-
throw new InvalidIndexError(
|
|
145
|
+
throw new InvalidIndexError('start');
|
|
146
146
|
}
|
|
147
147
|
if (!isIndex(end)) {
|
|
148
|
-
throw new InvalidIndexError(
|
|
148
|
+
throw new InvalidIndexError('end');
|
|
149
149
|
}
|
|
150
150
|
super();
|
|
151
151
|
this.start = Math.min(start, end);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare module
|
|
1
|
+
declare module 'fast-formula-parser' {
|
|
2
2
|
export type CellCoord = {
|
|
3
3
|
row: number;
|
|
4
4
|
col: number;
|
|
@@ -34,13 +34,13 @@ declare module "fast-formula-parser" {
|
|
|
34
34
|
/** Return the formula error in string representation. */
|
|
35
35
|
toString(): string;
|
|
36
36
|
|
|
37
|
-
static DIV0 =
|
|
38
|
-
static NA =
|
|
39
|
-
static NAME =
|
|
40
|
-
static NULL =
|
|
41
|
-
static NUM =
|
|
42
|
-
static REF =
|
|
43
|
-
static VALUE =
|
|
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
44
|
}
|
|
45
45
|
|
|
46
46
|
export default class FormulaParser {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useContextSelector } from
|
|
2
|
-
import context, { Dispatch } from
|
|
1
|
+
import { useContextSelector } from 'use-context-selector';
|
|
2
|
+
import context, { Dispatch } from './context';
|
|
3
3
|
|
|
4
4
|
function useDispatch(): Dispatch {
|
|
5
5
|
return useContextSelector(context, ([, dispatch]) => dispatch);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useContextSelector } from
|
|
2
|
-
import context from
|
|
3
|
-
import * as Types from
|
|
1
|
+
import { useContextSelector } from 'use-context-selector';
|
|
2
|
+
import context from './context';
|
|
3
|
+
import * as Types from './types';
|
|
4
4
|
|
|
5
5
|
function useSelector<T>(selector: (state: Types.StoreState) => T): T {
|
|
6
6
|
return useContextSelector(context, ([state]) => selector(state));
|