@kne/super-select 0.1.46 → 0.1.48

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.
@@ -18,9 +18,10 @@ import SimpleBar from 'simplebar-react';
18
18
  import SearchInput from '@kne/search-input';
19
19
  import { FetchScrollLoader } from '@kne/scroll-loader';
20
20
  import '@kne/scroll-loader/dist/index.css';
21
- import TableView, { isTreeDataType, normalizeTreeData, flattenAllTree } from '@kne/table-view';
22
- export { mergeTreeChildren } from '@kne/table-view';
23
- import '@kne/table-view/dist/index.css';
21
+ import merge from 'lodash/merge';
22
+ import TablePage, { hasColumnWidth, isTreeDataType, normalizeTreeData, flattenAllTree } from '@kne/table-page';
23
+ export { mergeTreeChildren } from '@kne/table-page';
24
+ import '@kne/table-page/dist/index.css';
24
25
  import { CentralContent } from '@kne/info-page';
25
26
  import '@kne/info-page/dist/index.css';
26
27
  import memoize from 'lodash/memoize';
@@ -1178,7 +1179,7 @@ const SelectList = forwardRef((_ref, ref) => {
1178
1179
  });
1179
1180
  });
1180
1181
 
1181
- var style$2 = {"body":"kne-super-select_704J1","is-mobile":"kne-super-select_HYGUN","table-panel-wrap":"kne-super-select_Boo1a","selected-panel-wrap":"kne-super-select_q-BjK","table-panel":"kne-super-select_UAejp","filter-wrap":"kne-super-select_gmlBv","table":"kne-super-select_zE-14","list":"kne-super-select_DrEYJ","is-popup":"kne-super-select_KgWTX","empty":"kne-super-select_5Tyrt","right-options-col":"kne-super-select_sNBrJ","right-options":"kne-super-select_UXi-g","no-padding-btn":"kne-super-select_iaCir","selected-tags-scroll":"kne-super-select_b-3Xk","tag":"kne-super-select_JkYqS","tag-inner":"kne-super-select_VZlBL","single-checked":"kne-super-select_Eiz-u","select-search":"kne-super-select_temy6","tags-search":"kne-super-select_7phL2","descriptions":"kne-super-select_ttNK9","footer":"kne-super-select_lISfA"};
1182
+ var style$2 = {"body":"kne-super-select_704J1","is-mobile":"kne-super-select_HYGUN","table-panel-wrap":"kne-super-select_Boo1a","selected-panel-wrap":"kne-super-select_q-BjK","table-panel":"kne-super-select_UAejp","filter-wrap":"kne-super-select_gmlBv","table":"kne-super-select_zE-14","list":"kne-super-select_DrEYJ","is-fit-columns":"kne-super-select_QqZxW","empty":"kne-super-select_5Tyrt","right-options-col":"kne-super-select_sNBrJ","right-options":"kne-super-select_UXi-g","no-padding-btn":"kne-super-select_iaCir","selected-tags-scroll":"kne-super-select_b-3Xk","tag":"kne-super-select_JkYqS","tag-inner":"kne-super-select_VZlBL","single-checked":"kne-super-select_Eiz-u","select-search":"kne-super-select_temy6","tags-search":"kne-super-select_7phL2","descriptions":"kne-super-select_ttNK9","footer":"kne-super-select_lISfA"};
1182
1183
 
1183
1184
  const isEmptyParentKey = value => value == null || value === '';
1184
1185
  const flattenSelectList = (list, {
@@ -1248,12 +1249,25 @@ const filterTreeOptions = (options, searchProps, getSearchCallback, targetProps,
1248
1249
  }
1249
1250
  return options.filter(item => getSearchCallback(searchProps, item, targetProps));
1250
1251
  };
1252
+ const getListFromPageData = data => {
1253
+ if (Array.isArray(data == null ? void 0 : data.pageData)) {
1254
+ return data.pageData;
1255
+ }
1256
+ if (Array.isArray(data == null ? void 0 : data.list)) {
1257
+ return data.list;
1258
+ }
1259
+ return [];
1260
+ };
1261
+ const TABLE_LIST_MAX_HEIGHT_POPUP = 300;
1262
+ const TABLE_LIST_MAX_HEIGHT_EMBED = 400;
1263
+ const TABLE_HEADER_HEIGHT = 48;
1251
1264
  const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select')(forwardRef((p, ref) => {
1252
1265
  const {
1253
1266
  formatMessage
1254
1267
  } = useIntl();
1255
1268
  const [tagSearchText, setTagSearchText] = useState('');
1256
- const fetchListRef = useRef();
1269
+ const tablePageRef = useRef();
1270
+ const listScrollRef = useRef();
1257
1271
  const props = Object.assign({}, {
1258
1272
  overlayWidth: '600px',
1259
1273
  dataType: 'list',
@@ -1347,7 +1361,9 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1347
1361
  defaultExpandedKeys,
1348
1362
  onExpandedKeysChange,
1349
1363
  indentSize,
1350
- checkRelation
1364
+ checkRelation,
1365
+ pagination: paginationProp,
1366
+ dataFormat
1351
1367
  } = props;
1352
1368
  const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
1353
1369
  const resolvedTreeTitleKey = treeTitleKey || labelKey;
@@ -1355,57 +1371,42 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1355
1371
  className: classnames(style$2['footer'], 'select-table-footer')
1356
1372
  }, typeof footer === 'function' ? footer({
1357
1373
  reload: () => {
1358
- var _fetchListRef$current, _fetchListRef$current2;
1359
- ((_fetchListRef$current = fetchListRef.current) == null ? void 0 : _fetchListRef$current.fetchApi) && ((_fetchListRef$current2 = fetchListRef.current) == null ? void 0 : _fetchListRef$current2.fetchApi.reload());
1374
+ var _tablePageRef$current;
1375
+ (_tablePageRef$current = tablePageRef.current) == null || _tablePageRef$current.reload();
1360
1376
  },
1361
1377
  close: () => {
1362
1378
  onOpenChange(false);
1363
1379
  }
1364
1380
  }) : footer);
1365
- const renderScrollList = renderContent => open ? /*#__PURE__*/React.createElement(FetchScrollLoader, _extends({}, props, {
1366
- className: classnames(style$2['list'], 'select-table-list-scroll-list', {
1367
- 'is-popup': isPopup
1368
- }),
1369
- useSimpleBar: !isMobile,
1370
- searchProps: searchProps,
1371
- getSearchProps: getSearchProps,
1372
- api: Object.assign({}, options ? {
1373
- data: {
1374
- options,
1375
- searchProps
1376
- },
1377
- loader: ({
1378
- data
1379
- }) => {
1380
- const {
1381
- options,
1382
- searchProps
1383
- } = data;
1384
- return {
1385
- pageData: filterTreeOptions(options, searchProps, getSearchCallback, targetProps, {
1386
- dataType,
1387
- valueKey,
1388
- parentKey,
1389
- childrenKey
1390
- })
1391
- };
1392
- }
1393
- } : api)
1394
- }), fetchProps => {
1395
- fetchListRef.current = fetchProps;
1396
- const {
1397
- list
1398
- } = fetchProps;
1399
- const contextProps = Object.assign({}, fetchProps, targetProps, {
1400
- isSelectedAll
1401
- });
1402
- if (!(list && list.length > 0)) {
1403
- return props.empty || /*#__PURE__*/React.createElement(Empty, {
1404
- className: classnames(style$2['empty'])
1381
+ const paginationParamsType = (paginationProp == null ? void 0 : paginationProp.paramsType) || 'data';
1382
+ const searchRequestProps = typeof getSearchProps === 'function' && isNotEmpty(searchProps) ? {
1383
+ [paginationParamsType]: getSearchProps(searchProps) || {}
1384
+ } : {};
1385
+ const tablePageFetchConfig = options ? {
1386
+ data: {
1387
+ options,
1388
+ searchProps
1389
+ },
1390
+ loader: ({
1391
+ data
1392
+ }) => {
1393
+ const {
1394
+ options: nextOptions,
1395
+ searchProps: nextSearchProps
1396
+ } = data;
1397
+ const pageData = filterTreeOptions(nextOptions, nextSearchProps, getSearchCallback, targetProps, {
1398
+ dataType,
1399
+ valueKey,
1400
+ parentKey,
1401
+ childrenKey
1405
1402
  });
1403
+ return {
1404
+ pageData,
1405
+ totalCount: pageData.length
1406
+ };
1406
1407
  }
1407
- return renderContent(list, contextProps);
1408
- }) : null;
1408
+ } : merge({}, api, searchRequestProps);
1409
+ const allColumnsHaveWidth = Array.isArray(columns) && columns.length > 0 && columns.every(hasColumnWidth);
1409
1410
  const tableSelection = {
1410
1411
  allowSelectedAll,
1411
1412
  isSelectedAll,
@@ -1417,9 +1418,9 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1417
1418
  checkRelation,
1418
1419
  onChange: selectedRowKeys => {
1419
1420
  setValue(prev => {
1420
- var _fetchListRef$current3;
1421
+ var _tablePageRef$current2;
1421
1422
  const prevMap = new Map((prev || []).map(item => [item[valueKey], item]));
1422
- const listMap = new Map(flattenSelectList((_fetchListRef$current3 = fetchListRef.current) == null ? void 0 : _fetchListRef$current3.list, {
1423
+ const listMap = new Map(flattenSelectList(getListFromPageData((_tablePageRef$current2 = tablePageRef.current) == null ? void 0 : _tablePageRef$current2.data), {
1423
1424
  dataType,
1424
1425
  rowKey: valueKey,
1425
1426
  parentKey,
@@ -1464,7 +1465,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1464
1465
  wrap: true,
1465
1466
  gap: 8
1466
1467
  }, value.filter(item => getTagSearchCallback(tagSearchText, item, targetProps)).map(item => {
1467
- var _fetchListRef$current4, _fetchListRef$current5;
1468
+ var _tablePageRef$current3;
1468
1469
  return /*#__PURE__*/React.createElement(Tag, {
1469
1470
  className: style$2['tag'],
1470
1471
  key: item[valueKey],
@@ -1488,8 +1489,8 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1488
1489
  })),
1489
1490
  dataSource: Object.assign({}, item),
1490
1491
  context: Object.assign({}, targetProps, {
1491
- fetchApi: (_fetchListRef$current4 = fetchListRef.current) == null ? void 0 : _fetchListRef$current4.fetchApi,
1492
- list: (_fetchListRef$current5 = fetchListRef.current) == null ? void 0 : _fetchListRef$current5.list
1492
+ fetchApi: tablePageRef.current,
1493
+ list: getListFromPageData((_tablePageRef$current3 = tablePageRef.current) == null ? void 0 : _tablePageRef$current3.data)
1493
1494
  })
1494
1495
  })
1495
1496
  }, /*#__PURE__*/React.createElement("span", {
@@ -1514,42 +1515,60 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1514
1515
  className: style$2['filter-wrap']
1515
1516
  }, filterRender(Object.assign({}, targetProps))), /*#__PURE__*/React.createElement("div", {
1516
1517
  className: classnames(style$2['table'], 'select-table')
1517
- }, renderScrollList((list, contextProps) => {
1518
- const tableViewProps = {
1519
- dataSource: list,
1520
- columns,
1521
- rowKey: valueKey,
1522
- rowSelection: tableSelection,
1523
- context: contextProps,
1524
- dataType,
1525
- parentKey,
1526
- childrenKey,
1527
- hasChildrenKey,
1528
- treeTitleKey: resolvedTreeTitleKey,
1529
- renderMobile: renderMobile === false ? false : typeof renderMobile === 'function' ? mobileProps => renderMobile(_extends({}, mobileProps, contextProps, {
1530
- list: mobileProps.displayDataSource || list,
1531
- dataSource: list,
1532
- renderBody: (nextList = mobileProps.displayDataSource || list, nextContext = contextProps) => mobileProps.renderBody(nextList, nextContext)
1533
- })) : true
1534
- };
1535
- // 可选树形 props:仅在有值 / 用户显式传入时透传,避免 undefined 覆盖 TableView 默认值
1536
- if (typeof onLoadChildren === 'function') {
1537
- tableViewProps.onLoadChildren = onLoadChildren;
1538
- }
1539
- if (typeof onExpandedKeysChange === 'function') {
1540
- tableViewProps.onExpandedKeysChange = onExpandedKeysChange;
1541
- }
1542
- if (indentSize != null) {
1543
- tableViewProps.indentSize = indentSize;
1544
- }
1545
- if (Object.prototype.hasOwnProperty.call(p, 'expandedKeys')) {
1546
- tableViewProps.expandedKeys = expandedKeys;
1547
- }
1548
- if (Object.prototype.hasOwnProperty.call(p, 'defaultExpandedKeys')) {
1549
- tableViewProps.defaultExpandedKeys = defaultExpandedKeys;
1550
- }
1551
- return /*#__PURE__*/React.createElement(TableView, tableViewProps);
1552
- })), single && footerEl || !isMobile && /*#__PURE__*/React.createElement("div", {
1518
+ }, open ? /*#__PURE__*/React.createElement("div", {
1519
+ ref: listScrollRef,
1520
+ className: classnames(style$2['list'], 'select-table-list-scroll-list', {
1521
+ 'is-popup': isPopup,
1522
+ [style$2['is-fit-columns']]: !allColumnsHaveWidth
1523
+ })
1524
+ }, /*#__PURE__*/React.createElement(TablePage, _extends({}, tablePageFetchConfig, {
1525
+ ref: tablePageRef
1526
+ }, dataFormat ? {
1527
+ dataFormat
1528
+ } : null, {
1529
+ pagination: Object.assign({
1530
+ open: false,
1531
+ showSizeChanger: false,
1532
+ showQuickJumper: false,
1533
+ hideOnSinglePage: true
1534
+ }, paginationProp),
1535
+ scroll: isMobile ? undefined : Object.assign({
1536
+ y: (isPopup ? TABLE_LIST_MAX_HEIGHT_POPUP : TABLE_LIST_MAX_HEIGHT_EMBED) - TABLE_HEADER_HEIGHT
1537
+ }, allColumnsHaveWidth ? null : {
1538
+ x: undefined
1539
+ }),
1540
+ controllerOpen: false,
1541
+ columns: columns,
1542
+ rowKey: valueKey,
1543
+ rowSelection: tableSelection,
1544
+ columnRenderProps: Object.assign({}, targetProps, {
1545
+ isSelectedAll
1546
+ }),
1547
+ empty: props.empty || /*#__PURE__*/React.createElement(Empty, {
1548
+ className: classnames(style$2['empty'])
1549
+ }),
1550
+ dataType: dataType,
1551
+ parentKey: parentKey,
1552
+ childrenKey: childrenKey,
1553
+ hasChildrenKey: hasChildrenKey,
1554
+ treeTitleKey: resolvedTreeTitleKey,
1555
+ renderMobile: renderMobile === false ? false : typeof renderMobile === 'function' ? mobileProps => renderMobile(_extends({}, mobileProps, targetProps, {
1556
+ isSelectedAll,
1557
+ list: mobileProps.displayDataSource || mobileProps.dataSource,
1558
+ dataSource: mobileProps.dataSource,
1559
+ renderBody: (nextList = mobileProps.displayDataSource || mobileProps.dataSource, nextContext) => mobileProps.renderBody(nextList, nextContext)
1560
+ })) : true
1561
+ }, typeof onLoadChildren === 'function' ? {
1562
+ onLoadChildren
1563
+ } : null, typeof onExpandedKeysChange === 'function' ? {
1564
+ onExpandedKeysChange
1565
+ } : null, indentSize != null ? {
1566
+ indentSize
1567
+ } : null, Object.prototype.hasOwnProperty.call(p, 'expandedKeys') ? {
1568
+ expandedKeys
1569
+ } : null, Object.prototype.hasOwnProperty.call(p, 'defaultExpandedKeys') ? {
1570
+ defaultExpandedKeys
1571
+ } : null))) : null), single && footerEl || !isMobile && /*#__PURE__*/React.createElement("div", {
1553
1572
  className: classnames(style$2['footer'], 'select-table-footer')
1554
1573
  }));
1555
1574