pixel-react 1.4.3 → 1.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. package/.yarn/install-state.gz +0 -0
  2. package/lib/components/AddResourceButton/type.d.ts +1 -1
  3. package/lib/components/Drawer/Types.d.ts +4 -0
  4. package/lib/components/Excel/ExcelContextMenu/ExcelContextMenu.d.ts +13 -0
  5. package/lib/components/Excel/ExcelFile/ExcelFileComponents/Spreadsheet.d.ts +0 -13
  6. package/lib/components/Excel/ExcelFile/ExcelFileComponents/actions.d.ts +29 -1
  7. package/lib/components/Excel/ExcelFile/ExcelFileComponents/engine/engine.d.ts +3 -9
  8. package/lib/components/Excel/ExcelFile/ExcelFileComponents/engine/formula.d.ts +2 -10
  9. package/lib/components/Excel/ExcelFile/ExcelFileComponents/engine/point-graph.d.ts +0 -1
  10. package/lib/components/Excel/ExcelFile/ExcelFileComponents/types.d.ts +27 -2
  11. package/lib/components/Form/Forms.d.ts +4 -2
  12. package/lib/components/InputWithDropdown/InputWithDropdown.d.ts +1 -1
  13. package/lib/components/MenuOption/MenuOption.d.ts +1 -1
  14. package/lib/components/MenuOption/types.d.ts +49 -15
  15. package/lib/components/MultiSelect/MultiSelect.d.ts +1 -1
  16. package/lib/components/MultiSelect/MultiSelectTypes.d.ts +4 -5
  17. package/lib/components/MultiSelect/dropdownTypes.d.ts +2 -0
  18. package/lib/components/RadioButton/RadioButton.d.ts +1 -0
  19. package/lib/components/RadioButton/radioButtonTypes.d.ts +3 -1
  20. package/lib/components/Select/components/types.d.ts +4 -2
  21. package/lib/components/Table/Table.d.ts +1 -1
  22. package/lib/components/ToggleSwitch/ToggleSwitch.d.ts +10 -0
  23. package/lib/components/ToggleSwitch/index.d.ts +1 -0
  24. package/lib/index.d.ts +109 -23
  25. package/lib/index.esm.js +5711 -635
  26. package/lib/index.esm.js.map +1 -1
  27. package/lib/index.js +5707 -629
  28. package/lib/index.js.map +1 -1
  29. package/lib/tsconfig.tsbuildinfo +1 -1
  30. package/package.json +11 -11
  31. package/src/StyleGuide/ColorPalette/colorPaletteList.ts +10 -0
  32. package/src/assets/Themes/BaseTheme.scss +17 -23
  33. package/src/assets/Themes/DarkTheme.scss +25 -38
  34. package/src/assets/icons/apk_file_type.svg +4 -0
  35. package/src/assets/icons/compressed_file_type.svg +4 -0
  36. package/src/assets/icons/csv_file_type.svg +4 -0
  37. package/src/assets/icons/excel_corner_menu.svg +3 -0
  38. package/src/assets/icons/formula_icon.svg +3 -0
  39. package/src/assets/icons/gif_file_type.svg +4 -0
  40. package/src/assets/icons/html_file_type.svg +4 -0
  41. package/src/assets/icons/ipk_file_type.svg +4 -0
  42. package/src/assets/icons/jpg_file_type.svg +4 -0
  43. package/src/assets/icons/json_file_type.svg +4 -0
  44. package/src/assets/icons/pdf_file_type.svg +4 -0
  45. package/src/assets/icons/png_file_type.svg +4 -0
  46. package/src/assets/icons/quick_run_setting_icon.svg +5 -0
  47. package/src/assets/icons/run_automation_scripts_icon.svg +33 -0
  48. package/src/assets/icons/run_manual_testcase_icon.svg +4 -0
  49. package/src/assets/icons/search.svg +2 -2
  50. package/src/assets/icons/txt_file_type.svg +4 -0
  51. package/src/assets/icons/xls_file_type.svg +4 -0
  52. package/src/assets/icons/xlsx_file_type.svg +4 -0
  53. package/src/assets/icons/xml_file_type.svg +4 -0
  54. package/src/components/AddResourceButton/AddButton.tsx +7 -7
  55. package/src/components/AddResourceButton/type.ts +1 -1
  56. package/src/components/AttachmentButton/AttachmentButton.scss +1 -1
  57. package/src/components/AttachmentButton/AttachmentButton.stories.tsx +1 -0
  58. package/src/components/Button/Button.scss +22 -20
  59. package/src/components/Button/Button.tsx +8 -1
  60. package/src/components/Charts/DashboardDonutChart/DashboardDonutChart.tsx +2 -2
  61. package/src/components/Drawer/Drawer.scss +4 -3
  62. package/src/components/Drawer/Drawer.tsx +14 -18
  63. package/src/components/Drawer/Types.ts +4 -0
  64. package/src/components/Editor/Editor.tsx +9 -11
  65. package/src/components/Excel/ExcelContextMenu/ExcelContextMenu.scss +39 -0
  66. package/src/components/Excel/ExcelContextMenu/ExcelContextMenu.tsx +51 -0
  67. package/src/components/Excel/ExcelFile/ExcelFile.tsx +7 -8
  68. package/src/components/Excel/ExcelFile/ExcelFileComponents/Cell.tsx +35 -0
  69. package/src/components/Excel/ExcelFile/ExcelFileComponents/ColumnIndicator.tsx +44 -7
  70. package/src/components/Excel/ExcelFile/ExcelFileComponents/CornerIndicator.tsx +8 -1
  71. package/src/components/Excel/ExcelFile/ExcelFileComponents/RowIndicator.tsx +45 -6
  72. package/src/components/Excel/ExcelFile/ExcelFileComponents/Spreadsheet.scss +37 -2
  73. package/src/components/Excel/ExcelFile/ExcelFileComponents/Spreadsheet.tsx +69 -24
  74. package/src/components/Excel/ExcelFile/ExcelFileComponents/actions.ts +59 -0
  75. package/src/components/Excel/ExcelFile/ExcelFileComponents/engine/engine.ts +18 -65
  76. package/src/components/Excel/ExcelFile/ExcelFileComponents/engine/formula.ts +5 -110
  77. package/src/components/Excel/ExcelFile/ExcelFileComponents/engine/point-graph.ts +0 -2
  78. package/src/components/Excel/ExcelFile/ExcelFileComponents/reducer.ts +105 -1
  79. package/src/components/Excel/ExcelFile/ExcelFileComponents/reducerFunctions.ts +670 -673
  80. package/src/components/Excel/ExcelFile/ExcelFileComponents/types.ts +38 -2
  81. package/src/components/Excel/ExcelToolBar/ExcelToolBar.tsx +0 -4
  82. package/src/components/FileDropzone/FileDropzone.scss +4 -2
  83. package/src/components/FileDropzone/FileDropzone.tsx +1 -1
  84. package/src/components/FileDropzone/FilePreview.tsx +3 -1
  85. package/src/components/Form/Form.scss +2 -0
  86. package/src/components/Form/Form.stories.tsx +195 -6
  87. package/src/components/Form/Forms.tsx +15 -8
  88. package/src/components/Icon/iconList.ts +46 -0
  89. package/src/components/IconRadioGroup/IconRadioGroup.scss +3 -0
  90. package/src/components/IconRadioGroup/IconRadioGroup.tsx +20 -17
  91. package/src/components/Input/Input.scss +14 -15
  92. package/src/components/Input/Input.stories.tsx +2 -1
  93. package/src/components/InputWithDropdown/InputWithDropdown.scss +12 -13
  94. package/src/components/InputWithDropdown/InputWithDropdown.stories.tsx +3 -2
  95. package/src/components/InputWithDropdown/InputWithDropdown.tsx +22 -19
  96. package/src/components/MenuOption/MenuOption.scss +11 -10
  97. package/src/components/MenuOption/MenuOption.stories.tsx +51 -232
  98. package/src/components/MenuOption/MenuOption.tsx +131 -52
  99. package/src/components/MenuOption/types.ts +55 -14
  100. package/src/components/MiniModal/MiniModal.stories.tsx +2 -3
  101. package/src/components/MultiSelect/Dropdown.tsx +11 -12
  102. package/src/components/MultiSelect/MultiSelect.scss +1 -0
  103. package/src/components/MultiSelect/MultiSelect.stories.tsx +45 -10
  104. package/src/components/MultiSelect/MultiSelect.tsx +29 -13
  105. package/src/components/MultiSelect/MultiSelectTypes.ts +7 -5
  106. package/src/components/MultiSelect/dropdownTypes.ts +2 -0
  107. package/src/components/RadioButton/RadioButton.scss +3 -1
  108. package/src/components/RadioButton/RadioButton.tsx +3 -1
  109. package/src/components/RadioButton/radioButtonTypes.tsx +5 -1
  110. package/src/components/Search/Search.scss +25 -6
  111. package/src/components/Search/Search.tsx +45 -24
  112. package/src/components/Select/Select.scss +12 -12
  113. package/src/components/Select/Select.stories.tsx +2 -0
  114. package/src/components/Select/Select.tsx +11 -5
  115. package/src/components/Select/components/Dropdown.scss +2 -0
  116. package/src/components/Select/components/Dropdown.tsx +19 -4
  117. package/src/components/Select/components/types.ts +4 -2
  118. package/src/components/StatusButton/StatusButton.tsx +26 -20
  119. package/src/components/Table/Table.scss +1 -3
  120. package/src/components/Table/Table.stories.tsx +1 -0
  121. package/src/components/Table/Table.tsx +7 -3
  122. package/src/components/ToggleSwitch/ToggleSwitch.scss +59 -0
  123. package/src/components/ToggleSwitch/ToggleSwitch.stories.tsx +52 -0
  124. package/src/components/ToggleSwitch/ToggleSwitch.tsx +30 -0
  125. package/src/components/ToggleSwitch/index.ts +1 -0
  126. package/src/hooks/useFileDropzone.tsx +1 -0
  127. package/src/index.ts +4 -2
  128. package/src/components/Excel/ContextMenu/ContextMenu.scss +0 -99
  129. 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
- currentData: Matrix.Matrix<Types.CellBase<any>>,
16
- selectedRange: PointRange
17
- ): Matrix.Matrix<Types.CellBase<any>> {
18
- if (!selectedRange) {
19
- return currentData;
20
- }
21
-
22
- const { start, end } = selectedRange;
23
-
24
- let updatedData = currentData;
25
-
26
- for (let row = start.row; row <= end.row; row++) {
27
- for (let col = start.column; col <= end.column; col++) {
28
- const currentCell = Matrix.get({ row, column: col }, updatedData);
29
-
30
- if (!currentCell) {
31
- continue;
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
- export function applyItalicToCells(
50
- currentData: Matrix.Matrix<Types.CellBase<any>>,
51
- selectedRange: PointRange
52
- ): Matrix.Matrix<Types.CellBase<any>> {
53
- if (!selectedRange) {
54
- return currentData;
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
- const { start, end } = selectedRange;
58
-
59
- let updatedData = currentData;
60
-
61
- for (let row = start.row; row <= end.row; row++) {
62
- for (let col = start.column; col <= end.column; col++) {
63
- const currentCell = Matrix.get({ row, column: col }, updatedData);
64
-
65
- if (!currentCell) {
66
- continue;
67
- }
68
-
69
- const updatedCell = {
70
- ...currentCell,
71
- style: {
72
- ...currentCell.style,
73
- fontStyle: 'italic',
74
- },
75
- };
76
-
77
- updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
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
- export function applyFontFamily(
85
- currentData: Matrix.Matrix<Types.CellBase<any>>,
86
- selectedRange: PointRange,
87
- value: string
88
- ): Matrix.Matrix<Types.CellBase<any>> {
89
- if (!selectedRange) {
90
- return currentData;
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
- const { start, end } = selectedRange;
94
-
95
- let updatedData = currentData;
96
-
97
- for (let row = start.row; row <= end.row; row++) {
98
- for (let col = start.column; col <= end.column; col++) {
99
- const currentCell = Matrix.get({ row, column: col }, updatedData);
100
-
101
- if (!currentCell) {
102
- continue;
103
- }
104
-
105
- let updatedCell = {
106
- ...currentCell,
107
- style: {
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
- fontFamily: value,
110
- },
111
- };
112
-
113
- updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
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
- export function applyFontSize(
121
- currentData: Matrix.Matrix<Types.CellBase<any>>,
122
- selectedRange: PointRange,
123
- value: string
124
- ): Matrix.Matrix<Types.CellBase<any>> {
125
- const conversion = Number(value);
126
-
127
- if (isNaN(conversion)) {
128
- return currentData;
129
- }
130
-
131
- const fontSizeInPx = convertPtToPx(conversion);
132
-
133
- if (!selectedRange) {
134
- return currentData;
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
- const { start, end } = selectedRange;
138
-
139
- let updatedData = currentData;
140
-
141
- for (let row = start.row; row <= end.row; row++) {
142
- for (let col = start.column; col <= end.column; col++) {
143
- const currentCell = Matrix.get({ row, column: col }, updatedData);
144
-
145
- if (!currentCell) {
146
- continue;
147
- }
148
-
149
- let updatedCell = {
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
- fontSize: fontSizeInPx,
295
+ textDecoration: 'none',
296
+ textDecorationStyle: 'none' as TextDecorationStyle,
154
297
  },
155
298
  };
156
-
157
- updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
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
- textAlign: value as TextAlign,
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
- export function applyUnderlineToCells(
273
- currentData: Matrix.Matrix<Types.CellBase<any>>,
274
- selectedRange: PointRange,
275
- value: string,
276
- active: boolean
277
- ): Matrix.Matrix<Types.CellBase<any>> {
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
- export function isValidHexColor(color: string): boolean {
322
- if (color.length !== 6) {
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
- const hexChars = '0123456789ABCDEFabcdef';
327
- for (let i = 1; i < color.length; i++) {
328
- if (!hexChars.includes(color[i] as string)) {
329
- return false;
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
- export function applyColorToCells(
337
- currentData: Matrix.Matrix<Types.CellBase<any>>,
338
- selectedRange: PointRange | null,
339
- color: string
340
- ): Matrix.Matrix<Types.CellBase<any>> {
341
- if (!selectedRange) {
342
- return currentData;
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(color);
350
-
351
- const applyColor = isHex ? `#${color}` : color;
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
- color: applyColor,
401
+ backgroundColor: applyColor,
366
402
  },
367
403
  };
368
-
369
- updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
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
- export function applyBackgroundColorToCells(
377
- currentData: Matrix.Matrix<Types.CellBase<any>>,
378
- selectedRange: PointRange | null,
379
- backgroundColor: string
380
- ): Matrix.Matrix<Types.CellBase<any>> {
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
- export function edit(state: Types.StoreState): Types.StoreState {
420
- if (isActiveReadOnly(state)) {
421
- return state;
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 { ...state, mode: 'edit' };
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
- export function clear(state: Types.StoreState): Types.StoreState {
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 state;
478
+ return;
429
479
  }
430
-
431
- const canClearCell = (cell: Types.CellBase | undefined) =>
432
- cell && !cell.readOnly;
433
- const clearCell = (cell: Types.CellBase | undefined) => {
434
- if (!canClearCell(cell)) {
435
- return cell;
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
- const selectedRange = state.selected.toRange(state.model.data);
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
- model: new Model(createFormulaParser, newData),
458
- ...commit(changes),
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
- const editShiftKeyDownHandlers: KeyDownHandlers = {
539
- Tab: go(0, -1),
540
- };
541
-
542
- export enum Direction {
543
- Left = 'Left',
544
- Right = 'Right',
545
- Top = 'Top',
546
- Bottom = 'Bottom',
547
- }
548
-
549
- const shiftKeyDownHandlers: KeyDownHandlers = {
550
- ArrowUp: (state) => ({
551
- ...state,
552
- selected: modifyEdge(
553
- state.selected,
554
- state.active,
555
- state.model.data,
556
- Direction.Top
557
- ),
558
- }),
559
- ArrowDown: (state) => ({
560
- ...state,
561
- selected: modifyEdge(
562
- state.selected,
563
- state.active,
564
- state.model.data,
565
- Direction.Bottom
566
- ),
567
- }),
568
- ArrowLeft: (state) => ({
569
- ...state,
570
- selected: modifyEdge(
571
- state.selected,
572
- state.active,
573
- state.model.data,
574
- Direction.Left
575
- ),
576
- }),
577
- ArrowRight: (state) => ({
578
- ...state,
579
- selected: modifyEdge(
580
- state.selected,
581
- state.active,
582
- state.model.data,
583
- Direction.Right
584
- ),
585
- }),
586
- Tab: go(0, -1),
587
- };
588
-
589
- const shiftMetaKeyDownHandlers: KeyDownHandlers = {};
590
- const metaKeyDownHandlers: KeyDownHandlers = {};
591
-
592
- export function getKeyDownHandler(
593
- state: Types.StoreState,
594
- event: React.KeyboardEvent
595
- ): KeyDownHandler | undefined {
596
- const { key } = event;
597
- let handlers;
598
- // Order matters
599
- if (state.mode === 'edit') {
600
- if (event.shiftKey) {
601
- handlers = editShiftKeyDownHandlers;
602
- } else {
603
- handlers = editKeyDownHandlers;
604
- }
605
- } else if (event.shiftKey && event.metaKey) {
606
- handlers = shiftMetaKeyDownHandlers;
607
- } else if (event.shiftKey) {
608
- handlers = shiftKeyDownHandlers;
609
- } else if (event.metaKey) {
610
- handlers = metaKeyDownHandlers;
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 = keyDownHandlers;
601
+ handlers = editKeyDownHandlers;
613
602
  }
614
-
615
- return handlers[key];
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
- /** Returns whether the reducer has a handler for the given keydown event */
619
- export function hasKeyDownHandler(
620
- state: Types.StoreState,
621
- event: React.KeyboardEvent
622
- ): boolean {
623
- return getKeyDownHandler(state, event) !== undefined;
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
- /** Returns whether the active cell is read only */
627
- export function isActiveReadOnly(state: Types.StoreState): boolean {
628
- const activeCell = getActive(state);
629
- return Boolean(activeCell?.readOnly);
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
- /** Gets active cell from given state */
633
- export function getActive(state: Types.StoreState): Types.CellBase | null {
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
- /** Modify given edge according to given active point and data */
639
- export function modifyEdge<T extends Selection>(
640
- selection: T,
641
- active: Point.Point | null,
642
- data: Matrix.Matrix<unknown>,
643
- direction: Direction
644
- ): T {
645
- if (!active) {
646
- return selection;
647
- }
648
- if (selection instanceof RangeSelection) {
649
- const nextSelection = modifyRangeSelectionEdge(
650
- selection,
651
- active,
652
- data,
653
- direction
654
- );
655
- // @ts-expect-error
656
- return nextSelection;
657
- }
658
- if (selection instanceof EntireColumnsSelection) {
659
- // @ts-expect-error
660
- return modifyEntireColumnsSelection(selection, active, data, direction);
661
- }
662
- if (selection instanceof EntireRowsSelection) {
663
- // @ts-expect-error
664
- return modifyEntireRowsSelection(selection, active, data, direction);
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
- export function modifyRangeSelectionEdge(
670
- rangeSelection: RangeSelection,
671
- active: Point.Point,
672
- data: Matrix.Matrix<unknown>,
673
- edge: Direction
674
- ): RangeSelection {
675
- const field =
676
- edge === Direction.Left || edge === Direction.Right ? 'column' : 'row';
677
-
678
- const key =
679
- edge === Direction.Left || edge === Direction.Top ? 'start' : 'end';
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
- export function modifyEntireRowsSelection(
702
- selection: EntireRowsSelection,
703
- active: Point.Point,
704
- data: Matrix.Matrix<unknown>,
705
- edge: Direction
706
- ): EntireRowsSelection {
707
- if (edge === Direction.Left || edge === Direction.Right) {
708
- return selection;
709
- }
710
- const delta = edge === Direction.Top ? -1 : 1;
711
- const property = edge === Direction.Top ? 'start' : 'end';
712
- const oppositeProperty = property === 'start' ? 'end' : 'start';
713
- const newSelectionData = { ...selection };
714
- if (
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
- export function modifyEntireColumnsSelection(
731
- selection: EntireColumnsSelection,
732
- active: Point.Point,
733
- data: Matrix.Matrix<unknown>,
734
- edge: Direction
735
- ): EntireColumnsSelection {
736
- if (edge === Direction.Top || edge === Direction.Bottom) {
737
- return selection;
738
- }
739
- const delta = edge === Direction.Left ? -1 : 1;
740
- const property = edge === Direction.Left ? 'start' : 'end';
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
+ }