@douyinfe/semi-ui 2.50.0-alpha.0 → 2.50.0-beta.0

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