pixel-react 1.2.7 → 1.2.8
Sign up to get free protection for your applications and to get access to all the features.
- package/.yarn/install-state.gz +0 -0
- package/lib/components/Drawer/Types.d.ts +23 -12
- package/lib/components/{ExcelFile → Excel}/ExcelFile/ExcelFile.d.ts +1 -0
- package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/actions.d.ts +39 -10
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/reducer.d.ts +4 -0
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/reducerFunctions.d.ts +40 -0
- package/lib/components/{ExcelFile → Excel}/ExcelToolBar/ExcelToolBar.d.ts +7 -3
- package/lib/components/MenuOption/MenuOption.d.ts +1 -1
- package/lib/components/MenuOption/types.d.ts +4 -0
- package/lib/components/Select/Select.stories.d.ts +1 -0
- package/lib/components/Toastify/Toastify.d.ts +5 -4
- package/lib/components/Toastify/types.d.ts +1 -0
- package/lib/index.d.ts +68 -18
- package/lib/index.esm.js +1512 -1089
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +1513 -1089
- package/lib/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils/getSequentialPayload/getSequentialPayload.d.ts +2 -0
- package/lib/utils/getSequentialPayload/getSequentialPayload.stories.d.ts +10 -0
- package/lib/utils/getSequentialPayload/types.d.ts +30 -0
- package/package.json +3 -3
- package/src/assets/Themes/BaseTheme.scss +4 -0
- package/src/assets/icons/maximize_icon.svg +5 -0
- package/src/assets/styles/_fonts.scss +1 -1
- package/src/components/AllProjectsDropdown/AllProjectsDropdown.scss +15 -6
- package/src/components/AllProjectsDropdown/AllProjectsDropdown.stories.tsx +0 -5
- package/src/components/AllProjectsDropdown/AllProjectsDropdown.tsx +20 -10
- package/src/components/Drawer/Drawer.scss +1 -0
- package/src/components/Drawer/Types.ts +24 -13
- package/src/components/Excel/ExcelFile/ExcelFile.scss +62 -0
- package/src/components/Excel/ExcelFile/ExcelFile.tsx +312 -0
- package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/ActiveCell.tsx +2 -2
- package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Cell.tsx +3 -3
- package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/ColumnIndicator.tsx +4 -4
- package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/CornerIndicator.tsx +2 -2
- package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/DataEditor.tsx +1 -1
- package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/DataViewer.tsx +3 -3
- package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/FloatingRect.tsx +4 -4
- package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/RowIndicator.tsx +4 -4
- package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Spreadsheet.scss +26 -24
- package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Spreadsheet.tsx +13 -45
- package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Table.tsx +1 -1
- package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/actions.ts +88 -20
- package/src/components/Excel/ExcelFile/ExcelFileComponents/reducer.ts +495 -0
- package/src/components/Excel/ExcelFile/ExcelFileComponents/reducerFunctions.ts +758 -0
- package/src/components/{ExcelFile → Excel}/ExcelFile.stories.tsx +45 -0
- package/src/components/Excel/ExcelToolBar/ExcelToolBar.scss +36 -0
- package/src/components/Excel/ExcelToolBar/ExcelToolBar.tsx +346 -0
- package/src/components/Form/Form.scss +54 -35
- package/src/components/Form/Form.stories.tsx +264 -225
- package/src/components/Icon/iconList.ts +2 -1
- package/src/components/Input/Input.tsx +0 -1
- package/src/components/MenuOption/MenuOption.scss +0 -1
- package/src/components/MenuOption/MenuOption.stories.tsx +3 -0
- package/src/components/MenuOption/MenuOption.tsx +5 -4
- package/src/components/MenuOption/types.ts +4 -0
- package/src/components/MultiSelect/MultiSelect.scss +5 -1
- package/src/components/MultiSelect/MultiSelect.stories.tsx +17 -13
- package/src/components/MultiSelect/MultiSelect.tsx +27 -14
- package/src/components/Select/Select.stories.tsx +161 -18
- package/src/components/Select/Select.tsx +41 -33
- package/src/components/Table/Table.scss +6 -5
- package/src/components/Table/Table.stories.tsx +0 -9
- package/src/components/Table/Table.tsx +2 -2
- package/src/components/TableTree/TableTree.scss +1 -1
- package/src/components/TableTree/TableTree.tsx +3 -1
- package/src/components/Toastify/Toastify.stories.tsx +29 -10
- package/src/components/Toastify/Toastify.tsx +42 -16
- package/src/components/Toastify/types.ts +2 -0
- package/src/index.ts +4 -2
- package/src/utils/getSequentialPayload/getSequentialPayload.stories.tsx +75 -0
- package/src/utils/getSequentialPayload/getSequentialPayload.ts +29 -0
- package/src/utils/getSequentialPayload/types.ts +35 -0
- package/lib/components/AddButton/AddButton.d.ts +0 -5
- package/lib/components/AddButton/AddButton.stories.d.ts +0 -6
- package/lib/components/AddButton/index.d.ts +0 -1
- package/lib/components/AddButton/types.d.ts +0 -4
- package/lib/components/ExcelFile/ChangeExcelStyles.d.ts +0 -14
- package/lib/components/ExcelFile/ExcelFile/Excel/reducer.d.ts +0 -27
- package/lib/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.d.ts +0 -12
- package/lib/components/ExcelFile/ImportExcelStyles.d.ts +0 -24
- package/lib/utils/find/findAndInsert.d.ts +0 -7
- package/lib/utils/find/findAndInsert.stories.d.ts +0 -7
- package/src/components/ExcelFile/ExcelFile/Excel/reducer.ts +0 -952
- package/src/components/ExcelFile/ExcelFile/ExcelFile.scss +0 -24
- package/src/components/ExcelFile/ExcelFile/ExcelFile.tsx +0 -162
- package/src/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.scss +0 -16
- package/src/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.tsx +0 -68
- package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.scss +0 -19
- package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.tsx +0 -291
- package/src/fonts/Montserrat/Montserrat-Medium.ttf +0 -0
- package/src/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
- package/src/fonts/Montserrat/Montserrat-SemiBold.ttf +0 -0
- package/src/fonts/Poppins/Poppins-Black.ttf +0 -0
- package/src/fonts/Poppins/Poppins-BlackItalic.ttf +0 -0
- package/src/fonts/Poppins/Poppins-BoldItalic.ttf +0 -0
- package/src/fonts/Poppins/Poppins-ExtraBold.ttf +0 -0
- package/src/fonts/Poppins/Poppins-ExtraBoldItalic.ttf +0 -0
- package/src/fonts/Poppins/Poppins-ExtraLight.ttf +0 -0
- package/src/fonts/Poppins/Poppins-ExtraLightItalic.ttf +0 -0
- package/src/fonts/Poppins/Poppins-Italic.ttf +0 -0
- package/src/fonts/Poppins/Poppins-Light.ttf +0 -0
- package/src/fonts/Poppins/Poppins-LightItalic.ttf +0 -0
- package/src/fonts/Poppins/Poppins-MediumItalic.ttf +0 -0
- package/src/fonts/Poppins/Poppins-SemiBoldItalic.ttf +0 -0
- package/src/fonts/Poppins/Poppins-Thin.ttf +0 -0
- package/src/fonts/Poppins/Poppins-ThinItalic.ttf +0 -0
- /package/lib/components/{ExcelFile → Excel}/ColorBarSelector/ColorBarSelector.d.ts +0 -0
- /package/lib/components/{ExcelFile → Excel}/ContextMenu/ContextMenu.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/ActiveCell.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Cell.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/ColumnIndicator.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Copied.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/CornerIndicator.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/DataEditor.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/DataViewer.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/FloatingRect.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/HeaderRow.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Row.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/RowIndicator.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Selected.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Spreadsheet.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Table.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/areModelsEqual.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/context.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/engine.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/formula.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/index.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/point-graph.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/point-hash.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/point-set.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/index.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/matrix.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/point-range.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/point.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/selection.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/types.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/use-dispatch.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/use-selector.d.ts +0 -0
- /package/lib/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/util.d.ts +0 -0
- /package/lib/components/{ExcelFile → Excel}/ExcelFile.stories.d.ts +0 -0
- /package/lib/components/{ExcelFile → Excel}/Types.d.ts +0 -0
- /package/lib/components/{ExcelFile → Excel}/index.d.ts +0 -0
- /package/src/components/{ExcelFile/ColorBarselector → Excel/ColorBarSelector}/ColorBarSelector.scss +0 -0
- /package/src/components/{ExcelFile/ColorBarselector → Excel/ColorBarSelector}/ColorBarSelector.tsx +0 -0
- /package/src/components/{ExcelFile → Excel}/ContextMenu/ContextMenu.scss +0 -0
- /package/src/components/{ExcelFile → Excel}/ContextMenu/ContextMenu.tsx +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Copied.tsx +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/HeaderRow.tsx +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Row.tsx +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Selected.tsx +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/areModelsEqual.ts +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/context.ts +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/engine.ts +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/formula.ts +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/index.ts +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/point-graph.ts +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/point-hash.ts +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/engine/point-set.ts +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/index.ts +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/matrix.ts +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/point-range.ts +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/point.ts +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/selection.ts +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/types.ts +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/typings/fast-formula-parser.d.ts +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/use-dispatch.ts +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/use-selector.ts +0 -0
- /package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/util.ts +0 -0
- /package/src/components/{ExcelFile → Excel}/Types.ts +0 -0
- /package/src/components/{ExcelFile → Excel}/index.ts +0 -0
@@ -0,0 +1,312 @@
|
|
1
|
+
import React, { useState, useRef, useEffect } from 'react';
|
2
|
+
import Spreadsheet, { CellBase } from './ExcelFileComponents/index';
|
3
|
+
import * as Matrix from './ExcelFileComponents/matrix';
|
4
|
+
import './ExcelFile.scss';
|
5
|
+
import { Col, Row } from '../../GridLayout/GridLayout';
|
6
|
+
import Tooltip from '../../Tooltip';
|
7
|
+
import Icon from '../../Icon';
|
8
|
+
import Toastify from '../../Toastify';
|
9
|
+
import { toast } from '../../Toastify/Toastify';
|
10
|
+
|
11
|
+
interface ExcelFileProps {
|
12
|
+
/** The Excel data containing sheets and their content */
|
13
|
+
excelData: {
|
14
|
+
sheets: WorkSheet[];
|
15
|
+
};
|
16
|
+
|
17
|
+
/** Optional: Provide context menu options for actions like right-click */
|
18
|
+
contextOption?: {
|
19
|
+
name: string;
|
20
|
+
title: React.ReactNode;
|
21
|
+
action: () => void;
|
22
|
+
}[];
|
23
|
+
|
24
|
+
/** Controls whether the toolbar is shown, disabled, or hidden */
|
25
|
+
toolbar?: 'show' | 'disable' | 'hide';
|
26
|
+
|
27
|
+
/** Callback function to save the Excel data */
|
28
|
+
onSave?: (excelData?: any) => void;
|
29
|
+
}
|
30
|
+
|
31
|
+
const ExcelFile: React.FC<ExcelFileProps> = ({
|
32
|
+
excelData,
|
33
|
+
onSave = () => {},
|
34
|
+
}) => {
|
35
|
+
const [sheetNames, setSheetNames] = useState<string[]>([]);
|
36
|
+
const EmptyRow: CellBase = {
|
37
|
+
value: '',
|
38
|
+
style: {
|
39
|
+
color: 'var(--text-color)',
|
40
|
+
backgroundColor: 'var(--drawer-footer-bg)',
|
41
|
+
borderColor: 'var(--toggle-strip-color)',
|
42
|
+
},
|
43
|
+
};
|
44
|
+
const [selectedSheet, setSelectedSheet] = useState<{
|
45
|
+
name: string;
|
46
|
+
index: number;
|
47
|
+
}>({ name: 'defaultSheet', index: 0 });
|
48
|
+
|
49
|
+
const [worksheetsData, setWorksheetsData] = useState<{
|
50
|
+
[key: string]: Matrix.Matrix<CellBase>;
|
51
|
+
}>({ defaultSheet: [[EmptyRow]] });
|
52
|
+
|
53
|
+
const [selectedSheetData, setSelectedSheetData] = useState<
|
54
|
+
Matrix.Matrix<CellBase>
|
55
|
+
>([[EmptyRow]]);
|
56
|
+
|
57
|
+
let pageRef = useRef<string>('');
|
58
|
+
const sheetRef = useRef<HTMLDivElement | null>(null);
|
59
|
+
|
60
|
+
let checkVal = (val: any) => {
|
61
|
+
if (val === undefined || val === null) {
|
62
|
+
return null;
|
63
|
+
}
|
64
|
+
return val;
|
65
|
+
};
|
66
|
+
useEffect(() => {
|
67
|
+
const payload = excelData;
|
68
|
+
const sheetNames = payload.sheets.map((e) => e.sheetName);
|
69
|
+
setSheetNames(sheetNames);
|
70
|
+
if (sheetNames.length > 0) {
|
71
|
+
pageRef.current = sheetNames[0] ? sheetNames[0] : '';
|
72
|
+
setSelectedSheet({ name: sheetNames[0] ? sheetNames[0] : '', index: 0 });
|
73
|
+
}
|
74
|
+
const newWorksheetsData: { [key: string]: Matrix.Matrix<CellBase> } = {};
|
75
|
+
payload.sheets.forEach((sheet) => {
|
76
|
+
const sheetName = sheet.sheetName;
|
77
|
+
const json = sheet.data;
|
78
|
+
const maxRows = Math.max(15, json.length + 2);
|
79
|
+
const maxCols = Math.max(
|
80
|
+
15,
|
81
|
+
Math.max(...json.map((row) => row.length)) + 2
|
82
|
+
);
|
83
|
+
|
84
|
+
let spreadsheetData: Matrix.Matrix<CellBase> = Array.from(
|
85
|
+
{ length: maxRows },
|
86
|
+
() => Array.from({ length: maxCols }, () => EmptyRow)
|
87
|
+
);
|
88
|
+
json.forEach((row, rowIndex) => {
|
89
|
+
row.forEach((cell, colIndex) => {
|
90
|
+
if (rowIndex < maxRows && colIndex < maxCols) {
|
91
|
+
if (!spreadsheetData[rowIndex]) {
|
92
|
+
spreadsheetData[rowIndex] = [];
|
93
|
+
}
|
94
|
+
spreadsheetData[rowIndex][colIndex] = {
|
95
|
+
value: checkVal(cell.value),
|
96
|
+
style: cell.style,
|
97
|
+
type: true,
|
98
|
+
};
|
99
|
+
}
|
100
|
+
});
|
101
|
+
});
|
102
|
+
|
103
|
+
newWorksheetsData[sheetName] = spreadsheetData;
|
104
|
+
});
|
105
|
+
setWorksheetsData(newWorksheetsData);
|
106
|
+
const firstSheetName = Object.keys(newWorksheetsData)[0];
|
107
|
+
if (firstSheetName && newWorksheetsData[firstSheetName] !== undefined) {
|
108
|
+
setSelectedSheetData(newWorksheetsData[firstSheetName]);
|
109
|
+
}
|
110
|
+
}, []);
|
111
|
+
|
112
|
+
const onEvaluateChange = (data: Matrix.Matrix<CellBase>) => {
|
113
|
+
setWorksheetsData((prev) => ({ ...prev, [pageRef.current]: data }));
|
114
|
+
onSave()
|
115
|
+
};
|
116
|
+
|
117
|
+
const [editingSheet, setEditingSheet] = useState<number | null>(null);
|
118
|
+
|
119
|
+
const handleAddSheet = () => {
|
120
|
+
const generateUniqueSheetName = (
|
121
|
+
baseName: string,
|
122
|
+
existingNames: string[]
|
123
|
+
) => {
|
124
|
+
let newName = baseName;
|
125
|
+
let counter = 1;
|
126
|
+
while (existingNames.includes(newName)) {
|
127
|
+
newName = `${baseName}${counter}`;
|
128
|
+
counter++;
|
129
|
+
}
|
130
|
+
return newName;
|
131
|
+
};
|
132
|
+
const baseName = 'NewSheet';
|
133
|
+
const existingSheetNames = sheetNames;
|
134
|
+
const newSheetName = generateUniqueSheetName(baseName, existingSheetNames);
|
135
|
+
const newSheetData = Array.from({ length: 15 }, () =>
|
136
|
+
Array.from({ length: 15 }, () => EmptyRow)
|
137
|
+
);
|
138
|
+
setSheetNames((prev) => [...prev, newSheetName]);
|
139
|
+
setSelectedSheet({ index: sheetNames?.length, name: newSheetName });
|
140
|
+
setWorksheetsData({ ...worksheetsData, [newSheetName]: newSheetData });
|
141
|
+
setSelectedSheetData(newSheetData);
|
142
|
+
pageRef.current = newSheetName;
|
143
|
+
};
|
144
|
+
|
145
|
+
const handleNameChange = (
|
146
|
+
event: React.SyntheticEvent<HTMLDivElement>,
|
147
|
+
index: number,
|
148
|
+
name: string
|
149
|
+
): void => {
|
150
|
+
const target = event.target as HTMLDivElement;
|
151
|
+
if (!target) {
|
152
|
+
setEditingSheet(null);
|
153
|
+
return;
|
154
|
+
}
|
155
|
+
|
156
|
+
const updatedSheetValue = target.textContent?.trim();
|
157
|
+
|
158
|
+
if (!updatedSheetValue) {
|
159
|
+
toast.warning('Sheet name cannot be empty.');
|
160
|
+
target.textContent = selectedSheet.name;
|
161
|
+
setEditingSheet(null);
|
162
|
+
return;
|
163
|
+
}
|
164
|
+
|
165
|
+
if (updatedSheetValue.length > 30) {
|
166
|
+
toast.warning('The sheet name cannot be greater than 30 characters');
|
167
|
+
target.textContent = selectedSheet.name;
|
168
|
+
setEditingSheet(null);
|
169
|
+
return;
|
170
|
+
}
|
171
|
+
|
172
|
+
if (
|
173
|
+
sheetNames.includes(updatedSheetValue) &&
|
174
|
+
sheetNames[index] !== updatedSheetValue
|
175
|
+
) {
|
176
|
+
toast.warning('Sheet name already exists');
|
177
|
+
target.textContent = selectedSheet.name;
|
178
|
+
setEditingSheet(null);
|
179
|
+
return;
|
180
|
+
}
|
181
|
+
|
182
|
+
let updatedSheetNames = sheetNames;
|
183
|
+
|
184
|
+
updatedSheetNames.splice(index, 1, updatedSheetValue);
|
185
|
+
|
186
|
+
let remainingSheets = worksheetsData;
|
187
|
+
|
188
|
+
let updatedData = replaceKeyValueByKeyName(
|
189
|
+
remainingSheets,
|
190
|
+
name,
|
191
|
+
updatedSheetValue,
|
192
|
+
selectedSheetData
|
193
|
+
);
|
194
|
+
pageRef.current = updatedSheetValue;
|
195
|
+
setSelectedSheet((prev) => ({ ...prev, name: updatedSheetValue }));
|
196
|
+
setWorksheetsData(updatedData);
|
197
|
+
setEditingSheet(null);
|
198
|
+
};
|
199
|
+
|
200
|
+
function replaceKeyValueByKeyName(
|
201
|
+
obj: {
|
202
|
+
[key: string]: Matrix.Matrix<CellBase>;
|
203
|
+
},
|
204
|
+
oldKey: string,
|
205
|
+
newKey: string,
|
206
|
+
newValue: Matrix.Matrix<CellBase>
|
207
|
+
) {
|
208
|
+
if (!(oldKey in obj)) {
|
209
|
+
throw new Error(`Key "${oldKey}" not found in object`);
|
210
|
+
}
|
211
|
+
delete obj[oldKey];
|
212
|
+
obj[newKey] = newValue;
|
213
|
+
return obj;
|
214
|
+
}
|
215
|
+
|
216
|
+
const handleSheetChange = (name: string, index: number) => {
|
217
|
+
setSelectedSheet({ index, name });
|
218
|
+
setSheetNames((prev: string[]) => {
|
219
|
+
const updatedSheetNames = [...prev];
|
220
|
+
updatedSheetNames[index] = name;
|
221
|
+
return updatedSheetNames;
|
222
|
+
});
|
223
|
+
|
224
|
+
const selectedSheetData = worksheetsData[name];
|
225
|
+
if (selectedSheetData) {
|
226
|
+
setSelectedSheetData(selectedSheetData);
|
227
|
+
} else {
|
228
|
+
setSelectedSheetData([[EmptyRow]]);
|
229
|
+
}
|
230
|
+
pageRef.current = name;
|
231
|
+
};
|
232
|
+
|
233
|
+
const setCursorToEnd = (element: HTMLDivElement): void => {
|
234
|
+
const range = document.createRange();
|
235
|
+
const selection = window.getSelection();
|
236
|
+
range.selectNodeContents(element);
|
237
|
+
range.collapse(false);
|
238
|
+
selection?.removeAllRanges();
|
239
|
+
selection?.addRange(range);
|
240
|
+
};
|
241
|
+
|
242
|
+
return (
|
243
|
+
<div className="excel-page">
|
244
|
+
{sheetNames.length > 0 && (
|
245
|
+
<div className="excel-book">
|
246
|
+
<div ref={sheetRef} className="excel-sheet">
|
247
|
+
<Spreadsheet
|
248
|
+
data={selectedSheetData}
|
249
|
+
onEvaluatedDataChange={onEvaluateChange}
|
250
|
+
/>
|
251
|
+
</div>
|
252
|
+
<Row className="sheet-bar">
|
253
|
+
<Col size={0} className="add-sheet-icon">
|
254
|
+
<Tooltip title="Add Sheet" placement="top">
|
255
|
+
<Icon
|
256
|
+
className="cursor-pointer ml-1"
|
257
|
+
hoverEffect={true}
|
258
|
+
onClick={() => {
|
259
|
+
handleAddSheet();
|
260
|
+
}}
|
261
|
+
name="plus_icon"
|
262
|
+
height={20}
|
263
|
+
width={20}
|
264
|
+
/>
|
265
|
+
</Tooltip>
|
266
|
+
</Col>
|
267
|
+
<Col size={10}>
|
268
|
+
<div className="excel-tab-container">
|
269
|
+
{sheetNames.map((name, index) => (
|
270
|
+
<div
|
271
|
+
key={name}
|
272
|
+
className={`excel-tab-list ${
|
273
|
+
name === selectedSheet.name ? 'active' : ''
|
274
|
+
}`}
|
275
|
+
onClick={() => {
|
276
|
+
handleSheetChange(name, index);
|
277
|
+
}}
|
278
|
+
suppressContentEditableWarning={editingSheet === index}
|
279
|
+
onDoubleClick={(e) => {
|
280
|
+
setEditingSheet(index);
|
281
|
+
if (editingSheet === null) {
|
282
|
+
setTimeout(
|
283
|
+
() => setCursorToEnd(e.target as HTMLDivElement),
|
284
|
+
0
|
285
|
+
);
|
286
|
+
}
|
287
|
+
}}
|
288
|
+
contentEditable={editingSheet === index}
|
289
|
+
onBlur={(e) => {
|
290
|
+
handleNameChange(e, index, name);
|
291
|
+
}}
|
292
|
+
onKeyDown={(e) => {
|
293
|
+
if (e.key === 'Enter') {
|
294
|
+
e.preventDefault();
|
295
|
+
handleNameChange(e, index, name);
|
296
|
+
}
|
297
|
+
}}
|
298
|
+
>
|
299
|
+
{name}
|
300
|
+
</div>
|
301
|
+
))}
|
302
|
+
</div>
|
303
|
+
</Col>
|
304
|
+
</Row>
|
305
|
+
</div>
|
306
|
+
)}
|
307
|
+
<Toastify />
|
308
|
+
</div>
|
309
|
+
);
|
310
|
+
};
|
311
|
+
|
312
|
+
export default ExcelFile;
|
@@ -107,8 +107,8 @@ const ActiveCell: React.FC<Props> = (props) => {
|
|
107
107
|
<div
|
108
108
|
ref={rootRef}
|
109
109
|
className={classnames(
|
110
|
-
'
|
111
|
-
`
|
110
|
+
'ff-spreadsheet-active-cell',
|
111
|
+
`ff-spreadsheet-active-cell--${mode}`
|
112
112
|
)}
|
113
113
|
style={dimensions}
|
114
114
|
onClick={mode === 'view' && !readOnly ? edit : undefined}
|
package/src/components/{ExcelFile/ExcelFile/Excel → Excel/ExcelFile/ExcelFileComponents}/Cell.tsx
RENAMED
@@ -102,9 +102,9 @@ export const Cell: React.FC<Types.CellComponentProps> = ({
|
|
102
102
|
return (
|
103
103
|
<td
|
104
104
|
ref={rootRef}
|
105
|
-
|
106
|
-
className={classnames('
|
107
|
-
'
|
105
|
+
style={data?.style}
|
106
|
+
className={classnames('ff-spreadsheet-cell', data?.className, {
|
107
|
+
'ff-spreadsheet-active-cell': active || dragging,
|
108
108
|
})}
|
109
109
|
onMouseEnter={handleMouseOver}
|
110
110
|
onMouseDown={handleMouseDown}
|
@@ -25,10 +25,10 @@ const ColumnIndicator: Types.ColumnIndicatorComponent = ({
|
|
25
25
|
setWidth(newWidth);
|
26
26
|
|
27
27
|
const selectedAllRow = document.querySelector(
|
28
|
-
'
|
28
|
+
'ff-spreadsheet-floating-rect--selected'
|
29
29
|
);
|
30
30
|
const selectedSingleRow = document.querySelector(
|
31
|
-
'
|
31
|
+
'ff-spreadsheet-active-cell'
|
32
32
|
);
|
33
33
|
|
34
34
|
// If the element exists, update its height
|
@@ -68,8 +68,8 @@ const ColumnIndicator: Types.ColumnIndicatorComponent = ({
|
|
68
68
|
return (
|
69
69
|
<th
|
70
70
|
style={{ minWidth: `${width}px`, position: 'relative' }} // Use dynamic width
|
71
|
-
className={classNames('
|
72
|
-
'
|
71
|
+
className={classNames('ff-spreadsheet-header', {
|
72
|
+
'ff-spreadsheet-header--selected': selected,
|
73
73
|
})}
|
74
74
|
onClick={handleClick}
|
75
75
|
tabIndex={0}
|
@@ -15,8 +15,8 @@ const CornerIndicator: Types.CornerIndicatorComponent = ({
|
|
15
15
|
}, [onSelect]);
|
16
16
|
return (
|
17
17
|
<th
|
18
|
-
className={classNames('
|
19
|
-
'
|
18
|
+
className={classNames('ff-spreadsheet-header', {
|
19
|
+
'ff-spreadsheet-header--selected': selected,
|
20
20
|
})}
|
21
21
|
onClick={handleClick}
|
22
22
|
tabIndex={0}
|
@@ -22,7 +22,7 @@ const DataEditor: React.FC<Types.DataEditorProps> = ({ onChange, cell }) => {
|
|
22
22
|
const value = cell?.value ?? '';
|
23
23
|
|
24
24
|
return (
|
25
|
-
<div className="
|
25
|
+
<div className="ff-spreadsheet-data-editor">
|
26
26
|
<input
|
27
27
|
ref={inputRef}
|
28
28
|
type="text"
|
@@ -14,13 +14,13 @@ const DataViewer = <Cell extends Types.CellBase<Value>, Value>({
|
|
14
14
|
const value = getValue(cell, evaluatedCell);
|
15
15
|
|
16
16
|
return typeof value === 'boolean' ? (
|
17
|
-
<span className="
|
17
|
+
<span className="ff-spreadsheet-data-viewer ff-spreadsheet-data-viewer--boolean">
|
18
18
|
{convertBooleanToText(value)}
|
19
19
|
</span>
|
20
20
|
) : (
|
21
21
|
<span
|
22
|
-
className={classNames('
|
23
|
-
'
|
22
|
+
className={classNames('ff-spreadsheet-data-viewer', {
|
23
|
+
'ff-spreadsheet-data-viewer--preserve-breaks': hasLineBreaker(value),
|
24
24
|
})}
|
25
25
|
>
|
26
26
|
{value}
|
@@ -18,10 +18,10 @@ const FloatingRect: React.FC<Props> = ({
|
|
18
18
|
const { width, height, top, left } = dimensions || {};
|
19
19
|
return (
|
20
20
|
<div
|
21
|
-
className={classnames('
|
22
|
-
[`
|
23
|
-
'
|
24
|
-
'
|
21
|
+
className={classnames('ff-spreadsheet-floating-rect', {
|
22
|
+
[`ff-spreadsheet-floating-rect--${variant}`]: variant,
|
23
|
+
'ff-spreadsheet-floating-rect--dragging': dragging,
|
24
|
+
'ff-spreadsheet-floating-rect--hidden': hidden,
|
25
25
|
})}
|
26
26
|
style={{ width, height, top, left }}
|
27
27
|
/>
|
@@ -23,10 +23,10 @@ const RowIndicator: Types.RowIndicatorComponent = ({
|
|
23
23
|
setHeight(newHeight);
|
24
24
|
// Fetch the floating rectangle element from the DOM
|
25
25
|
const selectedAllRow = document.querySelector(
|
26
|
-
'.
|
26
|
+
'.ff-spreadsheet-floating-rect--selected'
|
27
27
|
);
|
28
28
|
const selectedSingleRow = document.querySelector(
|
29
|
-
'.
|
29
|
+
'.ff-spreadsheet-active-cell'
|
30
30
|
);
|
31
31
|
|
32
32
|
// If the element exists, update its height
|
@@ -60,8 +60,8 @@ const RowIndicator: Types.RowIndicatorComponent = ({
|
|
60
60
|
return (
|
61
61
|
<th
|
62
62
|
style={{ height: `${height}px`, minWidth: '60px', position: 'relative' }}
|
63
|
-
className={classNames('
|
64
|
-
'
|
63
|
+
className={classNames('ff-spreadsheet-header', {
|
64
|
+
'ff-spreadsheet-header--selected': selected,
|
65
65
|
})}
|
66
66
|
onClick={handleClick}
|
67
67
|
tabIndex={0}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
.
|
1
|
+
.ff-spreadsheet{
|
2
2
|
--background-color: var(--drawer-footer-bg);
|
3
3
|
--text-color: var(--text-color);
|
4
4
|
--readonly-text-color: var(--toggle-strip-active);
|
@@ -15,28 +15,30 @@
|
|
15
15
|
display: inline-block;
|
16
16
|
}
|
17
17
|
|
18
|
-
.
|
18
|
+
.ff-spreadsheet-active-cell {
|
19
19
|
position: absolute;
|
20
20
|
border: 2px solid var(--outline-color);
|
21
21
|
box-sizing: border-box;
|
22
22
|
}
|
23
23
|
|
24
|
-
.
|
24
|
+
.ff-spreadsheet-active-cell--edit {
|
25
25
|
background: var(--background-color);
|
26
26
|
box-shadow: var(--elevation);
|
27
27
|
}
|
28
28
|
|
29
|
-
.
|
29
|
+
.ff-spreadsheet-table {
|
30
|
+
margin-top: 20px;
|
30
31
|
border-collapse: collapse;
|
31
32
|
table-layout: fixed;
|
32
33
|
}
|
33
34
|
|
34
|
-
.
|
35
|
+
.ff-spreadsheet-cell {
|
35
36
|
outline: none;
|
36
37
|
position: relative;
|
38
|
+
z-index:0;
|
37
39
|
}
|
38
40
|
|
39
|
-
.
|
41
|
+
.ff-spreadsheet-active-cell .Selection_dot {
|
40
42
|
background-color: var(--elevation);
|
41
43
|
height: 7px;
|
42
44
|
width: 7px;
|
@@ -48,12 +50,12 @@
|
|
48
50
|
cursor: crosshair;
|
49
51
|
}
|
50
52
|
|
51
|
-
.
|
53
|
+
.ff-spreadsheet-cell--readonly {
|
52
54
|
color: var(--readonly-text-color);
|
53
55
|
}
|
54
56
|
|
55
|
-
.
|
56
|
-
.
|
57
|
+
.ff-spreadsheet-cell,
|
58
|
+
.ff-spreadsheet-header {
|
57
59
|
border: 0.1px solid var(--border-color);
|
58
60
|
overflow: hidden;
|
59
61
|
word-break: keep-all;
|
@@ -63,35 +65,35 @@
|
|
63
65
|
user-select: none;
|
64
66
|
}
|
65
67
|
|
66
|
-
.
|
68
|
+
.ff-spreadsheet-header {
|
67
69
|
background: var(--header-background-color);
|
68
70
|
color: var(--readonly-text-color);
|
69
71
|
text-align: center;
|
70
72
|
}
|
71
73
|
|
72
|
-
.
|
74
|
+
.ff-spreadsheet-header--selected {
|
73
75
|
background: var(--brand-color);
|
74
76
|
color: var(--tooltip-text-color);
|
75
77
|
}
|
76
78
|
|
77
|
-
.
|
78
|
-
.
|
79
|
-
.
|
79
|
+
.ff-spreadsheet-header,
|
80
|
+
.ff-spreadsheet-data-viewer,
|
81
|
+
.ff-spreadsheet-data-editor input {
|
80
82
|
padding: 4px;
|
81
83
|
box-sizing: border-box;
|
82
84
|
}
|
83
85
|
|
84
|
-
.
|
86
|
+
.ff-spreadsheet-data-viewer--preserve-breaks {
|
85
87
|
white-space: pre-wrap;
|
86
88
|
}
|
87
89
|
|
88
|
-
.
|
89
|
-
.
|
90
|
+
.ff-spreadsheet-data-editor,
|
91
|
+
.ff-spreadsheet-data-editor input {
|
90
92
|
width: 100%;
|
91
93
|
height: 100%;
|
92
94
|
}
|
93
95
|
|
94
|
-
.
|
96
|
+
.ff-spreadsheet-data-editor input {
|
95
97
|
font: inherit;
|
96
98
|
color: inherit;
|
97
99
|
background: none;
|
@@ -100,29 +102,29 @@
|
|
100
102
|
margin: 0;
|
101
103
|
}
|
102
104
|
|
103
|
-
.
|
105
|
+
.ff-spreadsheet-data-viewer--boolean {
|
104
106
|
text-align: center;
|
105
107
|
}
|
106
108
|
|
107
|
-
.
|
109
|
+
.ff-spreadsheet-floating-rect {
|
108
110
|
position: absolute;
|
109
111
|
pointer-events: none;
|
110
112
|
box-sizing: border-box;
|
111
113
|
}
|
112
114
|
|
113
|
-
.
|
115
|
+
.ff-spreadsheet-floating-rect--hidden {
|
114
116
|
display: none;
|
115
117
|
}
|
116
118
|
|
117
|
-
.
|
119
|
+
.ff-spreadsheet-floating-rect--selected {
|
118
120
|
background: var(--outline-background-color);
|
119
121
|
border: 2px var(--outline-color) solid;
|
120
122
|
}
|
121
123
|
|
122
|
-
.
|
124
|
+
.ff-spreadsheet-floating-rect--dragging {
|
123
125
|
border: none;
|
124
126
|
}
|
125
127
|
|
126
|
-
.
|
128
|
+
.ff-spreadsheet-floating-rect--copied {
|
127
129
|
border: 2px var(--outline-color) dashed;
|
128
130
|
}
|