@kne/table-page 0.1.25 → 0.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +328 -6
- package/dist/index.css +35 -4
- package/dist/index.css.map +1 -1
- package/dist/index.js +110 -60
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +105 -58
- package/dist/index.modern.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1538,7 +1538,11 @@ const Table = p => {
|
|
|
1538
1538
|
return undefined;
|
|
1539
1539
|
}
|
|
1540
1540
|
const getRowKey = record => resolveRowKey(rowKey, record);
|
|
1541
|
-
|
|
1541
|
+
// 全选判断/操作只针对可勾选行,排除 disabled
|
|
1542
|
+
const allKeys = isTree ? ((treeKeyMaps == null ? void 0 : treeKeyMaps.allKeys) || []).filter(key => {
|
|
1543
|
+
var _treeKeyMaps$nodeMap$;
|
|
1544
|
+
return !((_treeKeyMaps$nodeMap$ = treeKeyMaps.nodeMap.get(key)) != null && _treeKeyMaps$nodeMap$.disabled);
|
|
1545
|
+
}) : (dataSource || []).filter(item => !item.disabled).map(getRowKey);
|
|
1542
1546
|
const useTreeCheck = isTree && rowSelection.type === 'checkbox' && checkRelation !== 'independent' && treeKeyMaps;
|
|
1543
1547
|
const renderSelectAllNode = () => {
|
|
1544
1548
|
if (rowSelection.type !== 'checkbox') {
|
|
@@ -1588,7 +1592,7 @@ const Table = p => {
|
|
|
1588
1592
|
});
|
|
1589
1593
|
}
|
|
1590
1594
|
const checkedAll = rowSelection.isSelectedAll || allKeys.length > 0 && allKeys.every(key => (rowSelection.selectedRowKeys || []).indexOf(key) > -1);
|
|
1591
|
-
const indeterminate = !checkedAll && (rowSelection.selectedRowKeys || []).
|
|
1595
|
+
const indeterminate = !checkedAll && allKeys.some(key => (rowSelection.selectedRowKeys || []).indexOf(key) > -1);
|
|
1592
1596
|
return /*#__PURE__*/jsxRuntime.jsx(antd.Checkbox, {
|
|
1593
1597
|
checked: checkedAll,
|
|
1594
1598
|
indeterminate: indeterminate,
|
|
@@ -1606,6 +1610,9 @@ const Table = p => {
|
|
|
1606
1610
|
});
|
|
1607
1611
|
return;
|
|
1608
1612
|
}
|
|
1613
|
+
if (allKeys.length === 0) {
|
|
1614
|
+
return;
|
|
1615
|
+
}
|
|
1609
1616
|
const merged = existing.slice();
|
|
1610
1617
|
allKeys.forEach(key => {
|
|
1611
1618
|
if (merged.indexOf(key) === -1) {
|
|
@@ -1720,39 +1727,13 @@ const Table = p => {
|
|
|
1720
1727
|
}
|
|
1721
1728
|
return _extends({
|
|
1722
1729
|
type: rowSelection.type === 'radio' ? 'radio' : 'checkbox',
|
|
1723
|
-
preserveSelectedRowKeys: true
|
|
1730
|
+
preserveSelectedRowKeys: true,
|
|
1731
|
+
hideSelectAll: true
|
|
1724
1732
|
}, hasFixedColumn ? {
|
|
1725
1733
|
fixed: 'left'
|
|
1726
1734
|
} : {}, {
|
|
1727
1735
|
selectedRowKeys: rowSelection.isSelectedAll ? allKeys : rowSelection.selectedRowKeys,
|
|
1728
|
-
onChange: (selectedRowKeys, selectedRows
|
|
1729
|
-
if (info.type === 'all') {
|
|
1730
|
-
const checked = selectedRowKeys.length > 0;
|
|
1731
|
-
if (typeof rowSelection.onIsSelectAllChange === 'function') {
|
|
1732
|
-
rowSelection.onIsSelectAllChange(checked);
|
|
1733
|
-
return;
|
|
1734
|
-
}
|
|
1735
|
-
const pageKeys = (dataSource || []).filter(item => !item.disabled).map(getRowKey);
|
|
1736
|
-
const existing = rowSelection.selectedRowKeys || [];
|
|
1737
|
-
if (!checked) {
|
|
1738
|
-
rowSelection.onChange(existing.filter(key => pageKeys.indexOf(key) === -1), undefined, {
|
|
1739
|
-
context,
|
|
1740
|
-
checked: false
|
|
1741
|
-
});
|
|
1742
|
-
return;
|
|
1743
|
-
}
|
|
1744
|
-
const merged = existing.slice();
|
|
1745
|
-
pageKeys.forEach(key => {
|
|
1746
|
-
if (merged.indexOf(key) === -1) {
|
|
1747
|
-
merged.push(key);
|
|
1748
|
-
}
|
|
1749
|
-
});
|
|
1750
|
-
rowSelection.onChange(merged, undefined, {
|
|
1751
|
-
context,
|
|
1752
|
-
checked: true
|
|
1753
|
-
});
|
|
1754
|
-
return;
|
|
1755
|
-
}
|
|
1736
|
+
onChange: (selectedRowKeys, selectedRows) => {
|
|
1756
1737
|
const currentKey = selectedRows.length > 0 ? getRowKey(selectedRows[selectedRows.length - 1]) : selectedRowKeys[selectedRowKeys.length - 1];
|
|
1757
1738
|
const checked = selectedRowKeys.indexOf(currentKey) > -1;
|
|
1758
1739
|
rowSelection.onChange(selectedRowKeys, currentKey, {
|
|
@@ -1764,17 +1745,14 @@ const Table = p => {
|
|
|
1764
1745
|
disabled: record.disabled || rowSelection.isSelectedAll
|
|
1765
1746
|
})
|
|
1766
1747
|
}, rowSelection.type === 'checkbox' ? {
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
visibility: 'hidden'
|
|
1770
|
-
}
|
|
1771
|
-
})),
|
|
1748
|
+
columnWidth: antdSelectionColumnWidth || 48,
|
|
1749
|
+
columnTitle: wrapColContent(renderSelectAllNode()),
|
|
1772
1750
|
renderCell: (checked, record, index, originNode) => wrapColContent(originNode),
|
|
1773
1751
|
onCell: () => ({
|
|
1774
1752
|
className: getAntCellClassName(style$2['selection-col'])
|
|
1775
1753
|
})
|
|
1776
1754
|
} : {
|
|
1777
|
-
columnWidth:
|
|
1755
|
+
columnWidth: antdSelectionColumnWidth || 48,
|
|
1778
1756
|
renderCell: (checked, record, index, originNode) => wrapColContent(originNode),
|
|
1779
1757
|
onCell: () => ({
|
|
1780
1758
|
className: getAntCellClassName(style$2['radio-col'])
|
|
@@ -1842,11 +1820,11 @@ const Table = p => {
|
|
|
1842
1820
|
if (cssValue) {
|
|
1843
1821
|
next['--scroll-top-inset'] = cssValue;
|
|
1844
1822
|
}
|
|
1845
|
-
if (
|
|
1823
|
+
if (antdSelectionColumnWidth) {
|
|
1846
1824
|
next['--selection-col-width'] = antdSelectionColumnWidth + "px";
|
|
1847
1825
|
}
|
|
1848
1826
|
return Object.keys(next).length > 0 ? next : undefined;
|
|
1849
|
-
}, [resolvedScrollTopInset,
|
|
1827
|
+
}, [resolvedScrollTopInset, antdSelectionColumnWidth]);
|
|
1850
1828
|
const useTreeCheckForRow = isTree && (rowSelection == null ? void 0 : rowSelection.type) === 'checkbox' && checkRelation !== 'independent' && treeKeyMaps;
|
|
1851
1829
|
if (useMobileRender) {
|
|
1852
1830
|
return /*#__PURE__*/jsxRuntime.jsx(TableView, _extends({}, others, {
|
|
@@ -2524,7 +2502,7 @@ const isPaginationSearchParamsEnabled = pagination => {
|
|
|
2524
2502
|
return !!(pagination?.searchParams && typeof pagination.setSearchParams === 'function');
|
|
2525
2503
|
};
|
|
2526
2504
|
|
|
2527
|
-
const _excluded = ["data", "refresh", "reload", "requestParams", "fetchProps", "isComplete", "loadMore", "send", "dataFormat", "className", "columns", "getColumns", "pagination", "columnRenderProps", "summary", "sticky", "scrollTopInset", "stickyOffset", "renderType", "horizontalScroller", "getScrollContainer", "filter", "search", "tab", "tabProps", "batchActions", "buttonGroup", "selectedRows", "rowSelection", "renderMobile", "renderCard", "forceCard", "mobileSortToolbar", "filterSeedParams"],
|
|
2505
|
+
const _excluded = ["data", "refresh", "reload", "requestParams", "fetchProps", "isComplete", "loadMore", "send", "dataFormat", "className", "columns", "getColumns", "pagination", "columnRenderProps", "summary", "sticky", "scrollTopInset", "stickyOffset", "renderType", "horizontalScroller", "getScrollContainer", "filter", "search", "tab", "tabProps", "batchActions", "buttonGroup", "selectedRows", "rowSelection", "renderMobile", "renderCard", "forceCard", "mobileSortToolbar", "filterSeedParams", "filterFetchApiRef"],
|
|
2528
2506
|
_excluded2 = ["loading"],
|
|
2529
2507
|
_excluded3 = ["pagination", "horizontalScroller", "getScrollContainer", "filter"],
|
|
2530
2508
|
_excluded4 = ["searchParamsValue"];
|
|
@@ -2938,6 +2916,7 @@ const TablePageInnerContent = withLocale(_ref3 => {
|
|
|
2938
2916
|
mobileSortToolbar = _ref3.mobileSortToolbar,
|
|
2939
2917
|
_ref3$filterSeedParam = _ref3.filterSeedParams,
|
|
2940
2918
|
filterSeedParams = _ref3$filterSeedParam === void 0 ? {} : _ref3$filterSeedParam,
|
|
2919
|
+
filterFetchApiRef = _ref3.filterFetchApiRef,
|
|
2941
2920
|
props = _objectWithoutPropertiesLoose(_ref3, _excluded);
|
|
2942
2921
|
const _useIntl = reactIntl.useIntl(),
|
|
2943
2922
|
formatMessage = _useIntl.formatMessage;
|
|
@@ -3029,6 +3008,32 @@ const TablePageInnerContent = withLocale(_ref3 => {
|
|
|
3029
3008
|
});
|
|
3030
3009
|
return merged;
|
|
3031
3010
|
});
|
|
3011
|
+
|
|
3012
|
+
// react-fetch 的 reload 以 props.data(首包种子)为底合并,裸调会丢掉当前已选筛选。
|
|
3013
|
+
// 对外(ref / batchActions / summary)统一注入 filterValue,保证 UI 与查询一致。
|
|
3014
|
+
// handleFilterChange 仍走原始 reload:setState 前要用新 value 组参,不能读旧 filterValue。
|
|
3015
|
+
const injectFilterParams = useRefCallback__default["default"](function (sendProps) {
|
|
3016
|
+
if (sendProps === void 0) {
|
|
3017
|
+
sendProps = {};
|
|
3018
|
+
}
|
|
3019
|
+
const paramsType = pagination.paramsType;
|
|
3020
|
+
const incoming = get__default["default"](sendProps, paramsType);
|
|
3021
|
+
return Object.assign({}, sendProps, {
|
|
3022
|
+
[paramsType]: buildRequestParamsWithFilter(filterValue, isPlainObject(incoming) ? incoming : {})
|
|
3023
|
+
});
|
|
3024
|
+
});
|
|
3025
|
+
const reloadWithFilter = useRefCallback__default["default"]((sendProps, force) => reload(injectFilterParams(sendProps), force));
|
|
3026
|
+
const refreshWithFilter = useRefCallback__default["default"]((sendProps, force) => refresh(injectFilterParams(sendProps), force));
|
|
3027
|
+
const sendWithFilter = useRefCallback__default["default"]((sendProps, force) => send(injectFilterParams(sendProps), force));
|
|
3028
|
+
const loadMoreWithFilter = useRefCallback__default["default"]((sendProps, callback, force) => loadMore(injectFilterParams(sendProps), callback, force));
|
|
3029
|
+
if (filterFetchApiRef) {
|
|
3030
|
+
filterFetchApiRef.current = {
|
|
3031
|
+
reload: reloadWithFilter,
|
|
3032
|
+
refresh: refreshWithFilter,
|
|
3033
|
+
send: sendWithFilter,
|
|
3034
|
+
loadMore: loadMoreWithFilter
|
|
3035
|
+
};
|
|
3036
|
+
}
|
|
3032
3037
|
const formatData = react.useMemo(() => {
|
|
3033
3038
|
return handlerDataFormat(data);
|
|
3034
3039
|
}, [data, handlerDataFormat]);
|
|
@@ -3037,13 +3042,13 @@ const TablePageInnerContent = withLocale(_ref3 => {
|
|
|
3037
3042
|
data,
|
|
3038
3043
|
fetchProps,
|
|
3039
3044
|
requestParams,
|
|
3040
|
-
refresh,
|
|
3041
|
-
reload,
|
|
3042
|
-
loadMore,
|
|
3043
|
-
send,
|
|
3045
|
+
refresh: refreshWithFilter,
|
|
3046
|
+
reload: reloadWithFilter,
|
|
3047
|
+
loadMore: loadMoreWithFilter,
|
|
3048
|
+
send: sendWithFilter,
|
|
3044
3049
|
dataFormat,
|
|
3045
3050
|
pagination
|
|
3046
|
-
}), [data, fetchProps, requestParams,
|
|
3051
|
+
}), [data, fetchProps, requestParams, refreshWithFilter, reloadWithFilter, loadMoreWithFilter, sendWithFilter, dataFormat, pagination]);
|
|
3047
3052
|
const hasTab = !!(tab != null && tab.name && Array.isArray(tab.list) && tab.list.length > 0);
|
|
3048
3053
|
const hasInnerToolbar = !!(filter != null && (_filter$list3 = filter.list) != null && _filter$list3.length || search && search.name || batchActions && batchActions.length || showButtonGroup || showCardModeToggle);
|
|
3049
3054
|
const showOuterTab = hasTab && !isMobile;
|
|
@@ -3187,13 +3192,13 @@ const TablePageInnerContent = withLocale(_ref3 => {
|
|
|
3187
3192
|
data,
|
|
3188
3193
|
fetchProps,
|
|
3189
3194
|
requestParams,
|
|
3190
|
-
refresh,
|
|
3191
|
-
reload,
|
|
3192
|
-
loadMore,
|
|
3193
|
-
send,
|
|
3195
|
+
refresh: refreshWithFilter,
|
|
3196
|
+
reload: reloadWithFilter,
|
|
3197
|
+
loadMore: loadMoreWithFilter,
|
|
3198
|
+
send: sendWithFilter,
|
|
3194
3199
|
dataFormat,
|
|
3195
3200
|
pagination
|
|
3196
|
-
}), [data, fetchProps, requestParams,
|
|
3201
|
+
}), [data, fetchProps, requestParams, refreshWithFilter, reloadWithFilter, loadMoreWithFilter, sendWithFilter, dataFormat, pagination]);
|
|
3197
3202
|
const tableContext = _extends({}, columnRenderProps, {
|
|
3198
3203
|
requestParams,
|
|
3199
3204
|
fetchProps,
|
|
@@ -3332,11 +3337,56 @@ const TablePageInner = /*#__PURE__*/react.forwardRef((props, ref) => {
|
|
|
3332
3337
|
const isMobile = responsiveUtils.useIsMobile();
|
|
3333
3338
|
const loadingProp = props.loading,
|
|
3334
3339
|
rest = _objectWithoutPropertiesLoose(props, _excluded2);
|
|
3340
|
+
const fetchRef = react.useRef(null);
|
|
3341
|
+
const filterFetchApiRef = react.useRef(null);
|
|
3335
3342
|
const reserveToolbar = hasToolbarArea(props, isMobile);
|
|
3336
3343
|
const loading = loadingProp !== undefined ? loadingProp : /*#__PURE__*/jsxRuntime.jsx(TablePageLoadingShell, _extends({}, props));
|
|
3344
|
+
react.useImperativeHandle(ref, () => ({
|
|
3345
|
+
get isLoading() {
|
|
3346
|
+
var _fetchRef$current;
|
|
3347
|
+
return (_fetchRef$current = fetchRef.current) == null ? void 0 : _fetchRef$current.isLoading;
|
|
3348
|
+
},
|
|
3349
|
+
get isComplete() {
|
|
3350
|
+
var _fetchRef$current2;
|
|
3351
|
+
return (_fetchRef$current2 = fetchRef.current) == null ? void 0 : _fetchRef$current2.isComplete;
|
|
3352
|
+
},
|
|
3353
|
+
get data() {
|
|
3354
|
+
var _fetchRef$current3;
|
|
3355
|
+
return (_fetchRef$current3 = fetchRef.current) == null ? void 0 : _fetchRef$current3.data;
|
|
3356
|
+
},
|
|
3357
|
+
get requestParams() {
|
|
3358
|
+
var _fetchRef$current4;
|
|
3359
|
+
return (_fetchRef$current4 = fetchRef.current) == null ? void 0 : _fetchRef$current4.requestParams;
|
|
3360
|
+
},
|
|
3361
|
+
get error() {
|
|
3362
|
+
var _fetchRef$current5;
|
|
3363
|
+
return (_fetchRef$current5 = fetchRef.current) == null ? void 0 : _fetchRef$current5.error;
|
|
3364
|
+
},
|
|
3365
|
+
get setData() {
|
|
3366
|
+
var _fetchRef$current6;
|
|
3367
|
+
return (_fetchRef$current6 = fetchRef.current) == null ? void 0 : _fetchRef$current6.setData;
|
|
3368
|
+
},
|
|
3369
|
+
send: function () {
|
|
3370
|
+
var _ref4, _filterFetchApiRef$cu, _fetchRef$current7;
|
|
3371
|
+
return (_ref4 = ((_filterFetchApiRef$cu = filterFetchApiRef.current) == null ? void 0 : _filterFetchApiRef$cu.send) || ((_fetchRef$current7 = fetchRef.current) == null ? void 0 : _fetchRef$current7.send)) == null ? void 0 : _ref4(...[].slice.call(arguments));
|
|
3372
|
+
},
|
|
3373
|
+
refresh: function () {
|
|
3374
|
+
var _ref5, _filterFetchApiRef$cu2, _fetchRef$current8;
|
|
3375
|
+
return (_ref5 = ((_filterFetchApiRef$cu2 = filterFetchApiRef.current) == null ? void 0 : _filterFetchApiRef$cu2.refresh) || ((_fetchRef$current8 = fetchRef.current) == null ? void 0 : _fetchRef$current8.refresh)) == null ? void 0 : _ref5(...[].slice.call(arguments));
|
|
3376
|
+
},
|
|
3377
|
+
reload: function () {
|
|
3378
|
+
var _ref6, _filterFetchApiRef$cu3, _fetchRef$current9;
|
|
3379
|
+
return (_ref6 = ((_filterFetchApiRef$cu3 = filterFetchApiRef.current) == null ? void 0 : _filterFetchApiRef$cu3.reload) || ((_fetchRef$current9 = fetchRef.current) == null ? void 0 : _fetchRef$current9.reload)) == null ? void 0 : _ref6(...[].slice.call(arguments));
|
|
3380
|
+
},
|
|
3381
|
+
loadMore: function () {
|
|
3382
|
+
var _ref7, _filterFetchApiRef$cu4, _fetchRef$current0;
|
|
3383
|
+
return (_ref7 = ((_filterFetchApiRef$cu4 = filterFetchApiRef.current) == null ? void 0 : _filterFetchApiRef$cu4.loadMore) || ((_fetchRef$current0 = fetchRef.current) == null ? void 0 : _fetchRef$current0.loadMore)) == null ? void 0 : _ref7(...[].slice.call(arguments));
|
|
3384
|
+
}
|
|
3385
|
+
}));
|
|
3337
3386
|
const fetched = /*#__PURE__*/jsxRuntime.jsx(TablePageFetched, _extends({}, rest, {
|
|
3338
3387
|
loading: loading,
|
|
3339
|
-
ref:
|
|
3388
|
+
ref: fetchRef,
|
|
3389
|
+
filterFetchApiRef: filterFetchApiRef
|
|
3340
3390
|
}));
|
|
3341
3391
|
if (!reserveToolbar) {
|
|
3342
3392
|
return fetched;
|
|
@@ -3349,13 +3399,13 @@ const TablePageInner = /*#__PURE__*/react.forwardRef((props, ref) => {
|
|
|
3349
3399
|
}), fetched]
|
|
3350
3400
|
});
|
|
3351
3401
|
});
|
|
3352
|
-
const TablePage = /*#__PURE__*/react.forwardRef((
|
|
3353
|
-
let pagination =
|
|
3354
|
-
|
|
3355
|
-
horizontalScroller =
|
|
3356
|
-
getScrollContainer =
|
|
3357
|
-
filterProp =
|
|
3358
|
-
props = _objectWithoutPropertiesLoose(
|
|
3402
|
+
const TablePage = /*#__PURE__*/react.forwardRef((_ref8, ref) => {
|
|
3403
|
+
let pagination = _ref8.pagination,
|
|
3404
|
+
_ref8$horizontalScrol = _ref8.horizontalScroller,
|
|
3405
|
+
horizontalScroller = _ref8$horizontalScrol === void 0 ? true : _ref8$horizontalScrol,
|
|
3406
|
+
getScrollContainer = _ref8.getScrollContainer,
|
|
3407
|
+
filterProp = _ref8.filter,
|
|
3408
|
+
props = _objectWithoutPropertiesLoose(_ref8, _excluded3);
|
|
3359
3409
|
pagination = Object.assign({}, {
|
|
3360
3410
|
showSizeChanger: true,
|
|
3361
3411
|
showQuickJumper: true,
|
|
@@ -3376,8 +3426,8 @@ const TablePage = /*#__PURE__*/react.forwardRef((_ref4, ref) => {
|
|
|
3376
3426
|
}) : {}),
|
|
3377
3427
|
urlPagination = _useState2[0];
|
|
3378
3428
|
const _useState3 = react.useState(() => {
|
|
3379
|
-
var
|
|
3380
|
-
return (
|
|
3429
|
+
var _ref9, _urlPagination$pageSi;
|
|
3430
|
+
return (_ref9 = (_urlPagination$pageSi = urlPagination.pageSize) != null ? _urlPagination$pageSi : cachePageSize ? readPageSize(pageSizeKey) : null) != null ? _ref9 : pagination.pageSize;
|
|
3381
3431
|
}),
|
|
3382
3432
|
pageSize = _useState3[0],
|
|
3383
3433
|
setPageSize = _useState3[1];
|