@kne/react-filter 1.0.9 → 1.0.11
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 +85 -49
- package/dist/index.css.map +1 -1
- package/dist/index.js +86 -42
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +82 -38
- package/dist/index.modern.js.map +1 -1
- package/package.json +1 -1
package/dist/index.modern.js
CHANGED
|
@@ -3,7 +3,7 @@ import { useContext as useContext$1, createContext, useEffect, useRef, useState,
|
|
|
3
3
|
import { Space, Row, Col, Tag, Button, Dropdown, Input, InputNumber, DatePicker, Flex, Select, App } from 'antd';
|
|
4
4
|
import { useIntl, createWithIntlProvider } from '@kne/react-intl';
|
|
5
5
|
import get from 'lodash/get';
|
|
6
|
-
import { useResponsiveContext, useMediaQuery, IS_MOBILE_QUERY, MOBILE_BREAKPOINT, useScrollElement, resetViewportCssVars, applyViewportCssVars,
|
|
6
|
+
import { useResponsiveContext, useMediaQuery, IS_MOBILE_QUERY, MOBILE_BREAKPOINT, useScrollElement, resetViewportCssVars, applyViewportCssVars, usePopupContainer } from '@kne/responsive-utils';
|
|
7
7
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
8
8
|
import { UpOutlined, DownOutlined } from '@ant-design/icons';
|
|
9
9
|
import clone from 'lodash/clone';
|
|
@@ -37,7 +37,7 @@ function _objectWithoutPropertiesLoose(r, e) {
|
|
|
37
37
|
return t;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
var style$1 = {"kne-responsive-boundary":"kne-react-filter_gh14z","kne-responsive-scroll":"kne-react-filter_Kfn6L","filter":"kne-react-filter_b3gMw","filter-item-icon":"kne-react-filter_e3V6h","filter-item-option-icon":"kne-react-filter_dLoYj","filter-title":"kne-react-filter_khFt2","filter-title-hidden":"kne-react-filter_j2mP1","ad-filter-title":"kne-react-filter_HptIY","ad-filter-line":"kne-react-filter_7Ob6-","filter-line":"kne-react-filter_Y9XTa","clean-btn":"kne-react-filter_CJ935","filter-item":"kne-react-filter_JpaMr","un-expand":"kne-react-filter_LfQME","ad-filter-selected":"kne-react-filter_pBsaE","filter-label":"kne-react-filter_Bx3s8","filter-line-nowrap":"kne-react-filter_Ccx24","filter-line-measure":"kne-react-filter_uMXzo","filter-item-wrap":"kne-react-filter_Co4Pg","option":"kne-react-filter_G1cRp","is-active":"kne-react-filter_Aab98","is-visited":"kne-react-filter_Ww12R","un-expand-shadow":"kne-react-filter_2ExqW","filter-item-label":"kne-react-filter_JAmeE","filter-item-field":"kne-react-filter_WvRvl","filter-drop-tag":"kne-react-filter_dG8rq","filter-list":"kne-react-filter_qlWu6","filter-list-scroll-wrap":"kne-react-filter_oaIF4","filter-list-constrained":"kne-react-filter_3gXxO","filter-list-scroll":"kne-react-filter_Jq43Q","filter-scroll-next":"kne-react-filter_BdfSI","filter-list-tag":"kne-react-filter_LV2VI","filter-tag":"kne-react-filter_yyR3u","filter-tag-value":"kne-react-filter_8nm8n","filter-value-tag":"kne-react-filter_tWyCr","filter-value-tag-label":"kne-react-filter_XPzrL","filter-value-tag-content":"kne-react-filter_6e79l","filter-value-display-content":"kne-react-filter_v2dnw","filter-value-display":"kne-react-filter_8-R34","is-hide-label":"kne-react-filter_zpGJE","is-flush":"kne-react-filter_z8bDM","filter-value-tags-wrap":"kne-react-filter_J1wBU","filter-value-tags":"kne-react-filter_rRhFE","filter-value-actions":"kne-react-filter_-Brt9","filter-value-toggle":"kne-react-filter_WuL0c","pop-util-content":"kne-react-filter_g-hXk","pop-util-body":"kne-react-filter_4n4MP","date-range-picker-popup":"kne-react-filter_6Zx60","pop-util-overlay":"kne-react-filter_m7Csi","
|
|
40
|
+
var style$1 = {"kne-responsive-boundary":"kne-react-filter_gh14z","kne-responsive-scroll":"kne-react-filter_Kfn6L","filter":"kne-react-filter_b3gMw","filter-item-icon":"kne-react-filter_e3V6h","filter-item-option-icon":"kne-react-filter_dLoYj","filter-title":"kne-react-filter_khFt2","filter-title-hidden":"kne-react-filter_j2mP1","ad-filter-title":"kne-react-filter_HptIY","ad-filter-line":"kne-react-filter_7Ob6-","filter-line":"kne-react-filter_Y9XTa","clean-btn":"kne-react-filter_CJ935","filter-item":"kne-react-filter_JpaMr","un-expand":"kne-react-filter_LfQME","ad-filter-selected":"kne-react-filter_pBsaE","filter-label":"kne-react-filter_Bx3s8","filter-line-nowrap":"kne-react-filter_Ccx24","filter-line-measure":"kne-react-filter_uMXzo","filter-item-wrap":"kne-react-filter_Co4Pg","option":"kne-react-filter_G1cRp","is-active":"kne-react-filter_Aab98","is-visited":"kne-react-filter_Ww12R","un-expand-shadow":"kne-react-filter_2ExqW","filter-item-label":"kne-react-filter_JAmeE","filter-item-field":"kne-react-filter_WvRvl","filter-drop-tag":"kne-react-filter_dG8rq","filter-list":"kne-react-filter_qlWu6","filter-list-scroll-wrap":"kne-react-filter_oaIF4","filter-list-constrained":"kne-react-filter_3gXxO","filter-list-scroll":"kne-react-filter_Jq43Q","filter-scroll-prev":"kne-react-filter_Punga","filter-scroll-next":"kne-react-filter_BdfSI","filter-list-tag":"kne-react-filter_LV2VI","filter-tag":"kne-react-filter_yyR3u","filter-tag-value":"kne-react-filter_8nm8n","filter-value-tag":"kne-react-filter_tWyCr","filter-value-tag-label":"kne-react-filter_XPzrL","filter-value-tag-content":"kne-react-filter_6e79l","filter-value-display-content":"kne-react-filter_v2dnw","filter-value-display":"kne-react-filter_8-R34","is-hide-label":"kne-react-filter_zpGJE","is-flush":"kne-react-filter_z8bDM","filter-value-tags-wrap":"kne-react-filter_J1wBU","filter-value-tags":"kne-react-filter_rRhFE","filter-value-actions":"kne-react-filter_-Brt9","filter-value-toggle":"kne-react-filter_WuL0c","pop-util-content":"kne-react-filter_g-hXk","pop-util-body":"kne-react-filter_4n4MP","date-range-picker-popup":"kne-react-filter_6Zx60","pop-util-overlay":"kne-react-filter_m7Csi","is-viewport":"kne-react-filter_3Wr-x","is-boundary":"kne-react-filter_pPiQ8","pop-util-footer":"kne-react-filter_iqe8W","pop-util-mask":"kne-react-filter_o2B3k","pop-util-mask-fade-in":"kne-react-filter_oCXiX","pop-util-mask-leave":"kne-react-filter_qGnRO","pop-util-mask-fade-out":"kne-react-filter_cDx1y","field-item-mobile-popup":"kne-react-filter_wq5nf","pop-util-mobile-expand-down":"kne-react-filter_6RxjE","date-picker-popup":"kne-react-filter_iwLs2","pop-util-mobile-collapse-up":"kne-react-filter_009r-","pop-util-text":"kne-react-filter_72gGQ","filter-item-inner":"kne-react-filter_cYX12","filter-item-text":"kne-react-filter_cnMY-","filter-item-number-range":"kne-react-filter_Cv2Bw","filter-item-custom":"kne-react-filter_CBczA","filter-item-custom-active":"kne-react-filter_ldxUR","filter-item-number-range-split":"kne-react-filter_4p3C9","filter-item-number-input":"kne-react-filter_yy1y1","range-picker":"kne-react-filter_81zQn","cascader-select-wrap":"kne-react-filter_UHBfi","cascader-dropdown-menu":"kne-react-filter_bY8JQ","filter-advanced":"kne-react-filter_rg45N","filter-advanced-item-other":"kne-react-filter_HcsA8","filter-advanced-item-other-inner":"kne-react-filter_4Bqtz","filter-advanced-more":"kne-react-filter_jVH7z","is-mobile":"kne-react-filter_LtgJz","is-not-overflow":"kne-react-filter_TM1E2","is-expand":"kne-react-filter_7aclr","filter-value-scroll-prev-shadow":"kne-react-filter_C1t-q","filter-value-scroll-next-shadow":"kne-react-filter_ZFoeL","is-overflow":"kne-react-filter_GhFCl","filter-value-action-placeholder":"kne-react-filter_wGZp6","filter-value-action-right":"kne-react-filter_vyPwo","filter-scroll-prev-shadow":"kne-react-filter_fyhz3","filter-scroll-prev-icon":"kne-react-filter_B3jzr","filter-scroll-next-icon":"kne-react-filter_Fd6ab"};
|
|
41
41
|
|
|
42
42
|
const context = /*#__PURE__*/createContext({});
|
|
43
43
|
const {
|
|
@@ -485,6 +485,14 @@ const FilterLines = ({
|
|
|
485
485
|
behavior: 'smooth'
|
|
486
486
|
});
|
|
487
487
|
}, [scrollRef]);
|
|
488
|
+
const scrollToPrev = useCallback(() => {
|
|
489
|
+
const el = scrollRef.current;
|
|
490
|
+
if (!el) return;
|
|
491
|
+
el.scrollTo({
|
|
492
|
+
left: Math.max(el.scrollLeft - el.clientWidth * 0.8, 0),
|
|
493
|
+
behavior: 'smooth'
|
|
494
|
+
});
|
|
495
|
+
}, [scrollRef]);
|
|
488
496
|
const scrollItemIntoView = useCallback(e => {
|
|
489
497
|
if (!isMobile) return;
|
|
490
498
|
const container = scrollRef.current;
|
|
@@ -593,8 +601,15 @@ const FilterLines = ({
|
|
|
593
601
|
children: moreButtonLabel
|
|
594
602
|
})
|
|
595
603
|
})]
|
|
596
|
-
}) : null, isMobile && showScrollPrev ? /*#__PURE__*/jsx("
|
|
597
|
-
|
|
604
|
+
}) : null, isMobile && showScrollPrev ? /*#__PURE__*/jsx("button", {
|
|
605
|
+
type: "button",
|
|
606
|
+
className: style$1['filter-scroll-prev'],
|
|
607
|
+
onClick: scrollToPrev,
|
|
608
|
+
"aria-label": "scroll prev",
|
|
609
|
+
children: /*#__PURE__*/jsx("span", {
|
|
610
|
+
className: style$1['filter-scroll-prev-icon'],
|
|
611
|
+
children: "\u2039"
|
|
612
|
+
})
|
|
598
613
|
}) : null, /*#__PURE__*/jsx("div", {
|
|
599
614
|
className: style$1['filter-list-scroll'],
|
|
600
615
|
ref: setScrollContainerRef,
|
|
@@ -919,7 +934,7 @@ const FilterOuter = _ref => {
|
|
|
919
934
|
return /*#__PURE__*/jsx(FilterProvider, _extends({}, props, {
|
|
920
935
|
children: context => /*#__PURE__*/jsx("div", {
|
|
921
936
|
ref: boundaryRef,
|
|
922
|
-
className: classnames(style$1['filter'], 'filter',
|
|
937
|
+
className: classnames(style$1['filter'], 'filter', isMobile && style$1['is-mobile'], className),
|
|
923
938
|
children: children(_extends({}, context, {
|
|
924
939
|
props
|
|
925
940
|
}))
|
|
@@ -975,6 +990,43 @@ const useMobileFixedMode = () => {
|
|
|
975
990
|
};
|
|
976
991
|
};
|
|
977
992
|
|
|
993
|
+
/**
|
|
994
|
+
* Filter Item 弹窗挂载(不使用 RESPONSIVE_BOUNDARY_CLASS,避免劫持全局 pop):
|
|
995
|
+
* - useBoundaryMount(example container / 手机预览):ResponsiveProvider 的 boundary
|
|
996
|
+
* - 真实移动端 viewport:document.body
|
|
997
|
+
* - 桌面端:页面级 boundary(usePopupContainer)
|
|
998
|
+
*/
|
|
999
|
+
const resolveFilterPopupContainer = ({
|
|
1000
|
+
isMobile,
|
|
1001
|
+
useBoundaryMount,
|
|
1002
|
+
getBoundaryElement
|
|
1003
|
+
}) => {
|
|
1004
|
+
if (!isMobile || useBoundaryMount) {
|
|
1005
|
+
return typeof getBoundaryElement === 'function' ? getBoundaryElement() : null;
|
|
1006
|
+
}
|
|
1007
|
+
return typeof document !== 'undefined' ? document.body : null;
|
|
1008
|
+
};
|
|
1009
|
+
|
|
1010
|
+
const useFilterPopupContainer = () => {
|
|
1011
|
+
const getBoundaryElement = usePopupContainer();
|
|
1012
|
+
const {
|
|
1013
|
+
isMobile,
|
|
1014
|
+
useBoundaryMount
|
|
1015
|
+
} = useMobileFixedMode();
|
|
1016
|
+
const getMountNode = useCallback(() => resolveFilterPopupContainer({
|
|
1017
|
+
isMobile,
|
|
1018
|
+
useBoundaryMount,
|
|
1019
|
+
getBoundaryElement
|
|
1020
|
+
}), [getBoundaryElement, isMobile, useBoundaryMount]);
|
|
1021
|
+
const getPopupContainer = useCallback(() => getMountNode(), [getMountNode]);
|
|
1022
|
+
return {
|
|
1023
|
+
isMobile,
|
|
1024
|
+
useBoundaryMount,
|
|
1025
|
+
getMountNode,
|
|
1026
|
+
getPopupContainer
|
|
1027
|
+
};
|
|
1028
|
+
};
|
|
1029
|
+
|
|
978
1030
|
const FilterItem = withLocale(({
|
|
979
1031
|
open,
|
|
980
1032
|
active,
|
|
@@ -1069,8 +1121,10 @@ const withFieldItem = (WrappedComponent, options = {}) => _ref => {
|
|
|
1069
1121
|
const [open, setOpen] = useState(false);
|
|
1070
1122
|
const {
|
|
1071
1123
|
isMobile,
|
|
1072
|
-
useBoundaryMount
|
|
1073
|
-
|
|
1124
|
+
useBoundaryMount,
|
|
1125
|
+
getMountNode,
|
|
1126
|
+
getPopupContainer
|
|
1127
|
+
} = useFilterPopupContainer();
|
|
1074
1128
|
const fixedModeClass = useBoundaryMount ? style$1['is-boundary'] : style$1['is-viewport'];
|
|
1075
1129
|
const [renderMask, setRenderMask] = useState(false);
|
|
1076
1130
|
const [maskClosing, setMaskClosing] = useState(false);
|
|
@@ -1080,7 +1134,6 @@ const withFieldItem = (WrappedComponent, options = {}) => _ref => {
|
|
|
1080
1134
|
height: 0
|
|
1081
1135
|
});
|
|
1082
1136
|
const triggerRef = useRef(null);
|
|
1083
|
-
const getBoundaryElement = usePopupContainer();
|
|
1084
1137
|
const getScrollElement = useScrollElement();
|
|
1085
1138
|
const resolveGetPopupContainer = useCallback(triggerNode => {
|
|
1086
1139
|
if (typeof props.getPopupContainer === 'function') {
|
|
@@ -1089,15 +1142,9 @@ const withFieldItem = (WrappedComponent, options = {}) => _ref => {
|
|
|
1089
1142
|
return customContainer;
|
|
1090
1143
|
}
|
|
1091
1144
|
}
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
if (useBoundaryMount) {
|
|
1096
|
-
return getBoundaryElement();
|
|
1097
|
-
}
|
|
1098
|
-
return typeof document !== 'undefined' ? document.body : null;
|
|
1099
|
-
}, [getBoundaryElement, isMobile, props.getPopupContainer, useBoundaryMount]);
|
|
1100
|
-
const popupMountNode = typeof document !== 'undefined' ? isMobile ? useBoundaryMount ? getBoundaryElement() || document.body : document.body : getBoundaryElement() || document.body : null;
|
|
1145
|
+
return getPopupContainer(triggerNode);
|
|
1146
|
+
}, [getPopupContainer, props.getPopupContainer]);
|
|
1147
|
+
const popupMountNode = typeof document !== 'undefined' ? getMountNode() || document.body : null;
|
|
1101
1148
|
const setMobilePopupVariables = useCallback(metrics => {
|
|
1102
1149
|
if (typeof document === 'undefined') return;
|
|
1103
1150
|
document.body.style.setProperty('--react-filter-field-mobile-height', `${metrics.height}px`);
|
|
@@ -1108,13 +1155,13 @@ const withFieldItem = (WrappedComponent, options = {}) => _ref => {
|
|
|
1108
1155
|
if (typeof window === 'undefined' || !triggerRef.current) return;
|
|
1109
1156
|
const metrics = getMobilePopupMetrics(triggerRef.current, {
|
|
1110
1157
|
scrollEl: getScrollElement(),
|
|
1111
|
-
boundaryEl:
|
|
1158
|
+
boundaryEl: getMountNode(),
|
|
1112
1159
|
useBoundaryMount,
|
|
1113
1160
|
offset: MOBILE_POPUP_OFFSET$1
|
|
1114
1161
|
});
|
|
1115
1162
|
setPopupMetrics(metrics);
|
|
1116
1163
|
setMobilePopupVariables(metrics);
|
|
1117
|
-
}, [
|
|
1164
|
+
}, [getMountNode, getScrollElement, setMobilePopupVariables, useBoundaryMount]);
|
|
1118
1165
|
useResponsiveScrollListener(updatePopupMetrics, open && isMobile);
|
|
1119
1166
|
useEffect(() => {
|
|
1120
1167
|
if (typeof document === 'undefined' || !isMobile || popupMetrics.height <= 0) return;
|
|
@@ -1210,7 +1257,7 @@ const withFieldItem = (WrappedComponent, options = {}) => _ref => {
|
|
|
1210
1257
|
zIndex: isMobile ? MOBILE_POPUP_Z_INDEX : props.zIndex,
|
|
1211
1258
|
overlayWidth: isMobile && options.forcePopup ? typeof window === 'undefined' ? props.overlayWidth : getMobilePopupMetrics(triggerRef.current, {
|
|
1212
1259
|
scrollEl: getScrollElement(),
|
|
1213
|
-
boundaryEl:
|
|
1260
|
+
boundaryEl: getMountNode(),
|
|
1214
1261
|
useBoundaryMount
|
|
1215
1262
|
}).width || window.innerWidth : props.overlayWidth
|
|
1216
1263
|
}));
|
|
@@ -1265,10 +1312,11 @@ const PopoverItem = withLocale(({
|
|
|
1265
1312
|
const [open, setOpen] = useState(false);
|
|
1266
1313
|
const {
|
|
1267
1314
|
isMobile,
|
|
1268
|
-
useBoundaryMount
|
|
1269
|
-
|
|
1315
|
+
useBoundaryMount,
|
|
1316
|
+
getMountNode,
|
|
1317
|
+
getPopupContainer
|
|
1318
|
+
} = useFilterPopupContainer();
|
|
1270
1319
|
const fixedModeClass = useBoundaryMount ? style$1['is-boundary'] : style$1['is-viewport'];
|
|
1271
|
-
const getBoundaryElement = usePopupContainer();
|
|
1272
1320
|
const getScrollElement = useScrollElement();
|
|
1273
1321
|
const resolveGetPopupContainer = useCallback(triggerNode => {
|
|
1274
1322
|
if (typeof customGetPopupContainer === 'function') {
|
|
@@ -1277,15 +1325,8 @@ const PopoverItem = withLocale(({
|
|
|
1277
1325
|
return customContainer;
|
|
1278
1326
|
}
|
|
1279
1327
|
}
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
}
|
|
1283
|
-
if (useBoundaryMount) {
|
|
1284
|
-
return getBoundaryElement();
|
|
1285
|
-
}
|
|
1286
|
-
return typeof document !== 'undefined' ? document.body : null;
|
|
1287
|
-
}, [customGetPopupContainer, getBoundaryElement, isMobile, useBoundaryMount]);
|
|
1288
|
-
const popupMountNode = typeof document !== 'undefined' ? isMobile ? useBoundaryMount ? getBoundaryElement() || document.body : document.body : getBoundaryElement() || document.body : null;
|
|
1328
|
+
return getPopupContainer(triggerNode);
|
|
1329
|
+
}, [customGetPopupContainer, getPopupContainer]);
|
|
1289
1330
|
const [renderMask, setRenderMask] = useState(false);
|
|
1290
1331
|
const [maskClosing, setMaskClosing] = useState(false);
|
|
1291
1332
|
const [popupMetrics, setPopupMetrics] = useState({
|
|
@@ -1294,6 +1335,7 @@ const PopoverItem = withLocale(({
|
|
|
1294
1335
|
height: 0
|
|
1295
1336
|
});
|
|
1296
1337
|
const triggerRef = useRef(null);
|
|
1338
|
+
const popupMountNode = typeof document !== 'undefined' ? getMountNode() || document.body : null;
|
|
1297
1339
|
const disabled = useMemo(() => {
|
|
1298
1340
|
return onValidate && !onValidate(state);
|
|
1299
1341
|
}, [onValidate, state]);
|
|
@@ -1306,12 +1348,12 @@ const PopoverItem = withLocale(({
|
|
|
1306
1348
|
if (typeof window === 'undefined' || !triggerRef.current) return;
|
|
1307
1349
|
const metrics = getMobilePopupMetrics(triggerRef.current, {
|
|
1308
1350
|
scrollEl: getScrollElement(),
|
|
1309
|
-
boundaryEl:
|
|
1351
|
+
boundaryEl: getMountNode(),
|
|
1310
1352
|
useBoundaryMount,
|
|
1311
1353
|
offset: MOBILE_POPUP_OFFSET
|
|
1312
1354
|
});
|
|
1313
1355
|
setPopupMetrics(metrics);
|
|
1314
|
-
}, [
|
|
1356
|
+
}, [getMountNode, getScrollElement, useBoundaryMount]);
|
|
1315
1357
|
useResponsiveScrollListener(updatePopupMetrics, open && isMobile);
|
|
1316
1358
|
useEffect(() => {
|
|
1317
1359
|
if (open && isMobile) {
|
|
@@ -1658,11 +1700,11 @@ const TypeDateRangePickerField = _ref => {
|
|
|
1658
1700
|
} = useIntl({
|
|
1659
1701
|
moduleName: 'Filter'
|
|
1660
1702
|
});
|
|
1661
|
-
const getPopupContainer = usePopupContainer();
|
|
1662
1703
|
const {
|
|
1663
1704
|
isMobile,
|
|
1664
|
-
useBoundaryMount
|
|
1665
|
-
|
|
1705
|
+
useBoundaryMount,
|
|
1706
|
+
getPopupContainer
|
|
1707
|
+
} = useFilterPopupContainer();
|
|
1666
1708
|
const fixedModeClass = useBoundaryMount ? style['is-boundary'] : style['is-viewport'];
|
|
1667
1709
|
const nestedPopupClassName = classnames(style['field-item-mobile-popup'], FIELD_MOBILE_POPUP_CLASS, fixedModeClass);
|
|
1668
1710
|
const nestedPopupStyle = isMobile ? {
|
|
@@ -2761,7 +2803,9 @@ const CityFilterItemInner = _ref => {
|
|
|
2761
2803
|
const {
|
|
2762
2804
|
message
|
|
2763
2805
|
} = App.useApp();
|
|
2764
|
-
const
|
|
2806
|
+
const {
|
|
2807
|
+
getPopupContainer
|
|
2808
|
+
} = useFilterPopupContainer();
|
|
2765
2809
|
const {
|
|
2766
2810
|
locale
|
|
2767
2811
|
} = useIntl();
|