@manuscripts/style-guide 1.3.2-LEAN-2859-2 → 1.3.2-LEAN-2880-1

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 (102) hide show
  1. package/dist/cjs/components/FileManager/ConfirmationPopUp.js +90 -0
  2. package/dist/cjs/components/FileManager/DragItemArea.js +28 -0
  3. package/dist/cjs/components/FileManager/FileManager.js +125 -14
  4. package/dist/cjs/components/FileManager/FileManagerProvider.js +7 -2
  5. package/dist/cjs/components/FileManager/{DragLayer.js → FileSectionItem/DragLayer.js} +10 -12
  6. package/dist/cjs/components/FileManager/FileSectionItem/DraggableFileSectionItem.js +76 -0
  7. package/dist/cjs/components/FileManager/FileSectionItem/FileInfo.js +115 -0
  8. package/dist/cjs/components/FileManager/FileSectionItem/FileSectionItem.js +95 -0
  9. package/dist/cjs/components/FileManager/FileSectionItem/FileSectionUploadItem.js +37 -0
  10. package/dist/cjs/components/FileManager/FileSectionItem/FileTypeIcon.js +53 -0
  11. package/dist/cjs/components/FileManager/FileSectionItem/ItemActions.js +92 -0
  12. package/dist/cjs/components/FileManager/FileSectionItem/ProgressBarUploadItem.js +120 -0
  13. package/dist/cjs/components/FileManager/FileSectionState.js +83 -0
  14. package/dist/cjs/components/FileManager/FilesSection.js +61 -0
  15. package/dist/cjs/components/FileManager/InlineFilesSection.js +123 -64
  16. package/dist/cjs/components/FileManager/ItemsAction.js +48 -0
  17. package/dist/cjs/components/FileManager/{Tooltip.js → TooltipDiv.js} +3 -8
  18. package/dist/cjs/components/FileManager/{FileUploader.js → UploadFileArea.js} +12 -19
  19. package/dist/cjs/components/FileManager/util.js +67 -52
  20. package/dist/cjs/components/icons/document-icon-with-dot.js +1 -1
  21. package/dist/cjs/hooks/use-deep-compare.js +2 -2
  22. package/dist/cjs/hooks/use-files.js +43 -29
  23. package/dist/cjs/index.js +4 -3
  24. package/dist/cjs/lib/inlineFiles.js +92 -0
  25. package/dist/es/components/FileManager/ConfirmationPopUp.js +62 -0
  26. package/dist/es/components/FileManager/DragItemArea.js +21 -0
  27. package/dist/es/components/FileManager/FileManager.js +124 -16
  28. package/dist/es/components/FileManager/FileManagerProvider.js +8 -3
  29. package/dist/es/components/FileManager/{DragLayer.js → FileSectionItem/DragLayer.js} +10 -12
  30. package/dist/es/components/FileManager/FileSectionItem/DraggableFileSectionItem.js +46 -0
  31. package/dist/es/components/FileManager/FileSectionItem/FileInfo.js +85 -0
  32. package/dist/es/components/FileManager/FileSectionItem/FileSectionItem.js +88 -0
  33. package/dist/es/components/FileManager/FileSectionItem/FileSectionUploadItem.js +30 -0
  34. package/dist/es/components/FileManager/FileSectionItem/FileTypeIcon.js +46 -0
  35. package/dist/es/components/FileManager/FileSectionItem/ItemActions.js +65 -0
  36. package/dist/es/components/FileManager/FileSectionItem/ProgressBarUploadItem.js +113 -0
  37. package/dist/es/components/FileManager/FileSectionState.js +78 -0
  38. package/dist/es/components/FileManager/FilesSection.js +34 -0
  39. package/dist/es/components/FileManager/InlineFilesSection.js +124 -65
  40. package/dist/es/components/FileManager/ItemsAction.js +42 -0
  41. package/dist/es/components/FileManager/{Tooltip.js → TooltipDiv.js} +2 -7
  42. package/dist/es/components/FileManager/{FileUploader.js → UploadFileArea.js} +10 -17
  43. package/dist/es/components/FileManager/util.js +65 -47
  44. package/dist/es/components/icons/document-icon-with-dot.js +1 -1
  45. package/dist/es/hooks/use-deep-compare.js +2 -2
  46. package/dist/es/hooks/use-files.js +40 -29
  47. package/dist/es/index.js +2 -2
  48. package/dist/es/lib/inlineFiles.js +90 -0
  49. package/dist/types/components/FileManager/ConfirmationPopUp.d.ts +12 -0
  50. package/dist/types/components/FileManager/DragItemArea.d.ts +4 -0
  51. package/dist/types/components/FileManager/FileManager.d.ts +8 -17
  52. package/dist/types/components/FileManager/FileManagerProvider.d.ts +18 -8
  53. package/dist/types/components/FileManager/FileSectionItem/DraggableFileSectionItem.d.ts +3 -0
  54. package/dist/types/components/FileManager/FileSectionItem/FileInfo.d.ts +19 -0
  55. package/dist/types/components/FileManager/FileSectionItem/FileSectionItem.d.ts +38 -0
  56. package/dist/types/components/FileManager/FileSectionItem/FileSectionUploadItem.d.ts +12 -0
  57. package/dist/types/components/FileManager/{FileTypeIcon.d.ts → FileSectionItem/FileTypeIcon.d.ts} +3 -2
  58. package/dist/types/components/FileManager/FileSectionItem/ItemActions.d.ts +21 -0
  59. package/dist/types/components/FileManager/FileSectionItem/ProgressBarUploadItem.d.ts +4 -0
  60. package/dist/types/components/FileManager/FileSectionState.d.ts +38 -0
  61. package/dist/types/components/FileManager/FilesSection.d.ts +12 -0
  62. package/dist/types/components/FileManager/InlineFilesSection.d.ts +19 -3
  63. package/dist/types/components/FileManager/ItemsAction.d.ts +4 -0
  64. package/dist/types/components/FileManager/TooltipDiv.d.ts +1 -0
  65. package/dist/types/components/FileManager/UploadFileArea.d.ts +9 -0
  66. package/dist/types/components/FileManager/util.d.ts +12 -8
  67. package/dist/types/hooks/use-files.d.ts +6 -4
  68. package/dist/types/index.d.ts +2 -2
  69. package/dist/types/lib/inlineFiles.d.ts +11 -0
  70. package/package.json +2 -2
  71. package/dist/cjs/components/FileManager/FileActions.js +0 -135
  72. package/dist/cjs/components/FileManager/FileContainer.js +0 -38
  73. package/dist/cjs/components/FileManager/FileCreatedDate.js +0 -25
  74. package/dist/cjs/components/FileManager/FileName.js +0 -27
  75. package/dist/cjs/components/FileManager/FileSectionAlert.js +0 -170
  76. package/dist/cjs/components/FileManager/FileTypeIcon.js +0 -22
  77. package/dist/cjs/components/FileManager/OtherFilesSection.js +0 -101
  78. package/dist/cjs/components/FileManager/SupplementsSection.js +0 -118
  79. package/dist/cjs/components/icons/corrupted-file-icon.js +0 -27
  80. package/dist/cjs/lib/files.js +0 -85
  81. package/dist/es/components/FileManager/FileActions.js +0 -105
  82. package/dist/es/components/FileManager/FileContainer.js +0 -32
  83. package/dist/es/components/FileManager/FileCreatedDate.js +0 -18
  84. package/dist/es/components/FileManager/FileName.js +0 -20
  85. package/dist/es/components/FileManager/FileSectionAlert.js +0 -163
  86. package/dist/es/components/FileManager/FileTypeIcon.js +0 -15
  87. package/dist/es/components/FileManager/OtherFilesSection.js +0 -74
  88. package/dist/es/components/FileManager/SupplementsSection.js +0 -91
  89. package/dist/es/components/icons/corrupted-file-icon.js +0 -22
  90. package/dist/es/lib/files.js +0 -79
  91. package/dist/types/components/FileManager/FileActions.d.ts +0 -19
  92. package/dist/types/components/FileManager/FileContainer.d.ts +0 -1
  93. package/dist/types/components/FileManager/FileCreatedDate.d.ts +0 -8
  94. package/dist/types/components/FileManager/FileName.d.ts +0 -6
  95. package/dist/types/components/FileManager/FileSectionAlert.d.ts +0 -13
  96. package/dist/types/components/FileManager/FileUploader.d.ts +0 -4
  97. package/dist/types/components/FileManager/OtherFilesSection.d.ts +0 -5
  98. package/dist/types/components/FileManager/SupplementsSection.d.ts +0 -5
  99. package/dist/types/components/FileManager/Tooltip.d.ts +0 -2
  100. package/dist/types/components/icons/corrupted-file-icon.d.ts +0 -19
  101. package/dist/types/lib/files.d.ts +0 -24
  102. /package/dist/types/components/FileManager/{DragLayer.d.ts → FileSectionItem/DragLayer.d.ts} +0 -0
@@ -1,99 +1,158 @@
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';
1
+ import { format } from 'date-fns';
2
+ import React, { useCallback } from 'react';
3
+ import ReactTooltip from 'react-tooltip';
11
4
  import styled from 'styled-components';
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';
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';
18
11
  const trackedJoint = ':dataTracked:';
19
- export const InlineFilesSection = ({ elements, isEditor }) => {
20
- const { modelMap, fileManagement, saveModel } = useContext(FileManagerContext);
12
+ export const InlineFilesSection = ({ handleReplace, handleDownload, handleUpdateInline, handleDetachFile, inlineFiles, isEditor, dispatch, }) => {
21
13
  const onElementClick = useCallback((e) => {
22
14
  if (!isEditor) {
23
15
  return;
24
16
  }
25
17
  const { id } = e.currentTarget;
26
18
  const clearedId = id.split(trackedJoint)[0];
27
- const isSelected = clearedId == window.location.hash.substring(1);
19
+ const isSelected = clearedId == window.location.hash.substr(1);
28
20
  window.location.hash = !isSelected ? `#${clearedId}` : '#';
29
- }, [isEditor]);
30
- const updateFigureSrc = (modelId, src) => __awaiter(void 0, void 0, void 0, function* () {
31
- const figure = modelMap.get(modelId);
32
- if (figure) {
33
- yield saveModel(Object.assign(Object.assign({}, figure), { src: src }));
21
+ if (isSelected) {
22
+ window.location.hash = `#${clearedId}`;
34
23
  }
35
- });
36
- const detach = (modelId) => __awaiter(void 0, void 0, void 0, function* () {
37
- yield updateFigureSrc(modelId, '');
38
- });
39
- const replace = (modelId, file) => __awaiter(void 0, void 0, void 0, function* () {
40
- const uploaded = yield fileManagement.upload(file);
41
- yield updateFigureSrc(modelId, uploaded.id);
42
- });
43
- return (React.createElement(React.Fragment, null, elements.map((element, index) => {
24
+ }, [isEditor]);
25
+ return (React.createElement("div", null, inlineFiles.map((file, index) => {
44
26
  var _a;
45
- return (React.createElement(Element, { key: index, id: element.modelId, onClick: onElementClick },
46
- React.createElement(ElementLabelContainer, null,
47
- getFileTypeIcon(element.type),
48
- React.createElement(ElementLabel, null, element.label)),
49
- 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(file.modelId, f); }), handleDetach: () => __awaiter(void 0, void 0, void 0, function* () { return yield detach(file.modelId); }), handleDownload: () => fileManagement.download(file) }))))));
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))))));
50
35
  })));
51
36
  };
52
- const ElementFile = ({ file, handleReplace, handleDownload, handleDetach }) => {
53
- return (React.createElement(ModelFileContainer, null,
54
- React.createElement(FileName, { file: file }),
55
- React.createElement(FileCreatedDate, { file: file, className: "show-on-hover" }),
56
- React.createElement(FileActions, { sectionType: FileSectionType.Inline, handleDownload: file.id ? handleDownload : undefined, handleDetach: file.id ? handleDetach : undefined, handleReplace: handleReplace })));
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' }))))));
57
58
  };
58
- const Element = styled.div `
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) `
59
66
  display: flex;
60
- flex-direction: column;
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;
61
70
  padding: 0;
62
71
 
63
- border-bottom: 1px dashed #f0f0f0;
72
+ :hover {
73
+ background: #f2fbfc;
74
+ }
75
+
76
+ .refItems:hover ~ .element {
77
+ background: white !important;
78
+ }
79
+ &:hover ${FileDateContainer} {
80
+ display: flex;
81
+ }
64
82
 
65
- svg {
66
- width: 24px;
83
+ .refItems:hover {
84
+ background: white !important;
67
85
  }
68
86
 
87
+ border-bottom: 1px dashed #f0f0f0;
88
+
69
89
  :last-child {
70
90
  border-bottom: 0;
71
91
  }
72
92
  `;
73
- const ElementLabelContainer = styled.div `
93
+ const Container = styled.div `
74
94
  display: flex;
75
- padding: 20px 16px;
76
- cursor: pointer;
95
+ width: 100%;
77
96
  `;
78
- const ElementLabel = styled.div `
79
- color: ${(props) => props.theme.colors.text.primary};
80
- font-weight: bold;
81
- font-size: 16px;
82
- line-height: 20px;
83
- white-space: nowrap;
84
- margin-left: ${(props) => props.theme.grid.unit * 2}px;
97
+ const Element = styled.div `
98
+ display: flex;
99
+ padding: 20px 15px;
85
100
  `;
86
- const ElementFilesContainer = styled.div `
101
+ const FileReferences = styled.div `
102
+ display: flex;
103
+ align-items: center;
104
+ justify-content: space-between;
87
105
  width: 100%;
88
- > :last-child {
89
- margin-bottom: 25px;
90
- }
91
106
  `;
92
- const ModelFileContainer = styled(FileContainer) `
93
- padding: 8px 16px;
94
- height: 40px;
107
+ const FileReferenceItem = styled.div `
108
+ display: flex;
109
+ width: 100%;
110
+ align-items: space;
111
+ justify-content: space-between;
112
+ width: 100% svg {
113
+ width: 14px;
114
+ height: 17px;
115
+ }
95
116
 
96
117
  path {
97
118
  fill: #6e6e6e;
98
119
  }
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;
99
158
  `;
@@ -0,0 +1,42 @@
1
+ import styled from 'styled-components';
2
+ export const ActionsBox = styled.ul `
3
+ border: 1px solid #e2e2e2;
4
+ box-sizing: border-box;
5
+ box-shadow: 0px 4px 9px rgba(0, 0, 0, 0.3);
6
+ border-radius: 4px;
7
+ min-width: 180px;
8
+ background: ${(props) => props.theme.colors.background.primary};
9
+ margin: 0;
10
+ padding: 8px 0;
11
+ z-index: 999;
12
+ text-align: left;
13
+ list-style-type: none;
14
+ `;
15
+ export const ActionsItem = styled.li `
16
+ font-family: ${(props) => props.theme.font.family.Lato};
17
+ cursor: pointer;
18
+ font-size: 16px;
19
+ line-height: 24px;
20
+ color: ${(props) => props.theme.colors.text.primary};
21
+ list-style: none;
22
+ padding: 8px 16px;
23
+ &:hover,
24
+ &:focus {
25
+ background: #f2fbfc;
26
+ }
27
+ `;
28
+ export const ActionsLabel = styled.li `
29
+ font-family: ${(props) => props.theme.font.family.Lato};
30
+ font-size: 12px;
31
+ line-height: 16px;
32
+ color: ${(props) => props.theme.colors.text.onLight};
33
+ list-style: none;
34
+ padding: 8px 16px;
35
+ cursor: default;
36
+ `;
37
+ export const ActionsSeparator = styled.li `
38
+ height: 1px;
39
+ background: ${(props) => props.theme.colors.background.tertiary};
40
+ margin: 8px 0;
41
+ cursor: default;
42
+ `;
@@ -1,7 +1,6 @@
1
- import ReactTooltip from 'react-tooltip';
2
1
  import styled from 'styled-components';
3
- export const Tooltip = styled(ReactTooltip) `
4
- &.tooltip {
2
+ export const TooltipDiv = styled.div `
3
+ .tooltip {
5
4
  font-size: 12px;
6
5
  line-height: 16px;
7
6
  font-family: ${(props) => props.theme.font.family.Lato};
@@ -12,9 +11,5 @@ export const Tooltip = styled(ReactTooltip) `
12
11
  text-align: center;
13
12
  white-space: nowrap;
14
13
  pointer-events: none;
15
-
16
- &.place-bottom::after {
17
- background: #353535;
18
- }
19
14
  }
20
15
  `;
@@ -1,35 +1,27 @@
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
1
  import React, { useCallback, useRef } from 'react';
11
2
  import { useDrop } from 'react-dnd';
12
3
  import { NativeTypes } from 'react-dnd-html5-backend';
13
4
  import styled, { css } from 'styled-components';
14
- export const FileUploader = ({ handler }) => {
5
+ import { actions } from './FileSectionState';
6
+ export const UploadFileArea = ({ fileSection, dispatch }) => {
15
7
  const fileInputRef = useRef(null);
16
8
  const openFileDialog = () => {
17
9
  if (fileInputRef && fileInputRef.current) {
18
10
  fileInputRef.current.click();
19
11
  }
20
12
  };
21
- const handleChange = (event) => __awaiter(void 0, void 0, void 0, function* () {
13
+ const handleChange = (event) => {
22
14
  if (event && event.target && event.target.files) {
23
15
  const file = event.target.files[0];
24
- yield handler(file);
16
+ dispatch(actions.UPLOAD_FILE(file, fileSection));
25
17
  }
26
- });
27
- const handleFileDrop = useCallback((monitor) => __awaiter(void 0, void 0, void 0, function* () {
18
+ };
19
+ const handleFileDrop = useCallback((monitor) => {
28
20
  if (monitor) {
29
21
  const file = monitor.getItem().files[0];
30
- yield handler(file);
22
+ dispatch(actions.UPLOAD_FILE(file, fileSection));
31
23
  }
32
- }), [handler]);
24
+ }, [dispatch, fileSection]);
33
25
  const [{ canDrop, isOver }, dropRef] = useDrop({
34
26
  accept: [NativeTypes.FILE],
35
27
  drop(item, monitor) {
@@ -63,7 +55,8 @@ const Container = styled.div `
63
55
  font-family: ${(props) => props.theme.font.family.Lato};
64
56
  color: ${(props) => props.theme.colors.text.onLight};
65
57
  cursor: pointer;
66
- margin: 16px 16px 8px;
58
+ margin-bottom: 7px;
59
+ margin-top: 16px;
67
60
  ${(props) => props.active
68
61
  ? css `
69
62
  ${activeBoxStyle}
@@ -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["Inline"] = "Inline files";
17
- FileSectionType["Supplements"] = "Supplements";
18
- FileSectionType["OtherFile"] = "Other files";
16
+ FileSectionType[FileSectionType["Inline"] = 0] = "Inline";
17
+ FileSectionType[FileSectionType["Supplements"] = 1] = "Supplements";
18
+ FileSectionType[FileSectionType["OtherFile"] = 2] = "OtherFile";
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
- const extension2type = new Map([
35
+ export const extensionsWithFileTypesMap = new Map([
36
36
  ['png', FileType.Image],
37
37
  ['jpg', FileType.Image],
38
38
  ['jpeg', FileType.Image],
@@ -68,60 +68,78 @@ const extension2type = new Map([
68
68
  ['tgz', FileType.CompressedFile],
69
69
  ['txt', FileType.PlainText],
70
70
  ]);
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" })],
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 })],
74
87
  [
75
88
  FileType.PlainDocument,
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" }),
89
+ React.createElement(DocumentIcon, { key: FileType.PlainDocument, color: "#1A9BC7" }),
93
90
  ],
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 })],
94
95
  [
95
96
  FileType.CompressedFile,
96
- React.createElement(CompressedFileIcon, { key: FileType.CompressedFile, className: "file-icon" }),
97
+ React.createElement(CompressedFileIcon, { key: FileType.CompressedFile }),
97
98
  ],
98
99
  [
99
100
  FileType.PlainText,
100
- React.createElement(DocumentIcon, { key: FileType.PlainText, color: "#FFBD26", className: "file-icon" }),
101
+ React.createElement(DocumentIcon, { key: FileType.PlainText, color: "#FFBD26" }),
101
102
  ],
102
- [FileType.Image, React.createElement(ImageIcon, { key: FileType.Image, className: "file-icon" })],
103
- [FileType.Figure, React.createElement(FigureIcon, { key: FileType.Figure, className: "file-icon" })],
103
+ [FileType.Image, React.createElement(ImageIcon, { key: FileType.Image })],
104
+ [FileType.Figure, React.createElement(FigureIcon, { key: FileType.Figure })],
104
105
  [
105
106
  FileType.GraphicalAbstract,
106
- React.createElement(GraphicalAbstractIcon, { key: FileType.GraphicalAbstract, className: "file-icon" }),
107
+ React.createElement(GraphicalAbstractIcon, { key: FileType.GraphicalAbstract }),
107
108
  ],
108
- [undefined, React.createElement(UnknownFormatFileIcon, { key: undefined, className: "file-icon" })],
109
+ [undefined, React.createElement(UnknownFormatFileIcon, { key: undefined })],
109
110
  ]);
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) : '';
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;
127
141
  };
142
+ export const droppableSections = [
143
+ FileSectionType.Supplements,
144
+ FileSectionType.OtherFile,
145
+ ];
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import React from 'react';
17
- const DocumentIconWithDot = (props) => (React.createElement("svg", { className: props.className, width: "28", height: "33", style: { marginLeft: -7, marginTop: -4 }, viewBox: "0 0 28 33", fill: "none", xmlns: "http://www.w3.org/2000/svg", "data-for": "dot", "data-tip": true },
17
+ const DocumentIconWithDot = (props) => (React.createElement("svg", { width: "28", height: "33", viewBox: "0 0 28 33", fill: "none", xmlns: "http://www.w3.org/2000/svg", "data-for": "dot", "data-tip": true },
18
18
  React.createElement("rect", { x: "9", y: "9.71973", width: "18", height: "22", rx: "2", stroke: "#1A9BC7", strokeWidth: "2" }),
19
19
  React.createElement("rect", { x: "13.167", y: "14.0771", width: "5.66667", height: "1.14286", rx: "0.5", fill: "#1A9BC7", stroke: "#1A9BC7" }),
20
20
  React.createElement("rect", { x: "13.167", y: "19.791", width: "9.66667", height: "1.14286", rx: "0.5", fill: "#1A9BC7", stroke: "#1A9BC7" }),
@@ -22,5 +22,5 @@ const useDeepCompare = (deps) => {
22
22
  }
23
23
  return ref.current;
24
24
  };
25
- export const useDeepCompareMemo = (callback, deps) => useMemo(callback, [useDeepCompare(deps)]);
26
- export const useDeepCompareCallback = (callback, deps) => useCallback(callback, [useDeepCompare(deps)]);
25
+ export const useDeepCompareMemo = (callback, deps) => useMemo(callback, [useDeepCompare(deps), callback]);
26
+ export const useDeepCompareCallback = (callback, deps) => useCallback(callback, [useDeepCompare(deps), callback]);
@@ -1,35 +1,46 @@
1
1
  import { ObjectTypes } from '@manuscripts/json-schema';
2
- import { getInlineFiles, getSupplements, } from '../lib/files';
2
+ import { getModelsByType } from '@manuscripts/transform';
3
+ import getInlineFiles from '../lib/inlineFiles';
3
4
  import { useDeepCompareMemo } from './use-deep-compare';
4
- const types = [
5
- ObjectTypes.Section,
6
- ObjectTypes.FigureElement,
7
- ObjectTypes.Figure,
8
- ObjectTypes.Supplement,
9
- ObjectTypes.ElementsOrder,
10
- ];
11
- const getOtherFiles = (inlineFiles, supplements, files) => {
12
- const excluded = new Set();
13
- inlineFiles.flatMap((f) => f.files).forEach((f) => excluded.add(f.id));
14
- supplements.forEach((s) => excluded.add(s.id));
15
- return files.filter((f) => !excluded.has(f.id));
5
+ const getInlineFilesIds = (inlineFiles) => {
6
+ return inlineFiles
7
+ .map(({ attachments }) => (attachments === null || attachments === void 0 ? void 0 : attachments.map(({ id }) => ({ id }))) || [])
8
+ .flat();
16
9
  };
17
- export const useFiles = (modelMap, files) => {
18
- const models = [];
19
- for (const [_, model] of modelMap.entries()) {
20
- if (types.includes(model.objectType)) {
21
- models.push(model);
10
+ const getSupplementFiles = (modelMap, inlineFiles, attachments, filePredicate) => {
11
+ const supplements = new Map(getModelsByType(modelMap, ObjectTypes.Supplement).map((supplement) => { var _a; return [(_a = supplement.href) === null || _a === void 0 ? void 0 : _a.replace('attachment:', ''), supplement]; }));
12
+ const excludedAttachmentsIds = new Set(getInlineFilesIds(inlineFiles).map(({ id }) => id));
13
+ return attachments.filter((attachment) => {
14
+ if (supplements.has(attachment.id) && filePredicate) {
15
+ return (!excludedAttachmentsIds.has(attachment.id) &&
16
+ filePredicate(attachment.name));
22
17
  }
23
- }
24
- return useDeepCompareMemo(() => {
25
- const inlineFiles = getInlineFiles(modelMap, files);
26
- const supplements = getSupplements(modelMap, files);
27
- const otherFiles = getOtherFiles(inlineFiles, supplements, files);
28
- return {
29
- inlineFiles,
30
- supplements,
31
- otherFiles,
32
- };
33
- }, [models, files]);
18
+ else {
19
+ return (!excludedAttachmentsIds.has(attachment.id) &&
20
+ supplements.has(attachment.id));
21
+ }
22
+ });
23
+ };
24
+ const getOtherFiles = (inlineFiles, supplementFiles, attachments, filePredicate) => {
25
+ const inlineFilesAttachmentIds = getInlineFilesIds(inlineFiles);
26
+ const excludedAttachmentsIds = new Set([...inlineFilesAttachmentIds, ...supplementFiles].map(({ id }) => id));
27
+ return attachments.filter(({ id, name }) => {
28
+ if (!excludedAttachmentsIds.has(id) && filePredicate) {
29
+ return filePredicate(name);
30
+ }
31
+ else {
32
+ return !excludedAttachmentsIds.has(id);
33
+ }
34
+ });
34
35
  };
36
+ export const useFiles = (modelMap, attachments, filePredicate) => useDeepCompareMemo(() => {
37
+ const inlineFiles = getInlineFiles(modelMap, attachments);
38
+ const supplementFiles = getSupplementFiles(modelMap, inlineFiles, attachments, filePredicate);
39
+ const otherFiles = getOtherFiles(inlineFiles, supplementFiles, attachments, filePredicate);
40
+ return {
41
+ otherFiles,
42
+ supplementFiles,
43
+ inlineFiles,
44
+ };
45
+ }, [...Array.from(modelMap.values()), ...attachments]);
35
46
  export default useFiles;
package/dist/es/index.js CHANGED
@@ -31,6 +31,7 @@ export * from './components/Checkbox';
31
31
  export * from './components/Form';
32
32
  export * from './components/FileManager';
33
33
  export * from './components/FileManager/util';
34
+ export * from './components/FileManager/FileSectionItem/FileSectionItem';
34
35
  export * from './components/Resizer';
35
36
  export * from './components/SaveStatus';
36
37
  export * from './components/SimpleModal';
@@ -48,11 +49,10 @@ export * from './components/NavDropdown';
48
49
  export * from './components/SubmissionInspector';
49
50
  export * from './components/Dropdown';
50
51
  export * from './hooks/use-dropdown';
51
- export * from './hooks/use-files';
52
+ export { useFiles } from './hooks/use-files';
52
53
  export { useDeepCompareMemo, useDeepCompareCallback, } from './hooks/use-deep-compare';
53
54
  export * from './lib/authors';
54
55
  export * from './lib/capabilities';
55
- export * from './lib/files';
56
56
  export { default as errorsDecoder } from './lib/errors-decoder';
57
57
  export * from './types';
58
58
  export * from './components/LoadingOverlay';