react-excel-lite 0.1.0 → 0.3.0

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