@manuscripts/style-guide 1.0.6 → 1.0.7
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/cjs/index.js +1 -3
- package/dist/es/index.js +0 -1
- package/dist/types/components/FileManager/util.d.ts +0 -1
- package/dist/types/components/icons/add-author.d.ts +0 -1
- package/dist/types/components/icons/add-comment-icon.d.ts +0 -1
- package/dist/types/components/icons/add-icon-active.d.ts +0 -1
- package/dist/types/components/icons/add-icon-inverted.d.ts +0 -1
- package/dist/types/components/icons/back-arrow.d.ts +0 -1
- package/dist/types/components/icons/bookmark.d.ts +0 -1
- package/dist/types/components/icons/google.d.ts +0 -1
- package/dist/types/components/icons/orcid.d.ts +0 -1
- package/dist/types/components/icons/plus-icon.d.ts +0 -1
- package/dist/types/components/icons/project-notification.d.ts +0 -1
- package/dist/types/components/icons/project.d.ts +0 -1
- package/dist/types/components/icons/projects-list.d.ts +0 -1
- package/dist/types/components/icons/search.d.ts +0 -1
- package/dist/types/components/icons/tick-mark.d.ts +0 -1
- package/dist/types/components/icons/user.d.ts +0 -1
- package/dist/types/index.d.ts +0 -1
- package/package.json +35 -37
- package/dist/cjs/components/PdfPreview.js +0 -111
- package/dist/es/components/PdfPreview.js +0 -83
- package/dist/types/components/PdfPreview.d.ts +0 -7
package/dist/cjs/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
32
32
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.SelectDialogDesignation = exports.errorsDecoder = exports.useDeepCompareCallback = exports.useDeepCompareMemo = exports.useFiles =
|
|
35
|
+
exports.SelectDialogDesignation = exports.errorsDecoder = exports.useDeepCompareCallback = exports.useDeepCompareMemo = exports.useFiles = void 0;
|
|
36
36
|
__exportStar(require("./components/AffiliationsEditor"), exports);
|
|
37
37
|
__exportStar(require("./components/AffiliationsList"), exports);
|
|
38
38
|
__exportStar(require("./components/AuthorForm"), exports);
|
|
@@ -66,8 +66,6 @@ __exportStar(require("./components/Inspector"), exports);
|
|
|
66
66
|
__exportStar(require("./components/InspectorSection"), exports);
|
|
67
67
|
__exportStar(require("./components/Badge"), exports);
|
|
68
68
|
__exportStar(require("./components/NavDropdown"), exports);
|
|
69
|
-
var PdfPreview_1 = require("./components/PdfPreview");
|
|
70
|
-
Object.defineProperty(exports, "PdfPreview", { enumerable: true, get: function () { return __importDefault(PdfPreview_1).default; } });
|
|
71
69
|
__exportStar(require("./components/SubmissionInspector"), exports);
|
|
72
70
|
__exportStar(require("./components/Dropdown"), exports);
|
|
73
71
|
__exportStar(require("./hooks/use-dropdown"), exports);
|
package/dist/es/index.js
CHANGED
|
@@ -46,7 +46,6 @@ export * from './components/Inspector';
|
|
|
46
46
|
export * from './components/InspectorSection';
|
|
47
47
|
export * from './components/Badge';
|
|
48
48
|
export * from './components/NavDropdown';
|
|
49
|
-
export { default as PdfPreview } from './components/PdfPreview';
|
|
50
49
|
export * from './components/SubmissionInspector';
|
|
51
50
|
export * from './components/Dropdown';
|
|
52
51
|
export * from './hooks/use-dropdown';
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
/// <reference types="react" />
|
|
17
16
|
import { IconProps } from './types';
|
|
18
17
|
declare const AddAuthor: (props: IconProps) => JSX.Element;
|
|
19
18
|
export default AddAuthor;
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
/// <reference types="react" />
|
|
17
16
|
import { IconProps } from './types';
|
|
18
17
|
declare const AddIconActive: (props: IconProps) => JSX.Element;
|
|
19
18
|
export default AddIconActive;
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
/// <reference types="react" />
|
|
17
16
|
import { IconProps } from './types';
|
|
18
17
|
declare const AddIconInverted: (props: IconProps) => JSX.Element;
|
|
19
18
|
export default AddIconInverted;
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
/// <reference types="react" />
|
|
17
16
|
import { IconProps } from './types';
|
|
18
17
|
export declare const BackArrow: (props: IconProps) => JSX.Element;
|
|
19
18
|
export default BackArrow;
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
/// <reference types="react" />
|
|
17
16
|
import { IconProps } from './types';
|
|
18
17
|
declare const Bookmark: (props: IconProps) => JSX.Element;
|
|
19
18
|
export default Bookmark;
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
/// <reference types="react" />
|
|
17
16
|
import { IconProps } from './types';
|
|
18
17
|
declare const Google: (props: IconProps) => JSX.Element;
|
|
19
18
|
export default Google;
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
/// <reference types="react" />
|
|
17
16
|
import { IconProps } from './types';
|
|
18
17
|
declare const Orcid: (props: IconProps) => JSX.Element;
|
|
19
18
|
export default Orcid;
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
/// <reference types="react" />
|
|
17
16
|
import { IconProps } from './types';
|
|
18
17
|
declare const ProjectNotification: (props: IconProps) => JSX.Element;
|
|
19
18
|
export default ProjectNotification;
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
/// <reference types="react" />
|
|
17
16
|
import { IconProps } from './types';
|
|
18
17
|
declare const ProjectIcon: (props: IconProps) => JSX.Element;
|
|
19
18
|
export default ProjectIcon;
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
/// <reference types="react" />
|
|
17
16
|
import { IconProps } from './types';
|
|
18
17
|
declare const ProjectsList: (props: IconProps) => JSX.Element;
|
|
19
18
|
export default ProjectsList;
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
/// <reference types="react" />
|
|
17
16
|
import { IconProps } from './types';
|
|
18
17
|
declare const SearchIcon: (props: IconProps) => JSX.Element;
|
|
19
18
|
export default SearchIcon;
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
/// <reference types="react" />
|
|
17
16
|
import { IconProps } from './types';
|
|
18
17
|
declare const TickMark: (props: IconProps) => JSX.Element;
|
|
19
18
|
export default TickMark;
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
/// <reference types="react" />
|
|
17
16
|
import { IconProps } from './types';
|
|
18
17
|
declare const User: (props: IconProps) => JSX.Element;
|
|
19
18
|
export default User;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -47,7 +47,6 @@ export * from './components/Inspector';
|
|
|
47
47
|
export * from './components/InspectorSection';
|
|
48
48
|
export * from './components/Badge';
|
|
49
49
|
export * from './components/NavDropdown';
|
|
50
|
-
export { default as PdfPreview } from './components/PdfPreview';
|
|
51
50
|
export * from './components/SubmissionInspector';
|
|
52
51
|
export * from './components/Dropdown';
|
|
53
52
|
export * from './hooks/use-dropdown';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manuscripts/style-guide",
|
|
3
3
|
"description": "Shared components for Manuscripts applications",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.7",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-style-guide",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -32,29 +32,51 @@
|
|
|
32
32
|
"prepare": "husky install"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"@apollo/client": "^3.7.3",
|
|
35
36
|
"@formatjs/intl-relativetimeformat": "^4.5.9",
|
|
36
37
|
"@formatjs/intl-utils": "^2.2.0",
|
|
38
|
+
"@manuscripts/assets": "^0.6.2",
|
|
39
|
+
"@manuscripts/transform": "^1.1.1",
|
|
40
|
+
"@manuscripts/json-schema": "^1.0.0",
|
|
41
|
+
"@manuscripts/title-editor": "^1.1.0",
|
|
42
|
+
"@manuscripts/comment-editor": "^1.0.1",
|
|
43
|
+
"@reach/tabs": "^0.11.2",
|
|
44
|
+
"formik": "^2.2.9",
|
|
37
45
|
"date-fns": "^2.29.3",
|
|
38
46
|
"lodash-es": "^4.17.21",
|
|
39
|
-
"pdfjs-dist": "^3.1.81",
|
|
40
47
|
"tooltip.js": "^1.3.3",
|
|
41
|
-
"typeface-lato": "^1.1.13"
|
|
48
|
+
"typeface-lato": "^1.1.13",
|
|
49
|
+
"prosemirror-commands": "^1.5.0",
|
|
50
|
+
"prosemirror-history": "^1.3.0",
|
|
51
|
+
"prosemirror-inputrules": "^1.2.0",
|
|
52
|
+
"prosemirror-keymap": "^1.2.0",
|
|
53
|
+
"prosemirror-model": "^1.18.3",
|
|
54
|
+
"prosemirror-state": "^1.4.2",
|
|
55
|
+
"prosemirror-transform": "^1.7.0",
|
|
56
|
+
"prosemirror-view": "^1.29.1",
|
|
57
|
+
"react": "^17.0.2",
|
|
58
|
+
"react-color": "^2.19.3",
|
|
59
|
+
"react-dnd": "^11.1.3",
|
|
60
|
+
"react-dnd-html5-backend": "^11.1.3",
|
|
61
|
+
"react-dom": "^17.0.2",
|
|
62
|
+
"react-intl": "^3.12.0",
|
|
63
|
+
"react-modal": "^3.11.2",
|
|
64
|
+
"react-modern-calendar-datepicker": "^3.1.3",
|
|
65
|
+
"react-popper": "^1.3.11",
|
|
66
|
+
"react-router-dom": "^5.2.0",
|
|
67
|
+
"react-select": "^5.0.1",
|
|
68
|
+
"react-sizeme": "^2.6.12",
|
|
69
|
+
"react-tooltip": "^4.2.11",
|
|
70
|
+
"styled-components": "^5.2.0"
|
|
42
71
|
},
|
|
43
72
|
"devDependencies": {
|
|
44
|
-
"@apollo/client": "^3.7.3",
|
|
45
73
|
"@babel/core": "^7.20.5",
|
|
46
74
|
"@babel/preset-env": "^7.20.2",
|
|
47
75
|
"@babel/preset-react": "^7.18.6",
|
|
48
76
|
"@babel/preset-typescript": "^7.18.6",
|
|
49
|
-
"@manuscripts/assets": "^0.6.2",
|
|
50
|
-
"@manuscripts/comment-editor": "^1.0.0",
|
|
51
77
|
"@manuscripts/data": "^0.1.0",
|
|
52
78
|
"@manuscripts/eslint-config": "^0.5.1",
|
|
53
79
|
"@manuscripts/examples": "^0.0.7",
|
|
54
|
-
"@manuscripts/json-schema": "^1.0.0",
|
|
55
|
-
"@manuscripts/title-editor": "^1.0.0",
|
|
56
|
-
"@manuscripts/transform": "^1.0.1",
|
|
57
|
-
"@reach/tabs": "^0.11.2",
|
|
58
80
|
"@storybook/addon-actions": "^6.5.15",
|
|
59
81
|
"@storybook/addons": "^6.5.15",
|
|
60
82
|
"@storybook/core": "^6.5.15",
|
|
@@ -84,36 +106,12 @@
|
|
|
84
106
|
"eslint-plugin-react": "^7.31.11",
|
|
85
107
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
86
108
|
"eslint-plugin-simple-import-sort": "^8.0.0",
|
|
87
|
-
"formik": "^2.2.9",
|
|
88
109
|
"husky": "^8.0.2",
|
|
89
110
|
"jest": "^29.3.1",
|
|
90
111
|
"jest-environment-jsdom": "^29.3.1",
|
|
91
112
|
"npm-run-all": "^4.1.5",
|
|
92
113
|
"prettier": "^2.8.1",
|
|
93
|
-
"prosemirror-commands": "^1.5.0",
|
|
94
|
-
"prosemirror-history": "^1.3.0",
|
|
95
|
-
"prosemirror-inputrules": "^1.2.0",
|
|
96
|
-
"prosemirror-keymap": "^1.2.0",
|
|
97
|
-
"prosemirror-model": "^1.18.3",
|
|
98
|
-
"prosemirror-state": "^1.4.2",
|
|
99
|
-
"prosemirror-transform": "^1.7.0",
|
|
100
|
-
"prosemirror-view": "^1.29.1",
|
|
101
|
-
"react": "^16.13.1",
|
|
102
|
-
"react-color": "^2.19.3",
|
|
103
|
-
"react-dnd": "^11.1.3",
|
|
104
|
-
"react-dnd-html5-backend": "^11.1.3",
|
|
105
|
-
"react-dom": "^16.13.1",
|
|
106
|
-
"react-intl": "^3.12.0",
|
|
107
|
-
"react-is": "^16.13.1",
|
|
108
|
-
"react-modal": "^3.11.2",
|
|
109
|
-
"react-modern-calendar-datepicker": "^3.1.3",
|
|
110
|
-
"react-popper": "^1.3.11",
|
|
111
|
-
"react-router-dom": "^5.2.0",
|
|
112
|
-
"react-select": "^5.0.1",
|
|
113
|
-
"react-sizeme": "^2.6.12",
|
|
114
|
-
"react-tooltip": "^4.2.11",
|
|
115
114
|
"rimraf": "^3.0.0",
|
|
116
|
-
"styled-components": "^5.2.0",
|
|
117
115
|
"typescript": "^4.4.4"
|
|
118
116
|
},
|
|
119
117
|
"peerDependencies": {
|
|
@@ -133,11 +131,11 @@
|
|
|
133
131
|
"prosemirror-state": "^1.4.2",
|
|
134
132
|
"prosemirror-transform": "^1.7.0",
|
|
135
133
|
"prosemirror-view": "^1.29.1",
|
|
136
|
-
"react": "^
|
|
134
|
+
"react": "^17.0.2",
|
|
137
135
|
"react-color": "^2.19.3",
|
|
138
136
|
"react-dnd": "^11.1.3",
|
|
139
137
|
"react-dnd-html5-backend": "^11.1.3",
|
|
140
|
-
"react-dom": "^
|
|
138
|
+
"react-dom": "^17.0.2",
|
|
141
139
|
"react-intl": "^3.12.0",
|
|
142
140
|
"react-modal": "^3.11.2",
|
|
143
141
|
"react-modern-calendar-datepicker": "^3.1.3",
|
|
@@ -148,6 +146,6 @@
|
|
|
148
146
|
"react-tooltip": "^4.2.11"
|
|
149
147
|
},
|
|
150
148
|
"resolutions": {
|
|
151
|
-
"@types/react": "^
|
|
149
|
+
"@types/react": "^17.0.2"
|
|
152
150
|
}
|
|
153
151
|
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
require("pdfjs-dist/web/pdf_viewer.css");
|
|
30
|
-
const pdf_1 = require("pdfjs-dist/build/pdf");
|
|
31
|
-
const pdfjsWorker = __importStar(require("pdfjs-dist/build/pdf.worker.entry"));
|
|
32
|
-
const pdf_viewer_1 = require("pdfjs-dist/web/pdf_viewer");
|
|
33
|
-
const react_1 = __importStar(require("react"));
|
|
34
|
-
const styled_components_1 = __importDefault(require("styled-components"));
|
|
35
|
-
pdf_1.GlobalWorkerOptions.workerSrc = pdfjsWorker;
|
|
36
|
-
const PdfPreview = ({ url, scale = 1, }) => {
|
|
37
|
-
const [pdfViewer, setPdfViewer] = (0, react_1.useState)({
|
|
38
|
-
currentScaleValue: scale,
|
|
39
|
-
});
|
|
40
|
-
const [error, setError] = (0, react_1.useState)(null);
|
|
41
|
-
const [progress, setProgress] = (0, react_1.useState)(null);
|
|
42
|
-
const [eventBus, setEventBus] = (0, react_1.useState)(null);
|
|
43
|
-
const nodeRef = (0, react_1.useRef)(null);
|
|
44
|
-
(0, react_1.useEffect)(() => {
|
|
45
|
-
const container = nodeRef.current;
|
|
46
|
-
const eventBus = new pdf_viewer_1.EventBus();
|
|
47
|
-
const pdfViewer = new pdf_viewer_1.PDFViewer({
|
|
48
|
-
container,
|
|
49
|
-
eventBus,
|
|
50
|
-
});
|
|
51
|
-
setPdfViewer(pdfViewer);
|
|
52
|
-
setEventBus(eventBus);
|
|
53
|
-
const loadingTask = (0, pdf_1.getDocument)({
|
|
54
|
-
url,
|
|
55
|
-
withCredentials: true,
|
|
56
|
-
});
|
|
57
|
-
loadingTask.onProgress = (progressData) => setProgress(progressData);
|
|
58
|
-
loadingTask.promise
|
|
59
|
-
.then((pdfDocument) => {
|
|
60
|
-
pdfViewer.setDocument(pdfDocument);
|
|
61
|
-
return true;
|
|
62
|
-
}, (exception) => {
|
|
63
|
-
setError(exception);
|
|
64
|
-
})
|
|
65
|
-
.catch((err) => {
|
|
66
|
-
setError(err);
|
|
67
|
-
});
|
|
68
|
-
}, [url]);
|
|
69
|
-
(0, react_1.useEffect)(() => {
|
|
70
|
-
pdfViewer.currentScaleValue = scale;
|
|
71
|
-
if (eventBus) {
|
|
72
|
-
eventBus.on('pagesinit', () => (pdfViewer.currentScaleValue = scale));
|
|
73
|
-
}
|
|
74
|
-
}, [pdfViewer, eventBus, scale]);
|
|
75
|
-
if (error) {
|
|
76
|
-
return react_1.default.createElement(Error, null, "Unable to download PDF file");
|
|
77
|
-
}
|
|
78
|
-
return (react_1.default.createElement(ViewerContainer, { ref: nodeRef, id: 'viewerContainer' },
|
|
79
|
-
react_1.default.createElement("div", { id: "viewer", className: "pdfViewer" }),
|
|
80
|
-
progress != null ? (progress.total > progress.loaded && (react_1.default.createElement(Container, null,
|
|
81
|
-
react_1.default.createElement(ProgressContainer, null,
|
|
82
|
-
react_1.default.createElement(Progress, { progress: (progress.loaded / progress.total) * 100 },
|
|
83
|
-
((progress.loaded / progress.total) * 100).toFixed(),
|
|
84
|
-
"%"))))) : (react_1.default.createElement(Container, null, 'Loading\u2026'))));
|
|
85
|
-
};
|
|
86
|
-
exports.default = PdfPreview;
|
|
87
|
-
const ViewerContainer = styled_components_1.default.div `
|
|
88
|
-
position: absolute;
|
|
89
|
-
width: 100%;
|
|
90
|
-
`;
|
|
91
|
-
const Container = styled_components_1.default.div `
|
|
92
|
-
position: fixed;
|
|
93
|
-
top: 50%;
|
|
94
|
-
right: 50%;
|
|
95
|
-
`;
|
|
96
|
-
const ProgressContainer = styled_components_1.default.div `
|
|
97
|
-
width: ${(props) => props.theme.grid.unit * 50}px;
|
|
98
|
-
height: ${(props) => props.theme.grid.unit * 7}px;
|
|
99
|
-
overflow: hidden;
|
|
100
|
-
background: ${(props) => props.theme.colors.background.secondary};
|
|
101
|
-
`;
|
|
102
|
-
const Progress = styled_components_1.default.div `
|
|
103
|
-
height: 100%;
|
|
104
|
-
display: block;
|
|
105
|
-
width: ${(props) => props.progress}%;
|
|
106
|
-
background: ${(props) => props.theme.colors.background.success};
|
|
107
|
-
text-align: center;
|
|
108
|
-
`;
|
|
109
|
-
const Error = (0, styled_components_1.default)(Container) `
|
|
110
|
-
color: ${(props) => props.theme.colors.text.error};
|
|
111
|
-
`;
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import 'pdfjs-dist/web/pdf_viewer.css';
|
|
2
|
-
import { getDocument, GlobalWorkerOptions } from 'pdfjs-dist/build/pdf';
|
|
3
|
-
import * as pdfjsWorker from 'pdfjs-dist/build/pdf.worker.entry';
|
|
4
|
-
import { EventBus, PDFViewer } from 'pdfjs-dist/web/pdf_viewer';
|
|
5
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
6
|
-
import styled from 'styled-components';
|
|
7
|
-
GlobalWorkerOptions.workerSrc = pdfjsWorker;
|
|
8
|
-
const PdfPreview = ({ url, scale = 1, }) => {
|
|
9
|
-
const [pdfViewer, setPdfViewer] = useState({
|
|
10
|
-
currentScaleValue: scale,
|
|
11
|
-
});
|
|
12
|
-
const [error, setError] = useState(null);
|
|
13
|
-
const [progress, setProgress] = useState(null);
|
|
14
|
-
const [eventBus, setEventBus] = useState(null);
|
|
15
|
-
const nodeRef = useRef(null);
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
const container = nodeRef.current;
|
|
18
|
-
const eventBus = new EventBus();
|
|
19
|
-
const pdfViewer = new PDFViewer({
|
|
20
|
-
container,
|
|
21
|
-
eventBus,
|
|
22
|
-
});
|
|
23
|
-
setPdfViewer(pdfViewer);
|
|
24
|
-
setEventBus(eventBus);
|
|
25
|
-
const loadingTask = getDocument({
|
|
26
|
-
url,
|
|
27
|
-
withCredentials: true,
|
|
28
|
-
});
|
|
29
|
-
loadingTask.onProgress = (progressData) => setProgress(progressData);
|
|
30
|
-
loadingTask.promise
|
|
31
|
-
.then((pdfDocument) => {
|
|
32
|
-
pdfViewer.setDocument(pdfDocument);
|
|
33
|
-
return true;
|
|
34
|
-
}, (exception) => {
|
|
35
|
-
setError(exception);
|
|
36
|
-
})
|
|
37
|
-
.catch((err) => {
|
|
38
|
-
setError(err);
|
|
39
|
-
});
|
|
40
|
-
}, [url]);
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
pdfViewer.currentScaleValue = scale;
|
|
43
|
-
if (eventBus) {
|
|
44
|
-
eventBus.on('pagesinit', () => (pdfViewer.currentScaleValue = scale));
|
|
45
|
-
}
|
|
46
|
-
}, [pdfViewer, eventBus, scale]);
|
|
47
|
-
if (error) {
|
|
48
|
-
return React.createElement(Error, null, "Unable to download PDF file");
|
|
49
|
-
}
|
|
50
|
-
return (React.createElement(ViewerContainer, { ref: nodeRef, id: 'viewerContainer' },
|
|
51
|
-
React.createElement("div", { id: "viewer", className: "pdfViewer" }),
|
|
52
|
-
progress != null ? (progress.total > progress.loaded && (React.createElement(Container, null,
|
|
53
|
-
React.createElement(ProgressContainer, null,
|
|
54
|
-
React.createElement(Progress, { progress: (progress.loaded / progress.total) * 100 },
|
|
55
|
-
((progress.loaded / progress.total) * 100).toFixed(),
|
|
56
|
-
"%"))))) : (React.createElement(Container, null, 'Loading\u2026'))));
|
|
57
|
-
};
|
|
58
|
-
export default PdfPreview;
|
|
59
|
-
const ViewerContainer = styled.div `
|
|
60
|
-
position: absolute;
|
|
61
|
-
width: 100%;
|
|
62
|
-
`;
|
|
63
|
-
const Container = styled.div `
|
|
64
|
-
position: fixed;
|
|
65
|
-
top: 50%;
|
|
66
|
-
right: 50%;
|
|
67
|
-
`;
|
|
68
|
-
const ProgressContainer = styled.div `
|
|
69
|
-
width: ${(props) => props.theme.grid.unit * 50}px;
|
|
70
|
-
height: ${(props) => props.theme.grid.unit * 7}px;
|
|
71
|
-
overflow: hidden;
|
|
72
|
-
background: ${(props) => props.theme.colors.background.secondary};
|
|
73
|
-
`;
|
|
74
|
-
const Progress = styled.div `
|
|
75
|
-
height: 100%;
|
|
76
|
-
display: block;
|
|
77
|
-
width: ${(props) => props.progress}%;
|
|
78
|
-
background: ${(props) => props.theme.colors.background.success};
|
|
79
|
-
text-align: center;
|
|
80
|
-
`;
|
|
81
|
-
const Error = styled(Container) `
|
|
82
|
-
color: ${(props) => props.theme.colors.text.error};
|
|
83
|
-
`;
|