@kne/react-modal 0.1.10 → 0.1.12
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 +156 -331
- package/dist/index.css +27 -5
- package/dist/index.css.map +1 -1
- package/dist/index.js +285 -238
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +284 -239
- package/dist/index.modern.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -116,6 +116,97 @@ const Footer = ({
|
|
|
116
116
|
});
|
|
117
117
|
};
|
|
118
118
|
|
|
119
|
+
let parentScrollLockCount = 0;
|
|
120
|
+
let parentScrollLocked = [];
|
|
121
|
+
|
|
122
|
+
/** Modal / Drawer 共用:锁 body + layout scroll,避免背后页面滚动 */
|
|
123
|
+
const lockParentScroll = getScrollElement => {
|
|
124
|
+
parentScrollLockCount += 1;
|
|
125
|
+
if (parentScrollLockCount === 1) {
|
|
126
|
+
const targets = [document.body];
|
|
127
|
+
const scrollEl = typeof getScrollElement === 'function' ? getScrollElement() : null;
|
|
128
|
+
if (scrollEl && scrollEl !== document.body && !targets.includes(scrollEl)) {
|
|
129
|
+
targets.push(scrollEl);
|
|
130
|
+
}
|
|
131
|
+
parentScrollLocked = targets.map(el => {
|
|
132
|
+
const prev = {
|
|
133
|
+
overflow: el.style.overflow,
|
|
134
|
+
overscrollBehavior: el.style.overscrollBehavior
|
|
135
|
+
};
|
|
136
|
+
el.style.overflow = 'hidden';
|
|
137
|
+
el.style.overscrollBehavior = 'none';
|
|
138
|
+
return {
|
|
139
|
+
el,
|
|
140
|
+
prev
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return () => {
|
|
145
|
+
parentScrollLockCount = Math.max(0, parentScrollLockCount - 1);
|
|
146
|
+
if (parentScrollLockCount === 0) {
|
|
147
|
+
parentScrollLocked.forEach(({
|
|
148
|
+
el,
|
|
149
|
+
prev
|
|
150
|
+
}) => {
|
|
151
|
+
el.style.overflow = prev.overflow;
|
|
152
|
+
el.style.overscrollBehavior = prev.overscrollBehavior;
|
|
153
|
+
});
|
|
154
|
+
parentScrollLocked = [];
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
const useLockParentScroll = (enabled, getScrollElement) => {
|
|
159
|
+
react.useEffect(() => {
|
|
160
|
+
if (!enabled) {
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
return lockParentScroll(getScrollElement);
|
|
164
|
+
}, [enabled, getScrollElement]);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const usePatchElement = () => {
|
|
168
|
+
const [elements, setElements] = react.useState([]);
|
|
169
|
+
const patchElement = react.useCallback(element => {
|
|
170
|
+
setElements(originElements => [...originElements, element]);
|
|
171
|
+
return () => {
|
|
172
|
+
setElements(originElements => originElements.filter(ele => ele !== element));
|
|
173
|
+
};
|
|
174
|
+
}, []);
|
|
175
|
+
return [elements, patchElement];
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const ModalLayerContext = /*#__PURE__*/react.createContext(null);
|
|
179
|
+
const useModalLayer = () => react.useContext(ModalLayerContext);
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 挂在 Modal 内容树内(antd ZIndexContext 之下),
|
|
183
|
+
* 使就近 useModal 打开的内层成为本层 React 子树,从而自动叠层。
|
|
184
|
+
*/
|
|
185
|
+
const ModalLayerProvider = ({
|
|
186
|
+
children
|
|
187
|
+
}) => {
|
|
188
|
+
const [elements, patchElement] = usePatchElement();
|
|
189
|
+
const value = react.useMemo(() => ({
|
|
190
|
+
patchElement
|
|
191
|
+
}), [patchElement]);
|
|
192
|
+
return /*#__PURE__*/jsxRuntime.jsxs(ModalLayerContext.Provider, {
|
|
193
|
+
value: value,
|
|
194
|
+
children: [children, elements]
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/** 根级命令式打开(页面首次弹层);不包 ModalLayerContext。 */
|
|
199
|
+
const rootModalPatchRef = {
|
|
200
|
+
current: null
|
|
201
|
+
};
|
|
202
|
+
const ModalContextHolder = () => {
|
|
203
|
+
const [elements, patchElement] = usePatchElement();
|
|
204
|
+
rootModalPatchRef.current = patchElement;
|
|
205
|
+
return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
206
|
+
children: elements
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
|
|
119
210
|
const ModalLocaleRoot = withLocale(({
|
|
120
211
|
children
|
|
121
212
|
}) => children);
|
|
@@ -135,20 +226,10 @@ const wrapCustomGetContainer$2 = customGetContainer => {
|
|
|
135
226
|
return () => customGetContainer;
|
|
136
227
|
};
|
|
137
228
|
const VIEWPORT_EXAMPLE_SELECTORS$3 = ['.example-driver-device-scroll'];
|
|
138
|
-
const viewportPopupMountOptions$
|
|
229
|
+
const viewportPopupMountOptions$3 = {
|
|
139
230
|
cover: 'viewport',
|
|
140
231
|
exampleSelectors: VIEWPORT_EXAMPLE_SELECTORS$3
|
|
141
232
|
};
|
|
142
|
-
const findParentModalMountHost = node => {
|
|
143
|
-
if (!node || typeof node.closest !== 'function') {
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
const parentRoot = node.closest('.ant-modal-root');
|
|
147
|
-
if (!parentRoot) {
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
return parentRoot.parentElement || (typeof document !== 'undefined' ? document.body : null);
|
|
151
|
-
};
|
|
152
233
|
const resolveModalGetContainer = ({
|
|
153
234
|
customGetContainer,
|
|
154
235
|
getPopupContainer,
|
|
@@ -163,59 +244,15 @@ const resolveModalGetContainer = ({
|
|
|
163
244
|
}
|
|
164
245
|
}
|
|
165
246
|
const from = triggerNode || (typeof getHostNode === 'function' ? getHostNode() : null);
|
|
166
|
-
const nestedHost =
|
|
247
|
+
const nestedHost = responsiveUtils.hoistOutOfModalRoot(from);
|
|
167
248
|
if (nestedHost) {
|
|
168
249
|
return nestedHost;
|
|
169
250
|
}
|
|
170
251
|
return getPopupContainer(triggerNode);
|
|
171
252
|
};
|
|
172
253
|
};
|
|
173
|
-
let parentScrollLockCount$1 = 0;
|
|
174
|
-
let parentScrollLocked$1 = [];
|
|
175
|
-
const lockParentScroll$1 = getScrollElement => {
|
|
176
|
-
parentScrollLockCount$1 += 1;
|
|
177
|
-
if (parentScrollLockCount$1 === 1) {
|
|
178
|
-
const targets = [document.body];
|
|
179
|
-
const scrollEl = typeof getScrollElement === 'function' ? getScrollElement() : null;
|
|
180
|
-
if (scrollEl && scrollEl !== document.body && !targets.includes(scrollEl)) {
|
|
181
|
-
targets.push(scrollEl);
|
|
182
|
-
}
|
|
183
|
-
parentScrollLocked$1 = targets.map(el => {
|
|
184
|
-
const prev = {
|
|
185
|
-
overflow: el.style.overflow,
|
|
186
|
-
overscrollBehavior: el.style.overscrollBehavior
|
|
187
|
-
};
|
|
188
|
-
el.style.overflow = 'hidden';
|
|
189
|
-
el.style.overscrollBehavior = 'none';
|
|
190
|
-
return {
|
|
191
|
-
el,
|
|
192
|
-
prev
|
|
193
|
-
};
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
return () => {
|
|
197
|
-
parentScrollLockCount$1 = Math.max(0, parentScrollLockCount$1 - 1);
|
|
198
|
-
if (parentScrollLockCount$1 === 0) {
|
|
199
|
-
parentScrollLocked$1.forEach(({
|
|
200
|
-
el,
|
|
201
|
-
prev
|
|
202
|
-
}) => {
|
|
203
|
-
el.style.overflow = prev.overflow;
|
|
204
|
-
el.style.overscrollBehavior = prev.overscrollBehavior;
|
|
205
|
-
});
|
|
206
|
-
parentScrollLocked$1 = [];
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
};
|
|
210
|
-
const useLockParentScroll$1 = (enabled, getScrollElement) => {
|
|
211
|
-
react.useEffect(() => {
|
|
212
|
-
if (!enabled) {
|
|
213
|
-
return undefined;
|
|
214
|
-
}
|
|
215
|
-
return lockParentScroll$1(getScrollElement);
|
|
216
|
-
}, [enabled, getScrollElement]);
|
|
217
|
-
};
|
|
218
254
|
const sizeStyleVars$1 = (size, hasFooter) => {
|
|
255
|
+
// body 最低高度随 size:small 基准 300,default/large 基准 500(再扣 title/footer chrome)
|
|
219
256
|
const minBase = size === 'small' ? 300 : 500;
|
|
220
257
|
const chrome = 48 + (hasFooter ? 58 : 0);
|
|
221
258
|
const minHeight = `${Math.max(0, minBase - chrome)}px`;
|
|
@@ -260,6 +297,19 @@ const ModalOuter = ({
|
|
|
260
297
|
children: children
|
|
261
298
|
});
|
|
262
299
|
const bodyClassName = classnames__default["default"](modalStyle['modal-body'], 'modal-body');
|
|
300
|
+
// 移动端全屏:body 用 flex 吃满 title/footer 之间剩余高度,footer 才能贴底;
|
|
301
|
+
// 桌面默认:height:auto + max-height,短内容不撑满;bodyScroll=false 仍写死满高供 Tabs/分栏
|
|
302
|
+
const bodyStyle = isMobile ? {
|
|
303
|
+
flex: '1 1 auto',
|
|
304
|
+
minHeight: 0,
|
|
305
|
+
height: 'auto'
|
|
306
|
+
} : bodyScroll !== false ? {
|
|
307
|
+
height: 'auto',
|
|
308
|
+
maxHeight: 'var(--kne-modal-body-max-height)',
|
|
309
|
+
minHeight: 'var(--kne-modal-body-min-height)'
|
|
310
|
+
} : {
|
|
311
|
+
height: 'var(--kne-modal-body-height)'
|
|
312
|
+
};
|
|
263
313
|
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
264
314
|
className: classnames__default["default"](modalStyle['modal-outer'], 'modal-container', {
|
|
265
315
|
[modalStyle['is-mobile']]: isMobile,
|
|
@@ -282,12 +332,11 @@ const ModalOuter = ({
|
|
|
282
332
|
children: title
|
|
283
333
|
}) : null, bodyScroll !== false ? /*#__PURE__*/jsxRuntime.jsx(SimpleBar__default["default"], {
|
|
284
334
|
className: bodyClassName,
|
|
285
|
-
style:
|
|
286
|
-
height: 'var(--kne-modal-body-height)'
|
|
287
|
-
},
|
|
335
|
+
style: bodyStyle,
|
|
288
336
|
children: bodyInner
|
|
289
337
|
}) : /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
290
338
|
className: classnames__default["default"](bodyClassName, modalStyle['body-scroll-off']),
|
|
339
|
+
style: bodyStyle,
|
|
291
340
|
children: bodyInner
|
|
292
341
|
}), footer === null && footerButtons === undefined ? null : /*#__PURE__*/jsxRuntime.jsx(Footer, {
|
|
293
342
|
footer: footer,
|
|
@@ -415,8 +464,11 @@ const computedCommonProps = ({
|
|
|
415
464
|
} : null)
|
|
416
465
|
}
|
|
417
466
|
},
|
|
467
|
+
// LayerProvider 须在 antd Modal 内容树内(ZIndexContext 下),内层命令式才能自动 +100
|
|
418
468
|
children: /*#__PURE__*/jsxRuntime.jsx(ModalLocaleRoot, {
|
|
419
|
-
children:
|
|
469
|
+
children: /*#__PURE__*/jsxRuntime.jsx(ModalLayerProvider, {
|
|
470
|
+
children: runChildren({})
|
|
471
|
+
})
|
|
420
472
|
})
|
|
421
473
|
};
|
|
422
474
|
};
|
|
@@ -434,12 +486,12 @@ const Modal = withLocale(({
|
|
|
434
486
|
fixedModeClass,
|
|
435
487
|
getPopupContainer,
|
|
436
488
|
anchorRef
|
|
437
|
-
} = responsiveUtils.
|
|
438
|
-
...viewportPopupMountOptions$
|
|
489
|
+
} = responsiveUtils.usePopupMount({
|
|
490
|
+
...viewportPopupMountOptions$3,
|
|
439
491
|
getPopupContainer: wrapCustomGetContainer$2(getContainer)
|
|
440
492
|
});
|
|
441
493
|
const getScrollElement = responsiveUtils.useScrollElement();
|
|
442
|
-
useLockParentScroll
|
|
494
|
+
useLockParentScroll(!!open, getScrollElement);
|
|
443
495
|
const setAnchorRef = node => {
|
|
444
496
|
hostRef.current = node;
|
|
445
497
|
anchorRef(node);
|
|
@@ -468,84 +520,123 @@ const Modal = withLocale(({
|
|
|
468
520
|
})]
|
|
469
521
|
});
|
|
470
522
|
});
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
523
|
+
|
|
524
|
+
let hookModalUuid = 0;
|
|
525
|
+
const HookModal = /*#__PURE__*/react.forwardRef(({
|
|
526
|
+
config,
|
|
527
|
+
afterClose: hookAfterClose
|
|
528
|
+
}, ref) => {
|
|
529
|
+
const [open, setOpen] = react.useState(true);
|
|
530
|
+
const [innerConfig, setInnerConfig] = react.useState(config);
|
|
531
|
+
const close = () => {
|
|
532
|
+
setOpen(false);
|
|
533
|
+
};
|
|
534
|
+
react.useImperativeHandle(ref, () => ({
|
|
535
|
+
destroy: close,
|
|
536
|
+
update: newConfig => {
|
|
537
|
+
setInnerConfig(origin => Object.assign({}, origin, typeof newConfig === 'function' ? newConfig(origin) : newConfig));
|
|
538
|
+
}
|
|
539
|
+
}));
|
|
475
540
|
const {
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
541
|
+
afterClose: userAfterClose,
|
|
542
|
+
onClose: userOnClose,
|
|
543
|
+
onConfirm: userOnConfirm,
|
|
544
|
+
onCancel: userOnCancel,
|
|
545
|
+
...restConfig
|
|
546
|
+
} = innerConfig;
|
|
547
|
+
return /*#__PURE__*/jsxRuntime.jsx(Modal, {
|
|
548
|
+
...restConfig,
|
|
549
|
+
open: open,
|
|
550
|
+
onClose: () => {
|
|
551
|
+
userOnClose?.();
|
|
552
|
+
close();
|
|
553
|
+
},
|
|
554
|
+
onCancel: function () {
|
|
555
|
+
userOnCancel?.(...[].slice.call(arguments));
|
|
556
|
+
close();
|
|
557
|
+
},
|
|
558
|
+
onConfirm: function () {
|
|
559
|
+
try {
|
|
560
|
+
const _arguments = arguments;
|
|
561
|
+
return Promise.resolve(Promise.resolve(userOnConfirm?.(...[].slice.call(_arguments)))).then(function (res) {
|
|
562
|
+
if (res !== false) {
|
|
563
|
+
close();
|
|
564
|
+
}
|
|
565
|
+
return res;
|
|
566
|
+
});
|
|
567
|
+
} catch (e) {
|
|
568
|
+
return Promise.reject(e);
|
|
569
|
+
}
|
|
570
|
+
},
|
|
571
|
+
afterClose: function () {
|
|
572
|
+
var args = [].slice.call(arguments);
|
|
573
|
+
hookAfterClose?.(...args);
|
|
574
|
+
userAfterClose?.(...args);
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* 命令式内容弹窗:就近 patch 到 ModalLayerProvider(多层)或根 ModalContextHolder。
|
|
581
|
+
* 不走 App.modal.info / ConfirmDialog,层级交给 antd ZIndexContext。
|
|
582
|
+
*/
|
|
583
|
+
const useModal = () => {
|
|
584
|
+
const layer = react.useContext(ModalLayerContext);
|
|
479
585
|
const getScrollElement = responsiveUtils.useScrollElement();
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
586
|
+
const [actionQueue, setActionQueue] = react.useState([]);
|
|
587
|
+
react.useEffect(() => {
|
|
588
|
+
if (actionQueue.length) {
|
|
589
|
+
const cloneQueue = [...actionQueue];
|
|
590
|
+
cloneQueue.forEach(action => action());
|
|
591
|
+
setActionQueue([]);
|
|
592
|
+
}
|
|
593
|
+
}, [actionQueue]);
|
|
594
|
+
return react.useCallback(props => {
|
|
595
|
+
hookModalUuid += 1;
|
|
596
|
+
const modalRef = /*#__PURE__*/react.createRef();
|
|
487
597
|
const api = {};
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
onCancel: function () {
|
|
513
|
-
userOnCancel?.(...[].slice.call(arguments));
|
|
514
|
-
closeModal();
|
|
515
|
-
},
|
|
516
|
-
onConfirm: function () {
|
|
517
|
-
try {
|
|
518
|
-
const _arguments = arguments;
|
|
519
|
-
return Promise.resolve(Promise.resolve(userOnConfirm?.(...[].slice.call(_arguments)))).then(function (res) {
|
|
520
|
-
if (res !== false) {
|
|
521
|
-
closeModal();
|
|
522
|
-
}
|
|
523
|
-
return res;
|
|
524
|
-
});
|
|
525
|
-
} catch (e) {
|
|
526
|
-
return Promise.reject(e);
|
|
598
|
+
let closeFunc;
|
|
599
|
+
let unlock = () => {};
|
|
600
|
+
const resolvePatch = () => layer?.patchElement || rootModalPatchRef.current;
|
|
601
|
+
const runOpen = () => {
|
|
602
|
+
const patch = resolvePatch();
|
|
603
|
+
if (typeof patch !== 'function') {
|
|
604
|
+
throw new Error('useModal requires <ModalContextHolder /> mounted inside <App> before calling useModal()');
|
|
605
|
+
}
|
|
606
|
+
unlock = lockParentScroll(getScrollElement);
|
|
607
|
+
const {
|
|
608
|
+
afterClose: userAfterClose,
|
|
609
|
+
...restProps
|
|
610
|
+
} = props;
|
|
611
|
+
const modalEl = /*#__PURE__*/jsxRuntime.jsx(HookModal, {
|
|
612
|
+
ref: modalRef,
|
|
613
|
+
config: {
|
|
614
|
+
...restProps,
|
|
615
|
+
afterClose: function () {
|
|
616
|
+
unlock();
|
|
617
|
+
userAfterClose?.(...[].slice.call(arguments));
|
|
618
|
+
}
|
|
619
|
+
},
|
|
620
|
+
afterClose: () => {
|
|
621
|
+
closeFunc && closeFunc();
|
|
527
622
|
}
|
|
528
|
-
},
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
623
|
+
}, `react-modal-${hookModalUuid}`);
|
|
624
|
+
closeFunc = patch(modalEl);
|
|
625
|
+
};
|
|
626
|
+
if (resolvePatch()) {
|
|
627
|
+
runOpen();
|
|
628
|
+
} else {
|
|
629
|
+
setActionQueue(prev => [...prev, runOpen]);
|
|
630
|
+
}
|
|
631
|
+
api.close = () => {
|
|
632
|
+
if (modalRef.current) {
|
|
633
|
+
modalRef.current.destroy();
|
|
634
|
+
} else {
|
|
635
|
+
setActionQueue(prev => [...prev, () => modalRef.current?.destroy()]);
|
|
532
636
|
}
|
|
533
|
-
}
|
|
534
|
-
const {
|
|
535
|
-
destroy
|
|
536
|
-
} = modal.info({
|
|
537
|
-
...otherProps,
|
|
538
|
-
afterClose,
|
|
539
|
-
content: children,
|
|
540
|
-
getContainer: resolveModalGetContainer({
|
|
541
|
-
customGetContainer: customGetContainer ?? getContainer,
|
|
542
|
-
getPopupContainer,
|
|
543
|
-
getHostNode: () => anchor
|
|
544
|
-
})
|
|
545
|
-
});
|
|
546
|
-
api.close = destroy;
|
|
637
|
+
};
|
|
547
638
|
return api;
|
|
548
|
-
};
|
|
639
|
+
}, [getScrollElement, layer]);
|
|
549
640
|
};
|
|
550
641
|
|
|
551
642
|
var style = {"kne-responsive-boundary":"kne-react-modal_qwqLr","kne-responsive-scroll":"kne-react-modal_vmry7","drawer":"kne-react-modal_cDsbq","small":"kne-react-modal_3QgK-","is-mobile":"kne-react-modal_FFf73","large":"kne-react-modal_8lell","drawer-body-inner":"kne-react-modal_xgX4D","drawer-antd-header":"kne-react-modal_3EUxr","drawer-antd-footer":"kne-react-modal_2G81L","drawer-antd-body":"kne-react-modal_eKVMu","drawer-outer":"kne-react-modal_P3Cw8","no-title":"kne-react-modal_upRot","no-footer":"kne-react-modal_j4sGu","no-padding":"kne-react-modal_pg37M","drawer-title":"kne-react-modal_-hw5V","drawer-body":"kne-react-modal_nJj7Y","body-scroll-off":"kne-react-modal_2Wh1H","modal-footer-extra":"kne-react-modal_M4hy9","drawer-close":"kne-react-modal_dVh38","drawer-host":"kne-react-modal_Nsxi9","drawer-host-render":"kne-react-modal_iGDWP","drawer-panel-host":"kne-react-modal_A0h-2","drawer-panel-body":"kne-react-modal_E4tcc","drawer-form-host":"kne-react-modal_vKkQW","drawer-wrapper-mobile":"kne-react-modal_vsxOs","drawer-wrapper-mobile-vertical":"kne-react-modal_HG8Vz","drawer-root-mobile":"kne-react-modal_G-qXe"};
|
|
@@ -554,8 +645,10 @@ const DrawerLocaleRoot = withLocale(({
|
|
|
554
645
|
children
|
|
555
646
|
}) => children);
|
|
556
647
|
const VIEWPORT_EXAMPLE_SELECTORS$2 = ['.example-driver-device-scroll'];
|
|
557
|
-
|
|
558
|
-
|
|
648
|
+
|
|
649
|
+
// 与 Modal 一致:真机挂 body+fixed;示例框 / container 模式仍走 boundary(usePopupMount 内判定)
|
|
650
|
+
const viewportPopupMountOptions$2 = {
|
|
651
|
+
cover: 'viewport',
|
|
559
652
|
exampleSelectors: VIEWPORT_EXAMPLE_SELECTORS$2
|
|
560
653
|
};
|
|
561
654
|
const renderWithOptions = (value, options) => {
|
|
@@ -605,51 +698,6 @@ const resolveDrawerGetContainer = ({
|
|
|
605
698
|
return getPopupContainer(triggerNode);
|
|
606
699
|
};
|
|
607
700
|
};
|
|
608
|
-
let parentScrollLockCount = 0;
|
|
609
|
-
let parentScrollLocked = [];
|
|
610
|
-
const lockParentScroll = getScrollElement => {
|
|
611
|
-
parentScrollLockCount += 1;
|
|
612
|
-
if (parentScrollLockCount === 1) {
|
|
613
|
-
const targets = [document.body];
|
|
614
|
-
const scrollEl = typeof getScrollElement === 'function' ? getScrollElement() : null;
|
|
615
|
-
if (scrollEl && scrollEl !== document.body && !targets.includes(scrollEl)) {
|
|
616
|
-
targets.push(scrollEl);
|
|
617
|
-
}
|
|
618
|
-
parentScrollLocked = targets.map(el => {
|
|
619
|
-
const prev = {
|
|
620
|
-
overflow: el.style.overflow,
|
|
621
|
-
overscrollBehavior: el.style.overscrollBehavior
|
|
622
|
-
};
|
|
623
|
-
el.style.overflow = 'hidden';
|
|
624
|
-
el.style.overscrollBehavior = 'none';
|
|
625
|
-
return {
|
|
626
|
-
el,
|
|
627
|
-
prev
|
|
628
|
-
};
|
|
629
|
-
});
|
|
630
|
-
}
|
|
631
|
-
return () => {
|
|
632
|
-
parentScrollLockCount = Math.max(0, parentScrollLockCount - 1);
|
|
633
|
-
if (parentScrollLockCount === 0) {
|
|
634
|
-
parentScrollLocked.forEach(({
|
|
635
|
-
el,
|
|
636
|
-
prev
|
|
637
|
-
}) => {
|
|
638
|
-
el.style.overflow = prev.overflow;
|
|
639
|
-
el.style.overscrollBehavior = prev.overscrollBehavior;
|
|
640
|
-
});
|
|
641
|
-
parentScrollLocked = [];
|
|
642
|
-
}
|
|
643
|
-
};
|
|
644
|
-
};
|
|
645
|
-
const useLockParentScroll = (enabled, getScrollElement) => {
|
|
646
|
-
react.useEffect(() => {
|
|
647
|
-
if (!enabled) {
|
|
648
|
-
return undefined;
|
|
649
|
-
}
|
|
650
|
-
return lockParentScroll(getScrollElement);
|
|
651
|
-
}, [enabled, getScrollElement]);
|
|
652
|
-
};
|
|
653
701
|
const sizeStyleVars = (size, hasFooter) => {
|
|
654
702
|
const minBase = size === 'small' ? 300 : 500;
|
|
655
703
|
const chrome = 48 + (hasFooter ? 69 : 0);
|
|
@@ -896,8 +944,8 @@ const Drawer = withLocale(({
|
|
|
896
944
|
fixedModeClass,
|
|
897
945
|
getPopupContainer,
|
|
898
946
|
anchorRef
|
|
899
|
-
} = responsiveUtils.
|
|
900
|
-
...
|
|
947
|
+
} = responsiveUtils.usePopupMount({
|
|
948
|
+
...viewportPopupMountOptions$2,
|
|
901
949
|
getPopupContainer: wrapCustomGetContainer$1(getContainer)
|
|
902
950
|
});
|
|
903
951
|
const getScrollElement = responsiveUtils.useScrollElement();
|
|
@@ -931,20 +979,11 @@ const Drawer = withLocale(({
|
|
|
931
979
|
});
|
|
932
980
|
});
|
|
933
981
|
|
|
934
|
-
const usePatchElement = () => {
|
|
935
|
-
const [elements, setElements] = react.useState([]);
|
|
936
|
-
const patchElement = react.useCallback(element => {
|
|
937
|
-
setElements(originElements => [...originElements, element]);
|
|
938
|
-
return () => {
|
|
939
|
-
setElements(originElements => originElements.filter(ele => ele !== element));
|
|
940
|
-
};
|
|
941
|
-
}, []);
|
|
942
|
-
return [elements, patchElement];
|
|
943
|
-
};
|
|
944
|
-
|
|
945
982
|
const VIEWPORT_EXAMPLE_SELECTORS$1 = ['.example-driver-device-scroll'];
|
|
946
|
-
|
|
947
|
-
|
|
983
|
+
|
|
984
|
+
// 与 Modal / Drawer 一致:真机 viewport;示例框 / container 仍 boundary
|
|
985
|
+
const viewportPopupMountOptions$1 = {
|
|
986
|
+
cover: 'viewport',
|
|
948
987
|
exampleSelectors: VIEWPORT_EXAMPLE_SELECTORS$1
|
|
949
988
|
};
|
|
950
989
|
const wrapCustomGetContainer = customGetContainer => {
|
|
@@ -970,8 +1009,8 @@ const HookDrawer = /*#__PURE__*/react.forwardRef(({
|
|
|
970
1009
|
const {
|
|
971
1010
|
getPopupContainer,
|
|
972
1011
|
anchorRef
|
|
973
|
-
} = responsiveUtils.
|
|
974
|
-
...
|
|
1012
|
+
} = responsiveUtils.usePopupMount({
|
|
1013
|
+
...viewportPopupMountOptions$1,
|
|
975
1014
|
getPopupContainer: wrapCustomGetContainer(innerConfig.getContainer)
|
|
976
1015
|
});
|
|
977
1016
|
const close = () => {
|
|
@@ -1038,7 +1077,7 @@ const useDrawerHolder = () => {
|
|
|
1038
1077
|
const {
|
|
1039
1078
|
resolveMount,
|
|
1040
1079
|
getPopupContainer
|
|
1041
|
-
} = responsiveUtils.
|
|
1080
|
+
} = responsiveUtils.usePopupMount(viewportPopupMountOptions$1);
|
|
1042
1081
|
const getScrollElement = responsiveUtils.useScrollElement();
|
|
1043
1082
|
react.useEffect(() => {
|
|
1044
1083
|
if (actionQueue.length) {
|
|
@@ -1252,43 +1291,48 @@ const mapConfirmProps = (props, {
|
|
|
1252
1291
|
icon,
|
|
1253
1292
|
isMobile
|
|
1254
1293
|
});
|
|
1294
|
+
|
|
1295
|
+
// Confirm 走 antd ConfirmDialog:未传 zIndex 时用 static 顶层,适合真确认框盖住内容弹窗
|
|
1296
|
+
const config = {
|
|
1297
|
+
...otherProps,
|
|
1298
|
+
okText: confirmText ?? otherProps.okText,
|
|
1299
|
+
cancelText: cancelText ?? otherProps.cancelText,
|
|
1300
|
+
onOk: onConfirm ?? otherProps.onOk,
|
|
1301
|
+
onCancel: onCancel ?? otherProps.onCancel,
|
|
1302
|
+
getContainer: resolveModalGetContainer({
|
|
1303
|
+
customGetContainer,
|
|
1304
|
+
getPopupContainer,
|
|
1305
|
+
getHostNode: () => anchor
|
|
1306
|
+
}),
|
|
1307
|
+
centered: true,
|
|
1308
|
+
afterClose: function () {
|
|
1309
|
+
var args = [].slice.call(arguments);
|
|
1310
|
+
unlock();
|
|
1311
|
+
userAfterClose && userAfterClose(...args);
|
|
1312
|
+
afterClose && afterClose(...args);
|
|
1313
|
+
},
|
|
1314
|
+
icon: null,
|
|
1315
|
+
classNames: {
|
|
1316
|
+
mask: classnames__default["default"](isMobile && modalStyle['modal-mask-fullscreen'], isMobile && fixedModeClass, otherProps.classNames?.mask)
|
|
1317
|
+
},
|
|
1318
|
+
wrapClassName: classnames__default["default"](modalStyle['modal-wrap'], modalStyle['modal-wrap-centered'], confirmStyle['confirm-modal-wrap'], wrapClassName, {
|
|
1319
|
+
[confirmStyle['is-danger']]: danger,
|
|
1320
|
+
[confirmStyle['is-mobile']]: isMobile,
|
|
1321
|
+
[fixedModeClass]: isMobile
|
|
1322
|
+
}),
|
|
1323
|
+
title: confirmTitle ? /*#__PURE__*/jsxRuntime.jsx(ConfirmLocaleRoot, {
|
|
1324
|
+
children: confirmTitle
|
|
1325
|
+
}) : null,
|
|
1326
|
+
content: /*#__PURE__*/jsxRuntime.jsx(ConfirmLocaleRoot, {
|
|
1327
|
+
children: content
|
|
1328
|
+
})
|
|
1329
|
+
};
|
|
1330
|
+
if (zIndex !== undefined) {
|
|
1331
|
+
config.zIndex = zIndex;
|
|
1332
|
+
}
|
|
1255
1333
|
return {
|
|
1256
1334
|
modalMethod: type,
|
|
1257
|
-
config
|
|
1258
|
-
...otherProps,
|
|
1259
|
-
zIndex: zIndex ?? 1100,
|
|
1260
|
-
okText: confirmText ?? otherProps.okText,
|
|
1261
|
-
cancelText: cancelText ?? otherProps.cancelText,
|
|
1262
|
-
onOk: onConfirm ?? otherProps.onOk,
|
|
1263
|
-
onCancel: onCancel ?? otherProps.onCancel,
|
|
1264
|
-
getContainer: resolveModalGetContainer({
|
|
1265
|
-
customGetContainer,
|
|
1266
|
-
getPopupContainer,
|
|
1267
|
-
getHostNode: () => anchor
|
|
1268
|
-
}),
|
|
1269
|
-
centered: true,
|
|
1270
|
-
afterClose: function () {
|
|
1271
|
-
var args = [].slice.call(arguments);
|
|
1272
|
-
unlock();
|
|
1273
|
-
userAfterClose && userAfterClose(...args);
|
|
1274
|
-
afterClose && afterClose(...args);
|
|
1275
|
-
},
|
|
1276
|
-
icon: null,
|
|
1277
|
-
classNames: {
|
|
1278
|
-
mask: classnames__default["default"](isMobile && modalStyle['modal-mask-fullscreen'], isMobile && fixedModeClass, otherProps.classNames?.mask)
|
|
1279
|
-
},
|
|
1280
|
-
wrapClassName: classnames__default["default"](modalStyle['modal-wrap'], modalStyle['modal-wrap-centered'], confirmStyle['confirm-modal-wrap'], wrapClassName, {
|
|
1281
|
-
[confirmStyle['is-danger']]: danger,
|
|
1282
|
-
[confirmStyle['is-mobile']]: isMobile,
|
|
1283
|
-
[fixedModeClass]: isMobile
|
|
1284
|
-
}),
|
|
1285
|
-
title: confirmTitle ? /*#__PURE__*/jsxRuntime.jsx(ConfirmLocaleRoot, {
|
|
1286
|
-
children: confirmTitle
|
|
1287
|
-
}) : null,
|
|
1288
|
-
content: /*#__PURE__*/jsxRuntime.jsx(ConfirmLocaleRoot, {
|
|
1289
|
-
children: content
|
|
1290
|
-
})
|
|
1291
|
-
}
|
|
1335
|
+
config
|
|
1292
1336
|
};
|
|
1293
1337
|
};
|
|
1294
1338
|
const useConfirmModal = () => {
|
|
@@ -1298,7 +1342,7 @@ const useConfirmModal = () => {
|
|
|
1298
1342
|
const {
|
|
1299
1343
|
resolveMount,
|
|
1300
1344
|
getPopupContainer
|
|
1301
|
-
} = responsiveUtils.
|
|
1345
|
+
} = responsiveUtils.usePopupMount(viewportPopupMountOptions);
|
|
1302
1346
|
const getScrollElement = responsiveUtils.useScrollElement();
|
|
1303
1347
|
return props => {
|
|
1304
1348
|
const anchor = typeof document !== 'undefined' ? document.activeElement : null;
|
|
@@ -1306,7 +1350,7 @@ const useConfirmModal = () => {
|
|
|
1306
1350
|
isMobile,
|
|
1307
1351
|
fixedModeClass
|
|
1308
1352
|
} = resolveMount(anchor);
|
|
1309
|
-
const unlock = lockParentScroll
|
|
1353
|
+
const unlock = lockParentScroll(getScrollElement);
|
|
1310
1354
|
const api = {};
|
|
1311
1355
|
const {
|
|
1312
1356
|
afterClose: userAfterClose,
|
|
@@ -1412,6 +1456,8 @@ const modalClassNames = {
|
|
|
1412
1456
|
exports.ColumnsLayout = ColumnsLayout;
|
|
1413
1457
|
exports.Drawer = Drawer;
|
|
1414
1458
|
exports.DrawerContextHolder = DrawerContextHolder;
|
|
1459
|
+
exports.ModalContextHolder = ModalContextHolder;
|
|
1460
|
+
exports.ModalLayerContext = ModalLayerContext;
|
|
1415
1461
|
exports.ScrollRegion = ScrollRegion;
|
|
1416
1462
|
exports.TabsLayout = TabsLayout;
|
|
1417
1463
|
exports.createDrawerRender = createDrawerRender;
|
|
@@ -1421,4 +1467,5 @@ exports.modalClassNames = modalClassNames;
|
|
|
1421
1467
|
exports.useConfirmModal = useConfirmModal;
|
|
1422
1468
|
exports.useDrawer = useDrawer;
|
|
1423
1469
|
exports.useModal = useModal;
|
|
1470
|
+
exports.useModalLayer = useModalLayer;
|
|
1424
1471
|
//# sourceMappingURL=index.js.map
|