@topconsultnpm/sdkui-react 6.20.0-dev1.26 → 6.20.0-dev1.27
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/lib/helper/TMPdfViewer.js +17 -14
- package/package.json +1 -1
|
@@ -9,15 +9,27 @@ import { TMColors } from "../utils/theme";
|
|
|
9
9
|
let pdfjs;
|
|
10
10
|
let Document;
|
|
11
11
|
let Page;
|
|
12
|
+
let isReactPdfAvailable = false;
|
|
12
13
|
try {
|
|
13
14
|
const reactPdf = require('react-pdf');
|
|
14
15
|
pdfjs = reactPdf.pdfjs;
|
|
15
16
|
Document = reactPdf.Document;
|
|
16
17
|
Page = reactPdf.Page;
|
|
18
|
+
isReactPdfAvailable = true;
|
|
19
|
+
// Configura il worker PDF.js PRIMA del rendering
|
|
20
|
+
if (pdfjs && !pdfjs.GlobalWorkerOptions.workerSrc) {
|
|
21
|
+
try {
|
|
22
|
+
pdfjs.GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/build/pdf.worker.min.mjs', import.meta.url).toString();
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
console.warn('Worker PDF.js locale non disponibile, uso CDN fallback');
|
|
26
|
+
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.min.js`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
17
29
|
}
|
|
18
30
|
catch (error) {
|
|
19
|
-
// react-pdf not available
|
|
20
|
-
// console.warn('react-pdf is not installed. TMPdfViewer will use iframe fallback
|
|
31
|
+
// react-pdf not available - will use iframe fallback
|
|
32
|
+
// console.warn('react-pdf is not installed. TMPdfViewer will use iframe fallback.');
|
|
21
33
|
}
|
|
22
34
|
const PDFViewerContainer = styled.div `
|
|
23
35
|
width: 100%;
|
|
@@ -76,16 +88,6 @@ const TMPdfViewer = (props) => {
|
|
|
76
88
|
(window.matchMedia?.('(hover: none) and (pointer: coarse)').matches ?? false) ||
|
|
77
89
|
// Touch-capable devices excluding desktop OS
|
|
78
90
|
(navigator.maxTouchPoints > 1 && !/Win|Mac|Linux x86_64/i.test(userAgent));
|
|
79
|
-
// Configura il worker PDF.js solo per mobile (react-pdf)
|
|
80
|
-
if (isMobileDevice && !pdfjs.GlobalWorkerOptions.workerSrc) {
|
|
81
|
-
try {
|
|
82
|
-
pdfjs.GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/build/pdf.worker.min.mjs', import.meta.url).toString();
|
|
83
|
-
}
|
|
84
|
-
catch (error) {
|
|
85
|
-
console.warn('Worker PDF.js locale non disponibile, uso CDN fallback');
|
|
86
|
-
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.min.js`;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
91
|
setIsMobile(isMobileDevice);
|
|
90
92
|
};
|
|
91
93
|
checkIsMobile();
|
|
@@ -139,8 +141,8 @@ const TMPdfViewer = (props) => {
|
|
|
139
141
|
observerRef.current?.disconnect();
|
|
140
142
|
};
|
|
141
143
|
}, [pageObserverCallback]);
|
|
142
|
-
// Use iframe
|
|
143
|
-
if (!isMobile && pdfUrl) {
|
|
144
|
+
// Use iframe se react-pdf non è disponibile O se è desktop
|
|
145
|
+
if (!isReactPdfAvailable || (!isMobile && pdfUrl)) {
|
|
144
146
|
return (_jsx(PDFViewerContainer, { children: _jsx("iframe", { src: `${pdfUrl}#${enableFitToWidth ? 'view=FitH&' : ''}scrollbar=1`, title: title, style: {
|
|
145
147
|
width: '100%',
|
|
146
148
|
height: '100%',
|
|
@@ -149,6 +151,7 @@ const TMPdfViewer = (props) => {
|
|
|
149
151
|
pointerEvents: isResizingActive === true ? "none" : "auto"
|
|
150
152
|
} }, pdfUrl) }));
|
|
151
153
|
}
|
|
154
|
+
// Usa react-pdf solo per mobile e solo se disponibile
|
|
152
155
|
return _jsxs(PDFViewerContainer, { children: [loadedPagesNumber === 0 && totalPagesNumber > 0 && _jsx(LoadingOverlay, { children: _jsxs("div", { style: {
|
|
153
156
|
display: 'flex',
|
|
154
157
|
justifyContent: 'center',
|