pixel-react 1.4.2 → 1.4.4
Sign up to get free protection for your applications and to get access to all the features.
- package/.yarn/install-state.gz +0 -0
- package/lib/components/AddResourceButton/type.d.ts +1 -1
- package/lib/components/Drawer/Types.d.ts +4 -0
- package/lib/components/Excel/ExcelContextMenu/ExcelContextMenu.d.ts +13 -0
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/Spreadsheet.d.ts +0 -13
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/actions.d.ts +29 -1
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/engine/engine.d.ts +3 -9
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/engine/formula.d.ts +2 -10
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/engine/point-graph.d.ts +0 -1
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/types.d.ts +27 -2
- package/lib/components/Form/Forms.d.ts +4 -2
- package/lib/components/InputWithDropdown/InputWithDropdown.d.ts +1 -1
- package/lib/components/MenuOption/MenuOption.d.ts +1 -1
- package/lib/components/MenuOption/types.d.ts +49 -15
- package/lib/components/MiniModal/types.d.ts +1 -1
- package/lib/components/MultiSelect/MultiSelect.d.ts +1 -1
- package/lib/components/MultiSelect/MultiSelectTypes.d.ts +4 -5
- package/lib/components/MultiSelect/dropdownTypes.d.ts +2 -0
- package/lib/components/RadioButton/RadioButton.d.ts +1 -0
- package/lib/components/RadioButton/radioButtonTypes.d.ts +3 -1
- package/lib/components/Select/components/types.d.ts +4 -2
- package/lib/components/Table/Table.d.ts +1 -1
- package/lib/components/ToggleSwitch/ToggleSwitch.d.ts +10 -0
- package/lib/components/ToggleSwitch/index.d.ts +1 -0
- package/lib/index.d.ts +110 -24
- package/lib/index.esm.js +5732 -648
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +5728 -642
- package/lib/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -11
- package/src/StyleGuide/ColorPalette/colorPaletteList.ts +10 -0
- package/src/assets/Themes/BaseTheme.scss +17 -23
- package/src/assets/Themes/DarkTheme.scss +25 -38
- package/src/assets/icons/apk_file_type.svg +4 -0
- package/src/assets/icons/compressed_file_type.svg +4 -0
- package/src/assets/icons/csv_file_type.svg +4 -0
- package/src/assets/icons/excel_corner_menu.svg +3 -0
- package/src/assets/icons/formula_icon.svg +3 -0
- package/src/assets/icons/gif_file_type.svg +4 -0
- package/src/assets/icons/html_file_type.svg +4 -0
- package/src/assets/icons/ipk_file_type.svg +4 -0
- package/src/assets/icons/jpg_file_type.svg +4 -0
- package/src/assets/icons/json_file_type.svg +4 -0
- package/src/assets/icons/pdf_file_type.svg +4 -0
- package/src/assets/icons/png_file_type.svg +4 -0
- package/src/assets/icons/quick_run_setting_icon.svg +5 -0
- package/src/assets/icons/run_automation_scripts_icon.svg +33 -0
- package/src/assets/icons/run_manual_testcase_icon.svg +4 -0
- package/src/assets/icons/search.svg +2 -2
- package/src/assets/icons/txt_file_type.svg +4 -0
- package/src/assets/icons/xls_file_type.svg +4 -0
- package/src/assets/icons/xlsx_file_type.svg +4 -0
- package/src/assets/icons/xml_file_type.svg +4 -0
- package/src/assets/styles/_fonts.scss +32 -2
- package/src/components/AddResourceButton/AddButton.tsx +7 -7
- package/src/components/AddResourceButton/type.ts +1 -1
- package/src/components/AttachmentButton/AttachmentButton.scss +1 -1
- package/src/components/AttachmentButton/AttachmentButton.stories.tsx +1 -0
- package/src/components/Button/Button.scss +22 -20
- package/src/components/Button/Button.tsx +8 -1
- package/src/components/Charts/DashboardDonutChart/DashboardDonutChart.tsx +2 -2
- package/src/components/Drawer/Drawer.scss +4 -3
- package/src/components/Drawer/Drawer.tsx +14 -18
- package/src/components/Drawer/Types.ts +4 -0
- package/src/components/Editor/Editor.tsx +9 -11
- package/src/components/Excel/ExcelContextMenu/ExcelContextMenu.scss +39 -0
- package/src/components/Excel/ExcelContextMenu/ExcelContextMenu.tsx +51 -0
- package/src/components/Excel/ExcelFile/ExcelFile.tsx +7 -8
- package/src/components/Excel/ExcelFile/ExcelFileComponents/Cell.tsx +35 -0
- package/src/components/Excel/ExcelFile/ExcelFileComponents/ColumnIndicator.tsx +44 -7
- package/src/components/Excel/ExcelFile/ExcelFileComponents/CornerIndicator.tsx +8 -1
- package/src/components/Excel/ExcelFile/ExcelFileComponents/RowIndicator.tsx +45 -6
- package/src/components/Excel/ExcelFile/ExcelFileComponents/Spreadsheet.scss +37 -2
- package/src/components/Excel/ExcelFile/ExcelFileComponents/Spreadsheet.tsx +69 -24
- package/src/components/Excel/ExcelFile/ExcelFileComponents/actions.ts +59 -0
- package/src/components/Excel/ExcelFile/ExcelFileComponents/engine/engine.ts +18 -65
- package/src/components/Excel/ExcelFile/ExcelFileComponents/engine/formula.ts +5 -110
- package/src/components/Excel/ExcelFile/ExcelFileComponents/engine/point-graph.ts +0 -2
- package/src/components/Excel/ExcelFile/ExcelFileComponents/reducer.ts +105 -1
- package/src/components/Excel/ExcelFile/ExcelFileComponents/reducerFunctions.ts +670 -673
- package/src/components/Excel/ExcelFile/ExcelFileComponents/types.ts +38 -2
- package/src/components/Excel/ExcelToolBar/ExcelToolBar.tsx +0 -4
- package/src/components/FileDropzone/FileDropzone.scss +4 -2
- package/src/components/FileDropzone/FileDropzone.tsx +1 -1
- package/src/components/FileDropzone/FilePreview.tsx +3 -1
- package/src/components/Form/Form.scss +2 -0
- package/src/components/Form/Form.stories.tsx +195 -6
- package/src/components/Form/Forms.tsx +15 -8
- package/src/components/Icon/iconList.ts +46 -0
- package/src/components/IconRadioGroup/IconRadioGroup.scss +3 -0
- package/src/components/IconRadioGroup/IconRadioGroup.tsx +20 -17
- package/src/components/Input/Input.scss +14 -15
- package/src/components/Input/Input.stories.tsx +2 -1
- package/src/components/InputWithDropdown/InputWithDropdown.scss +12 -13
- package/src/components/InputWithDropdown/InputWithDropdown.stories.tsx +3 -2
- package/src/components/InputWithDropdown/InputWithDropdown.tsx +22 -19
- package/src/components/MenuOption/MenuOption.scss +11 -10
- package/src/components/MenuOption/MenuOption.stories.tsx +51 -232
- package/src/components/MenuOption/MenuOption.tsx +131 -52
- package/src/components/MenuOption/types.ts +55 -14
- package/src/components/MiniModal/MiniModal.stories.tsx +7 -6
- package/src/components/MiniModal/MiniModal.tsx +29 -23
- package/src/components/MiniModal/types.ts +1 -1
- package/src/components/MultiSelect/Dropdown.tsx +11 -12
- package/src/components/MultiSelect/MultiSelect.scss +1 -0
- package/src/components/MultiSelect/MultiSelect.stories.tsx +45 -10
- package/src/components/MultiSelect/MultiSelect.tsx +29 -13
- package/src/components/MultiSelect/MultiSelectTypes.ts +7 -5
- package/src/components/MultiSelect/dropdownTypes.ts +2 -0
- package/src/components/RadioButton/RadioButton.scss +3 -1
- package/src/components/RadioButton/RadioButton.tsx +3 -1
- package/src/components/RadioButton/radioButtonTypes.tsx +5 -1
- package/src/components/Search/Search.scss +25 -6
- package/src/components/Search/Search.tsx +45 -24
- package/src/components/Select/Select.scss +12 -12
- package/src/components/Select/Select.stories.tsx +2 -0
- package/src/components/Select/Select.tsx +11 -5
- package/src/components/Select/components/Dropdown.scss +2 -0
- package/src/components/Select/components/Dropdown.tsx +19 -4
- package/src/components/Select/components/types.ts +4 -2
- package/src/components/StatusButton/StatusButton.tsx +26 -20
- package/src/components/Table/Table.scss +1 -3
- package/src/components/Table/Table.stories.tsx +1 -0
- package/src/components/Table/Table.tsx +7 -3
- package/src/components/ToggleSwitch/ToggleSwitch.scss +59 -0
- package/src/components/ToggleSwitch/ToggleSwitch.stories.tsx +52 -0
- package/src/components/ToggleSwitch/ToggleSwitch.tsx +30 -0
- package/src/components/ToggleSwitch/index.ts +1 -0
- package/src/components/Typography/Typography.scss +32 -2
- package/src/hooks/useFileDropzone.tsx +1 -0
- package/src/index.ts +4 -2
- package/src/components/Excel/ContextMenu/ContextMenu.scss +0 -99
- package/src/components/Excel/ContextMenu/ContextMenu.tsx +0 -103
@@ -9,750 +9,747 @@ import {
|
|
9
9
|
EntireColumnsSelection,
|
10
10
|
EntireRowsSelection,
|
11
11
|
} from './selection';
|
12
|
-
import { Model, createFormulaParser } from './engine';
|
13
12
|
|
14
13
|
export function applyBoldToCells(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
}
|
33
|
-
|
34
|
-
const updatedCell = {
|
35
|
-
...currentCell,
|
36
|
-
style: {
|
37
|
-
...currentCell.style,
|
38
|
-
fontWeight: 'bold',
|
39
|
-
},
|
40
|
-
};
|
41
|
-
|
42
|
-
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
14
|
+
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
15
|
+
selectedRange: PointRange
|
16
|
+
): Matrix.Matrix<Types.CellBase<any>> {
|
17
|
+
if (!selectedRange) {
|
18
|
+
return currentData;
|
19
|
+
}
|
20
|
+
|
21
|
+
const { start, end } = selectedRange;
|
22
|
+
|
23
|
+
let updatedData = currentData;
|
24
|
+
|
25
|
+
for (let row = start.row; row <= end.row; row++) {
|
26
|
+
for (let col = start.column; col <= end.column; col++) {
|
27
|
+
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
28
|
+
|
29
|
+
if (!currentCell) {
|
30
|
+
continue;
|
43
31
|
}
|
32
|
+
|
33
|
+
const updatedCell = {
|
34
|
+
...currentCell,
|
35
|
+
style: {
|
36
|
+
...currentCell.style,
|
37
|
+
fontWeight: 'bold',
|
38
|
+
},
|
39
|
+
};
|
40
|
+
|
41
|
+
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
44
42
|
}
|
45
|
-
|
46
|
-
return updatedData;
|
47
43
|
}
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
44
|
+
|
45
|
+
return updatedData;
|
46
|
+
}
|
47
|
+
|
48
|
+
export function applyItalicToCells(
|
49
|
+
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
50
|
+
selectedRange: PointRange
|
51
|
+
): Matrix.Matrix<Types.CellBase<any>> {
|
52
|
+
if (!selectedRange) {
|
53
|
+
return currentData;
|
54
|
+
}
|
55
|
+
|
56
|
+
const { start, end } = selectedRange;
|
57
|
+
|
58
|
+
let updatedData = currentData;
|
59
|
+
|
60
|
+
for (let row = start.row; row <= end.row; row++) {
|
61
|
+
for (let col = start.column; col <= end.column; col++) {
|
62
|
+
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
63
|
+
|
64
|
+
if (!currentCell) {
|
65
|
+
continue;
|
66
|
+
}
|
67
|
+
|
68
|
+
const updatedCell = {
|
69
|
+
...currentCell,
|
70
|
+
style: {
|
71
|
+
...currentCell.style,
|
72
|
+
fontStyle: 'italic',
|
73
|
+
},
|
74
|
+
};
|
75
|
+
|
76
|
+
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
55
77
|
}
|
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
|
+
return updatedData;
|
81
|
+
}
|
82
|
+
|
83
|
+
export function applyFontFamily(
|
84
|
+
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
85
|
+
selectedRange: PointRange,
|
86
|
+
value: string
|
87
|
+
): Matrix.Matrix<Types.CellBase<any>> {
|
88
|
+
if (!selectedRange) {
|
89
|
+
return currentData;
|
90
|
+
}
|
91
|
+
|
92
|
+
const { start, end } = selectedRange;
|
93
|
+
|
94
|
+
let updatedData = currentData;
|
95
|
+
|
96
|
+
for (let row = start.row; row <= end.row; row++) {
|
97
|
+
for (let col = start.column; col <= end.column; col++) {
|
98
|
+
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
99
|
+
|
100
|
+
if (!currentCell) {
|
101
|
+
continue;
|
78
102
|
}
|
103
|
+
|
104
|
+
let updatedCell = {
|
105
|
+
...currentCell,
|
106
|
+
style: {
|
107
|
+
...currentCell.style,
|
108
|
+
fontFamily: value,
|
109
|
+
},
|
110
|
+
};
|
111
|
+
|
112
|
+
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
79
113
|
}
|
80
|
-
|
81
|
-
return updatedData;
|
82
114
|
}
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
115
|
+
|
116
|
+
return updatedData;
|
117
|
+
}
|
118
|
+
|
119
|
+
export function applyFontSize(
|
120
|
+
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
121
|
+
selectedRange: PointRange,
|
122
|
+
value: string
|
123
|
+
): Matrix.Matrix<Types.CellBase<any>> {
|
124
|
+
if (!selectedRange) {
|
125
|
+
return currentData;
|
126
|
+
}
|
127
|
+
|
128
|
+
const conversion = Number(value);
|
129
|
+
|
130
|
+
if (isNaN(conversion)) {
|
131
|
+
return currentData;
|
132
|
+
}
|
133
|
+
|
134
|
+
const fontSizeInPx = convertPtToPx(conversion);
|
135
|
+
|
136
|
+
const { start, end } = selectedRange;
|
137
|
+
|
138
|
+
let updatedData = currentData;
|
139
|
+
|
140
|
+
for (let row = start.row; row <= end.row; row++) {
|
141
|
+
for (let col = start.column; col <= end.column; col++) {
|
142
|
+
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
143
|
+
|
144
|
+
if (!currentCell) {
|
145
|
+
continue;
|
146
|
+
}
|
147
|
+
|
148
|
+
let updatedCell = {
|
149
|
+
...currentCell,
|
150
|
+
style: {
|
151
|
+
...currentCell.style,
|
152
|
+
fontSize: fontSizeInPx,
|
153
|
+
},
|
154
|
+
};
|
155
|
+
|
156
|
+
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
91
157
|
}
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
158
|
+
}
|
159
|
+
|
160
|
+
return updatedData;
|
161
|
+
}
|
162
|
+
|
163
|
+
export function applyBorderToCells(
|
164
|
+
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
165
|
+
selectedRange: PointRange,
|
166
|
+
value: string,
|
167
|
+
color: string
|
168
|
+
): Matrix.Matrix<Types.CellBase<any>> {
|
169
|
+
if (!selectedRange) {
|
170
|
+
return currentData;
|
171
|
+
}
|
172
|
+
|
173
|
+
const { start, end } = selectedRange;
|
174
|
+
|
175
|
+
let updatedData = currentData;
|
176
|
+
|
177
|
+
for (let row = start.row; row <= end.row; row++) {
|
178
|
+
for (let col = start.column; col <= end.column; col++) {
|
179
|
+
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
180
|
+
|
181
|
+
if (!currentCell) {
|
182
|
+
continue;
|
183
|
+
}
|
184
|
+
|
185
|
+
let updatedCell = { ...currentCell };
|
186
|
+
|
187
|
+
switch (value) {
|
188
|
+
case 'border-all-sides':
|
189
|
+
updatedCell.style = {
|
108
190
|
...currentCell.style,
|
109
|
-
|
110
|
-
}
|
111
|
-
|
112
|
-
|
113
|
-
|
191
|
+
border: `2px solid ${color}`,
|
192
|
+
};
|
193
|
+
break;
|
194
|
+
case 'border-none':
|
195
|
+
updatedCell.style = {
|
196
|
+
...currentCell.style,
|
197
|
+
border: `1px solid var(--toggle-strip-color)`,
|
198
|
+
};
|
199
|
+
break;
|
200
|
+
case 'border-right':
|
201
|
+
updatedCell.style = {
|
202
|
+
...currentCell.style,
|
203
|
+
borderRight: `2px solid ${color}`,
|
204
|
+
};
|
205
|
+
break;
|
206
|
+
case 'border-left':
|
207
|
+
updatedCell.style = {
|
208
|
+
...currentCell.style,
|
209
|
+
borderLeft: `2px solid ${color}`,
|
210
|
+
};
|
211
|
+
break;
|
212
|
+
case 'border-top':
|
213
|
+
updatedCell.style = {
|
214
|
+
...currentCell.style,
|
215
|
+
borderTop: `2px solid ${color}`,
|
216
|
+
};
|
217
|
+
break;
|
218
|
+
case 'border-bottom':
|
219
|
+
updatedCell.style = {
|
220
|
+
...currentCell.style,
|
221
|
+
borderBottom: `2px solid ${color}`,
|
222
|
+
};
|
223
|
+
break;
|
224
|
+
default:
|
225
|
+
break;
|
114
226
|
}
|
227
|
+
|
228
|
+
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
115
229
|
}
|
116
|
-
|
117
|
-
return updatedData;
|
118
230
|
}
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
231
|
+
|
232
|
+
return updatedData;
|
233
|
+
}
|
234
|
+
|
235
|
+
export function applyTextAlign(
|
236
|
+
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
237
|
+
selectedRange: PointRange,
|
238
|
+
value: string
|
239
|
+
): Matrix.Matrix<Types.CellBase<any>> {
|
240
|
+
if (!selectedRange) {
|
241
|
+
return currentData;
|
242
|
+
}
|
243
|
+
|
244
|
+
const { start, end } = selectedRange;
|
245
|
+
|
246
|
+
let updatedData = currentData;
|
247
|
+
|
248
|
+
for (let row = start.row; row <= end.row; row++) {
|
249
|
+
for (let col = start.column; col <= end.column; col++) {
|
250
|
+
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
251
|
+
|
252
|
+
if (!currentCell) {
|
253
|
+
continue;
|
254
|
+
}
|
255
|
+
|
256
|
+
let updatedCell = {
|
257
|
+
...currentCell,
|
258
|
+
style: {
|
259
|
+
...currentCell.style,
|
260
|
+
textAlign: value as TextAlign,
|
261
|
+
},
|
262
|
+
};
|
263
|
+
|
264
|
+
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
135
265
|
}
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
266
|
+
}
|
267
|
+
|
268
|
+
return updatedData;
|
269
|
+
}
|
270
|
+
|
271
|
+
export function applyUnderlineToCells(
|
272
|
+
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
273
|
+
selectedRange: PointRange,
|
274
|
+
value: string,
|
275
|
+
active: boolean
|
276
|
+
): Matrix.Matrix<Types.CellBase<any>> {
|
277
|
+
const { start, end } = selectedRange;
|
278
|
+
|
279
|
+
let updatedData = currentData;
|
280
|
+
|
281
|
+
for (let row = start.row; row <= end.row; row++) {
|
282
|
+
for (let col = start.column; col <= end.column; col++) {
|
283
|
+
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
284
|
+
|
285
|
+
if (!currentCell) {
|
286
|
+
continue;
|
287
|
+
}
|
288
|
+
|
289
|
+
let updatedCell;
|
290
|
+
if (!active) {
|
291
|
+
updatedCell = {
|
150
292
|
...currentCell,
|
151
293
|
style: {
|
152
294
|
...currentCell.style,
|
153
|
-
|
295
|
+
textDecoration: 'none',
|
296
|
+
textDecorationStyle: 'none' as TextDecorationStyle,
|
154
297
|
},
|
155
298
|
};
|
156
|
-
|
157
|
-
|
158
|
-
}
|
159
|
-
}
|
160
|
-
|
161
|
-
return updatedData;
|
162
|
-
}
|
163
|
-
|
164
|
-
export function applyBorderToCells(
|
165
|
-
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
166
|
-
selectedRange: PointRange,
|
167
|
-
value: string,
|
168
|
-
color: string
|
169
|
-
): Matrix.Matrix<Types.CellBase<any>> {
|
170
|
-
if (!selectedRange) {
|
171
|
-
return currentData;
|
172
|
-
}
|
173
|
-
|
174
|
-
const { start, end } = selectedRange;
|
175
|
-
|
176
|
-
let updatedData = currentData;
|
177
|
-
|
178
|
-
for (let row = start.row; row <= end.row; row++) {
|
179
|
-
for (let col = start.column; col <= end.column; col++) {
|
180
|
-
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
181
|
-
|
182
|
-
if (!currentCell) {
|
183
|
-
continue;
|
184
|
-
}
|
185
|
-
|
186
|
-
let updatedCell = { ...currentCell };
|
187
|
-
|
188
|
-
switch (value) {
|
189
|
-
case 'border-all-sides':
|
190
|
-
updatedCell.style = {
|
191
|
-
...currentCell.style,
|
192
|
-
border: `2px solid ${color}`,
|
193
|
-
};
|
194
|
-
break;
|
195
|
-
case 'border-none':
|
196
|
-
updatedCell.style = {
|
197
|
-
...currentCell.style,
|
198
|
-
border: `1px solid var(--toggle-strip-color)`,
|
199
|
-
};
|
200
|
-
break;
|
201
|
-
case 'border-right':
|
202
|
-
updatedCell.style = {
|
203
|
-
...currentCell.style,
|
204
|
-
borderRight: `2px solid ${color}`,
|
205
|
-
};
|
206
|
-
break;
|
207
|
-
case 'border-left':
|
208
|
-
updatedCell.style = {
|
209
|
-
...currentCell.style,
|
210
|
-
borderLeft: `2px solid ${color}`,
|
211
|
-
};
|
212
|
-
break;
|
213
|
-
case 'border-top':
|
214
|
-
updatedCell.style = {
|
215
|
-
...currentCell.style,
|
216
|
-
borderTop: `2px solid ${color}`,
|
217
|
-
};
|
218
|
-
break;
|
219
|
-
case 'border-bottom':
|
220
|
-
updatedCell.style = {
|
221
|
-
...currentCell.style,
|
222
|
-
borderBottom: `2px solid ${color}`,
|
223
|
-
};
|
224
|
-
break;
|
225
|
-
default:
|
226
|
-
break;
|
227
|
-
}
|
228
|
-
|
229
|
-
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
230
|
-
}
|
231
|
-
}
|
232
|
-
|
233
|
-
return updatedData;
|
234
|
-
}
|
235
|
-
|
236
|
-
export function applyTextAlign(
|
237
|
-
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
238
|
-
selectedRange: PointRange,
|
239
|
-
value: string
|
240
|
-
): Matrix.Matrix<Types.CellBase<any>> {
|
241
|
-
if (!selectedRange) {
|
242
|
-
return currentData;
|
243
|
-
}
|
244
|
-
|
245
|
-
const { start, end } = selectedRange;
|
246
|
-
|
247
|
-
let updatedData = currentData;
|
248
|
-
|
249
|
-
for (let row = start.row; row <= end.row; row++) {
|
250
|
-
for (let col = start.column; col <= end.column; col++) {
|
251
|
-
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
252
|
-
|
253
|
-
if (!currentCell) {
|
254
|
-
continue;
|
255
|
-
}
|
256
|
-
|
257
|
-
let updatedCell = {
|
299
|
+
} else {
|
300
|
+
updatedCell = {
|
258
301
|
...currentCell,
|
259
302
|
style: {
|
260
303
|
...currentCell.style,
|
261
|
-
|
304
|
+
textDecoration: value === 'double_border' ? 'underline' : value,
|
305
|
+
textDecorationStyle:
|
306
|
+
value === 'double_border'
|
307
|
+
? 'double'
|
308
|
+
: ('none' as TextDecorationStyle),
|
262
309
|
},
|
263
310
|
};
|
264
|
-
|
265
|
-
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
266
311
|
}
|
312
|
+
|
313
|
+
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
267
314
|
}
|
268
|
-
|
269
|
-
return updatedData;
|
270
315
|
}
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
const { start, end } = selectedRange;
|
279
|
-
|
280
|
-
let updatedData = currentData;
|
281
|
-
|
282
|
-
for (let row = start.row; row <= end.row; row++) {
|
283
|
-
for (let col = start.column; col <= end.column; col++) {
|
284
|
-
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
285
|
-
|
286
|
-
if (!currentCell) {
|
287
|
-
continue;
|
288
|
-
}
|
289
|
-
|
290
|
-
let updatedCell;
|
291
|
-
if (!active) {
|
292
|
-
updatedCell = {
|
293
|
-
...currentCell,
|
294
|
-
style: {
|
295
|
-
...currentCell.style,
|
296
|
-
textDecoration: 'none',
|
297
|
-
textDecorationStyle: 'none' as TextDecorationStyle,
|
298
|
-
},
|
299
|
-
};
|
300
|
-
} else {
|
301
|
-
updatedCell = {
|
302
|
-
...currentCell,
|
303
|
-
style: {
|
304
|
-
...currentCell.style,
|
305
|
-
textDecoration: value === 'double_border' ? 'underline' : value,
|
306
|
-
textDecorationStyle:
|
307
|
-
value === 'double_border'
|
308
|
-
? 'double'
|
309
|
-
: ('none' as TextDecorationStyle),
|
310
|
-
},
|
311
|
-
};
|
312
|
-
}
|
313
|
-
|
314
|
-
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
315
|
-
}
|
316
|
-
}
|
317
|
-
|
318
|
-
return updatedData;
|
316
|
+
|
317
|
+
return updatedData;
|
318
|
+
}
|
319
|
+
|
320
|
+
export function isValidHexColor(color: string): boolean {
|
321
|
+
if (color.length !== 6) {
|
322
|
+
return false;
|
319
323
|
}
|
320
|
-
|
321
|
-
|
322
|
-
|
324
|
+
|
325
|
+
const hexChars = '0123456789ABCDEFabcdef';
|
326
|
+
for (let i = 1; i < color.length; i++) {
|
327
|
+
if (!hexChars.includes(color[i] as string)) {
|
323
328
|
return false;
|
324
329
|
}
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
+
}
|
331
|
+
|
332
|
+
return true;
|
333
|
+
}
|
334
|
+
|
335
|
+
export function applyColorToCells(
|
336
|
+
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
337
|
+
selectedRange: PointRange | null,
|
338
|
+
color: string
|
339
|
+
): Matrix.Matrix<Types.CellBase<any>> {
|
340
|
+
if (!selectedRange) {
|
341
|
+
return currentData;
|
342
|
+
}
|
343
|
+
|
344
|
+
const { start, end } = selectedRange;
|
345
|
+
|
346
|
+
let updatedData = currentData;
|
347
|
+
|
348
|
+
const isHex = isValidHexColor(color);
|
349
|
+
|
350
|
+
const applyColor = isHex ? `#${color}` : color;
|
351
|
+
|
352
|
+
for (let row = start.row; row <= end.row; row++) {
|
353
|
+
for (let col = start.column; col <= end.column; col++) {
|
354
|
+
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
355
|
+
|
356
|
+
if (!currentCell) {
|
357
|
+
continue;
|
330
358
|
}
|
359
|
+
|
360
|
+
const updatedCell = {
|
361
|
+
...currentCell,
|
362
|
+
style: {
|
363
|
+
...currentCell.style,
|
364
|
+
color: applyColor,
|
365
|
+
},
|
366
|
+
};
|
367
|
+
|
368
|
+
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
331
369
|
}
|
332
|
-
|
333
|
-
return true;
|
334
370
|
}
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
371
|
+
|
372
|
+
return updatedData;
|
373
|
+
}
|
374
|
+
|
375
|
+
export function applyBackgroundColorToCells(
|
376
|
+
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
377
|
+
selectedRange: PointRange | null,
|
378
|
+
backgroundColor: string
|
379
|
+
): Matrix.Matrix<Types.CellBase<any>> {
|
380
|
+
if (selectedRange) {
|
345
381
|
const { start, end } = selectedRange;
|
346
|
-
|
382
|
+
|
347
383
|
let updatedData = currentData;
|
348
|
-
|
349
|
-
const isHex = isValidHexColor(
|
350
|
-
|
351
|
-
const applyColor = isHex ? `#${
|
352
|
-
|
384
|
+
|
385
|
+
const isHex = isValidHexColor(backgroundColor);
|
386
|
+
|
387
|
+
const applyColor = isHex ? `#${backgroundColor}` : backgroundColor;
|
388
|
+
|
353
389
|
for (let row = start.row; row <= end.row; row++) {
|
354
390
|
for (let col = start.column; col <= end.column; col++) {
|
355
391
|
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
356
|
-
|
392
|
+
|
357
393
|
if (!currentCell) {
|
358
394
|
continue;
|
359
395
|
}
|
360
|
-
|
396
|
+
|
361
397
|
const updatedCell = {
|
362
398
|
...currentCell,
|
363
399
|
style: {
|
364
400
|
...currentCell.style,
|
365
|
-
|
401
|
+
backgroundColor: applyColor,
|
366
402
|
},
|
367
403
|
};
|
368
|
-
|
369
|
-
updatedData = Matrix.set(
|
404
|
+
|
405
|
+
updatedData = Matrix.set(
|
406
|
+
{ row, column: col },
|
407
|
+
updatedCell,
|
408
|
+
updatedData
|
409
|
+
);
|
370
410
|
}
|
371
411
|
}
|
372
|
-
|
412
|
+
|
373
413
|
return updatedData;
|
374
414
|
}
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
if (selectedRange) {
|
382
|
-
const { start, end } = selectedRange;
|
383
|
-
|
384
|
-
let updatedData = currentData;
|
385
|
-
|
386
|
-
const isHex = isValidHexColor(backgroundColor);
|
387
|
-
|
388
|
-
const applyColor = isHex ? `#${backgroundColor}` : backgroundColor;
|
389
|
-
|
390
|
-
for (let row = start.row; row <= end.row; row++) {
|
391
|
-
for (let col = start.column; col <= end.column; col++) {
|
392
|
-
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
393
|
-
|
394
|
-
if (!currentCell) {
|
395
|
-
continue;
|
396
|
-
}
|
397
|
-
|
398
|
-
const updatedCell = {
|
399
|
-
...currentCell,
|
400
|
-
style: {
|
401
|
-
...currentCell.style,
|
402
|
-
backgroundColor: applyColor,
|
403
|
-
},
|
404
|
-
};
|
405
|
-
|
406
|
-
updatedData = Matrix.set(
|
407
|
-
{ row, column: col },
|
408
|
-
updatedCell,
|
409
|
-
updatedData
|
410
|
-
);
|
411
|
-
}
|
412
|
-
}
|
413
|
-
|
414
|
-
return updatedData;
|
415
|
-
}
|
416
|
-
return currentData;
|
415
|
+
return currentData;
|
416
|
+
}
|
417
|
+
|
418
|
+
export function edit(state: Types.StoreState): Types.StoreState {
|
419
|
+
if (isActiveReadOnly(state)) {
|
420
|
+
return state;
|
417
421
|
}
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
+
return { ...state, mode: 'edit' };
|
423
|
+
}
|
424
|
+
|
425
|
+
export function clear(state: Types.StoreState): Types.StoreState {
|
426
|
+
if (!state.active) {
|
427
|
+
return state;
|
428
|
+
}
|
429
|
+
|
430
|
+
const canClearCell = (cell: Types.CellBase | undefined) =>
|
431
|
+
cell && !cell.readOnly;
|
432
|
+
const clearCell = (cell: Types.CellBase | undefined) => {
|
433
|
+
if (!canClearCell(cell)) {
|
434
|
+
return cell;
|
422
435
|
}
|
423
|
-
return {
|
436
|
+
return Object.assign({}, cell, { value: undefined });
|
437
|
+
};
|
438
|
+
|
439
|
+
const selectedRange = state.selected.toRange(state.model.data);
|
440
|
+
|
441
|
+
const changes: Types.CommitChanges = [];
|
442
|
+
let newData = state.model.data;
|
443
|
+
|
444
|
+
for (const point of selectedRange || []) {
|
445
|
+
const cell = Matrix.get(point, state.model.data);
|
446
|
+
const clearedCell = clearCell(cell);
|
447
|
+
changes.push({
|
448
|
+
prevCell: cell || null,
|
449
|
+
nextCell: clearedCell || null,
|
450
|
+
});
|
451
|
+
newData = Matrix.set(point, clearedCell, newData);
|
424
452
|
}
|
425
|
-
|
426
|
-
|
453
|
+
|
454
|
+
return {
|
455
|
+
...state,
|
456
|
+
...commit(changes),
|
457
|
+
};
|
458
|
+
}
|
459
|
+
|
460
|
+
export function blur(state: Types.StoreState): Types.StoreState {
|
461
|
+
return { ...state, active: null, selected: new EmptySelection() };
|
462
|
+
}
|
463
|
+
|
464
|
+
export function view(state: Types.StoreState): Types.StoreState {
|
465
|
+
return { ...state, mode: 'view' };
|
466
|
+
}
|
467
|
+
|
468
|
+
export function commit(
|
469
|
+
changes: Types.CommitChanges
|
470
|
+
): Partial<Types.StoreState> {
|
471
|
+
return { lastCommit: changes };
|
472
|
+
}
|
473
|
+
|
474
|
+
export const go =
|
475
|
+
(rowDelta: number, columnDelta: number): KeyDownHandler =>
|
476
|
+
(state) => {
|
427
477
|
if (!state.active) {
|
428
|
-
return
|
478
|
+
return;
|
429
479
|
}
|
430
|
-
|
431
|
-
const
|
432
|
-
|
433
|
-
const
|
434
|
-
|
435
|
-
|
436
|
-
}
|
437
|
-
return Object.assign({}, cell, { value: undefined });
|
480
|
+
const size = Matrix.getSize(state.model.data);
|
481
|
+
const newColumn = state.active.column + columnDelta;
|
482
|
+
const shouldWrap = newColumn >= size.columns;
|
483
|
+
const nextActive = {
|
484
|
+
row: state.active.row + rowDelta + (shouldWrap ? 1 : 0),
|
485
|
+
column: (state.active.column + columnDelta) % size.columns,
|
438
486
|
};
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
const changes: Types.CommitChanges = [];
|
443
|
-
let newData = state.model.data;
|
444
|
-
|
445
|
-
for (const point of selectedRange || []) {
|
446
|
-
const cell = Matrix.get(point, state.model.data);
|
447
|
-
const clearedCell = clearCell(cell);
|
448
|
-
changes.push({
|
449
|
-
prevCell: cell || null,
|
450
|
-
nextCell: clearedCell || null,
|
451
|
-
});
|
452
|
-
newData = Matrix.set(point, clearedCell, newData);
|
487
|
+
if (!Matrix.has(nextActive, state.model.data)) {
|
488
|
+
return { ...state, mode: 'view' };
|
453
489
|
}
|
454
|
-
|
455
490
|
return {
|
456
491
|
...state,
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
}
|
461
|
-
|
462
|
-
export function blur(state: Types.StoreState): Types.StoreState {
|
463
|
-
return { ...state, active: null, selected: new EmptySelection() };
|
464
|
-
}
|
465
|
-
|
466
|
-
export function view(state: Types.StoreState): Types.StoreState {
|
467
|
-
return { ...state, mode: 'view' };
|
468
|
-
}
|
469
|
-
|
470
|
-
export function commit(changes: Types.CommitChanges): Partial<Types.StoreState> {
|
471
|
-
return { lastCommit: changes };
|
472
|
-
}
|
473
|
-
|
474
|
-
// Utility
|
475
|
-
|
476
|
-
export const go =
|
477
|
-
(rowDelta: number, columnDelta: number): KeyDownHandler =>
|
478
|
-
(state) => {
|
479
|
-
if (!state.active) {
|
480
|
-
return;
|
481
|
-
}
|
482
|
-
const size = Matrix.getSize(state.model.data);
|
483
|
-
const newColumn = state.active.column + columnDelta;
|
484
|
-
const shouldWrap = newColumn >= size.columns;
|
485
|
-
const nextActive = {
|
486
|
-
row: state.active.row + rowDelta + (shouldWrap ? 1 : 0),
|
487
|
-
column: (state.active.column + columnDelta) % size.columns,
|
488
|
-
};
|
489
|
-
if (!Matrix.has(nextActive, state.model.data)) {
|
490
|
-
return { ...state, mode: 'view' };
|
491
|
-
}
|
492
|
-
return {
|
493
|
-
...state,
|
494
|
-
active: nextActive,
|
495
|
-
selected: new RangeSelection(new PointRange(nextActive, nextActive)),
|
496
|
-
mode: 'view',
|
497
|
-
};
|
492
|
+
active: nextActive,
|
493
|
+
selected: new RangeSelection(new PointRange(nextActive, nextActive)),
|
494
|
+
mode: 'view',
|
498
495
|
};
|
499
|
-
|
500
|
-
function convertPtToPx(pt: number): string {
|
501
|
-
const px = pt * 1.33;
|
502
|
-
return `${Math.round(px)}px`;
|
503
|
-
}
|
504
|
-
|
505
|
-
// Key Bindings
|
506
|
-
|
507
|
-
type TextDecorationStyle = 'solid' | 'double' | 'dotted' | 'dashed' | 'wavy';
|
508
|
-
|
509
|
-
type TextAlign = 'left' | 'center' | 'right';
|
510
|
-
|
511
|
-
export type KeyDownHandler = (
|
512
|
-
state: Types.StoreState,
|
513
|
-
event: React.KeyboardEvent
|
514
|
-
) => Types.StoreState | void;
|
515
|
-
|
516
|
-
type KeyDownHandlers = {
|
517
|
-
[K in string]: KeyDownHandler | undefined;
|
518
|
-
};
|
519
|
-
|
520
|
-
const keyDownHandlers: KeyDownHandlers = {
|
521
|
-
ArrowUp: go(-1, 0),
|
522
|
-
ArrowDown: go(+1, 0),
|
523
|
-
ArrowLeft: go(0, -1),
|
524
|
-
ArrowRight: go(0, +1),
|
525
|
-
Tab: go(0, +1),
|
526
|
-
Enter: edit,
|
527
|
-
Backspace: clear,
|
528
|
-
Delete: clear,
|
529
|
-
Escape: blur,
|
530
|
-
};
|
531
|
-
|
532
|
-
const editKeyDownHandlers: KeyDownHandlers = {
|
533
|
-
Escape: view,
|
534
|
-
Tab: keyDownHandlers.Tab,
|
535
|
-
Enter: keyDownHandlers.ArrowDown,
|
536
496
|
};
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
}
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
497
|
+
|
498
|
+
function convertPtToPx(pt: number): string {
|
499
|
+
const px = pt * 1.33;
|
500
|
+
return `${Math.round(px)}px`;
|
501
|
+
}
|
502
|
+
|
503
|
+
// Key Bindings
|
504
|
+
|
505
|
+
type TextDecorationStyle = 'solid' | 'double' | 'dotted' | 'dashed' | 'wavy';
|
506
|
+
|
507
|
+
type TextAlign = 'left' | 'center' | 'right';
|
508
|
+
|
509
|
+
export type KeyDownHandler = (
|
510
|
+
state: Types.StoreState,
|
511
|
+
event: React.KeyboardEvent
|
512
|
+
) => Types.StoreState | void;
|
513
|
+
|
514
|
+
type KeyDownHandlers = {
|
515
|
+
[K in string]: KeyDownHandler | undefined;
|
516
|
+
};
|
517
|
+
|
518
|
+
const keyDownHandlers: KeyDownHandlers = {
|
519
|
+
ArrowUp: go(-1, 0),
|
520
|
+
ArrowDown: go(+1, 0),
|
521
|
+
ArrowLeft: go(0, -1),
|
522
|
+
ArrowRight: go(0, +1),
|
523
|
+
Tab: go(0, +1),
|
524
|
+
Enter: edit,
|
525
|
+
Backspace: clear,
|
526
|
+
Delete: clear,
|
527
|
+
Escape: blur,
|
528
|
+
};
|
529
|
+
|
530
|
+
const editKeyDownHandlers: KeyDownHandlers = {
|
531
|
+
Escape: view,
|
532
|
+
Tab: keyDownHandlers.Tab,
|
533
|
+
Enter: keyDownHandlers.ArrowDown,
|
534
|
+
};
|
535
|
+
|
536
|
+
const editShiftKeyDownHandlers: KeyDownHandlers = {
|
537
|
+
Tab: go(0, -1),
|
538
|
+
};
|
539
|
+
|
540
|
+
export enum Direction {
|
541
|
+
Left = 'Left',
|
542
|
+
Right = 'Right',
|
543
|
+
Top = 'Top',
|
544
|
+
Bottom = 'Bottom',
|
545
|
+
}
|
546
|
+
|
547
|
+
const shiftKeyDownHandlers: KeyDownHandlers = {
|
548
|
+
ArrowUp: (state) => ({
|
549
|
+
...state,
|
550
|
+
selected: modifyEdge(
|
551
|
+
state.selected,
|
552
|
+
state.active,
|
553
|
+
state.model.data,
|
554
|
+
Direction.Top
|
555
|
+
),
|
556
|
+
}),
|
557
|
+
ArrowDown: (state) => ({
|
558
|
+
...state,
|
559
|
+
selected: modifyEdge(
|
560
|
+
state.selected,
|
561
|
+
state.active,
|
562
|
+
state.model.data,
|
563
|
+
Direction.Bottom
|
564
|
+
),
|
565
|
+
}),
|
566
|
+
ArrowLeft: (state) => ({
|
567
|
+
...state,
|
568
|
+
selected: modifyEdge(
|
569
|
+
state.selected,
|
570
|
+
state.active,
|
571
|
+
state.model.data,
|
572
|
+
Direction.Left
|
573
|
+
),
|
574
|
+
}),
|
575
|
+
ArrowRight: (state) => ({
|
576
|
+
...state,
|
577
|
+
selected: modifyEdge(
|
578
|
+
state.selected,
|
579
|
+
state.active,
|
580
|
+
state.model.data,
|
581
|
+
Direction.Right
|
582
|
+
),
|
583
|
+
}),
|
584
|
+
Tab: go(0, -1),
|
585
|
+
};
|
586
|
+
|
587
|
+
const shiftMetaKeyDownHandlers: KeyDownHandlers = {};
|
588
|
+
const metaKeyDownHandlers: KeyDownHandlers = {};
|
589
|
+
|
590
|
+
export function getKeyDownHandler(
|
591
|
+
state: Types.StoreState,
|
592
|
+
event: React.KeyboardEvent
|
593
|
+
): KeyDownHandler | undefined {
|
594
|
+
const { key } = event;
|
595
|
+
let handlers;
|
596
|
+
// Order matters
|
597
|
+
if (state.mode === 'edit') {
|
598
|
+
if (event.shiftKey) {
|
599
|
+
handlers = editShiftKeyDownHandlers;
|
611
600
|
} else {
|
612
|
-
handlers =
|
601
|
+
handlers = editKeyDownHandlers;
|
613
602
|
}
|
614
|
-
|
615
|
-
|
603
|
+
} else if (event.shiftKey && event.metaKey) {
|
604
|
+
handlers = shiftMetaKeyDownHandlers;
|
605
|
+
} else if (event.shiftKey) {
|
606
|
+
handlers = shiftKeyDownHandlers;
|
607
|
+
} else if (event.metaKey) {
|
608
|
+
handlers = metaKeyDownHandlers;
|
609
|
+
} else {
|
610
|
+
handlers = keyDownHandlers;
|
616
611
|
}
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
612
|
+
|
613
|
+
return handlers[key];
|
614
|
+
}
|
615
|
+
|
616
|
+
/** Returns whether the reducer has a handler for the given keydown event */
|
617
|
+
export function hasKeyDownHandler(
|
618
|
+
state: Types.StoreState,
|
619
|
+
event: React.KeyboardEvent
|
620
|
+
): boolean {
|
621
|
+
return getKeyDownHandler(state, event) !== undefined;
|
622
|
+
}
|
623
|
+
|
624
|
+
/** Returns whether the active cell is read only */
|
625
|
+
export function isActiveReadOnly(state: Types.StoreState): boolean {
|
626
|
+
const activeCell = getActive(state);
|
627
|
+
return Boolean(activeCell?.readOnly);
|
628
|
+
}
|
629
|
+
|
630
|
+
/** Gets active cell from given state */
|
631
|
+
export function getActive(state: Types.StoreState): Types.CellBase | null {
|
632
|
+
const activeCell = state.active && Matrix.get(state.active, state.model.data);
|
633
|
+
return activeCell || null;
|
634
|
+
}
|
635
|
+
|
636
|
+
/** Modify given edge according to given active point and data */
|
637
|
+
export function modifyEdge<T extends Selection>(
|
638
|
+
selection: T,
|
639
|
+
active: Point.Point | null,
|
640
|
+
data: Matrix.Matrix<unknown>,
|
641
|
+
direction: Direction
|
642
|
+
): T {
|
643
|
+
if (!active) {
|
644
|
+
return selection;
|
624
645
|
}
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
646
|
+
if (selection instanceof RangeSelection) {
|
647
|
+
const nextSelection = modifyRangeSelectionEdge(
|
648
|
+
selection,
|
649
|
+
active,
|
650
|
+
data,
|
651
|
+
direction
|
652
|
+
);
|
653
|
+
// @ts-expect-error
|
654
|
+
return nextSelection;
|
630
655
|
}
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
const activeCell = state.active && Matrix.get(state.active, state.model.data);
|
635
|
-
return activeCell || null;
|
656
|
+
if (selection instanceof EntireColumnsSelection) {
|
657
|
+
// @ts-expect-error
|
658
|
+
return modifyEntireColumnsSelection(selection, active, data, direction);
|
636
659
|
}
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
660
|
+
if (selection instanceof EntireRowsSelection) {
|
661
|
+
// @ts-expect-error
|
662
|
+
return modifyEntireRowsSelection(selection, active, data, direction);
|
663
|
+
}
|
664
|
+
return selection;
|
665
|
+
}
|
666
|
+
|
667
|
+
export function modifyRangeSelectionEdge(
|
668
|
+
rangeSelection: RangeSelection,
|
669
|
+
active: Point.Point,
|
670
|
+
data: Matrix.Matrix<unknown>,
|
671
|
+
edge: Direction
|
672
|
+
): RangeSelection {
|
673
|
+
const field =
|
674
|
+
edge === Direction.Left || edge === Direction.Right ? 'column' : 'row';
|
675
|
+
|
676
|
+
const key =
|
677
|
+
edge === Direction.Left || edge === Direction.Top ? 'start' : 'end';
|
678
|
+
const delta = key === 'start' ? -1 : 1;
|
679
|
+
|
680
|
+
const edgeOffsets = rangeSelection.range.has({
|
681
|
+
...active,
|
682
|
+
[field]: active[field] + delta * -1,
|
683
|
+
});
|
684
|
+
|
685
|
+
const keyToModify = edgeOffsets ? (key === 'start' ? 'end' : 'start') : key;
|
686
|
+
|
687
|
+
const nextRange = new PointRange(
|
688
|
+
rangeSelection.range.start,
|
689
|
+
rangeSelection.range.end
|
690
|
+
);
|
691
|
+
|
692
|
+
nextRange[keyToModify][field] += delta;
|
693
|
+
|
694
|
+
const nextSelection = new RangeSelection(nextRange).normalizeTo(data);
|
695
|
+
|
696
|
+
return nextSelection;
|
697
|
+
}
|
698
|
+
|
699
|
+
export function modifyEntireRowsSelection(
|
700
|
+
selection: EntireRowsSelection,
|
701
|
+
active: Point.Point,
|
702
|
+
data: Matrix.Matrix<unknown>,
|
703
|
+
edge: Direction
|
704
|
+
): EntireRowsSelection {
|
705
|
+
if (edge === Direction.Left || edge === Direction.Right) {
|
666
706
|
return selection;
|
667
707
|
}
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
edge
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
const delta = key === 'start' ? -1 : 1;
|
681
|
-
|
682
|
-
const edgeOffsets = rangeSelection.range.has({
|
683
|
-
...active,
|
684
|
-
[field]: active[field] + delta * -1,
|
685
|
-
});
|
686
|
-
|
687
|
-
const keyToModify = edgeOffsets ? (key === 'start' ? 'end' : 'start') : key;
|
688
|
-
|
689
|
-
const nextRange = new PointRange(
|
690
|
-
rangeSelection.range.start,
|
691
|
-
rangeSelection.range.end
|
692
|
-
);
|
693
|
-
|
694
|
-
nextRange[keyToModify][field] += delta;
|
695
|
-
|
696
|
-
const nextSelection = new RangeSelection(nextRange).normalizeTo(data);
|
697
|
-
|
698
|
-
return nextSelection;
|
708
|
+
const delta = edge === Direction.Top ? -1 : 1;
|
709
|
+
const property = edge === Direction.Top ? 'start' : 'end';
|
710
|
+
const oppositeProperty = property === 'start' ? 'end' : 'start';
|
711
|
+
const newSelectionData = { ...selection };
|
712
|
+
if (
|
713
|
+
edge === Direction.Top
|
714
|
+
? selection.end > active.row
|
715
|
+
: selection.start < active.row
|
716
|
+
) {
|
717
|
+
newSelectionData[oppositeProperty] = selection[oppositeProperty] + delta;
|
718
|
+
} else {
|
719
|
+
newSelectionData[property] = selection[property] + delta;
|
699
720
|
}
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
edge === Direction.Top
|
716
|
-
? selection.end > active.row
|
717
|
-
: selection.start < active.row
|
718
|
-
) {
|
719
|
-
newSelectionData[oppositeProperty] = selection[oppositeProperty] + delta;
|
720
|
-
} else {
|
721
|
-
newSelectionData[property] = selection[property] + delta;
|
722
|
-
}
|
723
|
-
const nextSelection = new EntireRowsSelection(
|
724
|
-
Math.max(newSelectionData.start, 0),
|
725
|
-
Math.max(newSelectionData.end, 0)
|
726
|
-
);
|
727
|
-
return nextSelection.normalizeTo(data);
|
721
|
+
const nextSelection = new EntireRowsSelection(
|
722
|
+
Math.max(newSelectionData.start, 0),
|
723
|
+
Math.max(newSelectionData.end, 0)
|
724
|
+
);
|
725
|
+
return nextSelection.normalizeTo(data);
|
726
|
+
}
|
727
|
+
|
728
|
+
export function modifyEntireColumnsSelection(
|
729
|
+
selection: EntireColumnsSelection,
|
730
|
+
active: Point.Point,
|
731
|
+
data: Matrix.Matrix<unknown>,
|
732
|
+
edge: Direction
|
733
|
+
): EntireColumnsSelection {
|
734
|
+
if (edge === Direction.Top || edge === Direction.Bottom) {
|
735
|
+
return selection;
|
728
736
|
}
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
edge
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
const oppositeProperty = property === 'start' ? 'end' : 'start';
|
742
|
-
const newSelectionData = { ...selection };
|
743
|
-
if (
|
744
|
-
edge === Direction.Left
|
745
|
-
? selection.end > active.row
|
746
|
-
: selection.start < active.row
|
747
|
-
) {
|
748
|
-
newSelectionData[oppositeProperty] = selection[oppositeProperty] + delta;
|
749
|
-
} else {
|
750
|
-
newSelectionData[property] = selection[property] + delta;
|
751
|
-
}
|
752
|
-
const nextSelection = new EntireColumnsSelection(
|
753
|
-
Math.max(newSelectionData.start, 0),
|
754
|
-
Math.max(newSelectionData.end, 0)
|
755
|
-
);
|
756
|
-
return nextSelection.normalizeTo(data);
|
737
|
+
const delta = edge === Direction.Left ? -1 : 1;
|
738
|
+
const property = edge === Direction.Left ? 'start' : 'end';
|
739
|
+
const oppositeProperty = property === 'start' ? 'end' : 'start';
|
740
|
+
const newSelectionData = { ...selection };
|
741
|
+
if (
|
742
|
+
edge === Direction.Left
|
743
|
+
? selection.end > active.row
|
744
|
+
: selection.start < active.row
|
745
|
+
) {
|
746
|
+
newSelectionData[oppositeProperty] = selection[oppositeProperty] + delta;
|
747
|
+
} else {
|
748
|
+
newSelectionData[property] = selection[property] + delta;
|
757
749
|
}
|
758
|
-
|
750
|
+
const nextSelection = new EntireColumnsSelection(
|
751
|
+
Math.max(newSelectionData.start, 0),
|
752
|
+
Math.max(newSelectionData.end, 0)
|
753
|
+
);
|
754
|
+
return nextSelection.normalizeTo(data);
|
755
|
+
}
|