@macive/ui 0.0.23 → 0.0.25
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/dist/src/components/Upload/components/FileViewer/FileViewer.js +41 -6
- package/dist/src/components/Upload/components/Modal/UploadModalFileItem.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/components/Checkbox/Checkbox.d.ts +1 -1
- package/dist/types/src/components/Input/Input.d.ts +1 -1
- package/dist/types/src/components/Upload/components/FileViewer/FileViewer.d.ts.map +1 -1
- package/dist/types/src/components/Upload/components/Modal/UploadModalFileItem.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -12,6 +12,7 @@ const Image_1 = require("../../../Image");
|
|
|
12
12
|
const FileViewer_classnames_1 = __importDefault(require("./FileViewer.classnames"));
|
|
13
13
|
const VideoPlayer_1 = require("./VideoPlayer");
|
|
14
14
|
const FileViewer = (props) => {
|
|
15
|
+
var _a, _b;
|
|
15
16
|
const [imageSource, setImageSource] = (0, react_1.useState)();
|
|
16
17
|
const { file, disabled, previewable, legacyImage, unAcceptedType, className } = props;
|
|
17
18
|
const { type: fileType } = file || {};
|
|
@@ -22,19 +23,53 @@ const FileViewer = (props) => {
|
|
|
22
23
|
return (0, jsx_runtime_1.jsx)(VideoPlayer_1.VideoPlayer, { file: file, disabled: unAcceptedType });
|
|
23
24
|
}
|
|
24
25
|
if (fileType === 'archive') {
|
|
25
|
-
return ((0, jsx_runtime_1.jsxs)(FileTypeDisplay, { disabled: unAcceptedType, previewable: previewable, file: file, children: [
|
|
26
|
+
return ((0, jsx_runtime_1.jsxs)(FileTypeDisplay, { disabled: unAcceptedType, previewable: previewable, file: file, children: [(_a = file === null || file === void 0 ? void 0 : file.extension) !== null && _a !== void 0 ? _a : 'zip', (0, jsx_runtime_1.jsx)(FileTypeDisplayTitle, { file: file })] }));
|
|
26
27
|
}
|
|
27
28
|
if (fileType === 'document') {
|
|
28
|
-
return ((0, jsx_runtime_1.jsxs)(FileTypeDisplay, { disabled: unAcceptedType, previewable: previewable, file: file, children: [
|
|
29
|
+
return ((0, jsx_runtime_1.jsxs)(FileTypeDisplay, { disabled: unAcceptedType, previewable: previewable, file: file, children: [(_b = file === null || file === void 0 ? void 0 : file.extension) !== null && _b !== void 0 ? _b : 'pdf', (0, jsx_runtime_1.jsx)(FileTypeDisplayTitle, { file: file })] }));
|
|
29
30
|
}
|
|
30
31
|
return ((0, jsx_runtime_1.jsx)(FileTypeDisplay, { disabled: unAcceptedType, previewable: previewable, file: file, children: "media" }));
|
|
31
32
|
};
|
|
32
33
|
exports.FileViewer = FileViewer;
|
|
33
34
|
const FileTypeDisplayTitle = ({ file, children }) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
// Extract file name from URL or use provided fileName
|
|
36
|
+
const getFileName = (file) => {
|
|
37
|
+
if (!file)
|
|
38
|
+
return 'file';
|
|
39
|
+
// Use fileName if provided
|
|
40
|
+
if (file.fileName)
|
|
41
|
+
return file.fileName;
|
|
42
|
+
// Extract file name from src URL
|
|
43
|
+
if (file.src) {
|
|
44
|
+
try {
|
|
45
|
+
const url = new URL(file.src);
|
|
46
|
+
const pathSegments = url.pathname.split('/');
|
|
47
|
+
const extractedName = pathSegments[pathSegments.length - 1];
|
|
48
|
+
return extractedName || 'file';
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return 'file';
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return 'file';
|
|
55
|
+
};
|
|
56
|
+
const truncateString = (str) => {
|
|
57
|
+
// If string is empty or not a string, return 'file'
|
|
58
|
+
if (!str || typeof str !== 'string')
|
|
59
|
+
return 'file';
|
|
60
|
+
// Adjust truncation to show more meaningful part of the file name
|
|
61
|
+
const maxLength = 20; // Increased to show more characters
|
|
62
|
+
if (str.length <= maxLength)
|
|
63
|
+
return str;
|
|
64
|
+
const extension = str.includes('.') ? str.split('.').pop() : '';
|
|
65
|
+
const nameWithoutExt = str.replace(`.${extension}`, '');
|
|
66
|
+
const truncatePoint = maxLength - (extension ? extension.length + 1 : 0) - 3; // Account for '...' and extension
|
|
67
|
+
if (truncatePoint <= 0)
|
|
68
|
+
return str; // Avoid negative or zero truncation point
|
|
69
|
+
return `${nameWithoutExt.substring(0, truncatePoint)}...${extension ? `.${extension}` : ''}`;
|
|
70
|
+
};
|
|
71
|
+
const displayName = truncateString(getFileName(file));
|
|
72
|
+
return (0, jsx_runtime_1.jsx)("div", { className: FileViewer_classnames_1.default['file-type-title'], children: children !== null && children !== void 0 ? children : displayName });
|
|
38
73
|
};
|
|
39
74
|
const FileTypeDisplay = ({ disabled, file, children, className }) => {
|
|
40
75
|
return ((0, jsx_runtime_1.jsx)("div", { className: (0, utils_1.cn)(FileViewer_classnames_1.default['file-type-display'], disabled && FileViewer_classnames_1.default.disabled, className), children: children || `${file === null || file === void 0 ? void 0 : file.extension} File` }));
|
|
@@ -36,7 +36,7 @@ const UploadModalFileItem = ({ selectedAttachments = [], file, onClick, allowedF
|
|
|
36
36
|
setIcon((0, jsx_runtime_1.jsx)(Icon_1.Icon, { source: Icons_1.MaError }));
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
-
return ((0, jsx_runtime_1.jsx)(Box_1.Box, { borderRadius: '3', borderWidth: '1', borderBlockEndWidth: '5', borderColor: 'border', children: (0, jsx_runtime_1.jsx)("div", { className: UploadModalFileItem_classnames_1.default['upload-modal-file-item'], children: (0, jsx_runtime_1.jsxs)("div", { className: UploadModalFileItem_classnames_1.default['file-item-container'], onClick: !disabled ? onClick : undefined, children: [(0, jsx_runtime_1.jsx)("div", { className: UploadModalFileItem_classnames_1.default.fileActionsCard, children: (0, jsx_runtime_1.jsx)(Box_1.Box, { borderRadius: '2', padding: '1', children: (0, jsx_runtime_1.jsx)(HorizontalStack_1.HorizontalStack, { gap: '1', align: 'space-between', blockAlign: 'center', children: (0, jsx_runtime_1.jsxs)("div", { className: UploadModalFileItem_classnames_1.default['file-actions'], children: [(0, jsx_runtime_1.jsxs)(HorizontalStack_1.HorizontalStack, { gap: '1', blockAlign: 'center', wrap: false, children: [(0, jsx_runtime_1.jsx)(ActionButton, { onClick: () => handleCopyClick(file.url), icon: icon }), (0, jsx_runtime_1.jsx)(ActionButton, { onClick: () => window.open(file.url, '_blank'), icon: (0, jsx_runtime_1.jsx)(Icon_1.Icon, { source: Icons_1.MaEyes }) })] }), (0, jsx_runtime_1.jsx)(FileCheckbox, { checked: isSelected, disabled: disabled })] }) }) }) }), (0, jsx_runtime_1.jsx)(FileViewer_1.FileViewer, { file: file, disabled: disabled, unAcceptedType: unAcceptedType }), (0, jsx_runtime_1.jsx)(CheckedOverlay, { checked: isSelected, checkedNumber: checkedNumber, maxAttachments: maxAttachments })] }) }) }));
|
|
39
|
+
return ((0, jsx_runtime_1.jsx)(Box_1.Box, { borderRadius: '3', borderWidth: '1', borderBlockEndWidth: '5', borderColor: 'border', children: (0, jsx_runtime_1.jsx)("div", { className: UploadModalFileItem_classnames_1.default['upload-modal-file-item'], style: { height: '100%' }, children: (0, jsx_runtime_1.jsxs)("div", { className: UploadModalFileItem_classnames_1.default['file-item-container'], style: { height: '100%' }, onClick: !disabled ? onClick : undefined, children: [(0, jsx_runtime_1.jsx)("div", { className: UploadModalFileItem_classnames_1.default.fileActionsCard, children: (0, jsx_runtime_1.jsx)(Box_1.Box, { borderRadius: '2', padding: '1', children: (0, jsx_runtime_1.jsx)(HorizontalStack_1.HorizontalStack, { gap: '1', align: 'space-between', blockAlign: 'center', children: (0, jsx_runtime_1.jsxs)("div", { className: UploadModalFileItem_classnames_1.default['file-actions'], children: [(0, jsx_runtime_1.jsxs)(HorizontalStack_1.HorizontalStack, { gap: '1', blockAlign: 'center', wrap: false, children: [(0, jsx_runtime_1.jsx)(ActionButton, { onClick: () => handleCopyClick(file.url), icon: icon }), (0, jsx_runtime_1.jsx)(ActionButton, { onClick: () => window.open(file.url, '_blank'), icon: (0, jsx_runtime_1.jsx)(Icon_1.Icon, { source: Icons_1.MaEyes }) })] }), (0, jsx_runtime_1.jsx)(FileCheckbox, { checked: isSelected, disabled: disabled })] }) }) }) }), (0, jsx_runtime_1.jsx)(FileViewer_1.FileViewer, { file: file, disabled: disabled, unAcceptedType: unAcceptedType }), (0, jsx_runtime_1.jsx)(CheckedOverlay, { checked: isSelected, checkedNumber: checkedNumber, maxAttachments: maxAttachments })] }) }) }));
|
|
40
40
|
};
|
|
41
41
|
const ActionButton = ({ onClick, icon }) => ((0, jsx_runtime_1.jsx)(Button_1.Button, { plain: true, size: 'slim', monochrome: true, icon: icon, onClick: onClick }));
|
|
42
42
|
const FileCheckbox = ({ checked, disabled }) => ((0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, { label: 'checkbox', labelHidden: true, checked: checked, readOnly: true, disabled: disabled }));
|