@manuscripts/transform 1.0.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 (315) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +193 -0
  3. package/dist/cjs/errors.js +17 -0
  4. package/dist/cjs/index.js +27 -0
  5. package/dist/cjs/jats/importer/index.js +24 -0
  6. package/dist/cjs/jats/importer/jats-body-dom-parser.js +650 -0
  7. package/dist/cjs/jats/importer/jats-body-transformations.js +269 -0
  8. package/dist/cjs/jats/importer/jats-comments.js +131 -0
  9. package/dist/cjs/jats/importer/jats-front-parser.js +341 -0
  10. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +77 -0
  11. package/dist/cjs/jats/importer/jats-parser-utils.js +145 -0
  12. package/dist/cjs/jats/importer/jats-reference-parser.js +180 -0
  13. package/dist/cjs/jats/importer/parse-jats-article.js +237 -0
  14. package/dist/cjs/jats/index.js +40 -0
  15. package/dist/cjs/jats/jats-exporter.js +1569 -0
  16. package/dist/cjs/jats/jats-versions.js +41 -0
  17. package/dist/cjs/lib/attributes.js +26 -0
  18. package/dist/cjs/lib/html.js +48 -0
  19. package/dist/cjs/lib/styled-content.js +28 -0
  20. package/dist/cjs/lib/table-cell-styles.js +52 -0
  21. package/dist/cjs/lib/utils.js +66 -0
  22. package/dist/cjs/mathjax/index.js +41 -0
  23. package/dist/cjs/mathjax/mathjax-packages.js +20 -0
  24. package/dist/cjs/mathjax/mathml-to-svg.js +56 -0
  25. package/dist/cjs/mathjax/tex-to-mathml.js +49 -0
  26. package/dist/cjs/mathjax/tex-to-svg.js +59 -0
  27. package/dist/cjs/schema/groups.js +31 -0
  28. package/dist/cjs/schema/index.js +195 -0
  29. package/dist/cjs/schema/marks.js +159 -0
  30. package/dist/cjs/schema/nodes/attribution.js +32 -0
  31. package/dist/cjs/schema/nodes/bibliography_element.js +44 -0
  32. package/dist/cjs/schema/nodes/bibliography_item.js +101 -0
  33. package/dist/cjs/schema/nodes/bibliography_section.js +46 -0
  34. package/dist/cjs/schema/nodes/blockquote_element.js +62 -0
  35. package/dist/cjs/schema/nodes/caption.js +52 -0
  36. package/dist/cjs/schema/nodes/caption_title.js +51 -0
  37. package/dist/cjs/schema/nodes/citation.js +52 -0
  38. package/dist/cjs/schema/nodes/comment.js +26 -0
  39. package/dist/cjs/schema/nodes/cross_reference.js +58 -0
  40. package/dist/cjs/schema/nodes/doc.js +21 -0
  41. package/dist/cjs/schema/nodes/equation.js +55 -0
  42. package/dist/cjs/schema/nodes/equation_element.js +52 -0
  43. package/dist/cjs/schema/nodes/figcaption.js +31 -0
  44. package/dist/cjs/schema/nodes/figure.js +52 -0
  45. package/dist/cjs/schema/nodes/figure_element.js +78 -0
  46. package/dist/cjs/schema/nodes/footnote.js +67 -0
  47. package/dist/cjs/schema/nodes/footnotes_element.js +54 -0
  48. package/dist/cjs/schema/nodes/footnotes_section.js +45 -0
  49. package/dist/cjs/schema/nodes/graphical_abstract_section.js +46 -0
  50. package/dist/cjs/schema/nodes/hard_break.js +30 -0
  51. package/dist/cjs/schema/nodes/highlight_marker.js +53 -0
  52. package/dist/cjs/schema/nodes/inline_equation.js +58 -0
  53. package/dist/cjs/schema/nodes/inline_footnote.js +51 -0
  54. package/dist/cjs/schema/nodes/keywords_element.js +52 -0
  55. package/dist/cjs/schema/nodes/keywords_section.js +46 -0
  56. package/dist/cjs/schema/nodes/link.js +61 -0
  57. package/dist/cjs/schema/nodes/list.js +121 -0
  58. package/dist/cjs/schema/nodes/listing.js +73 -0
  59. package/dist/cjs/schema/nodes/listing_element.js +52 -0
  60. package/dist/cjs/schema/nodes/manuscript.js +46 -0
  61. package/dist/cjs/schema/nodes/missing_figure.js +50 -0
  62. package/dist/cjs/schema/nodes/paragraph.js +63 -0
  63. package/dist/cjs/schema/nodes/placeholder.js +49 -0
  64. package/dist/cjs/schema/nodes/placeholder_element.js +48 -0
  65. package/dist/cjs/schema/nodes/pullquote_element.js +65 -0
  66. package/dist/cjs/schema/nodes/section.js +94 -0
  67. package/dist/cjs/schema/nodes/section_label.js +30 -0
  68. package/dist/cjs/schema/nodes/section_title.js +48 -0
  69. package/dist/cjs/schema/nodes/table.js +70 -0
  70. package/dist/cjs/schema/nodes/table_col.js +57 -0
  71. package/dist/cjs/schema/nodes/table_element.js +62 -0
  72. package/dist/cjs/schema/nodes/table_row.js +123 -0
  73. package/dist/cjs/schema/nodes/text.js +21 -0
  74. package/dist/cjs/schema/nodes/toc_element.js +52 -0
  75. package/dist/cjs/schema/nodes/toc_section.js +46 -0
  76. package/dist/cjs/schema/types.js +17 -0
  77. package/dist/cjs/tests.js +30 -0
  78. package/dist/cjs/transformer/builders.js +305 -0
  79. package/dist/cjs/transformer/bundles-data.js +36 -0
  80. package/dist/cjs/transformer/bundles.js +32 -0
  81. package/dist/cjs/transformer/decode.js +619 -0
  82. package/dist/cjs/transformer/document-object-types.js +31 -0
  83. package/dist/cjs/transformer/encode.js +545 -0
  84. package/dist/cjs/transformer/filename.js +27 -0
  85. package/dist/cjs/transformer/footnote-category.js +20 -0
  86. package/dist/cjs/transformer/footnotes-order.js +59 -0
  87. package/dist/cjs/transformer/highlight-markers.js +126 -0
  88. package/dist/cjs/transformer/html.js +414 -0
  89. package/dist/cjs/transformer/id.js +28 -0
  90. package/dist/cjs/transformer/index.js +54 -0
  91. package/dist/cjs/transformer/labels.js +85 -0
  92. package/dist/cjs/transformer/manuscript-dependencies.js +74 -0
  93. package/dist/cjs/transformer/model-map.js +26 -0
  94. package/dist/cjs/transformer/models.js +17 -0
  95. package/dist/cjs/transformer/node-names.js +42 -0
  96. package/dist/cjs/transformer/node-title.js +87 -0
  97. package/dist/cjs/transformer/node-types.js +62 -0
  98. package/dist/cjs/transformer/object-types.js +57 -0
  99. package/dist/cjs/transformer/project-bundle.js +86 -0
  100. package/dist/cjs/transformer/section-category.js +222 -0
  101. package/dist/cjs/transformer/serializer.js +23 -0
  102. package/dist/cjs/transformer/shared-data.js +31 -0
  103. package/dist/cjs/transformer/tei-grobid-importer.js +121 -0
  104. package/dist/cjs/transformer/timestamp.js +20 -0
  105. package/dist/cjs/transformer/update-identifiers.js +93 -0
  106. package/dist/cjs/types.js +2 -0
  107. package/dist/es/errors.js +12 -0
  108. package/dist/es/index.js +9 -0
  109. package/dist/es/jats/importer/index.js +16 -0
  110. package/dist/es/jats/importer/jats-body-dom-parser.js +644 -0
  111. package/dist/es/jats/importer/jats-body-transformations.js +266 -0
  112. package/dist/es/jats/importer/jats-comments.js +124 -0
  113. package/dist/es/jats/importer/jats-front-parser.js +335 -0
  114. package/dist/es/jats/importer/jats-journal-meta-parser.js +70 -0
  115. package/dist/es/jats/importer/jats-parser-utils.js +139 -0
  116. package/dist/es/jats/importer/jats-reference-parser.js +177 -0
  117. package/dist/es/jats/importer/parse-jats-article.js +229 -0
  118. package/dist/es/jats/index.js +18 -0
  119. package/dist/es/jats/jats-exporter.js +1561 -0
  120. package/dist/es/jats/jats-versions.js +36 -0
  121. package/dist/es/lib/attributes.js +22 -0
  122. package/dist/es/lib/html.js +43 -0
  123. package/dist/es/lib/styled-content.js +23 -0
  124. package/dist/es/lib/table-cell-styles.js +47 -0
  125. package/dist/es/lib/utils.js +59 -0
  126. package/dist/es/mathjax/index.js +12 -0
  127. package/dist/es/mathjax/mathjax-packages.js +17 -0
  128. package/dist/es/mathjax/mathml-to-svg.js +52 -0
  129. package/dist/es/mathjax/tex-to-mathml.js +45 -0
  130. package/dist/es/mathjax/tex-to-svg.js +55 -0
  131. package/dist/es/schema/groups.js +27 -0
  132. package/dist/es/schema/index.js +178 -0
  133. package/dist/es/schema/marks.js +156 -0
  134. package/dist/es/schema/nodes/attribution.js +29 -0
  135. package/dist/es/schema/nodes/bibliography_element.js +41 -0
  136. package/dist/es/schema/nodes/bibliography_item.js +98 -0
  137. package/dist/es/schema/nodes/bibliography_section.js +42 -0
  138. package/dist/es/schema/nodes/blockquote_element.js +58 -0
  139. package/dist/es/schema/nodes/caption.js +49 -0
  140. package/dist/es/schema/nodes/caption_title.js +48 -0
  141. package/dist/es/schema/nodes/citation.js +48 -0
  142. package/dist/es/schema/nodes/comment.js +23 -0
  143. package/dist/es/schema/nodes/cross_reference.js +55 -0
  144. package/dist/es/schema/nodes/doc.js +18 -0
  145. package/dist/es/schema/nodes/equation.js +52 -0
  146. package/dist/es/schema/nodes/equation_element.js +49 -0
  147. package/dist/es/schema/nodes/figcaption.js +28 -0
  148. package/dist/es/schema/nodes/figure.js +49 -0
  149. package/dist/es/schema/nodes/figure_element.js +74 -0
  150. package/dist/es/schema/nodes/footnote.js +63 -0
  151. package/dist/es/schema/nodes/footnotes_element.js +50 -0
  152. package/dist/es/schema/nodes/footnotes_section.js +41 -0
  153. package/dist/es/schema/nodes/graphical_abstract_section.js +42 -0
  154. package/dist/es/schema/nodes/hard_break.js +27 -0
  155. package/dist/es/schema/nodes/highlight_marker.js +49 -0
  156. package/dist/es/schema/nodes/inline_equation.js +55 -0
  157. package/dist/es/schema/nodes/inline_footnote.js +47 -0
  158. package/dist/es/schema/nodes/keywords_element.js +49 -0
  159. package/dist/es/schema/nodes/keywords_section.js +42 -0
  160. package/dist/es/schema/nodes/link.js +58 -0
  161. package/dist/es/schema/nodes/list.js +117 -0
  162. package/dist/es/schema/nodes/listing.js +69 -0
  163. package/dist/es/schema/nodes/listing_element.js +49 -0
  164. package/dist/es/schema/nodes/manuscript.js +43 -0
  165. package/dist/es/schema/nodes/missing_figure.js +47 -0
  166. package/dist/es/schema/nodes/paragraph.js +59 -0
  167. package/dist/es/schema/nodes/placeholder.js +46 -0
  168. package/dist/es/schema/nodes/placeholder_element.js +45 -0
  169. package/dist/es/schema/nodes/pullquote_element.js +61 -0
  170. package/dist/es/schema/nodes/section.js +90 -0
  171. package/dist/es/schema/nodes/section_label.js +26 -0
  172. package/dist/es/schema/nodes/section_title.js +44 -0
  173. package/dist/es/schema/nodes/table.js +67 -0
  174. package/dist/es/schema/nodes/table_col.js +54 -0
  175. package/dist/es/schema/nodes/table_element.js +59 -0
  176. package/dist/es/schema/nodes/table_row.js +120 -0
  177. package/dist/es/schema/nodes/text.js +18 -0
  178. package/dist/es/schema/nodes/toc_element.js +49 -0
  179. package/dist/es/schema/nodes/toc_section.js +42 -0
  180. package/dist/es/schema/types.js +16 -0
  181. package/dist/es/tests.js +28 -0
  182. package/dist/es/transformer/builders.js +261 -0
  183. package/dist/es/transformer/bundles-data.js +8 -0
  184. package/dist/es/transformer/bundles.js +27 -0
  185. package/dist/es/transformer/decode.js +608 -0
  186. package/dist/es/transformer/document-object-types.js +28 -0
  187. package/dist/es/transformer/encode.js +535 -0
  188. package/dist/es/transformer/filename.js +23 -0
  189. package/dist/es/transformer/footnote-category.js +16 -0
  190. package/dist/es/transformer/footnotes-order.js +53 -0
  191. package/dist/es/transformer/highlight-markers.js +120 -0
  192. package/dist/es/transformer/html.js +407 -0
  193. package/dist/es/transformer/id.js +23 -0
  194. package/dist/es/transformer/index.js +38 -0
  195. package/dist/es/transformer/labels.js +81 -0
  196. package/dist/es/transformer/manuscript-dependencies.js +64 -0
  197. package/dist/es/transformer/model-map.js +22 -0
  198. package/dist/es/transformer/models.js +16 -0
  199. package/dist/es/transformer/node-names.js +39 -0
  200. package/dist/es/transformer/node-title.js +82 -0
  201. package/dist/es/transformer/node-types.js +55 -0
  202. package/dist/es/transformer/object-types.js +52 -0
  203. package/dist/es/transformer/project-bundle.js +77 -0
  204. package/dist/es/transformer/section-category.js +210 -0
  205. package/dist/es/transformer/serializer.js +17 -0
  206. package/dist/es/transformer/shared-data.js +1 -0
  207. package/dist/es/transformer/tei-grobid-importer.js +115 -0
  208. package/dist/es/transformer/timestamp.js +16 -0
  209. package/dist/es/transformer/update-identifiers.js +87 -0
  210. package/dist/es/types.js +1 -0
  211. package/dist/types/errors.d.ts +6 -0
  212. package/dist/types/index.d.ts +9 -0
  213. package/dist/types/jats/importer/index.d.ts +16 -0
  214. package/dist/types/jats/importer/jats-body-dom-parser.d.ts +24 -0
  215. package/dist/types/jats/importer/jats-body-transformations.d.ts +31 -0
  216. package/dist/types/jats/importer/jats-comments.d.ts +26 -0
  217. package/dist/types/jats/importer/jats-front-parser.d.ts +62 -0
  218. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +37 -0
  219. package/dist/types/jats/importer/jats-parser-utils.d.ts +23 -0
  220. package/dist/types/jats/importer/jats-reference-parser.d.ts +23 -0
  221. package/dist/types/jats/importer/parse-jats-article.d.ts +30 -0
  222. package/dist/types/jats/index.d.ts +18 -0
  223. package/dist/types/jats/jats-exporter.d.ts +72 -0
  224. package/dist/types/jats/jats-versions.d.ts +23 -0
  225. package/dist/types/lib/attributes.d.ts +20 -0
  226. package/dist/types/lib/html.d.ts +17 -0
  227. package/dist/types/lib/styled-content.d.ts +22 -0
  228. package/dist/types/lib/table-cell-styles.d.ts +27 -0
  229. package/dist/types/lib/utils.d.ts +26 -0
  230. package/dist/types/mathjax/index.d.ts +3 -0
  231. package/dist/types/mathjax/mathjax-packages.d.ts +16 -0
  232. package/dist/types/mathjax/mathml-to-svg.d.ts +17 -0
  233. package/dist/types/mathjax/tex-to-mathml.d.ts +17 -0
  234. package/dist/types/mathjax/tex-to-svg.d.ts +17 -0
  235. package/dist/types/schema/groups.d.ts +22 -0
  236. package/dist/types/schema/index.d.ts +65 -0
  237. package/dist/types/schema/marks.d.ts +27 -0
  238. package/dist/types/schema/nodes/attribution.d.ts +21 -0
  239. package/dist/types/schema/nodes/bibliography_element.d.ts +26 -0
  240. package/dist/types/schema/nodes/bibliography_item.d.ts +36 -0
  241. package/dist/types/schema/nodes/bibliography_section.d.ts +26 -0
  242. package/dist/types/schema/nodes/blockquote_element.d.ts +28 -0
  243. package/dist/types/schema/nodes/caption.d.ts +25 -0
  244. package/dist/types/schema/nodes/caption_title.d.ts +25 -0
  245. package/dist/types/schema/nodes/citation.d.ts +27 -0
  246. package/dist/types/schema/nodes/comment.d.ts +31 -0
  247. package/dist/types/schema/nodes/cross_reference.d.ts +26 -0
  248. package/dist/types/schema/nodes/doc.d.ts +17 -0
  249. package/dist/types/schema/nodes/equation.d.ts +28 -0
  250. package/dist/types/schema/nodes/equation_element.d.ts +29 -0
  251. package/dist/types/schema/nodes/figcaption.d.ts +21 -0
  252. package/dist/types/schema/nodes/figure.d.ts +25 -0
  253. package/dist/types/schema/nodes/figure_element.d.ts +44 -0
  254. package/dist/types/schema/nodes/footnote.d.ts +32 -0
  255. package/dist/types/schema/nodes/footnotes_element.d.ts +28 -0
  256. package/dist/types/schema/nodes/footnotes_section.d.ts +26 -0
  257. package/dist/types/schema/nodes/graphical_abstract_section.d.ts +26 -0
  258. package/dist/types/schema/nodes/hard_break.d.ts +21 -0
  259. package/dist/types/schema/nodes/highlight_marker.d.ts +29 -0
  260. package/dist/types/schema/nodes/inline_equation.d.ts +28 -0
  261. package/dist/types/schema/nodes/inline_footnote.d.ts +27 -0
  262. package/dist/types/schema/nodes/keywords_element.d.ts +27 -0
  263. package/dist/types/schema/nodes/keywords_section.d.ts +26 -0
  264. package/dist/types/schema/nodes/link.d.ts +26 -0
  265. package/dist/types/schema/nodes/list.d.ts +39 -0
  266. package/dist/types/schema/nodes/listing.d.ts +33 -0
  267. package/dist/types/schema/nodes/listing_element.d.ts +29 -0
  268. package/dist/types/schema/nodes/manuscript.d.ts +23 -0
  269. package/dist/types/schema/nodes/missing_figure.d.ts +23 -0
  270. package/dist/types/schema/nodes/paragraph.d.ts +30 -0
  271. package/dist/types/schema/nodes/placeholder.d.ts +26 -0
  272. package/dist/types/schema/nodes/placeholder_element.d.ts +25 -0
  273. package/dist/types/schema/nodes/pullquote_element.d.ts +28 -0
  274. package/dist/types/schema/nodes/section.d.ts +36 -0
  275. package/dist/types/schema/nodes/section_label.d.ts +22 -0
  276. package/dist/types/schema/nodes/section_title.d.ts +22 -0
  277. package/dist/types/schema/nodes/table.d.ts +27 -0
  278. package/dist/types/schema/nodes/table_col.d.ts +24 -0
  279. package/dist/types/schema/nodes/table_element.d.ts +35 -0
  280. package/dist/types/schema/nodes/table_row.d.ts +41 -0
  281. package/dist/types/schema/nodes/text.d.ts +17 -0
  282. package/dist/types/schema/nodes/toc_element.d.ts +27 -0
  283. package/dist/types/schema/nodes/toc_section.d.ts +26 -0
  284. package/dist/types/schema/types.d.ts +45 -0
  285. package/dist/types/tests.d.ts +16 -0
  286. package/dist/types/transformer/builders.d.ts +74 -0
  287. package/dist/types/transformer/bundles-data.d.ts +3 -0
  288. package/dist/types/transformer/bundles.d.ts +3 -0
  289. package/dist/types/transformer/decode.d.ts +38 -0
  290. package/dist/types/transformer/document-object-types.d.ts +17 -0
  291. package/dist/types/transformer/encode.d.ts +29 -0
  292. package/dist/types/transformer/filename.d.ts +16 -0
  293. package/dist/types/transformer/footnote-category.d.ts +17 -0
  294. package/dist/types/transformer/footnotes-order.d.ts +23 -0
  295. package/dist/types/transformer/highlight-markers.d.ts +26 -0
  296. package/dist/types/transformer/html.d.ts +36 -0
  297. package/dist/types/transformer/id.d.ts +20 -0
  298. package/dist/types/transformer/index.d.ts +38 -0
  299. package/dist/types/transformer/labels.d.ts +24 -0
  300. package/dist/types/transformer/manuscript-dependencies.d.ts +12 -0
  301. package/dist/types/transformer/model-map.d.ts +19 -0
  302. package/dist/types/transformer/models.d.ts +48 -0
  303. package/dist/types/transformer/node-names.d.ts +17 -0
  304. package/dist/types/transformer/node-title.d.ts +19 -0
  305. package/dist/types/transformer/node-types.d.ts +22 -0
  306. package/dist/types/transformer/object-types.d.ts +29 -0
  307. package/dist/types/transformer/project-bundle.d.ts +30 -0
  308. package/dist/types/transformer/section-category.d.ts +28 -0
  309. package/dist/types/transformer/serializer.d.ts +19 -0
  310. package/dist/types/transformer/shared-data.d.ts +2 -0
  311. package/dist/types/transformer/tei-grobid-importer.d.ts +20 -0
  312. package/dist/types/transformer/timestamp.d.ts +16 -0
  313. package/dist/types/transformer/update-identifiers.d.ts +23 -0
  314. package/dist/types/types.d.ts +2 -0
  315. package/package.json +89 -0
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2020 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.buildTargets = void 0;
19
+ const schema_1 = require("../schema");
20
+ const node_names_1 = require("./node-names");
21
+ const labelledNodeTypes = [
22
+ schema_1.schema.nodes.figure_element,
23
+ schema_1.schema.nodes.table_element,
24
+ schema_1.schema.nodes.equation_element,
25
+ schema_1.schema.nodes.listing_element,
26
+ ];
27
+ const labelProperties = new Map([
28
+ [schema_1.schema.nodes.figure_element, 'figureElementLabel'],
29
+ [schema_1.schema.nodes.table_element, 'tableElementLabel'],
30
+ [schema_1.schema.nodes.equation_element, 'equationElementLabel'],
31
+ [schema_1.schema.nodes.listing_element, 'listingElementLabel'],
32
+ ]);
33
+ const chooseLabel = (nodeType, manuscript) => {
34
+ const labelProperty = labelProperties.get(nodeType);
35
+ if (labelProperty) {
36
+ const label = manuscript[labelProperty];
37
+ if (label) {
38
+ return label;
39
+ }
40
+ }
41
+ return node_names_1.nodeNames.get(nodeType);
42
+ };
43
+ const buildTargets = (fragment, manuscript) => {
44
+ const counters = {};
45
+ for (const nodeType of labelledNodeTypes) {
46
+ counters[nodeType.name] = {
47
+ label: chooseLabel(nodeType, manuscript),
48
+ index: 0,
49
+ };
50
+ }
51
+ const buildLabel = (type) => {
52
+ const viewLabel = type;
53
+ const counter = counters[viewLabel.name];
54
+ counter.index++;
55
+ return `${counter.label} ${counter.index}`;
56
+ };
57
+ const targets = new Map();
58
+ const figures = [];
59
+ fragment.forEach((node) => {
60
+ if (node.type === node.type.schema.nodes.graphical_abstract_section) {
61
+ node.forEach((item) => {
62
+ if (item.type === node.type.schema.nodes.figure_element) {
63
+ figures.push(item.attrs.id);
64
+ }
65
+ });
66
+ }
67
+ });
68
+ fragment.descendants((node) => {
69
+ if (node.type.name in counters) {
70
+ const isInGraphicalAbstract = figures.indexOf(node.attrs.id) > -1;
71
+ if (isInGraphicalAbstract) {
72
+ return;
73
+ }
74
+ const label = buildLabel(node.type);
75
+ targets.set(node.attrs.id, {
76
+ type: node.type.name,
77
+ id: node.attrs.id,
78
+ label,
79
+ caption: node.textContent,
80
+ });
81
+ }
82
+ });
83
+ return targets;
84
+ };
85
+ exports.buildTargets = buildTargets;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.updatedPageLayout = exports.getByPrototype = exports.fromPrototype = exports.loadBundledDependencies = exports.loadContributorRoles = exports.loadKeywords = exports.loadStyles = void 0;
15
+ const manuscripts_json_schema_1 = require("@manuscripts/manuscripts-json-schema");
16
+ const id_1 = require("./id");
17
+ const object_types_1 = require("./object-types");
18
+ const shared_data_1 = require("./shared-data");
19
+ const isStatusLabel = (0, object_types_1.hasObjectType)(manuscripts_json_schema_1.ObjectTypes.StatusLabel);
20
+ const isBundledModel = (model) => model.bundled === true;
21
+ const loadBundledData = async (file) => {
22
+ const models = await (0, shared_data_1.loadSharedData)(file);
23
+ return models.filter(isBundledModel);
24
+ };
25
+ const loadStyles = () => loadBundledData('styles');
26
+ exports.loadStyles = loadStyles;
27
+ const loadKeywords = () => loadBundledData('keywords');
28
+ exports.loadKeywords = loadKeywords;
29
+ const loadContributorRoles = () => loadBundledData('contributor-roles');
30
+ exports.loadContributorRoles = loadContributorRoles;
31
+ const loadBundledDependencies = async () => {
32
+ const contributorRoles = await (0, exports.loadContributorRoles)();
33
+ const keywords = await (0, exports.loadKeywords)();
34
+ const styles = await (0, exports.loadStyles)();
35
+ return [...contributorRoles, ...keywords.filter(isStatusLabel), ...styles];
36
+ };
37
+ exports.loadBundledDependencies = loadBundledDependencies;
38
+ const fromPrototype = (model) => {
39
+ const { _id, _rev } = model, data = __rest(model, ["_id", "_rev"]);
40
+ const output = Object.assign(Object.assign({}, data), { prototype: _id, _id: (0, id_1.generateID)(model.objectType) });
41
+ return output;
42
+ };
43
+ exports.fromPrototype = fromPrototype;
44
+ const getByPrototype = (modelMap, prototype) => {
45
+ for (const model of modelMap.values()) {
46
+ if (model.prototype === prototype) {
47
+ return model;
48
+ }
49
+ }
50
+ };
51
+ exports.getByPrototype = getByPrototype;
52
+ const isParagraphStyle = (0, object_types_1.hasObjectType)(manuscripts_json_schema_1.ObjectTypes.ParagraphStyle);
53
+ const chooseNewDefaultParagraphStyle = (styles) => {
54
+ for (const style of styles.values()) {
55
+ if (isParagraphStyle(style)) {
56
+ if (style.title === 'Body Text') {
57
+ return style;
58
+ }
59
+ }
60
+ }
61
+ };
62
+ const updatedPageLayout = (styleMap, pageLayoutID) => {
63
+ const newPageLayout = (0, exports.getByPrototype)(styleMap, pageLayoutID);
64
+ if (!newPageLayout) {
65
+ throw new Error('Page layout not found');
66
+ }
67
+ const newDefaultParagraphStyle = (0, exports.getByPrototype)(styleMap, newPageLayout.defaultParagraphStyle) || chooseNewDefaultParagraphStyle(styleMap);
68
+ if (!newDefaultParagraphStyle) {
69
+ throw new Error('Default paragraph style not found');
70
+ }
71
+ newPageLayout.defaultParagraphStyle = newDefaultParagraphStyle._id;
72
+ return newPageLayout;
73
+ };
74
+ exports.updatedPageLayout = updatedPageLayout;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2020 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.addModelToMap = void 0;
19
+ const id_1 = require("./id");
20
+ const addModelToMap = (modelMap) => (data) => {
21
+ if (!data._id) {
22
+ data._id = (0, id_1.generateID)(data.objectType);
23
+ }
24
+ modelMap.set(data._id, data);
25
+ };
26
+ exports.addModelToMap = addModelToMap;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2019 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2019 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.nodeNames = void 0;
19
+ const schema_1 = require("../schema");
20
+ exports.nodeNames = new Map([
21
+ [schema_1.schema.nodes.bibliography_element, 'Bibliography'],
22
+ [schema_1.schema.nodes.bibliography_section, 'Section'],
23
+ [schema_1.schema.nodes.citation, 'Citation'],
24
+ [schema_1.schema.nodes.listing_element, 'Listing'],
25
+ [schema_1.schema.nodes.cross_reference, 'Cross Reference'],
26
+ [schema_1.schema.nodes.equation_element, 'Equation'],
27
+ [schema_1.schema.nodes.figure_element, 'Figure'],
28
+ [schema_1.schema.nodes.footnote, 'Footnote'],
29
+ [schema_1.schema.nodes.footnotes_element, 'Notes'],
30
+ [schema_1.schema.nodes.bullet_list, 'Bullet List'],
31
+ [schema_1.schema.nodes.ordered_list, 'Ordered List'],
32
+ [schema_1.schema.nodes.manuscript, 'Manuscript'],
33
+ [schema_1.schema.nodes.paragraph, 'Paragraph'],
34
+ [schema_1.schema.nodes.section, 'Section'],
35
+ [schema_1.schema.nodes.section_title, 'Section'],
36
+ [schema_1.schema.nodes.table, 'Table'],
37
+ [schema_1.schema.nodes.table_element, 'Table'],
38
+ [schema_1.schema.nodes.blockquote_element, 'Block Quote'],
39
+ [schema_1.schema.nodes.pullquote_element, 'Pull Quote'],
40
+ [schema_1.schema.nodes.keywords_section, 'Section'],
41
+ [schema_1.schema.nodes.toc_section, 'Section'],
42
+ ]);
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2019 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.nodeTitlePlaceholder = exports.nodeTitle = void 0;
19
+ const utils_1 = require("../lib/utils");
20
+ const schema_1 = require("../schema");
21
+ const node_names_1 = require("./node-names");
22
+ const textSnippet = (node, max = 100) => {
23
+ let text = '';
24
+ node.forEach((child) => {
25
+ if (child.isText) {
26
+ text += child.text;
27
+ }
28
+ else if ((0, schema_1.isHighlightMarkerNode)(node)) {
29
+ text += '';
30
+ }
31
+ else {
32
+ text += ' ';
33
+ }
34
+ });
35
+ return text.substr(0, max);
36
+ };
37
+ const snippetOfNodeType = (node, nodeType) => {
38
+ for (const child of (0, utils_1.iterateChildren)(node, true)) {
39
+ if (child.type === nodeType) {
40
+ return textSnippet(child);
41
+ }
42
+ }
43
+ return null;
44
+ };
45
+ const nodeTitle = (node) => {
46
+ const nodes = node.type.schema.nodes;
47
+ switch (node.type) {
48
+ case nodes.section:
49
+ case nodes.bibliography_section:
50
+ case nodes.footnotes_section:
51
+ case nodes.keywords_section:
52
+ case nodes.toc_section:
53
+ case nodes.graphical_abstract_section:
54
+ return snippetOfNodeType(node, nodes.section_title);
55
+ case nodes.footnotes_element:
56
+ return node.attrs.collateByKind === 'footnote' ? 'Footnotes' : 'Endnotes';
57
+ case nodes.ordered_list:
58
+ case nodes.bullet_list:
59
+ case nodes.blockquote_element:
60
+ case nodes.footnote:
61
+ case nodes.pullquote_element:
62
+ return snippetOfNodeType(node, nodes.paragraph);
63
+ case nodes.figure_element:
64
+ case nodes.table_element:
65
+ case nodes.equation_element:
66
+ case nodes.listing_element:
67
+ case nodes.multi_graphic_figure_element:
68
+ return '';
69
+ default:
70
+ return textSnippet(node);
71
+ }
72
+ };
73
+ exports.nodeTitle = nodeTitle;
74
+ const nodeTitlePlaceholder = (nodeType) => {
75
+ const nodes = nodeType.schema.nodes;
76
+ switch (nodeType) {
77
+ case nodes.title:
78
+ return 'Untitled Manuscript';
79
+ case nodes.section:
80
+ return 'Untitled Section';
81
+ case nodes.bibliography_section:
82
+ return 'Bibliography';
83
+ default:
84
+ return node_names_1.nodeNames.get(nodeType) || '';
85
+ }
86
+ };
87
+ exports.nodeTitlePlaceholder = nodeTitlePlaceholder;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2019 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.isNodeType = exports.isSectionNodeType = exports.isElementNodeType = exports.isExecutableNodeType = exports.nodeTypesMap = void 0;
19
+ const manuscripts_json_schema_1 = require("@manuscripts/manuscripts-json-schema");
20
+ const schema_1 = require("../schema");
21
+ exports.nodeTypesMap = new Map([
22
+ [schema_1.schema.nodes.comment, manuscripts_json_schema_1.ObjectTypes.CommentAnnotation],
23
+ [schema_1.schema.nodes.bibliography_item, manuscripts_json_schema_1.ObjectTypes.BibliographyItem],
24
+ [schema_1.schema.nodes.bibliography_element, manuscripts_json_schema_1.ObjectTypes.BibliographyElement],
25
+ [schema_1.schema.nodes.bibliography_section, manuscripts_json_schema_1.ObjectTypes.Section],
26
+ [schema_1.schema.nodes.blockquote_element, manuscripts_json_schema_1.ObjectTypes.QuoteElement],
27
+ [schema_1.schema.nodes.bullet_list, manuscripts_json_schema_1.ObjectTypes.ListElement],
28
+ [schema_1.schema.nodes.citation, manuscripts_json_schema_1.ObjectTypes.Citation],
29
+ [schema_1.schema.nodes.cross_reference, manuscripts_json_schema_1.ObjectTypes.AuxiliaryObjectReference],
30
+ [schema_1.schema.nodes.equation, manuscripts_json_schema_1.ObjectTypes.Equation],
31
+ [schema_1.schema.nodes.equation_element, manuscripts_json_schema_1.ObjectTypes.EquationElement],
32
+ [schema_1.schema.nodes.figure, manuscripts_json_schema_1.ObjectTypes.Figure],
33
+ [schema_1.schema.nodes.missing_figure, manuscripts_json_schema_1.ObjectTypes.MissingFigure],
34
+ [schema_1.schema.nodes.figure_element, manuscripts_json_schema_1.ObjectTypes.FigureElement],
35
+ [schema_1.schema.nodes.footnote, manuscripts_json_schema_1.ObjectTypes.Footnote],
36
+ [schema_1.schema.nodes.footnotes_element, manuscripts_json_schema_1.ObjectTypes.FootnotesElement],
37
+ [schema_1.schema.nodes.footnotes_section, manuscripts_json_schema_1.ObjectTypes.Section],
38
+ [schema_1.schema.nodes.graphical_abstract_section, manuscripts_json_schema_1.ObjectTypes.Section],
39
+ [schema_1.schema.nodes.highlight_marker, manuscripts_json_schema_1.ObjectTypes.HighlightMarker],
40
+ [schema_1.schema.nodes.inline_equation, manuscripts_json_schema_1.ObjectTypes.InlineMathFragment],
41
+ [schema_1.schema.nodes.keywords_element, manuscripts_json_schema_1.ObjectTypes.KeywordsElement],
42
+ [schema_1.schema.nodes.keywords_section, manuscripts_json_schema_1.ObjectTypes.Section],
43
+ [schema_1.schema.nodes.listing, manuscripts_json_schema_1.ObjectTypes.Listing],
44
+ [schema_1.schema.nodes.listing_element, manuscripts_json_schema_1.ObjectTypes.ListingElement],
45
+ [schema_1.schema.nodes.manuscript, manuscripts_json_schema_1.ObjectTypes.Manuscript],
46
+ [schema_1.schema.nodes.ordered_list, manuscripts_json_schema_1.ObjectTypes.ListElement],
47
+ [schema_1.schema.nodes.paragraph, manuscripts_json_schema_1.ObjectTypes.ParagraphElement],
48
+ [schema_1.schema.nodes.pullquote_element, manuscripts_json_schema_1.ObjectTypes.QuoteElement],
49
+ [schema_1.schema.nodes.section, manuscripts_json_schema_1.ObjectTypes.Section],
50
+ [schema_1.schema.nodes.table, manuscripts_json_schema_1.ObjectTypes.Table],
51
+ [schema_1.schema.nodes.table_element, manuscripts_json_schema_1.ObjectTypes.TableElement],
52
+ [schema_1.schema.nodes.toc_element, manuscripts_json_schema_1.ObjectTypes.TOCElement],
53
+ [schema_1.schema.nodes.toc_section, manuscripts_json_schema_1.ObjectTypes.Section],
54
+ ]);
55
+ const isExecutableNodeType = (type) => (0, schema_1.hasGroup)(type, schema_1.GROUP_EXECUTABLE);
56
+ exports.isExecutableNodeType = isExecutableNodeType;
57
+ const isElementNodeType = (type) => (0, schema_1.hasGroup)(type, schema_1.GROUP_ELEMENT);
58
+ exports.isElementNodeType = isElementNodeType;
59
+ const isSectionNodeType = (type) => (0, schema_1.hasGroup)(type, schema_1.GROUP_SECTION);
60
+ exports.isSectionNodeType = isSectionNodeType;
61
+ const isNodeType = (node, type) => node.type === node.type.schema.nodes[type];
62
+ exports.isNodeType = isNodeType;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2019 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.isCommentAnnotation = exports.isUserProfile = exports.isTable = exports.isManuscript = exports.isFigure = exports.hasObjectType = exports.isManuscriptModel = exports.manuscriptObjects = exports.elementObjects = exports.ExtraObjectTypes = void 0;
19
+ const manuscripts_json_schema_1 = require("@manuscripts/manuscripts-json-schema");
20
+ var ExtraObjectTypes;
21
+ (function (ExtraObjectTypes) {
22
+ ExtraObjectTypes["PlaceholderElement"] = "MPPlaceholderElement";
23
+ })(ExtraObjectTypes = exports.ExtraObjectTypes || (exports.ExtraObjectTypes = {}));
24
+ exports.elementObjects = [
25
+ manuscripts_json_schema_1.ObjectTypes.BibliographyElement,
26
+ manuscripts_json_schema_1.ObjectTypes.EquationElement,
27
+ manuscripts_json_schema_1.ObjectTypes.FigureElement,
28
+ manuscripts_json_schema_1.ObjectTypes.FootnotesElement,
29
+ manuscripts_json_schema_1.ObjectTypes.ListElement,
30
+ manuscripts_json_schema_1.ObjectTypes.ListingElement,
31
+ manuscripts_json_schema_1.ObjectTypes.ParagraphElement,
32
+ manuscripts_json_schema_1.ObjectTypes.TableElement,
33
+ manuscripts_json_schema_1.ObjectTypes.TOCElement,
34
+ ];
35
+ exports.manuscriptObjects = [
36
+ manuscripts_json_schema_1.ObjectTypes.Affiliation,
37
+ manuscripts_json_schema_1.ObjectTypes.Citation,
38
+ manuscripts_json_schema_1.ObjectTypes.CommentAnnotation,
39
+ manuscripts_json_schema_1.ObjectTypes.Contributor,
40
+ manuscripts_json_schema_1.ObjectTypes.Footnote,
41
+ manuscripts_json_schema_1.ObjectTypes.InlineMathFragment,
42
+ manuscripts_json_schema_1.ObjectTypes.Section,
43
+ ].concat(exports.elementObjects);
44
+ const isManuscriptModel = (model) => {
45
+ if (!model.objectType) {
46
+ throw new Error('Model must have objectType');
47
+ }
48
+ return manuscripts_json_schema_1.manuscriptIDTypes.has(model.objectType);
49
+ };
50
+ exports.isManuscriptModel = isManuscriptModel;
51
+ const hasObjectType = (objectType) => (model) => model.objectType === objectType;
52
+ exports.hasObjectType = hasObjectType;
53
+ exports.isFigure = (0, exports.hasObjectType)(manuscripts_json_schema_1.ObjectTypes.Figure);
54
+ exports.isManuscript = (0, exports.hasObjectType)(manuscripts_json_schema_1.ObjectTypes.Manuscript);
55
+ exports.isTable = (0, exports.hasObjectType)(manuscripts_json_schema_1.ObjectTypes.Table);
56
+ exports.isUserProfile = (0, exports.hasObjectType)(manuscripts_json_schema_1.ObjectTypes.UserProfile);
57
+ exports.isCommentAnnotation = (0, exports.hasObjectType)(manuscripts_json_schema_1.ObjectTypes.CommentAnnotation);
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2019 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.findManuscriptById = exports.findLatestManuscriptSubmission = exports.findManuscriptModelByType = exports.findJournal = exports.findManuscript = exports.parseProjectBundle = void 0;
19
+ const manuscripts_json_schema_1 = require("@manuscripts/manuscripts-json-schema");
20
+ const decode_1 = require("./decode");
21
+ const object_types_1 = require("./object-types");
22
+ const parseProjectBundle = (projectBundle, manuscriptID) => {
23
+ const manuscriptData = manuscriptID
24
+ ? projectBundle.data.filter((doc) => !doc.manuscriptID || doc.manuscriptID === manuscriptID)
25
+ : projectBundle.data;
26
+ const modelMap = new Map();
27
+ for (const component of manuscriptData) {
28
+ modelMap.set(component._id, component);
29
+ }
30
+ const decoder = new decode_1.Decoder(modelMap);
31
+ const doc = decoder.createArticleNode();
32
+ return { doc, modelMap };
33
+ };
34
+ exports.parseProjectBundle = parseProjectBundle;
35
+ const isManuscript = (0, object_types_1.hasObjectType)(manuscripts_json_schema_1.ObjectTypes.Manuscript);
36
+ const findManuscript = (modelMap) => {
37
+ for (const model of modelMap.values()) {
38
+ if (isManuscript(model)) {
39
+ return model;
40
+ }
41
+ }
42
+ throw new Error('No manuscript found');
43
+ };
44
+ exports.findManuscript = findManuscript;
45
+ const isJournal = (0, object_types_1.hasObjectType)(manuscripts_json_schema_1.ObjectTypes.Journal);
46
+ const findJournal = (modelMap) => {
47
+ for (const model of modelMap.values()) {
48
+ if (isJournal(model)) {
49
+ return model;
50
+ }
51
+ }
52
+ return null;
53
+ };
54
+ exports.findJournal = findJournal;
55
+ const isManuscriptModel = (model) => 'manuscriptID' in model;
56
+ const findManuscriptModelByType = (modelMap, manuscript, objectType) => {
57
+ for (const model of modelMap.values()) {
58
+ if (model.objectType === objectType &&
59
+ isManuscriptModel(model) &&
60
+ manuscript._id === model.manuscriptID) {
61
+ return model;
62
+ }
63
+ }
64
+ };
65
+ exports.findManuscriptModelByType = findManuscriptModelByType;
66
+ const isSubmission = (0, object_types_1.hasObjectType)(manuscripts_json_schema_1.ObjectTypes.Submission);
67
+ const newestFirst = (a, b) => b.createdAt - a.createdAt;
68
+ const findLatestManuscriptSubmission = (modelMap, manuscript) => {
69
+ const submissions = [];
70
+ for (const model of modelMap.values()) {
71
+ if (isSubmission(model) && model.manuscriptID === manuscript._id) {
72
+ submissions.push(model);
73
+ }
74
+ }
75
+ submissions.sort(newestFirst);
76
+ return submissions.length ? submissions[0] : undefined;
77
+ };
78
+ exports.findLatestManuscriptSubmission = findLatestManuscriptSubmission;
79
+ const findManuscriptById = (modelMap, manuscriptID) => {
80
+ const manuscript = modelMap.get(manuscriptID);
81
+ if (manuscript && isManuscript(manuscript)) {
82
+ return manuscript;
83
+ }
84
+ throw new Error(`There is no manuscript found for the following _id (${manuscriptID})`);
85
+ };
86
+ exports.findManuscriptById = findManuscriptById;