@douyinfe/semi-ui 2.49.0-beta.0 → 2.49.1
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/dist/umd/semi-ui.js +361 -358
- package/dist/umd/semi-ui.js.map +1 -1
- package/dist/umd/semi-ui.min.js +1 -1
- package/dist/umd/semi-ui.min.js.map +1 -1
- package/lib/cjs/image/interface.d.ts +3 -3
- package/lib/cjs/image/previewFooter.js +5 -8
- package/lib/cjs/image/previewHeader.d.ts +2 -2
- package/lib/cjs/image/previewHeader.js +9 -8
- package/lib/cjs/image/previewImage.d.ts +1 -12
- package/lib/cjs/image/previewImage.js +23 -83
- package/lib/cjs/image/previewInner.d.ts +11 -2
- package/lib/cjs/image/previewInner.js +60 -42
- package/lib/cjs/index.d.ts +2 -0
- package/lib/cjs/index.js +14 -0
- package/lib/cjs/modal/confirm.d.ts +6 -6
- package/lib/es/image/interface.d.ts +3 -3
- package/lib/es/image/previewFooter.js +5 -8
- package/lib/es/image/previewHeader.d.ts +2 -2
- package/lib/es/image/previewHeader.js +4 -3
- package/lib/es/image/previewImage.d.ts +1 -12
- package/lib/es/image/previewImage.js +23 -83
- package/lib/es/image/previewInner.d.ts +11 -2
- package/lib/es/image/previewInner.js +60 -42
- package/lib/es/index.d.ts +2 -0
- package/lib/es/index.js +2 -0
- package/lib/es/modal/confirm.d.ts +6 -6
- package/package.json +8 -8
|
@@ -157,13 +157,13 @@ export declare function withError(props: ModalReactProps): {
|
|
|
157
157
|
height?: string | number;
|
|
158
158
|
content?: React.ReactNode;
|
|
159
159
|
icon: string | number | boolean | React.ReactFragment | JSX.Element;
|
|
160
|
-
onCancel?: (e: React.MouseEvent<Element, MouseEvent>) => void | Promise<any>;
|
|
161
160
|
closeOnEsc?: boolean;
|
|
162
161
|
preventScroll?: boolean;
|
|
163
162
|
afterClose?: () => void;
|
|
164
163
|
keepDOM?: boolean;
|
|
165
164
|
cancelText?: string;
|
|
166
165
|
okText?: string;
|
|
166
|
+
onCancel?: (e: React.MouseEvent<Element, MouseEvent>) => void | Promise<any>;
|
|
167
167
|
closeIcon?: React.ReactNode;
|
|
168
168
|
bodyStyle?: React.CSSProperties;
|
|
169
169
|
closable?: boolean;
|
|
@@ -377,11 +377,6 @@ export declare function withError(props: ModalReactProps): {
|
|
|
377
377
|
accessKey?: string;
|
|
378
378
|
autoFocus?: boolean;
|
|
379
379
|
content?: string;
|
|
380
|
-
formAction?: string;
|
|
381
|
-
formEncType?: string;
|
|
382
|
-
formMethod?: string;
|
|
383
|
-
formNoValidate?: boolean;
|
|
384
|
-
formTarget?: string;
|
|
385
380
|
contextMenu?: string;
|
|
386
381
|
dir?: string;
|
|
387
382
|
draggable?: boolean | "true" | "false";
|
|
@@ -463,6 +458,11 @@ export declare function withError(props: ModalReactProps): {
|
|
|
463
458
|
'aria-valuemin'?: number;
|
|
464
459
|
'aria-valuenow'?: number;
|
|
465
460
|
'aria-valuetext'?: string;
|
|
461
|
+
formAction?: string;
|
|
462
|
+
formEncType?: string;
|
|
463
|
+
formMethod?: string;
|
|
464
|
+
formNoValidate?: boolean;
|
|
465
|
+
formTarget?: string;
|
|
466
466
|
};
|
|
467
467
|
};
|
|
468
468
|
export declare function withConfirm(props: ModalReactProps): {
|
|
@@ -53,6 +53,8 @@ export interface PreviewProps extends BaseProps {
|
|
|
53
53
|
zIndex?: number;
|
|
54
54
|
children?: ReactNode;
|
|
55
55
|
crossOrigin?: "anonymous" | "use-credentials";
|
|
56
|
+
maxZoom?: number;
|
|
57
|
+
minZoom?: number;
|
|
56
58
|
renderHeader?: (info: any) => ReactNode;
|
|
57
59
|
renderPreviewMenu?: (props: MenuProps) => ReactNode;
|
|
58
60
|
getPopupContainer?: () => HTMLElement;
|
|
@@ -138,14 +140,12 @@ export interface FooterProps extends SliderProps {
|
|
|
138
140
|
onRotate?: (direction: string) => void;
|
|
139
141
|
onDownload?: () => void;
|
|
140
142
|
renderPreviewMenu?: (props: MenuProps) => ReactNode;
|
|
143
|
+
forwardRef?: React.RefObject<HTMLElement>;
|
|
141
144
|
}
|
|
142
145
|
export interface PreviewImageProps {
|
|
143
146
|
src?: string;
|
|
144
147
|
rotation?: number;
|
|
145
148
|
style?: React.CSSProperties;
|
|
146
|
-
maxZoom?: number;
|
|
147
|
-
minZoom?: number;
|
|
148
|
-
zoomStep?: number;
|
|
149
149
|
zoom?: number;
|
|
150
150
|
ratio?: RatioType;
|
|
151
151
|
disableDownload?: boolean;
|
|
@@ -12,14 +12,9 @@ import PreviewFooterFoundation from '@douyinfe/semi-foundation/lib/es/image/prev
|
|
|
12
12
|
import LocaleConsumer from "../locale/localeConsumer";
|
|
13
13
|
const prefixCls = cssClasses.PREFIX;
|
|
14
14
|
const footerPrefixCls = `${cssClasses.PREFIX}-preview-footer`;
|
|
15
|
-
let mouseActiveTime = 0;
|
|
16
15
|
export default class Footer extends BaseComponent {
|
|
17
16
|
get adapter() {
|
|
18
|
-
return Object.assign(
|
|
19
|
-
setStartMouseOffset: time => {
|
|
20
|
-
mouseActiveTime = time;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
17
|
+
return Object.assign({}, super.adapter);
|
|
23
18
|
}
|
|
24
19
|
constructor(props) {
|
|
25
20
|
super(props);
|
|
@@ -259,13 +254,15 @@ export default class Footer extends BaseComponent {
|
|
|
259
254
|
render() {
|
|
260
255
|
const {
|
|
261
256
|
className,
|
|
262
|
-
renderPreviewMenu
|
|
257
|
+
renderPreviewMenu,
|
|
258
|
+
forwardRef
|
|
263
259
|
} = this.props;
|
|
264
260
|
const menuCls = cls(footerPrefixCls, `${footerPrefixCls}-wrapper`, className, {
|
|
265
261
|
[`${footerPrefixCls}-content`]: !Boolean(renderPreviewMenu)
|
|
266
262
|
});
|
|
267
263
|
return /*#__PURE__*/React.createElement("section", {
|
|
268
|
-
className: menuCls
|
|
264
|
+
className: menuCls,
|
|
265
|
+
ref: forwardRef
|
|
269
266
|
}, renderPreviewMenu ? this.customRenderViewMenu() : this.getFooterMenu());
|
|
270
267
|
}
|
|
271
268
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from "react";
|
|
2
2
|
import { HeaderProps } from "./interface";
|
|
3
|
-
declare const Header: React.
|
|
3
|
+
declare const Header: React.ForwardRefExoticComponent<HeaderProps & React.RefAttributes<HTMLElement>>;
|
|
4
4
|
export default Header;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, { forwardRef } from "react";
|
|
2
2
|
import { IconClose } from "@douyinfe/semi-icons";
|
|
3
3
|
import { cssClasses } from '@douyinfe/semi-foundation/lib/es/image/constants';
|
|
4
4
|
import cls from "classnames";
|
|
5
5
|
import { PreviewContext } from "./previewContext";
|
|
6
6
|
const prefixCls = `${cssClasses.PREFIX}-preview-header`;
|
|
7
|
-
const Header = _ref => {
|
|
7
|
+
const Header = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
8
8
|
let {
|
|
9
9
|
onClose,
|
|
10
10
|
titleStyle,
|
|
@@ -21,6 +21,7 @@ const Header = _ref => {
|
|
|
21
21
|
title = titles[currentIndex];
|
|
22
22
|
}
|
|
23
23
|
return /*#__PURE__*/React.createElement("section", {
|
|
24
|
+
ref: ref,
|
|
24
25
|
className: cls(prefixCls, className)
|
|
25
26
|
}, /*#__PURE__*/React.createElement("section", {
|
|
26
27
|
className: `${prefixCls}-title`,
|
|
@@ -30,5 +31,5 @@ const Header = _ref => {
|
|
|
30
31
|
onMouseUp: onClose
|
|
31
32
|
}, /*#__PURE__*/React.createElement(IconClose, null)));
|
|
32
33
|
});
|
|
33
|
-
};
|
|
34
|
+
});
|
|
34
35
|
export default Header;
|
|
@@ -8,9 +8,6 @@ export default class PreviewImage extends BaseComponent<PreviewImageProps, Previ
|
|
|
8
8
|
src: PropTypes.Requireable<string>;
|
|
9
9
|
rotation: PropTypes.Requireable<number>;
|
|
10
10
|
style: PropTypes.Requireable<object>;
|
|
11
|
-
maxZoom: PropTypes.Requireable<number>;
|
|
12
|
-
minZoom: PropTypes.Requireable<number>;
|
|
13
|
-
zoomStep: PropTypes.Requireable<number>;
|
|
14
11
|
zoom: PropTypes.Requireable<number>;
|
|
15
12
|
ratio: PropTypes.Requireable<string>;
|
|
16
13
|
disableDownload: PropTypes.Requireable<boolean>;
|
|
@@ -21,29 +18,21 @@ export default class PreviewImage extends BaseComponent<PreviewImageProps, Previ
|
|
|
21
18
|
onError: PropTypes.Requireable<(...args: any[]) => any>;
|
|
22
19
|
};
|
|
23
20
|
static defaultProps: {
|
|
24
|
-
maxZoom: number;
|
|
25
|
-
minZoom: number;
|
|
26
|
-
zoomStep: number;
|
|
27
21
|
zoom: any;
|
|
28
22
|
};
|
|
29
23
|
get adapter(): PreviewImageAdapter<PreviewImageProps, PreviewImageStates>;
|
|
30
24
|
containerRef: React.RefObject<HTMLDivElement>;
|
|
31
|
-
imageRef: HTMLImageElement
|
|
25
|
+
imageRef: React.RefObject<HTMLImageElement>;
|
|
32
26
|
foundation: PreviewImageFoundation;
|
|
33
27
|
constructor(props: any);
|
|
34
28
|
componentDidMount(): void;
|
|
35
29
|
componentWillUnmount(): void;
|
|
36
30
|
componentDidUpdate(prevProps: PreviewImageProps, prevStates: PreviewImageStates): void;
|
|
37
31
|
onWindowResize: () => void;
|
|
38
|
-
handleZoomChange: (newZoom: any, e: any) => void;
|
|
39
32
|
handleRightClickImage: (e: any) => void;
|
|
40
|
-
handleWheel: (e: any) => void;
|
|
41
33
|
handleLoad: (e: any) => void;
|
|
42
34
|
handleError: (e: any) => void;
|
|
43
|
-
resizeImage: () => void;
|
|
44
35
|
handleMoveImage: (e: any) => void;
|
|
45
|
-
registryImageRef: (ref: any) => void;
|
|
46
36
|
onImageMouseDown: (e: React.MouseEvent<HTMLImageElement>) => void;
|
|
47
|
-
onImageMouseUp: () => void;
|
|
48
37
|
render(): JSX.Element;
|
|
49
38
|
}
|
|
@@ -6,38 +6,14 @@ import Spin from "../spin";
|
|
|
6
6
|
import PreviewImageFoundation from '@douyinfe/semi-foundation/lib/es/image/previewImageFoundation';
|
|
7
7
|
const prefixCls = cssClasses.PREFIX;
|
|
8
8
|
const preViewImgPrefixCls = `${prefixCls}-preview-image`;
|
|
9
|
-
let originImageWidth = null;
|
|
10
|
-
let originImageHeight = null;
|
|
11
|
-
let startMouseMove = false;
|
|
12
|
-
// startMouseOffset:The offset of the mouse relative to the left and top of the picture
|
|
13
|
-
let startMouseOffset = {
|
|
14
|
-
x: 0,
|
|
15
|
-
y: 0
|
|
16
|
-
};
|
|
17
9
|
export default class PreviewImage extends BaseComponent {
|
|
18
10
|
get adapter() {
|
|
19
11
|
return Object.assign(Object.assign({}, super.adapter), {
|
|
20
|
-
getOriginImageSize: () => ({
|
|
21
|
-
originImageWidth,
|
|
22
|
-
originImageHeight
|
|
23
|
-
}),
|
|
24
|
-
setOriginImageSize: size => {
|
|
25
|
-
originImageWidth = size.originImageWidth;
|
|
26
|
-
originImageHeight = size.originImageHeight;
|
|
27
|
-
},
|
|
28
12
|
getContainer: () => {
|
|
29
13
|
return this.containerRef.current;
|
|
30
14
|
},
|
|
31
15
|
getImage: () => {
|
|
32
|
-
return this.imageRef;
|
|
33
|
-
},
|
|
34
|
-
getMouseMove: () => startMouseMove,
|
|
35
|
-
setStartMouseMove: move => {
|
|
36
|
-
startMouseMove = move;
|
|
37
|
-
},
|
|
38
|
-
getMouseOffset: () => startMouseOffset,
|
|
39
|
-
setStartMouseOffset: offset => {
|
|
40
|
-
startMouseOffset = offset;
|
|
16
|
+
return this.imageRef.current;
|
|
41
17
|
},
|
|
42
18
|
setLoading: loading => {
|
|
43
19
|
this.setState({
|
|
@@ -45,7 +21,7 @@ export default class PreviewImage extends BaseComponent {
|
|
|
45
21
|
});
|
|
46
22
|
},
|
|
47
23
|
setImageCursor: canDrag => {
|
|
48
|
-
this.imageRef.style.cursor = canDrag ? "grab" : "default";
|
|
24
|
+
this.imageRef.current.style.cursor = canDrag ? "grab" : "default";
|
|
49
25
|
}
|
|
50
26
|
});
|
|
51
27
|
}
|
|
@@ -54,52 +30,22 @@ export default class PreviewImage extends BaseComponent {
|
|
|
54
30
|
this.onWindowResize = () => {
|
|
55
31
|
this.foundation.handleWindowResize();
|
|
56
32
|
};
|
|
57
|
-
this.handleZoomChange = (newZoom, e) => {
|
|
58
|
-
this.foundation.handleZoomChange(newZoom, e);
|
|
59
|
-
};
|
|
60
33
|
// Determine the response method of right click according to the disableDownload parameter in props
|
|
61
34
|
this.handleRightClickImage = e => {
|
|
62
35
|
this.foundation.handleRightClickImage(e);
|
|
63
36
|
};
|
|
64
|
-
this.handleWheel = e => {
|
|
65
|
-
this.foundation.handleWheel(e);
|
|
66
|
-
};
|
|
67
37
|
this.handleLoad = e => {
|
|
68
38
|
this.foundation.handleLoad(e);
|
|
69
39
|
};
|
|
70
40
|
this.handleError = e => {
|
|
71
41
|
this.foundation.handleError(e);
|
|
72
42
|
};
|
|
73
|
-
this.resizeImage = () => {
|
|
74
|
-
this.foundation.handleResizeImage();
|
|
75
|
-
};
|
|
76
43
|
this.handleMoveImage = e => {
|
|
77
44
|
this.foundation.handleMoveImage(e);
|
|
78
45
|
};
|
|
79
|
-
// 为什么通过ref注册wheel而不是使用onWheel事件?
|
|
80
|
-
// 因为对于wheel事件,浏览器将 addEventListener 的 passive 默认值更改为 true。如此,事件监听器便不能取消事件,也不会在用户滚动页面时阻止页面呈现。
|
|
81
|
-
// 这里我们需要保持页面不动,仅放大图片,因此此处需要将 passive 更改设置为 false。
|
|
82
|
-
// Why register wheel via ref instead of using onWheel event?
|
|
83
|
-
// Because for wheel events, the browser changes the passive default of addEventListener to true. This way, the event listener cannot cancel the event, nor prevent the page from rendering when the user scrolls.
|
|
84
|
-
// Here we need to keep the page still and only zoom in on the image, so here we need to set the passive change to false.
|
|
85
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#improving_scrolling_performance_with_passive_listeners。
|
|
86
|
-
this.registryImageRef = ref => {
|
|
87
|
-
if (this.imageRef) {
|
|
88
|
-
this.imageRef.removeEventListener("wheel", this.handleWheel);
|
|
89
|
-
}
|
|
90
|
-
if (ref) {
|
|
91
|
-
ref.addEventListener("wheel", this.handleWheel, {
|
|
92
|
-
passive: false
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
this.imageRef = ref;
|
|
96
|
-
};
|
|
97
46
|
this.onImageMouseDown = e => {
|
|
98
47
|
this.foundation.handleImageMouseDown(e);
|
|
99
48
|
};
|
|
100
|
-
this.onImageMouseUp = () => {
|
|
101
|
-
this.foundation.handleImageMouseUp();
|
|
102
|
-
};
|
|
103
49
|
this.state = {
|
|
104
50
|
width: 0,
|
|
105
51
|
height: 0,
|
|
@@ -113,7 +59,7 @@ export default class PreviewImage extends BaseComponent {
|
|
|
113
59
|
left: 0
|
|
114
60
|
};
|
|
115
61
|
this.containerRef = /*#__PURE__*/React.createRef();
|
|
116
|
-
this.imageRef =
|
|
62
|
+
this.imageRef = /*#__PURE__*/React.createRef();
|
|
117
63
|
this.foundation = new PreviewImageFoundation(this.adapter);
|
|
118
64
|
}
|
|
119
65
|
componentDidMount() {
|
|
@@ -124,27 +70,22 @@ export default class PreviewImage extends BaseComponent {
|
|
|
124
70
|
}
|
|
125
71
|
componentDidUpdate(prevProps, prevStates) {
|
|
126
72
|
// If src changes, start a new loading
|
|
127
|
-
|
|
73
|
+
const zoomChange = "zoom" in this.props && this.props.zoom !== this.state.currZoom;
|
|
74
|
+
const srcChange = this.props.src && this.props.src !== prevProps.src;
|
|
75
|
+
if (srcChange) {
|
|
128
76
|
this.foundation.setLoading(true);
|
|
129
77
|
}
|
|
130
78
|
// If the incoming zoom changes, other content changes are determined based on the new zoom value
|
|
131
|
-
if (
|
|
132
|
-
this.
|
|
79
|
+
if (zoomChange) {
|
|
80
|
+
this.foundation.calculatePreviewImage(this.props.zoom, null);
|
|
133
81
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
} else {
|
|
141
|
-
this.props.onZoom(1);
|
|
142
|
-
}
|
|
82
|
+
if (!zoomChange && !srcChange && prevProps) {
|
|
83
|
+
if ("ratio" in this.props && this.props.ratio !== prevProps.ratio) {
|
|
84
|
+
this.foundation.handleRatioChange();
|
|
85
|
+
}
|
|
86
|
+
if ("rotation" in this.props && this.props.rotation !== prevProps.rotation) {
|
|
87
|
+
this.onWindowResize();
|
|
143
88
|
}
|
|
144
|
-
}
|
|
145
|
-
// When the incoming rotation angle of the image changes, it needs to be resized to make the image fit on the page
|
|
146
|
-
if ("rotation" in this.props && this.props.rotation !== prevProps.rotation) {
|
|
147
|
-
this.onWindowResize();
|
|
148
89
|
}
|
|
149
90
|
}
|
|
150
91
|
render() {
|
|
@@ -166,21 +107,20 @@ export default class PreviewImage extends BaseComponent {
|
|
|
166
107
|
transform: `rotate(${-rotation}deg)`,
|
|
167
108
|
top,
|
|
168
109
|
left,
|
|
169
|
-
width
|
|
170
|
-
height
|
|
110
|
+
width,
|
|
111
|
+
height
|
|
171
112
|
};
|
|
172
113
|
return /*#__PURE__*/React.createElement("div", {
|
|
173
114
|
className: `${preViewImgPrefixCls}`,
|
|
174
115
|
ref: this.containerRef
|
|
175
116
|
}, /*#__PURE__*/React.createElement("img", {
|
|
176
|
-
ref: this.
|
|
117
|
+
ref: this.imageRef,
|
|
177
118
|
src: src,
|
|
178
119
|
alt: "previewImag",
|
|
179
120
|
className: `${preViewImgPrefixCls}-img`,
|
|
180
121
|
key: src,
|
|
181
122
|
onMouseMove: this.handleMoveImage,
|
|
182
123
|
onMouseDown: this.onImageMouseDown,
|
|
183
|
-
onMouseUp: this.onImageMouseUp,
|
|
184
124
|
onContextMenu: this.handleRightClickImage,
|
|
185
125
|
onDragStart: e => e.preventDefault(),
|
|
186
126
|
onLoad: this.handleLoad,
|
|
@@ -197,9 +137,9 @@ PreviewImage.propTypes = {
|
|
|
197
137
|
src: PropTypes.string,
|
|
198
138
|
rotation: PropTypes.number,
|
|
199
139
|
style: PropTypes.object,
|
|
200
|
-
maxZoom: PropTypes.number,
|
|
201
|
-
minZoom: PropTypes.number,
|
|
202
|
-
zoomStep: PropTypes.number,
|
|
140
|
+
// maxZoom: PropTypes.number,
|
|
141
|
+
// minZoom: PropTypes.number,
|
|
142
|
+
// zoomStep: PropTypes.number,
|
|
203
143
|
zoom: PropTypes.number,
|
|
204
144
|
ratio: PropTypes.string,
|
|
205
145
|
disableDownload: PropTypes.bool,
|
|
@@ -210,8 +150,8 @@ PreviewImage.propTypes = {
|
|
|
210
150
|
onError: PropTypes.func
|
|
211
151
|
};
|
|
212
152
|
PreviewImage.defaultProps = {
|
|
213
|
-
maxZoom: 5,
|
|
214
|
-
minZoom: 0.1,
|
|
215
|
-
zoomStep: 0.1,
|
|
153
|
+
// maxZoom: 5,
|
|
154
|
+
// minZoom: 0.1,
|
|
155
|
+
// zoomStep: 0.1,
|
|
216
156
|
zoom: undefined
|
|
217
157
|
};
|
|
@@ -33,6 +33,8 @@ export default class PreviewInner extends BaseComponent<PreviewInnerProps, Previ
|
|
|
33
33
|
disableDownload: PropTypes.Requireable<boolean>;
|
|
34
34
|
viewerVisibleDelay: PropTypes.Requireable<number>;
|
|
35
35
|
zIndex: PropTypes.Requireable<number>;
|
|
36
|
+
maxZoom: PropTypes.Requireable<number>;
|
|
37
|
+
minZoom: PropTypes.Requireable<number>;
|
|
36
38
|
renderHeader: PropTypes.Requireable<(...args: any[]) => any>;
|
|
37
39
|
renderPreviewMenu: PropTypes.Requireable<(...args: any[]) => any>;
|
|
38
40
|
getPopupContainer: PropTypes.Requireable<(...args: any[]) => any>;
|
|
@@ -58,14 +60,20 @@ export default class PreviewInner extends BaseComponent<PreviewInnerProps, Previ
|
|
|
58
60
|
zIndex: number;
|
|
59
61
|
maskClosable: boolean;
|
|
60
62
|
viewerVisibleDelay: number;
|
|
63
|
+
maxZoom: number;
|
|
64
|
+
minZoom: number;
|
|
61
65
|
};
|
|
62
66
|
private bodyOverflow;
|
|
63
67
|
private scrollBarWidth;
|
|
64
68
|
private originBodyWidth;
|
|
65
69
|
get adapter(): PreviewInnerAdapter<PreviewInnerProps, PreviewInnerStates>;
|
|
66
|
-
timer: any;
|
|
67
70
|
context: PreviewContextProps;
|
|
68
71
|
foundation: PreviewInnerFoundation;
|
|
72
|
+
imageWrapRef: React.RefObject<HTMLDivElement>;
|
|
73
|
+
headerRef: React.RefObject<HTMLElement>;
|
|
74
|
+
footerRef: React.RefObject<HTMLElement>;
|
|
75
|
+
leftIconRef: React.RefObject<HTMLDivElement>;
|
|
76
|
+
rightIconRef: React.RefObject<HTMLDivElement>;
|
|
69
77
|
constructor(props: PreviewInnerProps);
|
|
70
78
|
static getDerivedStateFromProps(props: PreviewInnerProps, state: PreviewInnerStates): Partial<PreviewInnerStates>;
|
|
71
79
|
componentDidMount(): void;
|
|
@@ -81,10 +89,11 @@ export default class PreviewInner extends BaseComponent<PreviewInnerProps, Previ
|
|
|
81
89
|
handleZoomImage: (newZoom: number) => void;
|
|
82
90
|
handleMouseUp: (e: any) => void;
|
|
83
91
|
handleMouseMove: (e: any) => void;
|
|
84
|
-
handleMouseEvent: (e: any, event: string) => void;
|
|
85
92
|
handleKeyDown: (e: KeyboardEvent) => void;
|
|
86
93
|
onImageError: () => void;
|
|
87
94
|
onImageLoad: (src: any) => void;
|
|
88
95
|
handleMouseDown: (e: any) => void;
|
|
96
|
+
handleWheel: (e: any) => void;
|
|
97
|
+
registryImageWrapRef: (ref: any) => void;
|
|
89
98
|
render(): JSX.Element;
|
|
90
99
|
}
|
|
@@ -14,14 +14,6 @@ import PreviewInnerFoundation from '@douyinfe/semi-foundation/lib/es/image/previ
|
|
|
14
14
|
import { PreviewContext } from "./previewContext";
|
|
15
15
|
import { getScrollbarWidth } from "../_utils";
|
|
16
16
|
const prefixCls = cssClasses.PREFIX;
|
|
17
|
-
let startMouseDown = {
|
|
18
|
-
x: 0,
|
|
19
|
-
y: 0
|
|
20
|
-
};
|
|
21
|
-
let mouseActiveTime = null;
|
|
22
|
-
let stopTiming = false;
|
|
23
|
-
let timer = null;
|
|
24
|
-
// let bodyOverflowValue = document.body.style.overflow;
|
|
25
17
|
export default class PreviewInner extends BaseComponent {
|
|
26
18
|
get adapter() {
|
|
27
19
|
return Object.assign(Object.assign({}, super.adapter), {
|
|
@@ -105,30 +97,22 @@ export default class PreviewInner extends BaseComponent {
|
|
|
105
97
|
unregisterKeyDownListener: () => {
|
|
106
98
|
window && window.removeEventListener("keydown", this.handleKeyDown);
|
|
107
99
|
},
|
|
108
|
-
getMouseActiveTime: () => {
|
|
109
|
-
return mouseActiveTime;
|
|
110
|
-
},
|
|
111
|
-
getStopTiming: () => {
|
|
112
|
-
return stopTiming;
|
|
113
|
-
},
|
|
114
|
-
setStopTiming: value => {
|
|
115
|
-
stopTiming = value;
|
|
116
|
-
},
|
|
117
|
-
getStartMouseDown: () => {
|
|
118
|
-
return startMouseDown;
|
|
119
|
-
},
|
|
120
|
-
setStartMouseDown: (x, y) => {
|
|
121
|
-
startMouseDown = {
|
|
122
|
-
x,
|
|
123
|
-
y
|
|
124
|
-
};
|
|
125
|
-
},
|
|
126
|
-
setMouseActiveTime: time => {
|
|
127
|
-
mouseActiveTime = time;
|
|
128
|
-
},
|
|
129
100
|
getSetDownloadFunc: () => {
|
|
130
101
|
var _a, _b;
|
|
131
102
|
return (_b = (_a = this.context) === null || _a === void 0 ? void 0 : _a.setDownloadName) !== null && _b !== void 0 ? _b : this.props.setDownloadName;
|
|
103
|
+
},
|
|
104
|
+
isValidTarget: e => {
|
|
105
|
+
const headerDom = this.headerRef && this.headerRef.current;
|
|
106
|
+
const footerDom = this.footerRef && this.footerRef.current;
|
|
107
|
+
const leftIconDom = this.leftIconRef && this.leftIconRef.current;
|
|
108
|
+
const rightIconDom = this.rightIconRef && this.rightIconRef.current;
|
|
109
|
+
const target = e.target;
|
|
110
|
+
if (headerDom && headerDom.contains(target) || footerDom && footerDom.contains(target) || leftIconDom && leftIconDom.contains(target) || rightIconDom && rightIconDom.contains(target)) {
|
|
111
|
+
// Move in the operation area, return false
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
// Move in the preview area except the operation area, return true
|
|
115
|
+
return true;
|
|
132
116
|
}
|
|
133
117
|
});
|
|
134
118
|
}
|
|
@@ -161,9 +145,6 @@ export default class PreviewInner extends BaseComponent {
|
|
|
161
145
|
this.handleMouseMove = e => {
|
|
162
146
|
this.foundation.handleMouseMove(e);
|
|
163
147
|
};
|
|
164
|
-
this.handleMouseEvent = (e, event) => {
|
|
165
|
-
this.foundation.handleMouseMoveEvent(e, event);
|
|
166
|
-
};
|
|
167
148
|
this.handleKeyDown = e => {
|
|
168
149
|
this.foundation.handleKeyDown(e);
|
|
169
150
|
};
|
|
@@ -176,6 +157,31 @@ export default class PreviewInner extends BaseComponent {
|
|
|
176
157
|
this.handleMouseDown = e => {
|
|
177
158
|
this.foundation.handleMouseDown(e);
|
|
178
159
|
};
|
|
160
|
+
this.handleWheel = e => {
|
|
161
|
+
this.foundation.handleWheel(e);
|
|
162
|
+
};
|
|
163
|
+
// 为什么通过 addEventListener 注册 wheel 事件而不是使用 onWheel 事件?
|
|
164
|
+
// 因为 Passive Event Listeners(https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#improving_scrolling_performance_with_passive_listeners)
|
|
165
|
+
// Passive Event Listeners 是一种优化技术,用于提高滚动性能。在默认情况下,浏览器会假设事件的监听器不会调用
|
|
166
|
+
// preventDefault() 方法来阻止事件的默认行为,从而允许进行一些优化操作,例如滚动平滑。
|
|
167
|
+
// 对于 Image 而言,如果使用触控板,双指朝不同方向分开放大图片,则需要 preventDefault 防止页面整体放大。
|
|
168
|
+
// Why register wheel event through addEventListener instead of using onWheel event?
|
|
169
|
+
// Because of Passive Event Listeners(an optimization technique used to improve scrolling performance. By default,
|
|
170
|
+
// the browser will assume that event listeners will not call preventDefault() method to prevent the default behavior of the event,
|
|
171
|
+
// allowing some optimization operations such as scroll smoothing.)
|
|
172
|
+
// For Image, if we use the trackpad and spread your fingers in different directions to enlarge the image, we need to preventDefault
|
|
173
|
+
// to prevent the page from being enlarged as a whole.
|
|
174
|
+
this.registryImageWrapRef = ref => {
|
|
175
|
+
if (this.imageWrapRef) {
|
|
176
|
+
this.imageWrapRef.removeEventListener("wheel", this.handleWheel);
|
|
177
|
+
}
|
|
178
|
+
if (ref) {
|
|
179
|
+
ref.addEventListener("wheel", this.handleWheel, {
|
|
180
|
+
passive: false
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
this.imageWrapRef = ref;
|
|
184
|
+
};
|
|
179
185
|
this.state = {
|
|
180
186
|
imgSrc: [],
|
|
181
187
|
imgLoadStatus: new Map(),
|
|
@@ -192,6 +198,11 @@ export default class PreviewInner extends BaseComponent {
|
|
|
192
198
|
this.bodyOverflow = '';
|
|
193
199
|
this.originBodyWidth = '100%';
|
|
194
200
|
this.scrollBarWidth = 0;
|
|
201
|
+
this.imageWrapRef = null;
|
|
202
|
+
this.headerRef = /*#__PURE__*/React.createRef();
|
|
203
|
+
this.footerRef = /*#__PURE__*/React.createRef();
|
|
204
|
+
this.leftIconRef = /*#__PURE__*/React.createRef();
|
|
205
|
+
this.rightIconRef = /*#__PURE__*/React.createRef();
|
|
195
206
|
}
|
|
196
207
|
static getDerivedStateFromProps(props, state) {
|
|
197
208
|
const willUpdateStates = {};
|
|
@@ -207,6 +218,9 @@ export default class PreviewInner extends BaseComponent {
|
|
|
207
218
|
willUpdateStates.visible = props.visible;
|
|
208
219
|
if (props.visible) {
|
|
209
220
|
willUpdateStates.preloadAfterVisibleChange = true;
|
|
221
|
+
willUpdateStates.viewerVisible = true;
|
|
222
|
+
willUpdateStates.rotation = 0;
|
|
223
|
+
willUpdateStates.ratio = 'adaptation';
|
|
210
224
|
}
|
|
211
225
|
}
|
|
212
226
|
if ("currentIndex" in props && props.currentIndex !== state.currentIndex) {
|
|
@@ -225,10 +239,8 @@ export default class PreviewInner extends BaseComponent {
|
|
|
225
239
|
}
|
|
226
240
|
}
|
|
227
241
|
componentDidUpdate(prevProps, prevState) {
|
|
228
|
-
if (
|
|
229
|
-
|
|
230
|
-
timer && clearInterval(timer);
|
|
231
|
-
timer = setInterval(this.viewVisibleChange, 1000);
|
|
242
|
+
if (prevProps.src !== this.props.src) {
|
|
243
|
+
this.foundation.updateTimer();
|
|
232
244
|
}
|
|
233
245
|
// hide => show
|
|
234
246
|
if (!prevProps.visible && this.props.visible) {
|
|
@@ -240,7 +252,7 @@ export default class PreviewInner extends BaseComponent {
|
|
|
240
252
|
}
|
|
241
253
|
}
|
|
242
254
|
componentWillUnmount() {
|
|
243
|
-
|
|
255
|
+
this.foundation.clearTimer();
|
|
244
256
|
}
|
|
245
257
|
isInGroup() {
|
|
246
258
|
return Boolean(this.context && this.context.isGroup);
|
|
@@ -305,10 +317,10 @@ export default class PreviewInner extends BaseComponent {
|
|
|
305
317
|
style: style,
|
|
306
318
|
onMouseDown: this.handleMouseDown,
|
|
307
319
|
onMouseUp: this.handleMouseUp,
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
onMouseOut: e => this.handleMouseEvent(e.nativeEvent, "out")
|
|
320
|
+
ref: this.registryImageWrapRef,
|
|
321
|
+
onMouseMove: this.handleMouseMove
|
|
311
322
|
}, /*#__PURE__*/React.createElement(Header, {
|
|
323
|
+
ref: this.headerRef,
|
|
312
324
|
className: cls(hideViewerCls),
|
|
313
325
|
onClose: this.handlePreviewClose,
|
|
314
326
|
renderHeader: renderHeader
|
|
@@ -319,7 +331,6 @@ export default class PreviewInner extends BaseComponent {
|
|
|
319
331
|
setRatio: this.handleAdjustRatio,
|
|
320
332
|
zoom: zoom,
|
|
321
333
|
ratio: ratio,
|
|
322
|
-
zoomStep: zoomStep,
|
|
323
334
|
rotation: rotation,
|
|
324
335
|
crossOrigin: crossOrigin,
|
|
325
336
|
onError: this.onImageError,
|
|
@@ -328,6 +339,7 @@ export default class PreviewInner extends BaseComponent {
|
|
|
328
339
|
/*#__PURE__*/
|
|
329
340
|
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
|
|
330
341
|
React.createElement("div", {
|
|
342
|
+
ref: this.leftIconRef,
|
|
331
343
|
className: cls(`${previewPrefixCls}-icon`, `${previewPrefixCls}-prev`, hideViewerCls),
|
|
332
344
|
onClick: () => this.handleSwitchImage("prev")
|
|
333
345
|
}, /*#__PURE__*/React.createElement(IconArrowLeft, {
|
|
@@ -336,11 +348,13 @@ export default class PreviewInner extends BaseComponent {
|
|
|
336
348
|
/*#__PURE__*/
|
|
337
349
|
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
|
|
338
350
|
React.createElement("div", {
|
|
351
|
+
ref: this.rightIconRef,
|
|
339
352
|
className: cls(`${previewPrefixCls}-icon`, `${previewPrefixCls}-next`, hideViewerCls),
|
|
340
353
|
onClick: () => this.handleSwitchImage("next")
|
|
341
354
|
}, /*#__PURE__*/React.createElement(IconArrowRight, {
|
|
342
355
|
size: "large"
|
|
343
356
|
})), /*#__PURE__*/React.createElement(Footer, {
|
|
357
|
+
forwardRef: this.footerRef,
|
|
344
358
|
className: hideViewerCls,
|
|
345
359
|
totalNum: total,
|
|
346
360
|
curPage: currentIndex + 1,
|
|
@@ -398,6 +412,8 @@ PreviewInner.propTypes = {
|
|
|
398
412
|
disableDownload: PropTypes.bool,
|
|
399
413
|
viewerVisibleDelay: PropTypes.number,
|
|
400
414
|
zIndex: PropTypes.number,
|
|
415
|
+
maxZoom: PropTypes.number,
|
|
416
|
+
minZoom: PropTypes.number,
|
|
401
417
|
renderHeader: PropTypes.func,
|
|
402
418
|
renderPreviewMenu: PropTypes.func,
|
|
403
419
|
getPopupContainer: PropTypes.func,
|
|
@@ -422,5 +438,7 @@ PreviewInner.defaultProps = {
|
|
|
422
438
|
preLoadGap: 2,
|
|
423
439
|
zIndex: 1000,
|
|
424
440
|
maskClosable: true,
|
|
425
|
-
viewerVisibleDelay: 10000
|
|
441
|
+
viewerVisibleDelay: 10000,
|
|
442
|
+
maxZoom: 5,
|
|
443
|
+
minZoom: 0.1
|
|
426
444
|
};
|
package/lib/es/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import './_base/base.css';
|
|
2
|
+
export { default as BaseFoundation } from '@douyinfe/semi-foundation/lib/es/base/foundation';
|
|
3
|
+
export { default as BaseComponent } from "./_base/baseComponent";
|
|
2
4
|
export { default as Anchor } from './anchor';
|
|
3
5
|
export { default as AutoComplete } from './autoComplete';
|
|
4
6
|
export { default as Avatar } from './avatar';
|
package/lib/es/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import './_base/base.css';
|
|
2
|
+
export { default as BaseFoundation } from '@douyinfe/semi-foundation/lib/es/base/foundation';
|
|
3
|
+
export { default as BaseComponent } from "./_base/baseComponent";
|
|
2
4
|
export { default as Anchor } from './anchor';
|
|
3
5
|
export { default as AutoComplete } from './autoComplete';
|
|
4
6
|
export { default as Avatar } from './avatar';
|
|
@@ -157,13 +157,13 @@ export declare function withError(props: ModalReactProps): {
|
|
|
157
157
|
height?: string | number;
|
|
158
158
|
content?: React.ReactNode;
|
|
159
159
|
icon: string | number | boolean | React.ReactFragment | JSX.Element;
|
|
160
|
-
onCancel?: (e: React.MouseEvent<Element, MouseEvent>) => void | Promise<any>;
|
|
161
160
|
closeOnEsc?: boolean;
|
|
162
161
|
preventScroll?: boolean;
|
|
163
162
|
afterClose?: () => void;
|
|
164
163
|
keepDOM?: boolean;
|
|
165
164
|
cancelText?: string;
|
|
166
165
|
okText?: string;
|
|
166
|
+
onCancel?: (e: React.MouseEvent<Element, MouseEvent>) => void | Promise<any>;
|
|
167
167
|
closeIcon?: React.ReactNode;
|
|
168
168
|
bodyStyle?: React.CSSProperties;
|
|
169
169
|
closable?: boolean;
|
|
@@ -377,11 +377,6 @@ export declare function withError(props: ModalReactProps): {
|
|
|
377
377
|
accessKey?: string;
|
|
378
378
|
autoFocus?: boolean;
|
|
379
379
|
content?: string;
|
|
380
|
-
formAction?: string;
|
|
381
|
-
formEncType?: string;
|
|
382
|
-
formMethod?: string;
|
|
383
|
-
formNoValidate?: boolean;
|
|
384
|
-
formTarget?: string;
|
|
385
380
|
contextMenu?: string;
|
|
386
381
|
dir?: string;
|
|
387
382
|
draggable?: boolean | "true" | "false";
|
|
@@ -463,6 +458,11 @@ export declare function withError(props: ModalReactProps): {
|
|
|
463
458
|
'aria-valuemin'?: number;
|
|
464
459
|
'aria-valuenow'?: number;
|
|
465
460
|
'aria-valuetext'?: string;
|
|
461
|
+
formAction?: string;
|
|
462
|
+
formEncType?: string;
|
|
463
|
+
formMethod?: string;
|
|
464
|
+
formNoValidate?: boolean;
|
|
465
|
+
formTarget?: string;
|
|
466
466
|
};
|
|
467
467
|
};
|
|
468
468
|
export declare function withConfirm(props: ModalReactProps): {
|