@kne/table-page 0.1.16 → 0.1.19

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.
@@ -25,6 +25,7 @@ import cloneDeep from 'lodash/cloneDeep';
25
25
  import { createWithIntlProvider, useIntl } from '@kne/react-intl';
26
26
  import filterZhCN from '@kne/react-filter/dist/locale/zh-CN';
27
27
  import filterEnUS from '@kne/react-filter/dist/locale/en-US';
28
+ import useControlValue from '@kne/use-control-value';
28
29
  import { createPortal } from 'react-dom';
29
30
  import '@kne/button-group/dist/index.css';
30
31
  import '@kne/react-filter/dist/index.css';
@@ -1413,16 +1414,15 @@ const Table = p => {
1413
1414
  setResizeGuideStyle(null);
1414
1415
  return;
1415
1416
  }
1417
+ const wrapperRect = root.getBoundingClientRect();
1416
1418
  const headerRect = headerCell.getBoundingClientRect();
1417
1419
  const resizeBar = headerCell.querySelector('.table-cell-resize-bar');
1418
1420
  const barRect = resizeBar == null ? void 0 : resizeBar.getBoundingClientRect();
1419
1421
  const containerRect = tableContainer.getBoundingClientRect();
1420
1422
  setResizeGuideStyle({
1421
- position: 'fixed',
1422
- left: Math.round((_barRect$right = barRect == null ? void 0 : barRect.right) != null ? _barRect$right : headerRect.right),
1423
- top: Math.round(containerRect.top),
1424
- height: Math.round(containerRect.height),
1425
- zIndex: 100
1423
+ left: Math.round(((_barRect$right = barRect == null ? void 0 : barRect.right) != null ? _barRect$right : headerRect.right) - wrapperRect.left),
1424
+ top: Math.round(containerRect.top - wrapperRect.top),
1425
+ height: Math.round(containerRect.height)
1426
1426
  });
1427
1427
  }, [currentMoveColumnIndex]);
1428
1428
  useLayoutEffect(() => {
@@ -2659,6 +2659,17 @@ const defaultMergeList = (data, newData) => {
2659
2659
  pageData: [...((data == null ? void 0 : data.pageData) || []), ...((newData == null ? void 0 : newData.pageData) || [])]
2660
2660
  });
2661
2661
  };
2662
+
2663
+ /** 与 use-control-value 一致:有 value key 为受控,否则用 defaultValue */
2664
+ const resolveInitialFilterValue = filter => {
2665
+ if (!filter) {
2666
+ return [];
2667
+ }
2668
+ if ('value' in filter) {
2669
+ return filter.value || [];
2670
+ }
2671
+ return filter.defaultValue || [];
2672
+ };
2662
2673
  const readPageSize = key => {
2663
2674
  try {
2664
2675
  const value = localStorage.getItem(key);
@@ -2802,9 +2813,9 @@ const TablePageInnerContent = withLocale(_ref => {
2802
2813
  const tableContentRef = useRef(null);
2803
2814
  const pendingScrollRef = useRef(false);
2804
2815
  const handlerDataFormat = useRefCallback(dataFormat);
2805
- const isFilterControlled = filter && filter.value !== undefined;
2806
- const [internalFilterValue, setInternalFilterValue] = useState(() => (filter == null ? void 0 : filter.defaultValue) || []);
2807
- const filterValue = isFilterControlled ? filter.value : internalFilterValue;
2816
+ const [filterValue, setFilterValue] = useControlValue(Object.assign({
2817
+ defaultValue: []
2818
+ }, filter));
2808
2819
  const mapFilterValue = (filter == null ? void 0 : filter.mapFilterValue) || getFilterValue;
2809
2820
  const getFilterParams = useRefCallback(value => {
2810
2821
  return mapFilterValue(value || []);
@@ -2851,10 +2862,7 @@ const TablePageInnerContent = withLocale(_ref => {
2851
2862
  });
2852
2863
  });
2853
2864
  const handleFilterChange = useRefCallback(value => {
2854
- if (!isFilterControlled) {
2855
- setInternalFilterValue(value);
2856
- }
2857
- filter == null || filter.onChange == null || filter.onChange(value);
2865
+ setFilterValue(value);
2858
2866
  reload({
2859
2867
  [pagination.paramsType]: buildRequestParamsWithFilter(value, {
2860
2868
  [pagination.currentName]: 1
@@ -2876,7 +2884,7 @@ const TablePageInnerContent = withLocale(_ref => {
2876
2884
  }
2877
2885
  const nextSize = Number(size);
2878
2886
  const currentPage = get(requestParams, [pagination.paramsType, pagination.currentName], 1);
2879
- const currentSize = Number(get(requestParams, [pagination.paramsType, pagination.pageSizeName], pagination.pageSize)) || pagination.pageSize || 50;
2887
+ const currentSize = Number(get(requestParams, [pagination.paramsType, pagination.pageSizeName], pagination.pageSize)) || pagination.pageSize || 20;
2880
2888
  if (nextSize !== currentSize) {
2881
2889
  pagination.onShowSizeChange && pagination.onShowSizeChange(page, nextSize);
2882
2890
  }
@@ -2894,7 +2902,7 @@ const TablePageInnerContent = withLocale(_ref => {
2894
2902
  const useCardLoadMore = isCardModeActive && pagination.open && !pagination.forcePagination;
2895
2903
  const useLoadMoreMode = useMobileLoadMore || useCardLoadMore;
2896
2904
  const currentPage = get(requestParams, [pagination.paramsType, pagination.currentName], 1);
2897
- const currentPageSize = Number(get(requestParams, [pagination.paramsType, pagination.pageSizeName], pagination.pageSize)) || pagination.pageSize || 50;
2905
+ const currentPageSize = Number(get(requestParams, [pagination.paramsType, pagination.pageSizeName], pagination.pageSize)) || pagination.pageSize || 20;
2898
2906
  const loadMoreNoMore = !formatData.total || currentPage * currentPageSize >= formatData.total;
2899
2907
  const handleLoadMore = useRefCallback(async () => {
2900
2908
  const mergeList = pagination.mergeList || defaultMergeList;
@@ -2926,7 +2934,7 @@ const TablePageInnerContent = withLocale(_ref => {
2926
2934
  showTotal: typeof pagination.showTotal === 'function' ? pagination.showTotal : defaultShowTotal
2927
2935
  } : {}, {
2928
2936
  current: get(requestParams, [pagination.paramsType, pagination.currentName], 1),
2929
- pageSize: Number(get(requestParams, [pagination.paramsType, pagination.pageSizeName], pagination.pageSize)) || pagination.pageSize || 50,
2937
+ pageSize: Number(get(requestParams, [pagination.paramsType, pagination.pageSizeName], pagination.pageSize)) || pagination.pageSize || 20,
2930
2938
  onChange: handlePaginationChange,
2931
2939
  size: pagination.size,
2932
2940
  hideOnSinglePage: pagination.hideOnSinglePage,
@@ -3033,9 +3041,7 @@ const TablePageInnerContent = withLocale(_ref => {
3033
3041
  ref: tableContentRef,
3034
3042
  enabled: horizontalScroller && renderType === 'Table' && !isCardModeActive,
3035
3043
  getPortalContainer: getScrollContainer,
3036
- className: classnames(style$1['table-content'], 'loading-container', {
3037
- 'is-loading': !isComplete && !data
3038
- }),
3044
+ className: style$1['table-content'],
3039
3045
  children: [showOuterTab ? /*#__PURE__*/jsx(TablePageTabs, {
3040
3046
  filterValue: filterValue,
3041
3047
  onFilterChange: handleFilterChange,
@@ -3068,7 +3074,10 @@ const TablePageInnerContent = withLocale(_ref => {
3068
3074
  }) : tableElement]
3069
3075
  });
3070
3076
  return /*#__PURE__*/jsx("div", {
3071
- className: style$1['table-page'],
3077
+ className: classnames(style$1['table-page'], 'loading-container', {
3078
+ // reload 会保留旧 data,仅将 isComplete 置为 false;用蒙层提示切换中,避免卸载表格
3079
+ 'is-loading': !isComplete
3080
+ }),
3072
3081
  style: scrollTopInsetStyle,
3073
3082
  children: useLoadMoreMode ? /*#__PURE__*/jsx(ScrollLoader, _extends({
3074
3083
  className: style$1['mobile-load-more'],
@@ -3099,13 +3108,13 @@ const TablePage = /*#__PURE__*/forwardRef((_ref2, ref) => {
3099
3108
  pagination = Object.assign({}, {
3100
3109
  showSizeChanger: true,
3101
3110
  showQuickJumper: true,
3102
- hideOnSinglePage: false,
3111
+ hideOnSinglePage: true,
3103
3112
  open: true,
3104
3113
  paramsType: 'data',
3105
3114
  requestType: 'reload',
3106
3115
  currentName: 'currentPage',
3107
3116
  pageSizeName: 'perPage',
3108
- pageSize: 50
3117
+ pageSize: 20
3109
3118
  }, pagination);
3110
3119
  const pageSizeKey = `${(props.name || 'common').toUpperCase()}_TABLE_PAGE_SIZE`;
3111
3120
  const cachePageSize = pagination.cachePageSize !== false;
@@ -3115,12 +3124,17 @@ const TablePage = /*#__PURE__*/forwardRef((_ref2, ref) => {
3115
3124
  });
3116
3125
  const params = props[pagination.paramsType];
3117
3126
  const filterDefaultParams = useMemo(() => {
3118
- var _props$filter;
3119
- if (!((_props$filter = props.filter) != null && (_props$filter = _props$filter.defaultValue) != null && _props$filter.length)) {
3127
+ const filter = props.filter;
3128
+ if (!filter) {
3129
+ return {};
3130
+ }
3131
+ const initialValue = resolveInitialFilterValue(filter);
3132
+ const mapFilterValue = filter.mapFilterValue || getFilterValue;
3133
+ // 有 mapFilterValue 时即使 initialValue 为空也要跑(注入 namespace 等)
3134
+ if (!initialValue.length && !filter.mapFilterValue) {
3120
3135
  return {};
3121
3136
  }
3122
- const mapFilterValue = props.filter.mapFilterValue || getFilterValue;
3123
- return mapFilterValue(props.filter.defaultValue);
3137
+ return mapFilterValue(initialValue);
3124
3138
  }, [props.filter]);
3125
3139
  const fetchParams = useMemo(() => {
3126
3140
  return {