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