dtable-ui-component 4.4.30 → 4.4.31

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.
@@ -63,20 +63,22 @@ class SimpleLongTextFormatter extends _react.default.Component {
63
63
  }
64
64
  return {};
65
65
  };
66
- this.clearTimer = () => {
67
- if (this.timer) {
68
- clearTimeout(this.timer);
69
- this.timer = null;
70
- }
66
+ this.clearOpenPreviewTimer = () => {
67
+ if (!this.openPreviewTimer) return;
68
+ clearTimeout(this.openPreviewTimer);
69
+ this.openPreviewTimer = null;
70
+ };
71
+ this.clearClosePreviewTimer = () => {
72
+ if (!this.closePreviewTimer) return;
73
+ clearTimeout(this.closePreviewTimer);
74
+ this.closePreviewTimer = null;
71
75
  };
72
76
  this.onMouseEnter = () => {
73
77
  // in case that there is no `modal-wrapper`
74
- if (!document.getElementById('modal-wrapper')) {
75
- return;
76
- }
77
- this.clearTimer();
78
+ if (!document.getElementById('modal-wrapper')) return;
79
+ this.clearOpenPreviewTimer();
78
80
  if (this.props.value) {
79
- this.timer = setTimeout(() => {
81
+ this.openPreviewTimer = setTimeout(() => {
80
82
  const style = this.ref.getBoundingClientRect();
81
83
  this.formatterStyle = style;
82
84
  this.setState({
@@ -86,7 +88,23 @@ class SimpleLongTextFormatter extends _react.default.Component {
86
88
  }
87
89
  };
88
90
  this.onMouseLeave = () => {
89
- this.clearTimer();
91
+ this.clearOpenPreviewTimer();
92
+
93
+ // Case 1: The mouse moves out of the cell and is not in the preview component, close the preview component after 2S
94
+ this.closePreviewTimer = setTimeout(() => {
95
+ if (this.state.isPreview) {
96
+ this.setState({
97
+ isPreview: false
98
+ });
99
+ }
100
+ }, 2000);
101
+ };
102
+ // Case 2: The mouse moves out of the cell and into the preview component, do not close the preview component
103
+ this.onPreviewMouseEnter = () => {
104
+ this.clearClosePreviewTimer();
105
+ };
106
+ // Case 2: The mouse move out of the preview component, close the preview component
107
+ this.onPreviewMouseLeave = () => {
90
108
  if (this.state.isPreview) {
91
109
  this.setState({
92
110
  isPreview: false
@@ -99,7 +117,8 @@ class SimpleLongTextFormatter extends _react.default.Component {
99
117
  };
100
118
  }
101
119
  componentWillUnmount() {
102
- this.clearTimer();
120
+ this.clearOpenPreviewTimer();
121
+ this.clearClosePreviewTimer();
103
122
  }
104
123
  render() {
105
124
  const {
@@ -119,7 +138,9 @@ class SimpleLongTextFormatter extends _react.default.Component {
119
138
  }, this.renderLinks(value), this.renderCheckList(value), this.renderImages(value), this.renderContent(value), isPreview && /*#__PURE__*/_react.default.createElement(_ModalPortal.default, null, /*#__PURE__*/_react.default.createElement(_LongTextPreview.default, {
120
139
  className: previewClassName,
121
140
  value: value,
122
- formatterStyle: this.formatterStyle
141
+ formatterStyle: this.formatterStyle,
142
+ onMouseEnter: this.onPreviewMouseEnter,
143
+ onMouseLeave: this.onPreviewMouseLeave
123
144
  })));
124
145
  }
125
146
  }
@@ -20,8 +20,11 @@ class LongTextPreview extends _react.default.PureComponent {
20
20
  left,
21
21
  top
22
22
  } = formatterStyle;
23
+ const {
24
+ height,
25
+ opacity
26
+ } = this.state;
23
27
  const width = 520;
24
- const height = this.state.height;
25
28
  const padding = 6;
26
29
  left = left - width > 0 ? left - width - 12 : 0;
27
30
  top = top - padding;
@@ -31,9 +34,15 @@ class LongTextPreview extends _react.default.PureComponent {
31
34
  return {
32
35
  left,
33
36
  top,
34
- opacity: this.state.opacity
37
+ opacity
35
38
  };
36
39
  };
40
+ this.onMouseEnter = e => {
41
+ this.props.onMouseEnter && this.props.onMouseEnter(e);
42
+ };
43
+ this.onMouseLeave = e => {
44
+ this.props.onMouseLeave && this.props.onMouseLeave(e);
45
+ };
37
46
  this.state = {
38
47
  height: 450,
39
48
  opacity: 0
@@ -41,13 +50,23 @@ class LongTextPreview extends _react.default.PureComponent {
41
50
  }
42
51
  componentDidMount() {
43
52
  setTimeout(() => {
53
+ var _value$images;
44
54
  if (!this.ref) return;
45
- const domHeight = this.ref.offsetHeight;
55
+ const {
56
+ value
57
+ } = this.props;
58
+
59
+ // If image is included, sets the preview height to the maximum height
60
+ const hasImage = (value === null || value === void 0 ? void 0 : (_value$images = value.images) === null || _value$images === void 0 ? void 0 : _value$images.length) >= 2 ? true : false;
61
+ let {
62
+ height: domHeight
63
+ } = this.ref.getBoundingClientRect();
64
+ domHeight = hasImage ? 450 : domHeight;
46
65
  this.setState({
47
- height: domHeight,
66
+ height: Math.min(domHeight, 450),
48
67
  opacity: 1
49
68
  });
50
- }, 0);
69
+ }, 10);
51
70
  }
52
71
  render() {
53
72
  const {
@@ -58,7 +77,9 @@ class LongTextPreview extends _react.default.PureComponent {
58
77
  return /*#__PURE__*/_react.default.createElement("div", {
59
78
  className: (0, _classnames.default)('longtext-modal-dialog longtext-preview', className),
60
79
  style: this.getStyle(),
61
- ref: ref => this.ref = ref
80
+ ref: ref => this.ref = ref,
81
+ onMouseEnter: this.onMouseEnter,
82
+ onMouseLeave: this.onMouseLeave
62
83
  }, /*#__PURE__*/_react.default.createElement("div", {
63
84
  className: "longtext-container longtext-container-scroll"
64
85
  }, /*#__PURE__*/_react.default.createElement(_dtableMarkdownViewer.default, {
@@ -339,10 +339,12 @@
339
339
 
340
340
  .longtext-preview .sf-slate-viewer-scroll-container .sf-slate-viewer-article-container {
341
341
  width: 100%;
342
+ margin: 0;
342
343
  }
343
344
 
344
345
  .longtext-preview .longtext-container .article {
345
346
  padding: 10px 16px;
347
+ border: unset;
346
348
  }
347
349
 
348
350
  .row-height-128 .longtext-formatter .article {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtable-ui-component",
3
- "version": "4.4.30",
3
+ "version": "4.4.31",
4
4
  "main": "./lib/index.js",
5
5
  "dependencies": {
6
6
  "@seafile/react-image-lightbox": "2.0.5",