pixel-react 1.2.0 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. package/lib/components/AppHeader/types.d.ts +11 -2
  2. package/lib/components/Avatar/Avatar.d.ts +5 -0
  3. package/lib/components/Avatar/Avatar.stories.d.ts +10 -0
  4. package/lib/components/Avatar/index.d.ts +1 -0
  5. package/lib/components/Avatar/types.d.ts +26 -0
  6. package/lib/components/ExcelFile/ExcelFile/Excel/ActiveCell.d.ts +2 -2
  7. package/lib/components/ExcelFile/ExcelFile/Excel/ColumnIndicator.d.ts +2 -2
  8. package/lib/components/ExcelFile/ExcelFile/Excel/Copied.d.ts +1 -1
  9. package/lib/components/ExcelFile/ExcelFile/Excel/CornerIndicator.d.ts +2 -2
  10. package/lib/components/ExcelFile/ExcelFile/Excel/DataEditor.d.ts +2 -2
  11. package/lib/components/ExcelFile/ExcelFile/Excel/DataViewer.d.ts +2 -2
  12. package/lib/components/ExcelFile/ExcelFile/Excel/FloatingRect.d.ts +2 -2
  13. package/lib/components/ExcelFile/ExcelFile/Excel/HeaderRow.d.ts +1 -1
  14. package/lib/components/ExcelFile/ExcelFile/Excel/Row.d.ts +1 -1
  15. package/lib/components/ExcelFile/ExcelFile/Excel/RowIndicator.d.ts +2 -2
  16. package/lib/components/ExcelFile/ExcelFile/Excel/Selected.d.ts +1 -1
  17. package/lib/components/ExcelFile/ExcelFile/Excel/Spreadsheet.d.ts +6 -7
  18. package/lib/components/ExcelFile/ExcelFile/Excel/Table.d.ts +1 -1
  19. package/lib/components/ExcelFile/ExcelFile/Excel/actions.d.ts +49 -5
  20. package/lib/components/ExcelFile/ExcelFile/Excel/context.d.ts +3 -3
  21. package/lib/components/ExcelFile/ExcelFile/Excel/engine/engine.d.ts +5 -5
  22. package/lib/components/ExcelFile/ExcelFile/Excel/engine/formula.d.ts +6 -6
  23. package/lib/components/ExcelFile/ExcelFile/Excel/engine/index.d.ts +2 -2
  24. package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-graph.d.ts +2 -2
  25. package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-hash.d.ts +1 -1
  26. package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-set.d.ts +1 -1
  27. package/lib/components/ExcelFile/ExcelFile/Excel/index.d.ts +11 -11
  28. package/lib/components/ExcelFile/ExcelFile/Excel/matrix.d.ts +1 -1
  29. package/lib/components/ExcelFile/ExcelFile/Excel/point-range.d.ts +1 -1
  30. package/lib/components/ExcelFile/ExcelFile/Excel/reducer.d.ts +5 -5
  31. package/lib/components/ExcelFile/ExcelFile/Excel/selection.d.ts +3 -3
  32. package/lib/components/ExcelFile/ExcelFile/Excel/types.d.ts +11 -48
  33. package/lib/components/ExcelFile/ExcelFile/Excel/use-dispatch.d.ts +1 -1
  34. package/lib/components/ExcelFile/ExcelFile/Excel/use-selector.d.ts +1 -1
  35. package/lib/components/ExcelFile/ExcelFile/Excel/util.d.ts +11 -12
  36. package/lib/components/ExcelFile/ExcelFile/ExcelFile.d.ts +16 -0
  37. package/lib/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.d.ts +0 -3
  38. package/lib/components/ExcelFile/ExcelToolBar/ExcelToolBar.d.ts +12 -0
  39. package/lib/components/ExcelFile/Types.d.ts +2 -49
  40. package/lib/components/Form/Form.d.ts +1 -15
  41. package/lib/components/Form/Form.stories.d.ts +6 -5
  42. package/lib/components/Form/Forms.d.ts +8 -0
  43. package/lib/components/Form/index.d.ts +1 -1
  44. package/lib/components/InputWithDropdown/types.d.ts +1 -1
  45. package/lib/components/LabelEditTextField/LabelEditTextField.d.ts +5 -0
  46. package/lib/components/LabelEditTextField/LabelEditTextField.stories.d.ts +11 -0
  47. package/lib/components/LabelEditTextField/index.d.ts +1 -0
  48. package/lib/components/LabelEditTextField/types.d.ts +38 -0
  49. package/lib/components/MenuOption/types.d.ts +7 -7
  50. package/lib/components/ModulesChip/ModuleChip.d.ts +4 -0
  51. package/lib/components/ModulesChip/ModuleChip.stories.d.ts +6 -0
  52. package/lib/components/ModulesChip/index.d.ts +1 -0
  53. package/lib/components/ModulesChip/types.d.ts +14 -0
  54. package/lib/components/MultiSelect/MultiSelectTypes.d.ts +1 -0
  55. package/lib/components/Select/Select.d.ts +1 -1
  56. package/lib/components/Select/components/Dropdown/Dropdown.d.ts +1 -1
  57. package/lib/components/Select/components/Dropdown/dropdownTypes.d.ts +2 -0
  58. package/lib/components/Select/types.d.ts +11 -4
  59. package/lib/components/Toastify/Toastify.d.ts +8 -0
  60. package/lib/components/Toastify/Toastify.stories.d.ts +6 -0
  61. package/lib/components/Toastify/index.d.ts +1 -0
  62. package/lib/components/Toastify/types.d.ts +7 -0
  63. package/lib/components/Tooltip/types.d.ts +6 -0
  64. package/lib/components/Typography/types.d.ts +1 -0
  65. package/lib/index.d.ts +130 -29
  66. package/lib/index.esm.js +26882 -872
  67. package/lib/index.esm.js.map +1 -1
  68. package/lib/index.js +26881 -866
  69. package/lib/index.js.map +1 -1
  70. package/lib/tsconfig.tsbuildinfo +1 -1
  71. package/lib/utils/getSelectOptionValue/getSelectOptionValue.d.ts +8 -0
  72. package/package.json +1 -1
  73. package/src/StyleGuide/ColorPalette/colorPaletteList.ts +10 -0
  74. package/src/assets/Themes/BaseTheme.scss +10 -1
  75. package/src/assets/Themes/DarkTheme.scss +19 -8
  76. package/src/assets/icons/client_profile.svg +4 -0
  77. package/src/assets/icons/fireflink_finder_logo.svg +7 -0
  78. package/src/assets/icons/fireflink_platform.svg +4 -0
  79. package/src/assets/icons/license_expired.svg +20 -0
  80. package/src/components/AppHeader/AppHeader.scss +5 -2
  81. package/src/components/AppHeader/AppHeader.stories.tsx +24 -3
  82. package/src/components/AppHeader/AppHeader.tsx +29 -11
  83. package/src/components/AppHeader/types.ts +11 -3
  84. package/src/components/Avatar/Avatar.scss +24 -0
  85. package/src/components/Avatar/Avatar.stories.tsx +56 -0
  86. package/src/components/Avatar/Avatar.tsx +25 -0
  87. package/src/components/Avatar/index.ts +1 -0
  88. package/src/components/Avatar/types.ts +27 -0
  89. package/src/components/Drawer/Drawer.scss +0 -1
  90. package/src/components/Drawer/Drawer.tsx +1 -1
  91. package/src/components/ExcelFile/ColorBarselector/ColorBarSelector.scss +0 -2
  92. package/src/components/ExcelFile/ContextMenu/ContextMenu.scss +1 -4
  93. package/src/components/ExcelFile/ContextMenu/ContextMenu.tsx +0 -1
  94. package/src/components/ExcelFile/ExcelFile/Excel/ActiveCell.tsx +13 -13
  95. package/src/components/ExcelFile/ExcelFile/Excel/Cell.tsx +13 -12
  96. package/src/components/ExcelFile/ExcelFile/Excel/ColumnIndicator.tsx +40 -32
  97. package/src/components/ExcelFile/ExcelFile/Excel/Copied.tsx +4 -4
  98. package/src/components/ExcelFile/ExcelFile/Excel/CornerIndicator.tsx +10 -10
  99. package/src/components/ExcelFile/ExcelFile/Excel/DataEditor.tsx +5 -5
  100. package/src/components/ExcelFile/ExcelFile/Excel/DataViewer.tsx +10 -10
  101. package/src/components/ExcelFile/ExcelFile/Excel/FloatingRect.tsx +6 -6
  102. package/src/components/ExcelFile/ExcelFile/Excel/HeaderRow.tsx +1 -1
  103. package/src/components/ExcelFile/ExcelFile/Excel/Row.tsx +1 -1
  104. package/src/components/ExcelFile/ExcelFile/Excel/RowIndicator.tsx +34 -27
  105. package/src/components/ExcelFile/ExcelFile/Excel/Selected.tsx +5 -5
  106. package/src/components/ExcelFile/ExcelFile/Excel/{Spreadsheet.css → Spreadsheet.scss} +21 -37
  107. package/src/components/ExcelFile/ExcelFile/Excel/Spreadsheet.tsx +87 -78
  108. package/src/components/ExcelFile/ExcelFile/Excel/Table.tsx +2 -2
  109. package/src/components/ExcelFile/ExcelFile/Excel/actions.ts +121 -31
  110. package/src/components/ExcelFile/ExcelFile/Excel/areModelsEqual.ts +1 -1
  111. package/src/components/ExcelFile/ExcelFile/Excel/context.ts +4 -4
  112. package/src/components/ExcelFile/ExcelFile/Excel/engine/engine.ts +7 -7
  113. package/src/components/ExcelFile/ExcelFile/Excel/engine/formula.ts +11 -11
  114. package/src/components/ExcelFile/ExcelFile/Excel/engine/index.ts +2 -2
  115. package/src/components/ExcelFile/ExcelFile/Excel/engine/point-graph.ts +3 -3
  116. package/src/components/ExcelFile/ExcelFile/Excel/engine/point-hash.ts +2 -2
  117. package/src/components/ExcelFile/ExcelFile/Excel/engine/point-set.ts +2 -2
  118. package/src/components/ExcelFile/ExcelFile/Excel/index.ts +12 -11
  119. package/src/components/ExcelFile/ExcelFile/Excel/matrix.ts +18 -24
  120. package/src/components/ExcelFile/ExcelFile/Excel/point-range.ts +1 -1
  121. package/src/components/ExcelFile/ExcelFile/Excel/reducer.ts +311 -41
  122. package/src/components/ExcelFile/ExcelFile/Excel/selection.ts +5 -5
  123. package/src/components/ExcelFile/ExcelFile/Excel/types.ts +14 -66
  124. package/src/components/ExcelFile/ExcelFile/Excel/typings/fast-formula-parser.d.ts +8 -8
  125. package/src/components/ExcelFile/ExcelFile/Excel/use-dispatch.ts +2 -2
  126. package/src/components/ExcelFile/ExcelFile/Excel/use-selector.ts +3 -3
  127. package/src/components/ExcelFile/ExcelFile/Excel/util.ts +21 -22
  128. package/src/components/ExcelFile/ExcelFile/ExcelFile.scss +0 -3
  129. package/src/components/ExcelFile/ExcelFile/ExcelFile.tsx +45 -403
  130. package/src/components/ExcelFile/ExcelFile.stories.tsx +10 -29
  131. package/src/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.tsx +1 -12
  132. package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.scss +0 -3
  133. package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.tsx +147 -127
  134. package/src/components/ExcelFile/Types.ts +3 -70
  135. package/src/components/ExcelFile/index.ts +1 -1
  136. package/src/components/Form/Form.d.ts +3 -0
  137. package/src/components/Form/Form.scss +31 -4
  138. package/src/components/Form/Form.stories.tsx +172 -138
  139. package/src/components/Form/Form.ts +2 -0
  140. package/src/components/Form/Forms.tsx +25 -0
  141. package/src/components/Form/index.ts +1 -1
  142. package/src/components/Icon/Icons.scss +1 -0
  143. package/src/components/Icon/iconList.ts +8 -0
  144. package/src/components/IconButton/IconButton.scss +1 -1
  145. package/src/components/InputWithDropdown/types.ts +1 -1
  146. package/src/components/LabelEditTextField/LabelEditTextField.scss +85 -0
  147. package/src/components/LabelEditTextField/LabelEditTextField.stories.tsx +136 -0
  148. package/src/components/LabelEditTextField/LabelEditTextField.tsx +207 -0
  149. package/src/components/LabelEditTextField/index.ts +1 -0
  150. package/src/components/LabelEditTextField/types.ts +38 -0
  151. package/src/components/MenuOption/types.ts +7 -6
  152. package/src/components/ModulesChip/ModuleChip.scss +20 -0
  153. package/src/components/ModulesChip/ModuleChip.stories.tsx +41 -0
  154. package/src/components/ModulesChip/ModuleChip.tsx +31 -0
  155. package/src/components/ModulesChip/index.ts +1 -0
  156. package/src/components/ModulesChip/types.ts +14 -0
  157. package/src/components/MultiSelect/Dropdown.tsx +6 -1
  158. package/src/components/MultiSelect/MultiSelect.scss +17 -10
  159. package/src/components/MultiSelect/MultiSelect.stories.tsx +16 -4
  160. package/src/components/MultiSelect/MultiSelect.tsx +11 -4
  161. package/src/components/MultiSelect/MultiSelectTypes.ts +4 -3
  162. package/src/components/Select/Select.scss +4 -0
  163. package/src/components/Select/Select.stories.tsx +5 -3
  164. package/src/components/Select/Select.tsx +15 -7
  165. package/src/components/Select/components/Dropdown/Dropdown.tsx +3 -1
  166. package/src/components/Select/components/Dropdown/dropdownTypes.ts +3 -0
  167. package/src/components/Select/types.ts +12 -5
  168. package/src/components/Toastify/Toastify.stories.tsx +52 -0
  169. package/src/components/Toastify/Toastify.tsx +66 -0
  170. package/src/components/Toastify/index.ts +1 -0
  171. package/src/components/Toastify/types.ts +8 -0
  172. package/src/components/Tooltip/Tooltip.tsx +2 -1
  173. package/src/components/Tooltip/types.ts +6 -0
  174. package/src/components/Typography/Typography.scss +12 -4
  175. package/src/components/Typography/Typography.stories.tsx +2 -0
  176. package/src/components/Typography/Typography.tsx +2 -0
  177. package/src/components/Typography/types.ts +1 -0
  178. package/src/index.ts +12 -2
  179. package/src/utils/getSelectOptionValue/getSelectOptionValue.ts +31 -0
  180. package/src/components/ExcelFile/ChangeExcelStyles.tsx +0 -78
  181. package/src/components/ExcelFile/ImportExcelStyles.tsx +0 -86
  182. package/src/components/Form/Form.tsx +0 -57
@@ -1,7 +1,7 @@
1
- import { PointRange } from "./point-range";
2
- import * as Matrix from "./matrix";
3
- import * as Types from "./types";
4
- import * as Point from "./point";
1
+ import { PointRange } from './point-range';
2
+ import * as Matrix from './matrix';
3
+ import * as Types from './types';
4
+ import * as Point from './point';
5
5
  import {
6
6
  Selection,
7
7
  EmptySelection,
@@ -9,14 +9,14 @@ import {
9
9
  EntireColumnsSelection,
10
10
  EntireRowsSelection,
11
11
  EntireWorksheetSelection,
12
- } from "./selection";
13
- import { isActive } from "./util";
14
- import * as Actions from "./actions";
15
- import { Model, updateCellValue, createFormulaParser } from "./engine";
12
+ } from './selection';
13
+ import { isActive } from './util';
14
+ import * as Actions from './actions';
15
+ import { Model, updateCellValue, createFormulaParser } from './engine';
16
16
 
17
17
  export const INITIAL_STATE: Types.StoreState = {
18
18
  active: null,
19
- mode: "view",
19
+ mode: 'view',
20
20
  rowDimensions: {},
21
21
  columnDimensions: {},
22
22
  lastChanged: null,
@@ -34,6 +34,83 @@ export default function reducer(
34
34
  action: Actions.Action
35
35
  ): Types.StoreState {
36
36
  switch (action.type) {
37
+ case Actions.BOLD: {
38
+ const selectedRange = state.selected.toRange(state.model.data);
39
+ const updatedData = applyBoldToCells(
40
+ state.model.data,
41
+ selectedRange as PointRange
42
+ );
43
+ return {
44
+ ...state,
45
+ model: new Model(state.model.createFormulaParser, updatedData),
46
+ };
47
+ }
48
+
49
+ case Actions.ITALIC: {
50
+ const selectedRange = state.selected.toRange(state.model.data);
51
+ const updatedData = applyItalicToCells(
52
+ state.model.data,
53
+ selectedRange as PointRange
54
+ );
55
+ return {
56
+ ...state,
57
+ model: new Model(state.model.createFormulaParser, updatedData),
58
+ };
59
+ }
60
+
61
+ case Actions.UNDERLINE: {
62
+ const selectedRange = state.selected.toRange(state.model.data);
63
+ const updatedData = applyUnderlineToCells(
64
+ state.model.data,
65
+ selectedRange as PointRange
66
+ );
67
+ return {
68
+ ...state,
69
+ model: new Model(state.model.createFormulaParser, updatedData),
70
+ };
71
+ }
72
+ case Actions.COLOR: {
73
+ const { value } = action.payload;
74
+ const selectedRange = state.selected.toRange(state.model.data);
75
+ const updatedData = applyColorToCells(
76
+ state.model.data,
77
+ selectedRange as PointRange,
78
+ value
79
+ );
80
+
81
+ return {
82
+ ...state,
83
+ model: new Model(state.model.createFormulaParser, updatedData),
84
+ };
85
+ }
86
+
87
+ case Actions.BACKGROUND_COLOR: {
88
+ const { value } = action.payload;
89
+ const selectedRange = state.selected.toRange(state.model.data);
90
+ const updatedData = applyBackgroundColorToCells(
91
+ state.model.data,
92
+ selectedRange as PointRange,
93
+ value
94
+ );
95
+
96
+ return {
97
+ ...state,
98
+ model: new Model(state.model.createFormulaParser, updatedData),
99
+ };
100
+ }
101
+
102
+ case Actions.FORMATE_PAINTER: {
103
+ const selectedRange = state.selected.toRange(state.model.data);
104
+ const updatedData = applyUnderlineToCells(
105
+ state.model.data,
106
+ selectedRange as PointRange
107
+ );
108
+ return {
109
+ ...state,
110
+ model: new Model(state.model.createFormulaParser, updatedData),
111
+ };
112
+ }
113
+
37
114
  case Actions.SET_DATA: {
38
115
  const { data } = action.payload;
39
116
  const nextActive =
@@ -64,7 +141,7 @@ export default function reducer(
64
141
  ? new EntireRowsSelection(active.row, row)
65
142
  : new EntireRowsSelection(row, row),
66
143
  active: extend && active ? active : { ...Point.ORIGIN, row },
67
- mode: "view",
144
+ mode: 'view',
68
145
  };
69
146
  }
70
147
  case Actions.SELECT_ENTIRE_COLUMN: {
@@ -78,7 +155,7 @@ export default function reducer(
78
155
  ? new EntireColumnsSelection(active.column, column)
79
156
  : new EntireColumnsSelection(column, column),
80
157
  active: extend && active ? active : { ...Point.ORIGIN, column },
81
- mode: "view",
158
+ mode: 'view',
82
159
  };
83
160
  }
84
161
  case Actions.SELECT_ENTIRE_WORKSHEET: {
@@ -86,7 +163,7 @@ export default function reducer(
86
163
  ...state,
87
164
  selected: new EntireWorksheetSelection(),
88
165
  active: Point.ORIGIN,
89
- mode: "view",
166
+ mode: 'view',
90
167
  };
91
168
  }
92
169
  case Actions.SET_SELECTION: {
@@ -100,7 +177,7 @@ export default function reducer(
100
177
  ...state,
101
178
  selected: selection,
102
179
  active: active || null,
103
- mode: "view",
180
+ mode: 'view',
104
181
  };
105
182
  }
106
183
  case Actions.SELECT: {
@@ -109,7 +186,7 @@ export default function reducer(
109
186
  return {
110
187
  ...state,
111
188
  selected: new RangeSelection(new PointRange(point, state.active)),
112
- mode: "view",
189
+ mode: 'view',
113
190
  };
114
191
  }
115
192
  return state;
@@ -120,7 +197,7 @@ export default function reducer(
120
197
  ...state,
121
198
  selected: new RangeSelection(new PointRange(point, point)),
122
199
  active: point,
123
- mode: isActive(state.active, point) ? "edit" : "view",
200
+ mode: isActive(state.active, point) ? 'edit' : 'view',
124
201
  };
125
202
  }
126
203
  case Actions.SET_CELL_DATA: {
@@ -174,7 +251,7 @@ export default function reducer(
174
251
  case Actions.PASTE: {
175
252
  const { data: text } = action.payload;
176
253
  const { active } = state;
177
-
254
+
178
255
  if (!active) {
179
256
  return state;
180
257
  }
@@ -189,7 +266,7 @@ export default function reducer(
189
266
  state.cut && state.copied
190
267
  ? Matrix.unset(state.copied.start, state.model.data)
191
268
  : state.model.data;
192
- const commit: Types.StoreState["lastCommit"] = [];
269
+ const commit: Types.StoreState['lastCommit'] = [];
193
270
  for (const point of selectedRange || []) {
194
271
  const currentCell = Matrix.get(point, state.model.data);
195
272
  commit.push({
@@ -205,7 +282,7 @@ export default function reducer(
205
282
  copied: null,
206
283
  cut: false,
207
284
  hasPasted: true,
208
- mode: "view",
285
+ mode: 'view',
209
286
  lastCommit: commit,
210
287
  };
211
288
  }
@@ -217,8 +294,8 @@ export default function reducer(
217
294
  const paddedData = Matrix.pad(state.model.data, requiredSize);
218
295
 
219
296
  let acc: {
220
- data: Types.StoreState["model"]["data"];
221
- commit: Types.StoreState["lastCommit"];
297
+ data: Types.StoreState['model']['data'];
298
+ commit: Types.StoreState['lastCommit'];
222
299
  } = { data: paddedData, commit: [] };
223
300
  for (const [point, cell] of Matrix.entries(copied)) {
224
301
  let commit = acc.commit || [];
@@ -275,7 +352,7 @@ export default function reducer(
275
352
  copied: null,
276
353
  cut: false,
277
354
  hasPasted: true,
278
- mode: "view",
355
+ mode: 'view',
279
356
  lastCommit: acc.commit,
280
357
  };
281
358
  }
@@ -301,7 +378,7 @@ export default function reducer(
301
378
  if (isActiveReadOnly(state) || event.metaKey) {
302
379
  return state;
303
380
  }
304
- if (state.mode === "view" && state.active) {
381
+ if (state.mode === 'view' && state.active) {
305
382
  const selectedRange = state.selected.toRange(state.model.data);
306
383
  if (selectedRange?.size() === 1) {
307
384
  return edit(clear(state));
@@ -334,7 +411,7 @@ export default function reducer(
334
411
  }
335
412
 
336
413
  default:
337
- throw new Error("Unknown action");
414
+ throw new Error('Unknown action');
338
415
  }
339
416
  }
340
417
 
@@ -350,11 +427,204 @@ export default function reducer(
350
427
 
351
428
  // // Shared reducers
352
429
 
430
+ function applyBoldToCells(
431
+ currentData: Matrix.Matrix<Types.CellBase<any>>,
432
+ selectedRange: PointRange
433
+ ): Matrix.Matrix<Types.CellBase<any>> {
434
+ const { start, end } = selectedRange;
435
+
436
+ let updatedData = currentData;
437
+
438
+ for (let row = start.row; row <= end.row; row++) {
439
+ for (let col = start.column; col <= end.column; col++) {
440
+ const currentCell = Matrix.get({ row, column: col }, updatedData);
441
+
442
+ if (!currentCell) {
443
+ continue;
444
+ }
445
+
446
+ const updatedCell = {
447
+ ...currentCell,
448
+ style: {
449
+ ...currentCell.style,
450
+ fontWeight: 'bold',
451
+ },
452
+ };
453
+
454
+ updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
455
+ }
456
+ }
457
+
458
+ return updatedData;
459
+ }
460
+
461
+ function applyItalicToCells(
462
+ currentData: Matrix.Matrix<Types.CellBase<any>>,
463
+ selectedRange: PointRange
464
+ ): Matrix.Matrix<Types.CellBase<any>> {
465
+ const { start, end } = selectedRange;
466
+
467
+ let updatedData = currentData;
468
+
469
+ for (let row = start.row; row <= end.row; row++) {
470
+ for (let col = start.column; col <= end.column; col++) {
471
+ const currentCell = Matrix.get({ row, column: col }, updatedData);
472
+
473
+ if (!currentCell) {
474
+ continue;
475
+ }
476
+
477
+ const updatedCell = {
478
+ ...currentCell,
479
+ style: {
480
+ ...currentCell.style,
481
+ fontStyle: 'italic',
482
+ },
483
+ };
484
+
485
+ updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
486
+ }
487
+ }
488
+
489
+ return updatedData;
490
+ }
491
+
492
+ function applyUnderlineToCells(
493
+ currentData: Matrix.Matrix<Types.CellBase<any>>,
494
+ selectedRange: PointRange
495
+ ): Matrix.Matrix<Types.CellBase<any>> {
496
+ const { start, end } = selectedRange;
497
+
498
+ let updatedData = currentData;
499
+
500
+ for (let row = start.row; row <= end.row; row++) {
501
+ for (let col = start.column; col <= end.column; col++) {
502
+ const currentCell = Matrix.get({ row, column: col }, updatedData);
503
+
504
+ if (!currentCell) {
505
+ continue;
506
+ }
507
+
508
+ const updatedCell = {
509
+ ...currentCell,
510
+ style: {
511
+ ...currentCell.style,
512
+ textDecoration: 'underline',
513
+ },
514
+ };
515
+
516
+ updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
517
+ }
518
+ }
519
+
520
+ return updatedData;
521
+ }
522
+
523
+ function isValidHexColor(color: string): boolean {
524
+ if (color.length !== 6) {
525
+ return false;
526
+ }
527
+
528
+ const hexChars = '0123456789ABCDEFabcdef';
529
+ for (let i = 1; i < color.length; i++) {
530
+ console.log(typeof color[i]);
531
+
532
+ if (!hexChars.includes(color[i] as string)) {
533
+ return false;
534
+ }
535
+ }
536
+
537
+ return true;
538
+ }
539
+
540
+ function applyColorToCells(
541
+ currentData: Matrix.Matrix<Types.CellBase<any>>,
542
+ selectedRange: PointRange | null,
543
+ color: string
544
+ ): Matrix.Matrix<Types.CellBase<any>> {
545
+ if (!selectedRange) {
546
+ return currentData;
547
+ }
548
+
549
+ const { start, end } = selectedRange;
550
+
551
+ let updatedData = currentData;
552
+
553
+ const isHex = isValidHexColor(color);
554
+
555
+ const applyColor = isHex ? `#${color}` : color;
556
+
557
+ for (let row = start.row; row <= end.row; row++) {
558
+ for (let col = start.column; col <= end.column; col++) {
559
+ const currentCell = Matrix.get({ row, column: col }, updatedData);
560
+
561
+ if (!currentCell) {
562
+ continue;
563
+ }
564
+
565
+ const updatedCell = {
566
+ ...currentCell,
567
+ style: {
568
+ ...currentCell.style,
569
+ color: applyColor,
570
+ },
571
+ };
572
+
573
+ updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
574
+ }
575
+ }
576
+
577
+ return updatedData;
578
+ }
579
+
580
+ function applyBackgroundColorToCells(
581
+ currentData: Matrix.Matrix<Types.CellBase<any>>,
582
+ selectedRange: PointRange | null,
583
+ backgroundColor: string
584
+ ): Matrix.Matrix<Types.CellBase<any>> {
585
+ if (selectedRange) {
586
+ const { start, end } = selectedRange;
587
+
588
+ let updatedData = currentData;
589
+
590
+ const isHex = isValidHexColor(backgroundColor);
591
+
592
+ const applyColor = isHex ? `#${backgroundColor}` : backgroundColor;
593
+
594
+ for (let row = start.row; row <= end.row; row++) {
595
+ for (let col = start.column; col <= end.column; col++) {
596
+ const currentCell = Matrix.get({ row, column: col }, updatedData);
597
+
598
+ if (!currentCell) {
599
+ continue;
600
+ }
601
+
602
+ const updatedCell = {
603
+ ...currentCell,
604
+ style: {
605
+ ...currentCell.style,
606
+ backgroundColor: applyColor,
607
+ },
608
+ };
609
+
610
+ updatedData = Matrix.set(
611
+ { row, column: col },
612
+ updatedCell,
613
+ updatedData
614
+ );
615
+ }
616
+ }
617
+
618
+ return updatedData;
619
+ }
620
+ return currentData;
621
+ }
622
+
353
623
  function edit(state: Types.StoreState): Types.StoreState {
354
624
  if (isActiveReadOnly(state)) {
355
625
  return state;
356
626
  }
357
- return { ...state, mode: "edit" };
627
+ return { ...state, mode: 'edit' };
358
628
  }
359
629
 
360
630
  function clear(state: Types.StoreState): Types.StoreState {
@@ -398,7 +668,7 @@ function blur(state: Types.StoreState): Types.StoreState {
398
668
  }
399
669
 
400
670
  function view(state: Types.StoreState): Types.StoreState {
401
- return { ...state, mode: "view" };
671
+ return { ...state, mode: 'view' };
402
672
  }
403
673
 
404
674
  function commit(changes: Types.CommitChanges): Partial<Types.StoreState> {
@@ -421,13 +691,13 @@ export const go =
421
691
  column: (state.active.column + columnDelta) % size.columns,
422
692
  };
423
693
  if (!Matrix.has(nextActive, state.model.data)) {
424
- return { ...state, mode: "view" };
694
+ return { ...state, mode: 'view' };
425
695
  }
426
696
  return {
427
697
  ...state,
428
698
  active: nextActive,
429
699
  selected: new RangeSelection(new PointRange(nextActive, nextActive)),
430
- mode: "view",
700
+ mode: 'view',
431
701
  };
432
702
  };
433
703
 
@@ -439,7 +709,7 @@ export type KeyDownHandler = (
439
709
  ) => Types.StoreState | void;
440
710
 
441
711
  type KeyDownHandlers = {
442
- [K in string]: KeyDownHandler|undefined;
712
+ [K in string]: KeyDownHandler | undefined;
443
713
  };
444
714
 
445
715
  const keyDownHandlers: KeyDownHandlers = {
@@ -465,10 +735,10 @@ const editShiftKeyDownHandlers: KeyDownHandlers = {
465
735
  };
466
736
 
467
737
  export enum Direction {
468
- Left = "Left",
469
- Right = "Right",
470
- Top = "Top",
471
- Bottom = "Bottom",
738
+ Left = 'Left',
739
+ Right = 'Right',
740
+ Top = 'Top',
741
+ Bottom = 'Bottom',
472
742
  }
473
743
 
474
744
  const shiftKeyDownHandlers: KeyDownHandlers = {
@@ -521,7 +791,7 @@ export function getKeyDownHandler(
521
791
  const { key } = event;
522
792
  let handlers;
523
793
  // Order matters
524
- if (state.mode === "edit") {
794
+ if (state.mode === 'edit') {
525
795
  if (event.shiftKey) {
526
796
  handlers = editShiftKeyDownHandlers;
527
797
  } else {
@@ -598,18 +868,18 @@ export function modifyRangeSelectionEdge(
598
868
  edge: Direction
599
869
  ): RangeSelection {
600
870
  const field =
601
- edge === Direction.Left || edge === Direction.Right ? "column" : "row";
871
+ edge === Direction.Left || edge === Direction.Right ? 'column' : 'row';
602
872
 
603
873
  const key =
604
- edge === Direction.Left || edge === Direction.Top ? "start" : "end";
605
- const delta = key === "start" ? -1 : 1;
874
+ edge === Direction.Left || edge === Direction.Top ? 'start' : 'end';
875
+ const delta = key === 'start' ? -1 : 1;
606
876
 
607
877
  const edgeOffsets = rangeSelection.range.has({
608
878
  ...active,
609
879
  [field]: active[field] + delta * -1,
610
880
  });
611
881
 
612
- const keyToModify = edgeOffsets ? (key === "start" ? "end" : "start") : key;
882
+ const keyToModify = edgeOffsets ? (key === 'start' ? 'end' : 'start') : key;
613
883
 
614
884
  const nextRange = new PointRange(
615
885
  rangeSelection.range.start,
@@ -633,8 +903,8 @@ export function modifyEntireRowsSelection(
633
903
  return selection;
634
904
  }
635
905
  const delta = edge === Direction.Top ? -1 : 1;
636
- const property = edge === Direction.Top ? "start" : "end";
637
- const oppositeProperty = property === "start" ? "end" : "start";
906
+ const property = edge === Direction.Top ? 'start' : 'end';
907
+ const oppositeProperty = property === 'start' ? 'end' : 'start';
638
908
  const newSelectionData = { ...selection };
639
909
  if (
640
910
  edge === Direction.Top
@@ -662,8 +932,8 @@ export function modifyEntireColumnsSelection(
662
932
  return selection;
663
933
  }
664
934
  const delta = edge === Direction.Left ? -1 : 1;
665
- const property = edge === Direction.Left ? "start" : "end";
666
- const oppositeProperty = property === "start" ? "end" : "start";
935
+ const property = edge === Direction.Left ? 'start' : 'end';
936
+ const oppositeProperty = property === 'start' ? 'end' : 'start';
667
937
  const newSelectionData = { ...selection };
668
938
  if (
669
939
  edge === Direction.Left
@@ -1,6 +1,6 @@
1
- import { PointRange } from "./point-range";
2
- import * as Point from "./point";
3
- import * as Matrix from "./matrix";
1
+ import { PointRange } from './point-range';
2
+ import * as Point from './point';
3
+ import * as Matrix from './matrix';
4
4
 
5
5
  /** Selection from a spreadsheet */
6
6
  export abstract class Selection {
@@ -142,10 +142,10 @@ export abstract class EntireAxisSelection extends EntireSelection {
142
142
  */
143
143
  constructor(start: number, end: number) {
144
144
  if (!isIndex(start)) {
145
- throw new InvalidIndexError("start");
145
+ throw new InvalidIndexError('start');
146
146
  }
147
147
  if (!isIndex(end)) {
148
- throw new InvalidIndexError("end");
148
+ throw new InvalidIndexError('end');
149
149
  }
150
150
  super();
151
151
  this.start = Math.min(start, end);
@@ -1,10 +1,10 @@
1
- import * as React from "react";
2
- import FormulaParser from "fast-formula-parser";
3
- import { Point } from "./point";
4
- import { Selection } from "./selection";
5
- import { Model } from "./engine";
6
- import { PointRange } from "./point-range";
7
- import { Matrix } from "./matrix";
1
+ import * as React from 'react';
2
+ import FormulaParser from 'fast-formula-parser';
3
+ import { Point } from './point';
4
+ import { Selection } from './selection';
5
+ import { Model } from './engine';
6
+ import { PointRange } from './point-range';
7
+ import { Matrix } from './matrix';
8
8
 
9
9
  /** The base type of cell data in Spreadsheet */
10
10
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -15,68 +15,16 @@ export type CellBase<Value = any> = {
15
15
  className?: string;
16
16
  /** The value of the cell */
17
17
  value: Value;
18
- // style?: React.CSSProperties; // or any other relevant type
19
- style?: CellStyle;
20
- type?: boolean; // or any other relevant type
18
+ // style?: React.CSSProperties;
19
+ style?: React.CSSProperties | undefined;
20
+ //type? to check the style is altered or not
21
+ type?: boolean;
21
22
  /** Custom component to render when the cell is edited, if not defined would default to the component defined for the Spreadsheet */
22
23
  DataEditor?: DataEditorComponent<CellBase<Value>>;
23
24
  /** Custom component to render when the cell is viewed, if not defined would default to the component defined for the Spreadsheet */
24
25
  DataViewer?: DataViewerComponent<CellBase<Value>>;
25
26
  };
26
27
 
27
- interface CellStyle {
28
- /** Font name for the cell text */
29
- name?: string;
30
-
31
- /** Font size of the cell text */
32
- size?: number;
33
-
34
- position?:string;
35
-
36
-
37
- /** Whether the text is bold */
38
- bold?: boolean;
39
-
40
- /** Whether the text is italicized */
41
- italic?: boolean;
42
-
43
- /** Text color in the cell (hex code) */
44
- color?: string;
45
-
46
- /** Background color of the cell (hex code) */
47
- backgroundColor?: string;
48
-
49
- /** Border color of the cell (hex code) */
50
- borderColor?: string;
51
-
52
- /** Border styles for each side of the cell */
53
- border?: {
54
- /** Border style for the top side of the cell */
55
- top: string;
56
-
57
- /** Border style for the bottom side of the cell */
58
- bottom: string;
59
-
60
- /** Border style for the left side of the cell */
61
- left: string;
62
-
63
- /** Border style for the right side of the cell */
64
- right: string;
65
- };
66
-
67
- /** Text alignment and wrapping properties */
68
- alignment?: {
69
- /** Horizontal text alignment ('left', 'center', or 'right') */
70
- horizontal: string;
71
-
72
- /** Vertical text alignment ('top', 'middle', or 'bottom') */
73
- vertical: string;
74
-
75
- /** Whether the text is wrapped within the cell */
76
- wrapText: boolean;
77
- };
78
- }
79
-
80
28
  /**
81
29
  * A cell with it's coordinates
82
30
  * @deprecated the component does not use cell descriptors anymore. Instead it passes cell point and cell value explicitly.
@@ -87,7 +35,7 @@ export type CellDescriptor<Cell extends CellBase> = {
87
35
  } & Point;
88
36
 
89
37
  /** The spreadsheet's write mode */
90
- export type Mode = "view" | "edit";
38
+ export type Mode = 'view' | 'edit';
91
39
 
92
40
  /** Dimensions of an element */
93
41
  export type Dimensions = {
@@ -109,10 +57,10 @@ export type StoreState<Cell extends CellBase = CellBase> = {
109
57
  cut: boolean;
110
58
  active: Point | null;
111
59
  mode: Mode;
112
- rowDimensions: Record<number, Pick<Dimensions, "height" | "top"> | undefined>;
60
+ rowDimensions: Record<number, Pick<Dimensions, 'height' | 'top'> | undefined>;
113
61
  columnDimensions: Record<
114
62
  number,
115
- Pick<Dimensions, "width" | "left"> | undefined
63
+ Pick<Dimensions, 'width' | 'left'> | undefined
116
64
  >;
117
65
  dragging: boolean;
118
66
  lastChanged: Point | null;
@@ -1,4 +1,4 @@
1
- declare module "fast-formula-parser" {
1
+ declare module 'fast-formula-parser' {
2
2
  export type CellCoord = {
3
3
  row: number;
4
4
  col: number;
@@ -34,13 +34,13 @@ declare module "fast-formula-parser" {
34
34
  /** Return the formula error in string representation. */
35
35
  toString(): string;
36
36
 
37
- static DIV0 = "#DIV/0!";
38
- static NA = "#N/A";
39
- static NAME = "#NAME?";
40
- static NULL = "#NULL!";
41
- static NUM = "#NUM!";
42
- static REF = "#REF!";
43
- static VALUE = "#VALUE!";
37
+ static DIV0 = '#DIV/0!';
38
+ static NA = '#N/A';
39
+ static NAME = '#NAME?';
40
+ static NULL = '#NULL!';
41
+ static NUM = '#NUM!';
42
+ static REF = '#REF!';
43
+ static VALUE = '#VALUE!';
44
44
  }
45
45
 
46
46
  export default class FormulaParser {