@manuscripts/style-guide 0.31.16 → 0.31.19
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 +7 -26
- package/dist/cjs/components/FileManager/FileSectionState.js +11 -3
- package/dist/cjs/components/FileManager/FilesSection.js +10 -0
- package/dist/cjs/hooks/use-deep-compare.js +31 -0
- package/dist/cjs/hooks/use-files.js +44 -0
- package/dist/cjs/index.js +6 -4
- package/dist/cjs/lib/inlineFiles.js +6 -18
- package/dist/es/components/FileManager/FileManager.js +8 -27
- package/dist/es/components/FileManager/FileSectionState.js +11 -3
- package/dist/es/components/FileManager/FilesSection.js +10 -0
- package/dist/es/hooks/use-deep-compare.js +26 -0
- package/dist/es/hooks/use-files.js +39 -0
- package/dist/es/index.js +2 -1
- package/dist/es/lib/inlineFiles.js +7 -17
- package/dist/types/components/FileManager/FileSectionState.d.ts +4 -2
- package/dist/types/hooks/use-deep-compare.d.ts +17 -0
- package/dist/types/hooks/use-files.d.ts +10 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/lib/inlineFiles.d.ts +4 -5
- package/package.json +1 -1
|
@@ -35,8 +35,7 @@ exports.FileManager = exports.PermissionsContext = void 0;
|
|
|
35
35
|
const manuscript_transform_1 = require("@manuscripts/manuscript-transform");
|
|
36
36
|
const react_1 = __importStar(require("react"));
|
|
37
37
|
const react_tooltip_1 = __importDefault(require("react-tooltip"));
|
|
38
|
-
const
|
|
39
|
-
const AlertMessage_1 = require("../AlertMessage");
|
|
38
|
+
const index_1 = require("../../index");
|
|
40
39
|
const Inspector_1 = require("../Inspector");
|
|
41
40
|
const InspectorSection_1 = require("../InspectorSection");
|
|
42
41
|
const DraggableFileSectionItem_1 = require("./FileSectionItem/DraggableFileSectionItem");
|
|
@@ -55,6 +54,7 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
|
|
|
55
54
|
dispatch(FileSectionState_1.actions.SELECT_DESIGNATION(util_1.namesWithDesignationMap.get(typeId) || util_1.Designation.Document));
|
|
56
55
|
const res = yield replace(attachmentId, name, file, typeId);
|
|
57
56
|
dispatch(FileSectionState_1.actions.HANDLE_FINISH_UPLOAD());
|
|
57
|
+
dispatch(FileSectionState_1.actions.HANDLE_SUCCESS_MESSAGE('File uploaded successfully.'));
|
|
58
58
|
return res;
|
|
59
59
|
}), [replace]);
|
|
60
60
|
const handleUploadFile = (0, react_1.useCallback)((file, designation) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -64,6 +64,7 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
|
|
|
64
64
|
}
|
|
65
65
|
const res = yield upload(file, designation);
|
|
66
66
|
dispatch(FileSectionState_1.actions.HANDLE_FINISH_UPLOAD());
|
|
67
|
+
dispatch(FileSectionState_1.actions.HANDLE_SUCCESS_MESSAGE('File uploaded successfully.'));
|
|
67
68
|
return res;
|
|
68
69
|
}), [upload]);
|
|
69
70
|
const handleUploadFileWithSupplement = (0, react_1.useCallback)((file, designation) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -77,7 +78,7 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
|
|
|
77
78
|
const handleChangeDesignationFile = (0, react_1.useCallback)((attachmentId, typeId, name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
79
|
const res = yield changeDesignation(attachmentId, typeId, name);
|
|
79
80
|
if (res) {
|
|
80
|
-
dispatch(FileSectionState_1.actions.HANDLE_SUCCESS_MESSAGE());
|
|
81
|
+
dispatch(FileSectionState_1.actions.HANDLE_SUCCESS_MESSAGE(''));
|
|
81
82
|
}
|
|
82
83
|
return res;
|
|
83
84
|
}), [changeDesignation]);
|
|
@@ -96,27 +97,13 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
|
|
|
96
97
|
}
|
|
97
98
|
}), [modelMap, saveModel]);
|
|
98
99
|
const attachments = getAttachments();
|
|
99
|
-
const
|
|
100
|
-
const supplementFiles = (0, react_1.useMemo)(() => (0, inlineFiles_1.getSupplementFiles)(modelMap, attachments), [attachments, modelMap.size]);
|
|
101
|
-
const excludedAttachmentsIds = (0, react_1.useMemo)(() => {
|
|
102
|
-
const attachmentsIDs = new Set();
|
|
103
|
-
inlineFiles.map(({ attachments }) => {
|
|
104
|
-
if (attachments) {
|
|
105
|
-
attachments.map((attachment) => attachmentsIDs.add(attachment.id));
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
supplementFiles.map(({ id }) => attachmentsIDs.add(id));
|
|
109
|
-
return attachmentsIDs;
|
|
110
|
-
}, [inlineFiles, supplementFiles]);
|
|
100
|
+
const { otherFiles, supplementFiles, inlineFiles } = (0, index_1.useFiles)(modelMap, attachments);
|
|
111
101
|
const getFileSectionExternalFile = (fileSection) => {
|
|
112
102
|
const isSupplementOrOtherFilesTab = fileSection === util_1.FileSectionType.Supplements ||
|
|
113
103
|
fileSection === util_1.FileSectionType.OtherFile;
|
|
114
104
|
const isOtherFilesTab = fileSection === util_1.FileSectionType.OtherFile;
|
|
115
105
|
const itemsData = (fileSection === util_1.FileSectionType.Supplements && supplementFiles) ||
|
|
116
|
-
|
|
117
|
-
const designation = util_1.namesWithDesignationMap.get(element.type.label);
|
|
118
|
-
return (designation !== undefined && !excludedAttachmentsIds.has(element.id));
|
|
119
|
-
});
|
|
106
|
+
otherFiles;
|
|
120
107
|
const itemsDataWithTitle = (0, util_1.generateAttachmentsTitles)(itemsData, fileSection);
|
|
121
108
|
const filesItems = itemsDataWithTitle.map((element) => {
|
|
122
109
|
const itemProps = {
|
|
@@ -139,9 +126,6 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
|
|
|
139
126
|
});
|
|
140
127
|
return filesItems;
|
|
141
128
|
};
|
|
142
|
-
const handleSuccessMessage = () => {
|
|
143
|
-
return (react_1.default.createElement(AlertMessage_1.AlertMessage, { type: AlertMessage_1.AlertMessageType.info, hideCloseButton: false }, state.successMessage));
|
|
144
|
-
};
|
|
145
129
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
146
130
|
react_1.default.createElement(DragLayer_1.DragLayer, null),
|
|
147
131
|
react_1.default.createElement(exports.PermissionsContext.Provider, { value: can },
|
|
@@ -169,9 +153,6 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
|
|
|
169
153
|
react_1.default.createElement(Inspector_1.InspectorTabPanel, null,
|
|
170
154
|
react_1.default.createElement(FilesSection_1.FilesSection, { enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFileWithSupplement, fileSection: util_1.FileSectionType.Supplements, filesItem: getFileSectionExternalFile(util_1.FileSectionType.Supplements), state: state, dispatch: dispatch })),
|
|
171
155
|
react_1.default.createElement(Inspector_1.InspectorTabPanel, null,
|
|
172
|
-
react_1.default.createElement(FilesSection_1.FilesSection, { enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFile, fileSection: util_1.FileSectionType.OtherFile, filesItem: getFileSectionExternalFile(util_1.FileSectionType.OtherFile), state: state, dispatch: dispatch }))))))
|
|
173
|
-
state.isShowSuccessMessage &&
|
|
174
|
-
state.successMessage !== '' &&
|
|
175
|
-
handleSuccessMessage()));
|
|
156
|
+
react_1.default.createElement(FilesSection_1.FilesSection, { enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFile, fileSection: util_1.FileSectionType.OtherFile, filesItem: getFileSectionExternalFile(util_1.FileSectionType.OtherFile), state: state, dispatch: dispatch }))))))));
|
|
176
157
|
};
|
|
177
158
|
exports.FileManager = FileManager;
|
|
@@ -20,6 +20,7 @@ var ActionTypes;
|
|
|
20
20
|
ActionTypes["HANDLE_UPLOAD_ACTION"] = "handleUpload";
|
|
21
21
|
ActionTypes["HANDLE_FINISH_UPLOAD"] = "handleFinishUpload";
|
|
22
22
|
ActionTypes["HANDLE_SUCCESS_MESSAGE"] = "handleSuccessMessage";
|
|
23
|
+
ActionTypes["HANDLE_SUCCESS_MESSAGE_DISMISS"] = "handleSuccessMessageDismiss";
|
|
23
24
|
})(ActionTypes || (ActionTypes = {}));
|
|
24
25
|
const reducer = (state, action) => {
|
|
25
26
|
switch (action.type) {
|
|
@@ -36,7 +37,7 @@ const reducer = (state, action) => {
|
|
|
36
37
|
return Object.assign(Object.assign({}, state), { selectDesignation: action.designation });
|
|
37
38
|
}
|
|
38
39
|
case ActionTypes.HANDLE_UPLOAD_ACTION: {
|
|
39
|
-
return Object.assign(Object.assign({}, state), { isOpenSelectDesignationPopup: false, isUploadFile: true });
|
|
40
|
+
return Object.assign(Object.assign({}, state), { isOpenSelectDesignationPopup: false, isUploadFile: true, isShowSuccessMessage: false, successMessage: '' });
|
|
40
41
|
}
|
|
41
42
|
case ActionTypes.HANDLE_CANCEL_UPLOAD: {
|
|
42
43
|
return Object.assign(Object.assign({}, state), { isOpenSelectDesignationPopup: false });
|
|
@@ -45,7 +46,10 @@ const reducer = (state, action) => {
|
|
|
45
46
|
return Object.assign(Object.assign({}, state), { isUploadFile: false, uploadedFile: undefined, selectDesignation: undefined });
|
|
46
47
|
}
|
|
47
48
|
case ActionTypes.HANDLE_SUCCESS_MESSAGE: {
|
|
48
|
-
return Object.assign(Object.assign({}, state), { isShowSuccessMessage: true });
|
|
49
|
+
return Object.assign(Object.assign({}, state), { isShowSuccessMessage: true, successMessage: action.successMessage });
|
|
50
|
+
}
|
|
51
|
+
case ActionTypes.HANDLE_SUCCESS_MESSAGE_DISMISS: {
|
|
52
|
+
return Object.assign(Object.assign({}, state), { isShowSuccessMessage: false, successMessage: '' });
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
55
|
return state;
|
|
@@ -75,7 +79,11 @@ exports.actions = {
|
|
|
75
79
|
HANDLE_FINISH_UPLOAD: () => ({
|
|
76
80
|
type: ActionTypes.HANDLE_FINISH_UPLOAD,
|
|
77
81
|
}),
|
|
78
|
-
HANDLE_SUCCESS_MESSAGE: () => ({
|
|
82
|
+
HANDLE_SUCCESS_MESSAGE: (successMessage) => ({
|
|
79
83
|
type: ActionTypes.HANDLE_SUCCESS_MESSAGE,
|
|
84
|
+
successMessage,
|
|
85
|
+
}),
|
|
86
|
+
HANDLE_SUCCESS_MESSAGE_DISMISS: () => ({
|
|
87
|
+
type: ActionTypes.HANDLE_SUCCESS_MESSAGE_DISMISS,
|
|
80
88
|
}),
|
|
81
89
|
};
|
|
@@ -21,6 +21,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
22
|
exports.FilesSection = void 0;
|
|
23
23
|
const react_1 = __importStar(require("react"));
|
|
24
|
+
const AlertMessage_1 = require("../AlertMessage");
|
|
24
25
|
const DragItemArea_1 = require("./DragItemArea");
|
|
25
26
|
const FileManager_1 = require("./FileManager");
|
|
26
27
|
const FileSectionUploadItem_1 = require("./FileSectionItem/FileSectionUploadItem");
|
|
@@ -42,12 +43,21 @@ const FilesSection = ({ enableDragAndDrop, handleUpload, fileSection, filesItem,
|
|
|
42
43
|
handleUpload(state.uploadedFile, (0, util_1.getDesignationName)(state.selectDesignation));
|
|
43
44
|
};
|
|
44
45
|
const can = (0, react_1.useContext)(FileManager_1.PermissionsContext);
|
|
46
|
+
const handleSuccessMessage = () => {
|
|
47
|
+
return (react_1.default.createElement(AlertMessage_1.AlertMessage, { type: AlertMessage_1.AlertMessageType.success, hideCloseButton: true, dismissButton: {
|
|
48
|
+
text: 'OK',
|
|
49
|
+
action: () => dispatch(FileSectionState_1.actions.HANDLE_SUCCESS_MESSAGE_DISMISS()),
|
|
50
|
+
} }, state.successMessage));
|
|
51
|
+
};
|
|
45
52
|
return (react_1.default.createElement("div", null,
|
|
46
53
|
(can === null || can === void 0 ? void 0 : can.uploadFile) && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
47
54
|
(isOtherFileTab || isSupplementFilesTab) && (react_1.default.createElement(UploadFileArea_1.UploadFileArea, { handleUploadFile: handleUpload, fileSection: fileSection, dispatch: dispatch })),
|
|
48
55
|
state.isUploadFile &&
|
|
49
56
|
state.uploadedFile &&
|
|
50
57
|
state.selectDesignation !== undefined && (react_1.default.createElement(FileSectionUploadItem_1.FileSectionUploadItem, { fileName: state.uploadedFile.name, isLoading: state.isUploadFile })))),
|
|
58
|
+
state.isShowSuccessMessage &&
|
|
59
|
+
state.successMessage !== '' &&
|
|
60
|
+
handleSuccessMessage(),
|
|
51
61
|
state.uploadedFile && isOtherFileTab && (react_1.default.createElement(SelectDialogDesignation_1.SelectDialogDesignation, { isOpen: state.isOpenSelectDesignationPopup, fileExtension: uploadedFileExtension, handleCancel: () => {
|
|
52
62
|
dispatch(FileSectionState_1.actions.HANDLE_CANCEL_UPLOAD());
|
|
53
63
|
}, uploadFileHandler: () => handleUploadOtherFile(), dispatch: dispatch, fileSection: fileSection })),
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* © 2022 Atypon Systems LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.useDeepCompareCallback = exports.useDeepCompareMemo = void 0;
|
|
19
|
+
const lodash_1 = require("lodash");
|
|
20
|
+
const react_1 = require("react");
|
|
21
|
+
const useDeepCompare = (deps) => {
|
|
22
|
+
const ref = (0, react_1.useRef)(deps);
|
|
23
|
+
if (!(0, lodash_1.isEqual)(deps, ref.current)) {
|
|
24
|
+
ref.current = deps;
|
|
25
|
+
}
|
|
26
|
+
return ref.current;
|
|
27
|
+
};
|
|
28
|
+
const useDeepCompareMemo = (callback, deps) => (0, react_1.useMemo)(callback, [useDeepCompare(deps), callback]);
|
|
29
|
+
exports.useDeepCompareMemo = useDeepCompareMemo;
|
|
30
|
+
const useDeepCompareCallback = (callback, deps) => (0, react_1.useCallback)(callback, [useDeepCompare(deps), callback]);
|
|
31
|
+
exports.useDeepCompareCallback = useDeepCompareCallback;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const manuscript_transform_1 = require("@manuscripts/manuscript-transform");
|
|
7
|
+
const manuscripts_json_schema_1 = require("@manuscripts/manuscripts-json-schema");
|
|
8
|
+
const inlineFiles_1 = __importDefault(require("../lib/inlineFiles"));
|
|
9
|
+
const use_deep_compare_1 = require("./use-deep-compare");
|
|
10
|
+
const getSupplementFiles = (modelMap, attachments, filePredicate) => {
|
|
11
|
+
const supplements = new Map((0, manuscript_transform_1.getModelsByType)(modelMap, manuscripts_json_schema_1.ObjectTypes.Supplement).map((supplement) => { var _a; return [(_a = supplement.href) === null || _a === void 0 ? void 0 : _a.replace('attachment:', ''), supplement]; }));
|
|
12
|
+
return attachments.filter((attachment) => {
|
|
13
|
+
if (supplements.has(attachment.id) && filePredicate) {
|
|
14
|
+
return filePredicate(attachment.name);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return supplements.has(attachment.id);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
const getOtherFiles = (inlineFiles, supplementFiles, attachments, filePredicate) => {
|
|
22
|
+
const inlineFilesAttachmentIds = inlineFiles
|
|
23
|
+
.map(({ attachments }) => (attachments === null || attachments === void 0 ? void 0 : attachments.map(({ id }) => ({ id }))) || [])
|
|
24
|
+
.flat();
|
|
25
|
+
const excludedAttachmentsIds = new Set([...inlineFilesAttachmentIds, ...supplementFiles].map(({ id }) => id));
|
|
26
|
+
return attachments.filter(({ id, name }) => {
|
|
27
|
+
if (!excludedAttachmentsIds.has(id) && filePredicate) {
|
|
28
|
+
return filePredicate(name);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return !excludedAttachmentsIds.has(id);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
exports.default = (modelMap, attachments, filePredicate) => (0, use_deep_compare_1.useDeepCompareMemo)(() => {
|
|
36
|
+
const inlineFiles = (0, inlineFiles_1.default)(modelMap, attachments);
|
|
37
|
+
const supplementFiles = getSupplementFiles(modelMap, attachments, filePredicate);
|
|
38
|
+
const otherFiles = getOtherFiles(inlineFiles, supplementFiles, attachments, filePredicate);
|
|
39
|
+
return {
|
|
40
|
+
otherFiles,
|
|
41
|
+
supplementFiles,
|
|
42
|
+
inlineFiles,
|
|
43
|
+
};
|
|
44
|
+
}, [...Array.from(modelMap.values()), ...attachments]);
|
package/dist/cjs/index.js
CHANGED
|
@@ -28,7 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
29
|
};
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.SelectDialogDesignation = exports.errorsDecoder = exports.
|
|
31
|
+
exports.SelectDialogDesignation = exports.errorsDecoder = exports.useDeepCompareCallback = exports.useDeepCompareMemo = exports.useFiles = exports.PdfPreview = void 0;
|
|
32
32
|
__exportStar(require("./components/AffiliationsEditor"), exports);
|
|
33
33
|
__exportStar(require("./components/AffiliationsList"), exports);
|
|
34
34
|
__exportStar(require("./components/AuthorForm"), exports);
|
|
@@ -60,14 +60,16 @@ __exportStar(require("./components/Tip"), exports);
|
|
|
60
60
|
__exportStar(require("./components/icons"), exports);
|
|
61
61
|
__exportStar(require("./components/Inspector"), exports);
|
|
62
62
|
__exportStar(require("./components/InspectorSection"), exports);
|
|
63
|
-
var inlineFiles_1 = require("./lib/inlineFiles");
|
|
64
|
-
Object.defineProperty(exports, "inlineFiles", { enumerable: true, get: function () { return __importDefault(inlineFiles_1).default; } });
|
|
65
|
-
Object.defineProperty(exports, "getSupplementFiles", { enumerable: true, get: function () { return inlineFiles_1.getSupplementFiles; } });
|
|
66
63
|
var PdfPreview_1 = require("./components/PdfPreview");
|
|
67
64
|
Object.defineProperty(exports, "PdfPreview", { enumerable: true, get: function () { return __importDefault(PdfPreview_1).default; } });
|
|
68
65
|
__exportStar(require("./components/SubmissionInspector"), exports);
|
|
69
66
|
__exportStar(require("./components/Dropdown"), exports);
|
|
70
67
|
__exportStar(require("./hooks/use-dropdown"), exports);
|
|
68
|
+
var use_files_1 = require("./hooks/use-files");
|
|
69
|
+
Object.defineProperty(exports, "useFiles", { enumerable: true, get: function () { return __importDefault(use_files_1).default; } });
|
|
70
|
+
var use_deep_compare_1 = require("./hooks/use-deep-compare");
|
|
71
|
+
Object.defineProperty(exports, "useDeepCompareMemo", { enumerable: true, get: function () { return use_deep_compare_1.useDeepCompareMemo; } });
|
|
72
|
+
Object.defineProperty(exports, "useDeepCompareCallback", { enumerable: true, get: function () { return use_deep_compare_1.useDeepCompareCallback; } });
|
|
71
73
|
__exportStar(require("./lib/authors"), exports);
|
|
72
74
|
__exportStar(require("./lib/capabilities"), exports);
|
|
73
75
|
var lw_errors_decoder_1 = require("./lib/lw-errors-decoder");
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSupplementFiles = void 0;
|
|
4
3
|
const manuscript_transform_1 = require("@manuscripts/manuscript-transform");
|
|
5
4
|
const manuscripts_json_schema_1 = require("@manuscripts/manuscripts-json-schema");
|
|
6
5
|
const util_1 = require("../components/FileManager/util");
|
|
7
|
-
const getCaptionText = (caption) => caption &&
|
|
8
|
-
new DOMParser().parseFromString(caption, 'text/html').documentElement
|
|
9
|
-
.innerText;
|
|
10
6
|
const getAttachment = (externalFileRef, attachmentsMap) => {
|
|
11
7
|
if (!(externalFileRef === null || externalFileRef === void 0 ? void 0 : externalFileRef.url.includes('https://'))) {
|
|
12
8
|
const attachmentId = externalFileRef === null || externalFileRef === void 0 ? void 0 : externalFileRef.url.replace('attachment:', '');
|
|
@@ -33,7 +29,6 @@ const getFigureData = (element, modelMap, attachmentsMap) => {
|
|
|
33
29
|
return {
|
|
34
30
|
id: element._id,
|
|
35
31
|
attachments,
|
|
36
|
-
caption: getCaptionText(element.caption),
|
|
37
32
|
};
|
|
38
33
|
};
|
|
39
34
|
exports.default = (modelMap, attachments) => {
|
|
@@ -60,7 +55,6 @@ exports.default = (modelMap, attachments) => {
|
|
|
60
55
|
label: `Table`,
|
|
61
56
|
type: util_1.FileType.SheetsWorkbooks,
|
|
62
57
|
attachments: [attachment],
|
|
63
|
-
caption: getCaptionText(tableElement.caption),
|
|
64
58
|
});
|
|
65
59
|
}
|
|
66
60
|
});
|
|
@@ -110,19 +104,13 @@ const getAuxiliaryObjects = (modelMap) => {
|
|
|
110
104
|
}
|
|
111
105
|
return {
|
|
112
106
|
graphicalAbstractFigureId,
|
|
113
|
-
figureElement: orderObjects[manuscripts_json_schema_1.ObjectTypes.FigureElement]
|
|
114
|
-
|
|
115
|
-
: figureElementIds,
|
|
116
|
-
tableElement: orderObjects[manuscripts_json_schema_1.ObjectTypes.TableElement]
|
|
117
|
-
? sortAuxiliaryObject(orderObjects[manuscripts_json_schema_1.ObjectTypes.TableElement], tableElementIds)
|
|
118
|
-
: tableElementIds,
|
|
107
|
+
figureElement: sortAuxiliaryObject(figureElementIds, orderObjects[manuscripts_json_schema_1.ObjectTypes.FigureElement]),
|
|
108
|
+
tableElement: sortAuxiliaryObject(tableElementIds, orderObjects[manuscripts_json_schema_1.ObjectTypes.TableElement]),
|
|
119
109
|
};
|
|
120
110
|
};
|
|
121
|
-
const sortAuxiliaryObject = (
|
|
111
|
+
const sortAuxiliaryObject = (auxiliaryObjectIds, orderObject) => {
|
|
112
|
+
if (!orderObject) {
|
|
113
|
+
return auxiliaryObjectIds;
|
|
114
|
+
}
|
|
122
115
|
return auxiliaryObjectIds.sort((a, b) => orderObject.elements.indexOf(a) - orderObject.elements.indexOf(b));
|
|
123
116
|
};
|
|
124
|
-
const getSupplementFiles = (modelMap, attachments) => {
|
|
125
|
-
const supplements = new Map((0, manuscript_transform_1.getModelsByType)(modelMap, manuscripts_json_schema_1.ObjectTypes.Supplement).map((supplement) => { var _a; return [(_a = supplement.href) === null || _a === void 0 ? void 0 : _a.replace('attachment:', ''), supplement]; }));
|
|
126
|
-
return attachments.filter((attachment) => supplements.has(attachment.id));
|
|
127
|
-
};
|
|
128
|
-
exports.getSupplementFiles = getSupplementFiles;
|
|
@@ -8,10 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { buildSupplementaryMaterial, } from '@manuscripts/manuscript-transform';
|
|
11
|
-
import React, { createContext, useCallback,
|
|
11
|
+
import React, { createContext, useCallback, useReducer } from 'react';
|
|
12
12
|
import ReactTooltip from 'react-tooltip';
|
|
13
|
-
import
|
|
14
|
-
import { AlertMessage, AlertMessageType } from '../AlertMessage';
|
|
13
|
+
import { useFiles } from '../../index';
|
|
15
14
|
import { InspectorTab, InspectorTabList, InspectorTabPanel, InspectorTabPanels, InspectorTabs, } from '../Inspector';
|
|
16
15
|
import { InspectorSection } from '../InspectorSection';
|
|
17
16
|
import { DraggableFileSectionItem } from './FileSectionItem/DraggableFileSectionItem';
|
|
@@ -30,6 +29,7 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
|
|
|
30
29
|
dispatch(actions.SELECT_DESIGNATION(namesWithDesignationMap.get(typeId) || Designation.Document));
|
|
31
30
|
const res = yield replace(attachmentId, name, file, typeId);
|
|
32
31
|
dispatch(actions.HANDLE_FINISH_UPLOAD());
|
|
32
|
+
dispatch(actions.HANDLE_SUCCESS_MESSAGE('File uploaded successfully.'));
|
|
33
33
|
return res;
|
|
34
34
|
}), [replace]);
|
|
35
35
|
const handleUploadFile = useCallback((file, designation) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -39,6 +39,7 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
|
|
|
39
39
|
}
|
|
40
40
|
const res = yield upload(file, designation);
|
|
41
41
|
dispatch(actions.HANDLE_FINISH_UPLOAD());
|
|
42
|
+
dispatch(actions.HANDLE_SUCCESS_MESSAGE('File uploaded successfully.'));
|
|
42
43
|
return res;
|
|
43
44
|
}), [upload]);
|
|
44
45
|
const handleUploadFileWithSupplement = useCallback((file, designation) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -52,7 +53,7 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
|
|
|
52
53
|
const handleChangeDesignationFile = useCallback((attachmentId, typeId, name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
54
|
const res = yield changeDesignation(attachmentId, typeId, name);
|
|
54
55
|
if (res) {
|
|
55
|
-
dispatch(actions.HANDLE_SUCCESS_MESSAGE());
|
|
56
|
+
dispatch(actions.HANDLE_SUCCESS_MESSAGE(''));
|
|
56
57
|
}
|
|
57
58
|
return res;
|
|
58
59
|
}), [changeDesignation]);
|
|
@@ -71,27 +72,13 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
|
|
|
71
72
|
}
|
|
72
73
|
}), [modelMap, saveModel]);
|
|
73
74
|
const attachments = getAttachments();
|
|
74
|
-
const
|
|
75
|
-
const supplementFiles = useMemo(() => getSupplementFiles(modelMap, attachments), [attachments, modelMap.size]);
|
|
76
|
-
const excludedAttachmentsIds = useMemo(() => {
|
|
77
|
-
const attachmentsIDs = new Set();
|
|
78
|
-
inlineFiles.map(({ attachments }) => {
|
|
79
|
-
if (attachments) {
|
|
80
|
-
attachments.map((attachment) => attachmentsIDs.add(attachment.id));
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
supplementFiles.map(({ id }) => attachmentsIDs.add(id));
|
|
84
|
-
return attachmentsIDs;
|
|
85
|
-
}, [inlineFiles, supplementFiles]);
|
|
75
|
+
const { otherFiles, supplementFiles, inlineFiles } = useFiles(modelMap, attachments);
|
|
86
76
|
const getFileSectionExternalFile = (fileSection) => {
|
|
87
77
|
const isSupplementOrOtherFilesTab = fileSection === FileSectionType.Supplements ||
|
|
88
78
|
fileSection === FileSectionType.OtherFile;
|
|
89
79
|
const isOtherFilesTab = fileSection === FileSectionType.OtherFile;
|
|
90
80
|
const itemsData = (fileSection === FileSectionType.Supplements && supplementFiles) ||
|
|
91
|
-
|
|
92
|
-
const designation = namesWithDesignationMap.get(element.type.label);
|
|
93
|
-
return (designation !== undefined && !excludedAttachmentsIds.has(element.id));
|
|
94
|
-
});
|
|
81
|
+
otherFiles;
|
|
95
82
|
const itemsDataWithTitle = generateAttachmentsTitles(itemsData, fileSection);
|
|
96
83
|
const filesItems = itemsDataWithTitle.map((element) => {
|
|
97
84
|
const itemProps = {
|
|
@@ -114,9 +101,6 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
|
|
|
114
101
|
});
|
|
115
102
|
return filesItems;
|
|
116
103
|
};
|
|
117
|
-
const handleSuccessMessage = () => {
|
|
118
|
-
return (React.createElement(AlertMessage, { type: AlertMessageType.info, hideCloseButton: false }, state.successMessage));
|
|
119
|
-
};
|
|
120
104
|
return (React.createElement(React.Fragment, null,
|
|
121
105
|
React.createElement(DragLayer, null),
|
|
122
106
|
React.createElement(PermissionsContext.Provider, { value: can },
|
|
@@ -144,8 +128,5 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
|
|
|
144
128
|
React.createElement(InspectorTabPanel, null,
|
|
145
129
|
React.createElement(FilesSection, { enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFileWithSupplement, fileSection: FileSectionType.Supplements, filesItem: getFileSectionExternalFile(FileSectionType.Supplements), state: state, dispatch: dispatch })),
|
|
146
130
|
React.createElement(InspectorTabPanel, null,
|
|
147
|
-
React.createElement(FilesSection, { enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFile, fileSection: FileSectionType.OtherFile, filesItem: getFileSectionExternalFile(FileSectionType.OtherFile), state: state, dispatch: dispatch }))))))
|
|
148
|
-
state.isShowSuccessMessage &&
|
|
149
|
-
state.successMessage !== '' &&
|
|
150
|
-
handleSuccessMessage()));
|
|
131
|
+
React.createElement(FilesSection, { enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFile, fileSection: FileSectionType.OtherFile, filesItem: getFileSectionExternalFile(FileSectionType.OtherFile), state: state, dispatch: dispatch }))))))));
|
|
151
132
|
};
|
|
@@ -16,6 +16,7 @@ var ActionTypes;
|
|
|
16
16
|
ActionTypes["HANDLE_UPLOAD_ACTION"] = "handleUpload";
|
|
17
17
|
ActionTypes["HANDLE_FINISH_UPLOAD"] = "handleFinishUpload";
|
|
18
18
|
ActionTypes["HANDLE_SUCCESS_MESSAGE"] = "handleSuccessMessage";
|
|
19
|
+
ActionTypes["HANDLE_SUCCESS_MESSAGE_DISMISS"] = "handleSuccessMessageDismiss";
|
|
19
20
|
})(ActionTypes || (ActionTypes = {}));
|
|
20
21
|
export const reducer = (state, action) => {
|
|
21
22
|
switch (action.type) {
|
|
@@ -32,7 +33,7 @@ export const reducer = (state, action) => {
|
|
|
32
33
|
return Object.assign(Object.assign({}, state), { selectDesignation: action.designation });
|
|
33
34
|
}
|
|
34
35
|
case ActionTypes.HANDLE_UPLOAD_ACTION: {
|
|
35
|
-
return Object.assign(Object.assign({}, state), { isOpenSelectDesignationPopup: false, isUploadFile: true });
|
|
36
|
+
return Object.assign(Object.assign({}, state), { isOpenSelectDesignationPopup: false, isUploadFile: true, isShowSuccessMessage: false, successMessage: '' });
|
|
36
37
|
}
|
|
37
38
|
case ActionTypes.HANDLE_CANCEL_UPLOAD: {
|
|
38
39
|
return Object.assign(Object.assign({}, state), { isOpenSelectDesignationPopup: false });
|
|
@@ -41,7 +42,10 @@ export const reducer = (state, action) => {
|
|
|
41
42
|
return Object.assign(Object.assign({}, state), { isUploadFile: false, uploadedFile: undefined, selectDesignation: undefined });
|
|
42
43
|
}
|
|
43
44
|
case ActionTypes.HANDLE_SUCCESS_MESSAGE: {
|
|
44
|
-
return Object.assign(Object.assign({}, state), { isShowSuccessMessage: true });
|
|
45
|
+
return Object.assign(Object.assign({}, state), { isShowSuccessMessage: true, successMessage: action.successMessage });
|
|
46
|
+
}
|
|
47
|
+
case ActionTypes.HANDLE_SUCCESS_MESSAGE_DISMISS: {
|
|
48
|
+
return Object.assign(Object.assign({}, state), { isShowSuccessMessage: false, successMessage: '' });
|
|
45
49
|
}
|
|
46
50
|
}
|
|
47
51
|
return state;
|
|
@@ -70,7 +74,11 @@ export const actions = {
|
|
|
70
74
|
HANDLE_FINISH_UPLOAD: () => ({
|
|
71
75
|
type: ActionTypes.HANDLE_FINISH_UPLOAD,
|
|
72
76
|
}),
|
|
73
|
-
HANDLE_SUCCESS_MESSAGE: () => ({
|
|
77
|
+
HANDLE_SUCCESS_MESSAGE: (successMessage) => ({
|
|
74
78
|
type: ActionTypes.HANDLE_SUCCESS_MESSAGE,
|
|
79
|
+
successMessage,
|
|
80
|
+
}),
|
|
81
|
+
HANDLE_SUCCESS_MESSAGE_DISMISS: () => ({
|
|
82
|
+
type: ActionTypes.HANDLE_SUCCESS_MESSAGE_DISMISS,
|
|
75
83
|
}),
|
|
76
84
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { useContext } from 'react';
|
|
2
|
+
import { AlertMessage, AlertMessageType } from '../AlertMessage';
|
|
2
3
|
import { DragItemArea } from './DragItemArea';
|
|
3
4
|
import { PermissionsContext } from './FileManager';
|
|
4
5
|
import { FileSectionUploadItem } from './FileSectionItem/FileSectionUploadItem';
|
|
@@ -20,12 +21,21 @@ export const FilesSection = ({ enableDragAndDrop, handleUpload, fileSection, fil
|
|
|
20
21
|
handleUpload(state.uploadedFile, getDesignationName(state.selectDesignation));
|
|
21
22
|
};
|
|
22
23
|
const can = useContext(PermissionsContext);
|
|
24
|
+
const handleSuccessMessage = () => {
|
|
25
|
+
return (React.createElement(AlertMessage, { type: AlertMessageType.success, hideCloseButton: true, dismissButton: {
|
|
26
|
+
text: 'OK',
|
|
27
|
+
action: () => dispatch(actions.HANDLE_SUCCESS_MESSAGE_DISMISS()),
|
|
28
|
+
} }, state.successMessage));
|
|
29
|
+
};
|
|
23
30
|
return (React.createElement("div", null,
|
|
24
31
|
(can === null || can === void 0 ? void 0 : can.uploadFile) && (React.createElement(React.Fragment, null,
|
|
25
32
|
(isOtherFileTab || isSupplementFilesTab) && (React.createElement(UploadFileArea, { handleUploadFile: handleUpload, fileSection: fileSection, dispatch: dispatch })),
|
|
26
33
|
state.isUploadFile &&
|
|
27
34
|
state.uploadedFile &&
|
|
28
35
|
state.selectDesignation !== undefined && (React.createElement(FileSectionUploadItem, { fileName: state.uploadedFile.name, isLoading: state.isUploadFile })))),
|
|
36
|
+
state.isShowSuccessMessage &&
|
|
37
|
+
state.successMessage !== '' &&
|
|
38
|
+
handleSuccessMessage(),
|
|
29
39
|
state.uploadedFile && isOtherFileTab && (React.createElement(SelectDialogDesignation, { isOpen: state.isOpenSelectDesignationPopup, fileExtension: uploadedFileExtension, handleCancel: () => {
|
|
30
40
|
dispatch(actions.HANDLE_CANCEL_UPLOAD());
|
|
31
41
|
}, uploadFileHandler: () => handleUploadOtherFile(), dispatch: dispatch, fileSection: fileSection })),
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2022 Atypon Systems LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { isEqual } from 'lodash';
|
|
17
|
+
import { useCallback, useMemo, useRef } from 'react';
|
|
18
|
+
const useDeepCompare = (deps) => {
|
|
19
|
+
const ref = useRef(deps);
|
|
20
|
+
if (!isEqual(deps, ref.current)) {
|
|
21
|
+
ref.current = deps;
|
|
22
|
+
}
|
|
23
|
+
return ref.current;
|
|
24
|
+
};
|
|
25
|
+
export const useDeepCompareMemo = (callback, deps) => useMemo(callback, [useDeepCompare(deps), callback]);
|
|
26
|
+
export const useDeepCompareCallback = (callback, deps) => useCallback(callback, [useDeepCompare(deps), callback]);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getModelsByType } from '@manuscripts/manuscript-transform';
|
|
2
|
+
import { ObjectTypes, } from '@manuscripts/manuscripts-json-schema';
|
|
3
|
+
import getInlineFiles from '../lib/inlineFiles';
|
|
4
|
+
import { useDeepCompareMemo } from './use-deep-compare';
|
|
5
|
+
const getSupplementFiles = (modelMap, attachments, filePredicate) => {
|
|
6
|
+
const supplements = new Map(getModelsByType(modelMap, ObjectTypes.Supplement).map((supplement) => { var _a; return [(_a = supplement.href) === null || _a === void 0 ? void 0 : _a.replace('attachment:', ''), supplement]; }));
|
|
7
|
+
return attachments.filter((attachment) => {
|
|
8
|
+
if (supplements.has(attachment.id) && filePredicate) {
|
|
9
|
+
return filePredicate(attachment.name);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return supplements.has(attachment.id);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
const getOtherFiles = (inlineFiles, supplementFiles, attachments, filePredicate) => {
|
|
17
|
+
const inlineFilesAttachmentIds = inlineFiles
|
|
18
|
+
.map(({ attachments }) => (attachments === null || attachments === void 0 ? void 0 : attachments.map(({ id }) => ({ id }))) || [])
|
|
19
|
+
.flat();
|
|
20
|
+
const excludedAttachmentsIds = new Set([...inlineFilesAttachmentIds, ...supplementFiles].map(({ id }) => id));
|
|
21
|
+
return attachments.filter(({ id, name }) => {
|
|
22
|
+
if (!excludedAttachmentsIds.has(id) && filePredicate) {
|
|
23
|
+
return filePredicate(name);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return !excludedAttachmentsIds.has(id);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
export default (modelMap, attachments, filePredicate) => useDeepCompareMemo(() => {
|
|
31
|
+
const inlineFiles = getInlineFiles(modelMap, attachments);
|
|
32
|
+
const supplementFiles = getSupplementFiles(modelMap, attachments, filePredicate);
|
|
33
|
+
const otherFiles = getOtherFiles(inlineFiles, supplementFiles, attachments, filePredicate);
|
|
34
|
+
return {
|
|
35
|
+
otherFiles,
|
|
36
|
+
supplementFiles,
|
|
37
|
+
inlineFiles,
|
|
38
|
+
};
|
|
39
|
+
}, [...Array.from(modelMap.values()), ...attachments]);
|
package/dist/es/index.js
CHANGED
|
@@ -44,11 +44,12 @@ export * from './components/Tip';
|
|
|
44
44
|
export * from './components/icons';
|
|
45
45
|
export * from './components/Inspector';
|
|
46
46
|
export * from './components/InspectorSection';
|
|
47
|
-
export { default as inlineFiles, getSupplementFiles } from './lib/inlineFiles';
|
|
48
47
|
export { default as PdfPreview } from './components/PdfPreview';
|
|
49
48
|
export * from './components/SubmissionInspector';
|
|
50
49
|
export * from './components/Dropdown';
|
|
51
50
|
export * from './hooks/use-dropdown';
|
|
51
|
+
export { default as useFiles } from './hooks/use-files';
|
|
52
|
+
export { useDeepCompareMemo, useDeepCompareCallback, } from './hooks/use-deep-compare';
|
|
52
53
|
export * from './lib/authors';
|
|
53
54
|
export * from './lib/capabilities';
|
|
54
55
|
export { default as errorsDecoder } from './lib/lw-errors-decoder';
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { hasObjectType } from '@manuscripts/manuscript-transform';
|
|
2
2
|
import { ObjectTypes, } from '@manuscripts/manuscripts-json-schema';
|
|
3
3
|
import { FileType } from '../components/FileManager/util';
|
|
4
|
-
const getCaptionText = (caption) => caption &&
|
|
5
|
-
new DOMParser().parseFromString(caption, 'text/html').documentElement
|
|
6
|
-
.innerText;
|
|
7
4
|
const getAttachment = (externalFileRef, attachmentsMap) => {
|
|
8
5
|
if (!(externalFileRef === null || externalFileRef === void 0 ? void 0 : externalFileRef.url.includes('https://'))) {
|
|
9
6
|
const attachmentId = externalFileRef === null || externalFileRef === void 0 ? void 0 : externalFileRef.url.replace('attachment:', '');
|
|
@@ -30,7 +27,6 @@ const getFigureData = (element, modelMap, attachmentsMap) => {
|
|
|
30
27
|
return {
|
|
31
28
|
id: element._id,
|
|
32
29
|
attachments,
|
|
33
|
-
caption: getCaptionText(element.caption),
|
|
34
30
|
};
|
|
35
31
|
};
|
|
36
32
|
export default (modelMap, attachments) => {
|
|
@@ -57,7 +53,6 @@ export default (modelMap, attachments) => {
|
|
|
57
53
|
label: `Table`,
|
|
58
54
|
type: FileType.SheetsWorkbooks,
|
|
59
55
|
attachments: [attachment],
|
|
60
|
-
caption: getCaptionText(tableElement.caption),
|
|
61
56
|
});
|
|
62
57
|
}
|
|
63
58
|
});
|
|
@@ -107,18 +102,13 @@ const getAuxiliaryObjects = (modelMap) => {
|
|
|
107
102
|
}
|
|
108
103
|
return {
|
|
109
104
|
graphicalAbstractFigureId,
|
|
110
|
-
figureElement: orderObjects[ObjectTypes.FigureElement]
|
|
111
|
-
|
|
112
|
-
: figureElementIds,
|
|
113
|
-
tableElement: orderObjects[ObjectTypes.TableElement]
|
|
114
|
-
? sortAuxiliaryObject(orderObjects[ObjectTypes.TableElement], tableElementIds)
|
|
115
|
-
: tableElementIds,
|
|
105
|
+
figureElement: sortAuxiliaryObject(figureElementIds, orderObjects[ObjectTypes.FigureElement]),
|
|
106
|
+
tableElement: sortAuxiliaryObject(tableElementIds, orderObjects[ObjectTypes.TableElement]),
|
|
116
107
|
};
|
|
117
108
|
};
|
|
118
|
-
const sortAuxiliaryObject = (
|
|
109
|
+
const sortAuxiliaryObject = (auxiliaryObjectIds, orderObject) => {
|
|
110
|
+
if (!orderObject) {
|
|
111
|
+
return auxiliaryObjectIds;
|
|
112
|
+
}
|
|
119
113
|
return auxiliaryObjectIds.sort((a, b) => orderObject.elements.indexOf(a) - orderObject.elements.indexOf(b));
|
|
120
114
|
};
|
|
121
|
-
export const getSupplementFiles = (modelMap, attachments) => {
|
|
122
|
-
const supplements = new Map(getModelsByType(modelMap, ObjectTypes.Supplement).map((supplement) => { var _a; return [(_a = supplement.href) === null || _a === void 0 ? void 0 : _a.replace('attachment:', ''), supplement]; }));
|
|
123
|
-
return attachments.filter((attachment) => supplements.has(attachment.id));
|
|
124
|
-
};
|
|
@@ -19,7 +19,8 @@ declare enum ActionTypes {
|
|
|
19
19
|
HANDLE_CANCEL_UPLOAD = "handleCancel",
|
|
20
20
|
HANDLE_UPLOAD_ACTION = "handleUpload",
|
|
21
21
|
HANDLE_FINISH_UPLOAD = "handleFinishUpload",
|
|
22
|
-
HANDLE_SUCCESS_MESSAGE = "handleSuccessMessage"
|
|
22
|
+
HANDLE_SUCCESS_MESSAGE = "handleSuccessMessage",
|
|
23
|
+
HANDLE_SUCCESS_MESSAGE_DISMISS = "handleSuccessMessageDismiss"
|
|
23
24
|
}
|
|
24
25
|
export declare const reducer: (state: State, action: Action) => State;
|
|
25
26
|
export interface Action {
|
|
@@ -33,6 +34,7 @@ export declare const actions: {
|
|
|
33
34
|
SELECT_DESIGNATION: (designation: Designation) => Action;
|
|
34
35
|
MOVE_FILE: (attachmentId: string, typeId: string, name: string, successMoveMessage: string) => Action;
|
|
35
36
|
HANDLE_FINISH_UPLOAD: () => Action;
|
|
36
|
-
HANDLE_SUCCESS_MESSAGE: () => Action;
|
|
37
|
+
HANDLE_SUCCESS_MESSAGE: (successMessage: string) => Action;
|
|
38
|
+
HANDLE_SUCCESS_MESSAGE_DISMISS: () => Action;
|
|
37
39
|
};
|
|
38
40
|
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2022 Atypon Systems LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export declare const useDeepCompareMemo: <T, D>(callback: () => T, deps: D) => T;
|
|
17
|
+
export declare const useDeepCompareCallback: <T, D>(callback: () => T, deps: D) => () => T;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Model } from '@manuscripts/manuscripts-json-schema';
|
|
2
|
+
import { SubmissionAttachment } from '../components/FileManager/FileSectionItem/FileSectionItem';
|
|
3
|
+
import { InlineFile } from '../lib/inlineFiles';
|
|
4
|
+
declare type FilePredicate = (fileName: string) => boolean;
|
|
5
|
+
declare const _default: (modelMap: Map<string, Model>, attachments: SubmissionAttachment[], filePredicate?: FilePredicate | undefined) => {
|
|
6
|
+
otherFiles: SubmissionAttachment[];
|
|
7
|
+
supplementFiles: SubmissionAttachment[];
|
|
8
|
+
inlineFiles: InlineFile[];
|
|
9
|
+
};
|
|
10
|
+
export default _default;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -45,11 +45,12 @@ export * from './components/Tip';
|
|
|
45
45
|
export * from './components/icons';
|
|
46
46
|
export * from './components/Inspector';
|
|
47
47
|
export * from './components/InspectorSection';
|
|
48
|
-
export { default as inlineFiles, getSupplementFiles } from './lib/inlineFiles';
|
|
49
48
|
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';
|
|
52
|
+
export { default as useFiles } from './hooks/use-files';
|
|
53
|
+
export { useDeepCompareMemo, useDeepCompareCallback, } from './hooks/use-deep-compare';
|
|
53
54
|
export * from './lib/authors';
|
|
54
55
|
export * from './lib/capabilities';
|
|
55
56
|
export { default as errorsDecoder } from './lib/lw-errors-decoder';
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Model } from '@manuscripts/manuscripts-json-schema';
|
|
2
2
|
import { SubmissionAttachment } from '../components/FileManager/FileSectionItem/FileSectionItem';
|
|
3
3
|
import { FileType } from '../components/FileManager/util';
|
|
4
|
-
declare
|
|
4
|
+
export declare type InlineFile = {
|
|
5
5
|
id: string;
|
|
6
6
|
label: string;
|
|
7
7
|
type: FileType;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
attachments?: SubmissionAttachment[];
|
|
9
|
+
};
|
|
10
|
+
declare const _default: (modelMap: Map<string, Model>, attachments: SubmissionAttachment[]) => InlineFile[];
|
|
11
11
|
export default _default;
|
|
12
|
-
export declare const getSupplementFiles: (modelMap: Map<string, Model>, attachments: SubmissionAttachment[]) => SubmissionAttachment[];
|
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": "0.31.
|
|
4
|
+
"version": "0.31.19",
|
|
5
5
|
"repository": "gitlab:atypon-opensource/manuscripts-style-guide",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|