@manuscripts/style-guide 0.31.27 → 0.31.28-LEAN-1156

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.
@@ -98,6 +98,14 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
98
98
  }), [modelMap, saveModel]);
99
99
  const attachments = getAttachments();
100
100
  const { otherFiles, supplementFiles, inlineFiles } = (0, index_1.useFiles)(modelMap, attachments);
101
+ const handleDetachFile = (attachmentId, modelId) => {
102
+ var _a;
103
+ const model = modelMap.get(modelId);
104
+ if (model) {
105
+ const externalFileReferences = (_a = model.externalFileReferences) === null || _a === void 0 ? void 0 : _a.filter((ref) => ref.url.replace('attachment:', '') !== attachmentId);
106
+ saveModel(Object.assign(Object.assign({}, model), { externalFileReferences: externalFileReferences || [] }));
107
+ }
108
+ };
101
109
  const getFileSectionExternalFile = (fileSection) => {
102
110
  const isSupplementOrOtherFilesTab = fileSection === util_1.FileSectionType.Supplements ||
103
111
  fileSection === util_1.FileSectionType.OtherFile;
@@ -149,7 +157,7 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
149
157
  react_1.default.createElement("div", null, "Files excluded from the final submission.")))),
150
158
  react_1.default.createElement(Inspector_1.InspectorTabPanels, { style: { overflowY: 'visible', position: 'relative' } },
151
159
  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 })),
160
+ react_1.default.createElement(InlineFilesSection_1.InlineFilesSection, { inlineFiles: inlineFiles, handleReplace: replace, handleDownload: handleDownload, handleUpdateInline: handleUpdateInline, handleDetachFile: handleDetachFile, isEditor: enableDragAndDrop, dispatch: dispatch })),
153
161
  react_1.default.createElement(Inspector_1.InspectorTabPanel, null,
154
162
  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
163
  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,10 +73,11 @@ 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: 96, top: 5, onClick: hideActionList },
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
+ (can === null || can === void 0 ? void 0 : can.editArticle) && detachAttachmnetHandler && (react_1.default.createElement(ItemsAction_1.ActionsItem, { onClick: () => detachAttachmnetHandler() }, "Detach")),
80
81
  (can === null || can === void 0 ? void 0 : can.replaceFile) && canBeReplaced && (react_1.default.createElement(react_1.default.Fragment, null,
81
82
  react_1.default.createElement(ItemsAction_1.ActionsItem, { onClick: openFileDialog }, "Replace"),
82
83
  react_1.default.createElement("input", { ref: fileInputRef, type: "file", style: { display: 'none' }, onChange: (e) => handleChange(e), value: '' })))));
@@ -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), downloadAttachmentHandler: handleDownload, attachmentId: attachment.id, fileName: attachment.name, designation: attachment.type.label, publicUrl: attachment.link, hideActionList: toggleOpen, dispatch: dispatch, dropDownClassName: 'ref_item_dropdown' }))))));
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;
@@ -143,6 +143,8 @@ exports.NoteBodyContainer = styled_components_1.default.div `
143
143
  ${(props) => borderStyle(props.theme.colors.border.secondary)};
144
144
  ${(props) => (props.isNew || props.isSelected) &&
145
145
  borderStyle(props.theme.colors.border.primary)}
146
+ ${(props) => props.isSelected &&
147
+ `background: ${props.theme.colors.background.selected};`}
146
148
 
147
149
  .tooltip {
148
150
  border-radius: 6px;
@@ -73,6 +73,14 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
73
73
  }), [modelMap, saveModel]);
74
74
  const attachments = getAttachments();
75
75
  const { otherFiles, supplementFiles, inlineFiles } = useFiles(modelMap, attachments);
76
+ const handleDetachFile = (attachmentId, modelId) => {
77
+ var _a;
78
+ const model = modelMap.get(modelId);
79
+ if (model) {
80
+ const externalFileReferences = (_a = model.externalFileReferences) === null || _a === void 0 ? void 0 : _a.filter((ref) => ref.url.replace('attachment:', '') !== attachmentId);
81
+ saveModel(Object.assign(Object.assign({}, model), { externalFileReferences: externalFileReferences || [] }));
82
+ }
83
+ };
76
84
  const getFileSectionExternalFile = (fileSection) => {
77
85
  const isSupplementOrOtherFilesTab = fileSection === FileSectionType.Supplements ||
78
86
  fileSection === FileSectionType.OtherFile;
@@ -124,7 +132,7 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
124
132
  React.createElement("div", null, "Files excluded from the final submission.")))),
125
133
  React.createElement(InspectorTabPanels, { style: { overflowY: 'visible', position: 'relative' } },
126
134
  React.createElement(InspectorTabPanel, null,
127
- React.createElement(InlineFilesSection, { inlineFiles: inlineFiles, handleReplace: replace, handleDownload: handleDownload, handleUpdateInline: handleUpdateInline, isEditor: enableDragAndDrop, dispatch: dispatch })),
135
+ React.createElement(InlineFilesSection, { inlineFiles: inlineFiles, handleReplace: replace, handleDownload: handleDownload, handleUpdateInline: handleUpdateInline, handleDetachFile: handleDetachFile, isEditor: enableDragAndDrop, dispatch: dispatch })),
128
136
  React.createElement(InspectorTabPanel, null,
129
137
  React.createElement(FilesSection, { enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFileWithSupplement, fileSection: FileSectionType.Supplements, filesItem: getFileSectionExternalFile(FileSectionType.Supplements), state: state, dispatch: dispatch })),
130
138
  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,10 +51,11 @@ 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: 96, top: 5, onClick: hideActionList },
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
+ (can === null || can === void 0 ? void 0 : can.editArticle) && detachAttachmnetHandler && (React.createElement(ActionsItem, { onClick: () => detachAttachmnetHandler() }, "Detach")),
58
59
  (can === null || can === void 0 ? void 0 : can.replaceFile) && canBeReplaced && (React.createElement(React.Fragment, null,
59
60
  React.createElement(ActionsItem, { onClick: openFileDialog }, "Replace"),
60
61
  React.createElement("input", { ref: fileInputRef, type: "file", style: { display: 'none' }, onChange: (e) => handleChange(e), value: '' })))));
@@ -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), downloadAttachmentHandler: handleDownload, attachmentId: attachment.id, fileName: attachment.name, designation: attachment.type.label, publicUrl: attachment.link, hideActionList: toggleOpen, dispatch: dispatch, dropDownClassName: 'ref_item_dropdown' }))))));
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;
@@ -118,6 +118,8 @@ export const NoteBodyContainer = styled.div `
118
118
  ${(props) => borderStyle(props.theme.colors.border.secondary)};
119
119
  ${(props) => (props.isNew || props.isSelected) &&
120
120
  borderStyle(props.theme.colors.border.primary)}
121
+ ${(props) => props.isSelected &&
122
+ `background: ${props.theme.colors.background.selected};`}
121
123
 
122
124
  .tooltip {
123
125
  border-radius: 6px;
@@ -1,5 +1,5 @@
1
1
  import { Build } from '@manuscripts/manuscript-transform';
2
- import { Model, Supplement } from '@manuscripts/manuscripts-json-schema';
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,7 @@ 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<Supplement>) => Promise<Build<Supplement>>;
19
+ saveModel: <T extends Model>(model: T | Build<T> | Partial<T>) => Promise<T>;
20
20
  enableDragAndDrop: boolean;
21
21
  can: Capabilities;
22
22
  }>;
@@ -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
  }>;
@@ -75,6 +75,7 @@ interface Variations {
75
75
  }
76
76
  interface Background {
77
77
  dark: string;
78
+ selected: string;
78
79
  }
79
80
  interface Border {
80
81
  field: States;
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.27",
4
+ "version": "0.31.28-LEAN-1156",
5
5
  "repository": "gitlab:atypon-opensource/manuscripts-style-guide",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",