@atlaskit/media-document-viewer 0.3.0 → 0.3.2
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 +17 -0
- package/dist/cjs/annotations.js +14 -1
- package/dist/cjs/documentViewer.compiled.css +1 -3
- package/dist/cjs/documentViewer.js +33 -2
- package/dist/cjs/page.compiled.css +7 -0
- package/dist/cjs/page.js +26 -6
- package/dist/cjs/utils/getDocumentRoot.js +10 -7
- package/dist/es2019/annotations.js +14 -1
- package/dist/es2019/documentViewer.compiled.css +1 -3
- package/dist/es2019/documentViewer.js +32 -1
- package/dist/es2019/page.compiled.css +7 -0
- package/dist/es2019/page.js +26 -6
- package/dist/es2019/utils/getDocumentRoot.js +9 -6
- package/dist/esm/annotations.js +14 -1
- package/dist/esm/documentViewer.compiled.css +1 -3
- package/dist/esm/documentViewer.js +32 -1
- package/dist/esm/page.compiled.css +7 -0
- package/dist/esm/page.js +26 -6
- package/dist/esm/utils/getDocumentRoot.js +9 -6
- package/dist/types/utils/getDocumentRoot.d.ts +1 -0
- package/dist/types-ts4.5/utils/getDocumentRoot.d.ts +1 -0
- package/package.json +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/media-document-viewer
|
|
2
2
|
|
|
3
|
+
## 0.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#183808](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/183808)
|
|
8
|
+
[`4436100210ca9`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/4436100210ca9) -
|
|
9
|
+
Added spinner to document viewer
|
|
10
|
+
|
|
11
|
+
## 0.3.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#180383](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/180383)
|
|
16
|
+
[`ff93dcfae3aa1`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ff93dcfae3aa1) -
|
|
17
|
+
Fixed zoom centering correctly, zooming on mixed page size pdfs no longer cutting off PDFs and
|
|
18
|
+
pressing arrow keys on PDF inputs no longer causing media viewer to scroll
|
|
19
|
+
|
|
3
20
|
## 0.3.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
package/dist/cjs/annotations.js
CHANGED
|
@@ -32,6 +32,12 @@ var TextInputFormField = exports.TextInputFormField = function TextInputFormFiel
|
|
|
32
32
|
type: "text",
|
|
33
33
|
value: field.text,
|
|
34
34
|
readOnly: true,
|
|
35
|
+
onKeyUp: function onKeyUp(e) {
|
|
36
|
+
// stop propagation of the arrow key events because they can be used to navigate viewports
|
|
37
|
+
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
|
|
38
|
+
e.stopPropagation();
|
|
39
|
+
}
|
|
40
|
+
},
|
|
35
41
|
className: (0, _runtime.ax)(["_19itglyw _ca0qidpf _u5f3idpf _n3tdidpf _19bvidpf _r06hglyw", "_kqswstnw _4t3i1osq _1bsb1osq"])
|
|
36
42
|
})));
|
|
37
43
|
};
|
|
@@ -51,7 +57,14 @@ var ComboBoxFormField = exports.ComboBoxFormField = function ComboBoxFormField(_
|
|
|
51
57
|
}), /*#__PURE__*/_react.default.createElement("input", {
|
|
52
58
|
style: (0, _defineProperty2.default)({}, 'fontSize', "".concat(field.f, "px")),
|
|
53
59
|
type: "text",
|
|
54
|
-
value: field.text
|
|
60
|
+
value: field.text
|
|
61
|
+
// stop propagation of the arrow key events because they can be used to navigate viewports
|
|
62
|
+
,
|
|
63
|
+
onKeyUp: function onKeyUp(e) {
|
|
64
|
+
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
|
|
65
|
+
e.stopPropagation();
|
|
66
|
+
}
|
|
67
|
+
},
|
|
55
68
|
readOnly: true,
|
|
56
69
|
className: (0, _runtime.ax)(["_19itglyw _ca0qidpf _u5f3idpf _n3tdidpf _19bvidpf _r06hglyw", "_1bsb1osq"])
|
|
57
70
|
}), /*#__PURE__*/_react.default.createElement(_chevronDown.default, {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
._zulputpp{gap:var(--ds-space-150,9pt)}._18m91wug{overflow-y:auto}
|
|
3
3
|
._19pkxncg{margin-top:var(--ds-space-800,4pc)}
|
|
4
|
-
._1bah1h6o{justify-content:center}
|
|
5
4
|
._1e0c1txw{display:flex}
|
|
6
5
|
._1reo1wug{overflow-x:auto}
|
|
7
6
|
._1ul91osq{min-width:100%}
|
|
8
|
-
._2lx21bp4{flex-direction:column}
|
|
9
|
-
._4cvr1h6o{align-items:center}
|
|
7
|
+
._2lx21bp4{flex-direction:column}
|
|
@@ -8,11 +8,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
});
|
|
9
9
|
exports.DocumentViewer = void 0;
|
|
10
10
|
require("./documentViewer.compiled.css");
|
|
11
|
-
var
|
|
11
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
+
var React = _react;
|
|
12
13
|
var _runtime = require("@compiled/react/runtime");
|
|
13
14
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
14
15
|
var _page = require("./page");
|
|
15
16
|
var _usePageContent2 = require("./usePageContent");
|
|
17
|
+
var _getDocumentRoot = require("./utils/getDocumentRoot");
|
|
16
18
|
var _useCachedGetImage = require("./utils/useCachedGetImage");
|
|
17
19
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
18
20
|
var documentViewerStyles = null;
|
|
@@ -33,10 +35,39 @@ var DocumentViewer = exports.DocumentViewer = function DocumentViewer(_ref) {
|
|
|
33
35
|
var style = {
|
|
34
36
|
'--document-viewer-zoom': zoom
|
|
35
37
|
};
|
|
38
|
+
var previousZoomRef = (0, _react.useRef)(zoom);
|
|
39
|
+
|
|
40
|
+
// Apply zoom with center-based adjustment
|
|
41
|
+
(0, _react.useLayoutEffect)(function () {
|
|
42
|
+
var previousZoom = previousZoomRef.current;
|
|
43
|
+
|
|
44
|
+
// Only adjust scroll if zoom actually changed
|
|
45
|
+
if (previousZoom !== zoom) {
|
|
46
|
+
// If we are not using a custom scroll element, we don't need to adjust the scroll position
|
|
47
|
+
var container = (0, _getDocumentRoot.getScrollElement)();
|
|
48
|
+
if (!container) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Calculate the center point of the viewport before zoom
|
|
53
|
+
var viewportCenterX = container.scrollLeft + container.clientWidth / 2;
|
|
54
|
+
var viewportCenterY = container.scrollTop + container.clientHeight / 2;
|
|
55
|
+
|
|
56
|
+
// Calculate scale difference
|
|
57
|
+
var scaleDiff = zoom / previousZoom - 1;
|
|
58
|
+
|
|
59
|
+
// Adjust scroll to keep center point fixed
|
|
60
|
+
container.scrollLeft += viewportCenterX * scaleDiff;
|
|
61
|
+
container.scrollTop += viewportCenterY * scaleDiff;
|
|
62
|
+
|
|
63
|
+
// Update previous zoom
|
|
64
|
+
previousZoomRef.current = zoom;
|
|
65
|
+
}
|
|
66
|
+
}, [zoom]);
|
|
36
67
|
return /*#__PURE__*/React.createElement("div", {
|
|
37
68
|
"data-testid": "document-viewer",
|
|
38
69
|
style: style,
|
|
39
|
-
className: (0, _runtime.ax)(["_zulputpp _1reo1wug _18m91wug _19pkxncg _1ul91osq _1e0c1txw _2lx21bp4
|
|
70
|
+
className: (0, _runtime.ax)(["_zulputpp _1reo1wug _18m91wug _19pkxncg _1ul91osq _1e0c1txw _2lx21bp4"])
|
|
40
71
|
}, (0, _toConsumableArray2.default)(Array((_documentMetadata$pag = documentMetadata.pageCount) !== null && _documentMetadata$pag !== void 0 ? _documentMetadata$pag : 4)).map(function (_, i) {
|
|
41
72
|
var _getPageContent = getPageContent(i),
|
|
42
73
|
page = _getPageContent.page,
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
._154iidpf{top:0}
|
|
2
|
+
._18u01wug{margin-left:auto}
|
|
3
|
+
._1bah1h6o{justify-content:center}
|
|
4
|
+
._1bsb1osq{width:100%}
|
|
5
|
+
._1e0c1txw{display:flex}
|
|
2
6
|
._1kemd8h4{image-rendering:pixelated}
|
|
3
7
|
._1ltvidpf{left:0}
|
|
8
|
+
._2hwx1wug{margin-right:auto}
|
|
9
|
+
._4cvr1h6o{align-items:center}
|
|
10
|
+
._4t3i1osq{height:100%}
|
|
4
11
|
._80om1kdv{cursor:text}
|
|
5
12
|
._bfhku67f{background-color:#fff}
|
|
6
13
|
._kqswh2mm{position:relative}
|
package/dist/cjs/page.js
CHANGED
|
@@ -14,6 +14,7 @@ var _runtime = require("@compiled/react/runtime");
|
|
|
14
14
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
15
15
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
16
|
var _mediaCommon = require("@atlaskit/media-common");
|
|
17
|
+
var _spinner = _interopRequireDefault(require("@atlaskit/spinner"));
|
|
17
18
|
var _annotations = require("./annotations");
|
|
18
19
|
var _documentLinks = require("./documentLinks");
|
|
19
20
|
var _getDocumentRoot = require("./utils/getDocumentRoot");
|
|
@@ -66,7 +67,12 @@ var Line = function Line() {
|
|
|
66
67
|
};
|
|
67
68
|
var pageSvgStyles = null;
|
|
68
69
|
var pageImageStyles = null;
|
|
70
|
+
var pageSpinnerStyles = null;
|
|
69
71
|
var pageWrapperStyles = null;
|
|
72
|
+
var a4Dimensions = {
|
|
73
|
+
height: 595,
|
|
74
|
+
width: 842
|
|
75
|
+
};
|
|
70
76
|
var PageView = /*#__PURE__*/(0, _react.forwardRef)(function (_ref4, ref) {
|
|
71
77
|
var dimensions = _ref4.dimensions,
|
|
72
78
|
imageSrc = _ref4.imageSrc,
|
|
@@ -75,17 +81,31 @@ var PageView = /*#__PURE__*/(0, _react.forwardRef)(function (_ref4, ref) {
|
|
|
75
81
|
pageIndex = _ref4.pageIndex,
|
|
76
82
|
zoom = _ref4.zoom,
|
|
77
83
|
onImageLoad = _ref4.onImageLoad;
|
|
78
|
-
var style = {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
var style = {};
|
|
85
|
+
if (dimensions) {
|
|
86
|
+
// contents endpoint has loaded so dimensions are available
|
|
87
|
+
style.width = "calc(var(--document-viewer-zoom) * ".concat(dimensions.width, "px)");
|
|
88
|
+
style.height = "calc(var(--document-viewer-zoom) * ".concat(dimensions.height, "px)");
|
|
89
|
+
} else if (imageSrc) {
|
|
90
|
+
// contents endpoint has not loaded dimensions but image is loaded so we can use the image dimensions
|
|
91
|
+
style.width = 'initial';
|
|
92
|
+
style.height = 'initial';
|
|
93
|
+
} else {
|
|
94
|
+
// contents endpoint has not loaded dimensions and image is not loaded so we can use the a4 dimensions
|
|
95
|
+
style.width = "calc(var(--document-viewer-zoom) * ".concat(a4Dimensions.width, "px)");
|
|
96
|
+
style.height = "calc(var(--document-viewer-zoom) * ".concat(a4Dimensions.height, "px)");
|
|
97
|
+
}
|
|
82
98
|
return /*#__PURE__*/React.createElement("div", {
|
|
83
99
|
ref: ref,
|
|
84
100
|
style: style,
|
|
85
101
|
"data-testid": "page-".concat(pageIndex),
|
|
86
102
|
id: "page-".concat(pageIndex + 1),
|
|
87
|
-
className: (0, _runtime.ax)(["_kqswh2mm _bfhku67f"])
|
|
88
|
-
}, imageSrc && /*#__PURE__*/React.createElement("
|
|
103
|
+
className: (0, _runtime.ax)(["_kqswh2mm _bfhku67f _18u01wug _2hwx1wug"])
|
|
104
|
+
}, !imageSrc && /*#__PURE__*/React.createElement("div", {
|
|
105
|
+
className: (0, _runtime.ax)(["_4t3i1osq _1bsb1osq _1e0c1txw _1bah1h6o _4cvr1h6o"])
|
|
106
|
+
}, /*#__PURE__*/React.createElement(_spinner.default, {
|
|
107
|
+
size: "large"
|
|
108
|
+
})), imageSrc && /*#__PURE__*/React.createElement("img", {
|
|
89
109
|
style: style,
|
|
90
110
|
"data-testid": "page-".concat(pageIndex, "-image"),
|
|
91
111
|
"data-zoom": zoom,
|
|
@@ -3,18 +3,21 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getDocumentRoot = exports.DOCUMENT_SCROLL_ROOT_ID = void 0;
|
|
6
|
+
exports.getScrollElement = exports.getDocumentRoot = exports.DOCUMENT_SCROLL_ROOT_ID = void 0;
|
|
7
|
+
var _browserApis = require("@atlaskit/browser-apis");
|
|
7
8
|
var DOCUMENT_SCROLL_ROOT_ID = exports.DOCUMENT_SCROLL_ROOT_ID = 'document-scroll-root';
|
|
8
9
|
var getDocumentRoot = exports.getDocumentRoot = function getDocumentRoot() {
|
|
9
|
-
|
|
10
|
+
var doc = (0, _browserApis.getDocument)();
|
|
11
|
+
if (!doc) {
|
|
10
12
|
return;
|
|
11
13
|
}
|
|
12
|
-
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
var root = document.getElementById(DOCUMENT_SCROLL_ROOT_ID);
|
|
14
|
+
var root = doc.getElementById(DOCUMENT_SCROLL_ROOT_ID);
|
|
16
15
|
if (root) {
|
|
17
16
|
return root;
|
|
18
17
|
}
|
|
19
|
-
return
|
|
18
|
+
return doc;
|
|
19
|
+
};
|
|
20
|
+
var getScrollElement = exports.getScrollElement = function getScrollElement() {
|
|
21
|
+
var element = (0, _browserApis.getDocument)();
|
|
22
|
+
return element && element.getElementById(DOCUMENT_SCROLL_ROOT_ID);
|
|
20
23
|
};
|
|
@@ -28,6 +28,12 @@ export const TextInputFormField = ({
|
|
|
28
28
|
type: "text",
|
|
29
29
|
value: field.text,
|
|
30
30
|
readOnly: true,
|
|
31
|
+
onKeyUp: e => {
|
|
32
|
+
// stop propagation of the arrow key events because they can be used to navigate viewports
|
|
33
|
+
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
|
|
34
|
+
e.stopPropagation();
|
|
35
|
+
}
|
|
36
|
+
},
|
|
31
37
|
className: ax(["_19itglyw _ca0qidpf _u5f3idpf _n3tdidpf _19bvidpf _r06hglyw", "_kqswstnw _4t3i1osq _1bsb1osq"])
|
|
32
38
|
})));
|
|
33
39
|
};
|
|
@@ -50,7 +56,14 @@ export const ComboBoxFormField = ({
|
|
|
50
56
|
['fontSize']: `${field.f}px`
|
|
51
57
|
},
|
|
52
58
|
type: "text",
|
|
53
|
-
value: field.text
|
|
59
|
+
value: field.text
|
|
60
|
+
// stop propagation of the arrow key events because they can be used to navigate viewports
|
|
61
|
+
,
|
|
62
|
+
onKeyUp: e => {
|
|
63
|
+
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
|
|
64
|
+
e.stopPropagation();
|
|
65
|
+
}
|
|
66
|
+
},
|
|
54
67
|
readOnly: true,
|
|
55
68
|
className: ax(["_19itglyw _ca0qidpf _u5f3idpf _n3tdidpf _19bvidpf _r06hglyw", "_1bsb1osq"])
|
|
56
69
|
}), /*#__PURE__*/React.createElement(ChevronDownIcon, {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
._zulputpp{gap:var(--ds-space-150,9pt)}._18m91wug{overflow-y:auto}
|
|
3
3
|
._19pkxncg{margin-top:var(--ds-space-800,4pc)}
|
|
4
|
-
._1bah1h6o{justify-content:center}
|
|
5
4
|
._1e0c1txw{display:flex}
|
|
6
5
|
._1reo1wug{overflow-x:auto}
|
|
7
6
|
._1ul91osq{min-width:100%}
|
|
8
|
-
._2lx21bp4{flex-direction:column}
|
|
9
|
-
._4cvr1h6o{align-items:center}
|
|
7
|
+
._2lx21bp4{flex-direction:column}
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
import "./documentViewer.compiled.css";
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { ax, ix } from "@compiled/react/runtime";
|
|
5
|
+
import { useLayoutEffect, useRef } from 'react';
|
|
5
6
|
import { Page } from './page';
|
|
6
7
|
import { usePageContent } from './usePageContent';
|
|
8
|
+
import { getScrollElement } from './utils/getDocumentRoot';
|
|
7
9
|
import { useCachedGetImage } from './utils/useCachedGetImage';
|
|
8
10
|
const documentViewerStyles = null;
|
|
9
11
|
const DEFAULT_PAGINATION_SIZE = 50;
|
|
@@ -24,10 +26,39 @@ export const DocumentViewer = ({
|
|
|
24
26
|
const style = {
|
|
25
27
|
'--document-viewer-zoom': zoom
|
|
26
28
|
};
|
|
29
|
+
const previousZoomRef = useRef(zoom);
|
|
30
|
+
|
|
31
|
+
// Apply zoom with center-based adjustment
|
|
32
|
+
useLayoutEffect(() => {
|
|
33
|
+
const previousZoom = previousZoomRef.current;
|
|
34
|
+
|
|
35
|
+
// Only adjust scroll if zoom actually changed
|
|
36
|
+
if (previousZoom !== zoom) {
|
|
37
|
+
// If we are not using a custom scroll element, we don't need to adjust the scroll position
|
|
38
|
+
const container = getScrollElement();
|
|
39
|
+
if (!container) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Calculate the center point of the viewport before zoom
|
|
44
|
+
const viewportCenterX = container.scrollLeft + container.clientWidth / 2;
|
|
45
|
+
const viewportCenterY = container.scrollTop + container.clientHeight / 2;
|
|
46
|
+
|
|
47
|
+
// Calculate scale difference
|
|
48
|
+
const scaleDiff = zoom / previousZoom - 1;
|
|
49
|
+
|
|
50
|
+
// Adjust scroll to keep center point fixed
|
|
51
|
+
container.scrollLeft += viewportCenterX * scaleDiff;
|
|
52
|
+
container.scrollTop += viewportCenterY * scaleDiff;
|
|
53
|
+
|
|
54
|
+
// Update previous zoom
|
|
55
|
+
previousZoomRef.current = zoom;
|
|
56
|
+
}
|
|
57
|
+
}, [zoom]);
|
|
27
58
|
return /*#__PURE__*/React.createElement("div", {
|
|
28
59
|
"data-testid": "document-viewer",
|
|
29
60
|
style: style,
|
|
30
|
-
className: ax(["_zulputpp _1reo1wug _18m91wug _19pkxncg _1ul91osq _1e0c1txw _2lx21bp4
|
|
61
|
+
className: ax(["_zulputpp _1reo1wug _18m91wug _19pkxncg _1ul91osq _1e0c1txw _2lx21bp4"])
|
|
31
62
|
}, [...Array((_documentMetadata$pag = documentMetadata.pageCount) !== null && _documentMetadata$pag !== void 0 ? _documentMetadata$pag : 4)].map((_, i) => {
|
|
32
63
|
const {
|
|
33
64
|
page,
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
._154iidpf{top:0}
|
|
2
|
+
._18u01wug{margin-left:auto}
|
|
3
|
+
._1bah1h6o{justify-content:center}
|
|
4
|
+
._1bsb1osq{width:100%}
|
|
5
|
+
._1e0c1txw{display:flex}
|
|
2
6
|
._1kemd8h4{image-rendering:pixelated}
|
|
3
7
|
._1ltvidpf{left:0}
|
|
8
|
+
._2hwx1wug{margin-right:auto}
|
|
9
|
+
._4cvr1h6o{align-items:center}
|
|
10
|
+
._4t3i1osq{height:100%}
|
|
4
11
|
._80om1kdv{cursor:text}
|
|
5
12
|
._bfhku67f{background-color:#fff}
|
|
6
13
|
._kqswh2mm{position:relative}
|
package/dist/es2019/page.js
CHANGED
|
@@ -4,6 +4,7 @@ import * as React from 'react';
|
|
|
4
4
|
import { ax, ix } from "@compiled/react/runtime";
|
|
5
5
|
import { forwardRef, useEffect, useState } from 'react';
|
|
6
6
|
import { useStaticCallback } from '@atlaskit/media-common';
|
|
7
|
+
import Spinner from '@atlaskit/spinner';
|
|
7
8
|
import { Annotations } from './annotations';
|
|
8
9
|
import { DocumentLinks } from './documentLinks';
|
|
9
10
|
import { getDocumentRoot } from './utils/getDocumentRoot';
|
|
@@ -55,7 +56,12 @@ const Line = ({
|
|
|
55
56
|
})));
|
|
56
57
|
const pageSvgStyles = null;
|
|
57
58
|
const pageImageStyles = null;
|
|
59
|
+
const pageSpinnerStyles = null;
|
|
58
60
|
const pageWrapperStyles = null;
|
|
61
|
+
const a4Dimensions = {
|
|
62
|
+
height: 595,
|
|
63
|
+
width: 842
|
|
64
|
+
};
|
|
59
65
|
const PageView = /*#__PURE__*/forwardRef(({
|
|
60
66
|
dimensions,
|
|
61
67
|
imageSrc,
|
|
@@ -65,17 +71,31 @@ const PageView = /*#__PURE__*/forwardRef(({
|
|
|
65
71
|
zoom,
|
|
66
72
|
onImageLoad
|
|
67
73
|
}, ref) => {
|
|
68
|
-
const style = {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
const style = {};
|
|
75
|
+
if (dimensions) {
|
|
76
|
+
// contents endpoint has loaded so dimensions are available
|
|
77
|
+
style.width = `calc(var(--document-viewer-zoom) * ${dimensions.width}px)`;
|
|
78
|
+
style.height = `calc(var(--document-viewer-zoom) * ${dimensions.height}px)`;
|
|
79
|
+
} else if (imageSrc) {
|
|
80
|
+
// contents endpoint has not loaded dimensions but image is loaded so we can use the image dimensions
|
|
81
|
+
style.width = 'initial';
|
|
82
|
+
style.height = 'initial';
|
|
83
|
+
} else {
|
|
84
|
+
// contents endpoint has not loaded dimensions and image is not loaded so we can use the a4 dimensions
|
|
85
|
+
style.width = `calc(var(--document-viewer-zoom) * ${a4Dimensions.width}px)`;
|
|
86
|
+
style.height = `calc(var(--document-viewer-zoom) * ${a4Dimensions.height}px)`;
|
|
87
|
+
}
|
|
72
88
|
return /*#__PURE__*/React.createElement("div", {
|
|
73
89
|
ref: ref,
|
|
74
90
|
style: style,
|
|
75
91
|
"data-testid": `page-${pageIndex}`,
|
|
76
92
|
id: `page-${pageIndex + 1}`,
|
|
77
|
-
className: ax(["_kqswh2mm _bfhku67f"])
|
|
78
|
-
}, imageSrc && /*#__PURE__*/React.createElement("
|
|
93
|
+
className: ax(["_kqswh2mm _bfhku67f _18u01wug _2hwx1wug"])
|
|
94
|
+
}, !imageSrc && /*#__PURE__*/React.createElement("div", {
|
|
95
|
+
className: ax(["_4t3i1osq _1bsb1osq _1e0c1txw _1bah1h6o _4cvr1h6o"])
|
|
96
|
+
}, /*#__PURE__*/React.createElement(Spinner, {
|
|
97
|
+
size: "large"
|
|
98
|
+
})), imageSrc && /*#__PURE__*/React.createElement("img", {
|
|
79
99
|
style: style,
|
|
80
100
|
"data-testid": `page-${pageIndex}-image`,
|
|
81
101
|
"data-zoom": zoom,
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
import { getDocument } from '@atlaskit/browser-apis';
|
|
1
2
|
export const DOCUMENT_SCROLL_ROOT_ID = 'document-scroll-root';
|
|
2
3
|
export const getDocumentRoot = () => {
|
|
3
|
-
|
|
4
|
+
const doc = getDocument();
|
|
5
|
+
if (!doc) {
|
|
4
6
|
return;
|
|
5
7
|
}
|
|
6
|
-
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
const root = document.getElementById(DOCUMENT_SCROLL_ROOT_ID);
|
|
8
|
+
const root = doc.getElementById(DOCUMENT_SCROLL_ROOT_ID);
|
|
10
9
|
if (root) {
|
|
11
10
|
return root;
|
|
12
11
|
}
|
|
13
|
-
return
|
|
12
|
+
return doc;
|
|
13
|
+
};
|
|
14
|
+
export const getScrollElement = () => {
|
|
15
|
+
const element = getDocument();
|
|
16
|
+
return element && element.getElementById(DOCUMENT_SCROLL_ROOT_ID);
|
|
14
17
|
};
|
package/dist/esm/annotations.js
CHANGED
|
@@ -26,6 +26,12 @@ export var TextInputFormField = function TextInputFormField(_ref) {
|
|
|
26
26
|
type: "text",
|
|
27
27
|
value: field.text,
|
|
28
28
|
readOnly: true,
|
|
29
|
+
onKeyUp: function onKeyUp(e) {
|
|
30
|
+
// stop propagation of the arrow key events because they can be used to navigate viewports
|
|
31
|
+
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
|
|
32
|
+
e.stopPropagation();
|
|
33
|
+
}
|
|
34
|
+
},
|
|
29
35
|
className: ax(["_19itglyw _ca0qidpf _u5f3idpf _n3tdidpf _19bvidpf _r06hglyw", "_kqswstnw _4t3i1osq _1bsb1osq"])
|
|
30
36
|
})));
|
|
31
37
|
};
|
|
@@ -45,7 +51,14 @@ export var ComboBoxFormField = function ComboBoxFormField(_ref3) {
|
|
|
45
51
|
}), /*#__PURE__*/React.createElement("input", {
|
|
46
52
|
style: _defineProperty({}, 'fontSize', "".concat(field.f, "px")),
|
|
47
53
|
type: "text",
|
|
48
|
-
value: field.text
|
|
54
|
+
value: field.text
|
|
55
|
+
// stop propagation of the arrow key events because they can be used to navigate viewports
|
|
56
|
+
,
|
|
57
|
+
onKeyUp: function onKeyUp(e) {
|
|
58
|
+
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
|
|
59
|
+
e.stopPropagation();
|
|
60
|
+
}
|
|
61
|
+
},
|
|
49
62
|
readOnly: true,
|
|
50
63
|
className: ax(["_19itglyw _ca0qidpf _u5f3idpf _n3tdidpf _19bvidpf _r06hglyw", "_1bsb1osq"])
|
|
51
64
|
}), /*#__PURE__*/React.createElement(ChevronDownIcon, {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
._zulputpp{gap:var(--ds-space-150,9pt)}._18m91wug{overflow-y:auto}
|
|
3
3
|
._19pkxncg{margin-top:var(--ds-space-800,4pc)}
|
|
4
|
-
._1bah1h6o{justify-content:center}
|
|
5
4
|
._1e0c1txw{display:flex}
|
|
6
5
|
._1reo1wug{overflow-x:auto}
|
|
7
6
|
._1ul91osq{min-width:100%}
|
|
8
|
-
._2lx21bp4{flex-direction:column}
|
|
9
|
-
._4cvr1h6o{align-items:center}
|
|
7
|
+
._2lx21bp4{flex-direction:column}
|
|
@@ -3,8 +3,10 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
|
3
3
|
import "./documentViewer.compiled.css";
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { ax, ix } from "@compiled/react/runtime";
|
|
6
|
+
import { useLayoutEffect, useRef } from 'react';
|
|
6
7
|
import { Page } from './page';
|
|
7
8
|
import { usePageContent } from './usePageContent';
|
|
9
|
+
import { getScrollElement } from './utils/getDocumentRoot';
|
|
8
10
|
import { useCachedGetImage } from './utils/useCachedGetImage';
|
|
9
11
|
var documentViewerStyles = null;
|
|
10
12
|
var DEFAULT_PAGINATION_SIZE = 50;
|
|
@@ -24,10 +26,39 @@ export var DocumentViewer = function DocumentViewer(_ref) {
|
|
|
24
26
|
var style = {
|
|
25
27
|
'--document-viewer-zoom': zoom
|
|
26
28
|
};
|
|
29
|
+
var previousZoomRef = useRef(zoom);
|
|
30
|
+
|
|
31
|
+
// Apply zoom with center-based adjustment
|
|
32
|
+
useLayoutEffect(function () {
|
|
33
|
+
var previousZoom = previousZoomRef.current;
|
|
34
|
+
|
|
35
|
+
// Only adjust scroll if zoom actually changed
|
|
36
|
+
if (previousZoom !== zoom) {
|
|
37
|
+
// If we are not using a custom scroll element, we don't need to adjust the scroll position
|
|
38
|
+
var container = getScrollElement();
|
|
39
|
+
if (!container) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Calculate the center point of the viewport before zoom
|
|
44
|
+
var viewportCenterX = container.scrollLeft + container.clientWidth / 2;
|
|
45
|
+
var viewportCenterY = container.scrollTop + container.clientHeight / 2;
|
|
46
|
+
|
|
47
|
+
// Calculate scale difference
|
|
48
|
+
var scaleDiff = zoom / previousZoom - 1;
|
|
49
|
+
|
|
50
|
+
// Adjust scroll to keep center point fixed
|
|
51
|
+
container.scrollLeft += viewportCenterX * scaleDiff;
|
|
52
|
+
container.scrollTop += viewportCenterY * scaleDiff;
|
|
53
|
+
|
|
54
|
+
// Update previous zoom
|
|
55
|
+
previousZoomRef.current = zoom;
|
|
56
|
+
}
|
|
57
|
+
}, [zoom]);
|
|
27
58
|
return /*#__PURE__*/React.createElement("div", {
|
|
28
59
|
"data-testid": "document-viewer",
|
|
29
60
|
style: style,
|
|
30
|
-
className: ax(["_zulputpp _1reo1wug _18m91wug _19pkxncg _1ul91osq _1e0c1txw _2lx21bp4
|
|
61
|
+
className: ax(["_zulputpp _1reo1wug _18m91wug _19pkxncg _1ul91osq _1e0c1txw _2lx21bp4"])
|
|
31
62
|
}, _toConsumableArray(Array((_documentMetadata$pag = documentMetadata.pageCount) !== null && _documentMetadata$pag !== void 0 ? _documentMetadata$pag : 4)).map(function (_, i) {
|
|
32
63
|
var _getPageContent = getPageContent(i),
|
|
33
64
|
page = _getPageContent.page,
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
._154iidpf{top:0}
|
|
2
|
+
._18u01wug{margin-left:auto}
|
|
3
|
+
._1bah1h6o{justify-content:center}
|
|
4
|
+
._1bsb1osq{width:100%}
|
|
5
|
+
._1e0c1txw{display:flex}
|
|
2
6
|
._1kemd8h4{image-rendering:pixelated}
|
|
3
7
|
._1ltvidpf{left:0}
|
|
8
|
+
._2hwx1wug{margin-right:auto}
|
|
9
|
+
._4cvr1h6o{align-items:center}
|
|
10
|
+
._4t3i1osq{height:100%}
|
|
4
11
|
._80om1kdv{cursor:text}
|
|
5
12
|
._bfhku67f{background-color:#fff}
|
|
6
13
|
._kqswh2mm{position:relative}
|
package/dist/esm/page.js
CHANGED
|
@@ -6,6 +6,7 @@ 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 Spinner from '@atlaskit/spinner';
|
|
9
10
|
import { Annotations } from './annotations';
|
|
10
11
|
import { DocumentLinks } from './documentLinks';
|
|
11
12
|
import { getDocumentRoot } from './utils/getDocumentRoot';
|
|
@@ -57,7 +58,12 @@ var Line = function Line() {
|
|
|
57
58
|
};
|
|
58
59
|
var pageSvgStyles = null;
|
|
59
60
|
var pageImageStyles = null;
|
|
61
|
+
var pageSpinnerStyles = null;
|
|
60
62
|
var pageWrapperStyles = null;
|
|
63
|
+
var a4Dimensions = {
|
|
64
|
+
height: 595,
|
|
65
|
+
width: 842
|
|
66
|
+
};
|
|
61
67
|
var PageView = /*#__PURE__*/forwardRef(function (_ref4, ref) {
|
|
62
68
|
var dimensions = _ref4.dimensions,
|
|
63
69
|
imageSrc = _ref4.imageSrc,
|
|
@@ -66,17 +72,31 @@ var PageView = /*#__PURE__*/forwardRef(function (_ref4, ref) {
|
|
|
66
72
|
pageIndex = _ref4.pageIndex,
|
|
67
73
|
zoom = _ref4.zoom,
|
|
68
74
|
onImageLoad = _ref4.onImageLoad;
|
|
69
|
-
var style = {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
var style = {};
|
|
76
|
+
if (dimensions) {
|
|
77
|
+
// contents endpoint has loaded so dimensions are available
|
|
78
|
+
style.width = "calc(var(--document-viewer-zoom) * ".concat(dimensions.width, "px)");
|
|
79
|
+
style.height = "calc(var(--document-viewer-zoom) * ".concat(dimensions.height, "px)");
|
|
80
|
+
} else if (imageSrc) {
|
|
81
|
+
// contents endpoint has not loaded dimensions but image is loaded so we can use the image dimensions
|
|
82
|
+
style.width = 'initial';
|
|
83
|
+
style.height = 'initial';
|
|
84
|
+
} else {
|
|
85
|
+
// contents endpoint has not loaded dimensions and image is not loaded so we can use the a4 dimensions
|
|
86
|
+
style.width = "calc(var(--document-viewer-zoom) * ".concat(a4Dimensions.width, "px)");
|
|
87
|
+
style.height = "calc(var(--document-viewer-zoom) * ".concat(a4Dimensions.height, "px)");
|
|
88
|
+
}
|
|
73
89
|
return /*#__PURE__*/React.createElement("div", {
|
|
74
90
|
ref: ref,
|
|
75
91
|
style: style,
|
|
76
92
|
"data-testid": "page-".concat(pageIndex),
|
|
77
93
|
id: "page-".concat(pageIndex + 1),
|
|
78
|
-
className: ax(["_kqswh2mm _bfhku67f"])
|
|
79
|
-
}, imageSrc && /*#__PURE__*/React.createElement("
|
|
94
|
+
className: ax(["_kqswh2mm _bfhku67f _18u01wug _2hwx1wug"])
|
|
95
|
+
}, !imageSrc && /*#__PURE__*/React.createElement("div", {
|
|
96
|
+
className: ax(["_4t3i1osq _1bsb1osq _1e0c1txw _1bah1h6o _4cvr1h6o"])
|
|
97
|
+
}, /*#__PURE__*/React.createElement(Spinner, {
|
|
98
|
+
size: "large"
|
|
99
|
+
})), imageSrc && /*#__PURE__*/React.createElement("img", {
|
|
80
100
|
style: style,
|
|
81
101
|
"data-testid": "page-".concat(pageIndex, "-image"),
|
|
82
102
|
"data-zoom": zoom,
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
import { getDocument } from '@atlaskit/browser-apis';
|
|
1
2
|
export var DOCUMENT_SCROLL_ROOT_ID = 'document-scroll-root';
|
|
2
3
|
export var getDocumentRoot = function getDocumentRoot() {
|
|
3
|
-
|
|
4
|
+
var doc = getDocument();
|
|
5
|
+
if (!doc) {
|
|
4
6
|
return;
|
|
5
7
|
}
|
|
6
|
-
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
var root = document.getElementById(DOCUMENT_SCROLL_ROOT_ID);
|
|
8
|
+
var root = doc.getElementById(DOCUMENT_SCROLL_ROOT_ID);
|
|
10
9
|
if (root) {
|
|
11
10
|
return root;
|
|
12
11
|
}
|
|
13
|
-
return
|
|
12
|
+
return doc;
|
|
13
|
+
};
|
|
14
|
+
export var getScrollElement = function getScrollElement() {
|
|
15
|
+
var element = getDocument();
|
|
16
|
+
return element && element.getElementById(DOCUMENT_SCROLL_ROOT_ID);
|
|
14
17
|
};
|
package/package.json
CHANGED
|
@@ -27,10 +27,12 @@
|
|
|
27
27
|
".": "./src/index.ts"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
+
"@atlaskit/browser-apis": "^0.0.1",
|
|
30
31
|
"@atlaskit/css": "^0.12.0",
|
|
31
|
-
"@atlaskit/icon": "^27.
|
|
32
|
+
"@atlaskit/icon": "^27.3.0",
|
|
32
33
|
"@atlaskit/media-common": "^12.3.0",
|
|
33
34
|
"@atlaskit/primitives": "^14.10.0",
|
|
35
|
+
"@atlaskit/spinner": "^18.0.0",
|
|
34
36
|
"@atlaskit/tokens": "^5.4.0",
|
|
35
37
|
"@babel/runtime": "^7.0.0",
|
|
36
38
|
"@compiled/react": "^0.18.3"
|
|
@@ -44,6 +46,7 @@
|
|
|
44
46
|
"@atlaskit/ssr": "workspace:^",
|
|
45
47
|
"@atlaskit/visual-regression": "workspace:^",
|
|
46
48
|
"@testing-library/react": "^13.4.0",
|
|
49
|
+
"@testing-library/user-event": "^14.4.3",
|
|
47
50
|
"react-dom": "^18.2.0",
|
|
48
51
|
"typescript": "~5.4.2"
|
|
49
52
|
},
|
|
@@ -83,7 +86,7 @@
|
|
|
83
86
|
}
|
|
84
87
|
},
|
|
85
88
|
"name": "@atlaskit/media-document-viewer",
|
|
86
|
-
"version": "0.3.
|
|
89
|
+
"version": "0.3.2",
|
|
87
90
|
"description": "Modern and fast document viewer",
|
|
88
91
|
"author": "Atlassian Pty Ltd",
|
|
89
92
|
"license": "Apache-2.0",
|