@manuscripts/style-guide 0.31.7 → 0.31.10
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 +29 -8
- package/dist/cjs/components/FileManager/InlineFilesSection.js +1 -2
- package/dist/cjs/lib/capabilities.js +1 -0
- package/dist/cjs/lib/inlineFiles.js +5 -2
- package/dist/es/components/FileManager/FileManager.js +29 -8
- package/dist/es/components/FileManager/InlineFilesSection.js +2 -3
- package/dist/es/lib/capabilities.js +1 -0
- package/dist/es/lib/inlineFiles.js +5 -2
- package/dist/types/components/FileManager/FileManager.d.ts +3 -1
- package/dist/types/lib/capabilities.d.ts +1 -0
- package/package.json +2 -2
|
@@ -32,6 +32,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
32
32
|
};
|
|
33
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
34
|
exports.FileManager = exports.PermissionsContext = void 0;
|
|
35
|
+
const manuscript_transform_1 = require("@manuscripts/manuscript-transform");
|
|
36
|
+
const manuscripts_json_schema_1 = require("@manuscripts/manuscripts-json-schema");
|
|
35
37
|
const react_1 = __importStar(require("react"));
|
|
36
38
|
const react_tooltip_1 = __importDefault(require("react-tooltip"));
|
|
37
39
|
const inlineFiles_1 = __importDefault(require("../../lib/inlineFiles"));
|
|
@@ -47,7 +49,7 @@ const InlineFilesSection_1 = require("./InlineFilesSection");
|
|
|
47
49
|
const TooltipDiv_1 = require("./TooltipDiv");
|
|
48
50
|
const util_1 = require("./util");
|
|
49
51
|
exports.PermissionsContext = (0, react_1.createContext)(null);
|
|
50
|
-
const FileManager = ({ submissionId, attachments, modelMap, enableDragAndDrop, can, handleUpload, handleDownload, handleReplace, handleChangeDesignation, }) => {
|
|
52
|
+
const FileManager = ({ submissionId, attachments, modelMap, saveModel, enableDragAndDrop, can, handleUpload, handleDownload, handleReplace, handleChangeDesignation, }) => {
|
|
51
53
|
const [state, dispatch] = (0, react_1.useReducer)(FileSectionState_1.reducer, (0, FileSectionState_1.getInitialState)());
|
|
52
54
|
const handleReplaceFile = (0, react_1.useCallback)((submissionId, attachmentId, name, file, typeId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
55
|
dispatch(FileSectionState_1.actions.HANDLE_UPLOAD_ACTION());
|
|
@@ -65,6 +67,14 @@ const FileManager = ({ submissionId, attachments, modelMap, enableDragAndDrop, c
|
|
|
65
67
|
dispatch(FileSectionState_1.actions.HANDLE_FINISH_UPLOAD());
|
|
66
68
|
return res;
|
|
67
69
|
}), [handleUpload]);
|
|
70
|
+
const handleUploadFileWithSupplement = (0, react_1.useCallback)((submissionId, file, designation) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
const res = (yield handleUploadFile(submissionId, file, designation));
|
|
72
|
+
if (res && res.data) {
|
|
73
|
+
const { id, name } = res.data.uploadAttachment;
|
|
74
|
+
yield saveModel((0, manuscript_transform_1.buildSupplementaryMaterial)(name, `attachment:${id}`));
|
|
75
|
+
}
|
|
76
|
+
return res;
|
|
77
|
+
}), [handleUploadFile, saveModel]);
|
|
68
78
|
const handleChangeDesignationFile = (0, react_1.useCallback)((submissionId, attachmentId, typeId, name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
79
|
const res = yield handleChangeDesignation(submissionId, attachmentId, typeId, name);
|
|
70
80
|
if (res) {
|
|
@@ -85,15 +95,26 @@ const FileManager = ({ submissionId, attachments, modelMap, enableDragAndDrop, c
|
|
|
85
95
|
});
|
|
86
96
|
return attachmentsIDs;
|
|
87
97
|
}, [inlineFiles]);
|
|
98
|
+
const supplementFiles = (0, react_1.useMemo)(() => {
|
|
99
|
+
const supplements = new Map((0, manuscript_transform_1.getModelsByType)(modelMap, manuscripts_json_schema_1.ObjectTypes.Supplement).map((supplement) => {
|
|
100
|
+
var _a;
|
|
101
|
+
return [
|
|
102
|
+
(_a = supplement.href) === null || _a === void 0 ? void 0 : _a.replace('attachment:', ''),
|
|
103
|
+
supplement,
|
|
104
|
+
];
|
|
105
|
+
}));
|
|
106
|
+
return attachments.filter((attachment) => supplements.has(attachment.id));
|
|
107
|
+
}, [attachments, modelMap.size]);
|
|
88
108
|
const getFileSectionExternalFile = (fileSection) => {
|
|
89
109
|
const isSupplementOrOtherFilesTab = fileSection === util_1.FileSectionType.Supplements ||
|
|
90
110
|
fileSection === util_1.FileSectionType.OtherFile;
|
|
91
|
-
const itemsData =
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
111
|
+
const itemsData = (fileSection === util_1.FileSectionType.Supplements && supplementFiles) ||
|
|
112
|
+
attachments.filter((element) => {
|
|
113
|
+
const designation = util_1.namesWithDesignationMap.get(element.type.label);
|
|
114
|
+
return (designation !== undefined &&
|
|
115
|
+
util_1.designationWithFileSectionsMap.get(designation) === fileSection &&
|
|
116
|
+
!inlineAttachmentsIds.has(element.id));
|
|
117
|
+
});
|
|
97
118
|
const itemsDataWithTitle = (0, util_1.generateAttachmentsTitles)(itemsData, fileSection);
|
|
98
119
|
const filesItems = itemsDataWithTitle.map((element) => {
|
|
99
120
|
const itemProps = {
|
|
@@ -144,7 +165,7 @@ const FileManager = ({ submissionId, attachments, modelMap, enableDragAndDrop, c
|
|
|
144
165
|
react_1.default.createElement(Inspector_1.InspectorTabPanel, null,
|
|
145
166
|
react_1.default.createElement(InlineFilesSection_1.InlineFilesSection, { inlineFiles: inlineFiles, submissionId: submissionId, handleReplace: handleReplace, handleDownload: handleDownload, isEditor: enableDragAndDrop, dispatch: dispatch })),
|
|
146
167
|
react_1.default.createElement(Inspector_1.InspectorTabPanel, null,
|
|
147
|
-
react_1.default.createElement(FilesSection_1.FilesSection, { submissionId: submissionId, enableDragAndDrop: enableDragAndDrop, handleUpload:
|
|
168
|
+
react_1.default.createElement(FilesSection_1.FilesSection, { submissionId: submissionId, enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFileWithSupplement, fileSection: util_1.FileSectionType.Supplements, filesItem: getFileSectionExternalFile(util_1.FileSectionType.Supplements), state: state, dispatch: dispatch })),
|
|
148
169
|
react_1.default.createElement(Inspector_1.InspectorTabPanel, null,
|
|
149
170
|
react_1.default.createElement(FilesSection_1.FilesSection, { submissionId: submissionId, enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFile, fileSection: util_1.FileSectionType.OtherFile, filesItem: getFileSectionExternalFile(util_1.FileSectionType.OtherFile), state: state, dispatch: dispatch })))))),
|
|
150
171
|
state.isShowSuccessMessage &&
|
|
@@ -51,8 +51,7 @@ const InlineFilesSection = ({ submissionId, handleReplace, handleDownload, inlin
|
|
|
51
51
|
util_1.fileTypesWithIconMap.get(file.type),
|
|
52
52
|
react_1.default.createElement(FileInfo_1.FileInfoContainer, null,
|
|
53
53
|
react_1.default.createElement(FileInfo_1.FileNameTitleContainer, null,
|
|
54
|
-
react_1.default.createElement(FileInfo_1.FileTitle, null, file.label))
|
|
55
|
-
file.caption && (react_1.default.createElement(FileInfo_1.FileDescription, null, file.caption))))));
|
|
54
|
+
react_1.default.createElement(FileInfo_1.FileTitle, null, file.label))))));
|
|
56
55
|
})));
|
|
57
56
|
};
|
|
58
57
|
exports.InlineFilesSection = InlineFilesSection;
|
|
@@ -66,8 +66,8 @@ exports.default = (modelMap, attachments) => {
|
|
|
66
66
|
};
|
|
67
67
|
const getAuxiliaryObjects = (modelMap) => {
|
|
68
68
|
var _a, _b;
|
|
69
|
-
let graphicalAbstractFigureId;
|
|
70
|
-
const
|
|
69
|
+
let graphicalAbstractFigureId, figureElementIds = [];
|
|
70
|
+
const tableElementIds = [], orderObjects = {};
|
|
71
71
|
for (const model of modelMap.values()) {
|
|
72
72
|
switch (model.objectType) {
|
|
73
73
|
case manuscripts_json_schema_1.ObjectTypes.Section: {
|
|
@@ -103,6 +103,9 @@ const getAuxiliaryObjects = (modelMap) => {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
+
if (graphicalAbstractFigureId) {
|
|
107
|
+
figureElementIds = figureElementIds.filter((id) => id != graphicalAbstractFigureId);
|
|
108
|
+
}
|
|
106
109
|
return {
|
|
107
110
|
graphicalAbstractFigureId,
|
|
108
111
|
figureElement: orderObjects[manuscripts_json_schema_1.ObjectTypes.FigureElement]
|
|
@@ -7,6 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import { buildSupplementaryMaterial, getModelsByType, } from '@manuscripts/manuscript-transform';
|
|
11
|
+
import { ObjectTypes, } from '@manuscripts/manuscripts-json-schema';
|
|
10
12
|
import React, { createContext, useCallback, useMemo, useReducer } from 'react';
|
|
11
13
|
import ReactTooltip from 'react-tooltip';
|
|
12
14
|
import getInlineFiles from '../../lib/inlineFiles';
|
|
@@ -22,7 +24,7 @@ import { InlineFilesSection } from './InlineFilesSection';
|
|
|
22
24
|
import { TooltipDiv } from './TooltipDiv';
|
|
23
25
|
import { Designation, designationWithFileSectionsMap, FileSectionType, generateAttachmentsTitles, namesWithDesignationMap, } from './util';
|
|
24
26
|
export const PermissionsContext = createContext(null);
|
|
25
|
-
export const FileManager = ({ submissionId, attachments, modelMap, enableDragAndDrop, can, handleUpload, handleDownload, handleReplace, handleChangeDesignation, }) => {
|
|
27
|
+
export const FileManager = ({ submissionId, attachments, modelMap, saveModel, enableDragAndDrop, can, handleUpload, handleDownload, handleReplace, handleChangeDesignation, }) => {
|
|
26
28
|
const [state, dispatch] = useReducer(reducer, getInitialState());
|
|
27
29
|
const handleReplaceFile = useCallback((submissionId, attachmentId, name, file, typeId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
30
|
dispatch(actions.HANDLE_UPLOAD_ACTION());
|
|
@@ -40,6 +42,14 @@ export const FileManager = ({ submissionId, attachments, modelMap, enableDragAnd
|
|
|
40
42
|
dispatch(actions.HANDLE_FINISH_UPLOAD());
|
|
41
43
|
return res;
|
|
42
44
|
}), [handleUpload]);
|
|
45
|
+
const handleUploadFileWithSupplement = useCallback((submissionId, file, designation) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const res = (yield handleUploadFile(submissionId, file, designation));
|
|
47
|
+
if (res && res.data) {
|
|
48
|
+
const { id, name } = res.data.uploadAttachment;
|
|
49
|
+
yield saveModel(buildSupplementaryMaterial(name, `attachment:${id}`));
|
|
50
|
+
}
|
|
51
|
+
return res;
|
|
52
|
+
}), [handleUploadFile, saveModel]);
|
|
43
53
|
const handleChangeDesignationFile = useCallback((submissionId, attachmentId, typeId, name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
54
|
const res = yield handleChangeDesignation(submissionId, attachmentId, typeId, name);
|
|
45
55
|
if (res) {
|
|
@@ -60,15 +70,26 @@ export const FileManager = ({ submissionId, attachments, modelMap, enableDragAnd
|
|
|
60
70
|
});
|
|
61
71
|
return attachmentsIDs;
|
|
62
72
|
}, [inlineFiles]);
|
|
73
|
+
const supplementFiles = useMemo(() => {
|
|
74
|
+
const supplements = new Map(getModelsByType(modelMap, ObjectTypes.Supplement).map((supplement) => {
|
|
75
|
+
var _a;
|
|
76
|
+
return [
|
|
77
|
+
(_a = supplement.href) === null || _a === void 0 ? void 0 : _a.replace('attachment:', ''),
|
|
78
|
+
supplement,
|
|
79
|
+
];
|
|
80
|
+
}));
|
|
81
|
+
return attachments.filter((attachment) => supplements.has(attachment.id));
|
|
82
|
+
}, [attachments, modelMap.size]);
|
|
63
83
|
const getFileSectionExternalFile = (fileSection) => {
|
|
64
84
|
const isSupplementOrOtherFilesTab = fileSection === FileSectionType.Supplements ||
|
|
65
85
|
fileSection === FileSectionType.OtherFile;
|
|
66
|
-
const itemsData =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
86
|
+
const itemsData = (fileSection === FileSectionType.Supplements && supplementFiles) ||
|
|
87
|
+
attachments.filter((element) => {
|
|
88
|
+
const designation = namesWithDesignationMap.get(element.type.label);
|
|
89
|
+
return (designation !== undefined &&
|
|
90
|
+
designationWithFileSectionsMap.get(designation) === fileSection &&
|
|
91
|
+
!inlineAttachmentsIds.has(element.id));
|
|
92
|
+
});
|
|
72
93
|
const itemsDataWithTitle = generateAttachmentsTitles(itemsData, fileSection);
|
|
73
94
|
const filesItems = itemsDataWithTitle.map((element) => {
|
|
74
95
|
const itemProps = {
|
|
@@ -119,7 +140,7 @@ export const FileManager = ({ submissionId, attachments, modelMap, enableDragAnd
|
|
|
119
140
|
React.createElement(InspectorTabPanel, null,
|
|
120
141
|
React.createElement(InlineFilesSection, { inlineFiles: inlineFiles, submissionId: submissionId, handleReplace: handleReplace, handleDownload: handleDownload, isEditor: enableDragAndDrop, dispatch: dispatch })),
|
|
121
142
|
React.createElement(InspectorTabPanel, null,
|
|
122
|
-
React.createElement(FilesSection, { submissionId: submissionId, enableDragAndDrop: enableDragAndDrop, handleUpload:
|
|
143
|
+
React.createElement(FilesSection, { submissionId: submissionId, enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFileWithSupplement, fileSection: FileSectionType.Supplements, filesItem: getFileSectionExternalFile(FileSectionType.Supplements), state: state, dispatch: dispatch })),
|
|
123
144
|
React.createElement(InspectorTabPanel, null,
|
|
124
145
|
React.createElement(FilesSection, { submissionId: submissionId, enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFile, fileSection: FileSectionType.OtherFile, filesItem: getFileSectionExternalFile(FileSectionType.OtherFile), state: state, dispatch: dispatch })))))),
|
|
125
146
|
state.isShowSuccessMessage &&
|
|
@@ -2,7 +2,7 @@ import React, { useCallback } from 'react';
|
|
|
2
2
|
import styled from 'styled-components';
|
|
3
3
|
import { useDropdown } from '../../hooks/use-dropdown';
|
|
4
4
|
import DotsIcon from '../icons/dots-icon';
|
|
5
|
-
import {
|
|
5
|
+
import { FileInfoContainer, FileNameTitleContainer, FileTitle, } from './FileSectionItem/FileInfo';
|
|
6
6
|
import { ActionsIcon, Item, } from './FileSectionItem/FileSectionItem';
|
|
7
7
|
import { ItemActions } from './FileSectionItem/ItemActions';
|
|
8
8
|
import { extensionsWithFileTypesMap, fileTypesWithIconMap, } from './util';
|
|
@@ -26,8 +26,7 @@ export const InlineFilesSection = ({ submissionId, handleReplace, handleDownload
|
|
|
26
26
|
fileTypesWithIconMap.get(file.type),
|
|
27
27
|
React.createElement(FileInfoContainer, null,
|
|
28
28
|
React.createElement(FileNameTitleContainer, null,
|
|
29
|
-
React.createElement(FileTitle, null, file.label))
|
|
30
|
-
file.caption && (React.createElement(FileDescription, null, file.caption))))));
|
|
29
|
+
React.createElement(FileTitle, null, file.label))))));
|
|
31
30
|
})));
|
|
32
31
|
};
|
|
33
32
|
const FileReference = ({ attachment, submissionId, handleReplace, handleDownload, dispatch, }) => {
|
|
@@ -64,8 +64,8 @@ export default (modelMap, attachments) => {
|
|
|
64
64
|
};
|
|
65
65
|
const getAuxiliaryObjects = (modelMap) => {
|
|
66
66
|
var _a, _b;
|
|
67
|
-
let graphicalAbstractFigureId;
|
|
68
|
-
const
|
|
67
|
+
let graphicalAbstractFigureId, figureElementIds = [];
|
|
68
|
+
const tableElementIds = [], orderObjects = {};
|
|
69
69
|
for (const model of modelMap.values()) {
|
|
70
70
|
switch (model.objectType) {
|
|
71
71
|
case ObjectTypes.Section: {
|
|
@@ -101,6 +101,9 @@ const getAuxiliaryObjects = (modelMap) => {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
+
if (graphicalAbstractFigureId) {
|
|
105
|
+
figureElementIds = figureElementIds.filter((id) => id != graphicalAbstractFigureId);
|
|
106
|
+
}
|
|
104
107
|
return {
|
|
105
108
|
graphicalAbstractFigureId,
|
|
106
109
|
figureElement: orderObjects[ObjectTypes.FigureElement]
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Build } from '@manuscripts/manuscript-transform';
|
|
2
|
+
import { Model, Supplement } from '@manuscripts/manuscripts-json-schema';
|
|
2
3
|
import React from 'react';
|
|
3
4
|
import { Capabilities } from '../../lib/capabilities';
|
|
4
5
|
import { SubmissionAttachment } from './FileSectionItem/FileSectionItem';
|
|
@@ -7,6 +8,7 @@ export declare const FileManager: React.FC<{
|
|
|
7
8
|
submissionId: string;
|
|
8
9
|
attachments: SubmissionAttachment[];
|
|
9
10
|
modelMap: Map<string, Model>;
|
|
11
|
+
saveModel: (model: Build<Supplement>) => Promise<Build<Supplement>>;
|
|
10
12
|
enableDragAndDrop: boolean;
|
|
11
13
|
can: Capabilities;
|
|
12
14
|
handleUpload: (submissionId: string, file: File, designation: string) => Promise<any>;
|
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.10",
|
|
5
5
|
"repository": "gitlab:atypon-opensource/manuscripts-style-guide",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"@manuscripts/comment-editor": "^0.2.3",
|
|
64
64
|
"@manuscripts/data": "^0.1.0",
|
|
65
65
|
"@manuscripts/examples": "^0.0.7",
|
|
66
|
-
"@manuscripts/manuscript-transform": "^0.48.
|
|
66
|
+
"@manuscripts/manuscript-transform": "^0.48.19",
|
|
67
67
|
"@manuscripts/manuscripts-json-schema": "^1.49.11",
|
|
68
68
|
"@manuscripts/publish": "^0.2.2",
|
|
69
69
|
"@storybook/addon-actions": "^5.3.14",
|