@manuscripts/transform 1.5.0-LIT-528106 → 1.5.1

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.
@@ -1302,7 +1302,7 @@ class JATSExporter {
1302
1302
  authorNotesEl.appendChild(correspondingEl);
1303
1303
  });
1304
1304
  if (authorNotesEl.childNodes.length > 0) {
1305
- articleMeta.appendChild(authorNotesEl);
1305
+ articleMeta.insertBefore(authorNotesEl, contribGroup.nextSibling);
1306
1306
  }
1307
1307
  }
1308
1308
  }
@@ -1626,7 +1626,22 @@ class JATSExporter {
1626
1626
  authorNoteEl.append(...authorNotes.childNodes);
1627
1627
  }
1628
1628
  else {
1629
- articleMeta.appendChild(authorNotes);
1629
+ const appendableSelectors = [
1630
+ 'contrib-group',
1631
+ 'title-group',
1632
+ 'article-id',
1633
+ ];
1634
+ const appendable = [
1635
+ ...articleMeta.querySelectorAll(appendableSelectors.join(', ')),
1636
+ ];
1637
+ for (let i = 0; i < appendableSelectors.length; i++) {
1638
+ const sel = appendableSelectors[i];
1639
+ const match = appendable.find((el) => el.matches(sel));
1640
+ if (match) {
1641
+ articleMeta.insertBefore(authorNotes, match.nextSibling);
1642
+ break;
1643
+ }
1644
+ }
1630
1645
  }
1631
1646
  }
1632
1647
  }
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.modelsEqual = exports.getTrimmedTextContent = exports.findParentNodeClosestToPos = exports.isInAbstractsSection = exports.isInBibliographySection = exports.isInGraphicalAbstractSection = exports.findNodePositions = exports.iterateChildren = void 0;
18
+ exports.getTrimmedTextContent = exports.findParentNodeClosestToPos = exports.isInAbstractsSection = 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) {
@@ -94,16 +94,3 @@ const getTrimmedTextContent = (node, querySelector) => {
94
94
  return (_b = (_a = node.querySelector(querySelector)) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim();
95
95
  };
96
96
  exports.getTrimmedTextContent = getTrimmedTextContent;
97
- function modelsEqual(model, model2) {
98
- for (const v in model) {
99
- for (const v2 in model2) {
100
- const prepV = typeof v == 'object' ? JSON.stringify(v) : v;
101
- const prepV2 = typeof v2 == 'object' ? JSON.stringify(v2) : v2;
102
- if (prepV !== prepV2) {
103
- return false;
104
- }
105
- }
106
- }
107
- return true;
108
- }
109
- exports.modelsEqual = modelsEqual;
@@ -25,7 +25,6 @@ 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");
29
28
  const node_types_1 = require("./node-types");
30
29
  const section_category_1 = require("./section-category");
31
30
  const serializer = prosemirror_model_1.DOMSerializer.fromSchema(schema_1.schema);
@@ -571,7 +570,7 @@ const modelFromNode = (node, parent, path, priority) => {
571
570
  return { model, commentAnnotationsMap };
572
571
  };
573
572
  exports.modelFromNode = modelFromNode;
574
- const encode = (node, preserveWithRepeatedID = false) => {
573
+ const encode = (node) => {
575
574
  const models = new Map();
576
575
  const priority = {
577
576
  value: 1,
@@ -591,14 +590,8 @@ const encode = (node, preserveWithRepeatedID = false) => {
591
590
  return;
592
591
  }
593
592
  const { model } = (0, exports.modelFromNode)(child, parent, path, priority);
594
- const existingModel = models.get(model._id);
595
- if (existingModel) {
596
- if (preserveWithRepeatedID && !(0, utils_1.modelsEqual)(model, existingModel)) {
597
- model._id = (0, id_1.generateID)(model.objectType);
598
- }
599
- else {
600
- throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
601
- }
593
+ if (models.has(model._id)) {
594
+ throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
602
595
  }
603
596
  models.set(model._id, model);
604
597
  child.forEach(addModel(path.concat(child.attrs.id), child));
@@ -1295,7 +1295,7 @@ export class JATSExporter {
1295
1295
  authorNotesEl.appendChild(correspondingEl);
1296
1296
  });
1297
1297
  if (authorNotesEl.childNodes.length > 0) {
1298
- articleMeta.appendChild(authorNotesEl);
1298
+ articleMeta.insertBefore(authorNotesEl, contribGroup.nextSibling);
1299
1299
  }
1300
1300
  }
1301
1301
  }
@@ -1619,7 +1619,22 @@ export class JATSExporter {
1619
1619
  authorNoteEl.append(...authorNotes.childNodes);
1620
1620
  }
1621
1621
  else {
1622
- articleMeta.appendChild(authorNotes);
1622
+ const appendableSelectors = [
1623
+ 'contrib-group',
1624
+ 'title-group',
1625
+ 'article-id',
1626
+ ];
1627
+ const appendable = [
1628
+ ...articleMeta.querySelectorAll(appendableSelectors.join(', ')),
1629
+ ];
1630
+ for (let i = 0; i < appendableSelectors.length; i++) {
1631
+ const sel = appendableSelectors[i];
1632
+ const match = appendable.find((el) => el.matches(sel));
1633
+ if (match) {
1634
+ articleMeta.insertBefore(authorNotes, match.nextSibling);
1635
+ break;
1636
+ }
1637
+ }
1623
1638
  }
1624
1639
  }
1625
1640
  }
@@ -84,15 +84,3 @@ export const getTrimmedTextContent = (node, querySelector) => {
84
84
  }
85
85
  return (_b = (_a = node.querySelector(querySelector)) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim();
86
86
  };
87
- export function modelsEqual(model, model2) {
88
- for (const v in model) {
89
- for (const v2 in model2) {
90
- const prepV = typeof v == 'object' ? JSON.stringify(v) : v;
91
- const prepV2 = typeof v2 == 'object' ? JSON.stringify(v2) : v2;
92
- if (prepV !== prepV2) {
93
- return false;
94
- }
95
- }
96
- }
97
- return true;
98
- }
@@ -15,11 +15,10 @@
15
15
  */
16
16
  import { DOMSerializer } from 'prosemirror-model';
17
17
  import serializeToXML from 'w3c-xmlserializer';
18
- import { iterateChildren, modelsEqual } from '../lib/utils';
18
+ import { iterateChildren } 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';
23
22
  import { nodeTypesMap } from './node-types';
24
23
  import { buildSectionCategory } from './section-category';
25
24
  const serializer = DOMSerializer.fromSchema(schema);
@@ -562,7 +561,7 @@ export const modelFromNode = (node, parent, path, priority) => {
562
561
  }
563
562
  return { model, commentAnnotationsMap };
564
563
  };
565
- export const encode = (node, preserveWithRepeatedID = false) => {
564
+ export const encode = (node) => {
566
565
  const models = new Map();
567
566
  const priority = {
568
567
  value: 1,
@@ -582,14 +581,8 @@ export const encode = (node, preserveWithRepeatedID = false) => {
582
581
  return;
583
582
  }
584
583
  const { model } = modelFromNode(child, parent, path, priority);
585
- const existingModel = models.get(model._id);
586
- if (existingModel) {
587
- if (preserveWithRepeatedID && !modelsEqual(model, existingModel)) {
588
- model._id = generateID(model.objectType);
589
- }
590
- else {
591
- throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
592
- }
584
+ if (models.has(model._id)) {
585
+ throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
593
586
  }
594
587
  models.set(model._id, model);
595
588
  child.forEach(addModel(path.concat(child.attrs.id), child));
@@ -13,7 +13,6 @@
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';
17
16
  import { Node as ProsemirrorNode, ResolvedPos } from 'prosemirror-model';
18
17
  import { ManuscriptEditorState, ManuscriptNode } from '../schema';
19
18
  export declare function iterateChildren(node: ManuscriptNode, recurse?: boolean): Iterable<ManuscriptNode>;
@@ -28,4 +27,3 @@ export declare const findParentNodeClosestToPos: ($pos: ResolvedPos, predicate:
28
27
  node: ProsemirrorNode;
29
28
  } | undefined;
30
29
  export declare const getTrimmedTextContent: (node: Element | Document, querySelector: string) => string | null | undefined;
31
- 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, preserveWithRepeatedID?: boolean) => Map<string, Model>;
28
+ export declare const encode: (node: ManuscriptNode) => Map<string, Model>;
29
29
  export {};
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.5.0-LIT-528106",
4
+ "version": "1.5.1",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",