@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,88 @@
|
|
|
1
|
+
import { TranslationLanguage } from '@eightyfourthousand/data-access';
|
|
2
|
+
import { Mark, mergeAttributes } from '@tiptap/core';
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
+
|
|
5
|
+
export interface MantraOptions {
|
|
6
|
+
HTMLAttributes: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module '@tiptap/core' {
|
|
10
|
+
interface Commands<ReturnType> {
|
|
11
|
+
mantra: {
|
|
12
|
+
setMantra: (lang?: TranslationLanguage) => ReturnType;
|
|
13
|
+
toggleMantra: (lang?: TranslationLanguage) => ReturnType;
|
|
14
|
+
unsetMantra: () => ReturnType;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const MantraMark = Mark.create<MantraOptions>({
|
|
20
|
+
name: 'mantra',
|
|
21
|
+
addAttributes() {
|
|
22
|
+
return {
|
|
23
|
+
type: {
|
|
24
|
+
default: 'mantra',
|
|
25
|
+
},
|
|
26
|
+
lang: {
|
|
27
|
+
default: 'Sa-Ltn',
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
addOptions() {
|
|
33
|
+
return {
|
|
34
|
+
HTMLAttributes: {},
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
parseHTML() {
|
|
39
|
+
return [
|
|
40
|
+
{
|
|
41
|
+
tag: 'span[type="mantra"]',
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
renderHTML({ HTMLAttributes, mark }) {
|
|
47
|
+
const lang = mark.attrs.lang;
|
|
48
|
+
return [
|
|
49
|
+
'span',
|
|
50
|
+
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
|
|
51
|
+
lang,
|
|
52
|
+
}),
|
|
53
|
+
0,
|
|
54
|
+
];
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
addCommands() {
|
|
58
|
+
return {
|
|
59
|
+
setMantra:
|
|
60
|
+
(lang?: TranslationLanguage) =>
|
|
61
|
+
({ chain }) => {
|
|
62
|
+
return chain()
|
|
63
|
+
.setMark(this.name)
|
|
64
|
+
.updateAttributes(this.name, {
|
|
65
|
+
lang,
|
|
66
|
+
uuid: uuidv4(),
|
|
67
|
+
})
|
|
68
|
+
.run();
|
|
69
|
+
},
|
|
70
|
+
toggleMantra:
|
|
71
|
+
(lang?: TranslationLanguage) =>
|
|
72
|
+
({ commands }) => {
|
|
73
|
+
if (this.editor.isActive(this.name, { lang })) {
|
|
74
|
+
return commands.unsetMantra();
|
|
75
|
+
}
|
|
76
|
+
return commands.setMantra(lang);
|
|
77
|
+
},
|
|
78
|
+
unsetMantra:
|
|
79
|
+
() =>
|
|
80
|
+
({ chain }) => {
|
|
81
|
+
return chain()
|
|
82
|
+
.unsetMark(this.name)
|
|
83
|
+
.resetAttributes(this.name, 'lang')
|
|
84
|
+
.run();
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
});
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { Node, mergeAttributes } from '@tiptap/core';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
import { registerEditorElement } from '../../util';
|
|
4
|
+
import { PANEL_FOR_SECTION, TAB_FOR_SECTION } from '../../../shared/types';
|
|
5
|
+
|
|
6
|
+
export interface MentionOptions {
|
|
7
|
+
HTMLAttributes: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface MentionItem {
|
|
11
|
+
uuid: string;
|
|
12
|
+
entity: string;
|
|
13
|
+
linkType: string;
|
|
14
|
+
text?: string;
|
|
15
|
+
displayText?: string;
|
|
16
|
+
isSameWork?: boolean;
|
|
17
|
+
subtype?: string;
|
|
18
|
+
linkToh?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare module '@tiptap/core' {
|
|
22
|
+
interface Commands<ReturnType> {
|
|
23
|
+
mention: {
|
|
24
|
+
setMention: (entity: string, linkType: string) => ReturnType;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const Mention = Node.create<MentionOptions>({
|
|
30
|
+
name: 'mention',
|
|
31
|
+
group: 'inline',
|
|
32
|
+
inline: true,
|
|
33
|
+
atom: true,
|
|
34
|
+
|
|
35
|
+
addOptions() {
|
|
36
|
+
return {
|
|
37
|
+
HTMLAttributes: {},
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
addAttributes() {
|
|
42
|
+
return {
|
|
43
|
+
items: {
|
|
44
|
+
default: [],
|
|
45
|
+
parseHTML: (element) => {
|
|
46
|
+
const itemsAttr = element.getAttribute('data-items');
|
|
47
|
+
if (itemsAttr) {
|
|
48
|
+
try {
|
|
49
|
+
return JSON.parse(itemsAttr);
|
|
50
|
+
} catch {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return [];
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
parseHTML() {
|
|
61
|
+
return [{ tag: 'span[data-type="mention"]' }];
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
renderHTML({ HTMLAttributes }) {
|
|
65
|
+
return [
|
|
66
|
+
'span',
|
|
67
|
+
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
|
|
68
|
+
'data-type': 'mention',
|
|
69
|
+
}),
|
|
70
|
+
];
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
addNodeView() {
|
|
74
|
+
return (props) => {
|
|
75
|
+
const isEditable = props.editor.isEditable;
|
|
76
|
+
const dom = document.createElement('span');
|
|
77
|
+
dom.classList.add('mention-container');
|
|
78
|
+
|
|
79
|
+
const items: MentionItem[] = props.node.attrs.items || [];
|
|
80
|
+
|
|
81
|
+
items.forEach((item) => {
|
|
82
|
+
const anchor = document.createElement('a');
|
|
83
|
+
anchor.classList.add('mention-link', 'pe-1');
|
|
84
|
+
|
|
85
|
+
// Display priority: text (custom override) > displayText (dynamic) > entity UUID (fallback)
|
|
86
|
+
anchor.textContent = item.text || item.displayText || item.entity;
|
|
87
|
+
|
|
88
|
+
// Compute href from linkType + entity
|
|
89
|
+
const href = `/entity/${item.linkType}/${item.entity}`;
|
|
90
|
+
|
|
91
|
+
if (item.isSameWork) {
|
|
92
|
+
// Same-work links navigate in-place via panel system
|
|
93
|
+
anchor.setAttribute('href', '#');
|
|
94
|
+
anchor.setAttribute('data-same-work', 'true');
|
|
95
|
+
|
|
96
|
+
if (item.subtype) {
|
|
97
|
+
anchor.setAttribute('data-subtype', item.subtype);
|
|
98
|
+
}
|
|
99
|
+
if (item.linkToh) {
|
|
100
|
+
anchor.setAttribute('data-link-toh', item.linkToh);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!isEditable) {
|
|
104
|
+
anchor.addEventListener('click', (e) => {
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
const query = new URLSearchParams(window.location.search);
|
|
107
|
+
|
|
108
|
+
if (item.linkToh) {
|
|
109
|
+
query.set('toh', item.linkToh);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
switch (item.linkType) {
|
|
113
|
+
case 'bibliography':
|
|
114
|
+
query.set('right', `open:bibliography:${item.entity}`);
|
|
115
|
+
break;
|
|
116
|
+
case 'glossary':
|
|
117
|
+
query.set('right', `open:glossary:${item.entity}`);
|
|
118
|
+
break;
|
|
119
|
+
case 'passage': {
|
|
120
|
+
const panel =
|
|
121
|
+
PANEL_FOR_SECTION[item.subtype || ''] || 'main';
|
|
122
|
+
const tab =
|
|
123
|
+
TAB_FOR_SECTION[item.subtype || ''] || 'translation';
|
|
124
|
+
query.set(panel, `open:${tab}:${item.entity}`);
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
default:
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
window.history.pushState({}, '', `?${query.toString()}`);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
// Cross-work links open in a new tab
|
|
136
|
+
anchor.setAttribute('href', href);
|
|
137
|
+
anchor.setAttribute('target', '_blank');
|
|
138
|
+
anchor.setAttribute('rel', 'noreferrer');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Set DOM attrs for HoverCardProvider identification
|
|
142
|
+
if (item.uuid) {
|
|
143
|
+
anchor.setAttribute('uuid', item.uuid);
|
|
144
|
+
}
|
|
145
|
+
if (item.entity) {
|
|
146
|
+
anchor.setAttribute('entity', item.entity);
|
|
147
|
+
}
|
|
148
|
+
if (item.linkType) {
|
|
149
|
+
anchor.setAttribute('entity-type', item.linkType);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (isEditable) {
|
|
153
|
+
anchor.setAttribute('type', 'mention');
|
|
154
|
+
registerEditorElement(anchor, props.editor);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
dom.appendChild(anchor);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
return { dom };
|
|
161
|
+
};
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
addCommands() {
|
|
165
|
+
return {
|
|
166
|
+
setMention:
|
|
167
|
+
(entity: string, linkType: string) =>
|
|
168
|
+
({ commands }) => {
|
|
169
|
+
return commands.insertContent({
|
|
170
|
+
type: this.name,
|
|
171
|
+
attrs: {
|
|
172
|
+
items: [
|
|
173
|
+
{
|
|
174
|
+
uuid: uuidv4(),
|
|
175
|
+
entity,
|
|
176
|
+
linkType,
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
},
|
|
184
|
+
});
|
|
@@ -0,0 +1,158 @@
|
|
|
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 '../InternalLink/InternalLinkInput';
|
|
6
|
+
import { useHoverCard } from '../../../shared/HoverCardProvider';
|
|
7
|
+
import type { MentionItem } from './Mention';
|
|
8
|
+
|
|
9
|
+
const EDITOR_UPDATE_DELAY_MS = 100;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Find a mention node in the document that contains an item with the given UUID.
|
|
13
|
+
*/
|
|
14
|
+
function findMentionNodeByItemUuid(
|
|
15
|
+
editor: Editor,
|
|
16
|
+
itemUuid: string,
|
|
17
|
+
): { pos: number; node: ReturnType<Editor['state']['doc']['nodeAt']> } | undefined {
|
|
18
|
+
const { doc } = editor.state;
|
|
19
|
+
let result: { pos: number; node: ReturnType<typeof doc.nodeAt> } | undefined;
|
|
20
|
+
|
|
21
|
+
doc.descendants((node, pos) => {
|
|
22
|
+
if (result) return false;
|
|
23
|
+
if (node.type.name === 'mention') {
|
|
24
|
+
const items: MentionItem[] = node.attrs.items || [];
|
|
25
|
+
if (items.some((item) => item.uuid === itemUuid)) {
|
|
26
|
+
result = { pos, node };
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const MentionHoverContent = ({
|
|
37
|
+
uuid,
|
|
38
|
+
entityType,
|
|
39
|
+
entity,
|
|
40
|
+
editor,
|
|
41
|
+
}: {
|
|
42
|
+
uuid: string;
|
|
43
|
+
entityType: string;
|
|
44
|
+
entity: string;
|
|
45
|
+
editor: Editor;
|
|
46
|
+
anchor: HTMLElement;
|
|
47
|
+
}) => {
|
|
48
|
+
const [isEditing, setIsEditingLocal] = useState(false);
|
|
49
|
+
const { close, setIsEditing: setIsEditingContext } = useHoverCard();
|
|
50
|
+
|
|
51
|
+
const setIsEditing = useCallback(
|
|
52
|
+
(editing: boolean) => {
|
|
53
|
+
setIsEditingLocal(editing);
|
|
54
|
+
setIsEditingContext(editing);
|
|
55
|
+
},
|
|
56
|
+
[setIsEditingContext],
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const deleteMention = useCallback(() => {
|
|
60
|
+
setIsEditing(false);
|
|
61
|
+
close();
|
|
62
|
+
|
|
63
|
+
setTimeout(() => {
|
|
64
|
+
const found = findMentionNodeByItemUuid(editor, uuid);
|
|
65
|
+
if (!found || !found.node) {
|
|
66
|
+
console.warn('Mention node not found in the document.');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const { pos, node } = found;
|
|
71
|
+
const items: MentionItem[] = (node.attrs.items || []).filter(
|
|
72
|
+
(item: MentionItem) => item.uuid !== uuid,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const { tr } = editor.state;
|
|
76
|
+
if (items.length === 0) {
|
|
77
|
+
// Delete the entire node
|
|
78
|
+
tr.delete(pos, pos + node.nodeSize);
|
|
79
|
+
} else {
|
|
80
|
+
// Update items array without deleted item
|
|
81
|
+
tr.setNodeMarkup(pos, undefined, { ...node.attrs, items });
|
|
82
|
+
}
|
|
83
|
+
editor.view.dispatch(tr);
|
|
84
|
+
}, EDITOR_UPDATE_DELAY_MS);
|
|
85
|
+
}, [editor, uuid, close, setIsEditing]);
|
|
86
|
+
|
|
87
|
+
const updateMention = useCallback(
|
|
88
|
+
(newType: string, newEntity: string) => {
|
|
89
|
+
setIsEditing(false);
|
|
90
|
+
close();
|
|
91
|
+
|
|
92
|
+
setTimeout(() => {
|
|
93
|
+
const found = findMentionNodeByItemUuid(editor, uuid);
|
|
94
|
+
if (!found || !found.node) {
|
|
95
|
+
console.warn('Mention node not found in the document.');
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const { pos, node } = found;
|
|
100
|
+
const items: MentionItem[] = (node.attrs.items || []).map(
|
|
101
|
+
(item: MentionItem) =>
|
|
102
|
+
item.uuid === uuid
|
|
103
|
+
? { ...item, entity: newEntity, linkType: newType }
|
|
104
|
+
: item,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const { tr } = editor.state;
|
|
108
|
+
tr.setNodeMarkup(pos, undefined, { ...node.attrs, items });
|
|
109
|
+
editor.view.dispatch(tr);
|
|
110
|
+
}, EDITOR_UPDATE_DELAY_MS);
|
|
111
|
+
},
|
|
112
|
+
[editor, uuid, close, setIsEditing],
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<div className="flex justify-between gap-2 p-2 w-fit max-w-80">
|
|
117
|
+
{isEditing ? (
|
|
118
|
+
<InternalLinkInput
|
|
119
|
+
type={entityType}
|
|
120
|
+
uuid={entity}
|
|
121
|
+
onSubmit={(type, entityVal) => {
|
|
122
|
+
if (type && entityVal) {
|
|
123
|
+
updateMention(type, entityVal);
|
|
124
|
+
} else {
|
|
125
|
+
deleteMention();
|
|
126
|
+
}
|
|
127
|
+
setIsEditing(false);
|
|
128
|
+
}}
|
|
129
|
+
/>
|
|
130
|
+
) : (
|
|
131
|
+
<>
|
|
132
|
+
<span className="text-primary text-sm my-auto">{entityType}</span>
|
|
133
|
+
<ChevronRightIcon className="my-auto size-4" />
|
|
134
|
+
<span className="truncate text-muted-foreground text-sm my-auto">
|
|
135
|
+
{entity}
|
|
136
|
+
</span>
|
|
137
|
+
<span className="flex-grow" />
|
|
138
|
+
<Button
|
|
139
|
+
variant="ghost"
|
|
140
|
+
size="icon"
|
|
141
|
+
className="size-6 [&_svg]:size-4"
|
|
142
|
+
onClick={() => setIsEditing(true)}
|
|
143
|
+
>
|
|
144
|
+
<PencilIcon className="text-primary my-auto" />
|
|
145
|
+
</Button>
|
|
146
|
+
<Button
|
|
147
|
+
variant="ghost"
|
|
148
|
+
size="icon"
|
|
149
|
+
className="size-6 [&_svg]:size-4"
|
|
150
|
+
onClick={deleteMention}
|
|
151
|
+
>
|
|
152
|
+
<Trash2Icon className="text-destructive my-auto" />
|
|
153
|
+
</Button>
|
|
154
|
+
</>
|
|
155
|
+
)}
|
|
156
|
+
</div>
|
|
157
|
+
);
|
|
158
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NodeViewContent,
|
|
3
|
+
NodeViewProps,
|
|
4
|
+
NodeViewRendererOptions,
|
|
5
|
+
NodeViewWrapper,
|
|
6
|
+
ReactNodeViewRenderer,
|
|
7
|
+
} from '@tiptap/react';
|
|
8
|
+
import { JSX, ReactNode, useEffect } from 'react';
|
|
9
|
+
import { validateAttrs } from '../util';
|
|
10
|
+
|
|
11
|
+
export interface NodeWrapperProps extends NodeViewProps {
|
|
12
|
+
className?: string;
|
|
13
|
+
innerClassName?: string;
|
|
14
|
+
children?: ReactNode;
|
|
15
|
+
wrapperAs?: keyof JSX.IntrinsicElements;
|
|
16
|
+
contentAs?: keyof JSX.IntrinsicElements;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const NodeWrapper = ({
|
|
20
|
+
node,
|
|
21
|
+
editor,
|
|
22
|
+
className,
|
|
23
|
+
innerClassName,
|
|
24
|
+
children,
|
|
25
|
+
wrapperAs = 'div',
|
|
26
|
+
contentAs = 'div',
|
|
27
|
+
getPos,
|
|
28
|
+
updateAttributes,
|
|
29
|
+
}: NodeWrapperProps) => {
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
validateAttrs({ node, editor, getPos, updateAttributes });
|
|
32
|
+
}, [node, editor, getPos, updateAttributes]);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<NodeViewWrapper id={node.attrs.uuid} as={wrapperAs} className={className}>
|
|
36
|
+
{children}
|
|
37
|
+
{/* @ts-expect-error: NodeViewContent is only typed for div, but any element works */}
|
|
38
|
+
<NodeViewContent as={contentAs} className={innerClassName} />
|
|
39
|
+
</NodeViewWrapper>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export interface CreateNodeWrapperOptions extends NodeViewRendererOptions {
|
|
44
|
+
className?: string;
|
|
45
|
+
innerClassName?: string;
|
|
46
|
+
children?: ReactNode;
|
|
47
|
+
wrapperAs?: keyof JSX.IntrinsicElements;
|
|
48
|
+
contentAs?: keyof JSX.IntrinsicElements;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const createNodeWrapper = (
|
|
52
|
+
options: Partial<Omit<NodeWrapperProps, keyof NodeViewProps>> = {},
|
|
53
|
+
) => {
|
|
54
|
+
return ReactNodeViewRenderer((props: NodeViewProps) => (
|
|
55
|
+
<NodeWrapper {...props} {...options} />
|
|
56
|
+
));
|
|
57
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import TiptapParagraph from '@tiptap/extension-paragraph';
|
|
2
|
+
import { createNodeViewDom } from '../../util';
|
|
3
|
+
|
|
4
|
+
export const Paragraph = TiptapParagraph.extend({
|
|
5
|
+
addNodeView() {
|
|
6
|
+
return ({ node, extension, editor, getPos, HTMLAttributes }) => {
|
|
7
|
+
const { dom } = createNodeViewDom({
|
|
8
|
+
editor,
|
|
9
|
+
getPos,
|
|
10
|
+
node,
|
|
11
|
+
extension,
|
|
12
|
+
HTMLAttributes,
|
|
13
|
+
element: 'p',
|
|
14
|
+
className: 'paragraph',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
dom,
|
|
19
|
+
contentDOM: dom,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export default Paragraph;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Extension, mergeAttributes } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
export interface ParagraphIndentOptions {
|
|
4
|
+
types: string[];
|
|
5
|
+
defaultHasParagraphIndent: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare module '@tiptap/core' {
|
|
9
|
+
interface Commands<ReturnType> {
|
|
10
|
+
paragraphIndent: {
|
|
11
|
+
/**
|
|
12
|
+
* Add an indent
|
|
13
|
+
*/
|
|
14
|
+
setParagraphIndent: () => ReturnType;
|
|
15
|
+
/**
|
|
16
|
+
* Remove an indent
|
|
17
|
+
*/
|
|
18
|
+
unsetParagraphIndent: () => ReturnType;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Toggle an indent
|
|
22
|
+
*/
|
|
23
|
+
toggleParagraphIndent: () => ReturnType;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const ParagraphIndent = Extension.create<ParagraphIndentOptions>({
|
|
29
|
+
name: 'paragraphIndent',
|
|
30
|
+
addOptions() {
|
|
31
|
+
return {
|
|
32
|
+
types: ['paragraph'],
|
|
33
|
+
defaultHasParagraphIndent: false,
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
addGlobalAttributes() {
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
39
|
+
types: this.options.types,
|
|
40
|
+
attributes: {
|
|
41
|
+
hasParagraphIndent: {
|
|
42
|
+
default: this.options.defaultHasParagraphIndent,
|
|
43
|
+
parseHTML: (element) =>
|
|
44
|
+
element.className.includes('conditional-indent'),
|
|
45
|
+
renderHTML: (attributes) => {
|
|
46
|
+
if (attributes.hasParagraphIndent) {
|
|
47
|
+
return mergeAttributes(attributes, {
|
|
48
|
+
class: 'conditional-indent',
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return mergeAttributes(attributes, { class: 'no-indent' });
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
addCommands() {
|
|
60
|
+
return {
|
|
61
|
+
setParagraphIndent:
|
|
62
|
+
() =>
|
|
63
|
+
({ commands }) => {
|
|
64
|
+
return this.options.types
|
|
65
|
+
.map((type) =>
|
|
66
|
+
commands.updateAttributes(type, { hasParagraphIndent: true }),
|
|
67
|
+
)
|
|
68
|
+
.every((response) => response);
|
|
69
|
+
},
|
|
70
|
+
unsetParagraphIndent:
|
|
71
|
+
() =>
|
|
72
|
+
({ commands }) => {
|
|
73
|
+
return this.options.types
|
|
74
|
+
.map((type) => commands.resetAttributes(type, 'hasParagraphIndent'))
|
|
75
|
+
.every((response) => response);
|
|
76
|
+
},
|
|
77
|
+
toggleParagraphIndent:
|
|
78
|
+
() =>
|
|
79
|
+
({ editor, commands }) => {
|
|
80
|
+
if (editor.isActive({ hasParagraphIndent: true })) {
|
|
81
|
+
return commands.unsetParagraphIndent();
|
|
82
|
+
}
|
|
83
|
+
return commands.setParagraphIndent();
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Button,
|
|
5
|
+
DialogContent,
|
|
6
|
+
DialogDescription,
|
|
7
|
+
DialogTitle,
|
|
8
|
+
Input,
|
|
9
|
+
} from '@eightyfourthousand/design-system';
|
|
10
|
+
import { NodeViewProps } from '@tiptap/react';
|
|
11
|
+
import { ChangeEvent, useCallback, useState } from 'react';
|
|
12
|
+
|
|
13
|
+
export const EditLabel = ({
|
|
14
|
+
node,
|
|
15
|
+
updateAttributes,
|
|
16
|
+
close,
|
|
17
|
+
}: NodeViewProps & { close: () => void }) => {
|
|
18
|
+
const [newLabel, setNewLabel] = useState(node.attrs.label || '');
|
|
19
|
+
const updateNewLabel = (event: ChangeEvent<HTMLInputElement>) => {
|
|
20
|
+
setNewLabel(event.target.value);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const save = useCallback(() => {
|
|
24
|
+
updateAttributes({ label: newLabel });
|
|
25
|
+
close();
|
|
26
|
+
}, [newLabel, updateAttributes, close]);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<DialogContent className="sm:max-w-lg">
|
|
30
|
+
<DialogTitle>Edit Passage Label</DialogTitle>
|
|
31
|
+
<DialogDescription>{`Update the label for passage ${node.attrs.label}`}</DialogDescription>
|
|
32
|
+
<form
|
|
33
|
+
onSubmit={(e) => {
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
save();
|
|
36
|
+
}}
|
|
37
|
+
>
|
|
38
|
+
<Input
|
|
39
|
+
type="text"
|
|
40
|
+
value={newLabel}
|
|
41
|
+
onChange={updateNewLabel}
|
|
42
|
+
onBlur={updateNewLabel}
|
|
43
|
+
className="mt-2"
|
|
44
|
+
placeholder="X.X"
|
|
45
|
+
/>
|
|
46
|
+
<div className="mt-4 flex justify-end gap-2">
|
|
47
|
+
<Button variant="outline" type="button" onClick={close}>
|
|
48
|
+
Cancel
|
|
49
|
+
</Button>
|
|
50
|
+
<Button variant="default" size="sm" type="submit" className="px-5">
|
|
51
|
+
Save
|
|
52
|
+
</Button>
|
|
53
|
+
</div>
|
|
54
|
+
</form>
|
|
55
|
+
</DialogContent>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { DropdownMenuItem, DropdownMenuSeparator } from '@eightyfourthousand/design-system';
|
|
4
|
+
import { BracesIcon, PencilIcon, Trash2Icon } from 'lucide-react';
|
|
5
|
+
|
|
6
|
+
export const EditorOptions = ({
|
|
7
|
+
onSelection,
|
|
8
|
+
}: {
|
|
9
|
+
onSelection: (item: string) => void;
|
|
10
|
+
}) => {
|
|
11
|
+
return (
|
|
12
|
+
<>
|
|
13
|
+
<DropdownMenuItem onSelect={() => onSelection('label')}>
|
|
14
|
+
<PencilIcon className="text-ochre" /> Edit Label
|
|
15
|
+
</DropdownMenuItem>
|
|
16
|
+
<DropdownMenuSeparator />
|
|
17
|
+
<DropdownMenuItem onSelect={() => onSelection('attributes')}>
|
|
18
|
+
<BracesIcon className="text-ochre" /> View Attributes
|
|
19
|
+
</DropdownMenuItem>
|
|
20
|
+
<DropdownMenuSeparator />
|
|
21
|
+
<DropdownMenuItem
|
|
22
|
+
onSelect={() => onSelection('delete')}
|
|
23
|
+
className="text-destructive"
|
|
24
|
+
>
|
|
25
|
+
<Trash2Icon className="text-destructive" /> Delete
|
|
26
|
+
</DropdownMenuItem>
|
|
27
|
+
</>
|
|
28
|
+
);
|
|
29
|
+
};
|