@manuscripts/transform 2.3.37 → 2.3.38-LEAN-3911.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/dist/cjs/index.js +6 -6
  2. package/dist/cjs/jats/{jats-exporter.js → exporter/jats-exporter.js} +263 -390
  3. package/dist/cjs/jats/{jats-versions.js → exporter/jats-versions.js} +1 -3
  4. package/dist/cjs/{transformer → jats/exporter}/labels.js +4 -4
  5. package/dist/cjs/{transformer/filename.js → jats/importer/create-article-node.js} +10 -9
  6. package/dist/cjs/jats/importer/jats-body-transformations.js +73 -0
  7. package/dist/cjs/jats/importer/jats-comments.js +27 -104
  8. package/dist/cjs/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +281 -10
  9. package/dist/cjs/jats/importer/jats-front-transformations.js +79 -0
  10. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +8 -1
  11. package/dist/cjs/jats/importer/jats-parser-utils.js +43 -5
  12. package/dist/cjs/jats/importer/jats-reference-parser.js +16 -23
  13. package/dist/cjs/jats/importer/jats-references.js +18 -18
  14. package/dist/cjs/jats/importer/parse-jats-article.js +40 -78
  15. package/dist/cjs/jats/index.js +7 -7
  16. package/dist/cjs/{transformer/models.js → lib/deafults.js} +3 -1
  17. package/dist/cjs/lib/utils.js +12 -1
  18. package/dist/cjs/transformer/id.js +10 -5
  19. package/dist/cjs/transformer/index.js +0 -18
  20. package/dist/cjs/version.js +1 -1
  21. package/dist/es/index.js +5 -5
  22. package/dist/es/jats/{jats-exporter.js → exporter/jats-exporter.js} +257 -384
  23. package/dist/es/jats/{jats-versions.js → exporter/jats-versions.js} +0 -1
  24. package/dist/es/{transformer → jats/exporter}/labels.js +4 -4
  25. package/dist/es/{transformer/filename.js → jats/importer/create-article-node.js} +8 -7
  26. package/dist/es/jats/importer/jats-body-transformations.js +73 -0
  27. package/dist/es/jats/importer/jats-comments.js +26 -101
  28. package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +282 -11
  29. package/dist/es/jats/importer/jats-front-transformations.js +76 -0
  30. package/dist/es/jats/importer/jats-journal-meta-parser.js +6 -0
  31. package/dist/es/jats/importer/jats-parser-utils.js +44 -6
  32. package/dist/es/jats/importer/jats-reference-parser.js +16 -23
  33. package/dist/es/jats/importer/jats-references.js +18 -18
  34. package/dist/es/jats/importer/parse-jats-article.js +41 -77
  35. package/dist/es/jats/index.js +5 -3
  36. package/dist/{types/transformer/timestamp.d.ts → es/lib/deafults.js} +2 -2
  37. package/dist/es/lib/utils.js +9 -0
  38. package/dist/es/transformer/id.js +8 -3
  39. package/dist/es/transformer/index.js +0 -16
  40. package/dist/es/version.js +1 -1
  41. package/dist/types/index.d.ts +6 -6
  42. package/dist/types/jats/{jats-exporter.d.ts → exporter/jats-exporter.d.ts} +15 -29
  43. package/dist/types/jats/{jats-versions.d.ts → exporter/jats-versions.d.ts} +0 -1
  44. package/dist/types/{transformer → jats/exporter}/labels.d.ts +2 -2
  45. package/dist/{es/transformer/footnote-category.js → types/jats/importer/create-article-node.d.ts} +3 -2
  46. package/dist/types/jats/importer/jats-body-transformations.d.ts +5 -0
  47. package/dist/types/jats/importer/jats-comments.d.ts +4 -10
  48. package/dist/types/jats/importer/{jats-body-dom-parser.d.ts → jats-dom-parser.d.ts} +1 -1
  49. package/dist/{cjs/transformer/serializer.js → types/jats/importer/jats-front-transformations.d.ts} +7 -8
  50. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +10 -0
  51. package/dist/types/jats/importer/jats-references.d.ts +19 -8
  52. package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
  53. package/dist/types/jats/index.d.ts +5 -3
  54. package/dist/types/jats/types.d.ts +1 -0
  55. package/dist/{es/transformer/models.js → types/lib/deafults.d.ts} +2 -2
  56. package/dist/types/lib/utils.d.ts +2 -0
  57. package/dist/types/schema/nodes/bibliography_item.d.ts +3 -3
  58. package/dist/types/schema/nodes/contributor.d.ts +10 -0
  59. package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
  60. package/dist/types/schema/nodes/manuscript.d.ts +8 -7
  61. package/dist/types/schema/nodes/title.d.ts +0 -3
  62. package/dist/types/transformer/id.d.ts +5 -2
  63. package/dist/types/transformer/index.d.ts +0 -16
  64. package/dist/types/version.d.ts +1 -1
  65. package/package.json +2 -1
  66. package/dist/cjs/__tests__/data/project-dump.json +0 -825
  67. package/dist/cjs/jats/importer/index.js +0 -22
  68. package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
  69. package/dist/cjs/transformer/__tests__/__helpers__/doc.js +0 -37
  70. package/dist/cjs/transformer/builders.js +0 -219
  71. package/dist/cjs/transformer/decode.js +0 -874
  72. package/dist/cjs/transformer/document-object-types.js +0 -31
  73. package/dist/cjs/transformer/encode.js +0 -664
  74. package/dist/cjs/transformer/footnote-category.js +0 -20
  75. package/dist/cjs/transformer/footnotes-order.js +0 -60
  76. package/dist/cjs/transformer/highlight-markers.js +0 -138
  77. package/dist/cjs/transformer/html.js +0 -400
  78. package/dist/cjs/transformer/manuscript-dependencies.js +0 -21
  79. package/dist/cjs/transformer/model-map.js +0 -26
  80. package/dist/cjs/transformer/object-types.js +0 -57
  81. package/dist/cjs/transformer/project-bundle.js +0 -94
  82. package/dist/cjs/transformer/timestamp.js +0 -20
  83. package/dist/cjs/transformer/update-identifiers.js +0 -93
  84. package/dist/es/__tests__/data/project-dump.json +0 -825
  85. package/dist/es/jats/importer/index.js +0 -16
  86. package/dist/es/jats/importer/jats-front-parser.js +0 -315
  87. package/dist/es/transformer/__tests__/__helpers__/doc.js +0 -29
  88. package/dist/es/transformer/builders.js +0 -186
  89. package/dist/es/transformer/decode.js +0 -864
  90. package/dist/es/transformer/document-object-types.js +0 -28
  91. package/dist/es/transformer/encode.js +0 -654
  92. package/dist/es/transformer/footnotes-order.js +0 -55
  93. package/dist/es/transformer/highlight-markers.js +0 -132
  94. package/dist/es/transformer/html.js +0 -393
  95. package/dist/es/transformer/manuscript-dependencies.js +0 -17
  96. package/dist/es/transformer/model-map.js +0 -22
  97. package/dist/es/transformer/object-types.js +0 -52
  98. package/dist/es/transformer/project-bundle.js +0 -85
  99. package/dist/es/transformer/serializer.js +0 -17
  100. package/dist/es/transformer/timestamp.js +0 -16
  101. package/dist/es/transformer/update-identifiers.js +0 -87
  102. package/dist/types/jats/importer/index.d.ts +0 -16
  103. package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
  104. package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +0 -18
  105. package/dist/types/transformer/builders.d.ts +0 -61
  106. package/dist/types/transformer/decode.d.ts +0 -51
  107. package/dist/types/transformer/document-object-types.d.ts +0 -17
  108. package/dist/types/transformer/encode.d.ts +0 -29
  109. package/dist/types/transformer/filename.d.ts +0 -16
  110. package/dist/types/transformer/footnote-category.d.ts +0 -17
  111. package/dist/types/transformer/footnotes-order.d.ts +0 -22
  112. package/dist/types/transformer/highlight-markers.d.ts +0 -31
  113. package/dist/types/transformer/html.d.ts +0 -36
  114. package/dist/types/transformer/manuscript-dependencies.d.ts +0 -4
  115. package/dist/types/transformer/model-map.d.ts +0 -19
  116. package/dist/types/transformer/models.d.ts +0 -48
  117. package/dist/types/transformer/object-types.d.ts +0 -30
  118. package/dist/types/transformer/project-bundle.d.ts +0 -30
  119. package/dist/types/transformer/serializer.d.ts +0 -19
  120. package/dist/types/transformer/update-identifiers.d.ts +0 -23
  121. package/dist/types/types.d.ts +0 -2
  122. /package/dist/cjs/{types.js → jats/types.js} +0 -0
  123. /package/dist/es/{types.js → jats/types.js} +0 -0
@@ -23,44 +23,18 @@ 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
- const html_1 = require("../lib/html");
28
- const styled_content_1 = require("../lib/styled-content");
29
- const utils_1 = require("../lib/utils");
30
- const schema_1 = require("../schema");
31
- const filename_1 = require("../transformer/filename");
32
- const labels_1 = require("../transformer/labels");
33
- 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
- const section_category_1 = require("../transformer/section-category");
28
+ const html_1 = require("../../lib/html");
29
+ const utils_1 = require("../../lib/utils");
30
+ const schema_1 = require("../../schema");
31
+ const transformer_1 = require("../../transformer");
37
32
  const jats_versions_1 = require("./jats-versions");
33
+ const labels_1 = require("./labels");
38
34
  const warn = (0, debug_1.default)('manuscripts-transform');
39
35
  const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
40
36
  const normalizeID = (id) => id.replace(/:/g, '_');
41
37
  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
38
  const insertAbstractNode = (articleMeta, abstractNode) => {
65
39
  const siblings = [
66
40
  'kwd-group',
@@ -98,24 +72,24 @@ const createDefaultIdGenerator = () => {
98
72
  return `${element.localName}-${value}`;
99
73
  };
100
74
  };
101
- const chooseRefType = (objectType) => {
102
- switch (objectType) {
103
- case json_schema_1.ObjectTypes.Figure:
104
- case json_schema_1.ObjectTypes.FigureElement:
75
+ const chooseRefType = (type) => {
76
+ switch (type) {
77
+ case schema_1.schema.nodes.figure:
78
+ case schema_1.schema.nodes.figure_element:
105
79
  return 'fig';
106
- case json_schema_1.ObjectTypes.Footnote:
80
+ case schema_1.schema.nodes.footnote:
107
81
  return 'fn';
108
- case json_schema_1.ObjectTypes.Table:
109
- case json_schema_1.ObjectTypes.TableElement:
82
+ case schema_1.schema.nodes.table:
83
+ case schema_1.schema.nodes.table_element:
110
84
  return 'table';
111
- case json_schema_1.ObjectTypes.Section:
85
+ case schema_1.schema.nodes.section:
112
86
  return 'sec';
113
- case json_schema_1.ObjectTypes.Equation:
114
- case json_schema_1.ObjectTypes.EquationElement:
87
+ case schema_1.schema.nodes.equation:
88
+ case schema_1.schema.nodes.equation_element:
115
89
  return 'disp-formula';
116
90
  }
117
91
  };
118
- const sortContributors = (a, b) => Number(a.priority) - Number(b.priority);
92
+ const sortContributors = (a, b) => Number(a.attrs.priority) - Number(b.attrs.priority);
119
93
  const buildCitations = (citations) => citations.map((citation) => ({
120
94
  citationID: citation.attrs.id,
121
95
  citationItems: citation.attrs.rids.map((rid) => ({
@@ -128,39 +102,57 @@ const buildCitations = (citations) => citations.map((citation) => ({
128
102
  exports.buildCitations = buildCitations;
129
103
  class JATSExporter {
130
104
  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);
105
+ this.getLibraryItem = (manuscriptID) => {
106
+ return (id) => {
107
+ var _a;
108
+ const node = (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attrs) => attrs.id === id)[0]) === null || _a === void 0 ? void 0 : _a.node;
109
+ if (!node) {
110
+ return undefined;
111
+ }
112
+ return {
113
+ _id: node.attrs.id,
114
+ issued: node.attrs.issued,
115
+ DOI: node.attrs.doi,
116
+ manuscriptID,
117
+ objectType: json_schema_1.ObjectTypes.BibliographyItem,
118
+ author: node.attrs.author,
119
+ 'container-title': node.attrs.containerTitle,
120
+ volume: node.attrs.volume,
121
+ issue: node.attrs.issue,
122
+ supplement: node.attrs.supplement,
123
+ page: node.attrs.page,
124
+ title: node.attrs.title,
125
+ literal: node.attrs.literal,
126
+ type: node.attrs.type,
127
+ };
128
+ };
129
+ };
130
+ this.serializeToJATS = async (manuscriptNode, options) => {
131
+ var _a;
132
+ this.manuscriptNode = manuscriptNode;
133
+ this.generateCitationTexts(options.csl, manuscriptNode.attrs.id);
136
134
  this.createSerializer();
137
- const versionIds = (0, jats_versions_1.selectVersionIds)(version);
135
+ const versionIds = (0, jats_versions_1.selectVersionIds)((_a = options.version) !== null && _a !== void 0 ? _a : '1.2');
138
136
  this.document = document.implementation.createDocument(null, 'article', document.implementation.createDocumentType('article', versionIds.publicId, versionIds.systemId));
139
137
  const article = this.document.documentElement;
140
138
  article.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', XLINK_NAMESPACE);
141
- const front = this.buildFront(doi, id, links);
139
+ const front = this.buildFront(options.journal);
142
140
  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
- }
141
+ article.setAttribute('article-type', manuscriptNode.attrs.articleType || 'other');
142
+ this.labelTargets = (0, labels_1.buildTargets)(manuscriptNode);
143
+ const body = this.buildBody();
144
+ article.appendChild(body);
145
+ const back = this.buildBack(body);
146
+ this.moveCoiStatementToAuthorNotes(back, front);
147
+ article.appendChild(back);
148
+ this.unwrapBody(body);
149
+ this.moveAbstracts(front, body);
150
+ this.moveFloatsGroup(body, article);
151
+ this.removeBackContainer(body);
152
+ this.updateFootnoteTypes(front, back);
153
+ this.fillEmptyTableFooters(article);
154
+ this.fillEmptyFootnotes(article);
155
+ await this.rewriteIDs();
164
156
  return (0, w3c_xmlserializer_1.default)(this.document);
165
157
  };
166
158
  this.nodeFromJATS = (JATSFragment) => {
@@ -173,19 +165,6 @@ class JATSExporter {
173
165
  template.innerHTML = JATSFragment;
174
166
  return template.firstChild;
175
167
  };
176
- this.rewriteMediaPaths = async (generator) => {
177
- const doc = this.document;
178
- for (const fig of doc.querySelectorAll('fig')) {
179
- for (const graphic of fig.querySelectorAll('graphic')) {
180
- const newHref = await generator(graphic, fig.id);
181
- graphic.setAttributeNS(XLINK_NAMESPACE, 'href', newHref);
182
- }
183
- }
184
- for (const suppl of doc.querySelectorAll('supplementary-material')) {
185
- const newHref = await generator(suppl, suppl.id);
186
- suppl.setAttributeNS(XLINK_NAMESPACE, 'href', newHref);
187
- }
188
- };
189
168
  this.rewriteIDs = async (generator = createDefaultIdGenerator()) => {
190
169
  const ids = new Map();
191
170
  for (const element of this.document.querySelectorAll('[id]')) {
@@ -227,16 +206,14 @@ class JATSExporter {
227
206
  }
228
207
  }
229
208
  };
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);
209
+ this.buildFront = (journal) => {
210
+ var _a;
211
+ 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
212
  const front = this.document.createElement('front');
235
213
  const journalMeta = this.document.createElement('journal-meta');
236
214
  front.appendChild(journalMeta);
237
215
  const articleMeta = this.document.createElement('article-meta');
238
216
  front.appendChild(articleMeta);
239
- const journal = [...this.modelMap.values()].find((model) => model.objectType === json_schema_1.ObjectTypes.Journal);
240
217
  if (journal) {
241
218
  if (journal.journalIdentifiers) {
242
219
  for (const item of journal.journalIdentifiers) {
@@ -285,109 +262,47 @@ class JATSExporter {
285
262
  journalMeta.appendChild(publisher);
286
263
  }
287
264
  }
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) {
265
+ if (this.manuscriptNode.attrs.doi) {
295
266
  const articleID = this.document.createElement('article-id');
296
267
  articleID.setAttribute('pub-id-type', 'doi');
297
- articleID.textContent = (_a = manuscript.DOI) !== null && _a !== void 0 ? _a : doi;
268
+ articleID.textContent = this.manuscriptNode.attrs.doi;
298
269
  articleMeta.appendChild(articleID);
299
270
  }
300
271
  const titleGroup = this.document.createElement('title-group');
301
272
  articleMeta.appendChild(titleGroup);
302
273
  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) {
274
+ if (titleNode) {
312
275
  const element = this.document.createElement('article-title');
313
- this.setTitleContent(element, titles.title);
276
+ this.setTitleContent(element, titleNode.textContent);
314
277
  titleGroup.appendChild(element);
315
278
  }
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
- }
279
+ const supplementsNodes = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.supplement);
280
+ supplementsNodes.forEach(({ node }) => {
281
+ var _a, _b, _c, _d;
282
+ const supplementaryMaterial = this.document.createElement('supplementary-material');
283
+ supplementaryMaterial.setAttribute('id', normalizeID(node.attrs.id));
284
+ supplementaryMaterial.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = node.attrs.href) !== null && _a !== void 0 ? _a : '');
285
+ supplementaryMaterial.setAttribute('mimetype', (_b = node.attrs.mimeType) !== null && _b !== void 0 ? _b : '');
286
+ supplementaryMaterial.setAttribute('mime-subtype', (_c = node.attrs.mimeSubType) !== null && _c !== void 0 ? _c : '');
287
+ const caption = this.document.createElement('caption');
288
+ const title = this.document.createElement('title');
289
+ title.textContent = (_d = node.attrs.title) !== null && _d !== void 0 ? _d : '';
290
+ caption.append(title);
291
+ supplementaryMaterial.append(caption);
292
+ articleMeta.append(supplementaryMaterial);
293
+ });
374
294
  this.buildKeywords(articleMeta);
375
295
  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));
296
+ const figureCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.figure).length;
297
+ countingElements.push(this.buildCountingElement('fig-count', figureCount));
298
+ const equationCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.equation_element).length;
299
+ countingElements.push(this.buildCountingElement('equation-count', equationCount));
300
+ const tableCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.table).length;
301
+ countingElements.push(this.buildCountingElement('table-count', tableCount));
302
+ const referencesCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.bibliography_item).length;
303
+ countingElements.push(this.buildCountingElement('ref-count', referencesCount));
304
+ const wordCount = this.manuscriptNode.textContent.split(/\s+/).length;
305
+ countingElements.push(this.buildCountingElement('word-count', wordCount));
391
306
  countingElements = countingElements.filter((el) => el);
392
307
  if (countingElements.length > 0) {
393
308
  const counts = this.document.createElement('counts');
@@ -422,16 +337,17 @@ class JATSExporter {
422
337
  return wordCount;
423
338
  }
424
339
  };
425
- this.buildBody = (fragment) => {
340
+ this.buildBody = () => {
426
341
  const body = this.document.createElement('body');
427
- fragment.forEach((cFragment) => {
342
+ this.manuscriptNode.forEach((cFragment) => {
428
343
  const serializedNode = this.serializeNode(cFragment);
429
344
  body.append(...serializedNode.childNodes);
430
345
  });
431
- this.fixBody(body, fragment);
346
+ this.fixBody(body);
432
347
  return body;
433
348
  };
434
349
  this.buildBack = (body) => {
350
+ var _a;
435
351
  const back = this.document.createElement('back');
436
352
  this.moveSectionsToBack(back, body);
437
353
  const footnotesElements = this.document.querySelectorAll('sec > fn-group');
@@ -456,7 +372,7 @@ class JATSExporter {
456
372
  back.appendChild(refList);
457
373
  const [meta] = this.citationProvider.makeBibliography();
458
374
  for (const id of meta.entry_ids) {
459
- const bibliographyItem = this.modelMap.get(id[0]);
375
+ 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
376
  const ref = this.document.createElement('ref');
461
377
  ref.setAttribute('id', normalizeID(id[0]));
462
378
  const updateCitationPubType = (citationEl, pubType) => {
@@ -475,21 +391,21 @@ class JATSExporter {
475
391
  citationEl.setAttribute('publication-type', 'journal');
476
392
  }
477
393
  };
478
- if (bibliographyItem.literal) {
394
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.literal) {
479
395
  const mixedCitation = this.document.createElement('mixed-citation');
480
- updateCitationPubType(mixedCitation, bibliographyItem.type);
481
- mixedCitation.textContent = bibliographyItem.literal;
396
+ updateCitationPubType(mixedCitation, bibliographyNode.attrs.type);
397
+ mixedCitation.textContent = bibliographyNode.attrs.literal;
482
398
  ref.appendChild(mixedCitation);
483
399
  refList.appendChild(ref);
484
400
  }
485
401
  else {
486
402
  const citation = this.document.createElement('element-citation');
487
- updateCitationPubType(citation, bibliographyItem.type);
488
- if (bibliographyItem.author) {
403
+ updateCitationPubType(citation, bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.type);
404
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.author) {
489
405
  const personGroupNode = this.document.createElement('person-group');
490
406
  personGroupNode.setAttribute('person-group-type', 'author');
491
407
  citation.appendChild(personGroupNode);
492
- bibliographyItem.author.forEach((author) => {
408
+ bibliographyNode.attrs.author.forEach((author) => {
493
409
  const name = this.document.createElement('string-name');
494
410
  if (author.family) {
495
411
  const node = this.document.createElement('surname');
@@ -511,8 +427,8 @@ class JATSExporter {
511
427
  }
512
428
  });
513
429
  }
514
- if (bibliographyItem.issued) {
515
- const dateParts = bibliographyItem.issued['date-parts'];
430
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issued) {
431
+ const dateParts = bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issued['date-parts'];
516
432
  if (dateParts && dateParts.length) {
517
433
  const [[year, month, day]] = dateParts;
518
434
  if (year) {
@@ -532,33 +448,33 @@ class JATSExporter {
532
448
  }
533
449
  }
534
450
  }
535
- if (bibliographyItem.title) {
451
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.title) {
536
452
  const node = this.document.createElement('article-title');
537
- this.setTitleContent(node, bibliographyItem.title);
453
+ this.setTitleContent(node, bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.title);
538
454
  citation.appendChild(node);
539
455
  }
540
- if (bibliographyItem['container-title']) {
456
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.containerTitle) {
541
457
  const node = this.document.createElement('source');
542
- node.textContent = bibliographyItem['container-title'];
458
+ node.textContent = bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.containerTitle;
543
459
  citation.appendChild(node);
544
460
  }
545
- if (bibliographyItem.volume) {
461
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.volume) {
546
462
  const node = this.document.createElement('volume');
547
- node.textContent = String(bibliographyItem.volume);
463
+ node.textContent = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.volume);
548
464
  citation.appendChild(node);
549
465
  }
550
- if (bibliographyItem.issue) {
466
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issue) {
551
467
  const node = this.document.createElement('issue');
552
- node.textContent = String(bibliographyItem.issue);
468
+ node.textContent = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.issue);
553
469
  citation.appendChild(node);
554
470
  }
555
- if (bibliographyItem.supplement) {
471
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.supplement) {
556
472
  const node = this.document.createElement('supplement');
557
- node.textContent = bibliographyItem.supplement;
473
+ node.textContent = bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.supplement;
558
474
  citation.appendChild(node);
559
475
  }
560
- if (bibliographyItem.page) {
561
- const pageString = String(bibliographyItem.page);
476
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.page) {
477
+ const pageString = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.page);
562
478
  if (/^\d+$/.test(pageString)) {
563
479
  const node = this.document.createElement('fpage');
564
480
  node.textContent = pageString;
@@ -579,10 +495,10 @@ class JATSExporter {
579
495
  citation.appendChild(node);
580
496
  }
581
497
  }
582
- if (bibliographyItem.DOI) {
498
+ if (bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.doi) {
583
499
  const node = this.document.createElement('pub-id');
584
500
  node.setAttribute('pub-id-type', 'doi');
585
- node.textContent = String(bibliographyItem.DOI);
501
+ node.textContent = String(bibliographyNode === null || bibliographyNode === void 0 ? void 0 : bibliographyNode.attrs.doi);
586
502
  citation.appendChild(node);
587
503
  }
588
504
  ref.appendChild(citation);
@@ -592,7 +508,6 @@ class JATSExporter {
592
508
  return back;
593
509
  };
594
510
  this.createSerializer = () => {
595
- const getModel = (id) => id ? this.modelMap.get(id) : undefined;
596
511
  const nodes = {
597
512
  award: () => '',
598
513
  awards: () => '',
@@ -657,24 +572,25 @@ class JATSExporter {
657
572
  return xref;
658
573
  },
659
574
  cross_reference: (node) => {
575
+ var _a;
660
576
  const cross = node;
661
577
  const rids = cross.attrs.rids;
662
578
  if (!rids.length) {
663
579
  return cross.attrs.label;
664
580
  }
665
581
  const text = cross.attrs.customLabel || cross.attrs.label;
666
- const model = getModel(rids[0]);
667
- if (!model) {
582
+ const target = (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attrs) => attrs.id === rids[0])[0]) === null || _a === void 0 ? void 0 : _a.node;
583
+ if (!target) {
668
584
  warn('');
669
585
  return text;
670
586
  }
671
587
  const xref = this.document.createElement('xref');
672
- const type = chooseRefType(model.objectType);
588
+ const type = chooseRefType(target.type);
673
589
  if (type) {
674
590
  xref.setAttribute('ref-type', type);
675
591
  }
676
592
  else {
677
- warn(`Unset ref-type for objectType ${model.objectType}`);
593
+ warn(`Unset ref-type for schema type ${target.type.name}`);
678
594
  }
679
595
  xref.setAttribute('rid', normalizeID(rids.join(' ')));
680
596
  xref.textContent = text;
@@ -746,7 +662,10 @@ class JATSExporter {
746
662
  hard_break: () => '',
747
663
  highlight_marker: () => '',
748
664
  inline_footnote: (node) => {
749
- const rids = node.attrs.rids.filter(getModel);
665
+ const rids = node.attrs.rids.filter((rid) => {
666
+ var _a;
667
+ return (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attrs) => attrs.id === rid)[0]) === null || _a === void 0 ? void 0 : _a.node;
668
+ });
750
669
  if (rids.length == 0) {
751
670
  return '';
752
671
  }
@@ -828,7 +747,7 @@ class JATSExporter {
828
747
  id: normalizeID(node.attrs.id),
829
748
  };
830
749
  if (node.attrs.category) {
831
- attrs['sec-type'] = (0, section_category_1.chooseSecType)(node.attrs.category);
750
+ attrs['sec-type'] = (0, transformer_1.chooseSecType)(node.attrs.category);
832
751
  }
833
752
  return ['sec', attrs, 0];
834
753
  },
@@ -865,14 +784,7 @@ class JATSExporter {
865
784
  italic: () => ['italic'],
866
785
  smallcaps: () => ['sc'],
867
786
  strikethrough: () => ['strike'],
868
- styled: (mark) => {
869
- const inlineStyle = getModel(mark.attrs.rid);
870
- const attrs = {};
871
- if (inlineStyle && inlineStyle.title) {
872
- attrs.style = (0, styled_content_1.normalizeStyleName)(inlineStyle.title);
873
- }
874
- return ['styled-content', attrs];
875
- },
787
+ styled: () => ['styled-content'],
876
788
  superscript: () => ['sup'],
877
789
  subscript: () => ['sub'],
878
790
  underline: () => ['underline'],
@@ -923,14 +835,16 @@ class JATSExporter {
923
835
  }
924
836
  };
925
837
  const appendChildNodeOfType = (element, node, type) => {
926
- const childNode = findChildNodeOfType(node, type);
838
+ var _a;
839
+ const childNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, type)[0]) === null || _a === void 0 ? void 0 : _a.node;
927
840
  if (childNode) {
928
841
  element.appendChild(this.serializeNode(childNode));
929
842
  }
930
843
  };
931
844
  const appendTable = (element, node) => {
932
- const tableNode = findChildNodeOfType(node, node.type.schema.nodes.table);
933
- const colGroupNode = findChildNodeOfType(node, node.type.schema.nodes.table_colgroup);
845
+ var _a, _b;
846
+ const tableNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.table)[0]) === null || _a === void 0 ? void 0 : _a.node;
847
+ const colGroupNode = (_b = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.table_colgroup)[0]) === null || _b === void 0 ? void 0 : _b.node;
934
848
  if (!tableNode) {
935
849
  return;
936
850
  }
@@ -958,7 +872,7 @@ class JATSExporter {
958
872
  appendChildNodeOfType(element, node, node.type.schema.nodes.footnotes_element);
959
873
  processChildNodes(element, node, contentNodeType);
960
874
  appendAttributions(element, node);
961
- if ((0, node_types_1.isExecutableNodeType)(node.type)) {
875
+ if ((0, transformer_1.isExecutableNodeType)(node.type)) {
962
876
  processExecutableNode(node, element);
963
877
  }
964
878
  return element;
@@ -970,13 +884,14 @@ class JATSExporter {
970
884
  appendChildNodeOfType(element, node, node.type.schema.nodes.figcaption);
971
885
  appendTable(element, node);
972
886
  appendChildNodeOfType(element, node, node.type.schema.nodes.table_element_footer);
973
- if ((0, node_types_1.isExecutableNodeType)(node.type)) {
887
+ if ((0, transformer_1.isExecutableNodeType)(node.type)) {
974
888
  processExecutableNode(node, element);
975
889
  }
976
890
  return element;
977
891
  };
978
892
  const processExecutableNode = (node, element) => {
979
- const listingNode = findChildNodeOfType(node, node.type.schema.nodes.listing);
893
+ var _a;
894
+ const listingNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.listing)[0]) === null || _a === void 0 ? void 0 : _a.node;
980
895
  if (listingNode) {
981
896
  const { contents, languageKey } = listingNode.attrs;
982
897
  if (contents && languageKey) {
@@ -994,7 +909,7 @@ class JATSExporter {
994
909
  for (const attachment of attachments) {
995
910
  const p = this.document.createElement('p');
996
911
  caption.appendChild(p);
997
- const filename = (0, filename_1.generateAttachmentFilename)(`${listingNode.attrs.id}:${attachment.id}`, attachment.type);
912
+ const filename = (0, utils_1.generateAttachmentFilename)(`${listingNode.attrs.id}:${attachment.id}`, attachment.type);
998
913
  const supp = this.document.createElement('supplementary-material');
999
914
  supp.setAttributeNS(XLINK_NAMESPACE, 'xlink:href', `suppl/${filename}`);
1000
915
  const [mimeType, mimeSubType] = attachment.type.split('/');
@@ -1010,25 +925,25 @@ class JATSExporter {
1010
925
  }
1011
926
  };
1012
927
  };
1013
- this.serializeFragment = (fragment) => this.serializer.serializeFragment(fragment, {
1014
- document: this.document,
1015
- });
1016
928
  this.serializeNode = (node) => this.serializer.serializeNode(node, {
1017
929
  document: this.document,
1018
930
  });
1019
931
  this.validateContributor = (contributor) => {
1020
- if (!contributor.bibliographicName) {
1021
- throw new Error(`${contributor._id} has no bibliographicName`);
932
+ if (!contributor.attrs.bibliographicName) {
933
+ throw new Error(`${contributor.attrs.id} has no bibliographicName`);
1022
934
  }
1023
- const { family, given } = contributor.bibliographicName;
935
+ const { family, given } = contributor.attrs.bibliographicName;
1024
936
  if (!family && !given) {
1025
- throw new Error(`${contributor._id} has neither family nor given name`);
937
+ throw new Error(`${contributor.attrs.id} has neither family nor given name`);
1026
938
  }
1027
939
  };
1028
940
  this.buildContributors = (articleMeta) => {
1029
- const contributors = this.models.filter(isContributor);
1030
- const authorContributors = contributors
1031
- .filter((contributor) => contributor.role === 'author')
941
+ const contributorNodes = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.contributor).map((result) => result.node);
942
+ const authorContributorNodes = contributorNodes
943
+ .filter((n) => n.attrs.role === 'author')
944
+ .sort(sortContributors);
945
+ const otherContributorsNodes = contributorNodes
946
+ .filter((n) => n.attrs.role !== 'author')
1032
947
  .sort(sortContributors);
1033
948
  const affiliationLabels = new Map();
1034
949
  const creatAffiliationLabel = (rid) => {
@@ -1046,11 +961,11 @@ class JATSExporter {
1046
961
  sup.textContent = String(content);
1047
962
  return sup;
1048
963
  };
1049
- if (authorContributors.length) {
964
+ if (authorContributorNodes.length) {
1050
965
  const contribGroup = this.document.createElement('contrib-group');
1051
966
  contribGroup.setAttribute('content-type', 'authors');
1052
967
  articleMeta.appendChild(contribGroup);
1053
- authorContributors.forEach((contributor) => {
968
+ authorContributorNodes.forEach((contributor) => {
1054
969
  try {
1055
970
  this.validateContributor(contributor);
1056
971
  }
@@ -1060,39 +975,25 @@ class JATSExporter {
1060
975
  }
1061
976
  const contrib = this.document.createElement('contrib');
1062
977
  contrib.setAttribute('contrib-type', 'author');
1063
- contrib.setAttribute('id', normalizeID(contributor._id));
1064
- if (contributor.isCorresponding) {
978
+ contrib.setAttribute('id', normalizeID(contributor.attrs.id));
979
+ if (contributor.attrs.isCorresponding) {
1065
980
  contrib.setAttribute('corresp', 'yes');
1066
981
  }
1067
- if (contributor.ORCIDIdentifier) {
982
+ if (contributor.attrs.ORCIDIdentifier) {
1068
983
  const identifier = this.document.createElement('contrib-id');
1069
984
  identifier.setAttribute('contrib-id-type', 'orcid');
1070
- identifier.textContent = contributor.ORCIDIdentifier;
985
+ identifier.textContent = contributor.attrs.ORCIDIdentifier;
1071
986
  contrib.appendChild(identifier);
1072
987
  }
1073
988
  const name = this.buildContributorName(contributor);
1074
989
  contrib.appendChild(name);
1075
- if (contributor.email) {
990
+ if (contributor.attrs.email) {
1076
991
  const email = this.document.createElement('email');
1077
- email.textContent = contributor.email;
992
+ email.textContent = contributor.attrs.email;
1078
993
  contrib.appendChild(email);
1079
994
  }
1080
- if (contributor.roles) {
1081
- contributor.roles.forEach((rid) => {
1082
- const contributorRole = this.modelMap.get(rid);
1083
- if (contributorRole) {
1084
- const role = this.document.createElement('role');
1085
- const attributes = chooseRoleVocabAttributes(contributorRole);
1086
- for (const [key, value] of Object.entries(attributes)) {
1087
- role.setAttribute(key, value);
1088
- }
1089
- role.textContent = contributorRole.name;
1090
- contrib.appendChild(role);
1091
- }
1092
- });
1093
- }
1094
- if (contributor.affiliations) {
1095
- contributor.affiliations.forEach((rid) => {
995
+ if (contributor.attrs.affiliations) {
996
+ contributor.attrs.affiliations.forEach((rid) => {
1096
997
  const xref = this.document.createElement('xref');
1097
998
  xref.setAttribute('ref-type', 'aff');
1098
999
  xref.setAttribute('rid', normalizeID(rid));
@@ -1100,8 +1001,8 @@ class JATSExporter {
1100
1001
  contrib.appendChild(xref);
1101
1002
  });
1102
1003
  }
1103
- if (contributor.footnote) {
1104
- contributor.footnote.map((note) => {
1004
+ if (contributor.attrs.footnote) {
1005
+ contributor.attrs.footnote.map((note) => {
1105
1006
  const xref = this.document.createElement('xref');
1106
1007
  xref.setAttribute('ref-type', 'fn');
1107
1008
  xref.setAttribute('rid', normalizeID(note.noteID));
@@ -1109,8 +1010,8 @@ class JATSExporter {
1109
1010
  contrib.appendChild(xref);
1110
1011
  });
1111
1012
  }
1112
- if (contributor.corresp) {
1113
- contributor.corresp.map((corresp) => {
1013
+ if (contributor.attrs.corresp) {
1014
+ contributor.attrs.corresp.map((corresp) => {
1114
1015
  const xref = this.document.createElement('xref');
1115
1016
  xref.setAttribute('ref-type', 'corresp');
1116
1017
  xref.setAttribute('rid', normalizeID(corresp.correspID));
@@ -1120,13 +1021,10 @@ class JATSExporter {
1120
1021
  }
1121
1022
  contribGroup.appendChild(contrib);
1122
1023
  });
1123
- const otherContributors = contributors
1124
- .filter((contributor) => contributor.role !== 'author')
1125
- .sort(sortContributors);
1126
- if (otherContributors.length) {
1024
+ if (otherContributorsNodes.length) {
1127
1025
  const contribGroup = this.document.createElement('contrib-group');
1128
1026
  articleMeta.appendChild(contribGroup);
1129
- otherContributors.forEach((contributor) => {
1027
+ otherContributorsNodes.forEach((contributor) => {
1130
1028
  try {
1131
1029
  this.validateContributor(contributor);
1132
1030
  }
@@ -1135,30 +1033,16 @@ class JATSExporter {
1135
1033
  return;
1136
1034
  }
1137
1035
  const contrib = this.document.createElement('contrib');
1138
- contrib.setAttribute('id', normalizeID(contributor._id));
1036
+ contrib.setAttribute('id', normalizeID(contributor.attrs.id));
1139
1037
  const name = this.buildContributorName(contributor);
1140
1038
  contrib.appendChild(name);
1141
- if (contributor.email) {
1039
+ if (contributor.attrs.email) {
1142
1040
  const email = this.document.createElement('email');
1143
- email.textContent = contributor.email;
1041
+ email.textContent = contributor.attrs.email;
1144
1042
  contrib.appendChild(email);
1145
1043
  }
1146
- if (contributor.roles) {
1147
- contributor.roles.forEach((rid) => {
1148
- const contributorRole = this.modelMap.get(rid);
1149
- if (contributorRole) {
1150
- const role = this.document.createElement('role');
1151
- const attributes = chooseRoleVocabAttributes(contributorRole);
1152
- for (const [key, value] of Object.entries(attributes)) {
1153
- role.setAttribute(key, value);
1154
- }
1155
- role.textContent = contributorRole.name;
1156
- contrib.appendChild(role);
1157
- }
1158
- });
1159
- }
1160
- if (contributor.affiliations) {
1161
- contributor.affiliations.forEach((rid) => {
1044
+ if (contributor.attrs.affiliations) {
1045
+ contributor.attrs.affiliations.forEach((rid) => {
1162
1046
  const xref = this.document.createElement('xref');
1163
1047
  xref.setAttribute('ref-type', 'aff');
1164
1048
  xref.setAttribute('rid', normalizeID(rid));
@@ -1166,8 +1050,8 @@ class JATSExporter {
1166
1050
  contrib.appendChild(xref);
1167
1051
  });
1168
1052
  }
1169
- if (contributor.footnote) {
1170
- contributor.footnote.map((note) => {
1053
+ if (contributor.attrs.footnote) {
1054
+ contributor.attrs.footnote.map((note) => {
1171
1055
  const xref = this.document.createElement('xref');
1172
1056
  xref.setAttribute('ref-type', 'fn');
1173
1057
  xref.setAttribute('rid', normalizeID(note.noteID));
@@ -1179,64 +1063,68 @@ class JATSExporter {
1179
1063
  });
1180
1064
  }
1181
1065
  const affiliationRIDs = [];
1182
- const sortedContributors = [...authorContributors, ...otherContributors];
1066
+ const sortedContributors = [
1067
+ ...authorContributorNodes,
1068
+ ...otherContributorsNodes,
1069
+ ];
1183
1070
  for (const contributor of sortedContributors) {
1184
- if (contributor.affiliations) {
1185
- affiliationRIDs.push(...contributor.affiliations);
1071
+ if (contributor.attrs.affiliations) {
1072
+ affiliationRIDs.push(...contributor.attrs.affiliations);
1186
1073
  }
1187
1074
  }
1188
- const affiliations = this.models.filter((0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.Affiliation));
1075
+ const affiliations = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.affiliation).map((result) => result.node);
1189
1076
  if (affiliations) {
1190
- const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation._id));
1191
- usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a._id) - affiliationRIDs.indexOf(b._id));
1077
+ const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation.attrs.id));
1078
+ usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a.attrs.id) -
1079
+ affiliationRIDs.indexOf(b.attrs.id));
1192
1080
  usedAffiliations.forEach((affiliation) => {
1193
1081
  var _a, _b;
1194
1082
  const aff = this.document.createElement('aff');
1195
- aff.setAttribute('id', normalizeID(affiliation._id));
1083
+ aff.setAttribute('id', normalizeID(affiliation.attrs.id));
1196
1084
  contribGroup.appendChild(aff);
1197
- if (affiliation.department) {
1085
+ if (affiliation.attrs.department) {
1198
1086
  const department = this.document.createElement('institution');
1199
1087
  department.setAttribute('content-type', 'dept');
1200
- department.textContent = affiliation.department;
1088
+ department.textContent = affiliation.attrs.department;
1201
1089
  aff.appendChild(department);
1202
1090
  }
1203
- if (affiliation.institution) {
1091
+ if (affiliation.attrs.institution) {
1204
1092
  const institution = this.document.createElement('institution');
1205
- institution.textContent = affiliation.institution;
1093
+ institution.textContent = affiliation.attrs.institution;
1206
1094
  aff.appendChild(institution);
1207
1095
  }
1208
- if (affiliation.addressLine1) {
1096
+ if (affiliation.attrs.addressLine1) {
1209
1097
  const addressLine = this.document.createElement('addr-line');
1210
- addressLine.textContent = affiliation.addressLine1;
1098
+ addressLine.textContent = affiliation.attrs.addressLine1;
1211
1099
  aff.appendChild(addressLine);
1212
1100
  }
1213
- if (affiliation.addressLine2) {
1101
+ if (affiliation.attrs.addressLine2) {
1214
1102
  const addressLine = this.document.createElement('addr-line');
1215
- addressLine.textContent = affiliation.addressLine2;
1103
+ addressLine.textContent = affiliation.attrs.addressLine2;
1216
1104
  aff.appendChild(addressLine);
1217
1105
  }
1218
- if (affiliation.addressLine3) {
1106
+ if (affiliation.attrs.addressLine3) {
1219
1107
  const addressLine = this.document.createElement('addr-line');
1220
- addressLine.textContent = affiliation.addressLine3;
1108
+ addressLine.textContent = affiliation.attrs.addressLine3;
1221
1109
  aff.appendChild(addressLine);
1222
1110
  }
1223
- if (affiliation.city) {
1111
+ if (affiliation.attrs.city) {
1224
1112
  const city = this.document.createElement('city');
1225
- city.textContent = affiliation.city;
1113
+ city.textContent = affiliation.attrs.city;
1226
1114
  aff.appendChild(city);
1227
1115
  }
1228
- if (affiliation.country) {
1116
+ if (affiliation.attrs.country) {
1229
1117
  const country = this.document.createElement('country');
1230
- country.textContent = affiliation.country;
1118
+ country.textContent = affiliation.attrs.country;
1231
1119
  aff.appendChild(country);
1232
1120
  }
1233
- if (affiliation.email) {
1121
+ if (affiliation.attrs.email) {
1234
1122
  const email = this.document.createElement('email');
1235
- email.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = affiliation.email.href) !== null && _a !== void 0 ? _a : '');
1236
- email.textContent = (_b = affiliation.email.text) !== null && _b !== void 0 ? _b : '';
1123
+ email.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = affiliation.attrs.email.href) !== null && _a !== void 0 ? _a : '');
1124
+ email.textContent = (_b = affiliation.attrs.email.text) !== null && _b !== void 0 ? _b : '';
1237
1125
  aff.appendChild(email);
1238
1126
  }
1239
- const labelNumber = affiliationLabels.get(affiliation._id);
1127
+ const labelNumber = affiliationLabels.get(affiliation.attrs.id);
1240
1128
  if (labelNumber) {
1241
1129
  const label = this.document.createElement('label');
1242
1130
  label.textContent = String(labelNumber);
@@ -1253,41 +1141,48 @@ class JATSExporter {
1253
1141
  this.createAuthorNotesElement = () => {
1254
1142
  var _a;
1255
1143
  const authorNotesEl = this.document.createElement('author-notes');
1256
- const authorNotes = (_a = (0, json_schema_1.getModelsByType)(this.modelMap, json_schema_1.ObjectTypes.AuthorNotes)) === null || _a === void 0 ? void 0 : _a[0];
1257
- if (authorNotes) {
1258
- this.appendModelsToAuthorNotes(authorNotesEl, authorNotes.containedObjectIDs);
1144
+ 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;
1145
+ if (authorNotesNode) {
1146
+ this.appendModelsToAuthorNotes(authorNotesEl, authorNotesNode);
1259
1147
  }
1260
1148
  return authorNotesEl;
1261
1149
  };
1262
1150
  this.appendCorrespondingToElement = (corresponding, element) => {
1263
1151
  const correspondingEl = this.document.createElement('corresp');
1264
- correspondingEl.setAttribute('id', normalizeID(corresponding._id));
1265
- if (corresponding.label) {
1152
+ correspondingEl.setAttribute('id', normalizeID(corresponding.attrs.id));
1153
+ if (corresponding.attrs.label) {
1266
1154
  const labelEl = this.document.createElement('label');
1267
- labelEl.textContent = corresponding.label;
1155
+ labelEl.textContent = corresponding.attrs.label;
1268
1156
  correspondingEl.appendChild(labelEl);
1269
1157
  }
1270
- correspondingEl.append(corresponding.contents);
1158
+ correspondingEl.append(corresponding.textContent);
1271
1159
  element.appendChild(correspondingEl);
1272
1160
  };
1273
1161
  this.appendParagraphToElement = (paragraph, element) => {
1274
- const parsedDoc = new DOMParser().parseFromString(paragraph.contents, 'text/html');
1162
+ const parsedDoc = new DOMParser().parseFromString(paragraph.textContent, 'text/html');
1275
1163
  const parsedParagraph = parsedDoc.body.querySelector('p');
1276
1164
  if (parsedParagraph) {
1277
1165
  const paragraphEl = this.document.createElement('p');
1278
1166
  paragraphEl.innerHTML = parsedParagraph.innerHTML;
1279
- paragraphEl.setAttribute('id', normalizeID(paragraph._id));
1167
+ paragraphEl.setAttribute('id', normalizeID(paragraph.attrs.id));
1280
1168
  element.appendChild(paragraphEl);
1281
1169
  }
1282
1170
  };
1283
1171
  this.appendFootnoteToElement = (footnote, element) => {
1284
1172
  const footnoteEl = this.document.createElement('fn');
1285
- footnoteEl.setAttribute('id', normalizeID(footnote._id));
1286
- footnoteEl.innerHTML = footnote.contents;
1173
+ footnoteEl.setAttribute('id', normalizeID(footnote.attrs.id));
1174
+ if (!footnote.textContent.includes('<p>')) {
1175
+ const p = this.document.createElement('p');
1176
+ p.innerHTML = footnote.textContent;
1177
+ footnoteEl.appendChild(p);
1178
+ }
1179
+ else {
1180
+ footnoteEl.innerHTML = footnote.textContent;
1181
+ }
1287
1182
  element.appendChild(footnoteEl);
1288
1183
  };
1289
- this.fixBody = (body, fragment) => {
1290
- fragment.descendants((node) => {
1184
+ this.fixBody = (body) => {
1185
+ this.manuscriptNode.descendants((node) => {
1291
1186
  if (node.attrs.id) {
1292
1187
  if (node.attrs.titleSuppressed) {
1293
1188
  const title = body.querySelector(`#${normalizeID(node.attrs.id)} > title`);
@@ -1305,7 +1200,7 @@ class JATSExporter {
1305
1200
  label.remove();
1306
1201
  }
1307
1202
  }
1308
- if ((0, node_types_1.isNodeType)(node, 'general_table_footnote')) {
1203
+ if ((0, transformer_1.isNodeType)(node, 'general_table_footnote')) {
1309
1204
  const generalTableFootnote = body.querySelector(`#${normalizeID(node.attrs.id)}`);
1310
1205
  if (generalTableFootnote) {
1311
1206
  Array.from(generalTableFootnote.childNodes).forEach((cn) => {
@@ -1314,7 +1209,7 @@ class JATSExporter {
1314
1209
  generalTableFootnote.remove();
1315
1210
  }
1316
1211
  }
1317
- if ((0, node_types_1.isNodeType)(node, 'table_element')) {
1212
+ if ((0, transformer_1.isNodeType)(node, 'table_element')) {
1318
1213
  const tableElement = body.querySelector(`#${normalizeID(node.attrs.id)}`);
1319
1214
  if (tableElement) {
1320
1215
  for (const childNode of tableElement.childNodes) {
@@ -1548,36 +1443,36 @@ class JATSExporter {
1548
1443
  };
1549
1444
  this.buildContributorName = (contributor) => {
1550
1445
  const name = this.document.createElement('name');
1551
- if (contributor.bibliographicName.family) {
1446
+ if (contributor.attrs.bibliographicName.family) {
1552
1447
  const surname = this.document.createElement('surname');
1553
- surname.textContent = contributor.bibliographicName.family;
1448
+ surname.textContent = contributor.attrs.bibliographicName.family;
1554
1449
  name.appendChild(surname);
1555
1450
  }
1556
- if (contributor.bibliographicName.given) {
1451
+ if (contributor.attrs.bibliographicName.given) {
1557
1452
  const givenNames = this.document.createElement('given-names');
1558
- givenNames.textContent = contributor.bibliographicName.given;
1453
+ givenNames.textContent = contributor.attrs.bibliographicName.given;
1559
1454
  name.appendChild(givenNames);
1560
1455
  }
1561
1456
  return name;
1562
1457
  };
1563
1458
  }
1564
- generateCitations(fragment) {
1459
+ generateCitations() {
1565
1460
  const nodes = [];
1566
- fragment.descendants((node) => {
1461
+ this.manuscriptNode.descendants((node) => {
1567
1462
  if ((0, schema_1.isCitationNode)(node)) {
1568
1463
  nodes.push(node);
1569
1464
  }
1570
1465
  });
1571
1466
  return (0, exports.buildCitations)(nodes);
1572
1467
  }
1573
- generateCitationTexts(fragment, csl) {
1468
+ generateCitationTexts(csl, manuscriptID) {
1574
1469
  this.citationTexts = new Map();
1575
1470
  this.citationProvider = new library_1.CitationProvider({
1576
- getLibraryItem: (id) => this.modelMap.get(id),
1471
+ getLibraryItem: this.getLibraryItem(manuscriptID),
1577
1472
  locale: csl.locale,
1578
1473
  citationStyle: csl.style,
1579
1474
  });
1580
- const citations = this.generateCitations(fragment);
1475
+ const citations = this.generateCitations();
1581
1476
  this.citationProvider.rebuildState(citations).forEach(([id, , output]) => {
1582
1477
  this.citationTexts.set(id, output);
1583
1478
  });
@@ -1604,72 +1499,50 @@ class JATSExporter {
1604
1499
  return mathml;
1605
1500
  }
1606
1501
  }
1607
- appendModelsToAuthorNotes(authorNotesEl, containedObjectIDs) {
1608
- const contributors = this.models.filter(isContributor);
1609
- const usedCorrespondings = this.getUsedCorrespondings(contributors);
1610
- containedObjectIDs.forEach((id) => {
1611
- const model = this.modelMap.get(id);
1612
- if (!model) {
1613
- return;
1614
- }
1615
- switch (model.objectType) {
1616
- case json_schema_1.ObjectTypes.ParagraphElement:
1617
- this.appendParagraphToElement(model, authorNotesEl);
1502
+ appendModelsToAuthorNotes(authorNotesEl, authorNotesNode) {
1503
+ const contributorsNodes = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.contributor).map((result) => result.node);
1504
+ const usedCorrespondings = this.getUsedCorrespondings(contributorsNodes);
1505
+ authorNotesNode.descendants((node) => {
1506
+ switch (node.type) {
1507
+ case schema_1.schema.nodes.paragraph:
1508
+ this.appendParagraphToElement(node, authorNotesEl);
1618
1509
  break;
1619
- case json_schema_1.ObjectTypes.Footnote:
1620
- this.appendFootnoteToElement(model, authorNotesEl);
1510
+ case schema_1.schema.nodes.footnote:
1511
+ this.appendFootnoteToElement(node, authorNotesEl);
1621
1512
  break;
1622
- case json_schema_1.ObjectTypes.Corresponding:
1623
- if (usedCorrespondings.includes(model)) {
1624
- this.appendCorrespondingToElement(model, authorNotesEl);
1513
+ case schema_1.schema.nodes.corresp:
1514
+ if (usedCorrespondings.includes(node)) {
1515
+ this.appendCorrespondingToElement(node, authorNotesEl);
1625
1516
  }
1626
1517
  break;
1627
1518
  }
1519
+ return false;
1628
1520
  });
1629
1521
  }
1630
1522
  getUsedCorrespondings(contributors) {
1631
1523
  return contributors
1632
- .flatMap((c) => { var _a; return (_a = c.corresp) !== null && _a !== void 0 ? _a : []; })
1633
- .map((corresp) => this.modelMap.get(corresp.correspID))
1524
+ .flatMap((c) => { var _a; return (_a = c.attrs.corresp) !== null && _a !== void 0 ? _a : []; })
1525
+ .map((corresp) => {
1526
+ var _a;
1527
+ return (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attr) => attr.id === corresp.correspID)[0]) === null || _a === void 0 ? void 0 : _a.node;
1528
+ })
1634
1529
  .filter((corresp) => !!corresp);
1635
1530
  }
1636
1531
  buildKeywords(articleMeta) {
1637
- const keywords = [...this.modelMap.values()].filter((model) => model.objectType === json_schema_1.ObjectTypes.Keyword);
1638
- const keywordGroups = new Map();
1639
- keywords.forEach((keyword) => {
1640
- const containedGroup = keyword.containedGroup || '';
1641
- const group = keywordGroups.get(containedGroup);
1642
- if (group) {
1643
- group.push(keyword);
1644
- }
1645
- else {
1646
- keywordGroups.set(containedGroup, [keyword]);
1647
- }
1648
- });
1649
- for (const [groupID, keywords] of keywordGroups) {
1650
- const keywordGroup = (this.modelMap.get(groupID) || {});
1532
+ const keywordGroups = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.keyword_group).map((result) => result.node);
1533
+ keywordGroups.forEach((group) => {
1651
1534
  const kwdGroup = this.document.createElement('kwd-group');
1652
- if (keywordGroup.type) {
1653
- kwdGroup.setAttribute('kwd-group-type', keywordGroup.type);
1654
- }
1655
- if (keywordGroup.label) {
1656
- const label = this.document.createElement('label');
1657
- label.textContent = keywordGroup.label;
1658
- kwdGroup.appendChild(label);
1659
- }
1660
- if (keywordGroup.title) {
1661
- const title = this.document.createElement('title');
1662
- title.textContent = keywordGroup.title;
1663
- kwdGroup.appendChild(title);
1535
+ if (group.attrs.type) {
1536
+ kwdGroup.setAttribute('kwd-group-type', group.attrs.type);
1664
1537
  }
1665
1538
  articleMeta.appendChild(kwdGroup);
1666
- for (const keyword of keywords) {
1539
+ group.content.forEach((keyword) => {
1667
1540
  const kwd = this.document.createElement('kwd');
1668
- kwd.textContent = keyword.name;
1541
+ kwd.textContent = keyword.textContent;
1669
1542
  kwdGroup.appendChild(kwd);
1670
- }
1543
+ });
1671
1544
  articleMeta.appendChild(kwdGroup);
1672
- }
1545
+ });
1673
1546
  }
1674
1547
  moveCoiStatementToAuthorNotes(back, front) {
1675
1548
  const fnGroups = back.querySelectorAll('fn-group');
@@ -1717,7 +1590,7 @@ class JATSExporter {
1717
1590
  footnotes.forEach((fn) => {
1718
1591
  const fnType = fn.getAttribute('fn-type');
1719
1592
  if (fnType) {
1720
- fn.setAttribute('fn-type', (0, section_category_1.chooseJatsFnType)(fnType));
1593
+ fn.setAttribute('fn-type', (0, transformer_1.chooseJatsFnType)(fnType));
1721
1594
  }
1722
1595
  });
1723
1596
  }