@macive/ui 0.0.24 → 0.0.26
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/Image/Image.js +3 -4
- package/dist/src/components/Upload/components/FileViewer/FileViewer.js +35 -4
- package/dist/src/components/Upload/components/Modal/UploadModalFileItem.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/components/Image/Image.d.ts +1 -1
- package/dist/types/src/components/Image/Image.d.ts.map +1 -1
- package/dist/types/src/components/Upload/components/Modal/UploadModalFileItem.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -23,17 +23,16 @@ const errorkSVG = `
|
|
|
23
23
|
</svg>
|
|
24
24
|
`;
|
|
25
25
|
const fallbackImageURL = `data:image/svg+xml;utf8,${encodeURIComponent(fallbackSVG)}`;
|
|
26
|
-
function Image({ alt, sourceSet, source, crossOrigin, onLoad, onError, className, rounded, lazy = true, // Default to
|
|
26
|
+
function Image({ alt, sourceSet, source, crossOrigin, onLoad, onError, className, rounded, lazy = true, // Default to true
|
|
27
27
|
style, ...rest }) {
|
|
28
28
|
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
29
|
-
const [imgSrc, setImgSrc] = (0, react_1.useState)(lazy ?
|
|
29
|
+
const [imgSrc, setImgSrc] = (0, react_1.useState)(lazy ? null : source); // Use null instead of '' for lazy loading
|
|
30
30
|
const [isInView, setIsInView] = (0, react_1.useState)(!lazy); // Assume visible if not lazy
|
|
31
31
|
const imgRef = (0, react_1.useRef)(null);
|
|
32
32
|
// Intersection Observer for lazy loading
|
|
33
33
|
(0, react_1.useEffect)(() => {
|
|
34
34
|
if (!lazy)
|
|
35
35
|
return;
|
|
36
|
-
// Store the current ref value in a variable
|
|
37
36
|
const currentImgRef = imgRef.current;
|
|
38
37
|
if (!currentImgRef)
|
|
39
38
|
return;
|
|
@@ -96,7 +95,7 @@ style, ...rest }) {
|
|
|
96
95
|
};
|
|
97
96
|
return (
|
|
98
97
|
// eslint-disable-next-line @next/next/no-img-element
|
|
99
|
-
(0, jsx_runtime_1.jsx)("img", { ...rest, ref: imgRef, alt: alt, src: imgSrc, style: combinedStyle, crossOrigin: crossOrigin, srcSet: sourceSet === null || sourceSet === void 0 ? void 0 : sourceSet.map(({ source, descriptor }) => `${source} ${descriptor || ''}`).join(', '), className: className, loading: lazy ? 'lazy' : 'eager', onError: (e) => {
|
|
98
|
+
(0, jsx_runtime_1.jsx)("img", { ...rest, ref: imgRef, alt: alt, src: imgSrc !== null && imgSrc !== void 0 ? imgSrc : undefined, style: combinedStyle, crossOrigin: crossOrigin, srcSet: sourceSet === null || sourceSet === void 0 ? void 0 : sourceSet.map(({ source, descriptor }) => `${source} ${descriptor || ''}`).join(', '), className: className, loading: lazy ? 'lazy' : 'eager', onError: (e) => {
|
|
100
99
|
e.currentTarget.src = fallbackImageURL; // Set fallback SVG on error
|
|
101
100
|
setIsLoading(false);
|
|
102
101
|
onError === null || onError === void 0 ? void 0 : onError();
|
|
@@ -32,13 +32,44 @@ const FileViewer = (props) => {
|
|
|
32
32
|
};
|
|
33
33
|
exports.FileViewer = FileViewer;
|
|
34
34
|
const FileTypeDisplayTitle = ({ file, children }) => {
|
|
35
|
-
|
|
36
|
-
|
|
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
|
|
54
|
+
return 'file';
|
|
40
55
|
};
|
|
41
|
-
|
|
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 }));
|