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