pixel-react 1.2.7 → 1.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. package/.yarn/install-state.gz +0 -0
  2. package/lib/components/Drawer/Types.d.ts +23 -12
  3. package/lib/components/{ExcelFile → Excel}/ExcelFile/ExcelFile.d.ts +1 -0
  4. package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/actions.d.ts +39 -10
  5. package/lib/components/Excel/ExcelFile/ExcelFileComponents/reducer.d.ts +4 -0
  6. package/lib/components/Excel/ExcelFile/ExcelFileComponents/reducerFunctions.d.ts +40 -0
  7. package/lib/components/{ExcelFile → Excel}/ExcelToolBar/ExcelToolBar.d.ts +7 -3
  8. package/lib/components/MenuOption/MenuOption.d.ts +1 -1
  9. package/lib/components/MenuOption/types.d.ts +4 -0
  10. package/lib/components/Select/Select.stories.d.ts +1 -0
  11. package/lib/components/Toastify/Toastify.d.ts +5 -4
  12. package/lib/components/Toastify/types.d.ts +1 -0
  13. package/lib/index.d.ts +68 -18
  14. package/lib/index.esm.js +1512 -1089
  15. package/lib/index.esm.js.map +1 -1
  16. package/lib/index.js +1513 -1089
  17. package/lib/index.js.map +1 -1
  18. package/lib/tsconfig.tsbuildinfo +1 -1
  19. package/lib/utils/getSequentialPayload/getSequentialPayload.d.ts +2 -0
  20. package/lib/utils/getSequentialPayload/getSequentialPayload.stories.d.ts +10 -0
  21. package/lib/utils/getSequentialPayload/types.d.ts +30 -0
  22. package/package.json +3 -3
  23. package/src/assets/Themes/BaseTheme.scss +4 -0
  24. package/src/assets/icons/maximize_icon.svg +5 -0
  25. package/src/assets/styles/_fonts.scss +1 -1
  26. package/src/components/AllProjectsDropdown/AllProjectsDropdown.scss +15 -6
  27. package/src/components/AllProjectsDropdown/AllProjectsDropdown.stories.tsx +0 -5
  28. package/src/components/AllProjectsDropdown/AllProjectsDropdown.tsx +20 -10
  29. package/src/components/Drawer/Drawer.scss +1 -0
  30. package/src/components/Drawer/Types.ts +24 -13
  31. package/src/components/Excel/ExcelFile/ExcelFile.scss +62 -0
  32. package/src/components/Excel/ExcelFile/ExcelFile.tsx +312 -0
  33. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/ActiveCell.tsx +2 -2
  34. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Cell.tsx +3 -3
  35. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/ColumnIndicator.tsx +4 -4
  36. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/CornerIndicator.tsx +2 -2
  37. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/DataEditor.tsx +1 -1
  38. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/DataViewer.tsx +3 -3
  39. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/FloatingRect.tsx +4 -4
  40. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/RowIndicator.tsx +4 -4
  41. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Spreadsheet.scss +26 -24
  42. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Spreadsheet.tsx +13 -45
  43. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Table.tsx +1 -1
  44. package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/actions.ts +88 -20
  45. package/src/components/Excel/ExcelFile/ExcelFileComponents/reducer.ts +495 -0
  46. package/src/components/Excel/ExcelFile/ExcelFileComponents/reducerFunctions.ts +758 -0
  47. package/src/components/{ExcelFile → Excel}/ExcelFile.stories.tsx +45 -0
  48. package/src/components/Excel/ExcelToolBar/ExcelToolBar.scss +36 -0
  49. package/src/components/Excel/ExcelToolBar/ExcelToolBar.tsx +346 -0
  50. package/src/components/Form/Form.scss +54 -35
  51. package/src/components/Form/Form.stories.tsx +264 -225
  52. package/src/components/Icon/iconList.ts +2 -1
  53. package/src/components/Input/Input.tsx +0 -1
  54. package/src/components/MenuOption/MenuOption.scss +0 -1
  55. package/src/components/MenuOption/MenuOption.stories.tsx +3 -0
  56. package/src/components/MenuOption/MenuOption.tsx +5 -4
  57. package/src/components/MenuOption/types.ts +4 -0
  58. package/src/components/MultiSelect/MultiSelect.scss +5 -1
  59. package/src/components/MultiSelect/MultiSelect.stories.tsx +17 -13
  60. package/src/components/MultiSelect/MultiSelect.tsx +27 -14
  61. package/src/components/Select/Select.stories.tsx +161 -18
  62. package/src/components/Select/Select.tsx +41 -33
  63. package/src/components/Table/Table.scss +6 -5
  64. package/src/components/Table/Table.stories.tsx +0 -9
  65. package/src/components/Table/Table.tsx +2 -2
  66. package/src/components/TableTree/TableTree.scss +1 -1
  67. package/src/components/TableTree/TableTree.tsx +3 -1
  68. package/src/components/Toastify/Toastify.stories.tsx +29 -10
  69. package/src/components/Toastify/Toastify.tsx +42 -16
  70. package/src/components/Toastify/types.ts +2 -0
  71. package/src/index.ts +4 -2
  72. package/src/utils/getSequentialPayload/getSequentialPayload.stories.tsx +75 -0
  73. package/src/utils/getSequentialPayload/getSequentialPayload.ts +29 -0
  74. package/src/utils/getSequentialPayload/types.ts +35 -0
  75. package/lib/components/AddButton/AddButton.d.ts +0 -5
  76. package/lib/components/AddButton/AddButton.stories.d.ts +0 -6
  77. package/lib/components/AddButton/index.d.ts +0 -1
  78. package/lib/components/AddButton/types.d.ts +0 -4
  79. package/lib/components/ExcelFile/ChangeExcelStyles.d.ts +0 -14
  80. package/lib/components/ExcelFile/ExcelFile/Excel/reducer.d.ts +0 -27
  81. package/lib/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.d.ts +0 -12
  82. package/lib/components/ExcelFile/ImportExcelStyles.d.ts +0 -24
  83. package/lib/utils/find/findAndInsert.d.ts +0 -7
  84. package/lib/utils/find/findAndInsert.stories.d.ts +0 -7
  85. package/src/components/ExcelFile/ExcelFile/Excel/reducer.ts +0 -952
  86. package/src/components/ExcelFile/ExcelFile/ExcelFile.scss +0 -24
  87. package/src/components/ExcelFile/ExcelFile/ExcelFile.tsx +0 -162
  88. package/src/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.scss +0 -16
  89. package/src/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.tsx +0 -68
  90. package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.scss +0 -19
  91. package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.tsx +0 -291
  92. package/src/fonts/Montserrat/Montserrat-Medium.ttf +0 -0
  93. package/src/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  94. package/src/fonts/Montserrat/Montserrat-SemiBold.ttf +0 -0
  95. package/src/fonts/Poppins/Poppins-Black.ttf +0 -0
  96. package/src/fonts/Poppins/Poppins-BlackItalic.ttf +0 -0
  97. package/src/fonts/Poppins/Poppins-BoldItalic.ttf +0 -0
  98. package/src/fonts/Poppins/Poppins-ExtraBold.ttf +0 -0
  99. package/src/fonts/Poppins/Poppins-ExtraBoldItalic.ttf +0 -0
  100. package/src/fonts/Poppins/Poppins-ExtraLight.ttf +0 -0
  101. package/src/fonts/Poppins/Poppins-ExtraLightItalic.ttf +0 -0
  102. package/src/fonts/Poppins/Poppins-Italic.ttf +0 -0
  103. package/src/fonts/Poppins/Poppins-Light.ttf +0 -0
  104. package/src/fonts/Poppins/Poppins-LightItalic.ttf +0 -0
  105. package/src/fonts/Poppins/Poppins-MediumItalic.ttf +0 -0
  106. package/src/fonts/Poppins/Poppins-SemiBoldItalic.ttf +0 -0
  107. package/src/fonts/Poppins/Poppins-Thin.ttf +0 -0
  108. package/src/fonts/Poppins/Poppins-ThinItalic.ttf +0 -0
  109. /package/lib/components/{ExcelFile → Excel}/ColorBarSelector/ColorBarSelector.d.ts +0 -0
  110. /package/lib/components/{ExcelFile → Excel}/ContextMenu/ContextMenu.d.ts +0 -0
  111. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/ActiveCell.d.ts +0 -0
  112. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Cell.d.ts +0 -0
  113. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/ColumnIndicator.d.ts +0 -0
  114. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Copied.d.ts +0 -0
  115. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/CornerIndicator.d.ts +0 -0
  116. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/DataEditor.d.ts +0 -0
  117. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/DataViewer.d.ts +0 -0
  118. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/FloatingRect.d.ts +0 -0
  119. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/HeaderRow.d.ts +0 -0
  120. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Row.d.ts +0 -0
  121. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/RowIndicator.d.ts +0 -0
  122. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Selected.d.ts +0 -0
  123. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Spreadsheet.d.ts +0 -0
  124. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Table.d.ts +0 -0
  125. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/areModelsEqual.d.ts +0 -0
  126. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/context.d.ts +0 -0
  127. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/engine.d.ts +0 -0
  128. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/formula.d.ts +0 -0
  129. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/index.d.ts +0 -0
  130. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/point-graph.d.ts +0 -0
  131. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/point-hash.d.ts +0 -0
  132. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/point-set.d.ts +0 -0
  133. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/index.d.ts +0 -0
  134. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/matrix.d.ts +0 -0
  135. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/point-range.d.ts +0 -0
  136. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/point.d.ts +0 -0
  137. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/selection.d.ts +0 -0
  138. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/types.d.ts +0 -0
  139. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/use-dispatch.d.ts +0 -0
  140. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/use-selector.d.ts +0 -0
  141. /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/util.d.ts +0 -0
  142. /package/lib/components/{ExcelFile → Excel}/ExcelFile.stories.d.ts +0 -0
  143. /package/lib/components/{ExcelFile → Excel}/Types.d.ts +0 -0
  144. /package/lib/components/{ExcelFile → Excel}/index.d.ts +0 -0
  145. /package/src/components/{ExcelFile/ColorBarselector → Excel/ColorBarSelector}/ColorBarSelector.scss +0 -0
  146. /package/src/components/{ExcelFile/ColorBarselector → Excel/ColorBarSelector}/ColorBarSelector.tsx +0 -0
  147. /package/src/components/{ExcelFile → Excel}/ContextMenu/ContextMenu.scss +0 -0
  148. /package/src/components/{ExcelFile → Excel}/ContextMenu/ContextMenu.tsx +0 -0
  149. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Copied.tsx +0 -0
  150. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/HeaderRow.tsx +0 -0
  151. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Row.tsx +0 -0
  152. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Selected.tsx +0 -0
  153. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/areModelsEqual.ts +0 -0
  154. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/context.ts +0 -0
  155. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/engine.ts +0 -0
  156. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/formula.ts +0 -0
  157. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/index.ts +0 -0
  158. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/point-graph.ts +0 -0
  159. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/point-hash.ts +0 -0
  160. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/point-set.ts +0 -0
  161. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/index.ts +0 -0
  162. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/matrix.ts +0 -0
  163. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/point-range.ts +0 -0
  164. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/point.ts +0 -0
  165. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/selection.ts +0 -0
  166. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/types.ts +0 -0
  167. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/typings/fast-formula-parser.d.ts +0 -0
  168. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/use-dispatch.ts +0 -0
  169. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/use-selector.ts +0 -0
  170. /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/util.ts +0 -0
  171. /package/src/components/{ExcelFile → Excel}/Types.ts +0 -0
  172. /package/src/components/{ExcelFile → Excel}/index.ts +0 -0
@@ -0,0 +1,758 @@
1
+ import { PointRange } from './point-range';
2
+ import * as Matrix from './matrix';
3
+ import * as Types from './types';
4
+ import * as Point from './point';
5
+ import {
6
+ Selection,
7
+ EmptySelection,
8
+ RangeSelection,
9
+ EntireColumnsSelection,
10
+ EntireRowsSelection,
11
+ } from './selection';
12
+ import { Model, createFormulaParser } from './engine';
13
+
14
+ 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);
43
+ }
44
+ }
45
+
46
+ return updatedData;
47
+ }
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;
55
+ }
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
+
81
+ return updatedData;
82
+ }
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;
91
+ }
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: {
108
+ ...currentCell.style,
109
+ fontFamily: value,
110
+ },
111
+ };
112
+
113
+ updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
114
+ }
115
+ }
116
+
117
+ return updatedData;
118
+ }
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;
135
+ }
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 = {
150
+ ...currentCell,
151
+ style: {
152
+ ...currentCell.style,
153
+ fontSize: fontSizeInPx,
154
+ },
155
+ };
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 = {
258
+ ...currentCell,
259
+ style: {
260
+ ...currentCell.style,
261
+ textAlign: value as TextAlign,
262
+ },
263
+ };
264
+
265
+ updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
266
+ }
267
+ }
268
+
269
+ return updatedData;
270
+ }
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;
319
+ }
320
+
321
+ export function isValidHexColor(color: string): boolean {
322
+ if (color.length !== 6) {
323
+ return false;
324
+ }
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
+
333
+ return true;
334
+ }
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
+
345
+ const { start, end } = selectedRange;
346
+
347
+ let updatedData = currentData;
348
+
349
+ const isHex = isValidHexColor(color);
350
+
351
+ const applyColor = isHex ? `#${color}` : color;
352
+
353
+ for (let row = start.row; row <= end.row; row++) {
354
+ for (let col = start.column; col <= end.column; col++) {
355
+ const currentCell = Matrix.get({ row, column: col }, updatedData);
356
+
357
+ if (!currentCell) {
358
+ continue;
359
+ }
360
+
361
+ const updatedCell = {
362
+ ...currentCell,
363
+ style: {
364
+ ...currentCell.style,
365
+ color: applyColor,
366
+ },
367
+ };
368
+
369
+ updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
370
+ }
371
+ }
372
+
373
+ return updatedData;
374
+ }
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;
417
+ }
418
+
419
+ export function edit(state: Types.StoreState): Types.StoreState {
420
+ if (isActiveReadOnly(state)) {
421
+ return state;
422
+ }
423
+ return { ...state, mode: 'edit' };
424
+ }
425
+
426
+ export function clear(state: Types.StoreState): Types.StoreState {
427
+ if (!state.active) {
428
+ return state;
429
+ }
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 });
438
+ };
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);
453
+ }
454
+
455
+ return {
456
+ ...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
+ };
498
+ };
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
+ };
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;
611
+ } else {
612
+ handlers = keyDownHandlers;
613
+ }
614
+
615
+ return handlers[key];
616
+ }
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;
624
+ }
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);
630
+ }
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;
636
+ }
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
+ }
666
+ return selection;
667
+ }
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;
699
+ }
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);
728
+ }
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);
757
+ }
758
+