pixel-react 1.2.1 → 1.2.2
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/MenuOption/types.d.ts +7 -7
- 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 +75 -22
- package/lib/index.esm.js +26686 -870
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +26684 -864
- 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/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/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/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 +31 -4
- package/src/components/Form/Form.stories.tsx +172 -138
- 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 +8 -0
- package/src/components/IconButton/IconButton.scss +1 -1
- package/src/components/MenuOption/types.ts +7 -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 +10 -2
- 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,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
|
)}
|
|
@@ -36,29 +36,20 @@ export const Default: Story = {
|
|
|
36
36
|
{
|
|
37
37
|
value: "A1",
|
|
38
38
|
style: {
|
|
39
|
-
name: "Arial",
|
|
40
|
-
size: 12,
|
|
41
|
-
bold: true,
|
|
42
39
|
fontSize: "12px",
|
|
43
|
-
italic: false,
|
|
44
40
|
fontFamily: "Arial",
|
|
45
|
-
color: "
|
|
46
|
-
backgroundColor: "
|
|
47
|
-
border: { top: "1px solid black", bottom: "1px solid black", left: "1px solid black", right: "1px solid black" },
|
|
41
|
+
color: "var(--text-bg-highlight)",
|
|
42
|
+
backgroundColor: "var(--tooltip-bg-color)",
|
|
48
43
|
},
|
|
49
44
|
},
|
|
50
45
|
{
|
|
51
|
-
value: "B1",
|
|
46
|
+
value: "SUM(A1+B1)",
|
|
47
|
+
// isFormula:true,
|
|
52
48
|
style: {
|
|
53
|
-
name: "Arial",
|
|
54
|
-
size: 12,
|
|
55
|
-
bold: false,
|
|
56
49
|
fontSize: "12px",
|
|
57
|
-
italic: false,
|
|
58
50
|
fontFamily: "Arial",
|
|
59
|
-
color: "
|
|
60
|
-
backgroundColor: "
|
|
61
|
-
border: { top: "1px solid black", bottom: "1px solid black", left: "1px solid black", right: "1px solid black" },
|
|
51
|
+
color: "var(--text-bg-highlight)",
|
|
52
|
+
backgroundColor: "var(--brand-color)",
|
|
62
53
|
},
|
|
63
54
|
},
|
|
64
55
|
],
|
|
@@ -66,29 +57,19 @@ export const Default: Story = {
|
|
|
66
57
|
{
|
|
67
58
|
value: "A2",
|
|
68
59
|
style: {
|
|
69
|
-
name: "Arial",
|
|
70
|
-
size: 12,
|
|
71
|
-
bold: true,
|
|
72
60
|
fontSize: "12px",
|
|
73
|
-
italic: false,
|
|
74
61
|
fontFamily: "Arial",
|
|
75
|
-
color: "
|
|
76
|
-
backgroundColor: "
|
|
77
|
-
border: { top: "1px solid black", bottom: "1px solid black", left: "1px solid black", right: "1px solid black" },
|
|
62
|
+
color: "var(--drawer-footer-bg)",
|
|
63
|
+
backgroundColor: "var(--brand-color)",
|
|
78
64
|
},
|
|
79
65
|
},
|
|
80
66
|
{
|
|
81
67
|
value: "B2",
|
|
82
68
|
style: {
|
|
83
|
-
name: "Arial",
|
|
84
|
-
size: 12,
|
|
85
|
-
bold: false,
|
|
86
69
|
fontSize: "12px",
|
|
87
|
-
italic: false,
|
|
88
70
|
fontFamily: "Arial",
|
|
89
|
-
color: "
|
|
90
|
-
backgroundColor: "
|
|
91
|
-
border: { top: "1px solid black", bottom: "1px solid black", left: "1px solid black", right: "1px solid black" },
|
|
71
|
+
color: "var(--brand-color)",
|
|
72
|
+
backgroundColor: "var(--text-bg-highlight)",
|
|
92
73
|
},
|
|
93
74
|
},
|
|
94
75
|
],
|
|
@@ -6,22 +6,16 @@ import { Col, Container, Row } from '../../GridLayout/GridLayout';
|
|
|
6
6
|
|
|
7
7
|
interface ExcelSheetBarProps {
|
|
8
8
|
fileDetails: {
|
|
9
|
-
sheetNames: string[];
|
|
9
|
+
sheetNames: string[];
|
|
10
10
|
};
|
|
11
11
|
handleSheetChange: (name: string, index: number) => void;
|
|
12
|
-
contextMenu: (e: React.MouseEvent, name: string, index: number) => void;
|
|
13
|
-
addSheet: () => void;
|
|
14
12
|
selectedSheet: { name: string };
|
|
15
|
-
contextSelect: (e: React.MouseEvent) => void;
|
|
16
13
|
}
|
|
17
14
|
|
|
18
15
|
const ExcelSheetBar: React.FC<ExcelSheetBarProps> = ({
|
|
19
16
|
fileDetails,
|
|
20
17
|
handleSheetChange,
|
|
21
|
-
contextMenu,
|
|
22
|
-
addSheet,
|
|
23
18
|
selectedSheet,
|
|
24
|
-
contextSelect,
|
|
25
19
|
}) => {
|
|
26
20
|
const [activeTabId, setActiveTabId] = useState<string>('0');
|
|
27
21
|
|
|
@@ -34,10 +28,6 @@ const ExcelSheetBar: React.FC<ExcelSheetBarProps> = ({
|
|
|
34
28
|
name === selectedSheet.name ? 'active font-bold' : ''
|
|
35
29
|
}`}
|
|
36
30
|
onClick={() => handleSheetChange(name, index)}
|
|
37
|
-
onContextMenu={(e) => {
|
|
38
|
-
contextMenu(e, name, index);
|
|
39
|
-
contextSelect(e);
|
|
40
|
-
}}
|
|
41
31
|
>
|
|
42
32
|
{name}
|
|
43
33
|
</div>
|
|
@@ -57,7 +47,6 @@ const ExcelSheetBar: React.FC<ExcelSheetBarProps> = ({
|
|
|
57
47
|
name="plus_icon"
|
|
58
48
|
height={20}
|
|
59
49
|
width={20}
|
|
60
|
-
onClick={addSheet}
|
|
61
50
|
/>
|
|
62
51
|
</Tooltip>
|
|
63
52
|
</Col>
|