@manuscripts/style-guide 1.1.8 → 1.1.9

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.
@@ -14,7 +14,7 @@ exports.DropdownList = styled_components_1.default.div `
14
14
  box-shadow: 0 4px 9px rgba(0, 0, 0, 0.3);
15
15
  background: ${(props) => props.theme.colors.background.primary};
16
16
  width: ${(props) => (props.width ? props.width + 'px' : 'auto')};
17
- ${(props) => props.height && `height: ${props.height}px`};
17
+ ${(props) => props.height && `max-height: ${props.height}px`};
18
18
  ${(props) => (props.direction === 'right' ? ' right: 0' : 'left : 0')};
19
19
  top: ${(props) => props.theme.grid.unit * (props.top || 3)}px;
20
20
  position: absolute;
@@ -1,11 +1,45 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
4
33
  };
5
34
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ConfirmationPopUp = void 0;
7
- const react_1 = __importDefault(require("react"));
35
+ exports.MoveFilePopup = exports.ConfirmationPopUp = void 0;
36
+ const json_schema_1 = require("@manuscripts/json-schema");
37
+ const transform_1 = require("@manuscripts/transform");
38
+ const react_1 = __importStar(require("react"));
8
39
  const Dialog_1 = require("../Dialog");
40
+ const FileManagerProvider_1 = require("./FileManagerProvider");
41
+ const FileSectionState_1 = require("./FileSectionState");
42
+ const util_1 = require("./util");
9
43
  const ConfirmationPopUp = ({ popupHeader, popUpMessage, isOpen, handleClose, handleMove }) => {
10
44
  return (react_1.default.createElement(Dialog_1.Dialog, { isOpen: isOpen, category: Dialog_1.Category.confirmation, header: popupHeader, message: popUpMessage, actions: {
11
45
  primary: {
@@ -19,3 +53,38 @@ const ConfirmationPopUp = ({ popupHeader, popUpMessage, isOpen, handleClose, han
19
53
  } }));
20
54
  };
21
55
  exports.ConfirmationPopUp = ConfirmationPopUp;
56
+ const MoveFilePopup = ({ dispatch, }) => {
57
+ const { moveFilePopup: { isOpen, fileSection, attachmentId }, saveModel, deleteModel, modelMap, getAttachments, setMoveFilePopupData, } = (0, react_1.useContext)(FileManagerProvider_1.FileManagerContext);
58
+ const isSupplement = fileSection === util_1.FileSectionType.Supplements;
59
+ const message = {
60
+ popupHeader: `Are you sure you want to move this file to “${(!isSupplement && 'Supplements') || 'Other files'}”?`,
61
+ popUpMessage: `The file will be removed from the “${(isSupplement && 'Supplements') || 'Other files'}” and added to “${(!isSupplement && 'Supplements') || 'Other files'}”.`,
62
+ };
63
+ const closePopup = (0, react_1.useCallback)(() => setMoveFilePopupData({
64
+ isOpen: false,
65
+ fileSection: fileSection,
66
+ }), [fileSection, setMoveFilePopupData]);
67
+ const showSuccessMessage = (0, react_1.useCallback)(() => dispatch(FileSectionState_1.actions.HANDLE_SUCCESS_MESSAGE(`File moved to ${(isSupplement && 'Other files') || 'Supplements'}.`, fileSection)), [dispatch, fileSection, isSupplement]);
68
+ const moveToSupplement = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
69
+ closePopup();
70
+ const attachment = getAttachments().find(({ id }) => id === attachmentId);
71
+ if (!attachment) {
72
+ return;
73
+ }
74
+ const model = (0, transform_1.buildSupplementaryMaterial)(attachment.name, `attachment:${attachment.id}`);
75
+ yield saveModel(Object.assign(Object.assign({}, model), { title: attachment.name, href: `attachment:${attachment.id}` }));
76
+ showSuccessMessage();
77
+ }), [getAttachments, saveModel, showSuccessMessage, closePopup, attachmentId]);
78
+ const moveSupplementToOtherFiles = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
79
+ closePopup();
80
+ const model = (0, transform_1.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Supplement).find(({ href }) => (href === null || href === void 0 ? void 0 : href.replace('attachment:', '')) === attachmentId);
81
+ if (!model) {
82
+ return;
83
+ }
84
+ yield deleteModel(model._id);
85
+ showSuccessMessage();
86
+ }), [attachmentId, closePopup, deleteModel, modelMap, showSuccessMessage]);
87
+ return (react_1.default.createElement(react_1.default.Fragment, null,
88
+ react_1.default.createElement(exports.ConfirmationPopUp, Object.assign({ isOpen: isOpen }, message, { handleMove: () => (!isSupplement && moveToSupplement()) || moveSupplementToOtherFiles(), handleClose: closePopup }))));
89
+ };
90
+ exports.MoveFilePopup = MoveFilePopup;
@@ -43,6 +43,8 @@ const react_tooltip_1 = __importDefault(require("react-tooltip"));
43
43
  const index_1 = require("../../index");
44
44
  const Inspector_1 = require("../Inspector");
45
45
  const InspectorSection_1 = require("../InspectorSection");
46
+ const ConfirmationPopUp_1 = require("./ConfirmationPopUp");
47
+ const FileManagerProvider_1 = require("./FileManagerProvider");
46
48
  const DraggableFileSectionItem_1 = require("./FileSectionItem/DraggableFileSectionItem");
47
49
  const DragLayer_1 = require("./FileSectionItem/DragLayer");
48
50
  const FileSectionItem_1 = require("./FileSectionItem/FileSectionItem");
@@ -52,7 +54,7 @@ const InlineFilesSection_1 = require("./InlineFilesSection");
52
54
  const TooltipDiv_1 = require("./TooltipDiv");
53
55
  const util_1 = require("./util");
54
56
  exports.PermissionsContext = (0, react_1.createContext)(null);
55
- const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManagement: { getAttachments, replace, upload }, addAttachmentToState, }) => {
57
+ const FileManager = ({ modelMap, saveModel, deleteModel, enableDragAndDrop, can, fileManagement: { getAttachments, replace, upload }, addAttachmentToState, }) => {
56
58
  const [state, dispatch] = (0, react_1.useReducer)(FileSectionState_1.reducer, (0, FileSectionState_1.getInitialState)());
57
59
  const handleReplaceFile = (0, react_1.useCallback)((attachmentId, name, file) => __awaiter(void 0, void 0, void 0, function* () {
58
60
  dispatch(FileSectionState_1.actions.HANDLE_UPLOAD_ACTION());
@@ -136,7 +138,7 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
136
138
  });
137
139
  return filesItems;
138
140
  };
139
- return (react_1.default.createElement(react_1.default.Fragment, null,
141
+ return (react_1.default.createElement(FileManagerProvider_1.FileManagerProvider, { saveModel: saveModel, modelMap: modelMap, deleteModel: deleteModel, getAttachments: getAttachments },
140
142
  react_1.default.createElement(DragLayer_1.DragLayer, null),
141
143
  react_1.default.createElement(exports.PermissionsContext.Provider, { value: can },
142
144
  react_1.default.createElement(InspectorSection_1.InspectorSection, { title: 'Files', contentStyles: { margin: '24px' } },
@@ -163,6 +165,7 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
163
165
  react_1.default.createElement(Inspector_1.InspectorTabPanel, null,
164
166
  react_1.default.createElement(FilesSection_1.FilesSection, { enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFileWithSupplement, fileSection: index_1.FileSectionType.Supplements, filesItem: getFileSectionExternalFile(index_1.FileSectionType.Supplements), state: state, dispatch: dispatch })),
165
167
  react_1.default.createElement(Inspector_1.InspectorTabPanel, null,
166
- react_1.default.createElement(FilesSection_1.FilesSection, { enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFile, fileSection: index_1.FileSectionType.OtherFile, filesItem: getFileSectionExternalFile(index_1.FileSectionType.OtherFile), state: state, dispatch: dispatch }))))))));
168
+ react_1.default.createElement(FilesSection_1.FilesSection, { enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFile, fileSection: index_1.FileSectionType.OtherFile, filesItem: getFileSectionExternalFile(index_1.FileSectionType.OtherFile), state: state, dispatch: dispatch }))))),
169
+ react_1.default.createElement(ConfirmationPopUp_1.MoveFilePopup, { dispatch: dispatch }))));
167
170
  };
168
171
  exports.FileManager = FileManager;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.FileManagerProvider = exports.FileManagerContext = void 0;
27
+ const react_1 = __importStar(require("react"));
28
+ exports.FileManagerContext = (0, react_1.createContext)({
29
+ saveModel: () => '',
30
+ moveFilePopup: { isOpen: false },
31
+ setMoveFilePopupData: () => '',
32
+ });
33
+ const FileManagerProvider = ({ children, saveModel, deleteModel, modelMap, getAttachments }) => {
34
+ const [moveFilePopup, setMoveFilePopupData] = (0, react_1.useState)({ isOpen: false });
35
+ return (react_1.default.createElement(exports.FileManagerContext.Provider, { value: {
36
+ saveModel,
37
+ deleteModel,
38
+ modelMap,
39
+ getAttachments,
40
+ moveFilePopup,
41
+ setMoveFilePopupData,
42
+ } }, children));
43
+ };
44
+ exports.FileManagerProvider = FileManagerProvider;
@@ -36,7 +36,7 @@ const FileSectionItem = ({ fileSection, externalFile, title, showAttachmentName
36
36
  handleDownload && handleReplace && (react_1.default.createElement(Dropdown_1.DropdownContainer, { ref: wrapperRef },
37
37
  react_1.default.createElement(exports.ActionsIcon, { onClick: toggleOpen, type: "button", "aria-label": "Download or Replace", "aria-pressed": isOpen },
38
38
  react_1.default.createElement(dots_icon_1.default, null)),
39
- isOpen && (react_1.default.createElement(ItemActions_1.ItemActions, { fileSection: fileSection, replaceAttachmentHandler: handleReplace, showReplaceAction: showReplaceAction, downloadAttachmentHandler: handleDownload, handleSupplementReplace: handleSupplementReplace, attachmentId: externalFile.id, fileName: externalFile.name, publicUrl: externalFile.link, hideActionList: toggleOpen, dispatch: dispatch }))))));
39
+ isOpen && (react_1.default.createElement(ItemActions_1.ItemActions, { fileSection: fileSection, isMainManuscript: isMainManuscript, replaceAttachmentHandler: handleReplace, showReplaceAction: showReplaceAction, downloadAttachmentHandler: handleDownload, handleSupplementReplace: handleSupplementReplace, attachmentId: externalFile.id, fileName: externalFile.name, publicUrl: externalFile.link, hideActionList: toggleOpen, dispatch: dispatch }))))));
40
40
  };
41
41
  exports.FileSectionItem = FileSectionItem;
42
42
  const IconCloseButton = styled_components_1.default.button `
@@ -36,11 +36,13 @@ exports.ItemActions = void 0;
36
36
  const react_1 = __importStar(require("react"));
37
37
  const Dropdown_1 = require("../../Dropdown");
38
38
  const FileManager_1 = require("../FileManager");
39
+ const FileManagerProvider_1 = require("../FileManagerProvider");
39
40
  const FileSectionState_1 = require("../FileSectionState");
40
41
  const ItemsAction_1 = require("../ItemsAction");
41
42
  const util_1 = require("../util");
42
- const ItemActions = ({ fileSection, downloadAttachmentHandler, replaceAttachmentHandler, handleSupplementReplace, detachAttachmnetHandler, handleUpdateInline, attachmentId, fileName, publicUrl, hideActionList, dispatch, dropDownClassName, showReplaceAction, }) => {
43
+ const ItemActions = ({ fileSection, isMainManuscript, downloadAttachmentHandler, replaceAttachmentHandler, handleSupplementReplace, detachAttachmnetHandler, handleUpdateInline, attachmentId, fileName, publicUrl, hideActionList, dispatch, dropDownClassName, showReplaceAction, }) => {
43
44
  const can = (0, react_1.useContext)(FileManager_1.PermissionsContext);
45
+ const { setMoveFilePopupData } = (0, react_1.useContext)(FileManagerProvider_1.FileManagerContext);
44
46
  const canBeReplaced = showReplaceAction == undefined || showReplaceAction;
45
47
  const fileInputRef = (0, react_1.useRef)(null);
46
48
  const [selectedFile, setSelectedFile] = (0, react_1.useState)();
@@ -71,13 +73,20 @@ const ItemActions = ({ fileSection, downloadAttachmentHandler, replaceAttachment
71
73
  fileInputRef.current.click();
72
74
  }
73
75
  };
74
- return (react_1.default.createElement(Dropdown_1.DropdownList, { direction: 'right', className: dropDownClassName, width: 125, height: 120, top: 5, onClick: hideActionList },
76
+ return (react_1.default.createElement(Dropdown_1.DropdownList, { direction: 'right', className: dropDownClassName, width: 200, height: 120, top: 5, onClick: hideActionList },
75
77
  react_1.default.createElement(ItemsAction_1.ActionsItem, { onClick: () => {
76
78
  publicUrl !== undefined ? downloadAttachmentHandler(publicUrl) : {};
77
79
  } }, "Download"),
78
80
  (can === null || can === void 0 ? void 0 : can.replaceFile) && canBeReplaced && (react_1.default.createElement(react_1.default.Fragment, null,
79
81
  react_1.default.createElement(ItemsAction_1.ActionsItem, { onClick: openFileDialog }, "Replace"),
80
82
  react_1.default.createElement("input", { ref: fileInputRef, type: "file", style: { display: 'none' }, onChange: (e) => handleChange(e), value: '' }))),
81
- (can === null || can === void 0 ? void 0 : can.editArticle) && detachAttachmnetHandler && (react_1.default.createElement(ItemsAction_1.ActionsItem, { onClick: () => detachAttachmnetHandler() }, "Detach"))));
83
+ (can === null || can === void 0 ? void 0 : can.editArticle) && detachAttachmnetHandler && (react_1.default.createElement(ItemsAction_1.ActionsItem, { onClick: () => detachAttachmnetHandler() }, "Detach")),
84
+ !isMainManuscript &&
85
+ fileSection !== util_1.FileSectionType.Inline &&
86
+ (can === null || can === void 0 ? void 0 : can.moveFile) && (react_1.default.createElement(ItemsAction_1.ActionsItem, { onClick: () => setMoveFilePopupData({ isOpen: true, attachmentId, fileSection }) },
87
+ "Move to",
88
+ ' ',
89
+ (fileSection === util_1.FileSectionType.OtherFile && 'Supplements') ||
90
+ 'Other files'))));
82
91
  };
83
92
  exports.ItemActions = ItemActions;
@@ -33,7 +33,7 @@ const reducer = (state, action) => {
33
33
  }, successMessage: action.successMoveMessage, isShowSuccessMessage: false });
34
34
  }
35
35
  case ActionTypes.HANDLE_UPLOAD_ACTION: {
36
- return Object.assign(Object.assign({}, state), { isUploadFile: true, isShowSuccessMessage: false, successMessage: '' });
36
+ return Object.assign(Object.assign({}, state), { isUploadFile: true, isShowSuccessMessage: false, fileUploadedSuccessfullySection: undefined, successMessage: '' });
37
37
  }
38
38
  case ActionTypes.HANDLE_CANCEL_UPLOAD: {
39
39
  return Object.assign({}, state);
@@ -40,6 +40,7 @@ const getCapabilities = (project, profile, role, actions) => {
40
40
  downloadFiles: true,
41
41
  changeDesignation: (isOwner() || isEditor() || isWriter()) &&
42
42
  allowed(Actions.updateAttachment),
43
+ moveFile: isOwner() || isEditor() || isWriter(),
43
44
  replaceFile: isOwner() || isEditor() || isWriter(),
44
45
  uploadFile: isOwner() || isEditor() || isWriter(),
45
46
  handleQualityReport: isOwner() || isEditor() || isWriter(),
@@ -8,7 +8,7 @@ export const DropdownList = styled.div `
8
8
  box-shadow: 0 4px 9px rgba(0, 0, 0, 0.3);
9
9
  background: ${(props) => props.theme.colors.background.primary};
10
10
  width: ${(props) => (props.width ? props.width + 'px' : 'auto')};
11
- ${(props) => props.height && `height: ${props.height}px`};
11
+ ${(props) => props.height && `max-height: ${props.height}px`};
12
12
  ${(props) => (props.direction === 'right' ? ' right: 0' : 'left : 0')};
13
13
  top: ${(props) => props.theme.grid.unit * (props.top || 3)}px;
14
14
  position: absolute;
@@ -1,5 +1,19 @@
1
- import React from 'react';
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
+ };
10
+ import { ObjectTypes } from '@manuscripts/json-schema';
11
+ import { buildSupplementaryMaterial, getModelsByType, } from '@manuscripts/transform';
12
+ import React, { useCallback, useContext } from 'react';
2
13
  import { Category, Dialog } from '../Dialog';
14
+ import { FileManagerContext } from './FileManagerProvider';
15
+ import { actions } from './FileSectionState';
16
+ import { FileSectionType } from './util';
3
17
  export const ConfirmationPopUp = ({ popupHeader, popUpMessage, isOpen, handleClose, handleMove }) => {
4
18
  return (React.createElement(Dialog, { isOpen: isOpen, category: Category.confirmation, header: popupHeader, message: popUpMessage, actions: {
5
19
  primary: {
@@ -12,3 +26,37 @@ export const ConfirmationPopUp = ({ popupHeader, popUpMessage, isOpen, handleClo
12
26
  },
13
27
  } }));
14
28
  };
29
+ export const MoveFilePopup = ({ dispatch, }) => {
30
+ const { moveFilePopup: { isOpen, fileSection, attachmentId }, saveModel, deleteModel, modelMap, getAttachments, setMoveFilePopupData, } = useContext(FileManagerContext);
31
+ const isSupplement = fileSection === FileSectionType.Supplements;
32
+ const message = {
33
+ popupHeader: `Are you sure you want to move this file to “${(!isSupplement && 'Supplements') || 'Other files'}”?`,
34
+ popUpMessage: `The file will be removed from the “${(isSupplement && 'Supplements') || 'Other files'}” and added to “${(!isSupplement && 'Supplements') || 'Other files'}”.`,
35
+ };
36
+ const closePopup = useCallback(() => setMoveFilePopupData({
37
+ isOpen: false,
38
+ fileSection: fileSection,
39
+ }), [fileSection, setMoveFilePopupData]);
40
+ const showSuccessMessage = useCallback(() => dispatch(actions.HANDLE_SUCCESS_MESSAGE(`File moved to ${(isSupplement && 'Other files') || 'Supplements'}.`, fileSection)), [dispatch, fileSection, isSupplement]);
41
+ const moveToSupplement = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
42
+ closePopup();
43
+ const attachment = getAttachments().find(({ id }) => id === attachmentId);
44
+ if (!attachment) {
45
+ return;
46
+ }
47
+ const model = buildSupplementaryMaterial(attachment.name, `attachment:${attachment.id}`);
48
+ yield saveModel(Object.assign(Object.assign({}, model), { title: attachment.name, href: `attachment:${attachment.id}` }));
49
+ showSuccessMessage();
50
+ }), [getAttachments, saveModel, showSuccessMessage, closePopup, attachmentId]);
51
+ const moveSupplementToOtherFiles = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
52
+ closePopup();
53
+ const model = getModelsByType(modelMap, ObjectTypes.Supplement).find(({ href }) => (href === null || href === void 0 ? void 0 : href.replace('attachment:', '')) === attachmentId);
54
+ if (!model) {
55
+ return;
56
+ }
57
+ yield deleteModel(model._id);
58
+ showSuccessMessage();
59
+ }), [attachmentId, closePopup, deleteModel, modelMap, showSuccessMessage]);
60
+ return (React.createElement(React.Fragment, null,
61
+ React.createElement(ConfirmationPopUp, Object.assign({ isOpen: isOpen }, message, { handleMove: () => (!isSupplement && moveToSupplement()) || moveSupplementToOtherFiles(), handleClose: closePopup }))));
62
+ };
@@ -14,6 +14,8 @@ import ReactTooltip from 'react-tooltip';
14
14
  import { FileSectionType, useFiles } from '../../index';
15
15
  import { InspectorTab, InspectorTabList, InspectorTabPanel, InspectorTabPanels, InspectorTabs, } from '../Inspector';
16
16
  import { InspectorSection } from '../InspectorSection';
17
+ import { MoveFilePopup } from './ConfirmationPopUp';
18
+ import { FileManagerProvider } from './FileManagerProvider';
17
19
  import { DraggableFileSectionItem } from './FileSectionItem/DraggableFileSectionItem';
18
20
  import { DragLayer } from './FileSectionItem/DragLayer';
19
21
  import { FileSectionItem, } from './FileSectionItem/FileSectionItem';
@@ -23,7 +25,7 @@ import { InlineFilesSection } from './InlineFilesSection';
23
25
  import { TooltipDiv } from './TooltipDiv';
24
26
  import { generateAttachmentsTitles } from './util';
25
27
  export const PermissionsContext = createContext(null);
26
- export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManagement: { getAttachments, replace, upload }, addAttachmentToState, }) => {
28
+ export const FileManager = ({ modelMap, saveModel, deleteModel, enableDragAndDrop, can, fileManagement: { getAttachments, replace, upload }, addAttachmentToState, }) => {
27
29
  const [state, dispatch] = useReducer(reducer, getInitialState());
28
30
  const handleReplaceFile = useCallback((attachmentId, name, file) => __awaiter(void 0, void 0, void 0, function* () {
29
31
  dispatch(actions.HANDLE_UPLOAD_ACTION());
@@ -107,7 +109,7 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
107
109
  });
108
110
  return filesItems;
109
111
  };
110
- return (React.createElement(React.Fragment, null,
112
+ return (React.createElement(FileManagerProvider, { saveModel: saveModel, modelMap: modelMap, deleteModel: deleteModel, getAttachments: getAttachments },
111
113
  React.createElement(DragLayer, null),
112
114
  React.createElement(PermissionsContext.Provider, { value: can },
113
115
  React.createElement(InspectorSection, { title: 'Files', contentStyles: { margin: '24px' } },
@@ -134,5 +136,6 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
134
136
  React.createElement(InspectorTabPanel, null,
135
137
  React.createElement(FilesSection, { enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFileWithSupplement, fileSection: FileSectionType.Supplements, filesItem: getFileSectionExternalFile(FileSectionType.Supplements), state: state, dispatch: dispatch })),
136
138
  React.createElement(InspectorTabPanel, null,
137
- React.createElement(FilesSection, { enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFile, fileSection: FileSectionType.OtherFile, filesItem: getFileSectionExternalFile(FileSectionType.OtherFile), state: state, dispatch: dispatch }))))))));
139
+ React.createElement(FilesSection, { enableDragAndDrop: enableDragAndDrop, handleUpload: handleUploadFile, fileSection: FileSectionType.OtherFile, filesItem: getFileSectionExternalFile(FileSectionType.OtherFile), state: state, dispatch: dispatch }))))),
140
+ React.createElement(MoveFilePopup, { dispatch: dispatch }))));
138
141
  };
@@ -0,0 +1,17 @@
1
+ import React, { createContext, useState } from 'react';
2
+ export const FileManagerContext = createContext({
3
+ saveModel: () => '',
4
+ moveFilePopup: { isOpen: false },
5
+ setMoveFilePopupData: () => '',
6
+ });
7
+ export const FileManagerProvider = ({ children, saveModel, deleteModel, modelMap, getAttachments }) => {
8
+ const [moveFilePopup, setMoveFilePopupData] = useState({ isOpen: false });
9
+ return (React.createElement(FileManagerContext.Provider, { value: {
10
+ saveModel,
11
+ deleteModel,
12
+ modelMap,
13
+ getAttachments,
14
+ moveFilePopup,
15
+ setMoveFilePopupData,
16
+ } }, children));
17
+ };
@@ -30,7 +30,7 @@ export const FileSectionItem = ({ fileSection, externalFile, title, showAttachme
30
30
  handleDownload && handleReplace && (React.createElement(DropdownContainer, { ref: wrapperRef },
31
31
  React.createElement(ActionsIcon, { onClick: toggleOpen, type: "button", "aria-label": "Download or Replace", "aria-pressed": isOpen },
32
32
  React.createElement(DotsIcon, null)),
33
- isOpen && (React.createElement(ItemActions, { fileSection: fileSection, replaceAttachmentHandler: handleReplace, showReplaceAction: showReplaceAction, downloadAttachmentHandler: handleDownload, handleSupplementReplace: handleSupplementReplace, attachmentId: externalFile.id, fileName: externalFile.name, publicUrl: externalFile.link, hideActionList: toggleOpen, dispatch: dispatch }))))));
33
+ isOpen && (React.createElement(ItemActions, { fileSection: fileSection, isMainManuscript: isMainManuscript, replaceAttachmentHandler: handleReplace, showReplaceAction: showReplaceAction, downloadAttachmentHandler: handleDownload, handleSupplementReplace: handleSupplementReplace, attachmentId: externalFile.id, fileName: externalFile.name, publicUrl: externalFile.link, hideActionList: toggleOpen, dispatch: dispatch }))))));
34
34
  };
35
35
  const IconCloseButton = styled.button `
36
36
  border: none;
@@ -10,11 +10,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import React, { useContext, useRef, useState, } from 'react';
11
11
  import { DropdownList } from '../../Dropdown';
12
12
  import { PermissionsContext } from '../FileManager';
13
+ import { FileManagerContext } from '../FileManagerProvider';
13
14
  import { actions } from '../FileSectionState';
14
15
  import { ActionsItem } from '../ItemsAction';
15
16
  import { FileSectionType } from '../util';
16
- export const ItemActions = ({ fileSection, downloadAttachmentHandler, replaceAttachmentHandler, handleSupplementReplace, detachAttachmnetHandler, handleUpdateInline, attachmentId, fileName, publicUrl, hideActionList, dispatch, dropDownClassName, showReplaceAction, }) => {
17
+ export const ItemActions = ({ fileSection, isMainManuscript, downloadAttachmentHandler, replaceAttachmentHandler, handleSupplementReplace, detachAttachmnetHandler, handleUpdateInline, attachmentId, fileName, publicUrl, hideActionList, dispatch, dropDownClassName, showReplaceAction, }) => {
17
18
  const can = useContext(PermissionsContext);
19
+ const { setMoveFilePopupData } = useContext(FileManagerContext);
18
20
  const canBeReplaced = showReplaceAction == undefined || showReplaceAction;
19
21
  const fileInputRef = useRef(null);
20
22
  const [selectedFile, setSelectedFile] = useState();
@@ -45,12 +47,19 @@ export const ItemActions = ({ fileSection, downloadAttachmentHandler, replaceAtt
45
47
  fileInputRef.current.click();
46
48
  }
47
49
  };
48
- return (React.createElement(DropdownList, { direction: 'right', className: dropDownClassName, width: 125, height: 120, top: 5, onClick: hideActionList },
50
+ return (React.createElement(DropdownList, { direction: 'right', className: dropDownClassName, width: 200, height: 120, top: 5, onClick: hideActionList },
49
51
  React.createElement(ActionsItem, { onClick: () => {
50
52
  publicUrl !== undefined ? downloadAttachmentHandler(publicUrl) : {};
51
53
  } }, "Download"),
52
54
  (can === null || can === void 0 ? void 0 : can.replaceFile) && canBeReplaced && (React.createElement(React.Fragment, null,
53
55
  React.createElement(ActionsItem, { onClick: openFileDialog }, "Replace"),
54
56
  React.createElement("input", { ref: fileInputRef, type: "file", style: { display: 'none' }, onChange: (e) => handleChange(e), value: '' }))),
55
- (can === null || can === void 0 ? void 0 : can.editArticle) && detachAttachmnetHandler && (React.createElement(ActionsItem, { onClick: () => detachAttachmnetHandler() }, "Detach"))));
57
+ (can === null || can === void 0 ? void 0 : can.editArticle) && detachAttachmnetHandler && (React.createElement(ActionsItem, { onClick: () => detachAttachmnetHandler() }, "Detach")),
58
+ !isMainManuscript &&
59
+ fileSection !== FileSectionType.Inline &&
60
+ (can === null || can === void 0 ? void 0 : can.moveFile) && (React.createElement(ActionsItem, { onClick: () => setMoveFilePopupData({ isOpen: true, attachmentId, fileSection }) },
61
+ "Move to",
62
+ ' ',
63
+ (fileSection === FileSectionType.OtherFile && 'Supplements') ||
64
+ 'Other files'))));
56
65
  };
@@ -29,7 +29,7 @@ export const reducer = (state, action) => {
29
29
  }, successMessage: action.successMoveMessage, isShowSuccessMessage: false });
30
30
  }
31
31
  case ActionTypes.HANDLE_UPLOAD_ACTION: {
32
- return Object.assign(Object.assign({}, state), { isUploadFile: true, isShowSuccessMessage: false, successMessage: '' });
32
+ return Object.assign(Object.assign({}, state), { isUploadFile: true, isShowSuccessMessage: false, fileUploadedSuccessfullySection: undefined, successMessage: '' });
33
33
  }
34
34
  case ActionTypes.HANDLE_CANCEL_UPLOAD: {
35
35
  return Object.assign({}, state);
@@ -34,6 +34,7 @@ export const getCapabilities = (project, profile, role, actions) => {
34
34
  downloadFiles: true,
35
35
  changeDesignation: (isOwner() || isEditor() || isWriter()) &&
36
36
  allowed(Actions.updateAttachment),
37
+ moveFile: isOwner() || isEditor() || isWriter(),
37
38
  replaceFile: isOwner() || isEditor() || isWriter(),
38
39
  uploadFile: isOwner() || isEditor() || isWriter(),
39
40
  handleQualityReport: isOwner() || isEditor() || isWriter(),
@@ -1,4 +1,5 @@
1
- import React from 'react';
1
+ import React, { Dispatch } from 'react';
2
+ import { Action } from './FileSectionState';
2
3
  export declare const ConfirmationPopUp: React.FC<{
3
4
  popupHeader: string;
4
5
  popUpMessage: string;
@@ -6,3 +7,6 @@ export declare const ConfirmationPopUp: React.FC<{
6
7
  handleClose: () => void;
7
8
  handleMove: () => void;
8
9
  }>;
10
+ export declare const MoveFilePopup: React.FC<{
11
+ dispatch: Dispatch<Action>;
12
+ }>;
@@ -15,6 +15,7 @@ export declare const FileManager: React.FC<{
15
15
  fileManagement: FileManagement;
16
16
  modelMap: Map<string, Model>;
17
17
  saveModel: <T extends Model>(model: T | Build<T> | Partial<T>) => Promise<T>;
18
+ deleteModel: (id: string) => Promise<string>;
18
19
  enableDragAndDrop: boolean;
19
20
  can: Capabilities;
20
21
  addAttachmentToState?: (a: FileAttachment) => void;
@@ -0,0 +1,25 @@
1
+ import { Model } from '@manuscripts/json-schema';
2
+ import { Build } from '@manuscripts/transform';
3
+ import React, { Dispatch, SetStateAction } from 'react';
4
+ import { FileAttachment } from './FileSectionItem/FileSectionItem';
5
+ import { FileSectionType } from './util';
6
+ type MoveFilePopup = {
7
+ isOpen: boolean;
8
+ fileSection?: FileSectionType;
9
+ attachmentId?: string;
10
+ };
11
+ export declare const FileManagerContext: React.Context<{
12
+ saveModel: <T extends Model>(model: T | Build<T> | Partial<T>) => Promise<T>;
13
+ deleteModel: (id: string) => Promise<string>;
14
+ modelMap: Map<string, Model>;
15
+ getAttachments: () => FileAttachment[];
16
+ moveFilePopup: MoveFilePopup;
17
+ setMoveFilePopupData: Dispatch<SetStateAction<MoveFilePopup>>;
18
+ }>;
19
+ export declare const FileManagerProvider: React.FC<{
20
+ saveModel: <T extends Model>(model: T | Build<T> | Partial<T>) => Promise<T>;
21
+ deleteModel: (id: string) => Promise<string>;
22
+ modelMap: Map<string, Model>;
23
+ getAttachments: () => FileAttachment[];
24
+ }>;
25
+ export {};
@@ -5,6 +5,7 @@ import { FileSectionType } from '../util';
5
5
  import { FileAttachment } from './FileSectionItem';
6
6
  export declare const ItemActions: React.FC<{
7
7
  fileSection: FileSectionType;
8
+ isMainManuscript?: boolean;
8
9
  downloadAttachmentHandler: (url: string) => void;
9
10
  replaceAttachmentHandler: Replace;
10
11
  detachAttachmnetHandler?: () => void;
@@ -20,6 +20,7 @@ export type Capabilities = {
20
20
  restoreVersion: boolean;
21
21
  downloadFiles: boolean;
22
22
  changeDesignation: boolean;
23
+ moveFile: boolean;
23
24
  replaceFile: boolean;
24
25
  uploadFile: boolean;
25
26
  handleQualityReport: boolean;
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.8",
4
+ "version": "1.1.9",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-style-guide",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",