@ant-design/pro-components 3.1.1-1 → 3.1.2-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/dist/pro-components.min.js +1 -1
- package/es/descriptions/index.d.ts +0 -2
- package/es/descriptions/index.js +1 -5
- package/es/field/components/Cascader/index.d.ts +3 -3
- package/es/field/components/Checkbox/index.d.ts +2 -2
- package/es/field/components/ColorPicker/index.d.ts +1 -1
- package/es/field/components/DatePicker/index.d.ts +2 -2
- package/es/field/components/Radio/index.d.ts +1 -1
- package/es/field/components/RangePicker/index.d.ts +2 -2
- package/es/field/components/Segmented/index.d.ts +1 -1
- package/es/field/components/Select/LightSelect/index.d.ts +1 -1
- package/es/field/components/Select/index.d.ts +1 -1
- package/es/field/components/Select/index.js +0 -2
- package/es/field/components/Switch/index.d.ts +1 -1
- package/es/field/components/TreeSelect/index.d.ts +3 -3
- package/es/form/components/Cascader/index.d.ts +1 -1
- package/es/form/components/ColorPicker/index.d.ts +1 -1
- package/es/form/components/DateRangePicker/DateTimeRangePicker.d.ts +1 -1
- package/es/form/components/Digit/DigitRange.d.ts +2 -2
- package/es/form/components/Digit/index.d.ts +1 -1
- package/es/form/components/Money/index.d.ts +1 -1
- package/es/form/components/Radio/index.d.ts +2 -2
- package/es/form/components/Rate/index.d.ts +1 -1
- package/es/form/components/Slider/index.d.ts +1 -1
- package/es/form/components/TextArea/index.d.ts +1 -1
- package/es/form/layouts/ProForm/index.d.ts +1 -1
- package/es/layout/components/SiderMenu/BaseMenu.js +0 -2
- package/es/list/ListView.js +3 -3
- package/es/provider/index.js +1 -1
- package/es/table/Store/Provide.d.ts +0 -1
- package/es/table/Store/Provide.js +1 -1
- package/es/table/Table.js +0 -1
- package/es/table/typing.d.ts +0 -4
- package/es/table/utils/cellRenderToFromItem.d.ts +1 -1
- package/es/table/utils/columnRender.d.ts +1 -1
- package/es/table/utils/columnRender.js +1 -4
- package/es/table/utils/genProColumnToColumn.d.ts +2 -2
- package/es/table/utils/index.d.ts +0 -10
- package/es/table/utils/index.js +0 -12
- package/es/utils/useEditableArray/index.d.ts +1 -1
- package/es/utils/useEditableArray/index.js +1 -1
- package/es/utils/useLazyKVMap.d.ts +5 -0
- package/es/utils/useLazyKVMap.js +28 -0
- package/es/utils/useMediaQuery/index.d.ts +2 -2
- package/es/utils/usePagination.d.ts +8 -0
- package/es/utils/usePagination.js +67 -0
- package/es/utils/useSelection.d.ts +19 -0
- package/es/utils/useSelection.js +61 -0
- package/lib/descriptions/index.d.ts +0 -2
- package/lib/descriptions/index.js +1 -5
- package/lib/field/components/Select/index.js +0 -2
- package/lib/form/components/DateRangePicker/DateTimeRangePicker.d.ts +1 -1
- package/lib/layout/components/SiderMenu/BaseMenu.js +0 -2
- package/lib/list/ListView.js +4 -4
- package/lib/provider/index.js +1 -1
- package/lib/table/Store/Provide.d.ts +0 -1
- package/lib/table/Store/Provide.js +1 -1
- package/lib/table/Table.js +0 -1
- package/lib/table/typing.d.ts +0 -4
- package/lib/table/utils/cellRenderToFromItem.d.ts +1 -1
- package/lib/table/utils/columnRender.d.ts +1 -1
- package/lib/table/utils/columnRender.js +1 -4
- package/lib/table/utils/genProColumnToColumn.d.ts +2 -2
- package/lib/table/utils/index.d.ts +0 -10
- package/lib/table/utils/index.js +3 -15
- package/lib/utils/useEditableArray/index.d.ts +1 -1
- package/lib/utils/useEditableArray/index.js +2 -2
- package/lib/utils/useLazyKVMap.d.ts +5 -0
- package/lib/utils/useLazyKVMap.js +34 -0
- package/lib/utils/usePagination.d.ts +8 -0
- package/lib/utils/usePagination.js +74 -0
- package/lib/utils/useSelection.d.ts +19 -0
- package/lib/utils/useSelection.js +68 -0
- package/package.json +2 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
export const DEFAULT_PAGE_SIZE = 10;
|
|
3
|
+
function extendsObject(base, override, extra = {}) {
|
|
4
|
+
return {
|
|
5
|
+
...base,
|
|
6
|
+
...override,
|
|
7
|
+
...extra
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export function getPaginationParam(mergedPagination, pagination) {
|
|
11
|
+
const param = {
|
|
12
|
+
current: mergedPagination.current,
|
|
13
|
+
pageSize: mergedPagination.pageSize
|
|
14
|
+
};
|
|
15
|
+
const paginationObj = pagination && typeof pagination === 'object' ? pagination : {};
|
|
16
|
+
Object.keys(paginationObj).forEach(pageProp => {
|
|
17
|
+
const value = mergedPagination[pageProp];
|
|
18
|
+
if (typeof value !== 'function') {
|
|
19
|
+
param[pageProp] = value;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return param;
|
|
23
|
+
}
|
|
24
|
+
function usePagination(total, onChange, pagination) {
|
|
25
|
+
const {
|
|
26
|
+
total: paginationTotal = 0,
|
|
27
|
+
...paginationObj
|
|
28
|
+
} = pagination && typeof pagination === 'object' ? pagination : {};
|
|
29
|
+
const [innerPagination, setInnerPagination] = useState(() => ({
|
|
30
|
+
current: 'defaultCurrent' in paginationObj ? paginationObj.defaultCurrent : 1,
|
|
31
|
+
pageSize: 'defaultPageSize' in paginationObj ? paginationObj.defaultPageSize : DEFAULT_PAGE_SIZE
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
// ============ Basic Pagination Config ============
|
|
35
|
+
const mergedPagination = extendsObject(innerPagination, paginationObj, {
|
|
36
|
+
total: paginationTotal > 0 ? paginationTotal : total
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Reset `current` if data length or pageSize changed
|
|
40
|
+
const pageSize = mergedPagination.pageSize || DEFAULT_PAGE_SIZE;
|
|
41
|
+
const maxPage = Math.ceil((paginationTotal || total) / pageSize);
|
|
42
|
+
if ((mergedPagination.current || 1) > maxPage) {
|
|
43
|
+
// Prevent a maximum page count of 0
|
|
44
|
+
mergedPagination.current = maxPage || 1;
|
|
45
|
+
}
|
|
46
|
+
const refreshPagination = (current, pageSizeArg) => {
|
|
47
|
+
setInnerPagination({
|
|
48
|
+
current: current ?? 1,
|
|
49
|
+
pageSize: pageSizeArg || mergedPagination.pageSize
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
const onInternalChange = (current, pageSizeArg) => {
|
|
53
|
+
if (pagination && typeof pagination === 'object') {
|
|
54
|
+
pagination.onChange?.(current, pageSizeArg);
|
|
55
|
+
}
|
|
56
|
+
refreshPagination(current, pageSizeArg);
|
|
57
|
+
onChange(current, pageSizeArg || mergedPagination.pageSize);
|
|
58
|
+
};
|
|
59
|
+
if (pagination === false) {
|
|
60
|
+
return [{}, () => {}];
|
|
61
|
+
}
|
|
62
|
+
return [{
|
|
63
|
+
...mergedPagination,
|
|
64
|
+
onChange: onInternalChange
|
|
65
|
+
}, refreshPagination];
|
|
66
|
+
}
|
|
67
|
+
export default usePagination;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { GetRowKey, TableRowSelection } from 'antd/lib/table/interface';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
type UseSelectionConfig<RecordType> = {
|
|
4
|
+
getRowKey: GetRowKey<RecordType>;
|
|
5
|
+
getRecordByKey: (key: React.Key) => RecordType | undefined;
|
|
6
|
+
prefixCls?: string;
|
|
7
|
+
data: RecordType[];
|
|
8
|
+
pageData: RecordType[];
|
|
9
|
+
expandType?: 'row' | 'nest';
|
|
10
|
+
childrenColumnName?: string;
|
|
11
|
+
locale?: any;
|
|
12
|
+
};
|
|
13
|
+
declare function useSelection<RecordType>(config: UseSelectionConfig<RecordType>, rowSelection?: TableRowSelection<RecordType>): readonly [
|
|
14
|
+
(columns?: any[]) => Array<{
|
|
15
|
+
render: (text: any, record: RecordType, index: number) => React.ReactElement;
|
|
16
|
+
}>,
|
|
17
|
+
Set<React.Key>
|
|
18
|
+
];
|
|
19
|
+
export default useSelection;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Checkbox } from 'antd';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
function useSelection(config, rowSelection) {
|
|
5
|
+
const {
|
|
6
|
+
getRowKey,
|
|
7
|
+
data
|
|
8
|
+
} = config;
|
|
9
|
+
const controlledKeys = rowSelection?.selectedRowKeys;
|
|
10
|
+
const [innerKeys, setInnerKeys] = React.useState(controlledKeys || []);
|
|
11
|
+
|
|
12
|
+
// Keep in sync with controlled keys
|
|
13
|
+
React.useEffect(() => {
|
|
14
|
+
if (controlledKeys) {
|
|
15
|
+
setInnerKeys(controlledKeys);
|
|
16
|
+
}
|
|
17
|
+
}, [controlledKeys && controlledKeys.join(';')]);
|
|
18
|
+
const selectedKeySet = React.useMemo(() => new Set(innerKeys), [innerKeys]);
|
|
19
|
+
const toggleKey = React.useCallback((key, record, checked) => {
|
|
20
|
+
setInnerKeys(prevKeys => {
|
|
21
|
+
const prevSet = new Set(prevKeys);
|
|
22
|
+
const next = new Set(prevSet);
|
|
23
|
+
if (checked) {
|
|
24
|
+
next.add(key);
|
|
25
|
+
} else {
|
|
26
|
+
next.delete(key);
|
|
27
|
+
}
|
|
28
|
+
const nextKeys = Array.from(next);
|
|
29
|
+
|
|
30
|
+
// Fire callbacks similar to antd rowSelection
|
|
31
|
+
const selectedRows = data.filter((item, idx) => next.has(getRowKey(item, idx)));
|
|
32
|
+
rowSelection?.onChange?.(nextKeys, selectedRows, {
|
|
33
|
+
type: 'multiple',
|
|
34
|
+
selectedRows,
|
|
35
|
+
selectedRowKeys: nextKeys
|
|
36
|
+
});
|
|
37
|
+
rowSelection?.onSelect?.(record, checked, data.filter((item, idx) => next.has(getRowKey(item, idx))), {});
|
|
38
|
+
if (!controlledKeys) {
|
|
39
|
+
return nextKeys;
|
|
40
|
+
}
|
|
41
|
+
return prevKeys;
|
|
42
|
+
});
|
|
43
|
+
}, [data, getRowKey, rowSelection, controlledKeys]);
|
|
44
|
+
const selectItemRender = React.useCallback(columns => {
|
|
45
|
+
void columns;
|
|
46
|
+
return [{
|
|
47
|
+
render: (_text, record, index) => {
|
|
48
|
+
const key = getRowKey(record, index);
|
|
49
|
+
const checked = selectedKeySet.has(key);
|
|
50
|
+
return /*#__PURE__*/_jsx(Checkbox, {
|
|
51
|
+
checked: checked,
|
|
52
|
+
onChange: e => {
|
|
53
|
+
toggleKey(key, record, e.target.checked);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}];
|
|
58
|
+
}, [getRowKey, selectedKeySet, toggleKey]);
|
|
59
|
+
return [selectItemRender, selectedKeySet];
|
|
60
|
+
}
|
|
61
|
+
export default useSelection;
|
|
@@ -17,8 +17,6 @@ var _skeleton = _interopRequireDefault(require("../skeleton"));
|
|
|
17
17
|
var _utils = require("../utils");
|
|
18
18
|
var _useFetchData = _interopRequireDefault(require("./useFetchData"));
|
|
19
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
|
-
// todo remove it
|
|
21
|
-
|
|
22
20
|
/**
|
|
23
21
|
* 定义列表属性的类型定义,用于定义列表的一列
|
|
24
22
|
* @typedef {Object} ProDescriptionsItemProps
|
|
@@ -304,7 +302,6 @@ const ProDescriptions = props => {
|
|
|
304
302
|
actionRef,
|
|
305
303
|
onRequestError,
|
|
306
304
|
emptyText,
|
|
307
|
-
contentStyle,
|
|
308
305
|
...rest
|
|
309
306
|
} = props;
|
|
310
307
|
const proContext = (0, _react.useContext)(_provider.default);
|
|
@@ -422,8 +419,7 @@ const ProDescriptions = props => {
|
|
|
422
419
|
...rest,
|
|
423
420
|
styles: {
|
|
424
421
|
content: {
|
|
425
|
-
minWidth: 0
|
|
426
|
-
...(contentStyle || {})
|
|
422
|
+
minWidth: 0
|
|
427
423
|
}
|
|
428
424
|
},
|
|
429
425
|
extra: rest.extra ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_antd.Space, {
|
|
@@ -190,10 +190,8 @@ const useFieldFetchData = props => {
|
|
|
190
190
|
keyWords: kw
|
|
191
191
|
}, props), {
|
|
192
192
|
revalidateIfStale: !cacheForSwr,
|
|
193
|
-
// 打开 cacheForSwr 的时候才应该支持两个功能
|
|
194
193
|
revalidateOnReconnect: cacheForSwr,
|
|
195
194
|
shouldRetryOnError: false,
|
|
196
|
-
// @todo 这个功能感觉应该搞个API出来
|
|
197
195
|
revalidateOnFocus: false
|
|
198
196
|
});
|
|
199
197
|
const resOptions = (0, _react.useMemo)(() => {
|
|
@@ -16,8 +16,6 @@ var _defaultSettings = require("../../defaultSettings");
|
|
|
16
16
|
var _utils2 = require("../../utils/utils");
|
|
17
17
|
var _menu = require("./style/menu");
|
|
18
18
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
|
-
// todo
|
|
20
|
-
|
|
21
19
|
const MenuItemTooltip = props => {
|
|
22
20
|
const [collapsed, setCollapsed] = (0, _react.useState)(props.collapsed);
|
|
23
21
|
const [open, setOpen] = (0, _react.useState)(false);
|
package/lib/list/ListView.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
var _util = require("@rc-component/util");
|
|
10
10
|
var _antd = require("antd");
|
|
11
|
-
var _useLazyKVMap = _interopRequireDefault(require("antd/lib/table/hooks/useLazyKVMap"));
|
|
12
|
-
var _usePagination = _interopRequireDefault(require("antd/lib/table/hooks/usePagination"));
|
|
13
|
-
var _useSelection = _interopRequireDefault(require("antd/lib/table/hooks/useSelection"));
|
|
14
11
|
var _clsx = require("clsx");
|
|
15
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
16
13
|
var _provider = require("../provider");
|
|
14
|
+
var _useLazyKVMap = _interopRequireDefault(require("../utils/useLazyKVMap"));
|
|
15
|
+
var _usePagination = _interopRequireDefault(require("../utils/usePagination"));
|
|
16
|
+
var _useSelection = _interopRequireDefault(require("../utils/useSelection"));
|
|
17
17
|
var _constants = require("./constants");
|
|
18
18
|
var _Item = _interopRequireDefault(require("./Item"));
|
|
19
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
package/lib/provider/index.js
CHANGED
|
@@ -16,7 +16,7 @@ exports.isNeedOpenHash = exports.default = exports.ProProvider = exports.ProConf
|
|
|
16
16
|
exports.useIntl = useIntl;
|
|
17
17
|
var _cssinjs = require("@ant-design/cssinjs");
|
|
18
18
|
var _antd = require("antd");
|
|
19
|
-
var _zh_CN = _interopRequireDefault(require("antd/
|
|
19
|
+
var _zh_CN = _interopRequireDefault(require("antd/es/locale/zh_CN"));
|
|
20
20
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
21
21
|
require("dayjs/locale/zh-cn");
|
|
22
22
|
var _react = _interopRequireWildcard(require("react"));
|
|
@@ -13,7 +13,6 @@ export type ColumnsState = {
|
|
|
13
13
|
};
|
|
14
14
|
export type ProTableColumn<T> = ColumnsState & TableColumnType<T>;
|
|
15
15
|
export type UseContainerProps<T = any> = {
|
|
16
|
-
onColumnsStateChange?: (map: Record<string, ColumnsState>) => void;
|
|
17
16
|
size?: DensitySize;
|
|
18
17
|
defaultSize?: DensitySize;
|
|
19
18
|
onSizeChange?: (size: DensitySize) => void;
|
|
@@ -76,7 +76,7 @@ function useContainer(props = {}) {
|
|
|
76
76
|
}
|
|
77
77
|
return props.columnsState?.value || props.columnsState?.defaultValue || defaultColumnKeyMap;
|
|
78
78
|
}, props.columnsState?.value);
|
|
79
|
-
const onColumnsMapChange = props.columnsState?.onChange
|
|
79
|
+
const onColumnsMapChange = props.columnsState?.onChange;
|
|
80
80
|
const setColumnsMap = (0, _react.useCallback)(updater => {
|
|
81
81
|
setColumnsMapInner(prev => {
|
|
82
82
|
const next = typeof updater === 'function' ? updater(prev) : updater;
|
package/lib/table/Table.js
CHANGED
|
@@ -791,7 +791,6 @@ const ProviderTableContainer = props => {
|
|
|
791
791
|
...props,
|
|
792
792
|
columnsState: props.columnsState,
|
|
793
793
|
columns: props.columns,
|
|
794
|
-
onColumnsStateChange: props.onColumnsStateChange,
|
|
795
794
|
onSizeChange: props.onSizeChange,
|
|
796
795
|
size: props.size,
|
|
797
796
|
defaultSize: props.defaultSize
|
package/lib/table/typing.d.ts
CHANGED
|
@@ -162,10 +162,6 @@ export type ProTableProps<DataSource, U, ValueType = 'text'> = {
|
|
|
162
162
|
params?: U;
|
|
163
163
|
/** @name 列状态的配置,可以用来操作列功能 */
|
|
164
164
|
columnsState?: ColumnStateType;
|
|
165
|
-
/**
|
|
166
|
-
* @deprecated 请使用 columnsState.onChange。保留兼容,后续版本将移除。
|
|
167
|
-
*/
|
|
168
|
-
onColumnsStateChange?: (map: Record<string, ColumnsState>) => void;
|
|
169
165
|
onSizeChange?: (size: DensitySize) => void;
|
|
170
166
|
/**
|
|
171
167
|
* @name table 外面卡片的设置
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyObject } from 'antd/lib/_util/type';
|
|
1
|
+
import type { AnyObject } from 'antd/lib/_util/type';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import type { ProFieldEmptyText } from '../../field';
|
|
4
4
|
import type { ProSchemaComponentTypes, UseEditableUtilType } from '../../utils';
|
|
@@ -25,10 +25,7 @@ const renderColumnsTitle = item => {
|
|
|
25
25
|
} = item;
|
|
26
26
|
const ellipsis = typeof item?.ellipsis === 'boolean' ? item?.ellipsis : item?.ellipsis?.showTitle;
|
|
27
27
|
if (title && typeof title === 'function') {
|
|
28
|
-
return title(item, 'table',
|
|
29
|
-
label: null,
|
|
30
|
-
tooltip: item.tooltip
|
|
31
|
-
}));
|
|
28
|
+
return title(item, 'table', null);
|
|
32
29
|
}
|
|
33
30
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_utils.LabelIconTip, {
|
|
34
31
|
label: title,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TableColumnType, TableProps } from 'antd';
|
|
2
|
-
import { AnyObject } from 'antd/lib/_util/type';
|
|
3
|
-
import { SortOrder } from 'antd/lib/table/interface';
|
|
2
|
+
import type { AnyObject } from 'antd/lib/_util/type';
|
|
3
|
+
import type { SortOrder } from 'antd/lib/table/interface';
|
|
4
4
|
import type { ProFieldEmptyText } from '../../field';
|
|
5
5
|
import type { ProSchemaComponentTypes, UseEditableUtilType } from '../../utils';
|
|
6
6
|
import type { ContainerType } from '../Store/Provide';
|
|
@@ -75,22 +75,12 @@ export declare const flattenColumns: (data: any[]) => any[];
|
|
|
75
75
|
* @returns 是否为本地筛选
|
|
76
76
|
*/
|
|
77
77
|
export declare const isLocalFilter: <T>(filters: ProColumnType<T>['filters'], onFilter: ProColumnType<T>['onFilter']) => boolean;
|
|
78
|
-
/**
|
|
79
|
-
* @deprecated typo kept for backward compatibility
|
|
80
|
-
* use `isLocalFilter` instead
|
|
81
|
-
*/
|
|
82
|
-
export declare const isLocaleFilter: <T>(filters: ProColumnType<T>['filters'], onFilter: ProColumnType<T>['onFilter']) => boolean;
|
|
83
78
|
/**
|
|
84
79
|
* 判断是否为本地排序
|
|
85
80
|
* @param sorter 排序配置
|
|
86
81
|
* @returns 是否为本地排序
|
|
87
82
|
*/
|
|
88
83
|
export declare const isLocalSorter: <T>(sorter: ProSorter<T>) => boolean;
|
|
89
|
-
/**
|
|
90
|
-
* @deprecated typo kept for backward compatibility
|
|
91
|
-
* use `isLocalSorter` instead
|
|
92
|
-
*/
|
|
93
|
-
export declare const isLocaleSorter: <T>(sorter: ProSorter<T>) => boolean;
|
|
94
84
|
/**
|
|
95
85
|
* 获取服务端筛选数据
|
|
96
86
|
* @param filters 筛选数据
|
package/lib/table/utils/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isMergeCell = exports.
|
|
6
|
+
exports.isMergeCell = exports.isLocalSorter = exports.isLocalFilter = exports.isBordered = exports.getServerSorterResult = exports.getServerFilterResult = exports.genColumnKey = exports.flattenColumns = exports.checkUndefinedOrNull = void 0;
|
|
7
7
|
exports.mergePagination = mergePagination;
|
|
8
8
|
exports.parseServerDefaultColumnConfig = exports.parseProSortOrder = exports.parseProFilteredValue = exports.parseDataIndex = void 0;
|
|
9
9
|
exports.postDataPipeline = postDataPipeline;
|
|
@@ -186,35 +186,23 @@ const isLocalFilter = (filters, onFilter) => {
|
|
|
186
186
|
return !!filters && !!onFilter;
|
|
187
187
|
};
|
|
188
188
|
|
|
189
|
-
/**
|
|
190
|
-
* @deprecated typo kept for backward compatibility
|
|
191
|
-
* use `isLocalFilter` instead
|
|
192
|
-
*/
|
|
193
|
-
exports.isLocalFilter = isLocalFilter;
|
|
194
|
-
const isLocaleFilter = exports.isLocaleFilter = isLocalFilter;
|
|
195
|
-
|
|
196
189
|
/**
|
|
197
190
|
* 判断是否为本地排序
|
|
198
191
|
* @param sorter 排序配置
|
|
199
192
|
* @returns 是否为本地排序
|
|
200
193
|
*/
|
|
194
|
+
exports.isLocalFilter = isLocalFilter;
|
|
201
195
|
const isLocalSorter = sorter => {
|
|
202
196
|
return typeof sorter === 'function' || typeof sorter === 'object' && typeof sorter.compare === 'function';
|
|
203
197
|
};
|
|
204
198
|
|
|
205
|
-
/**
|
|
206
|
-
* @deprecated typo kept for backward compatibility
|
|
207
|
-
* use `isLocalSorter` instead
|
|
208
|
-
*/
|
|
209
|
-
exports.isLocalSorter = isLocalSorter;
|
|
210
|
-
const isLocaleSorter = exports.isLocaleSorter = isLocalSorter;
|
|
211
|
-
|
|
212
199
|
/**
|
|
213
200
|
* 获取服务端筛选数据
|
|
214
201
|
* @param filters 筛选数据
|
|
215
202
|
* @param columns 列配置
|
|
216
203
|
* @returns 服务端筛选数据
|
|
217
204
|
*/
|
|
205
|
+
exports.isLocalSorter = isLocalSorter;
|
|
218
206
|
const getServerFilterResult = (filters, columns) => {
|
|
219
207
|
// 过滤掉本地筛选的列
|
|
220
208
|
return Object.entries(filters).reduce((acc, [key, value]) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FormInstance, FormProps } from 'antd';
|
|
2
|
-
import { AnyObject } from 'antd/lib/_util/type';
|
|
2
|
+
import type { AnyObject } from 'antd/lib/_util/type';
|
|
3
3
|
import type { NamePath } from 'antd/lib/form/interface';
|
|
4
4
|
import type { GetRowKey } from 'antd/lib/table/interface';
|
|
5
5
|
import React from 'react';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
@@ -14,7 +14,6 @@ exports.useEditableArray = useEditableArray;
|
|
|
14
14
|
var _icons = require("@ant-design/icons");
|
|
15
15
|
var _util = require("@rc-component/util");
|
|
16
16
|
var _antd = require("antd");
|
|
17
|
-
var _useLazyKVMap = _interopRequireDefault(require("antd/lib/table/hooks/useLazyKVMap"));
|
|
18
17
|
var _react = _interopRequireWildcard(require("react"));
|
|
19
18
|
var _ = require("..");
|
|
20
19
|
var _provider = require("../../provider");
|
|
@@ -22,6 +21,7 @@ var _ProFormContext = require("../components/ProFormContext");
|
|
|
22
21
|
var _useDeepCompareEffect = require("../hooks/useDeepCompareEffect");
|
|
23
22
|
var _usePrevious = require("../hooks/usePrevious");
|
|
24
23
|
var _merge = require("../merge");
|
|
24
|
+
var _useLazyKVMap = _interopRequireDefault(require("../useLazyKVMap"));
|
|
25
25
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
26
26
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
27
27
|
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AnyObject } from 'antd/lib/_util/type';
|
|
2
|
+
import type { GetRowKey } from 'antd/lib/table/interface';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
declare const useLazyKVMap: <RecordType extends AnyObject = AnyObject>(data: readonly RecordType[], childrenColumnName: string, getRowKey: GetRowKey<RecordType>) => readonly [(key: React.Key) => RecordType | undefined];
|
|
5
|
+
export default useLazyKVMap;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
const useLazyKVMap = (data, childrenColumnName, getRowKey) => {
|
|
9
|
+
const mapCacheRef = (0, _react.useRef)({});
|
|
10
|
+
function getRecordByKey(key) {
|
|
11
|
+
function dig(records, kv) {
|
|
12
|
+
records.forEach((record, index) => {
|
|
13
|
+
const rowKey = getRowKey(record, index);
|
|
14
|
+
kv.set(rowKey, record);
|
|
15
|
+
if (record && typeof record === 'object' && childrenColumnName in record) {
|
|
16
|
+
dig(record[childrenColumnName] || [], kv);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
if (!mapCacheRef.current || mapCacheRef.current.data !== data || mapCacheRef.current.childrenColumnName !== childrenColumnName || mapCacheRef.current.getRowKey !== getRowKey) {
|
|
21
|
+
const kvMap = new Map();
|
|
22
|
+
dig(data, kvMap);
|
|
23
|
+
mapCacheRef.current = {
|
|
24
|
+
data,
|
|
25
|
+
childrenColumnName,
|
|
26
|
+
kvMap,
|
|
27
|
+
getRowKey
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return mapCacheRef.current.kvMap?.get(key);
|
|
31
|
+
}
|
|
32
|
+
return [getRecordByKey];
|
|
33
|
+
};
|
|
34
|
+
var _default = exports.default = useLazyKVMap;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TablePaginationConfig } from 'antd/es/table/interface';
|
|
2
|
+
export declare const DEFAULT_PAGE_SIZE = 10;
|
|
3
|
+
export declare function getPaginationParam(mergedPagination: TablePaginationConfig, pagination?: TablePaginationConfig | boolean): any;
|
|
4
|
+
declare function usePagination(total: number, onChange: (current: number, pageSize: number) => void, pagination?: TablePaginationConfig | false): readonly [
|
|
5
|
+
TablePaginationConfig,
|
|
6
|
+
(current?: number, pageSize?: number) => void
|
|
7
|
+
];
|
|
8
|
+
export default usePagination;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.DEFAULT_PAGE_SIZE = void 0;
|
|
7
|
+
exports.getPaginationParam = getPaginationParam;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
const DEFAULT_PAGE_SIZE = exports.DEFAULT_PAGE_SIZE = 10;
|
|
10
|
+
function extendsObject(base, override, extra = {}) {
|
|
11
|
+
return {
|
|
12
|
+
...base,
|
|
13
|
+
...override,
|
|
14
|
+
...extra
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function getPaginationParam(mergedPagination, pagination) {
|
|
18
|
+
const param = {
|
|
19
|
+
current: mergedPagination.current,
|
|
20
|
+
pageSize: mergedPagination.pageSize
|
|
21
|
+
};
|
|
22
|
+
const paginationObj = pagination && typeof pagination === 'object' ? pagination : {};
|
|
23
|
+
Object.keys(paginationObj).forEach(pageProp => {
|
|
24
|
+
const value = mergedPagination[pageProp];
|
|
25
|
+
if (typeof value !== 'function') {
|
|
26
|
+
param[pageProp] = value;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return param;
|
|
30
|
+
}
|
|
31
|
+
function usePagination(total, onChange, pagination) {
|
|
32
|
+
const {
|
|
33
|
+
total: paginationTotal = 0,
|
|
34
|
+
...paginationObj
|
|
35
|
+
} = pagination && typeof pagination === 'object' ? pagination : {};
|
|
36
|
+
const [innerPagination, setInnerPagination] = (0, _react.useState)(() => ({
|
|
37
|
+
current: 'defaultCurrent' in paginationObj ? paginationObj.defaultCurrent : 1,
|
|
38
|
+
pageSize: 'defaultPageSize' in paginationObj ? paginationObj.defaultPageSize : DEFAULT_PAGE_SIZE
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
// ============ Basic Pagination Config ============
|
|
42
|
+
const mergedPagination = extendsObject(innerPagination, paginationObj, {
|
|
43
|
+
total: paginationTotal > 0 ? paginationTotal : total
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Reset `current` if data length or pageSize changed
|
|
47
|
+
const pageSize = mergedPagination.pageSize || DEFAULT_PAGE_SIZE;
|
|
48
|
+
const maxPage = Math.ceil((paginationTotal || total) / pageSize);
|
|
49
|
+
if ((mergedPagination.current || 1) > maxPage) {
|
|
50
|
+
// Prevent a maximum page count of 0
|
|
51
|
+
mergedPagination.current = maxPage || 1;
|
|
52
|
+
}
|
|
53
|
+
const refreshPagination = (current, pageSizeArg) => {
|
|
54
|
+
setInnerPagination({
|
|
55
|
+
current: current ?? 1,
|
|
56
|
+
pageSize: pageSizeArg || mergedPagination.pageSize
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
const onInternalChange = (current, pageSizeArg) => {
|
|
60
|
+
if (pagination && typeof pagination === 'object') {
|
|
61
|
+
pagination.onChange?.(current, pageSizeArg);
|
|
62
|
+
}
|
|
63
|
+
refreshPagination(current, pageSizeArg);
|
|
64
|
+
onChange(current, pageSizeArg || mergedPagination.pageSize);
|
|
65
|
+
};
|
|
66
|
+
if (pagination === false) {
|
|
67
|
+
return [{}, () => {}];
|
|
68
|
+
}
|
|
69
|
+
return [{
|
|
70
|
+
...mergedPagination,
|
|
71
|
+
onChange: onInternalChange
|
|
72
|
+
}, refreshPagination];
|
|
73
|
+
}
|
|
74
|
+
var _default = exports.default = usePagination;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { GetRowKey, TableRowSelection } from 'antd/lib/table/interface';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
type UseSelectionConfig<RecordType> = {
|
|
4
|
+
getRowKey: GetRowKey<RecordType>;
|
|
5
|
+
getRecordByKey: (key: React.Key) => RecordType | undefined;
|
|
6
|
+
prefixCls?: string;
|
|
7
|
+
data: RecordType[];
|
|
8
|
+
pageData: RecordType[];
|
|
9
|
+
expandType?: 'row' | 'nest';
|
|
10
|
+
childrenColumnName?: string;
|
|
11
|
+
locale?: any;
|
|
12
|
+
};
|
|
13
|
+
declare function useSelection<RecordType>(config: UseSelectionConfig<RecordType>, rowSelection?: TableRowSelection<RecordType>): readonly [
|
|
14
|
+
(columns?: any[]) => Array<{
|
|
15
|
+
render: (text: any, record: RecordType, index: number) => React.ReactElement;
|
|
16
|
+
}>,
|
|
17
|
+
Set<React.Key>
|
|
18
|
+
];
|
|
19
|
+
export default useSelection;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _antd = require("antd");
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
function useSelection(config, rowSelection) {
|
|
12
|
+
const {
|
|
13
|
+
getRowKey,
|
|
14
|
+
data
|
|
15
|
+
} = config;
|
|
16
|
+
const controlledKeys = rowSelection?.selectedRowKeys;
|
|
17
|
+
const [innerKeys, setInnerKeys] = _react.default.useState(controlledKeys || []);
|
|
18
|
+
|
|
19
|
+
// Keep in sync with controlled keys
|
|
20
|
+
_react.default.useEffect(() => {
|
|
21
|
+
if (controlledKeys) {
|
|
22
|
+
setInnerKeys(controlledKeys);
|
|
23
|
+
}
|
|
24
|
+
}, [controlledKeys && controlledKeys.join(';')]);
|
|
25
|
+
const selectedKeySet = _react.default.useMemo(() => new Set(innerKeys), [innerKeys]);
|
|
26
|
+
const toggleKey = _react.default.useCallback((key, record, checked) => {
|
|
27
|
+
setInnerKeys(prevKeys => {
|
|
28
|
+
const prevSet = new Set(prevKeys);
|
|
29
|
+
const next = new Set(prevSet);
|
|
30
|
+
if (checked) {
|
|
31
|
+
next.add(key);
|
|
32
|
+
} else {
|
|
33
|
+
next.delete(key);
|
|
34
|
+
}
|
|
35
|
+
const nextKeys = Array.from(next);
|
|
36
|
+
|
|
37
|
+
// Fire callbacks similar to antd rowSelection
|
|
38
|
+
const selectedRows = data.filter((item, idx) => next.has(getRowKey(item, idx)));
|
|
39
|
+
rowSelection?.onChange?.(nextKeys, selectedRows, {
|
|
40
|
+
type: 'multiple',
|
|
41
|
+
selectedRows,
|
|
42
|
+
selectedRowKeys: nextKeys
|
|
43
|
+
});
|
|
44
|
+
rowSelection?.onSelect?.(record, checked, data.filter((item, idx) => next.has(getRowKey(item, idx))), {});
|
|
45
|
+
if (!controlledKeys) {
|
|
46
|
+
return nextKeys;
|
|
47
|
+
}
|
|
48
|
+
return prevKeys;
|
|
49
|
+
});
|
|
50
|
+
}, [data, getRowKey, rowSelection, controlledKeys]);
|
|
51
|
+
const selectItemRender = _react.default.useCallback(columns => {
|
|
52
|
+
void columns;
|
|
53
|
+
return [{
|
|
54
|
+
render: (_text, record, index) => {
|
|
55
|
+
const key = getRowKey(record, index);
|
|
56
|
+
const checked = selectedKeySet.has(key);
|
|
57
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_antd.Checkbox, {
|
|
58
|
+
checked: checked,
|
|
59
|
+
onChange: e => {
|
|
60
|
+
toggleKey(key, record, e.target.checked);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}];
|
|
65
|
+
}, [getRowKey, selectedKeySet, toggleKey]);
|
|
66
|
+
return [selectItemRender, selectedKeySet];
|
|
67
|
+
}
|
|
68
|
+
var _default = exports.default = useSelection;
|