@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,388 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { cn } from '@eightyfourthousand/lib-utils';
|
|
4
|
+
import { Editor } from '@tiptap/core';
|
|
5
|
+
import { useEditorState as useTiptapEditorState } from '@tiptap/react';
|
|
6
|
+
import {
|
|
7
|
+
Button,
|
|
8
|
+
Input,
|
|
9
|
+
Popover,
|
|
10
|
+
PopoverContent,
|
|
11
|
+
PopoverTrigger,
|
|
12
|
+
Separator,
|
|
13
|
+
} from '@eightyfourthousand/design-system';
|
|
14
|
+
import { AsteriskIcon, Loader2Icon, PlusIcon } from 'lucide-react';
|
|
15
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
16
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
17
|
+
import { createGraphQLClient } from '@eightyfourthousand/client-graphql';
|
|
18
|
+
import { gql } from 'graphql-request';
|
|
19
|
+
import { useEditorState } from '../../EditorProvider';
|
|
20
|
+
import { useNavigation } from '../../../shared';
|
|
21
|
+
import {
|
|
22
|
+
findLastEndNoteLinkBefore,
|
|
23
|
+
findPassageNode,
|
|
24
|
+
getFirstEndnoteInEditor,
|
|
25
|
+
getLastEndnoteInEditor,
|
|
26
|
+
insertEndnotePassage,
|
|
27
|
+
syncEndnoteLinkLabelsAcrossEditors,
|
|
28
|
+
} from '../../extensions/EndNoteLink/endnote-utils';
|
|
29
|
+
import { incrementLabel } from '../../extensions/Passage/label';
|
|
30
|
+
|
|
31
|
+
const SEARCH_ENDNOTES = gql`
|
|
32
|
+
query SearchEndnotes($uuid: ID!, $limit: Int, $filter: PassageFilter) {
|
|
33
|
+
work(uuid: $uuid) {
|
|
34
|
+
uuid
|
|
35
|
+
passages(limit: $limit, filter: $filter) {
|
|
36
|
+
nodes {
|
|
37
|
+
uuid
|
|
38
|
+
content
|
|
39
|
+
label
|
|
40
|
+
sort
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
interface EndnoteResult {
|
|
48
|
+
uuid: string;
|
|
49
|
+
label: string | null;
|
|
50
|
+
content: string;
|
|
51
|
+
sort: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const EndNoteSelector = ({ editor }: { editor: Editor }) => {
|
|
55
|
+
const [open, setOpen] = useState(false);
|
|
56
|
+
const [searchQuery, setSearchQuery] = useState('');
|
|
57
|
+
const [results, setResults] = useState<EndnoteResult[]>([]);
|
|
58
|
+
const [loading, setLoading] = useState(false);
|
|
59
|
+
const debounceRef = useRef<ReturnType<typeof setTimeout>>(undefined);
|
|
60
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
61
|
+
|
|
62
|
+
const { getEditor } = useEditorState();
|
|
63
|
+
const { uuid: workUuid, updatePanel, fetchEndNote } = useNavigation();
|
|
64
|
+
|
|
65
|
+
const editorState = useTiptapEditorState({
|
|
66
|
+
editor,
|
|
67
|
+
selector: (instance) => ({
|
|
68
|
+
isActive: instance.editor.isActive('endNoteLink'),
|
|
69
|
+
}),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const searchEndnotes = useCallback(
|
|
73
|
+
async (query: string) => {
|
|
74
|
+
if (!query.trim() || !workUuid) {
|
|
75
|
+
setResults([]);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
setLoading(true);
|
|
80
|
+
try {
|
|
81
|
+
const client = createGraphQLClient();
|
|
82
|
+
|
|
83
|
+
// Normalize input: if just a number, prepend "n."
|
|
84
|
+
let labelPattern = query.trim();
|
|
85
|
+
if (/^\d+$/.test(labelPattern)) {
|
|
86
|
+
labelPattern = `n.${labelPattern}`;
|
|
87
|
+
}
|
|
88
|
+
// Append % for ILIKE pattern matching
|
|
89
|
+
if (!labelPattern.endsWith('%')) {
|
|
90
|
+
labelPattern = `${labelPattern}%`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const response = await client.request<{
|
|
94
|
+
work: {
|
|
95
|
+
passages: {
|
|
96
|
+
nodes: Array<{
|
|
97
|
+
uuid: string;
|
|
98
|
+
content: string;
|
|
99
|
+
label: string | null;
|
|
100
|
+
sort: number;
|
|
101
|
+
}>;
|
|
102
|
+
};
|
|
103
|
+
} | null;
|
|
104
|
+
}>(SEARCH_ENDNOTES, {
|
|
105
|
+
uuid: workUuid,
|
|
106
|
+
limit: 20,
|
|
107
|
+
filter: { types: ['endnotes'], label: labelPattern },
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const nodes = response.work?.passages.nodes ?? [];
|
|
111
|
+
setResults(
|
|
112
|
+
nodes.map((n) => ({
|
|
113
|
+
uuid: n.uuid,
|
|
114
|
+
label: n.label ?? null,
|
|
115
|
+
content: n.content,
|
|
116
|
+
sort: n.sort,
|
|
117
|
+
})),
|
|
118
|
+
);
|
|
119
|
+
} catch (err) {
|
|
120
|
+
console.error('Error searching endnotes:', err);
|
|
121
|
+
setResults([]);
|
|
122
|
+
} finally {
|
|
123
|
+
setLoading(false);
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
[workUuid],
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
if (debounceRef.current) {
|
|
131
|
+
clearTimeout(debounceRef.current);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (!searchQuery.trim()) {
|
|
135
|
+
setResults([]);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
debounceRef.current = setTimeout(() => {
|
|
140
|
+
searchEndnotes(searchQuery);
|
|
141
|
+
}, 300);
|
|
142
|
+
|
|
143
|
+
return () => {
|
|
144
|
+
if (debounceRef.current) {
|
|
145
|
+
clearTimeout(debounceRef.current);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}, [searchQuery, searchEndnotes]);
|
|
149
|
+
|
|
150
|
+
const linkToExisting = useCallback(
|
|
151
|
+
(endnoteUuid: string, endnoteLabel: string | null) => {
|
|
152
|
+
const { to } = editor.state.selection;
|
|
153
|
+
editor
|
|
154
|
+
.chain()
|
|
155
|
+
.focus()
|
|
156
|
+
.setEndNoteLink(endnoteUuid, endnoteLabel ?? undefined)
|
|
157
|
+
.setTextSelection(to)
|
|
158
|
+
.run();
|
|
159
|
+
setOpen(false);
|
|
160
|
+
setSearchQuery('');
|
|
161
|
+
setResults([]);
|
|
162
|
+
},
|
|
163
|
+
[editor],
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
const createNewEndnote = useCallback(async () => {
|
|
167
|
+
const endnotesEditor = getEditor('endnotes');
|
|
168
|
+
const { from, to } = editor.state.selection;
|
|
169
|
+
const selectionIsRange = from !== to;
|
|
170
|
+
|
|
171
|
+
// Check for an existing endNoteLink mark at the end of the selection.
|
|
172
|
+
// Only the end matters — the endnote superscript renders there.
|
|
173
|
+
const nodeBeforeTo =
|
|
174
|
+
selectionIsRange ? editor.state.doc.nodeAt(to - 1) : null;
|
|
175
|
+
const endMark = nodeBeforeTo?.marks.find(
|
|
176
|
+
(m) => m.type.name === 'endNoteLink',
|
|
177
|
+
);
|
|
178
|
+
const endNote =
|
|
179
|
+
endMark &&
|
|
180
|
+
(endMark.attrs.notes as { endNote: string }[] | undefined)?.find(
|
|
181
|
+
(n) => n.endNote,
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
// Determine whether `to` is exactly at the end of the mark or in the middle.
|
|
185
|
+
// nodeAt(to) returns the character after the selection — if it still carries
|
|
186
|
+
// the same mark, `to` is in the middle and a split is needed.
|
|
187
|
+
const markType = editor.state.schema.marks.endNoteLink;
|
|
188
|
+
const nodeAtTo = endNote ? editor.state.doc.nodeAt(to) : null;
|
|
189
|
+
const markContinues = nodeAtTo && markType.isInSet(nodeAtTo.marks);
|
|
190
|
+
|
|
191
|
+
// Find the previous endnote link before cursor to determine insertion point
|
|
192
|
+
const prevLink = findLastEndNoteLinkBefore(editor, from);
|
|
193
|
+
|
|
194
|
+
let newLabel: string;
|
|
195
|
+
let newSort: number;
|
|
196
|
+
let afterPassageUuid: string | undefined;
|
|
197
|
+
let beforePassageUuid: string | undefined;
|
|
198
|
+
|
|
199
|
+
if (endNote && !markContinues) {
|
|
200
|
+
// `to` is at the exact end of the mark — append a new note after
|
|
201
|
+
// the last existing note's passage.
|
|
202
|
+
const notes = endMark.attrs.notes as { endNote: string }[];
|
|
203
|
+
const lastNote = notes[notes.length - 1];
|
|
204
|
+
const passage = await fetchEndNote(lastNote.endNote);
|
|
205
|
+
if (passage) {
|
|
206
|
+
newLabel = incrementLabel(passage.label || 'n.0');
|
|
207
|
+
newSort = passage.sort + 1;
|
|
208
|
+
afterPassageUuid = passage.uuid;
|
|
209
|
+
} else if (endnotesEditor) {
|
|
210
|
+
const last = getLastEndnoteInEditor(endnotesEditor);
|
|
211
|
+
newLabel = last ? incrementLabel(last.label) : 'n.1';
|
|
212
|
+
newSort = last ? last.sort + 1 : 1;
|
|
213
|
+
} else {
|
|
214
|
+
newLabel = 'n.1';
|
|
215
|
+
newSort = 1;
|
|
216
|
+
}
|
|
217
|
+
} else if (endNote && markContinues) {
|
|
218
|
+
// `to` is in the middle of the mark — split. The new endnote takes
|
|
219
|
+
// the existing passage's label and is inserted before it.
|
|
220
|
+
const passage = await fetchEndNote(endNote.endNote);
|
|
221
|
+
if (passage) {
|
|
222
|
+
newLabel = passage.label || 'n.1';
|
|
223
|
+
newSort = passage.sort;
|
|
224
|
+
beforePassageUuid = passage.uuid;
|
|
225
|
+
} else if (endnotesEditor) {
|
|
226
|
+
const last = getLastEndnoteInEditor(endnotesEditor);
|
|
227
|
+
newLabel = last ? incrementLabel(last.label) : 'n.1';
|
|
228
|
+
newSort = last ? last.sort + 1 : 1;
|
|
229
|
+
} else {
|
|
230
|
+
newLabel = 'n.1';
|
|
231
|
+
newSort = 1;
|
|
232
|
+
}
|
|
233
|
+
} else if (prevLink) {
|
|
234
|
+
// Try to get the label/sort from the endnotes editor or API
|
|
235
|
+
const passage = await fetchEndNote(prevLink.endNote);
|
|
236
|
+
if (passage) {
|
|
237
|
+
newLabel = incrementLabel(passage.label || 'n.0');
|
|
238
|
+
newSort = passage.sort + 1;
|
|
239
|
+
afterPassageUuid = passage.uuid;
|
|
240
|
+
} else if (endnotesEditor) {
|
|
241
|
+
const last = getLastEndnoteInEditor(endnotesEditor);
|
|
242
|
+
newLabel = last ? incrementLabel(last.label) : 'n.1';
|
|
243
|
+
newSort = last ? last.sort + 1 : 1;
|
|
244
|
+
} else {
|
|
245
|
+
newLabel = 'n.1';
|
|
246
|
+
newSort = 1;
|
|
247
|
+
}
|
|
248
|
+
} else if (endnotesEditor) {
|
|
249
|
+
// No previous link; insert before the first endnote passage
|
|
250
|
+
const first = getFirstEndnoteInEditor(endnotesEditor);
|
|
251
|
+
if (first) {
|
|
252
|
+
newLabel = 'n.1';
|
|
253
|
+
newSort = first.sort;
|
|
254
|
+
beforePassageUuid = first.uuid;
|
|
255
|
+
} else {
|
|
256
|
+
newLabel = 'n.1';
|
|
257
|
+
newSort = 1;
|
|
258
|
+
}
|
|
259
|
+
} else {
|
|
260
|
+
newLabel = 'n.1';
|
|
261
|
+
newSort = 1;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const newPassageUuid = uuidv4();
|
|
265
|
+
|
|
266
|
+
// Insert endNoteLink mark in main editor with the label for immediate display,
|
|
267
|
+
// then collapse the selection to dismiss the bubble menu.
|
|
268
|
+
editor
|
|
269
|
+
.chain()
|
|
270
|
+
.focus()
|
|
271
|
+
.setEndNoteLink(newPassageUuid, newLabel)
|
|
272
|
+
.setTextSelection(to)
|
|
273
|
+
.run();
|
|
274
|
+
|
|
275
|
+
// Insert new passage in endnotes editor at the correct position
|
|
276
|
+
if (endnotesEditor) {
|
|
277
|
+
insertEndnotePassage(endnotesEditor, {
|
|
278
|
+
label: newLabel,
|
|
279
|
+
sort: newSort,
|
|
280
|
+
uuid: newPassageUuid,
|
|
281
|
+
afterPassageUuid,
|
|
282
|
+
beforePassageUuid,
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
// Sync updated labels into endNoteLink marks across front + translation
|
|
286
|
+
syncEndnoteLinkLabelsAcrossEditors(endnotesEditor, getEditor);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// Navigate to the new endnote
|
|
290
|
+
updatePanel({
|
|
291
|
+
name: 'right',
|
|
292
|
+
state: { open: true, tab: 'endnotes', hash: newPassageUuid },
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
// Focus the new endnote passage after navigation
|
|
296
|
+
if (endnotesEditor) {
|
|
297
|
+
setTimeout(() => {
|
|
298
|
+
const found = findPassageNode(endnotesEditor, newPassageUuid);
|
|
299
|
+
if (found) {
|
|
300
|
+
endnotesEditor.commands.focus(found.pos + 2);
|
|
301
|
+
}
|
|
302
|
+
}, 200);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
setOpen(false);
|
|
306
|
+
setSearchQuery('');
|
|
307
|
+
setResults([]);
|
|
308
|
+
}, [editor, getEditor, fetchEndNote, updatePanel]);
|
|
309
|
+
|
|
310
|
+
return (
|
|
311
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
312
|
+
<PopoverTrigger asChild>
|
|
313
|
+
<Button
|
|
314
|
+
variant="ghost"
|
|
315
|
+
size="icon"
|
|
316
|
+
className="rounded-none flex-shrink-0"
|
|
317
|
+
>
|
|
318
|
+
<AsteriskIcon
|
|
319
|
+
className={cn(
|
|
320
|
+
'size-4',
|
|
321
|
+
editorState.isActive ? 'text-primary' : 'text-muted-foreground',
|
|
322
|
+
)}
|
|
323
|
+
strokeWidth={2.5}
|
|
324
|
+
/>
|
|
325
|
+
</Button>
|
|
326
|
+
</PopoverTrigger>
|
|
327
|
+
<PopoverContent
|
|
328
|
+
className="w-72 shadow-xl rounded-md border p-2"
|
|
329
|
+
align="end"
|
|
330
|
+
noPortal
|
|
331
|
+
>
|
|
332
|
+
<div className="flex flex-col gap-2">
|
|
333
|
+
<Input
|
|
334
|
+
ref={inputRef}
|
|
335
|
+
placeholder="Search endnotes by label..."
|
|
336
|
+
value={searchQuery}
|
|
337
|
+
onChange={(e) => setSearchQuery(e.target.value)}
|
|
338
|
+
className="h-8 text-sm"
|
|
339
|
+
/>
|
|
340
|
+
|
|
341
|
+
{loading && (
|
|
342
|
+
<div className="flex items-center justify-center py-2">
|
|
343
|
+
<Loader2Icon className="size-4 animate-spin text-muted-foreground" />
|
|
344
|
+
</div>
|
|
345
|
+
)}
|
|
346
|
+
|
|
347
|
+
{!loading && results.length > 0 && (
|
|
348
|
+
<div className="max-h-48 overflow-y-auto flex flex-col gap-0.5">
|
|
349
|
+
{results.map((result) => (
|
|
350
|
+
<button
|
|
351
|
+
key={result.uuid}
|
|
352
|
+
className="flex items-start gap-2 px-2 py-1.5 text-sm rounded hover:bg-muted cursor-pointer text-left w-full"
|
|
353
|
+
onClick={() => linkToExisting(result.uuid, result.label)}
|
|
354
|
+
>
|
|
355
|
+
<span className="font-medium text-primary shrink-0">
|
|
356
|
+
{result.label}
|
|
357
|
+
</span>
|
|
358
|
+
<span className="text-muted-foreground truncate">
|
|
359
|
+
{result.content.slice(0, 80)}
|
|
360
|
+
{result.content.length > 80 ? '...' : ''}
|
|
361
|
+
</span>
|
|
362
|
+
</button>
|
|
363
|
+
))}
|
|
364
|
+
</div>
|
|
365
|
+
)}
|
|
366
|
+
|
|
367
|
+
{!loading && searchQuery && results.length === 0 && (
|
|
368
|
+
<p className="text-xs text-muted-foreground text-center py-1">
|
|
369
|
+
No matching endnotes found.
|
|
370
|
+
</p>
|
|
371
|
+
)}
|
|
372
|
+
|
|
373
|
+
<Separator />
|
|
374
|
+
|
|
375
|
+
<Button
|
|
376
|
+
variant="ghost"
|
|
377
|
+
size="sm"
|
|
378
|
+
className="w-full justify-start text-sm"
|
|
379
|
+
onClick={createNewEndnote}
|
|
380
|
+
>
|
|
381
|
+
<PlusIcon className="size-4 mr-1" />
|
|
382
|
+
Create new endnote
|
|
383
|
+
</Button>
|
|
384
|
+
</div>
|
|
385
|
+
</PopoverContent>
|
|
386
|
+
</Popover>
|
|
387
|
+
);
|
|
388
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { cn } from '@eightyfourthousand/lib-utils';
|
|
4
|
+
import { Editor } from '@tiptap/core';
|
|
5
|
+
import { useEditorState } from '@tiptap/react';
|
|
6
|
+
import {
|
|
7
|
+
Button,
|
|
8
|
+
Popover,
|
|
9
|
+
PopoverContent,
|
|
10
|
+
PopoverTrigger,
|
|
11
|
+
} from '@eightyfourthousand/design-system';
|
|
12
|
+
import { BookOpenTextIcon } from 'lucide-react';
|
|
13
|
+
import { SelectorInputField } from './SelectorInputField';
|
|
14
|
+
|
|
15
|
+
export const GlossarySelector = ({ editor }: { editor: Editor }) => {
|
|
16
|
+
const editorState = useEditorState({
|
|
17
|
+
editor,
|
|
18
|
+
selector: (instance) => ({
|
|
19
|
+
isActive: instance.editor.isActive('glossaryInstance'),
|
|
20
|
+
}),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Popover>
|
|
25
|
+
<PopoverTrigger asChild>
|
|
26
|
+
<Button
|
|
27
|
+
variant="ghost"
|
|
28
|
+
size="icon"
|
|
29
|
+
className="px-2 rounded-none flex-shrink-0"
|
|
30
|
+
>
|
|
31
|
+
<BookOpenTextIcon
|
|
32
|
+
className={cn(
|
|
33
|
+
'size-4',
|
|
34
|
+
editorState.isActive
|
|
35
|
+
? 'text-foreground'
|
|
36
|
+
: 'text-muted-foreground',
|
|
37
|
+
)}
|
|
38
|
+
strokeWidth={2.5}
|
|
39
|
+
/>
|
|
40
|
+
</Button>
|
|
41
|
+
</PopoverTrigger>
|
|
42
|
+
<PopoverContent
|
|
43
|
+
className="w-fit shadow-xl rounded-md border p-1"
|
|
44
|
+
align="end"
|
|
45
|
+
noPortal
|
|
46
|
+
>
|
|
47
|
+
<SelectorInputField
|
|
48
|
+
editor={editor}
|
|
49
|
+
type="glossaryInstance"
|
|
50
|
+
attr="glossary"
|
|
51
|
+
placeholder="Add glossary uuid..."
|
|
52
|
+
onSubmit={(value) => {
|
|
53
|
+
if (value) {
|
|
54
|
+
editor.chain().focus().setGlossaryInstance(value).run();
|
|
55
|
+
} else {
|
|
56
|
+
editor.chain().focus().unsetGlossaryInstance().run();
|
|
57
|
+
}
|
|
58
|
+
}}
|
|
59
|
+
/>
|
|
60
|
+
</PopoverContent>
|
|
61
|
+
</Popover>
|
|
62
|
+
);
|
|
63
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { cn } from '@eightyfourthousand/lib-utils';
|
|
4
|
+
import { Editor } from '@tiptap/core';
|
|
5
|
+
import { useEditorState } from '@tiptap/react';
|
|
6
|
+
import {
|
|
7
|
+
Button,
|
|
8
|
+
Popover,
|
|
9
|
+
PopoverContent,
|
|
10
|
+
PopoverTrigger,
|
|
11
|
+
} from '@eightyfourthousand/design-system';
|
|
12
|
+
import { LinkIcon } from 'lucide-react';
|
|
13
|
+
import { SelectorInputField } from './SelectorInputField';
|
|
14
|
+
|
|
15
|
+
export const LinkSelector = ({ editor }: { editor: Editor }) => {
|
|
16
|
+
const editorState = useEditorState({
|
|
17
|
+
editor,
|
|
18
|
+
selector: (instance) => ({
|
|
19
|
+
isActive: instance.editor.isActive('link'),
|
|
20
|
+
}),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Popover>
|
|
25
|
+
<PopoverTrigger asChild>
|
|
26
|
+
<Button
|
|
27
|
+
variant="ghost"
|
|
28
|
+
size="icon"
|
|
29
|
+
className="rounded-none flex-shrink-0"
|
|
30
|
+
>
|
|
31
|
+
<LinkIcon
|
|
32
|
+
className={cn(
|
|
33
|
+
'size-4',
|
|
34
|
+
editorState.isActive
|
|
35
|
+
? 'text-foreground'
|
|
36
|
+
: 'text-muted-foreground',
|
|
37
|
+
)}
|
|
38
|
+
strokeWidth={2.5}
|
|
39
|
+
/>
|
|
40
|
+
</Button>
|
|
41
|
+
</PopoverTrigger>
|
|
42
|
+
<PopoverContent
|
|
43
|
+
className="w-fit shadow-xl rounded-md border p-1"
|
|
44
|
+
align="end"
|
|
45
|
+
noPortal
|
|
46
|
+
>
|
|
47
|
+
<SelectorInputField
|
|
48
|
+
editor={editor}
|
|
49
|
+
type="link"
|
|
50
|
+
attr="href"
|
|
51
|
+
placeholder="Add link..."
|
|
52
|
+
onSubmit={(value) => {
|
|
53
|
+
if (value) {
|
|
54
|
+
editor
|
|
55
|
+
.chain()
|
|
56
|
+
.focus()
|
|
57
|
+
.extendMarkRange('link')
|
|
58
|
+
.setLink({ href: value })
|
|
59
|
+
.run();
|
|
60
|
+
} else {
|
|
61
|
+
editor.chain().focus().extendMarkRange('link').unsetLink().run();
|
|
62
|
+
}
|
|
63
|
+
}}
|
|
64
|
+
/>
|
|
65
|
+
</PopoverContent>
|
|
66
|
+
</Popover>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Editor } from '@tiptap/core';
|
|
4
|
+
import { useEditorState } from '@tiptap/react';
|
|
5
|
+
import {
|
|
6
|
+
Button,
|
|
7
|
+
Popover,
|
|
8
|
+
PopoverContent,
|
|
9
|
+
PopoverTrigger,
|
|
10
|
+
} from '@eightyfourthousand/design-system';
|
|
11
|
+
import { CheckIcon, ChevronDownIcon, SpeechIcon } from 'lucide-react';
|
|
12
|
+
import { cn } from '@eightyfourthousand/lib-utils';
|
|
13
|
+
|
|
14
|
+
interface SelectorResult {
|
|
15
|
+
isEnglish: boolean;
|
|
16
|
+
isSanskrit: boolean;
|
|
17
|
+
isTibetan: boolean;
|
|
18
|
+
isWylie: boolean;
|
|
19
|
+
isMixed: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface MenuItem {
|
|
23
|
+
name: string;
|
|
24
|
+
onClick: (editor: Editor) => void;
|
|
25
|
+
isActive: (state: SelectorResult) => boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const items: MenuItem[] = [
|
|
29
|
+
{
|
|
30
|
+
name: 'English',
|
|
31
|
+
onClick: (editor: Editor) => {
|
|
32
|
+
editor.chain().focus().toggleMantra('en').run();
|
|
33
|
+
},
|
|
34
|
+
isActive: (state: SelectorResult) => state.isEnglish,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'Sanskrit',
|
|
38
|
+
onClick: (editor: Editor) => {
|
|
39
|
+
editor.chain().focus().toggleMantra('Sa-Ltn').run();
|
|
40
|
+
},
|
|
41
|
+
isActive: (state: SelectorResult) => state.isSanskrit,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'Wylie',
|
|
45
|
+
onClick: (editor: Editor) => {
|
|
46
|
+
editor.chain().focus().toggleMantra('Bo-Ltn').run();
|
|
47
|
+
},
|
|
48
|
+
isActive: (state: SelectorResult) => state.isWylie,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'Tibetan',
|
|
52
|
+
onClick: (editor: Editor) => {
|
|
53
|
+
editor.chain().focus().toggleMantra('bo').run();
|
|
54
|
+
},
|
|
55
|
+
isActive: (state: SelectorResult) => state.isTibetan,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'Mixed',
|
|
59
|
+
onClick: (editor: Editor) => {
|
|
60
|
+
editor.chain().focus().toggleMantra().run();
|
|
61
|
+
},
|
|
62
|
+
isActive: (state: SelectorResult) => state.isMixed,
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
export const MantraSelector = ({ editor }: { editor: Editor }) => {
|
|
67
|
+
const editorState = useEditorState({
|
|
68
|
+
editor,
|
|
69
|
+
selector: (instance) => ({
|
|
70
|
+
isEnglish: instance.editor.isActive('mantra', { lang: 'en' }),
|
|
71
|
+
isSanskrit: instance.editor.isActive('mantra', { lang: 'Sa-Ltn' }),
|
|
72
|
+
isTibetan: instance.editor.isActive('mantra', { lang: 'bo' }),
|
|
73
|
+
isWylie: instance.editor.isActive('mantra', { lang: 'Bo-Ltn' }),
|
|
74
|
+
isMixed: instance.editor.isActive('mantra', { lang: undefined }),
|
|
75
|
+
}),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<Popover>
|
|
80
|
+
<PopoverTrigger asChild>
|
|
81
|
+
<Button variant="ghost" className="rounded-none">
|
|
82
|
+
<SpeechIcon
|
|
83
|
+
className={cn(
|
|
84
|
+
'size-3',
|
|
85
|
+
editorState.isEnglish ||
|
|
86
|
+
editorState.isSanskrit ||
|
|
87
|
+
editorState.isTibetan ||
|
|
88
|
+
editorState.isWylie ||
|
|
89
|
+
editorState.isMixed
|
|
90
|
+
? 'text-primary'
|
|
91
|
+
: 'text-muted-foreground',
|
|
92
|
+
)}
|
|
93
|
+
strokeWidth={2.5}
|
|
94
|
+
/>
|
|
95
|
+
<ChevronDownIcon className="size-2" />
|
|
96
|
+
</Button>
|
|
97
|
+
</PopoverTrigger>
|
|
98
|
+
<PopoverContent
|
|
99
|
+
className="w-28 shadow-xl rounded-md border p-1"
|
|
100
|
+
align="end"
|
|
101
|
+
noPortal
|
|
102
|
+
>
|
|
103
|
+
{items.map((item) => (
|
|
104
|
+
<div
|
|
105
|
+
key={item.name}
|
|
106
|
+
className="flex items-center text-sm rounded-md hover:bg-muted text-foreground px-2 py-1.5 cursor-pointer"
|
|
107
|
+
onClick={() => item.onClick(editor)}
|
|
108
|
+
>
|
|
109
|
+
<span>{item.name}</span>
|
|
110
|
+
<div className="flex-1"></div>
|
|
111
|
+
{item.isActive(editorState) && (
|
|
112
|
+
<CheckIcon className="size-3.5 ms-4" />
|
|
113
|
+
)}
|
|
114
|
+
</div>
|
|
115
|
+
))}
|
|
116
|
+
</PopoverContent>
|
|
117
|
+
</Popover>
|
|
118
|
+
);
|
|
119
|
+
};
|