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

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/{FileSectionItem/DragLayer.js → DragLayer.js} +12 -10
  2. package/dist/cjs/components/FileManager/FileActions.js +134 -0
  3. package/dist/cjs/components/FileManager/FileContainer.js +39 -0
  4. package/dist/cjs/components/FileManager/FileCreatedDate.js +25 -0
  5. package/dist/cjs/components/FileManager/FileManager.js +14 -125
  6. package/dist/cjs/components/FileManager/FileManagerProvider.js +2 -7
  7. package/dist/cjs/components/FileManager/FileName.js +27 -0
  8. package/dist/cjs/components/FileManager/FileSectionAlert.js +170 -0
  9. package/dist/cjs/components/FileManager/FileTypeIcon.js +22 -0
  10. package/dist/cjs/components/FileManager/{UploadFileArea.js → FileUploader.js} +19 -12
  11. package/dist/cjs/components/FileManager/InlineFilesSection.js +71 -126
  12. package/dist/cjs/components/FileManager/OtherFilesSection.js +101 -0
  13. package/dist/cjs/components/FileManager/SupplementsSection.js +118 -0
  14. package/dist/cjs/components/FileManager/{TooltipDiv.js → Tooltip.js} +8 -3
  15. package/dist/cjs/components/FileManager/util.js +52 -67
  16. package/dist/cjs/components/icons/corrupted-file-icon.js +27 -0
  17. package/dist/cjs/components/icons/document-icon-with-dot.js +1 -1
  18. package/dist/cjs/hooks/use-deep-compare.js +2 -2
  19. package/dist/cjs/hooks/use-files.js +29 -43
  20. package/dist/cjs/index.js +3 -4
  21. package/dist/cjs/lib/files.js +85 -0
  22. package/dist/es/components/FileManager/{FileSectionItem/DragLayer.js → DragLayer.js} +12 -10
  23. package/dist/es/components/FileManager/FileActions.js +104 -0
  24. package/dist/es/components/FileManager/FileContainer.js +33 -0
  25. package/dist/es/components/FileManager/FileCreatedDate.js +18 -0
  26. package/dist/es/components/FileManager/FileManager.js +16 -124
  27. package/dist/es/components/FileManager/FileManagerProvider.js +3 -8
  28. package/dist/es/components/FileManager/FileName.js +20 -0
  29. package/dist/es/components/FileManager/FileSectionAlert.js +163 -0
  30. package/dist/es/components/FileManager/FileTypeIcon.js +15 -0
  31. package/dist/es/components/FileManager/{UploadFileArea.js → FileUploader.js} +17 -10
  32. package/dist/es/components/FileManager/InlineFilesSection.js +72 -127
  33. package/dist/es/components/FileManager/OtherFilesSection.js +74 -0
  34. package/dist/es/components/FileManager/SupplementsSection.js +91 -0
  35. package/dist/es/components/FileManager/{TooltipDiv.js → Tooltip.js} +7 -2
  36. package/dist/es/components/FileManager/util.js +47 -65
  37. package/dist/es/components/icons/corrupted-file-icon.js +22 -0
  38. package/dist/es/components/icons/document-icon-with-dot.js +1 -1
  39. package/dist/es/hooks/use-deep-compare.js +2 -2
  40. package/dist/es/hooks/use-files.js +29 -40
  41. package/dist/es/index.js +2 -2
  42. package/dist/es/lib/files.js +79 -0
  43. package/dist/types/components/FileManager/FileActions.d.ts +19 -0
  44. package/dist/types/components/FileManager/FileContainer.d.ts +1 -0
  45. package/dist/types/components/FileManager/FileCreatedDate.d.ts +8 -0
  46. package/dist/types/components/FileManager/FileManager.d.ts +17 -8
  47. package/dist/types/components/FileManager/FileManagerProvider.d.ts +8 -18
  48. package/dist/types/components/FileManager/FileName.d.ts +6 -0
  49. package/dist/types/components/FileManager/FileSectionAlert.d.ts +13 -0
  50. package/dist/types/components/FileManager/{FileSectionItem/FileTypeIcon.d.ts → FileTypeIcon.d.ts} +2 -3
  51. package/dist/types/components/FileManager/FileUploader.d.ts +4 -0
  52. package/dist/types/components/FileManager/InlineFilesSection.d.ts +3 -19
  53. package/dist/types/components/FileManager/OtherFilesSection.d.ts +5 -0
  54. package/dist/types/components/FileManager/SupplementsSection.d.ts +5 -0
  55. package/dist/types/components/FileManager/Tooltip.d.ts +2 -0
  56. package/dist/types/components/FileManager/util.d.ts +8 -12
  57. package/dist/types/components/icons/corrupted-file-icon.d.ts +19 -0
  58. package/dist/types/hooks/use-files.d.ts +4 -6
  59. package/dist/types/index.d.ts +2 -2
  60. package/dist/types/lib/files.d.ts +24 -0
  61. package/package.json +2 -2
  62. package/dist/cjs/components/FileManager/ConfirmationPopUp.js +0 -90
  63. package/dist/cjs/components/FileManager/DragItemArea.js +0 -28
  64. package/dist/cjs/components/FileManager/FileSectionItem/DraggableFileSectionItem.js +0 -76
  65. package/dist/cjs/components/FileManager/FileSectionItem/FileInfo.js +0 -115
  66. package/dist/cjs/components/FileManager/FileSectionItem/FileSectionItem.js +0 -95
  67. package/dist/cjs/components/FileManager/FileSectionItem/FileSectionUploadItem.js +0 -37
  68. package/dist/cjs/components/FileManager/FileSectionItem/FileTypeIcon.js +0 -53
  69. package/dist/cjs/components/FileManager/FileSectionItem/ItemActions.js +0 -92
  70. package/dist/cjs/components/FileManager/FileSectionItem/ProgressBarUploadItem.js +0 -120
  71. package/dist/cjs/components/FileManager/FileSectionState.js +0 -83
  72. package/dist/cjs/components/FileManager/FilesSection.js +0 -61
  73. package/dist/cjs/components/FileManager/ItemsAction.js +0 -48
  74. package/dist/cjs/lib/inlineFiles.js +0 -92
  75. package/dist/es/components/FileManager/ConfirmationPopUp.js +0 -62
  76. package/dist/es/components/FileManager/DragItemArea.js +0 -21
  77. package/dist/es/components/FileManager/FileSectionItem/DraggableFileSectionItem.js +0 -46
  78. package/dist/es/components/FileManager/FileSectionItem/FileInfo.js +0 -85
  79. package/dist/es/components/FileManager/FileSectionItem/FileSectionItem.js +0 -88
  80. package/dist/es/components/FileManager/FileSectionItem/FileSectionUploadItem.js +0 -30
  81. package/dist/es/components/FileManager/FileSectionItem/FileTypeIcon.js +0 -46
  82. package/dist/es/components/FileManager/FileSectionItem/ItemActions.js +0 -65
  83. package/dist/es/components/FileManager/FileSectionItem/ProgressBarUploadItem.js +0 -113
  84. package/dist/es/components/FileManager/FileSectionState.js +0 -78
  85. package/dist/es/components/FileManager/FilesSection.js +0 -34
  86. package/dist/es/components/FileManager/ItemsAction.js +0 -42
  87. package/dist/es/lib/inlineFiles.js +0 -90
  88. package/dist/types/components/FileManager/ConfirmationPopUp.d.ts +0 -12
  89. package/dist/types/components/FileManager/DragItemArea.d.ts +0 -4
  90. package/dist/types/components/FileManager/FileSectionItem/DraggableFileSectionItem.d.ts +0 -3
  91. package/dist/types/components/FileManager/FileSectionItem/FileInfo.d.ts +0 -19
  92. package/dist/types/components/FileManager/FileSectionItem/FileSectionItem.d.ts +0 -38
  93. package/dist/types/components/FileManager/FileSectionItem/FileSectionUploadItem.d.ts +0 -12
  94. package/dist/types/components/FileManager/FileSectionItem/ItemActions.d.ts +0 -21
  95. package/dist/types/components/FileManager/FileSectionItem/ProgressBarUploadItem.d.ts +0 -4
  96. package/dist/types/components/FileManager/FileSectionState.d.ts +0 -38
  97. package/dist/types/components/FileManager/FilesSection.d.ts +0 -12
  98. package/dist/types/components/FileManager/ItemsAction.d.ts +0 -4
  99. package/dist/types/components/FileManager/TooltipDiv.d.ts +0 -1
  100. package/dist/types/components/FileManager/UploadFileArea.d.ts +0 -9
  101. package/dist/types/lib/inlineFiles.d.ts +0 -11
  102. /package/dist/types/components/FileManager/{FileSectionItem/DragLayer.d.ts → DragLayer.d.ts} +0 -0
@@ -1,46 +1,35 @@
1
1
  import { ObjectTypes } from '@manuscripts/json-schema';
2
- import { getModelsByType } from '@manuscripts/transform';
3
- import getInlineFiles from '../lib/inlineFiles';
2
+ import { getInlineFiles, getSupplements, } from '../lib/files';
4
3
  import { useDeepCompareMemo } from './use-deep-compare';
5
- const getInlineFilesIds = (inlineFiles) => {
6
- return inlineFiles
7
- .map(({ attachments }) => (attachments === null || attachments === void 0 ? void 0 : attachments.map(({ id }) => ({ id }))) || [])
8
- .flat();
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));
9
16
  };
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));
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);
17
22
  }
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
- });
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]);
35
34
  };
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]);
46
35
  export default useFiles;
package/dist/es/index.js CHANGED
@@ -31,7 +31,6 @@ 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';
35
34
  export * from './components/Resizer';
36
35
  export * from './components/SaveStatus';
37
36
  export * from './components/SimpleModal';
@@ -49,10 +48,11 @@ export * from './components/NavDropdown';
49
48
  export * from './components/SubmissionInspector';
50
49
  export * from './components/Dropdown';
51
50
  export * from './hooks/use-dropdown';
52
- export { useFiles } from './hooks/use-files';
51
+ export * from './hooks/use-files';
53
52
  export { useDeepCompareMemo, useDeepCompareCallback, } from './hooks/use-deep-compare';
54
53
  export * from './lib/authors';
55
54
  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';
@@ -0,0 +1,79 @@
1
+ import { ObjectTypes, } from '@manuscripts/json-schema';
2
+ import { getModelsByType } from '@manuscripts/transform';
3
+ import { FileType } from '../components/FileManager/util';
4
+ export const isModelFile = (file) => {
5
+ return file.modelId;
6
+ };
7
+ const MISSING_FILE = {
8
+ id: '',
9
+ name: 'Missing file',
10
+ type: {
11
+ id: 'missing',
12
+ },
13
+ };
14
+ const getFile = (files, id) => {
15
+ return files.filter((f) => f.id === id)[0] || MISSING_FILE;
16
+ };
17
+ const getFigureFiles = (element, modelMap, files) => {
18
+ const figureFiles = [];
19
+ element.containedObjectIDs.map((id) => {
20
+ const model = modelMap.get(id);
21
+ if (model && model.objectType === ObjectTypes.Figure) {
22
+ const figure = model;
23
+ if (figure.src) {
24
+ figureFiles.push(Object.assign(Object.assign({}, getFile(files, figure.src)), { modelId: figure._id }));
25
+ }
26
+ }
27
+ });
28
+ return figureFiles;
29
+ };
30
+ const getSupplementFiles = (supplement, files) => {
31
+ if (supplement.href) {
32
+ const href = supplement.href;
33
+ if (href) {
34
+ return [
35
+ Object.assign(Object.assign({}, getFile(files, href)), { modelId: supplement._id }),
36
+ ];
37
+ }
38
+ }
39
+ return [];
40
+ };
41
+ export const getInlineFiles = (modelMap, files) => {
42
+ var _a;
43
+ const elements = [];
44
+ const orders = getOrderByType(modelMap);
45
+ const sections = getModelsByType(modelMap, ObjectTypes.Section);
46
+ const graphicalAbstractElementIds = (_a = sections.filter((s) => s.category === 'MPSectionCategory:abstract-graphical')[0]) === null || _a === void 0 ? void 0 : _a.elementIDs;
47
+ graphicalAbstractElementIds === null || graphicalAbstractElementIds === void 0 ? void 0 : graphicalAbstractElementIds.map((id) => {
48
+ const figure = modelMap.get(id);
49
+ if (figure) {
50
+ elements.push({
51
+ modelId: id,
52
+ type: FileType.GraphicalAbstract,
53
+ label: 'Graphical Abstract',
54
+ files: getFigureFiles(figure, modelMap, files),
55
+ });
56
+ }
57
+ });
58
+ const figures = getModelsByType(modelMap, ObjectTypes.FigureElement);
59
+ const figureOrder = orders.get(ObjectTypes.FigureElement);
60
+ if (figureOrder) {
61
+ }
62
+ figures === null || figures === void 0 ? void 0 : figures.filter((f) => !(graphicalAbstractElementIds === null || graphicalAbstractElementIds === void 0 ? void 0 : graphicalAbstractElementIds.includes(f._id))).map((figure, index) => ({
63
+ modelId: figure._id,
64
+ type: FileType.Figure,
65
+ label: `Figure ${index + 1}`,
66
+ files: getFigureFiles(figure, modelMap, files),
67
+ })).forEach((e) => elements.push(e));
68
+ return elements;
69
+ };
70
+ export const getSupplements = (modelMap, files) => {
71
+ const supplements = getModelsByType(modelMap, ObjectTypes.Supplement);
72
+ return supplements.flatMap((s) => getSupplementFiles(s, files));
73
+ };
74
+ const getOrderByType = (modelMap) => {
75
+ const groups = new Map();
76
+ const orders = getModelsByType(modelMap, ObjectTypes.ElementsOrder);
77
+ orders.forEach((o) => groups.set(o.elementType, o));
78
+ return groups;
79
+ };
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { Move, Replace } from './FileManager';
3
+ import { FileSectionType } from './util';
4
+ export declare const FileActions: React.FC<{
5
+ sectionType: FileSectionType;
6
+ handleDownload?: () => void;
7
+ handleReplace?: Replace;
8
+ handleDetach?: () => void;
9
+ move?: Move;
10
+ className?: string;
11
+ }>;
12
+ export declare const ActionsIcon: import("styled-components").StyledComponent<"button", import("styled-components").DefaultTheme, {}, never>;
13
+ export declare const FileActionDropdownList: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {
14
+ direction?: "left" | "right" | undefined;
15
+ width?: number | undefined;
16
+ height?: number | undefined;
17
+ top?: number | undefined;
18
+ }, never>;
19
+ export declare const FileAction: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
@@ -0,0 +1 @@
1
+ export declare const FileContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { FileAttachment } from '../../lib/files';
3
+ export declare const FileCreatedDate: React.FC<{
4
+ file: FileAttachment;
5
+ className?: string;
6
+ }>;
7
+ export declare const FileDateContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
8
+ export declare const FileDate: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
@@ -1,22 +1,31 @@
1
1
  import { Model } from '@manuscripts/json-schema';
2
2
  import { Build } from '@manuscripts/transform';
3
3
  import React from 'react';
4
+ import { FileSectionType } from '../../index';
4
5
  import { Capabilities } from '../../lib/capabilities';
5
- import { FileAttachment } from './FileSectionItem/FileSectionItem';
6
- export type Upload = (file: File) => Promise<boolean | FileAttachment | undefined>;
7
- export type Replace = (attachmentId: string, name: string, file: File) => Promise<boolean | FileAttachment | undefined>;
6
+ import { FileAttachment } from '../../lib/files';
7
+ export type Upload = (file: File) => Promise<FileAttachment>;
8
+ export type Download = (file: FileAttachment) => void;
9
+ export type PreviewLink = (file: FileAttachment) => string | undefined;
10
+ export type Replace = (file: File) => Promise<void>;
11
+ export type Move = {
12
+ sectionType: FileSectionType;
13
+ handler: () => Promise<void>;
14
+ };
8
15
  export interface FileManagement {
9
- getAttachments: () => FileAttachment[];
10
16
  upload: Upload;
11
- replace: Replace;
17
+ download: Download;
18
+ previewLink: PreviewLink;
12
19
  }
20
+ export type SaveModel = <T extends Model>(model: T | Build<T> | Partial<T>) => Promise<T>;
21
+ export type DeleteModel = (id: string) => Promise<string>;
13
22
  export declare const PermissionsContext: React.Context<Capabilities | null>;
14
23
  export declare const FileManager: React.FC<{
24
+ files: FileAttachment[];
15
25
  fileManagement: FileManagement;
16
26
  modelMap: Map<string, Model>;
17
- saveModel: <T extends Model>(model: T | Build<T> | Partial<T>) => Promise<T>;
18
- deleteModel: (id: string) => Promise<string>;
27
+ saveModel: SaveModel;
28
+ deleteModel: DeleteModel;
19
29
  enableDragAndDrop: boolean;
20
30
  can: Capabilities;
21
- addAttachmentToState?: (a: FileAttachment) => void;
22
31
  }>;
@@ -1,25 +1,15 @@
1
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
- };
2
+ import React from 'react';
3
+ import { DeleteModel, FileManagement, SaveModel } from './FileManager';
11
4
  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>;
5
+ saveModel: SaveModel;
6
+ deleteModel: DeleteModel;
14
7
  modelMap: Map<string, Model>;
15
- getAttachments: () => FileAttachment[];
16
- moveFilePopup: MoveFilePopup;
17
- setMoveFilePopupData: Dispatch<SetStateAction<MoveFilePopup>>;
8
+ fileManagement: FileManagement;
18
9
  }>;
19
10
  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>;
11
+ saveModel: SaveModel;
12
+ deleteModel: DeleteModel;
22
13
  modelMap: Map<string, Model>;
23
- getAttachments: () => FileAttachment[];
14
+ fileManagement: FileManagement;
24
15
  }>;
25
- export {};
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { FileAttachment } from '../../lib/files';
3
+ export declare const FileName: React.FC<{
4
+ file: FileAttachment;
5
+ }>;
6
+ export declare const FileNameText: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ export declare enum FileSectionAlertType {
3
+ NONE = 0,
4
+ UPLOAD_IN_PROGRESS = 1,
5
+ UPLOAD_SUCCESSFUL = 2,
6
+ MOVE_SUCCESSFUL = 3
7
+ }
8
+ export declare const FileSectionAlert: React.FC<{
9
+ alert: {
10
+ type: FileSectionAlertType;
11
+ message: string;
12
+ };
13
+ }>;
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
+ import { FileAttachment } from '../../lib/files';
2
3
  export declare const FileTypeIcon: React.FC<{
3
- withDot: boolean;
4
- fileExtension?: string;
5
- alt?: string;
4
+ file: FileAttachment;
6
5
  }>;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export declare const FileUploader: React.FC<{
3
+ handler: (file: File) => Promise<void>;
4
+ }>;
@@ -1,22 +1,6 @@
1
- import React, { Dispatch } from 'react';
2
- import { Replace } from './FileManager';
3
- import { FileAttachment } from './FileSectionItem/FileSectionItem';
4
- import { Action } from './FileSectionState';
5
- import { FileType } from './util';
1
+ import React from 'react';
2
+ import { ElementFiles } from '../../lib/files';
6
3
  export declare const InlineFilesSection: React.FC<{
7
- inlineFiles: {
8
- id: string;
9
- label: string;
10
- type: FileType;
11
- caption?: string;
12
- attachments?: FileAttachment[];
13
- }[];
14
- handleReplace: Replace;
15
- handleDownload: (url: string) => void;
16
- handleUpdateInline?: (modelId: string, attachment: FileAttachment) => void;
17
- handleDetachFile?: (attachmentLink: string, modelId: string) => void;
4
+ elements: ElementFiles[];
18
5
  isEditor: boolean;
19
- dispatch: Dispatch<Action>;
20
6
  }>;
21
- export declare const FileDateContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
22
- export declare const FileDate: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { FileAttachment } from '../../lib/files';
3
+ export declare const OtherFilesSection: React.FC<{
4
+ files: FileAttachment[];
5
+ }>;
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { ModelFile } from '../../lib/files';
3
+ export declare const SupplementsSection: React.FC<{
4
+ supplements: ModelFile[];
5
+ }>;
@@ -0,0 +1,2 @@
1
+ import ReactTooltip from 'react-tooltip';
2
+ export declare const Tooltip: import("styled-components").StyledComponent<typeof ReactTooltip, import("styled-components").DefaultTheme, {}, never>;
@@ -1,8 +1,8 @@
1
- import { FileAttachment } from './FileSectionItem/FileSectionItem';
1
+ import { FileAttachment } from '../../lib/files';
2
2
  export declare enum FileSectionType {
3
- Inline = 0,
4
- Supplements = 1,
5
- OtherFile = 2
3
+ Inline = "Inline files",
4
+ Supplements = "Supplements",
5
+ OtherFile = "Other files"
6
6
  }
7
7
  export declare enum FileType {
8
8
  Image = 0,
@@ -18,11 +18,7 @@ export declare enum FileType {
18
18
  Figure = 10,
19
19
  GraphicalAbstract = 11
20
20
  }
21
- export declare const extensionsWithFileTypesMap: Map<string, FileType>;
22
- export declare const fileTypesWithTitlesMap: Map<FileType | undefined, string>;
23
- export declare const fileTypesWithIconMap: Map<FileType | undefined, JSX.Element>;
24
- export declare const generateAttachmentsTitles: (externalFiles: FileAttachment[], fileSectionType: FileSectionType) => Array<{
25
- title: string;
26
- externalFile: FileAttachment;
27
- }>;
28
- export declare const droppableSections: FileSectionType[];
21
+ export declare const getFileType: (file: FileAttachment) => FileType | undefined;
22
+ export declare const getFileIcon: (file: FileAttachment) => JSX.Element | undefined;
23
+ export declare const getFileTypeIcon: (type: FileType) => JSX.Element | undefined;
24
+ export declare const isImageFile: (file: FileAttachment) => boolean;
@@ -0,0 +1,19 @@
1
+ /*!
2
+ * © 2019 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import React from 'react';
17
+ import { IconProps } from './types';
18
+ declare const CorruptedFileIcon: React.FC<IconProps>;
19
+ export default CorruptedFileIcon;
@@ -1,10 +1,8 @@
1
1
  import { Model } from '@manuscripts/json-schema';
2
- import { FileAttachment } from '../components/FileManager/FileSectionItem/FileSectionItem';
3
- import { InlineFile } from '../lib/inlineFiles';
4
- type FilePredicate = (fileName: string) => boolean;
5
- export declare const useFiles: (modelMap: Map<string, Model>, attachments: FileAttachment[], filePredicate?: FilePredicate) => {
2
+ import { ElementFiles, FileAttachment, ModelFile } from '../lib/files';
3
+ export declare const useFiles: (modelMap: Map<string, Model>, files: FileAttachment[]) => {
4
+ inlineFiles: ElementFiles[];
5
+ supplements: ModelFile[];
6
6
  otherFiles: FileAttachment[];
7
- supplementFiles: FileAttachment[];
8
- inlineFiles: InlineFile[];
9
7
  };
10
8
  export default useFiles;
@@ -32,7 +32,6 @@ export * from './components/Checkbox';
32
32
  export * from './components/Form';
33
33
  export * from './components/FileManager';
34
34
  export * from './components/FileManager/util';
35
- export * from './components/FileManager/FileSectionItem/FileSectionItem';
36
35
  export * from './components/Resizer';
37
36
  export * from './components/SaveStatus';
38
37
  export * from './components/SimpleModal';
@@ -50,10 +49,11 @@ export * from './components/NavDropdown';
50
49
  export * from './components/SubmissionInspector';
51
50
  export * from './components/Dropdown';
52
51
  export * from './hooks/use-dropdown';
53
- export { useFiles } from './hooks/use-files';
52
+ export * from './hooks/use-files';
54
53
  export { useDeepCompareMemo, useDeepCompareCallback, } from './hooks/use-deep-compare';
55
54
  export * from './lib/authors';
56
55
  export * from './lib/capabilities';
56
+ export * from './lib/files';
57
57
  export { default as errorsDecoder } from './lib/errors-decoder';
58
58
  export * from './types';
59
59
  export * from './components/LoadingOverlay';
@@ -0,0 +1,24 @@
1
+ import { Model } from '@manuscripts/json-schema';
2
+ import { FileType } from '../components/FileManager/util';
3
+ export type FileDesignation = {
4
+ id: string;
5
+ label?: string;
6
+ };
7
+ export type FileAttachment = {
8
+ id: string;
9
+ name: string;
10
+ type: FileDesignation;
11
+ createdDate?: Date;
12
+ };
13
+ export type ModelFile = FileAttachment & {
14
+ modelId: string;
15
+ };
16
+ export type ElementFiles = {
17
+ modelId: string;
18
+ label: string;
19
+ type: FileType;
20
+ files: ModelFile[];
21
+ };
22
+ export declare const isModelFile: (file: FileAttachment) => file is ModelFile;
23
+ export declare const getInlineFiles: (modelMap: Map<string, Model>, files: FileAttachment[]) => ElementFiles[];
24
+ export declare const getSupplements: (modelMap: Map<string, Model>, files: FileAttachment[]) => ModelFile[];
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.3.2-LEAN-2880-2",
4
+ "version": "1.3.2-LEAN-2859-5",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-style-guide",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -36,7 +36,7 @@
36
36
  "@formatjs/intl-relativetimeformat": "^4.5.9",
37
37
  "@formatjs/intl-utils": "^2.2.0",
38
38
  "@manuscripts/assets": "^0.6.2",
39
- "@manuscripts/transform": "1.3.12-LEAN-2880-8",
39
+ "@manuscripts/transform": "^1.4.3",
40
40
  "@manuscripts/json-schema": "^2.1.2",
41
41
  "@manuscripts/title-editor": "^1.1.0",
42
42
  "@manuscripts/comment-editor": "^1.0.3",
@@ -1,90 +0,0 @@
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
- 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
- });
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
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"));
39
- const Dialog_1 = require("../Dialog");
40
- const FileManagerProvider_1 = require("./FileManagerProvider");
41
- const FileSectionState_1 = require("./FileSectionState");
42
- const util_1 = require("./util");
43
- const ConfirmationPopUp = ({ popupHeader, popUpMessage, isOpen, handleClose, handleMove }) => {
44
- return (react_1.default.createElement(Dialog_1.Dialog, { isOpen: isOpen, category: Dialog_1.Category.confirmation, header: popupHeader, message: popUpMessage, actions: {
45
- primary: {
46
- action: handleMove,
47
- title: 'Move',
48
- },
49
- secondary: {
50
- action: handleClose,
51
- title: 'Cancel',
52
- },
53
- } }));
54
- };
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;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DragItemArea = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const styled_components_1 = __importDefault(require("styled-components"));
9
- const drag_drop_file_icon_1 = __importDefault(require("../icons/drag-drop-file-icon"));
10
- const DragItemArea = ({ text }) => {
11
- return (react_1.default.createElement(Container, null,
12
- react_1.default.createElement("div", null,
13
- react_1.default.createElement(drag_drop_file_icon_1.default, null)),
14
- text));
15
- };
16
- exports.DragItemArea = DragItemArea;
17
- const Container = styled_components_1.default.div `
18
- display: flex;
19
- flex-direction: column;
20
- align-items: center;
21
- justify-content: center;
22
- font-size: 14px;
23
- line-height: 24px;
24
- font-family: ${(props) => props.theme.font.family.Lato};
25
- color: ${(props) => props.theme.colors.text.onLight};
26
- padding: 32px 0;
27
- text-align: center;
28
- `;