@manuscripts/transform 2.3.35 → 2.3.37-LEAN-3911.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.
Files changed (123) hide show
  1. package/dist/cjs/jats/importer/create-article-node.js +31 -0
  2. package/dist/cjs/jats/importer/index.js +3 -3
  3. package/dist/cjs/jats/importer/jats-body-transformations.js +70 -0
  4. package/dist/cjs/jats/importer/jats-comments.js +27 -104
  5. package/dist/cjs/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +229 -9
  6. package/dist/cjs/jats/importer/jats-front-transformations.js +262 -0
  7. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +8 -1
  8. package/dist/cjs/jats/importer/jats-parser-utils.js +39 -5
  9. package/dist/cjs/jats/importer/jats-reference-parser.js +16 -27
  10. package/dist/cjs/jats/importer/jats-references.js +18 -18
  11. package/dist/cjs/jats/importer/parse-jats-article.js +42 -78
  12. package/dist/cjs/jats/index.js +4 -3
  13. package/dist/cjs/jats/jats-exporter.js +252 -354
  14. package/dist/cjs/{transformer → jats}/labels.js +3 -3
  15. package/dist/cjs/lib/utils.js +9 -1
  16. package/dist/cjs/schema/index.js +2 -0
  17. package/dist/cjs/schema/nodes/box_element.js +55 -0
  18. package/dist/cjs/transformer/id.js +10 -5
  19. package/dist/cjs/transformer/index.js +0 -18
  20. package/dist/cjs/transformer/node-types.js +1 -0
  21. package/dist/cjs/transformer/section-category.js +8 -0
  22. package/dist/cjs/version.js +1 -1
  23. package/dist/{cjs/transformer/serializer.js → es/jats/importer/create-article-node.js} +12 -8
  24. package/dist/es/jats/importer/index.js +2 -1
  25. package/dist/es/jats/importer/jats-body-transformations.js +70 -0
  26. package/dist/es/jats/importer/jats-comments.js +26 -101
  27. package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +230 -10
  28. package/dist/es/jats/importer/jats-front-transformations.js +259 -0
  29. package/dist/es/jats/importer/jats-journal-meta-parser.js +6 -0
  30. package/dist/es/jats/importer/jats-parser-utils.js +40 -6
  31. package/dist/es/jats/importer/jats-reference-parser.js +16 -27
  32. package/dist/es/jats/importer/jats-references.js +18 -18
  33. package/dist/es/jats/importer/parse-jats-article.js +43 -77
  34. package/dist/es/jats/index.js +3 -1
  35. package/dist/es/jats/jats-exporter.js +254 -356
  36. package/dist/es/{transformer → jats}/labels.js +3 -3
  37. package/dist/es/lib/utils.js +7 -0
  38. package/dist/es/schema/index.js +2 -0
  39. package/dist/es/schema/nodes/box_element.js +52 -0
  40. package/dist/es/transformer/id.js +8 -3
  41. package/dist/es/transformer/index.js +0 -16
  42. package/dist/es/transformer/node-types.js +1 -0
  43. package/dist/es/transformer/section-category.js +8 -0
  44. package/dist/es/version.js +1 -1
  45. package/dist/{cjs/transformer/models.js → types/jats/importer/create-article-node.d.ts} +3 -3
  46. package/dist/types/jats/importer/index.d.ts +2 -1
  47. package/dist/types/jats/importer/jats-body-transformations.d.ts +5 -0
  48. package/dist/types/jats/importer/jats-comments.d.ts +4 -10
  49. package/dist/types/jats/importer/{jats-body-dom-parser.d.ts → jats-dom-parser.d.ts} +1 -1
  50. package/dist/types/jats/importer/jats-front-transformations.d.ts +38 -0
  51. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +10 -0
  52. package/dist/types/jats/importer/jats-references.d.ts +19 -8
  53. package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
  54. package/dist/types/jats/index.d.ts +3 -1
  55. package/dist/types/jats/jats-exporter.d.ts +10 -29
  56. package/dist/types/{transformer → jats}/labels.d.ts +2 -1
  57. package/dist/types/lib/utils.d.ts +3 -0
  58. package/dist/types/schema/nodes/bibliography_item.d.ts +28 -5
  59. package/dist/{es/transformer/models.js → types/schema/nodes/box_element.d.ts} +10 -0
  60. package/dist/types/schema/nodes/contributor.d.ts +10 -0
  61. package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
  62. package/dist/types/schema/types.d.ts +1 -1
  63. package/dist/types/transformer/id.d.ts +5 -2
  64. package/dist/types/transformer/index.d.ts +0 -16
  65. package/dist/types/transformer/section-category.d.ts +2 -2
  66. package/dist/types/version.d.ts +1 -1
  67. package/package.json +2 -1
  68. package/dist/cjs/__tests__/data/project-dump.json +0 -825
  69. package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
  70. package/dist/cjs/transformer/__tests__/__helpers__/doc.js +0 -37
  71. package/dist/cjs/transformer/builders.js +0 -219
  72. package/dist/cjs/transformer/decode.js +0 -874
  73. package/dist/cjs/transformer/document-object-types.js +0 -31
  74. package/dist/cjs/transformer/encode.js +0 -664
  75. package/dist/cjs/transformer/footnote-category.js +0 -20
  76. package/dist/cjs/transformer/footnotes-order.js +0 -60
  77. package/dist/cjs/transformer/highlight-markers.js +0 -138
  78. package/dist/cjs/transformer/html.js +0 -400
  79. package/dist/cjs/transformer/manuscript-dependencies.js +0 -21
  80. package/dist/cjs/transformer/model-map.js +0 -26
  81. package/dist/cjs/transformer/object-types.js +0 -57
  82. package/dist/cjs/transformer/project-bundle.js +0 -94
  83. package/dist/cjs/transformer/update-identifiers.js +0 -93
  84. package/dist/es/__tests__/data/project-dump.json +0 -825
  85. package/dist/es/jats/importer/jats-front-parser.js +0 -315
  86. package/dist/es/transformer/__tests__/__helpers__/doc.js +0 -29
  87. package/dist/es/transformer/builders.js +0 -186
  88. package/dist/es/transformer/decode.js +0 -864
  89. package/dist/es/transformer/document-object-types.js +0 -28
  90. package/dist/es/transformer/encode.js +0 -654
  91. package/dist/es/transformer/footnote-category.js +0 -16
  92. package/dist/es/transformer/footnotes-order.js +0 -55
  93. package/dist/es/transformer/highlight-markers.js +0 -132
  94. package/dist/es/transformer/html.js +0 -393
  95. package/dist/es/transformer/manuscript-dependencies.js +0 -17
  96. package/dist/es/transformer/model-map.js +0 -22
  97. package/dist/es/transformer/object-types.js +0 -52
  98. package/dist/es/transformer/project-bundle.js +0 -85
  99. package/dist/es/transformer/serializer.js +0 -17
  100. package/dist/es/transformer/update-identifiers.js +0 -87
  101. package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
  102. package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +0 -18
  103. package/dist/types/transformer/builders.d.ts +0 -61
  104. package/dist/types/transformer/decode.d.ts +0 -51
  105. package/dist/types/transformer/document-object-types.d.ts +0 -17
  106. package/dist/types/transformer/encode.d.ts +0 -29
  107. package/dist/types/transformer/footnote-category.d.ts +0 -17
  108. package/dist/types/transformer/footnotes-order.d.ts +0 -22
  109. package/dist/types/transformer/highlight-markers.d.ts +0 -31
  110. package/dist/types/transformer/html.d.ts +0 -36
  111. package/dist/types/transformer/manuscript-dependencies.d.ts +0 -4
  112. package/dist/types/transformer/model-map.d.ts +0 -19
  113. package/dist/types/transformer/models.d.ts +0 -48
  114. package/dist/types/transformer/object-types.d.ts +0 -30
  115. package/dist/types/transformer/project-bundle.d.ts +0 -30
  116. package/dist/types/transformer/serializer.d.ts +0 -19
  117. package/dist/types/transformer/update-identifiers.d.ts +0 -23
  118. /package/dist/cjs/{transformer → jats}/filename.js +0 -0
  119. /package/dist/cjs/{transformer → jats}/timestamp.js +0 -0
  120. /package/dist/es/{transformer → jats}/filename.js +0 -0
  121. /package/dist/es/{transformer → jats}/timestamp.js +0 -0
  122. /package/dist/types/{transformer → jats}/filename.d.ts +0 -0
  123. /package/dist/types/{transformer → jats}/timestamp.d.ts +0 -0
@@ -23,44 +23,19 @@ const json_schema_1 = require("@manuscripts/json-schema");
23
23
  const library_1 = require("@manuscripts/library");
24
24
  const debug_1 = __importDefault(require("debug"));
25
25
  const prosemirror_model_1 = require("prosemirror-model");
26
+ const prosemirror_utils_1 = require("prosemirror-utils");
26
27
  const w3c_xmlserializer_1 = __importDefault(require("w3c-xmlserializer"));
27
28
  const html_1 = require("../lib/html");
28
- const styled_content_1 = require("../lib/styled-content");
29
- const utils_1 = require("../lib/utils");
30
29
  const schema_1 = require("../schema");
31
- const filename_1 = require("../transformer/filename");
32
- const labels_1 = require("../transformer/labels");
33
30
  const node_types_1 = require("../transformer/node-types");
34
- const object_types_1 = require("../transformer/object-types");
35
- const project_bundle_1 = require("../transformer/project-bundle");
36
31
  const section_category_1 = require("../transformer/section-category");
32
+ const filename_1 = require("./filename");
37
33
  const jats_versions_1 = require("./jats-versions");
34
+ const labels_1 = require("./labels");
38
35
  const warn = (0, debug_1.default)('manuscripts-transform');
39
36
  const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
40
37
  const normalizeID = (id) => id.replace(/:/g, '_');
41
38
  const parser = prosemirror_model_1.DOMParser.fromSchema(schema_1.schema);
42
- const findChildNodeOfType = (node, nodeType) => {
43
- for (const child of (0, utils_1.iterateChildren)(node)) {
44
- if (child.type === nodeType) {
45
- return child;
46
- }
47
- }
48
- };
49
- const isContributor = (0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.Contributor);
50
- const CREDIT_VOCAB_IDENTIFIER = 'https://dictionary.casrai.org/Contributor_Roles';
51
- const chooseRoleVocabAttributes = (role) => {
52
- if (role.uri && role.uri.startsWith(CREDIT_VOCAB_IDENTIFIER)) {
53
- return {
54
- vocab: 'credit',
55
- 'vocab-identifier': CREDIT_VOCAB_IDENTIFIER,
56
- 'vocab-term': role.name,
57
- 'vocab-term-identifier': role.uri,
58
- };
59
- }
60
- return {
61
- vocab: 'uncontrolled',
62
- };
63
- };
64
39
  const insertAbstractNode = (articleMeta, abstractNode) => {
65
40
  const siblings = [
66
41
  'kwd-group',
@@ -98,24 +73,24 @@ const createDefaultIdGenerator = () => {
98
73
  return `${element.localName}-${value}`;
99
74
  };
100
75
  };
101
- const chooseRefType = (objectType) => {
102
- switch (objectType) {
103
- case json_schema_1.ObjectTypes.Figure:
104
- case json_schema_1.ObjectTypes.FigureElement:
76
+ const chooseRefType = (type) => {
77
+ switch (type) {
78
+ case schema_1.schema.nodes.figure:
79
+ case schema_1.schema.nodes.figure_element:
105
80
  return 'fig';
106
- case json_schema_1.ObjectTypes.Footnote:
81
+ case schema_1.schema.nodes.footnote:
107
82
  return 'fn';
108
- case json_schema_1.ObjectTypes.Table:
109
- case json_schema_1.ObjectTypes.TableElement:
83
+ case schema_1.schema.nodes.table:
84
+ case schema_1.schema.nodes.table_element:
110
85
  return 'table';
111
- case json_schema_1.ObjectTypes.Section:
86
+ case schema_1.schema.nodes.section:
112
87
  return 'sec';
113
- case json_schema_1.ObjectTypes.Equation:
114
- case json_schema_1.ObjectTypes.EquationElement:
88
+ case schema_1.schema.nodes.equation:
89
+ case schema_1.schema.nodes.equation_element:
115
90
  return 'disp-formula';
116
91
  }
117
92
  };
118
- const sortContributors = (a, b) => Number(a.priority) - Number(b.priority);
93
+ const sortContributors = (a, b) => Number(a.attrs.priority) - Number(b.attrs.priority);
119
94
  const buildCitations = (citations) => citations.map((citation) => ({
120
95
  citationID: citation.attrs.id,
121
96
  citationItems: citation.attrs.rids.map((rid) => ({
@@ -128,39 +103,57 @@ const buildCitations = (citations) => citations.map((citation) => ({
128
103
  exports.buildCitations = buildCitations;
129
104
  class JATSExporter {
130
105
  constructor() {
131
- this.serializeToJATS = async (fragment, modelMap, manuscriptID, options) => {
132
- const { version = '1.2', doi, id, frontMatterOnly = false, links, idGenerator, mediaPathGenerator, csl, } = options;
133
- this.modelMap = modelMap;
134
- this.models = Array.from(this.modelMap.values());
135
- this.generateCitationTexts(fragment, csl);
106
+ this.getLibraryItem = (manuscriptID) => {
107
+ return (id) => {
108
+ var _a;
109
+ const node = (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attrs) => attrs.id === id)[0]) === null || _a === void 0 ? void 0 : _a.node;
110
+ if (!node) {
111
+ return undefined;
112
+ }
113
+ return {
114
+ _id: node.attrs.id,
115
+ issued: node.attrs.issued,
116
+ DOI: node.attrs.doi,
117
+ manuscriptID,
118
+ objectType: json_schema_1.ObjectTypes.BibliographyItem,
119
+ author: node.attrs.author,
120
+ 'container-title': node.attrs.containerTitle,
121
+ volume: node.attrs.volume,
122
+ issue: node.attrs.issue,
123
+ supplement: node.attrs.supplement,
124
+ page: node.attrs.page,
125
+ title: node.attrs.title,
126
+ literal: node.attrs.literal,
127
+ type: node.attrs.type,
128
+ };
129
+ };
130
+ };
131
+ this.serializeToJATS = async (manuscriptNode, csl, manuscript, jorunal) => {
132
+ const version = '1.2';
133
+ this.manuscriptNode = manuscriptNode;
134
+ this.generateCitationTexts(csl, manuscriptNode.attrs.id);
136
135
  this.createSerializer();
137
136
  const versionIds = (0, jats_versions_1.selectVersionIds)(version);
138
137
  this.document = document.implementation.createDocument(null, 'article', document.implementation.createDocumentType('article', versionIds.publicId, versionIds.systemId));
139
138
  const article = this.document.documentElement;
140
139
  article.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', XLINK_NAMESPACE);
141
- const front = this.buildFront(doi, id, links);
140
+ const front = this.buildFront(manuscript, jorunal);
142
141
  article.appendChild(front);
143
- const manuscript = (0, project_bundle_1.findManuscriptById)(this.modelMap, manuscriptID);
144
142
  article.setAttribute('article-type', manuscript.articleType || 'other');
145
- if (!frontMatterOnly) {
146
- this.labelTargets = (0, labels_1.buildTargets)(fragment);
147
- const body = this.buildBody(fragment);
148
- article.appendChild(body);
149
- const back = this.buildBack(body);
150
- this.moveCoiStatementToAuthorNotes(back, front);
151
- article.appendChild(back);
152
- this.unwrapBody(body);
153
- this.moveAbstracts(front, body);
154
- this.moveFloatsGroup(body, article);
155
- this.removeBackContainer(body);
156
- this.updateFootnoteTypes(front, back);
157
- this.fillEmptyTableFooters(article);
158
- this.fillEmptyFootnotes(article);
159
- }
160
- await this.rewriteIDs(idGenerator);
161
- if (mediaPathGenerator) {
162
- await this.rewriteMediaPaths(mediaPathGenerator);
163
- }
143
+ this.labelTargets = (0, labels_1.buildTargets)(manuscriptNode);
144
+ const body = this.buildBody();
145
+ article.appendChild(body);
146
+ const back = this.buildBack(body);
147
+ this.moveCoiStatementToAuthorNotes(back, front);
148
+ article.appendChild(back);
149
+ this.unwrapBody(body);
150
+ this.moveAbstracts(front, body);
151
+ this.moveFloatsGroup(body, article);
152
+ this.removeBackContainer(body);
153
+ this.updateFootnoteTypes(front, back);
154
+ this.fillEmptyTableFooters(article);
155
+ this.fillEmptyFootnotes(article);
156
+ await this.rewriteIDs();
164
157
  return (0, w3c_xmlserializer_1.default)(this.document);
165
158
  };
166
159
  this.nodeFromJATS = (JATSFragment) => {
@@ -227,16 +220,14 @@ class JATSExporter {
227
220
  }
228
221
  }
229
222
  };
230
- this.buildFront = (doi, id, links) => {
231
- var _a, _b, _c, _d, _e;
232
- const manuscript = (0, project_bundle_1.findManuscript)(this.modelMap);
233
- const titles = (0, project_bundle_1.findTitles)(this.modelMap);
223
+ this.buildFront = (manuscript, journal) => {
224
+ var _a;
225
+ const titleNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.title)[0]) === null || _a === void 0 ? void 0 : _a.node;
234
226
  const front = this.document.createElement('front');
235
227
  const journalMeta = this.document.createElement('journal-meta');
236
228
  front.appendChild(journalMeta);
237
229
  const articleMeta = this.document.createElement('article-meta');
238
230
  front.appendChild(articleMeta);
239
- const journal = [...this.modelMap.values()].find((model) => model.objectType === json_schema_1.ObjectTypes.Journal);
240
231
  if (journal) {
241
232
  if (journal.journalIdentifiers) {
242
233
  for (const item of journal.journalIdentifiers) {
@@ -285,92 +276,35 @@ class JATSExporter {
285
276
  journalMeta.appendChild(publisher);
286
277
  }
287
278
  }
288
- if (id) {
289
- const articleID = this.document.createElement('article-id');
290
- articleID.setAttribute('pub-id-type', 'publisher-id');
291
- articleID.textContent = id;
292
- articleMeta.appendChild(articleID);
293
- }
294
- if (doi || manuscript.DOI) {
279
+ if (manuscript.DOI) {
295
280
  const articleID = this.document.createElement('article-id');
296
281
  articleID.setAttribute('pub-id-type', 'doi');
297
- articleID.textContent = (_a = manuscript.DOI) !== null && _a !== void 0 ? _a : doi;
282
+ articleID.textContent = manuscript.DOI;
298
283
  articleMeta.appendChild(articleID);
299
284
  }
300
285
  const titleGroup = this.document.createElement('title-group');
301
286
  articleMeta.appendChild(titleGroup);
302
287
  this.buildContributors(articleMeta);
303
- if (links && links.self) {
304
- for (const [key, value] of Object.entries(links.self)) {
305
- const link = this.document.createElement('self-uri');
306
- link.setAttribute('content-type', key);
307
- link.setAttributeNS(XLINK_NAMESPACE, 'href', value);
308
- articleMeta.appendChild(link);
309
- }
310
- }
311
- if (titles.title) {
288
+ if (titleNode) {
312
289
  const element = this.document.createElement('article-title');
313
- this.setTitleContent(element, titles.title);
290
+ this.setTitleContent(element, titleNode.textContent);
314
291
  titleGroup.appendChild(element);
315
292
  }
316
- if (titles.subtitle) {
317
- const element = this.document.createElement('subtitle');
318
- this.setTitleContent(element, titles.subtitle);
319
- titleGroup.appendChild(element);
320
- }
321
- if (titles.runningTitle) {
322
- const element = this.document.createElement('alt-title');
323
- element.setAttribute('alt-title-type', 'right-running');
324
- this.setTitleContent(element, titles.runningTitle);
325
- titleGroup.appendChild(element);
326
- }
327
- const supplements = [...this.modelMap.values()].filter((model) => model.objectType === json_schema_1.ObjectTypes.Supplement);
328
- if (supplements && supplements.length > 0) {
329
- for (const supplement of supplements) {
330
- const supplementaryMaterial = this.document.createElement('supplementary-material');
331
- supplementaryMaterial.setAttribute('id', normalizeID(supplement._id));
332
- supplementaryMaterial.setAttributeNS(XLINK_NAMESPACE, 'href', (_b = supplement.href) !== null && _b !== void 0 ? _b : '');
333
- const mimeType = (_c = supplement.MIME) === null || _c === void 0 ? void 0 : _c.split('/')[0];
334
- const mimeSubType = (_d = supplement.MIME) === null || _d === void 0 ? void 0 : _d.split('/')[1];
335
- supplementaryMaterial.setAttribute('mimetype', mimeType !== null && mimeType !== void 0 ? mimeType : '');
336
- supplementaryMaterial.setAttribute('mime-subtype', mimeSubType !== null && mimeSubType !== void 0 ? mimeSubType : '');
337
- const caption = this.document.createElement('caption');
338
- const title = this.document.createElement('title');
339
- title.textContent = (_e = supplement.title) !== null && _e !== void 0 ? _e : '';
340
- caption.append(title);
341
- supplementaryMaterial.append(caption);
342
- articleMeta.append(supplementaryMaterial);
343
- }
344
- }
345
- const history = articleMeta.querySelector('history') ||
346
- this.document.createElement('history');
347
- if (manuscript.acceptanceDate) {
348
- const date = this.buildDateElement(manuscript.acceptanceDate, 'accepted');
349
- history.appendChild(date);
350
- }
351
- if (manuscript.correctionDate) {
352
- const date = this.buildDateElement(manuscript.correctionDate, 'corrected');
353
- history.appendChild(date);
354
- }
355
- if (manuscript.retractionDate) {
356
- const date = this.buildDateElement(manuscript.retractionDate, 'retracted');
357
- history.appendChild(date);
358
- }
359
- if (manuscript.receiveDate) {
360
- const date = this.buildDateElement(manuscript.receiveDate, 'received');
361
- history.appendChild(date);
362
- }
363
- if (manuscript.revisionReceiveDate) {
364
- const date = this.buildDateElement(manuscript.revisionReceiveDate, 'rev-recd');
365
- history.appendChild(date);
366
- }
367
- if (manuscript.revisionRequestDate) {
368
- const date = this.buildDateElement(manuscript.revisionRequestDate, 'rev-request');
369
- history.appendChild(date);
370
- }
371
- if (history.childElementCount) {
372
- articleMeta.appendChild(history);
373
- }
293
+ const supplementsNodes = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.supplement);
294
+ supplementsNodes.forEach(({ node }) => {
295
+ var _a, _b, _c, _d;
296
+ const supplementaryMaterial = this.document.createElement('supplementary-material');
297
+ supplementaryMaterial.setAttribute('id', normalizeID(node.attrs.id));
298
+ supplementaryMaterial.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = node.attrs.href) !== null && _a !== void 0 ? _a : '');
299
+ supplementaryMaterial.setAttribute('mimetype', (_b = node.attrs.mimeType) !== null && _b !== void 0 ? _b : '');
300
+ supplementaryMaterial.setAttribute('mime-subtype', (_c = node.attrs.mimeSubType) !== null && _c !== void 0 ? _c : '');
301
+ const caption = this.document.createElement('caption');
302
+ const title = this.document.createElement('title');
303
+ title.textContent = (_d = node.attrs.title) !== null && _d !== void 0 ? _d : '';
304
+ caption.append(title);
305
+ supplementaryMaterial.append(caption);
306
+ articleMeta.append(supplementaryMaterial);
307
+ });
374
308
  this.buildKeywords(articleMeta);
375
309
  let countingElements = [];
376
310
  if (manuscript.genericCounts) {
@@ -383,11 +317,16 @@ class JATSExporter {
383
317
  });
384
318
  countingElements.push(...elements);
385
319
  }
386
- countingElements.push(this.buildCountingElement('fig-count', manuscript.figureCount));
387
- countingElements.push(this.buildCountingElement('table-count', manuscript.tableCount));
388
- countingElements.push(this.buildCountingElement('equation-count', manuscript.equationCount));
389
- countingElements.push(this.buildCountingElement('ref-count', manuscript.referencesCount));
390
- countingElements.push(this.buildCountingElement('word-count', manuscript.wordCount));
320
+ const figureCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.figure).length;
321
+ countingElements.push(this.buildCountingElement('fig-count', figureCount));
322
+ const equationCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.equation_element).length;
323
+ const tableCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.table).length;
324
+ const referencesCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.bibliography_item).length;
325
+ countingElements.push(this.buildCountingElement('table-count', tableCount));
326
+ countingElements.push(this.buildCountingElement('equation-count', equationCount));
327
+ countingElements.push(this.buildCountingElement('ref-count', referencesCount));
328
+ const wordCount = this.manuscriptNode.textContent.split(/\s+/).length;
329
+ countingElements.push(this.buildCountingElement('word-count', wordCount));
391
330
  countingElements = countingElements.filter((el) => el);
392
331
  if (countingElements.length > 0) {
393
332
  const counts = this.document.createElement('counts');
@@ -422,16 +361,17 @@ class JATSExporter {
422
361
  return wordCount;
423
362
  }
424
363
  };
425
- this.buildBody = (fragment) => {
364
+ this.buildBody = () => {
426
365
  const body = this.document.createElement('body');
427
- fragment.forEach((cFragment) => {
366
+ this.manuscriptNode.forEach((cFragment) => {
428
367
  const serializedNode = this.serializeNode(cFragment);
429
368
  body.append(...serializedNode.childNodes);
430
369
  });
431
- this.fixBody(body, fragment);
370
+ this.fixBody(body);
432
371
  return body;
433
372
  };
434
373
  this.buildBack = (body) => {
374
+ var _a;
435
375
  const back = this.document.createElement('back');
436
376
  this.moveSectionsToBack(back, body);
437
377
  const footnotesElements = this.document.querySelectorAll('sec > fn-group');
@@ -456,7 +396,7 @@ class JATSExporter {
456
396
  back.appendChild(refList);
457
397
  const [meta] = this.citationProvider.makeBibliography();
458
398
  for (const id of meta.entry_ids) {
459
- const bibliographyItem = this.modelMap.get(id[0]);
399
+ const bibliographyNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.bibliography_item).find(({ node }) => node.attrs.id === id[0])) === null || _a === void 0 ? void 0 : _a.node;
460
400
  const ref = this.document.createElement('ref');
461
401
  ref.setAttribute('id', normalizeID(id[0]));
462
402
  const updateCitationPubType = (citationEl, pubType) => {
@@ -475,21 +415,21 @@ class JATSExporter {
475
415
  citationEl.setAttribute('publication-type', 'journal');
476
416
  }
477
417
  };
478
- if (bibliographyItem.literal) {
418
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.literal) {
479
419
  const mixedCitation = this.document.createElement('mixed-citation');
480
- updateCitationPubType(mixedCitation, bibliographyItem.type);
481
- mixedCitation.textContent = bibliographyItem.literal;
420
+ updateCitationPubType(mixedCitation, bibliographyNode.attrs.type);
421
+ mixedCitation.textContent = bibliographyNode.attrs.literal;
482
422
  ref.appendChild(mixedCitation);
483
423
  refList.appendChild(ref);
484
424
  }
485
425
  else {
486
426
  const citation = this.document.createElement('element-citation');
487
- updateCitationPubType(citation, bibliographyItem.type);
488
- if (bibliographyItem.author) {
427
+ updateCitationPubType(citation, bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.type);
428
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.author) {
489
429
  const personGroupNode = this.document.createElement('person-group');
490
430
  personGroupNode.setAttribute('person-group-type', 'author');
491
431
  citation.appendChild(personGroupNode);
492
- bibliographyItem.author.forEach((author) => {
432
+ bibliographyNode.attrs.author.forEach((author) => {
493
433
  const name = this.document.createElement('string-name');
494
434
  if (author.family) {
495
435
  const node = this.document.createElement('surname');
@@ -511,8 +451,8 @@ class JATSExporter {
511
451
  }
512
452
  });
513
453
  }
514
- if (bibliographyItem.issued) {
515
- const dateParts = bibliographyItem.issued['date-parts'];
454
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issued) {
455
+ const dateParts = bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issued['date-parts'];
516
456
  if (dateParts && dateParts.length) {
517
457
  const [[year, month, day]] = dateParts;
518
458
  if (year) {
@@ -532,33 +472,33 @@ class JATSExporter {
532
472
  }
533
473
  }
534
474
  }
535
- if (bibliographyItem.title) {
475
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.title) {
536
476
  const node = this.document.createElement('article-title');
537
- this.setTitleContent(node, bibliographyItem.title);
477
+ this.setTitleContent(node, bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.title);
538
478
  citation.appendChild(node);
539
479
  }
540
- if (bibliographyItem['container-title']) {
480
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.containerTitle) {
541
481
  const node = this.document.createElement('source');
542
- node.textContent = bibliographyItem['container-title'];
482
+ node.textContent = bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.containerTitle;
543
483
  citation.appendChild(node);
544
484
  }
545
- if (bibliographyItem.volume) {
485
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.volume) {
546
486
  const node = this.document.createElement('volume');
547
- node.textContent = String(bibliographyItem.volume);
487
+ node.textContent = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.volume);
548
488
  citation.appendChild(node);
549
489
  }
550
- if (bibliographyItem.issue) {
490
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issue) {
551
491
  const node = this.document.createElement('issue');
552
- node.textContent = String(bibliographyItem.issue);
492
+ node.textContent = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issue);
553
493
  citation.appendChild(node);
554
494
  }
555
- if (bibliographyItem.supplement) {
495
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.supplement) {
556
496
  const node = this.document.createElement('supplement');
557
- node.textContent = bibliographyItem.supplement;
497
+ node.textContent = bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.supplement;
558
498
  citation.appendChild(node);
559
499
  }
560
- if (bibliographyItem.page) {
561
- const pageString = String(bibliographyItem.page);
500
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.page) {
501
+ const pageString = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.page);
562
502
  if (/^\d+$/.test(pageString)) {
563
503
  const node = this.document.createElement('fpage');
564
504
  node.textContent = pageString;
@@ -579,10 +519,10 @@ class JATSExporter {
579
519
  citation.appendChild(node);
580
520
  }
581
521
  }
582
- if (bibliographyItem.DOI) {
522
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.doi) {
583
523
  const node = this.document.createElement('pub-id');
584
524
  node.setAttribute('pub-id-type', 'doi');
585
- node.textContent = String(bibliographyItem.DOI);
525
+ node.textContent = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.doi);
586
526
  citation.appendChild(node);
587
527
  }
588
528
  ref.appendChild(citation);
@@ -592,8 +532,8 @@ class JATSExporter {
592
532
  return back;
593
533
  };
594
534
  this.createSerializer = () => {
595
- const getModel = (id) => id ? this.modelMap.get(id) : undefined;
596
535
  const nodes = {
536
+ box_element: () => ['boxed-text', 0],
597
537
  author_notes: () => '',
598
538
  corresp: () => '',
599
539
  title: () => '',
@@ -654,24 +594,25 @@ class JATSExporter {
654
594
  return xref;
655
595
  },
656
596
  cross_reference: (node) => {
597
+ var _a;
657
598
  const cross = node;
658
599
  const rids = cross.attrs.rids;
659
600
  if (!rids.length) {
660
601
  return cross.attrs.label;
661
602
  }
662
603
  const text = cross.attrs.customLabel || cross.attrs.label;
663
- const model = getModel(rids[0]);
664
- if (!model) {
604
+ const target = (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attrs) => attrs.id === rids[0])[0]) === null || _a === void 0 ? void 0 : _a.node;
605
+ if (!target) {
665
606
  warn('');
666
607
  return text;
667
608
  }
668
609
  const xref = this.document.createElement('xref');
669
- const type = chooseRefType(model.objectType);
610
+ const type = chooseRefType(target.type);
670
611
  if (type) {
671
612
  xref.setAttribute('ref-type', type);
672
613
  }
673
614
  else {
674
- warn(`Unset ref-type for objectType ${model.objectType}`);
615
+ warn(`Unset ref-type for schema type ${target.type.name}`);
675
616
  }
676
617
  xref.setAttribute('rid', normalizeID(rids.join(' ')));
677
618
  xref.textContent = text;
@@ -743,7 +684,10 @@ class JATSExporter {
743
684
  hard_break: () => '',
744
685
  highlight_marker: () => '',
745
686
  inline_footnote: (node) => {
746
- const rids = node.attrs.rids.filter(getModel);
687
+ const rids = node.attrs.rids.filter((rid) => {
688
+ var _a;
689
+ return (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attrs) => attrs.id === rid)[0]) === null || _a === void 0 ? void 0 : _a.node;
690
+ });
747
691
  if (rids.length == 0) {
748
692
  return '';
749
693
  }
@@ -862,14 +806,7 @@ class JATSExporter {
862
806
  italic: () => ['italic'],
863
807
  smallcaps: () => ['sc'],
864
808
  strikethrough: () => ['strike'],
865
- styled: (mark) => {
866
- const inlineStyle = getModel(mark.attrs.rid);
867
- const attrs = {};
868
- if (inlineStyle && inlineStyle.title) {
869
- attrs.style = (0, styled_content_1.normalizeStyleName)(inlineStyle.title);
870
- }
871
- return ['styled-content', attrs];
872
- },
809
+ styled: () => ['styled-content'],
873
810
  superscript: () => ['sup'],
874
811
  subscript: () => ['sub'],
875
812
  underline: () => ['underline'],
@@ -920,14 +857,16 @@ class JATSExporter {
920
857
  }
921
858
  };
922
859
  const appendChildNodeOfType = (element, node, type) => {
923
- const childNode = findChildNodeOfType(node, type);
860
+ var _a;
861
+ const childNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, type)[0]) === null || _a === void 0 ? void 0 : _a.node;
924
862
  if (childNode) {
925
863
  element.appendChild(this.serializeNode(childNode));
926
864
  }
927
865
  };
928
866
  const appendTable = (element, node) => {
929
- const tableNode = findChildNodeOfType(node, node.type.schema.nodes.table);
930
- const colGroupNode = findChildNodeOfType(node, node.type.schema.nodes.table_colgroup);
867
+ var _a, _b;
868
+ const tableNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.table)[0]) === null || _a === void 0 ? void 0 : _a.node;
869
+ const colGroupNode = (_b = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.table_colgroup)[0]) === null || _b === void 0 ? void 0 : _b.node;
931
870
  if (!tableNode) {
932
871
  return;
933
872
  }
@@ -973,7 +912,8 @@ class JATSExporter {
973
912
  return element;
974
913
  };
975
914
  const processExecutableNode = (node, element) => {
976
- const listingNode = findChildNodeOfType(node, node.type.schema.nodes.listing);
915
+ var _a;
916
+ const listingNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.listing)[0]) === null || _a === void 0 ? void 0 : _a.node;
977
917
  if (listingNode) {
978
918
  const { contents, languageKey } = listingNode.attrs;
979
919
  if (contents && languageKey) {
@@ -1007,25 +947,25 @@ class JATSExporter {
1007
947
  }
1008
948
  };
1009
949
  };
1010
- this.serializeFragment = (fragment) => this.serializer.serializeFragment(fragment, {
1011
- document: this.document,
1012
- });
1013
950
  this.serializeNode = (node) => this.serializer.serializeNode(node, {
1014
951
  document: this.document,
1015
952
  });
1016
953
  this.validateContributor = (contributor) => {
1017
- if (!contributor.bibliographicName) {
1018
- throw new Error(`${contributor._id} has no bibliographicName`);
954
+ if (!contributor.attrs.bibliographicName) {
955
+ throw new Error(`${contributor.attrs.id} has no bibliographicName`);
1019
956
  }
1020
- const { family, given } = contributor.bibliographicName;
957
+ const { family, given } = contributor.attrs.bibliographicName;
1021
958
  if (!family && !given) {
1022
- throw new Error(`${contributor._id} has neither family nor given name`);
959
+ throw new Error(`${contributor.attrs.id} has neither family nor given name`);
1023
960
  }
1024
961
  };
1025
962
  this.buildContributors = (articleMeta) => {
1026
- const contributors = this.models.filter(isContributor);
1027
- const authorContributors = contributors
1028
- .filter((contributor) => contributor.role === 'author')
963
+ const contributorNodes = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.contributor).map((result) => result.node);
964
+ const authorContributorNodes = contributorNodes
965
+ .filter((n) => n.attrs.role === 'author')
966
+ .sort(sortContributors);
967
+ const otherContributorsNodes = contributorNodes
968
+ .filter((n) => n.attrs.role !== 'author')
1029
969
  .sort(sortContributors);
1030
970
  const affiliationLabels = new Map();
1031
971
  const creatAffiliationLabel = (rid) => {
@@ -1043,11 +983,11 @@ class JATSExporter {
1043
983
  sup.textContent = String(content);
1044
984
  return sup;
1045
985
  };
1046
- if (authorContributors.length) {
986
+ if (authorContributorNodes.length) {
1047
987
  const contribGroup = this.document.createElement('contrib-group');
1048
988
  contribGroup.setAttribute('content-type', 'authors');
1049
989
  articleMeta.appendChild(contribGroup);
1050
- authorContributors.forEach((contributor) => {
990
+ authorContributorNodes.forEach((contributor) => {
1051
991
  try {
1052
992
  this.validateContributor(contributor);
1053
993
  }
@@ -1057,39 +997,25 @@ class JATSExporter {
1057
997
  }
1058
998
  const contrib = this.document.createElement('contrib');
1059
999
  contrib.setAttribute('contrib-type', 'author');
1060
- contrib.setAttribute('id', normalizeID(contributor._id));
1061
- if (contributor.isCorresponding) {
1000
+ contrib.setAttribute('id', normalizeID(contributor.attrs.id));
1001
+ if (contributor.attrs.isCorresponding) {
1062
1002
  contrib.setAttribute('corresp', 'yes');
1063
1003
  }
1064
- if (contributor.ORCIDIdentifier) {
1004
+ if (contributor.attrs.ORCIDIdentifier) {
1065
1005
  const identifier = this.document.createElement('contrib-id');
1066
1006
  identifier.setAttribute('contrib-id-type', 'orcid');
1067
- identifier.textContent = contributor.ORCIDIdentifier;
1007
+ identifier.textContent = contributor.attrs.ORCIDIdentifier;
1068
1008
  contrib.appendChild(identifier);
1069
1009
  }
1070
1010
  const name = this.buildContributorName(contributor);
1071
1011
  contrib.appendChild(name);
1072
- if (contributor.email) {
1012
+ if (contributor.attrs.email) {
1073
1013
  const email = this.document.createElement('email');
1074
- email.textContent = contributor.email;
1014
+ email.textContent = contributor.attrs.email;
1075
1015
  contrib.appendChild(email);
1076
1016
  }
1077
- if (contributor.roles) {
1078
- contributor.roles.forEach((rid) => {
1079
- const contributorRole = this.modelMap.get(rid);
1080
- if (contributorRole) {
1081
- const role = this.document.createElement('role');
1082
- const attributes = chooseRoleVocabAttributes(contributorRole);
1083
- for (const [key, value] of Object.entries(attributes)) {
1084
- role.setAttribute(key, value);
1085
- }
1086
- role.textContent = contributorRole.name;
1087
- contrib.appendChild(role);
1088
- }
1089
- });
1090
- }
1091
- if (contributor.affiliations) {
1092
- contributor.affiliations.forEach((rid) => {
1017
+ if (contributor.attrs.affiliations) {
1018
+ contributor.attrs.affiliations.forEach((rid) => {
1093
1019
  const xref = this.document.createElement('xref');
1094
1020
  xref.setAttribute('ref-type', 'aff');
1095
1021
  xref.setAttribute('rid', normalizeID(rid));
@@ -1097,8 +1023,8 @@ class JATSExporter {
1097
1023
  contrib.appendChild(xref);
1098
1024
  });
1099
1025
  }
1100
- if (contributor.footnote) {
1101
- contributor.footnote.map((note) => {
1026
+ if (contributor.attrs.footnote) {
1027
+ contributor.attrs.footnote.map((note) => {
1102
1028
  const xref = this.document.createElement('xref');
1103
1029
  xref.setAttribute('ref-type', 'fn');
1104
1030
  xref.setAttribute('rid', normalizeID(note.noteID));
@@ -1106,8 +1032,8 @@ class JATSExporter {
1106
1032
  contrib.appendChild(xref);
1107
1033
  });
1108
1034
  }
1109
- if (contributor.corresp) {
1110
- contributor.corresp.map((corresp) => {
1035
+ if (contributor.attrs.corresp) {
1036
+ contributor.attrs.corresp.map((corresp) => {
1111
1037
  const xref = this.document.createElement('xref');
1112
1038
  xref.setAttribute('ref-type', 'corresp');
1113
1039
  xref.setAttribute('rid', normalizeID(corresp.correspID));
@@ -1117,13 +1043,10 @@ class JATSExporter {
1117
1043
  }
1118
1044
  contribGroup.appendChild(contrib);
1119
1045
  });
1120
- const otherContributors = contributors
1121
- .filter((contributor) => contributor.role !== 'author')
1122
- .sort(sortContributors);
1123
- if (otherContributors.length) {
1046
+ if (otherContributorsNodes.length) {
1124
1047
  const contribGroup = this.document.createElement('contrib-group');
1125
1048
  articleMeta.appendChild(contribGroup);
1126
- otherContributors.forEach((contributor) => {
1049
+ otherContributorsNodes.forEach((contributor) => {
1127
1050
  try {
1128
1051
  this.validateContributor(contributor);
1129
1052
  }
@@ -1132,30 +1055,16 @@ class JATSExporter {
1132
1055
  return;
1133
1056
  }
1134
1057
  const contrib = this.document.createElement('contrib');
1135
- contrib.setAttribute('id', normalizeID(contributor._id));
1058
+ contrib.setAttribute('id', normalizeID(contributor.attrs.id));
1136
1059
  const name = this.buildContributorName(contributor);
1137
1060
  contrib.appendChild(name);
1138
- if (contributor.email) {
1061
+ if (contributor.attrs.email) {
1139
1062
  const email = this.document.createElement('email');
1140
- email.textContent = contributor.email;
1063
+ email.textContent = contributor.attrs.email;
1141
1064
  contrib.appendChild(email);
1142
1065
  }
1143
- if (contributor.roles) {
1144
- contributor.roles.forEach((rid) => {
1145
- const contributorRole = this.modelMap.get(rid);
1146
- if (contributorRole) {
1147
- const role = this.document.createElement('role');
1148
- const attributes = chooseRoleVocabAttributes(contributorRole);
1149
- for (const [key, value] of Object.entries(attributes)) {
1150
- role.setAttribute(key, value);
1151
- }
1152
- role.textContent = contributorRole.name;
1153
- contrib.appendChild(role);
1154
- }
1155
- });
1156
- }
1157
- if (contributor.affiliations) {
1158
- contributor.affiliations.forEach((rid) => {
1066
+ if (contributor.attrs.affiliations) {
1067
+ contributor.attrs.affiliations.forEach((rid) => {
1159
1068
  const xref = this.document.createElement('xref');
1160
1069
  xref.setAttribute('ref-type', 'aff');
1161
1070
  xref.setAttribute('rid', normalizeID(rid));
@@ -1163,8 +1072,8 @@ class JATSExporter {
1163
1072
  contrib.appendChild(xref);
1164
1073
  });
1165
1074
  }
1166
- if (contributor.footnote) {
1167
- contributor.footnote.map((note) => {
1075
+ if (contributor.attrs.footnote) {
1076
+ contributor.attrs.footnote.map((note) => {
1168
1077
  const xref = this.document.createElement('xref');
1169
1078
  xref.setAttribute('ref-type', 'fn');
1170
1079
  xref.setAttribute('rid', normalizeID(note.noteID));
@@ -1176,64 +1085,68 @@ class JATSExporter {
1176
1085
  });
1177
1086
  }
1178
1087
  const affiliationRIDs = [];
1179
- const sortedContributors = [...authorContributors, ...otherContributors];
1088
+ const sortedContributors = [
1089
+ ...authorContributorNodes,
1090
+ ...otherContributorsNodes,
1091
+ ];
1180
1092
  for (const contributor of sortedContributors) {
1181
- if (contributor.affiliations) {
1182
- affiliationRIDs.push(...contributor.affiliations);
1093
+ if (contributor.attrs.affiliations) {
1094
+ affiliationRIDs.push(...contributor.attrs.affiliations);
1183
1095
  }
1184
1096
  }
1185
- const affiliations = this.models.filter((0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.Affiliation));
1097
+ const affiliations = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.affiliation).map((result) => result.node);
1186
1098
  if (affiliations) {
1187
- const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation._id));
1188
- usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a._id) - affiliationRIDs.indexOf(b._id));
1099
+ const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation.attrs.id));
1100
+ usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a.attrs.id) -
1101
+ affiliationRIDs.indexOf(b.attrs.id));
1189
1102
  usedAffiliations.forEach((affiliation) => {
1190
1103
  var _a, _b;
1191
1104
  const aff = this.document.createElement('aff');
1192
- aff.setAttribute('id', normalizeID(affiliation._id));
1105
+ aff.setAttribute('id', normalizeID(affiliation.attrs.id));
1193
1106
  contribGroup.appendChild(aff);
1194
- if (affiliation.department) {
1107
+ if (affiliation.attrs.department) {
1195
1108
  const department = this.document.createElement('institution');
1196
1109
  department.setAttribute('content-type', 'dept');
1197
- department.textContent = affiliation.department;
1110
+ department.textContent = affiliation.attrs.department;
1198
1111
  aff.appendChild(department);
1199
1112
  }
1200
- if (affiliation.institution) {
1113
+ if (affiliation.attrs.institution) {
1201
1114
  const institution = this.document.createElement('institution');
1202
- institution.textContent = affiliation.institution;
1115
+ institution.textContent = affiliation.attrs.institution;
1203
1116
  aff.appendChild(institution);
1204
1117
  }
1205
- if (affiliation.addressLine1) {
1118
+ if (affiliation.attrs.addressLine1) {
1206
1119
  const addressLine = this.document.createElement('addr-line');
1207
- addressLine.textContent = affiliation.addressLine1;
1120
+ addressLine.textContent = affiliation.attrs.addressLine1;
1208
1121
  aff.appendChild(addressLine);
1209
1122
  }
1210
- if (affiliation.addressLine2) {
1123
+ if (affiliation.attrs.addressLine2) {
1211
1124
  const addressLine = this.document.createElement('addr-line');
1212
- addressLine.textContent = affiliation.addressLine2;
1125
+ addressLine.textContent = affiliation.attrs.addressLine2;
1213
1126
  aff.appendChild(addressLine);
1214
1127
  }
1215
- if (affiliation.addressLine3) {
1128
+ if (affiliation.attrs.addressLine3) {
1216
1129
  const addressLine = this.document.createElement('addr-line');
1217
- addressLine.textContent = affiliation.addressLine3;
1130
+ addressLine.textContent = affiliation.attrs.addressLine3;
1218
1131
  aff.appendChild(addressLine);
1219
1132
  }
1220
- if (affiliation.city) {
1133
+ if (affiliation.attrs.city) {
1221
1134
  const city = this.document.createElement('city');
1222
- city.textContent = affiliation.city;
1135
+ city.textContent = affiliation.attrs.city;
1223
1136
  aff.appendChild(city);
1224
1137
  }
1225
- if (affiliation.country) {
1138
+ if (affiliation.attrs.country) {
1226
1139
  const country = this.document.createElement('country');
1227
- country.textContent = affiliation.country;
1140
+ country.textContent = affiliation.attrs.country;
1228
1141
  aff.appendChild(country);
1229
1142
  }
1230
- if (affiliation.email) {
1143
+ if (affiliation.attrs.email) {
1231
1144
  const email = this.document.createElement('email');
1232
- email.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = affiliation.email.href) !== null && _a !== void 0 ? _a : '');
1233
- email.textContent = (_b = affiliation.email.text) !== null && _b !== void 0 ? _b : '';
1145
+ email.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = affiliation.attrs.email.href) !== null && _a !== void 0 ? _a : '');
1146
+ email.textContent = (_b = affiliation.attrs.email.text) !== null && _b !== void 0 ? _b : '';
1234
1147
  aff.appendChild(email);
1235
1148
  }
1236
- const labelNumber = affiliationLabels.get(affiliation._id);
1149
+ const labelNumber = affiliationLabels.get(affiliation.attrs.id);
1237
1150
  if (labelNumber) {
1238
1151
  const label = this.document.createElement('label');
1239
1152
  label.textContent = String(labelNumber);
@@ -1250,41 +1163,48 @@ class JATSExporter {
1250
1163
  this.createAuthorNotesElement = () => {
1251
1164
  var _a;
1252
1165
  const authorNotesEl = this.document.createElement('author-notes');
1253
- const authorNotes = (_a = (0, json_schema_1.getModelsByType)(this.modelMap, json_schema_1.ObjectTypes.AuthorNotes)) === null || _a === void 0 ? void 0 : _a[0];
1254
- if (authorNotes) {
1255
- this.appendModelsToAuthorNotes(authorNotesEl, authorNotes.containedObjectIDs);
1166
+ const authorNotesNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.author_notes)[0]) === null || _a === void 0 ? void 0 : _a.node;
1167
+ if (authorNotesNode) {
1168
+ this.appendModelsToAuthorNotes(authorNotesEl, authorNotesNode);
1256
1169
  }
1257
1170
  return authorNotesEl;
1258
1171
  };
1259
1172
  this.appendCorrespondingToElement = (corresponding, element) => {
1260
1173
  const correspondingEl = this.document.createElement('corresp');
1261
- correspondingEl.setAttribute('id', normalizeID(corresponding._id));
1262
- if (corresponding.label) {
1174
+ correspondingEl.setAttribute('id', normalizeID(corresponding.attrs.id));
1175
+ if (corresponding.attrs.label) {
1263
1176
  const labelEl = this.document.createElement('label');
1264
- labelEl.textContent = corresponding.label;
1177
+ labelEl.textContent = corresponding.attrs.label;
1265
1178
  correspondingEl.appendChild(labelEl);
1266
1179
  }
1267
- correspondingEl.append(corresponding.contents);
1180
+ correspondingEl.append(corresponding.textContent);
1268
1181
  element.appendChild(correspondingEl);
1269
1182
  };
1270
1183
  this.appendParagraphToElement = (paragraph, element) => {
1271
- const parsedDoc = new DOMParser().parseFromString(paragraph.contents, 'text/html');
1184
+ const parsedDoc = new DOMParser().parseFromString(paragraph.textContent, 'text/html');
1272
1185
  const parsedParagraph = parsedDoc.body.querySelector('p');
1273
1186
  if (parsedParagraph) {
1274
1187
  const paragraphEl = this.document.createElement('p');
1275
1188
  paragraphEl.innerHTML = parsedParagraph.innerHTML;
1276
- paragraphEl.setAttribute('id', normalizeID(paragraph._id));
1189
+ paragraphEl.setAttribute('id', normalizeID(paragraph.attrs.id));
1277
1190
  element.appendChild(paragraphEl);
1278
1191
  }
1279
1192
  };
1280
1193
  this.appendFootnoteToElement = (footnote, element) => {
1281
1194
  const footnoteEl = this.document.createElement('fn');
1282
- footnoteEl.setAttribute('id', normalizeID(footnote._id));
1283
- footnoteEl.innerHTML = footnote.contents;
1195
+ footnoteEl.setAttribute('id', normalizeID(footnote.attrs.id));
1196
+ if (!footnote.textContent.includes('<p>')) {
1197
+ const p = this.document.createElement('p');
1198
+ p.innerHTML = footnote.textContent;
1199
+ footnoteEl.appendChild(p);
1200
+ }
1201
+ else {
1202
+ footnoteEl.innerHTML = footnote.textContent;
1203
+ }
1284
1204
  element.appendChild(footnoteEl);
1285
1205
  };
1286
- this.fixBody = (body, fragment) => {
1287
- fragment.descendants((node) => {
1206
+ this.fixBody = (body) => {
1207
+ this.manuscriptNode.descendants((node) => {
1288
1208
  if (node.attrs.id) {
1289
1209
  if (node.attrs.titleSuppressed) {
1290
1210
  const title = body.querySelector(`#${normalizeID(node.attrs.id)} > title`);
@@ -1545,36 +1465,36 @@ class JATSExporter {
1545
1465
  };
1546
1466
  this.buildContributorName = (contributor) => {
1547
1467
  const name = this.document.createElement('name');
1548
- if (contributor.bibliographicName.family) {
1468
+ if (contributor.attrs.bibliographicName.family) {
1549
1469
  const surname = this.document.createElement('surname');
1550
- surname.textContent = contributor.bibliographicName.family;
1470
+ surname.textContent = contributor.attrs.bibliographicName.family;
1551
1471
  name.appendChild(surname);
1552
1472
  }
1553
- if (contributor.bibliographicName.given) {
1473
+ if (contributor.attrs.bibliographicName.given) {
1554
1474
  const givenNames = this.document.createElement('given-names');
1555
- givenNames.textContent = contributor.bibliographicName.given;
1475
+ givenNames.textContent = contributor.attrs.bibliographicName.given;
1556
1476
  name.appendChild(givenNames);
1557
1477
  }
1558
1478
  return name;
1559
1479
  };
1560
1480
  }
1561
- generateCitations(fragment) {
1481
+ generateCitations() {
1562
1482
  const nodes = [];
1563
- fragment.descendants((node) => {
1483
+ this.manuscriptNode.descendants((node) => {
1564
1484
  if ((0, schema_1.isCitationNode)(node)) {
1565
1485
  nodes.push(node);
1566
1486
  }
1567
1487
  });
1568
1488
  return (0, exports.buildCitations)(nodes);
1569
1489
  }
1570
- generateCitationTexts(fragment, csl) {
1490
+ generateCitationTexts(csl, manuscriptID) {
1571
1491
  this.citationTexts = new Map();
1572
1492
  this.citationProvider = new library_1.CitationProvider({
1573
- getLibraryItem: (id) => this.modelMap.get(id),
1493
+ getLibraryItem: this.getLibraryItem(manuscriptID),
1574
1494
  locale: csl.locale,
1575
1495
  citationStyle: csl.style,
1576
1496
  });
1577
- const citations = this.generateCitations(fragment);
1497
+ const citations = this.generateCitations();
1578
1498
  this.citationProvider.rebuildState(citations).forEach(([id, , output]) => {
1579
1499
  this.citationTexts.set(id, output);
1580
1500
  });
@@ -1601,72 +1521,50 @@ class JATSExporter {
1601
1521
  return mathml;
1602
1522
  }
1603
1523
  }
1604
- appendModelsToAuthorNotes(authorNotesEl, containedObjectIDs) {
1605
- const contributors = this.models.filter(isContributor);
1606
- const usedCorrespondings = this.getUsedCorrespondings(contributors);
1607
- containedObjectIDs.forEach((id) => {
1608
- const model = this.modelMap.get(id);
1609
- if (!model) {
1610
- return;
1611
- }
1612
- switch (model.objectType) {
1613
- case json_schema_1.ObjectTypes.ParagraphElement:
1614
- this.appendParagraphToElement(model, authorNotesEl);
1524
+ appendModelsToAuthorNotes(authorNotesEl, authorNotesNode) {
1525
+ const contributorsNodes = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.contributor).map((result) => result.node);
1526
+ const usedCorrespondings = this.getUsedCorrespondings(contributorsNodes);
1527
+ authorNotesNode.descendants((node) => {
1528
+ switch (node.type) {
1529
+ case schema_1.schema.nodes.paragraph:
1530
+ this.appendParagraphToElement(node, authorNotesEl);
1615
1531
  break;
1616
- case json_schema_1.ObjectTypes.Footnote:
1617
- this.appendFootnoteToElement(model, authorNotesEl);
1532
+ case schema_1.schema.nodes.footnote:
1533
+ this.appendFootnoteToElement(node, authorNotesEl);
1618
1534
  break;
1619
- case json_schema_1.ObjectTypes.Corresponding:
1620
- if (usedCorrespondings.includes(model)) {
1621
- this.appendCorrespondingToElement(model, authorNotesEl);
1535
+ case schema_1.schema.nodes.corresp:
1536
+ if (usedCorrespondings.includes(node)) {
1537
+ this.appendCorrespondingToElement(node, authorNotesEl);
1622
1538
  }
1623
1539
  break;
1624
1540
  }
1541
+ return false;
1625
1542
  });
1626
1543
  }
1627
1544
  getUsedCorrespondings(contributors) {
1628
1545
  return contributors
1629
- .flatMap((c) => { var _a; return (_a = c.corresp) !== null && _a !== void 0 ? _a : []; })
1630
- .map((corresp) => this.modelMap.get(corresp.correspID))
1546
+ .flatMap((c) => { var _a; return (_a = c.attrs.corresp) !== null && _a !== void 0 ? _a : []; })
1547
+ .map((corresp) => {
1548
+ var _a;
1549
+ return (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attr) => attr.id === corresp.correspID)[0]) === null || _a === void 0 ? void 0 : _a.node;
1550
+ })
1631
1551
  .filter((corresp) => !!corresp);
1632
1552
  }
1633
1553
  buildKeywords(articleMeta) {
1634
- const keywords = [...this.modelMap.values()].filter((model) => model.objectType === json_schema_1.ObjectTypes.Keyword);
1635
- const keywordGroups = new Map();
1636
- keywords.forEach((keyword) => {
1637
- const containedGroup = keyword.containedGroup || '';
1638
- const group = keywordGroups.get(containedGroup);
1639
- if (group) {
1640
- group.push(keyword);
1641
- }
1642
- else {
1643
- keywordGroups.set(containedGroup, [keyword]);
1644
- }
1645
- });
1646
- for (const [groupID, keywords] of keywordGroups) {
1647
- const keywordGroup = (this.modelMap.get(groupID) || {});
1554
+ const keywordGroups = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.keyword_group).map((result) => result.node);
1555
+ keywordGroups.forEach((group) => {
1648
1556
  const kwdGroup = this.document.createElement('kwd-group');
1649
- if (keywordGroup.type) {
1650
- kwdGroup.setAttribute('kwd-group-type', keywordGroup.type);
1651
- }
1652
- if (keywordGroup.label) {
1653
- const label = this.document.createElement('label');
1654
- label.textContent = keywordGroup.label;
1655
- kwdGroup.appendChild(label);
1656
- }
1657
- if (keywordGroup.title) {
1658
- const title = this.document.createElement('title');
1659
- title.textContent = keywordGroup.title;
1660
- kwdGroup.appendChild(title);
1557
+ if (group.attrs.type) {
1558
+ kwdGroup.setAttribute('kwd-group-type', group.attrs.type);
1661
1559
  }
1662
1560
  articleMeta.appendChild(kwdGroup);
1663
- for (const keyword of keywords) {
1561
+ group.content.forEach((keyword) => {
1664
1562
  const kwd = this.document.createElement('kwd');
1665
- kwd.textContent = keyword.name;
1563
+ kwd.textContent = keyword.textContent;
1666
1564
  kwdGroup.appendChild(kwd);
1667
- }
1565
+ });
1668
1566
  articleMeta.appendChild(kwdGroup);
1669
- }
1567
+ });
1670
1568
  }
1671
1569
  moveCoiStatementToAuthorNotes(back, front) {
1672
1570
  const fnGroups = back.querySelectorAll('fn-group');