@eightyfourthousand/lib-editing 2026.3.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 (304) hide show
  1. package/.babelrc +12 -0
  2. package/.eslintrc.json +18 -0
  3. package/README.md +7 -0
  4. package/jest.config.ts +10 -0
  5. package/package.json +35 -0
  6. package/postcss.config.mjs +9 -0
  7. package/project.json +29 -0
  8. package/src/fixtures/basic/json.ts +396 -0
  9. package/src/fixtures/toh251/json.ts +4913 -0
  10. package/src/fixtures/toh251/passages.ts +2814 -0
  11. package/src/fixtures/types.ts +8 -0
  12. package/src/index.ts +4 -0
  13. package/src/lib/block.ts +226 -0
  14. package/src/lib/components/editor/BlockEditor.tsx +38 -0
  15. package/src/lib/components/editor/EditorBackMatterPage.tsx +95 -0
  16. package/src/lib/components/editor/EditorBodyPage.tsx +87 -0
  17. package/src/lib/components/editor/EditorHeader.tsx +22 -0
  18. package/src/lib/components/editor/EditorLayout.tsx +62 -0
  19. package/src/lib/components/editor/EditorLeftPanelPage.tsx +27 -0
  20. package/src/lib/components/editor/EditorProvider.tsx +399 -0
  21. package/src/lib/components/editor/PaginationProvider.tsx +472 -0
  22. package/src/lib/components/editor/TitlesBuilder.tsx +40 -0
  23. package/src/lib/components/editor/TranslationBuilder.tsx +171 -0
  24. package/src/lib/components/editor/TranslationEditor.tsx +32 -0
  25. package/src/lib/components/editor/extensions/Abbreviation/Abbreviation.ts +133 -0
  26. package/src/lib/components/editor/extensions/Audio/Audio.ts +69 -0
  27. package/src/lib/components/editor/extensions/Bold.ts +43 -0
  28. package/src/lib/components/editor/extensions/Document.ts +8 -0
  29. package/src/lib/components/editor/extensions/DragHandle/DragHandle.ts +429 -0
  30. package/src/lib/components/editor/extensions/EndNoteLink/EndNoteLink.tsx +39 -0
  31. package/src/lib/components/editor/extensions/EndNoteLink/EndNoteLinkHoverContent.tsx +139 -0
  32. package/src/lib/components/editor/extensions/EndNoteLink/EndNoteLinkMark.ts +236 -0
  33. package/src/lib/components/editor/extensions/EndNoteLink/endnote-utils.ts +412 -0
  34. package/src/lib/components/editor/extensions/GlobalConfig.ts +52 -0
  35. package/src/lib/components/editor/extensions/GlossaryInstance/GlossaryInput.tsx +54 -0
  36. package/src/lib/components/editor/extensions/GlossaryInstance/GlossaryInstance.tsx +129 -0
  37. package/src/lib/components/editor/extensions/GlossaryInstance/GlossaryInstanceNode.ts +148 -0
  38. package/src/lib/components/editor/extensions/Heading/Heading.ts +71 -0
  39. package/src/lib/components/editor/extensions/HoverInputField.tsx +54 -0
  40. package/src/lib/components/editor/extensions/Image.ts +18 -0
  41. package/src/lib/components/editor/extensions/Indent.ts +103 -0
  42. package/src/lib/components/editor/extensions/InternalLink/InternalLink.ts +173 -0
  43. package/src/lib/components/editor/extensions/InternalLink/InternalLinkHoverContent.tsx +137 -0
  44. package/src/lib/components/editor/extensions/InternalLink/InternalLinkInput.tsx +71 -0
  45. package/src/lib/components/editor/extensions/InternalLink/index.ts +1 -0
  46. package/src/lib/components/editor/extensions/Italic.ts +50 -0
  47. package/src/lib/components/editor/extensions/LeadingSpace.ts +106 -0
  48. package/src/lib/components/editor/extensions/Line/LineNode.ts +41 -0
  49. package/src/lib/components/editor/extensions/LineGroup/LineGroupNode.ts +124 -0
  50. package/src/lib/components/editor/extensions/Link/Link.ts +65 -0
  51. package/src/lib/components/editor/extensions/Link/LinkHoverContent.tsx +124 -0
  52. package/src/lib/components/editor/extensions/Link/index.ts +1 -0
  53. package/src/lib/components/editor/extensions/List.ts +74 -0
  54. package/src/lib/components/editor/extensions/Mantra/Mantra.ts +88 -0
  55. package/src/lib/components/editor/extensions/Mention/Mention.ts +184 -0
  56. package/src/lib/components/editor/extensions/Mention/MentionHoverContent.tsx +158 -0
  57. package/src/lib/components/editor/extensions/NodeWrapper.tsx +57 -0
  58. package/src/lib/components/editor/extensions/Paragraph/Paragraph.ts +25 -0
  59. package/src/lib/components/editor/extensions/ParagraphIndent.ts +87 -0
  60. package/src/lib/components/editor/extensions/Passage/EditLabel.tsx +57 -0
  61. package/src/lib/components/editor/extensions/Passage/EditorOptions.tsx +29 -0
  62. package/src/lib/components/editor/extensions/Passage/Passage.tsx +238 -0
  63. package/src/lib/components/editor/extensions/Passage/PassageNode.ts +223 -0
  64. package/src/lib/components/editor/extensions/Passage/ReaderOptions.tsx +55 -0
  65. package/src/lib/components/editor/extensions/Passage/ShowAnnotations.tsx +92 -0
  66. package/src/lib/components/editor/extensions/Passage/index.ts +1 -0
  67. package/src/lib/components/editor/extensions/Passage/label.spec.ts +118 -0
  68. package/src/lib/components/editor/extensions/Passage/label.ts +39 -0
  69. package/src/lib/components/editor/extensions/Placeholder.ts +9 -0
  70. package/src/lib/components/editor/extensions/SlashCommand/SlashCommand.ts +65 -0
  71. package/src/lib/components/editor/extensions/SlashCommand/SuggestionList.tsx +109 -0
  72. package/src/lib/components/editor/extensions/SlashCommand/Suggestions.ts +185 -0
  73. package/src/lib/components/editor/extensions/SmallCaps.ts +110 -0
  74. package/src/lib/components/editor/extensions/StarterKit.ts +36 -0
  75. package/src/lib/components/editor/extensions/Subscript.ts +43 -0
  76. package/src/lib/components/editor/extensions/Superscript.ts +43 -0
  77. package/src/lib/components/editor/extensions/Table.ts +32 -0
  78. package/src/lib/components/editor/extensions/TextAlign.ts +5 -0
  79. package/src/lib/components/editor/extensions/TitleMetadata.ts +40 -0
  80. package/src/lib/components/editor/extensions/TitleNode.ts +133 -0
  81. package/src/lib/components/editor/extensions/TitlesNode.ts +102 -0
  82. package/src/lib/components/editor/extensions/Trailer.ts +57 -0
  83. package/src/lib/components/editor/extensions/TranslationDocument.ts +7 -0
  84. package/src/lib/components/editor/extensions/TranslationMetadata.ts +58 -0
  85. package/src/lib/components/editor/extensions/Underline.ts +43 -0
  86. package/src/lib/components/editor/hooks/index.ts +4 -0
  87. package/src/lib/components/editor/hooks/useBlockEditor.ts +53 -0
  88. package/src/lib/components/editor/hooks/useDefaultExtensions.ts +39 -0
  89. package/src/lib/components/editor/hooks/useDirtyStore.ts +33 -0
  90. package/src/lib/components/editor/hooks/useTranslationExtensions.ts +148 -0
  91. package/src/lib/components/editor/index.ts +10 -0
  92. package/src/lib/components/editor/menus/EmptyBubbleMenu.tsx +42 -0
  93. package/src/lib/components/editor/menus/MainBubbleMenu.tsx +51 -0
  94. package/src/lib/components/editor/menus/TranslationBubbleMenu.tsx +57 -0
  95. package/src/lib/components/editor/menus/index.ts +3 -0
  96. package/src/lib/components/editor/menus/selectors/EndNoteSelector.tsx +388 -0
  97. package/src/lib/components/editor/menus/selectors/GlossarySelector.tsx +63 -0
  98. package/src/lib/components/editor/menus/selectors/LinkSelector.tsx +68 -0
  99. package/src/lib/components/editor/menus/selectors/MantraSelector.tsx +119 -0
  100. package/src/lib/components/editor/menus/selectors/NodeSelector.tsx +144 -0
  101. package/src/lib/components/editor/menus/selectors/ParagraphButtons.tsx +68 -0
  102. package/src/lib/components/editor/menus/selectors/SelectorInputField.tsx +68 -0
  103. package/src/lib/components/editor/menus/selectors/TextAlignSelector.tsx +89 -0
  104. package/src/lib/components/editor/menus/selectors/TextButtons.tsx +89 -0
  105. package/src/lib/components/editor/menus/selectors/TranslationNodeSelector.tsx +143 -0
  106. package/src/lib/components/editor/menus/selectors/TranslationTextButtons.tsx +125 -0
  107. package/src/lib/components/editor/menus/selectors/index.ts +5 -0
  108. package/src/lib/components/editor/save-filter.spec.ts +94 -0
  109. package/src/lib/components/editor/save-filter.ts +27 -0
  110. package/src/lib/components/editor/util.ts +304 -0
  111. package/src/lib/components/index.ts +3 -0
  112. package/src/lib/components/reader/ReaderBackMatterPage.tsx +62 -0
  113. package/src/lib/components/reader/ReaderBackMatterPanel.tsx +53 -0
  114. package/src/lib/components/reader/ReaderBodyPage.tsx +46 -0
  115. package/src/lib/components/reader/ReaderBodyPanel.tsx +68 -0
  116. package/src/lib/components/reader/ReaderLayout.tsx +39 -0
  117. package/src/lib/components/reader/ReaderLeftPanel.tsx +8 -0
  118. package/src/lib/components/reader/ReaderLeftPanelPage.tsx +31 -0
  119. package/src/lib/components/reader/TranslationReader.tsx +28 -0
  120. package/src/lib/components/reader/index.ts +2 -0
  121. package/src/lib/components/reader/ssr.ts +3 -0
  122. package/src/lib/components/shared/AiSummarizerPage.tsx +12 -0
  123. package/src/lib/components/shared/BackMatterPanel.tsx +143 -0
  124. package/src/lib/components/shared/BodyPanel.tsx +214 -0
  125. package/src/lib/components/shared/HoverCardProvider.tsx +407 -0
  126. package/src/lib/components/shared/Imprint.tsx +24 -0
  127. package/src/lib/components/shared/LabeledElement.tsx +133 -0
  128. package/src/lib/components/shared/LeftPanel.tsx +65 -0
  129. package/src/lib/components/shared/NavigationContext.ts +64 -0
  130. package/src/lib/components/shared/NavigationProvider.tsx +368 -0
  131. package/src/lib/components/shared/OpenGraphImage.tsx +75 -0
  132. package/src/lib/components/shared/PassageSkeleton.tsx +10 -0
  133. package/src/lib/components/shared/RestrictionWarning.tsx +177 -0
  134. package/src/lib/components/shared/SourceReader.tsx +83 -0
  135. package/src/lib/components/shared/SuggestRevisionForm.tsx +99 -0
  136. package/src/lib/components/shared/TableOfContents.tsx +280 -0
  137. package/src/lib/components/shared/ThreeColumnRenderer.tsx +54 -0
  138. package/src/lib/components/shared/TranslationHeader.tsx +86 -0
  139. package/src/lib/components/shared/TranslationHoverCard.tsx +84 -0
  140. package/src/lib/components/shared/TranslationSkeleton.tsx +16 -0
  141. package/src/lib/components/shared/TranslationTable.tsx +155 -0
  142. package/src/lib/components/shared/bibliography/BibliographyBody.tsx +28 -0
  143. package/src/lib/components/shared/bibliography/BibliographyList.tsx +63 -0
  144. package/src/lib/components/shared/bibliography/index.ts +1 -0
  145. package/src/lib/components/shared/generate-metadata.ts +44 -0
  146. package/src/lib/components/shared/glossary/GlossaryInstanceBody.tsx +144 -0
  147. package/src/lib/components/shared/glossary/GlossaryPaginationProvider.tsx +317 -0
  148. package/src/lib/components/shared/glossary/GlossarySkeleton.tsx +19 -0
  149. package/src/lib/components/shared/glossary/GlossaryTermList.tsx +58 -0
  150. package/src/lib/components/shared/glossary/index.ts +3 -0
  151. package/src/lib/components/shared/hooks/useGlossaryInstanceListener.tsx +42 -0
  152. package/src/lib/components/shared/hooks/useScrollInTab.tsx +43 -0
  153. package/src/lib/components/shared/hooks/useScrollPositionRestore.ts +274 -0
  154. package/src/lib/components/shared/hooks/useTohToggle.tsx +52 -0
  155. package/src/lib/components/shared/index.ts +11 -0
  156. package/src/lib/components/shared/ssr.ts +2 -0
  157. package/src/lib/components/shared/titles/FramedCard.tsx +132 -0
  158. package/src/lib/components/shared/titles/LongTitle.tsx +20 -0
  159. package/src/lib/components/shared/titles/LongTitles.tsx +28 -0
  160. package/src/lib/components/shared/titles/Title.tsx +54 -0
  161. package/src/lib/components/shared/titles/TitleDetails.tsx +47 -0
  162. package/src/lib/components/shared/titles/TitleForm.tsx +37 -0
  163. package/src/lib/components/shared/titles/Titles.tsx +114 -0
  164. package/src/lib/components/shared/titles/TitlesCard.tsx +113 -0
  165. package/src/lib/components/shared/titles/index.ts +8 -0
  166. package/src/lib/components/shared/types.ts +79 -0
  167. package/src/lib/components/ssr.ts +2 -0
  168. package/src/lib/exporters/abbreviation.spec.ts +31 -0
  169. package/src/lib/exporters/abbreviation.ts +22 -0
  170. package/src/lib/exporters/annotation.ts +193 -0
  171. package/src/lib/exporters/audio.spec.ts +77 -0
  172. package/src/lib/exporters/audio.ts +27 -0
  173. package/src/lib/exporters/blockquote.spec.ts +48 -0
  174. package/src/lib/exporters/blockquote.ts +24 -0
  175. package/src/lib/exporters/code.spec.ts +93 -0
  176. package/src/lib/exporters/code.ts +26 -0
  177. package/src/lib/exporters/end-note-link.spec.ts +104 -0
  178. package/src/lib/exporters/end-note-link.ts +35 -0
  179. package/src/lib/exporters/export.ts +12 -0
  180. package/src/lib/exporters/glossary-instance.spec.ts +85 -0
  181. package/src/lib/exporters/glossary-instance.ts +31 -0
  182. package/src/lib/exporters/has-abbreviation.spec.ts +31 -0
  183. package/src/lib/exporters/has-abbreviation.ts +21 -0
  184. package/src/lib/exporters/heading.spec.ts +80 -0
  185. package/src/lib/exporters/heading.ts +28 -0
  186. package/src/lib/exporters/image.spec.ts +48 -0
  187. package/src/lib/exporters/image.ts +25 -0
  188. package/src/lib/exporters/indent.spec.ts +58 -0
  189. package/src/lib/exporters/indent.ts +18 -0
  190. package/src/lib/exporters/index.ts +1 -0
  191. package/src/lib/exporters/internal-link.spec.ts +90 -0
  192. package/src/lib/exporters/internal-link.ts +35 -0
  193. package/src/lib/exporters/italic.spec.ts +84 -0
  194. package/src/lib/exporters/italic.ts +55 -0
  195. package/src/lib/exporters/leading-space.spec.ts +28 -0
  196. package/src/lib/exporters/leading-space.ts +16 -0
  197. package/src/lib/exporters/line-group.spec.ts +48 -0
  198. package/src/lib/exporters/line-group.ts +24 -0
  199. package/src/lib/exporters/line.spec.ts +48 -0
  200. package/src/lib/exporters/line.ts +24 -0
  201. package/src/lib/exporters/link.spec.ts +123 -0
  202. package/src/lib/exporters/link.ts +67 -0
  203. package/src/lib/exporters/list-item.spec.ts +48 -0
  204. package/src/lib/exporters/list-item.ts +24 -0
  205. package/src/lib/exporters/list.spec.ts +82 -0
  206. package/src/lib/exporters/list.ts +31 -0
  207. package/src/lib/exporters/mantra.spec.ts +51 -0
  208. package/src/lib/exporters/mantra.ts +25 -0
  209. package/src/lib/exporters/mention.ts +41 -0
  210. package/src/lib/exporters/paragraph.spec.ts +173 -0
  211. package/src/lib/exporters/paragraph.ts +32 -0
  212. package/src/lib/exporters/quote.spec.ts +56 -0
  213. package/src/lib/exporters/quote.ts +25 -0
  214. package/src/lib/exporters/span.spec.ts +118 -0
  215. package/src/lib/exporters/span.ts +44 -0
  216. package/src/lib/exporters/table-body-data.spec.ts +48 -0
  217. package/src/lib/exporters/table-body-data.ts +24 -0
  218. package/src/lib/exporters/table-body-header.spec.ts +48 -0
  219. package/src/lib/exporters/table-body-header.ts +24 -0
  220. package/src/lib/exporters/table-body-row.spec.ts +48 -0
  221. package/src/lib/exporters/table-body-row.ts +24 -0
  222. package/src/lib/exporters/table.spec.ts +48 -0
  223. package/src/lib/exporters/table.ts +24 -0
  224. package/src/lib/exporters/trailer.spec.ts +48 -0
  225. package/src/lib/exporters/trailer.ts +24 -0
  226. package/src/lib/exporters/util.ts +62 -0
  227. package/src/lib/passage.ts +182 -0
  228. package/src/lib/titles.ts +80 -0
  229. package/src/lib/transformers/abbreviation.spec.ts +87 -0
  230. package/src/lib/transformers/abbreviation.ts +30 -0
  231. package/src/lib/transformers/annotate.ts +146 -0
  232. package/src/lib/transformers/audio.spec.ts +55 -0
  233. package/src/lib/transformers/audio.ts +29 -0
  234. package/src/lib/transformers/blockquote.spec.ts +48 -0
  235. package/src/lib/transformers/blockquote.ts +41 -0
  236. package/src/lib/transformers/code.spec.ts +52 -0
  237. package/src/lib/transformers/code.ts +22 -0
  238. package/src/lib/transformers/deprecated.ts +7 -0
  239. package/src/lib/transformers/end-note-link.spec.ts +56 -0
  240. package/src/lib/transformers/end-note-link.ts +76 -0
  241. package/src/lib/transformers/glossary-instance.spec.ts +55 -0
  242. package/src/lib/transformers/glossary-instance.ts +40 -0
  243. package/src/lib/transformers/has-abbreviation.spec.ts +50 -0
  244. package/src/lib/transformers/has-abbreviation.ts +30 -0
  245. package/src/lib/transformers/heading.spec.ts +62 -0
  246. package/src/lib/transformers/heading.ts +30 -0
  247. package/src/lib/transformers/image.spec.ts +51 -0
  248. package/src/lib/transformers/image.ts +28 -0
  249. package/src/lib/transformers/indent.spec.ts +53 -0
  250. package/src/lib/transformers/indent.ts +17 -0
  251. package/src/lib/transformers/index.ts +33 -0
  252. package/src/lib/transformers/inline-title.spec.ts +59 -0
  253. package/src/lib/transformers/inline-title.ts +34 -0
  254. package/src/lib/transformers/internal-link.spec.ts +67 -0
  255. package/src/lib/transformers/internal-link.ts +65 -0
  256. package/src/lib/transformers/italic.ts +22 -0
  257. package/src/lib/transformers/leading-space.spec.ts +55 -0
  258. package/src/lib/transformers/leading-space.ts +17 -0
  259. package/src/lib/transformers/line-group.spec.ts +48 -0
  260. package/src/lib/transformers/line-group.ts +37 -0
  261. package/src/lib/transformers/line.spec.ts +54 -0
  262. package/src/lib/transformers/line.ts +27 -0
  263. package/src/lib/transformers/link.spec.ts +61 -0
  264. package/src/lib/transformers/link.ts +27 -0
  265. package/src/lib/transformers/list-item.spec.ts +48 -0
  266. package/src/lib/transformers/list-item.ts +37 -0
  267. package/src/lib/transformers/list.spec.ts +58 -0
  268. package/src/lib/transformers/list.ts +42 -0
  269. package/src/lib/transformers/mantra.spec.ts +58 -0
  270. package/src/lib/transformers/mantra.ts +28 -0
  271. package/src/lib/transformers/mention.ts +70 -0
  272. package/src/lib/transformers/paragraph.spec.ts +46 -0
  273. package/src/lib/transformers/paragraph.ts +26 -0
  274. package/src/lib/transformers/quote.spec.ts +42 -0
  275. package/src/lib/transformers/quote.ts +3 -0
  276. package/src/lib/transformers/quoted.ts +3 -0
  277. package/src/lib/transformers/recurse.ts +76 -0
  278. package/src/lib/transformers/reference.ts +3 -0
  279. package/src/lib/transformers/span.spec.ts +68 -0
  280. package/src/lib/transformers/span.ts +78 -0
  281. package/src/lib/transformers/split-at.ts +58 -0
  282. package/src/lib/transformers/split-block.ts +110 -0
  283. package/src/lib/transformers/split-content.ts +67 -0
  284. package/src/lib/transformers/split-insert.ts +76 -0
  285. package/src/lib/transformers/split-marks.ts +42 -0
  286. package/src/lib/transformers/split-node.ts +138 -0
  287. package/src/lib/transformers/table-body-data.spec.ts +44 -0
  288. package/src/lib/transformers/table-body-data.ts +29 -0
  289. package/src/lib/transformers/table-body-header.spec.ts +44 -0
  290. package/src/lib/transformers/table-body-header.ts +29 -0
  291. package/src/lib/transformers/table-body-row.spec.ts +44 -0
  292. package/src/lib/transformers/table-body-row.ts +29 -0
  293. package/src/lib/transformers/table.spec.ts +47 -0
  294. package/src/lib/transformers/table.ts +29 -0
  295. package/src/lib/transformers/trailer.spec.ts +43 -0
  296. package/src/lib/transformers/trailer.ts +26 -0
  297. package/src/lib/transformers/transformer.ts +25 -0
  298. package/src/lib/transformers/unknown.ts +8 -0
  299. package/src/lib/transformers/util.ts +20 -0
  300. package/src/lib/types.ts +10 -0
  301. package/src/ssr.ts +1 -0
  302. package/tsconfig.json +20 -0
  303. package/tsconfig.lib.json +29 -0
  304. package/tsconfig.spec.json +22 -0
@@ -0,0 +1,48 @@
1
+ import type { Node } from '@tiptap/pm/model';
2
+ import { blockquote } from './blockquote';
3
+
4
+ describe('blockquote exporter', () => {
5
+ it('should export blockquote annotation correctly', () => {
6
+ const node = {
7
+ attrs: {
8
+ uuid: 'blockquote-uuid-1234',
9
+ },
10
+ textContent: 'This is a quoted passage from another text.',
11
+ } as unknown as Node;
12
+
13
+ const result = blockquote({
14
+ node,
15
+ parent: node,
16
+ root: node,
17
+ start: 0,
18
+ passageUuid: 'passage-uuid-1234',
19
+ });
20
+
21
+ expect(result).toEqual({
22
+ uuid: 'blockquote-uuid-1234',
23
+ passageUuid: 'passage-uuid-1234',
24
+ type: 'blockquote',
25
+ start: 0,
26
+ end: 43,
27
+ });
28
+ });
29
+
30
+ it('should return undefined when textContent is missing', () => {
31
+ const node = {
32
+ attrs: {
33
+ uuid: 'blockquote-uuid-empty',
34
+ },
35
+ textContent: '',
36
+ } as unknown as Node;
37
+
38
+ const result = blockquote({
39
+ node,
40
+ parent: node,
41
+ root: node,
42
+ start: 0,
43
+ passageUuid: 'passage-uuid-1234',
44
+ });
45
+
46
+ expect(result).toBeUndefined();
47
+ });
48
+ });
@@ -0,0 +1,24 @@
1
+ import { BlockquoteAnnotation } from '@eightyfourthousand/data-access';
2
+ import { Exporter } from './export';
3
+
4
+ export const blockquote: Exporter<BlockquoteAnnotation> = ({
5
+ node,
6
+ start,
7
+ passageUuid,
8
+ }): BlockquoteAnnotation | undefined => {
9
+ const textContent = node.textContent;
10
+ const uuid = node.attrs.uuid;
11
+
12
+ if (!textContent) {
13
+ console.warn(`Blockquote node ${uuid} is missing body text`);
14
+ return undefined;
15
+ }
16
+
17
+ return {
18
+ uuid,
19
+ type: 'blockquote',
20
+ passageUuid,
21
+ start,
22
+ end: start + textContent.length,
23
+ };
24
+ };
@@ -0,0 +1,93 @@
1
+ import type { Node, Mark } from '@tiptap/pm/model';
2
+ import { code } from './code';
3
+
4
+ describe('code exporter', () => {
5
+ it('should export code annotation correctly', () => {
6
+ const node = {
7
+ textContent: 'const x = 1;',
8
+ } as unknown as Node;
9
+
10
+ const mark = {
11
+ attrs: {
12
+ uuid: 'code-uuid-1234',
13
+ },
14
+ } as unknown as Mark;
15
+
16
+ const result = code({
17
+ node,
18
+ mark,
19
+ parent: node,
20
+ root: node,
21
+ start: 0,
22
+ passageUuid: 'passage-uuid-1234',
23
+ });
24
+
25
+ expect(result).toEqual({
26
+ uuid: 'code-uuid-1234',
27
+ passageUuid: 'passage-uuid-1234',
28
+ type: 'code',
29
+ start: 0,
30
+ end: 12,
31
+ });
32
+ });
33
+
34
+ it('should use parent textContent when node textContent is missing', () => {
35
+ const parent = {
36
+ textContent: 'function test()',
37
+ } as unknown as Node;
38
+
39
+ const node = {
40
+ textContent: '',
41
+ } as unknown as Node;
42
+
43
+ const mark = {
44
+ attrs: {
45
+ uuid: 'code-uuid-5678',
46
+ },
47
+ } as unknown as Mark;
48
+
49
+ const result = code({
50
+ node,
51
+ mark,
52
+ parent,
53
+ root: parent,
54
+ start: 0,
55
+ passageUuid: 'passage-uuid-1234',
56
+ });
57
+
58
+ expect(result).toEqual({
59
+ uuid: 'code-uuid-5678',
60
+ passageUuid: 'passage-uuid-1234',
61
+ type: 'code',
62
+ start: 0,
63
+ end: 15,
64
+ });
65
+ });
66
+
67
+ it('should return undefined when textContent is missing', () => {
68
+ const node = {
69
+ textContent: '',
70
+ } as unknown as Node;
71
+
72
+ const parent = {
73
+ textContent: '',
74
+ } as unknown as Node;
75
+
76
+ const mark = {
77
+ attrs: {
78
+ uuid: 'code-uuid-empty',
79
+ },
80
+ } as unknown as Mark;
81
+
82
+ const result = code({
83
+ node,
84
+ mark,
85
+ parent,
86
+ root: parent,
87
+ start: 0,
88
+ passageUuid: 'passage-uuid-1234',
89
+ });
90
+
91
+ expect(result).toBeUndefined();
92
+ });
93
+ });
@@ -0,0 +1,26 @@
1
+ import { CodeAnnotation } from '@eightyfourthousand/data-access';
2
+ import { Exporter } from './export';
3
+
4
+ export const code: Exporter<CodeAnnotation> = ({
5
+ node,
6
+ mark,
7
+ parent,
8
+ start,
9
+ passageUuid,
10
+ }): CodeAnnotation | undefined => {
11
+ const textContent = node.textContent || parent.textContent || '';
12
+ const uuid = mark?.attrs.uuid;
13
+
14
+ if (!textContent || !uuid) {
15
+ console.warn(`Code node ${uuid} is missing body text or uuid`);
16
+ return undefined;
17
+ }
18
+
19
+ return {
20
+ uuid,
21
+ type: 'code',
22
+ passageUuid,
23
+ start,
24
+ end: start + textContent.length,
25
+ };
26
+ };
@@ -0,0 +1,104 @@
1
+ import type { Node, Mark } from '@tiptap/pm/model';
2
+ import { endNoteLink } from './end-note-link';
3
+
4
+ describe('endNoteLink exporter', () => {
5
+ it('should export endNoteLink annotations correctly', () => {
6
+ const node = {
7
+ textContent: 'text',
8
+ } as unknown as Node;
9
+
10
+ const mark = {
11
+ attrs: {
12
+ notes: [
13
+ {
14
+ uuid: 'note-uuid-1',
15
+ endNote: 'endnote-uuid-1',
16
+ },
17
+ {
18
+ uuid: 'note-uuid-2',
19
+ endNote: 'endnote-uuid-2',
20
+ },
21
+ ],
22
+ },
23
+ } as unknown as Mark;
24
+
25
+ const result = endNoteLink({
26
+ node,
27
+ mark,
28
+ parent: node,
29
+ root: node,
30
+ start: 10,
31
+ passageUuid: 'passage-uuid-1234',
32
+ });
33
+
34
+ expect(result).toEqual([
35
+ {
36
+ uuid: 'note-uuid-1',
37
+ passageUuid: 'passage-uuid-1234',
38
+ type: 'endNoteLink',
39
+ start: 14,
40
+ end: 14,
41
+ endNote: 'endnote-uuid-1',
42
+ },
43
+ {
44
+ uuid: 'note-uuid-2',
45
+ passageUuid: 'passage-uuid-1234',
46
+ type: 'endNoteLink',
47
+ start: 14,
48
+ end: 14,
49
+ endNote: 'endnote-uuid-2',
50
+ },
51
+ ]);
52
+ });
53
+
54
+ it('should return empty array when textContent is missing', () => {
55
+ const node = {
56
+ textContent: '',
57
+ } as unknown as Node;
58
+
59
+ const mark = {
60
+ attrs: {
61
+ notes: [
62
+ {
63
+ uuid: 'note-uuid-1',
64
+ endNote: 'endnote-uuid-1',
65
+ },
66
+ ],
67
+ },
68
+ } as unknown as Mark;
69
+
70
+ const result = endNoteLink({
71
+ node,
72
+ mark,
73
+ parent: node,
74
+ root: node,
75
+ start: 0,
76
+ passageUuid: 'passage-uuid-1234',
77
+ });
78
+
79
+ expect(result).toEqual([]);
80
+ });
81
+
82
+ it('should return empty array when notes are missing', () => {
83
+ const node = {
84
+ textContent: 'text',
85
+ } as unknown as Node;
86
+
87
+ const mark = {
88
+ attrs: {
89
+ notes: [],
90
+ },
91
+ } as unknown as Mark;
92
+
93
+ const result = endNoteLink({
94
+ node,
95
+ mark,
96
+ parent: node,
97
+ root: node,
98
+ start: 0,
99
+ passageUuid: 'passage-uuid-1234',
100
+ });
101
+
102
+ expect(result).toEqual([]);
103
+ });
104
+ });
@@ -0,0 +1,35 @@
1
+ import { EndNoteLinkAnnotation } from '@eightyfourthousand/data-access';
2
+ import { Exporter } from './export';
3
+
4
+ export const endNoteLink: Exporter<EndNoteLinkAnnotation[]> = ({
5
+ mark,
6
+ node,
7
+ start,
8
+ passageUuid,
9
+ }): EndNoteLinkAnnotation[] => {
10
+ const textContent = node.textContent;
11
+ const notes = mark?.attrs.notes || [];
12
+
13
+ if (!textContent || notes.length === 0) {
14
+ console.warn(`Endnote link instance on passage ${passageUuid} incomplete`);
15
+ return [];
16
+ }
17
+
18
+ const end = start + textContent.length;
19
+ const annotations: EndNoteLinkAnnotation[] = notes.map(
20
+ (note: { uuid: string; endNote: string }) => {
21
+ const { uuid, endNote } = note;
22
+ return {
23
+ uuid,
24
+ type: 'endNoteLink',
25
+ passageUuid,
26
+ // end note links are 0-length annotations
27
+ start: end,
28
+ end,
29
+ endNote,
30
+ };
31
+ },
32
+ );
33
+
34
+ return annotations;
35
+ };
@@ -0,0 +1,12 @@
1
+ import type { Node, Mark } from '@tiptap/pm/model';
2
+
3
+ export type ExporterContext = {
4
+ passageUuid: string;
5
+ node: Node;
6
+ parent: Node;
7
+ root: Node;
8
+ start: number;
9
+ mark?: Mark;
10
+ };
11
+
12
+ export type Exporter<T> = (ctx: ExporterContext) => T | undefined;
@@ -0,0 +1,85 @@
1
+ import type { Node, Mark } from '@tiptap/pm/model';
2
+ import { glossaryInstance } from './glossary-instance';
3
+
4
+ describe('glossaryInstance exporter', () => {
5
+ it('should export glossaryInstance annotation correctly', () => {
6
+ const node = {
7
+ textContent: 'Buddha',
8
+ } as unknown as Node;
9
+
10
+ const mark = {
11
+ attrs: {
12
+ uuid: 'a1b2c3d4-5678-90ab-cdef-1234567890ab',
13
+ authority: 'f1e2d3c4-5678-90ab-cdef-fedcba098766',
14
+ glossary: 'f1e2d3c4-5678-90ab-cdef-fedcba098765',
15
+ },
16
+ } as unknown as Mark;
17
+
18
+ const result = glossaryInstance({
19
+ node,
20
+ mark,
21
+ parent: node,
22
+ root: node,
23
+ start: 5,
24
+ passageUuid: 'passage-uuid-1234',
25
+ });
26
+
27
+ expect(result).toEqual({
28
+ uuid: 'a1b2c3d4-5678-90ab-cdef-1234567890ab',
29
+ authority: 'f1e2d3c4-5678-90ab-cdef-fedcba098766',
30
+ passageUuid: 'passage-uuid-1234',
31
+ type: 'glossaryInstance',
32
+ start: 5,
33
+ end: 11,
34
+ glossary: 'f1e2d3c4-5678-90ab-cdef-fedcba098765',
35
+ });
36
+ });
37
+
38
+ it('should return undefined when textContent is missing', () => {
39
+ const node = {
40
+ textContent: '',
41
+ } as unknown as Node;
42
+
43
+ const mark = {
44
+ attrs: {
45
+ uuid: 'a1b2c3d4-5678-90ab-cdef-1234567890ab',
46
+ glossary: 'f1e2d3c4-5678-90ab-cdef-fedcba098765',
47
+ authority: 'f1e2d3c4-5678-90ab-cdef-fedcba098766',
48
+ },
49
+ } as unknown as Mark;
50
+
51
+ const result = glossaryInstance({
52
+ node,
53
+ mark,
54
+ parent: node,
55
+ root: node,
56
+ start: 0,
57
+ passageUuid: 'passage-uuid-1234',
58
+ });
59
+
60
+ expect(result).toBeUndefined();
61
+ });
62
+
63
+ it('should return undefined when glossary is missing', () => {
64
+ const node = {
65
+ textContent: 'Buddha',
66
+ } as unknown as Node;
67
+
68
+ const mark = {
69
+ attrs: {
70
+ uuid: 'a1b2c3d4-5678-90ab-cdef-1234567890ab',
71
+ },
72
+ } as unknown as Mark;
73
+
74
+ const result = glossaryInstance({
75
+ node,
76
+ mark,
77
+ parent: node,
78
+ root: node,
79
+ start: 0,
80
+ passageUuid: 'passage-uuid-1234',
81
+ });
82
+
83
+ expect(result).toBeUndefined();
84
+ });
85
+ });
@@ -0,0 +1,31 @@
1
+ import { GlossaryInstanceAnnotation } from '@eightyfourthousand/data-access';
2
+ import { Exporter } from './export';
3
+
4
+ export const glossaryInstance: Exporter<GlossaryInstanceAnnotation> = ({
5
+ mark,
6
+ node,
7
+ start,
8
+ passageUuid,
9
+ }): GlossaryInstanceAnnotation | undefined => {
10
+ const textContent = node.textContent;
11
+ const authority = mark?.attrs.authority;
12
+ const glossary = mark?.attrs.glossary;
13
+ const uuid = mark?.attrs.uuid;
14
+
15
+ if (!textContent || !glossary || !authority || !uuid) {
16
+ console.warn(
17
+ `Glossary instance ${uuid} on pasage ${passageUuid} is incomplete`,
18
+ );
19
+ return undefined;
20
+ }
21
+
22
+ return {
23
+ uuid,
24
+ type: 'glossaryInstance',
25
+ passageUuid,
26
+ start,
27
+ end: start + textContent.length,
28
+ authority,
29
+ glossary,
30
+ };
31
+ };
@@ -0,0 +1,31 @@
1
+ import type { Node } from '@tiptap/pm/model';
2
+ import { hasAbbreviation } from './has-abbreviation';
3
+
4
+ describe('hasAbbreviation exporter', () => {
5
+ it('should export hasAbbreviation annotation correctly', () => {
6
+ const node = {
7
+ attrs: {
8
+ uuid: 'has-abbr-uuid-1234',
9
+ abbreviation: 'abbr-ref-uuid-5678',
10
+ },
11
+ textContent: 'Toh',
12
+ } as unknown as Node;
13
+
14
+ const result = hasAbbreviation({
15
+ node,
16
+ parent: node,
17
+ root: node,
18
+ start: 0,
19
+ passageUuid: 'passage-uuid-1234',
20
+ });
21
+
22
+ expect(result).toEqual({
23
+ uuid: 'has-abbr-uuid-1234',
24
+ passageUuid: 'passage-uuid-1234',
25
+ type: 'hasAbbreviation',
26
+ start: 0,
27
+ end: 3,
28
+ abbreviation: 'abbr-ref-uuid-5678',
29
+ });
30
+ });
31
+ });
@@ -0,0 +1,21 @@
1
+ import { HasAbbreviationAnnotation } from '@eightyfourthousand/data-access';
2
+ import { Exporter } from './export';
3
+
4
+ export const hasAbbreviation: Exporter<HasAbbreviationAnnotation> = ({
5
+ node,
6
+ start,
7
+ passageUuid,
8
+ }): HasAbbreviationAnnotation => {
9
+ const textContent = node.textContent;
10
+ const abbreviation = node.attrs.abbreviation;
11
+ const uuid = node.attrs.uuid;
12
+
13
+ return {
14
+ uuid,
15
+ type: 'hasAbbreviation',
16
+ passageUuid,
17
+ start,
18
+ end: start + textContent.length,
19
+ abbreviation,
20
+ };
21
+ };
@@ -0,0 +1,80 @@
1
+ import type { Node } from '@tiptap/pm/model';
2
+ import { heading } from './heading';
3
+
4
+ describe('heading exporter', () => {
5
+ it('should export heading annotation correctly', () => {
6
+ const node = {
7
+ attrs: {
8
+ uuid: 'heading-uuid-1234',
9
+ level: 2,
10
+ class: 'chapter-title',
11
+ },
12
+ textContent: 'Chapter Title',
13
+ } as unknown as Node;
14
+
15
+ const result = heading({
16
+ node,
17
+ parent: node,
18
+ root: node,
19
+ start: 0,
20
+ passageUuid: 'passage-uuid-1234',
21
+ });
22
+
23
+ expect(result).toEqual({
24
+ uuid: 'heading-uuid-1234',
25
+ passageUuid: 'passage-uuid-1234',
26
+ type: 'heading',
27
+ start: 0,
28
+ end: 13,
29
+ level: 2,
30
+ class: 'chapter-title',
31
+ });
32
+ });
33
+
34
+ it('should default to level 1 when level is missing', () => {
35
+ const node = {
36
+ attrs: {
37
+ uuid: 'heading-uuid-5678',
38
+ },
39
+ textContent: 'Default Heading',
40
+ } as unknown as Node;
41
+
42
+ const result = heading({
43
+ node,
44
+ parent: node,
45
+ root: node,
46
+ start: 0,
47
+ passageUuid: 'passage-uuid-1234',
48
+ });
49
+
50
+ expect(result).toEqual({
51
+ uuid: 'heading-uuid-5678',
52
+ passageUuid: 'passage-uuid-1234',
53
+ type: 'heading',
54
+ start: 0,
55
+ end: 15,
56
+ level: 1,
57
+ class: undefined,
58
+ });
59
+ });
60
+
61
+ it('should return undefined when textContent is missing', () => {
62
+ const node = {
63
+ attrs: {
64
+ uuid: 'heading-uuid-empty',
65
+ level: 1,
66
+ },
67
+ textContent: '',
68
+ } as unknown as Node;
69
+
70
+ const result = heading({
71
+ node,
72
+ parent: node,
73
+ root: node,
74
+ start: 0,
75
+ passageUuid: 'passage-uuid-1234',
76
+ });
77
+
78
+ expect(result).toBeUndefined();
79
+ });
80
+ });
@@ -0,0 +1,28 @@
1
+ import { HeadingAnnotation } from '@eightyfourthousand/data-access';
2
+ import { Exporter } from './export';
3
+
4
+ export const heading: Exporter<HeadingAnnotation> = ({
5
+ node,
6
+ start,
7
+ passageUuid,
8
+ }): HeadingAnnotation | undefined => {
9
+ const textContent = node.textContent;
10
+ const uuid = node.attrs.uuid;
11
+ const level = (node.attrs.level as number) || 1;
12
+ const cls = node.attrs.class;
13
+
14
+ if (!textContent) {
15
+ console.warn(`Heading node ${uuid} is incomplete`);
16
+ return undefined;
17
+ }
18
+
19
+ return {
20
+ uuid,
21
+ type: 'heading',
22
+ passageUuid,
23
+ start,
24
+ end: start + textContent.length,
25
+ level,
26
+ class: cls,
27
+ };
28
+ };
@@ -0,0 +1,48 @@
1
+ import type { Node } from '@tiptap/pm/model';
2
+ import { image } from './image';
3
+
4
+ describe('image exporter', () => {
5
+ it('should export image annotation correctly', () => {
6
+ const node = {
7
+ attrs: {
8
+ uuid: 'image-uuid-1234',
9
+ src: '/images/thangka.jpg',
10
+ },
11
+ } as unknown as Node;
12
+
13
+ const result = image({
14
+ node,
15
+ parent: node,
16
+ root: node,
17
+ start: 100,
18
+ passageUuid: 'passage-uuid-1234',
19
+ });
20
+
21
+ expect(result).toEqual({
22
+ uuid: 'image-uuid-1234',
23
+ passageUuid: 'passage-uuid-1234',
24
+ type: 'image',
25
+ start: 100,
26
+ end: 100,
27
+ src: '/images/thangka.jpg',
28
+ });
29
+ });
30
+
31
+ it('should return undefined when src is missing', () => {
32
+ const node = {
33
+ attrs: {
34
+ uuid: 'image-uuid-nosrc',
35
+ },
36
+ } as unknown as Node;
37
+
38
+ const result = image({
39
+ node,
40
+ parent: node,
41
+ root: node,
42
+ start: 0,
43
+ passageUuid: 'passage-uuid-1234',
44
+ });
45
+
46
+ expect(result).toBeUndefined();
47
+ });
48
+ });
@@ -0,0 +1,25 @@
1
+ import { ImageAnnotation } from '@eightyfourthousand/data-access';
2
+ import { Exporter } from './export';
3
+
4
+ export const image: Exporter<ImageAnnotation> = ({
5
+ node,
6
+ start,
7
+ passageUuid,
8
+ }): ImageAnnotation | undefined => {
9
+ const src = node.attrs.src;
10
+ const uuid = node.attrs.uuid;
11
+
12
+ if (!src) {
13
+ console.warn(`Image node ${uuid} is missing src attribute`);
14
+ return undefined;
15
+ }
16
+
17
+ return {
18
+ uuid,
19
+ type: 'image',
20
+ passageUuid,
21
+ start,
22
+ end: start,
23
+ src,
24
+ };
25
+ };