@kne/super-select 0.1.49 → 0.1.51
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/README.md +68 -16
- package/dist/index.css +0 -1
- package/dist/index.css.map +1 -1
- package/dist/index.js +194 -85
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +294 -185
- package/dist/index.modern.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var React
|
|
1
|
+
var React = require('react');
|
|
2
2
|
var reactDom = require('react-dom');
|
|
3
3
|
var globalContext = require('@kne/global-context');
|
|
4
4
|
var useResize = require('@kne/use-resize');
|
|
@@ -7,6 +7,7 @@ var classnames = require('classnames');
|
|
|
7
7
|
var isEqual = require('lodash/isEqual');
|
|
8
8
|
var last = require('lodash/last');
|
|
9
9
|
var antd = require('antd');
|
|
10
|
+
var hooks = require('antd/es/_util/hooks');
|
|
10
11
|
var icons = require('@ant-design/icons');
|
|
11
12
|
var isEmpty = require('@kne/is-empty');
|
|
12
13
|
var responsiveUtils = require('@kne/responsive-utils');
|
|
@@ -29,7 +30,7 @@ var isNil = require('lodash/isNil');
|
|
|
29
30
|
|
|
30
31
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
31
32
|
|
|
32
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React
|
|
33
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
33
34
|
var useResize__default = /*#__PURE__*/_interopDefaultLegacy(useResize);
|
|
34
35
|
var useControlValue__default = /*#__PURE__*/_interopDefaultLegacy(useControlValue);
|
|
35
36
|
var classnames__default = /*#__PURE__*/_interopDefaultLegacy(classnames);
|
|
@@ -103,7 +104,7 @@ const TagOverflowInner = ({
|
|
|
103
104
|
const list = Array.isArray(value) ? value : [];
|
|
104
105
|
const availableWidth = Math.max((innerWidth || 0) - iconSpace, 0);
|
|
105
106
|
const maxTagWidth = innerWidth > 0 ? Math.min(150, Math.max(60, innerWidth - 60)) : 150;
|
|
106
|
-
const shareItems = React
|
|
107
|
+
const shareItems = React.useMemo(() => list.map(item => ({
|
|
107
108
|
key: item?.[valueKey],
|
|
108
109
|
label: item?.[labelKey]
|
|
109
110
|
})), [list, labelKey, valueKey]);
|
|
@@ -192,6 +193,20 @@ const MOBILE_SHEET_MIN_HEIGHT = '30%';
|
|
|
192
193
|
const MOBILE_MASK_Z_INDEX = 1000;
|
|
193
194
|
const MOBILE_POPUP_Z_INDEX = 1050;
|
|
194
195
|
const MASK_ANIMATION_DURATION = 180;
|
|
196
|
+
|
|
197
|
+
/** Modal 内半屏 sheet 对齐 antd Dropdown:消费 zIndexContext,保留移动端 UX */
|
|
198
|
+
const resolveMobileSheetZIndex = popupZIndex => {
|
|
199
|
+
if (popupZIndex == null) {
|
|
200
|
+
return {
|
|
201
|
+
maskZIndex: MOBILE_MASK_Z_INDEX,
|
|
202
|
+
panelZIndex: MOBILE_POPUP_Z_INDEX
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
maskZIndex: popupZIndex - 1,
|
|
207
|
+
panelZIndex: popupZIndex
|
|
208
|
+
};
|
|
209
|
+
};
|
|
195
210
|
let parentScrollLockCount = 0;
|
|
196
211
|
let parentScrollLocked = [];
|
|
197
212
|
const lockParentScroll = getScrollElements => {
|
|
@@ -238,7 +253,7 @@ const lockParentScroll = getScrollElements => {
|
|
|
238
253
|
};
|
|
239
254
|
};
|
|
240
255
|
const useLockParentScroll = (enabled, getScrollElements) => {
|
|
241
|
-
React
|
|
256
|
+
React.useEffect(() => {
|
|
242
257
|
if (!enabled) {
|
|
243
258
|
return undefined;
|
|
244
259
|
}
|
|
@@ -270,8 +285,8 @@ const ModalContent = _ref2 => {
|
|
|
270
285
|
open,
|
|
271
286
|
value: propsValue
|
|
272
287
|
} = others;
|
|
273
|
-
const [value, setValue] = React
|
|
274
|
-
React
|
|
288
|
+
const [value, setValue] = React.useState(propsValue);
|
|
289
|
+
React.useEffect(() => {
|
|
275
290
|
if (open && !isEqual__default["default"](value, propsValue)) {
|
|
276
291
|
setValue(propsValue);
|
|
277
292
|
}
|
|
@@ -300,11 +315,12 @@ const MobileSheetMask = _ref3 => {
|
|
|
300
315
|
open,
|
|
301
316
|
mountNode,
|
|
302
317
|
fixedModeClass,
|
|
303
|
-
onClose
|
|
318
|
+
onClose,
|
|
319
|
+
zIndex = MOBILE_MASK_Z_INDEX
|
|
304
320
|
} = _ref3;
|
|
305
|
-
const [renderMask, setRenderMask] = React
|
|
306
|
-
const [maskClosing, setMaskClosing] = React
|
|
307
|
-
React
|
|
321
|
+
const [renderMask, setRenderMask] = React.useState(false);
|
|
322
|
+
const [maskClosing, setMaskClosing] = React.useState(false);
|
|
323
|
+
React.useEffect(() => {
|
|
308
324
|
if (open) {
|
|
309
325
|
setRenderMask(true);
|
|
310
326
|
setMaskClosing(false);
|
|
@@ -326,7 +342,7 @@ const MobileSheetMask = _ref3 => {
|
|
|
326
342
|
return reactDom.createPortal(/*#__PURE__*/React__default["default"].createElement("div", {
|
|
327
343
|
className: classnames__default["default"](style$6['mobile-sheet-mask'], maskClosing && style$6['mobile-sheet-mask-leave'], fixedModeClass),
|
|
328
344
|
style: {
|
|
329
|
-
zIndex
|
|
345
|
+
zIndex
|
|
330
346
|
},
|
|
331
347
|
onClick: onClose,
|
|
332
348
|
onTouchMove: e => {
|
|
@@ -368,7 +384,8 @@ const MobileSheetPanel = _ref5 => {
|
|
|
368
384
|
confirmText,
|
|
369
385
|
onCancel,
|
|
370
386
|
onConfirm,
|
|
371
|
-
children
|
|
387
|
+
children,
|
|
388
|
+
zIndex = MOBILE_POPUP_Z_INDEX
|
|
372
389
|
} = _ref5;
|
|
373
390
|
if (!open || !mountNode) {
|
|
374
391
|
return null;
|
|
@@ -376,7 +393,7 @@ const MobileSheetPanel = _ref5 => {
|
|
|
376
393
|
return reactDom.createPortal(/*#__PURE__*/React__default["default"].createElement("div", {
|
|
377
394
|
className: classnames__default["default"](style$6['mobile-sheet-popup'], style$6['mobile-sheet-portal'], fixedModeClass, overlayClassName),
|
|
378
395
|
style: {
|
|
379
|
-
zIndex
|
|
396
|
+
zIndex,
|
|
380
397
|
maxHeight: MOBILE_SHEET_MAX_HEIGHT,
|
|
381
398
|
minHeight: MOBILE_SHEET_MIN_HEIGHT
|
|
382
399
|
},
|
|
@@ -407,7 +424,7 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
407
424
|
'zh-CN': locale$1,
|
|
408
425
|
'en-US': locale
|
|
409
426
|
}
|
|
410
|
-
})(React
|
|
427
|
+
})(React.forwardRef((p, ref) => {
|
|
411
428
|
const intl = reactIntl.useIntl();
|
|
412
429
|
const {
|
|
413
430
|
formatMessage
|
|
@@ -455,7 +472,8 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
455
472
|
isMobile,
|
|
456
473
|
getPopupContainer,
|
|
457
474
|
formatMessage,
|
|
458
|
-
fixedModeClass
|
|
475
|
+
fixedModeClass,
|
|
476
|
+
mobileSheetZIndex
|
|
459
477
|
} = contextProps;
|
|
460
478
|
const {
|
|
461
479
|
placeholder,
|
|
@@ -466,11 +484,16 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
466
484
|
if (isMobile && !disableMobileSheet) {
|
|
467
485
|
const mountNode = typeof getPopupContainer === 'function' ? getPopupContainer() : null;
|
|
468
486
|
const closeWithoutCommit = () => onOpenChange(false);
|
|
487
|
+
const {
|
|
488
|
+
maskZIndex,
|
|
489
|
+
panelZIndex
|
|
490
|
+
} = mobileSheetZIndex || resolveMobileSheetZIndex();
|
|
469
491
|
return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(MobileSheetMask, {
|
|
470
492
|
open: open,
|
|
471
493
|
mountNode: mountNode,
|
|
472
494
|
fixedModeClass: fixedModeClass,
|
|
473
|
-
onClose: closeWithoutCommit
|
|
495
|
+
onClose: closeWithoutCommit,
|
|
496
|
+
zIndex: maskZIndex
|
|
474
497
|
}), /*#__PURE__*/React__default["default"].createElement(MobileSheetPanel, {
|
|
475
498
|
open: open,
|
|
476
499
|
mountNode: mountNode,
|
|
@@ -487,7 +510,8 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
487
510
|
onConfirm: () => {
|
|
488
511
|
onComplete();
|
|
489
512
|
onOpenChange(false);
|
|
490
|
-
}
|
|
513
|
+
},
|
|
514
|
+
zIndex: panelZIndex
|
|
491
515
|
}, open ? children(contextProps) : null));
|
|
492
516
|
}
|
|
493
517
|
return /*#__PURE__*/React__default["default"].createElement(antd.Modal, {
|
|
@@ -539,9 +563,8 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
539
563
|
size,
|
|
540
564
|
disableMobileSheet
|
|
541
565
|
} = props;
|
|
542
|
-
const getPopupContainerDefault = responsiveUtils.usePopupContainer();
|
|
543
566
|
const getScrollElement = responsiveUtils.useScrollElement();
|
|
544
|
-
const wrapCustomGetPopupContainer = React
|
|
567
|
+
const wrapCustomGetPopupContainer = React.useMemo(() => {
|
|
545
568
|
if (typeof getPopupContainerProp === 'function') {
|
|
546
569
|
return triggerNode => getPopupContainerProp(triggerNode) || null;
|
|
547
570
|
}
|
|
@@ -553,12 +576,14 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
553
576
|
const {
|
|
554
577
|
isMobile,
|
|
555
578
|
fixedModeClass,
|
|
556
|
-
getPopupContainer:
|
|
579
|
+
getPopupContainer: resolveGetPopupContainer,
|
|
557
580
|
anchorRef
|
|
558
|
-
} = responsiveUtils.
|
|
581
|
+
} = responsiveUtils.usePopupMount({
|
|
559
582
|
cover: 'viewport',
|
|
560
583
|
getPopupContainer: wrapCustomGetPopupContainer
|
|
561
584
|
});
|
|
585
|
+
const [antdPopupZIndex] = hooks.useZIndex('Dropdown');
|
|
586
|
+
const mobileSheetZIndex = React.useMemo(() => resolveMobileSheetZIndex(antdPopupZIndex), [antdPopupZIndex]);
|
|
562
587
|
const useMobileSheet = isMobile && !disableMobileSheet;
|
|
563
588
|
const useBoundaryMount = !!(isMobile && fixedModeClass === responsiveUtils.MOBILE_POPUP_MODE.boundary);
|
|
564
589
|
const transformValue = value => {
|
|
@@ -577,16 +602,16 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
577
602
|
} : {
|
|
578
603
|
defaultValue: transformValue(props.defaultValue)
|
|
579
604
|
}));
|
|
580
|
-
const [searchProps, setSearchProps] = React
|
|
605
|
+
const [searchProps, setSearchProps] = React.useState({});
|
|
581
606
|
const [open, setOpen] = useControlValue__default["default"](props, {
|
|
582
607
|
defaultValue: 'defaultOpen',
|
|
583
608
|
value: 'open',
|
|
584
609
|
onChange: 'onOpenChange'
|
|
585
610
|
});
|
|
586
|
-
const [hover, setHover] = React
|
|
587
|
-
const [innerWidth, setInnerWidth] = React
|
|
588
|
-
const [containerWidth, setContainerWidth] = React
|
|
589
|
-
const [popupMountNode, setPopupMountNode] = React
|
|
611
|
+
const [hover, setHover] = React.useState(false);
|
|
612
|
+
const [innerWidth, setInnerWidth] = React.useState(0);
|
|
613
|
+
const [containerWidth, setContainerWidth] = React.useState(0);
|
|
614
|
+
const [popupMountNode, setPopupMountNode] = React.useState(null);
|
|
590
615
|
const containerWidthChange = el => {
|
|
591
616
|
if (!el) {
|
|
592
617
|
return;
|
|
@@ -596,13 +621,13 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
596
621
|
const innerEl = el.querySelector('.select-input-inner');
|
|
597
622
|
setInnerWidth(innerEl.clientWidth);
|
|
598
623
|
};
|
|
599
|
-
const popupOverlayWidth = React
|
|
624
|
+
const popupOverlayWidth = React.useMemo(() => {
|
|
600
625
|
const configured = overlayWidth != null && overlayWidth !== '' ? pxToNumber(overlayWidth) : DEFAULT_OVERLAY_MIN_WIDTH;
|
|
601
626
|
return numberToPx$1(Math.max(containerWidth || 0, configured));
|
|
602
627
|
}, [containerWidth, overlayWidth]);
|
|
603
628
|
|
|
604
629
|
// 同步给 Dropdown 外层 minWidth,避免 antd 按窄触发器裁剪面板
|
|
605
|
-
const mergedOverlayStyle = React
|
|
630
|
+
const mergedOverlayStyle = React.useMemo(() => {
|
|
606
631
|
return Object.assign({}, overlayStyle, zIndex != null ? {
|
|
607
632
|
zIndex
|
|
608
633
|
} : null, {
|
|
@@ -611,34 +636,20 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
611
636
|
});
|
|
612
637
|
}, [overlayStyle, zIndex, popupOverlayWidth]);
|
|
613
638
|
const resizeRef = useResize__default["default"](containerWidthChange);
|
|
614
|
-
const setContainerRef = React
|
|
639
|
+
const setContainerRef = React.useCallback(node => {
|
|
615
640
|
resizeRef.current = node;
|
|
616
641
|
anchorRef(node);
|
|
617
642
|
}, [anchorRef, resizeRef]);
|
|
618
|
-
const resolveGetPopupContainer = React$1.useCallback(triggerNode => {
|
|
619
|
-
if (typeof getPopupContainerProp === 'function') {
|
|
620
|
-
const customContainer = getPopupContainerProp(triggerNode);
|
|
621
|
-
if (customContainer) {
|
|
622
|
-
return customContainer;
|
|
623
|
-
}
|
|
624
|
-
} else if (getPopupContainerProp) {
|
|
625
|
-
return getPopupContainerProp;
|
|
626
|
-
}
|
|
627
|
-
if (useMobileSheet) {
|
|
628
|
-
return getSheetPopupContainer(triggerNode);
|
|
629
|
-
}
|
|
630
|
-
return getPopupContainerDefault(triggerNode);
|
|
631
|
-
}, [getPopupContainerDefault, getPopupContainerProp, getSheetPopupContainer, useMobileSheet]);
|
|
632
643
|
|
|
633
644
|
// 打开时再取挂载节点,避免落到错误容器
|
|
634
|
-
React
|
|
645
|
+
React.useLayoutEffect(() => {
|
|
635
646
|
if (!useMobileSheet) {
|
|
636
647
|
setPopupMountNode(null);
|
|
637
648
|
return;
|
|
638
649
|
}
|
|
639
650
|
setPopupMountNode(resolveGetPopupContainer(resizeRef.current) || (typeof document !== 'undefined' ? document.body : null));
|
|
640
651
|
}, [useMobileSheet, resolveGetPopupContainer, open, resizeRef]);
|
|
641
|
-
const getLockScrollTargets = React
|
|
652
|
+
const getLockScrollTargets = React.useCallback(() => {
|
|
642
653
|
const targets = [];
|
|
643
654
|
const scrollEl = typeof getScrollElement === 'function' ? getScrollElement() : null;
|
|
644
655
|
if (scrollEl) {
|
|
@@ -704,12 +715,12 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
704
715
|
return newValue;
|
|
705
716
|
});
|
|
706
717
|
};
|
|
707
|
-
const handleOpenChange = React
|
|
718
|
+
const handleOpenChange = React.useCallback(nextOpen => {
|
|
708
719
|
setOpen(nextOpen);
|
|
709
720
|
}, [setOpen]);
|
|
710
721
|
|
|
711
722
|
// 关闭时清空搜索,保证下次展开重新请求且从初始搜索态开始
|
|
712
|
-
React
|
|
723
|
+
React.useEffect(() => {
|
|
713
724
|
if (!open) {
|
|
714
725
|
setSearchProps({});
|
|
715
726
|
}
|
|
@@ -730,6 +741,7 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
730
741
|
children,
|
|
731
742
|
isMobile,
|
|
732
743
|
useBoundaryMount,
|
|
744
|
+
mobileSheetZIndex,
|
|
733
745
|
fixedModeClass,
|
|
734
746
|
getPopupContainer: resolveGetPopupContainer,
|
|
735
747
|
formatMessage
|
|
@@ -795,7 +807,7 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
795
807
|
}, current);
|
|
796
808
|
})());
|
|
797
809
|
};
|
|
798
|
-
React
|
|
810
|
+
React.useImperativeHandle(ref, () => {
|
|
799
811
|
return contextProps;
|
|
800
812
|
});
|
|
801
813
|
|
|
@@ -826,7 +838,8 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
826
838
|
open: sheetOpen,
|
|
827
839
|
mountNode: popupMountNode,
|
|
828
840
|
fixedModeClass: fixedModeClass,
|
|
829
|
-
onClose: closeWithoutCommit
|
|
841
|
+
onClose: closeWithoutCommit,
|
|
842
|
+
zIndex: mobileSheetZIndex.maskZIndex
|
|
830
843
|
}), /*#__PURE__*/React__default["default"].createElement(MobileSheetPanel, {
|
|
831
844
|
open: sheetOpen,
|
|
832
845
|
mountNode: popupMountNode,
|
|
@@ -843,7 +856,8 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
843
856
|
onConfirm: () => {
|
|
844
857
|
onComplete();
|
|
845
858
|
setOpen(false);
|
|
846
|
-
}
|
|
859
|
+
},
|
|
860
|
+
zIndex: mobileSheetZIndex.panelZIndex
|
|
847
861
|
}, sheetOpen ? children(sheetContextProps) : null));
|
|
848
862
|
}));
|
|
849
863
|
}
|
|
@@ -980,12 +994,12 @@ const SelectedTagList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
|
|
|
980
994
|
|
|
981
995
|
var style$3 = {"kne-responsive-boundary":"kne-super-select_Nc-y4","kne-responsive-scroll":"kne-super-select_RlrDm","list":"kne-super-select_IsXdU","empty":"kne-super-select_SQZ8k","default-list":"kne-super-select_QD1Mz","is-selected-all":"kne-super-select_M-mOy","default-list-item":"kne-super-select_KtOsz","is-selected":"kne-super-select_TQhBB","single-checked":"kne-super-select_2rUrh","is-disabled":"kne-super-select_NbwX5","selected-all":"kne-super-select_vN2Fx","selected-tag":"kne-super-select_6oITk","select-search":"kne-super-select_iAH9D","select-list-item-description":"kne-super-select_TCkeJ","footer":"kne-super-select_v3f23","is-mobile":"kne-super-select_w-WB8"};
|
|
982
996
|
|
|
983
|
-
const SelectList = React
|
|
997
|
+
const SelectList = React.forwardRef((_ref, ref) => {
|
|
984
998
|
let {
|
|
985
999
|
children,
|
|
986
1000
|
...p
|
|
987
1001
|
} = _ref;
|
|
988
|
-
const fetchListRef = React
|
|
1002
|
+
const fetchListRef = React.useRef(null);
|
|
989
1003
|
const props = Object.assign({}, {
|
|
990
1004
|
renderItemContent: _ref2 => {
|
|
991
1005
|
let {
|
|
@@ -1214,7 +1228,7 @@ const FetchTableContent = ({
|
|
|
1214
1228
|
...tableProps
|
|
1215
1229
|
}) => {
|
|
1216
1230
|
const paginationMerged = Object.assign({
|
|
1217
|
-
open:
|
|
1231
|
+
open: true,
|
|
1218
1232
|
paramsType: 'data',
|
|
1219
1233
|
requestType: 'reload',
|
|
1220
1234
|
currentName: 'currentPage',
|
|
@@ -1230,16 +1244,101 @@ const FetchTableContent = ({
|
|
|
1230
1244
|
requestParams,
|
|
1231
1245
|
fetchProps
|
|
1232
1246
|
});
|
|
1233
|
-
const showPagination = paginationMerged.open && formatData.total > 0;
|
|
1234
1247
|
const currentPage = get__default["default"](requestParams, [paginationMerged.paramsType, paginationMerged.currentName], 1);
|
|
1235
1248
|
const currentPageSize = Number(get__default["default"](requestParams, [paginationMerged.paramsType, paginationMerged.pageSizeName], paginationMerged.pageSize)) || paginationMerged.pageSize || 20;
|
|
1236
|
-
|
|
1237
|
-
|
|
1249
|
+
const hasMore = formatData.total > currentPage * currentPageSize;
|
|
1250
|
+
const showPagination = paginationMerged.open && formatData.total > 0;
|
|
1251
|
+
const isLoadMoreMode = !paginationMerged.open;
|
|
1252
|
+
const [accumulatedList, setAccumulatedList] = React.useState([]);
|
|
1253
|
+
const [isLoadingMore, setIsLoadingMore] = React.useState(false);
|
|
1254
|
+
const isLoadingMoreRef = React.useRef(false);
|
|
1255
|
+
const prevDataRef = React.useRef(null);
|
|
1256
|
+
const containerRef = React.useRef(null);
|
|
1257
|
+
React.useEffect(() => {
|
|
1258
|
+
if (!isLoadMoreMode) return;
|
|
1259
|
+
if (data === prevDataRef.current) return;
|
|
1260
|
+
prevDataRef.current = data;
|
|
1261
|
+
const newList = formatData.list || [];
|
|
1262
|
+
if (currentPage <= 1) {
|
|
1263
|
+
setAccumulatedList(newList);
|
|
1264
|
+
} else {
|
|
1265
|
+
setAccumulatedList(prev => prev.concat(newList));
|
|
1266
|
+
}
|
|
1267
|
+
setIsLoadingMore(false);
|
|
1268
|
+
isLoadingMoreRef.current = false;
|
|
1269
|
+
}, [data, isLoadMoreMode, currentPage, formatData.list]);
|
|
1270
|
+
const doLoadNextPage = React.useCallback(() => {
|
|
1271
|
+
if (isLoadingMoreRef.current || !hasMore || !isLoadMoreMode) return;
|
|
1272
|
+
isLoadingMoreRef.current = true;
|
|
1273
|
+
setIsLoadingMore(true);
|
|
1274
|
+
const nextPage = currentPage + 1;
|
|
1275
|
+
const currentParams = get__default["default"](requestParams, paginationMerged.paramsType, {});
|
|
1276
|
+
(paginationMerged.requestType === 'refresh' ? refresh : reload)({
|
|
1277
|
+
[paginationMerged.paramsType]: Object.assign({}, currentParams, {
|
|
1278
|
+
[paginationMerged.currentName]: nextPage,
|
|
1279
|
+
[paginationMerged.pageSizeName]: currentPageSize
|
|
1280
|
+
})
|
|
1281
|
+
});
|
|
1282
|
+
}, [hasMore, isLoadMoreMode, currentPage, requestParams, paginationMerged, refresh, reload, currentPageSize]);
|
|
1283
|
+
React.useEffect(() => {
|
|
1284
|
+
if (!isLoadMoreMode) return;
|
|
1285
|
+
const container = containerRef.current;
|
|
1286
|
+
if (!container) return;
|
|
1287
|
+
const scrollEl = container.querySelector('.ant-table-body') || container.closest('.select-table-list-scroll-list');
|
|
1288
|
+
if (!scrollEl) return;
|
|
1289
|
+
const onScroll = () => {
|
|
1290
|
+
const {
|
|
1291
|
+
scrollTop,
|
|
1292
|
+
scrollHeight,
|
|
1293
|
+
clientHeight
|
|
1294
|
+
} = scrollEl;
|
|
1295
|
+
if (scrollHeight - scrollTop - clientHeight < 50) {
|
|
1296
|
+
doLoadNextPage();
|
|
1297
|
+
}
|
|
1298
|
+
};
|
|
1299
|
+
scrollEl.addEventListener('scroll', onScroll, {
|
|
1300
|
+
passive: true
|
|
1301
|
+
});
|
|
1302
|
+
return () => scrollEl.removeEventListener('scroll', onScroll);
|
|
1303
|
+
}, [isLoadMoreMode, doLoadNextPage]);
|
|
1304
|
+
|
|
1305
|
+
// 如果当前列表高度没有超过容器(弹窗模式可能不出现滚动条),
|
|
1306
|
+
// 仅靠 scroll 事件无法触发 loadMore:自动补页直到出现溢出或没有更多。
|
|
1307
|
+
const autoLoadCountRef = React.useRef(0);
|
|
1308
|
+
React.useEffect(() => {
|
|
1309
|
+
if (!isLoadMoreMode) return;
|
|
1310
|
+
if (isLoadingMoreRef.current) return;
|
|
1311
|
+
if (!hasMore) return;
|
|
1312
|
+
const container = containerRef.current;
|
|
1313
|
+
if (!container) return;
|
|
1314
|
+
const scrollEl = container.querySelector('.ant-table-body') || container.closest('.select-table-list-scroll-list');
|
|
1315
|
+
if (!scrollEl) return;
|
|
1316
|
+
const isOverflowing = scrollEl.scrollHeight > scrollEl.clientHeight + 1;
|
|
1317
|
+
if (isOverflowing) {
|
|
1318
|
+
autoLoadCountRef.current = 0;
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
if (autoLoadCountRef.current >= 5) return;
|
|
1322
|
+
autoLoadCountRef.current += 1;
|
|
1323
|
+
setTimeout(() => doLoadNextPage(), 0);
|
|
1324
|
+
}, [isLoadMoreMode, hasMore, data, currentPage, currentPageSize, doLoadNextPage]);
|
|
1325
|
+
const displayList = isLoadMoreMode ? accumulatedList : formatData.list || [];
|
|
1326
|
+
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1327
|
+
ref: containerRef
|
|
1328
|
+
}, /*#__PURE__*/React__default["default"].createElement(tableView.Table, _extends({}, tableProps, {
|
|
1329
|
+
dataSource: displayList,
|
|
1238
1330
|
pagination: false,
|
|
1239
1331
|
columns: columns,
|
|
1240
1332
|
context: tableContext,
|
|
1241
1333
|
columnRenderProps: tableContext
|
|
1242
|
-
})), showPagination ? /*#__PURE__*/
|
|
1334
|
+
})), showPagination ? /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1335
|
+
style: {
|
|
1336
|
+
padding: '8px 12px',
|
|
1337
|
+
display: 'flex',
|
|
1338
|
+
justifyContent: 'flex-end'
|
|
1339
|
+
}
|
|
1340
|
+
}, /*#__PURE__*/React__default["default"].createElement(antd.Pagination, {
|
|
1341
|
+
size: "small",
|
|
1243
1342
|
total: formatData.total,
|
|
1244
1343
|
current: currentPage,
|
|
1245
1344
|
pageSize: currentPageSize,
|
|
@@ -1247,14 +1346,24 @@ const FetchTableContent = ({
|
|
|
1247
1346
|
showQuickJumper: paginationMerged.showQuickJumper,
|
|
1248
1347
|
hideOnSinglePage: paginationMerged.hideOnSinglePage,
|
|
1249
1348
|
onChange: (page, size) => {
|
|
1349
|
+
const currentParams = get__default["default"](requestParams, paginationMerged.paramsType, {});
|
|
1250
1350
|
(paginationMerged.requestType === 'refresh' ? refresh : reload)({
|
|
1251
|
-
[paginationMerged.paramsType]: Object.assign({},
|
|
1351
|
+
[paginationMerged.paramsType]: Object.assign({}, currentParams, {
|
|
1252
1352
|
[paginationMerged.currentName]: page,
|
|
1253
1353
|
[paginationMerged.pageSizeName]: size
|
|
1254
1354
|
})
|
|
1255
1355
|
});
|
|
1256
1356
|
}
|
|
1257
|
-
}) : null
|
|
1357
|
+
})) : null, isLoadMoreMode ? /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1358
|
+
style: {
|
|
1359
|
+
textAlign: 'center',
|
|
1360
|
+
padding: '8px 0',
|
|
1361
|
+
color: '#999',
|
|
1362
|
+
fontSize: 12,
|
|
1363
|
+
height: 32,
|
|
1364
|
+
visibility: isLoadingMore ? 'visible' : 'hidden'
|
|
1365
|
+
}
|
|
1366
|
+
}, "\u52A0\u8F7D\u4E2D...") : null);
|
|
1258
1367
|
};
|
|
1259
1368
|
const FetchTable = Fetch.withFetch(FetchTableContent);
|
|
1260
1369
|
|
|
@@ -1340,13 +1449,13 @@ const getListFromPageData = data => {
|
|
|
1340
1449
|
const TABLE_LIST_MAX_HEIGHT_POPUP = 300;
|
|
1341
1450
|
const TABLE_LIST_MAX_HEIGHT_EMBED = 400;
|
|
1342
1451
|
const TABLE_HEADER_HEIGHT = 48;
|
|
1343
|
-
const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'super-select')(React
|
|
1452
|
+
const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'super-select')(React.forwardRef((p, ref) => {
|
|
1344
1453
|
const {
|
|
1345
1454
|
formatMessage
|
|
1346
1455
|
} = reactIntl.useIntl();
|
|
1347
|
-
const [tagSearchText, setTagSearchText] = React
|
|
1348
|
-
const tablePageRef = React
|
|
1349
|
-
const listScrollRef = React
|
|
1456
|
+
const [tagSearchText, setTagSearchText] = React.useState('');
|
|
1457
|
+
const tablePageRef = React.useRef();
|
|
1458
|
+
const listScrollRef = React.useRef();
|
|
1350
1459
|
const props = Object.assign({}, {
|
|
1351
1460
|
overlayWidth: '600px',
|
|
1352
1461
|
dataType: 'list',
|
|
@@ -1398,7 +1507,7 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
|
|
|
1398
1507
|
return item[labelKey].indexOf(tagSearchText) > -1;
|
|
1399
1508
|
}
|
|
1400
1509
|
}, p);
|
|
1401
|
-
const bodyRef = React
|
|
1510
|
+
const bodyRef = React.useRef(null);
|
|
1402
1511
|
return /*#__PURE__*/React__default["default"].createElement(SelectInput, _extends({}, props, {
|
|
1403
1512
|
ref: ref
|
|
1404
1513
|
}), targetProps => {
|
|
@@ -1604,7 +1713,7 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
|
|
|
1604
1713
|
dataFormat
|
|
1605
1714
|
} : null, {
|
|
1606
1715
|
pagination: Object.assign({
|
|
1607
|
-
open:
|
|
1716
|
+
open: true,
|
|
1608
1717
|
showSizeChanger: false,
|
|
1609
1718
|
showQuickJumper: false,
|
|
1610
1719
|
hideOnSinglePage: true
|
|
@@ -1709,13 +1818,13 @@ const parseTreeData = memoize__default["default"](function (data, _ref) {
|
|
|
1709
1818
|
ids: data.map(item => item.id)
|
|
1710
1819
|
};
|
|
1711
1820
|
});
|
|
1712
|
-
const SelectTree = React
|
|
1821
|
+
const SelectTree = React.forwardRef((_ref2, ref) => {
|
|
1713
1822
|
let {
|
|
1714
1823
|
children,
|
|
1715
1824
|
...p
|
|
1716
1825
|
} = _ref2;
|
|
1717
|
-
const fetchListRef = React
|
|
1718
|
-
const [expandedKeys, setExpandedKeys] = React
|
|
1826
|
+
const fetchListRef = React.useRef(null);
|
|
1827
|
+
const [expandedKeys, setExpandedKeys] = React.useState([]);
|
|
1719
1828
|
const props = Object.assign({}, {
|
|
1720
1829
|
parentKey: 'parentId',
|
|
1721
1830
|
childrenKey: 'children',
|
|
@@ -2190,13 +2299,13 @@ const CascaderInner = _ref => {
|
|
|
2190
2299
|
const {
|
|
2191
2300
|
message
|
|
2192
2301
|
} = antd.App.useApp();
|
|
2193
|
-
const [searchText, setSearchText] = React
|
|
2194
|
-
const [loading, setLoading] = React
|
|
2302
|
+
const [searchText, setSearchText] = React.useState('');
|
|
2303
|
+
const [loading, setLoading] = React.useState(false);
|
|
2195
2304
|
// 移动端弹窗内不用 SimpleBar,改原生滚动
|
|
2196
2305
|
const ScrollBox = isMobile ? 'div' : SimpleBar__default["default"];
|
|
2197
2306
|
|
|
2198
2307
|
// 构建 mapping
|
|
2199
|
-
const mapping = React
|
|
2308
|
+
const mapping = React.useMemo(() => {
|
|
2200
2309
|
const map = new Map();
|
|
2201
2310
|
const processData = function (items, parentId) {
|
|
2202
2311
|
if (parentId === void 0) {
|
|
@@ -2226,12 +2335,12 @@ const CascaderInner = _ref => {
|
|
|
2226
2335
|
}, [options, valueKey, labelKey]);
|
|
2227
2336
|
|
|
2228
2337
|
// 创建树工具
|
|
2229
|
-
const treeUtils = React
|
|
2338
|
+
const treeUtils = React.useMemo(() => {
|
|
2230
2339
|
return createTreeUtils(mapping);
|
|
2231
2340
|
}, [mapping]);
|
|
2232
2341
|
|
|
2233
2342
|
// 当前选中的列
|
|
2234
|
-
const [selectedIds, setSelectedIds] = React
|
|
2343
|
+
const [selectedIds, setSelectedIds] = React.useState(() => {
|
|
2235
2344
|
const initValue = value.find(item => {
|
|
2236
2345
|
const id = typeof item === 'object' ? item[valueKey] : item;
|
|
2237
2346
|
return !!mapping.get(id);
|
|
@@ -2250,8 +2359,8 @@ const CascaderInner = _ref => {
|
|
|
2250
2359
|
});
|
|
2251
2360
|
|
|
2252
2361
|
// 当 Modal 打开时,根据 value 重新初始化 selectedIds
|
|
2253
|
-
const prevOpenRef = React
|
|
2254
|
-
React
|
|
2362
|
+
const prevOpenRef = React.useRef(open);
|
|
2363
|
+
React.useEffect(() => {
|
|
2255
2364
|
// 只在非 popup 模式下且 Modal 从关闭变为打开时处理
|
|
2256
2365
|
if (!isPopup && open && !prevOpenRef.current) {
|
|
2257
2366
|
const initValue = value.find(item => {
|
|
@@ -2273,14 +2382,14 @@ const CascaderInner = _ref => {
|
|
|
2273
2382
|
}, [open, value, mapping, treeUtils, valueKey, isPopup]);
|
|
2274
2383
|
|
|
2275
2384
|
// 懒加载支持
|
|
2276
|
-
const loadMorePropsRef = React
|
|
2385
|
+
const loadMorePropsRef = React.useRef({});
|
|
2277
2386
|
loadMorePropsRef.current = {
|
|
2278
2387
|
openLoadData,
|
|
2279
2388
|
onLoadMore,
|
|
2280
2389
|
parentIdKey,
|
|
2281
2390
|
treeUtils
|
|
2282
2391
|
};
|
|
2283
|
-
React
|
|
2392
|
+
React.useEffect(() => {
|
|
2284
2393
|
if (!open || !openLoadData || !onLoadMore) {
|
|
2285
2394
|
return;
|
|
2286
2395
|
}
|
|
@@ -2304,7 +2413,7 @@ const CascaderInner = _ref => {
|
|
|
2304
2413
|
}, [open, selectedIds, mapping, openLoadData, onLoadMore, parentIdKey]);
|
|
2305
2414
|
|
|
2306
2415
|
// 检查是否为非叶子节点
|
|
2307
|
-
const isNotLastNode = React
|
|
2416
|
+
const isNotLastNode = React.useCallback(id => {
|
|
2308
2417
|
const node = mapping.get(id);
|
|
2309
2418
|
if (!node) return false;
|
|
2310
2419
|
if (openLoadData && !node.hasOwnProperty('children')) {
|
|
@@ -2314,7 +2423,7 @@ const CascaderInner = _ref => {
|
|
|
2314
2423
|
}, [mapping, openLoadData]);
|
|
2315
2424
|
|
|
2316
2425
|
// 选择处理
|
|
2317
|
-
const onCheckedChange = React
|
|
2426
|
+
const onCheckedChange = React.useCallback((checked, id) => {
|
|
2318
2427
|
const newValue = (() => {
|
|
2319
2428
|
if (onlyAllowLastLevel && checked) {
|
|
2320
2429
|
const currentIds = value.map(item => typeof item === 'object' ? item[valueKey] : item);
|
|
@@ -2353,7 +2462,7 @@ const CascaderInner = _ref => {
|
|
|
2353
2462
|
}, [value, maxLength, single, onlyAllowLastLevel, treeUtils, mapping, message, valueKey, labelKey, isPopup, onOpenChange, isNotLastNode]);
|
|
2354
2463
|
|
|
2355
2464
|
// 搜索结果
|
|
2356
|
-
const searchResults = React
|
|
2465
|
+
const searchResults = React.useMemo(() => {
|
|
2357
2466
|
if (!searchText || !onSearch) return null;
|
|
2358
2467
|
const keyword = searchText.toLowerCase();
|
|
2359
2468
|
return Array.from(mapping.values()).filter(item => {
|
|
@@ -2604,17 +2713,17 @@ const SelectCascader = _ref4 => {
|
|
|
2604
2713
|
} = _ref4;
|
|
2605
2714
|
// 内部始终使用数组格式处理
|
|
2606
2715
|
// SelectInput 会处理 single 模式的 value 和 onChange 转换
|
|
2607
|
-
const [innerValue, setInnerValue] = React
|
|
2716
|
+
const [innerValue, setInnerValue] = React.useState(Array.isArray(defaultValue) ? defaultValue : defaultValue ? [defaultValue] : []);
|
|
2608
2717
|
|
|
2609
2718
|
// currentValue 用于内部处理,始终是数组
|
|
2610
|
-
const currentValue = React
|
|
2719
|
+
const currentValue = React.useMemo(() => {
|
|
2611
2720
|
if (value !== undefined) {
|
|
2612
2721
|
// 外部传入的 value 可能是对象(single)或数组(多选)
|
|
2613
2722
|
return Array.isArray(value) ? value : value ? [value] : [];
|
|
2614
2723
|
}
|
|
2615
2724
|
return innerValue;
|
|
2616
2725
|
}, [value, innerValue]);
|
|
2617
|
-
const setValue = React
|
|
2726
|
+
const setValue = React.useCallback(newValue => {
|
|
2618
2727
|
// SelectInput 在 single 模式下会传单个对象或 null/undefined,需要转换为数组
|
|
2619
2728
|
const normalizedValue = (() => {
|
|
2620
2729
|
if (single) {
|
|
@@ -2642,7 +2751,7 @@ const SelectCascader = _ref4 => {
|
|
|
2642
2751
|
}, [value, onChange, single]);
|
|
2643
2752
|
|
|
2644
2753
|
// 传递给 SelectInput 的值:根据 single 参数决定格式
|
|
2645
|
-
const selectInputValue = React
|
|
2754
|
+
const selectInputValue = React.useMemo(() => {
|
|
2646
2755
|
if (single) {
|
|
2647
2756
|
// single 模式:传单个对象或 undefined
|
|
2648
2757
|
return currentValue.length > 0 ? currentValue[0] : undefined;
|
|
@@ -2652,7 +2761,7 @@ const SelectCascader = _ref4 => {
|
|
|
2652
2761
|
}, [currentValue, single]);
|
|
2653
2762
|
|
|
2654
2763
|
// 计算 label 显示
|
|
2655
|
-
React
|
|
2764
|
+
React.useMemo(() => {
|
|
2656
2765
|
// currentValue 已经是数组格式了
|
|
2657
2766
|
return currentValue.map(item => {
|
|
2658
2767
|
// 如果已经是对象,确保有标准化的字段
|