@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,118 @@
|
|
|
1
|
+
import type { Node, Mark } from '@tiptap/pm/model';
|
|
2
|
+
import { span } from './span';
|
|
3
|
+
|
|
4
|
+
describe('span exporter', () => {
|
|
5
|
+
it('should export bold span annotation correctly', () => {
|
|
6
|
+
const node = {
|
|
7
|
+
textContent: 'bold text',
|
|
8
|
+
} as unknown as Node;
|
|
9
|
+
|
|
10
|
+
const mark = {
|
|
11
|
+
type: { name: 'bold' },
|
|
12
|
+
attrs: {
|
|
13
|
+
uuid: 'span-uuid-1234',
|
|
14
|
+
},
|
|
15
|
+
} as unknown as Mark;
|
|
16
|
+
|
|
17
|
+
const result = span({
|
|
18
|
+
node,
|
|
19
|
+
mark,
|
|
20
|
+
parent: node,
|
|
21
|
+
root: node,
|
|
22
|
+
start: 0,
|
|
23
|
+
passageUuid: 'passage-uuid-1234',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
expect(result).toEqual({
|
|
27
|
+
uuid: 'span-uuid-1234',
|
|
28
|
+
passageUuid: 'passage-uuid-1234',
|
|
29
|
+
type: 'span',
|
|
30
|
+
start: 0,
|
|
31
|
+
end: 9,
|
|
32
|
+
textStyle: 'text-bold',
|
|
33
|
+
lang: undefined,
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should export smallCaps span annotation correctly', () => {
|
|
38
|
+
const node = {
|
|
39
|
+
textContent: 'small caps',
|
|
40
|
+
} as unknown as Node;
|
|
41
|
+
|
|
42
|
+
const mark = {
|
|
43
|
+
type: { name: 'smallCaps' },
|
|
44
|
+
attrs: {
|
|
45
|
+
uuid: 'span-uuid-5678',
|
|
46
|
+
},
|
|
47
|
+
} as unknown as Mark;
|
|
48
|
+
|
|
49
|
+
const result = span({
|
|
50
|
+
node,
|
|
51
|
+
mark,
|
|
52
|
+
parent: node,
|
|
53
|
+
root: node,
|
|
54
|
+
start: 5,
|
|
55
|
+
passageUuid: 'passage-uuid-1234',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(result).toEqual({
|
|
59
|
+
uuid: 'span-uuid-5678',
|
|
60
|
+
passageUuid: 'passage-uuid-1234',
|
|
61
|
+
type: 'span',
|
|
62
|
+
start: 5,
|
|
63
|
+
end: 15,
|
|
64
|
+
textStyle: 'small-caps',
|
|
65
|
+
lang: undefined,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should export span with language', () => {
|
|
70
|
+
const node = {
|
|
71
|
+
textContent: 'text',
|
|
72
|
+
} as unknown as Node;
|
|
73
|
+
|
|
74
|
+
const mark = {
|
|
75
|
+
type: { name: 'bold' },
|
|
76
|
+
attrs: {
|
|
77
|
+
uuid: 'span-uuid-lang',
|
|
78
|
+
lang: 'bo',
|
|
79
|
+
},
|
|
80
|
+
} as unknown as Mark;
|
|
81
|
+
|
|
82
|
+
const result = span({
|
|
83
|
+
node,
|
|
84
|
+
mark,
|
|
85
|
+
parent: node,
|
|
86
|
+
root: node,
|
|
87
|
+
start: 0,
|
|
88
|
+
passageUuid: 'passage-uuid-1234',
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
expect(result).toEqual({
|
|
92
|
+
uuid: 'span-uuid-lang',
|
|
93
|
+
passageUuid: 'passage-uuid-1234',
|
|
94
|
+
type: 'span',
|
|
95
|
+
start: 0,
|
|
96
|
+
end: 4,
|
|
97
|
+
textStyle: 'text-bold',
|
|
98
|
+
lang: 'bo',
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('should return undefined when mark is missing', () => {
|
|
103
|
+
const node = {
|
|
104
|
+
textContent: 'text',
|
|
105
|
+
} as unknown as Node;
|
|
106
|
+
|
|
107
|
+
const result = span({
|
|
108
|
+
node,
|
|
109
|
+
mark: undefined,
|
|
110
|
+
parent: node,
|
|
111
|
+
root: node,
|
|
112
|
+
start: 0,
|
|
113
|
+
passageUuid: 'passage-uuid-1234',
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
expect(result).toBeUndefined();
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ExtendedTranslationLanguage, SpanAnnotation } from '@eightyfourthousand/data-access';
|
|
2
|
+
import { Exporter, ExporterContext } from './export';
|
|
3
|
+
import { SpanMarkType } from '../types';
|
|
4
|
+
|
|
5
|
+
const SPAN_TYPE_FOR_MARK_TYPE: {
|
|
6
|
+
[key in SpanMarkType]: string;
|
|
7
|
+
} = {
|
|
8
|
+
bold: 'text-bold',
|
|
9
|
+
smallCaps: 'small-caps',
|
|
10
|
+
subscript: 'subscript',
|
|
11
|
+
superscript: 'superscript',
|
|
12
|
+
underline: 'underline',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const span: Exporter<SpanAnnotation> = ({
|
|
16
|
+
mark,
|
|
17
|
+
node,
|
|
18
|
+
parent,
|
|
19
|
+
start,
|
|
20
|
+
passageUuid,
|
|
21
|
+
}: ExporterContext): SpanAnnotation | undefined => {
|
|
22
|
+
if (!mark) {
|
|
23
|
+
console.warn('Span exporter called without mark');
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const uuid = mark?.attrs.uuid;
|
|
28
|
+
|
|
29
|
+
const textContent = node.textContent || parent.textContent || '';
|
|
30
|
+
const end = start + textContent.length;
|
|
31
|
+
const markType = mark.type.name as SpanMarkType;
|
|
32
|
+
const lang = mark?.attrs.lang as ExtendedTranslationLanguage;
|
|
33
|
+
const textStyle = SPAN_TYPE_FOR_MARK_TYPE[markType] || mark.attrs.textStyle;
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
uuid,
|
|
37
|
+
type: 'span',
|
|
38
|
+
passageUuid,
|
|
39
|
+
start,
|
|
40
|
+
end,
|
|
41
|
+
textStyle,
|
|
42
|
+
lang,
|
|
43
|
+
} as SpanAnnotation;
|
|
44
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Node } from '@tiptap/pm/model';
|
|
2
|
+
import { tableBodyData } from './table-body-data';
|
|
3
|
+
|
|
4
|
+
describe('tableBodyData exporter', () => {
|
|
5
|
+
it('should export tableBodyData annotation correctly', () => {
|
|
6
|
+
const node = {
|
|
7
|
+
attrs: {
|
|
8
|
+
uuid: 'table-data-uuid-1234',
|
|
9
|
+
},
|
|
10
|
+
textContent: 'Table cell content',
|
|
11
|
+
} as unknown as Node;
|
|
12
|
+
|
|
13
|
+
const result = tableBodyData({
|
|
14
|
+
node,
|
|
15
|
+
parent: node,
|
|
16
|
+
root: node,
|
|
17
|
+
start: 0,
|
|
18
|
+
passageUuid: 'passage-uuid-1234',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
expect(result).toEqual({
|
|
22
|
+
uuid: 'table-data-uuid-1234',
|
|
23
|
+
passageUuid: 'passage-uuid-1234',
|
|
24
|
+
type: 'tableBodyData',
|
|
25
|
+
start: 0,
|
|
26
|
+
end: 18,
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should return undefined when textContent is empty', () => {
|
|
31
|
+
const node = {
|
|
32
|
+
attrs: {
|
|
33
|
+
uuid: 'table-data-uuid-empty',
|
|
34
|
+
},
|
|
35
|
+
textContent: '',
|
|
36
|
+
} as unknown as Node;
|
|
37
|
+
|
|
38
|
+
const result = tableBodyData({
|
|
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 { TableBodyDataAnnotation } from '@eightyfourthousand/data-access';
|
|
2
|
+
import { Exporter } from './export';
|
|
3
|
+
|
|
4
|
+
export const tableBodyData: Exporter<TableBodyDataAnnotation> = ({
|
|
5
|
+
node,
|
|
6
|
+
start,
|
|
7
|
+
passageUuid,
|
|
8
|
+
}): TableBodyDataAnnotation | undefined => {
|
|
9
|
+
const textContent = node.textContent || '';
|
|
10
|
+
const uuid = node.attrs.uuid;
|
|
11
|
+
|
|
12
|
+
if (!textContent) {
|
|
13
|
+
console.warn(`Table body data item ${uuid} is empty`);
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
uuid,
|
|
19
|
+
type: 'tableBodyData',
|
|
20
|
+
passageUuid,
|
|
21
|
+
start,
|
|
22
|
+
end: start + textContent.length,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Node } from '@tiptap/pm/model';
|
|
2
|
+
import { tableBodyHeader } from './table-body-header';
|
|
3
|
+
|
|
4
|
+
describe('tableBodyHeader exporter', () => {
|
|
5
|
+
it('should export tableBodyHeader annotation correctly', () => {
|
|
6
|
+
const node = {
|
|
7
|
+
attrs: {
|
|
8
|
+
uuid: 'table-header-uuid-1234',
|
|
9
|
+
},
|
|
10
|
+
textContent: 'Header Cell',
|
|
11
|
+
} as unknown as Node;
|
|
12
|
+
|
|
13
|
+
const result = tableBodyHeader({
|
|
14
|
+
node,
|
|
15
|
+
parent: node,
|
|
16
|
+
root: node,
|
|
17
|
+
start: 0,
|
|
18
|
+
passageUuid: 'passage-uuid-1234',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
expect(result).toEqual({
|
|
22
|
+
uuid: 'table-header-uuid-1234',
|
|
23
|
+
passageUuid: 'passage-uuid-1234',
|
|
24
|
+
type: 'tableBodyHeader',
|
|
25
|
+
start: 0,
|
|
26
|
+
end: 11,
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should return undefined when textContent is empty', () => {
|
|
31
|
+
const node = {
|
|
32
|
+
attrs: {
|
|
33
|
+
uuid: 'table-header-uuid-empty',
|
|
34
|
+
},
|
|
35
|
+
textContent: '',
|
|
36
|
+
} as unknown as Node;
|
|
37
|
+
|
|
38
|
+
const result = tableBodyHeader({
|
|
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 { TableBodyHeaderAnnotation } from '@eightyfourthousand/data-access';
|
|
2
|
+
import { Exporter } from './export';
|
|
3
|
+
|
|
4
|
+
export const tableBodyHeader: Exporter<TableBodyHeaderAnnotation> = ({
|
|
5
|
+
node,
|
|
6
|
+
start,
|
|
7
|
+
passageUuid,
|
|
8
|
+
}): TableBodyHeaderAnnotation | undefined => {
|
|
9
|
+
const textContent = node.textContent || '';
|
|
10
|
+
const uuid = node.attrs.uuid;
|
|
11
|
+
|
|
12
|
+
if (!textContent) {
|
|
13
|
+
console.warn(`List item ${uuid} is empty`);
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
uuid,
|
|
19
|
+
type: 'tableBodyHeader',
|
|
20
|
+
passageUuid,
|
|
21
|
+
start,
|
|
22
|
+
end: start + textContent.length,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Node } from '@tiptap/pm/model';
|
|
2
|
+
import { tableBodyRow } from './table-body-row';
|
|
3
|
+
|
|
4
|
+
describe('tableBodyRow exporter', () => {
|
|
5
|
+
it('should export tableBodyRow annotation correctly', () => {
|
|
6
|
+
const node = {
|
|
7
|
+
attrs: {
|
|
8
|
+
uuid: 'table-row-uuid-1234',
|
|
9
|
+
},
|
|
10
|
+
textContent: 'Cell 1\tCell 2\tCell 3',
|
|
11
|
+
} as unknown as Node;
|
|
12
|
+
|
|
13
|
+
const result = tableBodyRow({
|
|
14
|
+
node,
|
|
15
|
+
parent: node,
|
|
16
|
+
root: node,
|
|
17
|
+
start: 0,
|
|
18
|
+
passageUuid: 'passage-uuid-1234',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
expect(result).toEqual({
|
|
22
|
+
uuid: 'table-row-uuid-1234',
|
|
23
|
+
passageUuid: 'passage-uuid-1234',
|
|
24
|
+
type: 'tableBodyRow',
|
|
25
|
+
start: 0,
|
|
26
|
+
end: 20,
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should return undefined when textContent is empty', () => {
|
|
31
|
+
const node = {
|
|
32
|
+
attrs: {
|
|
33
|
+
uuid: 'table-row-uuid-empty',
|
|
34
|
+
},
|
|
35
|
+
textContent: '',
|
|
36
|
+
} as unknown as Node;
|
|
37
|
+
|
|
38
|
+
const result = tableBodyRow({
|
|
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 { TableBodyRowAnnotation } from '@eightyfourthousand/data-access';
|
|
2
|
+
import { Exporter } from './export';
|
|
3
|
+
|
|
4
|
+
export const tableBodyRow: Exporter<TableBodyRowAnnotation> = ({
|
|
5
|
+
node,
|
|
6
|
+
start,
|
|
7
|
+
passageUuid,
|
|
8
|
+
}): TableBodyRowAnnotation | undefined => {
|
|
9
|
+
const textContent = node.textContent || '';
|
|
10
|
+
const uuid = node.attrs.uuid;
|
|
11
|
+
|
|
12
|
+
if (!textContent) {
|
|
13
|
+
console.warn(`List item ${uuid} is empty`);
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
uuid,
|
|
19
|
+
type: 'tableBodyRow',
|
|
20
|
+
passageUuid,
|
|
21
|
+
start,
|
|
22
|
+
end: start + textContent.length,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Node } from '@tiptap/pm/model';
|
|
2
|
+
import { table } from './table';
|
|
3
|
+
|
|
4
|
+
describe('table exporter', () => {
|
|
5
|
+
it('should export table annotation correctly', () => {
|
|
6
|
+
const node = {
|
|
7
|
+
attrs: {
|
|
8
|
+
uuid: 'table-uuid-1234',
|
|
9
|
+
},
|
|
10
|
+
textContent: 'Cell 1\tCell 2\nCell 3\tCell 4',
|
|
11
|
+
} as unknown as Node;
|
|
12
|
+
|
|
13
|
+
const result = table({
|
|
14
|
+
node,
|
|
15
|
+
parent: node,
|
|
16
|
+
root: node,
|
|
17
|
+
start: 0,
|
|
18
|
+
passageUuid: 'passage-uuid-1234',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
expect(result).toEqual({
|
|
22
|
+
uuid: 'table-uuid-1234',
|
|
23
|
+
passageUuid: 'passage-uuid-1234',
|
|
24
|
+
type: 'table',
|
|
25
|
+
start: 0,
|
|
26
|
+
end: 27,
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should return undefined when textContent is empty', () => {
|
|
31
|
+
const node = {
|
|
32
|
+
attrs: {
|
|
33
|
+
uuid: 'table-uuid-empty',
|
|
34
|
+
},
|
|
35
|
+
textContent: '',
|
|
36
|
+
} as unknown as Node;
|
|
37
|
+
|
|
38
|
+
const result = table({
|
|
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 { TableAnnotation } from '@eightyfourthousand/data-access';
|
|
2
|
+
import { Exporter } from './export';
|
|
3
|
+
|
|
4
|
+
export const table: Exporter<TableAnnotation> = ({
|
|
5
|
+
node,
|
|
6
|
+
start,
|
|
7
|
+
passageUuid,
|
|
8
|
+
}): TableAnnotation | undefined => {
|
|
9
|
+
const textContent = node.textContent || '';
|
|
10
|
+
const uuid = node.attrs.uuid;
|
|
11
|
+
|
|
12
|
+
if (!textContent) {
|
|
13
|
+
console.warn(`Table ${uuid} is empty`);
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
uuid,
|
|
19
|
+
type: 'table',
|
|
20
|
+
passageUuid,
|
|
21
|
+
start,
|
|
22
|
+
end: start + textContent.length,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Node } from '@tiptap/pm/model';
|
|
2
|
+
import { trailer } from './trailer';
|
|
3
|
+
|
|
4
|
+
describe('trailer exporter', () => {
|
|
5
|
+
it('should export trailer annotation correctly', () => {
|
|
6
|
+
const node = {
|
|
7
|
+
attrs: {
|
|
8
|
+
uuid: 'trailer-uuid-1234',
|
|
9
|
+
},
|
|
10
|
+
textContent: 'This concludes the chapter.',
|
|
11
|
+
} as unknown as Node;
|
|
12
|
+
|
|
13
|
+
const result = trailer({
|
|
14
|
+
node,
|
|
15
|
+
parent: node,
|
|
16
|
+
root: node,
|
|
17
|
+
start: 100,
|
|
18
|
+
passageUuid: 'passage-uuid-1234',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
expect(result).toEqual({
|
|
22
|
+
uuid: 'trailer-uuid-1234',
|
|
23
|
+
passageUuid: 'passage-uuid-1234',
|
|
24
|
+
type: 'trailer',
|
|
25
|
+
start: 100,
|
|
26
|
+
end: 127,
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should return undefined when textContent is missing', () => {
|
|
31
|
+
const node = {
|
|
32
|
+
attrs: {
|
|
33
|
+
uuid: 'trailer-uuid-empty',
|
|
34
|
+
},
|
|
35
|
+
textContent: '',
|
|
36
|
+
} as unknown as Node;
|
|
37
|
+
|
|
38
|
+
const result = trailer({
|
|
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 { TrailerAnnotation } from '@eightyfourthousand/data-access';
|
|
2
|
+
import { Exporter } from './export';
|
|
3
|
+
|
|
4
|
+
export const trailer: Exporter<TrailerAnnotation> = ({
|
|
5
|
+
node,
|
|
6
|
+
start,
|
|
7
|
+
passageUuid,
|
|
8
|
+
}) => {
|
|
9
|
+
const textContent = node.textContent;
|
|
10
|
+
const uuid = node.attrs.uuid;
|
|
11
|
+
|
|
12
|
+
if (!textContent) {
|
|
13
|
+
console.warn(`Trailer node ${uuid} is missing body text`);
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
uuid,
|
|
19
|
+
type: 'trailer',
|
|
20
|
+
passageUuid,
|
|
21
|
+
start,
|
|
22
|
+
end: start + textContent.length,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Node, Mark } from '@tiptap/pm/model';
|
|
2
|
+
|
|
3
|
+
export const findNodePosition = (
|
|
4
|
+
parent: Node,
|
|
5
|
+
uuid: string,
|
|
6
|
+
type: string,
|
|
7
|
+
): number | undefined => {
|
|
8
|
+
let textOffset = 0;
|
|
9
|
+
let targetFound = false;
|
|
10
|
+
|
|
11
|
+
const traverse = (node: Node): boolean => {
|
|
12
|
+
if (node.attrs?.uuid === uuid && node.type.name === type) {
|
|
13
|
+
targetFound = true;
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (node.isText) {
|
|
18
|
+
if (node.marks && node.marks.length > 0) {
|
|
19
|
+
for (const mark of node.marks) {
|
|
20
|
+
if (mark.attrs?.uuid === uuid && mark.type.name === type) {
|
|
21
|
+
targetFound = true;
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!targetFound) {
|
|
28
|
+
textOffset += node?.text?.length || 0;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Handle nodes with content
|
|
34
|
+
if (node.content && node.content.size > 0) {
|
|
35
|
+
for (let i = 0; i < node.content.childCount; i++) {
|
|
36
|
+
const child = node.content.child(i);
|
|
37
|
+
const found = traverse(child);
|
|
38
|
+
if (found) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return false;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
if (parent.content && parent.content.size > 0) {
|
|
48
|
+
for (let i = 0; i < parent.content.childCount; i++) {
|
|
49
|
+
const child = parent.content.child(i);
|
|
50
|
+
const found = traverse(child);
|
|
51
|
+
if (found) break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return targetFound ? textOffset : undefined;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const nodeNotFound = (node: Node | Mark) => {
|
|
59
|
+
console.warn(
|
|
60
|
+
`Could not find position of node with uuid ${node.attrs.uuid} and type ${node.type.name}`,
|
|
61
|
+
);
|
|
62
|
+
};
|