@manuscripts/transform 1.4.4 → 1.4.5

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.
@@ -651,9 +651,13 @@ const nodes = [
651
651
  getAttrs: (node) => {
652
652
  var _a;
653
653
  const element = node;
654
+ const embeddedCitationAttr = element.getAttribute('data-reference-embedded-citation');
654
655
  return {
655
656
  rid: element.getAttribute('rid'),
656
657
  contents: (_a = element.textContent) === null || _a === void 0 ? void 0 : _a.trim(),
658
+ embeddedCitationItems: embeddedCitationAttr
659
+ ? JSON.parse(embeddedCitationAttr)
660
+ : null,
657
661
  };
658
662
  },
659
663
  },
@@ -158,6 +158,10 @@ exports.jatsReferenceParser = {
158
158
  const citation = (0, builders_1.buildCitation)('', rids);
159
159
  modelNodes.push(citation);
160
160
  crossReferenceNode.setAttribute('rid', citation._id);
161
+ crossReferenceNode.setAttribute('data-reference-embedded-citation', JSON.stringify(citation.embeddedCitationItems.map(({ _id: id, bibliographyItem }) => ({
162
+ id,
163
+ bibliographyItem,
164
+ }))));
161
165
  }
162
166
  else {
163
167
  crossReferenceNode.removeAttribute('rid');
@@ -628,20 +628,16 @@ class JATSExporter {
628
628
  warn(`${node.attrs.id} has no rid`);
629
629
  return node.attrs.label;
630
630
  }
631
- const citation = getModel(node.attrs.rid);
632
- if (!citation) {
633
- warn(`Missing citation ${node.attrs.rid}`);
634
- return '';
635
- }
636
- const rids = citation.embeddedCitationItems.filter((item) => {
631
+ const rids = node.attrs
632
+ .embeddedCitationItems.filter((item) => {
637
633
  if (!this.modelMap.has(item.bibliographyItem)) {
638
- warn(`Missing ${item.bibliographyItem} referenced by ${citation._id}`);
634
+ warn(`Missing ${item.bibliographyItem} referenced by ${node.attrs.rid}`);
639
635
  return false;
640
636
  }
641
637
  return true;
642
638
  });
643
639
  if (!rids.length) {
644
- warn(`${citation._id} has no confirmed rids`);
640
+ warn(`${node.attrs.rid} has no confirmed rids`);
645
641
  return '';
646
642
  }
647
643
  const xref = this.document.createElement('xref');
@@ -26,16 +26,22 @@ exports.citation = {
26
26
  contents: { default: '' },
27
27
  selectedText: { default: '' },
28
28
  dataTracked: { default: null },
29
+ embeddedCitationItems: { default: [] },
29
30
  },
30
31
  parseDOM: [
31
32
  {
32
33
  tag: 'span.citation[data-reference-id]',
33
34
  getAttrs: (p) => {
34
35
  const dom = p;
35
- return {
36
+ const attr = {
36
37
  rid: dom.getAttribute('data-reference-id'),
37
38
  contents: dom.innerHTML,
38
39
  };
40
+ const embeddedCitationAttr = dom.getAttribute('data-reference-embedded-citation');
41
+ if (embeddedCitationAttr) {
42
+ attr['embeddedCitationItems'] = JSON.parse(embeddedCitationAttr);
43
+ }
44
+ return attr;
39
45
  },
40
46
  },
41
47
  ],
@@ -44,6 +50,9 @@ exports.citation = {
44
50
  const dom = document.createElement('span');
45
51
  dom.className = 'citation';
46
52
  dom.setAttribute('data-reference-id', citationNode.attrs.rid);
53
+ if (citationNode.attrs.embeddedCitationItems) {
54
+ dom.setAttribute('data-reference-embedded-citation', JSON.stringify(citationNode.attrs.embeddedCitationItems));
55
+ }
47
56
  dom.innerHTML = citationNode.attrs.contents;
48
57
  return dom;
49
58
  },
@@ -271,8 +271,9 @@ const encoders = {
271
271
  }),
272
272
  bibliography_item: (node) => {
273
273
  const { type, containerTitle, doi, volume, issue, supplement, page, title, literal, } = node.attrs;
274
- const author = fromJson(node.attrs.author);
275
- const issued = fromJson(node.attrs.issued);
274
+ const getObjectAtrr = (obj) => typeof obj === 'string' ? fromJson(obj) : obj;
275
+ const author = getObjectAtrr(node.attrs.author);
276
+ const issued = getObjectAtrr(node.attrs.issued);
276
277
  const ref = {
277
278
  type,
278
279
  };
@@ -645,9 +645,13 @@ const nodes = [
645
645
  getAttrs: (node) => {
646
646
  var _a;
647
647
  const element = node;
648
+ const embeddedCitationAttr = element.getAttribute('data-reference-embedded-citation');
648
649
  return {
649
650
  rid: element.getAttribute('rid'),
650
651
  contents: (_a = element.textContent) === null || _a === void 0 ? void 0 : _a.trim(),
652
+ embeddedCitationItems: embeddedCitationAttr
653
+ ? JSON.parse(embeddedCitationAttr)
654
+ : null,
651
655
  };
652
656
  },
653
657
  },
@@ -155,6 +155,10 @@ export const jatsReferenceParser = {
155
155
  const citation = buildCitation('', rids);
156
156
  modelNodes.push(citation);
157
157
  crossReferenceNode.setAttribute('rid', citation._id);
158
+ crossReferenceNode.setAttribute('data-reference-embedded-citation', JSON.stringify(citation.embeddedCitationItems.map(({ _id: id, bibliographyItem }) => ({
159
+ id,
160
+ bibliographyItem,
161
+ }))));
158
162
  }
159
163
  else {
160
164
  crossReferenceNode.removeAttribute('rid');
@@ -621,20 +621,16 @@ export class JATSExporter {
621
621
  warn(`${node.attrs.id} has no rid`);
622
622
  return node.attrs.label;
623
623
  }
624
- const citation = getModel(node.attrs.rid);
625
- if (!citation) {
626
- warn(`Missing citation ${node.attrs.rid}`);
627
- return '';
628
- }
629
- const rids = citation.embeddedCitationItems.filter((item) => {
624
+ const rids = node.attrs
625
+ .embeddedCitationItems.filter((item) => {
630
626
  if (!this.modelMap.has(item.bibliographyItem)) {
631
- warn(`Missing ${item.bibliographyItem} referenced by ${citation._id}`);
627
+ warn(`Missing ${item.bibliographyItem} referenced by ${node.attrs.rid}`);
632
628
  return false;
633
629
  }
634
630
  return true;
635
631
  });
636
632
  if (!rids.length) {
637
- warn(`${citation._id} has no confirmed rids`);
633
+ warn(`${node.attrs.rid} has no confirmed rids`);
638
634
  return '';
639
635
  }
640
636
  const xref = this.document.createElement('xref');
@@ -23,16 +23,22 @@ export const citation = {
23
23
  contents: { default: '' },
24
24
  selectedText: { default: '' },
25
25
  dataTracked: { default: null },
26
+ embeddedCitationItems: { default: [] },
26
27
  },
27
28
  parseDOM: [
28
29
  {
29
30
  tag: 'span.citation[data-reference-id]',
30
31
  getAttrs: (p) => {
31
32
  const dom = p;
32
- return {
33
+ const attr = {
33
34
  rid: dom.getAttribute('data-reference-id'),
34
35
  contents: dom.innerHTML,
35
36
  };
37
+ const embeddedCitationAttr = dom.getAttribute('data-reference-embedded-citation');
38
+ if (embeddedCitationAttr) {
39
+ attr['embeddedCitationItems'] = JSON.parse(embeddedCitationAttr);
40
+ }
41
+ return attr;
36
42
  },
37
43
  },
38
44
  ],
@@ -41,6 +47,9 @@ export const citation = {
41
47
  const dom = document.createElement('span');
42
48
  dom.className = 'citation';
43
49
  dom.setAttribute('data-reference-id', citationNode.attrs.rid);
50
+ if (citationNode.attrs.embeddedCitationItems) {
51
+ dom.setAttribute('data-reference-embedded-citation', JSON.stringify(citationNode.attrs.embeddedCitationItems));
52
+ }
44
53
  dom.innerHTML = citationNode.attrs.contents;
45
54
  return dom;
46
55
  },
@@ -263,8 +263,9 @@ const encoders = {
263
263
  }),
264
264
  bibliography_item: (node) => {
265
265
  const { type, containerTitle, doi, volume, issue, supplement, page, title, literal, } = node.attrs;
266
- const author = fromJson(node.attrs.author);
267
- const issued = fromJson(node.attrs.issued);
266
+ const getObjectAtrr = (obj) => typeof obj === 'string' ? fromJson(obj) : obj;
267
+ const author = getObjectAtrr(node.attrs.author);
268
+ const issued = getObjectAtrr(node.attrs.issued);
268
269
  const ref = {
269
270
  type,
270
271
  };
@@ -18,6 +18,10 @@ import { ManuscriptNode } from '../types';
18
18
  interface Attrs {
19
19
  rid: string;
20
20
  contents: string;
21
+ embeddedCitationItems: {
22
+ id: string;
23
+ bibliographyItem: string;
24
+ }[];
21
25
  }
22
26
  export interface CitationNode extends ManuscriptNode {
23
27
  attrs: Attrs;
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.4.4",
4
+ "version": "1.4.5",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",