@douyinfe/semi-ui 2.49.0 → 2.50.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/css/semi.css +1 -1
- package/dist/css/semi.min.css +1 -1
- package/dist/umd/semi-ui.js +276 -263
- 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/anchor/index.d.ts +1 -1
- package/lib/cjs/autoComplete/index.d.ts +1 -1
- package/lib/cjs/button/Button.d.ts +1 -1
- package/lib/cjs/button/index.d.ts +1 -1
- package/lib/cjs/carousel/index.d.ts +1 -1
- package/lib/cjs/datePicker/datePicker.d.ts +1 -1
- package/lib/cjs/dropdown/index.d.ts +1 -1
- package/lib/cjs/form/baseForm.d.ts +1 -1
- package/lib/cjs/form/field.d.ts +1 -1
- package/lib/cjs/image/interface.d.ts +3 -3
- package/lib/cjs/image/previewFooter.js +8 -5
- package/lib/cjs/image/previewHeader.d.ts +2 -2
- package/lib/cjs/image/previewHeader.js +8 -9
- package/lib/cjs/image/previewImage.d.ts +12 -1
- package/lib/cjs/image/previewImage.js +83 -23
- package/lib/cjs/image/previewInner.d.ts +2 -11
- package/lib/cjs/image/previewInner.js +42 -60
- package/lib/cjs/modal/confirm.d.ts +17 -17
- package/lib/cjs/popover/index.d.ts +1 -1
- package/lib/cjs/select/index.d.ts +1 -1
- package/lib/cjs/table/ColumnSorter.d.ts +3 -1
- package/lib/cjs/table/ColumnSorter.js +26 -15
- package/lib/cjs/table/Table.d.ts +1 -1
- package/lib/cjs/table/Table.js +1 -0
- package/lib/cjs/table/interface.d.ts +4 -0
- package/lib/cjs/timePicker/TimePicker.d.ts +2 -2
- package/lib/cjs/timePicker/TimeShape.d.ts +1 -1
- package/lib/cjs/timePicker/index.d.ts +2 -2
- package/lib/cjs/tooltip/index.d.ts +1 -1
- package/lib/cjs/typography/base.d.ts +1 -1
- package/lib/cjs/typography/numeral.d.ts +1 -1
- package/lib/cjs/typography/paragraph.d.ts +1 -1
- package/lib/cjs/typography/text.d.ts +1 -1
- package/lib/cjs/typography/title.d.ts +1 -1
- package/lib/es/anchor/index.d.ts +1 -1
- package/lib/es/autoComplete/index.d.ts +1 -1
- package/lib/es/button/Button.d.ts +1 -1
- package/lib/es/button/index.d.ts +1 -1
- package/lib/es/carousel/index.d.ts +1 -1
- package/lib/es/datePicker/datePicker.d.ts +1 -1
- package/lib/es/dropdown/index.d.ts +1 -1
- package/lib/es/form/baseForm.d.ts +1 -1
- package/lib/es/form/field.d.ts +1 -1
- package/lib/es/image/interface.d.ts +3 -3
- package/lib/es/image/previewFooter.js +8 -5
- package/lib/es/image/previewHeader.d.ts +2 -2
- package/lib/es/image/previewHeader.js +3 -4
- package/lib/es/image/previewImage.d.ts +12 -1
- package/lib/es/image/previewImage.js +83 -23
- package/lib/es/image/previewInner.d.ts +2 -11
- package/lib/es/image/previewInner.js +42 -60
- package/lib/es/modal/confirm.d.ts +17 -17
- package/lib/es/popover/index.d.ts +1 -1
- package/lib/es/select/index.d.ts +1 -1
- package/lib/es/table/ColumnSorter.d.ts +3 -1
- package/lib/es/table/ColumnSorter.js +26 -15
- package/lib/es/table/Table.d.ts +1 -1
- package/lib/es/table/Table.js +1 -0
- package/lib/es/table/interface.d.ts +4 -0
- package/lib/es/timePicker/TimePicker.d.ts +2 -2
- package/lib/es/timePicker/TimeShape.d.ts +1 -1
- package/lib/es/timePicker/index.d.ts +2 -2
- package/lib/es/tooltip/index.d.ts +1 -1
- package/lib/es/typography/base.d.ts +1 -1
- package/lib/es/typography/numeral.d.ts +1 -1
- package/lib/es/typography/paragraph.d.ts +1 -1
- package/lib/es/typography/text.d.ts +1 -1
- package/lib/es/typography/title.d.ts +1 -1
- package/package.json +8 -8
|
@@ -85,7 +85,7 @@ declare class Form<Values extends Record<string, any> = any> extends BaseCompone
|
|
|
85
85
|
expandRestTagsOnClick?: boolean;
|
|
86
86
|
onDropdownVisibleChange?: (visible: boolean) => void;
|
|
87
87
|
zIndex?: number;
|
|
88
|
-
position?: "left" | "right" | "top" | "
|
|
88
|
+
position?: "left" | "right" | "top" | "topLeft" | "topRight" | "leftTop" | "leftBottom" | "rightTop" | "rightBottom" | "bottom" | "bottomLeft" | "bottomRight" | "leftTopOver" | "rightTopOver" | "leftBottomOver" | "rightBottomOver";
|
|
89
89
|
onSearch?: (value: string, event: React.KeyboardEvent<Element> | React.MouseEvent<Element, MouseEvent>) => void;
|
|
90
90
|
dropdownClassName?: string;
|
|
91
91
|
dropdownStyle?: React.CSSProperties;
|
package/lib/es/form/field.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ declare const FormSelect: import("react").ComponentType<import("utility-types").
|
|
|
31
31
|
expandRestTagsOnClick?: boolean;
|
|
32
32
|
onDropdownVisibleChange?: (visible: boolean) => void;
|
|
33
33
|
zIndex?: number;
|
|
34
|
-
position?: "left" | "right" | "top" | "
|
|
34
|
+
position?: "left" | "right" | "top" | "topLeft" | "topRight" | "leftTop" | "leftBottom" | "rightTop" | "rightBottom" | "bottom" | "bottomLeft" | "bottomRight" | "leftTopOver" | "rightTopOver" | "leftBottomOver" | "rightBottomOver";
|
|
35
35
|
onSearch?: (value: string, event: import("react").KeyboardEvent<Element> | import("react").MouseEvent<Element, MouseEvent>) => void;
|
|
36
36
|
dropdownClassName?: string;
|
|
37
37
|
dropdownStyle?: import("react").CSSProperties;
|
|
@@ -53,8 +53,6 @@ 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;
|
|
58
56
|
renderHeader?: (info: any) => ReactNode;
|
|
59
57
|
renderPreviewMenu?: (props: MenuProps) => ReactNode;
|
|
60
58
|
getPopupContainer?: () => HTMLElement;
|
|
@@ -140,12 +138,14 @@ export interface FooterProps extends SliderProps {
|
|
|
140
138
|
onRotate?: (direction: string) => void;
|
|
141
139
|
onDownload?: () => void;
|
|
142
140
|
renderPreviewMenu?: (props: MenuProps) => ReactNode;
|
|
143
|
-
forwardRef?: React.RefObject<HTMLElement>;
|
|
144
141
|
}
|
|
145
142
|
export interface PreviewImageProps {
|
|
146
143
|
src?: string;
|
|
147
144
|
rotation?: number;
|
|
148
145
|
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,9 +12,14 @@ 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;
|
|
15
16
|
export default class Footer extends BaseComponent {
|
|
16
17
|
get adapter() {
|
|
17
|
-
return Object.assign({}, super.adapter)
|
|
18
|
+
return Object.assign(Object.assign({}, super.adapter), {
|
|
19
|
+
setStartMouseOffset: time => {
|
|
20
|
+
mouseActiveTime = time;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
18
23
|
}
|
|
19
24
|
constructor(props) {
|
|
20
25
|
super(props);
|
|
@@ -254,15 +259,13 @@ export default class Footer extends BaseComponent {
|
|
|
254
259
|
render() {
|
|
255
260
|
const {
|
|
256
261
|
className,
|
|
257
|
-
renderPreviewMenu
|
|
258
|
-
forwardRef
|
|
262
|
+
renderPreviewMenu
|
|
259
263
|
} = this.props;
|
|
260
264
|
const menuCls = cls(footerPrefixCls, `${footerPrefixCls}-wrapper`, className, {
|
|
261
265
|
[`${footerPrefixCls}-content`]: !Boolean(renderPreviewMenu)
|
|
262
266
|
});
|
|
263
267
|
return /*#__PURE__*/React.createElement("section", {
|
|
264
|
-
className: menuCls
|
|
265
|
-
ref: forwardRef
|
|
268
|
+
className: menuCls
|
|
266
269
|
}, renderPreviewMenu ? this.customRenderViewMenu() : this.getFooterMenu());
|
|
267
270
|
}
|
|
268
271
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import * as React from "react";
|
|
2
2
|
import { HeaderProps } from "./interface";
|
|
3
|
-
declare const Header: React.
|
|
3
|
+
declare const Header: React.FC<HeaderProps>;
|
|
4
4
|
export default Header;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as React 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 =
|
|
7
|
+
const Header = _ref => {
|
|
8
8
|
let {
|
|
9
9
|
onClose,
|
|
10
10
|
titleStyle,
|
|
@@ -21,7 +21,6 @@ const Header = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
21
21
|
title = titles[currentIndex];
|
|
22
22
|
}
|
|
23
23
|
return /*#__PURE__*/React.createElement("section", {
|
|
24
|
-
ref: ref,
|
|
25
24
|
className: cls(prefixCls, className)
|
|
26
25
|
}, /*#__PURE__*/React.createElement("section", {
|
|
27
26
|
className: `${prefixCls}-title`,
|
|
@@ -31,5 +30,5 @@ const Header = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
31
30
|
onMouseUp: onClose
|
|
32
31
|
}, /*#__PURE__*/React.createElement(IconClose, null)));
|
|
33
32
|
});
|
|
34
|
-
}
|
|
33
|
+
};
|
|
35
34
|
export default Header;
|
|
@@ -8,6 +8,9 @@ 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>;
|
|
11
14
|
zoom: PropTypes.Requireable<number>;
|
|
12
15
|
ratio: PropTypes.Requireable<string>;
|
|
13
16
|
disableDownload: PropTypes.Requireable<boolean>;
|
|
@@ -18,21 +21,29 @@ export default class PreviewImage extends BaseComponent<PreviewImageProps, Previ
|
|
|
18
21
|
onError: PropTypes.Requireable<(...args: any[]) => any>;
|
|
19
22
|
};
|
|
20
23
|
static defaultProps: {
|
|
24
|
+
maxZoom: number;
|
|
25
|
+
minZoom: number;
|
|
26
|
+
zoomStep: number;
|
|
21
27
|
zoom: any;
|
|
22
28
|
};
|
|
23
29
|
get adapter(): PreviewImageAdapter<PreviewImageProps, PreviewImageStates>;
|
|
24
30
|
containerRef: React.RefObject<HTMLDivElement>;
|
|
25
|
-
imageRef:
|
|
31
|
+
imageRef: HTMLImageElement | null;
|
|
26
32
|
foundation: PreviewImageFoundation;
|
|
27
33
|
constructor(props: any);
|
|
28
34
|
componentDidMount(): void;
|
|
29
35
|
componentWillUnmount(): void;
|
|
30
36
|
componentDidUpdate(prevProps: PreviewImageProps, prevStates: PreviewImageStates): void;
|
|
31
37
|
onWindowResize: () => void;
|
|
38
|
+
handleZoomChange: (newZoom: any, e: any) => void;
|
|
32
39
|
handleRightClickImage: (e: any) => void;
|
|
40
|
+
handleWheel: (e: any) => void;
|
|
33
41
|
handleLoad: (e: any) => void;
|
|
34
42
|
handleError: (e: any) => void;
|
|
43
|
+
resizeImage: () => void;
|
|
35
44
|
handleMoveImage: (e: any) => void;
|
|
45
|
+
registryImageRef: (ref: any) => void;
|
|
36
46
|
onImageMouseDown: (e: React.MouseEvent<HTMLImageElement>) => void;
|
|
47
|
+
onImageMouseUp: () => void;
|
|
37
48
|
render(): JSX.Element;
|
|
38
49
|
}
|
|
@@ -6,14 +6,38 @@ 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
|
+
};
|
|
9
17
|
export default class PreviewImage extends BaseComponent {
|
|
10
18
|
get adapter() {
|
|
11
19
|
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
|
+
},
|
|
12
28
|
getContainer: () => {
|
|
13
29
|
return this.containerRef.current;
|
|
14
30
|
},
|
|
15
31
|
getImage: () => {
|
|
16
|
-
return this.imageRef
|
|
32
|
+
return this.imageRef;
|
|
33
|
+
},
|
|
34
|
+
getMouseMove: () => startMouseMove,
|
|
35
|
+
setStartMouseMove: move => {
|
|
36
|
+
startMouseMove = move;
|
|
37
|
+
},
|
|
38
|
+
getMouseOffset: () => startMouseOffset,
|
|
39
|
+
setStartMouseOffset: offset => {
|
|
40
|
+
startMouseOffset = offset;
|
|
17
41
|
},
|
|
18
42
|
setLoading: loading => {
|
|
19
43
|
this.setState({
|
|
@@ -21,7 +45,7 @@ export default class PreviewImage extends BaseComponent {
|
|
|
21
45
|
});
|
|
22
46
|
},
|
|
23
47
|
setImageCursor: canDrag => {
|
|
24
|
-
this.imageRef.
|
|
48
|
+
this.imageRef.style.cursor = canDrag ? "grab" : "default";
|
|
25
49
|
}
|
|
26
50
|
});
|
|
27
51
|
}
|
|
@@ -30,22 +54,52 @@ export default class PreviewImage extends BaseComponent {
|
|
|
30
54
|
this.onWindowResize = () => {
|
|
31
55
|
this.foundation.handleWindowResize();
|
|
32
56
|
};
|
|
57
|
+
this.handleZoomChange = (newZoom, e) => {
|
|
58
|
+
this.foundation.handleZoomChange(newZoom, e);
|
|
59
|
+
};
|
|
33
60
|
// Determine the response method of right click according to the disableDownload parameter in props
|
|
34
61
|
this.handleRightClickImage = e => {
|
|
35
62
|
this.foundation.handleRightClickImage(e);
|
|
36
63
|
};
|
|
64
|
+
this.handleWheel = e => {
|
|
65
|
+
this.foundation.handleWheel(e);
|
|
66
|
+
};
|
|
37
67
|
this.handleLoad = e => {
|
|
38
68
|
this.foundation.handleLoad(e);
|
|
39
69
|
};
|
|
40
70
|
this.handleError = e => {
|
|
41
71
|
this.foundation.handleError(e);
|
|
42
72
|
};
|
|
73
|
+
this.resizeImage = () => {
|
|
74
|
+
this.foundation.handleResizeImage();
|
|
75
|
+
};
|
|
43
76
|
this.handleMoveImage = e => {
|
|
44
77
|
this.foundation.handleMoveImage(e);
|
|
45
78
|
};
|
|
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
|
+
};
|
|
46
97
|
this.onImageMouseDown = e => {
|
|
47
98
|
this.foundation.handleImageMouseDown(e);
|
|
48
99
|
};
|
|
100
|
+
this.onImageMouseUp = () => {
|
|
101
|
+
this.foundation.handleImageMouseUp();
|
|
102
|
+
};
|
|
49
103
|
this.state = {
|
|
50
104
|
width: 0,
|
|
51
105
|
height: 0,
|
|
@@ -59,7 +113,7 @@ export default class PreviewImage extends BaseComponent {
|
|
|
59
113
|
left: 0
|
|
60
114
|
};
|
|
61
115
|
this.containerRef = /*#__PURE__*/React.createRef();
|
|
62
|
-
this.imageRef =
|
|
116
|
+
this.imageRef = null;
|
|
63
117
|
this.foundation = new PreviewImageFoundation(this.adapter);
|
|
64
118
|
}
|
|
65
119
|
componentDidMount() {
|
|
@@ -70,23 +124,28 @@ export default class PreviewImage extends BaseComponent {
|
|
|
70
124
|
}
|
|
71
125
|
componentDidUpdate(prevProps, prevStates) {
|
|
72
126
|
// If src changes, start a new loading
|
|
73
|
-
|
|
74
|
-
const srcChange = this.props.src && this.props.src !== prevProps.src;
|
|
75
|
-
if (srcChange) {
|
|
127
|
+
if (this.props.src && this.props.src !== prevProps.src) {
|
|
76
128
|
this.foundation.setLoading(true);
|
|
77
129
|
}
|
|
78
130
|
// If the incoming zoom changes, other content changes are determined based on the new zoom value
|
|
79
|
-
if (
|
|
80
|
-
this.
|
|
131
|
+
if ("zoom" in this.props && this.props.zoom !== prevStates.currZoom) {
|
|
132
|
+
this.handleZoomChange(this.props.zoom, null);
|
|
81
133
|
}
|
|
82
|
-
if
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
134
|
+
// When the incoming ratio is changed, if it"s adaptation, then resizeImage is triggered to make the image adapt to the page
|
|
135
|
+
// else if it"s adaptation is realSize, then onZoom(1) is called to make the image size the original size;
|
|
136
|
+
if ("ratio" in this.props && this.props.ratio !== prevProps.ratio) {
|
|
137
|
+
if (originImageWidth && originImageHeight) {
|
|
138
|
+
if (this.props.ratio === "adaptation") {
|
|
139
|
+
this.resizeImage();
|
|
140
|
+
} else {
|
|
141
|
+
this.props.onZoom(1);
|
|
142
|
+
}
|
|
88
143
|
}
|
|
89
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
|
+
}
|
|
90
149
|
}
|
|
91
150
|
render() {
|
|
92
151
|
const {
|
|
@@ -107,20 +166,21 @@ export default class PreviewImage extends BaseComponent {
|
|
|
107
166
|
transform: `rotate(${-rotation}deg)`,
|
|
108
167
|
top,
|
|
109
168
|
left,
|
|
110
|
-
width
|
|
111
|
-
height
|
|
169
|
+
width: loading ? "auto" : `${width}px`,
|
|
170
|
+
height: loading ? "auto" : `${height}px`
|
|
112
171
|
};
|
|
113
172
|
return /*#__PURE__*/React.createElement("div", {
|
|
114
173
|
className: `${preViewImgPrefixCls}`,
|
|
115
174
|
ref: this.containerRef
|
|
116
175
|
}, /*#__PURE__*/React.createElement("img", {
|
|
117
|
-
ref: this.
|
|
176
|
+
ref: this.registryImageRef,
|
|
118
177
|
src: src,
|
|
119
178
|
alt: "previewImag",
|
|
120
179
|
className: `${preViewImgPrefixCls}-img`,
|
|
121
180
|
key: src,
|
|
122
181
|
onMouseMove: this.handleMoveImage,
|
|
123
182
|
onMouseDown: this.onImageMouseDown,
|
|
183
|
+
onMouseUp: this.onImageMouseUp,
|
|
124
184
|
onContextMenu: this.handleRightClickImage,
|
|
125
185
|
onDragStart: e => e.preventDefault(),
|
|
126
186
|
onLoad: this.handleLoad,
|
|
@@ -137,9 +197,9 @@ PreviewImage.propTypes = {
|
|
|
137
197
|
src: PropTypes.string,
|
|
138
198
|
rotation: PropTypes.number,
|
|
139
199
|
style: PropTypes.object,
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
200
|
+
maxZoom: PropTypes.number,
|
|
201
|
+
minZoom: PropTypes.number,
|
|
202
|
+
zoomStep: PropTypes.number,
|
|
143
203
|
zoom: PropTypes.number,
|
|
144
204
|
ratio: PropTypes.string,
|
|
145
205
|
disableDownload: PropTypes.bool,
|
|
@@ -150,8 +210,8 @@ PreviewImage.propTypes = {
|
|
|
150
210
|
onError: PropTypes.func
|
|
151
211
|
};
|
|
152
212
|
PreviewImage.defaultProps = {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
213
|
+
maxZoom: 5,
|
|
214
|
+
minZoom: 0.1,
|
|
215
|
+
zoomStep: 0.1,
|
|
156
216
|
zoom: undefined
|
|
157
217
|
};
|
|
@@ -33,8 +33,6 @@ 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>;
|
|
38
36
|
renderHeader: PropTypes.Requireable<(...args: any[]) => any>;
|
|
39
37
|
renderPreviewMenu: PropTypes.Requireable<(...args: any[]) => any>;
|
|
40
38
|
getPopupContainer: PropTypes.Requireable<(...args: any[]) => any>;
|
|
@@ -60,20 +58,14 @@ export default class PreviewInner extends BaseComponent<PreviewInnerProps, Previ
|
|
|
60
58
|
zIndex: number;
|
|
61
59
|
maskClosable: boolean;
|
|
62
60
|
viewerVisibleDelay: number;
|
|
63
|
-
maxZoom: number;
|
|
64
|
-
minZoom: number;
|
|
65
61
|
};
|
|
66
62
|
private bodyOverflow;
|
|
67
63
|
private scrollBarWidth;
|
|
68
64
|
private originBodyWidth;
|
|
69
65
|
get adapter(): PreviewInnerAdapter<PreviewInnerProps, PreviewInnerStates>;
|
|
66
|
+
timer: any;
|
|
70
67
|
context: PreviewContextProps;
|
|
71
68
|
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>;
|
|
77
69
|
constructor(props: PreviewInnerProps);
|
|
78
70
|
static getDerivedStateFromProps(props: PreviewInnerProps, state: PreviewInnerStates): Partial<PreviewInnerStates>;
|
|
79
71
|
componentDidMount(): void;
|
|
@@ -89,11 +81,10 @@ export default class PreviewInner extends BaseComponent<PreviewInnerProps, Previ
|
|
|
89
81
|
handleZoomImage: (newZoom: number) => void;
|
|
90
82
|
handleMouseUp: (e: any) => void;
|
|
91
83
|
handleMouseMove: (e: any) => void;
|
|
84
|
+
handleMouseEvent: (e: any, event: string) => void;
|
|
92
85
|
handleKeyDown: (e: KeyboardEvent) => void;
|
|
93
86
|
onImageError: () => void;
|
|
94
87
|
onImageLoad: (src: any) => void;
|
|
95
88
|
handleMouseDown: (e: any) => void;
|
|
96
|
-
handleWheel: (e: any) => void;
|
|
97
|
-
registryImageWrapRef: (ref: any) => void;
|
|
98
89
|
render(): JSX.Element;
|
|
99
90
|
}
|
|
@@ -14,6 +14,14 @@ 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;
|
|
17
25
|
export default class PreviewInner extends BaseComponent {
|
|
18
26
|
get adapter() {
|
|
19
27
|
return Object.assign(Object.assign({}, super.adapter), {
|
|
@@ -97,22 +105,30 @@ export default class PreviewInner extends BaseComponent {
|
|
|
97
105
|
unregisterKeyDownListener: () => {
|
|
98
106
|
window && window.removeEventListener("keydown", this.handleKeyDown);
|
|
99
107
|
},
|
|
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
|
+
},
|
|
100
129
|
getSetDownloadFunc: () => {
|
|
101
130
|
var _a, _b;
|
|
102
131
|
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;
|
|
116
132
|
}
|
|
117
133
|
});
|
|
118
134
|
}
|
|
@@ -145,6 +161,9 @@ export default class PreviewInner extends BaseComponent {
|
|
|
145
161
|
this.handleMouseMove = e => {
|
|
146
162
|
this.foundation.handleMouseMove(e);
|
|
147
163
|
};
|
|
164
|
+
this.handleMouseEvent = (e, event) => {
|
|
165
|
+
this.foundation.handleMouseMoveEvent(e, event);
|
|
166
|
+
};
|
|
148
167
|
this.handleKeyDown = e => {
|
|
149
168
|
this.foundation.handleKeyDown(e);
|
|
150
169
|
};
|
|
@@ -157,31 +176,6 @@ export default class PreviewInner extends BaseComponent {
|
|
|
157
176
|
this.handleMouseDown = e => {
|
|
158
177
|
this.foundation.handleMouseDown(e);
|
|
159
178
|
};
|
|
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
|
-
};
|
|
185
179
|
this.state = {
|
|
186
180
|
imgSrc: [],
|
|
187
181
|
imgLoadStatus: new Map(),
|
|
@@ -198,11 +192,6 @@ export default class PreviewInner extends BaseComponent {
|
|
|
198
192
|
this.bodyOverflow = '';
|
|
199
193
|
this.originBodyWidth = '100%';
|
|
200
194
|
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();
|
|
206
195
|
}
|
|
207
196
|
static getDerivedStateFromProps(props, state) {
|
|
208
197
|
const willUpdateStates = {};
|
|
@@ -218,9 +207,6 @@ export default class PreviewInner extends BaseComponent {
|
|
|
218
207
|
willUpdateStates.visible = props.visible;
|
|
219
208
|
if (props.visible) {
|
|
220
209
|
willUpdateStates.preloadAfterVisibleChange = true;
|
|
221
|
-
willUpdateStates.viewerVisible = true;
|
|
222
|
-
willUpdateStates.rotation = 0;
|
|
223
|
-
willUpdateStates.ratio = 'adaptation';
|
|
224
210
|
}
|
|
225
211
|
}
|
|
226
212
|
if ("currentIndex" in props && props.currentIndex !== state.currentIndex) {
|
|
@@ -239,8 +225,10 @@ export default class PreviewInner extends BaseComponent {
|
|
|
239
225
|
}
|
|
240
226
|
}
|
|
241
227
|
componentDidUpdate(prevProps, prevState) {
|
|
242
|
-
if (
|
|
243
|
-
|
|
228
|
+
if (prevState.visible !== this.props.visible && this.props.visible) {
|
|
229
|
+
mouseActiveTime = new Date().getTime();
|
|
230
|
+
timer && clearInterval(timer);
|
|
231
|
+
timer = setInterval(this.viewVisibleChange, 1000);
|
|
244
232
|
}
|
|
245
233
|
// hide => show
|
|
246
234
|
if (!prevProps.visible && this.props.visible) {
|
|
@@ -252,7 +240,7 @@ export default class PreviewInner extends BaseComponent {
|
|
|
252
240
|
}
|
|
253
241
|
}
|
|
254
242
|
componentWillUnmount() {
|
|
255
|
-
|
|
243
|
+
timer && clearInterval(timer);
|
|
256
244
|
}
|
|
257
245
|
isInGroup() {
|
|
258
246
|
return Boolean(this.context && this.context.isGroup);
|
|
@@ -317,10 +305,10 @@ export default class PreviewInner extends BaseComponent {
|
|
|
317
305
|
style: style,
|
|
318
306
|
onMouseDown: this.handleMouseDown,
|
|
319
307
|
onMouseUp: this.handleMouseUp,
|
|
320
|
-
|
|
321
|
-
|
|
308
|
+
onMouseMove: this.handleMouseMove,
|
|
309
|
+
onMouseOver: e => this.handleMouseEvent(e.nativeEvent, "over"),
|
|
310
|
+
onMouseOut: e => this.handleMouseEvent(e.nativeEvent, "out")
|
|
322
311
|
}, /*#__PURE__*/React.createElement(Header, {
|
|
323
|
-
ref: this.headerRef,
|
|
324
312
|
className: cls(hideViewerCls),
|
|
325
313
|
onClose: this.handlePreviewClose,
|
|
326
314
|
renderHeader: renderHeader
|
|
@@ -331,6 +319,7 @@ export default class PreviewInner extends BaseComponent {
|
|
|
331
319
|
setRatio: this.handleAdjustRatio,
|
|
332
320
|
zoom: zoom,
|
|
333
321
|
ratio: ratio,
|
|
322
|
+
zoomStep: zoomStep,
|
|
334
323
|
rotation: rotation,
|
|
335
324
|
crossOrigin: crossOrigin,
|
|
336
325
|
onError: this.onImageError,
|
|
@@ -339,7 +328,6 @@ export default class PreviewInner extends BaseComponent {
|
|
|
339
328
|
/*#__PURE__*/
|
|
340
329
|
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
|
|
341
330
|
React.createElement("div", {
|
|
342
|
-
ref: this.leftIconRef,
|
|
343
331
|
className: cls(`${previewPrefixCls}-icon`, `${previewPrefixCls}-prev`, hideViewerCls),
|
|
344
332
|
onClick: () => this.handleSwitchImage("prev")
|
|
345
333
|
}, /*#__PURE__*/React.createElement(IconArrowLeft, {
|
|
@@ -348,13 +336,11 @@ export default class PreviewInner extends BaseComponent {
|
|
|
348
336
|
/*#__PURE__*/
|
|
349
337
|
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
|
|
350
338
|
React.createElement("div", {
|
|
351
|
-
ref: this.rightIconRef,
|
|
352
339
|
className: cls(`${previewPrefixCls}-icon`, `${previewPrefixCls}-next`, hideViewerCls),
|
|
353
340
|
onClick: () => this.handleSwitchImage("next")
|
|
354
341
|
}, /*#__PURE__*/React.createElement(IconArrowRight, {
|
|
355
342
|
size: "large"
|
|
356
343
|
})), /*#__PURE__*/React.createElement(Footer, {
|
|
357
|
-
forwardRef: this.footerRef,
|
|
358
344
|
className: hideViewerCls,
|
|
359
345
|
totalNum: total,
|
|
360
346
|
curPage: currentIndex + 1,
|
|
@@ -412,8 +398,6 @@ PreviewInner.propTypes = {
|
|
|
412
398
|
disableDownload: PropTypes.bool,
|
|
413
399
|
viewerVisibleDelay: PropTypes.number,
|
|
414
400
|
zIndex: PropTypes.number,
|
|
415
|
-
maxZoom: PropTypes.number,
|
|
416
|
-
minZoom: PropTypes.number,
|
|
417
401
|
renderHeader: PropTypes.func,
|
|
418
402
|
renderPreviewMenu: PropTypes.func,
|
|
419
403
|
getPopupContainer: PropTypes.func,
|
|
@@ -438,7 +422,5 @@ PreviewInner.defaultProps = {
|
|
|
438
422
|
preLoadGap: 2,
|
|
439
423
|
zIndex: 1000,
|
|
440
424
|
maskClosable: true,
|
|
441
|
-
viewerVisibleDelay: 10000
|
|
442
|
-
maxZoom: 5,
|
|
443
|
-
minZoom: 0.1
|
|
425
|
+
viewerVisibleDelay: 10000
|
|
444
426
|
};
|