react-excel-lite 0.0.6 → 0.0.7

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 +1 @@
1
- {"version":3,"file":"excel-grid.d.ts","sourceRoot":"","sources":["../../src/components/excel-grid.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAa,MAAM,UAAU,CAAC;AAgD1D,wBAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,UAAU,EACV,SAAS,EACT,cAAmB,EACnB,MAAM,GACP,EAAE,cAAc,2CA+OhB"}
1
+ {"version":3,"file":"excel-grid.d.ts","sourceRoot":"","sources":["../../src/components/excel-grid.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAa,MAAM,UAAU,CAAC;AA2D1D,wBAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,UAAU,EACV,SAAS,EACT,cAAmB,EACnB,MAAM,GACP,EAAE,cAAc,2CA+PhB"}
@@ -1,36 +1,36 @@
1
- import { jsxs as G, jsx as v } from "react/jsx-runtime";
2
- import { useState as K, useCallback as x, useEffect as W, useRef as $, useMemo as q } from "react";
3
- function I(...o) {
1
+ import { jsxs as K, jsx as v } from "react/jsx-runtime";
2
+ import { useState as L, useCallback as C, useEffect as W, useRef as O, useMemo as U } from "react";
3
+ function H(...o) {
4
4
  return o.filter(Boolean).join(" ");
5
5
  }
6
- function fo(o) {
6
+ function Co(o) {
7
7
  return `${o.row}-${o.col}`;
8
8
  }
9
- function wo(o) {
10
- const [n, l] = o.split("-").map(Number);
11
- return { row: n, col: l };
9
+ function xo(o) {
10
+ const [t, n] = o.split("-").map(Number);
11
+ return { row: t, col: n };
12
12
  }
13
- function ho(o, n) {
14
- if (!o || !n) return o ? [o] : [];
15
- const l = Math.min(o.row, n.row), s = Math.max(o.row, n.row), u = Math.min(o.col, n.col), b = Math.max(o.col, n.col), i = [];
16
- for (let h = l; h <= s; h++)
13
+ function So(o, t) {
14
+ if (!o || !t) return o ? [o] : [];
15
+ const n = Math.min(o.row, t.row), s = Math.max(o.row, t.row), u = Math.min(o.col, t.col), b = Math.max(o.col, t.col), c = [];
16
+ for (let h = n; h <= s; h++)
17
17
  for (let f = u; f <= b; f++)
18
- i.push({ row: h, col: f });
19
- return i;
20
- }
21
- function O(o, n) {
22
- if (!n.start) return !1;
23
- const l = n.end || n.start, s = Math.min(n.start.row, l.row), u = Math.max(n.start.row, l.row), b = Math.min(n.start.col, l.col), i = Math.max(n.start.col, l.col);
24
- return o.row >= s && o.row <= u && o.col >= b && o.col <= i;
18
+ c.push({ row: h, col: f });
19
+ return c;
25
20
  }
26
- function X(o) {
27
- return o.split(/\r?\n/).filter((n) => n.trim()).map((n) => n.split(" ").map((l) => l.trim()));
21
+ function X(o, t) {
22
+ if (!t.start) return !1;
23
+ const n = t.end || t.start, s = Math.min(t.start.row, n.row), u = Math.max(t.start.row, n.row), b = Math.min(t.start.col, n.col), c = Math.max(t.start.col, n.col);
24
+ return o.row >= s && o.row <= u && o.col >= b && o.col <= c;
28
25
  }
29
26
  function _(o) {
30
- return o.map((n) => n.join(" ")).join(`
27
+ return o.split(/\r?\n/).filter((t) => t.trim()).map((t) => t.split(" ").map((n) => n.trim()));
28
+ }
29
+ function J(o) {
30
+ return o.map((t) => t.join(" ")).join(`
31
31
  `);
32
32
  }
33
- function L(o) {
33
+ function j(o) {
34
34
  return !o.start || !o.end ? o : {
35
35
  start: {
36
36
  row: Math.min(o.start.row, o.end.row),
@@ -42,220 +42,220 @@ function L(o) {
42
42
  }
43
43
  };
44
44
  }
45
- function po(o, n) {
46
- if (o.row === n.row && o.col === n.col)
45
+ function yo(o, t) {
46
+ if (o.row === t.row && o.col === t.col)
47
47
  return [];
48
- const l = Math.min(o.row, n.row), s = Math.max(o.row, n.row), u = Math.min(o.col, n.col), b = Math.max(o.col, n.col), i = [];
49
- for (let h = l; h <= s; h++)
48
+ const n = Math.min(o.row, t.row), s = Math.max(o.row, t.row), u = Math.min(o.col, t.col), b = Math.max(o.col, t.col), c = [];
49
+ for (let h = n; h <= s; h++)
50
50
  for (let f = u; f <= b; f++)
51
- h === o.row && f === o.col || i.push({ row: h, col: f });
52
- return i;
51
+ h === o.row && f === o.col || c.push({ row: h, col: f });
52
+ return c;
53
53
  }
54
- function J() {
55
- const [o, n] = K({
54
+ function Q() {
55
+ const [o, t] = L({
56
56
  start: null,
57
57
  end: null
58
- }), [l, s] = K(!1), u = x((a) => {
59
- n({ start: a, end: a }), s(!0);
60
- }, []), b = x(
58
+ }), [n, s] = L(!1), u = C((a) => {
59
+ t({ start: a, end: a }), s(!0);
60
+ }, []), b = C(
61
61
  (a) => {
62
- l && n((e) => ({ ...e, end: a }));
62
+ n && t((l) => ({ ...l, end: a }));
63
63
  },
64
- [l]
65
- ), i = x(() => {
64
+ [n]
65
+ ), c = C(() => {
66
66
  s(!1);
67
- }, []), h = x(() => {
68
- n({ start: null, end: null }), s(!1);
69
- }, []), f = x(
70
- (a) => O(a, o),
67
+ }, []), h = C(() => {
68
+ t({ start: null, end: null }), s(!1);
69
+ }, []), f = C(
70
+ (a) => X(a, o),
71
71
  [o]
72
72
  );
73
73
  return W(() => {
74
74
  const a = () => {
75
- l && s(!1);
75
+ n && s(!1);
76
76
  };
77
77
  return window.addEventListener("mouseup", a), () => window.removeEventListener("mouseup", a);
78
- }, [l]), {
78
+ }, [n]), {
79
79
  selection: o,
80
- isSelecting: l,
80
+ isSelecting: n,
81
81
  isCellSelected: f,
82
82
  handleCellMouseDown: u,
83
83
  handleCellMouseEnter: b,
84
- handleMouseUp: i,
84
+ handleMouseUp: c,
85
85
  clearSelection: h,
86
- setSelection: n
86
+ setSelection: t
87
87
  };
88
88
  }
89
- function Q({
89
+ function Y({
90
90
  selection: o,
91
- getValue: n,
92
- setValues: l,
91
+ getValue: t,
92
+ setValues: n,
93
93
  rowCount: s,
94
94
  colCount: u
95
95
  }) {
96
- const b = x(() => {
97
- const e = L(o);
98
- if (!e.start || !e.end) return [];
99
- const C = [];
100
- for (let M = e.start.row; M <= e.end.row; M++) {
101
- const S = [];
102
- for (let g = e.start.col; g <= e.end.col; g++)
103
- S.push(n({ row: M, col: g }));
104
- C.push(S);
96
+ const b = C(() => {
97
+ const l = j(o);
98
+ if (!l.start || !l.end) return [];
99
+ const x = [];
100
+ for (let y = l.start.row; y <= l.end.row; y++) {
101
+ const M = [];
102
+ for (let g = l.start.col; g <= l.end.col; g++)
103
+ M.push(t({ row: y, col: g }));
104
+ x.push(M);
105
105
  }
106
- return C;
107
- }, [o, n]), i = x(async () => {
108
- const e = b();
109
- if (e.length === 0) return;
110
- const C = _(e);
106
+ return x;
107
+ }, [o, t]), c = C(async () => {
108
+ const l = b();
109
+ if (l.length === 0) return;
110
+ const x = J(l);
111
111
  try {
112
- await navigator.clipboard.writeText(C);
113
- } catch (M) {
114
- console.error("Clipboard copy failed:", M);
112
+ await navigator.clipboard.writeText(x);
113
+ } catch (y) {
114
+ console.error("Clipboard copy failed:", y);
115
115
  }
116
- }, [b]), h = x(async () => {
116
+ }, [b]), h = C(async () => {
117
117
  if (o.start)
118
118
  try {
119
- const e = await navigator.clipboard.readText(), C = X(e);
120
- if (C.length === 0) return;
121
- const M = o.start.row, S = o.start.col, g = [];
122
- C.forEach((w, p) => {
123
- const d = M + p;
124
- d >= s || w.forEach((c, N) => {
125
- const D = S + N;
126
- D >= u || g.push({ coord: { row: d, col: D }, value: c });
119
+ const l = await navigator.clipboard.readText(), x = _(l);
120
+ if (x.length === 0) return;
121
+ const y = o.start.row, M = o.start.col, g = [];
122
+ x.forEach((w, p) => {
123
+ const d = y + p;
124
+ d >= s || w.forEach((i, R) => {
125
+ const F = M + R;
126
+ F >= u || g.push({ coord: { row: d, col: F }, value: i });
127
127
  });
128
- }), g.length > 0 && l(g);
129
- } catch (e) {
130
- console.error("Clipboard paste failed:", e);
128
+ }), g.length > 0 && n(g);
129
+ } catch (l) {
130
+ console.error("Clipboard paste failed:", l);
131
131
  }
132
- }, [o.start, l, s, u]), f = x(() => {
133
- const e = L(o);
134
- if (!e.start || !e.end) return;
135
- const C = [];
136
- for (let M = e.start.row; M <= e.end.row; M++)
137
- for (let S = e.start.col; S <= e.end.col; S++)
138
- C.push({ coord: { row: M, col: S }, value: "" });
139
- C.length > 0 && l(C);
140
- }, [o, l]), a = x(
141
- (e) => {
142
- (e.ctrlKey || e.metaKey) && e.key === "c" && (e.preventDefault(), i()), (e.ctrlKey || e.metaKey) && e.key === "v" && (e.preventDefault(), h()), (e.key === "Backspace" || e.key === "Delete") && (e.preventDefault(), f());
132
+ }, [o.start, n, s, u]), f = C(() => {
133
+ const l = j(o);
134
+ if (!l.start || !l.end) return;
135
+ const x = [];
136
+ for (let y = l.start.row; y <= l.end.row; y++)
137
+ for (let M = l.start.col; M <= l.end.col; M++)
138
+ x.push({ coord: { row: y, col: M }, value: "" });
139
+ x.length > 0 && n(x);
140
+ }, [o, n]), a = C(
141
+ (l) => {
142
+ (l.ctrlKey || l.metaKey) && l.key === "c" && (l.preventDefault(), c()), (l.ctrlKey || l.metaKey) && l.key === "v" && (l.preventDefault(), h()), (l.key === "Backspace" || l.key === "Delete") && (l.preventDefault(), f());
143
143
  },
144
- [i, h, f]
144
+ [c, h, f]
145
145
  );
146
146
  return {
147
- handleCopy: i,
147
+ handleCopy: c,
148
148
  handlePaste: h,
149
149
  handleKeyDown: a
150
150
  };
151
151
  }
152
- function Y(o) {
152
+ function Z(o) {
153
153
  if (o.trim() === "") return null;
154
- const n = Number(o);
155
- return isNaN(n) ? null : n;
154
+ const t = Number(o);
155
+ return isNaN(t) ? null : t;
156
156
  }
157
- function H(o) {
157
+ function q(o) {
158
158
  if (o.length === 0) return null;
159
- const n = o.map(Y);
160
- if (n.some((u) => u === null)) return null;
161
- const l = n;
162
- if (l.length === 1)
163
- return { numbers: l, diff: 0 };
164
- const s = l[1] - l[0];
165
- for (let u = 2; u < l.length; u++)
166
- if (l[u] - l[u - 1] !== s)
167
- return { numbers: l, diff: 0 };
168
- return { numbers: l, diff: s };
159
+ const t = o.map(Z);
160
+ if (t.some((u) => u === null)) return null;
161
+ const n = t;
162
+ if (n.length === 1)
163
+ return { numbers: n, diff: 0 };
164
+ const s = n[1] - n[0];
165
+ for (let u = 2; u < n.length; u++)
166
+ if (n[u] - n[u - 1] !== s)
167
+ return { numbers: n, diff: 0 };
168
+ return { numbers: n, diff: s };
169
169
  }
170
- function Z({
170
+ function oo({
171
171
  selection: o,
172
- getValue: n,
173
- setValues: l
172
+ getValue: t,
173
+ setValues: n
174
174
  }) {
175
- const [s, u] = K(null), [b, i] = K([]), [h, f] = K(!1), [a, e] = K(null), C = x((w) => {
176
- u(w), f(!0), i([]), e(null);
177
- }, []), M = x(
175
+ const [s, u] = L(null), [b, c] = L([]), [h, f] = L(!1), [a, l] = L(null), x = C((w) => {
176
+ u(w), f(!0), c([]), l(null);
177
+ }, []), y = C(
178
178
  (w) => {
179
179
  if (!h || !o.start) return;
180
- const p = L(o);
180
+ const p = j(o);
181
181
  if (!p.start || !p.end) return;
182
- e(w);
182
+ l(w);
183
183
  const d = {
184
184
  row: Math.min(p.start.row, w.row),
185
185
  col: Math.min(p.start.col, w.col)
186
- }, c = {
186
+ }, i = {
187
187
  row: Math.max(p.end.row, w.row),
188
188
  col: Math.max(p.end.col, w.col)
189
- }, N = [];
190
- for (let D = d.row; D <= c.row; D++)
191
- for (let r = d.col; r <= c.col; r++)
192
- D >= p.start.row && D <= p.end.row && r >= p.start.col && r <= p.end.col || N.push({ row: D, col: r });
193
- i(N);
189
+ }, R = [];
190
+ for (let F = d.row; F <= i.row; F++)
191
+ for (let r = d.col; r <= i.col; r++)
192
+ F >= p.start.row && F <= p.end.row && r >= p.start.col && r <= p.end.col || R.push({ row: F, col: r });
193
+ c(R);
194
194
  },
195
195
  [h, o]
196
- ), S = x(() => {
196
+ ), M = C(() => {
197
197
  if (!o.start || b.length === 0 || !a) {
198
- u(null), i([]), f(!1), e(null);
198
+ u(null), c([]), f(!1), l(null);
199
199
  return;
200
200
  }
201
- const w = L(o);
201
+ const w = j(o);
202
202
  if (!w.start || !w.end) {
203
- u(null), i([]), f(!1), e(null);
203
+ u(null), c([]), f(!1), l(null);
204
204
  return;
205
205
  }
206
- const p = [], d = w.start, c = w.end, N = c.row - d.row + 1, D = c.col - d.col + 1;
206
+ const p = [], d = w.start, i = w.end, R = i.row - d.row + 1, F = i.col - d.col + 1;
207
207
  b.forEach((r) => {
208
- let R, k;
208
+ let k, T;
209
209
  if (r.row < d.row) {
210
- const F = d.row - r.row;
211
- R = c.row - (F - 1) % N;
212
- } else if (r.row > c.row) {
213
- const F = r.row - c.row;
214
- R = d.row + (F - 1) % N;
210
+ const N = d.row - r.row;
211
+ k = i.row - (N - 1) % R;
212
+ } else if (r.row > i.row) {
213
+ const N = r.row - i.row;
214
+ k = d.row + (N - 1) % R;
215
215
  } else
216
- R = r.row;
216
+ k = r.row;
217
217
  if (r.col < d.col) {
218
- const F = d.col - r.col;
219
- k = c.col - (F - 1) % D;
220
- } else if (r.col > c.col) {
221
- const F = r.col - c.col;
222
- k = d.col + (F - 1) % D;
218
+ const N = d.col - r.col;
219
+ T = i.col - (N - 1) % F;
220
+ } else if (r.col > i.col) {
221
+ const N = r.col - i.col;
222
+ T = d.col + (N - 1) % F;
223
223
  } else
224
- k = r.col;
225
- let T = n({ row: R, col: k });
226
- if (r.row !== R && r.col >= d.col && r.col <= c.col) {
227
- const F = [];
228
- for (let t = d.row; t <= c.row; t++)
229
- F.push(n({ row: t, col: r.col }));
230
- const y = H(F);
231
- if (y && y.diff !== 0) {
232
- if (r.row > c.row) {
233
- const t = r.row - c.row;
234
- T = String(y.numbers[y.numbers.length - 1] + y.diff * t);
224
+ T = r.col;
225
+ let G = t({ row: k, col: T });
226
+ if (r.row !== k && r.col >= d.col && r.col <= i.col) {
227
+ const N = [];
228
+ for (let S = d.row; S <= i.row; S++)
229
+ N.push(t({ row: S, col: r.col }));
230
+ const D = q(N);
231
+ if (D && D.diff !== 0) {
232
+ if (r.row > i.row) {
233
+ const S = r.row - i.row;
234
+ G = String(D.numbers[D.numbers.length - 1] + D.diff * S);
235
235
  } else if (r.row < d.row) {
236
- const t = d.row - r.row;
237
- T = String(y.numbers[0] - y.diff * t);
236
+ const S = d.row - r.row;
237
+ G = String(D.numbers[0] - D.diff * S);
238
238
  }
239
239
  }
240
240
  }
241
- if (r.col !== k && r.row >= d.row && r.row <= c.row) {
242
- const F = [];
243
- for (let t = d.col; t <= c.col; t++)
244
- F.push(n({ row: r.row, col: t }));
245
- const y = H(F);
246
- if (y && y.diff !== 0) {
247
- if (r.col > c.col) {
248
- const t = r.col - c.col;
249
- T = String(y.numbers[y.numbers.length - 1] + y.diff * t);
241
+ if (r.col !== T && r.row >= d.row && r.row <= i.row) {
242
+ const N = [];
243
+ for (let S = d.col; S <= i.col; S++)
244
+ N.push(t({ row: r.row, col: S }));
245
+ const D = q(N);
246
+ if (D && D.diff !== 0) {
247
+ if (r.col > i.col) {
248
+ const S = r.col - i.col;
249
+ G = String(D.numbers[D.numbers.length - 1] + D.diff * S);
250
250
  } else if (r.col < d.col) {
251
- const t = d.col - r.col;
252
- T = String(y.numbers[0] - y.diff * t);
251
+ const S = d.col - r.col;
252
+ G = String(D.numbers[0] - D.diff * S);
253
253
  }
254
254
  }
255
255
  }
256
- p.push({ coord: r, value: T });
257
- }), p.length > 0 && l(p), u(null), i([]), f(!1), e(null);
258
- }, [o, b, a, n, l]), g = x(
256
+ p.push({ coord: r, value: G });
257
+ }), p.length > 0 && n(p), u(null), c([]), f(!1), l(null);
258
+ }, [o, b, a, t, n]), g = C(
259
259
  (w) => b.some(
260
260
  (p) => p.row === w.row && p.col === w.col
261
261
  ),
@@ -263,24 +263,24 @@ function Z({
263
263
  );
264
264
  return W(() => {
265
265
  const w = () => {
266
- h && S();
266
+ h && M();
267
267
  };
268
268
  return window.addEventListener("mouseup", w), () => window.removeEventListener("mouseup", w);
269
- }, [h, S]), {
269
+ }, [h, M]), {
270
270
  fillSource: s,
271
271
  fillTargets: b,
272
272
  isDraggingFill: h,
273
273
  isFillTarget: g,
274
- handleFillHandleMouseDown: C,
275
- handleCellMouseEnterForFill: M,
276
- handleFillMouseUp: S
274
+ handleFillHandleMouseDown: x,
275
+ handleCellMouseEnterForFill: y,
276
+ handleFillMouseUp: M
277
277
  };
278
278
  }
279
- const V = {
279
+ const to = {
280
280
  position: "relative",
281
281
  border: "1px solid #d1d5db",
282
282
  padding: 0
283
- }, oo = {
283
+ }, no = {
284
284
  width: "100%",
285
285
  height: "100%",
286
286
  paddingLeft: "4px",
@@ -292,7 +292,7 @@ const V = {
292
292
  backgroundColor: "transparent",
293
293
  outline: "none",
294
294
  cursor: "cell"
295
- }, no = {
295
+ }, lo = {
296
296
  position: "absolute",
297
297
  bottom: "-2px",
298
298
  right: "-2px",
@@ -301,261 +301,273 @@ const V = {
301
301
  cursor: "crosshair",
302
302
  zIndex: 20,
303
303
  backgroundColor: "#3b82f6"
304
- }, to = {
304
+ }, eo = {
305
305
  backgroundColor: "#dbeafe",
306
306
  outline: "2px solid #3b82f6",
307
307
  outlineOffset: "-2px"
308
- }, lo = {
308
+ }, ro = {
309
309
  backgroundColor: "#eff6ff"
310
310
  };
311
- function eo({
311
+ function so({
312
312
  coord: o,
313
- value: n,
314
- isSelected: l,
313
+ value: t,
314
+ isSelected: n,
315
315
  isFillTarget: s,
316
316
  showFillHandle: u,
317
317
  onMouseDown: b,
318
- onMouseEnter: i,
318
+ onMouseEnter: c,
319
319
  onChange: h,
320
320
  onFillHandleMouseDown: f,
321
321
  styles: a
322
322
  }) {
323
- const e = (c) => {
324
- h(o, c.target.value);
325
- }, C = (c) => {
326
- c.target.classList.contains("fill-handle") || b(o);
327
- }, M = (c) => {
328
- c.stopPropagation(), c.preventDefault(), f(o);
329
- }, S = !!a?.selected, g = !!a?.fillTarget, w = !!a?.fillHandle, p = {
330
- ...V,
331
- ...l && !S ? to : {},
332
- ...s && !g ? lo : {}
323
+ const l = (i) => {
324
+ h(o, i.target.value);
325
+ }, x = (i) => {
326
+ i.target.classList.contains("fill-handle") || b(o);
327
+ }, y = (i) => {
328
+ i.stopPropagation(), i.preventDefault(), f(o);
329
+ }, M = !!a?.selected, g = !!a?.fillTarget, w = !!a?.fillHandle, p = {
330
+ ...to,
331
+ ...n && !M ? eo : {},
332
+ ...s && !g ? ro : {}
333
333
  }, d = {
334
- ...no,
334
+ ...lo,
335
335
  ...w ? { backgroundColor: void 0 } : {}
336
336
  };
337
- return /* @__PURE__ */ G(
337
+ return /* @__PURE__ */ K(
338
338
  "td",
339
339
  {
340
- className: I(
340
+ className: H(
341
341
  a?.cell,
342
- l && a?.selected,
342
+ n && a?.selected,
343
343
  s && a?.fillTarget
344
344
  ),
345
345
  style: p,
346
- onMouseDown: C,
347
- onMouseEnter: () => i(o),
346
+ onMouseDown: x,
347
+ onMouseEnter: () => c(o),
348
348
  children: [
349
349
  /* @__PURE__ */ v(
350
350
  "input",
351
351
  {
352
352
  type: "text",
353
- value: n,
354
- onChange: e,
355
- style: oo
353
+ value: t,
354
+ onChange: l,
355
+ style: no
356
356
  }
357
357
  ),
358
358
  u && /* @__PURE__ */ v(
359
359
  "div",
360
360
  {
361
- className: I("fill-handle", a?.fillHandle),
361
+ className: H("fill-handle", a?.fillHandle),
362
362
  style: d,
363
- onMouseDown: M
363
+ onMouseDown: y
364
364
  }
365
365
  )
366
366
  ]
367
367
  }
368
368
  );
369
369
  }
370
- const ro = {
370
+ const co = {
371
371
  outline: "none",
372
372
  overflowX: "auto"
373
- }, so = {
373
+ }, io = {
374
374
  borderCollapse: "collapse",
375
375
  fontSize: "12px",
376
376
  userSelect: "none"
377
- }, U = {
377
+ }, ao = {
378
378
  position: "sticky",
379
379
  left: 0,
380
380
  zIndex: 10,
381
- backgroundColor: "#f3f4f6",
382
381
  border: "1px solid #d1d5db",
383
382
  padding: "6px 8px",
384
383
  textAlign: "center",
385
384
  fontWeight: 500
386
- }, co = {
387
- backgroundColor: "#dbeafe",
385
+ }, uo = {
388
386
  border: "1px solid #d1d5db",
389
387
  padding: "6px 4px",
390
388
  textAlign: "center",
391
- fontWeight: 500,
392
- color: "#1d4ed8"
393
- }, io = {
394
- backgroundColor: "#f9fafb",
389
+ fontWeight: 500
390
+ }, fo = {
395
391
  border: "1px solid #d1d5db",
396
392
  padding: "4px",
397
393
  textAlign: "center",
398
394
  fontWeight: 500,
399
395
  fontSize: "11px"
396
+ }, wo = {
397
+ backgroundColor: "#f3f4f6"
398
+ }, ho = {
399
+ backgroundColor: "#dbeafe",
400
+ color: "#1d4ed8"
401
+ }, po = {
402
+ backgroundColor: "#f9fafb"
400
403
  };
401
- function mo({
404
+ function Mo({
402
405
  data: o,
403
- onChange: n,
404
- rowHeaders: l,
406
+ onChange: t,
407
+ rowHeaders: n,
405
408
  colHeaders: s,
406
409
  className: u,
407
410
  rowHeaderTitle: b = "",
408
- styles: i
411
+ styles: c
409
412
  }) {
410
- const h = $(null), f = o.length, a = q(() => s ? s.reduce(
411
- (t, m) => t + m.headers.length,
413
+ const h = O(null), f = o.length, a = U(() => s ? s.reduce(
414
+ (e, m) => e + m.headers.length,
412
415
  0
413
- ) : o[0]?.length ?? 0, [s, o]), e = q(() => s ? s.flatMap((t) => t.headers) : [], [s]), C = x(
414
- (t) => t.row < 0 || t.row >= f || t.col < 0 || t.col >= a ? "" : o[t.row]?.[t.col] ?? "",
416
+ ) : o[0]?.length ?? 0, [s, o]), l = U(() => s ? s.flatMap((e) => e.headers) : [], [s]), x = C(
417
+ (e) => e.row < 0 || e.row >= f || e.col < 0 || e.col >= a ? "" : o[e.row]?.[e.col] ?? "",
415
418
  [o, f, a]
416
- ), M = x(
417
- (t, m) => {
419
+ ), y = C(
420
+ (e, m) => {
418
421
  const E = o.map(
419
- (B, z) => z === t.row ? B.map(
420
- (j, A) => A === t.col ? m : j
421
- ) : B
422
+ (z, B) => B === e.row ? z.map(
423
+ (A, I) => I === e.col ? m : A
424
+ ) : z
422
425
  );
423
- n(E);
426
+ t(E);
424
427
  },
425
- [o, n]
426
- ), S = x(
427
- (t) => {
428
- if (t.length === 0) return;
428
+ [o, t]
429
+ ), M = C(
430
+ (e) => {
431
+ if (e.length === 0) return;
429
432
  const m = o.map((E) => [...E]);
430
- t.forEach(({ coord: E, value: B }) => {
431
- E.row >= 0 && E.row < f && E.col >= 0 && E.col < a && (m[E.row][E.col] = B);
432
- }), n(m);
433
+ e.forEach(({ coord: E, value: z }) => {
434
+ E.row >= 0 && E.row < f && E.col >= 0 && E.col < a && (m[E.row][E.col] = z);
435
+ }), t(m);
433
436
  },
434
- [o, n, f, a]
437
+ [o, t, f, a]
435
438
  ), {
436
439
  selection: g,
437
440
  isSelecting: w,
438
441
  isCellSelected: p,
439
442
  handleCellMouseDown: d,
440
- handleCellMouseEnter: c
441
- } = J(), { handleKeyDown: N } = Q({
443
+ handleCellMouseEnter: i
444
+ } = Q(), { handleKeyDown: R } = Y({
442
445
  selection: g,
443
- getValue: C,
444
- setValues: S,
446
+ getValue: x,
447
+ setValues: M,
445
448
  rowCount: f,
446
449
  colCount: a
447
450
  }), {
448
- isDraggingFill: D,
451
+ isDraggingFill: F,
449
452
  isFillTarget: r,
450
- handleFillHandleMouseDown: R,
451
- handleCellMouseEnterForFill: k
452
- } = Z({
453
+ handleFillHandleMouseDown: k,
454
+ handleCellMouseEnterForFill: T
455
+ } = oo({
453
456
  selection: g,
454
- getValue: C,
455
- setValues: S
456
- }), T = x(
457
- (t) => {
458
- D ? k(t) : w && c(t);
457
+ getValue: x,
458
+ setValues: M
459
+ }), G = C(
460
+ (e) => {
461
+ F ? T(e) : w && i(e);
459
462
  },
460
463
  [
461
- D,
464
+ F,
462
465
  w,
463
- k,
464
- c
466
+ T,
467
+ i
465
468
  ]
466
- ), F = x(
467
- (t, m) => {
468
- M(t, m);
469
+ ), N = C(
470
+ (e, m) => {
471
+ y(e, m);
469
472
  },
470
- [M]
471
- ), y = x(
472
- (t) => {
473
+ [y]
474
+ ), D = C(
475
+ (e) => {
473
476
  if (!g.start) return !1;
474
- const m = L(g);
475
- return !m.start || !m.end ? !1 : t.row === m.end.row && t.col === m.end.col;
477
+ const m = j(g);
478
+ return !m.start || !m.end ? !1 : e.row === m.end.row && e.col === m.end.col;
476
479
  },
477
480
  [g]
478
- );
481
+ ), S = (e) => ({
482
+ ...ao,
483
+ ...!e && !c?.rowHeader ? wo : {}
484
+ }), P = (e) => ({
485
+ ...uo,
486
+ ...!e && !c?.colGroup ? ho : {}
487
+ }), V = (e) => ({
488
+ ...fo,
489
+ ...!e && !c?.colHeader ? po : {}
490
+ });
479
491
  return /* @__PURE__ */ v(
480
492
  "div",
481
493
  {
482
494
  ref: h,
483
495
  className: u,
484
- style: ro,
496
+ style: co,
485
497
  tabIndex: 0,
486
- onKeyDown: N,
487
- children: /* @__PURE__ */ G("table", { style: so, children: [
488
- /* @__PURE__ */ G("thead", { children: [
489
- s && /* @__PURE__ */ G("tr", { children: [
490
- l && /* @__PURE__ */ v(
498
+ onKeyDown: R,
499
+ children: /* @__PURE__ */ K("table", { style: io, children: [
500
+ /* @__PURE__ */ K("thead", { children: [
501
+ s && /* @__PURE__ */ K("tr", { children: [
502
+ n && /* @__PURE__ */ v(
491
503
  "th",
492
504
  {
493
- className: i?.rowHeader,
494
- style: U,
505
+ className: c?.rowHeader,
506
+ style: S(),
495
507
  children: b
496
508
  }
497
509
  ),
498
- s.map((t, m) => /* @__PURE__ */ v(
510
+ s.map((e, m) => /* @__PURE__ */ v(
499
511
  "th",
500
512
  {
501
- colSpan: t.headers.length,
502
- className: I(i?.colGroup, t.className),
503
- style: co,
504
- children: t.label
513
+ colSpan: e.headers.length,
514
+ className: H(c?.colGroup, e.className),
515
+ style: P(e.className),
516
+ children: e.label
505
517
  },
506
518
  m
507
519
  ))
508
520
  ] }),
509
- s && /* @__PURE__ */ G("tr", { children: [
510
- l && /* @__PURE__ */ v(
521
+ s && /* @__PURE__ */ K("tr", { children: [
522
+ n && /* @__PURE__ */ v(
511
523
  "th",
512
524
  {
513
- className: i?.rowHeader,
514
- style: U
525
+ className: c?.rowHeader,
526
+ style: S()
515
527
  }
516
528
  ),
517
- e.map((t) => /* @__PURE__ */ v(
529
+ l.map((e) => /* @__PURE__ */ v(
518
530
  "th",
519
531
  {
520
- className: I(i?.colHeader, t.className),
521
- style: io,
522
- title: t.description,
523
- children: t.label
532
+ className: H(c?.colHeader, e.className),
533
+ style: V(e.className),
534
+ title: e.description,
535
+ children: e.label
524
536
  },
525
- t.key
537
+ e.key
526
538
  ))
527
539
  ] })
528
540
  ] }),
529
- /* @__PURE__ */ v("tbody", { children: o.map((t, m) => /* @__PURE__ */ G("tr", { children: [
530
- l && l[m] && /* @__PURE__ */ v(
541
+ /* @__PURE__ */ v("tbody", { children: o.map((e, m) => /* @__PURE__ */ K("tr", { children: [
542
+ n && n[m] && /* @__PURE__ */ v(
531
543
  "td",
532
544
  {
533
- className: I(
534
- i?.rowHeader,
535
- l[m].className
545
+ className: H(
546
+ c?.rowHeader,
547
+ n[m].className
536
548
  ),
537
- style: U,
538
- title: l[m].description,
539
- children: l[m].label
549
+ style: S(n[m].className),
550
+ title: n[m].description,
551
+ children: n[m].label
540
552
  }
541
553
  ),
542
- t.map((E, B) => {
543
- const z = { row: m, col: B }, j = p(z), A = r(z), P = y(z);
554
+ e.map((E, z) => {
555
+ const B = { row: m, col: z }, A = p(B), I = r(B), $ = D(B);
544
556
  return /* @__PURE__ */ v(
545
- eo,
557
+ so,
546
558
  {
547
- coord: z,
548
- value: C(z),
549
- isSelected: j,
550
- isFillTarget: A,
551
- showFillHandle: P && !D,
559
+ coord: B,
560
+ value: x(B),
561
+ isSelected: A,
562
+ isFillTarget: I,
563
+ showFillHandle: $ && !F,
552
564
  onMouseDown: d,
553
- onMouseEnter: T,
554
- onChange: F,
555
- onFillHandleMouseDown: R,
556
- styles: i
565
+ onMouseEnter: G,
566
+ onChange: N,
567
+ onFillHandleMouseDown: k,
568
+ styles: c
557
569
  },
558
- B
570
+ z
559
571
  );
560
572
  })
561
573
  ] }, m)) })
@@ -563,29 +575,29 @@ function mo({
563
575
  }
564
576
  );
565
577
  }
566
- function bo(o) {
567
- const n = typeof o == "string" ? parseFloat(o.replace(/,/g, "")) : o;
568
- return isNaN(n) ? "0" : new Intl.NumberFormat("ko-KR").format(n);
578
+ function go(o) {
579
+ const t = typeof o == "string" ? parseFloat(o.replace(/,/g, "")) : o;
580
+ return isNaN(t) ? "0" : new Intl.NumberFormat("ko-KR").format(t);
569
581
  }
570
- function xo(o) {
571
- const n = parseInt(o.replace(/,/g, ""), 10);
572
- return isNaN(n) ? 0 : n;
582
+ function Do(o) {
583
+ const t = parseInt(o.replace(/,/g, ""), 10);
584
+ return isNaN(t) ? 0 : t;
573
585
  }
574
586
  export {
575
- mo as ExcelGrid,
576
- eo as GridCell,
577
- I as cn,
578
- fo as coordToKey,
579
- bo as formatCurrency,
580
- ho as getCellsInRange,
581
- po as getFillTargetCells,
582
- O as isCellInRange,
583
- wo as keyToCoord,
584
- L as normalizeRange,
585
- xo as parseCurrency,
586
- X as parseTSV,
587
- _ as toTSV,
588
- Q as useGridClipboard,
589
- Z as useGridDragFill,
590
- J as useGridSelection
587
+ Mo as ExcelGrid,
588
+ so as GridCell,
589
+ H as cn,
590
+ Co as coordToKey,
591
+ go as formatCurrency,
592
+ So as getCellsInRange,
593
+ yo as getFillTargetCells,
594
+ X as isCellInRange,
595
+ xo as keyToCoord,
596
+ j as normalizeRange,
597
+ Do as parseCurrency,
598
+ _ as parseTSV,
599
+ J as toTSV,
600
+ Y as useGridClipboard,
601
+ oo as useGridDragFill,
602
+ Q as useGridSelection
591
603
  };
@@ -1,2 +1,2 @@
1
- (function(m,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],g):(m=typeof globalThis<"u"?globalThis:m||self,g(m.ReactExcelLite={},m.ReactJsxRuntime,m.React))})(this,(function(m,g,r){"use strict";function K(...l){return l.filter(Boolean).join(" ")}function V(l){return`${l.row}-${l.col}`}function X(l){const[o,e]=l.split("-").map(Number);return{row:o,col:e}}function _(l,o){if(!l||!o)return l?[l]:[];const e=Math.min(l.row,o.row),c=Math.max(l.row,o.row),f=Math.min(l.col,o.col),S=Math.max(l.col,o.col),a=[];for(let p=e;p<=c;p++)for(let d=f;d<=S;d++)a.push({row:p,col:d});return a}function A(l,o){if(!o.start)return!1;const e=o.end||o.start,c=Math.min(o.start.row,e.row),f=Math.max(o.start.row,e.row),S=Math.min(o.start.col,e.col),a=Math.max(o.start.col,e.col);return l.row>=c&&l.row<=f&&l.col>=S&&l.col<=a}function U(l){return l.split(/\r?\n/).filter(o=>o.trim()).map(o=>o.split(" ").map(e=>e.trim()))}function H(l){return l.map(o=>o.join(" ")).join(`
2
- `)}function j(l){return!l.start||!l.end?l:{start:{row:Math.min(l.start.row,l.end.row),col:Math.min(l.start.col,l.end.col)},end:{row:Math.max(l.start.row,l.end.row),col:Math.max(l.start.col,l.end.col)}}}function Q(l,o){if(l.row===o.row&&l.col===o.col)return[];const e=Math.min(l.row,o.row),c=Math.max(l.row,o.row),f=Math.min(l.col,o.col),S=Math.max(l.col,o.col),a=[];for(let p=e;p<=c;p++)for(let d=f;d<=S;d++)p===l.row&&d===l.col||a.push({row:p,col:d});return a}function P(){const[l,o]=r.useState({start:null,end:null}),[e,c]=r.useState(!1),f=r.useCallback(u=>{o({start:u,end:u}),c(!0)},[]),S=r.useCallback(u=>{e&&o(t=>({...t,end:u}))},[e]),a=r.useCallback(()=>{c(!1)},[]),p=r.useCallback(()=>{o({start:null,end:null}),c(!1)},[]),d=r.useCallback(u=>A(u,l),[l]);return r.useEffect(()=>{const u=()=>{e&&c(!1)};return window.addEventListener("mouseup",u),()=>window.removeEventListener("mouseup",u)},[e]),{selection:l,isSelecting:e,isCellSelected:d,handleCellMouseDown:f,handleCellMouseEnter:S,handleMouseUp:a,clearSelection:p,setSelection:o}}function W({selection:l,getValue:o,setValues:e,rowCount:c,colCount:f}){const S=r.useCallback(()=>{const t=j(l);if(!t.start||!t.end)return[];const y=[];for(let M=t.start.row;M<=t.end.row;M++){const x=[];for(let k=t.start.col;k<=t.end.col;k++)x.push(o({row:M,col:k}));y.push(x)}return y},[l,o]),a=r.useCallback(async()=>{const t=S();if(t.length===0)return;const y=H(t);try{await navigator.clipboard.writeText(y)}catch(M){console.error("Clipboard copy failed:",M)}},[S]),p=r.useCallback(async()=>{if(l.start)try{const t=await navigator.clipboard.readText(),y=U(t);if(y.length===0)return;const M=l.start.row,x=l.start.col,k=[];y.forEach((h,b)=>{const w=M+b;w>=c||h.forEach((i,v)=>{const F=x+v;F>=f||k.push({coord:{row:w,col:F},value:i})})}),k.length>0&&e(k)}catch(t){console.error("Clipboard paste failed:",t)}},[l.start,e,c,f]),d=r.useCallback(()=>{const t=j(l);if(!t.start||!t.end)return;const y=[];for(let M=t.start.row;M<=t.end.row;M++)for(let x=t.start.col;x<=t.end.col;x++)y.push({coord:{row:M,col:x},value:""});y.length>0&&e(y)},[l,e]),u=r.useCallback(t=>{(t.ctrlKey||t.metaKey)&&t.key==="c"&&(t.preventDefault(),a()),(t.ctrlKey||t.metaKey)&&t.key==="v"&&(t.preventDefault(),p()),(t.key==="Backspace"||t.key==="Delete")&&(t.preventDefault(),d())},[a,p,d]);return{handleCopy:a,handlePaste:p,handleKeyDown:u}}function Y(l){if(l.trim()==="")return null;const o=Number(l);return isNaN(o)?null:o}function O(l){if(l.length===0)return null;const o=l.map(Y);if(o.some(f=>f===null))return null;const e=o;if(e.length===1)return{numbers:e,diff:0};const c=e[1]-e[0];for(let f=2;f<e.length;f++)if(e[f]-e[f-1]!==c)return{numbers:e,diff:0};return{numbers:e,diff:c}}function $({selection:l,getValue:o,setValues:e}){const[c,f]=r.useState(null),[S,a]=r.useState([]),[p,d]=r.useState(!1),[u,t]=r.useState(null),y=r.useCallback(h=>{f(h),d(!0),a([]),t(null)},[]),M=r.useCallback(h=>{if(!p||!l.start)return;const b=j(l);if(!b.start||!b.end)return;t(h);const w={row:Math.min(b.start.row,h.row),col:Math.min(b.start.col,h.col)},i={row:Math.max(b.end.row,h.row),col:Math.max(b.end.col,h.col)},v=[];for(let F=w.row;F<=i.row;F++)for(let s=w.col;s<=i.col;s++)F>=b.start.row&&F<=b.end.row&&s>=b.start.col&&s<=b.end.col||v.push({row:F,col:s});a(v)},[p,l]),x=r.useCallback(()=>{if(!l.start||S.length===0||!u){f(null),a([]),d(!1),t(null);return}const h=j(l);if(!h.start||!h.end){f(null),a([]),d(!1),t(null);return}const b=[],w=h.start,i=h.end,v=i.row-w.row+1,F=i.col-w.col+1;S.forEach(s=>{let N,G;if(s.row<w.row){const E=w.row-s.row;N=i.row-(E-1)%v}else if(s.row>i.row){const E=s.row-i.row;N=w.row+(E-1)%v}else N=s.row;if(s.col<w.col){const E=w.col-s.col;G=i.col-(E-1)%F}else if(s.col>i.col){const E=s.col-i.col;G=w.col+(E-1)%F}else G=s.col;let B=o({row:N,col:G});if(s.row!==N&&s.col>=w.col&&s.col<=i.col){const E=[];for(let n=w.row;n<=i.row;n++)E.push(o({row:n,col:s.col}));const D=O(E);if(D&&D.diff!==0){if(s.row>i.row){const n=s.row-i.row;B=String(D.numbers[D.numbers.length-1]+D.diff*n)}else if(s.row<w.row){const n=w.row-s.row;B=String(D.numbers[0]-D.diff*n)}}}if(s.col!==G&&s.row>=w.row&&s.row<=i.row){const E=[];for(let n=w.col;n<=i.col;n++)E.push(o({row:s.row,col:n}));const D=O(E);if(D&&D.diff!==0){if(s.col>i.col){const n=s.col-i.col;B=String(D.numbers[D.numbers.length-1]+D.diff*n)}else if(s.col<w.col){const n=w.col-s.col;B=String(D.numbers[0]-D.diff*n)}}}b.push({coord:s,value:B})}),b.length>0&&e(b),f(null),a([]),d(!1),t(null)},[l,S,u,o,e]),k=r.useCallback(h=>S.some(b=>b.row===h.row&&b.col===h.col),[S]);return r.useEffect(()=>{const h=()=>{p&&x()};return window.addEventListener("mouseup",h),()=>window.removeEventListener("mouseup",h)},[p,x]),{fillSource:c,fillTargets:S,isDraggingFill:p,isFillTarget:k,handleFillHandleMouseDown:y,handleCellMouseEnterForFill:M,handleFillMouseUp:x}}const Z={position:"relative",border:"1px solid #d1d5db",padding:0},ll={width:"100%",height:"100%",paddingLeft:"4px",paddingRight:"4px",paddingTop:"4px",paddingBottom:"4px",textAlign:"right",fontSize:"12px",backgroundColor:"transparent",outline:"none",cursor:"cell"},ol={position:"absolute",bottom:"-2px",right:"-2px",width:"8px",height:"8px",cursor:"crosshair",zIndex:20,backgroundColor:"#3b82f6"},nl={backgroundColor:"#dbeafe",outline:"2px solid #3b82f6",outlineOffset:"-2px"},el={backgroundColor:"#eff6ff"};function J({coord:l,value:o,isSelected:e,isFillTarget:c,showFillHandle:f,onMouseDown:S,onMouseEnter:a,onChange:p,onFillHandleMouseDown:d,styles:u}){const t=i=>{p(l,i.target.value)},y=i=>{i.target.classList.contains("fill-handle")||S(l)},M=i=>{i.stopPropagation(),i.preventDefault(),d(l)},x=!!u?.selected,k=!!u?.fillTarget,h=!!u?.fillHandle,b={...Z,...e&&!x?nl:{},...c&&!k?el:{}},w={...ol,...h?{backgroundColor:void 0}:{}};return g.jsxs("td",{className:K(u?.cell,e&&u?.selected,c&&u?.fillTarget),style:b,onMouseDown:y,onMouseEnter:()=>a(l),children:[g.jsx("input",{type:"text",value:o,onChange:t,style:ll}),f&&g.jsx("div",{className:K("fill-handle",u?.fillHandle),style:w,onMouseDown:M})]})}const tl={outline:"none",overflowX:"auto"},sl={borderCollapse:"collapse",fontSize:"12px",userSelect:"none"},I={position:"sticky",left:0,zIndex:10,backgroundColor:"#f3f4f6",border:"1px solid #d1d5db",padding:"6px 8px",textAlign:"center",fontWeight:500},rl={backgroundColor:"#dbeafe",border:"1px solid #d1d5db",padding:"6px 4px",textAlign:"center",fontWeight:500,color:"#1d4ed8"},cl={backgroundColor:"#f9fafb",border:"1px solid #d1d5db",padding:"4px",textAlign:"center",fontWeight:500,fontSize:"11px"};function il({data:l,onChange:o,rowHeaders:e,colHeaders:c,className:f,rowHeaderTitle:S="",styles:a}){const p=r.useRef(null),d=l.length,u=r.useMemo(()=>c?c.reduce((n,C)=>n+C.headers.length,0):l[0]?.length??0,[c,l]),t=r.useMemo(()=>c?c.flatMap(n=>n.headers):[],[c]),y=r.useCallback(n=>n.row<0||n.row>=d||n.col<0||n.col>=u?"":l[n.row]?.[n.col]??"",[l,d,u]),M=r.useCallback((n,C)=>{const T=l.map((z,R)=>R===n.row?z.map((L,q)=>q===n.col?C:L):z);o(T)},[l,o]),x=r.useCallback(n=>{if(n.length===0)return;const C=l.map(T=>[...T]);n.forEach(({coord:T,value:z})=>{T.row>=0&&T.row<d&&T.col>=0&&T.col<u&&(C[T.row][T.col]=z)}),o(C)},[l,o,d,u]),{selection:k,isSelecting:h,isCellSelected:b,handleCellMouseDown:w,handleCellMouseEnter:i}=P(),{handleKeyDown:v}=W({selection:k,getValue:y,setValues:x,rowCount:d,colCount:u}),{isDraggingFill:F,isFillTarget:s,handleFillHandleMouseDown:N,handleCellMouseEnterForFill:G}=$({selection:k,getValue:y,setValues:x}),B=r.useCallback(n=>{F?G(n):h&&i(n)},[F,h,G,i]),E=r.useCallback((n,C)=>{M(n,C)},[M]),D=r.useCallback(n=>{if(!k.start)return!1;const C=j(k);return!C.start||!C.end?!1:n.row===C.end.row&&n.col===C.end.col},[k]);return g.jsx("div",{ref:p,className:f,style:tl,tabIndex:0,onKeyDown:v,children:g.jsxs("table",{style:sl,children:[g.jsxs("thead",{children:[c&&g.jsxs("tr",{children:[e&&g.jsx("th",{className:a?.rowHeader,style:I,children:S}),c.map((n,C)=>g.jsx("th",{colSpan:n.headers.length,className:K(a?.colGroup,n.className),style:rl,children:n.label},C))]}),c&&g.jsxs("tr",{children:[e&&g.jsx("th",{className:a?.rowHeader,style:I}),t.map(n=>g.jsx("th",{className:K(a?.colHeader,n.className),style:cl,title:n.description,children:n.label},n.key))]})]}),g.jsx("tbody",{children:l.map((n,C)=>g.jsxs("tr",{children:[e&&e[C]&&g.jsx("td",{className:K(a?.rowHeader,e[C].className),style:I,title:e[C].description,children:e[C].label}),n.map((T,z)=>{const R={row:C,col:z},L=b(R),q=s(R),fl=D(R);return g.jsx(J,{coord:R,value:y(R),isSelected:L,isFillTarget:q,showFillHandle:fl&&!F,onMouseDown:w,onMouseEnter:B,onChange:E,onFillHandleMouseDown:N,styles:a},z)})]},C))})]})})}function al(l){const o=typeof l=="string"?parseFloat(l.replace(/,/g,"")):l;return isNaN(o)?"0":new Intl.NumberFormat("ko-KR").format(o)}function ul(l){const o=parseInt(l.replace(/,/g,""),10);return isNaN(o)?0:o}m.ExcelGrid=il,m.GridCell=J,m.cn=K,m.coordToKey=V,m.formatCurrency=al,m.getCellsInRange=_,m.getFillTargetCells=Q,m.isCellInRange=A,m.keyToCoord=X,m.normalizeRange=j,m.parseCurrency=ul,m.parseTSV=U,m.toTSV=H,m.useGridClipboard=W,m.useGridDragFill=$,m.useGridSelection=P,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(m,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],y):(m=typeof globalThis<"u"?globalThis:m||self,y(m.ReactExcelLite={},m.ReactJsxRuntime,m.React))})(this,(function(m,y,r){"use strict";function L(...l){return l.filter(Boolean).join(" ")}function J(l){return`${l.row}-${l.col}`}function X(l){const[o,e]=l.split("-").map(Number);return{row:o,col:e}}function _(l,o){if(!l||!o)return l?[l]:[];const e=Math.min(l.row,o.row),c=Math.max(l.row,o.row),f=Math.min(l.col,o.col),S=Math.max(l.col,o.col),i=[];for(let p=e;p<=c;p++)for(let d=f;d<=S;d++)i.push({row:p,col:d});return i}function q(l,o){if(!o.start)return!1;const e=o.end||o.start,c=Math.min(o.start.row,e.row),f=Math.max(o.start.row,e.row),S=Math.min(o.start.col,e.col),i=Math.max(o.start.col,e.col);return l.row>=c&&l.row<=f&&l.col>=S&&l.col<=i}function A(l){return l.split(/\r?\n/).filter(o=>o.trim()).map(o=>o.split(" ").map(e=>e.trim()))}function U(l){return l.map(o=>o.join(" ")).join(`
2
+ `)}function j(l){return!l.start||!l.end?l:{start:{row:Math.min(l.start.row,l.end.row),col:Math.min(l.start.col,l.end.col)},end:{row:Math.max(l.start.row,l.end.row),col:Math.max(l.start.col,l.end.col)}}}function Q(l,o){if(l.row===o.row&&l.col===o.col)return[];const e=Math.min(l.row,o.row),c=Math.max(l.row,o.row),f=Math.min(l.col,o.col),S=Math.max(l.col,o.col),i=[];for(let p=e;p<=c;p++)for(let d=f;d<=S;d++)p===l.row&&d===l.col||i.push({row:p,col:d});return i}function V(){const[l,o]=r.useState({start:null,end:null}),[e,c]=r.useState(!1),f=r.useCallback(u=>{o({start:u,end:u}),c(!0)},[]),S=r.useCallback(u=>{e&&o(n=>({...n,end:u}))},[e]),i=r.useCallback(()=>{c(!1)},[]),p=r.useCallback(()=>{o({start:null,end:null}),c(!1)},[]),d=r.useCallback(u=>q(u,l),[l]);return r.useEffect(()=>{const u=()=>{e&&c(!1)};return window.addEventListener("mouseup",u),()=>window.removeEventListener("mouseup",u)},[e]),{selection:l,isSelecting:e,isCellSelected:d,handleCellMouseDown:f,handleCellMouseEnter:S,handleMouseUp:i,clearSelection:p,setSelection:o}}function P({selection:l,getValue:o,setValues:e,rowCount:c,colCount:f}){const S=r.useCallback(()=>{const n=j(l);if(!n.start||!n.end)return[];const g=[];for(let k=n.start.row;k<=n.end.row;k++){const x=[];for(let D=n.start.col;D<=n.end.col;D++)x.push(o({row:k,col:D}));g.push(x)}return g},[l,o]),i=r.useCallback(async()=>{const n=S();if(n.length===0)return;const g=U(n);try{await navigator.clipboard.writeText(g)}catch(k){console.error("Clipboard copy failed:",k)}},[S]),p=r.useCallback(async()=>{if(l.start)try{const n=await navigator.clipboard.readText(),g=A(n);if(g.length===0)return;const k=l.start.row,x=l.start.col,D=[];g.forEach((h,C)=>{const w=k+C;w>=c||h.forEach((a,v)=>{const E=x+v;E>=f||D.push({coord:{row:w,col:E},value:a})})}),D.length>0&&e(D)}catch(n){console.error("Clipboard paste failed:",n)}},[l.start,e,c,f]),d=r.useCallback(()=>{const n=j(l);if(!n.start||!n.end)return;const g=[];for(let k=n.start.row;k<=n.end.row;k++)for(let x=n.start.col;x<=n.end.col;x++)g.push({coord:{row:k,col:x},value:""});g.length>0&&e(g)},[l,e]),u=r.useCallback(n=>{(n.ctrlKey||n.metaKey)&&n.key==="c"&&(n.preventDefault(),i()),(n.ctrlKey||n.metaKey)&&n.key==="v"&&(n.preventDefault(),p()),(n.key==="Backspace"||n.key==="Delete")&&(n.preventDefault(),d())},[i,p,d]);return{handleCopy:i,handlePaste:p,handleKeyDown:u}}function Y(l){if(l.trim()==="")return null;const o=Number(l);return isNaN(o)?null:o}function W(l){if(l.length===0)return null;const o=l.map(Y);if(o.some(f=>f===null))return null;const e=o;if(e.length===1)return{numbers:e,diff:0};const c=e[1]-e[0];for(let f=2;f<e.length;f++)if(e[f]-e[f-1]!==c)return{numbers:e,diff:0};return{numbers:e,diff:c}}function O({selection:l,getValue:o,setValues:e}){const[c,f]=r.useState(null),[S,i]=r.useState([]),[p,d]=r.useState(!1),[u,n]=r.useState(null),g=r.useCallback(h=>{f(h),d(!0),i([]),n(null)},[]),k=r.useCallback(h=>{if(!p||!l.start)return;const C=j(l);if(!C.start||!C.end)return;n(h);const w={row:Math.min(C.start.row,h.row),col:Math.min(C.start.col,h.col)},a={row:Math.max(C.end.row,h.row),col:Math.max(C.end.col,h.col)},v=[];for(let E=w.row;E<=a.row;E++)for(let s=w.col;s<=a.col;s++)E>=C.start.row&&E<=C.end.row&&s>=C.start.col&&s<=C.end.col||v.push({row:E,col:s});i(v)},[p,l]),x=r.useCallback(()=>{if(!l.start||S.length===0||!u){f(null),i([]),d(!1),n(null);return}const h=j(l);if(!h.start||!h.end){f(null),i([]),d(!1),n(null);return}const C=[],w=h.start,a=h.end,v=a.row-w.row+1,E=a.col-w.col+1;S.forEach(s=>{let G,z;if(s.row<w.row){const T=w.row-s.row;G=a.row-(T-1)%v}else if(s.row>a.row){const T=s.row-a.row;G=w.row+(T-1)%v}else G=s.row;if(s.col<w.col){const T=w.col-s.col;z=a.col-(T-1)%E}else if(s.col>a.col){const T=s.col-a.col;z=w.col+(T-1)%E}else z=s.col;let R=o({row:G,col:z});if(s.row!==G&&s.col>=w.col&&s.col<=a.col){const T=[];for(let M=w.row;M<=a.row;M++)T.push(o({row:M,col:s.col}));const F=W(T);if(F&&F.diff!==0){if(s.row>a.row){const M=s.row-a.row;R=String(F.numbers[F.numbers.length-1]+F.diff*M)}else if(s.row<w.row){const M=w.row-s.row;R=String(F.numbers[0]-F.diff*M)}}}if(s.col!==z&&s.row>=w.row&&s.row<=a.row){const T=[];for(let M=w.col;M<=a.col;M++)T.push(o({row:s.row,col:M}));const F=W(T);if(F&&F.diff!==0){if(s.col>a.col){const M=s.col-a.col;R=String(F.numbers[F.numbers.length-1]+F.diff*M)}else if(s.col<w.col){const M=w.col-s.col;R=String(F.numbers[0]-F.diff*M)}}}C.push({coord:s,value:R})}),C.length>0&&e(C),f(null),i([]),d(!1),n(null)},[l,S,u,o,e]),D=r.useCallback(h=>S.some(C=>C.row===h.row&&C.col===h.col),[S]);return r.useEffect(()=>{const h=()=>{p&&x()};return window.addEventListener("mouseup",h),()=>window.removeEventListener("mouseup",h)},[p,x]),{fillSource:c,fillTargets:S,isDraggingFill:p,isFillTarget:D,handleFillHandleMouseDown:g,handleCellMouseEnterForFill:k,handleFillMouseUp:x}}const Z={position:"relative",border:"1px solid #d1d5db",padding:0},ll={width:"100%",height:"100%",paddingLeft:"4px",paddingRight:"4px",paddingTop:"4px",paddingBottom:"4px",textAlign:"right",fontSize:"12px",backgroundColor:"transparent",outline:"none",cursor:"cell"},ol={position:"absolute",bottom:"-2px",right:"-2px",width:"8px",height:"8px",cursor:"crosshair",zIndex:20,backgroundColor:"#3b82f6"},el={backgroundColor:"#dbeafe",outline:"2px solid #3b82f6",outlineOffset:"-2px"},nl={backgroundColor:"#eff6ff"};function $({coord:l,value:o,isSelected:e,isFillTarget:c,showFillHandle:f,onMouseDown:S,onMouseEnter:i,onChange:p,onFillHandleMouseDown:d,styles:u}){const n=a=>{p(l,a.target.value)},g=a=>{a.target.classList.contains("fill-handle")||S(l)},k=a=>{a.stopPropagation(),a.preventDefault(),d(l)},x=!!u?.selected,D=!!u?.fillTarget,h=!!u?.fillHandle,C={...Z,...e&&!x?el:{},...c&&!D?nl:{}},w={...ol,...h?{backgroundColor:void 0}:{}};return y.jsxs("td",{className:L(u?.cell,e&&u?.selected,c&&u?.fillTarget),style:C,onMouseDown:g,onMouseEnter:()=>i(l),children:[y.jsx("input",{type:"text",value:o,onChange:n,style:ll}),f&&y.jsx("div",{className:L("fill-handle",u?.fillHandle),style:w,onMouseDown:k})]})}const tl={outline:"none",overflowX:"auto"},sl={borderCollapse:"collapse",fontSize:"12px",userSelect:"none"},rl={position:"sticky",left:0,zIndex:10,border:"1px solid #d1d5db",padding:"6px 8px",textAlign:"center",fontWeight:500},cl={border:"1px solid #d1d5db",padding:"6px 4px",textAlign:"center",fontWeight:500},il={border:"1px solid #d1d5db",padding:"4px",textAlign:"center",fontWeight:500,fontSize:"11px"},al={backgroundColor:"#f3f4f6"},ul={backgroundColor:"#dbeafe",color:"#1d4ed8"},fl={backgroundColor:"#f9fafb"};function dl({data:l,onChange:o,rowHeaders:e,colHeaders:c,className:f,rowHeaderTitle:S="",styles:i}){const p=r.useRef(null),d=l.length,u=r.useMemo(()=>c?c.reduce((t,b)=>t+b.headers.length,0):l[0]?.length??0,[c,l]),n=r.useMemo(()=>c?c.flatMap(t=>t.headers):[],[c]),g=r.useCallback(t=>t.row<0||t.row>=d||t.col<0||t.col>=u?"":l[t.row]?.[t.col]??"",[l,d,u]),k=r.useCallback((t,b)=>{const N=l.map((B,K)=>K===t.row?B.map((H,I)=>I===t.col?b:H):B);o(N)},[l,o]),x=r.useCallback(t=>{if(t.length===0)return;const b=l.map(N=>[...N]);t.forEach(({coord:N,value:B})=>{N.row>=0&&N.row<d&&N.col>=0&&N.col<u&&(b[N.row][N.col]=B)}),o(b)},[l,o,d,u]),{selection:D,isSelecting:h,isCellSelected:C,handleCellMouseDown:w,handleCellMouseEnter:a}=V(),{handleKeyDown:v}=P({selection:D,getValue:g,setValues:x,rowCount:d,colCount:u}),{isDraggingFill:E,isFillTarget:s,handleFillHandleMouseDown:G,handleCellMouseEnterForFill:z}=O({selection:D,getValue:g,setValues:x}),R=r.useCallback(t=>{E?z(t):h&&a(t)},[E,h,z,a]),T=r.useCallback((t,b)=>{k(t,b)},[k]),F=r.useCallback(t=>{if(!D.start)return!1;const b=j(D);return!b.start||!b.end?!1:t.row===b.end.row&&t.col===b.end.col},[D]),M=t=>({...rl,...!t&&!i?.rowHeader?al:{}}),pl=t=>({...cl,...!t&&!i?.colGroup?ul:{}}),ml=t=>({...il,...!t&&!i?.colHeader?fl:{}});return y.jsx("div",{ref:p,className:f,style:tl,tabIndex:0,onKeyDown:v,children:y.jsxs("table",{style:sl,children:[y.jsxs("thead",{children:[c&&y.jsxs("tr",{children:[e&&y.jsx("th",{className:i?.rowHeader,style:M(),children:S}),c.map((t,b)=>y.jsx("th",{colSpan:t.headers.length,className:L(i?.colGroup,t.className),style:pl(t.className),children:t.label},b))]}),c&&y.jsxs("tr",{children:[e&&y.jsx("th",{className:i?.rowHeader,style:M()}),n.map(t=>y.jsx("th",{className:L(i?.colHeader,t.className),style:ml(t.className),title:t.description,children:t.label},t.key))]})]}),y.jsx("tbody",{children:l.map((t,b)=>y.jsxs("tr",{children:[e&&e[b]&&y.jsx("td",{className:L(i?.rowHeader,e[b].className),style:M(e[b].className),title:e[b].description,children:e[b].label}),t.map((N,B)=>{const K={row:b,col:B},H=C(K),I=s(K),Cl=F(K);return y.jsx($,{coord:K,value:g(K),isSelected:H,isFillTarget:I,showFillHandle:Cl&&!E,onMouseDown:w,onMouseEnter:R,onChange:T,onFillHandleMouseDown:G,styles:i},B)})]},b))})]})})}function wl(l){const o=typeof l=="string"?parseFloat(l.replace(/,/g,"")):l;return isNaN(o)?"0":new Intl.NumberFormat("ko-KR").format(o)}function hl(l){const o=parseInt(l.replace(/,/g,""),10);return isNaN(o)?0:o}m.ExcelGrid=dl,m.GridCell=$,m.cn=L,m.coordToKey=J,m.formatCurrency=wl,m.getCellsInRange=_,m.getFillTargetCells=Q,m.isCellInRange=q,m.keyToCoord=X,m.normalizeRange=j,m.parseCurrency=hl,m.parseTSV=A,m.toTSV=U,m.useGridClipboard=P,m.useGridDragFill=O,m.useGridSelection=V,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-excel-lite",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "A lightweight, Excel-like editable grid component for React with cell selection, copy/paste, auto-fill with arithmetic sequence detection, and customizable styling.",
5
5
  "license": "MIT",
6
6
  "type": "module",