@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.
- package/.babelrc +12 -0
- package/.eslintrc.json +18 -0
- package/README.md +7 -0
- package/jest.config.ts +10 -0
- package/package.json +35 -0
- package/postcss.config.mjs +9 -0
- package/project.json +29 -0
- package/src/fixtures/basic/json.ts +396 -0
- package/src/fixtures/toh251/json.ts +4913 -0
- package/src/fixtures/toh251/passages.ts +2814 -0
- package/src/fixtures/types.ts +8 -0
- package/src/index.ts +4 -0
- package/src/lib/block.ts +226 -0
- package/src/lib/components/editor/BlockEditor.tsx +38 -0
- package/src/lib/components/editor/EditorBackMatterPage.tsx +95 -0
- package/src/lib/components/editor/EditorBodyPage.tsx +87 -0
- package/src/lib/components/editor/EditorHeader.tsx +22 -0
- package/src/lib/components/editor/EditorLayout.tsx +62 -0
- package/src/lib/components/editor/EditorLeftPanelPage.tsx +27 -0
- package/src/lib/components/editor/EditorProvider.tsx +399 -0
- package/src/lib/components/editor/PaginationProvider.tsx +472 -0
- package/src/lib/components/editor/TitlesBuilder.tsx +40 -0
- package/src/lib/components/editor/TranslationBuilder.tsx +171 -0
- package/src/lib/components/editor/TranslationEditor.tsx +32 -0
- package/src/lib/components/editor/extensions/Abbreviation/Abbreviation.ts +133 -0
- package/src/lib/components/editor/extensions/Audio/Audio.ts +69 -0
- package/src/lib/components/editor/extensions/Bold.ts +43 -0
- package/src/lib/components/editor/extensions/Document.ts +8 -0
- package/src/lib/components/editor/extensions/DragHandle/DragHandle.ts +429 -0
- package/src/lib/components/editor/extensions/EndNoteLink/EndNoteLink.tsx +39 -0
- package/src/lib/components/editor/extensions/EndNoteLink/EndNoteLinkHoverContent.tsx +139 -0
- package/src/lib/components/editor/extensions/EndNoteLink/EndNoteLinkMark.ts +236 -0
- package/src/lib/components/editor/extensions/EndNoteLink/endnote-utils.ts +412 -0
- package/src/lib/components/editor/extensions/GlobalConfig.ts +52 -0
- package/src/lib/components/editor/extensions/GlossaryInstance/GlossaryInput.tsx +54 -0
- package/src/lib/components/editor/extensions/GlossaryInstance/GlossaryInstance.tsx +129 -0
- package/src/lib/components/editor/extensions/GlossaryInstance/GlossaryInstanceNode.ts +148 -0
- package/src/lib/components/editor/extensions/Heading/Heading.ts +71 -0
- package/src/lib/components/editor/extensions/HoverInputField.tsx +54 -0
- package/src/lib/components/editor/extensions/Image.ts +18 -0
- package/src/lib/components/editor/extensions/Indent.ts +103 -0
- package/src/lib/components/editor/extensions/InternalLink/InternalLink.ts +173 -0
- package/src/lib/components/editor/extensions/InternalLink/InternalLinkHoverContent.tsx +137 -0
- package/src/lib/components/editor/extensions/InternalLink/InternalLinkInput.tsx +71 -0
- package/src/lib/components/editor/extensions/InternalLink/index.ts +1 -0
- package/src/lib/components/editor/extensions/Italic.ts +50 -0
- package/src/lib/components/editor/extensions/LeadingSpace.ts +106 -0
- package/src/lib/components/editor/extensions/Line/LineNode.ts +41 -0
- package/src/lib/components/editor/extensions/LineGroup/LineGroupNode.ts +124 -0
- package/src/lib/components/editor/extensions/Link/Link.ts +65 -0
- package/src/lib/components/editor/extensions/Link/LinkHoverContent.tsx +124 -0
- package/src/lib/components/editor/extensions/Link/index.ts +1 -0
- package/src/lib/components/editor/extensions/List.ts +74 -0
- package/src/lib/components/editor/extensions/Mantra/Mantra.ts +88 -0
- package/src/lib/components/editor/extensions/Mention/Mention.ts +184 -0
- package/src/lib/components/editor/extensions/Mention/MentionHoverContent.tsx +158 -0
- package/src/lib/components/editor/extensions/NodeWrapper.tsx +57 -0
- package/src/lib/components/editor/extensions/Paragraph/Paragraph.ts +25 -0
- package/src/lib/components/editor/extensions/ParagraphIndent.ts +87 -0
- package/src/lib/components/editor/extensions/Passage/EditLabel.tsx +57 -0
- package/src/lib/components/editor/extensions/Passage/EditorOptions.tsx +29 -0
- package/src/lib/components/editor/extensions/Passage/Passage.tsx +238 -0
- package/src/lib/components/editor/extensions/Passage/PassageNode.ts +223 -0
- package/src/lib/components/editor/extensions/Passage/ReaderOptions.tsx +55 -0
- package/src/lib/components/editor/extensions/Passage/ShowAnnotations.tsx +92 -0
- package/src/lib/components/editor/extensions/Passage/index.ts +1 -0
- package/src/lib/components/editor/extensions/Passage/label.spec.ts +118 -0
- package/src/lib/components/editor/extensions/Passage/label.ts +39 -0
- package/src/lib/components/editor/extensions/Placeholder.ts +9 -0
- package/src/lib/components/editor/extensions/SlashCommand/SlashCommand.ts +65 -0
- package/src/lib/components/editor/extensions/SlashCommand/SuggestionList.tsx +109 -0
- package/src/lib/components/editor/extensions/SlashCommand/Suggestions.ts +185 -0
- package/src/lib/components/editor/extensions/SmallCaps.ts +110 -0
- package/src/lib/components/editor/extensions/StarterKit.ts +36 -0
- package/src/lib/components/editor/extensions/Subscript.ts +43 -0
- package/src/lib/components/editor/extensions/Superscript.ts +43 -0
- package/src/lib/components/editor/extensions/Table.ts +32 -0
- package/src/lib/components/editor/extensions/TextAlign.ts +5 -0
- package/src/lib/components/editor/extensions/TitleMetadata.ts +40 -0
- package/src/lib/components/editor/extensions/TitleNode.ts +133 -0
- package/src/lib/components/editor/extensions/TitlesNode.ts +102 -0
- package/src/lib/components/editor/extensions/Trailer.ts +57 -0
- package/src/lib/components/editor/extensions/TranslationDocument.ts +7 -0
- package/src/lib/components/editor/extensions/TranslationMetadata.ts +58 -0
- package/src/lib/components/editor/extensions/Underline.ts +43 -0
- package/src/lib/components/editor/hooks/index.ts +4 -0
- package/src/lib/components/editor/hooks/useBlockEditor.ts +53 -0
- package/src/lib/components/editor/hooks/useDefaultExtensions.ts +39 -0
- package/src/lib/components/editor/hooks/useDirtyStore.ts +33 -0
- package/src/lib/components/editor/hooks/useTranslationExtensions.ts +148 -0
- package/src/lib/components/editor/index.ts +10 -0
- package/src/lib/components/editor/menus/EmptyBubbleMenu.tsx +42 -0
- package/src/lib/components/editor/menus/MainBubbleMenu.tsx +51 -0
- package/src/lib/components/editor/menus/TranslationBubbleMenu.tsx +57 -0
- package/src/lib/components/editor/menus/index.ts +3 -0
- package/src/lib/components/editor/menus/selectors/EndNoteSelector.tsx +388 -0
- package/src/lib/components/editor/menus/selectors/GlossarySelector.tsx +63 -0
- package/src/lib/components/editor/menus/selectors/LinkSelector.tsx +68 -0
- package/src/lib/components/editor/menus/selectors/MantraSelector.tsx +119 -0
- package/src/lib/components/editor/menus/selectors/NodeSelector.tsx +144 -0
- package/src/lib/components/editor/menus/selectors/ParagraphButtons.tsx +68 -0
- package/src/lib/components/editor/menus/selectors/SelectorInputField.tsx +68 -0
- package/src/lib/components/editor/menus/selectors/TextAlignSelector.tsx +89 -0
- package/src/lib/components/editor/menus/selectors/TextButtons.tsx +89 -0
- package/src/lib/components/editor/menus/selectors/TranslationNodeSelector.tsx +143 -0
- package/src/lib/components/editor/menus/selectors/TranslationTextButtons.tsx +125 -0
- package/src/lib/components/editor/menus/selectors/index.ts +5 -0
- package/src/lib/components/editor/save-filter.spec.ts +94 -0
- package/src/lib/components/editor/save-filter.ts +27 -0
- package/src/lib/components/editor/util.ts +304 -0
- package/src/lib/components/index.ts +3 -0
- package/src/lib/components/reader/ReaderBackMatterPage.tsx +62 -0
- package/src/lib/components/reader/ReaderBackMatterPanel.tsx +53 -0
- package/src/lib/components/reader/ReaderBodyPage.tsx +46 -0
- package/src/lib/components/reader/ReaderBodyPanel.tsx +68 -0
- package/src/lib/components/reader/ReaderLayout.tsx +39 -0
- package/src/lib/components/reader/ReaderLeftPanel.tsx +8 -0
- package/src/lib/components/reader/ReaderLeftPanelPage.tsx +31 -0
- package/src/lib/components/reader/TranslationReader.tsx +28 -0
- package/src/lib/components/reader/index.ts +2 -0
- package/src/lib/components/reader/ssr.ts +3 -0
- package/src/lib/components/shared/AiSummarizerPage.tsx +12 -0
- package/src/lib/components/shared/BackMatterPanel.tsx +143 -0
- package/src/lib/components/shared/BodyPanel.tsx +214 -0
- package/src/lib/components/shared/HoverCardProvider.tsx +407 -0
- package/src/lib/components/shared/Imprint.tsx +24 -0
- package/src/lib/components/shared/LabeledElement.tsx +133 -0
- package/src/lib/components/shared/LeftPanel.tsx +65 -0
- package/src/lib/components/shared/NavigationContext.ts +64 -0
- package/src/lib/components/shared/NavigationProvider.tsx +368 -0
- package/src/lib/components/shared/OpenGraphImage.tsx +75 -0
- package/src/lib/components/shared/PassageSkeleton.tsx +10 -0
- package/src/lib/components/shared/RestrictionWarning.tsx +177 -0
- package/src/lib/components/shared/SourceReader.tsx +83 -0
- package/src/lib/components/shared/SuggestRevisionForm.tsx +99 -0
- package/src/lib/components/shared/TableOfContents.tsx +280 -0
- package/src/lib/components/shared/ThreeColumnRenderer.tsx +54 -0
- package/src/lib/components/shared/TranslationHeader.tsx +86 -0
- package/src/lib/components/shared/TranslationHoverCard.tsx +84 -0
- package/src/lib/components/shared/TranslationSkeleton.tsx +16 -0
- package/src/lib/components/shared/TranslationTable.tsx +155 -0
- package/src/lib/components/shared/bibliography/BibliographyBody.tsx +28 -0
- package/src/lib/components/shared/bibliography/BibliographyList.tsx +63 -0
- package/src/lib/components/shared/bibliography/index.ts +1 -0
- package/src/lib/components/shared/generate-metadata.ts +44 -0
- package/src/lib/components/shared/glossary/GlossaryInstanceBody.tsx +144 -0
- package/src/lib/components/shared/glossary/GlossaryPaginationProvider.tsx +317 -0
- package/src/lib/components/shared/glossary/GlossarySkeleton.tsx +19 -0
- package/src/lib/components/shared/glossary/GlossaryTermList.tsx +58 -0
- package/src/lib/components/shared/glossary/index.ts +3 -0
- package/src/lib/components/shared/hooks/useGlossaryInstanceListener.tsx +42 -0
- package/src/lib/components/shared/hooks/useScrollInTab.tsx +43 -0
- package/src/lib/components/shared/hooks/useScrollPositionRestore.ts +274 -0
- package/src/lib/components/shared/hooks/useTohToggle.tsx +52 -0
- package/src/lib/components/shared/index.ts +11 -0
- package/src/lib/components/shared/ssr.ts +2 -0
- package/src/lib/components/shared/titles/FramedCard.tsx +132 -0
- package/src/lib/components/shared/titles/LongTitle.tsx +20 -0
- package/src/lib/components/shared/titles/LongTitles.tsx +28 -0
- package/src/lib/components/shared/titles/Title.tsx +54 -0
- package/src/lib/components/shared/titles/TitleDetails.tsx +47 -0
- package/src/lib/components/shared/titles/TitleForm.tsx +37 -0
- package/src/lib/components/shared/titles/Titles.tsx +114 -0
- package/src/lib/components/shared/titles/TitlesCard.tsx +113 -0
- package/src/lib/components/shared/titles/index.ts +8 -0
- package/src/lib/components/shared/types.ts +79 -0
- package/src/lib/components/ssr.ts +2 -0
- package/src/lib/exporters/abbreviation.spec.ts +31 -0
- package/src/lib/exporters/abbreviation.ts +22 -0
- package/src/lib/exporters/annotation.ts +193 -0
- package/src/lib/exporters/audio.spec.ts +77 -0
- package/src/lib/exporters/audio.ts +27 -0
- package/src/lib/exporters/blockquote.spec.ts +48 -0
- package/src/lib/exporters/blockquote.ts +24 -0
- package/src/lib/exporters/code.spec.ts +93 -0
- package/src/lib/exporters/code.ts +26 -0
- package/src/lib/exporters/end-note-link.spec.ts +104 -0
- package/src/lib/exporters/end-note-link.ts +35 -0
- package/src/lib/exporters/export.ts +12 -0
- package/src/lib/exporters/glossary-instance.spec.ts +85 -0
- package/src/lib/exporters/glossary-instance.ts +31 -0
- package/src/lib/exporters/has-abbreviation.spec.ts +31 -0
- package/src/lib/exporters/has-abbreviation.ts +21 -0
- package/src/lib/exporters/heading.spec.ts +80 -0
- package/src/lib/exporters/heading.ts +28 -0
- package/src/lib/exporters/image.spec.ts +48 -0
- package/src/lib/exporters/image.ts +25 -0
- package/src/lib/exporters/indent.spec.ts +58 -0
- package/src/lib/exporters/indent.ts +18 -0
- package/src/lib/exporters/index.ts +1 -0
- package/src/lib/exporters/internal-link.spec.ts +90 -0
- package/src/lib/exporters/internal-link.ts +35 -0
- package/src/lib/exporters/italic.spec.ts +84 -0
- package/src/lib/exporters/italic.ts +55 -0
- package/src/lib/exporters/leading-space.spec.ts +28 -0
- package/src/lib/exporters/leading-space.ts +16 -0
- package/src/lib/exporters/line-group.spec.ts +48 -0
- package/src/lib/exporters/line-group.ts +24 -0
- package/src/lib/exporters/line.spec.ts +48 -0
- package/src/lib/exporters/line.ts +24 -0
- package/src/lib/exporters/link.spec.ts +123 -0
- package/src/lib/exporters/link.ts +67 -0
- package/src/lib/exporters/list-item.spec.ts +48 -0
- package/src/lib/exporters/list-item.ts +24 -0
- package/src/lib/exporters/list.spec.ts +82 -0
- package/src/lib/exporters/list.ts +31 -0
- package/src/lib/exporters/mantra.spec.ts +51 -0
- package/src/lib/exporters/mantra.ts +25 -0
- package/src/lib/exporters/mention.ts +41 -0
- package/src/lib/exporters/paragraph.spec.ts +173 -0
- package/src/lib/exporters/paragraph.ts +32 -0
- package/src/lib/exporters/quote.spec.ts +56 -0
- package/src/lib/exporters/quote.ts +25 -0
- package/src/lib/exporters/span.spec.ts +118 -0
- package/src/lib/exporters/span.ts +44 -0
- package/src/lib/exporters/table-body-data.spec.ts +48 -0
- package/src/lib/exporters/table-body-data.ts +24 -0
- package/src/lib/exporters/table-body-header.spec.ts +48 -0
- package/src/lib/exporters/table-body-header.ts +24 -0
- package/src/lib/exporters/table-body-row.spec.ts +48 -0
- package/src/lib/exporters/table-body-row.ts +24 -0
- package/src/lib/exporters/table.spec.ts +48 -0
- package/src/lib/exporters/table.ts +24 -0
- package/src/lib/exporters/trailer.spec.ts +48 -0
- package/src/lib/exporters/trailer.ts +24 -0
- package/src/lib/exporters/util.ts +62 -0
- package/src/lib/passage.ts +182 -0
- package/src/lib/titles.ts +80 -0
- package/src/lib/transformers/abbreviation.spec.ts +87 -0
- package/src/lib/transformers/abbreviation.ts +30 -0
- package/src/lib/transformers/annotate.ts +146 -0
- package/src/lib/transformers/audio.spec.ts +55 -0
- package/src/lib/transformers/audio.ts +29 -0
- package/src/lib/transformers/blockquote.spec.ts +48 -0
- package/src/lib/transformers/blockquote.ts +41 -0
- package/src/lib/transformers/code.spec.ts +52 -0
- package/src/lib/transformers/code.ts +22 -0
- package/src/lib/transformers/deprecated.ts +7 -0
- package/src/lib/transformers/end-note-link.spec.ts +56 -0
- package/src/lib/transformers/end-note-link.ts +76 -0
- package/src/lib/transformers/glossary-instance.spec.ts +55 -0
- package/src/lib/transformers/glossary-instance.ts +40 -0
- package/src/lib/transformers/has-abbreviation.spec.ts +50 -0
- package/src/lib/transformers/has-abbreviation.ts +30 -0
- package/src/lib/transformers/heading.spec.ts +62 -0
- package/src/lib/transformers/heading.ts +30 -0
- package/src/lib/transformers/image.spec.ts +51 -0
- package/src/lib/transformers/image.ts +28 -0
- package/src/lib/transformers/indent.spec.ts +53 -0
- package/src/lib/transformers/indent.ts +17 -0
- package/src/lib/transformers/index.ts +33 -0
- package/src/lib/transformers/inline-title.spec.ts +59 -0
- package/src/lib/transformers/inline-title.ts +34 -0
- package/src/lib/transformers/internal-link.spec.ts +67 -0
- package/src/lib/transformers/internal-link.ts +65 -0
- package/src/lib/transformers/italic.ts +22 -0
- package/src/lib/transformers/leading-space.spec.ts +55 -0
- package/src/lib/transformers/leading-space.ts +17 -0
- package/src/lib/transformers/line-group.spec.ts +48 -0
- package/src/lib/transformers/line-group.ts +37 -0
- package/src/lib/transformers/line.spec.ts +54 -0
- package/src/lib/transformers/line.ts +27 -0
- package/src/lib/transformers/link.spec.ts +61 -0
- package/src/lib/transformers/link.ts +27 -0
- package/src/lib/transformers/list-item.spec.ts +48 -0
- package/src/lib/transformers/list-item.ts +37 -0
- package/src/lib/transformers/list.spec.ts +58 -0
- package/src/lib/transformers/list.ts +42 -0
- package/src/lib/transformers/mantra.spec.ts +58 -0
- package/src/lib/transformers/mantra.ts +28 -0
- package/src/lib/transformers/mention.ts +70 -0
- package/src/lib/transformers/paragraph.spec.ts +46 -0
- package/src/lib/transformers/paragraph.ts +26 -0
- package/src/lib/transformers/quote.spec.ts +42 -0
- package/src/lib/transformers/quote.ts +3 -0
- package/src/lib/transformers/quoted.ts +3 -0
- package/src/lib/transformers/recurse.ts +76 -0
- package/src/lib/transformers/reference.ts +3 -0
- package/src/lib/transformers/span.spec.ts +68 -0
- package/src/lib/transformers/span.ts +78 -0
- package/src/lib/transformers/split-at.ts +58 -0
- package/src/lib/transformers/split-block.ts +110 -0
- package/src/lib/transformers/split-content.ts +67 -0
- package/src/lib/transformers/split-insert.ts +76 -0
- package/src/lib/transformers/split-marks.ts +42 -0
- package/src/lib/transformers/split-node.ts +138 -0
- package/src/lib/transformers/table-body-data.spec.ts +44 -0
- package/src/lib/transformers/table-body-data.ts +29 -0
- package/src/lib/transformers/table-body-header.spec.ts +44 -0
- package/src/lib/transformers/table-body-header.ts +29 -0
- package/src/lib/transformers/table-body-row.spec.ts +44 -0
- package/src/lib/transformers/table-body-row.ts +29 -0
- package/src/lib/transformers/table.spec.ts +47 -0
- package/src/lib/transformers/table.ts +29 -0
- package/src/lib/transformers/trailer.spec.ts +43 -0
- package/src/lib/transformers/trailer.ts +26 -0
- package/src/lib/transformers/transformer.ts +25 -0
- package/src/lib/transformers/unknown.ts +8 -0
- package/src/lib/transformers/util.ts +20 -0
- package/src/lib/types.ts +10 -0
- package/src/ssr.ts +1 -0
- package/tsconfig.json +20 -0
- package/tsconfig.lib.json +29 -0
- package/tsconfig.spec.json +22 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { cn } from '@eightyfourthousand/lib-utils';
|
|
4
|
+
import { Editor } from '@tiptap/core';
|
|
5
|
+
import { useEditorState } from '@tiptap/react';
|
|
6
|
+
import {
|
|
7
|
+
BoldIcon,
|
|
8
|
+
CaseUpperIcon,
|
|
9
|
+
ItalicIcon,
|
|
10
|
+
SubscriptIcon,
|
|
11
|
+
SuperscriptIcon,
|
|
12
|
+
UnderlineIcon,
|
|
13
|
+
} from 'lucide-react';
|
|
14
|
+
import { Button, Separator } from '@eightyfourthousand/design-system';
|
|
15
|
+
import { LinkSelector } from './LinkSelector';
|
|
16
|
+
import { MantraSelector } from './MantraSelector';
|
|
17
|
+
import { EndNoteSelector } from './EndNoteSelector';
|
|
18
|
+
import { GlossarySelector } from './GlossarySelector';
|
|
19
|
+
|
|
20
|
+
interface SelectorResult {
|
|
21
|
+
isBold: boolean;
|
|
22
|
+
isItalic: boolean;
|
|
23
|
+
isSmallCaps: boolean;
|
|
24
|
+
isSubscript: boolean;
|
|
25
|
+
isSuperscript: boolean;
|
|
26
|
+
isUnderline: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const items = [
|
|
30
|
+
{
|
|
31
|
+
icon: BoldIcon,
|
|
32
|
+
onClick: (editor: Editor, state: SelectorResult) =>
|
|
33
|
+
state.isBold
|
|
34
|
+
? editor.chain().focus().unsetBold().run()
|
|
35
|
+
: editor.chain().focus().setBold().run(),
|
|
36
|
+
isActive: (state: SelectorResult) => state.isBold,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
icon: ItalicIcon,
|
|
40
|
+
onClick: (editor: Editor, state: SelectorResult) =>
|
|
41
|
+
state.isItalic
|
|
42
|
+
? editor.chain().focus().unsetItalic().run()
|
|
43
|
+
: editor.chain().focus().setItalic().run(),
|
|
44
|
+
isActive: (state: SelectorResult) => state.isItalic,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
icon: UnderlineIcon,
|
|
48
|
+
onClick: (editor: Editor, state: SelectorResult) =>
|
|
49
|
+
state.isUnderline
|
|
50
|
+
? editor.chain().focus().unsetUnderline().run()
|
|
51
|
+
: editor.chain().focus().setUnderline().run(),
|
|
52
|
+
isActive: (state: SelectorResult) => state.isUnderline,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
icon: SubscriptIcon,
|
|
56
|
+
onClick: (editor: Editor, state: SelectorResult) =>
|
|
57
|
+
state.isSubscript
|
|
58
|
+
? editor.chain().focus().unsetSubscript().run()
|
|
59
|
+
: editor.chain().focus().setSubscript().run(),
|
|
60
|
+
isActive: (state: SelectorResult) => state.isSubscript,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
icon: SuperscriptIcon,
|
|
64
|
+
onClick: (editor: Editor, state: SelectorResult) =>
|
|
65
|
+
state.isSuperscript
|
|
66
|
+
? editor.chain().focus().unsetSuperscript().run()
|
|
67
|
+
: editor.chain().focus().setSuperscript().run(),
|
|
68
|
+
isActive: (state: SelectorResult) => state.isSuperscript,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
icon: CaseUpperIcon,
|
|
72
|
+
onClick: (editor: Editor, state: SelectorResult) =>
|
|
73
|
+
state.isSmallCaps
|
|
74
|
+
? editor.chain().focus().unsetSmallCaps().run()
|
|
75
|
+
: editor.chain().focus().setSmallCaps().run(),
|
|
76
|
+
isActive: (state: SelectorResult) => state.isSmallCaps,
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
export const TranslationTextButtons = ({ editor }: { editor: Editor }) => {
|
|
81
|
+
const editorState = useEditorState<SelectorResult>({
|
|
82
|
+
editor,
|
|
83
|
+
selector: (instance) => ({
|
|
84
|
+
isBold: instance.editor.isActive('bold'),
|
|
85
|
+
isItalic: instance.editor.isActive('italic'),
|
|
86
|
+
isUnderline: instance.editor.isActive('underline'),
|
|
87
|
+
isSmallCaps: instance.editor.isActive('smallCaps'),
|
|
88
|
+
isSubscript: instance.editor.isActive('subscript'),
|
|
89
|
+
isSuperscript: instance.editor.isActive('superscript'),
|
|
90
|
+
}),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<>
|
|
95
|
+
{items.map((item, i) => {
|
|
96
|
+
return (
|
|
97
|
+
<Button
|
|
98
|
+
key={i}
|
|
99
|
+
variant="ghost"
|
|
100
|
+
size="icon"
|
|
101
|
+
className="rounded-none flex-shrink-0"
|
|
102
|
+
onClick={() => {
|
|
103
|
+
item.onClick(editor, editorState);
|
|
104
|
+
}}
|
|
105
|
+
>
|
|
106
|
+
<item.icon
|
|
107
|
+
className={cn(
|
|
108
|
+
'size-4',
|
|
109
|
+
item.isActive(editorState)
|
|
110
|
+
? 'text-foreground'
|
|
111
|
+
: 'text-muted-foreground',
|
|
112
|
+
)}
|
|
113
|
+
strokeWidth={2.5}
|
|
114
|
+
/>
|
|
115
|
+
</Button>
|
|
116
|
+
);
|
|
117
|
+
})}
|
|
118
|
+
<MantraSelector editor={editor} />
|
|
119
|
+
<Separator orientation="vertical" className="h-10" />
|
|
120
|
+
<GlossarySelector editor={editor} />
|
|
121
|
+
<LinkSelector editor={editor} />
|
|
122
|
+
<EndNoteSelector editor={editor} />
|
|
123
|
+
</>
|
|
124
|
+
);
|
|
125
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { computeSavePayload } from './save-filter';
|
|
2
|
+
|
|
3
|
+
describe('computeSavePayload', () => {
|
|
4
|
+
it('should return dirty UUIDs as uuidsToSave when no deletions', () => {
|
|
5
|
+
const result = computeSavePayload({
|
|
6
|
+
dirtyUuids: new Set(['a', 'b']),
|
|
7
|
+
deletedUuids: new Set(),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
expect(result.uuidsToSave).toEqual(['a', 'b']);
|
|
11
|
+
expect(result.uuidsToDelete).toEqual([]);
|
|
12
|
+
expect(result.hasChanges).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should return deleted UUIDs as uuidsToDelete when no dirty', () => {
|
|
16
|
+
const result = computeSavePayload({
|
|
17
|
+
dirtyUuids: new Set(),
|
|
18
|
+
deletedUuids: new Set(['x']),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
expect(result.uuidsToSave).toEqual([]);
|
|
22
|
+
expect(result.uuidsToDelete).toEqual(['x']);
|
|
23
|
+
expect(result.hasChanges).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should exclude deleted UUIDs from the save list', () => {
|
|
27
|
+
const result = computeSavePayload({
|
|
28
|
+
dirtyUuids: new Set(['a', 'b', 'c']),
|
|
29
|
+
deletedUuids: new Set(['b']),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
expect(result.uuidsToSave).toEqual(['a', 'c']);
|
|
33
|
+
expect(result.uuidsToDelete).toEqual(['b']);
|
|
34
|
+
expect(result.hasChanges).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should handle a UUID that is both dirty and deleted', () => {
|
|
38
|
+
const result = computeSavePayload({
|
|
39
|
+
dirtyUuids: new Set(['a']),
|
|
40
|
+
deletedUuids: new Set(['a']),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
expect(result.uuidsToSave).toEqual([]);
|
|
44
|
+
expect(result.uuidsToDelete).toEqual(['a']);
|
|
45
|
+
expect(result.hasChanges).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should report no changes when both sets are empty', () => {
|
|
49
|
+
const result = computeSavePayload({
|
|
50
|
+
dirtyUuids: new Set(),
|
|
51
|
+
deletedUuids: new Set(),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
expect(result.uuidsToSave).toEqual([]);
|
|
55
|
+
expect(result.uuidsToDelete).toEqual([]);
|
|
56
|
+
expect(result.hasChanges).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should handle split scenario: original dirty + new dirty, none deleted', () => {
|
|
60
|
+
const result = computeSavePayload({
|
|
61
|
+
dirtyUuids: new Set(['original', 'new-split']),
|
|
62
|
+
deletedUuids: new Set(),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
expect(result.uuidsToSave).toEqual(
|
|
66
|
+
expect.arrayContaining(['original', 'new-split']),
|
|
67
|
+
);
|
|
68
|
+
expect(result.uuidsToSave).toHaveLength(2);
|
|
69
|
+
expect(result.uuidsToDelete).toEqual([]);
|
|
70
|
+
expect(result.hasChanges).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should handle merge scenario: merged passage dirty + old passage deleted', () => {
|
|
74
|
+
const result = computeSavePayload({
|
|
75
|
+
dirtyUuids: new Set(['passage-a', 'passage-b']),
|
|
76
|
+
deletedUuids: new Set(['passage-b']),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
expect(result.uuidsToSave).toEqual(['passage-a']);
|
|
80
|
+
expect(result.uuidsToDelete).toEqual(['passage-b']);
|
|
81
|
+
expect(result.hasChanges).toBe(true);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should handle delete-only scenario: passage deleted without edits', () => {
|
|
85
|
+
const result = computeSavePayload({
|
|
86
|
+
dirtyUuids: new Set(),
|
|
87
|
+
deletedUuids: new Set(['deleted-passage']),
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
expect(result.uuidsToSave).toEqual([]);
|
|
91
|
+
expect(result.uuidsToDelete).toEqual(['deleted-passage']);
|
|
92
|
+
expect(result.hasChanges).toBe(true);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute which passage UUIDs should be saved and which should be deleted.
|
|
3
|
+
* Passages that are both dirty and deleted are excluded from the save list
|
|
4
|
+
* (they no longer exist in the editor).
|
|
5
|
+
*/
|
|
6
|
+
export const computeSavePayload = ({
|
|
7
|
+
dirtyUuids,
|
|
8
|
+
deletedUuids,
|
|
9
|
+
}: {
|
|
10
|
+
dirtyUuids: Set<string>;
|
|
11
|
+
deletedUuids: Set<string>;
|
|
12
|
+
}): {
|
|
13
|
+
uuidsToSave: string[];
|
|
14
|
+
uuidsToDelete: string[];
|
|
15
|
+
hasChanges: boolean;
|
|
16
|
+
} => {
|
|
17
|
+
const uuidsToDelete = Array.from(deletedUuids);
|
|
18
|
+
const uuidsToSave = Array.from(dirtyUuids).filter(
|
|
19
|
+
(uuid) => !deletedUuids.has(uuid),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
uuidsToSave,
|
|
24
|
+
uuidsToDelete,
|
|
25
|
+
hasChanges: uuidsToSave.length > 0 || uuidsToDelete.length > 0,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MarkViewProps,
|
|
3
|
+
mergeAttributes,
|
|
4
|
+
NodeViewProps,
|
|
5
|
+
NodeViewRendererProps,
|
|
6
|
+
} from '@tiptap/react';
|
|
7
|
+
import { Editor } from '@tiptap/core';
|
|
8
|
+
import { HTMLElementType } from 'react';
|
|
9
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* WeakMap to associate DOM elements with their editor instances.
|
|
13
|
+
* Used by HoverCardProvider to find the correct editor for a hovered element.
|
|
14
|
+
*/
|
|
15
|
+
const editorElementMap = new WeakMap<HTMLElement, Editor>();
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Registers an editor for a DOM element.
|
|
19
|
+
* Call this when creating mark/node views to enable hover card functionality.
|
|
20
|
+
*/
|
|
21
|
+
export const registerEditorElement = (element: HTMLElement, editor: Editor) => {
|
|
22
|
+
editorElementMap.set(element, editor);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Gets the editor associated with a DOM element.
|
|
27
|
+
*/
|
|
28
|
+
export const getEditorForElement = (
|
|
29
|
+
element: HTMLElement,
|
|
30
|
+
): Editor | undefined => {
|
|
31
|
+
return editorElementMap.get(element);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Validates and updates the attributes of a Node.
|
|
36
|
+
* Specifically, it ensures that the node has a unique 'uuid' attribute.
|
|
37
|
+
* If the 'uuid' is missing or duplicates the previous node's 'uuid',
|
|
38
|
+
* a new UUID is generated and assigned. In the case of duplication, all
|
|
39
|
+
* global attributes are set to their default values.
|
|
40
|
+
*/
|
|
41
|
+
export const validateAttrs = ({
|
|
42
|
+
node,
|
|
43
|
+
editor,
|
|
44
|
+
getPos,
|
|
45
|
+
updateAttributes,
|
|
46
|
+
}: Partial<NodeViewProps>) => {
|
|
47
|
+
if (!node?.attrs.uuid) {
|
|
48
|
+
updateAttributes?.({ uuid: uuidv4() });
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const pos = getPos?.();
|
|
53
|
+
if (pos === null || pos === undefined) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// check if previous node has same uuid, if so, set a new one
|
|
58
|
+
const $pos = editor?.state.doc.resolve(pos);
|
|
59
|
+
const parent = $pos?.parent;
|
|
60
|
+
const index = $pos?.index();
|
|
61
|
+
if (!parent || index === null || index === undefined) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (index > 0 && parent.child(index - 1).attrs.uuid === node.attrs.uuid) {
|
|
66
|
+
const attrs: { [attr: string]: unknown } = {
|
|
67
|
+
...node.attrs,
|
|
68
|
+
uuid: uuidv4(),
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// reset all global attributes to default values
|
|
72
|
+
if (attrs.leadingSpaceUuid) {
|
|
73
|
+
attrs.leadSpaceUuid = undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (attrs.hasLeadingSpace) {
|
|
77
|
+
attrs.hasLeadingSpace = false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (attrs.indentUuid) {
|
|
81
|
+
attrs.indentUuid = undefined;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (attrs.hasIndent) {
|
|
85
|
+
attrs.hasIndent = false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (attrs.hasParagraphIndent) {
|
|
89
|
+
attrs.hasParagraphIndent = false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
updateAttributes?.(attrs);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Finds the range of a given mark in the editor's document by its reference.
|
|
98
|
+
* Returns an object with 'from' and 'to' positions if found, otherwise undefined.
|
|
99
|
+
*/
|
|
100
|
+
export const findMarkRange = ({ editor, mark }: Partial<MarkViewProps>) => {
|
|
101
|
+
if (!editor || !mark) {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const { state } = editor;
|
|
106
|
+
const { doc, tr } = state;
|
|
107
|
+
|
|
108
|
+
let foundRange: { from: number; to: number } | undefined = undefined;
|
|
109
|
+
|
|
110
|
+
const thisMark = mark;
|
|
111
|
+
doc.descendants((node, pos) => {
|
|
112
|
+
let foundMark = false;
|
|
113
|
+
const from = tr.mapping.map(pos);
|
|
114
|
+
const to = from + node.nodeSize;
|
|
115
|
+
|
|
116
|
+
node.marks.forEach((m) => {
|
|
117
|
+
if (m === thisMark) {
|
|
118
|
+
foundMark = true;
|
|
119
|
+
foundRange = { from, to };
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
return !foundMark;
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
return foundRange;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Finds a mark in the editor's document by its UUID attribute.
|
|
132
|
+
* Returns an object with 'from', 'to', and 'mark' if found, otherwise undefined.
|
|
133
|
+
*/
|
|
134
|
+
export const findMarkByUuid = ({
|
|
135
|
+
editor,
|
|
136
|
+
uuid,
|
|
137
|
+
markType,
|
|
138
|
+
comparator = (mark, uuid) => mark.attrs.uuid === uuid,
|
|
139
|
+
}: {
|
|
140
|
+
editor: {
|
|
141
|
+
state: {
|
|
142
|
+
doc: MarkViewProps['editor']['state']['doc'];
|
|
143
|
+
tr: MarkViewProps['editor']['state']['tr'];
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
uuid: string;
|
|
147
|
+
markType: string;
|
|
148
|
+
comparator?: (mark: MarkViewProps['mark'], uuid: string) => boolean;
|
|
149
|
+
}): { from: number; to: number; mark: MarkViewProps['mark'] } | undefined => {
|
|
150
|
+
const { state } = editor;
|
|
151
|
+
const { doc, tr } = state;
|
|
152
|
+
|
|
153
|
+
let foundRange:
|
|
154
|
+
| { from: number; to: number; mark: MarkViewProps['mark'] }
|
|
155
|
+
| undefined = undefined;
|
|
156
|
+
|
|
157
|
+
doc.descendants((node, pos) => {
|
|
158
|
+
if (foundRange) return false;
|
|
159
|
+
|
|
160
|
+
const from = tr.mapping.map(pos);
|
|
161
|
+
const to = from + node.nodeSize;
|
|
162
|
+
|
|
163
|
+
for (const m of node.marks) {
|
|
164
|
+
if (m.type.name === markType && comparator(m, uuid)) {
|
|
165
|
+
foundRange = { from, to, mark: m };
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return true;
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
return foundRange;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export const findEndnoteMarkByUuid = ({
|
|
177
|
+
editor,
|
|
178
|
+
uuid,
|
|
179
|
+
}: {
|
|
180
|
+
editor: {
|
|
181
|
+
state: {
|
|
182
|
+
doc: MarkViewProps['editor']['state']['doc'];
|
|
183
|
+
tr: MarkViewProps['editor']['state']['tr'];
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
uuid: string;
|
|
187
|
+
}): { from: number; to: number; mark: MarkViewProps['mark'] } | undefined => {
|
|
188
|
+
return findMarkByUuid({
|
|
189
|
+
editor,
|
|
190
|
+
uuid,
|
|
191
|
+
markType: 'endNoteLink',
|
|
192
|
+
comparator: (mark, uuid) =>
|
|
193
|
+
mark.attrs.notes?.some((note: { uuid: string }) => note.uuid === uuid),
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Find a passage node in any editor by UUID.
|
|
199
|
+
* Returns { pos, node } or undefined.
|
|
200
|
+
*/
|
|
201
|
+
export const findPassageNode = (
|
|
202
|
+
editor: Editor,
|
|
203
|
+
passageUuid: string,
|
|
204
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
205
|
+
): { pos: number; node: any } | undefined => {
|
|
206
|
+
const { doc } = editor.state;
|
|
207
|
+
let result: { pos: number; node: typeof doc } | undefined;
|
|
208
|
+
|
|
209
|
+
doc.descendants((node, pos) => {
|
|
210
|
+
if (result) return false;
|
|
211
|
+
if (node.type.name === 'passage' && node.attrs.uuid === passageUuid) {
|
|
212
|
+
result = { pos, node };
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
return true;
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
return result;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Creates a function to update the attributes of a given HTML element.
|
|
223
|
+
* The returned function takes an object of attributes and sets them on the element.
|
|
224
|
+
*/
|
|
225
|
+
export const createUpdateAttributes = (element: HTMLElement) => {
|
|
226
|
+
return (attrs: { [key: string]: unknown }) => {
|
|
227
|
+
Object.keys(attrs).forEach((key) => {
|
|
228
|
+
element.setAttribute(key, attrs[key] as string);
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Creates a NodeView DOM element for a given node and extension.
|
|
235
|
+
* It sets up the element with merged attributes and validates them.
|
|
236
|
+
*/
|
|
237
|
+
export const createNodeViewDom = ({
|
|
238
|
+
editor,
|
|
239
|
+
getPos,
|
|
240
|
+
node,
|
|
241
|
+
extension,
|
|
242
|
+
HTMLAttributes,
|
|
243
|
+
element,
|
|
244
|
+
className,
|
|
245
|
+
}: Partial<NodeViewRendererProps> & {
|
|
246
|
+
element: HTMLElementType;
|
|
247
|
+
className?: string;
|
|
248
|
+
}) => {
|
|
249
|
+
const dom = document.createElement(element);
|
|
250
|
+
const updateAttributes = createUpdateAttributes(dom);
|
|
251
|
+
|
|
252
|
+
const attributes = mergeAttributes(
|
|
253
|
+
node?.attrs || {},
|
|
254
|
+
extension?.options.HTMLAttributes,
|
|
255
|
+
HTMLAttributes || {},
|
|
256
|
+
{
|
|
257
|
+
class: className,
|
|
258
|
+
type: extension?.name,
|
|
259
|
+
},
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
updateAttributes(attributes);
|
|
263
|
+
|
|
264
|
+
validateAttrs({
|
|
265
|
+
node,
|
|
266
|
+
editor,
|
|
267
|
+
getPos,
|
|
268
|
+
updateAttributes,
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
return { dom, updateAttributes };
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Creates a MarkView DOM element for a given mark and extension.
|
|
276
|
+
* It sets up the element with merged attributes.
|
|
277
|
+
*/
|
|
278
|
+
export const createMarkViewDom = ({
|
|
279
|
+
mark,
|
|
280
|
+
extension,
|
|
281
|
+
HTMLAttributes,
|
|
282
|
+
element,
|
|
283
|
+
className,
|
|
284
|
+
}: Partial<MarkViewProps> & {
|
|
285
|
+
element: HTMLElementType;
|
|
286
|
+
className?: string;
|
|
287
|
+
}) => {
|
|
288
|
+
const dom = document.createElement(element);
|
|
289
|
+
const updateElementAttributes = createUpdateAttributes(dom);
|
|
290
|
+
|
|
291
|
+
const attributes = mergeAttributes(
|
|
292
|
+
mark?.attrs || {},
|
|
293
|
+
extension?.options.HTMLAttributes,
|
|
294
|
+
HTMLAttributes || {},
|
|
295
|
+
{
|
|
296
|
+
class: className,
|
|
297
|
+
type: extension?.name,
|
|
298
|
+
},
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
updateElementAttributes(attributes);
|
|
302
|
+
|
|
303
|
+
return { dom, updateAttributes: updateElementAttributes };
|
|
304
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createBuildGraphQLClient,
|
|
3
|
+
getTranslationBlocks,
|
|
4
|
+
getWorkGlossaryTerms,
|
|
5
|
+
getWorkBibliography,
|
|
6
|
+
} from '@eightyfourthousand/client-graphql/ssr';
|
|
7
|
+
import { isStaticFeatureEnabled } from '@eightyfourthousand/lib-instr/static';
|
|
8
|
+
import { ReaderBackMatterPanel } from './ReaderBackMatterPanel';
|
|
9
|
+
import { isUuid } from '@eightyfourthousand/lib-utils';
|
|
10
|
+
import { notFound } from 'next/navigation';
|
|
11
|
+
|
|
12
|
+
export const ReaderBackMatterPage = async ({
|
|
13
|
+
params,
|
|
14
|
+
}: {
|
|
15
|
+
params: Promise<{ slug: string }>;
|
|
16
|
+
}) => {
|
|
17
|
+
const { slug } = await params;
|
|
18
|
+
|
|
19
|
+
if (!isUuid(slug)) {
|
|
20
|
+
return notFound();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const graphqlClient = createBuildGraphQLClient();
|
|
24
|
+
const withAttestations = isStaticFeatureEnabled('glossary-attestations');
|
|
25
|
+
|
|
26
|
+
const [
|
|
27
|
+
{ blocks: endnotes },
|
|
28
|
+
{ blocks: abbreviations },
|
|
29
|
+
glossary,
|
|
30
|
+
bibliography,
|
|
31
|
+
] = await Promise.all([
|
|
32
|
+
getTranslationBlocks({
|
|
33
|
+
client: graphqlClient,
|
|
34
|
+
uuid: slug,
|
|
35
|
+
type: 'endnotes',
|
|
36
|
+
}),
|
|
37
|
+
getTranslationBlocks({
|
|
38
|
+
client: graphqlClient,
|
|
39
|
+
uuid: slug,
|
|
40
|
+
type: 'abbreviations',
|
|
41
|
+
}),
|
|
42
|
+
getWorkGlossaryTerms({
|
|
43
|
+
client: graphqlClient,
|
|
44
|
+
uuid: slug,
|
|
45
|
+
withAttestations,
|
|
46
|
+
}),
|
|
47
|
+
getWorkBibliography({
|
|
48
|
+
client: graphqlClient,
|
|
49
|
+
uuid: slug,
|
|
50
|
+
}),
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<ReaderBackMatterPanel
|
|
55
|
+
workUuid={slug}
|
|
56
|
+
abbreviations={abbreviations}
|
|
57
|
+
bibliography={bibliography}
|
|
58
|
+
endnotes={endnotes}
|
|
59
|
+
glossary={glossary}
|
|
60
|
+
/>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
|
+
import { BibliographyEntries } from '@eightyfourthousand/data-access';
|
|
5
|
+
import type { GlossaryTermsPage } from '@eightyfourthousand/client-graphql';
|
|
6
|
+
import { BackMatterPanel } from '../shared/BackMatterPanel';
|
|
7
|
+
import { TranslationRenderer } from '../shared/types';
|
|
8
|
+
import { TranslationReader } from '.';
|
|
9
|
+
import { TranslationEditorContent } from '../editor';
|
|
10
|
+
import { useNavigation } from '../shared/NavigationProvider';
|
|
11
|
+
|
|
12
|
+
export const ReaderBackMatterPanel = ({
|
|
13
|
+
workUuid,
|
|
14
|
+
endnotes,
|
|
15
|
+
glossary,
|
|
16
|
+
bibliography,
|
|
17
|
+
abbreviations,
|
|
18
|
+
}: {
|
|
19
|
+
workUuid: string;
|
|
20
|
+
endnotes: TranslationEditorContent;
|
|
21
|
+
glossary: GlossaryTermsPage;
|
|
22
|
+
bibliography: BibliographyEntries;
|
|
23
|
+
abbreviations: TranslationEditorContent;
|
|
24
|
+
}) => {
|
|
25
|
+
const { hasTranslationContent } = useNavigation();
|
|
26
|
+
if (!hasTranslationContent) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const renderTranslation = useCallback(
|
|
31
|
+
({ content, name, className }: TranslationRenderer) => (
|
|
32
|
+
<TranslationReader
|
|
33
|
+
content={content}
|
|
34
|
+
name={name}
|
|
35
|
+
className={className}
|
|
36
|
+
filter={name}
|
|
37
|
+
panel="right"
|
|
38
|
+
/>
|
|
39
|
+
),
|
|
40
|
+
[],
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<BackMatterPanel
|
|
45
|
+
workUuid={workUuid}
|
|
46
|
+
endnotes={endnotes}
|
|
47
|
+
glossary={glossary}
|
|
48
|
+
bibliography={bibliography}
|
|
49
|
+
abbreviations={abbreviations}
|
|
50
|
+
renderTranslation={renderTranslation}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
};
|