@manuscripts/style-guide 0.32.31 → 0.33.0

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.
@@ -86,22 +86,12 @@ const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileManageme
86
86
  window.location.assign(url);
87
87
  }, []);
88
88
  const handleUpdateInline = (0, react_1.useCallback)((modelId, attachment) => __awaiter(void 0, void 0, void 0, function* () {
89
- var _a;
90
89
  const figureModel = modelMap.get(modelId);
91
- const imageExternalFileIndex = (_a = figureModel === null || figureModel === void 0 ? void 0 : figureModel.externalFileReferences) === null || _a === void 0 ? void 0 : _a.findIndex((file) => file && file.kind === 'imageRepresentation');
92
- if (figureModel.externalFileReferences &&
93
- typeof imageExternalFileIndex !== 'undefined' &&
94
- imageExternalFileIndex > -1) {
95
- const newRefs = [...figureModel.externalFileReferences];
96
- newRefs[imageExternalFileIndex] = {
97
- url: `attachment:${attachment.id}`,
98
- kind: 'imageRepresentation',
99
- };
100
- if (addAttachmentToState) {
101
- addAttachmentToState(Object.assign({}, attachment));
102
- }
103
- yield saveModel(Object.assign(Object.assign({}, figureModel), { src: '', externalFileReferences: newRefs }));
90
+ figureModel.src = `attachment:${attachment.id}`;
91
+ if (addAttachmentToState) {
92
+ addAttachmentToState(Object.assign({}, attachment));
104
93
  }
94
+ yield saveModel(figureModel);
105
95
  }), [modelMap, saveModel, addAttachmentToState]);
106
96
  const attachments = getAttachments();
107
97
  const { otherFiles, supplementFiles, inlineFiles } = (0, index_1.useFiles)(modelMap, attachments);
@@ -3,26 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const manuscript_transform_1 = require("@manuscripts/manuscript-transform");
4
4
  const manuscripts_json_schema_1 = require("@manuscripts/manuscripts-json-schema");
5
5
  const util_1 = require("../components/FileManager/util");
6
- const getAttachment = (externalFileRef, attachmentsMap) => {
7
- if (!(externalFileRef === null || externalFileRef === void 0 ? void 0 : externalFileRef.url.startsWith('http'))) {
8
- const attachmentId = externalFileRef === null || externalFileRef === void 0 ? void 0 : externalFileRef.url.replace('attachment:', '');
9
- return attachmentId ? attachmentsMap.get(attachmentId) : undefined;
10
- }
11
- else {
12
- return [...attachmentsMap.values()].find((attachment) => attachment.link === externalFileRef.url.replace(/[&|?]format=jpg/, ''));
13
- }
14
- };
15
6
  const getFigureData = (element, modelMap, attachmentsMap) => {
16
7
  const attachments = [];
17
8
  element.containedObjectIDs.map((id) => {
18
- var _a;
19
9
  const object = modelMap.get(id);
20
10
  if (object && object.objectType === manuscripts_json_schema_1.ObjectTypes.Figure) {
21
- const externalFileRef = (_a = object.externalFileReferences) === null || _a === void 0 ? void 0 : _a.find((figure) => figure.kind === 'imageRepresentation');
22
- const attachment = getAttachment(externalFileRef, attachmentsMap);
23
- if (attachment) {
24
- attachment.modelId = id;
25
- attachments.push(attachment);
11
+ const figure = object;
12
+ if (figure.src) {
13
+ const attachment = attachmentsMap.get(figure.src.replace('attachment:', ''));
14
+ if (attachment) {
15
+ attachment.modelId = id;
16
+ attachments.push(attachment);
17
+ }
26
18
  }
27
19
  }
28
20
  });
@@ -34,7 +26,7 @@ const getFigureData = (element, modelMap, attachmentsMap) => {
34
26
  exports.default = (modelMap, attachments) => {
35
27
  const files = [];
36
28
  const attachmentsMap = new Map(attachments.map((attachment) => [attachment.id, attachment]));
37
- const { graphicalAbstractFigureId, figureElement, tableElement } = getAuxiliaryObjects(modelMap);
29
+ const { graphicalAbstractFigureId, figureElement } = getAuxiliaryObjects(modelMap);
38
30
  if (graphicalAbstractFigureId) {
39
31
  const element = modelMap.get(graphicalAbstractFigureId);
40
32
  files.unshift(Object.assign(Object.assign({}, getFigureData(element, modelMap, attachmentsMap)), { label: `Graphical Abstract`, type: util_1.FileType.GraphicalAbstract }));
@@ -43,21 +35,6 @@ exports.default = (modelMap, attachments) => {
43
35
  const element = modelMap.get(id);
44
36
  files.push(Object.assign(Object.assign({}, getFigureData(element, modelMap, attachmentsMap)), { label: `Figure ${index + 1}`, type: util_1.FileType.Figure }));
45
37
  });
46
- tableElement.map((id) => {
47
- var _a;
48
- const tableElement = modelMap.get(id);
49
- const table = modelMap.get(tableElement.containedObjectID);
50
- const externalFileReference = (_a = table === null || table === void 0 ? void 0 : table.externalFileReferences) === null || _a === void 0 ? void 0 : _a.find((file) => file.kind === 'dataset' && file.ref);
51
- const attachment = getAttachment(externalFileReference, attachmentsMap);
52
- if (attachment) {
53
- files.push({
54
- id: tableElement._id,
55
- label: `Table`,
56
- type: util_1.FileType.SheetsWorkbooks,
57
- attachments: [attachment],
58
- });
59
- }
60
- });
61
38
  return files;
62
39
  };
63
40
  const getAuxiliaryObjects = (modelMap) => {
@@ -61,22 +61,12 @@ export const FileManager = ({ modelMap, saveModel, enableDragAndDrop, can, fileM
61
61
  window.location.assign(url);
62
62
  }, []);
63
63
  const handleUpdateInline = useCallback((modelId, attachment) => __awaiter(void 0, void 0, void 0, function* () {
64
- var _a;
65
64
  const figureModel = modelMap.get(modelId);
66
- const imageExternalFileIndex = (_a = figureModel === null || figureModel === void 0 ? void 0 : figureModel.externalFileReferences) === null || _a === void 0 ? void 0 : _a.findIndex((file) => file && file.kind === 'imageRepresentation');
67
- if (figureModel.externalFileReferences &&
68
- typeof imageExternalFileIndex !== 'undefined' &&
69
- imageExternalFileIndex > -1) {
70
- const newRefs = [...figureModel.externalFileReferences];
71
- newRefs[imageExternalFileIndex] = {
72
- url: `attachment:${attachment.id}`,
73
- kind: 'imageRepresentation',
74
- };
75
- if (addAttachmentToState) {
76
- addAttachmentToState(Object.assign({}, attachment));
77
- }
78
- yield saveModel(Object.assign(Object.assign({}, figureModel), { src: '', externalFileReferences: newRefs }));
65
+ figureModel.src = `attachment:${attachment.id}`;
66
+ if (addAttachmentToState) {
67
+ addAttachmentToState(Object.assign({}, attachment));
79
68
  }
69
+ yield saveModel(figureModel);
80
70
  }), [modelMap, saveModel, addAttachmentToState]);
81
71
  const attachments = getAttachments();
82
72
  const { otherFiles, supplementFiles, inlineFiles } = useFiles(modelMap, attachments);
@@ -1,26 +1,18 @@
1
1
  import { hasObjectType } from '@manuscripts/manuscript-transform';
2
2
  import { ObjectTypes, } from '@manuscripts/manuscripts-json-schema';
3
3
  import { FileType } from '../components/FileManager/util';
4
- const getAttachment = (externalFileRef, attachmentsMap) => {
5
- if (!(externalFileRef === null || externalFileRef === void 0 ? void 0 : externalFileRef.url.startsWith('http'))) {
6
- const attachmentId = externalFileRef === null || externalFileRef === void 0 ? void 0 : externalFileRef.url.replace('attachment:', '');
7
- return attachmentId ? attachmentsMap.get(attachmentId) : undefined;
8
- }
9
- else {
10
- return [...attachmentsMap.values()].find((attachment) => attachment.link === externalFileRef.url.replace(/[&|?]format=jpg/, ''));
11
- }
12
- };
13
4
  const getFigureData = (element, modelMap, attachmentsMap) => {
14
5
  const attachments = [];
15
6
  element.containedObjectIDs.map((id) => {
16
- var _a;
17
7
  const object = modelMap.get(id);
18
8
  if (object && object.objectType === ObjectTypes.Figure) {
19
- const externalFileRef = (_a = object.externalFileReferences) === null || _a === void 0 ? void 0 : _a.find((figure) => figure.kind === 'imageRepresentation');
20
- const attachment = getAttachment(externalFileRef, attachmentsMap);
21
- if (attachment) {
22
- attachment.modelId = id;
23
- attachments.push(attachment);
9
+ const figure = object;
10
+ if (figure.src) {
11
+ const attachment = attachmentsMap.get(figure.src.replace('attachment:', ''));
12
+ if (attachment) {
13
+ attachment.modelId = id;
14
+ attachments.push(attachment);
15
+ }
24
16
  }
25
17
  }
26
18
  });
@@ -32,7 +24,7 @@ const getFigureData = (element, modelMap, attachmentsMap) => {
32
24
  export default (modelMap, attachments) => {
33
25
  const files = [];
34
26
  const attachmentsMap = new Map(attachments.map((attachment) => [attachment.id, attachment]));
35
- const { graphicalAbstractFigureId, figureElement, tableElement } = getAuxiliaryObjects(modelMap);
27
+ const { graphicalAbstractFigureId, figureElement } = getAuxiliaryObjects(modelMap);
36
28
  if (graphicalAbstractFigureId) {
37
29
  const element = modelMap.get(graphicalAbstractFigureId);
38
30
  files.unshift(Object.assign(Object.assign({}, getFigureData(element, modelMap, attachmentsMap)), { label: `Graphical Abstract`, type: FileType.GraphicalAbstract }));
@@ -41,21 +33,6 @@ export default (modelMap, attachments) => {
41
33
  const element = modelMap.get(id);
42
34
  files.push(Object.assign(Object.assign({}, getFigureData(element, modelMap, attachmentsMap)), { label: `Figure ${index + 1}`, type: FileType.Figure }));
43
35
  });
44
- tableElement.map((id) => {
45
- var _a;
46
- const tableElement = modelMap.get(id);
47
- const table = modelMap.get(tableElement.containedObjectID);
48
- const externalFileReference = (_a = table === null || table === void 0 ? void 0 : table.externalFileReferences) === null || _a === void 0 ? void 0 : _a.find((file) => file.kind === 'dataset' && file.ref);
49
- const attachment = getAttachment(externalFileReference, attachmentsMap);
50
- if (attachment) {
51
- files.push({
52
- id: tableElement._id,
53
- label: `Table`,
54
- type: FileType.SheetsWorkbooks,
55
- attachments: [attachment],
56
- });
57
- }
58
- });
59
36
  return files;
60
37
  };
61
38
  const getAuxiliaryObjects = (modelMap) => {
@@ -3,11 +3,6 @@ import { Replace } from './FileManager';
3
3
  import { SubmissionAttachment } from './FileSectionItem/FileSectionItem';
4
4
  import { Action } from './FileSectionState';
5
5
  import { FileType } from './util';
6
- export interface ExternalFileRef {
7
- url: string;
8
- kind?: string;
9
- ref?: SubmissionAttachment;
10
- }
11
6
  export declare const InlineFilesSection: React.FC<{
12
7
  inlineFiles: {
13
8
  id: string;
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": "0.32.31",
4
+ "version": "0.33.0",
5
5
  "repository": "gitlab:atypon-opensource/manuscripts-style-guide",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",