@manuscripts/transform 1.3.4 → 1.3.5-LIT-528106

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.
@@ -135,11 +135,13 @@ class JATSExporter {
135
135
  const body = this.buildBody(fragment);
136
136
  article.appendChild(body);
137
137
  const back = this.buildBack(body);
138
+ this.moveCoiStatementToAuthorNotes(back, front);
138
139
  article.appendChild(back);
139
140
  this.unwrapBody(body);
140
141
  this.moveAbstracts(front, body);
141
142
  this.moveFloatsGroup(body, article);
142
143
  this.removeBackContainer(body);
144
+ this.updateFootnoteTypes(front, back);
143
145
  }
144
146
  await this.rewriteIDs(idGenerator);
145
147
  if (mediaPathGenerator) {
@@ -1575,5 +1577,37 @@ class JATSExporter {
1575
1577
  articleMeta.appendChild(kwdGroup);
1576
1578
  }
1577
1579
  }
1580
+ moveCoiStatementToAuthorNotes(back, front) {
1581
+ const fnGroups = back.querySelectorAll('fn-group');
1582
+ fnGroups.forEach((fnGroup) => {
1583
+ if (fnGroup) {
1584
+ const coiStatement = fnGroup.querySelector('fn[fn-type="competing-interests"]');
1585
+ if (coiStatement) {
1586
+ const authorNotes = this.document.createElement('author-notes');
1587
+ authorNotes.append(coiStatement);
1588
+ const articleMeta = front.querySelector('article-meta');
1589
+ if (articleMeta) {
1590
+ const authorNoteEl = articleMeta.querySelector('author-notes');
1591
+ if (authorNoteEl) {
1592
+ authorNoteEl.append(...authorNotes.childNodes);
1593
+ }
1594
+ else {
1595
+ articleMeta.appendChild(authorNotes);
1596
+ }
1597
+ }
1598
+ }
1599
+ }
1600
+ });
1601
+ }
1602
+ updateFootnoteTypes(front, body) {
1603
+ const footnotes = [...front.querySelectorAll('fn').values()];
1604
+ footnotes.push(...body.querySelectorAll('fn'));
1605
+ footnotes.forEach((fn) => {
1606
+ const fnType = fn.getAttribute('fn-type');
1607
+ if (fnType) {
1608
+ fn.setAttribute('fn-type', (0, section_category_1.chooseJatsFnType)(fnType));
1609
+ }
1610
+ });
1611
+ }
1578
1612
  }
1579
1613
  exports.JATSExporter = JATSExporter;
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.getTrimmedTextContent = exports.findParentNodeClosestToPos = exports.isInBibliographySection = exports.isInGraphicalAbstractSection = exports.findNodePositions = exports.iterateChildren = void 0;
18
+ exports.modelsEqual = exports.getTrimmedTextContent = exports.findParentNodeClosestToPos = exports.isInBibliographySection = exports.isInGraphicalAbstractSection = exports.findNodePositions = exports.iterateChildren = void 0;
19
19
  const bibliography_section_1 = require("../schema/nodes/bibliography_section");
20
20
  const graphical_abstract_section_1 = require("../schema/nodes/graphical_abstract_section");
21
21
  function* iterateChildren(node, recurse = false) {
@@ -83,3 +83,16 @@ const getTrimmedTextContent = (node, querySelector) => {
83
83
  return (_b = (_a = node.querySelector(querySelector)) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim();
84
84
  };
85
85
  exports.getTrimmedTextContent = getTrimmedTextContent;
86
+ function modelsEqual(model, model2) {
87
+ for (const v in model) {
88
+ for (const v2 in model2) {
89
+ const prepV = typeof v == 'object' ? JSON.stringify(v) : v;
90
+ const prepV2 = typeof v2 == 'object' ? JSON.stringify(v2) : v2;
91
+ if (prepV !== prepV2) {
92
+ return false;
93
+ }
94
+ }
95
+ }
96
+ return true;
97
+ }
98
+ exports.modelsEqual = modelsEqual;
@@ -25,6 +25,7 @@ const utils_1 = require("../lib/utils");
25
25
  const schema_1 = require("../schema");
26
26
  const builders_1 = require("./builders");
27
27
  const highlight_markers_1 = require("./highlight-markers");
28
+ const id_1 = require("./id");
28
29
  const node_types_1 = require("./node-types");
29
30
  const section_category_1 = require("./section-category");
30
31
  const serializer = prosemirror_model_1.DOMSerializer.fromSchema(schema_1.schema);
@@ -526,7 +527,7 @@ const modelFromNode = (node, parent, path, priority) => {
526
527
  return { model, commentAnnotationsMap };
527
528
  };
528
529
  exports.modelFromNode = modelFromNode;
529
- const encode = (node) => {
530
+ const encode = (node, preserveWithRepeatedID = false) => {
530
531
  const models = new Map();
531
532
  const priority = {
532
533
  value: 1,
@@ -546,8 +547,14 @@ const encode = (node) => {
546
547
  return;
547
548
  }
548
549
  const { model } = (0, exports.modelFromNode)(child, parent, path, priority);
549
- if (models.has(model._id)) {
550
- throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
550
+ const existingModel = models.get(model._id);
551
+ if (existingModel) {
552
+ if (preserveWithRepeatedID && !(0, utils_1.modelsEqual)(model, existingModel)) {
553
+ model._id = (0, id_1.generateID)(model.objectType);
554
+ }
555
+ else {
556
+ throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
557
+ }
551
558
  }
552
559
  models.set(model._id, model);
553
560
  child.forEach(addModel(path.concat(child.attrs.id), child));
@@ -18,7 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.chooseSectionCategoryFromTitle = exports.chooseSectionCategory = exports.chooseSectionCategoryByType = exports.chooseSecType = exports.buildSectionCategory = exports.guessSectionCategory = exports.chooseSectionLableName = exports.chooseSectionNodeType = exports.isAnySectionNode = exports.getSectionTitles = void 0;
21
+ exports.chooseSectionCategoryFromTitle = exports.chooseSectionCategory = exports.chooseSectionCategoryByType = exports.chooseSecType = exports.chooseJatsFnType = exports.buildSectionCategory = exports.guessSectionCategory = exports.chooseSectionLableName = exports.chooseSectionNodeType = exports.isAnySectionNode = exports.getSectionTitles = void 0;
22
22
  const section_categories_json_1 = __importDefault(require("@manuscripts/data/dist/shared/section-categories.json"));
23
23
  const json_schema_1 = require("@manuscripts/json-schema");
24
24
  const schema_1 = require("../schema");
@@ -104,6 +104,15 @@ const buildSectionCategory = (node) => {
104
104
  }
105
105
  };
106
106
  exports.buildSectionCategory = buildSectionCategory;
107
+ const chooseJatsFnType = (footnoteType) => {
108
+ switch (footnoteType) {
109
+ case 'competing-interests':
110
+ return 'coi-statement';
111
+ default:
112
+ return footnoteType;
113
+ }
114
+ };
115
+ exports.chooseJatsFnType = chooseJatsFnType;
107
116
  const chooseSecType = (sectionCategory) => {
108
117
  const [, suffix] = sectionCategory.split(':', 2);
109
118
  switch (suffix) {
@@ -26,7 +26,7 @@ import { buildTargets } from '../transformer/labels';
26
26
  import { isExecutableNodeType, isNodeType } from '../transformer/node-types';
27
27
  import { hasObjectType } from '../transformer/object-types';
28
28
  import { findManuscript, findManuscriptById, } from '../transformer/project-bundle';
29
- import { chooseSecType } from '../transformer/section-category';
29
+ import { chooseJatsFnType, chooseSecType, } from '../transformer/section-category';
30
30
  import { selectVersionIds } from './jats-versions';
31
31
  const warn = debug('manuscripts-transform');
32
32
  const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
@@ -128,11 +128,13 @@ export class JATSExporter {
128
128
  const body = this.buildBody(fragment);
129
129
  article.appendChild(body);
130
130
  const back = this.buildBack(body);
131
+ this.moveCoiStatementToAuthorNotes(back, front);
131
132
  article.appendChild(back);
132
133
  this.unwrapBody(body);
133
134
  this.moveAbstracts(front, body);
134
135
  this.moveFloatsGroup(body, article);
135
136
  this.removeBackContainer(body);
137
+ this.updateFootnoteTypes(front, back);
136
138
  }
137
139
  await this.rewriteIDs(idGenerator);
138
140
  if (mediaPathGenerator) {
@@ -1568,4 +1570,36 @@ export class JATSExporter {
1568
1570
  articleMeta.appendChild(kwdGroup);
1569
1571
  }
1570
1572
  }
1573
+ moveCoiStatementToAuthorNotes(back, front) {
1574
+ const fnGroups = back.querySelectorAll('fn-group');
1575
+ fnGroups.forEach((fnGroup) => {
1576
+ if (fnGroup) {
1577
+ const coiStatement = fnGroup.querySelector('fn[fn-type="competing-interests"]');
1578
+ if (coiStatement) {
1579
+ const authorNotes = this.document.createElement('author-notes');
1580
+ authorNotes.append(coiStatement);
1581
+ const articleMeta = front.querySelector('article-meta');
1582
+ if (articleMeta) {
1583
+ const authorNoteEl = articleMeta.querySelector('author-notes');
1584
+ if (authorNoteEl) {
1585
+ authorNoteEl.append(...authorNotes.childNodes);
1586
+ }
1587
+ else {
1588
+ articleMeta.appendChild(authorNotes);
1589
+ }
1590
+ }
1591
+ }
1592
+ }
1593
+ });
1594
+ }
1595
+ updateFootnoteTypes(front, body) {
1596
+ const footnotes = [...front.querySelectorAll('fn').values()];
1597
+ footnotes.push(...body.querySelectorAll('fn'));
1598
+ footnotes.forEach((fn) => {
1599
+ const fnType = fn.getAttribute('fn-type');
1600
+ if (fnType) {
1601
+ fn.setAttribute('fn-type', chooseJatsFnType(fnType));
1602
+ }
1603
+ });
1604
+ }
1571
1605
  }
@@ -74,3 +74,15 @@ export const getTrimmedTextContent = (node, querySelector) => {
74
74
  }
75
75
  return (_b = (_a = node.querySelector(querySelector)) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim();
76
76
  };
77
+ export function modelsEqual(model, model2) {
78
+ for (const v in model) {
79
+ for (const v2 in model2) {
80
+ const prepV = typeof v == 'object' ? JSON.stringify(v) : v;
81
+ const prepV2 = typeof v2 == 'object' ? JSON.stringify(v2) : v2;
82
+ if (prepV !== prepV2) {
83
+ return false;
84
+ }
85
+ }
86
+ }
87
+ return true;
88
+ }
@@ -15,10 +15,11 @@
15
15
  */
16
16
  import { DOMSerializer } from 'prosemirror-model';
17
17
  import serializeToXML from 'w3c-xmlserializer';
18
- import { iterateChildren } from '../lib/utils';
18
+ import { iterateChildren, modelsEqual } from '../lib/utils';
19
19
  import { hasGroup, isHighlightMarkerNode, isSectionNode, schema, } from '../schema';
20
20
  import { buildAttribution } from './builders';
21
21
  import { extractHighlightMarkers, isHighlightableModel, } from './highlight-markers';
22
+ import { generateID } from './id';
22
23
  import { nodeTypesMap } from './node-types';
23
24
  import { buildSectionCategory } from './section-category';
24
25
  const serializer = DOMSerializer.fromSchema(schema);
@@ -517,7 +518,7 @@ export const modelFromNode = (node, parent, path, priority) => {
517
518
  }
518
519
  return { model, commentAnnotationsMap };
519
520
  };
520
- export const encode = (node) => {
521
+ export const encode = (node, preserveWithRepeatedID = false) => {
521
522
  const models = new Map();
522
523
  const priority = {
523
524
  value: 1,
@@ -537,8 +538,14 @@ export const encode = (node) => {
537
538
  return;
538
539
  }
539
540
  const { model } = modelFromNode(child, parent, path, priority);
540
- if (models.has(model._id)) {
541
- throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
541
+ const existingModel = models.get(model._id);
542
+ if (existingModel) {
543
+ if (preserveWithRepeatedID && !modelsEqual(model, existingModel)) {
544
+ model._id = generateID(model.objectType);
545
+ }
546
+ else {
547
+ throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
548
+ }
542
549
  }
543
550
  models.set(model._id, model);
544
551
  child.forEach(addModel(path.concat(child.attrs.id), child));
@@ -92,6 +92,14 @@ export const buildSectionCategory = (node) => {
92
92
  return node.attrs.category || undefined;
93
93
  }
94
94
  };
95
+ export const chooseJatsFnType = (footnoteType) => {
96
+ switch (footnoteType) {
97
+ case 'competing-interests':
98
+ return 'coi-statement';
99
+ default:
100
+ return footnoteType;
101
+ }
102
+ };
95
103
  export const chooseSecType = (sectionCategory) => {
96
104
  const [, suffix] = sectionCategory.split(':', 2);
97
105
  switch (suffix) {
@@ -70,5 +70,7 @@ export declare class JATSExporter {
70
70
  sectionToFootnote: (section: Element, fnType: string) => HTMLElement;
71
71
  private moveFloatsGroup;
72
72
  private buildContributorName;
73
+ private moveCoiStatementToAuthorNotes;
74
+ private updateFootnoteTypes;
73
75
  }
74
76
  export {};
@@ -13,6 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { Model } from '@manuscripts/json-schema';
16
17
  import { Node as ProsemirrorNode, ResolvedPos } from 'prosemirror-model';
17
18
  import { ManuscriptEditorState, ManuscriptNode } from '../schema';
18
19
  export declare function iterateChildren(node: ManuscriptNode, recurse?: boolean): Iterable<ManuscriptNode>;
@@ -26,3 +27,4 @@ export declare const findParentNodeClosestToPos: ($pos: ResolvedPos, predicate:
26
27
  node: ProsemirrorNode;
27
28
  } | undefined;
28
29
  export declare const getTrimmedTextContent: (node: Element | Document, querySelector: string) => string | null | undefined;
30
+ export declare function modelsEqual(model: Model, model2: Model): boolean;
@@ -25,5 +25,5 @@ export declare const modelFromNode: (node: ManuscriptNode, parent: ManuscriptNod
25
25
  interface PrioritizedValue {
26
26
  value: number;
27
27
  }
28
- export declare const encode: (node: ManuscriptNode) => Map<string, Model>;
28
+ export declare const encode: (node: ManuscriptNode, preserveWithRepeatedID?: boolean) => Map<string, Model>;
29
29
  export {};
@@ -23,6 +23,7 @@ export declare const chooseSectionNodeType: (category?: SectionCategory) => Manu
23
23
  export declare const chooseSectionLableName: (type?: SecType) => string;
24
24
  export declare const guessSectionCategory: (elements: Element[]) => SectionCategory | undefined;
25
25
  export declare const buildSectionCategory: (node: ManuscriptNode) => SectionCategory | undefined;
26
+ export declare const chooseJatsFnType: (footnoteType: string) => string;
26
27
  export declare const chooseSecType: (sectionCategory: SectionCategory) => SecType;
27
28
  export declare const chooseSectionCategoryByType: (secType: string) => SectionCategory | undefined;
28
29
  export declare const chooseSectionCategory: (section: HTMLElement) => SectionCategory | undefined;
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.4",
4
+ "version": "1.3.5-LIT-528106",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",