@manuscripts/transform 2.3.36 → 2.3.37-LEAN-3911.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +253 -366
  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 +10 -5
  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 +255 -368
  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 +8 -3
  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 +14 -27
  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 +28 -5
  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 +5 -2
  54. package/dist/types/transformer/index.d.ts +0 -16
  55. package/dist/types/version.d.ts +1 -1
  56. package/package.json +3 -2
  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, options) => {
132
+ var _a;
133
+ this.manuscriptNode = manuscriptNode;
134
+ this.generateCitationTexts(options.csl, manuscriptNode.attrs.id);
136
135
  this.createSerializer();
137
- const versionIds = (0, jats_versions_1.selectVersionIds)(version);
136
+ const versionIds = (0, jats_versions_1.selectVersionIds)((_a = options.version) !== null && _a !== void 0 ? _a : "1.2");
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(options.journal);
142
141
  article.appendChild(front);
143
- const manuscript = (0, project_bundle_1.findManuscriptById)(this.modelMap, manuscriptID);
144
- 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
- }
142
+ article.setAttribute('article-type', manuscriptNode.attrs.articleType || 'other');
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 = (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,109 +276,47 @@ 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 (this.manuscriptNode.attrs.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
- if (manuscript.genericCounts) {
377
- const elements = manuscript.genericCounts.map((el) => {
378
- const countingElement = this.buildCountingElement('count', el.count);
379
- if (countingElement) {
380
- countingElement.setAttribute('count-type', el.countType);
381
- }
382
- return countingElement;
383
- });
384
- countingElements.push(...elements);
385
- }
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));
310
+ const figureCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.figure).length;
311
+ countingElements.push(this.buildCountingElement('fig-count', figureCount));
312
+ const equationCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.equation_element).length;
313
+ const tableCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.table).length;
314
+ const referencesCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.bibliography_item).length;
315
+ countingElements.push(this.buildCountingElement('table-count', tableCount));
316
+ countingElements.push(this.buildCountingElement('equation-count', equationCount));
317
+ countingElements.push(this.buildCountingElement('ref-count', referencesCount));
318
+ const wordCount = this.manuscriptNode.textContent.split(/\s+/).length;
319
+ countingElements.push(this.buildCountingElement('word-count', wordCount));
391
320
  countingElements = countingElements.filter((el) => el);
392
321
  if (countingElements.length > 0) {
393
322
  const counts = this.document.createElement('counts');
@@ -422,16 +351,17 @@ class JATSExporter {
422
351
  return wordCount;
423
352
  }
424
353
  };
425
- this.buildBody = (fragment) => {
354
+ this.buildBody = () => {
426
355
  const body = this.document.createElement('body');
427
- fragment.forEach((cFragment) => {
356
+ this.manuscriptNode.forEach((cFragment) => {
428
357
  const serializedNode = this.serializeNode(cFragment);
429
358
  body.append(...serializedNode.childNodes);
430
359
  });
431
- this.fixBody(body, fragment);
360
+ this.fixBody(body);
432
361
  return body;
433
362
  };
434
363
  this.buildBack = (body) => {
364
+ var _a;
435
365
  const back = this.document.createElement('back');
436
366
  this.moveSectionsToBack(back, body);
437
367
  const footnotesElements = this.document.querySelectorAll('sec > fn-group');
@@ -456,7 +386,7 @@ class JATSExporter {
456
386
  back.appendChild(refList);
457
387
  const [meta] = this.citationProvider.makeBibliography();
458
388
  for (const id of meta.entry_ids) {
459
- const bibliographyItem = this.modelMap.get(id[0]);
389
+ 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
390
  const ref = this.document.createElement('ref');
461
391
  ref.setAttribute('id', normalizeID(id[0]));
462
392
  const updateCitationPubType = (citationEl, pubType) => {
@@ -475,21 +405,21 @@ class JATSExporter {
475
405
  citationEl.setAttribute('publication-type', 'journal');
476
406
  }
477
407
  };
478
- if (bibliographyItem.literal) {
408
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.literal) {
479
409
  const mixedCitation = this.document.createElement('mixed-citation');
480
- updateCitationPubType(mixedCitation, bibliographyItem.type);
481
- mixedCitation.textContent = bibliographyItem.literal;
410
+ updateCitationPubType(mixedCitation, bibliographyNode.attrs.type);
411
+ mixedCitation.textContent = bibliographyNode.attrs.literal;
482
412
  ref.appendChild(mixedCitation);
483
413
  refList.appendChild(ref);
484
414
  }
485
415
  else {
486
416
  const citation = this.document.createElement('element-citation');
487
- updateCitationPubType(citation, bibliographyItem.type);
488
- if (bibliographyItem.author) {
417
+ updateCitationPubType(citation, bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.type);
418
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.author) {
489
419
  const personGroupNode = this.document.createElement('person-group');
490
420
  personGroupNode.setAttribute('person-group-type', 'author');
491
421
  citation.appendChild(personGroupNode);
492
- bibliographyItem.author.forEach((author) => {
422
+ bibliographyNode.attrs.author.forEach((author) => {
493
423
  const name = this.document.createElement('string-name');
494
424
  if (author.family) {
495
425
  const node = this.document.createElement('surname');
@@ -511,8 +441,8 @@ class JATSExporter {
511
441
  }
512
442
  });
513
443
  }
514
- if (bibliographyItem.issued) {
515
- const dateParts = bibliographyItem.issued['date-parts'];
444
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issued) {
445
+ const dateParts = bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issued['date-parts'];
516
446
  if (dateParts && dateParts.length) {
517
447
  const [[year, month, day]] = dateParts;
518
448
  if (year) {
@@ -532,33 +462,33 @@ class JATSExporter {
532
462
  }
533
463
  }
534
464
  }
535
- if (bibliographyItem.title) {
465
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.title) {
536
466
  const node = this.document.createElement('article-title');
537
- this.setTitleContent(node, bibliographyItem.title);
467
+ this.setTitleContent(node, bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.title);
538
468
  citation.appendChild(node);
539
469
  }
540
- if (bibliographyItem['container-title']) {
470
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.containerTitle) {
541
471
  const node = this.document.createElement('source');
542
- node.textContent = bibliographyItem['container-title'];
472
+ node.textContent = bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.containerTitle;
543
473
  citation.appendChild(node);
544
474
  }
545
- if (bibliographyItem.volume) {
475
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.volume) {
546
476
  const node = this.document.createElement('volume');
547
- node.textContent = String(bibliographyItem.volume);
477
+ node.textContent = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.volume);
548
478
  citation.appendChild(node);
549
479
  }
550
- if (bibliographyItem.issue) {
480
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issue) {
551
481
  const node = this.document.createElement('issue');
552
- node.textContent = String(bibliographyItem.issue);
482
+ node.textContent = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issue);
553
483
  citation.appendChild(node);
554
484
  }
555
- if (bibliographyItem.supplement) {
485
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.supplement) {
556
486
  const node = this.document.createElement('supplement');
557
- node.textContent = bibliographyItem.supplement;
487
+ node.textContent = bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.supplement;
558
488
  citation.appendChild(node);
559
489
  }
560
- if (bibliographyItem.page) {
561
- const pageString = String(bibliographyItem.page);
490
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.page) {
491
+ const pageString = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.page);
562
492
  if (/^\d+$/.test(pageString)) {
563
493
  const node = this.document.createElement('fpage');
564
494
  node.textContent = pageString;
@@ -579,10 +509,10 @@ class JATSExporter {
579
509
  citation.appendChild(node);
580
510
  }
581
511
  }
582
- if (bibliographyItem.DOI) {
512
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.doi) {
583
513
  const node = this.document.createElement('pub-id');
584
514
  node.setAttribute('pub-id-type', 'doi');
585
- node.textContent = String(bibliographyItem.DOI);
515
+ node.textContent = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.doi);
586
516
  citation.appendChild(node);
587
517
  }
588
518
  ref.appendChild(citation);
@@ -592,7 +522,6 @@ class JATSExporter {
592
522
  return back;
593
523
  };
594
524
  this.createSerializer = () => {
595
- const getModel = (id) => id ? this.modelMap.get(id) : undefined;
596
525
  const nodes = {
597
526
  box_element: () => ['boxed-text', 0],
598
527
  author_notes: () => '',
@@ -655,24 +584,25 @@ class JATSExporter {
655
584
  return xref;
656
585
  },
657
586
  cross_reference: (node) => {
587
+ var _a;
658
588
  const cross = node;
659
589
  const rids = cross.attrs.rids;
660
590
  if (!rids.length) {
661
591
  return cross.attrs.label;
662
592
  }
663
593
  const text = cross.attrs.customLabel || cross.attrs.label;
664
- const model = getModel(rids[0]);
665
- if (!model) {
594
+ const target = (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attrs) => attrs.id === rids[0])[0]) === null || _a === void 0 ? void 0 : _a.node;
595
+ if (!target) {
666
596
  warn('');
667
597
  return text;
668
598
  }
669
599
  const xref = this.document.createElement('xref');
670
- const type = chooseRefType(model.objectType);
600
+ const type = chooseRefType(target.type);
671
601
  if (type) {
672
602
  xref.setAttribute('ref-type', type);
673
603
  }
674
604
  else {
675
- warn(`Unset ref-type for objectType ${model.objectType}`);
605
+ warn(`Unset ref-type for schema type ${target.type.name}`);
676
606
  }
677
607
  xref.setAttribute('rid', normalizeID(rids.join(' ')));
678
608
  xref.textContent = text;
@@ -744,7 +674,10 @@ class JATSExporter {
744
674
  hard_break: () => '',
745
675
  highlight_marker: () => '',
746
676
  inline_footnote: (node) => {
747
- const rids = node.attrs.rids.filter(getModel);
677
+ const rids = node.attrs.rids.filter((rid) => {
678
+ var _a;
679
+ return (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attrs) => attrs.id === rid)[0]) === null || _a === void 0 ? void 0 : _a.node;
680
+ });
748
681
  if (rids.length == 0) {
749
682
  return '';
750
683
  }
@@ -863,14 +796,7 @@ class JATSExporter {
863
796
  italic: () => ['italic'],
864
797
  smallcaps: () => ['sc'],
865
798
  strikethrough: () => ['strike'],
866
- styled: (mark) => {
867
- const inlineStyle = getModel(mark.attrs.rid);
868
- const attrs = {};
869
- if (inlineStyle && inlineStyle.title) {
870
- attrs.style = (0, styled_content_1.normalizeStyleName)(inlineStyle.title);
871
- }
872
- return ['styled-content', attrs];
873
- },
799
+ styled: () => ['styled-content'],
874
800
  superscript: () => ['sup'],
875
801
  subscript: () => ['sub'],
876
802
  underline: () => ['underline'],
@@ -921,14 +847,16 @@ class JATSExporter {
921
847
  }
922
848
  };
923
849
  const appendChildNodeOfType = (element, node, type) => {
924
- const childNode = findChildNodeOfType(node, type);
850
+ var _a;
851
+ const childNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, type)[0]) === null || _a === void 0 ? void 0 : _a.node;
925
852
  if (childNode) {
926
853
  element.appendChild(this.serializeNode(childNode));
927
854
  }
928
855
  };
929
856
  const appendTable = (element, node) => {
930
- const tableNode = findChildNodeOfType(node, node.type.schema.nodes.table);
931
- const colGroupNode = findChildNodeOfType(node, node.type.schema.nodes.table_colgroup);
857
+ var _a, _b;
858
+ const tableNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.table)[0]) === null || _a === void 0 ? void 0 : _a.node;
859
+ const colGroupNode = (_b = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.table_colgroup)[0]) === null || _b === void 0 ? void 0 : _b.node;
932
860
  if (!tableNode) {
933
861
  return;
934
862
  }
@@ -974,7 +902,8 @@ class JATSExporter {
974
902
  return element;
975
903
  };
976
904
  const processExecutableNode = (node, element) => {
977
- const listingNode = findChildNodeOfType(node, node.type.schema.nodes.listing);
905
+ var _a;
906
+ const listingNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.listing)[0]) === null || _a === void 0 ? void 0 : _a.node;
978
907
  if (listingNode) {
979
908
  const { contents, languageKey } = listingNode.attrs;
980
909
  if (contents && languageKey) {
@@ -1008,25 +937,25 @@ class JATSExporter {
1008
937
  }
1009
938
  };
1010
939
  };
1011
- this.serializeFragment = (fragment) => this.serializer.serializeFragment(fragment, {
1012
- document: this.document,
1013
- });
1014
940
  this.serializeNode = (node) => this.serializer.serializeNode(node, {
1015
941
  document: this.document,
1016
942
  });
1017
943
  this.validateContributor = (contributor) => {
1018
- if (!contributor.bibliographicName) {
1019
- throw new Error(`${contributor._id} has no bibliographicName`);
944
+ if (!contributor.attrs.bibliographicName) {
945
+ throw new Error(`${contributor.attrs.id} has no bibliographicName`);
1020
946
  }
1021
- const { family, given } = contributor.bibliographicName;
947
+ const { family, given } = contributor.attrs.bibliographicName;
1022
948
  if (!family && !given) {
1023
- throw new Error(`${contributor._id} has neither family nor given name`);
949
+ throw new Error(`${contributor.attrs.id} has neither family nor given name`);
1024
950
  }
1025
951
  };
1026
952
  this.buildContributors = (articleMeta) => {
1027
- const contributors = this.models.filter(isContributor);
1028
- const authorContributors = contributors
1029
- .filter((contributor) => contributor.role === 'author')
953
+ const contributorNodes = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.contributor).map((result) => result.node);
954
+ const authorContributorNodes = contributorNodes
955
+ .filter((n) => n.attrs.role === 'author')
956
+ .sort(sortContributors);
957
+ const otherContributorsNodes = contributorNodes
958
+ .filter((n) => n.attrs.role !== 'author')
1030
959
  .sort(sortContributors);
1031
960
  const affiliationLabels = new Map();
1032
961
  const creatAffiliationLabel = (rid) => {
@@ -1044,11 +973,11 @@ class JATSExporter {
1044
973
  sup.textContent = String(content);
1045
974
  return sup;
1046
975
  };
1047
- if (authorContributors.length) {
976
+ if (authorContributorNodes.length) {
1048
977
  const contribGroup = this.document.createElement('contrib-group');
1049
978
  contribGroup.setAttribute('content-type', 'authors');
1050
979
  articleMeta.appendChild(contribGroup);
1051
- authorContributors.forEach((contributor) => {
980
+ authorContributorNodes.forEach((contributor) => {
1052
981
  try {
1053
982
  this.validateContributor(contributor);
1054
983
  }
@@ -1058,39 +987,25 @@ class JATSExporter {
1058
987
  }
1059
988
  const contrib = this.document.createElement('contrib');
1060
989
  contrib.setAttribute('contrib-type', 'author');
1061
- contrib.setAttribute('id', normalizeID(contributor._id));
1062
- if (contributor.isCorresponding) {
990
+ contrib.setAttribute('id', normalizeID(contributor.attrs.id));
991
+ if (contributor.attrs.isCorresponding) {
1063
992
  contrib.setAttribute('corresp', 'yes');
1064
993
  }
1065
- if (contributor.ORCIDIdentifier) {
994
+ if (contributor.attrs.ORCIDIdentifier) {
1066
995
  const identifier = this.document.createElement('contrib-id');
1067
996
  identifier.setAttribute('contrib-id-type', 'orcid');
1068
- identifier.textContent = contributor.ORCIDIdentifier;
997
+ identifier.textContent = contributor.attrs.ORCIDIdentifier;
1069
998
  contrib.appendChild(identifier);
1070
999
  }
1071
1000
  const name = this.buildContributorName(contributor);
1072
1001
  contrib.appendChild(name);
1073
- if (contributor.email) {
1002
+ if (contributor.attrs.email) {
1074
1003
  const email = this.document.createElement('email');
1075
- email.textContent = contributor.email;
1004
+ email.textContent = contributor.attrs.email;
1076
1005
  contrib.appendChild(email);
1077
1006
  }
1078
- if (contributor.roles) {
1079
- contributor.roles.forEach((rid) => {
1080
- const contributorRole = this.modelMap.get(rid);
1081
- if (contributorRole) {
1082
- const role = this.document.createElement('role');
1083
- const attributes = chooseRoleVocabAttributes(contributorRole);
1084
- for (const [key, value] of Object.entries(attributes)) {
1085
- role.setAttribute(key, value);
1086
- }
1087
- role.textContent = contributorRole.name;
1088
- contrib.appendChild(role);
1089
- }
1090
- });
1091
- }
1092
- if (contributor.affiliations) {
1093
- contributor.affiliations.forEach((rid) => {
1007
+ if (contributor.attrs.affiliations) {
1008
+ contributor.attrs.affiliations.forEach((rid) => {
1094
1009
  const xref = this.document.createElement('xref');
1095
1010
  xref.setAttribute('ref-type', 'aff');
1096
1011
  xref.setAttribute('rid', normalizeID(rid));
@@ -1098,8 +1013,8 @@ class JATSExporter {
1098
1013
  contrib.appendChild(xref);
1099
1014
  });
1100
1015
  }
1101
- if (contributor.footnote) {
1102
- contributor.footnote.map((note) => {
1016
+ if (contributor.attrs.footnote) {
1017
+ contributor.attrs.footnote.map((note) => {
1103
1018
  const xref = this.document.createElement('xref');
1104
1019
  xref.setAttribute('ref-type', 'fn');
1105
1020
  xref.setAttribute('rid', normalizeID(note.noteID));
@@ -1107,8 +1022,8 @@ class JATSExporter {
1107
1022
  contrib.appendChild(xref);
1108
1023
  });
1109
1024
  }
1110
- if (contributor.corresp) {
1111
- contributor.corresp.map((corresp) => {
1025
+ if (contributor.attrs.corresp) {
1026
+ contributor.attrs.corresp.map((corresp) => {
1112
1027
  const xref = this.document.createElement('xref');
1113
1028
  xref.setAttribute('ref-type', 'corresp');
1114
1029
  xref.setAttribute('rid', normalizeID(corresp.correspID));
@@ -1118,13 +1033,10 @@ class JATSExporter {
1118
1033
  }
1119
1034
  contribGroup.appendChild(contrib);
1120
1035
  });
1121
- const otherContributors = contributors
1122
- .filter((contributor) => contributor.role !== 'author')
1123
- .sort(sortContributors);
1124
- if (otherContributors.length) {
1036
+ if (otherContributorsNodes.length) {
1125
1037
  const contribGroup = this.document.createElement('contrib-group');
1126
1038
  articleMeta.appendChild(contribGroup);
1127
- otherContributors.forEach((contributor) => {
1039
+ otherContributorsNodes.forEach((contributor) => {
1128
1040
  try {
1129
1041
  this.validateContributor(contributor);
1130
1042
  }
@@ -1133,30 +1045,16 @@ class JATSExporter {
1133
1045
  return;
1134
1046
  }
1135
1047
  const contrib = this.document.createElement('contrib');
1136
- contrib.setAttribute('id', normalizeID(contributor._id));
1048
+ contrib.setAttribute('id', normalizeID(contributor.attrs.id));
1137
1049
  const name = this.buildContributorName(contributor);
1138
1050
  contrib.appendChild(name);
1139
- if (contributor.email) {
1051
+ if (contributor.attrs.email) {
1140
1052
  const email = this.document.createElement('email');
1141
- email.textContent = contributor.email;
1053
+ email.textContent = contributor.attrs.email;
1142
1054
  contrib.appendChild(email);
1143
1055
  }
1144
- if (contributor.roles) {
1145
- contributor.roles.forEach((rid) => {
1146
- const contributorRole = this.modelMap.get(rid);
1147
- if (contributorRole) {
1148
- const role = this.document.createElement('role');
1149
- const attributes = chooseRoleVocabAttributes(contributorRole);
1150
- for (const [key, value] of Object.entries(attributes)) {
1151
- role.setAttribute(key, value);
1152
- }
1153
- role.textContent = contributorRole.name;
1154
- contrib.appendChild(role);
1155
- }
1156
- });
1157
- }
1158
- if (contributor.affiliations) {
1159
- contributor.affiliations.forEach((rid) => {
1056
+ if (contributor.attrs.affiliations) {
1057
+ contributor.attrs.affiliations.forEach((rid) => {
1160
1058
  const xref = this.document.createElement('xref');
1161
1059
  xref.setAttribute('ref-type', 'aff');
1162
1060
  xref.setAttribute('rid', normalizeID(rid));
@@ -1164,8 +1062,8 @@ class JATSExporter {
1164
1062
  contrib.appendChild(xref);
1165
1063
  });
1166
1064
  }
1167
- if (contributor.footnote) {
1168
- contributor.footnote.map((note) => {
1065
+ if (contributor.attrs.footnote) {
1066
+ contributor.attrs.footnote.map((note) => {
1169
1067
  const xref = this.document.createElement('xref');
1170
1068
  xref.setAttribute('ref-type', 'fn');
1171
1069
  xref.setAttribute('rid', normalizeID(note.noteID));
@@ -1177,64 +1075,68 @@ class JATSExporter {
1177
1075
  });
1178
1076
  }
1179
1077
  const affiliationRIDs = [];
1180
- const sortedContributors = [...authorContributors, ...otherContributors];
1078
+ const sortedContributors = [
1079
+ ...authorContributorNodes,
1080
+ ...otherContributorsNodes,
1081
+ ];
1181
1082
  for (const contributor of sortedContributors) {
1182
- if (contributor.affiliations) {
1183
- affiliationRIDs.push(...contributor.affiliations);
1083
+ if (contributor.attrs.affiliations) {
1084
+ affiliationRIDs.push(...contributor.attrs.affiliations);
1184
1085
  }
1185
1086
  }
1186
- const affiliations = this.models.filter((0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.Affiliation));
1087
+ const affiliations = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.affiliation).map((result) => result.node);
1187
1088
  if (affiliations) {
1188
- const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation._id));
1189
- usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a._id) - affiliationRIDs.indexOf(b._id));
1089
+ const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation.attrs.id));
1090
+ usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a.attrs.id) -
1091
+ affiliationRIDs.indexOf(b.attrs.id));
1190
1092
  usedAffiliations.forEach((affiliation) => {
1191
1093
  var _a, _b;
1192
1094
  const aff = this.document.createElement('aff');
1193
- aff.setAttribute('id', normalizeID(affiliation._id));
1095
+ aff.setAttribute('id', normalizeID(affiliation.attrs.id));
1194
1096
  contribGroup.appendChild(aff);
1195
- if (affiliation.department) {
1097
+ if (affiliation.attrs.department) {
1196
1098
  const department = this.document.createElement('institution');
1197
1099
  department.setAttribute('content-type', 'dept');
1198
- department.textContent = affiliation.department;
1100
+ department.textContent = affiliation.attrs.department;
1199
1101
  aff.appendChild(department);
1200
1102
  }
1201
- if (affiliation.institution) {
1103
+ if (affiliation.attrs.institution) {
1202
1104
  const institution = this.document.createElement('institution');
1203
- institution.textContent = affiliation.institution;
1105
+ institution.textContent = affiliation.attrs.institution;
1204
1106
  aff.appendChild(institution);
1205
1107
  }
1206
- if (affiliation.addressLine1) {
1108
+ if (affiliation.attrs.addressLine1) {
1207
1109
  const addressLine = this.document.createElement('addr-line');
1208
- addressLine.textContent = affiliation.addressLine1;
1110
+ addressLine.textContent = affiliation.attrs.addressLine1;
1209
1111
  aff.appendChild(addressLine);
1210
1112
  }
1211
- if (affiliation.addressLine2) {
1113
+ if (affiliation.attrs.addressLine2) {
1212
1114
  const addressLine = this.document.createElement('addr-line');
1213
- addressLine.textContent = affiliation.addressLine2;
1115
+ addressLine.textContent = affiliation.attrs.addressLine2;
1214
1116
  aff.appendChild(addressLine);
1215
1117
  }
1216
- if (affiliation.addressLine3) {
1118
+ if (affiliation.attrs.addressLine3) {
1217
1119
  const addressLine = this.document.createElement('addr-line');
1218
- addressLine.textContent = affiliation.addressLine3;
1120
+ addressLine.textContent = affiliation.attrs.addressLine3;
1219
1121
  aff.appendChild(addressLine);
1220
1122
  }
1221
- if (affiliation.city) {
1123
+ if (affiliation.attrs.city) {
1222
1124
  const city = this.document.createElement('city');
1223
- city.textContent = affiliation.city;
1125
+ city.textContent = affiliation.attrs.city;
1224
1126
  aff.appendChild(city);
1225
1127
  }
1226
- if (affiliation.country) {
1128
+ if (affiliation.attrs.country) {
1227
1129
  const country = this.document.createElement('country');
1228
- country.textContent = affiliation.country;
1130
+ country.textContent = affiliation.attrs.country;
1229
1131
  aff.appendChild(country);
1230
1132
  }
1231
- if (affiliation.email) {
1133
+ if (affiliation.attrs.email) {
1232
1134
  const email = this.document.createElement('email');
1233
- email.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = affiliation.email.href) !== null && _a !== void 0 ? _a : '');
1234
- email.textContent = (_b = affiliation.email.text) !== null && _b !== void 0 ? _b : '';
1135
+ email.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = affiliation.attrs.email.href) !== null && _a !== void 0 ? _a : '');
1136
+ email.textContent = (_b = affiliation.attrs.email.text) !== null && _b !== void 0 ? _b : '';
1235
1137
  aff.appendChild(email);
1236
1138
  }
1237
- const labelNumber = affiliationLabels.get(affiliation._id);
1139
+ const labelNumber = affiliationLabels.get(affiliation.attrs.id);
1238
1140
  if (labelNumber) {
1239
1141
  const label = this.document.createElement('label');
1240
1142
  label.textContent = String(labelNumber);
@@ -1251,41 +1153,48 @@ class JATSExporter {
1251
1153
  this.createAuthorNotesElement = () => {
1252
1154
  var _a;
1253
1155
  const authorNotesEl = this.document.createElement('author-notes');
1254
- const authorNotes = (_a = (0, json_schema_1.getModelsByType)(this.modelMap, json_schema_1.ObjectTypes.AuthorNotes)) === null || _a === void 0 ? void 0 : _a[0];
1255
- if (authorNotes) {
1256
- this.appendModelsToAuthorNotes(authorNotesEl, authorNotes.containedObjectIDs);
1156
+ 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;
1157
+ if (authorNotesNode) {
1158
+ this.appendModelsToAuthorNotes(authorNotesEl, authorNotesNode);
1257
1159
  }
1258
1160
  return authorNotesEl;
1259
1161
  };
1260
1162
  this.appendCorrespondingToElement = (corresponding, element) => {
1261
1163
  const correspondingEl = this.document.createElement('corresp');
1262
- correspondingEl.setAttribute('id', normalizeID(corresponding._id));
1263
- if (corresponding.label) {
1164
+ correspondingEl.setAttribute('id', normalizeID(corresponding.attrs.id));
1165
+ if (corresponding.attrs.label) {
1264
1166
  const labelEl = this.document.createElement('label');
1265
- labelEl.textContent = corresponding.label;
1167
+ labelEl.textContent = corresponding.attrs.label;
1266
1168
  correspondingEl.appendChild(labelEl);
1267
1169
  }
1268
- correspondingEl.append(corresponding.contents);
1170
+ correspondingEl.append(corresponding.textContent);
1269
1171
  element.appendChild(correspondingEl);
1270
1172
  };
1271
1173
  this.appendParagraphToElement = (paragraph, element) => {
1272
- const parsedDoc = new DOMParser().parseFromString(paragraph.contents, 'text/html');
1174
+ const parsedDoc = new DOMParser().parseFromString(paragraph.textContent, 'text/html');
1273
1175
  const parsedParagraph = parsedDoc.body.querySelector('p');
1274
1176
  if (parsedParagraph) {
1275
1177
  const paragraphEl = this.document.createElement('p');
1276
1178
  paragraphEl.innerHTML = parsedParagraph.innerHTML;
1277
- paragraphEl.setAttribute('id', normalizeID(paragraph._id));
1179
+ paragraphEl.setAttribute('id', normalizeID(paragraph.attrs.id));
1278
1180
  element.appendChild(paragraphEl);
1279
1181
  }
1280
1182
  };
1281
1183
  this.appendFootnoteToElement = (footnote, element) => {
1282
1184
  const footnoteEl = this.document.createElement('fn');
1283
- footnoteEl.setAttribute('id', normalizeID(footnote._id));
1284
- footnoteEl.innerHTML = footnote.contents;
1185
+ footnoteEl.setAttribute('id', normalizeID(footnote.attrs.id));
1186
+ if (!footnote.textContent.includes('<p>')) {
1187
+ const p = this.document.createElement('p');
1188
+ p.innerHTML = footnote.textContent;
1189
+ footnoteEl.appendChild(p);
1190
+ }
1191
+ else {
1192
+ footnoteEl.innerHTML = footnote.textContent;
1193
+ }
1285
1194
  element.appendChild(footnoteEl);
1286
1195
  };
1287
- this.fixBody = (body, fragment) => {
1288
- fragment.descendants((node) => {
1196
+ this.fixBody = (body) => {
1197
+ this.manuscriptNode.descendants((node) => {
1289
1198
  if (node.attrs.id) {
1290
1199
  if (node.attrs.titleSuppressed) {
1291
1200
  const title = body.querySelector(`#${normalizeID(node.attrs.id)} > title`);
@@ -1546,36 +1455,36 @@ class JATSExporter {
1546
1455
  };
1547
1456
  this.buildContributorName = (contributor) => {
1548
1457
  const name = this.document.createElement('name');
1549
- if (contributor.bibliographicName.family) {
1458
+ if (contributor.attrs.bibliographicName.family) {
1550
1459
  const surname = this.document.createElement('surname');
1551
- surname.textContent = contributor.bibliographicName.family;
1460
+ surname.textContent = contributor.attrs.bibliographicName.family;
1552
1461
  name.appendChild(surname);
1553
1462
  }
1554
- if (contributor.bibliographicName.given) {
1463
+ if (contributor.attrs.bibliographicName.given) {
1555
1464
  const givenNames = this.document.createElement('given-names');
1556
- givenNames.textContent = contributor.bibliographicName.given;
1465
+ givenNames.textContent = contributor.attrs.bibliographicName.given;
1557
1466
  name.appendChild(givenNames);
1558
1467
  }
1559
1468
  return name;
1560
1469
  };
1561
1470
  }
1562
- generateCitations(fragment) {
1471
+ generateCitations() {
1563
1472
  const nodes = [];
1564
- fragment.descendants((node) => {
1473
+ this.manuscriptNode.descendants((node) => {
1565
1474
  if ((0, schema_1.isCitationNode)(node)) {
1566
1475
  nodes.push(node);
1567
1476
  }
1568
1477
  });
1569
1478
  return (0, exports.buildCitations)(nodes);
1570
1479
  }
1571
- generateCitationTexts(fragment, csl) {
1480
+ generateCitationTexts(csl, manuscriptID) {
1572
1481
  this.citationTexts = new Map();
1573
1482
  this.citationProvider = new library_1.CitationProvider({
1574
- getLibraryItem: (id) => this.modelMap.get(id),
1483
+ getLibraryItem: this.getLibraryItem(manuscriptID),
1575
1484
  locale: csl.locale,
1576
1485
  citationStyle: csl.style,
1577
1486
  });
1578
- const citations = this.generateCitations(fragment);
1487
+ const citations = this.generateCitations();
1579
1488
  this.citationProvider.rebuildState(citations).forEach(([id, , output]) => {
1580
1489
  this.citationTexts.set(id, output);
1581
1490
  });
@@ -1602,72 +1511,50 @@ class JATSExporter {
1602
1511
  return mathml;
1603
1512
  }
1604
1513
  }
1605
- appendModelsToAuthorNotes(authorNotesEl, containedObjectIDs) {
1606
- const contributors = this.models.filter(isContributor);
1607
- const usedCorrespondings = this.getUsedCorrespondings(contributors);
1608
- containedObjectIDs.forEach((id) => {
1609
- const model = this.modelMap.get(id);
1610
- if (!model) {
1611
- return;
1612
- }
1613
- switch (model.objectType) {
1614
- case json_schema_1.ObjectTypes.ParagraphElement:
1615
- this.appendParagraphToElement(model, authorNotesEl);
1514
+ appendModelsToAuthorNotes(authorNotesEl, authorNotesNode) {
1515
+ const contributorsNodes = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.contributor).map((result) => result.node);
1516
+ const usedCorrespondings = this.getUsedCorrespondings(contributorsNodes);
1517
+ authorNotesNode.descendants((node) => {
1518
+ switch (node.type) {
1519
+ case schema_1.schema.nodes.paragraph:
1520
+ this.appendParagraphToElement(node, authorNotesEl);
1616
1521
  break;
1617
- case json_schema_1.ObjectTypes.Footnote:
1618
- this.appendFootnoteToElement(model, authorNotesEl);
1522
+ case schema_1.schema.nodes.footnote:
1523
+ this.appendFootnoteToElement(node, authorNotesEl);
1619
1524
  break;
1620
- case json_schema_1.ObjectTypes.Corresponding:
1621
- if (usedCorrespondings.includes(model)) {
1622
- this.appendCorrespondingToElement(model, authorNotesEl);
1525
+ case schema_1.schema.nodes.corresp:
1526
+ if (usedCorrespondings.includes(node)) {
1527
+ this.appendCorrespondingToElement(node, authorNotesEl);
1623
1528
  }
1624
1529
  break;
1625
1530
  }
1531
+ return false;
1626
1532
  });
1627
1533
  }
1628
1534
  getUsedCorrespondings(contributors) {
1629
1535
  return contributors
1630
- .flatMap((c) => { var _a; return (_a = c.corresp) !== null && _a !== void 0 ? _a : []; })
1631
- .map((corresp) => this.modelMap.get(corresp.correspID))
1536
+ .flatMap((c) => { var _a; return (_a = c.attrs.corresp) !== null && _a !== void 0 ? _a : []; })
1537
+ .map((corresp) => {
1538
+ var _a;
1539
+ return (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attr) => attr.id === corresp.correspID)[0]) === null || _a === void 0 ? void 0 : _a.node;
1540
+ })
1632
1541
  .filter((corresp) => !!corresp);
1633
1542
  }
1634
1543
  buildKeywords(articleMeta) {
1635
- const keywords = [...this.modelMap.values()].filter((model) => model.objectType === json_schema_1.ObjectTypes.Keyword);
1636
- const keywordGroups = new Map();
1637
- keywords.forEach((keyword) => {
1638
- const containedGroup = keyword.containedGroup || '';
1639
- const group = keywordGroups.get(containedGroup);
1640
- if (group) {
1641
- group.push(keyword);
1642
- }
1643
- else {
1644
- keywordGroups.set(containedGroup, [keyword]);
1645
- }
1646
- });
1647
- for (const [groupID, keywords] of keywordGroups) {
1648
- const keywordGroup = (this.modelMap.get(groupID) || {});
1544
+ const keywordGroups = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.keyword_group).map((result) => result.node);
1545
+ keywordGroups.forEach((group) => {
1649
1546
  const kwdGroup = this.document.createElement('kwd-group');
1650
- if (keywordGroup.type) {
1651
- kwdGroup.setAttribute('kwd-group-type', keywordGroup.type);
1652
- }
1653
- if (keywordGroup.label) {
1654
- const label = this.document.createElement('label');
1655
- label.textContent = keywordGroup.label;
1656
- kwdGroup.appendChild(label);
1657
- }
1658
- if (keywordGroup.title) {
1659
- const title = this.document.createElement('title');
1660
- title.textContent = keywordGroup.title;
1661
- kwdGroup.appendChild(title);
1547
+ if (group.attrs.type) {
1548
+ kwdGroup.setAttribute('kwd-group-type', group.attrs.type);
1662
1549
  }
1663
1550
  articleMeta.appendChild(kwdGroup);
1664
- for (const keyword of keywords) {
1551
+ group.content.forEach((keyword) => {
1665
1552
  const kwd = this.document.createElement('kwd');
1666
- kwd.textContent = keyword.name;
1553
+ kwd.textContent = keyword.textContent;
1667
1554
  kwdGroup.appendChild(kwd);
1668
- }
1555
+ });
1669
1556
  articleMeta.appendChild(kwdGroup);
1670
- }
1557
+ });
1671
1558
  }
1672
1559
  moveCoiStatementToAuthorNotes(back, front) {
1673
1560
  const fnGroups = back.querySelectorAll('fn-group');