pixel-react 1.2.1 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) 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/Icon/types.d.ts +1 -1
  45. package/lib/components/MenuOption/types.d.ts +7 -7
  46. package/lib/components/MiniModal/MiniModal.stories.d.ts +1 -0
  47. package/lib/components/MiniModal/types.d.ts +6 -6
  48. package/lib/components/ModulesChip/ModuleChip.d.ts +4 -0
  49. package/lib/components/ModulesChip/ModuleChip.stories.d.ts +6 -0
  50. package/lib/components/ModulesChip/index.d.ts +1 -0
  51. package/lib/components/ModulesChip/types.d.ts +14 -0
  52. package/lib/components/MultiSelect/MultiSelectTypes.d.ts +1 -0
  53. package/lib/components/Toastify/Toastify.d.ts +8 -0
  54. package/lib/components/Toastify/Toastify.stories.d.ts +6 -0
  55. package/lib/components/Toastify/index.d.ts +1 -0
  56. package/lib/components/Toastify/types.d.ts +7 -0
  57. package/lib/components/Tooltip/types.d.ts +6 -0
  58. package/lib/components/Typography/types.d.ts +1 -0
  59. package/lib/index.d.ts +84 -31
  60. package/lib/index.esm.js +26720 -881
  61. package/lib/index.esm.js.map +1 -1
  62. package/lib/index.js +26718 -875
  63. package/lib/index.js.map +1 -1
  64. package/lib/tsconfig.tsbuildinfo +1 -1
  65. package/package.json +1 -1
  66. package/src/StyleGuide/ColorPalette/colorPaletteList.ts +10 -0
  67. package/src/assets/Themes/BaseTheme.scss +2 -0
  68. package/src/assets/Themes/DarkTheme.scss +2 -0
  69. package/src/assets/icons/add_testcase.svg +3 -0
  70. package/src/assets/icons/add_variable_icon.svg +3 -4
  71. package/src/assets/icons/attachment_icon.svg +3 -0
  72. package/src/assets/icons/authorization_icon.svg +3 -0
  73. package/src/assets/icons/automation_testcase.svg +4 -0
  74. package/src/assets/icons/back_icon.svg +3 -0
  75. package/src/assets/icons/client_profile.svg +4 -0
  76. package/src/assets/icons/fireflink_finder_logo.svg +7 -0
  77. package/src/assets/icons/fireflink_platform.svg +4 -0
  78. package/src/assets/icons/license_expired.svg +20 -0
  79. package/src/assets/icons/manual_testcase.svg +3 -0
  80. package/src/assets/icons/variable_icon.svg +4 -0
  81. package/src/components/AllProjectsDropdown/AllProjectsDropdown.scss +2 -2
  82. package/src/components/AllProjectsDropdown/AllProjectsDropdown.tsx +1 -1
  83. package/src/components/AppHeader/AppHeader.stories.tsx +24 -3
  84. package/src/components/AppHeader/AppHeader.tsx +29 -11
  85. package/src/components/AppHeader/types.ts +11 -3
  86. package/src/components/Avatar/Avatar.scss +24 -0
  87. package/src/components/Avatar/Avatar.stories.tsx +56 -0
  88. package/src/components/Avatar/Avatar.tsx +25 -0
  89. package/src/components/Avatar/index.ts +1 -0
  90. package/src/components/Avatar/types.ts +27 -0
  91. package/src/components/Button/types.ts +1 -1
  92. package/src/components/ExcelFile/ColorBarselector/ColorBarSelector.scss +0 -2
  93. package/src/components/ExcelFile/ContextMenu/ContextMenu.scss +1 -4
  94. package/src/components/ExcelFile/ContextMenu/ContextMenu.tsx +0 -1
  95. package/src/components/ExcelFile/ExcelFile/Excel/ActiveCell.tsx +13 -13
  96. package/src/components/ExcelFile/ExcelFile/Excel/Cell.tsx +13 -12
  97. package/src/components/ExcelFile/ExcelFile/Excel/ColumnIndicator.tsx +40 -32
  98. package/src/components/ExcelFile/ExcelFile/Excel/Copied.tsx +4 -4
  99. package/src/components/ExcelFile/ExcelFile/Excel/CornerIndicator.tsx +10 -10
  100. package/src/components/ExcelFile/ExcelFile/Excel/DataEditor.tsx +5 -5
  101. package/src/components/ExcelFile/ExcelFile/Excel/DataViewer.tsx +10 -10
  102. package/src/components/ExcelFile/ExcelFile/Excel/FloatingRect.tsx +6 -6
  103. package/src/components/ExcelFile/ExcelFile/Excel/HeaderRow.tsx +1 -1
  104. package/src/components/ExcelFile/ExcelFile/Excel/Row.tsx +1 -1
  105. package/src/components/ExcelFile/ExcelFile/Excel/RowIndicator.tsx +34 -27
  106. package/src/components/ExcelFile/ExcelFile/Excel/Selected.tsx +5 -5
  107. package/src/components/ExcelFile/ExcelFile/Excel/{Spreadsheet.css → Spreadsheet.scss} +21 -37
  108. package/src/components/ExcelFile/ExcelFile/Excel/Spreadsheet.tsx +87 -78
  109. package/src/components/ExcelFile/ExcelFile/Excel/Table.tsx +2 -2
  110. package/src/components/ExcelFile/ExcelFile/Excel/actions.ts +121 -31
  111. package/src/components/ExcelFile/ExcelFile/Excel/areModelsEqual.ts +1 -1
  112. package/src/components/ExcelFile/ExcelFile/Excel/context.ts +4 -4
  113. package/src/components/ExcelFile/ExcelFile/Excel/engine/engine.ts +7 -7
  114. package/src/components/ExcelFile/ExcelFile/Excel/engine/formula.ts +11 -11
  115. package/src/components/ExcelFile/ExcelFile/Excel/engine/index.ts +2 -2
  116. package/src/components/ExcelFile/ExcelFile/Excel/engine/point-graph.ts +3 -3
  117. package/src/components/ExcelFile/ExcelFile/Excel/engine/point-hash.ts +2 -2
  118. package/src/components/ExcelFile/ExcelFile/Excel/engine/point-set.ts +2 -2
  119. package/src/components/ExcelFile/ExcelFile/Excel/index.ts +12 -11
  120. package/src/components/ExcelFile/ExcelFile/Excel/matrix.ts +18 -24
  121. package/src/components/ExcelFile/ExcelFile/Excel/point-range.ts +1 -1
  122. package/src/components/ExcelFile/ExcelFile/Excel/reducer.ts +311 -41
  123. package/src/components/ExcelFile/ExcelFile/Excel/selection.ts +5 -5
  124. package/src/components/ExcelFile/ExcelFile/Excel/types.ts +14 -66
  125. package/src/components/ExcelFile/ExcelFile/Excel/typings/fast-formula-parser.d.ts +8 -8
  126. package/src/components/ExcelFile/ExcelFile/Excel/use-dispatch.ts +2 -2
  127. package/src/components/ExcelFile/ExcelFile/Excel/use-selector.ts +3 -3
  128. package/src/components/ExcelFile/ExcelFile/Excel/util.ts +21 -22
  129. package/src/components/ExcelFile/ExcelFile/ExcelFile.scss +0 -3
  130. package/src/components/ExcelFile/ExcelFile/ExcelFile.tsx +45 -403
  131. package/src/components/ExcelFile/ExcelFile.stories.tsx +10 -29
  132. package/src/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.tsx +1 -12
  133. package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.scss +0 -3
  134. package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.tsx +147 -127
  135. package/src/components/ExcelFile/Types.ts +3 -70
  136. package/src/components/ExcelFile/index.ts +1 -1
  137. package/src/components/Form/Form.d.ts +3 -0
  138. package/src/components/Form/Form.scss +48 -4
  139. package/src/components/Form/Form.stories.tsx +244 -137
  140. package/src/components/Form/Form.ts +2 -0
  141. package/src/components/Form/Forms.tsx +25 -0
  142. package/src/components/Form/index.ts +1 -1
  143. package/src/components/Icon/iconList.ts +23 -0
  144. package/src/components/Icon/types.ts +1 -1
  145. package/src/components/IconButton/IconButton.scss +1 -1
  146. package/src/components/MenuOption/types.ts +7 -6
  147. package/src/components/MiniModal/MiniModal.scss +5 -0
  148. package/src/components/MiniModal/MiniModal.stories.tsx +95 -0
  149. package/src/components/MiniModal/MiniModal.tsx +11 -6
  150. package/src/components/MiniModal/types.ts +6 -6
  151. package/src/components/ModulesChip/ModuleChip.scss +20 -0
  152. package/src/components/ModulesChip/ModuleChip.stories.tsx +41 -0
  153. package/src/components/ModulesChip/ModuleChip.tsx +31 -0
  154. package/src/components/ModulesChip/index.ts +1 -0
  155. package/src/components/ModulesChip/types.ts +14 -0
  156. package/src/components/MultiSelect/Dropdown.tsx +6 -1
  157. package/src/components/MultiSelect/MultiSelect.scss +17 -10
  158. package/src/components/MultiSelect/MultiSelect.stories.tsx +16 -4
  159. package/src/components/MultiSelect/MultiSelect.tsx +11 -4
  160. package/src/components/MultiSelect/MultiSelectTypes.ts +4 -3
  161. package/src/components/Select/Select.scss +4 -0
  162. package/src/components/Select/Select.tsx +2 -2
  163. package/src/components/Toastify/Toastify.stories.tsx +52 -0
  164. package/src/components/Toastify/Toastify.tsx +66 -0
  165. package/src/components/Toastify/index.ts +1 -0
  166. package/src/components/Toastify/types.ts +8 -0
  167. package/src/components/Tooltip/Tooltip.tsx +2 -1
  168. package/src/components/Tooltip/types.ts +6 -0
  169. package/src/components/Typography/Typography.scss +12 -4
  170. package/src/components/Typography/Typography.stories.tsx +2 -0
  171. package/src/components/Typography/Typography.tsx +2 -0
  172. package/src/components/Typography/types.ts +1 -0
  173. package/src/index.ts +9 -1
  174. package/src/components/ExcelFile/ChangeExcelStyles.tsx +0 -78
  175. package/src/components/ExcelFile/ImportExcelStyles.tsx +0 -86
  176. package/src/components/Form/Form.tsx +0 -57
@@ -1,5 +1,5 @@
1
- import { useContextSelector } from "use-context-selector";
2
- import context, { Dispatch } from "./context";
1
+ import { useContextSelector } from 'use-context-selector';
2
+ import context, { Dispatch } from './context';
3
3
 
4
4
  function useDispatch(): Dispatch {
5
5
  return useContextSelector(context, ([, dispatch]) => dispatch);
@@ -1,6 +1,6 @@
1
- import { useContextSelector } from "use-context-selector";
2
- import context from "./context";
3
- import * as Types from "./types";
1
+ import { useContextSelector } from 'use-context-selector';
2
+ import context from './context';
3
+ import * as Types from './types';
4
4
 
5
5
  function useSelector<T>(selector: (state: Types.StoreState) => T): T {
6
6
  return useContextSelector(context, ([state]) => selector(state));
@@ -1,13 +1,13 @@
1
- import * as Types from "./types";
2
- import * as Matrix from "./matrix";
3
- import * as Point from "./point";
4
- import { PointRange } from "./point-range";
5
- import { Selection } from "./selection";
1
+ import * as Types from './types';
2
+ import * as Matrix from './matrix';
3
+ import * as Point from './point';
4
+ import { PointRange } from './point-range';
5
+ import { Selection } from './selection';
6
6
 
7
- export { createEmpty as createEmptyMatrix } from "./matrix";
7
+ export { createEmpty as createEmptyMatrix } from './matrix';
8
8
 
9
- export const PLAIN_TEXT_MIME = "text/plain";
10
- export const FOCUS_WITHIN_SELECTOR = ":focus-within";
9
+ export const PLAIN_TEXT_MIME = 'text/plain';
10
+ export const FOCUS_WITHIN_SELECTOR = ':focus-within';
11
11
 
12
12
  /** Move the cursor of given input element to the input's end */
13
13
  export function moveCursorToEnd(el: HTMLInputElement): void {
@@ -18,8 +18,7 @@ export function moveCursorToEnd(el: HTMLInputElement): void {
18
18
  * Creates an array of numbers (positive and/or negative) progressing from start up to, but not including, end. A step of -1 is used if a negative start is specified without an end or step. If end is not specified, it's set to start with start then set to 0.
19
19
  * @param end - an integer number specifying at which position to stop (not included).
20
20
  * @param start - An integer number specifying at which position to start.
21
- * @param step - An integer number specifying the incrementation
22
- */
21
+ * @param step - An integer number specifying the Increment */
23
22
  export function range(end: number, start = 0, step = 1): number[] {
24
23
  const array = [];
25
24
  if (Math.sign(end - start) === -1) {
@@ -36,7 +35,7 @@ export function range(end: number, start = 0, step = 1): number[] {
36
35
 
37
36
  /** Return whether given point is active */
38
37
  export function isActive(
39
- active: Types.StoreState["active"],
38
+ active: Types.StoreState['active'],
40
39
  point: Point.Point
41
40
  ): boolean {
42
41
  return Boolean(active && Point.isEqual(point, active));
@@ -65,19 +64,19 @@ export function readTextFromClipboard(event: ClipboardEvent): string {
65
64
  // @ts-ignore
66
65
  if (window.clipboardData && window.clipboardData.getData) {
67
66
  // @ts-ignore
68
- return window.clipboardData.getData("Text");
67
+ return window.clipboardData.getData('Text');
69
68
  }
70
69
  if (event.clipboardData && event.clipboardData.getData) {
71
70
  return event.clipboardData.getData(PLAIN_TEXT_MIME);
72
71
  }
73
- return "";
72
+ return '';
74
73
  }
75
74
 
76
75
  /** Get the dimensions of cell at point from state */
77
76
  export function getCellDimensions(
78
77
  point: Point.Point,
79
- rowDimensions: Types.StoreState["rowDimensions"] | undefined,
80
- columnDimensions: Types.StoreState["columnDimensions"] | undefined
78
+ rowDimensions: Types.StoreState['rowDimensions'] | undefined,
79
+ columnDimensions: Types.StoreState['columnDimensions'] | undefined
81
80
  ): Types.Dimensions | undefined {
82
81
  const cellRowDimensions = rowDimensions && rowDimensions[point.row];
83
82
  const cellColumnDimensions =
@@ -93,8 +92,8 @@ export function getCellDimensions(
93
92
 
94
93
  /** Get the dimensions of a range of cells */
95
94
  export function getRangeDimensions(
96
- rowDimensions: Types.StoreState["rowDimensions"],
97
- columnDimensions: Types.StoreState["columnDimensions"],
95
+ rowDimensions: Types.StoreState['rowDimensions'],
96
+ columnDimensions: Types.StoreState['columnDimensions'],
98
97
  range: PointRange
99
98
  ): Types.Dimensions | undefined {
100
99
  const startDimensions = getCellDimensions(
@@ -120,8 +119,8 @@ export function getRangeDimensions(
120
119
 
121
120
  /** Get the dimensions of selected */
122
121
  export function getSelectedDimensions(
123
- rowDimensions: Types.StoreState["rowDimensions"],
124
- columnDimensions: Types.StoreState["columnDimensions"],
122
+ rowDimensions: Types.StoreState['rowDimensions'],
123
+ columnDimensions: Types.StoreState['columnDimensions'],
125
124
  data: Matrix.Matrix<unknown>,
126
125
  selected: Selection
127
126
  ): Types.Dimensions | undefined {
@@ -133,7 +132,7 @@ export function getSelectedDimensions(
133
132
 
134
133
  /** Get given data as CSV */
135
134
  export function getCSV(data: Matrix.Matrix<Types.CellBase>): string {
136
- const valueMatrix = Matrix.map((cell) => cell?.value || "", data);
135
+ const valueMatrix = Matrix.map((cell) => cell?.value || '', data);
137
136
  return Matrix.join(valueMatrix);
138
137
  }
139
138
 
@@ -161,7 +160,7 @@ export function shouldHandleClipboardEvent(
161
160
  root: Element | null,
162
161
  mode: Types.Mode
163
162
  ): boolean {
164
- return root !== null && mode === "view" && isFocusedWithin(root);
163
+ return root !== null && mode === 'view' && isFocusedWithin(root);
165
164
  }
166
165
 
167
166
  export function isFocusedWithin(element: Element): boolean {
@@ -169,5 +168,5 @@ export function isFocusedWithin(element: Element): boolean {
169
168
  }
170
169
 
171
170
  export function hasLineBreaker(value: unknown) {
172
- return typeof value === "string" && value.includes("\n");
171
+ return typeof value === 'string' && value.includes('\n');
173
172
  }
@@ -1,6 +1,3 @@
1
- @import '../../../assets/styles/colors';
2
- @import '../../../assets/styles/rsfonts';
3
-
4
1
  .excel-page {
5
2
  width: 100%;
6
3
  display: flex;
@@ -1,32 +1,30 @@
1
1
  import React, { useState, useRef, useEffect } from 'react';
2
- // import './ExcelFile.scss';
3
- // import Spreadsheet from 'react-spreadsheet';
4
- // import ImportExcelStyles from '../ImportExcelStyles';
5
- // import ChangeExcelStyles from '../ChangeExcelStyles';
6
- // import { colors } from '../../../colors/colorConstants';
7
- import ExcelToolBar from '../ExcelToolBar/ExcelToolBar';
8
2
  import ExcelSheetBar from '../ExcelSheetBar/ExcelSheetBar';
9
- import ContextMenu from '../ContextMenu/ContextMenu';
10
3
  import Spreadsheet, { CellBase } from './Excel/index';
11
- import * as Matrix from "./Excel/matrix";
12
- import ChangeExcelStyles from './../ChangeExcelStyles';
4
+ import * as Matrix from './Excel/matrix';
13
5
 
6
+ interface ExcelFileProps {
7
+ /** The Excel data containing sheets and their content */
8
+ excelData: {
9
+ sheets: WorkSheet[];
10
+ };
14
11
 
15
- let colors={
16
- ff_down_arrow_color: '#acacac',
17
- ff_up_arrow_color: '#434db8',
18
- ff_input_up_down_arrow_color: '#B2AEAE',
19
- white: '#ffffff',
20
- black: '#000000',
21
- grey_dark: '#727171',
22
- light_gray_50: '#F2F2F2',
23
- button_red_60: '#C50303',
24
- };
12
+ /** Optional: Provide context menu options for actions like right-click */
13
+ contextOption?: {
14
+ name: string;
15
+ title: React.ReactNode;
16
+ action: () => void;
17
+ }[];
18
+
19
+ /** Controls whether the toolbar is shown, disabled, or hidden */
20
+ toolbar?: 'show' | 'disable' | 'hide';
21
+
22
+ /** Callback function to save the Excel data */
23
+ onSave?: (excelData?: any) => void;
24
+ }
25
25
 
26
26
  const ExcelFile: React.FC<ExcelFileProps> = ({
27
27
  excelData,
28
- toolbar = 'show',
29
- contextOption = [],
30
28
  onSave = () => {},
31
29
  }) => {
32
30
  const [fileDetails, setFileDetails] = useState<{
@@ -35,24 +33,9 @@ const ExcelFile: React.FC<ExcelFileProps> = ({
35
33
  const EmptyRow: CellBase = {
36
34
  value: '',
37
35
  style: {
38
- name: 'Arial',
39
- size: 11,
40
- bold: false,
41
- italic: false,
42
- color: colors.black.replace('#', ''),
43
- backgroundColor: colors.white.replace('#', ''),
44
- borderColor: colors.light_gray_50.replace('#', ''),
45
- border: {
46
- top: 'NONE',
47
- bottom: 'NONE',
48
- left: 'NONE',
49
- right: 'NONE',
50
- },
51
- alignment: {
52
- horizontal: 'GENERAL',
53
- vertical: 'BOTTOM',
54
- wrapText: false,
55
- },
36
+ color: 'var(--text-color)',
37
+ backgroundColor: 'var(--drawer-footer-bg)',
38
+ borderColor: 'var(--toggle-strip-color)',
56
39
  },
57
40
  };
58
41
  const [selectedSheet, setSelectedSheet] = useState<{
@@ -62,61 +45,18 @@ const ExcelFile: React.FC<ExcelFileProps> = ({
62
45
 
63
46
  const [worksheetsData, setWorksheetsData] = useState<{
64
47
  [key: string]: Matrix.Matrix<CellBase>;
65
- }>({defaultSheet:[[EmptyRow]]});
48
+ }>({ defaultSheet: [[EmptyRow]] });
66
49
 
50
+ const [selectedSheetData, setSelectedSheetData] = useState<
51
+ Matrix.Matrix<CellBase>
52
+ >([[EmptyRow]]);
67
53
 
68
- const [selectedSheetData, setSelectedSheetData] = useState<Matrix.Matrix<CellBase>>([
69
- [EmptyRow]
70
- ]);
71
-
72
- // const [selectedValue, setSelectedValue] = useState<SelectedValue>({
73
- // value: '',
74
- // row: 0,
75
- // column: 0,
76
- // alphaCol: '',
77
- // style: {
78
- // name: 'Arial',
79
- // size: 11,
80
- // bold: false,
81
- // italic: false,
82
- // color: colors.black.replace('#', ''),
83
- // backgroundColor: colors.white.replace('#', ''),
84
- // borderColor: colors.light_gray_50.replace('#', ''),
85
- // border: {
86
- // top: 'NONE',
87
- // bottom: 'NONE',
88
- // left: 'NONE',
89
- // right: 'NONE',
90
- // },
91
- // alignment: {
92
- // horizontal: 'GENERAL',
93
- // vertical: 'BOTTOM',
94
- // wrapText: false,
95
- // },
96
- // },
97
- // sheet: '',
98
- // });
99
- const [selectedCell, setSelectedCell] = useState<
100
- { row: number; column: number }[]
101
- >([]);
102
- // const [formatePainter, setFormatePainter] = useState<{
103
- // style: CellStyle | null;
104
- // active: boolean;
105
- // }>({
106
- // style: null,
107
- // active: false,
108
- // });
109
54
  const sheetRef = useRef<HTMLDivElement | null>(null);
110
- const excelDataCopy = useRef<{ [key: string]: Matrix.Matrix<CellBase> }>({defaultSheet:[[]]});
111
- const [contextData, setContextData] = useState<ContextMenuState>({
112
- visible: false,
113
- x: 0,
114
- y: 0,
115
- type: 'cell',
55
+ const excelDataCopy = useRef<{ [key: string]: Matrix.Matrix<CellBase> }>({
56
+ defaultSheet: [[]],
116
57
  });
117
58
 
118
-
119
- let checkVal = (val:any) => {
59
+ let checkVal = (val: any) => {
120
60
  if (val === undefined || val === null) {
121
61
  return null;
122
62
  }
@@ -127,18 +67,21 @@ const ExcelFile: React.FC<ExcelFileProps> = ({
127
67
  const sheetNames = payload.sheets.map((e) => e.sheetName);
128
68
  setFileDetails({ sheetNames });
129
69
  if (sheetNames.length > 0) {
130
- setSelectedSheet({ name: sheetNames[0]?sheetNames[0]:"", index: 0 });
70
+ setSelectedSheet({ name: sheetNames[0] ? sheetNames[0] : '', index: 0 });
131
71
  }
132
-
133
72
  const newWorksheetsData: { [key: string]: Matrix.Matrix<CellBase> } = {};
134
73
  payload.sheets.forEach((sheet) => {
135
74
  const sheetName = sheet.sheetName;
136
75
  const json = sheet.data;
137
76
  const maxRows = Math.max(26, json.length + 2);
138
- const maxCols = Math.max(26, Math.max(...json.map((row) => row.length)) + 2);
77
+ const maxCols = Math.max(
78
+ 26,
79
+ Math.max(...json.map((row) => row.length)) + 2
80
+ );
139
81
 
140
- let spreadsheetData: Matrix.Matrix<CellBase> = Array.from({ length: maxRows }, () =>
141
- Array.from({ length: maxCols }, () => EmptyRow)
82
+ let spreadsheetData: Matrix.Matrix<CellBase> = Array.from(
83
+ { length: maxRows },
84
+ () => Array.from({ length: maxCols }, () => EmptyRow)
142
85
  );
143
86
  json.forEach((row, rowIndex) => {
144
87
  row.forEach((cell, colIndex) => {
@@ -149,30 +92,23 @@ const ExcelFile: React.FC<ExcelFileProps> = ({
149
92
  spreadsheetData[rowIndex][colIndex] = {
150
93
  value: checkVal(cell.value),
151
94
  style: cell.style,
152
- type:true
95
+ type: true,
153
96
  };
154
97
  }
155
98
  });
156
99
  });
157
-
100
+
158
101
  newWorksheetsData[sheetName] = spreadsheetData;
159
102
  });
160
103
  excelDataCopy.current = newWorksheetsData;
161
104
  setWorksheetsData(newWorksheetsData);
162
105
  const firstSheetName = Object.keys(newWorksheetsData)[0];
163
- if (firstSheetName && newWorksheetsData[firstSheetName]!==undefined) {
106
+ if (firstSheetName && newWorksheetsData[firstSheetName] !== undefined) {
164
107
  setSelectedSheetData(newWorksheetsData[firstSheetName]);
165
108
  }
166
- }, [excelData]);
167
-
168
-
169
- const handleSaveData = () => {
170
- setWorksheetsData((prevData) => {
171
- let updatedData = { ...prevData };
172
- updatedData[selectedSheet.name] = selectedSheetData;
173
- return updatedData;
174
- });
109
+ }, []);
175
110
 
111
+ const handleSaveData = () => {
176
112
  const dataToSave = {
177
113
  sheets: fileDetails.sheetNames.map((sheetName) => ({
178
114
  sheetName: sheetName,
@@ -201,315 +137,21 @@ const ExcelFile: React.FC<ExcelFileProps> = ({
201
137
  }, [worksheetsData]);
202
138
 
203
139
  const handleSheetChange = (name: string, index: number) => {
204
- setWorksheetsData((prevData) => {
205
- let updatedData = prevData;
206
- updatedData[selectedSheet.name] = selectedSheetData;
207
- return updatedData;
208
- });
209
- setSelectedSheet({ index, name });
210
- };
211
-
212
- let addRow = () => {
213
- let updateSheet: Matrix.Matrix<CellBase> = worksheetsData[selectedSheet.name] ?? []; // Fallback to an empty array if undefined
214
- // let insertRow: CellBase[] = [];
215
-
216
- // insertRow = Array.from({ length: updateSheet[0]?.length ?? 0 }, () => EmptyRow); // Fallback to 0 if the length is undefined
217
-
218
- // updateSheet.splice(selectedValue.row - 1, 0, insertRow); // Add the new row
219
-
220
- setWorksheetsData((prev) => ({
221
- ...prev,
222
- [selectedSheet.name]: updateSheet,
223
- }));
224
- };
225
-
226
-
227
- let deleteRow = () => {
228
-
229
- };
230
-
231
- let addColumn = () => {
232
- let updateSheet: Matrix.Matrix<CellBase> = worksheetsData[selectedSheet.name] ?? []; // Fallback to empty array if undefined
233
- if (updateSheet.length > 0) {
234
- // updateSheet.forEach((row) => {
235
- // row.splice(selectedValue.column, 0, EmptyRow); // Insert EmptyRow at the specified column index
236
- // });
237
- setWorksheetsData((prev) => ({
238
- ...prev,
239
- [selectedSheet.name]: updateSheet,
240
- }));
241
- }
242
- };
243
-
244
- let deleteColumn = () => {
245
- let updateSheet: Matrix.Matrix<CellBase> = worksheetsData[selectedSheet.name] ?? [];
246
-
247
- // Ensure there is at least one row in the sheet and that the first row exists
248
- if (updateSheet.length > 0 && updateSheet[0]) {
249
- // const firstRow = updateSheet[0]; // Safely access the first row
250
- // const length = firstRow.length; // Get the length of the first row
251
-
252
- // Proceed only if the column index is within bounds
253
- // if (selectedValue.column >= 0 && selectedValue.column < length) {
254
- // // Delete the specified column from each row
255
- // updateSheet.forEach((row) => row.splice(selectedValue.column, 1));
256
-
257
- // // Update the worksheets data with the modified sheet
258
- // setWorksheetsData((prev) => ({
259
- // ...prev,
260
- // [selectedSheet.name]: updateSheet,
261
- // }));
262
- // }
263
- }
264
- };
265
-
266
- let addSheet = () => {
267
- const generateUniqueSheetName = (
268
- baseName: string,
269
- existingNames: string[]
270
- ): string => {
271
- let newName = baseName;
272
- let counter = 1;
273
- while (existingNames.includes(newName)) {
274
- newName = `${baseName}${counter}`;
275
- counter++;
276
- }
277
- return newName;
278
- };
279
- const baseName = 'NewSheet';
280
- const existingSheetNames = fileDetails.sheetNames;
281
- const newSheetName = generateUniqueSheetName(baseName, existingSheetNames);
282
- const newSheetData = Array.from({ length: 25 }, () =>
283
- Array.from({ length: 26 }, () => EmptyRow)
284
- );
285
-
286
- setFileDetails((prev) => ({
287
- sheetNames: prev.sheetNames.concat(newSheetName),
288
- }));
289
-
290
- setWorksheetsData({ ...worksheetsData, [newSheetName]: newSheetData });
291
- setSelectedSheet({
292
- index: fileDetails.sheetNames.length,
293
- name: newSheetName,
294
- });
295
- };
296
-
297
- let deleteSheet = () => {
298
- const { sheetNames } = fileDetails;
299
- const { index, name } = selectedSheet;
300
-
301
- if (sheetNames.length > 1) {
302
- const updatedSheetNames = sheetNames.slice();
303
- updatedSheetNames.splice(index, 1);
304
-
305
- const { [name]: _, ...updatedWorksheetsData } = worksheetsData;
306
-
307
- setFileDetails((prev) => ({
308
- ...prev,
309
- sheetNames: updatedSheetNames,
310
- }));
311
- setWorksheetsData(updatedWorksheetsData);
312
-
313
- const newIndex = Math.min(index, updatedSheetNames.length - 1);
314
-
315
- const newSheetName = updatedSheetNames[newIndex] ?? "";
316
-
317
- setSelectedSheet({
318
- index: newIndex,
319
- name: newSheetName,
320
- });
321
- } else {
322
- alert('Cannot delete the last sheet.');
323
- }
324
- };
325
-
326
- const contextAction: {
327
- addRow: () => void;
328
- deleteRow: () => void;
329
- addColumn: () => void;
330
- deleteColumn: () => void;
331
- addSheet: () => void;
332
- deleteSheet: () => void;
333
- } = {
334
- addRow,
335
- deleteRow,
336
- addColumn,
337
- deleteColumn,
338
- addSheet,
339
- deleteSheet,
340
- };
341
-
342
- const formatePaint = () => {
343
-
344
- };
345
-
346
-
347
- const handleSelect = (e: any) => {
348
- if (e.hasOwnProperty('range')) {
349
- let rowStart = e.range.start.row;
350
- let rowEnd = e.range.end.row;
351
- let columnStart = e.range.start.column;
352
- let columnEnd = e.range.end.column;
353
- let cell: { row: number; column: number }[] = [];
354
- for (let i = rowStart; i <= rowEnd; i++) {
355
- for (let j = columnStart; j <= columnEnd; j++) {
356
- cell.push({ row: i, column: j });
357
- }
358
- }
359
- setContextData((prev) => ({ ...prev, type: 'cell' }));
360
- setSelectedCell(cell);
361
- } else {
362
- if (e.hasOwnProperty('start') && e.hasOwnProperty('end')) {
363
- const columnName = e.constructor.name;
364
- if (columnName.includes('EntireColumnsSelection')) {
365
- setContextData((prev) => ({ ...prev, type: 'column' }));
366
- } else if (columnName.includes('EntireRowsSelection')) {
367
- setContextData((prev) => ({ ...prev, type: 'row' }));
368
- }
369
- }
370
- }
371
- };
372
-
373
- const contextSelect = (event: React.MouseEvent) => {
374
- event.preventDefault();
375
- const sheetTop = sheetRef.current?.getBoundingClientRect().top;
376
- const sheetLeft = sheetRef.current?.getBoundingClientRect().left;
377
-
378
- if (sheetLeft !== undefined && sheetTop !== undefined) {
379
- const contextMenuHeight =
380
- contextData.type === 'cell' ? contextOption.length * 35 + 40 : 110;
381
- const adjustedY = event.pageY - sheetTop - window.scrollY;
382
- const availableSpace = window.innerHeight - adjustedY;
383
- const contextMenuWidth = 250;
384
- const adjustedX = event.pageX - sheetLeft - window.scrollX;
385
- const availableXSpace = window.innerWidth - adjustedX;
386
-
387
- const finalY =
388
- availableSpace < contextMenuHeight
389
- ? adjustedY - contextMenuHeight
390
- : adjustedY;
391
-
392
- const finalX =
393
- availableXSpace < contextMenuWidth
394
- ? adjustedX - contextMenuWidth
395
- : adjustedX;
396
-
397
- const target = event.target as HTMLElement;
398
- const isCell =
399
- target.classList.contains('Spreadsheet__active-cell') &&
400
- contextData.type === 'cell';
401
- const isHeader =
402
- target.classList.contains('Spreadsheet__header--selected') &&
403
- (contextData.type === 'row' || contextData.type === 'column');
404
- const isSheetTab =
405
- target.classList.contains('tab-request') &&
406
- contextData.type === 'sheet_options';
407
-
408
- if (isCell || isHeader || isSheetTab) {
409
- setContextData((prev) => ({
410
- ...prev,
411
- visible: true,
412
- x: finalX,
413
- y: finalY,
414
- }));
415
- } else {
416
- setContextData((prev) => ({
417
- ...prev,
418
- visible: false,
419
- x: finalX,
420
- y: finalY,
421
- }));
422
- }
423
- }
424
- };
425
-
426
- const sheetContext = (
427
- _: React.MouseEvent<Element, MouseEvent>,
428
- name: string,
429
- index: number
430
- ) => {
431
-
432
140
  setSelectedSheet({ index, name });
433
- setContextData((prev) => ({
434
- ...prev,
435
- type: 'sheet_options',
436
- }));
437
141
  };
438
142
 
439
- const createStyler =
440
- (selectedCell: { row: number; column: number }[]) =>
441
- async (styleType: any, value: any) => {
442
- ChangeExcelStyles(setWorksheetsData, {
443
- sheetName: selectedSheet.name,
444
- styleType,
445
- value,
446
- selectedCell,
447
- });
448
- };
449
-
450
- const applyStyle = createStyler(selectedCell);
451
-
452
- useEffect(() => {
453
- const currentSheet = worksheetsData[selectedSheet.name] ?? [];
454
- const validSheetData: CellBase[][] = currentSheet.map(row =>
455
- row.map(cell => cell ? { value: cell.value, style: cell.style } : { value: "", style: EmptyRow.style })
456
- );
457
-
458
- setSelectedSheetData(validSheetData);
459
- }, [worksheetsData, selectedSheet.name]);
460
-
461
-
462
- useEffect(() => {
463
- let timeGap = setTimeout(() => {
464
- setWorksheetsData((prevData) => {
465
- let updatedData = prevData;
466
- updatedData[selectedSheet.name] = selectedSheetData;
467
- return updatedData;
468
- }); }, 1000);
469
- return () => {
470
- clearTimeout(timeGap);
471
- };
472
- }, [selectedSheetData]);
473
-
474
143
  return (
475
144
  <div className="excel-page">
476
- <ExcelToolBar
477
- toolbar={toolbar}
478
- applyStyle={applyStyle}
479
- formatePaint={formatePaint}
480
- />
481
-
482
145
  {fileDetails.sheetNames.length > 0 && (
483
- <div className="excel-book" >
484
- <div
485
- ref={sheetRef}
486
- onContextMenu={contextSelect}
487
- className="excel-sheet"
488
- >
489
- <Spreadsheet
490
- data={selectedSheetData}
491
- onActivate={() => {
492
- setContextData((prev) => ({ ...prev, visible: false }));
493
- }}
494
- onSelect={handleSelect}
495
- />
496
-
146
+ <div className="excel-book">
147
+ <div ref={sheetRef} className="excel-sheet">
148
+ <Spreadsheet data={selectedSheetData} />
497
149
  </div>
498
150
 
499
151
  <ExcelSheetBar
500
152
  selectedSheet={selectedSheet}
501
153
  fileDetails={fileDetails}
502
154
  handleSheetChange={handleSheetChange}
503
- contextMenu={sheetContext}
504
- contextSelect={contextSelect}
505
- addSheet={addSheet}
506
- />
507
-
508
- <ContextMenu
509
- customContext={contextOption}
510
- contextAction={contextAction}
511
- contextData={contextData}
512
- setContextData={setContextData}
513
155
  />
514
156
  </div>
515
157
  )}