@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.
@@ -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
- const allKeys = isTree ? (treeKeyMaps == null ? void 0 : treeKeyMaps.allKeys) || [] : (dataSource || []).filter(item => !item.disabled).map(getRowKey);
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 || []).length > 0;
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, info) => {
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
- columnTitle: rowSelection.allowSelectedAll ? checkboxNode => wrapColContent(checkboxNode) : wrapColContent(/*#__PURE__*/jsx(Checkbox, {
1711
- style: {
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: 30,
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 (isTree && antdSelectionColumnWidth) {
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, isTree, antdSelectionColumnWidth]);
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, {
@@ -1938,7 +1916,7 @@ const resolveButtonGroupProps = (buttonGroup, getPopupContainer, {
1938
1916
  getPopupContainer: userGetPopupContainer
1939
1917
  } = buttonGroup,
1940
1918
  rest = _objectWithoutPropertiesLoose(buttonGroup, _excluded$2);
1941
- const resolvedShowLength = Number.isInteger(showLength) ? Math.max(minShowLength, showLength) : defaultShowLength;
1919
+ const resolvedShowLength = Number.isInteger(showLength) ? Math.max(minShowLength, showLength) : Number.isInteger(defaultShowLength) ? defaultShowLength : undefined;
1942
1920
  return _extends({}, rest, {
1943
1921
  list: normalizeButtonGroupList(list, defaultSize)
1944
1922
  }, defaultSize !== undefined ? {
@@ -1946,15 +1924,18 @@ const resolveButtonGroupProps = (buttonGroup, getPopupContainer, {
1946
1924
  } : size !== undefined ? {
1947
1925
  size
1948
1926
  } : {}, {
1949
- moreType: moreType != null ? moreType : 'link',
1950
- showLength: resolvedShowLength,
1927
+ moreType: moreType != null ? moreType : 'link'
1928
+ }, resolvedShowLength !== undefined ? {
1929
+ showLength: resolvedShowLength
1930
+ } : {}, {
1951
1931
  getPopupContainer: userGetPopupContainer != null ? userGetPopupContainer : getPopupContainer
1952
1932
  });
1953
1933
  };
1954
1934
  const resolveToolbarButtonGroupProps = (buttonGroup, getPopupContainer) => {
1955
1935
  return resolveButtonGroupProps(buttonGroup, getPopupContainer, {
1956
1936
  defaultSize: 'small',
1957
- defaultShowLength: 1,
1937
+ // 未显式传 showLength 时走 ButtonGroup 自适应测宽(@kne/overflow-items)
1938
+ defaultShowLength: undefined,
1958
1939
  minShowLength: 1
1959
1940
  });
1960
1941
  };
@@ -2460,7 +2441,7 @@ const isPaginationSearchParamsEnabled = pagination => {
2460
2441
  return !!(pagination != null && pagination.searchParams && typeof pagination.setSearchParams === 'function');
2461
2442
  };
2462
2443
 
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"],
2444
+ 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
2445
  _excluded2 = ["loading"],
2465
2446
  _excluded3 = ["pagination", "horizontalScroller", "getScrollContainer", "filter"],
2466
2447
  _excluded4 = ["searchParamsValue"];
@@ -2856,7 +2837,8 @@ const TablePageInnerContent = withLocale(_ref => {
2856
2837
  renderCard,
2857
2838
  forceCard = false,
2858
2839
  mobileSortToolbar,
2859
- filterSeedParams = {}
2840
+ filterSeedParams = {},
2841
+ filterFetchApiRef
2860
2842
  } = _ref,
2861
2843
  props = _objectWithoutPropertiesLoose(_ref, _excluded);
2862
2844
  const {
@@ -2943,6 +2925,29 @@ const TablePageInnerContent = withLocale(_ref => {
2943
2925
  });
2944
2926
  return merged;
2945
2927
  });
2928
+
2929
+ // react-fetch 的 reload 以 props.data(首包种子)为底合并,裸调会丢掉当前已选筛选。
2930
+ // 对外(ref / batchActions / summary)统一注入 filterValue,保证 UI 与查询一致。
2931
+ // handleFilterChange 仍走原始 reload:setState 前要用新 value 组参,不能读旧 filterValue。
2932
+ const injectFilterParams = useRefCallback((sendProps = {}) => {
2933
+ const paramsType = pagination.paramsType;
2934
+ const incoming = get(sendProps, paramsType);
2935
+ return Object.assign({}, sendProps, {
2936
+ [paramsType]: buildRequestParamsWithFilter(filterValue, isPlainObject(incoming) ? incoming : {})
2937
+ });
2938
+ });
2939
+ const reloadWithFilter = useRefCallback((sendProps, force) => reload(injectFilterParams(sendProps), force));
2940
+ const refreshWithFilter = useRefCallback((sendProps, force) => refresh(injectFilterParams(sendProps), force));
2941
+ const sendWithFilter = useRefCallback((sendProps, force) => send(injectFilterParams(sendProps), force));
2942
+ const loadMoreWithFilter = useRefCallback((sendProps, callback, force) => loadMore(injectFilterParams(sendProps), callback, force));
2943
+ if (filterFetchApiRef) {
2944
+ filterFetchApiRef.current = {
2945
+ reload: reloadWithFilter,
2946
+ refresh: refreshWithFilter,
2947
+ send: sendWithFilter,
2948
+ loadMore: loadMoreWithFilter
2949
+ };
2950
+ }
2946
2951
  const formatData = useMemo(() => {
2947
2952
  return handlerDataFormat(data);
2948
2953
  }, [data, handlerDataFormat]);
@@ -2951,13 +2956,13 @@ const TablePageInnerContent = withLocale(_ref => {
2951
2956
  data,
2952
2957
  fetchProps,
2953
2958
  requestParams,
2954
- refresh,
2955
- reload,
2956
- loadMore,
2957
- send,
2959
+ refresh: refreshWithFilter,
2960
+ reload: reloadWithFilter,
2961
+ loadMore: loadMoreWithFilter,
2962
+ send: sendWithFilter,
2958
2963
  dataFormat,
2959
2964
  pagination
2960
- }), [data, fetchProps, requestParams, refresh, reload, loadMore, send, dataFormat, pagination]);
2965
+ }), [data, fetchProps, requestParams, refreshWithFilter, reloadWithFilter, loadMoreWithFilter, sendWithFilter, dataFormat, pagination]);
2961
2966
  const hasTab = !!(tab != null && tab.name && Array.isArray(tab.list) && tab.list.length > 0);
2962
2967
  const hasInnerToolbar = !!(filter != null && (_filter$list3 = filter.list) != null && _filter$list3.length || search && search.name || batchActions && batchActions.length || showButtonGroup || showCardModeToggle);
2963
2968
  const showOuterTab = hasTab && !isMobile;
@@ -3097,13 +3102,13 @@ const TablePageInnerContent = withLocale(_ref => {
3097
3102
  data,
3098
3103
  fetchProps,
3099
3104
  requestParams,
3100
- refresh,
3101
- reload,
3102
- loadMore,
3103
- send,
3105
+ refresh: refreshWithFilter,
3106
+ reload: reloadWithFilter,
3107
+ loadMore: loadMoreWithFilter,
3108
+ send: sendWithFilter,
3104
3109
  dataFormat,
3105
3110
  pagination
3106
- }), [data, fetchProps, requestParams, refresh, reload, loadMore, send, dataFormat, pagination]);
3111
+ }), [data, fetchProps, requestParams, refreshWithFilter, reloadWithFilter, loadMoreWithFilter, sendWithFilter, dataFormat, pagination]);
3107
3112
  const tableContext = _extends({}, columnRenderProps, {
3108
3113
  requestParams,
3109
3114
  fetchProps,
@@ -3244,11 +3249,56 @@ const TablePageInner = /*#__PURE__*/forwardRef((props, ref) => {
3244
3249
  loading: loadingProp
3245
3250
  } = props,
3246
3251
  rest = _objectWithoutPropertiesLoose(props, _excluded2);
3252
+ const fetchRef = useRef(null);
3253
+ const filterFetchApiRef = useRef(null);
3247
3254
  const reserveToolbar = hasToolbarArea(props, isMobile);
3248
3255
  const loading = loadingProp !== undefined ? loadingProp : /*#__PURE__*/jsx(TablePageLoadingShell, _extends({}, props));
3256
+ useImperativeHandle(ref, () => ({
3257
+ get isLoading() {
3258
+ var _fetchRef$current;
3259
+ return (_fetchRef$current = fetchRef.current) == null ? void 0 : _fetchRef$current.isLoading;
3260
+ },
3261
+ get isComplete() {
3262
+ var _fetchRef$current2;
3263
+ return (_fetchRef$current2 = fetchRef.current) == null ? void 0 : _fetchRef$current2.isComplete;
3264
+ },
3265
+ get data() {
3266
+ var _fetchRef$current3;
3267
+ return (_fetchRef$current3 = fetchRef.current) == null ? void 0 : _fetchRef$current3.data;
3268
+ },
3269
+ get requestParams() {
3270
+ var _fetchRef$current4;
3271
+ return (_fetchRef$current4 = fetchRef.current) == null ? void 0 : _fetchRef$current4.requestParams;
3272
+ },
3273
+ get error() {
3274
+ var _fetchRef$current5;
3275
+ return (_fetchRef$current5 = fetchRef.current) == null ? void 0 : _fetchRef$current5.error;
3276
+ },
3277
+ get setData() {
3278
+ var _fetchRef$current6;
3279
+ return (_fetchRef$current6 = fetchRef.current) == null ? void 0 : _fetchRef$current6.setData;
3280
+ },
3281
+ send: (...args) => {
3282
+ var _ref2, _filterFetchApiRef$cu, _fetchRef$current7;
3283
+ 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);
3284
+ },
3285
+ refresh: (...args) => {
3286
+ var _ref3, _filterFetchApiRef$cu2, _fetchRef$current8;
3287
+ 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);
3288
+ },
3289
+ reload: (...args) => {
3290
+ var _ref4, _filterFetchApiRef$cu3, _fetchRef$current9;
3291
+ 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);
3292
+ },
3293
+ loadMore: (...args) => {
3294
+ var _ref5, _filterFetchApiRef$cu4, _fetchRef$current0;
3295
+ 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);
3296
+ }
3297
+ }));
3249
3298
  const fetched = /*#__PURE__*/jsx(TablePageFetched, _extends({}, rest, {
3250
3299
  loading: loading,
3251
- ref: ref
3300
+ ref: fetchRef,
3301
+ filterFetchApiRef: filterFetchApiRef
3252
3302
  }));
3253
3303
  if (!reserveToolbar) {
3254
3304
  return fetched;
@@ -3261,14 +3311,14 @@ const TablePageInner = /*#__PURE__*/forwardRef((props, ref) => {
3261
3311
  }), fetched]
3262
3312
  });
3263
3313
  });
3264
- const TablePage = /*#__PURE__*/forwardRef((_ref2, ref) => {
3314
+ const TablePage = /*#__PURE__*/forwardRef((_ref6, ref) => {
3265
3315
  let {
3266
3316
  pagination,
3267
3317
  horizontalScroller = true,
3268
3318
  getScrollContainer,
3269
3319
  filter: filterProp
3270
- } = _ref2,
3271
- props = _objectWithoutPropertiesLoose(_ref2, _excluded3);
3320
+ } = _ref6,
3321
+ props = _objectWithoutPropertiesLoose(_ref6, _excluded3);
3272
3322
  pagination = Object.assign({}, {
3273
3323
  showSizeChanger: true,
3274
3324
  showQuickJumper: true,
@@ -3288,8 +3338,8 @@ const TablePage = /*#__PURE__*/forwardRef((_ref2, ref) => {
3288
3338
  pageSizeName: pagination.pageSizeName
3289
3339
  }) : {});
3290
3340
  const [pageSize, setPageSize] = useState(() => {
3291
- var _ref3, _urlPagination$pageSi;
3292
- return (_ref3 = (_urlPagination$pageSi = urlPagination.pageSize) != null ? _urlPagination$pageSi : cachePageSize ? readPageSize(pageSizeKey) : null) != null ? _ref3 : pagination.pageSize;
3341
+ var _ref7, _urlPagination$pageSi;
3342
+ return (_ref7 = (_urlPagination$pageSi = urlPagination.pageSize) != null ? _urlPagination$pageSi : cachePageSize ? readPageSize(pageSizeKey) : null) != null ? _ref7 : pagination.pageSize;
3293
3343
  });
3294
3344
  const [initialCurrent] = useState(() => {
3295
3345
  if (urlPagination.current != null) {