@manuscripts/transform 1.0.1 → 1.1.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.
- package/dist/cjs/jats/jats-exporter.js +1 -0
- package/dist/cjs/schema/index.js +2 -0
- package/dist/cjs/schema/nodes/comment_list.js +24 -0
- package/dist/cjs/schema/nodes/manuscript.js +1 -1
- package/dist/cjs/transformer/decode.js +42 -12
- package/dist/cjs/transformer/encode.js +11 -10
- package/dist/cjs/transformer/node-types.js +1 -0
- package/dist/es/jats/jats-exporter.js +1 -0
- package/dist/es/schema/index.js +2 -0
- package/dist/es/schema/nodes/comment_list.js +21 -0
- package/dist/es/schema/nodes/manuscript.js +1 -1
- package/dist/es/transformer/decode.js +42 -12
- package/dist/es/transformer/encode.js +12 -11
- package/dist/es/transformer/node-types.js +1 -0
- package/dist/types/schema/nodes/comment_list.d.ts +25 -0
- package/dist/types/schema/types.d.ts +1 -1
- package/dist/types/transformer/decode.d.ts +1 -0
- package/package.json +2 -2
package/dist/cjs/schema/index.js
CHANGED
|
@@ -41,6 +41,7 @@ const caption_1 = require("./nodes/caption");
|
|
|
41
41
|
const caption_title_1 = require("./nodes/caption_title");
|
|
42
42
|
const citation_1 = require("./nodes/citation");
|
|
43
43
|
const comment_1 = require("./nodes/comment");
|
|
44
|
+
const comment_list_1 = require("./nodes/comment_list");
|
|
44
45
|
const cross_reference_1 = require("./nodes/cross_reference");
|
|
45
46
|
const doc_1 = require("./nodes/doc");
|
|
46
47
|
const equation_1 = require("./nodes/equation");
|
|
@@ -141,6 +142,7 @@ exports.schema = new prosemirror_model_1.Schema({
|
|
|
141
142
|
},
|
|
142
143
|
nodes: {
|
|
143
144
|
comment: comment_1.comment,
|
|
145
|
+
comment_list: comment_list_1.commentList,
|
|
144
146
|
attribution: attribution_1.attribution,
|
|
145
147
|
bibliography_item: bibliography_item_1.bibliographyItem,
|
|
146
148
|
bibliography_element: bibliography_element_1.bibliographyElement,
|
|
@@ -0,0 +1,24 @@
|
|
|
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.commentList = void 0;
|
|
19
|
+
exports.commentList = {
|
|
20
|
+
content: 'comment*',
|
|
21
|
+
attrs: {
|
|
22
|
+
id: { default: '' },
|
|
23
|
+
},
|
|
24
|
+
};
|
|
@@ -98,6 +98,7 @@ class Decoder {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
constructor(modelMap, allowMissingElements = false) {
|
|
101
|
+
this.comments = new Map();
|
|
101
102
|
this.creators = {
|
|
102
103
|
[json_schema_1.ObjectTypes.BibliographyElement]: (data) => {
|
|
103
104
|
var _a;
|
|
@@ -144,12 +145,14 @@ class Decoder {
|
|
|
144
145
|
},
|
|
145
146
|
[json_schema_1.ObjectTypes.Figure]: (data) => {
|
|
146
147
|
const model = data;
|
|
148
|
+
const commentNodes = this.createCommentsNode(model);
|
|
149
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
147
150
|
return schema_1.schema.nodes.figure.create({
|
|
148
151
|
id: model._id,
|
|
149
152
|
contentType: model.contentType,
|
|
150
153
|
src: model.src,
|
|
151
154
|
position: model.position,
|
|
152
|
-
comments:
|
|
155
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
153
156
|
});
|
|
154
157
|
},
|
|
155
158
|
[json_schema_1.ObjectTypes.FigureElement]: (data) => {
|
|
@@ -178,6 +181,8 @@ class Decoder {
|
|
|
178
181
|
figures.push(schema_1.schema.nodes.figure.createAndFill());
|
|
179
182
|
}
|
|
180
183
|
const figcaption = this.getFigcaption(model);
|
|
184
|
+
const commentNodes = this.createCommentsNode(model);
|
|
185
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
181
186
|
const content = [...paragraphs, ...figures, figcaption];
|
|
182
187
|
const listing = this.extractListing(model);
|
|
183
188
|
if (listing) {
|
|
@@ -198,7 +203,7 @@ class Decoder {
|
|
|
198
203
|
suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
|
|
199
204
|
attribution: model.attribution,
|
|
200
205
|
alternatives: model.alternatives,
|
|
201
|
-
comments:
|
|
206
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
202
207
|
}, content);
|
|
203
208
|
},
|
|
204
209
|
[json_schema_1.ObjectTypes.Equation]: (data) => {
|
|
@@ -239,11 +244,13 @@ class Decoder {
|
|
|
239
244
|
const footnotesOfKind = [];
|
|
240
245
|
for (const model of this.modelMap.values()) {
|
|
241
246
|
if (isFootnote(model) && model.kind === collateByKind) {
|
|
247
|
+
const commentNodes = this.createCommentsNode(model);
|
|
248
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
242
249
|
const footnote = this.parseContents(model.contents || '<div></div>', undefined, this.getComments(model), {
|
|
243
250
|
topNode: schema_1.schema.nodes.footnote.create({
|
|
244
251
|
id: model._id,
|
|
245
252
|
kind: model.kind,
|
|
246
|
-
comments:
|
|
253
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
247
254
|
}),
|
|
248
255
|
});
|
|
249
256
|
footnotesOfKind.push(footnote);
|
|
@@ -257,10 +264,12 @@ class Decoder {
|
|
|
257
264
|
},
|
|
258
265
|
[json_schema_1.ObjectTypes.Footnote]: (data) => {
|
|
259
266
|
const model = data;
|
|
267
|
+
const commentNodes = this.createCommentsNode(model);
|
|
268
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
260
269
|
return schema_1.schema.nodes.footnote.create({
|
|
261
270
|
id: model._id,
|
|
262
271
|
kind: model.kind,
|
|
263
|
-
comments:
|
|
272
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
264
273
|
});
|
|
265
274
|
},
|
|
266
275
|
[json_schema_1.ObjectTypes.KeywordsElement]: (data) => {
|
|
@@ -275,13 +284,15 @@ class Decoder {
|
|
|
275
284
|
},
|
|
276
285
|
[json_schema_1.ObjectTypes.ListElement]: (data) => {
|
|
277
286
|
const model = data;
|
|
287
|
+
const commentNodes = this.createCommentsNode(model);
|
|
288
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
278
289
|
switch (model.elementType) {
|
|
279
290
|
case 'ol':
|
|
280
291
|
return this.parseContents(model.contents || '<ol></ol>', undefined, this.getComments(model), {
|
|
281
292
|
topNode: schema_1.schema.nodes.ordered_list.create({
|
|
282
293
|
id: model._id,
|
|
283
294
|
paragraphStyle: model.paragraphStyle,
|
|
284
|
-
comments:
|
|
295
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
285
296
|
}),
|
|
286
297
|
});
|
|
287
298
|
case 'ul':
|
|
@@ -297,12 +308,14 @@ class Decoder {
|
|
|
297
308
|
},
|
|
298
309
|
[json_schema_1.ObjectTypes.Listing]: (data) => {
|
|
299
310
|
const model = data;
|
|
311
|
+
const commentNodes = this.createCommentsNode(model);
|
|
312
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
300
313
|
return schema_1.schema.nodes.listing.createChecked({
|
|
301
314
|
id: model._id,
|
|
302
315
|
contents: model.contents,
|
|
303
316
|
language: model.language,
|
|
304
317
|
languageKey: model.languageKey,
|
|
305
|
-
comments:
|
|
318
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
306
319
|
});
|
|
307
320
|
},
|
|
308
321
|
[json_schema_1.ObjectTypes.ListingElement]: (data) => {
|
|
@@ -322,11 +335,13 @@ class Decoder {
|
|
|
322
335
|
throw new errors_1.MissingElement(model.containedObjectID);
|
|
323
336
|
}
|
|
324
337
|
const figcaption = this.getFigcaption(model);
|
|
338
|
+
const commentNodes = this.createCommentsNode(model);
|
|
339
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
325
340
|
return schema_1.schema.nodes.listing_element.createChecked({
|
|
326
341
|
id: model._id,
|
|
327
342
|
suppressCaption: model.suppressCaption,
|
|
328
343
|
suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
|
|
329
|
-
comments:
|
|
344
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
330
345
|
}, [listing, figcaption]);
|
|
331
346
|
},
|
|
332
347
|
[json_schema_1.ObjectTypes.MissingFigure]: (data) => {
|
|
@@ -338,12 +353,14 @@ class Decoder {
|
|
|
338
353
|
},
|
|
339
354
|
[json_schema_1.ObjectTypes.ParagraphElement]: (data) => {
|
|
340
355
|
const model = data;
|
|
356
|
+
const commentNodes = this.createCommentsNode(model);
|
|
357
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
341
358
|
return this.parseContents(model.contents || '<p></p>', undefined, this.getComments(model), {
|
|
342
359
|
topNode: schema_1.schema.nodes.paragraph.create({
|
|
343
360
|
id: model._id,
|
|
344
361
|
paragraphStyle: model.paragraphStyle,
|
|
345
362
|
placeholder: model.placeholderInnerHTML,
|
|
346
|
-
comments:
|
|
363
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
347
364
|
}),
|
|
348
365
|
});
|
|
349
366
|
},
|
|
@@ -418,6 +435,8 @@ class Decoder {
|
|
|
418
435
|
.map(this.creators[json_schema_1.ObjectTypes.Section]);
|
|
419
436
|
const sectionCategory = model.category || (0, section_category_1.guessSectionCategory)(elements);
|
|
420
437
|
const sectionNodeType = (0, section_category_1.chooseSectionNodeType)(sectionCategory);
|
|
438
|
+
const commentNodes = this.createCommentsNode(model);
|
|
439
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
421
440
|
const content = (sectionLabelNode
|
|
422
441
|
? [sectionLabelNode, sectionTitleNode]
|
|
423
442
|
: [sectionTitleNode])
|
|
@@ -429,7 +448,7 @@ class Decoder {
|
|
|
429
448
|
titleSuppressed: model.titleSuppressed,
|
|
430
449
|
pageBreakStyle: model.pageBreakStyle,
|
|
431
450
|
generatedLabel: model.generatedLabel,
|
|
432
|
-
comments:
|
|
451
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
433
452
|
}, content);
|
|
434
453
|
if (!sectionNode) {
|
|
435
454
|
console.error(model);
|
|
@@ -439,10 +458,12 @@ class Decoder {
|
|
|
439
458
|
},
|
|
440
459
|
[json_schema_1.ObjectTypes.Table]: (data) => {
|
|
441
460
|
const model = data;
|
|
461
|
+
const commentNodes = this.createCommentsNode(model);
|
|
462
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
442
463
|
return this.parseContents(model.contents, undefined, this.getComments(model), {
|
|
443
464
|
topNode: schema_1.schema.nodes.table.create({
|
|
444
465
|
id: model._id,
|
|
445
|
-
comments:
|
|
466
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
446
467
|
}),
|
|
447
468
|
});
|
|
448
469
|
},
|
|
@@ -463,6 +484,8 @@ class Decoder {
|
|
|
463
484
|
throw new errors_1.MissingElement(model.containedObjectID);
|
|
464
485
|
}
|
|
465
486
|
const figcaption = this.getFigcaption(model);
|
|
487
|
+
const commentNodes = this.createCommentsNode(model);
|
|
488
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
466
489
|
const content = [table, figcaption];
|
|
467
490
|
if (model.listingID) {
|
|
468
491
|
const listingModel = this.getModel(model.listingID);
|
|
@@ -494,7 +517,7 @@ class Decoder {
|
|
|
494
517
|
suppressHeader: model.suppressHeader,
|
|
495
518
|
tableStyle: model.tableStyle,
|
|
496
519
|
paragraphStyle: model.paragraphStyle,
|
|
497
|
-
comments:
|
|
520
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
498
521
|
}, content);
|
|
499
522
|
},
|
|
500
523
|
[json_schema_1.ObjectTypes.TOCElement]: (data) => {
|
|
@@ -536,9 +559,16 @@ class Decoder {
|
|
|
536
559
|
id: (0, id_1.generateNodeID)(schema_1.schema.nodes.section),
|
|
537
560
|
}));
|
|
538
561
|
}
|
|
562
|
+
const contents = rootSectionNodes;
|
|
563
|
+
if (this.comments.size) {
|
|
564
|
+
const comments = schema_1.schema.nodes.comment_list.createAndFill({
|
|
565
|
+
id: (0, id_1.generateNodeID)(schema_1.schema.nodes.comment_list),
|
|
566
|
+
}, [...this.comments.values()]);
|
|
567
|
+
contents.push(comments);
|
|
568
|
+
}
|
|
539
569
|
return schema_1.schema.nodes.manuscript.create({
|
|
540
570
|
id: manuscriptID || this.getManuscriptID(),
|
|
541
|
-
},
|
|
571
|
+
}, contents);
|
|
542
572
|
};
|
|
543
573
|
this.addGeneratedLabels = (sections) => {
|
|
544
574
|
const nextLableCount = { Appendix: 1 };
|
|
@@ -501,16 +501,6 @@ const modelFromNode = (node, parent, path, priority) => {
|
|
|
501
501
|
const model = data;
|
|
502
502
|
if ((0, highlight_markers_1.isHighlightableModel)(model)) {
|
|
503
503
|
(0, highlight_markers_1.extractHighlightMarkers)(model, commentAnnotationsMap);
|
|
504
|
-
if (node.attrs.comments) {
|
|
505
|
-
const commentNodes = node.attrs.comments;
|
|
506
|
-
commentNodes
|
|
507
|
-
.filter((commentNode) => !commentNode.attrs.selector)
|
|
508
|
-
.forEach((c) => {
|
|
509
|
-
const commentAnnotation = (0, builders_1.buildComment)(model._id, c.attrs.contents, c.attrs.selector);
|
|
510
|
-
commentAnnotation._id = c.attrs.id;
|
|
511
|
-
commentAnnotationsMap.set(commentAnnotation._id, commentAnnotation);
|
|
512
|
-
});
|
|
513
|
-
}
|
|
514
504
|
}
|
|
515
505
|
return { model, commentAnnotationsMap };
|
|
516
506
|
};
|
|
@@ -528,6 +518,9 @@ const encode = (node) => {
|
|
|
528
518
|
if ((0, schema_1.isHighlightMarkerNode)(child)) {
|
|
529
519
|
return;
|
|
530
520
|
}
|
|
521
|
+
if (child.type === schema_1.schema.nodes.comment_list) {
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
531
524
|
if (placeholders.includes(child.type.name)) {
|
|
532
525
|
return;
|
|
533
526
|
}
|
|
@@ -539,6 +532,14 @@ const encode = (node) => {
|
|
|
539
532
|
commentAnnotationsMap.forEach((val, key) => models.set(key, val));
|
|
540
533
|
child.forEach(addModel(path.concat(child.attrs.id), child));
|
|
541
534
|
};
|
|
535
|
+
node.forEach((cNode) => {
|
|
536
|
+
if (cNode.type === schema_1.schema.nodes.comment_list) {
|
|
537
|
+
cNode.forEach((child) => {
|
|
538
|
+
const { model } = (0, exports.modelFromNode)(child, cNode, [], priority);
|
|
539
|
+
models.set(model._id, model);
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
});
|
|
542
543
|
node.forEach(addModel([], node));
|
|
543
544
|
return models;
|
|
544
545
|
};
|
|
@@ -51,6 +51,7 @@ exports.nodeTypesMap = new Map([
|
|
|
51
51
|
[schema_1.schema.nodes.table_element, json_schema_1.ObjectTypes.TableElement],
|
|
52
52
|
[schema_1.schema.nodes.toc_element, json_schema_1.ObjectTypes.TOCElement],
|
|
53
53
|
[schema_1.schema.nodes.toc_section, json_schema_1.ObjectTypes.Section],
|
|
54
|
+
[schema_1.schema.nodes.comment_list, json_schema_1.ObjectTypes.MetaSection],
|
|
54
55
|
]);
|
|
55
56
|
const isExecutableNodeType = (type) => (0, schema_1.hasGroup)(type, schema_1.GROUP_EXECUTABLE);
|
|
56
57
|
exports.isExecutableNodeType = isExecutableNodeType;
|
|
@@ -616,6 +616,7 @@ export class JATSExporter {
|
|
|
616
616
|
attribution: () => ['attrib', 0],
|
|
617
617
|
bibliography_element: () => '',
|
|
618
618
|
bibliography_item: () => '',
|
|
619
|
+
comment_list: () => '',
|
|
619
620
|
bibliography_section: (node) => [
|
|
620
621
|
'ref-list',
|
|
621
622
|
{ id: normalizeID(node.attrs.id) },
|
package/dist/es/schema/index.js
CHANGED
|
@@ -24,6 +24,7 @@ import { caption } from './nodes/caption';
|
|
|
24
24
|
import { captionTitle } from './nodes/caption_title';
|
|
25
25
|
import { citation } from './nodes/citation';
|
|
26
26
|
import { comment } from './nodes/comment';
|
|
27
|
+
import { commentList } from './nodes/comment_list';
|
|
27
28
|
import { crossReference } from './nodes/cross_reference';
|
|
28
29
|
import { doc } from './nodes/doc';
|
|
29
30
|
import { equation } from './nodes/equation';
|
|
@@ -124,6 +125,7 @@ export const schema = new Schema({
|
|
|
124
125
|
},
|
|
125
126
|
nodes: {
|
|
126
127
|
comment,
|
|
128
|
+
comment_list: commentList,
|
|
127
129
|
attribution,
|
|
128
130
|
bibliography_item: bibliographyItem,
|
|
129
131
|
bibliography_element: bibliographyElement,
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
export const commentList = {
|
|
17
|
+
content: 'comment*',
|
|
18
|
+
attrs: {
|
|
19
|
+
id: { default: '' },
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -88,6 +88,7 @@ export class Decoder {
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
constructor(modelMap, allowMissingElements = false) {
|
|
91
|
+
this.comments = new Map();
|
|
91
92
|
this.creators = {
|
|
92
93
|
[ObjectTypes.BibliographyElement]: (data) => {
|
|
93
94
|
var _a;
|
|
@@ -134,12 +135,14 @@ export class Decoder {
|
|
|
134
135
|
},
|
|
135
136
|
[ObjectTypes.Figure]: (data) => {
|
|
136
137
|
const model = data;
|
|
138
|
+
const commentNodes = this.createCommentsNode(model);
|
|
139
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
137
140
|
return schema.nodes.figure.create({
|
|
138
141
|
id: model._id,
|
|
139
142
|
contentType: model.contentType,
|
|
140
143
|
src: model.src,
|
|
141
144
|
position: model.position,
|
|
142
|
-
comments:
|
|
145
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
143
146
|
});
|
|
144
147
|
},
|
|
145
148
|
[ObjectTypes.FigureElement]: (data) => {
|
|
@@ -168,6 +171,8 @@ export class Decoder {
|
|
|
168
171
|
figures.push(schema.nodes.figure.createAndFill());
|
|
169
172
|
}
|
|
170
173
|
const figcaption = this.getFigcaption(model);
|
|
174
|
+
const commentNodes = this.createCommentsNode(model);
|
|
175
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
171
176
|
const content = [...paragraphs, ...figures, figcaption];
|
|
172
177
|
const listing = this.extractListing(model);
|
|
173
178
|
if (listing) {
|
|
@@ -188,7 +193,7 @@ export class Decoder {
|
|
|
188
193
|
suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
|
|
189
194
|
attribution: model.attribution,
|
|
190
195
|
alternatives: model.alternatives,
|
|
191
|
-
comments:
|
|
196
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
192
197
|
}, content);
|
|
193
198
|
},
|
|
194
199
|
[ObjectTypes.Equation]: (data) => {
|
|
@@ -229,11 +234,13 @@ export class Decoder {
|
|
|
229
234
|
const footnotesOfKind = [];
|
|
230
235
|
for (const model of this.modelMap.values()) {
|
|
231
236
|
if (isFootnote(model) && model.kind === collateByKind) {
|
|
237
|
+
const commentNodes = this.createCommentsNode(model);
|
|
238
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
232
239
|
const footnote = this.parseContents(model.contents || '<div></div>', undefined, this.getComments(model), {
|
|
233
240
|
topNode: schema.nodes.footnote.create({
|
|
234
241
|
id: model._id,
|
|
235
242
|
kind: model.kind,
|
|
236
|
-
comments:
|
|
243
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
237
244
|
}),
|
|
238
245
|
});
|
|
239
246
|
footnotesOfKind.push(footnote);
|
|
@@ -247,10 +254,12 @@ export class Decoder {
|
|
|
247
254
|
},
|
|
248
255
|
[ObjectTypes.Footnote]: (data) => {
|
|
249
256
|
const model = data;
|
|
257
|
+
const commentNodes = this.createCommentsNode(model);
|
|
258
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
250
259
|
return schema.nodes.footnote.create({
|
|
251
260
|
id: model._id,
|
|
252
261
|
kind: model.kind,
|
|
253
|
-
comments:
|
|
262
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
254
263
|
});
|
|
255
264
|
},
|
|
256
265
|
[ObjectTypes.KeywordsElement]: (data) => {
|
|
@@ -265,13 +274,15 @@ export class Decoder {
|
|
|
265
274
|
},
|
|
266
275
|
[ObjectTypes.ListElement]: (data) => {
|
|
267
276
|
const model = data;
|
|
277
|
+
const commentNodes = this.createCommentsNode(model);
|
|
278
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
268
279
|
switch (model.elementType) {
|
|
269
280
|
case 'ol':
|
|
270
281
|
return this.parseContents(model.contents || '<ol></ol>', undefined, this.getComments(model), {
|
|
271
282
|
topNode: schema.nodes.ordered_list.create({
|
|
272
283
|
id: model._id,
|
|
273
284
|
paragraphStyle: model.paragraphStyle,
|
|
274
|
-
comments:
|
|
285
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
275
286
|
}),
|
|
276
287
|
});
|
|
277
288
|
case 'ul':
|
|
@@ -287,12 +298,14 @@ export class Decoder {
|
|
|
287
298
|
},
|
|
288
299
|
[ObjectTypes.Listing]: (data) => {
|
|
289
300
|
const model = data;
|
|
301
|
+
const commentNodes = this.createCommentsNode(model);
|
|
302
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
290
303
|
return schema.nodes.listing.createChecked({
|
|
291
304
|
id: model._id,
|
|
292
305
|
contents: model.contents,
|
|
293
306
|
language: model.language,
|
|
294
307
|
languageKey: model.languageKey,
|
|
295
|
-
comments:
|
|
308
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
296
309
|
});
|
|
297
310
|
},
|
|
298
311
|
[ObjectTypes.ListingElement]: (data) => {
|
|
@@ -312,11 +325,13 @@ export class Decoder {
|
|
|
312
325
|
throw new MissingElement(model.containedObjectID);
|
|
313
326
|
}
|
|
314
327
|
const figcaption = this.getFigcaption(model);
|
|
328
|
+
const commentNodes = this.createCommentsNode(model);
|
|
329
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
315
330
|
return schema.nodes.listing_element.createChecked({
|
|
316
331
|
id: model._id,
|
|
317
332
|
suppressCaption: model.suppressCaption,
|
|
318
333
|
suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
|
|
319
|
-
comments:
|
|
334
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
320
335
|
}, [listing, figcaption]);
|
|
321
336
|
},
|
|
322
337
|
[ObjectTypes.MissingFigure]: (data) => {
|
|
@@ -328,12 +343,14 @@ export class Decoder {
|
|
|
328
343
|
},
|
|
329
344
|
[ObjectTypes.ParagraphElement]: (data) => {
|
|
330
345
|
const model = data;
|
|
346
|
+
const commentNodes = this.createCommentsNode(model);
|
|
347
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
331
348
|
return this.parseContents(model.contents || '<p></p>', undefined, this.getComments(model), {
|
|
332
349
|
topNode: schema.nodes.paragraph.create({
|
|
333
350
|
id: model._id,
|
|
334
351
|
paragraphStyle: model.paragraphStyle,
|
|
335
352
|
placeholder: model.placeholderInnerHTML,
|
|
336
|
-
comments:
|
|
353
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
337
354
|
}),
|
|
338
355
|
});
|
|
339
356
|
},
|
|
@@ -408,6 +425,8 @@ export class Decoder {
|
|
|
408
425
|
.map(this.creators[ObjectTypes.Section]);
|
|
409
426
|
const sectionCategory = model.category || guessSectionCategory(elements);
|
|
410
427
|
const sectionNodeType = chooseSectionNodeType(sectionCategory);
|
|
428
|
+
const commentNodes = this.createCommentsNode(model);
|
|
429
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
411
430
|
const content = (sectionLabelNode
|
|
412
431
|
? [sectionLabelNode, sectionTitleNode]
|
|
413
432
|
: [sectionTitleNode])
|
|
@@ -419,7 +438,7 @@ export class Decoder {
|
|
|
419
438
|
titleSuppressed: model.titleSuppressed,
|
|
420
439
|
pageBreakStyle: model.pageBreakStyle,
|
|
421
440
|
generatedLabel: model.generatedLabel,
|
|
422
|
-
comments:
|
|
441
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
423
442
|
}, content);
|
|
424
443
|
if (!sectionNode) {
|
|
425
444
|
console.error(model);
|
|
@@ -429,10 +448,12 @@ export class Decoder {
|
|
|
429
448
|
},
|
|
430
449
|
[ObjectTypes.Table]: (data) => {
|
|
431
450
|
const model = data;
|
|
451
|
+
const commentNodes = this.createCommentsNode(model);
|
|
452
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
432
453
|
return this.parseContents(model.contents, undefined, this.getComments(model), {
|
|
433
454
|
topNode: schema.nodes.table.create({
|
|
434
455
|
id: model._id,
|
|
435
|
-
comments:
|
|
456
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
436
457
|
}),
|
|
437
458
|
});
|
|
438
459
|
},
|
|
@@ -453,6 +474,8 @@ export class Decoder {
|
|
|
453
474
|
throw new MissingElement(model.containedObjectID);
|
|
454
475
|
}
|
|
455
476
|
const figcaption = this.getFigcaption(model);
|
|
477
|
+
const commentNodes = this.createCommentsNode(model);
|
|
478
|
+
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
456
479
|
const content = [table, figcaption];
|
|
457
480
|
if (model.listingID) {
|
|
458
481
|
const listingModel = this.getModel(model.listingID);
|
|
@@ -484,7 +507,7 @@ export class Decoder {
|
|
|
484
507
|
suppressHeader: model.suppressHeader,
|
|
485
508
|
tableStyle: model.tableStyle,
|
|
486
509
|
paragraphStyle: model.paragraphStyle,
|
|
487
|
-
comments:
|
|
510
|
+
comments: commentNodes.map((c) => c.attrs.id),
|
|
488
511
|
}, content);
|
|
489
512
|
},
|
|
490
513
|
[ObjectTypes.TOCElement]: (data) => {
|
|
@@ -526,9 +549,16 @@ export class Decoder {
|
|
|
526
549
|
id: generateNodeID(schema.nodes.section),
|
|
527
550
|
}));
|
|
528
551
|
}
|
|
552
|
+
const contents = rootSectionNodes;
|
|
553
|
+
if (this.comments.size) {
|
|
554
|
+
const comments = schema.nodes.comment_list.createAndFill({
|
|
555
|
+
id: generateNodeID(schema.nodes.comment_list),
|
|
556
|
+
}, [...this.comments.values()]);
|
|
557
|
+
contents.push(comments);
|
|
558
|
+
}
|
|
529
559
|
return schema.nodes.manuscript.create({
|
|
530
560
|
id: manuscriptID || this.getManuscriptID(),
|
|
531
|
-
},
|
|
561
|
+
}, contents);
|
|
532
562
|
};
|
|
533
563
|
this.addGeneratedLabels = (sections) => {
|
|
534
564
|
const nextLableCount = { Appendix: 1 };
|
|
@@ -17,7 +17,7 @@ import { DOMSerializer } from 'prosemirror-model';
|
|
|
17
17
|
import serializeToXML from 'w3c-xmlserializer';
|
|
18
18
|
import { iterateChildren } from '../lib/utils';
|
|
19
19
|
import { isHighlightMarkerNode, isSectionNode, schema, } from '../schema';
|
|
20
|
-
import { buildAttribution
|
|
20
|
+
import { buildAttribution } from './builders';
|
|
21
21
|
import { extractHighlightMarkers, isHighlightableModel, } from './highlight-markers';
|
|
22
22
|
import { nodeTypesMap } from './node-types';
|
|
23
23
|
import { buildSectionCategory } from './section-category';
|
|
@@ -493,16 +493,6 @@ export const modelFromNode = (node, parent, path, priority) => {
|
|
|
493
493
|
const model = data;
|
|
494
494
|
if (isHighlightableModel(model)) {
|
|
495
495
|
extractHighlightMarkers(model, commentAnnotationsMap);
|
|
496
|
-
if (node.attrs.comments) {
|
|
497
|
-
const commentNodes = node.attrs.comments;
|
|
498
|
-
commentNodes
|
|
499
|
-
.filter((commentNode) => !commentNode.attrs.selector)
|
|
500
|
-
.forEach((c) => {
|
|
501
|
-
const commentAnnotation = buildComment(model._id, c.attrs.contents, c.attrs.selector);
|
|
502
|
-
commentAnnotation._id = c.attrs.id;
|
|
503
|
-
commentAnnotationsMap.set(commentAnnotation._id, commentAnnotation);
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
496
|
}
|
|
507
497
|
return { model, commentAnnotationsMap };
|
|
508
498
|
};
|
|
@@ -519,6 +509,9 @@ export const encode = (node) => {
|
|
|
519
509
|
if (isHighlightMarkerNode(child)) {
|
|
520
510
|
return;
|
|
521
511
|
}
|
|
512
|
+
if (child.type === schema.nodes.comment_list) {
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
522
515
|
if (placeholders.includes(child.type.name)) {
|
|
523
516
|
return;
|
|
524
517
|
}
|
|
@@ -530,6 +523,14 @@ export const encode = (node) => {
|
|
|
530
523
|
commentAnnotationsMap.forEach((val, key) => models.set(key, val));
|
|
531
524
|
child.forEach(addModel(path.concat(child.attrs.id), child));
|
|
532
525
|
};
|
|
526
|
+
node.forEach((cNode) => {
|
|
527
|
+
if (cNode.type === schema.nodes.comment_list) {
|
|
528
|
+
cNode.forEach((child) => {
|
|
529
|
+
const { model } = modelFromNode(child, cNode, [], priority);
|
|
530
|
+
models.set(model._id, model);
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
});
|
|
533
534
|
node.forEach(addModel([], node));
|
|
534
535
|
return models;
|
|
535
536
|
};
|
|
@@ -48,6 +48,7 @@ export const nodeTypesMap = new Map([
|
|
|
48
48
|
[schema.nodes.table_element, ObjectTypes.TableElement],
|
|
49
49
|
[schema.nodes.toc_element, ObjectTypes.TOCElement],
|
|
50
50
|
[schema.nodes.toc_section, ObjectTypes.Section],
|
|
51
|
+
[schema.nodes.comment_list, ObjectTypes.MetaSection],
|
|
51
52
|
]);
|
|
52
53
|
export const isExecutableNodeType = (type) => hasGroup(type, GROUP_EXECUTABLE);
|
|
53
54
|
export const isElementNodeType = (type) => hasGroup(type, GROUP_ELEMENT);
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { NodeSpec } from 'prosemirror-model';
|
|
17
|
+
import { ManuscriptNode } from '../types';
|
|
18
|
+
interface Attrs {
|
|
19
|
+
id: string;
|
|
20
|
+
}
|
|
21
|
+
export interface CommentListNode extends ManuscriptNode {
|
|
22
|
+
attrs: Attrs;
|
|
23
|
+
}
|
|
24
|
+
export declare const commentList: NodeSpec;
|
|
25
|
+
export {};
|
|
@@ -17,7 +17,7 @@ import { Fragment, Mark as ProsemirrorMark, MarkType, Node as ProsemirrorNode, N
|
|
|
17
17
|
import { EditorState, NodeSelection, Plugin, TextSelection, Transaction } from 'prosemirror-state';
|
|
18
18
|
import { EditorView, NodeView } from 'prosemirror-view';
|
|
19
19
|
export type Marks = 'bold' | 'code' | 'italic' | 'smallcaps' | 'strikethrough' | 'styled' | 'subscript' | 'superscript' | 'underline' | 'tracked_insert' | 'tracked_delete';
|
|
20
|
-
export type Nodes = 'attribution' | 'bibliography_item' | 'bibliography_element' | 'bibliography_section' | 'blockquote_element' | 'bullet_list' | 'caption' | 'caption_title' | 'comment' | 'citation' | 'cross_reference' | 'doc' | 'equation' | 'equation_element' | 'figcaption' | 'figure' | 'graphical_abstract_section' | 'figure_element' | 'footnote' | 'footnotes_element' | 'footnotes_section' | 'hard_break' | 'highlight_marker' | 'inline_equation' | 'inline_footnote' | 'keywords_element' | 'keywords_section' | 'link' | 'list_item' | 'listing' | 'listing_element' | 'manuscript' | 'missing_figure' | 'ordered_list' | 'paragraph' | 'placeholder' | 'placeholder_element' | 'pullquote_element' | 'section' | 'section_label' | 'section_title' | 'table' | 'table_body' | 'table_cell' | 'table_element' | 'table_row' | 'table_colgroup' | 'table_col' | 'text' | 'toc_element' | 'toc_section';
|
|
20
|
+
export type Nodes = 'attribution' | 'bibliography_item' | 'bibliography_element' | 'bibliography_section' | 'blockquote_element' | 'bullet_list' | 'caption' | 'caption_title' | 'comment' | 'comment_list' | 'citation' | 'cross_reference' | 'doc' | 'equation' | 'equation_element' | 'figcaption' | 'figure' | 'graphical_abstract_section' | 'figure_element' | 'footnote' | 'footnotes_element' | 'footnotes_section' | 'hard_break' | 'highlight_marker' | 'inline_equation' | 'inline_footnote' | 'keywords_element' | 'keywords_section' | 'link' | 'list_item' | 'listing' | 'listing_element' | 'manuscript' | 'missing_figure' | 'ordered_list' | 'paragraph' | 'placeholder' | 'placeholder_element' | 'pullquote_element' | 'section' | 'section_label' | 'section_title' | 'table' | 'table_body' | 'table_cell' | 'table_element' | 'table_row' | 'table_colgroup' | 'table_col' | 'text' | 'toc_element' | 'toc_section';
|
|
21
21
|
export type ManuscriptSchema = Schema<Nodes, Marks>;
|
|
22
22
|
export type ManuscriptEditorState = EditorState;
|
|
23
23
|
export type ManuscriptEditorView = EditorView;
|
|
@@ -23,6 +23,7 @@ export declare const isManuscriptNode: (model: ManuscriptNode | null) => model i
|
|
|
23
23
|
export declare class Decoder {
|
|
24
24
|
private readonly modelMap;
|
|
25
25
|
private readonly allowMissingElements;
|
|
26
|
+
private comments;
|
|
26
27
|
private creators;
|
|
27
28
|
private createCommentsNode;
|
|
28
29
|
private getComments;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manuscripts/transform",
|
|
3
3
|
"description": "ProseMirror transformer for Manuscripts applications",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-transform",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@manuscripts/data": "^0.1.12",
|
|
44
44
|
"@manuscripts/eslint-config": "^0.5.1",
|
|
45
45
|
"@manuscripts/examples": "^0.1.0",
|
|
46
|
-
"@manuscripts/json-schema": "^1.
|
|
46
|
+
"@manuscripts/json-schema": "^1.1.0",
|
|
47
47
|
"@types/debug": "^4.1.7",
|
|
48
48
|
"@types/jest": "^29.2.4",
|
|
49
49
|
"@types/lodash.pickby": "^4.6.7",
|