@manuscripts/transform 2.3.36 → 2.3.37-LEAN-3911.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +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 +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 +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 +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 +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, 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
  box_element: () => ['boxed-text', 0],
598
537
  author_notes: () => '',
@@ -655,24 +594,25 @@ class JATSExporter {
655
594
  return xref;
656
595
  },
657
596
  cross_reference: (node) => {
597
+ var _a;
658
598
  const cross = node;
659
599
  const rids = cross.attrs.rids;
660
600
  if (!rids.length) {
661
601
  return cross.attrs.label;
662
602
  }
663
603
  const text = cross.attrs.customLabel || cross.attrs.label;
664
- const model = getModel(rids[0]);
665
- if (!model) {
604
+ const target = (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attrs) => attrs.id === rids[0])[0]) === null || _a === void 0 ? void 0 : _a.node;
605
+ if (!target) {
666
606
  warn('');
667
607
  return text;
668
608
  }
669
609
  const xref = this.document.createElement('xref');
670
- const type = chooseRefType(model.objectType);
610
+ const type = chooseRefType(target.type);
671
611
  if (type) {
672
612
  xref.setAttribute('ref-type', type);
673
613
  }
674
614
  else {
675
- warn(`Unset ref-type for objectType ${model.objectType}`);
615
+ warn(`Unset ref-type for schema type ${target.type.name}`);
676
616
  }
677
617
  xref.setAttribute('rid', normalizeID(rids.join(' ')));
678
618
  xref.textContent = text;
@@ -744,7 +684,10 @@ class JATSExporter {
744
684
  hard_break: () => '',
745
685
  highlight_marker: () => '',
746
686
  inline_footnote: (node) => {
747
- const rids = node.attrs.rids.filter(getModel);
687
+ const rids = node.attrs.rids.filter((rid) => {
688
+ var _a;
689
+ return (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attrs) => attrs.id === rid)[0]) === null || _a === void 0 ? void 0 : _a.node;
690
+ });
748
691
  if (rids.length == 0) {
749
692
  return '';
750
693
  }
@@ -863,14 +806,7 @@ class JATSExporter {
863
806
  italic: () => ['italic'],
864
807
  smallcaps: () => ['sc'],
865
808
  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
- },
809
+ styled: () => ['styled-content'],
874
810
  superscript: () => ['sup'],
875
811
  subscript: () => ['sub'],
876
812
  underline: () => ['underline'],
@@ -921,14 +857,16 @@ class JATSExporter {
921
857
  }
922
858
  };
923
859
  const appendChildNodeOfType = (element, node, type) => {
924
- const childNode = findChildNodeOfType(node, type);
860
+ var _a;
861
+ const childNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, type)[0]) === null || _a === void 0 ? void 0 : _a.node;
925
862
  if (childNode) {
926
863
  element.appendChild(this.serializeNode(childNode));
927
864
  }
928
865
  };
929
866
  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);
867
+ var _a, _b;
868
+ const tableNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.table)[0]) === null || _a === void 0 ? void 0 : _a.node;
869
+ const colGroupNode = (_b = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.table_colgroup)[0]) === null || _b === void 0 ? void 0 : _b.node;
932
870
  if (!tableNode) {
933
871
  return;
934
872
  }
@@ -974,7 +912,8 @@ class JATSExporter {
974
912
  return element;
975
913
  };
976
914
  const processExecutableNode = (node, element) => {
977
- const listingNode = findChildNodeOfType(node, node.type.schema.nodes.listing);
915
+ var _a;
916
+ const listingNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.listing)[0]) === null || _a === void 0 ? void 0 : _a.node;
978
917
  if (listingNode) {
979
918
  const { contents, languageKey } = listingNode.attrs;
980
919
  if (contents && languageKey) {
@@ -1008,25 +947,25 @@ class JATSExporter {
1008
947
  }
1009
948
  };
1010
949
  };
1011
- this.serializeFragment = (fragment) => this.serializer.serializeFragment(fragment, {
1012
- document: this.document,
1013
- });
1014
950
  this.serializeNode = (node) => this.serializer.serializeNode(node, {
1015
951
  document: this.document,
1016
952
  });
1017
953
  this.validateContributor = (contributor) => {
1018
- if (!contributor.bibliographicName) {
1019
- throw new Error(`${contributor._id} has no bibliographicName`);
954
+ if (!contributor.attrs.bibliographicName) {
955
+ throw new Error(`${contributor.attrs.id} has no bibliographicName`);
1020
956
  }
1021
- const { family, given } = contributor.bibliographicName;
957
+ const { family, given } = contributor.attrs.bibliographicName;
1022
958
  if (!family && !given) {
1023
- throw new Error(`${contributor._id} has neither family nor given name`);
959
+ throw new Error(`${contributor.attrs.id} has neither family nor given name`);
1024
960
  }
1025
961
  };
1026
962
  this.buildContributors = (articleMeta) => {
1027
- const contributors = this.models.filter(isContributor);
1028
- const authorContributors = contributors
1029
- .filter((contributor) => contributor.role === 'author')
963
+ const contributorNodes = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.contributor).map((result) => result.node);
964
+ const authorContributorNodes = contributorNodes
965
+ .filter((n) => n.attrs.role === 'author')
966
+ .sort(sortContributors);
967
+ const otherContributorsNodes = contributorNodes
968
+ .filter((n) => n.attrs.role !== 'author')
1030
969
  .sort(sortContributors);
1031
970
  const affiliationLabels = new Map();
1032
971
  const creatAffiliationLabel = (rid) => {
@@ -1044,11 +983,11 @@ class JATSExporter {
1044
983
  sup.textContent = String(content);
1045
984
  return sup;
1046
985
  };
1047
- if (authorContributors.length) {
986
+ if (authorContributorNodes.length) {
1048
987
  const contribGroup = this.document.createElement('contrib-group');
1049
988
  contribGroup.setAttribute('content-type', 'authors');
1050
989
  articleMeta.appendChild(contribGroup);
1051
- authorContributors.forEach((contributor) => {
990
+ authorContributorNodes.forEach((contributor) => {
1052
991
  try {
1053
992
  this.validateContributor(contributor);
1054
993
  }
@@ -1058,39 +997,25 @@ class JATSExporter {
1058
997
  }
1059
998
  const contrib = this.document.createElement('contrib');
1060
999
  contrib.setAttribute('contrib-type', 'author');
1061
- contrib.setAttribute('id', normalizeID(contributor._id));
1062
- if (contributor.isCorresponding) {
1000
+ contrib.setAttribute('id', normalizeID(contributor.attrs.id));
1001
+ if (contributor.attrs.isCorresponding) {
1063
1002
  contrib.setAttribute('corresp', 'yes');
1064
1003
  }
1065
- if (contributor.ORCIDIdentifier) {
1004
+ if (contributor.attrs.ORCIDIdentifier) {
1066
1005
  const identifier = this.document.createElement('contrib-id');
1067
1006
  identifier.setAttribute('contrib-id-type', 'orcid');
1068
- identifier.textContent = contributor.ORCIDIdentifier;
1007
+ identifier.textContent = contributor.attrs.ORCIDIdentifier;
1069
1008
  contrib.appendChild(identifier);
1070
1009
  }
1071
1010
  const name = this.buildContributorName(contributor);
1072
1011
  contrib.appendChild(name);
1073
- if (contributor.email) {
1012
+ if (contributor.attrs.email) {
1074
1013
  const email = this.document.createElement('email');
1075
- email.textContent = contributor.email;
1014
+ email.textContent = contributor.attrs.email;
1076
1015
  contrib.appendChild(email);
1077
1016
  }
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) => {
1017
+ if (contributor.attrs.affiliations) {
1018
+ contributor.attrs.affiliations.forEach((rid) => {
1094
1019
  const xref = this.document.createElement('xref');
1095
1020
  xref.setAttribute('ref-type', 'aff');
1096
1021
  xref.setAttribute('rid', normalizeID(rid));
@@ -1098,8 +1023,8 @@ class JATSExporter {
1098
1023
  contrib.appendChild(xref);
1099
1024
  });
1100
1025
  }
1101
- if (contributor.footnote) {
1102
- contributor.footnote.map((note) => {
1026
+ if (contributor.attrs.footnote) {
1027
+ contributor.attrs.footnote.map((note) => {
1103
1028
  const xref = this.document.createElement('xref');
1104
1029
  xref.setAttribute('ref-type', 'fn');
1105
1030
  xref.setAttribute('rid', normalizeID(note.noteID));
@@ -1107,8 +1032,8 @@ class JATSExporter {
1107
1032
  contrib.appendChild(xref);
1108
1033
  });
1109
1034
  }
1110
- if (contributor.corresp) {
1111
- contributor.corresp.map((corresp) => {
1035
+ if (contributor.attrs.corresp) {
1036
+ contributor.attrs.corresp.map((corresp) => {
1112
1037
  const xref = this.document.createElement('xref');
1113
1038
  xref.setAttribute('ref-type', 'corresp');
1114
1039
  xref.setAttribute('rid', normalizeID(corresp.correspID));
@@ -1118,13 +1043,10 @@ class JATSExporter {
1118
1043
  }
1119
1044
  contribGroup.appendChild(contrib);
1120
1045
  });
1121
- const otherContributors = contributors
1122
- .filter((contributor) => contributor.role !== 'author')
1123
- .sort(sortContributors);
1124
- if (otherContributors.length) {
1046
+ if (otherContributorsNodes.length) {
1125
1047
  const contribGroup = this.document.createElement('contrib-group');
1126
1048
  articleMeta.appendChild(contribGroup);
1127
- otherContributors.forEach((contributor) => {
1049
+ otherContributorsNodes.forEach((contributor) => {
1128
1050
  try {
1129
1051
  this.validateContributor(contributor);
1130
1052
  }
@@ -1133,30 +1055,16 @@ class JATSExporter {
1133
1055
  return;
1134
1056
  }
1135
1057
  const contrib = this.document.createElement('contrib');
1136
- contrib.setAttribute('id', normalizeID(contributor._id));
1058
+ contrib.setAttribute('id', normalizeID(contributor.attrs.id));
1137
1059
  const name = this.buildContributorName(contributor);
1138
1060
  contrib.appendChild(name);
1139
- if (contributor.email) {
1061
+ if (contributor.attrs.email) {
1140
1062
  const email = this.document.createElement('email');
1141
- email.textContent = contributor.email;
1063
+ email.textContent = contributor.attrs.email;
1142
1064
  contrib.appendChild(email);
1143
1065
  }
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) => {
1066
+ if (contributor.attrs.affiliations) {
1067
+ contributor.attrs.affiliations.forEach((rid) => {
1160
1068
  const xref = this.document.createElement('xref');
1161
1069
  xref.setAttribute('ref-type', 'aff');
1162
1070
  xref.setAttribute('rid', normalizeID(rid));
@@ -1164,8 +1072,8 @@ class JATSExporter {
1164
1072
  contrib.appendChild(xref);
1165
1073
  });
1166
1074
  }
1167
- if (contributor.footnote) {
1168
- contributor.footnote.map((note) => {
1075
+ if (contributor.attrs.footnote) {
1076
+ contributor.attrs.footnote.map((note) => {
1169
1077
  const xref = this.document.createElement('xref');
1170
1078
  xref.setAttribute('ref-type', 'fn');
1171
1079
  xref.setAttribute('rid', normalizeID(note.noteID));
@@ -1177,64 +1085,68 @@ class JATSExporter {
1177
1085
  });
1178
1086
  }
1179
1087
  const affiliationRIDs = [];
1180
- const sortedContributors = [...authorContributors, ...otherContributors];
1088
+ const sortedContributors = [
1089
+ ...authorContributorNodes,
1090
+ ...otherContributorsNodes,
1091
+ ];
1181
1092
  for (const contributor of sortedContributors) {
1182
- if (contributor.affiliations) {
1183
- affiliationRIDs.push(...contributor.affiliations);
1093
+ if (contributor.attrs.affiliations) {
1094
+ affiliationRIDs.push(...contributor.attrs.affiliations);
1184
1095
  }
1185
1096
  }
1186
- const affiliations = this.models.filter((0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.Affiliation));
1097
+ const affiliations = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.affiliation).map((result) => result.node);
1187
1098
  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));
1099
+ const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation.attrs.id));
1100
+ usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a.attrs.id) -
1101
+ affiliationRIDs.indexOf(b.attrs.id));
1190
1102
  usedAffiliations.forEach((affiliation) => {
1191
1103
  var _a, _b;
1192
1104
  const aff = this.document.createElement('aff');
1193
- aff.setAttribute('id', normalizeID(affiliation._id));
1105
+ aff.setAttribute('id', normalizeID(affiliation.attrs.id));
1194
1106
  contribGroup.appendChild(aff);
1195
- if (affiliation.department) {
1107
+ if (affiliation.attrs.department) {
1196
1108
  const department = this.document.createElement('institution');
1197
1109
  department.setAttribute('content-type', 'dept');
1198
- department.textContent = affiliation.department;
1110
+ department.textContent = affiliation.attrs.department;
1199
1111
  aff.appendChild(department);
1200
1112
  }
1201
- if (affiliation.institution) {
1113
+ if (affiliation.attrs.institution) {
1202
1114
  const institution = this.document.createElement('institution');
1203
- institution.textContent = affiliation.institution;
1115
+ institution.textContent = affiliation.attrs.institution;
1204
1116
  aff.appendChild(institution);
1205
1117
  }
1206
- if (affiliation.addressLine1) {
1118
+ if (affiliation.attrs.addressLine1) {
1207
1119
  const addressLine = this.document.createElement('addr-line');
1208
- addressLine.textContent = affiliation.addressLine1;
1120
+ addressLine.textContent = affiliation.attrs.addressLine1;
1209
1121
  aff.appendChild(addressLine);
1210
1122
  }
1211
- if (affiliation.addressLine2) {
1123
+ if (affiliation.attrs.addressLine2) {
1212
1124
  const addressLine = this.document.createElement('addr-line');
1213
- addressLine.textContent = affiliation.addressLine2;
1125
+ addressLine.textContent = affiliation.attrs.addressLine2;
1214
1126
  aff.appendChild(addressLine);
1215
1127
  }
1216
- if (affiliation.addressLine3) {
1128
+ if (affiliation.attrs.addressLine3) {
1217
1129
  const addressLine = this.document.createElement('addr-line');
1218
- addressLine.textContent = affiliation.addressLine3;
1130
+ addressLine.textContent = affiliation.attrs.addressLine3;
1219
1131
  aff.appendChild(addressLine);
1220
1132
  }
1221
- if (affiliation.city) {
1133
+ if (affiliation.attrs.city) {
1222
1134
  const city = this.document.createElement('city');
1223
- city.textContent = affiliation.city;
1135
+ city.textContent = affiliation.attrs.city;
1224
1136
  aff.appendChild(city);
1225
1137
  }
1226
- if (affiliation.country) {
1138
+ if (affiliation.attrs.country) {
1227
1139
  const country = this.document.createElement('country');
1228
- country.textContent = affiliation.country;
1140
+ country.textContent = affiliation.attrs.country;
1229
1141
  aff.appendChild(country);
1230
1142
  }
1231
- if (affiliation.email) {
1143
+ if (affiliation.attrs.email) {
1232
1144
  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 : '';
1145
+ email.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = affiliation.attrs.email.href) !== null && _a !== void 0 ? _a : '');
1146
+ email.textContent = (_b = affiliation.attrs.email.text) !== null && _b !== void 0 ? _b : '';
1235
1147
  aff.appendChild(email);
1236
1148
  }
1237
- const labelNumber = affiliationLabels.get(affiliation._id);
1149
+ const labelNumber = affiliationLabels.get(affiliation.attrs.id);
1238
1150
  if (labelNumber) {
1239
1151
  const label = this.document.createElement('label');
1240
1152
  label.textContent = String(labelNumber);
@@ -1251,41 +1163,48 @@ class JATSExporter {
1251
1163
  this.createAuthorNotesElement = () => {
1252
1164
  var _a;
1253
1165
  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);
1166
+ const authorNotesNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.author_notes)[0]) === null || _a === void 0 ? void 0 : _a.node;
1167
+ if (authorNotesNode) {
1168
+ this.appendModelsToAuthorNotes(authorNotesEl, authorNotesNode);
1257
1169
  }
1258
1170
  return authorNotesEl;
1259
1171
  };
1260
1172
  this.appendCorrespondingToElement = (corresponding, element) => {
1261
1173
  const correspondingEl = this.document.createElement('corresp');
1262
- correspondingEl.setAttribute('id', normalizeID(corresponding._id));
1263
- if (corresponding.label) {
1174
+ correspondingEl.setAttribute('id', normalizeID(corresponding.attrs.id));
1175
+ if (corresponding.attrs.label) {
1264
1176
  const labelEl = this.document.createElement('label');
1265
- labelEl.textContent = corresponding.label;
1177
+ labelEl.textContent = corresponding.attrs.label;
1266
1178
  correspondingEl.appendChild(labelEl);
1267
1179
  }
1268
- correspondingEl.append(corresponding.contents);
1180
+ correspondingEl.append(corresponding.textContent);
1269
1181
  element.appendChild(correspondingEl);
1270
1182
  };
1271
1183
  this.appendParagraphToElement = (paragraph, element) => {
1272
- const parsedDoc = new DOMParser().parseFromString(paragraph.contents, 'text/html');
1184
+ const parsedDoc = new DOMParser().parseFromString(paragraph.textContent, 'text/html');
1273
1185
  const parsedParagraph = parsedDoc.body.querySelector('p');
1274
1186
  if (parsedParagraph) {
1275
1187
  const paragraphEl = this.document.createElement('p');
1276
1188
  paragraphEl.innerHTML = parsedParagraph.innerHTML;
1277
- paragraphEl.setAttribute('id', normalizeID(paragraph._id));
1189
+ paragraphEl.setAttribute('id', normalizeID(paragraph.attrs.id));
1278
1190
  element.appendChild(paragraphEl);
1279
1191
  }
1280
1192
  };
1281
1193
  this.appendFootnoteToElement = (footnote, element) => {
1282
1194
  const footnoteEl = this.document.createElement('fn');
1283
- footnoteEl.setAttribute('id', normalizeID(footnote._id));
1284
- footnoteEl.innerHTML = footnote.contents;
1195
+ footnoteEl.setAttribute('id', normalizeID(footnote.attrs.id));
1196
+ if (!footnote.textContent.includes('<p>')) {
1197
+ const p = this.document.createElement('p');
1198
+ p.innerHTML = footnote.textContent;
1199
+ footnoteEl.appendChild(p);
1200
+ }
1201
+ else {
1202
+ footnoteEl.innerHTML = footnote.textContent;
1203
+ }
1285
1204
  element.appendChild(footnoteEl);
1286
1205
  };
1287
- this.fixBody = (body, fragment) => {
1288
- fragment.descendants((node) => {
1206
+ this.fixBody = (body) => {
1207
+ this.manuscriptNode.descendants((node) => {
1289
1208
  if (node.attrs.id) {
1290
1209
  if (node.attrs.titleSuppressed) {
1291
1210
  const title = body.querySelector(`#${normalizeID(node.attrs.id)} > title`);
@@ -1546,36 +1465,36 @@ class JATSExporter {
1546
1465
  };
1547
1466
  this.buildContributorName = (contributor) => {
1548
1467
  const name = this.document.createElement('name');
1549
- if (contributor.bibliographicName.family) {
1468
+ if (contributor.attrs.bibliographicName.family) {
1550
1469
  const surname = this.document.createElement('surname');
1551
- surname.textContent = contributor.bibliographicName.family;
1470
+ surname.textContent = contributor.attrs.bibliographicName.family;
1552
1471
  name.appendChild(surname);
1553
1472
  }
1554
- if (contributor.bibliographicName.given) {
1473
+ if (contributor.attrs.bibliographicName.given) {
1555
1474
  const givenNames = this.document.createElement('given-names');
1556
- givenNames.textContent = contributor.bibliographicName.given;
1475
+ givenNames.textContent = contributor.attrs.bibliographicName.given;
1557
1476
  name.appendChild(givenNames);
1558
1477
  }
1559
1478
  return name;
1560
1479
  };
1561
1480
  }
1562
- generateCitations(fragment) {
1481
+ generateCitations() {
1563
1482
  const nodes = [];
1564
- fragment.descendants((node) => {
1483
+ this.manuscriptNode.descendants((node) => {
1565
1484
  if ((0, schema_1.isCitationNode)(node)) {
1566
1485
  nodes.push(node);
1567
1486
  }
1568
1487
  });
1569
1488
  return (0, exports.buildCitations)(nodes);
1570
1489
  }
1571
- generateCitationTexts(fragment, csl) {
1490
+ generateCitationTexts(csl, manuscriptID) {
1572
1491
  this.citationTexts = new Map();
1573
1492
  this.citationProvider = new library_1.CitationProvider({
1574
- getLibraryItem: (id) => this.modelMap.get(id),
1493
+ getLibraryItem: this.getLibraryItem(manuscriptID),
1575
1494
  locale: csl.locale,
1576
1495
  citationStyle: csl.style,
1577
1496
  });
1578
- const citations = this.generateCitations(fragment);
1497
+ const citations = this.generateCitations();
1579
1498
  this.citationProvider.rebuildState(citations).forEach(([id, , output]) => {
1580
1499
  this.citationTexts.set(id, output);
1581
1500
  });
@@ -1602,72 +1521,50 @@ class JATSExporter {
1602
1521
  return mathml;
1603
1522
  }
1604
1523
  }
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);
1524
+ appendModelsToAuthorNotes(authorNotesEl, authorNotesNode) {
1525
+ const contributorsNodes = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.contributor).map((result) => result.node);
1526
+ const usedCorrespondings = this.getUsedCorrespondings(contributorsNodes);
1527
+ authorNotesNode.descendants((node) => {
1528
+ switch (node.type) {
1529
+ case schema_1.schema.nodes.paragraph:
1530
+ this.appendParagraphToElement(node, authorNotesEl);
1616
1531
  break;
1617
- case json_schema_1.ObjectTypes.Footnote:
1618
- this.appendFootnoteToElement(model, authorNotesEl);
1532
+ case schema_1.schema.nodes.footnote:
1533
+ this.appendFootnoteToElement(node, authorNotesEl);
1619
1534
  break;
1620
- case json_schema_1.ObjectTypes.Corresponding:
1621
- if (usedCorrespondings.includes(model)) {
1622
- this.appendCorrespondingToElement(model, authorNotesEl);
1535
+ case schema_1.schema.nodes.corresp:
1536
+ if (usedCorrespondings.includes(node)) {
1537
+ this.appendCorrespondingToElement(node, authorNotesEl);
1623
1538
  }
1624
1539
  break;
1625
1540
  }
1541
+ return false;
1626
1542
  });
1627
1543
  }
1628
1544
  getUsedCorrespondings(contributors) {
1629
1545
  return contributors
1630
- .flatMap((c) => { var _a; return (_a = c.corresp) !== null && _a !== void 0 ? _a : []; })
1631
- .map((corresp) => this.modelMap.get(corresp.correspID))
1546
+ .flatMap((c) => { var _a; return (_a = c.attrs.corresp) !== null && _a !== void 0 ? _a : []; })
1547
+ .map((corresp) => {
1548
+ var _a;
1549
+ return (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attr) => attr.id === corresp.correspID)[0]) === null || _a === void 0 ? void 0 : _a.node;
1550
+ })
1632
1551
  .filter((corresp) => !!corresp);
1633
1552
  }
1634
1553
  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) || {});
1554
+ const keywordGroups = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.keyword_group).map((result) => result.node);
1555
+ keywordGroups.forEach((group) => {
1649
1556
  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);
1557
+ if (group.attrs.type) {
1558
+ kwdGroup.setAttribute('kwd-group-type', group.attrs.type);
1662
1559
  }
1663
1560
  articleMeta.appendChild(kwdGroup);
1664
- for (const keyword of keywords) {
1561
+ group.content.forEach((keyword) => {
1665
1562
  const kwd = this.document.createElement('kwd');
1666
- kwd.textContent = keyword.name;
1563
+ kwd.textContent = keyword.textContent;
1667
1564
  kwdGroup.appendChild(kwd);
1668
- }
1565
+ });
1669
1566
  articleMeta.appendChild(kwdGroup);
1670
- }
1567
+ });
1671
1568
  }
1672
1569
  moveCoiStatementToAuthorNotes(back, front) {
1673
1570
  const fnGroups = back.querySelectorAll('fn-group');