@lobehub/ui 5.61.1 → 5.62.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/es/base-ui/ProTable/ColumnSetting.mjs +156 -0
- package/es/base-ui/ProTable/ColumnSetting.mjs.map +1 -0
- package/es/base-ui/ProTable/FieldControl.mjs +108 -0
- package/es/base-ui/ProTable/FieldControl.mjs.map +1 -0
- package/es/base-ui/ProTable/LightFilter.mjs +71 -0
- package/es/base-ui/ProTable/LightFilter.mjs.map +1 -0
- package/es/base-ui/ProTable/OptionPopover.mjs +21 -0
- package/es/base-ui/ProTable/OptionPopover.mjs.map +1 -0
- package/es/base-ui/ProTable/ProTable.d.mts +13 -0
- package/es/base-ui/ProTable/ProTable.mjs +651 -0
- package/es/base-ui/ProTable/ProTable.mjs.map +1 -0
- package/es/base-ui/ProTable/SearchForm.mjs +138 -0
- package/es/base-ui/ProTable/SearchForm.mjs.map +1 -0
- package/es/base-ui/ProTable/index.d.mts +3 -0
- package/es/base-ui/ProTable/index.mjs +1 -0
- package/es/base-ui/ProTable/renderValue.mjs +118 -0
- package/es/base-ui/ProTable/renderValue.mjs.map +1 -0
- package/es/base-ui/ProTable/style.mjs +373 -0
- package/es/base-ui/ProTable/style.mjs.map +1 -0
- package/es/base-ui/ProTable/type.d.mts +343 -0
- package/es/base-ui/ProTable/useFetchData.mjs +98 -0
- package/es/base-ui/ProTable/useFetchData.mjs.map +1 -0
- package/es/base-ui/ProTable/useSearchForm.mjs +151 -0
- package/es/base-ui/ProTable/useSearchForm.mjs.map +1 -0
- package/es/base-ui/ProTable/utils.mjs +102 -0
- package/es/base-ui/ProTable/utils.mjs.map +1 -0
- package/es/base-ui/Table/Table.mjs +6 -2
- package/es/base-ui/Table/Table.mjs.map +1 -1
- package/es/base-ui/Text/style.d.mts +1 -1
- package/es/dashboard/ConsoleShell/style.mjs +3 -1
- package/es/dashboard/ConsoleShell/style.mjs.map +1 -1
- package/es/dashboard/MetricStrip/MetricCell.mjs +25 -14
- package/es/dashboard/MetricStrip/MetricCell.mjs.map +1 -1
- package/es/dashboard/MetricStrip/style.mjs +14 -0
- package/es/dashboard/MetricStrip/style.mjs.map +1 -1
- package/es/dashboard/MetricStrip/type.d.mts +2 -0
- package/es/dashboard/StatCard/StatCard.d.mts +1 -1
- package/es/dashboard/StatCard/StatCard.mjs +2 -1
- package/es/dashboard/StatCard/StatCard.mjs.map +1 -1
- package/es/dashboard/StatCard/type.d.mts +2 -0
- package/es/dashboard/Surface/style.d.mts +3 -2
- package/es/dashboard/Surface/style.mjs +7 -3
- package/es/dashboard/Surface/style.mjs.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,651 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import Button from "../Button/Button.mjs";
|
|
3
|
+
import ActionIcon from "../ActionIcon/ActionIcon.mjs";
|
|
4
|
+
import ActionIconGroup from "../../ActionIconGroup/ActionIconGroup.mjs";
|
|
5
|
+
import Input_default from "../Input/Input.mjs";
|
|
6
|
+
import { useEventCallback } from "../../hooks/useEventCallback.mjs";
|
|
7
|
+
import Table from "../Table/Table.mjs";
|
|
8
|
+
import { PRO_PREFIX_CLS, styles } from "./style.mjs";
|
|
9
|
+
import ColumnSetting from "./ColumnSetting.mjs";
|
|
10
|
+
import { getByPath, getProColumnKey, isEmptyValue, readPersistedState, resolveValueEnum, resolveValueType, valueEnumToList, writePersistedState } from "./utils.mjs";
|
|
11
|
+
import { getSearchFields, useSearchForm } from "./useSearchForm.mjs";
|
|
12
|
+
import LightFilter from "./LightFilter.mjs";
|
|
13
|
+
import OptionPopover from "./OptionPopover.mjs";
|
|
14
|
+
import { CopyableText, renderValue } from "./renderValue.mjs";
|
|
15
|
+
import SearchForm from "./SearchForm.mjs";
|
|
16
|
+
import { useFetchData } from "./useFetchData.mjs";
|
|
17
|
+
import { useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
18
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
+
import { cx } from "antd-style";
|
|
20
|
+
import { Check, CircleHelp, Fullscreen, Minimize, RotateCw, Rows3, Settings } from "lucide-react";
|
|
21
|
+
//#region src/base-ui/ProTable/ProTable.tsx
|
|
22
|
+
const DEFAULT_PRO_TABLE_LOCALE = {
|
|
23
|
+
alertClear: "Clear",
|
|
24
|
+
alertSelected: (count) => `${count} selected`,
|
|
25
|
+
collapse: "Collapse",
|
|
26
|
+
columnSetting: "Column settings",
|
|
27
|
+
columnSettingReset: "Reset",
|
|
28
|
+
columnSettingTitle: "Columns",
|
|
29
|
+
copy: "Copy",
|
|
30
|
+
density: "Density",
|
|
31
|
+
densityLarge: "Large",
|
|
32
|
+
densityMedium: "Medium",
|
|
33
|
+
densitySmall: "Compact",
|
|
34
|
+
expand: "Expand",
|
|
35
|
+
fixedEnd: "Pin to end",
|
|
36
|
+
fixedEndTitle: "Pinned to end",
|
|
37
|
+
fixedStart: "Pin to start",
|
|
38
|
+
fixedStartTitle: "Pinned to start",
|
|
39
|
+
fullScreen: "Full screen",
|
|
40
|
+
moveDown: "Move down",
|
|
41
|
+
moveUp: "Move up",
|
|
42
|
+
noFixed: "Unpin",
|
|
43
|
+
reload: "Reload",
|
|
44
|
+
reset: "Reset",
|
|
45
|
+
search: "Search",
|
|
46
|
+
searchPlaceholder: "Please enter",
|
|
47
|
+
selectPlaceholder: "Please select",
|
|
48
|
+
unfixedTitle: "Not pinned"
|
|
49
|
+
};
|
|
50
|
+
const assignRef = (ref, value) => {
|
|
51
|
+
if (!ref) return;
|
|
52
|
+
if (typeof ref === "function") ref(value);
|
|
53
|
+
else ref.current = value;
|
|
54
|
+
};
|
|
55
|
+
const stableKey = (value) => {
|
|
56
|
+
try {
|
|
57
|
+
return JSON.stringify(value, (_key, item) => item instanceof Date ? item.toISOString() : item);
|
|
58
|
+
} catch {
|
|
59
|
+
return String(Math.random());
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const isGroup = (column) => !!column.children?.length;
|
|
63
|
+
const ProTable = (props) => {
|
|
64
|
+
const { actionRef, beforeSearchSubmit, cardBordered, className, columnEmptyText = "-", columns: columnsProp = [], columnsState, dataSource, dateFormatter = "string", debounceTime = 10, defaultData, defaultSize, form: formConfig, formRef, ghost: _ghost, headerTitle, loading: loadingProp, locale: localeProp, manualRequest = false, onChange, onDataSourceChange, onLoad, onLoadingChange, onRequestError, onReset, onSizeChange, onSubmit, options, pagination: paginationProp, params, polling, postData, request, rowSelection, search, searchFormRender, size: sizeProp, style, tableAlertOptionRender, tableAlertRender, tableClassName, tableExtraRender, tableRender, tableStyle, toolbar, toolBarRender, tooltip, variant, ...tableProps } = props;
|
|
65
|
+
const locale = {
|
|
66
|
+
...DEFAULT_PRO_TABLE_LOCALE,
|
|
67
|
+
...localeProp
|
|
68
|
+
};
|
|
69
|
+
const rootRef = useRef(null);
|
|
70
|
+
const actionHolderRef = useRef(void 0);
|
|
71
|
+
const [innerSize, setInnerSize] = useState(defaultSize ?? "medium");
|
|
72
|
+
const size = sizeProp ?? innerSize;
|
|
73
|
+
const setSize = (next) => {
|
|
74
|
+
setInnerSize(next);
|
|
75
|
+
onSizeChange?.(next);
|
|
76
|
+
};
|
|
77
|
+
const [fullscreen, setFullscreen] = useState(false);
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (typeof document === "undefined") return;
|
|
80
|
+
const sync = () => setFullscreen(document.fullscreenElement === rootRef.current);
|
|
81
|
+
document.addEventListener("fullscreenchange", sync);
|
|
82
|
+
return () => document.removeEventListener("fullscreenchange", sync);
|
|
83
|
+
}, []);
|
|
84
|
+
const toggleFullScreen = useEventCallback(() => {
|
|
85
|
+
const node = rootRef.current;
|
|
86
|
+
if (!node || typeof document === "undefined") return;
|
|
87
|
+
if (document.fullscreenElement) document.exitFullscreen?.();
|
|
88
|
+
else node.requestFullscreen?.();
|
|
89
|
+
});
|
|
90
|
+
const persistKey = columnsState?.persistenceKey;
|
|
91
|
+
const persistType = columnsState?.persistenceType;
|
|
92
|
+
const defaultColumnsState = useMemo(() => {
|
|
93
|
+
const map = {};
|
|
94
|
+
columnsProp.forEach((column, index) => {
|
|
95
|
+
const key = getProColumnKey(column, index);
|
|
96
|
+
if (column.fixed) map[key] = { fixed: column.fixed };
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
...map,
|
|
100
|
+
...columnsState?.defaultValue
|
|
101
|
+
};
|
|
102
|
+
}, []);
|
|
103
|
+
const [innerColumnsState, setInnerColumnsState] = useState(() => readPersistedState(persistKey, persistType) ?? defaultColumnsState);
|
|
104
|
+
const columnsStateMap = columnsState?.value ?? innerColumnsState;
|
|
105
|
+
const setColumnsStateMap = (next) => {
|
|
106
|
+
setInnerColumnsState(next);
|
|
107
|
+
writePersistedState(persistKey, persistType, next);
|
|
108
|
+
columnsState?.onChange?.(next);
|
|
109
|
+
};
|
|
110
|
+
const resetColumnsState = () => {
|
|
111
|
+
writePersistedState(persistKey, persistType, void 0);
|
|
112
|
+
setInnerColumnsState(defaultColumnsState);
|
|
113
|
+
columnsState?.onChange?.(defaultColumnsState);
|
|
114
|
+
};
|
|
115
|
+
const paginationConfig = paginationProp === false ? false : paginationProp ?? {};
|
|
116
|
+
const [pageInfo, setPageInfoState] = useState(() => ({
|
|
117
|
+
current: paginationConfig && (paginationConfig.current ?? paginationConfig.defaultCurrent) || 1,
|
|
118
|
+
pageSize: paginationConfig && (paginationConfig.pageSize ?? paginationConfig.defaultPageSize) || 10,
|
|
119
|
+
total: 0
|
|
120
|
+
}));
|
|
121
|
+
const mergedPageInfo = {
|
|
122
|
+
...pageInfo,
|
|
123
|
+
...paginationConfig && paginationConfig.current !== void 0 && { current: paginationConfig.current },
|
|
124
|
+
...paginationConfig && paginationConfig.pageSize !== void 0 && { pageSize: paginationConfig.pageSize }
|
|
125
|
+
};
|
|
126
|
+
const setPageInfo = useEventCallback((next) => setPageInfoState((prev) => ({
|
|
127
|
+
...prev,
|
|
128
|
+
...next
|
|
129
|
+
})));
|
|
130
|
+
const [sort, setSort] = useState({});
|
|
131
|
+
const [filter, setFilter] = useState({});
|
|
132
|
+
const searchFields = useMemo(() => getSearchFields(columnsProp), [columnsProp]);
|
|
133
|
+
const [formParams, setFormParams] = useState({});
|
|
134
|
+
const [keyword, setKeyword] = useState(void 0);
|
|
135
|
+
const formReadyRef = useRef(false);
|
|
136
|
+
const handleSubmit = useEventCallback((formatted) => {
|
|
137
|
+
const next = beforeSearchSubmit ? beforeSearchSubmit(formatted) : formatted;
|
|
138
|
+
formReadyRef.current = true;
|
|
139
|
+
setFormParams(next);
|
|
140
|
+
setPageInfo({ current: 1 });
|
|
141
|
+
onSubmit?.(next);
|
|
142
|
+
fetcher.reload();
|
|
143
|
+
});
|
|
144
|
+
const { form } = useSearchForm({
|
|
145
|
+
dateFormatter,
|
|
146
|
+
fields: searchFields,
|
|
147
|
+
initialValues: formConfig?.initialValues,
|
|
148
|
+
onSubmit: handleSubmit,
|
|
149
|
+
onValuesChange: formConfig?.onValuesChange,
|
|
150
|
+
validateOn: formConfig?.validateOn
|
|
151
|
+
});
|
|
152
|
+
const initialFormParams = useMemo(() => form.getFieldsFormatValue(), [form]);
|
|
153
|
+
const effectiveFormParams = formReadyRef.current ? formParams : initialFormParams;
|
|
154
|
+
useImperativeHandle(formRef, () => form, [form]);
|
|
155
|
+
const keywordName = options && typeof options.search === "object" ? options.search.name ?? "keyword" : "keyword";
|
|
156
|
+
const getParams = () => ({
|
|
157
|
+
...effectiveFormParams,
|
|
158
|
+
...params,
|
|
159
|
+
...keyword !== void 0 && keyword !== "" && { [keywordName]: keyword }
|
|
160
|
+
});
|
|
161
|
+
const fetcher = useFetchData({
|
|
162
|
+
debounceTime,
|
|
163
|
+
defaultData,
|
|
164
|
+
depsKey: stableKey([
|
|
165
|
+
effectiveFormParams,
|
|
166
|
+
params,
|
|
167
|
+
keyword,
|
|
168
|
+
sort,
|
|
169
|
+
filter
|
|
170
|
+
]),
|
|
171
|
+
filter,
|
|
172
|
+
getParams,
|
|
173
|
+
manual: manualRequest,
|
|
174
|
+
onDataSourceChange,
|
|
175
|
+
onLoad,
|
|
176
|
+
onLoadingChange,
|
|
177
|
+
onRequestError,
|
|
178
|
+
pageInfo: mergedPageInfo,
|
|
179
|
+
paginated: paginationConfig !== false,
|
|
180
|
+
polling,
|
|
181
|
+
postData,
|
|
182
|
+
request,
|
|
183
|
+
setTotal: (total) => setPageInfo({ total }),
|
|
184
|
+
sort
|
|
185
|
+
});
|
|
186
|
+
const paramsKey = stableKey(params);
|
|
187
|
+
const firstParamsRef = useRef(true);
|
|
188
|
+
useEffect(() => {
|
|
189
|
+
if (firstParamsRef.current) {
|
|
190
|
+
firstParamsRef.current = false;
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
setPageInfo({ current: 1 });
|
|
194
|
+
}, [paramsKey, setPageInfo]);
|
|
195
|
+
const rows = request ? fetcher.data : dataSource ?? defaultData ?? [];
|
|
196
|
+
const loading = loadingProp ?? fetcher.loading;
|
|
197
|
+
const selectionEnabled = !!rowSelection;
|
|
198
|
+
const [innerSelectedKeys, setInnerSelectedKeys] = useState(rowSelection && rowSelection.defaultSelectedRowKeys || []);
|
|
199
|
+
const selectedRowKeys = rowSelection && rowSelection.selectedRowKeys || innerSelectedKeys;
|
|
200
|
+
const selectedRowsCacheRef = useRef(/* @__PURE__ */ new Map());
|
|
201
|
+
const rowKeyProp = tableProps.rowKey ?? "key";
|
|
202
|
+
const getRowKey = useCallback((record, index) => typeof rowKeyProp === "function" ? rowKeyProp(record, index) : record[rowKeyProp], [rowKeyProp]);
|
|
203
|
+
rows.forEach((record, index) => selectedRowsCacheRef.current.set(getRowKey(record, index), record));
|
|
204
|
+
const selectedRows = selectedRowKeys.map((key) => selectedRowsCacheRef.current.get(key)).filter((row) => row !== void 0);
|
|
205
|
+
const clearSelected = useEventCallback(() => {
|
|
206
|
+
setInnerSelectedKeys([]);
|
|
207
|
+
if (rowSelection) rowSelection.onChange?.([], [], { type: "none" });
|
|
208
|
+
});
|
|
209
|
+
const reload = useEventCallback(async (resetPageIndex) => {
|
|
210
|
+
if (resetPageIndex) setPageInfo({ current: 1 });
|
|
211
|
+
await fetcher.reload();
|
|
212
|
+
});
|
|
213
|
+
actionHolderRef.current = {
|
|
214
|
+
clearSelected,
|
|
215
|
+
fullScreen: toggleFullScreen,
|
|
216
|
+
getSortFilter: () => ({
|
|
217
|
+
filter,
|
|
218
|
+
sort
|
|
219
|
+
}),
|
|
220
|
+
nativeElement: rootRef.current,
|
|
221
|
+
pageInfo: mergedPageInfo,
|
|
222
|
+
reload,
|
|
223
|
+
reloadAndRest: async () => {
|
|
224
|
+
clearSelected();
|
|
225
|
+
await reload(true);
|
|
226
|
+
},
|
|
227
|
+
reset: () => {
|
|
228
|
+
form.resetFields();
|
|
229
|
+
const formatted = form.getFieldsFormatValue();
|
|
230
|
+
formReadyRef.current = true;
|
|
231
|
+
setFormParams(beforeSearchSubmit ? beforeSearchSubmit(formatted) : formatted);
|
|
232
|
+
setPageInfo({ current: 1 });
|
|
233
|
+
fetcher.reload();
|
|
234
|
+
},
|
|
235
|
+
setPageInfo
|
|
236
|
+
};
|
|
237
|
+
useEffect(() => {
|
|
238
|
+
assignRef(actionRef, actionHolderRef.current);
|
|
239
|
+
});
|
|
240
|
+
const handleReset = useEventCallback(() => {
|
|
241
|
+
form.resetFields();
|
|
242
|
+
const formatted = form.getFieldsFormatValue();
|
|
243
|
+
formReadyRef.current = true;
|
|
244
|
+
const next = beforeSearchSubmit ? beforeSearchSubmit(formatted) : formatted;
|
|
245
|
+
setFormParams(next);
|
|
246
|
+
setPageInfo({ current: 1 });
|
|
247
|
+
onReset?.();
|
|
248
|
+
fetcher.reload();
|
|
249
|
+
});
|
|
250
|
+
const settingColumns = [];
|
|
251
|
+
const tableColumns = useMemo(() => {
|
|
252
|
+
const offset = (mergedPageInfo.current - 1) * mergedPageInfo.pageSize;
|
|
253
|
+
const convert = (column, index, top) => {
|
|
254
|
+
const key = getProColumnKey(column, index);
|
|
255
|
+
const state = top ? columnsStateMap[key] : void 0;
|
|
256
|
+
if (column.hideInTable || state?.show === false) return null;
|
|
257
|
+
const { children, colSize: _colSize, copyable, disable: _disable, fieldProps, filters, formItemProps: _formItemProps, hideInForm: _hideInForm, hideInSearch: _hideInSearch, hideInSetting: _hideInSetting, hideInTable: _hideInTable, initialValue: _initialValue, onFilter, order: _order, render, renderFormItem: _renderFormItem, renderText, search: _search, sorter, title, tooltip: columnTooltip, valueEnum: _valueEnum, valueType: _valueType, ...rest } = column;
|
|
258
|
+
const titleNode = columnTooltip ? /* @__PURE__ */ jsxs("span", {
|
|
259
|
+
className: styles.titleTooltip,
|
|
260
|
+
children: [title, /* @__PURE__ */ jsx(ActionIcon, {
|
|
261
|
+
icon: CircleHelp,
|
|
262
|
+
size: "small",
|
|
263
|
+
title: columnTooltip
|
|
264
|
+
})]
|
|
265
|
+
}) : title;
|
|
266
|
+
if (children?.length) {
|
|
267
|
+
const childColumns = children.map((child, childIndex) => convert(child, childIndex, false)).filter((child) => child !== null);
|
|
268
|
+
return {
|
|
269
|
+
...rest,
|
|
270
|
+
children: childColumns,
|
|
271
|
+
key,
|
|
272
|
+
title: titleNode
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
const valueType = resolveValueType(column);
|
|
276
|
+
const staticEnum = typeof column.valueEnum === "function" ? void 0 : column.valueEnum;
|
|
277
|
+
const resolvedFilters = filters === true ? valueEnumToList(staticEnum).map((item) => ({
|
|
278
|
+
text: item.text,
|
|
279
|
+
value: item.value
|
|
280
|
+
})) : filters || void 0;
|
|
281
|
+
const resolvedOnFilter = onFilter === true ? (value, record) => String(getByPath(record, column.dataIndex)) === String(value) : onFilter || void 0;
|
|
282
|
+
const fixed = state?.fixed ?? rest.fixed;
|
|
283
|
+
return {
|
|
284
|
+
...rest,
|
|
285
|
+
...valueType === "option" && rest.align === void 0 && { align: "end" },
|
|
286
|
+
...(valueType === "index" || valueType === "indexBorder") && rest.width === void 0 && { width: 56 },
|
|
287
|
+
filters: resolvedFilters,
|
|
288
|
+
fixed: fixed === "left" ? "start" : fixed === "right" ? "end" : fixed,
|
|
289
|
+
key,
|
|
290
|
+
onFilter: resolvedOnFilter,
|
|
291
|
+
sorter: typeof sorter === "string" ? true : sorter,
|
|
292
|
+
title: titleNode,
|
|
293
|
+
render: (value, record, rowIndex) => {
|
|
294
|
+
const current = actionHolderRef.current;
|
|
295
|
+
const text = renderText ? renderText(value, record, rowIndex, current) : value;
|
|
296
|
+
let dom = renderValue(text, {
|
|
297
|
+
emptyText: columnEmptyText === false ? null : columnEmptyText,
|
|
298
|
+
fieldProps,
|
|
299
|
+
rowIndex: offset + rowIndex,
|
|
300
|
+
valueEnum: resolveValueEnum(column, record),
|
|
301
|
+
valueType: resolveValueType(column, record)
|
|
302
|
+
});
|
|
303
|
+
if (copyable && !isEmptyValue(text)) dom = /* @__PURE__ */ jsx(CopyableText, {
|
|
304
|
+
label: locale.copy,
|
|
305
|
+
text: String(text),
|
|
306
|
+
children: dom
|
|
307
|
+
});
|
|
308
|
+
if (!render) return dom;
|
|
309
|
+
const result = render(dom, record, rowIndex, current, column);
|
|
310
|
+
if (valueType === "option" && Array.isArray(result)) return /* @__PURE__ */ jsx("div", {
|
|
311
|
+
className: styles.optionCell,
|
|
312
|
+
children: result
|
|
313
|
+
});
|
|
314
|
+
return result;
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
};
|
|
318
|
+
const indexed = columnsProp.map((column, index) => ({
|
|
319
|
+
column,
|
|
320
|
+
index,
|
|
321
|
+
key: getProColumnKey(column, index)
|
|
322
|
+
}));
|
|
323
|
+
indexed.sort((a, b) => {
|
|
324
|
+
return (columnsStateMap[a.key]?.order ?? a.index) - (columnsStateMap[b.key]?.order ?? b.index);
|
|
325
|
+
});
|
|
326
|
+
return indexed.map(({ column, index }) => convert(column, index, true)).filter((column) => column !== null);
|
|
327
|
+
}, [
|
|
328
|
+
columnsProp,
|
|
329
|
+
columnsStateMap,
|
|
330
|
+
columnEmptyText,
|
|
331
|
+
mergedPageInfo.current,
|
|
332
|
+
mergedPageInfo.pageSize
|
|
333
|
+
]);
|
|
334
|
+
[...columnsProp].map((column, index) => ({
|
|
335
|
+
column,
|
|
336
|
+
index,
|
|
337
|
+
key: getProColumnKey(column, index)
|
|
338
|
+
})).sort((a, b) => (columnsStateMap[a.key]?.order ?? a.index) - (columnsStateMap[b.key]?.order ?? b.index)).forEach(({ column, key }) => {
|
|
339
|
+
if (column.hideInTable || column.hideInSetting) return;
|
|
340
|
+
const disable = columnsStateMap[key]?.disable ?? (typeof column.disable === "object" ? column.disable.checkbox : column.disable);
|
|
341
|
+
settingColumns.push({
|
|
342
|
+
disabled: !!disable,
|
|
343
|
+
key,
|
|
344
|
+
title: column.title ?? key
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
const sortFieldOf = useMemo(() => {
|
|
348
|
+
const map = /* @__PURE__ */ new Map();
|
|
349
|
+
const walk = (list) => list.forEach((column, index) => {
|
|
350
|
+
if (isGroup(column)) walk(column.children);
|
|
351
|
+
const key = getProColumnKey(column, index);
|
|
352
|
+
if (typeof column.sorter === "string") map.set(key, column.sorter);
|
|
353
|
+
else if (Array.isArray(column.dataIndex)) map.set(key, column.dataIndex.join("."));
|
|
354
|
+
else if (column.dataIndex !== void 0) map.set(key, String(column.dataIndex));
|
|
355
|
+
});
|
|
356
|
+
walk(columnsProp);
|
|
357
|
+
return map;
|
|
358
|
+
}, [columnsProp]);
|
|
359
|
+
const handleTableChange = useEventCallback((pagination, filters, sorter, extra) => {
|
|
360
|
+
if (extra.action === "sort") {
|
|
361
|
+
const list = Array.isArray(sorter) ? sorter : [sorter];
|
|
362
|
+
const next = {};
|
|
363
|
+
list.forEach((item) => {
|
|
364
|
+
if (!item.order || item.columnKey === void 0) return;
|
|
365
|
+
const columnKey = String(item.columnKey);
|
|
366
|
+
next[sortFieldOf.get(columnKey) ?? columnKey] = item.order;
|
|
367
|
+
});
|
|
368
|
+
setSort(next);
|
|
369
|
+
}
|
|
370
|
+
if (extra.action === "filter") {
|
|
371
|
+
const next = {};
|
|
372
|
+
Object.entries(filters).forEach(([columnKey, value]) => {
|
|
373
|
+
next[sortFieldOf.get(columnKey) ?? columnKey] = value;
|
|
374
|
+
});
|
|
375
|
+
setFilter(next);
|
|
376
|
+
}
|
|
377
|
+
onChange?.(pagination, filters, sorter, extra);
|
|
378
|
+
});
|
|
379
|
+
const optionConfig = options === false ? false : {
|
|
380
|
+
density: true,
|
|
381
|
+
fullScreen: false,
|
|
382
|
+
reload: true,
|
|
383
|
+
setting: true,
|
|
384
|
+
...options
|
|
385
|
+
};
|
|
386
|
+
const reloadOption = optionConfig && optionConfig.reload;
|
|
387
|
+
const fullScreenOption = optionConfig && optionConfig.fullScreen;
|
|
388
|
+
const settingOption = optionConfig && optionConfig.setting;
|
|
389
|
+
const searchOption = optionConfig && optionConfig.search;
|
|
390
|
+
const [openOption, setOpenOption] = useState(null);
|
|
391
|
+
const toggleOption = (key, event) => {
|
|
392
|
+
const anchor = event?.currentTarget ?? null;
|
|
393
|
+
setOpenOption((prev) => prev?.key === key || !anchor ? null : {
|
|
394
|
+
anchor,
|
|
395
|
+
key
|
|
396
|
+
});
|
|
397
|
+
};
|
|
398
|
+
const closeOption = () => setOpenOption(null);
|
|
399
|
+
const optionItems = [];
|
|
400
|
+
if (optionConfig) {
|
|
401
|
+
if (reloadOption) optionItems.push({
|
|
402
|
+
icon: RotateCw,
|
|
403
|
+
key: "reload",
|
|
404
|
+
label: locale.reload,
|
|
405
|
+
loading: !!loading && !!request,
|
|
406
|
+
onClick: () => typeof reloadOption === "function" ? reloadOption() : void reload()
|
|
407
|
+
});
|
|
408
|
+
if (optionConfig.density) optionItems.push({
|
|
409
|
+
icon: Rows3,
|
|
410
|
+
key: "density",
|
|
411
|
+
label: locale.density,
|
|
412
|
+
onClick: ((event) => toggleOption("density", event))
|
|
413
|
+
});
|
|
414
|
+
if (fullScreenOption) optionItems.push({
|
|
415
|
+
icon: fullscreen ? Minimize : Fullscreen,
|
|
416
|
+
key: "fullScreen",
|
|
417
|
+
label: locale.fullScreen,
|
|
418
|
+
onClick: () => typeof fullScreenOption === "function" ? fullScreenOption() : toggleFullScreen()
|
|
419
|
+
});
|
|
420
|
+
if (settingOption) optionItems.push({
|
|
421
|
+
icon: Settings,
|
|
422
|
+
key: "setting",
|
|
423
|
+
label: locale.columnSetting,
|
|
424
|
+
onClick: ((event) => toggleOption("setting", event))
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
const settingProps = settingOption && typeof settingOption === "object" ? settingOption : {};
|
|
428
|
+
const optionNodes = optionItems.length > 0 ? [
|
|
429
|
+
/* @__PURE__ */ jsx(ActionIconGroup, {
|
|
430
|
+
className: `${PRO_PREFIX_CLS}-options`,
|
|
431
|
+
items: optionItems,
|
|
432
|
+
size: "small",
|
|
433
|
+
variant: "outlined"
|
|
434
|
+
}, "options"),
|
|
435
|
+
/* @__PURE__ */ jsx(OptionPopover, {
|
|
436
|
+
anchor: openOption?.key === "density" ? openOption.anchor : null,
|
|
437
|
+
open: openOption?.key === "density",
|
|
438
|
+
onOpenChange: (next) => !next && closeOption(),
|
|
439
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
440
|
+
className: styles.density,
|
|
441
|
+
"data-pro-table-density": "",
|
|
442
|
+
role: "menu",
|
|
443
|
+
children: [
|
|
444
|
+
"large",
|
|
445
|
+
"medium",
|
|
446
|
+
"small"
|
|
447
|
+
].map((item) => /* @__PURE__ */ jsxs("button", {
|
|
448
|
+
"aria-checked": size === item,
|
|
449
|
+
className: styles.densityItem,
|
|
450
|
+
role: "menuitemradio",
|
|
451
|
+
type: "button",
|
|
452
|
+
onClick: () => {
|
|
453
|
+
setSize(item);
|
|
454
|
+
closeOption();
|
|
455
|
+
},
|
|
456
|
+
children: [/* @__PURE__ */ jsx("span", { children: item === "large" ? locale.densityLarge : item === "medium" ? locale.densityMedium : locale.densitySmall }), size === item && /* @__PURE__ */ jsx(Check, { size: 14 })]
|
|
457
|
+
}, item))
|
|
458
|
+
})
|
|
459
|
+
}, "density-popover"),
|
|
460
|
+
/* @__PURE__ */ jsx(OptionPopover, {
|
|
461
|
+
anchor: openOption?.key === "setting" ? openOption.anchor : null,
|
|
462
|
+
open: openOption?.key === "setting",
|
|
463
|
+
onOpenChange: (next) => !next && closeOption(),
|
|
464
|
+
children: /* @__PURE__ */ jsx(ColumnSetting, {
|
|
465
|
+
checkable: settingProps.checkable,
|
|
466
|
+
columns: settingColumns,
|
|
467
|
+
draggable: settingProps.draggable,
|
|
468
|
+
locale,
|
|
469
|
+
showListItemOption: settingProps.showListItemOption,
|
|
470
|
+
state: columnsStateMap,
|
|
471
|
+
onChange: setColumnsStateMap,
|
|
472
|
+
onReset: resetColumnsState
|
|
473
|
+
})
|
|
474
|
+
}, "setting-popover")
|
|
475
|
+
] : [];
|
|
476
|
+
const lightMode = search !== false && search?.filterType === "light";
|
|
477
|
+
const lightFilterDom = lightMode && searchFields.length > 0 ? /* @__PURE__ */ jsx(LightFilter, {
|
|
478
|
+
fields: searchFields,
|
|
479
|
+
form,
|
|
480
|
+
placeholder: {
|
|
481
|
+
input: locale.searchPlaceholder,
|
|
482
|
+
select: locale.selectPlaceholder
|
|
483
|
+
}
|
|
484
|
+
}) : null;
|
|
485
|
+
const keywordDom = searchOption ? /* @__PURE__ */ jsx(Input_default, {
|
|
486
|
+
allowClear: true,
|
|
487
|
+
style: { width: 200 },
|
|
488
|
+
placeholder: typeof searchOption === "object" && searchOption.placeholder || locale.searchPlaceholder,
|
|
489
|
+
onClear: () => {
|
|
490
|
+
setKeyword(void 0);
|
|
491
|
+
setPageInfo({ current: 1 });
|
|
492
|
+
},
|
|
493
|
+
onPressEnter: (event) => {
|
|
494
|
+
const value = event.target.value;
|
|
495
|
+
if (typeof searchOption === "object" && searchOption.onSearch?.(value) === false) return;
|
|
496
|
+
setKeyword(value);
|
|
497
|
+
setPageInfo({ current: 1 });
|
|
498
|
+
}
|
|
499
|
+
}, "keyword") : null;
|
|
500
|
+
const actionNodes = toolBarRender === false ? [] : [...toolbar?.actions ?? [], ...toolBarRender?.(actionHolderRef.current, {
|
|
501
|
+
selectedRowKeys,
|
|
502
|
+
selectedRows
|
|
503
|
+
}) ?? []];
|
|
504
|
+
const titleNode = headerTitle ?? toolbar?.title;
|
|
505
|
+
const titleTooltip = tooltip ?? toolbar?.tooltip;
|
|
506
|
+
const settingsNodes = toolbar?.settings ?? optionNodes;
|
|
507
|
+
const toolbarDom = toolBarRender !== false && (titleNode !== void 0 || actionNodes.length > 0 || settingsNodes.length > 0 || !!lightFilterDom || !!keywordDom) ? /* @__PURE__ */ jsxs("div", {
|
|
508
|
+
className: cx(styles.toolbar, `${PRO_PREFIX_CLS}-toolbar`),
|
|
509
|
+
children: [(titleNode !== void 0 || toolbar?.subTitle) && /* @__PURE__ */ jsxs("div", {
|
|
510
|
+
className: styles.title,
|
|
511
|
+
children: [
|
|
512
|
+
titleNode,
|
|
513
|
+
titleTooltip && /* @__PURE__ */ jsx(ActionIcon, {
|
|
514
|
+
icon: CircleHelp,
|
|
515
|
+
size: "small",
|
|
516
|
+
title: titleTooltip
|
|
517
|
+
}),
|
|
518
|
+
toolbar?.subTitle && /* @__PURE__ */ jsx("span", {
|
|
519
|
+
className: styles.titleSub,
|
|
520
|
+
children: toolbar.subTitle
|
|
521
|
+
})
|
|
522
|
+
]
|
|
523
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
524
|
+
className: styles.toolbarActions,
|
|
525
|
+
children: [
|
|
526
|
+
lightFilterDom,
|
|
527
|
+
keywordDom,
|
|
528
|
+
actionNodes,
|
|
529
|
+
settingsNodes.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
530
|
+
className: styles.toolbarOptions,
|
|
531
|
+
children: settingsNodes
|
|
532
|
+
})
|
|
533
|
+
]
|
|
534
|
+
})]
|
|
535
|
+
}) : null;
|
|
536
|
+
const alwaysShowAlert = rowSelection ? rowSelection.alwaysShowAlert : false;
|
|
537
|
+
const alertProps = {
|
|
538
|
+
onCleanSelected: clearSelected,
|
|
539
|
+
selectedRowKeys,
|
|
540
|
+
selectedRows
|
|
541
|
+
};
|
|
542
|
+
const alertInfo = tableAlertRender === false ? false : tableAlertRender ? tableAlertRender(alertProps) : locale.alertSelected(selectedRowKeys.length);
|
|
543
|
+
const alertOption = tableAlertOptionRender === false ? null : tableAlertOptionRender ? tableAlertOptionRender(alertProps) : /* @__PURE__ */ jsx(Button, {
|
|
544
|
+
size: "small",
|
|
545
|
+
type: "link",
|
|
546
|
+
onClick: clearSelected,
|
|
547
|
+
children: locale.alertClear
|
|
548
|
+
});
|
|
549
|
+
const alertDom = selectionEnabled && alertInfo !== false && (selectedRowKeys.length > 0 || alwaysShowAlert) ? /* @__PURE__ */ jsxs("div", {
|
|
550
|
+
className: cx(styles.alert, `${PRO_PREFIX_CLS}-alert`),
|
|
551
|
+
role: "status",
|
|
552
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
553
|
+
className: styles.alertInfo,
|
|
554
|
+
children: alertInfo
|
|
555
|
+
}), alertOption && /* @__PURE__ */ jsx("div", {
|
|
556
|
+
className: styles.alertOption,
|
|
557
|
+
children: alertOption
|
|
558
|
+
})]
|
|
559
|
+
}) : null;
|
|
560
|
+
const mergedRowSelection = rowSelection ? (() => {
|
|
561
|
+
const { alwaysShowAlert: _always, ...restSelection } = rowSelection;
|
|
562
|
+
return {
|
|
563
|
+
...restSelection,
|
|
564
|
+
onChange: (keys, selected, info) => {
|
|
565
|
+
setInnerSelectedKeys(keys);
|
|
566
|
+
restSelection.onChange?.(keys, selected, info);
|
|
567
|
+
},
|
|
568
|
+
preserveSelectedRowKeys: restSelection.preserveSelectedRowKeys ?? !!request,
|
|
569
|
+
selectedRowKeys
|
|
570
|
+
};
|
|
571
|
+
})() : void 0;
|
|
572
|
+
const tablePagination = paginationConfig === false ? false : {
|
|
573
|
+
...paginationConfig,
|
|
574
|
+
current: mergedPageInfo.current,
|
|
575
|
+
onChange: (page, pageSize) => {
|
|
576
|
+
setPageInfo({
|
|
577
|
+
current: page,
|
|
578
|
+
pageSize
|
|
579
|
+
});
|
|
580
|
+
paginationConfig.onChange?.(page, pageSize);
|
|
581
|
+
},
|
|
582
|
+
pageSize: mergedPageInfo.pageSize,
|
|
583
|
+
...request && { total: mergedPageInfo.total }
|
|
584
|
+
};
|
|
585
|
+
const tableDom = /* @__PURE__ */ jsx(Table, {
|
|
586
|
+
...tableProps,
|
|
587
|
+
className: tableClassName,
|
|
588
|
+
columns: tableColumns,
|
|
589
|
+
dataSource: rows,
|
|
590
|
+
loading,
|
|
591
|
+
pagination: tablePagination,
|
|
592
|
+
rowSelection: mergedRowSelection,
|
|
593
|
+
size,
|
|
594
|
+
style: tableStyle,
|
|
595
|
+
variant,
|
|
596
|
+
onChange: handleTableChange
|
|
597
|
+
});
|
|
598
|
+
const cardBorder = (part) => typeof cardBordered === "object" ? !!cardBordered[part] : !!cardBordered;
|
|
599
|
+
const cardClass = (part) => cx(styles.part, cardBorder(part) && styles.partBordered, `${PRO_PREFIX_CLS}-${part}`);
|
|
600
|
+
const tableBody = /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
601
|
+
toolbarDom,
|
|
602
|
+
alertDom,
|
|
603
|
+
tableDom
|
|
604
|
+
] });
|
|
605
|
+
const tableCard = /* @__PURE__ */ jsx("div", {
|
|
606
|
+
className: cardClass("table"),
|
|
607
|
+
children: tableRender ? tableRender(props, tableBody, {
|
|
608
|
+
alert: alertDom,
|
|
609
|
+
table: tableDom,
|
|
610
|
+
toolbar: toolbarDom
|
|
611
|
+
}) : tableBody
|
|
612
|
+
});
|
|
613
|
+
let searchDom = null;
|
|
614
|
+
if (search !== false && !lightMode && searchFields.length > 0) {
|
|
615
|
+
const formDom = /* @__PURE__ */ jsx("div", {
|
|
616
|
+
className: cardClass("search"),
|
|
617
|
+
children: /* @__PURE__ */ jsx(SearchForm, {
|
|
618
|
+
config: search ?? {},
|
|
619
|
+
fields: searchFields,
|
|
620
|
+
form,
|
|
621
|
+
loading: !!loading && !!request,
|
|
622
|
+
locale: {
|
|
623
|
+
collapse: locale.collapse,
|
|
624
|
+
expand: locale.expand,
|
|
625
|
+
inputPlaceholder: locale.searchPlaceholder,
|
|
626
|
+
reset: locale.reset,
|
|
627
|
+
search: locale.search,
|
|
628
|
+
selectPlaceholder: locale.selectPlaceholder
|
|
629
|
+
},
|
|
630
|
+
onReset: handleReset
|
|
631
|
+
})
|
|
632
|
+
});
|
|
633
|
+
searchDom = searchFormRender ? searchFormRender(props, formDom) : formDom;
|
|
634
|
+
}
|
|
635
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
636
|
+
className: cx(styles.root, PRO_PREFIX_CLS, className),
|
|
637
|
+
"data-fullscreen": fullscreen || void 0,
|
|
638
|
+
ref: rootRef,
|
|
639
|
+
style,
|
|
640
|
+
children: [
|
|
641
|
+
searchDom,
|
|
642
|
+
tableExtraRender?.(props, rows),
|
|
643
|
+
tableCard
|
|
644
|
+
]
|
|
645
|
+
});
|
|
646
|
+
};
|
|
647
|
+
ProTable.displayName = "ProTable";
|
|
648
|
+
//#endregion
|
|
649
|
+
export { DEFAULT_PRO_TABLE_LOCALE, ProTable as default };
|
|
650
|
+
|
|
651
|
+
//# sourceMappingURL=ProTable.mjs.map
|