antd-mobile 5.42.2-alpha.0 → 5.42.2-alpha.2
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/2x/bundle/antd-mobile.cjs.development.js +14 -6
- package/2x/bundle/antd-mobile.cjs.js +4 -4
- package/2x/bundle/antd-mobile.es.development.js +14 -6
- package/2x/bundle/antd-mobile.es.js +373 -373
- package/2x/bundle/antd-mobile.umd.development.js +14 -6
- package/2x/bundle/antd-mobile.umd.js +4 -4
- package/2x/cjs/components/virtual-input/use-click-outside.d.ts +1 -1
- package/2x/cjs/components/virtual-input/use-click-outside.js +10 -4
- package/2x/cjs/components/virtual-input/virtual-input.js +11 -3
- package/2x/cjs/utils/with-stop-propagation.d.ts +2 -2
- package/2x/cjs/utils/with-stop-propagation.js +5 -0
- package/2x/es/components/virtual-input/use-click-outside.d.ts +1 -1
- package/2x/es/components/virtual-input/use-click-outside.js +10 -4
- package/2x/es/components/virtual-input/virtual-input.js +11 -3
- package/2x/es/utils/with-stop-propagation.d.ts +2 -2
- package/2x/es/utils/with-stop-propagation.js +5 -0
- package/2x/package.json +1 -1
- package/bundle/antd-mobile.cjs.development.js +14 -6
- package/bundle/antd-mobile.cjs.js +4 -4
- package/bundle/antd-mobile.compatible.umd.js +1 -1
- package/bundle/antd-mobile.es.development.js +14 -6
- package/bundle/antd-mobile.es.js +373 -373
- package/bundle/antd-mobile.umd.development.js +14 -6
- package/bundle/antd-mobile.umd.js +4 -4
- package/cjs/components/virtual-input/use-click-outside.d.ts +1 -1
- package/cjs/components/virtual-input/use-click-outside.js +10 -4
- package/cjs/components/virtual-input/virtual-input.js +11 -3
- package/cjs/utils/with-stop-propagation.d.ts +2 -2
- package/cjs/utils/with-stop-propagation.js +5 -0
- package/es/components/virtual-input/use-click-outside.d.ts +1 -1
- package/es/components/virtual-input/use-click-outside.js +10 -4
- package/es/components/virtual-input/virtual-input.js +11 -3
- package/es/utils/with-stop-propagation.d.ts +2 -2
- package/es/utils/with-stop-propagation.js +5 -0
- package/package.json +1 -1
- package/umd/antd-mobile.js +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare function useClickOutside(handler: (event: MouseEvent) => void, ref: React.RefObject<HTMLElement
|
|
1
|
+
declare function useClickOutside(handler: (event: MouseEvent) => void, ref: React.RefObject<HTMLElement>, hasKeyboardProps?: boolean): void;
|
|
2
2
|
export default useClickOutside;
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
// 监听点击组件外部的事件
|
|
9
|
-
function useClickOutside(handler, ref) {
|
|
9
|
+
function useClickOutside(handler, ref, hasKeyboardProps = false) {
|
|
10
10
|
(0, _react.useEffect)(() => {
|
|
11
11
|
function handleClick(event) {
|
|
12
12
|
if (!ref.current || ref.current.contains(event.target)) {
|
|
@@ -14,10 +14,16 @@ function useClickOutside(handler, ref) {
|
|
|
14
14
|
}
|
|
15
15
|
handler(event);
|
|
16
16
|
}
|
|
17
|
-
//
|
|
18
|
-
|
|
17
|
+
// 向前兼容逻辑:
|
|
18
|
+
// 1. 对于有键盘属性的 VirtualInput,在捕获阶段监听:
|
|
19
|
+
// 这是为了确保在事件被阻止传播之前触发。比如输入框中的单个数字 click 事件会 stopPropagation, 但这里依然能捕获到
|
|
20
|
+
// 2. 对于无键盘属性的 VirtualInput 组件,在冒泡阶段监听:
|
|
21
|
+
// 这种情况通常是 VirtualInput + NumberKeyboard 为兄弟关系,在以前版本中点击 NumberKeyboard **不会**触发 VirtualInput 的 blur 事件
|
|
22
|
+
// 原先原理:通过 NumberKeyboard 内部 onMouseDown 时 preventDefault 阻止的 VirtualInput 内原生的 blur 事件
|
|
23
|
+
// 新的原理:NumberKeyboard 的 Popup 默认会 stopPropagation click, 这里在冒泡阶段监听不到,不会调用 VirtualInput 的 onBlur 回调(非原生事件)。
|
|
24
|
+
document.addEventListener('click', handleClick, hasKeyboardProps ? true : false);
|
|
19
25
|
return () => {
|
|
20
|
-
document.removeEventListener('click', handleClick, true);
|
|
26
|
+
document.removeEventListener('click', handleClick, hasKeyboardProps ? true : false);
|
|
21
27
|
};
|
|
22
28
|
}, [handler, ref]);
|
|
23
29
|
}
|
|
@@ -100,7 +100,7 @@ const VirtualInput = (0, _react.forwardRef)((props, ref) => {
|
|
|
100
100
|
}
|
|
101
101
|
(0, _useClickOutside.default)(() => {
|
|
102
102
|
setBlur();
|
|
103
|
-
}, rootRef);
|
|
103
|
+
}, rootRef, !!mergedProps.keyboard);
|
|
104
104
|
const keyboard = mergedProps.keyboard;
|
|
105
105
|
const keyboardElement = keyboard && _react.default.cloneElement(keyboard, {
|
|
106
106
|
onInput: v => {
|
|
@@ -128,15 +128,23 @@ const VirtualInput = (0, _react.forwardRef)((props, ref) => {
|
|
|
128
128
|
},
|
|
129
129
|
visible: hasFocus,
|
|
130
130
|
onClose: () => {
|
|
131
|
-
var _a, _b;
|
|
131
|
+
var _a, _b, _c;
|
|
132
|
+
const activeElement = document.activeElement;
|
|
133
|
+
if (activeElement === contentRef.current) {
|
|
134
|
+
// 点击 NumberKeyboard 的确认和关闭时不会触发输入框的 blur 事件,手动调用让其失焦,否则之后无法 focus
|
|
135
|
+
(_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
136
|
+
}
|
|
132
137
|
setBlur();
|
|
133
|
-
(
|
|
138
|
+
(_c = (_b = keyboard.props).onClose) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
134
139
|
},
|
|
135
140
|
getContainer: null
|
|
136
141
|
});
|
|
137
142
|
// 点击输入框时,将光标置于最后
|
|
138
143
|
const setCaretPositionToEnd = e => {
|
|
139
144
|
var _a, _b, _c;
|
|
145
|
+
if (mergedProps.disabled) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
140
148
|
if (caretPosition !== value.length) {
|
|
141
149
|
setCaretPosition(value.length);
|
|
142
150
|
(_b = (_a = mergedProps.cursor) === null || _a === void 0 ? void 0 : _a.onMove) === null || _b === void 0 ? void 0 : _b.call(_a, value.length);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import type { ReactElement } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
3
|
export declare type PropagationEvent = 'click' | 'touchstart';
|
|
4
|
-
export declare function withStopPropagation(events: PropagationEvent[], element: ReactElement):
|
|
4
|
+
export declare function withStopPropagation(events: PropagationEvent[], element: ReactElement): ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
@@ -17,6 +17,11 @@ function withStopPropagation(events, element) {
|
|
|
17
17
|
props[prop] = function (e) {
|
|
18
18
|
var _a, _b;
|
|
19
19
|
e.stopPropagation();
|
|
20
|
+
// react <=16 事件绑定在 document,因此上面的 stopPropagation 无法阻止事件冒泡到用原生方式监听的 document 的事件回调中
|
|
21
|
+
// 增加 stopImmediatePropagation 可以阻止事件在**后绑定**的 document 上的回调执行
|
|
22
|
+
// 专用于解决 VirtualInput useClickOutside 的问题
|
|
23
|
+
// react >=17 则无此问题,事件会绑定在 React 根节点上
|
|
24
|
+
e.nativeEvent.stopImmediatePropagation();
|
|
20
25
|
(_b = (_a = element.props)[prop]) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
21
26
|
};
|
|
22
27
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare function useClickOutside(handler: (event: MouseEvent) => void, ref: React.RefObject<HTMLElement
|
|
1
|
+
declare function useClickOutside(handler: (event: MouseEvent) => void, ref: React.RefObject<HTMLElement>, hasKeyboardProps?: boolean): void;
|
|
2
2
|
export default useClickOutside;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
// 监听点击组件外部的事件
|
|
3
|
-
function useClickOutside(handler, ref) {
|
|
3
|
+
function useClickOutside(handler, ref, hasKeyboardProps = false) {
|
|
4
4
|
useEffect(() => {
|
|
5
5
|
function handleClick(event) {
|
|
6
6
|
if (!ref.current || ref.current.contains(event.target)) {
|
|
@@ -8,10 +8,16 @@ function useClickOutside(handler, ref) {
|
|
|
8
8
|
}
|
|
9
9
|
handler(event);
|
|
10
10
|
}
|
|
11
|
-
//
|
|
12
|
-
|
|
11
|
+
// 向前兼容逻辑:
|
|
12
|
+
// 1. 对于有键盘属性的 VirtualInput,在捕获阶段监听:
|
|
13
|
+
// 这是为了确保在事件被阻止传播之前触发。比如输入框中的单个数字 click 事件会 stopPropagation, 但这里依然能捕获到
|
|
14
|
+
// 2. 对于无键盘属性的 VirtualInput 组件,在冒泡阶段监听:
|
|
15
|
+
// 这种情况通常是 VirtualInput + NumberKeyboard 为兄弟关系,在以前版本中点击 NumberKeyboard **不会**触发 VirtualInput 的 blur 事件
|
|
16
|
+
// 原先原理:通过 NumberKeyboard 内部 onMouseDown 时 preventDefault 阻止的 VirtualInput 内原生的 blur 事件
|
|
17
|
+
// 新的原理:NumberKeyboard 的 Popup 默认会 stopPropagation click, 这里在冒泡阶段监听不到,不会调用 VirtualInput 的 onBlur 回调(非原生事件)。
|
|
18
|
+
document.addEventListener('click', handleClick, hasKeyboardProps ? true : false);
|
|
13
19
|
return () => {
|
|
14
|
-
document.removeEventListener('click', handleClick, true);
|
|
20
|
+
document.removeEventListener('click', handleClick, hasKeyboardProps ? true : false);
|
|
15
21
|
};
|
|
16
22
|
}, [handler, ref]);
|
|
17
23
|
}
|
|
@@ -91,7 +91,7 @@ export const VirtualInput = forwardRef((props, ref) => {
|
|
|
91
91
|
}
|
|
92
92
|
useClickOutside(() => {
|
|
93
93
|
setBlur();
|
|
94
|
-
}, rootRef);
|
|
94
|
+
}, rootRef, !!mergedProps.keyboard);
|
|
95
95
|
const keyboard = mergedProps.keyboard;
|
|
96
96
|
const keyboardElement = keyboard && React.cloneElement(keyboard, {
|
|
97
97
|
onInput: v => {
|
|
@@ -119,15 +119,23 @@ export const VirtualInput = forwardRef((props, ref) => {
|
|
|
119
119
|
},
|
|
120
120
|
visible: hasFocus,
|
|
121
121
|
onClose: () => {
|
|
122
|
-
var _a, _b;
|
|
122
|
+
var _a, _b, _c;
|
|
123
|
+
const activeElement = document.activeElement;
|
|
124
|
+
if (activeElement === contentRef.current) {
|
|
125
|
+
// 点击 NumberKeyboard 的确认和关闭时不会触发输入框的 blur 事件,手动调用让其失焦,否则之后无法 focus
|
|
126
|
+
(_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
127
|
+
}
|
|
123
128
|
setBlur();
|
|
124
|
-
(
|
|
129
|
+
(_c = (_b = keyboard.props).onClose) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
125
130
|
},
|
|
126
131
|
getContainer: null
|
|
127
132
|
});
|
|
128
133
|
// 点击输入框时,将光标置于最后
|
|
129
134
|
const setCaretPositionToEnd = e => {
|
|
130
135
|
var _a, _b, _c;
|
|
136
|
+
if (mergedProps.disabled) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
131
139
|
if (caretPosition !== value.length) {
|
|
132
140
|
setCaretPosition(value.length);
|
|
133
141
|
(_b = (_a = mergedProps.cursor) === null || _a === void 0 ? void 0 : _a.onMove) === null || _b === void 0 ? void 0 : _b.call(_a, value.length);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import type { ReactElement } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
3
|
export declare type PropagationEvent = 'click' | 'touchstart';
|
|
4
|
-
export declare function withStopPropagation(events: PropagationEvent[], element: ReactElement):
|
|
4
|
+
export declare function withStopPropagation(events: PropagationEvent[], element: ReactElement): ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
@@ -10,6 +10,11 @@ export function withStopPropagation(events, element) {
|
|
|
10
10
|
props[prop] = function (e) {
|
|
11
11
|
var _a, _b;
|
|
12
12
|
e.stopPropagation();
|
|
13
|
+
// react <=16 事件绑定在 document,因此上面的 stopPropagation 无法阻止事件冒泡到用原生方式监听的 document 的事件回调中
|
|
14
|
+
// 增加 stopImmediatePropagation 可以阻止事件在**后绑定**的 document 上的回调执行
|
|
15
|
+
// 专用于解决 VirtualInput useClickOutside 的问题
|
|
16
|
+
// react >=17 则无此问题,事件会绑定在 React 根节点上
|
|
17
|
+
e.nativeEvent.stopImmediatePropagation();
|
|
13
18
|
(_b = (_a = element.props)[prop]) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
14
19
|
};
|
|
15
20
|
}
|
package/2x/package.json
CHANGED
|
@@ -5834,6 +5834,7 @@ function withStopPropagation(events, element) {
|
|
|
5834
5834
|
props[prop] = function(e2) {
|
|
5835
5835
|
var _a, _b;
|
|
5836
5836
|
e2.stopPropagation();
|
|
5837
|
+
e2.nativeEvent.stopImmediatePropagation();
|
|
5837
5838
|
(_b = (_a = element.props)[prop]) === null || _b === void 0 ? void 0 : _b.call(_a, e2);
|
|
5838
5839
|
};
|
|
5839
5840
|
}
|
|
@@ -27604,7 +27605,7 @@ const Multiple = (p) => {
|
|
|
27604
27605
|
const index = attachPropertiesToComponent(TreeSelect, {
|
|
27605
27606
|
Multiple
|
|
27606
27607
|
});
|
|
27607
|
-
function useClickOutside(handler, ref2) {
|
|
27608
|
+
function useClickOutside(handler, ref2, hasKeyboardProps = false) {
|
|
27608
27609
|
React$3.useEffect(() => {
|
|
27609
27610
|
function handleClick(event) {
|
|
27610
27611
|
if (!ref2.current || ref2.current.contains(event.target)) {
|
|
@@ -27612,9 +27613,9 @@ function useClickOutside(handler, ref2) {
|
|
|
27612
27613
|
}
|
|
27613
27614
|
handler(event);
|
|
27614
27615
|
}
|
|
27615
|
-
document.addEventListener("click", handleClick, true);
|
|
27616
|
+
document.addEventListener("click", handleClick, hasKeyboardProps ? true : false);
|
|
27616
27617
|
return () => {
|
|
27617
|
-
document.removeEventListener("click", handleClick, true);
|
|
27618
|
+
document.removeEventListener("click", handleClick, hasKeyboardProps ? true : false);
|
|
27618
27619
|
};
|
|
27619
27620
|
}, [handler, ref2]);
|
|
27620
27621
|
}
|
|
@@ -27702,7 +27703,7 @@ const VirtualInput = React$3.forwardRef((props, ref2) => {
|
|
|
27702
27703
|
}
|
|
27703
27704
|
useClickOutside(() => {
|
|
27704
27705
|
setBlur();
|
|
27705
|
-
}, rootRef);
|
|
27706
|
+
}, rootRef, !!mergedProps.keyboard);
|
|
27706
27707
|
const keyboard = mergedProps.keyboard;
|
|
27707
27708
|
const keyboardElement = keyboard && React$3.cloneElement(keyboard, {
|
|
27708
27709
|
onInput: (v) => {
|
|
@@ -27729,14 +27730,21 @@ const VirtualInput = React$3.forwardRef((props, ref2) => {
|
|
|
27729
27730
|
},
|
|
27730
27731
|
visible: hasFocus,
|
|
27731
27732
|
onClose: () => {
|
|
27732
|
-
var _a, _b;
|
|
27733
|
+
var _a, _b, _c;
|
|
27734
|
+
const activeElement = document.activeElement;
|
|
27735
|
+
if (activeElement === contentRef.current) {
|
|
27736
|
+
(_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
27737
|
+
}
|
|
27733
27738
|
setBlur();
|
|
27734
|
-
(
|
|
27739
|
+
(_c = (_b = keyboard.props).onClose) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
27735
27740
|
},
|
|
27736
27741
|
getContainer: null
|
|
27737
27742
|
});
|
|
27738
27743
|
const setCaretPositionToEnd = (e2) => {
|
|
27739
27744
|
var _a, _b, _c;
|
|
27745
|
+
if (mergedProps.disabled) {
|
|
27746
|
+
return;
|
|
27747
|
+
}
|
|
27740
27748
|
if (caretPosition !== value.length) {
|
|
27741
27749
|
setCaretPosition(value.length);
|
|
27742
27750
|
(_b = (_a = mergedProps.cursor) === null || _a === void 0 ? void 0 : _a.onMove) === null || _b === void 0 ? void 0 : _b.call(_a, value.length);
|