@kne/super-select 0.1.40 → 0.1.41
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.css +4 -4
- package/dist/index.js +51 -53
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +39 -39
- package/dist/index.modern.js.map +1 -1
- package/package.json +3 -3
package/dist/index.modern.js
CHANGED
|
@@ -9,7 +9,7 @@ import last from 'lodash/last';
|
|
|
9
9
|
import { Tag, Modal, App, Dropdown, Flex, Checkbox, List, Empty, Row, Col, Button, Popover, Tree, Space, Badge, Spin } from 'antd';
|
|
10
10
|
import { CloseCircleFilled, DownOutlined, CheckOutlined, RightOutlined } from '@ant-design/icons';
|
|
11
11
|
import { isNotEmpty } from '@kne/is-empty';
|
|
12
|
-
import {
|
|
12
|
+
import { usePopupContainer, useScrollElement, useMobilePopupMount, MOBILE_POPUP_MODE } from '@kne/responsive-utils';
|
|
13
13
|
import { createWithIntlProvider, useIntl } from '@kne/react-intl';
|
|
14
14
|
import 'simplebar-react/dist/simplebar.min.css';
|
|
15
15
|
import get from 'lodash/get';
|
|
@@ -50,7 +50,7 @@ const {
|
|
|
50
50
|
useContext
|
|
51
51
|
} = context;
|
|
52
52
|
|
|
53
|
-
var style$6 = {"kne-responsive-boundary":"kne-super-select_mJpBa","kne-responsive-scroll":"kne-super-select_90VCi","select-input":"kne-super-select_d8lGc","disabled":"kne-super-select_3kjwO","wrap":"kne-super-select_dsTM2","select-input-inner":"kne-super-select_NQoX9","large":"kne-super-select_T8ZX8","small":"kne-super-select_1B72H","is-mobile":"kne-super-select_VoUSp","single-label":"kne-super-select_pL0tE","tag-item":"kne-super-select_lc4o7","tag-label":"kne-super-select_RJmlD","overflow-tag":"kne-super-select_aHua2","measure-layer":"kne-super-select_QoQpC","select-input-icon":"kne-super-select_g8QC-","placeholder":"kne-super-select_r3q69","overlay-content":"kne-super-select_zEqGe","mobile-sheet-body":"kne-super-select_Gmh-5","overlay":"kne-super-select_ybN30","select-input-prefix":"kne-super-select_4Pw75","select-input-suffix":"kne-super-select_Wd4pE","mobile-sheet-mask":"kne-super-select_EOKDm","mobile-sheet-mask-fade-in":"kne-super-select_tWTg9","
|
|
53
|
+
var style$6 = {"kne-responsive-boundary":"kne-super-select_mJpBa","kne-responsive-scroll":"kne-super-select_90VCi","select-input":"kne-super-select_d8lGc","disabled":"kne-super-select_3kjwO","wrap":"kne-super-select_dsTM2","select-input-inner":"kne-super-select_NQoX9","large":"kne-super-select_T8ZX8","small":"kne-super-select_1B72H","is-mobile":"kne-super-select_VoUSp","single-label":"kne-super-select_pL0tE","tag-item":"kne-super-select_lc4o7","tag-label":"kne-super-select_RJmlD","overflow-tag":"kne-super-select_aHua2","measure-layer":"kne-super-select_QoQpC","select-input-icon":"kne-super-select_g8QC-","placeholder":"kne-super-select_r3q69","overlay-content":"kne-super-select_zEqGe","mobile-sheet-body":"kne-super-select_Gmh-5","overlay":"kne-super-select_ybN30","select-input-prefix":"kne-super-select_4Pw75","select-input-suffix":"kne-super-select_Wd4pE","mobile-sheet-mask":"kne-super-select_EOKDm","mobile-sheet-mask-fade-in":"kne-super-select_tWTg9","mobile-sheet-mask-leave":"kne-super-select_UAU38","mobile-sheet-mask-fade-out":"kne-super-select_e3tK2","mobile-sheet-popup":"kne-super-select_x0gT0","mobile-sheet-portal":"kne-super-select_kuA7x","mobile-sheet-header":"kne-super-select_EqRnq","mobile-sheet-title":"kne-super-select_5DU3x","mobile-sheet-action":"kne-super-select_UMAVM","mobile-sheet-confirm":"kne-super-select_Y48cj"};
|
|
54
54
|
|
|
55
55
|
const locale$1 = {
|
|
56
56
|
placeholder: '请选择',
|
|
@@ -174,15 +174,6 @@ const MOBILE_SHEET_MIN_HEIGHT = '30%';
|
|
|
174
174
|
const MOBILE_MASK_Z_INDEX = 1000;
|
|
175
175
|
const MOBILE_POPUP_Z_INDEX = 1050;
|
|
176
176
|
const MASK_ANIMATION_DURATION = 180;
|
|
177
|
-
// example-driver 手机预览外框(container 模式可能被外层 Global 的 viewport Provider 盖掉)
|
|
178
|
-
const EXAMPLE_PHONE_SCROLL_SELECTOR = '.example-driver-device-scroll';
|
|
179
|
-
const EXAMPLE_BOUNDARY_SELECTOR = '.kne-responsive-boundary';
|
|
180
|
-
const findExamplePhoneMountNode = anchor => {
|
|
181
|
-
if (!anchor || typeof anchor.closest !== 'function') {
|
|
182
|
-
return null;
|
|
183
|
-
}
|
|
184
|
-
return anchor.closest(EXAMPLE_PHONE_SCROLL_SELECTOR) || anchor.closest(EXAMPLE_BOUNDARY_SELECTOR);
|
|
185
|
-
};
|
|
186
177
|
let parentScrollLockCount = 0;
|
|
187
178
|
let parentScrollLocked = [];
|
|
188
179
|
const lockParentScroll = getScrollElements => {
|
|
@@ -440,7 +431,7 @@ const SelectInput = createWithIntlProvider({
|
|
|
440
431
|
isMobile,
|
|
441
432
|
getPopupContainer,
|
|
442
433
|
formatMessage,
|
|
443
|
-
|
|
434
|
+
fixedModeClass
|
|
444
435
|
} = contextProps;
|
|
445
436
|
const {
|
|
446
437
|
placeholder,
|
|
@@ -449,7 +440,6 @@ const SelectInput = createWithIntlProvider({
|
|
|
449
440
|
disableMobileSheet
|
|
450
441
|
} = props;
|
|
451
442
|
if (isMobile && !disableMobileSheet) {
|
|
452
|
-
const fixedModeClass = useBoundaryMount ? style$6['is-boundary'] : style$6['is-viewport'];
|
|
453
443
|
const mountNode = typeof getPopupContainer === 'function' ? getPopupContainer() : null;
|
|
454
444
|
const closeWithoutCommit = () => onOpenChange(false);
|
|
455
445
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MobileSheetMask, {
|
|
@@ -523,18 +513,28 @@ const SelectInput = createWithIntlProvider({
|
|
|
523
513
|
size,
|
|
524
514
|
disableMobileSheet
|
|
525
515
|
} = props;
|
|
526
|
-
const isMobileContext = useIsMobile();
|
|
527
|
-
const {
|
|
528
|
-
mode
|
|
529
|
-
} = useResponsiveContext();
|
|
530
516
|
const getPopupContainerDefault = usePopupContainer();
|
|
531
517
|
const getScrollElement = useScrollElement();
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
518
|
+
const wrapCustomGetPopupContainer = useMemo(() => {
|
|
519
|
+
if (typeof getPopupContainerProp === 'function') {
|
|
520
|
+
return triggerNode => getPopupContainerProp(triggerNode) || null;
|
|
521
|
+
}
|
|
522
|
+
if (getPopupContainerProp) {
|
|
523
|
+
return () => getPopupContainerProp;
|
|
524
|
+
}
|
|
525
|
+
return undefined;
|
|
526
|
+
}, [getPopupContainerProp]);
|
|
527
|
+
const {
|
|
528
|
+
isMobile,
|
|
529
|
+
fixedModeClass,
|
|
530
|
+
getPopupContainer: getSheetPopupContainer,
|
|
531
|
+
anchorRef
|
|
532
|
+
} = useMobilePopupMount({
|
|
533
|
+
cover: 'viewport',
|
|
534
|
+
getPopupContainer: wrapCustomGetPopupContainer
|
|
535
|
+
});
|
|
535
536
|
const useMobileSheet = isMobile && !disableMobileSheet;
|
|
536
|
-
const useBoundaryMount =
|
|
537
|
-
const fixedModeClass = useBoundaryMount ? style$6['is-boundary'] : style$6['is-viewport'];
|
|
537
|
+
const useBoundaryMount = !!(isMobile && fixedModeClass === MOBILE_POPUP_MODE.boundary);
|
|
538
538
|
const mergedOverlayStyle = useMemo(() => {
|
|
539
539
|
return Object.assign({}, overlayStyle, zIndex != null ? {
|
|
540
540
|
zIndex
|
|
@@ -574,51 +574,50 @@ const SelectInput = createWithIntlProvider({
|
|
|
574
574
|
setContainerWidth(containerWidth);
|
|
575
575
|
const innerEl = el.querySelector('.select-input-inner');
|
|
576
576
|
setInnerWidth(innerEl.clientWidth);
|
|
577
|
-
setInExamplePhoneFrame(!!findExamplePhoneMountNode(el));
|
|
578
577
|
};
|
|
579
578
|
const popupOverlayWidth = useMemo(() => {
|
|
580
579
|
return numberToPx$1(Math.max(containerWidth, pxToNumber(overlayWidth)));
|
|
581
580
|
}, [containerWidth, overlayWidth]);
|
|
582
|
-
const
|
|
581
|
+
const resizeRef = useResize(containerWidthChange);
|
|
582
|
+
const setContainerRef = useCallback(node => {
|
|
583
|
+
resizeRef.current = node;
|
|
584
|
+
anchorRef(node);
|
|
585
|
+
}, [anchorRef, resizeRef]);
|
|
583
586
|
const resolveGetPopupContainer = useCallback(triggerNode => {
|
|
584
587
|
if (typeof getPopupContainerProp === 'function') {
|
|
585
588
|
const customContainer = getPopupContainerProp(triggerNode);
|
|
586
589
|
if (customContainer) {
|
|
587
590
|
return customContainer;
|
|
588
591
|
}
|
|
592
|
+
} else if (getPopupContainerProp) {
|
|
593
|
+
return getPopupContainerProp;
|
|
589
594
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
return exampleMount;
|
|
593
|
-
}
|
|
594
|
-
if (useMobileSheet && !useBoundaryMount && typeof document !== 'undefined') {
|
|
595
|
-
return document.body;
|
|
595
|
+
if (useMobileSheet) {
|
|
596
|
+
return getSheetPopupContainer(triggerNode);
|
|
596
597
|
}
|
|
597
598
|
return getPopupContainerDefault(triggerNode);
|
|
598
|
-
}, [getPopupContainerDefault, getPopupContainerProp,
|
|
599
|
+
}, [getPopupContainerDefault, getPopupContainerProp, getSheetPopupContainer, useMobileSheet]);
|
|
599
600
|
|
|
600
|
-
//
|
|
601
|
+
// 打开时再取挂载节点,避免落到错误容器
|
|
601
602
|
useLayoutEffect(() => {
|
|
602
|
-
const exampleMount = findExamplePhoneMountNode(containerRef.current);
|
|
603
|
-
setInExamplePhoneFrame(!!exampleMount);
|
|
604
603
|
if (!useMobileSheet) {
|
|
605
604
|
setPopupMountNode(null);
|
|
606
605
|
return;
|
|
607
606
|
}
|
|
608
|
-
setPopupMountNode(resolveGetPopupContainer(
|
|
609
|
-
}, [useMobileSheet, resolveGetPopupContainer, open,
|
|
607
|
+
setPopupMountNode(resolveGetPopupContainer(resizeRef.current) || (typeof document !== 'undefined' ? document.body : null));
|
|
608
|
+
}, [useMobileSheet, resolveGetPopupContainer, open, resizeRef]);
|
|
610
609
|
const getLockScrollTargets = useCallback(() => {
|
|
611
610
|
const targets = [];
|
|
612
611
|
const scrollEl = typeof getScrollElement === 'function' ? getScrollElement() : null;
|
|
613
612
|
if (scrollEl) {
|
|
614
613
|
targets.push(scrollEl);
|
|
615
614
|
}
|
|
616
|
-
const mountNode = popupMountNode
|
|
615
|
+
const mountNode = popupMountNode;
|
|
617
616
|
if (mountNode && mountNode !== document.body) {
|
|
618
617
|
targets.push(mountNode);
|
|
619
618
|
}
|
|
620
619
|
return targets;
|
|
621
|
-
}, [getScrollElement, popupMountNode
|
|
620
|
+
}, [getScrollElement, popupMountNode]);
|
|
622
621
|
const sheetOpen = !disabled && open;
|
|
623
622
|
useLockParentScroll(useMobileSheet && sheetOpen, getLockScrollTargets);
|
|
624
623
|
const {
|
|
@@ -692,6 +691,7 @@ const SelectInput = createWithIntlProvider({
|
|
|
692
691
|
children,
|
|
693
692
|
isMobile,
|
|
694
693
|
useBoundaryMount,
|
|
694
|
+
fixedModeClass,
|
|
695
695
|
getPopupContainer: resolveGetPopupContainer,
|
|
696
696
|
formatMessage
|
|
697
697
|
};
|
|
@@ -700,7 +700,7 @@ const SelectInput = createWithIntlProvider({
|
|
|
700
700
|
return contextProps.props.inputRender(props, contextProps);
|
|
701
701
|
}
|
|
702
702
|
return /*#__PURE__*/React.createElement(Flex, _extends({}, props, {
|
|
703
|
-
ref:
|
|
703
|
+
ref: setContainerRef,
|
|
704
704
|
className: classnames(className, style$6['select-input'], 'select-input', {
|
|
705
705
|
[style$6['wrap']]: labelWrap,
|
|
706
706
|
[style$6['disabled']]: disabled,
|