@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,148 @@
|
|
|
1
|
+
import { Mark } from '@tiptap/core';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
import { createMarkViewDom, registerEditorElement } from '../../util';
|
|
4
|
+
import { cn } from '@eightyfourthousand/lib-utils';
|
|
5
|
+
|
|
6
|
+
export interface GlossaryInstanceOptions {
|
|
7
|
+
HTMLAttributes: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare module '@tiptap/core' {
|
|
11
|
+
interface Commands<ReturnType> {
|
|
12
|
+
glossaryInstance: {
|
|
13
|
+
setGlossaryInstance: (glossary: string) => ReturnType;
|
|
14
|
+
unsetGlossaryInstance: () => ReturnType;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const GlossaryInstanceNode = Mark.create<GlossaryInstanceOptions>({
|
|
20
|
+
name: 'glossaryInstance',
|
|
21
|
+
|
|
22
|
+
addAttributes() {
|
|
23
|
+
return {
|
|
24
|
+
...this.parent?.(),
|
|
25
|
+
authority: {
|
|
26
|
+
default: undefined,
|
|
27
|
+
parseHTML(element) {
|
|
28
|
+
return element.getAttribute('authority');
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
glossary: {
|
|
32
|
+
default: undefined,
|
|
33
|
+
parseHTML(element) {
|
|
34
|
+
return element.getAttribute('glossary');
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
uuid: {
|
|
38
|
+
default: undefined,
|
|
39
|
+
parseHTML(element) {
|
|
40
|
+
return element.getAttribute('uuid');
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
isInline: { default: true },
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
addOptions() {
|
|
48
|
+
return {
|
|
49
|
+
HTMLAttributes: {
|
|
50
|
+
className: 'glossary-instance',
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
parseHTML() {
|
|
56
|
+
return [
|
|
57
|
+
{
|
|
58
|
+
tag: 'span[type="gloassaryInstance"]',
|
|
59
|
+
getAttrs: (dom) => {
|
|
60
|
+
const authority = (dom as HTMLElement).getAttribute('authority');
|
|
61
|
+
const glossary = (dom as HTMLElement).getAttribute('glossary');
|
|
62
|
+
|
|
63
|
+
if (!authority || !glossary) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
renderHTML({ HTMLAttributes }) {
|
|
73
|
+
return [
|
|
74
|
+
'span',
|
|
75
|
+
{ class: HTMLAttributes.className, type: 'glossaryInstance' },
|
|
76
|
+
0,
|
|
77
|
+
];
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
addMarkView() {
|
|
81
|
+
return (props) => {
|
|
82
|
+
const isEditable = props.editor.isEditable;
|
|
83
|
+
const { dom } = createMarkViewDom({
|
|
84
|
+
...props,
|
|
85
|
+
element: 'span',
|
|
86
|
+
className: cn('glossary-instance', props.mark.attrs.toh),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Set attributes for HoverCardProvider identification
|
|
90
|
+
if (props.mark.attrs.uuid) {
|
|
91
|
+
dom.setAttribute('uuid', props.mark.attrs.uuid);
|
|
92
|
+
}
|
|
93
|
+
if (props.mark.attrs.authority) {
|
|
94
|
+
dom.setAttribute('authority', props.mark.attrs.authority);
|
|
95
|
+
}
|
|
96
|
+
if (props.mark.attrs.glossary) {
|
|
97
|
+
dom.setAttribute('glossary', props.mark.attrs.glossary);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Only add type attribute and register in edit mode for hover card detection
|
|
101
|
+
if (isEditable) {
|
|
102
|
+
dom.setAttribute('type', 'glossaryInstance');
|
|
103
|
+
registerEditorElement(dom, props.editor);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
dom.addEventListener('click', () => {
|
|
107
|
+
const { authority } = props.mark.attrs;
|
|
108
|
+
if (!authority) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const query = new URLSearchParams(window.location.search);
|
|
113
|
+
query.set('right', `open:glossary:${authority}`);
|
|
114
|
+
window.history.pushState({}, '', `?${query.toString()}`);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
dom,
|
|
119
|
+
contentDOM: dom,
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
addCommands() {
|
|
125
|
+
return {
|
|
126
|
+
setGlossaryInstance:
|
|
127
|
+
(glossary) =>
|
|
128
|
+
({ chain }) => {
|
|
129
|
+
return chain()
|
|
130
|
+
.setMark(this.name)
|
|
131
|
+
.updateAttributes(this.name, {
|
|
132
|
+
glossary,
|
|
133
|
+
uuid: uuidv4(),
|
|
134
|
+
})
|
|
135
|
+
.run();
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
unsetGlossaryInstance:
|
|
139
|
+
() =>
|
|
140
|
+
({ chain }) => {
|
|
141
|
+
return chain()
|
|
142
|
+
.unsetMark(this.name)
|
|
143
|
+
.resetAttributes(this.name, 'glossary')
|
|
144
|
+
.run();
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
},
|
|
148
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import TiptapHeading from '@tiptap/extension-heading';
|
|
2
|
+
import type { Level } from '@tiptap/extension-heading';
|
|
3
|
+
import {
|
|
4
|
+
BODY_TITLE_STYLE,
|
|
5
|
+
H1_STYLE,
|
|
6
|
+
H2_STYLE,
|
|
7
|
+
H3_STYLE,
|
|
8
|
+
H4_STYLE,
|
|
9
|
+
H5_STYLE,
|
|
10
|
+
HONORIFIC_TITLE_STYLE,
|
|
11
|
+
SECTION_TITLE_STYLE,
|
|
12
|
+
} from '@eightyfourthousand/design-system';
|
|
13
|
+
import { createNodeViewDom } from '../../util';
|
|
14
|
+
import { HTMLElementType } from 'react';
|
|
15
|
+
|
|
16
|
+
const CLASS_FOR_LEVEL: Record<Level, string> = {
|
|
17
|
+
1: H1_STYLE,
|
|
18
|
+
2: H2_STYLE,
|
|
19
|
+
3: H3_STYLE,
|
|
20
|
+
4: H4_STYLE,
|
|
21
|
+
5: H5_STYLE,
|
|
22
|
+
6: H5_STYLE,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const CLASS_FOR_CLASS: Record<string, string> = {
|
|
26
|
+
'section-title': SECTION_TITLE_STYLE,
|
|
27
|
+
'body-title-main': BODY_TITLE_STYLE,
|
|
28
|
+
'body-title-honorific': HONORIFIC_TITLE_STYLE,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const Heading = TiptapHeading.extend({
|
|
32
|
+
addAttributes() {
|
|
33
|
+
return {
|
|
34
|
+
...this.parent?.(),
|
|
35
|
+
class: {
|
|
36
|
+
default: null,
|
|
37
|
+
parseHTML(element) {
|
|
38
|
+
return element.getAttribute('class');
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
addNodeView() {
|
|
45
|
+
return ({ node, editor, extension, getPos, HTMLAttributes }) => {
|
|
46
|
+
const nodeLevel = parseInt(node.attrs.level, 10) as Level;
|
|
47
|
+
const hasLevel = this.options.levels.includes(nodeLevel);
|
|
48
|
+
const level = hasLevel ? nodeLevel : this.options.levels.at(-1);
|
|
49
|
+
const element = `h${level}` as HTMLElementType;
|
|
50
|
+
const className =
|
|
51
|
+
CLASS_FOR_CLASS[node.attrs.class] || CLASS_FOR_LEVEL[nodeLevel];
|
|
52
|
+
|
|
53
|
+
const { dom } = createNodeViewDom({
|
|
54
|
+
editor,
|
|
55
|
+
getPos,
|
|
56
|
+
node,
|
|
57
|
+
extension,
|
|
58
|
+
HTMLAttributes,
|
|
59
|
+
element,
|
|
60
|
+
className,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
dom,
|
|
65
|
+
contentDOM: dom,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
export default Heading;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Button, Input } from '@eightyfourthousand/design-system';
|
|
2
|
+
import { CheckIcon, Trash2Icon } from 'lucide-react';
|
|
3
|
+
import { useRef } from 'react';
|
|
4
|
+
|
|
5
|
+
export const HoverInputField = ({
|
|
6
|
+
placeholder,
|
|
7
|
+
valueRef,
|
|
8
|
+
onSubmit,
|
|
9
|
+
}: {
|
|
10
|
+
type: string;
|
|
11
|
+
attr: string;
|
|
12
|
+
valueRef: string;
|
|
13
|
+
placeholder: string;
|
|
14
|
+
onSubmit: (value?: string) => void;
|
|
15
|
+
}) => {
|
|
16
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div className="flex space-x-1 items-center">
|
|
20
|
+
<Input
|
|
21
|
+
ref={inputRef}
|
|
22
|
+
placeholder={placeholder}
|
|
23
|
+
value={valueRef}
|
|
24
|
+
onKeyDown={(e) => {
|
|
25
|
+
if (e.key === 'Enter') {
|
|
26
|
+
e.preventDefault();
|
|
27
|
+
onSubmit(inputRef.current?.value);
|
|
28
|
+
}
|
|
29
|
+
}}
|
|
30
|
+
/>
|
|
31
|
+
<Button
|
|
32
|
+
size="icon"
|
|
33
|
+
variant="ghost"
|
|
34
|
+
disabled={!!inputRef.current}
|
|
35
|
+
onClick={() => onSubmit(inputRef.current?.value)}
|
|
36
|
+
>
|
|
37
|
+
<CheckIcon />
|
|
38
|
+
</Button>
|
|
39
|
+
<Button
|
|
40
|
+
variant="ghost"
|
|
41
|
+
size="icon"
|
|
42
|
+
type="button"
|
|
43
|
+
onClick={() => {
|
|
44
|
+
if (inputRef.current) {
|
|
45
|
+
inputRef.current.value = '';
|
|
46
|
+
}
|
|
47
|
+
onSubmit();
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
<Trash2Icon className="text-destructive" />
|
|
51
|
+
</Button>
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Image from '@tiptap/extension-image';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
|
|
4
|
+
export default Image.extend({
|
|
5
|
+
addCommands() {
|
|
6
|
+
return {
|
|
7
|
+
setImage:
|
|
8
|
+
(options) =>
|
|
9
|
+
({ commands }) => {
|
|
10
|
+
return commands.insertContent({
|
|
11
|
+
type: this.name,
|
|
12
|
+
attrs: options,
|
|
13
|
+
uuid: uuidv4(),
|
|
14
|
+
});
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Extension, mergeAttributes } from '@tiptap/core';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
|
|
4
|
+
export interface IndentOptions {
|
|
5
|
+
types: string[];
|
|
6
|
+
defaultHasIndent: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module '@tiptap/core' {
|
|
10
|
+
interface Commands<ReturnType> {
|
|
11
|
+
indent: {
|
|
12
|
+
/**
|
|
13
|
+
* Add an indent
|
|
14
|
+
*/
|
|
15
|
+
setIndent: () => ReturnType;
|
|
16
|
+
/**
|
|
17
|
+
* Remove an indent
|
|
18
|
+
*/
|
|
19
|
+
unsetIndent: () => ReturnType;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Toggle an indent
|
|
23
|
+
*/
|
|
24
|
+
toggleIndent: () => ReturnType;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const Indent = Extension.create<IndentOptions>({
|
|
30
|
+
name: 'indent',
|
|
31
|
+
addOptions() {
|
|
32
|
+
return {
|
|
33
|
+
types: ['paragraph', 'lineGroup', 'list', 'blockquote'],
|
|
34
|
+
defaultHasIndent: false,
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
addGlobalAttributes() {
|
|
38
|
+
return [
|
|
39
|
+
{
|
|
40
|
+
types: this.options.types,
|
|
41
|
+
attributes: {
|
|
42
|
+
hasIndent: {
|
|
43
|
+
default: this.options.defaultHasIndent,
|
|
44
|
+
parseHTML: (element) => element.className.includes('pl-8'),
|
|
45
|
+
renderHTML: (attributes) => {
|
|
46
|
+
if (!attributes.hasIndent) {
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
return mergeAttributes(attributes, { class: 'pl-8' });
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
indentUuid: {
|
|
53
|
+
default: undefined,
|
|
54
|
+
parseHTML: (element) =>
|
|
55
|
+
element.getAttribute('data-indent-uuid') || undefined,
|
|
56
|
+
renderHTML: (attributes) => {
|
|
57
|
+
if (!attributes.indentUuid) {
|
|
58
|
+
return {};
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
'data-indent-uuid': attributes.indentUuid,
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
addCommands() {
|
|
71
|
+
return {
|
|
72
|
+
setIndent:
|
|
73
|
+
() =>
|
|
74
|
+
({ commands }) => {
|
|
75
|
+
return this.options.types
|
|
76
|
+
.map((type) =>
|
|
77
|
+
commands.updateAttributes(type, {
|
|
78
|
+
hasIndent: true,
|
|
79
|
+
indentUuid: uuidv4(),
|
|
80
|
+
}),
|
|
81
|
+
)
|
|
82
|
+
.every((response) => response);
|
|
83
|
+
},
|
|
84
|
+
unsetIndent:
|
|
85
|
+
() =>
|
|
86
|
+
({ commands }) => {
|
|
87
|
+
return this.options.types
|
|
88
|
+
.map((type) =>
|
|
89
|
+
commands.resetAttributes(type, ['hasIndent', 'indentUuid']),
|
|
90
|
+
)
|
|
91
|
+
.every((response) => response);
|
|
92
|
+
},
|
|
93
|
+
toggleIndent:
|
|
94
|
+
() =>
|
|
95
|
+
({ editor, commands }) => {
|
|
96
|
+
if (editor.isActive({ hasIndent: true })) {
|
|
97
|
+
return commands.unsetIndent();
|
|
98
|
+
}
|
|
99
|
+
return commands.setIndent();
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
});
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { Mark, mergeAttributes } from '@tiptap/core';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
import { createMarkViewDom, registerEditorElement } from '../../util';
|
|
4
|
+
import {
|
|
5
|
+
PANEL_FOR_SECTION,
|
|
6
|
+
TAB_FOR_SECTION,
|
|
7
|
+
} from '../../../shared/types';
|
|
8
|
+
import { cn } from '@eightyfourthousand/lib-utils';
|
|
9
|
+
import { LINK_STYLE } from '@eightyfourthousand/design-system';
|
|
10
|
+
|
|
11
|
+
export interface InternalLinkOptions {
|
|
12
|
+
HTMLAttributes: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare module '@tiptap/core' {
|
|
16
|
+
interface Commands<ReturnType> {
|
|
17
|
+
internalLink: {
|
|
18
|
+
setInternalLink: (entity: string, type: string) => ReturnType;
|
|
19
|
+
unsetInternalLink: () => ReturnType;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const InternalLink = Mark.create<InternalLinkOptions>({
|
|
25
|
+
name: 'internalLink',
|
|
26
|
+
addAttributes() {
|
|
27
|
+
return {
|
|
28
|
+
entity: {
|
|
29
|
+
default: undefined,
|
|
30
|
+
parseHTML: (element) => element.getAttribute('entity'),
|
|
31
|
+
},
|
|
32
|
+
type: {
|
|
33
|
+
default: undefined,
|
|
34
|
+
parseHTML: (element) => element.getAttribute('entity-type'),
|
|
35
|
+
},
|
|
36
|
+
href: {
|
|
37
|
+
default: undefined,
|
|
38
|
+
parseHTML: (element) => element.getAttribute('href'),
|
|
39
|
+
},
|
|
40
|
+
uuid: {
|
|
41
|
+
default: undefined,
|
|
42
|
+
parseHTML: (element) => element.getAttribute('uuid'),
|
|
43
|
+
},
|
|
44
|
+
isSameWork: {
|
|
45
|
+
default: undefined,
|
|
46
|
+
parseHTML: (element) =>
|
|
47
|
+
element.getAttribute('data-same-work') === 'true',
|
|
48
|
+
},
|
|
49
|
+
subtype: {
|
|
50
|
+
default: undefined,
|
|
51
|
+
parseHTML: (element) => element.getAttribute('data-subtype'),
|
|
52
|
+
},
|
|
53
|
+
linkToh: {
|
|
54
|
+
default: undefined,
|
|
55
|
+
parseHTML: (element) => element.getAttribute('data-link-toh'),
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
addOptions() {
|
|
60
|
+
return {
|
|
61
|
+
HTMLAttributes: {},
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
parseHTML() {
|
|
65
|
+
return [
|
|
66
|
+
{
|
|
67
|
+
tag: 'a[type="internalLink"]',
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
},
|
|
71
|
+
renderHTML({ HTMLAttributes }) {
|
|
72
|
+
return [
|
|
73
|
+
'a',
|
|
74
|
+
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
|
75
|
+
0,
|
|
76
|
+
];
|
|
77
|
+
},
|
|
78
|
+
addMarkView() {
|
|
79
|
+
return (props) => {
|
|
80
|
+
const isEditable = props.editor.isEditable;
|
|
81
|
+
const { dom } = createMarkViewDom({
|
|
82
|
+
...props,
|
|
83
|
+
element: 'span',
|
|
84
|
+
className: cn(LINK_STYLE, props.mark.attrs.toh),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const { isSameWork, subtype, entity, type: linkType, linkToh } =
|
|
88
|
+
props.mark.attrs;
|
|
89
|
+
|
|
90
|
+
dom.addEventListener('click', (e) => {
|
|
91
|
+
e.preventDefault();
|
|
92
|
+
if (!isSameWork) {
|
|
93
|
+
// Cross-work links open in a new tab
|
|
94
|
+
const href = props.mark.attrs.href || '#';
|
|
95
|
+
window.open(href, '_blank');
|
|
96
|
+
return
|
|
97
|
+
}
|
|
98
|
+
const query = new URLSearchParams(window.location.search);
|
|
99
|
+
|
|
100
|
+
if (linkToh) {
|
|
101
|
+
query.set('toh', linkToh);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
switch (linkType) {
|
|
105
|
+
case 'bibliography':
|
|
106
|
+
query.set('right', `open:bibliography:${entity}`);
|
|
107
|
+
break;
|
|
108
|
+
case 'glossary':
|
|
109
|
+
query.set('right', `open:glossary:${entity}`);
|
|
110
|
+
break;
|
|
111
|
+
case 'passage': {
|
|
112
|
+
const panel =
|
|
113
|
+
PANEL_FOR_SECTION[subtype] || 'main';
|
|
114
|
+
const tab =
|
|
115
|
+
TAB_FOR_SECTION[subtype] || 'translation';
|
|
116
|
+
query.set(panel, `open:${tab}:${entity}`);
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
default:
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
window.history.pushState({}, '', `?${query.toString()}`);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// Set attributes for HoverCardProvider identification
|
|
127
|
+
if (props.mark.attrs.uuid) {
|
|
128
|
+
dom.setAttribute('uuid', props.mark.attrs.uuid);
|
|
129
|
+
}
|
|
130
|
+
if (entity) {
|
|
131
|
+
dom.setAttribute('entity', entity);
|
|
132
|
+
}
|
|
133
|
+
if (linkType) {
|
|
134
|
+
dom.setAttribute('entity-type', linkType);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Only add type attribute in edit mode for hover card detection
|
|
138
|
+
if (isEditable) {
|
|
139
|
+
dom.setAttribute('type', 'internalLink');
|
|
140
|
+
registerEditorElement(dom, props.editor);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
dom,
|
|
145
|
+
contentDOM: dom,
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
},
|
|
149
|
+
addCommands() {
|
|
150
|
+
return {
|
|
151
|
+
setInternalLink:
|
|
152
|
+
(entity: string, type: string) =>
|
|
153
|
+
({ chain }) => {
|
|
154
|
+
return chain()
|
|
155
|
+
.setMark(this.name, {
|
|
156
|
+
entity,
|
|
157
|
+
type,
|
|
158
|
+
uuid: uuidv4(),
|
|
159
|
+
href: `/entity/${type}/${entity}`,
|
|
160
|
+
})
|
|
161
|
+
.run();
|
|
162
|
+
},
|
|
163
|
+
unsetInternalLink:
|
|
164
|
+
() =>
|
|
165
|
+
({ chain }) => {
|
|
166
|
+
return chain()
|
|
167
|
+
.unsetMark(this.name)
|
|
168
|
+
.resetAttributes(this.name, ['entity', 'type'])
|
|
169
|
+
.run();
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
},
|
|
173
|
+
});
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { Button } from '@eightyfourthousand/design-system';
|
|
2
|
+
import { Editor } from '@tiptap/core';
|
|
3
|
+
import { ChevronRightIcon, PencilIcon, Trash2Icon } from 'lucide-react';
|
|
4
|
+
import { useCallback, useState } from 'react';
|
|
5
|
+
import { InternalLinkInput } from './InternalLinkInput';
|
|
6
|
+
import { findMarkByUuid } from '../../util';
|
|
7
|
+
import { useHoverCard } from '../../../shared/HoverCardProvider';
|
|
8
|
+
|
|
9
|
+
const EDITOR_UPDATE_DELAY_MS = 100;
|
|
10
|
+
|
|
11
|
+
export const InternalLinkHoverContent = ({
|
|
12
|
+
uuid,
|
|
13
|
+
entityType,
|
|
14
|
+
entity,
|
|
15
|
+
editor,
|
|
16
|
+
anchor,
|
|
17
|
+
}: {
|
|
18
|
+
uuid: string;
|
|
19
|
+
entityType: string;
|
|
20
|
+
entity: string;
|
|
21
|
+
editor: Editor;
|
|
22
|
+
anchor: HTMLElement;
|
|
23
|
+
}) => {
|
|
24
|
+
const [isEditing, setIsEditingLocal] = useState(false);
|
|
25
|
+
const { close, setIsEditing: setIsEditingContext } = useHoverCard();
|
|
26
|
+
|
|
27
|
+
const setIsEditing = useCallback(
|
|
28
|
+
(editing: boolean) => {
|
|
29
|
+
setIsEditingLocal(editing);
|
|
30
|
+
setIsEditingContext(editing);
|
|
31
|
+
},
|
|
32
|
+
[setIsEditingContext],
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const deleteLink = useCallback(() => {
|
|
36
|
+
setIsEditing(false);
|
|
37
|
+
close();
|
|
38
|
+
|
|
39
|
+
setTimeout(() => {
|
|
40
|
+
const range = findMarkByUuid({ editor, uuid, markType: 'internalLink' });
|
|
41
|
+
if (!range) {
|
|
42
|
+
console.warn('InternalLink mark not found in the document.');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const { from, to, mark } = range;
|
|
47
|
+
const { tr } = editor.state;
|
|
48
|
+
tr.removeMark(from, to, mark.type);
|
|
49
|
+
editor.view.dispatch(tr);
|
|
50
|
+
}, EDITOR_UPDATE_DELAY_MS);
|
|
51
|
+
}, [editor, uuid, close, setIsEditing]);
|
|
52
|
+
|
|
53
|
+
const updateValues = useCallback(
|
|
54
|
+
(newType: string, newEntity: string) => {
|
|
55
|
+
setIsEditing(false);
|
|
56
|
+
close();
|
|
57
|
+
|
|
58
|
+
setTimeout(() => {
|
|
59
|
+
const range = findMarkByUuid({
|
|
60
|
+
editor,
|
|
61
|
+
uuid,
|
|
62
|
+
markType: 'internalLink',
|
|
63
|
+
});
|
|
64
|
+
if (!range) {
|
|
65
|
+
console.warn('InternalLink mark not found in the document.');
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const { from, to, mark } = range;
|
|
70
|
+
const newHref = `/entity/${newType}/${newEntity}`;
|
|
71
|
+
const { tr } = editor.state;
|
|
72
|
+
tr.removeMark(from, to, mark.type);
|
|
73
|
+
tr.addMark(
|
|
74
|
+
from,
|
|
75
|
+
to,
|
|
76
|
+
mark.type.create({
|
|
77
|
+
...mark.attrs,
|
|
78
|
+
type: newType,
|
|
79
|
+
entity: newEntity,
|
|
80
|
+
href: newHref,
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
editor.view.dispatch(tr);
|
|
84
|
+
|
|
85
|
+
// Update the DOM attributes directly for immediate feedback
|
|
86
|
+
anchor.setAttribute('entity-type', newType);
|
|
87
|
+
anchor.setAttribute('entity', newEntity);
|
|
88
|
+
anchor.setAttribute('href', newHref);
|
|
89
|
+
}, EDITOR_UPDATE_DELAY_MS);
|
|
90
|
+
},
|
|
91
|
+
[editor, uuid, anchor, close, setIsEditing],
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<div className="flex justify-between gap-2 p-2 w-fit max-w-80">
|
|
96
|
+
{isEditing ? (
|
|
97
|
+
<InternalLinkInput
|
|
98
|
+
type={entityType}
|
|
99
|
+
uuid={entity}
|
|
100
|
+
onSubmit={(type, entityVal) => {
|
|
101
|
+
if (type && entityVal) {
|
|
102
|
+
updateValues(type, entityVal);
|
|
103
|
+
} else {
|
|
104
|
+
deleteLink();
|
|
105
|
+
}
|
|
106
|
+
setIsEditing(false);
|
|
107
|
+
}}
|
|
108
|
+
/>
|
|
109
|
+
) : (
|
|
110
|
+
<>
|
|
111
|
+
<span className="text-primary text-sm my-auto">{entityType}</span>
|
|
112
|
+
<ChevronRightIcon className="my-auto size-4" />
|
|
113
|
+
<span className="truncate text-muted-foreground text-sm my-auto">
|
|
114
|
+
{entity}
|
|
115
|
+
</span>
|
|
116
|
+
<span className="flex-grow" />
|
|
117
|
+
<Button
|
|
118
|
+
variant="ghost"
|
|
119
|
+
size="icon"
|
|
120
|
+
className="size-6 [&_svg]:size-4"
|
|
121
|
+
onClick={() => setIsEditing(true)}
|
|
122
|
+
>
|
|
123
|
+
<PencilIcon className="text-primary my-auto" />
|
|
124
|
+
</Button>
|
|
125
|
+
<Button
|
|
126
|
+
variant="ghost"
|
|
127
|
+
size="icon"
|
|
128
|
+
className="size-6 [&_svg]:size-4"
|
|
129
|
+
onClick={deleteLink}
|
|
130
|
+
>
|
|
131
|
+
<Trash2Icon className="text-destructive my-auto" />
|
|
132
|
+
</Button>
|
|
133
|
+
</>
|
|
134
|
+
)}
|
|
135
|
+
</div>
|
|
136
|
+
);
|
|
137
|
+
};
|