@gridsheet/react-core 3.0.5 → 3.0.7

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.
@@ -0,0 +1,1186 @@
1
+ import { useRef as V, useEffect as O, useState as N } from "react";
2
+ import { x2c as ne, y2r as se, a2p as $, Autofill as ie, areaToZone as L, zoneToArea as z, areaDiff as G, restrictZone as U, matrixShape as oe, superposeArea as re, p2a as ce, operations as K, DEFAULT_HEIGHT as F, DEFAULT_WIDTH as k, smartScroll as J, createBook as ae } from "@gridsheet/core";
3
+ const p = (o) => {
4
+ const e = { ...o };
5
+ return e.selectingZone != null && e.selectingZone.endY === -1 && e.selectingZone.endX === -1 && delete e.selectingZone, e;
6
+ }, W = (o, e) => {
7
+ const { choosing: s, selectingZone: t } = o;
8
+ let { y: n, x: i } = s, { startY: r, startX: a, endY: c, endX: d } = t;
9
+ const [l, u] = [e.numRows, e.numCols];
10
+ return n > l && (n = l), i > u && (i = u), r > l && (r = l), c > l && (c = l), a > u && (a = u), d > u && (d = u), {
11
+ choosing: { y: n, x: i },
12
+ selectingZone: { startY: r, startX: a, endY: c, endX: d }
13
+ };
14
+ }, _ = "gs-flash-overlay--active", le = 600, D = (o) => {
15
+ o && (o.classList.remove(_), o.offsetWidth, o.classList.add(_), setTimeout(() => o.classList.remove(_), le));
16
+ }, ee = (o, e, s) => ({
17
+ ...o,
18
+ sheetReactive: { current: e },
19
+ callback: (t) => {
20
+ s == null || s(t), D(o.flashRef.current);
21
+ }
22
+ }), M = (o, e) => {
23
+ const { searchQuery: s, searchCaseSensitive: t, searchRegex: n, searchRange: i } = e;
24
+ let { choosing: r } = e;
25
+ if (!s)
26
+ return { matchingCells: [] };
27
+ const a = [];
28
+ let c;
29
+ if (n)
30
+ try {
31
+ const R = t ? "" : "i", h = new RegExp(s, R);
32
+ c = (w) => h.test(w);
33
+ } catch {
34
+ const h = t ? s : s.toLowerCase();
35
+ c = (w) => (t ? w : w.toLowerCase()).indexOf(h) !== -1;
36
+ }
37
+ else {
38
+ const R = t ? s : s.toLowerCase();
39
+ c = (h) => (t ? h : h.toLowerCase()).indexOf(R) !== -1;
40
+ }
41
+ let d = 1, l = o.bottom, u = 1, g = o.right;
42
+ i && (d = i.startY, l = i.endY, u = i.startX, g = i.endX);
43
+ for (let R = d; R <= l; R++)
44
+ for (let h = u; h <= g; h++) {
45
+ const w = o.getSerializedValue({ point: { y: R, x: h } });
46
+ c(w) && a.push(`${ne(h)}${se(R)}`);
47
+ }
48
+ const S = a.length === e.matchingCells.length ? e.matchingCellIndex : 0;
49
+ if (a.length > 0) {
50
+ const R = a[S];
51
+ r = $(R);
52
+ }
53
+ return { matchingCells: a, searchQuery: s, matchingCellIndex: S, choosing: r };
54
+ }, Zt = (o) => {
55
+ const { sheetId: e, sheetReactive: s } = o, t = s.current;
56
+ return !t || e === t.registry.editingSheetId ? !1 : !!t.registry.editingAddress;
57
+ }, E = { startY: -1, startX: -1, endY: -1, endX: -1 }, j = {}, Xt = (o, e) => {
58
+ var a, c;
59
+ const s = j[e.type];
60
+ if (s == null)
61
+ return o;
62
+ const t = (a = o.sheetReactive.current) == null ? void 0 : a.registry;
63
+ if ((c = t == null ? void 0 : t._strictModeCache) != null && c.has(e)) {
64
+ const d = t._strictModeCache.get(e);
65
+ return t._strictModeCache.delete(e), d;
66
+ }
67
+ const { callback: n, ...i } = s.reduce(o, e.value);
68
+ n == null || n(i);
69
+ const r = { ...o, ...i };
70
+ return t && (t._strictModeCache || (t._strictModeCache = /* @__PURE__ */ new Map()), t._strictModeCache.set(e, r), queueMicrotask(() => {
71
+ var d;
72
+ (d = t._strictModeCache) == null || d.delete(e);
73
+ })), r;
74
+ }, B = class B {
75
+ constructor() {
76
+ this.actionId = 1, this.mutation = !1;
77
+ }
78
+ reduce(e, s) {
79
+ return e;
80
+ }
81
+ call(e) {
82
+ return {
83
+ type: this.actionId,
84
+ value: e
85
+ };
86
+ }
87
+ bind() {
88
+ return this.actionId = B.head++, j[this.actionId] = this, this.call.bind(this);
89
+ }
90
+ };
91
+ B.head = 1;
92
+ let f = B;
93
+ const Mt = (o) => {
94
+ var e;
95
+ return ((e = j[o]) == null ? void 0 : e.mutation) === !0;
96
+ };
97
+ class ue extends f {
98
+ reduce(e, s) {
99
+ const t = s, { sheetReactive: n } = e;
100
+ return n.current == null ? e : {
101
+ ...e,
102
+ ...M(n.current, { ...e, searchQuery: t }),
103
+ searchQuery: t
104
+ };
105
+ }
106
+ }
107
+ const Et = new ue().bind();
108
+ class de extends f {
109
+ reduce(e, s) {
110
+ const t = s, { sheetReactive: n } = e;
111
+ return n.current == null ? e : {
112
+ ...e,
113
+ ...M(n.current, { ...e, searchCaseSensitive: t }),
114
+ searchCaseSensitive: t
115
+ };
116
+ }
117
+ }
118
+ const Ht = new de().bind();
119
+ class he extends f {
120
+ reduce(e, s) {
121
+ const t = s, { sheetReactive: n } = e;
122
+ return n.current == null ? e : {
123
+ ...e,
124
+ ...M(n.current, { ...e, searchRegex: t }),
125
+ searchRegex: t
126
+ };
127
+ }
128
+ }
129
+ const Tt = new he().bind();
130
+ class fe extends f {
131
+ reduce(e, s) {
132
+ const t = s, { sheetReactive: n } = e;
133
+ return n.current == null ? e : {
134
+ ...e,
135
+ ...M(n.current, { ...e, searchRange: t }),
136
+ searchRange: t
137
+ };
138
+ }
139
+ }
140
+ const Ft = new fe().bind();
141
+ class ge extends f {
142
+ reduce(e, s) {
143
+ return {
144
+ ...e,
145
+ editingAddress: s
146
+ };
147
+ }
148
+ }
149
+ const kt = new ge().bind();
150
+ class Re extends f {
151
+ reduce(e, s) {
152
+ return {
153
+ ...e,
154
+ autofillDraggingTo: s
155
+ };
156
+ }
157
+ }
158
+ const Lt = new Re().bind();
159
+ class we extends f {
160
+ reduce(e, s) {
161
+ const t = new ie(e, s), n = t.applied, i = L(t.wholeArea);
162
+ return {
163
+ ...e,
164
+ sheetReactive: { current: n },
165
+ ...M(n, e),
166
+ ...W(e, n),
167
+ selectingZone: i,
168
+ leftHeaderSelecting: !1,
169
+ topHeaderSelecting: !1,
170
+ autofillDraggingTo: null
171
+ };
172
+ }
173
+ }
174
+ const Dt = new we().bind();
175
+ class Se extends f {
176
+ reduce(e, s) {
177
+ return {
178
+ ...e,
179
+ contextMenuPosition: s
180
+ };
181
+ }
182
+ }
183
+ const Pt = new Se().bind();
184
+ class xe extends f {
185
+ reduce(e, s) {
186
+ return {
187
+ ...e,
188
+ resizingPositionY: s
189
+ };
190
+ }
191
+ }
192
+ const zt = new xe().bind();
193
+ class me extends f {
194
+ reduce(e, s) {
195
+ return {
196
+ ...e,
197
+ resizingPositionX: s
198
+ };
199
+ }
200
+ }
201
+ const Bt = new me().bind();
202
+ class ye extends f {
203
+ reduce(e, s) {
204
+ return {
205
+ ...e,
206
+ entering: s
207
+ };
208
+ }
209
+ }
210
+ const Wt = new ye().bind();
211
+ class pe extends f {
212
+ reduce(e, s) {
213
+ return {
214
+ ...e,
215
+ sheetReactive: { current: s },
216
+ ...M(s, e),
217
+ ...W(e, s)
218
+ };
219
+ }
220
+ }
221
+ const ve = new pe().bind();
222
+ class be extends f {
223
+ reduce(e, s) {
224
+ return {
225
+ ...e,
226
+ editorRect: s
227
+ };
228
+ }
229
+ }
230
+ const Ut = new be().bind();
231
+ class Ae extends f {
232
+ reduce(e, s) {
233
+ return {
234
+ ...e,
235
+ dragging: s
236
+ };
237
+ }
238
+ }
239
+ const _t = new Ae().bind();
240
+ class Ce extends f {
241
+ reduce(e, s) {
242
+ return {
243
+ ...e,
244
+ editingAddress: ""
245
+ };
246
+ }
247
+ }
248
+ const Ye = new Ce().bind();
249
+ class Ie extends f {
250
+ reduce(e, s) {
251
+ const { sheetReactive: t } = e, n = t.current;
252
+ return n ? {
253
+ ...e,
254
+ callback: ({ sheetReactive: i }) => {
255
+ n.registry.transmit({
256
+ copyingSheetId: n.id,
257
+ copyingZone: s,
258
+ cutting: !1
259
+ });
260
+ }
261
+ } : e;
262
+ }
263
+ }
264
+ const Ze = new Ie().bind();
265
+ class Xe extends f {
266
+ constructor() {
267
+ super(...arguments), this.mutation = !0;
268
+ }
269
+ reduce(e, s) {
270
+ const { sheetReactive: t } = e, n = t.current;
271
+ return n ? {
272
+ ...e,
273
+ callback: ({ sheetReactive: i }) => {
274
+ n.registry.transmit({
275
+ copyingSheetId: n.id,
276
+ copyingZone: s,
277
+ cutting: !0
278
+ });
279
+ }
280
+ } : e;
281
+ }
282
+ }
283
+ const Me = new Xe().bind();
284
+ class Ee extends f {
285
+ constructor() {
286
+ super(...arguments), this.mutation = !0;
287
+ }
288
+ reduce(e, s) {
289
+ const { choosing: t, selectingZone: n, sheetReactive: i } = e, r = i.current;
290
+ if (!r)
291
+ return e;
292
+ const { registry: a } = r, { copyingSheetId: c, copyingZone: d, cutting: l } = a, u = r.getSheetBySheetId(c);
293
+ let g = z(n);
294
+ const S = z(d), { matrix: R, onlyValue: h } = s;
295
+ if (l) {
296
+ if (!u)
297
+ return e;
298
+ const I = S, { rows: C, cols: v } = G(S), x = g.top !== -1 ? {
299
+ top: g.top,
300
+ left: g.left,
301
+ bottom: g.top + C,
302
+ right: g.left + v
303
+ } : {
304
+ top: t.y,
305
+ left: t.x,
306
+ bottom: t.y + C,
307
+ right: t.x + v
308
+ }, y = U(L(x)), X = r.move({
309
+ srcSheet: u,
310
+ src: I,
311
+ dst: x,
312
+ operator: "USER",
313
+ undoReflection: p({
314
+ sheetId: u.id,
315
+ selectingZone: y,
316
+ choosing: t,
317
+ transmit: { copyingSheetId: u.id, copyingZone: d, cutting: !0 }
318
+ }),
319
+ redoReflection: p({
320
+ sheetId: u.id,
321
+ choosing: t,
322
+ transmit: { copyingSheetId: u.id, copyingZone: E }
323
+ })
324
+ });
325
+ return {
326
+ ...e,
327
+ ...M(X, e),
328
+ sheetReactive: { current: X },
329
+ selectingZone: y,
330
+ inputting: X.getSerializedValue({ point: t, resolution: "RAW" }),
331
+ callback: ({ sheetReactive: T }) => {
332
+ a.transmit({
333
+ cutting: !1,
334
+ copyingZone: E
335
+ });
336
+ }
337
+ };
338
+ }
339
+ let w, { y: m, x: Z } = t;
340
+ if (S.top === -1) {
341
+ const { rows: I, cols: C } = oe({ matrix: R, base: -1 });
342
+ g = {
343
+ top: m,
344
+ left: Z,
345
+ bottom: m + I,
346
+ right: Z + C
347
+ };
348
+ const v = U(L(g));
349
+ w = r.writeRawCellMatrix({
350
+ point: { y: m, x: Z },
351
+ matrix: R,
352
+ onlyValue: h,
353
+ undoReflection: p({
354
+ sheetId: r.id,
355
+ selectingZone: v,
356
+ choosing: t
357
+ }),
358
+ redoReflection: p({
359
+ sheetId: r.id,
360
+ selectingZone: v,
361
+ choosing: t
362
+ })
363
+ });
364
+ } else {
365
+ if (u == null)
366
+ return e;
367
+ let { rows: I, cols: C } = G(S);
368
+ if (g.top !== -1) {
369
+ m = g.top, Z = g.left;
370
+ const v = re(g, S);
371
+ I = v.rows, C = v.cols;
372
+ }
373
+ g = { top: m, left: Z, bottom: m + I, right: Z + C }, w = r.copy({
374
+ srcSheet: u,
375
+ src: S,
376
+ dst: g,
377
+ onlyValue: h,
378
+ operator: "USER",
379
+ undoReflection: p({
380
+ sheetId: u.id,
381
+ transmit: { copyingZone: d },
382
+ choosing: t,
383
+ selectingZone: n
384
+ }),
385
+ redoReflection: p({
386
+ sheetId: u.id,
387
+ transmit: { copyingSheetId: u.id, copyingZone: E },
388
+ choosing: t,
389
+ selectingZone: L(g)
390
+ })
391
+ });
392
+ }
393
+ const Y = U(L(g));
394
+ return Y.endX = Math.min(Y.endX, w.numCols), Y.endY = Math.min(Y.endY, w.numRows), {
395
+ ...e,
396
+ sheetReactive: { current: w },
397
+ selectingZone: Y,
398
+ inputting: w.getSerializedValue({ point: t, resolution: "RAW" }),
399
+ ...M(w, e),
400
+ callback: ({ sheetReactive: I }) => {
401
+ a.transmit({
402
+ copyingZone: E
403
+ });
404
+ }
405
+ };
406
+ }
407
+ }
408
+ const He = new Ee().bind();
409
+ class Te extends f {
410
+ reduce(e, s) {
411
+ const { sheetReactive: t } = e;
412
+ return {
413
+ ...e,
414
+ editingAddress: "",
415
+ leftHeaderSelecting: !1,
416
+ topHeaderSelecting: !1,
417
+ callback: ({ sheetReactive: n }) => {
418
+ n.current.registry.transmit({
419
+ copyingZone: E,
420
+ cutting: !1
421
+ });
422
+ }
423
+ };
424
+ }
425
+ }
426
+ const Fe = new Te().bind();
427
+ class ke extends f {
428
+ reduce(e, s) {
429
+ return {
430
+ ...e,
431
+ choosing: s,
432
+ entering: !0
433
+ };
434
+ }
435
+ }
436
+ const Le = new ke().bind();
437
+ class De extends f {
438
+ reduce(e, s) {
439
+ return {
440
+ ...e,
441
+ selectingZone: s,
442
+ leftHeaderSelecting: !1,
443
+ topHeaderSelecting: !1
444
+ };
445
+ }
446
+ }
447
+ const Pe = new De().bind();
448
+ class ze extends f {
449
+ reduce(e, s) {
450
+ const { range: t, numCols: n } = s, { start: i, end: r } = t, a = e.sheetReactive.current, c = {
451
+ startY: i,
452
+ startX: 1,
453
+ endY: r,
454
+ endX: n
455
+ };
456
+ let d = i;
457
+ if (a) {
458
+ for (let l = i; l <= r; l++)
459
+ if (!a.isRowFiltered(l)) {
460
+ d = l;
461
+ break;
462
+ }
463
+ }
464
+ return {
465
+ ...e,
466
+ selectingZone: c,
467
+ choosing: { y: d, x: 1 },
468
+ leftHeaderSelecting: !0,
469
+ topHeaderSelecting: !1
470
+ };
471
+ }
472
+ }
473
+ const Be = new ze().bind();
474
+ class We extends f {
475
+ reduce(e, s) {
476
+ const { range: t, numRows: n } = s, { start: i, end: r } = t, a = e.sheetReactive.current, c = {
477
+ startY: 1,
478
+ startX: i,
479
+ endY: n,
480
+ endX: r
481
+ };
482
+ let d = 1;
483
+ if (a) {
484
+ for (let l = 1; l <= n; l++)
485
+ if (!a.isRowFiltered(l)) {
486
+ d = l;
487
+ break;
488
+ }
489
+ }
490
+ return {
491
+ ...e,
492
+ selectingZone: c,
493
+ choosing: { y: d, x: i },
494
+ leftHeaderSelecting: !1,
495
+ topHeaderSelecting: !0
496
+ };
497
+ }
498
+ }
499
+ const Ue = new We().bind();
500
+ class _e extends f {
501
+ reduce(e, s) {
502
+ const { startY: t, startX: n } = e.selectingZone, i = {
503
+ startY: t,
504
+ startX: n,
505
+ endY: s.y,
506
+ endX: s.x
507
+ };
508
+ return t === s.y && n === s.x && (i.endY = -1, i.endX = -1), { ...e, selectingZone: i };
509
+ }
510
+ }
511
+ const Oe = new _e().bind();
512
+ class je extends f {
513
+ reduce(e, s) {
514
+ const { matchingCells: t } = e;
515
+ let { matchingCellIndex: n, choosing: i } = e;
516
+ if (n += s, n >= t.length ? n = 0 : n < 0 && (n = t.length - 1), t.length > 0) {
517
+ const r = t[n];
518
+ i = $(r);
519
+ }
520
+ return { ...e, matchingCells: t, matchingCellIndex: n, choosing: i };
521
+ }
522
+ }
523
+ const qe = new je().bind();
524
+ class Qe extends f {
525
+ reduce(e, s) {
526
+ let { value: t, point: n } = s;
527
+ const { choosing: i, selectingZone: r, sheetReactive: a } = e;
528
+ n == null && (n = i);
529
+ const c = a.current;
530
+ if (!c)
531
+ return e;
532
+ const d = c.write({
533
+ point: n,
534
+ value: t,
535
+ operator: "USER",
536
+ undoReflection: p({
537
+ sheetId: c.id,
538
+ selectingZone: r,
539
+ choosing: n
540
+ }),
541
+ redoReflection: p({
542
+ sheetId: c.id,
543
+ selectingZone: r,
544
+ choosing: n
545
+ })
546
+ });
547
+ return {
548
+ ...e,
549
+ ...M(d, e),
550
+ sheetReactive: { current: d },
551
+ callback: ({ sheetReactive: l }) => {
552
+ c.registry.transmit({
553
+ copyingZone: E
554
+ });
555
+ }
556
+ };
557
+ }
558
+ }
559
+ const Ve = new Qe().bind();
560
+ class Ge extends f {
561
+ constructor() {
562
+ super(...arguments), this.mutation = !0;
563
+ }
564
+ reduce(e, s) {
565
+ var R;
566
+ const { choosing: t, selectingZone: n, sheetReactive: i } = e, r = i.current;
567
+ if (!r)
568
+ return e;
569
+ let a = z(n);
570
+ if (a.top === -1) {
571
+ const { y: h, x: w } = t;
572
+ a = { top: h, left: w, bottom: h, right: w };
573
+ }
574
+ const { top: c, left: d, bottom: l, right: u } = a, g = {};
575
+ let S = 0;
576
+ for (let h = c; h <= l; h++)
577
+ if (!r.isRowFiltered(h))
578
+ for (let w = d; w <= u; w++) {
579
+ const m = r.getCell({ y: h, x: w }, { resolution: "SYSTEM" }), Z = ce({ y: h, x: w });
580
+ K.hasOperation(m == null ? void 0 : m.prevention, K.Write) || ((R = r.getSystem({ y: h, x: w })) == null ? void 0 : R.spilledFrom) == null && (m == null ? void 0 : m.value) != null && (g[Z] = { value: void 0 }, S++);
581
+ }
582
+ return S === 0 ? e : (r.update({
583
+ diff: g,
584
+ partial: !0,
585
+ operator: "USER",
586
+ undoReflection: p({
587
+ sheetId: r.id,
588
+ selectingZone: n,
589
+ choosing: t
590
+ }),
591
+ redoReflection: p({
592
+ sheetId: r.id,
593
+ selectingZone: n,
594
+ choosing: t
595
+ })
596
+ }), {
597
+ ...e,
598
+ ...M(r, e),
599
+ sheetReactive: { current: r }
600
+ });
601
+ }
602
+ }
603
+ const Ke = new Ge().bind();
604
+ class Ne extends f {
605
+ constructor() {
606
+ super(...arguments), this.mutation = !0;
607
+ }
608
+ reduce(e, s) {
609
+ const { sheetReactive: t } = e, n = t.current;
610
+ if (!n)
611
+ return e;
612
+ const { history: i, callback: r } = n.undo();
613
+ if (i == null)
614
+ return e;
615
+ if (i.dstSheetId !== n.id) {
616
+ const { dispatch: a, store: c } = n.registry.contextsBySheetId[i.dstSheetId];
617
+ return a(
618
+ te({
619
+ ...c,
620
+ ...i.undoReflection,
621
+ sheetReactive: { current: c.sheetReactive.current }
622
+ })
623
+ ), D(c.flashRef.current), i.srcSheetId === n.id ? ee(e, n, r) : e;
624
+ }
625
+ return {
626
+ ...e,
627
+ ...W(e, n),
628
+ ...i.undoReflection,
629
+ ...M(n, e),
630
+ sheetReactive: { current: n },
631
+ callback: (a) => {
632
+ r == null || r(a), D(e.flashRef.current);
633
+ }
634
+ };
635
+ }
636
+ }
637
+ const $e = new Ne().bind();
638
+ class Je extends f {
639
+ constructor() {
640
+ super(...arguments), this.mutation = !0;
641
+ }
642
+ reduce(e, s) {
643
+ const { sheetReactive: t } = e, n = t.current;
644
+ if (n == null)
645
+ return e;
646
+ const { history: i, newSheet: r, callback: a } = n.redo();
647
+ if (i == null)
648
+ return e;
649
+ if (i.dstSheetId !== n.id) {
650
+ const { dispatch: c, store: d } = n.registry.contextsBySheetId[i.dstSheetId];
651
+ return c(
652
+ te({
653
+ ...d,
654
+ ...i.redoReflection,
655
+ sheetReactive: { current: d.sheetReactive.current }
656
+ })
657
+ ), D(d.flashRef.current), i.srcSheetId === n.id ? ee(e, n, a) : e;
658
+ }
659
+ return {
660
+ ...e,
661
+ ...W(e, n),
662
+ ...i.redoReflection,
663
+ ...M(n, e),
664
+ sheetReactive: { current: n },
665
+ callback: (c) => {
666
+ a == null || a(c), D(e.flashRef.current);
667
+ }
668
+ };
669
+ }
670
+ }
671
+ const et = new Je().bind();
672
+ class tt extends f {
673
+ reduce(e, s) {
674
+ var x, y, X, T;
675
+ const { shiftKey: t, deltaY: n, deltaX: i, numRows: r, numCols: a } = s, { choosing: c, sheetReactive: d, tabularRef: l } = e, u = d.current;
676
+ if (u == null)
677
+ return e;
678
+ let { selectingZone: g } = e;
679
+ const { y: S, x: R } = c;
680
+ if (t) {
681
+ const [b, P] = [
682
+ g.endY === -1 ? S : g.endY,
683
+ g.endX === -1 ? R : g.endX
684
+ ], [H, A] = [b + n, P + i];
685
+ return H < 1 || r < H || A < 1 || a < A ? e : (g = S === H && R === A ? { startY: -1, startX: -1, endY: -1, endX: -1 } : { startY: S, startX: R, endY: H, endX: A }, {
686
+ ...e,
687
+ selectingZone: g
688
+ });
689
+ }
690
+ const [h, w] = [S + n, R + i];
691
+ if (h < 1 || r < h || w < 1 || a < w)
692
+ return e;
693
+ let m = h;
694
+ if (u.isRowFiltered(m)) {
695
+ const b = n >= 0 ? 1 : -1;
696
+ for (; m >= 1 && m <= r && u.isRowFiltered(m); )
697
+ m += b;
698
+ if (m < 1 || m > r)
699
+ return e;
700
+ }
701
+ let { y: Z, x: Y, height: I, width: C } = e.editorRect;
702
+ if (n > 0)
703
+ for (let b = S; b < m; b++)
704
+ Z += ((x = u.getCell({ y: b, x: 0 }, { resolution: "SYSTEM" })) == null ? void 0 : x.height) || F;
705
+ else if (n < 0)
706
+ for (let b = S - 1; b >= m; b--)
707
+ Z -= ((y = u.getCell({ y: b, x: 0 }, { resolution: "SYSTEM" })) == null ? void 0 : y.height) || F;
708
+ if (i > 0)
709
+ for (let b = R; b < w; b++)
710
+ Y += ((X = u.getCell({ y: 0, x: b }, { resolution: "SYSTEM" })) == null ? void 0 : X.width) || k;
711
+ else if (i < 0)
712
+ for (let b = R - 1; b >= w; b--)
713
+ Y -= ((T = u.getCell({ y: 0, x: b }, { resolution: "SYSTEM" })) == null ? void 0 : T.width) || k;
714
+ const v = u.getCell({ y: m, x: w }, { resolution: "SYSTEM" });
715
+ return I = (v == null ? void 0 : v.height) || F, C = (v == null ? void 0 : v.width) || k, J(u, l.current, { y: m, x: w }), {
716
+ ...e,
717
+ selectingZone: { startY: -1, startX: -1, endY: -1, endX: -1 },
718
+ choosing: { y: m, x: w },
719
+ editorRect: { y: Z, x: Y, height: I, width: C }
720
+ };
721
+ }
722
+ }
723
+ const nt = new tt().bind();
724
+ class st extends f {
725
+ reduce(e, s) {
726
+ var T, b, P, H;
727
+ const { numRows: t, numCols: n } = s;
728
+ let { deltaY: i, deltaX: r } = s;
729
+ const { choosing: a, selectingZone: c, sheetReactive: d, tabularRef: l } = e, u = d.current;
730
+ if (u == null)
731
+ return e;
732
+ let { y: g, x: S, height: R, width: h } = e.editorRect;
733
+ const { y: w, x: m } = a, Z = z(c), { top: Y, left: I, bottom: C, right: v } = Z;
734
+ let [x, y] = [w + i, m + r];
735
+ if (x < Y && Y !== -1 && (i = C - x, x = C, y > I ? (y--, r--) : (r = v - y, y = v)), x > C && C !== -1 && (i = Y - x, x = Y, y < v ? (y++, r++) : (r = I - y, y = I)), y < I && I !== -1 && (r = v - y, y = v, x > Y ? (x--, i--) : (i = C - x, x = C)), y > v && v !== -1 && (r = I - y, y = I, x < C ? (x++, i++) : (i = Y - x, x = Y)), x < 1 || t < x || y < 1 || n < y)
736
+ return e;
737
+ if (u.isRowFiltered(x)) {
738
+ const A = i >= 0 ? 1 : -1, q = Y !== -1 ? Y : 1, Q = C !== -1 ? C : t;
739
+ for (; x >= q && x <= Q && u.isRowFiltered(x); )
740
+ x += A;
741
+ if (x < q || x > Q || u.isRowFiltered(x))
742
+ return e;
743
+ }
744
+ if (i > 0)
745
+ for (let A = w; A < x; A++)
746
+ g += ((T = u.getCell({ y: A, x: 0 }, { resolution: "SYSTEM" })) == null ? void 0 : T.height) || F;
747
+ else if (i < 0)
748
+ for (let A = w - 1; A >= x; A--)
749
+ g -= ((b = u.getCell({ y: A, x: 0 }, { resolution: "SYSTEM" })) == null ? void 0 : b.height) || F;
750
+ if (r > 0)
751
+ for (let A = m; A < y; A++)
752
+ S += ((P = u.getCell({ y: 0, x: A }, { resolution: "SYSTEM" })) == null ? void 0 : P.width) || k;
753
+ else if (r < 0)
754
+ for (let A = m - 1; A >= y; A--)
755
+ S -= ((H = u.getCell({ y: 0, x: A }, { resolution: "SYSTEM" })) == null ? void 0 : H.width) || k;
756
+ const X = u.getCell({ y: x, x: y }, { resolution: "SYSTEM" });
757
+ return R = (X == null ? void 0 : X.height) || F, h = (X == null ? void 0 : X.width) || k, J(u, l.current, { y: x, x: y }), {
758
+ ...e,
759
+ choosing: { y: x, x: y },
760
+ editorRect: { y: g, x: S, height: R, width: h }
761
+ };
762
+ }
763
+ }
764
+ const it = new st().bind();
765
+ class ot extends f {
766
+ reduce(e, s) {
767
+ return {
768
+ ...e,
769
+ inputting: s
770
+ };
771
+ }
772
+ }
773
+ const Ot = new ot().bind();
774
+ class rt extends f {
775
+ constructor() {
776
+ super(...arguments), this.mutation = !0;
777
+ }
778
+ reduce(e, s) {
779
+ const { numRows: t, y: n, operator: i } = s, { sheetReactive: r, selectingZone: a, choosing: c } = e, d = r.current;
780
+ return d == null ? e : (d.insertRows({
781
+ y: n,
782
+ numRows: t,
783
+ baseY: n,
784
+ operator: i,
785
+ undoReflection: p({
786
+ sheetId: d.id,
787
+ selectingZone: a,
788
+ choosing: c
789
+ }),
790
+ redoReflection: p({
791
+ sheetId: d.id,
792
+ selectingZone: a,
793
+ choosing: c
794
+ })
795
+ }), {
796
+ ...e,
797
+ sheetReactive: { current: d }
798
+ });
799
+ }
800
+ }
801
+ const ct = new rt().bind();
802
+ class at extends f {
803
+ constructor() {
804
+ super(...arguments), this.mutation = !0;
805
+ }
806
+ reduce(e, s) {
807
+ const { numRows: t, y: n, operator: i } = s, { sheetReactive: r, selectingZone: a, choosing: c, editorRef: d } = e, l = r.current;
808
+ if (l == null)
809
+ return e;
810
+ const u = {
811
+ ...a,
812
+ startY: a.startY + t,
813
+ endY: a.endY + t
814
+ }, g = { ...c, y: c.y + t };
815
+ return l.insertRows({
816
+ y: n + 1,
817
+ numRows: t,
818
+ baseY: n,
819
+ operator: i,
820
+ undoReflection: p({
821
+ sheetId: l.id,
822
+ selectingZone: a,
823
+ choosing: c
824
+ }),
825
+ redoReflection: p({
826
+ sheetId: l.id,
827
+ selectingZone: u,
828
+ choosing: g
829
+ })
830
+ }), {
831
+ ...e,
832
+ selectingZone: u,
833
+ choosing: g,
834
+ sheetReactive: { current: l }
835
+ };
836
+ }
837
+ }
838
+ const lt = new at().bind();
839
+ class ut extends f {
840
+ constructor() {
841
+ super(...arguments), this.mutation = !0;
842
+ }
843
+ reduce(e, s) {
844
+ const { numCols: t, x: n, operator: i } = s, { sheetReactive: r, selectingZone: a, choosing: c, editorRef: d } = e, l = r.current;
845
+ return l == null ? e : (l.insertCols({
846
+ x: n,
847
+ numCols: t,
848
+ baseX: n,
849
+ operator: i,
850
+ undoReflection: p({
851
+ sheetId: l.id,
852
+ selectingZone: a,
853
+ choosing: c
854
+ }),
855
+ redoReflection: p({
856
+ sheetId: l.id,
857
+ selectingZone: a,
858
+ choosing: c
859
+ })
860
+ }), {
861
+ ...e,
862
+ sheetReactive: { current: l }
863
+ });
864
+ }
865
+ }
866
+ const dt = new ut().bind();
867
+ class ht extends f {
868
+ constructor() {
869
+ super(...arguments), this.mutation = !0;
870
+ }
871
+ reduce(e, s) {
872
+ const { numCols: t, x: n, operator: i } = s, { sheetReactive: r, selectingZone: a, choosing: c } = e, d = r.current;
873
+ if (d == null)
874
+ return e;
875
+ const l = {
876
+ ...a,
877
+ startX: a.startX + t,
878
+ endX: a.endX + t
879
+ }, u = { ...c, x: c.x + t };
880
+ return a.startX += t, a.endX += t, d.insertCols({
881
+ x: n + 1,
882
+ numCols: t,
883
+ baseX: n,
884
+ operator: i,
885
+ undoReflection: p({
886
+ sheetId: d.id,
887
+ selectingZone: a,
888
+ choosing: c
889
+ }),
890
+ redoReflection: p({
891
+ sheetId: d.id,
892
+ selectingZone: l,
893
+ choosing: u
894
+ })
895
+ }), {
896
+ ...e,
897
+ selectingZone: l,
898
+ choosing: u,
899
+ sheetReactive: { current: d }
900
+ };
901
+ }
902
+ }
903
+ const ft = new ht().bind();
904
+ class gt extends f {
905
+ constructor() {
906
+ super(...arguments), this.mutation = !0;
907
+ }
908
+ reduce(e, s) {
909
+ const { numRows: t, y: n, operator: i } = s, { sheetReactive: r, selectingZone: a, choosing: c, editorRef: d } = e, l = r.current;
910
+ if (l == null)
911
+ return e;
912
+ l.removeRows({
913
+ y: n,
914
+ numRows: t,
915
+ operator: i,
916
+ undoReflection: p({
917
+ sheetId: l.id,
918
+ selectingZone: a,
919
+ choosing: c,
920
+ sheetHeight: e.sheetHeight
921
+ }),
922
+ redoReflection: p({
923
+ sheetId: l.id,
924
+ selectingZone: a,
925
+ choosing: c
926
+ })
927
+ });
928
+ const u = l.numRows, g = l.numCols;
929
+ let S = Math.max(1, Math.min(n, u));
930
+ if (l.isRowFiltered(S)) {
931
+ let R = -1;
932
+ for (let h = S; h <= u; h++)
933
+ if (!l.isRowFiltered(h)) {
934
+ R = h;
935
+ break;
936
+ }
937
+ if (R === -1) {
938
+ for (let h = S; h >= 1; h--)
939
+ if (!l.isRowFiltered(h)) {
940
+ R = h;
941
+ break;
942
+ }
943
+ }
944
+ R !== -1 && (S = R);
945
+ }
946
+ return {
947
+ ...e,
948
+ sheetReactive: { current: l },
949
+ selectingZone: { startY: S, startX: 1, endY: S, endX: g },
950
+ choosing: { y: S, x: 1 },
951
+ leftHeaderSelecting: !0,
952
+ topHeaderSelecting: !1
953
+ };
954
+ }
955
+ }
956
+ const Rt = new gt().bind();
957
+ class wt extends f {
958
+ constructor() {
959
+ super(...arguments), this.mutation = !0;
960
+ }
961
+ reduce(e, s) {
962
+ const { numCols: t, x: n, operator: i } = s, { sheetReactive: r, selectingZone: a, choosing: c, editorRef: d } = e, l = r.current;
963
+ if (l == null)
964
+ return e;
965
+ l.removeCols({
966
+ x: n,
967
+ numCols: t,
968
+ operator: i,
969
+ undoReflection: p({
970
+ sheetId: l.id,
971
+ selectingZone: a,
972
+ choosing: c,
973
+ sheetWidth: e.sheetWidth
974
+ }),
975
+ redoReflection: p({
976
+ sheetId: l.id,
977
+ selectingZone: a,
978
+ choosing: c
979
+ })
980
+ });
981
+ const u = l.numCols, g = l.numRows, S = Math.max(1, Math.min(n, u));
982
+ let R = 1;
983
+ for (let h = 1; h <= g; h++)
984
+ if (!l.isRowFiltered(h)) {
985
+ R = h;
986
+ break;
987
+ }
988
+ return {
989
+ ...e,
990
+ sheetReactive: { current: l },
991
+ selectingZone: { startY: 1, startX: S, endY: g, endX: S },
992
+ choosing: { y: R, x: S },
993
+ leftHeaderSelecting: !1,
994
+ topHeaderSelecting: !0
995
+ };
996
+ }
997
+ }
998
+ const St = new wt().bind();
999
+ class xt extends f {
1000
+ constructor() {
1001
+ super(...arguments), this.mutation = !0;
1002
+ }
1003
+ reduce(e, s) {
1004
+ const { x: t, direction: n } = s, { sheetReactive: i, selectingZone: r, choosing: a } = e, c = i.current;
1005
+ if (c == null)
1006
+ return e;
1007
+ c.sortRows({ x: t, direction: n });
1008
+ const d = p({ sheetId: c.id, selectingZone: r, choosing: a });
1009
+ return c.registry.lastHistory && (c.registry.lastHistory.undoReflection = d, c.registry.lastHistory.redoReflection = d), {
1010
+ ...e,
1011
+ sheetReactive: { current: c }
1012
+ };
1013
+ }
1014
+ }
1015
+ const mt = new xt().bind();
1016
+ class yt extends f {
1017
+ constructor() {
1018
+ super(...arguments), this.mutation = !0;
1019
+ }
1020
+ reduce(e, s) {
1021
+ const { x: t, filter: n } = s, { sheetReactive: i, selectingZone: r, choosing: a } = e, c = i.current;
1022
+ if (c == null)
1023
+ return e;
1024
+ c.filterRows({ x: t, filter: n });
1025
+ const d = p({ sheetId: c.id, selectingZone: r, choosing: a });
1026
+ c.registry.lastHistory && (c.registry.lastHistory.undoReflection = d, c.registry.lastHistory.redoReflection = d);
1027
+ let l = a;
1028
+ if (c.isRowFiltered(a.y)) {
1029
+ for (let u = 1; u <= c.numRows; u++)
1030
+ if (!c.isRowFiltered(u)) {
1031
+ l = { y: u, x: a.x };
1032
+ break;
1033
+ }
1034
+ }
1035
+ return {
1036
+ ...e,
1037
+ choosing: l,
1038
+ selectingZone: l !== a ? E : r,
1039
+ sheetReactive: { current: c },
1040
+ callback: ({ sheetReactive: u }) => {
1041
+ const g = u.current;
1042
+ g && g.registry.transmit({
1043
+ cutting: !1,
1044
+ copyingZone: E
1045
+ });
1046
+ }
1047
+ };
1048
+ }
1049
+ }
1050
+ const pt = new yt().bind();
1051
+ class vt extends f {
1052
+ reduce(e, s) {
1053
+ return {
1054
+ ...e,
1055
+ columnMenuState: s
1056
+ };
1057
+ }
1058
+ }
1059
+ const jt = new vt().bind();
1060
+ class bt extends f {
1061
+ reduce(e, s) {
1062
+ return {
1063
+ ...e,
1064
+ rowMenuState: s
1065
+ };
1066
+ }
1067
+ }
1068
+ const qt = new bt().bind();
1069
+ class At extends f {
1070
+ reduce(e, s) {
1071
+ return {
1072
+ ...e,
1073
+ editorHovering: s
1074
+ };
1075
+ }
1076
+ }
1077
+ const Qt = new At().bind();
1078
+ class Ct extends f {
1079
+ reduce(e, s) {
1080
+ return {
1081
+ ...e,
1082
+ ...s
1083
+ };
1084
+ }
1085
+ }
1086
+ const te = new Ct().bind(), Vt = {
1087
+ blur: Ye,
1088
+ copy: Ze,
1089
+ cut: Me,
1090
+ paste: He,
1091
+ escape: Fe,
1092
+ choose: Le,
1093
+ select: Pe,
1094
+ selectRows: Be,
1095
+ selectCols: Ue,
1096
+ drag: Oe,
1097
+ search: qe,
1098
+ write: Ve,
1099
+ clear: Ke,
1100
+ undo: $e,
1101
+ redo: et,
1102
+ arrow: nt,
1103
+ walk: it,
1104
+ insertRowsAbove: ct,
1105
+ insertRowsBelow: lt,
1106
+ insertColsLeft: dt,
1107
+ insertColsRight: ft,
1108
+ removeRows: Rt,
1109
+ removeCols: St,
1110
+ sortRows: mt,
1111
+ filterRows: pt
1112
+ }, Gt = () => {
1113
+ const [o, e] = N(!1);
1114
+ return O(() => {
1115
+ e(!0);
1116
+ }, []), o && typeof window < "u" ? { window, document } : { window: null, document: null };
1117
+ }, Kt = (o, e = 100) => {
1118
+ const s = V(o), t = V();
1119
+ return O(() => {
1120
+ s.current = o;
1121
+ }, [o]), (...n) => {
1122
+ window.clearTimeout(t.current), t.current = window.setTimeout(() => {
1123
+ s.current(...n);
1124
+ }, e);
1125
+ };
1126
+ }, Nt = (o = {}) => {
1127
+ const [e, s] = N(() => ae(o)), { registry: t } = e;
1128
+ return t.updateSheet = ve, t.transmit = (n) => {
1129
+ Object.assign(t, n), t.ready && requestAnimationFrame(() => s({ registry: t }));
1130
+ }, O(() => {
1131
+ Object.assign(t, o);
1132
+ }, [o]), e;
1133
+ };
1134
+ export {
1135
+ dt as A,
1136
+ lt as B,
1137
+ ct as C,
1138
+ Pt as D,
1139
+ jt as E,
1140
+ qt as F,
1141
+ Zt as G,
1142
+ Ut as H,
1143
+ Le as I,
1144
+ Oe as J,
1145
+ _t as K,
1146
+ Dt as L,
1147
+ Lt as M,
1148
+ Ue as N,
1149
+ Kt as O,
1150
+ Be as P,
1151
+ qe as Q,
1152
+ Ht as R,
1153
+ Tt as S,
1154
+ Ft as T,
1155
+ Nt as U,
1156
+ Xt as V,
1157
+ Mt as W,
1158
+ Vt as X,
1159
+ Ot as a,
1160
+ ve as b,
1161
+ $e as c,
1162
+ Me as d,
1163
+ Et as e,
1164
+ Wt as f,
1165
+ Ze as g,
1166
+ Pe as h,
1167
+ nt as i,
1168
+ Fe as j,
1169
+ Ke as k,
1170
+ it as l,
1171
+ Qt as m,
1172
+ te as n,
1173
+ zt as o,
1174
+ He as p,
1175
+ Bt as q,
1176
+ et as r,
1177
+ kt as s,
1178
+ pt as t,
1179
+ Gt as u,
1180
+ mt as v,
1181
+ Ve as w,
1182
+ St as x,
1183
+ Rt as y,
1184
+ ft as z
1185
+ };
1186
+ //# sourceMappingURL=hooks-CvkA2lFB.mjs.map