@kne/super-select 0.1.50 → 0.1.54

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.
@@ -7,9 +7,10 @@ import classnames from 'classnames';
7
7
  import isEqual from 'lodash/isEqual';
8
8
  import last from 'lodash/last';
9
9
  import { Tag, Modal, App, Dropdown, Flex, Checkbox, List, Empty, Pagination, Row, Col, Button, Popover, Tree, Space, Badge, Spin } from 'antd';
10
+ import { useZIndex } from 'antd/es/_util/hooks';
10
11
  import { CloseCircleFilled, DownOutlined, CheckOutlined, RightOutlined } from '@ant-design/icons';
11
12
  import { isNotEmpty } from '@kne/is-empty';
12
- import { usePopupContainer, useScrollElement, useMobilePopupMount, MOBILE_POPUP_MODE } from '@kne/responsive-utils';
13
+ import { useScrollElement, usePopupMount, MOBILE_POPUP_MODE } from '@kne/responsive-utils';
13
14
  import { createWithIntlProvider, useIntl } from '@kne/react-intl';
14
15
  import { useOverflowItems } from '@kne/overflow-items';
15
16
  import 'simplebar-react/dist/simplebar.min.css';
@@ -140,7 +141,7 @@ const TagOverflowInner = ({
140
141
  "data-tag-measure": true
141
142
  }, /*#__PURE__*/React.createElement(Tag, {
142
143
  closable: true,
143
- bordered: false,
144
+ variant: "filled",
144
145
  className: style$6['tag-item'],
145
146
  style: {
146
147
  '--max-tag-width': `${maxTagWidth}px`,
@@ -163,7 +164,7 @@ const TagOverflowInner = ({
163
164
  }, displayTags.map(item => /*#__PURE__*/React.createElement(Tag, {
164
165
  key: item[valueKey],
165
166
  closable: true,
166
- bordered: false,
167
+ variant: "filled",
167
168
  className: style$6['tag-item'],
168
169
  style: {
169
170
  '--max-tag-width': `${maxTagWidth}px`,
@@ -187,6 +188,20 @@ const MOBILE_SHEET_MIN_HEIGHT = '30%';
187
188
  const MOBILE_MASK_Z_INDEX = 1000;
188
189
  const MOBILE_POPUP_Z_INDEX = 1050;
189
190
  const MASK_ANIMATION_DURATION = 180;
191
+
192
+ /** Modal 内半屏 sheet 对齐 antd Dropdown:消费 zIndexContext,保留移动端 UX */
193
+ const resolveMobileSheetZIndex = popupZIndex => {
194
+ if (popupZIndex == null) {
195
+ return {
196
+ maskZIndex: MOBILE_MASK_Z_INDEX,
197
+ panelZIndex: MOBILE_POPUP_Z_INDEX
198
+ };
199
+ }
200
+ return {
201
+ maskZIndex: popupZIndex - 1,
202
+ panelZIndex: popupZIndex
203
+ };
204
+ };
190
205
  let parentScrollLockCount = 0;
191
206
  let parentScrollLocked = [];
192
207
  const lockParentScroll = getScrollElements => {
@@ -294,7 +309,8 @@ const MobileSheetMask = ({
294
309
  open,
295
310
  mountNode,
296
311
  fixedModeClass,
297
- onClose
312
+ onClose,
313
+ zIndex: _zIndex = MOBILE_MASK_Z_INDEX
298
314
  }) => {
299
315
  const [renderMask, setRenderMask] = useState(false);
300
316
  const [maskClosing, setMaskClosing] = useState(false);
@@ -318,9 +334,9 @@ const MobileSheetMask = ({
318
334
  return null;
319
335
  }
320
336
  return createPortal(/*#__PURE__*/React.createElement("div", {
321
- className: classnames(style$6['mobile-sheet-mask'], maskClosing && style$6['mobile-sheet-mask-leave'], fixedModeClass),
337
+ className: classnames(style$6['mobile-sheet-mask'], 'select-mobile-sheet-mask', maskClosing && style$6['mobile-sheet-mask-leave'], fixedModeClass),
322
338
  style: {
323
- zIndex: MOBILE_MASK_Z_INDEX
339
+ zIndex: _zIndex
324
340
  },
325
341
  onClick: onClose,
326
342
  onTouchMove: e => {
@@ -336,17 +352,17 @@ const MobileSheetHeader = ({
336
352
  onConfirm
337
353
  }) => {
338
354
  return /*#__PURE__*/React.createElement("div", {
339
- className: style$6['mobile-sheet-header']
355
+ className: classnames(style$6['mobile-sheet-header'], 'select-mobile-sheet-header')
340
356
  }, /*#__PURE__*/React.createElement("button", {
341
357
  type: "button",
342
- className: style$6['mobile-sheet-action'],
358
+ className: classnames(style$6['mobile-sheet-action'], 'select-mobile-sheet-cancel'),
343
359
  onClick: onCancel
344
360
  }, cancelText), /*#__PURE__*/React.createElement("div", {
345
- className: style$6['mobile-sheet-title'],
361
+ className: classnames(style$6['mobile-sheet-title'], 'select-mobile-sheet-title'),
346
362
  title: title
347
363
  }, title), /*#__PURE__*/React.createElement("button", {
348
364
  type: "button",
349
- className: classnames(style$6['mobile-sheet-action'], style$6['mobile-sheet-confirm']),
365
+ className: classnames(style$6['mobile-sheet-action'], style$6['mobile-sheet-confirm'], 'select-mobile-sheet-confirm'),
350
366
  onClick: onConfirm
351
367
  }, confirmText));
352
368
  };
@@ -360,15 +376,16 @@ const MobileSheetPanel = ({
360
376
  confirmText,
361
377
  onCancel,
362
378
  onConfirm,
363
- children
379
+ children,
380
+ zIndex: _zIndex2 = MOBILE_POPUP_Z_INDEX
364
381
  }) => {
365
382
  if (!open || !mountNode) {
366
383
  return null;
367
384
  }
368
385
  return createPortal(/*#__PURE__*/React.createElement("div", {
369
- className: classnames(style$6['mobile-sheet-popup'], style$6['mobile-sheet-portal'], fixedModeClass, overlayClassName),
386
+ className: classnames(style$6['mobile-sheet-popup'], style$6['mobile-sheet-portal'], 'select-mobile-sheet', fixedModeClass, overlayClassName),
370
387
  style: {
371
- zIndex: MOBILE_POPUP_Z_INDEX,
388
+ zIndex: _zIndex2,
372
389
  maxHeight: MOBILE_SHEET_MAX_HEIGHT,
373
390
  minHeight: MOBILE_SHEET_MIN_HEIGHT
374
391
  },
@@ -447,7 +464,8 @@ const SelectInput = createWithIntlProvider({
447
464
  isMobile,
448
465
  getPopupContainer,
449
466
  formatMessage,
450
- fixedModeClass
467
+ fixedModeClass,
468
+ mobileSheetZIndex
451
469
  } = contextProps;
452
470
  const {
453
471
  placeholder,
@@ -458,11 +476,16 @@ const SelectInput = createWithIntlProvider({
458
476
  if (isMobile && !disableMobileSheet) {
459
477
  const mountNode = typeof getPopupContainer === 'function' ? getPopupContainer() : null;
460
478
  const closeWithoutCommit = () => onOpenChange(false);
479
+ const {
480
+ maskZIndex,
481
+ panelZIndex
482
+ } = mobileSheetZIndex || resolveMobileSheetZIndex();
461
483
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MobileSheetMask, {
462
484
  open: open,
463
485
  mountNode: mountNode,
464
486
  fixedModeClass: fixedModeClass,
465
- onClose: closeWithoutCommit
487
+ onClose: closeWithoutCommit,
488
+ zIndex: maskZIndex
466
489
  }), /*#__PURE__*/React.createElement(MobileSheetPanel, {
467
490
  open: open,
468
491
  mountNode: mountNode,
@@ -479,14 +502,14 @@ const SelectInput = createWithIntlProvider({
479
502
  onConfirm: () => {
480
503
  onComplete();
481
504
  onOpenChange(false);
482
- }
505
+ },
506
+ zIndex: panelZIndex
483
507
  }, open ? children(contextProps) : null));
484
508
  }
485
509
  return /*#__PURE__*/React.createElement(Modal, {
486
510
  className: overlayClassName,
487
511
  width: 1000,
488
512
  open: open,
489
- destroyOnClose: true,
490
513
  destroyOnHidden: true,
491
514
  title: placeholder,
492
515
  onCancel: () => {
@@ -531,7 +554,6 @@ const SelectInput = createWithIntlProvider({
531
554
  size,
532
555
  disableMobileSheet
533
556
  } = props;
534
- const getPopupContainerDefault = usePopupContainer();
535
557
  const getScrollElement = useScrollElement();
536
558
  const wrapCustomGetPopupContainer = useMemo(() => {
537
559
  if (typeof getPopupContainerProp === 'function') {
@@ -545,12 +567,14 @@ const SelectInput = createWithIntlProvider({
545
567
  const {
546
568
  isMobile,
547
569
  fixedModeClass,
548
- getPopupContainer: getSheetPopupContainer,
570
+ getPopupContainer: resolveGetPopupContainer,
549
571
  anchorRef
550
- } = useMobilePopupMount({
572
+ } = usePopupMount({
551
573
  cover: 'viewport',
552
574
  getPopupContainer: wrapCustomGetPopupContainer
553
575
  });
576
+ const [antdPopupZIndex] = useZIndex('Dropdown');
577
+ const mobileSheetZIndex = useMemo(() => resolveMobileSheetZIndex(antdPopupZIndex), [antdPopupZIndex]);
554
578
  const useMobileSheet = isMobile && !disableMobileSheet;
555
579
  const useBoundaryMount = !!(isMobile && fixedModeClass === MOBILE_POPUP_MODE.boundary);
556
580
  const transformValue = value => {
@@ -607,20 +631,6 @@ const SelectInput = createWithIntlProvider({
607
631
  resizeRef.current = node;
608
632
  anchorRef(node);
609
633
  }, [anchorRef, resizeRef]);
610
- const resolveGetPopupContainer = useCallback(triggerNode => {
611
- if (typeof getPopupContainerProp === 'function') {
612
- const customContainer = getPopupContainerProp(triggerNode);
613
- if (customContainer) {
614
- return customContainer;
615
- }
616
- } else if (getPopupContainerProp) {
617
- return getPopupContainerProp;
618
- }
619
- if (useMobileSheet) {
620
- return getSheetPopupContainer(triggerNode);
621
- }
622
- return getPopupContainerDefault(triggerNode);
623
- }, [getPopupContainerDefault, getPopupContainerProp, getSheetPopupContainer, useMobileSheet]);
624
634
 
625
635
  // 打开时再取挂载节点,避免落到错误容器
626
636
  useLayoutEffect(() => {
@@ -722,6 +732,7 @@ const SelectInput = createWithIntlProvider({
722
732
  children,
723
733
  isMobile,
724
734
  useBoundaryMount,
735
+ mobileSheetZIndex,
725
736
  fixedModeClass,
726
737
  getPopupContainer: resolveGetPopupContainer,
727
738
  formatMessage
@@ -815,7 +826,8 @@ const SelectInput = createWithIntlProvider({
815
826
  open: sheetOpen,
816
827
  mountNode: popupMountNode,
817
828
  fixedModeClass: fixedModeClass,
818
- onClose: closeWithoutCommit
829
+ onClose: closeWithoutCommit,
830
+ zIndex: mobileSheetZIndex.maskZIndex
819
831
  }), /*#__PURE__*/React.createElement(MobileSheetPanel, {
820
832
  open: sheetOpen,
821
833
  mountNode: popupMountNode,
@@ -832,7 +844,8 @@ const SelectInput = createWithIntlProvider({
832
844
  onConfirm: () => {
833
845
  onComplete();
834
846
  setOpen(false);
835
- }
847
+ },
848
+ zIndex: mobileSheetZIndex.panelZIndex
836
849
  }, sheetOpen ? children(sheetContextProps) : null));
837
850
  }));
838
851
  }
@@ -853,16 +866,18 @@ const SelectInput = createWithIntlProvider({
853
866
  placement: placement,
854
867
  arrow: false,
855
868
  getPopupContainer: resolveGetPopupContainer,
856
- overlayClassName: classnames(style$6['overlay'], overlayClassName),
857
- overlayStyle: mergedOverlayStyle,
869
+ classNames: {
870
+ root: classnames(style$6['overlay'], overlayClassName)
871
+ },
872
+ styles: {
873
+ root: mergedOverlayStyle
874
+ },
858
875
  align: align,
859
876
  autoAdjustOverflow: autoAdjustOverflow,
860
877
  transitionName: transitionName,
861
878
  trigger: "click",
862
- destroyPopupOnHide: true,
863
879
  destroyOnHidden: true,
864
- popupRender: () => overlayContent,
865
- dropdownRender: () => overlayContent
880
+ popupRender: () => overlayContent
866
881
  }, /*#__PURE__*/React.createElement("span", null, inputInnerRender())) : /*#__PURE__*/React.createElement(React.Fragment, null, inputInnerRender({
867
882
  onClick: () => {
868
883
  setOpen(true);
@@ -953,7 +968,7 @@ const SelectedTagList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
953
968
  className: style$4['tag'],
954
969
  key: item[valueKey],
955
970
  closable: true,
956
- bordered: false,
971
+ variant: "filled",
957
972
  onClose: e => {
958
973
  e.preventDefault();
959
974
  onRemove(item);
@@ -1629,7 +1644,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1629
1644
  className: style$2['tag'],
1630
1645
  key: item[valueKey],
1631
1646
  closable: true,
1632
- bordered: false,
1647
+ variant: "filled",
1633
1648
  onClose: e => {
1634
1649
  e.preventDefault();
1635
1650
  onRemove(item);
@@ -2198,7 +2213,7 @@ const createTreeUtils = mapping => {
2198
2213
  };
2199
2214
  };
2200
2215
 
2201
- var style = {"kne-responsive-boundary":"kne-super-select_5gTKr","kne-responsive-scroll":"kne-super-select_fhAr5","content":"kne-super-select_fHNBt","columns":"kne-super-select_VgpIp","content-item":"kne-super-select_kSkN1","last-level-area":"kne-super-select_1QV-l","is-popup":"kne-super-select_zFwDF","menu":"kne-super-select_s-ON4","scroll-plus-box":"kne-super-select_rIix2","menu-label":"kne-super-select_XAs20","menu-label-text":"kne-super-select_Y8AoQ","menu-item":"kne-super-select_ZwakZ","checkbox-hidden":"kne-super-select_0FUoe","single-mode":"kne-super-select_dahnB","menu-item-icon":"kne-super-select_AZZvN","menu-item-placeholder":"kne-super-select_TudTj","loading":"kne-super-select_ljvZk","search-input":"kne-super-select_FVxuS","scroller":"kne-super-select_vnHAM","is-mobile":"kne-super-select_HjXMw","list":"kne-super-select_iUhv7","is-selected":"kne-super-select_tx4-l","custom-menu":"kne-super-select_OerpL","selected":"kne-super-select_OUkpN"};
2216
+ var style = {"kne-responsive-boundary":"kne-super-select_5gTKr","kne-responsive-scroll":"kne-super-select_fhAr5","content":"kne-super-select_fHNBt","columns":"kne-super-select_VgpIp","content-item":"kne-super-select_kSkN1","last-level-area":"kne-super-select_1QV-l","is-popup":"kne-super-select_zFwDF","menu":"kne-super-select_s-ON4","scroll-plus-box":"kne-super-select_rIix2","menu-label":"kne-super-select_XAs20","menu-label-text":"kne-super-select_Y8AoQ","menu-item":"kne-super-select_ZwakZ","checkbox-hidden":"kne-super-select_0FUoe","single-mode":"kne-super-select_dahnB","menu-item-icon":"kne-super-select_AZZvN","menu-item-placeholder":"kne-super-select_TudTj","loading":"kne-super-select_ljvZk","search-input":"kne-super-select_FVxuS","scroller":"kne-super-select_vnHAM","is-mobile":"kne-super-select_HjXMw","custom-menu":"kne-super-select_OerpL","list":"kne-super-select_iUhv7","is-selected":"kne-super-select_tx4-l","selected":"kne-super-select_OUkpN"};
2202
2217
 
2203
2218
  const CustomMenu = ({
2204
2219
  className,
@@ -2336,6 +2351,32 @@ const CascaderInner = ({
2336
2351
  prevOpenRef.current = open;
2337
2352
  }, [open, value, mapping, treeUtils, valueKey, isPopup]);
2338
2353
 
2354
+ // 移动端多列竖直堆叠:切换后子级列若完全不在可视区,滚动到子级列
2355
+ const scrollerRef = useRef(null);
2356
+ const columnsRef = useRef(null);
2357
+ const scrollToLevelRef = useRef(null);
2358
+ useEffect(() => {
2359
+ const level = scrollToLevelRef.current;
2360
+ const scroller = scrollerRef.current;
2361
+ if (!isMobile || level === null || !scroller || !columnsRef.current) {
2362
+ return;
2363
+ }
2364
+ const column = columnsRef.current.children[level];
2365
+ // 懒加载时子级列在数据返回后才渲染
2366
+ if (!column) {
2367
+ return;
2368
+ }
2369
+ scrollToLevelRef.current = null;
2370
+ const scrollerRect = scroller.getBoundingClientRect();
2371
+ const columnRect = column.getBoundingClientRect();
2372
+ if (columnRect.top >= scrollerRect.bottom || columnRect.bottom <= scrollerRect.top) {
2373
+ scroller.scrollTo({
2374
+ top: scroller.scrollTop + columnRect.top - scrollerRect.top,
2375
+ behavior: 'smooth'
2376
+ });
2377
+ }
2378
+ }, [selectedIds, mapping, isMobile]);
2379
+
2339
2380
  // 懒加载支持
2340
2381
  const loadMorePropsRef = useRef({});
2341
2382
  loadMorePropsRef.current = {
@@ -2500,11 +2541,14 @@ const CascaderInner = ({
2500
2541
  showSearchButton: !isPopup
2501
2542
  }), /*#__PURE__*/React.createElement(ScrollBox, _extends({
2502
2543
  className: classnames(style['scroller'], 'select-cascader-scroller')
2503
- }, isMobile ? {} : {
2544
+ }, isMobile ? {
2545
+ ref: scrollerRef
2546
+ } : {
2504
2547
  options: {
2505
2548
  autoHide: false
2506
2549
  }
2507
2550
  }), /*#__PURE__*/React.createElement("div", {
2551
+ ref: columnsRef,
2508
2552
  className: classnames(style['columns'], {
2509
2553
  [style['is-mobile']]: isMobile
2510
2554
  })
@@ -2584,6 +2628,7 @@ const CascaderInner = ({
2584
2628
  const node = mapping.get(key);
2585
2629
  if (!node) return;
2586
2630
  if (isNotLastNode(node.id)) {
2631
+ scrollToLevelRef.current = index + 1;
2587
2632
  setSelectedIds(treeUtils.getSelectedQueue(node.id));
2588
2633
  } else {
2589
2634
  const {