@macive/ui 0.0.24 → 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.
@@ -32,13 +32,44 @@ const FileViewer = (props) => {
32
32
  };
33
33
  exports.FileViewer = FileViewer;
34
34
  const FileTypeDisplayTitle = ({ file, children }) => {
35
- const truncateString = (str = 'file') => {
36
- if (str === null || str === undefined || typeof str !== 'string') {
35
+ // Extract file name from URL or use provided fileName
36
+ const getFileName = (file) => {
37
+ if (!file)
37
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
+ }
38
53
  }
39
- return str.length > 9 ? `${str.substring(0, 1)}...${str.substring(str.length - 10)}` : str;
54
+ return 'file';
40
55
  };
41
- return ((0, jsx_runtime_1.jsx)("div", { className: FileViewer_classnames_1.default['file-type-title'], children: children !== null && children !== void 0 ? children : truncateString(file === null || file === void 0 ? void 0 : file.fileName) }));
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 });
42
73
  };
43
74
  const FileTypeDisplay = ({ disabled, file, children, className }) => {
44
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 }));