@manuscripts/transform 2.3.32 → 2.3.34-LEAN-3911.2

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 (115) hide show
  1. package/dist/cjs/jats/importer/create-article-node.js +31 -0
  2. package/dist/cjs/jats/importer/index.js +3 -3
  3. package/dist/cjs/jats/importer/jats-body-transformations.js +70 -0
  4. package/dist/cjs/jats/importer/jats-comments.js +27 -104
  5. package/dist/cjs/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +229 -9
  6. package/dist/cjs/jats/importer/jats-front-transformations.js +262 -0
  7. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +8 -1
  8. package/dist/cjs/jats/importer/jats-parser-utils.js +39 -5
  9. package/dist/cjs/jats/importer/jats-reference-parser.js +16 -27
  10. package/dist/cjs/jats/importer/jats-references.js +18 -18
  11. package/dist/cjs/jats/importer/parse-jats-article.js +42 -78
  12. package/dist/cjs/jats/index.js +4 -3
  13. package/dist/cjs/jats/jats-exporter.js +251 -354
  14. package/dist/cjs/{transformer → jats}/labels.js +3 -3
  15. package/dist/cjs/lib/utils.js +9 -1
  16. package/dist/cjs/schema/nodes/footnotes_section.js +1 -1
  17. package/dist/cjs/transformer/id.js +6 -6
  18. package/dist/cjs/transformer/index.js +0 -18
  19. package/dist/cjs/version.js +1 -1
  20. package/dist/{cjs/transformer/serializer.js → es/jats/importer/create-article-node.js} +12 -8
  21. package/dist/es/jats/importer/index.js +2 -1
  22. package/dist/es/jats/importer/jats-body-transformations.js +70 -0
  23. package/dist/es/jats/importer/jats-comments.js +26 -101
  24. package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +230 -10
  25. package/dist/es/jats/importer/jats-front-transformations.js +259 -0
  26. package/dist/es/jats/importer/jats-journal-meta-parser.js +6 -0
  27. package/dist/es/jats/importer/jats-parser-utils.js +40 -6
  28. package/dist/es/jats/importer/jats-reference-parser.js +16 -27
  29. package/dist/es/jats/importer/jats-references.js +18 -18
  30. package/dist/es/jats/importer/parse-jats-article.js +43 -77
  31. package/dist/es/jats/index.js +3 -1
  32. package/dist/es/jats/jats-exporter.js +253 -356
  33. package/dist/es/{transformer → jats}/labels.js +3 -3
  34. package/dist/es/lib/utils.js +7 -0
  35. package/dist/es/schema/nodes/footnotes_section.js +1 -1
  36. package/dist/es/transformer/id.js +5 -4
  37. package/dist/es/transformer/index.js +0 -16
  38. package/dist/es/version.js +1 -1
  39. package/dist/{cjs/transformer/models.js → types/jats/importer/create-article-node.d.ts} +3 -3
  40. package/dist/types/jats/importer/index.d.ts +2 -1
  41. package/dist/types/jats/importer/jats-body-transformations.d.ts +5 -0
  42. package/dist/types/jats/importer/jats-comments.d.ts +4 -10
  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-front-transformations.d.ts +38 -0
  45. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +10 -0
  46. package/dist/types/jats/importer/jats-references.d.ts +19 -8
  47. package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
  48. package/dist/types/jats/index.d.ts +3 -1
  49. package/dist/types/jats/jats-exporter.d.ts +10 -29
  50. package/dist/types/{transformer → jats}/labels.d.ts +2 -1
  51. package/dist/types/lib/utils.d.ts +3 -0
  52. package/dist/types/schema/nodes/bibliography_item.d.ts +16 -6
  53. package/dist/types/schema/nodes/contributor.d.ts +10 -0
  54. package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
  55. package/dist/types/transformer/id.d.ts +4 -3
  56. package/dist/types/transformer/index.d.ts +0 -16
  57. package/dist/types/version.d.ts +1 -1
  58. package/package.json +3 -2
  59. package/dist/cjs/__tests__/data/project-dump.json +0 -825
  60. package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
  61. package/dist/cjs/transformer/__tests__/__helpers__/doc.js +0 -37
  62. package/dist/cjs/transformer/builders.js +0 -219
  63. package/dist/cjs/transformer/decode.js +0 -874
  64. package/dist/cjs/transformer/document-object-types.js +0 -31
  65. package/dist/cjs/transformer/encode.js +0 -664
  66. package/dist/cjs/transformer/footnote-category.js +0 -20
  67. package/dist/cjs/transformer/footnotes-order.js +0 -60
  68. package/dist/cjs/transformer/highlight-markers.js +0 -138
  69. package/dist/cjs/transformer/html.js +0 -400
  70. package/dist/cjs/transformer/manuscript-dependencies.js +0 -21
  71. package/dist/cjs/transformer/model-map.js +0 -26
  72. package/dist/cjs/transformer/object-types.js +0 -57
  73. package/dist/cjs/transformer/project-bundle.js +0 -94
  74. package/dist/cjs/transformer/update-identifiers.js +0 -93
  75. package/dist/es/__tests__/data/project-dump.json +0 -825
  76. package/dist/es/jats/importer/jats-front-parser.js +0 -315
  77. package/dist/es/transformer/__tests__/__helpers__/doc.js +0 -29
  78. package/dist/es/transformer/builders.js +0 -186
  79. package/dist/es/transformer/decode.js +0 -864
  80. package/dist/es/transformer/document-object-types.js +0 -28
  81. package/dist/es/transformer/encode.js +0 -654
  82. package/dist/es/transformer/footnote-category.js +0 -16
  83. package/dist/es/transformer/footnotes-order.js +0 -55
  84. package/dist/es/transformer/highlight-markers.js +0 -132
  85. package/dist/es/transformer/html.js +0 -393
  86. package/dist/es/transformer/manuscript-dependencies.js +0 -17
  87. package/dist/es/transformer/model-map.js +0 -22
  88. package/dist/es/transformer/models.js +0 -16
  89. package/dist/es/transformer/object-types.js +0 -52
  90. package/dist/es/transformer/project-bundle.js +0 -85
  91. package/dist/es/transformer/serializer.js +0 -17
  92. package/dist/es/transformer/update-identifiers.js +0 -87
  93. package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
  94. package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +0 -18
  95. package/dist/types/transformer/builders.d.ts +0 -61
  96. package/dist/types/transformer/decode.d.ts +0 -51
  97. package/dist/types/transformer/document-object-types.d.ts +0 -17
  98. package/dist/types/transformer/encode.d.ts +0 -29
  99. package/dist/types/transformer/footnote-category.d.ts +0 -17
  100. package/dist/types/transformer/footnotes-order.d.ts +0 -22
  101. package/dist/types/transformer/highlight-markers.d.ts +0 -31
  102. package/dist/types/transformer/html.d.ts +0 -36
  103. package/dist/types/transformer/manuscript-dependencies.d.ts +0 -4
  104. package/dist/types/transformer/model-map.d.ts +0 -19
  105. package/dist/types/transformer/models.d.ts +0 -48
  106. package/dist/types/transformer/object-types.d.ts +0 -30
  107. package/dist/types/transformer/project-bundle.d.ts +0 -30
  108. package/dist/types/transformer/serializer.d.ts +0 -19
  109. package/dist/types/transformer/update-identifiers.d.ts +0 -23
  110. /package/dist/cjs/{transformer → jats}/filename.js +0 -0
  111. /package/dist/cjs/{transformer → jats}/timestamp.js +0 -0
  112. /package/dist/es/{transformer → jats}/filename.js +0 -0
  113. /package/dist/es/{transformer → jats}/timestamp.js +0 -0
  114. /package/dist/types/{transformer → jats}/filename.d.ts +0 -0
  115. /package/dist/types/{transformer → jats}/timestamp.d.ts +0 -0
@@ -1,321 +0,0 @@
1
- "use strict";
2
- /*!
3
- * © 2020 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.jatsFrontParser = void 0;
22
- const debug_1 = __importDefault(require("debug"));
23
- const utils_1 = require("../../lib/utils");
24
- const transformer_1 = require("../../transformer");
25
- const jats_journal_meta_parser_1 = require("./jats-journal-meta-parser");
26
- const jats_parser_utils_1 = require("./jats-parser-utils");
27
- const warn = (0, debug_1.default)('manuscripts-transform');
28
- const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
29
- const defaultTitle = 'Untitled Manuscript';
30
- exports.jatsFrontParser = {
31
- parseTitles(element, createElement) {
32
- var _a;
33
- if (!element) {
34
- return (0, transformer_1.buildTitles)(defaultTitle);
35
- }
36
- const title = element.querySelector('article-title');
37
- const subtitle = element.querySelector('subtitle');
38
- const runningTitle = element.querySelector('alt-title[alt-title-type="right-running"]');
39
- const titles = (0, transformer_1.buildTitles)((_a = (0, jats_parser_utils_1.htmlFromJatsNode)(title, createElement)) !== null && _a !== void 0 ? _a : defaultTitle);
40
- if (subtitle) {
41
- titles.subtitle = (0, jats_parser_utils_1.htmlFromJatsNode)(subtitle, createElement);
42
- }
43
- if (runningTitle) {
44
- titles.runningTitle = (0, jats_parser_utils_1.htmlFromJatsNode)(runningTitle, createElement);
45
- }
46
- return titles;
47
- },
48
- parseDOI(front) {
49
- var _a;
50
- const doi = front === null || front === void 0 ? void 0 : front.querySelector('article-meta > article-id[pub-id-type="doi"]');
51
- return (_a = doi === null || doi === void 0 ? void 0 : doi.textContent) !== null && _a !== void 0 ? _a : undefined;
52
- },
53
- parseCounts(counts) {
54
- var _a, _b, _c, _d, _e;
55
- if (counts) {
56
- const parseCount = (count) => {
57
- if (count && /^-?\d+$/.test(count)) {
58
- return parseInt(count);
59
- }
60
- else if (count) {
61
- warn(`Invalid count number for ${count}`);
62
- }
63
- };
64
- const genericCounts = [];
65
- const countElements = counts.querySelectorAll('count');
66
- for (const element of countElements.values()) {
67
- const countType = element.getAttribute('count-type');
68
- const count = parseCount(element.getAttribute('count'));
69
- if (countType) {
70
- const genericCount = { count, countType };
71
- genericCounts.push(genericCount);
72
- }
73
- }
74
- return {
75
- wordCount: parseCount((_a = counts.querySelector('word-count')) === null || _a === void 0 ? void 0 : _a.getAttribute('count')),
76
- figureCount: parseCount((_b = counts.querySelector('fig-count')) === null || _b === void 0 ? void 0 : _b.getAttribute('count')),
77
- tableCount: parseCount((_c = counts.querySelector('table-count')) === null || _c === void 0 ? void 0 : _c.getAttribute('count')),
78
- equationCount: parseCount((_d = counts.querySelector('equation-count')) === null || _d === void 0 ? void 0 : _d.getAttribute('count')),
79
- referencesCount: parseCount((_e = counts.querySelector('ref-count')) === null || _e === void 0 ? void 0 : _e.getAttribute('count')),
80
- genericCounts: genericCounts.length > 0 ? genericCounts : undefined,
81
- };
82
- }
83
- },
84
- parseJournal(element) {
85
- const meta = (0, jats_journal_meta_parser_1.parseJournalMeta)(element);
86
- return Object.assign(Object.assign({}, meta), (0, transformer_1.buildJournal)());
87
- },
88
- parseDates(historyNode) {
89
- if (!historyNode) {
90
- return undefined;
91
- }
92
- const history = {};
93
- const dateToTimestamp = (dateElement) => {
94
- const selectors = ['year', 'month', 'day'];
95
- const values = [];
96
- for (const selector of selectors) {
97
- const value = (0, utils_1.getTrimmedTextContent)(dateElement, selector);
98
- if (!value || isNaN(+value)) {
99
- return;
100
- }
101
- values.push(+value);
102
- }
103
- return Date.UTC(values[0], values[1], values[2]) / 1000;
104
- };
105
- for (const date of historyNode.children) {
106
- const dateType = date.getAttribute('date-type');
107
- switch (dateType) {
108
- case 'received': {
109
- history.receiveDate = dateToTimestamp(date);
110
- break;
111
- }
112
- case 'rev-recd': {
113
- history.revisionReceiveDate = dateToTimestamp(date);
114
- break;
115
- }
116
- case 'accepted': {
117
- history.acceptanceDate = dateToTimestamp(date);
118
- break;
119
- }
120
- case 'rev-request': {
121
- history.revisionRequestDate = dateToTimestamp(date);
122
- break;
123
- }
124
- case 'retracted': {
125
- history.retractionDate = dateToTimestamp(date);
126
- break;
127
- }
128
- case 'corrected': {
129
- history.correctionDate = dateToTimestamp(date);
130
- break;
131
- }
132
- }
133
- }
134
- return history;
135
- },
136
- parseAffiliations(elements) {
137
- const affiliationIDs = new Map();
138
- const affiliations = elements.map((element, priority) => {
139
- var _a, _b;
140
- const affiliation = (0, transformer_1.buildAffiliation)('', priority);
141
- for (const node of element.querySelectorAll('institution')) {
142
- const content = (_a = node.textContent) === null || _a === void 0 ? void 0 : _a.trim();
143
- if (!content) {
144
- continue;
145
- }
146
- const type = node.getAttribute('content-type');
147
- if (type === 'dept') {
148
- affiliation.department = content;
149
- }
150
- else {
151
- affiliation.institution = content;
152
- }
153
- }
154
- affiliation.addressLine1 =
155
- (0, utils_1.getTrimmedTextContent)(element, 'addr-line:nth-of-type(1)') || undefined;
156
- affiliation.addressLine2 =
157
- (0, utils_1.getTrimmedTextContent)(element, 'addr-line:nth-of-type(2)') || undefined;
158
- affiliation.addressLine3 =
159
- (0, utils_1.getTrimmedTextContent)(element, 'addr-line:nth-of-type(3)') || undefined;
160
- affiliation.postCode =
161
- (0, utils_1.getTrimmedTextContent)(element, 'postal-code') || undefined;
162
- affiliation.country =
163
- (0, utils_1.getTrimmedTextContent)(element, 'country') || undefined;
164
- const email = element.querySelector('email');
165
- if (email) {
166
- affiliation.email = {
167
- href: email.getAttributeNS(XLINK_NAMESPACE, 'href') || undefined,
168
- text: ((_b = email.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
169
- };
170
- }
171
- const id = element.getAttribute('id');
172
- if (id) {
173
- affiliationIDs.set(id, affiliation._id);
174
- }
175
- return affiliation;
176
- });
177
- return {
178
- affiliations,
179
- affiliationIDs,
180
- };
181
- },
182
- parseAuthorNotes(element) {
183
- if (!element) {
184
- return {
185
- footnotes: [],
186
- footnoteIDs: new Map(),
187
- authorNotes: [],
188
- authorNotesParagraphs: [],
189
- correspondingIDs: new Map(),
190
- correspondingList: [],
191
- };
192
- }
193
- const { footnotes, footnoteIDs } = this.parseFootnotes([
194
- ...element.querySelectorAll('fn:not([fn-type])'),
195
- ]);
196
- const authorNotesParagraphs = this.parseParagraphs([
197
- ...element.querySelectorAll(':scope > p'),
198
- ]);
199
- const { correspondingList, correspondingIDs } = this.parseCorresp([
200
- ...element.querySelectorAll('corresp'),
201
- ]);
202
- const authorNotes = [
203
- (0, transformer_1.buildAuthorNotes)([
204
- ...correspondingIDs.values(),
205
- ...footnoteIDs.values(),
206
- ...authorNotesParagraphs.map((p) => p._id),
207
- ]),
208
- ];
209
- return {
210
- footnotes,
211
- footnoteIDs,
212
- authorNotesParagraphs,
213
- authorNotes,
214
- correspondingIDs,
215
- correspondingList,
216
- };
217
- },
218
- parseParagraphs(elements) {
219
- return elements.map((p) => (0, transformer_1.buildParagraph)(p.innerHTML));
220
- },
221
- parseFootnotes(elements) {
222
- const footnoteIDs = new Map();
223
- const footnotes = elements.map((element) => {
224
- const fn = (0, transformer_1.buildFootnote)('', element.innerHTML);
225
- const id = element.getAttribute('id');
226
- if (id) {
227
- footnoteIDs.set(id, fn._id);
228
- }
229
- return fn;
230
- });
231
- return {
232
- footnotes,
233
- footnoteIDs,
234
- };
235
- },
236
- parseCorresp(elements) {
237
- const correspondingIDs = new Map();
238
- const correspondingList = elements.map((element) => {
239
- var _a, _b, _c;
240
- const label = element.querySelector('label');
241
- if (label) {
242
- label.remove();
243
- }
244
- const corresponding = (0, transformer_1.buildCorresp)((_b = (_a = element.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '');
245
- corresponding.label = ((_c = label === null || label === void 0 ? void 0 : label.textContent) === null || _c === void 0 ? void 0 : _c.trim()) || undefined;
246
- const id = element.getAttribute('id');
247
- if (id) {
248
- correspondingIDs.set(id, corresponding._id);
249
- }
250
- return corresponding;
251
- });
252
- return {
253
- correspondingList,
254
- correspondingIDs,
255
- };
256
- },
257
- parseContributors(elements, affiliationIDs, footnoteIDs, correspondingIDs) {
258
- return elements.map((element, priority) => {
259
- var _a, _b;
260
- const name = (0, transformer_1.buildBibliographicName)({});
261
- const given = (0, utils_1.getTrimmedTextContent)(element, 'name > given-names');
262
- if (given) {
263
- name.given = given;
264
- }
265
- const surname = (0, utils_1.getTrimmedTextContent)(element, 'name > surname');
266
- if (surname) {
267
- name.family = surname;
268
- }
269
- const contributor = (0, transformer_1.buildContributor)(name, 'author', priority);
270
- const corresponding = element.getAttribute('corresp') === 'yes';
271
- if (corresponding) {
272
- contributor.isCorresponding = corresponding;
273
- }
274
- const orcid = (0, utils_1.getTrimmedTextContent)(element, 'contrib-id[contrib-id-type="orcid"]');
275
- if (orcid) {
276
- contributor.ORCIDIdentifier = orcid;
277
- }
278
- const xrefs = element.querySelectorAll('xref');
279
- for (const xref of xrefs) {
280
- if (xref) {
281
- const rid = xref.getAttribute('rid');
282
- const type = xref.getAttribute('ref-type');
283
- if (rid) {
284
- if (type === 'fn') {
285
- contributor.footnote = [];
286
- const footnoteID = footnoteIDs.get(rid);
287
- if (footnoteID) {
288
- const authorFootNoteRef = {
289
- noteID: footnoteID,
290
- noteLabel: ((_a = xref.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '',
291
- };
292
- contributor.footnote.push(authorFootNoteRef);
293
- }
294
- }
295
- else if (type === 'corresp') {
296
- contributor.corresp = [];
297
- const correspID = correspondingIDs.get(rid);
298
- if (correspID) {
299
- const authorCorrespRef = {
300
- correspID: correspID,
301
- correspLabel: ((_b = xref.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || '',
302
- };
303
- contributor.corresp.push(authorCorrespRef);
304
- }
305
- }
306
- else if (type === 'aff') {
307
- const rids = rid
308
- .split(/\s+/)
309
- .map((id) => affiliationIDs.get(id))
310
- .filter(Boolean);
311
- if (rids.length) {
312
- contributor.affiliations = rids;
313
- }
314
- }
315
- }
316
- }
317
- }
318
- return contributor;
319
- });
320
- },
321
- };
@@ -1,37 +0,0 @@
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.createTestDoc = exports.createTestModelMap = void 0;
22
- const project_dump_json_1 = __importDefault(require("../../../__tests__/data/project-dump.json"));
23
- const decode_1 = require("../../decode");
24
- const createTestModelMap = () => {
25
- const modelMap = new Map();
26
- for (const component of project_dump_json_1.default.data) {
27
- modelMap.set(component._id, component);
28
- }
29
- return modelMap;
30
- };
31
- exports.createTestModelMap = createTestModelMap;
32
- const createTestDoc = () => {
33
- const modelMap = (0, exports.createTestModelMap)();
34
- const decoder = new decode_1.Decoder(modelMap);
35
- return decoder.createArticleNode();
36
- };
37
- exports.createTestDoc = createTestDoc;
@@ -1,219 +0,0 @@
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.buildTitles = exports.buildElementsOrder = exports.auxiliaryObjectTypes = exports.buildJournal = exports.buildAttribution = exports.buildContributorRole = exports.buildContribution = exports.buildColor = exports.buildParagraph = exports.buildSection = exports.buildCorresp = exports.buildFootnotesOrder = exports.buildAuthorNotes = exports.buildFootnote = exports.buildNote = exports.buildComment = exports.buildSupplementaryMaterial = exports.buildAffiliation = exports.buildFigure = exports.buildKeywordGroup = exports.buildKeyword = exports.buildBibliographyElement = exports.buildBibliographicDate = exports.buildBibliographicName = exports.buildBibliographyItem = exports.buildContributor = exports.buildManuscript = exports.buildProject = void 0;
22
- const json_schema_1 = require("@manuscripts/json-schema");
23
- const w3c_xmlserializer_1 = __importDefault(require("w3c-xmlserializer"));
24
- const schema_1 = require("../schema");
25
- const id_1 = require("./id");
26
- const timestamp_1 = require("./timestamp");
27
- const buildProject = (owner) => ({
28
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.Project),
29
- objectType: json_schema_1.ObjectTypes.Project,
30
- owners: [owner],
31
- writers: [],
32
- viewers: [],
33
- title: '',
34
- });
35
- exports.buildProject = buildProject;
36
- const buildManuscript = () => ({
37
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.Manuscript),
38
- objectType: json_schema_1.ObjectTypes.Manuscript,
39
- });
40
- exports.buildManuscript = buildManuscript;
41
- const buildContributor = (bibliographicName, role = 'author', priority = 0, userID, invitationID) => ({
42
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.Contributor),
43
- objectType: json_schema_1.ObjectTypes.Contributor,
44
- priority,
45
- role,
46
- affiliations: [],
47
- bibliographicName: (0, exports.buildBibliographicName)(bibliographicName),
48
- userID,
49
- invitationID,
50
- });
51
- exports.buildContributor = buildContributor;
52
- const buildBibliographyItem = (data) => (Object.assign(Object.assign({}, data), { type: data.type || 'article-journal', _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.BibliographyItem), objectType: json_schema_1.ObjectTypes.BibliographyItem }));
53
- exports.buildBibliographyItem = buildBibliographyItem;
54
- const buildBibliographicName = (data) => (Object.assign(Object.assign({}, data), { _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.BibliographicName), objectType: json_schema_1.ObjectTypes.BibliographicName }));
55
- exports.buildBibliographicName = buildBibliographicName;
56
- const buildBibliographicDate = (data) => (Object.assign(Object.assign({}, data), { _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.BibliographicDate), objectType: json_schema_1.ObjectTypes.BibliographicDate }));
57
- exports.buildBibliographicDate = buildBibliographicDate;
58
- const buildBibliographyElement = (bibliographyItems) => ({
59
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.BibliographyElement),
60
- objectType: json_schema_1.ObjectTypes.BibliographyElement,
61
- contents: '',
62
- elementType: 'div',
63
- containedObjectIDs: bibliographyItems.map((b) => b._id),
64
- });
65
- exports.buildBibliographyElement = buildBibliographyElement;
66
- const buildKeyword = (name) => ({
67
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.Keyword),
68
- objectType: json_schema_1.ObjectTypes.Keyword,
69
- name,
70
- });
71
- exports.buildKeyword = buildKeyword;
72
- const buildKeywordGroup = (attributes) => (Object.assign(Object.assign(Object.assign({ _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.KeywordGroup), objectType: json_schema_1.ObjectTypes.KeywordGroup }, (attributes.type && { type: attributes.type })), (attributes.title && { title: attributes.title })), (attributes.label && { label: attributes.label })));
73
- exports.buildKeywordGroup = buildKeywordGroup;
74
- const buildFigure = (blob) => ({
75
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.Figure),
76
- objectType: json_schema_1.ObjectTypes.Figure,
77
- contentType: blob.type,
78
- src: window.URL.createObjectURL(blob),
79
- attachment: {
80
- id: 'image',
81
- type: blob.type,
82
- data: blob,
83
- },
84
- });
85
- exports.buildFigure = buildFigure;
86
- const buildAffiliation = (institution, priority = 0) => ({
87
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.Affiliation),
88
- objectType: json_schema_1.ObjectTypes.Affiliation,
89
- institution,
90
- priority,
91
- });
92
- exports.buildAffiliation = buildAffiliation;
93
- const buildSupplementaryMaterial = (title, href) => ({
94
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.Supplement),
95
- objectType: json_schema_1.ObjectTypes.Supplement,
96
- title,
97
- href,
98
- });
99
- exports.buildSupplementaryMaterial = buildSupplementaryMaterial;
100
- const buildComment = (target, contents = '', selector, contributions, annotationColor) => ({
101
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.CommentAnnotation),
102
- objectType: json_schema_1.ObjectTypes.CommentAnnotation,
103
- target,
104
- selector,
105
- contents,
106
- contributions,
107
- annotationColor,
108
- });
109
- exports.buildComment = buildComment;
110
- const buildNote = (target, source, contents = '') => ({
111
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.ManuscriptNote),
112
- objectType: json_schema_1.ObjectTypes.ManuscriptNote,
113
- target,
114
- source,
115
- contents,
116
- });
117
- exports.buildNote = buildNote;
118
- const buildFootnote = (containingObject, contents, kind = 'footnote') => ({
119
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.Footnote),
120
- objectType: json_schema_1.ObjectTypes.Footnote,
121
- containingObject: containingObject || undefined,
122
- contents,
123
- kind,
124
- });
125
- exports.buildFootnote = buildFootnote;
126
- const buildAuthorNotes = (containedObjectIDs) => ({
127
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.AuthorNotes),
128
- objectType: json_schema_1.ObjectTypes.AuthorNotes,
129
- containedObjectIDs: containedObjectIDs,
130
- });
131
- exports.buildAuthorNotes = buildAuthorNotes;
132
- const buildFootnotesOrder = (footnotesList, containedObjectID) => ({
133
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.FootnotesOrder),
134
- objectType: json_schema_1.ObjectTypes.FootnotesOrder,
135
- footnotesList,
136
- containedObjectID,
137
- });
138
- exports.buildFootnotesOrder = buildFootnotesOrder;
139
- const buildCorresp = (contents) => ({
140
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.Corresponding),
141
- objectType: json_schema_1.ObjectTypes.Corresponding,
142
- contents,
143
- });
144
- exports.buildCorresp = buildCorresp;
145
- const buildSection = (priority = 0, path = []) => {
146
- const id = (0, id_1.generateID)(json_schema_1.ObjectTypes.Section);
147
- return {
148
- _id: id,
149
- objectType: json_schema_1.ObjectTypes.Section,
150
- priority,
151
- path: path.concat(id),
152
- };
153
- };
154
- exports.buildSection = buildSection;
155
- const buildParagraph = (innerHTML = '') => {
156
- const _id = (0, id_1.generateID)(json_schema_1.ObjectTypes.ParagraphElement);
157
- const element = document.createElementNS(null, 'p');
158
- element.setAttribute('id', _id);
159
- if (innerHTML) {
160
- element.innerHTML = innerHTML;
161
- }
162
- const contents = (0, w3c_xmlserializer_1.default)(element);
163
- return {
164
- _id,
165
- objectType: json_schema_1.ObjectTypes.ParagraphElement,
166
- elementType: 'p',
167
- contents,
168
- };
169
- };
170
- exports.buildParagraph = buildParagraph;
171
- const buildColor = (value, priority) => ({
172
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.Color),
173
- objectType: json_schema_1.ObjectTypes.Color,
174
- priority,
175
- value,
176
- });
177
- exports.buildColor = buildColor;
178
- const buildContribution = (profileID) => ({
179
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.Contribution),
180
- objectType: json_schema_1.ObjectTypes.Contribution,
181
- profileID,
182
- timestamp: (0, timestamp_1.timestamp)(),
183
- });
184
- exports.buildContribution = buildContribution;
185
- const buildContributorRole = (name) => ({
186
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.ContributorRole),
187
- objectType: json_schema_1.ObjectTypes.ContributorRole,
188
- name,
189
- });
190
- exports.buildContributorRole = buildContributorRole;
191
- const buildAttribution = () => ({
192
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.Attribution),
193
- objectType: json_schema_1.ObjectTypes.Attribution,
194
- });
195
- exports.buildAttribution = buildAttribution;
196
- const buildJournal = () => ({
197
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.Journal),
198
- objectType: json_schema_1.ObjectTypes.Journal,
199
- });
200
- exports.buildJournal = buildJournal;
201
- exports.auxiliaryObjectTypes = new Set([
202
- schema_1.schema.nodes.figure_element,
203
- schema_1.schema.nodes.table_element,
204
- schema_1.schema.nodes.equation_element,
205
- schema_1.schema.nodes.listing_element,
206
- ]);
207
- const buildElementsOrder = (elementType) => ({
208
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.ElementsOrder),
209
- objectType: json_schema_1.ObjectTypes.ElementsOrder,
210
- elementType: elementType,
211
- elements: [],
212
- });
213
- exports.buildElementsOrder = buildElementsOrder;
214
- const buildTitles = (title) => ({
215
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.Titles),
216
- objectType: json_schema_1.ObjectTypes.Titles,
217
- title: title || '',
218
- });
219
- exports.buildTitles = buildTitles;