@manuscripts/transform 2.0.1-LEAN-3034 → 2.0.1-LEAN-3074-0

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.
@@ -18,9 +18,8 @@ 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.JATSExporter = exports.buildCitations = exports.createCounter = void 0;
21
+ exports.JATSExporter = exports.createCounter = void 0;
22
22
  const json_schema_1 = require("@manuscripts/json-schema");
23
- const library_1 = require("@manuscripts/library");
24
23
  const debug_1 = __importDefault(require("debug"));
25
24
  const prosemirror_model_1 = require("prosemirror-model");
26
25
  const w3c_xmlserializer_1 = __importDefault(require("w3c-xmlserializer"));
@@ -116,23 +115,12 @@ const chooseRefType = (objectType) => {
116
115
  }
117
116
  };
118
117
  const sortContributors = (a, b) => Number(a.priority) - Number(b.priority);
119
- const buildCitations = (citations) => citations.map((citation) => ({
120
- citationID: citation.attrs.id,
121
- citationItems: citation.attrs.rids.map((rid) => ({
122
- id: rid,
123
- })),
124
- properties: {
125
- noteIndex: 0,
126
- },
127
- }));
128
- exports.buildCitations = buildCitations;
129
118
  class JATSExporter {
130
119
  constructor() {
131
- this.serializeToJATS = async (fragment, modelMap, manuscriptID, options) => {
132
- const { version = '1.2', doi, id, frontMatterOnly = false, links, idGenerator, mediaPathGenerator, csl, } = options;
120
+ this.serializeToJATS = async (fragment, modelMap, manuscriptID, options = {}) => {
121
+ const { version = '1.2', doi, id, frontMatterOnly = false, links, idGenerator, mediaPathGenerator, } = options;
133
122
  this.modelMap = modelMap;
134
123
  this.models = Array.from(this.modelMap.values());
135
- this.generateCitationTexts(fragment, csl);
136
124
  this.createSerializer();
137
125
  const versionIds = (0, jats_versions_1.selectVersionIds)(version);
138
126
  this.document = document.implementation.createDocument(null, 'article', document.implementation.createDocumentType('article', versionIds.publicId, versionIds.systemId));
@@ -474,11 +462,10 @@ class JATSExporter {
474
462
  refList = this.document.createElement('ref-list');
475
463
  }
476
464
  back.appendChild(refList);
477
- const [meta] = this.citationProvider.makeBibliography();
478
- for (const id of meta.entry_ids) {
479
- const bibliographyItem = this.modelMap.get(id[0]);
465
+ const bibliographyItems = this.models.filter((0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.BibliographyItem));
466
+ for (const bibliographyItem of bibliographyItems) {
480
467
  const ref = this.document.createElement('ref');
481
- ref.setAttribute('id', normalizeID(id[0]));
468
+ ref.setAttribute('id', normalizeID(bibliographyItem._id));
482
469
  const updateCitationPubType = (citationEl, pubType) => {
483
470
  if (pubType) {
484
471
  switch (pubType) {
@@ -651,11 +638,12 @@ class JATSExporter {
651
638
  const xref = this.document.createElement('xref');
652
639
  xref.setAttribute('ref-type', 'bibr');
653
640
  xref.setAttribute('rid', normalizeID(rids.join(' ')));
654
- const citationTextContent = this.citationTexts.get(node.attrs.id);
655
- if (!citationTextContent) {
656
- throw new Error(`No citation text found for ${node.attrs.id}`);
641
+ if (citation.attrs.contents) {
642
+ const text = (0, html_1.textFromHTML)(node.attrs.contents);
643
+ if (text !== null && text.length) {
644
+ xref.textContent = text;
645
+ }
657
646
  }
658
- xref.textContent = (0, html_1.textFromHTML)(citationTextContent);
659
647
  return xref;
660
648
  },
661
649
  cross_reference: (node) => {
@@ -1566,27 +1554,6 @@ class JATSExporter {
1566
1554
  return name;
1567
1555
  };
1568
1556
  }
1569
- generateCitations(fragment) {
1570
- const nodes = [];
1571
- fragment.descendants((node) => {
1572
- if ((0, schema_1.isCitationNode)(node)) {
1573
- nodes.push(node);
1574
- }
1575
- });
1576
- return (0, exports.buildCitations)(nodes);
1577
- }
1578
- generateCitationTexts(fragment, csl) {
1579
- this.citationTexts = new Map();
1580
- this.citationProvider = new library_1.CitationProvider({
1581
- getLibraryItem: (id) => this.modelMap.get(id),
1582
- locale: csl.locale,
1583
- citationStyle: csl.style,
1584
- });
1585
- const citations = this.generateCitations(fragment);
1586
- this.citationProvider.rebuildState(citations).forEach(([id, , output]) => {
1587
- this.citationTexts.set(id, output);
1588
- });
1589
- }
1590
1557
  buildKeywords(articleMeta) {
1591
1558
  const keywords = [...this.modelMap.values()].filter((model) => model.objectType === json_schema_1.ObjectTypes.Keyword);
1592
1559
  const keywordGroups = new Map();
@@ -17,7 +17,7 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.tableElement = void 0;
19
19
  exports.tableElement = {
20
- content: '(table | placeholder) figcaption? table_element_footer? (listing | placeholder)',
20
+ content: '(table | placeholder) table_element_footer? figcaption? (listing | placeholder)',
21
21
  attrs: {
22
22
  id: { default: '' },
23
23
  paragraphStyle: { default: '' },
@@ -564,7 +564,7 @@ class Decoder {
564
564
  const comments = this.createCommentNodes(model);
565
565
  comments.forEach((c) => this.comments.set(c.attrs.id, c));
566
566
  const content = tableElementFooter
567
- ? [table, figcaption, tableElementFooter]
567
+ ? [table, tableElementFooter, figcaption]
568
568
  : [table, figcaption];
569
569
  if (model.listingID) {
570
570
  const listing = this.createListing(model.listingID);
@@ -14,14 +14,13 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { ObjectTypes, } from '@manuscripts/json-schema';
17
- import { CitationProvider } from '@manuscripts/library';
18
17
  import debug from 'debug';
19
18
  import { DOMParser, DOMSerializer } from 'prosemirror-model';
20
19
  import serializeToXML from 'w3c-xmlserializer';
21
20
  import { nodeFromHTML, textFromHTML } from '../lib/html';
22
21
  import { normalizeStyleName } from '../lib/styled-content';
23
22
  import { iterateChildren } from '../lib/utils';
24
- import { isCitationNode, schema, } from '../schema';
23
+ import { schema, } from '../schema';
25
24
  import { generateAttachmentFilename } from '../transformer/filename';
26
25
  import { buildTargets } from '../transformer/labels';
27
26
  import { isExecutableNodeType, isNodeType } from '../transformer/node-types';
@@ -109,22 +108,12 @@ const chooseRefType = (objectType) => {
109
108
  }
110
109
  };
111
110
  const sortContributors = (a, b) => Number(a.priority) - Number(b.priority);
112
- export const buildCitations = (citations) => citations.map((citation) => ({
113
- citationID: citation.attrs.id,
114
- citationItems: citation.attrs.rids.map((rid) => ({
115
- id: rid,
116
- })),
117
- properties: {
118
- noteIndex: 0,
119
- },
120
- }));
121
111
  export class JATSExporter {
122
112
  constructor() {
123
- this.serializeToJATS = async (fragment, modelMap, manuscriptID, options) => {
124
- const { version = '1.2', doi, id, frontMatterOnly = false, links, idGenerator, mediaPathGenerator, csl, } = options;
113
+ this.serializeToJATS = async (fragment, modelMap, manuscriptID, options = {}) => {
114
+ const { version = '1.2', doi, id, frontMatterOnly = false, links, idGenerator, mediaPathGenerator, } = options;
125
115
  this.modelMap = modelMap;
126
116
  this.models = Array.from(this.modelMap.values());
127
- this.generateCitationTexts(fragment, csl);
128
117
  this.createSerializer();
129
118
  const versionIds = selectVersionIds(version);
130
119
  this.document = document.implementation.createDocument(null, 'article', document.implementation.createDocumentType('article', versionIds.publicId, versionIds.systemId));
@@ -466,11 +455,10 @@ export class JATSExporter {
466
455
  refList = this.document.createElement('ref-list');
467
456
  }
468
457
  back.appendChild(refList);
469
- const [meta] = this.citationProvider.makeBibliography();
470
- for (const id of meta.entry_ids) {
471
- const bibliographyItem = this.modelMap.get(id[0]);
458
+ const bibliographyItems = this.models.filter(hasObjectType(ObjectTypes.BibliographyItem));
459
+ for (const bibliographyItem of bibliographyItems) {
472
460
  const ref = this.document.createElement('ref');
473
- ref.setAttribute('id', normalizeID(id[0]));
461
+ ref.setAttribute('id', normalizeID(bibliographyItem._id));
474
462
  const updateCitationPubType = (citationEl, pubType) => {
475
463
  if (pubType) {
476
464
  switch (pubType) {
@@ -643,11 +631,12 @@ export class JATSExporter {
643
631
  const xref = this.document.createElement('xref');
644
632
  xref.setAttribute('ref-type', 'bibr');
645
633
  xref.setAttribute('rid', normalizeID(rids.join(' ')));
646
- const citationTextContent = this.citationTexts.get(node.attrs.id);
647
- if (!citationTextContent) {
648
- throw new Error(`No citation text found for ${node.attrs.id}`);
634
+ if (citation.attrs.contents) {
635
+ const text = textFromHTML(node.attrs.contents);
636
+ if (text !== null && text.length) {
637
+ xref.textContent = text;
638
+ }
649
639
  }
650
- xref.textContent = textFromHTML(citationTextContent);
651
640
  return xref;
652
641
  },
653
642
  cross_reference: (node) => {
@@ -1558,27 +1547,6 @@ export class JATSExporter {
1558
1547
  return name;
1559
1548
  };
1560
1549
  }
1561
- generateCitations(fragment) {
1562
- const nodes = [];
1563
- fragment.descendants((node) => {
1564
- if (isCitationNode(node)) {
1565
- nodes.push(node);
1566
- }
1567
- });
1568
- return buildCitations(nodes);
1569
- }
1570
- generateCitationTexts(fragment, csl) {
1571
- this.citationTexts = new Map();
1572
- this.citationProvider = new CitationProvider({
1573
- getLibraryItem: (id) => this.modelMap.get(id),
1574
- locale: csl.locale,
1575
- citationStyle: csl.style,
1576
- });
1577
- const citations = this.generateCitations(fragment);
1578
- this.citationProvider.rebuildState(citations).forEach(([id, , output]) => {
1579
- this.citationTexts.set(id, output);
1580
- });
1581
- }
1582
1550
  buildKeywords(articleMeta) {
1583
1551
  const keywords = [...this.modelMap.values()].filter((model) => model.objectType === ObjectTypes.Keyword);
1584
1552
  const keywordGroups = new Map();
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  export const tableElement = {
17
- content: '(table | placeholder) figcaption? table_element_footer? (listing | placeholder)',
17
+ content: '(table | placeholder) table_element_footer? figcaption? (listing | placeholder)',
18
18
  attrs: {
19
19
  id: { default: '' },
20
20
  paragraphStyle: { default: '' },
@@ -555,7 +555,7 @@ export class Decoder {
555
555
  const comments = this.createCommentNodes(model);
556
556
  comments.forEach((c) => this.comments.set(c.attrs.id, c));
557
557
  const content = tableElementFooter
558
- ? [table, figcaption, tableElementFooter]
558
+ ? [table, tableElementFooter, figcaption]
559
559
  : [table, figcaption];
560
560
  if (model.listingID) {
561
561
  const listing = this.createListing(model.listingID);
@@ -14,9 +14,8 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { Model } from '@manuscripts/json-schema';
17
- import { CitationProvider } from '@manuscripts/library';
18
17
  import { DOMSerializer } from 'prosemirror-model';
19
- import { CitationNode, ManuscriptFragment, ManuscriptNode } from '../schema';
18
+ import { ManuscriptFragment, ManuscriptNode } from '../schema';
20
19
  import { Target } from '../transformer/labels';
21
20
  import { IDGenerator, MediaPathGenerator } from '../types';
22
21
  import { Version } from './jats-versions';
@@ -28,12 +27,7 @@ interface Links {
28
27
  export declare const createCounter: () => {
29
28
  increment: (field: string) => number;
30
29
  };
31
- export type CSLOptions = {
32
- style: string;
33
- locale: string;
34
- };
35
30
  export interface JATSExporterOptions {
36
- csl: CSLOptions;
37
31
  version?: Version;
38
32
  doi?: string;
39
33
  id?: string;
@@ -43,34 +37,13 @@ export interface JATSExporterOptions {
43
37
  idGenerator?: IDGenerator;
44
38
  mediaPathGenerator?: MediaPathGenerator;
45
39
  }
46
- export declare const buildCitations: (citations: CitationNode[]) => {
47
- citationID: string;
48
- citationItems: {
49
- id: string;
50
- }[];
51
- properties: {
52
- noteIndex: number;
53
- };
54
- }[];
55
40
  export declare class JATSExporter {
56
41
  protected document: Document;
57
42
  protected modelMap: Map<string, Model>;
58
43
  protected models: Model[];
59
44
  protected serializer: DOMSerializer;
60
45
  protected labelTargets?: Map<string, Target>;
61
- protected citationTexts: Map<string, string>;
62
- protected citationProvider: CitationProvider;
63
- protected generateCitations(fragment: ManuscriptFragment): {
64
- citationID: string;
65
- citationItems: {
66
- id: string;
67
- }[];
68
- properties: {
69
- noteIndex: number;
70
- };
71
- }[];
72
- protected generateCitationTexts(fragment: ManuscriptFragment, csl: CSLOptions): void;
73
- serializeToJATS: (fragment: ManuscriptFragment, modelMap: Map<string, Model>, manuscriptID: string, options: JATSExporterOptions) => Promise<string>;
46
+ serializeToJATS: (fragment: ManuscriptFragment, modelMap: Map<string, Model>, manuscriptID: string, options?: JATSExporterOptions) => Promise<string>;
74
47
  private nodeFromJATS;
75
48
  protected rewriteCrossReferenceTypes: () => void;
76
49
  protected rewriteMediaPaths: (mediaPathGenerator: MediaPathGenerator) => Promise<void>;
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": "2.0.1-LEAN-3034",
4
+ "version": "2.0.1-LEAN-3074-0",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -29,8 +29,7 @@
29
29
  "version": "yarn build"
30
30
  },
31
31
  "dependencies": {
32
- "@manuscripts/json-schema": "2.2.1-LEAN-3034",
33
- "@manuscripts/library": "1.3.0-LEAN-3034",
32
+ "@manuscripts/json-schema": "2.2.1",
34
33
  "debug": "^4.3.4",
35
34
  "jszip": "^3.10.1",
36
35
  "mathjax-full": "^3.2.2",
@@ -78,4 +77,4 @@
78
77
  "rimraf": "^3.0.2",
79
78
  "typescript": "^4.0.5"
80
79
  }
81
- }
80
+ }