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