@atlaskit/media-document-viewer 0.6.10 → 0.7.0
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/CHANGELOG.md +20 -0
- package/dist/cjs/documentLinks.js +9 -3
- package/dist/cjs/documentViewer.js +179 -34
- package/dist/cjs/page.js +11 -10
- package/dist/cjs/utils/useCachedGetImage.js +14 -34
- package/dist/es2019/documentLinks.js +7 -3
- package/dist/es2019/documentViewer.js +169 -31
- package/dist/es2019/page.js +11 -10
- package/dist/es2019/utils/useCachedGetImage.js +4 -23
- package/dist/esm/documentLinks.js +9 -3
- package/dist/esm/documentViewer.js +180 -35
- package/dist/esm/page.js +11 -10
- package/dist/esm/utils/useCachedGetImage.js +14 -33
- package/dist/types/documentLinks.d.ts +2 -1
- package/dist/types/documentViewer.d.ts +7 -1
- package/dist/types/page.d.ts +9 -3
- package/dist/types/utils/useCachedGetImage.d.ts +1 -11
- package/dist/types-ts4.5/documentLinks.d.ts +2 -1
- package/dist/types-ts4.5/documentViewer.d.ts +7 -1
- package/dist/types-ts4.5/page.d.ts +9 -3
- package/dist/types-ts4.5/utils/useCachedGetImage.d.ts +1 -11
- package/package.json +4 -10
package/dist/esm/page.js
CHANGED
|
@@ -6,12 +6,10 @@ import * as React from 'react';
|
|
|
6
6
|
import { ax, ix } from "@compiled/react/runtime";
|
|
7
7
|
import { forwardRef, useEffect, useState } from 'react';
|
|
8
8
|
import { useStaticCallback } from '@atlaskit/media-common';
|
|
9
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
10
9
|
import Spinner from '@atlaskit/spinner';
|
|
11
10
|
import { Annotations } from './annotations';
|
|
12
11
|
import { DocumentLinks } from './documentLinks';
|
|
13
12
|
import { getDocumentRoot } from './utils/getDocumentRoot';
|
|
14
|
-
import { getImageZoom } from './utils/useCachedGetImage';
|
|
15
13
|
import { useIntersectionObserver } from './utils/useIntersectionObserver';
|
|
16
14
|
var Span = function Span(_ref) {
|
|
17
15
|
var span = _ref.span,
|
|
@@ -74,7 +72,8 @@ var PageView = /*#__PURE__*/forwardRef(function (_ref4, ref) {
|
|
|
74
72
|
fonts = _ref4.fonts,
|
|
75
73
|
pageIndex = _ref4.pageIndex,
|
|
76
74
|
zoom = _ref4.zoom,
|
|
77
|
-
onImageLoad = _ref4.onImageLoad
|
|
75
|
+
onImageLoad = _ref4.onImageLoad,
|
|
76
|
+
appendUpTo = _ref4.appendUpTo;
|
|
78
77
|
var style = {};
|
|
79
78
|
if (dimensions) {
|
|
80
79
|
// contents endpoint has loaded so dimensions are available
|
|
@@ -106,7 +105,7 @@ var PageView = /*#__PURE__*/forwardRef(function (_ref4, ref) {
|
|
|
106
105
|
src: imageSrc,
|
|
107
106
|
alt: "",
|
|
108
107
|
onLoad: onImageLoad,
|
|
109
|
-
className: ax(["_kqswstnw _154iidpf _1ltvidpf _uiztglyw",
|
|
108
|
+
className: ax(["_kqswstnw _154iidpf _1ltvidpf _uiztglyw", "_1kemd8h4"])
|
|
110
109
|
}), content && /*#__PURE__*/React.createElement("svg", {
|
|
111
110
|
"data-testid": "page-".concat(pageIndex, "-text-layer"),
|
|
112
111
|
style: style,
|
|
@@ -123,20 +122,21 @@ var PageView = /*#__PURE__*/forwardRef(function (_ref4, ref) {
|
|
|
123
122
|
}), content.annotations && /*#__PURE__*/React.createElement(Annotations, {
|
|
124
123
|
annotations: content.annotations
|
|
125
124
|
}), content.links && /*#__PURE__*/React.createElement(DocumentLinks, {
|
|
126
|
-
links: content.links
|
|
125
|
+
links: content.links,
|
|
126
|
+
appendUpTo: appendUpTo
|
|
127
127
|
})));
|
|
128
128
|
});
|
|
129
129
|
export var Page = function Page(_ref5) {
|
|
130
130
|
var _ref6;
|
|
131
131
|
var getPageSrc = _ref5.getPageSrc,
|
|
132
|
-
maxPageImageZoom = _ref5.maxPageImageZoom,
|
|
133
132
|
content = _ref5.content,
|
|
134
133
|
fonts = _ref5.fonts,
|
|
135
134
|
pageIndex = _ref5.pageIndex,
|
|
136
135
|
zoom = _ref5.zoom,
|
|
137
136
|
defaultDimensions = _ref5.defaultDimensions,
|
|
138
137
|
onVisible = _ref5.onVisible,
|
|
139
|
-
onLoad = _ref5.onLoad
|
|
138
|
+
onLoad = _ref5.onLoad,
|
|
139
|
+
appendUpTo = _ref5.appendUpTo;
|
|
140
140
|
var _useState = useState(),
|
|
141
141
|
_useState2 = _slicedToArray(_useState, 2),
|
|
142
142
|
imageSrc = _useState2[0],
|
|
@@ -148,7 +148,7 @@ export var Page = function Page(_ref5) {
|
|
|
148
148
|
rootMargin: '300%',
|
|
149
149
|
threshold: 0.1
|
|
150
150
|
}, function () {
|
|
151
|
-
onVisible();
|
|
151
|
+
onVisible(pageIndex);
|
|
152
152
|
getPageSrc(pageIndex, zoom).then(setImageSrc);
|
|
153
153
|
}),
|
|
154
154
|
observedRef = _useIntersectionObser.observedRef,
|
|
@@ -162,7 +162,7 @@ export var Page = function Page(_ref5) {
|
|
|
162
162
|
onLoad === null || onLoad === void 0 || onLoad();
|
|
163
163
|
if (!content) {
|
|
164
164
|
var _zoom = image.dataset.zoom ? Number(image.dataset.zoom) : 1;
|
|
165
|
-
var imageZoom =
|
|
165
|
+
var imageZoom = _zoom;
|
|
166
166
|
var contentWidth = image.naturalWidth / imageZoom;
|
|
167
167
|
var contentHeight = image.naturalHeight / imageZoom;
|
|
168
168
|
setDimensions({
|
|
@@ -184,6 +184,7 @@ export var Page = function Page(_ref5) {
|
|
|
184
184
|
fonts: fonts,
|
|
185
185
|
pageIndex: pageIndex,
|
|
186
186
|
zoom: zoom,
|
|
187
|
-
onImageLoad: onImageLoad
|
|
187
|
+
onImageLoad: onImageLoad,
|
|
188
|
+
appendUpTo: appendUpTo
|
|
188
189
|
});
|
|
189
190
|
};
|
|
@@ -2,8 +2,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
3
|
import { useEffect, useRef } from 'react';
|
|
4
4
|
import { useStaticCallback } from '@atlaskit/media-common';
|
|
5
|
-
|
|
6
|
-
export var useCachedGetImage = function useCachedGetImage(getPageImageUrl, maxPageImageZoom) {
|
|
5
|
+
export var useCachedGetImage = function useCachedGetImage(getPageImageUrl) {
|
|
7
6
|
var imageUrlRefs = useRef({});
|
|
8
7
|
useEffect(function () {
|
|
9
8
|
return function () {
|
|
@@ -16,38 +15,37 @@ export var useCachedGetImage = function useCachedGetImage(getPageImageUrl, maxPa
|
|
|
16
15
|
}, []);
|
|
17
16
|
var getImageUrl = useStaticCallback( /*#__PURE__*/function () {
|
|
18
17
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(pageNumber, zoom) {
|
|
19
|
-
var
|
|
18
|
+
var key, url, isBlobUrl, blob;
|
|
20
19
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
21
20
|
while (1) switch (_context.prev = _context.next) {
|
|
22
21
|
case 0:
|
|
23
|
-
|
|
24
|
-
key = "".concat(pageNumber, "-").concat(imageZoom);
|
|
22
|
+
key = "".concat(pageNumber, "-").concat(zoom);
|
|
25
23
|
if (!imageUrlRefs.current[key]) {
|
|
26
|
-
_context.next =
|
|
24
|
+
_context.next = 3;
|
|
27
25
|
break;
|
|
28
26
|
}
|
|
29
27
|
return _context.abrupt("return", imageUrlRefs.current[key]);
|
|
30
|
-
case
|
|
31
|
-
_context.next =
|
|
32
|
-
return getPageImageUrl(pageNumber,
|
|
33
|
-
case
|
|
28
|
+
case 3:
|
|
29
|
+
_context.next = 5;
|
|
30
|
+
return getPageImageUrl(pageNumber, zoom);
|
|
31
|
+
case 5:
|
|
34
32
|
url = _context.sent;
|
|
35
33
|
isBlobUrl = url.startsWith('blob:');
|
|
36
34
|
if (isBlobUrl) {
|
|
37
|
-
_context.next =
|
|
35
|
+
_context.next = 12;
|
|
38
36
|
break;
|
|
39
37
|
}
|
|
40
|
-
_context.next =
|
|
38
|
+
_context.next = 10;
|
|
41
39
|
return fetch(url).then(function (res) {
|
|
42
40
|
return res.blob();
|
|
43
41
|
});
|
|
44
|
-
case
|
|
42
|
+
case 10:
|
|
45
43
|
blob = _context.sent;
|
|
46
44
|
url = URL.createObjectURL(blob);
|
|
47
|
-
case
|
|
45
|
+
case 12:
|
|
48
46
|
imageUrlRefs.current[key] = url;
|
|
49
47
|
return _context.abrupt("return", url);
|
|
50
|
-
case
|
|
48
|
+
case 14:
|
|
51
49
|
case "end":
|
|
52
50
|
return _context.stop();
|
|
53
51
|
}
|
|
@@ -58,21 +56,4 @@ export var useCachedGetImage = function useCachedGetImage(getPageImageUrl, maxPa
|
|
|
58
56
|
};
|
|
59
57
|
}());
|
|
60
58
|
return getImageUrl;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* The actual zoom that will be requested from the image service.
|
|
65
|
-
*
|
|
66
|
-
* This is different from the 'zoom' prop because it is adjusted for the device pixel ratio.
|
|
67
|
-
* We're achieving the same result as a srcset, crisp images for high DPI screens.
|
|
68
|
-
*
|
|
69
|
-
* We also reduce impact of excessively slow rendering by setting a max zoom level.
|
|
70
|
-
* If the user is zoomed past this level, the image will just be scaled-up client side.
|
|
71
|
-
*/
|
|
72
|
-
export function getImageZoom(zoom, maxPageImageZoom) {
|
|
73
|
-
if (!fg('media-document-viewer-clear-render')) {
|
|
74
|
-
return zoom;
|
|
75
|
-
}
|
|
76
|
-
var dpiAdjustedZoom = zoom * (window.devicePixelRatio || 1);
|
|
77
|
-
return Math.min(dpiAdjustedZoom, maxPageImageZoom);
|
|
78
|
-
}
|
|
59
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type Link } from './types';
|
|
3
|
-
export declare const DocumentLinks: ({ links }: {
|
|
3
|
+
export declare const DocumentLinks: ({ links, appendUpTo, }: {
|
|
4
4
|
links: readonly Link[];
|
|
5
|
+
appendUpTo?: (n: number) => void;
|
|
5
6
|
}) => React.JSX.Element;
|
|
@@ -13,5 +13,11 @@ export type DocumentViewerProps = {
|
|
|
13
13
|
maxPageImageZoom?: number;
|
|
14
14
|
zoom: number;
|
|
15
15
|
onSuccess?: () => void;
|
|
16
|
+
/**
|
|
17
|
+
* When true, renders an initial batch of pages and appends more as the user scrolls.
|
|
18
|
+
* Intended for large documents (e.g. large Excel previews).
|
|
19
|
+
* Default: false.
|
|
20
|
+
*/
|
|
21
|
+
enableLazyPageRendering?: boolean;
|
|
16
22
|
};
|
|
17
|
-
export declare const DocumentViewer: ({ onSuccess, getContent, getPageImageUrl, paginationSize,
|
|
23
|
+
export declare const DocumentViewer: ({ onSuccess, getContent, getPageImageUrl, paginationSize, zoom, enableLazyPageRendering, }: DocumentViewerProps) => JSX.Element;
|
package/dist/types/page.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type Font, type PageContent } from './types';
|
|
2
2
|
type PageProps = {
|
|
3
3
|
getPageSrc: (pageIndex: number, zoom: number) => Promise<string>;
|
|
4
|
-
maxPageImageZoom: number;
|
|
5
4
|
content?: PageContent;
|
|
6
5
|
fonts: readonly Font[];
|
|
7
6
|
pageIndex: number;
|
|
@@ -10,8 +9,15 @@ type PageProps = {
|
|
|
10
9
|
width: number;
|
|
11
10
|
height: number;
|
|
12
11
|
};
|
|
13
|
-
onVisible: () => void;
|
|
12
|
+
onVisible: (pageIndex: number) => void;
|
|
14
13
|
onLoad?: () => void;
|
|
14
|
+
/**
|
|
15
|
+
* Called when a local `#page-N` anchor inside this page is clicked.
|
|
16
|
+
* Fast-forwards the lazy page count so the target page exists in the DOM
|
|
17
|
+
* before the browser performs the native anchor scroll.
|
|
18
|
+
* Only provided when `enableLazyPageRendering` is true.
|
|
19
|
+
*/
|
|
20
|
+
appendUpTo?: (n: number) => void;
|
|
15
21
|
};
|
|
16
|
-
export declare const Page: ({ getPageSrc,
|
|
22
|
+
export declare const Page: ({ getPageSrc, content, fonts, pageIndex, zoom, defaultDimensions, onVisible, onLoad, appendUpTo, }: PageProps) => JSX.Element;
|
|
17
23
|
export {};
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
export declare const useCachedGetImage: (getPageImageUrl: (pageNumber: number, zoom: number) => Promise<string
|
|
2
|
-
/**
|
|
3
|
-
* The actual zoom that will be requested from the image service.
|
|
4
|
-
*
|
|
5
|
-
* This is different from the 'zoom' prop because it is adjusted for the device pixel ratio.
|
|
6
|
-
* We're achieving the same result as a srcset, crisp images for high DPI screens.
|
|
7
|
-
*
|
|
8
|
-
* We also reduce impact of excessively slow rendering by setting a max zoom level.
|
|
9
|
-
* If the user is zoomed past this level, the image will just be scaled-up client side.
|
|
10
|
-
*/
|
|
11
|
-
export declare function getImageZoom(zoom: number, maxPageImageZoom: number): number;
|
|
1
|
+
export declare const useCachedGetImage: (getPageImageUrl: (pageNumber: number, zoom: number) => Promise<string>) => ((pageNumber: number, zoom: number) => Promise<string>);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type Link } from './types';
|
|
3
|
-
export declare const DocumentLinks: ({ links }: {
|
|
3
|
+
export declare const DocumentLinks: ({ links, appendUpTo, }: {
|
|
4
4
|
links: readonly Link[];
|
|
5
|
+
appendUpTo?: (n: number) => void;
|
|
5
6
|
}) => React.JSX.Element;
|
|
@@ -13,5 +13,11 @@ export type DocumentViewerProps = {
|
|
|
13
13
|
maxPageImageZoom?: number;
|
|
14
14
|
zoom: number;
|
|
15
15
|
onSuccess?: () => void;
|
|
16
|
+
/**
|
|
17
|
+
* When true, renders an initial batch of pages and appends more as the user scrolls.
|
|
18
|
+
* Intended for large documents (e.g. large Excel previews).
|
|
19
|
+
* Default: false.
|
|
20
|
+
*/
|
|
21
|
+
enableLazyPageRendering?: boolean;
|
|
16
22
|
};
|
|
17
|
-
export declare const DocumentViewer: ({ onSuccess, getContent, getPageImageUrl, paginationSize,
|
|
23
|
+
export declare const DocumentViewer: ({ onSuccess, getContent, getPageImageUrl, paginationSize, zoom, enableLazyPageRendering, }: DocumentViewerProps) => JSX.Element;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type Font, type PageContent } from './types';
|
|
2
2
|
type PageProps = {
|
|
3
3
|
getPageSrc: (pageIndex: number, zoom: number) => Promise<string>;
|
|
4
|
-
maxPageImageZoom: number;
|
|
5
4
|
content?: PageContent;
|
|
6
5
|
fonts: readonly Font[];
|
|
7
6
|
pageIndex: number;
|
|
@@ -10,8 +9,15 @@ type PageProps = {
|
|
|
10
9
|
width: number;
|
|
11
10
|
height: number;
|
|
12
11
|
};
|
|
13
|
-
onVisible: () => void;
|
|
12
|
+
onVisible: (pageIndex: number) => void;
|
|
14
13
|
onLoad?: () => void;
|
|
14
|
+
/**
|
|
15
|
+
* Called when a local `#page-N` anchor inside this page is clicked.
|
|
16
|
+
* Fast-forwards the lazy page count so the target page exists in the DOM
|
|
17
|
+
* before the browser performs the native anchor scroll.
|
|
18
|
+
* Only provided when `enableLazyPageRendering` is true.
|
|
19
|
+
*/
|
|
20
|
+
appendUpTo?: (n: number) => void;
|
|
15
21
|
};
|
|
16
|
-
export declare const Page: ({ getPageSrc,
|
|
22
|
+
export declare const Page: ({ getPageSrc, content, fonts, pageIndex, zoom, defaultDimensions, onVisible, onLoad, appendUpTo, }: PageProps) => JSX.Element;
|
|
17
23
|
export {};
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
export declare const useCachedGetImage: (getPageImageUrl: (pageNumber: number, zoom: number) => Promise<string
|
|
2
|
-
/**
|
|
3
|
-
* The actual zoom that will be requested from the image service.
|
|
4
|
-
*
|
|
5
|
-
* This is different from the 'zoom' prop because it is adjusted for the device pixel ratio.
|
|
6
|
-
* We're achieving the same result as a srcset, crisp images for high DPI screens.
|
|
7
|
-
*
|
|
8
|
-
* We also reduce impact of excessively slow rendering by setting a max zoom level.
|
|
9
|
-
* If the user is zoomed past this level, the image will just be scaled-up client side.
|
|
10
|
-
*/
|
|
11
|
-
export declare function getImageZoom(zoom: number, maxPageImageZoom: number): number;
|
|
1
|
+
export declare const useCachedGetImage: (getPageImageUrl: (pageNumber: number, zoom: number) => Promise<string>) => ((pageNumber: number, zoom: number) => Promise<string>);
|
package/package.json
CHANGED
|
@@ -26,11 +26,10 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@atlaskit/browser-apis": "^0.0.1",
|
|
28
28
|
"@atlaskit/css": "^0.19.0",
|
|
29
|
-
"@atlaskit/media-common": "^13.
|
|
30
|
-
"@atlaskit/
|
|
31
|
-
"@atlaskit/primitives": "^18.1.0",
|
|
29
|
+
"@atlaskit/media-common": "^13.3.0",
|
|
30
|
+
"@atlaskit/primitives": "^19.0.0",
|
|
32
31
|
"@atlaskit/spinner": "^19.1.0",
|
|
33
|
-
"@atlaskit/tokens": "^
|
|
32
|
+
"@atlaskit/tokens": "^13.0.0",
|
|
34
33
|
"@babel/runtime": "^7.0.0",
|
|
35
34
|
"@compiled/react": "^0.20.0"
|
|
36
35
|
},
|
|
@@ -47,11 +46,6 @@
|
|
|
47
46
|
"@testing-library/user-event": "^14.4.3",
|
|
48
47
|
"react-dom": "^18.2.0"
|
|
49
48
|
},
|
|
50
|
-
"platform-feature-flags": {
|
|
51
|
-
"media-document-viewer-clear-render": {
|
|
52
|
-
"type": "boolean"
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
49
|
"techstack": {
|
|
56
50
|
"@atlassian/frontend": {
|
|
57
51
|
"import-structure": [
|
|
@@ -88,7 +82,7 @@
|
|
|
88
82
|
}
|
|
89
83
|
},
|
|
90
84
|
"name": "@atlaskit/media-document-viewer",
|
|
91
|
-
"version": "0.
|
|
85
|
+
"version": "0.7.0",
|
|
92
86
|
"description": "Modern and fast document viewer",
|
|
93
87
|
"author": "Atlassian Pty Ltd",
|
|
94
88
|
"license": "Apache-2.0",
|