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