@douyinfe/semi-ui 2.50.0-alpha.1 → 2.50.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 +3 -0
- package/dist/css/semi.min.css +1 -1
- package/dist/umd/semi-ui.js +523 -416
- 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/datePicker/yearAndMonth.js +1 -5
- 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 +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 +12 -3
- package/lib/cjs/image/previewInner.js +65 -44
- package/lib/cjs/index.d.ts +2 -0
- package/lib/cjs/index.js +14 -0
- package/lib/cjs/notification/index.js +6 -5
- package/lib/cjs/select/index.d.ts +1 -1
- package/lib/cjs/timePicker/TimePicker.d.ts +1 -1
- package/lib/cjs/treeSelect/index.d.ts +2 -2
- package/lib/cjs/treeSelect/index.js +117 -29
- package/lib/es/datePicker/yearAndMonth.js +1 -5
- 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 +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 +12 -3
- package/lib/es/image/previewInner.js +65 -44
- package/lib/es/index.d.ts +2 -0
- package/lib/es/index.js +2 -0
- package/lib/es/notification/index.js +6 -5
- package/lib/es/select/index.d.ts +1 -1
- package/lib/es/timePicker/TimePicker.d.ts +1 -1
- package/lib/es/treeSelect/index.d.ts +2 -2
- package/lib/es/treeSelect/index.js +118 -30
- package/package.json +8 -8
|
@@ -131,11 +131,7 @@ class YearAndMonth extends _baseComponent.default {
|
|
|
131
131
|
const right = _constants2.strings.PANEL_TYPE_RIGHT;
|
|
132
132
|
const needDisabled = year => {
|
|
133
133
|
if (panelType === right && currentYear[left]) {
|
|
134
|
-
|
|
135
|
-
return currentYear[left] > year;
|
|
136
|
-
} else {
|
|
137
|
-
return currentYear[left] >= year;
|
|
138
|
-
}
|
|
134
|
+
return currentYear[left] > year;
|
|
139
135
|
}
|
|
140
136
|
return false;
|
|
141
137
|
};
|
|
@@ -130,7 +130,7 @@ declare class Form<Values extends Record<string, any> = any> extends BaseCompone
|
|
|
130
130
|
onDeselect?: (value: string | number | any[] | Record<string, any>, option: Record<string, any>) => void;
|
|
131
131
|
onSelect?: (value: string | number | any[] | Record<string, any>, option: Record<string, any>) => void;
|
|
132
132
|
allowCreate?: boolean;
|
|
133
|
-
triggerRender?: (props
|
|
133
|
+
triggerRender?: (props: import("../select").TriggerRenderProps) => React.ReactNode;
|
|
134
134
|
onClear?: () => void;
|
|
135
135
|
virtualize?: import("../select").virtualListProps;
|
|
136
136
|
onFocus?: (e: React.FocusEvent<Element, Element>) => void;
|
package/lib/cjs/form/field.d.ts
CHANGED
|
@@ -76,7 +76,7 @@ declare const FormSelect: import("react").ComponentType<import("utility-types").
|
|
|
76
76
|
onDeselect?: (value: string | number | any[] | Record<string, any>, option: Record<string, any>) => void;
|
|
77
77
|
onSelect?: (value: string | number | any[] | Record<string, any>, option: Record<string, any>) => void;
|
|
78
78
|
allowCreate?: boolean;
|
|
79
|
-
triggerRender?: (props
|
|
79
|
+
triggerRender?: (props: import("../select/index").TriggerRenderProps) => import("react").ReactNode;
|
|
80
80
|
onClear?: () => void;
|
|
81
81
|
virtualize?: import("../select/index").virtualListProps;
|
|
82
82
|
onFocus?: (e: import("react").FocusEvent<Element, Element>) => void;
|
|
@@ -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;
|
|
@@ -19,14 +19,9 @@ var _localeConsumer = _interopRequireDefault(require("../locale/localeConsumer")
|
|
|
19
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
20
|
const prefixCls = _constants.cssClasses.PREFIX;
|
|
21
21
|
const footerPrefixCls = `${_constants.cssClasses.PREFIX}-preview-footer`;
|
|
22
|
-
let mouseActiveTime = 0;
|
|
23
22
|
class Footer extends _baseComponent.default {
|
|
24
23
|
get adapter() {
|
|
25
|
-
return Object.assign(
|
|
26
|
-
setStartMouseOffset: time => {
|
|
27
|
-
mouseActiveTime = time;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
24
|
+
return Object.assign({}, super.adapter);
|
|
30
25
|
}
|
|
31
26
|
constructor(props) {
|
|
32
27
|
super(props);
|
|
@@ -266,13 +261,15 @@ class Footer extends _baseComponent.default {
|
|
|
266
261
|
render() {
|
|
267
262
|
const {
|
|
268
263
|
className,
|
|
269
|
-
renderPreviewMenu
|
|
264
|
+
renderPreviewMenu,
|
|
265
|
+
forwardRef
|
|
270
266
|
} = this.props;
|
|
271
267
|
const menuCls = (0, _classnames.default)(footerPrefixCls, `${footerPrefixCls}-wrapper`, className, {
|
|
272
268
|
[`${footerPrefixCls}-content`]: !Boolean(renderPreviewMenu)
|
|
273
269
|
});
|
|
274
270
|
return /*#__PURE__*/_react.default.createElement("section", {
|
|
275
|
-
className: menuCls
|
|
271
|
+
className: menuCls,
|
|
272
|
+
ref: forwardRef
|
|
276
273
|
}, renderPreviewMenu ? this.customRenderViewMenu() : this.getFooterMenu());
|
|
277
274
|
}
|
|
278
275
|
}
|
|
@@ -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;
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _semiIcons = require("@douyinfe/semi-icons");
|
|
9
9
|
var _constants = require("@douyinfe/semi-foundation/lib/cjs/image/constants");
|
|
10
10
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
@@ -13,14 +13,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
13
13
|
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); }
|
|
14
14
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
15
|
const prefixCls = `${_constants.cssClasses.PREFIX}-preview-header`;
|
|
16
|
-
const Header = _ref => {
|
|
16
|
+
const Header = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
17
17
|
let {
|
|
18
18
|
onClose,
|
|
19
19
|
titleStyle,
|
|
20
20
|
className,
|
|
21
21
|
renderHeader
|
|
22
22
|
} = _ref;
|
|
23
|
-
return /*#__PURE__*/
|
|
23
|
+
return /*#__PURE__*/_react.default.createElement(_previewContext.PreviewContext.Consumer, null, _ref2 => {
|
|
24
24
|
let {
|
|
25
25
|
currentIndex,
|
|
26
26
|
titles
|
|
@@ -29,16 +29,17 @@ const Header = _ref => {
|
|
|
29
29
|
if (titles && typeof currentIndex === "number") {
|
|
30
30
|
title = titles[currentIndex];
|
|
31
31
|
}
|
|
32
|
-
return /*#__PURE__*/
|
|
32
|
+
return /*#__PURE__*/_react.default.createElement("section", {
|
|
33
|
+
ref: ref,
|
|
33
34
|
className: (0, _classnames.default)(prefixCls, className)
|
|
34
|
-
}, /*#__PURE__*/
|
|
35
|
+
}, /*#__PURE__*/_react.default.createElement("section", {
|
|
35
36
|
className: `${prefixCls}-title`,
|
|
36
37
|
style: titleStyle
|
|
37
|
-
}, renderHeader ? renderHeader(title) : title), /*#__PURE__*/
|
|
38
|
+
}, renderHeader ? renderHeader(title) : title), /*#__PURE__*/_react.default.createElement("section", {
|
|
38
39
|
className: `${prefixCls}-close`,
|
|
39
40
|
onMouseUp: onClose
|
|
40
|
-
}, /*#__PURE__*/
|
|
41
|
+
}, /*#__PURE__*/_react.default.createElement(_semiIcons.IconClose, null)));
|
|
41
42
|
});
|
|
42
|
-
};
|
|
43
|
+
});
|
|
43
44
|
var _default = Header;
|
|
44
45
|
exports.default = _default;
|
|
@@ -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
|
}
|
|
@@ -13,38 +13,14 @@ var _previewImageFoundation = _interopRequireDefault(require("@douyinfe/semi-fou
|
|
|
13
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
14
|
const prefixCls = _constants.cssClasses.PREFIX;
|
|
15
15
|
const preViewImgPrefixCls = `${prefixCls}-preview-image`;
|
|
16
|
-
let originImageWidth = null;
|
|
17
|
-
let originImageHeight = null;
|
|
18
|
-
let startMouseMove = false;
|
|
19
|
-
// startMouseOffset:The offset of the mouse relative to the left and top of the picture
|
|
20
|
-
let startMouseOffset = {
|
|
21
|
-
x: 0,
|
|
22
|
-
y: 0
|
|
23
|
-
};
|
|
24
16
|
class PreviewImage extends _baseComponent.default {
|
|
25
17
|
get adapter() {
|
|
26
18
|
return Object.assign(Object.assign({}, super.adapter), {
|
|
27
|
-
getOriginImageSize: () => ({
|
|
28
|
-
originImageWidth,
|
|
29
|
-
originImageHeight
|
|
30
|
-
}),
|
|
31
|
-
setOriginImageSize: size => {
|
|
32
|
-
originImageWidth = size.originImageWidth;
|
|
33
|
-
originImageHeight = size.originImageHeight;
|
|
34
|
-
},
|
|
35
19
|
getContainer: () => {
|
|
36
20
|
return this.containerRef.current;
|
|
37
21
|
},
|
|
38
22
|
getImage: () => {
|
|
39
|
-
return this.imageRef;
|
|
40
|
-
},
|
|
41
|
-
getMouseMove: () => startMouseMove,
|
|
42
|
-
setStartMouseMove: move => {
|
|
43
|
-
startMouseMove = move;
|
|
44
|
-
},
|
|
45
|
-
getMouseOffset: () => startMouseOffset,
|
|
46
|
-
setStartMouseOffset: offset => {
|
|
47
|
-
startMouseOffset = offset;
|
|
23
|
+
return this.imageRef.current;
|
|
48
24
|
},
|
|
49
25
|
setLoading: loading => {
|
|
50
26
|
this.setState({
|
|
@@ -52,7 +28,7 @@ class PreviewImage extends _baseComponent.default {
|
|
|
52
28
|
});
|
|
53
29
|
},
|
|
54
30
|
setImageCursor: canDrag => {
|
|
55
|
-
this.imageRef.style.cursor = canDrag ? "grab" : "default";
|
|
31
|
+
this.imageRef.current.style.cursor = canDrag ? "grab" : "default";
|
|
56
32
|
}
|
|
57
33
|
});
|
|
58
34
|
}
|
|
@@ -61,52 +37,22 @@ class PreviewImage extends _baseComponent.default {
|
|
|
61
37
|
this.onWindowResize = () => {
|
|
62
38
|
this.foundation.handleWindowResize();
|
|
63
39
|
};
|
|
64
|
-
this.handleZoomChange = (newZoom, e) => {
|
|
65
|
-
this.foundation.handleZoomChange(newZoom, e);
|
|
66
|
-
};
|
|
67
40
|
// Determine the response method of right click according to the disableDownload parameter in props
|
|
68
41
|
this.handleRightClickImage = e => {
|
|
69
42
|
this.foundation.handleRightClickImage(e);
|
|
70
43
|
};
|
|
71
|
-
this.handleWheel = e => {
|
|
72
|
-
this.foundation.handleWheel(e);
|
|
73
|
-
};
|
|
74
44
|
this.handleLoad = e => {
|
|
75
45
|
this.foundation.handleLoad(e);
|
|
76
46
|
};
|
|
77
47
|
this.handleError = e => {
|
|
78
48
|
this.foundation.handleError(e);
|
|
79
49
|
};
|
|
80
|
-
this.resizeImage = () => {
|
|
81
|
-
this.foundation.handleResizeImage();
|
|
82
|
-
};
|
|
83
50
|
this.handleMoveImage = e => {
|
|
84
51
|
this.foundation.handleMoveImage(e);
|
|
85
52
|
};
|
|
86
|
-
// 为什么通过ref注册wheel而不是使用onWheel事件?
|
|
87
|
-
// 因为对于wheel事件,浏览器将 addEventListener 的 passive 默认值更改为 true。如此,事件监听器便不能取消事件,也不会在用户滚动页面时阻止页面呈现。
|
|
88
|
-
// 这里我们需要保持页面不动,仅放大图片,因此此处需要将 passive 更改设置为 false。
|
|
89
|
-
// Why register wheel via ref instead of using onWheel event?
|
|
90
|
-
// 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.
|
|
91
|
-
// 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.
|
|
92
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#improving_scrolling_performance_with_passive_listeners。
|
|
93
|
-
this.registryImageRef = ref => {
|
|
94
|
-
if (this.imageRef) {
|
|
95
|
-
this.imageRef.removeEventListener("wheel", this.handleWheel);
|
|
96
|
-
}
|
|
97
|
-
if (ref) {
|
|
98
|
-
ref.addEventListener("wheel", this.handleWheel, {
|
|
99
|
-
passive: false
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
this.imageRef = ref;
|
|
103
|
-
};
|
|
104
53
|
this.onImageMouseDown = e => {
|
|
105
54
|
this.foundation.handleImageMouseDown(e);
|
|
106
55
|
};
|
|
107
|
-
this.onImageMouseUp = () => {
|
|
108
|
-
this.foundation.handleImageMouseUp();
|
|
109
|
-
};
|
|
110
56
|
this.state = {
|
|
111
57
|
width: 0,
|
|
112
58
|
height: 0,
|
|
@@ -120,7 +66,7 @@ class PreviewImage extends _baseComponent.default {
|
|
|
120
66
|
left: 0
|
|
121
67
|
};
|
|
122
68
|
this.containerRef = /*#__PURE__*/_react.default.createRef();
|
|
123
|
-
this.imageRef =
|
|
69
|
+
this.imageRef = /*#__PURE__*/_react.default.createRef();
|
|
124
70
|
this.foundation = new _previewImageFoundation.default(this.adapter);
|
|
125
71
|
}
|
|
126
72
|
componentDidMount() {
|
|
@@ -131,27 +77,22 @@ class PreviewImage extends _baseComponent.default {
|
|
|
131
77
|
}
|
|
132
78
|
componentDidUpdate(prevProps, prevStates) {
|
|
133
79
|
// If src changes, start a new loading
|
|
134
|
-
|
|
80
|
+
const zoomChange = "zoom" in this.props && this.props.zoom !== this.state.currZoom;
|
|
81
|
+
const srcChange = this.props.src && this.props.src !== prevProps.src;
|
|
82
|
+
if (srcChange) {
|
|
135
83
|
this.foundation.setLoading(true);
|
|
136
84
|
}
|
|
137
85
|
// If the incoming zoom changes, other content changes are determined based on the new zoom value
|
|
138
|
-
if (
|
|
139
|
-
this.
|
|
86
|
+
if (zoomChange) {
|
|
87
|
+
this.foundation.calculatePreviewImage(this.props.zoom, null);
|
|
140
88
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
} else {
|
|
148
|
-
this.props.onZoom(1);
|
|
149
|
-
}
|
|
89
|
+
if (!zoomChange && !srcChange && prevProps) {
|
|
90
|
+
if ("ratio" in this.props && this.props.ratio !== prevProps.ratio) {
|
|
91
|
+
this.foundation.handleRatioChange();
|
|
92
|
+
}
|
|
93
|
+
if ("rotation" in this.props && this.props.rotation !== prevProps.rotation) {
|
|
94
|
+
this.onWindowResize();
|
|
150
95
|
}
|
|
151
|
-
}
|
|
152
|
-
// When the incoming rotation angle of the image changes, it needs to be resized to make the image fit on the page
|
|
153
|
-
if ("rotation" in this.props && this.props.rotation !== prevProps.rotation) {
|
|
154
|
-
this.onWindowResize();
|
|
155
96
|
}
|
|
156
97
|
}
|
|
157
98
|
render() {
|
|
@@ -173,21 +114,20 @@ class PreviewImage extends _baseComponent.default {
|
|
|
173
114
|
transform: `rotate(${-rotation}deg)`,
|
|
174
115
|
top,
|
|
175
116
|
left,
|
|
176
|
-
width
|
|
177
|
-
height
|
|
117
|
+
width,
|
|
118
|
+
height
|
|
178
119
|
};
|
|
179
120
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
180
121
|
className: `${preViewImgPrefixCls}`,
|
|
181
122
|
ref: this.containerRef
|
|
182
123
|
}, /*#__PURE__*/_react.default.createElement("img", {
|
|
183
|
-
ref: this.
|
|
124
|
+
ref: this.imageRef,
|
|
184
125
|
src: src,
|
|
185
126
|
alt: "previewImag",
|
|
186
127
|
className: `${preViewImgPrefixCls}-img`,
|
|
187
128
|
key: src,
|
|
188
129
|
onMouseMove: this.handleMoveImage,
|
|
189
130
|
onMouseDown: this.onImageMouseDown,
|
|
190
|
-
onMouseUp: this.onImageMouseUp,
|
|
191
131
|
onContextMenu: this.handleRightClickImage,
|
|
192
132
|
onDragStart: e => e.preventDefault(),
|
|
193
133
|
onLoad: this.handleLoad,
|
|
@@ -205,9 +145,9 @@ PreviewImage.propTypes = {
|
|
|
205
145
|
src: _propTypes.default.string,
|
|
206
146
|
rotation: _propTypes.default.number,
|
|
207
147
|
style: _propTypes.default.object,
|
|
208
|
-
maxZoom:
|
|
209
|
-
minZoom:
|
|
210
|
-
zoomStep:
|
|
148
|
+
// maxZoom: PropTypes.number,
|
|
149
|
+
// minZoom: PropTypes.number,
|
|
150
|
+
// zoomStep: PropTypes.number,
|
|
211
151
|
zoom: _propTypes.default.number,
|
|
212
152
|
ratio: _propTypes.default.string,
|
|
213
153
|
disableDownload: _propTypes.default.bool,
|
|
@@ -218,8 +158,8 @@ PreviewImage.propTypes = {
|
|
|
218
158
|
onError: _propTypes.default.func
|
|
219
159
|
};
|
|
220
160
|
PreviewImage.defaultProps = {
|
|
221
|
-
maxZoom: 5,
|
|
222
|
-
minZoom: 0.1,
|
|
223
|
-
zoomStep: 0.1,
|
|
161
|
+
// maxZoom: 5,
|
|
162
|
+
// minZoom: 0.1,
|
|
163
|
+
// zoomStep: 0.1,
|
|
224
164
|
zoom: undefined
|
|
225
165
|
};
|
|
@@ -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;
|
|
@@ -78,13 +86,14 @@ export default class PreviewInner extends BaseComponent<PreviewInnerProps, Previ
|
|
|
78
86
|
handlePreviewClose: () => void;
|
|
79
87
|
handleAdjustRatio: (type: RatioType) => void;
|
|
80
88
|
handleRotateImage: (direction: any) => void;
|
|
81
|
-
handleZoomImage: (newZoom: number) => void;
|
|
89
|
+
handleZoomImage: (newZoom: number, notify?: boolean) => 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
|
}
|
|
@@ -21,14 +21,6 @@ var _previewContext = require("./previewContext");
|
|
|
21
21
|
var _utils = require("../_utils");
|
|
22
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
23
|
const prefixCls = _constants.cssClasses.PREFIX;
|
|
24
|
-
let startMouseDown = {
|
|
25
|
-
x: 0,
|
|
26
|
-
y: 0
|
|
27
|
-
};
|
|
28
|
-
let mouseActiveTime = null;
|
|
29
|
-
let stopTiming = false;
|
|
30
|
-
let timer = null;
|
|
31
|
-
// let bodyOverflowValue = document.body.style.overflow;
|
|
32
24
|
class PreviewInner extends _baseComponent.default {
|
|
33
25
|
get adapter() {
|
|
34
26
|
return Object.assign(Object.assign({}, super.adapter), {
|
|
@@ -112,35 +104,29 @@ class PreviewInner extends _baseComponent.default {
|
|
|
112
104
|
unregisterKeyDownListener: () => {
|
|
113
105
|
window && window.removeEventListener("keydown", this.handleKeyDown);
|
|
114
106
|
},
|
|
115
|
-
getMouseActiveTime: () => {
|
|
116
|
-
return mouseActiveTime;
|
|
117
|
-
},
|
|
118
|
-
getStopTiming: () => {
|
|
119
|
-
return stopTiming;
|
|
120
|
-
},
|
|
121
|
-
setStopTiming: value => {
|
|
122
|
-
stopTiming = value;
|
|
123
|
-
},
|
|
124
|
-
getStartMouseDown: () => {
|
|
125
|
-
return startMouseDown;
|
|
126
|
-
},
|
|
127
|
-
setStartMouseDown: (x, y) => {
|
|
128
|
-
startMouseDown = {
|
|
129
|
-
x,
|
|
130
|
-
y
|
|
131
|
-
};
|
|
132
|
-
},
|
|
133
|
-
setMouseActiveTime: time => {
|
|
134
|
-
mouseActiveTime = time;
|
|
135
|
-
},
|
|
136
107
|
getSetDownloadFunc: () => {
|
|
137
108
|
var _a, _b;
|
|
138
109
|
return (_b = (_a = this.context) === null || _a === void 0 ? void 0 : _a.setDownloadName) !== null && _b !== void 0 ? _b : this.props.setDownloadName;
|
|
110
|
+
},
|
|
111
|
+
isValidTarget: e => {
|
|
112
|
+
const headerDom = this.headerRef && this.headerRef.current;
|
|
113
|
+
const footerDom = this.footerRef && this.footerRef.current;
|
|
114
|
+
const leftIconDom = this.leftIconRef && this.leftIconRef.current;
|
|
115
|
+
const rightIconDom = this.rightIconRef && this.rightIconRef.current;
|
|
116
|
+
const target = e.target;
|
|
117
|
+
if (headerDom && headerDom.contains(target) || footerDom && footerDom.contains(target) || leftIconDom && leftIconDom.contains(target) || rightIconDom && rightIconDom.contains(target)) {
|
|
118
|
+
// Move in the operation area, return false
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
// Move in the preview area except the operation area, return true
|
|
122
|
+
return true;
|
|
139
123
|
}
|
|
140
124
|
});
|
|
141
125
|
}
|
|
142
126
|
constructor(props) {
|
|
127
|
+
var _this;
|
|
143
128
|
super(props);
|
|
129
|
+
_this = this;
|
|
144
130
|
this.viewVisibleChange = () => {
|
|
145
131
|
this.foundation.handleViewVisibleChange();
|
|
146
132
|
};
|
|
@@ -159,8 +145,9 @@ class PreviewInner extends _baseComponent.default {
|
|
|
159
145
|
this.handleRotateImage = direction => {
|
|
160
146
|
this.foundation.handleRotateImage(direction);
|
|
161
147
|
};
|
|
162
|
-
this.handleZoomImage = newZoom
|
|
163
|
-
|
|
148
|
+
this.handleZoomImage = function (newZoom) {
|
|
149
|
+
let notify = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
150
|
+
_this.foundation.handleZoomImage(newZoom, notify);
|
|
164
151
|
};
|
|
165
152
|
this.handleMouseUp = e => {
|
|
166
153
|
this.foundation.handleMouseUp(e.nativeEvent);
|
|
@@ -168,9 +155,6 @@ class PreviewInner extends _baseComponent.default {
|
|
|
168
155
|
this.handleMouseMove = e => {
|
|
169
156
|
this.foundation.handleMouseMove(e);
|
|
170
157
|
};
|
|
171
|
-
this.handleMouseEvent = (e, event) => {
|
|
172
|
-
this.foundation.handleMouseMoveEvent(e, event);
|
|
173
|
-
};
|
|
174
158
|
this.handleKeyDown = e => {
|
|
175
159
|
this.foundation.handleKeyDown(e);
|
|
176
160
|
};
|
|
@@ -183,6 +167,31 @@ class PreviewInner extends _baseComponent.default {
|
|
|
183
167
|
this.handleMouseDown = e => {
|
|
184
168
|
this.foundation.handleMouseDown(e);
|
|
185
169
|
};
|
|
170
|
+
this.handleWheel = e => {
|
|
171
|
+
this.foundation.handleWheel(e);
|
|
172
|
+
};
|
|
173
|
+
// 为什么通过 addEventListener 注册 wheel 事件而不是使用 onWheel 事件?
|
|
174
|
+
// 因为 Passive Event Listeners(https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#improving_scrolling_performance_with_passive_listeners)
|
|
175
|
+
// Passive Event Listeners 是一种优化技术,用于提高滚动性能。在默认情况下,浏览器会假设事件的监听器不会调用
|
|
176
|
+
// preventDefault() 方法来阻止事件的默认行为,从而允许进行一些优化操作,例如滚动平滑。
|
|
177
|
+
// 对于 Image 而言,如果使用触控板,双指朝不同方向分开放大图片,则需要 preventDefault 防止页面整体放大。
|
|
178
|
+
// Why register wheel event through addEventListener instead of using onWheel event?
|
|
179
|
+
// Because of Passive Event Listeners(an optimization technique used to improve scrolling performance. By default,
|
|
180
|
+
// the browser will assume that event listeners will not call preventDefault() method to prevent the default behavior of the event,
|
|
181
|
+
// allowing some optimization operations such as scroll smoothing.)
|
|
182
|
+
// For Image, if we use the trackpad and spread your fingers in different directions to enlarge the image, we need to preventDefault
|
|
183
|
+
// to prevent the page from being enlarged as a whole.
|
|
184
|
+
this.registryImageWrapRef = ref => {
|
|
185
|
+
if (this.imageWrapRef) {
|
|
186
|
+
this.imageWrapRef.removeEventListener("wheel", this.handleWheel);
|
|
187
|
+
}
|
|
188
|
+
if (ref) {
|
|
189
|
+
ref.addEventListener("wheel", this.handleWheel, {
|
|
190
|
+
passive: false
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
this.imageWrapRef = ref;
|
|
194
|
+
};
|
|
186
195
|
this.state = {
|
|
187
196
|
imgSrc: [],
|
|
188
197
|
imgLoadStatus: new Map(),
|
|
@@ -199,6 +208,11 @@ class PreviewInner extends _baseComponent.default {
|
|
|
199
208
|
this.bodyOverflow = '';
|
|
200
209
|
this.originBodyWidth = '100%';
|
|
201
210
|
this.scrollBarWidth = 0;
|
|
211
|
+
this.imageWrapRef = null;
|
|
212
|
+
this.headerRef = /*#__PURE__*/_react.default.createRef();
|
|
213
|
+
this.footerRef = /*#__PURE__*/_react.default.createRef();
|
|
214
|
+
this.leftIconRef = /*#__PURE__*/_react.default.createRef();
|
|
215
|
+
this.rightIconRef = /*#__PURE__*/_react.default.createRef();
|
|
202
216
|
}
|
|
203
217
|
static getDerivedStateFromProps(props, state) {
|
|
204
218
|
const willUpdateStates = {};
|
|
@@ -214,6 +228,9 @@ class PreviewInner extends _baseComponent.default {
|
|
|
214
228
|
willUpdateStates.visible = props.visible;
|
|
215
229
|
if (props.visible) {
|
|
216
230
|
willUpdateStates.preloadAfterVisibleChange = true;
|
|
231
|
+
willUpdateStates.viewerVisible = true;
|
|
232
|
+
willUpdateStates.rotation = 0;
|
|
233
|
+
willUpdateStates.ratio = 'adaptation';
|
|
217
234
|
}
|
|
218
235
|
}
|
|
219
236
|
if ("currentIndex" in props && props.currentIndex !== state.currentIndex) {
|
|
@@ -232,10 +249,8 @@ class PreviewInner extends _baseComponent.default {
|
|
|
232
249
|
}
|
|
233
250
|
}
|
|
234
251
|
componentDidUpdate(prevProps, prevState) {
|
|
235
|
-
if (
|
|
236
|
-
|
|
237
|
-
timer && clearInterval(timer);
|
|
238
|
-
timer = setInterval(this.viewVisibleChange, 1000);
|
|
252
|
+
if (prevProps.src !== this.props.src) {
|
|
253
|
+
this.foundation.updateTimer();
|
|
239
254
|
}
|
|
240
255
|
// hide => show
|
|
241
256
|
if (!prevProps.visible && this.props.visible) {
|
|
@@ -247,7 +262,7 @@ class PreviewInner extends _baseComponent.default {
|
|
|
247
262
|
}
|
|
248
263
|
}
|
|
249
264
|
componentWillUnmount() {
|
|
250
|
-
|
|
265
|
+
this.foundation.clearTimer();
|
|
251
266
|
}
|
|
252
267
|
isInGroup() {
|
|
253
268
|
return Boolean(this.context && this.context.isGroup);
|
|
@@ -312,10 +327,10 @@ class PreviewInner extends _baseComponent.default {
|
|
|
312
327
|
style: style,
|
|
313
328
|
onMouseDown: this.handleMouseDown,
|
|
314
329
|
onMouseUp: this.handleMouseUp,
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
onMouseOut: e => this.handleMouseEvent(e.nativeEvent, "out")
|
|
330
|
+
ref: this.registryImageWrapRef,
|
|
331
|
+
onMouseMove: this.handleMouseMove
|
|
318
332
|
}, /*#__PURE__*/_react.default.createElement(_previewHeader.default, {
|
|
333
|
+
ref: this.headerRef,
|
|
319
334
|
className: (0, _classnames.default)(hideViewerCls),
|
|
320
335
|
onClose: this.handlePreviewClose,
|
|
321
336
|
renderHeader: renderHeader
|
|
@@ -326,7 +341,6 @@ class PreviewInner extends _baseComponent.default {
|
|
|
326
341
|
setRatio: this.handleAdjustRatio,
|
|
327
342
|
zoom: zoom,
|
|
328
343
|
ratio: ratio,
|
|
329
|
-
zoomStep: zoomStep,
|
|
330
344
|
rotation: rotation,
|
|
331
345
|
crossOrigin: crossOrigin,
|
|
332
346
|
onError: this.onImageError,
|
|
@@ -335,6 +349,7 @@ class PreviewInner extends _baseComponent.default {
|
|
|
335
349
|
/*#__PURE__*/
|
|
336
350
|
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
|
|
337
351
|
_react.default.createElement("div", {
|
|
352
|
+
ref: this.leftIconRef,
|
|
338
353
|
className: (0, _classnames.default)(`${previewPrefixCls}-icon`, `${previewPrefixCls}-prev`, hideViewerCls),
|
|
339
354
|
onClick: () => this.handleSwitchImage("prev")
|
|
340
355
|
}, /*#__PURE__*/_react.default.createElement(_semiIcons.IconArrowLeft, {
|
|
@@ -343,11 +358,13 @@ class PreviewInner extends _baseComponent.default {
|
|
|
343
358
|
/*#__PURE__*/
|
|
344
359
|
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
|
|
345
360
|
_react.default.createElement("div", {
|
|
361
|
+
ref: this.rightIconRef,
|
|
346
362
|
className: (0, _classnames.default)(`${previewPrefixCls}-icon`, `${previewPrefixCls}-next`, hideViewerCls),
|
|
347
363
|
onClick: () => this.handleSwitchImage("next")
|
|
348
364
|
}, /*#__PURE__*/_react.default.createElement(_semiIcons.IconArrowRight, {
|
|
349
365
|
size: "large"
|
|
350
366
|
})), /*#__PURE__*/_react.default.createElement(_previewFooter.default, {
|
|
367
|
+
forwardRef: this.footerRef,
|
|
351
368
|
className: hideViewerCls,
|
|
352
369
|
totalNum: total,
|
|
353
370
|
curPage: currentIndex + 1,
|
|
@@ -406,6 +423,8 @@ PreviewInner.propTypes = {
|
|
|
406
423
|
disableDownload: _propTypes.default.bool,
|
|
407
424
|
viewerVisibleDelay: _propTypes.default.number,
|
|
408
425
|
zIndex: _propTypes.default.number,
|
|
426
|
+
maxZoom: _propTypes.default.number,
|
|
427
|
+
minZoom: _propTypes.default.number,
|
|
409
428
|
renderHeader: _propTypes.default.func,
|
|
410
429
|
renderPreviewMenu: _propTypes.default.func,
|
|
411
430
|
getPopupContainer: _propTypes.default.func,
|
|
@@ -430,5 +449,7 @@ PreviewInner.defaultProps = {
|
|
|
430
449
|
preLoadGap: 2,
|
|
431
450
|
zIndex: 1000,
|
|
432
451
|
maskClosable: true,
|
|
433
|
-
viewerVisibleDelay: 10000
|
|
452
|
+
viewerVisibleDelay: 10000,
|
|
453
|
+
maxZoom: 5,
|
|
454
|
+
minZoom: 0.1
|
|
434
455
|
};
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import './_base/base.css';
|
|
2
|
+
export { default as BaseFoundation } from '@douyinfe/semi-foundation/lib/cjs/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';
|