@manuscripts/style-guide 0.31.30 → 0.32.31
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 +20 -5
- 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 +2 -2
- package/dist/es/components/FileManager/FileManager.js +20 -5
- 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 +2 -2
- 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 -0
- 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());
|
|
@@ -92,12 +92,27 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
|
|
|
92
92
|
if (figureModel.externalFileReferences &&
|
|
93
93
|
typeof imageExternalFileIndex !== 'undefined' &&
|
|
94
94
|
imageExternalFileIndex > -1) {
|
|
95
|
-
figureModel.externalFileReferences
|
|
96
|
-
|
|
95
|
+
const newRefs = [...figureModel.externalFileReferences];
|
|
96
|
+
newRefs[imageExternalFileIndex] = {
|
|
97
|
+
url: `attachment:${attachment.id}`,
|
|
98
|
+
kind: 'imageRepresentation',
|
|
99
|
+
};
|
|
100
|
+
if (addAttachmentToState) {
|
|
101
|
+
addAttachmentToState(Object.assign({}, attachment));
|
|
102
|
+
}
|
|
103
|
+
yield saveModel(Object.assign(Object.assign({}, figureModel), { src: '', externalFileReferences: newRefs }));
|
|
97
104
|
}
|
|
98
|
-
}), [modelMap, saveModel]);
|
|
105
|
+
}), [modelMap, saveModel, addAttachmentToState]);
|
|
99
106
|
const attachments = getAttachments();
|
|
100
107
|
const { otherFiles, supplementFiles, inlineFiles } = (0, index_1.useFiles)(modelMap, attachments);
|
|
108
|
+
const handleDetachFile = (attachmentId, modelId) => {
|
|
109
|
+
var _a;
|
|
110
|
+
const model = modelMap.get(modelId);
|
|
111
|
+
if (model) {
|
|
112
|
+
const externalFileReferences = (_a = model.externalFileReferences) === null || _a === void 0 ? void 0 : _a.filter((ref) => ref.url.replace('attachment:', '') !== attachmentId);
|
|
113
|
+
saveModel(Object.assign(Object.assign({}, model), { externalFileReferences: externalFileReferences || [], src: '' }));
|
|
114
|
+
}
|
|
115
|
+
};
|
|
101
116
|
const getFileSectionExternalFile = (fileSection) => {
|
|
102
117
|
const isSupplementOrOtherFilesTab = fileSection === util_1.FileSectionType.Supplements ||
|
|
103
118
|
fileSection === util_1.FileSectionType.OtherFile;
|
|
@@ -149,7 +164,7 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
|
|
|
149
164
|
react_1.default.createElement("div", null, "Files excluded from the final submission.")))),
|
|
150
165
|
react_1.default.createElement(Inspector_1.InspectorTabPanels, { style: { overflowY: 'visible', position: 'relative' } },
|
|
151
166
|
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 })),
|
|
167
|
+
react_1.default.createElement(InlineFilesSection_1.InlineFilesSection, { inlineFiles: inlineFiles, handleReplace: replace, handleDownload: handleDownload, handleUpdateInline: handleUpdateInline, handleDetachFile: handleDetachFile, isEditor: enableDragAndDrop, dispatch: dispatch })),
|
|
153
168
|
react_1.default.createElement(Inspector_1.InspectorTabPanel, null,
|
|
154
169
|
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
170
|
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;
|
|
@@ -4,12 +4,12 @@ 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
6
|
const getAttachment = (externalFileRef, attachmentsMap) => {
|
|
7
|
-
if (!(externalFileRef === null || externalFileRef === void 0 ? void 0 : externalFileRef.url.
|
|
7
|
+
if (!(externalFileRef === null || externalFileRef === void 0 ? void 0 : externalFileRef.url.startsWith('http'))) {
|
|
8
8
|
const attachmentId = externalFileRef === null || externalFileRef === void 0 ? void 0 : externalFileRef.url.replace('attachment:', '');
|
|
9
9
|
return attachmentId ? attachmentsMap.get(attachmentId) : undefined;
|
|
10
10
|
}
|
|
11
11
|
else {
|
|
12
|
-
return [...attachmentsMap.values()].find((attachment) => attachment.link === externalFileRef.url);
|
|
12
|
+
return [...attachmentsMap.values()].find((attachment) => attachment.link === externalFileRef.url.replace(/[&|?]format=jpg/, ''));
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
const getFigureData = (element, modelMap, attachmentsMap) => {
|
|
@@ -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());
|
|
@@ -67,12 +67,27 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
|
|
|
67
67
|
if (figureModel.externalFileReferences &&
|
|
68
68
|
typeof imageExternalFileIndex !== 'undefined' &&
|
|
69
69
|
imageExternalFileIndex > -1) {
|
|
70
|
-
figureModel.externalFileReferences
|
|
71
|
-
|
|
70
|
+
const newRefs = [...figureModel.externalFileReferences];
|
|
71
|
+
newRefs[imageExternalFileIndex] = {
|
|
72
|
+
url: `attachment:${attachment.id}`,
|
|
73
|
+
kind: 'imageRepresentation',
|
|
74
|
+
};
|
|
75
|
+
if (addAttachmentToState) {
|
|
76
|
+
addAttachmentToState(Object.assign({}, attachment));
|
|
77
|
+
}
|
|
78
|
+
yield saveModel(Object.assign(Object.assign({}, figureModel), { src: '', externalFileReferences: newRefs }));
|
|
72
79
|
}
|
|
73
|
-
}), [modelMap, saveModel]);
|
|
80
|
+
}), [modelMap, saveModel, addAttachmentToState]);
|
|
74
81
|
const attachments = getAttachments();
|
|
75
82
|
const { otherFiles, supplementFiles, inlineFiles } = useFiles(modelMap, attachments);
|
|
83
|
+
const handleDetachFile = (attachmentId, modelId) => {
|
|
84
|
+
var _a;
|
|
85
|
+
const model = modelMap.get(modelId);
|
|
86
|
+
if (model) {
|
|
87
|
+
const externalFileReferences = (_a = model.externalFileReferences) === null || _a === void 0 ? void 0 : _a.filter((ref) => ref.url.replace('attachment:', '') !== attachmentId);
|
|
88
|
+
saveModel(Object.assign(Object.assign({}, model), { externalFileReferences: externalFileReferences || [], src: '' }));
|
|
89
|
+
}
|
|
90
|
+
};
|
|
76
91
|
const getFileSectionExternalFile = (fileSection) => {
|
|
77
92
|
const isSupplementOrOtherFilesTab = fileSection === FileSectionType.Supplements ||
|
|
78
93
|
fileSection === FileSectionType.OtherFile;
|
|
@@ -124,7 +139,7 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
|
|
|
124
139
|
React.createElement("div", null, "Files excluded from the final submission.")))),
|
|
125
140
|
React.createElement(InspectorTabPanels, { style: { overflowY: 'visible', position: 'relative' } },
|
|
126
141
|
React.createElement(InspectorTabPanel, null,
|
|
127
|
-
React.createElement(InlineFilesSection, { inlineFiles: inlineFiles, handleReplace: replace, handleDownload: handleDownload, handleUpdateInline: handleUpdateInline, isEditor: enableDragAndDrop, dispatch: dispatch })),
|
|
142
|
+
React.createElement(InlineFilesSection, { inlineFiles: inlineFiles, handleReplace: replace, handleDownload: handleDownload, handleUpdateInline: handleUpdateInline, handleDetachFile: handleDetachFile, isEditor: enableDragAndDrop, dispatch: dispatch })),
|
|
128
143
|
React.createElement(InspectorTabPanel, null,
|
|
129
144
|
React.createElement(FilesSection, { enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFileWithSupplement, fileSection: FileSectionType.Supplements, filesItem: getFileSectionExternalFile(FileSectionType.Supplements), state: state, dispatch: dispatch })),
|
|
130
145
|
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;
|
|
@@ -2,12 +2,12 @@ import { hasObjectType } from '@manuscripts/manuscript-transform';
|
|
|
2
2
|
import { ObjectTypes, } from '@manuscripts/manuscripts-json-schema';
|
|
3
3
|
import { FileType } from '../components/FileManager/util';
|
|
4
4
|
const getAttachment = (externalFileRef, attachmentsMap) => {
|
|
5
|
-
if (!(externalFileRef === null || externalFileRef === void 0 ? void 0 : externalFileRef.url.
|
|
5
|
+
if (!(externalFileRef === null || externalFileRef === void 0 ? void 0 : externalFileRef.url.startsWith('http'))) {
|
|
6
6
|
const attachmentId = externalFileRef === null || externalFileRef === void 0 ? void 0 : externalFileRef.url.replace('attachment:', '');
|
|
7
7
|
return attachmentId ? attachmentsMap.get(attachmentId) : undefined;
|
|
8
8
|
}
|
|
9
9
|
else {
|
|
10
|
-
return [...attachmentsMap.values()].find((attachment) => attachment.link === externalFileRef.url);
|
|
10
|
+
return [...attachmentsMap.values()].find((attachment) => attachment.link === externalFileRef.url.replace(/[&|?]format=jpg/, ''));
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
13
|
const getFigureData = (element, modelMap, attachmentsMap) => {
|
|
@@ -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;
|
|
@@ -19,6 +19,7 @@ export declare const InlineFilesSection: React.FC<{
|
|
|
19
19
|
handleReplace: Replace;
|
|
20
20
|
handleDownload: (url: string) => void;
|
|
21
21
|
handleUpdateInline?: (modelId: string, attachment: SubmissionAttachment) => void;
|
|
22
|
+
handleDetachFile?: (attachmentLink: string, modelId: string) => void;
|
|
22
23
|
isEditor: boolean;
|
|
23
24
|
dispatch: Dispatch<Action>;
|
|
24
25
|
}>;
|
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",
|
|
5
5
|
"repository": "gitlab:atypon-opensource/manuscripts-style-guide",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|