@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,114 @@
1
+ 'use client';
2
+
3
+ import { useState } from 'react';
4
+ import {
5
+ BO_TITLE_PREFIX,
6
+ Imprint,
7
+ Titles as TitlesData,
8
+ TitleType,
9
+ } from '@eightyfourthousand/data-access';
10
+ import {
11
+ Dialog,
12
+ DialogContent,
13
+ DialogDescription,
14
+ DialogTitle,
15
+ } from '@eightyfourthousand/design-system';
16
+ import { TitlesCard } from './TitlesCard';
17
+ import { TitleForm } from './TitleForm';
18
+
19
+ export type TitlesVariant = 'english' | 'tibetan' | 'comparison' | 'other';
20
+
21
+ export const Titles = ({
22
+ titles,
23
+ variant = 'english',
24
+ imprint,
25
+ canEdit = false,
26
+ }: {
27
+ titles: TitlesData;
28
+ imprint?: Imprint;
29
+ variant?: TitlesVariant;
30
+ canEdit?: boolean;
31
+ }) => {
32
+ const [isEditOpen, setIsEditOpen] = useState(false);
33
+
34
+ const titlesByType = titles.reduce(
35
+ (acc, title) => {
36
+ if (!acc[title.type]) {
37
+ acc[title.type] = [];
38
+ }
39
+ acc[title.type].push(title);
40
+ return acc;
41
+ },
42
+ {} as Record<TitleType, TitlesData>,
43
+ );
44
+
45
+ const mainTitles = titlesByType['mainTitle'] || [];
46
+
47
+ let header = '';
48
+ let main = '';
49
+ const authors = imprint?.tibetanAuthors || [];
50
+
51
+ const footer =
52
+ imprint?.mainTitles?.['Sa-Ltn'] ||
53
+ mainTitles.find((t) => t.language === 'Sa-Ltn')?.title ||
54
+ '...';
55
+
56
+ switch (variant) {
57
+ case 'tibetan': {
58
+ const boMain =
59
+ imprint?.mainTitles?.bo ||
60
+ mainTitles.find((t) => t.language === 'bo')?.title;
61
+ header = `${BO_TITLE_PREFIX}${boMain || '...'}`;
62
+ break;
63
+ }
64
+ case 'comparison': {
65
+ const boMain =
66
+ imprint?.mainTitles?.bo ||
67
+ mainTitles.find((t) => t.language === 'bo')?.title;
68
+ const enMain =
69
+ imprint?.mainTitles?.en ||
70
+ mainTitles.find((t) => t.language === 'en')?.title ||
71
+ '...';
72
+ header = `${BO_TITLE_PREFIX}${boMain || '...'}`;
73
+ main = enMain;
74
+ break;
75
+ }
76
+ case 'english':
77
+ default:
78
+ main =
79
+ imprint?.mainTitles?.en ||
80
+ mainTitles.find((t) => t.language === 'en')?.title ||
81
+ mainTitles[0]?.title ||
82
+ '';
83
+ break;
84
+ }
85
+
86
+ return (
87
+ <>
88
+ <TitlesCard
89
+ header={header}
90
+ main={main}
91
+ footer={footer}
92
+ toh={imprint?.toh}
93
+ section={imprint?.section}
94
+ authors={authors}
95
+ attribution={imprint?.isAuthorContested ? 'attributed to' : 'by'}
96
+ authorsJoiner={imprint?.isAuthorContested ? ' or' : ','}
97
+ canEdit={canEdit}
98
+ onEdit={() => setIsEditOpen(true)}
99
+ />
100
+ <Dialog open={isEditOpen} onOpenChange={setIsEditOpen}>
101
+ <DialogContent className="max-w-4xl" showCloseButton={false}>
102
+ <DialogTitle className="hidden">Edit Titles</DialogTitle>
103
+ <DialogDescription className="hidden">Edit Titles</DialogDescription>
104
+ <TitleForm
105
+ titles={titles}
106
+ onChange={(title) => {
107
+ console.log('TODO: save title', title);
108
+ }}
109
+ />
110
+ </DialogContent>
111
+ </Dialog>
112
+ </>
113
+ );
114
+ };
@@ -0,0 +1,113 @@
1
+ 'use client';
2
+
3
+ import { PencilIcon } from 'lucide-react';
4
+ import { Button, Vajrasattva } from '@eightyfourthousand/design-system';
5
+ import { cn } from '@eightyfourthousand/lib-utils';
6
+
7
+ export const TitlesCard = ({
8
+ header = '',
9
+ main = '',
10
+ footer = '',
11
+ toh = '',
12
+ section = '',
13
+ authors = [],
14
+ attribution = 'by',
15
+ authorsJoiner = ',',
16
+ canEdit = false,
17
+ onEdit,
18
+ }: {
19
+ header?: string;
20
+ main?: string;
21
+ footer?: string;
22
+ toh?: string;
23
+ section?: string;
24
+ authors?: string[];
25
+ attribution?: string;
26
+ authorsJoiner?: string;
27
+ canEdit?: boolean;
28
+ onEdit?(): void;
29
+ }) => {
30
+ const radial =
31
+ 'bg-radial-[at_50%_50%] from-ochre-25 from-35% to-navy-25';
32
+
33
+ return (
34
+ <div className="mx-auto flex w-full max-w-7xl gap-1.5 rounded-lg border bg-background p-1.5">
35
+ {(toh || section) && (
36
+ <div
37
+ className={cn(
38
+ 'hidden w-32 flex-col justify-center gap-4 rounded-s-lg border p-2 text-center md:flex',
39
+ radial,
40
+ )}
41
+ >
42
+ <span className="text-sm leading-4 font-light text-ochre-700">
43
+ {section}
44
+ </span>
45
+ <span className="text-xs uppercase text-muted-foreground">{toh}</span>
46
+ </div>
47
+ )}
48
+ <div className="grow min-w-0 flex flex-col justify-center gap-3 rounded-lg border px-2 py-4 text-center md:rounded-s-none md:rounded-e-lg lg:rounded-none">
49
+ {header && (
50
+ <div
51
+ className={cn(
52
+ 'font-tibetan text-navy-500 px-2',
53
+ main ? 'text-2xl' : 'text-3xl',
54
+ 'leading-relaxed break-all xs:break-normal',
55
+ )}
56
+ >
57
+ {header}
58
+ </div>
59
+ )}
60
+ {main && (
61
+ <div className="title-main break-all px-2 font-serif text-3xl text-navy-500 xs:break-normal">
62
+ {main}
63
+ </div>
64
+ )}
65
+ <div className="flex justify-between gap-2 px-2">
66
+ {canEdit && <div className="w-1/8" />}
67
+ {footer && (
68
+ <span className="title-sub long-term flex-grow font-serif text-2xl font-light italic text-muted-foreground">
69
+ {footer}
70
+ </span>
71
+ )}
72
+ {canEdit && (
73
+ <div className="w-1/8 flex justify-end gap-1">
74
+ <Button
75
+ className="size-7 rounded-lg text-muted-foreground"
76
+ size="icon"
77
+ variant="outline"
78
+ aria-label="Edit titles"
79
+ onClick={onEdit}
80
+ >
81
+ <PencilIcon />
82
+ </Button>
83
+ </div>
84
+ )}
85
+ </div>
86
+ {authors.length > 0 && (
87
+ <div className="title-sub font-serif">
88
+ <div className="py-2 text-xs uppercase text-muted-foreground">
89
+ {attribution}
90
+ </div>
91
+ <div className="-mt-2 mx-auto flex flex-wrap justify-center gap-x-2 text-xl text-secondary">
92
+ {authors.map((author, idx) => (
93
+ <div key={`author-wrapper-${idx}`} className="flex">
94
+ <span key={`${author}-${idx}`} className="italic">
95
+ {author}
96
+ </span>
97
+ {idx < authors.length - 1 && (
98
+ <span key={`comma-${idx}`} className="whitespace-pre">
99
+ {authorsJoiner}
100
+ </span>
101
+ )}
102
+ </div>
103
+ ))}
104
+ </div>
105
+ </div>
106
+ )}
107
+ </div>
108
+ <div className={cn('hidden w-32 rounded-e-lg border lg:flex', radial)}>
109
+ <Vajrasattva className="size-full object-contain opacity-40 mix-blend-multiply" />
110
+ </div>
111
+ </div>
112
+ );
113
+ };
@@ -0,0 +1,8 @@
1
+ export * from './FramedCard';
2
+ export * from './LongTitle';
3
+ export * from './LongTitles';
4
+ export * from './Title';
5
+ export * from './TitleDetails';
6
+ export * from './TitleForm';
7
+ export * from './Titles';
8
+ export * from './TitlesCard';
@@ -0,0 +1,79 @@
1
+ import { BodyItemType, Imprint, PanelFilter, Titles } from '@eightyfourthousand/data-access';
2
+ import { TranslationEditorContent } from '../editor';
3
+
4
+ export type EditorBuilderType = BodyItemType | 'titles';
5
+
6
+ export type EditorToolsType = 'summarizer' | 'bibliography' | 'glossary';
7
+
8
+ export type EditorMenuItemType = EditorBuilderType | EditorToolsType;
9
+
10
+ export const PANEL_NAMES = ['left', 'right', 'main'] as const;
11
+ export type PanelName = (typeof PANEL_NAMES)[number];
12
+ export type TabName =
13
+ | 'toc'
14
+ | 'front'
15
+ | 'translation'
16
+ | 'source'
17
+ | 'compare'
18
+ | 'endnotes'
19
+ | 'bibliography'
20
+ | 'glossary'
21
+ | 'abbreviations';
22
+
23
+ export interface TitlesRenderer {
24
+ titles: Titles;
25
+ imprint?: Imprint;
26
+ name: string;
27
+ }
28
+
29
+ export interface TranslationRenderer {
30
+ content: TranslationEditorContent;
31
+ name: TabName;
32
+ className?: string;
33
+ filter?: PanelFilter;
34
+ panel: PanelName;
35
+ }
36
+
37
+ export const TAB_FOR_SECTION: Record<string, TabName> = {
38
+ abbreviations: 'abbreviations',
39
+ acknowledgment: 'front',
40
+ appendix: 'translation',
41
+ bibliography: 'bibliography',
42
+ colophon: 'translation',
43
+ endnotes: 'endnotes',
44
+ glossary: 'glossary',
45
+ homage: 'translation',
46
+ imprint: 'front',
47
+ introduction: 'front',
48
+ prelude: 'translation',
49
+ prologue: 'translation',
50
+ summary: 'front',
51
+ translation: 'translation',
52
+ };
53
+
54
+ export const PANEL_FOR_SECTION: Record<string, PanelName> = {
55
+ abbreviations: 'right',
56
+ acknowledgment: 'main',
57
+ appendix: 'main',
58
+ bibliography: 'right',
59
+ colophon: 'main',
60
+ endnotes: 'right',
61
+ glossary: 'right',
62
+ homage: 'main',
63
+ imprint: 'main',
64
+ introduction: 'main',
65
+ prelude: 'main',
66
+ prologue: 'main',
67
+ summary: 'main',
68
+ translation: 'main',
69
+ };
70
+
71
+ export type PanelState = {
72
+ open: boolean;
73
+ tab?: TabName;
74
+ hash?: string;
75
+ };
76
+
77
+ export type PanelsState = {
78
+ [key in PanelName]: PanelState;
79
+ };
@@ -0,0 +1,2 @@
1
+ export * from './shared/ssr';
2
+ export * from './reader/ssr';
@@ -0,0 +1,31 @@
1
+ import type { Node } from '@tiptap/pm/model';
2
+ import { abbreviation } from './abbreviation';
3
+
4
+ describe('abbreviation exporter', () => {
5
+ it('should export abbreviation annotation correctly', () => {
6
+ const node = {
7
+ attrs: {
8
+ uuid: '49c41c6d-0e04-412e-81ad-22f3af377470',
9
+ abbreviation: 'e350ec6c-a40c-46bf-8182-acba5a50e4fe',
10
+ },
11
+ textContent: 'C',
12
+ } as unknown as Node;
13
+
14
+ const result = abbreviation({
15
+ node,
16
+ parent: node,
17
+ root: node,
18
+ start: 0,
19
+ passageUuid: 'e350ec6c-a40c-46bf-8182-acba5a50e4fe',
20
+ });
21
+
22
+ expect(result).toEqual({
23
+ uuid: '49c41c6d-0e04-412e-81ad-22f3af377470',
24
+ passageUuid: 'e350ec6c-a40c-46bf-8182-acba5a50e4fe',
25
+ type: 'abbreviation',
26
+ start: 0,
27
+ end: 1,
28
+ abbreviation: 'e350ec6c-a40c-46bf-8182-acba5a50e4fe',
29
+ });
30
+ });
31
+ });
@@ -0,0 +1,22 @@
1
+ import { AbbreviationAnnotation } from '@eightyfourthousand/data-access';
2
+ import { Exporter } from './export';
3
+
4
+ export const abbreviation: Exporter<AbbreviationAnnotation> = ({
5
+ node,
6
+ parent,
7
+ start,
8
+ passageUuid,
9
+ }): AbbreviationAnnotation => {
10
+ const textContent = node.textContent || parent.textContent || '';
11
+ const abbreviation = node.attrs.abbreviation;
12
+ const uuid = node.attrs.uuid;
13
+
14
+ return {
15
+ uuid,
16
+ passageUuid,
17
+ type: 'abbreviation',
18
+ start,
19
+ end: start + textContent.length,
20
+ abbreviation,
21
+ };
22
+ };
@@ -0,0 +1,193 @@
1
+ import { Annotation, AnnotationType } from '@eightyfourthousand/data-access';
2
+ import { Exporter, ExporterContext } from './export';
3
+ import { abbreviation } from './abbreviation';
4
+ import { audio } from './audio';
5
+ import { blockquote } from './blockquote';
6
+ import { code } from './code';
7
+ import { endNoteLink } from './end-note-link';
8
+ import { glossaryInstance } from './glossary-instance';
9
+ import { hasAbbreviation } from './has-abbreviation';
10
+ import { heading } from './heading';
11
+ import { image } from './image';
12
+ import { indent } from './indent';
13
+ import { internalLink } from './internal-link';
14
+ import { italic } from './italic';
15
+ import { leadingSpace } from './leading-space';
16
+ import { line } from './line';
17
+ import { lineGroup } from './line-group';
18
+ import { link } from './link';
19
+ import { listItem } from './list-item';
20
+ import { list } from './list';
21
+ import { mantra } from './mantra';
22
+ import { mention } from './mention';
23
+ import { paragraph } from './paragraph';
24
+ import { quote } from './quote';
25
+ import { span } from './span';
26
+ import { trailer } from './trailer';
27
+ import { table } from './table';
28
+ import { tableBodyData } from './table-body-data';
29
+ import { tableBodyHeader } from './table-body-header';
30
+ import { tableBodyRow } from './table-body-row';
31
+ import { SpanMarkType } from '../types';
32
+ import { findNodePosition, nodeNotFound } from './util';
33
+
34
+ const EXPORTERS: Partial<
35
+ Record<
36
+ | AnnotationType
37
+ | SpanMarkType
38
+ | 'text'
39
+ | 'bulletList'
40
+ | 'tableCell'
41
+ | 'tableHeader'
42
+ | 'tableRow',
43
+ Exporter<Annotation | Annotation[]>
44
+ >
45
+ > = {
46
+ abbreviation,
47
+ audio,
48
+ bold: span,
49
+ blockquote,
50
+ bulletList: list,
51
+ code,
52
+ endNoteLink,
53
+ glossaryInstance,
54
+ hasAbbreviation,
55
+ heading,
56
+ image,
57
+ indent,
58
+ inlineTitle: italic,
59
+ internalLink,
60
+ italic,
61
+ leadingSpace,
62
+ line,
63
+ lineGroup,
64
+ link,
65
+ listItem,
66
+ mantra,
67
+ mention,
68
+ paragraph,
69
+ quote,
70
+ reference: link,
71
+ smallCaps: span,
72
+ subscript: span,
73
+ superscript: span,
74
+ table,
75
+ tableCell: tableBodyData,
76
+ tableHeader: tableBodyHeader,
77
+ tableRow: tableBodyRow,
78
+ trailer,
79
+ underline: span,
80
+
81
+ // ignored types
82
+ deprecated: undefined,
83
+ quoted: undefined,
84
+ unknown: undefined,
85
+ text: undefined,
86
+ };
87
+
88
+ const PARAMETER_ANNOTATION_MAP: { [key: string]: AnnotationType } = {
89
+ hasIndent: 'indent',
90
+ hasLeadingSpace: 'leadingSpace',
91
+ };
92
+
93
+ export const parameterAnnotationFromNode = (
94
+ ctx: ExporterContext,
95
+ ): Annotation[] => {
96
+ const annotations: Annotation[] = [];
97
+ const { node, start } = ctx;
98
+
99
+ const keys = Object.keys(PARAMETER_ANNOTATION_MAP);
100
+ keys.forEach((key) => {
101
+ const annotType = PARAMETER_ANNOTATION_MAP[key];
102
+ const exporter = EXPORTERS[annotType];
103
+ const hasAttr = !!node.attrs[key];
104
+ if (!hasAttr) {
105
+ return;
106
+ }
107
+
108
+ if (!exporter) {
109
+ console.warn(`No exporter for parameter annotation: ${key}`);
110
+ }
111
+
112
+ const annotation = exporter?.({ ...ctx, start });
113
+ if (!annotation) {
114
+ return;
115
+ }
116
+
117
+ if (Array.isArray(annotation)) {
118
+ annotations.push(...annotation);
119
+ } else {
120
+ annotations.push(annotation);
121
+ }
122
+ });
123
+
124
+ return annotations;
125
+ };
126
+
127
+ export const markAnnotationFromNode = (ctx: ExporterContext): Annotation[] => {
128
+ const { node } = ctx;
129
+ const annotations: Annotation[] = [];
130
+ node.marks.forEach((mark) => {
131
+ const start = findNodePosition(ctx.root, mark.attrs.uuid, mark.type.name);
132
+ if (start === undefined) {
133
+ return nodeNotFound(mark);
134
+ }
135
+ const type = mark.type.name as AnnotationType;
136
+ const annotation = EXPORTERS[type]?.({ ...ctx, mark, start });
137
+ if (!annotation) {
138
+ return;
139
+ }
140
+
141
+ if (Array.isArray(annotation)) {
142
+ annotations.push(...annotation);
143
+ } else {
144
+ annotations.push(annotation);
145
+ }
146
+ });
147
+ return annotations;
148
+ };
149
+
150
+ export const annotationExportsFromNode = (
151
+ ctx: ExporterContext,
152
+ ): Annotation[] => {
153
+ const { node, root } = ctx;
154
+ const annotations = [
155
+ ...parameterAnnotationFromNode(ctx),
156
+ ...markAnnotationFromNode(ctx),
157
+ ];
158
+
159
+ const blockAnnotation = EXPORTERS[node.type.name as AnnotationType]?.(ctx);
160
+
161
+ // NOTE: passages often have a root paragraph node that does not map to an
162
+ // annotation. Ignore nodes without a uuid.
163
+ if (!node.attrs.uuid) {
164
+ if (blockAnnotation) {
165
+ console.warn(
166
+ `Node "${node.type.name}" is missing a uuid — its annotation was skipped. ` +
167
+ 'This is likely a timing issue where ensureUuids() was not called before export.',
168
+ );
169
+ }
170
+ } else if (blockAnnotation) {
171
+ if (Array.isArray(blockAnnotation)) {
172
+ annotations.push(...blockAnnotation);
173
+ } else {
174
+ annotations.push(blockAnnotation);
175
+ }
176
+ }
177
+
178
+ node.content.forEach((child) => {
179
+ const start = findNodePosition(root, child.attrs.uuid, child.type.name);
180
+ if (start === undefined) {
181
+ return nodeNotFound(child);
182
+ }
183
+ annotations.push(
184
+ ...annotationExportsFromNode({
185
+ ...ctx,
186
+ node: child,
187
+ parent: node,
188
+ start,
189
+ }),
190
+ );
191
+ });
192
+ return annotations;
193
+ };
@@ -0,0 +1,77 @@
1
+ import type { Node } from '@tiptap/pm/model';
2
+ import { audio } from './audio';
3
+
4
+ describe('audio exporter', () => {
5
+ it('should export audio annotation correctly', () => {
6
+ const node = {
7
+ attrs: {
8
+ uuid: 'audio-uuid-1234',
9
+ src: '/audio/recitation.mp3',
10
+ mediaType: 'audio/mpeg',
11
+ },
12
+ } as unknown as Node;
13
+
14
+ const result = audio({
15
+ node,
16
+ parent: node,
17
+ root: node,
18
+ start: 50,
19
+ passageUuid: 'passage-uuid-1234',
20
+ });
21
+
22
+ expect(result).toEqual({
23
+ uuid: 'audio-uuid-1234',
24
+ passageUuid: 'passage-uuid-1234',
25
+ type: 'audio',
26
+ start: 50,
27
+ end: 50,
28
+ src: '/audio/recitation.mp3',
29
+ mediaType: 'audio/mpeg',
30
+ });
31
+ });
32
+
33
+ it('should default to audio/mpeg when mediaType is missing', () => {
34
+ const node = {
35
+ attrs: {
36
+ uuid: 'audio-uuid-5678',
37
+ src: '/audio/recitation.mp3',
38
+ },
39
+ } as unknown as Node;
40
+
41
+ const result = audio({
42
+ node,
43
+ parent: node,
44
+ root: node,
45
+ start: 0,
46
+ passageUuid: 'passage-uuid-1234',
47
+ });
48
+
49
+ expect(result).toEqual({
50
+ uuid: 'audio-uuid-5678',
51
+ passageUuid: 'passage-uuid-1234',
52
+ type: 'audio',
53
+ start: 0,
54
+ end: 0,
55
+ src: '/audio/recitation.mp3',
56
+ mediaType: 'audio/mpeg',
57
+ });
58
+ });
59
+
60
+ it('should return undefined when src is missing', () => {
61
+ const node = {
62
+ attrs: {
63
+ uuid: 'audio-uuid-nosrc',
64
+ },
65
+ } as unknown as Node;
66
+
67
+ const result = audio({
68
+ node,
69
+ parent: node,
70
+ root: node,
71
+ start: 0,
72
+ passageUuid: 'passage-uuid-1234',
73
+ });
74
+
75
+ expect(result).toBeUndefined();
76
+ });
77
+ });
@@ -0,0 +1,27 @@
1
+ import { AudioAnnotation } from '@eightyfourthousand/data-access';
2
+ import { Exporter } from './export';
3
+
4
+ export const audio: Exporter<AudioAnnotation> = ({
5
+ node,
6
+ start,
7
+ passageUuid,
8
+ }): AudioAnnotation | undefined => {
9
+ const uuid = node.attrs.uuid;
10
+ const src = node.attrs.src;
11
+ const mediaType = node.attrs.mediaType || 'audio/mpeg';
12
+
13
+ if (!src) {
14
+ console.warn(`Audio node ${uuid} is missing src attribute`);
15
+ return undefined;
16
+ }
17
+
18
+ return {
19
+ uuid,
20
+ passageUuid,
21
+ type: 'audio',
22
+ start,
23
+ end: start,
24
+ src,
25
+ mediaType,
26
+ };
27
+ };