@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,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Annotation,
|
|
3
|
+
annotationsFromDTO,
|
|
4
|
+
PassageDTO,
|
|
5
|
+
passageFromDTO,
|
|
6
|
+
} from '@eightyfourthousand/data-access';
|
|
7
|
+
import { code } from './code';
|
|
8
|
+
import { blockFromPassage } from '../block';
|
|
9
|
+
import { findTextNodeWithMarks } from './recurse';
|
|
10
|
+
|
|
11
|
+
const dto: PassageDTO = {
|
|
12
|
+
sort: 1,
|
|
13
|
+
type: 'root',
|
|
14
|
+
uuid: 'passage-uuid-1234',
|
|
15
|
+
label: '',
|
|
16
|
+
xmlId: 'test-passage',
|
|
17
|
+
parent: 'test-parent',
|
|
18
|
+
content: 'Some code text here',
|
|
19
|
+
work_uuid: 'work-uuid-5678',
|
|
20
|
+
annotations: [
|
|
21
|
+
{
|
|
22
|
+
end: 14,
|
|
23
|
+
type: 'code',
|
|
24
|
+
uuid: 'code-uuid-1',
|
|
25
|
+
start: 5,
|
|
26
|
+
content: [],
|
|
27
|
+
passage_uuid: 'passage-uuid-1234',
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
describe('code transformer', () => {
|
|
33
|
+
const passage = passageFromDTO(
|
|
34
|
+
dto,
|
|
35
|
+
annotationsFromDTO(dto.annotations || [], dto.content.length),
|
|
36
|
+
);
|
|
37
|
+
const block = blockFromPassage(passage);
|
|
38
|
+
|
|
39
|
+
if (!block?.content) {
|
|
40
|
+
throw new Error('Block conversion failed');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
it('should transform code annotation correctly', () => {
|
|
44
|
+
const textNode = findTextNodeWithMarks(block);
|
|
45
|
+
expect(textNode).toBeDefined();
|
|
46
|
+
expect(textNode?.type).toBe('text');
|
|
47
|
+
expect(textNode?.marks).toBeDefined();
|
|
48
|
+
const codeMark = textNode?.marks?.find((m: any) => m.type === 'code');
|
|
49
|
+
expect(codeMark).toBeDefined();
|
|
50
|
+
expect(textNode?.text).toBe('code text');
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Transformer } from './transformer';
|
|
2
|
+
import { splitContent } from './split-content';
|
|
3
|
+
import { recurse } from './recurse';
|
|
4
|
+
|
|
5
|
+
export const code: Transformer = (ctx) => {
|
|
6
|
+
recurse({
|
|
7
|
+
...ctx,
|
|
8
|
+
until: ['text'],
|
|
9
|
+
transform: (ctx) =>
|
|
10
|
+
splitContent({
|
|
11
|
+
...ctx,
|
|
12
|
+
transform: ({ block }) => {
|
|
13
|
+
block.marks = [
|
|
14
|
+
...(block.marks || []),
|
|
15
|
+
{
|
|
16
|
+
type: 'code',
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
},
|
|
20
|
+
}),
|
|
21
|
+
});
|
|
22
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { annotationsFromDTO, PassageDTO, passageFromDTO } from '@eightyfourthousand/data-access';
|
|
2
|
+
import { blockFromPassage } from '../block';
|
|
3
|
+
import { findTextNodeWithMarks } from './recurse';
|
|
4
|
+
|
|
5
|
+
const dto: PassageDTO = {
|
|
6
|
+
sort: 1,
|
|
7
|
+
type: 'root',
|
|
8
|
+
uuid: 'passage-uuid-1234',
|
|
9
|
+
label: '',
|
|
10
|
+
xmlId: 'test-passage',
|
|
11
|
+
parent: 'test-parent',
|
|
12
|
+
content: 'Some text',
|
|
13
|
+
work_uuid: 'work-uuid-5678',
|
|
14
|
+
annotations: [
|
|
15
|
+
{
|
|
16
|
+
end: 9,
|
|
17
|
+
type: 'end-note-link',
|
|
18
|
+
uuid: 'endnote-link-uuid-1',
|
|
19
|
+
start: 9,
|
|
20
|
+
content: [
|
|
21
|
+
{
|
|
22
|
+
uuid: 'endnote-uuid-1',
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
passage_uuid: 'passage-uuid-1234',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
describe('endNoteLink transformer', () => {
|
|
31
|
+
const passage = passageFromDTO(
|
|
32
|
+
dto,
|
|
33
|
+
annotationsFromDTO(dto.annotations || [], dto.content.length),
|
|
34
|
+
);
|
|
35
|
+
const block = blockFromPassage(passage);
|
|
36
|
+
|
|
37
|
+
if (!block?.content) {
|
|
38
|
+
throw new Error('Block conversion failed');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
it('should transform endNoteLink annotation correctly', () => {
|
|
42
|
+
// Transformers are applied automatically in blockFromPassage
|
|
43
|
+
const textNode = findTextNodeWithMarks(block);
|
|
44
|
+
expect(textNode).toBeDefined();
|
|
45
|
+
expect(textNode?.type).toBe('text');
|
|
46
|
+
expect(textNode?.marks).toBeDefined();
|
|
47
|
+
const endnoteMark = textNode?.marks?.find(
|
|
48
|
+
(m: any) => m.type === 'endNoteLink',
|
|
49
|
+
);
|
|
50
|
+
expect(endnoteMark).toBeDefined();
|
|
51
|
+
expect(endnoteMark?.attrs?.notes).toBeDefined();
|
|
52
|
+
expect(endnoteMark?.attrs?.notes?.length).toBe(1);
|
|
53
|
+
expect(endnoteMark?.attrs?.notes?.[0].endNote).toBe('endnote-uuid-1');
|
|
54
|
+
expect(endnoteMark?.attrs?.notes?.[0].uuid).toBe('endnote-link-uuid-1');
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { EndNoteLinkAnnotation } from '@eightyfourthousand/data-access';
|
|
2
|
+
import { Transformer } from './transformer';
|
|
3
|
+
import { recurse } from './recurse';
|
|
4
|
+
import { splitContentAt } from './split-at';
|
|
5
|
+
import { splitContent } from './split-content';
|
|
6
|
+
|
|
7
|
+
const innerTransform: Transformer = ({ block, annotation }) => {
|
|
8
|
+
const { endNote, label, uuid, start, end, toh } =
|
|
9
|
+
annotation as EndNoteLinkAnnotation;
|
|
10
|
+
let endnoteMark = block.marks?.find((m) => m.type === 'endNoteLink');
|
|
11
|
+
const marks = block.marks || [];
|
|
12
|
+
const notes = endnoteMark?.attrs?.notes || [];
|
|
13
|
+
notes.push({
|
|
14
|
+
endNote,
|
|
15
|
+
label,
|
|
16
|
+
uuid,
|
|
17
|
+
start,
|
|
18
|
+
end,
|
|
19
|
+
location: end === 0 ? 'start' : 'end',
|
|
20
|
+
toh,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (endnoteMark) {
|
|
24
|
+
endnoteMark.attrs = endnoteMark.attrs || {};
|
|
25
|
+
endnoteMark.attrs.notes = notes;
|
|
26
|
+
} else {
|
|
27
|
+
endnoteMark = {
|
|
28
|
+
type: 'endNoteLink',
|
|
29
|
+
attrs: {
|
|
30
|
+
notes,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
marks.push(endnoteMark);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
block.marks = [...marks];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const endNoteLink: Transformer = (ctx) => {
|
|
40
|
+
const { annotation } = ctx;
|
|
41
|
+
const { endNote, uuid, end } = annotation as EndNoteLinkAnnotation;
|
|
42
|
+
|
|
43
|
+
if (!endNote) {
|
|
44
|
+
console.warn(`End note link ${uuid} is missing end note reference`);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const isStart = end === 0;
|
|
49
|
+
|
|
50
|
+
recurse({
|
|
51
|
+
...ctx,
|
|
52
|
+
until: ['text'],
|
|
53
|
+
transform: (ctx) => {
|
|
54
|
+
if (isStart) {
|
|
55
|
+
splitContent({
|
|
56
|
+
...ctx,
|
|
57
|
+
annotation: {
|
|
58
|
+
...annotation,
|
|
59
|
+
end: 1,
|
|
60
|
+
},
|
|
61
|
+
transform: ({ block }) => {
|
|
62
|
+
innerTransform({ ...ctx, block });
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
splitContentAt({
|
|
69
|
+
...ctx,
|
|
70
|
+
transform: ({ block }) => {
|
|
71
|
+
innerTransform({ ...ctx, block });
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { annotationsFromDTO, PassageDTO, passageFromDTO } from '@eightyfourthousand/data-access';
|
|
2
|
+
import { blockFromPassage } from '../block';
|
|
3
|
+
import { findTextNodeWithMarks } from './recurse';
|
|
4
|
+
|
|
5
|
+
const dto: PassageDTO = {
|
|
6
|
+
sort: 1,
|
|
7
|
+
type: 'root',
|
|
8
|
+
uuid: 'passage-uuid-1234',
|
|
9
|
+
label: '',
|
|
10
|
+
xmlId: 'test-passage',
|
|
11
|
+
parent: 'test-parent',
|
|
12
|
+
content: 'The Buddha taught the Dharma.',
|
|
13
|
+
work_uuid: 'work-uuid-5678',
|
|
14
|
+
annotations: [
|
|
15
|
+
{
|
|
16
|
+
end: 10,
|
|
17
|
+
type: 'glossary-instance',
|
|
18
|
+
uuid: 'glossary-instance-uuid-1',
|
|
19
|
+
start: 4,
|
|
20
|
+
content: [
|
|
21
|
+
{
|
|
22
|
+
uuid: 'glossary-entry-uuid-1',
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
passage_uuid: 'passage-uuid-1234',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
describe('glossaryInstance transformer', () => {
|
|
31
|
+
const passage = passageFromDTO(
|
|
32
|
+
dto,
|
|
33
|
+
annotationsFromDTO(dto.annotations || [], dto.content.length),
|
|
34
|
+
);
|
|
35
|
+
const block = blockFromPassage(passage);
|
|
36
|
+
|
|
37
|
+
if (!block?.content) {
|
|
38
|
+
throw new Error('Block conversion failed');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
it('should transform glossaryInstance annotation correctly', () => {
|
|
42
|
+
// Transformers are applied automatically in blockFromPassage
|
|
43
|
+
const textNode = findTextNodeWithMarks(block);
|
|
44
|
+
expect(textNode).toBeDefined();
|
|
45
|
+
expect(textNode?.type).toBe('text');
|
|
46
|
+
expect(textNode?.marks).toBeDefined();
|
|
47
|
+
const glossaryMark = textNode?.marks?.find(
|
|
48
|
+
(m: any) => m.type === 'glossaryInstance',
|
|
49
|
+
);
|
|
50
|
+
expect(glossaryMark).toBeDefined();
|
|
51
|
+
expect(glossaryMark?.attrs?.glossary).toBe('glossary-entry-uuid-1');
|
|
52
|
+
expect(glossaryMark?.attrs?.uuid).toBe('glossary-instance-uuid-1');
|
|
53
|
+
expect(textNode?.text).toBe('Buddha');
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { GlossaryInstanceAnnotation } from '@eightyfourthousand/data-access';
|
|
2
|
+
import { Transformer } from './transformer';
|
|
3
|
+
import { recurse } from './recurse';
|
|
4
|
+
import { splitContent } from './split-content';
|
|
5
|
+
|
|
6
|
+
export const glossaryInstance: Transformer = (ctx) => {
|
|
7
|
+
const { annotation } = ctx;
|
|
8
|
+
const { uuid, glossary, authority, toh } = annotation as GlossaryInstanceAnnotation;
|
|
9
|
+
|
|
10
|
+
if (!glossary) {
|
|
11
|
+
console.warn(`Glossary instance ${uuid} is missing glossary UUID`);
|
|
12
|
+
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
recurse({
|
|
17
|
+
...ctx,
|
|
18
|
+
until: ['text'],
|
|
19
|
+
transform: (ctx) => {
|
|
20
|
+
splitContent({
|
|
21
|
+
...ctx,
|
|
22
|
+
transform: (ctx) => {
|
|
23
|
+
const { block } = ctx;
|
|
24
|
+
block.marks = [
|
|
25
|
+
...(block.marks || []),
|
|
26
|
+
{
|
|
27
|
+
type: 'glossaryInstance',
|
|
28
|
+
attrs: {
|
|
29
|
+
authority,
|
|
30
|
+
glossary,
|
|
31
|
+
uuid,
|
|
32
|
+
toh,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { annotationsFromDTO, PassageDTO, passageFromDTO } from '@eightyfourthousand/data-access';
|
|
2
|
+
import { blockFromPassage } from '../block';
|
|
3
|
+
import { recurseForType } from './recurse';
|
|
4
|
+
|
|
5
|
+
const dto: PassageDTO = {
|
|
6
|
+
sort: 1,
|
|
7
|
+
type: 'root',
|
|
8
|
+
uuid: 'passage-uuid-1234',
|
|
9
|
+
label: '',
|
|
10
|
+
xmlId: 'test-passage',
|
|
11
|
+
parent: 'test-parent',
|
|
12
|
+
content: 'The 84000 project translates Tibetan texts.',
|
|
13
|
+
work_uuid: 'work-uuid-5678',
|
|
14
|
+
annotations: [
|
|
15
|
+
{
|
|
16
|
+
end: 10,
|
|
17
|
+
type: 'has-abbreviation',
|
|
18
|
+
uuid: 'has-abbr-uuid-1',
|
|
19
|
+
start: 4,
|
|
20
|
+
content: [
|
|
21
|
+
{
|
|
22
|
+
uuid: 'abbr-uuid-1',
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
passage_uuid: 'passage-uuid-1234',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
describe('hasAbbreviation transformer', () => {
|
|
31
|
+
const passage = passageFromDTO(
|
|
32
|
+
dto,
|
|
33
|
+
annotationsFromDTO(dto.annotations || [], dto.content.length),
|
|
34
|
+
);
|
|
35
|
+
const block = blockFromPassage(passage);
|
|
36
|
+
|
|
37
|
+
if (!block?.content) {
|
|
38
|
+
throw new Error('Block conversion failed');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
it('should transform hasAbbreviation annotation correctly', () => {
|
|
42
|
+
const hasAbbrNode = recurseForType({ block, until: 'hasAbbreviation' });
|
|
43
|
+
expect(hasAbbrNode).toBeDefined();
|
|
44
|
+
expect(hasAbbrNode?.type).toBe('hasAbbreviation');
|
|
45
|
+
expect(hasAbbrNode?.attrs?.abbreviation).toBe('abbr-uuid-1');
|
|
46
|
+
expect(hasAbbrNode?.attrs?.uuid).toBe('has-abbr-uuid-1');
|
|
47
|
+
expect(hasAbbrNode?.content?.[0]?.type).toBe('text');
|
|
48
|
+
expect(hasAbbrNode?.content?.[0]?.text).toBe('84000 ');
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { HasAbbreviationAnnotation } from '@eightyfourthousand/data-access';
|
|
2
|
+
import { recurse } from './recurse';
|
|
3
|
+
import { splitContent } from './split-content';
|
|
4
|
+
import { Transformer } from './transformer';
|
|
5
|
+
|
|
6
|
+
export const hasAbbreviation: Transformer = (ctx) => {
|
|
7
|
+
const { annotation } = ctx;
|
|
8
|
+
const { abbreviation, uuid } = annotation as HasAbbreviationAnnotation;
|
|
9
|
+
|
|
10
|
+
recurse({
|
|
11
|
+
until: ['text'],
|
|
12
|
+
...ctx,
|
|
13
|
+
transform: (ctx) => {
|
|
14
|
+
splitContent({
|
|
15
|
+
...ctx,
|
|
16
|
+
transform: ({ block }) => {
|
|
17
|
+
block.type = 'hasAbbreviation';
|
|
18
|
+
block.attrs = {
|
|
19
|
+
...block.attrs,
|
|
20
|
+
abbreviation,
|
|
21
|
+
uuid,
|
|
22
|
+
};
|
|
23
|
+
block.content = [
|
|
24
|
+
{ type: 'text', text: block.text, marks: block.marks },
|
|
25
|
+
];
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Annotation,
|
|
3
|
+
annotationsFromDTO,
|
|
4
|
+
PassageDTO,
|
|
5
|
+
passageFromDTO,
|
|
6
|
+
} from '@eightyfourthousand/data-access';
|
|
7
|
+
import { heading } from './heading';
|
|
8
|
+
import { blockFromPassage } from '../block';
|
|
9
|
+
|
|
10
|
+
const dto: PassageDTO = {
|
|
11
|
+
sort: 1,
|
|
12
|
+
type: 'root',
|
|
13
|
+
uuid: 'passage-uuid-1234',
|
|
14
|
+
label: '',
|
|
15
|
+
xmlId: 'test-passage',
|
|
16
|
+
parent: 'test-parent',
|
|
17
|
+
content: 'Chapter Title',
|
|
18
|
+
work_uuid: 'work-uuid-5678',
|
|
19
|
+
annotations: [
|
|
20
|
+
{
|
|
21
|
+
end: 13,
|
|
22
|
+
type: 'heading',
|
|
23
|
+
uuid: 'heading-uuid-1',
|
|
24
|
+
start: 0,
|
|
25
|
+
content: [
|
|
26
|
+
{
|
|
27
|
+
'heading-level': 'h2',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
'heading-type': 'chapter-title',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
passage_uuid: 'passage-uuid-1234',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
describe('heading transformer', () => {
|
|
39
|
+
const passage = passageFromDTO(
|
|
40
|
+
dto,
|
|
41
|
+
annotationsFromDTO(dto.annotations || [], dto.content.length),
|
|
42
|
+
);
|
|
43
|
+
const block = blockFromPassage(passage);
|
|
44
|
+
|
|
45
|
+
if (!block?.content) {
|
|
46
|
+
throw new Error('Block conversion failed');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
it('should transform heading annotation correctly', () => {
|
|
50
|
+
// The heading transformer should have already been applied during blockFromPassage
|
|
51
|
+
// The annotation is applied to the paragraph block inside the passage block
|
|
52
|
+
expect(block.content).toBeDefined();
|
|
53
|
+
expect(block.content?.length).toBeGreaterThan(0);
|
|
54
|
+
|
|
55
|
+
const paragraphBlock = block.content?.[0];
|
|
56
|
+
expect(paragraphBlock).toBeDefined();
|
|
57
|
+
expect(paragraphBlock?.type).toBe('heading');
|
|
58
|
+
expect(paragraphBlock?.attrs).toBeDefined();
|
|
59
|
+
expect(paragraphBlock?.attrs?.level).toBe(2);
|
|
60
|
+
expect(paragraphBlock?.attrs?.class).toBe('chapter-title');
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { HeadingAnnotation } from '@eightyfourthousand/data-access';
|
|
2
|
+
import { splitBlock } from './split-block';
|
|
3
|
+
import { Transformer } from './transformer';
|
|
4
|
+
import { recurse } from './recurse';
|
|
5
|
+
|
|
6
|
+
export const heading: Transformer = ({ root, parent, block, annotation }) => {
|
|
7
|
+
const heading = annotation as HeadingAnnotation;
|
|
8
|
+
const level = heading.level || 3;
|
|
9
|
+
const cls = heading.class;
|
|
10
|
+
|
|
11
|
+
recurse({
|
|
12
|
+
until: ['heading', 'paragraph'],
|
|
13
|
+
root,
|
|
14
|
+
parent,
|
|
15
|
+
block,
|
|
16
|
+
annotation,
|
|
17
|
+
transform: (ctx) =>
|
|
18
|
+
splitBlock({
|
|
19
|
+
...ctx,
|
|
20
|
+
transform: ({ block: item }) => {
|
|
21
|
+
item.type = 'heading';
|
|
22
|
+
item.attrs = {
|
|
23
|
+
...item.attrs,
|
|
24
|
+
level,
|
|
25
|
+
class: cls,
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { annotationsFromDTO, PassageDTO, passageFromDTO } from '@eightyfourthousand/data-access';
|
|
2
|
+
import { blockFromPassage } from '../block';
|
|
3
|
+
import { recurseForType } from './recurse';
|
|
4
|
+
|
|
5
|
+
const dto: PassageDTO = {
|
|
6
|
+
sort: 1,
|
|
7
|
+
type: 'root',
|
|
8
|
+
uuid: 'passage-uuid-1234',
|
|
9
|
+
label: '',
|
|
10
|
+
xmlId: 'test-passage',
|
|
11
|
+
parent: 'test-parent',
|
|
12
|
+
content: 'See the diagram below.',
|
|
13
|
+
work_uuid: 'work-uuid-5678',
|
|
14
|
+
annotations: [
|
|
15
|
+
{
|
|
16
|
+
end: 3,
|
|
17
|
+
type: 'image',
|
|
18
|
+
uuid: 'image-uuid-1',
|
|
19
|
+
start: 3,
|
|
20
|
+
content: [
|
|
21
|
+
{
|
|
22
|
+
src: 'https://example.com/image.jpg',
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
passage_uuid: 'passage-uuid-1234',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
describe('image transformer', () => {
|
|
31
|
+
const passage = passageFromDTO(
|
|
32
|
+
dto,
|
|
33
|
+
annotationsFromDTO(dto.annotations || [], dto.content.length),
|
|
34
|
+
);
|
|
35
|
+
const block = blockFromPassage(passage);
|
|
36
|
+
|
|
37
|
+
if (!block?.content) {
|
|
38
|
+
throw new Error('Block conversion failed');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
it('should transform image annotation correctly', () => {
|
|
42
|
+
const imageNode = recurseForType({
|
|
43
|
+
until: 'image',
|
|
44
|
+
block,
|
|
45
|
+
});
|
|
46
|
+
expect(imageNode).toBeDefined();
|
|
47
|
+
expect(imageNode?.type).toBe('image');
|
|
48
|
+
expect(imageNode?.attrs?.src).toBe('https://example.com/image.jpg');
|
|
49
|
+
expect(imageNode?.attrs?.uuid).toBe('image-uuid-1');
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ImageAnnotation } from '@eightyfourthousand/data-access';
|
|
2
|
+
import { Transformer } from './transformer';
|
|
3
|
+
import { recurse } from './recurse';
|
|
4
|
+
import { splitAndInsert } from './split-insert';
|
|
5
|
+
|
|
6
|
+
export const image: Transformer = (ctx) => {
|
|
7
|
+
const { annotation } = ctx;
|
|
8
|
+
const { src, uuid, start, end } = annotation as ImageAnnotation;
|
|
9
|
+
recurse({
|
|
10
|
+
...ctx,
|
|
11
|
+
until: ['paragraph'],
|
|
12
|
+
transform: (ctx) => {
|
|
13
|
+
splitAndInsert({
|
|
14
|
+
...ctx,
|
|
15
|
+
transform: ({ block }) => {
|
|
16
|
+
block.type = 'image';
|
|
17
|
+
block.attrs = {
|
|
18
|
+
...block.attrs,
|
|
19
|
+
src,
|
|
20
|
+
uuid,
|
|
21
|
+
start,
|
|
22
|
+
end,
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Annotation,
|
|
3
|
+
annotationsFromDTO,
|
|
4
|
+
PassageDTO,
|
|
5
|
+
passageFromDTO,
|
|
6
|
+
} from '@eightyfourthousand/data-access';
|
|
7
|
+
import { indent } from './indent';
|
|
8
|
+
import { blockFromPassage } from '../block';
|
|
9
|
+
|
|
10
|
+
const dto: PassageDTO = {
|
|
11
|
+
sort: 1,
|
|
12
|
+
type: 'root',
|
|
13
|
+
uuid: 'passage-uuid-1234',
|
|
14
|
+
label: '',
|
|
15
|
+
xmlId: 'test-passage',
|
|
16
|
+
parent: 'test-parent',
|
|
17
|
+
content: 'Indented paragraph text',
|
|
18
|
+
work_uuid: 'work-uuid-5678',
|
|
19
|
+
annotations: [
|
|
20
|
+
{
|
|
21
|
+
end: 23,
|
|
22
|
+
type: 'indent',
|
|
23
|
+
uuid: 'indent-uuid-1',
|
|
24
|
+
start: 0,
|
|
25
|
+
content: [],
|
|
26
|
+
passage_uuid: 'passage-uuid-1234',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
describe('indent transformer', () => {
|
|
32
|
+
const passage = passageFromDTO(
|
|
33
|
+
dto,
|
|
34
|
+
annotationsFromDTO(dto.annotations || [], dto.content.length),
|
|
35
|
+
);
|
|
36
|
+
const block = blockFromPassage(passage);
|
|
37
|
+
|
|
38
|
+
if (!block?.content) {
|
|
39
|
+
throw new Error('Block conversion failed');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
it('should transform indent annotation correctly', () => {
|
|
43
|
+
// The indent annotation is applied to the paragraph block inside the passage block
|
|
44
|
+
expect(block.content).toBeDefined();
|
|
45
|
+
expect(block.content?.length).toBeGreaterThan(0);
|
|
46
|
+
|
|
47
|
+
const paragraphBlock = block.content?.[0];
|
|
48
|
+
expect(paragraphBlock).toBeDefined();
|
|
49
|
+
expect(paragraphBlock?.attrs).toBeDefined();
|
|
50
|
+
expect(paragraphBlock?.attrs?.hasIndent).toBe(true);
|
|
51
|
+
expect(paragraphBlock?.attrs?.indentUuid).toBe('indent-uuid-1');
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { recurse } from './recurse';
|
|
2
|
+
import { Transformer } from './transformer';
|
|
3
|
+
|
|
4
|
+
export const indent: Transformer = (ctx) => {
|
|
5
|
+
const indentUuid = ctx.annotation.uuid;
|
|
6
|
+
recurse({
|
|
7
|
+
...ctx,
|
|
8
|
+
until: ['paragraph', 'lineGroup', 'list', 'blockquote'],
|
|
9
|
+
transform: ({ block }) => {
|
|
10
|
+
block.attrs = {
|
|
11
|
+
...block.attrs,
|
|
12
|
+
hasIndent: true,
|
|
13
|
+
indentUuid,
|
|
14
|
+
};
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export * from './abbreviation';
|
|
2
|
+
export * from './audio';
|
|
3
|
+
export * from './blockquote';
|
|
4
|
+
export * from './code';
|
|
5
|
+
export * from './deprecated';
|
|
6
|
+
export * from './end-note-link';
|
|
7
|
+
export * from './glossary-instance';
|
|
8
|
+
export * from './has-abbreviation';
|
|
9
|
+
export * from './heading';
|
|
10
|
+
export * from './image';
|
|
11
|
+
export * from './indent';
|
|
12
|
+
export * from './inline-title';
|
|
13
|
+
export * from './internal-link';
|
|
14
|
+
export * from './leading-space';
|
|
15
|
+
export * from './line-group';
|
|
16
|
+
export * from './line';
|
|
17
|
+
export * from './link';
|
|
18
|
+
export * from './list-item';
|
|
19
|
+
export * from './list';
|
|
20
|
+
export * from './mantra';
|
|
21
|
+
export * from './mention';
|
|
22
|
+
export * from './paragraph';
|
|
23
|
+
export * from './quote';
|
|
24
|
+
export * from './quoted';
|
|
25
|
+
export * from './reference';
|
|
26
|
+
export * from './span';
|
|
27
|
+
export * from './table';
|
|
28
|
+
export * from './table-body-data';
|
|
29
|
+
export * from './table-body-header';
|
|
30
|
+
export * from './table-body-row';
|
|
31
|
+
export * from './trailer';
|
|
32
|
+
export * from './unknown';
|
|
33
|
+
export * from './transformer';
|