@manuscripts/transform 2.3.38-LEAN-3911.0 → 2.4.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/__tests__/data/project-dump.json +825 -0
  2. package/dist/cjs/index.js +6 -6
  3. package/dist/cjs/jats/importer/index.js +22 -0
  4. package/dist/cjs/jats/importer/{jats-dom-parser.js → jats-body-dom-parser.js} +34 -273
  5. package/dist/cjs/jats/importer/jats-body-transformations.js +22 -74
  6. package/dist/cjs/jats/importer/jats-comments.js +104 -27
  7. package/dist/cjs/jats/importer/jats-front-parser.js +321 -0
  8. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +1 -8
  9. package/dist/cjs/jats/importer/jats-parser-utils.js +5 -43
  10. package/dist/cjs/jats/importer/jats-reference-parser.js +23 -16
  11. package/dist/cjs/jats/importer/jats-references.js +18 -18
  12. package/dist/cjs/jats/importer/parse-jats-article.js +79 -40
  13. package/dist/cjs/jats/index.js +7 -7
  14. package/dist/cjs/jats/{exporter/jats-exporter.js → jats-exporter.js} +398 -264
  15. package/dist/cjs/jats/{exporter/jats-versions.js → jats-versions.js} +3 -1
  16. package/dist/cjs/lib/utils.js +1 -12
  17. package/dist/cjs/transformer/__tests__/__helpers__/doc.js +37 -0
  18. package/dist/cjs/transformer/builders.js +219 -0
  19. package/dist/cjs/transformer/decode.js +898 -0
  20. package/dist/cjs/transformer/document-object-types.js +31 -0
  21. package/dist/cjs/transformer/encode.js +674 -0
  22. package/dist/cjs/{jats/importer/create-article-node.js → transformer/filename.js} +9 -10
  23. package/dist/cjs/transformer/footnote-category.js +20 -0
  24. package/dist/cjs/transformer/footnotes-order.js +60 -0
  25. package/dist/cjs/transformer/highlight-markers.js +138 -0
  26. package/dist/cjs/transformer/html.js +400 -0
  27. package/dist/cjs/transformer/id.js +5 -10
  28. package/dist/cjs/transformer/index.js +18 -0
  29. package/dist/cjs/{jats/exporter → transformer}/labels.js +5 -4
  30. package/dist/cjs/transformer/manuscript-dependencies.js +21 -0
  31. package/dist/cjs/transformer/model-map.js +26 -0
  32. package/dist/cjs/{lib/deafults.js → transformer/models.js} +1 -3
  33. package/dist/cjs/transformer/node-names.js +1 -0
  34. package/dist/cjs/transformer/object-types.js +57 -0
  35. package/dist/cjs/transformer/project-bundle.js +94 -0
  36. package/dist/cjs/transformer/serializer.js +23 -0
  37. package/dist/cjs/transformer/timestamp.js +20 -0
  38. package/dist/cjs/transformer/update-identifiers.js +93 -0
  39. package/dist/cjs/version.js +1 -1
  40. package/dist/es/__tests__/data/project-dump.json +825 -0
  41. package/dist/es/index.js +5 -5
  42. package/dist/{types/jats/importer/create-article-node.d.ts → es/jats/importer/index.js} +2 -3
  43. package/dist/es/jats/importer/{jats-dom-parser.js → jats-body-dom-parser.js} +35 -274
  44. package/dist/es/jats/importer/jats-body-transformations.js +22 -74
  45. package/dist/es/jats/importer/jats-comments.js +101 -26
  46. package/dist/es/jats/importer/jats-front-parser.js +315 -0
  47. package/dist/es/jats/importer/jats-journal-meta-parser.js +0 -6
  48. package/dist/es/jats/importer/jats-parser-utils.js +6 -44
  49. package/dist/es/jats/importer/jats-reference-parser.js +23 -16
  50. package/dist/es/jats/importer/jats-references.js +18 -18
  51. package/dist/es/jats/importer/parse-jats-article.js +78 -41
  52. package/dist/es/jats/index.js +3 -5
  53. package/dist/es/jats/{exporter/jats-exporter.js → jats-exporter.js} +392 -258
  54. package/dist/es/jats/{exporter/jats-versions.js → jats-versions.js} +1 -0
  55. package/dist/es/lib/utils.js +0 -9
  56. package/dist/es/transformer/__tests__/__helpers__/doc.js +29 -0
  57. package/dist/es/transformer/builders.js +186 -0
  58. package/dist/es/transformer/decode.js +888 -0
  59. package/dist/es/transformer/document-object-types.js +28 -0
  60. package/dist/es/transformer/encode.js +664 -0
  61. package/dist/es/transformer/filename.js +23 -0
  62. package/dist/es/transformer/footnote-category.js +16 -0
  63. package/dist/es/transformer/footnotes-order.js +55 -0
  64. package/dist/es/transformer/highlight-markers.js +132 -0
  65. package/dist/es/transformer/html.js +393 -0
  66. package/dist/es/transformer/id.js +3 -8
  67. package/dist/es/transformer/index.js +16 -0
  68. package/dist/es/{jats/exporter → transformer}/labels.js +5 -4
  69. package/dist/es/transformer/manuscript-dependencies.js +17 -0
  70. package/dist/es/transformer/model-map.js +22 -0
  71. package/dist/es/{lib/deafults.js → transformer/models.js} +2 -2
  72. package/dist/es/transformer/node-names.js +1 -0
  73. package/dist/es/transformer/object-types.js +52 -0
  74. package/dist/es/transformer/project-bundle.js +85 -0
  75. package/dist/es/transformer/serializer.js +17 -0
  76. package/dist/es/transformer/timestamp.js +16 -0
  77. package/dist/es/transformer/update-identifiers.js +87 -0
  78. package/dist/es/version.js +1 -1
  79. package/dist/types/index.d.ts +6 -6
  80. package/dist/types/jats/importer/index.d.ts +16 -0
  81. package/dist/types/jats/importer/{jats-dom-parser.d.ts → jats-body-dom-parser.d.ts} +1 -1
  82. package/dist/types/jats/importer/jats-body-transformations.d.ts +1 -5
  83. package/dist/types/jats/importer/jats-comments.d.ts +10 -4
  84. package/dist/types/jats/importer/jats-front-parser.d.ts +84 -0
  85. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +0 -10
  86. package/dist/types/jats/importer/jats-references.d.ts +8 -19
  87. package/dist/types/jats/importer/parse-jats-article.d.ts +5 -12
  88. package/dist/types/jats/index.d.ts +3 -5
  89. package/dist/types/jats/{exporter/jats-exporter.d.ts → jats-exporter.d.ts} +29 -15
  90. package/dist/types/jats/{exporter/jats-versions.d.ts → jats-versions.d.ts} +1 -0
  91. package/dist/types/lib/utils.d.ts +0 -2
  92. package/dist/types/schema/nodes/bibliography_item.d.ts +3 -3
  93. package/dist/types/schema/nodes/contributor.d.ts +0 -10
  94. package/dist/types/schema/nodes/keyword_group.d.ts +0 -1
  95. package/dist/types/schema/nodes/manuscript.d.ts +7 -8
  96. package/dist/types/schema/nodes/title.d.ts +3 -0
  97. package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +18 -0
  98. package/dist/types/transformer/builders.d.ts +61 -0
  99. package/dist/types/transformer/decode.d.ts +52 -0
  100. package/dist/types/transformer/document-object-types.d.ts +17 -0
  101. package/dist/types/transformer/encode.d.ts +29 -0
  102. package/dist/types/transformer/filename.d.ts +16 -0
  103. package/dist/types/transformer/footnote-category.d.ts +17 -0
  104. package/dist/{es/jats/importer/create-article-node.js → types/transformer/footnotes-order.d.ts} +8 -10
  105. package/dist/types/transformer/highlight-markers.d.ts +31 -0
  106. package/dist/types/transformer/html.d.ts +36 -0
  107. package/dist/types/transformer/id.d.ts +2 -5
  108. package/dist/types/transformer/index.d.ts +16 -0
  109. package/dist/types/{jats/exporter → transformer}/labels.d.ts +2 -2
  110. package/dist/types/transformer/manuscript-dependencies.d.ts +4 -0
  111. package/dist/types/transformer/model-map.d.ts +19 -0
  112. package/dist/types/transformer/models.d.ts +48 -0
  113. package/dist/types/transformer/object-types.d.ts +30 -0
  114. package/dist/types/transformer/project-bundle.d.ts +30 -0
  115. package/dist/types/transformer/serializer.d.ts +19 -0
  116. package/dist/types/{lib/deafults.d.ts → transformer/timestamp.d.ts} +2 -2
  117. package/dist/types/transformer/update-identifiers.d.ts +23 -0
  118. package/dist/types/types.d.ts +2 -0
  119. package/dist/types/version.d.ts +1 -1
  120. package/package.json +1 -2
  121. package/dist/cjs/jats/importer/jats-front-transformations.js +0 -79
  122. package/dist/es/jats/importer/jats-front-transformations.js +0 -76
  123. package/dist/types/jats/importer/jats-front-transformations.d.ts +0 -22
  124. package/dist/types/jats/types.d.ts +0 -1
  125. /package/dist/cjs/{jats/types.js → types.js} +0 -0
  126. /package/dist/es/{jats/types.js → types.js} +0 -0
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2019 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.documentObjectTypes = void 0;
19
+ const json_schema_1 = require("@manuscripts/json-schema");
20
+ exports.documentObjectTypes = [
21
+ json_schema_1.ObjectTypes.BibliographyElement,
22
+ json_schema_1.ObjectTypes.EquationElement,
23
+ json_schema_1.ObjectTypes.FigureElement,
24
+ json_schema_1.ObjectTypes.ListElement,
25
+ json_schema_1.ObjectTypes.ListingElement,
26
+ json_schema_1.ObjectTypes.Manuscript,
27
+ json_schema_1.ObjectTypes.ParagraphElement,
28
+ json_schema_1.ObjectTypes.Section,
29
+ json_schema_1.ObjectTypes.TableElement,
30
+ json_schema_1.ObjectTypes.TOCElement,
31
+ ];
@@ -0,0 +1,674 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2019 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.encode = exports.modelFromNode = exports.inlineText = exports.inlineContents = void 0;
22
+ const prosemirror_model_1 = require("prosemirror-model");
23
+ const w3c_xmlserializer_1 = __importDefault(require("w3c-xmlserializer"));
24
+ const utils_1 = require("../lib/utils");
25
+ const schema_1 = require("../schema");
26
+ const builders_1 = require("./builders");
27
+ const highlight_markers_1 = require("./highlight-markers");
28
+ const node_types_1 = require("./node-types");
29
+ const section_category_1 = require("./section-category");
30
+ const serializer = prosemirror_model_1.DOMSerializer.fromSchema(schema_1.schema);
31
+ const contents = (node) => {
32
+ const output = serializer.serializeNode(node);
33
+ return (0, w3c_xmlserializer_1.default)(output);
34
+ };
35
+ const footnoteContents = (node) => {
36
+ const output = serializer.serializeNode(node);
37
+ output.querySelectorAll('p').forEach((element) => {
38
+ element.removeAttribute('class');
39
+ element.removeAttribute('data-object-type');
40
+ });
41
+ return (0, w3c_xmlserializer_1.default)(output);
42
+ };
43
+ const keywordContents = (node) => {
44
+ const text = serializer.serializeNode(node).textContent;
45
+ return text === null ? '' : text;
46
+ };
47
+ const inlineContents = (node) => serializer.serializeNode(node).innerHTML;
48
+ exports.inlineContents = inlineContents;
49
+ const inlineText = (node) => {
50
+ const text = serializer.serializeNode(node).textContent;
51
+ return text === null ? '' : text;
52
+ };
53
+ exports.inlineText = inlineText;
54
+ const listContents = (node) => {
55
+ const output = serializer.serializeNode(node);
56
+ for (const p of output.querySelectorAll('li > p')) {
57
+ const parent = p.parentNode;
58
+ while (p.firstChild) {
59
+ parent.insertBefore(p.firstChild, p);
60
+ }
61
+ parent.removeChild(p);
62
+ }
63
+ return (0, w3c_xmlserializer_1.default)(output);
64
+ };
65
+ const tableRowDisplayStyle = (tagName, parent) => {
66
+ switch (tagName) {
67
+ case 'thead':
68
+ return parent.attrs.suppressHeader ? 'none' : 'table-header-group';
69
+ case 'tfoot':
70
+ return parent.attrs.suppressFooter ? 'none' : 'table-footer-group';
71
+ default:
72
+ return null;
73
+ }
74
+ };
75
+ const buildTableSection = (tagName, inputRows, parent) => {
76
+ const section = document.createElement(tagName);
77
+ for (const sectionRow of inputRows) {
78
+ const row = section.appendChild(document.createElement('tr'));
79
+ for (const child of sectionRow.children) {
80
+ const cellType = tagName === 'thead' ? 'th' : 'td';
81
+ const cell = row.appendChild(document.createElement(cellType));
82
+ while (child.firstChild) {
83
+ cell.appendChild(child.firstChild);
84
+ }
85
+ for (const attribute of child.attributes) {
86
+ cell.setAttribute(attribute.name, attribute.value);
87
+ }
88
+ }
89
+ }
90
+ const displayStyle = tableRowDisplayStyle(tagName, parent);
91
+ if (displayStyle) {
92
+ section.style.display = displayStyle;
93
+ }
94
+ return section;
95
+ };
96
+ function buildTableColGroup(cols) {
97
+ if (cols.length === 0) {
98
+ return undefined;
99
+ }
100
+ const colgroup = document.createElement('colgroup');
101
+ for (const inputCol of cols) {
102
+ const col = document.createElement('col');
103
+ for (const attribute of inputCol.attributes) {
104
+ col.setAttribute(attribute.name, attribute.value);
105
+ }
106
+ colgroup.appendChild(inputCol);
107
+ }
108
+ return colgroup;
109
+ }
110
+ const tableContents = (node, parent) => {
111
+ const input = serializer.serializeNode(node);
112
+ const parentInput = serializer.serializeNode(parent);
113
+ const output = document.createElement('table');
114
+ const colgroup = buildTableColGroup(Array.from(parentInput.querySelectorAll('col')));
115
+ if (colgroup) {
116
+ output.appendChild(colgroup);
117
+ }
118
+ output.setAttribute('id', parent.attrs.id);
119
+ output.classList.add('MPElement');
120
+ if (parent.attrs.tableStyle) {
121
+ output.classList.add(parent.attrs.tableStyle.replace(/:/g, '_'));
122
+ }
123
+ if (parent.attrs.paragraphStyle) {
124
+ output.classList.add(parent.attrs.paragraphStyle.replace(/:/g, '_'));
125
+ }
126
+ output.setAttribute('data-contained-object-id', node.attrs.id);
127
+ const rows = Array.from(input.querySelectorAll('tr'));
128
+ let headerCount = 0;
129
+ for (const row of rows) {
130
+ const th = row.querySelector('th[scope="col"], th[scope="colgroup"]');
131
+ th && headerCount++;
132
+ }
133
+ const thead = rows.splice(0, headerCount || 1);
134
+ const tfoot = rows.splice(-1, 1);
135
+ output.appendChild(buildTableSection('thead', thead, parent));
136
+ output.appendChild(buildTableSection('tbody', rows, parent));
137
+ output.appendChild(buildTableSection('tfoot', tfoot, parent));
138
+ return (0, w3c_xmlserializer_1.default)(output);
139
+ };
140
+ const elementContents = (node) => {
141
+ const input = serializer.serializeNode(node);
142
+ input.classList.add('MPElement');
143
+ if (node.attrs.paragraphStyle) {
144
+ input.classList.add(node.attrs.paragraphStyle.replace(/:/g, '_'));
145
+ }
146
+ if (node.attrs.id) {
147
+ input.setAttribute('id', node.attrs.id);
148
+ }
149
+ return (0, w3c_xmlserializer_1.default)(input);
150
+ };
151
+ const childElements = (node) => {
152
+ const nodes = [];
153
+ node.forEach((childNode) => {
154
+ if (!(0, schema_1.isSectionNode)(childNode)) {
155
+ nodes.push(childNode);
156
+ }
157
+ });
158
+ return nodes;
159
+ };
160
+ const sectionChildElementIds = (node) => {
161
+ const nodes = [];
162
+ node.forEach((childNode) => {
163
+ if (!(0, schema_1.hasGroup)(childNode.type, 'sections')) {
164
+ nodes.push(childNode);
165
+ }
166
+ });
167
+ return nodes.map((childNode) => childNode.attrs.id).filter((id) => id);
168
+ };
169
+ const attributeOfNodeType = (node, type, attribute) => {
170
+ for (const child of (0, utils_1.iterateChildren)(node)) {
171
+ if (child.type.name === type) {
172
+ return child.attrs[attribute];
173
+ }
174
+ }
175
+ return '';
176
+ };
177
+ const inlineContentsOfNodeType = (node, nodeType) => {
178
+ for (let i = 0; i < node.childCount; i++) {
179
+ const child = node.child(i);
180
+ if (child.type === nodeType) {
181
+ return (0, exports.inlineContents)(child);
182
+ }
183
+ }
184
+ return '';
185
+ };
186
+ const inlineContentOfChildNodeType = (node, parentNodeType, childNodeType, empty = true) => {
187
+ const parentNode = childElements(node).find((node) => node.type === parentNodeType && node);
188
+ const content = parentNode && inlineContentsOfNodeType(parentNode, childNodeType);
189
+ return content && content.length > 1 ? content : empty ? content : undefined;
190
+ };
191
+ const wrappedContentOfChildrenNodeType = (node, parentNodeType, childNodeType) => {
192
+ const parentNode = childElements(node).find((node) => node.type === parentNodeType && node);
193
+ const content = parentNode &&
194
+ childElements(parentNode)
195
+ .filter((node) => node.type === childNodeType && node)
196
+ .map((node) => serializer.serializeNode(node).outerHTML)
197
+ .join('');
198
+ return content;
199
+ };
200
+ const containedFigureIDs = (node) => {
201
+ const figureNodeType = node.type.schema.nodes.figure;
202
+ const missingFigureNodeType = node.type.schema.nodes.missing_figure;
203
+ return containedObjectIDs(node, [figureNodeType, missingFigureNodeType]);
204
+ };
205
+ const containedParagraphIDs = (node) => {
206
+ const paragraphNodeType = node.type.schema.nodes.paragraph;
207
+ return containedObjectIDs(node, [paragraphNodeType]);
208
+ };
209
+ const containedAuthorNotesIDs = (node) => {
210
+ const correspNodeType = node.type.schema.nodes.corresp;
211
+ const footnoteNodetype = node.type.schema.nodes.footnote;
212
+ const paragraphNodeType = node.type.schema.nodes.paragraph;
213
+ return containedObjectIDs(node, [
214
+ correspNodeType,
215
+ footnoteNodetype,
216
+ paragraphNodeType,
217
+ ]);
218
+ };
219
+ const containedBibliographyItemIDs = (node) => {
220
+ const bibliographyItemNodeType = node.type.schema.nodes.bibliography_item;
221
+ return containedObjectIDs(node, [bibliographyItemNodeType]);
222
+ };
223
+ const tableElementFooterContainedIDs = (node) => {
224
+ const containedGeneralTableFootnoteIDs = containedObjectIDs(node, [
225
+ schema_1.schema.nodes.footnotes_element,
226
+ ]);
227
+ for (let i = 0; i < node.childCount; i++) {
228
+ const childNode = node.child(i);
229
+ if (childNode.type === schema_1.schema.nodes.general_table_footnote) {
230
+ containedGeneralTableFootnoteIDs.push(...containedObjectIDs(childNode));
231
+ }
232
+ }
233
+ return containedGeneralTableFootnoteIDs;
234
+ };
235
+ const containedObjectIDs = (node, nodeTypes) => {
236
+ const ids = [];
237
+ for (let i = 0; i < node.childCount; i++) {
238
+ const childNode = node.child(i);
239
+ if (!nodeTypes || nodeTypes.includes(childNode.type)) {
240
+ ids.push(childNode.attrs.id);
241
+ }
242
+ }
243
+ return ids;
244
+ };
245
+ const attribution = (node) => {
246
+ if (node.attrs.attribution) {
247
+ return Object.assign(Object.assign({}, node.attrs.attribution), (0, builders_1.buildAttribution)());
248
+ }
249
+ return undefined;
250
+ };
251
+ const fromJson = (json) => {
252
+ let obj;
253
+ try {
254
+ obj = JSON.parse(json);
255
+ }
256
+ catch (e) {
257
+ }
258
+ return obj;
259
+ };
260
+ function figureElementEncoder(node) {
261
+ var _a;
262
+ return {
263
+ containedObjectIDs: (_a = containedParagraphIDs(node)) === null || _a === void 0 ? void 0 : _a.concat(containedFigureIDs(node)),
264
+ caption: wrappedContentOfChildrenNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
265
+ title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
266
+ label: node.attrs.label,
267
+ elementType: 'figure',
268
+ attribution: attribution(node),
269
+ alternatives: node.attrs.alternatives,
270
+ listingID: attributeOfNodeType(node, 'listing', 'id') || undefined,
271
+ alignment: node.attrs.alignment || undefined,
272
+ sizeFraction: node.attrs.sizeFraction || undefined,
273
+ suppressCaption: Boolean(node.attrs.suppressCaption) || undefined,
274
+ suppressTitle: node.attrs.suppressTitle === undefined ||
275
+ node.attrs.suppressTitle === true
276
+ ? undefined
277
+ : false,
278
+ figureStyle: node.attrs.figureStyle || undefined,
279
+ figureLayout: node.attrs.figureLayout || undefined,
280
+ };
281
+ }
282
+ const encoders = {
283
+ title: (node) => ({
284
+ title: (0, exports.inlineContents)(node),
285
+ subtitle: node.attrs.subtitle,
286
+ runningTitle: node.attrs.runningTitle,
287
+ placeholder: node.attrs.placeholder,
288
+ _id: node.attrs._id,
289
+ }),
290
+ bibliography_element: (node) => ({
291
+ elementType: 'div',
292
+ contents: '',
293
+ containedObjectIDs: containedBibliographyItemIDs(node),
294
+ paragraphStyle: node.attrs.paragraphStyle || undefined,
295
+ }),
296
+ bibliography_item: (node) => {
297
+ const { type, containerTitle, doi, volume, issue, supplement, page, title, literal, } = node.attrs;
298
+ const getObjectAtrr = (obj) => typeof obj === 'string' ? fromJson(obj) : obj;
299
+ const author = getObjectAtrr(node.attrs.author);
300
+ const issued = getObjectAtrr(node.attrs.issued);
301
+ const ref = {
302
+ type,
303
+ };
304
+ if (author) {
305
+ ref.author = author;
306
+ }
307
+ if (issued) {
308
+ ref.issued = issued;
309
+ }
310
+ if (containerTitle) {
311
+ ref['container-title'] = containerTitle;
312
+ }
313
+ if (doi) {
314
+ ref.DOI = doi;
315
+ }
316
+ if (volume) {
317
+ ref.volume = volume;
318
+ }
319
+ if (issue) {
320
+ ref.issue = issue;
321
+ }
322
+ if (supplement) {
323
+ ref.supplement = supplement;
324
+ }
325
+ if (page) {
326
+ ref.page = page;
327
+ }
328
+ if (title) {
329
+ ref.title = title;
330
+ }
331
+ if (literal) {
332
+ ref.literal = literal;
333
+ }
334
+ return ref;
335
+ },
336
+ bibliography_section: (node, parent, path, priority) => ({
337
+ category: (0, section_category_1.buildSectionCategory)(node),
338
+ priority: priority.value++,
339
+ title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
340
+ path: path.concat([node.attrs.id]),
341
+ elementIDs: childElements(node)
342
+ .map((childNode) => childNode.attrs.id)
343
+ .filter((id) => id),
344
+ }),
345
+ blockquote_element: (node) => ({
346
+ contents: contents(node),
347
+ elementType: 'div',
348
+ paragraphStyle: node.attrs.paragraphStyle || undefined,
349
+ placeholderInnerHTML: node.attrs.placeholder || '',
350
+ quoteType: 'block',
351
+ }),
352
+ list: (node) => ({
353
+ elementType: (0, schema_1.getListType)(node.attrs.listStyleType).type,
354
+ contents: listContents(node),
355
+ listStyleType: node.attrs.listStyleType,
356
+ paragraphStyle: node.attrs.paragraphStyle || undefined,
357
+ }),
358
+ listing: (node) => ({
359
+ contents: (0, exports.inlineText)(node),
360
+ language: node.attrs.language || undefined,
361
+ languageKey: node.attrs.languageKey || 'null',
362
+ }),
363
+ listing_element: (node) => ({
364
+ containedObjectID: attributeOfNodeType(node, 'listing', 'id'),
365
+ caption: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
366
+ title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
367
+ elementType: 'figure',
368
+ suppressCaption: node.attrs.suppressCaption === true ? undefined : false,
369
+ suppressTitle: node.attrs.suppressTitle === undefined ||
370
+ node.attrs.suppressTitle === true
371
+ ? undefined
372
+ : false,
373
+ }),
374
+ equation: (node) => ({
375
+ contents: node.attrs.contents,
376
+ format: node.attrs.format,
377
+ }),
378
+ equation_element: (node) => ({
379
+ containedObjectID: attributeOfNodeType(node, 'equation', 'id'),
380
+ elementType: 'div',
381
+ label: node.attrs.label,
382
+ }),
383
+ figure: (node) => ({
384
+ contentType: node.attrs.contentType || undefined,
385
+ src: node.attrs.src || undefined,
386
+ position: node.attrs.position || undefined,
387
+ }),
388
+ figure_element: (node) => figureElementEncoder(node),
389
+ comment: (node) => ({
390
+ selector: node.attrs.selector,
391
+ target: node.attrs.target,
392
+ contents: node.attrs.contents,
393
+ resolved: node.attrs.resolved,
394
+ contributions: node.attrs.contributions,
395
+ originalText: node.attrs.originalText,
396
+ }),
397
+ footnote: (node, parent) => ({
398
+ containingObject: parent.attrs.id,
399
+ contents: footnoteContents(node),
400
+ kind: node.attrs.kind || 'footnote',
401
+ }),
402
+ footnotes_element: (node) => ({
403
+ contents: '<div></div>',
404
+ elementType: 'div',
405
+ paragraphStyle: node.attrs.paragraphStyle || undefined,
406
+ }),
407
+ table_element_footer: (node) => ({
408
+ containedObjectIDs: tableElementFooterContainedIDs(node),
409
+ }),
410
+ author_notes: (node) => ({
411
+ containedObjectIDs: containedAuthorNotesIDs(node),
412
+ }),
413
+ footnotes_section: (node, parent, path, priority) => ({
414
+ category: (0, section_category_1.buildSectionCategory)(node),
415
+ priority: priority.value++,
416
+ title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
417
+ path: path.concat([node.attrs.id]),
418
+ elementIDs: childElements(node)
419
+ .map((childNode) => childNode.attrs.id)
420
+ .filter((id) => id),
421
+ }),
422
+ graphical_abstract_section: (node, parent, path, priority) => ({
423
+ category: (0, section_category_1.buildSectionCategory)(node),
424
+ priority: priority.value++,
425
+ title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
426
+ path: path.concat([node.attrs.id]),
427
+ elementIDs: childElements(node)
428
+ .map((childNode) => childNode.attrs.id)
429
+ .filter((id) => id),
430
+ }),
431
+ keyword: (node, parent) => ({
432
+ containedGroup: parent.attrs.id,
433
+ name: keywordContents(node),
434
+ }),
435
+ keywords_element: (node) => ({
436
+ contents: '<div></div>',
437
+ elementType: 'div',
438
+ paragraphStyle: node.attrs.paragraphStyle || undefined,
439
+ }),
440
+ keyword_group: (node) => ({
441
+ type: node.attrs.type,
442
+ }),
443
+ missing_figure: (node) => ({
444
+ position: node.attrs.position || undefined,
445
+ }),
446
+ paragraph: (node) => ({
447
+ elementType: 'p',
448
+ contents: contents(node),
449
+ paragraphStyle: node.attrs.paragraphStyle || undefined,
450
+ placeholderInnerHTML: node.attrs.placeholder || '',
451
+ }),
452
+ placeholder_element: () => ({
453
+ elementType: 'p',
454
+ }),
455
+ pullquote_element: (node) => ({
456
+ contents: contents(node),
457
+ elementType: 'div',
458
+ paragraphStyle: node.attrs.paragraphStyle || undefined,
459
+ placeholderInnerHTML: node.attrs.placeholder || '',
460
+ quoteType: 'pull',
461
+ }),
462
+ section: (node, parent, path, priority) => ({
463
+ category: (0, section_category_1.buildSectionCategory)(node),
464
+ priority: priority.value++,
465
+ title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
466
+ label: inlineContentsOfNodeType(node, node.type.schema.nodes.section_label) ||
467
+ undefined,
468
+ path: path.concat([node.attrs.id]),
469
+ elementIDs: sectionChildElementIds(node),
470
+ titleSuppressed: node.attrs.titleSuppressed || undefined,
471
+ generatedLabel: node.attrs.generatedLabel || undefined,
472
+ pageBreakStyle: node.attrs.pageBreakStyle || undefined,
473
+ }),
474
+ table: (node, parent) => ({
475
+ contents: tableContents(node, parent),
476
+ listingAttachment: node.attrs.listingAttachment || undefined,
477
+ }),
478
+ table_element: (node) => ({
479
+ containedObjectID: attributeOfNodeType(node, 'table', 'id'),
480
+ tableElementFooterID: attributeOfNodeType(node, 'table_element_footer', 'id') || undefined,
481
+ caption: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
482
+ title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
483
+ elementType: 'table',
484
+ listingID: attributeOfNodeType(node, 'listing', 'id') || undefined,
485
+ paragraphStyle: node.attrs.paragraphStyle || undefined,
486
+ suppressCaption: Boolean(node.attrs.suppressCaption) || undefined,
487
+ suppressTitle: node.attrs.suppressTitle === undefined ||
488
+ node.attrs.suppressTitle === true
489
+ ? undefined
490
+ : false,
491
+ suppressFooter: Boolean(node.attrs.suppressFooter) || undefined,
492
+ suppressHeader: Boolean(node.attrs.suppressHeader) || undefined,
493
+ tableStyle: node.attrs.tableStyle || undefined,
494
+ }),
495
+ toc_element: (node) => ({
496
+ contents: elementContents(node),
497
+ elementType: 'div',
498
+ paragraphStyle: node.attrs.paragraphStyle || undefined,
499
+ }),
500
+ toc_section: (node, parent, path, priority) => ({
501
+ category: (0, section_category_1.buildSectionCategory)(node),
502
+ priority: priority.value++,
503
+ title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
504
+ path: path.concat([node.attrs.id]),
505
+ elementIDs: childElements(node)
506
+ .map((childNode) => childNode.attrs.id)
507
+ .filter((id) => id),
508
+ }),
509
+ affiliation: (node) => ({
510
+ institution: node.attrs.institution,
511
+ addressLine1: node.attrs.addressLine1,
512
+ addressLine2: node.attrs.addressLine2,
513
+ addressLine3: node.attrs.addressLine3,
514
+ department: node.attrs.department,
515
+ postCode: node.attrs.postCode,
516
+ country: node.attrs.country,
517
+ county: node.attrs.county,
518
+ city: node.attrs.city,
519
+ email: node.attrs.email,
520
+ priority: node.attrs.priority,
521
+ }),
522
+ contributor: (node) => ({
523
+ role: node.attrs.role,
524
+ affiliations: node.attrs.affiliations,
525
+ bibliographicName: node.attrs.bibliographicName,
526
+ userID: node.attrs.userID,
527
+ invitationID: node.attrs.invitationID,
528
+ isCorresponding: node.attrs.isCorresponding,
529
+ isJointContributor: node.attrs.isJointContributor,
530
+ ORCIDIdentifier: node.attrs.ORCIDIdentifier,
531
+ footnote: node.attrs.footnote,
532
+ corresp: node.attrs.corresp,
533
+ priority: node.attrs.priority,
534
+ }),
535
+ supplement: (node) => ({
536
+ href: node.attrs.href,
537
+ title: node.attrs.title,
538
+ MIME: node.attrs.mimeType && node.attrs.mimeSubType
539
+ ? [node.attrs.mimeType, node.attrs.mimeSubType].join('/')
540
+ : '',
541
+ }),
542
+ corresp: (node) => ({
543
+ contents: (0, exports.inlineContents)(node),
544
+ label: node.attrs.label,
545
+ }),
546
+ box_element: (node, parent, path, priority) => ({
547
+ label: node.attrs.label,
548
+ priority: priority.value++,
549
+ path: path.concat([node.attrs.id]),
550
+ title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
551
+ elementIDs: childElements(node)
552
+ .map((childNode) => childNode.attrs.id)
553
+ .filter((id) => id),
554
+ category: (0, section_category_1.buildSectionCategory)(node),
555
+ }),
556
+ };
557
+ const modelData = (node, parent, path, priority) => {
558
+ const encoder = encoders[node.type.name];
559
+ if (!encoder) {
560
+ throw new Error(`Unhandled model: ${node.type.name}`);
561
+ }
562
+ return encoder(node, parent, path, priority);
563
+ };
564
+ const modelFromNode = (node, parent, path, priority) => {
565
+ const objectType = node_types_1.nodeTypesMap.get(node.type);
566
+ if (!objectType) {
567
+ throw new Error(`No objectType is defined for ${node.type.name}`);
568
+ }
569
+ const { id } = node.attrs;
570
+ if (!id) {
571
+ throw new Error(`No id is defined for this ${node.type.name}`);
572
+ }
573
+ const data = Object.assign(Object.assign({}, modelData(node, parent, path, priority)), { _id: id, objectType: objectType });
574
+ const model = data;
575
+ const markers = (0, highlight_markers_1.extractCommentMarkers)(model);
576
+ return { model, markers };
577
+ };
578
+ exports.modelFromNode = modelFromNode;
579
+ const containerTypes = [
580
+ schema_1.schema.nodes.affiliations,
581
+ schema_1.schema.nodes.contributors,
582
+ schema_1.schema.nodes.keywords,
583
+ schema_1.schema.nodes.supplements,
584
+ schema_1.schema.nodes.abstracts,
585
+ schema_1.schema.nodes.body,
586
+ schema_1.schema.nodes.backmatter,
587
+ schema_1.schema.nodes.general_table_footnote,
588
+ ];
589
+ const placeholderTypes = [
590
+ schema_1.schema.nodes.placeholder,
591
+ schema_1.schema.nodes.placeholder_element,
592
+ ];
593
+ const encode = (node) => {
594
+ const models = new Map();
595
+ const priority = {
596
+ value: 1,
597
+ };
598
+ const processNode = (path, parent) => (child) => {
599
+ if (containerTypes.includes(child.type)) {
600
+ child.forEach(processNode([], child));
601
+ return;
602
+ }
603
+ if (!child.attrs.id) {
604
+ return;
605
+ }
606
+ if ((0, schema_1.isHighlightMarkerNode)(child)) {
607
+ return;
608
+ }
609
+ if (placeholderTypes.includes(child.type)) {
610
+ return;
611
+ }
612
+ if (parent.type === schema_1.schema.nodes.paragraph) {
613
+ return;
614
+ }
615
+ if (child.type === schema_1.schema.nodes.footnotes_element) {
616
+ addFootnotesOrderModel(child, models);
617
+ }
618
+ const { model, markers } = (0, exports.modelFromNode)(child, parent, path, priority);
619
+ markers.forEach((marker) => {
620
+ const comment = models.get(marker._id);
621
+ if (comment) {
622
+ comment.selector = {
623
+ from: marker.from,
624
+ to: marker.to,
625
+ };
626
+ }
627
+ });
628
+ if (models.has(model._id)) {
629
+ throw Error(`Duplicate ids in encode: ${model._id}`);
630
+ }
631
+ models.set(model._id, model);
632
+ child.forEach(processNode(path.concat(child.attrs.id), child));
633
+ };
634
+ const comments = node.lastChild;
635
+ if (comments && comments.type === schema_1.schema.nodes.comments) {
636
+ comments.forEach(processNode([], comments));
637
+ }
638
+ node.forEach(processNode([], node));
639
+ if ((0, schema_1.isManuscriptNode)(node)) {
640
+ builders_1.auxiliaryObjectTypes.forEach((t) => {
641
+ const order = generateElementOrder(node, t);
642
+ if (order) {
643
+ models.set(order._id, order);
644
+ }
645
+ });
646
+ }
647
+ return models;
648
+ };
649
+ exports.encode = encode;
650
+ const generateElementOrder = (node, nodeType) => {
651
+ const ids = [];
652
+ node.descendants((n) => {
653
+ if (n.type === nodeType) {
654
+ ids.push(n.attrs.id);
655
+ }
656
+ return true;
657
+ });
658
+ if (!ids.length) {
659
+ return undefined;
660
+ }
661
+ const type = node_types_1.nodeTypesMap.get(nodeType);
662
+ if (!type) {
663
+ return undefined;
664
+ }
665
+ const order = (0, builders_1.buildElementsOrder)(type);
666
+ order.elements = ids;
667
+ return order;
668
+ };
669
+ const addFootnotesOrderModel = (child, models) => {
670
+ const footnoteList = [];
671
+ child.forEach((footnote, _, index) => footnoteList.push({ id: footnote.attrs.id, index }));
672
+ const footnotesOrder = (0, builders_1.buildFootnotesOrder)(footnoteList, child.attrs.id);
673
+ models.set(footnotesOrder._id, footnotesOrder);
674
+ };