@manuscripts/transform 2.3.34-LEAN-3911.2 → 2.3.35

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