pixel-react 1.2.1 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/AppHeader/types.d.ts +11 -2
- package/lib/components/Avatar/Avatar.d.ts +5 -0
- package/lib/components/Avatar/Avatar.stories.d.ts +10 -0
- package/lib/components/Avatar/index.d.ts +1 -0
- package/lib/components/Avatar/types.d.ts +26 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/ActiveCell.d.ts +2 -2
- package/lib/components/ExcelFile/ExcelFile/Excel/ColumnIndicator.d.ts +2 -2
- package/lib/components/ExcelFile/ExcelFile/Excel/Copied.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/CornerIndicator.d.ts +2 -2
- package/lib/components/ExcelFile/ExcelFile/Excel/DataEditor.d.ts +2 -2
- package/lib/components/ExcelFile/ExcelFile/Excel/DataViewer.d.ts +2 -2
- package/lib/components/ExcelFile/ExcelFile/Excel/FloatingRect.d.ts +2 -2
- package/lib/components/ExcelFile/ExcelFile/Excel/HeaderRow.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/Row.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/RowIndicator.d.ts +2 -2
- package/lib/components/ExcelFile/ExcelFile/Excel/Selected.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/Spreadsheet.d.ts +6 -7
- package/lib/components/ExcelFile/ExcelFile/Excel/Table.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/actions.d.ts +49 -5
- package/lib/components/ExcelFile/ExcelFile/Excel/context.d.ts +3 -3
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/engine.d.ts +5 -5
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/formula.d.ts +6 -6
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/index.d.ts +2 -2
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-graph.d.ts +2 -2
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-hash.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-set.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/index.d.ts +11 -11
- package/lib/components/ExcelFile/ExcelFile/Excel/matrix.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/point-range.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/reducer.d.ts +5 -5
- package/lib/components/ExcelFile/ExcelFile/Excel/selection.d.ts +3 -3
- package/lib/components/ExcelFile/ExcelFile/Excel/types.d.ts +11 -48
- package/lib/components/ExcelFile/ExcelFile/Excel/use-dispatch.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/use-selector.d.ts +1 -1
- package/lib/components/ExcelFile/ExcelFile/Excel/util.d.ts +11 -12
- package/lib/components/ExcelFile/ExcelFile/ExcelFile.d.ts +16 -0
- package/lib/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.d.ts +0 -3
- package/lib/components/ExcelFile/ExcelToolBar/ExcelToolBar.d.ts +12 -0
- package/lib/components/ExcelFile/Types.d.ts +2 -49
- package/lib/components/Form/Form.d.ts +1 -15
- package/lib/components/Form/Form.stories.d.ts +6 -5
- package/lib/components/Form/Forms.d.ts +8 -0
- package/lib/components/Form/index.d.ts +1 -1
- package/lib/components/Icon/types.d.ts +1 -1
- package/lib/components/MenuOption/types.d.ts +7 -7
- package/lib/components/MiniModal/MiniModal.stories.d.ts +1 -0
- package/lib/components/MiniModal/types.d.ts +6 -6
- package/lib/components/ModulesChip/ModuleChip.d.ts +4 -0
- package/lib/components/ModulesChip/ModuleChip.stories.d.ts +6 -0
- package/lib/components/ModulesChip/index.d.ts +1 -0
- package/lib/components/ModulesChip/types.d.ts +14 -0
- package/lib/components/MultiSelect/MultiSelectTypes.d.ts +1 -0
- package/lib/components/Toastify/Toastify.d.ts +8 -0
- package/lib/components/Toastify/Toastify.stories.d.ts +6 -0
- package/lib/components/Toastify/index.d.ts +1 -0
- package/lib/components/Toastify/types.d.ts +7 -0
- package/lib/components/Tooltip/types.d.ts +6 -0
- package/lib/components/Typography/types.d.ts +1 -0
- package/lib/index.d.ts +84 -31
- package/lib/index.esm.js +26720 -881
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +26718 -875
- package/lib/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/StyleGuide/ColorPalette/colorPaletteList.ts +10 -0
- package/src/assets/Themes/BaseTheme.scss +2 -0
- package/src/assets/Themes/DarkTheme.scss +2 -0
- package/src/assets/icons/add_testcase.svg +3 -0
- package/src/assets/icons/add_variable_icon.svg +3 -4
- package/src/assets/icons/attachment_icon.svg +3 -0
- package/src/assets/icons/authorization_icon.svg +3 -0
- package/src/assets/icons/automation_testcase.svg +4 -0
- package/src/assets/icons/back_icon.svg +3 -0
- package/src/assets/icons/client_profile.svg +4 -0
- package/src/assets/icons/fireflink_finder_logo.svg +7 -0
- package/src/assets/icons/fireflink_platform.svg +4 -0
- package/src/assets/icons/license_expired.svg +20 -0
- package/src/assets/icons/manual_testcase.svg +3 -0
- package/src/assets/icons/variable_icon.svg +4 -0
- package/src/components/AllProjectsDropdown/AllProjectsDropdown.scss +2 -2
- package/src/components/AllProjectsDropdown/AllProjectsDropdown.tsx +1 -1
- package/src/components/AppHeader/AppHeader.stories.tsx +24 -3
- package/src/components/AppHeader/AppHeader.tsx +29 -11
- package/src/components/AppHeader/types.ts +11 -3
- package/src/components/Avatar/Avatar.scss +24 -0
- package/src/components/Avatar/Avatar.stories.tsx +56 -0
- package/src/components/Avatar/Avatar.tsx +25 -0
- package/src/components/Avatar/index.ts +1 -0
- package/src/components/Avatar/types.ts +27 -0
- package/src/components/Button/types.ts +1 -1
- package/src/components/ExcelFile/ColorBarselector/ColorBarSelector.scss +0 -2
- package/src/components/ExcelFile/ContextMenu/ContextMenu.scss +1 -4
- package/src/components/ExcelFile/ContextMenu/ContextMenu.tsx +0 -1
- package/src/components/ExcelFile/ExcelFile/Excel/ActiveCell.tsx +13 -13
- package/src/components/ExcelFile/ExcelFile/Excel/Cell.tsx +13 -12
- package/src/components/ExcelFile/ExcelFile/Excel/ColumnIndicator.tsx +40 -32
- package/src/components/ExcelFile/ExcelFile/Excel/Copied.tsx +4 -4
- package/src/components/ExcelFile/ExcelFile/Excel/CornerIndicator.tsx +10 -10
- package/src/components/ExcelFile/ExcelFile/Excel/DataEditor.tsx +5 -5
- package/src/components/ExcelFile/ExcelFile/Excel/DataViewer.tsx +10 -10
- package/src/components/ExcelFile/ExcelFile/Excel/FloatingRect.tsx +6 -6
- package/src/components/ExcelFile/ExcelFile/Excel/HeaderRow.tsx +1 -1
- package/src/components/ExcelFile/ExcelFile/Excel/Row.tsx +1 -1
- package/src/components/ExcelFile/ExcelFile/Excel/RowIndicator.tsx +34 -27
- package/src/components/ExcelFile/ExcelFile/Excel/Selected.tsx +5 -5
- package/src/components/ExcelFile/ExcelFile/Excel/{Spreadsheet.css → Spreadsheet.scss} +21 -37
- package/src/components/ExcelFile/ExcelFile/Excel/Spreadsheet.tsx +87 -78
- package/src/components/ExcelFile/ExcelFile/Excel/Table.tsx +2 -2
- package/src/components/ExcelFile/ExcelFile/Excel/actions.ts +121 -31
- package/src/components/ExcelFile/ExcelFile/Excel/areModelsEqual.ts +1 -1
- package/src/components/ExcelFile/ExcelFile/Excel/context.ts +4 -4
- package/src/components/ExcelFile/ExcelFile/Excel/engine/engine.ts +7 -7
- package/src/components/ExcelFile/ExcelFile/Excel/engine/formula.ts +11 -11
- package/src/components/ExcelFile/ExcelFile/Excel/engine/index.ts +2 -2
- package/src/components/ExcelFile/ExcelFile/Excel/engine/point-graph.ts +3 -3
- package/src/components/ExcelFile/ExcelFile/Excel/engine/point-hash.ts +2 -2
- package/src/components/ExcelFile/ExcelFile/Excel/engine/point-set.ts +2 -2
- package/src/components/ExcelFile/ExcelFile/Excel/index.ts +12 -11
- package/src/components/ExcelFile/ExcelFile/Excel/matrix.ts +18 -24
- package/src/components/ExcelFile/ExcelFile/Excel/point-range.ts +1 -1
- package/src/components/ExcelFile/ExcelFile/Excel/reducer.ts +311 -41
- package/src/components/ExcelFile/ExcelFile/Excel/selection.ts +5 -5
- package/src/components/ExcelFile/ExcelFile/Excel/types.ts +14 -66
- package/src/components/ExcelFile/ExcelFile/Excel/typings/fast-formula-parser.d.ts +8 -8
- package/src/components/ExcelFile/ExcelFile/Excel/use-dispatch.ts +2 -2
- package/src/components/ExcelFile/ExcelFile/Excel/use-selector.ts +3 -3
- package/src/components/ExcelFile/ExcelFile/Excel/util.ts +21 -22
- package/src/components/ExcelFile/ExcelFile/ExcelFile.scss +0 -3
- package/src/components/ExcelFile/ExcelFile/ExcelFile.tsx +45 -403
- package/src/components/ExcelFile/ExcelFile.stories.tsx +10 -29
- package/src/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.tsx +1 -12
- package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.scss +0 -3
- package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.tsx +147 -127
- package/src/components/ExcelFile/Types.ts +3 -70
- package/src/components/ExcelFile/index.ts +1 -1
- package/src/components/Form/Form.d.ts +3 -0
- package/src/components/Form/Form.scss +48 -4
- package/src/components/Form/Form.stories.tsx +244 -137
- package/src/components/Form/Form.ts +2 -0
- package/src/components/Form/Forms.tsx +25 -0
- package/src/components/Form/index.ts +1 -1
- package/src/components/Icon/iconList.ts +23 -0
- package/src/components/Icon/types.ts +1 -1
- package/src/components/IconButton/IconButton.scss +1 -1
- package/src/components/MenuOption/types.ts +7 -6
- package/src/components/MiniModal/MiniModal.scss +5 -0
- package/src/components/MiniModal/MiniModal.stories.tsx +95 -0
- package/src/components/MiniModal/MiniModal.tsx +11 -6
- package/src/components/MiniModal/types.ts +6 -6
- package/src/components/ModulesChip/ModuleChip.scss +20 -0
- package/src/components/ModulesChip/ModuleChip.stories.tsx +41 -0
- package/src/components/ModulesChip/ModuleChip.tsx +31 -0
- package/src/components/ModulesChip/index.ts +1 -0
- package/src/components/ModulesChip/types.ts +14 -0
- package/src/components/MultiSelect/Dropdown.tsx +6 -1
- package/src/components/MultiSelect/MultiSelect.scss +17 -10
- package/src/components/MultiSelect/MultiSelect.stories.tsx +16 -4
- package/src/components/MultiSelect/MultiSelect.tsx +11 -4
- package/src/components/MultiSelect/MultiSelectTypes.ts +4 -3
- package/src/components/Select/Select.scss +4 -0
- package/src/components/Select/Select.tsx +2 -2
- package/src/components/Toastify/Toastify.stories.tsx +52 -0
- package/src/components/Toastify/Toastify.tsx +66 -0
- package/src/components/Toastify/index.ts +1 -0
- package/src/components/Toastify/types.ts +8 -0
- package/src/components/Tooltip/Tooltip.tsx +2 -1
- package/src/components/Tooltip/types.ts +6 -0
- package/src/components/Typography/Typography.scss +12 -4
- package/src/components/Typography/Typography.stories.tsx +2 -0
- package/src/components/Typography/Typography.tsx +2 -0
- package/src/components/Typography/types.ts +1 -0
- package/src/index.ts +9 -1
- package/src/components/ExcelFile/ChangeExcelStyles.tsx +0 -78
- package/src/components/ExcelFile/ImportExcelStyles.tsx +0 -86
- package/src/components/Form/Form.tsx +0 -57
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useContextSelector } from
|
|
2
|
-
import context, { Dispatch } from
|
|
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
|
|
2
|
-
import context from
|
|
3
|
-
import * as Types from
|
|
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
|
|
2
|
-
import * as Matrix from
|
|
3
|
-
import * as Point from
|
|
4
|
-
import { PointRange } from
|
|
5
|
-
import { Selection } from
|
|
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
|
|
7
|
+
export { createEmpty as createEmptyMatrix } from './matrix';
|
|
8
8
|
|
|
9
|
-
export const PLAIN_TEXT_MIME =
|
|
10
|
-
export const FOCUS_WITHIN_SELECTOR =
|
|
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
|
|
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[
|
|
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(
|
|
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[
|
|
80
|
-
columnDimensions: Types.StoreState[
|
|
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[
|
|
97
|
-
columnDimensions: Types.StoreState[
|
|
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[
|
|
124
|
-
columnDimensions: Types.StoreState[
|
|
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 ||
|
|
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 ===
|
|
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 ===
|
|
171
|
+
return typeof value === 'string' && value.includes('\n');
|
|
173
172
|
}
|
|
@@ -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
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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> }>({
|
|
111
|
-
|
|
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]:
|
|
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(
|
|
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(
|
|
141
|
-
|
|
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
|
-
}, [
|
|
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
|
-
|
|
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
|
)}
|