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
@@ -11,8 +11,6 @@ var _web = require("@react-spring/web");
11
11
 
12
12
  var _react2 = require("@use-gesture/react");
13
13
 
14
- var _convertPx = require("../../utils/convert-px");
15
-
16
14
  var _rubberband = require("../../utils/rubberband");
17
15
 
18
16
  var _bound = require("../../utils/bound");
@@ -21,6 +19,8 @@ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
21
19
 
22
20
  var _ahooks = require("ahooks");
23
21
 
22
+ var _classnames = _interopRequireDefault(require("classnames"));
23
+
24
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
25
 
26
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); }
@@ -29,7 +29,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
29
29
 
30
30
  const classPrefix = `adm-picker-view`;
31
31
  const Wheel = (0, _react.memo)(props => {
32
- const itemHeight = (0, _convertPx.convertPx)(34);
33
32
  const {
34
33
  value,
35
34
  column
@@ -51,12 +50,23 @@ const Wheel = (0, _react.memo)(props => {
51
50
  }
52
51
  }));
53
52
  const draggingRef = (0, _react.useRef)(false);
53
+ const dummyItemRef = (0, _react.useRef)(null);
54
+ const itemHeight = (0, _react.useRef)(34);
55
+ (0, _ahooks.useIsomorphicLayoutEffect)(() => {
56
+ const dummyItem = dummyItemRef.current;
57
+ if (!dummyItem) return;
58
+ const rect = dummyItem.getBoundingClientRect();
59
+
60
+ if (rect.height > 0) {
61
+ itemHeight.current = rect.height;
62
+ }
63
+ });
54
64
  (0, _ahooks.useIsomorphicLayoutEffect)(() => {
55
65
  if (draggingRef.current) return;
56
66
  if (!value) return;
57
67
  const targetIndex = column.findIndex(item => item.value === value);
58
68
  if (targetIndex < 0) return;
59
- const finalPosition = targetIndex * -itemHeight;
69
+ const finalPosition = targetIndex * -itemHeight.current;
60
70
  api.start({
61
71
  y: finalPosition,
62
72
  immediate: y.goal !== finalPosition
@@ -76,7 +86,7 @@ const Wheel = (0, _react.memo)(props => {
76
86
  }, [column, value]);
77
87
 
78
88
  function scrollSelect(index) {
79
- const finalPosition = index * -itemHeight;
89
+ const finalPosition = index * -itemHeight.current;
80
90
  api.start({
81
91
  y: finalPosition
82
92
  });
@@ -87,18 +97,18 @@ const Wheel = (0, _react.memo)(props => {
87
97
 
88
98
  const bind = (0, _react2.useDrag)(state => {
89
99
  draggingRef.current = true;
90
- const min = -((column.length - 1) * itemHeight);
100
+ const min = -((column.length - 1) * itemHeight.current);
91
101
  const max = 0;
92
102
 
93
103
  if (state.last) {
94
104
  draggingRef.current = false;
95
105
  const position = state.offset[1] + state.velocity[1] * state.direction[1] * 50;
96
- const targetIndex = min < max ? -Math.round((0, _bound.bound)(position, min, max) / itemHeight) : 0;
106
+ const targetIndex = min < max ? -Math.round((0, _bound.bound)(position, min, max) / itemHeight.current) : 0;
97
107
  scrollSelect(targetIndex);
98
108
  } else {
99
109
  const position = state.offset[1];
100
110
  api.start({
101
- y: (0, _rubberband.rubberbandIfOutOfBounds)(position, min, max, itemHeight * 50, 0.2)
111
+ y: (0, _rubberband.rubberbandIfOutOfBounds)(position, min, max, itemHeight.current * 50, 0.2)
102
112
  });
103
113
  }
104
114
  }, {
@@ -146,7 +156,11 @@ const Wheel = (0, _react.memo)(props => {
146
156
 
147
157
  return _react.default.createElement("div", Object.assign({
148
158
  className: `${classPrefix}-column`
149
- }, bind()), _react.default.createElement(_web.animated.div, {
159
+ }, bind()), _react.default.createElement("div", {
160
+ ref: dummyItemRef,
161
+ className: (0, _classnames.default)(`${classPrefix}-column-item`, `${classPrefix}-column-item-dummy`),
162
+ "aria-hidden": true
163
+ }), _react.default.createElement(_web.animated.div, {
150
164
  style: {
151
165
  translateY: y
152
166
  },
@@ -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;
@@ -52,8 +52,7 @@ function show(p) {
52
52
  bodyContainer.appendChild(container);
53
53
  clear();
54
54
  containers.push(container);
55
-
56
- const TempToast = () => {
55
+ const TempToast = (0, _react.forwardRef)((_, ref) => {
57
56
  const [visible, setVisible] = (0, _react.useState)(true);
58
57
  (0, _react.useEffect)(() => {
59
58
  return () => {
@@ -74,6 +73,9 @@ function show(p) {
74
73
  window.clearTimeout(timer);
75
74
  };
76
75
  }, []);
76
+ (0, _react.useImperativeHandle)(ref, () => ({
77
+ close: () => setVisible(false)
78
+ }));
77
79
  return _react.default.createElement(_toast.InternalToast, Object.assign({}, props, {
78
80
  getContainer: () => container,
79
81
  visible: visible,
@@ -81,9 +83,20 @@ function show(p) {
81
83
  unmount(container);
82
84
  }
83
85
  }));
84
- };
86
+ });
87
+ const ref = (0, _react.createRef)();
85
88
 
86
- _reactDom.default.render(_react.default.createElement(TempToast, null), container);
89
+ _reactDom.default.render(_react.default.createElement(TempToast, {
90
+ ref: ref
91
+ }), container);
92
+
93
+ return {
94
+ close: () => {
95
+ var _a;
96
+
97
+ (_a = ref.current) === null || _a === void 0 ? void 0 : _a.close();
98
+ }
99
+ };
87
100
  }
88
101
 
89
102
  function clear() {
@@ -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,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useDragAndPinch = void 0;
7
+
8
+ var _react = require("@use-gesture/react");
9
+
10
+ const useDragAndPinch = (0, _react.createUseGesture)([_react.dragAction, _react.pinchAction]);
11
+ exports.useDragAndPinch = useDragAndPinch;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const useIsomorphicUpdateLayoutEffect: typeof import("react").useEffect | typeof import("react").useLayoutEffect;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useIsomorphicUpdateLayoutEffect = void 0;
7
+
8
+ var _createUpdateEffect = require("ahooks/lib/createUpdateEffect");
9
+
10
+ var _ahooks = require("ahooks");
11
+
12
+ const useIsomorphicUpdateLayoutEffect = (0, _createUpdateEffect.createUpdateEffect)(_ahooks.useIsomorphicLayoutEffect);
13
+ exports.useIsomorphicUpdateLayoutEffect = useIsomorphicUpdateLayoutEffect;
@@ -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
 
17
18
  .adm-floating-panel-mask {
@@ -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>>;
@@ -6,11 +6,12 @@ import { supportsPassive } from '../../utils/supports-passive';
6
6
  import { nearest } from '../../utils/nearest';
7
7
  import { mergeProps } from '../../utils/with-default-props';
8
8
  import { useLockScroll } from '../../utils/use-lock-scroll';
9
+ import { useMemoizedFn } from 'ahooks';
9
10
  const defaultProps = {
10
11
  handleDraggingOfContent: true
11
12
  };
12
13
  export const FloatingPanel = forwardRef((p, ref) => {
13
- var _a;
14
+ var _a, _b;
14
15
 
15
16
  const props = mergeProps(defaultProps, p);
16
17
  const {
@@ -27,6 +28,7 @@ export const FloatingPanel = forwardRef((p, ref) => {
27
28
  top: possibles[possibles.length - 1],
28
29
  bottom: possibles[0]
29
30
  };
31
+ const onHeightChange = useMemoizedFn((_b = props.onHeightChange) !== null && _b !== void 0 ? _b : () => {});
30
32
  const [{
31
33
  y
32
34
  }, api] = useSpring(() => ({
@@ -35,9 +37,7 @@ export const FloatingPanel = forwardRef((p, ref) => {
35
37
  tension: 300
36
38
  },
37
39
  onChange: result => {
38
- var _a;
39
-
40
- (_a = props.onHeightChange) === null || _a === void 0 ? void 0 : _a.call(props, result.value.y, y.isAnimating);
40
+ onHeightChange(result.value.y, y.isAnimating);
41
41
  }
42
42
  }));
43
43
  useDrag(state => {
@@ -114,7 +114,7 @@ export const FloatingPanel = forwardRef((p, ref) => {
114
114
  className: 'adm-floating-panel',
115
115
  style: {
116
116
  height: maxHeight,
117
- y
117
+ translateY: y.to(y => `calc(100% + (${y}px))`)
118
118
  }
119
119
  }, React.createElement("div", {
120
120
  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,14 @@
1
+ import React from 'react';
2
+ import Form from '.';
3
+ export const FormSubscribe = ({
4
+ children,
5
+ to
6
+ }) => {
7
+ return React.createElement(Form.Item, {
8
+ noStyle: true,
9
+ dependencies: to
10
+ }, form => {
11
+ const changedValues = form.getFieldsValue(to);
12
+ return children(changedValues, form);
13
+ });
14
+ };
@@ -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
  };
@@ -4,8 +4,10 @@ import { attachPropertiesToComponent } from '../../utils/attach-properties-to-co
4
4
  import { FormItem } from './form-item';
5
5
  import { Header } from './header';
6
6
  import { useForm } from 'rc-field-form';
7
+ import { FormSubscribe } from './form-subscribe';
7
8
  export default attachPropertiesToComponent(Form, {
8
9
  Item: FormItem,
10
+ Subscribe: FormSubscribe,
9
11
  Header,
10
12
  useForm
11
13
  });
@@ -5,7 +5,7 @@ import { PictureOutline, PictureWrongOutline } from 'antd-mobile-icons';
5
5
  import { staged } from 'staged-components';
6
6
  import { toCSSLength } from '../../utils/to-css-length';
7
7
  import { LazyDetector } from './lazy-detector';
8
- import { useUpdateLayoutEffect } from 'ahooks';
8
+ import { useIsomorphicUpdateLayoutEffect } from '../../utils/use-isomorphic-update-layout-effect';
9
9
  const classPrefix = `adm-image`;
10
10
  const defaultProps = {
11
11
  fit: 'fill',
@@ -27,7 +27,7 @@ export const Image = staged(p => {
27
27
  const [initialized, setInitialized] = useState(!props.lazy);
28
28
  src = initialized ? props.src : undefined;
29
29
  srcSet = initialized ? props.srcSet : undefined;
30
- useUpdateLayoutEffect(() => {
30
+ useIsomorphicUpdateLayoutEffect(() => {
31
31
  setLoaded(false);
32
32
  setFailed(false);
33
33
  }, [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>;
@@ -17,7 +17,8 @@ const defaultProps = {
17
17
  maxCount: 0,
18
18
  defaultValue: [],
19
19
  accept: 'image/*',
20
- preview: true
20
+ preview: true,
21
+ showFailed: true
21
22
  };
22
23
  export const ImageUploader = p => {
23
24
  const props = mergeProps(defaultProps, p);
@@ -154,15 +155,21 @@ export const ImageUploader = p => {
154
155
  setValue(value.filter((x, i) => i !== index));
155
156
  })
156
157
  });
157
- }), tasks.map(task => React.createElement(PreviewItem, {
158
- key: task.id,
159
- file: task.file,
160
- deletable: task.status !== 'pending',
161
- status: task.status,
162
- onDelete: () => {
163
- setTasks(tasks.filter(x => x.id !== task.id));
158
+ }), tasks.map(task => {
159
+ if (!props.showFailed && task.status === 'fail') {
160
+ return null;
164
161
  }
165
- })), showUpload && React.createElement("div", {
162
+
163
+ return React.createElement(PreviewItem, {
164
+ key: task.id,
165
+ file: task.file,
166
+ deletable: task.status !== 'pending',
167
+ status: task.status,
168
+ onDelete: () => {
169
+ setTasks(tasks.filter(x => x.id !== task.id));
170
+ }
171
+ });
172
+ }), showUpload && React.createElement("div", {
166
173
  className: `${classPrefix}-upload-button-wrap`
167
174
  }, props.children ? props.children : React.createElement("span", {
168
175
  className: `${classPrefix}-cell ${classPrefix}-upload-button`,
@@ -1,12 +1,15 @@
1
1
  import React, { useRef } from 'react';
2
- import { useGesture } from '@use-gesture/react';
3
2
  import { useSpring, animated } from '@react-spring/web';
3
+ import { rubberbandIfOutOfBounds } from '../../utils/rubberband';
4
+ import { useDragAndPinch } from '../../utils/use-drag-and-pinch';
5
+ import { bound } from '../../utils/bound';
4
6
  const classPrefix = `adm-image-viewer`;
5
7
  export const Slide = props => {
6
8
  const {
7
9
  dragLockRef
8
10
  } = props;
9
11
  const controlRef = useRef(null);
12
+ const imgRef = useRef(null);
10
13
  const [{
11
14
  zoom,
12
15
  x,
@@ -16,11 +19,38 @@ export const Slide = props => {
16
19
  x: 0,
17
20
  y: 0,
18
21
  config: {
19
- tension: 300
22
+ tension: 200
20
23
  }
21
24
  }));
22
25
  const pinchLockRef = useRef(false);
23
- useGesture({
26
+
27
+ function boundXY([x, y], rubberband) {
28
+ const currentZoom = zoom.get();
29
+ let xOffset = 0,
30
+ yOffset = 0;
31
+
32
+ if (imgRef.current && controlRef.current) {
33
+ xOffset = ((currentZoom * imgRef.current.width || 0) - controlRef.current.clientWidth) / 2;
34
+ yOffset = ((currentZoom * imgRef.current.height || 0) - controlRef.current.clientHeight) / 2;
35
+ }
36
+
37
+ xOffset = xOffset > 0 ? xOffset : 0;
38
+ yOffset = yOffset > 0 ? yOffset : 0;
39
+ const bounds = {
40
+ left: -xOffset,
41
+ right: xOffset,
42
+ top: -yOffset,
43
+ bottom: yOffset
44
+ };
45
+
46
+ if (rubberband) {
47
+ return [rubberbandIfOutOfBounds(x, bounds.left, bounds.right, currentZoom * 50), rubberbandIfOutOfBounds(y, bounds.top, bounds.bottom, currentZoom * 50)];
48
+ } else {
49
+ return [bound(x, bounds.left, bounds.right), bound(y, bounds.top, bounds.bottom)];
50
+ }
51
+ }
52
+
53
+ useDragAndPinch({
24
54
  onDrag: state => {
25
55
  if (state.tap && state.elapsedTime > 0 && state.elapsedTime < 1000) {
26
56
  // 判断点击时间>0是为了过滤掉非正常操作,例如用户长按选择图片之后的取消操作(也是一次点击)
@@ -40,12 +70,20 @@ export const Slide = props => {
40
70
  y: 0
41
71
  });
42
72
  } else {
43
- const [x, y] = state.offset;
44
- api.start({
45
- x,
46
- y,
47
- immediate: true
48
- });
73
+ if (state.last) {
74
+ 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);
75
+ api.start({
76
+ x,
77
+ y
78
+ });
79
+ } else {
80
+ const [x, y] = boundXY(state.offset, true);
81
+ api.start({
82
+ x,
83
+ y,
84
+ immediate: true
85
+ });
86
+ }
49
87
  }
50
88
  },
51
89
  onPinch: state => {
@@ -53,16 +91,15 @@ export const Slide = props => {
53
91
 
54
92
  pinchLockRef.current = !state.last;
55
93
  const [d] = state.offset;
56
- if (d < 0) return; // pinch的rubberband不会自动弹回bound,这里手动实现了
57
-
58
- const zoom = state.last ? Math.max(Math.min(d, props.maxZoom), 1) : d;
94
+ if (d < 0) return;
95
+ const nextZoom = state.last ? bound(d, 1, props.maxZoom) : d;
59
96
  api.start({
60
- zoom,
97
+ zoom: nextZoom,
61
98
  immediate: !state.last
62
99
  });
63
- (_a = props.onZoomChange) === null || _a === void 0 ? void 0 : _a.call(props, zoom);
100
+ (_a = props.onZoomChange) === null || _a === void 0 ? void 0 : _a.call(props, nextZoom);
64
101
 
65
- if (state.last && zoom <= 1) {
102
+ if (state.last && nextZoom <= 1) {
66
103
  api.start({
67
104
  x: 0,
68
105
  y: 0
@@ -106,11 +143,12 @@ export const Slide = props => {
106
143
  }, React.createElement(animated.div, {
107
144
  className: `${classPrefix}-image-wrapper`,
108
145
  style: {
109
- scale: zoom,
110
- x,
111
- y
146
+ translateX: x,
147
+ translateY: y,
148
+ scale: zoom
112
149
  }
113
150
  }, React.createElement("img", {
151
+ ref: imgRef,
114
152
  src: props.image,
115
153
  draggable: false,
116
154
  alt: props.image
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { ReactNode } from 'react';
2
2
  import { NativeProps } from '../../utils/native-props';
3
3
  export declare type IndexBarProps = {
4
4
  sticky?: boolean;
@@ -15,9 +15,11 @@ export const IndexBar = forwardRef((p, ref) => {
15
15
  const props = mergeProps(defaultProps, p);
16
16
  const titleHeight = convertPx(35);
17
17
  const bodyRef = useRef(null);
18
- const indexes = [];
18
+ const indexItems = [];
19
19
  const panels = [];
20
20
  React.Children.forEach(props.children, child => {
21
+ var _a;
22
+
21
23
  if (!React.isValidElement(child)) return;
22
24
 
23
25
  if (child.type !== Panel) {
@@ -25,7 +27,10 @@ export const IndexBar = forwardRef((p, ref) => {
25
27
  return;
26
28
  }
27
29
 
28
- indexes.push(child.props.index);
30
+ indexItems.push({
31
+ index: child.props.index,
32
+ brief: (_a = child.props.brief) !== null && _a !== void 0 ? _a : child.props.index.charAt(0)
33
+ });
29
34
  panels.push(withNativeProps(child.props, React.createElement("div", {
30
35
  key: child.props.index,
31
36
  "data-index": child.props.index,
@@ -34,7 +39,10 @@ export const IndexBar = forwardRef((p, ref) => {
34
39
  className: `${classPrefix}-anchor-title`
35
40
  }, child.props.title || child.props.index), child.props.children)));
36
41
  });
37
- const [activeIndex, setActiveIndex] = useState(indexes[0]);
42
+ const [activeIndex, setActiveIndex] = useState(() => {
43
+ const firstItem = indexItems[0];
44
+ return firstItem ? firstItem.index : null;
45
+ });
38
46
  useImperativeHandle(ref, () => ({
39
47
  scrollTo
40
48
  }));
@@ -86,7 +94,7 @@ export const IndexBar = forwardRef((p, ref) => {
86
94
  [`${classPrefix}-sticky`]: props.sticky
87
95
  })
88
96
  }, React.createElement(Sidebar, {
89
- indexes: indexes,
97
+ indexItems: indexItems,
90
98
  activeIndex: activeIndex,
91
99
  onActive: index => {
92
100
  scrollTo(index);
@@ -1,10 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import './index-bar.less';
3
3
  export type { IndexBarProps, IndexBarRef } from './index-bar';
4
+ export type { IndexBarPanelProps } from './panel';
4
5
  declare const _default: import("react").ForwardRefExoticComponent<{
5
6
  sticky?: boolean | undefined;
6
7
  children?: import("react").ReactNode;
7
8
  } & import("../../utils/native-props").NativeProps<"--sticky-offset-top"> & import("react").RefAttributes<import("./index-bar").IndexBarRef>> & {
8
- Panel: import("react").FC<import("./panel").IndexBarAnchorProps>;
9
+ Panel: import("react").FC<import("./panel").IndexBarPanelProps>;
9
10
  };
10
11
  export default _default;
@@ -1,7 +1,8 @@
1
- import { FC } from 'react';
1
+ import { FC, ReactNode } from 'react';
2
2
  import { NativeProps } from '../../utils/native-props';
3
- export declare type IndexBarAnchorProps = {
3
+ export declare type IndexBarPanelProps = {
4
4
  index: string;
5
- title?: string;
5
+ title?: ReactNode;
6
+ brief?: ReactNode;
6
7
  } & NativeProps;
7
- export declare const Panel: FC<IndexBarAnchorProps>;
8
+ export declare const Panel: FC<IndexBarPanelProps>;
@@ -1,7 +1,10 @@
1
- import { FC } from 'react';
1
+ import { FC, ReactNode } from 'react';
2
2
  declare type SidebarProps = {
3
- indexes: string[];
4
- activeIndex: string;
3
+ indexItems: {
4
+ index: string;
5
+ brief: ReactNode;
6
+ }[];
7
+ activeIndex: string | null;
5
8
  onActive: (index: string) => void;
6
9
  };
7
10
  export declare const Sidebar: FC<SidebarProps>;
@@ -33,7 +33,10 @@ export const Sidebar = props => {
33
33
  props.onActive(index);
34
34
  }
35
35
  }
36
- }, props.indexes.map(index => {
36
+ }, props.indexItems.map(({
37
+ index,
38
+ brief
39
+ }) => {
37
40
  const active = index === props.activeIndex;
38
41
  return React.createElement("div", {
39
42
  className: `${classPrefix}-sidebar-row`,
@@ -52,11 +55,11 @@ export const Sidebar = props => {
52
55
  key: index
53
56
  }, interacting && active && React.createElement("div", {
54
57
  className: `${classPrefix}-sidebar-bubble`
55
- }, index), React.createElement("div", {
58
+ }, brief), React.createElement("div", {
56
59
  className: classNames(`${classPrefix}-sidebar-item`, {
57
60
  [`${classPrefix}-sidebar-item-active`]: active
58
61
  }),
59
62
  "data-index": index
60
- }, React.createElement("div", null, index)));
63
+ }, React.createElement("div", null, brief)));
61
64
  }));
62
65
  };