@manuscripts/style-guide 1.0.6-LEAN-2237 → 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/components/FileManager/FileManager.js +14 -1
- package/dist/cjs/components/FileManager/FileSectionItem/FileInfo.js +3 -1
- package/dist/cjs/components/FileManager/FileSectionItem/FileSectionItem.js +2 -2
- package/dist/cjs/components/FileManager/FileSectionItem/ItemActions.js +1 -0
- package/dist/cjs/components/FileManager/FilesSection.js +13 -6
- package/dist/cjs/index.js +1 -3
- package/dist/es/components/FileManager/FileManager.js +15 -2
- package/dist/es/components/FileManager/FileSectionItem/FileInfo.js +3 -1
- package/dist/es/components/FileManager/FileSectionItem/FileSectionItem.js +2 -2
- package/dist/es/components/FileManager/FileSectionItem/ItemActions.js +1 -0
- package/dist/es/components/FileManager/FilesSection.js +15 -8
- package/dist/es/index.js +0 -1
- package/dist/types/components/FileManager/FileManager.d.ts +1 -0
- package/dist/types/components/FileManager/FileSectionItem/FileInfo.d.ts +5 -0
- package/dist/types/components/FileManager/FileSectionItem/FileSectionItem.d.ts +3 -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
|
@@ -51,10 +51,11 @@ const InlineFilesSection_1 = require("./InlineFilesSection");
|
|
|
51
51
|
const TooltipDiv_1 = require("./TooltipDiv");
|
|
52
52
|
const util_1 = require("./util");
|
|
53
53
|
exports.PermissionsContext = (0, react_1.createContext)(null);
|
|
54
|
-
const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManagement: { getAttachments, replace, upload }, addAttachmentToState, }) => {
|
|
54
|
+
const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManagement: { getAttachments, changeDesignation, replace, upload }, addAttachmentToState, }) => {
|
|
55
55
|
const [state, dispatch] = (0, react_1.useReducer)(FileSectionState_1.reducer, (0, FileSectionState_1.getInitialState)());
|
|
56
56
|
const handleReplaceFile = (0, react_1.useCallback)((attachmentId, name, file, typeId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
57
|
dispatch(FileSectionState_1.actions.HANDLE_UPLOAD_ACTION());
|
|
58
|
+
dispatch(FileSectionState_1.actions.SELECT_DESIGNATION(util_1.namesWithDesignationMap.get(typeId) || util_1.Designation.Document));
|
|
58
59
|
const res = yield replace(attachmentId, name, file, typeId);
|
|
59
60
|
dispatch(FileSectionState_1.actions.HANDLE_FINISH_UPLOAD());
|
|
60
61
|
if (res) {
|
|
@@ -64,6 +65,9 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
|
|
|
64
65
|
}), [replace]);
|
|
65
66
|
const handleUploadFile = (0, react_1.useCallback)((file, designation) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
67
|
dispatch(FileSectionState_1.actions.HANDLE_UPLOAD_ACTION());
|
|
68
|
+
if (util_1.namesWithDesignationMap.get(designation) == util_1.Designation.Supplementary) {
|
|
69
|
+
dispatch(FileSectionState_1.actions.SELECT_DESIGNATION(util_1.Designation.Supplementary));
|
|
70
|
+
}
|
|
67
71
|
const res = yield upload(file, designation);
|
|
68
72
|
dispatch(FileSectionState_1.actions.HANDLE_FINISH_UPLOAD());
|
|
69
73
|
if (res) {
|
|
@@ -83,6 +87,13 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
|
|
|
83
87
|
}
|
|
84
88
|
return response;
|
|
85
89
|
}), [upload, saveModel]);
|
|
90
|
+
const handleChangeDesignationFile = (0, react_1.useCallback)((attachmentId, typeId, name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
|
+
const res = yield changeDesignation(attachmentId, typeId, name);
|
|
92
|
+
if (res) {
|
|
93
|
+
dispatch(FileSectionState_1.actions.HANDLE_SUCCESS_MESSAGE(''));
|
|
94
|
+
}
|
|
95
|
+
return res;
|
|
96
|
+
}), [changeDesignation]);
|
|
86
97
|
const handleDownload = (0, react_1.useCallback)((url) => {
|
|
87
98
|
window.location.assign(url);
|
|
88
99
|
}, []);
|
|
@@ -114,9 +125,11 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
|
|
|
114
125
|
externalFile: element.externalFile,
|
|
115
126
|
title: element.title,
|
|
116
127
|
showAttachmentName: isSupplementOrOtherFilesTab,
|
|
128
|
+
showDesignationActions: isSupplementOrOtherFilesTab,
|
|
117
129
|
showReplaceAction: !isOtherFilesTab,
|
|
118
130
|
handleDownload,
|
|
119
131
|
handleReplace: handleReplaceFile,
|
|
132
|
+
handleChangeDesignation: handleChangeDesignationFile,
|
|
120
133
|
dispatch: dispatch,
|
|
121
134
|
};
|
|
122
135
|
if (enableDragAndDrop && isSupplementOrOtherFilesTab) {
|
|
@@ -30,10 +30,12 @@ exports.FileDescription = exports.FileName = exports.FileNameContainer = exports
|
|
|
30
30
|
const react_1 = __importStar(require("react"));
|
|
31
31
|
const styled_components_1 = __importDefault(require("styled-components"));
|
|
32
32
|
const FileManager_1 = require("../FileManager");
|
|
33
|
-
const
|
|
33
|
+
const DesignationActions_1 = require("./DesignationActions");
|
|
34
|
+
const FileInfo = ({ showAttachmentName, showDesignationActions, title, submissionAttachmentName, fileExtension, designation, attachmentId, handleChangeDesignation, dispatch, }) => {
|
|
34
35
|
const fileName = submissionAttachmentName.substring(0, submissionAttachmentName.lastIndexOf('.'));
|
|
35
36
|
const can = (0, react_1.useContext)(FileManager_1.PermissionsContext);
|
|
36
37
|
return (react_1.default.createElement(exports.FileInfoContainer, null,
|
|
38
|
+
showDesignationActions && designation !== undefined && (react_1.default.createElement(DesignationActions_1.DesignationActions, { designation: designation, attachmentId: attachmentId, fileExtension: fileExtension, handleChangeDesignation: handleChangeDesignation, fileName: submissionAttachmentName, dispatch: dispatch, can: can })),
|
|
37
39
|
react_1.default.createElement(exports.FileNameTitleContainer, null,
|
|
38
40
|
react_1.default.createElement(exports.FileTitle, null,
|
|
39
41
|
!showAttachmentName ? fileName : title,
|
|
@@ -14,7 +14,7 @@ const util_1 = require("../util");
|
|
|
14
14
|
const FileInfo_1 = require("./FileInfo");
|
|
15
15
|
const FileTypeIcon_1 = require("./FileTypeIcon");
|
|
16
16
|
const ItemActions_1 = require("./ItemActions");
|
|
17
|
-
const FileSectionItem = ({ externalFile, title, showAttachmentName = false, showReplaceAction = true, handleDownload, handleReplace, dispatch, dragRef, className, style, onClose, isEditor, }) => {
|
|
17
|
+
const FileSectionItem = ({ externalFile, title, showAttachmentName = false, showDesignationActions = false, showReplaceAction = true, handleDownload, handleReplace, handleChangeDesignation, dispatch, dragRef, className, style, onClose, isEditor, }) => {
|
|
18
18
|
const { isOpen, toggleOpen, wrapperRef } = (0, use_dropdown_1.useDropdown)();
|
|
19
19
|
const fileExtension = externalFile.name.substring(externalFile.name.lastIndexOf('.') + 1);
|
|
20
20
|
const designation = util_1.namesWithDesignationMap.get(externalFile.type.label);
|
|
@@ -29,7 +29,7 @@ const FileSectionItem = ({ externalFile, title, showAttachmentName = false, show
|
|
|
29
29
|
}
|
|
30
30
|
} },
|
|
31
31
|
react_1.default.createElement(FileTypeIcon_1.FileTypeIcon, { withDot: isMainManuscript, fileExtension: fileExtension, alt: externalFile.name }),
|
|
32
|
-
react_1.default.createElement(FileInfo_1.FileInfo, { fileExtension: fileExtension, showAttachmentName: showAttachmentName, submissionAttachmentName: externalFile.name, title: title, attachmentId: externalFile.id, dispatch: dispatch })),
|
|
32
|
+
react_1.default.createElement(FileInfo_1.FileInfo, { fileExtension: fileExtension, showAttachmentName: showAttachmentName, showDesignationActions: showDesignationActions, submissionAttachmentName: externalFile.name, title: title, designation: designation, attachmentId: externalFile.id, handleChangeDesignation: handleChangeDesignation, dispatch: dispatch })),
|
|
33
33
|
onClose && (react_1.default.createElement(IconCloseButton, { onClick: (e) => {
|
|
34
34
|
e.preventDefault();
|
|
35
35
|
onClose();
|
|
@@ -62,6 +62,7 @@ const ItemActions = ({ downloadAttachmentHandler, replaceAttachmentHandler, deta
|
|
|
62
62
|
setSelectedFile(file);
|
|
63
63
|
if (dispatch) {
|
|
64
64
|
dispatch(FileSectionState_1.actions.HANDLE_UPLOAD_ACTION());
|
|
65
|
+
dispatch(FileSectionState_1.actions.SELECT_DESIGNATION(attachmentDesignationName || util_1.Designation.Document));
|
|
65
66
|
}
|
|
66
67
|
const result = yield replaceAttachmentHandler(attachmentId, fileName, file, attachmentDesignation);
|
|
67
68
|
if (typeof result === 'object' && handleUpdateInline) {
|
|
@@ -30,6 +30,7 @@ const DragItemArea_1 = require("./DragItemArea");
|
|
|
30
30
|
const FileManager_1 = require("./FileManager");
|
|
31
31
|
const FileSectionUploadItem_1 = require("./FileSectionItem/FileSectionUploadItem");
|
|
32
32
|
const FileSectionState_1 = require("./FileSectionState");
|
|
33
|
+
const SelectDialogDesignation_1 = require("./SelectDialogDesignation");
|
|
33
34
|
const UploadFileArea_1 = require("./UploadFileArea");
|
|
34
35
|
const util_1 = require("./util");
|
|
35
36
|
const FilesSection = ({ enableDragAndDrop, handleUpload, fileSection, filesItem, dispatch, state, }) => {
|
|
@@ -39,12 +40,13 @@ const FilesSection = ({ enableDragAndDrop, handleUpload, fileSection, filesItem,
|
|
|
39
40
|
}
|
|
40
41
|
const isSupplementFilesTab = fileSection === util_1.FileSectionType.Supplements;
|
|
41
42
|
const isOtherFileTab = fileSection === util_1.FileSectionType.OtherFile;
|
|
42
|
-
const
|
|
43
|
-
const EMPTY_DESIGNATION = '';
|
|
44
|
-
(0, react_1.useEffect)(() => {
|
|
43
|
+
const handleUploadOtherFile = () => {
|
|
45
44
|
dispatch(FileSectionState_1.actions.HANDLE_UPLOAD_ACTION());
|
|
46
|
-
state.uploadedFile &&
|
|
47
|
-
|
|
45
|
+
state.uploadedFile &&
|
|
46
|
+
state.selectDesignation !== undefined &&
|
|
47
|
+
handleUpload(state.uploadedFile, (0, util_1.getDesignationName)(state.selectDesignation));
|
|
48
|
+
};
|
|
49
|
+
const can = (0, react_1.useContext)(FileManager_1.PermissionsContext);
|
|
48
50
|
const handleSuccessMessage = () => {
|
|
49
51
|
return (react_1.default.createElement(AlertMessage_1.AlertMessage, { type: AlertMessage_1.AlertMessageType.success, hideCloseButton: true, dismissButton: {
|
|
50
52
|
text: 'OK',
|
|
@@ -54,9 +56,14 @@ const FilesSection = ({ enableDragAndDrop, handleUpload, fileSection, filesItem,
|
|
|
54
56
|
return (react_1.default.createElement("div", null,
|
|
55
57
|
(can === null || can === void 0 ? void 0 : can.uploadFile) && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
56
58
|
(isOtherFileTab || isSupplementFilesTab) && (react_1.default.createElement(UploadFileArea_1.UploadFileArea, { handleUploadFile: handleUpload, fileSection: fileSection, dispatch: dispatch })),
|
|
57
|
-
state.isUploadFile &&
|
|
59
|
+
state.isUploadFile &&
|
|
60
|
+
state.uploadedFile &&
|
|
61
|
+
state.selectDesignation !== undefined && (react_1.default.createElement(FileSectionUploadItem_1.FileSectionUploadItem, { fileName: state.uploadedFile.name, isLoading: state.isUploadFile })))),
|
|
58
62
|
state.fileUploadedSuccessfullySection === fileSection &&
|
|
59
63
|
handleSuccessMessage(),
|
|
64
|
+
react_1.default.createElement(SelectDialogDesignation_1.SelectDialogDesignation, { isOpen: state.showDesignationPopup === fileSection, fileExtension: uploadedFileExtension, handleCancel: () => {
|
|
65
|
+
dispatch(FileSectionState_1.actions.HANDLE_CANCEL_UPLOAD());
|
|
66
|
+
}, uploadFileHandler: handleUploadOtherFile, dispatch: dispatch, fileSection: fileSection }),
|
|
60
67
|
filesItem,
|
|
61
68
|
(can === null || can === void 0 ? void 0 : can.changeDesignation) &&
|
|
62
69
|
enableDragAndDrop &&
|
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);
|
|
@@ -20,12 +20,13 @@ import { actions, getInitialState, reducer } from './FileSectionState';
|
|
|
20
20
|
import { FilesSection } from './FilesSection';
|
|
21
21
|
import { InlineFilesSection } from './InlineFilesSection';
|
|
22
22
|
import { TooltipDiv } from './TooltipDiv';
|
|
23
|
-
import { generateAttachmentsTitles } from './util';
|
|
23
|
+
import { Designation, generateAttachmentsTitles, namesWithDesignationMap, } from './util';
|
|
24
24
|
export const PermissionsContext = createContext(null);
|
|
25
|
-
export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManagement: { getAttachments, replace, upload }, addAttachmentToState, }) => {
|
|
25
|
+
export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManagement: { getAttachments, changeDesignation, replace, upload }, addAttachmentToState, }) => {
|
|
26
26
|
const [state, dispatch] = useReducer(reducer, getInitialState());
|
|
27
27
|
const handleReplaceFile = useCallback((attachmentId, name, file, typeId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
28
|
dispatch(actions.HANDLE_UPLOAD_ACTION());
|
|
29
|
+
dispatch(actions.SELECT_DESIGNATION(namesWithDesignationMap.get(typeId) || Designation.Document));
|
|
29
30
|
const res = yield replace(attachmentId, name, file, typeId);
|
|
30
31
|
dispatch(actions.HANDLE_FINISH_UPLOAD());
|
|
31
32
|
if (res) {
|
|
@@ -35,6 +36,9 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
|
|
|
35
36
|
}), [replace]);
|
|
36
37
|
const handleUploadFile = useCallback((file, designation) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
38
|
dispatch(actions.HANDLE_UPLOAD_ACTION());
|
|
39
|
+
if (namesWithDesignationMap.get(designation) == Designation.Supplementary) {
|
|
40
|
+
dispatch(actions.SELECT_DESIGNATION(Designation.Supplementary));
|
|
41
|
+
}
|
|
38
42
|
const res = yield upload(file, designation);
|
|
39
43
|
dispatch(actions.HANDLE_FINISH_UPLOAD());
|
|
40
44
|
if (res) {
|
|
@@ -54,6 +58,13 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
|
|
|
54
58
|
}
|
|
55
59
|
return response;
|
|
56
60
|
}), [upload, saveModel]);
|
|
61
|
+
const handleChangeDesignationFile = useCallback((attachmentId, typeId, name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
+
const res = yield changeDesignation(attachmentId, typeId, name);
|
|
63
|
+
if (res) {
|
|
64
|
+
dispatch(actions.HANDLE_SUCCESS_MESSAGE(''));
|
|
65
|
+
}
|
|
66
|
+
return res;
|
|
67
|
+
}), [changeDesignation]);
|
|
57
68
|
const handleDownload = useCallback((url) => {
|
|
58
69
|
window.location.assign(url);
|
|
59
70
|
}, []);
|
|
@@ -85,9 +96,11 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
|
|
|
85
96
|
externalFile: element.externalFile,
|
|
86
97
|
title: element.title,
|
|
87
98
|
showAttachmentName: isSupplementOrOtherFilesTab,
|
|
99
|
+
showDesignationActions: isSupplementOrOtherFilesTab,
|
|
88
100
|
showReplaceAction: !isOtherFilesTab,
|
|
89
101
|
handleDownload,
|
|
90
102
|
handleReplace: handleReplaceFile,
|
|
103
|
+
handleChangeDesignation: handleChangeDesignationFile,
|
|
91
104
|
dispatch: dispatch,
|
|
92
105
|
};
|
|
93
106
|
if (enableDragAndDrop && isSupplementOrOtherFilesTab) {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React, { useContext } from 'react';
|
|
2
2
|
import styled from 'styled-components';
|
|
3
3
|
import { PermissionsContext } from '../FileManager';
|
|
4
|
-
|
|
4
|
+
import { DesignationActions } from './DesignationActions';
|
|
5
|
+
export const FileInfo = ({ showAttachmentName, showDesignationActions, title, submissionAttachmentName, fileExtension, designation, attachmentId, handleChangeDesignation, dispatch, }) => {
|
|
5
6
|
const fileName = submissionAttachmentName.substring(0, submissionAttachmentName.lastIndexOf('.'));
|
|
6
7
|
const can = useContext(PermissionsContext);
|
|
7
8
|
return (React.createElement(FileInfoContainer, null,
|
|
9
|
+
showDesignationActions && designation !== undefined && (React.createElement(DesignationActions, { designation: designation, attachmentId: attachmentId, fileExtension: fileExtension, handleChangeDesignation: handleChangeDesignation, fileName: submissionAttachmentName, dispatch: dispatch, can: can })),
|
|
8
10
|
React.createElement(FileNameTitleContainer, null,
|
|
9
11
|
React.createElement(FileTitle, null,
|
|
10
12
|
!showAttachmentName ? fileName : title,
|
|
@@ -8,7 +8,7 @@ import { Designation, namesWithDesignationMap } from '../util';
|
|
|
8
8
|
import { FileInfo } from './FileInfo';
|
|
9
9
|
import { FileTypeIcon } from './FileTypeIcon';
|
|
10
10
|
import { ItemActions } from './ItemActions';
|
|
11
|
-
export const FileSectionItem = ({ externalFile, title, showAttachmentName = false, showReplaceAction = true, handleDownload, handleReplace, dispatch, dragRef, className, style, onClose, isEditor, }) => {
|
|
11
|
+
export const FileSectionItem = ({ externalFile, title, showAttachmentName = false, showDesignationActions = false, showReplaceAction = true, handleDownload, handleReplace, handleChangeDesignation, dispatch, dragRef, className, style, onClose, isEditor, }) => {
|
|
12
12
|
const { isOpen, toggleOpen, wrapperRef } = useDropdown();
|
|
13
13
|
const fileExtension = externalFile.name.substring(externalFile.name.lastIndexOf('.') + 1);
|
|
14
14
|
const designation = namesWithDesignationMap.get(externalFile.type.label);
|
|
@@ -23,7 +23,7 @@ export const FileSectionItem = ({ externalFile, title, showAttachmentName = fals
|
|
|
23
23
|
}
|
|
24
24
|
} },
|
|
25
25
|
React.createElement(FileTypeIcon, { withDot: isMainManuscript, fileExtension: fileExtension, alt: externalFile.name }),
|
|
26
|
-
React.createElement(FileInfo, { fileExtension: fileExtension, showAttachmentName: showAttachmentName, submissionAttachmentName: externalFile.name, title: title, attachmentId: externalFile.id, dispatch: dispatch })),
|
|
26
|
+
React.createElement(FileInfo, { fileExtension: fileExtension, showAttachmentName: showAttachmentName, showDesignationActions: showDesignationActions, submissionAttachmentName: externalFile.name, title: title, designation: designation, attachmentId: externalFile.id, handleChangeDesignation: handleChangeDesignation, dispatch: dispatch })),
|
|
27
27
|
onClose && (React.createElement(IconCloseButton, { onClick: (e) => {
|
|
28
28
|
e.preventDefault();
|
|
29
29
|
onClose();
|
|
@@ -36,6 +36,7 @@ export const ItemActions = ({ downloadAttachmentHandler, replaceAttachmentHandle
|
|
|
36
36
|
setSelectedFile(file);
|
|
37
37
|
if (dispatch) {
|
|
38
38
|
dispatch(actions.HANDLE_UPLOAD_ACTION());
|
|
39
|
+
dispatch(actions.SELECT_DESIGNATION(attachmentDesignationName || Designation.Document));
|
|
39
40
|
}
|
|
40
41
|
const result = yield replaceAttachmentHandler(attachmentId, fileName, file, attachmentDesignation);
|
|
41
42
|
if (typeof result === 'object' && handleUpdateInline) {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import React, { useContext
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
2
|
import { AlertMessage, AlertMessageType } from '../AlertMessage';
|
|
3
3
|
import { DragItemArea } from './DragItemArea';
|
|
4
4
|
import { PermissionsContext } from './FileManager';
|
|
5
5
|
import { FileSectionUploadItem } from './FileSectionItem/FileSectionUploadItem';
|
|
6
6
|
import { actions } from './FileSectionState';
|
|
7
|
+
import { SelectDialogDesignation } from './SelectDialogDesignation';
|
|
7
8
|
import { UploadFileArea } from './UploadFileArea';
|
|
8
|
-
import { FileSectionType } from './util';
|
|
9
|
+
import { FileSectionType, getDesignationName } from './util';
|
|
9
10
|
export const FilesSection = ({ enableDragAndDrop, handleUpload, fileSection, filesItem, dispatch, state, }) => {
|
|
10
11
|
let uploadedFileExtension = '';
|
|
11
12
|
if (state.uploadedFile) {
|
|
@@ -13,12 +14,13 @@ export const FilesSection = ({ enableDragAndDrop, handleUpload, fileSection, fil
|
|
|
13
14
|
}
|
|
14
15
|
const isSupplementFilesTab = fileSection === FileSectionType.Supplements;
|
|
15
16
|
const isOtherFileTab = fileSection === FileSectionType.OtherFile;
|
|
16
|
-
const
|
|
17
|
-
const EMPTY_DESIGNATION = '';
|
|
18
|
-
useEffect(() => {
|
|
17
|
+
const handleUploadOtherFile = () => {
|
|
19
18
|
dispatch(actions.HANDLE_UPLOAD_ACTION());
|
|
20
|
-
state.uploadedFile &&
|
|
21
|
-
|
|
19
|
+
state.uploadedFile &&
|
|
20
|
+
state.selectDesignation !== undefined &&
|
|
21
|
+
handleUpload(state.uploadedFile, getDesignationName(state.selectDesignation));
|
|
22
|
+
};
|
|
23
|
+
const can = useContext(PermissionsContext);
|
|
22
24
|
const handleSuccessMessage = () => {
|
|
23
25
|
return (React.createElement(AlertMessage, { type: AlertMessageType.success, hideCloseButton: true, dismissButton: {
|
|
24
26
|
text: 'OK',
|
|
@@ -28,9 +30,14 @@ export const FilesSection = ({ enableDragAndDrop, handleUpload, fileSection, fil
|
|
|
28
30
|
return (React.createElement("div", null,
|
|
29
31
|
(can === null || can === void 0 ? void 0 : can.uploadFile) && (React.createElement(React.Fragment, null,
|
|
30
32
|
(isOtherFileTab || isSupplementFilesTab) && (React.createElement(UploadFileArea, { handleUploadFile: handleUpload, fileSection: fileSection, dispatch: dispatch })),
|
|
31
|
-
state.isUploadFile &&
|
|
33
|
+
state.isUploadFile &&
|
|
34
|
+
state.uploadedFile &&
|
|
35
|
+
state.selectDesignation !== undefined && (React.createElement(FileSectionUploadItem, { fileName: state.uploadedFile.name, isLoading: state.isUploadFile })))),
|
|
32
36
|
state.fileUploadedSuccessfullySection === fileSection &&
|
|
33
37
|
handleSuccessMessage(),
|
|
38
|
+
React.createElement(SelectDialogDesignation, { isOpen: state.showDesignationPopup === fileSection, fileExtension: uploadedFileExtension, handleCancel: () => {
|
|
39
|
+
dispatch(actions.HANDLE_CANCEL_UPLOAD());
|
|
40
|
+
}, uploadFileHandler: handleUploadOtherFile, dispatch: dispatch, fileSection: fileSection }),
|
|
34
41
|
filesItem,
|
|
35
42
|
(can === null || can === void 0 ? void 0 : can.changeDesignation) &&
|
|
36
43
|
enableDragAndDrop &&
|
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';
|
|
@@ -10,6 +10,7 @@ export interface FileManagement {
|
|
|
10
10
|
getAttachments: () => SubmissionAttachment[];
|
|
11
11
|
upload: Upload;
|
|
12
12
|
replace: Replace;
|
|
13
|
+
changeDesignation: ChangeDesignation;
|
|
13
14
|
}
|
|
14
15
|
export declare const PermissionsContext: React.Context<Capabilities | null>;
|
|
15
16
|
export declare const FileManager: React.FC<{
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import React, { Dispatch } from 'react';
|
|
2
|
+
import { ChangeDesignation } from '../FileManager';
|
|
2
3
|
import { Action } from '../FileSectionState';
|
|
4
|
+
import { Designation } from '../util';
|
|
3
5
|
export declare const FileInfo: React.FC<{
|
|
4
6
|
showAttachmentName: boolean;
|
|
7
|
+
showDesignationActions: boolean;
|
|
5
8
|
title: string;
|
|
6
9
|
submissionAttachmentName: string;
|
|
7
10
|
fileExtension: string;
|
|
11
|
+
designation?: Designation;
|
|
8
12
|
attachmentId: string;
|
|
13
|
+
handleChangeDesignation: ChangeDesignation;
|
|
9
14
|
dispatch?: Dispatch<Action>;
|
|
10
15
|
}>;
|
|
11
16
|
export declare const FileInfoContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { CSSProperties, Dispatch } from 'react';
|
|
2
2
|
import { DragElementWrapper, DragSourceOptions } from 'react-dnd';
|
|
3
3
|
import { Maybe } from '../../SubmissionInspector/types';
|
|
4
|
-
import { Replace } from '../FileManager';
|
|
4
|
+
import { ChangeDesignation, Replace } from '../FileManager';
|
|
5
5
|
import { Action } from '../FileSectionState';
|
|
6
6
|
export type SubmissionAttachment = {
|
|
7
7
|
id: string;
|
|
@@ -17,10 +17,12 @@ export interface FileSectionItemProps {
|
|
|
17
17
|
externalFile: SubmissionAttachment;
|
|
18
18
|
title: string;
|
|
19
19
|
showAttachmentName?: boolean;
|
|
20
|
+
showDesignationActions?: boolean;
|
|
20
21
|
showActions?: boolean;
|
|
21
22
|
showReplaceAction?: boolean;
|
|
22
23
|
handleDownload?: (url: string) => void;
|
|
23
24
|
handleReplace?: Replace;
|
|
25
|
+
handleChangeDesignation: ChangeDesignation;
|
|
24
26
|
dispatch?: Dispatch<Action>;
|
|
25
27
|
dragRef?: DragElementWrapper<DragSourceOptions>;
|
|
26
28
|
className?: string;
|
|
@@ -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
|
-
`;
|