@manuscripts/transform 1.3.8 → 1.3.9

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 (33) hide show
  1. package/dist/cjs/jats/jats-exporter.js +5 -0
  2. package/dist/cjs/schema/index.js +15 -0
  3. package/dist/cjs/schema/nodes/affiliation.js +23 -0
  4. package/dist/cjs/schema/nodes/affiliation_list.js +10 -0
  5. package/dist/cjs/schema/nodes/contributor.js +15 -0
  6. package/dist/cjs/schema/nodes/contributor_list.js +10 -0
  7. package/dist/cjs/schema/nodes/manuscript.js +1 -1
  8. package/dist/cjs/schema/nodes/meta_section.js +26 -0
  9. package/dist/cjs/transformer/decode.js +71 -15
  10. package/dist/cjs/transformer/encode.js +30 -6
  11. package/dist/cjs/transformer/html.js +1 -1
  12. package/dist/cjs/transformer/node-types.js +3 -1
  13. package/dist/es/jats/jats-exporter.js +5 -0
  14. package/dist/es/schema/index.js +15 -0
  15. package/dist/es/schema/nodes/affiliation.js +19 -0
  16. package/dist/es/schema/nodes/affiliation_list.js +7 -0
  17. package/dist/es/schema/nodes/contributor.js +12 -0
  18. package/dist/es/schema/nodes/contributor_list.js +7 -0
  19. package/dist/es/schema/nodes/manuscript.js +1 -1
  20. package/dist/es/schema/nodes/meta_section.js +23 -0
  21. package/dist/es/transformer/decode.js +71 -15
  22. package/dist/es/transformer/encode.js +30 -6
  23. package/dist/es/transformer/html.js +1 -1
  24. package/dist/es/transformer/node-types.js +3 -1
  25. package/dist/types/schema/index.d.ts +5 -0
  26. package/dist/types/schema/nodes/affiliation.d.ts +23 -0
  27. package/dist/types/schema/nodes/affiliation_list.d.ts +10 -0
  28. package/dist/types/schema/nodes/contributor.d.ts +18 -0
  29. package/dist/types/schema/nodes/contributor_list.d.ts +10 -0
  30. package/dist/types/schema/nodes/meta_section.d.ts +25 -0
  31. package/dist/types/schema/types.d.ts +1 -1
  32. package/dist/types/transformer/decode.d.ts +5 -0
  33. package/package.json +2 -2
@@ -598,6 +598,11 @@ class JATSExporter {
598
598
  this.createSerializer = () => {
599
599
  const getModel = (id) => id ? this.modelMap.get(id) : undefined;
600
600
  const nodes = {
601
+ contributor_list: () => '',
602
+ contributor: () => '',
603
+ affiliation_list: () => '',
604
+ affiliation: () => '',
605
+ meta_section: () => '',
601
606
  attribution: () => ['attrib', 0],
602
607
  bibliography_element: () => '',
603
608
  bibliography_item: () => '',
@@ -32,6 +32,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
32
32
  exports.schema = void 0;
33
33
  const prosemirror_model_1 = require("prosemirror-model");
34
34
  const marks_1 = require("./marks");
35
+ const affiliation_1 = require("./nodes/affiliation");
36
+ const affiliation_list_1 = require("./nodes/affiliation_list");
35
37
  const attribution_1 = require("./nodes/attribution");
36
38
  const bibliography_element_1 = require("./nodes/bibliography_element");
37
39
  const bibliography_item_1 = require("./nodes/bibliography_item");
@@ -42,6 +44,8 @@ const caption_title_1 = require("./nodes/caption_title");
42
44
  const citation_1 = require("./nodes/citation");
43
45
  const comment_1 = require("./nodes/comment");
44
46
  const comment_list_1 = require("./nodes/comment_list");
47
+ const contributor_1 = require("./nodes/contributor");
48
+ const contributor_list_1 = require("./nodes/contributor_list");
45
49
  const cross_reference_1 = require("./nodes/cross_reference");
46
50
  const doc_1 = require("./nodes/doc");
47
51
  const equation_1 = require("./nodes/equation");
@@ -66,6 +70,7 @@ const list_1 = require("./nodes/list");
66
70
  const listing_1 = require("./nodes/listing");
67
71
  const listing_element_1 = require("./nodes/listing_element");
68
72
  const manuscript_1 = require("./nodes/manuscript");
73
+ const meta_section_1 = require("./nodes/meta_section");
69
74
  const missing_figure_1 = require("./nodes/missing_figure");
70
75
  const paragraph_1 = require("./nodes/paragraph");
71
76
  const placeholder_1 = require("./nodes/placeholder");
@@ -130,6 +135,11 @@ __exportStar(require("./nodes/table_row"), exports);
130
135
  __exportStar(require("./nodes/text"), exports);
131
136
  __exportStar(require("./nodes/toc_element"), exports);
132
137
  __exportStar(require("./nodes/toc_section"), exports);
138
+ __exportStar(require("./nodes/affiliation"), exports);
139
+ __exportStar(require("./nodes/affiliation_list"), exports);
140
+ __exportStar(require("./nodes/meta_section"), exports);
141
+ __exportStar(require("./nodes/contributor_list"), exports);
142
+ __exportStar(require("./nodes/contributor"), exports);
133
143
  exports.schema = new prosemirror_model_1.Schema({
134
144
  marks: {
135
145
  bold: marks_1.bold,
@@ -200,5 +210,10 @@ exports.schema = new prosemirror_model_1.Schema({
200
210
  text: text_1.text,
201
211
  toc_element: toc_element_1.tocElement,
202
212
  toc_section: toc_section_1.tocSection,
213
+ affiliation: affiliation_1.affiliation,
214
+ meta_section: meta_section_1.metaSection,
215
+ affiliation_list: affiliation_list_1.affiliationList,
216
+ contributor_list: contributor_list_1.contributorList,
217
+ contributor: contributor_1.contributor,
203
218
  },
204
219
  });
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAffiliationNode = exports.affiliation = void 0;
4
+ exports.affiliation = {
5
+ attrs: {
6
+ id: { default: '' },
7
+ institution: { default: '' },
8
+ department: { default: '' },
9
+ addressLine1: { default: '' },
10
+ addressLine2: { default: '' },
11
+ addressLine3: { default: '' },
12
+ postCode: { default: '' },
13
+ country: { default: '' },
14
+ email: {
15
+ default: {
16
+ href: undefined,
17
+ text: undefined,
18
+ },
19
+ },
20
+ },
21
+ };
22
+ const isAffiliationNode = (node) => node.type === node.type.schema.nodes.affiliation;
23
+ exports.isAffiliationNode = isAffiliationNode;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.affiliationList = void 0;
4
+ exports.affiliationList = {
5
+ content: 'affiliation*',
6
+ attrs: {
7
+ id: { default: 'AFFILIATION_LIST' },
8
+ },
9
+ toDOM: () => ['section', 0],
10
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.contributor = void 0;
4
+ exports.contributor = {
5
+ attrs: {
6
+ id: { default: '' },
7
+ role: { default: '' },
8
+ affiliations: { default: [] },
9
+ bibliographicName: { default: {} },
10
+ userID: { default: '' },
11
+ invitationID: { default: '' },
12
+ isCorresponding: { default: undefined },
13
+ ORCIDIdentifier: { default: '' },
14
+ },
15
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.contributorList = void 0;
4
+ exports.contributorList = {
5
+ content: 'contributor*',
6
+ attrs: {
7
+ id: { default: 'CONTRIBUTOR_LIST' },
8
+ },
9
+ toDOM: () => ['section', 0],
10
+ };
@@ -17,7 +17,7 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.manuscript = void 0;
19
19
  exports.manuscript = {
20
- content: '(section | sections)+ comment_list',
20
+ content: '(section | sections)+ meta_section',
21
21
  attrs: {
22
22
  id: { default: '' },
23
23
  },
@@ -0,0 +1,26 @@
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.metaSection = void 0;
19
+ exports.metaSection = {
20
+ content: 'affiliation_list contributor_list comment_list',
21
+ attrs: {
22
+ id: { default: 'META_SECTION' },
23
+ },
24
+ group: 'block sections',
25
+ toDOM: () => ['section', 0],
26
+ };
@@ -60,6 +60,8 @@ exports.getModelsByType = getModelsByType;
60
60
  const sortSectionsByPriority = (a, b) => a.priority === b.priority ? 0 : Number(a.priority) - Number(b.priority);
61
61
  exports.sortSectionsByPriority = sortSectionsByPriority;
62
62
  const getSections = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Section).sort(exports.sortSectionsByPriority);
63
+ const getAffiliations = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Affiliation);
64
+ const getContributors = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Contributor);
63
65
  const isManuscriptNode = (model) => model !== null;
64
66
  exports.isManuscriptNode = isManuscriptNode;
65
67
  const isParagraphElement = (0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.ParagraphElement);
@@ -69,6 +71,46 @@ const hasParentSection = (id) => (section) => section.path &&
69
71
  section.path.length > 1 &&
70
72
  section.path[section.path.length - 2] === id;
71
73
  class Decoder {
74
+ createAffiliationListNode() {
75
+ const affiliationNodes = getAffiliations(this.modelMap)
76
+ .map((affiliation) => this.decode(affiliation))
77
+ .filter(Boolean);
78
+ return schema_1.schema.nodes.affiliation_list.createAndFill({}, affiliationNodes);
79
+ }
80
+ createContributorListNode() {
81
+ const contributorNodes = getContributors(this.modelMap)
82
+ .map((contributor) => this.decode(contributor))
83
+ .filter(Boolean);
84
+ return schema_1.schema.nodes.contributor_list.createAndFill({}, contributorNodes);
85
+ }
86
+ createMetaSectionNode() {
87
+ const affiliationListNode = this.createAffiliationListNode();
88
+ const contributorListNode = this.createContributorListNode();
89
+ const commentListNode = this.createCommentListNode();
90
+ return schema_1.schema.nodes.meta_section.createAndFill({}, [
91
+ affiliationListNode,
92
+ contributorListNode,
93
+ commentListNode,
94
+ ]);
95
+ }
96
+ createCommentListNode() {
97
+ return schema_1.schema.nodes.comment_list.createAndFill({}, [
98
+ ...this.comments.values(),
99
+ ]);
100
+ }
101
+ createRootSectionNodes() {
102
+ let rootSections = getSections(this.modelMap).filter((section) => !section.path || section.path.length <= 1);
103
+ rootSections = this.addGeneratedLabels(rootSections);
104
+ const rootSectionNodes = rootSections
105
+ .map(this.decode)
106
+ .filter(exports.isManuscriptNode);
107
+ if (!rootSectionNodes.length) {
108
+ rootSectionNodes.push(schema_1.schema.nodes.section.createAndFill({
109
+ id: (0, id_1.generateNodeID)(schema_1.schema.nodes.section),
110
+ }));
111
+ }
112
+ return rootSectionNodes;
113
+ }
72
114
  createCommentsNode(model) {
73
115
  const comments = [];
74
116
  for (const comment of this.getComments(model)) {
@@ -550,6 +592,32 @@ class Decoder {
550
592
  originalText: model.originalText,
551
593
  });
552
594
  },
595
+ [json_schema_1.ObjectTypes.Affiliation]: (data) => {
596
+ const model = data;
597
+ return schema_1.schema.nodes.affiliation.create({
598
+ id: model._id,
599
+ institution: model.institution,
600
+ addressLine1: model.addressLine1,
601
+ addressLine2: model.addressLine2,
602
+ addressLine3: model.addressLine3,
603
+ postCode: model.postCode,
604
+ country: model.country,
605
+ email: model.email,
606
+ });
607
+ },
608
+ [json_schema_1.ObjectTypes.Contributor]: (data) => {
609
+ const model = data;
610
+ return schema_1.schema.nodes.contributor.create({
611
+ id: model._id,
612
+ role: model.role,
613
+ affiliations: model.affiliations,
614
+ bibliographicName: model.bibliographicName,
615
+ userID: model.userID,
616
+ invitationID: model.invitationID,
617
+ isCorresponding: model.isCorresponding,
618
+ ORCIDIdentifier: model.ORCIDIdentifier,
619
+ });
620
+ },
553
621
  };
554
622
  this.decode = (model) => {
555
623
  if (!this.creators[model.objectType]) {
@@ -560,21 +628,9 @@ class Decoder {
560
628
  };
561
629
  this.getModel = (id) => this.modelMap.get(id);
562
630
  this.createArticleNode = (manuscriptID) => {
563
- let rootSections = getSections(this.modelMap).filter((section) => !section.path || section.path.length <= 1);
564
- rootSections = this.addGeneratedLabels(rootSections);
565
- const rootSectionNodes = rootSections
566
- .map(this.decode)
567
- .filter(exports.isManuscriptNode);
568
- if (!rootSectionNodes.length) {
569
- rootSectionNodes.push(schema_1.schema.nodes.section.createAndFill({
570
- id: (0, id_1.generateNodeID)(schema_1.schema.nodes.section),
571
- }));
572
- }
573
- const contents = rootSectionNodes;
574
- const comments = schema_1.schema.nodes.comment_list.createAndFill({}, [
575
- ...this.comments.values(),
576
- ]);
577
- contents.push(comments);
631
+ const rootSectionNodes = this.createRootSectionNodes();
632
+ const metaSectionNode = this.createMetaSectionNode();
633
+ const contents = [...rootSectionNodes, metaSectionNode];
578
634
  return schema_1.schema.nodes.manuscript.create({
579
635
  id: manuscriptID || this.getManuscriptID(),
580
636
  }, contents);
@@ -500,6 +500,24 @@ const encoders = {
500
500
  .map((childNode) => childNode.attrs.id)
501
501
  .filter((id) => id),
502
502
  }),
503
+ affiliation: (node) => ({
504
+ institution: node.attrs.institution,
505
+ addressLine1: node.attrs.addressLine1,
506
+ addressLine2: node.attrs.addressLine2,
507
+ addressLine3: node.attrs.addressLine3,
508
+ postCode: node.attrs.postCode,
509
+ country: node.attrs.country,
510
+ email: node.attrs.email,
511
+ }),
512
+ contributor: (node) => ({
513
+ role: node.attrs.role,
514
+ affiliations: node.attrs.affiliations,
515
+ bibliographicName: node.attrs.bibliographicName,
516
+ userID: node.attrs.userID,
517
+ invitationID: node.attrs.invitationID,
518
+ isCorresponding: node.attrs.isCorresponding,
519
+ ORCIDIdentifier: node.attrs.ORCIDIdentifier,
520
+ }),
503
521
  };
504
522
  const modelData = (node, parent, path, priority) => {
505
523
  const encoder = encoders[node.type.name];
@@ -539,7 +557,7 @@ const encode = (node) => {
539
557
  if ((0, schema_1.isHighlightMarkerNode)(child)) {
540
558
  return;
541
559
  }
542
- if (child.type === schema_1.schema.nodes.comment_list) {
560
+ if (child.type === schema_1.schema.nodes.meta_section) {
543
561
  return;
544
562
  }
545
563
  if (placeholders.includes(child.type.name)) {
@@ -553,14 +571,20 @@ const encode = (node) => {
553
571
  child.forEach(addModel(path.concat(child.attrs.id), child));
554
572
  };
555
573
  node.forEach((cNode) => {
556
- if (cNode.type === schema_1.schema.nodes.comment_list) {
557
- cNode.forEach((child) => {
558
- const { model } = (0, exports.modelFromNode)(child, cNode, [], priority);
559
- models.set(model._id, model);
560
- });
574
+ if (cNode.type === schema_1.schema.nodes.meta_section) {
575
+ processMetaSectionNode(cNode, models, priority);
561
576
  }
562
577
  });
563
578
  node.forEach(addModel([], node));
564
579
  return models;
565
580
  };
566
581
  exports.encode = encode;
582
+ const processMetaSectionNode = (node, models, priority) => {
583
+ node.descendants((child) => {
584
+ if ((!child.content || child.content.size === 0) &&
585
+ node_types_1.nodeTypesMap.get(child.type)) {
586
+ const { model } = (0, exports.modelFromNode)(child, node, [], priority);
587
+ models.set(model._id, model);
588
+ }
589
+ });
590
+ };
@@ -260,7 +260,7 @@ class HTMLTransformer {
260
260
  };
261
261
  return ['span', attrs];
262
262
  };
263
- nodes.comment_list = () => '';
263
+ nodes.meta_section = () => '';
264
264
  const serializer = new prosemirror_model_1.DOMSerializer(nodes, marks);
265
265
  return serializer.serializeFragment(fragment, { document });
266
266
  };
@@ -53,7 +53,9 @@ exports.nodeTypesMap = new Map([
53
53
  [schema_1.schema.nodes.table_element, json_schema_1.ObjectTypes.TableElement],
54
54
  [schema_1.schema.nodes.toc_element, json_schema_1.ObjectTypes.TOCElement],
55
55
  [schema_1.schema.nodes.toc_section, json_schema_1.ObjectTypes.Section],
56
- [schema_1.schema.nodes.comment_list, json_schema_1.ObjectTypes.MetaSection],
56
+ [schema_1.schema.nodes.meta_section, json_schema_1.ObjectTypes.MetaSection],
57
+ [schema_1.schema.nodes.affiliation, json_schema_1.ObjectTypes.Affiliation],
58
+ [schema_1.schema.nodes.contributor, json_schema_1.ObjectTypes.Contributor],
57
59
  ]);
58
60
  const isExecutableNodeType = (type) => (0, schema_1.hasGroup)(type, schema_1.GROUP_EXECUTABLE);
59
61
  exports.isExecutableNodeType = isExecutableNodeType;
@@ -591,6 +591,11 @@ export class JATSExporter {
591
591
  this.createSerializer = () => {
592
592
  const getModel = (id) => id ? this.modelMap.get(id) : undefined;
593
593
  const nodes = {
594
+ contributor_list: () => '',
595
+ contributor: () => '',
596
+ affiliation_list: () => '',
597
+ affiliation: () => '',
598
+ meta_section: () => '',
594
599
  attribution: () => ['attrib', 0],
595
600
  bibliography_element: () => '',
596
601
  bibliography_item: () => '',
@@ -15,6 +15,8 @@
15
15
  */
16
16
  import { Schema } from 'prosemirror-model';
17
17
  import { bold, code, italic, smallcaps, strikethrough, styled, subscript, superscript, tracked_delete, tracked_insert, underline, } from './marks';
18
+ import { affiliation } from './nodes/affiliation';
19
+ import { affiliationList } from './nodes/affiliation_list';
18
20
  import { attribution } from './nodes/attribution';
19
21
  import { bibliographyElement } from './nodes/bibliography_element';
20
22
  import { bibliographyItem } from './nodes/bibliography_item';
@@ -25,6 +27,8 @@ import { captionTitle } from './nodes/caption_title';
25
27
  import { citation } from './nodes/citation';
26
28
  import { comment } from './nodes/comment';
27
29
  import { commentList } from './nodes/comment_list';
30
+ import { contributor } from './nodes/contributor';
31
+ import { contributorList } from './nodes/contributor_list';
28
32
  import { crossReference } from './nodes/cross_reference';
29
33
  import { doc } from './nodes/doc';
30
34
  import { equation } from './nodes/equation';
@@ -49,6 +53,7 @@ import { bulletList, listItem, orderedList } from './nodes/list';
49
53
  import { listing } from './nodes/listing';
50
54
  import { listingElement } from './nodes/listing_element';
51
55
  import { manuscript } from './nodes/manuscript';
56
+ import { metaSection } from './nodes/meta_section';
52
57
  import { missingFigure } from './nodes/missing_figure';
53
58
  import { paragraph } from './nodes/paragraph';
54
59
  import { placeholder } from './nodes/placeholder';
@@ -113,6 +118,11 @@ export * from './nodes/table_row';
113
118
  export * from './nodes/text';
114
119
  export * from './nodes/toc_element';
115
120
  export * from './nodes/toc_section';
121
+ export * from './nodes/affiliation';
122
+ export * from './nodes/affiliation_list';
123
+ export * from './nodes/meta_section';
124
+ export * from './nodes/contributor_list';
125
+ export * from './nodes/contributor';
116
126
  export const schema = new Schema({
117
127
  marks: {
118
128
  bold,
@@ -183,5 +193,10 @@ export const schema = new Schema({
183
193
  text,
184
194
  toc_element: tocElement,
185
195
  toc_section: tocSection,
196
+ affiliation,
197
+ meta_section: metaSection,
198
+ affiliation_list: affiliationList,
199
+ contributor_list: contributorList,
200
+ contributor: contributor,
186
201
  },
187
202
  });
@@ -0,0 +1,19 @@
1
+ export const affiliation = {
2
+ attrs: {
3
+ id: { default: '' },
4
+ institution: { default: '' },
5
+ department: { default: '' },
6
+ addressLine1: { default: '' },
7
+ addressLine2: { default: '' },
8
+ addressLine3: { default: '' },
9
+ postCode: { default: '' },
10
+ country: { default: '' },
11
+ email: {
12
+ default: {
13
+ href: undefined,
14
+ text: undefined,
15
+ },
16
+ },
17
+ },
18
+ };
19
+ export const isAffiliationNode = (node) => node.type === node.type.schema.nodes.affiliation;
@@ -0,0 +1,7 @@
1
+ export const affiliationList = {
2
+ content: 'affiliation*',
3
+ attrs: {
4
+ id: { default: 'AFFILIATION_LIST' },
5
+ },
6
+ toDOM: () => ['section', 0],
7
+ };
@@ -0,0 +1,12 @@
1
+ export const contributor = {
2
+ attrs: {
3
+ id: { default: '' },
4
+ role: { default: '' },
5
+ affiliations: { default: [] },
6
+ bibliographicName: { default: {} },
7
+ userID: { default: '' },
8
+ invitationID: { default: '' },
9
+ isCorresponding: { default: undefined },
10
+ ORCIDIdentifier: { default: '' },
11
+ },
12
+ };
@@ -0,0 +1,7 @@
1
+ export const contributorList = {
2
+ content: 'contributor*',
3
+ attrs: {
4
+ id: { default: 'CONTRIBUTOR_LIST' },
5
+ },
6
+ toDOM: () => ['section', 0],
7
+ };
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  export const manuscript = {
17
- content: '(section | sections)+ comment_list',
17
+ content: '(section | sections)+ meta_section',
18
18
  attrs: {
19
19
  id: { default: '' },
20
20
  },
@@ -0,0 +1,23 @@
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 metaSection = {
17
+ content: 'affiliation_list contributor_list comment_list',
18
+ attrs: {
19
+ id: { default: 'META_SECTION' },
20
+ },
21
+ group: 'block sections',
22
+ toDOM: () => ['section', 0],
23
+ };
@@ -51,6 +51,8 @@ export const getModelsByType = (modelMap, objectType) => {
51
51
  };
52
52
  export const sortSectionsByPriority = (a, b) => a.priority === b.priority ? 0 : Number(a.priority) - Number(b.priority);
53
53
  const getSections = (modelMap) => getModelsByType(modelMap, ObjectTypes.Section).sort(sortSectionsByPriority);
54
+ const getAffiliations = (modelMap) => getModelsByType(modelMap, ObjectTypes.Affiliation);
55
+ const getContributors = (modelMap) => getModelsByType(modelMap, ObjectTypes.Contributor);
54
56
  export const isManuscriptNode = (model) => model !== null;
55
57
  const isParagraphElement = hasObjectType(ObjectTypes.ParagraphElement);
56
58
  const isFootnote = hasObjectType(ObjectTypes.Footnote);
@@ -59,6 +61,46 @@ const hasParentSection = (id) => (section) => section.path &&
59
61
  section.path.length > 1 &&
60
62
  section.path[section.path.length - 2] === id;
61
63
  export class Decoder {
64
+ createAffiliationListNode() {
65
+ const affiliationNodes = getAffiliations(this.modelMap)
66
+ .map((affiliation) => this.decode(affiliation))
67
+ .filter(Boolean);
68
+ return schema.nodes.affiliation_list.createAndFill({}, affiliationNodes);
69
+ }
70
+ createContributorListNode() {
71
+ const contributorNodes = getContributors(this.modelMap)
72
+ .map((contributor) => this.decode(contributor))
73
+ .filter(Boolean);
74
+ return schema.nodes.contributor_list.createAndFill({}, contributorNodes);
75
+ }
76
+ createMetaSectionNode() {
77
+ const affiliationListNode = this.createAffiliationListNode();
78
+ const contributorListNode = this.createContributorListNode();
79
+ const commentListNode = this.createCommentListNode();
80
+ return schema.nodes.meta_section.createAndFill({}, [
81
+ affiliationListNode,
82
+ contributorListNode,
83
+ commentListNode,
84
+ ]);
85
+ }
86
+ createCommentListNode() {
87
+ return schema.nodes.comment_list.createAndFill({}, [
88
+ ...this.comments.values(),
89
+ ]);
90
+ }
91
+ createRootSectionNodes() {
92
+ let rootSections = getSections(this.modelMap).filter((section) => !section.path || section.path.length <= 1);
93
+ rootSections = this.addGeneratedLabels(rootSections);
94
+ const rootSectionNodes = rootSections
95
+ .map(this.decode)
96
+ .filter(isManuscriptNode);
97
+ if (!rootSectionNodes.length) {
98
+ rootSectionNodes.push(schema.nodes.section.createAndFill({
99
+ id: generateNodeID(schema.nodes.section),
100
+ }));
101
+ }
102
+ return rootSectionNodes;
103
+ }
62
104
  createCommentsNode(model) {
63
105
  const comments = [];
64
106
  for (const comment of this.getComments(model)) {
@@ -540,6 +582,32 @@ export class Decoder {
540
582
  originalText: model.originalText,
541
583
  });
542
584
  },
585
+ [ObjectTypes.Affiliation]: (data) => {
586
+ const model = data;
587
+ return schema.nodes.affiliation.create({
588
+ id: model._id,
589
+ institution: model.institution,
590
+ addressLine1: model.addressLine1,
591
+ addressLine2: model.addressLine2,
592
+ addressLine3: model.addressLine3,
593
+ postCode: model.postCode,
594
+ country: model.country,
595
+ email: model.email,
596
+ });
597
+ },
598
+ [ObjectTypes.Contributor]: (data) => {
599
+ const model = data;
600
+ return schema.nodes.contributor.create({
601
+ id: model._id,
602
+ role: model.role,
603
+ affiliations: model.affiliations,
604
+ bibliographicName: model.bibliographicName,
605
+ userID: model.userID,
606
+ invitationID: model.invitationID,
607
+ isCorresponding: model.isCorresponding,
608
+ ORCIDIdentifier: model.ORCIDIdentifier,
609
+ });
610
+ },
543
611
  };
544
612
  this.decode = (model) => {
545
613
  if (!this.creators[model.objectType]) {
@@ -550,21 +618,9 @@ export class Decoder {
550
618
  };
551
619
  this.getModel = (id) => this.modelMap.get(id);
552
620
  this.createArticleNode = (manuscriptID) => {
553
- let rootSections = getSections(this.modelMap).filter((section) => !section.path || section.path.length <= 1);
554
- rootSections = this.addGeneratedLabels(rootSections);
555
- const rootSectionNodes = rootSections
556
- .map(this.decode)
557
- .filter(isManuscriptNode);
558
- if (!rootSectionNodes.length) {
559
- rootSectionNodes.push(schema.nodes.section.createAndFill({
560
- id: generateNodeID(schema.nodes.section),
561
- }));
562
- }
563
- const contents = rootSectionNodes;
564
- const comments = schema.nodes.comment_list.createAndFill({}, [
565
- ...this.comments.values(),
566
- ]);
567
- contents.push(comments);
621
+ const rootSectionNodes = this.createRootSectionNodes();
622
+ const metaSectionNode = this.createMetaSectionNode();
623
+ const contents = [...rootSectionNodes, metaSectionNode];
568
624
  return schema.nodes.manuscript.create({
569
625
  id: manuscriptID || this.getManuscriptID(),
570
626
  }, contents);
@@ -492,6 +492,24 @@ const encoders = {
492
492
  .map((childNode) => childNode.attrs.id)
493
493
  .filter((id) => id),
494
494
  }),
495
+ affiliation: (node) => ({
496
+ institution: node.attrs.institution,
497
+ addressLine1: node.attrs.addressLine1,
498
+ addressLine2: node.attrs.addressLine2,
499
+ addressLine3: node.attrs.addressLine3,
500
+ postCode: node.attrs.postCode,
501
+ country: node.attrs.country,
502
+ email: node.attrs.email,
503
+ }),
504
+ contributor: (node) => ({
505
+ role: node.attrs.role,
506
+ affiliations: node.attrs.affiliations,
507
+ bibliographicName: node.attrs.bibliographicName,
508
+ userID: node.attrs.userID,
509
+ invitationID: node.attrs.invitationID,
510
+ isCorresponding: node.attrs.isCorresponding,
511
+ ORCIDIdentifier: node.attrs.ORCIDIdentifier,
512
+ }),
495
513
  };
496
514
  const modelData = (node, parent, path, priority) => {
497
515
  const encoder = encoders[node.type.name];
@@ -530,7 +548,7 @@ export const encode = (node) => {
530
548
  if (isHighlightMarkerNode(child)) {
531
549
  return;
532
550
  }
533
- if (child.type === schema.nodes.comment_list) {
551
+ if (child.type === schema.nodes.meta_section) {
534
552
  return;
535
553
  }
536
554
  if (placeholders.includes(child.type.name)) {
@@ -544,13 +562,19 @@ export const encode = (node) => {
544
562
  child.forEach(addModel(path.concat(child.attrs.id), child));
545
563
  };
546
564
  node.forEach((cNode) => {
547
- if (cNode.type === schema.nodes.comment_list) {
548
- cNode.forEach((child) => {
549
- const { model } = modelFromNode(child, cNode, [], priority);
550
- models.set(model._id, model);
551
- });
565
+ if (cNode.type === schema.nodes.meta_section) {
566
+ processMetaSectionNode(cNode, models, priority);
552
567
  }
553
568
  });
554
569
  node.forEach(addModel([], node));
555
570
  return models;
556
571
  };
572
+ const processMetaSectionNode = (node, models, priority) => {
573
+ node.descendants((child) => {
574
+ if ((!child.content || child.content.size === 0) &&
575
+ nodeTypesMap.get(child.type)) {
576
+ const { model } = modelFromNode(child, node, [], priority);
577
+ models.set(model._id, model);
578
+ }
579
+ });
580
+ };
@@ -254,7 +254,7 @@ export class HTMLTransformer {
254
254
  };
255
255
  return ['span', attrs];
256
256
  };
257
- nodes.comment_list = () => '';
257
+ nodes.meta_section = () => '';
258
258
  const serializer = new DOMSerializer(nodes, marks);
259
259
  return serializer.serializeFragment(fragment, { document });
260
260
  };
@@ -50,7 +50,9 @@ export const nodeTypesMap = new Map([
50
50
  [schema.nodes.table_element, ObjectTypes.TableElement],
51
51
  [schema.nodes.toc_element, ObjectTypes.TOCElement],
52
52
  [schema.nodes.toc_section, ObjectTypes.Section],
53
- [schema.nodes.comment_list, ObjectTypes.MetaSection],
53
+ [schema.nodes.meta_section, ObjectTypes.MetaSection],
54
+ [schema.nodes.affiliation, ObjectTypes.Affiliation],
55
+ [schema.nodes.contributor, ObjectTypes.Contributor],
54
56
  ]);
55
57
  export const isExecutableNodeType = (type) => hasGroup(type, GROUP_EXECUTABLE);
56
58
  export const isElementNodeType = (type) => hasGroup(type, GROUP_ELEMENT);
@@ -64,4 +64,9 @@ export * from './nodes/table_row';
64
64
  export * from './nodes/text';
65
65
  export * from './nodes/toc_element';
66
66
  export * from './nodes/toc_section';
67
+ export * from './nodes/affiliation';
68
+ export * from './nodes/affiliation_list';
69
+ export * from './nodes/meta_section';
70
+ export * from './nodes/contributor_list';
71
+ export * from './nodes/contributor';
67
72
  export declare const schema: Schema<Nodes, Marks>;
@@ -0,0 +1,23 @@
1
+ import { NodeSpec } from 'prosemirror-model';
2
+ import { ManuscriptNode } from '../types';
3
+ interface Email {
4
+ href: string;
5
+ text: string;
6
+ }
7
+ interface Attrs {
8
+ id: string;
9
+ institution: string;
10
+ department: string;
11
+ addressLine1: string;
12
+ addressLine2: string;
13
+ addressLine3: string;
14
+ postCode: string;
15
+ country: string;
16
+ email: Email;
17
+ }
18
+ export interface AffiliationNode extends ManuscriptNode {
19
+ attrs: Attrs;
20
+ }
21
+ export declare const affiliation: NodeSpec;
22
+ export declare const isAffiliationNode: (node: ManuscriptNode) => node is AffiliationNode;
23
+ export {};
@@ -0,0 +1,10 @@
1
+ import { NodeSpec } from 'prosemirror-model';
2
+ import { ManuscriptNode } from '../types';
3
+ interface Attrs {
4
+ id: string;
5
+ }
6
+ export interface AffiliationListNode extends ManuscriptNode {
7
+ attrs: Attrs;
8
+ }
9
+ export declare const affiliationList: NodeSpec;
10
+ export {};
@@ -0,0 +1,18 @@
1
+ import { Affiliation, BibliographicName } from '@manuscripts/json-schema';
2
+ import { NodeSpec } from 'prosemirror-model';
3
+ import { ManuscriptNode } from '../types';
4
+ interface Attrs {
5
+ id: string;
6
+ role: string;
7
+ affiliations: Affiliation[];
8
+ bibliographicName: BibliographicName;
9
+ userID: string;
10
+ invitationID: string;
11
+ isCorresponding: boolean;
12
+ ORCIDIdentifier: string;
13
+ }
14
+ export interface ContributorNode extends ManuscriptNode {
15
+ attrs: Attrs;
16
+ }
17
+ export declare const contributor: NodeSpec;
18
+ export {};
@@ -0,0 +1,10 @@
1
+ import { NodeSpec } from 'prosemirror-model';
2
+ import { ManuscriptNode } from '../types';
3
+ interface Attrs {
4
+ id: string;
5
+ }
6
+ export interface ContributorListNode extends ManuscriptNode {
7
+ attrs: Attrs;
8
+ }
9
+ export declare const contributorList: NodeSpec;
10
+ export {};
@@ -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 MetaSectionNode extends ManuscriptNode {
22
+ attrs: Attrs;
23
+ }
24
+ export declare const metaSection: 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' | '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' | 'keyword' | 'keywords_element' | 'keywords_group' | 'keywords_section' | 'link' | 'list_item' | 'listing' | 'listing_element' | 'manuscript' | 'missing_figure' | 'ordered_list' | 'paragraph' | 'placeholder' | 'placeholder_element' | 'pullquote_element' | 'section' | 'section_label' | 'section_title' | 'section_title_plain' | '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' | 'keyword' | 'keywords_element' | 'keywords_group' | 'keywords_section' | 'link' | 'list_item' | 'listing' | 'listing_element' | 'manuscript' | 'missing_figure' | 'ordered_list' | 'paragraph' | 'placeholder' | 'placeholder_element' | 'pullquote_element' | 'section' | 'section_label' | 'section_title' | 'section_title_plain' | 'table' | 'table_body' | 'table_cell' | 'table_element' | 'table_row' | 'table_colgroup' | 'table_col' | 'text' | 'toc_element' | 'toc_section' | 'affiliation' | 'meta_section' | 'affiliation_list' | 'contributor_list' | 'contributor';
21
21
  export type ManuscriptSchema = Schema<Nodes, Marks>;
22
22
  export type ManuscriptEditorState = EditorState;
23
23
  export type ManuscriptEditorView = EditorView;
@@ -25,6 +25,11 @@ export declare class Decoder {
25
25
  private readonly allowMissingElements;
26
26
  private comments;
27
27
  private creators;
28
+ private createAffiliationListNode;
29
+ private createContributorListNode;
30
+ private createMetaSectionNode;
31
+ private createCommentListNode;
32
+ private createRootSectionNodes;
28
33
  private createCommentsNode;
29
34
  private getComments;
30
35
  private extractListing;
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.3.8",
4
+ "version": "1.3.9",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -83,4 +83,4 @@
83
83
  "prosemirror-state": "^1.4.2",
84
84
  "prosemirror-view": "^1.29.1"
85
85
  }
86
- }
86
+ }