@gridsheet/preact-core 3.0.0-rc.0 → 3.0.0-rc.10

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