@kne/super-select 0.1.46 → 0.1.47

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,40 @@ 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 tablePageFetchConfig = options ? {
1382
+ data: {
1383
+ options,
1384
+ searchProps
1385
+ },
1386
+ loader: ({
1387
+ data
1388
+ }) => {
1389
+ const {
1390
+ options: nextOptions,
1391
+ searchProps: nextSearchProps
1392
+ } = data;
1393
+ const pageData = filterTreeOptions(nextOptions, nextSearchProps, getSearchCallback, targetProps, {
1394
+ dataType,
1395
+ valueKey,
1396
+ parentKey,
1397
+ childrenKey
1405
1398
  });
1399
+ return {
1400
+ pageData,
1401
+ totalCount: pageData.length
1402
+ };
1406
1403
  }
1407
- return renderContent(list, contextProps);
1408
- }) : null;
1404
+ } : merge({}, api, typeof getSearchProps === 'function' && isNotEmpty(searchProps) ? {
1405
+ data: getSearchProps(searchProps) || {}
1406
+ } : {});
1407
+ const allColumnsHaveWidth = Array.isArray(columns) && columns.length > 0 && columns.every(hasColumnWidth);
1409
1408
  const tableSelection = {
1410
1409
  allowSelectedAll,
1411
1410
  isSelectedAll,
@@ -1417,9 +1416,9 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1417
1416
  checkRelation,
1418
1417
  onChange: selectedRowKeys => {
1419
1418
  setValue(prev => {
1420
- var _fetchListRef$current3;
1419
+ var _tablePageRef$current2;
1421
1420
  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, {
1421
+ const listMap = new Map(flattenSelectList(getListFromPageData((_tablePageRef$current2 = tablePageRef.current) == null ? void 0 : _tablePageRef$current2.data), {
1423
1422
  dataType,
1424
1423
  rowKey: valueKey,
1425
1424
  parentKey,
@@ -1464,7 +1463,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1464
1463
  wrap: true,
1465
1464
  gap: 8
1466
1465
  }, value.filter(item => getTagSearchCallback(tagSearchText, item, targetProps)).map(item => {
1467
- var _fetchListRef$current4, _fetchListRef$current5;
1466
+ var _tablePageRef$current3;
1468
1467
  return /*#__PURE__*/React.createElement(Tag, {
1469
1468
  className: style$2['tag'],
1470
1469
  key: item[valueKey],
@@ -1488,8 +1487,8 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1488
1487
  })),
1489
1488
  dataSource: Object.assign({}, item),
1490
1489
  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
1490
+ fetchApi: tablePageRef.current,
1491
+ list: getListFromPageData((_tablePageRef$current3 = tablePageRef.current) == null ? void 0 : _tablePageRef$current3.data)
1493
1492
  })
1494
1493
  })
1495
1494
  }, /*#__PURE__*/React.createElement("span", {
@@ -1514,42 +1513,60 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1514
1513
  className: style$2['filter-wrap']
1515
1514
  }, filterRender(Object.assign({}, targetProps))), /*#__PURE__*/React.createElement("div", {
1516
1515
  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", {
1516
+ }, open ? /*#__PURE__*/React.createElement("div", {
1517
+ ref: listScrollRef,
1518
+ className: classnames(style$2['list'], 'select-table-list-scroll-list', {
1519
+ 'is-popup': isPopup,
1520
+ [style$2['is-fit-columns']]: !allColumnsHaveWidth
1521
+ })
1522
+ }, /*#__PURE__*/React.createElement(TablePage, _extends({}, tablePageFetchConfig, {
1523
+ ref: tablePageRef
1524
+ }, dataFormat ? {
1525
+ dataFormat
1526
+ } : null, {
1527
+ pagination: Object.assign({
1528
+ open: false,
1529
+ showSizeChanger: false,
1530
+ showQuickJumper: false,
1531
+ hideOnSinglePage: true
1532
+ }, paginationProp),
1533
+ scroll: isMobile ? undefined : Object.assign({
1534
+ y: (isPopup ? TABLE_LIST_MAX_HEIGHT_POPUP : TABLE_LIST_MAX_HEIGHT_EMBED) - TABLE_HEADER_HEIGHT
1535
+ }, allColumnsHaveWidth ? null : {
1536
+ x: undefined
1537
+ }),
1538
+ controllerOpen: false,
1539
+ columns: columns,
1540
+ rowKey: valueKey,
1541
+ rowSelection: tableSelection,
1542
+ columnRenderProps: Object.assign({}, targetProps, {
1543
+ isSelectedAll
1544
+ }),
1545
+ empty: props.empty || /*#__PURE__*/React.createElement(Empty, {
1546
+ className: classnames(style$2['empty'])
1547
+ }),
1548
+ dataType: dataType,
1549
+ parentKey: parentKey,
1550
+ childrenKey: childrenKey,
1551
+ hasChildrenKey: hasChildrenKey,
1552
+ treeTitleKey: resolvedTreeTitleKey,
1553
+ renderMobile: renderMobile === false ? false : typeof renderMobile === 'function' ? mobileProps => renderMobile(_extends({}, mobileProps, targetProps, {
1554
+ isSelectedAll,
1555
+ list: mobileProps.displayDataSource || mobileProps.dataSource,
1556
+ dataSource: mobileProps.dataSource,
1557
+ renderBody: (nextList = mobileProps.displayDataSource || mobileProps.dataSource, nextContext) => mobileProps.renderBody(nextList, nextContext)
1558
+ })) : true
1559
+ }, typeof onLoadChildren === 'function' ? {
1560
+ onLoadChildren
1561
+ } : null, typeof onExpandedKeysChange === 'function' ? {
1562
+ onExpandedKeysChange
1563
+ } : null, indentSize != null ? {
1564
+ indentSize
1565
+ } : null, Object.prototype.hasOwnProperty.call(p, 'expandedKeys') ? {
1566
+ expandedKeys
1567
+ } : null, Object.prototype.hasOwnProperty.call(p, 'defaultExpandedKeys') ? {
1568
+ defaultExpandedKeys
1569
+ } : null))) : null), single && footerEl || !isMobile && /*#__PURE__*/React.createElement("div", {
1553
1570
  className: classnames(style$2['footer'], 'select-table-footer')
1554
1571
  }));
1555
1572