@kne/super-select 0.1.41 → 0.1.42

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.
@@ -17,7 +17,8 @@ import SimpleBar from 'simplebar-react';
17
17
  import SearchInput from '@kne/search-input';
18
18
  import { FetchScrollLoader } from '@kne/scroll-loader';
19
19
  import '@kne/scroll-loader/dist/index.css';
20
- import TableView from '@kne/table-view';
20
+ import TableView, { isTreeDataType, normalizeTreeData, flattenAllTree } from '@kne/table-view';
21
+ export { mergeTreeChildren } from '@kne/table-view';
21
22
  import '@kne/table-view/dist/index.css';
22
23
  import { CentralContent } from '@kne/info-page';
23
24
  import '@kne/info-page/dist/index.css';
@@ -168,7 +169,7 @@ const TagOverflowInner = ({
168
169
  }, "+", hiddenCount));
169
170
  };
170
171
 
171
- const _excluded$4 = ["children"];
172
+ const _excluded$3 = ["children"];
172
173
  const MOBILE_SHEET_MAX_HEIGHT = '80%';
173
174
  const MOBILE_SHEET_MIN_HEIGHT = '30%';
174
175
  const MOBILE_MASK_Z_INDEX = 1000;
@@ -243,7 +244,7 @@ const ModalContent = _ref => {
243
244
  let {
244
245
  children: renderContent
245
246
  } = _ref,
246
- others = _objectWithoutPropertiesLoose(_ref, _excluded$4);
247
+ others = _objectWithoutPropertiesLoose(_ref, _excluded$3);
247
248
  const {
248
249
  open,
249
250
  value: propsValue
@@ -928,12 +929,12 @@ const SelectedTagList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
928
929
 
929
930
  var style$3 = {"kne-responsive-boundary":"kne-super-select_Nc-y4","kne-responsive-scroll":"kne-super-select_RlrDm","list":"kne-super-select_IsXdU","empty":"kne-super-select_SQZ8k","default-list":"kne-super-select_QD1Mz","is-selected-all":"kne-super-select_M-mOy","default-list-item":"kne-super-select_KtOsz","is-selected":"kne-super-select_TQhBB","single-checked":"kne-super-select_2rUrh","is-disabled":"kne-super-select_NbwX5","selected-all":"kne-super-select_vN2Fx","selected-tag":"kne-super-select_6oITk","select-search":"kne-super-select_iAH9D","select-list-item-description":"kne-super-select_TCkeJ","footer":"kne-super-select_v3f23","is-mobile":"kne-super-select_w-WB8"};
930
931
 
931
- const _excluded$3 = ["children"];
932
+ const _excluded$2 = ["children"];
932
933
  const SelectList = forwardRef((_ref, ref) => {
933
934
  let {
934
935
  children
935
936
  } = _ref,
936
- p = _objectWithoutPropertiesLoose(_ref, _excluded$3);
937
+ p = _objectWithoutPropertiesLoose(_ref, _excluded$2);
937
938
  const fetchListRef = useRef(null);
938
939
  const props = Object.assign({}, {
939
940
  renderItemContent: ({
@@ -1141,7 +1142,74 @@ const SelectList = forwardRef((_ref, ref) => {
1141
1142
 
1142
1143
  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"};
1143
1144
 
1144
- const _excluded$2 = ["renderBody"];
1145
+ const isEmptyParentKey = value => value == null || value === '';
1146
+ const flattenSelectList = (list, {
1147
+ dataType,
1148
+ rowKey,
1149
+ parentKey,
1150
+ childrenKey
1151
+ }) => {
1152
+ if (!list || !isTreeDataType(dataType)) {
1153
+ return list || [];
1154
+ }
1155
+ const tree = normalizeTreeData(list, {
1156
+ dataType,
1157
+ rowKey,
1158
+ parentKey,
1159
+ childrenKey
1160
+ });
1161
+ return flattenAllTree(tree, {
1162
+ rowKey,
1163
+ childrenKey
1164
+ }).map(row => row.item);
1165
+ };
1166
+ const filterTreeOptions = (options, searchProps, getSearchCallback, targetProps, {
1167
+ dataType,
1168
+ valueKey,
1169
+ parentKey,
1170
+ childrenKey
1171
+ }) => {
1172
+ if (typeof getSearchCallback !== 'function') {
1173
+ return options;
1174
+ }
1175
+ if (dataType === 'tree') {
1176
+ const filterNodes = nodes => (nodes || []).reduce((acc, item) => {
1177
+ const rawChildren = Array.isArray(item[childrenKey]) ? item[childrenKey] : [];
1178
+ const filteredChildren = filterNodes(rawChildren);
1179
+ const selfMatch = getSearchCallback(searchProps, item, targetProps);
1180
+ if (selfMatch) {
1181
+ acc.push(item);
1182
+ } else if (filteredChildren.length > 0) {
1183
+ acc.push(Object.assign({}, item, {
1184
+ [childrenKey]: filteredChildren
1185
+ }));
1186
+ }
1187
+ return acc;
1188
+ }, []);
1189
+ return filterNodes(options);
1190
+ }
1191
+ if (dataType === 'treeList') {
1192
+ const matched = options.filter(item => getSearchCallback(searchProps, item, targetProps));
1193
+ if (matched.length === 0) {
1194
+ return [];
1195
+ }
1196
+ const idSet = new Set(matched.map(item => item[valueKey]));
1197
+ const map = new Map(options.map(item => [item[valueKey], item]));
1198
+ matched.forEach(item => {
1199
+ let parentId = item[parentKey];
1200
+ while (!isEmptyParentKey(parentId) && !idSet.has(parentId)) {
1201
+ idSet.add(parentId);
1202
+ const parent = map.get(parentId);
1203
+ if (!parent) {
1204
+ break;
1205
+ }
1206
+ parentId = parent[parentKey];
1207
+ }
1208
+ });
1209
+ return options.filter(item => idSet.has(item[valueKey]));
1210
+ }
1211
+ return options.filter(item => getSearchCallback(searchProps, item, targetProps));
1212
+ };
1145
1213
  const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select')(forwardRef((p, ref) => {
1146
1214
  const {
1147
1215
  formatMessage
@@ -1150,6 +1218,10 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1150
1218
  const fetchListRef = useRef();
1151
1219
  const props = Object.assign({}, {
1152
1220
  overlayWidth: '600px',
1221
+ dataType: 'list',
1222
+ parentKey: 'parentId',
1223
+ childrenKey: 'children',
1224
+ hasChildrenKey: 'hasChildren',
1153
1225
  filterRender: contextProps => {
1154
1226
  const {
1155
1227
  props,
@@ -1225,9 +1297,21 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1225
1297
  allowSelectedAll,
1226
1298
  labelKey,
1227
1299
  valueKey,
1228
- renderMobile
1300
+ renderMobile,
1301
+ dataType,
1302
+ parentKey,
1303
+ childrenKey,
1304
+ hasChildrenKey,
1305
+ treeTitleKey,
1306
+ onLoadChildren,
1307
+ expandedKeys,
1308
+ defaultExpandedKeys,
1309
+ onExpandedKeysChange,
1310
+ indentSize,
1311
+ checkRelation
1229
1312
  } = props;
1230
1313
  const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
1314
+ const resolvedTreeTitleKey = treeTitleKey || labelKey;
1231
1315
  const footerEl = footer && /*#__PURE__*/React.createElement("div", {
1232
1316
  className: classnames(style$2['footer'], 'select-table-footer')
1233
1317
  }, typeof footer === 'function' ? footer({
@@ -1239,7 +1323,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1239
1323
  onOpenChange(false);
1240
1324
  }
1241
1325
  }) : footer);
1242
- const renderScrollList = renderBody => /*#__PURE__*/React.createElement(FetchScrollLoader, _extends({}, props, {
1326
+ const renderScrollList = renderContent => /*#__PURE__*/React.createElement(FetchScrollLoader, _extends({}, props, {
1243
1327
  className: classnames(style$2['list'], 'select-table-list-scroll-list', {
1244
1328
  'is-popup': isPopup
1245
1329
  }),
@@ -1258,14 +1342,13 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1258
1342
  options,
1259
1343
  searchProps
1260
1344
  } = data;
1261
- if (typeof getSearchCallback === 'function') {
1262
- const newOptions = options.filter(item => getSearchCallback(searchProps, item, targetProps));
1263
- return {
1264
- pageData: newOptions
1265
- };
1266
- }
1267
1345
  return {
1268
- pageData: options
1346
+ pageData: filterTreeOptions(options, searchProps, getSearchCallback, targetProps, {
1347
+ dataType,
1348
+ valueKey,
1349
+ parentKey,
1350
+ childrenKey
1351
+ })
1269
1352
  };
1270
1353
  }
1271
1354
  } : api)
@@ -1282,7 +1365,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1282
1365
  className: classnames(style$2['empty'])
1283
1366
  });
1284
1367
  }
1285
- return renderBody(list, contextProps);
1368
+ return renderContent(list, contextProps);
1286
1369
  });
1287
1370
  const tableSelection = {
1288
1371
  allowSelectedAll,
@@ -1292,27 +1375,20 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1292
1375
  },
1293
1376
  type: single ? 'radio' : 'checkbox',
1294
1377
  selectedRowKeys: (value || []).map(item => item[valueKey]),
1295
- onChange: (selectedRowKeys, selectedKey, {
1296
- checked
1297
- }) => {
1298
- setValue(value => {
1299
- if (checked) {
1300
- var _fetchListRef$current3;
1301
- const selectedItem = (_fetchListRef$current3 = fetchListRef.current) == null ? void 0 : _fetchListRef$current3.list.find(item => item[valueKey] === selectedKey);
1302
- if (selectedItem) {
1303
- if (single) {
1304
- return [selectedItem];
1305
- }
1306
- const newValue = value.slice(0);
1307
- newValue.push(selectedItem);
1308
- return newValue;
1309
- }
1310
- return value;
1311
- } else {
1312
- return value.filter(item => item[valueKey] !== selectedKey);
1313
- }
1378
+ checkRelation,
1379
+ onChange: selectedRowKeys => {
1380
+ setValue(prev => {
1381
+ var _fetchListRef$current3;
1382
+ const prevMap = new Map((prev || []).map(item => [item[valueKey], item]));
1383
+ const listMap = new Map(flattenSelectList((_fetchListRef$current3 = fetchListRef.current) == null ? void 0 : _fetchListRef$current3.list, {
1384
+ dataType,
1385
+ rowKey: valueKey,
1386
+ parentKey,
1387
+ childrenKey
1388
+ }).map(item => [item[valueKey], item]));
1389
+ return (selectedRowKeys || []).map(key => prevMap.get(key) || listMap.get(key)).filter(Boolean);
1314
1390
  });
1315
- if (isPopup && single) {
1391
+ if (isPopup && single && selectedRowKeys && selectedRowKeys.length > 0) {
1316
1392
  onOpenChange(false);
1317
1393
  }
1318
1394
  }
@@ -1391,21 +1467,6 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1391
1467
  className: style$2['selected-tags-scroll']
1392
1468
  }, selectedTags);
1393
1469
  })(), footerEl);
1394
- const tableMobileRender = _ref => {
1395
- let {
1396
- renderBody
1397
- } = _ref,
1398
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
1399
- return renderScrollList((list, contextProps) => {
1400
- if (typeof renderMobile === 'function') {
1401
- return renderMobile(_extends({}, rest, contextProps, {
1402
- list,
1403
- renderBody: (nextList = list, nextContext = contextProps) => renderBody(nextList, nextContext)
1404
- }));
1405
- }
1406
- return renderBody(list, contextProps);
1407
- });
1408
- };
1409
1470
  const tablePanel = /*#__PURE__*/React.createElement("div", {
1410
1471
  className: classnames(style$2['table-panel'], {
1411
1472
  [style$2['single-body']]: single
@@ -1414,14 +1475,41 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1414
1475
  className: style$2['filter-wrap']
1415
1476
  }, filterRender(Object.assign({}, targetProps))), /*#__PURE__*/React.createElement("div", {
1416
1477
  className: classnames(style$2['table'], 'select-table')
1417
- }, /*#__PURE__*/React.createElement(TableView, {
1418
- columns: columns,
1419
- rowKey: valueKey,
1420
- rowSelection: tableSelection,
1421
- renderMobile: renderMobile === false ? undefined : tableMobileRender,
1422
- render: ({
1423
- renderBody
1424
- }) => renderScrollList(renderBody)
1478
+ }, renderScrollList((list, contextProps) => {
1479
+ const tableViewProps = {
1480
+ dataSource: list,
1481
+ columns,
1482
+ rowKey: valueKey,
1483
+ rowSelection: tableSelection,
1484
+ context: contextProps,
1485
+ dataType,
1486
+ parentKey,
1487
+ childrenKey,
1488
+ hasChildrenKey,
1489
+ treeTitleKey: resolvedTreeTitleKey,
1490
+ renderMobile: renderMobile === false ? false : typeof renderMobile === 'function' ? mobileProps => renderMobile(_extends({}, mobileProps, contextProps, {
1491
+ list: mobileProps.displayDataSource || list,
1492
+ dataSource: list,
1493
+ renderBody: (nextList = mobileProps.displayDataSource || list, nextContext = contextProps) => mobileProps.renderBody(nextList, nextContext)
1494
+ })) : true
1495
+ };
1496
+ // 可选树形 props:仅在有值 / 用户显式传入时透传,避免 undefined 覆盖 TableView 默认值
1497
+ if (typeof onLoadChildren === 'function') {
1498
+ tableViewProps.onLoadChildren = onLoadChildren;
1499
+ }
1500
+ if (typeof onExpandedKeysChange === 'function') {
1501
+ tableViewProps.onExpandedKeysChange = onExpandedKeysChange;
1502
+ }
1503
+ if (indentSize != null) {
1504
+ tableViewProps.indentSize = indentSize;
1505
+ }
1506
+ if (Object.prototype.hasOwnProperty.call(p, 'expandedKeys')) {
1507
+ tableViewProps.expandedKeys = expandedKeys;
1508
+ }
1509
+ if (Object.prototype.hasOwnProperty.call(p, 'defaultExpandedKeys')) {
1510
+ tableViewProps.defaultExpandedKeys = defaultExpandedKeys;
1511
+ }
1512
+ return /*#__PURE__*/React.createElement(TableView, tableViewProps);
1425
1513
  })), single && footerEl || !isMobile && /*#__PURE__*/React.createElement("div", {
1426
1514
  className: classnames(style$2['footer'], 'select-table-footer')
1427
1515
  }));