@manuscripts/style-guide 1.3.5 → 1.3.6-LEAN-2705

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.
Files changed (110) hide show
  1. package/dist/cjs/components/EditorHeader/EditorHeader.js +3 -11
  2. package/dist/cjs/components/EditorHeader/ProceedView.js +25 -6
  3. package/dist/cjs/components/FileManager/{FileSectionItem/DragLayer.js → DragLayer.js} +12 -10
  4. package/dist/cjs/components/FileManager/FileActions.js +134 -0
  5. package/dist/cjs/components/FileManager/FileContainer.js +39 -0
  6. package/dist/cjs/components/FileManager/FileCreatedDate.js +25 -0
  7. package/dist/cjs/components/FileManager/FileManager.js +14 -125
  8. package/dist/cjs/components/FileManager/FileManagerProvider.js +2 -7
  9. package/dist/cjs/components/FileManager/FileName.js +27 -0
  10. package/dist/cjs/components/FileManager/FileSectionAlert.js +170 -0
  11. package/dist/cjs/components/FileManager/FileTypeIcon.js +22 -0
  12. package/dist/cjs/components/FileManager/{UploadFileArea.js → FileUploader.js} +19 -12
  13. package/dist/cjs/components/FileManager/InlineFilesSection.js +71 -126
  14. package/dist/cjs/components/FileManager/OtherFilesSection.js +101 -0
  15. package/dist/cjs/components/FileManager/SupplementsSection.js +118 -0
  16. package/dist/cjs/components/FileManager/{TooltipDiv.js → Tooltip.js} +8 -3
  17. package/dist/cjs/components/FileManager/util.js +52 -67
  18. package/dist/cjs/components/icons/corrupted-file-icon.js +27 -0
  19. package/dist/cjs/components/icons/document-icon-with-dot.js +1 -1
  20. package/dist/cjs/hooks/use-deep-compare.js +2 -2
  21. package/dist/cjs/hooks/use-files.js +29 -43
  22. package/dist/cjs/index.js +3 -4
  23. package/dist/cjs/lib/capabilities.js +1 -0
  24. package/dist/cjs/lib/files.js +85 -0
  25. package/dist/es/components/EditorHeader/EditorHeader.js +3 -11
  26. package/dist/es/components/EditorHeader/ProceedView.js +26 -7
  27. package/dist/es/components/FileManager/{FileSectionItem/DragLayer.js → DragLayer.js} +12 -10
  28. package/dist/es/components/FileManager/FileActions.js +104 -0
  29. package/dist/es/components/FileManager/FileContainer.js +33 -0
  30. package/dist/es/components/FileManager/FileCreatedDate.js +18 -0
  31. package/dist/es/components/FileManager/FileManager.js +16 -124
  32. package/dist/es/components/FileManager/FileManagerProvider.js +3 -8
  33. package/dist/es/components/FileManager/FileName.js +20 -0
  34. package/dist/es/components/FileManager/FileSectionAlert.js +163 -0
  35. package/dist/es/components/FileManager/FileTypeIcon.js +15 -0
  36. package/dist/es/components/FileManager/{UploadFileArea.js → FileUploader.js} +17 -10
  37. package/dist/es/components/FileManager/InlineFilesSection.js +72 -127
  38. package/dist/es/components/FileManager/OtherFilesSection.js +74 -0
  39. package/dist/es/components/FileManager/SupplementsSection.js +91 -0
  40. package/dist/es/components/FileManager/{TooltipDiv.js → Tooltip.js} +7 -2
  41. package/dist/es/components/FileManager/util.js +47 -65
  42. package/dist/es/components/icons/corrupted-file-icon.js +22 -0
  43. package/dist/es/components/icons/document-icon-with-dot.js +1 -1
  44. package/dist/es/hooks/use-deep-compare.js +2 -2
  45. package/dist/es/hooks/use-files.js +29 -40
  46. package/dist/es/index.js +2 -2
  47. package/dist/es/lib/capabilities.js +1 -0
  48. package/dist/es/lib/files.js +79 -0
  49. package/dist/types/components/EditorHeader/ProceedView.d.ts +0 -1
  50. package/dist/types/components/FileManager/FileActions.d.ts +19 -0
  51. package/dist/types/components/FileManager/FileContainer.d.ts +1 -0
  52. package/dist/types/components/FileManager/FileCreatedDate.d.ts +8 -0
  53. package/dist/types/components/FileManager/FileManager.d.ts +17 -8
  54. package/dist/types/components/FileManager/FileManagerProvider.d.ts +8 -18
  55. package/dist/types/components/FileManager/FileName.d.ts +6 -0
  56. package/dist/types/components/FileManager/FileSectionAlert.d.ts +13 -0
  57. package/dist/types/components/FileManager/{FileSectionItem/FileTypeIcon.d.ts → FileTypeIcon.d.ts} +2 -3
  58. package/dist/types/components/FileManager/FileUploader.d.ts +4 -0
  59. package/dist/types/components/FileManager/InlineFilesSection.d.ts +3 -19
  60. package/dist/types/components/FileManager/OtherFilesSection.d.ts +5 -0
  61. package/dist/types/components/FileManager/SupplementsSection.d.ts +5 -0
  62. package/dist/types/components/FileManager/Tooltip.d.ts +2 -0
  63. package/dist/types/components/FileManager/util.d.ts +8 -12
  64. package/dist/types/components/icons/corrupted-file-icon.d.ts +19 -0
  65. package/dist/types/hooks/use-files.d.ts +4 -6
  66. package/dist/types/index.d.ts +2 -2
  67. package/dist/types/lib/capabilities.d.ts +1 -0
  68. package/dist/types/lib/files.d.ts +24 -0
  69. package/package.json +3 -3
  70. package/dist/cjs/components/FileManager/ConfirmationPopUp.js +0 -90
  71. package/dist/cjs/components/FileManager/DragItemArea.js +0 -28
  72. package/dist/cjs/components/FileManager/FileSectionItem/DraggableFileSectionItem.js +0 -76
  73. package/dist/cjs/components/FileManager/FileSectionItem/FileInfo.js +0 -115
  74. package/dist/cjs/components/FileManager/FileSectionItem/FileSectionItem.js +0 -95
  75. package/dist/cjs/components/FileManager/FileSectionItem/FileSectionUploadItem.js +0 -37
  76. package/dist/cjs/components/FileManager/FileSectionItem/FileTypeIcon.js +0 -53
  77. package/dist/cjs/components/FileManager/FileSectionItem/ItemActions.js +0 -92
  78. package/dist/cjs/components/FileManager/FileSectionItem/ProgressBarUploadItem.js +0 -120
  79. package/dist/cjs/components/FileManager/FileSectionState.js +0 -83
  80. package/dist/cjs/components/FileManager/FilesSection.js +0 -61
  81. package/dist/cjs/components/FileManager/ItemsAction.js +0 -48
  82. package/dist/cjs/lib/inlineFiles.js +0 -92
  83. package/dist/es/components/FileManager/ConfirmationPopUp.js +0 -62
  84. package/dist/es/components/FileManager/DragItemArea.js +0 -21
  85. package/dist/es/components/FileManager/FileSectionItem/DraggableFileSectionItem.js +0 -46
  86. package/dist/es/components/FileManager/FileSectionItem/FileInfo.js +0 -85
  87. package/dist/es/components/FileManager/FileSectionItem/FileSectionItem.js +0 -88
  88. package/dist/es/components/FileManager/FileSectionItem/FileSectionUploadItem.js +0 -30
  89. package/dist/es/components/FileManager/FileSectionItem/FileTypeIcon.js +0 -46
  90. package/dist/es/components/FileManager/FileSectionItem/ItemActions.js +0 -65
  91. package/dist/es/components/FileManager/FileSectionItem/ProgressBarUploadItem.js +0 -113
  92. package/dist/es/components/FileManager/FileSectionState.js +0 -78
  93. package/dist/es/components/FileManager/FilesSection.js +0 -34
  94. package/dist/es/components/FileManager/ItemsAction.js +0 -42
  95. package/dist/es/lib/inlineFiles.js +0 -90
  96. package/dist/types/components/FileManager/ConfirmationPopUp.d.ts +0 -12
  97. package/dist/types/components/FileManager/DragItemArea.d.ts +0 -4
  98. package/dist/types/components/FileManager/FileSectionItem/DraggableFileSectionItem.d.ts +0 -3
  99. package/dist/types/components/FileManager/FileSectionItem/FileInfo.d.ts +0 -19
  100. package/dist/types/components/FileManager/FileSectionItem/FileSectionItem.d.ts +0 -38
  101. package/dist/types/components/FileManager/FileSectionItem/FileSectionUploadItem.d.ts +0 -12
  102. package/dist/types/components/FileManager/FileSectionItem/ItemActions.d.ts +0 -21
  103. package/dist/types/components/FileManager/FileSectionItem/ProgressBarUploadItem.d.ts +0 -4
  104. package/dist/types/components/FileManager/FileSectionState.d.ts +0 -38
  105. package/dist/types/components/FileManager/FilesSection.d.ts +0 -12
  106. package/dist/types/components/FileManager/ItemsAction.d.ts +0 -4
  107. package/dist/types/components/FileManager/TooltipDiv.d.ts +0 -1
  108. package/dist/types/components/FileManager/UploadFileArea.d.ts +0 -9
  109. package/dist/types/lib/inlineFiles.d.ts +0 -11
  110. /package/dist/types/components/FileManager/{FileSectionItem/DragLayer.d.ts → DragLayer.d.ts} +0 -0
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import CorruptedFileIcon from '../icons/corrupted-file-icon';
3
+ import DocumentIconWithDot from '../icons/document-icon-with-dot';
4
+ import UnknownFormatFileIcon from '../icons/unknown-format-file-icon';
5
+ import { getFileIcon } from './util';
6
+ export const FileTypeIcon = ({ file }) => {
7
+ if (file.type.id === 'missing') {
8
+ return React.createElement(CorruptedFileIcon, { className: "file-icon" });
9
+ }
10
+ if (file.type.id === 'main-manuscript') {
11
+ return React.createElement(DocumentIconWithDot, { className: "file-icon" });
12
+ }
13
+ const icon = getFileIcon(file);
14
+ return icon || React.createElement(UnknownFormatFileIcon, { className: "file-icon" });
15
+ };
@@ -1,27 +1,35 @@
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, { useCallback, useRef } from 'react';
2
11
  import { useDrop } from 'react-dnd';
3
12
  import { NativeTypes } from 'react-dnd-html5-backend';
4
13
  import styled, { css } from 'styled-components';
5
- import { actions } from './FileSectionState';
6
- export const UploadFileArea = ({ fileSection, dispatch }) => {
14
+ export const FileUploader = ({ handler }) => {
7
15
  const fileInputRef = useRef(null);
8
16
  const openFileDialog = () => {
9
17
  if (fileInputRef && fileInputRef.current) {
10
18
  fileInputRef.current.click();
11
19
  }
12
20
  };
13
- const handleChange = (event) => {
21
+ const handleChange = (event) => __awaiter(void 0, void 0, void 0, function* () {
14
22
  if (event && event.target && event.target.files) {
15
23
  const file = event.target.files[0];
16
- dispatch(actions.UPLOAD_FILE(file, fileSection));
24
+ yield handler(file);
17
25
  }
18
- };
19
- const handleFileDrop = useCallback((monitor) => {
26
+ });
27
+ const handleFileDrop = useCallback((monitor) => __awaiter(void 0, void 0, void 0, function* () {
20
28
  if (monitor) {
21
29
  const file = monitor.getItem().files[0];
22
- dispatch(actions.UPLOAD_FILE(file, fileSection));
30
+ yield handler(file);
23
31
  }
24
- }, [dispatch, fileSection]);
32
+ }), [handler]);
25
33
  const [{ canDrop, isOver }, dropRef] = useDrop({
26
34
  accept: [NativeTypes.FILE],
27
35
  drop(item, monitor) {
@@ -55,8 +63,7 @@ const Container = styled.div `
55
63
  font-family: ${(props) => props.theme.font.family.Lato};
56
64
  color: ${(props) => props.theme.colors.text.onLight};
57
65
  cursor: pointer;
58
- margin-bottom: 7px;
59
- margin-top: 16px;
66
+ margin: 16px 16px 8px;
60
67
  ${(props) => props.active
61
68
  ? css `
62
69
  ${activeBoxStyle}
@@ -1,158 +1,103 @@
1
- import { format } from 'date-fns';
2
- import React, { useCallback } from 'react';
3
- import ReactTooltip from 'react-tooltip';
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 React, { useCallback, useContext } from 'react';
4
11
  import styled from 'styled-components';
5
- import { useDropdown } from '../../hooks/use-dropdown';
6
- import DotsIcon from '../icons/dots-icon';
7
- import { FileInfoContainer, FileNameTitleContainer, FileTitle, } from './FileSectionItem/FileInfo';
8
- import { ActionsIcon, Item, } from './FileSectionItem/FileSectionItem';
9
- import { ItemActions } from './FileSectionItem/ItemActions';
10
- import { extensionsWithFileTypesMap, FileSectionType, fileTypesWithIconMap, } from './util';
12
+ import { FileActions } from './FileActions';
13
+ import { FileContainer } from './FileContainer';
14
+ import { FileCreatedDate } from './FileCreatedDate';
15
+ import { FileManagerContext } from './FileManagerProvider';
16
+ import { FileName } from './FileName';
17
+ import { FileSectionType, getFileTypeIcon } from './util';
11
18
  const trackedJoint = ':dataTracked:';
12
- export const InlineFilesSection = ({ handleReplace, handleDownload, handleUpdateInline, handleDetachFile, inlineFiles, isEditor, dispatch, }) => {
19
+ export const InlineFilesSection = ({ elements, isEditor }) => {
20
+ const { modelMap, fileManagement, saveModel } = useContext(FileManagerContext);
21
+ const navigateToElement = (id) => {
22
+ const clearedId = id.split(trackedJoint)[0];
23
+ const isSelected = clearedId == window.location.hash.substring(1);
24
+ window.location.hash = !isSelected ? `#${clearedId}` : '#';
25
+ };
13
26
  const onElementClick = useCallback((e) => {
14
27
  if (!isEditor) {
15
28
  return;
16
29
  }
17
- const { id } = e.currentTarget;
18
- const clearedId = id.split(trackedJoint)[0];
19
- const isSelected = clearedId == window.location.hash.substr(1);
20
- window.location.hash = !isSelected ? `#${clearedId}` : '#';
21
- if (isSelected) {
22
- window.location.hash = `#${clearedId}`;
23
- }
30
+ navigateToElement(e.currentTarget.id);
24
31
  }, [isEditor]);
25
- return (React.createElement("div", null, inlineFiles.map((file, index) => {
32
+ const updateFigureSrc = (modelId, src) => __awaiter(void 0, void 0, void 0, function* () {
33
+ const figure = modelMap.get(modelId);
34
+ if (figure) {
35
+ yield saveModel(Object.assign(Object.assign({}, figure), { src: src }));
36
+ }
37
+ });
38
+ const detach = (element, file) => __awaiter(void 0, void 0, void 0, function* () {
39
+ yield updateFigureSrc(file.modelId, '');
40
+ navigateToElement(element.modelId);
41
+ });
42
+ const replace = (element, model, file) => __awaiter(void 0, void 0, void 0, function* () {
43
+ const uploaded = yield fileManagement.upload(file);
44
+ yield updateFigureSrc(model.modelId, uploaded.id);
45
+ navigateToElement(element.modelId);
46
+ });
47
+ return (React.createElement(React.Fragment, null, elements.map((element, index) => {
26
48
  var _a;
27
- return (React.createElement(ElementItem, { className: 'item', key: index, id: file.id, onClick: onElementClick },
28
- React.createElement(FileReferences, { className: 'refItems' }, (_a = file.attachments) === null || _a === void 0 ? void 0 : _a.map((attachment) => (React.createElement(React.Fragment, null,
29
- React.createElement(FileReference, { key: attachment.id, attachment: attachment, handleReplace: handleReplace, handleUpdateInline: handleUpdateInline, handleDetachFile: handleDetachFile, handleDownload: handleDownload, dispatch: dispatch }))))),
30
- React.createElement(Element, { className: 'element' },
31
- fileTypesWithIconMap.get(file.type),
32
- React.createElement(FileInfoContainer, null,
33
- React.createElement(FileNameTitleContainer, null,
34
- React.createElement(FileTitle, null, file.label))))));
49
+ return (React.createElement(Element, { key: index, id: element.modelId, onClick: onElementClick },
50
+ React.createElement(ElementLabelContainer, null,
51
+ getFileTypeIcon(element.type),
52
+ React.createElement(ElementLabel, null, element.label)),
53
+ React.createElement(ElementFilesContainer, null, (_a = element.files) === null || _a === void 0 ? void 0 : _a.map((file) => (React.createElement(ElementFile, { key: file.modelId, file: file, handleReplace: (f) => __awaiter(void 0, void 0, void 0, function* () { return yield replace(element, file, f); }), handleDetach: () => __awaiter(void 0, void 0, void 0, function* () { return yield detach(element, file); }), handleDownload: () => fileManagement.download(file) }))))));
35
54
  })));
36
55
  };
37
- const FileReference = ({ attachment, handleReplace, handleDownload, handleUpdateInline, handleDetachFile, dispatch, }) => {
38
- const { isOpen, toggleOpen, wrapperRef } = useDropdown();
39
- if (!attachment || !attachment.name) {
40
- return null;
41
- }
42
- const fileExtension = attachment.name.substring(attachment.name.lastIndexOf('.') + 1);
43
- return (React.createElement(FileReferenceItem, { key: attachment.id },
44
- React.createElement(Container, null,
45
- fileTypesWithIconMap.get(extensionsWithFileTypesMap.get(fileExtension)),
46
- React.createElement(FileReferenceName, null, attachment.name)),
47
- attachment.createdDate && (React.createElement(FileDateContainer, { "data-tip": "tooltip-content" },
48
- React.createElement(FileDate, null, format(new Date(attachment.createdDate), 'M/d/yy, HH:mm')),
49
- React.createElement(ReactTooltip, { place: "bottom", offset: { top: 0 }, effect: "solid", className: "tooltip" }, "File Uploaded"))),
50
- handleDownload && handleReplace && (React.createElement(DropdownContainer, { ref: wrapperRef },
51
- React.createElement(ActionsIcon, { onClick: toggleOpen, type: "button", className: 'external_file_dropdown', "aria-label": "Download or Replace or Detach", "aria-pressed": isOpen },
52
- React.createElement(DotsIcon, null)),
53
- isOpen && (React.createElement(ItemActions, { fileSection: FileSectionType.Inline, replaceAttachmentHandler: handleReplace, showReplaceAction: true, handleUpdateInline: (uploadAttachment) => handleUpdateInline &&
54
- (attachment === null || attachment === void 0 ? void 0 : attachment.modelId) &&
55
- handleUpdateInline(attachment.modelId, uploadAttachment), detachAttachmnetHandler: () => handleDetachFile &&
56
- attachment.modelId &&
57
- handleDetachFile(attachment.id, attachment.modelId), downloadAttachmentHandler: handleDownload, attachmentId: attachment.id, fileName: attachment.name, publicUrl: attachment.link, hideActionList: toggleOpen, dispatch: dispatch, dropDownClassName: 'ref_item_dropdown' }))))));
56
+ const ElementFile = ({ file, handleReplace, handleDownload, handleDetach }) => {
57
+ return (React.createElement(ModelFileContainer, null,
58
+ React.createElement(FileName, { file: file }),
59
+ React.createElement(FileCreatedDate, { file: file, className: "show-on-hover" }),
60
+ React.createElement(FileActions, { sectionType: FileSectionType.Inline, handleDownload: file.id ? handleDownload : undefined, handleDetach: file.id ? handleDetach : undefined, handleReplace: handleReplace })));
58
61
  };
59
- export const FileDateContainer = styled.div `
60
- overflow: hidden;
61
- display: none;
62
- width: 100%;
63
- justify-content: flex-end;
64
- `;
65
- const ElementItem = styled(Item) `
62
+ const Element = styled.div `
66
63
  display: flex;
67
- // this will allow us to select the previous sibling node,
68
- // to change the background on the hover for adjacent node
69
- flex-direction: column-reverse;
64
+ flex-direction: column;
70
65
  padding: 0;
71
66
 
72
- :hover {
73
- background: #f2fbfc;
74
- }
75
-
76
- .refItems:hover ~ .element {
77
- background: white !important;
78
- }
79
- &:hover ${FileDateContainer} {
80
- display: flex;
81
- }
67
+ border-bottom: 1px dashed #f0f0f0;
82
68
 
83
- .refItems:hover {
84
- background: white !important;
69
+ svg {
70
+ width: 24px;
85
71
  }
86
72
 
87
- border-bottom: 1px dashed #f0f0f0;
88
-
89
73
  :last-child {
90
74
  border-bottom: 0;
91
75
  }
92
76
  `;
93
- const Container = styled.div `
77
+ const ElementLabelContainer = styled.div `
94
78
  display: flex;
95
- width: 100%;
79
+ padding: 20px 16px;
80
+ cursor: pointer;
96
81
  `;
97
- const Element = styled.div `
98
- display: flex;
99
- padding: 20px 15px;
100
- `;
101
- const FileReferences = styled.div `
102
- display: flex;
103
- align-items: center;
104
- justify-content: space-between;
105
- width: 100%;
82
+ const ElementLabel = styled.div `
83
+ color: ${(props) => props.theme.colors.text.primary};
84
+ font-weight: bold;
85
+ font-size: 16px;
86
+ line-height: 20px;
87
+ white-space: nowrap;
88
+ margin-left: ${(props) => props.theme.grid.unit * 2}px;
106
89
  `;
107
- const FileReferenceItem = styled.div `
108
- display: flex;
90
+ const ElementFilesContainer = styled.div `
109
91
  width: 100%;
110
- align-items: space;
111
- justify-content: space-between;
112
- width: 100% svg {
113
- width: 14px;
114
- height: 17px;
92
+ > :last-child {
93
+ margin-bottom: 25px;
115
94
  }
95
+ `;
96
+ const ModelFileContainer = styled(FileContainer) `
97
+ padding: 8px 16px;
98
+ height: 40px;
116
99
 
117
100
  path {
118
101
  fill: #6e6e6e;
119
102
  }
120
-
121
- padding: ${(props) => props.theme.grid.unit * 2}px
122
- ${(props) => props.theme.grid.unit * 4}px;
123
-
124
- :hover {
125
- background: #f2fbfc;
126
- }
127
-
128
- .external_file_dropdown {
129
- opacity: 0;
130
- }
131
- :hover .external_file_dropdown {
132
- opacity: 1;
133
- }
134
-
135
- .ref_item_dropdown {
136
- top: 65%;
137
- right: 10px;
138
- width: 180px;
139
- }
140
- :last-child {
141
- margin-bottom: 25px;
142
- }
143
- `;
144
- const FileReferenceName = styled.div `
145
- font-family: ${(props) => props.theme.font.family.Lato};
146
- font-size: ${(props) => props.theme.font.size.medium};
147
- line-height: ${(props) => props.theme.font.lineHeight.large};
148
- font-weight: ${(props) => props.theme.font.weight.normal};
149
- color: ${(props) => props.theme.colors.text.primary};
150
- margin-left: ${(props) => props.theme.grid.unit * 2}px;
151
- `;
152
- const DropdownContainer = styled.div `
153
- position: relative;
154
- `;
155
- export const FileDate = styled.div `
156
- font-size: ${(props) => props.theme.font.size.small};
157
- line-height: 27px;
158
103
  `;
@@ -0,0 +1,74 @@
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 { buildSupplementaryMaterial } from '@manuscripts/transform';
11
+ import React, { useContext, useEffect, useState } from 'react';
12
+ import { useDrag } from 'react-dnd';
13
+ import { getEmptyImage } from 'react-dnd-html5-backend';
14
+ import { FileActions } from './FileActions';
15
+ import { FileContainer } from './FileContainer';
16
+ import { FileCreatedDate } from './FileCreatedDate';
17
+ import { PermissionsContext } from './FileManager';
18
+ import { FileManagerContext } from './FileManagerProvider';
19
+ import { FileName } from './FileName';
20
+ import { FileSectionAlert, FileSectionAlertType } from './FileSectionAlert';
21
+ import { FileUploader } from './FileUploader';
22
+ import { FileSectionType } from './util';
23
+ export const OtherFilesSection = ({ files }) => {
24
+ const { fileManagement, saveModel } = useContext(FileManagerContext);
25
+ const can = useContext(PermissionsContext);
26
+ const [alert, setAlert] = useState({
27
+ type: FileSectionAlertType.NONE,
28
+ message: '',
29
+ });
30
+ const upload = (file) => __awaiter(void 0, void 0, void 0, function* () {
31
+ setAlert({
32
+ type: FileSectionAlertType.UPLOAD_IN_PROGRESS,
33
+ message: file.name,
34
+ });
35
+ yield fileManagement.upload(file);
36
+ setAlert({
37
+ type: FileSectionAlertType.UPLOAD_SUCCESSFUL,
38
+ message: '',
39
+ });
40
+ });
41
+ const moveToSupplements = (file) => __awaiter(void 0, void 0, void 0, function* () {
42
+ const supplement = buildSupplementaryMaterial('', file.id);
43
+ yield saveModel(supplement);
44
+ setAlert({
45
+ type: FileSectionAlertType.MOVE_SUCCESSFUL,
46
+ message: FileSectionType.Supplements,
47
+ });
48
+ });
49
+ return (React.createElement("div", null,
50
+ (can === null || can === void 0 ? void 0 : can.uploadFile) && React.createElement(FileUploader, { handler: upload }),
51
+ React.createElement(FileSectionAlert, { alert: alert }),
52
+ files.map((file) => (React.createElement(OtherFile, { key: file.id, file: file, handleDownload: () => fileManagement.download(file), handleMoveToSupplements: () => __awaiter(void 0, void 0, void 0, function* () { return yield moveToSupplements(file); }) })))));
53
+ };
54
+ const OtherFile = ({ file, handleDownload, handleMoveToSupplements }) => {
55
+ const [{ isDragging }, drag, preview] = useDrag({
56
+ item: {
57
+ file,
58
+ type: 'file',
59
+ },
60
+ collect: (monitor) => ({
61
+ isDragging: monitor.isDragging(),
62
+ }),
63
+ });
64
+ useEffect(() => {
65
+ preview(getEmptyImage());
66
+ }, [preview]);
67
+ return (React.createElement(FileContainer, { key: file.id, ref: drag, className: isDragging ? 'dragging' : '' },
68
+ React.createElement(FileName, { file: file }),
69
+ React.createElement(FileCreatedDate, { file: file, className: "show-on-hover" }),
70
+ React.createElement(FileActions, { sectionType: FileSectionType.OtherFile, handleDownload: handleDownload, move: {
71
+ sectionType: FileSectionType.Supplements,
72
+ handler: handleMoveToSupplements,
73
+ } })));
74
+ };
@@ -0,0 +1,91 @@
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 } from '@manuscripts/transform';
12
+ import React, { useContext, useEffect, useState } from 'react';
13
+ import { useDrag } from 'react-dnd';
14
+ import { getEmptyImage } from 'react-dnd-html5-backend';
15
+ import { FileActions } from './FileActions';
16
+ import { FileContainer } from './FileContainer';
17
+ import { FileCreatedDate } from './FileCreatedDate';
18
+ import { PermissionsContext } from './FileManager';
19
+ import { FileManagerContext } from './FileManagerProvider';
20
+ import { FileName } from './FileName';
21
+ import { FileSectionAlert, FileSectionAlertType } from './FileSectionAlert';
22
+ import { FileUploader } from './FileUploader';
23
+ import { FileSectionType } from './util';
24
+ export const SupplementsSection = ({ supplements }) => {
25
+ const { modelMap, saveModel, deleteModel, fileManagement } = useContext(FileManagerContext);
26
+ const can = useContext(PermissionsContext);
27
+ const [alert, setAlert] = useState({
28
+ type: FileSectionAlertType.NONE,
29
+ message: '',
30
+ });
31
+ const upload = (file) => __awaiter(void 0, void 0, void 0, function* () {
32
+ setAlert({
33
+ type: FileSectionAlertType.UPLOAD_IN_PROGRESS,
34
+ message: file.name,
35
+ });
36
+ const uploaded = yield fileManagement.upload(file);
37
+ setAlert({
38
+ type: FileSectionAlertType.UPLOAD_SUCCESSFUL,
39
+ message: '',
40
+ });
41
+ return uploaded;
42
+ });
43
+ const handleUpload = (file) => __awaiter(void 0, void 0, void 0, function* () {
44
+ const uploaded = yield upload(file);
45
+ const supplement = buildSupplementaryMaterial('', uploaded.id);
46
+ yield saveModel(supplement);
47
+ });
48
+ const handleReplace = (modelId, file) => __awaiter(void 0, void 0, void 0, function* () {
49
+ const uploaded = yield upload(file);
50
+ const supplement = modelMap.get(modelId);
51
+ yield saveModel(Object.assign(Object.assign({}, supplement), { href: uploaded.id }));
52
+ });
53
+ const handleMoveToOtherFiles = (modelId) => __awaiter(void 0, void 0, void 0, function* () {
54
+ yield deleteModel(modelId);
55
+ setAlert({
56
+ type: FileSectionAlertType.MOVE_SUCCESSFUL,
57
+ message: FileSectionType.OtherFile,
58
+ });
59
+ });
60
+ return (React.createElement(React.Fragment, null,
61
+ (can === null || can === void 0 ? void 0 : can.uploadFile) && React.createElement(FileUploader, { handler: handleUpload }),
62
+ React.createElement(FileSectionAlert, { alert: alert }),
63
+ supplements.map((supplement) => (React.createElement(SupplementFile, { key: supplement.modelId, file: supplement, handleDownload: () => fileManagement.download(supplement), handleReplace: (f) => __awaiter(void 0, void 0, void 0, function* () { return yield handleReplace(supplement.modelId, f); }), handleDetach: () => __awaiter(void 0, void 0, void 0, function* () { return yield handleMoveToOtherFiles(supplement.modelId); }) })))));
64
+ };
65
+ const SupplementFile = ({ file, handleDownload, handleReplace, handleDetach }) => {
66
+ const [{ isDragging }, drag, preview] = useDrag({
67
+ item: {
68
+ file,
69
+ model: {
70
+ _id: file.modelId,
71
+ objectType: ObjectTypes.Supplement,
72
+ },
73
+ type: 'file',
74
+ },
75
+ collect: (monitor) => ({
76
+ isDragging: monitor.isDragging(),
77
+ }),
78
+ });
79
+ useEffect(() => {
80
+ preview(getEmptyImage());
81
+ }, [preview]);
82
+ return (React.createElement(FileContainer, { key: file.id, ref: drag, className: isDragging ? 'dragging' : '' },
83
+ React.createElement(FileName, { file: file }),
84
+ React.createElement(FileCreatedDate, { file: file, className: "show-on-hover" }),
85
+ React.createElement(FileActions, { sectionType: FileSectionType.Supplements, handleDownload: file.id ? handleDownload : undefined, handleReplace: handleReplace, move: file.id
86
+ ? {
87
+ sectionType: FileSectionType.OtherFile,
88
+ handler: handleDetach,
89
+ }
90
+ : undefined })));
91
+ };
@@ -1,6 +1,7 @@
1
+ import ReactTooltip from 'react-tooltip';
1
2
  import styled from 'styled-components';
2
- export const TooltipDiv = styled.div `
3
- .tooltip {
3
+ export const Tooltip = styled(ReactTooltip) `
4
+ &.tooltip {
4
5
  font-size: 12px;
5
6
  line-height: 16px;
6
7
  font-family: ${(props) => props.theme.font.family.Lato};
@@ -11,5 +12,9 @@ export const TooltipDiv = styled.div `
11
12
  text-align: center;
12
13
  white-space: nowrap;
13
14
  pointer-events: none;
15
+
16
+ &.place-bottom::after {
17
+ background: #353535;
18
+ }
14
19
  }
15
20
  `;
@@ -13,9 +13,9 @@ import UnknownFormatFileIcon from '../icons/unknown-format-file-icon';
13
13
  import VideoIcon from '../icons/video-icon';
14
14
  export var FileSectionType;
15
15
  (function (FileSectionType) {
16
- FileSectionType[FileSectionType["Inline"] = 0] = "Inline";
17
- FileSectionType[FileSectionType["Supplements"] = 1] = "Supplements";
18
- FileSectionType[FileSectionType["OtherFile"] = 2] = "OtherFile";
16
+ FileSectionType["Inline"] = "Inline files";
17
+ FileSectionType["Supplements"] = "Supplements";
18
+ FileSectionType["OtherFile"] = "Other files";
19
19
  })(FileSectionType || (FileSectionType = {}));
20
20
  export var FileType;
21
21
  (function (FileType) {
@@ -32,7 +32,7 @@ export var FileType;
32
32
  FileType[FileType["Figure"] = 10] = "Figure";
33
33
  FileType[FileType["GraphicalAbstract"] = 11] = "GraphicalAbstract";
34
34
  })(FileType || (FileType = {}));
35
- export const extensionsWithFileTypesMap = new Map([
35
+ const extension2type = new Map([
36
36
  ['png', FileType.Image],
37
37
  ['jpg', FileType.Image],
38
38
  ['jpeg', FileType.Image],
@@ -68,78 +68,60 @@ export const extensionsWithFileTypesMap = new Map([
68
68
  ['tgz', FileType.CompressedFile],
69
69
  ['txt', FileType.PlainText],
70
70
  ]);
71
- export const fileTypesWithTitlesMap = new Map([
72
- [FileType.Image, 'Image'],
73
- [FileType.Audio, 'Audio'],
74
- [FileType.Video, 'Video'],
75
- [FileType.PlainDocument, 'Doc'],
76
- [FileType.SheetsWorkbooks, 'Table'],
77
- [FileType.Latex, 'Doc'],
78
- [FileType.CodeFile, 'Code File'],
79
- [FileType.PdfFile, 'Doc'],
80
- [FileType.CompressedFile, 'Compressed File'],
81
- [FileType.PlainText, 'Plain Text'],
82
- [undefined, 'Unknown'],
83
- ]);
84
- export const fileTypesWithIconMap = new Map([
85
- [FileType.Audio, React.createElement(AudioIcon, { key: FileType.Audio })],
86
- [FileType.Video, React.createElement(VideoIcon, { key: FileType.Video })],
71
+ const type2icon = new Map([
72
+ [FileType.Audio, React.createElement(AudioIcon, { key: FileType.Audio, className: "file-icon" })],
73
+ [FileType.Video, React.createElement(VideoIcon, { key: FileType.Video, className: "file-icon" })],
87
74
  [
88
75
  FileType.PlainDocument,
89
- React.createElement(DocumentIcon, { key: FileType.PlainDocument, color: "#1A9BC7" }),
76
+ React.createElement(DocumentIcon, { key: FileType.PlainDocument, color: "#1A9BC7", className: "file-icon" }),
77
+ ],
78
+ [
79
+ FileType.SheetsWorkbooks,
80
+ React.createElement(TableIcon, { key: FileType.SheetsWorkbooks, className: "file-icon" }),
81
+ ],
82
+ [
83
+ FileType.Latex,
84
+ React.createElement(LatexIcon, { key: FileType.Latex, color: "#1A9BC7", className: "file-icon" }),
85
+ ],
86
+ [
87
+ FileType.CodeFile,
88
+ React.createElement(CodeFileIcon, { key: FileType.CodeFile, className: "file-icon" }),
89
+ ],
90
+ [
91
+ FileType.PdfFile,
92
+ React.createElement(PdfFileIcon, { key: FileType.PdfFile, className: "file-icon" }),
90
93
  ],
91
- [FileType.SheetsWorkbooks, React.createElement(TableIcon, { key: FileType.SheetsWorkbooks })],
92
- [FileType.Latex, React.createElement(LatexIcon, { key: FileType.Latex, color: "#1A9BC7" })],
93
- [FileType.CodeFile, React.createElement(CodeFileIcon, { key: FileType.CodeFile })],
94
- [FileType.PdfFile, React.createElement(PdfFileIcon, { key: FileType.PdfFile })],
95
94
  [
96
95
  FileType.CompressedFile,
97
- React.createElement(CompressedFileIcon, { key: FileType.CompressedFile }),
96
+ React.createElement(CompressedFileIcon, { key: FileType.CompressedFile, className: "file-icon" }),
98
97
  ],
99
98
  [
100
99
  FileType.PlainText,
101
- React.createElement(DocumentIcon, { key: FileType.PlainText, color: "#FFBD26" }),
100
+ React.createElement(DocumentIcon, { key: FileType.PlainText, color: "#FFBD26", className: "file-icon" }),
102
101
  ],
103
- [FileType.Image, React.createElement(ImageIcon, { key: FileType.Image })],
104
- [FileType.Figure, React.createElement(FigureIcon, { key: FileType.Figure })],
102
+ [FileType.Image, React.createElement(ImageIcon, { key: FileType.Image, className: "file-icon" })],
103
+ [FileType.Figure, React.createElement(FigureIcon, { key: FileType.Figure, className: "file-icon" })],
105
104
  [
106
105
  FileType.GraphicalAbstract,
107
- React.createElement(GraphicalAbstractIcon, { key: FileType.GraphicalAbstract }),
106
+ React.createElement(GraphicalAbstractIcon, { key: FileType.GraphicalAbstract, className: "file-icon" }),
108
107
  ],
109
- [undefined, React.createElement(UnknownFormatFileIcon, { key: undefined })],
108
+ [undefined, React.createElement(UnknownFormatFileIcon, { key: undefined, className: "file-icon" })],
110
109
  ]);
111
- export const generateAttachmentsTitles = (externalFiles, fileSectionType) => {
112
- const titleCountersMap = new Map();
113
- const externalFilesWithTitlesMap = new Map();
114
- externalFiles.forEach((element) => {
115
- const fileExtension = element.name.substring(element.name.lastIndexOf('.') + 1);
116
- const fileType = extensionsWithFileTypesMap.get(fileExtension.toLowerCase());
117
- const fileTitle = fileTypesWithTitlesMap.get(fileType);
118
- if (fileSectionType === FileSectionType.Inline) {
119
- externalFilesWithTitlesMap.set(element.name, element);
120
- }
121
- else {
122
- if (fileTitle !== undefined) {
123
- const oldCount = titleCountersMap.get(fileTitle);
124
- if (oldCount) {
125
- const newCount = oldCount + 1;
126
- titleCountersMap.set(fileTitle, newCount);
127
- externalFilesWithTitlesMap.set(`${fileTitle} ${newCount}`, element);
128
- }
129
- else {
130
- titleCountersMap.set(fileTitle, 1);
131
- externalFilesWithTitlesMap.set(`${fileTitle} 1`, element);
132
- }
133
- }
134
- }
135
- });
136
- const result = Array.from(externalFilesWithTitlesMap, ([key, value]) => ({
137
- title: key,
138
- externalFile: value,
139
- }));
140
- return result;
110
+ export const getFileType = (file) => {
111
+ const extension = getExtension(file.name);
112
+ return extension2type.get(extension.toLowerCase());
113
+ };
114
+ export const getFileIcon = (file) => {
115
+ const type = getFileType(file);
116
+ return type2icon.get(type);
117
+ };
118
+ export const getFileTypeIcon = (type) => {
119
+ return type2icon.get(type);
120
+ };
121
+ export const isImageFile = (file) => {
122
+ return getFileType(file) === FileType.Image;
123
+ };
124
+ const getExtension = (name) => {
125
+ const index = name.indexOf('.');
126
+ return index ? name.substring(index + 1) : '';
141
127
  };
142
- export const droppableSections = [
143
- FileSectionType.Supplements,
144
- FileSectionType.OtherFile,
145
- ];