@manuscripts/style-guide 0.31.9 → 0.31.12

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.
@@ -33,10 +33,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
34
  exports.FileManager = exports.PermissionsContext = void 0;
35
35
  const manuscript_transform_1 = require("@manuscripts/manuscript-transform");
36
- const manuscripts_json_schema_1 = require("@manuscripts/manuscripts-json-schema");
37
36
  const react_1 = __importStar(require("react"));
38
37
  const react_tooltip_1 = __importDefault(require("react-tooltip"));
39
- const inlineFiles_1 = __importDefault(require("../../lib/inlineFiles"));
38
+ const inlineFiles_1 = __importStar(require("../../lib/inlineFiles"));
40
39
  const AlertMessage_1 = require("../AlertMessage");
41
40
  const Inspector_1 = require("../Inspector");
42
41
  const InspectorSection_1 = require("../InspectorSection");
@@ -49,7 +48,7 @@ const InlineFilesSection_1 = require("./InlineFilesSection");
49
48
  const TooltipDiv_1 = require("./TooltipDiv");
50
49
  const util_1 = require("./util");
51
50
  exports.PermissionsContext = (0, react_1.createContext)(null);
52
- const FileManager = ({ submissionId, attachments, modelMap, saveModel, enableDragAndDrop, can, handleUpload, handleDownload, handleReplace, handleChangeDesignation, }) => {
51
+ const FileManager = ({ submissionId, attachments, modelMap, saveModel, enableDragAndDrop, can, handleUpload, handleDownload, handleReplace, handleChangeDesignation, handleUpdateInline, }) => {
53
52
  const [state, dispatch] = (0, react_1.useReducer)(FileSectionState_1.reducer, (0, FileSectionState_1.getInitialState)());
54
53
  const handleReplaceFile = (0, react_1.useCallback)((submissionId, attachmentId, name, file, typeId) => __awaiter(void 0, void 0, void 0, function* () {
55
54
  dispatch(FileSectionState_1.actions.HANDLE_UPLOAD_ACTION());
@@ -86,25 +85,17 @@ const FileManager = ({ submissionId, attachments, modelMap, saveModel, enableDra
86
85
  return handleDownload(publicUrl);
87
86
  }, [handleDownload]);
88
87
  const inlineFiles = (0, react_1.useMemo)(() => (0, inlineFiles_1.default)(modelMap, attachments), [modelMap.values(), attachments]);
89
- const inlineAttachmentsIds = (0, react_1.useMemo)(() => {
88
+ const supplementFiles = (0, react_1.useMemo)(() => (0, inlineFiles_1.getSupplementFiles)(modelMap, attachments), [attachments, modelMap.size]);
89
+ const excludedAttachmentsIds = (0, react_1.useMemo)(() => {
90
90
  const attachmentsIDs = new Set();
91
91
  inlineFiles.map(({ attachments }) => {
92
92
  if (attachments) {
93
93
  attachments.map((attachment) => attachmentsIDs.add(attachment.id));
94
94
  }
95
95
  });
96
+ supplementFiles.map(({ id }) => attachmentsIDs.add(id));
96
97
  return attachmentsIDs;
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]);
98
+ }, [inlineFiles, supplementFiles]);
108
99
  const getFileSectionExternalFile = (fileSection) => {
109
100
  const isSupplementOrOtherFilesTab = fileSection === util_1.FileSectionType.Supplements ||
110
101
  fileSection === util_1.FileSectionType.OtherFile;
@@ -113,7 +104,7 @@ const FileManager = ({ submissionId, attachments, modelMap, saveModel, enableDra
113
104
  const designation = util_1.namesWithDesignationMap.get(element.type.label);
114
105
  return (designation !== undefined &&
115
106
  util_1.designationWithFileSectionsMap.get(designation) === fileSection &&
116
- !inlineAttachmentsIds.has(element.id));
107
+ !excludedAttachmentsIds.has(element.id));
117
108
  });
118
109
  const itemsDataWithTitle = (0, util_1.generateAttachmentsTitles)(itemsData, fileSection);
119
110
  const filesItems = itemsDataWithTitle.map((element) => {
@@ -163,7 +154,7 @@ const FileManager = ({ submissionId, attachments, modelMap, saveModel, enableDra
163
154
  react_1.default.createElement("div", null, "Files excluded from the final submission.")))),
164
155
  react_1.default.createElement(Inspector_1.InspectorTabPanels, { style: { overflowY: 'visible', position: 'relative' } },
165
156
  react_1.default.createElement(Inspector_1.InspectorTabPanel, null,
166
- react_1.default.createElement(InlineFilesSection_1.InlineFilesSection, { inlineFiles: inlineFiles, submissionId: submissionId, handleReplace: handleReplace, handleDownload: handleDownload, isEditor: enableDragAndDrop, dispatch: dispatch })),
157
+ react_1.default.createElement(InlineFilesSection_1.InlineFilesSection, { inlineFiles: inlineFiles, submissionId: submissionId, handleReplace: handleReplace, handleDownload: handleDownload, handleUpdateInline: handleUpdateInline, isEditor: enableDragAndDrop, dispatch: dispatch })),
167
158
  react_1.default.createElement(Inspector_1.InspectorTabPanel, null,
168
159
  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 })),
169
160
  react_1.default.createElement(Inspector_1.InspectorTabPanel, null,
@@ -18,6 +18,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
21
30
  Object.defineProperty(exports, "__esModule", { value: true });
22
31
  exports.ItemActions = void 0;
23
32
  const react_1 = __importStar(require("react"));
@@ -25,22 +34,40 @@ const Dropdown_1 = require("../../Dropdown");
25
34
  const FileManager_1 = require("../FileManager");
26
35
  const FileSectionState_1 = require("../FileSectionState");
27
36
  const ItemsAction_1 = require("../ItemsAction");
28
- const ItemActions = ({ downloadAttachmentHandler, replaceAttachmentHandler, submissionId, attachmentId, fileName, designation, publicUrl, hideActionList, dispatch, dropDownClassName, }) => {
37
+ const util_1 = require("../util");
38
+ const ItemActions = ({ downloadAttachmentHandler, replaceAttachmentHandler, handleUpdateInline, submissionId, attachmentId, fileName, designation, publicUrl, hideActionList, dispatch, dropDownClassName, }) => {
29
39
  const attachmentDesignation = designation == undefined ? 'undefined' : designation;
40
+ const attachmentDesignationName = attachmentDesignation !== 'undefined'
41
+ ? util_1.namesWithDesignationMap.get(attachmentDesignation)
42
+ : undefined;
43
+ const canBeReplaced = attachmentDesignationName == undefined ||
44
+ ![
45
+ util_1.Designation.MainManuscript,
46
+ util_1.Designation.SubmissionFile,
47
+ util_1.Designation.SubmissionPdf,
48
+ ].includes(attachmentDesignationName);
30
49
  const fileInputRef = (0, react_1.useRef)(null);
31
50
  const [selectedFile, setSelectedFile] = (0, react_1.useState)();
32
51
  const can = (0, react_1.useContext)(FileManager_1.PermissionsContext);
33
- const handleChange = (event) => {
52
+ const handleChange = (event) => __awaiter(void 0, void 0, void 0, function* () {
34
53
  if (event && event.target && event.target.files) {
35
54
  const file = event.target.files[0];
36
55
  setSelectedFile(file);
37
56
  if (dispatch) {
38
- dispatch(FileSectionState_1.actions.UPLOAD_FILE(file));
57
+ dispatch(FileSectionState_1.actions.HANDLE_UPLOAD_ACTION());
58
+ dispatch(FileSectionState_1.actions.SELECT_DESIGNATION(attachmentDesignationName || util_1.Designation.Document));
59
+ }
60
+ const result = yield replaceAttachmentHandler(submissionId, attachmentId, fileName, file, attachmentDesignation);
61
+ const { uploadAttachment } = result === null || result === void 0 ? void 0 : result.data;
62
+ if (uploadAttachment && handleUpdateInline) {
63
+ handleUpdateInline(uploadAttachment);
64
+ }
65
+ if (dispatch) {
66
+ dispatch(FileSectionState_1.actions.HANDLE_FINISH_UPLOAD());
39
67
  }
40
- replaceAttachmentHandler(submissionId, attachmentId, fileName, file, attachmentDesignation);
41
68
  hideActionList();
42
69
  }
43
- };
70
+ });
44
71
  const openFileDialog = () => {
45
72
  if (fileInputRef && fileInputRef.current) {
46
73
  fileInputRef.current.click();
@@ -50,7 +77,7 @@ const ItemActions = ({ downloadAttachmentHandler, replaceAttachmentHandler, subm
50
77
  react_1.default.createElement(ItemsAction_1.ActionsItem, { onClick: () => {
51
78
  publicUrl !== undefined ? downloadAttachmentHandler(publicUrl) : {};
52
79
  } }, "Download"),
53
- (can === null || can === void 0 ? void 0 : can.replaceFile) && (react_1.default.createElement(react_1.default.Fragment, null,
80
+ (can === null || can === void 0 ? void 0 : can.replaceFile) && canBeReplaced && (react_1.default.createElement(react_1.default.Fragment, null,
54
81
  react_1.default.createElement(ItemsAction_1.ActionsItem, { onClick: openFileDialog }, "Replace"),
55
82
  react_1.default.createElement("input", { ref: fileInputRef, type: "file", style: { display: 'none' }, onChange: (e) => handleChange(e), value: '' })))));
56
83
  };
@@ -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 = ({ submissionId, handleReplace, handleDownload, inlineFiles, isEditor, dispatch, }) => {
34
+ const InlineFilesSection = ({ submissionId, handleReplace, handleDownload, handleUpdateInline, inlineFiles, isEditor, dispatch, }) => {
35
35
  const onElementClick = (0, react_1.useCallback)((e) => {
36
36
  if (!isEditor) {
37
37
  return;
@@ -46,17 +46,16 @@ const InlineFilesSection = ({ submissionId, handleReplace, handleDownload, inlin
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, submissionId: submissionId, handleReplace: handleReplace, 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, submissionId: submissionId, handleReplace: handleReplace, handleUpdateInline: handleUpdateInline, 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,
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;
59
- const FileReference = ({ attachment, submissionId, handleReplace, handleDownload, dispatch, }) => {
58
+ const FileReference = ({ attachment, submissionId, handleReplace, handleDownload, handleUpdateInline, dispatch, }) => {
60
59
  const { isOpen, toggleOpen, wrapperRef } = (0, use_dropdown_1.useDropdown)();
61
60
  if (!attachment || !attachment.name) {
62
61
  return null;
@@ -69,7 +68,9 @@ const FileReference = ({ attachment, submissionId, handleReplace, handleDownload
69
68
  handleDownload && handleReplace && submissionId && (react_1.default.createElement(DropdownContainer, { ref: wrapperRef },
70
69
  react_1.default.createElement(FileSectionItem_1.ActionsIcon, { onClick: toggleOpen, type: "button", className: 'external_file_dropdown', "aria-label": "Download or Replace", "aria-pressed": isOpen },
71
70
  react_1.default.createElement(dots_icon_1.default, null)),
72
- isOpen && (react_1.default.createElement(ItemActions_1.ItemActions, { replaceAttachmentHandler: handleReplace, downloadAttachmentHandler: handleDownload, submissionId: submissionId, attachmentId: attachment.id, fileName: attachment.name, designation: attachment.type.label, publicUrl: attachment.link, hideActionList: toggleOpen, dispatch: dispatch, dropDownClassName: 'ref_item_dropdown' }))))));
71
+ isOpen && (react_1.default.createElement(ItemActions_1.ItemActions, { replaceAttachmentHandler: handleReplace, handleUpdateInline: (uploadAttachment) => handleUpdateInline &&
72
+ (attachment === null || attachment === void 0 ? void 0 : attachment.modelId) &&
73
+ handleUpdateInline(attachment.modelId, uploadAttachment), downloadAttachmentHandler: handleDownload, submissionId: submissionId, attachmentId: attachment.id, fileName: attachment.name, designation: attachment.type.label, publicUrl: attachment.link, hideActionList: toggleOpen, dispatch: dispatch, dropDownClassName: 'ref_item_dropdown' }))))));
73
74
  };
74
75
  const ElementItem = (0, styled_components_1.default)(FileSectionItem_1.Item) `
75
76
  display: flex;
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.PdfPreview = exports.inlineFiles = void 0;
31
+ exports.SelectDialogDesignation = exports.errorsDecoder = exports.PdfPreview = exports.getSupplementFiles = exports.inlineFiles = void 0;
32
32
  __exportStar(require("./components/AffiliationsEditor"), exports);
33
33
  __exportStar(require("./components/AffiliationsList"), exports);
34
34
  __exportStar(require("./components/AuthorForm"), exports);
@@ -62,6 +62,7 @@ __exportStar(require("./components/Inspector"), exports);
62
62
  __exportStar(require("./components/InspectorSection"), exports);
63
63
  var inlineFiles_1 = require("./lib/inlineFiles");
64
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; } });
65
66
  var PdfPreview_1 = require("./components/PdfPreview");
66
67
  Object.defineProperty(exports, "PdfPreview", { enumerable: true, get: function () { return __importDefault(PdfPreview_1).default; } });
67
68
  __exportStar(require("./components/SubmissionInspector"), exports);
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSupplementFiles = void 0;
3
4
  const manuscript_transform_1 = require("@manuscripts/manuscript-transform");
4
5
  const manuscripts_json_schema_1 = require("@manuscripts/manuscripts-json-schema");
5
6
  const util_1 = require("../components/FileManager/util");
@@ -17,13 +18,14 @@ const getAttachment = (externalFileRef, attachmentsMap) => {
17
18
  };
18
19
  const getFigureData = (element, modelMap, attachmentsMap) => {
19
20
  const attachments = [];
20
- element.containedObjectIDs.map((e) => {
21
+ element.containedObjectIDs.map((id) => {
21
22
  var _a;
22
- const object = modelMap.get(e);
23
+ const object = modelMap.get(id);
23
24
  if (object && object.objectType === manuscripts_json_schema_1.ObjectTypes.Figure) {
24
25
  const externalFileRef = (_a = object.externalFileReferences) === null || _a === void 0 ? void 0 : _a.find((figure) => figure.kind === 'imageRepresentation');
25
26
  const attachment = getAttachment(externalFileRef, attachmentsMap);
26
27
  if (attachment) {
28
+ attachment.modelId = id;
27
29
  attachments.push(attachment);
28
30
  }
29
31
  }
@@ -66,8 +68,8 @@ exports.default = (modelMap, attachments) => {
66
68
  };
67
69
  const getAuxiliaryObjects = (modelMap) => {
68
70
  var _a, _b;
69
- let graphicalAbstractFigureId;
70
- const figureElementIds = [], tableElementIds = [], orderObjects = {};
71
+ let graphicalAbstractFigureId, figureElementIds = [];
72
+ const tableElementIds = [], orderObjects = {};
71
73
  for (const model of modelMap.values()) {
72
74
  switch (model.objectType) {
73
75
  case manuscripts_json_schema_1.ObjectTypes.Section: {
@@ -103,6 +105,9 @@ const getAuxiliaryObjects = (modelMap) => {
103
105
  }
104
106
  }
105
107
  }
108
+ if (graphicalAbstractFigureId) {
109
+ figureElementIds = figureElementIds.filter((id) => id != graphicalAbstractFigureId);
110
+ }
106
111
  return {
107
112
  graphicalAbstractFigureId,
108
113
  figureElement: orderObjects[manuscripts_json_schema_1.ObjectTypes.FigureElement]
@@ -116,3 +121,8 @@ const getAuxiliaryObjects = (modelMap) => {
116
121
  const sortAuxiliaryObject = (orderObject, auxiliaryObjectIds) => {
117
122
  return auxiliaryObjectIds.sort((a, b) => orderObject.elements.indexOf(a) - orderObject.elements.indexOf(b));
118
123
  };
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;
@@ -7,11 +7,10 @@ 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
+ import { buildSupplementaryMaterial, } from '@manuscripts/manuscript-transform';
12
11
  import React, { createContext, useCallback, useMemo, useReducer } from 'react';
13
12
  import ReactTooltip from 'react-tooltip';
14
- import getInlineFiles from '../../lib/inlineFiles';
13
+ import getInlineFiles, { getSupplementFiles } from '../../lib/inlineFiles';
15
14
  import { AlertMessage, AlertMessageType } from '../AlertMessage';
16
15
  import { InspectorTab, InspectorTabList, InspectorTabPanel, InspectorTabPanels, InspectorTabs, } from '../Inspector';
17
16
  import { InspectorSection } from '../InspectorSection';
@@ -24,7 +23,7 @@ import { InlineFilesSection } from './InlineFilesSection';
24
23
  import { TooltipDiv } from './TooltipDiv';
25
24
  import { Designation, designationWithFileSectionsMap, FileSectionType, generateAttachmentsTitles, namesWithDesignationMap, } from './util';
26
25
  export const PermissionsContext = createContext(null);
27
- export const FileManager = ({ submissionId, attachments, modelMap, saveModel, enableDragAndDrop, can, handleUpload, handleDownload, handleReplace, handleChangeDesignation, }) => {
26
+ export const FileManager = ({ submissionId, attachments, modelMap, saveModel, enableDragAndDrop, can, handleUpload, handleDownload, handleReplace, handleChangeDesignation, handleUpdateInline, }) => {
28
27
  const [state, dispatch] = useReducer(reducer, getInitialState());
29
28
  const handleReplaceFile = useCallback((submissionId, attachmentId, name, file, typeId) => __awaiter(void 0, void 0, void 0, function* () {
30
29
  dispatch(actions.HANDLE_UPLOAD_ACTION());
@@ -61,25 +60,17 @@ export const FileManager = ({ submissionId, attachments, modelMap, saveModel, en
61
60
  return handleDownload(publicUrl);
62
61
  }, [handleDownload]);
63
62
  const inlineFiles = useMemo(() => getInlineFiles(modelMap, attachments), [modelMap.values(), attachments]);
64
- const inlineAttachmentsIds = useMemo(() => {
63
+ const supplementFiles = useMemo(() => getSupplementFiles(modelMap, attachments), [attachments, modelMap.size]);
64
+ const excludedAttachmentsIds = useMemo(() => {
65
65
  const attachmentsIDs = new Set();
66
66
  inlineFiles.map(({ attachments }) => {
67
67
  if (attachments) {
68
68
  attachments.map((attachment) => attachmentsIDs.add(attachment.id));
69
69
  }
70
70
  });
71
+ supplementFiles.map(({ id }) => attachmentsIDs.add(id));
71
72
  return attachmentsIDs;
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]);
73
+ }, [inlineFiles, supplementFiles]);
83
74
  const getFileSectionExternalFile = (fileSection) => {
84
75
  const isSupplementOrOtherFilesTab = fileSection === FileSectionType.Supplements ||
85
76
  fileSection === FileSectionType.OtherFile;
@@ -88,7 +79,7 @@ export const FileManager = ({ submissionId, attachments, modelMap, saveModel, en
88
79
  const designation = namesWithDesignationMap.get(element.type.label);
89
80
  return (designation !== undefined &&
90
81
  designationWithFileSectionsMap.get(designation) === fileSection &&
91
- !inlineAttachmentsIds.has(element.id));
82
+ !excludedAttachmentsIds.has(element.id));
92
83
  });
93
84
  const itemsDataWithTitle = generateAttachmentsTitles(itemsData, fileSection);
94
85
  const filesItems = itemsDataWithTitle.map((element) => {
@@ -138,7 +129,7 @@ export const FileManager = ({ submissionId, attachments, modelMap, saveModel, en
138
129
  React.createElement("div", null, "Files excluded from the final submission.")))),
139
130
  React.createElement(InspectorTabPanels, { style: { overflowY: 'visible', position: 'relative' } },
140
131
  React.createElement(InspectorTabPanel, null,
141
- React.createElement(InlineFilesSection, { inlineFiles: inlineFiles, submissionId: submissionId, handleReplace: handleReplace, handleDownload: handleDownload, isEditor: enableDragAndDrop, dispatch: dispatch })),
132
+ React.createElement(InlineFilesSection, { inlineFiles: inlineFiles, submissionId: submissionId, handleReplace: handleReplace, handleDownload: handleDownload, handleUpdateInline: handleUpdateInline, isEditor: enableDragAndDrop, dispatch: dispatch })),
142
133
  React.createElement(InspectorTabPanel, null,
143
134
  React.createElement(FilesSection, { submissionId: submissionId, enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFileWithSupplement, fileSection: FileSectionType.Supplements, filesItem: getFileSectionExternalFile(FileSectionType.Supplements), state: state, dispatch: dispatch })),
144
135
  React.createElement(InspectorTabPanel, null,
@@ -1,24 +1,51 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import React, { useContext, useRef, useState, } from 'react';
2
11
  import { DropdownList } from '../../Dropdown';
3
12
  import { PermissionsContext } from '../FileManager';
4
13
  import { actions } from '../FileSectionState';
5
14
  import { ActionsItem } from '../ItemsAction';
6
- export const ItemActions = ({ downloadAttachmentHandler, replaceAttachmentHandler, submissionId, attachmentId, fileName, designation, publicUrl, hideActionList, dispatch, dropDownClassName, }) => {
15
+ import { Designation, namesWithDesignationMap } from '../util';
16
+ export const ItemActions = ({ downloadAttachmentHandler, replaceAttachmentHandler, handleUpdateInline, submissionId, attachmentId, fileName, designation, publicUrl, hideActionList, dispatch, dropDownClassName, }) => {
7
17
  const attachmentDesignation = designation == undefined ? 'undefined' : designation;
18
+ const attachmentDesignationName = attachmentDesignation !== 'undefined'
19
+ ? namesWithDesignationMap.get(attachmentDesignation)
20
+ : undefined;
21
+ const canBeReplaced = attachmentDesignationName == undefined ||
22
+ ![
23
+ Designation.MainManuscript,
24
+ Designation.SubmissionFile,
25
+ Designation.SubmissionPdf,
26
+ ].includes(attachmentDesignationName);
8
27
  const fileInputRef = useRef(null);
9
28
  const [selectedFile, setSelectedFile] = useState();
10
29
  const can = useContext(PermissionsContext);
11
- const handleChange = (event) => {
30
+ const handleChange = (event) => __awaiter(void 0, void 0, void 0, function* () {
12
31
  if (event && event.target && event.target.files) {
13
32
  const file = event.target.files[0];
14
33
  setSelectedFile(file);
15
34
  if (dispatch) {
16
- dispatch(actions.UPLOAD_FILE(file));
35
+ dispatch(actions.HANDLE_UPLOAD_ACTION());
36
+ dispatch(actions.SELECT_DESIGNATION(attachmentDesignationName || Designation.Document));
37
+ }
38
+ const result = yield replaceAttachmentHandler(submissionId, attachmentId, fileName, file, attachmentDesignation);
39
+ const { uploadAttachment } = result === null || result === void 0 ? void 0 : result.data;
40
+ if (uploadAttachment && handleUpdateInline) {
41
+ handleUpdateInline(uploadAttachment);
42
+ }
43
+ if (dispatch) {
44
+ dispatch(actions.HANDLE_FINISH_UPLOAD());
17
45
  }
18
- replaceAttachmentHandler(submissionId, attachmentId, fileName, file, attachmentDesignation);
19
46
  hideActionList();
20
47
  }
21
- };
48
+ });
22
49
  const openFileDialog = () => {
23
50
  if (fileInputRef && fileInputRef.current) {
24
51
  fileInputRef.current.click();
@@ -28,7 +55,7 @@ export const ItemActions = ({ downloadAttachmentHandler, replaceAttachmentHandle
28
55
  React.createElement(ActionsItem, { onClick: () => {
29
56
  publicUrl !== undefined ? downloadAttachmentHandler(publicUrl) : {};
30
57
  } }, "Download"),
31
- (can === null || can === void 0 ? void 0 : can.replaceFile) && (React.createElement(React.Fragment, null,
58
+ (can === null || can === void 0 ? void 0 : can.replaceFile) && canBeReplaced && (React.createElement(React.Fragment, null,
32
59
  React.createElement(ActionsItem, { onClick: openFileDialog }, "Replace"),
33
60
  React.createElement("input", { ref: fileInputRef, type: "file", style: { display: 'none' }, onChange: (e) => handleChange(e), value: '' })))));
34
61
  };
@@ -2,11 +2,11 @@ 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 { FileDescription, FileInfoContainer, FileNameTitleContainer, FileTitle, } from './FileSectionItem/FileInfo';
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';
9
- export const InlineFilesSection = ({ submissionId, handleReplace, handleDownload, inlineFiles, isEditor, dispatch, }) => {
9
+ export const InlineFilesSection = ({ submissionId, handleReplace, handleDownload, handleUpdateInline, inlineFiles, isEditor, dispatch, }) => {
10
10
  const onElementClick = useCallback((e) => {
11
11
  if (!isEditor) {
12
12
  return;
@@ -21,16 +21,15 @@ export const InlineFilesSection = ({ submissionId, handleReplace, handleDownload
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, submissionId: submissionId, handleReplace: handleReplace, 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, submissionId: submissionId, handleReplace: handleReplace, handleUpdateInline: handleUpdateInline, handleDownload: handleDownload, dispatch: dispatch })))),
25
25
  React.createElement(Element, { className: 'element' },
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
- const FileReference = ({ attachment, submissionId, handleReplace, handleDownload, dispatch, }) => {
32
+ const FileReference = ({ attachment, submissionId, handleReplace, handleDownload, handleUpdateInline, dispatch, }) => {
34
33
  const { isOpen, toggleOpen, wrapperRef } = useDropdown();
35
34
  if (!attachment || !attachment.name) {
36
35
  return null;
@@ -43,7 +42,9 @@ const FileReference = ({ attachment, submissionId, handleReplace, handleDownload
43
42
  handleDownload && handleReplace && submissionId && (React.createElement(DropdownContainer, { ref: wrapperRef },
44
43
  React.createElement(ActionsIcon, { onClick: toggleOpen, type: "button", className: 'external_file_dropdown', "aria-label": "Download or Replace", "aria-pressed": isOpen },
45
44
  React.createElement(DotsIcon, null)),
46
- isOpen && (React.createElement(ItemActions, { replaceAttachmentHandler: handleReplace, downloadAttachmentHandler: handleDownload, submissionId: submissionId, attachmentId: attachment.id, fileName: attachment.name, designation: attachment.type.label, publicUrl: attachment.link, hideActionList: toggleOpen, dispatch: dispatch, dropDownClassName: 'ref_item_dropdown' }))))));
45
+ isOpen && (React.createElement(ItemActions, { replaceAttachmentHandler: handleReplace, handleUpdateInline: (uploadAttachment) => handleUpdateInline &&
46
+ (attachment === null || attachment === void 0 ? void 0 : attachment.modelId) &&
47
+ handleUpdateInline(attachment.modelId, uploadAttachment), downloadAttachmentHandler: handleDownload, submissionId: submissionId, attachmentId: attachment.id, fileName: attachment.name, designation: attachment.type.label, publicUrl: attachment.link, hideActionList: toggleOpen, dispatch: dispatch, dropDownClassName: 'ref_item_dropdown' }))))));
47
48
  };
48
49
  const ElementItem = styled(Item) `
49
50
  display: flex;
package/dist/es/index.js CHANGED
@@ -44,7 +44,7 @@ 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 } from './lib/inlineFiles';
47
+ export { default as inlineFiles, getSupplementFiles } from './lib/inlineFiles';
48
48
  export { default as PdfPreview } from './components/PdfPreview';
49
49
  export * from './components/SubmissionInspector';
50
50
  export * from './components/Dropdown';
@@ -1,4 +1,4 @@
1
- import { hasObjectType } from '@manuscripts/manuscript-transform';
1
+ import { getModelsByType, 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 getCaptionText = (caption) => caption &&
@@ -15,13 +15,14 @@ const getAttachment = (externalFileRef, attachmentsMap) => {
15
15
  };
16
16
  const getFigureData = (element, modelMap, attachmentsMap) => {
17
17
  const attachments = [];
18
- element.containedObjectIDs.map((e) => {
18
+ element.containedObjectIDs.map((id) => {
19
19
  var _a;
20
- const object = modelMap.get(e);
20
+ const object = modelMap.get(id);
21
21
  if (object && object.objectType === ObjectTypes.Figure) {
22
22
  const externalFileRef = (_a = object.externalFileReferences) === null || _a === void 0 ? void 0 : _a.find((figure) => figure.kind === 'imageRepresentation');
23
23
  const attachment = getAttachment(externalFileRef, attachmentsMap);
24
24
  if (attachment) {
25
+ attachment.modelId = id;
25
26
  attachments.push(attachment);
26
27
  }
27
28
  }
@@ -64,8 +65,8 @@ export default (modelMap, attachments) => {
64
65
  };
65
66
  const getAuxiliaryObjects = (modelMap) => {
66
67
  var _a, _b;
67
- let graphicalAbstractFigureId;
68
- const figureElementIds = [], tableElementIds = [], orderObjects = {};
68
+ let graphicalAbstractFigureId, figureElementIds = [];
69
+ const tableElementIds = [], orderObjects = {};
69
70
  for (const model of modelMap.values()) {
70
71
  switch (model.objectType) {
71
72
  case ObjectTypes.Section: {
@@ -101,6 +102,9 @@ const getAuxiliaryObjects = (modelMap) => {
101
102
  }
102
103
  }
103
104
  }
105
+ if (graphicalAbstractFigureId) {
106
+ figureElementIds = figureElementIds.filter((id) => id != graphicalAbstractFigureId);
107
+ }
104
108
  return {
105
109
  graphicalAbstractFigureId,
106
110
  figureElement: orderObjects[ObjectTypes.FigureElement]
@@ -114,3 +118,7 @@ const getAuxiliaryObjects = (modelMap) => {
114
118
  const sortAuxiliaryObject = (orderObject, auxiliaryObjectIds) => {
115
119
  return auxiliaryObjectIds.sort((a, b) => orderObject.elements.indexOf(a) - orderObject.elements.indexOf(b));
116
120
  };
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
+ };
@@ -15,4 +15,5 @@ export declare const FileManager: React.FC<{
15
15
  handleDownload: (url: string) => void;
16
16
  handleReplace: (submissionId: string, attachmentId: string, name: string, file: File, typeId: string) => Promise<any>;
17
17
  handleChangeDesignation: (submissionId: string, attachmentId: string, typeId: string, name: string) => Promise<any>;
18
+ handleUpdateInline?: (modelId: string, attachment: SubmissionAttachment) => void;
18
19
  }>;
@@ -20,7 +20,11 @@ export interface FileSectionItemProps {
20
20
  showDesignationActions?: boolean;
21
21
  showActions?: boolean;
22
22
  handleDownload?: (url: string) => void;
23
- handleReplace?: (submissionId: string, attachmentId: string, name: string, file: File, typeId: string) => Promise<boolean>;
23
+ handleReplace?: (submissionId: string, attachmentId: string, name: string, file: File, typeId: string) => Promise<{
24
+ data: {
25
+ uploadAttachment: SubmissionAttachment;
26
+ };
27
+ }>;
24
28
  handleChangeDesignation: (submissionId: string, attachmentId: string, typeId: string, name: string) => Promise<boolean>;
25
29
  dispatch?: Dispatch<Action>;
26
30
  dragRef?: DragElementWrapper<DragSourceOptions>;
@@ -1,9 +1,15 @@
1
1
  import React, { Dispatch } from 'react';
2
2
  import { Maybe } from '../../SubmissionInspector/types';
3
3
  import { Action } from '../FileSectionState';
4
+ import { SubmissionAttachment } from './FileSectionItem';
4
5
  export declare const ItemActions: React.FC<{
5
6
  downloadAttachmentHandler: (url: string) => void;
6
- replaceAttachmentHandler: (submissionId: string, attachmentId: string, name: string, file: File, typeId: string) => Promise<boolean>;
7
+ replaceAttachmentHandler: (submissionId: string, attachmentId: string, name: string, file: File, typeId: string) => Promise<{
8
+ data: {
9
+ uploadAttachment: SubmissionAttachment;
10
+ };
11
+ }>;
12
+ handleUpdateInline?: (attachment: SubmissionAttachment) => void;
7
13
  submissionId: string;
8
14
  attachmentId: string;
9
15
  fileName: string;
@@ -16,8 +16,13 @@ export declare const InlineFilesSection: React.FC<{
16
16
  caption?: string;
17
17
  attachments?: SubmissionAttachment[];
18
18
  }[];
19
- handleReplace: (submissionId: string, attachmentId: string, name: string, file: File, typeId: string) => Promise<boolean>;
19
+ handleReplace: (submissionId: string, attachmentId: string, name: string, file: File, typeId: string) => Promise<{
20
+ data: {
21
+ uploadAttachment: SubmissionAttachment;
22
+ };
23
+ }>;
20
24
  handleDownload: (url: string) => void;
25
+ handleUpdateInline?: (modelId: string, attachment: SubmissionAttachment) => void;
21
26
  isEditor: boolean;
22
27
  dispatch: Dispatch<Action>;
23
28
  }>;
@@ -45,7 +45,7 @@ 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 } from './lib/inlineFiles';
48
+ export { default as inlineFiles, getSupplementFiles } from './lib/inlineFiles';
49
49
  export { default as PdfPreview } from './components/PdfPreview';
50
50
  export * from './components/SubmissionInspector';
51
51
  export * from './components/Dropdown';
@@ -9,3 +9,4 @@ declare const _default: (modelMap: Map<string, Model>, attachments: SubmissionAt
9
9
  attachments?: SubmissionAttachment[] | undefined;
10
10
  }[];
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.9",
4
+ "version": "0.31.12",
5
5
  "repository": "gitlab:atypon-opensource/manuscripts-style-guide",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",