antd-mobile 5.3.1 → 5.4.0
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/cjs/components/floating-bubble/floating-bubble.d.ts +2 -0
- package/2x/cjs/components/floating-bubble/floating-bubble.js +47 -16
- package/2x/cjs/components/form/form.js +1 -1
- package/2x/cjs/components/infinite-scroll/infinite-scroll.js +23 -19
- package/2x/cjs/components/modal/modal.js +0 -1
- package/2x/cjs/components/notice-bar/notice-bar.js +1 -1
- package/2x/cjs/components/search-bar/search-bar.js +0 -1
- package/2x/cjs/components/swiper/swiper.js +1 -1
- package/2x/cjs/components/text-area/text-area.css +4 -1
- package/2x/cjs/components/text-area/text-area.d.ts +2 -2
- package/2x/es/components/floating-bubble/floating-bubble.d.ts +2 -0
- package/2x/es/components/floating-bubble/floating-bubble.js +48 -17
- package/2x/es/components/form/form.js +1 -1
- package/2x/es/components/infinite-scroll/infinite-scroll.js +22 -19
- package/2x/es/components/modal/modal.js +0 -1
- package/2x/es/components/notice-bar/notice-bar.js +1 -1
- package/2x/es/components/search-bar/search-bar.js +0 -1
- package/2x/es/components/swiper/swiper.js +1 -1
- package/2x/es/components/text-area/text-area.css +4 -1
- package/2x/es/components/text-area/text-area.d.ts +2 -2
- package/2x/package.json +1 -1
- package/cjs/components/floating-bubble/floating-bubble.d.ts +2 -0
- package/cjs/components/floating-bubble/floating-bubble.js +47 -16
- package/cjs/components/form/form.js +1 -1
- package/cjs/components/infinite-scroll/infinite-scroll.js +23 -19
- package/cjs/components/modal/modal.js +0 -1
- package/cjs/components/notice-bar/notice-bar.js +1 -1
- package/cjs/components/search-bar/search-bar.js +0 -1
- package/cjs/components/swiper/swiper.js +1 -1
- package/cjs/components/text-area/text-area.css +4 -1
- package/cjs/components/text-area/text-area.d.ts +2 -2
- package/es/components/floating-bubble/floating-bubble.d.ts +2 -0
- package/es/components/floating-bubble/floating-bubble.js +48 -17
- package/es/components/form/form.js +1 -1
- package/es/components/infinite-scroll/infinite-scroll.js +22 -19
- package/es/components/modal/modal.js +0 -1
- package/es/components/notice-bar/notice-bar.js +1 -1
- package/es/components/search-bar/search-bar.js +0 -1
- package/es/components/swiper/swiper.js +1 -1
- package/es/components/text-area/text-area.css +4 -1
- package/es/components/text-area/text-area.d.ts +2 -2
- package/package.json +1 -1
- package/umd/antd-mobile.js +1 -1
|
@@ -2,5 +2,7 @@ import React, { FC } from 'react';
|
|
|
2
2
|
import { NativeProps } from '../../utils/native-props';
|
|
3
3
|
export declare type FloatingBubbleProps = {
|
|
4
4
|
onClick?: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
|
|
5
|
+
axis?: 'x' | 'y' | 'xy' | 'lock';
|
|
6
|
+
magnetic?: 'x' | 'y';
|
|
5
7
|
} & NativeProps<'--initial-position-left' | '--initial-position-right' | '--initial-position-top' | '--initial-position-bottom' | '--z-index' | '--edge-distance' | '--size' | '--border-radius'>;
|
|
6
8
|
export declare const FloatingBubble: FC<FloatingBubbleProps>;
|
|
@@ -20,45 +20,72 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
20
20
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
21
|
|
|
22
22
|
const classPrefix = `adm-floating-bubble`;
|
|
23
|
-
const defaultProps = {
|
|
23
|
+
const defaultProps = {
|
|
24
|
+
axis: 'y'
|
|
25
|
+
};
|
|
24
26
|
|
|
25
27
|
const FloatingBubble = p => {
|
|
26
28
|
const props = (0, _withDefaultProps.mergeProps)(defaultProps, p);
|
|
27
29
|
const boundaryRef = (0, _react.useRef)(null);
|
|
30
|
+
const buttonRef = (0, _react.useRef)(null);
|
|
28
31
|
/**
|
|
29
32
|
* memoize the `to` function
|
|
30
33
|
* inside a component that renders frequently
|
|
31
34
|
* to prevent an unintended restart
|
|
32
35
|
*/
|
|
33
36
|
|
|
34
|
-
const [
|
|
37
|
+
const [{
|
|
38
|
+
x,
|
|
39
|
+
y,
|
|
40
|
+
opacity
|
|
41
|
+
}, api] = (0, _web.useSpring)(() => ({
|
|
42
|
+
x: 0,
|
|
35
43
|
y: 0,
|
|
36
|
-
scale: 1,
|
|
37
44
|
opacity: 1
|
|
38
45
|
}));
|
|
39
46
|
const bind = (0, _react2.useDrag)(state => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
let nextX = state.offset[0];
|
|
48
|
+
let nextY = state.offset[1];
|
|
49
|
+
|
|
50
|
+
if (state.last) {
|
|
51
|
+
const boundary = boundaryRef.current;
|
|
52
|
+
const button = buttonRef.current;
|
|
53
|
+
if (!boundary || !button) return;
|
|
54
|
+
|
|
55
|
+
if (props.magnetic === 'x') {
|
|
56
|
+
const compensation = x.goal - x.get();
|
|
57
|
+
const boundaryRect = boundary.getBoundingClientRect();
|
|
58
|
+
const buttonRect = button.getBoundingClientRect();
|
|
59
|
+
const leftDistance = buttonRect.left + compensation - boundaryRect.left;
|
|
60
|
+
const rightDistance = boundaryRect.right - (buttonRect.right + compensation);
|
|
46
61
|
|
|
62
|
+
if (rightDistance <= leftDistance) {
|
|
63
|
+
nextX += rightDistance;
|
|
64
|
+
} else {
|
|
65
|
+
nextX -= leftDistance;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
47
69
|
|
|
48
|
-
|
|
49
|
-
|
|
70
|
+
api.start({
|
|
71
|
+
x: nextX,
|
|
72
|
+
y: nextY // immediate: !state.last,
|
|
73
|
+
|
|
74
|
+
}); // active status
|
|
75
|
+
|
|
76
|
+
api.start({
|
|
50
77
|
opacity: state.active ? 0.8 : 1
|
|
51
78
|
});
|
|
52
79
|
}, {
|
|
53
|
-
|
|
54
|
-
axis: 'y',
|
|
80
|
+
axis: props.axis === 'xy' ? undefined : props.axis,
|
|
55
81
|
pointer: {
|
|
56
82
|
touch: true
|
|
57
83
|
},
|
|
58
84
|
// the component won't trigger drag logic if the user just clicked on the component.
|
|
59
85
|
filterTaps: true,
|
|
60
86
|
// set constraints to the user gesture
|
|
61
|
-
bounds: boundaryRef
|
|
87
|
+
bounds: boundaryRef,
|
|
88
|
+
from: () => [x.get(), y.get()]
|
|
62
89
|
});
|
|
63
90
|
return (0, _nativeProps.withNativeProps)(props, _react.default.createElement("div", {
|
|
64
91
|
className: classPrefix
|
|
@@ -68,9 +95,13 @@ const FloatingBubble = p => {
|
|
|
68
95
|
className: `${classPrefix}-boundary`,
|
|
69
96
|
ref: boundaryRef
|
|
70
97
|
})), _react.default.createElement(_web.animated.div, Object.assign({}, bind(), {
|
|
71
|
-
style:
|
|
98
|
+
style: {
|
|
99
|
+
opacity,
|
|
100
|
+
transform: (0, _web.to)([x, y], (x, y) => `translate(${x}px, ${y}px)`)
|
|
101
|
+
},
|
|
72
102
|
onClick: props.onClick,
|
|
73
|
-
className: `${classPrefix}-button
|
|
103
|
+
className: `${classPrefix}-button`,
|
|
104
|
+
ref: buttonRef
|
|
74
105
|
}), props.children)));
|
|
75
106
|
};
|
|
76
107
|
|
|
@@ -66,7 +66,7 @@ const Form = (0, _react.forwardRef)((p, ref) => {
|
|
|
66
66
|
items = [];
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
_react.default.Children.forEach(props.children,
|
|
69
|
+
_react.default.Children.forEach(props.children, child => {
|
|
70
70
|
if (_react.default.isValidElement(child) && child.type === _header.Header) {
|
|
71
71
|
collect();
|
|
72
72
|
currentHeader = child.props.children;
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.InfiniteScroll = void 0;
|
|
7
7
|
|
|
8
|
+
var _tslib = require("tslib");
|
|
9
|
+
|
|
8
10
|
var _withDefaultProps = require("../../utils/with-default-props");
|
|
9
11
|
|
|
10
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
@@ -41,25 +43,27 @@ const InfiniteScroll = p => {
|
|
|
41
43
|
}, p);
|
|
42
44
|
const doLoadMore = (0, _ahooks.useLockFn)(() => props.loadMore());
|
|
43
45
|
const elementRef = (0, _react.useRef)(null);
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
46
|
+
const [flag, setFlag] = (0, _react.useState)({});
|
|
47
|
+
const nextFlagRef = (0, _react.useRef)(flag);
|
|
48
|
+
const check = (0, _ahooks.useMemoizedFn)(() => (0, _tslib.__awaiter)(void 0, void 0, void 0, function* () {
|
|
49
|
+
if (nextFlagRef.current !== flag) return;
|
|
50
|
+
if (!props.hasMore) return;
|
|
51
|
+
const element = elementRef.current;
|
|
52
|
+
if (!element) return;
|
|
53
|
+
if (!element.offsetParent) return;
|
|
54
|
+
const parent = (0, _getScrollParent.getScrollParent)(element);
|
|
55
|
+
if (!parent) return;
|
|
56
|
+
const rect = element.getBoundingClientRect();
|
|
57
|
+
const elementTop = rect.top;
|
|
58
|
+
const current = isWindow(parent) ? window.innerHeight : parent.getBoundingClientRect().bottom;
|
|
59
|
+
|
|
60
|
+
if (current >= elementTop - props.threshold) {
|
|
61
|
+
const nextFlag = {};
|
|
62
|
+
nextFlagRef.current = nextFlag;
|
|
63
|
+
yield doLoadMore();
|
|
64
|
+
setFlag(nextFlag);
|
|
65
|
+
}
|
|
66
|
+
})); // 确保在内容不足时会自动触发加载事件
|
|
63
67
|
|
|
64
68
|
(0, _react.useEffect)(() => {
|
|
65
69
|
check();
|
|
@@ -41,7 +41,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
41
41
|
|
|
42
42
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
43
43
|
|
|
44
|
-
const classPrefix = `adm-modal`;
|
|
45
44
|
const defaultProps = {
|
|
46
45
|
visible: false,
|
|
47
46
|
actions: [],
|
|
@@ -76,7 +76,7 @@ const NoticeBar = (0, _react.memo)(p => {
|
|
|
76
76
|
delayLockRef.current = false;
|
|
77
77
|
start();
|
|
78
78
|
}, props.delay);
|
|
79
|
-
(0, _useResizeEffect.useResizeEffect)(
|
|
79
|
+
(0, _useResizeEffect.useResizeEffect)(() => {
|
|
80
80
|
start();
|
|
81
81
|
}, containerRef);
|
|
82
82
|
(0, _useMutationEffect.useMutationEffect)(() => {
|
|
@@ -67,7 +67,6 @@ const SearchBar = (0, _react.forwardRef)((p, ref) => {
|
|
|
67
67
|
|
|
68
68
|
const renderCancelButton = () => {
|
|
69
69
|
let isShowCancel = false;
|
|
70
|
-
const showCancelButton = props.showCancelButton;
|
|
71
70
|
|
|
72
71
|
if (typeof props.showCancelButton === 'function') {
|
|
73
72
|
isShowCancel = props.showCancelButton(hasFocus, value);
|
|
@@ -258,7 +258,7 @@ const Swiper = (0, _react.forwardRef)((0, _stagedComponents.staged)((p, ref) =>
|
|
|
258
258
|
style: {
|
|
259
259
|
[isVertical ? 'y' : 'x']: position.to(position => `${-position}%`)
|
|
260
260
|
}
|
|
261
|
-
}, _react.default.Children.map(validChildren,
|
|
261
|
+
}, _react.default.Children.map(validChildren, child => {
|
|
262
262
|
return _react.default.createElement("div", {
|
|
263
263
|
className: 'adm-swiper-slide'
|
|
264
264
|
}, child);
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
--color: var(--adm-color-text);
|
|
4
4
|
--placeholder-color: var(--adm-color-light);
|
|
5
5
|
--disabled-color: var(--adm-color-weak);
|
|
6
|
+
--text-align: left;
|
|
7
|
+
--count-text-align: right;
|
|
6
8
|
width: 100%;
|
|
7
9
|
max-width: 100%;
|
|
8
10
|
max-height: 100%;
|
|
@@ -27,6 +29,7 @@
|
|
|
27
29
|
outline: none;
|
|
28
30
|
appearance: none;
|
|
29
31
|
min-height: 1.5em;
|
|
32
|
+
text-align: var(--text-align);
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
.adm-text-area-element::placeholder {
|
|
@@ -62,7 +65,7 @@
|
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
.adm-text-area-count {
|
|
65
|
-
text-align:
|
|
68
|
+
text-align: var(--count-text-align);
|
|
66
69
|
color: var(--adm-color-weak);
|
|
67
70
|
font-size: 34px;
|
|
68
71
|
padding-top: 16px;
|
|
@@ -14,7 +14,7 @@ export declare type TextAreaProps = Pick<React.DetailedHTMLProps<React.TextareaH
|
|
|
14
14
|
maxRows?: number;
|
|
15
15
|
};
|
|
16
16
|
id?: string;
|
|
17
|
-
} & NativeProps<'--font-size' | '--color' | '--placeholder-color' | '--disabled-color'>;
|
|
17
|
+
} & NativeProps<'--font-size' | '--color' | '--placeholder-color' | '--disabled-color' | '--text-align' | '--count-text-align'>;
|
|
18
18
|
export declare type TextAreaRef = {
|
|
19
19
|
clear: () => void;
|
|
20
20
|
focus: () => void;
|
|
@@ -33,4 +33,4 @@ export declare const TextArea: React.ForwardRefExoticComponent<Pick<React.Detail
|
|
|
33
33
|
maxRows?: number | undefined;
|
|
34
34
|
} | undefined;
|
|
35
35
|
id?: string | undefined;
|
|
36
|
-
} & NativeProps<"--color" | "--font-size" | "--placeholder-color" | "--disabled-color"> & React.RefAttributes<TextAreaRef>>;
|
|
36
|
+
} & NativeProps<"--color" | "--font-size" | "--placeholder-color" | "--text-align" | "--disabled-color" | "--count-text-align"> & React.RefAttributes<TextAreaRef>>;
|
|
@@ -2,5 +2,7 @@ import React, { FC } from 'react';
|
|
|
2
2
|
import { NativeProps } from '../../utils/native-props';
|
|
3
3
|
export declare type FloatingBubbleProps = {
|
|
4
4
|
onClick?: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
|
|
5
|
+
axis?: 'x' | 'y' | 'xy' | 'lock';
|
|
6
|
+
magnetic?: 'x' | 'y';
|
|
5
7
|
} & NativeProps<'--initial-position-left' | '--initial-position-right' | '--initial-position-top' | '--initial-position-bottom' | '--z-index' | '--edge-distance' | '--size' | '--border-radius'>;
|
|
6
8
|
export declare const FloatingBubble: FC<FloatingBubbleProps>;
|
|
@@ -1,47 +1,74 @@
|
|
|
1
1
|
import React, { useRef } from 'react';
|
|
2
|
-
import { useSpring, animated } from '@react-spring/web';
|
|
2
|
+
import { useSpring, animated, to } from '@react-spring/web';
|
|
3
3
|
import { useDrag } from '@use-gesture/react';
|
|
4
4
|
import { mergeProps } from '../../utils/with-default-props';
|
|
5
5
|
import { withNativeProps } from '../../utils/native-props';
|
|
6
6
|
const classPrefix = `adm-floating-bubble`;
|
|
7
|
-
const defaultProps = {
|
|
7
|
+
const defaultProps = {
|
|
8
|
+
axis: 'y'
|
|
9
|
+
};
|
|
8
10
|
export const FloatingBubble = p => {
|
|
9
11
|
const props = mergeProps(defaultProps, p);
|
|
10
12
|
const boundaryRef = useRef(null);
|
|
13
|
+
const buttonRef = useRef(null);
|
|
11
14
|
/**
|
|
12
15
|
* memoize the `to` function
|
|
13
16
|
* inside a component that renders frequently
|
|
14
17
|
* to prevent an unintended restart
|
|
15
18
|
*/
|
|
16
19
|
|
|
17
|
-
const [
|
|
20
|
+
const [{
|
|
21
|
+
x,
|
|
22
|
+
y,
|
|
23
|
+
opacity
|
|
24
|
+
}, api] = useSpring(() => ({
|
|
25
|
+
x: 0,
|
|
18
26
|
y: 0,
|
|
19
|
-
scale: 1,
|
|
20
27
|
opacity: 1
|
|
21
28
|
}));
|
|
22
29
|
const bind = useDrag(state => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
animation.start({
|
|
26
|
-
y: state.offset[1]
|
|
27
|
-
});
|
|
28
|
-
} // active status
|
|
30
|
+
let nextX = state.offset[0];
|
|
31
|
+
let nextY = state.offset[1];
|
|
29
32
|
|
|
33
|
+
if (state.last) {
|
|
34
|
+
const boundary = boundaryRef.current;
|
|
35
|
+
const button = buttonRef.current;
|
|
36
|
+
if (!boundary || !button) return;
|
|
30
37
|
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
if (props.magnetic === 'x') {
|
|
39
|
+
const compensation = x.goal - x.get();
|
|
40
|
+
const boundaryRect = boundary.getBoundingClientRect();
|
|
41
|
+
const buttonRect = button.getBoundingClientRect();
|
|
42
|
+
const leftDistance = buttonRect.left + compensation - boundaryRect.left;
|
|
43
|
+
const rightDistance = boundaryRect.right - (buttonRect.right + compensation);
|
|
44
|
+
|
|
45
|
+
if (rightDistance <= leftDistance) {
|
|
46
|
+
nextX += rightDistance;
|
|
47
|
+
} else {
|
|
48
|
+
nextX -= leftDistance;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
api.start({
|
|
54
|
+
x: nextX,
|
|
55
|
+
y: nextY // immediate: !state.last,
|
|
56
|
+
|
|
57
|
+
}); // active status
|
|
58
|
+
|
|
59
|
+
api.start({
|
|
33
60
|
opacity: state.active ? 0.8 : 1
|
|
34
61
|
});
|
|
35
62
|
}, {
|
|
36
|
-
|
|
37
|
-
axis: 'y',
|
|
63
|
+
axis: props.axis === 'xy' ? undefined : props.axis,
|
|
38
64
|
pointer: {
|
|
39
65
|
touch: true
|
|
40
66
|
},
|
|
41
67
|
// the component won't trigger drag logic if the user just clicked on the component.
|
|
42
68
|
filterTaps: true,
|
|
43
69
|
// set constraints to the user gesture
|
|
44
|
-
bounds: boundaryRef
|
|
70
|
+
bounds: boundaryRef,
|
|
71
|
+
from: () => [x.get(), y.get()]
|
|
45
72
|
});
|
|
46
73
|
return withNativeProps(props, React.createElement("div", {
|
|
47
74
|
className: classPrefix
|
|
@@ -51,8 +78,12 @@ export const FloatingBubble = p => {
|
|
|
51
78
|
className: `${classPrefix}-boundary`,
|
|
52
79
|
ref: boundaryRef
|
|
53
80
|
})), React.createElement(animated.div, Object.assign({}, bind(), {
|
|
54
|
-
style:
|
|
81
|
+
style: {
|
|
82
|
+
opacity,
|
|
83
|
+
transform: to([x, y], (x, y) => `translate(${x}px, ${y}px)`)
|
|
84
|
+
},
|
|
55
85
|
onClick: props.onClick,
|
|
56
|
-
className: `${classPrefix}-button
|
|
86
|
+
className: `${classPrefix}-button`,
|
|
87
|
+
ref: buttonRef
|
|
57
88
|
}), props.children)));
|
|
58
89
|
};
|
|
@@ -45,7 +45,7 @@ export const Form = forwardRef((p, ref) => {
|
|
|
45
45
|
items = [];
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
React.Children.forEach(props.children,
|
|
48
|
+
React.Children.forEach(props.children, child => {
|
|
49
49
|
if (React.isValidElement(child) && child.type === Header) {
|
|
50
50
|
collect();
|
|
51
51
|
currentHeader = child.props.children;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
1
2
|
import { mergeProps } from '../../utils/with-default-props';
|
|
2
|
-
import React, { useEffect, useRef } from 'react';
|
|
3
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
3
4
|
import { useLockFn, useMemoizedFn } from 'ahooks';
|
|
4
5
|
import { withNativeProps } from '../../utils/native-props';
|
|
5
6
|
import { getScrollParent } from '../../utils/get-scroll-parent';
|
|
@@ -23,25 +24,27 @@ export const InfiniteScroll = p => {
|
|
|
23
24
|
}, p);
|
|
24
25
|
const doLoadMore = useLockFn(() => props.loadMore());
|
|
25
26
|
const elementRef = useRef(null);
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
const [flag, setFlag] = useState({});
|
|
28
|
+
const nextFlagRef = useRef(flag);
|
|
29
|
+
const check = useMemoizedFn(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
if (nextFlagRef.current !== flag) return;
|
|
31
|
+
if (!props.hasMore) return;
|
|
32
|
+
const element = elementRef.current;
|
|
33
|
+
if (!element) return;
|
|
34
|
+
if (!element.offsetParent) return;
|
|
35
|
+
const parent = getScrollParent(element);
|
|
36
|
+
if (!parent) return;
|
|
37
|
+
const rect = element.getBoundingClientRect();
|
|
38
|
+
const elementTop = rect.top;
|
|
39
|
+
const current = isWindow(parent) ? window.innerHeight : parent.getBoundingClientRect().bottom;
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
if (current >= elementTop - props.threshold) {
|
|
42
|
+
const nextFlag = {};
|
|
43
|
+
nextFlagRef.current = nextFlag;
|
|
44
|
+
yield doLoadMore();
|
|
45
|
+
setFlag(nextFlag);
|
|
46
|
+
}
|
|
47
|
+
})); // 确保在内容不足时会自动触发加载事件
|
|
45
48
|
|
|
46
49
|
useEffect(() => {
|
|
47
50
|
check();
|
|
@@ -13,7 +13,6 @@ import AutoCenter from '../auto-center';
|
|
|
13
13
|
import { useSpring, animated } from '@react-spring/web';
|
|
14
14
|
import { withNativeProps } from '../../utils/native-props';
|
|
15
15
|
import { CloseOutline } from 'antd-mobile-icons';
|
|
16
|
-
const classPrefix = `adm-modal`;
|
|
17
16
|
const defaultProps = {
|
|
18
17
|
visible: false,
|
|
19
18
|
actions: [],
|
|
@@ -45,7 +45,6 @@ export const SearchBar = forwardRef((p, ref) => {
|
|
|
45
45
|
|
|
46
46
|
const renderCancelButton = () => {
|
|
47
47
|
let isShowCancel = false;
|
|
48
|
-
const showCancelButton = props.showCancelButton;
|
|
49
48
|
|
|
50
49
|
if (typeof props.showCancelButton === 'function') {
|
|
51
50
|
isShowCancel = props.showCancelButton(hasFocus, value);
|
|
@@ -230,7 +230,7 @@ export const Swiper = forwardRef(staged((p, ref) => {
|
|
|
230
230
|
style: {
|
|
231
231
|
[isVertical ? 'y' : 'x']: position.to(position => `${-position}%`)
|
|
232
232
|
}
|
|
233
|
-
}, React.Children.map(validChildren,
|
|
233
|
+
}, React.Children.map(validChildren, child => {
|
|
234
234
|
return React.createElement("div", {
|
|
235
235
|
className: 'adm-swiper-slide'
|
|
236
236
|
}, child);
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
--color: var(--adm-color-text);
|
|
4
4
|
--placeholder-color: var(--adm-color-light);
|
|
5
5
|
--disabled-color: var(--adm-color-weak);
|
|
6
|
+
--text-align: left;
|
|
7
|
+
--count-text-align: right;
|
|
6
8
|
width: 100%;
|
|
7
9
|
max-width: 100%;
|
|
8
10
|
max-height: 100%;
|
|
@@ -27,6 +29,7 @@
|
|
|
27
29
|
outline: none;
|
|
28
30
|
appearance: none;
|
|
29
31
|
min-height: 1.5em;
|
|
32
|
+
text-align: var(--text-align);
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
.adm-text-area-element::placeholder {
|
|
@@ -62,7 +65,7 @@
|
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
.adm-text-area-count {
|
|
65
|
-
text-align:
|
|
68
|
+
text-align: var(--count-text-align);
|
|
66
69
|
color: var(--adm-color-weak);
|
|
67
70
|
font-size: 34px;
|
|
68
71
|
padding-top: 16px;
|
|
@@ -14,7 +14,7 @@ export declare type TextAreaProps = Pick<React.DetailedHTMLProps<React.TextareaH
|
|
|
14
14
|
maxRows?: number;
|
|
15
15
|
};
|
|
16
16
|
id?: string;
|
|
17
|
-
} & NativeProps<'--font-size' | '--color' | '--placeholder-color' | '--disabled-color'>;
|
|
17
|
+
} & NativeProps<'--font-size' | '--color' | '--placeholder-color' | '--disabled-color' | '--text-align' | '--count-text-align'>;
|
|
18
18
|
export declare type TextAreaRef = {
|
|
19
19
|
clear: () => void;
|
|
20
20
|
focus: () => void;
|
|
@@ -33,4 +33,4 @@ export declare const TextArea: React.ForwardRefExoticComponent<Pick<React.Detail
|
|
|
33
33
|
maxRows?: number | undefined;
|
|
34
34
|
} | undefined;
|
|
35
35
|
id?: string | undefined;
|
|
36
|
-
} & NativeProps<"--color" | "--font-size" | "--placeholder-color" | "--disabled-color"> & React.RefAttributes<TextAreaRef>>;
|
|
36
|
+
} & NativeProps<"--color" | "--font-size" | "--placeholder-color" | "--text-align" | "--disabled-color" | "--count-text-align"> & React.RefAttributes<TextAreaRef>>;
|
package/2x/package.json
CHANGED
|
@@ -2,5 +2,7 @@ import React, { FC } from 'react';
|
|
|
2
2
|
import { NativeProps } from '../../utils/native-props';
|
|
3
3
|
export declare type FloatingBubbleProps = {
|
|
4
4
|
onClick?: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
|
|
5
|
+
axis?: 'x' | 'y' | 'xy' | 'lock';
|
|
6
|
+
magnetic?: 'x' | 'y';
|
|
5
7
|
} & NativeProps<'--initial-position-left' | '--initial-position-right' | '--initial-position-top' | '--initial-position-bottom' | '--z-index' | '--edge-distance' | '--size' | '--border-radius'>;
|
|
6
8
|
export declare const FloatingBubble: FC<FloatingBubbleProps>;
|
|
@@ -20,45 +20,72 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
20
20
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
21
|
|
|
22
22
|
const classPrefix = `adm-floating-bubble`;
|
|
23
|
-
const defaultProps = {
|
|
23
|
+
const defaultProps = {
|
|
24
|
+
axis: 'y'
|
|
25
|
+
};
|
|
24
26
|
|
|
25
27
|
const FloatingBubble = p => {
|
|
26
28
|
const props = (0, _withDefaultProps.mergeProps)(defaultProps, p);
|
|
27
29
|
const boundaryRef = (0, _react.useRef)(null);
|
|
30
|
+
const buttonRef = (0, _react.useRef)(null);
|
|
28
31
|
/**
|
|
29
32
|
* memoize the `to` function
|
|
30
33
|
* inside a component that renders frequently
|
|
31
34
|
* to prevent an unintended restart
|
|
32
35
|
*/
|
|
33
36
|
|
|
34
|
-
const [
|
|
37
|
+
const [{
|
|
38
|
+
x,
|
|
39
|
+
y,
|
|
40
|
+
opacity
|
|
41
|
+
}, api] = (0, _web.useSpring)(() => ({
|
|
42
|
+
x: 0,
|
|
35
43
|
y: 0,
|
|
36
|
-
scale: 1,
|
|
37
44
|
opacity: 1
|
|
38
45
|
}));
|
|
39
46
|
const bind = (0, _react2.useDrag)(state => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
let nextX = state.offset[0];
|
|
48
|
+
let nextY = state.offset[1];
|
|
49
|
+
|
|
50
|
+
if (state.last) {
|
|
51
|
+
const boundary = boundaryRef.current;
|
|
52
|
+
const button = buttonRef.current;
|
|
53
|
+
if (!boundary || !button) return;
|
|
54
|
+
|
|
55
|
+
if (props.magnetic === 'x') {
|
|
56
|
+
const compensation = x.goal - x.get();
|
|
57
|
+
const boundaryRect = boundary.getBoundingClientRect();
|
|
58
|
+
const buttonRect = button.getBoundingClientRect();
|
|
59
|
+
const leftDistance = buttonRect.left + compensation - boundaryRect.left;
|
|
60
|
+
const rightDistance = boundaryRect.right - (buttonRect.right + compensation);
|
|
46
61
|
|
|
62
|
+
if (rightDistance <= leftDistance) {
|
|
63
|
+
nextX += rightDistance;
|
|
64
|
+
} else {
|
|
65
|
+
nextX -= leftDistance;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
47
69
|
|
|
48
|
-
|
|
49
|
-
|
|
70
|
+
api.start({
|
|
71
|
+
x: nextX,
|
|
72
|
+
y: nextY // immediate: !state.last,
|
|
73
|
+
|
|
74
|
+
}); // active status
|
|
75
|
+
|
|
76
|
+
api.start({
|
|
50
77
|
opacity: state.active ? 0.8 : 1
|
|
51
78
|
});
|
|
52
79
|
}, {
|
|
53
|
-
|
|
54
|
-
axis: 'y',
|
|
80
|
+
axis: props.axis === 'xy' ? undefined : props.axis,
|
|
55
81
|
pointer: {
|
|
56
82
|
touch: true
|
|
57
83
|
},
|
|
58
84
|
// the component won't trigger drag logic if the user just clicked on the component.
|
|
59
85
|
filterTaps: true,
|
|
60
86
|
// set constraints to the user gesture
|
|
61
|
-
bounds: boundaryRef
|
|
87
|
+
bounds: boundaryRef,
|
|
88
|
+
from: () => [x.get(), y.get()]
|
|
62
89
|
});
|
|
63
90
|
return (0, _nativeProps.withNativeProps)(props, _react.default.createElement("div", {
|
|
64
91
|
className: classPrefix
|
|
@@ -68,9 +95,13 @@ const FloatingBubble = p => {
|
|
|
68
95
|
className: `${classPrefix}-boundary`,
|
|
69
96
|
ref: boundaryRef
|
|
70
97
|
})), _react.default.createElement(_web.animated.div, Object.assign({}, bind(), {
|
|
71
|
-
style:
|
|
98
|
+
style: {
|
|
99
|
+
opacity,
|
|
100
|
+
transform: (0, _web.to)([x, y], (x, y) => `translate(${x}px, ${y}px)`)
|
|
101
|
+
},
|
|
72
102
|
onClick: props.onClick,
|
|
73
|
-
className: `${classPrefix}-button
|
|
103
|
+
className: `${classPrefix}-button`,
|
|
104
|
+
ref: buttonRef
|
|
74
105
|
}), props.children)));
|
|
75
106
|
};
|
|
76
107
|
|
|
@@ -66,7 +66,7 @@ const Form = (0, _react.forwardRef)((p, ref) => {
|
|
|
66
66
|
items = [];
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
_react.default.Children.forEach(props.children,
|
|
69
|
+
_react.default.Children.forEach(props.children, child => {
|
|
70
70
|
if (_react.default.isValidElement(child) && child.type === _header.Header) {
|
|
71
71
|
collect();
|
|
72
72
|
currentHeader = child.props.children;
|