@blocklet/editor-lite 2.6.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/LICENSE +13 -0
- package/README.md +33 -0
- package/lib/blocklet-editor-viewer.d.ts +4 -0
- package/lib/blocklet-editor-viewer.js +12 -0
- package/lib/blocklet-editor.d.ts +2 -0
- package/lib/blocklet-editor.js +12 -0
- package/lib/components/Loading.d.ts +4 -0
- package/lib/components/Loading.js +13 -0
- package/lib/components/SelectionPopper.d.ts +14 -0
- package/lib/components/SelectionPopper.js +73 -0
- package/lib/components/animateText.d.ts +3 -0
- package/lib/components/animateText.js +29 -0
- package/lib/components/createPortal.d.ts +2 -0
- package/lib/components/createPortal.js +16 -0
- package/lib/config.d.ts +37 -0
- package/lib/config.js +12 -0
- package/lib/ext/AIPlugin/AIIcon.d.ts +5 -0
- package/lib/ext/AIPlugin/AIIcon.js +7 -0
- package/lib/ext/AIPlugin/Arrow.d.ts +1 -0
- package/lib/ext/AIPlugin/Arrow.js +5 -0
- package/lib/ext/AIPlugin/TextGeneration.d.ts +6 -0
- package/lib/ext/AIPlugin/TextGeneration.js +131 -0
- package/lib/ext/AIPlugin/Writing.d.ts +1 -0
- package/lib/ext/AIPlugin/Writing.js +7 -0
- package/lib/ext/AIPlugin/index.d.ts +9 -0
- package/lib/ext/AIPlugin/index.js +180 -0
- package/lib/ext/AIPlugin/utils.d.ts +6 -0
- package/lib/ext/AIPlugin/utils.js +44 -0
- package/lib/ext/AITranslationPlugin/index.d.ts +9 -0
- package/lib/ext/AITranslationPlugin/index.js +124 -0
- package/lib/ext/AITranslationPlugin/selection.d.ts +3 -0
- package/lib/ext/AITranslationPlugin/selection.js +45 -0
- package/lib/ext/AITranslationPlugin/translation.d.ts +3 -0
- package/lib/ext/AITranslationPlugin/translation.js +67 -0
- package/lib/ext/AITranslationPlugin/types.d.ts +49 -0
- package/lib/ext/AITranslationPlugin/types.js +1 -0
- package/lib/ext/AITranslationPlugin/utils.d.ts +46 -0
- package/lib/ext/AITranslationPlugin/utils.js +343 -0
- package/lib/ext/Aide/Aide.d.ts +4 -0
- package/lib/ext/Aide/Aide.js +30 -0
- package/lib/ext/Aide/Delayed.d.ts +7 -0
- package/lib/ext/Aide/Delayed.js +12 -0
- package/lib/ext/Aide/Input.d.ts +6 -0
- package/lib/ext/Aide/Input.js +49 -0
- package/lib/ext/Aide/Menu.d.ts +4 -0
- package/lib/ext/Aide/Menu.js +29 -0
- package/lib/ext/Aide/Output.d.ts +4 -0
- package/lib/ext/Aide/Output.js +14 -0
- package/lib/ext/Aide/Templates.d.ts +4 -0
- package/lib/ext/Aide/Templates.js +34 -0
- package/lib/ext/Aide/builtin-templates.d.ts +3 -0
- package/lib/ext/Aide/builtin-templates.js +48 -0
- package/lib/ext/Aide/context.d.ts +47 -0
- package/lib/ext/Aide/context.js +114 -0
- package/lib/ext/Aide/external-templates/Breadcrumb.d.ts +10 -0
- package/lib/ext/Aide/external-templates/Breadcrumb.js +11 -0
- package/lib/ext/Aide/external-templates/Output.d.ts +8 -0
- package/lib/ext/Aide/external-templates/Output.js +22 -0
- package/lib/ext/Aide/external-templates/Search.d.ts +6 -0
- package/lib/ext/Aide/external-templates/Search.js +14 -0
- package/lib/ext/Aide/external-templates/Tags.d.ts +4 -0
- package/lib/ext/Aide/external-templates/Tags.js +44 -0
- package/lib/ext/Aide/external-templates/Template.d.ts +7 -0
- package/lib/ext/Aide/external-templates/Template.js +110 -0
- package/lib/ext/Aide/external-templates/Templates.d.ts +6 -0
- package/lib/ext/Aide/external-templates/Templates.js +61 -0
- package/lib/ext/Aide/external-templates/index.d.ts +4 -0
- package/lib/ext/Aide/external-templates/index.js +83 -0
- package/lib/ext/Aide/external-templates/parameter-field.d.ts +6 -0
- package/lib/ext/Aide/external-templates/parameter-field.js +92 -0
- package/lib/ext/Aide/hooks.d.ts +7 -0
- package/lib/ext/Aide/hooks.js +14 -0
- package/lib/ext/Aide/index.d.ts +2 -0
- package/lib/ext/Aide/index.js +2 -0
- package/lib/ext/Aide/types.d.ts +84 -0
- package/lib/ext/Aide/types.js +25 -0
- package/lib/ext/Aide/withAiAvailable.d.ts +5 -0
- package/lib/ext/Aide/withAiAvailable.js +11 -0
- package/lib/ext/Alert/AlertComponent.d.ts +10 -0
- package/lib/ext/Alert/AlertComponent.js +38 -0
- package/lib/ext/Alert/AlertNode.d.ts +28 -0
- package/lib/ext/Alert/AlertNode.js +105 -0
- package/lib/ext/Alert/AlertPlugin.d.ts +11 -0
- package/lib/ext/Alert/AlertPlugin.js +41 -0
- package/lib/ext/BilibiliPlugin/BilibiliNode.d.ts +31 -0
- package/lib/ext/BilibiliPlugin/BilibiliNode.js +95 -0
- package/lib/ext/BilibiliPlugin/BilibiliVideo.d.ts +6 -0
- package/lib/ext/BilibiliPlugin/BilibiliVideo.js +24 -0
- package/lib/ext/BilibiliPlugin/config.d.ts +2 -0
- package/lib/ext/BilibiliPlugin/config.js +40 -0
- package/lib/ext/BilibiliPlugin/index.d.ts +5 -0
- package/lib/ext/BilibiliPlugin/index.js +20 -0
- package/lib/ext/BlockletEmbedPlugin/BlockletEmbed.d.ts +7 -0
- package/lib/ext/BlockletEmbedPlugin/BlockletEmbed.js +51 -0
- package/lib/ext/BlockletEmbedPlugin/BlockletEmbedNode.d.ts +30 -0
- package/lib/ext/BlockletEmbedPlugin/BlockletEmbedNode.js +96 -0
- package/lib/ext/BlockletEmbedPlugin/index.d.ts +12 -0
- package/lib/ext/BlockletEmbedPlugin/index.js +76 -0
- package/lib/ext/BlurTextPlugin.d.ts +1 -0
- package/lib/ext/BlurTextPlugin.js +40 -0
- package/lib/ext/BookmarkPlugin/Bookmark.d.ts +7 -0
- package/lib/ext/BookmarkPlugin/Bookmark.js +175 -0
- package/lib/ext/BookmarkPlugin/BookmarkNode.d.ts +35 -0
- package/lib/ext/BookmarkPlugin/BookmarkNode.js +110 -0
- package/lib/ext/BookmarkPlugin/index.d.ts +11 -0
- package/lib/ext/BookmarkPlugin/index.js +45 -0
- package/lib/ext/BusyPlugin.d.ts +9 -0
- package/lib/ext/BusyPlugin.js +17 -0
- package/lib/ext/CharacterCountPlugin/index.d.ts +10 -0
- package/lib/ext/CharacterCountPlugin/index.js +39 -0
- package/lib/ext/CharacterCountPlugin/useCharacterCount.d.ts +11 -0
- package/lib/ext/CharacterCountPlugin/useCharacterCount.js +49 -0
- package/lib/ext/CharacterLimitPlugin/index.d.ts +9 -0
- package/lib/ext/CharacterLimitPlugin/index.js +49 -0
- package/lib/ext/CheckboxPlugin.d.ts +3 -0
- package/lib/ext/CheckboxPlugin.js +75 -0
- package/lib/ext/CodeCopyPlugin/CodeCopyPlugin.d.ts +2 -0
- package/lib/ext/CodeCopyPlugin/CodeCopyPlugin.js +90 -0
- package/lib/ext/CodeCopyPlugin/copy.svg +1 -0
- package/lib/ext/CodeCopyPlugin/index.d.ts +1 -0
- package/lib/ext/CodeCopyPlugin/index.js +1 -0
- package/lib/ext/CodeCopyPlugin/style.css +12 -0
- package/lib/ext/ContentLocale.d.ts +7 -0
- package/lib/ext/ContentLocale.js +15 -0
- package/lib/ext/CustomOnChangePlugin/index.d.ts +5 -0
- package/lib/ext/CustomOnChangePlugin/index.js +17 -0
- package/lib/ext/CustomOnChangePlugin/styles.css +14 -0
- package/lib/ext/CustomOnChangePlugin/utils.d.ts +30 -0
- package/lib/ext/CustomOnChangePlugin/utils.js +148 -0
- package/lib/ext/EditorHolderPlugin/EditorHolderContext.d.ts +13 -0
- package/lib/ext/EditorHolderPlugin/EditorHolderContext.js +15 -0
- package/lib/ext/EditorHolderPlugin/EditorHolderPlugin.d.ts +1 -0
- package/lib/ext/EditorHolderPlugin/EditorHolderPlugin.js +11 -0
- package/lib/ext/EditorHolderPlugin/index.d.ts +2 -0
- package/lib/ext/EditorHolderPlugin/index.js +2 -0
- package/lib/ext/EditorReadyPlugin.d.ts +3 -0
- package/lib/ext/EditorReadyPlugin.js +15 -0
- package/lib/ext/FilePlugin/FileNode.d.ts +44 -0
- package/lib/ext/FilePlugin/FileNode.js +195 -0
- package/lib/ext/FilePlugin/FilePlugin.d.ts +7 -0
- package/lib/ext/FilePlugin/FilePlugin.js +27 -0
- package/lib/ext/FilePlugin/index.d.ts +2 -0
- package/lib/ext/FilePlugin/index.js +2 -0
- package/lib/ext/HeadingsIdPlugin.d.ts +1 -0
- package/lib/ext/HeadingsIdPlugin.js +67 -0
- package/lib/ext/ImagePathFixerPlugin.d.ts +1 -0
- package/lib/ext/ImagePathFixerPlugin.js +31 -0
- package/lib/ext/InlineTranslationPlugin/EditorTranslator.d.ts +42 -0
- package/lib/ext/InlineTranslationPlugin/EditorTranslator.js +199 -0
- package/lib/ext/InlineTranslationPlugin/InlineTranslationPlugin.d.ts +12 -0
- package/lib/ext/InlineTranslationPlugin/InlineTranslationPlugin.js +232 -0
- package/lib/ext/InlineTranslationPlugin/TranslationNode.d.ts +23 -0
- package/lib/ext/InlineTranslationPlugin/TranslationNode.js +49 -0
- package/lib/ext/InlineTranslationPlugin/index.d.ts +4 -0
- package/lib/ext/InlineTranslationPlugin/index.js +4 -0
- package/lib/ext/InlineTranslationPlugin/store.d.ts +50 -0
- package/lib/ext/InlineTranslationPlugin/store.js +94 -0
- package/lib/ext/InlineTranslationPlugin/types.d.ts +1 -0
- package/lib/ext/InlineTranslationPlugin/types.js +1 -0
- package/lib/ext/LexicalEditorRefPlugin.d.ts +14 -0
- package/lib/ext/LexicalEditorRefPlugin.js +26 -0
- package/lib/ext/OnContentChangePlugin.d.ts +14 -0
- package/lib/ext/OnContentChangePlugin.js +35 -0
- package/lib/ext/PasteSlackImagePlugin/index.d.ts +2 -0
- package/lib/ext/PasteSlackImagePlugin/index.js +22 -0
- package/lib/ext/PostLinkEmbedPlugin/PostLinkNode.d.ts +32 -0
- package/lib/ext/PostLinkEmbedPlugin/PostLinkNode.js +140 -0
- package/lib/ext/PostLinkEmbedPlugin/fixInvalidPostLinkNodes.d.ts +1 -0
- package/lib/ext/PostLinkEmbedPlugin/fixInvalidPostLinkNodes.js +15 -0
- package/lib/ext/PostLinkEmbedPlugin/index.d.ts +21 -0
- package/lib/ext/PostLinkEmbedPlugin/index.js +148 -0
- package/lib/ext/RemoveListPlugin.d.ts +1 -0
- package/lib/ext/RemoveListPlugin.js +63 -0
- package/lib/ext/SafeAreaPlugin.d.ts +12 -0
- package/lib/ext/SafeAreaPlugin.js +56 -0
- package/lib/ext/SelectBlockPlugin.d.ts +1 -0
- package/lib/ext/SelectBlockPlugin.js +95 -0
- package/lib/ext/ShortcutPlugin/CtrlsShortcutPlugin.d.ts +6 -0
- package/lib/ext/ShortcutPlugin/CtrlsShortcutPlugin.js +17 -0
- package/lib/ext/ShortcutPlugin/index.d.ts +1 -0
- package/lib/ext/ShortcutPlugin/index.js +1 -0
- package/lib/ext/TemplatePlugin.d.ts +8 -0
- package/lib/ext/TemplatePlugin.js +170 -0
- package/lib/ext/VideoPathFixerPlugin.d.ts +1 -0
- package/lib/ext/VideoPathFixerPlugin.js +31 -0
- package/lib/ext/VideoPlugin/VideoComponent.d.ts +5 -0
- package/lib/ext/VideoPlugin/VideoComponent.js +5 -0
- package/lib/ext/VideoPlugin/VideoNode.d.ts +37 -0
- package/lib/ext/VideoPlugin/VideoNode.js +97 -0
- package/lib/ext/VideoPlugin/VideoPlugin.d.ts +7 -0
- package/lib/ext/VideoPlugin/VideoPlugin.js +26 -0
- package/lib/ext/VideoPlugin/index.d.ts +2 -0
- package/lib/ext/VideoPlugin/index.js +2 -0
- package/lib/ext/common.d.ts +15 -0
- package/lib/ext/common.js +62 -0
- package/lib/ext/nodes/GithubComp.d.ts +3 -0
- package/lib/ext/nodes/GithubComp.js +20 -0
- package/lib/ext/nodes/GithubNode.d.ts +28 -0
- package/lib/ext/nodes/GithubNode.js +94 -0
- package/lib/ext/nodes/util.d.ts +5 -0
- package/lib/ext/nodes/util.js +1 -0
- package/lib/ext/translation/translation-utils.d.ts +16 -0
- package/lib/ext/translation/translation-utils.js +63 -0
- package/lib/ext/utils.d.ts +21 -0
- package/lib/ext/utils.js +88 -0
- package/lib/global.d.ts +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +5 -0
- package/lib/lexical-utils/index.d.ts +46 -0
- package/lib/lexical-utils/index.js +243 -0
- package/lib/libs/sort-array-by-key.d.ts +4 -0
- package/lib/libs/sort-array-by-key.js +68 -0
- package/lib/libs/utm.d.ts +9 -0
- package/lib/libs/utm.js +43 -0
- package/lib/main/appSettings.d.ts +11 -0
- package/lib/main/appSettings.js +20 -0
- package/lib/main/context/SharedAutocompleteContext.d.ts +16 -0
- package/lib/main/context/SharedAutocompleteContext.js +35 -0
- package/lib/main/context/SharedHistoryContext.d.ts +17 -0
- package/lib/main/context/SharedHistoryContext.js +11 -0
- package/lib/main/editor-root.d.ts +2 -0
- package/lib/main/editor-root.js +46 -0
- package/lib/main/editor.d.ts +21 -0
- package/lib/main/editor.js +99 -0
- package/lib/main/hooks/hooks.d.ts +15 -0
- package/lib/main/hooks/hooks.js +49 -0
- package/lib/main/hooks/medium-zoom.d.ts +9 -0
- package/lib/main/hooks/medium-zoom.js +34 -0
- package/lib/main/hooks/use-mobile.d.ts +4 -0
- package/lib/main/hooks/use-mobile.js +6 -0
- package/lib/main/hooks/useBeforeUnload.d.ts +1 -0
- package/lib/main/hooks/useBeforeUnload.js +15 -0
- package/lib/main/hooks/useHasNodes.d.ts +1 -0
- package/lib/main/hooks/useHasNodes.js +8 -0
- package/lib/main/hooks/useIsFocused.d.ts +1 -0
- package/lib/main/hooks/useIsFocused.js +20 -0
- package/lib/main/hooks/useModal.d.ts +12 -0
- package/lib/main/hooks/useModal.js +33 -0
- package/lib/main/hooks/useReport.d.ts +8 -0
- package/lib/main/hooks/useReport.js +48 -0
- package/lib/main/hooks/useResponsiveTable.d.ts +5 -0
- package/lib/main/hooks/useResponsiveTable.js +31 -0
- package/lib/main/hooks/useTranslationListener.d.ts +4 -0
- package/lib/main/hooks/useTranslationListener.js +94 -0
- package/lib/main/icons.d.ts +3 -0
- package/lib/main/icons.js +25 -0
- package/lib/main/images/emoji/1F600.png +0 -0
- package/lib/main/images/emoji/1F641.png +0 -0
- package/lib/main/images/emoji/1F642.png +0 -0
- package/lib/main/images/emoji/2764.png +0 -0
- package/lib/main/images/excalidraw.svg +3 -0
- package/lib/main/images/icons/arrow-clockwise.svg +1 -0
- package/lib/main/images/icons/arrow-counterclockwise.svg +1 -0
- package/lib/main/images/icons/bg-color.svg +1 -0
- package/lib/main/images/icons/camera.svg +1 -0
- package/lib/main/images/icons/caret-right-fill.svg +1 -0
- package/lib/main/images/icons/chat-left-text.svg +1 -0
- package/lib/main/images/icons/chat-right-dots.svg +1 -0
- package/lib/main/images/icons/chat-right-text.svg +1 -0
- package/lib/main/images/icons/chat-right.svg +1 -0
- package/lib/main/images/icons/chat-square-quote.svg +1 -0
- package/lib/main/images/icons/chevron-down.svg +1 -0
- package/lib/main/images/icons/clipboard.svg +1 -0
- package/lib/main/images/icons/close.svg +1 -0
- package/lib/main/images/icons/code.svg +1 -0
- package/lib/main/images/icons/comments.svg +1 -0
- package/lib/main/images/icons/copy.svg +1 -0
- package/lib/main/images/icons/diagram-2.svg +1 -0
- package/lib/main/images/icons/download.svg +1 -0
- package/lib/main/images/icons/draggable-block-menu.svg +1 -0
- package/lib/main/images/icons/dropdown-more.svg +1 -0
- package/lib/main/images/icons/figma.svg +1 -0
- package/lib/main/images/icons/file-image.svg +1 -0
- package/lib/main/images/icons/filetype-gif.svg +1 -0
- package/lib/main/images/icons/font-color.svg +1 -0
- package/lib/main/images/icons/font-family.svg +1 -0
- package/lib/main/images/icons/gear.svg +1 -0
- package/lib/main/images/icons/horizontal-rule.svg +1 -0
- package/lib/main/images/icons/indent.svg +1 -0
- package/lib/main/images/icons/journal-code.svg +1 -0
- package/lib/main/images/icons/journal-text.svg +1 -0
- package/lib/main/images/icons/justify.svg +1 -0
- package/lib/main/images/icons/link.svg +1 -0
- package/lib/main/images/icons/list-ol.svg +1 -0
- package/lib/main/images/icons/list-ul.svg +1 -0
- package/lib/main/images/icons/lock-fill.svg +1 -0
- package/lib/main/images/icons/lock.svg +1 -0
- package/lib/main/images/icons/markdown.svg +1 -0
- package/lib/main/images/icons/mic.svg +1 -0
- package/lib/main/images/icons/outdent.svg +1 -0
- package/lib/main/images/icons/paint-bucket.svg +1 -0
- package/lib/main/images/icons/palette.svg +1 -0
- package/lib/main/images/icons/pencil-fill.svg +1 -0
- package/lib/main/images/icons/plug-fill.svg +1 -0
- package/lib/main/images/icons/plug.svg +1 -0
- package/lib/main/images/icons/plus-slash-minus.svg +1 -0
- package/lib/main/images/icons/plus.svg +1 -0
- package/lib/main/images/icons/prettier-error.svg +1 -0
- package/lib/main/images/icons/prettier.svg +1 -0
- package/lib/main/images/icons/send.svg +1 -0
- package/lib/main/images/icons/square-check.svg +1 -0
- package/lib/main/images/icons/sticky.svg +1 -0
- package/lib/main/images/icons/success.svg +1 -0
- package/lib/main/images/icons/table.svg +1 -0
- package/lib/main/images/icons/text-center.svg +1 -0
- package/lib/main/images/icons/text-left.svg +1 -0
- package/lib/main/images/icons/text-paragraph.svg +1 -0
- package/lib/main/images/icons/text-right.svg +1 -0
- package/lib/main/images/icons/trash.svg +1 -0
- package/lib/main/images/icons/trash3.svg +1 -0
- package/lib/main/images/icons/tweet.svg +1 -0
- package/lib/main/images/icons/type-bold.svg +1 -0
- package/lib/main/images/icons/type-h1.svg +1 -0
- package/lib/main/images/icons/type-h2.svg +1 -0
- package/lib/main/images/icons/type-h3.svg +1 -0
- package/lib/main/images/icons/type-h4.svg +1 -0
- package/lib/main/images/icons/type-h5.svg +1 -0
- package/lib/main/images/icons/type-h6.svg +1 -0
- package/lib/main/images/icons/type-italic.svg +1 -0
- package/lib/main/images/icons/type-strikethrough.svg +1 -0
- package/lib/main/images/icons/type-subscript.svg +1 -0
- package/lib/main/images/icons/type-superscript.svg +1 -0
- package/lib/main/images/icons/type-underline.svg +1 -0
- package/lib/main/images/icons/upload.svg +1 -0
- package/lib/main/images/icons/user.svg +1 -0
- package/lib/main/images/icons/youtube.svg +1 -0
- package/lib/main/images/landscape.jpg +0 -0
- package/lib/main/index.css +257 -0
- package/lib/main/index.d.ts +28 -0
- package/lib/main/index.js +52 -0
- package/lib/main/nodes/EmojiNode.d.ts +25 -0
- package/lib/main/nodes/EmojiNode.js +57 -0
- package/lib/main/nodes/EquationNode.d.ts +31 -0
- package/lib/main/nodes/EquationNode.js +65 -0
- package/lib/main/nodes/ExcalidrawNode/ExcalidrawComponent.d.ts +13 -0
- package/lib/main/nodes/ExcalidrawNode/ExcalidrawComponent.js +155 -0
- package/lib/main/nodes/ExcalidrawNode/ExcalidrawImage.d.ts +58 -0
- package/lib/main/nodes/ExcalidrawNode/ExcalidrawImage.js +60 -0
- package/lib/main/nodes/ExcalidrawNode/ExcalidrawModal.css +75 -0
- package/lib/main/nodes/ExcalidrawNode/ExcalidrawModal.d.ts +49 -0
- package/lib/main/nodes/ExcalidrawNode/ExcalidrawModal.js +197 -0
- package/lib/main/nodes/ExcalidrawNode/index.d.ts +30 -0
- package/lib/main/nodes/ExcalidrawNode/index.js +95 -0
- package/lib/main/nodes/ExcalidrawNode/utils.d.ts +5 -0
- package/lib/main/nodes/ExcalidrawNode/utils.js +71 -0
- package/lib/main/nodes/FigmaNode.d.ts +30 -0
- package/lib/main/nodes/FigmaNode.js +59 -0
- package/lib/main/nodes/ImageComponent.d.ts +27 -0
- package/lib/main/nodes/ImageComponent.js +432 -0
- package/lib/main/nodes/ImageNode.css +51 -0
- package/lib/main/nodes/ImageNode.d.ts +74 -0
- package/lib/main/nodes/ImageNode.js +151 -0
- package/lib/main/nodes/KeywordNode.d.ts +25 -0
- package/lib/main/nodes/KeywordNode.js +52 -0
- package/lib/main/nodes/MentionNode.d.ts +27 -0
- package/lib/main/nodes/MentionNode.js +88 -0
- package/lib/main/nodes/PlaygroundNodes.d.ts +10 -0
- package/lib/main/nodes/PlaygroundNodes.js +70 -0
- package/lib/main/nodes/TweetNode.d.ts +31 -0
- package/lib/main/nodes/TweetNode.js +126 -0
- package/lib/main/nodes/YouTubeNode.d.ts +32 -0
- package/lib/main/nodes/YouTubeNode.js +94 -0
- package/lib/main/plugins/AutoEmbedPlugin/index.d.ts +27 -0
- package/lib/main/plugins/AutoEmbedPlugin/index.js +353 -0
- package/lib/main/plugins/AutoEmbedPlugin/urlParseCache.d.ts +2 -0
- package/lib/main/plugins/AutoEmbedPlugin/urlParseCache.js +14 -0
- package/lib/main/plugins/AutoLinkPlugin/index.d.ts +9 -0
- package/lib/main/plugins/AutoLinkPlugin/index.js +39 -0
- package/lib/main/plugins/ClickableLinkPlugin/index.d.ts +8 -0
- package/lib/main/plugins/ClickableLinkPlugin/index.js +141 -0
- package/lib/main/plugins/CodeActionMenuPlugin/components/CopyButton/index.d.ts +7 -0
- package/lib/main/plugins/CodeActionMenuPlugin/components/CopyButton/index.js +44 -0
- package/lib/main/plugins/CodeActionMenuPlugin/index.css +46 -0
- package/lib/main/plugins/CodeActionMenuPlugin/index.d.ts +12 -0
- package/lib/main/plugins/CodeActionMenuPlugin/index.js +100 -0
- package/lib/main/plugins/CodeActionMenuPlugin/utils.d.ts +2 -0
- package/lib/main/plugins/CodeActionMenuPlugin/utils.js +18 -0
- package/lib/main/plugins/CodeHighlightPlugin/index.d.ts +9 -0
- package/lib/main/plugins/CodeHighlightPlugin/index.js +17 -0
- package/lib/main/plugins/CollapsiblePlugin/Collapsible.css +61 -0
- package/lib/main/plugins/CollapsiblePlugin/CollapsibleContainerNode.d.ts +30 -0
- package/lib/main/plugins/CollapsiblePlugin/CollapsibleContainerNode.js +120 -0
- package/lib/main/plugins/CollapsiblePlugin/CollapsibleContentNode.d.ts +24 -0
- package/lib/main/plugins/CollapsiblePlugin/CollapsibleContentNode.js +90 -0
- package/lib/main/plugins/CollapsiblePlugin/CollapsibleTitleNode.d.ts +24 -0
- package/lib/main/plugins/CollapsiblePlugin/CollapsibleTitleNode.js +95 -0
- package/lib/main/plugins/CollapsiblePlugin/CollapsibleUtils.d.ts +9 -0
- package/lib/main/plugins/CollapsiblePlugin/CollapsibleUtils.js +15 -0
- package/lib/main/plugins/CollapsiblePlugin/index.d.ts +11 -0
- package/lib/main/plugins/CollapsiblePlugin/index.js +147 -0
- package/lib/main/plugins/ComponentPickerPlugin/index.d.ts +12 -0
- package/lib/main/plugins/ComponentPickerPlugin/index.js +438 -0
- package/lib/main/plugins/DragDropPastePlugin/index.d.ts +8 -0
- package/lib/main/plugins/DragDropPastePlugin/index.js +32 -0
- package/lib/main/plugins/DraggableBlockPlugin/index.css +36 -0
- package/lib/main/plugins/DraggableBlockPlugin/index.d.ts +12 -0
- package/lib/main/plugins/DraggableBlockPlugin/index.js +288 -0
- package/lib/main/plugins/EmojisPlugin/index.d.ts +9 -0
- package/lib/main/plugins/EmojisPlugin/index.js +63 -0
- package/lib/main/plugins/ExcalidrawPlugin/index.d.ts +3 -0
- package/lib/main/plugins/ExcalidrawPlugin/index.js +30 -0
- package/lib/main/plugins/FigmaPlugin/index.d.ts +11 -0
- package/lib/main/plugins/FigmaPlugin/index.js +27 -0
- package/lib/main/plugins/FloatingLinkEditorPlugin/index.css +39 -0
- package/lib/main/plugins/FloatingLinkEditorPlugin/index.d.ts +12 -0
- package/lib/main/plugins/FloatingLinkEditorPlugin/index.js +181 -0
- package/lib/main/plugins/FloatingTextFormatToolbarPlugin/ColorPickerButton.d.ts +5 -0
- package/lib/main/plugins/FloatingTextFormatToolbarPlugin/ColorPickerButton.js +24 -0
- package/lib/main/plugins/FloatingTextFormatToolbarPlugin/index.css +128 -0
- package/lib/main/plugins/FloatingTextFormatToolbarPlugin/index.d.ts +12 -0
- package/lib/main/plugins/FloatingTextFormatToolbarPlugin/index.js +216 -0
- package/lib/main/plugins/HorizontalRulePlugin/index.d.ts +8 -0
- package/lib/main/plugins/HorizontalRulePlugin/index.js +30 -0
- package/lib/main/plugins/ImagesPlugin/index.d.ts +15 -0
- package/lib/main/plugins/ImagesPlugin/index.js +36 -0
- package/lib/main/plugins/LexicalTypeaheadMenuPlugin/index.d.ts +64 -0
- package/lib/main/plugins/LexicalTypeaheadMenuPlugin/index.js +493 -0
- package/lib/main/plugins/MarkdownShortcutPlugin/index.d.ts +9 -0
- package/lib/main/plugins/MarkdownShortcutPlugin/index.js +22 -0
- package/lib/main/plugins/MarkdownTransformers/index.d.ts +12 -0
- package/lib/main/plugins/MarkdownTransformers/index.js +185 -0
- package/lib/main/plugins/MaxLengthPlugin/index.d.ts +10 -0
- package/lib/main/plugins/MaxLengthPlugin/index.js +43 -0
- package/lib/main/plugins/MentionsPlugin/HighlightStyle.d.ts +2 -0
- package/lib/main/plugins/MentionsPlugin/HighlightStyle.js +13 -0
- package/lib/main/plugins/MentionsPlugin/index.d.ts +9 -0
- package/lib/main/plugins/MentionsPlugin/index.js +175 -0
- package/lib/main/plugins/TabFocusPlugin/index.d.ts +8 -0
- package/lib/main/plugins/TabFocusPlugin/index.js +41 -0
- package/lib/main/plugins/TableActionMenuPlugin/index.d.ts +12 -0
- package/lib/main/plugins/TableActionMenuPlugin/index.js +486 -0
- package/lib/main/plugins/TableCellResizer/index.css +20 -0
- package/lib/main/plugins/TableCellResizer/index.d.ts +3 -0
- package/lib/main/plugins/TableCellResizer/index.js +295 -0
- package/lib/main/plugins/TableOfContentsPlugin/index.css +87 -0
- package/lib/main/plugins/TableOfContentsPlugin/index.d.ts +2 -0
- package/lib/main/plugins/TableOfContentsPlugin/index.js +106 -0
- package/lib/main/plugins/TablePlugin.d.ts +38 -0
- package/lib/main/plugins/TablePlugin.js +63 -0
- package/lib/main/plugins/ToolbarPlugin/index.d.ts +8 -0
- package/lib/main/plugins/ToolbarPlugin/index.js +467 -0
- package/lib/main/plugins/TreeViewPlugin/index.d.ts +9 -0
- package/lib/main/plugins/TreeViewPlugin/index.js +14 -0
- package/lib/main/plugins/TwitterPlugin/index.d.ts +11 -0
- package/lib/main/plugins/TwitterPlugin/index.js +27 -0
- package/lib/main/plugins/TypingPerfPlugin/index.d.ts +9 -0
- package/lib/main/plugins/TypingPerfPlugin/index.js +100 -0
- package/lib/main/plugins/YouTubePlugin/index.d.ts +11 -0
- package/lib/main/plugins/YouTubePlugin/index.js +27 -0
- package/lib/main/server/validation.d.ts +8 -0
- package/lib/main/server/validation.js +119 -0
- package/lib/main/setupEnv.d.ts +8 -0
- package/lib/main/setupEnv.js +25 -0
- package/lib/main/style/editable.css +476 -0
- package/lib/main/styled-editor-content.d.ts +5 -0
- package/lib/main/styled-editor-content.js +206 -0
- package/lib/main/themes/code-highlight/index.d.ts +32 -0
- package/lib/main/themes/code-highlight/index.js +58 -0
- package/lib/main/themes/customTheme.d.ts +2 -0
- package/lib/main/themes/customTheme.js +324 -0
- package/lib/main/themes/defaultTheme.d.ts +10 -0
- package/lib/main/themes/defaultTheme.js +554 -0
- package/lib/main/themes/table/index.d.ts +3 -0
- package/lib/main/themes/table/index.js +20 -0
- package/lib/main/themes/table/table.css +214 -0
- package/lib/main/ui/Button.css +36 -0
- package/lib/main/ui/Button.d.ts +18 -0
- package/lib/main/ui/Button.js +13 -0
- package/lib/main/ui/ColorPicker.css +89 -0
- package/lib/main/ui/ColorPicker.d.ts +28 -0
- package/lib/main/ui/ColorPicker.js +206 -0
- package/lib/main/ui/ContentEditable.d.ts +2 -0
- package/lib/main/ui/ContentEditable.js +15 -0
- package/lib/main/ui/Dialog.css +17 -0
- package/lib/main/ui/Dialog.d.ts +16 -0
- package/lib/main/ui/Dialog.js +15 -0
- package/lib/main/ui/DropDown.d.ts +25 -0
- package/lib/main/ui/DropDown.js +146 -0
- package/lib/main/ui/FileInput.d.ts +17 -0
- package/lib/main/ui/FileInput.js +5 -0
- package/lib/main/ui/FrameMockup/browser.css +52 -0
- package/lib/main/ui/FrameMockup/browser.d.ts +13 -0
- package/lib/main/ui/FrameMockup/browser.js +22 -0
- package/lib/main/ui/FrameMockup/index.d.ts +113 -0
- package/lib/main/ui/FrameMockup/index.js +61 -0
- package/lib/main/ui/ImageEnhancer.d.ts +29 -0
- package/lib/main/ui/ImageEnhancer.js +113 -0
- package/lib/main/ui/ImageResizer.d.ts +24 -0
- package/lib/main/ui/ImageResizer.js +154 -0
- package/lib/main/ui/Input.css +30 -0
- package/lib/main/ui/Modal.css +62 -0
- package/lib/main/ui/Modal.d.ts +15 -0
- package/lib/main/ui/Modal.js +50 -0
- package/lib/main/ui/Placeholder.d.ts +6 -0
- package/lib/main/ui/Placeholder.js +20 -0
- package/lib/main/ui/TextInput.d.ts +20 -0
- package/lib/main/ui/TextInput.js +14 -0
- package/lib/main/utils/getDOMRangeRect.d.ts +8 -0
- package/lib/main/utils/getDOMRangeRect.js +22 -0
- package/lib/main/utils/getSelectedNode.d.ts +2 -0
- package/lib/main/utils/getSelectedNode.js +22 -0
- package/lib/main/utils/guard.d.ts +14 -0
- package/lib/main/utils/guard.js +36 -0
- package/lib/main/utils/images.d.ts +10 -0
- package/lib/main/utils/images.js +16 -0
- package/lib/main/utils/join-classes.d.ts +8 -0
- package/lib/main/utils/join-classes.js +10 -0
- package/lib/main/utils/point.d.ts +21 -0
- package/lib/main/utils/point.js +42 -0
- package/lib/main/utils/prevent-duplicate-upload.d.ts +2 -0
- package/lib/main/utils/prevent-duplicate-upload.js +25 -0
- package/lib/main/utils/rect.d.ts +45 -0
- package/lib/main/utils/rect.js +98 -0
- package/lib/main/utils/sanitizeUrl.d.ts +8 -0
- package/lib/main/utils/sanitizeUrl.js +17 -0
- package/lib/main/utils/setFloatingElemPosition.d.ts +1 -0
- package/lib/main/utils/setFloatingElemPosition.js +32 -0
- package/lib/main/utils/swipe.d.ts +11 -0
- package/lib/main/utils/swipe.js +98 -0
- package/lib/main/viewer/index.d.ts +5 -0
- package/lib/main/viewer/index.js +25 -0
- package/lib/main/viewer/types.d.ts +14 -0
- package/lib/main/viewer/types.js +1 -0
- package/lib/main/viewer/viewer.d.ts +3 -0
- package/lib/main/viewer/viewer.js +31 -0
- package/lib/shared/canUseDOM.d.ts +8 -0
- package/lib/shared/canUseDOM.js +10 -0
- package/lib/shared/environment.d.ts +24 -0
- package/lib/shared/environment.js +21 -0
- package/lib/shared/getDOMSelection.d.ts +9 -0
- package/lib/shared/getDOMSelection.js +10 -0
- package/lib/shared/invariant.d.ts +8 -0
- package/lib/shared/invariant.js +16 -0
- package/lib/shared/useLayoutEffect.d.ts +10 -0
- package/lib/shared/useLayoutEffect.js +11 -0
- package/lib/types.d.ts +19 -0
- package/lib/types.js +1 -0
- package/lib/vendor/LexicalCharacterLimitPlugin/LexicalCharacterLimitPlugin.d.ts +15 -0
- package/lib/vendor/LexicalCharacterLimitPlugin/LexicalCharacterLimitPlugin.js +45 -0
- package/lib/vendor/LexicalCharacterLimitPlugin/index.d.ts +1 -0
- package/lib/vendor/LexicalCharacterLimitPlugin/index.js +1 -0
- package/lib/vendor/LexicalCharacterLimitPlugin/useCharacterLimit.d.ts +16 -0
- package/lib/vendor/LexicalCharacterLimitPlugin/useCharacterLimit.js +208 -0
- package/lib/vendor/history/LexicalHistoryPlugin.d.ts +14 -0
- package/lib/vendor/history/LexicalHistoryPlugin.js +15 -0
- package/lib/vendor/history/history/index.d.ts +63 -0
- package/lib/vendor/history/history/index.js +351 -0
- package/lib/vendor/history/useHistory.d.ts +10 -0
- package/lib/vendor/history/useHistory.js +15 -0
- package/package.json +109 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
export function EditorReadyPlugin({ onReady }) {
|
|
4
|
+
const [editor] = useLexicalComposerContext();
|
|
5
|
+
const readyRef = useRef(false);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
return editor.registerRootListener((rootElement, prevRootElement) => {
|
|
8
|
+
if (rootElement && !readyRef.current) {
|
|
9
|
+
readyRef.current = true;
|
|
10
|
+
onReady();
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}, [editor]);
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { DOMConversionMap, DOMExportOutput, EditorConfig, LexicalNode, NodeKey, SerializedLexicalNode, Spread } from 'lexical';
|
|
2
|
+
import { type JSX } from 'react';
|
|
3
|
+
import { DecoratorNode } from 'lexical';
|
|
4
|
+
export declare const getAbsoluteUrl: ({ fileUrl, name }: {
|
|
5
|
+
fileUrl: string;
|
|
6
|
+
name?: string | undefined;
|
|
7
|
+
}) => string;
|
|
8
|
+
export interface FilePayload {
|
|
9
|
+
key?: NodeKey;
|
|
10
|
+
src: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
mimetype?: string;
|
|
13
|
+
width?: number | string;
|
|
14
|
+
height?: number | string;
|
|
15
|
+
}
|
|
16
|
+
export type SerializedFileNode = Spread<{
|
|
17
|
+
height?: number | string;
|
|
18
|
+
src: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
mimetype?: string;
|
|
21
|
+
width?: number | string;
|
|
22
|
+
}, SerializedLexicalNode>;
|
|
23
|
+
export declare class FileNode extends DecoratorNode<JSX.Element> {
|
|
24
|
+
__src: string;
|
|
25
|
+
__name?: string;
|
|
26
|
+
__mimetype?: string;
|
|
27
|
+
__width: 'inherit' | number | string;
|
|
28
|
+
__height: 'inherit' | number | string;
|
|
29
|
+
static getType(): string;
|
|
30
|
+
static clone(node: FileNode): FileNode;
|
|
31
|
+
static importJSON(serializedNode: SerializedFileNode): FileNode;
|
|
32
|
+
exportDOM(): DOMExportOutput;
|
|
33
|
+
static importDOM(): DOMConversionMap | null;
|
|
34
|
+
constructor(src: string, name?: string, mimetype?: string, width?: 'inherit' | number | string, height?: 'inherit' | number | string, key?: NodeKey);
|
|
35
|
+
exportJSON(): SerializedFileNode;
|
|
36
|
+
setWidthAndHeight(width: 'inherit' | number, height: 'inherit' | number): void;
|
|
37
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
38
|
+
updateDOM(): false;
|
|
39
|
+
getSrc(): string;
|
|
40
|
+
setSrc(src: string): void;
|
|
41
|
+
decorate(): JSX.Element;
|
|
42
|
+
}
|
|
43
|
+
export declare function $createFileNode({ height, src, name, mimetype, width, key }: FilePayload): FileNode;
|
|
44
|
+
export declare function $isFileNode(node: LexicalNode | null | undefined): node is FileNode;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Tooltip } from '@mui/material';
|
|
3
|
+
import { useEffect, Suspense, useState } from 'react';
|
|
4
|
+
import { Link } from 'react-router-dom';
|
|
5
|
+
import { joinURL, withQuery } from 'ufo';
|
|
6
|
+
import { Icon } from '@iconify/react';
|
|
7
|
+
import { $applyNodeReplacement, DecoratorNode } from 'lexical';
|
|
8
|
+
import mime from 'mime-types';
|
|
9
|
+
import TablerFileIcon from '@iconify/icons-tabler/file';
|
|
10
|
+
const iconSize = 80;
|
|
11
|
+
const baseColor = 'primary.main';
|
|
12
|
+
const FileComponent = ({ src, mimetype, name }) => {
|
|
13
|
+
const [ext, setExt] = useState('file');
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
setExt(mime.extension(mimetype || '') || 'file');
|
|
16
|
+
}, [mimetype]);
|
|
17
|
+
return (_jsx(Tooltip, { title: name, placement: "top", children: _jsxs(Box, { component: Link, to: src, target: "_blank", sx: {
|
|
18
|
+
// remove a tag underline and color
|
|
19
|
+
color: baseColor,
|
|
20
|
+
textDecoration: 'none',
|
|
21
|
+
display: 'inline-flex',
|
|
22
|
+
flexDirection: 'column',
|
|
23
|
+
alignItems: 'center',
|
|
24
|
+
gap: 1,
|
|
25
|
+
pt: 1.25,
|
|
26
|
+
mt: 1,
|
|
27
|
+
border: 2,
|
|
28
|
+
borderColor: baseColor,
|
|
29
|
+
borderRadius: 1,
|
|
30
|
+
transition: 'all 0.3s',
|
|
31
|
+
userSelect: 'none',
|
|
32
|
+
':hover': {
|
|
33
|
+
opacity: 0.75,
|
|
34
|
+
},
|
|
35
|
+
}, children: [_jsxs(Box, { sx: {
|
|
36
|
+
position: 'relative',
|
|
37
|
+
display: 'inline-flex',
|
|
38
|
+
}, children: [_jsx(Icon, { icon: TablerFileIcon, style: { fontSize: iconSize } }), _jsx(Box, { sx: {
|
|
39
|
+
position: 'absolute',
|
|
40
|
+
left: 0,
|
|
41
|
+
right: 0,
|
|
42
|
+
top: '50%',
|
|
43
|
+
textAlign: 'center',
|
|
44
|
+
margin: 'auto',
|
|
45
|
+
fontWeight: 900,
|
|
46
|
+
maxWidth: iconSize * 0.45,
|
|
47
|
+
whiteSpace: 'nowrap',
|
|
48
|
+
overflow: 'hidden',
|
|
49
|
+
textOverflow: 'ellipsis',
|
|
50
|
+
fontSize: 14,
|
|
51
|
+
}, children: ext })] }), _jsx(Box, { sx: {
|
|
52
|
+
bgcolor: baseColor,
|
|
53
|
+
color: 'white',
|
|
54
|
+
px: 1,
|
|
55
|
+
lineHeight: 2,
|
|
56
|
+
fontSize: 13,
|
|
57
|
+
textAlign: 'center',
|
|
58
|
+
maxWidth: iconSize * 1.5,
|
|
59
|
+
whiteSpace: 'nowrap',
|
|
60
|
+
overflow: 'hidden',
|
|
61
|
+
display: 'inline-block',
|
|
62
|
+
'@keyframes scroll': {
|
|
63
|
+
'0%': {
|
|
64
|
+
ml: 0,
|
|
65
|
+
transform: 'translateX(0)',
|
|
66
|
+
},
|
|
67
|
+
'100%': {
|
|
68
|
+
ml: '100%',
|
|
69
|
+
transform: 'translateX(-100%)',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
}, children: _jsx(Box, { sx: {
|
|
73
|
+
animation: 'scroll linear 5s alternate infinite',
|
|
74
|
+
float: 'left',
|
|
75
|
+
minWidth: iconSize,
|
|
76
|
+
}, children: name }) })] }) }));
|
|
77
|
+
};
|
|
78
|
+
export const getAbsoluteUrl = ({ fileUrl, name }) => {
|
|
79
|
+
if (!fileUrl || typeof fileUrl !== 'string') {
|
|
80
|
+
return '';
|
|
81
|
+
}
|
|
82
|
+
if (/^https?:\/\//.test(fileUrl)) {
|
|
83
|
+
return withQuery(fileUrl, {
|
|
84
|
+
filename: name,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
// @ts-ignore
|
|
88
|
+
const { componentMountPoints = [] } = window.blocklet;
|
|
89
|
+
const mediaKit = componentMountPoints.find((x) => x.did === 'z8ia1mAXo8ZE7ytGF36L5uBf9kD2kenhqFGp9');
|
|
90
|
+
const realUrl = mediaKit ? joinURL(window.location.origin, mediaKit.mountPoint || '/', '/uploads', fileUrl) : fileUrl;
|
|
91
|
+
return withQuery(realUrl, {
|
|
92
|
+
filename: name,
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
function convertFileElement(domNode) {
|
|
96
|
+
if (domNode instanceof HTMLObjectElement) {
|
|
97
|
+
// @ts-ignore
|
|
98
|
+
const { data, width, height, type, alt } = domNode;
|
|
99
|
+
const node = $createFileNode({ height, width, src: data, mimetype: type, name: alt });
|
|
100
|
+
return { node };
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
export class FileNode extends DecoratorNode {
|
|
105
|
+
__src;
|
|
106
|
+
__name;
|
|
107
|
+
__mimetype;
|
|
108
|
+
__width;
|
|
109
|
+
__height;
|
|
110
|
+
static getType() {
|
|
111
|
+
return 'file';
|
|
112
|
+
}
|
|
113
|
+
static clone(node) {
|
|
114
|
+
return new FileNode(node.__src, node.__name, node.__mimetype, node.__width, node.__height, node.__key);
|
|
115
|
+
}
|
|
116
|
+
static importJSON(serializedNode) {
|
|
117
|
+
const { height, width, src, mimetype, name } = serializedNode;
|
|
118
|
+
const node = $createFileNode({
|
|
119
|
+
height,
|
|
120
|
+
src,
|
|
121
|
+
width,
|
|
122
|
+
mimetype,
|
|
123
|
+
name,
|
|
124
|
+
});
|
|
125
|
+
return node;
|
|
126
|
+
}
|
|
127
|
+
exportDOM() {
|
|
128
|
+
const element = document.createElement('object');
|
|
129
|
+
element.setAttribute('data', this.__src);
|
|
130
|
+
element.setAttribute('width', this.__width.toString());
|
|
131
|
+
element.setAttribute('height', this.__height.toString());
|
|
132
|
+
element.setAttribute('type', this.__mimetype || 'image/png');
|
|
133
|
+
element.setAttribute('loading', 'lazy');
|
|
134
|
+
element.setAttribute('alt', this.__name || '');
|
|
135
|
+
return { element };
|
|
136
|
+
}
|
|
137
|
+
static importDOM() {
|
|
138
|
+
return {
|
|
139
|
+
object: (node) => ({
|
|
140
|
+
conversion: convertFileElement,
|
|
141
|
+
priority: 0,
|
|
142
|
+
}),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
constructor(src, name, mimetype, width, height, key) {
|
|
146
|
+
super(key);
|
|
147
|
+
this.__src = src;
|
|
148
|
+
this.__name = name;
|
|
149
|
+
this.__mimetype = mimetype;
|
|
150
|
+
this.__width = width || 'inherit';
|
|
151
|
+
this.__height = height || 'inherit';
|
|
152
|
+
}
|
|
153
|
+
exportJSON() {
|
|
154
|
+
return {
|
|
155
|
+
height: this.__height === 'inherit' ? 0 : this.__height,
|
|
156
|
+
src: this.getSrc(),
|
|
157
|
+
type: 'file',
|
|
158
|
+
version: 1,
|
|
159
|
+
width: this.__width === 'inherit' ? 0 : this.__width,
|
|
160
|
+
name: this.__name,
|
|
161
|
+
mimetype: this.__mimetype,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
setWidthAndHeight(width, height) {
|
|
165
|
+
const writable = this.getWritable();
|
|
166
|
+
writable.__width = width;
|
|
167
|
+
writable.__height = height;
|
|
168
|
+
}
|
|
169
|
+
createDOM(config) {
|
|
170
|
+
const span = document.createElement('span');
|
|
171
|
+
return span;
|
|
172
|
+
}
|
|
173
|
+
updateDOM() {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
getSrc() {
|
|
177
|
+
return this.__src;
|
|
178
|
+
}
|
|
179
|
+
setSrc(src) {
|
|
180
|
+
const writable = this.getWritable();
|
|
181
|
+
writable.__src = src;
|
|
182
|
+
}
|
|
183
|
+
decorate() {
|
|
184
|
+
return (_jsx(Suspense, { fallback: null, children: _jsx(FileComponent, { src: getAbsoluteUrl({
|
|
185
|
+
fileUrl: this.__src,
|
|
186
|
+
name: this.__name,
|
|
187
|
+
}), mimetype: this.__mimetype, name: this.__name }) }));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
export function $createFileNode({ height, src, name, mimetype, width, key }) {
|
|
191
|
+
return $applyNodeReplacement(new FileNode(src, name, mimetype, width, height, key));
|
|
192
|
+
}
|
|
193
|
+
export function $isFileNode(node) {
|
|
194
|
+
return node instanceof FileNode;
|
|
195
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LexicalCommand } from 'lexical';
|
|
2
|
+
import { type JSX } from 'react';
|
|
3
|
+
import { FilePayload } from './FileNode';
|
|
4
|
+
export type InsertFilePayload = Readonly<FilePayload>;
|
|
5
|
+
export declare const INSERT_FILE_COMMAND: LexicalCommand<InsertFilePayload>;
|
|
6
|
+
export declare function FilePlugin(): JSX.Element | null;
|
|
7
|
+
export declare const isFile: (filename: string) => string | undefined;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
2
|
+
import { $wrapNodeInElement, mergeRegister } from '@lexical/utils';
|
|
3
|
+
import { $createParagraphNode, $insertNodes, $isRootOrShadowRoot, COMMAND_PRIORITY_EDITOR, createCommand, } from 'lexical';
|
|
4
|
+
import { useEffect } from 'react';
|
|
5
|
+
import { $createFileNode, FileNode } from './FileNode';
|
|
6
|
+
export const INSERT_FILE_COMMAND = createCommand('INSERT_FILE_COMMAND');
|
|
7
|
+
export function FilePlugin() {
|
|
8
|
+
const [editor] = useLexicalComposerContext();
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (!editor.hasNodes([FileNode])) {
|
|
11
|
+
throw new Error('FilePlugin: FileNode not registered on editor');
|
|
12
|
+
}
|
|
13
|
+
return mergeRegister(editor.registerCommand(INSERT_FILE_COMMAND, (payload) => {
|
|
14
|
+
const fileNode = $createFileNode(payload);
|
|
15
|
+
$insertNodes([fileNode]);
|
|
16
|
+
if ($isRootOrShadowRoot(fileNode.getParentOrThrow())) {
|
|
17
|
+
$wrapNodeInElement(fileNode, $createParagraphNode).selectEnd();
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}, COMMAND_PRIORITY_EDITOR));
|
|
21
|
+
}, [editor]);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
export const isFile = (filename) => {
|
|
25
|
+
const ext = filename.split('.').pop();
|
|
26
|
+
return ext;
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function HeadingsIdPlugin(): null;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
2
|
+
import { HeadingNode } from '@lexical/rich-text';
|
|
3
|
+
import { $createTextNode } from 'lexical';
|
|
4
|
+
import { useEffect, useRef } from 'react';
|
|
5
|
+
import { $createLinkNode, $isLinkNode } from '@lexical/link';
|
|
6
|
+
// Generates a random ID
|
|
7
|
+
function genRandomId() {
|
|
8
|
+
return Math.random().toString(36).substr(2, 3);
|
|
9
|
+
}
|
|
10
|
+
function removeAnchors(headingNode) {
|
|
11
|
+
headingNode.getChildren().forEach((child) => {
|
|
12
|
+
if ($isLinkNode(child) && child.getURL().startsWith('#')) {
|
|
13
|
+
child.remove();
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
const headingIdTransform = (headingNode, editor) => {
|
|
18
|
+
// enable this transformer only when editor is not editable
|
|
19
|
+
if (editor.isEditable()) {
|
|
20
|
+
// 编辑模式下, 清理多余的 anchors (因在阅读模式下勾选 checkbox 导致 anchors 被持久化, #1737)
|
|
21
|
+
removeAnchors(headingNode);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const el = editor.getElementByKey(headingNode.getKey());
|
|
25
|
+
if (el) {
|
|
26
|
+
const id = el.getAttribute('id');
|
|
27
|
+
if (!id) {
|
|
28
|
+
const randomId = genRandomId();
|
|
29
|
+
const textContent = headingNode.getTextContent();
|
|
30
|
+
const headingId = encodeURIComponent(textContent
|
|
31
|
+
.toLowerCase()
|
|
32
|
+
.replace(/\s+/g, '-')
|
|
33
|
+
.replace(/(^-|-$)/g, '') || randomId);
|
|
34
|
+
// avoid duplicate id
|
|
35
|
+
const uniqueId = document.getElementById(headingId) ? `${headingId}-${randomId}` : headingId;
|
|
36
|
+
el.setAttribute('id', uniqueId);
|
|
37
|
+
// 先清理 heading 内的 anchor, 再添加新的 anchor, 避免 heading 内出现重复的 anchor (#1737)
|
|
38
|
+
removeAnchors(headingNode);
|
|
39
|
+
const linkNode = $createLinkNode(`#${uniqueId}`).append($createTextNode('#'));
|
|
40
|
+
headingNode.append(linkNode);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
// refer to: https://gist.github.com/ericdcobb/b9dc0e9d985c8bd0d9a3ecf9ec87d417#file-scrolltolocation-js
|
|
45
|
+
const useScrollToLocation = () => {
|
|
46
|
+
const scrolledRef = useRef(false);
|
|
47
|
+
const { hash } = window.location;
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (hash && !scrolledRef.current) {
|
|
50
|
+
const id = hash.replace('#', '');
|
|
51
|
+
const element = document.getElementById(id);
|
|
52
|
+
if (element) {
|
|
53
|
+
// @see https://github.com/facebook/react/issues/23396
|
|
54
|
+
element.scrollIntoView();
|
|
55
|
+
scrolledRef.current = true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
export function HeadingsIdPlugin() {
|
|
61
|
+
const [editor] = useLexicalComposerContext();
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
return editor.registerNodeTransform(HeadingNode, (node) => headingIdTransform(node, editor));
|
|
64
|
+
}, [editor]);
|
|
65
|
+
useScrollToLocation();
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function ImagePathFixerPlugin(): null;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useLayoutEffect } from 'react';
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { joinURL } from 'ufo';
|
|
4
|
+
import { discussKitUploadsUrl } from './utils';
|
|
5
|
+
import { ImageNode } from '../main/nodes/ImageNode';
|
|
6
|
+
const originalExportJSON = ImageNode.prototype.exportJSON;
|
|
7
|
+
const ensureLeadingSlash = (str) => (str.startsWith('/') ? str : `/${str}`);
|
|
8
|
+
ImageNode.prototype.exportJSON = function exportJSON() {
|
|
9
|
+
const json = originalExportJSON.call(this);
|
|
10
|
+
// 保存 editor content 时恢复 image src (剥除 discussKitUploadsUrl)
|
|
11
|
+
if (json.src && json.src.startsWith(discussKitUploadsUrl)) {
|
|
12
|
+
json.src = json.src.replace(discussKitUploadsUrl, '');
|
|
13
|
+
json.src = ensureLeadingSlash(json.src);
|
|
14
|
+
}
|
|
15
|
+
return json;
|
|
16
|
+
};
|
|
17
|
+
function imageNodeTransform(node) {
|
|
18
|
+
const targetNode = node;
|
|
19
|
+
const src = targetNode.getSrc();
|
|
20
|
+
// 仅处理以 "/" 为前缀的 image src, 并且避免重复处理
|
|
21
|
+
if (src?.startsWith('/') && !src.startsWith(discussKitUploadsUrl)) {
|
|
22
|
+
targetNode.setSrc(joinURL(discussKitUploadsUrl, src));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export default function ImagePathFixerPlugin() {
|
|
26
|
+
const [editor] = useLexicalComposerContext();
|
|
27
|
+
useLayoutEffect(() => {
|
|
28
|
+
return editor.registerNodeTransform(ImageNode, imageNodeTransform);
|
|
29
|
+
}, [editor]);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { LexicalEditor } from 'lexical';
|
|
2
|
+
import { DisplayMode } from './types';
|
|
3
|
+
export interface TranslateItem {
|
|
4
|
+
sid: string;
|
|
5
|
+
text: string;
|
|
6
|
+
}
|
|
7
|
+
export type TranslateService = ({ sourceItems, targetLanguage, useCache, }: {
|
|
8
|
+
sourceItems: TranslateItem[];
|
|
9
|
+
targetLanguage: string;
|
|
10
|
+
useCache?: boolean;
|
|
11
|
+
}) => Promise<TranslateItem[]>;
|
|
12
|
+
export interface EditorTranslatorOptions {
|
|
13
|
+
displayMode: DisplayMode;
|
|
14
|
+
}
|
|
15
|
+
export declare class EditorTranslator {
|
|
16
|
+
private editor;
|
|
17
|
+
private options;
|
|
18
|
+
private originalEditorState;
|
|
19
|
+
private preprocessEditorState;
|
|
20
|
+
private nodeKeyToSidMap;
|
|
21
|
+
private sidToNodeKeyMap;
|
|
22
|
+
private translations;
|
|
23
|
+
private sourceItems;
|
|
24
|
+
isTranslating: boolean;
|
|
25
|
+
constructor(editor: LexicalEditor, options: EditorTranslatorOptions);
|
|
26
|
+
get isTranslated(): boolean;
|
|
27
|
+
setEditor(editor: LexicalEditor): void;
|
|
28
|
+
updateOptions(options: EditorTranslatorOptions): void;
|
|
29
|
+
updateDisplayMode(): void;
|
|
30
|
+
translate({ targetLanguage, translateService, detectLanguage, useCache, }: {
|
|
31
|
+
targetLanguage: string;
|
|
32
|
+
translateService: TranslateService;
|
|
33
|
+
detectLanguage: (text: string) => string | null;
|
|
34
|
+
useCache?: boolean;
|
|
35
|
+
}): Promise<void>;
|
|
36
|
+
applyTranslations(): void;
|
|
37
|
+
restore(sid?: string): void;
|
|
38
|
+
preprocessNodes(): Promise<void>;
|
|
39
|
+
getOriginalText(sid: string): string | undefined;
|
|
40
|
+
getTranslationText(sid: string): string | undefined;
|
|
41
|
+
}
|
|
42
|
+
export declare function useEditorTranslator(options: EditorTranslatorOptions): EditorTranslator;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
2
|
+
import { $createParagraphNode, $getNodeByKey } from 'lexical';
|
|
3
|
+
import { useRef, useEffect } from 'react';
|
|
4
|
+
import { $createNodeKeyToSidMap, $createSidToNodeKeyMap, $nodeToHtml, $findTranslatableElementNodes, $htmlToNodes, } from '../translation/translation-utils';
|
|
5
|
+
import { $createEmojiNode } from '../../main/nodes/EmojiNode';
|
|
6
|
+
import { $createTranslationNode } from './TranslationNode';
|
|
7
|
+
import { $isExcalidrawNode } from '../../main/nodes/ExcalidrawNode';
|
|
8
|
+
import { $isImageNode } from '../../main/nodes/ImageNode';
|
|
9
|
+
import { $isVideoNode } from '../VideoPlugin/VideoNode';
|
|
10
|
+
import { $isFileNode } from '../FilePlugin/FileNode';
|
|
11
|
+
export class EditorTranslator {
|
|
12
|
+
editor;
|
|
13
|
+
options;
|
|
14
|
+
originalEditorState;
|
|
15
|
+
preprocessEditorState = null;
|
|
16
|
+
nodeKeyToSidMap = new Map();
|
|
17
|
+
sidToNodeKeyMap = new Map();
|
|
18
|
+
translations = [];
|
|
19
|
+
sourceItems = [];
|
|
20
|
+
isTranslating = false;
|
|
21
|
+
constructor(editor, options) {
|
|
22
|
+
this.editor = editor;
|
|
23
|
+
this.options = options;
|
|
24
|
+
this.originalEditorState = editor.getEditorState();
|
|
25
|
+
}
|
|
26
|
+
get isTranslated() {
|
|
27
|
+
return this.translations.length > 0;
|
|
28
|
+
}
|
|
29
|
+
setEditor(editor) {
|
|
30
|
+
this.editor = editor;
|
|
31
|
+
}
|
|
32
|
+
updateOptions(options) {
|
|
33
|
+
const previousDisplayMode = this.options.displayMode;
|
|
34
|
+
this.options = options;
|
|
35
|
+
if (this.isTranslated && previousDisplayMode !== this.options.displayMode) {
|
|
36
|
+
this.updateDisplayMode();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
updateDisplayMode() {
|
|
40
|
+
// Warning: flushSync was called from inside a lifecycle method
|
|
41
|
+
setTimeout(() => {
|
|
42
|
+
this.editor.setEditorState(this.preprocessEditorState || this.originalEditorState);
|
|
43
|
+
this.applyTranslations();
|
|
44
|
+
}, 10);
|
|
45
|
+
}
|
|
46
|
+
async translate({ targetLanguage, translateService, detectLanguage, useCache, }) {
|
|
47
|
+
if (this.isTranslating) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this.isTranslating = true;
|
|
51
|
+
// 翻译前备份 editor state (fix 恢复原文时图片路径错误的问题)
|
|
52
|
+
this.originalEditorState = this.editor.getEditorState().clone();
|
|
53
|
+
await this.preprocessNodes();
|
|
54
|
+
this.nodeKeyToSidMap = this.editor.getEditorState().read(() => $createNodeKeyToSidMap());
|
|
55
|
+
this.sidToNodeKeyMap = this.editor.getEditorState().read(() => $createSidToNodeKeyMap());
|
|
56
|
+
let nodes = [];
|
|
57
|
+
this.editor.update(() => {
|
|
58
|
+
nodes = $findTranslatableElementNodes()
|
|
59
|
+
.filter((node) => detectLanguage(node.getTextContent()) !== targetLanguage)
|
|
60
|
+
.map((node) => {
|
|
61
|
+
const html = $nodeToHtml(this.editor, node);
|
|
62
|
+
return { node, html };
|
|
63
|
+
});
|
|
64
|
+
nodes.forEach(({ node }) => {
|
|
65
|
+
node.append($createEmojiNode('global-loading', ''));
|
|
66
|
+
});
|
|
67
|
+
}, { discrete: true });
|
|
68
|
+
if (nodes.length === 0) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
this.sourceItems = nodes.map(({ node, html }) => ({
|
|
73
|
+
sid: this.nodeKeyToSidMap.get(node.getKey()),
|
|
74
|
+
text: html,
|
|
75
|
+
}));
|
|
76
|
+
this.translations = await translateService({
|
|
77
|
+
sourceItems: this.sourceItems,
|
|
78
|
+
targetLanguage,
|
|
79
|
+
useCache,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
console.error(err);
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
nodes.forEach(({ node }, index) => {
|
|
87
|
+
this.editor.update(() => {
|
|
88
|
+
const lastChild = node.getLastChild();
|
|
89
|
+
if (lastChild) {
|
|
90
|
+
lastChild.remove();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (this.isTranslated) {
|
|
96
|
+
this.applyTranslations();
|
|
97
|
+
}
|
|
98
|
+
this.isTranslating = false;
|
|
99
|
+
}
|
|
100
|
+
applyTranslations() {
|
|
101
|
+
this.editor.update(() => {
|
|
102
|
+
this.translations.forEach(({ sid, text }) => {
|
|
103
|
+
try {
|
|
104
|
+
const node = $getNodeByKey(this.sidToNodeKeyMap.get(sid));
|
|
105
|
+
if (node) {
|
|
106
|
+
const translationNode = $createTranslationNode({
|
|
107
|
+
translatedNodes: $htmlToNodes(this.editor, text),
|
|
108
|
+
data: { sid, displayMode: this.options.displayMode },
|
|
109
|
+
});
|
|
110
|
+
if (this.options.displayMode === 'inline') {
|
|
111
|
+
node.append(translationNode);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
node.getChildren().forEach((child) => child.remove());
|
|
115
|
+
node.append(translationNode
|
|
116
|
+
// $createTranslationNode({
|
|
117
|
+
// translatedNodes: node.getChildren(),
|
|
118
|
+
// data: { sid, displayMode: this.options.displayMode },
|
|
119
|
+
// }) // 利用一个隐藏的 TranslationNode 来存储 original nodes, 用于单个结点恢复
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
console.error('Failed to apply translations to editor', e);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
restore(sid) {
|
|
131
|
+
this.editor.update(() => {
|
|
132
|
+
if (!sid) {
|
|
133
|
+
this.editor.setEditorState(this.originalEditorState);
|
|
134
|
+
this.translations = [];
|
|
135
|
+
}
|
|
136
|
+
else if (this.options.displayMode === 'translationOnly') {
|
|
137
|
+
const nodeKey = this.sidToNodeKeyMap.get(sid);
|
|
138
|
+
if (!nodeKey) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
// TranslationNode 容器结点
|
|
142
|
+
const node = $getNodeByKey(nodeKey);
|
|
143
|
+
if (node && node.getChildren().length === 2) {
|
|
144
|
+
const firstTranslationNode = node.getFirstChild();
|
|
145
|
+
const secondTranslationNode = node.getLastChild();
|
|
146
|
+
node.append(secondTranslationNode, firstTranslationNode);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
async preprocessNodes() {
|
|
152
|
+
const isSpecialNode = (node) => {
|
|
153
|
+
return $isExcalidrawNode(node) || $isImageNode(node) || $isVideoNode(node) || $isFileNode(node);
|
|
154
|
+
};
|
|
155
|
+
this.editor.update(() => {
|
|
156
|
+
$findTranslatableElementNodes().forEach((node) => {
|
|
157
|
+
// 如果 children 中即包含特殊结点, 也包含普通结点, 则将特殊结点与普通结点分开
|
|
158
|
+
const children = node.getChildren();
|
|
159
|
+
if (!children.some(isSpecialNode) || children.every(isSpecialNode)) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const normalNodes = [];
|
|
163
|
+
children.forEach((child) => {
|
|
164
|
+
if (isSpecialNode(child)) {
|
|
165
|
+
if (normalNodes.length > 0) {
|
|
166
|
+
node.insertBefore($createParagraphNode().append(...normalNodes));
|
|
167
|
+
normalNodes.length = 0;
|
|
168
|
+
}
|
|
169
|
+
node.insertBefore($createParagraphNode().append(child));
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
normalNodes.push(child);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}, { discrete: true });
|
|
176
|
+
});
|
|
177
|
+
// 延时 10ms, 否则获取的 node-key <=> sid 映射不准确
|
|
178
|
+
// eslint-disable-next-line no-promise-executor-return
|
|
179
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
180
|
+
this.preprocessEditorState = this.editor.getEditorState().clone();
|
|
181
|
+
}
|
|
182
|
+
getOriginalText(sid) {
|
|
183
|
+
return this.sourceItems.find((item) => item.sid === sid)?.text;
|
|
184
|
+
}
|
|
185
|
+
getTranslationText(sid) {
|
|
186
|
+
return this.translations.find((item) => item.sid === sid)?.text;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
export function useEditorTranslator(options) {
|
|
190
|
+
const [editor] = useLexicalComposerContext();
|
|
191
|
+
const ref = useRef(new EditorTranslator(editor, options));
|
|
192
|
+
useEffect(() => {
|
|
193
|
+
ref.current.setEditor(editor);
|
|
194
|
+
}, [editor]);
|
|
195
|
+
useEffect(() => {
|
|
196
|
+
ref.current.updateOptions(options);
|
|
197
|
+
}, [...Object.values(options)]);
|
|
198
|
+
return ref.current;
|
|
199
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TranslateService } from './EditorTranslator';
|
|
2
|
+
interface Props {
|
|
3
|
+
translateService: TranslateService;
|
|
4
|
+
detectLanguage: (text: string) => string | null;
|
|
5
|
+
onTranslate?: ({ targetLanguage }: {
|
|
6
|
+
targetLanguage: string;
|
|
7
|
+
}) => void;
|
|
8
|
+
onRestore?: () => void;
|
|
9
|
+
showTranslationBadge?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function InlineTranslationPlugin(props: Props): import("react/jsx-runtime").JSX.Element | null;
|
|
12
|
+
export {};
|