@manuscripts/transform 2.0.1-LEAN-3034 → 2.0.1-LEAN-3083-2
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.
- package/dist/cjs/jats/jats-exporter.js +11 -44
- package/dist/cjs/schema/nodes/contributor.js +2 -0
- package/dist/cjs/transformer/decode.js +2 -1
- package/dist/es/jats/jats-exporter.js +11 -43
- package/dist/es/schema/nodes/contributor.js +2 -0
- package/dist/es/transformer/decode.js +2 -1
- package/dist/types/jats/jats-exporter.d.ts +2 -29
- package/dist/types/schema/nodes/contributor.d.ts +3 -2
- package/package.json +2 -3
|
@@ -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.
|
|
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,
|
|
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
|
|
478
|
-
for (const
|
|
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(
|
|
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
|
-
|
|
655
|
-
|
|
656
|
-
|
|
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();
|
|
@@ -6,6 +6,7 @@ exports.contributor = {
|
|
|
6
6
|
attrs: {
|
|
7
7
|
id: { default: '' },
|
|
8
8
|
role: { default: '' },
|
|
9
|
+
email: { default: '' },
|
|
9
10
|
affiliations: { default: [] },
|
|
10
11
|
footnote: { default: undefined },
|
|
11
12
|
corresp: { default: undefined },
|
|
@@ -13,6 +14,7 @@ exports.contributor = {
|
|
|
13
14
|
userID: { default: undefined },
|
|
14
15
|
invitationID: { default: undefined },
|
|
15
16
|
isCorresponding: { default: undefined },
|
|
17
|
+
isJointContributor: { default: undefined },
|
|
16
18
|
ORCIDIdentifier: { default: undefined },
|
|
17
19
|
priority: { default: undefined },
|
|
18
20
|
dataTracked: { default: null },
|
|
@@ -91,7 +91,7 @@ class Decoder {
|
|
|
91
91
|
const contributors = getContributors(this.modelMap)
|
|
92
92
|
.map((c) => this.decode(c))
|
|
93
93
|
.filter(Boolean);
|
|
94
|
-
return schema_1.schema.nodes.contributors.createAndFill({}, contributors);
|
|
94
|
+
return schema_1.schema.nodes.contributors.createAndFill({}, contributors.sort((a, b) => Number(a.attrs.priority) - Number(b.attrs.priority)));
|
|
95
95
|
}
|
|
96
96
|
createKeywordsNode() {
|
|
97
97
|
const elements = getKeywordElements(this.modelMap)
|
|
@@ -629,6 +629,7 @@ class Decoder {
|
|
|
629
629
|
id: model._id,
|
|
630
630
|
role: model.role,
|
|
631
631
|
affiliations: model.affiliations,
|
|
632
|
+
email: model.email,
|
|
632
633
|
bibliographicName: model.bibliographicName,
|
|
633
634
|
userID: model.userID,
|
|
634
635
|
invitationID: model.invitationID,
|
|
@@ -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 {
|
|
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,
|
|
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
|
|
470
|
-
for (const
|
|
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(
|
|
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
|
-
|
|
647
|
-
|
|
648
|
-
|
|
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();
|
|
@@ -3,6 +3,7 @@ export const contributor = {
|
|
|
3
3
|
attrs: {
|
|
4
4
|
id: { default: '' },
|
|
5
5
|
role: { default: '' },
|
|
6
|
+
email: { default: '' },
|
|
6
7
|
affiliations: { default: [] },
|
|
7
8
|
footnote: { default: undefined },
|
|
8
9
|
corresp: { default: undefined },
|
|
@@ -10,6 +11,7 @@ export const contributor = {
|
|
|
10
11
|
userID: { default: undefined },
|
|
11
12
|
invitationID: { default: undefined },
|
|
12
13
|
isCorresponding: { default: undefined },
|
|
14
|
+
isJointContributor: { default: undefined },
|
|
13
15
|
ORCIDIdentifier: { default: undefined },
|
|
14
16
|
priority: { default: undefined },
|
|
15
17
|
dataTracked: { default: null },
|
|
@@ -82,7 +82,7 @@ export class Decoder {
|
|
|
82
82
|
const contributors = getContributors(this.modelMap)
|
|
83
83
|
.map((c) => this.decode(c))
|
|
84
84
|
.filter(Boolean);
|
|
85
|
-
return schema.nodes.contributors.createAndFill({}, contributors);
|
|
85
|
+
return schema.nodes.contributors.createAndFill({}, contributors.sort((a, b) => Number(a.attrs.priority) - Number(b.attrs.priority)));
|
|
86
86
|
}
|
|
87
87
|
createKeywordsNode() {
|
|
88
88
|
const elements = getKeywordElements(this.modelMap)
|
|
@@ -620,6 +620,7 @@ export class Decoder {
|
|
|
620
620
|
id: model._id,
|
|
621
621
|
role: model.role,
|
|
622
622
|
affiliations: model.affiliations,
|
|
623
|
+
email: model.email,
|
|
623
624
|
bibliographicName: model.bibliographicName,
|
|
624
625
|
userID: model.userID,
|
|
625
626
|
invitationID: model.invitationID,
|
|
@@ -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 {
|
|
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
|
-
|
|
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>;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BibliographicName } from '@manuscripts/json-schema';
|
|
2
2
|
import { NodeSpec } from 'prosemirror-model';
|
|
3
3
|
import { ManuscriptNode } from '../types';
|
|
4
4
|
interface Attrs {
|
|
5
5
|
id: string;
|
|
6
6
|
role: string;
|
|
7
|
-
affiliations:
|
|
7
|
+
affiliations: string[];
|
|
8
8
|
bibliographicName: BibliographicName;
|
|
9
9
|
userID: string;
|
|
10
|
+
email: string;
|
|
10
11
|
invitationID: string;
|
|
11
12
|
isCorresponding: boolean;
|
|
12
13
|
ORCIDIdentifier: string;
|
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-
|
|
4
|
+
"version": "2.0.1-LEAN-3083-2",
|
|
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
|
|
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",
|