@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.modern.js
CHANGED
|
@@ -5,7 +5,7 @@ import { Checkbox, Row, Col, Input, List, Tooltip, Button, Collapse, Popover, Em
|
|
|
5
5
|
import { HolderOutlined, RedoOutlined, SettingOutlined, LoadingOutlined, CaretRightOutlined, DownOutlined, MinusSquareOutlined, TableOutlined, AppstoreOutlined } from '@ant-design/icons';
|
|
6
6
|
import { SearchInput, FilterLines, FilterOuter, FilterValueDisplay, getFilterValue } from '@kne/react-filter';
|
|
7
7
|
import ScrollLoader from '@kne/scroll-loader';
|
|
8
|
-
import { useState, useMemo, useRef, useCallback, useEffect, useLayoutEffect, forwardRef } from 'react';
|
|
8
|
+
import { useState, useMemo, useRef, useCallback, useEffect, useLayoutEffect, forwardRef, useImperativeHandle } from 'react';
|
|
9
9
|
import classnames from 'classnames';
|
|
10
10
|
import get from 'lodash/get';
|
|
11
11
|
import { TableView as TableView$1, isOptionsColumn, parseColumnWidth, isTreeDataType, normalizeTreeData, collectExpandableKeys, buildTreeKeyMaps, nodeCanExpand, isRenderMobileActive, resolveColumns, resolveCheckRelation, flattenVisibleTree, getTreeSelectionColumnWidth, toggleExpandedKey, getTreeCheckState, useSelectedRow, useSort, wrapColumnHeaderTitle, isAllTreeSelected, hasAnyTreeSelected, buildSelectAllKeys, buildClearSelectAllKeys, toggleTreeCheck, renderColumnTitle, getColumnEllipsis, computeColumnsValue, renderCellContent, computeDisplay, globalParams } from '@kne/table-view';
|
|
@@ -1481,7 +1481,11 @@ const Table = p => {
|
|
|
1481
1481
|
return undefined;
|
|
1482
1482
|
}
|
|
1483
1483
|
const getRowKey = record => resolveRowKey(rowKey, record);
|
|
1484
|
-
|
|
1484
|
+
// 全选判断/操作只针对可勾选行,排除 disabled
|
|
1485
|
+
const allKeys = isTree ? ((treeKeyMaps == null ? void 0 : treeKeyMaps.allKeys) || []).filter(key => {
|
|
1486
|
+
var _treeKeyMaps$nodeMap$;
|
|
1487
|
+
return !((_treeKeyMaps$nodeMap$ = treeKeyMaps.nodeMap.get(key)) != null && _treeKeyMaps$nodeMap$.disabled);
|
|
1488
|
+
}) : (dataSource || []).filter(item => !item.disabled).map(getRowKey);
|
|
1485
1489
|
const useTreeCheck = isTree && rowSelection.type === 'checkbox' && checkRelation !== 'independent' && treeKeyMaps;
|
|
1486
1490
|
const renderSelectAllNode = () => {
|
|
1487
1491
|
if (rowSelection.type !== 'checkbox') {
|
|
@@ -1531,7 +1535,7 @@ const Table = p => {
|
|
|
1531
1535
|
});
|
|
1532
1536
|
}
|
|
1533
1537
|
const checkedAll = rowSelection.isSelectedAll || allKeys.length > 0 && allKeys.every(key => (rowSelection.selectedRowKeys || []).indexOf(key) > -1);
|
|
1534
|
-
const indeterminate = !checkedAll && (rowSelection.selectedRowKeys || []).
|
|
1538
|
+
const indeterminate = !checkedAll && allKeys.some(key => (rowSelection.selectedRowKeys || []).indexOf(key) > -1);
|
|
1535
1539
|
return /*#__PURE__*/jsx(Checkbox, {
|
|
1536
1540
|
checked: checkedAll,
|
|
1537
1541
|
indeterminate: indeterminate,
|
|
@@ -1549,6 +1553,9 @@ const Table = p => {
|
|
|
1549
1553
|
});
|
|
1550
1554
|
return;
|
|
1551
1555
|
}
|
|
1556
|
+
if (allKeys.length === 0) {
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1552
1559
|
const merged = existing.slice();
|
|
1553
1560
|
allKeys.forEach(key => {
|
|
1554
1561
|
if (merged.indexOf(key) === -1) {
|
|
@@ -1663,39 +1670,13 @@ const Table = p => {
|
|
|
1663
1670
|
}
|
|
1664
1671
|
return _extends({
|
|
1665
1672
|
type: rowSelection.type === 'radio' ? 'radio' : 'checkbox',
|
|
1666
|
-
preserveSelectedRowKeys: true
|
|
1673
|
+
preserveSelectedRowKeys: true,
|
|
1674
|
+
hideSelectAll: true
|
|
1667
1675
|
}, hasFixedColumn ? {
|
|
1668
1676
|
fixed: 'left'
|
|
1669
1677
|
} : {}, {
|
|
1670
1678
|
selectedRowKeys: rowSelection.isSelectedAll ? allKeys : rowSelection.selectedRowKeys,
|
|
1671
|
-
onChange: (selectedRowKeys, selectedRows
|
|
1672
|
-
if (info.type === 'all') {
|
|
1673
|
-
const _checked = selectedRowKeys.length > 0;
|
|
1674
|
-
if (typeof rowSelection.onIsSelectAllChange === 'function') {
|
|
1675
|
-
rowSelection.onIsSelectAllChange(_checked);
|
|
1676
|
-
return;
|
|
1677
|
-
}
|
|
1678
|
-
const pageKeys = (dataSource || []).filter(item => !item.disabled).map(getRowKey);
|
|
1679
|
-
const existing = rowSelection.selectedRowKeys || [];
|
|
1680
|
-
if (!_checked) {
|
|
1681
|
-
rowSelection.onChange(existing.filter(key => pageKeys.indexOf(key) === -1), undefined, {
|
|
1682
|
-
context,
|
|
1683
|
-
checked: false
|
|
1684
|
-
});
|
|
1685
|
-
return;
|
|
1686
|
-
}
|
|
1687
|
-
const merged = existing.slice();
|
|
1688
|
-
pageKeys.forEach(key => {
|
|
1689
|
-
if (merged.indexOf(key) === -1) {
|
|
1690
|
-
merged.push(key);
|
|
1691
|
-
}
|
|
1692
|
-
});
|
|
1693
|
-
rowSelection.onChange(merged, undefined, {
|
|
1694
|
-
context,
|
|
1695
|
-
checked: true
|
|
1696
|
-
});
|
|
1697
|
-
return;
|
|
1698
|
-
}
|
|
1679
|
+
onChange: (selectedRowKeys, selectedRows) => {
|
|
1699
1680
|
const currentKey = selectedRows.length > 0 ? getRowKey(selectedRows[selectedRows.length - 1]) : selectedRowKeys[selectedRowKeys.length - 1];
|
|
1700
1681
|
const checked = selectedRowKeys.indexOf(currentKey) > -1;
|
|
1701
1682
|
rowSelection.onChange(selectedRowKeys, currentKey, {
|
|
@@ -1707,17 +1688,14 @@ const Table = p => {
|
|
|
1707
1688
|
disabled: record.disabled || rowSelection.isSelectedAll
|
|
1708
1689
|
})
|
|
1709
1690
|
}, rowSelection.type === 'checkbox' ? {
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
visibility: 'hidden'
|
|
1713
|
-
}
|
|
1714
|
-
})),
|
|
1691
|
+
columnWidth: antdSelectionColumnWidth || 48,
|
|
1692
|
+
columnTitle: wrapColContent(renderSelectAllNode()),
|
|
1715
1693
|
renderCell: (checked, record, index, originNode) => wrapColContent(originNode),
|
|
1716
1694
|
onCell: () => ({
|
|
1717
1695
|
className: getAntCellClassName(style$2['selection-col'])
|
|
1718
1696
|
})
|
|
1719
1697
|
} : {
|
|
1720
|
-
columnWidth:
|
|
1698
|
+
columnWidth: antdSelectionColumnWidth || 48,
|
|
1721
1699
|
renderCell: (checked, record, index, originNode) => wrapColContent(originNode),
|
|
1722
1700
|
onCell: () => ({
|
|
1723
1701
|
className: getAntCellClassName(style$2['radio-col'])
|
|
@@ -1785,11 +1763,11 @@ const Table = p => {
|
|
|
1785
1763
|
if (cssValue) {
|
|
1786
1764
|
next['--scroll-top-inset'] = cssValue;
|
|
1787
1765
|
}
|
|
1788
|
-
if (
|
|
1766
|
+
if (antdSelectionColumnWidth) {
|
|
1789
1767
|
next['--selection-col-width'] = `${antdSelectionColumnWidth}px`;
|
|
1790
1768
|
}
|
|
1791
1769
|
return Object.keys(next).length > 0 ? next : undefined;
|
|
1792
|
-
}, [resolvedScrollTopInset,
|
|
1770
|
+
}, [resolvedScrollTopInset, antdSelectionColumnWidth]);
|
|
1793
1771
|
const useTreeCheckForRow = isTree && (rowSelection == null ? void 0 : rowSelection.type) === 'checkbox' && checkRelation !== 'independent' && treeKeyMaps;
|
|
1794
1772
|
if (useMobileRender) {
|
|
1795
1773
|
return /*#__PURE__*/jsx(TableView, _extends({}, others, {
|
|
@@ -2460,7 +2438,7 @@ const isPaginationSearchParamsEnabled = pagination => {
|
|
|
2460
2438
|
return !!(pagination != null && pagination.searchParams && typeof pagination.setSearchParams === 'function');
|
|
2461
2439
|
};
|
|
2462
2440
|
|
|
2463
|
-
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"],
|
|
2441
|
+
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"],
|
|
2464
2442
|
_excluded2 = ["loading"],
|
|
2465
2443
|
_excluded3 = ["pagination", "horizontalScroller", "getScrollContainer", "filter"],
|
|
2466
2444
|
_excluded4 = ["searchParamsValue"];
|
|
@@ -2856,7 +2834,8 @@ const TablePageInnerContent = withLocale(_ref => {
|
|
|
2856
2834
|
renderCard,
|
|
2857
2835
|
forceCard = false,
|
|
2858
2836
|
mobileSortToolbar,
|
|
2859
|
-
filterSeedParams = {}
|
|
2837
|
+
filterSeedParams = {},
|
|
2838
|
+
filterFetchApiRef
|
|
2860
2839
|
} = _ref,
|
|
2861
2840
|
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
2862
2841
|
const {
|
|
@@ -2943,6 +2922,29 @@ const TablePageInnerContent = withLocale(_ref => {
|
|
|
2943
2922
|
});
|
|
2944
2923
|
return merged;
|
|
2945
2924
|
});
|
|
2925
|
+
|
|
2926
|
+
// react-fetch 的 reload 以 props.data(首包种子)为底合并,裸调会丢掉当前已选筛选。
|
|
2927
|
+
// 对外(ref / batchActions / summary)统一注入 filterValue,保证 UI 与查询一致。
|
|
2928
|
+
// handleFilterChange 仍走原始 reload:setState 前要用新 value 组参,不能读旧 filterValue。
|
|
2929
|
+
const injectFilterParams = useRefCallback((sendProps = {}) => {
|
|
2930
|
+
const paramsType = pagination.paramsType;
|
|
2931
|
+
const incoming = get(sendProps, paramsType);
|
|
2932
|
+
return Object.assign({}, sendProps, {
|
|
2933
|
+
[paramsType]: buildRequestParamsWithFilter(filterValue, isPlainObject(incoming) ? incoming : {})
|
|
2934
|
+
});
|
|
2935
|
+
});
|
|
2936
|
+
const reloadWithFilter = useRefCallback((sendProps, force) => reload(injectFilterParams(sendProps), force));
|
|
2937
|
+
const refreshWithFilter = useRefCallback((sendProps, force) => refresh(injectFilterParams(sendProps), force));
|
|
2938
|
+
const sendWithFilter = useRefCallback((sendProps, force) => send(injectFilterParams(sendProps), force));
|
|
2939
|
+
const loadMoreWithFilter = useRefCallback((sendProps, callback, force) => loadMore(injectFilterParams(sendProps), callback, force));
|
|
2940
|
+
if (filterFetchApiRef) {
|
|
2941
|
+
filterFetchApiRef.current = {
|
|
2942
|
+
reload: reloadWithFilter,
|
|
2943
|
+
refresh: refreshWithFilter,
|
|
2944
|
+
send: sendWithFilter,
|
|
2945
|
+
loadMore: loadMoreWithFilter
|
|
2946
|
+
};
|
|
2947
|
+
}
|
|
2946
2948
|
const formatData = useMemo(() => {
|
|
2947
2949
|
return handlerDataFormat(data);
|
|
2948
2950
|
}, [data, handlerDataFormat]);
|
|
@@ -2951,13 +2953,13 @@ const TablePageInnerContent = withLocale(_ref => {
|
|
|
2951
2953
|
data,
|
|
2952
2954
|
fetchProps,
|
|
2953
2955
|
requestParams,
|
|
2954
|
-
refresh,
|
|
2955
|
-
reload,
|
|
2956
|
-
loadMore,
|
|
2957
|
-
send,
|
|
2956
|
+
refresh: refreshWithFilter,
|
|
2957
|
+
reload: reloadWithFilter,
|
|
2958
|
+
loadMore: loadMoreWithFilter,
|
|
2959
|
+
send: sendWithFilter,
|
|
2958
2960
|
dataFormat,
|
|
2959
2961
|
pagination
|
|
2960
|
-
}), [data, fetchProps, requestParams,
|
|
2962
|
+
}), [data, fetchProps, requestParams, refreshWithFilter, reloadWithFilter, loadMoreWithFilter, sendWithFilter, dataFormat, pagination]);
|
|
2961
2963
|
const hasTab = !!(tab != null && tab.name && Array.isArray(tab.list) && tab.list.length > 0);
|
|
2962
2964
|
const hasInnerToolbar = !!(filter != null && (_filter$list3 = filter.list) != null && _filter$list3.length || search && search.name || batchActions && batchActions.length || showButtonGroup || showCardModeToggle);
|
|
2963
2965
|
const showOuterTab = hasTab && !isMobile;
|
|
@@ -3097,13 +3099,13 @@ const TablePageInnerContent = withLocale(_ref => {
|
|
|
3097
3099
|
data,
|
|
3098
3100
|
fetchProps,
|
|
3099
3101
|
requestParams,
|
|
3100
|
-
refresh,
|
|
3101
|
-
reload,
|
|
3102
|
-
loadMore,
|
|
3103
|
-
send,
|
|
3102
|
+
refresh: refreshWithFilter,
|
|
3103
|
+
reload: reloadWithFilter,
|
|
3104
|
+
loadMore: loadMoreWithFilter,
|
|
3105
|
+
send: sendWithFilter,
|
|
3104
3106
|
dataFormat,
|
|
3105
3107
|
pagination
|
|
3106
|
-
}), [data, fetchProps, requestParams,
|
|
3108
|
+
}), [data, fetchProps, requestParams, refreshWithFilter, reloadWithFilter, loadMoreWithFilter, sendWithFilter, dataFormat, pagination]);
|
|
3107
3109
|
const tableContext = _extends({}, columnRenderProps, {
|
|
3108
3110
|
requestParams,
|
|
3109
3111
|
fetchProps,
|
|
@@ -3244,11 +3246,56 @@ const TablePageInner = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
3244
3246
|
loading: loadingProp
|
|
3245
3247
|
} = props,
|
|
3246
3248
|
rest = _objectWithoutPropertiesLoose(props, _excluded2);
|
|
3249
|
+
const fetchRef = useRef(null);
|
|
3250
|
+
const filterFetchApiRef = useRef(null);
|
|
3247
3251
|
const reserveToolbar = hasToolbarArea(props, isMobile);
|
|
3248
3252
|
const loading = loadingProp !== undefined ? loadingProp : /*#__PURE__*/jsx(TablePageLoadingShell, _extends({}, props));
|
|
3253
|
+
useImperativeHandle(ref, () => ({
|
|
3254
|
+
get isLoading() {
|
|
3255
|
+
var _fetchRef$current;
|
|
3256
|
+
return (_fetchRef$current = fetchRef.current) == null ? void 0 : _fetchRef$current.isLoading;
|
|
3257
|
+
},
|
|
3258
|
+
get isComplete() {
|
|
3259
|
+
var _fetchRef$current2;
|
|
3260
|
+
return (_fetchRef$current2 = fetchRef.current) == null ? void 0 : _fetchRef$current2.isComplete;
|
|
3261
|
+
},
|
|
3262
|
+
get data() {
|
|
3263
|
+
var _fetchRef$current3;
|
|
3264
|
+
return (_fetchRef$current3 = fetchRef.current) == null ? void 0 : _fetchRef$current3.data;
|
|
3265
|
+
},
|
|
3266
|
+
get requestParams() {
|
|
3267
|
+
var _fetchRef$current4;
|
|
3268
|
+
return (_fetchRef$current4 = fetchRef.current) == null ? void 0 : _fetchRef$current4.requestParams;
|
|
3269
|
+
},
|
|
3270
|
+
get error() {
|
|
3271
|
+
var _fetchRef$current5;
|
|
3272
|
+
return (_fetchRef$current5 = fetchRef.current) == null ? void 0 : _fetchRef$current5.error;
|
|
3273
|
+
},
|
|
3274
|
+
get setData() {
|
|
3275
|
+
var _fetchRef$current6;
|
|
3276
|
+
return (_fetchRef$current6 = fetchRef.current) == null ? void 0 : _fetchRef$current6.setData;
|
|
3277
|
+
},
|
|
3278
|
+
send: (...args) => {
|
|
3279
|
+
var _ref2, _filterFetchApiRef$cu, _fetchRef$current7;
|
|
3280
|
+
return (_ref2 = ((_filterFetchApiRef$cu = filterFetchApiRef.current) == null ? void 0 : _filterFetchApiRef$cu.send) || ((_fetchRef$current7 = fetchRef.current) == null ? void 0 : _fetchRef$current7.send)) == null ? void 0 : _ref2(...args);
|
|
3281
|
+
},
|
|
3282
|
+
refresh: (...args) => {
|
|
3283
|
+
var _ref3, _filterFetchApiRef$cu2, _fetchRef$current8;
|
|
3284
|
+
return (_ref3 = ((_filterFetchApiRef$cu2 = filterFetchApiRef.current) == null ? void 0 : _filterFetchApiRef$cu2.refresh) || ((_fetchRef$current8 = fetchRef.current) == null ? void 0 : _fetchRef$current8.refresh)) == null ? void 0 : _ref3(...args);
|
|
3285
|
+
},
|
|
3286
|
+
reload: (...args) => {
|
|
3287
|
+
var _ref4, _filterFetchApiRef$cu3, _fetchRef$current9;
|
|
3288
|
+
return (_ref4 = ((_filterFetchApiRef$cu3 = filterFetchApiRef.current) == null ? void 0 : _filterFetchApiRef$cu3.reload) || ((_fetchRef$current9 = fetchRef.current) == null ? void 0 : _fetchRef$current9.reload)) == null ? void 0 : _ref4(...args);
|
|
3289
|
+
},
|
|
3290
|
+
loadMore: (...args) => {
|
|
3291
|
+
var _ref5, _filterFetchApiRef$cu4, _fetchRef$current0;
|
|
3292
|
+
return (_ref5 = ((_filterFetchApiRef$cu4 = filterFetchApiRef.current) == null ? void 0 : _filterFetchApiRef$cu4.loadMore) || ((_fetchRef$current0 = fetchRef.current) == null ? void 0 : _fetchRef$current0.loadMore)) == null ? void 0 : _ref5(...args);
|
|
3293
|
+
}
|
|
3294
|
+
}));
|
|
3249
3295
|
const fetched = /*#__PURE__*/jsx(TablePageFetched, _extends({}, rest, {
|
|
3250
3296
|
loading: loading,
|
|
3251
|
-
ref:
|
|
3297
|
+
ref: fetchRef,
|
|
3298
|
+
filterFetchApiRef: filterFetchApiRef
|
|
3252
3299
|
}));
|
|
3253
3300
|
if (!reserveToolbar) {
|
|
3254
3301
|
return fetched;
|
|
@@ -3261,14 +3308,14 @@ const TablePageInner = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
3261
3308
|
}), fetched]
|
|
3262
3309
|
});
|
|
3263
3310
|
});
|
|
3264
|
-
const TablePage = /*#__PURE__*/forwardRef((
|
|
3311
|
+
const TablePage = /*#__PURE__*/forwardRef((_ref6, ref) => {
|
|
3265
3312
|
let {
|
|
3266
3313
|
pagination,
|
|
3267
3314
|
horizontalScroller = true,
|
|
3268
3315
|
getScrollContainer,
|
|
3269
3316
|
filter: filterProp
|
|
3270
|
-
} =
|
|
3271
|
-
props = _objectWithoutPropertiesLoose(
|
|
3317
|
+
} = _ref6,
|
|
3318
|
+
props = _objectWithoutPropertiesLoose(_ref6, _excluded3);
|
|
3272
3319
|
pagination = Object.assign({}, {
|
|
3273
3320
|
showSizeChanger: true,
|
|
3274
3321
|
showQuickJumper: true,
|
|
@@ -3288,8 +3335,8 @@ const TablePage = /*#__PURE__*/forwardRef((_ref2, ref) => {
|
|
|
3288
3335
|
pageSizeName: pagination.pageSizeName
|
|
3289
3336
|
}) : {});
|
|
3290
3337
|
const [pageSize, setPageSize] = useState(() => {
|
|
3291
|
-
var
|
|
3292
|
-
return (
|
|
3338
|
+
var _ref7, _urlPagination$pageSi;
|
|
3339
|
+
return (_ref7 = (_urlPagination$pageSi = urlPagination.pageSize) != null ? _urlPagination$pageSi : cachePageSize ? readPageSize(pageSizeKey) : null) != null ? _ref7 : pagination.pageSize;
|
|
3293
3340
|
});
|
|
3294
3341
|
const [initialCurrent] = useState(() => {
|
|
3295
3342
|
if (urlPagination.current != null) {
|