@progress/kendo-react-pdf-viewer 5.10.0-dev.202212231206 → 5.10.0-dev.202301051045
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/cdn/js/kendo-react-pdf-viewer.js +1 -1
- package/dist/es/PDFViewer.d.ts +1 -0
- package/dist/es/PDFViewer.js +66 -45
- package/dist/es/package-metadata.js +1 -1
- package/dist/es/scroller.d.ts +1 -1
- package/dist/es/scroller.js +2 -2
- package/dist/es/utils.d.ts +4 -1
- package/dist/es/utils.js +11 -11
- package/dist/npm/PDFViewer.d.ts +1 -0
- package/dist/npm/PDFViewer.js +66 -45
- package/dist/npm/package-metadata.js +1 -1
- package/dist/npm/scroller.d.ts +1 -1
- package/dist/npm/scroller.js +2 -2
- package/dist/npm/utils.d.ts +4 -1
- package/dist/npm/utils.js +11 -11
- package/dist/systemjs/kendo-react-pdf-viewer.js +1 -1
- package/package.json +2 -2
package/dist/es/PDFViewer.d.ts
CHANGED
package/dist/es/PDFViewer.js
CHANGED
|
@@ -25,20 +25,19 @@ const defaultProps = {
|
|
|
25
25
|
tools: [...toolNames],
|
|
26
26
|
zoomRate: 0.25,
|
|
27
27
|
zoomLevels: [
|
|
28
|
-
{ id: 1, value: 1, text: '
|
|
29
|
-
{ id: 2, value: 1, text: '
|
|
30
|
-
{ id: 3, value: 1, text: '
|
|
31
|
-
{ id: 4, value: 0.5, text: '50%', type: '' },
|
|
32
|
-
{ id: 5, value: 0.75, text: '75%', type: '' },
|
|
33
|
-
{ id: 6, value: 1, text: '100%', type: '' },
|
|
34
|
-
{ id: 7, value: 1.25, text: '125%', type: '' },
|
|
35
|
-
{ id: 8, value: 1.5, text: '150%', type: '' },
|
|
36
|
-
{ id: 9, value: 2, text: '200%', type: '' },
|
|
37
|
-
{ id: 10, value: 3, text: '300%', type: '' },
|
|
38
|
-
{ id: 11, value: 4, text: '400%', type: '' }
|
|
28
|
+
{ id: 1, priority: 1, value: 1, text: 'Actual width', type: 'ActualWidth', locationString: actualWidth },
|
|
29
|
+
{ id: 2, priority: 2, value: 1, text: 'Fit to width', type: 'FitToWidth', locationString: fitToWidth },
|
|
30
|
+
{ id: 3, priority: 3, value: 1, text: 'Fit to page', type: 'FitToPage', locationString: fitToPage },
|
|
31
|
+
{ id: 4, priority: 4, value: 0.5, text: '50%', type: '' },
|
|
32
|
+
{ id: 5, priority: 5, value: 0.75, text: '75%', type: '' },
|
|
33
|
+
{ id: 6, priority: 100, value: 1, text: '100%', type: '' },
|
|
34
|
+
{ id: 7, priority: 7, value: 1.25, text: '125%', type: '' },
|
|
35
|
+
{ id: 8, priority: 8, value: 1.5, text: '150%', type: '' },
|
|
36
|
+
{ id: 9, priority: 9, value: 2, text: '200%', type: '' },
|
|
37
|
+
{ id: 10, priority: 10, value: 3, text: '300%', type: '' },
|
|
38
|
+
{ id: 11, priority: 11, value: 4, text: '400%', type: '' }
|
|
39
39
|
],
|
|
40
|
-
defaultZoom:
|
|
41
|
-
defaultPage: 1
|
|
40
|
+
defaultZoom: DEFAULT_ZOOM_LEVEL
|
|
42
41
|
};
|
|
43
42
|
const navigation = [
|
|
44
43
|
'.k-toolbar > button',
|
|
@@ -47,6 +46,15 @@ const navigation = [
|
|
|
47
46
|
'.k-toolbar .k-pager > a',
|
|
48
47
|
'.k-toolbar .k-pager input'
|
|
49
48
|
];
|
|
49
|
+
const sortByPriority = (a, b) => {
|
|
50
|
+
if (a.priority > b.priority) {
|
|
51
|
+
return -1;
|
|
52
|
+
}
|
|
53
|
+
else if (a.priority < b.priority) {
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
return 0;
|
|
57
|
+
};
|
|
50
58
|
/**
|
|
51
59
|
* Represents the [KendoReact PDFViewer component]({% slug api_pdf-viewer_pdfviewerprops %}).
|
|
52
60
|
*/
|
|
@@ -57,7 +65,7 @@ export const PDFViewer = React.forwardRef((props, ref) => {
|
|
|
57
65
|
const pagesRef = React.useRef(null);
|
|
58
66
|
const [stateZoom, setStateZoom] = React.useState(defaultZoom);
|
|
59
67
|
const currentZoom = zoom !== undefined ? zoom : stateZoom;
|
|
60
|
-
const currentZoomLevel = zoomLevels.find(z => z.value === currentZoom) ||
|
|
68
|
+
const currentZoomLevel = zoomLevels.slice().sort(sortByPriority).find(z => z.value === currentZoom) ||
|
|
61
69
|
{ text: (currentZoom * 100) + '%', value: currentZoom, id: currentZoom, locationString: '' };
|
|
62
70
|
if (currentZoomLevel.locationString) {
|
|
63
71
|
currentZoomLevel.text = loc.toLanguageString(currentZoomLevel.locationString, messages[currentZoomLevel.locationString]);
|
|
@@ -73,6 +81,7 @@ export const PDFViewer = React.forwardRef((props, ref) => {
|
|
|
73
81
|
const [searchText, setSearchText] = React.useState('');
|
|
74
82
|
const refObj = React.useMemo(() => ({}), []);
|
|
75
83
|
refObj.currentZoom = currentZoom;
|
|
84
|
+
refObj.props = props;
|
|
76
85
|
const target = React.useRef(null);
|
|
77
86
|
const pdfViewerRef = React.useRef(null);
|
|
78
87
|
React.useImperativeHandle(target, () => ({
|
|
@@ -83,11 +92,11 @@ export const PDFViewer = React.forwardRef((props, ref) => {
|
|
|
83
92
|
}), []);
|
|
84
93
|
React.useImperativeHandle(ref, () => target.current);
|
|
85
94
|
const triggerOnLoad = React.useCallback(() => {
|
|
86
|
-
if (props.onLoad) {
|
|
95
|
+
if (refObj.props.onLoad) {
|
|
87
96
|
const loadEvent = { target: target.current };
|
|
88
|
-
props.onLoad.call(undefined, loadEvent);
|
|
97
|
+
refObj.props.onLoad.call(undefined, loadEvent);
|
|
89
98
|
}
|
|
90
|
-
}, [
|
|
99
|
+
}, []);
|
|
91
100
|
const triggerOnDownload = React.useCallback((blob, fileName, saveOptions) => {
|
|
92
101
|
if (props.onDownload) {
|
|
93
102
|
const downloadEvent = {
|
|
@@ -121,7 +130,7 @@ export const PDFViewer = React.forwardRef((props, ref) => {
|
|
|
121
130
|
charClass: 'k-text-char'
|
|
122
131
|
});
|
|
123
132
|
}, []);
|
|
124
|
-
|
|
133
|
+
refObj.done = React.useCallback(({ pdfPages, pdfDoc, zoom: documentZoom }) => {
|
|
125
134
|
refObj.document = pdfDoc;
|
|
126
135
|
refObj.pages = pdfPages;
|
|
127
136
|
refObj.zoom = documentZoom;
|
|
@@ -129,8 +138,11 @@ export const PDFViewer = React.forwardRef((props, ref) => {
|
|
|
129
138
|
setLoading(false);
|
|
130
139
|
setHasDocument(true);
|
|
131
140
|
triggerOnLoad();
|
|
141
|
+
if (pagesRef.current) {
|
|
142
|
+
scrollToPage(pagesRef.current, 0);
|
|
143
|
+
}
|
|
132
144
|
}, []);
|
|
133
|
-
|
|
145
|
+
refObj.error = React.useCallback((reason) => {
|
|
134
146
|
refObj.document = null;
|
|
135
147
|
refObj.pages = [];
|
|
136
148
|
setLoading(false);
|
|
@@ -143,7 +155,6 @@ export const PDFViewer = React.forwardRef((props, ref) => {
|
|
|
143
155
|
props.onError.call(undefined, errorEvent);
|
|
144
156
|
}
|
|
145
157
|
}, [props.onError]);
|
|
146
|
-
refObj.onError = error;
|
|
147
158
|
React.useEffect(() => {
|
|
148
159
|
if (pagesRef.current) {
|
|
149
160
|
if (props.url || props.data || props.arrayBuffer) {
|
|
@@ -155,8 +166,8 @@ export const PDFViewer = React.forwardRef((props, ref) => {
|
|
|
155
166
|
arrayBuffer: props.arrayBuffer,
|
|
156
167
|
dom: pagesRef.current,
|
|
157
168
|
zoom: refObj.currentZoom,
|
|
158
|
-
done,
|
|
159
|
-
error: refObj.
|
|
169
|
+
done: refObj.done,
|
|
170
|
+
error: refObj.error
|
|
160
171
|
});
|
|
161
172
|
}
|
|
162
173
|
else {
|
|
@@ -181,15 +192,25 @@ export const PDFViewer = React.forwardRef((props, ref) => {
|
|
|
181
192
|
refObj.zoom = zoomLev;
|
|
182
193
|
setLoading(false);
|
|
183
194
|
},
|
|
184
|
-
error
|
|
195
|
+
error: refObj.error
|
|
185
196
|
});
|
|
186
197
|
}
|
|
187
|
-
}, [
|
|
198
|
+
}, []);
|
|
188
199
|
React.useEffect(() => {
|
|
189
200
|
if (pagesRef.current && refObj.document && currentZoom !== refObj.zoom) {
|
|
190
201
|
reload(refObj.document, currentZoom);
|
|
191
202
|
}
|
|
192
203
|
}, [currentZoom, reload]);
|
|
204
|
+
React.useEffect(() => {
|
|
205
|
+
return () => {
|
|
206
|
+
refObj.scroller.destroy();
|
|
207
|
+
if (refObj.search) {
|
|
208
|
+
refObj.search.destroy();
|
|
209
|
+
}
|
|
210
|
+
refObj.document = null;
|
|
211
|
+
refObj.pages = [];
|
|
212
|
+
};
|
|
213
|
+
}, []);
|
|
193
214
|
const onSearch = React.useCallback(() => {
|
|
194
215
|
setShowSearch(true);
|
|
195
216
|
initSearch(pagesRef.current);
|
|
@@ -265,8 +286,8 @@ export const PDFViewer = React.forwardRef((props, ref) => {
|
|
|
265
286
|
}
|
|
266
287
|
}, [skip, props.onPageChange]);
|
|
267
288
|
const onZoomIn = React.useCallback((e) => {
|
|
268
|
-
const newZoom = Math.min(currentZoom + zoomRate, maxZoom);
|
|
269
|
-
if (newZoom !== currentZoom && refObj.document) {
|
|
289
|
+
const newZoom = Math.min(refObj.currentZoom + zoomRate, maxZoom);
|
|
290
|
+
if (newZoom !== refObj.currentZoom && refObj.document) {
|
|
270
291
|
setStateZoom(newZoom);
|
|
271
292
|
if (zoom === undefined) {
|
|
272
293
|
reload(refObj.document, newZoom);
|
|
@@ -280,10 +301,10 @@ export const PDFViewer = React.forwardRef((props, ref) => {
|
|
|
280
301
|
props.onZoom.call(undefined, zoomEvent);
|
|
281
302
|
}
|
|
282
303
|
}
|
|
283
|
-
}, [
|
|
304
|
+
}, [zoomRate, maxZoom, zoom, props.onZoom, reload]);
|
|
284
305
|
const onZoomOut = React.useCallback((e) => {
|
|
285
|
-
const newZoom = Math.max(
|
|
286
|
-
if (newZoom !==
|
|
306
|
+
const newZoom = Math.max(refObj.currentZoom - zoomRate, minZoom);
|
|
307
|
+
if (newZoom !== refObj.currentZoom && refObj.document) {
|
|
287
308
|
setStateZoom(newZoom);
|
|
288
309
|
if (zoom === undefined) {
|
|
289
310
|
reload(refObj.document, newZoom);
|
|
@@ -297,7 +318,7 @@ export const PDFViewer = React.forwardRef((props, ref) => {
|
|
|
297
318
|
props.onZoom.call(undefined, zoomEvent);
|
|
298
319
|
}
|
|
299
320
|
}
|
|
300
|
-
}, [
|
|
321
|
+
}, [zoomRate, minZoom, zoom, props.onZoom, reload]);
|
|
301
322
|
const onZoomLevelChange = React.useCallback((e) => {
|
|
302
323
|
const item = e.value === null ? { text: '100%', value: 1, id: 100 } : Object.assign({}, e.value);
|
|
303
324
|
if (item.value === undefined) {
|
|
@@ -309,8 +330,9 @@ export const PDFViewer = React.forwardRef((props, ref) => {
|
|
|
309
330
|
item.value = 1;
|
|
310
331
|
}
|
|
311
332
|
}
|
|
312
|
-
|
|
313
|
-
|
|
333
|
+
let newZoom = item ? calculateZoomLevel(item.value, item.type, refObj.currentZoom, pagesRef.current) : 1;
|
|
334
|
+
newZoom = Math.round(newZoom * 100) / 100;
|
|
335
|
+
if (refObj.currentZoom !== newZoom && refObj.document) {
|
|
314
336
|
setStateZoom(newZoom);
|
|
315
337
|
if (zoom === undefined) {
|
|
316
338
|
reload(refObj.document, newZoom);
|
|
@@ -324,7 +346,7 @@ export const PDFViewer = React.forwardRef((props, ref) => {
|
|
|
324
346
|
props.onZoom.call(undefined, zoomEvent);
|
|
325
347
|
}
|
|
326
348
|
}
|
|
327
|
-
}, [
|
|
349
|
+
}, [zoom, props.onZoom, reload]);
|
|
328
350
|
const onTextSelection = React.useCallback(() => {
|
|
329
351
|
refObj.scroller.disablePanEventsTracking();
|
|
330
352
|
setEnabledSelection(true);
|
|
@@ -335,22 +357,20 @@ export const PDFViewer = React.forwardRef((props, ref) => {
|
|
|
335
357
|
}, []);
|
|
336
358
|
const onDownload = React.useCallback(() => {
|
|
337
359
|
download({
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
arrayBuffer: props.arrayBuffer,
|
|
341
|
-
error
|
|
360
|
+
pdf: refObj.document,
|
|
361
|
+
error: refObj.error
|
|
342
362
|
}, props.saveFileName, props.saveOptions, triggerOnDownload);
|
|
343
|
-
}, [props.url, props.data, props.arrayBuffer,
|
|
363
|
+
}, [props.url, props.data, props.arrayBuffer, props.saveFileName, props.saveOptions, triggerOnDownload]);
|
|
344
364
|
const onPrint = React.useCallback(() => {
|
|
345
365
|
setLoading(true);
|
|
346
366
|
const onError = (e) => {
|
|
347
|
-
error(typeof (e ? e.message || e : null) === 'string' ? e.message || e : loc.toLanguageString(popupBlocked, messages[popupBlocked]));
|
|
367
|
+
refObj.error(typeof (e ? e.message || e : null) === 'string' ? e.message || e : loc.toLanguageString(popupBlocked, messages[popupBlocked]));
|
|
348
368
|
};
|
|
349
369
|
const onDone = () => {
|
|
350
370
|
setLoading(false);
|
|
351
371
|
};
|
|
352
372
|
print(refObj.pages, onDone, onError);
|
|
353
|
-
}, [
|
|
373
|
+
}, []);
|
|
354
374
|
const onAdd = React.useCallback((e) => {
|
|
355
375
|
const st = e.newState;
|
|
356
376
|
if (st[0] && st[0].getRawFile) {
|
|
@@ -359,18 +379,19 @@ export const PDFViewer = React.forwardRef((props, ref) => {
|
|
|
359
379
|
if (pagesRef.current) {
|
|
360
380
|
setLoading(true);
|
|
361
381
|
removeChildren(pagesRef.current);
|
|
382
|
+
const currentZoomValue = refObj.props.zoom === undefined ? defaultZoom : refObj.props.zoom;
|
|
362
383
|
loadPDF({
|
|
363
384
|
arrayBuffer,
|
|
364
385
|
dom: pagesRef.current,
|
|
365
|
-
zoom:
|
|
366
|
-
done,
|
|
367
|
-
error
|
|
386
|
+
zoom: currentZoomValue,
|
|
387
|
+
done: refObj.done,
|
|
388
|
+
error: refObj.error
|
|
368
389
|
});
|
|
369
|
-
setStateZoom(
|
|
390
|
+
setStateZoom(currentZoomValue);
|
|
370
391
|
}
|
|
371
392
|
});
|
|
372
393
|
}
|
|
373
|
-
}, [
|
|
394
|
+
}, [defaultZoom]);
|
|
374
395
|
const onFileOpen = React.useCallback((e) => {
|
|
375
396
|
const targetEl = e.target;
|
|
376
397
|
if (targetEl instanceof HTMLElement && targetEl.parentNode) {
|
|
@@ -5,7 +5,7 @@ export const packageMetadata = {
|
|
|
5
5
|
name: '@progress/kendo-react-pdf-viewer',
|
|
6
6
|
productName: 'KendoReact',
|
|
7
7
|
productCodes: ['KENDOUIREACT', 'KENDOUICOMPLETE'],
|
|
8
|
-
publishDate:
|
|
8
|
+
publishDate: 1672915293,
|
|
9
9
|
version: '',
|
|
10
10
|
licensingDocsUrl: 'https://www.telerik.com/kendo-react-ui/my-license/?utm_medium=product&utm_source=kendoreact&utm_campaign=kendo-ui-react-purchase-license-keys-warning'
|
|
11
11
|
};
|
package/dist/es/scroller.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare class Scroller {
|
|
|
24
24
|
disablePanEventsTracking(): void;
|
|
25
25
|
shouldTrackPanEvents(): any;
|
|
26
26
|
onElementScroll: () => void;
|
|
27
|
-
|
|
27
|
+
onDragStart: (e: any) => void;
|
|
28
28
|
onDrag: (e: any) => void;
|
|
29
29
|
onDragEnd: () => void;
|
|
30
30
|
calculateEventLocationDelta(e: any): void;
|
package/dist/es/scroller.js
CHANGED
|
@@ -82,7 +82,7 @@ export class Scroller {
|
|
|
82
82
|
this.state.trackNextElementScroll = true;
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
|
-
this.
|
|
85
|
+
this.onDragStart = (e) => {
|
|
86
86
|
this.state.dragStarted = false;
|
|
87
87
|
if (!this.shouldTrackPanEvents()) {
|
|
88
88
|
return;
|
|
@@ -143,7 +143,7 @@ export class Scroller {
|
|
|
143
143
|
}
|
|
144
144
|
this.draggable = new Draggable({
|
|
145
145
|
mouseOnly: false,
|
|
146
|
-
press: this.
|
|
146
|
+
press: this.onDragStart,
|
|
147
147
|
drag: this.throttledOnDrag,
|
|
148
148
|
release: this.onDragEnd
|
|
149
149
|
});
|
package/dist/es/utils.d.ts
CHANGED
|
@@ -48,7 +48,10 @@ export declare const DEFAULT_ZOOM_LEVEL = 1.25;
|
|
|
48
48
|
/**
|
|
49
49
|
* @hidden
|
|
50
50
|
*/
|
|
51
|
-
export declare const download: (options:
|
|
51
|
+
export declare const download: (options: {
|
|
52
|
+
pdf: PDFDocumentProxy | null;
|
|
53
|
+
error: ErrorFn;
|
|
54
|
+
}, fileName: string | undefined, saveOptions: SaveOptions | undefined, onDownload: (blob: Blob, fileName: string, saveOptions: SaveOptions) => boolean) => void;
|
|
52
55
|
/**
|
|
53
56
|
* @hidden
|
|
54
57
|
*/
|
package/dist/es/utils.js
CHANGED
|
@@ -27,16 +27,16 @@ const getDocumentParameters = (options) => {
|
|
|
27
27
|
* @hidden
|
|
28
28
|
*/
|
|
29
29
|
export const download = (options, fileName = 'Document', saveOptions = {}, onDownload) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
if (options.pdf) {
|
|
31
|
+
options.pdf.getData()
|
|
32
|
+
.then((data) => new Blob([data], { type: 'application/pdf' }))
|
|
33
|
+
.then((blob) => {
|
|
34
|
+
if (!onDownload(blob, fileName, saveOptions)) {
|
|
35
|
+
saveAs(blob, fileName, saveOptions);
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
.catch((reason) => { options.error.call(undefined, reason); });
|
|
39
|
+
}
|
|
40
40
|
};
|
|
41
41
|
/**
|
|
42
42
|
* @hidden
|
|
@@ -264,5 +264,5 @@ export const scrollToPage = (rootElement, pageNumber) => {
|
|
|
264
264
|
export const currentPage = (rootElement) => {
|
|
265
265
|
const scrollElement = rootElement.querySelector('.k-pdf-viewer-canvas');
|
|
266
266
|
const page = rootElement.querySelector('.k-page');
|
|
267
|
-
return (scrollElement && page) ? Math.floor(scrollElement.scrollTop / (page.offsetHeight + page.offsetTop)) : 0;
|
|
267
|
+
return (scrollElement && page) ? Math.floor((Math.round(scrollElement.scrollTop)) / (page.offsetHeight + page.offsetTop) + 0.01) : 0;
|
|
268
268
|
};
|
package/dist/npm/PDFViewer.d.ts
CHANGED
package/dist/npm/PDFViewer.js
CHANGED
|
@@ -28,20 +28,19 @@ const defaultProps = {
|
|
|
28
28
|
tools: [...toolNames],
|
|
29
29
|
zoomRate: 0.25,
|
|
30
30
|
zoomLevels: [
|
|
31
|
-
{ id: 1, value: 1, text: '
|
|
32
|
-
{ id: 2, value: 1, text: '
|
|
33
|
-
{ id: 3, value: 1, text: '
|
|
34
|
-
{ id: 4, value: 0.5, text: '50%', type: '' },
|
|
35
|
-
{ id: 5, value: 0.75, text: '75%', type: '' },
|
|
36
|
-
{ id: 6, value: 1, text: '100%', type: '' },
|
|
37
|
-
{ id: 7, value: 1.25, text: '125%', type: '' },
|
|
38
|
-
{ id: 8, value: 1.5, text: '150%', type: '' },
|
|
39
|
-
{ id: 9, value: 2, text: '200%', type: '' },
|
|
40
|
-
{ id: 10, value: 3, text: '300%', type: '' },
|
|
41
|
-
{ id: 11, value: 4, text: '400%', type: '' }
|
|
31
|
+
{ id: 1, priority: 1, value: 1, text: 'Actual width', type: 'ActualWidth', locationString: messages_1.actualWidth },
|
|
32
|
+
{ id: 2, priority: 2, value: 1, text: 'Fit to width', type: 'FitToWidth', locationString: messages_1.fitToWidth },
|
|
33
|
+
{ id: 3, priority: 3, value: 1, text: 'Fit to page', type: 'FitToPage', locationString: messages_1.fitToPage },
|
|
34
|
+
{ id: 4, priority: 4, value: 0.5, text: '50%', type: '' },
|
|
35
|
+
{ id: 5, priority: 5, value: 0.75, text: '75%', type: '' },
|
|
36
|
+
{ id: 6, priority: 100, value: 1, text: '100%', type: '' },
|
|
37
|
+
{ id: 7, priority: 7, value: 1.25, text: '125%', type: '' },
|
|
38
|
+
{ id: 8, priority: 8, value: 1.5, text: '150%', type: '' },
|
|
39
|
+
{ id: 9, priority: 9, value: 2, text: '200%', type: '' },
|
|
40
|
+
{ id: 10, priority: 10, value: 3, text: '300%', type: '' },
|
|
41
|
+
{ id: 11, priority: 11, value: 4, text: '400%', type: '' }
|
|
42
42
|
],
|
|
43
|
-
defaultZoom:
|
|
44
|
-
defaultPage: 1
|
|
43
|
+
defaultZoom: utils_1.DEFAULT_ZOOM_LEVEL
|
|
45
44
|
};
|
|
46
45
|
const navigation = [
|
|
47
46
|
'.k-toolbar > button',
|
|
@@ -50,6 +49,15 @@ const navigation = [
|
|
|
50
49
|
'.k-toolbar .k-pager > a',
|
|
51
50
|
'.k-toolbar .k-pager input'
|
|
52
51
|
];
|
|
52
|
+
const sortByPriority = (a, b) => {
|
|
53
|
+
if (a.priority > b.priority) {
|
|
54
|
+
return -1;
|
|
55
|
+
}
|
|
56
|
+
else if (a.priority < b.priority) {
|
|
57
|
+
return 1;
|
|
58
|
+
}
|
|
59
|
+
return 0;
|
|
60
|
+
};
|
|
53
61
|
/**
|
|
54
62
|
* Represents the [KendoReact PDFViewer component]({% slug api_pdf-viewer_pdfviewerprops %}).
|
|
55
63
|
*/
|
|
@@ -60,7 +68,7 @@ exports.PDFViewer = React.forwardRef((props, ref) => {
|
|
|
60
68
|
const pagesRef = React.useRef(null);
|
|
61
69
|
const [stateZoom, setStateZoom] = React.useState(defaultZoom);
|
|
62
70
|
const currentZoom = zoom !== undefined ? zoom : stateZoom;
|
|
63
|
-
const currentZoomLevel = zoomLevels.find(z => z.value === currentZoom) ||
|
|
71
|
+
const currentZoomLevel = zoomLevels.slice().sort(sortByPriority).find(z => z.value === currentZoom) ||
|
|
64
72
|
{ text: (currentZoom * 100) + '%', value: currentZoom, id: currentZoom, locationString: '' };
|
|
65
73
|
if (currentZoomLevel.locationString) {
|
|
66
74
|
currentZoomLevel.text = loc.toLanguageString(currentZoomLevel.locationString, messages_1.messages[currentZoomLevel.locationString]);
|
|
@@ -76,6 +84,7 @@ exports.PDFViewer = React.forwardRef((props, ref) => {
|
|
|
76
84
|
const [searchText, setSearchText] = React.useState('');
|
|
77
85
|
const refObj = React.useMemo(() => ({}), []);
|
|
78
86
|
refObj.currentZoom = currentZoom;
|
|
87
|
+
refObj.props = props;
|
|
79
88
|
const target = React.useRef(null);
|
|
80
89
|
const pdfViewerRef = React.useRef(null);
|
|
81
90
|
React.useImperativeHandle(target, () => ({
|
|
@@ -86,11 +95,11 @@ exports.PDFViewer = React.forwardRef((props, ref) => {
|
|
|
86
95
|
}), []);
|
|
87
96
|
React.useImperativeHandle(ref, () => target.current);
|
|
88
97
|
const triggerOnLoad = React.useCallback(() => {
|
|
89
|
-
if (props.onLoad) {
|
|
98
|
+
if (refObj.props.onLoad) {
|
|
90
99
|
const loadEvent = { target: target.current };
|
|
91
|
-
props.onLoad.call(undefined, loadEvent);
|
|
100
|
+
refObj.props.onLoad.call(undefined, loadEvent);
|
|
92
101
|
}
|
|
93
|
-
}, [
|
|
102
|
+
}, []);
|
|
94
103
|
const triggerOnDownload = React.useCallback((blob, fileName, saveOptions) => {
|
|
95
104
|
if (props.onDownload) {
|
|
96
105
|
const downloadEvent = {
|
|
@@ -124,7 +133,7 @@ exports.PDFViewer = React.forwardRef((props, ref) => {
|
|
|
124
133
|
charClass: 'k-text-char'
|
|
125
134
|
});
|
|
126
135
|
}, []);
|
|
127
|
-
|
|
136
|
+
refObj.done = React.useCallback(({ pdfPages, pdfDoc, zoom: documentZoom }) => {
|
|
128
137
|
refObj.document = pdfDoc;
|
|
129
138
|
refObj.pages = pdfPages;
|
|
130
139
|
refObj.zoom = documentZoom;
|
|
@@ -132,8 +141,11 @@ exports.PDFViewer = React.forwardRef((props, ref) => {
|
|
|
132
141
|
setLoading(false);
|
|
133
142
|
setHasDocument(true);
|
|
134
143
|
triggerOnLoad();
|
|
144
|
+
if (pagesRef.current) {
|
|
145
|
+
(0, utils_1.scrollToPage)(pagesRef.current, 0);
|
|
146
|
+
}
|
|
135
147
|
}, []);
|
|
136
|
-
|
|
148
|
+
refObj.error = React.useCallback((reason) => {
|
|
137
149
|
refObj.document = null;
|
|
138
150
|
refObj.pages = [];
|
|
139
151
|
setLoading(false);
|
|
@@ -146,7 +158,6 @@ exports.PDFViewer = React.forwardRef((props, ref) => {
|
|
|
146
158
|
props.onError.call(undefined, errorEvent);
|
|
147
159
|
}
|
|
148
160
|
}, [props.onError]);
|
|
149
|
-
refObj.onError = error;
|
|
150
161
|
React.useEffect(() => {
|
|
151
162
|
if (pagesRef.current) {
|
|
152
163
|
if (props.url || props.data || props.arrayBuffer) {
|
|
@@ -158,8 +169,8 @@ exports.PDFViewer = React.forwardRef((props, ref) => {
|
|
|
158
169
|
arrayBuffer: props.arrayBuffer,
|
|
159
170
|
dom: pagesRef.current,
|
|
160
171
|
zoom: refObj.currentZoom,
|
|
161
|
-
done,
|
|
162
|
-
error: refObj.
|
|
172
|
+
done: refObj.done,
|
|
173
|
+
error: refObj.error
|
|
163
174
|
});
|
|
164
175
|
}
|
|
165
176
|
else {
|
|
@@ -184,15 +195,25 @@ exports.PDFViewer = React.forwardRef((props, ref) => {
|
|
|
184
195
|
refObj.zoom = zoomLev;
|
|
185
196
|
setLoading(false);
|
|
186
197
|
},
|
|
187
|
-
error
|
|
198
|
+
error: refObj.error
|
|
188
199
|
});
|
|
189
200
|
}
|
|
190
|
-
}, [
|
|
201
|
+
}, []);
|
|
191
202
|
React.useEffect(() => {
|
|
192
203
|
if (pagesRef.current && refObj.document && currentZoom !== refObj.zoom) {
|
|
193
204
|
reload(refObj.document, currentZoom);
|
|
194
205
|
}
|
|
195
206
|
}, [currentZoom, reload]);
|
|
207
|
+
React.useEffect(() => {
|
|
208
|
+
return () => {
|
|
209
|
+
refObj.scroller.destroy();
|
|
210
|
+
if (refObj.search) {
|
|
211
|
+
refObj.search.destroy();
|
|
212
|
+
}
|
|
213
|
+
refObj.document = null;
|
|
214
|
+
refObj.pages = [];
|
|
215
|
+
};
|
|
216
|
+
}, []);
|
|
196
217
|
const onSearch = React.useCallback(() => {
|
|
197
218
|
setShowSearch(true);
|
|
198
219
|
initSearch(pagesRef.current);
|
|
@@ -268,8 +289,8 @@ exports.PDFViewer = React.forwardRef((props, ref) => {
|
|
|
268
289
|
}
|
|
269
290
|
}, [skip, props.onPageChange]);
|
|
270
291
|
const onZoomIn = React.useCallback((e) => {
|
|
271
|
-
const newZoom = Math.min(currentZoom + zoomRate, maxZoom);
|
|
272
|
-
if (newZoom !== currentZoom && refObj.document) {
|
|
292
|
+
const newZoom = Math.min(refObj.currentZoom + zoomRate, maxZoom);
|
|
293
|
+
if (newZoom !== refObj.currentZoom && refObj.document) {
|
|
273
294
|
setStateZoom(newZoom);
|
|
274
295
|
if (zoom === undefined) {
|
|
275
296
|
reload(refObj.document, newZoom);
|
|
@@ -283,10 +304,10 @@ exports.PDFViewer = React.forwardRef((props, ref) => {
|
|
|
283
304
|
props.onZoom.call(undefined, zoomEvent);
|
|
284
305
|
}
|
|
285
306
|
}
|
|
286
|
-
}, [
|
|
307
|
+
}, [zoomRate, maxZoom, zoom, props.onZoom, reload]);
|
|
287
308
|
const onZoomOut = React.useCallback((e) => {
|
|
288
|
-
const newZoom = Math.max(
|
|
289
|
-
if (newZoom !==
|
|
309
|
+
const newZoom = Math.max(refObj.currentZoom - zoomRate, minZoom);
|
|
310
|
+
if (newZoom !== refObj.currentZoom && refObj.document) {
|
|
290
311
|
setStateZoom(newZoom);
|
|
291
312
|
if (zoom === undefined) {
|
|
292
313
|
reload(refObj.document, newZoom);
|
|
@@ -300,7 +321,7 @@ exports.PDFViewer = React.forwardRef((props, ref) => {
|
|
|
300
321
|
props.onZoom.call(undefined, zoomEvent);
|
|
301
322
|
}
|
|
302
323
|
}
|
|
303
|
-
}, [
|
|
324
|
+
}, [zoomRate, minZoom, zoom, props.onZoom, reload]);
|
|
304
325
|
const onZoomLevelChange = React.useCallback((e) => {
|
|
305
326
|
const item = e.value === null ? { text: '100%', value: 1, id: 100 } : Object.assign({}, e.value);
|
|
306
327
|
if (item.value === undefined) {
|
|
@@ -312,8 +333,9 @@ exports.PDFViewer = React.forwardRef((props, ref) => {
|
|
|
312
333
|
item.value = 1;
|
|
313
334
|
}
|
|
314
335
|
}
|
|
315
|
-
|
|
316
|
-
|
|
336
|
+
let newZoom = item ? (0, utils_1.calculateZoomLevel)(item.value, item.type, refObj.currentZoom, pagesRef.current) : 1;
|
|
337
|
+
newZoom = Math.round(newZoom * 100) / 100;
|
|
338
|
+
if (refObj.currentZoom !== newZoom && refObj.document) {
|
|
317
339
|
setStateZoom(newZoom);
|
|
318
340
|
if (zoom === undefined) {
|
|
319
341
|
reload(refObj.document, newZoom);
|
|
@@ -327,7 +349,7 @@ exports.PDFViewer = React.forwardRef((props, ref) => {
|
|
|
327
349
|
props.onZoom.call(undefined, zoomEvent);
|
|
328
350
|
}
|
|
329
351
|
}
|
|
330
|
-
}, [
|
|
352
|
+
}, [zoom, props.onZoom, reload]);
|
|
331
353
|
const onTextSelection = React.useCallback(() => {
|
|
332
354
|
refObj.scroller.disablePanEventsTracking();
|
|
333
355
|
setEnabledSelection(true);
|
|
@@ -338,22 +360,20 @@ exports.PDFViewer = React.forwardRef((props, ref) => {
|
|
|
338
360
|
}, []);
|
|
339
361
|
const onDownload = React.useCallback(() => {
|
|
340
362
|
(0, utils_1.download)({
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
arrayBuffer: props.arrayBuffer,
|
|
344
|
-
error
|
|
363
|
+
pdf: refObj.document,
|
|
364
|
+
error: refObj.error
|
|
345
365
|
}, props.saveFileName, props.saveOptions, triggerOnDownload);
|
|
346
|
-
}, [props.url, props.data, props.arrayBuffer,
|
|
366
|
+
}, [props.url, props.data, props.arrayBuffer, props.saveFileName, props.saveOptions, triggerOnDownload]);
|
|
347
367
|
const onPrint = React.useCallback(() => {
|
|
348
368
|
setLoading(true);
|
|
349
369
|
const onError = (e) => {
|
|
350
|
-
error(typeof (e ? e.message || e : null) === 'string' ? e.message || e : loc.toLanguageString(messages_1.popupBlocked, messages_1.messages[messages_1.popupBlocked]));
|
|
370
|
+
refObj.error(typeof (e ? e.message || e : null) === 'string' ? e.message || e : loc.toLanguageString(messages_1.popupBlocked, messages_1.messages[messages_1.popupBlocked]));
|
|
351
371
|
};
|
|
352
372
|
const onDone = () => {
|
|
353
373
|
setLoading(false);
|
|
354
374
|
};
|
|
355
375
|
(0, utils_1.print)(refObj.pages, onDone, onError);
|
|
356
|
-
}, [
|
|
376
|
+
}, []);
|
|
357
377
|
const onAdd = React.useCallback((e) => {
|
|
358
378
|
const st = e.newState;
|
|
359
379
|
if (st[0] && st[0].getRawFile) {
|
|
@@ -362,18 +382,19 @@ exports.PDFViewer = React.forwardRef((props, ref) => {
|
|
|
362
382
|
if (pagesRef.current) {
|
|
363
383
|
setLoading(true);
|
|
364
384
|
(0, utils_1.removeChildren)(pagesRef.current);
|
|
385
|
+
const currentZoomValue = refObj.props.zoom === undefined ? defaultZoom : refObj.props.zoom;
|
|
365
386
|
(0, utils_1.loadPDF)({
|
|
366
387
|
arrayBuffer,
|
|
367
388
|
dom: pagesRef.current,
|
|
368
|
-
zoom:
|
|
369
|
-
done,
|
|
370
|
-
error
|
|
389
|
+
zoom: currentZoomValue,
|
|
390
|
+
done: refObj.done,
|
|
391
|
+
error: refObj.error
|
|
371
392
|
});
|
|
372
|
-
setStateZoom(
|
|
393
|
+
setStateZoom(currentZoomValue);
|
|
373
394
|
}
|
|
374
395
|
});
|
|
375
396
|
}
|
|
376
|
-
}, [
|
|
397
|
+
}, [defaultZoom]);
|
|
377
398
|
const onFileOpen = React.useCallback((e) => {
|
|
378
399
|
const targetEl = e.target;
|
|
379
400
|
if (targetEl instanceof HTMLElement && targetEl.parentNode) {
|
|
@@ -8,7 +8,7 @@ exports.packageMetadata = {
|
|
|
8
8
|
name: '@progress/kendo-react-pdf-viewer',
|
|
9
9
|
productName: 'KendoReact',
|
|
10
10
|
productCodes: ['KENDOUIREACT', 'KENDOUICOMPLETE'],
|
|
11
|
-
publishDate:
|
|
11
|
+
publishDate: 1672915293,
|
|
12
12
|
version: '',
|
|
13
13
|
licensingDocsUrl: 'https://www.telerik.com/kendo-react-ui/my-license/?utm_medium=product&utm_source=kendoreact&utm_campaign=kendo-ui-react-purchase-license-keys-warning'
|
|
14
14
|
};
|
package/dist/npm/scroller.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare class Scroller {
|
|
|
24
24
|
disablePanEventsTracking(): void;
|
|
25
25
|
shouldTrackPanEvents(): any;
|
|
26
26
|
onElementScroll: () => void;
|
|
27
|
-
|
|
27
|
+
onDragStart: (e: any) => void;
|
|
28
28
|
onDrag: (e: any) => void;
|
|
29
29
|
onDragEnd: () => void;
|
|
30
30
|
calculateEventLocationDelta(e: any): void;
|
package/dist/npm/scroller.js
CHANGED
|
@@ -85,7 +85,7 @@ class Scroller {
|
|
|
85
85
|
this.state.trackNextElementScroll = true;
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
|
-
this.
|
|
88
|
+
this.onDragStart = (e) => {
|
|
89
89
|
this.state.dragStarted = false;
|
|
90
90
|
if (!this.shouldTrackPanEvents()) {
|
|
91
91
|
return;
|
|
@@ -146,7 +146,7 @@ class Scroller {
|
|
|
146
146
|
}
|
|
147
147
|
this.draggable = new kendo_draggable_1.default({
|
|
148
148
|
mouseOnly: false,
|
|
149
|
-
press: this.
|
|
149
|
+
press: this.onDragStart,
|
|
150
150
|
drag: this.throttledOnDrag,
|
|
151
151
|
release: this.onDragEnd
|
|
152
152
|
});
|
package/dist/npm/utils.d.ts
CHANGED
|
@@ -48,7 +48,10 @@ export declare const DEFAULT_ZOOM_LEVEL = 1.25;
|
|
|
48
48
|
/**
|
|
49
49
|
* @hidden
|
|
50
50
|
*/
|
|
51
|
-
export declare const download: (options:
|
|
51
|
+
export declare const download: (options: {
|
|
52
|
+
pdf: PDFDocumentProxy | null;
|
|
53
|
+
error: ErrorFn;
|
|
54
|
+
}, fileName: string | undefined, saveOptions: SaveOptions | undefined, onDownload: (blob: Blob, fileName: string, saveOptions: SaveOptions) => boolean) => void;
|
|
52
55
|
/**
|
|
53
56
|
* @hidden
|
|
54
57
|
*/
|