@c-time/simple-ex-grid 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +208 -0
- package/dist/SimpleExGrid.d.ts +3 -0
- package/dist/__tests__/setup.d.ts +1 -0
- package/dist/components/CellEditor.d.ts +9 -0
- package/dist/components/ContextMenu.d.ts +17 -0
- package/dist/hooks/useClipboard.d.ts +29 -0
- package/dist/hooks/useEditing.d.ts +30 -0
- package/dist/hooks/useGripSelection.d.ts +15 -0
- package/dist/hooks/useHistory.d.ts +27 -0
- package/dist/hooks/useKeyboardNavigation.d.ts +14 -0
- package/dist/hooks/useOverlayScrollbar.d.ts +18 -0
- package/dist/hooks/usePagination.d.ts +22 -0
- package/dist/hooks/usePointerSelection.d.ts +14 -0
- package/dist/hooks/useSelection.d.ts +37 -0
- package/dist/index.cjs +5 -0
- package/dist/index.css +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1525 -0
- package/dist/types.d.ts +84 -0
- package/dist/utils/colspan.d.ts +33 -0
- package/dist/utils/html.d.ts +9 -0
- package/dist/utils/tsv.d.ts +8 -0
- package/package.json +66 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1525 @@
|
|
|
1
|
+
import { useCallback as e, useEffect as t, useMemo as n, useRef as r, useState as i } from "react";
|
|
2
|
+
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
3
|
+
//#region src/utils/colspan.ts
|
|
4
|
+
function s(e, t, n, r) {
|
|
5
|
+
let i = 0;
|
|
6
|
+
for (; i < n && i <= t;) {
|
|
7
|
+
let a = Math.max(1, Math.min(r(e, i), n - i));
|
|
8
|
+
if (t < i + a) return i;
|
|
9
|
+
i += a;
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
}
|
|
13
|
+
function c(e, t, n, r) {
|
|
14
|
+
let i = s(e, t, n, r);
|
|
15
|
+
return i + Math.max(1, Math.min(r(e, i), n - i));
|
|
16
|
+
}
|
|
17
|
+
function l(e, t, n, r) {
|
|
18
|
+
let i = s(e, t, n, r);
|
|
19
|
+
return i === 0 ? -1 : s(e, i - 1, n, r);
|
|
20
|
+
}
|
|
21
|
+
function u(e, t, n) {
|
|
22
|
+
return s(e, t - 1, t, n);
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/hooks/useSelection.ts
|
|
26
|
+
function d(t) {
|
|
27
|
+
let { rowCount: a, colCount: o, selection: d, onSelectionChange: f, onActiveCellChange: p, colSpan: m, hiddenColumns: h } = t, [g, _] = i(null), [v, y] = i(null), [b, x] = i(null), S = r(null), C = e((e) => {
|
|
28
|
+
let t = S.current;
|
|
29
|
+
(t?.row !== e.row || t?.col !== e.col) && p?.(e.row, e.col), S.current = e, _(e);
|
|
30
|
+
}, [p]), w = d !== void 0, T = w ? d ?? null : v, E = g, D = e((e) => {
|
|
31
|
+
w ? f?.(e) : y(e);
|
|
32
|
+
}, [w, f]), O = e((e, t) => ({
|
|
33
|
+
row: Math.max(0, Math.min(e, a - 1)),
|
|
34
|
+
col: Math.max(0, Math.min(t, o - 1))
|
|
35
|
+
}), [a, o]), k = e((e, t) => {
|
|
36
|
+
if (!h || h.size === 0) return e;
|
|
37
|
+
let n = e;
|
|
38
|
+
for (; n >= 0 && n < o && h.has(n);) n += t;
|
|
39
|
+
return n;
|
|
40
|
+
}, [h, o]), A = e(() => {
|
|
41
|
+
if (!h || h.size === 0) return 0;
|
|
42
|
+
for (let e = 0; e < o; e++) if (!h.has(e)) return e;
|
|
43
|
+
return 0;
|
|
44
|
+
}, [h, o]), j = e(() => {
|
|
45
|
+
if (!h || h.size === 0) return o - 1;
|
|
46
|
+
for (let e = o - 1; e >= 0; e--) if (!h.has(e)) return e;
|
|
47
|
+
return o - 1;
|
|
48
|
+
}, [h, o]), M = e((e, t) => {
|
|
49
|
+
let n = O(e, t);
|
|
50
|
+
h?.has(n.col) && (n.col = k(n.col, 1), n.col >= o && (n.col = k(t, -1)), n.col < 0) || (C(n), x(n), D({
|
|
51
|
+
start: n,
|
|
52
|
+
end: n
|
|
53
|
+
}));
|
|
54
|
+
}, [
|
|
55
|
+
O,
|
|
56
|
+
D,
|
|
57
|
+
C,
|
|
58
|
+
h,
|
|
59
|
+
k,
|
|
60
|
+
o
|
|
61
|
+
]), N = e((e, t) => {
|
|
62
|
+
let n = O(e, t), r = b ?? g ?? n;
|
|
63
|
+
C(n), D({
|
|
64
|
+
start: r,
|
|
65
|
+
end: n
|
|
66
|
+
});
|
|
67
|
+
}, [
|
|
68
|
+
b,
|
|
69
|
+
g,
|
|
70
|
+
O,
|
|
71
|
+
D,
|
|
72
|
+
C
|
|
73
|
+
]), P = e((e, t) => {
|
|
74
|
+
let n = O(e, t);
|
|
75
|
+
D({
|
|
76
|
+
start: b ?? g ?? n,
|
|
77
|
+
end: n
|
|
78
|
+
});
|
|
79
|
+
}, [
|
|
80
|
+
b,
|
|
81
|
+
g,
|
|
82
|
+
O,
|
|
83
|
+
D
|
|
84
|
+
]), F = e(() => {
|
|
85
|
+
a === 0 || o === 0 || (C({
|
|
86
|
+
row: 0,
|
|
87
|
+
col: 0
|
|
88
|
+
}), x({
|
|
89
|
+
row: 0,
|
|
90
|
+
col: 0
|
|
91
|
+
}), D({
|
|
92
|
+
start: {
|
|
93
|
+
row: 0,
|
|
94
|
+
col: 0
|
|
95
|
+
},
|
|
96
|
+
end: {
|
|
97
|
+
row: a - 1,
|
|
98
|
+
col: o - 1
|
|
99
|
+
}
|
|
100
|
+
}));
|
|
101
|
+
}, [
|
|
102
|
+
a,
|
|
103
|
+
o,
|
|
104
|
+
D,
|
|
105
|
+
C
|
|
106
|
+
]), ee = e(() => {
|
|
107
|
+
S.current = null, _(null), x(null), D(null);
|
|
108
|
+
}, [D]), I = e((e, t) => {
|
|
109
|
+
let n = g ?? {
|
|
110
|
+
row: 0,
|
|
111
|
+
col: 0
|
|
112
|
+
}, r = n.row + e, i = n.col + t;
|
|
113
|
+
if (m) {
|
|
114
|
+
if (t > 0 && e === 0) i = c(n.row, n.col, o, m);
|
|
115
|
+
else if (t < 0 && e === 0) {
|
|
116
|
+
let e = l(n.row, n.col, o, m);
|
|
117
|
+
i = e >= 0 ? e : n.col;
|
|
118
|
+
}
|
|
119
|
+
i >= o ? (i = 0, r = n.row + 1) : i < 0 && (r = n.row - 1, i = r >= 0 ? u(r, o, m) : o - 1), e !== 0 && (i = s(Math.max(0, Math.min(r, a - 1)), Math.max(0, Math.min(i, o - 1)), o, m));
|
|
120
|
+
} else h && h.size > 0 && t !== 0 && e === 0 && (i = k(i, t > 0 ? 1 : -1)), i >= o ? (i = A(), r += 1) : i < 0 && (i = j(), --r), h && h.size > 0 && e !== 0 && (i = k(i, 1), i >= o && (i = j()));
|
|
121
|
+
let d = O(r, i);
|
|
122
|
+
C(d), x(d), D({
|
|
123
|
+
start: d,
|
|
124
|
+
end: d
|
|
125
|
+
});
|
|
126
|
+
}, [
|
|
127
|
+
g,
|
|
128
|
+
o,
|
|
129
|
+
a,
|
|
130
|
+
O,
|
|
131
|
+
D,
|
|
132
|
+
C,
|
|
133
|
+
m,
|
|
134
|
+
h,
|
|
135
|
+
k,
|
|
136
|
+
A,
|
|
137
|
+
j
|
|
138
|
+
]), L = e((e, t) => {
|
|
139
|
+
let n = O(e, t);
|
|
140
|
+
m && (n.col = s(n.row, n.col, o, m)), !(h?.has(n.col) && (n.col = k(n.col, 1), n.col >= o && (n.col = k(t, -1)), n.col < 0)) && (C(n), x(n), D({
|
|
141
|
+
start: n,
|
|
142
|
+
end: n
|
|
143
|
+
}));
|
|
144
|
+
}, [
|
|
145
|
+
O,
|
|
146
|
+
o,
|
|
147
|
+
D,
|
|
148
|
+
C,
|
|
149
|
+
m,
|
|
150
|
+
h,
|
|
151
|
+
k
|
|
152
|
+
]), R = e((e) => {
|
|
153
|
+
let t = Math.max(0, Math.min(e, a - 1));
|
|
154
|
+
S.current || C({
|
|
155
|
+
row: t,
|
|
156
|
+
col: 0
|
|
157
|
+
}), x({
|
|
158
|
+
row: t,
|
|
159
|
+
col: 0
|
|
160
|
+
}), D({
|
|
161
|
+
start: {
|
|
162
|
+
row: t,
|
|
163
|
+
col: 0
|
|
164
|
+
},
|
|
165
|
+
end: {
|
|
166
|
+
row: t,
|
|
167
|
+
col: o - 1
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}, [
|
|
171
|
+
a,
|
|
172
|
+
o,
|
|
173
|
+
D,
|
|
174
|
+
C
|
|
175
|
+
]), z = e((e) => {
|
|
176
|
+
let t = Math.max(0, Math.min(e, a - 1));
|
|
177
|
+
D({
|
|
178
|
+
start: {
|
|
179
|
+
row: (b ?? {
|
|
180
|
+
row: t,
|
|
181
|
+
col: 0
|
|
182
|
+
}).row,
|
|
183
|
+
col: 0
|
|
184
|
+
},
|
|
185
|
+
end: {
|
|
186
|
+
row: t,
|
|
187
|
+
col: o - 1
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}, [
|
|
191
|
+
b,
|
|
192
|
+
a,
|
|
193
|
+
o,
|
|
194
|
+
D
|
|
195
|
+
]), B = e((e) => {
|
|
196
|
+
let t = Math.max(0, Math.min(e, o - 1));
|
|
197
|
+
S.current || C({
|
|
198
|
+
row: 0,
|
|
199
|
+
col: t
|
|
200
|
+
}), x({
|
|
201
|
+
row: 0,
|
|
202
|
+
col: t
|
|
203
|
+
}), D({
|
|
204
|
+
start: {
|
|
205
|
+
row: 0,
|
|
206
|
+
col: t
|
|
207
|
+
},
|
|
208
|
+
end: {
|
|
209
|
+
row: a - 1,
|
|
210
|
+
col: t
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}, [
|
|
214
|
+
a,
|
|
215
|
+
o,
|
|
216
|
+
D,
|
|
217
|
+
C
|
|
218
|
+
]), V = e((e) => {
|
|
219
|
+
let t = Math.max(0, Math.min(e, o - 1));
|
|
220
|
+
D({
|
|
221
|
+
start: {
|
|
222
|
+
row: 0,
|
|
223
|
+
col: (b ?? {
|
|
224
|
+
row: 0,
|
|
225
|
+
col: t
|
|
226
|
+
}).col
|
|
227
|
+
},
|
|
228
|
+
end: {
|
|
229
|
+
row: a - 1,
|
|
230
|
+
col: t
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}, [
|
|
234
|
+
b,
|
|
235
|
+
a,
|
|
236
|
+
o,
|
|
237
|
+
D
|
|
238
|
+
]), H = e((e, t) => {
|
|
239
|
+
if (!T) return !1;
|
|
240
|
+
let n = Math.min(T.start.row, T.end.row), r = Math.max(T.start.row, T.end.row), i = Math.min(T.start.col, T.end.col), a = Math.max(T.start.col, T.end.col);
|
|
241
|
+
return e >= n && e <= r && t >= i && t <= a;
|
|
242
|
+
}, [T]), U = e((e, t) => E?.row === e && E?.col === t, [E]), te = e((e, t) => {
|
|
243
|
+
t ? (S.current = t, _(t), x(t)) : (S.current = null, _(null), x(null)), D(e);
|
|
244
|
+
}, [D]);
|
|
245
|
+
return n(() => ({
|
|
246
|
+
activeCell: E,
|
|
247
|
+
selectionRange: T,
|
|
248
|
+
selectCell: M,
|
|
249
|
+
extendSelection: N,
|
|
250
|
+
setRangeEnd: P,
|
|
251
|
+
selectAll: F,
|
|
252
|
+
clearSelection: ee,
|
|
253
|
+
moveActiveCell: I,
|
|
254
|
+
moveActiveCellTo: L,
|
|
255
|
+
isSelected: H,
|
|
256
|
+
isActiveCell: U,
|
|
257
|
+
selectEntireRow: R,
|
|
258
|
+
selectEntireCol: B,
|
|
259
|
+
extendRowSelection: z,
|
|
260
|
+
extendColSelection: V,
|
|
261
|
+
restoreSelection: te
|
|
262
|
+
}), [
|
|
263
|
+
E,
|
|
264
|
+
T,
|
|
265
|
+
M,
|
|
266
|
+
N,
|
|
267
|
+
P,
|
|
268
|
+
F,
|
|
269
|
+
ee,
|
|
270
|
+
I,
|
|
271
|
+
L,
|
|
272
|
+
H,
|
|
273
|
+
U,
|
|
274
|
+
R,
|
|
275
|
+
B,
|
|
276
|
+
z,
|
|
277
|
+
V,
|
|
278
|
+
te
|
|
279
|
+
]);
|
|
280
|
+
}
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region src/hooks/usePointerSelection.ts
|
|
283
|
+
function f(e) {
|
|
284
|
+
let t = e.target.closest("[data-row][data-col]");
|
|
285
|
+
if (!t) return null;
|
|
286
|
+
let n = parseInt(t.dataset.row, 10), r = parseInt(t.dataset.col, 10);
|
|
287
|
+
return isNaN(n) || isNaN(r) ? null : {
|
|
288
|
+
row: n,
|
|
289
|
+
col: r
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
function p(e, t) {
|
|
293
|
+
let n = document.elementFromPoint(e, t)?.closest("[data-row][data-col]");
|
|
294
|
+
if (!n) return null;
|
|
295
|
+
let r = parseInt(n.dataset.row, 10), i = parseInt(n.dataset.col, 10);
|
|
296
|
+
return isNaN(r) || isNaN(i) ? null : {
|
|
297
|
+
row: r,
|
|
298
|
+
col: i
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
function m(t) {
|
|
302
|
+
let { mode: i, selection: a, editing: o } = t, s = r(!1), c = r(!1), l = r(null), u = r(null), d = r(null), m = r(null), h = e((e, t) => {
|
|
303
|
+
let n = e.closest(".seg-scroll-inner");
|
|
304
|
+
n && (n.setPointerCapture?.(t), l.current = n);
|
|
305
|
+
}, []), g = e((e) => {
|
|
306
|
+
let t = e.target;
|
|
307
|
+
if (t.closest("[data-grip-row]") || t.closest("[data-grip-col]")) return;
|
|
308
|
+
let n = f(e);
|
|
309
|
+
if (n && (u.current = null, c.current = !1, !(e.button === 2 && a.isSelected(n.row, n.col)))) {
|
|
310
|
+
if (i === "edit") {
|
|
311
|
+
m.current = null;
|
|
312
|
+
let r = d.current;
|
|
313
|
+
if (r !== null && r.row === n.row && r.col === n.col && !o.editingCell) {
|
|
314
|
+
m.current = n;
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
o.editingCell && o.commitEdit(), a.selectCell(n.row, n.col), d.current = n, s.current = !0, h(t, e.pointerId);
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (o.editingCell && o.commitEdit(), e.shiftKey) {
|
|
321
|
+
a.extendSelection(n.row, n.col);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (a.isSelected(n.row, n.col)) {
|
|
325
|
+
u.current = n, s.current = !0, h(t, e.pointerId);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
a.selectCell(n.row, n.col), d.current = n, s.current = !0, h(t, e.pointerId);
|
|
329
|
+
}
|
|
330
|
+
}, [
|
|
331
|
+
i,
|
|
332
|
+
a,
|
|
333
|
+
o,
|
|
334
|
+
h
|
|
335
|
+
]), _ = e((e) => {
|
|
336
|
+
if (!s.current) return;
|
|
337
|
+
let t = p(e.clientX, e.clientY);
|
|
338
|
+
t && (u.current &&= (a.selectCell(u.current.row, u.current.col), null), c.current = !0, a.setRangeEnd(t.row, t.col));
|
|
339
|
+
}, [a]), v = e((e) => {
|
|
340
|
+
if (m.current) {
|
|
341
|
+
let e = m.current;
|
|
342
|
+
m.current = null, o.startEditing(e.row, e.col);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
u.current && !c.current && (a.selectCell(u.current.row, u.current.col), d.current = u.current, u.current = null), u.current = null, s.current && (s.current = !1, c.current = !1, l.current &&= (l.current.releasePointerCapture?.(e.pointerId), null));
|
|
346
|
+
}, [a, o]);
|
|
347
|
+
return n(() => ({
|
|
348
|
+
onPointerDown: g,
|
|
349
|
+
onPointerMove: _,
|
|
350
|
+
onPointerUp: v
|
|
351
|
+
}), [
|
|
352
|
+
g,
|
|
353
|
+
_,
|
|
354
|
+
v
|
|
355
|
+
]);
|
|
356
|
+
}
|
|
357
|
+
//#endregion
|
|
358
|
+
//#region src/hooks/useGripSelection.ts
|
|
359
|
+
function h(t) {
|
|
360
|
+
let { selection: i, colCount: a, rowCount: o } = t, s = r(!1), c = r(!1), l = r(!1), u = r(!1), d = r(null), f = r(null), p = e((e) => {
|
|
361
|
+
let t = i.selectionRange;
|
|
362
|
+
if (!t) return !1;
|
|
363
|
+
let n = Math.min(t.start.row, t.end.row), r = Math.max(t.start.row, t.end.row), o = Math.min(t.start.col, t.end.col), s = Math.max(t.start.col, t.end.col);
|
|
364
|
+
return e >= n && e <= r && o === 0 && s === a - 1;
|
|
365
|
+
}, [i.selectionRange, a]), m = e((e) => {
|
|
366
|
+
let t = i.selectionRange;
|
|
367
|
+
if (!t) return !1;
|
|
368
|
+
let n = Math.min(t.start.row, t.end.row), r = Math.max(t.start.row, t.end.row), a = Math.min(t.start.col, t.end.col), s = Math.max(t.start.col, t.end.col);
|
|
369
|
+
return e >= a && e <= s && n === 0 && r === o - 1;
|
|
370
|
+
}, [i.selectionRange, o]), h = e((e) => {
|
|
371
|
+
let t = e.currentTarget, n = parseInt(t.dataset.gripRow, 10);
|
|
372
|
+
isNaN(n) || e.button === 2 && p(n) || (t.setPointerCapture?.(e.pointerId), s.current = !0, l.current = !1, d.current = null, e.shiftKey ? i.extendRowSelection(n) : p(n) ? d.current = n : i.selectEntireRow(n));
|
|
373
|
+
}, [i, p]), g = e((e) => {
|
|
374
|
+
if (!s.current) return;
|
|
375
|
+
let t = document.elementFromPoint(e.clientX, e.clientY)?.closest("[data-grip-row]");
|
|
376
|
+
if (!t) return;
|
|
377
|
+
let n = parseInt(t.dataset.gripRow, 10);
|
|
378
|
+
isNaN(n) || (d.current !== null && (i.selectEntireRow(d.current), d.current = null), l.current = !0, i.extendRowSelection(n));
|
|
379
|
+
}, [i]), _ = e((e) => {
|
|
380
|
+
d.current !== null && !l.current && i.selectEntireRow(d.current), d.current = null, s.current = !1, l.current = !1, e.currentTarget.releasePointerCapture?.(e.pointerId);
|
|
381
|
+
}, [i]), v = e((e) => {
|
|
382
|
+
let t = e.currentTarget, n = parseInt(t.dataset.gripCol, 10);
|
|
383
|
+
isNaN(n) || e.button === 2 && m(n) || (t.setPointerCapture?.(e.pointerId), c.current = !0, u.current = !1, f.current = null, e.shiftKey ? i.extendColSelection(n) : m(n) ? f.current = n : i.selectEntireCol(n));
|
|
384
|
+
}, [i, m]), y = e((e) => {
|
|
385
|
+
if (!c.current) return;
|
|
386
|
+
let t = document.elementFromPoint(e.clientX, e.clientY)?.closest("[data-grip-col]");
|
|
387
|
+
if (!t) return;
|
|
388
|
+
let n = parseInt(t.dataset.gripCol, 10);
|
|
389
|
+
isNaN(n) || (f.current !== null && (i.selectEntireCol(f.current), f.current = null), u.current = !0, i.extendColSelection(n));
|
|
390
|
+
}, [i]), b = e((e) => {
|
|
391
|
+
f.current !== null && !u.current && i.selectEntireCol(f.current), f.current = null, c.current = !1, u.current = !1, e.currentTarget.releasePointerCapture?.(e.pointerId);
|
|
392
|
+
}, [i]);
|
|
393
|
+
return n(() => ({
|
|
394
|
+
onRowGripPointerDown: h,
|
|
395
|
+
onRowGripPointerMove: g,
|
|
396
|
+
onRowGripPointerUp: _,
|
|
397
|
+
onColGripPointerDown: v,
|
|
398
|
+
onColGripPointerMove: y,
|
|
399
|
+
onColGripPointerUp: b
|
|
400
|
+
}), [
|
|
401
|
+
h,
|
|
402
|
+
g,
|
|
403
|
+
_,
|
|
404
|
+
v,
|
|
405
|
+
y,
|
|
406
|
+
b
|
|
407
|
+
]);
|
|
408
|
+
}
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region src/hooks/useKeyboardNavigation.ts
|
|
411
|
+
function g(t) {
|
|
412
|
+
let { selection: r, editing: i, mode: a, rowCount: o, colCount: s } = t, c = e((e) => {
|
|
413
|
+
if (i.editingCell) return;
|
|
414
|
+
let { key: t, shiftKey: n, ctrlKey: c, metaKey: l } = e, u = c || l;
|
|
415
|
+
switch (t) {
|
|
416
|
+
case "ArrowUp":
|
|
417
|
+
e.preventDefault(), n ? r.extendSelection((r.activeCell?.row ?? 0) - 1, r.activeCell?.col ?? 0) : r.moveActiveCell(-1, 0);
|
|
418
|
+
break;
|
|
419
|
+
case "ArrowDown":
|
|
420
|
+
e.preventDefault(), n ? r.extendSelection((r.activeCell?.row ?? 0) + 1, r.activeCell?.col ?? 0) : r.moveActiveCell(1, 0);
|
|
421
|
+
break;
|
|
422
|
+
case "ArrowLeft":
|
|
423
|
+
e.preventDefault(), n ? r.extendSelection(r.activeCell?.row ?? 0, (r.activeCell?.col ?? 0) - 1) : r.moveActiveCell(0, -1);
|
|
424
|
+
break;
|
|
425
|
+
case "ArrowRight":
|
|
426
|
+
e.preventDefault(), n ? r.extendSelection(r.activeCell?.row ?? 0, (r.activeCell?.col ?? 0) + 1) : r.moveActiveCell(0, 1);
|
|
427
|
+
break;
|
|
428
|
+
case "Tab":
|
|
429
|
+
e.preventDefault(), r.moveActiveCell(0, n ? -1 : 1);
|
|
430
|
+
break;
|
|
431
|
+
case "Enter":
|
|
432
|
+
e.preventDefault(), a === "edit" && r.activeCell ? i.startEditing(r.activeCell.row, r.activeCell.col) : r.moveActiveCell(1, 0);
|
|
433
|
+
break;
|
|
434
|
+
case "F2":
|
|
435
|
+
e.preventDefault(), a === "edit" && r.activeCell && i.startEditing(r.activeCell.row, r.activeCell.col);
|
|
436
|
+
break;
|
|
437
|
+
case "Escape":
|
|
438
|
+
e.preventDefault(), r.clearSelection();
|
|
439
|
+
break;
|
|
440
|
+
case "Home":
|
|
441
|
+
e.preventDefault(), u ? r.moveActiveCellTo(0, 0) : r.moveActiveCellTo(r.activeCell?.row ?? 0, 0);
|
|
442
|
+
break;
|
|
443
|
+
case "End":
|
|
444
|
+
e.preventDefault(), u ? r.moveActiveCellTo(o - 1, s - 1) : r.moveActiveCellTo(r.activeCell?.row ?? 0, s - 1);
|
|
445
|
+
break;
|
|
446
|
+
case "a":
|
|
447
|
+
u && (e.preventDefault(), r.selectAll());
|
|
448
|
+
break;
|
|
449
|
+
default:
|
|
450
|
+
a === "edit" && r.activeCell && t.length === 1 && !u && i.startEditing(r.activeCell.row, r.activeCell.col, t);
|
|
451
|
+
break;
|
|
452
|
+
}
|
|
453
|
+
}, [
|
|
454
|
+
r,
|
|
455
|
+
i,
|
|
456
|
+
a,
|
|
457
|
+
o,
|
|
458
|
+
s
|
|
459
|
+
]);
|
|
460
|
+
return n(() => ({ onKeyDown: c }), [c]);
|
|
461
|
+
}
|
|
462
|
+
//#endregion
|
|
463
|
+
//#region src/hooks/useEditing.ts
|
|
464
|
+
function _(t) {
|
|
465
|
+
let { rows: r, columns: a, mode: o, onChange: s, onCommitMove: c, onEditStart: l, onEditCommit: u, onEditCancel: d } = t, [f, p] = i(null), [m, h] = i(""), [g, _] = i(!1), v = e((e, t, n) => {
|
|
466
|
+
if (o === "readonly" || o === "select") return;
|
|
467
|
+
let i = a[t];
|
|
468
|
+
if (i?.editable === !1 || l?.(e, t) === !1) return;
|
|
469
|
+
let s = r[e]?.[i.key], c = n ?? String(s ?? "");
|
|
470
|
+
p({
|
|
471
|
+
row: e,
|
|
472
|
+
col: t
|
|
473
|
+
}), h(c);
|
|
474
|
+
}, [
|
|
475
|
+
o,
|
|
476
|
+
a,
|
|
477
|
+
r,
|
|
478
|
+
l
|
|
479
|
+
]), y = e(() => {
|
|
480
|
+
if (!f) return;
|
|
481
|
+
let { row: e, col: t } = f, n = a[t];
|
|
482
|
+
if (!n) {
|
|
483
|
+
p(null);
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
let i = n.parser ? n.parser(m) : m, o = r[e]?.[n.key];
|
|
487
|
+
if (u?.(e, t, o, i) === !1) {
|
|
488
|
+
p(null);
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
if (o !== i && s) {
|
|
492
|
+
let a = {
|
|
493
|
+
...r[e],
|
|
494
|
+
[n.key]: i
|
|
495
|
+
}, c = [...r];
|
|
496
|
+
c[e] = a, s(c, [{
|
|
497
|
+
row: e,
|
|
498
|
+
col: t,
|
|
499
|
+
before: o,
|
|
500
|
+
after: i
|
|
501
|
+
}]);
|
|
502
|
+
}
|
|
503
|
+
p(null);
|
|
504
|
+
}, [
|
|
505
|
+
f,
|
|
506
|
+
a,
|
|
507
|
+
m,
|
|
508
|
+
r,
|
|
509
|
+
s,
|
|
510
|
+
u
|
|
511
|
+
]), b = e(() => {
|
|
512
|
+
f && d?.(f.row, f.col), p(null);
|
|
513
|
+
}, [f, d]), x = e((e, t) => f?.row === e && f?.col === t, [f]), S = e((e) => {
|
|
514
|
+
if (e.nativeEvent.type === "compositionstart") {
|
|
515
|
+
_(!0);
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
if (e.nativeEvent.type === "compositionend") {
|
|
519
|
+
_(!1);
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
if (!g) switch (e.key) {
|
|
523
|
+
case "Enter":
|
|
524
|
+
e.preventDefault(), e.stopPropagation(), y(), c(1, 0);
|
|
525
|
+
break;
|
|
526
|
+
case "Tab":
|
|
527
|
+
e.preventDefault(), e.stopPropagation(), y(), c(0, e.shiftKey ? -1 : 1);
|
|
528
|
+
break;
|
|
529
|
+
case "Escape":
|
|
530
|
+
e.preventDefault(), e.stopPropagation(), b();
|
|
531
|
+
break;
|
|
532
|
+
}
|
|
533
|
+
}, [
|
|
534
|
+
g,
|
|
535
|
+
y,
|
|
536
|
+
b,
|
|
537
|
+
c
|
|
538
|
+
]);
|
|
539
|
+
return n(() => ({
|
|
540
|
+
editingCell: f,
|
|
541
|
+
editValue: m,
|
|
542
|
+
setEditValue: h,
|
|
543
|
+
startEditing: v,
|
|
544
|
+
commitEdit: y,
|
|
545
|
+
cancelEdit: b,
|
|
546
|
+
isEditing: x,
|
|
547
|
+
onEditorKeyDown: S
|
|
548
|
+
}), [
|
|
549
|
+
f,
|
|
550
|
+
m,
|
|
551
|
+
v,
|
|
552
|
+
y,
|
|
553
|
+
b,
|
|
554
|
+
x,
|
|
555
|
+
S
|
|
556
|
+
]);
|
|
557
|
+
}
|
|
558
|
+
//#endregion
|
|
559
|
+
//#region src/utils/tsv.ts
|
|
560
|
+
function v(e) {
|
|
561
|
+
return e.includes(" ") || e.includes("\n") || e.includes("\r") || e.includes("\"") ? `"${e.replace(/"/g, "\"\"")}"` : e;
|
|
562
|
+
}
|
|
563
|
+
function y(e) {
|
|
564
|
+
return e.map((e) => e.map(v).join(" ")).join("\r\n");
|
|
565
|
+
}
|
|
566
|
+
function b(e) {
|
|
567
|
+
let t = [], n = "", r = !1, i = [];
|
|
568
|
+
for (let a = 0; a < e.length; a++) {
|
|
569
|
+
let o = e[a];
|
|
570
|
+
r ? o === "\"" ? e[a + 1] === "\"" ? (n += "\"", a++) : r = !1 : n += o : o === "\"" ? r = !0 : o === " " ? (i.push(n), n = "") : o === "\r" ? (e[a + 1] === "\n" && a++, i.push(n), n = "", t.push(i), i = []) : o === "\n" ? (i.push(n), n = "", t.push(i), i = []) : n += o;
|
|
571
|
+
}
|
|
572
|
+
return (n || i.length > 0) && (i.push(n), t.push(i)), t;
|
|
573
|
+
}
|
|
574
|
+
//#endregion
|
|
575
|
+
//#region src/utils/html.ts
|
|
576
|
+
function x(e) {
|
|
577
|
+
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
578
|
+
}
|
|
579
|
+
function S(e, t) {
|
|
580
|
+
let n = t?.colSpan, r = t?.startRow ?? 0, i = t?.startCol ?? 0;
|
|
581
|
+
return `<table>${e.map((e, t) => {
|
|
582
|
+
let a = r + t, o = "", s = 0;
|
|
583
|
+
for (; s < e.length;) {
|
|
584
|
+
let t = i + s, r = n ? Math.max(1, Math.min(n(a, t), e.length - s)) : 1, c = r > 1 ? ` colspan="${r}"` : "";
|
|
585
|
+
o += `<td${c}>${x(e[s])}</td>`, s += r;
|
|
586
|
+
}
|
|
587
|
+
return `<tr>${o}</tr>`;
|
|
588
|
+
}).join("")}</table>`;
|
|
589
|
+
}
|
|
590
|
+
//#endregion
|
|
591
|
+
//#region src/hooks/useClipboard.ts
|
|
592
|
+
function C(e) {
|
|
593
|
+
let t = e.selectionRange;
|
|
594
|
+
return t ? {
|
|
595
|
+
minRow: Math.min(t.start.row, t.end.row),
|
|
596
|
+
maxRow: Math.max(t.start.row, t.end.row),
|
|
597
|
+
minCol: Math.min(t.start.col, t.end.col),
|
|
598
|
+
maxCol: Math.max(t.start.col, t.end.col)
|
|
599
|
+
} : null;
|
|
600
|
+
}
|
|
601
|
+
function w(t) {
|
|
602
|
+
let { rows: r, columns: i, mode: a, selection: o, onChange: s, clipboardFormat: c, allowRowAdd: l, allowRowDelete: u, onRowsAdd: d, onRowsDelete: f, colSpan: p } = t, m = e(() => {
|
|
603
|
+
let e = C(o);
|
|
604
|
+
if (!e) return null;
|
|
605
|
+
let t = [];
|
|
606
|
+
for (let n = e.minRow; n <= e.maxRow; n++) {
|
|
607
|
+
let a = [];
|
|
608
|
+
for (let t = e.minCol; t <= e.maxCol; t++) {
|
|
609
|
+
let e = i[t], o = r[n]?.[e.key];
|
|
610
|
+
a.push(String(o ?? ""));
|
|
611
|
+
}
|
|
612
|
+
t.push(a);
|
|
613
|
+
}
|
|
614
|
+
return t;
|
|
615
|
+
}, [
|
|
616
|
+
r,
|
|
617
|
+
i,
|
|
618
|
+
o
|
|
619
|
+
]), h = e(async (e, t, n) => {
|
|
620
|
+
let r = y(e), i = {};
|
|
621
|
+
if ((c === "tsv" || c === "both") && (i["text/plain"] = new Blob([r], { type: "text/plain" })), c === "html" || c === "both") {
|
|
622
|
+
let a = S(e, {
|
|
623
|
+
colSpan: p,
|
|
624
|
+
startRow: t,
|
|
625
|
+
startCol: n
|
|
626
|
+
});
|
|
627
|
+
i["text/html"] = new Blob([a], { type: "text/html" }), i["text/plain"] ||= new Blob([r], { type: "text/plain" });
|
|
628
|
+
}
|
|
629
|
+
await navigator.clipboard.write([new ClipboardItem(i)]);
|
|
630
|
+
}, [c, p]), g = e(async () => {
|
|
631
|
+
let e = m();
|
|
632
|
+
if (!e) return;
|
|
633
|
+
let t = C(o);
|
|
634
|
+
await h(e, t?.minRow, t?.minCol);
|
|
635
|
+
}, [
|
|
636
|
+
m,
|
|
637
|
+
h,
|
|
638
|
+
o
|
|
639
|
+
]), _ = e(async () => {
|
|
640
|
+
if (a === "readonly") return;
|
|
641
|
+
let e = C(o);
|
|
642
|
+
if (!e) return;
|
|
643
|
+
let t = m();
|
|
644
|
+
if (t) if (await h(t, e.minRow, e.minCol), u) {
|
|
645
|
+
let t = e.minRow, n = e.maxRow, a = n - t + 1, c = [...r];
|
|
646
|
+
c.splice(t, a);
|
|
647
|
+
let l = [];
|
|
648
|
+
for (let e = t; e <= n; e++) for (let t = 0; t < i.length; t++) l.push({
|
|
649
|
+
row: e,
|
|
650
|
+
col: t,
|
|
651
|
+
before: r[e][i[t].key],
|
|
652
|
+
after: void 0
|
|
653
|
+
});
|
|
654
|
+
if (s?.(c, l), f?.(t, a), c.length === 0) o.clearSelection();
|
|
655
|
+
else {
|
|
656
|
+
let n = Math.min(t, c.length - 1);
|
|
657
|
+
o.selectCell(n, e.minCol);
|
|
658
|
+
}
|
|
659
|
+
} else {
|
|
660
|
+
let t = [...r], n = [];
|
|
661
|
+
for (let r = e.minRow; r <= e.maxRow; r++) {
|
|
662
|
+
t[r] = { ...t[r] };
|
|
663
|
+
for (let a = e.minCol; a <= e.maxCol; a++) {
|
|
664
|
+
let e = i[a];
|
|
665
|
+
if (e.editable === !1) continue;
|
|
666
|
+
let o = t[r][e.key], s = e.parser ? e.parser("") : "";
|
|
667
|
+
t[r][e.key] = s, n.push({
|
|
668
|
+
row: r,
|
|
669
|
+
col: a,
|
|
670
|
+
before: o,
|
|
671
|
+
after: s
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
n.length > 0 && s?.(t, n);
|
|
676
|
+
}
|
|
677
|
+
}, [
|
|
678
|
+
a,
|
|
679
|
+
r,
|
|
680
|
+
i,
|
|
681
|
+
o,
|
|
682
|
+
m,
|
|
683
|
+
h,
|
|
684
|
+
s,
|
|
685
|
+
u,
|
|
686
|
+
f
|
|
687
|
+
]), v = e(async () => {
|
|
688
|
+
if (a === "readonly") return;
|
|
689
|
+
let e = C(o) ?? {
|
|
690
|
+
minRow: 0,
|
|
691
|
+
maxRow: 0,
|
|
692
|
+
minCol: 0,
|
|
693
|
+
maxCol: 0
|
|
694
|
+
}, t;
|
|
695
|
+
try {
|
|
696
|
+
t = await navigator.clipboard.readText();
|
|
697
|
+
} catch {
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
let n = b(t);
|
|
701
|
+
if (n.length === 0) return;
|
|
702
|
+
let c = [...r], u = [], f = e.minRow, p = e.minCol;
|
|
703
|
+
for (let e = 0; e < n.length; e++) {
|
|
704
|
+
let t = f + e;
|
|
705
|
+
if (t >= c.length) {
|
|
706
|
+
if (!l) break;
|
|
707
|
+
let e = {};
|
|
708
|
+
for (let t of i) e[t.key] = t.parser ? t.parser("") : "";
|
|
709
|
+
c.push(e);
|
|
710
|
+
}
|
|
711
|
+
c[t] = { ...c[t] };
|
|
712
|
+
for (let r = 0; r < n[e].length; r++) {
|
|
713
|
+
let a = p + r;
|
|
714
|
+
if (a >= i.length) break;
|
|
715
|
+
let o = i[a];
|
|
716
|
+
if (o.editable === !1) continue;
|
|
717
|
+
let s = c[t][o.key], l = o.parser ? o.parser(n[e][r]) : n[e][r];
|
|
718
|
+
c[t][o.key] = l, u.push({
|
|
719
|
+
row: t,
|
|
720
|
+
col: a,
|
|
721
|
+
before: s,
|
|
722
|
+
after: l
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
u.length > 0 && s?.(c, u);
|
|
727
|
+
let m = c.length - r.length;
|
|
728
|
+
m > 0 && d?.(r.length, m);
|
|
729
|
+
}, [
|
|
730
|
+
a,
|
|
731
|
+
r,
|
|
732
|
+
i,
|
|
733
|
+
o,
|
|
734
|
+
s,
|
|
735
|
+
l,
|
|
736
|
+
d
|
|
737
|
+
]), x = e(async () => {
|
|
738
|
+
if (a === "readonly" || !l) return;
|
|
739
|
+
let e = C(o) ?? {
|
|
740
|
+
minRow: 0,
|
|
741
|
+
maxRow: -1,
|
|
742
|
+
minCol: 0,
|
|
743
|
+
maxCol: 0
|
|
744
|
+
}, t;
|
|
745
|
+
try {
|
|
746
|
+
t = await navigator.clipboard.readText();
|
|
747
|
+
} catch {
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
let n = b(t);
|
|
751
|
+
if (n.length === 0) return;
|
|
752
|
+
let c = e.minCol, u = e.maxRow + 1, f = r[e.minRow] ?? {}, p = n.map((e) => {
|
|
753
|
+
let t = { ...f };
|
|
754
|
+
for (let n = 0; n < e.length; n++) {
|
|
755
|
+
let r = c + n;
|
|
756
|
+
if (r >= i.length) break;
|
|
757
|
+
let a = i[r];
|
|
758
|
+
a.editable !== !1 && (t[a.key] = a.parser ? a.parser(e[n]) : e[n]);
|
|
759
|
+
}
|
|
760
|
+
return t;
|
|
761
|
+
}), m = [...r];
|
|
762
|
+
m.splice(u, 0, ...p);
|
|
763
|
+
let h = [];
|
|
764
|
+
for (let e = 0; e < p.length; e++) for (let t = 0; t < (n[e]?.length ?? 0); t++) {
|
|
765
|
+
let n = c + t;
|
|
766
|
+
if (n >= i.length) break;
|
|
767
|
+
let r = i[n];
|
|
768
|
+
r.editable !== !1 && h.push({
|
|
769
|
+
row: u + e,
|
|
770
|
+
col: n,
|
|
771
|
+
before: void 0,
|
|
772
|
+
after: p[e][r.key]
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
s && s(m, h), d?.(u, p.length);
|
|
776
|
+
}, [
|
|
777
|
+
a,
|
|
778
|
+
l,
|
|
779
|
+
r,
|
|
780
|
+
i,
|
|
781
|
+
o,
|
|
782
|
+
s,
|
|
783
|
+
d
|
|
784
|
+
]), w = e(() => {
|
|
785
|
+
if (a === "readonly" || !l) return;
|
|
786
|
+
let e = C(o) ?? {
|
|
787
|
+
minRow: 0,
|
|
788
|
+
maxRow: -1,
|
|
789
|
+
minCol: 0,
|
|
790
|
+
maxCol: 0
|
|
791
|
+
}, t = Math.max(1, e.maxRow - e.minRow + 1), n = e.maxRow + 1, c = [...r], u = Array.from({ length: t }, () => {
|
|
792
|
+
let e = {};
|
|
793
|
+
for (let t of i) e[t.key] = t.parser ? t.parser("") : "";
|
|
794
|
+
return e;
|
|
795
|
+
});
|
|
796
|
+
c.splice(n, 0, ...u), s?.(c, []), d?.(n, t);
|
|
797
|
+
}, [
|
|
798
|
+
a,
|
|
799
|
+
l,
|
|
800
|
+
r,
|
|
801
|
+
i,
|
|
802
|
+
o,
|
|
803
|
+
s,
|
|
804
|
+
d
|
|
805
|
+
]), T = e(() => {
|
|
806
|
+
if (a === "readonly" || !u) return;
|
|
807
|
+
let e = C(o);
|
|
808
|
+
if (!e) return;
|
|
809
|
+
let t = e.minRow, n = e.maxRow, c = n - t + 1, l = [...r];
|
|
810
|
+
l.splice(t, c);
|
|
811
|
+
let d = [];
|
|
812
|
+
for (let e = t; e <= n; e++) for (let t = 0; t < i.length; t++) d.push({
|
|
813
|
+
row: e,
|
|
814
|
+
col: t,
|
|
815
|
+
before: r[e][i[t].key],
|
|
816
|
+
after: void 0
|
|
817
|
+
});
|
|
818
|
+
if (s?.(l, d), f?.(t, c), l.length === 0) o.clearSelection();
|
|
819
|
+
else {
|
|
820
|
+
let n = Math.min(t, l.length - 1);
|
|
821
|
+
o.selectCell(n, e.minCol);
|
|
822
|
+
}
|
|
823
|
+
}, [
|
|
824
|
+
a,
|
|
825
|
+
u,
|
|
826
|
+
r,
|
|
827
|
+
i,
|
|
828
|
+
o,
|
|
829
|
+
s,
|
|
830
|
+
f
|
|
831
|
+
]), E = o.selectionRange !== null;
|
|
832
|
+
return n(() => ({
|
|
833
|
+
copy: g,
|
|
834
|
+
cut: _,
|
|
835
|
+
paste: v,
|
|
836
|
+
pasteInsert: x,
|
|
837
|
+
addRows: w,
|
|
838
|
+
deleteRows: T,
|
|
839
|
+
hasSelection: E,
|
|
840
|
+
allowRowAdd: l,
|
|
841
|
+
allowRowDelete: u
|
|
842
|
+
}), [
|
|
843
|
+
g,
|
|
844
|
+
_,
|
|
845
|
+
v,
|
|
846
|
+
x,
|
|
847
|
+
w,
|
|
848
|
+
T,
|
|
849
|
+
E,
|
|
850
|
+
l,
|
|
851
|
+
u
|
|
852
|
+
]);
|
|
853
|
+
}
|
|
854
|
+
//#endregion
|
|
855
|
+
//#region src/hooks/useHistory.ts
|
|
856
|
+
function T(a) {
|
|
857
|
+
let { rows: o, selection: s, onChange: c, onRowsAdd: l, onRowsDelete: u, maxHistory: d, shouldRecordHistory: f, historyApiRef: p } = a, [m, h] = i([]), [g, _] = i([]), v = r(null), y = r(!1), b = e(() => ({
|
|
858
|
+
activeCell: s.activeCell,
|
|
859
|
+
range: s.selectionRange
|
|
860
|
+
}), [s]), x = e((e) => {
|
|
861
|
+
h((t) => {
|
|
862
|
+
let n = [...t, e];
|
|
863
|
+
return n.length > d && n.splice(0, n.length - d), n;
|
|
864
|
+
}), _([]);
|
|
865
|
+
}, [d]), S = e((e, t) => {
|
|
866
|
+
y.current || (v.current = {
|
|
867
|
+
entry: {
|
|
868
|
+
beforeRows: o,
|
|
869
|
+
afterRows: e,
|
|
870
|
+
beforeSelection: b()
|
|
871
|
+
},
|
|
872
|
+
changes: t
|
|
873
|
+
}, queueMicrotask(() => {
|
|
874
|
+
let e = v.current;
|
|
875
|
+
e && (v.current = null, !(f && !f(e.changes, e.entry.rowEvent)) && x(e.entry));
|
|
876
|
+
})), c?.(e, t);
|
|
877
|
+
}, [
|
|
878
|
+
o,
|
|
879
|
+
c,
|
|
880
|
+
b,
|
|
881
|
+
f,
|
|
882
|
+
x
|
|
883
|
+
]), C = e((e, t) => {
|
|
884
|
+
!y.current && v.current && (v.current.entry.rowEvent = {
|
|
885
|
+
kind: "add",
|
|
886
|
+
startRow: e,
|
|
887
|
+
count: t
|
|
888
|
+
}), l?.(e, t);
|
|
889
|
+
}, [l]), w = e((e, t) => {
|
|
890
|
+
!y.current && v.current && (v.current.entry.rowEvent = {
|
|
891
|
+
kind: "delete",
|
|
892
|
+
startRow: e,
|
|
893
|
+
count: t
|
|
894
|
+
}), u?.(e, t);
|
|
895
|
+
}, [u]), T = e(() => {
|
|
896
|
+
h((e) => {
|
|
897
|
+
if (e.length === 0) return e;
|
|
898
|
+
let t = e[e.length - 1], n = e.slice(0, -1);
|
|
899
|
+
return _((e) => [...e, t]), y.current = !0, c?.(t.beforeRows, []), t.rowEvent && (t.rowEvent.kind === "add" ? u?.(t.rowEvent.startRow, t.rowEvent.count) : l?.(t.rowEvent.startRow, t.rowEvent.count)), s.restoreSelection(t.beforeSelection.range, t.beforeSelection.activeCell), y.current = !1, n;
|
|
900
|
+
});
|
|
901
|
+
}, [
|
|
902
|
+
c,
|
|
903
|
+
l,
|
|
904
|
+
u,
|
|
905
|
+
s
|
|
906
|
+
]), E = e(() => {
|
|
907
|
+
_((e) => {
|
|
908
|
+
if (e.length === 0) return e;
|
|
909
|
+
let t = e[e.length - 1], n = e.slice(0, -1);
|
|
910
|
+
return h((e) => {
|
|
911
|
+
let n = [...e, t];
|
|
912
|
+
return n.length > d && n.splice(0, n.length - d), n;
|
|
913
|
+
}), y.current = !0, c?.(t.afterRows, []), t.rowEvent && (t.rowEvent.kind === "add" ? l?.(t.rowEvent.startRow, t.rowEvent.count) : u?.(t.rowEvent.startRow, t.rowEvent.count)), y.current = !1, n;
|
|
914
|
+
});
|
|
915
|
+
}, [
|
|
916
|
+
d,
|
|
917
|
+
c,
|
|
918
|
+
l,
|
|
919
|
+
u
|
|
920
|
+
]), D = e((e, t) => {
|
|
921
|
+
x({
|
|
922
|
+
beforeRows: e,
|
|
923
|
+
afterRows: t,
|
|
924
|
+
beforeSelection: b()
|
|
925
|
+
});
|
|
926
|
+
}, [b, x]), O = m.length > 0, k = g.length > 0;
|
|
927
|
+
return t(() => {
|
|
928
|
+
p && (p.current = {
|
|
929
|
+
pushHistory: D,
|
|
930
|
+
undo: T,
|
|
931
|
+
redo: E,
|
|
932
|
+
canUndo: O,
|
|
933
|
+
canRedo: k
|
|
934
|
+
});
|
|
935
|
+
}, [
|
|
936
|
+
p,
|
|
937
|
+
D,
|
|
938
|
+
T,
|
|
939
|
+
E,
|
|
940
|
+
O,
|
|
941
|
+
k
|
|
942
|
+
]), n(() => ({
|
|
943
|
+
wrappedOnChange: S,
|
|
944
|
+
wrappedOnRowsAdd: C,
|
|
945
|
+
wrappedOnRowsDelete: w,
|
|
946
|
+
undo: T,
|
|
947
|
+
redo: E,
|
|
948
|
+
canUndo: O,
|
|
949
|
+
canRedo: k
|
|
950
|
+
}), [
|
|
951
|
+
S,
|
|
952
|
+
C,
|
|
953
|
+
w,
|
|
954
|
+
T,
|
|
955
|
+
E,
|
|
956
|
+
O,
|
|
957
|
+
k
|
|
958
|
+
]);
|
|
959
|
+
}
|
|
960
|
+
//#endregion
|
|
961
|
+
//#region src/hooks/useOverlayScrollbar.ts
|
|
962
|
+
function E() {
|
|
963
|
+
let n = r(null), a = r(null), [o, s] = i({
|
|
964
|
+
vTop: 0,
|
|
965
|
+
vHeight: 0,
|
|
966
|
+
showV: !1,
|
|
967
|
+
hLeft: 0,
|
|
968
|
+
hWidth: 0,
|
|
969
|
+
showH: !1
|
|
970
|
+
}), c = r(null), l = r(null), u = r({
|
|
971
|
+
pos: 0,
|
|
972
|
+
scroll: 0
|
|
973
|
+
}), d = e(() => {
|
|
974
|
+
let e = n.current;
|
|
975
|
+
if (!e) return;
|
|
976
|
+
let { scrollTop: t, scrollLeft: r, scrollWidth: i, scrollHeight: o, clientWidth: l, clientHeight: u } = e, d = o > u + 1, f = i > l + 1, p = u / o, m = l / i;
|
|
977
|
+
s({
|
|
978
|
+
showV: d,
|
|
979
|
+
vTop: d ? t / o * u : 0,
|
|
980
|
+
vHeight: d ? Math.max(p * u, 24) : 0,
|
|
981
|
+
showH: f,
|
|
982
|
+
hLeft: f ? r / i * l : 0,
|
|
983
|
+
hWidth: f ? Math.max(m * l, 24) : 0
|
|
984
|
+
});
|
|
985
|
+
let h = a.current;
|
|
986
|
+
h && (h.classList.add("seg-scrolling"), c.current && clearTimeout(c.current), c.current = setTimeout(() => {
|
|
987
|
+
h.classList.remove("seg-scrolling");
|
|
988
|
+
}, 800));
|
|
989
|
+
}, []);
|
|
990
|
+
return t(() => {
|
|
991
|
+
let e = n.current;
|
|
992
|
+
if (!e) return;
|
|
993
|
+
e.addEventListener("scroll", d, { passive: !0 });
|
|
994
|
+
let t = new ResizeObserver(d);
|
|
995
|
+
return t.observe(e), e.firstElementChild && t.observe(e.firstElementChild), d(), () => {
|
|
996
|
+
e.removeEventListener("scroll", d), t.disconnect();
|
|
997
|
+
};
|
|
998
|
+
}, [d]), {
|
|
999
|
+
scrollRef: n,
|
|
1000
|
+
areaRef: a,
|
|
1001
|
+
state: o,
|
|
1002
|
+
onVBarPointerDown: e((e) => {
|
|
1003
|
+
e.preventDefault(), e.stopPropagation(), l.current = "v", u.current = {
|
|
1004
|
+
pos: e.clientY,
|
|
1005
|
+
scroll: n.current?.scrollTop ?? 0
|
|
1006
|
+
}, e.target.setPointerCapture?.(e.pointerId);
|
|
1007
|
+
}, []),
|
|
1008
|
+
onHBarPointerDown: e((e) => {
|
|
1009
|
+
e.preventDefault(), e.stopPropagation(), l.current = "h", u.current = {
|
|
1010
|
+
pos: e.clientX,
|
|
1011
|
+
scroll: n.current?.scrollLeft ?? 0
|
|
1012
|
+
}, e.target.setPointerCapture?.(e.pointerId);
|
|
1013
|
+
}, []),
|
|
1014
|
+
onBarPointerMove: e((e) => {
|
|
1015
|
+
let t = n.current;
|
|
1016
|
+
if (!(!t || !l.current)) if (l.current === "v") {
|
|
1017
|
+
let n = e.clientY - u.current.pos, r = t.scrollHeight / t.clientHeight;
|
|
1018
|
+
t.scrollTop = u.current.scroll + n * r;
|
|
1019
|
+
} else {
|
|
1020
|
+
let n = e.clientX - u.current.pos, r = t.scrollWidth / t.clientWidth;
|
|
1021
|
+
t.scrollLeft = u.current.scroll + n * r;
|
|
1022
|
+
}
|
|
1023
|
+
}, []),
|
|
1024
|
+
onBarPointerUp: e((e) => {
|
|
1025
|
+
l.current = null, e.target.releasePointerCapture?.(e.pointerId);
|
|
1026
|
+
}, [])
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
//#endregion
|
|
1030
|
+
//#region src/hooks/usePagination.ts
|
|
1031
|
+
function D(t) {
|
|
1032
|
+
let { totalRows: r, pageSize: a, page: o, onPageChange: s, onPageSizeChange: c } = t, [l, u] = i(0), [d, f] = i(a), p = o !== void 0, m = p ? o : l, h = d, g = Math.max(1, Math.ceil(r / h)), _ = e((e) => {
|
|
1033
|
+
let t = Math.max(0, Math.min(e, g - 1));
|
|
1034
|
+
p || u(t), s?.(t);
|
|
1035
|
+
}, [
|
|
1036
|
+
g,
|
|
1037
|
+
p,
|
|
1038
|
+
s
|
|
1039
|
+
]), v = e((e) => {
|
|
1040
|
+
let t = Math.max(1, e);
|
|
1041
|
+
f(t), c?.(t), _(0);
|
|
1042
|
+
}, [c, _]), y = e(() => _(0), [_]), b = e(() => _(m - 1), [_, m]), x = e(() => _(m + 1), [_, m]), S = e(() => _(g - 1), [_, g]), C = m * h, w = Math.min(C + h, r);
|
|
1043
|
+
return n(() => ({
|
|
1044
|
+
currentPage: m,
|
|
1045
|
+
pageSize: h,
|
|
1046
|
+
totalPages: g,
|
|
1047
|
+
startRow: C,
|
|
1048
|
+
endRow: w,
|
|
1049
|
+
setPage: _,
|
|
1050
|
+
setPageSize: v,
|
|
1051
|
+
goFirst: y,
|
|
1052
|
+
goPrev: b,
|
|
1053
|
+
goNext: x,
|
|
1054
|
+
goLast: S
|
|
1055
|
+
}), [
|
|
1056
|
+
m,
|
|
1057
|
+
h,
|
|
1058
|
+
g,
|
|
1059
|
+
C,
|
|
1060
|
+
w,
|
|
1061
|
+
_,
|
|
1062
|
+
v,
|
|
1063
|
+
y,
|
|
1064
|
+
b,
|
|
1065
|
+
x,
|
|
1066
|
+
S
|
|
1067
|
+
]);
|
|
1068
|
+
}
|
|
1069
|
+
//#endregion
|
|
1070
|
+
//#region src/components/CellEditor.tsx
|
|
1071
|
+
function O({ value: e, onChange: n, onCommit: i, onKeyDown: o }) {
|
|
1072
|
+
let s = r(null);
|
|
1073
|
+
return t(() => {
|
|
1074
|
+
let e = s.current;
|
|
1075
|
+
e && (e.focus(), e.select());
|
|
1076
|
+
}, []), /* @__PURE__ */ a("input", {
|
|
1077
|
+
ref: s,
|
|
1078
|
+
className: "seg-cell-editor",
|
|
1079
|
+
value: e,
|
|
1080
|
+
onChange: (e) => n(e.target.value),
|
|
1081
|
+
onKeyDown: o,
|
|
1082
|
+
onBlur: i,
|
|
1083
|
+
onPointerDown: (e) => e.stopPropagation()
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
//#endregion
|
|
1087
|
+
//#region src/components/ContextMenu.tsx
|
|
1088
|
+
function k({ x: e, y: n, items: i, onClose: s }) {
|
|
1089
|
+
let c = r(null);
|
|
1090
|
+
return t(() => {
|
|
1091
|
+
let e = (e) => {
|
|
1092
|
+
c.current && !c.current.contains(e.target) && s();
|
|
1093
|
+
}, t = (e) => {
|
|
1094
|
+
e.key === "Escape" && s();
|
|
1095
|
+
};
|
|
1096
|
+
return document.addEventListener("mousedown", e), document.addEventListener("keydown", t), () => {
|
|
1097
|
+
document.removeEventListener("mousedown", e), document.removeEventListener("keydown", t);
|
|
1098
|
+
};
|
|
1099
|
+
}, [s]), t(() => {
|
|
1100
|
+
let t = c.current;
|
|
1101
|
+
if (!t) return;
|
|
1102
|
+
let r = t.getBoundingClientRect();
|
|
1103
|
+
r.right > window.innerWidth && (t.style.left = `${e - r.width}px`), r.bottom > window.innerHeight && (t.style.top = `${n - r.height}px`);
|
|
1104
|
+
}, [e, n]), /* @__PURE__ */ a("div", {
|
|
1105
|
+
ref: c,
|
|
1106
|
+
className: "seg-context-menu",
|
|
1107
|
+
style: {
|
|
1108
|
+
left: e,
|
|
1109
|
+
top: n
|
|
1110
|
+
},
|
|
1111
|
+
children: i.map((e, t) => "type" in e && e.type === "separator" ? /* @__PURE__ */ a("hr", { className: "seg-context-menu-separator" }, t) : /* @__PURE__ */ o("button", {
|
|
1112
|
+
className: "seg-context-menu-item",
|
|
1113
|
+
disabled: "disabled" in e ? e.disabled : !1,
|
|
1114
|
+
onClick: () => {
|
|
1115
|
+
"onClick" in e && e.onClick(), s();
|
|
1116
|
+
},
|
|
1117
|
+
children: [/* @__PURE__ */ a("span", {
|
|
1118
|
+
className: "seg-context-menu-label",
|
|
1119
|
+
children: "label" in e ? e.label : ""
|
|
1120
|
+
}), "shortcut" in e && e.shortcut && /* @__PURE__ */ a("span", {
|
|
1121
|
+
className: "seg-context-menu-shortcut",
|
|
1122
|
+
children: e.shortcut
|
|
1123
|
+
})]
|
|
1124
|
+
}, t))
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
//#endregion
|
|
1128
|
+
//#region src/SimpleExGrid.tsx
|
|
1129
|
+
function A(t) {
|
|
1130
|
+
let { rows: s, columns: c, mode: l = "select", onChange: u, showRowGripHeader: f = !0, showColumnGripHeader: p = !0, rowHeight: v = "single-line", allowRowAdd: y = !1, allowRowDelete: b = !1, onEditStart: x, onEditCommit: S, onEditCancel: C, onActiveCellChange: A, onRowsAdd: j, onRowsDelete: M, pagination: N = !1, pageSize: P = 20, page: F, onPageChange: ee, onPageSizeChange: I, clipboard: L, colSpan: R, cellAlign: z, maxHistory: B = 200, shouldRecordHistory: V, historyApiRef: H } = t, U = L?.enabled !== !1, te = L?.format ?? "both", ne = r(null), W = D({
|
|
1131
|
+
totalRows: s.length,
|
|
1132
|
+
pageSize: P,
|
|
1133
|
+
page: F,
|
|
1134
|
+
onPageChange: ee,
|
|
1135
|
+
onPageSizeChange: I
|
|
1136
|
+
}), re = N ? s.slice(W.startRow, W.endRow) : s, ie = N ? W.startRow : 0, G = s.length, K = c.length, ae = n(() => {
|
|
1137
|
+
let e = /* @__PURE__ */ new Set();
|
|
1138
|
+
return c.forEach((t, n) => {
|
|
1139
|
+
t.hidden && e.add(n);
|
|
1140
|
+
}), e;
|
|
1141
|
+
}, [c]), q = d({
|
|
1142
|
+
rowCount: G,
|
|
1143
|
+
colCount: K,
|
|
1144
|
+
selection: t.selection,
|
|
1145
|
+
onSelectionChange: t.onSelectionChange,
|
|
1146
|
+
onActiveCellChange: A,
|
|
1147
|
+
colSpan: R,
|
|
1148
|
+
hiddenColumns: ae
|
|
1149
|
+
}), J = T({
|
|
1150
|
+
rows: s,
|
|
1151
|
+
selection: q,
|
|
1152
|
+
onChange: u,
|
|
1153
|
+
onRowsAdd: j,
|
|
1154
|
+
onRowsDelete: M,
|
|
1155
|
+
maxHistory: B,
|
|
1156
|
+
shouldRecordHistory: V,
|
|
1157
|
+
historyApiRef: H
|
|
1158
|
+
}), Y = _({
|
|
1159
|
+
rows: s,
|
|
1160
|
+
columns: c,
|
|
1161
|
+
mode: l,
|
|
1162
|
+
activeCell: q.activeCell,
|
|
1163
|
+
onChange: J.wrappedOnChange,
|
|
1164
|
+
onCommitMove: q.moveActiveCell,
|
|
1165
|
+
onEditStart: x,
|
|
1166
|
+
onEditCommit: S,
|
|
1167
|
+
onEditCancel: C
|
|
1168
|
+
}), X = w({
|
|
1169
|
+
rows: s,
|
|
1170
|
+
columns: c,
|
|
1171
|
+
mode: l,
|
|
1172
|
+
selection: q,
|
|
1173
|
+
onChange: J.wrappedOnChange,
|
|
1174
|
+
clipboardFormat: te,
|
|
1175
|
+
allowRowAdd: y,
|
|
1176
|
+
allowRowDelete: b,
|
|
1177
|
+
onRowsAdd: J.wrappedOnRowsAdd,
|
|
1178
|
+
onRowsDelete: J.wrappedOnRowsDelete,
|
|
1179
|
+
colSpan: R
|
|
1180
|
+
}), Z = m({
|
|
1181
|
+
mode: l,
|
|
1182
|
+
selection: q,
|
|
1183
|
+
editing: Y
|
|
1184
|
+
}), Q = h({
|
|
1185
|
+
selection: q,
|
|
1186
|
+
rowCount: G,
|
|
1187
|
+
colCount: K
|
|
1188
|
+
}), oe = g({
|
|
1189
|
+
selection: q,
|
|
1190
|
+
editing: Y,
|
|
1191
|
+
mode: l,
|
|
1192
|
+
rowCount: G,
|
|
1193
|
+
colCount: K
|
|
1194
|
+
}), { scrollRef: se, areaRef: ce, state: $, onVBarPointerDown: le, onHBarPointerDown: ue, onBarPointerMove: de, onBarPointerUp: fe } = E(), [pe, me] = i(null), he = e((e) => {
|
|
1195
|
+
e.preventDefault();
|
|
1196
|
+
let t = e.target.closest("[data-row][data-col]");
|
|
1197
|
+
if (t) {
|
|
1198
|
+
let e = parseInt(t.dataset.row, 10), n = parseInt(t.dataset.col, 10);
|
|
1199
|
+
!isNaN(e) && !isNaN(n) && !q.isSelected(e, n) && q.selectCell(e, n);
|
|
1200
|
+
}
|
|
1201
|
+
me({
|
|
1202
|
+
x: e.clientX,
|
|
1203
|
+
y: e.clientY
|
|
1204
|
+
});
|
|
1205
|
+
}, [q]), ge = e(() => me(null), []), _e = n(() => {
|
|
1206
|
+
let e = l !== "readonly", t = X.hasSelection;
|
|
1207
|
+
return [
|
|
1208
|
+
{
|
|
1209
|
+
label: "元に戻す",
|
|
1210
|
+
shortcut: "Ctrl+Z",
|
|
1211
|
+
disabled: !J.canUndo,
|
|
1212
|
+
onClick: () => J.undo()
|
|
1213
|
+
},
|
|
1214
|
+
{
|
|
1215
|
+
label: "やり直す",
|
|
1216
|
+
shortcut: "Ctrl+Y",
|
|
1217
|
+
disabled: !J.canRedo,
|
|
1218
|
+
onClick: () => J.redo()
|
|
1219
|
+
},
|
|
1220
|
+
{ type: "separator" },
|
|
1221
|
+
{
|
|
1222
|
+
label: "コピー",
|
|
1223
|
+
shortcut: "Ctrl+C",
|
|
1224
|
+
disabled: !t || !U,
|
|
1225
|
+
onClick: () => void X.copy()
|
|
1226
|
+
},
|
|
1227
|
+
{
|
|
1228
|
+
label: "切り取り",
|
|
1229
|
+
shortcut: "Ctrl+X",
|
|
1230
|
+
disabled: !t || !e || !U,
|
|
1231
|
+
onClick: () => void X.cut()
|
|
1232
|
+
},
|
|
1233
|
+
{
|
|
1234
|
+
label: "貼り付け",
|
|
1235
|
+
shortcut: "Ctrl+V",
|
|
1236
|
+
disabled: !e || !U || !y,
|
|
1237
|
+
onClick: () => void X.pasteInsert()
|
|
1238
|
+
},
|
|
1239
|
+
{
|
|
1240
|
+
label: "貼り付け(上書き)",
|
|
1241
|
+
shortcut: "Ctrl+Shift+V",
|
|
1242
|
+
disabled: !t || !e || !U,
|
|
1243
|
+
onClick: () => void X.paste()
|
|
1244
|
+
},
|
|
1245
|
+
{ type: "separator" },
|
|
1246
|
+
{
|
|
1247
|
+
label: "行を追加",
|
|
1248
|
+
shortcut: "Ctrl+I",
|
|
1249
|
+
disabled: !e || !y,
|
|
1250
|
+
onClick: () => X.addRows()
|
|
1251
|
+
},
|
|
1252
|
+
{
|
|
1253
|
+
label: "行を削除",
|
|
1254
|
+
shortcut: "Ctrl+D",
|
|
1255
|
+
disabled: !t || !e || !b,
|
|
1256
|
+
onClick: () => X.deleteRows()
|
|
1257
|
+
},
|
|
1258
|
+
{ type: "separator" },
|
|
1259
|
+
{
|
|
1260
|
+
label: "全選択",
|
|
1261
|
+
shortcut: "Ctrl+A",
|
|
1262
|
+
disabled: G === 0,
|
|
1263
|
+
onClick: () => q.selectAll()
|
|
1264
|
+
},
|
|
1265
|
+
{
|
|
1266
|
+
label: "選択解除",
|
|
1267
|
+
shortcut: "Esc",
|
|
1268
|
+
disabled: !t,
|
|
1269
|
+
onClick: () => q.clearSelection()
|
|
1270
|
+
}
|
|
1271
|
+
];
|
|
1272
|
+
}, [
|
|
1273
|
+
l,
|
|
1274
|
+
X,
|
|
1275
|
+
U,
|
|
1276
|
+
y,
|
|
1277
|
+
b,
|
|
1278
|
+
G,
|
|
1279
|
+
q,
|
|
1280
|
+
J
|
|
1281
|
+
]), ve = e((e) => {
|
|
1282
|
+
if (!Y.editingCell) {
|
|
1283
|
+
if (e.ctrlKey || e.metaKey) {
|
|
1284
|
+
if (e.key === "z" || e.key === "Z") {
|
|
1285
|
+
e.preventDefault(), e.shiftKey ? J.redo() : J.undo();
|
|
1286
|
+
return;
|
|
1287
|
+
}
|
|
1288
|
+
if (e.key === "y") {
|
|
1289
|
+
e.preventDefault(), J.redo();
|
|
1290
|
+
return;
|
|
1291
|
+
}
|
|
1292
|
+
if (U) switch (e.key) {
|
|
1293
|
+
case "c":
|
|
1294
|
+
e.preventDefault(), X.copy();
|
|
1295
|
+
return;
|
|
1296
|
+
case "x":
|
|
1297
|
+
e.preventDefault(), X.cut();
|
|
1298
|
+
return;
|
|
1299
|
+
case "v":
|
|
1300
|
+
e.preventDefault(), e.shiftKey ? X.paste() : X.pasteInsert();
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1303
|
+
if (l !== "readonly") switch (e.key) {
|
|
1304
|
+
case "i":
|
|
1305
|
+
y && (e.preventDefault(), X.addRows());
|
|
1306
|
+
return;
|
|
1307
|
+
case "d":
|
|
1308
|
+
b && X.hasSelection && (e.preventDefault(), X.deleteRows());
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
if (e.key === "Escape") {
|
|
1313
|
+
e.preventDefault(), q.clearSelection();
|
|
1314
|
+
return;
|
|
1315
|
+
}
|
|
1316
|
+
if ((e.key === "Delete" || e.key === "Backspace") && l !== "readonly") {
|
|
1317
|
+
e.preventDefault(), X.cut().catch(() => {});
|
|
1318
|
+
return;
|
|
1319
|
+
}
|
|
1320
|
+
oe.onKeyDown(e);
|
|
1321
|
+
}
|
|
1322
|
+
}, [
|
|
1323
|
+
Y.editingCell,
|
|
1324
|
+
U,
|
|
1325
|
+
X,
|
|
1326
|
+
l,
|
|
1327
|
+
oe,
|
|
1328
|
+
y,
|
|
1329
|
+
b,
|
|
1330
|
+
q,
|
|
1331
|
+
J
|
|
1332
|
+
]), ye = e((e, t, n = 1) => {
|
|
1333
|
+
let r = ["seg-cell"], i = !1;
|
|
1334
|
+
for (let r = t; r < t + n; r++) if (q.isSelected(e, r)) {
|
|
1335
|
+
i = !0;
|
|
1336
|
+
break;
|
|
1337
|
+
}
|
|
1338
|
+
return i && r.push("seg-selected"), q.isActiveCell(e, t) && r.push("seg-active"), Y.isEditing(e, t) && r.push("seg-editing"), r.join(" ");
|
|
1339
|
+
}, [q, Y]), be = e((e) => {
|
|
1340
|
+
let t = q.selectionRange;
|
|
1341
|
+
if (!t) return !1;
|
|
1342
|
+
let n = Math.min(t.start.row, t.end.row), r = Math.max(t.start.row, t.end.row), i = Math.min(t.start.col, t.end.col), a = Math.max(t.start.col, t.end.col);
|
|
1343
|
+
return e >= n && e <= r && i === 0 && a === K - 1;
|
|
1344
|
+
}, [q.selectionRange, K]), xe = n(() => c.map((e) => {
|
|
1345
|
+
let t = e.width;
|
|
1346
|
+
return t === void 0 ? { width: 120 } : t === "fit-content" ? { width: "auto" } : { width: t };
|
|
1347
|
+
}), [c]), Se = v === "single-line", Ce = c.some((e) => e.width === "fit-content" || e.width === void 0) ? void 0 : "fixed";
|
|
1348
|
+
return /* @__PURE__ */ o("div", {
|
|
1349
|
+
ref: ne,
|
|
1350
|
+
className: `seg-container${Se ? " seg-single-line" : ""}`,
|
|
1351
|
+
role: "grid",
|
|
1352
|
+
"data-mode": l,
|
|
1353
|
+
tabIndex: 0,
|
|
1354
|
+
onKeyDown: ve,
|
|
1355
|
+
onContextMenu: he,
|
|
1356
|
+
children: [
|
|
1357
|
+
/* @__PURE__ */ o("div", {
|
|
1358
|
+
className: "seg-scroll-area",
|
|
1359
|
+
ref: ce,
|
|
1360
|
+
children: [
|
|
1361
|
+
/* @__PURE__ */ a("div", {
|
|
1362
|
+
className: "seg-scroll-inner",
|
|
1363
|
+
ref: se,
|
|
1364
|
+
onPointerDown: Z.onPointerDown,
|
|
1365
|
+
onPointerMove: Z.onPointerMove,
|
|
1366
|
+
onPointerUp: Z.onPointerUp,
|
|
1367
|
+
children: /* @__PURE__ */ o("table", {
|
|
1368
|
+
className: "seg-table",
|
|
1369
|
+
style: Ce ? { tableLayout: Ce } : void 0,
|
|
1370
|
+
children: [
|
|
1371
|
+
/* @__PURE__ */ o("colgroup", { children: [f && /* @__PURE__ */ a("col", { style: { width: 32 } }), c.map((e, t) => e.hidden ? null : /* @__PURE__ */ a("col", { style: xe[t] }, e.key))] }),
|
|
1372
|
+
/* @__PURE__ */ o("thead", { children: [p && /* @__PURE__ */ o("tr", {
|
|
1373
|
+
className: "seg-grip-col-row",
|
|
1374
|
+
children: [f && /* @__PURE__ */ a("th", {
|
|
1375
|
+
className: "seg-corner",
|
|
1376
|
+
onClick: () => q.clearSelection()
|
|
1377
|
+
}), c.map((e, t) => e.hidden ? null : /* @__PURE__ */ a("th", {
|
|
1378
|
+
"data-grip-col": t,
|
|
1379
|
+
onPointerDown: Q.onColGripPointerDown,
|
|
1380
|
+
onPointerMove: Q.onColGripPointerMove,
|
|
1381
|
+
onPointerUp: Q.onColGripPointerUp
|
|
1382
|
+
}, e.key))]
|
|
1383
|
+
}), /* @__PURE__ */ o("tr", {
|
|
1384
|
+
className: "seg-header-row",
|
|
1385
|
+
children: [f && /* @__PURE__ */ a("th", {
|
|
1386
|
+
className: "seg-grip-placeholder",
|
|
1387
|
+
onClick: () => q.clearSelection()
|
|
1388
|
+
}), c.map((e) => e.hidden ? null : /* @__PURE__ */ a("th", {
|
|
1389
|
+
style: e.headerAlign ? { textAlign: e.headerAlign } : void 0,
|
|
1390
|
+
children: /* @__PURE__ */ o("span", {
|
|
1391
|
+
className: "seg-header-content",
|
|
1392
|
+
children: [
|
|
1393
|
+
e.header,
|
|
1394
|
+
e.sortMark === "asc" && /* @__PURE__ */ a("span", {
|
|
1395
|
+
className: "seg-sort-indicator",
|
|
1396
|
+
children: " ▲"
|
|
1397
|
+
}),
|
|
1398
|
+
e.sortMark === "desc" && /* @__PURE__ */ a("span", {
|
|
1399
|
+
className: "seg-sort-indicator",
|
|
1400
|
+
children: " ▼"
|
|
1401
|
+
})
|
|
1402
|
+
]
|
|
1403
|
+
})
|
|
1404
|
+
}, e.key))]
|
|
1405
|
+
})] }),
|
|
1406
|
+
/* @__PURE__ */ a("tbody", { children: re.map((e, t) => {
|
|
1407
|
+
let n = t + ie;
|
|
1408
|
+
return /* @__PURE__ */ o("tr", {
|
|
1409
|
+
"data-row": n,
|
|
1410
|
+
children: [f && /* @__PURE__ */ a("td", {
|
|
1411
|
+
className: `seg-grip-row${be(n) ? " seg-selected" : ""}`,
|
|
1412
|
+
"data-grip-row": n,
|
|
1413
|
+
onPointerDown: Q.onRowGripPointerDown,
|
|
1414
|
+
onPointerMove: Q.onRowGripPointerMove,
|
|
1415
|
+
onPointerUp: Q.onRowGripPointerUp
|
|
1416
|
+
}), (() => {
|
|
1417
|
+
let t = [], r = 0;
|
|
1418
|
+
for (; r < c.length;) {
|
|
1419
|
+
let i = R ? Math.max(1, Math.min(R(n, r), c.length - r)) : 1, o = c[r];
|
|
1420
|
+
if (o.hidden) {
|
|
1421
|
+
r += i;
|
|
1422
|
+
continue;
|
|
1423
|
+
}
|
|
1424
|
+
let s = 0;
|
|
1425
|
+
for (let e = 0; e < i; e++) c[r + e]?.hidden || s++;
|
|
1426
|
+
let l = e[o.key], u = o.render ? o.render(l, e, n) : o.formatter ? o.formatter(l, e) : String(l ?? ""), d = z?.(n, r) ?? o.align;
|
|
1427
|
+
t.push(/* @__PURE__ */ a("td", {
|
|
1428
|
+
className: ye(n, r, i),
|
|
1429
|
+
"data-row": n,
|
|
1430
|
+
"data-col": r,
|
|
1431
|
+
colSpan: s > 1 ? s : void 0,
|
|
1432
|
+
style: d ? { textAlign: d } : void 0,
|
|
1433
|
+
onDoubleClick: () => Y.startEditing(n, r),
|
|
1434
|
+
children: Y.isEditing(n, r) ? /* @__PURE__ */ a(O, {
|
|
1435
|
+
value: Y.editValue,
|
|
1436
|
+
onChange: Y.setEditValue,
|
|
1437
|
+
onCommit: Y.commitEdit,
|
|
1438
|
+
onCancel: Y.cancelEdit,
|
|
1439
|
+
onKeyDown: Y.onEditorKeyDown
|
|
1440
|
+
}) : u
|
|
1441
|
+
}, o.key)), r += i;
|
|
1442
|
+
}
|
|
1443
|
+
return t;
|
|
1444
|
+
})()]
|
|
1445
|
+
}, n);
|
|
1446
|
+
}) })
|
|
1447
|
+
]
|
|
1448
|
+
})
|
|
1449
|
+
}),
|
|
1450
|
+
$.showV && /* @__PURE__ */ a("div", {
|
|
1451
|
+
className: "seg-scrollbar seg-scrollbar-v",
|
|
1452
|
+
style: {
|
|
1453
|
+
top: $.vTop,
|
|
1454
|
+
height: $.vHeight
|
|
1455
|
+
},
|
|
1456
|
+
onPointerDown: le,
|
|
1457
|
+
onPointerMove: de,
|
|
1458
|
+
onPointerUp: fe
|
|
1459
|
+
}),
|
|
1460
|
+
$.showH && /* @__PURE__ */ a("div", {
|
|
1461
|
+
className: "seg-scrollbar seg-scrollbar-h",
|
|
1462
|
+
style: {
|
|
1463
|
+
left: $.hLeft,
|
|
1464
|
+
width: $.hWidth
|
|
1465
|
+
},
|
|
1466
|
+
onPointerDown: ue,
|
|
1467
|
+
onPointerMove: de,
|
|
1468
|
+
onPointerUp: fe
|
|
1469
|
+
})
|
|
1470
|
+
]
|
|
1471
|
+
}),
|
|
1472
|
+
N && /* @__PURE__ */ o("div", {
|
|
1473
|
+
className: "seg-pagination",
|
|
1474
|
+
children: [/* @__PURE__ */ a("div", {
|
|
1475
|
+
className: "seg-pagination-info",
|
|
1476
|
+
children: s.length === 0 ? "0 件" : `${W.startRow + 1}–${W.endRow} / ${s.length} 件`
|
|
1477
|
+
}), /* @__PURE__ */ o("div", {
|
|
1478
|
+
className: "seg-pagination-controls",
|
|
1479
|
+
children: [
|
|
1480
|
+
/* @__PURE__ */ a("button", {
|
|
1481
|
+
className: "seg-pagination-btn",
|
|
1482
|
+
disabled: W.currentPage === 0,
|
|
1483
|
+
onClick: W.goFirst,
|
|
1484
|
+
children: "«"
|
|
1485
|
+
}),
|
|
1486
|
+
/* @__PURE__ */ a("button", {
|
|
1487
|
+
className: "seg-pagination-btn",
|
|
1488
|
+
disabled: W.currentPage === 0,
|
|
1489
|
+
onClick: W.goPrev,
|
|
1490
|
+
children: "‹"
|
|
1491
|
+
}),
|
|
1492
|
+
/* @__PURE__ */ o("span", {
|
|
1493
|
+
className: "seg-pagination-page",
|
|
1494
|
+
children: [
|
|
1495
|
+
W.currentPage + 1,
|
|
1496
|
+
" / ",
|
|
1497
|
+
W.totalPages
|
|
1498
|
+
]
|
|
1499
|
+
}),
|
|
1500
|
+
/* @__PURE__ */ a("button", {
|
|
1501
|
+
className: "seg-pagination-btn",
|
|
1502
|
+
disabled: W.currentPage >= W.totalPages - 1,
|
|
1503
|
+
onClick: W.goNext,
|
|
1504
|
+
children: "›"
|
|
1505
|
+
}),
|
|
1506
|
+
/* @__PURE__ */ a("button", {
|
|
1507
|
+
className: "seg-pagination-btn",
|
|
1508
|
+
disabled: W.currentPage >= W.totalPages - 1,
|
|
1509
|
+
onClick: W.goLast,
|
|
1510
|
+
children: "»"
|
|
1511
|
+
})
|
|
1512
|
+
]
|
|
1513
|
+
})]
|
|
1514
|
+
}),
|
|
1515
|
+
pe && /* @__PURE__ */ a(k, {
|
|
1516
|
+
x: pe.x,
|
|
1517
|
+
y: pe.y,
|
|
1518
|
+
items: _e,
|
|
1519
|
+
onClose: ge
|
|
1520
|
+
})
|
|
1521
|
+
]
|
|
1522
|
+
});
|
|
1523
|
+
}
|
|
1524
|
+
//#endregion
|
|
1525
|
+
export { A as SimpleExGrid };
|