@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,180 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { createDOMRange, createRectsFromDOMRange } from '@lexical/selection';
|
|
4
|
+
import Box from '@mui/material/Box';
|
|
5
|
+
import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_NORMAL, createCommand, } from 'lexical';
|
|
6
|
+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
7
|
+
import { createPortal } from 'react-dom';
|
|
8
|
+
import { mergeRegister } from '@lexical/utils';
|
|
9
|
+
import { SelectionPopper } from '../../components/SelectionPopper';
|
|
10
|
+
import { useEditorConfig } from '../../config';
|
|
11
|
+
import { Aide, AideProvider, useAideContext } from '../Aide';
|
|
12
|
+
import TextGeneration from './TextGeneration';
|
|
13
|
+
import { replace, insertBelow, copy } from './utils';
|
|
14
|
+
import AIKitIcon from './AIIcon';
|
|
15
|
+
import { useAIAvailable } from '../Aide/hooks';
|
|
16
|
+
export const ACTIVATE_AI_COMMAND = createCommand('ACTIVATE_AI_COMMAND');
|
|
17
|
+
// AI external templates 可用时通过该命令与 editor 其它插件通讯
|
|
18
|
+
export const AI_TEMPLATES_AVAILABLE_COMMAND = createCommand('AI_TEMPLATES_AVAILABLE_COMMAND');
|
|
19
|
+
const globalStates = { templatesAvailable: false };
|
|
20
|
+
export function AideFloatingToolbarButton({ onClick }) {
|
|
21
|
+
const [editor] = useLexicalComposerContext();
|
|
22
|
+
const { available } = useAIAvailable();
|
|
23
|
+
return (_jsx("button", { disabled: !available, onClick: () => {
|
|
24
|
+
editor.dispatchCommand(ACTIVATE_AI_COMMAND, 'normal');
|
|
25
|
+
onClick?.();
|
|
26
|
+
}, className: "popup-item spaced", "aria-label": "Ask AI", children: _jsx(AIKitIcon, { disabled: !available }) }));
|
|
27
|
+
}
|
|
28
|
+
export function AideToolbarButton() {
|
|
29
|
+
const [editor] = useLexicalComposerContext();
|
|
30
|
+
const { available } = useAIAvailable();
|
|
31
|
+
const [templatesAvailable, setTemplatesAvailable] = useState(globalStates.templatesAvailable);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
return mergeRegister(editor.registerCommand(AI_TEMPLATES_AVAILABLE_COMMAND, (payload) => {
|
|
34
|
+
setTemplatesAvailable(payload);
|
|
35
|
+
globalStates.templatesAvailable = payload;
|
|
36
|
+
return false;
|
|
37
|
+
}, COMMAND_PRIORITY_NORMAL));
|
|
38
|
+
}, [editor]);
|
|
39
|
+
return (_jsx(Box, { component: "button", disabled: !editor.isEditable() || !available || !templatesAvailable, onClick: () => {
|
|
40
|
+
editor.dispatchCommand(ACTIVATE_AI_COMMAND, 'templates');
|
|
41
|
+
}, className: "toolbar-item aide", sx: { svg: { opacity: 0.6 } }, children: _jsx("i", { className: "iconify", "data-icon": "tabler:sparkles" }) }));
|
|
42
|
+
}
|
|
43
|
+
function AideBox({ editor }) {
|
|
44
|
+
const boxRef = useRef(null);
|
|
45
|
+
const selectionState = useMemo(() => {
|
|
46
|
+
const container = document.createElement('div');
|
|
47
|
+
container.style.position = 'relative';
|
|
48
|
+
container.style.zIndex = '0';
|
|
49
|
+
return {
|
|
50
|
+
container,
|
|
51
|
+
elements: [],
|
|
52
|
+
};
|
|
53
|
+
}, []);
|
|
54
|
+
// FIXME: 参考 lexical playground 中的 MentionPlugin 代码, 用于 editor 失去焦点时保持 selection, 页面滚动时有飘移问题
|
|
55
|
+
const updateLocation = useCallback(() => {
|
|
56
|
+
editor.getEditorState().read(() => {
|
|
57
|
+
const selection = $getSelection();
|
|
58
|
+
if ($isRangeSelection(selection)) {
|
|
59
|
+
const { anchor } = selection;
|
|
60
|
+
const { focus } = selection;
|
|
61
|
+
const range = createDOMRange(editor, anchor.getNode(), anchor.offset, focus.getNode(), focus.offset);
|
|
62
|
+
const boxElem = boxRef.current;
|
|
63
|
+
if (range !== null && boxElem !== null) {
|
|
64
|
+
const { left, bottom, width } = range.getBoundingClientRect();
|
|
65
|
+
const selectionRects = createRectsFromDOMRange(editor, range);
|
|
66
|
+
let correctedLeft = selectionRects.length === 1 ? left + width / 2 - 500 : left - 500;
|
|
67
|
+
if (correctedLeft < 10) {
|
|
68
|
+
correctedLeft = 10;
|
|
69
|
+
}
|
|
70
|
+
boxElem.style.left = `${correctedLeft}px`;
|
|
71
|
+
// boxElem.style.top = `${bottom + 20}px`;
|
|
72
|
+
boxElem.style.top = `${bottom}px`;
|
|
73
|
+
const selectionRectsLength = selectionRects.length;
|
|
74
|
+
const { container } = selectionState;
|
|
75
|
+
const { elements } = selectionState;
|
|
76
|
+
const elementsLength = elements.length;
|
|
77
|
+
for (let i = 0; i < selectionRectsLength; i++) {
|
|
78
|
+
const selectionRect = selectionRects[i];
|
|
79
|
+
let elem = elements[i];
|
|
80
|
+
if (elem === undefined) {
|
|
81
|
+
elem = document.createElement('span');
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
elements[i] = elem;
|
|
84
|
+
container.appendChild(elem);
|
|
85
|
+
}
|
|
86
|
+
const color = '0, 122, 255';
|
|
87
|
+
const style = `position:fixed;top:${selectionRect.top}px;left:${selectionRect.left}px;height:${selectionRect.height}px;width:${selectionRect.width}px;background-color:rgba(${color}, 0.3);pointer-events:none;z-index:5;`;
|
|
88
|
+
elem.style.cssText = style;
|
|
89
|
+
}
|
|
90
|
+
for (let i = elementsLength - 1; i >= selectionRectsLength; i--) {
|
|
91
|
+
const elem = elements[i];
|
|
92
|
+
container.removeChild(elem);
|
|
93
|
+
elements.pop();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}, [editor]);
|
|
99
|
+
useLayoutEffect(() => {
|
|
100
|
+
updateLocation();
|
|
101
|
+
const { container } = selectionState;
|
|
102
|
+
const { body } = document;
|
|
103
|
+
if (body !== null) {
|
|
104
|
+
body.appendChild(container);
|
|
105
|
+
return () => {
|
|
106
|
+
body.removeChild(container);
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}, [selectionState.container, updateLocation]);
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
window.addEventListener('resize', updateLocation);
|
|
112
|
+
return () => {
|
|
113
|
+
window.removeEventListener('resize', updateLocation);
|
|
114
|
+
};
|
|
115
|
+
}, [updateLocation]);
|
|
116
|
+
// fix 页面滚动时文本 selection 高亮飘移的问题
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
document.addEventListener('scroll', updateLocation, true);
|
|
119
|
+
return () => {
|
|
120
|
+
document.removeEventListener('scroll', updateLocation, true);
|
|
121
|
+
};
|
|
122
|
+
}, [updateLocation]);
|
|
123
|
+
return _jsx("div", { ref: boxRef });
|
|
124
|
+
}
|
|
125
|
+
function AidePlugin() {
|
|
126
|
+
const [editor] = useLexicalComposerContext();
|
|
127
|
+
const { available, status, externalTemplates, activateAI } = useAideContext();
|
|
128
|
+
const selectionRef = useRef(null);
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
editor.dispatchCommand(AI_TEMPLATES_AVAILABLE_COMMAND, externalTemplates.templates.length > 0);
|
|
131
|
+
}, [externalTemplates]);
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
return editor.registerCommand(ACTIVATE_AI_COMMAND, (mode) => {
|
|
134
|
+
return editor.getEditorState().read(() => {
|
|
135
|
+
const selection = $getSelection();
|
|
136
|
+
if ($isRangeSelection(selection)) {
|
|
137
|
+
activateAI({
|
|
138
|
+
mode,
|
|
139
|
+
selectionText: selection?.getTextContent() || '',
|
|
140
|
+
selection: selection?.clone(),
|
|
141
|
+
});
|
|
142
|
+
selectionRef.current = selection;
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
return false;
|
|
146
|
+
});
|
|
147
|
+
}, COMMAND_PRIORITY_EDITOR);
|
|
148
|
+
}, [editor]);
|
|
149
|
+
const restoreSelection = () => {
|
|
150
|
+
editor.update(() => {
|
|
151
|
+
const selection = $getSelection();
|
|
152
|
+
if (selection !== null) {
|
|
153
|
+
selection.dirty = true;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
if (status === 'initial') {
|
|
159
|
+
restoreSelection();
|
|
160
|
+
}
|
|
161
|
+
}, [status]);
|
|
162
|
+
return (_jsxs(_Fragment, { children: [status !== 'initial' && createPortal(_jsx(AideBox, { editor: editor }), document.body), _jsx(TextGeneration, {}), _jsx(SelectionPopper, { selection: status !== 'initial' ? selectionRef.current : null, sx: { zIndex: 1000 }, children: _jsx(Aide, {}) })] }));
|
|
163
|
+
}
|
|
164
|
+
export default function AidePluginWrapper() {
|
|
165
|
+
const { AI } = useEditorConfig();
|
|
166
|
+
const [editor] = useLexicalComposerContext();
|
|
167
|
+
if (AI) {
|
|
168
|
+
const _replaceSelection = (selection, output) => {
|
|
169
|
+
replace(editor, selection, output);
|
|
170
|
+
};
|
|
171
|
+
const _insertBelow = (selection, output) => {
|
|
172
|
+
insertBelow(editor, selection, output);
|
|
173
|
+
};
|
|
174
|
+
const _copy = (output) => {
|
|
175
|
+
copy(output);
|
|
176
|
+
};
|
|
177
|
+
return (_jsx(AideProvider, { completions: AI.completions, replaceSelection: _replaceSelection, copy: _copy, insertBelow: _insertBelow, children: _jsx(AidePlugin, {}) }));
|
|
178
|
+
}
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { LexicalEditor } from 'lexical';
|
|
2
|
+
export declare const insertBelow: (editor: LexicalEditor, selection: any, text: string) => void;
|
|
3
|
+
export declare const copy: (text: string) => void;
|
|
4
|
+
export declare const insert: (editor: LexicalEditor, range: Range, text: string) => void;
|
|
5
|
+
export declare const replace: (editor: LexicalEditor, selection: any, text: string) => void;
|
|
6
|
+
export declare const getParagraphText: (editor: LexicalEditor) => string | undefined;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { $findMatchingParent } from '@lexical/utils';
|
|
2
|
+
import { $createParagraphNode, $createRangeSelection, $createTextNode, $getSelection, $isRangeSelection, $setSelection, INSERT_LINE_BREAK_COMMAND, } from 'lexical';
|
|
3
|
+
import { $getDepth } from '../../lexical-utils';
|
|
4
|
+
export const insertBelow = (editor, selection, text) => {
|
|
5
|
+
editor.update(() => {
|
|
6
|
+
if ($isRangeSelection(selection)) {
|
|
7
|
+
const secondLevelParentNode = $findMatchingParent(selection.anchor.getNode(), (node) => $getDepth(node) === 1);
|
|
8
|
+
secondLevelParentNode.selectEnd();
|
|
9
|
+
editor.dispatchCommand(INSERT_LINE_BREAK_COMMAND, false);
|
|
10
|
+
const paragraphNode = $createParagraphNode();
|
|
11
|
+
const textNode = $createTextNode(text);
|
|
12
|
+
paragraphNode.append(textNode);
|
|
13
|
+
$getSelection()?.insertNodes(paragraphNode.getAllTextNodes());
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
export const copy = (text) => {
|
|
18
|
+
navigator.clipboard.writeText(text);
|
|
19
|
+
};
|
|
20
|
+
export const insert = (editor, range, text) => {
|
|
21
|
+
editor.update(() => {
|
|
22
|
+
const s = $createRangeSelection();
|
|
23
|
+
s.applyDOMRange(range);
|
|
24
|
+
s.insertNodes([$createTextNode(` ${text}`)]);
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
export const replace = (editor, selection, text) => {
|
|
28
|
+
editor.update(() => {
|
|
29
|
+
if ($isRangeSelection(selection)) {
|
|
30
|
+
$setSelection(selection);
|
|
31
|
+
const s = $getSelection();
|
|
32
|
+
s?.insertText(text);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
export const getParagraphText = (editor) => {
|
|
37
|
+
return editor.getEditorState().read(() => {
|
|
38
|
+
const selection = $getSelection();
|
|
39
|
+
if ($isRangeSelection(selection)) {
|
|
40
|
+
const secondLevelParentNode = $findMatchingParent(selection.anchor.getNode(), (node) => $getDepth(node) === 1);
|
|
41
|
+
return secondLevelParentNode?.getTextContent();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { LexicalCommand } from 'lexical';
|
|
2
|
+
import type { TranslateAPI } from './types';
|
|
3
|
+
export declare const AI_TRANSLATE_AVAILABLE_COMMAND: LexicalCommand<boolean>;
|
|
4
|
+
export declare function AITranslateToolbarButton(): import("react/jsx-runtime").JSX.Element | null;
|
|
5
|
+
interface Props {
|
|
6
|
+
translateAPI?: TranslateAPI;
|
|
7
|
+
}
|
|
8
|
+
export default function AITranslationPlugin(props: Props): null;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { Button, Box, Popover, ClickAwayListener, FormControl, MenuItem, Select, InputLabel, Backdrop, Snackbar, Alert, styled, LinearProgress, linearProgressClasses, Paper, } from '@mui/material';
|
|
4
|
+
import { COMMAND_PRIORITY_NORMAL, createCommand } from 'lexical';
|
|
5
|
+
import { useEffect, useLayoutEffect, useState } from 'react';
|
|
6
|
+
import { createPortal } from 'react-dom';
|
|
7
|
+
import { mergeRegister } from '@lexical/utils';
|
|
8
|
+
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
9
|
+
import { blockletExists } from '../utils';
|
|
10
|
+
import { translateFullContent } from './translation';
|
|
11
|
+
// editor key <=> available
|
|
12
|
+
const availableStates = {};
|
|
13
|
+
export const AI_TRANSLATE_AVAILABLE_COMMAND = createCommand('AI_TRANSLATE_AVAILABLE_COMMAND');
|
|
14
|
+
const BorderLinearProgress = styled(LinearProgress)(({ theme }) => ({
|
|
15
|
+
width: '100%',
|
|
16
|
+
height: 10,
|
|
17
|
+
borderRadius: 5,
|
|
18
|
+
[`&.${linearProgressClasses.colorPrimary}`]: {
|
|
19
|
+
backgroundColor: theme.palette.grey[theme.palette.mode === 'light' ? 200 : 800],
|
|
20
|
+
},
|
|
21
|
+
[`& .${linearProgressClasses.bar}`]: {
|
|
22
|
+
borderRadius: 5,
|
|
23
|
+
bgcolor: 'primary',
|
|
24
|
+
},
|
|
25
|
+
}));
|
|
26
|
+
function Wait({ open, progress, targetLanguage, onCancel, }) {
|
|
27
|
+
return (_jsx(Backdrop, { sx: { bgcolor: 'transparent', zIndex: (theme) => theme.zIndex.drawer + 1 }, open: open, children: _jsxs(Paper, { sx: {
|
|
28
|
+
display: 'flex',
|
|
29
|
+
flexDirection: 'column',
|
|
30
|
+
alignItems: 'center',
|
|
31
|
+
width: { xs: 360, md: 420, lg: 480 },
|
|
32
|
+
maxWidth: '100%',
|
|
33
|
+
px: 4,
|
|
34
|
+
py: 3,
|
|
35
|
+
}, elevation: 3, children: [_jsx(Box, { sx: { mb: 4, color: 'grey.800', fontSize: 20, fontWeight: 'bold' }, children: "Translating" }), _jsx(BorderLinearProgress, { variant: "determinate", value: progress }), _jsxs(Box, { sx: { mt: 3, color: 'grey.600', fontSize: 14, fontWeight: 'bold' }, children: ["Translating content to ", targetLanguage, ". Please be patient."] }), _jsx(Button, { variant: "outlined", color: "inherit", sx: { mt: 3 }, onClick: onCancel, children: "Cancel" })] }) }));
|
|
36
|
+
}
|
|
37
|
+
export function AITranslateToolbarButton() {
|
|
38
|
+
const [editor] = useLexicalComposerContext();
|
|
39
|
+
const { languages = [] } = useLocaleContext() || {};
|
|
40
|
+
const [available, setAvailable] = useState(!!availableStates[editor.getKey()]);
|
|
41
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
42
|
+
const [targetLanguage, setTargetLanguage] = useState(languages[0]?.name);
|
|
43
|
+
const [translating, setTranslating] = useState(false);
|
|
44
|
+
const [progress, setProgress] = useState(1);
|
|
45
|
+
const [error, setError] = useState(null);
|
|
46
|
+
const [abortController, setAbortController] = useState(null);
|
|
47
|
+
const handleClick = (event) => {
|
|
48
|
+
setAnchorEl(event.currentTarget);
|
|
49
|
+
};
|
|
50
|
+
const handleClose = () => {
|
|
51
|
+
setAnchorEl(null);
|
|
52
|
+
};
|
|
53
|
+
const handleClickAway = () => {
|
|
54
|
+
if (!translating) {
|
|
55
|
+
handleClose();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
useLayoutEffect(() => {
|
|
59
|
+
return mergeRegister(editor.registerCommand(AI_TRANSLATE_AVAILABLE_COMMAND, (payload) => {
|
|
60
|
+
setAvailable(payload);
|
|
61
|
+
return false;
|
|
62
|
+
}, COMMAND_PRIORITY_NORMAL));
|
|
63
|
+
}, [editor]);
|
|
64
|
+
if (!available) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const handleTranslate = async () => {
|
|
68
|
+
try {
|
|
69
|
+
const controller = new AbortController();
|
|
70
|
+
setAbortController(controller);
|
|
71
|
+
setTranslating(true);
|
|
72
|
+
setTimeout(() => handleClose());
|
|
73
|
+
await translateFullContent(editor, {
|
|
74
|
+
targetLanguage,
|
|
75
|
+
onProgress: (v) => setProgress(v),
|
|
76
|
+
signal: controller.signal,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
console.error(e);
|
|
81
|
+
setError(e);
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
setTranslating(false);
|
|
85
|
+
setProgress(1);
|
|
86
|
+
setAbortController(null);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const handleCancel = () => {
|
|
90
|
+
abortController?.abort();
|
|
91
|
+
setTranslating(false);
|
|
92
|
+
setProgress(1);
|
|
93
|
+
setAbortController(null);
|
|
94
|
+
};
|
|
95
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Box, { component: "button", disabled: !editor.isEditable(), onClick: handleClick, className: "toolbar-item spaced", sx: { '.iconify': { display: 'flex', alignItems: 'center', fontSize: 18, opacity: 0.6 } }, children: [_jsx("i", { className: "iconify", "data-icon": "ri:translate" }), _jsx(Popover, { open: !!anchorEl, anchorEl: anchorEl, onClose: handleClose, transformOrigin: {
|
|
96
|
+
vertical: 'top',
|
|
97
|
+
horizontal: 'right',
|
|
98
|
+
}, anchorOrigin: {
|
|
99
|
+
vertical: 'bottom',
|
|
100
|
+
horizontal: 'right',
|
|
101
|
+
}, elevation: 1, sx: { mt: 1 }, children: _jsx(ClickAwayListener, { onClickAway: handleClickAway, children: _jsxs(Box, { sx: {
|
|
102
|
+
p: 3,
|
|
103
|
+
border: 1,
|
|
104
|
+
borderColor: 'grey.300',
|
|
105
|
+
borderRadius: 2,
|
|
106
|
+
bgcolor: '#fff',
|
|
107
|
+
boxShadow: '0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)',
|
|
108
|
+
}, children: [_jsx(Box, { sx: { minWidth: 240 }, children: _jsxs(FormControl, { fullWidth: true, size: "small", children: [_jsx(InputLabel, { children: "Target Language" }), _jsx(Select, { label: "Target Language", size: "small", value: targetLanguage, MenuProps: { disablePortal: true }, onChange: (e) => setTargetLanguage(e.target.value), children: languages.map((item) => (_jsx(MenuItem, { value: item.name, children: item.name }, item.name))) })] }) }), _jsx(Button, { variant: "contained", onClick: handleTranslate, disabled: !targetLanguage, sx: { width: 1, mt: 2 }, children: "Translate" })] }) }) })] }), createPortal(_jsxs(_Fragment, { children: [_jsx(Wait, { open: translating, progress: progress, targetLanguage: targetLanguage, onCancel: handleCancel }), _jsx(Snackbar, { open: !!error, autoHideDuration: 6000, anchorOrigin: { vertical: 'top', horizontal: 'right' }, onClose: () => setError(null), children: _jsx(Alert, { onClose: () => setError(null), severity: "error", sx: { width: '100%' }, children: error?.message || 'Translation failed' }) })] }), document.body)] }));
|
|
109
|
+
}
|
|
110
|
+
export default function AITranslationPlugin(props) {
|
|
111
|
+
const [editor] = useLexicalComposerContext();
|
|
112
|
+
const available = blockletExists('ai-kit');
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (available) {
|
|
115
|
+
// 启用了 AITranslationPlugin 的 editor 实例才会在 toolbar 显示翻译按钮
|
|
116
|
+
availableStates[editor.getKey()] = true;
|
|
117
|
+
editor.dispatchCommand(AI_TRANSLATE_AVAILABLE_COMMAND, true);
|
|
118
|
+
}
|
|
119
|
+
return () => {
|
|
120
|
+
delete availableStates[editor.getKey()];
|
|
121
|
+
};
|
|
122
|
+
}, [editor]);
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { $getSelection, $isRangeSelection } from 'lexical';
|
|
2
|
+
import { $replaceTranslations, $extractTranslationBlocksFromSelection, defaultTranslateAPI, $preview, $insertTranslations, } from './utils';
|
|
3
|
+
// const isTranslationBlockWithSelection = (o: any): o is TranslationBlockWithSelection => !!o.point;
|
|
4
|
+
export const translateSelection = async (editor, options) => {
|
|
5
|
+
const selection = editor.getEditorState().read($getSelection);
|
|
6
|
+
if (!$isRangeSelection(selection) || selection.isCollapsed()) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const translationBlocks = editor
|
|
10
|
+
.getEditorState()
|
|
11
|
+
.read(() => $extractTranslationBlocksFromSelection(editor, selection));
|
|
12
|
+
const { sourceLanguage, targetLanguage } = options;
|
|
13
|
+
const translateAPI = options.translateAPI || defaultTranslateAPI;
|
|
14
|
+
if (translationBlocks && translationBlocks.length > 0) {
|
|
15
|
+
const sourceTexts = translationBlocks.reduce((acc, cur) => ({ ...acc, [cur.key]: cur.text }), {});
|
|
16
|
+
const targetTexts = {};
|
|
17
|
+
await translateAPI({ texts: sourceTexts, sourceLanguage, targetLanguage }, ({ data, progress }) => {
|
|
18
|
+
targetTexts[data.key] = data.text;
|
|
19
|
+
if (options.onProgress && progress) {
|
|
20
|
+
options.onProgress(progress);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const translations = translationBlocks.map((item, index) => ({
|
|
24
|
+
...item,
|
|
25
|
+
text: targetTexts[index] || sourceTexts[index],
|
|
26
|
+
}));
|
|
27
|
+
return {
|
|
28
|
+
translations,
|
|
29
|
+
preview: () => {
|
|
30
|
+
return editor.getEditorState().read(() => $preview(translations));
|
|
31
|
+
},
|
|
32
|
+
replace: () => {
|
|
33
|
+
editor.update(() => {
|
|
34
|
+
$replaceTranslations(editor, translations);
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
insertBelow: () => {
|
|
38
|
+
editor.update(() => {
|
|
39
|
+
$insertTranslations(translations, selection);
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { $extractTranslationBlocks, $preview, $replaceTranslations, defaultTranslateAPI } from './utils';
|
|
2
|
+
export const translateFullContent = async (editor, options) => {
|
|
3
|
+
const { sourceLanguage, targetLanguage, signal } = options;
|
|
4
|
+
const translateAPI = options.translateAPI || defaultTranslateAPI;
|
|
5
|
+
let translationBlocks = [];
|
|
6
|
+
editor.update(() => {
|
|
7
|
+
translationBlocks = $extractTranslationBlocks(editor);
|
|
8
|
+
}, { discrete: true });
|
|
9
|
+
// eslint-disable-next-line no-console
|
|
10
|
+
console.log('translationBlocks: ', translationBlocks);
|
|
11
|
+
if (translationBlocks) {
|
|
12
|
+
const sourceTexts = translationBlocks.reduce((acc, cur) => ({ ...acc, [cur.key]: cur.text }), {});
|
|
13
|
+
const targetTexts = {};
|
|
14
|
+
const errorsMap = {};
|
|
15
|
+
await translateAPI({ texts: sourceTexts, sourceLanguage, targetLanguage }, ({ data, progress, error }) => {
|
|
16
|
+
const sourceText = sourceTexts[data.key];
|
|
17
|
+
if (error) {
|
|
18
|
+
targetTexts[data.key] = sourceText;
|
|
19
|
+
errorsMap[data.key] = error;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
targetTexts[data.key] = data.text;
|
|
23
|
+
}
|
|
24
|
+
if (options.onProgress && progress) {
|
|
25
|
+
options.onProgress(progress);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const translations = translationBlocks
|
|
29
|
+
.map((item) => {
|
|
30
|
+
const targetText = targetTexts[item.key];
|
|
31
|
+
return {
|
|
32
|
+
...item,
|
|
33
|
+
// 注意判断类型, completions api 可能返回非字符串的格式, 如 `{ text: 'xxx' }`, 如果为非字符串则使用原来的文本(放弃替换)
|
|
34
|
+
text: typeof targetText === 'string' ? targetText : sourceTexts[item.key],
|
|
35
|
+
};
|
|
36
|
+
})
|
|
37
|
+
.filter((x) => !!x.text);
|
|
38
|
+
const errors = translationBlocks
|
|
39
|
+
.filter((x) => !!errorsMap[x.key])
|
|
40
|
+
.map((item) => ({ ...item, error: errorsMap[item.key] }));
|
|
41
|
+
// eslint-disable-next-line no-console
|
|
42
|
+
console.log('translations: ', translations);
|
|
43
|
+
// eslint-disable-next-line no-console
|
|
44
|
+
console.log('errors: ', errors);
|
|
45
|
+
// 默认自动替换
|
|
46
|
+
const autoReplace = options.autoReplace !== false;
|
|
47
|
+
if (autoReplace && !signal?.aborted) {
|
|
48
|
+
editor.update(() => {
|
|
49
|
+
$replaceTranslations(editor, translations);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
translations,
|
|
54
|
+
errors,
|
|
55
|
+
preview: () => {
|
|
56
|
+
return editor.getEditorState().read(() => $preview(translations));
|
|
57
|
+
},
|
|
58
|
+
replace: (e) => {
|
|
59
|
+
(e || editor).update(() => {
|
|
60
|
+
$replaceTranslations(editor, translations);
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
insertBelow: () => { },
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { LexicalEditor, LexicalNode } from 'lexical';
|
|
2
|
+
import { PointType } from 'lexical/LexicalSelection';
|
|
3
|
+
export interface TranslationBlock {
|
|
4
|
+
key: string;
|
|
5
|
+
text: string;
|
|
6
|
+
}
|
|
7
|
+
export interface TranslationBlockWithSelection extends TranslationBlock {
|
|
8
|
+
nodes: LexicalNode[];
|
|
9
|
+
point: PointType;
|
|
10
|
+
}
|
|
11
|
+
export interface NonTextNodeMatch {
|
|
12
|
+
key: string;
|
|
13
|
+
index: number;
|
|
14
|
+
length: number;
|
|
15
|
+
}
|
|
16
|
+
export interface TranslatePayload {
|
|
17
|
+
sourceLanguage?: string;
|
|
18
|
+
targetLanguage: string;
|
|
19
|
+
texts: {
|
|
20
|
+
[key: string]: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export type TranslateAPI = (payload: TranslatePayload, onData: ({ data, progress, error }: {
|
|
24
|
+
data: TranslationBlock;
|
|
25
|
+
progress?: number;
|
|
26
|
+
error?: string;
|
|
27
|
+
}) => void) => Promise<void>;
|
|
28
|
+
export interface TranslationOptions {
|
|
29
|
+
sourceLanguage?: string;
|
|
30
|
+
targetLanguage: string;
|
|
31
|
+
translateAPI?: TranslateAPI;
|
|
32
|
+
onProgress?: (progress: number) => void;
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
autoReplace?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface TranslateSelectionOperations {
|
|
37
|
+
preview: () => string;
|
|
38
|
+
replace: (editor?: LexicalEditor) => void;
|
|
39
|
+
insertBelow: () => void;
|
|
40
|
+
}
|
|
41
|
+
export interface TranslationError {
|
|
42
|
+
key: string;
|
|
43
|
+
text: string;
|
|
44
|
+
error: string;
|
|
45
|
+
}
|
|
46
|
+
export interface TranslationResult extends TranslateSelectionOperations {
|
|
47
|
+
translations: TranslationBlock[];
|
|
48
|
+
errors?: TranslationError[];
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ElementNode, LexicalNode, RangeSelection, LexicalEditor } from 'lexical';
|
|
2
|
+
import type { PointType } from 'lexical/LexicalSelection';
|
|
3
|
+
import type { TranslationBlock, NonTextNodeMatch, TranslateAPI, TranslationBlockWithSelection } from './types';
|
|
4
|
+
export declare const defaultTranslateAPI: TranslateAPI;
|
|
5
|
+
export declare function $copyNodeDeep<T extends LexicalNode>(node: T): T;
|
|
6
|
+
export declare const insertNodesAfter: (node: LexicalNode, nodesToInsert: LexicalNode[]) => void;
|
|
7
|
+
/**
|
|
8
|
+
* 遍历顶层结点,获取需要翻译的结点列表
|
|
9
|
+
* - HeadingNode
|
|
10
|
+
* - ParagraphNode
|
|
11
|
+
* - ListItemNode
|
|
12
|
+
* - QuoteNode
|
|
13
|
+
*/
|
|
14
|
+
export declare const $extractTranslationNodes: (topLevelNodes: ElementNode[]) => ElementNode[];
|
|
15
|
+
/**
|
|
16
|
+
* 以下 node 符合 translation node:
|
|
17
|
+
* - heading node
|
|
18
|
+
* - paragraph node
|
|
19
|
+
* - list item node
|
|
20
|
+
* - quote node
|
|
21
|
+
*/
|
|
22
|
+
export declare const $extractTextContentFromTranslationNode: (translationNode: ElementNode, selectedNodes?: LexicalNode[]) => string;
|
|
23
|
+
export declare const $extractTranslationBlocks: (editor: LexicalEditor, translationNodes?: ElementNode[]) => TranslationBlock[];
|
|
24
|
+
/**
|
|
25
|
+
* 处理带有 `###key###` 的文本, 将普通文本转成 TextNode, 将 `###key###` 替换成 key 对应的 Node
|
|
26
|
+
* @param {string} text - 如: "a ###1### b ###20### c"
|
|
27
|
+
* @param {NonTextNodeMatch[]} matches - 如: [{key: 1, index: 2, length: 7}, {key: 20, index: 12, length: 8}]
|
|
28
|
+
* @returns LexicalNode 数组, 如: [<text-node "a">, <node-key-1>, <text-node "b">, <node-key-20>, <text-node "c">, ]
|
|
29
|
+
*/
|
|
30
|
+
export declare const rearrangeNodes: (text: string, matches: NonTextNodeMatch[]) => LexicalNode[];
|
|
31
|
+
/**
|
|
32
|
+
* 处理带有 `###key###` 的文本 (对应一个 translation node 的文本), 解析文本中 `###key###` 的信息,
|
|
33
|
+
* 包括 Node Key, 在文本中的 index, 自身字符长度
|
|
34
|
+
* 比如: "a ###1### b ###20### c" => [{key: 1, index: 2, length: 7}, {key: 20, index: 12, length: 8}]
|
|
35
|
+
*/
|
|
36
|
+
export declare const matchNonTextNodes: (text: string) => NonTextNodeMatch[];
|
|
37
|
+
export declare const $replaceTranslation: (translationBlock: TranslationBlock, editor: LexicalEditor) => LexicalNode | ElementNode | null;
|
|
38
|
+
export declare const $replaceTranslations: (editor: LexicalEditor, translationBlocks: TranslationBlock[]) => (LexicalNode | ElementNode | null)[];
|
|
39
|
+
export declare const $insertTranslations: (translationBlocks: TranslationBlock[], selection: RangeSelection) => void;
|
|
40
|
+
export declare const $preview: (translationBlocks: TranslationBlock[]) => string;
|
|
41
|
+
/**
|
|
42
|
+
* TODO: 剥除未选中的部分
|
|
43
|
+
*/
|
|
44
|
+
export declare const $extractTranslationBlockWithSelection: (translationNode: ElementNode, point: PointType, backward?: boolean) => TranslationBlockWithSelection | null;
|
|
45
|
+
export declare const getTopLevelNodesFromSelection: (selection: RangeSelection) => ElementNode[];
|
|
46
|
+
export declare const $extractTranslationBlocksFromSelection: (editor: LexicalEditor, selection: RangeSelection) => TranslationBlockWithSelection[];
|