pixel-react 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) 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/MenuOption/types.d.ts +7 -7
  45. package/lib/components/ModulesChip/ModuleChip.d.ts +4 -0
  46. package/lib/components/ModulesChip/ModuleChip.stories.d.ts +6 -0
  47. package/lib/components/ModulesChip/index.d.ts +1 -0
  48. package/lib/components/ModulesChip/types.d.ts +14 -0
  49. package/lib/components/MultiSelect/MultiSelectTypes.d.ts +1 -0
  50. package/lib/components/Toastify/Toastify.d.ts +8 -0
  51. package/lib/components/Toastify/Toastify.stories.d.ts +6 -0
  52. package/lib/components/Toastify/index.d.ts +1 -0
  53. package/lib/components/Toastify/types.d.ts +7 -0
  54. package/lib/components/Tooltip/types.d.ts +6 -0
  55. package/lib/components/Typography/types.d.ts +1 -0
  56. package/lib/index.d.ts +75 -22
  57. package/lib/index.esm.js +26686 -870
  58. package/lib/index.esm.js.map +1 -1
  59. package/lib/index.js +26684 -864
  60. package/lib/index.js.map +1 -1
  61. package/lib/tsconfig.tsbuildinfo +1 -1
  62. package/package.json +1 -1
  63. package/src/StyleGuide/ColorPalette/colorPaletteList.ts +10 -0
  64. package/src/assets/Themes/BaseTheme.scss +2 -0
  65. package/src/assets/Themes/DarkTheme.scss +2 -0
  66. package/src/assets/icons/client_profile.svg +4 -0
  67. package/src/assets/icons/fireflink_finder_logo.svg +7 -0
  68. package/src/assets/icons/fireflink_platform.svg +4 -0
  69. package/src/assets/icons/license_expired.svg +20 -0
  70. package/src/components/AppHeader/AppHeader.stories.tsx +24 -3
  71. package/src/components/AppHeader/AppHeader.tsx +29 -11
  72. package/src/components/AppHeader/types.ts +11 -3
  73. package/src/components/Avatar/Avatar.scss +24 -0
  74. package/src/components/Avatar/Avatar.stories.tsx +56 -0
  75. package/src/components/Avatar/Avatar.tsx +25 -0
  76. package/src/components/Avatar/index.ts +1 -0
  77. package/src/components/Avatar/types.ts +27 -0
  78. package/src/components/ExcelFile/ColorBarselector/ColorBarSelector.scss +0 -2
  79. package/src/components/ExcelFile/ContextMenu/ContextMenu.scss +1 -4
  80. package/src/components/ExcelFile/ContextMenu/ContextMenu.tsx +0 -1
  81. package/src/components/ExcelFile/ExcelFile/Excel/ActiveCell.tsx +13 -13
  82. package/src/components/ExcelFile/ExcelFile/Excel/Cell.tsx +13 -12
  83. package/src/components/ExcelFile/ExcelFile/Excel/ColumnIndicator.tsx +40 -32
  84. package/src/components/ExcelFile/ExcelFile/Excel/Copied.tsx +4 -4
  85. package/src/components/ExcelFile/ExcelFile/Excel/CornerIndicator.tsx +10 -10
  86. package/src/components/ExcelFile/ExcelFile/Excel/DataEditor.tsx +5 -5
  87. package/src/components/ExcelFile/ExcelFile/Excel/DataViewer.tsx +10 -10
  88. package/src/components/ExcelFile/ExcelFile/Excel/FloatingRect.tsx +6 -6
  89. package/src/components/ExcelFile/ExcelFile/Excel/HeaderRow.tsx +1 -1
  90. package/src/components/ExcelFile/ExcelFile/Excel/Row.tsx +1 -1
  91. package/src/components/ExcelFile/ExcelFile/Excel/RowIndicator.tsx +34 -27
  92. package/src/components/ExcelFile/ExcelFile/Excel/Selected.tsx +5 -5
  93. package/src/components/ExcelFile/ExcelFile/Excel/{Spreadsheet.css → Spreadsheet.scss} +21 -37
  94. package/src/components/ExcelFile/ExcelFile/Excel/Spreadsheet.tsx +87 -78
  95. package/src/components/ExcelFile/ExcelFile/Excel/Table.tsx +2 -2
  96. package/src/components/ExcelFile/ExcelFile/Excel/actions.ts +121 -31
  97. package/src/components/ExcelFile/ExcelFile/Excel/areModelsEqual.ts +1 -1
  98. package/src/components/ExcelFile/ExcelFile/Excel/context.ts +4 -4
  99. package/src/components/ExcelFile/ExcelFile/Excel/engine/engine.ts +7 -7
  100. package/src/components/ExcelFile/ExcelFile/Excel/engine/formula.ts +11 -11
  101. package/src/components/ExcelFile/ExcelFile/Excel/engine/index.ts +2 -2
  102. package/src/components/ExcelFile/ExcelFile/Excel/engine/point-graph.ts +3 -3
  103. package/src/components/ExcelFile/ExcelFile/Excel/engine/point-hash.ts +2 -2
  104. package/src/components/ExcelFile/ExcelFile/Excel/engine/point-set.ts +2 -2
  105. package/src/components/ExcelFile/ExcelFile/Excel/index.ts +12 -11
  106. package/src/components/ExcelFile/ExcelFile/Excel/matrix.ts +18 -24
  107. package/src/components/ExcelFile/ExcelFile/Excel/point-range.ts +1 -1
  108. package/src/components/ExcelFile/ExcelFile/Excel/reducer.ts +311 -41
  109. package/src/components/ExcelFile/ExcelFile/Excel/selection.ts +5 -5
  110. package/src/components/ExcelFile/ExcelFile/Excel/types.ts +14 -66
  111. package/src/components/ExcelFile/ExcelFile/Excel/typings/fast-formula-parser.d.ts +8 -8
  112. package/src/components/ExcelFile/ExcelFile/Excel/use-dispatch.ts +2 -2
  113. package/src/components/ExcelFile/ExcelFile/Excel/use-selector.ts +3 -3
  114. package/src/components/ExcelFile/ExcelFile/Excel/util.ts +21 -22
  115. package/src/components/ExcelFile/ExcelFile/ExcelFile.scss +0 -3
  116. package/src/components/ExcelFile/ExcelFile/ExcelFile.tsx +45 -403
  117. package/src/components/ExcelFile/ExcelFile.stories.tsx +10 -29
  118. package/src/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.tsx +1 -12
  119. package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.scss +0 -3
  120. package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.tsx +147 -127
  121. package/src/components/ExcelFile/Types.ts +3 -70
  122. package/src/components/ExcelFile/index.ts +1 -1
  123. package/src/components/Form/Form.d.ts +3 -0
  124. package/src/components/Form/Form.scss +31 -4
  125. package/src/components/Form/Form.stories.tsx +172 -138
  126. package/src/components/Form/Form.ts +2 -0
  127. package/src/components/Form/Forms.tsx +25 -0
  128. package/src/components/Form/index.ts +1 -1
  129. package/src/components/Icon/iconList.ts +8 -0
  130. package/src/components/IconButton/IconButton.scss +1 -1
  131. package/src/components/MenuOption/types.ts +7 -6
  132. package/src/components/ModulesChip/ModuleChip.scss +20 -0
  133. package/src/components/ModulesChip/ModuleChip.stories.tsx +41 -0
  134. package/src/components/ModulesChip/ModuleChip.tsx +31 -0
  135. package/src/components/ModulesChip/index.ts +1 -0
  136. package/src/components/ModulesChip/types.ts +14 -0
  137. package/src/components/MultiSelect/Dropdown.tsx +6 -1
  138. package/src/components/MultiSelect/MultiSelect.scss +17 -10
  139. package/src/components/MultiSelect/MultiSelect.stories.tsx +16 -4
  140. package/src/components/MultiSelect/MultiSelect.tsx +11 -4
  141. package/src/components/MultiSelect/MultiSelectTypes.ts +4 -3
  142. package/src/components/Select/Select.scss +4 -0
  143. package/src/components/Select/Select.tsx +2 -2
  144. package/src/components/Toastify/Toastify.stories.tsx +52 -0
  145. package/src/components/Toastify/Toastify.tsx +66 -0
  146. package/src/components/Toastify/index.ts +1 -0
  147. package/src/components/Toastify/types.ts +8 -0
  148. package/src/components/Tooltip/Tooltip.tsx +2 -1
  149. package/src/components/Tooltip/types.ts +6 -0
  150. package/src/components/Typography/Typography.scss +12 -4
  151. package/src/components/Typography/Typography.stories.tsx +2 -0
  152. package/src/components/Typography/Typography.tsx +2 -0
  153. package/src/components/Typography/types.ts +1 -0
  154. package/src/index.ts +10 -2
  155. package/src/components/ExcelFile/ChangeExcelStyles.tsx +0 -78
  156. package/src/components/ExcelFile/ImportExcelStyles.tsx +0 -86
  157. package/src/components/Form/Form.tsx +0 -57
@@ -1,4 +1,4 @@
1
- import * as Point from "./point";
1
+ import * as Point from './point';
2
2
 
3
3
  /** A two-dimensional array of given type T in rows and columns */
4
4
  export type Matrix<T> = Array<Array<T | undefined>>;
@@ -65,7 +65,7 @@ export function set<T>(
65
65
  if (nextFirstRow.length <= point.column) {
66
66
  nextFirstRow.length = point.column + 1; // Extend the first row if needed
67
67
  }
68
-
68
+
69
69
  // Set the modified first row back into the matrix
70
70
  nextMatrix[0] = nextFirstRow;
71
71
 
@@ -82,10 +82,8 @@ export function set<T>(
82
82
  return nextMatrix;
83
83
  }
84
84
 
85
-
86
85
  /** Like Matrix.set() but mutates the matrix */
87
86
 
88
-
89
87
  export function mutableSet<T>(
90
88
  point: Point.Point,
91
89
  value: T,
@@ -114,8 +112,6 @@ export function mutableSet<T>(
114
112
  row[point.column] = value;
115
113
  }
116
114
 
117
-
118
-
119
115
  /** Removes the coordinate of matrix */
120
116
  // export function unset<T>(point: Point.Point, matrix: Matrix<T>): Matrix<T> {
121
117
  // if (!has(point, matrix)) {
@@ -155,7 +151,6 @@ export function unset<T>(point: Point.Point, matrix: Matrix<T>): Matrix<T> {
155
151
  return nextMatrix;
156
152
  }
157
153
 
158
-
159
154
  /** Creates an array of values by running each element in collection thru iteratee. */
160
155
  export function map<T, T2>(
161
156
  func: (value: T | undefined, point: Point.Point) => T2,
@@ -187,34 +182,33 @@ export function* entries<T>(
187
182
 
188
183
  export function join(
189
184
  matrix: Matrix<unknown>,
190
- horizontalSeparator = "\t",
191
- verticalSeparator = "\n"
185
+ horizontalSeparator = '\t',
186
+ verticalSeparator = '\n'
192
187
  ): string {
193
- let joined = "";
188
+ let joined = '';
194
189
  const { rows, columns } = getSize(matrix);
195
-
190
+
196
191
  for (let row = 0; row < rows; row++) {
197
192
  if (row) {
198
193
  joined += verticalSeparator;
199
194
  }
200
-
195
+
201
196
  for (let column = 0; column < columns; column++) {
202
197
  if (column) {
203
198
  joined += horizontalSeparator;
204
199
  }
205
-
200
+
206
201
  // Ensure matrix[row] exists and matrix[row][column] is not undefined
207
202
  const cellValue = matrix[row]?.[column];
208
-
203
+
209
204
  // If cellValue is undefined, you can use a fallback value like an empty string
210
- joined += cellValue !== undefined ? String(cellValue) : "";
205
+ joined += cellValue !== undefined ? String(cellValue) : '';
211
206
  }
212
207
  }
213
-
208
+
214
209
  return joined;
215
210
  }
216
211
 
217
-
218
212
  /**
219
213
  * Parses a CSV separated by a horizontalSeparator and verticalSeparator into a
220
214
  * Matrix using a transform function
@@ -222,19 +216,19 @@ export function join(
222
216
  export function split<T>(
223
217
  csv: string,
224
218
  transform: (value: string) => T,
225
- horizontalSeparator = "\t",
219
+ horizontalSeparator = '\t',
226
220
  verticalSeparator: string | RegExp = /\r\n|\n|\r/
227
221
  ): Matrix<T> {
228
222
  // Temporarily replace line breaks inside quotes
229
223
  const replaced = csv.replace(/"([^"]*?)"/g, (_, p1) => {
230
- return p1.replace(/\n/g, "\\n");
224
+ return p1.replace(/\n/g, '\\n');
231
225
  });
232
226
  return replaced.split(verticalSeparator).map((row) =>
233
227
  row
234
228
  .split(horizontalSeparator)
235
229
  .map((line) => {
236
230
  // Restore original line breaks in each line
237
- return line.replace(/\\n/g, "\n");
231
+ return line.replace(/\\n/g, '\n');
238
232
  })
239
233
  .map(transform)
240
234
  );
@@ -246,7 +240,7 @@ export function has(point: Point.Point, matrix: Matrix<unknown>): boolean {
246
240
  if (!firstRow) {
247
241
  return false; // If first row is undefined, return false
248
242
  }
249
-
243
+
250
244
  // Perform validation checks
251
245
  return (
252
246
  point.row >= 0 &&
@@ -258,7 +252,6 @@ export function has(point: Point.Point, matrix: Matrix<unknown>): boolean {
258
252
  );
259
253
  }
260
254
 
261
-
262
255
  /** Counts of the rows and column in a matrix */
263
256
  export type Size = {
264
257
  /** Count of the rows in the matrix */
@@ -372,7 +365,9 @@ export function toArray<T1, T2>(
372
365
  for (let column = 0; column < currentRow.length; column++) {
373
366
  const value = currentRow[column];
374
367
  // If transform is provided, apply it; otherwise, use the value as is
375
- array.push(transform ? transform(value, { row, column }) : value as T2);
368
+ array.push(
369
+ transform ? transform(value, { row, column }) : (value as T2)
370
+ );
376
371
  }
377
372
  }
378
373
  }
@@ -380,7 +375,6 @@ export function toArray<T1, T2>(
380
375
  return array;
381
376
  }
382
377
 
383
-
384
378
  /** Returns the maximum point in the matrix */
385
379
  export function maxPoint(matrix: Matrix<unknown>): Point.Point {
386
380
  const size = getSize(matrix);
@@ -2,7 +2,7 @@
2
2
  * Interface for ranges between two points
3
3
  */
4
4
 
5
- import * as Point from "./point";
5
+ import * as Point from './point';
6
6
 
7
7
  /** Range between two points. Creates a normalized range between two given points */
8
8
  export class PointRange {
@@ -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