@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,77 @@
1
+ /*!
2
+ * © 2024 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 { cloneDeep } from 'lodash'
17
+ import semver from 'semver'
18
+
19
+ import { JSONProsemirrorNode } from '../../types'
20
+ import { schema } from '..'
21
+ import { MigrationScript } from './migration-script'
22
+ import migrationScripts from './migration-scripts'
23
+
24
+ export default function migrate(
25
+ oldDoc: JSONProsemirrorNode,
26
+ migrationScript: MigrationScript['migrateNode']
27
+ ) {
28
+ function migrateNode(node: JSONProsemirrorNode) {
29
+ const migrated = migrationScript(node, oldDoc)
30
+ if (migrated.content) {
31
+ migrated.content = migrated.content.map((m) => migrateNode(m))
32
+ }
33
+ return migrated
34
+ }
35
+
36
+ return migrateNode(oldDoc)
37
+ }
38
+
39
+ export function migrateFor(oldDoc: JSONProsemirrorNode, baseVersion: string) {
40
+ const migrationScripts = ensureVersionAscOrder()
41
+ let migratedDoc = cloneDeep(oldDoc)
42
+
43
+ for (let i = 0; i < migrationScripts.length; i++) {
44
+ const script = migrationScripts[i]
45
+ if (semver.lt(script.fromVersion, baseVersion)) {
46
+ continue
47
+ }
48
+ console.log('Migrating doc with script to version ' + script.toVersion)
49
+ migratedDoc = migrate(migratedDoc, (node, oldDoc) =>
50
+ script.migrateNode(node, oldDoc)
51
+ )
52
+ }
53
+
54
+ return testDoc(migratedDoc, baseVersion)
55
+ // now find all versions that we have to migrate that do from version
56
+ }
57
+
58
+ const ensureVersionAscOrder = () =>
59
+ migrationScripts.sort((a, b) => semver.compare(a.toVersion, b.toVersion))
60
+
61
+ function testDoc(doc: JSONProsemirrorNode, fromVersion: string) {
62
+ try {
63
+ // not that even if the doc doesn't really require a migration but the schema changed it still needs to go through migration process
64
+ // this is needed to make sure that DB version of it is in sync with FE so the updates can be correctly exchanged
65
+ const resultDoc = schema.nodeFromJSON(doc)
66
+
67
+ resultDoc.check()
68
+ return resultDoc
69
+ } catch (e) {
70
+ const error =
71
+ 'Migration application from version ' +
72
+ fromVersion +
73
+ ' did not produce a valid document with ' +
74
+ e
75
+ throw new Error(error)
76
+ }
77
+ }
@@ -0,0 +1,26 @@
1
+ /*!
2
+ * © 2024 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 { JSONProsemirrorNode } from '../../types'
18
+
19
+ export interface MigrationScript {
20
+ fromVersion: string
21
+ toVersion: string
22
+ migrateNode: (
23
+ node: JSONProsemirrorNode,
24
+ doc: JSONProsemirrorNode
25
+ ) => JSONProsemirrorNode
26
+ }
@@ -0,0 +1,44 @@
1
+ /*!
2
+ * © 2024 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 { JSONProsemirrorNode } from '../../../types'
18
+ import { MigrationScript } from '../migration-script'
19
+
20
+ // @NOTE - this is an example migration
21
+ class Migration125 implements MigrationScript {
22
+ fromVersion = '1.2.3'
23
+ toVersion = '1.2.5'
24
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
25
+ migrateNode(node: JSONProsemirrorNode, doc: JSONProsemirrorNode) {
26
+ /*
27
+ NOTE - if schema is used in this function, it is imported from the current version of the package
28
+ in pratical terms it means that it's always the latest schema and you can't rely on that it will correspond the version in
29
+ which you created the migration script. That would also mean that you shouldn't rely on schema for migrations
30
+ */
31
+ if (node.type === 'paragraph') {
32
+ return {
33
+ ...node,
34
+ attrs: {
35
+ ...node.attrs,
36
+ someNewFanctAttribute: 'example-value',
37
+ },
38
+ }
39
+ }
40
+ return node
41
+ }
42
+ }
43
+
44
+ export default Migration125
@@ -0,0 +1,52 @@
1
+ /*!
2
+ * © 2024 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 { JSONProsemirrorNode } from '../../../types'
17
+ import { MigrationScript } from '../migration-script'
18
+
19
+ class Migration2322 implements MigrationScript {
20
+ fromVersion = '2.3.21'
21
+ toVersion = '2.3.22'
22
+
23
+ migrateNode(node: JSONProsemirrorNode): JSONProsemirrorNode {
24
+ if (node.type === 'table_element' && Array.isArray(node.content)) {
25
+ let figcaptionNode = null
26
+ const remainingContent = []
27
+
28
+ for (const child of node.content) {
29
+ if (child.type === 'figcaption') {
30
+ figcaptionNode = child
31
+ } else {
32
+ remainingContent.push(child)
33
+ }
34
+ }
35
+
36
+ // Create the new content array
37
+ const newContent = figcaptionNode
38
+ ? [figcaptionNode, ...remainingContent]
39
+ : remainingContent
40
+
41
+ // Return the updated node with the new content order
42
+ return {
43
+ ...node,
44
+ content: newContent,
45
+ }
46
+ }
47
+
48
+ return node
49
+ }
50
+ }
51
+
52
+ export default Migration2322
@@ -0,0 +1,33 @@
1
+ /*!
2
+ * © 2024 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 { JSONProsemirrorNode } from '../../../types'
17
+ import { MigrationScript } from '../migration-script'
18
+
19
+ export class Migration3012 implements MigrationScript {
20
+ fromVersion = '3.0.12'
21
+ toVersion = '3.0.13'
22
+
23
+ migrateNode(node: JSONProsemirrorNode): JSONProsemirrorNode {
24
+ if (node.type === 'body') {
25
+ const content = node.content?.filter((n) => n.type !== 'toc_section')
26
+ return {
27
+ ...node,
28
+ content,
29
+ }
30
+ }
31
+ return node
32
+ }
33
+ }
@@ -0,0 +1,50 @@
1
+ /*!
2
+ * © 2024 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 { JSONProsemirrorNode } from '../../../types'
17
+ import { MigrationScript } from '../migration-script'
18
+
19
+ class Migration3021 implements MigrationScript {
20
+ fromVersion = '3.0.20'
21
+ toVersion = '3.0.21'
22
+
23
+ private suffixMap = new Map([
24
+ ['competing-interests', 'coi-statement'],
25
+ ['acknowledgement', 'acknowledgements'],
26
+ ['introduction', 'intro'],
27
+ ['materials-method', 'methods'],
28
+ ['subsection', ''],
29
+ ])
30
+
31
+ migrateNode(node: JSONProsemirrorNode): JSONProsemirrorNode {
32
+ if (
33
+ node.type === 'section' &&
34
+ node.attrs.category.startsWith('MPSectionCategory:')
35
+ ) {
36
+ const [, suffix] = node.attrs.category.split(':', 2)
37
+ const newCategory = this.suffixMap.get(suffix) || suffix
38
+ return {
39
+ ...node,
40
+ attrs: {
41
+ ...node.attrs,
42
+ category: newCategory,
43
+ },
44
+ }
45
+ }
46
+ return node
47
+ }
48
+ }
49
+
50
+ export default Migration3021
@@ -0,0 +1,65 @@
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 { JSONProsemirrorNode } from '../../../types'
18
+ import { MigrationScript } from '../migration-script'
19
+
20
+ class Migration3030 implements MigrationScript {
21
+ fromVersion = '3.0.29'
22
+ toVersion = '3.0.30'
23
+
24
+ private addTypeToFigures(node: JSONProsemirrorNode, type: string) {
25
+ if (!Array.isArray(node.content)) {
26
+ return node.content
27
+ }
28
+
29
+ return node.content.map((child) =>
30
+ child.type === 'figure'
31
+ ? { ...child, attrs: { ...child.attrs, type } }
32
+ : child
33
+ )
34
+ }
35
+
36
+ private migrateFigure(node: JSONProsemirrorNode): JSONProsemirrorNode {
37
+ const type = node.attrs.contentType || node.attrs.type || ''
38
+ if (node.attrs.contentType) {
39
+ delete node.attrs.contentType
40
+ }
41
+ return { ...node, attrs: { ...node.attrs, type } }
42
+ }
43
+
44
+ private migrateFigureElement(node: JSONProsemirrorNode): JSONProsemirrorNode {
45
+ const newContent = this.addTypeToFigures(node, node.attrs.type || '')
46
+ if (node.attrs.type) {
47
+ delete node.attrs.type
48
+ }
49
+ return { ...node, content: newContent, attrs: { ...node.attrs } }
50
+ }
51
+
52
+ migrateNode(node: JSONProsemirrorNode): JSONProsemirrorNode {
53
+ if (node.type === 'figure') {
54
+ return this.migrateFigure(node)
55
+ }
56
+
57
+ if (node.type === 'figure_element') {
58
+ return this.migrateFigureElement(node)
59
+ }
60
+
61
+ return node
62
+ }
63
+ }
64
+
65
+ export default Migration3030
@@ -0,0 +1,40 @@
1
+ /*!
2
+ * © 2024 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 { JSONProsemirrorNode } from '../../../types'
17
+ import { MigrationScript } from '../migration-script'
18
+
19
+ class Migration3031 implements MigrationScript {
20
+ fromVersion = '3.0.30'
21
+ toVersion = '3.0.31'
22
+
23
+ migrateNode(node: JSONProsemirrorNode): JSONProsemirrorNode {
24
+ if (node.type === 'table_header' || node.type === 'table_cell') {
25
+ return {
26
+ ...node,
27
+ content: [
28
+ {
29
+ type: 'text_block',
30
+ attrs: {},
31
+ content: node.content,
32
+ },
33
+ ],
34
+ }
35
+ }
36
+ return node
37
+ }
38
+ }
39
+
40
+ export default Migration3031
@@ -0,0 +1,37 @@
1
+ /*!
2
+ * © 2024 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 { JSONProsemirrorNode } from '../../../types'
17
+ import { MigrationScript } from '../migration-script'
18
+
19
+ class Migration3041 implements MigrationScript {
20
+ fromVersion = '3.0.40'
21
+ toVersion = '3.0.41'
22
+
23
+ migrateNode(node: JSONProsemirrorNode): JSONProsemirrorNode {
24
+ if (node.type === 'graphical_abstract_section') {
25
+ return {
26
+ ...node,
27
+ attrs: {
28
+ ...node.attrs,
29
+ category: 'abstract-graphical',
30
+ },
31
+ }
32
+ }
33
+ return node
34
+ }
35
+ }
36
+
37
+ export default Migration3041
@@ -0,0 +1,42 @@
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 { JSONProsemirrorNode } from '../../../types'
17
+ import { MigrationScript } from '../migration-script'
18
+
19
+ class Migration3055 implements MigrationScript {
20
+ fromVersion = '3.0.54'
21
+ toVersion = '3.0.55'
22
+
23
+ migrateNode(node: JSONProsemirrorNode): JSONProsemirrorNode {
24
+ if (node.type === 'bibliography_item') {
25
+ const doi = node.attrs.doi
26
+ const containerTitle = node.attrs.containerTitle
27
+ delete node.attrs.doi
28
+ delete node.attrs.containerTitle
29
+ return {
30
+ ...node,
31
+ attrs: {
32
+ ...node.attrs,
33
+ DOI: doi,
34
+ 'container-title': containerTitle,
35
+ },
36
+ }
37
+ }
38
+ return node
39
+ }
40
+ }
41
+
42
+ export default Migration3055
@@ -0,0 +1,114 @@
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 { generateNodeID } from '../../../transformer'
17
+ import { JSONProsemirrorNode } from '../../../types'
18
+ import { schema } from '../../index'
19
+ import { MigrationScript } from '../migration-script'
20
+
21
+ class Migration3056 implements MigrationScript {
22
+ fromVersion = '3.0.55'
23
+ toVersion = '3.0.56'
24
+
25
+ migrateNode(node: JSONProsemirrorNode): JSONProsemirrorNode {
26
+ const targetNodeTypes = [
27
+ 'figure_element',
28
+ 'table_element',
29
+ 'image_element',
30
+ 'figure',
31
+ 'embed',
32
+ ]
33
+ const content = node.content
34
+
35
+ if (!targetNodeTypes.includes(node.type) || !content) {
36
+ return node
37
+ }
38
+
39
+ if (!content.some((node) => node.type === 'alt_text')) {
40
+ this.addAltText(node, content)
41
+ }
42
+
43
+ if (!content.some((node) => node.type === 'long_desc')) {
44
+ this.addLongDesc(content)
45
+ }
46
+
47
+ return node
48
+ }
49
+
50
+ private addAltText(
51
+ node: JSONProsemirrorNode,
52
+ content: JSONProsemirrorNode[]
53
+ ): void {
54
+ const altText = schema.nodes.alt_text
55
+ .create({
56
+ id: generateNodeID(schema.nodes.alt_text),
57
+ })
58
+ .toJSON()
59
+
60
+ switch (node.type) {
61
+ case 'image_element':
62
+ if (content.some((n) => n.type === 'long_desc')) {
63
+ const longDescIndex = content.findIndex((n) => n.type === 'long_desc')
64
+ content.splice(longDescIndex, 0, altText)
65
+ } else {
66
+ content.push(altText)
67
+ }
68
+ break
69
+
70
+ case 'figure_element':
71
+ case 'embed': {
72
+ const figCaption = content.findIndex((n) => n.type === 'figcaption')
73
+ if (figCaption !== -1) {
74
+ content.splice(figCaption + 1, 0, altText)
75
+ }
76
+ break
77
+ }
78
+
79
+ case 'table_element': {
80
+ const elementTypes = [
81
+ 'table_element_footer',
82
+ 'col_group',
83
+ 'table',
84
+ 'placeholder',
85
+ ]
86
+ for (const type of elementTypes) {
87
+ const index = content.findIndex((n) => n.type === type)
88
+ if (index !== -1) {
89
+ content.splice(index + 1, 0, altText)
90
+ break
91
+ }
92
+ }
93
+ break
94
+ }
95
+ }
96
+ }
97
+
98
+ private addLongDesc(content: JSONProsemirrorNode[]): void {
99
+ const altTextIndex = content.findIndex((n) => n.type === 'alt_text')
100
+ if (altTextIndex !== -1) {
101
+ content.splice(
102
+ altTextIndex + 1,
103
+ 0,
104
+ schema.nodes.long_desc
105
+ .create({
106
+ id: generateNodeID(schema.nodes.long_desc),
107
+ })
108
+ .toJSON()
109
+ )
110
+ }
111
+ }
112
+ }
113
+
114
+ export default Migration3056
@@ -0,0 +1,37 @@
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 { JSONProsemirrorNode } from '../../../types'
17
+ import { schema } from '../..'
18
+ import { MigrationScript } from '../migration-script'
19
+
20
+ class Migration4213 implements MigrationScript {
21
+ fromVersion = '4.2.12'
22
+ toVersion = '4.2.13'
23
+
24
+ migrateNode(node: JSONProsemirrorNode): JSONProsemirrorNode {
25
+ if (node.type === 'trans_abstract') {
26
+ const content = node.content || []
27
+ const sectionTitleNode = schema.nodes.section_title.create()
28
+ return {
29
+ ...node,
30
+ content: [sectionTitleNode.toJSON(), ...content],
31
+ }
32
+ }
33
+ return node
34
+ }
35
+ }
36
+
37
+ export default Migration4213
@@ -0,0 +1,48 @@
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 { JSONProsemirrorNode } from '../../../types'
17
+ import { schema } from '../..'
18
+ import { MigrationScript } from '../migration-script'
19
+
20
+ class Migration4215 implements MigrationScript {
21
+ fromVersion = '4.2.14'
22
+ toVersion = '4.2.15'
23
+
24
+ migrateNode(node: JSONProsemirrorNode): JSONProsemirrorNode {
25
+ if (node.type !== schema.nodes.manuscript.name || !node.content) {
26
+ return node
27
+ }
28
+
29
+ const supplementsNode = node.content.find(
30
+ (child) => child.type === schema.nodes.supplements.name
31
+ )
32
+
33
+ if (supplementsNode) {
34
+ node.content = node.content.filter(
35
+ (child) => child.type !== schema.nodes.supplements.name
36
+ )
37
+
38
+ const backmatterIndex = node.content.findIndex(
39
+ (child) => child.type === schema.nodes.backmatter.name
40
+ )
41
+ node.content.splice(backmatterIndex + 1, 0, supplementsNode)
42
+ }
43
+
44
+ return node
45
+ }
46
+ }
47
+
48
+ export default Migration4215