@manuscripts/transform 2.1.14-LEAN-3049.0 → 2.2.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.
@@ -201,6 +201,7 @@ exports.jatsFrontParser = {
201
201
  ]);
202
202
  const authorNotes = [
203
203
  (0, transformer_1.buildAuthorNotes)([
204
+ ...correspondingIDs.values(),
204
205
  ...footnoteIDs.values(),
205
206
  ...authorNotesParagraphs.map((p) => p._id),
206
207
  ]),
@@ -617,6 +617,7 @@ class JATSExporter {
617
617
  const getModel = (id) => id ? this.modelMap.get(id) : undefined;
618
618
  const nodes = {
619
619
  author_notes: () => ['author-notes', 0],
620
+ corresp: () => '',
620
621
  title: () => '',
621
622
  affiliations: () => '',
622
623
  contributors: () => '',
@@ -1047,7 +1048,6 @@ class JATSExporter {
1047
1048
  }
1048
1049
  };
1049
1050
  this.buildContributors = (articleMeta) => {
1050
- var _a;
1051
1051
  const contributors = this.models.filter(isContributor);
1052
1052
  const authorContributors = contributors
1053
1053
  .filter((contributor) => contributor.role === 'author')
@@ -1266,34 +1266,21 @@ class JATSExporter {
1266
1266
  }
1267
1267
  });
1268
1268
  }
1269
- const authorNotesEl = this.document.createElement('author-notes');
1270
- const usedCorrespodings = this.getUsedCorrespondings([
1271
- ...authorContributors,
1272
- ...otherContributors,
1273
- ]);
1274
- usedCorrespodings.forEach((corresp) => {
1275
- this.appendCorrespondingToElement(corresp, authorNotesEl);
1276
- });
1277
- const authorNotes = (_a = (0, json_schema_1.getModelsByType)(this.modelMap, json_schema_1.ObjectTypes.AuthorNotes)) === null || _a === void 0 ? void 0 : _a[0];
1278
- if (authorNotes) {
1279
- authorNotes.containedObjectIDs.forEach((id) => {
1280
- const model = this.modelMap.get(id);
1281
- if (!model) {
1282
- return;
1283
- }
1284
- if (id.startsWith('MPParagraphElement')) {
1285
- this.appendParagraphToElement(model, authorNotesEl);
1286
- }
1287
- else if (id.startsWith('MPFootnote')) {
1288
- this.appendFootnoteToElement(model, authorNotesEl);
1289
- }
1290
- });
1291
- }
1269
+ const authorNotesEl = this.createAuthorNotesElement();
1292
1270
  if (authorNotesEl.childNodes.length > 0) {
1293
1271
  articleMeta.insertBefore(authorNotesEl, contribGroup.nextSibling);
1294
1272
  }
1295
1273
  }
1296
1274
  };
1275
+ this.createAuthorNotesElement = () => {
1276
+ var _a;
1277
+ const authorNotesEl = this.document.createElement('author-notes');
1278
+ const authorNotes = (_a = (0, json_schema_1.getModelsByType)(this.modelMap, json_schema_1.ObjectTypes.AuthorNotes)) === null || _a === void 0 ? void 0 : _a[0];
1279
+ if (authorNotes) {
1280
+ this.appendModelsToAuthorNotes(authorNotesEl, authorNotes.containedObjectIDs);
1281
+ }
1282
+ return authorNotesEl;
1283
+ };
1297
1284
  this.appendCorrespondingToElement = (corresponding, element) => {
1298
1285
  const correspondingEl = this.document.createElement('corresp');
1299
1286
  correspondingEl.setAttribute('id', normalizeID(corresponding._id));
@@ -1623,6 +1610,29 @@ class JATSExporter {
1623
1610
  return mathml;
1624
1611
  }
1625
1612
  }
1613
+ appendModelsToAuthorNotes(authorNotesEl, containedObjectIDs) {
1614
+ const contributors = this.models.filter(isContributor);
1615
+ const usedCorrespondings = this.getUsedCorrespondings(contributors);
1616
+ containedObjectIDs.forEach((id) => {
1617
+ const model = this.modelMap.get(id);
1618
+ if (!model) {
1619
+ return;
1620
+ }
1621
+ switch (model.objectType) {
1622
+ case json_schema_1.ObjectTypes.ParagraphElement:
1623
+ this.appendParagraphToElement(model, authorNotesEl);
1624
+ break;
1625
+ case json_schema_1.ObjectTypes.Footnote:
1626
+ this.appendFootnoteToElement(model, authorNotesEl);
1627
+ break;
1628
+ case json_schema_1.ObjectTypes.Corresponding:
1629
+ if (usedCorrespondings.includes(model)) {
1630
+ this.appendCorrespondingToElement(model, authorNotesEl);
1631
+ }
1632
+ break;
1633
+ }
1634
+ });
1635
+ }
1626
1636
  getUsedCorrespondings(contributors) {
1627
1637
  return contributors
1628
1638
  .flatMap((c) => { var _a; return (_a = c.corresp) !== null && _a !== void 0 ? _a : []; })
@@ -50,6 +50,7 @@ const comment_1 = require("./nodes/comment");
50
50
  const comments_1 = require("./nodes/comments");
51
51
  const contributor_1 = require("./nodes/contributor");
52
52
  const contributors_1 = require("./nodes/contributors");
53
+ const corresp_1 = require("./nodes/corresp");
53
54
  const cross_reference_1 = require("./nodes/cross_reference");
54
55
  const doc_1 = require("./nodes/doc");
55
56
  const equation_1 = require("./nodes/equation");
@@ -229,5 +230,6 @@ exports.schema = new prosemirror_model_1.Schema({
229
230
  supplements: supplements_1.supplements,
230
231
  supplement: supplement_1.supplement,
231
232
  author_notes: author_notes_1.authorNotes,
233
+ corresp: corresp_1.corresp,
232
234
  },
233
235
  });
@@ -21,7 +21,7 @@ exports.authorNotes = {
21
21
  id: { default: '' },
22
22
  dataTracked: { default: null },
23
23
  },
24
- content: '(footnote | paragraph)+',
24
+ content: '(corresp | footnote | paragraph)+',
25
25
  group: 'block element',
26
26
  toDOM: () => ['author-notes', 0],
27
27
  };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.corresp = void 0;
4
+ exports.corresp = {
5
+ content: 'inline*',
6
+ attrs: {
7
+ id: { default: '' },
8
+ label: { default: undefined },
9
+ dataTracked: { default: null },
10
+ },
11
+ group: 'block',
12
+ toDOM: () => ['corresp', 0],
13
+ };
@@ -502,6 +502,15 @@ class Decoder {
502
502
  id: model._id,
503
503
  }, content);
504
504
  },
505
+ [json_schema_1.ObjectTypes.Corresponding]: (data) => {
506
+ const model = data;
507
+ return this.parseContents(model.contents, 'corresp', [], {
508
+ topNode: schema_1.schema.nodes.corresp.create({
509
+ id: model._id,
510
+ label: model.label,
511
+ }),
512
+ });
513
+ },
505
514
  [json_schema_1.ObjectTypes.Section]: (data) => {
506
515
  const model = data;
507
516
  const elements = [];
@@ -522,6 +522,10 @@ const encoders = {
522
522
  ? [node.attrs.mimeType, node.attrs.mimeSubType].join('/')
523
523
  : '',
524
524
  }),
525
+ corresp: (node) => ({
526
+ contents: (0, exports.inlineContents)(node),
527
+ label: node.attrs.label,
528
+ }),
525
529
  };
526
530
  const modelData = (node, parent, path, priority) => {
527
531
  const encoder = encoders[node.type.name];
@@ -62,6 +62,7 @@ exports.nodeTypesMap = new Map([
62
62
  [schema_1.schema.nodes.title, json_schema_1.ObjectTypes.Titles],
63
63
  [schema_1.schema.nodes.supplement, json_schema_1.ObjectTypes.Supplement],
64
64
  [schema_1.schema.nodes.author_notes, json_schema_1.ObjectTypes.AuthorNotes],
65
+ [schema_1.schema.nodes.corresp, json_schema_1.ObjectTypes.Corresponding],
65
66
  ]);
66
67
  const isExecutableNodeType = (type) => (0, schema_1.hasGroup)(type, schema_1.GROUP_EXECUTABLE);
67
68
  exports.isExecutableNodeType = isExecutableNodeType;
@@ -195,6 +195,7 @@ export const jatsFrontParser = {
195
195
  ]);
196
196
  const authorNotes = [
197
197
  buildAuthorNotes([
198
+ ...correspondingIDs.values(),
198
199
  ...footnoteIDs.values(),
199
200
  ...authorNotesParagraphs.map((p) => p._id),
200
201
  ]),
@@ -609,6 +609,7 @@ export class JATSExporter {
609
609
  const getModel = (id) => id ? this.modelMap.get(id) : undefined;
610
610
  const nodes = {
611
611
  author_notes: () => ['author-notes', 0],
612
+ corresp: () => '',
612
613
  title: () => '',
613
614
  affiliations: () => '',
614
615
  contributors: () => '',
@@ -1039,7 +1040,6 @@ export class JATSExporter {
1039
1040
  }
1040
1041
  };
1041
1042
  this.buildContributors = (articleMeta) => {
1042
- var _a;
1043
1043
  const contributors = this.models.filter(isContributor);
1044
1044
  const authorContributors = contributors
1045
1045
  .filter((contributor) => contributor.role === 'author')
@@ -1258,34 +1258,21 @@ export class JATSExporter {
1258
1258
  }
1259
1259
  });
1260
1260
  }
1261
- const authorNotesEl = this.document.createElement('author-notes');
1262
- const usedCorrespodings = this.getUsedCorrespondings([
1263
- ...authorContributors,
1264
- ...otherContributors,
1265
- ]);
1266
- usedCorrespodings.forEach((corresp) => {
1267
- this.appendCorrespondingToElement(corresp, authorNotesEl);
1268
- });
1269
- const authorNotes = (_a = getModelsByType(this.modelMap, ObjectTypes.AuthorNotes)) === null || _a === void 0 ? void 0 : _a[0];
1270
- if (authorNotes) {
1271
- authorNotes.containedObjectIDs.forEach((id) => {
1272
- const model = this.modelMap.get(id);
1273
- if (!model) {
1274
- return;
1275
- }
1276
- if (id.startsWith('MPParagraphElement')) {
1277
- this.appendParagraphToElement(model, authorNotesEl);
1278
- }
1279
- else if (id.startsWith('MPFootnote')) {
1280
- this.appendFootnoteToElement(model, authorNotesEl);
1281
- }
1282
- });
1283
- }
1261
+ const authorNotesEl = this.createAuthorNotesElement();
1284
1262
  if (authorNotesEl.childNodes.length > 0) {
1285
1263
  articleMeta.insertBefore(authorNotesEl, contribGroup.nextSibling);
1286
1264
  }
1287
1265
  }
1288
1266
  };
1267
+ this.createAuthorNotesElement = () => {
1268
+ var _a;
1269
+ const authorNotesEl = this.document.createElement('author-notes');
1270
+ const authorNotes = (_a = getModelsByType(this.modelMap, ObjectTypes.AuthorNotes)) === null || _a === void 0 ? void 0 : _a[0];
1271
+ if (authorNotes) {
1272
+ this.appendModelsToAuthorNotes(authorNotesEl, authorNotes.containedObjectIDs);
1273
+ }
1274
+ return authorNotesEl;
1275
+ };
1289
1276
  this.appendCorrespondingToElement = (corresponding, element) => {
1290
1277
  const correspondingEl = this.document.createElement('corresp');
1291
1278
  correspondingEl.setAttribute('id', normalizeID(corresponding._id));
@@ -1615,6 +1602,29 @@ export class JATSExporter {
1615
1602
  return mathml;
1616
1603
  }
1617
1604
  }
1605
+ appendModelsToAuthorNotes(authorNotesEl, containedObjectIDs) {
1606
+ const contributors = this.models.filter(isContributor);
1607
+ const usedCorrespondings = this.getUsedCorrespondings(contributors);
1608
+ containedObjectIDs.forEach((id) => {
1609
+ const model = this.modelMap.get(id);
1610
+ if (!model) {
1611
+ return;
1612
+ }
1613
+ switch (model.objectType) {
1614
+ case ObjectTypes.ParagraphElement:
1615
+ this.appendParagraphToElement(model, authorNotesEl);
1616
+ break;
1617
+ case ObjectTypes.Footnote:
1618
+ this.appendFootnoteToElement(model, authorNotesEl);
1619
+ break;
1620
+ case ObjectTypes.Corresponding:
1621
+ if (usedCorrespondings.includes(model)) {
1622
+ this.appendCorrespondingToElement(model, authorNotesEl);
1623
+ }
1624
+ break;
1625
+ }
1626
+ });
1627
+ }
1618
1628
  getUsedCorrespondings(contributors) {
1619
1629
  return contributors
1620
1630
  .flatMap((c) => { var _a; return (_a = c.corresp) !== null && _a !== void 0 ? _a : []; })
@@ -33,6 +33,7 @@ import { comment } from './nodes/comment';
33
33
  import { comments } from './nodes/comments';
34
34
  import { contributor } from './nodes/contributor';
35
35
  import { contributors } from './nodes/contributors';
36
+ import { corresp } from './nodes/corresp';
36
37
  import { crossReference } from './nodes/cross_reference';
37
38
  import { doc } from './nodes/doc';
38
39
  import { equation } from './nodes/equation';
@@ -212,5 +213,6 @@ export const schema = new Schema({
212
213
  supplements,
213
214
  supplement,
214
215
  author_notes: authorNotes,
216
+ corresp,
215
217
  },
216
218
  });
@@ -18,7 +18,7 @@ export const authorNotes = {
18
18
  id: { default: '' },
19
19
  dataTracked: { default: null },
20
20
  },
21
- content: '(footnote | paragraph)+',
21
+ content: '(corresp | footnote | paragraph)+',
22
22
  group: 'block element',
23
23
  toDOM: () => ['author-notes', 0],
24
24
  };
@@ -0,0 +1,10 @@
1
+ export const corresp = {
2
+ content: 'inline*',
3
+ attrs: {
4
+ id: { default: '' },
5
+ label: { default: undefined },
6
+ dataTracked: { default: null },
7
+ },
8
+ group: 'block',
9
+ toDOM: () => ['corresp', 0],
10
+ };
@@ -493,6 +493,15 @@ export class Decoder {
493
493
  id: model._id,
494
494
  }, content);
495
495
  },
496
+ [ObjectTypes.Corresponding]: (data) => {
497
+ const model = data;
498
+ return this.parseContents(model.contents, 'corresp', [], {
499
+ topNode: schema.nodes.corresp.create({
500
+ id: model._id,
501
+ label: model.label,
502
+ }),
503
+ });
504
+ },
496
505
  [ObjectTypes.Section]: (data) => {
497
506
  const model = data;
498
507
  const elements = [];
@@ -514,6 +514,10 @@ const encoders = {
514
514
  ? [node.attrs.mimeType, node.attrs.mimeSubType].join('/')
515
515
  : '',
516
516
  }),
517
+ corresp: (node) => ({
518
+ contents: inlineContents(node),
519
+ label: node.attrs.label,
520
+ }),
517
521
  };
518
522
  const modelData = (node, parent, path, priority) => {
519
523
  const encoder = encoders[node.type.name];
@@ -59,6 +59,7 @@ export const nodeTypesMap = new Map([
59
59
  [schema.nodes.title, ObjectTypes.Titles],
60
60
  [schema.nodes.supplement, ObjectTypes.Supplement],
61
61
  [schema.nodes.author_notes, ObjectTypes.AuthorNotes],
62
+ [schema.nodes.corresp, ObjectTypes.Corresponding],
62
63
  ]);
63
64
  export const isExecutableNodeType = (type) => hasGroup(type, GROUP_EXECUTABLE);
64
65
  export const isElementNodeType = (type) => hasGroup(type, GROUP_ELEMENT);
@@ -87,6 +87,8 @@ export declare class JATSExporter {
87
87
  protected serializeNode: (node: ManuscriptNode) => Node;
88
88
  private validateContributor;
89
89
  private buildContributors;
90
+ private createAuthorNotesElement;
91
+ private appendModelsToAuthorNotes;
90
92
  private appendCorrespondingToElement;
91
93
  private getUsedCorrespondings;
92
94
  private appendParagraphToElement;
@@ -0,0 +1,11 @@
1
+ import { NodeSpec } from 'prosemirror-model';
2
+ import { ManuscriptNode } from '../types';
3
+ interface Attrs {
4
+ id: string;
5
+ label?: string;
6
+ }
7
+ export interface CorrespNode extends ManuscriptNode {
8
+ attrs: Attrs;
9
+ }
10
+ export declare const corresp: NodeSpec;
11
+ export {};
@@ -17,7 +17,7 @@ import { Fragment, Mark as ProsemirrorMark, MarkType, Node as ProsemirrorNode, N
17
17
  import { EditorState, NodeSelection, Plugin, TextSelection, Transaction } from 'prosemirror-state';
18
18
  import { EditorView, NodeView } from 'prosemirror-view';
19
19
  export type Marks = 'bold' | 'code' | 'italic' | 'smallcaps' | 'strikethrough' | 'styled' | 'subscript' | 'superscript' | 'underline' | 'tracked_insert' | 'tracked_delete';
20
- export type Nodes = 'attribution' | 'bibliography_item' | 'bibliography_element' | 'bibliography_section' | 'blockquote_element' | 'bullet_list' | 'caption' | 'caption_title' | 'comment' | 'comments' | 'citation' | 'cross_reference' | 'doc' | 'equation' | 'equation_element' | 'figcaption' | 'figure' | 'graphical_abstract_section' | 'figure_element' | 'footnote' | 'footnotes_element' | 'footnotes_section' | 'hard_break' | 'highlight_marker' | 'inline_equation' | 'inline_footnote' | 'keyword' | 'keywords_element' | 'keyword_group' | 'keywords' | 'link' | 'list_item' | 'listing' | 'listing_element' | 'manuscript' | 'abstracts' | 'body' | 'backmatter' | 'missing_figure' | 'ordered_list' | 'paragraph' | 'placeholder' | 'placeholder_element' | 'pullquote_element' | 'section' | 'section_label' | 'section_title' | 'section_title_plain' | 'table' | 'table_cell' | 'table_element' | 'table_row' | 'table_colgroup' | 'table_col' | 'table_header' | 'text' | 'toc_element' | 'toc_section' | 'affiliation' | 'contributor' | 'table_element_footer' | 'title' | 'affiliations' | 'contributors' | 'supplements' | 'supplement' | 'author_notes';
20
+ export type Nodes = 'attribution' | 'bibliography_item' | 'bibliography_element' | 'bibliography_section' | 'blockquote_element' | 'bullet_list' | 'caption' | 'caption_title' | 'comment' | 'comments' | 'citation' | 'cross_reference' | 'doc' | 'equation' | 'equation_element' | 'figcaption' | 'figure' | 'graphical_abstract_section' | 'figure_element' | 'footnote' | 'footnotes_element' | 'footnotes_section' | 'hard_break' | 'highlight_marker' | 'inline_equation' | 'inline_footnote' | 'keyword' | 'keywords_element' | 'keyword_group' | 'keywords' | 'link' | 'list_item' | 'listing' | 'listing_element' | 'manuscript' | 'abstracts' | 'body' | 'backmatter' | 'missing_figure' | 'ordered_list' | 'paragraph' | 'placeholder' | 'placeholder_element' | 'pullquote_element' | 'section' | 'section_label' | 'section_title' | 'section_title_plain' | 'table' | 'table_cell' | 'table_element' | 'table_row' | 'table_colgroup' | 'table_col' | 'table_header' | 'text' | 'toc_element' | 'toc_section' | 'affiliation' | 'contributor' | 'table_element_footer' | 'title' | 'affiliations' | 'contributors' | 'supplements' | 'supplement' | 'author_notes' | 'corresp';
21
21
  export type ManuscriptSchema = Schema<Nodes, Marks>;
22
22
  export type ManuscriptEditorState = EditorState;
23
23
  export type ManuscriptEditorView = EditorView;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@manuscripts/transform",
3
3
  "description": "ProseMirror transformer for Manuscripts applications",
4
- "version": "2.1.14-LEAN-3049.0",
4
+ "version": "2.2.1",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",