@gridsheet/preact-core 3.0.0-rc.6 → 3.0.0-rc.8
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/dist/hooks-hS8l-fYa.mjs +1440 -0
- package/dist/hooks-hS8l-fYa.mjs.map +1 -0
- package/dist/index.d.ts +3 -34
- package/dist/index.js +367 -9232
- package/dist/index.js.map +1 -1
- package/dist/{components → react-core/src/components}/FunctionGuide.d.ts +2 -2
- package/dist/{components → react-core/src/components}/useAutocomplete.d.ts +3 -3
- package/dist/react-core/src/index.d.ts +17 -0
- package/dist/{lib → react-core/src/lib}/clipboard.d.ts +1 -1
- package/dist/{components → react-core/src/lib}/hooks.d.ts +2 -0
- package/dist/{lib → react-core/src/lib}/menu.d.ts +1 -1
- package/dist/react-core/src/lib/style.d.ts +12 -0
- package/dist/react-core/src/policy/checkbox.d.ts +3 -0
- package/dist/react-core/src/spellbook.d.ts +6 -0
- package/dist/{store → react-core/src/store}/actions.d.ts +1 -1
- package/dist/{store/dispatchers.d.ts → react-core/src/store/applyers.d.ts} +1 -1
- package/dist/{store → react-core/src/store}/helpers.d.ts +1 -2
- package/dist/react-core/src/types.d.ts +104 -0
- package/dist/spellbook.d.ts +2 -0
- package/dist/spellbook.js +10 -0
- package/dist/spellbook.js.map +1 -0
- package/package.json +18 -2
- package/dist/constants.d.ts +0 -21
- package/dist/formula/evaluator.d.ts +0 -134
- package/dist/formula/formula-error.d.ts +0 -10
- package/dist/formula/functions/__async.d.ts +0 -67
- package/dist/formula/functions/__base.d.ts +0 -112
- package/dist/formula/functions/__utils.d.ts +0 -23
- package/dist/formula/functions/abs.d.ts +0 -9
- package/dist/formula/functions/add.d.ts +0 -10
- package/dist/formula/functions/and.d.ts +0 -9
- package/dist/formula/functions/arrayformula.d.ts +0 -12
- package/dist/formula/functions/average.d.ts +0 -9
- package/dist/formula/functions/concat.d.ts +0 -9
- package/dist/formula/functions/count.d.ts +0 -9
- package/dist/formula/functions/counta.d.ts +0 -9
- package/dist/formula/functions/divide.d.ts +0 -10
- package/dist/formula/functions/eq.d.ts +0 -9
- package/dist/formula/functions/gt.d.ts +0 -9
- package/dist/formula/functions/gte.d.ts +0 -9
- package/dist/formula/functions/if.d.ts +0 -9
- package/dist/formula/functions/iferror.d.ts +0 -10
- package/dist/formula/functions/len.d.ts +0 -9
- package/dist/formula/functions/lt.d.ts +0 -9
- package/dist/formula/functions/lte.d.ts +0 -9
- package/dist/formula/functions/max.d.ts +0 -9
- package/dist/formula/functions/min.d.ts +0 -9
- package/dist/formula/functions/minus.d.ts +0 -10
- package/dist/formula/functions/multiply.d.ts +0 -9
- package/dist/formula/functions/ne.d.ts +0 -9
- package/dist/formula/functions/not.d.ts +0 -9
- package/dist/formula/functions/now.d.ts +0 -9
- package/dist/formula/functions/or.d.ts +0 -9
- package/dist/formula/functions/power.d.ts +0 -9
- package/dist/formula/functions/sum.d.ts +0 -9
- package/dist/formula/functions/uminus.d.ts +0 -9
- package/dist/formula/mapping.d.ts +0 -11
- package/dist/formula/solver.d.ts +0 -39
- package/dist/lib/autofill.d.ts +0 -17
- package/dist/lib/book.d.ts +0 -121
- package/dist/lib/cell.d.ts +0 -17
- package/dist/lib/coords.d.ts +0 -22
- package/dist/lib/date.d.ts +0 -2
- package/dist/lib/dom.d.ts +0 -7
- package/dist/lib/filter.d.ts +0 -7
- package/dist/lib/input.d.ts +0 -24
- package/dist/lib/label.d.ts +0 -4
- package/dist/lib/operation.d.ts +0 -31
- package/dist/lib/palette.d.ts +0 -2
- package/dist/lib/popup.d.ts +0 -24
- package/dist/lib/reference.d.ts +0 -19
- package/dist/lib/sheet.d.ts +0 -508
- package/dist/lib/sheet_utils.d.ts +0 -55
- package/dist/lib/spatial.d.ts +0 -79
- package/dist/lib/time.d.ts +0 -29
- package/dist/lib/virtualization.d.ts +0 -22
- package/dist/policy/checkbox.d.ts +0 -3
- package/dist/policy/core.d.ts +0 -164
- package/dist/policy/thousand_separator.d.ts +0 -4
- package/dist/sentinels.d.ts +0 -40
- package/dist/styles/embedder.d.ts +0 -2
- package/dist/styles/minified.d.ts +0 -3
- package/dist/styles/utils.d.ts +0 -52
- package/dist/types.d.ts +0 -369
- package/dist/utils.d.ts +0 -2
- /package/dist/{components → react-core/src/components}/Cell.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/CellStateOverlay.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/ColumnMenu.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/ColumnMenuFilterSection.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/ColumnMenuLabelSection.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/ColumnMenuSortSection.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/ContextMenu.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/Editor.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/EditorOptions.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/Emitter.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/Fixed.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/FormulaBar.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/GridSheet.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/HeaderCellLeft.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/HeaderCellTop.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/MenuItem.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/PluginBase.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/Resizer.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/RowMenu.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/ScrollHandle.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/SearchBar.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/StoreObserver.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/Tabular.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/svg/AddIcon.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/svg/Base.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/svg/CloseIcon.d.ts +0 -0
- /package/dist/{components → react-core/src/components}/svg/SearchIcon.d.ts +0 -0
- /package/dist/{lib → react-core/src/lib}/events.d.ts +0 -0
- /package/dist/{lib → react-core/src/lib}/paste.d.ts +0 -0
- /package/dist/{store → react-core/src/store}/index.d.ts +0 -0
|
@@ -0,0 +1,1440 @@
|
|
|
1
|
+
import { useRef, useEffect, useState } from "preact/compat";
|
|
2
|
+
import { createBook } from "@gridsheet/core";
|
|
3
|
+
import { areaToZone, zoneToArea, areaDiff, restrictZone, matrixShape, superposeArea } from "@gridsheet/core/lib/spatial";
|
|
4
|
+
import { x2c, y2r, a2p, p2a } from "@gridsheet/core/lib/coords";
|
|
5
|
+
import { DEFAULT_HEIGHT, DEFAULT_WIDTH } from "@gridsheet/core/constants";
|
|
6
|
+
import { smartScroll } from "@gridsheet/core/lib/virtualization";
|
|
7
|
+
import * as prevention from "@gridsheet/core/lib/operation";
|
|
8
|
+
import { Autofill } from "@gridsheet/core/lib/autofill";
|
|
9
|
+
const compactReflection = (reflection) => {
|
|
10
|
+
const result = { ...reflection };
|
|
11
|
+
if (result.selectingZone != null && result.selectingZone.endY === -1 && result.selectingZone.endX === -1) {
|
|
12
|
+
delete result.selectingZone;
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
};
|
|
16
|
+
const restrictPoints = (store, sheet) => {
|
|
17
|
+
const { choosing, selectingZone } = store;
|
|
18
|
+
let { y, x } = choosing;
|
|
19
|
+
let { startY: y1, startX: x1, endY: y2, endX: x2 } = selectingZone;
|
|
20
|
+
const [numRows, numCols] = [sheet.numRows, sheet.numCols];
|
|
21
|
+
if (y > numRows) {
|
|
22
|
+
y = numRows;
|
|
23
|
+
}
|
|
24
|
+
if (x > numCols) {
|
|
25
|
+
x = numCols;
|
|
26
|
+
}
|
|
27
|
+
if (y1 > numRows) {
|
|
28
|
+
y1 = numRows;
|
|
29
|
+
}
|
|
30
|
+
if (y2 > numRows) {
|
|
31
|
+
y2 = numRows;
|
|
32
|
+
}
|
|
33
|
+
if (x1 > numCols) {
|
|
34
|
+
x1 = numCols;
|
|
35
|
+
}
|
|
36
|
+
if (x2 > numCols) {
|
|
37
|
+
x2 = numCols;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
choosing: { y, x },
|
|
41
|
+
selectingZone: { startY: y1, startX: x1, endY: y2, endX: x2 }
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
const FLASH_CLASS = "gs-flash-overlay--active";
|
|
45
|
+
const FLASH_DURATION_MS = 600;
|
|
46
|
+
const flashSheet = (el) => {
|
|
47
|
+
if (!el) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
el.classList.remove(FLASH_CLASS);
|
|
51
|
+
void el.offsetWidth;
|
|
52
|
+
el.classList.add(FLASH_CLASS);
|
|
53
|
+
setTimeout(() => el.classList.remove(FLASH_CLASS), FLASH_DURATION_MS);
|
|
54
|
+
};
|
|
55
|
+
const flashWithCallback = (store, sheet, callback) => ({
|
|
56
|
+
...store,
|
|
57
|
+
sheetReactive: { current: sheet },
|
|
58
|
+
callback: (s) => {
|
|
59
|
+
callback == null ? void 0 : callback(s);
|
|
60
|
+
flashSheet(store.flashRef.current);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
const initSearchStatement = (sheet, store) => {
|
|
64
|
+
const { searchQuery, searchCaseSensitive, searchRegex, searchRange } = store;
|
|
65
|
+
let { choosing } = store;
|
|
66
|
+
if (!searchQuery) {
|
|
67
|
+
return { matchingCells: [] };
|
|
68
|
+
}
|
|
69
|
+
const matchingCells = [];
|
|
70
|
+
let matcher;
|
|
71
|
+
if (searchRegex) {
|
|
72
|
+
try {
|
|
73
|
+
const flags = searchCaseSensitive ? "" : "i";
|
|
74
|
+
const regex = new RegExp(searchQuery, flags);
|
|
75
|
+
matcher = (v) => regex.test(v);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
const q = searchCaseSensitive ? searchQuery : searchQuery.toLowerCase();
|
|
78
|
+
matcher = (v) => {
|
|
79
|
+
const s = searchCaseSensitive ? v : v.toLowerCase();
|
|
80
|
+
return s.indexOf(q) !== -1;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
const q = searchCaseSensitive ? searchQuery : searchQuery.toLowerCase();
|
|
85
|
+
matcher = (v) => {
|
|
86
|
+
const s = searchCaseSensitive ? v : v.toLowerCase();
|
|
87
|
+
return s.indexOf(q) !== -1;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
let startY = 1, endY = sheet.bottom;
|
|
91
|
+
let startX = 1, endX = sheet.right;
|
|
92
|
+
if (searchRange) {
|
|
93
|
+
startY = searchRange.startY;
|
|
94
|
+
endY = searchRange.endY;
|
|
95
|
+
startX = searchRange.startX;
|
|
96
|
+
endX = searchRange.endX;
|
|
97
|
+
}
|
|
98
|
+
for (let y = startY; y <= endY; y++) {
|
|
99
|
+
for (let x = startX; x <= endX; x++) {
|
|
100
|
+
const v = sheet.getSerializedValue({ point: { y, x } });
|
|
101
|
+
if (matcher(v)) {
|
|
102
|
+
matchingCells.push(`${x2c(x)}${y2r(y)}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const matchingCellIndex = matchingCells.length === store.matchingCells.length ? store.matchingCellIndex : 0;
|
|
107
|
+
if (matchingCells.length > 0) {
|
|
108
|
+
const address = matchingCells[matchingCellIndex];
|
|
109
|
+
choosing = a2p(address);
|
|
110
|
+
}
|
|
111
|
+
return { matchingCells, searchQuery, matchingCellIndex, choosing };
|
|
112
|
+
};
|
|
113
|
+
const isXSheetFocused = (store) => {
|
|
114
|
+
const { sheetId, sheetReactive: sheetRef } = store;
|
|
115
|
+
const sheet = sheetRef.current;
|
|
116
|
+
if (!sheet) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
if (sheetId === sheet.registry.editingSheetId) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
return !!sheet.registry.editingAddress;
|
|
123
|
+
};
|
|
124
|
+
const resetZone = { startY: -1, startX: -1, endY: -1, endX: -1 };
|
|
125
|
+
const actions = {};
|
|
126
|
+
const reducer = (store, action) => {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
const act = actions[action.type];
|
|
129
|
+
if (act == null) {
|
|
130
|
+
return store;
|
|
131
|
+
}
|
|
132
|
+
const registry = (_a = store.sheetReactive.current) == null ? void 0 : _a.registry;
|
|
133
|
+
if ((_b = registry == null ? void 0 : registry._strictModeCache) == null ? void 0 : _b.has(action)) {
|
|
134
|
+
const cached = registry._strictModeCache.get(action);
|
|
135
|
+
registry._strictModeCache.delete(action);
|
|
136
|
+
return cached;
|
|
137
|
+
}
|
|
138
|
+
const { callback, ...newStore } = act.reduce(store, action.value);
|
|
139
|
+
callback == null ? void 0 : callback(newStore);
|
|
140
|
+
const result = { ...store, ...newStore };
|
|
141
|
+
if (registry) {
|
|
142
|
+
if (!registry._strictModeCache) {
|
|
143
|
+
registry._strictModeCache = /* @__PURE__ */ new Map();
|
|
144
|
+
}
|
|
145
|
+
registry._strictModeCache.set(action, result);
|
|
146
|
+
queueMicrotask(() => {
|
|
147
|
+
var _a2;
|
|
148
|
+
(_a2 = registry._strictModeCache) == null ? void 0 : _a2.delete(action);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
};
|
|
153
|
+
const _CoreAction = class _CoreAction {
|
|
154
|
+
constructor() {
|
|
155
|
+
this.actionId = 1;
|
|
156
|
+
}
|
|
157
|
+
reduce(store, payload) {
|
|
158
|
+
return store;
|
|
159
|
+
}
|
|
160
|
+
call(payload) {
|
|
161
|
+
return {
|
|
162
|
+
type: this.actionId,
|
|
163
|
+
value: payload
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
bind() {
|
|
167
|
+
this.actionId = _CoreAction.head++;
|
|
168
|
+
actions[this.actionId] = this;
|
|
169
|
+
return this.call.bind(this);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
_CoreAction.head = 1;
|
|
173
|
+
let CoreAction = _CoreAction;
|
|
174
|
+
class SetSearchQueryAction extends CoreAction {
|
|
175
|
+
reduce(store, payload) {
|
|
176
|
+
const searchQuery = payload;
|
|
177
|
+
const { sheetReactive: sheetRef } = store;
|
|
178
|
+
if (sheetRef.current == null) {
|
|
179
|
+
return store;
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
...store,
|
|
183
|
+
...initSearchStatement(sheetRef.current, { ...store, searchQuery }),
|
|
184
|
+
searchQuery
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const setSearchQuery = new SetSearchQueryAction().bind();
|
|
189
|
+
class SetSearchCaseSensitiveAction extends CoreAction {
|
|
190
|
+
reduce(store, payload) {
|
|
191
|
+
const searchCaseSensitive = payload;
|
|
192
|
+
const { sheetReactive: sheetRef } = store;
|
|
193
|
+
if (sheetRef.current == null) {
|
|
194
|
+
return store;
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
...store,
|
|
198
|
+
...initSearchStatement(sheetRef.current, { ...store, searchCaseSensitive }),
|
|
199
|
+
searchCaseSensitive
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const setSearchCaseSensitive = new SetSearchCaseSensitiveAction().bind();
|
|
204
|
+
class SetSearchRegexAction extends CoreAction {
|
|
205
|
+
reduce(store, payload) {
|
|
206
|
+
const searchRegex = payload;
|
|
207
|
+
const { sheetReactive: sheetRef } = store;
|
|
208
|
+
if (sheetRef.current == null) {
|
|
209
|
+
return store;
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
...store,
|
|
213
|
+
...initSearchStatement(sheetRef.current, { ...store, searchRegex }),
|
|
214
|
+
searchRegex
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const setSearchRegex = new SetSearchRegexAction().bind();
|
|
219
|
+
class SetSearchRangeAction extends CoreAction {
|
|
220
|
+
reduce(store, payload) {
|
|
221
|
+
const searchRange = payload;
|
|
222
|
+
const { sheetReactive: sheetRef } = store;
|
|
223
|
+
if (sheetRef.current == null) {
|
|
224
|
+
return store;
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
...store,
|
|
228
|
+
...initSearchStatement(sheetRef.current, { ...store, searchRange }),
|
|
229
|
+
searchRange
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const setSearchRange = new SetSearchRangeAction().bind();
|
|
234
|
+
class SetEditingAddressAction extends CoreAction {
|
|
235
|
+
reduce(store, payload) {
|
|
236
|
+
return {
|
|
237
|
+
...store,
|
|
238
|
+
editingAddress: payload
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
const setEditingAddress = new SetEditingAddressAction().bind();
|
|
243
|
+
class SetAutofillDraggingToAction extends CoreAction {
|
|
244
|
+
reduce(store, payload) {
|
|
245
|
+
return {
|
|
246
|
+
...store,
|
|
247
|
+
autofillDraggingTo: payload
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const setAutofillDraggingTo = new SetAutofillDraggingToAction().bind();
|
|
252
|
+
class SubmitAutofillAction extends CoreAction {
|
|
253
|
+
reduce(store, payload) {
|
|
254
|
+
const autofill = new Autofill(store, payload);
|
|
255
|
+
const sheet = autofill.applied;
|
|
256
|
+
const selectingZone = areaToZone(autofill.wholeArea);
|
|
257
|
+
return {
|
|
258
|
+
...store,
|
|
259
|
+
sheetReactive: { current: sheet },
|
|
260
|
+
...initSearchStatement(sheet, store),
|
|
261
|
+
...restrictPoints(store, sheet),
|
|
262
|
+
selectingZone,
|
|
263
|
+
leftHeaderSelecting: false,
|
|
264
|
+
topHeaderSelecting: false,
|
|
265
|
+
autofillDraggingTo: null
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
const submitAutofill = new SubmitAutofillAction().bind();
|
|
270
|
+
class SetContextMenuPositionAction extends CoreAction {
|
|
271
|
+
reduce(store, payload) {
|
|
272
|
+
return {
|
|
273
|
+
...store,
|
|
274
|
+
contextMenuPosition: payload
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const setContextMenuPosition = new SetContextMenuPositionAction().bind();
|
|
279
|
+
class SetResizingPositionYAction extends CoreAction {
|
|
280
|
+
reduce(store, payload) {
|
|
281
|
+
return {
|
|
282
|
+
...store,
|
|
283
|
+
resizingPositionY: payload
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
const setResizingPositionY = new SetResizingPositionYAction().bind();
|
|
288
|
+
class SetResizingPositionXAction extends CoreAction {
|
|
289
|
+
reduce(store, payload) {
|
|
290
|
+
return {
|
|
291
|
+
...store,
|
|
292
|
+
resizingPositionX: payload
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
const setResizingPositionX = new SetResizingPositionXAction().bind();
|
|
297
|
+
class SetEnteringAction extends CoreAction {
|
|
298
|
+
reduce(store, payload) {
|
|
299
|
+
return {
|
|
300
|
+
...store,
|
|
301
|
+
entering: payload
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
const setEntering = new SetEnteringAction().bind();
|
|
306
|
+
class UpdateSheetAction extends CoreAction {
|
|
307
|
+
reduce(store, payload) {
|
|
308
|
+
return {
|
|
309
|
+
...store,
|
|
310
|
+
sheetReactive: { current: payload },
|
|
311
|
+
...initSearchStatement(payload, store),
|
|
312
|
+
...restrictPoints(store, payload)
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
const updateSheet = new UpdateSheetAction().bind();
|
|
317
|
+
class SetEditorRectAction extends CoreAction {
|
|
318
|
+
reduce(store, payload) {
|
|
319
|
+
return {
|
|
320
|
+
...store,
|
|
321
|
+
editorRect: payload
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const setEditorRect = new SetEditorRectAction().bind();
|
|
326
|
+
class SetDragging extends CoreAction {
|
|
327
|
+
reduce(store, payload) {
|
|
328
|
+
return {
|
|
329
|
+
...store,
|
|
330
|
+
dragging: payload
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
const setDragging = new SetDragging().bind();
|
|
335
|
+
class BlurAction extends CoreAction {
|
|
336
|
+
reduce(store, payload) {
|
|
337
|
+
return {
|
|
338
|
+
...store,
|
|
339
|
+
editingAddress: ""
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
const blur = new BlurAction().bind();
|
|
344
|
+
class CopyAction extends CoreAction {
|
|
345
|
+
reduce(store, payload) {
|
|
346
|
+
const { sheetReactive: sheetRef } = store;
|
|
347
|
+
const sheet = sheetRef.current;
|
|
348
|
+
if (!sheet) {
|
|
349
|
+
return store;
|
|
350
|
+
}
|
|
351
|
+
return {
|
|
352
|
+
...store,
|
|
353
|
+
callback: ({ sheetReactive: sheetRef2 }) => {
|
|
354
|
+
sheet.registry.transmit({
|
|
355
|
+
copyingSheetId: sheet.id,
|
|
356
|
+
copyingZone: payload,
|
|
357
|
+
cutting: false
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
const copy = new CopyAction().bind();
|
|
364
|
+
class CutAction extends CoreAction {
|
|
365
|
+
reduce(store, payload) {
|
|
366
|
+
const { sheetReactive: sheetRef } = store;
|
|
367
|
+
const sheet = sheetRef.current;
|
|
368
|
+
if (!sheet) {
|
|
369
|
+
return store;
|
|
370
|
+
}
|
|
371
|
+
return {
|
|
372
|
+
...store,
|
|
373
|
+
callback: ({ sheetReactive: sheetRef2 }) => {
|
|
374
|
+
sheet.registry.transmit({
|
|
375
|
+
copyingSheetId: sheet.id,
|
|
376
|
+
copyingZone: payload,
|
|
377
|
+
cutting: true
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
const cut = new CutAction().bind();
|
|
384
|
+
class PasteAction extends CoreAction {
|
|
385
|
+
reduce(store, payload) {
|
|
386
|
+
const { choosing, selectingZone, sheetReactive: dstSheetRef } = store;
|
|
387
|
+
const dstSheet = dstSheetRef.current;
|
|
388
|
+
if (!dstSheet) {
|
|
389
|
+
return store;
|
|
390
|
+
}
|
|
391
|
+
const { registry } = dstSheet;
|
|
392
|
+
const { copyingSheetId, copyingZone, cutting } = registry;
|
|
393
|
+
const srcSheet = dstSheet.getSheetBySheetId(copyingSheetId);
|
|
394
|
+
let selectingArea = zoneToArea(selectingZone);
|
|
395
|
+
const copyingArea = zoneToArea(copyingZone);
|
|
396
|
+
const { matrix, onlyValue } = payload;
|
|
397
|
+
if (cutting) {
|
|
398
|
+
if (!srcSheet) {
|
|
399
|
+
return store;
|
|
400
|
+
}
|
|
401
|
+
const src = copyingArea;
|
|
402
|
+
const { rows: dy, cols: dx } = areaDiff(copyingArea);
|
|
403
|
+
const dst = selectingArea.top !== -1 ? {
|
|
404
|
+
top: selectingArea.top,
|
|
405
|
+
left: selectingArea.left,
|
|
406
|
+
bottom: selectingArea.top + dy,
|
|
407
|
+
right: selectingArea.left + dx
|
|
408
|
+
} : {
|
|
409
|
+
top: choosing.y,
|
|
410
|
+
left: choosing.x,
|
|
411
|
+
bottom: choosing.y + dy,
|
|
412
|
+
right: choosing.x + dx
|
|
413
|
+
};
|
|
414
|
+
const nextSelectingZone2 = restrictZone(areaToZone(dst));
|
|
415
|
+
const newSheet2 = dstSheet.move({
|
|
416
|
+
srcSheet,
|
|
417
|
+
src,
|
|
418
|
+
dst,
|
|
419
|
+
operator: "USER",
|
|
420
|
+
undoReflection: compactReflection({
|
|
421
|
+
sheetId: srcSheet.id,
|
|
422
|
+
selectingZone: nextSelectingZone2,
|
|
423
|
+
choosing,
|
|
424
|
+
transmit: { copyingSheetId: srcSheet.id, copyingZone, cutting: true }
|
|
425
|
+
}),
|
|
426
|
+
redoReflection: compactReflection({
|
|
427
|
+
sheetId: srcSheet.id,
|
|
428
|
+
choosing,
|
|
429
|
+
transmit: { copyingSheetId: srcSheet.id, copyingZone: resetZone }
|
|
430
|
+
})
|
|
431
|
+
});
|
|
432
|
+
return {
|
|
433
|
+
...store,
|
|
434
|
+
...initSearchStatement(newSheet2, store),
|
|
435
|
+
sheetReactive: { current: newSheet2 },
|
|
436
|
+
selectingZone: nextSelectingZone2,
|
|
437
|
+
inputting: newSheet2.getSerializedValue({ point: choosing, resolution: "RAW" }),
|
|
438
|
+
callback: ({ sheetReactive: sheetRef }) => {
|
|
439
|
+
registry.transmit({
|
|
440
|
+
cutting: false,
|
|
441
|
+
copyingZone: resetZone
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
let newSheet;
|
|
447
|
+
let { y, x } = choosing;
|
|
448
|
+
if (copyingArea.top === -1) {
|
|
449
|
+
const { rows: height, cols: width } = matrixShape({ matrix, base: -1 });
|
|
450
|
+
selectingArea = {
|
|
451
|
+
top: y,
|
|
452
|
+
left: x,
|
|
453
|
+
bottom: y + height,
|
|
454
|
+
right: x + width
|
|
455
|
+
};
|
|
456
|
+
const nextSelectingZone2 = restrictZone(areaToZone(selectingArea));
|
|
457
|
+
newSheet = dstSheet.writeRawCellMatrix({
|
|
458
|
+
point: { y, x },
|
|
459
|
+
matrix,
|
|
460
|
+
onlyValue,
|
|
461
|
+
undoReflection: compactReflection({
|
|
462
|
+
sheetId: dstSheet.id,
|
|
463
|
+
selectingZone: nextSelectingZone2,
|
|
464
|
+
choosing
|
|
465
|
+
}),
|
|
466
|
+
redoReflection: compactReflection({
|
|
467
|
+
sheetId: dstSheet.id,
|
|
468
|
+
selectingZone: nextSelectingZone2,
|
|
469
|
+
choosing
|
|
470
|
+
})
|
|
471
|
+
});
|
|
472
|
+
} else {
|
|
473
|
+
if (srcSheet == null) {
|
|
474
|
+
return store;
|
|
475
|
+
}
|
|
476
|
+
let { rows: dy, cols: dx } = areaDiff(copyingArea);
|
|
477
|
+
if (selectingArea.top !== -1) {
|
|
478
|
+
y = selectingArea.top;
|
|
479
|
+
x = selectingArea.left;
|
|
480
|
+
const superposed = superposeArea(selectingArea, copyingArea);
|
|
481
|
+
dy = superposed.rows;
|
|
482
|
+
dx = superposed.cols;
|
|
483
|
+
}
|
|
484
|
+
selectingArea = { top: y, left: x, bottom: y + dy, right: x + dx };
|
|
485
|
+
newSheet = dstSheet.copy({
|
|
486
|
+
srcSheet,
|
|
487
|
+
src: copyingArea,
|
|
488
|
+
dst: selectingArea,
|
|
489
|
+
onlyValue,
|
|
490
|
+
operator: "USER",
|
|
491
|
+
undoReflection: compactReflection({
|
|
492
|
+
sheetId: srcSheet.id,
|
|
493
|
+
transmit: { copyingZone },
|
|
494
|
+
choosing,
|
|
495
|
+
selectingZone
|
|
496
|
+
}),
|
|
497
|
+
redoReflection: compactReflection({
|
|
498
|
+
sheetId: srcSheet.id,
|
|
499
|
+
transmit: { copyingSheetId: srcSheet.id, copyingZone: resetZone },
|
|
500
|
+
choosing,
|
|
501
|
+
selectingZone: areaToZone(selectingArea)
|
|
502
|
+
})
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
const nextSelectingZone = restrictZone(areaToZone(selectingArea));
|
|
506
|
+
nextSelectingZone.endX = Math.min(nextSelectingZone.endX, newSheet.numCols);
|
|
507
|
+
nextSelectingZone.endY = Math.min(nextSelectingZone.endY, newSheet.numRows);
|
|
508
|
+
return {
|
|
509
|
+
...store,
|
|
510
|
+
sheetReactive: { current: newSheet },
|
|
511
|
+
selectingZone: nextSelectingZone,
|
|
512
|
+
inputting: newSheet.getSerializedValue({ point: choosing, resolution: "RAW" }),
|
|
513
|
+
...initSearchStatement(newSheet, store),
|
|
514
|
+
callback: ({ sheetReactive: sheetRef }) => {
|
|
515
|
+
registry.transmit({
|
|
516
|
+
copyingZone: resetZone
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
const paste = new PasteAction().bind();
|
|
523
|
+
class EscapeAction extends CoreAction {
|
|
524
|
+
reduce(store, payload) {
|
|
525
|
+
const { sheetReactive: sheetRef } = store;
|
|
526
|
+
return {
|
|
527
|
+
...store,
|
|
528
|
+
editingAddress: "",
|
|
529
|
+
leftHeaderSelecting: false,
|
|
530
|
+
topHeaderSelecting: false,
|
|
531
|
+
callback: ({ sheetReactive: sheetRef2 }) => {
|
|
532
|
+
sheetRef2.current.registry.transmit({
|
|
533
|
+
copyingZone: resetZone,
|
|
534
|
+
cutting: false
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
const escape = new EscapeAction().bind();
|
|
541
|
+
class ChooseAction extends CoreAction {
|
|
542
|
+
reduce(store, payload) {
|
|
543
|
+
return {
|
|
544
|
+
...store,
|
|
545
|
+
choosing: payload,
|
|
546
|
+
entering: true
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
const choose = new ChooseAction().bind();
|
|
551
|
+
class SelectAction extends CoreAction {
|
|
552
|
+
reduce(store, payload) {
|
|
553
|
+
return {
|
|
554
|
+
...store,
|
|
555
|
+
selectingZone: payload,
|
|
556
|
+
leftHeaderSelecting: false,
|
|
557
|
+
topHeaderSelecting: false
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
const select = new SelectAction().bind();
|
|
562
|
+
class SelectRowsAction extends CoreAction {
|
|
563
|
+
reduce(store, payload) {
|
|
564
|
+
const { range, numCols } = payload;
|
|
565
|
+
const { start, end } = range;
|
|
566
|
+
const sheet = store.sheetReactive.current;
|
|
567
|
+
const selectingZone = {
|
|
568
|
+
startY: start,
|
|
569
|
+
startX: 1,
|
|
570
|
+
endY: end,
|
|
571
|
+
endX: numCols
|
|
572
|
+
};
|
|
573
|
+
let choosingY = start;
|
|
574
|
+
if (sheet) {
|
|
575
|
+
for (let y = start; y <= end; y++) {
|
|
576
|
+
if (!sheet.isRowFiltered(y)) {
|
|
577
|
+
choosingY = y;
|
|
578
|
+
break;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return {
|
|
583
|
+
...store,
|
|
584
|
+
selectingZone,
|
|
585
|
+
choosing: { y: choosingY, x: 1 },
|
|
586
|
+
leftHeaderSelecting: true,
|
|
587
|
+
topHeaderSelecting: false
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
const selectRows = new SelectRowsAction().bind();
|
|
592
|
+
class SelectColsAction extends CoreAction {
|
|
593
|
+
reduce(store, payload) {
|
|
594
|
+
const { range, numRows } = payload;
|
|
595
|
+
const { start, end } = range;
|
|
596
|
+
const sheet = store.sheetReactive.current;
|
|
597
|
+
const selectingZone = {
|
|
598
|
+
startY: 1,
|
|
599
|
+
startX: start,
|
|
600
|
+
endY: numRows,
|
|
601
|
+
endX: end
|
|
602
|
+
};
|
|
603
|
+
let choosingY = 1;
|
|
604
|
+
if (sheet) {
|
|
605
|
+
for (let y = 1; y <= numRows; y++) {
|
|
606
|
+
if (!sheet.isRowFiltered(y)) {
|
|
607
|
+
choosingY = y;
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
return {
|
|
613
|
+
...store,
|
|
614
|
+
selectingZone,
|
|
615
|
+
choosing: { y: choosingY, x: start },
|
|
616
|
+
leftHeaderSelecting: false,
|
|
617
|
+
topHeaderSelecting: true
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
const selectCols = new SelectColsAction().bind();
|
|
622
|
+
class DragAction extends CoreAction {
|
|
623
|
+
reduce(store, payload) {
|
|
624
|
+
const { startY, startX } = store.selectingZone;
|
|
625
|
+
const selectingZone = {
|
|
626
|
+
startY,
|
|
627
|
+
startX,
|
|
628
|
+
endY: payload.y,
|
|
629
|
+
endX: payload.x
|
|
630
|
+
};
|
|
631
|
+
if (startY === payload.y && startX === payload.x) {
|
|
632
|
+
selectingZone.endY = -1;
|
|
633
|
+
selectingZone.endX = -1;
|
|
634
|
+
}
|
|
635
|
+
return { ...store, selectingZone };
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
const drag = new DragAction().bind();
|
|
639
|
+
class SearchAction extends CoreAction {
|
|
640
|
+
reduce(store, payload) {
|
|
641
|
+
const { matchingCells } = store;
|
|
642
|
+
let { matchingCellIndex, choosing } = store;
|
|
643
|
+
matchingCellIndex += payload;
|
|
644
|
+
if (matchingCellIndex >= matchingCells.length) {
|
|
645
|
+
matchingCellIndex = 0;
|
|
646
|
+
} else if (matchingCellIndex < 0) {
|
|
647
|
+
matchingCellIndex = matchingCells.length - 1;
|
|
648
|
+
}
|
|
649
|
+
if (matchingCells.length > 0) {
|
|
650
|
+
const address = matchingCells[matchingCellIndex];
|
|
651
|
+
choosing = a2p(address);
|
|
652
|
+
}
|
|
653
|
+
return { ...store, matchingCells, matchingCellIndex, choosing };
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
const search = new SearchAction().bind();
|
|
657
|
+
class WriteAction extends CoreAction {
|
|
658
|
+
reduce(store, payload) {
|
|
659
|
+
let { value, point } = payload;
|
|
660
|
+
const { choosing, selectingZone, sheetReactive: sheetRef } = store;
|
|
661
|
+
if (point == null) {
|
|
662
|
+
point = choosing;
|
|
663
|
+
}
|
|
664
|
+
const sheet = sheetRef.current;
|
|
665
|
+
if (!sheet) {
|
|
666
|
+
return store;
|
|
667
|
+
}
|
|
668
|
+
const newSheet = sheet.write({
|
|
669
|
+
point,
|
|
670
|
+
value,
|
|
671
|
+
operator: "USER",
|
|
672
|
+
undoReflection: compactReflection({
|
|
673
|
+
sheetId: sheet.id,
|
|
674
|
+
selectingZone,
|
|
675
|
+
choosing: point
|
|
676
|
+
}),
|
|
677
|
+
redoReflection: compactReflection({
|
|
678
|
+
sheetId: sheet.id,
|
|
679
|
+
selectingZone,
|
|
680
|
+
choosing: point
|
|
681
|
+
})
|
|
682
|
+
});
|
|
683
|
+
return {
|
|
684
|
+
...store,
|
|
685
|
+
...initSearchStatement(newSheet, store),
|
|
686
|
+
sheetReactive: { current: newSheet },
|
|
687
|
+
callback: ({ sheetReactive: sheetRef2 }) => {
|
|
688
|
+
sheet.registry.transmit({
|
|
689
|
+
copyingZone: resetZone
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
const write = new WriteAction().bind();
|
|
696
|
+
class ClearAction extends CoreAction {
|
|
697
|
+
reduce(store, payload) {
|
|
698
|
+
var _a;
|
|
699
|
+
const { choosing, selectingZone, sheetReactive: sheetRef } = store;
|
|
700
|
+
const sheet = sheetRef.current;
|
|
701
|
+
if (!sheet) {
|
|
702
|
+
return store;
|
|
703
|
+
}
|
|
704
|
+
let selectingArea = zoneToArea(selectingZone);
|
|
705
|
+
if (selectingArea.top === -1) {
|
|
706
|
+
const { y, x } = choosing;
|
|
707
|
+
selectingArea = { top: y, left: x, bottom: y, right: x };
|
|
708
|
+
}
|
|
709
|
+
const { top, left, bottom, right } = selectingArea;
|
|
710
|
+
const diff = {};
|
|
711
|
+
let diffCount = 0;
|
|
712
|
+
for (let y = top; y <= bottom; y++) {
|
|
713
|
+
if (sheet.isRowFiltered(y)) {
|
|
714
|
+
continue;
|
|
715
|
+
}
|
|
716
|
+
for (let x = left; x <= right; x++) {
|
|
717
|
+
const cell = sheet.getCell({ y, x }, { resolution: "SYSTEM" });
|
|
718
|
+
const address = p2a({ y, x });
|
|
719
|
+
if (prevention.hasOperation(cell == null ? void 0 : cell.prevention, prevention.Write)) {
|
|
720
|
+
continue;
|
|
721
|
+
}
|
|
722
|
+
if (((_a = sheet.getSystem({ y, x })) == null ? void 0 : _a.spilledFrom) != null) {
|
|
723
|
+
continue;
|
|
724
|
+
}
|
|
725
|
+
if ((cell == null ? void 0 : cell.value) != null) {
|
|
726
|
+
diff[address] = { value: void 0 };
|
|
727
|
+
diffCount++;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
if (diffCount === 0) {
|
|
732
|
+
return store;
|
|
733
|
+
}
|
|
734
|
+
sheet.update({
|
|
735
|
+
diff,
|
|
736
|
+
partial: true,
|
|
737
|
+
operator: "USER",
|
|
738
|
+
undoReflection: compactReflection({
|
|
739
|
+
sheetId: sheet.id,
|
|
740
|
+
selectingZone,
|
|
741
|
+
choosing
|
|
742
|
+
}),
|
|
743
|
+
redoReflection: compactReflection({
|
|
744
|
+
sheetId: sheet.id,
|
|
745
|
+
selectingZone,
|
|
746
|
+
choosing
|
|
747
|
+
})
|
|
748
|
+
});
|
|
749
|
+
return {
|
|
750
|
+
...store,
|
|
751
|
+
...initSearchStatement(sheet, store),
|
|
752
|
+
sheetReactive: { current: sheet }
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
const clear = new ClearAction().bind();
|
|
757
|
+
class UndoAction extends CoreAction {
|
|
758
|
+
reduce(store, payload) {
|
|
759
|
+
const { sheetReactive: sheetRef } = store;
|
|
760
|
+
const sheet = sheetRef.current;
|
|
761
|
+
if (!sheet) {
|
|
762
|
+
return store;
|
|
763
|
+
}
|
|
764
|
+
const { history, callback } = sheet.undo();
|
|
765
|
+
if (history == null) {
|
|
766
|
+
return store;
|
|
767
|
+
}
|
|
768
|
+
if (history.dstSheetId !== sheet.id) {
|
|
769
|
+
const { dispatch, store: dstStore } = sheet.registry.contextsBySheetId[history.dstSheetId];
|
|
770
|
+
dispatch(
|
|
771
|
+
setStore({
|
|
772
|
+
...dstStore,
|
|
773
|
+
...history.undoReflection,
|
|
774
|
+
sheetReactive: { current: dstStore.sheetReactive.current }
|
|
775
|
+
})
|
|
776
|
+
);
|
|
777
|
+
flashSheet(dstStore.flashRef.current);
|
|
778
|
+
if (history.srcSheetId === sheet.id) {
|
|
779
|
+
return flashWithCallback(store, sheet, callback);
|
|
780
|
+
}
|
|
781
|
+
return store;
|
|
782
|
+
}
|
|
783
|
+
return {
|
|
784
|
+
...store,
|
|
785
|
+
...restrictPoints(store, sheet),
|
|
786
|
+
...history.undoReflection,
|
|
787
|
+
...initSearchStatement(sheet, store),
|
|
788
|
+
sheetReactive: { current: sheet },
|
|
789
|
+
callback: (s) => {
|
|
790
|
+
callback == null ? void 0 : callback(s);
|
|
791
|
+
flashSheet(store.flashRef.current);
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
const undo = new UndoAction().bind();
|
|
797
|
+
class RedoAction extends CoreAction {
|
|
798
|
+
reduce(store, payload) {
|
|
799
|
+
const { sheetReactive: sheetRef } = store;
|
|
800
|
+
const sheet = sheetRef.current;
|
|
801
|
+
if (sheet == null) {
|
|
802
|
+
return store;
|
|
803
|
+
}
|
|
804
|
+
const { history, newSheet, callback } = sheet.redo();
|
|
805
|
+
if (history == null) {
|
|
806
|
+
return store;
|
|
807
|
+
}
|
|
808
|
+
if (history.dstSheetId !== sheet.id) {
|
|
809
|
+
const { dispatch, store: dstStore } = sheet.registry.contextsBySheetId[history.dstSheetId];
|
|
810
|
+
dispatch(
|
|
811
|
+
setStore({
|
|
812
|
+
...dstStore,
|
|
813
|
+
...history.redoReflection,
|
|
814
|
+
sheetReactive: { current: dstStore.sheetReactive.current }
|
|
815
|
+
})
|
|
816
|
+
);
|
|
817
|
+
flashSheet(dstStore.flashRef.current);
|
|
818
|
+
if (history.srcSheetId === sheet.id) {
|
|
819
|
+
return flashWithCallback(store, sheet, callback);
|
|
820
|
+
}
|
|
821
|
+
return store;
|
|
822
|
+
}
|
|
823
|
+
return {
|
|
824
|
+
...store,
|
|
825
|
+
...restrictPoints(store, sheet),
|
|
826
|
+
...history.redoReflection,
|
|
827
|
+
...initSearchStatement(sheet, store),
|
|
828
|
+
sheetReactive: { current: sheet },
|
|
829
|
+
callback: (s) => {
|
|
830
|
+
callback == null ? void 0 : callback(s);
|
|
831
|
+
flashSheet(store.flashRef.current);
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
const redo = new RedoAction().bind();
|
|
837
|
+
class ArrowAction extends CoreAction {
|
|
838
|
+
reduce(store, payload) {
|
|
839
|
+
var _a, _b, _c, _d;
|
|
840
|
+
const { shiftKey, deltaY, deltaX, numRows, numCols } = payload;
|
|
841
|
+
const { choosing, sheetReactive: sheetRef, tabularRef } = store;
|
|
842
|
+
const sheet = sheetRef.current;
|
|
843
|
+
if (sheet == null) {
|
|
844
|
+
return store;
|
|
845
|
+
}
|
|
846
|
+
let { selectingZone } = store;
|
|
847
|
+
const { y, x } = choosing;
|
|
848
|
+
if (shiftKey) {
|
|
849
|
+
const [dragEndY, dragEndX] = [
|
|
850
|
+
selectingZone.endY === -1 ? y : selectingZone.endY,
|
|
851
|
+
selectingZone.endX === -1 ? x : selectingZone.endX
|
|
852
|
+
];
|
|
853
|
+
const [nextY2, nextX2] = [dragEndY + deltaY, dragEndX + deltaX];
|
|
854
|
+
if (nextY2 < 1 || numRows < nextY2 || nextX2 < 1 || numCols < nextX2) {
|
|
855
|
+
return store;
|
|
856
|
+
}
|
|
857
|
+
selectingZone = y === nextY2 && x === nextX2 ? { startY: -1, startX: -1, endY: -1, endX: -1 } : { startY: y, startX: x, endY: nextY2, endX: nextX2 };
|
|
858
|
+
return {
|
|
859
|
+
...store,
|
|
860
|
+
selectingZone
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
const [nextY, nextX] = [y + deltaY, x + deltaX];
|
|
864
|
+
if (nextY < 1 || numRows < nextY || nextX < 1 || numCols < nextX) {
|
|
865
|
+
return store;
|
|
866
|
+
}
|
|
867
|
+
let resolvedY = nextY;
|
|
868
|
+
if (sheet.isRowFiltered(resolvedY)) {
|
|
869
|
+
const dir = deltaY >= 0 ? 1 : -1;
|
|
870
|
+
while (resolvedY >= 1 && resolvedY <= numRows && sheet.isRowFiltered(resolvedY)) {
|
|
871
|
+
resolvedY += dir;
|
|
872
|
+
}
|
|
873
|
+
if (resolvedY < 1 || resolvedY > numRows) {
|
|
874
|
+
return store;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
let { y: editorTop, x: editorLeft, height, width } = store.editorRect;
|
|
878
|
+
if (deltaY > 0) {
|
|
879
|
+
for (let i = y; i < resolvedY; i++) {
|
|
880
|
+
editorTop += ((_a = sheet.getCell({ y: i, x: 0 }, { resolution: "SYSTEM" })) == null ? void 0 : _a.height) || DEFAULT_HEIGHT;
|
|
881
|
+
}
|
|
882
|
+
} else if (deltaY < 0) {
|
|
883
|
+
for (let i = y - 1; i >= resolvedY; i--) {
|
|
884
|
+
editorTop -= ((_b = sheet.getCell({ y: i, x: 0 }, { resolution: "SYSTEM" })) == null ? void 0 : _b.height) || DEFAULT_HEIGHT;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
if (deltaX > 0) {
|
|
888
|
+
for (let i = x; i < nextX; i++) {
|
|
889
|
+
editorLeft += ((_c = sheet.getCell({ y: 0, x: i }, { resolution: "SYSTEM" })) == null ? void 0 : _c.width) || DEFAULT_WIDTH;
|
|
890
|
+
}
|
|
891
|
+
} else if (deltaX < 0) {
|
|
892
|
+
for (let i = x - 1; i >= nextX; i--) {
|
|
893
|
+
editorLeft -= ((_d = sheet.getCell({ y: 0, x: i }, { resolution: "SYSTEM" })) == null ? void 0 : _d.width) || DEFAULT_WIDTH;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
const cell = sheet.getCell({ y: resolvedY, x: nextX }, { resolution: "SYSTEM" });
|
|
897
|
+
height = (cell == null ? void 0 : cell.height) || DEFAULT_HEIGHT;
|
|
898
|
+
width = (cell == null ? void 0 : cell.width) || DEFAULT_WIDTH;
|
|
899
|
+
smartScroll(sheet, tabularRef.current, { y: resolvedY, x: nextX });
|
|
900
|
+
return {
|
|
901
|
+
...store,
|
|
902
|
+
selectingZone: { startY: -1, startX: -1, endY: -1, endX: -1 },
|
|
903
|
+
choosing: { y: resolvedY, x: nextX },
|
|
904
|
+
editorRect: { y: editorTop, x: editorLeft, height, width }
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
const arrow = new ArrowAction().bind();
|
|
909
|
+
class WalkAction extends CoreAction {
|
|
910
|
+
reduce(store, payload) {
|
|
911
|
+
var _a, _b, _c, _d;
|
|
912
|
+
const { numRows, numCols } = payload;
|
|
913
|
+
let { deltaY, deltaX } = payload;
|
|
914
|
+
const { choosing, selectingZone, sheetReactive: sheetRef, tabularRef: gridOuterRef } = store;
|
|
915
|
+
const sheet = sheetRef.current;
|
|
916
|
+
if (sheet == null) {
|
|
917
|
+
return store;
|
|
918
|
+
}
|
|
919
|
+
let { y: editorTop, x: editorLeft, height, width } = store.editorRect;
|
|
920
|
+
const { y, x } = choosing;
|
|
921
|
+
const selectingArea = zoneToArea(selectingZone);
|
|
922
|
+
const { top, left, bottom, right } = selectingArea;
|
|
923
|
+
let [nextY, nextX] = [y + deltaY, x + deltaX];
|
|
924
|
+
if (nextY < top && top !== -1) {
|
|
925
|
+
deltaY = bottom - nextY;
|
|
926
|
+
nextY = bottom;
|
|
927
|
+
if (nextX > left) {
|
|
928
|
+
nextX--;
|
|
929
|
+
deltaX--;
|
|
930
|
+
} else {
|
|
931
|
+
deltaX = right - nextX;
|
|
932
|
+
nextX = right;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
if (nextY > bottom && bottom !== -1) {
|
|
936
|
+
deltaY = top - nextY;
|
|
937
|
+
nextY = top;
|
|
938
|
+
if (nextX < right) {
|
|
939
|
+
nextX++;
|
|
940
|
+
deltaX++;
|
|
941
|
+
} else {
|
|
942
|
+
deltaX = left - nextX;
|
|
943
|
+
nextX = left;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
if (nextX < left && left !== -1) {
|
|
947
|
+
deltaX = right - nextX;
|
|
948
|
+
nextX = right;
|
|
949
|
+
if (nextY > top) {
|
|
950
|
+
nextY--;
|
|
951
|
+
deltaY--;
|
|
952
|
+
} else {
|
|
953
|
+
deltaY = bottom - nextY;
|
|
954
|
+
nextY = bottom;
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
if (nextX > right && right !== -1) {
|
|
958
|
+
deltaX = left - nextX;
|
|
959
|
+
nextX = left;
|
|
960
|
+
if (nextY < bottom) {
|
|
961
|
+
nextY++;
|
|
962
|
+
deltaY++;
|
|
963
|
+
} else {
|
|
964
|
+
deltaY = top - nextY;
|
|
965
|
+
nextY = top;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
if (nextY < 1 || numRows < nextY || nextX < 1 || numCols < nextX) {
|
|
969
|
+
return store;
|
|
970
|
+
}
|
|
971
|
+
if (sheet.isRowFiltered(nextY)) {
|
|
972
|
+
const dir = deltaY >= 0 ? 1 : -1;
|
|
973
|
+
const lo = top !== -1 ? top : 1;
|
|
974
|
+
const hi = bottom !== -1 ? bottom : numRows;
|
|
975
|
+
while (nextY >= lo && nextY <= hi && sheet.isRowFiltered(nextY)) {
|
|
976
|
+
nextY += dir;
|
|
977
|
+
}
|
|
978
|
+
if (nextY < lo || nextY > hi || sheet.isRowFiltered(nextY)) {
|
|
979
|
+
return store;
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
if (deltaY > 0) {
|
|
983
|
+
for (let i = y; i < nextY; i++) {
|
|
984
|
+
editorTop += ((_a = sheet.getCell({ y: i, x: 0 }, { resolution: "SYSTEM" })) == null ? void 0 : _a.height) || DEFAULT_HEIGHT;
|
|
985
|
+
}
|
|
986
|
+
} else if (deltaY < 0) {
|
|
987
|
+
for (let i = y - 1; i >= nextY; i--) {
|
|
988
|
+
editorTop -= ((_b = sheet.getCell({ y: i, x: 0 }, { resolution: "SYSTEM" })) == null ? void 0 : _b.height) || DEFAULT_HEIGHT;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
if (deltaX > 0) {
|
|
992
|
+
for (let i = x; i < nextX; i++) {
|
|
993
|
+
editorLeft += ((_c = sheet.getCell({ y: 0, x: i }, { resolution: "SYSTEM" })) == null ? void 0 : _c.width) || DEFAULT_WIDTH;
|
|
994
|
+
}
|
|
995
|
+
} else if (deltaX < 0) {
|
|
996
|
+
for (let i = x - 1; i >= nextX; i--) {
|
|
997
|
+
editorLeft -= ((_d = sheet.getCell({ y: 0, x: i }, { resolution: "SYSTEM" })) == null ? void 0 : _d.width) || DEFAULT_WIDTH;
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
const cell = sheet.getCell({ y: nextY, x: nextX }, { resolution: "SYSTEM" });
|
|
1001
|
+
height = (cell == null ? void 0 : cell.height) || DEFAULT_HEIGHT;
|
|
1002
|
+
width = (cell == null ? void 0 : cell.width) || DEFAULT_WIDTH;
|
|
1003
|
+
smartScroll(sheet, gridOuterRef.current, { y: nextY, x: nextX });
|
|
1004
|
+
return {
|
|
1005
|
+
...store,
|
|
1006
|
+
choosing: { y: nextY, x: nextX },
|
|
1007
|
+
editorRect: { y: editorTop, x: editorLeft, height, width }
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
const walk = new WalkAction().bind();
|
|
1012
|
+
class SetInputtingAction extends CoreAction {
|
|
1013
|
+
reduce(store, payload) {
|
|
1014
|
+
return {
|
|
1015
|
+
...store,
|
|
1016
|
+
inputting: payload
|
|
1017
|
+
};
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
const setInputting = new SetInputtingAction().bind();
|
|
1021
|
+
class InsertRowsAboveAction extends CoreAction {
|
|
1022
|
+
reduce(store, payload) {
|
|
1023
|
+
const { numRows, y, operator } = payload;
|
|
1024
|
+
const { sheetReactive: sheetRef, selectingZone, choosing } = store;
|
|
1025
|
+
const sheet = sheetRef.current;
|
|
1026
|
+
if (sheet == null) {
|
|
1027
|
+
return store;
|
|
1028
|
+
}
|
|
1029
|
+
sheet.insertRows({
|
|
1030
|
+
y,
|
|
1031
|
+
numRows,
|
|
1032
|
+
baseY: y,
|
|
1033
|
+
operator,
|
|
1034
|
+
undoReflection: compactReflection({
|
|
1035
|
+
sheetId: sheet.id,
|
|
1036
|
+
selectingZone,
|
|
1037
|
+
choosing
|
|
1038
|
+
}),
|
|
1039
|
+
redoReflection: compactReflection({
|
|
1040
|
+
sheetId: sheet.id,
|
|
1041
|
+
selectingZone,
|
|
1042
|
+
choosing
|
|
1043
|
+
})
|
|
1044
|
+
});
|
|
1045
|
+
return {
|
|
1046
|
+
...store,
|
|
1047
|
+
sheetReactive: { current: sheet }
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
const insertRowsAbove = new InsertRowsAboveAction().bind();
|
|
1052
|
+
class InsertRowsBelowAction extends CoreAction {
|
|
1053
|
+
reduce(store, payload) {
|
|
1054
|
+
const { numRows, y, operator } = payload;
|
|
1055
|
+
const { sheetReactive: sheetRef, selectingZone, choosing, editorRef } = store;
|
|
1056
|
+
const sheet = sheetRef.current;
|
|
1057
|
+
if (sheet == null) {
|
|
1058
|
+
return store;
|
|
1059
|
+
}
|
|
1060
|
+
const nextSelectingZone = {
|
|
1061
|
+
...selectingZone,
|
|
1062
|
+
startY: selectingZone.startY + numRows,
|
|
1063
|
+
endY: selectingZone.endY + numRows
|
|
1064
|
+
};
|
|
1065
|
+
const nextChoosing = { ...choosing, y: choosing.y + numRows };
|
|
1066
|
+
sheet.insertRows({
|
|
1067
|
+
y: y + 1,
|
|
1068
|
+
numRows,
|
|
1069
|
+
baseY: y,
|
|
1070
|
+
operator,
|
|
1071
|
+
undoReflection: compactReflection({
|
|
1072
|
+
sheetId: sheet.id,
|
|
1073
|
+
selectingZone,
|
|
1074
|
+
choosing
|
|
1075
|
+
}),
|
|
1076
|
+
redoReflection: compactReflection({
|
|
1077
|
+
sheetId: sheet.id,
|
|
1078
|
+
selectingZone: nextSelectingZone,
|
|
1079
|
+
choosing: nextChoosing
|
|
1080
|
+
})
|
|
1081
|
+
});
|
|
1082
|
+
return {
|
|
1083
|
+
...store,
|
|
1084
|
+
selectingZone: nextSelectingZone,
|
|
1085
|
+
choosing: nextChoosing,
|
|
1086
|
+
sheetReactive: { current: sheet }
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
const insertRowsBelow = new InsertRowsBelowAction().bind();
|
|
1091
|
+
class InsertColsLeftAction extends CoreAction {
|
|
1092
|
+
reduce(store, payload) {
|
|
1093
|
+
const { numCols, x, operator } = payload;
|
|
1094
|
+
const { sheetReactive: sheetRef, selectingZone, choosing, editorRef } = store;
|
|
1095
|
+
const sheet = sheetRef.current;
|
|
1096
|
+
if (sheet == null) {
|
|
1097
|
+
return store;
|
|
1098
|
+
}
|
|
1099
|
+
sheet.insertCols({
|
|
1100
|
+
x,
|
|
1101
|
+
numCols,
|
|
1102
|
+
baseX: x,
|
|
1103
|
+
operator,
|
|
1104
|
+
undoReflection: compactReflection({
|
|
1105
|
+
sheetId: sheet.id,
|
|
1106
|
+
selectingZone,
|
|
1107
|
+
choosing
|
|
1108
|
+
}),
|
|
1109
|
+
redoReflection: compactReflection({
|
|
1110
|
+
sheetId: sheet.id,
|
|
1111
|
+
selectingZone,
|
|
1112
|
+
choosing
|
|
1113
|
+
})
|
|
1114
|
+
});
|
|
1115
|
+
return {
|
|
1116
|
+
...store,
|
|
1117
|
+
sheetReactive: { current: sheet }
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
const insertColsLeft = new InsertColsLeftAction().bind();
|
|
1122
|
+
class InsertColsRightAction extends CoreAction {
|
|
1123
|
+
reduce(store, payload) {
|
|
1124
|
+
const { numCols, x, operator } = payload;
|
|
1125
|
+
const { sheetReactive: sheetRef, selectingZone, choosing } = store;
|
|
1126
|
+
const sheet = sheetRef.current;
|
|
1127
|
+
if (sheet == null) {
|
|
1128
|
+
return store;
|
|
1129
|
+
}
|
|
1130
|
+
const nextSelectingZone = {
|
|
1131
|
+
...selectingZone,
|
|
1132
|
+
startX: selectingZone.startX + numCols,
|
|
1133
|
+
endX: selectingZone.endX + numCols
|
|
1134
|
+
};
|
|
1135
|
+
const nextChoosing = { ...choosing, x: choosing.x + numCols };
|
|
1136
|
+
selectingZone.startX += numCols;
|
|
1137
|
+
selectingZone.endX += numCols;
|
|
1138
|
+
sheet.insertCols({
|
|
1139
|
+
x: x + 1,
|
|
1140
|
+
numCols,
|
|
1141
|
+
baseX: x,
|
|
1142
|
+
operator,
|
|
1143
|
+
undoReflection: compactReflection({
|
|
1144
|
+
sheetId: sheet.id,
|
|
1145
|
+
selectingZone,
|
|
1146
|
+
choosing
|
|
1147
|
+
}),
|
|
1148
|
+
redoReflection: compactReflection({
|
|
1149
|
+
sheetId: sheet.id,
|
|
1150
|
+
selectingZone: nextSelectingZone,
|
|
1151
|
+
choosing: nextChoosing
|
|
1152
|
+
})
|
|
1153
|
+
});
|
|
1154
|
+
return {
|
|
1155
|
+
...store,
|
|
1156
|
+
selectingZone: nextSelectingZone,
|
|
1157
|
+
choosing: nextChoosing,
|
|
1158
|
+
sheetReactive: { current: sheet }
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
const insertColsRight = new InsertColsRightAction().bind();
|
|
1163
|
+
class RemoveRowsAction extends CoreAction {
|
|
1164
|
+
reduce(store, payload) {
|
|
1165
|
+
const { numRows, y, operator } = payload;
|
|
1166
|
+
const { sheetReactive: sheetRef, selectingZone, choosing, editorRef } = store;
|
|
1167
|
+
const sheet = sheetRef.current;
|
|
1168
|
+
if (sheet == null) {
|
|
1169
|
+
return store;
|
|
1170
|
+
}
|
|
1171
|
+
sheet.removeRows({
|
|
1172
|
+
y,
|
|
1173
|
+
numRows,
|
|
1174
|
+
operator,
|
|
1175
|
+
undoReflection: compactReflection({
|
|
1176
|
+
sheetId: sheet.id,
|
|
1177
|
+
selectingZone,
|
|
1178
|
+
choosing,
|
|
1179
|
+
sheetHeight: store.sheetHeight
|
|
1180
|
+
}),
|
|
1181
|
+
redoReflection: compactReflection({
|
|
1182
|
+
sheetId: sheet.id,
|
|
1183
|
+
selectingZone,
|
|
1184
|
+
choosing
|
|
1185
|
+
})
|
|
1186
|
+
});
|
|
1187
|
+
return {
|
|
1188
|
+
...store,
|
|
1189
|
+
sheetReactive: { current: sheet }
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
const removeRows = new RemoveRowsAction().bind();
|
|
1194
|
+
class RemoveColsAction extends CoreAction {
|
|
1195
|
+
reduce(store, payload) {
|
|
1196
|
+
const { numCols, x, operator } = payload;
|
|
1197
|
+
const { sheetReactive: sheetRef, selectingZone, choosing, editorRef } = store;
|
|
1198
|
+
const sheet = sheetRef.current;
|
|
1199
|
+
if (sheet == null) {
|
|
1200
|
+
return store;
|
|
1201
|
+
}
|
|
1202
|
+
sheet.removeCols({
|
|
1203
|
+
x,
|
|
1204
|
+
numCols,
|
|
1205
|
+
operator,
|
|
1206
|
+
undoReflection: compactReflection({
|
|
1207
|
+
sheetId: sheet.id,
|
|
1208
|
+
selectingZone,
|
|
1209
|
+
choosing,
|
|
1210
|
+
sheetWidth: store.sheetWidth
|
|
1211
|
+
}),
|
|
1212
|
+
redoReflection: compactReflection({
|
|
1213
|
+
sheetId: sheet.id,
|
|
1214
|
+
selectingZone,
|
|
1215
|
+
choosing
|
|
1216
|
+
})
|
|
1217
|
+
});
|
|
1218
|
+
return {
|
|
1219
|
+
...store,
|
|
1220
|
+
sheetReactive: { current: sheet }
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
const removeCols = new RemoveColsAction().bind();
|
|
1225
|
+
class SortRowsAction extends CoreAction {
|
|
1226
|
+
reduce(store, payload) {
|
|
1227
|
+
const { x, direction } = payload;
|
|
1228
|
+
const { sheetReactive: sheetRef, selectingZone, choosing } = store;
|
|
1229
|
+
const sheet = sheetRef.current;
|
|
1230
|
+
if (sheet == null) {
|
|
1231
|
+
return store;
|
|
1232
|
+
}
|
|
1233
|
+
sheet.sortRows({ x, direction });
|
|
1234
|
+
const reflection = compactReflection({ sheetId: sheet.id, selectingZone, choosing });
|
|
1235
|
+
if (sheet.registry.lastHistory) {
|
|
1236
|
+
sheet.registry.lastHistory.undoReflection = reflection;
|
|
1237
|
+
sheet.registry.lastHistory.redoReflection = reflection;
|
|
1238
|
+
}
|
|
1239
|
+
return {
|
|
1240
|
+
...store,
|
|
1241
|
+
sheetReactive: { current: sheet }
|
|
1242
|
+
};
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
const sortRows = new SortRowsAction().bind();
|
|
1246
|
+
class FilterRowsAction extends CoreAction {
|
|
1247
|
+
reduce(store, payload) {
|
|
1248
|
+
const { x, filter } = payload;
|
|
1249
|
+
const { sheetReactive: sheetRef, selectingZone, choosing } = store;
|
|
1250
|
+
const sheet = sheetRef.current;
|
|
1251
|
+
if (sheet == null) {
|
|
1252
|
+
return store;
|
|
1253
|
+
}
|
|
1254
|
+
sheet.filterRows({ x, filter });
|
|
1255
|
+
const reflection = compactReflection({ sheetId: sheet.id, selectingZone, choosing });
|
|
1256
|
+
if (sheet.registry.lastHistory) {
|
|
1257
|
+
sheet.registry.lastHistory.undoReflection = reflection;
|
|
1258
|
+
sheet.registry.lastHistory.redoReflection = reflection;
|
|
1259
|
+
}
|
|
1260
|
+
let newChoosing = choosing;
|
|
1261
|
+
if (sheet.isRowFiltered(choosing.y)) {
|
|
1262
|
+
for (let y = 1; y <= sheet.numRows; y++) {
|
|
1263
|
+
if (!sheet.isRowFiltered(y)) {
|
|
1264
|
+
newChoosing = { y, x: choosing.x };
|
|
1265
|
+
break;
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
return {
|
|
1270
|
+
...store,
|
|
1271
|
+
choosing: newChoosing,
|
|
1272
|
+
selectingZone: newChoosing !== choosing ? resetZone : selectingZone,
|
|
1273
|
+
sheetReactive: { current: sheet },
|
|
1274
|
+
callback: ({ sheetReactive: sheetRef2 }) => {
|
|
1275
|
+
const t = sheetRef2.current;
|
|
1276
|
+
if (t) {
|
|
1277
|
+
t.registry.transmit({
|
|
1278
|
+
cutting: false,
|
|
1279
|
+
copyingZone: resetZone
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
const filterRows = new FilterRowsAction().bind();
|
|
1287
|
+
class SetColumnMenuAction extends CoreAction {
|
|
1288
|
+
reduce(store, payload) {
|
|
1289
|
+
return {
|
|
1290
|
+
...store,
|
|
1291
|
+
columnMenuState: payload
|
|
1292
|
+
};
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
const setColumnMenu = new SetColumnMenuAction().bind();
|
|
1296
|
+
class SetRowMenuAction extends CoreAction {
|
|
1297
|
+
reduce(store, payload) {
|
|
1298
|
+
return {
|
|
1299
|
+
...store,
|
|
1300
|
+
rowMenuState: payload
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
const setRowMenu = new SetRowMenuAction().bind();
|
|
1305
|
+
class SetEditorHoveringAction extends CoreAction {
|
|
1306
|
+
reduce(store, payload) {
|
|
1307
|
+
return {
|
|
1308
|
+
...store,
|
|
1309
|
+
editorHovering: payload
|
|
1310
|
+
};
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
const setEditorHovering = new SetEditorHoveringAction().bind();
|
|
1314
|
+
class setStoreAction extends CoreAction {
|
|
1315
|
+
reduce(store, payload) {
|
|
1316
|
+
return {
|
|
1317
|
+
...store,
|
|
1318
|
+
...payload
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
const setStore = new setStoreAction().bind();
|
|
1323
|
+
const userActions = {
|
|
1324
|
+
blur,
|
|
1325
|
+
copy,
|
|
1326
|
+
cut,
|
|
1327
|
+
paste,
|
|
1328
|
+
escape,
|
|
1329
|
+
choose,
|
|
1330
|
+
select,
|
|
1331
|
+
selectRows,
|
|
1332
|
+
selectCols,
|
|
1333
|
+
drag,
|
|
1334
|
+
search,
|
|
1335
|
+
write,
|
|
1336
|
+
clear,
|
|
1337
|
+
undo,
|
|
1338
|
+
redo,
|
|
1339
|
+
arrow,
|
|
1340
|
+
walk,
|
|
1341
|
+
insertRowsAbove,
|
|
1342
|
+
insertRowsBelow,
|
|
1343
|
+
insertColsLeft,
|
|
1344
|
+
insertColsRight,
|
|
1345
|
+
removeRows,
|
|
1346
|
+
removeCols,
|
|
1347
|
+
sortRows,
|
|
1348
|
+
filterRows
|
|
1349
|
+
};
|
|
1350
|
+
const useBrowser = () => {
|
|
1351
|
+
const [ok, setOk] = useState(false);
|
|
1352
|
+
useEffect(() => {
|
|
1353
|
+
setOk(true);
|
|
1354
|
+
}, []);
|
|
1355
|
+
if (ok && typeof window !== "undefined") {
|
|
1356
|
+
return { window, document };
|
|
1357
|
+
}
|
|
1358
|
+
return { window: null, document: null };
|
|
1359
|
+
};
|
|
1360
|
+
const useDebounceCallback = (callback, delay = 100) => {
|
|
1361
|
+
const debouncedCallback = useRef(callback);
|
|
1362
|
+
const timerRef = useRef();
|
|
1363
|
+
useEffect(() => {
|
|
1364
|
+
debouncedCallback.current = callback;
|
|
1365
|
+
}, [callback]);
|
|
1366
|
+
return (...args) => {
|
|
1367
|
+
window.clearTimeout(timerRef.current);
|
|
1368
|
+
timerRef.current = window.setTimeout(() => {
|
|
1369
|
+
debouncedCallback.current(...args);
|
|
1370
|
+
}, delay);
|
|
1371
|
+
};
|
|
1372
|
+
};
|
|
1373
|
+
const useBook = (props = {}) => {
|
|
1374
|
+
const [book, setBook] = useState(() => createBook(props));
|
|
1375
|
+
const { registry } = book;
|
|
1376
|
+
registry.updateSheet = updateSheet;
|
|
1377
|
+
registry.transmit = (patch) => {
|
|
1378
|
+
Object.assign(registry, patch);
|
|
1379
|
+
if (!registry.ready) {
|
|
1380
|
+
return;
|
|
1381
|
+
}
|
|
1382
|
+
requestAnimationFrame(() => setBook({ registry }));
|
|
1383
|
+
};
|
|
1384
|
+
useEffect(() => {
|
|
1385
|
+
Object.assign(registry, props);
|
|
1386
|
+
}, [props]);
|
|
1387
|
+
return book;
|
|
1388
|
+
};
|
|
1389
|
+
export {
|
|
1390
|
+
insertColsLeft as A,
|
|
1391
|
+
insertRowsBelow as B,
|
|
1392
|
+
insertRowsAbove as C,
|
|
1393
|
+
setContextMenuPosition as D,
|
|
1394
|
+
setColumnMenu as E,
|
|
1395
|
+
setRowMenu as F,
|
|
1396
|
+
isXSheetFocused as G,
|
|
1397
|
+
setEditorRect as H,
|
|
1398
|
+
choose as I,
|
|
1399
|
+
drag as J,
|
|
1400
|
+
setDragging as K,
|
|
1401
|
+
submitAutofill as L,
|
|
1402
|
+
setAutofillDraggingTo as M,
|
|
1403
|
+
selectCols as N,
|
|
1404
|
+
useDebounceCallback as O,
|
|
1405
|
+
selectRows as P,
|
|
1406
|
+
search as Q,
|
|
1407
|
+
setSearchCaseSensitive as R,
|
|
1408
|
+
setSearchRegex as S,
|
|
1409
|
+
setSearchRange as T,
|
|
1410
|
+
useBook as U,
|
|
1411
|
+
reducer as V,
|
|
1412
|
+
userActions as W,
|
|
1413
|
+
setInputting as a,
|
|
1414
|
+
updateSheet as b,
|
|
1415
|
+
undo as c,
|
|
1416
|
+
cut as d,
|
|
1417
|
+
setSearchQuery as e,
|
|
1418
|
+
setEntering as f,
|
|
1419
|
+
copy as g,
|
|
1420
|
+
select as h,
|
|
1421
|
+
arrow as i,
|
|
1422
|
+
escape as j,
|
|
1423
|
+
clear as k,
|
|
1424
|
+
walk as l,
|
|
1425
|
+
setEditorHovering as m,
|
|
1426
|
+
setStore as n,
|
|
1427
|
+
setResizingPositionY as o,
|
|
1428
|
+
paste as p,
|
|
1429
|
+
setResizingPositionX as q,
|
|
1430
|
+
redo as r,
|
|
1431
|
+
setEditingAddress as s,
|
|
1432
|
+
filterRows as t,
|
|
1433
|
+
useBrowser as u,
|
|
1434
|
+
sortRows as v,
|
|
1435
|
+
write as w,
|
|
1436
|
+
removeCols as x,
|
|
1437
|
+
removeRows as y,
|
|
1438
|
+
insertColsRight as z
|
|
1439
|
+
};
|
|
1440
|
+
//# sourceMappingURL=hooks-hS8l-fYa.mjs.map
|