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