@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.
@@ -1,12 +1,12 @@
1
- import React, { forwardRef, useState, useImperativeHandle, useEffect, useRef } from 'react';
1
+ import React, { useState, useRef, useLayoutEffect, forwardRef, useMemo, useImperativeHandle, useEffect, useCallback } from 'react';
2
2
  import { createContext } from '@kne/global-context';
3
3
  import useResize from '@kne/use-resize';
4
4
  import useControlValue from '@kne/use-control-value';
5
5
  import classnames from 'classnames';
6
6
  import isEqual from 'lodash/isEqual';
7
7
  import last from 'lodash/last';
8
- import { Modal, App, Dropdown, Flex, Tag, Checkbox, List, Empty, Row, Col, Button, Popover, Tree } from 'antd';
9
- import { CloseCircleFilled, DownOutlined, CheckOutlined } from '@ant-design/icons';
8
+ import { Tag, Modal, App, Dropdown, Flex, Checkbox, List, Empty, Row, Col, Button, Popover, Tree, Space, Badge, Spin } from 'antd';
9
+ import { CloseCircleFilled, DownOutlined, CheckOutlined, RightOutlined } from '@ant-design/icons';
10
10
  import { isNotEmpty } from '@kne/is-empty';
11
11
  import { createWithIntlProvider, useIntl } from '@kne/react-intl';
12
12
  import get from 'lodash/get';
@@ -46,7 +46,7 @@ const {
46
46
  useContext
47
47
  } = context;
48
48
 
49
- 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"};
49
+ 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"};
50
50
 
51
51
  const locale$1 = {
52
52
  placeholder: '请选择',
@@ -70,8 +70,98 @@ const locale = {
70
70
  removeAll: 'Remove All'
71
71
  };
72
72
 
73
- const _excluded$2 = ["children"];
74
- const numberToPx = val => {
73
+ /**
74
+ * 标签溢出内部渲染组件
75
+ * 根据 innerWidth 计算标签显示数量
76
+ */
77
+ const TagOverflowInner = ({
78
+ value,
79
+ innerWidth,
80
+ labelKey,
81
+ valueKey,
82
+ onRemove,
83
+ overflowTagWidth: _overflowTagWidth = 45,
84
+ iconSpace: _iconSpace = 20
85
+ }) => {
86
+ const [visibleCount, setVisibleCount] = useState(value.length);
87
+ const measureRef = useRef(null);
88
+
89
+ // 测量每个标签的实际宽度并计算可见数量
90
+ useLayoutEffect(() => {
91
+ // innerWidth 为 0 时,保持当前状态,等待正确的宽度
92
+ if (!measureRef.current || innerWidth === 0 || value.length === 0) {
93
+ setVisibleCount(value.length);
94
+ return;
95
+ }
96
+ const tagElements = measureRef.current.querySelectorAll('[data-tag-measure]');
97
+ if (tagElements.length === 0) return;
98
+
99
+ // 获取每个标签的实际占用宽度(包含 margin)
100
+ const tagWidths = Array.from(tagElements).map(el => {
101
+ const style = window.getComputedStyle(el);
102
+ const marginLeft = parseFloat(style.marginLeft) || 0;
103
+ const marginRight = parseFloat(style.marginRight) || 0;
104
+ return el.offsetWidth + marginLeft + marginRight;
105
+ });
106
+ const availableWidth = innerWidth - _iconSpace;
107
+ let totalWidth = 0;
108
+ let count = 0;
109
+ for (let i = 0; i < tagWidths.length; i++) {
110
+ // 如果不是最后一个,需要预留 +N 标签空间
111
+ const needOverflowSpace = i < tagWidths.length - 1;
112
+ const requiredWidth = tagWidths[i] + (needOverflowSpace ? _overflowTagWidth : 0);
113
+ if (totalWidth + requiredWidth <= availableWidth) {
114
+ totalWidth += tagWidths[i];
115
+ count++;
116
+ } else {
117
+ break;
118
+ }
119
+ }
120
+
121
+ // 确保至少显示一个标签
122
+ setVisibleCount(Math.max(1, count));
123
+ }, [value, innerWidth, _overflowTagWidth, _iconSpace]);
124
+
125
+ // 计算单个标签最大宽度:min(150px, innerWidth - 60),初始状态默认 150px
126
+ const maxTagWidth = innerWidth > 0 ? Math.min(150, Math.max(60, innerWidth - 60)) : 150;
127
+ const displayTags = value.slice(0, visibleCount);
128
+ const hiddenCount = value.length - visibleCount;
129
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
130
+ ref: measureRef,
131
+ className: style$6['measure-layer']
132
+ }, value.map(item => /*#__PURE__*/React.createElement(Tag, {
133
+ key: item[valueKey],
134
+ "data-tag-measure": true,
135
+ closable: true,
136
+ bordered: false,
137
+ className: style$6['tag-item'],
138
+ style: {
139
+ '--max-tag-width': `${maxTagWidth}px`
140
+ }
141
+ }, /*#__PURE__*/React.createElement("span", {
142
+ className: style$6['tag-label']
143
+ }, item[labelKey])))), displayTags.map(item => /*#__PURE__*/React.createElement(Tag, {
144
+ key: item[valueKey],
145
+ closable: true,
146
+ bordered: false,
147
+ className: style$6['tag-item'],
148
+ style: {
149
+ '--max-tag-width': `${maxTagWidth}px`
150
+ },
151
+ onClose: e => {
152
+ e.preventDefault();
153
+ onRemove(item);
154
+ }
155
+ }, /*#__PURE__*/React.createElement("span", {
156
+ className: style$6['tag-label'],
157
+ title: item[labelKey]
158
+ }, item[labelKey]))), hiddenCount > 0 && /*#__PURE__*/React.createElement(Tag, {
159
+ className: style$6['overflow-tag']
160
+ }, "+", hiddenCount));
161
+ };
162
+
163
+ const _excluded$3 = ["children"];
164
+ const numberToPx$1 = val => {
75
165
  return typeof val === 'number' ? `${val}px` : val;
76
166
  };
77
167
  const pxToNumber = value => {
@@ -86,7 +176,7 @@ const ModalContent = _ref => {
86
176
  let {
87
177
  children
88
178
  } = _ref,
89
- others = _objectWithoutPropertiesLoose(_ref, _excluded$2);
179
+ others = _objectWithoutPropertiesLoose(_ref, _excluded$3);
90
180
  const {
91
181
  open,
92
182
  value: propsValue
@@ -228,11 +318,21 @@ const SelectInput = createWithIntlProvider({
228
318
  onChange: 'onOpenChange'
229
319
  });
230
320
  const [hover, setHover] = useState(false);
231
- const [inputWidth, setInputWidth] = useState(0);
232
- const inputRef = useResize(el => {
233
- setInputWidth(el.clientWidth);
234
- });
235
- const popupOverlayWidth = numberToPx(Math.max(inputWidth, pxToNumber(overlayWidth)));
321
+ const [innerWidth, setInnerWidth] = useState(0);
322
+ const [containerWidth, setContainerWidth] = useState(0);
323
+ const containerWidthChange = el => {
324
+ if (!el) {
325
+ return;
326
+ }
327
+ const containerWidth = el.clientWidth;
328
+ setContainerWidth(containerWidth);
329
+ const innerEl = el.querySelector('.select-input-inner');
330
+ setInnerWidth(innerEl.clientWidth);
331
+ };
332
+ const popupOverlayWidth = useMemo(() => {
333
+ return numberToPx$1(Math.max(containerWidth, pxToNumber(overlayWidth)));
334
+ }, [containerWidth, overlayWidth]);
335
+ const containerRef = useResize(containerWidthChange);
236
336
  const {
237
337
  message
238
338
  } = App.useApp();
@@ -292,7 +392,7 @@ const SelectInput = createWithIntlProvider({
292
392
  searchProps,
293
393
  setSearchProps,
294
394
  hover,
295
- inputWidth,
395
+ inputWidth: containerWidth,
296
396
  onAdd,
297
397
  onRemove,
298
398
  onSelect,
@@ -305,12 +405,12 @@ const SelectInput = createWithIntlProvider({
305
405
  return contextProps.props.inputRender(props, contextProps);
306
406
  }
307
407
  return /*#__PURE__*/React.createElement(Flex, _extends({}, props, {
308
- ref: inputRef,
309
- className: classnames(className, style$5['select-input'], 'select-input', {
310
- [style$5['wrap']]: labelWrap,
311
- [style$5['disabled']]: disabled,
312
- [style$5['small']]: size === 'small',
313
- [style$5['large']]: size === 'large'
408
+ ref: containerRef,
409
+ className: classnames(className, style$6['select-input'], 'select-input', {
410
+ [style$6['wrap']]: labelWrap,
411
+ [style$6['disabled']]: disabled,
412
+ [style$6['small']]: size === 'small',
413
+ [style$6['large']]: size === 'large'
314
414
  }),
315
415
  justify: "space-between",
316
416
  onMouseOver: () => {
@@ -322,27 +422,26 @@ const SelectInput = createWithIntlProvider({
322
422
  }), (() => {
323
423
  const current = typeof prefix === 'function' ? prefix(contextProps) : prefix;
324
424
  return current && /*#__PURE__*/React.createElement("span", {
325
- className: classnames(style$5['select-input-prefix'], 'select-input-prefix'),
425
+ className: classnames(style$6['select-input-prefix'], 'select-input-prefix'),
326
426
  onClick: e => {
327
427
  e.stopPropagation();
328
428
  }
329
429
  }, current);
330
430
  })(), /*#__PURE__*/React.createElement("div", {
331
- className: classnames(style$5['select-input-inner'], 'select-input-inner')
332
- }, value.length > 0 ? single || value[0][valueKey] === selectedAllValue[valueKey] ? value[0][labelKey] : value.map(item => {
333
- return /*#__PURE__*/React.createElement(Tag, {
334
- key: item[valueKey],
335
- closable: true,
336
- bordered: false,
337
- onClose: e => {
338
- e.preventDefault();
339
- onRemove(item);
340
- }
341
- }, item[labelKey]);
431
+ className: classnames(style$6['select-input-inner'], 'select-input-inner')
432
+ }, value.length > 0 ? single || value[0][valueKey] === selectedAllValue[valueKey] ? /*#__PURE__*/React.createElement("span", {
433
+ className: classnames(style$6['single-label'], 'select-input-single-label'),
434
+ title: value[0][labelKey]
435
+ }, value[0][labelKey]) : /*#__PURE__*/React.createElement(TagOverflowInner, {
436
+ value: value,
437
+ innerWidth: innerWidth,
438
+ labelKey: labelKey,
439
+ valueKey: valueKey,
440
+ onRemove: onRemove
342
441
  }) : /*#__PURE__*/React.createElement("span", {
343
- className: classnames(style$5['placeholder'], 'select-input-placeholder')
442
+ className: classnames(style$6['placeholder'], 'select-input-placeholder')
344
443
  }, placeholder)), /*#__PURE__*/React.createElement("div", {
345
- className: classnames(style$5['select-input-icon'], 'select-input-icon')
444
+ className: classnames(style$6['select-input-icon'], 'select-input-icon')
346
445
  }, !disabled && allowClear && hover && value.length > 0 ? /*#__PURE__*/React.createElement(CloseCircleFilled, {
347
446
  onClick: e => {
348
447
  e.stopPropagation();
@@ -351,7 +450,7 @@ const SelectInput = createWithIntlProvider({
351
450
  }) : /*#__PURE__*/React.createElement(DownOutlined, null)), (() => {
352
451
  const current = typeof suffix === 'function' ? suffix(contextProps) : suffix;
353
452
  return current && /*#__PURE__*/React.createElement("span", {
354
- className: classnames(style$5['select-input-suffix'], 'select-input-suffix'),
453
+ className: classnames(style$6['select-input-suffix'], 'select-input-suffix'),
355
454
  onClick: e => {
356
455
  e.stopPropagation();
357
456
  }
@@ -371,13 +470,13 @@ const SelectInput = createWithIntlProvider({
371
470
  onOpenChange: setOpen,
372
471
  placement: placement,
373
472
  arrow: false,
374
- overlayClassName: classnames(style$5['overlay'], overlayClassName),
473
+ overlayClassName: classnames(style$6['overlay'], overlayClassName),
375
474
  trigger: "click",
376
475
  popupRender: () => /*#__PURE__*/React.createElement("div", {
377
476
  style: {
378
477
  '--overlay-width': popupOverlayWidth
379
478
  },
380
- className: classnames(style$5['overlay-content'], 'over-content'),
479
+ className: classnames(style$6['overlay-content'], 'over-content'),
381
480
  onClick: e => {
382
481
  e.stopPropagation();
383
482
  }
@@ -389,7 +488,7 @@ const SelectInput = createWithIntlProvider({
389
488
  }), /*#__PURE__*/React.createElement(ModalContent, contextProps, renderModal)));
390
489
  }));
391
490
 
392
- var style$4 = {"selected-all":"_prlgN"};
491
+ var style$5 = {"selected-all":"_prlgN"};
393
492
 
394
493
  const SelectedAll = createWithIntlProvider('zh-CN', locale$1, 'super-select')(() => {
395
494
  const {
@@ -414,7 +513,7 @@ const SelectedAll = createWithIntlProvider('zh-CN', locale$1, 'super-select')(()
414
513
  const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
415
514
  return /*#__PURE__*/React.createElement(Flex, {
416
515
  justify: "space-between",
417
- className: classnames(style$4['selected-all'], 'selected-all')
516
+ className: classnames(style$5['selected-all'], 'selected-all')
418
517
  }, /*#__PURE__*/React.createElement(Flex, {
419
518
  gap: 8
420
519
  }, /*#__PURE__*/React.createElement("span", null, formatMessage({
@@ -437,7 +536,7 @@ const computedIsSelectAll = (value, selectedAllValue, valueKey = 'value') => {
437
536
  return (value == null ? void 0 : value.length) === 1 && get(value, `[0][${valueKey}]`) === selectedAllValue[valueKey];
438
537
  };
439
538
 
440
- var style$3 = {"label":"_l3KoW","tag-list":"_CCPzb","tag-container":"_dKZHi","tag-container-inner":"_oijCI","tag":"_WmnnS","tag-inner":"_TMcFl"};
539
+ var style$4 = {"label":"_l3KoW","tag-list":"_CCPzb","tag-container":"_dKZHi","tag-container-inner":"_oijCI","tag":"_WmnnS","tag-inner":"_TMcFl"};
441
540
 
442
541
  const SelectedTagList = createWithIntlProvider('zh-CN', locale$1, 'super-select')(() => {
443
542
  const {
@@ -455,21 +554,21 @@ const SelectedTagList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
455
554
  valueKey
456
555
  } = Object.assign({}, props);
457
556
  return /*#__PURE__*/React.createElement(Flex, {
458
- className: classnames(style$3['tag-list'], 'selected-tag-list'),
557
+ className: classnames(style$4['tag-list'], 'selected-tag-list'),
459
558
  gap: 8
460
559
  }, /*#__PURE__*/React.createElement("div", {
461
- className: style$3['label']
560
+ className: style$4['label']
462
561
  }, formatMessage({
463
562
  id: 'selected'
464
563
  }), !single && value.length > 0 && `(${value.length}${Number.isInteger(maxLength) ? `/${maxLength}` : ''})`, ":"), /*#__PURE__*/React.createElement(SimpleBar, {
465
- className: style$3['tag-container']
564
+ className: style$4['tag-container']
466
565
  }, /*#__PURE__*/React.createElement(Flex, {
467
566
  gap: 8,
468
567
  wrap: true,
469
- className: style$3['tag-container-inner']
568
+ className: style$4['tag-container-inner']
470
569
  }, value.map(item => {
471
570
  return /*#__PURE__*/React.createElement(Tag, {
472
- className: style$3['tag'],
571
+ className: style$4['tag'],
473
572
  key: item[valueKey],
474
573
  closable: true,
475
574
  bordered: false,
@@ -478,19 +577,19 @@ const SelectedTagList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
478
577
  onRemove(item);
479
578
  }
480
579
  }, /*#__PURE__*/React.createElement("span", {
481
- className: style$3['tag-inner']
580
+ className: style$4['tag-inner']
482
581
  }, item[labelKey]));
483
582
  }))));
484
583
  });
485
584
 
486
- 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"};
585
+ 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"};
487
586
 
488
- const _excluded$1 = ["children"];
587
+ const _excluded$2 = ["children"];
489
588
  const SelectList = forwardRef((_ref, ref) => {
490
589
  let {
491
590
  children
492
591
  } = _ref,
493
- p = _objectWithoutPropertiesLoose(_ref, _excluded$1);
592
+ p = _objectWithoutPropertiesLoose(_ref, _excluded$2);
494
593
  const fetchListRef = useRef(null);
495
594
  const props = Object.assign({}, {
496
595
  renderItemContent: ({
@@ -503,7 +602,7 @@ const SelectList = forwardRef((_ref, ref) => {
503
602
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
504
603
  className: 'select-list-item-label'
505
604
  }, item[labelKey]), item.description && /*#__PURE__*/React.createElement("div", {
506
- className: classnames(style$2['select-list-item-description'], 'select-list-item-description')
605
+ className: classnames(style$3['select-list-item-description'], 'select-list-item-description')
507
606
  }, item.description));
508
607
  },
509
608
  renderItem: contextProps => {
@@ -524,9 +623,9 @@ const SelectList = forwardRef((_ref, ref) => {
524
623
  } = props;
525
624
  const isChecked = value.some(target => target[valueKey] === item[valueKey]);
526
625
  return /*#__PURE__*/React.createElement(List.Item, {
527
- className: classnames(style$2['default-list-item'], 'select-list-item', {
528
- [style$2['is-selected']]: isChecked,
529
- [style$2['is-disabled']]: item.disabled
626
+ className: classnames(style$3['default-list-item'], 'select-list-item', {
627
+ [style$3['is-selected']]: isChecked,
628
+ [style$3['is-disabled']]: item.disabled
530
629
  }),
531
630
  key: item[valueKey],
532
631
  onClick: () => {
@@ -554,7 +653,7 @@ const SelectList = forwardRef((_ref, ref) => {
554
653
  flex: 1,
555
654
  className: 'select-list-item-content'
556
655
  }, renderItemContent(contextProps)), single && /*#__PURE__*/React.createElement("div", {
557
- className: style$2['single-checked']
656
+ className: style$3['single-checked']
558
657
  }, isChecked && /*#__PURE__*/React.createElement(CheckOutlined, null)));
559
658
  },
560
659
  renderList: contextProps => {
@@ -568,12 +667,12 @@ const SelectList = forwardRef((_ref, ref) => {
568
667
  } = props;
569
668
  if (!(list && list.length > 0)) {
570
669
  return props.empty || /*#__PURE__*/React.createElement(Empty, {
571
- className: style$2['empty']
670
+ className: style$3['empty']
572
671
  });
573
672
  }
574
673
  return /*#__PURE__*/React.createElement(List, {
575
- className: classnames(style$2['default-list'], {
576
- [style$2['is-selected-all']]: isSelectedAll
674
+ className: classnames(style$3['default-list'], {
675
+ [style$3['is-selected-all']]: isSelectedAll
577
676
  }),
578
677
  size: "small",
579
678
  dataSource: list,
@@ -610,7 +709,7 @@ const SelectList = forwardRef((_ref, ref) => {
610
709
  } = props;
611
710
  const components = {
612
711
  search: (api && typeof getSearchProps === 'function' || options && typeof getSearchCallback === 'function') && /*#__PURE__*/React.createElement(SearchInput, {
613
- className: classnames(style$2['select-search'], 'select-list-search', {
712
+ className: classnames(style$3['select-search'], 'select-list-search', {
614
713
  'is-popup': isPopup
615
714
  }),
616
715
  placeholder: searchPlaceholder,
@@ -624,12 +723,12 @@ const SelectList = forwardRef((_ref, ref) => {
624
723
  showSearchButton: !isPopup
625
724
  }),
626
725
  selectedAll: /*#__PURE__*/React.createElement("div", {
627
- className: classnames(style$2['selected-all'], 'select-list-selected-all', {
726
+ className: classnames(style$3['selected-all'], 'select-list-selected-all', {
628
727
  'is-popup': isPopup
629
728
  })
630
729
  }, !single && allowSelectedAll && /*#__PURE__*/React.createElement(SelectedAll, null)),
631
730
  fetchList: /*#__PURE__*/React.createElement(FetchScrollLoader, _extends({}, props, {
632
- className: classnames(style$2['list'], 'select-list-scroll-list', {
731
+ className: classnames(style$3['list'], 'select-list-scroll-list', {
633
732
  'is-popup': isPopup
634
733
  }),
635
734
  searchProps: searchProps,
@@ -665,12 +764,12 @@ const SelectList = forwardRef((_ref, ref) => {
665
764
  }));
666
765
  }),
667
766
  selectedTag: showSelectedTag && /*#__PURE__*/React.createElement("div", {
668
- className: classnames(style$2['selected-tag'], 'select-list-selected-tag', {
767
+ className: classnames(style$3['selected-tag'], 'select-list-selected-tag', {
669
768
  'is-popup': isPopup
670
769
  })
671
770
  }, /*#__PURE__*/React.createElement(SelectedTagList, null)),
672
771
  footer: footer && /*#__PURE__*/React.createElement("div", {
673
- className: classnames(style$2['footer'], 'select-list-footer')
772
+ className: classnames(style$3['footer'], 'select-list-footer')
674
773
  }, typeof footer === 'function' ? footer({
675
774
  reload: () => {
676
775
  fetchListRef.current && fetchListRef.current.reload();
@@ -691,7 +790,7 @@ const SelectList = forwardRef((_ref, ref) => {
691
790
  });
692
791
  });
693
792
 
694
- 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"};
793
+ 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"};
695
794
 
696
795
  const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select')(forwardRef((p, ref) => {
697
796
  const {
@@ -720,7 +819,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
720
819
  return null;
721
820
  }
722
821
  return /*#__PURE__*/React.createElement(SearchInput, {
723
- className: classnames(style$1['select-search'], 'select-table-search', {
822
+ className: classnames(style$2['select-search'], 'select-table-search', {
724
823
  'is-popup': isPopup
725
824
  }),
726
825
  placeholder: searchPlaceholder,
@@ -780,7 +879,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
780
879
  } = props;
781
880
  const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
782
881
  const footerEl = footer && /*#__PURE__*/React.createElement("div", {
783
- className: classnames(style$1['footer'], 'select-table-footer')
882
+ className: classnames(style$2['footer'], 'select-table-footer')
784
883
  }, typeof footer === 'function' ? footer({
785
884
  reload: () => {
786
885
  var _fetchListRef$current, _fetchListRef$current2;
@@ -795,11 +894,11 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
795
894
  ref: bodyRef
796
895
  }, /*#__PURE__*/React.createElement(Col, {
797
896
  className: classnames({
798
- [style$1['single-body']]: single
897
+ [style$2['single-body']]: single
799
898
  }),
800
899
  span: single ? 24 : 16
801
900
  }, /*#__PURE__*/React.createElement("div", null, filterRender(Object.assign({}, targetProps))), /*#__PURE__*/React.createElement("div", {
802
- className: classnames(style$1['table'], 'select-table')
901
+ className: classnames(style$2['table'], 'select-table')
803
902
  }, /*#__PURE__*/React.createElement(TableView, {
804
903
  columns: columns,
805
904
  rowKey: valueKey,
@@ -841,7 +940,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
841
940
  renderBody
842
941
  }) => {
843
942
  return /*#__PURE__*/React.createElement(React.Fragment, null, header, /*#__PURE__*/React.createElement(FetchScrollLoader, _extends({}, props, {
844
- className: classnames(style$1['list'], 'select-table-list-scroll-list', {
943
+ className: classnames(style$2['list'], 'select-table-list-scroll-list', {
845
944
  'is-popup': isPopup
846
945
  }),
847
946
  searchProps: searchProps,
@@ -879,21 +978,21 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
879
978
  });
880
979
  if (!(list && list.length > 0)) {
881
980
  return props.empty || /*#__PURE__*/React.createElement(Empty, {
882
- className: classnames(style$1['empty'])
981
+ className: classnames(style$2['empty'])
883
982
  });
884
983
  }
885
984
  return renderBody(list, contextProps);
886
985
  }));
887
986
  }
888
987
  })), single && footerEl || /*#__PURE__*/React.createElement("div", {
889
- className: classnames(style$1['footer'], 'select-table-footer')
988
+ className: classnames(style$2['footer'], 'select-table-footer')
890
989
  })), !single && /*#__PURE__*/React.createElement(Col, {
891
- className: classnames(style$1['right-options'], {
990
+ className: classnames(style$2['right-options'], {
892
991
  'is-popup': isPopup
893
992
  }),
894
993
  span: 8
895
994
  }, /*#__PURE__*/React.createElement(SearchInput, {
896
- className: style$1['tags-search'],
995
+ className: style$2['tags-search'],
897
996
  placeholder: searchPlaceholder,
898
997
  value: tagSearchText,
899
998
  onSearch: value => {
@@ -907,7 +1006,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
907
1006
  }, /*#__PURE__*/React.createElement(Col, null, formatMessage({
908
1007
  id: 'selected'
909
1008
  }), value.length > 0 && `(${value.length}${Number.isInteger(maxLength) ? `/${maxLength}` : ''})`, ":"), /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement(Button, {
910
- className: style$1['no-padding-btn'],
1009
+ className: style$2['no-padding-btn'],
911
1010
  type: "link",
912
1011
  onClick: () => {
913
1012
  setValue([]);
@@ -920,7 +1019,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
920
1019
  }, value.filter(item => getTagSearchCallback(tagSearchText, item, targetProps)).map(item => {
921
1020
  var _fetchListRef$current4, _fetchListRef$current5;
922
1021
  return /*#__PURE__*/React.createElement(Tag, {
923
- className: style$1['tag'],
1022
+ className: style$2['tag'],
924
1023
  key: item[valueKey],
925
1024
  closable: true,
926
1025
  bordered: false,
@@ -931,7 +1030,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
931
1030
  }, /*#__PURE__*/React.createElement(Popover, {
932
1031
  getPopupContainer: () => bodyRef.current,
933
1032
  content: /*#__PURE__*/React.createElement(CentralContent, {
934
- className: style$1['descriptions'],
1033
+ className: style$2['descriptions'],
935
1034
  columns: columns.filter(item => {
936
1035
  if (Object.hasOwn(item, 'previewHidden')) {
937
1036
  return !item.previewHidden;
@@ -947,15 +1046,15 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
947
1046
  })
948
1047
  })
949
1048
  }, /*#__PURE__*/React.createElement("span", {
950
- className: style$1['tag-inner']
1049
+ className: style$2['tag-inner']
951
1050
  }, item[labelKey])));
952
1051
  }))), footerEl));
953
1052
  });
954
1053
  }));
955
1054
 
956
- 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"};
1055
+ 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"};
957
1056
 
958
- const _excluded = ["children"],
1057
+ const _excluded$1 = ["children"],
959
1058
  _excluded2 = ["data"];
960
1059
  const parseTreeData = memoize((data = [], {
961
1060
  parentKey,
@@ -981,7 +1080,7 @@ const SelectTree = forwardRef((_ref, ref) => {
981
1080
  let {
982
1081
  children
983
1082
  } = _ref,
984
- p = _objectWithoutPropertiesLoose(_ref, _excluded);
1083
+ p = _objectWithoutPropertiesLoose(_ref, _excluded$1);
985
1084
  const fetchListRef = useRef(null);
986
1085
  const [expandedKeys, setExpandedKeys] = useState([]);
987
1086
  const props = Object.assign({}, {
@@ -1016,9 +1115,9 @@ const SelectTree = forwardRef((_ref, ref) => {
1016
1115
  } = props;
1017
1116
  const isChecked = value.some(target => target[valueKey] === item[valueKey]);
1018
1117
  return /*#__PURE__*/React.createElement(Flex, {
1019
- className: classnames(style['default-list-item'], 'select-tree-item', {
1020
- [style['is-selected']]: isChecked,
1021
- [style['is-disabled']]: item.disabled
1118
+ className: classnames(style$1['default-list-item'], 'select-tree-item', {
1119
+ [style$1['is-selected']]: isChecked,
1120
+ [style$1['is-disabled']]: item.disabled
1022
1121
  }),
1023
1122
  key: item[valueKey],
1024
1123
  onClick: () => {
@@ -1046,7 +1145,7 @@ const SelectTree = forwardRef((_ref, ref) => {
1046
1145
  flex: 1,
1047
1146
  className: 'select-tree-item-content'
1048
1147
  }, renderItemContent(contextProps)), single && /*#__PURE__*/React.createElement("div", {
1049
- className: style['single-checked']
1148
+ className: style$1['single-checked']
1050
1149
  }, isChecked && /*#__PURE__*/React.createElement(CheckOutlined, null)));
1051
1150
  },
1052
1151
  renderTree: contextProps => {
@@ -1074,8 +1173,8 @@ const SelectTree = forwardRef((_ref, ref) => {
1074
1173
  return props.empty || /*#__PURE__*/React.createElement(Empty, null);
1075
1174
  }
1076
1175
  return /*#__PURE__*/React.createElement(Tree, {
1077
- className: classnames(style['default-list'], {
1078
- [style['is-selected-all']]: isSelectedAll
1176
+ className: classnames(style$1['default-list'], {
1177
+ [style$1['is-selected-all']]: isSelectedAll
1079
1178
  }),
1080
1179
  showIcon: true,
1081
1180
  selectable: false,
@@ -1119,7 +1218,7 @@ const SelectTree = forwardRef((_ref, ref) => {
1119
1218
  } = props;
1120
1219
  const components = {
1121
1220
  selectedAll: /*#__PURE__*/React.createElement("div", {
1122
- className: classnames(style['selected-all'], 'select-tree-selected-all', {
1221
+ className: classnames(style$1['selected-all'], 'select-tree-selected-all', {
1123
1222
  'is-popup': isPopup
1124
1223
  })
1125
1224
  }, !single && allowSelectedAll && /*#__PURE__*/React.createElement(SelectedAll, null)),
@@ -1139,7 +1238,7 @@ const SelectTree = forwardRef((_ref, ref) => {
1139
1238
  fetchProps = _objectWithoutPropertiesLoose(_ref2, _excluded2);
1140
1239
  const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
1141
1240
  return /*#__PURE__*/React.createElement(SimpleBar, {
1142
- className: classnames(style['list'], 'select-tree-scroll-list', {
1241
+ className: classnames(style$1['list'], 'select-tree-scroll-list', {
1143
1242
  'is-popup': isPopup
1144
1243
  })
1145
1244
  }, renderTree(Object.assign({}, fetchProps, targetProps, {
@@ -1149,12 +1248,12 @@ const SelectTree = forwardRef((_ref, ref) => {
1149
1248
  }
1150
1249
  })),
1151
1250
  selectedTag: showSelectedTag && /*#__PURE__*/React.createElement("div", {
1152
- className: classnames(style['selected-tag'], 'select-tree-selected-tag', {
1251
+ className: classnames(style$1['selected-tag'], 'select-tree-selected-tag', {
1153
1252
  'is-popup': isPopup
1154
1253
  })
1155
1254
  }, /*#__PURE__*/React.createElement(SelectedTagList, null)),
1156
1255
  footer: footer && /*#__PURE__*/React.createElement("div", {
1157
- className: classnames(style['footer'], 'select-list-footer')
1256
+ className: classnames(style$1['footer'], 'select-list-footer')
1158
1257
  }, typeof footer === 'function' ? footer({
1159
1258
  reload: () => {
1160
1259
  fetchListRef.current && fetchListRef.current.reload();
@@ -1175,5 +1274,779 @@ const SelectTree = forwardRef((_ref, ref) => {
1175
1274
  });
1176
1275
  });
1177
1276
 
1178
- export { SelectInput, SelectTableList, SelectTree, SelectedAll, SelectedTagList, SelectList as default };
1277
+ const createTreeUtils = mapping => {
1278
+ const mappingList = Array.from(mapping.values());
1279
+ const rootNodes = mappingList.filter(item => item.parentId === null);
1280
+ const delItem = (array, item) => {
1281
+ const index = array.indexOf(item);
1282
+ if (index > -1) {
1283
+ array.splice(index, 1);
1284
+ }
1285
+ };
1286
+
1287
+ /**
1288
+ * 通过一个nodeId获取所有父级和所有子级的第一个元素,组成一个从最顶级到最子级的数组
1289
+ * */
1290
+ const getSelectedQueue = id => {
1291
+ const currentNode = mapping.get(id);
1292
+ if (!currentNode) {
1293
+ return [];
1294
+ }
1295
+ const getFirstChild = target => {
1296
+ if (target.children && target.children.length > 0) {
1297
+ return getFirstChild(target.children.find(item => item.children && target.children.length > 0) || get(target.children, '0'));
1298
+ }
1299
+ const hasChildrenItem = getAllChildren(target.parentId).find(item => item.children && item.children.length > 0);
1300
+ if (hasChildrenItem) {
1301
+ return getFirstChild(hasChildrenItem);
1302
+ }
1303
+ return target;
1304
+ };
1305
+ const getParentNodeIdList = (targetId, parents = []) => {
1306
+ const output = [targetId, ...parents];
1307
+ const node = mapping.get(targetId);
1308
+ if (!node || isNil(node.parentId)) {
1309
+ return output;
1310
+ }
1311
+ return getParentNodeIdList(node.parentId, output);
1312
+ };
1313
+ const lastLevelNode = getFirstChild(currentNode);
1314
+ return getParentNodeIdList(get(lastLevelNode, 'id'));
1315
+ };
1316
+
1317
+ /**
1318
+ * 通过一个nodeId获得该节点的所有子级后代的id数组
1319
+ * */
1320
+ const getAllChildren = id => {
1321
+ const output = [];
1322
+ const core = id => {
1323
+ const node = mapping.get(id);
1324
+ if (!node) {
1325
+ return;
1326
+ }
1327
+ if (Array.isArray(node.children) && node.children.length > 0) {
1328
+ output.push(...node.children);
1329
+ node.children.forEach(item => {
1330
+ core(item.id);
1331
+ });
1332
+ }
1333
+ };
1334
+ core(id);
1335
+ return output;
1336
+ };
1337
+
1338
+ /**
1339
+ * 从自身节点开始向父级查找callback返回为true的node,找到第一个返回结果
1340
+ * */
1341
+ const findInParents = (id, callback) => {
1342
+ const core = id => {
1343
+ const currentNode = mapping.get(id);
1344
+ if (!currentNode) {
1345
+ return null;
1346
+ }
1347
+ if (callback(currentNode)) {
1348
+ return currentNode;
1349
+ }
1350
+ if (!isNil(currentNode.parentId)) {
1351
+ return core(currentNode.parentId);
1352
+ }
1353
+ return null;
1354
+ };
1355
+ return core(id);
1356
+ };
1357
+ const getSiblingNode = id => {
1358
+ const currentNode = mapping.get(id);
1359
+ if (!currentNode) {
1360
+ return [];
1361
+ }
1362
+ const parentId = currentNode.parentId;
1363
+ if (isNil(parentId)) {
1364
+ return rootNodes;
1365
+ }
1366
+ const parentNode = mapping.get(parentId);
1367
+ return parentNode.children;
1368
+ };
1369
+ const setNodeChecked = (id, value = []) => {
1370
+ const newValue = value.slice(0);
1371
+ const core = id => {
1372
+ const node = mapping.get(id);
1373
+ if (!node) {
1374
+ return;
1375
+ }
1376
+ newValue.push(id);
1377
+ getAllChildren(id).forEach(node => {
1378
+ delItem(newValue, node.id);
1379
+ });
1380
+ const siblingNode = getSiblingNode(id);
1381
+ const siblingNodeIsAllChecked = siblingNode.every(node => newValue.indexOf(node.id) > -1);
1382
+ if (node.parentId && siblingNodeIsAllChecked) {
1383
+ siblingNode.forEach(node => {
1384
+ delItem(newValue, node.id);
1385
+ });
1386
+ core(node.parentId);
1387
+ }
1388
+ };
1389
+ core(id);
1390
+ return newValue;
1391
+ };
1392
+ const setNodeUnchecked = (id, value = []) => {
1393
+ const newValue = value.slice(0);
1394
+ const core = id => {
1395
+ const node = mapping.get(id);
1396
+ if (!node) {
1397
+ return;
1398
+ }
1399
+ if (newValue.indexOf(node.id) > -1) {
1400
+ delItem(newValue, node.id);
1401
+ return;
1402
+ }
1403
+ const siblingNode = getSiblingNode(id);
1404
+ if (node.parentId) {
1405
+ siblingNode.forEach(node => {
1406
+ if (id !== node.id) {
1407
+ newValue.push(node.id);
1408
+ }
1409
+ });
1410
+ core(node.parentId);
1411
+ }
1412
+ };
1413
+ core(id);
1414
+ return newValue;
1415
+ };
1416
+ const computedCheckboxStatus = (id, value = []) => {
1417
+ if (!!findInParents(id, node => {
1418
+ return value.indexOf(node.id) > -1;
1419
+ })) {
1420
+ return {
1421
+ checked: true,
1422
+ indeterminate: false
1423
+ };
1424
+ }
1425
+ const indeterminate = ((id, callback) => {
1426
+ const core = id => {
1427
+ const currentNode = mapping.get(id);
1428
+ if (!currentNode) {
1429
+ return null;
1430
+ }
1431
+ if (callback(currentNode)) {
1432
+ return currentNode;
1433
+ }
1434
+ if (Array.isArray(currentNode.children) && currentNode.children.length > 0) {
1435
+ return currentNode.children.find(item => !!core(item.id));
1436
+ }
1437
+ };
1438
+ return !!core(id);
1439
+ })(id, node => value.indexOf(node.id) > -1);
1440
+ if (indeterminate) {
1441
+ return {
1442
+ checked: false,
1443
+ indeterminate: true
1444
+ };
1445
+ }
1446
+ return {
1447
+ checked: false,
1448
+ indeterminate: false
1449
+ };
1450
+ };
1451
+ const transformToTreeData = () => {
1452
+ const core = nodeList => {
1453
+ if (Array.isArray(nodeList) && nodeList.length > 0) {
1454
+ return nodeList.map(node => {
1455
+ const children = mappingList.filter(item => item.parentId === node.id);
1456
+ return Object.assign({}, node, {
1457
+ children: core(children)
1458
+ });
1459
+ });
1460
+ }
1461
+ return null;
1462
+ };
1463
+ return core(rootNodes);
1464
+ };
1465
+ const treeData = transformToTreeData();
1466
+ return {
1467
+ mapping,
1468
+ getSelectedQueue,
1469
+ getAllChildren,
1470
+ computedCheckboxStatus,
1471
+ getSiblingNode,
1472
+ findInParents,
1473
+ setNodeChecked,
1474
+ setNodeUnchecked,
1475
+ treeData,
1476
+ treeMapping: new Map((treeData || []).map(item => [item.id, item]))
1477
+ };
1478
+ };
1479
+
1480
+ 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"};
1481
+
1482
+ const CustomMenu = ({
1483
+ className,
1484
+ selectedKeys,
1485
+ items,
1486
+ onSelect
1487
+ }) => {
1488
+ const handleItemClick = (key, e) => {
1489
+ // 只阻止事件冒泡,不阻止默认行为
1490
+ e.stopPropagation();
1491
+ onSelect == null || onSelect({
1492
+ key,
1493
+ domEvent: e
1494
+ });
1495
+ };
1496
+ return /*#__PURE__*/React.createElement(List, {
1497
+ className: classnames(style['custom-menu'], className),
1498
+ dataSource: items,
1499
+ renderItem: item => {
1500
+ const isSelected = selectedKeys == null ? void 0 : selectedKeys.includes(item.key);
1501
+ return /*#__PURE__*/React.createElement(List.Item, {
1502
+ className: classnames(style['custom-menu-item'], {
1503
+ [style['selected']]: isSelected
1504
+ }),
1505
+ onClick: e => handleItemClick(item.key, e)
1506
+ }, item.label);
1507
+ }
1508
+ });
1509
+ };
1510
+
1511
+ const _excluded = ["options", "value", "onChange", "defaultValue", "maxLength", "single", "onlyAllowLastLevel", "openLoadData", "onLoadMore", "parentIdKey", "menuItemWidth", "isPopup", "searchPlaceholder", "onSearch", "valueKey", "labelKey", "placeholder", "disabled", "size", "overlayWidth"];
1512
+ const numberToPx = val => {
1513
+ return typeof val === 'number' ? `${val}px` : val;
1514
+ };
1515
+
1516
+ // 级联选择内容组件
1517
+ const CascaderInner = ({
1518
+ options,
1519
+ value,
1520
+ setValue,
1521
+ maxLength,
1522
+ single,
1523
+ onlyAllowLastLevel,
1524
+ openLoadData,
1525
+ onLoadMore,
1526
+ parentIdKey,
1527
+ menuItemWidth,
1528
+ isPopup,
1529
+ searchPlaceholder,
1530
+ onSearch,
1531
+ valueKey,
1532
+ labelKey,
1533
+ onOpenChange,
1534
+ open
1535
+ }) => {
1536
+ const {
1537
+ message
1538
+ } = App.useApp();
1539
+ const [searchText, setSearchText] = useState('');
1540
+ const [loading, setLoading] = useState(false);
1541
+
1542
+ // 构建 mapping
1543
+ const mapping = useMemo(() => {
1544
+ const map = new Map();
1545
+ const processData = (items, parentId = null) => {
1546
+ items.forEach(item => {
1547
+ const node = _extends({}, item, {
1548
+ id: item[valueKey],
1549
+ label: item[labelKey],
1550
+ parentId
1551
+ });
1552
+ if (item.children && item.children.length > 0) {
1553
+ node.children = item.children.map(child => _extends({}, child, {
1554
+ id: child[valueKey],
1555
+ label: child[labelKey],
1556
+ parentId: node.id
1557
+ }));
1558
+ processData(item.children, node.id);
1559
+ }
1560
+ map.set(node.id, node);
1561
+ });
1562
+ };
1563
+ processData(options);
1564
+ return map;
1565
+ }, [options, valueKey, labelKey]);
1566
+
1567
+ // 创建树工具
1568
+ const treeUtils = useMemo(() => {
1569
+ return createTreeUtils(mapping);
1570
+ }, [mapping]);
1571
+
1572
+ // 当前选中的列
1573
+ const [selectedIds, setSelectedIds] = useState(() => {
1574
+ const initValue = value.find(item => {
1575
+ const id = typeof item === 'object' ? item[valueKey] : item;
1576
+ return !!mapping.get(id);
1577
+ });
1578
+ if (initValue) {
1579
+ const id = typeof initValue === 'object' ? initValue[valueKey] : initValue;
1580
+ return treeUtils.getSelectedQueue(id);
1581
+ }
1582
+
1583
+ // 默认选中第一列
1584
+ const firstNode = Array.from(mapping.values()).find(item => isNil(item.parentId));
1585
+ if (firstNode) {
1586
+ return treeUtils.getSelectedQueue(firstNode.id);
1587
+ }
1588
+ return [];
1589
+ });
1590
+
1591
+ // 当 Modal 打开时,根据 value 重新初始化 selectedIds
1592
+ const prevOpenRef = useRef(open);
1593
+ useEffect(() => {
1594
+ // 只在非 popup 模式下且 Modal 从关闭变为打开时处理
1595
+ if (!isPopup && open && !prevOpenRef.current) {
1596
+ const initValue = value.find(item => {
1597
+ const id = typeof item === 'object' ? item[valueKey] : item;
1598
+ return !!mapping.get(id);
1599
+ });
1600
+ if (initValue) {
1601
+ const id = typeof initValue === 'object' ? initValue[valueKey] : initValue;
1602
+ setSelectedIds(treeUtils.getSelectedQueue(id));
1603
+ } else {
1604
+ // 默认选中第一列
1605
+ const firstNode = Array.from(mapping.values()).find(item => isNil(item.parentId));
1606
+ if (firstNode) {
1607
+ setSelectedIds(treeUtils.getSelectedQueue(firstNode.id));
1608
+ }
1609
+ }
1610
+ }
1611
+ prevOpenRef.current = open;
1612
+ }, [open, value, mapping, treeUtils, valueKey, isPopup]);
1613
+
1614
+ // 懒加载支持
1615
+ const loadMorePropsRef = useRef({});
1616
+ loadMorePropsRef.current = {
1617
+ openLoadData,
1618
+ onLoadMore,
1619
+ parentIdKey,
1620
+ treeUtils
1621
+ };
1622
+ useEffect(() => {
1623
+ if (!openLoadData || !onLoadMore) {
1624
+ return;
1625
+ }
1626
+ const lastNode = mapping.get(last(selectedIds));
1627
+ if (!lastNode) {
1628
+ return;
1629
+ }
1630
+
1631
+ // 检查是否需要加载子节点
1632
+ if (lastNode.hasOwnProperty('children') && lastNode.children !== undefined) {
1633
+ return;
1634
+ }
1635
+ setLoading(true);
1636
+ onLoadMore({
1637
+ [parentIdKey]: lastNode.id
1638
+ }).then(() => {
1639
+ setLoading(false);
1640
+ }).catch(() => {
1641
+ setLoading(false);
1642
+ });
1643
+ }, [selectedIds, mapping, openLoadData, onLoadMore, parentIdKey]);
1644
+
1645
+ // 检查是否为非叶子节点
1646
+ const isNotLastNode = useCallback(id => {
1647
+ const node = mapping.get(id);
1648
+ if (!node) return false;
1649
+ if (openLoadData && !node.hasOwnProperty('children')) {
1650
+ return true;
1651
+ }
1652
+ return node.children && node.children.length > 0;
1653
+ }, [mapping, openLoadData]);
1654
+
1655
+ // 选择处理
1656
+ const onCheckedChange = useCallback((checked, id) => {
1657
+ const newValue = (() => {
1658
+ if (onlyAllowLastLevel && checked) {
1659
+ const _currentIds = value.map(item => typeof item === 'object' ? item[valueKey] : item);
1660
+ if (_currentIds.includes(id)) return _currentIds;
1661
+ return [..._currentIds, id];
1662
+ }
1663
+ if (onlyAllowLastLevel) {
1664
+ const _currentIds2 = value.map(item => typeof item === 'object' ? item[valueKey] : item);
1665
+ return _currentIds2.filter(itemId => itemId !== id);
1666
+ }
1667
+ const currentIds = value.map(item => typeof item === 'object' ? item[valueKey] : item);
1668
+ return checked ? treeUtils.setNodeChecked(id, currentIds) : treeUtils.setNodeUnchecked(id, currentIds);
1669
+ })();
1670
+ if (newValue.length > maxLength) {
1671
+ message.error(`最多只能选择 ${maxLength} 项`);
1672
+ return;
1673
+ }
1674
+
1675
+ // 转换回完整对象
1676
+ const newValues = newValue.map(id => {
1677
+ const node = mapping.get(id);
1678
+ // 返回完整的节点数据,保留所有原始字段
1679
+ return node ? _extends({}, node, {
1680
+ [valueKey]: node.id,
1681
+ [labelKey]: node.label
1682
+ }) : null;
1683
+ }).filter(Boolean);
1684
+ const finalValue = single && newValues.length > 0 ? [last(newValues)] : newValues;
1685
+ setValue(finalValue);
1686
+
1687
+ // 单选且是叶子节点且在 popup 模式下,自动关闭下拉框
1688
+ if (single && newValues.length > 0 && !isNotLastNode(id) && isPopup && onOpenChange) {
1689
+ onOpenChange(false);
1690
+ }
1691
+ }, [value, maxLength, single, onlyAllowLastLevel, treeUtils, mapping, message, valueKey, labelKey, isPopup, onOpenChange, isNotLastNode]);
1692
+
1693
+ // 搜索结果
1694
+ const searchResults = useMemo(() => {
1695
+ if (!searchText || !onSearch) return null;
1696
+ const keyword = searchText.toLowerCase();
1697
+ return Array.from(mapping.values()).filter(item => {
1698
+ return item.label && item.label.toLowerCase().includes(keyword);
1699
+ });
1700
+ }, [searchText, mapping, onSearch]);
1701
+
1702
+ // 搜索选择
1703
+ const onSearchSelect = item => {
1704
+ const currentIds = value.map(v => typeof v === 'object' ? v[valueKey] : v);
1705
+ const checked = currentIds.includes(item.id);
1706
+ onCheckedChange(!checked, item.id);
1707
+ if (!checked) {
1708
+ setSelectedIds(treeUtils.getSelectedQueue(item.id));
1709
+ }
1710
+ setSearchText('');
1711
+ };
1712
+
1713
+ // 渲染搜索内容
1714
+ if (searchText && searchResults) {
1715
+ const _currentIds3 = value.map(v => typeof v === 'object' ? v[valueKey] : v);
1716
+ return /*#__PURE__*/React.createElement("div", {
1717
+ className: classnames(style['content'], {
1718
+ [style['is-popup']]: isPopup
1719
+ })
1720
+ }, /*#__PURE__*/React.createElement(SearchInput, {
1721
+ className: classnames(style['search-input'], {
1722
+ 'is-popup': isPopup
1723
+ }),
1724
+ placeholder: searchPlaceholder,
1725
+ value: searchText,
1726
+ onSearch: setSearchText,
1727
+ simple: isPopup,
1728
+ showSearchButton: !isPopup
1729
+ }), /*#__PURE__*/React.createElement(SimpleBar, {
1730
+ className: style['scroll-plus-box']
1731
+ }, searchResults.length === 0 ? /*#__PURE__*/React.createElement(Empty, {
1732
+ description: "\u6682\u65E0\u6570\u636E"
1733
+ }) : /*#__PURE__*/React.createElement(List, {
1734
+ className: style['list'],
1735
+ size: "small",
1736
+ dataSource: searchResults,
1737
+ rowKey: "id",
1738
+ renderItem: item => {
1739
+ const checked = _currentIds3.includes(item.id);
1740
+ return /*#__PURE__*/React.createElement(List.Item, {
1741
+ className: classnames({
1742
+ [style['is-selected']]: checked
1743
+ }),
1744
+ onClick: () => onSearchSelect(item)
1745
+ }, /*#__PURE__*/React.createElement("span", null, item.label), checked && /*#__PURE__*/React.createElement("span", {
1746
+ style: {
1747
+ marginLeft: 8,
1748
+ color: '#1677ff'
1749
+ }
1750
+ }, "\u2713"));
1751
+ }
1752
+ })));
1753
+ }
1754
+
1755
+ // 渲染级联列
1756
+ const currentIds = value.map(v => typeof v === 'object' ? v[valueKey] : v);
1757
+ return /*#__PURE__*/React.createElement("div", {
1758
+ className: classnames(style['content'], {
1759
+ [style['is-popup']]: isPopup,
1760
+ [style['has-search']]: !!onSearch
1761
+ }),
1762
+ style: {
1763
+ '--menu-item-width': numberToPx(menuItemWidth)
1764
+ }
1765
+ }, onSearch && /*#__PURE__*/React.createElement(SearchInput, {
1766
+ className: classnames(style['search-input'], {
1767
+ 'is-popup': isPopup
1768
+ }),
1769
+ placeholder: searchPlaceholder,
1770
+ value: searchText,
1771
+ onSearch: setSearchText,
1772
+ simple: isPopup,
1773
+ showSearchButton: !isPopup
1774
+ }), /*#__PURE__*/React.createElement(SimpleBar, {
1775
+ className: style['scroller'],
1776
+ options: {
1777
+ autoHide: false
1778
+ }
1779
+ }, /*#__PURE__*/React.createElement("div", {
1780
+ className: style['columns']
1781
+ }, selectedIds.map((selectedId, index) => {
1782
+ const selectNode = mapping.get(selectedId);
1783
+ const siblingNodes = treeUtils.getSiblingNode(selectedId);
1784
+ const isLastLevel = !isNotLastNode(selectNode == null ? void 0 : selectNode.id) && index > 0;
1785
+ return /*#__PURE__*/React.createElement(SimpleBar, {
1786
+ key: selectedId || index,
1787
+ className: classnames(style['content-item'], {
1788
+ [style['last-level-area']]: isLastLevel
1789
+ })
1790
+ }, isLastLevel ? /*#__PURE__*/React.createElement(Space, {
1791
+ wrap: true,
1792
+ style: {
1793
+ padding: 12
1794
+ },
1795
+ className: classnames({
1796
+ [style['single-mode']]: single
1797
+ })
1798
+ }, siblingNodes.map(node => {
1799
+ const {
1800
+ checked,
1801
+ indeterminate
1802
+ } = treeUtils.computedCheckboxStatus(node.id, currentIds);
1803
+ return /*#__PURE__*/React.createElement(Checkbox, {
1804
+ key: node.id,
1805
+ checked: checked,
1806
+ indeterminate: indeterminate,
1807
+ onChange: e => onCheckedChange(e.target.checked, node.id)
1808
+ }, node.label);
1809
+ })) : /*#__PURE__*/React.createElement(CustomMenu, {
1810
+ className: style['menu'],
1811
+ selectedKeys: index === selectedIds.length - 1 ? [] : selectedIds,
1812
+ onSelect: ({
1813
+ key
1814
+ }) => {
1815
+ const node = mapping.get(key);
1816
+ if (!node) return;
1817
+ if (isNotLastNode(node.id)) {
1818
+ setSelectedIds(treeUtils.getSelectedQueue(node.id));
1819
+ } else {
1820
+ const {
1821
+ checked
1822
+ } = treeUtils.computedCheckboxStatus(node.id, currentIds);
1823
+ onCheckedChange(!checked, node.id);
1824
+ }
1825
+ },
1826
+ items: siblingNodes.map(node => {
1827
+ const {
1828
+ checked,
1829
+ indeterminate
1830
+ } = treeUtils.computedCheckboxStatus(node.id, currentIds);
1831
+ const hasChildren = isNotLastNode(node.id);
1832
+
1833
+ // 计算子级选中数量
1834
+ const childrenSelectedCount = hasChildren ? treeUtils.getAllChildren(node.id).filter(child => currentIds.includes(child.id)).length : 0;
1835
+ return {
1836
+ key: node.id,
1837
+ label: /*#__PURE__*/React.createElement(Space, {
1838
+ className: classnames(style['menu-item'], {
1839
+ [style['checkbox-hidden']]: onlyAllowLastLevel && hasChildren,
1840
+ [style['single-mode']]: single
1841
+ })
1842
+ }, (!onlyAllowLastLevel || !hasChildren) && /*#__PURE__*/React.createElement(Checkbox, {
1843
+ checked: checked,
1844
+ indeterminate: indeterminate,
1845
+ onClick: e => e.stopPropagation(),
1846
+ onChange: e => {
1847
+ e.stopPropagation();
1848
+ onCheckedChange(e.target.checked, node.id);
1849
+ }
1850
+ }), /*#__PURE__*/React.createElement("div", {
1851
+ className: style['menu-label']
1852
+ }, /*#__PURE__*/React.createElement("span", {
1853
+ className: style['menu-label-text']
1854
+ }, node.label), hasChildren && childrenSelectedCount > 0 && /*#__PURE__*/React.createElement(Badge, {
1855
+ count: childrenSelectedCount,
1856
+ size: "small"
1857
+ })), hasChildren ? /*#__PURE__*/React.createElement(RightOutlined, {
1858
+ className: style['menu-item-icon']
1859
+ }) : /*#__PURE__*/React.createElement("span", {
1860
+ className: style['menu-item-placeholder']
1861
+ }))
1862
+ };
1863
+ })
1864
+ }));
1865
+ }), loading && /*#__PURE__*/React.createElement("div", {
1866
+ className: style['loading']
1867
+ }, /*#__PURE__*/React.createElement(Spin, {
1868
+ size: "small"
1869
+ })))));
1870
+ };
1871
+
1872
+ // 主组件
1873
+ const SelectCascader = _ref => {
1874
+ let {
1875
+ options = [],
1876
+ value,
1877
+ onChange,
1878
+ defaultValue,
1879
+ maxLength = Number.MAX_VALUE,
1880
+ single = false,
1881
+ onlyAllowLastLevel = false,
1882
+ openLoadData = false,
1883
+ onLoadMore,
1884
+ parentIdKey = 'id',
1885
+ menuItemWidth = 180,
1886
+ isPopup = true,
1887
+ searchPlaceholder,
1888
+ onSearch,
1889
+ valueKey = 'id',
1890
+ labelKey = 'label',
1891
+ placeholder = '请选择',
1892
+ disabled = false,
1893
+ size = 'default',
1894
+ overlayWidth
1895
+ } = _ref,
1896
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
1897
+ // 内部始终使用数组格式处理
1898
+ // SelectInput 会处理 single 模式的 value 和 onChange 转换
1899
+ const [innerValue, setInnerValue] = useState(Array.isArray(defaultValue) ? defaultValue : defaultValue ? [defaultValue] : []);
1900
+
1901
+ // currentValue 用于内部处理,始终是数组
1902
+ const currentValue = useMemo(() => {
1903
+ if (value !== undefined) {
1904
+ // 外部传入的 value 可能是对象(single)或数组(多选)
1905
+ return Array.isArray(value) ? value : value ? [value] : [];
1906
+ }
1907
+ return innerValue;
1908
+ }, [value, innerValue]);
1909
+ const setValue = useCallback(newValue => {
1910
+ // SelectInput 在 single 模式下会传单个对象或 null/undefined,需要转换为数组
1911
+ const normalizedValue = (() => {
1912
+ if (single) {
1913
+ // 单选模式:可能是单个对象、null、undefined 或数组
1914
+ if (Array.isArray(newValue)) {
1915
+ return newValue;
1916
+ }
1917
+ return isNotEmpty(newValue) ? [newValue] : [];
1918
+ }
1919
+ // 多选模式:确保是数组
1920
+ return Array.isArray(newValue) ? newValue : [];
1921
+ })();
1922
+ if (value === undefined) {
1923
+ setInnerValue(normalizedValue);
1924
+ }
1925
+
1926
+ // 根据单选/多选模式转换输出格式
1927
+ if (single) {
1928
+ // 单选:返回单个对象或 null
1929
+ onChange == null || onChange(normalizedValue.length > 0 ? normalizedValue[0] : null);
1930
+ } else {
1931
+ // 多选:返回数组
1932
+ onChange == null || onChange(normalizedValue);
1933
+ }
1934
+ }, [value, onChange, single]);
1935
+
1936
+ // 传递给 SelectInput 的值:根据 single 参数决定格式
1937
+ const selectInputValue = useMemo(() => {
1938
+ if (single) {
1939
+ // single 模式:传单个对象或 undefined
1940
+ return currentValue.length > 0 ? currentValue[0] : undefined;
1941
+ }
1942
+ // 多选模式:传数组
1943
+ return currentValue;
1944
+ }, [currentValue, single]);
1945
+
1946
+ // 计算 label 显示
1947
+ useMemo(() => {
1948
+ // currentValue 已经是数组格式了
1949
+ return currentValue.map(item => {
1950
+ // 如果已经是对象,确保有标准化的字段
1951
+ if (typeof item === 'object') {
1952
+ // 优先使用 item[labelKey],然后是 item.label,最后是 item.name
1953
+ const label = item[labelKey] || item.label || item.name || String(item[valueKey] || '');
1954
+ return _extends({}, item, {
1955
+ [valueKey]: item[valueKey] || item.id,
1956
+ [labelKey]: label
1957
+ });
1958
+ }
1959
+ // 如果是值,从 options 中查找
1960
+ const findLabel = items => {
1961
+ for (const node of items) {
1962
+ if (node[valueKey] === item) {
1963
+ return {
1964
+ [valueKey]: item,
1965
+ [labelKey]: node[labelKey] || node.name || String(item)
1966
+ };
1967
+ }
1968
+ if (node.children) {
1969
+ const found = findLabel(node.children);
1970
+ if (found) return found;
1971
+ }
1972
+ }
1973
+ return null;
1974
+ };
1975
+ return findLabel(options) || {
1976
+ [valueKey]: item,
1977
+ [labelKey]: String(item)
1978
+ };
1979
+ }).filter(Boolean);
1980
+ }, [currentValue, options, valueKey, labelKey]);
1981
+ return /*#__PURE__*/React.createElement(SelectInput, _extends({}, props, {
1982
+ value: selectInputValue,
1983
+ onChange: setValue,
1984
+ single: single,
1985
+ maxLength: maxLength,
1986
+ isPopup: isPopup,
1987
+ placeholder: placeholder,
1988
+ disabled: disabled,
1989
+ size: size,
1990
+ valueKey: valueKey,
1991
+ labelKey: labelKey,
1992
+ overlayWidth: overlayWidth || menuItemWidth * 2
1993
+ }), contextProps => {
1994
+ // 使用 contextProps 中的 value 和 setValue,支持 Modal 模式下的内部状态管理
1995
+ const contextValue = contextProps.value;
1996
+ const contextSetValue = contextProps.setValue;
1997
+
1998
+ // 计算当前显示的 value
1999
+ const currentDisplayValue = contextValue.map(item => {
2000
+ // 如果已经是对象,确保有标准化的字段
2001
+ if (typeof item === 'object') {
2002
+ const label = item[labelKey] || item.label || item.name || String(item[valueKey] || '');
2003
+ return _extends({}, item, {
2004
+ [valueKey]: item[valueKey] || item.id,
2005
+ [labelKey]: label
2006
+ });
2007
+ }
2008
+ // 如果是值,从 options 中查找
2009
+ const findLabel = items => {
2010
+ for (const node of items) {
2011
+ if (node[valueKey] === item) {
2012
+ return {
2013
+ [valueKey]: item,
2014
+ [labelKey]: node[labelKey] || node.name || String(item)
2015
+ };
2016
+ }
2017
+ if (node.children) {
2018
+ const found = findLabel(node.children);
2019
+ if (found) return found;
2020
+ }
2021
+ }
2022
+ return null;
2023
+ };
2024
+ return findLabel(options) || {
2025
+ [valueKey]: item,
2026
+ [labelKey]: String(item)
2027
+ };
2028
+ }).filter(Boolean);
2029
+ return /*#__PURE__*/React.createElement(CascaderInner, {
2030
+ options: options,
2031
+ value: currentDisplayValue,
2032
+ setValue: contextSetValue,
2033
+ maxLength: maxLength,
2034
+ single: single,
2035
+ onlyAllowLastLevel: onlyAllowLastLevel,
2036
+ openLoadData: openLoadData,
2037
+ onLoadMore: onLoadMore,
2038
+ parentIdKey: parentIdKey,
2039
+ menuItemWidth: menuItemWidth,
2040
+ isPopup: isPopup,
2041
+ searchPlaceholder: searchPlaceholder,
2042
+ onSearch: onSearch,
2043
+ valueKey: valueKey,
2044
+ labelKey: labelKey,
2045
+ onOpenChange: contextProps.onOpenChange,
2046
+ open: contextProps.open
2047
+ });
2048
+ });
2049
+ };
2050
+
2051
+ export { SelectCascader, SelectInput, SelectTableList, SelectTree, SelectedAll, SelectedTagList, createTreeUtils, SelectList as default };
1179
2052
  //# sourceMappingURL=index.modern.js.map