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