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