pixel-react 1.1.8 → 1.1.9
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/components/AddButton/AddButton.d.ts +5 -0
- package/lib/components/AddButton/AddButton.stories.d.ts +6 -0
- package/lib/components/AddButton/index.d.ts +1 -0
- package/lib/components/AddButton/types.d.ts +4 -0
- package/lib/components/ExcelFile/ChangeExcelStyles.d.ts +14 -0
- package/lib/components/ExcelFile/ColorBarSelector/ColorBarSelector.d.ts +8 -0
- package/lib/components/ExcelFile/ContextMenu/ContextMenu.d.ts +4 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/ActiveCell.d.ts +7 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/Cell.d.ts +4 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/ColumnIndicator.d.ts +5 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/Copied.d.ts +3 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/CornerIndicator.d.ts +5 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/DataEditor.d.ts +5 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/DataViewer.d.ts +8 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/FloatingRect.d.ts +10 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/HeaderRow.d.ts +3 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/Row.d.ts +3 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/RowIndicator.d.ts +5 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/Selected.d.ts +3 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/Spreadsheet.d.ts +81 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/Table.d.ts +3 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/actions.d.ts +130 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/areModelsEqual.d.ts +1 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/context.d.ts +8 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/engine.d.ts +22 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/formula.d.ts +17 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/index.d.ts +2 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-graph.d.ts +21 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-hash.d.ts +3 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/engine/point-set.d.ts +24 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/index.d.ts +13 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/matrix.d.ts +67 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/point-range.d.ts +22 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/point.d.ts +11 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/reducer.d.ts +27 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/selection.d.ts +95 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/types.d.ts +215 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/use-dispatch.d.ts +3 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/use-selector.d.ts +3 -0
- package/lib/components/ExcelFile/ExcelFile/Excel/util.d.ts +45 -0
- package/lib/components/ExcelFile/ExcelFile/ExcelFile.d.ts +3 -0
- package/lib/components/ExcelFile/ExcelFile.stories.d.ts +6 -0
- package/lib/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.d.ts +15 -0
- package/lib/components/ExcelFile/ExcelToolBar/ExcelToolBar.d.ts +3 -0
- package/lib/components/ExcelFile/ImportExcelStyles.d.ts +24 -0
- package/lib/components/ExcelFile/Types.d.ts +176 -0
- package/lib/components/ExcelFile/index.d.ts +1 -0
- package/lib/components/IconRadioGroup/IconRadioGroup.d.ts +5 -0
- package/lib/components/IconRadioGroup/IconRadioGroup.stories.d.ts +7 -0
- package/lib/components/IconRadioGroup/index.d.ts +1 -0
- package/lib/components/IconRadioGroup/type.d.ts +41 -0
- package/lib/index.d.ts +45 -1
- package/lib/index.esm.js +682 -244
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +682 -243
- package/lib/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils/find/findAndInsert.d.ts +7 -0
- package/lib/utils/find/findAndInsert.stories.d.ts +7 -0
- package/package.json +4 -2
- package/src/assets/Themes/BaseTheme.scss +1 -0
- package/src/assets/Themes/DarkTheme.scss +1 -0
- package/src/assets/icons/all_borders.svg +3 -0
- package/src/assets/icons/bold.svg +3 -0
- package/src/assets/icons/border_bottom.svg +3 -0
- package/src/assets/icons/border_left.svg +3 -0
- package/src/assets/icons/border_right.svg +3 -0
- package/src/assets/icons/border_top.svg +3 -0
- package/src/assets/icons/clone_icon.svg +3 -0
- package/src/assets/icons/double_underline.svg +5 -0
- package/src/assets/icons/fill_color.svg +7 -0
- package/src/assets/icons/formate_painter.svg +5 -0
- package/src/assets/icons/full_access_icon.svg +4 -0
- package/src/assets/icons/history_icon.svg +19 -0
- package/src/assets/icons/italic.svg +3 -0
- package/src/assets/icons/jira.svg +3 -0
- package/src/assets/icons/linked_defects.svg +11 -0
- package/src/assets/icons/move_icon.svg +5 -0
- package/src/assets/icons/no_access_icon.svg +4 -0
- package/src/assets/icons/no_border.svg +3 -0
- package/src/assets/icons/strike_through.svg +3 -0
- package/src/assets/icons/text_align_center.svg +3 -0
- package/src/assets/icons/text_align_left.svg +3 -0
- package/src/assets/icons/text_align_right.svg +3 -0
- package/src/assets/icons/text_color.svg +3 -0
- package/src/assets/icons/underline.svg +4 -0
- package/src/assets/icons/view_access_icon.svg +4 -0
- package/src/components/AppHeader/AppHeader.scss +14 -9
- package/src/components/AppHeader/AppHeader.stories.tsx +1 -0
- package/src/components/AppHeader/AppHeader.tsx +7 -5
- package/src/components/ExcelFile/ChangeExcelStyles.tsx +78 -0
- package/src/components/ExcelFile/ColorBarselector/ColorBarSelector.scss +13 -0
- package/src/components/ExcelFile/ColorBarselector/ColorBarSelector.tsx +43 -0
- package/src/components/ExcelFile/ContextMenu/ContextMenu.scss +102 -0
- package/src/components/ExcelFile/ContextMenu/ContextMenu.tsx +104 -0
- package/src/components/ExcelFile/ExcelFile/Excel/ActiveCell.tsx +131 -0
- package/src/components/ExcelFile/ExcelFile/Excel/Cell.tsx +201 -0
- package/src/components/ExcelFile/ExcelFile/Excel/ColumnIndicator.tsx +123 -0
- package/src/components/ExcelFile/ExcelFile/Excel/Copied.tsx +25 -0
- package/src/components/ExcelFile/ExcelFile/Excel/CornerIndicator.tsx +49 -0
- package/src/components/ExcelFile/ExcelFile/Excel/DataEditor.tsx +37 -0
- package/src/components/ExcelFile/ExcelFile/Excel/DataViewer.tsx +46 -0
- package/src/components/ExcelFile/ExcelFile/Excel/FloatingRect.tsx +31 -0
- package/src/components/ExcelFile/ExcelFile/Excel/HeaderRow.tsx +5 -0
- package/src/components/ExcelFile/ExcelFile/Excel/Row.tsx +5 -0
- package/src/components/ExcelFile/ExcelFile/Excel/RowIndicator.tsx +102 -0
- package/src/components/ExcelFile/ExcelFile/Excel/Selected.tsx +32 -0
- package/src/components/ExcelFile/ExcelFile/Excel/Spreadsheet.css +144 -0
- package/src/components/ExcelFile/ExcelFile/Excel/Spreadsheet.tsx +494 -0
- package/src/components/ExcelFile/ExcelFile/Excel/Table.tsx +19 -0
- package/src/components/ExcelFile/ExcelFile/Excel/actions.ts +302 -0
- package/src/components/ExcelFile/ExcelFile/Excel/areModelsEqual.ts +18 -0
- package/src/components/ExcelFile/ExcelFile/Excel/context.ts +12 -0
- package/src/components/ExcelFile/ExcelFile/Excel/engine/engine.ts +200 -0
- package/src/components/ExcelFile/ExcelFile/Excel/engine/formula.ts +137 -0
- package/src/components/ExcelFile/ExcelFile/Excel/engine/index.ts +2 -0
- package/src/components/ExcelFile/ExcelFile/Excel/engine/point-graph.ts +154 -0
- package/src/components/ExcelFile/ExcelFile/Excel/engine/point-hash.ts +10 -0
- package/src/components/ExcelFile/ExcelFile/Excel/engine/point-set.ts +69 -0
- package/src/components/ExcelFile/ExcelFile/Excel/index.ts +48 -0
- package/src/components/ExcelFile/ExcelFile/Excel/matrix.ts +388 -0
- package/src/components/ExcelFile/ExcelFile/Excel/point-range.ts +82 -0
- package/src/components/ExcelFile/ExcelFile/Excel/point.ts +15 -0
- package/src/components/ExcelFile/ExcelFile/Excel/reducer.ts +682 -0
- package/src/components/ExcelFile/ExcelFile/Excel/selection.ts +257 -0
- package/src/components/ExcelFile/ExcelFile/Excel/types.ts +269 -0
- package/src/components/ExcelFile/ExcelFile/Excel/typings/fast-formula-parser.d.ts +58 -0
- package/src/components/ExcelFile/ExcelFile/Excel/use-dispatch.ts +8 -0
- package/src/components/ExcelFile/ExcelFile/Excel/use-selector.ts +9 -0
- package/src/components/ExcelFile/ExcelFile/Excel/util.ts +173 -0
- package/src/components/ExcelFile/ExcelFile/ExcelFile.scss +27 -0
- package/src/components/ExcelFile/ExcelFile/ExcelFile.tsx +520 -0
- package/src/components/ExcelFile/ExcelFile.stories.tsx +132 -0
- package/src/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.scss +16 -0
- package/src/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.tsx +79 -0
- package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.scss +22 -0
- package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.tsx +271 -0
- package/src/components/ExcelFile/ImportExcelStyles.tsx +86 -0
- package/src/components/ExcelFile/Types.ts +241 -0
- package/src/components/ExcelFile/index.ts +1 -0
- package/src/components/Icon/Icons.scss +2 -3
- package/src/components/Icon/iconList.ts +50 -1
- package/src/components/IconRadioGroup/IconRadioGroup.scss +60 -0
- package/src/components/IconRadioGroup/IconRadioGroup.stories.tsx +108 -0
- package/src/components/IconRadioGroup/IconRadioGroup.tsx +72 -0
- package/src/components/IconRadioGroup/index.ts +1 -0
- package/src/components/IconRadioGroup/type.ts +50 -0
- package/src/index.ts +2 -0
@@ -0,0 +1,78 @@
|
|
1
|
+
import { CellBase } from "./ExcelFile/Excel";
|
2
|
+
|
3
|
+
interface ChangeExcelStylesOptions {
|
4
|
+
sheetName: string;
|
5
|
+
styleType: string;
|
6
|
+
value: string;
|
7
|
+
selectedCell: { row: number; column: number }[];
|
8
|
+
}
|
9
|
+
|
10
|
+
export default function ChangeExcelStyles(
|
11
|
+
setWorksheetsData: React.Dispatch<React.SetStateAction<{ [key: string]: Matrix<CellBase>; }>>,
|
12
|
+
options: ChangeExcelStylesOptions
|
13
|
+
) {
|
14
|
+
const { sheetName, styleType, value, selectedCell } = options;
|
15
|
+
|
16
|
+
setWorksheetsData((prev) => {
|
17
|
+
if (!prev[sheetName]) {
|
18
|
+
return prev;
|
19
|
+
}
|
20
|
+
|
21
|
+
const sheetData = prev[sheetName]!;
|
22
|
+
const selectedCells = new Set(
|
23
|
+
selectedCell.map(({ row, column }) => `${row}-${column}`)
|
24
|
+
);
|
25
|
+
|
26
|
+
const updatedSheetData: Matrix<CellBase> = sheetData.map((row, rowIndex) =>
|
27
|
+
row.map((cell, columnIndex) => {
|
28
|
+
const isSelected = selectedCells.has(`${rowIndex}-${columnIndex}`);
|
29
|
+
if (isSelected&&cell!==undefined) {
|
30
|
+
let newStyle = { ...cell.style };
|
31
|
+
|
32
|
+
switch (styleType) {
|
33
|
+
// case 'border':
|
34
|
+
// newStyle = handleBorderChange(newStyle, value);
|
35
|
+
// break;
|
36
|
+
// case 'alignment':
|
37
|
+
// newStyle = handleAlignmentChange(newStyle, value);
|
38
|
+
// break;
|
39
|
+
// case 'bold':
|
40
|
+
// newStyle = handleBoldChange(newStyle);
|
41
|
+
// break;
|
42
|
+
// case 'italic':
|
43
|
+
// newStyle = handleItalicChange(newStyle);
|
44
|
+
// break;
|
45
|
+
case 'color':
|
46
|
+
newStyle = handleColorChange(newStyle, value);
|
47
|
+
break;
|
48
|
+
case 'backgroundColor':
|
49
|
+
newStyle = handleBackgroundColorChange(newStyle, value);
|
50
|
+
break;
|
51
|
+
default:
|
52
|
+
break;
|
53
|
+
}
|
54
|
+
|
55
|
+
const newValue = cell.value ?? "";
|
56
|
+
|
57
|
+
return { ...cell, style: newStyle, value: newValue };
|
58
|
+
}
|
59
|
+
return cell;
|
60
|
+
})
|
61
|
+
);
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
return { ...prev, [sheetName]: updatedSheetData };
|
66
|
+
});
|
67
|
+
}
|
68
|
+
|
69
|
+
function handleColorChange(style: CellStyle, value: string): CellStyle {
|
70
|
+
return { ...style, color: `#${value}` };
|
71
|
+
}
|
72
|
+
|
73
|
+
function handleBackgroundColorChange(
|
74
|
+
style: CellStyle,
|
75
|
+
value: string
|
76
|
+
): CellStyle {
|
77
|
+
return { ...style, backgroundColor: `#${value}` };
|
78
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import React, { useRef, useState } from 'react';
|
2
|
+
import './ColorBarSelector.scss';
|
3
|
+
|
4
|
+
interface ColorBarSelectorProps {
|
5
|
+
getColorValue: (color: string) => void;
|
6
|
+
disabled: boolean;
|
7
|
+
}
|
8
|
+
const ColorBarSelector: React.FC<ColorBarSelectorProps> = ({
|
9
|
+
getColorValue,
|
10
|
+
disabled,
|
11
|
+
}) => {
|
12
|
+
const colorInputRef = useRef<HTMLInputElement | null>(null);
|
13
|
+
const [color, setColor] = useState<string>('var(--error-light)');
|
14
|
+
|
15
|
+
const handleColorClick = () => {
|
16
|
+
if (colorInputRef.current) {
|
17
|
+
colorInputRef.current.click();
|
18
|
+
}
|
19
|
+
};
|
20
|
+
|
21
|
+
return (
|
22
|
+
<div
|
23
|
+
className="color-bar"
|
24
|
+
style={{
|
25
|
+
backgroundColor: `${color}`,
|
26
|
+
}}
|
27
|
+
onClick={handleColorClick}
|
28
|
+
>
|
29
|
+
<input
|
30
|
+
type="color"
|
31
|
+
disabled={disabled}
|
32
|
+
className="colorPicker"
|
33
|
+
ref={colorInputRef}
|
34
|
+
onChange={(e) => {
|
35
|
+
setColor(e.target.value);
|
36
|
+
getColorValue(e.target.value.replace('#', ''));
|
37
|
+
}}
|
38
|
+
/>
|
39
|
+
</div>
|
40
|
+
);
|
41
|
+
};
|
42
|
+
|
43
|
+
export default ColorBarSelector;
|
@@ -0,0 +1,102 @@
|
|
1
|
+
@import '../../../assets/styles/colors';
|
2
|
+
@import '../../../assets/styles/fonts';
|
3
|
+
|
4
|
+
.context-menu {
|
5
|
+
position: absolute;
|
6
|
+
z-index: 1;
|
7
|
+
outline: none;
|
8
|
+
background-color: var(--brand-color);
|
9
|
+
// box-shadow: 0px 0px 6px $shadow;
|
10
|
+
border-radius: 5px;
|
11
|
+
opacity: 1;
|
12
|
+
padding: 16px 0;
|
13
|
+
.menu-options {
|
14
|
+
overflow: auto;
|
15
|
+
min-height: 20px;
|
16
|
+
max-height: 175px;
|
17
|
+
min-width: 250px;
|
18
|
+
opacity: 1;
|
19
|
+
.options {
|
20
|
+
cursor: pointer;
|
21
|
+
display: flex;
|
22
|
+
align-items: center;
|
23
|
+
padding: 0 8px;
|
24
|
+
line-height: 35px;
|
25
|
+
gap: 16px;
|
26
|
+
.sheet-context-menu {
|
27
|
+
display: flex;
|
28
|
+
align-items: center;
|
29
|
+
justify-content: center;
|
30
|
+
}
|
31
|
+
&:hover {
|
32
|
+
// background-color: $primary;
|
33
|
+
.options-label {
|
34
|
+
background: var(--option-card-bg-color);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
.ff-icon-label {
|
42
|
+
display: flex;
|
43
|
+
align-items: center;
|
44
|
+
gap: 4px;
|
45
|
+
.ff-menuicon-container {
|
46
|
+
display: flex;
|
47
|
+
justify-content: center;
|
48
|
+
align-items: center;
|
49
|
+
cursor: pointer;
|
50
|
+
&:hover {
|
51
|
+
background-color: var(--brand-color);
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
.ff-menuicon-container-clicked {
|
56
|
+
display: flex;
|
57
|
+
justify-content: center;
|
58
|
+
align-items: center;
|
59
|
+
background-color: var(--brand-color);
|
60
|
+
cursor: pointer;
|
61
|
+
&:hover {
|
62
|
+
background-color: var(--brand-color);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
.ff-option-card {
|
68
|
+
position: absolute;
|
69
|
+
border: 1px solid var(--option-card-border-color);
|
70
|
+
background: var(--option-card-bg-color);
|
71
|
+
border-radius: 4px;
|
72
|
+
margin: 2px;
|
73
|
+
min-height: 32px;
|
74
|
+
min-width: 111px;
|
75
|
+
z-index: 100000;
|
76
|
+
white-space: nowrap;
|
77
|
+
|
78
|
+
.ff-options {
|
79
|
+
@extend .fontSm;
|
80
|
+
cursor: pointer;
|
81
|
+
border-radius: 4px;
|
82
|
+
display: flex;
|
83
|
+
align-items: center;
|
84
|
+
padding: 8px;
|
85
|
+
line-height: 16px;
|
86
|
+
gap: 8px;
|
87
|
+
&:hover {
|
88
|
+
background-color: var(--hover-color);
|
89
|
+
}
|
90
|
+
label {
|
91
|
+
cursor: pointer;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
.ff-disable-option {
|
96
|
+
opacity: 0.5;
|
97
|
+
cursor: no-drop;
|
98
|
+
label {
|
99
|
+
cursor: no-drop;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
@@ -0,0 +1,104 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import './ContextMenu.scss';
|
3
|
+
import Icon from '../../Icon';
|
4
|
+
// import { colors } from '../../../colors/colorConstants';
|
5
|
+
|
6
|
+
const ContextMenu: React.FC<ContextMenuProps> = ({
|
7
|
+
customContext,
|
8
|
+
contextAction,
|
9
|
+
contextData,
|
10
|
+
setContextData,
|
11
|
+
}) => {
|
12
|
+
const contextOptions: ContextOption[] = [
|
13
|
+
{
|
14
|
+
name: 'cell',
|
15
|
+
value: customContext || [],
|
16
|
+
},
|
17
|
+
{
|
18
|
+
name: 'row',
|
19
|
+
value: [
|
20
|
+
{ name: 'Add Row', title: 'Add Row', action: contextAction.addRow },
|
21
|
+
{
|
22
|
+
name: 'Delete Row',
|
23
|
+
title: 'Delete Row',
|
24
|
+
action: contextAction.deleteRow,
|
25
|
+
},
|
26
|
+
],
|
27
|
+
},
|
28
|
+
{
|
29
|
+
name: 'column',
|
30
|
+
value: [
|
31
|
+
{
|
32
|
+
name: 'Add Column',
|
33
|
+
title: 'Add Column',
|
34
|
+
action: contextAction.addColumn,
|
35
|
+
},
|
36
|
+
{
|
37
|
+
name: 'Delete Column',
|
38
|
+
title: 'Delete Column',
|
39
|
+
action: contextAction.deleteColumn,
|
40
|
+
},
|
41
|
+
],
|
42
|
+
},
|
43
|
+
{
|
44
|
+
name: 'sheet_options',
|
45
|
+
value: [
|
46
|
+
{
|
47
|
+
name: 'Add Sheet',
|
48
|
+
title: (
|
49
|
+
<span className="sheet-context-menu">
|
50
|
+
<Icon name="plus_icon" /> Add
|
51
|
+
Sheet
|
52
|
+
</span>
|
53
|
+
),
|
54
|
+
action: contextAction.addSheet,
|
55
|
+
},
|
56
|
+
{
|
57
|
+
name: 'Delete Sheet',
|
58
|
+
title: (
|
59
|
+
<span className="sheet-context-menu">
|
60
|
+
<Icon name="delete" /> Delete Sheet
|
61
|
+
</span>
|
62
|
+
),
|
63
|
+
action: contextAction.deleteSheet,
|
64
|
+
},
|
65
|
+
],
|
66
|
+
},
|
67
|
+
];
|
68
|
+
|
69
|
+
return (
|
70
|
+
contextData.visible &&
|
71
|
+
contextOptions.some(
|
72
|
+
(contextType) =>
|
73
|
+
contextType.name === contextData.type && contextType.value.length > 0
|
74
|
+
) && (
|
75
|
+
<div
|
76
|
+
className="context-menu"
|
77
|
+
style={{ top: contextData.y, left: contextData.x }}
|
78
|
+
>
|
79
|
+
<div className="menu-options">
|
80
|
+
{contextOptions
|
81
|
+
.filter((contextType) => contextType.name === contextData.type)
|
82
|
+
.map((contextType) =>
|
83
|
+
contextType.value.length > 0
|
84
|
+
? contextType.value.map((item) => (
|
85
|
+
<div
|
86
|
+
className="options"
|
87
|
+
key={item.name}
|
88
|
+
onClick={() => {
|
89
|
+
item.action();
|
90
|
+
setContextData((prev) => ({ ...prev, visible: false }));
|
91
|
+
}}
|
92
|
+
>
|
93
|
+
<label className="options-label">{item.title}</label>
|
94
|
+
</div>
|
95
|
+
))
|
96
|
+
: null
|
97
|
+
)}
|
98
|
+
</div>
|
99
|
+
</div>
|
100
|
+
)
|
101
|
+
);
|
102
|
+
};
|
103
|
+
|
104
|
+
export default ContextMenu;
|
@@ -0,0 +1,131 @@
|
|
1
|
+
import * as React from "react";
|
2
|
+
import classnames from "classnames";
|
3
|
+
import * as Actions from "./actions";
|
4
|
+
import * as Types from "./types";
|
5
|
+
import * as Point from "./point";
|
6
|
+
import useSelector from "./use-selector";
|
7
|
+
import useDispatch from "./use-dispatch";
|
8
|
+
import { getCellDimensions } from "./util";
|
9
|
+
import * as Matrix from "./matrix";
|
10
|
+
|
11
|
+
type Props = {
|
12
|
+
DataEditor: Types.DataEditorComponent;
|
13
|
+
};
|
14
|
+
|
15
|
+
const ActiveCell: React.FC<Props> = (props) => {
|
16
|
+
const rootRef = React.useRef<HTMLDivElement>(null);
|
17
|
+
const dispatch = useDispatch();
|
18
|
+
const setCellData = React.useCallback(
|
19
|
+
(active: Point.Point, data: Types.CellBase) =>
|
20
|
+
dispatch(Actions.setCellData(active, data)),
|
21
|
+
[dispatch]
|
22
|
+
);
|
23
|
+
const edit = React.useCallback(() => dispatch(Actions.edit()), [dispatch]);
|
24
|
+
const commit = React.useCallback(
|
25
|
+
(changes: Types.CommitChanges<Types.CellBase>) =>
|
26
|
+
dispatch(Actions.commit(changes)),
|
27
|
+
[dispatch]
|
28
|
+
);
|
29
|
+
const view = React.useCallback(() => {
|
30
|
+
dispatch(Actions.view());
|
31
|
+
}, [dispatch]);
|
32
|
+
const active = useSelector((state) => state.active);
|
33
|
+
const mode = useSelector((state) => state.mode);
|
34
|
+
const cell = useSelector((state) =>
|
35
|
+
state.active ? Matrix.get(state.active, state.model.data) : undefined
|
36
|
+
);
|
37
|
+
const dimensions = useSelector((state) =>
|
38
|
+
active
|
39
|
+
? getCellDimensions(active, state.rowDimensions, state.columnDimensions)
|
40
|
+
: undefined
|
41
|
+
);
|
42
|
+
const hidden = React.useMemo(
|
43
|
+
() => !active || !dimensions,
|
44
|
+
[active, dimensions]
|
45
|
+
);
|
46
|
+
|
47
|
+
const initialCellRef = React.useRef<Types.CellBase | undefined>(undefined);
|
48
|
+
const prevActiveRef = React.useRef<Point.Point | null>(null);
|
49
|
+
const prevCellRef = React.useRef<Types.CellBase | undefined>(undefined);
|
50
|
+
|
51
|
+
const handleChange = React.useCallback(
|
52
|
+
(cell: Types.CellBase) => {
|
53
|
+
if (!active) {
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
setCellData(active, cell);
|
57
|
+
},
|
58
|
+
[setCellData, active]
|
59
|
+
);
|
60
|
+
|
61
|
+
React.useEffect(() => {
|
62
|
+
const root = rootRef.current;
|
63
|
+
if (!hidden && root) {
|
64
|
+
root.focus();
|
65
|
+
}
|
66
|
+
}, [rootRef, hidden]);
|
67
|
+
|
68
|
+
React.useEffect(() => {
|
69
|
+
const prevActive = prevActiveRef.current;
|
70
|
+
const prevCell = prevCellRef.current;
|
71
|
+
prevActiveRef.current = active;
|
72
|
+
prevCellRef.current = cell;
|
73
|
+
|
74
|
+
if (!prevActive || !prevCell) {
|
75
|
+
return;
|
76
|
+
}
|
77
|
+
|
78
|
+
const coordsChanged =
|
79
|
+
active?.row !== prevActive.row || active?.column !== prevActive.column;
|
80
|
+
const exitedEditMode = mode !== "edit";
|
81
|
+
|
82
|
+
if (coordsChanged || exitedEditMode) {
|
83
|
+
const initialCell = initialCellRef.current;
|
84
|
+
if (prevCell !== initialCell) {
|
85
|
+
commit([
|
86
|
+
{
|
87
|
+
prevCell: initialCell || null,
|
88
|
+
nextCell: prevCell,
|
89
|
+
},
|
90
|
+
]);
|
91
|
+
} else if (!coordsChanged && cell !== prevCell) {
|
92
|
+
commit([
|
93
|
+
{
|
94
|
+
prevCell,
|
95
|
+
nextCell: cell || null,
|
96
|
+
},
|
97
|
+
]);
|
98
|
+
}
|
99
|
+
initialCellRef.current = cell;
|
100
|
+
}
|
101
|
+
});
|
102
|
+
|
103
|
+
const DataEditor = (cell && cell.DataEditor) || props.DataEditor;
|
104
|
+
const readOnly = cell && cell.readOnly;
|
105
|
+
|
106
|
+
return hidden ? null : (
|
107
|
+
<div
|
108
|
+
ref={rootRef}
|
109
|
+
className={classnames(
|
110
|
+
"Spreadsheet__active-cell",
|
111
|
+
`Spreadsheet__active-cell--${mode}`
|
112
|
+
)}
|
113
|
+
style={dimensions}
|
114
|
+
onClick={mode === "view" && !readOnly ? edit : undefined}
|
115
|
+
tabIndex={0}
|
116
|
+
>
|
117
|
+
{mode === "edit" && active && (
|
118
|
+
<DataEditor
|
119
|
+
row={active.row}
|
120
|
+
column={active.column}
|
121
|
+
cell={cell}
|
122
|
+
// @ts-ignore
|
123
|
+
onChange={handleChange}
|
124
|
+
exitEditMode={view}
|
125
|
+
/>
|
126
|
+
)}
|
127
|
+
</div>
|
128
|
+
);
|
129
|
+
};
|
130
|
+
|
131
|
+
export default ActiveCell;
|
@@ -0,0 +1,201 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import classnames from 'classnames';
|
3
|
+
import * as Matrix from './matrix';
|
4
|
+
import * as Types from './types';
|
5
|
+
import * as Point from './point';
|
6
|
+
import * as Actions from './actions';
|
7
|
+
import { isActive, getOffsetRect } from './util';
|
8
|
+
import useDispatch from './use-dispatch';
|
9
|
+
import useSelector from './use-selector';
|
10
|
+
|
11
|
+
export const Cell: React.FC<Types.CellComponentProps> = ({
|
12
|
+
row,
|
13
|
+
column,
|
14
|
+
DataViewer,
|
15
|
+
selected,
|
16
|
+
active,
|
17
|
+
dragging,
|
18
|
+
mode,
|
19
|
+
data,
|
20
|
+
evaluatedData,
|
21
|
+
select,
|
22
|
+
activate,
|
23
|
+
setCellDimensions,
|
24
|
+
setCellData,
|
25
|
+
}): React.ReactElement => {
|
26
|
+
const [isDotDragging, setIsDotDragging] = React.useState(false);
|
27
|
+
const [first, setFirst] = React.useState(true);
|
28
|
+
const rootRef = React.useRef<HTMLTableCellElement | null>(null);
|
29
|
+
const point = React.useMemo(
|
30
|
+
(): Point.Point => ({
|
31
|
+
row,
|
32
|
+
column,
|
33
|
+
}),
|
34
|
+
[row, column]
|
35
|
+
);
|
36
|
+
|
37
|
+
const handleMouseDown = React.useCallback(
|
38
|
+
(event: React.MouseEvent<HTMLTableCellElement>) => {
|
39
|
+
if (mode === 'view') {
|
40
|
+
setCellDimensions(point, getOffsetRect(event.currentTarget));
|
41
|
+
|
42
|
+
if (event.shiftKey) {
|
43
|
+
select(point);
|
44
|
+
} else {
|
45
|
+
activate(point);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
},
|
49
|
+
[mode, setCellDimensions, point, select, activate]
|
50
|
+
);
|
51
|
+
|
52
|
+
const handleMouseOver = React.useCallback(
|
53
|
+
(event: React.MouseEvent<HTMLTableCellElement>) => {
|
54
|
+
if (dragging && first && !isDotDragging) {
|
55
|
+
setCellDimensions(point, getOffsetRect(event.currentTarget));
|
56
|
+
select(point);
|
57
|
+
}
|
58
|
+
},
|
59
|
+
[setCellDimensions, select, dragging, point, first, isDotDragging]
|
60
|
+
);
|
61
|
+
|
62
|
+
const handleDotDown = React.useCallback(
|
63
|
+
(event: React.MouseEvent<HTMLTableCellElement>) => {
|
64
|
+
setIsDotDragging(true);
|
65
|
+
setCellDimensions(point, getOffsetRect(event.currentTarget));
|
66
|
+
|
67
|
+
if (event.shiftKey) {
|
68
|
+
select(point);
|
69
|
+
} else {
|
70
|
+
activate(point);
|
71
|
+
}
|
72
|
+
},
|
73
|
+
[setCellDimensions, point, select, activate]
|
74
|
+
);
|
75
|
+
|
76
|
+
const handleDotOver = React.useCallback(
|
77
|
+
(event: React.MouseEvent<HTMLTableCellElement>) => {
|
78
|
+
setFirst(false);
|
79
|
+
if (dragging && isDotDragging) {
|
80
|
+
setCellDimensions(point, getOffsetRect(event.currentTarget));
|
81
|
+
select(point);
|
82
|
+
}
|
83
|
+
},
|
84
|
+
[setCellDimensions, select, dragging, point, isDotDragging]
|
85
|
+
);
|
86
|
+
|
87
|
+
React.useEffect(() => {
|
88
|
+
const root = rootRef.current;
|
89
|
+
if (selected && root) {
|
90
|
+
setCellDimensions(point, getOffsetRect(root));
|
91
|
+
}
|
92
|
+
if (root && active && mode === 'view') {
|
93
|
+
root.focus();
|
94
|
+
}
|
95
|
+
}, [setCellDimensions, selected, active, mode, point, data]);
|
96
|
+
|
97
|
+
if (data && data.DataViewer) {
|
98
|
+
// @ts-ignore
|
99
|
+
DataViewer = data.DataViewer;
|
100
|
+
}
|
101
|
+
|
102
|
+
return (
|
103
|
+
<td
|
104
|
+
ref={rootRef}
|
105
|
+
className={classnames('Spreadsheet__cell', data?.className, {
|
106
|
+
'Spreadsheet__active-cell': active || dragging,
|
107
|
+
})}
|
108
|
+
onMouseEnter={handleMouseOver} // Handle drag when mouse enters
|
109
|
+
onMouseDown={handleMouseDown}
|
110
|
+
tabIndex={0}
|
111
|
+
>
|
112
|
+
<DataViewer
|
113
|
+
row={row}
|
114
|
+
column={column}
|
115
|
+
cell={data}
|
116
|
+
evaluatedCell={evaluatedData}
|
117
|
+
setCellData={setCellData}
|
118
|
+
/>
|
119
|
+
<div
|
120
|
+
className="Selection_dot"
|
121
|
+
onMouseOver={handleDotOver}
|
122
|
+
onMouseDown={handleDotDown}
|
123
|
+
></div>
|
124
|
+
</td>
|
125
|
+
);
|
126
|
+
};
|
127
|
+
|
128
|
+
export const enhance = (
|
129
|
+
CellComponent: React.ComponentType<Types.CellComponentProps>
|
130
|
+
): React.FC<
|
131
|
+
Omit<
|
132
|
+
Types.CellComponentProps,
|
133
|
+
| "selected"
|
134
|
+
| "active"
|
135
|
+
| "copied"
|
136
|
+
| "dragging"
|
137
|
+
| "mode"
|
138
|
+
| "data"
|
139
|
+
| "select"
|
140
|
+
| "activate"
|
141
|
+
| "setCellDimensions"
|
142
|
+
>
|
143
|
+
> => {
|
144
|
+
return function CellWrapper(props) {
|
145
|
+
const { row, column } = props;
|
146
|
+
const dispatch = useDispatch();
|
147
|
+
const point = React.useMemo(
|
148
|
+
(): Point.Point => ({
|
149
|
+
row,
|
150
|
+
column,
|
151
|
+
}),
|
152
|
+
[row, column]
|
153
|
+
);
|
154
|
+
const setCellData = React.useCallback(
|
155
|
+
(data: Types.CellBase) => dispatch(Actions.setCellData(point, data)),
|
156
|
+
[dispatch, point]
|
157
|
+
);
|
158
|
+
const select = React.useCallback(
|
159
|
+
(point: Point.Point) => dispatch(Actions.select(point)),
|
160
|
+
[dispatch]
|
161
|
+
);
|
162
|
+
const activate = React.useCallback(
|
163
|
+
(point: Point.Point) => dispatch(Actions.activate(point)),
|
164
|
+
[dispatch]
|
165
|
+
);
|
166
|
+
const setCellDimensions = React.useCallback(
|
167
|
+
(point: Point.Point, dimensions: Types.Dimensions) =>
|
168
|
+
dispatch(Actions.setCellDimensions(point, dimensions)),
|
169
|
+
[dispatch]
|
170
|
+
);
|
171
|
+
const active = useSelector((state) => isActive(state.active, point));
|
172
|
+
const mode = useSelector((state) => (active ? state.mode : "view"));
|
173
|
+
const data = useSelector((state) => Matrix.get(point, state.model.data));
|
174
|
+
const evaluatedData = useSelector((state) =>
|
175
|
+
Matrix.get(point, state.model.evaluatedData)
|
176
|
+
);
|
177
|
+
|
178
|
+
const selected = useSelector((state) =>
|
179
|
+
state.selected.has(state.model.data, point)
|
180
|
+
);
|
181
|
+
const dragging = useSelector((state) => state.dragging);
|
182
|
+
const copied = useSelector((state) => state.copied?.has(point) || false);
|
183
|
+
|
184
|
+
return (
|
185
|
+
<CellComponent
|
186
|
+
{...props}
|
187
|
+
selected={selected}
|
188
|
+
active={active}
|
189
|
+
copied={copied}
|
190
|
+
dragging={dragging}
|
191
|
+
mode={mode}
|
192
|
+
evaluatedData={evaluatedData}
|
193
|
+
data={data}
|
194
|
+
select={select}
|
195
|
+
activate={activate}
|
196
|
+
setCellDimensions={setCellDimensions}
|
197
|
+
setCellData={setCellData}
|
198
|
+
/>
|
199
|
+
);
|
200
|
+
};
|
201
|
+
};
|