pixel-react 1.2.6 → 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 +29 -17
- 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/MultiSelect/MultiSelect.d.ts +1 -1
- package/lib/components/MultiSelect/MultiSelectTypes.d.ts +1 -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 +76 -24
- package/lib/index.esm.js +1467 -1038
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +1468 -1038
- 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/Drawer.stories.tsx +8 -9
- package/src/components/Drawer/Drawer.tsx +8 -5
- package/src/components/Drawer/Types.ts +27 -14
- 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/Form/Forms.tsx +5 -1
- 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/ModulesChip/ModuleChip.scss +2 -2
- package/src/components/ModulesChip/ModuleChip.tsx +4 -4
- package/src/components/MultiSelect/Dropdown.tsx +5 -2
- package/src/components/MultiSelect/MultiSelect.scss +16 -11
- package/src/components/MultiSelect/MultiSelect.stories.tsx +17 -13
- package/src/components/MultiSelect/MultiSelect.tsx +49 -26
- package/src/components/MultiSelect/MultiSelectTypes.ts +2 -1
- 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/components/Tooltip/Tooltip.scss +1 -1
- 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
@@ -1,952 +0,0 @@
|
|
1
|
-
import { PointRange } from './point-range';
|
2
|
-
import * as Matrix from './matrix';
|
3
|
-
import * as Types from './types';
|
4
|
-
import * as Point from './point';
|
5
|
-
import {
|
6
|
-
Selection,
|
7
|
-
EmptySelection,
|
8
|
-
RangeSelection,
|
9
|
-
EntireColumnsSelection,
|
10
|
-
EntireRowsSelection,
|
11
|
-
EntireWorksheetSelection,
|
12
|
-
} from './selection';
|
13
|
-
import { isActive } from './util';
|
14
|
-
import * as Actions from './actions';
|
15
|
-
import { Model, updateCellValue, createFormulaParser } from './engine';
|
16
|
-
|
17
|
-
export const INITIAL_STATE: Types.StoreState = {
|
18
|
-
active: null,
|
19
|
-
mode: 'view',
|
20
|
-
rowDimensions: {},
|
21
|
-
columnDimensions: {},
|
22
|
-
lastChanged: null,
|
23
|
-
hasPasted: false,
|
24
|
-
cut: false,
|
25
|
-
dragging: false,
|
26
|
-
model: new Model(createFormulaParser, []),
|
27
|
-
selected: new EmptySelection(),
|
28
|
-
copied: null,
|
29
|
-
lastCommit: null,
|
30
|
-
};
|
31
|
-
|
32
|
-
export default function reducer(
|
33
|
-
state: Types.StoreState,
|
34
|
-
action: Actions.Action
|
35
|
-
): Types.StoreState {
|
36
|
-
switch (action.type) {
|
37
|
-
case Actions.BOLD: {
|
38
|
-
const selectedRange = state.selected.toRange(state.model.data);
|
39
|
-
const updatedData = applyBoldToCells(
|
40
|
-
state.model.data,
|
41
|
-
selectedRange as PointRange
|
42
|
-
);
|
43
|
-
return {
|
44
|
-
...state,
|
45
|
-
model: new Model(state.model.createFormulaParser, updatedData),
|
46
|
-
};
|
47
|
-
}
|
48
|
-
|
49
|
-
case Actions.ITALIC: {
|
50
|
-
const selectedRange = state.selected.toRange(state.model.data);
|
51
|
-
const updatedData = applyItalicToCells(
|
52
|
-
state.model.data,
|
53
|
-
selectedRange as PointRange
|
54
|
-
);
|
55
|
-
return {
|
56
|
-
...state,
|
57
|
-
model: new Model(state.model.createFormulaParser, updatedData),
|
58
|
-
};
|
59
|
-
}
|
60
|
-
|
61
|
-
case Actions.UNDERLINE: {
|
62
|
-
const selectedRange = state.selected.toRange(state.model.data);
|
63
|
-
const updatedData = applyUnderlineToCells(
|
64
|
-
state.model.data,
|
65
|
-
selectedRange as PointRange
|
66
|
-
);
|
67
|
-
return {
|
68
|
-
...state,
|
69
|
-
model: new Model(state.model.createFormulaParser, updatedData),
|
70
|
-
};
|
71
|
-
}
|
72
|
-
case Actions.COLOR: {
|
73
|
-
const { value } = action.payload;
|
74
|
-
const selectedRange = state.selected.toRange(state.model.data);
|
75
|
-
const updatedData = applyColorToCells(
|
76
|
-
state.model.data,
|
77
|
-
selectedRange as PointRange,
|
78
|
-
value
|
79
|
-
);
|
80
|
-
|
81
|
-
return {
|
82
|
-
...state,
|
83
|
-
model: new Model(state.model.createFormulaParser, updatedData),
|
84
|
-
};
|
85
|
-
}
|
86
|
-
|
87
|
-
case Actions.BACKGROUND_COLOR: {
|
88
|
-
const { value } = action.payload;
|
89
|
-
const selectedRange = state.selected.toRange(state.model.data);
|
90
|
-
const updatedData = applyBackgroundColorToCells(
|
91
|
-
state.model.data,
|
92
|
-
selectedRange as PointRange,
|
93
|
-
value
|
94
|
-
);
|
95
|
-
|
96
|
-
return {
|
97
|
-
...state,
|
98
|
-
model: new Model(state.model.createFormulaParser, updatedData),
|
99
|
-
};
|
100
|
-
}
|
101
|
-
|
102
|
-
case Actions.FORMATE_PAINTER: {
|
103
|
-
const selectedRange = state.selected.toRange(state.model.data);
|
104
|
-
const updatedData = applyUnderlineToCells(
|
105
|
-
state.model.data,
|
106
|
-
selectedRange as PointRange
|
107
|
-
);
|
108
|
-
return {
|
109
|
-
...state,
|
110
|
-
model: new Model(state.model.createFormulaParser, updatedData),
|
111
|
-
};
|
112
|
-
}
|
113
|
-
|
114
|
-
case Actions.SET_DATA: {
|
115
|
-
const { data } = action.payload;
|
116
|
-
const nextActive =
|
117
|
-
state.active && Matrix.has(state.active, data) ? state.active : null;
|
118
|
-
const nextSelected = state.selected.normalizeTo(data);
|
119
|
-
return {
|
120
|
-
...state,
|
121
|
-
model: new Model(state.model.createFormulaParser, data),
|
122
|
-
active: nextActive,
|
123
|
-
selected: nextSelected,
|
124
|
-
};
|
125
|
-
}
|
126
|
-
case Actions.SET_CREATE_FORMULA_PARSER: {
|
127
|
-
const { createFormulaParser } = action.payload;
|
128
|
-
return {
|
129
|
-
...state,
|
130
|
-
model: new Model(createFormulaParser, state.model.data),
|
131
|
-
};
|
132
|
-
}
|
133
|
-
case Actions.SELECT_ENTIRE_ROW: {
|
134
|
-
const { row, extend } = action.payload;
|
135
|
-
const { active } = state;
|
136
|
-
|
137
|
-
return {
|
138
|
-
...state,
|
139
|
-
selected:
|
140
|
-
extend && active
|
141
|
-
? new EntireRowsSelection(active.row, row)
|
142
|
-
: new EntireRowsSelection(row, row),
|
143
|
-
active: extend && active ? active : { ...Point.ORIGIN, row },
|
144
|
-
mode: 'view',
|
145
|
-
};
|
146
|
-
}
|
147
|
-
case Actions.SELECT_ENTIRE_COLUMN: {
|
148
|
-
const { column, extend } = action.payload;
|
149
|
-
const { active } = state;
|
150
|
-
|
151
|
-
return {
|
152
|
-
...state,
|
153
|
-
selected:
|
154
|
-
extend && active
|
155
|
-
? new EntireColumnsSelection(active.column, column)
|
156
|
-
: new EntireColumnsSelection(column, column),
|
157
|
-
active: extend && active ? active : { ...Point.ORIGIN, column },
|
158
|
-
mode: 'view',
|
159
|
-
};
|
160
|
-
}
|
161
|
-
case Actions.SELECT_ENTIRE_WORKSHEET: {
|
162
|
-
return {
|
163
|
-
...state,
|
164
|
-
selected: new EntireWorksheetSelection(),
|
165
|
-
active: Point.ORIGIN,
|
166
|
-
mode: 'view',
|
167
|
-
};
|
168
|
-
}
|
169
|
-
case Actions.SET_SELECTION: {
|
170
|
-
const { selection } = action.payload;
|
171
|
-
const range = selection.toRange(state.model.data);
|
172
|
-
const active =
|
173
|
-
state.active && selection.has(state.model.data, state.active)
|
174
|
-
? state.active
|
175
|
-
: range?.start;
|
176
|
-
return {
|
177
|
-
...state,
|
178
|
-
selected: selection,
|
179
|
-
active: active || null,
|
180
|
-
mode: 'view',
|
181
|
-
};
|
182
|
-
}
|
183
|
-
case Actions.SELECT: {
|
184
|
-
const { point } = action.payload;
|
185
|
-
if (state.active && !isActive(state.active, point)) {
|
186
|
-
return {
|
187
|
-
...state,
|
188
|
-
selected: new RangeSelection(new PointRange(point, state.active)),
|
189
|
-
mode: 'view',
|
190
|
-
};
|
191
|
-
}
|
192
|
-
return state;
|
193
|
-
}
|
194
|
-
case Actions.ACTIVATE: {
|
195
|
-
const { point } = action.payload;
|
196
|
-
return {
|
197
|
-
...state,
|
198
|
-
selected: new RangeSelection(new PointRange(point, point)),
|
199
|
-
active: point,
|
200
|
-
mode: isActive(state.active, point) ? 'edit' : 'view',
|
201
|
-
};
|
202
|
-
}
|
203
|
-
case Actions.SET_CELL_DATA: {
|
204
|
-
const { active, data: cellData } = action.payload;
|
205
|
-
if (isActiveReadOnly(state)) {
|
206
|
-
return state;
|
207
|
-
}
|
208
|
-
return {
|
209
|
-
...state,
|
210
|
-
model: updateCellValue(state.model, active, cellData),
|
211
|
-
lastChanged: active,
|
212
|
-
};
|
213
|
-
}
|
214
|
-
case Actions.SET_CELL_DIMENSIONS: {
|
215
|
-
const { point, dimensions } = action.payload;
|
216
|
-
const prevRowDimensions = state.rowDimensions[point.row];
|
217
|
-
const prevColumnDimensions = state.columnDimensions[point.column];
|
218
|
-
if (
|
219
|
-
prevRowDimensions &&
|
220
|
-
prevColumnDimensions &&
|
221
|
-
prevRowDimensions.top === dimensions.top &&
|
222
|
-
prevRowDimensions.height === dimensions.height &&
|
223
|
-
prevColumnDimensions.left === dimensions.left &&
|
224
|
-
prevColumnDimensions.width === dimensions.width
|
225
|
-
) {
|
226
|
-
return state;
|
227
|
-
}
|
228
|
-
return {
|
229
|
-
...state,
|
230
|
-
rowDimensions: {
|
231
|
-
...state.rowDimensions,
|
232
|
-
[point.row]: { top: dimensions.top, height: dimensions.height },
|
233
|
-
},
|
234
|
-
columnDimensions: {
|
235
|
-
...state.columnDimensions,
|
236
|
-
[point.column]: { left: dimensions.left, width: dimensions.width },
|
237
|
-
},
|
238
|
-
};
|
239
|
-
}
|
240
|
-
case Actions.COPY:
|
241
|
-
case Actions.CUT: {
|
242
|
-
const selectedRange = state.selected.toRange(state.model.data);
|
243
|
-
return {
|
244
|
-
...state,
|
245
|
-
copied: selectedRange,
|
246
|
-
cut: action.type === Actions.CUT,
|
247
|
-
hasPasted: false,
|
248
|
-
};
|
249
|
-
}
|
250
|
-
|
251
|
-
case Actions.PASTE: {
|
252
|
-
const { data: text } = action.payload;
|
253
|
-
const { active } = state;
|
254
|
-
|
255
|
-
if (!active) {
|
256
|
-
return state;
|
257
|
-
}
|
258
|
-
|
259
|
-
const copied = Matrix.split(text, (value) => ({ value }));
|
260
|
-
const copiedSize = Matrix.getSize(copied);
|
261
|
-
|
262
|
-
const selectedRange = state.selected.toRange(state.model.data);
|
263
|
-
if (selectedRange && copiedSize.rows === 1 && copiedSize.columns === 1) {
|
264
|
-
const cell = Matrix.get({ row: 0, column: 0 }, copied);
|
265
|
-
let newData =
|
266
|
-
state.cut && state.copied
|
267
|
-
? Matrix.unset(state.copied.start, state.model.data)
|
268
|
-
: state.model.data;
|
269
|
-
const commit: Types.StoreState['lastCommit'] = [];
|
270
|
-
for (const point of selectedRange || []) {
|
271
|
-
const currentCell = Matrix.get(point, state.model.data);
|
272
|
-
commit.push({
|
273
|
-
prevCell: currentCell || null,
|
274
|
-
nextCell: cell || null,
|
275
|
-
});
|
276
|
-
newData = Matrix.set(point, cell, newData);
|
277
|
-
}
|
278
|
-
|
279
|
-
return {
|
280
|
-
...state,
|
281
|
-
model: new Model(createFormulaParser, newData),
|
282
|
-
copied: null,
|
283
|
-
cut: false,
|
284
|
-
hasPasted: true,
|
285
|
-
mode: 'view',
|
286
|
-
lastCommit: commit,
|
287
|
-
};
|
288
|
-
}
|
289
|
-
|
290
|
-
const requiredSize: Matrix.Size = {
|
291
|
-
rows: active.row + copiedSize.rows,
|
292
|
-
columns: active.column + copiedSize.columns,
|
293
|
-
};
|
294
|
-
const paddedData = Matrix.pad(state.model.data, requiredSize);
|
295
|
-
|
296
|
-
let acc: {
|
297
|
-
data: Types.StoreState['model']['data'];
|
298
|
-
commit: Types.StoreState['lastCommit'];
|
299
|
-
} = { data: paddedData, commit: [] };
|
300
|
-
for (const [point, cell] of Matrix.entries(copied)) {
|
301
|
-
let commit = acc.commit || [];
|
302
|
-
const nextPoint: Point.Point = {
|
303
|
-
row: point.row + active.row,
|
304
|
-
column: point.column + active.column,
|
305
|
-
};
|
306
|
-
|
307
|
-
let nextData = acc.data;
|
308
|
-
|
309
|
-
if (state.cut) {
|
310
|
-
if (state.copied) {
|
311
|
-
const prevPoint: Point.Point = {
|
312
|
-
row: point.row + state.copied.start.row,
|
313
|
-
column: point.column + state.copied.start.column,
|
314
|
-
};
|
315
|
-
nextData = Matrix.unset(prevPoint, acc.data);
|
316
|
-
}
|
317
|
-
|
318
|
-
commit = [...commit, { prevCell: cell || null, nextCell: null }];
|
319
|
-
}
|
320
|
-
|
321
|
-
if (!Matrix.has(nextPoint, paddedData)) {
|
322
|
-
acc = { data: nextData, commit };
|
323
|
-
}
|
324
|
-
|
325
|
-
const currentCell = Matrix.get(nextPoint, nextData) || null;
|
326
|
-
|
327
|
-
commit = [
|
328
|
-
...commit,
|
329
|
-
{
|
330
|
-
prevCell: currentCell,
|
331
|
-
nextCell: cell || null,
|
332
|
-
},
|
333
|
-
];
|
334
|
-
|
335
|
-
acc.data = Matrix.set(
|
336
|
-
nextPoint,
|
337
|
-
{ value: undefined, ...currentCell, ...cell },
|
338
|
-
nextData
|
339
|
-
);
|
340
|
-
acc.commit = commit;
|
341
|
-
}
|
342
|
-
|
343
|
-
return {
|
344
|
-
...state,
|
345
|
-
model: new Model(createFormulaParser, acc.data),
|
346
|
-
selected: new RangeSelection(
|
347
|
-
new PointRange(active, {
|
348
|
-
row: active.row + copiedSize.rows - 1,
|
349
|
-
column: active.column + copiedSize.columns - 1,
|
350
|
-
})
|
351
|
-
),
|
352
|
-
copied: null,
|
353
|
-
cut: false,
|
354
|
-
hasPasted: true,
|
355
|
-
mode: 'view',
|
356
|
-
lastCommit: acc.commit,
|
357
|
-
};
|
358
|
-
}
|
359
|
-
|
360
|
-
case Actions.EDIT: {
|
361
|
-
return edit(state);
|
362
|
-
}
|
363
|
-
|
364
|
-
case Actions.VIEW: {
|
365
|
-
return view(state);
|
366
|
-
}
|
367
|
-
|
368
|
-
case Actions.CLEAR: {
|
369
|
-
return clear(state);
|
370
|
-
}
|
371
|
-
|
372
|
-
case Actions.BLUR: {
|
373
|
-
return blur(state);
|
374
|
-
}
|
375
|
-
|
376
|
-
case Actions.KEY_PRESS: {
|
377
|
-
const { event } = action.payload;
|
378
|
-
if (isActiveReadOnly(state) || event.metaKey) {
|
379
|
-
return state;
|
380
|
-
}
|
381
|
-
if (state.mode === 'view' && state.active) {
|
382
|
-
const selectedRange = state.selected.toRange(state.model.data);
|
383
|
-
if (selectedRange?.size() === 1) {
|
384
|
-
return edit(clear(state));
|
385
|
-
}
|
386
|
-
return edit(state);
|
387
|
-
}
|
388
|
-
return state;
|
389
|
-
}
|
390
|
-
|
391
|
-
case Actions.KEY_DOWN: {
|
392
|
-
const { event } = action.payload;
|
393
|
-
const handler = getKeyDownHandler(state, event);
|
394
|
-
if (handler) {
|
395
|
-
return { ...state, ...handler(state, event) };
|
396
|
-
}
|
397
|
-
return state;
|
398
|
-
}
|
399
|
-
|
400
|
-
case Actions.DRAG_START: {
|
401
|
-
return { ...state, dragging: true };
|
402
|
-
}
|
403
|
-
|
404
|
-
case Actions.DRAG_END: {
|
405
|
-
return { ...state, dragging: false };
|
406
|
-
}
|
407
|
-
|
408
|
-
case Actions.COMMIT: {
|
409
|
-
const { changes } = action.payload;
|
410
|
-
return { ...state, ...commit(changes) };
|
411
|
-
}
|
412
|
-
|
413
|
-
default:
|
414
|
-
throw new Error('Unknown action');
|
415
|
-
}
|
416
|
-
}
|
417
|
-
|
418
|
-
// const reducer = createReducer(INITIAL_STATE, (builder) => {
|
419
|
-
// builder.addMatcher(
|
420
|
-
// (action) =>
|
421
|
-
// action.type === Actions.copy.type || action.type === Actions.cut.type,
|
422
|
-
// (state, action) => {
|
423
|
-
|
424
|
-
// }
|
425
|
-
// );
|
426
|
-
// });
|
427
|
-
|
428
|
-
// // Shared reducers
|
429
|
-
|
430
|
-
function applyBoldToCells(
|
431
|
-
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
432
|
-
selectedRange: PointRange
|
433
|
-
): Matrix.Matrix<Types.CellBase<any>> {
|
434
|
-
const { start, end } = selectedRange;
|
435
|
-
|
436
|
-
let updatedData = currentData;
|
437
|
-
|
438
|
-
for (let row = start.row; row <= end.row; row++) {
|
439
|
-
for (let col = start.column; col <= end.column; col++) {
|
440
|
-
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
441
|
-
|
442
|
-
if (!currentCell) {
|
443
|
-
continue;
|
444
|
-
}
|
445
|
-
|
446
|
-
const updatedCell = {
|
447
|
-
...currentCell,
|
448
|
-
style: {
|
449
|
-
...currentCell.style,
|
450
|
-
fontWeight: 'bold',
|
451
|
-
},
|
452
|
-
};
|
453
|
-
|
454
|
-
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
455
|
-
}
|
456
|
-
}
|
457
|
-
|
458
|
-
return updatedData;
|
459
|
-
}
|
460
|
-
|
461
|
-
function applyItalicToCells(
|
462
|
-
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
463
|
-
selectedRange: PointRange
|
464
|
-
): Matrix.Matrix<Types.CellBase<any>> {
|
465
|
-
const { start, end } = selectedRange;
|
466
|
-
|
467
|
-
let updatedData = currentData;
|
468
|
-
|
469
|
-
for (let row = start.row; row <= end.row; row++) {
|
470
|
-
for (let col = start.column; col <= end.column; col++) {
|
471
|
-
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
472
|
-
|
473
|
-
if (!currentCell) {
|
474
|
-
continue;
|
475
|
-
}
|
476
|
-
|
477
|
-
const updatedCell = {
|
478
|
-
...currentCell,
|
479
|
-
style: {
|
480
|
-
...currentCell.style,
|
481
|
-
fontStyle: 'italic',
|
482
|
-
},
|
483
|
-
};
|
484
|
-
|
485
|
-
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
486
|
-
}
|
487
|
-
}
|
488
|
-
|
489
|
-
return updatedData;
|
490
|
-
}
|
491
|
-
|
492
|
-
function applyUnderlineToCells(
|
493
|
-
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
494
|
-
selectedRange: PointRange
|
495
|
-
): Matrix.Matrix<Types.CellBase<any>> {
|
496
|
-
const { start, end } = selectedRange;
|
497
|
-
|
498
|
-
let updatedData = currentData;
|
499
|
-
|
500
|
-
for (let row = start.row; row <= end.row; row++) {
|
501
|
-
for (let col = start.column; col <= end.column; col++) {
|
502
|
-
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
503
|
-
|
504
|
-
if (!currentCell) {
|
505
|
-
continue;
|
506
|
-
}
|
507
|
-
|
508
|
-
const updatedCell = {
|
509
|
-
...currentCell,
|
510
|
-
style: {
|
511
|
-
...currentCell.style,
|
512
|
-
textDecoration: 'underline',
|
513
|
-
},
|
514
|
-
};
|
515
|
-
|
516
|
-
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
517
|
-
}
|
518
|
-
}
|
519
|
-
|
520
|
-
return updatedData;
|
521
|
-
}
|
522
|
-
|
523
|
-
function isValidHexColor(color: string): boolean {
|
524
|
-
if (color.length !== 6) {
|
525
|
-
return false;
|
526
|
-
}
|
527
|
-
|
528
|
-
const hexChars = '0123456789ABCDEFabcdef';
|
529
|
-
for (let i = 1; i < color.length; i++) {
|
530
|
-
console.log(typeof color[i]);
|
531
|
-
|
532
|
-
if (!hexChars.includes(color[i] as string)) {
|
533
|
-
return false;
|
534
|
-
}
|
535
|
-
}
|
536
|
-
|
537
|
-
return true;
|
538
|
-
}
|
539
|
-
|
540
|
-
function applyColorToCells(
|
541
|
-
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
542
|
-
selectedRange: PointRange | null,
|
543
|
-
color: string
|
544
|
-
): Matrix.Matrix<Types.CellBase<any>> {
|
545
|
-
if (!selectedRange) {
|
546
|
-
return currentData;
|
547
|
-
}
|
548
|
-
|
549
|
-
const { start, end } = selectedRange;
|
550
|
-
|
551
|
-
let updatedData = currentData;
|
552
|
-
|
553
|
-
const isHex = isValidHexColor(color);
|
554
|
-
|
555
|
-
const applyColor = isHex ? `#${color}` : color;
|
556
|
-
|
557
|
-
for (let row = start.row; row <= end.row; row++) {
|
558
|
-
for (let col = start.column; col <= end.column; col++) {
|
559
|
-
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
560
|
-
|
561
|
-
if (!currentCell) {
|
562
|
-
continue;
|
563
|
-
}
|
564
|
-
|
565
|
-
const updatedCell = {
|
566
|
-
...currentCell,
|
567
|
-
style: {
|
568
|
-
...currentCell.style,
|
569
|
-
color: applyColor,
|
570
|
-
},
|
571
|
-
};
|
572
|
-
|
573
|
-
updatedData = Matrix.set({ row, column: col }, updatedCell, updatedData);
|
574
|
-
}
|
575
|
-
}
|
576
|
-
|
577
|
-
return updatedData;
|
578
|
-
}
|
579
|
-
|
580
|
-
function applyBackgroundColorToCells(
|
581
|
-
currentData: Matrix.Matrix<Types.CellBase<any>>,
|
582
|
-
selectedRange: PointRange | null,
|
583
|
-
backgroundColor: string
|
584
|
-
): Matrix.Matrix<Types.CellBase<any>> {
|
585
|
-
if (selectedRange) {
|
586
|
-
const { start, end } = selectedRange;
|
587
|
-
|
588
|
-
let updatedData = currentData;
|
589
|
-
|
590
|
-
const isHex = isValidHexColor(backgroundColor);
|
591
|
-
|
592
|
-
const applyColor = isHex ? `#${backgroundColor}` : backgroundColor;
|
593
|
-
|
594
|
-
for (let row = start.row; row <= end.row; row++) {
|
595
|
-
for (let col = start.column; col <= end.column; col++) {
|
596
|
-
const currentCell = Matrix.get({ row, column: col }, updatedData);
|
597
|
-
|
598
|
-
if (!currentCell) {
|
599
|
-
continue;
|
600
|
-
}
|
601
|
-
|
602
|
-
const updatedCell = {
|
603
|
-
...currentCell,
|
604
|
-
style: {
|
605
|
-
...currentCell.style,
|
606
|
-
backgroundColor: applyColor,
|
607
|
-
},
|
608
|
-
};
|
609
|
-
|
610
|
-
updatedData = Matrix.set(
|
611
|
-
{ row, column: col },
|
612
|
-
updatedCell,
|
613
|
-
updatedData
|
614
|
-
);
|
615
|
-
}
|
616
|
-
}
|
617
|
-
|
618
|
-
return updatedData;
|
619
|
-
}
|
620
|
-
return currentData;
|
621
|
-
}
|
622
|
-
|
623
|
-
function edit(state: Types.StoreState): Types.StoreState {
|
624
|
-
if (isActiveReadOnly(state)) {
|
625
|
-
return state;
|
626
|
-
}
|
627
|
-
return { ...state, mode: 'edit' };
|
628
|
-
}
|
629
|
-
|
630
|
-
function clear(state: Types.StoreState): Types.StoreState {
|
631
|
-
if (!state.active) {
|
632
|
-
return state;
|
633
|
-
}
|
634
|
-
|
635
|
-
const canClearCell = (cell: Types.CellBase | undefined) =>
|
636
|
-
cell && !cell.readOnly;
|
637
|
-
const clearCell = (cell: Types.CellBase | undefined) => {
|
638
|
-
if (!canClearCell(cell)) {
|
639
|
-
return cell;
|
640
|
-
}
|
641
|
-
return Object.assign({}, cell, { value: undefined });
|
642
|
-
};
|
643
|
-
|
644
|
-
const selectedRange = state.selected.toRange(state.model.data);
|
645
|
-
|
646
|
-
const changes: Types.CommitChanges = [];
|
647
|
-
let newData = state.model.data;
|
648
|
-
|
649
|
-
for (const point of selectedRange || []) {
|
650
|
-
const cell = Matrix.get(point, state.model.data);
|
651
|
-
const clearedCell = clearCell(cell);
|
652
|
-
changes.push({
|
653
|
-
prevCell: cell || null,
|
654
|
-
nextCell: clearedCell || null,
|
655
|
-
});
|
656
|
-
newData = Matrix.set(point, clearedCell, newData);
|
657
|
-
}
|
658
|
-
|
659
|
-
return {
|
660
|
-
...state,
|
661
|
-
model: new Model(createFormulaParser, newData),
|
662
|
-
...commit(changes),
|
663
|
-
};
|
664
|
-
}
|
665
|
-
|
666
|
-
function blur(state: Types.StoreState): Types.StoreState {
|
667
|
-
return { ...state, active: null, selected: new EmptySelection() };
|
668
|
-
}
|
669
|
-
|
670
|
-
function view(state: Types.StoreState): Types.StoreState {
|
671
|
-
return { ...state, mode: 'view' };
|
672
|
-
}
|
673
|
-
|
674
|
-
function commit(changes: Types.CommitChanges): Partial<Types.StoreState> {
|
675
|
-
return { lastCommit: changes };
|
676
|
-
}
|
677
|
-
|
678
|
-
// Utility
|
679
|
-
|
680
|
-
export const go =
|
681
|
-
(rowDelta: number, columnDelta: number): KeyDownHandler =>
|
682
|
-
(state) => {
|
683
|
-
if (!state.active) {
|
684
|
-
return;
|
685
|
-
}
|
686
|
-
const size = Matrix.getSize(state.model.data);
|
687
|
-
const newColumn = state.active.column + columnDelta;
|
688
|
-
const shouldWrap = newColumn >= size.columns;
|
689
|
-
const nextActive = {
|
690
|
-
row: state.active.row + rowDelta + (shouldWrap ? 1 : 0),
|
691
|
-
column: (state.active.column + columnDelta) % size.columns,
|
692
|
-
};
|
693
|
-
if (!Matrix.has(nextActive, state.model.data)) {
|
694
|
-
return { ...state, mode: 'view' };
|
695
|
-
}
|
696
|
-
return {
|
697
|
-
...state,
|
698
|
-
active: nextActive,
|
699
|
-
selected: new RangeSelection(new PointRange(nextActive, nextActive)),
|
700
|
-
mode: 'view',
|
701
|
-
};
|
702
|
-
};
|
703
|
-
|
704
|
-
// Key Bindings
|
705
|
-
|
706
|
-
export type KeyDownHandler = (
|
707
|
-
state: Types.StoreState,
|
708
|
-
event: React.KeyboardEvent
|
709
|
-
) => Types.StoreState | void;
|
710
|
-
|
711
|
-
type KeyDownHandlers = {
|
712
|
-
[K in string]: KeyDownHandler | undefined;
|
713
|
-
};
|
714
|
-
|
715
|
-
const keyDownHandlers: KeyDownHandlers = {
|
716
|
-
ArrowUp: go(-1, 0),
|
717
|
-
ArrowDown: go(+1, 0),
|
718
|
-
ArrowLeft: go(0, -1),
|
719
|
-
ArrowRight: go(0, +1),
|
720
|
-
Tab: go(0, +1),
|
721
|
-
Enter: edit,
|
722
|
-
Backspace: clear,
|
723
|
-
Delete: clear,
|
724
|
-
Escape: blur,
|
725
|
-
};
|
726
|
-
|
727
|
-
const editKeyDownHandlers: KeyDownHandlers = {
|
728
|
-
Escape: view,
|
729
|
-
Tab: keyDownHandlers.Tab,
|
730
|
-
Enter: keyDownHandlers.ArrowDown,
|
731
|
-
};
|
732
|
-
|
733
|
-
const editShiftKeyDownHandlers: KeyDownHandlers = {
|
734
|
-
Tab: go(0, -1),
|
735
|
-
};
|
736
|
-
|
737
|
-
export enum Direction {
|
738
|
-
Left = 'Left',
|
739
|
-
Right = 'Right',
|
740
|
-
Top = 'Top',
|
741
|
-
Bottom = 'Bottom',
|
742
|
-
}
|
743
|
-
|
744
|
-
const shiftKeyDownHandlers: KeyDownHandlers = {
|
745
|
-
ArrowUp: (state) => ({
|
746
|
-
...state,
|
747
|
-
selected: modifyEdge(
|
748
|
-
state.selected,
|
749
|
-
state.active,
|
750
|
-
state.model.data,
|
751
|
-
Direction.Top
|
752
|
-
),
|
753
|
-
}),
|
754
|
-
ArrowDown: (state) => ({
|
755
|
-
...state,
|
756
|
-
selected: modifyEdge(
|
757
|
-
state.selected,
|
758
|
-
state.active,
|
759
|
-
state.model.data,
|
760
|
-
Direction.Bottom
|
761
|
-
),
|
762
|
-
}),
|
763
|
-
ArrowLeft: (state) => ({
|
764
|
-
...state,
|
765
|
-
selected: modifyEdge(
|
766
|
-
state.selected,
|
767
|
-
state.active,
|
768
|
-
state.model.data,
|
769
|
-
Direction.Left
|
770
|
-
),
|
771
|
-
}),
|
772
|
-
ArrowRight: (state) => ({
|
773
|
-
...state,
|
774
|
-
selected: modifyEdge(
|
775
|
-
state.selected,
|
776
|
-
state.active,
|
777
|
-
state.model.data,
|
778
|
-
Direction.Right
|
779
|
-
),
|
780
|
-
}),
|
781
|
-
Tab: go(0, -1),
|
782
|
-
};
|
783
|
-
|
784
|
-
const shiftMetaKeyDownHandlers: KeyDownHandlers = {};
|
785
|
-
const metaKeyDownHandlers: KeyDownHandlers = {};
|
786
|
-
|
787
|
-
export function getKeyDownHandler(
|
788
|
-
state: Types.StoreState,
|
789
|
-
event: React.KeyboardEvent
|
790
|
-
): KeyDownHandler | undefined {
|
791
|
-
const { key } = event;
|
792
|
-
let handlers;
|
793
|
-
// Order matters
|
794
|
-
if (state.mode === 'edit') {
|
795
|
-
if (event.shiftKey) {
|
796
|
-
handlers = editShiftKeyDownHandlers;
|
797
|
-
} else {
|
798
|
-
handlers = editKeyDownHandlers;
|
799
|
-
}
|
800
|
-
} else if (event.shiftKey && event.metaKey) {
|
801
|
-
handlers = shiftMetaKeyDownHandlers;
|
802
|
-
} else if (event.shiftKey) {
|
803
|
-
handlers = shiftKeyDownHandlers;
|
804
|
-
} else if (event.metaKey) {
|
805
|
-
handlers = metaKeyDownHandlers;
|
806
|
-
} else {
|
807
|
-
handlers = keyDownHandlers;
|
808
|
-
}
|
809
|
-
|
810
|
-
return handlers[key];
|
811
|
-
}
|
812
|
-
|
813
|
-
/** Returns whether the reducer has a handler for the given keydown event */
|
814
|
-
export function hasKeyDownHandler(
|
815
|
-
state: Types.StoreState,
|
816
|
-
event: React.KeyboardEvent
|
817
|
-
): boolean {
|
818
|
-
return getKeyDownHandler(state, event) !== undefined;
|
819
|
-
}
|
820
|
-
|
821
|
-
/** Returns whether the active cell is read only */
|
822
|
-
export function isActiveReadOnly(state: Types.StoreState): boolean {
|
823
|
-
const activeCell = getActive(state);
|
824
|
-
return Boolean(activeCell?.readOnly);
|
825
|
-
}
|
826
|
-
|
827
|
-
/** Gets active cell from given state */
|
828
|
-
export function getActive(state: Types.StoreState): Types.CellBase | null {
|
829
|
-
const activeCell = state.active && Matrix.get(state.active, state.model.data);
|
830
|
-
return activeCell || null;
|
831
|
-
}
|
832
|
-
|
833
|
-
/** Modify given edge according to given active point and data */
|
834
|
-
export function modifyEdge<T extends Selection>(
|
835
|
-
selection: T,
|
836
|
-
active: Point.Point | null,
|
837
|
-
data: Matrix.Matrix<unknown>,
|
838
|
-
direction: Direction
|
839
|
-
): T {
|
840
|
-
if (!active) {
|
841
|
-
return selection;
|
842
|
-
}
|
843
|
-
if (selection instanceof RangeSelection) {
|
844
|
-
const nextSelection = modifyRangeSelectionEdge(
|
845
|
-
selection,
|
846
|
-
active,
|
847
|
-
data,
|
848
|
-
direction
|
849
|
-
);
|
850
|
-
// @ts-expect-error
|
851
|
-
return nextSelection;
|
852
|
-
}
|
853
|
-
if (selection instanceof EntireColumnsSelection) {
|
854
|
-
// @ts-expect-error
|
855
|
-
return modifyEntireColumnsSelection(selection, active, data, direction);
|
856
|
-
}
|
857
|
-
if (selection instanceof EntireRowsSelection) {
|
858
|
-
// @ts-expect-error
|
859
|
-
return modifyEntireRowsSelection(selection, active, data, direction);
|
860
|
-
}
|
861
|
-
return selection;
|
862
|
-
}
|
863
|
-
|
864
|
-
export function modifyRangeSelectionEdge(
|
865
|
-
rangeSelection: RangeSelection,
|
866
|
-
active: Point.Point,
|
867
|
-
data: Matrix.Matrix<unknown>,
|
868
|
-
edge: Direction
|
869
|
-
): RangeSelection {
|
870
|
-
const field =
|
871
|
-
edge === Direction.Left || edge === Direction.Right ? 'column' : 'row';
|
872
|
-
|
873
|
-
const key =
|
874
|
-
edge === Direction.Left || edge === Direction.Top ? 'start' : 'end';
|
875
|
-
const delta = key === 'start' ? -1 : 1;
|
876
|
-
|
877
|
-
const edgeOffsets = rangeSelection.range.has({
|
878
|
-
...active,
|
879
|
-
[field]: active[field] + delta * -1,
|
880
|
-
});
|
881
|
-
|
882
|
-
const keyToModify = edgeOffsets ? (key === 'start' ? 'end' : 'start') : key;
|
883
|
-
|
884
|
-
const nextRange = new PointRange(
|
885
|
-
rangeSelection.range.start,
|
886
|
-
rangeSelection.range.end
|
887
|
-
);
|
888
|
-
|
889
|
-
nextRange[keyToModify][field] += delta;
|
890
|
-
|
891
|
-
const nextSelection = new RangeSelection(nextRange).normalizeTo(data);
|
892
|
-
|
893
|
-
return nextSelection;
|
894
|
-
}
|
895
|
-
|
896
|
-
export function modifyEntireRowsSelection(
|
897
|
-
selection: EntireRowsSelection,
|
898
|
-
active: Point.Point,
|
899
|
-
data: Matrix.Matrix<unknown>,
|
900
|
-
edge: Direction
|
901
|
-
): EntireRowsSelection {
|
902
|
-
if (edge === Direction.Left || edge === Direction.Right) {
|
903
|
-
return selection;
|
904
|
-
}
|
905
|
-
const delta = edge === Direction.Top ? -1 : 1;
|
906
|
-
const property = edge === Direction.Top ? 'start' : 'end';
|
907
|
-
const oppositeProperty = property === 'start' ? 'end' : 'start';
|
908
|
-
const newSelectionData = { ...selection };
|
909
|
-
if (
|
910
|
-
edge === Direction.Top
|
911
|
-
? selection.end > active.row
|
912
|
-
: selection.start < active.row
|
913
|
-
) {
|
914
|
-
newSelectionData[oppositeProperty] = selection[oppositeProperty] + delta;
|
915
|
-
} else {
|
916
|
-
newSelectionData[property] = selection[property] + delta;
|
917
|
-
}
|
918
|
-
const nextSelection = new EntireRowsSelection(
|
919
|
-
Math.max(newSelectionData.start, 0),
|
920
|
-
Math.max(newSelectionData.end, 0)
|
921
|
-
);
|
922
|
-
return nextSelection.normalizeTo(data);
|
923
|
-
}
|
924
|
-
|
925
|
-
export function modifyEntireColumnsSelection(
|
926
|
-
selection: EntireColumnsSelection,
|
927
|
-
active: Point.Point,
|
928
|
-
data: Matrix.Matrix<unknown>,
|
929
|
-
edge: Direction
|
930
|
-
): EntireColumnsSelection {
|
931
|
-
if (edge === Direction.Top || edge === Direction.Bottom) {
|
932
|
-
return selection;
|
933
|
-
}
|
934
|
-
const delta = edge === Direction.Left ? -1 : 1;
|
935
|
-
const property = edge === Direction.Left ? 'start' : 'end';
|
936
|
-
const oppositeProperty = property === 'start' ? 'end' : 'start';
|
937
|
-
const newSelectionData = { ...selection };
|
938
|
-
if (
|
939
|
-
edge === Direction.Left
|
940
|
-
? selection.end > active.row
|
941
|
-
: selection.start < active.row
|
942
|
-
) {
|
943
|
-
newSelectionData[oppositeProperty] = selection[oppositeProperty] + delta;
|
944
|
-
} else {
|
945
|
-
newSelectionData[property] = selection[property] + delta;
|
946
|
-
}
|
947
|
-
const nextSelection = new EntireColumnsSelection(
|
948
|
-
Math.max(newSelectionData.start, 0),
|
949
|
-
Math.max(newSelectionData.end, 0)
|
950
|
-
);
|
951
|
-
return nextSelection.normalizeTo(data);
|
952
|
-
}
|