@manuscripts/transform 1.5.5 → 1.5.7-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.
@@ -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.isInAbstractsSection = exports.isInBibliographySection = exports.isInGraphicalAbstractSection = exports.findNodePositions = exports.iterateChildren = void 0;
18
+ exports.modelsEqual = 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,3 +94,16 @@ 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;
@@ -21,6 +21,7 @@ exports.graphicalAbstractSection = {
21
21
  attrs: {
22
22
  id: { default: '' },
23
23
  category: { default: '' },
24
+ dataTracked: { default: null },
24
25
  },
25
26
  group: 'block sections',
26
27
  selectable: false,
@@ -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);
@@ -573,10 +574,11 @@ const modelFromNode = (node, parent, path, priority) => {
573
574
  if ((0, highlight_markers_1.isHighlightableModel)(model)) {
574
575
  (0, highlight_markers_1.extractHighlightMarkers)(model, commentAnnotationsMap);
575
576
  }
576
- return { model, commentAnnotationsMap };
577
+ const comments = [...commentAnnotationsMap.values()];
578
+ return { model, comments };
577
579
  };
578
580
  exports.modelFromNode = modelFromNode;
579
- const encode = (node) => {
581
+ const encode = (node, preserveWithRepeatedID = false) => {
580
582
  const models = new Map();
581
583
  const priority = {
582
584
  value: 1,
@@ -595,10 +597,24 @@ const encode = (node) => {
595
597
  if (placeholders.includes(child.type.name)) {
596
598
  return;
597
599
  }
598
- const { model } = (0, exports.modelFromNode)(child, parent, path, priority);
599
- if (models.has(model._id)) {
600
- throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
600
+ const { model, comments } = (0, exports.modelFromNode)(child, parent, path, priority);
601
+ const existingModel = models.get(model._id);
602
+ if (existingModel) {
603
+ if (preserveWithRepeatedID && !(0, utils_1.modelsEqual)(model, existingModel)) {
604
+ model._id = (0, id_1.generateID)(model.objectType);
605
+ }
606
+ else {
607
+ throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
608
+ }
601
609
  }
610
+ comments.forEach((comment) => {
611
+ const proseMirrorComment = models.get(comment._id);
612
+ if (proseMirrorComment) {
613
+ ;
614
+ proseMirrorComment.selector = comment.selector;
615
+ models.set(comment._id, proseMirrorComment);
616
+ }
617
+ });
602
618
  models.set(model._id, model);
603
619
  child.forEach(addModel(path.concat(child.attrs.id), child));
604
620
  };
@@ -84,3 +84,15 @@ 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
+ }
@@ -18,6 +18,7 @@ export const graphicalAbstractSection = {
18
18
  attrs: {
19
19
  id: { default: '' },
20
20
  category: { default: '' },
21
+ dataTracked: { default: null },
21
22
  },
22
23
  group: 'block sections',
23
24
  selectable: false,
@@ -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);
@@ -565,9 +566,10 @@ export const modelFromNode = (node, parent, path, priority) => {
565
566
  if (isHighlightableModel(model)) {
566
567
  extractHighlightMarkers(model, commentAnnotationsMap);
567
568
  }
568
- return { model, commentAnnotationsMap };
569
+ const comments = [...commentAnnotationsMap.values()];
570
+ return { model, comments };
569
571
  };
570
- export const encode = (node) => {
572
+ export const encode = (node, preserveWithRepeatedID = false) => {
571
573
  const models = new Map();
572
574
  const priority = {
573
575
  value: 1,
@@ -586,10 +588,24 @@ export const encode = (node) => {
586
588
  if (placeholders.includes(child.type.name)) {
587
589
  return;
588
590
  }
589
- const { model } = modelFromNode(child, parent, path, priority);
590
- if (models.has(model._id)) {
591
- throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
591
+ const { model, comments } = modelFromNode(child, parent, path, priority);
592
+ const existingModel = models.get(model._id);
593
+ if (existingModel) {
594
+ if (preserveWithRepeatedID && !modelsEqual(model, existingModel)) {
595
+ model._id = generateID(model.objectType);
596
+ }
597
+ else {
598
+ throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
599
+ }
592
600
  }
601
+ comments.forEach((comment) => {
602
+ const proseMirrorComment = models.get(comment._id);
603
+ if (proseMirrorComment) {
604
+ ;
605
+ proseMirrorComment.selector = comment.selector;
606
+ models.set(comment._id, proseMirrorComment);
607
+ }
608
+ });
593
609
  models.set(model._id, model);
594
610
  child.forEach(addModel(path.concat(child.attrs.id), child));
595
611
  };
@@ -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>;
@@ -27,3 +28,4 @@ export declare const findParentNodeClosestToPos: ($pos: ResolvedPos, predicate:
27
28
  node: ProsemirrorNode;
28
29
  } | undefined;
29
30
  export declare const getTrimmedTextContent: (node: Element | Document, querySelector: string) => string | null | undefined;
31
+ export declare function modelsEqual(model: Model, model2: Model): boolean;
@@ -20,10 +20,10 @@ export declare const inlineContents: (node: ManuscriptNode) => string;
20
20
  export declare const inlineText: (node: ManuscriptNode) => string;
21
21
  export declare const modelFromNode: (node: ManuscriptNode, parent: ManuscriptNode, path: string[], priority: PrioritizedValue) => {
22
22
  model: Model;
23
- commentAnnotationsMap: Map<string, Build<CommentAnnotation>>;
23
+ comments: Build<CommentAnnotation>[];
24
24
  };
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 {};
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.5",
4
+ "version": "1.5.7-LIT-528106",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",