pixel-react-excel-sheet 1.0.1 → 1.1.9
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/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 -6
- 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/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/ExcelSheetBar/ExcelSheetBar.d.ts +0 -3
- package/lib/components/ExcelFile/ExcelToolBar/ExcelToolBar.d.ts +12 -0
- package/lib/components/ExcelFile/Types.d.ts +0 -8
- package/lib/components/Icon/Icon.stories.d.ts +1 -0
- package/lib/components/Icon/types.d.ts +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.esm.js +888 -995
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +888 -995
- package/lib/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/assets/Themes/BaseTheme.scss +1 -0
- package/src/assets/Themes/DarkTheme.scss +1 -0
- package/src/components/ExcelFile/ExcelFile/Excel/ActiveCell.tsx +13 -13
- package/src/components/ExcelFile/ExcelFile/Excel/Cell.tsx +12 -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.scss +127 -135
- package/src/components/ExcelFile/ExcelFile/Excel/Spreadsheet.tsx +87 -73
- 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 +292 -41
- package/src/components/ExcelFile/ExcelFile/Excel/selection.ts +5 -5
- 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.tsx +27 -335
- package/src/components/ExcelFile/ExcelFile.stories.tsx +10 -9
- package/src/components/ExcelFile/ExcelSheetBar/ExcelSheetBar.tsx +0 -11
- package/src/components/ExcelFile/ExcelToolBar/ExcelToolBar.tsx +145 -125
- package/src/components/ExcelFile/Types.ts +0 -11
- package/src/components/ExcelFile/index.ts +1 -1
- package/src/components/Icon/Icon.stories.tsx +27 -0
- package/src/components/Icon/Icon.tsx +5 -1
- package/src/components/Icon/Icons.scss +13 -2
- package/src/components/Icon/types.ts +1 -0
- package/src/components/ExcelFile/ChangeExcelStyles.tsx +0 -66
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import classNames from
|
|
3
|
-
import * as Actions from
|
|
4
|
-
import * as Types from
|
|
5
|
-
import useDispatch from
|
|
6
|
-
import useSelector from
|
|
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 useDispatch from './use-dispatch';
|
|
6
|
+
import useSelector from './use-selector';
|
|
7
7
|
|
|
8
8
|
const RowIndicator: Types.RowIndicatorComponent = ({
|
|
9
9
|
row,
|
|
@@ -12,7 +12,7 @@ const RowIndicator: Types.RowIndicatorComponent = ({
|
|
|
12
12
|
onSelect,
|
|
13
13
|
}) => {
|
|
14
14
|
const [height, setHeight] = React.useState(0);
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
// Function to handle the start of the resize (mouse down)
|
|
17
17
|
const onMouseDown = (e: React.MouseEvent) => {
|
|
18
18
|
const startY = e.clientY;
|
|
@@ -22,25 +22,32 @@ const RowIndicator: Types.RowIndicatorComponent = ({
|
|
|
22
22
|
const newHeight = height + (moveEvent.clientY - startY);
|
|
23
23
|
setHeight(newHeight);
|
|
24
24
|
// Fetch the floating rectangle element from the DOM
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const selectedAllRow = document.querySelector(
|
|
26
|
+
'.Spreadsheet__floating-rect--selected'
|
|
27
|
+
);
|
|
28
|
+
const selectedSingleRow = document.querySelector(
|
|
29
|
+
'.Spreadsheet__active-cell'
|
|
30
|
+
);
|
|
27
31
|
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
// If the element exists, update its height
|
|
33
|
+
if (
|
|
34
|
+
selectedAllRow instanceof HTMLElement &&
|
|
35
|
+
selectedSingleRow instanceof HTMLElement
|
|
36
|
+
) {
|
|
37
|
+
selectedAllRow.style.height = `${newHeight}px`;
|
|
38
|
+
selectedSingleRow.style.height = `${newHeight}px`;
|
|
39
|
+
}
|
|
33
40
|
};
|
|
34
41
|
|
|
35
42
|
// Function to stop the resizing (mouse up)
|
|
36
43
|
const onMouseUp = () => {
|
|
37
|
-
document.removeEventListener(
|
|
38
|
-
document.removeEventListener(
|
|
44
|
+
document.removeEventListener('mousemove', onMouseMove);
|
|
45
|
+
document.removeEventListener('mouseup', onMouseUp);
|
|
39
46
|
};
|
|
40
47
|
|
|
41
48
|
// Add event listeners for mouse move and mouse up
|
|
42
|
-
document.addEventListener(
|
|
43
|
-
document.addEventListener(
|
|
49
|
+
document.addEventListener('mousemove', onMouseMove);
|
|
50
|
+
document.addEventListener('mouseup', onMouseUp);
|
|
44
51
|
};
|
|
45
52
|
|
|
46
53
|
const handleClick = React.useCallback(
|
|
@@ -52,9 +59,9 @@ const RowIndicator: Types.RowIndicatorComponent = ({
|
|
|
52
59
|
|
|
53
60
|
return (
|
|
54
61
|
<th
|
|
55
|
-
|
|
56
|
-
className={classNames(
|
|
57
|
-
|
|
62
|
+
style={{ height: `${height}px`, minWidth: '60px', position: 'relative' }}
|
|
63
|
+
className={classNames('Spreadsheet__header', {
|
|
64
|
+
'Spreadsheet__header--selected': selected,
|
|
58
65
|
})}
|
|
59
66
|
onClick={handleClick}
|
|
60
67
|
tabIndex={0}
|
|
@@ -63,13 +70,13 @@ const RowIndicator: Types.RowIndicatorComponent = ({
|
|
|
63
70
|
<div
|
|
64
71
|
onMouseDown={onMouseDown}
|
|
65
72
|
style={{
|
|
66
|
-
zIndex:
|
|
67
|
-
height:
|
|
68
|
-
position:
|
|
73
|
+
zIndex: 'inherit',
|
|
74
|
+
height: '2px',
|
|
75
|
+
position: 'absolute',
|
|
69
76
|
right: 0,
|
|
70
77
|
bottom: 0,
|
|
71
|
-
width:
|
|
72
|
-
cursor:
|
|
78
|
+
width: '100%',
|
|
79
|
+
cursor: 'ns-resize',
|
|
73
80
|
}}
|
|
74
81
|
/>
|
|
75
82
|
</th>
|
|
@@ -80,7 +87,7 @@ export default RowIndicator;
|
|
|
80
87
|
|
|
81
88
|
export const enhance = (
|
|
82
89
|
RowIndicatorComponent: Types.RowIndicatorComponent
|
|
83
|
-
): React.FC<Omit<Types.RowIndicatorProps,
|
|
90
|
+
): React.FC<Omit<Types.RowIndicatorProps, 'selected' | 'onSelect'>> => {
|
|
84
91
|
return function RowIndicatorWrapper(props) {
|
|
85
92
|
const dispatch = useDispatch();
|
|
86
93
|
const selected = useSelector((state) =>
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { getSelectedDimensions } from
|
|
3
|
-
import FloatingRect from
|
|
4
|
-
import useSelector from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { getSelectedDimensions } from './util';
|
|
3
|
+
import FloatingRect from './FloatingRect';
|
|
4
|
+
import useSelector from './use-selector';
|
|
5
5
|
|
|
6
6
|
const Selected: React.FC = () => {
|
|
7
|
-
const selected = useSelector((state) => state.selected);
|
|
7
|
+
const selected = useSelector((state) => state.selected);
|
|
8
8
|
const dimensions = useSelector(
|
|
9
9
|
(state) =>
|
|
10
10
|
selected &&
|
|
@@ -1,138 +1,130 @@
|
|
|
1
1
|
@use '../../../../assets/Themes/BaseTheme.scss';
|
|
2
2
|
|
|
3
3
|
.Spreadsheet {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
.Spreadsheet__floating-rect--dragging {
|
|
132
|
-
border: none;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
.Spreadsheet__floating-rect--copied {
|
|
136
|
-
border: 2px var(--outline-color) dashed;
|
|
137
|
-
}
|
|
138
|
-
|
|
4
|
+
--background-color: var(--drawer-footer-bg);
|
|
5
|
+
--text-color: var(--text-color);
|
|
6
|
+
--readonly-text-color: var(--toggle-strip-active);
|
|
7
|
+
--outline-color: var(--toggle-strip-active);
|
|
8
|
+
--outline-background-color: var(--overlay-bg);
|
|
9
|
+
--border-color: var(--toggle-strip-color);
|
|
10
|
+
--header-background-color: var(--pop-up-background-blur);
|
|
11
|
+
--elevation: var(--brand-color);
|
|
12
|
+
|
|
13
|
+
position: relative;
|
|
14
|
+
overflow: visible;
|
|
15
|
+
background: var(--background-color);
|
|
16
|
+
color: var(--text-color);
|
|
17
|
+
display: inline-block;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.Spreadsheet__active-cell {
|
|
21
|
+
position: absolute;
|
|
22
|
+
border: 2px solid var(--outline-color);
|
|
23
|
+
box-sizing: border-box;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.Spreadsheet__active-cell--edit {
|
|
27
|
+
background: var(--background-color);
|
|
28
|
+
box-shadow: var(--elevation);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.Spreadsheet__table {
|
|
32
|
+
border-collapse: collapse;
|
|
33
|
+
table-layout: fixed;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.Spreadsheet__cell {
|
|
37
|
+
outline: none;
|
|
38
|
+
position: relative;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.Spreadsheet__active-cell .Selection_dot {
|
|
42
|
+
background-color: var(--elevation);
|
|
43
|
+
height: 7px;
|
|
44
|
+
width: 7px;
|
|
45
|
+
border-radius: 50%;
|
|
46
|
+
position: absolute;
|
|
47
|
+
right: -3px;
|
|
48
|
+
z-index: 10;
|
|
49
|
+
bottom: -3px;
|
|
50
|
+
cursor: crosshair;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.Spreadsheet__cell--readonly {
|
|
54
|
+
color: var(--readonly-text-color);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.Spreadsheet__cell,
|
|
58
|
+
.Spreadsheet__header {
|
|
59
|
+
border: 0.1px solid var(--border-color);
|
|
60
|
+
overflow: hidden;
|
|
61
|
+
word-break: keep-all;
|
|
62
|
+
white-space: nowrap;
|
|
63
|
+
text-align: left;
|
|
64
|
+
box-sizing: border-box;
|
|
65
|
+
user-select: none;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.Spreadsheet__header {
|
|
69
|
+
background: var(--header-background-color);
|
|
70
|
+
color: var(--readonly-text-color);
|
|
71
|
+
text-align: center;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.Spreadsheet__header--selected {
|
|
75
|
+
background: var(--brand-color);
|
|
76
|
+
color: var(--tooltip-text-color);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.Spreadsheet__header,
|
|
80
|
+
.Spreadsheet__data-viewer,
|
|
81
|
+
.Spreadsheet__data-editor input {
|
|
82
|
+
padding: 4px;
|
|
83
|
+
box-sizing: border-box;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.Spreadsheet__data-viewer--preserve-breaks {
|
|
87
|
+
white-space: pre-wrap;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.Spreadsheet__data-editor,
|
|
91
|
+
.Spreadsheet__data-editor input {
|
|
92
|
+
width: 100%;
|
|
93
|
+
height: 100%;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.Spreadsheet__data-editor input {
|
|
97
|
+
font: inherit;
|
|
98
|
+
color: inherit;
|
|
99
|
+
background: none;
|
|
100
|
+
border: none;
|
|
101
|
+
outline: none;
|
|
102
|
+
margin: 0;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.Spreadsheet__data-viewer--boolean {
|
|
106
|
+
text-align: center;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.Spreadsheet__floating-rect {
|
|
110
|
+
position: absolute;
|
|
111
|
+
pointer-events: none;
|
|
112
|
+
box-sizing: border-box;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.Spreadsheet__floating-rect--hidden {
|
|
116
|
+
display: none;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.Spreadsheet__floating-rect--selected {
|
|
120
|
+
background: var(--outline-background-color);
|
|
121
|
+
border: 2px var(--outline-color) solid;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.Spreadsheet__floating-rect--dragging {
|
|
125
|
+
border: none;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.Spreadsheet__floating-rect--copied {
|
|
129
|
+
border: 2px var(--outline-color) dashed;
|
|
130
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import classNames from
|
|
3
|
-
import * as Types from
|
|
4
|
-
import * as Actions from
|
|
5
|
-
import * as Matrix from
|
|
6
|
-
import * as Point from
|
|
7
|
-
import { Selection } from
|
|
8
|
-
import reducer, { INITIAL_STATE, hasKeyDownHandler } from
|
|
9
|
-
import context from
|
|
10
|
-
import { Model, createFormulaParser } from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import * as Types from './types';
|
|
4
|
+
import * as Actions from './actions';
|
|
5
|
+
import * as Matrix from './matrix';
|
|
6
|
+
import * as Point from './point';
|
|
7
|
+
import { Selection } from './selection';
|
|
8
|
+
import reducer, { INITIAL_STATE, hasKeyDownHandler } from './reducer';
|
|
9
|
+
import context from './context';
|
|
10
|
+
import { Model, createFormulaParser } from './engine';
|
|
11
11
|
import {
|
|
12
12
|
range,
|
|
13
13
|
readTextFromClipboard,
|
|
@@ -16,27 +16,28 @@ import {
|
|
|
16
16
|
getCSV,
|
|
17
17
|
shouldHandleClipboardEvent,
|
|
18
18
|
isFocusedWithin,
|
|
19
|
-
} from
|
|
19
|
+
} from './util';
|
|
20
20
|
|
|
21
|
-
import DefaultTable from
|
|
22
|
-
import DefaultRow from
|
|
23
|
-
import DefaultHeaderRow from
|
|
21
|
+
import DefaultTable from './Table';
|
|
22
|
+
import DefaultRow from './Row';
|
|
23
|
+
import DefaultHeaderRow from './HeaderRow';
|
|
24
24
|
import DefaultCornerIndicator, {
|
|
25
25
|
enhance as enhanceCornerIndicator,
|
|
26
|
-
} from
|
|
26
|
+
} from './CornerIndicator';
|
|
27
27
|
import DefaultColumnIndicator, {
|
|
28
28
|
enhance as enhanceColumnIndicator,
|
|
29
|
-
} from
|
|
29
|
+
} from './ColumnIndicator';
|
|
30
30
|
import DefaultRowIndicator, {
|
|
31
31
|
enhance as enhanceRowIndicator,
|
|
32
|
-
} from
|
|
33
|
-
import { Cell as DefaultCell, enhance as enhanceCell } from
|
|
34
|
-
import DefaultDataViewer from
|
|
35
|
-
import DefaultDataEditor from
|
|
36
|
-
import ActiveCell from
|
|
37
|
-
import Selected from
|
|
38
|
-
import Copied from
|
|
39
|
-
import
|
|
32
|
+
} from './RowIndicator';
|
|
33
|
+
import { Cell as DefaultCell, enhance as enhanceCell } from './Cell';
|
|
34
|
+
import DefaultDataViewer from './DataViewer';
|
|
35
|
+
import DefaultDataEditor from './DataEditor';
|
|
36
|
+
import ActiveCell from './ActiveCell';
|
|
37
|
+
import Selected from './Selected';
|
|
38
|
+
import Copied from './Copied';
|
|
39
|
+
import './Spreadsheet.scss';
|
|
40
|
+
import ExcelToolBar from '../../ExcelToolBar/ExcelToolBar';
|
|
40
41
|
|
|
41
42
|
/** The Spreadsheet component props */
|
|
42
43
|
export type Props<CellType extends Types.CellBase> = {
|
|
@@ -183,8 +184,13 @@ const Spreadsheet = <CellType extends Types.CellBase>(
|
|
|
183
184
|
const setData = useAction(Actions.setData);
|
|
184
185
|
const setCreateFormulaParser = useAction(Actions.setCreateFormulaParser);
|
|
185
186
|
const setSelection = useAction(Actions.setSelection);
|
|
187
|
+
const onBold = useAction(Actions.bold);
|
|
188
|
+
const onItalic = useAction(Actions.italic);
|
|
189
|
+
const onUnderline = useAction(Actions.underline);
|
|
190
|
+
const setColor = useAction(Actions.color);
|
|
191
|
+
const setBackgroundColor = useAction(Actions.backgroundStyle);
|
|
192
|
+
const setFormatePainter = useAction(Actions.formatePainter);
|
|
186
193
|
|
|
187
|
-
// Track active
|
|
188
194
|
const prevActiveRef = React.useRef<Point.Point | null>(state.active);
|
|
189
195
|
React.useEffect(() => {
|
|
190
196
|
if (state.active !== prevActiveRef.current) {
|
|
@@ -212,7 +218,6 @@ const Spreadsheet = <CellType extends Types.CellBase>(
|
|
|
212
218
|
prevEvaluatedDataRef.current = state.model.evaluatedData;
|
|
213
219
|
}, [state?.model?.evaluatedData, onEvaluatedDataChange]);
|
|
214
220
|
|
|
215
|
-
// Listen to selection changes
|
|
216
221
|
const prevSelectedRef = React.useRef<Selection>(state.selected);
|
|
217
222
|
React.useEffect(() => {
|
|
218
223
|
if (!state.selected.equals(prevSelectedRef.current)) {
|
|
@@ -241,7 +246,7 @@ const Spreadsheet = <CellType extends Types.CellBase>(
|
|
|
241
246
|
}, [props.selected, setSelection]);
|
|
242
247
|
|
|
243
248
|
// Update data when props.data changes
|
|
244
|
-
|
|
249
|
+
let prevDataPropRef = React.useRef<Matrix.Matrix<CellType> | undefined>(
|
|
245
250
|
props.data
|
|
246
251
|
);
|
|
247
252
|
React.useEffect(() => {
|
|
@@ -336,14 +341,14 @@ const Spreadsheet = <CellType extends Types.CellBase>(
|
|
|
336
341
|
|
|
337
342
|
const handleMouseUp = React.useCallback(() => {
|
|
338
343
|
onDragEnd();
|
|
339
|
-
document.removeEventListener(
|
|
344
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
340
345
|
}, [onDragEnd]);
|
|
341
346
|
|
|
342
347
|
const handleMouseMove = React.useCallback(
|
|
343
348
|
(event: React.MouseEvent) => {
|
|
344
349
|
if (!state.dragging && event.buttons === 1) {
|
|
345
350
|
onDragStart();
|
|
346
|
-
document.addEventListener(
|
|
351
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
347
352
|
}
|
|
348
353
|
},
|
|
349
354
|
[state, onDragStart, handleMouseUp]
|
|
@@ -372,14 +377,14 @@ const Spreadsheet = <CellType extends Types.CellBase>(
|
|
|
372
377
|
);
|
|
373
378
|
|
|
374
379
|
React.useEffect(() => {
|
|
375
|
-
document.addEventListener(
|
|
376
|
-
document.addEventListener(
|
|
377
|
-
document.addEventListener(
|
|
380
|
+
document.addEventListener('cut', handleCut);
|
|
381
|
+
document.addEventListener('copy', handleCopy);
|
|
382
|
+
document.addEventListener('paste', handlePaste);
|
|
378
383
|
|
|
379
384
|
return () => {
|
|
380
|
-
document.removeEventListener(
|
|
381
|
-
document.removeEventListener(
|
|
382
|
-
document.removeEventListener(
|
|
385
|
+
document.removeEventListener('cut', handleCut);
|
|
386
|
+
document.removeEventListener('copy', handleCopy);
|
|
387
|
+
document.removeEventListener('paste', handlePaste);
|
|
383
388
|
};
|
|
384
389
|
}, [handleCut, handleCopy, handlePaste]);
|
|
385
390
|
|
|
@@ -388,35 +393,33 @@ const Spreadsheet = <CellType extends Types.CellBase>(
|
|
|
388
393
|
<Table columns={size.columns}>
|
|
389
394
|
<HeaderRow>
|
|
390
395
|
{<CornerIndicator />}
|
|
391
|
-
{
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
)}
|
|
396
|
+
{range(size.columns).map((columnNumber) =>
|
|
397
|
+
columnLabels ? (
|
|
398
|
+
<ColumnIndicator
|
|
399
|
+
key={columnNumber}
|
|
400
|
+
column={columnNumber}
|
|
401
|
+
label={
|
|
402
|
+
columnNumber in columnLabels
|
|
403
|
+
? columnLabels[columnNumber]
|
|
404
|
+
: null
|
|
405
|
+
}
|
|
406
|
+
/>
|
|
407
|
+
) : (
|
|
408
|
+
<ColumnIndicator key={columnNumber} column={columnNumber} />
|
|
409
|
+
)
|
|
410
|
+
)}
|
|
407
411
|
</HeaderRow>
|
|
408
412
|
{range(size.rows).map((rowNumber) => (
|
|
409
413
|
<Row key={rowNumber} row={rowNumber}>
|
|
410
|
-
{
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
))}
|
|
414
|
+
{rowLabels ? (
|
|
415
|
+
<RowIndicator
|
|
416
|
+
key={rowNumber}
|
|
417
|
+
row={rowNumber}
|
|
418
|
+
label={rowNumber in rowLabels ? rowLabels[rowNumber] : null}
|
|
419
|
+
/>
|
|
420
|
+
) : (
|
|
421
|
+
<RowIndicator key={rowNumber} row={rowNumber} />
|
|
422
|
+
)}
|
|
420
423
|
{range(size.columns).map((columnNumber) => (
|
|
421
424
|
<Cell
|
|
422
425
|
key={columnNumber}
|
|
@@ -458,18 +461,29 @@ const Spreadsheet = <CellType extends Types.CellBase>(
|
|
|
458
461
|
|
|
459
462
|
const rootNode = React.useMemo(
|
|
460
463
|
() => (
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
<
|
|
472
|
-
|
|
464
|
+
<>
|
|
465
|
+
<ExcelToolBar
|
|
466
|
+
data={props.data}
|
|
467
|
+
onBold={onBold}
|
|
468
|
+
onItalic={onItalic}
|
|
469
|
+
onUnderline={onUnderline}
|
|
470
|
+
setColor={setColor}
|
|
471
|
+
setBackgroundColor={setBackgroundColor}
|
|
472
|
+
setFormatePainter={setFormatePainter}
|
|
473
|
+
/>
|
|
474
|
+
<div
|
|
475
|
+
ref={rootRef}
|
|
476
|
+
className={classNames('Spreadsheet', className)}
|
|
477
|
+
onKeyPress={onKeyPress}
|
|
478
|
+
onKeyDown={handleKeyDown}
|
|
479
|
+
onMouseMove={handleMouseMove}
|
|
480
|
+
>
|
|
481
|
+
{tableNode}
|
|
482
|
+
{activeCellNode}
|
|
483
|
+
<Selected />
|
|
484
|
+
<Copied />
|
|
485
|
+
</div>
|
|
486
|
+
</>
|
|
473
487
|
),
|
|
474
488
|
[
|
|
475
489
|
className,
|