@manuscripts/style-guide 1.1.3 → 1.1.4

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.
@@ -36,6 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  exports.FileManager = exports.PermissionsContext = void 0;
39
+ const json_schema_1 = require("@manuscripts/json-schema");
39
40
  const transform_1 = require("@manuscripts/transform");
40
41
  const react_1 = __importStar(require("react"));
41
42
  const react_tooltip_1 = __importDefault(require("react-tooltip"));
@@ -87,6 +88,10 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
87
88
  }
88
89
  return response;
89
90
  }), [upload, saveModel]);
91
+ const handleSupplementReplace = (0, react_1.useCallback)((attachment, oldAttachmentId) => __awaiter(void 0, void 0, void 0, function* () {
92
+ const model = (0, transform_1.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Supplement).find(({ href }) => (href === null || href === void 0 ? void 0 : href.replace('attachment:', '')) === oldAttachmentId);
93
+ yield saveModel(Object.assign(Object.assign({}, model), { title: attachment.name, href: `attachment:${attachment.id}` }));
94
+ }), [modelMap, saveModel]);
90
95
  const handleChangeDesignationFile = (0, react_1.useCallback)((attachmentId, typeId, name) => __awaiter(void 0, void 0, void 0, function* () {
91
96
  const res = yield changeDesignation(attachmentId, typeId, name);
92
97
  if (res) {
@@ -122,6 +127,7 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
122
127
  const itemsDataWithTitle = (0, util_1.generateAttachmentsTitles)(itemsData, fileSection);
123
128
  const filesItems = itemsDataWithTitle.map((element) => {
124
129
  const itemProps = {
130
+ fileSection,
125
131
  externalFile: element.externalFile,
126
132
  title: element.title,
127
133
  showAttachmentName: isSupplementOrOtherFilesTab,
@@ -129,6 +135,7 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
129
135
  showReplaceAction: !isOtherFilesTab,
130
136
  handleDownload,
131
137
  handleReplace: handleReplaceFile,
138
+ handleSupplementReplace,
132
139
  handleChangeDesignation: handleChangeDesignationFile,
133
140
  dispatch: dispatch,
134
141
  };
@@ -14,7 +14,7 @@ const util_1 = require("../util");
14
14
  const FileInfo_1 = require("./FileInfo");
15
15
  const FileTypeIcon_1 = require("./FileTypeIcon");
16
16
  const ItemActions_1 = require("./ItemActions");
17
- const FileSectionItem = ({ externalFile, title, showAttachmentName = false, showDesignationActions = false, showReplaceAction = true, handleDownload, handleReplace, handleChangeDesignation, dispatch, dragRef, className, style, onClose, isEditor, }) => {
17
+ const FileSectionItem = ({ fileSection, externalFile, title, showAttachmentName = false, showDesignationActions = false, showReplaceAction = true, handleDownload, handleReplace, handleChangeDesignation, handleSupplementReplace, dispatch, dragRef, className, style, onClose, isEditor, }) => {
18
18
  const { isOpen, toggleOpen, wrapperRef } = (0, use_dropdown_1.useDropdown)();
19
19
  const fileExtension = externalFile.name.substring(externalFile.name.lastIndexOf('.') + 1);
20
20
  const designation = util_1.namesWithDesignationMap.get(externalFile.type.label);
@@ -38,7 +38,7 @@ const FileSectionItem = ({ externalFile, title, showAttachmentName = false, show
38
38
  handleDownload && handleReplace && (react_1.default.createElement(Dropdown_1.DropdownContainer, { ref: wrapperRef },
39
39
  react_1.default.createElement(exports.ActionsIcon, { onClick: toggleOpen, type: "button", "aria-label": "Download or Replace", "aria-pressed": isOpen },
40
40
  react_1.default.createElement(dots_icon_1.default, null)),
41
- isOpen && (react_1.default.createElement(ItemActions_1.ItemActions, { replaceAttachmentHandler: handleReplace, showReplaceAction: showReplaceAction, downloadAttachmentHandler: handleDownload, attachmentId: externalFile.id, fileName: externalFile.name, designation: externalFile.type.label, publicUrl: externalFile.link, hideActionList: toggleOpen, dispatch: dispatch }))))));
41
+ isOpen && (react_1.default.createElement(ItemActions_1.ItemActions, { fileSection: fileSection, replaceAttachmentHandler: handleReplace, showReplaceAction: showReplaceAction, downloadAttachmentHandler: handleDownload, handleSupplementReplace: handleSupplementReplace, attachmentId: externalFile.id, fileName: externalFile.name, designation: externalFile.type.label, publicUrl: externalFile.link, hideActionList: toggleOpen, dispatch: dispatch }))))));
42
42
  };
43
43
  exports.FileSectionItem = FileSectionItem;
44
44
  const IconCloseButton = styled_components_1.default.button `
@@ -39,7 +39,7 @@ const FileManager_1 = require("../FileManager");
39
39
  const FileSectionState_1 = require("../FileSectionState");
40
40
  const ItemsAction_1 = require("../ItemsAction");
41
41
  const util_1 = require("../util");
42
- const ItemActions = ({ downloadAttachmentHandler, replaceAttachmentHandler, detachAttachmnetHandler, handleUpdateInline, attachmentId, fileName, designation, publicUrl, hideActionList, dispatch, dropDownClassName, showReplaceAction, }) => {
42
+ const ItemActions = ({ fileSection, downloadAttachmentHandler, replaceAttachmentHandler, handleSupplementReplace, detachAttachmnetHandler, handleUpdateInline, attachmentId, fileName, designation, publicUrl, hideActionList, dispatch, dropDownClassName, showReplaceAction, }) => {
43
43
  const attachmentDesignation = designation == undefined ? 'undefined' : designation;
44
44
  const attachmentDesignationName = attachmentDesignation !== 'undefined'
45
45
  ? util_1.namesWithDesignationMap.get(attachmentDesignation)
@@ -65,6 +65,11 @@ const ItemActions = ({ downloadAttachmentHandler, replaceAttachmentHandler, deta
65
65
  dispatch(FileSectionState_1.actions.SELECT_DESIGNATION(attachmentDesignationName || util_1.Designation.Document));
66
66
  }
67
67
  const result = yield replaceAttachmentHandler(attachmentId, fileName, file, attachmentDesignation);
68
+ if (fileSection === util_1.FileSectionType.Supplements &&
69
+ typeof result === 'object' &&
70
+ handleSupplementReplace) {
71
+ handleSupplementReplace(result, attachmentId);
72
+ }
68
73
  if (typeof result === 'object' && handleUpdateInline) {
69
74
  handleUpdateInline(result);
70
75
  }
@@ -74,7 +74,7 @@ const FileReference = ({ attachment, handleReplace, handleDownload, handleUpdate
74
74
  handleDownload && handleReplace && (react_1.default.createElement(DropdownContainer, { ref: wrapperRef },
75
75
  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 },
76
76
  react_1.default.createElement(dots_icon_1.default, null)),
77
- isOpen && (react_1.default.createElement(ItemActions_1.ItemActions, { replaceAttachmentHandler: handleReplace, showReplaceAction: true, handleUpdateInline: (uploadAttachment) => handleUpdateInline &&
77
+ isOpen && (react_1.default.createElement(ItemActions_1.ItemActions, { fileSection: util_1.FileSectionType.Inline, replaceAttachmentHandler: handleReplace, showReplaceAction: true, handleUpdateInline: (uploadAttachment) => handleUpdateInline &&
78
78
  (attachment === null || attachment === void 0 ? void 0 : attachment.modelId) &&
79
79
  handleUpdateInline(attachment.modelId, uploadAttachment), detachAttachmnetHandler: () => handleDetachFile &&
80
80
  attachment.modelId &&
@@ -7,7 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { buildSupplementaryMaterial } from '@manuscripts/transform';
10
+ import { ObjectTypes, } from '@manuscripts/json-schema';
11
+ import { buildSupplementaryMaterial, getModelsByType, } from '@manuscripts/transform';
11
12
  import React, { createContext, useCallback, useReducer } from 'react';
12
13
  import ReactTooltip from 'react-tooltip';
13
14
  import { FileSectionType, useFiles } from '../../index';
@@ -58,6 +59,10 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
58
59
  }
59
60
  return response;
60
61
  }), [upload, saveModel]);
62
+ const handleSupplementReplace = useCallback((attachment, oldAttachmentId) => __awaiter(void 0, void 0, void 0, function* () {
63
+ const model = getModelsByType(modelMap, ObjectTypes.Supplement).find(({ href }) => (href === null || href === void 0 ? void 0 : href.replace('attachment:', '')) === oldAttachmentId);
64
+ yield saveModel(Object.assign(Object.assign({}, model), { title: attachment.name, href: `attachment:${attachment.id}` }));
65
+ }), [modelMap, saveModel]);
61
66
  const handleChangeDesignationFile = useCallback((attachmentId, typeId, name) => __awaiter(void 0, void 0, void 0, function* () {
62
67
  const res = yield changeDesignation(attachmentId, typeId, name);
63
68
  if (res) {
@@ -93,6 +98,7 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
93
98
  const itemsDataWithTitle = generateAttachmentsTitles(itemsData, fileSection);
94
99
  const filesItems = itemsDataWithTitle.map((element) => {
95
100
  const itemProps = {
101
+ fileSection,
96
102
  externalFile: element.externalFile,
97
103
  title: element.title,
98
104
  showAttachmentName: isSupplementOrOtherFilesTab,
@@ -100,6 +106,7 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
100
106
  showReplaceAction: !isOtherFilesTab,
101
107
  handleDownload,
102
108
  handleReplace: handleReplaceFile,
109
+ handleSupplementReplace,
103
110
  handleChangeDesignation: handleChangeDesignationFile,
104
111
  dispatch: dispatch,
105
112
  };
@@ -8,7 +8,7 @@ import { Designation, namesWithDesignationMap } from '../util';
8
8
  import { FileInfo } from './FileInfo';
9
9
  import { FileTypeIcon } from './FileTypeIcon';
10
10
  import { ItemActions } from './ItemActions';
11
- export const FileSectionItem = ({ externalFile, title, showAttachmentName = false, showDesignationActions = false, showReplaceAction = true, handleDownload, handleReplace, handleChangeDesignation, dispatch, dragRef, className, style, onClose, isEditor, }) => {
11
+ export const FileSectionItem = ({ fileSection, externalFile, title, showAttachmentName = false, showDesignationActions = false, showReplaceAction = true, handleDownload, handleReplace, handleChangeDesignation, handleSupplementReplace, dispatch, dragRef, className, style, onClose, isEditor, }) => {
12
12
  const { isOpen, toggleOpen, wrapperRef } = useDropdown();
13
13
  const fileExtension = externalFile.name.substring(externalFile.name.lastIndexOf('.') + 1);
14
14
  const designation = namesWithDesignationMap.get(externalFile.type.label);
@@ -32,7 +32,7 @@ export const FileSectionItem = ({ externalFile, title, showAttachmentName = fals
32
32
  handleDownload && handleReplace && (React.createElement(DropdownContainer, { ref: wrapperRef },
33
33
  React.createElement(ActionsIcon, { onClick: toggleOpen, type: "button", "aria-label": "Download or Replace", "aria-pressed": isOpen },
34
34
  React.createElement(DotsIcon, null)),
35
- isOpen && (React.createElement(ItemActions, { replaceAttachmentHandler: handleReplace, showReplaceAction: showReplaceAction, downloadAttachmentHandler: handleDownload, attachmentId: externalFile.id, fileName: externalFile.name, designation: externalFile.type.label, publicUrl: externalFile.link, hideActionList: toggleOpen, dispatch: dispatch }))))));
35
+ isOpen && (React.createElement(ItemActions, { fileSection: fileSection, replaceAttachmentHandler: handleReplace, showReplaceAction: showReplaceAction, downloadAttachmentHandler: handleDownload, handleSupplementReplace: handleSupplementReplace, attachmentId: externalFile.id, fileName: externalFile.name, designation: externalFile.type.label, publicUrl: externalFile.link, hideActionList: toggleOpen, dispatch: dispatch }))))));
36
36
  };
37
37
  const IconCloseButton = styled.button `
38
38
  border: none;
@@ -12,8 +12,8 @@ import { DropdownList } from '../../Dropdown';
12
12
  import { PermissionsContext } from '../FileManager';
13
13
  import { actions } from '../FileSectionState';
14
14
  import { ActionsItem } from '../ItemsAction';
15
- import { Designation, namesWithDesignationMap } from '../util';
16
- export const ItemActions = ({ downloadAttachmentHandler, replaceAttachmentHandler, detachAttachmnetHandler, handleUpdateInline, attachmentId, fileName, designation, publicUrl, hideActionList, dispatch, dropDownClassName, showReplaceAction, }) => {
15
+ import { Designation, FileSectionType, namesWithDesignationMap } from '../util';
16
+ export const ItemActions = ({ fileSection, downloadAttachmentHandler, replaceAttachmentHandler, handleSupplementReplace, 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)
@@ -39,6 +39,11 @@ export const ItemActions = ({ downloadAttachmentHandler, replaceAttachmentHandle
39
39
  dispatch(actions.SELECT_DESIGNATION(attachmentDesignationName || Designation.Document));
40
40
  }
41
41
  const result = yield replaceAttachmentHandler(attachmentId, fileName, file, attachmentDesignation);
42
+ if (fileSection === FileSectionType.Supplements &&
43
+ typeof result === 'object' &&
44
+ handleSupplementReplace) {
45
+ handleSupplementReplace(result, attachmentId);
46
+ }
42
47
  if (typeof result === 'object' && handleUpdateInline) {
43
48
  handleUpdateInline(result);
44
49
  }
@@ -5,7 +5,7 @@ import DotsIcon from '../icons/dots-icon';
5
5
  import { FileInfoContainer, FileNameTitleContainer, FileTitle, } from './FileSectionItem/FileInfo';
6
6
  import { ActionsIcon, Item, } from './FileSectionItem/FileSectionItem';
7
7
  import { ItemActions } from './FileSectionItem/ItemActions';
8
- import { extensionsWithFileTypesMap, fileTypesWithIconMap, } from './util';
8
+ import { extensionsWithFileTypesMap, FileSectionType, fileTypesWithIconMap, } from './util';
9
9
  const trackedJoint = ':dataTracked:';
10
10
  export const InlineFilesSection = ({ handleReplace, handleDownload, handleUpdateInline, handleDetachFile, inlineFiles, isEditor, dispatch, }) => {
11
11
  const onElementClick = useCallback((e) => {
@@ -44,7 +44,7 @@ const FileReference = ({ attachment, handleReplace, handleDownload, handleUpdate
44
44
  handleDownload && handleReplace && (React.createElement(DropdownContainer, { ref: wrapperRef },
45
45
  React.createElement(ActionsIcon, { onClick: toggleOpen, type: "button", className: 'external_file_dropdown', "aria-label": "Download or Replace or Detach", "aria-pressed": isOpen },
46
46
  React.createElement(DotsIcon, null)),
47
- isOpen && (React.createElement(ItemActions, { replaceAttachmentHandler: handleReplace, showReplaceAction: true, handleUpdateInline: (uploadAttachment) => handleUpdateInline &&
47
+ isOpen && (React.createElement(ItemActions, { fileSection: FileSectionType.Inline, replaceAttachmentHandler: handleReplace, showReplaceAction: true, handleUpdateInline: (uploadAttachment) => handleUpdateInline &&
48
48
  (attachment === null || attachment === void 0 ? void 0 : attachment.modelId) &&
49
49
  handleUpdateInline(attachment.modelId, uploadAttachment), detachAttachmnetHandler: () => handleDetachFile &&
50
50
  attachment.modelId &&
@@ -3,6 +3,7 @@ import { DragElementWrapper, DragSourceOptions } from 'react-dnd';
3
3
  import { Maybe } from '../../SubmissionInspector/types';
4
4
  import { ChangeDesignation, Replace } from '../FileManager';
5
5
  import { Action } from '../FileSectionState';
6
+ import { FileSectionType } from '../util';
6
7
  export type FileAttachment = {
7
8
  id: string;
8
9
  name: string;
@@ -15,6 +16,7 @@ export type FileAttachmentType = {
15
16
  };
16
17
  export interface FileSectionItemProps {
17
18
  externalFile: FileAttachment;
19
+ fileSection: FileSectionType;
18
20
  title: string;
19
21
  showAttachmentName?: boolean;
20
22
  showDesignationActions?: boolean;
@@ -22,6 +24,7 @@ export interface FileSectionItemProps {
22
24
  showReplaceAction?: boolean;
23
25
  handleDownload?: (url: string) => void;
24
26
  handleReplace?: Replace;
27
+ handleSupplementReplace?: (attachment: FileAttachment, oldAttachmentId: string) => void;
25
28
  handleChangeDesignation: ChangeDesignation;
26
29
  dispatch?: Dispatch<Action>;
27
30
  dragRef?: DragElementWrapper<DragSourceOptions>;
@@ -2,12 +2,15 @@ import React, { Dispatch } from 'react';
2
2
  import { Maybe } from '../../SubmissionInspector/types';
3
3
  import { Replace } from '../FileManager';
4
4
  import { Action } from '../FileSectionState';
5
+ import { FileSectionType } from '../util';
5
6
  import { FileAttachment } from './FileSectionItem';
6
7
  export declare const ItemActions: React.FC<{
8
+ fileSection: FileSectionType;
7
9
  downloadAttachmentHandler: (url: string) => void;
8
10
  replaceAttachmentHandler: Replace;
9
11
  detachAttachmnetHandler?: () => void;
10
12
  handleUpdateInline?: (attachment: FileAttachment) => void;
13
+ handleSupplementReplace?: (attachment: FileAttachment, oldAttachmentId: string) => void;
11
14
  attachmentId: string;
12
15
  fileName: string;
13
16
  designation?: Maybe<string> | undefined;
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": "1.1.3",
4
+ "version": "1.1.4",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-style-guide",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",