dtable-ui-component 5.1.11 → 5.1.12

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.
@@ -12,6 +12,10 @@
12
12
  border: 1px solid #f0f0f0;
13
13
  }
14
14
 
15
+ .dtable-ui.file-formatter .file-item-icon.img {
16
+ width: fit-content;
17
+ }
18
+
15
19
  .dtable-ui.file-formatter .file-item-count {
16
20
  display: inline-block;
17
21
  padding: 0 3px;
@@ -8,22 +8,18 @@ exports.default = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _utils = require("./utils");
10
10
  class FileItemFormatter extends _react.Component {
11
- constructor() {
12
- super(...arguments);
13
- this.getFileIconData = item => {
14
- let fileIconUrl = (0, _utils.getFileIconUrl)(item.name, item.type);
15
- let fileIconData = require('./' + fileIconUrl);
16
- return fileIconData;
17
- };
18
- }
19
11
  render() {
20
12
  const {
21
13
  file
22
14
  } = this.props;
15
+ const {
16
+ fileIconUrl,
17
+ isImage
18
+ } = (0, _utils.getFileThumbnailInfo)(file);
23
19
  return /*#__PURE__*/_react.default.createElement("img", {
24
- className: "file-item-icon",
25
- src: this.getFileIconData(file),
26
- alt: file.name
20
+ className: "file-item-icon ".concat(isImage ? 'img' : ''),
21
+ src: fileIconUrl,
22
+ alt: (file === null || file === void 0 ? void 0 : file.name) || ''
27
23
  });
28
24
  }
29
25
  }
@@ -3,7 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getFileIconUrl = void 0;
6
+ exports.imageCheck = exports.getFileThumbnailInfo = exports.getFileIconUrl = void 0;
7
+ var _utils = require("../ImageFormatter/utils");
7
8
  const FILEEXT_ICON_MAP = {
8
9
  // text file
9
10
  md: 'txt.png',
@@ -52,6 +53,26 @@ const FILEEXT_ICON_MAP = {
52
53
  // default
53
54
  default: 'file.png'
54
55
  };
56
+ const getFileThumbnailInfo = fileItem => {
57
+ let fileIconUrl;
58
+ let isImage;
59
+ if (!fileItem.name) {
60
+ fileIconUrl = FILEEXT_ICON_MAP['default'];
61
+ isImage = false;
62
+ } else {
63
+ isImage = imageCheck(fileItem.name);
64
+ if (isImage) {
65
+ fileIconUrl = (0, _utils.getImageThumbnailUrl)(fileItem.url);
66
+ } else {
67
+ fileIconUrl = require('./' + getFileIconUrl(fileItem.name, fileItem.type));
68
+ }
69
+ }
70
+ return {
71
+ fileIconUrl,
72
+ isImage
73
+ };
74
+ };
75
+ exports.getFileThumbnailInfo = getFileThumbnailInfo;
55
76
  const getFileIconUrl = (filename, direntType) => {
56
77
  if (typeof direntType === 'string' && direntType === 'dir') {
57
78
  return 'assets/folder/' + FILEEXT_ICON_MAP['folder'];
@@ -64,4 +85,15 @@ const getFileIconUrl = (filename, direntType) => {
64
85
  const iconUrl = FILEEXT_ICON_MAP[file_ext] ? 'assets/file/192/' + FILEEXT_ICON_MAP[file_ext] : 'assets/file/192/' + FILEEXT_ICON_MAP['default'];
65
86
  return iconUrl;
66
87
  };
67
- exports.getFileIconUrl = getFileIconUrl;
88
+ exports.getFileIconUrl = getFileIconUrl;
89
+ const imageCheck = filename => {
90
+ // no file ext
91
+ if (!filename || typeof filename !== 'string') return false;
92
+ if (filename.lastIndexOf('.') === -1) {
93
+ return false;
94
+ }
95
+ const file_ext = filename.substr(filename.lastIndexOf('.') + 1).toLowerCase();
96
+ const image_exts = ['gif', 'jpeg', 'jpg', 'png', 'ico', 'bmp', 'tif', 'tiff', 'webp'];
97
+ return image_exts.includes(file_ext);
98
+ };
99
+ exports.imageCheck = imageCheck;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtable-ui-component",
3
- "version": "5.1.11",
3
+ "version": "5.1.12",
4
4
  "main": "./lib/index.js",
5
5
  "dependencies": {
6
6
  "@seafile/react-image-lightbox": "2.0.5",