@manuscripts/transform 4.3.53 → 4.4.1
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/__tests__/jats-roundtrip.test.js +3 -3
- package/dist/cjs/jats/exporter/jats-exporter.js +3 -0
- package/dist/cjs/jats/importer/jats-dom-parser.js +41 -1
- package/dist/cjs/schema/index.js +9 -0
- package/dist/cjs/schema/nodes/headshot_element.js +38 -0
- package/dist/cjs/schema/nodes/headshot_grid.js +37 -0
- package/dist/cjs/schema/nodes/headshot_image.js +51 -0
- package/dist/cjs/transformer/node-names.js +2 -0
- package/dist/cjs/transformer/node-title.js +6 -0
- package/dist/cjs/version.js +1 -1
- package/dist/es/jats/__tests__/jats-roundtrip.test.js +3 -3
- package/dist/es/jats/exporter/jats-exporter.js +3 -0
- package/dist/es/jats/importer/jats-dom-parser.js +41 -1
- package/dist/es/schema/index.js +9 -0
- package/dist/es/schema/nodes/headshot_element.js +34 -0
- package/dist/es/schema/nodes/headshot_grid.js +33 -0
- package/dist/es/schema/nodes/headshot_image.js +48 -0
- package/dist/es/transformer/node-names.js +2 -0
- package/dist/es/transformer/node-title.js +6 -0
- package/dist/es/version.js +1 -1
- package/dist/types/jats/__tests__/utils.d.ts +1 -1
- package/dist/types/schema/index.d.ts +3 -0
- package/dist/types/schema/nodes/headshot_element.d.ts +25 -0
- package/dist/types/schema/nodes/headshot_grid.d.ts +24 -0
- package/dist/types/schema/nodes/headshot_image.d.ts +26 -0
- package/dist/types/schema/types.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +22 -21
- package/src/errors.ts +28 -0
- package/src/getVersion.ts +21 -0
- package/src/index.ts +28 -0
- package/src/jats/__tests__/__fixtures__/debug-example.xml +136 -0
- package/src/jats/__tests__/__fixtures__/jats-abstract-no-body.xml +163 -0
- package/src/jats/__tests__/__fixtures__/jats-citations.xml +472 -0
- package/src/jats/__tests__/__fixtures__/jats-comments.xml +46 -0
- package/src/jats/__tests__/__fixtures__/jats-document.xml +134 -0
- package/src/jats/__tests__/__fixtures__/jats-example-doc.xml +1235 -0
- package/src/jats/__tests__/__fixtures__/jats-example-front-only.xml +26 -0
- package/src/jats/__tests__/__fixtures__/jats-example-full.xml +209 -0
- package/src/jats/__tests__/__fixtures__/jats-example-no-back.xml +156 -0
- package/src/jats/__tests__/__fixtures__/jats-example-no-body.xml +91 -0
- package/src/jats/__tests__/__fixtures__/jats-example.xml +221 -0
- package/src/jats/__tests__/__fixtures__/jats-fn-group.xml +60 -0
- package/src/jats/__tests__/__fixtures__/jats-import-no-refs.xml +1077 -0
- package/src/jats/__tests__/__fixtures__/jats-import.xml +1578 -0
- package/src/jats/__tests__/__fixtures__/jats-roundtrip.xml +133 -0
- package/src/jats/__tests__/__fixtures__/jats-tables-example.xml +2043 -0
- package/src/jats/__tests__/__fixtures__/math-fragment.xml +12 -0
- package/src/jats/__tests__/__snapshots__/citeproc.test.ts.snap +57 -0
- package/src/jats/__tests__/__snapshots__/create-article-node.test.ts.snap +65 -0
- package/src/jats/__tests__/__snapshots__/jats-exporter.test.ts.snap +7 -0
- package/src/jats/__tests__/__snapshots__/jats-importer.test.ts.snap +59796 -0
- package/src/jats/__tests__/__snapshots__/jats-roundtrip.test.ts.snap +18 -0
- package/src/jats/__tests__/citations.ts +25 -0
- package/src/jats/__tests__/citeproc.test.ts +195 -0
- package/src/jats/__tests__/create-article-node.test.ts +29 -0
- package/src/jats/__tests__/data/section-categories.ts +212 -0
- package/src/jats/__tests__/files.ts +24 -0
- package/src/jats/__tests__/jats-exporter.test.ts +223 -0
- package/src/jats/__tests__/jats-importer.test.ts +567 -0
- package/src/jats/__tests__/jats-roundtrip.test.ts +66 -0
- package/src/jats/__tests__/utils.ts +90 -0
- package/src/jats/exporter/citeproc.ts +265 -0
- package/src/jats/exporter/jats-exporter.ts +2093 -0
- package/src/jats/exporter/jats-versions.ts +50 -0
- package/src/jats/exporter/labels.ts +101 -0
- package/src/jats/importer/create-article-node.ts +52 -0
- package/src/jats/importer/jats-comments.ts +111 -0
- package/src/jats/importer/jats-dom-parser.ts +1306 -0
- package/src/jats/importer/jats-parser-utils.ts +234 -0
- package/src/jats/importer/jats-transformations.ts +591 -0
- package/src/jats/importer/parse-jats-article.ts +106 -0
- package/src/jats/index.ts +21 -0
- package/src/jats/types.ts +16 -0
- package/src/lib/__tests__/footnotes.test.ts +36 -0
- package/src/lib/citeproc.ts +30 -0
- package/src/lib/credit-roles.ts +91 -0
- package/src/lib/deafults.ts +17 -0
- package/src/lib/footnotes.ts +85 -0
- package/src/lib/html.ts +56 -0
- package/src/lib/section-categories.ts +27 -0
- package/src/lib/utils.ts +145 -0
- package/src/lib/xml.ts +28 -0
- package/src/schema/__tests__/docs.ts +1911 -0
- package/src/schema/__tests__/groups.test.ts +61 -0
- package/src/schema/__tests__/migration.test.ts +23 -0
- package/src/schema/groups.ts +36 -0
- package/src/schema/index.ts +295 -0
- package/src/schema/marks.ts +254 -0
- package/src/schema/migration/migrate.ts +77 -0
- package/src/schema/migration/migration-script.ts +26 -0
- package/src/schema/migration/migration-scripts/1.2.5.ts +44 -0
- package/src/schema/migration/migration-scripts/2.3.22.ts +52 -0
- package/src/schema/migration/migration-scripts/3.0.12.ts +33 -0
- package/src/schema/migration/migration-scripts/3.0.21.ts +50 -0
- package/src/schema/migration/migration-scripts/3.0.30.ts +65 -0
- package/src/schema/migration/migration-scripts/3.0.31.ts +40 -0
- package/src/schema/migration/migration-scripts/3.0.41.ts +37 -0
- package/src/schema/migration/migration-scripts/3.0.55.ts +42 -0
- package/src/schema/migration/migration-scripts/3.0.56.ts +114 -0
- package/src/schema/migration/migration-scripts/4.2.13.ts +37 -0
- package/src/schema/migration/migration-scripts/4.2.15.ts +48 -0
- package/src/schema/migration/migration-scripts/4.3.23.ts +55 -0
- package/src/schema/migration/migration-scripts/4.3.34.ts +132 -0
- package/src/schema/migration/migration-scripts/4.3.35.ts +41 -0
- package/src/schema/migration/migration-scripts/index.ts +49 -0
- package/src/schema/nodes/abstracts.ts +29 -0
- package/src/schema/nodes/affiliation.ts +88 -0
- package/src/schema/nodes/affiliations.ts +30 -0
- package/src/schema/nodes/alt_text.ts +36 -0
- package/src/schema/nodes/alt_title.ts +40 -0
- package/src/schema/nodes/alt_titles_section.ts +58 -0
- package/src/schema/nodes/attachment.ts +46 -0
- package/src/schema/nodes/attachments.ts +45 -0
- package/src/schema/nodes/attribution.ts +38 -0
- package/src/schema/nodes/author_notes.ts +44 -0
- package/src/schema/nodes/award.ts +52 -0
- package/src/schema/nodes/awards.ts +45 -0
- package/src/schema/nodes/backmatter.ts +31 -0
- package/src/schema/nodes/bibliography_element.ts +58 -0
- package/src/schema/nodes/bibliography_item.ts +108 -0
- package/src/schema/nodes/bibliography_section.ts +60 -0
- package/src/schema/nodes/blockquote_element.ts +79 -0
- package/src/schema/nodes/body.ts +29 -0
- package/src/schema/nodes/box_element.ts +67 -0
- package/src/schema/nodes/caption.ts +67 -0
- package/src/schema/nodes/caption_title.ts +67 -0
- package/src/schema/nodes/citation.ts +70 -0
- package/src/schema/nodes/comment.ts +50 -0
- package/src/schema/nodes/comments.ts +28 -0
- package/src/schema/nodes/contributor.ts +87 -0
- package/src/schema/nodes/contributors.ts +40 -0
- package/src/schema/nodes/core_section.ts +27 -0
- package/src/schema/nodes/corresp.ts +49 -0
- package/src/schema/nodes/cross_reference.ts +64 -0
- package/src/schema/nodes/doc.ts +21 -0
- package/src/schema/nodes/embed.ts +55 -0
- package/src/schema/nodes/equation.ts +65 -0
- package/src/schema/nodes/equation_element.ts +61 -0
- package/src/schema/nodes/figure.ts +65 -0
- package/src/schema/nodes/figure_element.ts +73 -0
- package/src/schema/nodes/footnote.ts +95 -0
- package/src/schema/nodes/footnotes_element.ts +69 -0
- package/src/schema/nodes/footnotes_section.ts +61 -0
- package/src/schema/nodes/general_table_footnote.ts +42 -0
- package/src/schema/nodes/graphical_abstract_section.ts +62 -0
- package/src/schema/nodes/hard_break.ts +36 -0
- package/src/schema/nodes/headshot_element.ts +48 -0
- package/src/schema/nodes/headshot_grid.ts +46 -0
- package/src/schema/nodes/headshot_image.ts +65 -0
- package/src/schema/nodes/hero_image.ts +46 -0
- package/src/schema/nodes/highlight_marker.ts +68 -0
- package/src/schema/nodes/image_element.ts +49 -0
- package/src/schema/nodes/inline_equation.ts +68 -0
- package/src/schema/nodes/inline_footnote.ts +66 -0
- package/src/schema/nodes/keyword.ts +61 -0
- package/src/schema/nodes/keyword_group.ts +63 -0
- package/src/schema/nodes/keywords.ts +59 -0
- package/src/schema/nodes/keywords_element.ts +64 -0
- package/src/schema/nodes/link.ts +79 -0
- package/src/schema/nodes/list.ts +134 -0
- package/src/schema/nodes/listing.ts +91 -0
- package/src/schema/nodes/listing_element.ts +61 -0
- package/src/schema/nodes/long_desc.ts +36 -0
- package/src/schema/nodes/manuscript.ts +86 -0
- package/src/schema/nodes/missing_figure.ts +59 -0
- package/src/schema/nodes/paragraph.ts +77 -0
- package/src/schema/nodes/placeholder.ts +62 -0
- package/src/schema/nodes/placeholder_element.ts +60 -0
- package/src/schema/nodes/pullquote_element.ts +81 -0
- package/src/schema/nodes/quote_image.ts +64 -0
- package/src/schema/nodes/section.ts +69 -0
- package/src/schema/nodes/section_label.ts +39 -0
- package/src/schema/nodes/section_title.ts +58 -0
- package/src/schema/nodes/subtitle.ts +40 -0
- package/src/schema/nodes/subtitles.ts +51 -0
- package/src/schema/nodes/supplement.ts +77 -0
- package/src/schema/nodes/supplements.ts +60 -0
- package/src/schema/nodes/table.ts +144 -0
- package/src/schema/nodes/table_col.ts +76 -0
- package/src/schema/nodes/table_element.ts +67 -0
- package/src/schema/nodes/table_element_footer.ts +42 -0
- package/src/schema/nodes/text.ts +31 -0
- package/src/schema/nodes/title.ts +43 -0
- package/src/schema/nodes/trans_abstract.ts +58 -0
- package/src/schema/nodes/trans_graphical_abstract.ts +67 -0
- package/src/schema/types.ts +243 -0
- package/src/tests.ts +33 -0
- package/src/transformer/id.ts +23 -0
- package/src/transformer/index.ts +21 -0
- package/src/transformer/node-names.ts +75 -0
- package/src/transformer/node-title.ts +116 -0
- package/src/transformer/node-types.ts +39 -0
- package/src/transformer/node-validator.ts +82 -0
- package/src/types.ts +25 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2019 Atypon Systems LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export * from './id'
|
|
18
|
+
export * from './node-names'
|
|
19
|
+
export * from './node-title'
|
|
20
|
+
export * from './node-types'
|
|
21
|
+
export * from './node-validator'
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2019 Atypon Systems LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { schema } from '../schema'
|
|
18
|
+
import { ManuscriptNodeType } from '../schema/types'
|
|
19
|
+
|
|
20
|
+
export const nodeNames: Map<ManuscriptNodeType, string> = new Map([
|
|
21
|
+
[schema.nodes.title, 'Title'],
|
|
22
|
+
[schema.nodes.contributor, 'Author'],
|
|
23
|
+
[schema.nodes.keywords, 'Keywords'],
|
|
24
|
+
[schema.nodes.keyword, 'Keyword'],
|
|
25
|
+
[schema.nodes.bibliography_element, 'Bibliography'],
|
|
26
|
+
[schema.nodes.bibliography_item, 'Reference'],
|
|
27
|
+
[schema.nodes.bibliography_section, 'Section'],
|
|
28
|
+
[schema.nodes.citation, 'Citation'],
|
|
29
|
+
[schema.nodes.listing_element, 'Listing'],
|
|
30
|
+
[schema.nodes.cross_reference, 'Cross Reference'],
|
|
31
|
+
[schema.nodes.equation_element, 'Equation'],
|
|
32
|
+
[schema.nodes.figure_element, 'Figure'],
|
|
33
|
+
[schema.nodes.image_element, 'Image'],
|
|
34
|
+
[schema.nodes.hero_image, 'Hero Image'],
|
|
35
|
+
[schema.nodes.headshot_grid, 'Headshot Panel'],
|
|
36
|
+
[schema.nodes.headshot_element, 'Headshot'],
|
|
37
|
+
[schema.nodes.table_element, 'Table'],
|
|
38
|
+
[schema.nodes.table_cell, 'Table Cell'],
|
|
39
|
+
[schema.nodes.table_col, 'Table Column'],
|
|
40
|
+
[schema.nodes.table_row, 'Table Row'],
|
|
41
|
+
[schema.nodes.table_header, 'Table Header'],
|
|
42
|
+
[schema.nodes.general_table_footnote, 'General Table note'],
|
|
43
|
+
[schema.nodes.table_element_footer, 'Table Footer'],
|
|
44
|
+
[schema.nodes.embed, 'Media'],
|
|
45
|
+
[schema.nodes.equation, 'Equation'],
|
|
46
|
+
[schema.nodes.inline_equation, 'Inline Equation'],
|
|
47
|
+
[schema.nodes.inline_footnote, 'Footnote Reference'],
|
|
48
|
+
[schema.nodes.footnote, 'Footnote'],
|
|
49
|
+
[schema.nodes.footnotes_element, 'Notes'],
|
|
50
|
+
[schema.nodes.footnotes_section, 'Footnotes Section'],
|
|
51
|
+
[schema.nodes.list, 'List'],
|
|
52
|
+
[schema.nodes.list_item, 'List Item'],
|
|
53
|
+
[schema.nodes.manuscript, 'Manuscript'],
|
|
54
|
+
[schema.nodes.paragraph, 'Paragraph'],
|
|
55
|
+
[schema.nodes.text_block, 'Paragraph'],
|
|
56
|
+
[schema.nodes.section, 'Section'],
|
|
57
|
+
[schema.nodes.graphical_abstract_section, 'Graphical Abstract'],
|
|
58
|
+
[schema.nodes.trans_abstract, 'Trans Abstract'],
|
|
59
|
+
[schema.nodes.trans_graphical_abstract, 'Trans Graphical Abstract'],
|
|
60
|
+
[schema.nodes.section_title, 'Section Title'],
|
|
61
|
+
[schema.nodes.section_title_plain, 'Section Title'],
|
|
62
|
+
[schema.nodes.table, 'Table'],
|
|
63
|
+
[schema.nodes.table_element, 'Table'],
|
|
64
|
+
[schema.nodes.blockquote_element, 'Block Quote'],
|
|
65
|
+
[schema.nodes.pullquote_element, 'Pull Quote'],
|
|
66
|
+
[schema.nodes.box_element, 'Box'],
|
|
67
|
+
[schema.nodes.supplements, 'Supplements'],
|
|
68
|
+
[schema.nodes.attachments, 'Main Document'],
|
|
69
|
+
])
|
|
70
|
+
|
|
71
|
+
export const typeName = (type: ManuscriptNodeType) =>
|
|
72
|
+
type.name
|
|
73
|
+
.split('_')
|
|
74
|
+
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
|
75
|
+
.join('')
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2019 Atypon Systems LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { NodeType } from 'prosemirror-model'
|
|
18
|
+
|
|
19
|
+
import { iterateChildren } from '../lib/utils'
|
|
20
|
+
import { isHighlightMarkerNode, schema } from '../schema'
|
|
21
|
+
import { ManuscriptNode, ManuscriptNodeType } from '../schema/types'
|
|
22
|
+
import { nodeNames } from './node-names'
|
|
23
|
+
|
|
24
|
+
const textSnippet = (node: ManuscriptNode, max = 100) => {
|
|
25
|
+
let text = ''
|
|
26
|
+
|
|
27
|
+
node.forEach((child) => {
|
|
28
|
+
if (child.isText) {
|
|
29
|
+
text += child.text
|
|
30
|
+
} else if (isHighlightMarkerNode(node)) {
|
|
31
|
+
text += ''
|
|
32
|
+
} else if (node.type === schema.nodes.headshot_element) {
|
|
33
|
+
if (child.type === schema.nodes.caption_title) {
|
|
34
|
+
text += child.textContent
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
text += ' '
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
return text.substring(0, max)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const snippetOfNodeType = (
|
|
45
|
+
node: ManuscriptNode,
|
|
46
|
+
nodeType: ManuscriptNodeType
|
|
47
|
+
) => {
|
|
48
|
+
for (const child of iterateChildren(node, true)) {
|
|
49
|
+
if (child.type === nodeType) {
|
|
50
|
+
return textSnippet(child)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return null
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const nodeTitle = (node: ManuscriptNode) => {
|
|
58
|
+
const nodes = schema.nodes
|
|
59
|
+
|
|
60
|
+
switch (node.type) {
|
|
61
|
+
case nodes.manuscript:
|
|
62
|
+
return snippetOfNodeType(node, nodes.title)
|
|
63
|
+
|
|
64
|
+
case nodes.section:
|
|
65
|
+
case nodes.bibliography_section:
|
|
66
|
+
case nodes.footnotes_section:
|
|
67
|
+
case nodes.keywords:
|
|
68
|
+
case nodes.graphical_abstract_section:
|
|
69
|
+
case nodes.trans_graphical_abstract:
|
|
70
|
+
return snippetOfNodeType(node, nodes.section_title)
|
|
71
|
+
|
|
72
|
+
case nodes.footnotes_element:
|
|
73
|
+
return node.attrs.collateByKind === 'footnote' ? 'Footnotes' : 'Endnotes' // TODO
|
|
74
|
+
|
|
75
|
+
case nodes.list:
|
|
76
|
+
case nodes.blockquote_element:
|
|
77
|
+
case nodes.footnote:
|
|
78
|
+
case nodes.pullquote_element:
|
|
79
|
+
return snippetOfNodeType(node, nodes.paragraph)
|
|
80
|
+
|
|
81
|
+
case nodes.embed:
|
|
82
|
+
case nodes.figure_element:
|
|
83
|
+
case nodes.table_element:
|
|
84
|
+
case nodes.equation_element:
|
|
85
|
+
case nodes.listing_element:
|
|
86
|
+
case nodes.multi_graphic_figure_element:
|
|
87
|
+
case nodes.image_element:
|
|
88
|
+
case nodes.hero_image:
|
|
89
|
+
case nodes.headshot_grid:
|
|
90
|
+
case nodes.box_element:
|
|
91
|
+
case nodes.supplements:
|
|
92
|
+
case nodes.attachments:
|
|
93
|
+
return ''
|
|
94
|
+
|
|
95
|
+
default:
|
|
96
|
+
return textSnippet(node)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export const nodeTitlePlaceholder = (nodeType: NodeType) => {
|
|
101
|
+
const nodes = schema.nodes
|
|
102
|
+
|
|
103
|
+
switch (nodeType) {
|
|
104
|
+
case nodes.manuscript:
|
|
105
|
+
return 'Untitled Manuscript'
|
|
106
|
+
|
|
107
|
+
case nodes.section:
|
|
108
|
+
return 'Untitled Section'
|
|
109
|
+
|
|
110
|
+
case nodes.bibliography_section:
|
|
111
|
+
return 'Bibliography'
|
|
112
|
+
|
|
113
|
+
default:
|
|
114
|
+
return nodeNames.get(nodeType) || ''
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2019 Atypon Systems LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
GROUP_ELEMENT,
|
|
19
|
+
GROUP_EXECUTABLE,
|
|
20
|
+
GROUP_SECTION,
|
|
21
|
+
hasGroup,
|
|
22
|
+
ManuscriptNode,
|
|
23
|
+
ManuscriptNodeType,
|
|
24
|
+
Nodes,
|
|
25
|
+
} from '../schema'
|
|
26
|
+
|
|
27
|
+
export const isExecutableNodeType = (type: ManuscriptNodeType) =>
|
|
28
|
+
hasGroup(type, GROUP_EXECUTABLE)
|
|
29
|
+
|
|
30
|
+
export const isElementNodeType = (type: ManuscriptNodeType) =>
|
|
31
|
+
hasGroup(type, GROUP_ELEMENT)
|
|
32
|
+
|
|
33
|
+
export const isSectionNodeType = (type: ManuscriptNodeType) =>
|
|
34
|
+
hasGroup(type, GROUP_SECTION)
|
|
35
|
+
|
|
36
|
+
export const isNodeType = <T extends ManuscriptNode>(
|
|
37
|
+
node: ManuscriptNode,
|
|
38
|
+
type: Nodes
|
|
39
|
+
): node is T => node.type === node.type.schema.nodes[type]
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2025 Atypon Systems LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { Node, NodeType } from 'prosemirror-model'
|
|
17
|
+
import { findChildrenByType } from 'prosemirror-utils'
|
|
18
|
+
|
|
19
|
+
import { TitleNode } from '../schema'
|
|
20
|
+
|
|
21
|
+
export interface ValidationError {
|
|
22
|
+
code: string
|
|
23
|
+
id?: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ValidationResult {
|
|
27
|
+
isValid: boolean
|
|
28
|
+
errors: ValidationError[]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const VALIDATION_ERROR_CODES = {
|
|
32
|
+
EMPTY_TITLE: 'EMPTY_TITLE',
|
|
33
|
+
} as const
|
|
34
|
+
|
|
35
|
+
const validateTitleNode = (node: TitleNode): ValidationError[] => {
|
|
36
|
+
const errors: ValidationError[] = []
|
|
37
|
+
if (!node.textContent) {
|
|
38
|
+
errors.push({
|
|
39
|
+
code: VALIDATION_ERROR_CODES.EMPTY_TITLE,
|
|
40
|
+
id: node.attrs.id,
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
return errors
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const validateNode = (
|
|
47
|
+
nodeType: NodeType,
|
|
48
|
+
node: Node,
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
50
|
+
doc: Node
|
|
51
|
+
): ValidationError[] => {
|
|
52
|
+
switch (nodeType.name) {
|
|
53
|
+
case 'title':
|
|
54
|
+
return validateTitleNode(node as TitleNode)
|
|
55
|
+
default:
|
|
56
|
+
return []
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const validateManuscriptNode = (doc: Node): ValidationResult => {
|
|
61
|
+
const schema = doc.type.schema
|
|
62
|
+
const validatableTypes = ['title']
|
|
63
|
+
const errors: ValidationError[] = []
|
|
64
|
+
|
|
65
|
+
validatableTypes.forEach((typeName) => {
|
|
66
|
+
const nodeType = schema.nodes[typeName]
|
|
67
|
+
if (nodeType) {
|
|
68
|
+
const nodes = findChildrenByType(doc, nodeType).map(
|
|
69
|
+
(result) => result.node
|
|
70
|
+
)
|
|
71
|
+
nodes.forEach((node) => {
|
|
72
|
+
const nodeErrors = validateNode(nodeType, node, doc)
|
|
73
|
+
errors.push(...nodeErrors)
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
isValid: errors.length === 0,
|
|
80
|
+
errors,
|
|
81
|
+
}
|
|
82
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2019 Atypon Systems LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export type JSONProsemirrorNode = {
|
|
18
|
+
type: string
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
attrs: { [key: string]: any }
|
|
21
|
+
content?: JSONProsemirrorNode[]
|
|
22
|
+
text?: string
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
+
marks?: Array<{ type: string; attrs?: Record<string, any> }>
|
|
25
|
+
}
|
package/src/version.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VERSION = "4.4.1";
|