@manuscripts/transform 4.3.52 → 4.4.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.
Files changed (175) hide show
  1. package/dist/cjs/jats/__tests__/jats-roundtrip.test.js +3 -3
  2. package/dist/cjs/schema/types.js +18 -0
  3. package/dist/cjs/version.js +1 -1
  4. package/dist/es/jats/__tests__/jats-roundtrip.test.js +3 -3
  5. package/dist/es/schema/types.js +17 -0
  6. package/dist/es/version.js +1 -1
  7. package/dist/types/jats/__tests__/utils.d.ts +1 -1
  8. package/dist/types/schema/types.d.ts +16 -0
  9. package/dist/types/version.d.ts +1 -1
  10. package/package.json +22 -21
  11. package/src/errors.ts +28 -0
  12. package/src/getVersion.ts +21 -0
  13. package/src/index.ts +28 -0
  14. package/src/jats/__tests__/__fixtures__/debug-example.xml +136 -0
  15. package/src/jats/__tests__/__fixtures__/jats-abstract-no-body.xml +163 -0
  16. package/src/jats/__tests__/__fixtures__/jats-citations.xml +472 -0
  17. package/src/jats/__tests__/__fixtures__/jats-comments.xml +46 -0
  18. package/src/jats/__tests__/__fixtures__/jats-document.xml +134 -0
  19. package/src/jats/__tests__/__fixtures__/jats-example-doc.xml +1235 -0
  20. package/src/jats/__tests__/__fixtures__/jats-example-front-only.xml +26 -0
  21. package/src/jats/__tests__/__fixtures__/jats-example-full.xml +209 -0
  22. package/src/jats/__tests__/__fixtures__/jats-example-no-back.xml +156 -0
  23. package/src/jats/__tests__/__fixtures__/jats-example-no-body.xml +91 -0
  24. package/src/jats/__tests__/__fixtures__/jats-example.xml +221 -0
  25. package/src/jats/__tests__/__fixtures__/jats-fn-group.xml +60 -0
  26. package/src/jats/__tests__/__fixtures__/jats-import-no-refs.xml +1077 -0
  27. package/src/jats/__tests__/__fixtures__/jats-import.xml +1561 -0
  28. package/src/jats/__tests__/__fixtures__/jats-roundtrip.xml +133 -0
  29. package/src/jats/__tests__/__fixtures__/jats-tables-example.xml +2043 -0
  30. package/src/jats/__tests__/__fixtures__/math-fragment.xml +12 -0
  31. package/src/jats/__tests__/__snapshots__/citeproc.test.ts.snap +57 -0
  32. package/src/jats/__tests__/__snapshots__/create-article-node.test.ts.snap +65 -0
  33. package/src/jats/__tests__/__snapshots__/jats-exporter.test.ts.snap +7 -0
  34. package/src/jats/__tests__/__snapshots__/jats-importer.test.ts.snap +59605 -0
  35. package/src/jats/__tests__/__snapshots__/jats-roundtrip.test.ts.snap +18 -0
  36. package/src/jats/__tests__/citations.ts +25 -0
  37. package/src/jats/__tests__/citeproc.test.ts +195 -0
  38. package/src/jats/__tests__/create-article-node.test.ts +29 -0
  39. package/src/jats/__tests__/data/section-categories.ts +212 -0
  40. package/src/jats/__tests__/files.ts +24 -0
  41. package/src/jats/__tests__/jats-exporter.test.ts +223 -0
  42. package/src/jats/__tests__/jats-importer.test.ts +567 -0
  43. package/src/jats/__tests__/jats-roundtrip.test.ts +66 -0
  44. package/src/jats/__tests__/utils.ts +90 -0
  45. package/src/jats/exporter/citeproc.ts +265 -0
  46. package/src/jats/exporter/jats-exporter.ts +2090 -0
  47. package/src/jats/exporter/jats-versions.ts +50 -0
  48. package/src/jats/exporter/labels.ts +101 -0
  49. package/src/jats/importer/create-article-node.ts +52 -0
  50. package/src/jats/importer/jats-comments.ts +111 -0
  51. package/src/jats/importer/jats-dom-parser.ts +1260 -0
  52. package/src/jats/importer/jats-parser-utils.ts +234 -0
  53. package/src/jats/importer/jats-transformations.ts +591 -0
  54. package/src/jats/importer/parse-jats-article.ts +106 -0
  55. package/src/jats/index.ts +21 -0
  56. package/src/jats/types.ts +16 -0
  57. package/src/lib/__tests__/footnotes.test.ts +36 -0
  58. package/src/lib/citeproc.ts +30 -0
  59. package/src/lib/credit-roles.ts +91 -0
  60. package/src/lib/deafults.ts +17 -0
  61. package/src/lib/footnotes.ts +85 -0
  62. package/src/lib/html.ts +56 -0
  63. package/src/lib/section-categories.ts +27 -0
  64. package/src/lib/utils.ts +145 -0
  65. package/src/lib/xml.ts +28 -0
  66. package/src/schema/__tests__/docs.ts +1911 -0
  67. package/src/schema/__tests__/groups.test.ts +61 -0
  68. package/src/schema/__tests__/migration.test.ts +23 -0
  69. package/src/schema/groups.ts +36 -0
  70. package/src/schema/index.ts +286 -0
  71. package/src/schema/marks.ts +254 -0
  72. package/src/schema/migration/migrate.ts +77 -0
  73. package/src/schema/migration/migration-script.ts +26 -0
  74. package/src/schema/migration/migration-scripts/1.2.5.ts +44 -0
  75. package/src/schema/migration/migration-scripts/2.3.22.ts +52 -0
  76. package/src/schema/migration/migration-scripts/3.0.12.ts +33 -0
  77. package/src/schema/migration/migration-scripts/3.0.21.ts +50 -0
  78. package/src/schema/migration/migration-scripts/3.0.30.ts +65 -0
  79. package/src/schema/migration/migration-scripts/3.0.31.ts +40 -0
  80. package/src/schema/migration/migration-scripts/3.0.41.ts +37 -0
  81. package/src/schema/migration/migration-scripts/3.0.55.ts +42 -0
  82. package/src/schema/migration/migration-scripts/3.0.56.ts +114 -0
  83. package/src/schema/migration/migration-scripts/4.2.13.ts +37 -0
  84. package/src/schema/migration/migration-scripts/4.2.15.ts +48 -0
  85. package/src/schema/migration/migration-scripts/4.3.23.ts +55 -0
  86. package/src/schema/migration/migration-scripts/4.3.34.ts +132 -0
  87. package/src/schema/migration/migration-scripts/4.3.35.ts +41 -0
  88. package/src/schema/migration/migration-scripts/index.ts +49 -0
  89. package/src/schema/nodes/abstracts.ts +29 -0
  90. package/src/schema/nodes/affiliation.ts +88 -0
  91. package/src/schema/nodes/affiliations.ts +30 -0
  92. package/src/schema/nodes/alt_text.ts +36 -0
  93. package/src/schema/nodes/alt_title.ts +40 -0
  94. package/src/schema/nodes/alt_titles_section.ts +58 -0
  95. package/src/schema/nodes/attachment.ts +46 -0
  96. package/src/schema/nodes/attachments.ts +45 -0
  97. package/src/schema/nodes/attribution.ts +38 -0
  98. package/src/schema/nodes/author_notes.ts +44 -0
  99. package/src/schema/nodes/award.ts +52 -0
  100. package/src/schema/nodes/awards.ts +45 -0
  101. package/src/schema/nodes/backmatter.ts +31 -0
  102. package/src/schema/nodes/bibliography_element.ts +58 -0
  103. package/src/schema/nodes/bibliography_item.ts +108 -0
  104. package/src/schema/nodes/bibliography_section.ts +60 -0
  105. package/src/schema/nodes/blockquote_element.ts +79 -0
  106. package/src/schema/nodes/body.ts +29 -0
  107. package/src/schema/nodes/box_element.ts +67 -0
  108. package/src/schema/nodes/caption.ts +67 -0
  109. package/src/schema/nodes/caption_title.ts +67 -0
  110. package/src/schema/nodes/citation.ts +70 -0
  111. package/src/schema/nodes/comment.ts +50 -0
  112. package/src/schema/nodes/comments.ts +28 -0
  113. package/src/schema/nodes/contributor.ts +87 -0
  114. package/src/schema/nodes/contributors.ts +40 -0
  115. package/src/schema/nodes/core_section.ts +27 -0
  116. package/src/schema/nodes/corresp.ts +49 -0
  117. package/src/schema/nodes/cross_reference.ts +64 -0
  118. package/src/schema/nodes/doc.ts +21 -0
  119. package/src/schema/nodes/embed.ts +55 -0
  120. package/src/schema/nodes/equation.ts +65 -0
  121. package/src/schema/nodes/equation_element.ts +61 -0
  122. package/src/schema/nodes/figure.ts +65 -0
  123. package/src/schema/nodes/figure_element.ts +73 -0
  124. package/src/schema/nodes/footnote.ts +95 -0
  125. package/src/schema/nodes/footnotes_element.ts +69 -0
  126. package/src/schema/nodes/footnotes_section.ts +61 -0
  127. package/src/schema/nodes/general_table_footnote.ts +42 -0
  128. package/src/schema/nodes/graphical_abstract_section.ts +62 -0
  129. package/src/schema/nodes/hard_break.ts +36 -0
  130. package/src/schema/nodes/hero_image.ts +46 -0
  131. package/src/schema/nodes/highlight_marker.ts +68 -0
  132. package/src/schema/nodes/image_element.ts +49 -0
  133. package/src/schema/nodes/inline_equation.ts +68 -0
  134. package/src/schema/nodes/inline_footnote.ts +66 -0
  135. package/src/schema/nodes/keyword.ts +61 -0
  136. package/src/schema/nodes/keyword_group.ts +63 -0
  137. package/src/schema/nodes/keywords.ts +59 -0
  138. package/src/schema/nodes/keywords_element.ts +64 -0
  139. package/src/schema/nodes/link.ts +79 -0
  140. package/src/schema/nodes/list.ts +134 -0
  141. package/src/schema/nodes/listing.ts +91 -0
  142. package/src/schema/nodes/listing_element.ts +61 -0
  143. package/src/schema/nodes/long_desc.ts +36 -0
  144. package/src/schema/nodes/manuscript.ts +86 -0
  145. package/src/schema/nodes/missing_figure.ts +59 -0
  146. package/src/schema/nodes/paragraph.ts +77 -0
  147. package/src/schema/nodes/placeholder.ts +62 -0
  148. package/src/schema/nodes/placeholder_element.ts +60 -0
  149. package/src/schema/nodes/pullquote_element.ts +81 -0
  150. package/src/schema/nodes/quote_image.ts +64 -0
  151. package/src/schema/nodes/section.ts +69 -0
  152. package/src/schema/nodes/section_label.ts +39 -0
  153. package/src/schema/nodes/section_title.ts +58 -0
  154. package/src/schema/nodes/subtitle.ts +40 -0
  155. package/src/schema/nodes/subtitles.ts +51 -0
  156. package/src/schema/nodes/supplement.ts +77 -0
  157. package/src/schema/nodes/supplements.ts +60 -0
  158. package/src/schema/nodes/table.ts +144 -0
  159. package/src/schema/nodes/table_col.ts +76 -0
  160. package/src/schema/nodes/table_element.ts +67 -0
  161. package/src/schema/nodes/table_element_footer.ts +42 -0
  162. package/src/schema/nodes/text.ts +31 -0
  163. package/src/schema/nodes/title.ts +43 -0
  164. package/src/schema/nodes/trans_abstract.ts +58 -0
  165. package/src/schema/nodes/trans_graphical_abstract.ts +67 -0
  166. package/src/schema/types.ts +240 -0
  167. package/src/tests.ts +33 -0
  168. package/src/transformer/id.ts +23 -0
  169. package/src/transformer/index.ts +21 -0
  170. package/src/transformer/node-names.ts +73 -0
  171. package/src/transformer/node-title.ts +111 -0
  172. package/src/transformer/node-types.ts +39 -0
  173. package/src/transformer/node-validator.ts +82 -0
  174. package/src/types.ts +25 -0
  175. package/src/version.ts +1 -0
@@ -0,0 +1,58 @@
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
+
17
+ import { NodeSpec } from 'prosemirror-model'
18
+
19
+ import { schema } from '../index'
20
+ import type { ManuscriptNode } from '../types'
21
+
22
+ export interface TransAbstractAttrs {
23
+ id: string
24
+ lang: string
25
+ category: string
26
+ }
27
+
28
+ export interface TransAbstractNode extends ManuscriptNode {
29
+ attrs: TransAbstractAttrs
30
+ }
31
+
32
+ export const transAbstract: NodeSpec = {
33
+ content: 'section_title (paragraph | element)* sections*',
34
+ attrs: {
35
+ id: { default: '' },
36
+ lang: { default: '' },
37
+ category: { default: '' },
38
+ dataTracked: { default: null },
39
+ },
40
+ group: 'block sections',
41
+ selectable: false,
42
+ toDOM: (node) => {
43
+ const { id, lang } = node.attrs
44
+ return [
45
+ 'section',
46
+ {
47
+ id,
48
+ lang,
49
+ class: 'trans-abstract',
50
+ },
51
+ 0,
52
+ ]
53
+ },
54
+ }
55
+
56
+ export const isTransAbstractNode = (
57
+ node: ManuscriptNode
58
+ ): node is TransAbstractNode => node.type === schema.nodes.trans_abstract
@@ -0,0 +1,67 @@
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
+
17
+ import { NodeSpec } from 'prosemirror-model'
18
+
19
+ import { schema } from '../index'
20
+ import type { ManuscriptNode } from '../types'
21
+
22
+ export interface TransGraphicalAbstractAttrs {
23
+ id: string
24
+ lang: string
25
+ category: string
26
+ }
27
+
28
+ export interface TransGraphicalAbstractNode extends ManuscriptNode {
29
+ attrs: TransGraphicalAbstractAttrs
30
+ }
31
+
32
+ export const transGraphicalAbstract: NodeSpec = {
33
+ content: 'section_title (figure_element | placeholder)',
34
+ attrs: {
35
+ id: { default: '' },
36
+ lang: { default: '' },
37
+ category: { default: '' },
38
+ dataTracked: { default: null },
39
+ },
40
+ group: 'block sections',
41
+ selectable: false,
42
+ parseDOM: [
43
+ {
44
+ tag: 'section.trans-graphical-abstract',
45
+ },
46
+ ],
47
+ toDOM: (node) => {
48
+ const transGraphicalAbstractNode = node as TransGraphicalAbstractNode
49
+ const { id, lang } = transGraphicalAbstractNode.attrs
50
+
51
+ return [
52
+ 'section',
53
+ {
54
+ id,
55
+ lang,
56
+ class: 'trans-graphical-abstract',
57
+ spellcheck: 'false',
58
+ },
59
+ 0,
60
+ ]
61
+ },
62
+ }
63
+
64
+ export const isTransGraphicalAbstractNode = (
65
+ node: ManuscriptNode
66
+ ): node is TransGraphicalAbstractNode =>
67
+ node.type === schema.nodes.trans_graphical_abstract
@@ -0,0 +1,240 @@
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
+ Fragment,
19
+ Mark as ProsemirrorMark,
20
+ MarkType,
21
+ Node as ProsemirrorNode,
22
+ NodeSpec,
23
+ NodeType,
24
+ ParseRule,
25
+ ResolvedPos,
26
+ Schema,
27
+ Slice,
28
+ } from 'prosemirror-model'
29
+ import {
30
+ EditorState,
31
+ NodeSelection,
32
+ Plugin,
33
+ TextSelection,
34
+ Transaction,
35
+ } from 'prosemirror-state'
36
+ import { EditorView, NodeView } from 'prosemirror-view'
37
+
38
+ export type Marks =
39
+ | 'bold'
40
+ | 'code'
41
+ | 'italic'
42
+ | 'smallcaps'
43
+ | 'strikethrough'
44
+ | 'styled'
45
+ | 'subscript'
46
+ | 'superscript'
47
+ | 'underline'
48
+ | 'tracked_insert'
49
+ | 'tracked_delete'
50
+
51
+ export type Nodes =
52
+ | 'attribution'
53
+ | 'bibliography_item'
54
+ | 'bibliography_element'
55
+ | 'bibliography_section'
56
+ | 'blockquote_element'
57
+ | 'quote_image'
58
+ | 'list'
59
+ | 'caption'
60
+ | 'caption_title'
61
+ | 'comment'
62
+ | 'comments'
63
+ | 'citation'
64
+ | 'cross_reference'
65
+ | 'doc'
66
+ | 'equation'
67
+ | 'equation_element'
68
+ | 'figure'
69
+ | 'graphical_abstract_section'
70
+ | 'figure_element'
71
+ | 'footnote'
72
+ | 'footnotes_element'
73
+ | 'footnotes_section'
74
+ | 'hard_break'
75
+ | 'highlight_marker'
76
+ | 'inline_equation'
77
+ | 'inline_footnote'
78
+ | 'keyword'
79
+ | 'keywords_element'
80
+ | 'keyword_group'
81
+ | 'keywords'
82
+ | 'link'
83
+ | 'list_item'
84
+ | 'listing'
85
+ | 'listing_element'
86
+ | 'manuscript'
87
+ | 'abstracts'
88
+ | 'body'
89
+ | 'backmatter'
90
+ | 'missing_figure'
91
+ | 'paragraph'
92
+ | 'placeholder'
93
+ | 'placeholder_element'
94
+ | 'pullquote_element'
95
+ | 'section'
96
+ | 'section_label'
97
+ | 'section_title'
98
+ | 'section_title_plain'
99
+ | 'table'
100
+ | 'table_cell'
101
+ | 'table_element'
102
+ | 'table_row'
103
+ | 'table_colgroup'
104
+ | 'table_col'
105
+ | 'table_header'
106
+ | 'text'
107
+ | 'text_block'
108
+ | 'affiliation'
109
+ | 'contributor'
110
+ | 'table_element_footer'
111
+ | 'title'
112
+ | 'affiliations'
113
+ | 'contributors'
114
+ | 'supplements'
115
+ | 'supplement'
116
+ | 'author_notes'
117
+ | 'corresp'
118
+ | 'general_table_footnote'
119
+ | 'box_element'
120
+ | 'awards'
121
+ | 'award'
122
+ | 'embed'
123
+ | 'image_element'
124
+ | 'attachment'
125
+ | 'attachments'
126
+ | 'alt_title'
127
+ | 'alt_text'
128
+ | 'alt_titles'
129
+ | 'long_desc'
130
+ | 'hero_image'
131
+ | 'trans_abstract'
132
+ | 'trans_graphical_abstract'
133
+ | 'subtitle'
134
+ | 'subtitles'
135
+
136
+ export type ManuscriptSchema = Schema<Nodes, Marks>
137
+
138
+ export type ManuscriptEditorState = EditorState
139
+ export type ManuscriptEditorView = EditorView
140
+ export type ManuscriptFragment = Fragment
141
+ export type ManuscriptMark = ProsemirrorMark
142
+ export type ManuscriptNode = ProsemirrorNode
143
+ export type ManuscriptNodeSelection = NodeSelection
144
+ export type ManuscriptTextSelection = TextSelection
145
+ export type ManuscriptMarkType = MarkType
146
+ export type ManuscriptNodeType = NodeType
147
+ export type ManuscriptNodeView = NodeView
148
+ export type ManuscriptResolvedPos = ResolvedPos
149
+ export type ManuscriptPlugin = Plugin
150
+ export type ManuscriptSlice = Slice
151
+ export type ManuscriptTransaction = Transaction
152
+
153
+ export interface TableNodeSpec extends NodeSpec {
154
+ tableRole: string
155
+ }
156
+
157
+ export type DataTrackedAttrs = {
158
+ id: string
159
+ status: string
160
+ operation: string
161
+ userID: string
162
+ createdAt: number
163
+ }
164
+
165
+ export type SectionGroup =
166
+ | 'abstracts'
167
+ | 'body'
168
+ | 'backmatter'
169
+ | 'abstracts-graphic'
170
+
171
+ export type SectionCategory = {
172
+ id: string
173
+ synonyms: string[]
174
+ label?: string // for display menu purposes, if not provided, the first title will be used
175
+ titles: [string, ...string[]]
176
+ group?: SectionGroup
177
+ isUnique: boolean
178
+ }
179
+
180
+ export type ManuscriptTemplate = {
181
+ _id: string
182
+ bundle: string
183
+ title: string
184
+ sectionCategories: SectionCategory[]
185
+ articleType: string
186
+ hiddenNodeTypes?: string[]
187
+ }
188
+
189
+ export interface UserProfile {
190
+ _id: string
191
+ userID: string
192
+ given?: string
193
+ family?: string
194
+ }
195
+
196
+ export interface Project {
197
+ _id: string
198
+ owners: string[]
199
+ writers: string[]
200
+ editors?: string[]
201
+ annotators?: string[]
202
+ proofers?: string[]
203
+ viewers: string[]
204
+ updatedAt: number
205
+ }
206
+
207
+ export interface Bundle {
208
+ _id: string
209
+ csl: {
210
+ _id: string
211
+ }
212
+ }
213
+
214
+ export enum ManuscriptActions {
215
+ handleSuggestion = 'handleSuggestion',
216
+ rejectOwnSuggestion = 'rejectOwnSuggestion',
217
+ handleOwnComments = 'handleOwnComments',
218
+ handleOthersComments = 'handleOthersComments',
219
+ resolveOwnComment = 'resolveOwnComment',
220
+ resolveOthersComment = 'resolveOthersComment',
221
+ createComment = 'createComment',
222
+ canEditFiles = 'canEditFiles',
223
+ editArticle = 'editArticle',
224
+ formatArticle = 'formatArticle',
225
+ editMetadata = 'editMetadata',
226
+ editCitationsAndRefs = 'editCitationsAndRefs',
227
+ seeEditorToolbar = 'seeEditorToolbar',
228
+ seeReferencesButtons = 'seeReferencesButtons',
229
+ }
230
+
231
+ export type MarkRule = ParseRule & { mark: Marks | null }
232
+
233
+ export type NodeRule = ParseRule & { node?: Nodes | null }
234
+
235
+ export function isNodeOfType<T extends ManuscriptNode>(
236
+ node: ManuscriptNode,
237
+ type: NodeType
238
+ ): node is T {
239
+ return node.type === type
240
+ }
package/src/tests.ts ADDED
@@ -0,0 +1,33 @@
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 { v4 as uuid } from 'uuid'
18
+
19
+ const supportedCommands: string[] = []
20
+
21
+ Object.defineProperty(document, 'queryCommandSupported', {
22
+ value: (cmd: string) => supportedCommands.includes(cmd),
23
+ })
24
+
25
+ Object.defineProperty(document, 'execCommand', {
26
+ value: (cmd: string) => supportedCommands.includes(cmd),
27
+ })
28
+
29
+ if (!window.URL.createObjectURL) {
30
+ Object.defineProperty(window.URL, 'createObjectURL', {
31
+ value: vi.fn(() => 'blob:https://localhost/' + uuid()),
32
+ })
33
+ }
@@ -0,0 +1,23 @@
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 { v4 as uuid } from 'uuid'
18
+
19
+ import { ManuscriptNodeType } from '../schema'
20
+ import { typeName } from './node-names'
21
+
22
+ export const generateNodeID = (type: ManuscriptNodeType) =>
23
+ `MP${typeName(type)}:${uuid()}`
@@ -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,73 @@
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.table_element, 'Table'],
36
+ [schema.nodes.table_cell, 'Table Cell'],
37
+ [schema.nodes.table_col, 'Table Column'],
38
+ [schema.nodes.table_row, 'Table Row'],
39
+ [schema.nodes.table_header, 'Table Header'],
40
+ [schema.nodes.general_table_footnote, 'General Table note'],
41
+ [schema.nodes.table_element_footer, 'Table Footer'],
42
+ [schema.nodes.embed, 'Media'],
43
+ [schema.nodes.equation, 'Equation'],
44
+ [schema.nodes.inline_equation, 'Inline Equation'],
45
+ [schema.nodes.inline_footnote, 'Footnote Reference'],
46
+ [schema.nodes.footnote, 'Footnote'],
47
+ [schema.nodes.footnotes_element, 'Notes'],
48
+ [schema.nodes.footnotes_section, 'Footnotes Section'],
49
+ [schema.nodes.list, 'List'],
50
+ [schema.nodes.list_item, 'List Item'],
51
+ [schema.nodes.manuscript, 'Manuscript'],
52
+ [schema.nodes.paragraph, 'Paragraph'],
53
+ [schema.nodes.text_block, 'Paragraph'],
54
+ [schema.nodes.section, 'Section'],
55
+ [schema.nodes.graphical_abstract_section, 'Graphical Abstract'],
56
+ [schema.nodes.trans_abstract, 'Trans Abstract'],
57
+ [schema.nodes.trans_graphical_abstract, 'Trans Graphical Abstract'],
58
+ [schema.nodes.section_title, 'Section Title'],
59
+ [schema.nodes.section_title_plain, 'Section Title'],
60
+ [schema.nodes.table, 'Table'],
61
+ [schema.nodes.table_element, 'Table'],
62
+ [schema.nodes.blockquote_element, 'Block Quote'],
63
+ [schema.nodes.pullquote_element, 'Pull Quote'],
64
+ [schema.nodes.box_element, 'Box'],
65
+ [schema.nodes.supplements, 'Supplements'],
66
+ [schema.nodes.attachments, 'Main Document'],
67
+ ])
68
+
69
+ export const typeName = (type: ManuscriptNodeType) =>
70
+ type.name
71
+ .split('_')
72
+ .map((w) => w.charAt(0).toUpperCase() + w.slice(1))
73
+ .join('')
@@ -0,0 +1,111 @@
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 {
33
+ text += ' '
34
+ }
35
+ })
36
+
37
+ return text.substring(0, max)
38
+ }
39
+
40
+ const snippetOfNodeType = (
41
+ node: ManuscriptNode,
42
+ nodeType: ManuscriptNodeType
43
+ ) => {
44
+ for (const child of iterateChildren(node, true)) {
45
+ if (child.type === nodeType) {
46
+ return textSnippet(child)
47
+ }
48
+ }
49
+
50
+ return null
51
+ }
52
+
53
+ export const nodeTitle = (node: ManuscriptNode) => {
54
+ const nodes = schema.nodes
55
+
56
+ switch (node.type) {
57
+ case nodes.manuscript:
58
+ return snippetOfNodeType(node, nodes.title)
59
+
60
+ case nodes.section:
61
+ case nodes.bibliography_section:
62
+ case nodes.footnotes_section:
63
+ case nodes.keywords:
64
+ case nodes.graphical_abstract_section:
65
+ case nodes.trans_graphical_abstract:
66
+ return snippetOfNodeType(node, nodes.section_title)
67
+
68
+ case nodes.footnotes_element:
69
+ return node.attrs.collateByKind === 'footnote' ? 'Footnotes' : 'Endnotes' // TODO
70
+
71
+ case nodes.list:
72
+ case nodes.blockquote_element:
73
+ case nodes.footnote:
74
+ case nodes.pullquote_element:
75
+ return snippetOfNodeType(node, nodes.paragraph)
76
+
77
+ case nodes.embed:
78
+ case nodes.figure_element:
79
+ case nodes.table_element:
80
+ case nodes.equation_element:
81
+ case nodes.listing_element:
82
+ case nodes.multi_graphic_figure_element:
83
+ case nodes.image_element:
84
+ case nodes.hero_image:
85
+ case nodes.box_element:
86
+ case nodes.supplements:
87
+ case nodes.attachments:
88
+ return ''
89
+
90
+ default:
91
+ return textSnippet(node)
92
+ }
93
+ }
94
+
95
+ export const nodeTitlePlaceholder = (nodeType: NodeType) => {
96
+ const nodes = schema.nodes
97
+
98
+ switch (nodeType) {
99
+ case nodes.manuscript:
100
+ return 'Untitled Manuscript'
101
+
102
+ case nodes.section:
103
+ return 'Untitled Section'
104
+
105
+ case nodes.bibliography_section:
106
+ return 'Bibliography'
107
+
108
+ default:
109
+ return nodeNames.get(nodeType) || ''
110
+ }
111
+ }
@@ -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]