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.
Files changed (43) hide show
  1. package/2x/cjs/components/floating-bubble/floating-bubble.d.ts +2 -0
  2. package/2x/cjs/components/floating-bubble/floating-bubble.js +47 -16
  3. package/2x/cjs/components/form/form.js +1 -1
  4. package/2x/cjs/components/infinite-scroll/infinite-scroll.js +23 -19
  5. package/2x/cjs/components/modal/modal.js +0 -1
  6. package/2x/cjs/components/notice-bar/notice-bar.js +1 -1
  7. package/2x/cjs/components/search-bar/search-bar.js +0 -1
  8. package/2x/cjs/components/swiper/swiper.js +1 -1
  9. package/2x/cjs/components/text-area/text-area.css +4 -1
  10. package/2x/cjs/components/text-area/text-area.d.ts +2 -2
  11. package/2x/es/components/floating-bubble/floating-bubble.d.ts +2 -0
  12. package/2x/es/components/floating-bubble/floating-bubble.js +48 -17
  13. package/2x/es/components/form/form.js +1 -1
  14. package/2x/es/components/infinite-scroll/infinite-scroll.js +22 -19
  15. package/2x/es/components/modal/modal.js +0 -1
  16. package/2x/es/components/notice-bar/notice-bar.js +1 -1
  17. package/2x/es/components/search-bar/search-bar.js +0 -1
  18. package/2x/es/components/swiper/swiper.js +1 -1
  19. package/2x/es/components/text-area/text-area.css +4 -1
  20. package/2x/es/components/text-area/text-area.d.ts +2 -2
  21. package/2x/package.json +1 -1
  22. package/cjs/components/floating-bubble/floating-bubble.d.ts +2 -0
  23. package/cjs/components/floating-bubble/floating-bubble.js +47 -16
  24. package/cjs/components/form/form.js +1 -1
  25. package/cjs/components/infinite-scroll/infinite-scroll.js +23 -19
  26. package/cjs/components/modal/modal.js +0 -1
  27. package/cjs/components/notice-bar/notice-bar.js +1 -1
  28. package/cjs/components/search-bar/search-bar.js +0 -1
  29. package/cjs/components/swiper/swiper.js +1 -1
  30. package/cjs/components/text-area/text-area.css +4 -1
  31. package/cjs/components/text-area/text-area.d.ts +2 -2
  32. package/es/components/floating-bubble/floating-bubble.d.ts +2 -0
  33. package/es/components/floating-bubble/floating-bubble.js +48 -17
  34. package/es/components/form/form.js +1 -1
  35. package/es/components/infinite-scroll/infinite-scroll.js +22 -19
  36. package/es/components/modal/modal.js +0 -1
  37. package/es/components/notice-bar/notice-bar.js +1 -1
  38. package/es/components/search-bar/search-bar.js +0 -1
  39. package/es/components/swiper/swiper.js +1 -1
  40. package/es/components/text-area/text-area.css +4 -1
  41. package/es/components/text-area/text-area.d.ts +2 -2
  42. package/package.json +1 -1
  43. package/umd/antd-mobile.js +1 -1
@@ -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 checkTimeoutRef = (0, _react.useRef)();
45
- const check = (0, _ahooks.useMemoizedFn)(() => {
46
- window.clearTimeout(checkTimeoutRef.current);
47
- checkTimeoutRef.current = window.setTimeout(() => {
48
- if (!props.hasMore) return;
49
- const element = elementRef.current;
50
- if (!element) return;
51
- if (!element.offsetParent) return;
52
- const parent = (0, _getScrollParent.getScrollParent)(element);
53
- if (!parent) return;
54
- const rect = element.getBoundingClientRect();
55
- const elementTop = rect.top;
56
- const current = isWindow(parent) ? window.innerHeight : parent.getBoundingClientRect().bottom;
57
-
58
- if (current >= elementTop - props.threshold) {
59
- doLoadMore();
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)(text => {
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, (child, index) => {
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%;
@@ -26,6 +28,7 @@
26
28
  outline: none;
27
29
  appearance: none;
28
30
  min-height: 1.5em;
31
+ text-align: var(--text-align);
29
32
  }
30
33
  .adm-text-area-element::placeholder {
31
34
  color: var(--placeholder-color);
@@ -53,7 +56,7 @@
53
56
  pointer-events: none;
54
57
  }
55
58
  .adm-text-area-count {
56
- text-align: right;
59
+ text-align: var(--count-text-align);
57
60
  color: var(--adm-color-weak);
58
61
  font-size: 17px;
59
62
  padding-top: 8px;
@@ -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 [animationStyles, animation] = useSpring(() => ({
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
- if (state.down) {
24
- // be movable in y axis
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
- animation.start({
32
- scale: state.active ? 1.1 : 1,
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
- // only trigger if a movement is detected on the specified axis.
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: Object.assign({}, animationStyles),
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, (child, index) => {
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 checkTimeoutRef = useRef();
27
- const check = useMemoizedFn(() => {
28
- window.clearTimeout(checkTimeoutRef.current);
29
- checkTimeoutRef.current = window.setTimeout(() => {
30
- if (!props.hasMore) return;
31
- const element = elementRef.current;
32
- if (!element) return;
33
- if (!element.offsetParent) return;
34
- const parent = getScrollParent(element);
35
- if (!parent) return;
36
- const rect = element.getBoundingClientRect();
37
- const elementTop = rect.top;
38
- const current = isWindow(parent) ? window.innerHeight : parent.getBoundingClientRect().bottom;
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
- if (current >= elementTop - props.threshold) {
41
- doLoadMore();
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: [],
@@ -55,7 +55,7 @@ export const NoticeBar = memo(p => {
55
55
  delayLockRef.current = false;
56
56
  start();
57
57
  }, props.delay);
58
- useResizeEffect(text => {
58
+ useResizeEffect(() => {
59
59
  start();
60
60
  }, containerRef);
61
61
  useMutationEffect(() => {
@@ -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, (child, index) => {
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%;
@@ -26,6 +28,7 @@
26
28
  outline: none;
27
29
  appearance: none;
28
30
  min-height: 1.5em;
31
+ text-align: var(--text-align);
29
32
  }
30
33
  .adm-text-area-element::placeholder {
31
34
  color: var(--placeholder-color);
@@ -53,7 +56,7 @@
53
56
  pointer-events: none;
54
57
  }
55
58
  .adm-text-area-count {
56
- text-align: right;
59
+ text-align: var(--count-text-align);
57
60
  color: var(--adm-color-weak);
58
61
  font-size: 17px;
59
62
  padding-top: 8px;
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antd-mobile",
3
- "version": "5.3.1",
3
+ "version": "5.4.0",
4
4
  "dependencies": {
5
5
  "@react-spring/web": "^9.4.3",
6
6
  "@types/resize-observer-browser": "^0.1.7",