@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,343 @@
|
|
|
1
|
+
import { $isParagraphNode, $createTextNode, $getNodeByKey, $isElementNode, $copyNode, } from 'lexical';
|
|
2
|
+
import { $isHeadingNode, $isQuoteNode } from '@lexical/rich-text';
|
|
3
|
+
import { $isListNode, $isListItemNode } from '@lexical/list';
|
|
4
|
+
import { $dfs, $findMatchingParent } from '@lexical/utils';
|
|
5
|
+
import { fetchEventSource } from '@microsoft/fetch-event-source';
|
|
6
|
+
import { joinURL } from 'ufo';
|
|
7
|
+
import { getCSRFToken } from '@blocklet/js-sdk';
|
|
8
|
+
import { blockletExists, getBlockletMountPointInfo, isValidUrl } from '../utils';
|
|
9
|
+
import { $getDepth } from '../../lexical-utils';
|
|
10
|
+
import { $htmlToNodes, $nodeToHtml, $hasValidTextNode, $isValidTextNode } from '../translation/translation-utils';
|
|
11
|
+
const REGEX_INVALID_SEQUENCE = /^[#$%^&*()_+\-=\\[\]{};':"\\|,.<>/?]+$/;
|
|
12
|
+
export const defaultTranslateAPI = async ({ texts, sourceLanguage, targetLanguage }, onData) => {
|
|
13
|
+
if (!blockletExists('did-comments')) {
|
|
14
|
+
throw new Error('Discuss Kit component must be installed.');
|
|
15
|
+
}
|
|
16
|
+
if (!texts || !Object.keys(texts)?.length) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const total = Object.keys(texts).length;
|
|
20
|
+
let done = 0;
|
|
21
|
+
try {
|
|
22
|
+
await fetchEventSource(joinURL(getBlockletMountPointInfo('did-comments').mountPoint, '/api/ai/translate'), {
|
|
23
|
+
method: 'POST',
|
|
24
|
+
headers: { 'Content-Type': 'application/json', 'x-csrf-token': getCSRFToken() },
|
|
25
|
+
body: JSON.stringify({ texts, sourceLanguage, targetLanguage }),
|
|
26
|
+
// @see: https://github.com/Azure/fetch-event-source/issues/36
|
|
27
|
+
openWhenHidden: true,
|
|
28
|
+
onmessage: (ev) => {
|
|
29
|
+
const { error, ...parsed } = JSON.parse(ev.data);
|
|
30
|
+
const data = {
|
|
31
|
+
data: parsed,
|
|
32
|
+
progress: Number((++done / total).toFixed(2)) * 100,
|
|
33
|
+
error,
|
|
34
|
+
};
|
|
35
|
+
// eslint-disable-next-line no-console
|
|
36
|
+
console.log('onmessage: ', ev, data);
|
|
37
|
+
onData(data);
|
|
38
|
+
},
|
|
39
|
+
onerror(e) {
|
|
40
|
+
console.error('fetchEventSource#onerror', e);
|
|
41
|
+
throw e;
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
console.error(e);
|
|
47
|
+
throw e;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
// @see: https://github.com/facebook/lexical/pull/4230
|
|
51
|
+
export function $copyNodeDeep(node) {
|
|
52
|
+
const nodeCopy = $copyNode(node);
|
|
53
|
+
const stack = [[node, nodeCopy]];
|
|
54
|
+
let stackLength;
|
|
55
|
+
// eslint-disable-next-line no-cond-assign
|
|
56
|
+
while ((stackLength = stack.length) > 0) {
|
|
57
|
+
for (let i = 0; i < stackLength; i++) {
|
|
58
|
+
const tuple = stack.shift();
|
|
59
|
+
if (tuple !== undefined) {
|
|
60
|
+
const [currentNode, currentNodeCopy] = tuple;
|
|
61
|
+
if ($isElementNode(currentNode) && $isElementNode(currentNodeCopy)) {
|
|
62
|
+
const children = currentNode.getChildren();
|
|
63
|
+
for (const child of children) {
|
|
64
|
+
const childCopy = $copyNode(child);
|
|
65
|
+
currentNodeCopy.append(childCopy);
|
|
66
|
+
stack.push([child, childCopy]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return nodeCopy;
|
|
73
|
+
}
|
|
74
|
+
export const insertNodesAfter = (node, nodesToInsert) => {
|
|
75
|
+
let currentNode = node;
|
|
76
|
+
nodesToInsert.forEach((item) => {
|
|
77
|
+
currentNode.insertAfter(item);
|
|
78
|
+
currentNode = item;
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* 遍历顶层结点,获取需要翻译的结点列表
|
|
83
|
+
* - HeadingNode
|
|
84
|
+
* - ParagraphNode
|
|
85
|
+
* - ListItemNode
|
|
86
|
+
* - QuoteNode
|
|
87
|
+
*/
|
|
88
|
+
export const $extractTranslationNodes = (topLevelNodes) => {
|
|
89
|
+
const results = [];
|
|
90
|
+
topLevelNodes.forEach((node) => {
|
|
91
|
+
if ($isHeadingNode(node) || $isParagraphNode(node) || $isQuoteNode(node) || $isListItemNode(node)) {
|
|
92
|
+
results.push(node);
|
|
93
|
+
}
|
|
94
|
+
else if ($isListNode(node)) {
|
|
95
|
+
const listItemNodes = node.getChildren().filter((child) => $isListItemNode(child));
|
|
96
|
+
results.push(...listItemNodes);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
return results.filter($hasValidTextNode);
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* 以下 node 符合 translation node:
|
|
103
|
+
* - heading node
|
|
104
|
+
* - paragraph node
|
|
105
|
+
* - list item node
|
|
106
|
+
* - quote node
|
|
107
|
+
*/
|
|
108
|
+
export const $extractTextContentFromTranslationNode = (translationNode, selectedNodes) => {
|
|
109
|
+
const selectedNodeKeys = new Set(selectedNodes?.map((item) => item.getKey()));
|
|
110
|
+
const isValidTextNode = (node) => $isValidTextNode(node) && (selectedNodes ? selectedNodeKeys.has(node.getKey()) : true);
|
|
111
|
+
const children = translationNode.getChildren();
|
|
112
|
+
const hasText = children.some((item) => $isValidTextNode(item) && !!item.getTextContent().trim());
|
|
113
|
+
if (!hasText) {
|
|
114
|
+
return '';
|
|
115
|
+
}
|
|
116
|
+
let text = '';
|
|
117
|
+
children.forEach((item) => {
|
|
118
|
+
if (isValidTextNode(item)) {
|
|
119
|
+
// 内容 trim 后若为空则忽略该 node
|
|
120
|
+
if (item.getTextContent().trim()) {
|
|
121
|
+
text += item.getTextContent();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
// 非 TextNode, 作为 ###<key>### 拼接到文本中
|
|
126
|
+
text += ` ###${item.getKey()}### `;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
return text;
|
|
130
|
+
};
|
|
131
|
+
// translation nodes => translation blocks (若未传入 nodes, 默认为 editor 内所有的顶层结点)
|
|
132
|
+
export const $extractTranslationBlocks = (editor, translationNodes) => {
|
|
133
|
+
const _translationNodes = translationNodes ||
|
|
134
|
+
$extractTranslationNodes($dfs()
|
|
135
|
+
.map((x) => x.node)
|
|
136
|
+
.filter((x) => $isElementNode(x)));
|
|
137
|
+
return _translationNodes
|
|
138
|
+
.map((node) => {
|
|
139
|
+
const text = $nodeToHtml(editor, node);
|
|
140
|
+
return { key: node.getKey(), text };
|
|
141
|
+
})
|
|
142
|
+
.filter((item) => {
|
|
143
|
+
const trim = item.text?.trim();
|
|
144
|
+
// 如果为空或 url, 则不翻译
|
|
145
|
+
if (!trim || isValidUrl(trim) || REGEX_INVALID_SEQUENCE.test(trim)) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
return true;
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* 处理带有 `###key###` 的文本, 将普通文本转成 TextNode, 将 `###key###` 替换成 key 对应的 Node
|
|
153
|
+
* @param {string} text - 如: "a ###1### b ###20### c"
|
|
154
|
+
* @param {NonTextNodeMatch[]} matches - 如: [{key: 1, index: 2, length: 7}, {key: 20, index: 12, length: 8}]
|
|
155
|
+
* @returns LexicalNode 数组, 如: [<text-node "a">, <node-key-1>, <text-node "b">, <node-key-20>, <text-node "c">, ]
|
|
156
|
+
*/
|
|
157
|
+
export const rearrangeNodes = (text, matches) => {
|
|
158
|
+
let cursor = 0;
|
|
159
|
+
const nodes = matches.reduce((acc, cur) => {
|
|
160
|
+
const { key, index, length } = cur;
|
|
161
|
+
const textBeforeNode = text.substring(cursor, index);
|
|
162
|
+
const node = $getNodeByKey(key);
|
|
163
|
+
if (textBeforeNode) {
|
|
164
|
+
acc.push($createTextNode(textBeforeNode));
|
|
165
|
+
}
|
|
166
|
+
if (node) {
|
|
167
|
+
acc.push(node);
|
|
168
|
+
}
|
|
169
|
+
cursor = index + length;
|
|
170
|
+
return acc;
|
|
171
|
+
}, []);
|
|
172
|
+
const lastText = text.substring(cursor);
|
|
173
|
+
if (lastText) {
|
|
174
|
+
nodes.push($createTextNode(lastText));
|
|
175
|
+
}
|
|
176
|
+
return nodes;
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* 处理带有 `###key###` 的文本 (对应一个 translation node 的文本), 解析文本中 `###key###` 的信息,
|
|
180
|
+
* 包括 Node Key, 在文本中的 index, 自身字符长度
|
|
181
|
+
* 比如: "a ###1### b ###20### c" => [{key: 1, index: 2, length: 7}, {key: 20, index: 12, length: 8}]
|
|
182
|
+
*/
|
|
183
|
+
export const matchNonTextNodes = (text) => {
|
|
184
|
+
const re = /###\d+###/g;
|
|
185
|
+
const matches = [];
|
|
186
|
+
let match = re.exec(text);
|
|
187
|
+
while (match) {
|
|
188
|
+
matches.push({ key: match[0].slice(3, -3), index: match.index, length: match[0].length });
|
|
189
|
+
match = re.exec(text);
|
|
190
|
+
}
|
|
191
|
+
return matches;
|
|
192
|
+
};
|
|
193
|
+
export const $replaceTranslation = (translationBlock, editor) => {
|
|
194
|
+
try {
|
|
195
|
+
const { text, key } = translationBlock;
|
|
196
|
+
const blockNode = $getNodeByKey(key);
|
|
197
|
+
if ($isElementNode(blockNode)) {
|
|
198
|
+
// 清除所有 children
|
|
199
|
+
blockNode.getChildren().forEach((child) => child.remove());
|
|
200
|
+
const nodes = $htmlToNodes(editor, text);
|
|
201
|
+
if (nodes.length === 1) {
|
|
202
|
+
const node = nodes[0];
|
|
203
|
+
if ($isElementNode(node)) {
|
|
204
|
+
blockNode.append(...node.getChildren());
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
blockNode.append(node);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
blockNode.append(...nodes);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return blockNode;
|
|
215
|
+
}
|
|
216
|
+
catch (e) {
|
|
217
|
+
console.error(e);
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
export const $replaceTranslations = (editor, translationBlocks) => {
|
|
222
|
+
return translationBlocks.map((item) => $replaceTranslation(item, editor));
|
|
223
|
+
};
|
|
224
|
+
export const $insertTranslations = (translationBlocks, selection) => {
|
|
225
|
+
const nodes = translationBlocks
|
|
226
|
+
.map((translationBlock) => {
|
|
227
|
+
const { text, key } = translationBlock;
|
|
228
|
+
const matches = matchNonTextNodes(text);
|
|
229
|
+
const newNodes = rearrangeNodes(text, matches);
|
|
230
|
+
const blockNode = $getNodeByKey(key);
|
|
231
|
+
if ($isElementNode(blockNode)) {
|
|
232
|
+
const copied = $copyNode(blockNode);
|
|
233
|
+
const clonedNodes = newNodes.map((node) => $copyNodeDeep(node));
|
|
234
|
+
copied.append(...clonedNodes);
|
|
235
|
+
return copied;
|
|
236
|
+
}
|
|
237
|
+
return null;
|
|
238
|
+
})
|
|
239
|
+
.filter((item) => !!item);
|
|
240
|
+
const insertPoint = selection.isBackward() ? selection.anchor : selection.focus;
|
|
241
|
+
const topLevelNodeOfInsertPoint = insertPoint.getNode().getTopLevelElement();
|
|
242
|
+
if (topLevelNodeOfInsertPoint) {
|
|
243
|
+
insertNodesAfter(topLevelNodeOfInsertPoint, nodes);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
export const $preview = (translationBlocks) => {
|
|
247
|
+
const result = translationBlocks.map((item) => {
|
|
248
|
+
const { text = '', key } = item;
|
|
249
|
+
const replaced = text
|
|
250
|
+
.replace(/###(\d+)###/g, (match, p1) => {
|
|
251
|
+
const node = $getNodeByKey(p1);
|
|
252
|
+
return node?.getTextContent() || '';
|
|
253
|
+
})
|
|
254
|
+
.trim();
|
|
255
|
+
const translationNode = $getNodeByKey(key);
|
|
256
|
+
if ($isHeadingNode(translationNode)) {
|
|
257
|
+
const tags = { h1: '#', h2: '##', h3: '###', h4: '####', h5: '#####', h6: '######' };
|
|
258
|
+
return `${tags[translationNode.getTag()]} ${replaced}`;
|
|
259
|
+
}
|
|
260
|
+
if ($isListItemNode(translationNode)) {
|
|
261
|
+
return `- ${replaced}`;
|
|
262
|
+
}
|
|
263
|
+
if ($isQuoteNode(translationNode)) {
|
|
264
|
+
return `> ${replaced}`;
|
|
265
|
+
}
|
|
266
|
+
return replaced;
|
|
267
|
+
});
|
|
268
|
+
return result.join('\n');
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* TODO: 剥除未选中的部分
|
|
272
|
+
*/
|
|
273
|
+
export const $extractTranslationBlockWithSelection = (translationNode, point, backward) => {
|
|
274
|
+
const pointNode = point.getNode();
|
|
275
|
+
// anchor/focus 可能对应着更深层的结点, 比如选中 link, anchor/focus 对应的是其内部的 text node
|
|
276
|
+
const thirdLevelParentNodeOfPointNode = $findMatchingParent(pointNode, (_node) => $getDepth(_node) === 2);
|
|
277
|
+
const subNodes = translationNode.getChildren();
|
|
278
|
+
const pointNodeIndex = subNodes.findIndex((item) => {
|
|
279
|
+
return item.getKey() === pointNode.getKey() || item.getKey() === thirdLevelParentNodeOfPointNode?.getKey();
|
|
280
|
+
});
|
|
281
|
+
let selectedNodes = [];
|
|
282
|
+
if (backward) {
|
|
283
|
+
selectedNodes = new Array(pointNodeIndex + 1).fill(null).map((_, index) => subNodes[index]);
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
selectedNodes = new Array(subNodes.length - pointNodeIndex)
|
|
287
|
+
.fill(null)
|
|
288
|
+
.map((_, index) => subNodes[pointNodeIndex + index]);
|
|
289
|
+
}
|
|
290
|
+
selectedNodes = selectedNodes.filter(Boolean);
|
|
291
|
+
const text = $extractTextContentFromTranslationNode(translationNode, selectedNodes);
|
|
292
|
+
if (!text.trim()) {
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
key: translationNode.getKey(),
|
|
297
|
+
text,
|
|
298
|
+
nodes: selectedNodes,
|
|
299
|
+
point,
|
|
300
|
+
// remainingText: ['', xxx],
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
export const getTopLevelNodesFromSelection = (selection) => {
|
|
304
|
+
const keys = new Set();
|
|
305
|
+
const topLevelNodes = [];
|
|
306
|
+
selection.getNodes().forEach((node) => {
|
|
307
|
+
const topLevelElement = node.getTopLevelElement();
|
|
308
|
+
if ($isElementNode(topLevelElement) && !keys.has(topLevelElement.getKey())) {
|
|
309
|
+
topLevelNodes.push(topLevelElement);
|
|
310
|
+
keys.add(topLevelElement.getKey());
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
return topLevelNodes;
|
|
314
|
+
};
|
|
315
|
+
// TODO: 选中非首个 list item 进行翻译时, firstTranslationNode 为首个 list item
|
|
316
|
+
// TODO: topLevelNode 内的简单选择, 比如只选择了一个段落或 list item 中的一个词语
|
|
317
|
+
export const $extractTranslationBlocksFromSelection = (editor, selection) => {
|
|
318
|
+
const topLevelNodes = getTopLevelNodesFromSelection(selection);
|
|
319
|
+
const translationNodes = $extractTranslationNodes(topLevelNodes);
|
|
320
|
+
const startPoint = selection.isBackward() ? selection.focus : selection.anchor;
|
|
321
|
+
const endPoint = selection.isBackward() ? selection.anchor : selection.focus;
|
|
322
|
+
// console.log('$extractTranslationBlocksFromSelection:', {
|
|
323
|
+
// topLevelNodes,
|
|
324
|
+
// translationNodes,
|
|
325
|
+
// anchor: startPoint,
|
|
326
|
+
// focus: endPoint,
|
|
327
|
+
// });
|
|
328
|
+
if (translationNodes.length === 0) {
|
|
329
|
+
return [];
|
|
330
|
+
}
|
|
331
|
+
const firstNode = translationNodes[0];
|
|
332
|
+
const firstTranslationBlock = $extractTranslationBlockWithSelection(firstNode, startPoint);
|
|
333
|
+
if (translationNodes.length === 1) {
|
|
334
|
+
return [firstTranslationBlock].filter((item) => !!item?.text);
|
|
335
|
+
}
|
|
336
|
+
// nodes length > 1
|
|
337
|
+
const lastNode = translationNodes[translationNodes.length - 1];
|
|
338
|
+
const lastTranslationBlock = $extractTranslationBlockWithSelection(lastNode, endPoint, true);
|
|
339
|
+
// 去掉首尾 node
|
|
340
|
+
const blocks = $extractTranslationBlocks(editor, translationNodes.slice(1, -1));
|
|
341
|
+
// console.log({ firstTranslationBlock, blocks, lastTranslationBlock });
|
|
342
|
+
return [firstTranslationBlock, ...blocks, lastTranslationBlock].filter((item) => !!item?.text);
|
|
343
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, ClickAwayListener } from '@mui/material';
|
|
3
|
+
import { useAideContext } from './context';
|
|
4
|
+
import Input from './Input';
|
|
5
|
+
import Output from './Output';
|
|
6
|
+
import Templates from './Templates';
|
|
7
|
+
import Menu from './Menu';
|
|
8
|
+
import ExternalTemplates from './external-templates';
|
|
9
|
+
import { useSafeArea } from '../SafeAreaPlugin';
|
|
10
|
+
export function Aide(props) {
|
|
11
|
+
const { status, mode, reset, available } = useAideContext();
|
|
12
|
+
const handleClickAway = (e) => {
|
|
13
|
+
reset();
|
|
14
|
+
};
|
|
15
|
+
useSafeArea({ enabled: available && status !== 'initial', size: '360px' });
|
|
16
|
+
if (!available || status === 'initial') {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
if (mode === 'templates') {
|
|
20
|
+
return _jsx(ExternalTemplates, {});
|
|
21
|
+
}
|
|
22
|
+
return (_jsx(ClickAwayListener, { onClickAway: handleClickAway, children: _jsxs(Box, { sx: {
|
|
23
|
+
display: 'flex',
|
|
24
|
+
flexDirection: 'column',
|
|
25
|
+
height: 320,
|
|
26
|
+
fontSize: 14,
|
|
27
|
+
pointerEvents: 'none',
|
|
28
|
+
zIndex: 1201,
|
|
29
|
+
}, ...props, children: [(status === 'activated' || status === 'waiting') && _jsx(Input, {}), _jsx(Templates, {}), status === 'completed' && (_jsxs(Box, { children: [_jsx(Output, {}), _jsx(Menu, {})] }))] }) }));
|
|
30
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface Props {
|
|
3
|
+
children: React.ReactElement<any>;
|
|
4
|
+
delay: number;
|
|
5
|
+
}
|
|
6
|
+
export default function Delayed({ children, delay }: Props): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | null;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
// delayed rendering
|
|
3
|
+
export default function Delayed({ children, delay }) {
|
|
4
|
+
const [show, setShow] = useState(false);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
const timer = setTimeout(() => {
|
|
7
|
+
setShow(true);
|
|
8
|
+
}, delay);
|
|
9
|
+
return () => clearTimeout(timer);
|
|
10
|
+
}, [delay]);
|
|
11
|
+
return show ? children : null;
|
|
12
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Button } from '@mui/material';
|
|
3
|
+
import { useAideContext } from './context';
|
|
4
|
+
import { Card } from '../common';
|
|
5
|
+
import AnimateText from '../../components/animateText';
|
|
6
|
+
export default function Input({ prepend, ...rest }) {
|
|
7
|
+
const { status, input, activeBuiltinTemplate, setInput, sendToAI, stop } = useAideContext();
|
|
8
|
+
const submit = () => {
|
|
9
|
+
if (activeBuiltinTemplate || input) {
|
|
10
|
+
sendToAI(activeBuiltinTemplate || input);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const handleOnKeyDown = (event) => {
|
|
14
|
+
if (event.key === 'Enter') {
|
|
15
|
+
submit();
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
return (_jsxs(Card, { sx: {
|
|
20
|
+
display: 'flex',
|
|
21
|
+
alignItems: 'center',
|
|
22
|
+
flex: '0 0 auto',
|
|
23
|
+
width: 480,
|
|
24
|
+
height: 36,
|
|
25
|
+
lineHeight: 36,
|
|
26
|
+
overflow: 'hidden',
|
|
27
|
+
}, ...rest, children: [_jsx(Box, { sx: {
|
|
28
|
+
display: 'flex',
|
|
29
|
+
justifyContent: 'center',
|
|
30
|
+
alighItems: 'center',
|
|
31
|
+
width: 36,
|
|
32
|
+
}, children: _jsx(Box, { component: "i", className: "iconify", "data-icon": "bi:stars", "data-height": "16px", sx: { color: 'grey.600' } }) }), prepend, status === 'activated' && (_jsxs(_Fragment, { children: [_jsx(Box, { component: "input", type: "text", value: input, onChange: (e) => setInput(e.target.value), onKeyDown: handleOnKeyDown, ref: (ref) => {
|
|
33
|
+
ref?.focus({ preventScroll: true });
|
|
34
|
+
}, sx: {
|
|
35
|
+
flex: '1 1 auto',
|
|
36
|
+
height: '100%',
|
|
37
|
+
border: 0,
|
|
38
|
+
outline: 'none',
|
|
39
|
+
bgcolor: 'transparent',
|
|
40
|
+
color: 'text.primary',
|
|
41
|
+
} }), _jsx(Box, { onClick: submit, sx: {
|
|
42
|
+
display: 'flex',
|
|
43
|
+
justifyContent: 'center',
|
|
44
|
+
alighItems: 'center',
|
|
45
|
+
width: 36,
|
|
46
|
+
color: input ? 'grey.500' : 'grey.400',
|
|
47
|
+
cursor: input ? 'pointer' : 'initial',
|
|
48
|
+
}, children: _jsx(Box, { component: "i", className: "iconify", "data-icon": "material-symbols:arrow-circle-up-rounded", "data-height": "20px" }) })] })), status === 'waiting' && (_jsxs(_Fragment, { children: [_jsx(Box, { sx: { flex: '1 1 auto', fontWeight: 'bold' }, children: _jsx(AnimateText, { sentence: "AI is writing ..." }) }), _jsx(Button, { onClick: () => stop(), size: "small", sx: { mr: 1, fontSize: 12, color: 'grey.400', '.MuiButton-startIcon': { mr: 0.5 } }, startIcon: _jsx(Box, { component: "i", className: "iconify", "data-icon": "material-symbols:stop-circle-rounded", "data-height": "18px" }), children: "Stop" })] }))] }));
|
|
49
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, MenuList, MenuItem, ListItemText, ListItemIcon, Typography } from '@mui/material';
|
|
3
|
+
import { useAideContext } from './context';
|
|
4
|
+
import { Card, MenuWrapper } from '../common';
|
|
5
|
+
export default function Menu({ ...rest }) {
|
|
6
|
+
const { reset, retry, output, selection, replaceSelection, insertBelow, copy } = useAideContext();
|
|
7
|
+
const handleDiscard = () => {
|
|
8
|
+
reset();
|
|
9
|
+
};
|
|
10
|
+
const handleReplace = () => {
|
|
11
|
+
replaceSelection?.(selection, output);
|
|
12
|
+
reset();
|
|
13
|
+
};
|
|
14
|
+
const handleInsert = () => {
|
|
15
|
+
insertBelow?.(selection, output);
|
|
16
|
+
reset();
|
|
17
|
+
};
|
|
18
|
+
const handleCopy = () => {
|
|
19
|
+
copy?.(output);
|
|
20
|
+
reset({}, false, true);
|
|
21
|
+
};
|
|
22
|
+
const canReplace = selection && replaceSelection;
|
|
23
|
+
const canInsertBelow = selection && insertBelow;
|
|
24
|
+
return (_jsx(Card, { component: MenuWrapper, sx: {
|
|
25
|
+
flex: '1 1 auto',
|
|
26
|
+
width: 280,
|
|
27
|
+
my: 0.5,
|
|
28
|
+
}, ...rest, children: _jsxs(MenuList, { children: [canReplace && (_jsxs(MenuItem, { onClick: () => handleReplace(), sx: { '&:hover .aide-templates-item': { display: 'inline-block' } }, children: [_jsx(ListItemIcon, { children: _jsx(Box, { component: "i", className: "iconify", "data-icon": "ic:baseline-check", "data-height": "16px" }) }), _jsx(ListItemText, { children: _jsx(Typography, { variant: "inherit", noWrap: true, children: "Replace selection" }) }), _jsx(Box, { component: "i", className: "iconify aide-templates-item", "data-icon": "fluent:arrow-enter-24-regular", "data-height": "14px", sx: { display: 'none', color: 'grey.500' } })] })), canInsertBelow && (_jsxs(MenuItem, { onClick: () => handleInsert(), sx: { '&:hover .aide-templates-item': { display: 'inline-block' } }, children: [_jsx(ListItemIcon, { children: _jsx(Box, { component: "i", className: "iconify", "data-icon": "lucide:list-end", "data-height": "16px" }) }), _jsx(ListItemText, { children: _jsx(Typography, { variant: "inherit", noWrap: true, children: "Insert below" }) }), _jsx(Box, { component: "i", className: "iconify aide-templates-item", "data-icon": "fluent:arrow-enter-24-regular", "data-height": "14px", sx: { display: 'none', color: 'grey.500' } })] })), _jsxs(MenuItem, { onClick: () => retry(), sx: { '&:hover .aide-templates-item': { display: 'inline-block' } }, children: [_jsx(ListItemIcon, { children: _jsx(Box, { component: "i", className: "iconify", "data-icon": "iconoir:redo", "data-height": "16px" }) }), _jsx(ListItemText, { children: _jsx(Typography, { variant: "inherit", noWrap: true, children: "Try again" }) }), _jsx(Box, { component: "i", className: "iconify aide-templates-item", "data-icon": "fluent:arrow-enter-24-regular", "data-height": "14px", sx: { display: 'none', color: 'grey.500' } })] }), _jsxs(MenuItem, { onClick: handleDiscard, sx: { '&:hover .aide-templates-item': { display: 'inline-block' } }, children: [_jsx(ListItemIcon, { children: _jsx(Box, { component: "i", className: "iconify", "data-icon": "ph:trash", "data-height": "16px" }) }), _jsx(ListItemText, { children: _jsx(Typography, { variant: "inherit", noWrap: true, children: "Discard" }) }), _jsx(Box, { component: "i", className: "iconify aide-templates-item", "data-icon": "fluent:arrow-enter-24-regular", "data-height": "14px", sx: { display: 'none', color: 'grey.500' } })] }), _jsxs(MenuItem, { onClick: handleCopy, sx: { '&:hover .aide-templates-item': { display: 'inline-block' } }, children: [_jsx(ListItemIcon, { children: _jsx(Box, { component: "i", className: "iconify", "data-icon": "ph:copy", "data-height": "16px" }) }), _jsx(ListItemText, { children: _jsx(Typography, { variant: "inherit", noWrap: true, children: "Copy" }) }), _jsx(Box, { component: "i", className: "iconify aide-templates-item", "data-icon": "fluent:arrow-enter-24-regular", "data-height": "14px", sx: { display: 'none', color: 'grey.500' } })] })] }) }));
|
|
29
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import Box from '@mui/material/Box';
|
|
3
|
+
import { useAideContext } from './context';
|
|
4
|
+
import { Card } from '../common';
|
|
5
|
+
export default function Output({ ...rest }) {
|
|
6
|
+
const { output } = useAideContext();
|
|
7
|
+
return (_jsx(Card, { sx: {
|
|
8
|
+
width: 480,
|
|
9
|
+
maxHeight: 300,
|
|
10
|
+
my: 0.5,
|
|
11
|
+
p: 1.5,
|
|
12
|
+
overflowY: 'auto',
|
|
13
|
+
}, ...rest, children: _jsx(Box, { children: output }) }));
|
|
14
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, MenuList, MenuItem, ListItemText, ListItemIcon, Typography } from '@mui/material';
|
|
3
|
+
import { useAideContext } from './context';
|
|
4
|
+
import { Card, MenuWrapper, NestedMenuItem } from '../common';
|
|
5
|
+
function TemplateOptions({ template, onSelect }) {
|
|
6
|
+
return (_jsx(MenuList, { children: template.options.map((option) => {
|
|
7
|
+
return (_jsx(MenuItem, { onClick: () => onSelect(template, option), children: option }, option));
|
|
8
|
+
}) }));
|
|
9
|
+
}
|
|
10
|
+
export default function Templates({ ...rest }) {
|
|
11
|
+
const { status, sendToAI, filteredTemplates, selectionText, activeBuiltinTemplate } = useAideContext();
|
|
12
|
+
if (status !== 'activated' || filteredTemplates.length === 0) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const selectOption = (template, option) => {
|
|
16
|
+
const prompt = template.getPrompt(selectionText, option);
|
|
17
|
+
sendToAI(prompt);
|
|
18
|
+
};
|
|
19
|
+
return (_jsx(Card, { component: MenuWrapper, sx: {
|
|
20
|
+
flex: '0 1 auto',
|
|
21
|
+
width: 280,
|
|
22
|
+
my: 0.5,
|
|
23
|
+
overflowY: 'auto',
|
|
24
|
+
}, ...rest, children: _jsx(MenuList, { children: filteredTemplates.map((template) => {
|
|
25
|
+
if (template.hasOptions()) {
|
|
26
|
+
return (_jsxs(NestedMenuItem, { subMenu: _jsx(Card, { sx: { minWidth: 200, maxHeight: 240, overflowY: 'auto' }, children: _jsx(TemplateOptions, { template: template, onSelect: selectOption }) }), children: [_jsx(ListItemIcon, { children: _jsx(Box, { component: "i", className: "iconify", "data-icon": template.icon, "data-height": "16px" }) }), _jsx(ListItemText, { children: _jsx(Typography, { variant: "inherit", noWrap: true, sx: {
|
|
27
|
+
lineHeight: 1.2,
|
|
28
|
+
}, children: template.name }) })] }, template.id));
|
|
29
|
+
}
|
|
30
|
+
return (_jsxs(MenuItem, { onClick: () => sendToAI(template), selected: activeBuiltinTemplate?.id === template.id, sx: { '&:hover .aide-templates-item': { display: 'inline-block' } }, children: [_jsx(ListItemIcon, { children: _jsx(Box, { component: "i", className: "iconify", "data-icon": template.icon, "data-height": "16px" }) }), _jsx(ListItemText, { children: _jsx(Typography, { variant: "inherit", noWrap: true, sx: {
|
|
31
|
+
lineHeight: 1.2,
|
|
32
|
+
}, children: template.name }) }), _jsx(Box, { component: "i", className: "iconify aide-templates-item", "data-icon": "fluent:arrow-enter-24-regular", "data-height": "14px", sx: { display: 'none', color: 'grey.500' } })] }, template.id));
|
|
33
|
+
}) }) }));
|
|
34
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Template } from './types';
|
|
2
|
+
const data = [
|
|
3
|
+
{
|
|
4
|
+
id: 'content-improver',
|
|
5
|
+
name: 'Content Improver',
|
|
6
|
+
icon: 'mingcute:pencil-2-line',
|
|
7
|
+
data: 'I want you to act as a content improver. I will speak to you in any language and you will detect the language, answer in the corrected and improved version of my text. Keep the meaning same, but make them more literary. I want you to only reply the correction, the improvements and nothing else, do not write explanations. My first content is: {0}.',
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
id: 'translate',
|
|
11
|
+
name: 'Translate',
|
|
12
|
+
options: ['English', 'Chinese', 'Japanese', 'Korean'],
|
|
13
|
+
icon: 'material-symbols:g-translate',
|
|
14
|
+
data: 'Provide the {1} translation for these sentences, just return the translation, do not include any other text: {0}',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: 'make-shorter',
|
|
18
|
+
name: 'Make shorter',
|
|
19
|
+
icon: 'material-symbols:short-text',
|
|
20
|
+
data: 'Shorten this text: {0}',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: 'make-longer',
|
|
24
|
+
name: 'Make longer',
|
|
25
|
+
icon: 'mdi:text-long',
|
|
26
|
+
data: 'Expand the following sentences by providing more information or detail: {0}',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: 'summarize',
|
|
30
|
+
name: 'Summarize',
|
|
31
|
+
icon: 'tabler:blockquote',
|
|
32
|
+
data: 'Summarize the following text with the most unique and helpful points, into a numbered list of key points and takeaways: {0}',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: 'change-tone',
|
|
36
|
+
name: 'Change tone',
|
|
37
|
+
options: ['Professional', 'Casual', 'Straightforward', 'Confident', 'Friendly'],
|
|
38
|
+
icon: 'material-symbols:auto-detect-voice-outline-rounded',
|
|
39
|
+
data: 'Rewrite the following content in a {1} tone: {0}',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'continue-writing',
|
|
43
|
+
name: 'Continue writing',
|
|
44
|
+
icon: 'mingcute:pencil-2-line',
|
|
45
|
+
data: 'Generate subsequent content based on input, keeping it within two to three sentences and no more than 60 words. The input is: {0}',
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
export default data.map((item) => new Template(item.id, item.name, item.icon, item.data, item.options));
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import type { Completions, FetchTemplatesRequest, Mode, ParameterizedTemplate, ParameterizedTemplateCompletionsPayload, Status } from './types';
|
|
3
|
+
import { Template } from './types';
|
|
4
|
+
interface AideProviderProps {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
completions: Completions;
|
|
7
|
+
replaceSelection?: (selection: any, output: string) => void;
|
|
8
|
+
insertBelow?: (selection: any, output: string) => void;
|
|
9
|
+
copy?: (output: string) => void;
|
|
10
|
+
}
|
|
11
|
+
interface AideContextState {
|
|
12
|
+
status: Status;
|
|
13
|
+
mode: Mode;
|
|
14
|
+
templates: Template[];
|
|
15
|
+
externalTemplates: {
|
|
16
|
+
templates: ParameterizedTemplate[];
|
|
17
|
+
hasMore: boolean;
|
|
18
|
+
tags: string[];
|
|
19
|
+
tag?: string;
|
|
20
|
+
loading: boolean;
|
|
21
|
+
};
|
|
22
|
+
selection: any;
|
|
23
|
+
selectionText: string;
|
|
24
|
+
input: string;
|
|
25
|
+
output: string;
|
|
26
|
+
}
|
|
27
|
+
interface AideContextType extends AideContextState, Pick<AideProviderProps, 'replaceSelection' | 'insertBelow' | 'completions' | 'copy'> {
|
|
28
|
+
available: boolean;
|
|
29
|
+
filteredTemplates: Template[];
|
|
30
|
+
activeBuiltinTemplate?: Template;
|
|
31
|
+
activateAI: ({ mode, selectionText, selection, }: {
|
|
32
|
+
mode: Mode;
|
|
33
|
+
selectionText: string;
|
|
34
|
+
selection: any;
|
|
35
|
+
}) => Promise<void>;
|
|
36
|
+
setInput: (text: string) => void;
|
|
37
|
+
sendToAI: (payload: Template | ParameterizedTemplateCompletionsPayload | string) => void;
|
|
38
|
+
retry: () => void;
|
|
39
|
+
stop: () => void;
|
|
40
|
+
reset: (params?: Partial<AideContextState>, keepSelection?: boolean, isCopy?: boolean) => void;
|
|
41
|
+
loadMoreTemplates: (params?: FetchTemplatesRequest) => Promise<void>;
|
|
42
|
+
selectionText: string;
|
|
43
|
+
}
|
|
44
|
+
export declare const AideContext: import("react").Context<AideContextType>;
|
|
45
|
+
export declare const useAideContext: () => AideContextType;
|
|
46
|
+
export declare function AideProvider({ completions, replaceSelection, insertBelow, copy, children }: AideProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
47
|
+
export {};
|