antd-mobile 5.0.0 → 5.1.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 (125) hide show
  1. package/2x/README.md +3 -6
  2. package/2x/cjs/components/floating-panel/floating-panel.css +2 -1
  3. package/2x/cjs/components/floating-panel/floating-panel.d.ts +2 -2
  4. package/2x/cjs/components/floating-panel/floating-panel.js +6 -5
  5. package/2x/cjs/components/form/form-subscribe.d.ts +11 -0
  6. package/2x/cjs/components/form/form-subscribe.js +27 -0
  7. package/2x/cjs/components/form/index.d.ts +2 -0
  8. package/2x/cjs/components/form/index.js +3 -0
  9. package/2x/cjs/components/image/image.js +2 -2
  10. package/2x/cjs/components/image-uploader/image-uploader.d.ts +1 -0
  11. package/2x/cjs/components/image-uploader/image-uploader.js +16 -9
  12. package/2x/cjs/components/image-viewer/slide.js +59 -19
  13. package/2x/cjs/components/index-bar/index-bar.d.ts +1 -1
  14. package/2x/cjs/components/index-bar/index-bar.js +12 -4
  15. package/2x/cjs/components/index-bar/index.d.ts +2 -1
  16. package/2x/cjs/components/index-bar/panel.d.ts +5 -4
  17. package/2x/cjs/components/index-bar/sidebar.d.ts +6 -3
  18. package/2x/cjs/components/index-bar/sidebar.js +6 -3
  19. package/2x/cjs/components/picker/picker.css +3 -0
  20. package/2x/cjs/components/picker/picker.d.ts +1 -1
  21. package/2x/cjs/components/picker-view/picker-view.css +14 -3
  22. package/2x/cjs/components/picker-view/picker-view.d.ts +1 -1
  23. package/2x/cjs/components/picker-view/wheel.js +23 -9
  24. package/2x/cjs/components/slider/slider.css +2 -1
  25. package/2x/cjs/components/toast/index.d.ts +1 -1
  26. package/2x/cjs/components/toast/methods.d.ts +4 -1
  27. package/2x/cjs/components/toast/methods.js +17 -4
  28. package/2x/cjs/utils/use-drag-and-pinch.d.ts +2 -0
  29. package/2x/cjs/utils/use-drag-and-pinch.js +11 -0
  30. package/2x/cjs/utils/use-isomorphic-update-layout-effect.d.ts +2 -0
  31. package/2x/cjs/utils/use-isomorphic-update-layout-effect.js +13 -0
  32. package/2x/es/components/floating-panel/floating-panel.css +2 -1
  33. package/2x/es/components/floating-panel/floating-panel.d.ts +2 -2
  34. package/2x/es/components/floating-panel/floating-panel.js +5 -5
  35. package/2x/es/components/form/form-subscribe.d.ts +11 -0
  36. package/2x/es/components/form/form-subscribe.js +14 -0
  37. package/2x/es/components/form/index.d.ts +2 -0
  38. package/2x/es/components/form/index.js +2 -0
  39. package/2x/es/components/image/image.js +2 -2
  40. package/2x/es/components/image-uploader/image-uploader.d.ts +1 -0
  41. package/2x/es/components/image-uploader/image-uploader.js +16 -9
  42. package/2x/es/components/image-viewer/slide.js +56 -18
  43. package/2x/es/components/index-bar/index-bar.d.ts +1 -1
  44. package/2x/es/components/index-bar/index-bar.js +12 -4
  45. package/2x/es/components/index-bar/index.d.ts +2 -1
  46. package/2x/es/components/index-bar/panel.d.ts +5 -4
  47. package/2x/es/components/index-bar/sidebar.d.ts +6 -3
  48. package/2x/es/components/index-bar/sidebar.js +6 -3
  49. package/2x/es/components/picker/picker.css +3 -0
  50. package/2x/es/components/picker/picker.d.ts +1 -1
  51. package/2x/es/components/picker-view/picker-view.css +14 -3
  52. package/2x/es/components/picker-view/picker-view.d.ts +1 -1
  53. package/2x/es/components/picker-view/wheel.js +22 -8
  54. package/2x/es/components/slider/slider.css +2 -1
  55. package/2x/es/components/toast/index.d.ts +1 -1
  56. package/2x/es/components/toast/methods.d.ts +4 -1
  57. package/2x/es/components/toast/methods.js +16 -5
  58. package/2x/es/utils/use-drag-and-pinch.d.ts +2 -0
  59. package/2x/es/utils/use-drag-and-pinch.js +2 -0
  60. package/2x/es/utils/use-isomorphic-update-layout-effect.d.ts +2 -0
  61. package/2x/es/utils/use-isomorphic-update-layout-effect.js +3 -0
  62. package/2x/package.json +1 -1
  63. package/README.md +3 -6
  64. package/cjs/components/floating-panel/floating-panel.css +2 -1
  65. package/cjs/components/floating-panel/floating-panel.d.ts +2 -2
  66. package/cjs/components/floating-panel/floating-panel.js +6 -5
  67. package/cjs/components/form/form-subscribe.d.ts +11 -0
  68. package/cjs/components/form/form-subscribe.js +27 -0
  69. package/cjs/components/form/index.d.ts +2 -0
  70. package/cjs/components/form/index.js +3 -0
  71. package/cjs/components/image/image.js +2 -2
  72. package/cjs/components/image-uploader/image-uploader.d.ts +1 -0
  73. package/cjs/components/image-uploader/image-uploader.js +16 -9
  74. package/cjs/components/image-viewer/slide.js +59 -19
  75. package/cjs/components/index-bar/index-bar.d.ts +1 -1
  76. package/cjs/components/index-bar/index-bar.js +12 -4
  77. package/cjs/components/index-bar/index.d.ts +2 -1
  78. package/cjs/components/index-bar/panel.d.ts +5 -4
  79. package/cjs/components/index-bar/sidebar.d.ts +6 -3
  80. package/cjs/components/index-bar/sidebar.js +6 -3
  81. package/cjs/components/picker/picker.css +3 -0
  82. package/cjs/components/picker/picker.d.ts +1 -1
  83. package/cjs/components/picker-view/picker-view.css +13 -3
  84. package/cjs/components/picker-view/picker-view.d.ts +1 -1
  85. package/cjs/components/picker-view/wheel.js +23 -9
  86. package/cjs/components/slider/slider.css +2 -1
  87. package/cjs/components/toast/index.d.ts +1 -1
  88. package/cjs/components/toast/methods.d.ts +4 -1
  89. package/cjs/components/toast/methods.js +17 -4
  90. package/cjs/utils/use-drag-and-pinch.d.ts +2 -0
  91. package/cjs/utils/use-drag-and-pinch.js +11 -0
  92. package/cjs/utils/use-isomorphic-update-layout-effect.d.ts +2 -0
  93. package/cjs/utils/use-isomorphic-update-layout-effect.js +13 -0
  94. package/es/components/floating-panel/floating-panel.css +2 -1
  95. package/es/components/floating-panel/floating-panel.d.ts +2 -2
  96. package/es/components/floating-panel/floating-panel.js +5 -5
  97. package/es/components/form/form-subscribe.d.ts +11 -0
  98. package/es/components/form/form-subscribe.js +14 -0
  99. package/es/components/form/index.d.ts +2 -0
  100. package/es/components/form/index.js +2 -0
  101. package/es/components/image/image.js +2 -2
  102. package/es/components/image-uploader/image-uploader.d.ts +1 -0
  103. package/es/components/image-uploader/image-uploader.js +16 -9
  104. package/es/components/image-viewer/slide.js +56 -18
  105. package/es/components/index-bar/index-bar.d.ts +1 -1
  106. package/es/components/index-bar/index-bar.js +12 -4
  107. package/es/components/index-bar/index.d.ts +2 -1
  108. package/es/components/index-bar/panel.d.ts +5 -4
  109. package/es/components/index-bar/sidebar.d.ts +6 -3
  110. package/es/components/index-bar/sidebar.js +6 -3
  111. package/es/components/picker/picker.css +3 -0
  112. package/es/components/picker/picker.d.ts +1 -1
  113. package/es/components/picker-view/picker-view.css +13 -3
  114. package/es/components/picker-view/picker-view.d.ts +1 -1
  115. package/es/components/picker-view/wheel.js +22 -8
  116. package/es/components/slider/slider.css +2 -1
  117. package/es/components/toast/index.d.ts +1 -1
  118. package/es/components/toast/methods.d.ts +4 -1
  119. package/es/components/toast/methods.js +16 -5
  120. package/es/utils/use-drag-and-pinch.d.ts +2 -0
  121. package/es/utils/use-drag-and-pinch.js +2 -0
  122. package/es/utils/use-isomorphic-update-layout-effect.d.ts +2 -0
  123. package/es/utils/use-isomorphic-update-layout-effect.js +3 -0
  124. package/package.json +1 -1
  125. package/umd/antd-mobile.js +1 -1
@@ -2,6 +2,7 @@
2
2
  --header-button-font-size: 30px;
3
3
  --title-font-size: 30px;
4
4
  --item-font-size: 32px;
5
+ --item-height: 68px;
5
6
  width: 100%;
6
7
  height: 600px;
7
8
  overflow: hidden;
@@ -9,10 +10,12 @@
9
10
  display: flex;
10
11
  flex-direction: column;
11
12
  ---item-font-size: var(--item-font-size);
13
+ ---item-height: var(--item-height);
12
14
  }
13
15
 
14
16
  .adm-picker .adm-picker-view.adm-picker-view {
15
17
  --item-font-size: var(---item-font-size);
18
+ --item-height: var(---item-height);
16
19
  }
17
20
 
18
21
  .adm-picker-header {
@@ -16,5 +16,5 @@ export declare type PickerProps = {
16
16
  confirmText?: ReactNode;
17
17
  cancelText?: ReactNode;
18
18
  children?: (items: (PickerColumnItem | null)[]) => ReactNode;
19
- } & Pick<PopupProps, 'getContainer' | 'afterShow' | 'afterClose' | 'onClick' | 'stopPropagation'> & NativeProps<'--header-button-font-size' | '--title-font-size' | '--item-font-size'>;
19
+ } & Pick<PopupProps, 'getContainer' | 'afterShow' | 'afterClose' | 'onClick' | 'stopPropagation'> & NativeProps<'--header-button-font-size' | '--title-font-size' | '--item-font-size' | '--item-height'>;
20
20
  export declare const Picker: React.NamedExoticComponent<PickerProps>;
@@ -1,5 +1,6 @@
1
1
  .adm-picker-view {
2
2
  --height: 480px;
3
+ --item-height: 68px;
3
4
  --item-font-size: 32px;
4
5
  height: var(--height);
5
6
  width: 100%;
@@ -22,7 +23,7 @@
22
23
  width: 100%;
23
24
  cursor: grab;
24
25
  position: absolute;
25
- top: calc(50% - 34px);
26
+ top: calc(50% - var(--item-height) / 2);
26
27
  left: 0;
27
28
  }
28
29
 
@@ -47,7 +48,7 @@
47
48
  .adm-picker-view-column-item {
48
49
  font-size: var(--item-font-size);
49
50
  padding: 0 12px;
50
- height: 68px;
51
+ height: var(--item-height);
51
52
  display: flex;
52
53
  justify-content: center;
53
54
  align-items: center;
@@ -59,6 +60,16 @@
59
60
  white-space: nowrap;
60
61
  }
61
62
 
63
+ .adm-picker-view-column-item.adm-picker-view-column-item-dummy {
64
+ position: fixed;
65
+ left: 0;
66
+ bottom: 0;
67
+ padding: 0;
68
+ opacity: 0;
69
+ user-select: none;
70
+ pointer-events: none;
71
+ }
72
+
62
73
  .adm-picker-view-column-accessible {
63
74
  width: 100%;
64
75
  height: 100%;
@@ -104,7 +115,7 @@
104
115
  }
105
116
 
106
117
  .adm-picker-view-mask-middle {
107
- height: 68px;
118
+ height: var(--item-height);
108
119
  box-sizing: border-box;
109
120
  flex: none;
110
121
  border-top: solid 2px var(--adm-border-color);
@@ -14,5 +14,5 @@ export declare type PickerViewProps = {
14
14
  value?: PickerValue[];
15
15
  defaultValue?: PickerValue[];
16
16
  onChange?: (value: PickerValue[], extend: PickerValueExtend) => void;
17
- } & NativeProps<'--height' | '--item-font-size'>;
17
+ } & NativeProps<'--height' | '--item-height' | '--item-font-size'>;
18
18
  export declare const PickerView: React.NamedExoticComponent<PickerViewProps>;
@@ -1,14 +1,13 @@
1
1
  import React, { memo, useRef } from 'react';
2
2
  import { useSpring, animated } from '@react-spring/web';
3
3
  import { useDrag } from '@use-gesture/react';
4
- import { convertPx } from '../../utils/convert-px';
5
4
  import { rubberbandIfOutOfBounds } from '../../utils/rubberband';
6
5
  import { bound } from '../../utils/bound';
7
6
  import isEqual from 'lodash/isEqual';
8
7
  import { useIsomorphicLayoutEffect } from 'ahooks';
8
+ import classNames from 'classnames';
9
9
  const classPrefix = `adm-picker-view`;
10
10
  export const Wheel = memo(props => {
11
- const itemHeight = convertPx(34);
12
11
  const {
13
12
  value,
14
13
  column
@@ -30,12 +29,23 @@ export const Wheel = memo(props => {
30
29
  }
31
30
  }));
32
31
  const draggingRef = useRef(false);
32
+ const dummyItemRef = useRef(null);
33
+ const itemHeight = useRef(34);
34
+ useIsomorphicLayoutEffect(() => {
35
+ const dummyItem = dummyItemRef.current;
36
+ if (!dummyItem) return;
37
+ const rect = dummyItem.getBoundingClientRect();
38
+
39
+ if (rect.height > 0) {
40
+ itemHeight.current = rect.height;
41
+ }
42
+ });
33
43
  useIsomorphicLayoutEffect(() => {
34
44
  if (draggingRef.current) return;
35
45
  if (!value) return;
36
46
  const targetIndex = column.findIndex(item => item.value === value);
37
47
  if (targetIndex < 0) return;
38
- const finalPosition = targetIndex * -itemHeight;
48
+ const finalPosition = targetIndex * -itemHeight.current;
39
49
  api.start({
40
50
  y: finalPosition,
41
51
  immediate: y.goal !== finalPosition
@@ -55,7 +65,7 @@ export const Wheel = memo(props => {
55
65
  }, [column, value]);
56
66
 
57
67
  function scrollSelect(index) {
58
- const finalPosition = index * -itemHeight;
68
+ const finalPosition = index * -itemHeight.current;
59
69
  api.start({
60
70
  y: finalPosition
61
71
  });
@@ -66,18 +76,18 @@ export const Wheel = memo(props => {
66
76
 
67
77
  const bind = useDrag(state => {
68
78
  draggingRef.current = true;
69
- const min = -((column.length - 1) * itemHeight);
79
+ const min = -((column.length - 1) * itemHeight.current);
70
80
  const max = 0;
71
81
 
72
82
  if (state.last) {
73
83
  draggingRef.current = false;
74
84
  const position = state.offset[1] + state.velocity[1] * state.direction[1] * 50;
75
- const targetIndex = min < max ? -Math.round(bound(position, min, max) / itemHeight) : 0;
85
+ const targetIndex = min < max ? -Math.round(bound(position, min, max) / itemHeight.current) : 0;
76
86
  scrollSelect(targetIndex);
77
87
  } else {
78
88
  const position = state.offset[1];
79
89
  api.start({
80
- y: rubberbandIfOutOfBounds(position, min, max, itemHeight * 50, 0.2)
90
+ y: rubberbandIfOutOfBounds(position, min, max, itemHeight.current * 50, 0.2)
81
91
  });
82
92
  }
83
93
  }, {
@@ -125,7 +135,11 @@ export const Wheel = memo(props => {
125
135
 
126
136
  return React.createElement("div", Object.assign({
127
137
  className: `${classPrefix}-column`
128
- }, bind()), React.createElement(animated.div, {
138
+ }, bind()), React.createElement("div", {
139
+ ref: dummyItemRef,
140
+ className: classNames(`${classPrefix}-column-item`, `${classPrefix}-column-item-dummy`),
141
+ "aria-hidden": true
142
+ }), React.createElement(animated.div, {
129
143
  style: {
130
144
  translateY: y
131
145
  },
@@ -32,12 +32,13 @@
32
32
 
33
33
  .adm-slider-tick {
34
34
  position: absolute;
35
- top: -7px;
35
+ top: 50%;
36
36
  width: 22px;
37
37
  height: 22px;
38
38
  margin-left: -10px;
39
39
  background-color: #f5f5f5;
40
40
  border-radius: 50%;
41
+ transform: translate(0, -50%);
41
42
  }
42
43
 
43
44
  .adm-slider-tick-active {
@@ -1,6 +1,6 @@
1
1
  import './toast.less';
2
2
  import { clear, show, config } from './methods';
3
- export type { ToastShowProps } from './methods';
3
+ export type { ToastShowProps, ToastHandler } from './methods';
4
4
  declare const Toast: {
5
5
  show: typeof show;
6
6
  clear: typeof clear;
@@ -1,5 +1,8 @@
1
1
  import { ToastProps } from './toast';
2
2
  export declare type ToastShowProps = Omit<ToastProps, 'visible'>;
3
- export declare function show(p: ToastShowProps | string): void;
3
+ export declare type ToastHandler = {
4
+ close: () => void;
5
+ };
6
+ export declare function show(p: ToastShowProps | string): ToastHandler;
4
7
  export declare function clear(): void;
5
8
  export declare function config(val: Pick<ToastProps, 'duration' | 'position' | 'maskClickable'>): void;
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { createRef, forwardRef, useEffect, useImperativeHandle, useState } from 'react';
2
2
  import { resolveContainer } from '../../utils/get-container';
3
3
  import ReactDOM from 'react-dom';
4
4
  import { InternalToast } from './toast';
@@ -31,8 +31,7 @@ export function show(p) {
31
31
  bodyContainer.appendChild(container);
32
32
  clear();
33
33
  containers.push(container);
34
-
35
- const TempToast = () => {
34
+ const TempToast = forwardRef((_, ref) => {
36
35
  const [visible, setVisible] = useState(true);
37
36
  useEffect(() => {
38
37
  return () => {
@@ -53,6 +52,9 @@ export function show(p) {
53
52
  window.clearTimeout(timer);
54
53
  };
55
54
  }, []);
55
+ useImperativeHandle(ref, () => ({
56
+ close: () => setVisible(false)
57
+ }));
56
58
  return React.createElement(InternalToast, Object.assign({}, props, {
57
59
  getContainer: () => container,
58
60
  visible: visible,
@@ -60,9 +62,18 @@ export function show(p) {
60
62
  unmount(container);
61
63
  }
62
64
  }));
63
- };
65
+ });
66
+ const ref = createRef();
67
+ ReactDOM.render(React.createElement(TempToast, {
68
+ ref: ref
69
+ }), container);
70
+ return {
71
+ close: () => {
72
+ var _a;
64
73
 
65
- ReactDOM.render(React.createElement(TempToast, null), container);
74
+ (_a = ref.current) === null || _a === void 0 ? void 0 : _a.close();
75
+ }
76
+ };
66
77
  }
67
78
  export function clear() {
68
79
  while (true) {
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const useDragAndPinch: <Config extends import("@use-gesture/react").UserGestureConfig = import("@use-gesture/react").UserGestureConfig>(_handlers: Partial<import("@use-gesture/react").NativeHandlers<import("@use-gesture/react").EventTypes> & import("@use-gesture/react").UserHandlers<import("@use-gesture/react").EventTypes>>, _config?: {} | Config | undefined) => Config["target"] extends object ? void : (...args: any[]) => Pick<import("react").DOMAttributes<EventTarget>, "onClick" | "onChange" | "onPause" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDragCapture" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScrollCapture" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture">;
@@ -0,0 +1,2 @@
1
+ import { createUseGesture, dragAction, pinchAction } from '@use-gesture/react';
2
+ export const useDragAndPinch = createUseGesture([dragAction, pinchAction]);
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const useIsomorphicUpdateLayoutEffect: typeof import("react").useEffect | typeof import("react").useLayoutEffect;
@@ -0,0 +1,3 @@
1
+ import { createUpdateEffect } from 'ahooks/lib/createUpdateEffect';
2
+ import { useIsomorphicLayoutEffect } from 'ahooks';
3
+ export const useIsomorphicUpdateLayoutEffect = createUpdateEffect(useIsomorphicLayoutEffect);
package/2x/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antd-mobile",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "dependencies": {
5
5
  "@react-spring/web": "^9.4.3",
6
6
  "@types/resize-observer-browser": "^0.1.7",
package/README.md CHANGED
@@ -1,4 +1,6 @@
1
- <img src="https://gw.alipayobjects.com/mdn/rms_ee68a8/afts/img/A*JzBoT6sg9t4AAAAAAAAAAAAAARQnAQ" alt="logo" width="100%" />
1
+ <img src="https://gw.alipayobjects.com/mdn/rms_ee68a8/afts/img/A*hjjDS5Yy-ooAAAAAAAAAAAAAARQnAQ" alt="logo" width="100%" />
2
+
3
+ [English Doc](https://mobile.ant.design) | [中文文档](https://mobile.ant.design/zh) | [Discord](https://discord.gg/jmNvw4WFYn) | [钉钉](https://gw.alipayobjects.com/mdn/rms_25513e/afts/img/A*hBjlR4nUWjkAAAAAAAAAAAAAARQnAQ)
2
4
 
3
5
  ![npm (tag)](https://img.shields.io/npm/v/antd-mobile)
4
6
  ![GitHub Release Date](https://img.shields.io/github/release-date/ant-design/ant-design-mobile)
@@ -28,11 +30,6 @@ If you found bugs or would like to request some new features, please consider op
28
30
 
29
31
  If you have some question about how to use ant-mobile, you can start a [discussion thread](https://github.com/ant-design/ant-design-mobile/discussions).
30
32
 
31
- And we also have some community groups here. Feel free to join us:
32
-
33
- - [DingDing](https://gw.alipayobjects.com/mdn/rms_25513e/afts/img/A*hBjlR4nUWjkAAAAAAAAAAAAAARQnAQ)
34
- - [Discord](https://discord.gg/jmNvw4WFYn)
35
-
36
33
  ---
37
34
 
38
35
  Thanks to all the contributors of antd-mobile:
@@ -7,11 +7,12 @@
7
7
  background: var(--adm-color-white);
8
8
  position: fixed;
9
9
  z-index: var(--z-index);
10
- top: 100vh;
10
+ bottom: 0;
11
11
  left: 0;
12
12
  width: 100vw;
13
13
  display: flex;
14
14
  flex-direction: column;
15
+ touch-action: none;
15
16
  }
16
17
  .adm-floating-panel-mask {
17
18
  display: block;
@@ -10,10 +10,10 @@ export declare type FloatingPanelProps = {
10
10
  children: ReactNode;
11
11
  onHeightChange?: (height: number, animating: boolean) => void;
12
12
  handleDraggingOfContent?: boolean;
13
- } & NativeProps<'--border-radius' | '--z-index'>;
13
+ } & NativeProps<'--border-radius' | '--z-index' | '--header-height'>;
14
14
  export declare const FloatingPanel: React.ForwardRefExoticComponent<{
15
15
  anchors: number[];
16
16
  children: ReactNode;
17
17
  onHeightChange?: ((height: number, animating: boolean) => void) | undefined;
18
18
  handleDraggingOfContent?: boolean | undefined;
19
- } & NativeProps<"--z-index" | "--border-radius"> & React.RefAttributes<FloatingPanelRef>>;
19
+ } & NativeProps<"--z-index" | "--border-radius" | "--header-height"> & React.RefAttributes<FloatingPanelRef>>;
@@ -21,6 +21,8 @@ var _withDefaultProps = require("../../utils/with-default-props");
21
21
 
22
22
  var _useLockScroll = require("../../utils/use-lock-scroll");
23
23
 
24
+ var _ahooks = require("ahooks");
25
+
24
26
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
27
 
26
28
  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; }
@@ -29,7 +31,7 @@ const defaultProps = {
29
31
  handleDraggingOfContent: true
30
32
  };
31
33
  const FloatingPanel = (0, _react.forwardRef)((p, ref) => {
32
- var _a;
34
+ var _a, _b;
33
35
 
34
36
  const props = (0, _withDefaultProps.mergeProps)(defaultProps, p);
35
37
  const {
@@ -46,6 +48,7 @@ const FloatingPanel = (0, _react.forwardRef)((p, ref) => {
46
48
  top: possibles[possibles.length - 1],
47
49
  bottom: possibles[0]
48
50
  };
51
+ const onHeightChange = (0, _ahooks.useMemoizedFn)((_b = props.onHeightChange) !== null && _b !== void 0 ? _b : () => {});
49
52
  const [{
50
53
  y
51
54
  }, api] = (0, _web.useSpring)(() => ({
@@ -54,9 +57,7 @@ const FloatingPanel = (0, _react.forwardRef)((p, ref) => {
54
57
  tension: 300
55
58
  },
56
59
  onChange: result => {
57
- var _a;
58
-
59
- (_a = props.onHeightChange) === null || _a === void 0 ? void 0 : _a.call(props, result.value.y, y.isAnimating);
60
+ onHeightChange(result.value.y, y.isAnimating);
60
61
  }
61
62
  }));
62
63
  (0, _react2.useDrag)(state => {
@@ -133,7 +134,7 @@ const FloatingPanel = (0, _react.forwardRef)((p, ref) => {
133
134
  className: 'adm-floating-panel',
134
135
  style: {
135
136
  height: maxHeight,
136
- y
137
+ translateY: y.to(y => `calc(100% + (${y}px))`)
137
138
  }
138
139
  }, _react.default.createElement("div", {
139
140
  className: 'adm-floating-panel-mask',
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import type { FormInstance } from 'rc-field-form';
3
+ import type { NamePath } from 'rc-field-form/es/interface';
4
+ declare type RenderChildren<Values = any> = (changedValues: Record<string, any>, form: FormInstance<Values>) => React.ReactNode;
5
+ declare type ChildrenType<Values = any> = RenderChildren<Values>;
6
+ export interface FormSubscribeProps {
7
+ to: NamePath[];
8
+ children: ChildrenType;
9
+ }
10
+ export declare const FormSubscribe: React.VFC<FormSubscribeProps>;
11
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.FormSubscribe = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _ = _interopRequireDefault(require("."));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ const FormSubscribe = ({
15
+ children,
16
+ to
17
+ }) => {
18
+ return _react.default.createElement(_.default.Item, {
19
+ noStyle: true,
20
+ dependencies: to
21
+ }, form => {
22
+ const changedValues = form.getFieldsValue(to);
23
+ return children(changedValues, form);
24
+ });
25
+ };
26
+
27
+ exports.FormSubscribe = FormSubscribe;
@@ -4,6 +4,7 @@ import { useForm } from 'rc-field-form';
4
4
  export declare type FormLayout = 'vertical' | 'horizontal';
5
5
  export type { FormProps, FormInstance } from './form';
6
6
  export type { FormItemProps } from './form-item';
7
+ export type { FormSubscribeProps } from './form-subscribe';
7
8
  export type { ValidateMessages, FieldData, NamePath, } from 'rc-field-form/es/interface';
8
9
  declare const _default: import("react").ForwardRefExoticComponent<Pick<import("rc-field-form").FormProps<any>, "children" | "form" | "name" | "initialValues" | "preserve" | "validateMessages" | "validateTrigger" | "onFieldsChange" | "onFinish" | "onFinishFailed" | "onValuesChange"> & import("../../utils/native-props").NativeProps<never> & Partial<import("./context").FormContextType> & {
9
10
  footer?: import("react").ReactNode;
@@ -11,6 +12,7 @@ declare const _default: import("react").ForwardRefExoticComponent<Pick<import("r
11
12
  mode?: "default" | "card" | undefined;
12
13
  } & import("react").RefAttributes<Pick<import("rc-field-form").FormInstance<any>, "submit" | "getFieldValue" | "getFieldsValue" | "getFieldError" | "getFieldsError" | "isFieldTouched" | "isFieldsTouched" | "resetFields" | "setFields" | "setFieldsValue" | "validateFields">>> & {
13
14
  Item: import("react").FC<import("./form-item").FormItemProps>;
15
+ Subscribe: import("react").VFC<import("./form-subscribe").FormSubscribeProps>;
14
16
  Header: import("react").FC<{}>;
15
17
  useForm: typeof useForm;
16
18
  };
@@ -17,8 +17,11 @@ var _header = require("./header");
17
17
 
18
18
  var _rcFieldForm = require("rc-field-form");
19
19
 
20
+ var _formSubscribe = require("./form-subscribe");
21
+
20
22
  var _default = (0, _attachPropertiesToComponent.attachPropertiesToComponent)(_form.Form, {
21
23
  Item: _formItem.FormItem,
24
+ Subscribe: _formSubscribe.FormSubscribe,
22
25
  Header: _header.Header,
23
26
  useForm: _rcFieldForm.useForm
24
27
  });
@@ -19,7 +19,7 @@ var _toCssLength = require("../../utils/to-css-length");
19
19
 
20
20
  var _lazyDetector = require("./lazy-detector");
21
21
 
22
- var _ahooks = require("ahooks");
22
+ var _useIsomorphicUpdateLayoutEffect = require("../../utils/use-isomorphic-update-layout-effect");
23
23
 
24
24
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
25
 
@@ -46,7 +46,7 @@ const Image = (0, _stagedComponents.staged)(p => {
46
46
  const [initialized, setInitialized] = (0, _react.useState)(!props.lazy);
47
47
  src = initialized ? props.src : undefined;
48
48
  srcSet = initialized ? props.srcSet : undefined;
49
- (0, _ahooks.useUpdateLayoutEffect)(() => {
49
+ (0, _useIsomorphicUpdateLayoutEffect.useIsomorphicUpdateLayoutEffect)(() => {
50
50
  setLoaded(false);
51
51
  setFailed(false);
52
52
  }, [src]);
@@ -24,5 +24,6 @@ export declare type ImageUploaderProps = {
24
24
  upload: (file: File) => Promise<ImageUploadItem>;
25
25
  onDelete?: (item: ImageUploadItem) => boolean | Promise<boolean> | void;
26
26
  preview?: boolean;
27
+ showFailed?: boolean;
27
28
  } & NativeProps<'--cell-size'>;
28
29
  export declare const ImageUploader: FC<ImageUploaderProps>;
@@ -40,7 +40,8 @@ const defaultProps = {
40
40
  maxCount: 0,
41
41
  defaultValue: [],
42
42
  accept: 'image/*',
43
- preview: true
43
+ preview: true,
44
+ showFailed: true
44
45
  };
45
46
 
46
47
  const ImageUploader = p => {
@@ -178,15 +179,21 @@ const ImageUploader = p => {
178
179
  setValue(value.filter((x, i) => i !== index));
179
180
  })
180
181
  });
181
- }), tasks.map(task => _react.default.createElement(_previewItem.default, {
182
- key: task.id,
183
- file: task.file,
184
- deletable: task.status !== 'pending',
185
- status: task.status,
186
- onDelete: () => {
187
- setTasks(tasks.filter(x => x.id !== task.id));
182
+ }), tasks.map(task => {
183
+ if (!props.showFailed && task.status === 'fail') {
184
+ return null;
188
185
  }
189
- })), showUpload && _react.default.createElement("div", {
186
+
187
+ return _react.default.createElement(_previewItem.default, {
188
+ key: task.id,
189
+ file: task.file,
190
+ deletable: task.status !== 'pending',
191
+ status: task.status,
192
+ onDelete: () => {
193
+ setTasks(tasks.filter(x => x.id !== task.id));
194
+ }
195
+ });
196
+ }), showUpload && _react.default.createElement("div", {
190
197
  className: `${classPrefix}-upload-button-wrap`
191
198
  }, props.children ? props.children : _react.default.createElement("span", {
192
199
  className: `${classPrefix}-cell ${classPrefix}-upload-button`,
@@ -7,10 +7,14 @@ exports.Slide = void 0;
7
7
 
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
 
10
- var _react2 = require("@use-gesture/react");
11
-
12
10
  var _web = require("@react-spring/web");
13
11
 
12
+ var _rubberband = require("../../utils/rubberband");
13
+
14
+ var _useDragAndPinch = require("../../utils/use-drag-and-pinch");
15
+
16
+ var _bound = require("../../utils/bound");
17
+
14
18
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
19
 
16
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; }
@@ -22,6 +26,7 @@ const Slide = props => {
22
26
  dragLockRef
23
27
  } = props;
24
28
  const controlRef = (0, _react.useRef)(null);
29
+ const imgRef = (0, _react.useRef)(null);
25
30
  const [{
26
31
  zoom,
27
32
  x,
@@ -31,11 +36,38 @@ const Slide = props => {
31
36
  x: 0,
32
37
  y: 0,
33
38
  config: {
34
- tension: 300
39
+ tension: 200
35
40
  }
36
41
  }));
37
42
  const pinchLockRef = (0, _react.useRef)(false);
38
- (0, _react2.useGesture)({
43
+
44
+ function boundXY([x, y], rubberband) {
45
+ const currentZoom = zoom.get();
46
+ let xOffset = 0,
47
+ yOffset = 0;
48
+
49
+ if (imgRef.current && controlRef.current) {
50
+ xOffset = ((currentZoom * imgRef.current.width || 0) - controlRef.current.clientWidth) / 2;
51
+ yOffset = ((currentZoom * imgRef.current.height || 0) - controlRef.current.clientHeight) / 2;
52
+ }
53
+
54
+ xOffset = xOffset > 0 ? xOffset : 0;
55
+ yOffset = yOffset > 0 ? yOffset : 0;
56
+ const bounds = {
57
+ left: -xOffset,
58
+ right: xOffset,
59
+ top: -yOffset,
60
+ bottom: yOffset
61
+ };
62
+
63
+ if (rubberband) {
64
+ return [(0, _rubberband.rubberbandIfOutOfBounds)(x, bounds.left, bounds.right, currentZoom * 50), (0, _rubberband.rubberbandIfOutOfBounds)(y, bounds.top, bounds.bottom, currentZoom * 50)];
65
+ } else {
66
+ return [(0, _bound.bound)(x, bounds.left, bounds.right), (0, _bound.bound)(y, bounds.top, bounds.bottom)];
67
+ }
68
+ }
69
+
70
+ (0, _useDragAndPinch.useDragAndPinch)({
39
71
  onDrag: state => {
40
72
  if (state.tap && state.elapsedTime > 0 && state.elapsedTime < 1000) {
41
73
  // 判断点击时间>0是为了过滤掉非正常操作,例如用户长按选择图片之后的取消操作(也是一次点击)
@@ -55,12 +87,20 @@ const Slide = props => {
55
87
  y: 0
56
88
  });
57
89
  } else {
58
- const [x, y] = state.offset;
59
- api.start({
60
- x,
61
- y,
62
- immediate: true
63
- });
90
+ if (state.last) {
91
+ const [x, y] = boundXY([state.offset[0] + state.velocity[0] * state.direction[0] * 200, state.offset[1] + state.velocity[1] * state.direction[1] * 200], false);
92
+ api.start({
93
+ x,
94
+ y
95
+ });
96
+ } else {
97
+ const [x, y] = boundXY(state.offset, true);
98
+ api.start({
99
+ x,
100
+ y,
101
+ immediate: true
102
+ });
103
+ }
64
104
  }
65
105
  },
66
106
  onPinch: state => {
@@ -68,16 +108,15 @@ const Slide = props => {
68
108
 
69
109
  pinchLockRef.current = !state.last;
70
110
  const [d] = state.offset;
71
- if (d < 0) return; // pinch的rubberband不会自动弹回bound,这里手动实现了
72
-
73
- const zoom = state.last ? Math.max(Math.min(d, props.maxZoom), 1) : d;
111
+ if (d < 0) return;
112
+ const nextZoom = state.last ? (0, _bound.bound)(d, 1, props.maxZoom) : d;
74
113
  api.start({
75
- zoom,
114
+ zoom: nextZoom,
76
115
  immediate: !state.last
77
116
  });
78
- (_a = props.onZoomChange) === null || _a === void 0 ? void 0 : _a.call(props, zoom);
117
+ (_a = props.onZoomChange) === null || _a === void 0 ? void 0 : _a.call(props, nextZoom);
79
118
 
80
- if (state.last && zoom <= 1) {
119
+ if (state.last && nextZoom <= 1) {
81
120
  api.start({
82
121
  x: 0,
83
122
  y: 0
@@ -121,11 +160,12 @@ const Slide = props => {
121
160
  }, _react.default.createElement(_web.animated.div, {
122
161
  className: `${classPrefix}-image-wrapper`,
123
162
  style: {
124
- scale: zoom,
125
- x,
126
- y
163
+ translateX: x,
164
+ translateY: y,
165
+ scale: zoom
127
166
  }
128
167
  }, _react.default.createElement("img", {
168
+ ref: imgRef,
129
169
  src: props.image,
130
170
  draggable: false,
131
171
  alt: props.image