@skygraph/react 0.0.0-placeholder.0 → 0.5.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/LICENSE +21 -0
- package/README.md +70 -12
- package/dist/Table-BmesoMje.d.ts +1017 -0
- package/dist/Table-CpKMOH2x.d.cts +1017 -0
- package/dist/chunk-2OCEO636.js +91 -0
- package/dist/chunk-2OCEO636.js.map +1 -0
- package/dist/chunk-BNMJSYI2.js +54 -0
- package/dist/chunk-BNMJSYI2.js.map +1 -0
- package/dist/chunk-FSV73JI4.js +58 -0
- package/dist/chunk-FSV73JI4.js.map +1 -0
- package/dist/chunk-GJDDPZH7.js +226 -0
- package/dist/chunk-GJDDPZH7.js.map +1 -0
- package/dist/chunk-MLEBVELO.js +1412 -0
- package/dist/chunk-MLEBVELO.js.map +1 -0
- package/dist/chunk-NXB3VAVF.js +3794 -0
- package/dist/chunk-NXB3VAVF.js.map +1 -0
- package/dist/chunk-SEQI65CF.js +61 -0
- package/dist/chunk-SEQI65CF.js.map +1 -0
- package/dist/chunk-UO6VJC3C.js +1667 -0
- package/dist/chunk-UO6VJC3C.js.map +1 -0
- package/dist/chunk-Z5UGF7EO.js +847 -0
- package/dist/chunk-Z5UGF7EO.js.map +1 -0
- package/dist/chunk-ZJF6SJLP.js +200 -0
- package/dist/chunk-ZJF6SJLP.js.map +1 -0
- package/dist/common-CdpocIEz.d.cts +27 -0
- package/dist/common-CdpocIEz.d.ts +27 -0
- package/dist/datagrid-B6hg5yJh.d.cts +200 -0
- package/dist/datagrid-B6hg5yJh.d.ts +200 -0
- package/dist/datagrid.cjs +1053 -0
- package/dist/datagrid.cjs.map +1 -0
- package/dist/datagrid.d.cts +2 -0
- package/dist/datagrid.d.ts +2 -0
- package/dist/datagrid.js +10 -0
- package/dist/datagrid.js.map +1 -0
- package/dist/devtools.cjs +253 -0
- package/dist/devtools.cjs.map +1 -0
- package/dist/devtools.d.cts +29 -0
- package/dist/devtools.d.ts +29 -0
- package/dist/devtools.js +9 -0
- package/dist/devtools.js.map +1 -0
- package/dist/form.cjs +1723 -0
- package/dist/form.cjs.map +1 -0
- package/dist/form.d.cts +530 -0
- package/dist/form.d.ts +530 -0
- package/dist/form.js +49 -0
- package/dist/form.js.map +1 -0
- package/dist/index.cjs +22467 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3685 -0
- package/dist/index.d.ts +3685 -0
- package/dist/index.js +14131 -0
- package/dist/index.js.map +1 -0
- package/dist/table.cjs +4134 -0
- package/dist/table.cjs.map +1 -0
- package/dist/table.d.cts +31 -0
- package/dist/table.d.ts +31 -0
- package/dist/table.js +26 -0
- package/dist/table.js.map +1 -0
- package/dist/tree.cjs +1822 -0
- package/dist/tree.cjs.map +1 -0
- package/dist/tree.d.cts +348 -0
- package/dist/tree.d.ts +348 -0
- package/dist/tree.js +13 -0
- package/dist/tree.js.map +1 -0
- package/dist/virtual.cjs +145 -0
- package/dist/virtual.cjs.map +1 -0
- package/dist/virtual.d.cts +50 -0
- package/dist/virtual.d.ts +50 -0
- package/dist/virtual.js +11 -0
- package/dist/virtual.js.map +1 -0
- package/package.json +108 -18
- package/index.js +0 -3
|
@@ -0,0 +1,3794 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Button,
|
|
3
|
+
Input,
|
|
4
|
+
Transition
|
|
5
|
+
} from "./chunk-ZJF6SJLP.js";
|
|
6
|
+
import {
|
|
7
|
+
Checkbox
|
|
8
|
+
} from "./chunk-FSV73JI4.js";
|
|
9
|
+
import {
|
|
10
|
+
Spin,
|
|
11
|
+
useConfig
|
|
12
|
+
} from "./chunk-2OCEO636.js";
|
|
13
|
+
|
|
14
|
+
// src/components/ui/Pagination.tsx
|
|
15
|
+
import { useState } from "react";
|
|
16
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
17
|
+
function Pagination({
|
|
18
|
+
current,
|
|
19
|
+
total,
|
|
20
|
+
pageSize = 10,
|
|
21
|
+
onChange,
|
|
22
|
+
onPageSizeChange,
|
|
23
|
+
showTotal,
|
|
24
|
+
disabled: disabledProp,
|
|
25
|
+
simple,
|
|
26
|
+
showSizeChanger,
|
|
27
|
+
pageSizeOptions = [10, 20, 50, 100],
|
|
28
|
+
showQuickJumper,
|
|
29
|
+
className,
|
|
30
|
+
style,
|
|
31
|
+
unstyled
|
|
32
|
+
}) {
|
|
33
|
+
const config = useConfig();
|
|
34
|
+
const disabled = disabledProp ?? config.disabled ?? false;
|
|
35
|
+
const locale = config.locale?.pagination;
|
|
36
|
+
const totalPrefix = locale?.totalPrefix ?? "Total";
|
|
37
|
+
const itemsPerPageLabel = locale?.itemsPerPage ?? "/ page";
|
|
38
|
+
const jumpLabel = locale?.jump ?? "Go to";
|
|
39
|
+
const ariaLabel = locale?.ariaLabel ?? "Pagination";
|
|
40
|
+
const [jumpValue, setJumpValue] = useState("");
|
|
41
|
+
const totalPages = Math.max(1, Math.ceil(total / pageSize));
|
|
42
|
+
const safeCurrentPage = Math.min(Math.max(1, current), totalPages);
|
|
43
|
+
const rangeStart = (safeCurrentPage - 1) * pageSize + 1;
|
|
44
|
+
const rangeEnd = Math.min(safeCurrentPage * pageSize, total);
|
|
45
|
+
const go = (page) => {
|
|
46
|
+
if (disabled || page < 1 || page > totalPages || page === safeCurrentPage) return;
|
|
47
|
+
onChange?.(page);
|
|
48
|
+
};
|
|
49
|
+
const handleJump = () => {
|
|
50
|
+
const num = parseInt(jumpValue, 10);
|
|
51
|
+
if (!isNaN(num)) {
|
|
52
|
+
go(num);
|
|
53
|
+
}
|
|
54
|
+
setJumpValue("");
|
|
55
|
+
};
|
|
56
|
+
const pages = buildPages(safeCurrentPage, totalPages);
|
|
57
|
+
const renderTotal = () => {
|
|
58
|
+
if (!showTotal) return null;
|
|
59
|
+
if (typeof showTotal === "function") {
|
|
60
|
+
return /* @__PURE__ */ jsx("span", { className: "sg-pagination-total", children: showTotal(total, [rangeStart, rangeEnd]) });
|
|
61
|
+
}
|
|
62
|
+
return /* @__PURE__ */ jsxs("span", { className: "sg-pagination-total", children: [
|
|
63
|
+
totalPrefix,
|
|
64
|
+
" ",
|
|
65
|
+
total
|
|
66
|
+
] });
|
|
67
|
+
};
|
|
68
|
+
const renderSizeChanger = () => {
|
|
69
|
+
if (!showSizeChanger) return null;
|
|
70
|
+
return /* @__PURE__ */ jsx(
|
|
71
|
+
"select",
|
|
72
|
+
{
|
|
73
|
+
className: "sg-pagination-size-changer",
|
|
74
|
+
value: pageSize,
|
|
75
|
+
onChange: (e) => onPageSizeChange?.(Number(e.target.value)),
|
|
76
|
+
disabled,
|
|
77
|
+
children: pageSizeOptions.map((opt) => /* @__PURE__ */ jsxs("option", { value: opt, children: [
|
|
78
|
+
opt,
|
|
79
|
+
" ",
|
|
80
|
+
itemsPerPageLabel
|
|
81
|
+
] }, opt))
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
const renderQuickJumper = () => {
|
|
86
|
+
if (!showQuickJumper) return null;
|
|
87
|
+
return /* @__PURE__ */ jsxs("span", { className: "sg-pagination-quick-jumper", children: [
|
|
88
|
+
jumpLabel,
|
|
89
|
+
/* @__PURE__ */ jsx(
|
|
90
|
+
"input",
|
|
91
|
+
{
|
|
92
|
+
type: "text",
|
|
93
|
+
value: jumpValue,
|
|
94
|
+
onChange: (e) => setJumpValue(e.target.value),
|
|
95
|
+
onKeyDown: (e) => {
|
|
96
|
+
if (e.key === "Enter") handleJump();
|
|
97
|
+
},
|
|
98
|
+
onBlur: handleJump,
|
|
99
|
+
disabled,
|
|
100
|
+
className: "sg-pagination-jumper-input"
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
] });
|
|
104
|
+
};
|
|
105
|
+
if (unstyled) {
|
|
106
|
+
return /* @__PURE__ */ jsxs("nav", { className, style, "aria-label": ariaLabel, children: [
|
|
107
|
+
/* @__PURE__ */ jsx("button", { disabled: safeCurrentPage <= 1, onClick: () => go(safeCurrentPage - 1), children: "\u2039" }),
|
|
108
|
+
pages.map(
|
|
109
|
+
(p, i) => p === "..." ? /* @__PURE__ */ jsx("span", { children: "\u2026" }, `e${i}`) : /* @__PURE__ */ jsx(
|
|
110
|
+
"button",
|
|
111
|
+
{
|
|
112
|
+
onClick: () => go(p),
|
|
113
|
+
"aria-current": p === safeCurrentPage ? "page" : void 0,
|
|
114
|
+
children: p
|
|
115
|
+
},
|
|
116
|
+
p
|
|
117
|
+
)
|
|
118
|
+
),
|
|
119
|
+
/* @__PURE__ */ jsx("button", { disabled: safeCurrentPage >= totalPages, onClick: () => go(safeCurrentPage + 1), children: "\u203A" })
|
|
120
|
+
] });
|
|
121
|
+
}
|
|
122
|
+
if (simple) {
|
|
123
|
+
return /* @__PURE__ */ jsxs(
|
|
124
|
+
"nav",
|
|
125
|
+
{
|
|
126
|
+
className: [
|
|
127
|
+
"sg-pagination sg-pagination-simple",
|
|
128
|
+
disabled ? "sg-pagination-disabled" : "",
|
|
129
|
+
className
|
|
130
|
+
].filter(Boolean).join(" "),
|
|
131
|
+
style,
|
|
132
|
+
"aria-label": ariaLabel,
|
|
133
|
+
children: [
|
|
134
|
+
/* @__PURE__ */ jsx(
|
|
135
|
+
"button",
|
|
136
|
+
{
|
|
137
|
+
className: "sg-pagination-item sg-pagination-prev",
|
|
138
|
+
disabled: safeCurrentPage <= 1,
|
|
139
|
+
onClick: () => go(safeCurrentPage - 1),
|
|
140
|
+
children: "\u2039"
|
|
141
|
+
}
|
|
142
|
+
),
|
|
143
|
+
/* @__PURE__ */ jsxs("span", { className: "sg-pagination-simple-pager", children: [
|
|
144
|
+
safeCurrentPage,
|
|
145
|
+
" / ",
|
|
146
|
+
totalPages
|
|
147
|
+
] }),
|
|
148
|
+
/* @__PURE__ */ jsx(
|
|
149
|
+
"button",
|
|
150
|
+
{
|
|
151
|
+
className: "sg-pagination-item sg-pagination-next",
|
|
152
|
+
disabled: safeCurrentPage >= totalPages,
|
|
153
|
+
onClick: () => go(safeCurrentPage + 1),
|
|
154
|
+
children: "\u203A"
|
|
155
|
+
}
|
|
156
|
+
)
|
|
157
|
+
]
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
return /* @__PURE__ */ jsxs(
|
|
162
|
+
"nav",
|
|
163
|
+
{
|
|
164
|
+
className: ["sg-pagination", disabled ? "sg-pagination-disabled" : "", className].filter(Boolean).join(" "),
|
|
165
|
+
style,
|
|
166
|
+
"aria-label": ariaLabel,
|
|
167
|
+
children: [
|
|
168
|
+
renderTotal(),
|
|
169
|
+
/* @__PURE__ */ jsx(
|
|
170
|
+
"button",
|
|
171
|
+
{
|
|
172
|
+
className: "sg-pagination-item sg-pagination-prev",
|
|
173
|
+
disabled: safeCurrentPage <= 1,
|
|
174
|
+
onClick: () => go(safeCurrentPage - 1),
|
|
175
|
+
children: "\u2039"
|
|
176
|
+
}
|
|
177
|
+
),
|
|
178
|
+
pages.map(
|
|
179
|
+
(p, i) => p === "..." ? /* @__PURE__ */ jsx("span", { className: "sg-pagination-ellipsis", children: "\u2026" }, `e${i}`) : /* @__PURE__ */ jsx(
|
|
180
|
+
"button",
|
|
181
|
+
{
|
|
182
|
+
className: `sg-pagination-item${p === safeCurrentPage ? " sg-pagination-item-active" : ""}`,
|
|
183
|
+
onClick: () => go(p),
|
|
184
|
+
"aria-current": p === safeCurrentPage ? "page" : void 0,
|
|
185
|
+
children: p
|
|
186
|
+
},
|
|
187
|
+
p
|
|
188
|
+
)
|
|
189
|
+
),
|
|
190
|
+
/* @__PURE__ */ jsx(
|
|
191
|
+
"button",
|
|
192
|
+
{
|
|
193
|
+
className: "sg-pagination-item sg-pagination-next",
|
|
194
|
+
disabled: safeCurrentPage >= totalPages,
|
|
195
|
+
onClick: () => go(safeCurrentPage + 1),
|
|
196
|
+
children: "\u203A"
|
|
197
|
+
}
|
|
198
|
+
),
|
|
199
|
+
renderSizeChanger(),
|
|
200
|
+
renderQuickJumper()
|
|
201
|
+
]
|
|
202
|
+
}
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
function buildPages(current, total) {
|
|
206
|
+
if (total <= 7) {
|
|
207
|
+
return Array.from({ length: total }, (_, i) => i + 1);
|
|
208
|
+
}
|
|
209
|
+
if (current <= 4) {
|
|
210
|
+
return [1, 2, 3, 4, 5, "...", total];
|
|
211
|
+
}
|
|
212
|
+
if (current >= total - 3) {
|
|
213
|
+
return [1, "...", total - 4, total - 3, total - 2, total - 1, total];
|
|
214
|
+
}
|
|
215
|
+
return [1, "...", current - 1, current, current + 1, "...", total];
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// src/components/ui/Select.tsx
|
|
219
|
+
import { useState as useState2, useRef, useEffect, useId } from "react";
|
|
220
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
221
|
+
function Select(props) {
|
|
222
|
+
const {
|
|
223
|
+
options,
|
|
224
|
+
placeholder = "Select...",
|
|
225
|
+
disabled: disabledProp,
|
|
226
|
+
loading,
|
|
227
|
+
size: sizeProp,
|
|
228
|
+
onBlur,
|
|
229
|
+
className,
|
|
230
|
+
style,
|
|
231
|
+
unstyled,
|
|
232
|
+
"aria-label": ariaLabel,
|
|
233
|
+
"aria-labelledby": ariaLabelledBy
|
|
234
|
+
} = props;
|
|
235
|
+
const isMultiple = props.multiple === true;
|
|
236
|
+
const config = useConfig();
|
|
237
|
+
const size = sizeProp ?? config.size ?? "middle";
|
|
238
|
+
const disabled = disabledProp ?? config.disabled ?? false;
|
|
239
|
+
const initialSingle = isMultiple ? void 0 : props.value ?? props.defaultValue;
|
|
240
|
+
const initialMultiple = isMultiple ? props.value ?? props.defaultValue ?? [] : [];
|
|
241
|
+
const [internalSingle, setInternalSingle] = useState2(initialSingle);
|
|
242
|
+
const [internalMultiple, setInternalMultiple] = useState2(initialMultiple);
|
|
243
|
+
const [open, setOpen] = useState2(false);
|
|
244
|
+
const [focusedIndex, setFocusedIndex] = useState2(-1);
|
|
245
|
+
const ref = useRef(null);
|
|
246
|
+
const listboxId = useId();
|
|
247
|
+
const currentSingle = isMultiple ? void 0 : props.value ?? internalSingle;
|
|
248
|
+
const currentMultiple = isMultiple ? props.value ?? internalMultiple : [];
|
|
249
|
+
const selectedOption = isMultiple ? void 0 : options.find((o) => o.value === currentSingle);
|
|
250
|
+
const selectedOptions = isMultiple ? options.filter((o) => currentMultiple.includes(o.value)) : [];
|
|
251
|
+
useEffect(() => {
|
|
252
|
+
const handleClickOutside = (e) => {
|
|
253
|
+
if (ref.current && !ref.current.contains(e.target)) {
|
|
254
|
+
setOpen(false);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
258
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
259
|
+
}, []);
|
|
260
|
+
useEffect(() => {
|
|
261
|
+
if (!open) setFocusedIndex(-1);
|
|
262
|
+
}, [open]);
|
|
263
|
+
const emitSingle = (val) => {
|
|
264
|
+
setInternalSingle(val);
|
|
265
|
+
if (!isMultiple) props.onChange?.(val);
|
|
266
|
+
};
|
|
267
|
+
const emitMultiple = (vals) => {
|
|
268
|
+
setInternalMultiple(vals);
|
|
269
|
+
if (isMultiple) props.onChange?.(vals);
|
|
270
|
+
};
|
|
271
|
+
const handleSelect = (opt) => {
|
|
272
|
+
if (opt.disabled || opt.loading) return;
|
|
273
|
+
if (isMultiple) {
|
|
274
|
+
const exists = currentMultiple.includes(opt.value);
|
|
275
|
+
const next = exists ? currentMultiple.filter((v) => v !== opt.value) : [...currentMultiple, opt.value];
|
|
276
|
+
emitMultiple(next);
|
|
277
|
+
} else {
|
|
278
|
+
emitSingle(opt.value);
|
|
279
|
+
setOpen(false);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
const handleRemoveTag = (val, e) => {
|
|
283
|
+
e.stopPropagation();
|
|
284
|
+
if (disabled || loading) return;
|
|
285
|
+
emitMultiple(currentMultiple.filter((v) => v !== val));
|
|
286
|
+
};
|
|
287
|
+
if (unstyled) {
|
|
288
|
+
if (isMultiple) {
|
|
289
|
+
return /* @__PURE__ */ jsx2(
|
|
290
|
+
"select",
|
|
291
|
+
{
|
|
292
|
+
className,
|
|
293
|
+
style,
|
|
294
|
+
multiple: true,
|
|
295
|
+
value: currentMultiple.map(String),
|
|
296
|
+
disabled: disabled || loading,
|
|
297
|
+
"aria-label": ariaLabel,
|
|
298
|
+
"aria-labelledby": ariaLabelledBy,
|
|
299
|
+
onChange: (e) => {
|
|
300
|
+
const picked = Array.from(e.target.selectedOptions).map((o) => {
|
|
301
|
+
const v = o.value;
|
|
302
|
+
const numVal = Number(v);
|
|
303
|
+
return options.some((opt) => opt.value === numVal) ? numVal : v;
|
|
304
|
+
});
|
|
305
|
+
emitMultiple(picked);
|
|
306
|
+
},
|
|
307
|
+
onBlur,
|
|
308
|
+
children: options.map((opt) => /* @__PURE__ */ jsx2("option", { value: opt.value, disabled: opt.disabled, children: opt.label }, opt.value))
|
|
309
|
+
}
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
return /* @__PURE__ */ jsxs2(
|
|
313
|
+
"select",
|
|
314
|
+
{
|
|
315
|
+
className,
|
|
316
|
+
style,
|
|
317
|
+
value: currentSingle,
|
|
318
|
+
disabled: disabled || loading,
|
|
319
|
+
"aria-label": ariaLabel,
|
|
320
|
+
"aria-labelledby": ariaLabelledBy,
|
|
321
|
+
onChange: (e) => {
|
|
322
|
+
const v = e.target.value;
|
|
323
|
+
const numVal = Number(v);
|
|
324
|
+
const finalVal = options.some((o) => o.value === numVal) ? numVal : v;
|
|
325
|
+
emitSingle(finalVal);
|
|
326
|
+
},
|
|
327
|
+
onBlur,
|
|
328
|
+
children: [
|
|
329
|
+
!selectedOption && /* @__PURE__ */ jsx2("option", { value: "", children: placeholder }),
|
|
330
|
+
options.map((opt) => /* @__PURE__ */ jsx2("option", { value: opt.value, disabled: opt.disabled, children: opt.label }, opt.value))
|
|
331
|
+
]
|
|
332
|
+
}
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
const wrapperClass = [
|
|
336
|
+
"sg-select",
|
|
337
|
+
`sg-select-${size}`,
|
|
338
|
+
isMultiple ? "sg-select-multiple" : "",
|
|
339
|
+
open ? "sg-select-open" : "",
|
|
340
|
+
disabled || loading ? "sg-select-disabled" : "",
|
|
341
|
+
loading ? "sg-select-loading" : "",
|
|
342
|
+
className
|
|
343
|
+
].filter(Boolean).join(" ");
|
|
344
|
+
const isOptionSelected = (opt) => isMultiple ? currentMultiple.includes(opt.value) : opt.value === currentSingle;
|
|
345
|
+
const renderTrigger = () => {
|
|
346
|
+
if (isMultiple) {
|
|
347
|
+
if (selectedOptions.length === 0) {
|
|
348
|
+
return /* @__PURE__ */ jsx2("span", { className: "sg-select-placeholder", children: placeholder });
|
|
349
|
+
}
|
|
350
|
+
return /* @__PURE__ */ jsx2("span", { className: "sg-select-tags", children: selectedOptions.map((opt) => /* @__PURE__ */ jsxs2("span", { className: "sg-select-tag", children: [
|
|
351
|
+
/* @__PURE__ */ jsx2("span", { className: "sg-select-tag-label", children: opt.label }),
|
|
352
|
+
/* @__PURE__ */ jsx2(
|
|
353
|
+
"button",
|
|
354
|
+
{
|
|
355
|
+
type: "button",
|
|
356
|
+
className: "sg-select-tag-remove",
|
|
357
|
+
"aria-label": `Remove ${opt.label}`,
|
|
358
|
+
tabIndex: -1,
|
|
359
|
+
onClick: (e) => handleRemoveTag(opt.value, e),
|
|
360
|
+
children: "\xD7"
|
|
361
|
+
}
|
|
362
|
+
)
|
|
363
|
+
] }, opt.value)) });
|
|
364
|
+
}
|
|
365
|
+
return /* @__PURE__ */ jsx2(
|
|
366
|
+
"span",
|
|
367
|
+
{
|
|
368
|
+
className: selectedOption ? "sg-select-selection-item" : "sg-select-placeholder",
|
|
369
|
+
children: selectedOption?.label ?? placeholder
|
|
370
|
+
}
|
|
371
|
+
);
|
|
372
|
+
};
|
|
373
|
+
return /* @__PURE__ */ jsxs2("div", { className: wrapperClass, ref, style, onBlur, children: [
|
|
374
|
+
/* @__PURE__ */ jsxs2(
|
|
375
|
+
"div",
|
|
376
|
+
{
|
|
377
|
+
className: "sg-select-selector",
|
|
378
|
+
role: "combobox",
|
|
379
|
+
"aria-expanded": open,
|
|
380
|
+
"aria-haspopup": "listbox",
|
|
381
|
+
"aria-controls": listboxId,
|
|
382
|
+
"aria-multiselectable": isMultiple || void 0,
|
|
383
|
+
"aria-label": ariaLabel,
|
|
384
|
+
"aria-labelledby": ariaLabelledBy,
|
|
385
|
+
"aria-disabled": disabled || loading || void 0,
|
|
386
|
+
tabIndex: disabled || loading ? -1 : 0,
|
|
387
|
+
onClick: () => !disabled && !loading && setOpen(!open),
|
|
388
|
+
onKeyDown: (e) => {
|
|
389
|
+
if (disabled || loading) return;
|
|
390
|
+
switch (e.key) {
|
|
391
|
+
case "Enter":
|
|
392
|
+
case " ":
|
|
393
|
+
e.preventDefault();
|
|
394
|
+
if (open && focusedIndex >= 0) {
|
|
395
|
+
handleSelect(options[focusedIndex]);
|
|
396
|
+
} else {
|
|
397
|
+
setOpen(!open);
|
|
398
|
+
}
|
|
399
|
+
break;
|
|
400
|
+
case "Escape":
|
|
401
|
+
e.preventDefault();
|
|
402
|
+
setOpen(false);
|
|
403
|
+
break;
|
|
404
|
+
case "ArrowDown":
|
|
405
|
+
e.preventDefault();
|
|
406
|
+
if (!open) setOpen(true);
|
|
407
|
+
else setFocusedIndex((i) => (i + 1) % options.length);
|
|
408
|
+
break;
|
|
409
|
+
case "ArrowUp":
|
|
410
|
+
e.preventDefault();
|
|
411
|
+
if (!open) setOpen(true);
|
|
412
|
+
else
|
|
413
|
+
setFocusedIndex(
|
|
414
|
+
(i) => (i - 1 + options.length) % options.length
|
|
415
|
+
);
|
|
416
|
+
break;
|
|
417
|
+
case "Backspace":
|
|
418
|
+
if (isMultiple && currentMultiple.length > 0) {
|
|
419
|
+
emitMultiple(currentMultiple.slice(0, -1));
|
|
420
|
+
}
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
children: [
|
|
425
|
+
renderTrigger(),
|
|
426
|
+
loading ? /* @__PURE__ */ jsx2(Spin, { size: "small", unstyled }) : /* @__PURE__ */ jsx2("span", { className: "sg-select-arrow", children: open ? "\u25B2" : "\u25BC" })
|
|
427
|
+
]
|
|
428
|
+
}
|
|
429
|
+
),
|
|
430
|
+
/* @__PURE__ */ jsx2(Transition, { visible: open, name: "sg-slide-up", unmountOnExit: true, children: /* @__PURE__ */ jsx2("div", { className: "sg-select-dropdown", role: "listbox", id: listboxId, "aria-multiselectable": isMultiple || void 0, children: options.map((opt, idx) => /* @__PURE__ */ jsxs2(
|
|
431
|
+
"div",
|
|
432
|
+
{
|
|
433
|
+
role: "option",
|
|
434
|
+
"aria-selected": isOptionSelected(opt),
|
|
435
|
+
className: [
|
|
436
|
+
"sg-select-option",
|
|
437
|
+
isOptionSelected(opt) ? "sg-select-option-selected" : "",
|
|
438
|
+
idx === focusedIndex ? "sg-select-option-focused" : "",
|
|
439
|
+
opt.disabled || opt.loading ? "sg-select-option-disabled" : "",
|
|
440
|
+
opt.loading ? "sg-select-option-loading" : ""
|
|
441
|
+
].filter(Boolean).join(" "),
|
|
442
|
+
onClick: () => handleSelect(opt),
|
|
443
|
+
children: [
|
|
444
|
+
/* @__PURE__ */ jsx2("span", { children: opt.label }),
|
|
445
|
+
opt.loading && /* @__PURE__ */ jsx2(Spin, { size: "small", unstyled })
|
|
446
|
+
]
|
|
447
|
+
},
|
|
448
|
+
opt.value
|
|
449
|
+
)) }) })
|
|
450
|
+
] });
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// src/components/complex/Table/export.ts
|
|
454
|
+
function toCSVString(data) {
|
|
455
|
+
return data.map(
|
|
456
|
+
(row) => row.map((cell) => {
|
|
457
|
+
if (cell.includes(",") || cell.includes('"') || cell.includes("\n")) {
|
|
458
|
+
return `"${cell.replace(/"/g, '""')}"`;
|
|
459
|
+
}
|
|
460
|
+
return cell;
|
|
461
|
+
}).join(",")
|
|
462
|
+
).join("\n");
|
|
463
|
+
}
|
|
464
|
+
function toTSVString(data) {
|
|
465
|
+
return data.map((row) => row.join(" ")).join("\n");
|
|
466
|
+
}
|
|
467
|
+
function toJSONString(headers, rows, pretty = true) {
|
|
468
|
+
const objects = rows.map((row) => {
|
|
469
|
+
const obj = {};
|
|
470
|
+
headers.forEach((h, i) => {
|
|
471
|
+
obj[h] = row[i] ?? "";
|
|
472
|
+
});
|
|
473
|
+
return obj;
|
|
474
|
+
});
|
|
475
|
+
return pretty ? JSON.stringify(objects, null, 2) : JSON.stringify(objects);
|
|
476
|
+
}
|
|
477
|
+
function downloadCSV(content, filename = "export.csv") {
|
|
478
|
+
const blob = new Blob([content], { type: "text/csv;charset=utf-8;" });
|
|
479
|
+
const url = URL.createObjectURL(blob);
|
|
480
|
+
const a = document.createElement("a");
|
|
481
|
+
a.href = url;
|
|
482
|
+
a.download = filename;
|
|
483
|
+
a.click();
|
|
484
|
+
URL.revokeObjectURL(url);
|
|
485
|
+
}
|
|
486
|
+
function downloadJSON(content, filename = "export.json") {
|
|
487
|
+
const blob = new Blob([content], { type: "application/json;charset=utf-8;" });
|
|
488
|
+
const url = URL.createObjectURL(blob);
|
|
489
|
+
const a = document.createElement("a");
|
|
490
|
+
a.href = url;
|
|
491
|
+
a.download = filename;
|
|
492
|
+
a.click();
|
|
493
|
+
URL.revokeObjectURL(url);
|
|
494
|
+
}
|
|
495
|
+
async function copyToClipboard(text) {
|
|
496
|
+
if (navigator.clipboard) {
|
|
497
|
+
await navigator.clipboard.writeText(text);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
function printTable(tableEl) {
|
|
501
|
+
if (!tableEl) return;
|
|
502
|
+
const printWindow = window.open("", "_blank");
|
|
503
|
+
if (!printWindow) return;
|
|
504
|
+
const styles = Array.from(document.querySelectorAll('style, link[rel="stylesheet"]')).map((el) => el.outerHTML).join("\n");
|
|
505
|
+
printWindow.document.write(`<!DOCTYPE html><html><head>${styles}
|
|
506
|
+
<style>
|
|
507
|
+
body { padding: 20px; }
|
|
508
|
+
.sg-table-toolbar, .sg-table-pagination, .sg-table-selection-bar { display: none !important; }
|
|
509
|
+
.sg-table-wrapper { overflow: visible !important; }
|
|
510
|
+
.sg-table-scroll { overflow: visible !important; max-height: none !important; }
|
|
511
|
+
@media print { @page { size: landscape; margin: 1cm; } }
|
|
512
|
+
</style>
|
|
513
|
+
</head><body>${tableEl.outerHTML}</body></html>`);
|
|
514
|
+
printWindow.document.close();
|
|
515
|
+
printWindow.focus();
|
|
516
|
+
setTimeout(() => {
|
|
517
|
+
printWindow.print();
|
|
518
|
+
printWindow.close();
|
|
519
|
+
}, 300);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// src/hooks/useTable.ts
|
|
523
|
+
import { useState as useState3, useCallback, useMemo, useEffect as useEffect2, useRef as useRef2 } from "react";
|
|
524
|
+
import { createCore, createTable } from "@skygraph/core";
|
|
525
|
+
function useTable(options) {
|
|
526
|
+
const [{ core, table }] = useState3(() => {
|
|
527
|
+
const c = createCore();
|
|
528
|
+
const t = createTable(c, options);
|
|
529
|
+
if (options?.data) {
|
|
530
|
+
t.addRows(options.data);
|
|
531
|
+
}
|
|
532
|
+
return { core: c, table: t };
|
|
533
|
+
});
|
|
534
|
+
const [visibleRows, setVisibleRows] = useState3(() => table.getVisibleRows());
|
|
535
|
+
const [tableState, setTableState] = useState3(() => table.getTableState());
|
|
536
|
+
const [pinnedColumns, setPinnedColumns] = useState3(() => table.getPinnedColumns());
|
|
537
|
+
const [columnWidths, setColumnWidthsState] = useState3(
|
|
538
|
+
() => table.getColumnWidths()
|
|
539
|
+
);
|
|
540
|
+
const prevDataRef = useRef2(options?.data);
|
|
541
|
+
useEffect2(() => {
|
|
542
|
+
const newData = options?.data;
|
|
543
|
+
if (newData === prevDataRef.current) return;
|
|
544
|
+
prevDataRef.current = newData;
|
|
545
|
+
table.reset();
|
|
546
|
+
if (newData) {
|
|
547
|
+
table.addRows(newData);
|
|
548
|
+
}
|
|
549
|
+
setVisibleRows(table.getVisibleRows());
|
|
550
|
+
setTableState(table.getTableState());
|
|
551
|
+
}, [options?.data, table]);
|
|
552
|
+
const refresh = useCallback(() => {
|
|
553
|
+
setVisibleRows(table.getVisibleRows());
|
|
554
|
+
setTableState(table.getTableState());
|
|
555
|
+
setPinnedColumns(table.getPinnedColumns());
|
|
556
|
+
setColumnWidthsState(table.getColumnWidths());
|
|
557
|
+
}, [table]);
|
|
558
|
+
const pinColumn = useCallback(
|
|
559
|
+
(column, side) => {
|
|
560
|
+
table.pinColumn(column, side);
|
|
561
|
+
setPinnedColumns(table.getPinnedColumns());
|
|
562
|
+
},
|
|
563
|
+
[table]
|
|
564
|
+
);
|
|
565
|
+
const clearPinned = useCallback(() => {
|
|
566
|
+
table.clearPinned();
|
|
567
|
+
setPinnedColumns(table.getPinnedColumns());
|
|
568
|
+
}, [table]);
|
|
569
|
+
const setColumnWidth = useCallback(
|
|
570
|
+
(column, width) => {
|
|
571
|
+
table.setColumnWidth(column, width);
|
|
572
|
+
setColumnWidthsState(table.getColumnWidths());
|
|
573
|
+
},
|
|
574
|
+
[table]
|
|
575
|
+
);
|
|
576
|
+
const clearColumnWidths = useCallback(() => {
|
|
577
|
+
table.clearColumnWidths();
|
|
578
|
+
setColumnWidthsState(table.getColumnWidths());
|
|
579
|
+
}, [table]);
|
|
580
|
+
const setSort = useCallback(
|
|
581
|
+
(column, direction) => {
|
|
582
|
+
table.setSort(column, direction);
|
|
583
|
+
refresh();
|
|
584
|
+
},
|
|
585
|
+
[table, refresh]
|
|
586
|
+
);
|
|
587
|
+
const setSorts = useCallback(
|
|
588
|
+
(sorts) => {
|
|
589
|
+
table.setSorts(sorts);
|
|
590
|
+
refresh();
|
|
591
|
+
},
|
|
592
|
+
[table, refresh]
|
|
593
|
+
);
|
|
594
|
+
const clearSort = useCallback(() => {
|
|
595
|
+
table.clearSort();
|
|
596
|
+
refresh();
|
|
597
|
+
}, [table, refresh]);
|
|
598
|
+
const addFilter = useCallback(
|
|
599
|
+
(filter) => {
|
|
600
|
+
table.addFilter(filter);
|
|
601
|
+
refresh();
|
|
602
|
+
},
|
|
603
|
+
[table, refresh]
|
|
604
|
+
);
|
|
605
|
+
const removeFilter = useCallback(
|
|
606
|
+
(column) => {
|
|
607
|
+
table.removeFilter(column);
|
|
608
|
+
refresh();
|
|
609
|
+
},
|
|
610
|
+
[table, refresh]
|
|
611
|
+
);
|
|
612
|
+
const clearFilters = useCallback(() => {
|
|
613
|
+
table.clearFilters();
|
|
614
|
+
refresh();
|
|
615
|
+
}, [table, refresh]);
|
|
616
|
+
const setFilterFn = useCallback(
|
|
617
|
+
(fn) => {
|
|
618
|
+
table.setFilterFn(fn);
|
|
619
|
+
refresh();
|
|
620
|
+
},
|
|
621
|
+
[table, refresh]
|
|
622
|
+
);
|
|
623
|
+
const setPage = useCallback(
|
|
624
|
+
(page) => {
|
|
625
|
+
table.setPage(page);
|
|
626
|
+
refresh();
|
|
627
|
+
},
|
|
628
|
+
[table, refresh]
|
|
629
|
+
);
|
|
630
|
+
const nextPage = useCallback(() => {
|
|
631
|
+
table.nextPage();
|
|
632
|
+
refresh();
|
|
633
|
+
}, [table, refresh]);
|
|
634
|
+
const prevPage = useCallback(() => {
|
|
635
|
+
table.prevPage();
|
|
636
|
+
refresh();
|
|
637
|
+
}, [table, refresh]);
|
|
638
|
+
return useMemo(
|
|
639
|
+
() => ({
|
|
640
|
+
core,
|
|
641
|
+
table,
|
|
642
|
+
visibleRows,
|
|
643
|
+
tableState,
|
|
644
|
+
pinnedColumns,
|
|
645
|
+
columnWidths,
|
|
646
|
+
setSort,
|
|
647
|
+
setSorts,
|
|
648
|
+
clearSort,
|
|
649
|
+
addFilter,
|
|
650
|
+
removeFilter,
|
|
651
|
+
clearFilters,
|
|
652
|
+
setFilterFn,
|
|
653
|
+
setPage,
|
|
654
|
+
nextPage,
|
|
655
|
+
prevPage,
|
|
656
|
+
pinColumn,
|
|
657
|
+
clearPinned,
|
|
658
|
+
setColumnWidth,
|
|
659
|
+
clearColumnWidths,
|
|
660
|
+
refresh
|
|
661
|
+
}),
|
|
662
|
+
[
|
|
663
|
+
core,
|
|
664
|
+
table,
|
|
665
|
+
visibleRows,
|
|
666
|
+
tableState,
|
|
667
|
+
pinnedColumns,
|
|
668
|
+
columnWidths,
|
|
669
|
+
setSort,
|
|
670
|
+
setSorts,
|
|
671
|
+
clearSort,
|
|
672
|
+
addFilter,
|
|
673
|
+
removeFilter,
|
|
674
|
+
clearFilters,
|
|
675
|
+
setFilterFn,
|
|
676
|
+
setPage,
|
|
677
|
+
nextPage,
|
|
678
|
+
prevPage,
|
|
679
|
+
pinColumn,
|
|
680
|
+
clearPinned,
|
|
681
|
+
setColumnWidth,
|
|
682
|
+
clearColumnWidths,
|
|
683
|
+
refresh
|
|
684
|
+
]
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// src/utils/print/printElement.ts
|
|
689
|
+
function buildPageRule(opts = {}) {
|
|
690
|
+
const orientation = opts.orientation ?? "portrait";
|
|
691
|
+
const pageSize = opts.pageSize ?? "A4";
|
|
692
|
+
const margins = opts.margins ?? "1cm";
|
|
693
|
+
return `@page { size: ${pageSize} ${orientation}; margin: ${margins}; }`;
|
|
694
|
+
}
|
|
695
|
+
function buildPrintHtml(fragment, opts = {}, documentRef = typeof document !== "undefined" ? document : null) {
|
|
696
|
+
const styles = documentRef === null ? "" : Array.from(documentRef.querySelectorAll('style, link[rel="stylesheet"]')).map((el) => el.outerHTML).join("\n");
|
|
697
|
+
const pageRule = buildPageRule(opts);
|
|
698
|
+
const scale = opts.scale && opts.scale !== 1 ? opts.scale : null;
|
|
699
|
+
const title = escapeHtml(opts.fileName ?? "SkyGraph print");
|
|
700
|
+
const customStyles = opts.customStyles ?? "";
|
|
701
|
+
const wrapperOpen = scale ? `<div class="sg-print-root" style="transform: scale(${scale}); transform-origin: 0 0;">` : `<div class="sg-print-root">`;
|
|
702
|
+
return `<!DOCTYPE html>
|
|
703
|
+
<html>
|
|
704
|
+
<head>
|
|
705
|
+
<meta charset="utf-8" />
|
|
706
|
+
<title>${title}</title>
|
|
707
|
+
${styles}
|
|
708
|
+
<style>
|
|
709
|
+
${pageRule}
|
|
710
|
+
html, body { margin: 0; padding: 0; background: #fff; }
|
|
711
|
+
body { padding: 0; }
|
|
712
|
+
.sg-print-root { width: 100%; }
|
|
713
|
+
${customStyles}
|
|
714
|
+
</style>
|
|
715
|
+
</head>
|
|
716
|
+
<body>
|
|
717
|
+
${wrapperOpen}
|
|
718
|
+
${fragment}
|
|
719
|
+
</div>
|
|
720
|
+
</body>
|
|
721
|
+
</html>`;
|
|
722
|
+
}
|
|
723
|
+
function escapeHtml(s) {
|
|
724
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
725
|
+
}
|
|
726
|
+
function printElement(node, opts = {}) {
|
|
727
|
+
if (!node) return null;
|
|
728
|
+
if (typeof window === "undefined") return null;
|
|
729
|
+
const popup = window.open("", "_blank");
|
|
730
|
+
if (!popup) return null;
|
|
731
|
+
const html = buildPrintHtml(node.outerHTML, opts);
|
|
732
|
+
popup.document.open();
|
|
733
|
+
popup.document.write(html);
|
|
734
|
+
popup.document.close();
|
|
735
|
+
popup.focus();
|
|
736
|
+
if (opts.skipPrint) return popup;
|
|
737
|
+
const trigger = () => {
|
|
738
|
+
try {
|
|
739
|
+
popup.print();
|
|
740
|
+
} catch {
|
|
741
|
+
}
|
|
742
|
+
if (!opts.keepOpen) {
|
|
743
|
+
try {
|
|
744
|
+
popup.close();
|
|
745
|
+
} catch {
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
if (popup.document.readyState === "complete") {
|
|
750
|
+
setTimeout(trigger, 0);
|
|
751
|
+
} else {
|
|
752
|
+
popup.addEventListener("load", () => setTimeout(trigger, 0), { once: true });
|
|
753
|
+
setTimeout(trigger, 300);
|
|
754
|
+
}
|
|
755
|
+
return popup;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// src/components/complex/Table/Table.tsx
|
|
759
|
+
import React5, { forwardRef, useCallback as useCallback4, useImperativeHandle, useMemo as useMemo4, useRef as useRef7 } from "react";
|
|
760
|
+
|
|
761
|
+
// src/components/complex/Table/FilterDropdown.tsx
|
|
762
|
+
import React from "react";
|
|
763
|
+
import { createPortal } from "react-dom";
|
|
764
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
765
|
+
var TEXT_OPS = [
|
|
766
|
+
"eq",
|
|
767
|
+
"neq",
|
|
768
|
+
"contains",
|
|
769
|
+
"startsWith",
|
|
770
|
+
"endsWith",
|
|
771
|
+
"in",
|
|
772
|
+
"notIn",
|
|
773
|
+
"isEmpty",
|
|
774
|
+
"isNotEmpty"
|
|
775
|
+
];
|
|
776
|
+
var NUMBER_OPS = [
|
|
777
|
+
"eq",
|
|
778
|
+
"neq",
|
|
779
|
+
"lt",
|
|
780
|
+
"lte",
|
|
781
|
+
"gt",
|
|
782
|
+
"gte",
|
|
783
|
+
"between",
|
|
784
|
+
"in",
|
|
785
|
+
"notIn",
|
|
786
|
+
"isEmpty",
|
|
787
|
+
"isNotEmpty"
|
|
788
|
+
];
|
|
789
|
+
var NO_VALUE_OPS = /* @__PURE__ */ new Set(["isEmpty", "isNotEmpty"]);
|
|
790
|
+
function FilterTrigger({ col, t, state, actions }) {
|
|
791
|
+
const hasFilter = col.filterDropdown || col.filterMode === "search" || col.filterMode === "advanced" || col.filters && col.filters.length > 0;
|
|
792
|
+
if (!hasFilter) return null;
|
|
793
|
+
const filtered = col.filterMode === "advanced" ? state.advancedFilters[col.key] != null : (state.activeFilters[col.key]?.length ?? 0) > 0;
|
|
794
|
+
const iconNode = col.filterIcon ? typeof col.filterIcon === "function" ? col.filterIcon(filtered) : col.filterIcon : col.filterMode === "search" ? t.searchIcon : t.filterIcon;
|
|
795
|
+
return /* @__PURE__ */ jsx3(
|
|
796
|
+
"span",
|
|
797
|
+
{
|
|
798
|
+
className: `sg-table-filter-trigger${filtered ? " sg-table-filter-active" : ""}`,
|
|
799
|
+
onClick: (e) => {
|
|
800
|
+
e.stopPropagation();
|
|
801
|
+
const isOpen = state.openFilterDropdown === col.key;
|
|
802
|
+
if (isOpen) {
|
|
803
|
+
actions.setOpenFilterDropdown(null);
|
|
804
|
+
actions.setFilterAnchor(null);
|
|
805
|
+
} else {
|
|
806
|
+
actions.setFilterAnchor(e.currentTarget);
|
|
807
|
+
actions.setOpenFilterDropdown(col.key);
|
|
808
|
+
}
|
|
809
|
+
},
|
|
810
|
+
children: iconNode
|
|
811
|
+
}
|
|
812
|
+
);
|
|
813
|
+
}
|
|
814
|
+
function FilterPortal({
|
|
815
|
+
anchor,
|
|
816
|
+
children
|
|
817
|
+
}) {
|
|
818
|
+
const [coords, setCoords] = React.useState(null);
|
|
819
|
+
React.useLayoutEffect(() => {
|
|
820
|
+
if (!anchor) return;
|
|
821
|
+
const update = () => {
|
|
822
|
+
const r = anchor.getBoundingClientRect();
|
|
823
|
+
setCoords({ top: r.bottom + 4, left: r.left });
|
|
824
|
+
};
|
|
825
|
+
update();
|
|
826
|
+
window.addEventListener("scroll", update, true);
|
|
827
|
+
window.addEventListener("resize", update);
|
|
828
|
+
return () => {
|
|
829
|
+
window.removeEventListener("scroll", update, true);
|
|
830
|
+
window.removeEventListener("resize", update);
|
|
831
|
+
};
|
|
832
|
+
}, [anchor]);
|
|
833
|
+
if (!anchor || !coords || typeof document === "undefined") return null;
|
|
834
|
+
return createPortal(
|
|
835
|
+
/* @__PURE__ */ jsx3(
|
|
836
|
+
"div",
|
|
837
|
+
{
|
|
838
|
+
className: "sg-table-filter-portal",
|
|
839
|
+
style: { position: "fixed", top: coords.top, left: coords.left, zIndex: 1100 },
|
|
840
|
+
children
|
|
841
|
+
}
|
|
842
|
+
),
|
|
843
|
+
document.body
|
|
844
|
+
);
|
|
845
|
+
}
|
|
846
|
+
function FilterDropdownContent({ col, t, state, actions, filterRef }) {
|
|
847
|
+
if (state.openFilterDropdown !== col.key) return null;
|
|
848
|
+
if (col.filterDropdown) {
|
|
849
|
+
const props = actions.getFilterDropdownProps(col);
|
|
850
|
+
const content = typeof col.filterDropdown === "function" ? col.filterDropdown(props) : col.filterDropdown;
|
|
851
|
+
return /* @__PURE__ */ jsx3(FilterPortal, { anchor: state.filterAnchor, children: /* @__PURE__ */ jsx3(
|
|
852
|
+
"div",
|
|
853
|
+
{
|
|
854
|
+
className: "sg-table-filter-dropdown",
|
|
855
|
+
ref: filterRef,
|
|
856
|
+
onClick: (e) => e.stopPropagation(),
|
|
857
|
+
children: content
|
|
858
|
+
}
|
|
859
|
+
) });
|
|
860
|
+
}
|
|
861
|
+
if (col.filterMode === "advanced") {
|
|
862
|
+
return /* @__PURE__ */ jsx3(FilterPortal, { anchor: state.filterAnchor, children: /* @__PURE__ */ jsx3(
|
|
863
|
+
AdvancedFilterPanel,
|
|
864
|
+
{
|
|
865
|
+
col,
|
|
866
|
+
t,
|
|
867
|
+
state,
|
|
868
|
+
actions,
|
|
869
|
+
filterRef
|
|
870
|
+
}
|
|
871
|
+
) });
|
|
872
|
+
}
|
|
873
|
+
if (col.filterMode === "search") {
|
|
874
|
+
const searchVal = state.activeFilters[col.key]?.[0] ?? "";
|
|
875
|
+
return /* @__PURE__ */ jsx3(FilterPortal, { anchor: state.filterAnchor, children: /* @__PURE__ */ jsxs3(
|
|
876
|
+
"div",
|
|
877
|
+
{
|
|
878
|
+
className: "sg-table-filter-dropdown sg-table-filter-search-mode",
|
|
879
|
+
ref: filterRef,
|
|
880
|
+
onClick: (e) => e.stopPropagation(),
|
|
881
|
+
children: [
|
|
882
|
+
/* @__PURE__ */ jsx3(
|
|
883
|
+
Input,
|
|
884
|
+
{
|
|
885
|
+
placeholder: `${t.searchPlaceholder.replace("...", "")} ${typeof col.title === "string" ? col.title : ""}...`,
|
|
886
|
+
size: "small",
|
|
887
|
+
value: searchVal,
|
|
888
|
+
onChange: (v) => actions.handleSearchFilterChange(col.key, v)
|
|
889
|
+
}
|
|
890
|
+
),
|
|
891
|
+
/* @__PURE__ */ jsxs3("div", { className: "sg-table-filter-actions", children: [
|
|
892
|
+
/* @__PURE__ */ jsx3(
|
|
893
|
+
Button,
|
|
894
|
+
{
|
|
895
|
+
size: "small",
|
|
896
|
+
onClick: () => {
|
|
897
|
+
actions.handleFilterReset(col.key);
|
|
898
|
+
actions.handleFilterClose(col.key);
|
|
899
|
+
},
|
|
900
|
+
children: t.filterReset
|
|
901
|
+
}
|
|
902
|
+
),
|
|
903
|
+
/* @__PURE__ */ jsx3(
|
|
904
|
+
Button,
|
|
905
|
+
{
|
|
906
|
+
size: "small",
|
|
907
|
+
type: "primary",
|
|
908
|
+
onClick: () => actions.handleFilterConfirm(col.key),
|
|
909
|
+
children: t.filterConfirm
|
|
910
|
+
}
|
|
911
|
+
)
|
|
912
|
+
] })
|
|
913
|
+
]
|
|
914
|
+
}
|
|
915
|
+
) });
|
|
916
|
+
}
|
|
917
|
+
if (!col.filters || col.filters.length === 0) return null;
|
|
918
|
+
const multiple = col.filterMultiple !== false;
|
|
919
|
+
const currentVals = state.activeFilters[col.key] ?? [];
|
|
920
|
+
const searchTxt = state.filterSearchText[col.key] ?? "";
|
|
921
|
+
let visibleFilters = col.filters;
|
|
922
|
+
if (col.filterSearch && searchTxt) {
|
|
923
|
+
visibleFilters = col.filters.filter((f) => {
|
|
924
|
+
if (typeof col.filterSearch === "function") {
|
|
925
|
+
return col.filterSearch(searchTxt, f);
|
|
926
|
+
}
|
|
927
|
+
return f.text.toLowerCase().includes(searchTxt.toLowerCase());
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
return /* @__PURE__ */ jsx3(FilterPortal, { anchor: state.filterAnchor, children: /* @__PURE__ */ jsxs3(
|
|
931
|
+
"div",
|
|
932
|
+
{
|
|
933
|
+
className: "sg-table-filter-dropdown",
|
|
934
|
+
ref: filterRef,
|
|
935
|
+
onClick: (e) => e.stopPropagation(),
|
|
936
|
+
children: [
|
|
937
|
+
col.filterSearch !== void 0 && col.filterSearch !== false && /* @__PURE__ */ jsx3("div", { className: "sg-table-filter-search", children: /* @__PURE__ */ jsx3(
|
|
938
|
+
Input,
|
|
939
|
+
{
|
|
940
|
+
placeholder: t.filterSearchPlaceholder,
|
|
941
|
+
size: "small",
|
|
942
|
+
value: searchTxt,
|
|
943
|
+
onChange: (v) => actions.setFilterSearchText((prev) => ({ ...prev, [col.key]: v }))
|
|
944
|
+
}
|
|
945
|
+
) }),
|
|
946
|
+
/* @__PURE__ */ jsxs3("div", { className: "sg-table-filter-list", children: [
|
|
947
|
+
visibleFilters.map((f) => {
|
|
948
|
+
const checked = currentVals.includes(f.value);
|
|
949
|
+
return /* @__PURE__ */ jsxs3("label", { className: "sg-table-filter-item", children: [
|
|
950
|
+
multiple ? /* @__PURE__ */ jsx3(
|
|
951
|
+
Checkbox,
|
|
952
|
+
{
|
|
953
|
+
checked,
|
|
954
|
+
onChange: () => actions.handleFilterToggle(col.key, f.value, true)
|
|
955
|
+
}
|
|
956
|
+
) : /* @__PURE__ */ jsx3(
|
|
957
|
+
"input",
|
|
958
|
+
{
|
|
959
|
+
type: "radio",
|
|
960
|
+
checked,
|
|
961
|
+
onChange: () => actions.handleFilterToggle(col.key, f.value, false)
|
|
962
|
+
}
|
|
963
|
+
),
|
|
964
|
+
/* @__PURE__ */ jsx3("span", { children: f.text })
|
|
965
|
+
] }, String(f.value));
|
|
966
|
+
}),
|
|
967
|
+
visibleFilters.length === 0 && /* @__PURE__ */ jsx3("div", { className: "sg-table-filter-empty", children: t.filterEmptyText })
|
|
968
|
+
] }),
|
|
969
|
+
/* @__PURE__ */ jsxs3("div", { className: "sg-table-filter-actions", children: [
|
|
970
|
+
/* @__PURE__ */ jsx3(
|
|
971
|
+
Button,
|
|
972
|
+
{
|
|
973
|
+
size: "small",
|
|
974
|
+
onClick: () => {
|
|
975
|
+
actions.handleFilterReset(col.key);
|
|
976
|
+
actions.handleFilterClose(col.key);
|
|
977
|
+
},
|
|
978
|
+
children: t.filterReset
|
|
979
|
+
}
|
|
980
|
+
),
|
|
981
|
+
/* @__PURE__ */ jsx3(Button, { size: "small", type: "primary", onClick: () => actions.handleFilterConfirm(col.key), children: t.filterConfirm })
|
|
982
|
+
] })
|
|
983
|
+
]
|
|
984
|
+
}
|
|
985
|
+
) });
|
|
986
|
+
}
|
|
987
|
+
function AdvancedFilterPanel({ col, t, state, actions, filterRef }) {
|
|
988
|
+
const isNumeric = col.advancedFilterType === "number";
|
|
989
|
+
const defaultOps = isNumeric ? NUMBER_OPS : TEXT_OPS;
|
|
990
|
+
const ops = col.advancedFilterOperators ?? defaultOps;
|
|
991
|
+
const current = state.advancedFilters[col.key];
|
|
992
|
+
const [draftOp, setDraftOp] = React.useState(current?.op ?? ops[0]);
|
|
993
|
+
const [draftValue, setDraftValue] = React.useState(() => formatDraftValue(current?.value));
|
|
994
|
+
const [draftValue2, setDraftValue2] = React.useState(() => {
|
|
995
|
+
const v = current?.value;
|
|
996
|
+
if (Array.isArray(v) && v.length === 2) return String(v[1] ?? "");
|
|
997
|
+
return "";
|
|
998
|
+
});
|
|
999
|
+
React.useEffect(() => {
|
|
1000
|
+
if (current) {
|
|
1001
|
+
setDraftOp(current.op);
|
|
1002
|
+
setDraftValue(formatDraftValue(current.value));
|
|
1003
|
+
if (Array.isArray(current.value) && current.value.length === 2) {
|
|
1004
|
+
setDraftValue2(String(current.value[1] ?? ""));
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
}, [state.openFilterDropdown]);
|
|
1008
|
+
const reset = () => {
|
|
1009
|
+
setDraftOp(ops[0]);
|
|
1010
|
+
setDraftValue("");
|
|
1011
|
+
setDraftValue2("");
|
|
1012
|
+
actions.setAdvancedFilter(col.key, null);
|
|
1013
|
+
actions.handleFilterClose(col.key);
|
|
1014
|
+
};
|
|
1015
|
+
const confirm = () => {
|
|
1016
|
+
if (NO_VALUE_OPS.has(draftOp)) {
|
|
1017
|
+
actions.setAdvancedFilter(col.key, { op: draftOp });
|
|
1018
|
+
} else if (draftOp === "between") {
|
|
1019
|
+
const a = parseValue(draftValue, isNumeric);
|
|
1020
|
+
const b = parseValue(draftValue2, isNumeric);
|
|
1021
|
+
actions.setAdvancedFilter(col.key, { op: "between", value: [a, b] });
|
|
1022
|
+
} else if (draftOp === "in" || draftOp === "notIn") {
|
|
1023
|
+
const list = draftValue.split(",").map((s) => s.trim()).filter((s) => s.length > 0).map((s) => parseValue(s, isNumeric));
|
|
1024
|
+
actions.setAdvancedFilter(col.key, { op: draftOp, value: list });
|
|
1025
|
+
} else {
|
|
1026
|
+
actions.setAdvancedFilter(col.key, {
|
|
1027
|
+
op: draftOp,
|
|
1028
|
+
value: parseValue(draftValue, isNumeric)
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
actions.setOpenFilterDropdown(null);
|
|
1032
|
+
};
|
|
1033
|
+
const showValueInput = !NO_VALUE_OPS.has(draftOp);
|
|
1034
|
+
const showSecondInput = draftOp === "between";
|
|
1035
|
+
const isValueRequired = showValueInput;
|
|
1036
|
+
const valueIsEmpty = isValueRequired && draftValue.trim() === "";
|
|
1037
|
+
const secondValueIsEmpty = showSecondInput && draftValue2.trim() === "";
|
|
1038
|
+
const confirmDisabled = valueIsEmpty || secondValueIsEmpty;
|
|
1039
|
+
return /* @__PURE__ */ jsxs3(
|
|
1040
|
+
"div",
|
|
1041
|
+
{
|
|
1042
|
+
className: "sg-table-filter-dropdown sg-table-filter-advanced-mode",
|
|
1043
|
+
ref: filterRef,
|
|
1044
|
+
onClick: (e) => e.stopPropagation(),
|
|
1045
|
+
children: [
|
|
1046
|
+
/* @__PURE__ */ jsx3("div", { className: "sg-table-filter-advanced-row", children: /* @__PURE__ */ jsx3(
|
|
1047
|
+
Select,
|
|
1048
|
+
{
|
|
1049
|
+
size: "small",
|
|
1050
|
+
value: draftOp,
|
|
1051
|
+
onChange: (v) => setDraftOp(v),
|
|
1052
|
+
options: ops.map((op) => ({ label: operatorLabel(op, t), value: op })),
|
|
1053
|
+
"aria-label": t.filterOperatorAriaLabel
|
|
1054
|
+
}
|
|
1055
|
+
) }),
|
|
1056
|
+
showValueInput && /* @__PURE__ */ jsx3("div", { className: "sg-table-filter-advanced-row", children: /* @__PURE__ */ jsx3(
|
|
1057
|
+
Input,
|
|
1058
|
+
{
|
|
1059
|
+
size: "small",
|
|
1060
|
+
type: isNumeric && draftOp !== "in" && draftOp !== "notIn" && draftOp !== "between" ? "number" : "text",
|
|
1061
|
+
value: draftValue,
|
|
1062
|
+
onChange: setDraftValue,
|
|
1063
|
+
placeholder: draftOp === "in" || draftOp === "notIn" ? t.filterAdvancedInPlaceholder : t.filterAdvancedValuePlaceholder
|
|
1064
|
+
}
|
|
1065
|
+
) }),
|
|
1066
|
+
showSecondInput && /* @__PURE__ */ jsx3("div", { className: "sg-table-filter-advanced-row", children: /* @__PURE__ */ jsx3(
|
|
1067
|
+
Input,
|
|
1068
|
+
{
|
|
1069
|
+
size: "small",
|
|
1070
|
+
type: isNumeric ? "number" : "text",
|
|
1071
|
+
value: draftValue2,
|
|
1072
|
+
onChange: setDraftValue2,
|
|
1073
|
+
placeholder: t.filterAdvancedBetweenMaxPlaceholder
|
|
1074
|
+
}
|
|
1075
|
+
) }),
|
|
1076
|
+
/* @__PURE__ */ jsxs3("div", { className: "sg-table-filter-actions", children: [
|
|
1077
|
+
/* @__PURE__ */ jsx3(Button, { size: "small", onClick: reset, children: t.filterReset }),
|
|
1078
|
+
/* @__PURE__ */ jsx3(Button, { size: "small", type: "primary", disabled: confirmDisabled, onClick: confirm, children: t.filterConfirm })
|
|
1079
|
+
] })
|
|
1080
|
+
]
|
|
1081
|
+
}
|
|
1082
|
+
);
|
|
1083
|
+
}
|
|
1084
|
+
function formatDraftValue(value) {
|
|
1085
|
+
if (value == null) return "";
|
|
1086
|
+
if (Array.isArray(value)) return value.map((v) => String(v ?? "")).join(", ");
|
|
1087
|
+
return String(value);
|
|
1088
|
+
}
|
|
1089
|
+
function parseValue(raw, numeric) {
|
|
1090
|
+
const trimmed = raw.trim();
|
|
1091
|
+
if (trimmed === "") return "";
|
|
1092
|
+
if (numeric) {
|
|
1093
|
+
const n = Number(trimmed);
|
|
1094
|
+
return Number.isNaN(n) ? trimmed : n;
|
|
1095
|
+
}
|
|
1096
|
+
return trimmed;
|
|
1097
|
+
}
|
|
1098
|
+
function operatorLabel(op, t) {
|
|
1099
|
+
const map = {
|
|
1100
|
+
eq: t.filterOpEq,
|
|
1101
|
+
neq: t.filterOpNeq,
|
|
1102
|
+
lt: t.filterOpLt,
|
|
1103
|
+
lte: t.filterOpLte,
|
|
1104
|
+
gt: t.filterOpGt,
|
|
1105
|
+
gte: t.filterOpGte,
|
|
1106
|
+
between: t.filterOpBetween,
|
|
1107
|
+
in: t.filterOpIn,
|
|
1108
|
+
notIn: t.filterOpNotIn,
|
|
1109
|
+
contains: t.filterOpContains,
|
|
1110
|
+
startsWith: t.filterOpStartsWith,
|
|
1111
|
+
endsWith: t.filterOpEndsWith,
|
|
1112
|
+
isEmpty: t.filterOpIsEmpty,
|
|
1113
|
+
isNotEmpty: t.filterOpIsNotEmpty
|
|
1114
|
+
};
|
|
1115
|
+
return map[op];
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
// src/components/complex/Table/TableHeader.tsx
|
|
1119
|
+
import { Fragment, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1120
|
+
function SortIndicator({
|
|
1121
|
+
col,
|
|
1122
|
+
sorts,
|
|
1123
|
+
getSortIndex,
|
|
1124
|
+
getSortDirection,
|
|
1125
|
+
t
|
|
1126
|
+
}) {
|
|
1127
|
+
if (!col.sortable) return null;
|
|
1128
|
+
const dir = getSortDirection(col.key);
|
|
1129
|
+
const idx = getSortIndex(col.key);
|
|
1130
|
+
const isActive = dir !== null;
|
|
1131
|
+
return /* @__PURE__ */ jsxs4("span", { className: `sg-table-sort-arrows${isActive ? " sg-table-sort-active" : ""}`, children: [
|
|
1132
|
+
/* @__PURE__ */ jsx4("span", { className: `sg-table-sort-asc${dir === "asc" ? " sg-table-sort-current" : ""}`, children: t.sortAsc }),
|
|
1133
|
+
/* @__PURE__ */ jsx4("span", { className: `sg-table-sort-desc${dir === "desc" ? " sg-table-sort-current" : ""}`, children: t.sortDesc }),
|
|
1134
|
+
idx >= 0 && sorts.length > 1 && /* @__PURE__ */ jsx4("span", { className: "sg-table-sort-index", children: idx + 1 })
|
|
1135
|
+
] });
|
|
1136
|
+
}
|
|
1137
|
+
function ColumnTooltip({ content }) {
|
|
1138
|
+
if (!content) return null;
|
|
1139
|
+
return /* @__PURE__ */ jsx4("span", { className: "sg-table-th-tooltip", title: typeof content === "string" ? content : void 0, children: "\u24D8" });
|
|
1140
|
+
}
|
|
1141
|
+
function TableHeader(props) {
|
|
1142
|
+
const {
|
|
1143
|
+
columns,
|
|
1144
|
+
headerRows,
|
|
1145
|
+
hasColumnGroups,
|
|
1146
|
+
rowSelection,
|
|
1147
|
+
expandable,
|
|
1148
|
+
draggable,
|
|
1149
|
+
allSelected,
|
|
1150
|
+
someSelected,
|
|
1151
|
+
dragOver,
|
|
1152
|
+
t,
|
|
1153
|
+
fixedStyle,
|
|
1154
|
+
onSort,
|
|
1155
|
+
onSelectAll,
|
|
1156
|
+
onDragStart,
|
|
1157
|
+
onDragOver,
|
|
1158
|
+
onDragLeave,
|
|
1159
|
+
onDrop,
|
|
1160
|
+
onDragEnd,
|
|
1161
|
+
onResizeStart,
|
|
1162
|
+
filterState,
|
|
1163
|
+
filterActions,
|
|
1164
|
+
filterRef,
|
|
1165
|
+
sorts,
|
|
1166
|
+
getSortIndex,
|
|
1167
|
+
getSortDirection,
|
|
1168
|
+
headerContextMenu,
|
|
1169
|
+
onContextMenu,
|
|
1170
|
+
showRowNumber,
|
|
1171
|
+
rowDraggable,
|
|
1172
|
+
columnPinning,
|
|
1173
|
+
onPinColumn,
|
|
1174
|
+
onAutoResize,
|
|
1175
|
+
slotClassNames,
|
|
1176
|
+
slotStyles
|
|
1177
|
+
} = props;
|
|
1178
|
+
const sCls = slotClassNames ?? {};
|
|
1179
|
+
const sSty = slotStyles ?? {};
|
|
1180
|
+
const filterProps = (col) => ({
|
|
1181
|
+
col,
|
|
1182
|
+
t,
|
|
1183
|
+
state: filterState,
|
|
1184
|
+
actions: filterActions,
|
|
1185
|
+
filterRef
|
|
1186
|
+
});
|
|
1187
|
+
const sortProps = {
|
|
1188
|
+
sorts,
|
|
1189
|
+
getSortIndex,
|
|
1190
|
+
getSortDirection,
|
|
1191
|
+
t
|
|
1192
|
+
};
|
|
1193
|
+
const buildContextMenu = (col, e) => {
|
|
1194
|
+
e.preventDefault();
|
|
1195
|
+
const items = [];
|
|
1196
|
+
if (headerContextMenu) {
|
|
1197
|
+
items.push(...headerContextMenu(col));
|
|
1198
|
+
}
|
|
1199
|
+
if (columnPinning && onPinColumn) {
|
|
1200
|
+
if (items.length > 0) {
|
|
1201
|
+
items.push({ key: "pin-divider", label: "", divider: true });
|
|
1202
|
+
}
|
|
1203
|
+
if (col.fixed !== "left") {
|
|
1204
|
+
items.push({
|
|
1205
|
+
key: "pin-left",
|
|
1206
|
+
label: t.pinLeft,
|
|
1207
|
+
onClick: () => onPinColumn(col.key, "left")
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
if (col.fixed !== "right") {
|
|
1211
|
+
items.push({
|
|
1212
|
+
key: "pin-right",
|
|
1213
|
+
label: t.pinRight,
|
|
1214
|
+
onClick: () => onPinColumn(col.key, "right")
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
if (col.fixed) {
|
|
1218
|
+
items.push({
|
|
1219
|
+
key: "unpin",
|
|
1220
|
+
label: t.unpin,
|
|
1221
|
+
onClick: () => onPinColumn(col.key, void 0)
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
if (items.length > 0) {
|
|
1226
|
+
onContextMenu({ x: e.clientX, y: e.clientY, items });
|
|
1227
|
+
}
|
|
1228
|
+
};
|
|
1229
|
+
if (hasColumnGroups && headerRows) {
|
|
1230
|
+
return /* @__PURE__ */ jsx4(Fragment, { children: headerRows.map((row, ri) => /* @__PURE__ */ jsxs4(
|
|
1231
|
+
"div",
|
|
1232
|
+
{
|
|
1233
|
+
className: ["sg-table-header-row", sCls.headerRow].filter(Boolean).join(" "),
|
|
1234
|
+
role: "row",
|
|
1235
|
+
style: { display: "contents", ...sSty.headerRow },
|
|
1236
|
+
children: [
|
|
1237
|
+
ri === 0 && rowDraggable && /* @__PURE__ */ jsx4(
|
|
1238
|
+
"div",
|
|
1239
|
+
{
|
|
1240
|
+
className: "sg-table-th",
|
|
1241
|
+
role: "columnheader",
|
|
1242
|
+
style: { gridRow: `span ${headerRows.length}` }
|
|
1243
|
+
}
|
|
1244
|
+
),
|
|
1245
|
+
ri === 0 && showRowNumber && /* @__PURE__ */ jsx4(
|
|
1246
|
+
"div",
|
|
1247
|
+
{
|
|
1248
|
+
className: "sg-table-th sg-table-cell-row-number",
|
|
1249
|
+
role: "columnheader",
|
|
1250
|
+
style: { gridRow: `span ${headerRows.length}` },
|
|
1251
|
+
children: t.rowNumber
|
|
1252
|
+
}
|
|
1253
|
+
),
|
|
1254
|
+
ri === 0 && rowSelection && /* @__PURE__ */ jsx4(
|
|
1255
|
+
"div",
|
|
1256
|
+
{
|
|
1257
|
+
className: "sg-table-th sg-table-cell-selection",
|
|
1258
|
+
role: "columnheader",
|
|
1259
|
+
style: { gridRow: `span ${headerRows.length}` },
|
|
1260
|
+
children: rowSelection.type !== "radio" && /* @__PURE__ */ jsx4(
|
|
1261
|
+
Checkbox,
|
|
1262
|
+
{
|
|
1263
|
+
checked: allSelected,
|
|
1264
|
+
indeterminate: someSelected,
|
|
1265
|
+
onChange: onSelectAll
|
|
1266
|
+
}
|
|
1267
|
+
)
|
|
1268
|
+
}
|
|
1269
|
+
),
|
|
1270
|
+
ri === 0 && expandable && /* @__PURE__ */ jsx4(
|
|
1271
|
+
"div",
|
|
1272
|
+
{
|
|
1273
|
+
className: "sg-table-th sg-table-cell-expand",
|
|
1274
|
+
role: "columnheader",
|
|
1275
|
+
style: { gridRow: `span ${headerRows.length}` }
|
|
1276
|
+
}
|
|
1277
|
+
),
|
|
1278
|
+
row.map((cell, ci) => {
|
|
1279
|
+
const isLeaf = !cell.col.children || cell.col.children.length === 0;
|
|
1280
|
+
return /* @__PURE__ */ jsxs4(
|
|
1281
|
+
"div",
|
|
1282
|
+
{
|
|
1283
|
+
className: [
|
|
1284
|
+
"sg-table-th",
|
|
1285
|
+
isLeaf && cell.col.sortable ? "sg-table-th-sortable" : "",
|
|
1286
|
+
cell.col.fixed ? "sg-table-cell-fixed" : "",
|
|
1287
|
+
cell.col.fixed ? `sg-table-cell-fixed-${cell.col.fixed}` : "",
|
|
1288
|
+
cell.colSpan > 1 ? "sg-table-th-group" : "",
|
|
1289
|
+
sCls.headerCell,
|
|
1290
|
+
cell.col.headerClassName
|
|
1291
|
+
].filter(Boolean).join(" "),
|
|
1292
|
+
style: {
|
|
1293
|
+
...isLeaf ? fixedStyle(cell.col, true) : {},
|
|
1294
|
+
gridColumn: cell.colSpan > 1 ? `span ${cell.colSpan}` : void 0,
|
|
1295
|
+
gridRow: cell.rowSpan > 1 ? `span ${cell.rowSpan}` : void 0,
|
|
1296
|
+
justifyContent: cell.colSpan > 1 ? "center" : void 0,
|
|
1297
|
+
...sSty.headerCell
|
|
1298
|
+
},
|
|
1299
|
+
role: "columnheader",
|
|
1300
|
+
onClick: isLeaf ? (e) => onSort(cell.col, e.shiftKey) : void 0,
|
|
1301
|
+
onContextMenu: isLeaf ? (e) => buildContextMenu(cell.col, e) : void 0,
|
|
1302
|
+
children: [
|
|
1303
|
+
/* @__PURE__ */ jsxs4(
|
|
1304
|
+
"span",
|
|
1305
|
+
{
|
|
1306
|
+
className: ["sg-table-th-content", sCls.headerCellContent].filter(Boolean).join(" "),
|
|
1307
|
+
style: sSty.headerCellContent,
|
|
1308
|
+
children: [
|
|
1309
|
+
/* @__PURE__ */ jsx4("span", { className: "sg-table-th-title", children: cell.col.title }),
|
|
1310
|
+
isLeaf && cell.col.tooltip && /* @__PURE__ */ jsx4(ColumnTooltip, { content: cell.col.tooltip }),
|
|
1311
|
+
isLeaf && /* @__PURE__ */ jsx4(SortIndicator, { col: cell.col, ...sortProps })
|
|
1312
|
+
]
|
|
1313
|
+
}
|
|
1314
|
+
),
|
|
1315
|
+
isLeaf && /* @__PURE__ */ jsx4(FilterTrigger, { ...filterProps(cell.col) }),
|
|
1316
|
+
isLeaf && /* @__PURE__ */ jsx4(FilterDropdownContent, { ...filterProps(cell.col) }),
|
|
1317
|
+
isLeaf && cell.col.resizable && /* @__PURE__ */ jsx4(
|
|
1318
|
+
"div",
|
|
1319
|
+
{
|
|
1320
|
+
className: "sg-table-resize-handle",
|
|
1321
|
+
onMouseDown: (e) => onResizeStart(e, cell.col.key),
|
|
1322
|
+
onDoubleClick: onAutoResize ? (e) => {
|
|
1323
|
+
e.stopPropagation();
|
|
1324
|
+
onAutoResize(cell.col.key);
|
|
1325
|
+
} : void 0
|
|
1326
|
+
}
|
|
1327
|
+
)
|
|
1328
|
+
]
|
|
1329
|
+
},
|
|
1330
|
+
cell.col.key ?? `g-${ri}-${ci}`
|
|
1331
|
+
);
|
|
1332
|
+
})
|
|
1333
|
+
]
|
|
1334
|
+
},
|
|
1335
|
+
`hdr-${ri}`
|
|
1336
|
+
)) });
|
|
1337
|
+
}
|
|
1338
|
+
return /* @__PURE__ */ jsxs4(
|
|
1339
|
+
"div",
|
|
1340
|
+
{
|
|
1341
|
+
className: ["sg-table-header-row", sCls.headerRow].filter(Boolean).join(" "),
|
|
1342
|
+
role: "row",
|
|
1343
|
+
style: { display: "contents", ...sSty.headerRow },
|
|
1344
|
+
children: [
|
|
1345
|
+
rowDraggable && /* @__PURE__ */ jsx4("div", { className: "sg-table-th", role: "columnheader" }),
|
|
1346
|
+
showRowNumber && /* @__PURE__ */ jsx4("div", { className: "sg-table-th sg-table-cell-row-number", role: "columnheader", children: t.rowNumber }),
|
|
1347
|
+
rowSelection && /* @__PURE__ */ jsx4("div", { className: "sg-table-th sg-table-cell-selection", role: "columnheader", children: rowSelection.type !== "radio" && /* @__PURE__ */ jsx4(Checkbox, { checked: allSelected, indeterminate: someSelected, onChange: onSelectAll }) }),
|
|
1348
|
+
expandable && /* @__PURE__ */ jsx4("div", { className: "sg-table-th sg-table-cell-expand", role: "columnheader" }),
|
|
1349
|
+
columns.map((col) => /* @__PURE__ */ jsxs4(
|
|
1350
|
+
"div",
|
|
1351
|
+
{
|
|
1352
|
+
className: [
|
|
1353
|
+
"sg-table-th",
|
|
1354
|
+
col.sortable ? "sg-table-th-sortable" : "",
|
|
1355
|
+
dragOver === col.key ? "sg-table-th-drag-over" : "",
|
|
1356
|
+
col.fixed ? "sg-table-cell-fixed" : "",
|
|
1357
|
+
col.fixed ? `sg-table-cell-fixed-${col.fixed}` : "",
|
|
1358
|
+
sCls.headerCell,
|
|
1359
|
+
col.headerClassName
|
|
1360
|
+
].filter(Boolean).join(" "),
|
|
1361
|
+
style: { ...fixedStyle(col, true), ...sSty.headerCell },
|
|
1362
|
+
role: "columnheader",
|
|
1363
|
+
onClick: (e) => onSort(col, e.shiftKey),
|
|
1364
|
+
onContextMenu: (e) => buildContextMenu(col, e),
|
|
1365
|
+
draggable: draggable && !col.fixed,
|
|
1366
|
+
onDragStart: draggable ? (e) => onDragStart(e, col.key) : void 0,
|
|
1367
|
+
onDragOver: draggable ? (e) => onDragOver(e, col.key) : void 0,
|
|
1368
|
+
onDragLeave: draggable ? () => onDragLeave() : void 0,
|
|
1369
|
+
onDrop: draggable ? (e) => onDrop(e, col.key) : void 0,
|
|
1370
|
+
onDragEnd: draggable ? () => onDragEnd() : void 0,
|
|
1371
|
+
children: [
|
|
1372
|
+
/* @__PURE__ */ jsxs4(
|
|
1373
|
+
"span",
|
|
1374
|
+
{
|
|
1375
|
+
className: ["sg-table-th-content", sCls.headerCellContent].filter(Boolean).join(" "),
|
|
1376
|
+
style: sSty.headerCellContent,
|
|
1377
|
+
children: [
|
|
1378
|
+
/* @__PURE__ */ jsx4("span", { className: "sg-table-th-title", children: col.title }),
|
|
1379
|
+
col.tooltip && /* @__PURE__ */ jsx4(ColumnTooltip, { content: col.tooltip }),
|
|
1380
|
+
/* @__PURE__ */ jsx4(SortIndicator, { col, ...sortProps })
|
|
1381
|
+
]
|
|
1382
|
+
}
|
|
1383
|
+
),
|
|
1384
|
+
/* @__PURE__ */ jsx4(FilterTrigger, { ...filterProps(col) }),
|
|
1385
|
+
/* @__PURE__ */ jsx4(FilterDropdownContent, { ...filterProps(col) }),
|
|
1386
|
+
col.resizable && /* @__PURE__ */ jsx4(
|
|
1387
|
+
"div",
|
|
1388
|
+
{
|
|
1389
|
+
className: "sg-table-resize-handle",
|
|
1390
|
+
onMouseDown: (e) => onResizeStart(e, col.key),
|
|
1391
|
+
onDoubleClick: onAutoResize ? (e) => {
|
|
1392
|
+
e.stopPropagation();
|
|
1393
|
+
onAutoResize(col.key);
|
|
1394
|
+
} : void 0
|
|
1395
|
+
}
|
|
1396
|
+
)
|
|
1397
|
+
]
|
|
1398
|
+
},
|
|
1399
|
+
col.key
|
|
1400
|
+
))
|
|
1401
|
+
]
|
|
1402
|
+
}
|
|
1403
|
+
);
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
// src/components/complex/Table/TableBody.tsx
|
|
1407
|
+
import React2, { useRef as useRef3, useState as useState4, useEffect as useEffect3, useCallback as useCallback2 } from "react";
|
|
1408
|
+
|
|
1409
|
+
// src/components/complex/Table/TableGroupRow.tsx
|
|
1410
|
+
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1411
|
+
function TableGroupRow({ group, groupBy, totalCols, t, onToggle }) {
|
|
1412
|
+
return /* @__PURE__ */ jsx5(
|
|
1413
|
+
"div",
|
|
1414
|
+
{
|
|
1415
|
+
className: "sg-table-group-row",
|
|
1416
|
+
role: "row",
|
|
1417
|
+
style: { display: "contents" },
|
|
1418
|
+
children: /* @__PURE__ */ jsxs5(
|
|
1419
|
+
"div",
|
|
1420
|
+
{
|
|
1421
|
+
className: "sg-table-td sg-table-group-cell",
|
|
1422
|
+
role: "cell",
|
|
1423
|
+
style: { gridColumn: `1 / ${totalCols + 1}` },
|
|
1424
|
+
onClick: () => onToggle(group.groupKey),
|
|
1425
|
+
children: [
|
|
1426
|
+
/* @__PURE__ */ jsx5(
|
|
1427
|
+
"button",
|
|
1428
|
+
{
|
|
1429
|
+
type: "button",
|
|
1430
|
+
className: `sg-table-expand-btn${group.expanded ? " sg-table-expand-open" : ""}`,
|
|
1431
|
+
"aria-label": group.expanded ? t.groupCollapse : t.groupExpand,
|
|
1432
|
+
"aria-expanded": group.expanded,
|
|
1433
|
+
onClick: (e) => {
|
|
1434
|
+
e.stopPropagation();
|
|
1435
|
+
onToggle(group.groupKey);
|
|
1436
|
+
},
|
|
1437
|
+
children: t.expandIcon
|
|
1438
|
+
}
|
|
1439
|
+
),
|
|
1440
|
+
/* @__PURE__ */ jsxs5("span", { className: "sg-table-group-title", children: [
|
|
1441
|
+
groupBy ? `${groupBy}: ` : null,
|
|
1442
|
+
/* @__PURE__ */ jsx5("strong", { children: String(group.groupValue) })
|
|
1443
|
+
] }),
|
|
1444
|
+
/* @__PURE__ */ jsxs5("span", { className: "sg-table-group-count", children: [
|
|
1445
|
+
"(",
|
|
1446
|
+
group.count,
|
|
1447
|
+
")"
|
|
1448
|
+
] }),
|
|
1449
|
+
Object.keys(group.aggregates).length > 0 && /* @__PURE__ */ jsx5("span", { className: "sg-table-group-aggregates", children: Object.entries(group.aggregates).map(([key, val]) => /* @__PURE__ */ jsxs5("span", { className: "sg-table-group-agg-item", children: [
|
|
1450
|
+
key,
|
|
1451
|
+
": ",
|
|
1452
|
+
String(val)
|
|
1453
|
+
] }, key)) })
|
|
1454
|
+
]
|
|
1455
|
+
}
|
|
1456
|
+
)
|
|
1457
|
+
}
|
|
1458
|
+
);
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
// src/components/complex/Table/TableBody.tsx
|
|
1462
|
+
import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1463
|
+
function TableBody(props) {
|
|
1464
|
+
const {
|
|
1465
|
+
columns,
|
|
1466
|
+
flatRows,
|
|
1467
|
+
rowSelection,
|
|
1468
|
+
expandable,
|
|
1469
|
+
isTreeMode,
|
|
1470
|
+
indentSize,
|
|
1471
|
+
treeExpanded,
|
|
1472
|
+
expandedKeys,
|
|
1473
|
+
totalCols,
|
|
1474
|
+
spanMap,
|
|
1475
|
+
hiddenCells,
|
|
1476
|
+
t,
|
|
1477
|
+
rowClassName,
|
|
1478
|
+
fixedStyle,
|
|
1479
|
+
onRowClick,
|
|
1480
|
+
onCellEdit,
|
|
1481
|
+
onSelectRow,
|
|
1482
|
+
onToggleExpand,
|
|
1483
|
+
onToggleTreeExpand,
|
|
1484
|
+
rowDraggable,
|
|
1485
|
+
onRowOrderChange,
|
|
1486
|
+
cellContextMenu,
|
|
1487
|
+
onContextMenu,
|
|
1488
|
+
striped,
|
|
1489
|
+
showRowNumber,
|
|
1490
|
+
groupBy,
|
|
1491
|
+
onToggleGroup,
|
|
1492
|
+
focusedCell,
|
|
1493
|
+
onFocusCell,
|
|
1494
|
+
keyboardNavigation,
|
|
1495
|
+
emptyContent,
|
|
1496
|
+
slotClassNames,
|
|
1497
|
+
slotStyles,
|
|
1498
|
+
isPinnedSection,
|
|
1499
|
+
rowIndexOffset
|
|
1500
|
+
} = props;
|
|
1501
|
+
const sCls = slotClassNames ?? {};
|
|
1502
|
+
const sSty = slotStyles ?? {};
|
|
1503
|
+
const [editingCell, setEditingCell] = useState4(null);
|
|
1504
|
+
const [editValue, setEditValue] = useState4("");
|
|
1505
|
+
const editRef = useRef3(null);
|
|
1506
|
+
const [dragRowIdx, setDragRowIdx] = useState4(null);
|
|
1507
|
+
const [dragOverRowIdx, setDragOverRowIdx] = useState4(null);
|
|
1508
|
+
const [copiedCell, setCopiedCell] = useState4(null);
|
|
1509
|
+
useEffect3(() => {
|
|
1510
|
+
if (editingCell && editRef.current) editRef.current.focus();
|
|
1511
|
+
}, [editingCell]);
|
|
1512
|
+
const handleEditStart = (rowId, col, val) => {
|
|
1513
|
+
setEditingCell({ rowId, col });
|
|
1514
|
+
setEditValue(String(val ?? ""));
|
|
1515
|
+
};
|
|
1516
|
+
const handleEditSave = () => {
|
|
1517
|
+
if (editingCell && onCellEdit) {
|
|
1518
|
+
onCellEdit(editingCell.rowId, editingCell.col, editValue);
|
|
1519
|
+
}
|
|
1520
|
+
setEditingCell(null);
|
|
1521
|
+
};
|
|
1522
|
+
const handleEditCancel = () => setEditingCell(null);
|
|
1523
|
+
const handleRowDragStart = (e, idx) => {
|
|
1524
|
+
setDragRowIdx(idx);
|
|
1525
|
+
e.dataTransfer.effectAllowed = "move";
|
|
1526
|
+
e.dataTransfer.setData("text/plain", String(idx));
|
|
1527
|
+
};
|
|
1528
|
+
const handleRowDragOver = (e, idx) => {
|
|
1529
|
+
e.preventDefault();
|
|
1530
|
+
e.dataTransfer.dropEffect = "move";
|
|
1531
|
+
setDragOverRowIdx(idx);
|
|
1532
|
+
};
|
|
1533
|
+
const handleRowDrop = (_e, toIdx) => {
|
|
1534
|
+
if (dragRowIdx !== null && dragRowIdx !== toIdx) {
|
|
1535
|
+
onRowOrderChange?.(dragRowIdx, toIdx);
|
|
1536
|
+
}
|
|
1537
|
+
setDragRowIdx(null);
|
|
1538
|
+
setDragOverRowIdx(null);
|
|
1539
|
+
};
|
|
1540
|
+
const handleRowDragEnd = () => {
|
|
1541
|
+
setDragRowIdx(null);
|
|
1542
|
+
setDragOverRowIdx(null);
|
|
1543
|
+
};
|
|
1544
|
+
const handleCellContext = (e, id, colKey, data) => {
|
|
1545
|
+
if (!cellContextMenu) return;
|
|
1546
|
+
e.preventDefault();
|
|
1547
|
+
const items = cellContextMenu(id, colKey, data);
|
|
1548
|
+
if (items.length > 0) {
|
|
1549
|
+
onContextMenu({ x: e.clientX, y: e.clientY, items });
|
|
1550
|
+
}
|
|
1551
|
+
};
|
|
1552
|
+
const handleCellCopy = useCallback2(
|
|
1553
|
+
async (rowId, colKey, value) => {
|
|
1554
|
+
await copyToClipboard(String(value ?? ""));
|
|
1555
|
+
setCopiedCell(`${rowId}:${colKey}`);
|
|
1556
|
+
setTimeout(() => setCopiedCell(null), 1500);
|
|
1557
|
+
},
|
|
1558
|
+
[]
|
|
1559
|
+
);
|
|
1560
|
+
if (flatRows.length === 0) {
|
|
1561
|
+
return /* @__PURE__ */ jsx6(
|
|
1562
|
+
"div",
|
|
1563
|
+
{
|
|
1564
|
+
className: ["sg-table-empty", sCls.empty].filter(Boolean).join(" "),
|
|
1565
|
+
style: { gridColumn: `1 / ${totalCols + 1}`, ...sSty.empty },
|
|
1566
|
+
role: "row",
|
|
1567
|
+
children: /* @__PURE__ */ jsx6("span", { role: "cell", children: emptyContent ?? t.emptyText })
|
|
1568
|
+
}
|
|
1569
|
+
);
|
|
1570
|
+
}
|
|
1571
|
+
let dataRowIndex = 0;
|
|
1572
|
+
return /* @__PURE__ */ jsx6(Fragment2, { children: flatRows.map((row, rowIdx) => {
|
|
1573
|
+
if (row.__groupRow) {
|
|
1574
|
+
return /* @__PURE__ */ jsx6(
|
|
1575
|
+
TableGroupRow,
|
|
1576
|
+
{
|
|
1577
|
+
group: row.__groupRow,
|
|
1578
|
+
groupBy,
|
|
1579
|
+
totalCols,
|
|
1580
|
+
t,
|
|
1581
|
+
onToggle: onToggleGroup ?? (() => {
|
|
1582
|
+
})
|
|
1583
|
+
},
|
|
1584
|
+
row.id
|
|
1585
|
+
);
|
|
1586
|
+
}
|
|
1587
|
+
const currentDataIdx = dataRowIndex++;
|
|
1588
|
+
const isExpanded = expandedKeys.has(row.id);
|
|
1589
|
+
const isSelected = rowSelection?.selectedKeys.includes(row.id);
|
|
1590
|
+
const canExpand = expandable?.rowExpandable ? expandable.rowExpandable(row.data) : !!expandable;
|
|
1591
|
+
const rowCls = typeof rowClassName === "function" ? rowClassName(row.data, row.id) : rowClassName ?? "";
|
|
1592
|
+
const isZebra = striped && currentDataIdx % 2 === 1;
|
|
1593
|
+
const isDragOver = dragOverRowIdx === rowIdx && dragRowIdx !== rowIdx;
|
|
1594
|
+
const isPinned = isPinnedSection;
|
|
1595
|
+
const virtualIndexAttr = rowIndexOffset !== void 0 ? rowIndexOffset + rowIdx : void 0;
|
|
1596
|
+
return /* @__PURE__ */ jsxs6(React2.Fragment, { children: [
|
|
1597
|
+
/* @__PURE__ */ jsxs6(
|
|
1598
|
+
"div",
|
|
1599
|
+
{
|
|
1600
|
+
className: [
|
|
1601
|
+
"sg-table-row",
|
|
1602
|
+
isSelected ? "sg-table-row-selected" : "",
|
|
1603
|
+
onRowClick ? "sg-table-row-clickable" : "",
|
|
1604
|
+
isZebra ? "sg-table-row-striped" : "",
|
|
1605
|
+
isDragOver ? "sg-table-row-drag-over" : "",
|
|
1606
|
+
isPinned ? "sg-table-row-pinned" : "",
|
|
1607
|
+
sCls.row,
|
|
1608
|
+
rowCls
|
|
1609
|
+
].filter(Boolean).join(" "),
|
|
1610
|
+
role: "row",
|
|
1611
|
+
style: { display: "contents", ...sSty.row },
|
|
1612
|
+
"data-sg-virtual-row-index": virtualIndexAttr,
|
|
1613
|
+
draggable: rowDraggable,
|
|
1614
|
+
onDragStart: rowDraggable ? (e) => handleRowDragStart(e, rowIdx) : void 0,
|
|
1615
|
+
onDragOver: rowDraggable ? (e) => handleRowDragOver(e, rowIdx) : void 0,
|
|
1616
|
+
onDrop: rowDraggable ? (e) => handleRowDrop(e, rowIdx) : void 0,
|
|
1617
|
+
onDragEnd: rowDraggable ? handleRowDragEnd : void 0,
|
|
1618
|
+
children: [
|
|
1619
|
+
rowDraggable && /* @__PURE__ */ jsx6(
|
|
1620
|
+
"div",
|
|
1621
|
+
{
|
|
1622
|
+
className: "sg-table-td sg-table-cell-drag-handle",
|
|
1623
|
+
role: "cell",
|
|
1624
|
+
style: { cursor: "grab", userSelect: "none", display: "flex", alignItems: "center", justifyContent: "center" },
|
|
1625
|
+
children: "\u283F"
|
|
1626
|
+
}
|
|
1627
|
+
),
|
|
1628
|
+
showRowNumber && /* @__PURE__ */ jsx6("div", { className: "sg-table-td sg-table-cell-row-number", role: "cell", children: currentDataIdx + 1 }),
|
|
1629
|
+
rowSelection && /* @__PURE__ */ jsx6(
|
|
1630
|
+
"div",
|
|
1631
|
+
{
|
|
1632
|
+
className: "sg-table-td sg-table-cell-selection",
|
|
1633
|
+
role: "cell",
|
|
1634
|
+
onClick: (e) => {
|
|
1635
|
+
e.stopPropagation();
|
|
1636
|
+
onSelectRow(row.id, row.data);
|
|
1637
|
+
},
|
|
1638
|
+
children: rowSelection.type === "radio" ? /* @__PURE__ */ jsx6("input", { type: "radio", checked: !!isSelected, readOnly: true }) : /* @__PURE__ */ jsx6(Checkbox, { checked: !!isSelected, onChange: () => {
|
|
1639
|
+
} })
|
|
1640
|
+
}
|
|
1641
|
+
),
|
|
1642
|
+
expandable && /* @__PURE__ */ jsx6("div", { className: "sg-table-td sg-table-cell-expand", role: "cell", children: canExpand && /* @__PURE__ */ jsx6(
|
|
1643
|
+
"button",
|
|
1644
|
+
{
|
|
1645
|
+
className: `sg-table-expand-btn${isExpanded ? " sg-table-expand-open" : ""}`,
|
|
1646
|
+
onClick: (e) => {
|
|
1647
|
+
e.stopPropagation();
|
|
1648
|
+
onToggleExpand(row.id);
|
|
1649
|
+
},
|
|
1650
|
+
children: t.expandIcon
|
|
1651
|
+
}
|
|
1652
|
+
) }),
|
|
1653
|
+
columns.map((col, colIndex) => {
|
|
1654
|
+
const cellKey = `${row.id}:${col.key}`;
|
|
1655
|
+
if (hiddenCells.has(cellKey)) return null;
|
|
1656
|
+
const span = spanMap.get(cellKey);
|
|
1657
|
+
const val = row.data[col.key];
|
|
1658
|
+
const isEditing = editingCell?.rowId === row.id && editingCell?.col === col.key;
|
|
1659
|
+
const isFocused = keyboardNavigation && focusedCell?.row === rowIdx && focusedCell?.col === colIndex;
|
|
1660
|
+
const isCopied = copiedCell === cellKey;
|
|
1661
|
+
const cellStyle = { ...fixedStyle(col) };
|
|
1662
|
+
if (span?.colSpan && span.colSpan > 1)
|
|
1663
|
+
cellStyle.gridColumn = `span ${span.colSpan}`;
|
|
1664
|
+
if (span?.rowSpan && span.rowSpan > 1)
|
|
1665
|
+
cellStyle.gridRow = `span ${span.rowSpan}`;
|
|
1666
|
+
const isFirstCol = colIndex === 0;
|
|
1667
|
+
const treeIndent = isTreeMode && isFirstCol ? row.depth * indentSize : 0;
|
|
1668
|
+
const cellClsExtra = typeof col.cellClassName === "function" ? col.cellClassName(val, row.data, row.id) : col.cellClassName ?? "";
|
|
1669
|
+
return /* @__PURE__ */ jsxs6(
|
|
1670
|
+
"div",
|
|
1671
|
+
{
|
|
1672
|
+
className: [
|
|
1673
|
+
"sg-table-td",
|
|
1674
|
+
col.fixed ? "sg-table-cell-fixed" : "",
|
|
1675
|
+
col.fixed ? `sg-table-cell-fixed-${col.fixed}` : "",
|
|
1676
|
+
col.editable ? "sg-table-td-editable" : "",
|
|
1677
|
+
isFocused ? "sg-table-cell-focused" : "",
|
|
1678
|
+
isCopied ? "sg-table-cell-copied" : "",
|
|
1679
|
+
col.copyable ? "sg-table-cell-copyable" : "",
|
|
1680
|
+
sCls.bodyCell,
|
|
1681
|
+
cellClsExtra
|
|
1682
|
+
].filter(Boolean).join(" "),
|
|
1683
|
+
style: { ...cellStyle, ...sSty.bodyCell },
|
|
1684
|
+
role: "cell",
|
|
1685
|
+
tabIndex: keyboardNavigation ? -1 : void 0,
|
|
1686
|
+
onClick: () => {
|
|
1687
|
+
onRowClick?.(row.id, row.data);
|
|
1688
|
+
if (keyboardNavigation) {
|
|
1689
|
+
onFocusCell?.({ row: rowIdx, col: colIndex });
|
|
1690
|
+
}
|
|
1691
|
+
},
|
|
1692
|
+
onContextMenu: (e) => handleCellContext(e, row.id, col.key, row.data),
|
|
1693
|
+
onDoubleClick: col.editable && onCellEdit ? (e) => {
|
|
1694
|
+
e.stopPropagation();
|
|
1695
|
+
handleEditStart(row.id, col.key, val);
|
|
1696
|
+
} : void 0,
|
|
1697
|
+
children: [
|
|
1698
|
+
isTreeMode && isFirstCol && /* @__PURE__ */ jsxs6(
|
|
1699
|
+
"span",
|
|
1700
|
+
{
|
|
1701
|
+
style: {
|
|
1702
|
+
display: "inline-flex",
|
|
1703
|
+
alignItems: "center",
|
|
1704
|
+
minWidth: treeIndent + 20,
|
|
1705
|
+
flexShrink: 0
|
|
1706
|
+
},
|
|
1707
|
+
children: [
|
|
1708
|
+
/* @__PURE__ */ jsx6("span", { style: { width: treeIndent } }),
|
|
1709
|
+
row.hasChildren ? /* @__PURE__ */ jsx6(
|
|
1710
|
+
"button",
|
|
1711
|
+
{
|
|
1712
|
+
className: `sg-table-expand-btn${treeExpanded.has(row.id) ? " sg-table-expand-open" : ""}`,
|
|
1713
|
+
onClick: (e) => {
|
|
1714
|
+
e.stopPropagation();
|
|
1715
|
+
onToggleTreeExpand(row.id);
|
|
1716
|
+
},
|
|
1717
|
+
children: t.expandIcon
|
|
1718
|
+
}
|
|
1719
|
+
) : /* @__PURE__ */ jsx6("span", { style: { width: 20 } })
|
|
1720
|
+
]
|
|
1721
|
+
}
|
|
1722
|
+
),
|
|
1723
|
+
/* @__PURE__ */ jsx6("span", { className: "sg-table-cell-content", children: isEditing ? /* @__PURE__ */ jsx6(
|
|
1724
|
+
"input",
|
|
1725
|
+
{
|
|
1726
|
+
ref: editRef,
|
|
1727
|
+
className: "sg-table-edit-input",
|
|
1728
|
+
value: editValue,
|
|
1729
|
+
onChange: (e) => setEditValue(e.target.value),
|
|
1730
|
+
onBlur: handleEditSave,
|
|
1731
|
+
onKeyDown: (e) => {
|
|
1732
|
+
if (e.key === "Enter") handleEditSave();
|
|
1733
|
+
if (e.key === "Escape") handleEditCancel();
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
) : col.render ? col.render(val, row.data, row.id) : String(val ?? "") }),
|
|
1737
|
+
col.copyable && !isEditing && /* @__PURE__ */ jsx6(
|
|
1738
|
+
"button",
|
|
1739
|
+
{
|
|
1740
|
+
className: "sg-table-copy-btn",
|
|
1741
|
+
onClick: (e) => {
|
|
1742
|
+
e.stopPropagation();
|
|
1743
|
+
handleCellCopy(row.id, col.key, val);
|
|
1744
|
+
},
|
|
1745
|
+
title: "Copy",
|
|
1746
|
+
children: isCopied ? "\u2713" : "\u2398"
|
|
1747
|
+
}
|
|
1748
|
+
)
|
|
1749
|
+
]
|
|
1750
|
+
},
|
|
1751
|
+
col.key
|
|
1752
|
+
);
|
|
1753
|
+
})
|
|
1754
|
+
]
|
|
1755
|
+
}
|
|
1756
|
+
),
|
|
1757
|
+
expandable && isExpanded && /* @__PURE__ */ jsx6(
|
|
1758
|
+
"div",
|
|
1759
|
+
{
|
|
1760
|
+
className: "sg-table-expanded-row",
|
|
1761
|
+
style: { gridColumn: `1 / ${totalCols + 1}` },
|
|
1762
|
+
role: "row",
|
|
1763
|
+
children: /* @__PURE__ */ jsx6("div", { role: "cell", children: expandable.expandedRowRender(row.data, row.id) })
|
|
1764
|
+
}
|
|
1765
|
+
)
|
|
1766
|
+
] }, row.id);
|
|
1767
|
+
}) });
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
// src/components/complex/Table/VirtualTableBody.tsx
|
|
1771
|
+
import { useEffect as useEffect4, useLayoutEffect, useMemo as useMemo2, useReducer, useRef as useRef4, useState as useState5 } from "react";
|
|
1772
|
+
import { createVirtual } from "@skygraph/core";
|
|
1773
|
+
import { Fragment as Fragment3, jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1774
|
+
var DEFAULT_ROW_HEIGHT = 40;
|
|
1775
|
+
function buildEstimate(rowHeight, estimate, flatRows) {
|
|
1776
|
+
if (typeof rowHeight === "number" && estimate == null) {
|
|
1777
|
+
return rowHeight;
|
|
1778
|
+
}
|
|
1779
|
+
const fallback = typeof rowHeight === "number" ? rowHeight : DEFAULT_ROW_HEIGHT;
|
|
1780
|
+
const fn = estimate ?? (typeof rowHeight === "function" ? rowHeight : void 0);
|
|
1781
|
+
if (!fn) return fallback;
|
|
1782
|
+
return (index) => {
|
|
1783
|
+
const row = flatRows[index];
|
|
1784
|
+
if (!row) return fallback;
|
|
1785
|
+
const v = fn(row.data, row.id);
|
|
1786
|
+
return Number.isFinite(v) && v >= 0 ? v : fallback;
|
|
1787
|
+
};
|
|
1788
|
+
}
|
|
1789
|
+
function VirtualTableBody(props) {
|
|
1790
|
+
const {
|
|
1791
|
+
rowHeight,
|
|
1792
|
+
estimateRowHeight,
|
|
1793
|
+
overscan,
|
|
1794
|
+
scrollContainerRef,
|
|
1795
|
+
flatRows,
|
|
1796
|
+
totalCols,
|
|
1797
|
+
...bodyProps
|
|
1798
|
+
} = props;
|
|
1799
|
+
const isDeclarative = typeof rowHeight === "function";
|
|
1800
|
+
const isDynamic = isDeclarative || estimateRowHeight != null;
|
|
1801
|
+
const virtual = useMemo2(
|
|
1802
|
+
() => createVirtual({
|
|
1803
|
+
itemCount: flatRows.length,
|
|
1804
|
+
itemHeight: buildEstimate(rowHeight, estimateRowHeight, flatRows),
|
|
1805
|
+
overscan
|
|
1806
|
+
}),
|
|
1807
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1808
|
+
[]
|
|
1809
|
+
);
|
|
1810
|
+
const [, forceUpdate] = useReducer((n) => n + 1, 0);
|
|
1811
|
+
useEffect4(() => virtual.subscribe(() => forceUpdate()), [virtual]);
|
|
1812
|
+
useEffect4(() => {
|
|
1813
|
+
virtual.setItemCount(flatRows.length);
|
|
1814
|
+
virtual.setItemHeight(buildEstimate(rowHeight, estimateRowHeight, flatRows));
|
|
1815
|
+
}, [virtual, flatRows, rowHeight, estimateRowHeight]);
|
|
1816
|
+
useEffect4(() => {
|
|
1817
|
+
if (!isDeclarative) return;
|
|
1818
|
+
const fn = rowHeight;
|
|
1819
|
+
for (let i = 0; i < flatRows.length; i++) {
|
|
1820
|
+
const row = flatRows[i];
|
|
1821
|
+
if (!row) continue;
|
|
1822
|
+
const h = fn(row.data, row.id);
|
|
1823
|
+
if (Number.isFinite(h) && h >= 0) {
|
|
1824
|
+
virtual.setMeasuredHeight(i, Math.round(h));
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
}, [virtual, flatRows, rowHeight, isDeclarative]);
|
|
1828
|
+
const [scrollTop, setScrollTop] = useState5(0);
|
|
1829
|
+
const [viewportHeight, setViewportHeight] = useState5(0);
|
|
1830
|
+
useEffect4(() => {
|
|
1831
|
+
const el = scrollContainerRef.current;
|
|
1832
|
+
if (!el) return;
|
|
1833
|
+
setViewportHeight(el.clientHeight);
|
|
1834
|
+
setScrollTop(el.scrollTop);
|
|
1835
|
+
const onScroll = () => {
|
|
1836
|
+
setScrollTop(el.scrollTop);
|
|
1837
|
+
};
|
|
1838
|
+
el.addEventListener("scroll", onScroll, { passive: true });
|
|
1839
|
+
let ro = null;
|
|
1840
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
1841
|
+
ro = new ResizeObserver(() => setViewportHeight(el.clientHeight));
|
|
1842
|
+
ro.observe(el);
|
|
1843
|
+
}
|
|
1844
|
+
return () => {
|
|
1845
|
+
el.removeEventListener("scroll", onScroll);
|
|
1846
|
+
ro?.disconnect();
|
|
1847
|
+
};
|
|
1848
|
+
}, [scrollContainerRef]);
|
|
1849
|
+
const range = virtual.getRange(scrollTop, viewportHeight || 400);
|
|
1850
|
+
const visibleRows = flatRows.slice(range.startIndex, range.endIndex + 1);
|
|
1851
|
+
const totalHeight = range.totalHeight;
|
|
1852
|
+
const topPad = range.offsetTop;
|
|
1853
|
+
const visibleSize = visibleRows.reduce(
|
|
1854
|
+
(sum, _row, idx) => sum + virtual.getItemSize(range.startIndex + idx),
|
|
1855
|
+
0
|
|
1856
|
+
);
|
|
1857
|
+
const bottomPad = Math.max(0, totalHeight - topPad - visibleSize);
|
|
1858
|
+
const normalizeHeight = (h) => Math.round(h);
|
|
1859
|
+
const roRef = useRef4(null);
|
|
1860
|
+
const observedCellsRef = useRef4(/* @__PURE__ */ new Set());
|
|
1861
|
+
useEffect4(() => {
|
|
1862
|
+
if (!isDynamic) return;
|
|
1863
|
+
if (isDeclarative) return;
|
|
1864
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
1865
|
+
const ro = new ResizeObserver((entries) => {
|
|
1866
|
+
for (const entry of entries) {
|
|
1867
|
+
const target = entry.target;
|
|
1868
|
+
const rowEl = target.closest("[data-sg-virtual-row-index]");
|
|
1869
|
+
if (!rowEl) continue;
|
|
1870
|
+
const idx = Number(rowEl.getAttribute("data-sg-virtual-row-index"));
|
|
1871
|
+
virtual.setMeasuredHeight(idx, normalizeHeight(entry.contentRect.height));
|
|
1872
|
+
}
|
|
1873
|
+
});
|
|
1874
|
+
roRef.current = ro;
|
|
1875
|
+
return () => {
|
|
1876
|
+
ro.disconnect();
|
|
1877
|
+
roRef.current = null;
|
|
1878
|
+
observedCellsRef.current.clear();
|
|
1879
|
+
};
|
|
1880
|
+
}, [isDynamic, isDeclarative, virtual]);
|
|
1881
|
+
useLayoutEffect(() => {
|
|
1882
|
+
if (!isDynamic) return;
|
|
1883
|
+
const grid = scrollContainerRef.current?.querySelector(".sg-table-grid");
|
|
1884
|
+
if (!grid) return;
|
|
1885
|
+
const rowEls = grid.querySelectorAll("[data-sg-virtual-row-index]");
|
|
1886
|
+
const ro = roRef.current;
|
|
1887
|
+
const currentCells = /* @__PURE__ */ new Set();
|
|
1888
|
+
rowEls.forEach((rowEl) => {
|
|
1889
|
+
const firstCell = rowEl.firstElementChild;
|
|
1890
|
+
if (!firstCell) return;
|
|
1891
|
+
const idx = Number(rowEl.getAttribute("data-sg-virtual-row-index"));
|
|
1892
|
+
currentCells.add(firstCell);
|
|
1893
|
+
if (isDeclarative) {
|
|
1894
|
+
const row = flatRows[idx];
|
|
1895
|
+
if (row) {
|
|
1896
|
+
const declared = rowHeight(row.data, row.id);
|
|
1897
|
+
if (Number.isFinite(declared) && declared >= 0) {
|
|
1898
|
+
virtual.setMeasuredHeight(idx, Math.round(declared));
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
} else if (!virtual.hasMeasured(idx)) {
|
|
1902
|
+
virtual.setMeasuredHeight(idx, normalizeHeight(firstCell.getBoundingClientRect().height));
|
|
1903
|
+
}
|
|
1904
|
+
if (isDeclarative || virtual.hasMeasured(idx)) {
|
|
1905
|
+
const h = virtual.getItemSize(idx);
|
|
1906
|
+
const px = `${h}px`;
|
|
1907
|
+
const children = rowEl.children;
|
|
1908
|
+
for (let c = 0; c < children.length; c++) {
|
|
1909
|
+
const cell = children[c];
|
|
1910
|
+
if (cell.style.height !== px) cell.style.height = px;
|
|
1911
|
+
if (cell.style.minHeight !== "0px") cell.style.minHeight = "0px";
|
|
1912
|
+
if (cell.style.overflow !== "hidden") cell.style.overflow = "hidden";
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
if (ro && !observedCellsRef.current.has(firstCell)) {
|
|
1916
|
+
ro.observe(firstCell);
|
|
1917
|
+
}
|
|
1918
|
+
});
|
|
1919
|
+
if (ro) {
|
|
1920
|
+
for (const cell of observedCellsRef.current) {
|
|
1921
|
+
if (!currentCells.has(cell)) ro.unobserve(cell);
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
observedCellsRef.current = currentCells;
|
|
1925
|
+
if (!isDeclarative && typeof ResizeObserver === "undefined") {
|
|
1926
|
+
rowEls.forEach((rowEl) => {
|
|
1927
|
+
const firstCell = rowEl.firstElementChild;
|
|
1928
|
+
if (!firstCell) return;
|
|
1929
|
+
const idx = Number(rowEl.getAttribute("data-sg-virtual-row-index"));
|
|
1930
|
+
virtual.setMeasuredHeight(idx, normalizeHeight(firstCell.getBoundingClientRect().height));
|
|
1931
|
+
});
|
|
1932
|
+
}
|
|
1933
|
+
}, [isDynamic, isDeclarative, virtual, scrollContainerRef, visibleRows, flatRows, rowHeight]);
|
|
1934
|
+
const spacerColumn = `1 / ${totalCols + 1}`;
|
|
1935
|
+
return /* @__PURE__ */ jsxs7(Fragment3, { children: [
|
|
1936
|
+
topPad > 0 && /* @__PURE__ */ jsx7("div", { style: { gridColumn: spacerColumn, height: topPad }, role: "presentation", "aria-hidden": true }),
|
|
1937
|
+
/* @__PURE__ */ jsx7(
|
|
1938
|
+
TableBody,
|
|
1939
|
+
{
|
|
1940
|
+
...bodyProps,
|
|
1941
|
+
flatRows: visibleRows,
|
|
1942
|
+
totalCols,
|
|
1943
|
+
rowIndexOffset: range.startIndex
|
|
1944
|
+
}
|
|
1945
|
+
),
|
|
1946
|
+
bottomPad > 0 && /* @__PURE__ */ jsx7(
|
|
1947
|
+
"div",
|
|
1948
|
+
{
|
|
1949
|
+
style: { gridColumn: spacerColumn, height: bottomPad },
|
|
1950
|
+
role: "presentation",
|
|
1951
|
+
"aria-hidden": true
|
|
1952
|
+
}
|
|
1953
|
+
)
|
|
1954
|
+
] });
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
// src/components/complex/Table/ContextMenu.tsx
|
|
1958
|
+
import { useEffect as useEffect5, useRef as useRef5, useState as useState6 } from "react";
|
|
1959
|
+
import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1960
|
+
function ContextMenu({ state, onClose }) {
|
|
1961
|
+
const ref = useRef5(null);
|
|
1962
|
+
const [subMenu, setSubMenu] = useState6(null);
|
|
1963
|
+
useEffect5(() => {
|
|
1964
|
+
if (!state) return;
|
|
1965
|
+
const handle = (e) => {
|
|
1966
|
+
if (ref.current && !ref.current.contains(e.target)) {
|
|
1967
|
+
onClose();
|
|
1968
|
+
}
|
|
1969
|
+
};
|
|
1970
|
+
const handleKey = (e) => {
|
|
1971
|
+
if (e.key === "Escape") onClose();
|
|
1972
|
+
};
|
|
1973
|
+
const handleScroll = () => onClose();
|
|
1974
|
+
document.addEventListener("mousedown", handle);
|
|
1975
|
+
document.addEventListener("keydown", handleKey);
|
|
1976
|
+
window.addEventListener("scroll", handleScroll, true);
|
|
1977
|
+
return () => {
|
|
1978
|
+
document.removeEventListener("mousedown", handle);
|
|
1979
|
+
document.removeEventListener("keydown", handleKey);
|
|
1980
|
+
window.removeEventListener("scroll", handleScroll, true);
|
|
1981
|
+
};
|
|
1982
|
+
}, [state, onClose]);
|
|
1983
|
+
if (!state) return null;
|
|
1984
|
+
const rootStyle = {
|
|
1985
|
+
position: "fixed",
|
|
1986
|
+
top: state.y,
|
|
1987
|
+
left: state.x
|
|
1988
|
+
};
|
|
1989
|
+
const submenuStyle = {
|
|
1990
|
+
position: "absolute",
|
|
1991
|
+
top: 0,
|
|
1992
|
+
left: "100%"
|
|
1993
|
+
};
|
|
1994
|
+
const itemClass = (item) => {
|
|
1995
|
+
const classes = ["sg-context-menu-item"];
|
|
1996
|
+
if (item.danger) classes.push("sg-context-menu-item--danger");
|
|
1997
|
+
if (item.disabled) classes.push("sg-context-menu-item--disabled");
|
|
1998
|
+
return classes.join(" ");
|
|
1999
|
+
};
|
|
2000
|
+
const renderItems = (items, isSubmenu = false) => /* @__PURE__ */ jsx8(
|
|
2001
|
+
"div",
|
|
2002
|
+
{
|
|
2003
|
+
ref: isSubmenu ? void 0 : ref,
|
|
2004
|
+
className: "sg-context-menu",
|
|
2005
|
+
style: isSubmenu ? submenuStyle : rootStyle,
|
|
2006
|
+
role: "menu",
|
|
2007
|
+
children: items.map((item) => {
|
|
2008
|
+
if (item.divider) {
|
|
2009
|
+
return /* @__PURE__ */ jsx8("div", { className: "sg-context-menu-divider" }, item.key);
|
|
2010
|
+
}
|
|
2011
|
+
return /* @__PURE__ */ jsxs8(
|
|
2012
|
+
"div",
|
|
2013
|
+
{
|
|
2014
|
+
className: itemClass(item),
|
|
2015
|
+
role: "menuitem",
|
|
2016
|
+
onClick: () => {
|
|
2017
|
+
if (item.disabled) return;
|
|
2018
|
+
item.onClick?.();
|
|
2019
|
+
if (!item.children) onClose();
|
|
2020
|
+
},
|
|
2021
|
+
onMouseEnter: (e) => {
|
|
2022
|
+
if (item.children) {
|
|
2023
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
2024
|
+
setSubMenu({ key: item.key, x: rect.right, y: rect.top, items: item.children });
|
|
2025
|
+
} else {
|
|
2026
|
+
setSubMenu(null);
|
|
2027
|
+
}
|
|
2028
|
+
},
|
|
2029
|
+
children: [
|
|
2030
|
+
item.icon && /* @__PURE__ */ jsx8("span", { className: "sg-context-menu-icon", children: item.icon }),
|
|
2031
|
+
/* @__PURE__ */ jsx8("span", { className: "sg-context-menu-label", children: item.label }),
|
|
2032
|
+
item.children && /* @__PURE__ */ jsx8("span", { className: "sg-context-menu-submenu-arrow", children: "\u203A" }),
|
|
2033
|
+
subMenu?.key === item.key && item.children && renderItems(item.children, true)
|
|
2034
|
+
]
|
|
2035
|
+
},
|
|
2036
|
+
item.key
|
|
2037
|
+
);
|
|
2038
|
+
})
|
|
2039
|
+
}
|
|
2040
|
+
);
|
|
2041
|
+
return renderItems(state.items);
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
// src/components/complex/Table/useTableState.ts
|
|
2045
|
+
import { useState as useState7, useRef as useRef6, useEffect as useEffect6, useMemo as useMemo3, useCallback as useCallback3 } from "react";
|
|
2046
|
+
|
|
2047
|
+
// src/components/complex/Table/helpers.ts
|
|
2048
|
+
function flattenLeafColumns(cols) {
|
|
2049
|
+
const result = [];
|
|
2050
|
+
for (const col of cols) {
|
|
2051
|
+
if (col.children && col.children.length > 0) {
|
|
2052
|
+
result.push(...flattenLeafColumns(col.children));
|
|
2053
|
+
} else {
|
|
2054
|
+
result.push(col);
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
return result;
|
|
2058
|
+
}
|
|
2059
|
+
function buildHeaderRows(cols) {
|
|
2060
|
+
function getDepth(c) {
|
|
2061
|
+
if (!c.children || c.children.length === 0) return 1;
|
|
2062
|
+
return 1 + Math.max(...c.children.map(getDepth));
|
|
2063
|
+
}
|
|
2064
|
+
const maxDepth = cols.length > 0 ? Math.max(...cols.map(getDepth)) : 1;
|
|
2065
|
+
function getLeafCount(c) {
|
|
2066
|
+
if (!c.children || c.children.length === 0) return 1;
|
|
2067
|
+
return c.children.reduce((sum, ch) => sum + getLeafCount(ch), 0);
|
|
2068
|
+
}
|
|
2069
|
+
const rows = Array.from({ length: maxDepth }, () => []);
|
|
2070
|
+
function fill(list, depth) {
|
|
2071
|
+
for (const c of list) {
|
|
2072
|
+
if (c.children && c.children.length > 0) {
|
|
2073
|
+
rows[depth].push({ col: c, colSpan: getLeafCount(c), rowSpan: 1 });
|
|
2074
|
+
fill(c.children, depth + 1);
|
|
2075
|
+
} else {
|
|
2076
|
+
rows[depth].push({ col: c, colSpan: 1, rowSpan: maxDepth - depth });
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
fill(cols, 0);
|
|
2081
|
+
return rows;
|
|
2082
|
+
}
|
|
2083
|
+
function flattenTreeRows(rows, childrenKey, expandedSet, depth = 0) {
|
|
2084
|
+
const result = [];
|
|
2085
|
+
for (const row of rows) {
|
|
2086
|
+
const children = row.data[childrenKey];
|
|
2087
|
+
const hasChildren = Array.isArray(children) && children.length > 0;
|
|
2088
|
+
result.push({ id: row.id, data: row.data, depth, hasChildren });
|
|
2089
|
+
if (hasChildren && expandedSet.has(row.id)) {
|
|
2090
|
+
result.push(...flattenTreeRows(children, childrenKey, expandedSet, depth + 1));
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
return result;
|
|
2094
|
+
}
|
|
2095
|
+
function collectAllTreeIds(rows, childrenKey) {
|
|
2096
|
+
const ids = [];
|
|
2097
|
+
for (const row of rows) {
|
|
2098
|
+
const children = row.data[childrenKey];
|
|
2099
|
+
if (Array.isArray(children) && children.length > 0) {
|
|
2100
|
+
ids.push(row.id);
|
|
2101
|
+
ids.push(...collectAllTreeIds(children, childrenKey));
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
return ids;
|
|
2105
|
+
}
|
|
2106
|
+
function computeSpanMap(columns, flatRows) {
|
|
2107
|
+
const map = /* @__PURE__ */ new Map();
|
|
2108
|
+
const hasOnCell = columns.some((c) => c.onCell);
|
|
2109
|
+
if (!hasOnCell) return map;
|
|
2110
|
+
flatRows.forEach((row, rowIndex) => {
|
|
2111
|
+
for (const col of columns) {
|
|
2112
|
+
if (col.onCell) {
|
|
2113
|
+
const span = col.onCell(row.data, rowIndex);
|
|
2114
|
+
if (span && (span.rowSpan !== void 0 || span.colSpan !== void 0)) {
|
|
2115
|
+
map.set(`${row.id}:${col.key}`, span);
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
});
|
|
2120
|
+
return map;
|
|
2121
|
+
}
|
|
2122
|
+
function computeHiddenCells(columns, flatRows, spanMap) {
|
|
2123
|
+
const hidden = /* @__PURE__ */ new Set();
|
|
2124
|
+
const hasOnCell = columns.some((c) => c.onCell);
|
|
2125
|
+
if (!hasOnCell) return hidden;
|
|
2126
|
+
flatRows.forEach((row, rowIndex) => {
|
|
2127
|
+
for (let ci = 0; ci < columns.length; ci++) {
|
|
2128
|
+
const key = `${row.id}:${columns[ci].key}`;
|
|
2129
|
+
const span = spanMap.get(key);
|
|
2130
|
+
if (!span) continue;
|
|
2131
|
+
if (span.rowSpan === 0 || span.colSpan === 0) {
|
|
2132
|
+
hidden.add(key);
|
|
2133
|
+
continue;
|
|
2134
|
+
}
|
|
2135
|
+
const rs = span.rowSpan ?? 1;
|
|
2136
|
+
const cs = span.colSpan ?? 1;
|
|
2137
|
+
for (let dr = 0; dr < rs; dr++) {
|
|
2138
|
+
for (let dc = 0; dc < cs; dc++) {
|
|
2139
|
+
if (dr === 0 && dc === 0) continue;
|
|
2140
|
+
const targetRow = flatRows[rowIndex + dr];
|
|
2141
|
+
const targetCol = columns[ci + dc];
|
|
2142
|
+
if (targetRow && targetCol) {
|
|
2143
|
+
hidden.add(`${targetRow.id}:${targetCol.key}`);
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
});
|
|
2149
|
+
return hidden;
|
|
2150
|
+
}
|
|
2151
|
+
function getFixedStyle(col, fixedLeftOffsets, fixedRightOffsets, isHeader) {
|
|
2152
|
+
const s = {};
|
|
2153
|
+
if (col.align) s.textAlign = col.align;
|
|
2154
|
+
if (col.ellipsis) {
|
|
2155
|
+
s.overflow = "hidden";
|
|
2156
|
+
s.textOverflow = "ellipsis";
|
|
2157
|
+
s.whiteSpace = "nowrap";
|
|
2158
|
+
}
|
|
2159
|
+
if (col.fixed === "left") {
|
|
2160
|
+
s.position = "sticky";
|
|
2161
|
+
s.left = fixedLeftOffsets[col.key];
|
|
2162
|
+
s.zIndex = isHeader ? 4 : 2;
|
|
2163
|
+
}
|
|
2164
|
+
if (col.fixed === "right") {
|
|
2165
|
+
s.position = "sticky";
|
|
2166
|
+
s.right = fixedRightOffsets[col.key];
|
|
2167
|
+
s.zIndex = isHeader ? 4 : 2;
|
|
2168
|
+
}
|
|
2169
|
+
return s;
|
|
2170
|
+
}
|
|
2171
|
+
function computeAggregate(values, type) {
|
|
2172
|
+
const nums = values.map(Number).filter((n) => !isNaN(n));
|
|
2173
|
+
if (nums.length === 0) return type === "count" ? values.length : "-";
|
|
2174
|
+
switch (type) {
|
|
2175
|
+
case "sum":
|
|
2176
|
+
return Math.round(nums.reduce((a, b) => a + b, 0) * 100) / 100;
|
|
2177
|
+
case "avg":
|
|
2178
|
+
return Math.round(nums.reduce((a, b) => a + b, 0) / nums.length * 100) / 100;
|
|
2179
|
+
case "count":
|
|
2180
|
+
return values.length;
|
|
2181
|
+
case "min":
|
|
2182
|
+
return Math.min(...nums);
|
|
2183
|
+
case "max":
|
|
2184
|
+
return Math.max(...nums);
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
function groupByColumn(flatRows, groupByKey, columns, expandedGroups) {
|
|
2188
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2189
|
+
const groupOrder = [];
|
|
2190
|
+
for (const row of flatRows) {
|
|
2191
|
+
const val = String(row.data[groupByKey] ?? "Other");
|
|
2192
|
+
if (!groups.has(val)) {
|
|
2193
|
+
groups.set(val, []);
|
|
2194
|
+
groupOrder.push(val);
|
|
2195
|
+
}
|
|
2196
|
+
groups.get(val).push(row);
|
|
2197
|
+
}
|
|
2198
|
+
const result = [];
|
|
2199
|
+
for (const gKey of groupOrder) {
|
|
2200
|
+
const rows = groups.get(gKey);
|
|
2201
|
+
const expanded = expandedGroups.has(gKey);
|
|
2202
|
+
const aggregates = {};
|
|
2203
|
+
for (const col of columns) {
|
|
2204
|
+
if (col.aggregate) {
|
|
2205
|
+
const values = rows.map((r) => r.data[col.key]);
|
|
2206
|
+
if (typeof col.aggregate === "function") {
|
|
2207
|
+
aggregates[col.key] = col.aggregate(values);
|
|
2208
|
+
} else {
|
|
2209
|
+
aggregates[col.key] = computeAggregate(values, col.aggregate);
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
const groupRow = {
|
|
2214
|
+
__isGroup: true,
|
|
2215
|
+
groupKey: gKey,
|
|
2216
|
+
groupValue: gKey,
|
|
2217
|
+
count: rows.length,
|
|
2218
|
+
expanded,
|
|
2219
|
+
aggregates
|
|
2220
|
+
};
|
|
2221
|
+
result.push({
|
|
2222
|
+
id: `__group_${gKey}`,
|
|
2223
|
+
data: {},
|
|
2224
|
+
depth: 0,
|
|
2225
|
+
hasChildren: false,
|
|
2226
|
+
__groupRow: groupRow
|
|
2227
|
+
});
|
|
2228
|
+
if (expanded) {
|
|
2229
|
+
result.push(...rows);
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
return result;
|
|
2233
|
+
}
|
|
2234
|
+
function separatePinnedRows(flatRows, topIds, bottomIds) {
|
|
2235
|
+
const topSet = new Set(topIds ?? []);
|
|
2236
|
+
const bottomSet = new Set(bottomIds ?? []);
|
|
2237
|
+
const top = [];
|
|
2238
|
+
const middle = [];
|
|
2239
|
+
const bottom = [];
|
|
2240
|
+
for (const row of flatRows) {
|
|
2241
|
+
if (topSet.has(row.id)) top.push(row);
|
|
2242
|
+
else if (bottomSet.has(row.id)) bottom.push(row);
|
|
2243
|
+
else middle.push(row);
|
|
2244
|
+
}
|
|
2245
|
+
if (topIds) {
|
|
2246
|
+
top.sort((a, b) => topIds.indexOf(a.id) - topIds.indexOf(b.id));
|
|
2247
|
+
}
|
|
2248
|
+
if (bottomIds) {
|
|
2249
|
+
bottom.sort((a, b) => bottomIds.indexOf(a.id) - bottomIds.indexOf(b.id));
|
|
2250
|
+
}
|
|
2251
|
+
return { top, middle, bottom };
|
|
2252
|
+
}
|
|
2253
|
+
function computeColumnAggregates(columns, flatRows) {
|
|
2254
|
+
const hasAny = columns.some((c) => c.aggregate);
|
|
2255
|
+
if (!hasAny) return null;
|
|
2256
|
+
const result = {};
|
|
2257
|
+
for (const col of columns) {
|
|
2258
|
+
if (!col.aggregate) continue;
|
|
2259
|
+
const values = flatRows.filter((r) => !r.__groupRow).map((r) => r.data[col.key]);
|
|
2260
|
+
if (typeof col.aggregate === "function") {
|
|
2261
|
+
result[col.key] = col.aggregate(values);
|
|
2262
|
+
} else {
|
|
2263
|
+
result[col.key] = computeAggregate(values, col.aggregate);
|
|
2264
|
+
}
|
|
2265
|
+
}
|
|
2266
|
+
return result;
|
|
2267
|
+
}
|
|
2268
|
+
|
|
2269
|
+
// src/components/complex/Table/defaultIcons.tsx
|
|
2270
|
+
import { jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
2271
|
+
var FilterIcon = /* @__PURE__ */ jsx9(
|
|
2272
|
+
"svg",
|
|
2273
|
+
{
|
|
2274
|
+
width: "12",
|
|
2275
|
+
height: "12",
|
|
2276
|
+
viewBox: "0 0 16 16",
|
|
2277
|
+
fill: "none",
|
|
2278
|
+
stroke: "currentColor",
|
|
2279
|
+
strokeWidth: "1.5",
|
|
2280
|
+
strokeLinejoin: "round",
|
|
2281
|
+
strokeLinecap: "round",
|
|
2282
|
+
"aria-hidden": "true",
|
|
2283
|
+
focusable: "false",
|
|
2284
|
+
children: /* @__PURE__ */ jsx9("path", { d: "M2 3h12l-5 6.5V14l-2 1V9.5L2 3z" })
|
|
2285
|
+
}
|
|
2286
|
+
);
|
|
2287
|
+
var SearchIcon = /* @__PURE__ */ jsxs9(
|
|
2288
|
+
"svg",
|
|
2289
|
+
{
|
|
2290
|
+
width: "12",
|
|
2291
|
+
height: "12",
|
|
2292
|
+
viewBox: "0 0 16 16",
|
|
2293
|
+
fill: "none",
|
|
2294
|
+
stroke: "currentColor",
|
|
2295
|
+
strokeWidth: "1.5",
|
|
2296
|
+
strokeLinecap: "round",
|
|
2297
|
+
"aria-hidden": "true",
|
|
2298
|
+
focusable: "false",
|
|
2299
|
+
children: [
|
|
2300
|
+
/* @__PURE__ */ jsx9("circle", { cx: "7", cy: "7", r: "4.5" }),
|
|
2301
|
+
/* @__PURE__ */ jsx9("path", { d: "M10.5 10.5L14 14" })
|
|
2302
|
+
]
|
|
2303
|
+
}
|
|
2304
|
+
);
|
|
2305
|
+
|
|
2306
|
+
// src/components/complex/Table/types.ts
|
|
2307
|
+
var DEFAULT_LOCALE = {
|
|
2308
|
+
emptyText: "No data",
|
|
2309
|
+
filterReset: "Reset",
|
|
2310
|
+
filterConfirm: "OK",
|
|
2311
|
+
filterSearchPlaceholder: "Search filters...",
|
|
2312
|
+
filterEmptyText: "No filters",
|
|
2313
|
+
searchPlaceholder: "Search...",
|
|
2314
|
+
sortAsc: "\u25B2",
|
|
2315
|
+
sortDesc: "\u25BC",
|
|
2316
|
+
expandIcon: "\u203A",
|
|
2317
|
+
filterIcon: FilterIcon,
|
|
2318
|
+
searchIcon: SearchIcon,
|
|
2319
|
+
totalRows: (count) => `${count} rows`,
|
|
2320
|
+
selectedRows: (count) => `${count} selected`,
|
|
2321
|
+
exportCSV: "Export CSV",
|
|
2322
|
+
exportJSON: "Export JSON",
|
|
2323
|
+
copyTable: "Copy",
|
|
2324
|
+
pinLeft: "Pin Left",
|
|
2325
|
+
pinRight: "Pin Right",
|
|
2326
|
+
unpin: "Unpin",
|
|
2327
|
+
showColumns: "Show Columns",
|
|
2328
|
+
print: "Print",
|
|
2329
|
+
fullscreen: "Fullscreen",
|
|
2330
|
+
exitFullscreen: "Exit Fullscreen",
|
|
2331
|
+
density: "Density",
|
|
2332
|
+
densitySmall: "Compact",
|
|
2333
|
+
densityMiddle: "Default",
|
|
2334
|
+
densityLarge: "Comfortable",
|
|
2335
|
+
groupCollapse: "Collapse All",
|
|
2336
|
+
groupExpand: "Expand All",
|
|
2337
|
+
sum: "Sum",
|
|
2338
|
+
avg: "Avg",
|
|
2339
|
+
count: "Count",
|
|
2340
|
+
min: "Min",
|
|
2341
|
+
max: "Max",
|
|
2342
|
+
copiedToClipboard: "Copied!",
|
|
2343
|
+
rowNumber: "#",
|
|
2344
|
+
groupByLabel: "Group by",
|
|
2345
|
+
groupByNone: "No grouping",
|
|
2346
|
+
filterAdvancedValuePlaceholder: "Value",
|
|
2347
|
+
filterAdvancedInPlaceholder: "value1, value2, ...",
|
|
2348
|
+
filterAdvancedBetweenMaxPlaceholder: "Max",
|
|
2349
|
+
filterOpEq: "=",
|
|
2350
|
+
filterOpNeq: "!=",
|
|
2351
|
+
filterOpLt: "<",
|
|
2352
|
+
filterOpLte: "<=",
|
|
2353
|
+
filterOpGt: ">",
|
|
2354
|
+
filterOpGte: ">=",
|
|
2355
|
+
filterOpBetween: "between",
|
|
2356
|
+
filterOpIn: "in",
|
|
2357
|
+
filterOpNotIn: "not in",
|
|
2358
|
+
filterOpContains: "contains",
|
|
2359
|
+
filterOpStartsWith: "starts with",
|
|
2360
|
+
filterOpEndsWith: "ends with",
|
|
2361
|
+
filterOpIsEmpty: "is empty",
|
|
2362
|
+
filterOpIsNotEmpty: "is not empty",
|
|
2363
|
+
filterOperatorAriaLabel: "Filter operator"
|
|
2364
|
+
};
|
|
2365
|
+
var DEFAULT_COL_WIDTH = 150;
|
|
2366
|
+
var MIN_COL_WIDTH = 50;
|
|
2367
|
+
var SELECTION_COL_WIDTH = "40px";
|
|
2368
|
+
|
|
2369
|
+
// src/components/complex/Table/useTableState.ts
|
|
2370
|
+
function useTableState(props) {
|
|
2371
|
+
const {
|
|
2372
|
+
columns: columnsProp,
|
|
2373
|
+
rowSelection,
|
|
2374
|
+
expandable,
|
|
2375
|
+
tree,
|
|
2376
|
+
draggable: _draggable,
|
|
2377
|
+
searchable,
|
|
2378
|
+
locale,
|
|
2379
|
+
onColumnOrderChange,
|
|
2380
|
+
onCellEdit: _onCellEdit,
|
|
2381
|
+
multiSort,
|
|
2382
|
+
sorts: controlledSorts,
|
|
2383
|
+
onSortsChange,
|
|
2384
|
+
hiddenColumns: hiddenColumnsProp,
|
|
2385
|
+
onHiddenColumnsChange,
|
|
2386
|
+
onColumnPinChange,
|
|
2387
|
+
groupBy,
|
|
2388
|
+
defaultGroupExpanded,
|
|
2389
|
+
onGroupExpandChange,
|
|
2390
|
+
pinnedRows: pinnedRowsConfig,
|
|
2391
|
+
keyboardNavigation,
|
|
2392
|
+
scroll,
|
|
2393
|
+
footer: _footer,
|
|
2394
|
+
showRowNumber: _showRowNumber,
|
|
2395
|
+
fullscreenable: _fullscreenable,
|
|
2396
|
+
densityToggle: _densityToggle,
|
|
2397
|
+
emptyContent: _emptyContent,
|
|
2398
|
+
printable: _printable,
|
|
2399
|
+
exportJSON: _exportJSON,
|
|
2400
|
+
highlightOnHover: _highlightOnHover,
|
|
2401
|
+
columnAutoResize: _columnAutoResize,
|
|
2402
|
+
...tableOptions
|
|
2403
|
+
} = props;
|
|
2404
|
+
const hasScrollX = scroll?.x != null;
|
|
2405
|
+
const {
|
|
2406
|
+
table,
|
|
2407
|
+
visibleRows,
|
|
2408
|
+
tableState,
|
|
2409
|
+
columnWidths: persistedColWidths,
|
|
2410
|
+
setSort,
|
|
2411
|
+
setSorts,
|
|
2412
|
+
clearSort,
|
|
2413
|
+
setPage,
|
|
2414
|
+
setFilterFn,
|
|
2415
|
+
setColumnWidth: persistColumnWidth,
|
|
2416
|
+
refresh
|
|
2417
|
+
} = useTable(tableOptions);
|
|
2418
|
+
const t = useMemo3(() => ({ ...DEFAULT_LOCALE, ...locale }), [locale]);
|
|
2419
|
+
const hasColumnGroups = columnsProp.some((c) => c.children && c.children.length > 0);
|
|
2420
|
+
const leafColumns = useMemo3(() => flattenLeafColumns(columnsProp), [columnsProp]);
|
|
2421
|
+
const headerRows = useMemo3(
|
|
2422
|
+
() => hasColumnGroups ? buildHeaderRows(columnsProp) : null,
|
|
2423
|
+
[columnsProp, hasColumnGroups]
|
|
2424
|
+
);
|
|
2425
|
+
const [internalSorts, setInternalSorts] = useState7([]);
|
|
2426
|
+
const sorts = controlledSorts ?? internalSorts;
|
|
2427
|
+
const [colWidths, setColWidths] = useState7(() => {
|
|
2428
|
+
const w = {};
|
|
2429
|
+
for (const c of leafColumns) {
|
|
2430
|
+
w[c.key] = persistedColWidths[c.key] ?? c.width ?? DEFAULT_COL_WIDTH;
|
|
2431
|
+
}
|
|
2432
|
+
return w;
|
|
2433
|
+
});
|
|
2434
|
+
const [userResizedCols, setUserResizedCols] = useState7(
|
|
2435
|
+
() => new Set(Object.keys(persistedColWidths))
|
|
2436
|
+
);
|
|
2437
|
+
const [colOrder, setColOrder] = useState7(() => leafColumns.map((c) => c.key));
|
|
2438
|
+
const [dragCol, setDragCol] = useState7(null);
|
|
2439
|
+
const [dragOver, setDragOver] = useState7(null);
|
|
2440
|
+
const [internalHidden, setInternalHidden] = useState7(
|
|
2441
|
+
() => new Set(hiddenColumnsProp ?? [])
|
|
2442
|
+
);
|
|
2443
|
+
const hiddenSet = useMemo3(
|
|
2444
|
+
() => hiddenColumnsProp ? new Set(hiddenColumnsProp) : internalHidden,
|
|
2445
|
+
[hiddenColumnsProp, internalHidden]
|
|
2446
|
+
);
|
|
2447
|
+
const toggleColumnVisibility = useCallback3(
|
|
2448
|
+
(key) => {
|
|
2449
|
+
if (onHiddenColumnsChange) {
|
|
2450
|
+
const current = hiddenColumnsProp ?? [];
|
|
2451
|
+
const next = current.includes(key) ? current.filter((k) => k !== key) : [...current, key];
|
|
2452
|
+
onHiddenColumnsChange(next);
|
|
2453
|
+
} else {
|
|
2454
|
+
setInternalHidden((prev) => {
|
|
2455
|
+
const next = new Set(prev);
|
|
2456
|
+
if (next.has(key)) {
|
|
2457
|
+
next.delete(key);
|
|
2458
|
+
} else {
|
|
2459
|
+
next.add(key);
|
|
2460
|
+
}
|
|
2461
|
+
return next;
|
|
2462
|
+
});
|
|
2463
|
+
}
|
|
2464
|
+
},
|
|
2465
|
+
[hiddenColumnsProp, onHiddenColumnsChange]
|
|
2466
|
+
);
|
|
2467
|
+
const [internalExpanded, setInternalExpanded] = useState7(() => {
|
|
2468
|
+
if (tree?.defaultExpandAllRows) {
|
|
2469
|
+
const childrenKey2 = tree.childrenColumnName ?? "children";
|
|
2470
|
+
return new Set(collectAllTreeIds(props.data ?? [], childrenKey2));
|
|
2471
|
+
}
|
|
2472
|
+
return new Set(expandable?.defaultExpandedRowKeys ?? []);
|
|
2473
|
+
});
|
|
2474
|
+
const expandedKeys = expandable?.expandedKeys ? new Set(expandable.expandedKeys) : internalExpanded;
|
|
2475
|
+
const [treeExpanded, setTreeExpanded] = useState7(() => {
|
|
2476
|
+
if (tree?.defaultExpandAllRows) {
|
|
2477
|
+
const childrenKey2 = tree.childrenColumnName ?? "children";
|
|
2478
|
+
return new Set(collectAllTreeIds(props.data ?? [], childrenKey2));
|
|
2479
|
+
}
|
|
2480
|
+
return /* @__PURE__ */ new Set();
|
|
2481
|
+
});
|
|
2482
|
+
const [searchText, setSearchText] = useState7("");
|
|
2483
|
+
const [activeFilters, setActiveFilters] = useState7(() => {
|
|
2484
|
+
const init = {};
|
|
2485
|
+
for (const col of leafColumns) {
|
|
2486
|
+
if (col.filteredValue) {
|
|
2487
|
+
init[col.key] = [...col.filteredValue];
|
|
2488
|
+
} else if (col.defaultFilteredValue) {
|
|
2489
|
+
init[col.key] = [...col.defaultFilteredValue];
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
return init;
|
|
2493
|
+
});
|
|
2494
|
+
const [filterSearchText, setFilterSearchText] = useState7({});
|
|
2495
|
+
const [openFilterDropdown, setOpenFilterDropdown] = useState7(null);
|
|
2496
|
+
const [advancedFilters, setAdvancedFiltersState] = useState7({});
|
|
2497
|
+
const filterRef = useRef6(null);
|
|
2498
|
+
const [filterAnchor, setFilterAnchor] = useState7(null);
|
|
2499
|
+
const setAdvancedFilter = useCallback3(
|
|
2500
|
+
(colKey, filter) => {
|
|
2501
|
+
setAdvancedFiltersState((prev) => {
|
|
2502
|
+
const next = { ...prev };
|
|
2503
|
+
if (filter == null) delete next[colKey];
|
|
2504
|
+
else next[colKey] = filter;
|
|
2505
|
+
return next;
|
|
2506
|
+
});
|
|
2507
|
+
table.setColumnFilter(colKey, filter);
|
|
2508
|
+
refresh();
|
|
2509
|
+
},
|
|
2510
|
+
[table, refresh]
|
|
2511
|
+
);
|
|
2512
|
+
const resizeRef = useRef6(null);
|
|
2513
|
+
const [contextMenu, setContextMenu] = useState7(null);
|
|
2514
|
+
const columns = useMemo3(() => {
|
|
2515
|
+
const base = hasColumnGroups ? leafColumns : (() => {
|
|
2516
|
+
const map = new Map(leafColumns.map((c) => [c.key, c]));
|
|
2517
|
+
return colOrder.filter((k) => map.has(k)).map((k) => map.get(k));
|
|
2518
|
+
})();
|
|
2519
|
+
return base.filter((c) => !hiddenSet.has(c.key) && !c.hidden);
|
|
2520
|
+
}, [leafColumns, colOrder, hasColumnGroups, hiddenSet]);
|
|
2521
|
+
useEffect6(() => {
|
|
2522
|
+
const keys = leafColumns.map((c) => c.key);
|
|
2523
|
+
setColOrder((prev) => {
|
|
2524
|
+
const prevSet = new Set(prev);
|
|
2525
|
+
const added = keys.filter((k) => !prevSet.has(k));
|
|
2526
|
+
const valid = prev.filter((k) => keys.includes(k));
|
|
2527
|
+
return [...valid, ...added];
|
|
2528
|
+
});
|
|
2529
|
+
}, [leafColumns]);
|
|
2530
|
+
useEffect6(() => {
|
|
2531
|
+
for (const col of leafColumns) {
|
|
2532
|
+
if (col.filteredValue !== void 0) {
|
|
2533
|
+
setActiveFilters((prev) => {
|
|
2534
|
+
if (JSON.stringify(prev[col.key]) === JSON.stringify(col.filteredValue)) return prev;
|
|
2535
|
+
return { ...prev, [col.key]: [...col.filteredValue] };
|
|
2536
|
+
});
|
|
2537
|
+
}
|
|
2538
|
+
}
|
|
2539
|
+
}, [leafColumns]);
|
|
2540
|
+
useEffect6(() => {
|
|
2541
|
+
const colFilters = columns.filter((c) => c.onFilter && activeFilters[c.key]?.length);
|
|
2542
|
+
const hasSearch = searchable && searchText.length > 0;
|
|
2543
|
+
if (colFilters.length === 0 && !hasSearch) {
|
|
2544
|
+
setFilterFn(null);
|
|
2545
|
+
return;
|
|
2546
|
+
}
|
|
2547
|
+
const lower = hasSearch ? searchText.toLowerCase() : "";
|
|
2548
|
+
setFilterFn((row) => {
|
|
2549
|
+
for (const col of colFilters) {
|
|
2550
|
+
const vals = activeFilters[col.key];
|
|
2551
|
+
const fn = col.onFilter;
|
|
2552
|
+
if (!vals.some((v) => fn(v, row))) return false;
|
|
2553
|
+
}
|
|
2554
|
+
if (hasSearch) {
|
|
2555
|
+
const match = Object.values(row).some(
|
|
2556
|
+
(v) => v != null && String(v).toLowerCase().includes(lower)
|
|
2557
|
+
);
|
|
2558
|
+
if (!match) return false;
|
|
2559
|
+
}
|
|
2560
|
+
return true;
|
|
2561
|
+
});
|
|
2562
|
+
}, [activeFilters, searchText, searchable, setFilterFn, columns]);
|
|
2563
|
+
useEffect6(() => {
|
|
2564
|
+
if (!openFilterDropdown) return;
|
|
2565
|
+
const handle = (e) => {
|
|
2566
|
+
if (filterRef.current && !filterRef.current.contains(e.target)) {
|
|
2567
|
+
setOpenFilterDropdown(null);
|
|
2568
|
+
}
|
|
2569
|
+
};
|
|
2570
|
+
document.addEventListener("mousedown", handle);
|
|
2571
|
+
return () => document.removeEventListener("mousedown", handle);
|
|
2572
|
+
}, [openFilterDropdown]);
|
|
2573
|
+
const handleSort = useCallback3(
|
|
2574
|
+
(col, shiftKey) => {
|
|
2575
|
+
if (!col.sortable) return;
|
|
2576
|
+
if (multiSort && shiftKey) {
|
|
2577
|
+
const existing = sorts.find((s) => s.column === col.key);
|
|
2578
|
+
let next;
|
|
2579
|
+
if (!existing) {
|
|
2580
|
+
next = [...sorts, { column: col.key, direction: "asc" }];
|
|
2581
|
+
} else if (existing.direction === "asc") {
|
|
2582
|
+
next = sorts.map(
|
|
2583
|
+
(s) => s.column === col.key ? { ...s, direction: "desc" } : s
|
|
2584
|
+
);
|
|
2585
|
+
} else {
|
|
2586
|
+
next = sorts.filter((s) => s.column !== col.key);
|
|
2587
|
+
}
|
|
2588
|
+
if (onSortsChange) {
|
|
2589
|
+
onSortsChange(next);
|
|
2590
|
+
} else {
|
|
2591
|
+
setInternalSorts(next);
|
|
2592
|
+
}
|
|
2593
|
+
if (next.length === 0) {
|
|
2594
|
+
clearSort();
|
|
2595
|
+
} else {
|
|
2596
|
+
setSorts(next);
|
|
2597
|
+
}
|
|
2598
|
+
} else {
|
|
2599
|
+
const current = sorts.length === 1 ? sorts[0] : null;
|
|
2600
|
+
let next;
|
|
2601
|
+
if (!current || current.column !== col.key) {
|
|
2602
|
+
next = [{ column: col.key, direction: "asc" }];
|
|
2603
|
+
} else if (current.direction === "asc") {
|
|
2604
|
+
next = [{ column: col.key, direction: "desc" }];
|
|
2605
|
+
} else {
|
|
2606
|
+
next = [];
|
|
2607
|
+
}
|
|
2608
|
+
if (onSortsChange) {
|
|
2609
|
+
onSortsChange(next);
|
|
2610
|
+
} else {
|
|
2611
|
+
setInternalSorts(next);
|
|
2612
|
+
}
|
|
2613
|
+
if (next.length === 0) {
|
|
2614
|
+
clearSort();
|
|
2615
|
+
} else {
|
|
2616
|
+
setSort(next[0].column, next[0].direction);
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
},
|
|
2620
|
+
[multiSort, sorts, onSortsChange, setSort, setSorts, clearSort]
|
|
2621
|
+
);
|
|
2622
|
+
const getSortIndex = useCallback3(
|
|
2623
|
+
(colKey) => {
|
|
2624
|
+
if (!multiSort || sorts.length <= 1) return -1;
|
|
2625
|
+
return sorts.findIndex((s) => s.column === colKey);
|
|
2626
|
+
},
|
|
2627
|
+
[multiSort, sorts]
|
|
2628
|
+
);
|
|
2629
|
+
const getSortDirection = useCallback3(
|
|
2630
|
+
(colKey) => {
|
|
2631
|
+
const found = sorts.find((s) => s.column === colKey);
|
|
2632
|
+
return found?.direction ?? null;
|
|
2633
|
+
},
|
|
2634
|
+
[sorts]
|
|
2635
|
+
);
|
|
2636
|
+
const handleToggleExpand = (id) => {
|
|
2637
|
+
const open = expandedKeys.has(id);
|
|
2638
|
+
if (expandable?.onExpand) {
|
|
2639
|
+
expandable.onExpand(!open, id);
|
|
2640
|
+
} else {
|
|
2641
|
+
setInternalExpanded((prev) => {
|
|
2642
|
+
const next = new Set(prev);
|
|
2643
|
+
if (open) {
|
|
2644
|
+
next.delete(id);
|
|
2645
|
+
} else {
|
|
2646
|
+
next.add(id);
|
|
2647
|
+
}
|
|
2648
|
+
return next;
|
|
2649
|
+
});
|
|
2650
|
+
}
|
|
2651
|
+
};
|
|
2652
|
+
const handleToggleTreeExpand = (id) => {
|
|
2653
|
+
setTreeExpanded((prev) => {
|
|
2654
|
+
const next = new Set(prev);
|
|
2655
|
+
if (next.has(id)) {
|
|
2656
|
+
next.delete(id);
|
|
2657
|
+
} else {
|
|
2658
|
+
next.add(id);
|
|
2659
|
+
}
|
|
2660
|
+
return next;
|
|
2661
|
+
});
|
|
2662
|
+
};
|
|
2663
|
+
const handleSelectRow = (id, row) => {
|
|
2664
|
+
if (!rowSelection) return;
|
|
2665
|
+
const { selectedKeys, onChange, type = "checkbox" } = rowSelection;
|
|
2666
|
+
if (type === "radio") {
|
|
2667
|
+
onChange([id], [row]);
|
|
2668
|
+
return;
|
|
2669
|
+
}
|
|
2670
|
+
const next = selectedKeys.includes(id) ? selectedKeys.filter((k) => k !== id) : [...selectedKeys, id];
|
|
2671
|
+
onChange(
|
|
2672
|
+
next,
|
|
2673
|
+
visibleRows.filter((r) => next.includes(r.id)).map((r) => r.data)
|
|
2674
|
+
);
|
|
2675
|
+
};
|
|
2676
|
+
const handleSelectAll = () => {
|
|
2677
|
+
if (!rowSelection) return;
|
|
2678
|
+
const ids = visibleRows.map((r) => r.id);
|
|
2679
|
+
const all = ids.every((id) => rowSelection.selectedKeys.includes(id));
|
|
2680
|
+
rowSelection.onChange(all ? [] : ids, all ? [] : visibleRows.map((r) => r.data));
|
|
2681
|
+
};
|
|
2682
|
+
const handleFilterToggle = (colKey, value, multiple) => {
|
|
2683
|
+
setActiveFilters((prev) => {
|
|
2684
|
+
const current = prev[colKey] ?? [];
|
|
2685
|
+
if (!multiple) return { ...prev, [colKey]: [value] };
|
|
2686
|
+
const idx = current.indexOf(value);
|
|
2687
|
+
const next = idx >= 0 ? current.filter((_, i) => i !== idx) : [...current, value];
|
|
2688
|
+
return { ...prev, [colKey]: next };
|
|
2689
|
+
});
|
|
2690
|
+
};
|
|
2691
|
+
const handleFilterConfirm = (colKey) => {
|
|
2692
|
+
setOpenFilterDropdown(null);
|
|
2693
|
+
setFilterSearchText((prev) => ({ ...prev, [colKey]: "" }));
|
|
2694
|
+
};
|
|
2695
|
+
const handleFilterReset = (colKey) => {
|
|
2696
|
+
setActiveFilters((prev) => ({ ...prev, [colKey]: [] }));
|
|
2697
|
+
setFilterSearchText((prev) => ({ ...prev, [colKey]: "" }));
|
|
2698
|
+
};
|
|
2699
|
+
const handleFilterClose = (colKey) => {
|
|
2700
|
+
setOpenFilterDropdown(null);
|
|
2701
|
+
setFilterSearchText((prev) => ({ ...prev, [colKey]: "" }));
|
|
2702
|
+
};
|
|
2703
|
+
const handleSearchFilterChange = (colKey, text) => {
|
|
2704
|
+
setActiveFilters((prev) => ({ ...prev, [colKey]: text ? [text] : [] }));
|
|
2705
|
+
};
|
|
2706
|
+
const getFilterDropdownProps = (col) => ({
|
|
2707
|
+
selectedKeys: activeFilters[col.key] ?? [],
|
|
2708
|
+
setSelectedKeys: (keys) => setActiveFilters((prev) => ({ ...prev, [col.key]: keys })),
|
|
2709
|
+
confirm: () => handleFilterConfirm(col.key),
|
|
2710
|
+
clearFilters: () => handleFilterReset(col.key),
|
|
2711
|
+
close: () => handleFilterClose(col.key)
|
|
2712
|
+
});
|
|
2713
|
+
const handleResizeStart = (e, colKey) => {
|
|
2714
|
+
e.preventDefault();
|
|
2715
|
+
e.stopPropagation();
|
|
2716
|
+
resizeRef.current = {
|
|
2717
|
+
col: colKey,
|
|
2718
|
+
startX: e.clientX,
|
|
2719
|
+
startW: colWidths[colKey] ?? DEFAULT_COL_WIDTH
|
|
2720
|
+
};
|
|
2721
|
+
const onMove = (ev) => {
|
|
2722
|
+
if (!resizeRef.current) return;
|
|
2723
|
+
const diff = ev.clientX - resizeRef.current.startX;
|
|
2724
|
+
const min = leafColumns.find((c) => c.key === resizeRef.current.col)?.minWidth ?? MIN_COL_WIDTH;
|
|
2725
|
+
setColWidths((prev) => ({
|
|
2726
|
+
...prev,
|
|
2727
|
+
[resizeRef.current.col]: Math.max(min, resizeRef.current.startW + diff)
|
|
2728
|
+
}));
|
|
2729
|
+
setUserResizedCols(
|
|
2730
|
+
(prev) => prev.has(resizeRef.current.col) ? prev : new Set(prev).add(resizeRef.current.col)
|
|
2731
|
+
);
|
|
2732
|
+
};
|
|
2733
|
+
const onUp = () => {
|
|
2734
|
+
const ref = resizeRef.current;
|
|
2735
|
+
resizeRef.current = null;
|
|
2736
|
+
document.removeEventListener("mousemove", onMove);
|
|
2737
|
+
document.removeEventListener("mouseup", onUp);
|
|
2738
|
+
if (!ref) return;
|
|
2739
|
+
setColWidths((prev) => {
|
|
2740
|
+
const w = prev[ref.col];
|
|
2741
|
+
if (typeof w === "number") persistColumnWidth(ref.col, w);
|
|
2742
|
+
return prev;
|
|
2743
|
+
});
|
|
2744
|
+
};
|
|
2745
|
+
document.addEventListener("mousemove", onMove);
|
|
2746
|
+
document.addEventListener("mouseup", onUp);
|
|
2747
|
+
};
|
|
2748
|
+
const handleDragStart = (e, key) => {
|
|
2749
|
+
setDragCol(key);
|
|
2750
|
+
e.dataTransfer.effectAllowed = "move";
|
|
2751
|
+
e.dataTransfer.setData("text/plain", key);
|
|
2752
|
+
};
|
|
2753
|
+
const handleDragOver = (e, key) => {
|
|
2754
|
+
e.preventDefault();
|
|
2755
|
+
e.dataTransfer.dropEffect = "move";
|
|
2756
|
+
setDragOver(key);
|
|
2757
|
+
};
|
|
2758
|
+
const handleDrop = (e, targetKey) => {
|
|
2759
|
+
e.preventDefault();
|
|
2760
|
+
if (!dragCol || dragCol === targetKey) {
|
|
2761
|
+
setDragCol(null);
|
|
2762
|
+
setDragOver(null);
|
|
2763
|
+
return;
|
|
2764
|
+
}
|
|
2765
|
+
setColOrder((prev) => {
|
|
2766
|
+
const next = prev.filter((k) => k !== dragCol);
|
|
2767
|
+
const idx = next.indexOf(targetKey);
|
|
2768
|
+
next.splice(idx, 0, dragCol);
|
|
2769
|
+
onColumnOrderChange?.(next);
|
|
2770
|
+
return next;
|
|
2771
|
+
});
|
|
2772
|
+
setDragCol(null);
|
|
2773
|
+
setDragOver(null);
|
|
2774
|
+
};
|
|
2775
|
+
const handleDragEnd = () => {
|
|
2776
|
+
setDragCol(null);
|
|
2777
|
+
setDragOver(null);
|
|
2778
|
+
};
|
|
2779
|
+
const handlePinColumn = useCallback3(
|
|
2780
|
+
(key, fixed) => {
|
|
2781
|
+
onColumnPinChange?.(key, fixed);
|
|
2782
|
+
},
|
|
2783
|
+
[onColumnPinChange]
|
|
2784
|
+
);
|
|
2785
|
+
const [isFullscreen, setIsFullscreen] = useState7(false);
|
|
2786
|
+
const wrapperRef = useRef6(null);
|
|
2787
|
+
const toggleFullscreen = useCallback3(() => {
|
|
2788
|
+
setIsFullscreen((prev) => !prev);
|
|
2789
|
+
}, []);
|
|
2790
|
+
const [density, setDensity] = useState7("middle");
|
|
2791
|
+
useEffect6(() => {
|
|
2792
|
+
if (!groupBy) {
|
|
2793
|
+
table.clearGroupBy();
|
|
2794
|
+
return;
|
|
2795
|
+
}
|
|
2796
|
+
const aggregates2 = leafColumns.filter((c) => c.aggregate).map((c) => ({
|
|
2797
|
+
column: c.key,
|
|
2798
|
+
type: typeof c.aggregate === "function" ? c.aggregate : c.aggregate
|
|
2799
|
+
}));
|
|
2800
|
+
table.groupBy(groupBy, aggregates2);
|
|
2801
|
+
}, [groupBy, leafColumns, table]);
|
|
2802
|
+
const [expandedGroups, setExpandedGroups] = useState7(() => {
|
|
2803
|
+
return defaultGroupExpanded ? /* @__PURE__ */ new Set(["__all__"]) : /* @__PURE__ */ new Set();
|
|
2804
|
+
});
|
|
2805
|
+
const toggleGroupExpand = useCallback3(
|
|
2806
|
+
(groupKey) => {
|
|
2807
|
+
setExpandedGroups((prev) => {
|
|
2808
|
+
const next = new Set(prev);
|
|
2809
|
+
const wasExpanded = next.has(groupKey);
|
|
2810
|
+
if (wasExpanded) {
|
|
2811
|
+
next.delete(groupKey);
|
|
2812
|
+
} else {
|
|
2813
|
+
next.add(groupKey);
|
|
2814
|
+
}
|
|
2815
|
+
onGroupExpandChange?.(groupKey, !wasExpanded);
|
|
2816
|
+
return next;
|
|
2817
|
+
});
|
|
2818
|
+
},
|
|
2819
|
+
[onGroupExpandChange]
|
|
2820
|
+
);
|
|
2821
|
+
const expandAllGroups = useCallback3(() => {
|
|
2822
|
+
setExpandedGroups((prev) => {
|
|
2823
|
+
const next = new Set(prev);
|
|
2824
|
+
next.add("__all__");
|
|
2825
|
+
return next;
|
|
2826
|
+
});
|
|
2827
|
+
}, []);
|
|
2828
|
+
const collapseAllGroups = useCallback3(() => {
|
|
2829
|
+
setExpandedGroups(/* @__PURE__ */ new Set());
|
|
2830
|
+
}, []);
|
|
2831
|
+
const [focusedCell, setFocusedCell] = useState7(null);
|
|
2832
|
+
const handleKeyNav = useCallback3(
|
|
2833
|
+
(e) => {
|
|
2834
|
+
if (!keyboardNavigation || !focusedCell) return;
|
|
2835
|
+
const maxRow = visibleRows.length - 1;
|
|
2836
|
+
const maxCol = columns.length - 1;
|
|
2837
|
+
let { row, col } = focusedCell;
|
|
2838
|
+
switch (e.key) {
|
|
2839
|
+
case "ArrowUp":
|
|
2840
|
+
e.preventDefault();
|
|
2841
|
+
row = Math.max(0, row - 1);
|
|
2842
|
+
break;
|
|
2843
|
+
case "ArrowDown":
|
|
2844
|
+
e.preventDefault();
|
|
2845
|
+
row = Math.min(maxRow, row + 1);
|
|
2846
|
+
break;
|
|
2847
|
+
case "ArrowLeft":
|
|
2848
|
+
e.preventDefault();
|
|
2849
|
+
col = Math.max(0, col - 1);
|
|
2850
|
+
break;
|
|
2851
|
+
case "ArrowRight":
|
|
2852
|
+
e.preventDefault();
|
|
2853
|
+
col = Math.min(maxCol, col + 1);
|
|
2854
|
+
break;
|
|
2855
|
+
case "Tab":
|
|
2856
|
+
e.preventDefault();
|
|
2857
|
+
if (e.shiftKey) {
|
|
2858
|
+
col -= 1;
|
|
2859
|
+
if (col < 0) {
|
|
2860
|
+
col = maxCol;
|
|
2861
|
+
row = Math.max(0, row - 1);
|
|
2862
|
+
}
|
|
2863
|
+
} else {
|
|
2864
|
+
col += 1;
|
|
2865
|
+
if (col > maxCol) {
|
|
2866
|
+
col = 0;
|
|
2867
|
+
row = Math.min(maxRow, row + 1);
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2870
|
+
break;
|
|
2871
|
+
case "Home":
|
|
2872
|
+
e.preventDefault();
|
|
2873
|
+
col = 0;
|
|
2874
|
+
if (e.ctrlKey) row = 0;
|
|
2875
|
+
break;
|
|
2876
|
+
case "End":
|
|
2877
|
+
e.preventDefault();
|
|
2878
|
+
col = maxCol;
|
|
2879
|
+
if (e.ctrlKey) row = maxRow;
|
|
2880
|
+
break;
|
|
2881
|
+
default:
|
|
2882
|
+
return;
|
|
2883
|
+
}
|
|
2884
|
+
setFocusedCell({ row, col });
|
|
2885
|
+
},
|
|
2886
|
+
[keyboardNavigation, focusedCell, visibleRows.length, columns.length]
|
|
2887
|
+
);
|
|
2888
|
+
const handleAutoResize = useCallback3(
|
|
2889
|
+
(colKey) => {
|
|
2890
|
+
const maxLen = visibleRows.reduce((max, row) => {
|
|
2891
|
+
const val = String(row.data[colKey] ?? "");
|
|
2892
|
+
return Math.max(max, val.length);
|
|
2893
|
+
}, 0);
|
|
2894
|
+
const headerCol = leafColumns.find((c) => c.key === colKey);
|
|
2895
|
+
const headerLen = typeof headerCol?.title === "string" ? headerCol.title.length : 6;
|
|
2896
|
+
const charWidth = 8;
|
|
2897
|
+
const padding = 32;
|
|
2898
|
+
const min = headerCol?.minWidth ?? MIN_COL_WIDTH;
|
|
2899
|
+
const optimal = Math.max(min, Math.max(maxLen, headerLen) * charWidth + padding);
|
|
2900
|
+
setColWidths((prev) => ({ ...prev, [colKey]: optimal }));
|
|
2901
|
+
setUserResizedCols((prev) => prev.has(colKey) ? prev : new Set(prev).add(colKey));
|
|
2902
|
+
},
|
|
2903
|
+
[visibleRows, leafColumns]
|
|
2904
|
+
);
|
|
2905
|
+
const isTreeMode = !!tree;
|
|
2906
|
+
const childrenKey = tree?.childrenColumnName ?? "children";
|
|
2907
|
+
const indentSize = tree?.indentSize ?? 20;
|
|
2908
|
+
const baseFlatRows = useMemo3(() => {
|
|
2909
|
+
if (!isTreeMode) {
|
|
2910
|
+
return visibleRows.map((r) => ({
|
|
2911
|
+
id: r.id,
|
|
2912
|
+
data: r.data,
|
|
2913
|
+
depth: 0,
|
|
2914
|
+
hasChildren: false
|
|
2915
|
+
}));
|
|
2916
|
+
}
|
|
2917
|
+
return flattenTreeRows(visibleRows, childrenKey, treeExpanded);
|
|
2918
|
+
}, [visibleRows, isTreeMode, childrenKey, treeExpanded]);
|
|
2919
|
+
const groupedRows = useMemo3(() => {
|
|
2920
|
+
if (!groupBy) return baseFlatRows;
|
|
2921
|
+
const allExpanded = expandedGroups.has("__all__");
|
|
2922
|
+
const effectiveExpanded = allExpanded ? /* @__PURE__ */ new Set([...expandedGroups, ...baseFlatRows.map((r) => String(r.data[groupBy] ?? "Other"))]) : expandedGroups;
|
|
2923
|
+
return groupByColumn(baseFlatRows, groupBy, columns, effectiveExpanded);
|
|
2924
|
+
}, [baseFlatRows, groupBy, columns, expandedGroups]);
|
|
2925
|
+
const {
|
|
2926
|
+
top: pinnedTop,
|
|
2927
|
+
middle: middleRows,
|
|
2928
|
+
bottom: pinnedBottom
|
|
2929
|
+
} = useMemo3(
|
|
2930
|
+
() => separatePinnedRows(groupedRows, pinnedRowsConfig?.top, pinnedRowsConfig?.bottom),
|
|
2931
|
+
[groupedRows, pinnedRowsConfig]
|
|
2932
|
+
);
|
|
2933
|
+
const flatRows = groupedRows;
|
|
2934
|
+
const aggregates = useMemo3(
|
|
2935
|
+
() => computeColumnAggregates(columns, baseFlatRows),
|
|
2936
|
+
[columns, baseFlatRows]
|
|
2937
|
+
);
|
|
2938
|
+
const extraBefore = [];
|
|
2939
|
+
if (rowSelection) extraBefore.push(SELECTION_COL_WIDTH);
|
|
2940
|
+
if (expandable) extraBefore.push(SELECTION_COL_WIDTH);
|
|
2941
|
+
const hasAutoColumns = columns.some(
|
|
2942
|
+
(c) => !c.fixed && !userResizedCols.has(c.key) && c.width == null
|
|
2943
|
+
);
|
|
2944
|
+
const shouldFlexExplicitWidths = !hasScrollX && !hasAutoColumns;
|
|
2945
|
+
const scrollXMinWidth = typeof scroll?.x === "number" ? scroll.x : typeof scroll?.x === "string" && scroll.x.trim().endsWith("px") ? Number.parseFloat(scroll.x) : null;
|
|
2946
|
+
const declaredGridWidth = extraBefore.reduce((sum, w) => sum + Number.parseFloat(w), 0) + columns.reduce((sum, c) => sum + (colWidths[c.key] ?? c.width ?? DEFAULT_COL_WIDTH), 0);
|
|
2947
|
+
const shouldFillScrollX = hasScrollX && scrollXMinWidth !== null && Number.isFinite(scrollXMinWidth) && scrollXMinWidth > declaredGridWidth;
|
|
2948
|
+
const colTemplates = columns.map((c) => {
|
|
2949
|
+
const resized = userResizedCols.has(c.key);
|
|
2950
|
+
const w = colWidths[c.key] ?? c.width ?? DEFAULT_COL_WIDTH;
|
|
2951
|
+
if (hasScrollX) {
|
|
2952
|
+
if (c.fixed || resized) {
|
|
2953
|
+
return `${w}px`;
|
|
2954
|
+
}
|
|
2955
|
+
return shouldFillScrollX ? `minmax(${w}px, ${w}fr)` : `${w}px`;
|
|
2956
|
+
}
|
|
2957
|
+
if (c.fixed || resized) {
|
|
2958
|
+
return `${w}px`;
|
|
2959
|
+
}
|
|
2960
|
+
if (c.width == null) {
|
|
2961
|
+
return `minmax(${MIN_COL_WIDTH}px, 1fr)`;
|
|
2962
|
+
}
|
|
2963
|
+
if (shouldFlexExplicitWidths) {
|
|
2964
|
+
return `minmax(${MIN_COL_WIDTH}px, ${w}fr)`;
|
|
2965
|
+
}
|
|
2966
|
+
return `minmax(${MIN_COL_WIDTH}px, ${w}px)`;
|
|
2967
|
+
});
|
|
2968
|
+
const gridTemplate = [...extraBefore, ...colTemplates].join(" ");
|
|
2969
|
+
const totalCols = extraBefore.length + columns.length;
|
|
2970
|
+
const fixedLeftOffsets = useMemo3(() => {
|
|
2971
|
+
const o = {};
|
|
2972
|
+
const selW = parseInt(SELECTION_COL_WIDTH);
|
|
2973
|
+
let left = (rowSelection ? selW : 0) + (expandable ? selW : 0);
|
|
2974
|
+
for (const col of columns) {
|
|
2975
|
+
if (col.fixed === "left") {
|
|
2976
|
+
o[col.key] = left;
|
|
2977
|
+
left += colWidths[col.key] ?? col.width ?? DEFAULT_COL_WIDTH;
|
|
2978
|
+
}
|
|
2979
|
+
}
|
|
2980
|
+
return o;
|
|
2981
|
+
}, [columns, colWidths, rowSelection, expandable]);
|
|
2982
|
+
const fixedRightOffsets = useMemo3(() => {
|
|
2983
|
+
const o = {};
|
|
2984
|
+
let right = 0;
|
|
2985
|
+
for (let i = columns.length - 1; i >= 0; i--) {
|
|
2986
|
+
if (columns[i].fixed === "right") {
|
|
2987
|
+
o[columns[i].key] = right;
|
|
2988
|
+
right += colWidths[columns[i].key] ?? columns[i].width ?? DEFAULT_COL_WIDTH;
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2991
|
+
return o;
|
|
2992
|
+
}, [columns, colWidths]);
|
|
2993
|
+
const fixedStyle = (col, isHeader) => getFixedStyle(col, fixedLeftOffsets, fixedRightOffsets, isHeader);
|
|
2994
|
+
const allSelected = rowSelection ? visibleRows.length > 0 && visibleRows.every((r) => rowSelection.selectedKeys.includes(r.id)) : false;
|
|
2995
|
+
const someSelected = rowSelection ? visibleRows.some((r) => rowSelection.selectedKeys.includes(r.id)) && !allSelected : false;
|
|
2996
|
+
const spanMap = useMemo3(() => computeSpanMap(columns, flatRows), [columns, flatRows]);
|
|
2997
|
+
const hiddenCells = useMemo3(
|
|
2998
|
+
() => computeHiddenCells(columns, flatRows, spanMap),
|
|
2999
|
+
[columns, flatRows, spanMap]
|
|
3000
|
+
);
|
|
3001
|
+
return {
|
|
3002
|
+
visibleRows,
|
|
3003
|
+
tableState,
|
|
3004
|
+
columns,
|
|
3005
|
+
leafColumns,
|
|
3006
|
+
flatRows,
|
|
3007
|
+
headerRows,
|
|
3008
|
+
hasColumnGroups,
|
|
3009
|
+
t,
|
|
3010
|
+
// Multi-sort
|
|
3011
|
+
sorts,
|
|
3012
|
+
getSortIndex,
|
|
3013
|
+
getSortDirection,
|
|
3014
|
+
handleSort,
|
|
3015
|
+
// Selection
|
|
3016
|
+
allSelected,
|
|
3017
|
+
someSelected,
|
|
3018
|
+
handleSelectAll,
|
|
3019
|
+
handleSelectRow,
|
|
3020
|
+
// Expand
|
|
3021
|
+
expandedKeys,
|
|
3022
|
+
handleToggleExpand,
|
|
3023
|
+
// Tree
|
|
3024
|
+
isTreeMode,
|
|
3025
|
+
indentSize,
|
|
3026
|
+
treeExpanded,
|
|
3027
|
+
handleToggleTreeExpand,
|
|
3028
|
+
// Filters
|
|
3029
|
+
filterState: {
|
|
3030
|
+
activeFilters,
|
|
3031
|
+
filterSearchText,
|
|
3032
|
+
openFilterDropdown,
|
|
3033
|
+
advancedFilters,
|
|
3034
|
+
filterAnchor
|
|
3035
|
+
},
|
|
3036
|
+
filterActions: {
|
|
3037
|
+
setOpenFilterDropdown,
|
|
3038
|
+
handleFilterToggle,
|
|
3039
|
+
handleFilterConfirm,
|
|
3040
|
+
handleFilterReset,
|
|
3041
|
+
handleFilterClose,
|
|
3042
|
+
handleSearchFilterChange,
|
|
3043
|
+
setFilterSearchText,
|
|
3044
|
+
getFilterDropdownProps,
|
|
3045
|
+
setAdvancedFilter,
|
|
3046
|
+
setFilterAnchor
|
|
3047
|
+
},
|
|
3048
|
+
filterRef,
|
|
3049
|
+
// Drag columns
|
|
3050
|
+
dragOver,
|
|
3051
|
+
handleDragStart,
|
|
3052
|
+
handleDragOver,
|
|
3053
|
+
handleDragEnd,
|
|
3054
|
+
handleDrop,
|
|
3055
|
+
setDragOver: () => setDragOver(null),
|
|
3056
|
+
// Resize
|
|
3057
|
+
colWidths,
|
|
3058
|
+
handleResizeStart,
|
|
3059
|
+
// Grid
|
|
3060
|
+
gridTemplate,
|
|
3061
|
+
totalCols,
|
|
3062
|
+
// Fixed
|
|
3063
|
+
fixedStyle,
|
|
3064
|
+
// Span
|
|
3065
|
+
spanMap,
|
|
3066
|
+
hiddenCells,
|
|
3067
|
+
// Search
|
|
3068
|
+
searchText,
|
|
3069
|
+
setSearchText,
|
|
3070
|
+
// Pagination
|
|
3071
|
+
setPage,
|
|
3072
|
+
// Column visibility
|
|
3073
|
+
hiddenSet,
|
|
3074
|
+
toggleColumnVisibility,
|
|
3075
|
+
// Column pin
|
|
3076
|
+
handlePinColumn,
|
|
3077
|
+
// Context menu
|
|
3078
|
+
contextMenu,
|
|
3079
|
+
setContextMenu,
|
|
3080
|
+
// Fullscreen
|
|
3081
|
+
isFullscreen,
|
|
3082
|
+
toggleFullscreen,
|
|
3083
|
+
wrapperRef,
|
|
3084
|
+
// Density
|
|
3085
|
+
density,
|
|
3086
|
+
setDensity,
|
|
3087
|
+
// Group by
|
|
3088
|
+
expandedGroups,
|
|
3089
|
+
toggleGroupExpand,
|
|
3090
|
+
expandAllGroups,
|
|
3091
|
+
collapseAllGroups,
|
|
3092
|
+
// Keyboard
|
|
3093
|
+
focusedCell,
|
|
3094
|
+
setFocusedCell,
|
|
3095
|
+
handleKeyNav,
|
|
3096
|
+
// Auto-resize
|
|
3097
|
+
handleAutoResize,
|
|
3098
|
+
// Aggregation
|
|
3099
|
+
aggregates,
|
|
3100
|
+
// Pinned
|
|
3101
|
+
pinnedTop,
|
|
3102
|
+
pinnedBottom,
|
|
3103
|
+
middleRows
|
|
3104
|
+
};
|
|
3105
|
+
}
|
|
3106
|
+
|
|
3107
|
+
// src/types/slots.ts
|
|
3108
|
+
function slotClass(...parts) {
|
|
3109
|
+
const filtered = parts.filter((p) => typeof p === "string" && p.length > 0);
|
|
3110
|
+
return filtered.length ? filtered.join(" ") : void 0;
|
|
3111
|
+
}
|
|
3112
|
+
function slotStyle(base, custom) {
|
|
3113
|
+
if (!base && !custom) return void 0;
|
|
3114
|
+
if (!base) return custom;
|
|
3115
|
+
if (!custom) return base;
|
|
3116
|
+
return { ...base, ...custom };
|
|
3117
|
+
}
|
|
3118
|
+
|
|
3119
|
+
// src/components/complex/Table/Table.tsx
|
|
3120
|
+
import { Fragment as Fragment4, jsx as jsx10, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
3121
|
+
var DRAG_HANDLE_WIDTH = "32px";
|
|
3122
|
+
var ROW_NUMBER_WIDTH = "48px";
|
|
3123
|
+
function TableInner(props, forwardedRef) {
|
|
3124
|
+
const {
|
|
3125
|
+
rowSelection,
|
|
3126
|
+
expandable,
|
|
3127
|
+
sticky,
|
|
3128
|
+
draggable,
|
|
3129
|
+
searchable,
|
|
3130
|
+
showPagination = true,
|
|
3131
|
+
bordered: borderedProp,
|
|
3132
|
+
size: sizeProp,
|
|
3133
|
+
scroll,
|
|
3134
|
+
summary,
|
|
3135
|
+
onRowClick,
|
|
3136
|
+
onCellEdit,
|
|
3137
|
+
loading: loadingProp,
|
|
3138
|
+
rowClassName,
|
|
3139
|
+
className,
|
|
3140
|
+
style,
|
|
3141
|
+
unstyled,
|
|
3142
|
+
rowDraggable,
|
|
3143
|
+
onRowOrderChange,
|
|
3144
|
+
headerContextMenu,
|
|
3145
|
+
cellContextMenu,
|
|
3146
|
+
columnVisibility,
|
|
3147
|
+
virtual: virtualProp,
|
|
3148
|
+
exportable,
|
|
3149
|
+
onExport,
|
|
3150
|
+
selectionSummary,
|
|
3151
|
+
selectionActions,
|
|
3152
|
+
striped,
|
|
3153
|
+
showSizeChanger,
|
|
3154
|
+
pageSizeOptions,
|
|
3155
|
+
showQuickJumper,
|
|
3156
|
+
showTotal,
|
|
3157
|
+
onPageSizeChange,
|
|
3158
|
+
showRowNumber,
|
|
3159
|
+
footer,
|
|
3160
|
+
fullscreenable,
|
|
3161
|
+
densityToggle,
|
|
3162
|
+
groupBy,
|
|
3163
|
+
groupByOptions,
|
|
3164
|
+
onGroupByChange,
|
|
3165
|
+
keyboardNavigation,
|
|
3166
|
+
emptyContent,
|
|
3167
|
+
printable,
|
|
3168
|
+
exportJSON,
|
|
3169
|
+
highlightOnHover,
|
|
3170
|
+
columnAutoResize,
|
|
3171
|
+
columnPinning,
|
|
3172
|
+
classNames: slotCls,
|
|
3173
|
+
styles: slotSty
|
|
3174
|
+
} = props;
|
|
3175
|
+
const sCls = slotCls ?? {};
|
|
3176
|
+
const sSty = slotSty ?? {};
|
|
3177
|
+
const config = useConfig();
|
|
3178
|
+
const sizeFromProp = sizeProp ?? config.size ?? "middle";
|
|
3179
|
+
const bordered = borderedProp ?? config.bordered ?? false;
|
|
3180
|
+
const loading = loadingProp ?? false;
|
|
3181
|
+
const state = useTableState(props);
|
|
3182
|
+
const tableRef = useRef7(null);
|
|
3183
|
+
const scrollRef = useRef7(null);
|
|
3184
|
+
const effectiveSize = densityToggle ? state.density : sizeFromProp;
|
|
3185
|
+
const rowNumConfig = useMemo4(
|
|
3186
|
+
() => showRowNumber ? typeof showRowNumber === "object" ? showRowNumber : {} : null,
|
|
3187
|
+
[showRowNumber]
|
|
3188
|
+
);
|
|
3189
|
+
const getExportData = useCallback4(() => {
|
|
3190
|
+
const cols = state.columns.map((c) => c.key);
|
|
3191
|
+
const headers = state.columns.map((c) => typeof c.title === "string" ? c.title : c.key);
|
|
3192
|
+
const rows = state.flatRows.filter((r) => !r.__groupRow).map(
|
|
3193
|
+
(row) => cols.map((k) => {
|
|
3194
|
+
const v = row.data[k];
|
|
3195
|
+
return v == null ? "" : String(v);
|
|
3196
|
+
})
|
|
3197
|
+
);
|
|
3198
|
+
return { cols, headers, rows };
|
|
3199
|
+
}, [state.columns, state.flatRows]);
|
|
3200
|
+
const handleExportCSV = useCallback4(() => {
|
|
3201
|
+
const { headers, rows } = getExportData();
|
|
3202
|
+
const data = [headers, ...rows];
|
|
3203
|
+
if (onExport) {
|
|
3204
|
+
onExport(data);
|
|
3205
|
+
} else {
|
|
3206
|
+
downloadCSV(toCSVString(data));
|
|
3207
|
+
}
|
|
3208
|
+
}, [getExportData, onExport]);
|
|
3209
|
+
const handleExportJSON = useCallback4(() => {
|
|
3210
|
+
const { headers, rows } = getExportData();
|
|
3211
|
+
downloadJSON(toJSONString(headers, rows));
|
|
3212
|
+
}, [getExportData]);
|
|
3213
|
+
const handleCopy = useCallback4(async () => {
|
|
3214
|
+
const { headers, rows } = getExportData();
|
|
3215
|
+
await copyToClipboard(toTSVString([headers, ...rows]));
|
|
3216
|
+
}, [getExportData]);
|
|
3217
|
+
const printOptionsFromProp = useMemo4(() => {
|
|
3218
|
+
if (typeof printable === "object" && printable !== null) {
|
|
3219
|
+
return { fileName: printable.fileName };
|
|
3220
|
+
}
|
|
3221
|
+
return {};
|
|
3222
|
+
}, [printable]);
|
|
3223
|
+
const doPrint = useCallback4(
|
|
3224
|
+
(opts) => {
|
|
3225
|
+
printElement(tableRef.current, { ...printOptionsFromProp, ...opts ?? {} });
|
|
3226
|
+
},
|
|
3227
|
+
[printOptionsFromProp]
|
|
3228
|
+
);
|
|
3229
|
+
const handlePrint = useCallback4(() => {
|
|
3230
|
+
doPrint();
|
|
3231
|
+
}, [doPrint]);
|
|
3232
|
+
useImperativeHandle(forwardedRef, () => ({ print: doPrint }), [doPrint]);
|
|
3233
|
+
const gridTemplate = useMemo4(() => {
|
|
3234
|
+
const parts = [];
|
|
3235
|
+
if (rowDraggable) parts.push(DRAG_HANDLE_WIDTH);
|
|
3236
|
+
if (rowNumConfig) parts.push(rowNumConfig.width ? `${rowNumConfig.width}px` : ROW_NUMBER_WIDTH);
|
|
3237
|
+
parts.push(state.gridTemplate);
|
|
3238
|
+
return parts.join(" ");
|
|
3239
|
+
}, [rowDraggable, rowNumConfig, state.gridTemplate]);
|
|
3240
|
+
const totalCols = state.totalCols + (rowDraggable ? 1 : 0) + (rowNumConfig ? 1 : 0);
|
|
3241
|
+
const virtualConfig = virtualProp ? {
|
|
3242
|
+
rowHeight: typeof virtualProp === "object" ? virtualProp.rowHeight ?? 40 : 40,
|
|
3243
|
+
estimateRowHeight: typeof virtualProp === "object" ? virtualProp.estimateRowHeight : void 0,
|
|
3244
|
+
overscan: typeof virtualProp === "object" ? virtualProp.overscan ?? 5 : 5,
|
|
3245
|
+
height: typeof virtualProp === "object" ? virtualProp.height : void 0
|
|
3246
|
+
} : null;
|
|
3247
|
+
const virtualFixedRowHeight = virtualConfig && typeof virtualConfig.rowHeight === "number" && virtualConfig.estimateRowHeight == null ? virtualConfig.rowHeight : null;
|
|
3248
|
+
if (unstyled) {
|
|
3249
|
+
return /* @__PURE__ */ jsxs10("div", { className, style, role: "table", children: [
|
|
3250
|
+
/* @__PURE__ */ jsx10("div", { role: "rowgroup", children: /* @__PURE__ */ jsx10("div", { role: "row", children: state.columns.map((col) => /* @__PURE__ */ jsx10(
|
|
3251
|
+
"span",
|
|
3252
|
+
{
|
|
3253
|
+
role: "columnheader",
|
|
3254
|
+
onClick: (e) => state.handleSort(col, e.shiftKey),
|
|
3255
|
+
children: col.title
|
|
3256
|
+
},
|
|
3257
|
+
col.key
|
|
3258
|
+
)) }) }),
|
|
3259
|
+
/* @__PURE__ */ jsx10("div", { role: "rowgroup", children: state.flatRows.map((row) => /* @__PURE__ */ jsx10("div", { role: "row", children: state.columns.map((col) => /* @__PURE__ */ jsx10("span", { role: "cell", children: col.render ? col.render(row.data[col.key], row.data, row.id) : String(row.data[col.key] ?? "") }, col.key)) }, row.id)) })
|
|
3260
|
+
] });
|
|
3261
|
+
}
|
|
3262
|
+
const hasToolbar = searchable || columnVisibility || exportable || exportJSON || fullscreenable || densityToggle || printable || groupBy || groupByOptions && groupByOptions.length > 0;
|
|
3263
|
+
const wrapperCls = [
|
|
3264
|
+
"sg-table-wrapper",
|
|
3265
|
+
`sg-table-${effectiveSize}`,
|
|
3266
|
+
bordered ? "sg-table-bordered" : "",
|
|
3267
|
+
sticky || virtualConfig ? "sg-table-sticky" : "",
|
|
3268
|
+
loading ? "sg-table-loading" : "",
|
|
3269
|
+
striped ? "sg-table-striped" : "",
|
|
3270
|
+
state.isFullscreen ? "sg-table-fullscreen" : "",
|
|
3271
|
+
highlightOnHover === false ? "" : "sg-table-hoverable",
|
|
3272
|
+
sCls.root,
|
|
3273
|
+
className
|
|
3274
|
+
].filter(Boolean).join(" ");
|
|
3275
|
+
const scrollStyle = {};
|
|
3276
|
+
if (scroll?.x) scrollStyle.overflowX = "auto";
|
|
3277
|
+
if (virtualConfig) {
|
|
3278
|
+
scrollStyle.overflowY = "auto";
|
|
3279
|
+
scrollStyle.height = virtualConfig.height ?? scroll?.y ?? 400;
|
|
3280
|
+
} else if (scroll?.y) {
|
|
3281
|
+
scrollStyle.overflowY = "auto";
|
|
3282
|
+
scrollStyle.maxHeight = scroll.y;
|
|
3283
|
+
}
|
|
3284
|
+
const selectedCount = rowSelection?.selectedKeys.length ?? 0;
|
|
3285
|
+
return /* @__PURE__ */ jsxs10(
|
|
3286
|
+
"div",
|
|
3287
|
+
{
|
|
3288
|
+
className: wrapperCls,
|
|
3289
|
+
style: slotStyle(sSty.root, style),
|
|
3290
|
+
ref: (el) => {
|
|
3291
|
+
;
|
|
3292
|
+
tableRef.current = el;
|
|
3293
|
+
state.wrapperRef.current = el;
|
|
3294
|
+
},
|
|
3295
|
+
onKeyDown: keyboardNavigation ? state.handleKeyNav : void 0,
|
|
3296
|
+
tabIndex: keyboardNavigation ? 0 : void 0,
|
|
3297
|
+
children: [
|
|
3298
|
+
hasToolbar && /* @__PURE__ */ jsxs10("div", { className: slotClass("sg-table-toolbar", sCls.toolbar), style: sSty.toolbar, children: [
|
|
3299
|
+
searchable && /* @__PURE__ */ jsx10(
|
|
3300
|
+
Input,
|
|
3301
|
+
{
|
|
3302
|
+
placeholder: state.t.searchPlaceholder,
|
|
3303
|
+
size: "small",
|
|
3304
|
+
value: state.searchText,
|
|
3305
|
+
onChange: state.setSearchText,
|
|
3306
|
+
style: { maxWidth: 240 }
|
|
3307
|
+
}
|
|
3308
|
+
),
|
|
3309
|
+
/* @__PURE__ */ jsxs10("div", { className: "sg-table-toolbar-right", children: [
|
|
3310
|
+
groupByOptions && groupByOptions.length > 0 && /* @__PURE__ */ jsx10(
|
|
3311
|
+
GroupByDropdown,
|
|
3312
|
+
{
|
|
3313
|
+
value: groupBy ?? null,
|
|
3314
|
+
options: groupByOptions,
|
|
3315
|
+
onChange: onGroupByChange ?? (() => {
|
|
3316
|
+
}),
|
|
3317
|
+
t: state.t
|
|
3318
|
+
}
|
|
3319
|
+
),
|
|
3320
|
+
groupBy && /* @__PURE__ */ jsxs10("div", { className: "sg-table-toolbar-group", children: [
|
|
3321
|
+
/* @__PURE__ */ jsx10("button", { className: "sg-table-toolbar-btn", onClick: state.expandAllGroups, children: state.t.groupExpand }),
|
|
3322
|
+
/* @__PURE__ */ jsx10("button", { className: "sg-table-toolbar-btn", onClick: state.collapseAllGroups, children: state.t.groupCollapse })
|
|
3323
|
+
] }),
|
|
3324
|
+
densityToggle && /* @__PURE__ */ jsx10(DensityDropdown, { value: state.density, onChange: state.setDensity, t: state.t }),
|
|
3325
|
+
columnVisibility && /* @__PURE__ */ jsx10(
|
|
3326
|
+
ColumnVisibilityDropdown,
|
|
3327
|
+
{
|
|
3328
|
+
leafColumns: state.leafColumns,
|
|
3329
|
+
hiddenSet: state.hiddenSet,
|
|
3330
|
+
onToggle: state.toggleColumnVisibility,
|
|
3331
|
+
label: state.t.showColumns
|
|
3332
|
+
}
|
|
3333
|
+
),
|
|
3334
|
+
exportable && /* @__PURE__ */ jsxs10(Fragment4, { children: [
|
|
3335
|
+
/* @__PURE__ */ jsx10("button", { className: "sg-table-toolbar-btn", onClick: handleExportCSV, children: state.t.exportCSV }),
|
|
3336
|
+
/* @__PURE__ */ jsx10("button", { className: "sg-table-toolbar-btn", onClick: handleCopy, children: state.t.copyTable })
|
|
3337
|
+
] }),
|
|
3338
|
+
exportJSON && /* @__PURE__ */ jsx10("button", { className: "sg-table-toolbar-btn", onClick: handleExportJSON, children: state.t.exportJSON }),
|
|
3339
|
+
printable && /* @__PURE__ */ jsx10("button", { className: "sg-table-toolbar-btn", onClick: handlePrint, children: state.t.print }),
|
|
3340
|
+
fullscreenable && /* @__PURE__ */ jsx10("button", { className: "sg-table-toolbar-btn", onClick: state.toggleFullscreen, children: state.isFullscreen ? state.t.exitFullscreen : state.t.fullscreen })
|
|
3341
|
+
] })
|
|
3342
|
+
] }),
|
|
3343
|
+
selectionSummary && selectedCount > 0 && /* @__PURE__ */ jsxs10("div", { className: "sg-table-selection-bar", children: [
|
|
3344
|
+
/* @__PURE__ */ jsx10("span", { className: "sg-table-selection-count", children: state.t.selectedRows(selectedCount) }),
|
|
3345
|
+
selectionActions?.map((action) => /* @__PURE__ */ jsx10(
|
|
3346
|
+
"button",
|
|
3347
|
+
{
|
|
3348
|
+
className: `sg-table-selection-action${action.danger ? " sg-table-selection-action-danger" : ""}`,
|
|
3349
|
+
onClick: () => action.onClick(
|
|
3350
|
+
rowSelection.selectedKeys,
|
|
3351
|
+
state.visibleRows.filter((r) => rowSelection.selectedKeys.includes(r.id)).map((r) => r.data)
|
|
3352
|
+
),
|
|
3353
|
+
children: action.label
|
|
3354
|
+
},
|
|
3355
|
+
action.key
|
|
3356
|
+
)),
|
|
3357
|
+
/* @__PURE__ */ jsx10(
|
|
3358
|
+
"button",
|
|
3359
|
+
{
|
|
3360
|
+
className: "sg-table-selection-clear",
|
|
3361
|
+
onClick: () => rowSelection?.onChange([], []),
|
|
3362
|
+
children: "\u2715"
|
|
3363
|
+
}
|
|
3364
|
+
)
|
|
3365
|
+
] }),
|
|
3366
|
+
/* @__PURE__ */ jsxs10(
|
|
3367
|
+
"div",
|
|
3368
|
+
{
|
|
3369
|
+
ref: scrollRef,
|
|
3370
|
+
className: slotClass("sg-table-scroll", scroll?.x ? "sg-table-scroll-x" : "", sCls.scroll),
|
|
3371
|
+
style: slotStyle(
|
|
3372
|
+
Object.keys(scrollStyle).length > 0 ? scrollStyle : void 0,
|
|
3373
|
+
sSty.scroll
|
|
3374
|
+
),
|
|
3375
|
+
children: [
|
|
3376
|
+
state.pinnedTop.length > 0 && /* @__PURE__ */ jsx10(
|
|
3377
|
+
"div",
|
|
3378
|
+
{
|
|
3379
|
+
className: "sg-table-pinned-top",
|
|
3380
|
+
style: { gridTemplateColumns: gridTemplate, minWidth: scroll?.x },
|
|
3381
|
+
children: /* @__PURE__ */ jsx10(
|
|
3382
|
+
TableBody,
|
|
3383
|
+
{
|
|
3384
|
+
columns: state.columns,
|
|
3385
|
+
flatRows: state.pinnedTop,
|
|
3386
|
+
rowSelection,
|
|
3387
|
+
expandable,
|
|
3388
|
+
isTreeMode: state.isTreeMode,
|
|
3389
|
+
indentSize: state.indentSize,
|
|
3390
|
+
treeExpanded: state.treeExpanded,
|
|
3391
|
+
expandedKeys: state.expandedKeys,
|
|
3392
|
+
totalCols,
|
|
3393
|
+
spanMap: state.spanMap,
|
|
3394
|
+
hiddenCells: state.hiddenCells,
|
|
3395
|
+
t: state.t,
|
|
3396
|
+
rowClassName,
|
|
3397
|
+
fixedStyle: state.fixedStyle,
|
|
3398
|
+
onRowClick,
|
|
3399
|
+
onCellEdit,
|
|
3400
|
+
onSelectRow: state.handleSelectRow,
|
|
3401
|
+
onToggleExpand: state.handleToggleExpand,
|
|
3402
|
+
onToggleTreeExpand: state.handleToggleTreeExpand,
|
|
3403
|
+
onContextMenu: state.setContextMenu,
|
|
3404
|
+
striped: false,
|
|
3405
|
+
isPinnedSection: true,
|
|
3406
|
+
slotClassNames: sCls,
|
|
3407
|
+
slotStyles: sSty
|
|
3408
|
+
}
|
|
3409
|
+
)
|
|
3410
|
+
}
|
|
3411
|
+
),
|
|
3412
|
+
/* @__PURE__ */ jsxs10(
|
|
3413
|
+
"div",
|
|
3414
|
+
{
|
|
3415
|
+
className: slotClass(
|
|
3416
|
+
"sg-table-grid",
|
|
3417
|
+
virtualFixedRowHeight != null ? "sg-table-grid-virtual-fixed" : "",
|
|
3418
|
+
sCls.grid
|
|
3419
|
+
),
|
|
3420
|
+
style: slotStyle(
|
|
3421
|
+
{
|
|
3422
|
+
gridTemplateColumns: gridTemplate,
|
|
3423
|
+
minWidth: scroll?.x,
|
|
3424
|
+
...virtualFixedRowHeight != null ? {
|
|
3425
|
+
["--sg-virtual-row-height"]: `${virtualFixedRowHeight}px`
|
|
3426
|
+
} : null
|
|
3427
|
+
},
|
|
3428
|
+
sSty.grid
|
|
3429
|
+
),
|
|
3430
|
+
role: "table",
|
|
3431
|
+
children: [
|
|
3432
|
+
/* @__PURE__ */ jsx10(
|
|
3433
|
+
TableHeader,
|
|
3434
|
+
{
|
|
3435
|
+
columns: state.columns,
|
|
3436
|
+
headerRows: state.headerRows,
|
|
3437
|
+
hasColumnGroups: state.hasColumnGroups,
|
|
3438
|
+
rowSelection,
|
|
3439
|
+
expandable,
|
|
3440
|
+
draggable,
|
|
3441
|
+
allSelected: state.allSelected,
|
|
3442
|
+
someSelected: state.someSelected,
|
|
3443
|
+
dragOver: state.dragOver,
|
|
3444
|
+
t: state.t,
|
|
3445
|
+
fixedStyle: state.fixedStyle,
|
|
3446
|
+
onSort: state.handleSort,
|
|
3447
|
+
onSelectAll: state.handleSelectAll,
|
|
3448
|
+
onDragStart: state.handleDragStart,
|
|
3449
|
+
onDragOver: state.handleDragOver,
|
|
3450
|
+
onDragLeave: state.setDragOver,
|
|
3451
|
+
onDrop: state.handleDrop,
|
|
3452
|
+
onDragEnd: state.handleDragEnd,
|
|
3453
|
+
onResizeStart: state.handleResizeStart,
|
|
3454
|
+
filterState: state.filterState,
|
|
3455
|
+
filterActions: state.filterActions,
|
|
3456
|
+
filterRef: state.filterRef,
|
|
3457
|
+
sorts: state.sorts,
|
|
3458
|
+
getSortIndex: state.getSortIndex,
|
|
3459
|
+
getSortDirection: state.getSortDirection,
|
|
3460
|
+
headerContextMenu,
|
|
3461
|
+
onContextMenu: state.setContextMenu,
|
|
3462
|
+
showRowNumber: !!rowNumConfig,
|
|
3463
|
+
rowDraggable,
|
|
3464
|
+
columnPinning,
|
|
3465
|
+
onPinColumn: state.handlePinColumn,
|
|
3466
|
+
onAutoResize: columnAutoResize ? state.handleAutoResize : void 0,
|
|
3467
|
+
slotClassNames: sCls,
|
|
3468
|
+
slotStyles: sSty
|
|
3469
|
+
}
|
|
3470
|
+
),
|
|
3471
|
+
virtualConfig ? /* @__PURE__ */ jsx10(
|
|
3472
|
+
VirtualTableBody,
|
|
3473
|
+
{
|
|
3474
|
+
columns: state.columns,
|
|
3475
|
+
flatRows: state.flatRows,
|
|
3476
|
+
rowHeight: virtualConfig.rowHeight,
|
|
3477
|
+
estimateRowHeight: virtualConfig.estimateRowHeight,
|
|
3478
|
+
overscan: virtualConfig.overscan,
|
|
3479
|
+
scrollContainerRef: scrollRef,
|
|
3480
|
+
rowSelection,
|
|
3481
|
+
expandable,
|
|
3482
|
+
isTreeMode: state.isTreeMode,
|
|
3483
|
+
indentSize: state.indentSize,
|
|
3484
|
+
treeExpanded: state.treeExpanded,
|
|
3485
|
+
expandedKeys: state.expandedKeys,
|
|
3486
|
+
totalCols,
|
|
3487
|
+
spanMap: state.spanMap,
|
|
3488
|
+
hiddenCells: state.hiddenCells,
|
|
3489
|
+
t: state.t,
|
|
3490
|
+
rowClassName,
|
|
3491
|
+
fixedStyle: state.fixedStyle,
|
|
3492
|
+
onRowClick,
|
|
3493
|
+
onCellEdit,
|
|
3494
|
+
onSelectRow: state.handleSelectRow,
|
|
3495
|
+
onToggleExpand: state.handleToggleExpand,
|
|
3496
|
+
onToggleTreeExpand: state.handleToggleTreeExpand,
|
|
3497
|
+
rowDraggable,
|
|
3498
|
+
showRowNumber: !!rowNumConfig,
|
|
3499
|
+
cellContextMenu,
|
|
3500
|
+
onContextMenu: state.setContextMenu,
|
|
3501
|
+
striped,
|
|
3502
|
+
groupBy,
|
|
3503
|
+
onToggleGroup: state.toggleGroupExpand,
|
|
3504
|
+
focusedCell: state.focusedCell,
|
|
3505
|
+
onFocusCell: state.setFocusedCell,
|
|
3506
|
+
keyboardNavigation,
|
|
3507
|
+
emptyContent,
|
|
3508
|
+
slotClassNames: sCls,
|
|
3509
|
+
slotStyles: sSty
|
|
3510
|
+
}
|
|
3511
|
+
) : /* @__PURE__ */ jsx10(
|
|
3512
|
+
TableBody,
|
|
3513
|
+
{
|
|
3514
|
+
columns: state.columns,
|
|
3515
|
+
flatRows: state.flatRows,
|
|
3516
|
+
rowSelection,
|
|
3517
|
+
expandable,
|
|
3518
|
+
isTreeMode: state.isTreeMode,
|
|
3519
|
+
indentSize: state.indentSize,
|
|
3520
|
+
treeExpanded: state.treeExpanded,
|
|
3521
|
+
expandedKeys: state.expandedKeys,
|
|
3522
|
+
totalCols,
|
|
3523
|
+
spanMap: state.spanMap,
|
|
3524
|
+
hiddenCells: state.hiddenCells,
|
|
3525
|
+
t: state.t,
|
|
3526
|
+
rowClassName,
|
|
3527
|
+
fixedStyle: state.fixedStyle,
|
|
3528
|
+
onRowClick,
|
|
3529
|
+
onCellEdit,
|
|
3530
|
+
onSelectRow: state.handleSelectRow,
|
|
3531
|
+
onToggleExpand: state.handleToggleExpand,
|
|
3532
|
+
onToggleTreeExpand: state.handleToggleTreeExpand,
|
|
3533
|
+
rowDraggable,
|
|
3534
|
+
onRowOrderChange,
|
|
3535
|
+
cellContextMenu,
|
|
3536
|
+
onContextMenu: state.setContextMenu,
|
|
3537
|
+
striped,
|
|
3538
|
+
showRowNumber: !!rowNumConfig,
|
|
3539
|
+
groupBy,
|
|
3540
|
+
onToggleGroup: state.toggleGroupExpand,
|
|
3541
|
+
focusedCell: state.focusedCell,
|
|
3542
|
+
onFocusCell: state.setFocusedCell,
|
|
3543
|
+
keyboardNavigation,
|
|
3544
|
+
emptyContent,
|
|
3545
|
+
slotClassNames: sCls,
|
|
3546
|
+
slotStyles: sSty
|
|
3547
|
+
}
|
|
3548
|
+
),
|
|
3549
|
+
footer && state.aggregates && /* @__PURE__ */ jsxs10(
|
|
3550
|
+
"div",
|
|
3551
|
+
{
|
|
3552
|
+
className: ["sg-table-footer-row", sCls.footer].filter(Boolean).join(" "),
|
|
3553
|
+
role: "row",
|
|
3554
|
+
style: { display: "contents", ...sSty.footer },
|
|
3555
|
+
children: [
|
|
3556
|
+
rowDraggable && /* @__PURE__ */ jsx10("div", { className: "sg-table-td sg-table-footer-cell", role: "cell" }),
|
|
3557
|
+
rowNumConfig && /* @__PURE__ */ jsx10("div", { className: "sg-table-td sg-table-footer-cell", role: "cell" }),
|
|
3558
|
+
rowSelection && /* @__PURE__ */ jsx10("div", { className: "sg-table-td sg-table-footer-cell", role: "cell" }),
|
|
3559
|
+
expandable && /* @__PURE__ */ jsx10("div", { className: "sg-table-td sg-table-footer-cell", role: "cell" }),
|
|
3560
|
+
state.columns.map((col) => /* @__PURE__ */ jsx10(
|
|
3561
|
+
"div",
|
|
3562
|
+
{
|
|
3563
|
+
className: "sg-table-td sg-table-footer-cell",
|
|
3564
|
+
role: "cell",
|
|
3565
|
+
style: state.fixedStyle(col),
|
|
3566
|
+
children: state.aggregates[col.key] != null ? /* @__PURE__ */ jsxs10("span", { className: "sg-table-aggregate-value", children: [
|
|
3567
|
+
/* @__PURE__ */ jsx10("span", { className: "sg-table-aggregate-label", children: typeof col.aggregate === "string" ? state.t[col.aggregate] : "" }),
|
|
3568
|
+
" ",
|
|
3569
|
+
String(state.aggregates[col.key])
|
|
3570
|
+
] }) : null
|
|
3571
|
+
},
|
|
3572
|
+
col.key
|
|
3573
|
+
))
|
|
3574
|
+
]
|
|
3575
|
+
}
|
|
3576
|
+
),
|
|
3577
|
+
summary && state.visibleRows && summary(state.visibleRows).map((cells, ri) => /* @__PURE__ */ jsx10(
|
|
3578
|
+
"div",
|
|
3579
|
+
{
|
|
3580
|
+
className: "sg-table-summary-row",
|
|
3581
|
+
role: "row",
|
|
3582
|
+
style: { display: "contents" },
|
|
3583
|
+
children: cells.map((cell, ci) => /* @__PURE__ */ jsx10(
|
|
3584
|
+
"div",
|
|
3585
|
+
{
|
|
3586
|
+
className: "sg-table-td sg-table-summary-cell",
|
|
3587
|
+
role: "cell",
|
|
3588
|
+
style: {
|
|
3589
|
+
gridColumn: cell.colSpan ? `span ${cell.colSpan}` : void 0,
|
|
3590
|
+
textAlign: cell.align
|
|
3591
|
+
},
|
|
3592
|
+
children: cell.content
|
|
3593
|
+
},
|
|
3594
|
+
ci
|
|
3595
|
+
))
|
|
3596
|
+
},
|
|
3597
|
+
`sum-${ri}`
|
|
3598
|
+
))
|
|
3599
|
+
]
|
|
3600
|
+
}
|
|
3601
|
+
),
|
|
3602
|
+
state.pinnedBottom.length > 0 && /* @__PURE__ */ jsx10(
|
|
3603
|
+
"div",
|
|
3604
|
+
{
|
|
3605
|
+
className: "sg-table-pinned-bottom",
|
|
3606
|
+
style: { gridTemplateColumns: gridTemplate, minWidth: scroll?.x },
|
|
3607
|
+
children: /* @__PURE__ */ jsx10(
|
|
3608
|
+
TableBody,
|
|
3609
|
+
{
|
|
3610
|
+
columns: state.columns,
|
|
3611
|
+
flatRows: state.pinnedBottom,
|
|
3612
|
+
rowSelection,
|
|
3613
|
+
expandable,
|
|
3614
|
+
isTreeMode: state.isTreeMode,
|
|
3615
|
+
indentSize: state.indentSize,
|
|
3616
|
+
treeExpanded: state.treeExpanded,
|
|
3617
|
+
expandedKeys: state.expandedKeys,
|
|
3618
|
+
totalCols,
|
|
3619
|
+
spanMap: state.spanMap,
|
|
3620
|
+
hiddenCells: state.hiddenCells,
|
|
3621
|
+
t: state.t,
|
|
3622
|
+
rowClassName,
|
|
3623
|
+
fixedStyle: state.fixedStyle,
|
|
3624
|
+
onRowClick,
|
|
3625
|
+
onCellEdit,
|
|
3626
|
+
onSelectRow: state.handleSelectRow,
|
|
3627
|
+
onToggleExpand: state.handleToggleExpand,
|
|
3628
|
+
onToggleTreeExpand: state.handleToggleTreeExpand,
|
|
3629
|
+
onContextMenu: state.setContextMenu,
|
|
3630
|
+
striped: false,
|
|
3631
|
+
isPinnedSection: true,
|
|
3632
|
+
slotClassNames: sCls,
|
|
3633
|
+
slotStyles: sSty
|
|
3634
|
+
}
|
|
3635
|
+
)
|
|
3636
|
+
}
|
|
3637
|
+
)
|
|
3638
|
+
]
|
|
3639
|
+
}
|
|
3640
|
+
),
|
|
3641
|
+
/* @__PURE__ */ jsx10(ContextMenu, { state: state.contextMenu, onClose: () => state.setContextMenu(null) }),
|
|
3642
|
+
loading && /* @__PURE__ */ jsx10("div", { className: "sg-table-loading-mask", children: /* @__PURE__ */ jsx10(Spin, { size: "large" }) }),
|
|
3643
|
+
showPagination && state.tableState.totalPages > 1 && /* @__PURE__ */ jsxs10("div", { className: slotClass("sg-table-pagination", sCls.pagination), style: sSty.pagination, children: [
|
|
3644
|
+
/* @__PURE__ */ jsx10("span", { className: "sg-table-pagination-total", children: state.t.totalRows(state.tableState.filteredRows) }),
|
|
3645
|
+
/* @__PURE__ */ jsx10(
|
|
3646
|
+
Pagination,
|
|
3647
|
+
{
|
|
3648
|
+
current: state.tableState.page,
|
|
3649
|
+
total: state.tableState.filteredRows,
|
|
3650
|
+
pageSize: state.tableState.pageSize,
|
|
3651
|
+
onChange: state.setPage,
|
|
3652
|
+
showSizeChanger,
|
|
3653
|
+
pageSizeOptions,
|
|
3654
|
+
showQuickJumper,
|
|
3655
|
+
showTotal,
|
|
3656
|
+
onPageSizeChange
|
|
3657
|
+
}
|
|
3658
|
+
)
|
|
3659
|
+
] })
|
|
3660
|
+
]
|
|
3661
|
+
}
|
|
3662
|
+
);
|
|
3663
|
+
}
|
|
3664
|
+
var Table = forwardRef(TableInner);
|
|
3665
|
+
Table.displayName = "Table";
|
|
3666
|
+
function ColumnVisibilityDropdown({
|
|
3667
|
+
leafColumns,
|
|
3668
|
+
hiddenSet,
|
|
3669
|
+
onToggle,
|
|
3670
|
+
label
|
|
3671
|
+
}) {
|
|
3672
|
+
const [open, setOpen] = React5.useState(false);
|
|
3673
|
+
const ref = React5.useRef(null);
|
|
3674
|
+
React5.useEffect(() => {
|
|
3675
|
+
if (!open) return;
|
|
3676
|
+
const h = (e) => {
|
|
3677
|
+
if (ref.current && !ref.current.contains(e.target)) setOpen(false);
|
|
3678
|
+
};
|
|
3679
|
+
document.addEventListener("mousedown", h);
|
|
3680
|
+
return () => document.removeEventListener("mousedown", h);
|
|
3681
|
+
}, [open]);
|
|
3682
|
+
return /* @__PURE__ */ jsxs10("div", { ref, style: { position: "relative" }, children: [
|
|
3683
|
+
/* @__PURE__ */ jsx10("button", { className: "sg-table-toolbar-btn", onClick: () => setOpen(!open), children: label }),
|
|
3684
|
+
open && /* @__PURE__ */ jsx10("div", { className: "sg-table-col-visibility-dropdown", children: leafColumns.map((col) => /* @__PURE__ */ jsxs10("label", { className: "sg-table-col-visibility-item", children: [
|
|
3685
|
+
/* @__PURE__ */ jsx10(Checkbox, { checked: !hiddenSet.has(col.key), onChange: () => onToggle(col.key) }),
|
|
3686
|
+
/* @__PURE__ */ jsx10("span", { children: typeof col.title === "string" ? col.title : col.key })
|
|
3687
|
+
] }, col.key)) })
|
|
3688
|
+
] });
|
|
3689
|
+
}
|
|
3690
|
+
function GroupByDropdown({
|
|
3691
|
+
value,
|
|
3692
|
+
options,
|
|
3693
|
+
onChange,
|
|
3694
|
+
t
|
|
3695
|
+
}) {
|
|
3696
|
+
const [open, setOpen] = React5.useState(false);
|
|
3697
|
+
const ref = React5.useRef(null);
|
|
3698
|
+
React5.useEffect(() => {
|
|
3699
|
+
if (!open) return;
|
|
3700
|
+
const h = (e) => {
|
|
3701
|
+
if (ref.current && !ref.current.contains(e.target)) setOpen(false);
|
|
3702
|
+
};
|
|
3703
|
+
document.addEventListener("mousedown", h);
|
|
3704
|
+
return () => document.removeEventListener("mousedown", h);
|
|
3705
|
+
}, [open]);
|
|
3706
|
+
const current = value ? options.find((o) => o.key === value) : null;
|
|
3707
|
+
return /* @__PURE__ */ jsxs10("div", { ref, style: { position: "relative" }, children: [
|
|
3708
|
+
/* @__PURE__ */ jsxs10("button", { className: "sg-table-toolbar-btn", onClick: () => setOpen(!open), children: [
|
|
3709
|
+
t.groupByLabel,
|
|
3710
|
+
current ? `: ${typeof current.label === "string" ? current.label : current.key}` : ""
|
|
3711
|
+
] }),
|
|
3712
|
+
open && /* @__PURE__ */ jsxs10("div", { className: "sg-table-group-by-dropdown", role: "menu", children: [
|
|
3713
|
+
/* @__PURE__ */ jsx10(
|
|
3714
|
+
"button",
|
|
3715
|
+
{
|
|
3716
|
+
type: "button",
|
|
3717
|
+
className: `sg-table-group-by-option${value === null ? " sg-table-group-by-active" : ""}`,
|
|
3718
|
+
onClick: () => {
|
|
3719
|
+
onChange(null);
|
|
3720
|
+
setOpen(false);
|
|
3721
|
+
},
|
|
3722
|
+
children: t.groupByNone
|
|
3723
|
+
}
|
|
3724
|
+
),
|
|
3725
|
+
options.map((opt) => /* @__PURE__ */ jsx10(
|
|
3726
|
+
"button",
|
|
3727
|
+
{
|
|
3728
|
+
type: "button",
|
|
3729
|
+
className: `sg-table-group-by-option${value === opt.key ? " sg-table-group-by-active" : ""}`,
|
|
3730
|
+
onClick: () => {
|
|
3731
|
+
onChange(opt.key);
|
|
3732
|
+
setOpen(false);
|
|
3733
|
+
},
|
|
3734
|
+
children: opt.label
|
|
3735
|
+
},
|
|
3736
|
+
opt.key
|
|
3737
|
+
))
|
|
3738
|
+
] })
|
|
3739
|
+
] });
|
|
3740
|
+
}
|
|
3741
|
+
function DensityDropdown({
|
|
3742
|
+
value,
|
|
3743
|
+
onChange,
|
|
3744
|
+
t
|
|
3745
|
+
}) {
|
|
3746
|
+
const [open, setOpen] = React5.useState(false);
|
|
3747
|
+
const ref = React5.useRef(null);
|
|
3748
|
+
React5.useEffect(() => {
|
|
3749
|
+
if (!open) return;
|
|
3750
|
+
const h = (e) => {
|
|
3751
|
+
if (ref.current && !ref.current.contains(e.target)) setOpen(false);
|
|
3752
|
+
};
|
|
3753
|
+
document.addEventListener("mousedown", h);
|
|
3754
|
+
return () => document.removeEventListener("mousedown", h);
|
|
3755
|
+
}, [open]);
|
|
3756
|
+
const options = [
|
|
3757
|
+
{ key: "small", label: t.densitySmall },
|
|
3758
|
+
{ key: "middle", label: t.densityMiddle },
|
|
3759
|
+
{ key: "large", label: t.densityLarge }
|
|
3760
|
+
];
|
|
3761
|
+
return /* @__PURE__ */ jsxs10("div", { ref, style: { position: "relative" }, children: [
|
|
3762
|
+
/* @__PURE__ */ jsx10("button", { className: "sg-table-toolbar-btn", onClick: () => setOpen(!open), children: t.density }),
|
|
3763
|
+
open && /* @__PURE__ */ jsx10("div", { className: "sg-table-density-dropdown", children: options.map((opt) => /* @__PURE__ */ jsx10(
|
|
3764
|
+
"button",
|
|
3765
|
+
{
|
|
3766
|
+
className: `sg-table-density-option${value === opt.key ? " sg-table-density-active" : ""}`,
|
|
3767
|
+
onClick: () => {
|
|
3768
|
+
onChange(opt.key);
|
|
3769
|
+
setOpen(false);
|
|
3770
|
+
},
|
|
3771
|
+
children: opt.label
|
|
3772
|
+
},
|
|
3773
|
+
opt.key
|
|
3774
|
+
)) })
|
|
3775
|
+
] });
|
|
3776
|
+
}
|
|
3777
|
+
|
|
3778
|
+
export {
|
|
3779
|
+
Pagination,
|
|
3780
|
+
Select,
|
|
3781
|
+
toCSVString,
|
|
3782
|
+
toTSVString,
|
|
3783
|
+
toJSONString,
|
|
3784
|
+
downloadCSV,
|
|
3785
|
+
downloadJSON,
|
|
3786
|
+
copyToClipboard,
|
|
3787
|
+
printTable,
|
|
3788
|
+
useTable,
|
|
3789
|
+
buildPageRule,
|
|
3790
|
+
buildPrintHtml,
|
|
3791
|
+
printElement,
|
|
3792
|
+
Table
|
|
3793
|
+
};
|
|
3794
|
+
//# sourceMappingURL=chunk-NXB3VAVF.js.map
|