react-excel-lite 0.0.7 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,298 +1,341 @@
1
- import { jsxs as K, jsx as v } from "react/jsx-runtime";
2
- import { useState as L, useCallback as C, useEffect as W, useRef as O, useMemo as U } from "react";
3
- function H(...o) {
4
- return o.filter(Boolean).join(" ");
1
+ import { jsxs as A, jsx as N, Fragment as Q } from "react/jsx-runtime";
2
+ import { useState as z, useCallback as M, useEffect as j, useRef as U, useLayoutEffect as Y, useMemo as $ } from "react";
3
+ function W(...e) {
4
+ return e.filter(Boolean).join(" ");
5
5
  }
6
- function Co(o) {
7
- return `${o.row}-${o.col}`;
6
+ function ke(e) {
7
+ return `${e.row}-${e.col}`;
8
8
  }
9
- function xo(o) {
10
- const [t, n] = o.split("-").map(Number);
11
- return { row: t, col: n };
9
+ function Ee(e) {
10
+ const [o, l] = e.split("-").map(Number);
11
+ return { row: o, col: l };
12
12
  }
13
- function So(o, t) {
14
- if (!o || !t) return o ? [o] : [];
15
- const n = Math.min(o.row, t.row), s = Math.max(o.row, t.row), u = Math.min(o.col, t.col), b = Math.max(o.col, t.col), c = [];
16
- for (let h = n; h <= s; h++)
17
- for (let f = u; f <= b; f++)
18
- c.push({ row: h, col: f });
19
- return c;
13
+ function ve(e, o) {
14
+ if (!e || !o) return e ? [e] : [];
15
+ const l = Math.min(e.row, o.row), i = Math.max(e.row, o.row), a = Math.min(e.col, o.col), x = Math.max(e.col, o.col), u = [];
16
+ for (let m = l; m <= i; m++)
17
+ for (let f = a; f <= x; f++)
18
+ u.push({ row: m, col: f });
19
+ return u;
20
20
  }
21
- function X(o, t) {
22
- if (!t.start) return !1;
23
- const n = t.end || t.start, s = Math.min(t.start.row, n.row), u = Math.max(t.start.row, n.row), b = Math.min(t.start.col, n.col), c = Math.max(t.start.col, n.col);
24
- return o.row >= s && o.row <= u && o.col >= b && o.col <= c;
21
+ function Z(e, o) {
22
+ if (!o.start) return !1;
23
+ const l = o.end || o.start, i = Math.min(o.start.row, l.row), a = Math.max(o.start.row, l.row), x = Math.min(o.start.col, l.col), u = Math.max(o.start.col, l.col);
24
+ return e.row >= i && e.row <= a && e.col >= x && e.col <= u;
25
25
  }
26
- function _(o) {
27
- return o.split(/\r?\n/).filter((t) => t.trim()).map((t) => t.split(" ").map((n) => n.trim()));
26
+ function ee(e) {
27
+ return e.split(/\r?\n/).filter((o) => o.trim()).map((o) => o.split(" ").map((l) => l.trim()));
28
28
  }
29
- function J(o) {
30
- return o.map((t) => t.join(" ")).join(`
29
+ function te(e) {
30
+ return e.map((o) => o.join(" ")).join(`
31
31
  `);
32
32
  }
33
- function j(o) {
34
- return !o.start || !o.end ? o : {
33
+ function B(e) {
34
+ return !e.start || !e.end ? e : {
35
35
  start: {
36
- row: Math.min(o.start.row, o.end.row),
37
- col: Math.min(o.start.col, o.end.col)
36
+ row: Math.min(e.start.row, e.end.row),
37
+ col: Math.min(e.start.col, e.end.col)
38
38
  },
39
39
  end: {
40
- row: Math.max(o.start.row, o.end.row),
41
- col: Math.max(o.start.col, o.end.col)
40
+ row: Math.max(e.start.row, e.end.row),
41
+ col: Math.max(e.start.col, e.end.col)
42
42
  }
43
43
  };
44
44
  }
45
- function yo(o, t) {
46
- if (o.row === t.row && o.col === t.col)
45
+ function Fe(e, o) {
46
+ if (e.row === o.row && e.col === o.col)
47
47
  return [];
48
- const n = Math.min(o.row, t.row), s = Math.max(o.row, t.row), u = Math.min(o.col, t.col), b = Math.max(o.col, t.col), c = [];
49
- for (let h = n; h <= s; h++)
50
- for (let f = u; f <= b; f++)
51
- h === o.row && f === o.col || c.push({ row: h, col: f });
52
- return c;
48
+ const l = Math.min(e.row, o.row), i = Math.max(e.row, o.row), a = Math.min(e.col, o.col), x = Math.max(e.col, o.col), u = [];
49
+ for (let m = l; m <= i; m++)
50
+ for (let f = a; f <= x; f++)
51
+ m === e.row && f === e.col || u.push({ row: m, col: f });
52
+ return u;
53
53
  }
54
- function Q() {
55
- const [o, t] = L({
54
+ function oe({
55
+ containerRef: e
56
+ }) {
57
+ const [o, l] = z({
56
58
  start: null,
57
59
  end: null
58
- }), [n, s] = L(!1), u = C((a) => {
59
- t({ start: a, end: a }), s(!0);
60
- }, []), b = C(
61
- (a) => {
62
- n && t((l) => ({ ...l, end: a }));
60
+ }), [i, a] = z(!1), x = M((c) => {
61
+ l({ start: c, end: c }), a(!0);
62
+ }, []), u = M(
63
+ (c) => {
64
+ i && l((n) => ({ ...n, end: c }));
63
65
  },
64
- [n]
65
- ), c = C(() => {
66
- s(!1);
67
- }, []), h = C(() => {
68
- t({ start: null, end: null }), s(!1);
69
- }, []), f = C(
70
- (a) => X(a, o),
66
+ [i]
67
+ ), m = M(() => {
68
+ a(!1);
69
+ }, []), f = M(() => {
70
+ l({ start: null, end: null }), a(!1);
71
+ }, []), g = M(
72
+ (c) => Z(c, o),
71
73
  [o]
72
74
  );
73
- return W(() => {
74
- const a = () => {
75
- n && s(!1);
75
+ return j(() => {
76
+ const c = () => {
77
+ i && a(!1);
78
+ };
79
+ return window.addEventListener("mouseup", c), () => window.removeEventListener("mouseup", c);
80
+ }, [i]), j(() => {
81
+ const c = (n) => {
82
+ e.current && !e.current.contains(n.target) && f();
76
83
  };
77
- return window.addEventListener("mouseup", a), () => window.removeEventListener("mouseup", a);
78
- }, [n]), {
84
+ return document.addEventListener("mousedown", c), () => document.removeEventListener("mousedown", c);
85
+ }, [e, f]), {
79
86
  selection: o,
80
- isSelecting: n,
81
- isCellSelected: f,
82
- handleCellMouseDown: u,
83
- handleCellMouseEnter: b,
84
- handleMouseUp: c,
85
- clearSelection: h,
86
- setSelection: t
87
+ isSelecting: i,
88
+ isCellSelected: g,
89
+ handleCellMouseDown: x,
90
+ handleCellMouseEnter: u,
91
+ handleMouseUp: m,
92
+ clearSelection: f,
93
+ setSelection: l
87
94
  };
88
95
  }
89
- function Y({
90
- selection: o,
91
- getValue: t,
92
- setValues: n,
93
- rowCount: s,
94
- colCount: u
96
+ function ne({
97
+ selection: e,
98
+ getValue: o,
99
+ setValues: l,
100
+ setSelection: i,
101
+ rowCount: a,
102
+ colCount: x
95
103
  }) {
96
- const b = C(() => {
97
- const l = j(o);
98
- if (!l.start || !l.end) return [];
99
- const x = [];
100
- for (let y = l.start.row; y <= l.end.row; y++) {
101
- const M = [];
102
- for (let g = l.start.col; g <= l.end.col; g++)
103
- M.push(t({ row: y, col: g }));
104
- x.push(M);
104
+ const u = M(() => {
105
+ const n = B(e);
106
+ if (!n.start || !n.end) return [];
107
+ const S = [];
108
+ for (let d = n.start.row; d <= n.end.row; d++) {
109
+ const C = [];
110
+ for (let r = n.start.col; r <= n.end.col; r++)
111
+ C.push(o({ row: d, col: r }));
112
+ S.push(C);
105
113
  }
106
- return x;
107
- }, [o, t]), c = C(async () => {
108
- const l = b();
109
- if (l.length === 0) return;
110
- const x = J(l);
114
+ return S;
115
+ }, [e, o]), m = M(async () => {
116
+ const n = u();
117
+ if (n.length === 0) return;
118
+ const S = te(n);
111
119
  try {
112
- await navigator.clipboard.writeText(x);
113
- } catch (y) {
114
- console.error("Clipboard copy failed:", y);
120
+ await navigator.clipboard.writeText(S);
121
+ } catch (d) {
122
+ console.error("Clipboard copy failed:", d);
115
123
  }
116
- }, [b]), h = C(async () => {
117
- if (o.start)
124
+ }, [u]), f = M(async () => {
125
+ if (e.start)
118
126
  try {
119
- const l = await navigator.clipboard.readText(), x = _(l);
120
- if (x.length === 0) return;
121
- const y = o.start.row, M = o.start.col, g = [];
122
- x.forEach((w, p) => {
123
- const d = y + p;
124
- d >= s || w.forEach((i, R) => {
125
- const F = M + R;
126
- F >= u || g.push({ coord: { row: d, col: F }, value: i });
127
+ const n = await navigator.clipboard.readText(), S = ee(n);
128
+ if (S.length === 0) return;
129
+ const d = e.start.row, C = e.start.col, r = [];
130
+ S.forEach((b, w) => {
131
+ const h = d + w;
132
+ h >= a || b.forEach((F, v) => {
133
+ const s = C + v;
134
+ s >= x || r.push({ coord: { row: h, col: s }, value: F });
127
135
  });
128
- }), g.length > 0 && n(g);
129
- } catch (l) {
130
- console.error("Clipboard paste failed:", l);
136
+ }), r.length > 0 && l(r);
137
+ } catch (n) {
138
+ console.error("Clipboard paste failed:", n);
139
+ }
140
+ }, [e.start, l, a, x]), g = M(() => {
141
+ const n = B(e);
142
+ if (!n.start || !n.end) return;
143
+ const S = [];
144
+ for (let d = n.start.row; d <= n.end.row; d++)
145
+ for (let C = n.start.col; C <= n.end.col; C++)
146
+ S.push({ coord: { row: d, col: C }, value: "" });
147
+ S.length > 0 && l(S);
148
+ }, [e, l]), c = M(
149
+ (n) => {
150
+ if (!(n.target instanceof HTMLInputElement && !n.target.readOnly)) {
151
+ if (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(n.key)) {
152
+ n.preventDefault();
153
+ const d = B(e).start ?? { row: 0, col: 0 };
154
+ let C = d.row, r = d.col;
155
+ switch (n.key) {
156
+ case "ArrowUp":
157
+ C = Math.max(0, d.row - 1);
158
+ break;
159
+ case "ArrowDown":
160
+ C = Math.min(a - 1, d.row + 1);
161
+ break;
162
+ case "ArrowLeft":
163
+ r = Math.max(0, d.col - 1);
164
+ break;
165
+ case "ArrowRight":
166
+ r = Math.min(x - 1, d.col + 1);
167
+ break;
168
+ }
169
+ i({
170
+ start: { row: C, col: r },
171
+ end: { row: C, col: r }
172
+ });
173
+ return;
174
+ }
175
+ (n.ctrlKey || n.metaKey) && n.key === "c" && (n.preventDefault(), m()), (n.ctrlKey || n.metaKey) && n.key === "v" && (n.preventDefault(), f()), (n.key === "Backspace" || n.key === "Delete") && (n.preventDefault(), g());
131
176
  }
132
- }, [o.start, n, s, u]), f = C(() => {
133
- const l = j(o);
134
- if (!l.start || !l.end) return;
135
- const x = [];
136
- for (let y = l.start.row; y <= l.end.row; y++)
137
- for (let M = l.start.col; M <= l.end.col; M++)
138
- x.push({ coord: { row: y, col: M }, value: "" });
139
- x.length > 0 && n(x);
140
- }, [o, n]), a = C(
141
- (l) => {
142
- (l.ctrlKey || l.metaKey) && l.key === "c" && (l.preventDefault(), c()), (l.ctrlKey || l.metaKey) && l.key === "v" && (l.preventDefault(), h()), (l.key === "Backspace" || l.key === "Delete") && (l.preventDefault(), f());
143
177
  },
144
- [c, h, f]
178
+ [
179
+ m,
180
+ f,
181
+ g,
182
+ e,
183
+ i,
184
+ a,
185
+ x
186
+ ]
145
187
  );
146
188
  return {
147
- handleCopy: c,
148
- handlePaste: h,
149
- handleKeyDown: a
189
+ handleCopy: m,
190
+ handlePaste: f,
191
+ handleKeyDown: c
150
192
  };
151
193
  }
152
- function Z(o) {
153
- if (o.trim() === "") return null;
154
- const t = Number(o);
155
- return isNaN(t) ? null : t;
194
+ function le(e) {
195
+ if (e.trim() === "") return null;
196
+ const o = Number(e);
197
+ return isNaN(o) ? null : o;
156
198
  }
157
- function q(o) {
158
- if (o.length === 0) return null;
159
- const t = o.map(Z);
160
- if (t.some((u) => u === null)) return null;
161
- const n = t;
162
- if (n.length === 1)
163
- return { numbers: n, diff: 0 };
164
- const s = n[1] - n[0];
165
- for (let u = 2; u < n.length; u++)
166
- if (n[u] - n[u - 1] !== s)
167
- return { numbers: n, diff: 0 };
168
- return { numbers: n, diff: s };
199
+ function X(e) {
200
+ if (e.length === 0) return null;
201
+ const o = e.map(le);
202
+ if (o.some((a) => a === null)) return null;
203
+ const l = o;
204
+ if (l.length === 1)
205
+ return { numbers: l, diff: 0 };
206
+ const i = l[1] - l[0];
207
+ for (let a = 2; a < l.length; a++)
208
+ if (l[a] - l[a - 1] !== i)
209
+ return { numbers: l, diff: 0 };
210
+ return { numbers: l, diff: i };
169
211
  }
170
- function oo({
171
- selection: o,
172
- getValue: t,
173
- setValues: n
212
+ function re({
213
+ selection: e,
214
+ getValue: o,
215
+ setValues: l
174
216
  }) {
175
- const [s, u] = L(null), [b, c] = L([]), [h, f] = L(!1), [a, l] = L(null), x = C((w) => {
176
- u(w), f(!0), c([]), l(null);
177
- }, []), y = C(
178
- (w) => {
179
- if (!h || !o.start) return;
180
- const p = j(o);
181
- if (!p.start || !p.end) return;
182
- l(w);
183
- const d = {
184
- row: Math.min(p.start.row, w.row),
185
- col: Math.min(p.start.col, w.col)
186
- }, i = {
187
- row: Math.max(p.end.row, w.row),
188
- col: Math.max(p.end.col, w.col)
189
- }, R = [];
190
- for (let F = d.row; F <= i.row; F++)
191
- for (let r = d.col; r <= i.col; r++)
192
- F >= p.start.row && F <= p.end.row && r >= p.start.col && r <= p.end.col || R.push({ row: F, col: r });
193
- c(R);
217
+ const [i, a] = z(null), [x, u] = z([]), [m, f] = z(!1), [g, c] = z(null), n = M((r) => {
218
+ a(r), f(!0), u([]), c(null);
219
+ }, []), S = M(
220
+ (r) => {
221
+ if (!m || !e.start) return;
222
+ const b = B(e);
223
+ if (!b.start || !b.end) return;
224
+ c(r);
225
+ const w = {
226
+ row: Math.min(b.start.row, r.row),
227
+ col: Math.min(b.start.col, r.col)
228
+ }, h = {
229
+ row: Math.max(b.end.row, r.row),
230
+ col: Math.max(b.end.col, r.col)
231
+ }, F = [];
232
+ for (let v = w.row; v <= h.row; v++)
233
+ for (let s = w.col; s <= h.col; s++)
234
+ v >= b.start.row && v <= b.end.row && s >= b.start.col && s <= b.end.col || F.push({ row: v, col: s });
235
+ u(F);
194
236
  },
195
- [h, o]
196
- ), M = C(() => {
197
- if (!o.start || b.length === 0 || !a) {
198
- u(null), c([]), f(!1), l(null);
237
+ [m, e]
238
+ ), d = M(() => {
239
+ if (!e.start || x.length === 0 || !g) {
240
+ a(null), u([]), f(!1), c(null);
199
241
  return;
200
242
  }
201
- const w = j(o);
202
- if (!w.start || !w.end) {
203
- u(null), c([]), f(!1), l(null);
243
+ const r = B(e);
244
+ if (!r.start || !r.end) {
245
+ a(null), u([]), f(!1), c(null);
204
246
  return;
205
247
  }
206
- const p = [], d = w.start, i = w.end, R = i.row - d.row + 1, F = i.col - d.col + 1;
207
- b.forEach((r) => {
208
- let k, T;
209
- if (r.row < d.row) {
210
- const N = d.row - r.row;
211
- k = i.row - (N - 1) % R;
212
- } else if (r.row > i.row) {
213
- const N = r.row - i.row;
214
- k = d.row + (N - 1) % R;
248
+ const b = [], w = r.start, h = r.end, F = h.row - w.row + 1, v = h.col - w.col + 1;
249
+ x.forEach((s) => {
250
+ let R, I;
251
+ if (s.row < w.row) {
252
+ const E = w.row - s.row;
253
+ R = h.row - (E - 1) % F;
254
+ } else if (s.row > h.row) {
255
+ const E = s.row - h.row;
256
+ R = w.row + (E - 1) % F;
215
257
  } else
216
- k = r.row;
217
- if (r.col < d.col) {
218
- const N = d.col - r.col;
219
- T = i.col - (N - 1) % F;
220
- } else if (r.col > i.col) {
221
- const N = r.col - i.col;
222
- T = d.col + (N - 1) % F;
258
+ R = s.row;
259
+ if (s.col < w.col) {
260
+ const E = w.col - s.col;
261
+ I = h.col - (E - 1) % v;
262
+ } else if (s.col > h.col) {
263
+ const E = s.col - h.col;
264
+ I = w.col + (E - 1) % v;
223
265
  } else
224
- T = r.col;
225
- let G = t({ row: k, col: T });
226
- if (r.row !== k && r.col >= d.col && r.col <= i.col) {
227
- const N = [];
228
- for (let S = d.row; S <= i.row; S++)
229
- N.push(t({ row: S, col: r.col }));
230
- const D = q(N);
266
+ I = s.col;
267
+ let H = o({ row: R, col: I });
268
+ if (s.row !== R && s.col >= w.col && s.col <= h.col) {
269
+ const E = [];
270
+ for (let k = w.row; k <= h.row; k++)
271
+ E.push(o({ row: k, col: s.col }));
272
+ const D = X(E);
231
273
  if (D && D.diff !== 0) {
232
- if (r.row > i.row) {
233
- const S = r.row - i.row;
234
- G = String(D.numbers[D.numbers.length - 1] + D.diff * S);
235
- } else if (r.row < d.row) {
236
- const S = d.row - r.row;
237
- G = String(D.numbers[0] - D.diff * S);
274
+ if (s.row > h.row) {
275
+ const k = s.row - h.row;
276
+ H = String(D.numbers[D.numbers.length - 1] + D.diff * k);
277
+ } else if (s.row < w.row) {
278
+ const k = w.row - s.row;
279
+ H = String(D.numbers[0] - D.diff * k);
238
280
  }
239
281
  }
240
282
  }
241
- if (r.col !== T && r.row >= d.row && r.row <= i.row) {
242
- const N = [];
243
- for (let S = d.col; S <= i.col; S++)
244
- N.push(t({ row: r.row, col: S }));
245
- const D = q(N);
283
+ if (s.col !== I && s.row >= w.row && s.row <= h.row) {
284
+ const E = [];
285
+ for (let k = w.col; k <= h.col; k++)
286
+ E.push(o({ row: s.row, col: k }));
287
+ const D = X(E);
246
288
  if (D && D.diff !== 0) {
247
- if (r.col > i.col) {
248
- const S = r.col - i.col;
249
- G = String(D.numbers[D.numbers.length - 1] + D.diff * S);
250
- } else if (r.col < d.col) {
251
- const S = d.col - r.col;
252
- G = String(D.numbers[0] - D.diff * S);
289
+ if (s.col > h.col) {
290
+ const k = s.col - h.col;
291
+ H = String(D.numbers[D.numbers.length - 1] + D.diff * k);
292
+ } else if (s.col < w.col) {
293
+ const k = w.col - s.col;
294
+ H = String(D.numbers[0] - D.diff * k);
253
295
  }
254
296
  }
255
297
  }
256
- p.push({ coord: r, value: G });
257
- }), p.length > 0 && n(p), u(null), c([]), f(!1), l(null);
258
- }, [o, b, a, t, n]), g = C(
259
- (w) => b.some(
260
- (p) => p.row === w.row && p.col === w.col
298
+ b.push({ coord: s, value: H });
299
+ }), b.length > 0 && l(b), a(null), u([]), f(!1), c(null);
300
+ }, [e, x, g, o, l]), C = M(
301
+ (r) => x.some(
302
+ (b) => b.row === r.row && b.col === r.col
261
303
  ),
262
- [b]
304
+ [x]
263
305
  );
264
- return W(() => {
265
- const w = () => {
266
- h && M();
306
+ return j(() => {
307
+ const r = () => {
308
+ m && d();
267
309
  };
268
- return window.addEventListener("mouseup", w), () => window.removeEventListener("mouseup", w);
269
- }, [h, M]), {
270
- fillSource: s,
271
- fillTargets: b,
272
- isDraggingFill: h,
273
- isFillTarget: g,
274
- handleFillHandleMouseDown: x,
275
- handleCellMouseEnterForFill: y,
276
- handleFillMouseUp: M
310
+ return window.addEventListener("mouseup", r), () => window.removeEventListener("mouseup", r);
311
+ }, [m, d]), {
312
+ fillSource: i,
313
+ fillTargets: x,
314
+ isDraggingFill: m,
315
+ isFillTarget: C,
316
+ handleFillHandleMouseDown: n,
317
+ handleCellMouseEnterForFill: S,
318
+ handleFillMouseUp: d
277
319
  };
278
320
  }
279
- const to = {
321
+ const se = {
280
322
  position: "relative",
281
323
  border: "1px solid #d1d5db",
282
- padding: 0
283
- }, no = {
324
+ padding: 0,
325
+ height: "28px",
326
+ minWidth: "80px"
327
+ }, ce = {
284
328
  width: "100%",
285
329
  height: "100%",
286
- paddingLeft: "4px",
287
- paddingRight: "4px",
288
- paddingTop: "4px",
289
- paddingBottom: "4px",
330
+ padding: "4px",
290
331
  textAlign: "right",
291
332
  fontSize: "12px",
333
+ boxSizing: "border-box",
334
+ cursor: "cell",
292
335
  backgroundColor: "transparent",
293
336
  outline: "none",
294
- cursor: "cell"
295
- }, lo = {
337
+ border: "none"
338
+ }, ie = {
296
339
  position: "absolute",
297
340
  bottom: "-2px",
298
341
  right: "-2px",
@@ -301,80 +344,146 @@ const to = {
301
344
  cursor: "crosshair",
302
345
  zIndex: 20,
303
346
  backgroundColor: "#3b82f6"
304
- }, eo = {
347
+ }, ae = {
348
+ position: "absolute",
349
+ top: 0,
350
+ left: 0,
351
+ minWidth: "100%",
352
+ height: "100%",
353
+ zIndex: 30
354
+ }, ue = {
355
+ height: "100%",
356
+ padding: "4px",
357
+ textAlign: "right",
358
+ fontSize: "12px",
359
+ boxSizing: "border-box",
360
+ backgroundColor: "#fff",
361
+ border: "2px solid #3b82f6",
362
+ outline: "none",
363
+ minWidth: "100%"
364
+ }, fe = {
365
+ position: "absolute",
366
+ visibility: "hidden",
367
+ whiteSpace: "pre",
368
+ fontSize: "12px",
369
+ padding: "4px"
370
+ }, de = {
305
371
  backgroundColor: "#dbeafe",
306
372
  outline: "2px solid #3b82f6",
307
373
  outlineOffset: "-2px"
308
- }, ro = {
374
+ }, we = {
309
375
  backgroundColor: "#eff6ff"
310
376
  };
311
- function so({
312
- coord: o,
313
- value: t,
314
- isSelected: n,
315
- isFillTarget: s,
316
- showFillHandle: u,
317
- onMouseDown: b,
318
- onMouseEnter: c,
319
- onChange: h,
377
+ function he({
378
+ coord: e,
379
+ value: o,
380
+ isSelected: l,
381
+ isFillTarget: i,
382
+ showFillHandle: a,
383
+ onMouseDown: x,
384
+ onMouseEnter: u,
385
+ onChange: m,
320
386
  onFillHandleMouseDown: f,
321
- styles: a
387
+ styles: g
322
388
  }) {
323
- const l = (i) => {
324
- h(o, i.target.value);
325
- }, x = (i) => {
326
- i.target.classList.contains("fill-handle") || b(o);
327
- }, y = (i) => {
328
- i.stopPropagation(), i.preventDefault(), f(o);
329
- }, M = !!a?.selected, g = !!a?.fillTarget, w = !!a?.fillHandle, p = {
330
- ...to,
331
- ...n && !M ? eo : {},
332
- ...s && !g ? ro : {}
333
- }, d = {
334
- ...lo,
335
- ...w ? { backgroundColor: void 0 } : {}
389
+ const [c, n] = z(!1), [S, d] = z(!1), [C, r] = z(null), b = U(null), w = U(null), h = U(null), F = U(null);
390
+ Y(() => {
391
+ if (c && h.current && F.current) {
392
+ const t = h.current.offsetWidth, p = F.current.offsetWidth;
393
+ r(Math.max(t + 16, p));
394
+ }
395
+ }, [c, o]), j(() => {
396
+ c && w.current ? (w.current.focus(), S && (w.current.select(), d(!1))) : l && !c && b.current && b.current.focus();
397
+ }, [l, c, S]), j(() => {
398
+ !l && c && (n(!1), r(null));
399
+ }, [l, c]);
400
+ const v = (t) => {
401
+ m(e, t.target.value);
402
+ }, s = (t) => {
403
+ t.target.classList.contains("fill-handle") || x(e);
404
+ }, R = () => {
405
+ n(!0), d(!0);
406
+ }, I = () => {
407
+ n(!1);
408
+ }, H = (t) => {
409
+ c ? (t.key === "Enter" || t.key === "Escape") && n(!1) : t.key === "Enter" ? (t.preventDefault(), n(!0), d(!0)) : t.key.length === 1 && !t.ctrlKey && !t.metaKey && (t.preventDefault(), m(e, t.key), n(!0));
410
+ }, E = (t) => {
411
+ t.stopPropagation(), t.preventDefault(), f(e);
412
+ }, D = !!g?.selected, k = !!g?.fillTarget, O = !!g?.fillHandle, G = {
413
+ ...se,
414
+ ...l && !D ? de : {},
415
+ ...i && !k ? we : {}
416
+ }, q = {
417
+ ...ie,
418
+ ...O ? { backgroundColor: void 0 } : {}
419
+ }, P = {
420
+ ...ce,
421
+ overflow: "hidden",
422
+ textOverflow: "ellipsis"
336
423
  };
337
- return /* @__PURE__ */ K(
424
+ return /* @__PURE__ */ A(
338
425
  "td",
339
426
  {
340
- className: H(
341
- a?.cell,
342
- n && a?.selected,
343
- s && a?.fillTarget
427
+ ref: F,
428
+ className: W(
429
+ g?.cell,
430
+ l && g?.selected,
431
+ i && g?.fillTarget
344
432
  ),
345
- style: p,
346
- onMouseDown: x,
347
- onMouseEnter: () => c(o),
433
+ style: G,
434
+ onMouseDown: s,
435
+ onMouseEnter: () => u(e),
436
+ onDoubleClick: R,
348
437
  children: [
349
- /* @__PURE__ */ v(
438
+ /* @__PURE__ */ N(
350
439
  "input",
351
440
  {
441
+ ref: b,
352
442
  type: "text",
353
- value: t,
354
- onChange: l,
355
- style: no
443
+ value: o,
444
+ readOnly: !0,
445
+ onChange: v,
446
+ onKeyDown: H,
447
+ style: P,
448
+ tabIndex: c ? -1 : 0
356
449
  }
357
450
  ),
358
- u && /* @__PURE__ */ v(
451
+ c && /* @__PURE__ */ N("div", { style: ae, children: /* @__PURE__ */ N(
452
+ "input",
453
+ {
454
+ ref: w,
455
+ type: "text",
456
+ value: o,
457
+ onChange: v,
458
+ onBlur: I,
459
+ onKeyDown: H,
460
+ style: {
461
+ ...ue,
462
+ width: C ?? "100%"
463
+ }
464
+ }
465
+ ) }),
466
+ c && /* @__PURE__ */ N("span", { ref: h, style: fe, children: o }),
467
+ a && /* @__PURE__ */ N(
359
468
  "div",
360
469
  {
361
- className: H("fill-handle", a?.fillHandle),
362
- style: d,
363
- onMouseDown: y
470
+ className: W("fill-handle", g?.fillHandle),
471
+ style: q,
472
+ onMouseDown: E
364
473
  }
365
474
  )
366
475
  ]
367
476
  }
368
477
  );
369
478
  }
370
- const co = {
479
+ const pe = {
371
480
  outline: "none",
372
481
  overflowX: "auto"
373
- }, io = {
482
+ }, me = {
374
483
  borderCollapse: "collapse",
375
484
  fontSize: "12px",
376
485
  userSelect: "none"
377
- }, ao = {
486
+ }, be = {
378
487
  position: "sticky",
379
488
  left: 0,
380
489
  zIndex: 10,
@@ -382,222 +491,255 @@ const co = {
382
491
  padding: "6px 8px",
383
492
  textAlign: "center",
384
493
  fontWeight: 500
385
- }, uo = {
494
+ }, ye = {
386
495
  border: "1px solid #d1d5db",
387
496
  padding: "6px 4px",
388
497
  textAlign: "center",
389
498
  fontWeight: 500
390
- }, fo = {
499
+ }, xe = {
391
500
  border: "1px solid #d1d5db",
392
501
  padding: "4px",
393
502
  textAlign: "center",
394
503
  fontWeight: 500,
395
504
  fontSize: "11px"
396
- }, wo = {
505
+ }, ge = {
397
506
  backgroundColor: "#f3f4f6"
398
- }, ho = {
507
+ }, Se = {
399
508
  backgroundColor: "#dbeafe",
400
509
  color: "#1d4ed8"
401
- }, po = {
510
+ }, Ce = {
402
511
  backgroundColor: "#f9fafb"
403
512
  };
404
- function Mo({
405
- data: o,
406
- onChange: t,
407
- rowHeaders: n,
408
- colHeaders: s,
409
- className: u,
410
- rowHeaderTitle: b = "",
411
- styles: c
513
+ function Ne({
514
+ data: e,
515
+ onChange: o,
516
+ rowHeaders: l,
517
+ colHeaders: i,
518
+ className: a,
519
+ rowHeaderTitle: x = "",
520
+ styles: u
412
521
  }) {
413
- const h = O(null), f = o.length, a = U(() => s ? s.reduce(
414
- (e, m) => e + m.headers.length,
522
+ const m = U(null), f = e.length, g = $(() => i ? i.reduce(
523
+ (t, p) => t + p.headers.length,
415
524
  0
416
- ) : o[0]?.length ?? 0, [s, o]), l = U(() => s ? s.flatMap((e) => e.headers) : [], [s]), x = C(
417
- (e) => e.row < 0 || e.row >= f || e.col < 0 || e.col >= a ? "" : o[e.row]?.[e.col] ?? "",
418
- [o, f, a]
419
- ), y = C(
420
- (e, m) => {
421
- const E = o.map(
422
- (z, B) => B === e.row ? z.map(
423
- (A, I) => I === e.col ? m : A
424
- ) : z
525
+ ) : e[0]?.length ?? 0, [i, e]), c = $(() => i ? i.flatMap((t) => t.headers) : [], [i]), n = $(() => {
526
+ if (!l) return null;
527
+ const t = [];
528
+ return l.forEach((p, y) => {
529
+ p.headers.forEach((L, K) => {
530
+ t.push({
531
+ groupIndex: y,
532
+ isFirstInGroup: K === 0,
533
+ groupLabel: p.label,
534
+ groupRowCount: p.headers.length,
535
+ rowHeader: L,
536
+ groupClassName: p.className,
537
+ groupDescription: p.description
538
+ });
539
+ });
540
+ }), t;
541
+ }, [l]), S = M(
542
+ (t) => t.row < 0 || t.row >= f || t.col < 0 || t.col >= g ? "" : e[t.row]?.[t.col] ?? "",
543
+ [e, f, g]
544
+ ), d = M(
545
+ (t, p) => {
546
+ const y = e.map(
547
+ (L, K) => K === t.row ? L.map(
548
+ (T, V) => V === t.col ? p : T
549
+ ) : L
425
550
  );
426
- t(E);
551
+ o(y);
427
552
  },
428
- [o, t]
429
- ), M = C(
430
- (e) => {
431
- if (e.length === 0) return;
432
- const m = o.map((E) => [...E]);
433
- e.forEach(({ coord: E, value: z }) => {
434
- E.row >= 0 && E.row < f && E.col >= 0 && E.col < a && (m[E.row][E.col] = z);
435
- }), t(m);
553
+ [e, o]
554
+ ), C = M(
555
+ (t) => {
556
+ if (t.length === 0) return;
557
+ const p = e.map((y) => [...y]);
558
+ t.forEach(({ coord: y, value: L }) => {
559
+ y.row >= 0 && y.row < f && y.col >= 0 && y.col < g && (p[y.row][y.col] = L);
560
+ }), o(p);
436
561
  },
437
- [o, t, f, a]
562
+ [e, o, f, g]
438
563
  ), {
439
- selection: g,
440
- isSelecting: w,
441
- isCellSelected: p,
442
- handleCellMouseDown: d,
443
- handleCellMouseEnter: i
444
- } = Q(), { handleKeyDown: R } = Y({
445
- selection: g,
446
- getValue: x,
447
- setValues: M,
564
+ selection: r,
565
+ isSelecting: b,
566
+ isCellSelected: w,
567
+ handleCellMouseDown: h,
568
+ handleCellMouseEnter: F,
569
+ setSelection: v
570
+ } = oe({ containerRef: m }), { handleKeyDown: s } = ne({
571
+ selection: r,
572
+ getValue: S,
573
+ setValues: C,
574
+ setSelection: v,
448
575
  rowCount: f,
449
- colCount: a
576
+ colCount: g
450
577
  }), {
451
- isDraggingFill: F,
452
- isFillTarget: r,
453
- handleFillHandleMouseDown: k,
454
- handleCellMouseEnterForFill: T
455
- } = oo({
456
- selection: g,
457
- getValue: x,
458
- setValues: M
459
- }), G = C(
460
- (e) => {
461
- F ? T(e) : w && i(e);
578
+ isDraggingFill: R,
579
+ isFillTarget: I,
580
+ handleFillHandleMouseDown: H,
581
+ handleCellMouseEnterForFill: E
582
+ } = re({
583
+ selection: r,
584
+ getValue: S,
585
+ setValues: C
586
+ }), D = M(
587
+ (t) => {
588
+ R ? E(t) : b && F(t);
462
589
  },
463
590
  [
464
- F,
465
- w,
466
- T,
467
- i
591
+ R,
592
+ b,
593
+ E,
594
+ F
468
595
  ]
469
- ), N = C(
470
- (e, m) => {
471
- y(e, m);
596
+ ), k = M(
597
+ (t, p) => {
598
+ d(t, p);
472
599
  },
473
- [y]
474
- ), D = C(
475
- (e) => {
476
- if (!g.start) return !1;
477
- const m = j(g);
478
- return !m.start || !m.end ? !1 : e.row === m.end.row && e.col === m.end.col;
600
+ [d]
601
+ ), O = M(
602
+ (t) => {
603
+ if (!r.start) return !1;
604
+ const p = B(r);
605
+ return !p.start || !p.end ? !1 : t.row === p.end.row && t.col === p.end.col;
479
606
  },
480
- [g]
481
- ), S = (e) => ({
482
- ...ao,
483
- ...!e && !c?.rowHeader ? wo : {}
484
- }), P = (e) => ({
485
- ...uo,
486
- ...!e && !c?.colGroup ? ho : {}
487
- }), V = (e) => ({
488
- ...fo,
489
- ...!e && !c?.colHeader ? po : {}
607
+ [r]
608
+ ), G = (t) => ({
609
+ ...be,
610
+ ...!t && !u?.rowHeader ? ge : {}
611
+ }), q = (t) => ({
612
+ ...ye,
613
+ ...!t && !u?.colGroup ? Se : {}
614
+ }), P = (t) => ({
615
+ ...xe,
616
+ ...!t && !u?.colHeader ? Ce : {}
490
617
  });
491
- return /* @__PURE__ */ v(
618
+ return /* @__PURE__ */ N(
492
619
  "div",
493
620
  {
494
- ref: h,
495
- className: u,
496
- style: co,
621
+ ref: m,
622
+ className: a,
623
+ style: pe,
497
624
  tabIndex: 0,
498
- onKeyDown: R,
499
- children: /* @__PURE__ */ K("table", { style: io, children: [
500
- /* @__PURE__ */ K("thead", { children: [
501
- s && /* @__PURE__ */ K("tr", { children: [
502
- n && /* @__PURE__ */ v(
625
+ onKeyDown: s,
626
+ children: /* @__PURE__ */ A("table", { style: me, children: [
627
+ /* @__PURE__ */ A("thead", { children: [
628
+ i && /* @__PURE__ */ A("tr", { children: [
629
+ l && /* @__PURE__ */ N(
503
630
  "th",
504
631
  {
505
- className: c?.rowHeader,
506
- style: S(),
507
- children: b
632
+ colSpan: 2,
633
+ className: u?.rowHeader,
634
+ style: G(),
635
+ children: x
508
636
  }
509
637
  ),
510
- s.map((e, m) => /* @__PURE__ */ v(
638
+ i.map((t, p) => /* @__PURE__ */ N(
511
639
  "th",
512
640
  {
513
- colSpan: e.headers.length,
514
- className: H(c?.colGroup, e.className),
515
- style: P(e.className),
516
- children: e.label
641
+ colSpan: t.headers.length,
642
+ className: W(u?.colGroup, t.className),
643
+ style: q(t.className),
644
+ title: t.description,
645
+ children: t.label
517
646
  },
518
- m
647
+ p
519
648
  ))
520
649
  ] }),
521
- s && /* @__PURE__ */ K("tr", { children: [
522
- n && /* @__PURE__ */ v(
650
+ i && /* @__PURE__ */ A("tr", { children: [
651
+ l && /* @__PURE__ */ N(
523
652
  "th",
524
653
  {
525
- className: c?.rowHeader,
526
- style: S()
654
+ colSpan: 2,
655
+ className: u?.rowHeader,
656
+ style: G()
527
657
  }
528
658
  ),
529
- l.map((e) => /* @__PURE__ */ v(
659
+ c.map((t) => /* @__PURE__ */ N(
530
660
  "th",
531
661
  {
532
- className: H(c?.colHeader, e.className),
533
- style: V(e.className),
534
- title: e.description,
535
- children: e.label
662
+ className: W(u?.colHeader, t.className),
663
+ style: P(t.className),
664
+ title: t.description,
665
+ children: t.label
536
666
  },
537
- e.key
667
+ t.key
538
668
  ))
539
669
  ] })
540
670
  ] }),
541
- /* @__PURE__ */ v("tbody", { children: o.map((e, m) => /* @__PURE__ */ K("tr", { children: [
542
- n && n[m] && /* @__PURE__ */ v(
543
- "td",
544
- {
545
- className: H(
546
- c?.rowHeader,
547
- n[m].className
671
+ /* @__PURE__ */ N("tbody", { children: e.map((t, p) => {
672
+ const y = n?.[p];
673
+ return /* @__PURE__ */ A("tr", { children: [
674
+ y && /* @__PURE__ */ A(Q, { children: [
675
+ y.isFirstInGroup && /* @__PURE__ */ N(
676
+ "td",
677
+ {
678
+ rowSpan: y.groupRowCount,
679
+ className: W(u?.rowHeader, y.groupClassName),
680
+ style: G(y.groupClassName),
681
+ title: y.groupDescription,
682
+ children: y.groupLabel
683
+ }
548
684
  ),
549
- style: S(n[m].className),
550
- title: n[m].description,
551
- children: n[m].label
552
- }
553
- ),
554
- e.map((E, z) => {
555
- const B = { row: m, col: z }, A = p(B), I = r(B), $ = D(B);
556
- return /* @__PURE__ */ v(
557
- so,
558
- {
559
- coord: B,
560
- value: x(B),
561
- isSelected: A,
562
- isFillTarget: I,
563
- showFillHandle: $ && !F,
564
- onMouseDown: d,
565
- onMouseEnter: G,
566
- onChange: N,
567
- onFillHandleMouseDown: k,
568
- styles: c
569
- },
570
- z
571
- );
572
- })
573
- ] }, m)) })
685
+ /* @__PURE__ */ N(
686
+ "td",
687
+ {
688
+ className: W(u?.rowHeader, y.rowHeader.className),
689
+ style: G(y.rowHeader.className),
690
+ title: y.rowHeader.description,
691
+ children: y.rowHeader.label
692
+ }
693
+ )
694
+ ] }),
695
+ t.map((L, K) => {
696
+ const T = { row: p, col: K }, V = w(T), _ = I(T), J = O(T);
697
+ return /* @__PURE__ */ N(
698
+ he,
699
+ {
700
+ coord: T,
701
+ value: S(T),
702
+ isSelected: V,
703
+ isFillTarget: _,
704
+ showFillHandle: J && !R,
705
+ onMouseDown: h,
706
+ onMouseEnter: D,
707
+ onChange: k,
708
+ onFillHandleMouseDown: H,
709
+ styles: u
710
+ },
711
+ K
712
+ );
713
+ })
714
+ ] }, p);
715
+ }) })
574
716
  ] })
575
717
  }
576
718
  );
577
719
  }
578
- function go(o) {
579
- const t = typeof o == "string" ? parseFloat(o.replace(/,/g, "")) : o;
580
- return isNaN(t) ? "0" : new Intl.NumberFormat("ko-KR").format(t);
720
+ function Re(e) {
721
+ const o = typeof e == "string" ? parseFloat(e.replace(/,/g, "")) : e;
722
+ return isNaN(o) ? "0" : new Intl.NumberFormat("ko-KR").format(o);
581
723
  }
582
- function Do(o) {
583
- const t = parseInt(o.replace(/,/g, ""), 10);
584
- return isNaN(t) ? 0 : t;
724
+ function He(e) {
725
+ const o = parseInt(e.replace(/,/g, ""), 10);
726
+ return isNaN(o) ? 0 : o;
585
727
  }
586
728
  export {
587
- Mo as ExcelGrid,
588
- so as GridCell,
589
- H as cn,
590
- Co as coordToKey,
591
- go as formatCurrency,
592
- So as getCellsInRange,
593
- yo as getFillTargetCells,
594
- X as isCellInRange,
595
- xo as keyToCoord,
596
- j as normalizeRange,
597
- Do as parseCurrency,
598
- _ as parseTSV,
599
- J as toTSV,
600
- Y as useGridClipboard,
601
- oo as useGridDragFill,
602
- Q as useGridSelection
729
+ Ne as ExcelGrid,
730
+ he as GridCell,
731
+ W as cn,
732
+ ke as coordToKey,
733
+ Re as formatCurrency,
734
+ ve as getCellsInRange,
735
+ Fe as getFillTargetCells,
736
+ Z as isCellInRange,
737
+ Ee as keyToCoord,
738
+ B as normalizeRange,
739
+ He as parseCurrency,
740
+ ee as parseTSV,
741
+ te as toTSV,
742
+ ne as useGridClipboard,
743
+ re as useGridDragFill,
744
+ oe as useGridSelection
603
745
  };