@douyinfe/semi-ui 2.49.1 → 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 +385 -376
- 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/index.d.ts +0 -2
- package/lib/cjs/index.js +0 -14
- package/lib/cjs/modal/confirm.d.ts +11 -11
- 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/index.d.ts +0 -2
- package/lib/es/index.js +0 -2
- package/lib/es/modal/confirm.d.ts +11 -11
- 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
|
@@ -49,7 +49,7 @@ declare class Anchor extends BaseComponent<AnchorProps, AnchorState> {
|
|
|
49
49
|
offsetTop: PropTypes.Requireable<number>;
|
|
50
50
|
targetOffset: PropTypes.Requireable<number>;
|
|
51
51
|
showTooltip: PropTypes.Requireable<boolean>;
|
|
52
|
-
position: PropTypes.Requireable<"left" | "right" | "top" | "
|
|
52
|
+
position: PropTypes.Requireable<"left" | "right" | "top" | "topLeft" | "topRight" | "leftTop" | "leftBottom" | "rightTop" | "rightBottom" | "bottom" | "bottomLeft" | "bottomRight" | "leftTopOver" | "rightTopOver">;
|
|
53
53
|
maxWidth: PropTypes.Requireable<NonNullable<string | number>>;
|
|
54
54
|
maxHeight: PropTypes.Requireable<NonNullable<string | number>>;
|
|
55
55
|
getContainer: PropTypes.Requireable<(...args: any[]) => any>;
|
|
@@ -116,7 +116,7 @@ declare class AutoComplete<T extends AutoCompleteItems> extends BaseComponent<Au
|
|
|
116
116
|
onFocus: PropTypes.Requireable<(...args: any[]) => any>;
|
|
117
117
|
onChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
118
118
|
onKeyDown: PropTypes.Requireable<(...args: any[]) => any>;
|
|
119
|
-
position: PropTypes.Requireable<"left" | "right" | "top" | "
|
|
119
|
+
position: PropTypes.Requireable<"left" | "right" | "top" | "topLeft" | "topRight" | "leftTop" | "leftBottom" | "rightTop" | "rightBottom" | "bottom" | "bottomLeft" | "bottomRight" | "leftTopOver" | "rightTopOver" | "leftBottomOver" | "rightBottomOver">;
|
|
120
120
|
placeholder: PropTypes.Requireable<string>;
|
|
121
121
|
prefix: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
122
122
|
onChangeWithObject: PropTypes.Requireable<boolean>;
|
|
@@ -48,7 +48,7 @@ export default class Button extends PureComponent<ButtonProps> {
|
|
|
48
48
|
prefixCls: PropTypes.Requireable<string>;
|
|
49
49
|
style: PropTypes.Requireable<object>;
|
|
50
50
|
size: PropTypes.Requireable<"default" | "small" | "large">;
|
|
51
|
-
type: PropTypes.Requireable<"warning" | "primary" | "
|
|
51
|
+
type: PropTypes.Requireable<"warning" | "primary" | "secondary" | "tertiary" | "danger">;
|
|
52
52
|
block: PropTypes.Requireable<boolean>;
|
|
53
53
|
onClick: PropTypes.Requireable<(...args: any[]) => any>;
|
|
54
54
|
onMouseDown: PropTypes.Requireable<(...args: any[]) => any>;
|
|
@@ -23,7 +23,7 @@ declare class Button extends React.PureComponent<ButtonProps> {
|
|
|
23
23
|
onMouseLeave: import("prop-types").Requireable<(...args: any[]) => any>;
|
|
24
24
|
disabled: import("prop-types").Requireable<boolean>;
|
|
25
25
|
size: import("prop-types").Requireable<"default" | "small" | "large">;
|
|
26
|
-
type: import("prop-types").Requireable<"warning" | "primary" | "
|
|
26
|
+
type: import("prop-types").Requireable<"warning" | "primary" | "secondary" | "tertiary" | "danger">;
|
|
27
27
|
block: import("prop-types").Requireable<boolean>;
|
|
28
28
|
onClick: import("prop-types").Requireable<(...args: any[]) => any>;
|
|
29
29
|
onMouseDown: import("prop-types").Requireable<(...args: any[]) => any>;
|
|
@@ -24,7 +24,7 @@ declare class Carousel extends BaseComponent<CarouselProps, CarouselState> {
|
|
|
24
24
|
indicatorType: PropTypes.Requireable<"line" | "dot" | "columnar">;
|
|
25
25
|
theme: PropTypes.Requireable<"dark" | "light" | "primary">;
|
|
26
26
|
onChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
27
|
-
arrowType: PropTypes.Requireable<"
|
|
27
|
+
arrowType: PropTypes.Requireable<"hover" | "always">;
|
|
28
28
|
showArrow: PropTypes.Requireable<boolean>;
|
|
29
29
|
showIndicator: PropTypes.Requireable<boolean>;
|
|
30
30
|
slideDirection: PropTypes.Requireable<"left" | "right">;
|
|
@@ -91,7 +91,7 @@ export default class DatePicker extends BaseComponent<DatePickerProps, DatePicke
|
|
|
91
91
|
insetLabel: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
92
92
|
insetLabelId: PropTypes.Requireable<string>;
|
|
93
93
|
zIndex: PropTypes.Requireable<number>;
|
|
94
|
-
position: PropTypes.Requireable<"left" | "right" | "top" | "
|
|
94
|
+
position: PropTypes.Requireable<"left" | "right" | "top" | "topLeft" | "topRight" | "leftTop" | "leftBottom" | "rightTop" | "rightBottom" | "bottom" | "bottomLeft" | "bottomRight" | "leftTopOver" | "rightTopOver">;
|
|
95
95
|
getPopupContainer: PropTypes.Requireable<(...args: any[]) => any>;
|
|
96
96
|
onCancel: PropTypes.Requireable<(...args: any[]) => any>;
|
|
97
97
|
onConfirm: PropTypes.Requireable<(...args: any[]) => any>;
|
|
@@ -66,7 +66,7 @@ declare class Dropdown extends BaseComponent<DropdownProps, DropdownState> {
|
|
|
66
66
|
motion: PropTypes.Requireable<NonNullable<boolean | object>>;
|
|
67
67
|
onVisibleChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
68
68
|
prefixCls: PropTypes.Requireable<string>;
|
|
69
|
-
position: PropTypes.Requireable<"left" | "right" | "top" | "
|
|
69
|
+
position: PropTypes.Requireable<"left" | "right" | "top" | "topLeft" | "topRight" | "leftTop" | "leftBottom" | "rightTop" | "rightBottom" | "bottom" | "bottomLeft" | "bottomRight" | "leftTopOver" | "rightTopOver" | "leftBottomOver" | "rightBottomOver">;
|
|
70
70
|
rePosKey: PropTypes.Requireable<NonNullable<string | number>>;
|
|
71
71
|
render: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
72
72
|
spacing: PropTypes.Requireable<NonNullable<number | object>>;
|
|
@@ -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/cjs/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;
|
|
@@ -19,9 +19,14 @@ 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;
|
|
22
23
|
class Footer extends _baseComponent.default {
|
|
23
24
|
get adapter() {
|
|
24
|
-
return Object.assign({}, super.adapter)
|
|
25
|
+
return Object.assign(Object.assign({}, super.adapter), {
|
|
26
|
+
setStartMouseOffset: time => {
|
|
27
|
+
mouseActiveTime = time;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
25
30
|
}
|
|
26
31
|
constructor(props) {
|
|
27
32
|
super(props);
|
|
@@ -261,15 +266,13 @@ class Footer extends _baseComponent.default {
|
|
|
261
266
|
render() {
|
|
262
267
|
const {
|
|
263
268
|
className,
|
|
264
|
-
renderPreviewMenu
|
|
265
|
-
forwardRef
|
|
269
|
+
renderPreviewMenu
|
|
266
270
|
} = this.props;
|
|
267
271
|
const menuCls = (0, _classnames.default)(footerPrefixCls, `${footerPrefixCls}-wrapper`, className, {
|
|
268
272
|
[`${footerPrefixCls}-content`]: !Boolean(renderPreviewMenu)
|
|
269
273
|
});
|
|
270
274
|
return /*#__PURE__*/_react.default.createElement("section", {
|
|
271
|
-
className: menuCls
|
|
272
|
-
ref: forwardRef
|
|
275
|
+
className: menuCls
|
|
273
276
|
}, renderPreviewMenu ? this.customRenderViewMenu() : this.getFooterMenu());
|
|
274
277
|
}
|
|
275
278
|
}
|
|
@@ -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;
|
|
@@ -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 =
|
|
16
|
+
const Header = _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.createElement(_previewContext.PreviewContext.Consumer, null, _ref2 => {
|
|
24
24
|
let {
|
|
25
25
|
currentIndex,
|
|
26
26
|
titles
|
|
@@ -29,17 +29,16 @@ const Header = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
|
29
29
|
if (titles && typeof currentIndex === "number") {
|
|
30
30
|
title = titles[currentIndex];
|
|
31
31
|
}
|
|
32
|
-
return /*#__PURE__*/
|
|
33
|
-
ref: ref,
|
|
32
|
+
return /*#__PURE__*/React.createElement("section", {
|
|
34
33
|
className: (0, _classnames.default)(prefixCls, className)
|
|
35
|
-
}, /*#__PURE__*/
|
|
34
|
+
}, /*#__PURE__*/React.createElement("section", {
|
|
36
35
|
className: `${prefixCls}-title`,
|
|
37
36
|
style: titleStyle
|
|
38
|
-
}, renderHeader ? renderHeader(title) : title), /*#__PURE__*/
|
|
37
|
+
}, renderHeader ? renderHeader(title) : title), /*#__PURE__*/React.createElement("section", {
|
|
39
38
|
className: `${prefixCls}-close`,
|
|
40
39
|
onMouseUp: onClose
|
|
41
|
-
}, /*#__PURE__*/
|
|
40
|
+
}, /*#__PURE__*/React.createElement(_semiIcons.IconClose, null)));
|
|
42
41
|
});
|
|
43
|
-
}
|
|
42
|
+
};
|
|
44
43
|
var _default = Header;
|
|
45
44
|
exports.default = _default;
|
|
@@ -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
|
}
|
|
@@ -13,14 +13,38 @@ 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
|
+
};
|
|
16
24
|
class PreviewImage extends _baseComponent.default {
|
|
17
25
|
get adapter() {
|
|
18
26
|
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
|
+
},
|
|
19
35
|
getContainer: () => {
|
|
20
36
|
return this.containerRef.current;
|
|
21
37
|
},
|
|
22
38
|
getImage: () => {
|
|
23
|
-
return this.imageRef
|
|
39
|
+
return this.imageRef;
|
|
40
|
+
},
|
|
41
|
+
getMouseMove: () => startMouseMove,
|
|
42
|
+
setStartMouseMove: move => {
|
|
43
|
+
startMouseMove = move;
|
|
44
|
+
},
|
|
45
|
+
getMouseOffset: () => startMouseOffset,
|
|
46
|
+
setStartMouseOffset: offset => {
|
|
47
|
+
startMouseOffset = offset;
|
|
24
48
|
},
|
|
25
49
|
setLoading: loading => {
|
|
26
50
|
this.setState({
|
|
@@ -28,7 +52,7 @@ class PreviewImage extends _baseComponent.default {
|
|
|
28
52
|
});
|
|
29
53
|
},
|
|
30
54
|
setImageCursor: canDrag => {
|
|
31
|
-
this.imageRef.
|
|
55
|
+
this.imageRef.style.cursor = canDrag ? "grab" : "default";
|
|
32
56
|
}
|
|
33
57
|
});
|
|
34
58
|
}
|
|
@@ -37,22 +61,52 @@ class PreviewImage extends _baseComponent.default {
|
|
|
37
61
|
this.onWindowResize = () => {
|
|
38
62
|
this.foundation.handleWindowResize();
|
|
39
63
|
};
|
|
64
|
+
this.handleZoomChange = (newZoom, e) => {
|
|
65
|
+
this.foundation.handleZoomChange(newZoom, e);
|
|
66
|
+
};
|
|
40
67
|
// Determine the response method of right click according to the disableDownload parameter in props
|
|
41
68
|
this.handleRightClickImage = e => {
|
|
42
69
|
this.foundation.handleRightClickImage(e);
|
|
43
70
|
};
|
|
71
|
+
this.handleWheel = e => {
|
|
72
|
+
this.foundation.handleWheel(e);
|
|
73
|
+
};
|
|
44
74
|
this.handleLoad = e => {
|
|
45
75
|
this.foundation.handleLoad(e);
|
|
46
76
|
};
|
|
47
77
|
this.handleError = e => {
|
|
48
78
|
this.foundation.handleError(e);
|
|
49
79
|
};
|
|
80
|
+
this.resizeImage = () => {
|
|
81
|
+
this.foundation.handleResizeImage();
|
|
82
|
+
};
|
|
50
83
|
this.handleMoveImage = e => {
|
|
51
84
|
this.foundation.handleMoveImage(e);
|
|
52
85
|
};
|
|
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
|
+
};
|
|
53
104
|
this.onImageMouseDown = e => {
|
|
54
105
|
this.foundation.handleImageMouseDown(e);
|
|
55
106
|
};
|
|
107
|
+
this.onImageMouseUp = () => {
|
|
108
|
+
this.foundation.handleImageMouseUp();
|
|
109
|
+
};
|
|
56
110
|
this.state = {
|
|
57
111
|
width: 0,
|
|
58
112
|
height: 0,
|
|
@@ -66,7 +120,7 @@ class PreviewImage extends _baseComponent.default {
|
|
|
66
120
|
left: 0
|
|
67
121
|
};
|
|
68
122
|
this.containerRef = /*#__PURE__*/_react.default.createRef();
|
|
69
|
-
this.imageRef =
|
|
123
|
+
this.imageRef = null;
|
|
70
124
|
this.foundation = new _previewImageFoundation.default(this.adapter);
|
|
71
125
|
}
|
|
72
126
|
componentDidMount() {
|
|
@@ -77,23 +131,28 @@ class PreviewImage extends _baseComponent.default {
|
|
|
77
131
|
}
|
|
78
132
|
componentDidUpdate(prevProps, prevStates) {
|
|
79
133
|
// If src changes, start a new loading
|
|
80
|
-
|
|
81
|
-
const srcChange = this.props.src && this.props.src !== prevProps.src;
|
|
82
|
-
if (srcChange) {
|
|
134
|
+
if (this.props.src && this.props.src !== prevProps.src) {
|
|
83
135
|
this.foundation.setLoading(true);
|
|
84
136
|
}
|
|
85
137
|
// If the incoming zoom changes, other content changes are determined based on the new zoom value
|
|
86
|
-
if (
|
|
87
|
-
this.
|
|
138
|
+
if ("zoom" in this.props && this.props.zoom !== prevStates.currZoom) {
|
|
139
|
+
this.handleZoomChange(this.props.zoom, null);
|
|
88
140
|
}
|
|
89
|
-
if
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
141
|
+
// When the incoming ratio is changed, if it"s adaptation, then resizeImage is triggered to make the image adapt to the page
|
|
142
|
+
// else if it"s adaptation is realSize, then onZoom(1) is called to make the image size the original size;
|
|
143
|
+
if ("ratio" in this.props && this.props.ratio !== prevProps.ratio) {
|
|
144
|
+
if (originImageWidth && originImageHeight) {
|
|
145
|
+
if (this.props.ratio === "adaptation") {
|
|
146
|
+
this.resizeImage();
|
|
147
|
+
} else {
|
|
148
|
+
this.props.onZoom(1);
|
|
149
|
+
}
|
|
95
150
|
}
|
|
96
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
|
+
}
|
|
97
156
|
}
|
|
98
157
|
render() {
|
|
99
158
|
const {
|
|
@@ -114,20 +173,21 @@ class PreviewImage extends _baseComponent.default {
|
|
|
114
173
|
transform: `rotate(${-rotation}deg)`,
|
|
115
174
|
top,
|
|
116
175
|
left,
|
|
117
|
-
width
|
|
118
|
-
height
|
|
176
|
+
width: loading ? "auto" : `${width}px`,
|
|
177
|
+
height: loading ? "auto" : `${height}px`
|
|
119
178
|
};
|
|
120
179
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
121
180
|
className: `${preViewImgPrefixCls}`,
|
|
122
181
|
ref: this.containerRef
|
|
123
182
|
}, /*#__PURE__*/_react.default.createElement("img", {
|
|
124
|
-
ref: this.
|
|
183
|
+
ref: this.registryImageRef,
|
|
125
184
|
src: src,
|
|
126
185
|
alt: "previewImag",
|
|
127
186
|
className: `${preViewImgPrefixCls}-img`,
|
|
128
187
|
key: src,
|
|
129
188
|
onMouseMove: this.handleMoveImage,
|
|
130
189
|
onMouseDown: this.onImageMouseDown,
|
|
190
|
+
onMouseUp: this.onImageMouseUp,
|
|
131
191
|
onContextMenu: this.handleRightClickImage,
|
|
132
192
|
onDragStart: e => e.preventDefault(),
|
|
133
193
|
onLoad: this.handleLoad,
|
|
@@ -145,9 +205,9 @@ PreviewImage.propTypes = {
|
|
|
145
205
|
src: _propTypes.default.string,
|
|
146
206
|
rotation: _propTypes.default.number,
|
|
147
207
|
style: _propTypes.default.object,
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
208
|
+
maxZoom: _propTypes.default.number,
|
|
209
|
+
minZoom: _propTypes.default.number,
|
|
210
|
+
zoomStep: _propTypes.default.number,
|
|
151
211
|
zoom: _propTypes.default.number,
|
|
152
212
|
ratio: _propTypes.default.string,
|
|
153
213
|
disableDownload: _propTypes.default.bool,
|
|
@@ -158,8 +218,8 @@ PreviewImage.propTypes = {
|
|
|
158
218
|
onError: _propTypes.default.func
|
|
159
219
|
};
|
|
160
220
|
PreviewImage.defaultProps = {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
221
|
+
maxZoom: 5,
|
|
222
|
+
minZoom: 0.1,
|
|
223
|
+
zoomStep: 0.1,
|
|
164
224
|
zoom: undefined
|
|
165
225
|
};
|
|
@@ -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
|
}
|