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