dtable-ui-component 5.2.3 → 5.2.4
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/lib/FileItemFormatter/utils.js +2 -2
- package/lib/ImageFormatter/images-lazy-load.js +4 -2
- package/lib/ImageFormatter/index.js +2 -2
- package/lib/ImageFormatter/utils.js +1 -14
- package/lib/ImagePreviewerLightbox/index.css +8 -0
- package/lib/ImagePreviewerLightbox/index.js +60 -26
- package/lib/utils/url.js +91 -0
- package/package.json +2 -3
- package/lib/ImagePreviewerLightbox/utils.js +0 -17
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.imageCheck = exports.getFileThumbnailInfo = exports.getFileIconUrl = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _url = require("../utils/url");
|
|
8
8
|
const FILEEXT_ICON_MAP = {
|
|
9
9
|
// text file
|
|
10
10
|
md: 'txt.png',
|
|
@@ -62,7 +62,7 @@ const getFileThumbnailInfo = fileItem => {
|
|
|
62
62
|
} else {
|
|
63
63
|
isImage = imageCheck(fileItem.name);
|
|
64
64
|
if (isImage) {
|
|
65
|
-
fileIconUrl = (0,
|
|
65
|
+
fileIconUrl = (0, _url.getImageThumbnailUrl)(fileItem.url);
|
|
66
66
|
} else {
|
|
67
67
|
fileIconUrl = require('./' + getFileIconUrl(fileItem.name, fileItem.type));
|
|
68
68
|
}
|
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _Loading = _interopRequireDefault(require("../Loading"));
|
|
11
|
-
var
|
|
11
|
+
var _url = require("../utils/url");
|
|
12
12
|
class ImagesLazyLoad extends _react.default.Component {
|
|
13
13
|
constructor(_props) {
|
|
14
14
|
super(_props);
|
|
@@ -42,7 +42,9 @@ class ImagesLazyLoad extends _react.default.Component {
|
|
|
42
42
|
server
|
|
43
43
|
} = this.props;
|
|
44
44
|
images.forEach((item, index) => {
|
|
45
|
-
let url = (0,
|
|
45
|
+
let url = (0, _url.getImageThumbnailUrl)(item, {
|
|
46
|
+
server
|
|
47
|
+
});
|
|
46
48
|
this.lazyLoadImage(url, image => {
|
|
47
49
|
let {
|
|
48
50
|
loadedCount,
|
|
@@ -9,8 +9,8 @@ exports.default = void 0;
|
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
11
11
|
var _imagesLazyLoad = _interopRequireDefault(require("./images-lazy-load"));
|
|
12
|
-
var _utils = require("./utils");
|
|
13
12
|
var _ImagePreviewerLightbox = _interopRequireDefault(require("../ImagePreviewerLightbox"));
|
|
13
|
+
var _url = require("../utils/url");
|
|
14
14
|
require("./index.css");
|
|
15
15
|
class ImageFormatter extends _react.default.Component {
|
|
16
16
|
constructor(props) {
|
|
@@ -79,7 +79,7 @@ class ImageFormatter extends _react.default.Component {
|
|
|
79
79
|
}
|
|
80
80
|
if (isSample) {
|
|
81
81
|
let item = value[0];
|
|
82
|
-
let url = (0,
|
|
82
|
+
let url = (0, _url.getImageThumbnailUrl)(item, server);
|
|
83
83
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
84
84
|
className: className
|
|
85
85
|
}, /*#__PURE__*/_react.default.createElement("img", {
|
|
@@ -1,14 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getImageThumbnailUrl = void 0;
|
|
7
|
-
const getImageThumbnailUrl = (url, server) => {
|
|
8
|
-
if (typeof url !== 'string') return '';
|
|
9
|
-
if (server && url.indexOf(server) > -1) {
|
|
10
|
-
return url.replace('/workspace', '/thumbnail/workspace') + '?size=256';
|
|
11
|
-
}
|
|
12
|
-
return url;
|
|
13
|
-
};
|
|
14
|
-
exports.getImageThumbnailUrl = getImageThumbnailUrl;
|
|
1
|
+
"use strict";
|
|
@@ -8,45 +8,83 @@ exports.default = void 0;
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
10
|
var _reactImageLightbox = _interopRequireDefault(require("@seafile/react-image-lightbox"));
|
|
11
|
-
var
|
|
11
|
+
var _url = require("../utils/url");
|
|
12
12
|
var _lang = require("../lang");
|
|
13
13
|
require("@seafile/react-image-lightbox/style.css");
|
|
14
|
+
require("./index.css");
|
|
14
15
|
function ImagePreviewerLightbox(props) {
|
|
15
16
|
const {
|
|
16
17
|
imageItems,
|
|
17
18
|
imageIndex,
|
|
18
|
-
deleteImage,
|
|
19
|
-
downloadImage,
|
|
20
|
-
onRotateImage,
|
|
21
19
|
readOnly,
|
|
20
|
+
className,
|
|
22
21
|
server,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
workspaceID,
|
|
23
|
+
dtableUuid,
|
|
24
|
+
deleteImage,
|
|
25
|
+
downloadImage,
|
|
26
|
+
onRotateImage
|
|
26
27
|
} = props;
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const imageSrcList = imageItems.map(src => {
|
|
29
|
+
if (server && dtableUuid && (0, _url.isCustomAssetUrl)(src)) {
|
|
30
|
+
const assetUuid = src.slice(src.lastIndexOf('/') + 1, src.lastIndexOf('.'));
|
|
31
|
+
return server + '/dtable/' + dtableUuid + '/custom-asset/' + assetUuid;
|
|
32
|
+
}
|
|
33
|
+
if (server && dtableUuid && workspaceID && (0, _url.isDigitalSignsUrl)(src)) {
|
|
34
|
+
return (0, _url.generateCurrentBaseImageUrl)({
|
|
35
|
+
server,
|
|
36
|
+
workspaceID,
|
|
37
|
+
dtableUuid,
|
|
38
|
+
partUrl: src
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return src;
|
|
42
|
+
});
|
|
43
|
+
const imagesLength = imageSrcList.length;
|
|
44
|
+
const URL = imageSrcList[imageIndex];
|
|
45
|
+
|
|
46
|
+
// Handle URL has special symbol %$
|
|
47
|
+
let imageName = '';
|
|
48
|
+
try {
|
|
49
|
+
imageName = URL ? decodeURI(URL.slice(URL.lastIndexOf('/') + 1)) : '';
|
|
50
|
+
} catch (error) {
|
|
51
|
+
// eslint-disable-next-line no-console
|
|
52
|
+
console.log(error);
|
|
53
|
+
}
|
|
54
|
+
|
|
30
55
|
// svg image is vectorgraph and can't rotate, external image can't rotate
|
|
31
|
-
const canRotateImage = onRotateImage && !readOnly && !(0,
|
|
32
|
-
|
|
56
|
+
const canRotateImage = onRotateImage && !readOnly && !(0, _url.checkSVGImage)(URL) && (0, _url.isInternalImg)(URL, server);
|
|
57
|
+
let mainSrc = URL;
|
|
58
|
+
if ((0, _url.needUseThumbnailImage)(URL)) {
|
|
59
|
+
mainSrc = (0, _url.getImageThumbnailUrl)(URL, {
|
|
60
|
+
server,
|
|
61
|
+
dtableUuid,
|
|
62
|
+
workspaceID,
|
|
63
|
+
size: 512
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const imageTitleDOM = props.imageTitle || /*#__PURE__*/_react.default.createElement("span", {
|
|
33
67
|
className: "d-flex"
|
|
34
68
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
35
69
|
className: "text-truncate"
|
|
36
|
-
},
|
|
37
|
-
className: "flex-shrink-0"
|
|
38
|
-
}, "(", imageIndex + 1, "/",
|
|
70
|
+
}, imageName), /*#__PURE__*/_react.default.createElement("span", {
|
|
71
|
+
className: "flex-shrink-0 pl-1"
|
|
72
|
+
}, "(", imageIndex + 1, "/", imagesLength, ")"));
|
|
39
73
|
return /*#__PURE__*/_react.default.createElement(_reactImageLightbox.default, {
|
|
40
74
|
wrapperClassName: (0, _classnames.default)('dtable-ui-component', className),
|
|
41
|
-
imageTitle:
|
|
42
|
-
mainSrc:
|
|
43
|
-
nextSrc:
|
|
44
|
-
prevSrc:
|
|
75
|
+
imageTitle: imageTitleDOM,
|
|
76
|
+
mainSrc: mainSrc,
|
|
77
|
+
nextSrc: imageSrcList[(imageIndex + 1) % imagesLength],
|
|
78
|
+
prevSrc: imageSrcList[(imageIndex + imagesLength - 1) % imagesLength],
|
|
79
|
+
imagePadding: 70,
|
|
80
|
+
viewOriginalImageLabel: (0, _lang.getLocale)('View_original_image'),
|
|
81
|
+
enableRotate: canRotateImage,
|
|
45
82
|
onCloseRequest: props.closeImagePopup,
|
|
46
83
|
onMovePrevRequest: props.moveToPrevImage,
|
|
47
84
|
onMoveNextRequest: props.moveToNextImage,
|
|
48
|
-
onClickMoveUp: moveToPrevRowImage,
|
|
49
|
-
onClickMoveDown: moveToNextRowImage,
|
|
85
|
+
onClickMoveUp: props.moveToPrevRowImage,
|
|
86
|
+
onClickMoveDown: props.moveToNextRowImage,
|
|
87
|
+
onViewOriginal: props.onViewOriginal,
|
|
50
88
|
onRotateImage: canRotateImage ? deg => {
|
|
51
89
|
onRotateImage(imageIndex, deg);
|
|
52
90
|
} : null,
|
|
@@ -55,11 +93,7 @@ function ImagePreviewerLightbox(props) {
|
|
|
55
93
|
} : null,
|
|
56
94
|
onClickDownload: downloadImage ? () => {
|
|
57
95
|
downloadImage(URL);
|
|
58
|
-
} : null
|
|
59
|
-
imagePadding: 70,
|
|
60
|
-
onViewOriginal: props.onViewOriginal,
|
|
61
|
-
viewOriginalImageLabel: (0, _lang.getLocale)('View_original_image'),
|
|
62
|
-
enableRotate: canRotateImage
|
|
96
|
+
} : null
|
|
63
97
|
});
|
|
64
98
|
}
|
|
65
99
|
var _default = exports.default = ImagePreviewerLightbox;
|
package/lib/utils/url.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.needUseThumbnailImage = exports.isTargetUrl = exports.isInternalImg = exports.isDigitalSignsUrl = exports.isCustomAssetUrl = exports.getImageThumbnailUrl = exports.generateCurrentBaseImageUrl = exports.generateCurrentBaseImageThumbnailUrl = exports.checkSVGImage = void 0;
|
|
7
|
+
const isTargetUrl = (target, url) => {
|
|
8
|
+
if (!url || typeof url !== 'string') return false;
|
|
9
|
+
return target && url ? url.indexOf(target) > -1 : false;
|
|
10
|
+
};
|
|
11
|
+
exports.isTargetUrl = isTargetUrl;
|
|
12
|
+
const isInternalImg = (url, server) => {
|
|
13
|
+
if (!url || typeof url !== 'string') return false;
|
|
14
|
+
const currentServer = server || window.dtable && window.dtable.server;
|
|
15
|
+
return url.indexOf(currentServer) > -1;
|
|
16
|
+
};
|
|
17
|
+
exports.isInternalImg = isInternalImg;
|
|
18
|
+
const isCustomAssetUrl = url => {
|
|
19
|
+
return isTargetUrl('custom-asset://', url);
|
|
20
|
+
};
|
|
21
|
+
exports.isCustomAssetUrl = isCustomAssetUrl;
|
|
22
|
+
const checkSVGImage = url => {
|
|
23
|
+
if (!url || typeof url !== 'string') return false;
|
|
24
|
+
const isSVGImage = url.substring(url.lastIndexOf('.')).toLowerCase() === '.svg';
|
|
25
|
+
return isSVGImage;
|
|
26
|
+
};
|
|
27
|
+
exports.checkSVGImage = checkSVGImage;
|
|
28
|
+
const isDigitalSignsUrl = url => {
|
|
29
|
+
if (!url || typeof url !== 'string') return false;
|
|
30
|
+
return isTargetUrl('/digital-signs/', url) && !url.includes('http');
|
|
31
|
+
};
|
|
32
|
+
exports.isDigitalSignsUrl = isDigitalSignsUrl;
|
|
33
|
+
const needUseThumbnailImage = url => {
|
|
34
|
+
if (!url || typeof url !== 'string' || url.lastIndexOf('.') === -1) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const image_suffix = url.substring(url.lastIndexOf('.') + 1).toLowerCase();
|
|
38
|
+
const suffix = ['bmp', 'tif', 'tiff'];
|
|
39
|
+
return suffix.includes(image_suffix);
|
|
40
|
+
};
|
|
41
|
+
exports.needUseThumbnailImage = needUseThumbnailImage;
|
|
42
|
+
const generateCurrentBaseImageThumbnailUrl = _ref => {
|
|
43
|
+
let {
|
|
44
|
+
server,
|
|
45
|
+
workspaceID,
|
|
46
|
+
dtableUuid,
|
|
47
|
+
partUrl,
|
|
48
|
+
size
|
|
49
|
+
} = _ref;
|
|
50
|
+
if (!partUrl || typeof partUrl !== 'string') return '';
|
|
51
|
+
return "".concat(server, "/thumbnail/workspace/").concat(workspaceID, "/asset/").concat(dtableUuid).concat(partUrl, "?size=").concat(size);
|
|
52
|
+
};
|
|
53
|
+
exports.generateCurrentBaseImageThumbnailUrl = generateCurrentBaseImageThumbnailUrl;
|
|
54
|
+
const generateCurrentBaseImageUrl = _ref2 => {
|
|
55
|
+
let {
|
|
56
|
+
server,
|
|
57
|
+
workspaceID,
|
|
58
|
+
dtableUuid,
|
|
59
|
+
partUrl
|
|
60
|
+
} = _ref2;
|
|
61
|
+
if (!partUrl || typeof partUrl !== 'string') return '';
|
|
62
|
+
return "".concat(server, "/workspace/").concat(workspaceID, "/asset/").concat(dtableUuid).concat(partUrl);
|
|
63
|
+
};
|
|
64
|
+
exports.generateCurrentBaseImageUrl = generateCurrentBaseImageUrl;
|
|
65
|
+
const getImageThumbnailUrl = function (url) {
|
|
66
|
+
let {
|
|
67
|
+
server,
|
|
68
|
+
dtableUuid,
|
|
69
|
+
workspaceID,
|
|
70
|
+
size = 256
|
|
71
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
72
|
+
if (!url || typeof url !== 'string') return '';
|
|
73
|
+
if (server && dtableUuid && isCustomAssetUrl(url)) {
|
|
74
|
+
const assetUuid = url.slice(url.lastIndexOf('/') + 1, url.lastIndexOf('.'));
|
|
75
|
+
return server + '/dtable/' + dtableUuid + '/custom-asset-thumbnail/' + assetUuid + '?size=' + size;
|
|
76
|
+
}
|
|
77
|
+
if (server && workspaceID && dtableUuid && isDigitalSignsUrl(url)) {
|
|
78
|
+
return generateCurrentBaseImageThumbnailUrl({
|
|
79
|
+
server,
|
|
80
|
+
workspaceID,
|
|
81
|
+
dtableUuid,
|
|
82
|
+
size,
|
|
83
|
+
partUrl: url
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (checkSVGImage(url) || !isInternalImg(url)) {
|
|
87
|
+
return url;
|
|
88
|
+
}
|
|
89
|
+
return url.replace('/workspace', '/thumbnail/workspace') + '?size=' + size;
|
|
90
|
+
};
|
|
91
|
+
exports.getImageThumbnailUrl = getImageThumbnailUrl;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dtable-ui-component",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.4",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@seafile/react-image-lightbox": "3.0.1",
|
|
@@ -9,11 +9,10 @@
|
|
|
9
9
|
"antd-mobile": "2.3.1",
|
|
10
10
|
"classnames": "2.3.2",
|
|
11
11
|
"dayjs": "1.10.7",
|
|
12
|
-
"dtable-utils": "
|
|
12
|
+
"dtable-utils": "5.0.11",
|
|
13
13
|
"is-hotkey": "0.2.0",
|
|
14
14
|
"prop-types": "^15.8.1",
|
|
15
15
|
"react": "17.0.2",
|
|
16
|
-
"react-app-polyfill": "^3.0.0",
|
|
17
16
|
"react-dom": "17.0.2",
|
|
18
17
|
"react-responsive": "9.0.2",
|
|
19
18
|
"react-color": "2.19.3",
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isInternalImg = exports.checkSVGImage = void 0;
|
|
7
|
-
const isInternalImg = (url, server) => {
|
|
8
|
-
if (!url) return;
|
|
9
|
-
const currentServer = server || window.dtable && window.dtable.server;
|
|
10
|
-
return url.indexOf(currentServer) > -1;
|
|
11
|
-
};
|
|
12
|
-
exports.isInternalImg = isInternalImg;
|
|
13
|
-
const checkSVGImage = url => {
|
|
14
|
-
if (!url) return false;
|
|
15
|
-
return url.substr(-4).toLowerCase() === '.svg';
|
|
16
|
-
};
|
|
17
|
-
exports.checkSVGImage = checkSVGImage;
|