@topconsultnpm/sdkui-react-beta 6.14.114 → 6.14.115
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.
|
@@ -105,6 +105,60 @@ const TMDcmtPreview = ({ dcmtData, isResizingActive, isVisible, canNext, canPrev
|
|
|
105
105
|
: renderedPreview(dcmtData?.tid, dcmtData?.did, dcmtData?.fileExt, dcmtData?.fileSize, dcmtData?.fileCount, extensionHandler(dcmtData?.fileExt), showPreview, isResizingActive, () => { loadDocumentWithCache(); setShowPreview(true); }, dcmtBlob) }) }));
|
|
106
106
|
};
|
|
107
107
|
export default TMDcmtPreview;
|
|
108
|
+
// export const TMFileViewer: React.FC<ITMFileViewerProps> = ({ fileBlob, isResizingActive }) => {
|
|
109
|
+
// const [blobUrl, setBlobUrl] = useState<string | undefined>(undefined);
|
|
110
|
+
// const [fileType, setFileType] = useState<string | undefined>(undefined);
|
|
111
|
+
// const [formattedXml, setFormattedXml] = useState<string | undefined>(undefined);
|
|
112
|
+
// useEffect(() => {
|
|
113
|
+
// if (fileBlob) {
|
|
114
|
+
// const url = URL.createObjectURL(fileBlob);
|
|
115
|
+
// setBlobUrl(url);
|
|
116
|
+
// setFileType(fileBlob.type);
|
|
117
|
+
// if (fileBlob.type.includes("xml")) {
|
|
118
|
+
// fileBlob.text().then((text) => {
|
|
119
|
+
// const parser = new DOMParser();
|
|
120
|
+
// const xmlDoc = parser.parseFromString(text, "application/xml");
|
|
121
|
+
// if (xmlDoc.querySelector("parsererror")) {
|
|
122
|
+
// setFormattedXml(`<div style="color: red;">Invalid XML</div>`);
|
|
123
|
+
// return;
|
|
124
|
+
// }
|
|
125
|
+
// const serializer = new XMLSerializer();
|
|
126
|
+
// const prettyXml = serializer
|
|
127
|
+
// .serializeToString(xmlDoc)
|
|
128
|
+
// .replace(/></g, ">\n<")
|
|
129
|
+
// .replace(/^(?!\s*$)/gm, " ");
|
|
130
|
+
// setFormattedXml(
|
|
131
|
+
// `<pre style="font-family: monospace; white-space: pre-wrap; line-height: 1.5;">${prettyXml
|
|
132
|
+
// .replace(/</g, "<")
|
|
133
|
+
// .replace(/>/g, ">")}</pre>`
|
|
134
|
+
// );
|
|
135
|
+
// });
|
|
136
|
+
// }
|
|
137
|
+
// return () => {
|
|
138
|
+
// URL.revokeObjectURL(url);
|
|
139
|
+
// };
|
|
140
|
+
// }
|
|
141
|
+
// return () => { }
|
|
142
|
+
// }, [fileBlob]);
|
|
143
|
+
// if (!fileBlob) {
|
|
144
|
+
// return <div>{`${SDKUI_Localizator.FileUpload}...`}</div>;
|
|
145
|
+
// }
|
|
146
|
+
// if (fileBlob.type.includes('image')) {
|
|
147
|
+
// return (
|
|
148
|
+
// <ImageViewer fileBlob={fileBlob} alt='' />
|
|
149
|
+
// )
|
|
150
|
+
// }
|
|
151
|
+
// return (
|
|
152
|
+
// <iframe
|
|
153
|
+
// srcDoc={fileType?.includes("xml") && formattedXml ? `<html><body>${formattedXml}</body></html>` : undefined}
|
|
154
|
+
// src={!fileType?.includes("xml") || !formattedXml ? blobUrl : undefined}
|
|
155
|
+
// title="File Viewer"
|
|
156
|
+
// width="100%"
|
|
157
|
+
// height="100%"
|
|
158
|
+
// style={{ border: 'none', zIndex: 0, pointerEvents: isResizingActive === true ? "none" : "auto" }}
|
|
159
|
+
// />
|
|
160
|
+
// );
|
|
161
|
+
// };
|
|
108
162
|
export const TMFileViewer = ({ fileBlob, isResizingActive }) => {
|
|
109
163
|
const [blobUrl, setBlobUrl] = useState(undefined);
|
|
110
164
|
const [fileType, setFileType] = useState(undefined);
|
|
@@ -114,6 +168,7 @@ export const TMFileViewer = ({ fileBlob, isResizingActive }) => {
|
|
|
114
168
|
const url = URL.createObjectURL(fileBlob);
|
|
115
169
|
setBlobUrl(url);
|
|
116
170
|
setFileType(fileBlob.type);
|
|
171
|
+
setFormattedXml(undefined); // Reset XML when blob changes
|
|
117
172
|
if (fileBlob.type.includes("xml")) {
|
|
118
173
|
fileBlob.text().then((text) => {
|
|
119
174
|
const parser = new DOMParser();
|
|
@@ -136,6 +191,11 @@ export const TMFileViewer = ({ fileBlob, isResizingActive }) => {
|
|
|
136
191
|
URL.revokeObjectURL(url);
|
|
137
192
|
};
|
|
138
193
|
}
|
|
194
|
+
else {
|
|
195
|
+
setBlobUrl(undefined);
|
|
196
|
+
setFileType(undefined);
|
|
197
|
+
setFormattedXml(undefined);
|
|
198
|
+
}
|
|
139
199
|
return () => { };
|
|
140
200
|
}, [fileBlob]);
|
|
141
201
|
if (!fileBlob) {
|
|
@@ -144,6 +204,34 @@ export const TMFileViewer = ({ fileBlob, isResizingActive }) => {
|
|
|
144
204
|
if (fileBlob.type.includes('image')) {
|
|
145
205
|
return (_jsx(ImageViewer, { fileBlob: fileBlob, alt: '' }));
|
|
146
206
|
}
|
|
207
|
+
if (fileType === 'application/pdf') {
|
|
208
|
+
return (_jsx("div", { style: { width: '100%', height: '100%', position: 'relative' }, children: _jsx("object", { data: blobUrl, type: "application/pdf", width: "100%", height: "100%", style: { border: 'none' }, children: _jsxs("div", { style: {
|
|
209
|
+
padding: '40px',
|
|
210
|
+
textAlign: 'center',
|
|
211
|
+
display: 'flex',
|
|
212
|
+
flexDirection: 'column',
|
|
213
|
+
alignItems: 'center',
|
|
214
|
+
justifyContent: 'center',
|
|
215
|
+
height: '100%',
|
|
216
|
+
gap: '20px'
|
|
217
|
+
}, children: [_jsx(IconPreview, { fontSize: 96 }), _jsxs("div", { children: [_jsx("h3", { children: "Documento PDF" }), _jsx("p", { children: "Anteprima non disponibile in questo despositivo. Clicca per visualizzare il documento." })] }), _jsxs("div", { style: { display: 'flex', gap: '10px', flexWrap: 'wrap', alignItems: 'center', justifyContent: 'center' }, children: [_jsx("a", { href: blobUrl, download: "document.pdf", style: {
|
|
218
|
+
minWidth: '180px',
|
|
219
|
+
padding: '12px 24px',
|
|
220
|
+
backgroundColor: TMColors.primaryColor,
|
|
221
|
+
color: 'white',
|
|
222
|
+
textDecoration: 'none',
|
|
223
|
+
borderRadius: '4px',
|
|
224
|
+
display: 'inline-block'
|
|
225
|
+
}, children: "Scarica PDF" }), _jsx("a", { href: blobUrl, target: "_blank", rel: "noopener noreferrer", style: {
|
|
226
|
+
minWidth: '180px',
|
|
227
|
+
padding: '12px 24px',
|
|
228
|
+
backgroundColor: '#6c757d',
|
|
229
|
+
color: 'white',
|
|
230
|
+
textDecoration: 'none',
|
|
231
|
+
borderRadius: '4px',
|
|
232
|
+
display: 'inline-block'
|
|
233
|
+
}, children: "Apri in nuova scheda" })] })] }) }) }));
|
|
234
|
+
}
|
|
147
235
|
return (_jsx("iframe", { srcDoc: fileType?.includes("xml") && formattedXml ? `<html><body>${formattedXml}</body></html>` : undefined, src: !fileType?.includes("xml") || !formattedXml ? blobUrl : undefined, title: "File Viewer", width: "100%", height: "100%", style: { border: 'none', zIndex: 0, pointerEvents: isResizingActive === true ? "none" : "auto" } }));
|
|
148
236
|
};
|
|
149
237
|
const ImageViewer = ({ fileBlob, alt = 'Image', className }) => {
|