@sage-bionetworks/react-datasheet-grid 4.11.5-sage.1

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 (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +77 -0
  3. package/dist/columns/checkboxColumn.d.ts +3 -0
  4. package/dist/columns/checkboxColumn.d.ts.map +1 -0
  5. package/dist/columns/dateColumn.d.ts +3 -0
  6. package/dist/columns/dateColumn.d.ts.map +1 -0
  7. package/dist/columns/floatColumn.d.ts +9 -0
  8. package/dist/columns/floatColumn.d.ts.map +1 -0
  9. package/dist/columns/intColumn.d.ts +9 -0
  10. package/dist/columns/intColumn.d.ts.map +1 -0
  11. package/dist/columns/isoDateColumn.d.ts +3 -0
  12. package/dist/columns/isoDateColumn.d.ts.map +1 -0
  13. package/dist/columns/keyColumn.d.ts +8 -0
  14. package/dist/columns/keyColumn.d.ts.map +1 -0
  15. package/dist/columns/percentColumn.d.ts +9 -0
  16. package/dist/columns/percentColumn.d.ts.map +1 -0
  17. package/dist/columns/textColumn.d.ts +24 -0
  18. package/dist/columns/textColumn.d.ts.map +1 -0
  19. package/dist/components/AddRows.d.ts +8 -0
  20. package/dist/components/AddRows.d.ts.map +1 -0
  21. package/dist/components/Cell.d.ts +12 -0
  22. package/dist/components/Cell.d.ts.map +1 -0
  23. package/dist/components/ContextMenu.d.ts +7 -0
  24. package/dist/components/ContextMenu.d.ts.map +1 -0
  25. package/dist/components/DataSheetGrid.d.ts +6 -0
  26. package/dist/components/DataSheetGrid.d.ts.map +1 -0
  27. package/dist/components/Grid.d.ts +43 -0
  28. package/dist/components/Grid.d.ts.map +1 -0
  29. package/dist/components/SelectionRect.d.ts +4 -0
  30. package/dist/components/SelectionRect.d.ts.map +1 -0
  31. package/dist/components/StaticDataSheetGrid.d.ts +6 -0
  32. package/dist/components/StaticDataSheetGrid.d.ts.map +1 -0
  33. package/dist/hooks/useColumnWidths.d.ts +14 -0
  34. package/dist/hooks/useColumnWidths.d.ts.map +1 -0
  35. package/dist/hooks/useColumns.d.ts +8 -0
  36. package/dist/hooks/useColumns.d.ts.map +1 -0
  37. package/dist/hooks/useDebounceState.d.ts +2 -0
  38. package/dist/hooks/useDebounceState.d.ts.map +1 -0
  39. package/dist/hooks/useDeepEqualState.d.ts +3 -0
  40. package/dist/hooks/useDeepEqualState.d.ts.map +1 -0
  41. package/dist/hooks/useDocumentEventListener.d.ts +2 -0
  42. package/dist/hooks/useDocumentEventListener.d.ts.map +1 -0
  43. package/dist/hooks/useEdges.d.ts +8 -0
  44. package/dist/hooks/useEdges.d.ts.map +1 -0
  45. package/dist/hooks/useFirstRender.d.ts +2 -0
  46. package/dist/hooks/useFirstRender.d.ts.map +1 -0
  47. package/dist/hooks/useGetBoundingClientRect.d.ts +3 -0
  48. package/dist/hooks/useGetBoundingClientRect.d.ts.map +1 -0
  49. package/dist/hooks/useMemoizedIndexCallback.d.ts +2 -0
  50. package/dist/hooks/useMemoizedIndexCallback.d.ts.map +1 -0
  51. package/dist/hooks/useRowHeights.d.ts +13 -0
  52. package/dist/hooks/useRowHeights.d.ts.map +1 -0
  53. package/dist/index.cjs +10 -0
  54. package/dist/index.cjs.map +1 -0
  55. package/dist/index.d.ts +28 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +3145 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/types.d.ts +198 -0
  60. package/dist/types.d.ts.map +1 -0
  61. package/dist/utils/copyPasting.d.ts +5 -0
  62. package/dist/utils/copyPasting.d.ts.map +1 -0
  63. package/dist/utils/domParser.d.ts +2 -0
  64. package/dist/utils/domParser.d.ts.map +1 -0
  65. package/dist/utils/tab.d.ts +2 -0
  66. package/dist/utils/tab.d.ts.map +1 -0
  67. package/dist/utils/typeCheck.d.ts +6 -0
  68. package/dist/utils/typeCheck.d.ts.map +1 -0
  69. package/package.json +87 -0
package/dist/index.js ADDED
@@ -0,0 +1,3145 @@
1
+ import { jsx as S, Fragment as ne, jsxs as Me } from "react/jsx-runtime";
2
+ import * as Ke from "react";
3
+ import be, { useMemo as ge, useRef as K, useState as re, useCallback as k, useEffect as J, useImperativeHandle as An, useLayoutEffect as $e } from "react";
4
+ import { flushSync as _n } from "react-dom";
5
+ const zn = (e, r) => {
6
+ const t = r.map(({ basis: n, minWidth: s, maxWidth: i }) => ({
7
+ basis: n,
8
+ minWidth: s,
9
+ maxWidth: i,
10
+ size: n,
11
+ violation: 0,
12
+ frozen: !1,
13
+ factor: 0
14
+ }));
15
+ let o = t.reduce(
16
+ (n, s) => n - s.size,
17
+ e
18
+ );
19
+ o > 0 ? r.forEach(({ grow: n }, s) => {
20
+ t[s].factor = n;
21
+ }) : o < 0 && r.forEach(({ shrink: n }, s) => {
22
+ t[s].factor = n;
23
+ });
24
+ for (const n of t)
25
+ n.factor === 0 && (n.frozen = !0);
26
+ for (; t.some(({ frozen: n }) => !n); ) {
27
+ const n = t.reduce(
28
+ (i, c) => i + (c.frozen ? 0 : c.factor),
29
+ 0
30
+ );
31
+ let s = 0;
32
+ for (const i of t)
33
+ i.frozen || (i.size += o * i.factor / n, i.size < i.minWidth ? i.violation = i.minWidth - i.size : i.maxWidth !== void 0 && i.size > i.maxWidth ? i.violation = i.maxWidth - i.size : i.violation = 0, i.size += i.violation, s += i.violation);
34
+ if (s > 0)
35
+ for (const i of t)
36
+ i.violation > 0 && (i.frozen = !0);
37
+ else if (s < 0)
38
+ for (const i of t)
39
+ i.violation < 0 && (i.frozen = !0);
40
+ else
41
+ break;
42
+ o = t.reduce((i, c) => i - c.size, e);
43
+ }
44
+ return t.map(({ size: n }) => n);
45
+ }, Fn = (e, r) => {
46
+ const t = e.map(
47
+ ({ basis: o, minWidth: n, maxWidth: s, grow: i, shrink: c }) => [o, n, s, i, c].join(",")
48
+ ).join("|");
49
+ return ge(() => {
50
+ if (r === void 0)
51
+ return {
52
+ fullWidth: !1,
53
+ columnWidths: void 0,
54
+ columnRights: void 0,
55
+ totalWidth: void 0
56
+ };
57
+ const o = zn(r, e);
58
+ let n = 0;
59
+ const s = o.map((i, c) => (n += i, c === o.length - 1 ? 1 / 0 : n));
60
+ return {
61
+ fullWidth: Math.abs(r - n) < 0.1,
62
+ columnWidths: o,
63
+ columnRights: s,
64
+ totalWidth: n
65
+ };
66
+ }, [r, t]);
67
+ };
68
+ var Le = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
69
+ function Ge(e) {
70
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
71
+ }
72
+ var nt, Rt;
73
+ function Et() {
74
+ if (Rt) return nt;
75
+ Rt = 1;
76
+ function e(r) {
77
+ var t = typeof r;
78
+ return r != null && (t == "object" || t == "function");
79
+ }
80
+ return nt = e, nt;
81
+ }
82
+ var rt, Mt;
83
+ function Vn() {
84
+ if (Mt) return rt;
85
+ Mt = 1;
86
+ var e = typeof Le == "object" && Le && Le.Object === Object && Le;
87
+ return rt = e, rt;
88
+ }
89
+ var ot, At;
90
+ function sn() {
91
+ if (At) return ot;
92
+ At = 1;
93
+ var e = Vn(), r = typeof self == "object" && self && self.Object === Object && self, t = e || r || Function("return this")();
94
+ return ot = t, ot;
95
+ }
96
+ var st, _t;
97
+ function jn() {
98
+ if (_t) return st;
99
+ _t = 1;
100
+ var e = sn(), r = function() {
101
+ return e.Date.now();
102
+ };
103
+ return st = r, st;
104
+ }
105
+ var it, zt;
106
+ function kn() {
107
+ if (zt) return it;
108
+ zt = 1;
109
+ var e = /\s/;
110
+ function r(t) {
111
+ for (var o = t.length; o-- && e.test(t.charAt(o)); )
112
+ ;
113
+ return o;
114
+ }
115
+ return it = r, it;
116
+ }
117
+ var lt, Ft;
118
+ function Pn() {
119
+ if (Ft) return lt;
120
+ Ft = 1;
121
+ var e = kn(), r = /^\s+/;
122
+ function t(o) {
123
+ return o && o.slice(0, e(o) + 1).replace(r, "");
124
+ }
125
+ return lt = t, lt;
126
+ }
127
+ var ct, Vt;
128
+ function ln() {
129
+ if (Vt) return ct;
130
+ Vt = 1;
131
+ var e = sn(), r = e.Symbol;
132
+ return ct = r, ct;
133
+ }
134
+ var at, jt;
135
+ function Ln() {
136
+ if (jt) return at;
137
+ jt = 1;
138
+ var e = ln(), r = Object.prototype, t = r.hasOwnProperty, o = r.toString, n = e ? e.toStringTag : void 0;
139
+ function s(i) {
140
+ var c = t.call(i, n), d = i[n];
141
+ try {
142
+ i[n] = void 0;
143
+ var f = !0;
144
+ } catch {
145
+ }
146
+ var p = o.call(i);
147
+ return f && (c ? i[n] = d : delete i[n]), p;
148
+ }
149
+ return at = s, at;
150
+ }
151
+ var ut, kt;
152
+ function Wn() {
153
+ if (kt) return ut;
154
+ kt = 1;
155
+ var e = Object.prototype, r = e.toString;
156
+ function t(o) {
157
+ return r.call(o);
158
+ }
159
+ return ut = t, ut;
160
+ }
161
+ var ft, Pt;
162
+ function qn() {
163
+ if (Pt) return ft;
164
+ Pt = 1;
165
+ var e = ln(), r = Ln(), t = Wn(), o = "[object Null]", n = "[object Undefined]", s = e ? e.toStringTag : void 0;
166
+ function i(c) {
167
+ return c == null ? c === void 0 ? n : o : s && s in Object(c) ? r(c) : t(c);
168
+ }
169
+ return ft = i, ft;
170
+ }
171
+ var dt, Lt;
172
+ function Bn() {
173
+ if (Lt) return dt;
174
+ Lt = 1;
175
+ function e(r) {
176
+ return r != null && typeof r == "object";
177
+ }
178
+ return dt = e, dt;
179
+ }
180
+ var ht, Wt;
181
+ function Kn() {
182
+ if (Wt) return ht;
183
+ Wt = 1;
184
+ var e = qn(), r = Bn(), t = "[object Symbol]";
185
+ function o(n) {
186
+ return typeof n == "symbol" || r(n) && e(n) == t;
187
+ }
188
+ return ht = o, ht;
189
+ }
190
+ var mt, qt;
191
+ function Un() {
192
+ if (qt) return mt;
193
+ qt = 1;
194
+ var e = Pn(), r = Et(), t = Kn(), o = NaN, n = /^[-+]0x[0-9a-f]+$/i, s = /^0b[01]+$/i, i = /^0o[0-7]+$/i, c = parseInt;
195
+ function d(f) {
196
+ if (typeof f == "number")
197
+ return f;
198
+ if (t(f))
199
+ return o;
200
+ if (r(f)) {
201
+ var p = typeof f.valueOf == "function" ? f.valueOf() : f;
202
+ f = r(p) ? p + "" : p;
203
+ }
204
+ if (typeof f != "string")
205
+ return f === 0 ? f : +f;
206
+ f = e(f);
207
+ var I = s.test(f);
208
+ return I || i.test(f) ? c(f.slice(2), I ? 2 : 8) : n.test(f) ? o : +f;
209
+ }
210
+ return mt = d, mt;
211
+ }
212
+ var pt, Bt;
213
+ function cn() {
214
+ if (Bt) return pt;
215
+ Bt = 1;
216
+ var e = Et(), r = jn(), t = Un(), o = "Expected a function", n = Math.max, s = Math.min;
217
+ function i(c, d, f) {
218
+ var p, I, m, D, y, N, F = 0, W = !1, O = !1, C = !0;
219
+ if (typeof c != "function")
220
+ throw new TypeError(o);
221
+ d = t(d) || 0, e(f) && (W = !!f.leading, O = "maxWait" in f, m = O ? n(t(f.maxWait) || 0, d) : m, C = "trailing" in f ? !!f.trailing : C);
222
+ function R(L) {
223
+ var b = p, A = I;
224
+ return p = I = void 0, F = L, D = c.apply(A, b), D;
225
+ }
226
+ function q(L) {
227
+ return F = L, y = setTimeout(oe, d), W ? R(L) : D;
228
+ }
229
+ function V(L) {
230
+ var b = L - N, A = L - F, fe = d - b;
231
+ return O ? s(fe, m - A) : fe;
232
+ }
233
+ function ae(L) {
234
+ var b = L - N, A = L - F;
235
+ return N === void 0 || b >= d || b < 0 || O && A >= m;
236
+ }
237
+ function oe() {
238
+ var L = r();
239
+ if (ae(L))
240
+ return P(L);
241
+ y = setTimeout(oe, V(L));
242
+ }
243
+ function P(L) {
244
+ return y = void 0, C && p ? R(L) : (p = I = void 0, D);
245
+ }
246
+ function Q() {
247
+ y !== void 0 && clearTimeout(y), F = 0, p = N = I = y = void 0;
248
+ }
249
+ function Ae() {
250
+ return y === void 0 ? D : P(r());
251
+ }
252
+ function se() {
253
+ var L = r(), b = ae(L);
254
+ if (p = arguments, I = this, N = L, b) {
255
+ if (y === void 0)
256
+ return q(N);
257
+ if (O)
258
+ return clearTimeout(y), y = setTimeout(oe, d), R(N);
259
+ }
260
+ return y === void 0 && (y = setTimeout(oe, d)), D;
261
+ }
262
+ return se.cancel = Q, se.flush = Ae, se;
263
+ }
264
+ return pt = i, pt;
265
+ }
266
+ var $n = cn();
267
+ const Gn = /* @__PURE__ */ Ge($n);
268
+ var gt, Kt;
269
+ function Xn() {
270
+ if (Kt) return gt;
271
+ Kt = 1;
272
+ var e = cn(), r = Et(), t = "Expected a function";
273
+ function o(n, s, i) {
274
+ var c = !0, d = !0;
275
+ if (typeof n != "function")
276
+ throw new TypeError(t);
277
+ return r(i) && (c = "leading" in i ? !!i.leading : c, d = "trailing" in i ? !!i.trailing : d), e(n, s, {
278
+ leading: c,
279
+ maxWait: s,
280
+ trailing: d
281
+ });
282
+ }
283
+ return gt = o, gt;
284
+ }
285
+ var Yn = Xn();
286
+ const Zn = /* @__PURE__ */ Ge(Yn), Jn = (e, r, t, o) => {
287
+ switch (r) {
288
+ case "debounce":
289
+ return Gn(e, t, o);
290
+ case "throttle":
291
+ return Zn(e, t, o);
292
+ default:
293
+ return e;
294
+ }
295
+ };
296
+ function Qn({ skipOnMount: e = !1, refreshMode: r, refreshRate: t = 1e3, refreshOptions: o, handleWidth: n = !0, handleHeight: s = !0, targetRef: i, observerOptions: c, onResize: d } = {}) {
297
+ const f = K(e), [p, I] = re({
298
+ width: void 0,
299
+ height: void 0
300
+ }), [m, D] = re(i?.current || null);
301
+ i && setTimeout(() => {
302
+ i.current !== m && D(i.current);
303
+ }, 0);
304
+ const y = ge(() => new Proxy((O) => {
305
+ O !== m && D(O);
306
+ }, {
307
+ get(O, C) {
308
+ return C === "current" ? m : O[C];
309
+ },
310
+ set(O, C, R) {
311
+ return C === "current" ? D(R) : O[C] = R, !0;
312
+ }
313
+ }), [m]), N = k((O, C) => !(O.width === C.width && O.height === C.height || O.width === C.width && !s || O.height === C.height && !n), [n, s]), F = k((O) => {
314
+ if (!(!n && !s)) {
315
+ if (f.current) {
316
+ f.current = !1;
317
+ return;
318
+ }
319
+ O.forEach((C) => {
320
+ const { width: R, height: q } = C?.contentRect || {};
321
+ I((V) => N(V, { width: R, height: q }) ? { width: R, height: q } : V);
322
+ });
323
+ }
324
+ }, [n, s, f, N]), W = k(Jn(F, r, t, o), [
325
+ F,
326
+ r,
327
+ t,
328
+ o
329
+ ]);
330
+ return J(() => {
331
+ let O;
332
+ return m ? (O = new window.ResizeObserver(W), O.observe(m, c)) : (p.width || p.height) && I({ width: void 0, height: void 0 }), () => {
333
+ var C, R, q;
334
+ (C = O?.disconnect) === null || C === void 0 || C.call(O), (q = (R = W).cancel) === null || q === void 0 || q.call(R);
335
+ };
336
+ }, [W, m]), J(() => {
337
+ d?.(p.width, p.height);
338
+ }, [p]), Object.assign({ ref: y }, p);
339
+ }
340
+ const Hn = () => /* @__PURE__ */ S(ne, {}), er = () => !1, Ut = ({ rowData: e }) => e, tr = () => null, nr = ({ rowIndex: e }) => /* @__PURE__ */ S(ne, { children: e + 1 }), wt = () => !0, rr = (e) => e, or = (e) => {
341
+ if (typeof e == "number")
342
+ return {
343
+ basis: 0,
344
+ grow: e,
345
+ shrink: 1
346
+ };
347
+ if (e.match(/^ *\d+(\.\d*)? *$/))
348
+ return {
349
+ basis: 0,
350
+ grow: parseFloat(e.trim()),
351
+ shrink: 1
352
+ };
353
+ if (e.match(/^ *\d+(\.\d*)? *px *$/))
354
+ return {
355
+ basis: parseFloat(e.trim()),
356
+ grow: 1,
357
+ shrink: 1
358
+ };
359
+ if (e.match(/^ *\d+(\.\d*)? \d+(\.\d*)? *$/)) {
360
+ const [r, t] = e.trim().split(" ");
361
+ return {
362
+ basis: 0,
363
+ grow: parseFloat(r),
364
+ shrink: parseFloat(t)
365
+ };
366
+ }
367
+ if (e.match(/^ *\d+(\.\d*)? \d+(\.\d*)? *px *$/)) {
368
+ const [r, t] = e.trim().split(" ");
369
+ return {
370
+ basis: parseFloat(t),
371
+ grow: parseFloat(r),
372
+ shrink: 1
373
+ };
374
+ }
375
+ if (e.match(/^ *\d+(\.\d*)? \d+(\.\d*)? \d+(\.\d*)? *px *$/)) {
376
+ const [r, t, o] = e.trim().split(" ");
377
+ return {
378
+ basis: parseFloat(o),
379
+ grow: parseFloat(r),
380
+ shrink: parseFloat(t)
381
+ };
382
+ }
383
+ return {
384
+ basis: 0,
385
+ grow: 1,
386
+ shrink: 1
387
+ };
388
+ }, sr = (e, r, t) => ge(() => {
389
+ const o = [
390
+ r === !1 ? {
391
+ basis: 0,
392
+ grow: 0,
393
+ shrink: 0,
394
+ minWidth: 0,
395
+ // eslint-disable-next-line react/display-name
396
+ component: () => /* @__PURE__ */ S(ne, {}),
397
+ headerClassName: "dsg-hidden-cell",
398
+ cellClassName: "dsg-hidden-cell",
399
+ isCellEmpty: wt
400
+ } : {
401
+ ...r,
402
+ basis: r?.basis ?? 40,
403
+ grow: r?.grow ?? 0,
404
+ shrink: r?.shrink ?? 0,
405
+ minWidth: r?.minWidth ?? 0,
406
+ title: r?.title ?? /* @__PURE__ */ S("div", { className: "dsg-corner-indicator" }),
407
+ component: r?.component ?? nr,
408
+ isCellEmpty: wt
409
+ },
410
+ ...e
411
+ ];
412
+ return t && o.push({
413
+ ...t,
414
+ basis: t?.basis ?? 40,
415
+ grow: t?.grow ?? 0,
416
+ shrink: t?.shrink ?? 0,
417
+ minWidth: t.minWidth ?? 0,
418
+ isCellEmpty: wt
419
+ }), o.map((n) => {
420
+ const s = n.width !== void 0 ? or(n.width) : {
421
+ basis: void 0,
422
+ grow: void 0,
423
+ shrink: void 0
424
+ };
425
+ return {
426
+ ...n,
427
+ basis: n.basis ?? s.basis ?? 0,
428
+ grow: n.grow ?? s.grow ?? 1,
429
+ shrink: n.shrink ?? s.shrink ?? 1,
430
+ minWidth: n.minWidth ?? 100,
431
+ component: n.component ?? Hn,
432
+ disableKeys: n.disableKeys ?? !1,
433
+ disabled: n.disabled ?? !1,
434
+ keepFocus: n.keepFocus ?? !1,
435
+ deleteValue: n.deleteValue ?? Ut,
436
+ copyValue: n.copyValue ?? tr,
437
+ pasteValue: n.pasteValue ?? Ut,
438
+ prePasteValues: n.prePasteValues ?? rr,
439
+ isCellEmpty: n.isCellEmpty ?? er
440
+ };
441
+ });
442
+ }, [r, t, e]);
443
+ function Ue(e, r, t, o) {
444
+ var n, s = !1, i = 0;
445
+ function c() {
446
+ n && clearTimeout(n);
447
+ }
448
+ function d() {
449
+ c(), s = !0;
450
+ }
451
+ typeof r != "boolean" && (o = t, t = r, r = void 0);
452
+ function f() {
453
+ for (var p = arguments.length, I = new Array(p), m = 0; m < p; m++)
454
+ I[m] = arguments[m];
455
+ var D = this, y = Date.now() - i;
456
+ if (s)
457
+ return;
458
+ function N() {
459
+ i = Date.now(), t.apply(D, I);
460
+ }
461
+ function F() {
462
+ n = void 0;
463
+ }
464
+ o && !n && N(), c(), o === void 0 && y > e ? N() : r !== !0 && (n = setTimeout(o ? F : N, o === void 0 ? e - y : e));
465
+ }
466
+ return f.cancel = d, f;
467
+ }
468
+ function ir(e, r, t) {
469
+ return t === void 0 ? Ue(e, r, !1) : Ue(e, t, r !== !1);
470
+ }
471
+ var bt, $t;
472
+ function lr() {
473
+ return $t || ($t = 1, bt = function e(r, t) {
474
+ if (r === t) return !0;
475
+ if (r && t && typeof r == "object" && typeof t == "object") {
476
+ if (r.constructor !== t.constructor) return !1;
477
+ var o, n, s;
478
+ if (Array.isArray(r)) {
479
+ if (o = r.length, o != t.length) return !1;
480
+ for (n = o; n-- !== 0; )
481
+ if (!e(r[n], t[n])) return !1;
482
+ return !0;
483
+ }
484
+ if (r.constructor === RegExp) return r.source === t.source && r.flags === t.flags;
485
+ if (r.valueOf !== Object.prototype.valueOf) return r.valueOf() === t.valueOf();
486
+ if (r.toString !== Object.prototype.toString) return r.toString() === t.toString();
487
+ if (s = Object.keys(r), o = s.length, o !== Object.keys(t).length) return !1;
488
+ for (n = o; n-- !== 0; )
489
+ if (!Object.prototype.hasOwnProperty.call(t, s[n])) return !1;
490
+ for (n = o; n-- !== 0; ) {
491
+ var i = s[n];
492
+ if (!e(r[i], t[i])) return !1;
493
+ }
494
+ return !0;
495
+ }
496
+ return r !== r && t !== t;
497
+ }), bt;
498
+ }
499
+ var cr = lr();
500
+ const an = /* @__PURE__ */ Ge(cr), Be = (e) => {
501
+ const [r, t] = re(e), o = k(
502
+ (n) => {
503
+ t((s) => {
504
+ const i = typeof n == "function" ? n(s) : n;
505
+ return an(i, s) ? s : i;
506
+ });
507
+ },
508
+ [t]
509
+ );
510
+ return [r, o];
511
+ }, ar = (e, r, t) => {
512
+ const [o, n] = Be({
513
+ top: !0,
514
+ right: !0,
515
+ bottom: !0,
516
+ left: !0
517
+ });
518
+ return J(() => {
519
+ const s = Ue(100, () => {
520
+ n({
521
+ top: e.current?.scrollTop === 0,
522
+ right: (e.current?.scrollLeft ?? 0) >= (e.current?.scrollWidth ?? 0) - (r ?? 0) - 1,
523
+ bottom: (e.current?.scrollTop ?? 0) >= (e.current?.scrollHeight ?? 0) - (t ?? 0) - 1,
524
+ left: e.current?.scrollLeft === 0
525
+ });
526
+ }), i = e.current;
527
+ return i?.addEventListener("scroll", s), setTimeout(s, 100), () => {
528
+ i?.removeEventListener("scroll", s), s.cancel();
529
+ };
530
+ }, [t, r, e, n]), o;
531
+ }, pe = (e, r) => {
532
+ J(() => (document.addEventListener(e, r), () => {
533
+ document.removeEventListener(e, r);
534
+ }), [r, e]);
535
+ }, Gt = (e, r = 200) => {
536
+ const t = K(null), o = ge(
537
+ () => Ue(r, !0, () => {
538
+ setTimeout(
539
+ () => t.current = e.current?.getBoundingClientRect() || null,
540
+ 0
541
+ );
542
+ }),
543
+ [e, r]
544
+ );
545
+ return k(
546
+ (n = !1) => (n ? t.current = e.current?.getBoundingClientRect() || null : o(), t.current),
547
+ [e, o]
548
+ );
549
+ }, ur = (e = {}) => (
550
+ // eslint-disable-next-line react/display-name
551
+ (({ addRows: r }) => {
552
+ const [t, o] = re(1), [n, s] = re(String(t));
553
+ return /* @__PURE__ */ Me("div", { className: "dsg-add-row", children: [
554
+ /* @__PURE__ */ S(
555
+ "button",
556
+ {
557
+ type: "button",
558
+ className: "dsg-add-row-btn",
559
+ onClick: () => r(t),
560
+ children: e.button ?? "Add"
561
+ }
562
+ ),
563
+ " ",
564
+ /* @__PURE__ */ S(
565
+ "input",
566
+ {
567
+ className: "dsg-add-row-input",
568
+ value: n,
569
+ onBlur: () => s(String(t)),
570
+ type: "number",
571
+ min: 1,
572
+ onChange: (i) => {
573
+ s(i.target.value), o(Math.max(1, Math.round(parseInt(i.target.value) || 0)));
574
+ },
575
+ onKeyDown: (i) => {
576
+ i.key === "Enter" && r(t);
577
+ }
578
+ }
579
+ ),
580
+ " ",
581
+ e.unit ?? "rows"
582
+ ] });
583
+ })
584
+ ), un = ur();
585
+ un.displayName = "AddRows";
586
+ const fr = (e, r) => {
587
+ const [t, o] = re(e), n = K();
588
+ J(() => () => n.current?.cancel(), []);
589
+ const s = ge(
590
+ () => n.current = ir(r, (i) => {
591
+ o(i);
592
+ }),
593
+ [r]
594
+ );
595
+ return [t, s];
596
+ }, fn = (e) => e.type === "CUT" ? /* @__PURE__ */ S(ne, { children: "Cut" }) : e.type === "COPY" ? /* @__PURE__ */ S(ne, { children: "Copy" }) : e.type === "PASTE" ? /* @__PURE__ */ S(ne, { children: "Paste" }) : e.type === "DELETE_ROW" ? /* @__PURE__ */ S(ne, { children: "Delete row" }) : e.type === "DELETE_ROWS" ? /* @__PURE__ */ Me(ne, { children: [
597
+ "Delete rows ",
598
+ /* @__PURE__ */ S("b", { children: e.fromRow }),
599
+ " to ",
600
+ /* @__PURE__ */ S("b", { children: e.toRow })
601
+ ] }) : e.type === "INSERT_ROW_BELLOW" ? /* @__PURE__ */ S(ne, { children: "Insert row below" }) : e.type === "DUPLICATE_ROW" ? /* @__PURE__ */ S(ne, { children: "Duplicate row" }) : e.type === "DUPLICATE_ROWS" ? /* @__PURE__ */ Me(ne, { children: [
602
+ "Duplicate rows ",
603
+ /* @__PURE__ */ S("b", { children: e.fromRow }),
604
+ " to ",
605
+ /* @__PURE__ */ S("b", { children: e.toRow })
606
+ ] }) : e.type, dr = (e = fn) => (
607
+ // eslint-disable-next-line react/display-name
608
+ (({ clientX: r, clientY: t, items: o, close: n }) => {
609
+ const s = K(null), i = k(
610
+ (c) => {
611
+ s.current?.contains(c.target) || n();
612
+ },
613
+ [n]
614
+ );
615
+ return pe("mousedown", i), /* @__PURE__ */ S(
616
+ "div",
617
+ {
618
+ className: "dsg-context-menu",
619
+ style: { left: r + "px", top: t + "px" },
620
+ ref: s,
621
+ children: o.map((c) => /* @__PURE__ */ S(
622
+ "div",
623
+ {
624
+ onClick: c.action,
625
+ className: "dsg-context-menu-item",
626
+ children: e(c)
627
+ },
628
+ c.type
629
+ ))
630
+ }
631
+ );
632
+ })
633
+ ), dn = dr(fn);
634
+ dn.displayName = "ContextMenu";
635
+ const hr = typeof DOMParser < "u" ? new DOMParser() : { parseFromString: () => null }, mr = (e) => hr.parseFromString(e, "text/html"), xt = (e) => {
636
+ const r = mr(e.replace(/<br\/?>/g, `
637
+ `)), t = r.getElementsByTagName("table")[0];
638
+ if (t) {
639
+ const n = [];
640
+ for (let s = 0; s < t.rows.length; s++) {
641
+ const i = [];
642
+ n.push(i);
643
+ for (let c = 0; c < t.rows[s].cells.length; c++)
644
+ i.push(t.rows[s].cells[c].textContent ?? "");
645
+ }
646
+ return n;
647
+ }
648
+ const o = r.getElementsByTagName("span")[0];
649
+ return o ? [[o.textContent ?? ""]] : [[""]];
650
+ }, We = (e) => {
651
+ const r = e.replace(/\r|\n$/g, ""), t = [[]];
652
+ let o = 0, n = 0, s = !1, i = 0;
653
+ const c = () => {
654
+ let d = r.slice(n, o);
655
+ d[0] === '"' && d[d.length - 1] === '"' && (s = !0), s && d[d.length - 1] === '"' && d.includes(`
656
+ `) && (d = d.slice(1, d.length - 1).replace(/""/g, '"'), s = !1), s && d[d.length - 1] !== '"' ? d.split(`
657
+ `).forEach((f, p, { length: I }) => {
658
+ t[i].push(f), p < I - 1 && (t.push([]), i++);
659
+ }) : t[i].push(d);
660
+ };
661
+ for (; o < r.length; )
662
+ s && r[o] === '"' && ![void 0, " ", '"'].includes(r[o + 1]) && (s = !1), s && r[o] === '"' && r[o + 1] === '"' && o++, o === n && r[o] === '"' && (s = !0), r[o] === " " && (c(), n = o + 1, s = !1), r[o] === `
663
+ ` && !s && (c(), t.push([]), n = o + 1, i++), o++;
664
+ return c(), t;
665
+ }, pr = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;"), gr = (e) => e.match(/^[^\x00-\x20\x7F-\x9F]$/) !== null, vt = (e, r, t, o) => {
666
+ if (e === null || !r || !t)
667
+ return null;
668
+ if (typeof e != "object")
669
+ throw new Error("Value must be an object or null");
670
+ const n = o.findIndex((i) => i.id === e.col), s = {
671
+ col: Math.max(
672
+ 0,
673
+ Math.min(r - 1, n === -1 ? Number(e.col) : n - 1)
674
+ ),
675
+ row: Math.max(0, Math.min(t - 1, Number(e.row)))
676
+ };
677
+ if (isNaN(s.col) || isNaN(s.row))
678
+ throw new Error("col or cell are not valid positive numbers");
679
+ return s;
680
+ }, Re = (e, r) => e ? {
681
+ col: e.col,
682
+ row: e.row,
683
+ colId: r[e.col + 1]?.id
684
+ } : null, wr = (e, r, t, o) => {
685
+ if (e === null || !r || !t)
686
+ return null;
687
+ if (typeof e != "object")
688
+ throw new Error("Value must be an object or null");
689
+ const n = {
690
+ min: vt(e.min, r, t, o),
691
+ max: vt(e.max, r, t, o)
692
+ };
693
+ if (!n.min || !n.max)
694
+ throw new Error("min and max must be defined");
695
+ return n;
696
+ }, Xt = (e, r) => e ? {
697
+ min: Re(e.min, r),
698
+ max: Re(e.max, r)
699
+ } : null, Yt = () => Array.from(document.querySelectorAll("*")).filter((e) => e instanceof HTMLElement && typeof e.tabIndex == "number" && e.tabIndex >= 0 && !e.disabled && (!(e instanceof HTMLAnchorElement) || !!e.href || e.getAttribute("tabIndex") !== null) && getComputedStyle(e).visibility !== "collapse");
700
+ function Ne(e, r, t) {
701
+ let o = t.initialDeps ?? [], n, s = !0;
702
+ function i() {
703
+ var c, d, f;
704
+ let p;
705
+ t.key && ((c = t.debug) != null && c.call(t)) && (p = Date.now());
706
+ const I = e();
707
+ if (!(I.length !== o.length || I.some((y, N) => o[N] !== y)))
708
+ return n;
709
+ o = I;
710
+ let D;
711
+ if (t.key && ((d = t.debug) != null && d.call(t)) && (D = Date.now()), n = r(...I), t.key && ((f = t.debug) != null && f.call(t))) {
712
+ const y = Math.round((Date.now() - p) * 100) / 100, N = Math.round((Date.now() - D) * 100) / 100, F = N / 16, W = (O, C) => {
713
+ for (O = String(O); O.length < C; )
714
+ O = " " + O;
715
+ return O;
716
+ };
717
+ console.info(
718
+ `%c⏱ ${W(N, 5)} /${W(y, 5)} ms`,
719
+ `
720
+ font-size: .6rem;
721
+ font-weight: bold;
722
+ color: hsl(${Math.max(
723
+ 0,
724
+ Math.min(120 - 120 * F, 120)
725
+ )}deg 100% 31%);`,
726
+ t?.key
727
+ );
728
+ }
729
+ return t?.onChange && !(s && t.skipInitialOnChange) && t.onChange(n), s = !1, n;
730
+ }
731
+ return i.updateDeps = (c) => {
732
+ o = c;
733
+ }, i;
734
+ }
735
+ function Zt(e, r) {
736
+ if (e === void 0)
737
+ throw new Error("Unexpected undefined");
738
+ return e;
739
+ }
740
+ const br = (e, r) => Math.abs(e - r) < 1.01, xr = (e, r, t) => {
741
+ let o;
742
+ return function(...n) {
743
+ e.clearTimeout(o), o = e.setTimeout(() => r.apply(this, n), t);
744
+ };
745
+ }, Jt = (e) => {
746
+ const { offsetWidth: r, offsetHeight: t } = e;
747
+ return { width: r, height: t };
748
+ }, yr = (e) => e, hn = (e) => {
749
+ const r = Math.max(e.startIndex - e.overscan, 0), t = Math.min(e.endIndex + e.overscan, e.count - 1), o = [];
750
+ for (let n = r; n <= t; n++)
751
+ o.push(n);
752
+ return o;
753
+ }, vr = (e, r) => {
754
+ const t = e.scrollElement;
755
+ if (!t)
756
+ return;
757
+ const o = e.targetWindow;
758
+ if (!o)
759
+ return;
760
+ const n = (i) => {
761
+ const { width: c, height: d } = i;
762
+ r({ width: Math.round(c), height: Math.round(d) });
763
+ };
764
+ if (n(Jt(t)), !o.ResizeObserver)
765
+ return () => {
766
+ };
767
+ const s = new o.ResizeObserver((i) => {
768
+ const c = () => {
769
+ const d = i[0];
770
+ if (d?.borderBoxSize) {
771
+ const f = d.borderBoxSize[0];
772
+ if (f) {
773
+ n({ width: f.inlineSize, height: f.blockSize });
774
+ return;
775
+ }
776
+ }
777
+ n(Jt(t));
778
+ };
779
+ e.options.useAnimationFrameWithResizeObserver ? requestAnimationFrame(c) : c();
780
+ });
781
+ return s.observe(t, { box: "border-box" }), () => {
782
+ s.unobserve(t);
783
+ };
784
+ }, Qt = {
785
+ passive: !0
786
+ }, Ht = typeof window > "u" ? !0 : "onscrollend" in window, Er = (e, r) => {
787
+ const t = e.scrollElement;
788
+ if (!t)
789
+ return;
790
+ const o = e.targetWindow;
791
+ if (!o)
792
+ return;
793
+ let n = 0;
794
+ const s = e.options.useScrollendEvent && Ht ? () => {
795
+ } : xr(
796
+ o,
797
+ () => {
798
+ r(n, !1);
799
+ },
800
+ e.options.isScrollingResetDelay
801
+ ), i = (p) => () => {
802
+ const { horizontal: I, isRtl: m } = e.options;
803
+ n = I ? t.scrollLeft * (m && -1 || 1) : t.scrollTop, s(), r(n, p);
804
+ }, c = i(!0), d = i(!1);
805
+ t.addEventListener("scroll", c, Qt);
806
+ const f = e.options.useScrollendEvent && Ht;
807
+ return f && t.addEventListener("scrollend", d, Qt), () => {
808
+ t.removeEventListener("scroll", c), f && t.removeEventListener("scrollend", d);
809
+ };
810
+ }, Sr = (e, r, t) => {
811
+ if (r?.borderBoxSize) {
812
+ const o = r.borderBoxSize[0];
813
+ if (o)
814
+ return Math.round(
815
+ o[t.options.horizontal ? "inlineSize" : "blockSize"]
816
+ );
817
+ }
818
+ return e[t.options.horizontal ? "offsetWidth" : "offsetHeight"];
819
+ }, Ir = (e, {
820
+ adjustments: r = 0,
821
+ behavior: t
822
+ }, o) => {
823
+ var n, s;
824
+ const i = e + r;
825
+ (s = (n = o.scrollElement) == null ? void 0 : n.scrollTo) == null || s.call(n, {
826
+ [o.options.horizontal ? "left" : "top"]: i,
827
+ behavior: t
828
+ });
829
+ };
830
+ class Tr {
831
+ constructor(r) {
832
+ this.unsubs = [], this.scrollElement = null, this.targetWindow = null, this.isScrolling = !1, this.currentScrollToIndex = null, this.measurementsCache = [], this.itemSizeCache = /* @__PURE__ */ new Map(), this.laneAssignments = /* @__PURE__ */ new Map(), this.pendingMeasuredCacheIndexes = [], this.prevLanes = void 0, this.lanesChangedFlag = !1, this.lanesSettling = !1, this.scrollRect = null, this.scrollOffset = null, this.scrollDirection = null, this.scrollAdjustments = 0, this.elementsCache = /* @__PURE__ */ new Map(), this.observer = /* @__PURE__ */ (() => {
833
+ let t = null;
834
+ const o = () => t || (!this.targetWindow || !this.targetWindow.ResizeObserver ? null : t = new this.targetWindow.ResizeObserver((n) => {
835
+ n.forEach((s) => {
836
+ const i = () => {
837
+ this._measureElement(s.target, s);
838
+ };
839
+ this.options.useAnimationFrameWithResizeObserver ? requestAnimationFrame(i) : i();
840
+ });
841
+ }));
842
+ return {
843
+ disconnect: () => {
844
+ var n;
845
+ (n = o()) == null || n.disconnect(), t = null;
846
+ },
847
+ observe: (n) => {
848
+ var s;
849
+ return (s = o()) == null ? void 0 : s.observe(n, { box: "border-box" });
850
+ },
851
+ unobserve: (n) => {
852
+ var s;
853
+ return (s = o()) == null ? void 0 : s.unobserve(n);
854
+ }
855
+ };
856
+ })(), this.range = null, this.setOptions = (t) => {
857
+ Object.entries(t).forEach(([o, n]) => {
858
+ typeof n > "u" && delete t[o];
859
+ }), this.options = {
860
+ debug: !1,
861
+ initialOffset: 0,
862
+ overscan: 1,
863
+ paddingStart: 0,
864
+ paddingEnd: 0,
865
+ scrollPaddingStart: 0,
866
+ scrollPaddingEnd: 0,
867
+ horizontal: !1,
868
+ getItemKey: yr,
869
+ rangeExtractor: hn,
870
+ onChange: () => {
871
+ },
872
+ measureElement: Sr,
873
+ initialRect: { width: 0, height: 0 },
874
+ scrollMargin: 0,
875
+ gap: 0,
876
+ indexAttribute: "data-index",
877
+ initialMeasurementsCache: [],
878
+ lanes: 1,
879
+ isScrollingResetDelay: 150,
880
+ enabled: !0,
881
+ isRtl: !1,
882
+ useScrollendEvent: !1,
883
+ useAnimationFrameWithResizeObserver: !1,
884
+ ...t
885
+ };
886
+ }, this.notify = (t) => {
887
+ var o, n;
888
+ (n = (o = this.options).onChange) == null || n.call(o, this, t);
889
+ }, this.maybeNotify = Ne(
890
+ () => (this.calculateRange(), [
891
+ this.isScrolling,
892
+ this.range ? this.range.startIndex : null,
893
+ this.range ? this.range.endIndex : null
894
+ ]),
895
+ (t) => {
896
+ this.notify(t);
897
+ },
898
+ {
899
+ key: process.env.NODE_ENV !== "production" && "maybeNotify",
900
+ debug: () => this.options.debug,
901
+ initialDeps: [
902
+ this.isScrolling,
903
+ this.range ? this.range.startIndex : null,
904
+ this.range ? this.range.endIndex : null
905
+ ]
906
+ }
907
+ ), this.cleanup = () => {
908
+ this.unsubs.filter(Boolean).forEach((t) => t()), this.unsubs = [], this.observer.disconnect(), this.scrollElement = null, this.targetWindow = null;
909
+ }, this._didMount = () => () => {
910
+ this.cleanup();
911
+ }, this._willUpdate = () => {
912
+ var t;
913
+ const o = this.options.enabled ? this.options.getScrollElement() : null;
914
+ if (this.scrollElement !== o) {
915
+ if (this.cleanup(), !o) {
916
+ this.maybeNotify();
917
+ return;
918
+ }
919
+ this.scrollElement = o, this.scrollElement && "ownerDocument" in this.scrollElement ? this.targetWindow = this.scrollElement.ownerDocument.defaultView : this.targetWindow = ((t = this.scrollElement) == null ? void 0 : t.window) ?? null, this.elementsCache.forEach((n) => {
920
+ this.observer.observe(n);
921
+ }), this.unsubs.push(
922
+ this.options.observeElementRect(this, (n) => {
923
+ this.scrollRect = n, this.maybeNotify();
924
+ })
925
+ ), this.unsubs.push(
926
+ this.options.observeElementOffset(this, (n, s) => {
927
+ this.scrollAdjustments = 0, this.scrollDirection = s ? this.getScrollOffset() < n ? "forward" : "backward" : null, this.scrollOffset = n, this.isScrolling = s, this.maybeNotify();
928
+ })
929
+ ), this._scrollToOffset(this.getScrollOffset(), {
930
+ adjustments: void 0,
931
+ behavior: void 0
932
+ });
933
+ }
934
+ }, this.getSize = () => this.options.enabled ? (this.scrollRect = this.scrollRect ?? this.options.initialRect, this.scrollRect[this.options.horizontal ? "width" : "height"]) : (this.scrollRect = null, 0), this.getScrollOffset = () => this.options.enabled ? (this.scrollOffset = this.scrollOffset ?? (typeof this.options.initialOffset == "function" ? this.options.initialOffset() : this.options.initialOffset), this.scrollOffset) : (this.scrollOffset = null, 0), this.getFurthestMeasurement = (t, o) => {
935
+ const n = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
936
+ for (let i = o - 1; i >= 0; i--) {
937
+ const c = t[i];
938
+ if (n.has(c.lane))
939
+ continue;
940
+ const d = s.get(
941
+ c.lane
942
+ );
943
+ if (d == null || c.end > d.end ? s.set(c.lane, c) : c.end < d.end && n.set(c.lane, !0), n.size === this.options.lanes)
944
+ break;
945
+ }
946
+ return s.size === this.options.lanes ? Array.from(s.values()).sort((i, c) => i.end === c.end ? i.index - c.index : i.end - c.end)[0] : void 0;
947
+ }, this.getMeasurementOptions = Ne(
948
+ () => [
949
+ this.options.count,
950
+ this.options.paddingStart,
951
+ this.options.scrollMargin,
952
+ this.options.getItemKey,
953
+ this.options.enabled,
954
+ this.options.lanes
955
+ ],
956
+ (t, o, n, s, i, c) => (this.prevLanes !== void 0 && this.prevLanes !== c && (this.lanesChangedFlag = !0), this.prevLanes = c, this.pendingMeasuredCacheIndexes = [], {
957
+ count: t,
958
+ paddingStart: o,
959
+ scrollMargin: n,
960
+ getItemKey: s,
961
+ enabled: i,
962
+ lanes: c
963
+ }),
964
+ {
965
+ key: !1
966
+ }
967
+ ), this.getMeasurements = Ne(
968
+ () => [this.getMeasurementOptions(), this.itemSizeCache],
969
+ ({ count: t, paddingStart: o, scrollMargin: n, getItemKey: s, enabled: i, lanes: c }, d) => {
970
+ if (!i)
971
+ return this.measurementsCache = [], this.itemSizeCache.clear(), this.laneAssignments.clear(), [];
972
+ if (this.laneAssignments.size > t)
973
+ for (const m of this.laneAssignments.keys())
974
+ m >= t && this.laneAssignments.delete(m);
975
+ this.lanesChangedFlag && (this.lanesChangedFlag = !1, this.lanesSettling = !0, this.measurementsCache = [], this.itemSizeCache.clear(), this.laneAssignments.clear(), this.pendingMeasuredCacheIndexes = []), this.measurementsCache.length === 0 && !this.lanesSettling && (this.measurementsCache = this.options.initialMeasurementsCache, this.measurementsCache.forEach((m) => {
976
+ this.itemSizeCache.set(m.key, m.size);
977
+ }));
978
+ const f = this.lanesSettling ? 0 : this.pendingMeasuredCacheIndexes.length > 0 ? Math.min(...this.pendingMeasuredCacheIndexes) : 0;
979
+ this.pendingMeasuredCacheIndexes = [], this.lanesSettling && this.measurementsCache.length === t && (this.lanesSettling = !1);
980
+ const p = this.measurementsCache.slice(0, f), I = new Array(c).fill(
981
+ void 0
982
+ );
983
+ for (let m = 0; m < f; m++) {
984
+ const D = p[m];
985
+ D && (I[D.lane] = m);
986
+ }
987
+ for (let m = f; m < t; m++) {
988
+ const D = s(m), y = this.laneAssignments.get(m);
989
+ let N, F;
990
+ if (y !== void 0 && this.options.lanes > 1) {
991
+ N = y;
992
+ const R = I[N], q = R !== void 0 ? p[R] : void 0;
993
+ F = q ? q.end + this.options.gap : o + n;
994
+ } else {
995
+ const R = this.options.lanes === 1 ? p[m - 1] : this.getFurthestMeasurement(p, m);
996
+ F = R ? R.end + this.options.gap : o + n, N = R ? R.lane : m % this.options.lanes, this.options.lanes > 1 && this.laneAssignments.set(m, N);
997
+ }
998
+ const W = d.get(D), O = typeof W == "number" ? W : this.options.estimateSize(m), C = F + O;
999
+ p[m] = {
1000
+ index: m,
1001
+ start: F,
1002
+ size: O,
1003
+ end: C,
1004
+ key: D,
1005
+ lane: N
1006
+ }, I[N] = m;
1007
+ }
1008
+ return this.measurementsCache = p, p;
1009
+ },
1010
+ {
1011
+ key: process.env.NODE_ENV !== "production" && "getMeasurements",
1012
+ debug: () => this.options.debug
1013
+ }
1014
+ ), this.calculateRange = Ne(
1015
+ () => [
1016
+ this.getMeasurements(),
1017
+ this.getSize(),
1018
+ this.getScrollOffset(),
1019
+ this.options.lanes
1020
+ ],
1021
+ (t, o, n, s) => this.range = t.length > 0 && o > 0 ? Cr({
1022
+ measurements: t,
1023
+ outerSize: o,
1024
+ scrollOffset: n,
1025
+ lanes: s
1026
+ }) : null,
1027
+ {
1028
+ key: process.env.NODE_ENV !== "production" && "calculateRange",
1029
+ debug: () => this.options.debug
1030
+ }
1031
+ ), this.getVirtualIndexes = Ne(
1032
+ () => {
1033
+ let t = null, o = null;
1034
+ const n = this.calculateRange();
1035
+ return n && (t = n.startIndex, o = n.endIndex), this.maybeNotify.updateDeps([this.isScrolling, t, o]), [
1036
+ this.options.rangeExtractor,
1037
+ this.options.overscan,
1038
+ this.options.count,
1039
+ t,
1040
+ o
1041
+ ];
1042
+ },
1043
+ (t, o, n, s, i) => s === null || i === null ? [] : t({
1044
+ startIndex: s,
1045
+ endIndex: i,
1046
+ overscan: o,
1047
+ count: n
1048
+ }),
1049
+ {
1050
+ key: process.env.NODE_ENV !== "production" && "getVirtualIndexes",
1051
+ debug: () => this.options.debug
1052
+ }
1053
+ ), this.indexFromElement = (t) => {
1054
+ const o = this.options.indexAttribute, n = t.getAttribute(o);
1055
+ return n ? parseInt(n, 10) : (console.warn(
1056
+ `Missing attribute name '${o}={index}' on measured element.`
1057
+ ), -1);
1058
+ }, this._measureElement = (t, o) => {
1059
+ const n = this.indexFromElement(t), s = this.measurementsCache[n];
1060
+ if (!s)
1061
+ return;
1062
+ const i = s.key, c = this.elementsCache.get(i);
1063
+ c !== t && (c && this.observer.unobserve(c), this.observer.observe(t), this.elementsCache.set(i, t)), t.isConnected && this.resizeItem(n, this.options.measureElement(t, o, this));
1064
+ }, this.resizeItem = (t, o) => {
1065
+ const n = this.measurementsCache[t];
1066
+ if (!n)
1067
+ return;
1068
+ const s = this.itemSizeCache.get(n.key) ?? n.size, i = o - s;
1069
+ i !== 0 && ((this.shouldAdjustScrollPositionOnItemSizeChange !== void 0 ? this.shouldAdjustScrollPositionOnItemSizeChange(n, i, this) : n.start < this.getScrollOffset() + this.scrollAdjustments) && (process.env.NODE_ENV !== "production" && this.options.debug && console.info("correction", i), this._scrollToOffset(this.getScrollOffset(), {
1070
+ adjustments: this.scrollAdjustments += i,
1071
+ behavior: void 0
1072
+ })), this.pendingMeasuredCacheIndexes.push(n.index), this.itemSizeCache = new Map(this.itemSizeCache.set(n.key, o)), this.notify(!1));
1073
+ }, this.measureElement = (t) => {
1074
+ if (!t) {
1075
+ this.elementsCache.forEach((o, n) => {
1076
+ o.isConnected || (this.observer.unobserve(o), this.elementsCache.delete(n));
1077
+ });
1078
+ return;
1079
+ }
1080
+ this._measureElement(t, void 0);
1081
+ }, this.getVirtualItems = Ne(
1082
+ () => [this.getVirtualIndexes(), this.getMeasurements()],
1083
+ (t, o) => {
1084
+ const n = [];
1085
+ for (let s = 0, i = t.length; s < i; s++) {
1086
+ const c = t[s], d = o[c];
1087
+ n.push(d);
1088
+ }
1089
+ return n;
1090
+ },
1091
+ {
1092
+ key: process.env.NODE_ENV !== "production" && "getVirtualItems",
1093
+ debug: () => this.options.debug
1094
+ }
1095
+ ), this.getVirtualItemForOffset = (t) => {
1096
+ const o = this.getMeasurements();
1097
+ if (o.length !== 0)
1098
+ return Zt(
1099
+ o[mn(
1100
+ 0,
1101
+ o.length - 1,
1102
+ (n) => Zt(o[n]).start,
1103
+ t
1104
+ )]
1105
+ );
1106
+ }, this.getMaxScrollOffset = () => {
1107
+ if (!this.scrollElement) return 0;
1108
+ if ("scrollHeight" in this.scrollElement)
1109
+ return this.options.horizontal ? this.scrollElement.scrollWidth - this.scrollElement.clientWidth : this.scrollElement.scrollHeight - this.scrollElement.clientHeight;
1110
+ {
1111
+ const t = this.scrollElement.document.documentElement;
1112
+ return this.options.horizontal ? t.scrollWidth - this.scrollElement.innerWidth : t.scrollHeight - this.scrollElement.innerHeight;
1113
+ }
1114
+ }, this.getOffsetForAlignment = (t, o, n = 0) => {
1115
+ if (!this.scrollElement) return 0;
1116
+ const s = this.getSize(), i = this.getScrollOffset();
1117
+ o === "auto" && (o = t >= i + s ? "end" : "start"), o === "center" ? t += (n - s) / 2 : o === "end" && (t -= s);
1118
+ const c = this.getMaxScrollOffset();
1119
+ return Math.max(Math.min(c, t), 0);
1120
+ }, this.getOffsetForIndex = (t, o = "auto") => {
1121
+ t = Math.max(0, Math.min(t, this.options.count - 1));
1122
+ const n = this.measurementsCache[t];
1123
+ if (!n)
1124
+ return;
1125
+ const s = this.getSize(), i = this.getScrollOffset();
1126
+ if (o === "auto")
1127
+ if (n.end >= i + s - this.options.scrollPaddingEnd)
1128
+ o = "end";
1129
+ else if (n.start <= i + this.options.scrollPaddingStart)
1130
+ o = "start";
1131
+ else
1132
+ return [i, o];
1133
+ if (o === "end" && t === this.options.count - 1)
1134
+ return [this.getMaxScrollOffset(), o];
1135
+ const c = o === "end" ? n.end + this.options.scrollPaddingEnd : n.start - this.options.scrollPaddingStart;
1136
+ return [
1137
+ this.getOffsetForAlignment(c, o, n.size),
1138
+ o
1139
+ ];
1140
+ }, this.isDynamicMode = () => this.elementsCache.size > 0, this.scrollToOffset = (t, { align: o = "start", behavior: n } = {}) => {
1141
+ n === "smooth" && this.isDynamicMode() && console.warn(
1142
+ "The `smooth` scroll behavior is not fully supported with dynamic size."
1143
+ ), this._scrollToOffset(this.getOffsetForAlignment(t, o), {
1144
+ adjustments: void 0,
1145
+ behavior: n
1146
+ });
1147
+ }, this.scrollToIndex = (t, { align: o = "auto", behavior: n } = {}) => {
1148
+ n === "smooth" && this.isDynamicMode() && console.warn(
1149
+ "The `smooth` scroll behavior is not fully supported with dynamic size."
1150
+ ), t = Math.max(0, Math.min(t, this.options.count - 1)), this.currentScrollToIndex = t;
1151
+ let s = 0;
1152
+ const i = 10, c = (f) => {
1153
+ if (!this.targetWindow) return;
1154
+ const p = this.getOffsetForIndex(t, f);
1155
+ if (!p) {
1156
+ console.warn("Failed to get offset for index:", t);
1157
+ return;
1158
+ }
1159
+ const [I, m] = p;
1160
+ this._scrollToOffset(I, { adjustments: void 0, behavior: n }), this.targetWindow.requestAnimationFrame(() => {
1161
+ const D = () => {
1162
+ if (this.currentScrollToIndex !== t) return;
1163
+ const y = this.getScrollOffset(), N = this.getOffsetForIndex(t, m);
1164
+ if (!N) {
1165
+ console.warn("Failed to get offset for index:", t);
1166
+ return;
1167
+ }
1168
+ br(N[0], y) || d(m);
1169
+ };
1170
+ this.isDynamicMode() ? this.targetWindow.requestAnimationFrame(D) : D();
1171
+ });
1172
+ }, d = (f) => {
1173
+ this.targetWindow && this.currentScrollToIndex === t && (s++, s < i ? (process.env.NODE_ENV !== "production" && this.options.debug && console.info("Schedule retry", s, i), this.targetWindow.requestAnimationFrame(() => c(f))) : console.warn(
1174
+ `Failed to scroll to index ${t} after ${i} attempts.`
1175
+ ));
1176
+ };
1177
+ c(o);
1178
+ }, this.scrollBy = (t, { behavior: o } = {}) => {
1179
+ o === "smooth" && this.isDynamicMode() && console.warn(
1180
+ "The `smooth` scroll behavior is not fully supported with dynamic size."
1181
+ ), this._scrollToOffset(this.getScrollOffset() + t, {
1182
+ adjustments: void 0,
1183
+ behavior: o
1184
+ });
1185
+ }, this.getTotalSize = () => {
1186
+ var t;
1187
+ const o = this.getMeasurements();
1188
+ let n;
1189
+ if (o.length === 0)
1190
+ n = this.options.paddingStart;
1191
+ else if (this.options.lanes === 1)
1192
+ n = ((t = o[o.length - 1]) == null ? void 0 : t.end) ?? 0;
1193
+ else {
1194
+ const s = Array(this.options.lanes).fill(null);
1195
+ let i = o.length - 1;
1196
+ for (; i >= 0 && s.some((c) => c === null); ) {
1197
+ const c = o[i];
1198
+ s[c.lane] === null && (s[c.lane] = c.end), i--;
1199
+ }
1200
+ n = Math.max(...s.filter((c) => c !== null));
1201
+ }
1202
+ return Math.max(
1203
+ n - this.options.scrollMargin + this.options.paddingEnd,
1204
+ 0
1205
+ );
1206
+ }, this._scrollToOffset = (t, {
1207
+ adjustments: o,
1208
+ behavior: n
1209
+ }) => {
1210
+ this.options.scrollToFn(t, { behavior: n, adjustments: o }, this);
1211
+ }, this.measure = () => {
1212
+ this.itemSizeCache = /* @__PURE__ */ new Map(), this.laneAssignments = /* @__PURE__ */ new Map(), this.notify(!1);
1213
+ }, this.setOptions(r);
1214
+ }
1215
+ }
1216
+ const mn = (e, r, t, o) => {
1217
+ for (; e <= r; ) {
1218
+ const n = (e + r) / 2 | 0, s = t(n);
1219
+ if (s < o)
1220
+ e = n + 1;
1221
+ else if (s > o)
1222
+ r = n - 1;
1223
+ else
1224
+ return n;
1225
+ }
1226
+ return e > 0 ? e - 1 : 0;
1227
+ };
1228
+ function Cr({
1229
+ measurements: e,
1230
+ outerSize: r,
1231
+ scrollOffset: t,
1232
+ lanes: o
1233
+ }) {
1234
+ const n = e.length - 1, s = (d) => e[d].start;
1235
+ if (e.length <= o)
1236
+ return {
1237
+ startIndex: 0,
1238
+ endIndex: n
1239
+ };
1240
+ let i = mn(
1241
+ 0,
1242
+ n,
1243
+ s,
1244
+ t
1245
+ ), c = i;
1246
+ if (o === 1)
1247
+ for (; c < n && e[c].end < t + r; )
1248
+ c++;
1249
+ else if (o > 1) {
1250
+ const d = Array(o).fill(0);
1251
+ for (; c < n && d.some((p) => p < t + r); ) {
1252
+ const p = e[c];
1253
+ d[p.lane] = p.end, c++;
1254
+ }
1255
+ const f = Array(o).fill(t + r);
1256
+ for (; i >= 0 && f.some((p) => p >= t); ) {
1257
+ const p = e[i];
1258
+ f[p.lane] = p.start, i--;
1259
+ }
1260
+ i = Math.max(0, i - i % o), c = Math.min(n, c + (o - 1 - c % o));
1261
+ }
1262
+ return { startIndex: i, endIndex: c };
1263
+ }
1264
+ const en = typeof document < "u" ? Ke.useLayoutEffect : Ke.useEffect;
1265
+ function Or({
1266
+ useFlushSync: e = !0,
1267
+ ...r
1268
+ }) {
1269
+ const t = Ke.useReducer(() => ({}), {})[1], o = {
1270
+ ...r,
1271
+ onChange: (s, i) => {
1272
+ var c;
1273
+ e && i ? _n(t) : t(), (c = r.onChange) == null || c.call(r, s, i);
1274
+ }
1275
+ }, [n] = Ke.useState(
1276
+ () => new Tr(o)
1277
+ );
1278
+ return n.setOptions(o), en(() => n._didMount(), []), en(() => n._willUpdate()), n;
1279
+ }
1280
+ function tn(e) {
1281
+ return Or({
1282
+ observeElementRect: vr,
1283
+ observeElementOffset: Er,
1284
+ scrollToFn: Ir,
1285
+ ...e
1286
+ });
1287
+ }
1288
+ var yt = { exports: {} };
1289
+ var nn;
1290
+ function Dr() {
1291
+ return nn || (nn = 1, (function(e) {
1292
+ (function() {
1293
+ var r = {}.hasOwnProperty;
1294
+ function t() {
1295
+ for (var s = "", i = 0; i < arguments.length; i++) {
1296
+ var c = arguments[i];
1297
+ c && (s = n(s, o(c)));
1298
+ }
1299
+ return s;
1300
+ }
1301
+ function o(s) {
1302
+ if (typeof s == "string" || typeof s == "number")
1303
+ return s;
1304
+ if (typeof s != "object")
1305
+ return "";
1306
+ if (Array.isArray(s))
1307
+ return t.apply(null, s);
1308
+ if (s.toString !== Object.prototype.toString && !s.toString.toString().includes("[native code]"))
1309
+ return s.toString();
1310
+ var i = "";
1311
+ for (var c in s)
1312
+ r.call(s, c) && s[c] && (i = n(i, c));
1313
+ return i;
1314
+ }
1315
+ function n(s, i) {
1316
+ return i ? s ? s + " " + i : s + i : s;
1317
+ }
1318
+ e.exports ? (t.default = t, e.exports = t) : window.classNames = t;
1319
+ })();
1320
+ })(yt)), yt.exports;
1321
+ }
1322
+ var Nr = Dr();
1323
+ const Y = /* @__PURE__ */ Ge(Nr), rn = ({
1324
+ children: e,
1325
+ gutter: r,
1326
+ stickyRight: t,
1327
+ active: o,
1328
+ disabled: n,
1329
+ className: s,
1330
+ width: i,
1331
+ left: c
1332
+ }) => /* @__PURE__ */ S(
1333
+ "div",
1334
+ {
1335
+ className: Y(
1336
+ "dsg-cell",
1337
+ r && "dsg-cell-gutter",
1338
+ n && "dsg-cell-disabled",
1339
+ r && o && "dsg-cell-gutter-active",
1340
+ t && "dsg-cell-sticky-right",
1341
+ s
1342
+ ),
1343
+ style: {
1344
+ width: i,
1345
+ left: t ? void 0 : c
1346
+ },
1347
+ children: e
1348
+ }
1349
+ ), qe = (e, r) => ge(() => {
1350
+ const t = /* @__PURE__ */ new Map();
1351
+ return (o) => (t.has(o) || t.set(o, (...n) => {
1352
+ e(o, ...n.slice(0, r));
1353
+ }), t.get(o));
1354
+ }, [r, e]), Rr = ({
1355
+ data: e,
1356
+ columns: r,
1357
+ outerRef: t,
1358
+ innerRef: o,
1359
+ columnWidths: n,
1360
+ hasStickyRightColumn: s,
1361
+ displayHeight: i,
1362
+ headerRowHeight: c,
1363
+ rowHeight: d,
1364
+ rowKey: f,
1365
+ fullWidth: p,
1366
+ selection: I,
1367
+ activeCell: m,
1368
+ rowClassName: D,
1369
+ cellClassName: y,
1370
+ children: N,
1371
+ editing: F,
1372
+ getContextMenuItems: W,
1373
+ setRowData: O,
1374
+ deleteRows: C,
1375
+ duplicateRows: R,
1376
+ insertRowAfter: q,
1377
+ stopEditing: V,
1378
+ onScroll: ae
1379
+ }) => {
1380
+ const oe = tn({
1381
+ count: e.length,
1382
+ getScrollElement: () => t.current,
1383
+ paddingStart: c,
1384
+ estimateSize: (T) => d(T).height,
1385
+ getItemKey: (T) => {
1386
+ if (f && T > 0) {
1387
+ const U = e[T - 1];
1388
+ if (typeof f == "function")
1389
+ return f({ rowData: U, rowIndex: T });
1390
+ if (typeof f == "string" && U instanceof Object && f in U) {
1391
+ const B = U[f];
1392
+ if (typeof B == "string" || typeof B == "number")
1393
+ return B;
1394
+ }
1395
+ }
1396
+ return T;
1397
+ },
1398
+ overscan: 5
1399
+ }), P = tn({
1400
+ count: r.length,
1401
+ getScrollElement: () => t.current,
1402
+ estimateSize: (T) => n?.[T] ?? 100,
1403
+ horizontal: !0,
1404
+ getItemKey: (T) => r[T].id ?? T,
1405
+ overscan: 1,
1406
+ rangeExtractor: (T) => {
1407
+ const U = hn(T);
1408
+ return U[0] !== 0 && U.unshift(0), s && U[U.length - 1] !== r.length - 1 && U.push(r.length - 1), U;
1409
+ }
1410
+ });
1411
+ J(() => {
1412
+ P.measure();
1413
+ }, [P, n]);
1414
+ const Q = qe(O, 1), Ae = qe(C, 0), se = qe(R, 0), L = qe(q, 0), b = I?.min.col ?? m?.col, A = I?.max.col ?? m?.col, fe = I?.min.row ?? m?.row, H = I?.max.row ?? m?.row;
1415
+ return /* @__PURE__ */ S(
1416
+ "div",
1417
+ {
1418
+ ref: t,
1419
+ className: "dsg-container",
1420
+ onScroll: ae,
1421
+ style: { height: i },
1422
+ children: /* @__PURE__ */ Me(
1423
+ "div",
1424
+ {
1425
+ ref: o,
1426
+ style: {
1427
+ width: p ? "100%" : P.getTotalSize(),
1428
+ height: oe.getTotalSize()
1429
+ },
1430
+ children: [
1431
+ c > 0 && /* @__PURE__ */ S(
1432
+ "div",
1433
+ {
1434
+ className: Y("dsg-row", "dsg-row-header"),
1435
+ style: {
1436
+ width: p ? "100%" : P.getTotalSize(),
1437
+ height: c
1438
+ },
1439
+ children: P.getVirtualItems().map((T) => /* @__PURE__ */ S(
1440
+ rn,
1441
+ {
1442
+ gutter: T.index === 0,
1443
+ stickyRight: s && T.index === r.length - 1,
1444
+ width: T.size,
1445
+ left: T.start,
1446
+ className: Y(
1447
+ "dsg-cell-header",
1448
+ b !== void 0 && A !== void 0 && b <= T.index - 1 && A >= T.index - 1 && "dsg-cell-header-active",
1449
+ r[T.index].headerClassName
1450
+ ),
1451
+ children: /* @__PURE__ */ S("div", { className: "dsg-cell-header-container", children: r[T.index].title })
1452
+ },
1453
+ T.key
1454
+ ))
1455
+ }
1456
+ ),
1457
+ oe.getVirtualItems().map((T) => {
1458
+ const U = T.index >= (fe ?? 1 / 0) && T.index <= (H ?? -1 / 0);
1459
+ return /* @__PURE__ */ S(
1460
+ "div",
1461
+ {
1462
+ className: Y(
1463
+ "dsg-row",
1464
+ typeof D == "string" ? D : null,
1465
+ typeof D == "function" ? D({
1466
+ rowData: e[T.index],
1467
+ rowIndex: T.index
1468
+ }) : null
1469
+ ),
1470
+ style: {
1471
+ height: T.size,
1472
+ top: T.start,
1473
+ width: p ? "100%" : P.getTotalSize()
1474
+ },
1475
+ children: P.getVirtualItems().map((B) => {
1476
+ const _e = r[B.index].cellClassName, ue = r[B.index].disabled, Ye = r[B.index].component, ze = ue === !0 || typeof ue == "function" && ue({
1477
+ rowData: e[T.index],
1478
+ rowIndex: T.index
1479
+ }), Fe = m?.row === T.index && m.col === B.index - 1;
1480
+ return /* @__PURE__ */ S(
1481
+ rn,
1482
+ {
1483
+ gutter: B.index === 0,
1484
+ stickyRight: s && B.index === r.length - 1,
1485
+ active: B.index === 0 && U,
1486
+ disabled: ze,
1487
+ className: Y(
1488
+ typeof _e == "function" ? _e({
1489
+ rowData: e[T.index],
1490
+ rowIndex: T.index,
1491
+ columnId: r[B.index].id
1492
+ }) : _e,
1493
+ typeof y == "function" ? y({
1494
+ rowData: e[T.index],
1495
+ rowIndex: T.index,
1496
+ columnId: r[B.index].id
1497
+ }) : y
1498
+ ),
1499
+ width: B.size,
1500
+ left: B.start,
1501
+ children: /* @__PURE__ */ S(
1502
+ Ye,
1503
+ {
1504
+ rowData: e[T.index],
1505
+ getContextMenuItems: W,
1506
+ disabled: ze,
1507
+ active: Fe,
1508
+ columnIndex: B.index - 1,
1509
+ rowIndex: T.index,
1510
+ focus: Fe && F,
1511
+ deleteRow: Ae(T.index),
1512
+ duplicateRow: se(T.index),
1513
+ stopEditing: V,
1514
+ insertRowBelow: L(T.index),
1515
+ setRowData: Q(T.index),
1516
+ columnData: r[B.index].columnData
1517
+ }
1518
+ )
1519
+ },
1520
+ B.key
1521
+ );
1522
+ })
1523
+ },
1524
+ T.key
1525
+ );
1526
+ }),
1527
+ N
1528
+ ]
1529
+ }
1530
+ )
1531
+ }
1532
+ );
1533
+ }, on = (e, r, t, o) => [
1534
+ [o, e],
1535
+ [r, e],
1536
+ [r, t],
1537
+ [o, t],
1538
+ [o, e]
1539
+ ], Mr = (e, r, t, o) => `polygon(evenodd, ${[
1540
+ ...on(0, "100%", "100%", 0),
1541
+ ...on(e, r, t, o)
1542
+ ].map(
1543
+ (s) => s.map(
1544
+ (i) => typeof i == "number" && i !== 0 ? i + "px" : i
1545
+ ).join(" ")
1546
+ ).join(",")})`, pn = be.memo(
1547
+ ({
1548
+ columnWidths: e,
1549
+ columnRights: r,
1550
+ headerRowHeight: t,
1551
+ selection: o,
1552
+ rowHeight: n,
1553
+ activeCell: s,
1554
+ hasStickyRightColumn: i,
1555
+ dataLength: c,
1556
+ viewWidth: d,
1557
+ viewHeight: f,
1558
+ contentWidth: p,
1559
+ edges: I,
1560
+ isCellDisabled: m,
1561
+ editing: D,
1562
+ expandSelection: y
1563
+ }) => {
1564
+ const N = s ? m(s) : !1, F = ge(() => {
1565
+ if (!o)
1566
+ return N;
1567
+ for (let P = o.min.col; P <= o.max.col; ++P)
1568
+ for (let Q = o.min.row; Q <= o.max.row; ++Q)
1569
+ if (!m({ col: P, row: Q }))
1570
+ return !1;
1571
+ return !0;
1572
+ }, [N, m, o]);
1573
+ if (!e || !r)
1574
+ return null;
1575
+ const W = (P) => P < c - 1 ? 1 : 0, O = (P) => P < e.length - (i ? 3 : 2) ? 1 : 0, C = s && {
1576
+ width: e[s.col + 1] + O(s.col),
1577
+ height: n(s.row).height + W(s.row),
1578
+ left: r[s.col],
1579
+ top: n(s.row).top + t
1580
+ }, R = o && {
1581
+ width: e.slice(o.min.col + 1, o.max.col + 2).reduce((P, Q) => P + Q) + O(o.max.col),
1582
+ height: n(o.max.row).top + n(o.max.row).height - n(o.min.row).top + W(o.max.row),
1583
+ left: r[o.min.col],
1584
+ top: n(o.min.row).top + t
1585
+ }, q = o?.min || s, V = o?.max || s, ae = V && y !== null && {
1586
+ left: r[V.col] + e[V.col + 1],
1587
+ top: n(V.row).top + n(V.row).height + t,
1588
+ transform: `translate(-${V.col < e.length - (i ? 3 : 2) ? 50 : 100}%, -${V.row < c - 1 ? 50 : 100}%)`
1589
+ }, oe = q && V && y !== null && {
1590
+ width: e.slice(q.col + 1, V.col + 2).reduce((P, Q) => P + Q) + O(V.col),
1591
+ height: n(V.row + y).top + n(V.row + y).height - n(V.row + 1).top + W(V.row + y) - 1,
1592
+ left: r[q.col],
1593
+ top: n(V.row).top + n(V.row).height + t + 1
1594
+ };
1595
+ return /* @__PURE__ */ Me(ne, { children: [
1596
+ /* @__PURE__ */ S(
1597
+ "div",
1598
+ {
1599
+ className: "dsg-scrollable-view-container",
1600
+ style: {
1601
+ height: n(c - 1).top + n(c - 1).height + t,
1602
+ width: p || "100%"
1603
+ },
1604
+ children: /* @__PURE__ */ S(
1605
+ "div",
1606
+ {
1607
+ className: Y({
1608
+ "dsg-scrollable-view": !0,
1609
+ "dsg-scrollable-view-t": !I.top,
1610
+ "dsg-scrollable-view-r": !I.right,
1611
+ "dsg-scrollable-view-b": !I.bottom,
1612
+ "dsg-scrollable-view-l": !I.left
1613
+ }),
1614
+ style: {
1615
+ top: t,
1616
+ left: e[0],
1617
+ height: f ? f - t : 0,
1618
+ width: p && d ? d - e[0] - (i ? e[e.length - 1] : 0) : `calc(100% - ${e[0] + (i ? e[e.length - 1] : 0)}px)`
1619
+ }
1620
+ }
1621
+ )
1622
+ }
1623
+ ),
1624
+ (R || C) && /* @__PURE__ */ S(
1625
+ "div",
1626
+ {
1627
+ className: "dsg-selection-col-marker-container",
1628
+ style: {
1629
+ left: R?.left ?? C?.left,
1630
+ width: R?.width ?? C?.width,
1631
+ height: n(c - 1).top + n(c - 1).height + t
1632
+ },
1633
+ children: /* @__PURE__ */ S(
1634
+ "div",
1635
+ {
1636
+ className: Y(
1637
+ "dsg-selection-col-marker",
1638
+ F && "dsg-selection-col-marker-disabled"
1639
+ ),
1640
+ style: { top: t }
1641
+ }
1642
+ )
1643
+ }
1644
+ ),
1645
+ (R || C) && /* @__PURE__ */ S(
1646
+ "div",
1647
+ {
1648
+ className: "dsg-selection-row-marker-container",
1649
+ style: {
1650
+ top: R?.top ?? C?.top,
1651
+ height: R?.height ?? C?.height,
1652
+ width: p || "100%"
1653
+ },
1654
+ children: /* @__PURE__ */ S(
1655
+ "div",
1656
+ {
1657
+ className: Y(
1658
+ "dsg-selection-row-marker",
1659
+ F && "dsg-selection-row-marker-disabled"
1660
+ ),
1661
+ style: { left: e[0] }
1662
+ }
1663
+ )
1664
+ }
1665
+ ),
1666
+ C && s && /* @__PURE__ */ S(
1667
+ "div",
1668
+ {
1669
+ className: Y("dsg-active-cell", {
1670
+ "dsg-active-cell-focus": D,
1671
+ "dsg-active-cell-disabled": N
1672
+ }),
1673
+ style: C
1674
+ }
1675
+ ),
1676
+ R && C && /* @__PURE__ */ S(
1677
+ "div",
1678
+ {
1679
+ className: Y(
1680
+ "dsg-selection-rect",
1681
+ F && "dsg-selection-rect-disabled"
1682
+ ),
1683
+ style: {
1684
+ ...R,
1685
+ clipPath: Mr(
1686
+ C.top - R.top,
1687
+ C.left - R.left,
1688
+ C.top + C.height - R.top,
1689
+ C.left + C.width - R.left
1690
+ )
1691
+ }
1692
+ }
1693
+ ),
1694
+ oe && /* @__PURE__ */ S("div", { className: Y("dsg-expand-rows-rect"), style: oe }),
1695
+ ae && /* @__PURE__ */ S(
1696
+ "div",
1697
+ {
1698
+ className: Y(
1699
+ "dsg-expand-rows-indicator",
1700
+ F && "dsg-expand-rows-indicator-disabled"
1701
+ ),
1702
+ style: ae
1703
+ }
1704
+ )
1705
+ ] });
1706
+ }
1707
+ );
1708
+ pn.displayName = "SelectionRect";
1709
+ const Ar = ({
1710
+ value: e,
1711
+ rowHeight: r
1712
+ }) => {
1713
+ const t = K([]), [, o] = re(0);
1714
+ return ge(() => {
1715
+ const n = (s) => {
1716
+ if (typeof r == "number")
1717
+ return Math.min(
1718
+ e.length - 1,
1719
+ Math.max(-1, Math.floor(s / r))
1720
+ );
1721
+ let i = 0, c = t.current.length - 1;
1722
+ for (; i <= c; ) {
1723
+ const d = Math.floor((i + c) / 2);
1724
+ if (t.current[d].top < s)
1725
+ i = d + 1;
1726
+ else if (t.current[d].top > s)
1727
+ c = d - 1;
1728
+ else
1729
+ return d;
1730
+ }
1731
+ if (c === t.current.length - 1 && e.length > t.current.length && (!t.current.length || s >= t.current[c].top + t.current[c].height)) {
1732
+ let d = c === -1 ? 0 : t.current[c].top + t.current[c].height;
1733
+ do {
1734
+ c++;
1735
+ const f = r({ rowIndex: c, rowData: e[c] });
1736
+ t.current.push({
1737
+ height: f,
1738
+ top: d
1739
+ }), d += f;
1740
+ } while (d <= s && c < t.current.length - 1);
1741
+ }
1742
+ return c;
1743
+ };
1744
+ return {
1745
+ resetAfter: (s) => {
1746
+ t.current = t.current.slice(0, s), o((i) => i + 1);
1747
+ },
1748
+ getRowSize: (s) => {
1749
+ if (typeof r == "number")
1750
+ return { height: r, top: r * s };
1751
+ if (s >= e.length)
1752
+ return { height: 0, top: 0 };
1753
+ if (s < t.current.length)
1754
+ return t.current[s];
1755
+ let i = t.current[t.current.length - 1].top + t.current[t.current.length - 1].height;
1756
+ for (let c = t.current.length; c <= s; c++) {
1757
+ const d = r({ rowIndex: c, rowData: e[c] });
1758
+ t.current.push({ height: d, top: i }), i += d;
1759
+ }
1760
+ return t.current[s];
1761
+ },
1762
+ getRowIndex: n,
1763
+ totalSize: (s) => {
1764
+ if (typeof r == "number")
1765
+ return e.length * r;
1766
+ const i = n(s);
1767
+ return t.current[i].top + t.current[i].height;
1768
+ }
1769
+ };
1770
+ }, [r, e]);
1771
+ }, _r = [], zr = [], Fr = () => ({}), ke = () => null, Vr = ({
1772
+ rowData: e
1773
+ }) => ({ ...e }), St = be.memo(
1774
+ be.forwardRef(
1775
+ ({
1776
+ value: e = _r,
1777
+ className: r,
1778
+ style: t,
1779
+ height: o = 400,
1780
+ onChange: n = ke,
1781
+ columns: s = zr,
1782
+ rowHeight: i = 40,
1783
+ headerRowHeight: c = typeof i == "number" ? i : 40,
1784
+ gutterColumn: d,
1785
+ stickyRightColumn: f,
1786
+ rowKey: p,
1787
+ addRowsComponent: I = un,
1788
+ createRow: m = Fr,
1789
+ autoAddRow: D = !1,
1790
+ lockRows: y = !1,
1791
+ disableExpandSelection: N = !1,
1792
+ disableSmartDelete: F = !1,
1793
+ duplicateRow: W = Vr,
1794
+ contextMenuComponent: O = dn,
1795
+ disableContextMenu: C = !1,
1796
+ onFocus: R = ke,
1797
+ onBlur: q = ke,
1798
+ onActiveCellChange: V = ke,
1799
+ onSelectionChange: ae = ke,
1800
+ rowClassName: oe,
1801
+ cellClassName: P,
1802
+ onScroll: Q
1803
+ }, Ae) => {
1804
+ const se = K(null), L = C || y, b = sr(s, d, f), A = !!f, fe = K(null), H = K(null), T = K(null), U = K(null), [B, _e] = fr(1, 100), { getRowSize: ue, totalSize: Ye, getRowIndex: ze } = Ar({
1805
+ value: e,
1806
+ rowHeight: i
1807
+ }), Fe = Math.min(
1808
+ o,
1809
+ c + Ye(o) + B
1810
+ ), { width: ve, height: xe } = Qn({
1811
+ targetRef: H,
1812
+ refreshMode: "throttle",
1813
+ refreshRate: 100
1814
+ });
1815
+ _e(xe ? Fe - xe : 0);
1816
+ const yn = ar(H, ve, xe), {
1817
+ fullWidth: It,
1818
+ totalWidth: vn,
1819
+ columnWidths: ie,
1820
+ columnRights: ce
1821
+ } = Fn(b, ve), [Ee, le] = re(null), [Se, En] = re([]), [j, $] = re(!1), [Ie, Tt] = re(0), [
1822
+ Te,
1823
+ Ct
1824
+ ] = re(null), [u, z] = Be(null), [X, _] = Be(null), w = ge(
1825
+ () => u && X && {
1826
+ min: {
1827
+ col: Math.min(u.col, X.col),
1828
+ row: Math.min(u.row, X.row)
1829
+ },
1830
+ max: {
1831
+ col: Math.max(u.col, X.col),
1832
+ row: Math.max(u.row, X.row)
1833
+ }
1834
+ },
1835
+ [u, X]
1836
+ ), [de, Ce] = Be({
1837
+ // True when the position of the cursor should impact the columns of the selection
1838
+ columns: !1,
1839
+ // True when the position of the cursor should impact the rows of the selection
1840
+ rows: !1,
1841
+ // True when the user is dragging the mouse around to select
1842
+ active: !1
1843
+ }), Sn = N || j || de.active || u?.row === e?.length - 1 || w?.max.row === e?.length - 1 || u && b.slice(
1844
+ (w?.min.col ?? u.col) + 1,
1845
+ (w?.max.col ?? u.col) + 2
1846
+ ).every((l) => l.disabled === !0) ? null : Ie, Ot = Gt(fe), Dt = Gt(H);
1847
+ J(() => {
1848
+ u !== null && (document.activeElement.blur(), window.getSelection()?.removeAllRanges());
1849
+ }, [u !== null]);
1850
+ const ye = k(
1851
+ (l, a = !1, g = !1) => {
1852
+ const h = Ot(a), v = g && Dt(a);
1853
+ if (h && ce && ie) {
1854
+ let x = l.clientX - h.left, M = l.clientY - h.top;
1855
+ return v && (l.clientY - v.top <= c && (M = 0), l.clientX - v.left <= ie[0] && (x = 0), A && v.right - l.clientX <= ie[ie.length - 1] && (x = ce[ce.length - 2] + 1)), {
1856
+ col: ce.findIndex((E) => x < E) - 1,
1857
+ row: ze(M - c)
1858
+ };
1859
+ }
1860
+ return null;
1861
+ },
1862
+ [
1863
+ ce,
1864
+ ie,
1865
+ e.length,
1866
+ Ot,
1867
+ Dt,
1868
+ c,
1869
+ A,
1870
+ ze
1871
+ ]
1872
+ ), ee = K(e);
1873
+ ee.current = e;
1874
+ const te = k(
1875
+ (l) => {
1876
+ const a = b[l.col + 1].disabled;
1877
+ return !!(typeof a == "function" ? a({
1878
+ rowData: ee.current[l.row],
1879
+ rowIndex: l.row
1880
+ }) : a);
1881
+ },
1882
+ [b]
1883
+ ), he = k(
1884
+ (l, a = 1) => {
1885
+ y || (_(null), $(!1), n(
1886
+ [
1887
+ ...ee.current.slice(0, l + 1),
1888
+ ...new Array(a).fill(0).map(m),
1889
+ ...ee.current.slice(l + 1)
1890
+ ],
1891
+ [
1892
+ {
1893
+ type: "CREATE",
1894
+ fromRowIndex: l + 1,
1895
+ toRowIndex: l + 1 + a
1896
+ }
1897
+ ]
1898
+ ), z((g) => ({
1899
+ col: g?.col || 0,
1900
+ row: l + a,
1901
+ doNotScrollX: !0
1902
+ })));
1903
+ },
1904
+ [m, y, n, z, _]
1905
+ ), Oe = k(
1906
+ (l, a = l) => {
1907
+ y || (n(
1908
+ [
1909
+ ...ee.current.slice(0, a + 1),
1910
+ ...ee.current.slice(l, a + 1).map(
1911
+ (g, h) => W({ rowData: g, rowIndex: h + l })
1912
+ ),
1913
+ ...ee.current.slice(a + 1)
1914
+ ],
1915
+ [
1916
+ {
1917
+ type: "CREATE",
1918
+ fromRowIndex: a + 1,
1919
+ toRowIndex: a + 2 + a - l
1920
+ }
1921
+ ]
1922
+ ), z({ col: 0, row: a + 1, doNotScrollX: !0 }), _({
1923
+ col: b.length - (A ? 3 : 2),
1924
+ row: 2 * a - l + 1,
1925
+ doNotScrollX: !0
1926
+ }), $(!1));
1927
+ },
1928
+ [
1929
+ b.length,
1930
+ W,
1931
+ y,
1932
+ n,
1933
+ z,
1934
+ _,
1935
+ A
1936
+ ]
1937
+ ), me = k(
1938
+ (l) => {
1939
+ if (!(!xe || !ve)) {
1940
+ if (!l.doNotScrollY) {
1941
+ const a = ue(l.row).top, g = ue(l.row).top + ue(l.row).height + c - xe + 1, h = H.current.scrollTop;
1942
+ h > a ? H.current.scrollTop = a : h < g && (H.current.scrollTop = g);
1943
+ }
1944
+ if (ce && ie && H.current && !l.doNotScrollX) {
1945
+ const a = ce[l.col] - ce[0], g = ce[l.col] + ie[l.col + 1] + (A ? ie[ie.length - 1] : 0) - ve + 1, h = H.current.scrollLeft;
1946
+ h > a ? H.current.scrollLeft = a : h < g && (H.current.scrollLeft = g);
1947
+ }
1948
+ }
1949
+ },
1950
+ [
1951
+ xe,
1952
+ ve,
1953
+ c,
1954
+ ce,
1955
+ ie,
1956
+ ue,
1957
+ A
1958
+ ]
1959
+ );
1960
+ J(() => {
1961
+ X && me(X);
1962
+ }, [X, me]), J(() => {
1963
+ u && me(u);
1964
+ }, [u, me]);
1965
+ const In = k(
1966
+ (l, a) => {
1967
+ n(
1968
+ [
1969
+ ...ee.current?.slice(0, l),
1970
+ a,
1971
+ ...ee.current?.slice(l + 1)
1972
+ ],
1973
+ [
1974
+ {
1975
+ type: "UPDATE",
1976
+ fromRowIndex: l,
1977
+ toRowIndex: l + 1
1978
+ }
1979
+ ]
1980
+ );
1981
+ },
1982
+ [n]
1983
+ ), De = k(
1984
+ (l, a = l) => {
1985
+ y || ($(!1), z((g) => {
1986
+ const h = Math.min(
1987
+ ee.current.length - 2 - a + l,
1988
+ l
1989
+ );
1990
+ return h < 0 ? null : g && { col: g.col, row: h };
1991
+ }), _(null), n(
1992
+ [
1993
+ ...ee.current.slice(0, l),
1994
+ ...ee.current.slice(a + 1)
1995
+ ],
1996
+ [
1997
+ {
1998
+ type: "DELETE",
1999
+ fromRowIndex: l,
2000
+ toRowIndex: a + 1
2001
+ }
2002
+ ]
2003
+ ));
2004
+ },
2005
+ [y, n, z, _]
2006
+ ), Pe = k(
2007
+ (l = !0) => {
2008
+ const a = l && !F;
2009
+ if (!u)
2010
+ return;
2011
+ const g = w?.min || u, h = w?.max || u;
2012
+ if (e.slice(g.row, h.row + 1).every(
2013
+ (x, M) => b.every(
2014
+ (E) => E.isCellEmpty({ rowData: x, rowIndex: M + g.row })
2015
+ )
2016
+ )) {
2017
+ a && De(g.row, h.row);
2018
+ return;
2019
+ }
2020
+ const v = [...e];
2021
+ for (let x = g.row; x <= h.row; ++x)
2022
+ for (let M = g.col; M <= h.col; ++M)
2023
+ if (!te({ col: M, row: x })) {
2024
+ const { deleteValue: E = ({ rowData: G }) => G } = b[M + 1];
2025
+ v[x] = E({
2026
+ rowData: v[x],
2027
+ rowIndex: x
2028
+ });
2029
+ }
2030
+ if (a && an(v, e)) {
2031
+ z({ col: 0, row: g.row, doNotScrollX: !0 }), _({
2032
+ col: b.length - (A ? 3 : 2),
2033
+ row: h.row,
2034
+ doNotScrollX: !0
2035
+ });
2036
+ return;
2037
+ }
2038
+ n(v, [
2039
+ {
2040
+ type: "UPDATE",
2041
+ fromRowIndex: g.row,
2042
+ toRowIndex: h.row + 1
2043
+ }
2044
+ ]);
2045
+ },
2046
+ [
2047
+ u,
2048
+ b,
2049
+ e,
2050
+ De,
2051
+ te,
2052
+ n,
2053
+ w?.max,
2054
+ w?.min,
2055
+ z,
2056
+ _,
2057
+ A
2058
+ ]
2059
+ ), Ze = k(
2060
+ ({ nextRow: l = !0 } = {}) => {
2061
+ u?.row === ee.current.length - 1 ? l && D ? he(u.row) : $(!1) : ($(!1), l && z((a) => a && { col: a.col, row: a.row + 1 }));
2062
+ },
2063
+ [u?.row, D, he, z]
2064
+ ), Ve = k(
2065
+ async (l) => {
2066
+ if (!j && u) {
2067
+ const a = [], g = w?.min || u, h = w?.max || u;
2068
+ for (let E = g.row; E <= h.row; ++E) {
2069
+ a.push([]);
2070
+ for (let G = g.col; G <= h.col; ++G) {
2071
+ const { copyValue: Z = () => null } = b[G + 1];
2072
+ a[E - g.row].push(
2073
+ Z({ rowData: e[E], rowIndex: E })
2074
+ );
2075
+ }
2076
+ }
2077
+ const v = a.map((E) => E.join(" ")).join(`
2078
+ `), x = `<table>${a.map(
2079
+ (E) => `<tr>${E.map(
2080
+ (G) => `<td>${pr(String(G ?? "")).replace(
2081
+ /\n/g,
2082
+ "<br/>"
2083
+ )}</td>`
2084
+ ).join("")}</tr>`
2085
+ ).join("")}</table>`;
2086
+ if (l !== void 0) {
2087
+ l.clipboardData?.setData("text/plain", v), l.clipboardData?.setData("text/html", x), l.preventDefault();
2088
+ return;
2089
+ }
2090
+ let M = !1;
2091
+ if (navigator.clipboard.write !== void 0) {
2092
+ const E = new Blob([v], {
2093
+ type: "text/plain"
2094
+ }), G = new Blob([x], { type: "text/html" }), Z = [
2095
+ new ClipboardItem({
2096
+ "text/plain": E,
2097
+ "text/html": G
2098
+ })
2099
+ ];
2100
+ await navigator.clipboard.write(Z).then(() => {
2101
+ M = !0;
2102
+ });
2103
+ } else navigator.clipboard.writeText !== void 0 ? await navigator.clipboard.writeText(v).then(() => {
2104
+ M = !0;
2105
+ }) : document.execCommand !== void 0 && document.execCommand("copy") && (M = !0);
2106
+ M || alert(
2107
+ "This action is unavailable in your browser, but you can still use Ctrl+C for copy or Ctrl+X for cut"
2108
+ );
2109
+ }
2110
+ },
2111
+ [u, b, e, j, w]
2112
+ );
2113
+ pe("copy", Ve);
2114
+ const Je = k(
2115
+ (l) => {
2116
+ !j && u && (Ve(l), Pe(!1));
2117
+ },
2118
+ [u, Pe, j, Ve]
2119
+ );
2120
+ pe("cut", Je);
2121
+ const je = k(
2122
+ async (l) => {
2123
+ if (!j && u) {
2124
+ const a = w?.min || u, g = w?.max || u, h = await Promise.all(
2125
+ l[0].map((v, x) => {
2126
+ const M = b[a.col + x + 1]?.prePasteValues, E = l.map((G) => G[x]);
2127
+ return M?.(E) ?? E;
2128
+ })
2129
+ );
2130
+ if (l = l.map(
2131
+ (v, x) => h.map((M) => M[x])
2132
+ ), l.length === 1) {
2133
+ const v = [...e];
2134
+ for (let x = 0; x < l[0].length; x++) {
2135
+ const M = b[a.col + x + 1]?.pasteValue;
2136
+ if (M)
2137
+ for (let E = a.row; E <= g.row; E++)
2138
+ te({
2139
+ col: x + a.col,
2140
+ row: E
2141
+ }) || (v[E] = await M({
2142
+ rowData: v[E],
2143
+ value: l[0][x],
2144
+ rowIndex: E
2145
+ }));
2146
+ }
2147
+ n(v, [
2148
+ {
2149
+ type: "UPDATE",
2150
+ fromRowIndex: a.row,
2151
+ toRowIndex: g.row + 1
2152
+ }
2153
+ ]), z({ col: a.col, row: a.row }), _({
2154
+ col: Math.min(
2155
+ a.col + l[0].length - 1,
2156
+ b.length - (A ? 3 : 2)
2157
+ ),
2158
+ row: g.row
2159
+ });
2160
+ } else {
2161
+ let v = [...e];
2162
+ const x = a.row + l.length - e.length;
2163
+ x > 0 && (y ? l.splice(l.length - x, x) : v = [
2164
+ ...v,
2165
+ ...new Array(x).fill(0).map(() => m())
2166
+ ]);
2167
+ for (let E = 0; E < l[0].length && a.col + E < b.length - (A ? 2 : 1); E++) {
2168
+ const G = b[a.col + E + 1]?.pasteValue;
2169
+ if (G)
2170
+ for (let Z = 0; Z < l.length; Z++)
2171
+ te({
2172
+ col: a.col + E,
2173
+ row: a.row + Z
2174
+ }) || (v[a.row + Z] = await G({
2175
+ rowData: v[a.row + Z],
2176
+ value: l[Z][E],
2177
+ rowIndex: a.row + Z
2178
+ }));
2179
+ }
2180
+ const M = [
2181
+ {
2182
+ type: "UPDATE",
2183
+ fromRowIndex: a.row,
2184
+ toRowIndex: a.row + l.length - (!y && x > 0 ? x : 0)
2185
+ }
2186
+ ];
2187
+ x > 0 && !y && M.push({
2188
+ type: "CREATE",
2189
+ fromRowIndex: a.row + l.length - x,
2190
+ toRowIndex: a.row + l.length
2191
+ }), n(v, M), z({ col: a.col, row: a.row }), _({
2192
+ col: Math.min(
2193
+ a.col + l[0].length - 1,
2194
+ b.length - (A ? 3 : 2)
2195
+ ),
2196
+ row: a.row + l.length - 1
2197
+ });
2198
+ }
2199
+ }
2200
+ },
2201
+ [
2202
+ u,
2203
+ b,
2204
+ m,
2205
+ e,
2206
+ j,
2207
+ A,
2208
+ te,
2209
+ y,
2210
+ n,
2211
+ w?.max,
2212
+ w?.min,
2213
+ z,
2214
+ _
2215
+ ]
2216
+ ), Tn = k(
2217
+ (l) => {
2218
+ if (u && !j) {
2219
+ let a = [[""]];
2220
+ l.clipboardData?.types.includes("text/html") ? a = xt(
2221
+ l.clipboardData?.getData("text/html")
2222
+ ) : l.clipboardData?.types.includes("text/plain") ? a = We(
2223
+ l.clipboardData?.getData("text/plain")
2224
+ ) : l.clipboardData?.types.includes("text") && (a = We(
2225
+ l.clipboardData?.getData("text")
2226
+ )), je(a), l.preventDefault();
2227
+ }
2228
+ },
2229
+ [u, je, j]
2230
+ );
2231
+ pe("paste", Tn);
2232
+ const Cn = k(
2233
+ (l) => {
2234
+ if (Ee && Se.length)
2235
+ return;
2236
+ const a = l.button === 2 || l.button === 0 && l.ctrlKey, g = fe.current?.contains(l.target) || !1, h = g ? ye(l, !0, !0) : null;
2237
+ if (!g && j && u && b[u.col + 1].keepFocus)
2238
+ return;
2239
+ if (l.target instanceof HTMLElement && l.target.className.includes("dsg-expand-rows-indicator")) {
2240
+ Ct(
2241
+ Math.max(u?.row ?? 0, w?.max.row ?? 0)
2242
+ );
2243
+ return;
2244
+ }
2245
+ const v = h && u && u.col === h.col && u.row === h.row && !te(u);
2246
+ if (v && j)
2247
+ return;
2248
+ const x = h?.col === b.length - 2 && A, M = a && w && h && h.row >= w.min.row && h.row <= w.max.row && h.col >= w.min.col && h.col <= w.max.col, E = a && w && h && h.row === -1 && h.col >= w.min.col && h.col <= w.max.col, G = a && w && h && h.row >= w.min.row && h.row <= w.max.row && h.col === -1, Z = x && w && h && h.row >= w.min.row && h.row <= w.max.row;
2249
+ if (a && !L && le({
2250
+ x: l.clientX,
2251
+ y: l.clientY,
2252
+ cursorIndex: h
2253
+ }), (!(l.shiftKey && u) || a) && e.length > 0 && z(
2254
+ h && {
2255
+ col: (M || E) && u ? u.col : Math.max(
2256
+ 0,
2257
+ x ? 0 : h.col
2258
+ ),
2259
+ row: (M || G || Z) && u ? u.row : Math.max(0, h.row),
2260
+ doNotScrollX: !!(M && u || x || h.col === -1),
2261
+ doNotScrollY: !!(M && u || h.row === -1)
2262
+ }
2263
+ ), v && !a && (se.current = u), $(!!(v && !a)), Ce(
2264
+ h && !a ? {
2265
+ columns: h.col !== -1 && !x || !!(l.shiftKey && u),
2266
+ rows: h.row !== -1 || !!(l.shiftKey && u),
2267
+ active: !0
2268
+ } : {
2269
+ columns: !1,
2270
+ rows: !1,
2271
+ active: !1
2272
+ }
2273
+ ), l.shiftKey && u && !a)
2274
+ _(
2275
+ h && {
2276
+ col: Math.max(
2277
+ 0,
2278
+ h.col - (x ? 1 : 0)
2279
+ ),
2280
+ row: Math.max(0, h.row)
2281
+ }
2282
+ );
2283
+ else if (!M) {
2284
+ if (h && (h?.col === -1 || h?.row === -1 || x)) {
2285
+ let Qe = h.col, He = h.row, et = !1, tt = !1;
2286
+ (h.col === -1 || x) && (Qe = b.length - (A ? 3 : 2), et = !0), h.row === -1 && (He = e.length - 1, tt = !0), E && X && (Qe = X.col, tt = !0), (G || Z) && X && (He = X.row, et = !0), _({ col: Qe, row: He, doNotScrollX: et, doNotScrollY: tt });
2287
+ } else
2288
+ _(null);
2289
+ g && l.preventDefault();
2290
+ }
2291
+ },
2292
+ [
2293
+ Ee,
2294
+ Se.length,
2295
+ ye,
2296
+ j,
2297
+ u,
2298
+ b,
2299
+ te,
2300
+ w,
2301
+ A,
2302
+ L,
2303
+ Ce,
2304
+ z,
2305
+ _,
2306
+ X,
2307
+ e.length
2308
+ ]
2309
+ );
2310
+ pe("mousedown", Cn);
2311
+ const On = k(() => {
2312
+ if (Te !== null) {
2313
+ if (Ie > 0 && u) {
2314
+ let l = [];
2315
+ const a = w?.min || u, g = w?.max || u;
2316
+ for (let h = a.row; h <= g.row; ++h) {
2317
+ l.push([]);
2318
+ for (let v = a.col; v <= g.col; ++v) {
2319
+ const { copyValue: x = () => null } = b[v + 1];
2320
+ l[h - a.row].push(
2321
+ String(x({ rowData: e[h], rowIndex: h }) ?? "")
2322
+ );
2323
+ }
2324
+ }
2325
+ Promise.all(
2326
+ l[0].map((h, v) => {
2327
+ const x = b[a.col + v + 1]?.prePasteValues, M = l.map((E) => E[v]);
2328
+ return x?.(M) ?? M;
2329
+ })
2330
+ ).then((h) => {
2331
+ l = l.map(
2332
+ (x, M) => h.map((E) => E[M])
2333
+ );
2334
+ const v = [...e];
2335
+ for (let x = 0; x < l[0].length; x++) {
2336
+ const M = b[a.col + x + 1]?.pasteValue;
2337
+ if (M)
2338
+ for (let E = g.row + 1; E <= g.row + Ie; E++)
2339
+ te({
2340
+ col: x + a.col,
2341
+ row: E
2342
+ }) || (v[E] = M({
2343
+ rowData: v[E],
2344
+ value: l[(E - g.row - 1) % l.length][x],
2345
+ rowIndex: E
2346
+ }));
2347
+ }
2348
+ n(v, [
2349
+ {
2350
+ type: "UPDATE",
2351
+ fromRowIndex: g.row + 1,
2352
+ toRowIndex: g.row + 1 + Ie
2353
+ }
2354
+ ]);
2355
+ }), Tt(0), z({
2356
+ col: Math.min(
2357
+ u?.col ?? 1 / 0,
2358
+ w?.min.col ?? 1 / 0
2359
+ ),
2360
+ row: Math.min(
2361
+ u?.row ?? 1 / 0,
2362
+ w?.min.row ?? 1 / 0
2363
+ ),
2364
+ doNotScrollX: !0,
2365
+ doNotScrollY: !0
2366
+ }), _({
2367
+ col: Math.max(u?.col ?? 0, w?.max.col ?? 0),
2368
+ row: Math.max(u?.row ?? 0, w?.max.row ?? 0) + Ie
2369
+ });
2370
+ }
2371
+ Ct(null);
2372
+ }
2373
+ Ce({
2374
+ columns: !1,
2375
+ rows: !1,
2376
+ active: !1
2377
+ });
2378
+ }, [
2379
+ Te,
2380
+ Ce,
2381
+ Ie,
2382
+ u,
2383
+ w?.min,
2384
+ w?.max,
2385
+ e,
2386
+ n,
2387
+ z,
2388
+ _,
2389
+ b,
2390
+ te
2391
+ ]);
2392
+ pe("mouseup", On);
2393
+ const Dn = k(
2394
+ (l) => {
2395
+ if (Te !== null) {
2396
+ const a = ye(l);
2397
+ a && (Tt(
2398
+ Math.max(0, a.row - Te)
2399
+ ), me({
2400
+ col: a.col,
2401
+ row: Math.max(a.row, Te)
2402
+ }));
2403
+ }
2404
+ if (de.active) {
2405
+ const a = ye(l), g = b.length - (A ? 3 : 2);
2406
+ _(
2407
+ a && {
2408
+ col: de.columns ? Math.max(0, Math.min(g, a.col)) : g,
2409
+ row: de.rows ? Math.max(0, a.row) : e.length - 1,
2410
+ doNotScrollX: !de.columns,
2411
+ doNotScrollY: !de.rows
2412
+ }
2413
+ ), $(!1);
2414
+ }
2415
+ },
2416
+ [
2417
+ me,
2418
+ de.active,
2419
+ de.columns,
2420
+ de.rows,
2421
+ ye,
2422
+ b.length,
2423
+ A,
2424
+ _,
2425
+ e.length,
2426
+ Te
2427
+ ]
2428
+ );
2429
+ pe("mousemove", Dn);
2430
+ const Nn = k(
2431
+ (l) => {
2432
+ if (u && !l.isComposing) {
2433
+ if (l.key === "Tab" && !l.shiftKey && u.col === b.length - (A ? 3 : 2) && !b[u.col + 1].disableKeys)
2434
+ if (u.row === e.length - 1) {
2435
+ if (U.current) {
2436
+ l.preventDefault(), z(null), _(null), $(!1);
2437
+ const a = Yt(), g = a.indexOf(U.current);
2438
+ a[(g + 1) % a.length].focus();
2439
+ return;
2440
+ }
2441
+ } else {
2442
+ z((a) => ({ col: 0, row: (a?.row ?? 0) + 1 })), _(null), $(!1), l.preventDefault();
2443
+ return;
2444
+ }
2445
+ if (l.key === "Tab" && l.shiftKey && u.col === 0 && !b[u.col + 1].disableKeys)
2446
+ if (u.row === 0) {
2447
+ if (T.current) {
2448
+ l.preventDefault(), z(null), _(null), $(!1);
2449
+ const a = Yt(), g = a.indexOf(T.current);
2450
+ a[(g - 1 + a.length) % a.length].focus();
2451
+ return;
2452
+ }
2453
+ } else {
2454
+ z((a) => ({
2455
+ col: b.length - (A ? 3 : 2),
2456
+ row: (a?.row ?? 1) - 1
2457
+ })), _(null), $(!1), l.preventDefault();
2458
+ return;
2459
+ }
2460
+ if (l.key?.startsWith("Arrow") || l.key === "Tab") {
2461
+ if (j && b[u.col + 1].disableKeys || j && ["ArrowLeft", "ArrowRight"].includes(l.key))
2462
+ return;
2463
+ const a = ([g, h], v) => v && {
2464
+ col: Math.max(
2465
+ 0,
2466
+ Math.min(
2467
+ b.length - (A ? 3 : 2),
2468
+ v.col + g
2469
+ )
2470
+ ),
2471
+ row: Math.max(0, Math.min(e.length - 1, v.row + h))
2472
+ };
2473
+ if (l.key === "Tab" && l.shiftKey)
2474
+ z((g) => a([-1, 0], g)), _(null);
2475
+ else {
2476
+ const g = {
2477
+ ArrowDown: [0, 1],
2478
+ ArrowUp: [0, -1],
2479
+ ArrowLeft: [-1, 0],
2480
+ ArrowRight: [1, 0],
2481
+ Tab: [1, 0]
2482
+ }[l.key];
2483
+ (l.ctrlKey || l.metaKey) && (g[0] *= b.length, g[1] *= e.length), l.shiftKey ? _((h) => a(g, h || u)) : (z((h) => a(g, h)), _(null));
2484
+ }
2485
+ $(!1), l.preventDefault();
2486
+ } else l.key === "Escape" ? (!j && !X && z(null), _(null), $(!1)) : (l.key === "Enter" || l.key === "F2") && !l.ctrlKey && !l.metaKey && !l.altKey && !l.shiftKey ? (_(null), j ? b[u.col + 1].disableKeys || (Ze(), l.preventDefault()) : te(u) || (se.current = u, $(!0), me(u), l.preventDefault())) : l.key === "Enter" && !l.ctrlKey && !l.metaKey && !l.altKey && l.shiftKey ? he(w?.max.row || u.row) : l.key === "d" && (l.ctrlKey || l.metaKey) && !l.altKey && !l.shiftKey ? (Oe(
2487
+ w?.min.row || u.row,
2488
+ w?.max.row
2489
+ ), l.preventDefault()) : (gr(l.key) || l.code.match(/Key[A-Z]$/)) && !l.ctrlKey && !l.metaKey && !l.altKey ? !j && !te(u) && (se.current = u, _(null), $(!0), me(u)) : ["Backspace", "Delete"].includes(l.key) ? j || (Pe(), l.preventDefault()) : l.key === "a" && (l.ctrlKey || l.metaKey) && (j || (z({
2490
+ col: 0,
2491
+ row: 0,
2492
+ doNotScrollY: !0,
2493
+ doNotScrollX: !0
2494
+ }), _({
2495
+ col: b.length - (A ? 3 : 2),
2496
+ row: e.length - 1,
2497
+ doNotScrollY: !0,
2498
+ doNotScrollX: !0
2499
+ }), l.preventDefault()));
2500
+ }
2501
+ },
2502
+ [
2503
+ u,
2504
+ b,
2505
+ e.length,
2506
+ Pe,
2507
+ Oe,
2508
+ j,
2509
+ he,
2510
+ te,
2511
+ me,
2512
+ w?.max.row,
2513
+ w?.min.row,
2514
+ X,
2515
+ z,
2516
+ _,
2517
+ Ze,
2518
+ A
2519
+ ]
2520
+ );
2521
+ pe("keydown", Nn);
2522
+ const Rn = k(
2523
+ (l) => {
2524
+ const a = fe.current?.contains(l.target) || !1, g = a ? ye(l, !0, !0) : null, h = g && u && u.col === g.col && u.row === g.row && j;
2525
+ a && !h && l.preventDefault();
2526
+ },
2527
+ [ye, u, j]
2528
+ );
2529
+ pe("contextmenu", Rn), J(() => {
2530
+ const l = [];
2531
+ u?.row !== void 0 && l.push(
2532
+ {
2533
+ type: "COPY",
2534
+ action: () => {
2535
+ Ve(), le(null);
2536
+ }
2537
+ },
2538
+ {
2539
+ type: "CUT",
2540
+ action: () => {
2541
+ Je(), le(null);
2542
+ }
2543
+ },
2544
+ {
2545
+ type: "PASTE",
2546
+ action: async () => {
2547
+ if (navigator.clipboard.read !== void 0)
2548
+ (await navigator.clipboard.read()).forEach(async (g) => {
2549
+ let h = [[""]];
2550
+ if (g.types.includes("text/html")) {
2551
+ const v = await g.getType("text/html");
2552
+ h = xt(await v.text());
2553
+ } else if (g.types.includes("text/plain")) {
2554
+ const v = await g.getType("text/plain");
2555
+ h = We(await v.text());
2556
+ } else if (g.types.includes("text")) {
2557
+ const v = await g.getType("text");
2558
+ h = xt(await v.text());
2559
+ }
2560
+ je(h);
2561
+ });
2562
+ else if (navigator.clipboard.readText !== void 0) {
2563
+ const a = await navigator.clipboard.readText();
2564
+ je(We(a));
2565
+ } else
2566
+ alert(
2567
+ "This action is unavailable in your browser, but you can still use Ctrl+V for paste"
2568
+ );
2569
+ le(null);
2570
+ }
2571
+ }
2572
+ ), w?.max.row !== void 0 ? l.push({
2573
+ type: "INSERT_ROW_BELLOW",
2574
+ action: () => {
2575
+ le(null), he(w.max.row);
2576
+ }
2577
+ }) : u?.row !== void 0 && l.push({
2578
+ type: "INSERT_ROW_BELLOW",
2579
+ action: () => {
2580
+ le(null), he(u.row);
2581
+ }
2582
+ }), w?.min.row !== void 0 && w.min.row !== w.max.row ? l.push({
2583
+ type: "DUPLICATE_ROWS",
2584
+ fromRow: w.min.row + 1,
2585
+ toRow: w.max.row + 1,
2586
+ action: () => {
2587
+ le(null), Oe(w.min.row, w.max.row);
2588
+ }
2589
+ }) : u?.row !== void 0 && l.push({
2590
+ type: "DUPLICATE_ROW",
2591
+ action: () => {
2592
+ le(null), Oe(u.row);
2593
+ }
2594
+ }), w?.min.row !== void 0 && w.min.row !== w.max.row ? l.push({
2595
+ type: "DELETE_ROWS",
2596
+ fromRow: w.min.row + 1,
2597
+ toRow: w.max.row + 1,
2598
+ action: () => {
2599
+ le(null), De(w.min.row, w.max.row);
2600
+ }
2601
+ }) : u?.row !== void 0 && l.push({
2602
+ type: "DELETE_ROW",
2603
+ action: () => {
2604
+ le(null), De(u.row);
2605
+ }
2606
+ }), En(l), l.length || le(null);
2607
+ }, [
2608
+ w,
2609
+ u,
2610
+ De,
2611
+ Oe,
2612
+ he,
2613
+ Je,
2614
+ Ve,
2615
+ je
2616
+ ]);
2617
+ const Nt = K(Se);
2618
+ Nt.current = Se;
2619
+ const Mn = k(
2620
+ () => Nt.current,
2621
+ []
2622
+ );
2623
+ An(Ae, () => ({
2624
+ activeCell: Re(u, b),
2625
+ selection: Xt(
2626
+ w ?? (u ? { min: u, max: u } : null),
2627
+ b
2628
+ ),
2629
+ setSelection: (l) => {
2630
+ const a = wr(
2631
+ l,
2632
+ b.length - (A ? 2 : 1),
2633
+ e.length,
2634
+ b
2635
+ );
2636
+ z(a?.min || null), $(!1), Ce({ columns: !1, active: !1, rows: !1 }), _(a?.max || null);
2637
+ },
2638
+ setActiveCell: (l) => {
2639
+ const a = vt(
2640
+ l,
2641
+ b.length - (A ? 2 : 1),
2642
+ e.length,
2643
+ b
2644
+ );
2645
+ z(a), $(!1), Ce({ columns: !1, active: !1, rows: !1 }), _(null);
2646
+ }
2647
+ }));
2648
+ const we = K({
2649
+ onFocus: R,
2650
+ onBlur: q,
2651
+ onActiveCellChange: V,
2652
+ onSelectionChange: ae
2653
+ });
2654
+ return we.current.onFocus = R, we.current.onBlur = q, we.current.onActiveCellChange = V, we.current.onSelectionChange = ae, J(() => {
2655
+ se.current && (j ? we.current.onFocus({
2656
+ cell: Re(se.current, b)
2657
+ }) : we.current.onBlur({
2658
+ cell: Re(se.current, b)
2659
+ }));
2660
+ }, [j, b]), J(() => {
2661
+ we.current.onActiveCellChange({
2662
+ cell: Re(u, b)
2663
+ });
2664
+ }, [u?.col, u?.row, b]), J(() => {
2665
+ we.current.onSelectionChange({
2666
+ selection: Xt(
2667
+ w ?? (u ? { min: u, max: u } : null),
2668
+ b
2669
+ )
2670
+ });
2671
+ }, [
2672
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2673
+ w?.min.col ?? u?.col,
2674
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2675
+ w?.min.row ?? u?.row,
2676
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2677
+ w?.max.col ?? u?.col,
2678
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2679
+ w?.max.row ?? u?.row,
2680
+ u?.col,
2681
+ u?.row,
2682
+ b
2683
+ ]), /* @__PURE__ */ Me("div", { className: r, style: t, children: [
2684
+ /* @__PURE__ */ S(
2685
+ "div",
2686
+ {
2687
+ ref: T,
2688
+ tabIndex: s.length && e.length ? 0 : void 0,
2689
+ onFocus: (l) => {
2690
+ l.target.blur(), z({ col: 0, row: 0 });
2691
+ }
2692
+ }
2693
+ ),
2694
+ /* @__PURE__ */ S(
2695
+ Rr,
2696
+ {
2697
+ columns: b,
2698
+ outerRef: H,
2699
+ columnWidths: ie,
2700
+ hasStickyRightColumn: A,
2701
+ displayHeight: Fe,
2702
+ data: e,
2703
+ fullWidth: It,
2704
+ headerRowHeight: c,
2705
+ activeCell: u,
2706
+ innerRef: fe,
2707
+ rowHeight: ue,
2708
+ rowKey: p,
2709
+ selection: w,
2710
+ rowClassName: oe,
2711
+ editing: j,
2712
+ getContextMenuItems: Mn,
2713
+ setRowData: In,
2714
+ deleteRows: De,
2715
+ insertRowAfter: he,
2716
+ duplicateRows: Oe,
2717
+ stopEditing: Ze,
2718
+ cellClassName: P,
2719
+ onScroll: Q,
2720
+ children: /* @__PURE__ */ S(
2721
+ pn,
2722
+ {
2723
+ columnRights: ce,
2724
+ columnWidths: ie,
2725
+ activeCell: u,
2726
+ selection: w,
2727
+ headerRowHeight: c,
2728
+ rowHeight: ue,
2729
+ hasStickyRightColumn: A,
2730
+ dataLength: e.length,
2731
+ viewHeight: xe,
2732
+ viewWidth: ve,
2733
+ contentWidth: It ? void 0 : vn,
2734
+ edges: yn,
2735
+ editing: j,
2736
+ isCellDisabled: te,
2737
+ expandSelection: Sn
2738
+ }
2739
+ )
2740
+ }
2741
+ ),
2742
+ /* @__PURE__ */ S(
2743
+ "div",
2744
+ {
2745
+ ref: U,
2746
+ tabIndex: s.length && e.length ? 0 : void 0,
2747
+ onFocus: (l) => {
2748
+ l.target.blur(), z({
2749
+ col: b.length - (A ? 3 : 2),
2750
+ row: e.length - 1
2751
+ });
2752
+ }
2753
+ }
2754
+ ),
2755
+ !y && I && /* @__PURE__ */ S(
2756
+ I,
2757
+ {
2758
+ addRows: (l) => he(e.length - 1, l)
2759
+ }
2760
+ ),
2761
+ Ee && Se.length > 0 && /* @__PURE__ */ S(
2762
+ O,
2763
+ {
2764
+ clientX: Ee.x,
2765
+ clientY: Ee.y,
2766
+ cursorIndex: Ee.cursorIndex,
2767
+ items: Se,
2768
+ close: () => le(null)
2769
+ }
2770
+ )
2771
+ ] });
2772
+ }
2773
+ )
2774
+ );
2775
+ St.displayName = "DataSheetGrid";
2776
+ const jr = be.forwardRef(
2777
+ ({
2778
+ columns: e,
2779
+ gutterColumn: r,
2780
+ stickyRightColumn: t,
2781
+ addRowsComponent: o,
2782
+ createRow: n,
2783
+ duplicateRow: s,
2784
+ style: i,
2785
+ rowKey: c,
2786
+ onFocus: d,
2787
+ onBlur: f,
2788
+ onActiveCellChange: p,
2789
+ onSelectionChange: I,
2790
+ rowClassName: m,
2791
+ rowHeight: D,
2792
+ ...y
2793
+ }, N) => {
2794
+ const [F] = re({
2795
+ columns: e,
2796
+ gutterColumn: r,
2797
+ stickyRightColumn: t,
2798
+ addRowsComponent: o,
2799
+ createRow: n,
2800
+ duplicateRow: s,
2801
+ style: i,
2802
+ rowKey: c,
2803
+ onFocus: d,
2804
+ onBlur: f,
2805
+ onActiveCellChange: p,
2806
+ onSelectionChange: I,
2807
+ rowClassName: m,
2808
+ rowHeight: D
2809
+ });
2810
+ return /* @__PURE__ */ S(
2811
+ St,
2812
+ {
2813
+ ...F,
2814
+ ...y,
2815
+ rowHeight: typeof D == "number" ? D : F.rowHeight,
2816
+ ref: N
2817
+ }
2818
+ );
2819
+ }
2820
+ ), kr = () => {
2821
+ const e = K(!0), r = e.current;
2822
+ return e.current = !1, r;
2823
+ }, gn = be.memo(
2824
+ ({
2825
+ active: e,
2826
+ focus: r,
2827
+ rowData: t,
2828
+ setRowData: o,
2829
+ columnData: {
2830
+ placeholder: n,
2831
+ alignRight: s,
2832
+ formatInputOnFocus: i,
2833
+ formatBlurredInput: c,
2834
+ parseUserInput: d,
2835
+ continuousUpdates: f
2836
+ }
2837
+ }) => {
2838
+ const p = K(null), I = kr(), m = K({
2839
+ rowData: t,
2840
+ formatInputOnFocus: i,
2841
+ formatBlurredInput: c,
2842
+ setRowData: o,
2843
+ parseUserInput: d,
2844
+ continuousUpdates: f,
2845
+ firstRender: I,
2846
+ // Timestamp of last focus (when focus becomes true) and last change (input change)
2847
+ // used to prevent un-necessary updates when value was not changed
2848
+ focusedAt: 0,
2849
+ changedAt: 0,
2850
+ // This allows us to keep track of whether or not the user blurred the input using the Esc key
2851
+ // If the Esc key is used we do not update the row's value (only relevant when continuousUpdates is false)
2852
+ escPressed: !1
2853
+ });
2854
+ return m.current = {
2855
+ rowData: t,
2856
+ formatInputOnFocus: i,
2857
+ formatBlurredInput: c,
2858
+ setRowData: o,
2859
+ parseUserInput: d,
2860
+ continuousUpdates: f,
2861
+ firstRender: I,
2862
+ // Keep the same values across renders
2863
+ focusedAt: m.current.focusedAt,
2864
+ changedAt: m.current.changedAt,
2865
+ escPressed: m.current.escPressed
2866
+ }, $e(() => {
2867
+ r ? (p.current && (p.current.value = m.current.formatInputOnFocus(
2868
+ m.current.rowData
2869
+ ), p.current.focus(), p.current.select()), m.current.escPressed = !1, m.current.focusedAt = Date.now()) : p.current && (!m.current.escPressed && !m.current.continuousUpdates && !m.current.firstRender && // Make sure that focus was gained more than 10 ms ago, used to prevent flickering
2870
+ m.current.changedAt >= m.current.focusedAt && m.current.setRowData(
2871
+ m.current.parseUserInput(p.current.value)
2872
+ ), p.current.blur());
2873
+ }, [r]), J(() => {
2874
+ !r && p.current && (p.current.value = m.current.formatBlurredInput(t));
2875
+ }, [r, t]), /* @__PURE__ */ S(
2876
+ "input",
2877
+ {
2878
+ defaultValue: c(t),
2879
+ className: Y("dsg-input", s && "dsg-input-align-right"),
2880
+ placeholder: e ? n : void 0,
2881
+ tabIndex: -1,
2882
+ ref: p,
2883
+ style: { pointerEvents: r ? "auto" : "none" },
2884
+ onChange: (D) => {
2885
+ m.current.changedAt = Date.now(), f && o(d(D.target.value));
2886
+ },
2887
+ onKeyDown: (D) => {
2888
+ D.key === "Escape" && (m.current.escPressed = !0);
2889
+ }
2890
+ }
2891
+ );
2892
+ }
2893
+ );
2894
+ gn.displayName = "TextComponent";
2895
+ const $r = Xe();
2896
+ function Xe({
2897
+ placeholder: e,
2898
+ alignRight: r = !1,
2899
+ continuousUpdates: t = !0,
2900
+ deletedValue: o = null,
2901
+ parseUserInput: n = (f) => f.trim() || null,
2902
+ formatBlurredInput: s = (f) => String(f ?? ""),
2903
+ formatInputOnFocus: i = (f) => String(f ?? ""),
2904
+ formatForCopy: c = (f) => String(f ?? ""),
2905
+ parsePastedValue: d = (f) => f.replace(/[\n\r]+/g, " ").trim() || null
2906
+ } = {}) {
2907
+ return {
2908
+ component: gn,
2909
+ columnData: {
2910
+ placeholder: e,
2911
+ alignRight: r,
2912
+ continuousUpdates: t,
2913
+ formatInputOnFocus: i,
2914
+ formatBlurredInput: s,
2915
+ parseUserInput: n
2916
+ },
2917
+ deleteValue: () => o,
2918
+ copyValue: ({ rowData: f }) => c(f),
2919
+ pasteValue: ({ value: f }) => d(f),
2920
+ isCellEmpty: ({ rowData: f }) => f == null
2921
+ };
2922
+ }
2923
+ const Pr = [
2924
+ "",
2925
+ "false",
2926
+ "no",
2927
+ "off",
2928
+ "disabled",
2929
+ "0",
2930
+ "n",
2931
+ "f",
2932
+ "unchecked",
2933
+ "undefined",
2934
+ "null",
2935
+ "wrong",
2936
+ "negative"
2937
+ ], wn = be.memo(
2938
+ ({ focus: e, rowData: r, setRowData: t, active: o, stopEditing: n, disabled: s }) => {
2939
+ const i = K(null);
2940
+ return $e(() => {
2941
+ e && (t(!r), n({ nextRow: !1 }));
2942
+ }, [e, n]), /* @__PURE__ */ S(
2943
+ "input",
2944
+ {
2945
+ className: "dsg-checkbox",
2946
+ tabIndex: -1,
2947
+ type: "checkbox",
2948
+ ref: i,
2949
+ disabled: s,
2950
+ checked: !!r,
2951
+ onMouseDown: () => !o && t(!r),
2952
+ onChange: () => null
2953
+ }
2954
+ );
2955
+ }
2956
+ );
2957
+ wn.displayName = "CheckboxComponent";
2958
+ const Gr = {
2959
+ component: wn,
2960
+ deleteValue: () => !1,
2961
+ // We can customize what value is copied: when the checkbox is checked we copy YES, otherwise we copy NO
2962
+ copyValue: ({ rowData: e }) => e ? "YES" : "NO",
2963
+ // Since we copy custom values, we have to make sure pasting gives us the expected result
2964
+ // Here NO is included in the FALSY array, so it will be converted to false, YES is not, so it will be converted to true
2965
+ pasteValue: ({ value: e }) => !Pr.includes(e.toLowerCase()),
2966
+ isCellEmpty: ({ rowData: e }) => !e
2967
+ }, Xr = Xe({
2968
+ alignRight: !0,
2969
+ formatBlurredInput: (e) => typeof e == "number" ? new Intl.NumberFormat().format(e) : "",
2970
+ parseUserInput: (e) => {
2971
+ const r = parseFloat(e);
2972
+ return isNaN(r) ? null : r;
2973
+ },
2974
+ parsePastedValue: (e) => {
2975
+ const r = parseFloat(e);
2976
+ return isNaN(r) ? null : r;
2977
+ }
2978
+ }), Yr = Xe({
2979
+ alignRight: !0,
2980
+ formatBlurredInput: (e) => typeof e == "number" ? new Intl.NumberFormat().format(e) : "",
2981
+ parseUserInput: (e) => {
2982
+ const r = parseFloat(e);
2983
+ return isNaN(r) ? null : Math.round(r);
2984
+ },
2985
+ parsePastedValue: (e) => {
2986
+ const r = parseFloat(e);
2987
+ return isNaN(r) ? null : Math.round(r);
2988
+ }
2989
+ }), Lr = 1e12, Wr = 1e10, Zr = Xe({
2990
+ alignRight: !0,
2991
+ formatBlurredInput: (e) => typeof e == "number" ? new Intl.NumberFormat(void 0, { style: "percent" }).format(e) : "",
2992
+ // We turn percentages (numbers between 0 and 1) into string (between 0 and 100)
2993
+ // We could have just multiply percentages by 100, but floating point arithmetic won't work as expected: 0.29 * 100 === 28.999999999999996
2994
+ // So we have to round those numbers to 10 decimals before turning them into strings
2995
+ formatInputOnFocus: (e) => typeof e == "number" && !isNaN(e) ? String(Math.round(e * Lr) / Wr) : "",
2996
+ parseUserInput: (e) => {
2997
+ const r = parseFloat(e);
2998
+ return isNaN(r) ? null : r / 100;
2999
+ },
3000
+ parsePastedValue: (e) => {
3001
+ const r = parseFloat(e);
3002
+ return isNaN(r) ? null : r;
3003
+ }
3004
+ }), bn = be.memo(
3005
+ ({ focus: e, active: r, rowData: t, setRowData: o }) => {
3006
+ const n = K(null);
3007
+ return $e(() => {
3008
+ e ? n.current?.select() : n.current?.blur();
3009
+ }, [e]), /* @__PURE__ */ S(
3010
+ "input",
3011
+ {
3012
+ className: Y("dsg-input", !r && "dsg-hide-date-picker"),
3013
+ type: "date",
3014
+ tabIndex: -1,
3015
+ max: "9999-12-31",
3016
+ ref: n,
3017
+ style: {
3018
+ pointerEvents: e ? "auto" : "none",
3019
+ opacity: t || r ? void 0 : 0
3020
+ },
3021
+ value: t?.toISOString().substr(0, 10) ?? "",
3022
+ onChange: (s) => {
3023
+ const i = new Date(s.target.value);
3024
+ o(isNaN(i.getTime()) ? null : i);
3025
+ }
3026
+ }
3027
+ );
3028
+ }
3029
+ );
3030
+ bn.displayName = "DateComponent";
3031
+ const Jr = {
3032
+ component: bn,
3033
+ deleteValue: () => null,
3034
+ // We convert the date to a string for copying using toISOString
3035
+ copyValue: ({ rowData: e }) => e ? e.toISOString().substr(0, 10) : null,
3036
+ // Because the Date constructor works using iso format, we can use it to parse ISO string back to a Date object
3037
+ pasteValue: ({ value: e }) => {
3038
+ const r = new Date(e.replace(/\.\s?|\//g, "-"));
3039
+ return isNaN(r.getTime()) ? null : r;
3040
+ },
3041
+ minWidth: 170,
3042
+ isCellEmpty: ({ rowData: e }) => !e
3043
+ }, xn = be.memo(
3044
+ ({ focus: e, active: r, rowData: t, setRowData: o }) => {
3045
+ const n = K(null);
3046
+ return $e(() => {
3047
+ e ? n.current?.select() : n.current?.blur();
3048
+ }, [e]), /* @__PURE__ */ S(
3049
+ "input",
3050
+ {
3051
+ className: Y("dsg-input", !r && "dsg-hide-date-picker"),
3052
+ type: "date",
3053
+ tabIndex: -1,
3054
+ max: "9999-12-31",
3055
+ ref: n,
3056
+ style: {
3057
+ pointerEvents: e ? "auto" : "none",
3058
+ opacity: t || r ? void 0 : 0
3059
+ },
3060
+ value: t ?? "",
3061
+ onChange: (s) => {
3062
+ const i = new Date(s.target.value);
3063
+ o(
3064
+ isNaN(i.getTime()) ? null : i.toISOString().substr(0, 10)
3065
+ );
3066
+ }
3067
+ }
3068
+ );
3069
+ }
3070
+ );
3071
+ xn.displayName = "IsoDateComponent";
3072
+ const Qr = {
3073
+ component: xn,
3074
+ deleteValue: () => null,
3075
+ copyValue: ({ rowData: e }) => e,
3076
+ // Because the Date constructor works using iso format, we can use it to parse ISO string back to a Date object
3077
+ pasteValue: ({ value: e }) => {
3078
+ const r = new Date(e.replace(/\.\s?|\//g, "-"));
3079
+ return isNaN(r.getTime()) ? null : r.toISOString().substr(0, 10);
3080
+ },
3081
+ minWidth: 170,
3082
+ isCellEmpty: ({ rowData: e }) => !e
3083
+ }, qr = ({
3084
+ columnData: { key: e, original: r },
3085
+ rowData: t,
3086
+ setRowData: o,
3087
+ ...n
3088
+ }) => {
3089
+ const s = K(t);
3090
+ s.current = t;
3091
+ const i = k(
3092
+ (d) => {
3093
+ o({ ...s.current, [e]: d });
3094
+ },
3095
+ [e, o]
3096
+ );
3097
+ if (!r.component)
3098
+ return /* @__PURE__ */ S(ne, {});
3099
+ const c = r.component;
3100
+ return /* @__PURE__ */ S(
3101
+ c,
3102
+ {
3103
+ columnData: r.columnData,
3104
+ setRowData: i,
3105
+ rowData: t[e],
3106
+ ...n
3107
+ }
3108
+ );
3109
+ }, Hr = (e, r) => ({
3110
+ id: e,
3111
+ ...r,
3112
+ // We pass the key and the original column as columnData to be able to retrieve them in the cell component
3113
+ columnData: { key: e, original: r },
3114
+ component: qr,
3115
+ // Here we simply wrap all functions to only pass the value of the desired key to the column, and not the entire row
3116
+ copyValue: ({ rowData: t, rowIndex: o }) => r.copyValue?.({ rowData: t[e], rowIndex: o }) ?? null,
3117
+ deleteValue: ({ rowData: t, rowIndex: o }) => ({
3118
+ ...t,
3119
+ [e]: r.deleteValue?.({ rowData: t[e], rowIndex: o }) ?? null
3120
+ }),
3121
+ pasteValue: ({ rowData: t, value: o, rowIndex: n }) => ({
3122
+ ...t,
3123
+ [e]: r.pasteValue?.({ rowData: t[e], value: o, rowIndex: n }) ?? null
3124
+ }),
3125
+ disabled: typeof r.disabled == "function" ? ({ rowData: t, rowIndex: o }) => typeof r.disabled == "function" ? r.disabled({ rowData: t[e], rowIndex: o }) : r.disabled ?? !1 : r.disabled,
3126
+ cellClassName: typeof r.cellClassName == "function" ? ({ rowData: t, rowIndex: o, columnId: n }) => typeof r.cellClassName == "function" ? r.cellClassName({ rowData: t[e], rowIndex: o, columnId: n }) : r.cellClassName ?? void 0 : r.cellClassName,
3127
+ isCellEmpty: ({ rowData: t, rowIndex: o }) => r.isCellEmpty?.({ rowData: t[e], rowIndex: o }) ?? !1
3128
+ }), eo = St, to = jr;
3129
+ export {
3130
+ to as DataSheetGrid,
3131
+ eo as DynamicDataSheetGrid,
3132
+ Gr as checkboxColumn,
3133
+ ur as createAddRowsComponent,
3134
+ dr as createContextMenuComponent,
3135
+ Xe as createTextColumn,
3136
+ Jr as dateColumn,
3137
+ Xr as floatColumn,
3138
+ Yr as intColumn,
3139
+ Qr as isoDateColumn,
3140
+ Hr as keyColumn,
3141
+ Zr as percentColumn,
3142
+ fn as renderContextMenuItem,
3143
+ $r as textColumn
3144
+ };
3145
+ //# sourceMappingURL=index.js.map