@manuscripts/style-guide 0.31.30 → 0.32.31-1620-2
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 +15 -10
- package/dist/cjs/components/FileManager/FileSectionItem/ItemActions.js +4 -3
- package/dist/cjs/components/FileManager/InlineFilesSection.js +7 -5
- package/dist/cjs/lib/inlineFiles.js +8 -31
- package/dist/es/components/FileManager/FileManager.js +15 -10
- package/dist/es/components/FileManager/FileSectionItem/ItemActions.js +4 -3
- package/dist/es/components/FileManager/InlineFilesSection.js +7 -5
- package/dist/es/lib/inlineFiles.js +8 -31
- package/dist/types/components/FileManager/FileManager.d.ts +3 -2
- package/dist/types/components/FileManager/FileSectionItem/ItemActions.d.ts +1 -0
- package/dist/types/components/FileManager/InlineFilesSection.d.ts +1 -5
- package/package.json +1 -1
|
@@ -47,7 +47,7 @@ const InlineFilesSection_1 = require("./InlineFilesSection");
|
|
|
47
47
|
const TooltipDiv_1 = require("./TooltipDiv");
|
|
48
48
|
const util_1 = require("./util");
|
|
49
49
|
exports.PermissionsContext = (0, react_1.createContext)(null);
|
|
50
|
-
const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManagement: { getAttachments, changeDesignation, replace, upload }, }) => {
|
|
50
|
+
const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManagement: { getAttachments, changeDesignation, replace, upload }, addAttachmentToState, }) => {
|
|
51
51
|
const [state, dispatch] = (0, react_1.useReducer)(FileSectionState_1.reducer, (0, FileSectionState_1.getInitialState)());
|
|
52
52
|
const handleReplaceFile = (0, react_1.useCallback)((attachmentId, name, file, typeId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
53
|
dispatch(FileSectionState_1.actions.HANDLE_UPLOAD_ACTION());
|
|
@@ -86,18 +86,23 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
|
|
|
86
86
|
window.location.assign(url);
|
|
87
87
|
}, []);
|
|
88
88
|
const handleUpdateInline = (0, react_1.useCallback)((modelId, attachment) => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
-
var _a;
|
|
90
89
|
const figureModel = modelMap.get(modelId);
|
|
91
|
-
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
imageExternalFileIndex > -1) {
|
|
95
|
-
figureModel.externalFileReferences[imageExternalFileIndex].url = `attachment:${attachment.id}`;
|
|
96
|
-
yield saveModel(figureModel);
|
|
90
|
+
figureModel.src = `attachment:${attachment.id}`;
|
|
91
|
+
if (addAttachmentToState) {
|
|
92
|
+
addAttachmentToState(Object.assign({}, attachment));
|
|
97
93
|
}
|
|
98
|
-
|
|
94
|
+
yield saveModel(figureModel);
|
|
95
|
+
}), [modelMap, saveModel, addAttachmentToState]);
|
|
99
96
|
const attachments = getAttachments();
|
|
100
97
|
const { otherFiles, supplementFiles, inlineFiles } = (0, index_1.useFiles)(modelMap, attachments);
|
|
98
|
+
const handleDetachFile = (attachmentId, modelId) => {
|
|
99
|
+
var _a;
|
|
100
|
+
const model = modelMap.get(modelId);
|
|
101
|
+
if (model) {
|
|
102
|
+
const externalFileReferences = (_a = model.externalFileReferences) === null || _a === void 0 ? void 0 : _a.filter((ref) => ref.url.replace('attachment:', '') !== attachmentId);
|
|
103
|
+
saveModel(Object.assign(Object.assign({}, model), { externalFileReferences: externalFileReferences || [], src: '' }));
|
|
104
|
+
}
|
|
105
|
+
};
|
|
101
106
|
const getFileSectionExternalFile = (fileSection) => {
|
|
102
107
|
const isSupplementOrOtherFilesTab = fileSection === util_1.FileSectionType.Supplements ||
|
|
103
108
|
fileSection === util_1.FileSectionType.OtherFile;
|
|
@@ -149,7 +154,7 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
|
|
|
149
154
|
react_1.default.createElement("div", null, "Files excluded from the final submission.")))),
|
|
150
155
|
react_1.default.createElement(Inspector_1.InspectorTabPanels, { style: { overflowY: 'visible', position: 'relative' } },
|
|
151
156
|
react_1.default.createElement(Inspector_1.InspectorTabPanel, null,
|
|
152
|
-
react_1.default.createElement(InlineFilesSection_1.InlineFilesSection, { inlineFiles: inlineFiles, handleReplace: replace, handleDownload: handleDownload, handleUpdateInline: handleUpdateInline, isEditor: enableDragAndDrop, dispatch: dispatch })),
|
|
157
|
+
react_1.default.createElement(InlineFilesSection_1.InlineFilesSection, { inlineFiles: inlineFiles, handleReplace: replace, handleDownload: handleDownload, handleUpdateInline: handleUpdateInline, handleDetachFile: handleDetachFile, isEditor: enableDragAndDrop, dispatch: dispatch })),
|
|
153
158
|
react_1.default.createElement(Inspector_1.InspectorTabPanel, null,
|
|
154
159
|
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 })),
|
|
155
160
|
react_1.default.createElement(Inspector_1.InspectorTabPanel, null,
|
|
@@ -35,7 +35,7 @@ const FileManager_1 = require("../FileManager");
|
|
|
35
35
|
const FileSectionState_1 = require("../FileSectionState");
|
|
36
36
|
const ItemsAction_1 = require("../ItemsAction");
|
|
37
37
|
const util_1 = require("../util");
|
|
38
|
-
const ItemActions = ({ downloadAttachmentHandler, replaceAttachmentHandler, handleUpdateInline, attachmentId, fileName, designation, publicUrl, hideActionList, dispatch, dropDownClassName, showReplaceAction, }) => {
|
|
38
|
+
const ItemActions = ({ downloadAttachmentHandler, replaceAttachmentHandler, detachAttachmnetHandler, handleUpdateInline, attachmentId, fileName, designation, publicUrl, hideActionList, dispatch, dropDownClassName, showReplaceAction, }) => {
|
|
39
39
|
const attachmentDesignation = designation == undefined ? 'undefined' : designation;
|
|
40
40
|
const attachmentDesignationName = attachmentDesignation !== 'undefined'
|
|
41
41
|
? util_1.namesWithDesignationMap.get(attachmentDesignation)
|
|
@@ -73,12 +73,13 @@ const ItemActions = ({ downloadAttachmentHandler, replaceAttachmentHandler, hand
|
|
|
73
73
|
fileInputRef.current.click();
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
|
-
return (react_1.default.createElement(Dropdown_1.DropdownList, { direction: 'right', className: dropDownClassName, width: 125, height:
|
|
76
|
+
return (react_1.default.createElement(Dropdown_1.DropdownList, { direction: 'right', className: dropDownClassName, width: 125, height: 120, top: 5, onClick: hideActionList },
|
|
77
77
|
react_1.default.createElement(ItemsAction_1.ActionsItem, { onClick: () => {
|
|
78
78
|
publicUrl !== undefined ? downloadAttachmentHandler(publicUrl) : {};
|
|
79
79
|
} }, "Download"),
|
|
80
80
|
(can === null || can === void 0 ? void 0 : can.replaceFile) && canBeReplaced && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
81
81
|
react_1.default.createElement(ItemsAction_1.ActionsItem, { onClick: openFileDialog }, "Replace"),
|
|
82
|
-
react_1.default.createElement("input", { ref: fileInputRef, type: "file", style: { display: 'none' }, onChange: (e) => handleChange(e), value: '' })))
|
|
82
|
+
react_1.default.createElement("input", { ref: fileInputRef, type: "file", style: { display: 'none' }, onChange: (e) => handleChange(e), value: '' }))),
|
|
83
|
+
(can === null || can === void 0 ? void 0 : can.editArticle) && detachAttachmnetHandler && (react_1.default.createElement(ItemsAction_1.ActionsItem, { onClick: () => detachAttachmnetHandler() }, "Detach"))));
|
|
83
84
|
};
|
|
84
85
|
exports.ItemActions = ItemActions;
|
|
@@ -31,7 +31,7 @@ const FileInfo_1 = require("./FileSectionItem/FileInfo");
|
|
|
31
31
|
const FileSectionItem_1 = require("./FileSectionItem/FileSectionItem");
|
|
32
32
|
const ItemActions_1 = require("./FileSectionItem/ItemActions");
|
|
33
33
|
const util_1 = require("./util");
|
|
34
|
-
const InlineFilesSection = ({ handleReplace, handleDownload, handleUpdateInline, inlineFiles, isEditor, dispatch, }) => {
|
|
34
|
+
const InlineFilesSection = ({ handleReplace, handleDownload, handleUpdateInline, handleDetachFile, inlineFiles, isEditor, dispatch, }) => {
|
|
35
35
|
const onElementClick = (0, react_1.useCallback)((e) => {
|
|
36
36
|
if (!isEditor) {
|
|
37
37
|
return;
|
|
@@ -46,7 +46,7 @@ const InlineFilesSection = ({ handleReplace, handleDownload, handleUpdateInline,
|
|
|
46
46
|
return (react_1.default.createElement("div", null, inlineFiles.map((file, index) => {
|
|
47
47
|
var _a;
|
|
48
48
|
return (react_1.default.createElement(ElementItem, { className: 'item', key: index, id: file.id, onClick: onElementClick },
|
|
49
|
-
react_1.default.createElement(FileReferences, { className: 'refItems' }, (_a = file.attachments) === null || _a === void 0 ? void 0 : _a.map((attachment) => (react_1.default.createElement(FileReference, { key: attachment.id, attachment: attachment, handleReplace: handleReplace, handleUpdateInline: handleUpdateInline, handleDownload: handleDownload, dispatch: dispatch })))),
|
|
49
|
+
react_1.default.createElement(FileReferences, { className: 'refItems' }, (_a = file.attachments) === null || _a === void 0 ? void 0 : _a.map((attachment) => (react_1.default.createElement(FileReference, { key: attachment.id, attachment: attachment, handleReplace: handleReplace, handleUpdateInline: handleUpdateInline, handleDetachFile: handleDetachFile, handleDownload: handleDownload, dispatch: dispatch })))),
|
|
50
50
|
react_1.default.createElement(Element, { className: 'element' },
|
|
51
51
|
util_1.fileTypesWithIconMap.get(file.type),
|
|
52
52
|
react_1.default.createElement(FileInfo_1.FileInfoContainer, null,
|
|
@@ -55,7 +55,7 @@ const InlineFilesSection = ({ handleReplace, handleDownload, handleUpdateInline,
|
|
|
55
55
|
})));
|
|
56
56
|
};
|
|
57
57
|
exports.InlineFilesSection = InlineFilesSection;
|
|
58
|
-
const FileReference = ({ attachment, handleReplace, handleDownload, handleUpdateInline, dispatch, }) => {
|
|
58
|
+
const FileReference = ({ attachment, handleReplace, handleDownload, handleUpdateInline, handleDetachFile, dispatch, }) => {
|
|
59
59
|
const { isOpen, toggleOpen, wrapperRef } = (0, use_dropdown_1.useDropdown)();
|
|
60
60
|
if (!attachment || !attachment.name) {
|
|
61
61
|
return null;
|
|
@@ -66,11 +66,13 @@ const FileReference = ({ attachment, handleReplace, handleDownload, handleUpdate
|
|
|
66
66
|
util_1.fileTypesWithIconMap.get(util_1.extensionsWithFileTypesMap.get(fileExtension)),
|
|
67
67
|
react_1.default.createElement(FileReferenceName, null, attachment.name)),
|
|
68
68
|
handleDownload && handleReplace && (react_1.default.createElement(DropdownContainer, { ref: wrapperRef },
|
|
69
|
-
react_1.default.createElement(FileSectionItem_1.ActionsIcon, { onClick: toggleOpen, type: "button", className: 'external_file_dropdown', "aria-label": "Download or Replace", "aria-pressed": isOpen },
|
|
69
|
+
react_1.default.createElement(FileSectionItem_1.ActionsIcon, { onClick: toggleOpen, type: "button", className: 'external_file_dropdown', "aria-label": "Download or Replace or Detach", "aria-pressed": isOpen },
|
|
70
70
|
react_1.default.createElement(dots_icon_1.default, null)),
|
|
71
71
|
isOpen && (react_1.default.createElement(ItemActions_1.ItemActions, { replaceAttachmentHandler: handleReplace, showReplaceAction: true, handleUpdateInline: (uploadAttachment) => handleUpdateInline &&
|
|
72
72
|
(attachment === null || attachment === void 0 ? void 0 : attachment.modelId) &&
|
|
73
|
-
handleUpdateInline(attachment.modelId, uploadAttachment),
|
|
73
|
+
handleUpdateInline(attachment.modelId, uploadAttachment), detachAttachmnetHandler: () => handleDetachFile &&
|
|
74
|
+
attachment.modelId &&
|
|
75
|
+
handleDetachFile(attachment.id, attachment.modelId), downloadAttachmentHandler: handleDownload, attachmentId: attachment.id, fileName: attachment.name, designation: attachment.type.label, publicUrl: attachment.link, hideActionList: toggleOpen, dispatch: dispatch, dropDownClassName: 'ref_item_dropdown' }))))));
|
|
74
76
|
};
|
|
75
77
|
const ElementItem = (0, styled_components_1.default)(FileSectionItem_1.Item) `
|
|
76
78
|
display: flex;
|
|
@@ -3,26 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const manuscript_transform_1 = require("@manuscripts/manuscript-transform");
|
|
4
4
|
const manuscripts_json_schema_1 = require("@manuscripts/manuscripts-json-schema");
|
|
5
5
|
const util_1 = require("../components/FileManager/util");
|
|
6
|
-
const getAttachment = (externalFileRef, attachmentsMap) => {
|
|
7
|
-
if (!(externalFileRef === null || externalFileRef === void 0 ? void 0 : externalFileRef.url.includes('https://'))) {
|
|
8
|
-
const attachmentId = externalFileRef === null || externalFileRef === void 0 ? void 0 : externalFileRef.url.replace('attachment:', '');
|
|
9
|
-
return attachmentId ? attachmentsMap.get(attachmentId) : undefined;
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
return [...attachmentsMap.values()].find((attachment) => attachment.link === externalFileRef.url);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
6
|
const getFigureData = (element, modelMap, attachmentsMap) => {
|
|
16
7
|
const attachments = [];
|
|
17
8
|
element.containedObjectIDs.map((id) => {
|
|
18
|
-
var _a;
|
|
19
9
|
const object = modelMap.get(id);
|
|
20
10
|
if (object && object.objectType === manuscripts_json_schema_1.ObjectTypes.Figure) {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
attachment
|
|
25
|
-
|
|
11
|
+
const figure = object;
|
|
12
|
+
if (figure.src) {
|
|
13
|
+
const attachment = attachmentsMap.get(figure.src.replace('attachment:', ''));
|
|
14
|
+
if (attachment) {
|
|
15
|
+
attachment.modelId = id;
|
|
16
|
+
attachments.push(attachment);
|
|
17
|
+
}
|
|
26
18
|
}
|
|
27
19
|
}
|
|
28
20
|
});
|
|
@@ -34,7 +26,7 @@ const getFigureData = (element, modelMap, attachmentsMap) => {
|
|
|
34
26
|
exports.default = (modelMap, attachments) => {
|
|
35
27
|
const files = [];
|
|
36
28
|
const attachmentsMap = new Map(attachments.map((attachment) => [attachment.id, attachment]));
|
|
37
|
-
const { graphicalAbstractFigureId, figureElement
|
|
29
|
+
const { graphicalAbstractFigureId, figureElement } = getAuxiliaryObjects(modelMap);
|
|
38
30
|
if (graphicalAbstractFigureId) {
|
|
39
31
|
const element = modelMap.get(graphicalAbstractFigureId);
|
|
40
32
|
files.unshift(Object.assign(Object.assign({}, getFigureData(element, modelMap, attachmentsMap)), { label: `Graphical Abstract`, type: util_1.FileType.GraphicalAbstract }));
|
|
@@ -43,21 +35,6 @@ exports.default = (modelMap, attachments) => {
|
|
|
43
35
|
const element = modelMap.get(id);
|
|
44
36
|
files.push(Object.assign(Object.assign({}, getFigureData(element, modelMap, attachmentsMap)), { label: `Figure ${index + 1}`, type: util_1.FileType.Figure }));
|
|
45
37
|
});
|
|
46
|
-
tableElement.map((id) => {
|
|
47
|
-
var _a;
|
|
48
|
-
const tableElement = modelMap.get(id);
|
|
49
|
-
const table = modelMap.get(tableElement.containedObjectID);
|
|
50
|
-
const externalFileReference = (_a = table === null || table === void 0 ? void 0 : table.externalFileReferences) === null || _a === void 0 ? void 0 : _a.find((file) => file.kind === 'dataset' && file.ref);
|
|
51
|
-
const attachment = getAttachment(externalFileReference, attachmentsMap);
|
|
52
|
-
if (attachment) {
|
|
53
|
-
files.push({
|
|
54
|
-
id: tableElement._id,
|
|
55
|
-
label: `Table`,
|
|
56
|
-
type: util_1.FileType.SheetsWorkbooks,
|
|
57
|
-
attachments: [attachment],
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
38
|
return files;
|
|
62
39
|
};
|
|
63
40
|
const getAuxiliaryObjects = (modelMap) => {
|
|
@@ -22,7 +22,7 @@ import { InlineFilesSection } from './InlineFilesSection';
|
|
|
22
22
|
import { TooltipDiv } from './TooltipDiv';
|
|
23
23
|
import { Designation, FileSectionType, generateAttachmentsTitles, namesWithDesignationMap, } from './util';
|
|
24
24
|
export const PermissionsContext = createContext(null);
|
|
25
|
-
export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManagement: { getAttachments, changeDesignation, replace, upload }, }) => {
|
|
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());
|
|
@@ -61,18 +61,23 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
|
|
|
61
61
|
window.location.assign(url);
|
|
62
62
|
}, []);
|
|
63
63
|
const handleUpdateInline = useCallback((modelId, attachment) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
-
var _a;
|
|
65
64
|
const figureModel = modelMap.get(modelId);
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
imageExternalFileIndex > -1) {
|
|
70
|
-
figureModel.externalFileReferences[imageExternalFileIndex].url = `attachment:${attachment.id}`;
|
|
71
|
-
yield saveModel(figureModel);
|
|
65
|
+
figureModel.src = `attachment:${attachment.id}`;
|
|
66
|
+
if (addAttachmentToState) {
|
|
67
|
+
addAttachmentToState(Object.assign({}, attachment));
|
|
72
68
|
}
|
|
73
|
-
|
|
69
|
+
yield saveModel(figureModel);
|
|
70
|
+
}), [modelMap, saveModel, addAttachmentToState]);
|
|
74
71
|
const attachments = getAttachments();
|
|
75
72
|
const { otherFiles, supplementFiles, inlineFiles } = useFiles(modelMap, attachments);
|
|
73
|
+
const handleDetachFile = (attachmentId, modelId) => {
|
|
74
|
+
var _a;
|
|
75
|
+
const model = modelMap.get(modelId);
|
|
76
|
+
if (model) {
|
|
77
|
+
const externalFileReferences = (_a = model.externalFileReferences) === null || _a === void 0 ? void 0 : _a.filter((ref) => ref.url.replace('attachment:', '') !== attachmentId);
|
|
78
|
+
saveModel(Object.assign(Object.assign({}, model), { externalFileReferences: externalFileReferences || [], src: '' }));
|
|
79
|
+
}
|
|
80
|
+
};
|
|
76
81
|
const getFileSectionExternalFile = (fileSection) => {
|
|
77
82
|
const isSupplementOrOtherFilesTab = fileSection === FileSectionType.Supplements ||
|
|
78
83
|
fileSection === FileSectionType.OtherFile;
|
|
@@ -124,7 +129,7 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
|
|
|
124
129
|
React.createElement("div", null, "Files excluded from the final submission.")))),
|
|
125
130
|
React.createElement(InspectorTabPanels, { style: { overflowY: 'visible', position: 'relative' } },
|
|
126
131
|
React.createElement(InspectorTabPanel, null,
|
|
127
|
-
React.createElement(InlineFilesSection, { inlineFiles: inlineFiles, handleReplace: replace, handleDownload: handleDownload, handleUpdateInline: handleUpdateInline, isEditor: enableDragAndDrop, dispatch: dispatch })),
|
|
132
|
+
React.createElement(InlineFilesSection, { inlineFiles: inlineFiles, handleReplace: replace, handleDownload: handleDownload, handleUpdateInline: handleUpdateInline, handleDetachFile: handleDetachFile, isEditor: enableDragAndDrop, dispatch: dispatch })),
|
|
128
133
|
React.createElement(InspectorTabPanel, null,
|
|
129
134
|
React.createElement(FilesSection, { enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFileWithSupplement, fileSection: FileSectionType.Supplements, filesItem: getFileSectionExternalFile(FileSectionType.Supplements), state: state, dispatch: dispatch })),
|
|
130
135
|
React.createElement(InspectorTabPanel, null,
|
|
@@ -13,7 +13,7 @@ import { PermissionsContext } from '../FileManager';
|
|
|
13
13
|
import { actions } from '../FileSectionState';
|
|
14
14
|
import { ActionsItem } from '../ItemsAction';
|
|
15
15
|
import { Designation, namesWithDesignationMap } from '../util';
|
|
16
|
-
export const ItemActions = ({ downloadAttachmentHandler, replaceAttachmentHandler, handleUpdateInline, attachmentId, fileName, designation, publicUrl, hideActionList, dispatch, dropDownClassName, showReplaceAction, }) => {
|
|
16
|
+
export const ItemActions = ({ downloadAttachmentHandler, replaceAttachmentHandler, detachAttachmnetHandler, handleUpdateInline, attachmentId, fileName, designation, publicUrl, hideActionList, dispatch, dropDownClassName, showReplaceAction, }) => {
|
|
17
17
|
const attachmentDesignation = designation == undefined ? 'undefined' : designation;
|
|
18
18
|
const attachmentDesignationName = attachmentDesignation !== 'undefined'
|
|
19
19
|
? namesWithDesignationMap.get(attachmentDesignation)
|
|
@@ -51,11 +51,12 @@ export const ItemActions = ({ downloadAttachmentHandler, replaceAttachmentHandle
|
|
|
51
51
|
fileInputRef.current.click();
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
|
-
return (React.createElement(DropdownList, { direction: 'right', className: dropDownClassName, width: 125, height:
|
|
54
|
+
return (React.createElement(DropdownList, { direction: 'right', className: dropDownClassName, width: 125, height: 120, top: 5, onClick: hideActionList },
|
|
55
55
|
React.createElement(ActionsItem, { onClick: () => {
|
|
56
56
|
publicUrl !== undefined ? downloadAttachmentHandler(publicUrl) : {};
|
|
57
57
|
} }, "Download"),
|
|
58
58
|
(can === null || can === void 0 ? void 0 : can.replaceFile) && canBeReplaced && (React.createElement(React.Fragment, null,
|
|
59
59
|
React.createElement(ActionsItem, { onClick: openFileDialog }, "Replace"),
|
|
60
|
-
React.createElement("input", { ref: fileInputRef, type: "file", style: { display: 'none' }, onChange: (e) => handleChange(e), value: '' })))
|
|
60
|
+
React.createElement("input", { ref: fileInputRef, type: "file", style: { display: 'none' }, onChange: (e) => handleChange(e), value: '' }))),
|
|
61
|
+
(can === null || can === void 0 ? void 0 : can.editArticle) && detachAttachmnetHandler && (React.createElement(ActionsItem, { onClick: () => detachAttachmnetHandler() }, "Detach"))));
|
|
61
62
|
};
|
|
@@ -6,7 +6,7 @@ import { FileInfoContainer, FileNameTitleContainer, FileTitle, } from './FileSec
|
|
|
6
6
|
import { ActionsIcon, Item, } from './FileSectionItem/FileSectionItem';
|
|
7
7
|
import { ItemActions } from './FileSectionItem/ItemActions';
|
|
8
8
|
import { extensionsWithFileTypesMap, fileTypesWithIconMap, } from './util';
|
|
9
|
-
export const InlineFilesSection = ({ handleReplace, handleDownload, handleUpdateInline, inlineFiles, isEditor, dispatch, }) => {
|
|
9
|
+
export const InlineFilesSection = ({ handleReplace, handleDownload, handleUpdateInline, handleDetachFile, inlineFiles, isEditor, dispatch, }) => {
|
|
10
10
|
const onElementClick = useCallback((e) => {
|
|
11
11
|
if (!isEditor) {
|
|
12
12
|
return;
|
|
@@ -21,7 +21,7 @@ export const InlineFilesSection = ({ handleReplace, handleDownload, handleUpdate
|
|
|
21
21
|
return (React.createElement("div", null, inlineFiles.map((file, index) => {
|
|
22
22
|
var _a;
|
|
23
23
|
return (React.createElement(ElementItem, { className: 'item', key: index, id: file.id, onClick: onElementClick },
|
|
24
|
-
React.createElement(FileReferences, { className: 'refItems' }, (_a = file.attachments) === null || _a === void 0 ? void 0 : _a.map((attachment) => (React.createElement(FileReference, { key: attachment.id, attachment: attachment, handleReplace: handleReplace, handleUpdateInline: handleUpdateInline, handleDownload: handleDownload, dispatch: dispatch })))),
|
|
24
|
+
React.createElement(FileReferences, { className: 'refItems' }, (_a = file.attachments) === null || _a === void 0 ? void 0 : _a.map((attachment) => (React.createElement(FileReference, { key: attachment.id, attachment: attachment, handleReplace: handleReplace, handleUpdateInline: handleUpdateInline, handleDetachFile: handleDetachFile, handleDownload: handleDownload, dispatch: dispatch })))),
|
|
25
25
|
React.createElement(Element, { className: 'element' },
|
|
26
26
|
fileTypesWithIconMap.get(file.type),
|
|
27
27
|
React.createElement(FileInfoContainer, null,
|
|
@@ -29,7 +29,7 @@ export const InlineFilesSection = ({ handleReplace, handleDownload, handleUpdate
|
|
|
29
29
|
React.createElement(FileTitle, null, file.label))))));
|
|
30
30
|
})));
|
|
31
31
|
};
|
|
32
|
-
const FileReference = ({ attachment, handleReplace, handleDownload, handleUpdateInline, dispatch, }) => {
|
|
32
|
+
const FileReference = ({ attachment, handleReplace, handleDownload, handleUpdateInline, handleDetachFile, dispatch, }) => {
|
|
33
33
|
const { isOpen, toggleOpen, wrapperRef } = useDropdown();
|
|
34
34
|
if (!attachment || !attachment.name) {
|
|
35
35
|
return null;
|
|
@@ -40,11 +40,13 @@ const FileReference = ({ attachment, handleReplace, handleDownload, handleUpdate
|
|
|
40
40
|
fileTypesWithIconMap.get(extensionsWithFileTypesMap.get(fileExtension)),
|
|
41
41
|
React.createElement(FileReferenceName, null, attachment.name)),
|
|
42
42
|
handleDownload && handleReplace && (React.createElement(DropdownContainer, { ref: wrapperRef },
|
|
43
|
-
React.createElement(ActionsIcon, { onClick: toggleOpen, type: "button", className: 'external_file_dropdown', "aria-label": "Download or Replace", "aria-pressed": isOpen },
|
|
43
|
+
React.createElement(ActionsIcon, { onClick: toggleOpen, type: "button", className: 'external_file_dropdown', "aria-label": "Download or Replace or Detach", "aria-pressed": isOpen },
|
|
44
44
|
React.createElement(DotsIcon, null)),
|
|
45
45
|
isOpen && (React.createElement(ItemActions, { replaceAttachmentHandler: handleReplace, showReplaceAction: true, handleUpdateInline: (uploadAttachment) => handleUpdateInline &&
|
|
46
46
|
(attachment === null || attachment === void 0 ? void 0 : attachment.modelId) &&
|
|
47
|
-
handleUpdateInline(attachment.modelId, uploadAttachment),
|
|
47
|
+
handleUpdateInline(attachment.modelId, uploadAttachment), detachAttachmnetHandler: () => handleDetachFile &&
|
|
48
|
+
attachment.modelId &&
|
|
49
|
+
handleDetachFile(attachment.id, attachment.modelId), downloadAttachmentHandler: handleDownload, attachmentId: attachment.id, fileName: attachment.name, designation: attachment.type.label, publicUrl: attachment.link, hideActionList: toggleOpen, dispatch: dispatch, dropDownClassName: 'ref_item_dropdown' }))))));
|
|
48
50
|
};
|
|
49
51
|
const ElementItem = styled(Item) `
|
|
50
52
|
display: flex;
|
|
@@ -1,26 +1,18 @@
|
|
|
1
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 getAttachment = (externalFileRef, attachmentsMap) => {
|
|
5
|
-
if (!(externalFileRef === null || externalFileRef === void 0 ? void 0 : externalFileRef.url.includes('https://'))) {
|
|
6
|
-
const attachmentId = externalFileRef === null || externalFileRef === void 0 ? void 0 : externalFileRef.url.replace('attachment:', '');
|
|
7
|
-
return attachmentId ? attachmentsMap.get(attachmentId) : undefined;
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
return [...attachmentsMap.values()].find((attachment) => attachment.link === externalFileRef.url);
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
4
|
const getFigureData = (element, modelMap, attachmentsMap) => {
|
|
14
5
|
const attachments = [];
|
|
15
6
|
element.containedObjectIDs.map((id) => {
|
|
16
|
-
var _a;
|
|
17
7
|
const object = modelMap.get(id);
|
|
18
8
|
if (object && object.objectType === ObjectTypes.Figure) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
attachment
|
|
23
|
-
|
|
9
|
+
const figure = object;
|
|
10
|
+
if (figure.src) {
|
|
11
|
+
const attachment = attachmentsMap.get(figure.src.replace('attachment:', ''));
|
|
12
|
+
if (attachment) {
|
|
13
|
+
attachment.modelId = id;
|
|
14
|
+
attachments.push(attachment);
|
|
15
|
+
}
|
|
24
16
|
}
|
|
25
17
|
}
|
|
26
18
|
});
|
|
@@ -32,7 +24,7 @@ const getFigureData = (element, modelMap, attachmentsMap) => {
|
|
|
32
24
|
export default (modelMap, attachments) => {
|
|
33
25
|
const files = [];
|
|
34
26
|
const attachmentsMap = new Map(attachments.map((attachment) => [attachment.id, attachment]));
|
|
35
|
-
const { graphicalAbstractFigureId, figureElement
|
|
27
|
+
const { graphicalAbstractFigureId, figureElement } = getAuxiliaryObjects(modelMap);
|
|
36
28
|
if (graphicalAbstractFigureId) {
|
|
37
29
|
const element = modelMap.get(graphicalAbstractFigureId);
|
|
38
30
|
files.unshift(Object.assign(Object.assign({}, getFigureData(element, modelMap, attachmentsMap)), { label: `Graphical Abstract`, type: FileType.GraphicalAbstract }));
|
|
@@ -41,21 +33,6 @@ export default (modelMap, attachments) => {
|
|
|
41
33
|
const element = modelMap.get(id);
|
|
42
34
|
files.push(Object.assign(Object.assign({}, getFigureData(element, modelMap, attachmentsMap)), { label: `Figure ${index + 1}`, type: FileType.Figure }));
|
|
43
35
|
});
|
|
44
|
-
tableElement.map((id) => {
|
|
45
|
-
var _a;
|
|
46
|
-
const tableElement = modelMap.get(id);
|
|
47
|
-
const table = modelMap.get(tableElement.containedObjectID);
|
|
48
|
-
const externalFileReference = (_a = table === null || table === void 0 ? void 0 : table.externalFileReferences) === null || _a === void 0 ? void 0 : _a.find((file) => file.kind === 'dataset' && file.ref);
|
|
49
|
-
const attachment = getAttachment(externalFileReference, attachmentsMap);
|
|
50
|
-
if (attachment) {
|
|
51
|
-
files.push({
|
|
52
|
-
id: tableElement._id,
|
|
53
|
-
label: `Table`,
|
|
54
|
-
type: FileType.SheetsWorkbooks,
|
|
55
|
-
attachments: [attachment],
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
36
|
return files;
|
|
60
37
|
};
|
|
61
38
|
const getAuxiliaryObjects = (modelMap) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Build } from '@manuscripts/manuscript-transform';
|
|
2
|
-
import { Model
|
|
2
|
+
import { Model } from '@manuscripts/manuscripts-json-schema';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { Capabilities } from '../../lib/capabilities';
|
|
5
5
|
import { SubmissionAttachment } from './FileSectionItem/FileSectionItem';
|
|
@@ -16,7 +16,8 @@ export declare const PermissionsContext: React.Context<Capabilities | null>;
|
|
|
16
16
|
export declare const FileManager: React.FC<{
|
|
17
17
|
fileManagement: FileManagement;
|
|
18
18
|
modelMap: Map<string, Model>;
|
|
19
|
-
saveModel: (model: Build<
|
|
19
|
+
saveModel: <T extends Model>(model: T | Build<T> | Partial<T>) => Promise<T>;
|
|
20
20
|
enableDragAndDrop: boolean;
|
|
21
21
|
can: Capabilities;
|
|
22
|
+
addAttachmentToState?: (a: SubmissionAttachment) => void;
|
|
22
23
|
}>;
|
|
@@ -6,6 +6,7 @@ import { SubmissionAttachment } from './FileSectionItem';
|
|
|
6
6
|
export declare const ItemActions: React.FC<{
|
|
7
7
|
downloadAttachmentHandler: (url: string) => void;
|
|
8
8
|
replaceAttachmentHandler: Replace;
|
|
9
|
+
detachAttachmnetHandler?: () => void;
|
|
9
10
|
handleUpdateInline?: (attachment: SubmissionAttachment) => void;
|
|
10
11
|
attachmentId: string;
|
|
11
12
|
fileName: string;
|
|
@@ -3,11 +3,6 @@ import { Replace } from './FileManager';
|
|
|
3
3
|
import { SubmissionAttachment } from './FileSectionItem/FileSectionItem';
|
|
4
4
|
import { Action } from './FileSectionState';
|
|
5
5
|
import { FileType } from './util';
|
|
6
|
-
export interface ExternalFileRef {
|
|
7
|
-
url: string;
|
|
8
|
-
kind?: string;
|
|
9
|
-
ref?: SubmissionAttachment;
|
|
10
|
-
}
|
|
11
6
|
export declare const InlineFilesSection: React.FC<{
|
|
12
7
|
inlineFiles: {
|
|
13
8
|
id: string;
|
|
@@ -19,6 +14,7 @@ export declare const InlineFilesSection: React.FC<{
|
|
|
19
14
|
handleReplace: Replace;
|
|
20
15
|
handleDownload: (url: string) => void;
|
|
21
16
|
handleUpdateInline?: (modelId: string, attachment: SubmissionAttachment) => void;
|
|
17
|
+
handleDetachFile?: (attachmentLink: string, modelId: string) => void;
|
|
22
18
|
isEditor: boolean;
|
|
23
19
|
dispatch: Dispatch<Action>;
|
|
24
20
|
}>;
|
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.32.31-1620-2",
|
|
5
5
|
"repository": "gitlab:atypon-opensource/manuscripts-style-guide",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|