@atlaskit/media-document-viewer 0.2.1 → 0.2.3
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 +16 -0
- package/dist/cjs/page.js +2 -2
- package/dist/cjs/usePageContent.js +2 -2
- package/dist/cjs/utils/useCachedGetImage.js +11 -2
- package/dist/cjs/utils/useIntersectionObserver.js +3 -3
- package/dist/es2019/page.js +1 -1
- package/dist/es2019/usePageContent.js +1 -1
- package/dist/es2019/utils/useCachedGetImage.js +10 -2
- package/dist/es2019/utils/useIntersectionObserver.js +1 -1
- package/dist/esm/page.js +1 -1
- package/dist/esm/usePageContent.js +1 -1
- package/dist/esm/utils/useCachedGetImage.js +11 -2
- package/dist/esm/utils/useIntersectionObserver.js +1 -1
- package/dist/types/usePageContent.d.ts +1 -1
- package/dist/types-ts4.5/usePageContent.d.ts +1 -1
- package/package.json +6 -5
- package/dist/cjs/utils/useStaticCallback.js +0 -14
- package/dist/es2019/utils/useStaticCallback.js +0 -6
- package/dist/esm/utils/useStaticCallback.js +0 -8
- package/dist/types/utils/useStaticCallback.d.ts +0 -1
- package/dist/types-ts4.5/utils/useStaticCallback.d.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/media-document-viewer
|
|
2
2
|
|
|
3
|
+
## 0.2.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 0.2.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#177492](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/177492)
|
|
14
|
+
[`d3012b2a16b3c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/d3012b2a16b3c) -
|
|
15
|
+
Changed from local version of useStaticCallback to a remote version and updated Cache image to
|
|
16
|
+
release object urls on unmount
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 0.2.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/cjs/page.js
CHANGED
|
@@ -13,11 +13,11 @@ var React = _react;
|
|
|
13
13
|
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
|
+
var _mediaCommon = require("@atlaskit/media-common");
|
|
16
17
|
var _annotations = require("./annotations");
|
|
17
18
|
var _documentLinks = require("./documentLinks");
|
|
18
19
|
var _getDocumentRoot = require("./utils/getDocumentRoot");
|
|
19
20
|
var _useIntersectionObserver = require("./utils/useIntersectionObserver");
|
|
20
|
-
var _useStaticCallback = require("./utils/useStaticCallback");
|
|
21
21
|
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); }
|
|
22
22
|
var Span = function Span(_ref) {
|
|
23
23
|
var span = _ref.span,
|
|
@@ -141,7 +141,7 @@ var Page = exports.Page = function Page(_ref5) {
|
|
|
141
141
|
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
142
142
|
dimensions = _useState4[0],
|
|
143
143
|
setDimensions = _useState4[1];
|
|
144
|
-
var onImageLoad = (0,
|
|
144
|
+
var onImageLoad = (0, _mediaCommon.useStaticCallback)(function (event) {
|
|
145
145
|
var image = event.currentTarget;
|
|
146
146
|
if (!content) {
|
|
147
147
|
var _zoom = image.dataset.zoom ? Number(image.dataset.zoom) : 1;
|
|
@@ -10,14 +10,14 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
|
|
|
10
10
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
11
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
12
|
var _react = require("react");
|
|
13
|
-
var
|
|
13
|
+
var _mediaCommon = require("@atlaskit/media-common");
|
|
14
14
|
function usePageContent(getContent, paginationSize) {
|
|
15
15
|
var _useState = (0, _react.useState)([]),
|
|
16
16
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
17
17
|
contentRanges = _useState2[0],
|
|
18
18
|
setContentRanges = _useState2[1];
|
|
19
19
|
var contentRangesRequestRef = (0, _react.useRef)({});
|
|
20
|
-
var loadPageContent = (0,
|
|
20
|
+
var loadPageContent = (0, _mediaCommon.useStaticCallback)( /*#__PURE__*/function () {
|
|
21
21
|
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(pageInd) {
|
|
22
22
|
var _contentRangesRequest, _contentRangesRequest2;
|
|
23
23
|
var contentRangeInd, startIndex, endIndex, content;
|
|
@@ -8,10 +8,19 @@ exports.useCachedGetImage = void 0;
|
|
|
8
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
9
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
10
|
var _react = require("react");
|
|
11
|
-
var
|
|
11
|
+
var _mediaCommon = require("@atlaskit/media-common");
|
|
12
12
|
var useCachedGetImage = exports.useCachedGetImage = function useCachedGetImage(getPageImageUrl) {
|
|
13
13
|
var imageUrlRefs = (0, _react.useRef)({});
|
|
14
|
-
|
|
14
|
+
(0, _react.useEffect)(function () {
|
|
15
|
+
return function () {
|
|
16
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
17
|
+
for (var _i = 0, _Object$values = Object.values(imageUrlRefs.current); _i < _Object$values.length; _i++) {
|
|
18
|
+
var url = _Object$values[_i];
|
|
19
|
+
URL.revokeObjectURL(url);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}, []);
|
|
23
|
+
var getImageUrl = (0, _mediaCommon.useStaticCallback)( /*#__PURE__*/function () {
|
|
15
24
|
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(pageNumber, zoom) {
|
|
16
25
|
var key, url, isBlobUrl, blob;
|
|
17
26
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
@@ -7,14 +7,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.useIntersectionObserver = void 0;
|
|
8
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
9
|
var _react = require("react");
|
|
10
|
-
var
|
|
10
|
+
var _mediaCommon = require("@atlaskit/media-common");
|
|
11
11
|
var useIntersectionObserver = exports.useIntersectionObserver = function useIntersectionObserver(options, onVisible) {
|
|
12
|
-
var staticOnVisible = (0,
|
|
12
|
+
var staticOnVisible = (0, _mediaCommon.useStaticCallback)(onVisible);
|
|
13
13
|
var observerRef = (0, _react.useRef)(null);
|
|
14
14
|
var timeoutRef = (0, _react.useRef)(null);
|
|
15
15
|
var isVisibleRef = (0, _react.useRef)(false);
|
|
16
16
|
var currentNodeRef = (0, _react.useRef)(null);
|
|
17
|
-
var observedRef = (0,
|
|
17
|
+
var observedRef = (0, _mediaCommon.useStaticCallback)(function (node) {
|
|
18
18
|
currentNodeRef.current = node;
|
|
19
19
|
if (observerRef.current) {
|
|
20
20
|
observerRef.current.disconnect();
|
package/dist/es2019/page.js
CHANGED
|
@@ -3,11 +3,11 @@ import "./page.compiled.css";
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { ax, ix } from "@compiled/react/runtime";
|
|
5
5
|
import { forwardRef, useEffect, useState } from 'react';
|
|
6
|
+
import { useStaticCallback } from '@atlaskit/media-common';
|
|
6
7
|
import { Annotations } from './annotations';
|
|
7
8
|
import { DocumentLinks } from './documentLinks';
|
|
8
9
|
import { getDocumentRoot } from './utils/getDocumentRoot';
|
|
9
10
|
import { useIntersectionObserver } from './utils/useIntersectionObserver';
|
|
10
|
-
import { useStaticCallback } from './utils/useStaticCallback';
|
|
11
11
|
const Span = ({
|
|
12
12
|
span,
|
|
13
13
|
font
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useMemo, useRef, useState } from 'react';
|
|
2
|
-
import { useStaticCallback } from '
|
|
2
|
+
import { useStaticCallback } from '@atlaskit/media-common';
|
|
3
3
|
export function usePageContent(getContent, paginationSize) {
|
|
4
4
|
const [contentRanges, setContentRanges] = useState([]);
|
|
5
5
|
const contentRangesRequestRef = useRef({});
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import { useRef } from 'react';
|
|
2
|
-
import { useStaticCallback } from '
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { useStaticCallback } from '@atlaskit/media-common';
|
|
3
3
|
export const useCachedGetImage = getPageImageUrl => {
|
|
4
4
|
const imageUrlRefs = useRef({});
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
return () => {
|
|
7
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
8
|
+
for (const url of Object.values(imageUrlRefs.current)) {
|
|
9
|
+
URL.revokeObjectURL(url);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}, []);
|
|
5
13
|
const getImageUrl = useStaticCallback(async (pageNumber, zoom) => {
|
|
6
14
|
const key = `${pageNumber}-${zoom}`;
|
|
7
15
|
if (imageUrlRefs.current[key]) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
|
-
import { useStaticCallback } from '
|
|
2
|
+
import { useStaticCallback } from '@atlaskit/media-common';
|
|
3
3
|
export const useIntersectionObserver = (options, onVisible) => {
|
|
4
4
|
const staticOnVisible = useStaticCallback(onVisible);
|
|
5
5
|
const observerRef = useRef(null);
|
package/dist/esm/page.js
CHANGED
|
@@ -5,11 +5,11 @@ import "./page.compiled.css";
|
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import { ax, ix } from "@compiled/react/runtime";
|
|
7
7
|
import { forwardRef, useEffect, useState } from 'react';
|
|
8
|
+
import { useStaticCallback } from '@atlaskit/media-common';
|
|
8
9
|
import { Annotations } from './annotations';
|
|
9
10
|
import { DocumentLinks } from './documentLinks';
|
|
10
11
|
import { getDocumentRoot } from './utils/getDocumentRoot';
|
|
11
12
|
import { useIntersectionObserver } from './utils/useIntersectionObserver';
|
|
12
|
-
import { useStaticCallback } from './utils/useStaticCallback';
|
|
13
13
|
var Span = function Span(_ref) {
|
|
14
14
|
var span = _ref.span,
|
|
15
15
|
font = _ref.font;
|
|
@@ -3,7 +3,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
3
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
4
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
5
|
import { useMemo, useRef, useState } from 'react';
|
|
6
|
-
import { useStaticCallback } from '
|
|
6
|
+
import { useStaticCallback } from '@atlaskit/media-common';
|
|
7
7
|
export function usePageContent(getContent, paginationSize) {
|
|
8
8
|
var _useState = useState([]),
|
|
9
9
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
-
import { useRef } from 'react';
|
|
4
|
-
import { useStaticCallback } from '
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
import { useStaticCallback } from '@atlaskit/media-common';
|
|
5
5
|
export var useCachedGetImage = function useCachedGetImage(getPageImageUrl) {
|
|
6
6
|
var imageUrlRefs = useRef({});
|
|
7
|
+
useEffect(function () {
|
|
8
|
+
return function () {
|
|
9
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
10
|
+
for (var _i = 0, _Object$values = Object.values(imageUrlRefs.current); _i < _Object$values.length; _i++) {
|
|
11
|
+
var url = _Object$values[_i];
|
|
12
|
+
URL.revokeObjectURL(url);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}, []);
|
|
7
16
|
var getImageUrl = useStaticCallback( /*#__PURE__*/function () {
|
|
8
17
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(pageNumber, zoom) {
|
|
9
18
|
var key, url, isBlobUrl, blob;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
import { useEffect, useRef } from 'react';
|
|
3
|
-
import { useStaticCallback } from '
|
|
3
|
+
import { useStaticCallback } from '@atlaskit/media-common';
|
|
4
4
|
export var useIntersectionObserver = function useIntersectionObserver(options, onVisible) {
|
|
5
5
|
var staticOnVisible = useStaticCallback(onVisible);
|
|
6
6
|
var observerRef = useRef(null);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PageRangeContent } from './types';
|
|
1
|
+
import type { PageRangeContent } from './types';
|
|
2
2
|
export declare function usePageContent(getContent: (startIndex: number, endIndex: number) => Promise<PageRangeContent>, paginationSize: number): {
|
|
3
3
|
getPageContent: (pageInd: number) => {
|
|
4
4
|
page: import("./types").PageContent;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PageRangeContent } from './types';
|
|
1
|
+
import type { PageRangeContent } from './types';
|
|
2
2
|
export declare function usePageContent(getContent: (startIndex: number, endIndex: number) => Promise<PageRangeContent>, paginationSize: number): {
|
|
3
3
|
getPageContent: (pageInd: number) => {
|
|
4
4
|
page: import("./types").PageContent;
|
package/package.json
CHANGED
|
@@ -28,10 +28,11 @@
|
|
|
28
28
|
".": "./src/index.ts"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@atlaskit/css": "^0.
|
|
32
|
-
"@atlaskit/icon": "^27.
|
|
33
|
-
"@atlaskit/
|
|
34
|
-
"@atlaskit/
|
|
31
|
+
"@atlaskit/css": "^0.12.0",
|
|
32
|
+
"@atlaskit/icon": "^27.2.0",
|
|
33
|
+
"@atlaskit/media-common": "^12.3.0",
|
|
34
|
+
"@atlaskit/primitives": "^14.10.0",
|
|
35
|
+
"@atlaskit/tokens": "^5.4.0",
|
|
35
36
|
"@babel/runtime": "^7.0.0",
|
|
36
37
|
"@compiled/react": "^0.18.3"
|
|
37
38
|
},
|
|
@@ -83,7 +84,7 @@
|
|
|
83
84
|
}
|
|
84
85
|
},
|
|
85
86
|
"name": "@atlaskit/media-document-viewer",
|
|
86
|
-
"version": "0.2.
|
|
87
|
+
"version": "0.2.3",
|
|
87
88
|
"description": "Modern and fast document viewer",
|
|
88
89
|
"author": "Atlassian Pty Ltd",
|
|
89
90
|
"license": "Apache-2.0",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useStaticCallback = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var useStaticCallback = exports.useStaticCallback = function useStaticCallback(callback) {
|
|
9
|
-
var callbackRef = (0, _react.useRef)(callback);
|
|
10
|
-
callbackRef.current = callback;
|
|
11
|
-
return (0, _react.useCallback)(function () {
|
|
12
|
-
return callbackRef.current.apply(callbackRef, arguments);
|
|
13
|
-
}, []);
|
|
14
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { useCallback, useRef } from 'react';
|
|
2
|
-
export var useStaticCallback = function useStaticCallback(callback) {
|
|
3
|
-
var callbackRef = useRef(callback);
|
|
4
|
-
callbackRef.current = callback;
|
|
5
|
-
return useCallback(function () {
|
|
6
|
-
return callbackRef.current.apply(callbackRef, arguments);
|
|
7
|
-
}, []);
|
|
8
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useStaticCallback: <Params extends any[], Result>(callback: (...args: Params) => Result) => (...args: Params) => Result;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useStaticCallback: <Params extends any[], Result>(callback: (...args: Params) => Result) => (...args: Params) => Result;
|