react-masume-grid 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,763 @@
1
+ import { jsx as W, jsxs as H } from "react/jsx-runtime";
2
+ import { useMemo as $, useState as z, useRef as I, useEffect as ue, useLayoutEffect as Be, useCallback as U } from "react";
3
+ function S(s, c, d) {
4
+ return Math.min(Math.max(s, c), d);
5
+ }
6
+ function wt(s) {
7
+ let c = "", d = s;
8
+ for (; c = String.fromCharCode(65 + d % 26) + c, d = Math.floor(d / 26) - 1, !(d < 0); )
9
+ ;
10
+ return c;
11
+ }
12
+ function gt(s) {
13
+ const c = new Array(s.length + 1);
14
+ c[0] = 0;
15
+ for (let d = 0; d < s.length; d++) c[d + 1] = c[d] + s[d];
16
+ return c;
17
+ }
18
+ function vt(s, c, d) {
19
+ const g = Math.max(0, c - 1), x = Math.max(0, d - 1), v = s.anchor, m = s.focus;
20
+ return {
21
+ top: S(Math.min(v.row, m.row), 0, g),
22
+ bottom: S(Math.max(v.row, m.row), 0, g),
23
+ left: S(Math.min(v.col, m.col), 0, x),
24
+ right: S(Math.max(v.col, m.col), 0, x)
25
+ };
26
+ }
27
+ function Ue(s) {
28
+ return s.replace(/[0-9a-zA-Z]/g, (c) => String.fromCharCode(c.charCodeAt(0) - 65248)).replace(/./g, ".").replace(/[-ー−]/g, "-").replace(/+/g, "+").replace(/,/g, ",").replace(///g, "/").replace(/ /g, " ");
29
+ }
30
+ function yt(s) {
31
+ const c = Ue(s).trim().replace(/,/g, "");
32
+ return c === "" ? "" : /^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/.test(c) ? c : null;
33
+ }
34
+ function Fe(s) {
35
+ const c = Ue(s).trim();
36
+ if (c === "") return "";
37
+ const d = /^(\d{4})[/\-.年](\d{1,2})[/\-.月](\d{1,2})日?$/.exec(c) ?? /^(\d{4})(\d{2})(\d{2})$/.exec(c);
38
+ if (!d) return null;
39
+ const g = Number(d[1]), x = Number(d[2]), v = Number(d[3]), m = new Date(g, x - 1, v);
40
+ if (m.getFullYear() !== g || m.getMonth() !== x - 1 || m.getDate() !== v) return null;
41
+ const q = (Y) => String(Y).padStart(2, "0");
42
+ return `${g}-${q(x)}-${q(v)}`;
43
+ }
44
+ function bt(s) {
45
+ return /[\t\n\r"]/.test(s) ? '"' + s.replace(/"/g, '""') + '"' : s;
46
+ }
47
+ function Dt(s) {
48
+ return s.map((c) => c.map(bt).join(" ")).join(`
49
+ `);
50
+ }
51
+ function xt(s) {
52
+ s.endsWith(`\r
53
+ `) ? s = s.slice(0, -2) : (s.endsWith(`
54
+ `) || s.endsWith("\r")) && (s = s.slice(0, -1));
55
+ const c = [];
56
+ let d = [], g = "", x = !1;
57
+ for (let v = 0; v < s.length; v++) {
58
+ const m = s[v];
59
+ x ? m === '"' ? s[v + 1] === '"' ? (g += '"', v++) : x = !1 : g += m : m === '"' && g === "" ? x = !0 : m === " " ? (d.push(g), g = "") : m === `
60
+ ` || m === "\r" ? (m === "\r" && s[v + 1] === `
61
+ ` && v++, d.push(g), c.push(d), d = [], g = "") : g += m;
62
+ }
63
+ return d.push(g), c.push(d), c;
64
+ }
65
+ const $e = 4, Mt = 24;
66
+ function Ct({
67
+ data: s,
68
+ columns: c,
69
+ onChange: d,
70
+ onCellChange: g,
71
+ onSelectionChange: x,
72
+ onColumnResize: v,
73
+ showRowNumbers: m = !0,
74
+ showHeader: q = !0,
75
+ readOnly: Y = !1,
76
+ resizableColumns: Xe = !0,
77
+ rowHeight: y = 28,
78
+ headerHeight: je = 28,
79
+ defaultColumnWidth: ge = 120,
80
+ rowNumberWidth: _e = 48,
81
+ className: ve,
82
+ style: qe
83
+ }) {
84
+ var Oe, Pe;
85
+ const w = s.length, p = $(
86
+ () => c ? c.length : s.reduce((e, t) => Math.max(e, t.length), 0),
87
+ [c, s]
88
+ ), [ye, be] = z({}), [De, xe] = z(null), L = $(
89
+ () => Array.from(
90
+ { length: p },
91
+ (e, t) => {
92
+ var r;
93
+ return ye[t] ?? ((r = c == null ? void 0 : c[t]) == null ? void 0 : r.width) ?? ge;
94
+ }
95
+ ),
96
+ [c, p, ge, ye]
97
+ ), O = $(() => gt(L), [L]), b = m ? _e : 0, M = q ? je : 0, fe = b + (O[p] ?? 0), Ye = w * y, [ee, A] = z([
98
+ { anchor: { row: 0, col: 0 }, focus: { row: 0, col: 0 } }
99
+ ]), [h, de] = z(null), [X, te] = z(""), [Me, Ge] = z(0), [Ee, ke] = z(0), [re, pe] = z(null), [G, oe] = z(0), P = I(null), V = I(null), j = I(null), ne = I(null), ce = I(!1), Ce = I(-1), B = I(h);
100
+ B.current = h;
101
+ const Re = I(X);
102
+ Re.current = X;
103
+ const le = ee[ee.length - 1], i = {
104
+ row: S(le.anchor.row, 0, Math.max(0, w - 1)),
105
+ col: S(le.anchor.col, 0, Math.max(0, p - 1))
106
+ }, T = $(
107
+ () => ee.map((e) => vt(e, w, p)),
108
+ [ee, w, p]
109
+ );
110
+ ue(() => {
111
+ x == null || x(T);
112
+ }, [T]), Be(() => {
113
+ const e = P.current;
114
+ if (!e || (ke(e.clientHeight), typeof ResizeObserver > "u")) return;
115
+ const t = new ResizeObserver(() => ke(e.clientHeight));
116
+ return t.observe(e), () => t.disconnect();
117
+ }, []);
118
+ const F = U(
119
+ (e) => {
120
+ var t;
121
+ return !Y && !((t = c == null ? void 0 : c[e]) != null && t.readOnly);
122
+ },
123
+ [Y, c]
124
+ ), E = U(
125
+ (e) => {
126
+ var t;
127
+ return ((t = c == null ? void 0 : c[e]) == null ? void 0 : t.type) ?? "text";
128
+ },
129
+ [c]
130
+ ), _ = $(() => {
131
+ const e = /* @__PURE__ */ new Map();
132
+ return c == null || c.forEach((t, r) => {
133
+ t.type === "select" && e.set(
134
+ r,
135
+ (t.options ?? []).map(
136
+ (o) => typeof o == "string" ? { value: o, label: o } : { value: o.value, label: o.label ?? o.value }
137
+ )
138
+ );
139
+ }), e;
140
+ }, [c]), he = $(() => {
141
+ const e = /* @__PURE__ */ new Map();
142
+ for (const [t, r] of _)
143
+ e.set(t, new Map(r.map((o) => [o.value, o.label])));
144
+ return e;
145
+ }, [_]), Se = U(
146
+ (e, t) => {
147
+ var r;
148
+ switch (E(e)) {
149
+ case "number":
150
+ return yt(t);
151
+ case "date":
152
+ return Fe(t);
153
+ case "select": {
154
+ if (t === "") return "";
155
+ const o = _.get(e);
156
+ if (o != null && o.some((a) => a.value === t)) return t;
157
+ const n = o == null ? void 0 : o.find((a) => a.label === t);
158
+ return n ? n.value : ((r = c == null ? void 0 : c[e]) == null ? void 0 : r.strict) === !1 ? t : null;
159
+ }
160
+ default:
161
+ return t;
162
+ }
163
+ },
164
+ [E, _, c]
165
+ ), se = U(
166
+ (e) => {
167
+ var r;
168
+ const t = [];
169
+ for (const o of e) {
170
+ if (!F(o.col)) continue;
171
+ const n = Se(o.col, o.value);
172
+ n !== null && (((r = s[o.row]) == null ? void 0 : r[o.col]) ?? "") !== n && t.push(n === o.value ? o : { ...o, value: n });
173
+ }
174
+ if (t.length !== 0) {
175
+ if (g)
176
+ for (const o of t) g(o.row, o.col, o.value);
177
+ if (d) {
178
+ const o = s.slice(), n = /* @__PURE__ */ new Set();
179
+ for (const a of t) {
180
+ n.has(a.row) || (o[a.row] = (o[a.row] ?? []).slice(), n.add(a.row));
181
+ const l = o[a.row];
182
+ for (; l.length < a.col; ) l.push("");
183
+ l[a.col] = a.value;
184
+ }
185
+ d(o);
186
+ }
187
+ }
188
+ },
189
+ [F, Se, s, d, g]
190
+ ), N = U(
191
+ (e = !0, t) => {
192
+ var o, n;
193
+ const r = B.current;
194
+ if (r) {
195
+ if (e && !(E(r.col) === "date" && ((o = j.current) == null ? void 0 : o.validity.badInput) === !0)) {
196
+ const l = t ?? Re.current, f = ((n = s[r.row]) == null ? void 0 : n[r.col]) ?? "";
197
+ l !== f && se([{ row: r.row, col: r.col, value: l }]);
198
+ }
199
+ de(null), te(""), pe(null), ce.current = !1;
200
+ }
201
+ },
202
+ [E, s, se]
203
+ ), Q = U(
204
+ (e) => {
205
+ const t = P.current;
206
+ if (!t || p === 0) return;
207
+ const r = M + e.row * y, o = r + y, n = b + O[e.col], a = n + L[e.col];
208
+ r - M < t.scrollTop ? t.scrollTop = r - M : o > t.scrollTop + t.clientHeight && (t.scrollTop = o - t.clientHeight), n - b < t.scrollLeft ? t.scrollLeft = n - b : a > t.scrollLeft + t.clientWidth && (t.scrollLeft = a - t.clientWidth);
209
+ },
210
+ [p, M, y, b, O, L]
211
+ ), J = U(
212
+ (e, t) => {
213
+ var a, l;
214
+ const r = t ?? i;
215
+ if (w === 0 || p === 0 || !F(r.col)) return;
216
+ const o = E(r.col);
217
+ let n = e === "edit" ? ((a = s[r.row]) == null ? void 0 : a[r.col]) ?? "" : "";
218
+ o === "date" && (n = Fe(n) ?? ""), o === "select" && (n = ((l = he.get(r.col)) == null ? void 0 : l.get(n)) ?? n), de({ row: r.row, col: r.col, mode: e }), te(n), pe(null), Q(r), e === "edit" && o !== "date" && requestAnimationFrame(() => {
219
+ var f;
220
+ (f = V.current) == null || f.setSelectionRange(n.length, n.length);
221
+ });
222
+ },
223
+ // eslint-disable-next-line react-hooks/exhaustive-deps
224
+ [i.row, i.col, w, p, F, E, he, s, Q]
225
+ ), Ae = I(i);
226
+ Ae.current = i;
227
+ const Ne = I({ rowNumW: b, headerH: M });
228
+ Be(() => {
229
+ const e = Ne.current;
230
+ e.rowNumW === b && e.headerH === M || (Ne.current = { rowNumW: b, headerH: M }, Q(Ae.current));
231
+ }, [b, M, Q]);
232
+ const Z = h ? E(h.col) : null, K = $(() => {
233
+ if (!h || Z !== "select") return null;
234
+ const e = _.get(h.col) ?? [];
235
+ if (re === null) return e;
236
+ const t = re.trim().toLowerCase();
237
+ return t === "" ? e : e.filter(
238
+ (r) => r.label.toLowerCase().includes(t) || r.value.toLowerCase().includes(t)
239
+ );
240
+ }, [h, Z, _, re]);
241
+ ue(() => {
242
+ var t;
243
+ if (!h || !K) return;
244
+ let e = K.findIndex((r) => r.value === X || r.label === X);
245
+ if (e < 0 && re === null) {
246
+ const r = ((t = s[h.row]) == null ? void 0 : t[h.col]) ?? "";
247
+ e = K.findIndex((o) => o.value === r);
248
+ }
249
+ oe(Math.max(0, e));
250
+ }, [K]), ue(() => {
251
+ var t;
252
+ const e = (t = ne.current) == null ? void 0 : t.children[G];
253
+ e == null || e.scrollIntoView({ block: "nearest" });
254
+ }, [G]), ue(() => {
255
+ var e;
256
+ h && Z === "date" && ((e = j.current) == null || e.focus({ preventScroll: !0 }));
257
+ }, [h, Z]);
258
+ const ae = (e, t) => {
259
+ const r = e.slice(), o = r[r.length - 1];
260
+ return r[r.length - 1] = { anchor: o.anchor, focus: t }, r;
261
+ }, D = (e, t, r) => {
262
+ if (w === 0 || p === 0) return;
263
+ const o = { row: S(e, 0, w - 1), col: S(t, 0, p - 1) };
264
+ r != null && r.extend ? A((n) => ae(n, o)) : A([{ anchor: o, focus: o }]), Q(o);
265
+ }, Le = () => {
266
+ w === 0 || p === 0 || A([
267
+ { anchor: { row: 0, col: 0 }, focus: { row: w - 1, col: p - 1 } }
268
+ ]);
269
+ }, me = () => {
270
+ var r;
271
+ const e = T[T.length - 1], t = [];
272
+ for (let o = e.top; o <= e.bottom; o++) {
273
+ const n = [];
274
+ for (let a = e.left; a <= e.right; a++) n.push(((r = s[o]) == null ? void 0 : r[a]) ?? "");
275
+ t.push(n);
276
+ }
277
+ return Dt(t);
278
+ }, Te = async () => {
279
+ var t;
280
+ if (w === 0 || p === 0) return;
281
+ const e = me();
282
+ try {
283
+ await navigator.clipboard.writeText(e);
284
+ } catch {
285
+ const r = document.createElement("textarea");
286
+ r.value = e, r.style.position = "fixed", r.style.opacity = "0", document.body.appendChild(r), r.select();
287
+ try {
288
+ document.execCommand("copy");
289
+ } finally {
290
+ r.remove(), (t = V.current) == null || t.focus({ preventScroll: !0 });
291
+ }
292
+ }
293
+ }, we = () => {
294
+ var r;
295
+ const e = [], t = /* @__PURE__ */ new Set();
296
+ for (const o of T)
297
+ for (let n = o.top; n <= o.bottom; n++)
298
+ for (let a = o.left; a <= o.right; a++) {
299
+ const l = n * Math.max(1, p) + a;
300
+ t.has(l) || (t.add(l), (((r = s[n]) == null ? void 0 : r[a]) ?? "") !== "" && e.push({ row: n, col: a, value: "" }));
301
+ }
302
+ se(e);
303
+ }, Qe = (e) => {
304
+ if (Y || w === 0 || p === 0) return;
305
+ const t = xt(e);
306
+ if (t.length === 0) return;
307
+ const r = T[T.length - 1], o = t.length, n = Math.max(...t.map((k) => k.length));
308
+ if (n === 0) return;
309
+ const a = r.bottom - r.top + 1, l = r.right - r.left + 1;
310
+ let f = o, u = n;
311
+ (a > o || l > n) && a % o === 0 && l % n === 0 && (f = a, u = l), f = Math.min(f, w - r.top), u = Math.min(u, p - r.left);
312
+ const C = [];
313
+ for (let k = 0; k < f; k++)
314
+ for (let R = 0; R < u; R++)
315
+ C.push({
316
+ row: r.top + k,
317
+ col: r.left + R,
318
+ value: t[k % o][R % n] ?? ""
319
+ });
320
+ se(C), A([
321
+ {
322
+ anchor: { row: r.top, col: r.left },
323
+ focus: { row: r.top + f - 1, col: r.left + u - 1 }
324
+ }
325
+ ]);
326
+ }, Je = (e) => {
327
+ if (ce.current || e.nativeEvent.isComposing || e.keyCode === 229) return;
328
+ const t = e.shiftKey, r = e.ctrlKey || e.metaKey, o = h;
329
+ if (o) {
330
+ if ((e.key === "Enter" || e.key === "Tab" || e.key === "Escape") && e.timeStamp - Ce.current < 80 || e.key === "Enter" && e.altKey) return;
331
+ if (E(o.col) === "select" && K) {
332
+ if (e.key === "ArrowDown") {
333
+ e.preventDefault(), oe((l) => Math.min(l + 1, Math.max(0, K.length - 1)));
334
+ return;
335
+ }
336
+ if (e.key === "ArrowUp") {
337
+ e.preventDefault(), oe((l) => Math.max(l - 1, 0));
338
+ return;
339
+ }
340
+ if (e.key === "Enter" || e.key === "Tab") {
341
+ e.preventDefault();
342
+ const l = K[G];
343
+ N(!0, l == null ? void 0 : l.value), e.key === "Enter" ? D(i.row + (t ? -1 : 1), i.col) : D(i.row, i.col + (t ? -1 : 1));
344
+ return;
345
+ }
346
+ }
347
+ switch (e.key) {
348
+ case "Enter":
349
+ e.preventDefault(), N(), D(i.row + (t ? -1 : 1), i.col);
350
+ return;
351
+ case "Tab":
352
+ e.preventDefault(), N(), D(i.row, i.col + (t ? -1 : 1));
353
+ return;
354
+ case "Escape":
355
+ e.preventDefault(), N(!1);
356
+ return;
357
+ case "ArrowUp":
358
+ case "ArrowDown":
359
+ case "ArrowLeft":
360
+ case "ArrowRight": {
361
+ if (o.mode !== "replace") return;
362
+ e.preventDefault(), N();
363
+ const l = e.key === "ArrowUp" ? -1 : e.key === "ArrowDown" ? 1 : 0, f = e.key === "ArrowLeft" ? -1 : e.key === "ArrowRight" ? 1 : 0;
364
+ D(i.row + l, i.col + f);
365
+ return;
366
+ }
367
+ default:
368
+ return;
369
+ }
370
+ }
371
+ const n = (l, f) => {
372
+ if (e.preventDefault(), t) {
373
+ const u = {
374
+ row: S(le.focus.row, 0, Math.max(0, w - 1)),
375
+ col: S(le.focus.col, 0, Math.max(0, p - 1))
376
+ };
377
+ D(u.row + l, u.col + f, { extend: !0 });
378
+ } else
379
+ D(i.row + l, i.col + f);
380
+ };
381
+ if (e.altKey && !r && e.key === "ArrowDown") {
382
+ const l = E(i.col);
383
+ if (l === "select" || l === "date") {
384
+ e.preventDefault(), J("edit"), l === "date" && requestAnimationFrame(() => {
385
+ var f, u;
386
+ try {
387
+ (u = (f = j.current) == null ? void 0 : f.showPicker) == null || u.call(f);
388
+ } catch {
389
+ }
390
+ });
391
+ return;
392
+ }
393
+ }
394
+ if (r && !e.altKey) {
395
+ const l = e.key.toLowerCase();
396
+ if (l === "a") {
397
+ e.preventDefault(), Le();
398
+ return;
399
+ }
400
+ if (l === "c") {
401
+ e.preventDefault(), Te();
402
+ return;
403
+ }
404
+ if (l === "x") {
405
+ e.preventDefault(), Te(), we();
406
+ return;
407
+ }
408
+ if (l === "v") return;
409
+ if (e.key === "Home") {
410
+ e.preventDefault(), D(0, 0, { extend: t });
411
+ return;
412
+ }
413
+ if (e.key === "End") {
414
+ e.preventDefault(), D(w - 1, p - 1, { extend: t });
415
+ return;
416
+ }
417
+ return;
418
+ }
419
+ const a = Math.max(1, Math.floor(Math.max(0, Ee - M) / y) - 1);
420
+ switch (e.key) {
421
+ case "ArrowUp":
422
+ n(-1, 0);
423
+ return;
424
+ case "ArrowDown":
425
+ n(1, 0);
426
+ return;
427
+ case "ArrowLeft":
428
+ n(0, -1);
429
+ return;
430
+ case "ArrowRight":
431
+ n(0, 1);
432
+ return;
433
+ case "PageUp":
434
+ n(-a, 0);
435
+ return;
436
+ case "PageDown":
437
+ n(a, 0);
438
+ return;
439
+ case "Tab":
440
+ e.preventDefault(), D(i.row, i.col + (t ? -1 : 1));
441
+ return;
442
+ case "Enter":
443
+ e.preventDefault(), D(i.row + (t ? -1 : 1), i.col);
444
+ return;
445
+ case "F2":
446
+ e.preventDefault(), J("edit");
447
+ return;
448
+ case "Delete":
449
+ case "Backspace":
450
+ e.preventDefault(), we();
451
+ return;
452
+ case "Home":
453
+ e.preventDefault(), D(i.row, 0, { extend: t });
454
+ return;
455
+ case "End":
456
+ e.preventDefault(), D(i.row, p - 1, { extend: t });
457
+ return;
458
+ }
459
+ e.key.length === 1 && !r && !e.altKey && (E(i.col) === "date" && e.preventDefault(), J("replace"));
460
+ }, Ze = (e) => {
461
+ var t, r, o;
462
+ switch (e.key) {
463
+ case "Enter":
464
+ e.preventDefault(), N(), (t = V.current) == null || t.focus({ preventScroll: !0 }), D(i.row + (e.shiftKey ? -1 : 1), i.col);
465
+ return;
466
+ case "Tab":
467
+ e.preventDefault(), N(), (r = V.current) == null || r.focus({ preventScroll: !0 }), D(i.row, i.col + (e.shiftKey ? -1 : 1));
468
+ return;
469
+ case "Escape":
470
+ e.preventDefault(), N(!1), (o = V.current) == null || o.focus({ preventScroll: !0 });
471
+ return;
472
+ }
473
+ }, He = (e) => {
474
+ const t = B.current;
475
+ if (!(t && E(t.col) === "date")) {
476
+ if (!t) {
477
+ if (!F(i.col) || E(i.col) === "date") return;
478
+ de({ row: i.row, col: i.col, mode: "replace" });
479
+ }
480
+ te(e.target.value), pe(e.target.value);
481
+ }
482
+ }, Ke = (e) => {
483
+ var t;
484
+ (t = P.current) != null && t.contains(e.relatedTarget) || N(!0);
485
+ }, et = () => {
486
+ ce.current = !0, B.current || J("replace");
487
+ }, tt = (e) => {
488
+ ce.current = !1, Ce.current = e.timeStamp;
489
+ }, rt = (e) => {
490
+ B.current || (e.preventDefault(), e.clipboardData.setData("text/plain", me()));
491
+ }, ot = (e) => {
492
+ B.current || (e.preventDefault(), e.clipboardData.setData("text/plain", me()), we());
493
+ }, nt = (e) => {
494
+ if (B.current) return;
495
+ e.preventDefault();
496
+ const t = e.clipboardData.getData("text/plain");
497
+ t && Qe(t);
498
+ }, ct = (e, t) => {
499
+ const r = P.current, o = r.getBoundingClientRect(), n = e - o.left + r.scrollLeft - b, a = t - o.top + r.scrollTop - M, l = S(Math.floor(a / y), 0, Math.max(0, w - 1));
500
+ let f = p - 1;
501
+ for (let u = 0; u < p; u++)
502
+ if (n < O[u + 1]) {
503
+ f = u;
504
+ break;
505
+ }
506
+ return { row: l, col: S(f, 0, Math.max(0, p - 1)) };
507
+ }, lt = () => {
508
+ const e = (r) => {
509
+ if (!P.current) return;
510
+ const o = ct(r.clientX, r.clientY);
511
+ A((n) => ae(n, o));
512
+ }, t = () => {
513
+ window.removeEventListener("mousemove", e), window.removeEventListener("mouseup", t);
514
+ };
515
+ window.addEventListener("mousemove", e), window.addEventListener("mouseup", t);
516
+ }, We = (e, t, r) => {
517
+ A(t ? (o) => ae(o, e.focus) : r ? (o) => [...o, e] : [e]);
518
+ }, st = (e) => {
519
+ var f;
520
+ if (e.button !== 0) return;
521
+ const t = e.target;
522
+ if (t === V.current || j.current && j.current.contains(t) || ne.current && ne.current.contains(t) || t === P.current || (e.preventDefault(), (f = V.current) == null || f.focus({ preventScroll: !0 }), w === 0 || p === 0)) return;
523
+ N();
524
+ const r = e.ctrlKey || e.metaKey, o = t.closest("[data-corner]"), n = t.closest("[data-hcol]"), a = t.closest("[data-rownum]"), l = t.closest("[data-row]");
525
+ if (o) {
526
+ Le();
527
+ return;
528
+ }
529
+ if (n) {
530
+ const u = Number(n.dataset.hcol);
531
+ We(
532
+ { anchor: { row: 0, col: u }, focus: { row: w - 1, col: u } },
533
+ e.shiftKey,
534
+ r
535
+ );
536
+ return;
537
+ }
538
+ if (a) {
539
+ const u = Number(a.dataset.rownum);
540
+ We(
541
+ { anchor: { row: u, col: 0 }, focus: { row: u, col: p - 1 } },
542
+ e.shiftKey,
543
+ r
544
+ );
545
+ return;
546
+ }
547
+ if (l) {
548
+ const u = { row: Number(l.dataset.row), col: Number(l.dataset.col) };
549
+ e.shiftKey ? A((C) => ae(C, u)) : A(r ? (C) => [...C, { anchor: u, focus: u }] : [{ anchor: u, focus: u }]), lt();
550
+ }
551
+ }, at = (e) => {
552
+ var t;
553
+ return ((t = c == null ? void 0 : c[e]) == null ? void 0 : t.resizable) ?? Xe;
554
+ }, it = (e, t) => {
555
+ var u;
556
+ if (e.button !== 0) return;
557
+ e.preventDefault(), e.stopPropagation(), (u = V.current) == null || u.focus({ preventScroll: !0 });
558
+ const r = e.clientX, o = L[t], n = (C) => Math.max(Mt, o + (C - r));
559
+ xe(t);
560
+ const a = document.body.style.cursor;
561
+ document.body.style.cursor = "col-resize";
562
+ const l = (C) => {
563
+ const k = n(C.clientX);
564
+ be((R) => R[t] === k ? R : { ...R, [t]: k });
565
+ }, f = (C) => {
566
+ window.removeEventListener("mousemove", l), window.removeEventListener("mouseup", f), document.body.style.cursor = a, xe(null);
567
+ const k = n(C.clientX);
568
+ be((R) => R[t] === k ? R : { ...R, [t]: k }), v == null || v(t, k);
569
+ };
570
+ window.addEventListener("mousemove", l), window.addEventListener("mouseup", f);
571
+ }, ut = (e) => {
572
+ const t = e.target.closest("[data-row]");
573
+ t && J("edit", { row: Number(t.dataset.row), col: Number(t.dataset.col) });
574
+ }, ft = Math.max(0, Math.floor(Me / y) - $e), dt = Math.min(
575
+ w,
576
+ Math.ceil((Me + Math.max(0, Ee - M)) / y) + $e
577
+ ), pt = (e) => T.some((t) => e >= t.left && e <= t.right), ht = (e) => T.some((t) => e >= t.top && e <= t.bottom), Ie = [];
578
+ for (let e = ft; e < dt; e++) {
579
+ const t = [];
580
+ m && t.push(
581
+ /* @__PURE__ */ W(
582
+ "div",
583
+ {
584
+ "data-rownum": e,
585
+ className: "masume-grid-rownum" + (ht(e) ? " masume-grid-rownum--sel" : ""),
586
+ style: { width: b, height: y },
587
+ children: e + 1
588
+ },
589
+ "rownum"
590
+ )
591
+ );
592
+ for (let r = 0; r < p; r++) {
593
+ const o = T.some(
594
+ (u) => e >= u.top && e <= u.bottom && r >= u.left && r <= u.right
595
+ ), n = e === i.row && r === i.col, a = E(r), l = ((Oe = s[e]) == null ? void 0 : Oe[r]) ?? "", f = a === "select" ? ((Pe = he.get(r)) == null ? void 0 : Pe.get(l)) ?? l : l;
596
+ t.push(
597
+ /* @__PURE__ */ H(
598
+ "div",
599
+ {
600
+ "data-row": e,
601
+ "data-col": r,
602
+ role: "gridcell",
603
+ "aria-selected": o,
604
+ className: "masume-grid-cell" + (o ? " masume-grid-cell--sel" : "") + (n ? " masume-grid-cell--active" : "") + (F(r) ? "" : " masume-grid-cell--readonly") + (a === "number" ? " masume-grid-cell--num" : "") + (a === "select" ? " masume-grid-cell--select" : ""),
605
+ style: { width: L[r], height: y },
606
+ children: [
607
+ f,
608
+ a === "select" && /* @__PURE__ */ W("span", { className: "masume-grid-cell-arrow", children: "▾" })
609
+ ]
610
+ },
611
+ r
612
+ )
613
+ );
614
+ }
615
+ Ie.push(
616
+ /* @__PURE__ */ W(
617
+ "div",
618
+ {
619
+ role: "row",
620
+ className: "masume-grid-row",
621
+ style: { top: e * y, width: fe, height: y },
622
+ children: t
623
+ },
624
+ e
625
+ )
626
+ );
627
+ }
628
+ const ie = h ?? i, mt = w > 0 && p > 0, Ve = h !== null && Z === "date", ze = h !== null && !Ve;
629
+ return /* @__PURE__ */ H(
630
+ "div",
631
+ {
632
+ ref: P,
633
+ role: "grid",
634
+ "aria-rowcount": w,
635
+ "aria-colcount": p,
636
+ className: "masume-grid" + (De !== null ? " masume-grid--resizing" : "") + (ve ? " " + ve : ""),
637
+ style: qe,
638
+ onScroll: (e) => Ge(e.target.scrollTop),
639
+ onMouseDown: st,
640
+ onDoubleClick: ut,
641
+ children: [
642
+ q && /* @__PURE__ */ H("div", { className: "masume-grid-head", style: { width: fe, height: M }, children: [
643
+ m && /* @__PURE__ */ W(
644
+ "div",
645
+ {
646
+ "data-corner": !0,
647
+ className: "masume-grid-corner",
648
+ style: { width: b, height: M }
649
+ }
650
+ ),
651
+ Array.from({ length: p }, (e, t) => {
652
+ var r;
653
+ return /* @__PURE__ */ H(
654
+ "div",
655
+ {
656
+ "data-hcol": t,
657
+ className: "masume-grid-hcell" + (pt(t) ? " masume-grid-hcell--sel" : ""),
658
+ style: { width: L[t], height: M },
659
+ children: [
660
+ /* @__PURE__ */ W("span", { className: "masume-grid-hcell-label", children: ((r = c == null ? void 0 : c[t]) == null ? void 0 : r.title) ?? wt(t) }),
661
+ at(t) && /* @__PURE__ */ W(
662
+ "div",
663
+ {
664
+ className: "masume-grid-resize-handle" + (De === t ? " masume-grid-resize-handle--active" : ""),
665
+ onMouseDown: (o) => it(o, t),
666
+ onDoubleClick: (o) => o.stopPropagation()
667
+ }
668
+ )
669
+ ]
670
+ },
671
+ t
672
+ );
673
+ })
674
+ ] }),
675
+ /* @__PURE__ */ H("div", { className: "masume-grid-body", style: { width: fe, height: Ye }, children: [
676
+ Ie,
677
+ mt && /* @__PURE__ */ W(
678
+ "textarea",
679
+ {
680
+ ref: V,
681
+ className: "masume-grid-editor" + (ze ? "" : " masume-grid-editor--hidden"),
682
+ style: {
683
+ top: ie.row * y,
684
+ left: b + O[ie.col],
685
+ width: L[ie.col],
686
+ height: y
687
+ },
688
+ value: ze ? X : "",
689
+ onChange: He,
690
+ onKeyDown: Je,
691
+ onCompositionStart: et,
692
+ onCompositionEnd: tt,
693
+ onCopy: rt,
694
+ onCut: ot,
695
+ onPaste: nt,
696
+ onBlur: Ke,
697
+ readOnly: !h && !F(i.col),
698
+ inputMode: E(ie.col) === "number" ? "decimal" : void 0,
699
+ wrap: "off",
700
+ rows: 1,
701
+ spellCheck: !1,
702
+ autoCapitalize: "off",
703
+ autoCorrect: "off",
704
+ "aria-label": "cell editor"
705
+ }
706
+ ),
707
+ h && Ve && /* @__PURE__ */ W(
708
+ "input",
709
+ {
710
+ ref: j,
711
+ type: "date",
712
+ className: "masume-grid-editor masume-grid-editor--date",
713
+ style: {
714
+ top: h.row * y,
715
+ left: b + O[h.col],
716
+ width: Math.max(L[h.col], 150),
717
+ height: y
718
+ },
719
+ value: X,
720
+ onChange: (e) => te(e.target.value),
721
+ onKeyDown: Ze,
722
+ onBlur: Ke,
723
+ "aria-label": "date editor"
724
+ }
725
+ ),
726
+ h && K && K.length > 0 && /* @__PURE__ */ W(
727
+ "div",
728
+ {
729
+ ref: ne,
730
+ className: "masume-grid-dropdown",
731
+ role: "listbox",
732
+ style: {
733
+ top: (h.row + 1) * y,
734
+ left: b + O[h.col],
735
+ minWidth: L[h.col]
736
+ },
737
+ children: K.map((e, t) => /* @__PURE__ */ W(
738
+ "div",
739
+ {
740
+ role: "option",
741
+ "aria-selected": t === G,
742
+ className: "masume-grid-option" + (t === G ? " masume-grid-option--hi" : ""),
743
+ onMouseDown: (r) => {
744
+ r.preventDefault(), r.stopPropagation(), N(!0, e.value);
745
+ },
746
+ onMouseEnter: () => oe(t),
747
+ children: e.label
748
+ },
749
+ `${e.value}\0${t}`
750
+ ))
751
+ }
752
+ )
753
+ ] })
754
+ ]
755
+ }
756
+ );
757
+ }
758
+ export {
759
+ Ct as MasumeGrid,
760
+ Fe as normalizeDateInput,
761
+ yt as normalizeNumberInput,
762
+ Ue as toHalfWidth
763
+ };