@kne/table-page 0.1.25 → 0.1.30

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/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
- const allKeys = isTree ? (treeKeyMaps == null ? void 0 : treeKeyMaps.allKeys) || [] : (dataSource || []).filter(item => !item.disabled).map(getRowKey);
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 || []).length > 0;
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, info) => {
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
- columnTitle: rowSelection.allowSelectedAll ? checkboxNode => wrapColContent(checkboxNode) : wrapColContent(/*#__PURE__*/jsxRuntime.jsx(antd.Checkbox, {
1768
- style: {
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: 30,
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 (isTree && antdSelectionColumnWidth) {
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, isTree, antdSelectionColumnWidth]);
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, {
@@ -1998,7 +1976,7 @@ const resolveButtonGroupProps = (buttonGroup, getPopupContainer, {
1998
1976
  getPopupContainer: userGetPopupContainer,
1999
1977
  ...rest
2000
1978
  } = buttonGroup;
2001
- const resolvedShowLength = Number.isInteger(showLength) ? Math.max(minShowLength, showLength) : defaultShowLength;
1979
+ const resolvedShowLength = Number.isInteger(showLength) ? Math.max(minShowLength, showLength) : Number.isInteger(defaultShowLength) ? defaultShowLength : undefined;
2002
1980
  return {
2003
1981
  ...rest,
2004
1982
  list: normalizeButtonGroupList(list, defaultSize),
@@ -2008,14 +1986,17 @@ const resolveButtonGroupProps = (buttonGroup, getPopupContainer, {
2008
1986
  size
2009
1987
  } : {}),
2010
1988
  moreType: moreType ?? 'link',
2011
- showLength: resolvedShowLength,
1989
+ ...(resolvedShowLength !== undefined ? {
1990
+ showLength: resolvedShowLength
1991
+ } : {}),
2012
1992
  getPopupContainer: userGetPopupContainer ?? getPopupContainer
2013
1993
  };
2014
1994
  };
2015
1995
  const resolveToolbarButtonGroupProps = (buttonGroup, getPopupContainer) => {
2016
1996
  return resolveButtonGroupProps(buttonGroup, getPopupContainer, {
2017
1997
  defaultSize: 'small',
2018
- defaultShowLength: 1,
1998
+ // 未显式传 showLength 时走 ButtonGroup 自适应测宽(@kne/overflow-items)
1999
+ defaultShowLength: undefined,
2019
2000
  minShowLength: 1
2020
2001
  });
2021
2002
  };
@@ -2524,7 +2505,7 @@ const isPaginationSearchParamsEnabled = pagination => {
2524
2505
  return !!(pagination?.searchParams && typeof pagination.setSearchParams === 'function');
2525
2506
  };
2526
2507
 
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"],
2508
+ 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
2509
  _excluded2 = ["loading"],
2529
2510
  _excluded3 = ["pagination", "horizontalScroller", "getScrollContainer", "filter"],
2530
2511
  _excluded4 = ["searchParamsValue"];
@@ -2938,6 +2919,7 @@ const TablePageInnerContent = withLocale(_ref3 => {
2938
2919
  mobileSortToolbar = _ref3.mobileSortToolbar,
2939
2920
  _ref3$filterSeedParam = _ref3.filterSeedParams,
2940
2921
  filterSeedParams = _ref3$filterSeedParam === void 0 ? {} : _ref3$filterSeedParam,
2922
+ filterFetchApiRef = _ref3.filterFetchApiRef,
2941
2923
  props = _objectWithoutPropertiesLoose(_ref3, _excluded);
2942
2924
  const _useIntl = reactIntl.useIntl(),
2943
2925
  formatMessage = _useIntl.formatMessage;
@@ -3029,6 +3011,32 @@ const TablePageInnerContent = withLocale(_ref3 => {
3029
3011
  });
3030
3012
  return merged;
3031
3013
  });
3014
+
3015
+ // react-fetch 的 reload 以 props.data(首包种子)为底合并,裸调会丢掉当前已选筛选。
3016
+ // 对外(ref / batchActions / summary)统一注入 filterValue,保证 UI 与查询一致。
3017
+ // handleFilterChange 仍走原始 reload:setState 前要用新 value 组参,不能读旧 filterValue。
3018
+ const injectFilterParams = useRefCallback__default["default"](function (sendProps) {
3019
+ if (sendProps === void 0) {
3020
+ sendProps = {};
3021
+ }
3022
+ const paramsType = pagination.paramsType;
3023
+ const incoming = get__default["default"](sendProps, paramsType);
3024
+ return Object.assign({}, sendProps, {
3025
+ [paramsType]: buildRequestParamsWithFilter(filterValue, isPlainObject(incoming) ? incoming : {})
3026
+ });
3027
+ });
3028
+ const reloadWithFilter = useRefCallback__default["default"]((sendProps, force) => reload(injectFilterParams(sendProps), force));
3029
+ const refreshWithFilter = useRefCallback__default["default"]((sendProps, force) => refresh(injectFilterParams(sendProps), force));
3030
+ const sendWithFilter = useRefCallback__default["default"]((sendProps, force) => send(injectFilterParams(sendProps), force));
3031
+ const loadMoreWithFilter = useRefCallback__default["default"]((sendProps, callback, force) => loadMore(injectFilterParams(sendProps), callback, force));
3032
+ if (filterFetchApiRef) {
3033
+ filterFetchApiRef.current = {
3034
+ reload: reloadWithFilter,
3035
+ refresh: refreshWithFilter,
3036
+ send: sendWithFilter,
3037
+ loadMore: loadMoreWithFilter
3038
+ };
3039
+ }
3032
3040
  const formatData = react.useMemo(() => {
3033
3041
  return handlerDataFormat(data);
3034
3042
  }, [data, handlerDataFormat]);
@@ -3037,13 +3045,13 @@ const TablePageInnerContent = withLocale(_ref3 => {
3037
3045
  data,
3038
3046
  fetchProps,
3039
3047
  requestParams,
3040
- refresh,
3041
- reload,
3042
- loadMore,
3043
- send,
3048
+ refresh: refreshWithFilter,
3049
+ reload: reloadWithFilter,
3050
+ loadMore: loadMoreWithFilter,
3051
+ send: sendWithFilter,
3044
3052
  dataFormat,
3045
3053
  pagination
3046
- }), [data, fetchProps, requestParams, refresh, reload, loadMore, send, dataFormat, pagination]);
3054
+ }), [data, fetchProps, requestParams, refreshWithFilter, reloadWithFilter, loadMoreWithFilter, sendWithFilter, dataFormat, pagination]);
3047
3055
  const hasTab = !!(tab != null && tab.name && Array.isArray(tab.list) && tab.list.length > 0);
3048
3056
  const hasInnerToolbar = !!(filter != null && (_filter$list3 = filter.list) != null && _filter$list3.length || search && search.name || batchActions && batchActions.length || showButtonGroup || showCardModeToggle);
3049
3057
  const showOuterTab = hasTab && !isMobile;
@@ -3187,13 +3195,13 @@ const TablePageInnerContent = withLocale(_ref3 => {
3187
3195
  data,
3188
3196
  fetchProps,
3189
3197
  requestParams,
3190
- refresh,
3191
- reload,
3192
- loadMore,
3193
- send,
3198
+ refresh: refreshWithFilter,
3199
+ reload: reloadWithFilter,
3200
+ loadMore: loadMoreWithFilter,
3201
+ send: sendWithFilter,
3194
3202
  dataFormat,
3195
3203
  pagination
3196
- }), [data, fetchProps, requestParams, refresh, reload, loadMore, send, dataFormat, pagination]);
3204
+ }), [data, fetchProps, requestParams, refreshWithFilter, reloadWithFilter, loadMoreWithFilter, sendWithFilter, dataFormat, pagination]);
3197
3205
  const tableContext = _extends({}, columnRenderProps, {
3198
3206
  requestParams,
3199
3207
  fetchProps,
@@ -3332,11 +3340,56 @@ const TablePageInner = /*#__PURE__*/react.forwardRef((props, ref) => {
3332
3340
  const isMobile = responsiveUtils.useIsMobile();
3333
3341
  const loadingProp = props.loading,
3334
3342
  rest = _objectWithoutPropertiesLoose(props, _excluded2);
3343
+ const fetchRef = react.useRef(null);
3344
+ const filterFetchApiRef = react.useRef(null);
3335
3345
  const reserveToolbar = hasToolbarArea(props, isMobile);
3336
3346
  const loading = loadingProp !== undefined ? loadingProp : /*#__PURE__*/jsxRuntime.jsx(TablePageLoadingShell, _extends({}, props));
3347
+ react.useImperativeHandle(ref, () => ({
3348
+ get isLoading() {
3349
+ var _fetchRef$current;
3350
+ return (_fetchRef$current = fetchRef.current) == null ? void 0 : _fetchRef$current.isLoading;
3351
+ },
3352
+ get isComplete() {
3353
+ var _fetchRef$current2;
3354
+ return (_fetchRef$current2 = fetchRef.current) == null ? void 0 : _fetchRef$current2.isComplete;
3355
+ },
3356
+ get data() {
3357
+ var _fetchRef$current3;
3358
+ return (_fetchRef$current3 = fetchRef.current) == null ? void 0 : _fetchRef$current3.data;
3359
+ },
3360
+ get requestParams() {
3361
+ var _fetchRef$current4;
3362
+ return (_fetchRef$current4 = fetchRef.current) == null ? void 0 : _fetchRef$current4.requestParams;
3363
+ },
3364
+ get error() {
3365
+ var _fetchRef$current5;
3366
+ return (_fetchRef$current5 = fetchRef.current) == null ? void 0 : _fetchRef$current5.error;
3367
+ },
3368
+ get setData() {
3369
+ var _fetchRef$current6;
3370
+ return (_fetchRef$current6 = fetchRef.current) == null ? void 0 : _fetchRef$current6.setData;
3371
+ },
3372
+ send: function () {
3373
+ var _ref4, _filterFetchApiRef$cu, _fetchRef$current7;
3374
+ 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));
3375
+ },
3376
+ refresh: function () {
3377
+ var _ref5, _filterFetchApiRef$cu2, _fetchRef$current8;
3378
+ 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));
3379
+ },
3380
+ reload: function () {
3381
+ var _ref6, _filterFetchApiRef$cu3, _fetchRef$current9;
3382
+ 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));
3383
+ },
3384
+ loadMore: function () {
3385
+ var _ref7, _filterFetchApiRef$cu4, _fetchRef$current0;
3386
+ 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));
3387
+ }
3388
+ }));
3337
3389
  const fetched = /*#__PURE__*/jsxRuntime.jsx(TablePageFetched, _extends({}, rest, {
3338
3390
  loading: loading,
3339
- ref: ref
3391
+ ref: fetchRef,
3392
+ filterFetchApiRef: filterFetchApiRef
3340
3393
  }));
3341
3394
  if (!reserveToolbar) {
3342
3395
  return fetched;
@@ -3349,13 +3402,13 @@ const TablePageInner = /*#__PURE__*/react.forwardRef((props, ref) => {
3349
3402
  }), fetched]
3350
3403
  });
3351
3404
  });
3352
- const TablePage = /*#__PURE__*/react.forwardRef((_ref4, ref) => {
3353
- let pagination = _ref4.pagination,
3354
- _ref4$horizontalScrol = _ref4.horizontalScroller,
3355
- horizontalScroller = _ref4$horizontalScrol === void 0 ? true : _ref4$horizontalScrol,
3356
- getScrollContainer = _ref4.getScrollContainer,
3357
- filterProp = _ref4.filter,
3358
- props = _objectWithoutPropertiesLoose(_ref4, _excluded3);
3405
+ const TablePage = /*#__PURE__*/react.forwardRef((_ref8, ref) => {
3406
+ let pagination = _ref8.pagination,
3407
+ _ref8$horizontalScrol = _ref8.horizontalScroller,
3408
+ horizontalScroller = _ref8$horizontalScrol === void 0 ? true : _ref8$horizontalScrol,
3409
+ getScrollContainer = _ref8.getScrollContainer,
3410
+ filterProp = _ref8.filter,
3411
+ props = _objectWithoutPropertiesLoose(_ref8, _excluded3);
3359
3412
  pagination = Object.assign({}, {
3360
3413
  showSizeChanger: true,
3361
3414
  showQuickJumper: true,
@@ -3376,8 +3429,8 @@ const TablePage = /*#__PURE__*/react.forwardRef((_ref4, ref) => {
3376
3429
  }) : {}),
3377
3430
  urlPagination = _useState2[0];
3378
3431
  const _useState3 = react.useState(() => {
3379
- var _ref5, _urlPagination$pageSi;
3380
- return (_ref5 = (_urlPagination$pageSi = urlPagination.pageSize) != null ? _urlPagination$pageSi : cachePageSize ? readPageSize(pageSizeKey) : null) != null ? _ref5 : pagination.pageSize;
3432
+ var _ref9, _urlPagination$pageSi;
3433
+ return (_ref9 = (_urlPagination$pageSi = urlPagination.pageSize) != null ? _urlPagination$pageSi : cachePageSize ? readPageSize(pageSizeKey) : null) != null ? _ref9 : pagination.pageSize;
3381
3434
  }),
3382
3435
  pageSize = _useState3[0],
3383
3436
  setPageSize = _useState3[1];