@manuscripts/transform 1.3.5-LEAN-2611 → 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.
@@ -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;
@@ -18,23 +18,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.convertMathMLToSVG = void 0;
19
19
  require("mathjax-full/js/util/entities/all");
20
20
  const HTMLAdaptor_1 = require("mathjax-full/js/adaptors/HTMLAdaptor");
21
- const MmlFactory_1 = require("mathjax-full/js/core/MmlTree/MmlFactory");
22
21
  const HTMLDocument_1 = require("mathjax-full/js/handlers/html/HTMLDocument");
23
22
  const mathml_1 = require("mathjax-full/js/input/mathml");
24
23
  const svg_1 = require("mathjax-full/js/output/svg");
25
24
  const transformer_1 = require("../transformer");
26
- class ManuscriptsMmlFactory extends MmlFactory_1.MmlFactory {
27
- constructor() {
28
- super();
29
- this.nodeMap.set('image', this.nodeMap.get('none'));
30
- }
31
- create(kind, properties = {}, children = []) {
32
- if (kind === 'image') {
33
- return this.node['none'](properties, children);
34
- }
35
- return this.node[kind](properties, children);
36
- }
37
- }
38
25
  class ManuscriptsHTMLAdaptor extends HTMLAdaptor_1.HTMLAdaptor {
39
26
  setAttribute(node, name, value, ns) {
40
27
  if (name !== 'xmlns') {
@@ -50,7 +37,6 @@ const adaptor = new ManuscriptsHTMLAdaptor(window);
50
37
  const doc = new HTMLDocument_1.HTMLDocument(document, adaptor, {
51
38
  InputJax,
52
39
  OutputJax,
53
- MmlFactory: new ManuscriptsMmlFactory(),
54
40
  });
55
41
  doc.addStyleSheet();
56
42
  const convertMathMLToSVG = (mathml, display) => {
@@ -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));
@@ -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,23 +15,10 @@
15
15
  */
16
16
  import 'mathjax-full/js/util/entities/all';
17
17
  import { HTMLAdaptor } from 'mathjax-full/js/adaptors/HTMLAdaptor';
18
- import { MmlFactory } from 'mathjax-full/js/core/MmlTree/MmlFactory';
19
18
  import { HTMLDocument } from 'mathjax-full/js/handlers/html/HTMLDocument';
20
19
  import { MathML } from 'mathjax-full/js/input/mathml';
21
20
  import { SVG } from 'mathjax-full/js/output/svg';
22
21
  import { xmlSerializer } from '../transformer';
23
- class ManuscriptsMmlFactory extends MmlFactory {
24
- constructor() {
25
- super();
26
- this.nodeMap.set('image', this.nodeMap.get('none'));
27
- }
28
- create(kind, properties = {}, children = []) {
29
- if (kind === 'image') {
30
- return this.node['none'](properties, children);
31
- }
32
- return this.node[kind](properties, children);
33
- }
34
- }
35
22
  class ManuscriptsHTMLAdaptor extends HTMLAdaptor {
36
23
  setAttribute(node, name, value, ns) {
37
24
  if (name !== 'xmlns') {
@@ -47,7 +34,6 @@ const adaptor = new ManuscriptsHTMLAdaptor(window);
47
34
  const doc = new HTMLDocument(document, adaptor, {
48
35
  InputJax,
49
36
  OutputJax,
50
- MmlFactory: new ManuscriptsMmlFactory(),
51
37
  });
52
38
  doc.addStyleSheet();
53
39
  export const convertMathMLToSVG = (mathml, display) => {
@@ -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));
@@ -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 {};
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.5-LEAN-2611",
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",