@manuscripts/transform 2.3.33 → 2.3.34-LEAN-3911.2

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 (113) 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 +251 -354
  14. package/dist/cjs/{transformer → jats}/labels.js +3 -3
  15. package/dist/cjs/lib/utils.js +9 -1
  16. package/dist/cjs/transformer/id.js +6 -6
  17. package/dist/cjs/transformer/index.js +0 -18
  18. package/dist/cjs/version.js +1 -1
  19. package/dist/{cjs/transformer/serializer.js → es/jats/importer/create-article-node.js} +12 -8
  20. package/dist/es/jats/importer/index.js +2 -1
  21. package/dist/es/jats/importer/jats-body-transformations.js +70 -0
  22. package/dist/es/jats/importer/jats-comments.js +26 -101
  23. package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +230 -10
  24. package/dist/es/jats/importer/jats-front-transformations.js +259 -0
  25. package/dist/es/jats/importer/jats-journal-meta-parser.js +6 -0
  26. package/dist/es/jats/importer/jats-parser-utils.js +40 -6
  27. package/dist/es/jats/importer/jats-reference-parser.js +16 -27
  28. package/dist/es/jats/importer/jats-references.js +18 -18
  29. package/dist/es/jats/importer/parse-jats-article.js +43 -77
  30. package/dist/es/jats/index.js +3 -1
  31. package/dist/es/jats/jats-exporter.js +253 -356
  32. package/dist/es/{transformer → jats}/labels.js +3 -3
  33. package/dist/es/lib/utils.js +7 -0
  34. package/dist/es/transformer/id.js +5 -4
  35. package/dist/es/transformer/index.js +0 -16
  36. package/dist/es/version.js +1 -1
  37. package/dist/{cjs/transformer/models.js → types/jats/importer/create-article-node.d.ts} +3 -3
  38. package/dist/types/jats/importer/index.d.ts +2 -1
  39. package/dist/types/jats/importer/jats-body-transformations.d.ts +5 -0
  40. package/dist/types/jats/importer/jats-comments.d.ts +4 -10
  41. package/dist/types/jats/importer/{jats-body-dom-parser.d.ts → jats-dom-parser.d.ts} +1 -1
  42. package/dist/types/jats/importer/jats-front-transformations.d.ts +38 -0
  43. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +10 -0
  44. package/dist/types/jats/importer/jats-references.d.ts +19 -8
  45. package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
  46. package/dist/types/jats/index.d.ts +3 -1
  47. package/dist/types/jats/jats-exporter.d.ts +10 -29
  48. package/dist/types/{transformer → jats}/labels.d.ts +2 -1
  49. package/dist/types/lib/utils.d.ts +3 -0
  50. package/dist/types/schema/nodes/bibliography_item.d.ts +16 -6
  51. package/dist/types/schema/nodes/contributor.d.ts +10 -0
  52. package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
  53. package/dist/types/transformer/id.d.ts +4 -3
  54. package/dist/types/transformer/index.d.ts +0 -16
  55. package/dist/types/version.d.ts +1 -1
  56. package/package.json +2 -1
  57. package/dist/cjs/__tests__/data/project-dump.json +0 -825
  58. package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
  59. package/dist/cjs/transformer/__tests__/__helpers__/doc.js +0 -37
  60. package/dist/cjs/transformer/builders.js +0 -219
  61. package/dist/cjs/transformer/decode.js +0 -874
  62. package/dist/cjs/transformer/document-object-types.js +0 -31
  63. package/dist/cjs/transformer/encode.js +0 -664
  64. package/dist/cjs/transformer/footnote-category.js +0 -20
  65. package/dist/cjs/transformer/footnotes-order.js +0 -60
  66. package/dist/cjs/transformer/highlight-markers.js +0 -138
  67. package/dist/cjs/transformer/html.js +0 -400
  68. package/dist/cjs/transformer/manuscript-dependencies.js +0 -21
  69. package/dist/cjs/transformer/model-map.js +0 -26
  70. package/dist/cjs/transformer/object-types.js +0 -57
  71. package/dist/cjs/transformer/project-bundle.js +0 -94
  72. package/dist/cjs/transformer/update-identifiers.js +0 -93
  73. package/dist/es/__tests__/data/project-dump.json +0 -825
  74. package/dist/es/jats/importer/jats-front-parser.js +0 -315
  75. package/dist/es/transformer/__tests__/__helpers__/doc.js +0 -29
  76. package/dist/es/transformer/builders.js +0 -186
  77. package/dist/es/transformer/decode.js +0 -864
  78. package/dist/es/transformer/document-object-types.js +0 -28
  79. package/dist/es/transformer/encode.js +0 -654
  80. package/dist/es/transformer/footnote-category.js +0 -16
  81. package/dist/es/transformer/footnotes-order.js +0 -55
  82. package/dist/es/transformer/highlight-markers.js +0 -132
  83. package/dist/es/transformer/html.js +0 -393
  84. package/dist/es/transformer/manuscript-dependencies.js +0 -17
  85. package/dist/es/transformer/model-map.js +0 -22
  86. package/dist/es/transformer/models.js +0 -16
  87. package/dist/es/transformer/object-types.js +0 -52
  88. package/dist/es/transformer/project-bundle.js +0 -85
  89. package/dist/es/transformer/serializer.js +0 -17
  90. package/dist/es/transformer/update-identifiers.js +0 -87
  91. package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
  92. package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +0 -18
  93. package/dist/types/transformer/builders.d.ts +0 -61
  94. package/dist/types/transformer/decode.d.ts +0 -51
  95. package/dist/types/transformer/document-object-types.d.ts +0 -17
  96. package/dist/types/transformer/encode.d.ts +0 -29
  97. package/dist/types/transformer/footnote-category.d.ts +0 -17
  98. package/dist/types/transformer/footnotes-order.d.ts +0 -22
  99. package/dist/types/transformer/highlight-markers.d.ts +0 -31
  100. package/dist/types/transformer/html.d.ts +0 -36
  101. package/dist/types/transformer/manuscript-dependencies.d.ts +0 -4
  102. package/dist/types/transformer/model-map.d.ts +0 -19
  103. package/dist/types/transformer/models.d.ts +0 -48
  104. package/dist/types/transformer/object-types.d.ts +0 -30
  105. package/dist/types/transformer/project-bundle.d.ts +0 -30
  106. package/dist/types/transformer/serializer.d.ts +0 -19
  107. package/dist/types/transformer/update-identifiers.d.ts +0 -23
  108. /package/dist/cjs/{transformer → jats}/filename.js +0 -0
  109. /package/dist/cjs/{transformer → jats}/timestamp.js +0 -0
  110. /package/dist/es/{transformer → jats}/filename.js +0 -0
  111. /package/dist/es/{transformer → jats}/timestamp.js +0 -0
  112. /package/dist/types/{transformer → jats}/filename.d.ts +0 -0
  113. /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,7 +532,6 @@ 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 = {
597
536
  author_notes: () => '',
598
537
  corresp: () => '',
@@ -654,24 +593,25 @@ class JATSExporter {
654
593
  return xref;
655
594
  },
656
595
  cross_reference: (node) => {
596
+ var _a;
657
597
  const cross = node;
658
598
  const rids = cross.attrs.rids;
659
599
  if (!rids.length) {
660
600
  return cross.attrs.label;
661
601
  }
662
602
  const text = cross.attrs.customLabel || cross.attrs.label;
663
- const model = getModel(rids[0]);
664
- if (!model) {
603
+ const target = (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attrs) => attrs.id === rids[0])[0]) === null || _a === void 0 ? void 0 : _a.node;
604
+ if (!target) {
665
605
  warn('');
666
606
  return text;
667
607
  }
668
608
  const xref = this.document.createElement('xref');
669
- const type = chooseRefType(model.objectType);
609
+ const type = chooseRefType(target.type);
670
610
  if (type) {
671
611
  xref.setAttribute('ref-type', type);
672
612
  }
673
613
  else {
674
- warn(`Unset ref-type for objectType ${model.objectType}`);
614
+ warn(`Unset ref-type for schema type ${target.type.name}`);
675
615
  }
676
616
  xref.setAttribute('rid', normalizeID(rids.join(' ')));
677
617
  xref.textContent = text;
@@ -743,7 +683,10 @@ class JATSExporter {
743
683
  hard_break: () => '',
744
684
  highlight_marker: () => '',
745
685
  inline_footnote: (node) => {
746
- const rids = node.attrs.rids.filter(getModel);
686
+ const rids = node.attrs.rids.filter((rid) => {
687
+ var _a;
688
+ return (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attrs) => attrs.id === rid)[0]) === null || _a === void 0 ? void 0 : _a.node;
689
+ });
747
690
  if (rids.length == 0) {
748
691
  return '';
749
692
  }
@@ -862,14 +805,7 @@ class JATSExporter {
862
805
  italic: () => ['italic'],
863
806
  smallcaps: () => ['sc'],
864
807
  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
- },
808
+ styled: () => ['styled-content'],
873
809
  superscript: () => ['sup'],
874
810
  subscript: () => ['sub'],
875
811
  underline: () => ['underline'],
@@ -920,14 +856,16 @@ class JATSExporter {
920
856
  }
921
857
  };
922
858
  const appendChildNodeOfType = (element, node, type) => {
923
- const childNode = findChildNodeOfType(node, type);
859
+ var _a;
860
+ const childNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, type)[0]) === null || _a === void 0 ? void 0 : _a.node;
924
861
  if (childNode) {
925
862
  element.appendChild(this.serializeNode(childNode));
926
863
  }
927
864
  };
928
865
  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);
866
+ var _a, _b;
867
+ const tableNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.table)[0]) === null || _a === void 0 ? void 0 : _a.node;
868
+ 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
869
  if (!tableNode) {
932
870
  return;
933
871
  }
@@ -973,7 +911,8 @@ class JATSExporter {
973
911
  return element;
974
912
  };
975
913
  const processExecutableNode = (node, element) => {
976
- const listingNode = findChildNodeOfType(node, node.type.schema.nodes.listing);
914
+ var _a;
915
+ const listingNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.listing)[0]) === null || _a === void 0 ? void 0 : _a.node;
977
916
  if (listingNode) {
978
917
  const { contents, languageKey } = listingNode.attrs;
979
918
  if (contents && languageKey) {
@@ -1007,25 +946,25 @@ class JATSExporter {
1007
946
  }
1008
947
  };
1009
948
  };
1010
- this.serializeFragment = (fragment) => this.serializer.serializeFragment(fragment, {
1011
- document: this.document,
1012
- });
1013
949
  this.serializeNode = (node) => this.serializer.serializeNode(node, {
1014
950
  document: this.document,
1015
951
  });
1016
952
  this.validateContributor = (contributor) => {
1017
- if (!contributor.bibliographicName) {
1018
- throw new Error(`${contributor._id} has no bibliographicName`);
953
+ if (!contributor.attrs.bibliographicName) {
954
+ throw new Error(`${contributor.attrs.id} has no bibliographicName`);
1019
955
  }
1020
- const { family, given } = contributor.bibliographicName;
956
+ const { family, given } = contributor.attrs.bibliographicName;
1021
957
  if (!family && !given) {
1022
- throw new Error(`${contributor._id} has neither family nor given name`);
958
+ throw new Error(`${contributor.attrs.id} has neither family nor given name`);
1023
959
  }
1024
960
  };
1025
961
  this.buildContributors = (articleMeta) => {
1026
- const contributors = this.models.filter(isContributor);
1027
- const authorContributors = contributors
1028
- .filter((contributor) => contributor.role === 'author')
962
+ const contributorNodes = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.contributor).map((result) => result.node);
963
+ const authorContributorNodes = contributorNodes
964
+ .filter((n) => n.attrs.role === 'author')
965
+ .sort(sortContributors);
966
+ const otherContributorsNodes = contributorNodes
967
+ .filter((n) => n.attrs.role !== 'author')
1029
968
  .sort(sortContributors);
1030
969
  const affiliationLabels = new Map();
1031
970
  const creatAffiliationLabel = (rid) => {
@@ -1043,11 +982,11 @@ class JATSExporter {
1043
982
  sup.textContent = String(content);
1044
983
  return sup;
1045
984
  };
1046
- if (authorContributors.length) {
985
+ if (authorContributorNodes.length) {
1047
986
  const contribGroup = this.document.createElement('contrib-group');
1048
987
  contribGroup.setAttribute('content-type', 'authors');
1049
988
  articleMeta.appendChild(contribGroup);
1050
- authorContributors.forEach((contributor) => {
989
+ authorContributorNodes.forEach((contributor) => {
1051
990
  try {
1052
991
  this.validateContributor(contributor);
1053
992
  }
@@ -1057,39 +996,25 @@ class JATSExporter {
1057
996
  }
1058
997
  const contrib = this.document.createElement('contrib');
1059
998
  contrib.setAttribute('contrib-type', 'author');
1060
- contrib.setAttribute('id', normalizeID(contributor._id));
1061
- if (contributor.isCorresponding) {
999
+ contrib.setAttribute('id', normalizeID(contributor.attrs.id));
1000
+ if (contributor.attrs.isCorresponding) {
1062
1001
  contrib.setAttribute('corresp', 'yes');
1063
1002
  }
1064
- if (contributor.ORCIDIdentifier) {
1003
+ if (contributor.attrs.ORCIDIdentifier) {
1065
1004
  const identifier = this.document.createElement('contrib-id');
1066
1005
  identifier.setAttribute('contrib-id-type', 'orcid');
1067
- identifier.textContent = contributor.ORCIDIdentifier;
1006
+ identifier.textContent = contributor.attrs.ORCIDIdentifier;
1068
1007
  contrib.appendChild(identifier);
1069
1008
  }
1070
1009
  const name = this.buildContributorName(contributor);
1071
1010
  contrib.appendChild(name);
1072
- if (contributor.email) {
1011
+ if (contributor.attrs.email) {
1073
1012
  const email = this.document.createElement('email');
1074
- email.textContent = contributor.email;
1013
+ email.textContent = contributor.attrs.email;
1075
1014
  contrib.appendChild(email);
1076
1015
  }
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) => {
1016
+ if (contributor.attrs.affiliations) {
1017
+ contributor.attrs.affiliations.forEach((rid) => {
1093
1018
  const xref = this.document.createElement('xref');
1094
1019
  xref.setAttribute('ref-type', 'aff');
1095
1020
  xref.setAttribute('rid', normalizeID(rid));
@@ -1097,8 +1022,8 @@ class JATSExporter {
1097
1022
  contrib.appendChild(xref);
1098
1023
  });
1099
1024
  }
1100
- if (contributor.footnote) {
1101
- contributor.footnote.map((note) => {
1025
+ if (contributor.attrs.footnote) {
1026
+ contributor.attrs.footnote.map((note) => {
1102
1027
  const xref = this.document.createElement('xref');
1103
1028
  xref.setAttribute('ref-type', 'fn');
1104
1029
  xref.setAttribute('rid', normalizeID(note.noteID));
@@ -1106,8 +1031,8 @@ class JATSExporter {
1106
1031
  contrib.appendChild(xref);
1107
1032
  });
1108
1033
  }
1109
- if (contributor.corresp) {
1110
- contributor.corresp.map((corresp) => {
1034
+ if (contributor.attrs.corresp) {
1035
+ contributor.attrs.corresp.map((corresp) => {
1111
1036
  const xref = this.document.createElement('xref');
1112
1037
  xref.setAttribute('ref-type', 'corresp');
1113
1038
  xref.setAttribute('rid', normalizeID(corresp.correspID));
@@ -1117,13 +1042,10 @@ class JATSExporter {
1117
1042
  }
1118
1043
  contribGroup.appendChild(contrib);
1119
1044
  });
1120
- const otherContributors = contributors
1121
- .filter((contributor) => contributor.role !== 'author')
1122
- .sort(sortContributors);
1123
- if (otherContributors.length) {
1045
+ if (otherContributorsNodes.length) {
1124
1046
  const contribGroup = this.document.createElement('contrib-group');
1125
1047
  articleMeta.appendChild(contribGroup);
1126
- otherContributors.forEach((contributor) => {
1048
+ otherContributorsNodes.forEach((contributor) => {
1127
1049
  try {
1128
1050
  this.validateContributor(contributor);
1129
1051
  }
@@ -1132,30 +1054,16 @@ class JATSExporter {
1132
1054
  return;
1133
1055
  }
1134
1056
  const contrib = this.document.createElement('contrib');
1135
- contrib.setAttribute('id', normalizeID(contributor._id));
1057
+ contrib.setAttribute('id', normalizeID(contributor.attrs.id));
1136
1058
  const name = this.buildContributorName(contributor);
1137
1059
  contrib.appendChild(name);
1138
- if (contributor.email) {
1060
+ if (contributor.attrs.email) {
1139
1061
  const email = this.document.createElement('email');
1140
- email.textContent = contributor.email;
1062
+ email.textContent = contributor.attrs.email;
1141
1063
  contrib.appendChild(email);
1142
1064
  }
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) => {
1065
+ if (contributor.attrs.affiliations) {
1066
+ contributor.attrs.affiliations.forEach((rid) => {
1159
1067
  const xref = this.document.createElement('xref');
1160
1068
  xref.setAttribute('ref-type', 'aff');
1161
1069
  xref.setAttribute('rid', normalizeID(rid));
@@ -1163,8 +1071,8 @@ class JATSExporter {
1163
1071
  contrib.appendChild(xref);
1164
1072
  });
1165
1073
  }
1166
- if (contributor.footnote) {
1167
- contributor.footnote.map((note) => {
1074
+ if (contributor.attrs.footnote) {
1075
+ contributor.attrs.footnote.map((note) => {
1168
1076
  const xref = this.document.createElement('xref');
1169
1077
  xref.setAttribute('ref-type', 'fn');
1170
1078
  xref.setAttribute('rid', normalizeID(note.noteID));
@@ -1176,64 +1084,68 @@ class JATSExporter {
1176
1084
  });
1177
1085
  }
1178
1086
  const affiliationRIDs = [];
1179
- const sortedContributors = [...authorContributors, ...otherContributors];
1087
+ const sortedContributors = [
1088
+ ...authorContributorNodes,
1089
+ ...otherContributorsNodes,
1090
+ ];
1180
1091
  for (const contributor of sortedContributors) {
1181
- if (contributor.affiliations) {
1182
- affiliationRIDs.push(...contributor.affiliations);
1092
+ if (contributor.attrs.affiliations) {
1093
+ affiliationRIDs.push(...contributor.attrs.affiliations);
1183
1094
  }
1184
1095
  }
1185
- const affiliations = this.models.filter((0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.Affiliation));
1096
+ const affiliations = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.affiliation).map((result) => result.node);
1186
1097
  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));
1098
+ const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation.attrs.id));
1099
+ usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a.attrs.id) -
1100
+ affiliationRIDs.indexOf(b.attrs.id));
1189
1101
  usedAffiliations.forEach((affiliation) => {
1190
1102
  var _a, _b;
1191
1103
  const aff = this.document.createElement('aff');
1192
- aff.setAttribute('id', normalizeID(affiliation._id));
1104
+ aff.setAttribute('id', normalizeID(affiliation.attrs.id));
1193
1105
  contribGroup.appendChild(aff);
1194
- if (affiliation.department) {
1106
+ if (affiliation.attrs.department) {
1195
1107
  const department = this.document.createElement('institution');
1196
1108
  department.setAttribute('content-type', 'dept');
1197
- department.textContent = affiliation.department;
1109
+ department.textContent = affiliation.attrs.department;
1198
1110
  aff.appendChild(department);
1199
1111
  }
1200
- if (affiliation.institution) {
1112
+ if (affiliation.attrs.institution) {
1201
1113
  const institution = this.document.createElement('institution');
1202
- institution.textContent = affiliation.institution;
1114
+ institution.textContent = affiliation.attrs.institution;
1203
1115
  aff.appendChild(institution);
1204
1116
  }
1205
- if (affiliation.addressLine1) {
1117
+ if (affiliation.attrs.addressLine1) {
1206
1118
  const addressLine = this.document.createElement('addr-line');
1207
- addressLine.textContent = affiliation.addressLine1;
1119
+ addressLine.textContent = affiliation.attrs.addressLine1;
1208
1120
  aff.appendChild(addressLine);
1209
1121
  }
1210
- if (affiliation.addressLine2) {
1122
+ if (affiliation.attrs.addressLine2) {
1211
1123
  const addressLine = this.document.createElement('addr-line');
1212
- addressLine.textContent = affiliation.addressLine2;
1124
+ addressLine.textContent = affiliation.attrs.addressLine2;
1213
1125
  aff.appendChild(addressLine);
1214
1126
  }
1215
- if (affiliation.addressLine3) {
1127
+ if (affiliation.attrs.addressLine3) {
1216
1128
  const addressLine = this.document.createElement('addr-line');
1217
- addressLine.textContent = affiliation.addressLine3;
1129
+ addressLine.textContent = affiliation.attrs.addressLine3;
1218
1130
  aff.appendChild(addressLine);
1219
1131
  }
1220
- if (affiliation.city) {
1132
+ if (affiliation.attrs.city) {
1221
1133
  const city = this.document.createElement('city');
1222
- city.textContent = affiliation.city;
1134
+ city.textContent = affiliation.attrs.city;
1223
1135
  aff.appendChild(city);
1224
1136
  }
1225
- if (affiliation.country) {
1137
+ if (affiliation.attrs.country) {
1226
1138
  const country = this.document.createElement('country');
1227
- country.textContent = affiliation.country;
1139
+ country.textContent = affiliation.attrs.country;
1228
1140
  aff.appendChild(country);
1229
1141
  }
1230
- if (affiliation.email) {
1142
+ if (affiliation.attrs.email) {
1231
1143
  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 : '';
1144
+ email.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = affiliation.attrs.email.href) !== null && _a !== void 0 ? _a : '');
1145
+ email.textContent = (_b = affiliation.attrs.email.text) !== null && _b !== void 0 ? _b : '';
1234
1146
  aff.appendChild(email);
1235
1147
  }
1236
- const labelNumber = affiliationLabels.get(affiliation._id);
1148
+ const labelNumber = affiliationLabels.get(affiliation.attrs.id);
1237
1149
  if (labelNumber) {
1238
1150
  const label = this.document.createElement('label');
1239
1151
  label.textContent = String(labelNumber);
@@ -1250,41 +1162,48 @@ class JATSExporter {
1250
1162
  this.createAuthorNotesElement = () => {
1251
1163
  var _a;
1252
1164
  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);
1165
+ 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;
1166
+ if (authorNotesNode) {
1167
+ this.appendModelsToAuthorNotes(authorNotesEl, authorNotesNode);
1256
1168
  }
1257
1169
  return authorNotesEl;
1258
1170
  };
1259
1171
  this.appendCorrespondingToElement = (corresponding, element) => {
1260
1172
  const correspondingEl = this.document.createElement('corresp');
1261
- correspondingEl.setAttribute('id', normalizeID(corresponding._id));
1262
- if (corresponding.label) {
1173
+ correspondingEl.setAttribute('id', normalizeID(corresponding.attrs.id));
1174
+ if (corresponding.attrs.label) {
1263
1175
  const labelEl = this.document.createElement('label');
1264
- labelEl.textContent = corresponding.label;
1176
+ labelEl.textContent = corresponding.attrs.label;
1265
1177
  correspondingEl.appendChild(labelEl);
1266
1178
  }
1267
- correspondingEl.append(corresponding.contents);
1179
+ correspondingEl.append(corresponding.textContent);
1268
1180
  element.appendChild(correspondingEl);
1269
1181
  };
1270
1182
  this.appendParagraphToElement = (paragraph, element) => {
1271
- const parsedDoc = new DOMParser().parseFromString(paragraph.contents, 'text/html');
1183
+ const parsedDoc = new DOMParser().parseFromString(paragraph.textContent, 'text/html');
1272
1184
  const parsedParagraph = parsedDoc.body.querySelector('p');
1273
1185
  if (parsedParagraph) {
1274
1186
  const paragraphEl = this.document.createElement('p');
1275
1187
  paragraphEl.innerHTML = parsedParagraph.innerHTML;
1276
- paragraphEl.setAttribute('id', normalizeID(paragraph._id));
1188
+ paragraphEl.setAttribute('id', normalizeID(paragraph.attrs.id));
1277
1189
  element.appendChild(paragraphEl);
1278
1190
  }
1279
1191
  };
1280
1192
  this.appendFootnoteToElement = (footnote, element) => {
1281
1193
  const footnoteEl = this.document.createElement('fn');
1282
- footnoteEl.setAttribute('id', normalizeID(footnote._id));
1283
- footnoteEl.innerHTML = footnote.contents;
1194
+ footnoteEl.setAttribute('id', normalizeID(footnote.attrs.id));
1195
+ if (!footnote.textContent.includes('<p>')) {
1196
+ const p = this.document.createElement('p');
1197
+ p.innerHTML = footnote.textContent;
1198
+ footnoteEl.appendChild(p);
1199
+ }
1200
+ else {
1201
+ footnoteEl.innerHTML = footnote.textContent;
1202
+ }
1284
1203
  element.appendChild(footnoteEl);
1285
1204
  };
1286
- this.fixBody = (body, fragment) => {
1287
- fragment.descendants((node) => {
1205
+ this.fixBody = (body) => {
1206
+ this.manuscriptNode.descendants((node) => {
1288
1207
  if (node.attrs.id) {
1289
1208
  if (node.attrs.titleSuppressed) {
1290
1209
  const title = body.querySelector(`#${normalizeID(node.attrs.id)} > title`);
@@ -1545,36 +1464,36 @@ class JATSExporter {
1545
1464
  };
1546
1465
  this.buildContributorName = (contributor) => {
1547
1466
  const name = this.document.createElement('name');
1548
- if (contributor.bibliographicName.family) {
1467
+ if (contributor.attrs.bibliographicName.family) {
1549
1468
  const surname = this.document.createElement('surname');
1550
- surname.textContent = contributor.bibliographicName.family;
1469
+ surname.textContent = contributor.attrs.bibliographicName.family;
1551
1470
  name.appendChild(surname);
1552
1471
  }
1553
- if (contributor.bibliographicName.given) {
1472
+ if (contributor.attrs.bibliographicName.given) {
1554
1473
  const givenNames = this.document.createElement('given-names');
1555
- givenNames.textContent = contributor.bibliographicName.given;
1474
+ givenNames.textContent = contributor.attrs.bibliographicName.given;
1556
1475
  name.appendChild(givenNames);
1557
1476
  }
1558
1477
  return name;
1559
1478
  };
1560
1479
  }
1561
- generateCitations(fragment) {
1480
+ generateCitations() {
1562
1481
  const nodes = [];
1563
- fragment.descendants((node) => {
1482
+ this.manuscriptNode.descendants((node) => {
1564
1483
  if ((0, schema_1.isCitationNode)(node)) {
1565
1484
  nodes.push(node);
1566
1485
  }
1567
1486
  });
1568
1487
  return (0, exports.buildCitations)(nodes);
1569
1488
  }
1570
- generateCitationTexts(fragment, csl) {
1489
+ generateCitationTexts(csl, manuscriptID) {
1571
1490
  this.citationTexts = new Map();
1572
1491
  this.citationProvider = new library_1.CitationProvider({
1573
- getLibraryItem: (id) => this.modelMap.get(id),
1492
+ getLibraryItem: this.getLibraryItem(manuscriptID),
1574
1493
  locale: csl.locale,
1575
1494
  citationStyle: csl.style,
1576
1495
  });
1577
- const citations = this.generateCitations(fragment);
1496
+ const citations = this.generateCitations();
1578
1497
  this.citationProvider.rebuildState(citations).forEach(([id, , output]) => {
1579
1498
  this.citationTexts.set(id, output);
1580
1499
  });
@@ -1601,72 +1520,50 @@ class JATSExporter {
1601
1520
  return mathml;
1602
1521
  }
1603
1522
  }
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);
1523
+ appendModelsToAuthorNotes(authorNotesEl, authorNotesNode) {
1524
+ const contributorsNodes = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.contributor).map((result) => result.node);
1525
+ const usedCorrespondings = this.getUsedCorrespondings(contributorsNodes);
1526
+ authorNotesNode.descendants((node) => {
1527
+ switch (node.type) {
1528
+ case schema_1.schema.nodes.paragraph:
1529
+ this.appendParagraphToElement(node, authorNotesEl);
1615
1530
  break;
1616
- case json_schema_1.ObjectTypes.Footnote:
1617
- this.appendFootnoteToElement(model, authorNotesEl);
1531
+ case schema_1.schema.nodes.footnote:
1532
+ this.appendFootnoteToElement(node, authorNotesEl);
1618
1533
  break;
1619
- case json_schema_1.ObjectTypes.Corresponding:
1620
- if (usedCorrespondings.includes(model)) {
1621
- this.appendCorrespondingToElement(model, authorNotesEl);
1534
+ case schema_1.schema.nodes.corresp:
1535
+ if (usedCorrespondings.includes(node)) {
1536
+ this.appendCorrespondingToElement(node, authorNotesEl);
1622
1537
  }
1623
1538
  break;
1624
1539
  }
1540
+ return false;
1625
1541
  });
1626
1542
  }
1627
1543
  getUsedCorrespondings(contributors) {
1628
1544
  return contributors
1629
- .flatMap((c) => { var _a; return (_a = c.corresp) !== null && _a !== void 0 ? _a : []; })
1630
- .map((corresp) => this.modelMap.get(corresp.correspID))
1545
+ .flatMap((c) => { var _a; return (_a = c.attrs.corresp) !== null && _a !== void 0 ? _a : []; })
1546
+ .map((corresp) => {
1547
+ var _a;
1548
+ return (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attr) => attr.id === corresp.correspID)[0]) === null || _a === void 0 ? void 0 : _a.node;
1549
+ })
1631
1550
  .filter((corresp) => !!corresp);
1632
1551
  }
1633
1552
  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) || {});
1553
+ const keywordGroups = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.keyword_group).map((result) => result.node);
1554
+ keywordGroups.forEach((group) => {
1648
1555
  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);
1556
+ if (group.attrs.type) {
1557
+ kwdGroup.setAttribute('kwd-group-type', group.attrs.type);
1661
1558
  }
1662
1559
  articleMeta.appendChild(kwdGroup);
1663
- for (const keyword of keywords) {
1560
+ group.content.forEach((keyword) => {
1664
1561
  const kwd = this.document.createElement('kwd');
1665
- kwd.textContent = keyword.name;
1562
+ kwd.textContent = keyword.textContent;
1666
1563
  kwdGroup.appendChild(kwd);
1667
- }
1564
+ });
1668
1565
  articleMeta.appendChild(kwdGroup);
1669
- }
1566
+ });
1670
1567
  }
1671
1568
  moveCoiStatementToAuthorNotes(back, front) {
1672
1569
  const fnGroups = back.querySelectorAll('fn-group');