@kne/super-select 0.1.33 → 0.1.34

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.
package/dist/index.js CHANGED
@@ -52,7 +52,7 @@ const {
52
52
  useContext
53
53
  } = context;
54
54
 
55
- var style$5 = {"select-input":"_d8lGc","disabled":"_3kjwO","wrap":"_dsTM2","select-input-inner":"_NQoX9","large":"_T8ZX8","small":"_1B72H","select-input-icon":"_g8QC-","placeholder":"_r3q69","overlay-content":"_zEqGe","overlay":"_ybN30","select-input-prefix":"_4Pw75","select-input-suffix":"_Wd4pE"};
55
+ var style$6 = {"select-input":"_d8lGc","disabled":"_3kjwO","wrap":"_dsTM2","select-input-inner":"_NQoX9","large":"_T8ZX8","small":"_1B72H","single-label":"_pL0tE","tag-item":"_lc4o7","tag-label":"_RJmlD","overflow-tag":"_aHua2","measure-layer":"_QoQpC","select-input-icon":"_g8QC-","placeholder":"_r3q69","overlay-content":"_zEqGe","overlay":"_ybN30","select-input-prefix":"_4Pw75","select-input-suffix":"_Wd4pE"};
56
56
 
57
57
  const locale$1 = {
58
58
  placeholder: '请选择',
@@ -76,7 +76,97 @@ const locale = {
76
76
  removeAll: 'Remove All'
77
77
  };
78
78
 
79
- const numberToPx = val => {
79
+ /**
80
+ * 标签溢出内部渲染组件
81
+ * 根据 innerWidth 计算标签显示数量
82
+ */
83
+ const TagOverflowInner = ({
84
+ value,
85
+ innerWidth,
86
+ labelKey,
87
+ valueKey,
88
+ onRemove,
89
+ overflowTagWidth = 45,
90
+ iconSpace = 20
91
+ }) => {
92
+ const [visibleCount, setVisibleCount] = React.useState(value.length);
93
+ const measureRef = React.useRef(null);
94
+
95
+ // 测量每个标签的实际宽度并计算可见数量
96
+ React.useLayoutEffect(() => {
97
+ // innerWidth 为 0 时,保持当前状态,等待正确的宽度
98
+ if (!measureRef.current || innerWidth === 0 || value.length === 0) {
99
+ setVisibleCount(value.length);
100
+ return;
101
+ }
102
+ const tagElements = measureRef.current.querySelectorAll('[data-tag-measure]');
103
+ if (tagElements.length === 0) return;
104
+
105
+ // 获取每个标签的实际占用宽度(包含 margin)
106
+ const tagWidths = Array.from(tagElements).map(el => {
107
+ const style = window.getComputedStyle(el);
108
+ const marginLeft = parseFloat(style.marginLeft) || 0;
109
+ const marginRight = parseFloat(style.marginRight) || 0;
110
+ return el.offsetWidth + marginLeft + marginRight;
111
+ });
112
+ const availableWidth = innerWidth - iconSpace;
113
+ let totalWidth = 0;
114
+ let count = 0;
115
+ for (let i = 0; i < tagWidths.length; i++) {
116
+ // 如果不是最后一个,需要预留 +N 标签空间
117
+ const needOverflowSpace = i < tagWidths.length - 1;
118
+ const requiredWidth = tagWidths[i] + (needOverflowSpace ? overflowTagWidth : 0);
119
+ if (totalWidth + requiredWidth <= availableWidth) {
120
+ totalWidth += tagWidths[i];
121
+ count++;
122
+ } else {
123
+ break;
124
+ }
125
+ }
126
+
127
+ // 确保至少显示一个标签
128
+ setVisibleCount(Math.max(1, count));
129
+ }, [value, innerWidth, overflowTagWidth, iconSpace]);
130
+
131
+ // 计算单个标签最大宽度:min(150px, innerWidth - 60),初始状态默认 150px
132
+ const maxTagWidth = innerWidth > 0 ? Math.min(150, Math.max(60, innerWidth - 60)) : 150;
133
+ const displayTags = value.slice(0, visibleCount);
134
+ const hiddenCount = value.length - visibleCount;
135
+ return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("div", {
136
+ ref: measureRef,
137
+ className: style$6['measure-layer']
138
+ }, value.map(item => /*#__PURE__*/React__default["default"].createElement(antd.Tag, {
139
+ key: item[valueKey],
140
+ "data-tag-measure": true,
141
+ closable: true,
142
+ bordered: false,
143
+ className: style$6['tag-item'],
144
+ style: {
145
+ '--max-tag-width': `${maxTagWidth}px`
146
+ }
147
+ }, /*#__PURE__*/React__default["default"].createElement("span", {
148
+ className: style$6['tag-label']
149
+ }, item[labelKey])))), displayTags.map(item => /*#__PURE__*/React__default["default"].createElement(antd.Tag, {
150
+ key: item[valueKey],
151
+ closable: true,
152
+ bordered: false,
153
+ className: style$6['tag-item'],
154
+ style: {
155
+ '--max-tag-width': `${maxTagWidth}px`
156
+ },
157
+ onClose: e => {
158
+ e.preventDefault();
159
+ onRemove(item);
160
+ }
161
+ }, /*#__PURE__*/React__default["default"].createElement("span", {
162
+ className: style$6['tag-label'],
163
+ title: item[labelKey]
164
+ }, item[labelKey]))), hiddenCount > 0 && /*#__PURE__*/React__default["default"].createElement(antd.Tag, {
165
+ className: style$6['overflow-tag']
166
+ }, "+", hiddenCount));
167
+ };
168
+
169
+ const numberToPx$1 = val => {
80
170
  return typeof val === 'number' ? `${val}px` : val;
81
171
  };
82
172
  const pxToNumber = value => {
@@ -233,11 +323,21 @@ const SelectInput = reactIntl.createWithIntlProvider({
233
323
  onChange: 'onOpenChange'
234
324
  });
235
325
  const [hover, setHover] = React.useState(false);
236
- const [inputWidth, setInputWidth] = React.useState(0);
237
- const inputRef = useResize__default["default"](el => {
238
- setInputWidth(el.clientWidth);
239
- });
240
- const popupOverlayWidth = numberToPx(Math.max(inputWidth, pxToNumber(overlayWidth)));
326
+ const [innerWidth, setInnerWidth] = React.useState(0);
327
+ const [containerWidth, setContainerWidth] = React.useState(0);
328
+ const containerWidthChange = el => {
329
+ if (!el) {
330
+ return;
331
+ }
332
+ const containerWidth = el.clientWidth;
333
+ setContainerWidth(containerWidth);
334
+ const innerEl = el.querySelector('.select-input-inner');
335
+ setInnerWidth(innerEl.clientWidth);
336
+ };
337
+ const popupOverlayWidth = React.useMemo(() => {
338
+ return numberToPx$1(Math.max(containerWidth, pxToNumber(overlayWidth)));
339
+ }, [containerWidth, overlayWidth]);
340
+ const containerRef = useResize__default["default"](containerWidthChange);
241
341
  const {
242
342
  message
243
343
  } = antd.App.useApp();
@@ -297,7 +397,7 @@ const SelectInput = reactIntl.createWithIntlProvider({
297
397
  searchProps,
298
398
  setSearchProps,
299
399
  hover,
300
- inputWidth,
400
+ inputWidth: containerWidth,
301
401
  onAdd,
302
402
  onRemove,
303
403
  onSelect,
@@ -313,12 +413,12 @@ const SelectInput = reactIntl.createWithIntlProvider({
313
413
  return contextProps.props.inputRender(props, contextProps);
314
414
  }
315
415
  return /*#__PURE__*/React__default["default"].createElement(antd.Flex, _extends({}, props, {
316
- ref: inputRef,
317
- className: classnames__default["default"](className, style$5['select-input'], 'select-input', {
318
- [style$5['wrap']]: labelWrap,
319
- [style$5['disabled']]: disabled,
320
- [style$5['small']]: size === 'small',
321
- [style$5['large']]: size === 'large'
416
+ ref: containerRef,
417
+ className: classnames__default["default"](className, style$6['select-input'], 'select-input', {
418
+ [style$6['wrap']]: labelWrap,
419
+ [style$6['disabled']]: disabled,
420
+ [style$6['small']]: size === 'small',
421
+ [style$6['large']]: size === 'large'
322
422
  }),
323
423
  justify: "space-between",
324
424
  onMouseOver: () => {
@@ -330,27 +430,26 @@ const SelectInput = reactIntl.createWithIntlProvider({
330
430
  }), (() => {
331
431
  const current = typeof prefix === 'function' ? prefix(contextProps) : prefix;
332
432
  return current && /*#__PURE__*/React__default["default"].createElement("span", {
333
- className: classnames__default["default"](style$5['select-input-prefix'], 'select-input-prefix'),
433
+ className: classnames__default["default"](style$6['select-input-prefix'], 'select-input-prefix'),
334
434
  onClick: e => {
335
435
  e.stopPropagation();
336
436
  }
337
437
  }, current);
338
438
  })(), /*#__PURE__*/React__default["default"].createElement("div", {
339
- className: classnames__default["default"](style$5['select-input-inner'], 'select-input-inner')
340
- }, value.length > 0 ? single || value[0][valueKey] === selectedAllValue[valueKey] ? value[0][labelKey] : value.map(item => {
341
- return /*#__PURE__*/React__default["default"].createElement(antd.Tag, {
342
- key: item[valueKey],
343
- closable: true,
344
- bordered: false,
345
- onClose: e => {
346
- e.preventDefault();
347
- onRemove(item);
348
- }
349
- }, item[labelKey]);
439
+ className: classnames__default["default"](style$6['select-input-inner'], 'select-input-inner')
440
+ }, value.length > 0 ? single || value[0][valueKey] === selectedAllValue[valueKey] ? /*#__PURE__*/React__default["default"].createElement("span", {
441
+ className: classnames__default["default"](style$6['single-label'], 'select-input-single-label'),
442
+ title: value[0][labelKey]
443
+ }, value[0][labelKey]) : /*#__PURE__*/React__default["default"].createElement(TagOverflowInner, {
444
+ value: value,
445
+ innerWidth: innerWidth,
446
+ labelKey: labelKey,
447
+ valueKey: valueKey,
448
+ onRemove: onRemove
350
449
  }) : /*#__PURE__*/React__default["default"].createElement("span", {
351
- className: classnames__default["default"](style$5['placeholder'], 'select-input-placeholder')
450
+ className: classnames__default["default"](style$6['placeholder'], 'select-input-placeholder')
352
451
  }, placeholder)), /*#__PURE__*/React__default["default"].createElement("div", {
353
- className: classnames__default["default"](style$5['select-input-icon'], 'select-input-icon')
452
+ className: classnames__default["default"](style$6['select-input-icon'], 'select-input-icon')
354
453
  }, !disabled && allowClear && hover && value.length > 0 ? /*#__PURE__*/React__default["default"].createElement(icons.CloseCircleFilled, {
355
454
  onClick: e => {
356
455
  e.stopPropagation();
@@ -359,7 +458,7 @@ const SelectInput = reactIntl.createWithIntlProvider({
359
458
  }) : /*#__PURE__*/React__default["default"].createElement(icons.DownOutlined, null)), (() => {
360
459
  const current = typeof suffix === 'function' ? suffix(contextProps) : suffix;
361
460
  return current && /*#__PURE__*/React__default["default"].createElement("span", {
362
- className: classnames__default["default"](style$5['select-input-suffix'], 'select-input-suffix'),
461
+ className: classnames__default["default"](style$6['select-input-suffix'], 'select-input-suffix'),
363
462
  onClick: e => {
364
463
  e.stopPropagation();
365
464
  }
@@ -379,13 +478,13 @@ const SelectInput = reactIntl.createWithIntlProvider({
379
478
  onOpenChange: setOpen,
380
479
  placement: placement,
381
480
  arrow: false,
382
- overlayClassName: classnames__default["default"](style$5['overlay'], overlayClassName),
481
+ overlayClassName: classnames__default["default"](style$6['overlay'], overlayClassName),
383
482
  trigger: "click",
384
483
  popupRender: () => /*#__PURE__*/React__default["default"].createElement("div", {
385
484
  style: {
386
485
  '--overlay-width': popupOverlayWidth
387
486
  },
388
- className: classnames__default["default"](style$5['overlay-content'], 'over-content'),
487
+ className: classnames__default["default"](style$6['overlay-content'], 'over-content'),
389
488
  onClick: e => {
390
489
  e.stopPropagation();
391
490
  }
@@ -397,7 +496,7 @@ const SelectInput = reactIntl.createWithIntlProvider({
397
496
  }), /*#__PURE__*/React__default["default"].createElement(ModalContent, contextProps, renderModal)));
398
497
  }));
399
498
 
400
- var style$4 = {"selected-all":"_prlgN"};
499
+ var style$5 = {"selected-all":"_prlgN"};
401
500
 
402
501
  const SelectedAll = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'super-select')(() => {
403
502
  const {
@@ -422,7 +521,7 @@ const SelectedAll = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'super-s
422
521
  const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
423
522
  return /*#__PURE__*/React__default["default"].createElement(antd.Flex, {
424
523
  justify: "space-between",
425
- className: classnames__default["default"](style$4['selected-all'], 'selected-all')
524
+ className: classnames__default["default"](style$5['selected-all'], 'selected-all')
426
525
  }, /*#__PURE__*/React__default["default"].createElement(antd.Flex, {
427
526
  gap: 8
428
527
  }, /*#__PURE__*/React__default["default"].createElement("span", null, formatMessage({
@@ -448,7 +547,7 @@ const computedIsSelectAll = function (value, selectedAllValue, valueKey) {
448
547
  return value?.length === 1 && get__default["default"](value, `[0][${valueKey}]`) === selectedAllValue[valueKey];
449
548
  };
450
549
 
451
- var style$3 = {"label":"_l3KoW","tag-list":"_CCPzb","tag-container":"_dKZHi","tag-container-inner":"_oijCI","tag":"_WmnnS","tag-inner":"_TMcFl"};
550
+ var style$4 = {"label":"_l3KoW","tag-list":"_CCPzb","tag-container":"_dKZHi","tag-container-inner":"_oijCI","tag":"_WmnnS","tag-inner":"_TMcFl"};
452
551
 
453
552
  const SelectedTagList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'super-select')(() => {
454
553
  const {
@@ -466,21 +565,21 @@ const SelectedTagList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
466
565
  valueKey
467
566
  } = Object.assign({}, props);
468
567
  return /*#__PURE__*/React__default["default"].createElement(antd.Flex, {
469
- className: classnames__default["default"](style$3['tag-list'], 'selected-tag-list'),
568
+ className: classnames__default["default"](style$4['tag-list'], 'selected-tag-list'),
470
569
  gap: 8
471
570
  }, /*#__PURE__*/React__default["default"].createElement("div", {
472
- className: style$3['label']
571
+ className: style$4['label']
473
572
  }, formatMessage({
474
573
  id: 'selected'
475
574
  }), !single && value.length > 0 && `(${value.length}${Number.isInteger(maxLength) ? `/${maxLength}` : ''})`, ":"), /*#__PURE__*/React__default["default"].createElement(SimpleBar__default["default"], {
476
- className: style$3['tag-container']
575
+ className: style$4['tag-container']
477
576
  }, /*#__PURE__*/React__default["default"].createElement(antd.Flex, {
478
577
  gap: 8,
479
578
  wrap: true,
480
- className: style$3['tag-container-inner']
579
+ className: style$4['tag-container-inner']
481
580
  }, value.map(item => {
482
581
  return /*#__PURE__*/React__default["default"].createElement(antd.Tag, {
483
- className: style$3['tag'],
582
+ className: style$4['tag'],
484
583
  key: item[valueKey],
485
584
  closable: true,
486
585
  bordered: false,
@@ -489,12 +588,12 @@ const SelectedTagList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
489
588
  onRemove(item);
490
589
  }
491
590
  }, /*#__PURE__*/React__default["default"].createElement("span", {
492
- className: style$3['tag-inner']
591
+ className: style$4['tag-inner']
493
592
  }, item[labelKey]));
494
593
  }))));
495
594
  });
496
595
 
497
- var style$2 = {"list":"_IsXdU","is-popup":"_-dvpa","empty":"_SQZ8k","default-list":"_QD1Mz","is-selected-all":"_M-mOy","default-list-item":"_KtOsz","is-selected":"_TQhBB","single-checked":"_2rUrh","is-disabled":"_NbwX5","selected-all":"_vN2Fx","selected-tag":"_6oITk","select-search":"_iAH9D","select-list-item-description":"_TCkeJ","footer":"_v3f23"};
596
+ var style$3 = {"list":"_IsXdU","is-popup":"_-dvpa","empty":"_SQZ8k","default-list":"_QD1Mz","is-selected-all":"_M-mOy","default-list-item":"_KtOsz","is-selected":"_TQhBB","single-checked":"_2rUrh","is-disabled":"_NbwX5","selected-all":"_vN2Fx","selected-tag":"_6oITk","select-search":"_iAH9D","select-list-item-description":"_TCkeJ","footer":"_v3f23"};
498
597
 
499
598
  const SelectList = React.forwardRef((_ref, ref) => {
500
599
  let {
@@ -514,7 +613,7 @@ const SelectList = React.forwardRef((_ref, ref) => {
514
613
  return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("div", {
515
614
  className: 'select-list-item-label'
516
615
  }, item[labelKey]), item.description && /*#__PURE__*/React__default["default"].createElement("div", {
517
- className: classnames__default["default"](style$2['select-list-item-description'], 'select-list-item-description')
616
+ className: classnames__default["default"](style$3['select-list-item-description'], 'select-list-item-description')
518
617
  }, item.description));
519
618
  },
520
619
  renderItem: contextProps => {
@@ -535,9 +634,9 @@ const SelectList = React.forwardRef((_ref, ref) => {
535
634
  } = props;
536
635
  const isChecked = value.some(target => target[valueKey] === item[valueKey]);
537
636
  return /*#__PURE__*/React__default["default"].createElement(antd.List.Item, {
538
- className: classnames__default["default"](style$2['default-list-item'], 'select-list-item', {
539
- [style$2['is-selected']]: isChecked,
540
- [style$2['is-disabled']]: item.disabled
637
+ className: classnames__default["default"](style$3['default-list-item'], 'select-list-item', {
638
+ [style$3['is-selected']]: isChecked,
639
+ [style$3['is-disabled']]: item.disabled
541
640
  }),
542
641
  key: item[valueKey],
543
642
  onClick: () => {
@@ -565,7 +664,7 @@ const SelectList = React.forwardRef((_ref, ref) => {
565
664
  flex: 1,
566
665
  className: 'select-list-item-content'
567
666
  }, renderItemContent(contextProps)), single && /*#__PURE__*/React__default["default"].createElement("div", {
568
- className: style$2['single-checked']
667
+ className: style$3['single-checked']
569
668
  }, isChecked && /*#__PURE__*/React__default["default"].createElement(icons.CheckOutlined, null)));
570
669
  },
571
670
  renderList: contextProps => {
@@ -579,12 +678,12 @@ const SelectList = React.forwardRef((_ref, ref) => {
579
678
  } = props;
580
679
  if (!(list && list.length > 0)) {
581
680
  return props.empty || /*#__PURE__*/React__default["default"].createElement(antd.Empty, {
582
- className: style$2['empty']
681
+ className: style$3['empty']
583
682
  });
584
683
  }
585
684
  return /*#__PURE__*/React__default["default"].createElement(antd.List, {
586
- className: classnames__default["default"](style$2['default-list'], {
587
- [style$2['is-selected-all']]: isSelectedAll
685
+ className: classnames__default["default"](style$3['default-list'], {
686
+ [style$3['is-selected-all']]: isSelectedAll
588
687
  }),
589
688
  size: "small",
590
689
  dataSource: list,
@@ -621,7 +720,7 @@ const SelectList = React.forwardRef((_ref, ref) => {
621
720
  } = props;
622
721
  const components = {
623
722
  search: (api && typeof getSearchProps === 'function' || options && typeof getSearchCallback === 'function') && /*#__PURE__*/React__default["default"].createElement(SearchInput__default["default"], {
624
- className: classnames__default["default"](style$2['select-search'], 'select-list-search', {
723
+ className: classnames__default["default"](style$3['select-search'], 'select-list-search', {
625
724
  'is-popup': isPopup
626
725
  }),
627
726
  placeholder: searchPlaceholder,
@@ -635,12 +734,12 @@ const SelectList = React.forwardRef((_ref, ref) => {
635
734
  showSearchButton: !isPopup
636
735
  }),
637
736
  selectedAll: /*#__PURE__*/React__default["default"].createElement("div", {
638
- className: classnames__default["default"](style$2['selected-all'], 'select-list-selected-all', {
737
+ className: classnames__default["default"](style$3['selected-all'], 'select-list-selected-all', {
639
738
  'is-popup': isPopup
640
739
  })
641
740
  }, !single && allowSelectedAll && /*#__PURE__*/React__default["default"].createElement(SelectedAll, null)),
642
741
  fetchList: /*#__PURE__*/React__default["default"].createElement(scrollLoader.FetchScrollLoader, _extends({}, props, {
643
- className: classnames__default["default"](style$2['list'], 'select-list-scroll-list', {
742
+ className: classnames__default["default"](style$3['list'], 'select-list-scroll-list', {
644
743
  'is-popup': isPopup
645
744
  }),
646
745
  searchProps: searchProps,
@@ -677,12 +776,12 @@ const SelectList = React.forwardRef((_ref, ref) => {
677
776
  }));
678
777
  }),
679
778
  selectedTag: showSelectedTag && /*#__PURE__*/React__default["default"].createElement("div", {
680
- className: classnames__default["default"](style$2['selected-tag'], 'select-list-selected-tag', {
779
+ className: classnames__default["default"](style$3['selected-tag'], 'select-list-selected-tag', {
681
780
  'is-popup': isPopup
682
781
  })
683
782
  }, /*#__PURE__*/React__default["default"].createElement(SelectedTagList, null)),
684
783
  footer: footer && /*#__PURE__*/React__default["default"].createElement("div", {
685
- className: classnames__default["default"](style$2['footer'], 'select-list-footer')
784
+ className: classnames__default["default"](style$3['footer'], 'select-list-footer')
686
785
  }, typeof footer === 'function' ? footer({
687
786
  reload: () => {
688
787
  fetchListRef.current && fetchListRef.current.reload();
@@ -703,7 +802,7 @@ const SelectList = React.forwardRef((_ref, ref) => {
703
802
  });
704
803
  });
705
804
 
706
- var style$1 = {"list":"_DrEYJ","is-popup":"_KgWTX","empty":"_5Tyrt","table":"_zE-14","right-options":"_UXi-g","no-padding-btn":"_iaCir","tag":"_JkYqS","tag-inner":"_VZlBL","single-checked":"_Eiz-u","select-search":"_temy6","tags-search":"_7phL2","descriptions":"_ttNK9","footer":"_lISfA"};
805
+ var style$2 = {"list":"_DrEYJ","is-popup":"_KgWTX","empty":"_5Tyrt","table":"_zE-14","right-options":"_UXi-g","no-padding-btn":"_iaCir","tag":"_JkYqS","tag-inner":"_VZlBL","single-checked":"_Eiz-u","select-search":"_temy6","tags-search":"_7phL2","descriptions":"_ttNK9","footer":"_lISfA"};
707
806
 
708
807
  const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'super-select')(React.forwardRef((p, ref) => {
709
808
  const {
@@ -732,7 +831,7 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
732
831
  return null;
733
832
  }
734
833
  return /*#__PURE__*/React__default["default"].createElement(SearchInput__default["default"], {
735
- className: classnames__default["default"](style$1['select-search'], 'select-table-search', {
834
+ className: classnames__default["default"](style$2['select-search'], 'select-table-search', {
736
835
  'is-popup': isPopup
737
836
  }),
738
837
  placeholder: searchPlaceholder,
@@ -792,7 +891,7 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
792
891
  } = props;
793
892
  const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
794
893
  const footerEl = footer && /*#__PURE__*/React__default["default"].createElement("div", {
795
- className: classnames__default["default"](style$1['footer'], 'select-table-footer')
894
+ className: classnames__default["default"](style$2['footer'], 'select-table-footer')
796
895
  }, typeof footer === 'function' ? footer({
797
896
  reload: () => {
798
897
  fetchListRef.current?.fetchApi && fetchListRef.current?.fetchApi.reload();
@@ -806,11 +905,11 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
806
905
  ref: bodyRef
807
906
  }, /*#__PURE__*/React__default["default"].createElement(antd.Col, {
808
907
  className: classnames__default["default"]({
809
- [style$1['single-body']]: single
908
+ [style$2['single-body']]: single
810
909
  }),
811
910
  span: single ? 24 : 16
812
911
  }, /*#__PURE__*/React__default["default"].createElement("div", null, filterRender(Object.assign({}, targetProps))), /*#__PURE__*/React__default["default"].createElement("div", {
813
- className: classnames__default["default"](style$1['table'], 'select-table')
912
+ className: classnames__default["default"](style$2['table'], 'select-table')
814
913
  }, /*#__PURE__*/React__default["default"].createElement(infoPage.TableView, {
815
914
  columns: columns,
816
915
  rowKey: valueKey,
@@ -853,7 +952,7 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
853
952
  renderBody
854
953
  } = _ref2;
855
954
  return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, header, /*#__PURE__*/React__default["default"].createElement(scrollLoader.FetchScrollLoader, _extends({}, props, {
856
- className: classnames__default["default"](style$1['list'], 'select-table-list-scroll-list', {
955
+ className: classnames__default["default"](style$2['list'], 'select-table-list-scroll-list', {
857
956
  'is-popup': isPopup
858
957
  }),
859
958
  searchProps: searchProps,
@@ -892,21 +991,21 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
892
991
  });
893
992
  if (!(list && list.length > 0)) {
894
993
  return props.empty || /*#__PURE__*/React__default["default"].createElement(antd.Empty, {
895
- className: classnames__default["default"](style$1['empty'])
994
+ className: classnames__default["default"](style$2['empty'])
896
995
  });
897
996
  }
898
997
  return renderBody(list, contextProps);
899
998
  }));
900
999
  }
901
1000
  })), single && footerEl || /*#__PURE__*/React__default["default"].createElement("div", {
902
- className: classnames__default["default"](style$1['footer'], 'select-table-footer')
1001
+ className: classnames__default["default"](style$2['footer'], 'select-table-footer')
903
1002
  })), !single && /*#__PURE__*/React__default["default"].createElement(antd.Col, {
904
- className: classnames__default["default"](style$1['right-options'], {
1003
+ className: classnames__default["default"](style$2['right-options'], {
905
1004
  'is-popup': isPopup
906
1005
  }),
907
1006
  span: 8
908
1007
  }, /*#__PURE__*/React__default["default"].createElement(SearchInput__default["default"], {
909
- className: style$1['tags-search'],
1008
+ className: style$2['tags-search'],
910
1009
  placeholder: searchPlaceholder,
911
1010
  value: tagSearchText,
912
1011
  onSearch: value => {
@@ -920,7 +1019,7 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
920
1019
  }, /*#__PURE__*/React__default["default"].createElement(antd.Col, null, formatMessage({
921
1020
  id: 'selected'
922
1021
  }), value.length > 0 && `(${value.length}${Number.isInteger(maxLength) ? `/${maxLength}` : ''})`, ":"), /*#__PURE__*/React__default["default"].createElement(antd.Col, null, /*#__PURE__*/React__default["default"].createElement(antd.Button, {
923
- className: style$1['no-padding-btn'],
1022
+ className: style$2['no-padding-btn'],
924
1023
  type: "link",
925
1024
  onClick: () => {
926
1025
  setValue([]);
@@ -932,7 +1031,7 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
932
1031
  gap: 8
933
1032
  }, value.filter(item => getTagSearchCallback(tagSearchText, item, targetProps)).map(item => {
934
1033
  return /*#__PURE__*/React__default["default"].createElement(antd.Tag, {
935
- className: style$1['tag'],
1034
+ className: style$2['tag'],
936
1035
  key: item[valueKey],
937
1036
  closable: true,
938
1037
  bordered: false,
@@ -943,7 +1042,7 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
943
1042
  }, /*#__PURE__*/React__default["default"].createElement(antd.Popover, {
944
1043
  getPopupContainer: () => bodyRef.current,
945
1044
  content: /*#__PURE__*/React__default["default"].createElement(infoPage.CentralContent, {
946
- className: style$1['descriptions'],
1045
+ className: style$2['descriptions'],
947
1046
  columns: columns.filter(item => {
948
1047
  if (Object.hasOwn(item, 'previewHidden')) {
949
1048
  return !item.previewHidden;
@@ -959,13 +1058,13 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
959
1058
  })
960
1059
  })
961
1060
  }, /*#__PURE__*/React__default["default"].createElement("span", {
962
- className: style$1['tag-inner']
1061
+ className: style$2['tag-inner']
963
1062
  }, item[labelKey])));
964
1063
  }))), footerEl));
965
1064
  });
966
1065
  }));
967
1066
 
968
- var style = {"list":"_YTqxA","is-popup":"_TR-1a","default-list":"_IZN7r","is-selected-all":"_GCIMn","default-list-item":"_AYi0i","is-selected":"_eovZv","single-checked":"_Tr-bO","is-disabled":"_T-hri","selected-all":"_4XFtm","selected-tag":"_Whlzr","select-search":"_7zuBL","select-tree-item-description":"_R-Sye","footer":"_PjlnR"};
1067
+ var style$1 = {"list":"_YTqxA","is-popup":"_TR-1a","default-list":"_IZN7r","is-selected-all":"_GCIMn","default-list-item":"_AYi0i","is-selected":"_eovZv","single-checked":"_Tr-bO","is-disabled":"_T-hri","selected-all":"_4XFtm","selected-tag":"_Whlzr","select-search":"_7zuBL","select-tree-item-description":"_R-Sye","footer":"_PjlnR"};
969
1068
 
970
1069
  const parseTreeData = memoize__default["default"](function (data, _ref) {
971
1070
  if (data === void 0) {
@@ -1031,9 +1130,9 @@ const SelectTree = React.forwardRef((_ref2, ref) => {
1031
1130
  } = props;
1032
1131
  const isChecked = value.some(target => target[valueKey] === item[valueKey]);
1033
1132
  return /*#__PURE__*/React__default["default"].createElement(antd.Flex, {
1034
- className: classnames__default["default"](style['default-list-item'], 'select-tree-item', {
1035
- [style['is-selected']]: isChecked,
1036
- [style['is-disabled']]: item.disabled
1133
+ className: classnames__default["default"](style$1['default-list-item'], 'select-tree-item', {
1134
+ [style$1['is-selected']]: isChecked,
1135
+ [style$1['is-disabled']]: item.disabled
1037
1136
  }),
1038
1137
  key: item[valueKey],
1039
1138
  onClick: () => {
@@ -1061,7 +1160,7 @@ const SelectTree = React.forwardRef((_ref2, ref) => {
1061
1160
  flex: 1,
1062
1161
  className: 'select-tree-item-content'
1063
1162
  }, renderItemContent(contextProps)), single && /*#__PURE__*/React__default["default"].createElement("div", {
1064
- className: style['single-checked']
1163
+ className: style$1['single-checked']
1065
1164
  }, isChecked && /*#__PURE__*/React__default["default"].createElement(icons.CheckOutlined, null)));
1066
1165
  },
1067
1166
  renderTree: contextProps => {
@@ -1089,8 +1188,8 @@ const SelectTree = React.forwardRef((_ref2, ref) => {
1089
1188
  return props.empty || /*#__PURE__*/React__default["default"].createElement(antd.Empty, null);
1090
1189
  }
1091
1190
  return /*#__PURE__*/React__default["default"].createElement(antd.Tree, {
1092
- className: classnames__default["default"](style['default-list'], {
1093
- [style['is-selected-all']]: isSelectedAll
1191
+ className: classnames__default["default"](style$1['default-list'], {
1192
+ [style$1['is-selected-all']]: isSelectedAll
1094
1193
  }),
1095
1194
  showIcon: true,
1096
1195
  selectable: false,
@@ -1134,7 +1233,7 @@ const SelectTree = React.forwardRef((_ref2, ref) => {
1134
1233
  } = props;
1135
1234
  const components = {
1136
1235
  selectedAll: /*#__PURE__*/React__default["default"].createElement("div", {
1137
- className: classnames__default["default"](style['selected-all'], 'select-tree-selected-all', {
1236
+ className: classnames__default["default"](style$1['selected-all'], 'select-tree-selected-all', {
1138
1237
  'is-popup': isPopup
1139
1238
  })
1140
1239
  }, !single && allowSelectedAll && /*#__PURE__*/React__default["default"].createElement(SelectedAll, null)),
@@ -1157,7 +1256,7 @@ const SelectTree = React.forwardRef((_ref2, ref) => {
1157
1256
  } = _ref5;
1158
1257
  const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
1159
1258
  return /*#__PURE__*/React__default["default"].createElement(SimpleBar__default["default"], {
1160
- className: classnames__default["default"](style['list'], 'select-tree-scroll-list', {
1259
+ className: classnames__default["default"](style$1['list'], 'select-tree-scroll-list', {
1161
1260
  'is-popup': isPopup
1162
1261
  })
1163
1262
  }, renderTree(Object.assign({}, fetchProps, targetProps, {
@@ -1167,12 +1266,12 @@ const SelectTree = React.forwardRef((_ref2, ref) => {
1167
1266
  }
1168
1267
  })),
1169
1268
  selectedTag: showSelectedTag && /*#__PURE__*/React__default["default"].createElement("div", {
1170
- className: classnames__default["default"](style['selected-tag'], 'select-tree-selected-tag', {
1269
+ className: classnames__default["default"](style$1['selected-tag'], 'select-tree-selected-tag', {
1171
1270
  'is-popup': isPopup
1172
1271
  })
1173
1272
  }, /*#__PURE__*/React__default["default"].createElement(SelectedTagList, null)),
1174
1273
  footer: footer && /*#__PURE__*/React__default["default"].createElement("div", {
1175
- className: classnames__default["default"](style['footer'], 'select-list-footer')
1274
+ className: classnames__default["default"](style$1['footer'], 'select-list-footer')
1176
1275
  }, typeof footer === 'function' ? footer({
1177
1276
  reload: () => {
1178
1277
  fetchListRef.current && fetchListRef.current.reload();
@@ -1193,10 +1292,795 @@ const SelectTree = React.forwardRef((_ref2, ref) => {
1193
1292
  });
1194
1293
  });
1195
1294
 
1295
+ const createTreeUtils = mapping => {
1296
+ const mappingList = Array.from(mapping.values());
1297
+ const rootNodes = mappingList.filter(item => item.parentId === null);
1298
+ const delItem = (array, item) => {
1299
+ const index = array.indexOf(item);
1300
+ if (index > -1) {
1301
+ array.splice(index, 1);
1302
+ }
1303
+ };
1304
+
1305
+ /**
1306
+ * 通过一个nodeId获取所有父级和所有子级的第一个元素,组成一个从最顶级到最子级的数组
1307
+ * */
1308
+ const getSelectedQueue = id => {
1309
+ const currentNode = mapping.get(id);
1310
+ if (!currentNode) {
1311
+ return [];
1312
+ }
1313
+ const getFirstChild = target => {
1314
+ if (target.children && target.children.length > 0) {
1315
+ return getFirstChild(target.children.find(item => item.children && target.children.length > 0) || get__default["default"](target.children, '0'));
1316
+ }
1317
+ const hasChildrenItem = getAllChildren(target.parentId).find(item => item.children && item.children.length > 0);
1318
+ if (hasChildrenItem) {
1319
+ return getFirstChild(hasChildrenItem);
1320
+ }
1321
+ return target;
1322
+ };
1323
+ const getParentNodeIdList = (targetId, parents = []) => {
1324
+ const output = [targetId, ...parents];
1325
+ const node = mapping.get(targetId);
1326
+ if (!node || isNil__default["default"](node.parentId)) {
1327
+ return output;
1328
+ }
1329
+ return getParentNodeIdList(node.parentId, output);
1330
+ };
1331
+ const lastLevelNode = getFirstChild(currentNode);
1332
+ return getParentNodeIdList(get__default["default"](lastLevelNode, 'id'));
1333
+ };
1334
+
1335
+ /**
1336
+ * 通过一个nodeId获得该节点的所有子级后代的id数组
1337
+ * */
1338
+ const getAllChildren = id => {
1339
+ const output = [];
1340
+ const core = id => {
1341
+ const node = mapping.get(id);
1342
+ if (!node) {
1343
+ return;
1344
+ }
1345
+ if (Array.isArray(node.children) && node.children.length > 0) {
1346
+ output.push(...node.children);
1347
+ node.children.forEach(item => {
1348
+ core(item.id);
1349
+ });
1350
+ }
1351
+ };
1352
+ core(id);
1353
+ return output;
1354
+ };
1355
+
1356
+ /**
1357
+ * 从自身节点开始向父级查找callback返回为true的node,找到第一个返回结果
1358
+ * */
1359
+ const findInParents = (id, callback) => {
1360
+ const core = id => {
1361
+ const currentNode = mapping.get(id);
1362
+ if (!currentNode) {
1363
+ return null;
1364
+ }
1365
+ if (callback(currentNode)) {
1366
+ return currentNode;
1367
+ }
1368
+ if (!isNil__default["default"](currentNode.parentId)) {
1369
+ return core(currentNode.parentId);
1370
+ }
1371
+ return null;
1372
+ };
1373
+ return core(id);
1374
+ };
1375
+ const getSiblingNode = id => {
1376
+ const currentNode = mapping.get(id);
1377
+ if (!currentNode) {
1378
+ return [];
1379
+ }
1380
+ const parentId = currentNode.parentId;
1381
+ if (isNil__default["default"](parentId)) {
1382
+ return rootNodes;
1383
+ }
1384
+ const parentNode = mapping.get(parentId);
1385
+ return parentNode.children;
1386
+ };
1387
+ const setNodeChecked = (id, value = []) => {
1388
+ const newValue = value.slice(0);
1389
+ const core = id => {
1390
+ const node = mapping.get(id);
1391
+ if (!node) {
1392
+ return;
1393
+ }
1394
+ newValue.push(id);
1395
+ getAllChildren(id).forEach(node => {
1396
+ delItem(newValue, node.id);
1397
+ });
1398
+ const siblingNode = getSiblingNode(id);
1399
+ const siblingNodeIsAllChecked = siblingNode.every(node => newValue.indexOf(node.id) > -1);
1400
+ if (node.parentId && siblingNodeIsAllChecked) {
1401
+ siblingNode.forEach(node => {
1402
+ delItem(newValue, node.id);
1403
+ });
1404
+ core(node.parentId);
1405
+ }
1406
+ };
1407
+ core(id);
1408
+ return newValue;
1409
+ };
1410
+ const setNodeUnchecked = (id, value = []) => {
1411
+ const newValue = value.slice(0);
1412
+ const core = id => {
1413
+ const node = mapping.get(id);
1414
+ if (!node) {
1415
+ return;
1416
+ }
1417
+ if (newValue.indexOf(node.id) > -1) {
1418
+ delItem(newValue, node.id);
1419
+ return;
1420
+ }
1421
+ const siblingNode = getSiblingNode(id);
1422
+ if (node.parentId) {
1423
+ siblingNode.forEach(node => {
1424
+ if (id !== node.id) {
1425
+ newValue.push(node.id);
1426
+ }
1427
+ });
1428
+ core(node.parentId);
1429
+ }
1430
+ };
1431
+ core(id);
1432
+ return newValue;
1433
+ };
1434
+ const computedCheckboxStatus = (id, value = []) => {
1435
+ if (!!findInParents(id, node => {
1436
+ return value.indexOf(node.id) > -1;
1437
+ })) {
1438
+ return {
1439
+ checked: true,
1440
+ indeterminate: false
1441
+ };
1442
+ }
1443
+ const indeterminate = ((id, callback) => {
1444
+ const core = id => {
1445
+ const currentNode = mapping.get(id);
1446
+ if (!currentNode) {
1447
+ return null;
1448
+ }
1449
+ if (callback(currentNode)) {
1450
+ return currentNode;
1451
+ }
1452
+ if (Array.isArray(currentNode.children) && currentNode.children.length > 0) {
1453
+ return currentNode.children.find(item => !!core(item.id));
1454
+ }
1455
+ };
1456
+ return !!core(id);
1457
+ })(id, node => value.indexOf(node.id) > -1);
1458
+ if (indeterminate) {
1459
+ return {
1460
+ checked: false,
1461
+ indeterminate: true
1462
+ };
1463
+ }
1464
+ return {
1465
+ checked: false,
1466
+ indeterminate: false
1467
+ };
1468
+ };
1469
+ const transformToTreeData = () => {
1470
+ const core = nodeList => {
1471
+ if (Array.isArray(nodeList) && nodeList.length > 0) {
1472
+ return nodeList.map(node => {
1473
+ const children = mappingList.filter(item => item.parentId === node.id);
1474
+ return Object.assign({}, node, {
1475
+ children: core(children)
1476
+ });
1477
+ });
1478
+ }
1479
+ return null;
1480
+ };
1481
+ return core(rootNodes);
1482
+ };
1483
+ const treeData = transformToTreeData();
1484
+ return {
1485
+ mapping,
1486
+ getSelectedQueue,
1487
+ getAllChildren,
1488
+ computedCheckboxStatus,
1489
+ getSiblingNode,
1490
+ findInParents,
1491
+ setNodeChecked,
1492
+ setNodeUnchecked,
1493
+ treeData,
1494
+ treeMapping: new Map((treeData || []).map(item => [item.id, item]))
1495
+ };
1496
+ };
1497
+
1498
+ var style = {"content":"_fHNBt","columns":"_VgpIp","content-item":"_kSkN1","last-level-area":"_1QV-l","is-popup":"_zFwDF","menu":"_s-ON4","scroll-plus-box":"_rIix2","menu-label":"_XAs20","menu-label-text":"_Y8AoQ","menu-item":"_ZwakZ","checkbox-hidden":"_0FUoe","single-mode":"_dahnB","menu-item-icon":"_AZZvN","menu-item-placeholder":"_TudTj","loading":"_ljvZk","search-input":"_FVxuS","list":"_iUhv7","is-selected":"_tx4-l","custom-menu":"_OerpL","selected":"_OUkpN"};
1499
+
1500
+ const CustomMenu = ({
1501
+ className,
1502
+ selectedKeys,
1503
+ items,
1504
+ onSelect
1505
+ }) => {
1506
+ const handleItemClick = (key, e) => {
1507
+ // 只阻止事件冒泡,不阻止默认行为
1508
+ e.stopPropagation();
1509
+ onSelect?.({
1510
+ key,
1511
+ domEvent: e
1512
+ });
1513
+ };
1514
+ return /*#__PURE__*/React__default["default"].createElement(antd.List, {
1515
+ className: classnames__default["default"](style['custom-menu'], className),
1516
+ dataSource: items,
1517
+ renderItem: item => {
1518
+ const isSelected = selectedKeys?.includes(item.key);
1519
+ return /*#__PURE__*/React__default["default"].createElement(antd.List.Item, {
1520
+ className: classnames__default["default"](style['custom-menu-item'], {
1521
+ [style['selected']]: isSelected
1522
+ }),
1523
+ onClick: e => handleItemClick(item.key, e)
1524
+ }, item.label);
1525
+ }
1526
+ });
1527
+ };
1528
+
1529
+ const numberToPx = val => {
1530
+ return typeof val === 'number' ? `${val}px` : val;
1531
+ };
1532
+
1533
+ // 级联选择内容组件
1534
+ const CascaderInner = _ref => {
1535
+ let {
1536
+ options,
1537
+ value,
1538
+ setValue,
1539
+ maxLength,
1540
+ single,
1541
+ onlyAllowLastLevel,
1542
+ openLoadData,
1543
+ onLoadMore,
1544
+ parentIdKey,
1545
+ menuItemWidth,
1546
+ isPopup,
1547
+ searchPlaceholder,
1548
+ onSearch,
1549
+ valueKey,
1550
+ labelKey,
1551
+ onOpenChange,
1552
+ open
1553
+ } = _ref;
1554
+ const {
1555
+ message
1556
+ } = antd.App.useApp();
1557
+ const [searchText, setSearchText] = React.useState('');
1558
+ const [loading, setLoading] = React.useState(false);
1559
+
1560
+ // 构建 mapping
1561
+ const mapping = React.useMemo(() => {
1562
+ const map = new Map();
1563
+ const processData = function (items, parentId) {
1564
+ if (parentId === void 0) {
1565
+ parentId = null;
1566
+ }
1567
+ items.forEach(item => {
1568
+ const node = {
1569
+ ...item,
1570
+ id: item[valueKey],
1571
+ label: item[labelKey],
1572
+ parentId
1573
+ };
1574
+ if (item.children && item.children.length > 0) {
1575
+ node.children = item.children.map(child => ({
1576
+ ...child,
1577
+ id: child[valueKey],
1578
+ label: child[labelKey],
1579
+ parentId: node.id
1580
+ }));
1581
+ processData(item.children, node.id);
1582
+ }
1583
+ map.set(node.id, node);
1584
+ });
1585
+ };
1586
+ processData(options);
1587
+ return map;
1588
+ }, [options, valueKey, labelKey]);
1589
+
1590
+ // 创建树工具
1591
+ const treeUtils = React.useMemo(() => {
1592
+ return createTreeUtils(mapping);
1593
+ }, [mapping]);
1594
+
1595
+ // 当前选中的列
1596
+ const [selectedIds, setSelectedIds] = React.useState(() => {
1597
+ const initValue = value.find(item => {
1598
+ const id = typeof item === 'object' ? item[valueKey] : item;
1599
+ return !!mapping.get(id);
1600
+ });
1601
+ if (initValue) {
1602
+ const id = typeof initValue === 'object' ? initValue[valueKey] : initValue;
1603
+ return treeUtils.getSelectedQueue(id);
1604
+ }
1605
+
1606
+ // 默认选中第一列
1607
+ const firstNode = Array.from(mapping.values()).find(item => isNil__default["default"](item.parentId));
1608
+ if (firstNode) {
1609
+ return treeUtils.getSelectedQueue(firstNode.id);
1610
+ }
1611
+ return [];
1612
+ });
1613
+
1614
+ // 当 Modal 打开时,根据 value 重新初始化 selectedIds
1615
+ const prevOpenRef = React.useRef(open);
1616
+ React.useEffect(() => {
1617
+ // 只在非 popup 模式下且 Modal 从关闭变为打开时处理
1618
+ if (!isPopup && open && !prevOpenRef.current) {
1619
+ const initValue = value.find(item => {
1620
+ const id = typeof item === 'object' ? item[valueKey] : item;
1621
+ return !!mapping.get(id);
1622
+ });
1623
+ if (initValue) {
1624
+ const id = typeof initValue === 'object' ? initValue[valueKey] : initValue;
1625
+ setSelectedIds(treeUtils.getSelectedQueue(id));
1626
+ } else {
1627
+ // 默认选中第一列
1628
+ const firstNode = Array.from(mapping.values()).find(item => isNil__default["default"](item.parentId));
1629
+ if (firstNode) {
1630
+ setSelectedIds(treeUtils.getSelectedQueue(firstNode.id));
1631
+ }
1632
+ }
1633
+ }
1634
+ prevOpenRef.current = open;
1635
+ }, [open, value, mapping, treeUtils, valueKey, isPopup]);
1636
+
1637
+ // 懒加载支持
1638
+ const loadMorePropsRef = React.useRef({});
1639
+ loadMorePropsRef.current = {
1640
+ openLoadData,
1641
+ onLoadMore,
1642
+ parentIdKey,
1643
+ treeUtils
1644
+ };
1645
+ React.useEffect(() => {
1646
+ if (!openLoadData || !onLoadMore) {
1647
+ return;
1648
+ }
1649
+ const lastNode = mapping.get(last__default["default"](selectedIds));
1650
+ if (!lastNode) {
1651
+ return;
1652
+ }
1653
+
1654
+ // 检查是否需要加载子节点
1655
+ if (lastNode.hasOwnProperty('children') && lastNode.children !== undefined) {
1656
+ return;
1657
+ }
1658
+ setLoading(true);
1659
+ onLoadMore({
1660
+ [parentIdKey]: lastNode.id
1661
+ }).then(() => {
1662
+ setLoading(false);
1663
+ }).catch(() => {
1664
+ setLoading(false);
1665
+ });
1666
+ }, [selectedIds, mapping, openLoadData, onLoadMore, parentIdKey]);
1667
+
1668
+ // 检查是否为非叶子节点
1669
+ const isNotLastNode = React.useCallback(id => {
1670
+ const node = mapping.get(id);
1671
+ if (!node) return false;
1672
+ if (openLoadData && !node.hasOwnProperty('children')) {
1673
+ return true;
1674
+ }
1675
+ return node.children && node.children.length > 0;
1676
+ }, [mapping, openLoadData]);
1677
+
1678
+ // 选择处理
1679
+ const onCheckedChange = React.useCallback((checked, id) => {
1680
+ const newValue = (() => {
1681
+ if (onlyAllowLastLevel && checked) {
1682
+ const currentIds = value.map(item => typeof item === 'object' ? item[valueKey] : item);
1683
+ if (currentIds.includes(id)) return currentIds;
1684
+ return [...currentIds, id];
1685
+ }
1686
+ if (onlyAllowLastLevel) {
1687
+ const currentIds = value.map(item => typeof item === 'object' ? item[valueKey] : item);
1688
+ return currentIds.filter(itemId => itemId !== id);
1689
+ }
1690
+ const currentIds = value.map(item => typeof item === 'object' ? item[valueKey] : item);
1691
+ return checked ? treeUtils.setNodeChecked(id, currentIds) : treeUtils.setNodeUnchecked(id, currentIds);
1692
+ })();
1693
+ if (newValue.length > maxLength) {
1694
+ message.error(`最多只能选择 ${maxLength} 项`);
1695
+ return;
1696
+ }
1697
+
1698
+ // 转换回完整对象
1699
+ const newValues = newValue.map(id => {
1700
+ const node = mapping.get(id);
1701
+ // 返回完整的节点数据,保留所有原始字段
1702
+ return node ? {
1703
+ ...node,
1704
+ [valueKey]: node.id,
1705
+ [labelKey]: node.label
1706
+ } : null;
1707
+ }).filter(Boolean);
1708
+ const finalValue = single && newValues.length > 0 ? [last__default["default"](newValues)] : newValues;
1709
+ setValue(finalValue);
1710
+
1711
+ // 单选且是叶子节点且在 popup 模式下,自动关闭下拉框
1712
+ if (single && newValues.length > 0 && !isNotLastNode(id) && isPopup && onOpenChange) {
1713
+ onOpenChange(false);
1714
+ }
1715
+ }, [value, maxLength, single, onlyAllowLastLevel, treeUtils, mapping, message, valueKey, labelKey, isPopup, onOpenChange, isNotLastNode]);
1716
+
1717
+ // 搜索结果
1718
+ const searchResults = React.useMemo(() => {
1719
+ if (!searchText || !onSearch) return null;
1720
+ const keyword = searchText.toLowerCase();
1721
+ return Array.from(mapping.values()).filter(item => {
1722
+ return item.label && item.label.toLowerCase().includes(keyword);
1723
+ });
1724
+ }, [searchText, mapping, onSearch]);
1725
+
1726
+ // 搜索选择
1727
+ const onSearchSelect = item => {
1728
+ const currentIds = value.map(v => typeof v === 'object' ? v[valueKey] : v);
1729
+ const checked = currentIds.includes(item.id);
1730
+ onCheckedChange(!checked, item.id);
1731
+ if (!checked) {
1732
+ setSelectedIds(treeUtils.getSelectedQueue(item.id));
1733
+ }
1734
+ setSearchText('');
1735
+ };
1736
+
1737
+ // 渲染搜索内容
1738
+ if (searchText && searchResults) {
1739
+ const currentIds = value.map(v => typeof v === 'object' ? v[valueKey] : v);
1740
+ return /*#__PURE__*/React__default["default"].createElement("div", {
1741
+ className: classnames__default["default"](style['content'], {
1742
+ [style['is-popup']]: isPopup
1743
+ })
1744
+ }, /*#__PURE__*/React__default["default"].createElement(SearchInput__default["default"], {
1745
+ className: classnames__default["default"](style['search-input'], {
1746
+ 'is-popup': isPopup
1747
+ }),
1748
+ placeholder: searchPlaceholder,
1749
+ value: searchText,
1750
+ onSearch: setSearchText,
1751
+ simple: isPopup,
1752
+ showSearchButton: !isPopup
1753
+ }), /*#__PURE__*/React__default["default"].createElement(SimpleBar__default["default"], {
1754
+ className: style['scroll-plus-box']
1755
+ }, searchResults.length === 0 ? /*#__PURE__*/React__default["default"].createElement(antd.Empty, {
1756
+ description: "\u6682\u65E0\u6570\u636E"
1757
+ }) : /*#__PURE__*/React__default["default"].createElement(antd.List, {
1758
+ className: style['list'],
1759
+ size: "small",
1760
+ dataSource: searchResults,
1761
+ rowKey: "id",
1762
+ renderItem: item => {
1763
+ const checked = currentIds.includes(item.id);
1764
+ return /*#__PURE__*/React__default["default"].createElement(antd.List.Item, {
1765
+ className: classnames__default["default"]({
1766
+ [style['is-selected']]: checked
1767
+ }),
1768
+ onClick: () => onSearchSelect(item)
1769
+ }, /*#__PURE__*/React__default["default"].createElement("span", null, item.label), checked && /*#__PURE__*/React__default["default"].createElement("span", {
1770
+ style: {
1771
+ marginLeft: 8,
1772
+ color: '#1677ff'
1773
+ }
1774
+ }, "\u2713"));
1775
+ }
1776
+ })));
1777
+ }
1778
+
1779
+ // 渲染级联列
1780
+ const currentIds = value.map(v => typeof v === 'object' ? v[valueKey] : v);
1781
+ return /*#__PURE__*/React__default["default"].createElement("div", {
1782
+ className: classnames__default["default"](style['content'], {
1783
+ [style['is-popup']]: isPopup,
1784
+ [style['has-search']]: !!onSearch
1785
+ }),
1786
+ style: {
1787
+ '--menu-item-width': numberToPx(menuItemWidth)
1788
+ }
1789
+ }, onSearch && /*#__PURE__*/React__default["default"].createElement(SearchInput__default["default"], {
1790
+ className: classnames__default["default"](style['search-input'], {
1791
+ 'is-popup': isPopup
1792
+ }),
1793
+ placeholder: searchPlaceholder,
1794
+ value: searchText,
1795
+ onSearch: setSearchText,
1796
+ simple: isPopup,
1797
+ showSearchButton: !isPopup
1798
+ }), /*#__PURE__*/React__default["default"].createElement(SimpleBar__default["default"], {
1799
+ className: style['scroller'],
1800
+ options: {
1801
+ autoHide: false
1802
+ }
1803
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
1804
+ className: style['columns']
1805
+ }, selectedIds.map((selectedId, index) => {
1806
+ const selectNode = mapping.get(selectedId);
1807
+ const siblingNodes = treeUtils.getSiblingNode(selectedId);
1808
+ const isLastLevel = !isNotLastNode(selectNode?.id) && index > 0;
1809
+ return /*#__PURE__*/React__default["default"].createElement(SimpleBar__default["default"], {
1810
+ key: selectedId || index,
1811
+ className: classnames__default["default"](style['content-item'], {
1812
+ [style['last-level-area']]: isLastLevel
1813
+ })
1814
+ }, isLastLevel ? /*#__PURE__*/React__default["default"].createElement(antd.Space, {
1815
+ wrap: true,
1816
+ style: {
1817
+ padding: 12
1818
+ },
1819
+ className: classnames__default["default"]({
1820
+ [style['single-mode']]: single
1821
+ })
1822
+ }, siblingNodes.map(node => {
1823
+ const {
1824
+ checked,
1825
+ indeterminate
1826
+ } = treeUtils.computedCheckboxStatus(node.id, currentIds);
1827
+ return /*#__PURE__*/React__default["default"].createElement(antd.Checkbox, {
1828
+ key: node.id,
1829
+ checked: checked,
1830
+ indeterminate: indeterminate,
1831
+ onChange: e => onCheckedChange(e.target.checked, node.id)
1832
+ }, node.label);
1833
+ })) : /*#__PURE__*/React__default["default"].createElement(CustomMenu, {
1834
+ className: style['menu'],
1835
+ selectedKeys: index === selectedIds.length - 1 ? [] : selectedIds,
1836
+ onSelect: _ref2 => {
1837
+ let {
1838
+ key
1839
+ } = _ref2;
1840
+ const node = mapping.get(key);
1841
+ if (!node) return;
1842
+ if (isNotLastNode(node.id)) {
1843
+ setSelectedIds(treeUtils.getSelectedQueue(node.id));
1844
+ } else {
1845
+ const {
1846
+ checked
1847
+ } = treeUtils.computedCheckboxStatus(node.id, currentIds);
1848
+ onCheckedChange(!checked, node.id);
1849
+ }
1850
+ },
1851
+ items: siblingNodes.map(node => {
1852
+ const {
1853
+ checked,
1854
+ indeterminate
1855
+ } = treeUtils.computedCheckboxStatus(node.id, currentIds);
1856
+ const hasChildren = isNotLastNode(node.id);
1857
+
1858
+ // 计算子级选中数量
1859
+ const childrenSelectedCount = hasChildren ? treeUtils.getAllChildren(node.id).filter(child => currentIds.includes(child.id)).length : 0;
1860
+ return {
1861
+ key: node.id,
1862
+ label: /*#__PURE__*/React__default["default"].createElement(antd.Space, {
1863
+ className: classnames__default["default"](style['menu-item'], {
1864
+ [style['checkbox-hidden']]: onlyAllowLastLevel && hasChildren,
1865
+ [style['single-mode']]: single
1866
+ })
1867
+ }, (!onlyAllowLastLevel || !hasChildren) && /*#__PURE__*/React__default["default"].createElement(antd.Checkbox, {
1868
+ checked: checked,
1869
+ indeterminate: indeterminate,
1870
+ onClick: e => e.stopPropagation(),
1871
+ onChange: e => {
1872
+ e.stopPropagation();
1873
+ onCheckedChange(e.target.checked, node.id);
1874
+ }
1875
+ }), /*#__PURE__*/React__default["default"].createElement("div", {
1876
+ className: style['menu-label']
1877
+ }, /*#__PURE__*/React__default["default"].createElement("span", {
1878
+ className: style['menu-label-text']
1879
+ }, node.label), hasChildren && childrenSelectedCount > 0 && /*#__PURE__*/React__default["default"].createElement(antd.Badge, {
1880
+ count: childrenSelectedCount,
1881
+ size: "small"
1882
+ })), hasChildren ? /*#__PURE__*/React__default["default"].createElement(icons.RightOutlined, {
1883
+ className: style['menu-item-icon']
1884
+ }) : /*#__PURE__*/React__default["default"].createElement("span", {
1885
+ className: style['menu-item-placeholder']
1886
+ }))
1887
+ };
1888
+ })
1889
+ }));
1890
+ }), loading && /*#__PURE__*/React__default["default"].createElement("div", {
1891
+ className: style['loading']
1892
+ }, /*#__PURE__*/React__default["default"].createElement(antd.Spin, {
1893
+ size: "small"
1894
+ })))));
1895
+ };
1896
+
1897
+ // 主组件
1898
+ const SelectCascader = _ref3 => {
1899
+ let {
1900
+ options = [],
1901
+ value,
1902
+ onChange,
1903
+ defaultValue,
1904
+ maxLength = Number.MAX_VALUE,
1905
+ single = false,
1906
+ onlyAllowLastLevel = false,
1907
+ openLoadData = false,
1908
+ onLoadMore,
1909
+ parentIdKey = 'id',
1910
+ menuItemWidth = 180,
1911
+ isPopup = true,
1912
+ searchPlaceholder,
1913
+ onSearch,
1914
+ valueKey = 'id',
1915
+ labelKey = 'label',
1916
+ placeholder = '请选择',
1917
+ disabled = false,
1918
+ size = 'default',
1919
+ overlayWidth,
1920
+ ...props
1921
+ } = _ref3;
1922
+ // 内部始终使用数组格式处理
1923
+ // SelectInput 会处理 single 模式的 value 和 onChange 转换
1924
+ const [innerValue, setInnerValue] = React.useState(Array.isArray(defaultValue) ? defaultValue : defaultValue ? [defaultValue] : []);
1925
+
1926
+ // currentValue 用于内部处理,始终是数组
1927
+ const currentValue = React.useMemo(() => {
1928
+ if (value !== undefined) {
1929
+ // 外部传入的 value 可能是对象(single)或数组(多选)
1930
+ return Array.isArray(value) ? value : value ? [value] : [];
1931
+ }
1932
+ return innerValue;
1933
+ }, [value, innerValue]);
1934
+ const setValue = React.useCallback(newValue => {
1935
+ // SelectInput 在 single 模式下会传单个对象或 null/undefined,需要转换为数组
1936
+ const normalizedValue = (() => {
1937
+ if (single) {
1938
+ // 单选模式:可能是单个对象、null、undefined 或数组
1939
+ if (Array.isArray(newValue)) {
1940
+ return newValue;
1941
+ }
1942
+ return isEmpty.isNotEmpty(newValue) ? [newValue] : [];
1943
+ }
1944
+ // 多选模式:确保是数组
1945
+ return Array.isArray(newValue) ? newValue : [];
1946
+ })();
1947
+ if (value === undefined) {
1948
+ setInnerValue(normalizedValue);
1949
+ }
1950
+
1951
+ // 根据单选/多选模式转换输出格式
1952
+ if (single) {
1953
+ // 单选:返回单个对象或 null
1954
+ onChange?.(normalizedValue.length > 0 ? normalizedValue[0] : null);
1955
+ } else {
1956
+ // 多选:返回数组
1957
+ onChange?.(normalizedValue);
1958
+ }
1959
+ }, [value, onChange, single]);
1960
+
1961
+ // 传递给 SelectInput 的值:根据 single 参数决定格式
1962
+ const selectInputValue = React.useMemo(() => {
1963
+ if (single) {
1964
+ // single 模式:传单个对象或 undefined
1965
+ return currentValue.length > 0 ? currentValue[0] : undefined;
1966
+ }
1967
+ // 多选模式:传数组
1968
+ return currentValue;
1969
+ }, [currentValue, single]);
1970
+
1971
+ // 计算 label 显示
1972
+ React.useMemo(() => {
1973
+ // currentValue 已经是数组格式了
1974
+ return currentValue.map(item => {
1975
+ // 如果已经是对象,确保有标准化的字段
1976
+ if (typeof item === 'object') {
1977
+ // 优先使用 item[labelKey],然后是 item.label,最后是 item.name
1978
+ const label = item[labelKey] || item.label || item.name || String(item[valueKey] || '');
1979
+ return {
1980
+ ...item,
1981
+ [valueKey]: item[valueKey] || item.id,
1982
+ [labelKey]: label
1983
+ };
1984
+ }
1985
+ // 如果是值,从 options 中查找
1986
+ const findLabel = items => {
1987
+ for (const node of items) {
1988
+ if (node[valueKey] === item) {
1989
+ return {
1990
+ [valueKey]: item,
1991
+ [labelKey]: node[labelKey] || node.name || String(item)
1992
+ };
1993
+ }
1994
+ if (node.children) {
1995
+ const found = findLabel(node.children);
1996
+ if (found) return found;
1997
+ }
1998
+ }
1999
+ return null;
2000
+ };
2001
+ return findLabel(options) || {
2002
+ [valueKey]: item,
2003
+ [labelKey]: String(item)
2004
+ };
2005
+ }).filter(Boolean);
2006
+ }, [currentValue, options, valueKey, labelKey]);
2007
+ return /*#__PURE__*/React__default["default"].createElement(SelectInput, _extends({}, props, {
2008
+ value: selectInputValue,
2009
+ onChange: setValue,
2010
+ single: single,
2011
+ maxLength: maxLength,
2012
+ isPopup: isPopup,
2013
+ placeholder: placeholder,
2014
+ disabled: disabled,
2015
+ size: size,
2016
+ valueKey: valueKey,
2017
+ labelKey: labelKey,
2018
+ overlayWidth: overlayWidth || menuItemWidth * 2
2019
+ }), contextProps => {
2020
+ // 使用 contextProps 中的 value 和 setValue,支持 Modal 模式下的内部状态管理
2021
+ const contextValue = contextProps.value;
2022
+ const contextSetValue = contextProps.setValue;
2023
+
2024
+ // 计算当前显示的 value
2025
+ const currentDisplayValue = contextValue.map(item => {
2026
+ // 如果已经是对象,确保有标准化的字段
2027
+ if (typeof item === 'object') {
2028
+ const label = item[labelKey] || item.label || item.name || String(item[valueKey] || '');
2029
+ return {
2030
+ ...item,
2031
+ [valueKey]: item[valueKey] || item.id,
2032
+ [labelKey]: label
2033
+ };
2034
+ }
2035
+ // 如果是值,从 options 中查找
2036
+ const findLabel = items => {
2037
+ for (const node of items) {
2038
+ if (node[valueKey] === item) {
2039
+ return {
2040
+ [valueKey]: item,
2041
+ [labelKey]: node[labelKey] || node.name || String(item)
2042
+ };
2043
+ }
2044
+ if (node.children) {
2045
+ const found = findLabel(node.children);
2046
+ if (found) return found;
2047
+ }
2048
+ }
2049
+ return null;
2050
+ };
2051
+ return findLabel(options) || {
2052
+ [valueKey]: item,
2053
+ [labelKey]: String(item)
2054
+ };
2055
+ }).filter(Boolean);
2056
+ return /*#__PURE__*/React__default["default"].createElement(CascaderInner, {
2057
+ options: options,
2058
+ value: currentDisplayValue,
2059
+ setValue: contextSetValue,
2060
+ maxLength: maxLength,
2061
+ single: single,
2062
+ onlyAllowLastLevel: onlyAllowLastLevel,
2063
+ openLoadData: openLoadData,
2064
+ onLoadMore: onLoadMore,
2065
+ parentIdKey: parentIdKey,
2066
+ menuItemWidth: menuItemWidth,
2067
+ isPopup: isPopup,
2068
+ searchPlaceholder: searchPlaceholder,
2069
+ onSearch: onSearch,
2070
+ valueKey: valueKey,
2071
+ labelKey: labelKey,
2072
+ onOpenChange: contextProps.onOpenChange,
2073
+ open: contextProps.open
2074
+ });
2075
+ });
2076
+ };
2077
+
2078
+ exports.SelectCascader = SelectCascader;
1196
2079
  exports.SelectInput = SelectInput;
1197
2080
  exports.SelectTableList = SelectTableList;
1198
2081
  exports.SelectTree = SelectTree;
1199
2082
  exports.SelectedAll = SelectedAll;
1200
2083
  exports.SelectedTagList = SelectedTagList;
2084
+ exports.createTreeUtils = createTreeUtils;
1201
2085
  exports["default"] = SelectList;
1202
2086
  //# sourceMappingURL=index.js.map