react-excel-lite 0.0.6 → 0.1.0

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