@gridsheet/preact-core 3.2.0 → 3.3.0

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