dtable-ui-component 0.3.0 → 0.3.2
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.
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
@import url('../css/cell-formatter.css');
|
|
2
|
+
|
|
3
|
+
.dtable-ui.digital-sign-formatter {
|
|
4
|
+
display: flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.dtable-ui.digital-sign-formatter .image-item {
|
|
9
|
+
height: 100%;
|
|
10
|
+
margin-right: 4px;
|
|
11
|
+
border: 1px solid #f0f0f0;
|
|
12
|
+
background-color: #fff;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.dtable-ui.digital-sign-formatter .image-item:hover {
|
|
16
|
+
border: 1px solid #c9c9c9;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.digital-sign-formatter-image-previewer .ril__image {
|
|
20
|
+
background-color: #fff;
|
|
21
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
|
+
import React, { Component } from 'react';
|
|
6
|
+
import cn from 'astro-classname';
|
|
7
|
+
import ImagesLazyLoad from '../ImageFormatter/images-lazy-load';
|
|
8
|
+
import ImagePreviewerLightbox from '../ImagePreviewerLightbox';
|
|
9
|
+
import { getDigitalSignImageUrl } from './utils';
|
|
10
|
+
import { downloadFile } from '../utils/utils';
|
|
11
|
+
import './index.css';
|
|
12
|
+
|
|
13
|
+
var DigitalSignFormatter = /*#__PURE__*/function (_Component) {
|
|
14
|
+
_inherits(DigitalSignFormatter, _Component);
|
|
15
|
+
|
|
16
|
+
var _super = _createSuper(DigitalSignFormatter);
|
|
17
|
+
|
|
18
|
+
function DigitalSignFormatter(props) {
|
|
19
|
+
var _this;
|
|
20
|
+
|
|
21
|
+
_classCallCheck(this, DigitalSignFormatter);
|
|
22
|
+
|
|
23
|
+
_this = _super.call(this, props);
|
|
24
|
+
|
|
25
|
+
_this.getSignImages = function () {
|
|
26
|
+
var _this$props = _this.props,
|
|
27
|
+
value = _this$props.value,
|
|
28
|
+
config = _this$props.config;
|
|
29
|
+
return [getDigitalSignImageUrl(value, config)].filter(Boolean);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
_this.onClickSignImage = function (index) {
|
|
33
|
+
if (!_this.props.isSupportPreview) return;
|
|
34
|
+
|
|
35
|
+
_this.setState({
|
|
36
|
+
isPreviewSignImage: true,
|
|
37
|
+
largeSignImageIndex: index
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
_this.hideLargeSignImage = function () {
|
|
42
|
+
if (!_this.props.isSupportPreview) return;
|
|
43
|
+
|
|
44
|
+
if (_this.props.onCloseCallback) {
|
|
45
|
+
_this.props.onCloseCallback();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
_this.setState({
|
|
49
|
+
isPreviewSignImage: false,
|
|
50
|
+
largeSignImageIndex: -1
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
_this.downloadImage = function (url) {
|
|
55
|
+
var availableUrl = url;
|
|
56
|
+
var rotateIndex = availableUrl.indexOf('?a=');
|
|
57
|
+
|
|
58
|
+
if (rotateIndex > -1) {
|
|
59
|
+
availableUrl = availableUrl.slice(0, rotateIndex);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
var urlSuffix = availableUrl.indexOf('?dl=1');
|
|
63
|
+
var downloadUrl = urlSuffix !== -1 ? availableUrl : availableUrl + '?dl=1';
|
|
64
|
+
downloadFile(downloadUrl);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
_this.state = {
|
|
68
|
+
isPreviewSignImage: false,
|
|
69
|
+
largeSignImageIndex: -1
|
|
70
|
+
};
|
|
71
|
+
return _this;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
_createClass(DigitalSignFormatter, [{
|
|
75
|
+
key: "render",
|
|
76
|
+
value: function render() {
|
|
77
|
+
var _this$props2 = this.props,
|
|
78
|
+
containerClassName = _this$props2.containerClassName,
|
|
79
|
+
readOnly = _this$props2.readOnly,
|
|
80
|
+
config = _this$props2.config,
|
|
81
|
+
isSample = _this$props2.isSample;
|
|
82
|
+
var className = cn('dtable-ui cell-formatter-container digital-sign-formatter', containerClassName);
|
|
83
|
+
var signImages = this.getSignImages();
|
|
84
|
+
if (signImages.length === 0) return null;
|
|
85
|
+
var _this$state = this.state,
|
|
86
|
+
isPreviewSignImage = _this$state.isPreviewSignImage,
|
|
87
|
+
largeSignImageIndex = _this$state.largeSignImageIndex;
|
|
88
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
89
|
+
className: className
|
|
90
|
+
}, /*#__PURE__*/React.createElement(ImagesLazyLoad, {
|
|
91
|
+
images: signImages,
|
|
92
|
+
server: config.server,
|
|
93
|
+
onImageClick: this.onClickSignImage
|
|
94
|
+
})), isPreviewSignImage && /*#__PURE__*/React.createElement(ImagePreviewerLightbox, {
|
|
95
|
+
className: "digital-sign-formatter-image-previewer",
|
|
96
|
+
readOnly: readOnly,
|
|
97
|
+
server: isSample ? config.server : '',
|
|
98
|
+
imageItems: signImages,
|
|
99
|
+
imageIndex: largeSignImageIndex,
|
|
100
|
+
closeImagePopup: this.hideLargeSignImage,
|
|
101
|
+
downloadImage: this.downloadImage,
|
|
102
|
+
moveToPrevImage: function moveToPrevImage() {},
|
|
103
|
+
moveToNextImage: function moveToNextImage() {}
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
}]);
|
|
107
|
+
|
|
108
|
+
return DigitalSignFormatter;
|
|
109
|
+
}(Component);
|
|
110
|
+
|
|
111
|
+
DigitalSignFormatter.defaultProps = {
|
|
112
|
+
isSample: false,
|
|
113
|
+
isSupportPreview: false,
|
|
114
|
+
readOnly: true,
|
|
115
|
+
value: '',
|
|
116
|
+
config: {},
|
|
117
|
+
containerClassName: ''
|
|
118
|
+
};
|
|
119
|
+
export default DigitalSignFormatter;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export var getDigitalSignImageUrl = function getDigitalSignImageUrl(cellValue, config) {
|
|
2
|
+
if (!cellValue) return '';
|
|
3
|
+
var url = cellValue && cellValue.sign_image_url || '';
|
|
4
|
+
if (!url) return '';
|
|
5
|
+
if (!config) return url;
|
|
6
|
+
|
|
7
|
+
var _ref = config || {},
|
|
8
|
+
server = _ref.server,
|
|
9
|
+
workspaceID = _ref.workspaceID,
|
|
10
|
+
dtableUuid = _ref.dtableUuid;
|
|
11
|
+
|
|
12
|
+
if (server && (workspaceID || workspaceID === 0) && dtableUuid) {
|
|
13
|
+
return "".concat(server, "/workspace/").concat(workspaceID, "/asset/").concat(dtableUuid).concat(url);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return url;
|
|
17
|
+
};
|
|
18
|
+
export var isValidDigitalSignImageValue = function isValidDigitalSignImageValue(cellValue) {
|
|
19
|
+
if (!cellValue) return false;
|
|
20
|
+
var digitalSignImage = cellValue && cellValue.sign_image_url;
|
|
21
|
+
if (!digitalSignImage) return false;
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { Fragment } from 'react';
|
|
2
2
|
import MediaQuery from 'react-responsive';
|
|
3
|
+
import cn from 'astro-classname';
|
|
3
4
|
import ModalPortal from '../ModalPortal';
|
|
4
5
|
import Lightbox from '@seafile/react-image-lightbox';
|
|
5
6
|
import { checkSVGImage, isInternalImg } from './utils';
|
|
@@ -15,7 +16,8 @@ function ImagePreviewerLightbox(props) {
|
|
|
15
16
|
readOnly = props.readOnly,
|
|
16
17
|
server = props.server,
|
|
17
18
|
moveToPrevRowImage = props.moveToPrevRowImage,
|
|
18
|
-
moveToNextRowImage = props.moveToNextRowImage
|
|
19
|
+
moveToNextRowImage = props.moveToNextRowImage,
|
|
20
|
+
className = props.className;
|
|
19
21
|
var imageItemsLength = imageItems.length;
|
|
20
22
|
var URL = imageItems[imageIndex];
|
|
21
23
|
var imageTitle = URL ? decodeURI(URL.slice(URL.lastIndexOf('/') + 1)) : ''; // svg image is vectorgraph and can't rotate, external image can't rotate
|
|
@@ -69,7 +71,7 @@ function ImagePreviewerLightbox(props) {
|
|
|
69
71
|
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(MediaQuery, {
|
|
70
72
|
query: "(min-width: 767.8px)"
|
|
71
73
|
}, /*#__PURE__*/React.createElement(Lightbox, {
|
|
72
|
-
wrapperClassName:
|
|
74
|
+
wrapperClassName: cn('PC-image-previewer', className),
|
|
73
75
|
imageTitle: imageTitleEl,
|
|
74
76
|
toolbarButtons: toolbarButtons,
|
|
75
77
|
mainSrc: imageItems[imageIndex],
|
|
@@ -91,7 +93,7 @@ function ImagePreviewerLightbox(props) {
|
|
|
91
93
|
query: "(max-width: 767.8px)"
|
|
92
94
|
}, /*#__PURE__*/React.createElement(Lightbox, {
|
|
93
95
|
isDesktop: false,
|
|
94
|
-
wrapperClassName:
|
|
96
|
+
wrapperClassName: cn('mobile-image-previewer dtable-ui-component', className),
|
|
95
97
|
mainSrc: imageItems[imageIndex],
|
|
96
98
|
nextSrc: imageItems[(imageIndex + 1) % imageItemsLength],
|
|
97
99
|
prevSrc: imageItems[(imageIndex + imageItemsLength - 1) % imageItemsLength],
|
package/lib/index.js
CHANGED
|
@@ -32,7 +32,8 @@ export { default as RateFormatter } from './RateFormatter';
|
|
|
32
32
|
export { default as ButtonFormatter } from './ButtonFormatter';
|
|
33
33
|
export { default as ImagePreviewerLightbox } from './ImagePreviewerLightbox';
|
|
34
34
|
export { default as CollaboratorItem } from './CollaboratorItem';
|
|
35
|
-
export { default as FileItemFormatter } from './FileItemFormatter';
|
|
35
|
+
export { default as FileItemFormatter } from './FileItemFormatter';
|
|
36
|
+
export { default as DigitalSignFormatter } from './DigitalSignFormatter'; // editor
|
|
36
37
|
|
|
37
38
|
export { default as TextEditor } from './TextEditor';
|
|
38
39
|
export { default as NumberEditor } from './NumberEditor';
|
package/lib/utils/utils.js
CHANGED
|
@@ -41,4 +41,17 @@ export var isMac = function isMac() {
|
|
|
41
41
|
var platform = navigator.platform; // eslint-disable-next-line eqeqeq
|
|
42
42
|
|
|
43
43
|
return platform == 'Mac68K' || platform == 'MacPPC' || platform == 'Macintosh' || platform == 'MacIntel';
|
|
44
|
+
};
|
|
45
|
+
export var downloadFile = function downloadFile(downloadUrl) {
|
|
46
|
+
var downloadFrame = document.getElementById('dtableUiComponentDownloadFrame');
|
|
47
|
+
|
|
48
|
+
if (downloadFrame != null) {
|
|
49
|
+
document.body.removeChild(downloadFrame);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
var iframe = document.createElement('iframe');
|
|
53
|
+
iframe.setAttribute('id', 'dtableUiComponentDownloadFrame');
|
|
54
|
+
iframe.style.display = 'none';
|
|
55
|
+
iframe.src = downloadUrl;
|
|
56
|
+
document.body.appendChild(iframe);
|
|
44
57
|
};
|