@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,30 @@
|
|
|
1
|
+
import type { DOMConversionMap, DOMExportOutput, EditorConfig, ElementFormatType, LexicalEditor, LexicalNode, NodeKey, Spread } from 'lexical';
|
|
2
|
+
import { DecoratorBlockNode, SerializedDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode';
|
|
3
|
+
import type { JSX } from 'react';
|
|
4
|
+
export interface Embed {
|
|
5
|
+
title: string;
|
|
6
|
+
url: string;
|
|
7
|
+
originalUrl: string;
|
|
8
|
+
}
|
|
9
|
+
export type SerializedBlockletEmbedNode = Spread<{
|
|
10
|
+
embed: Embed;
|
|
11
|
+
type: 'blocklet-embed';
|
|
12
|
+
version: 1;
|
|
13
|
+
}, SerializedDecoratorBlockNode>;
|
|
14
|
+
export declare class BlockletEmbedNode extends DecoratorBlockNode {
|
|
15
|
+
__embed: Embed;
|
|
16
|
+
static getType(): string;
|
|
17
|
+
static clone(node: BlockletEmbedNode): BlockletEmbedNode;
|
|
18
|
+
static importJSON(serializedNode: SerializedBlockletEmbedNode): BlockletEmbedNode;
|
|
19
|
+
exportJSON(): SerializedBlockletEmbedNode;
|
|
20
|
+
constructor(__embed: Embed, format?: ElementFormatType, key?: NodeKey);
|
|
21
|
+
exportDOM(): DOMExportOutput;
|
|
22
|
+
static importDOM(): DOMConversionMap | null;
|
|
23
|
+
updateDOM(): false;
|
|
24
|
+
getId(): string;
|
|
25
|
+
getTextContent(_includeInert?: boolean | undefined, _includeDirectionless?: false | undefined): string;
|
|
26
|
+
decorate(_editor: LexicalEditor, config: EditorConfig): JSX.Element;
|
|
27
|
+
isInline(): false;
|
|
28
|
+
}
|
|
29
|
+
export declare function $createBlockletEmbedNode(embed: Embed): BlockletEmbedNode;
|
|
30
|
+
export declare function $isBlockletEmbedNode(node: BlockletEmbedNode | LexicalNode | null | undefined): node is BlockletEmbedNode;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { BlockWithAlignableContents } from '@lexical/react/LexicalBlockWithAlignableContents';
|
|
3
|
+
import { DecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode';
|
|
4
|
+
import BlockletEmbed from './BlockletEmbed';
|
|
5
|
+
function BlockletEmbedComponent({ className, format, nodeKey, embed }) {
|
|
6
|
+
return (_jsx(BlockWithAlignableContents, { className: className, format: format, nodeKey: nodeKey, children: _jsx(BlockletEmbed, { url: embed.url, title: embed.title, originalUrl: embed.originalUrl }) }));
|
|
7
|
+
}
|
|
8
|
+
function convertBlockletEmbedElement(domNode) {
|
|
9
|
+
const embedStr = domNode.getAttribute('data-lexical-blocklet-embed');
|
|
10
|
+
try {
|
|
11
|
+
const parsed = JSON.parse(embedStr);
|
|
12
|
+
if (parsed) {
|
|
13
|
+
const node = $createBlockletEmbedNode(parsed);
|
|
14
|
+
return { node };
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
console.warn(`Failed to parse: ${embedStr}`, e);
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
export class BlockletEmbedNode extends DecoratorBlockNode {
|
|
23
|
+
__embed;
|
|
24
|
+
static getType() {
|
|
25
|
+
return 'blocklet-embed';
|
|
26
|
+
}
|
|
27
|
+
static clone(node) {
|
|
28
|
+
return new BlockletEmbedNode({ ...node.__embed }, node.__format, node.__key);
|
|
29
|
+
}
|
|
30
|
+
static importJSON(serializedNode) {
|
|
31
|
+
const node = $createBlockletEmbedNode(serializedNode.embed);
|
|
32
|
+
node.setFormat(serializedNode.format);
|
|
33
|
+
return node;
|
|
34
|
+
}
|
|
35
|
+
exportJSON() {
|
|
36
|
+
return {
|
|
37
|
+
...super.exportJSON(),
|
|
38
|
+
type: 'blocklet-embed',
|
|
39
|
+
version: 1,
|
|
40
|
+
embed: this.__embed,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
constructor(__embed, format, key) {
|
|
44
|
+
super(format, key);
|
|
45
|
+
this.__embed = __embed;
|
|
46
|
+
}
|
|
47
|
+
exportDOM() {
|
|
48
|
+
const element = document.createElement('iframe');
|
|
49
|
+
element.setAttribute('data-lexical-blocklet-embed', JSON.stringify(this.__embed));
|
|
50
|
+
element.setAttribute('width', '100%');
|
|
51
|
+
// element.setAttribute('height', '315');
|
|
52
|
+
element.setAttribute('frameborder', '0');
|
|
53
|
+
element.setAttribute('src', this.__embed.url);
|
|
54
|
+
element.setAttribute('title', this.__embed.title);
|
|
55
|
+
return { element };
|
|
56
|
+
}
|
|
57
|
+
static importDOM() {
|
|
58
|
+
return {
|
|
59
|
+
iframe: (domNode) => {
|
|
60
|
+
if (!domNode.hasAttribute('data-lexical-blocklet-embed')) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
conversion: convertBlockletEmbedElement,
|
|
65
|
+
priority: 1,
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
updateDOM() {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
getId() {
|
|
74
|
+
return this.__embed.url;
|
|
75
|
+
}
|
|
76
|
+
getTextContent(_includeInert, _includeDirectionless) {
|
|
77
|
+
return this.__embed.url;
|
|
78
|
+
}
|
|
79
|
+
decorate(_editor, config) {
|
|
80
|
+
const embedBlockTheme = config.theme.embedBlock || {};
|
|
81
|
+
const className = {
|
|
82
|
+
base: embedBlockTheme.base || '',
|
|
83
|
+
focus: embedBlockTheme.focus || '',
|
|
84
|
+
};
|
|
85
|
+
return (_jsx(BlockletEmbedComponent, { className: className, format: this.__format, nodeKey: this.getKey(), embed: this.__embed }));
|
|
86
|
+
}
|
|
87
|
+
isInline() {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export function $createBlockletEmbedNode(embed) {
|
|
92
|
+
return new BlockletEmbedNode(embed);
|
|
93
|
+
}
|
|
94
|
+
export function $isBlockletEmbedNode(node) {
|
|
95
|
+
return node instanceof BlockletEmbedNode;
|
|
96
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LexicalCommand } from 'lexical';
|
|
2
|
+
import { type JSX } from 'react';
|
|
3
|
+
import type { LexicalEditor } from 'lexical';
|
|
4
|
+
import { AutoEmbedOption } from '@lexical/react/LexicalAutoEmbedPlugin';
|
|
5
|
+
import { Embed } from './BlockletEmbedNode';
|
|
6
|
+
import { EditorConfig } from '../../config';
|
|
7
|
+
export declare const INSERT_BLOCKLET_EMBED_COMMAND: LexicalCommand<Embed>;
|
|
8
|
+
/**
|
|
9
|
+
* 创建 "Embed Blocklet Embed" AutoEmbedOption
|
|
10
|
+
*/
|
|
11
|
+
export declare const createBlockletEmbedOption: (editor: LexicalEditor, editorConfig: EditorConfig) => AutoEmbedOption | null;
|
|
12
|
+
export default function BlockletEmbedPlugin(): JSX.Element | null;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
2
|
+
import { $insertNodeToNearestRoot } from '@lexical/utils';
|
|
3
|
+
import { COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
|
|
4
|
+
import { useEffect } from 'react';
|
|
5
|
+
import { AutoEmbedOption } from '@lexical/react/LexicalAutoEmbedPlugin';
|
|
6
|
+
import pick from 'lodash/pick';
|
|
7
|
+
import { joinURL } from 'ufo';
|
|
8
|
+
import { $createBlockletEmbedNode, BlockletEmbedNode } from './BlockletEmbedNode';
|
|
9
|
+
import { $getLinkNode } from '../utils';
|
|
10
|
+
export const INSERT_BLOCKLET_EMBED_COMMAND = createCommand('INSERT_BLOCKLET_EMBED_COMMAND');
|
|
11
|
+
const parseBlockletEmbedUrl = async (blockletEmbedEndpoint, url) => {
|
|
12
|
+
const urlObj = new URL(blockletEmbedEndpoint);
|
|
13
|
+
urlObj.searchParams.set('url', url);
|
|
14
|
+
const response = await fetch(urlObj.href);
|
|
15
|
+
const data = await response.json();
|
|
16
|
+
const embed = data?.embed?.[0];
|
|
17
|
+
if (embed) {
|
|
18
|
+
const embedUrl = joinURL(data.origin, embed.url);
|
|
19
|
+
return {
|
|
20
|
+
id: url,
|
|
21
|
+
url: embedUrl,
|
|
22
|
+
title: embed.title,
|
|
23
|
+
originalUrl: url,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const embedCache = {};
|
|
28
|
+
/**
|
|
29
|
+
* 创建 "Embed Blocklet Embed" AutoEmbedOption
|
|
30
|
+
*/
|
|
31
|
+
export const createBlockletEmbedOption = (editor, editorConfig) => {
|
|
32
|
+
const linkNode = $getLinkNode(editor);
|
|
33
|
+
const url = linkNode?.__url;
|
|
34
|
+
if (editorConfig.blockletEmbedEndpoint && url) {
|
|
35
|
+
// 粘贴一个 link 到 editor 中, 弹出 embed menu 后 createBlockletEmbedOption 可能会被再次执行 (比如光标 focus 状态变化导致 AutoEmbedPlugin 内部的 re-render)
|
|
36
|
+
// embedCache 此时有额外的作用: 记住 option#disabled 状态以避免 loading 效果再次出现
|
|
37
|
+
let embed = embedCache[url];
|
|
38
|
+
const option = new AutoEmbedOption('Embed Blocklet Embed', {
|
|
39
|
+
onSelect: () => {
|
|
40
|
+
if (embed) {
|
|
41
|
+
editor.dispatchCommand(INSERT_BLOCKLET_EMBED_COMMAND, pick(embed, 'title', 'url', 'originalUrl'));
|
|
42
|
+
linkNode?.remove();
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
option.disabled = !embed;
|
|
48
|
+
if (!embed) {
|
|
49
|
+
parseBlockletEmbedUrl(editorConfig.blockletEmbedEndpoint, url).then((result) => {
|
|
50
|
+
if (result) {
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
option.disabled = false;
|
|
53
|
+
option.ref?.current?.classList.remove('embed-option-disabled');
|
|
54
|
+
embedCache[url] = result;
|
|
55
|
+
embed = result;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return option;
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
};
|
|
63
|
+
export default function BlockletEmbedPlugin() {
|
|
64
|
+
const [editor] = useLexicalComposerContext();
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (!editor.hasNodes([BlockletEmbedNode])) {
|
|
67
|
+
throw new Error('BlockletEmbedPlugin: BlockletEmbedNode not registered on editor');
|
|
68
|
+
}
|
|
69
|
+
return editor.registerCommand(INSERT_BLOCKLET_EMBED_COMMAND, (payload) => {
|
|
70
|
+
const blockletEmbedNode = $createBlockletEmbedNode(payload);
|
|
71
|
+
$insertNodeToNearestRoot(blockletEmbedNode);
|
|
72
|
+
return true;
|
|
73
|
+
}, COMMAND_PRIORITY_EDITOR);
|
|
74
|
+
}, [editor]);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const BlurTextPlugin: () => null;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { mergeRegister } from '@lexical/utils';
|
|
4
|
+
import { TextNode } from 'lexical';
|
|
5
|
+
const BLUR_TEXT_PLUGIN_FLAG = '@BLUR_TEXT_PLUGIN@';
|
|
6
|
+
const removeNodeBlurTextFlag = (node) => {
|
|
7
|
+
node?.setTextContent(node.getTextContent().replaceAll(BLUR_TEXT_PLUGIN_FLAG, ''));
|
|
8
|
+
node?.setStyle('filter: blur(4px) opacity(0.25); transition: all 0.2s ease-in-out;');
|
|
9
|
+
};
|
|
10
|
+
export const BlurTextPlugin = () => {
|
|
11
|
+
const [editor] = useLexicalComposerContext();
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
return mergeRegister(editor.registerNodeTransform(TextNode, (node) => {
|
|
14
|
+
if (node.isSimpleText()) {
|
|
15
|
+
const text = node.getTextContent();
|
|
16
|
+
const hasBlurTextFlag = (text.match(/@BLUR_TEXT_PLUGIN@/g) || [])?.length > 0;
|
|
17
|
+
try {
|
|
18
|
+
if (hasBlurTextFlag) {
|
|
19
|
+
const index = text.indexOf(BLUR_TEXT_PLUGIN_FLAG);
|
|
20
|
+
const lastIndex = text.lastIndexOf(BLUR_TEXT_PLUGIN_FLAG) + BLUR_TEXT_PLUGIN_FLAG.length;
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
const [startNode, blurNode, endNode] = node.splitText(index, lastIndex);
|
|
23
|
+
if (!blurNode) {
|
|
24
|
+
removeNodeBlurTextFlag(startNode);
|
|
25
|
+
removeNodeBlurTextFlag(endNode);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
removeNodeBlurTextFlag(blurNode);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
// ignore error
|
|
34
|
+
console.error('Blur Text Plugin error: ', error);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
}, []);
|
|
39
|
+
return null;
|
|
40
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { JSX } from 'react';
|
|
2
|
+
import type { BookmarkInfo } from './BookmarkNode';
|
|
3
|
+
export declare function Bookmark({ url, title, description, image, favicon, loading }: BookmarkInfo): JSX.Element;
|
|
4
|
+
export declare function BookmarkLoader({ url, onLoaded }: {
|
|
5
|
+
url: string;
|
|
6
|
+
onLoaded: (info: BookmarkInfo) => void;
|
|
7
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Icon } from '@iconify/react';
|
|
3
|
+
import { Box, CircularProgress, styled } from '@mui/material';
|
|
4
|
+
import { useRequest } from 'ahooks';
|
|
5
|
+
import { useEditorConfig } from '../../config';
|
|
6
|
+
import { fetchOpenGraphInfo } from '../utils';
|
|
7
|
+
const isGithubRepo = (url) => {
|
|
8
|
+
const reg = /^https?:\/\/github.com\//;
|
|
9
|
+
return reg.test(url);
|
|
10
|
+
};
|
|
11
|
+
const getHost = (url) => {
|
|
12
|
+
try {
|
|
13
|
+
return new URL(url).host;
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
return url;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export function Bookmark({ url, title, description, image, favicon, loading }) {
|
|
20
|
+
// title 显示:
|
|
21
|
+
// - 有 title 值则直接显示
|
|
22
|
+
// - loading 状态显示 "Fetching preview"
|
|
23
|
+
// - 非 loading 状态显示 url 的 host
|
|
24
|
+
const renderTitle = () => {
|
|
25
|
+
const previewTitle = title || (loading ? 'Fetching preview' : getHost(url));
|
|
26
|
+
return (_jsxs(Box, { className: "be-bookmark-title be-bookmark-ellipsis", sx: { display: 'flex', alignItems: 'center', gap: 1 }, children: [loading && _jsx(CircularProgress, { size: 14, sx: { color: 'grey.400' } }), _jsx(Box, { component: "span", sx: { color: loading ? 'grey.700' : 'inherit' }, children: previewTitle })] }));
|
|
27
|
+
};
|
|
28
|
+
if (isGithubRepo(url)) {
|
|
29
|
+
return (_jsxs(Root, { href: url, target: "_blank", className: "github-bookmark", children: [image && (_jsxs("div", { className: "be-github-image", children: [_jsx(Image, { src: image }), _jsx(Icon, { icon: "mdi:github", style: { fontSize: 18 }, className: "be-github-image-icon" })] })), _jsxs("div", { className: "be-bookmark-texts", children: [renderTitle(), description && _jsx("div", { className: "be-bookmark-description be-bookmark-clamp2", children: description }), loading && (_jsx(Box, { className: "be-bookmark-url-content", sx: { pt: 1 }, children: _jsx("div", { className: "be-bookmark-url be-bookmark-ellipsis", children: url }) }))] })] }));
|
|
30
|
+
}
|
|
31
|
+
return (_jsxs(Root, { href: url, target: "_blank", children: [_jsxs("div", { className: "be-bookmark-texts", children: [renderTitle(), _jsx("div", { className: "be-bookmark-description be-bookmark-clamp2", children: description }), _jsxs("div", { className: "be-bookmark-url-content", children: [favicon && _jsx("img", { src: favicon, alt: "favicon", className: "be-bookmark-favicon" }), _jsx("div", { className: "be-bookmark-url be-bookmark-ellipsis", children: url })] })] }), image && _jsx("div", { className: "be-bookmark-image", style: { backgroundImage: `url(${image})` } })] }));
|
|
32
|
+
}
|
|
33
|
+
const Root = styled('a') `
|
|
34
|
+
box-sizing: border-box;
|
|
35
|
+
display: inline-flex;
|
|
36
|
+
width: 100%;
|
|
37
|
+
margin: 8px 0;
|
|
38
|
+
border: 1px solid;
|
|
39
|
+
border-color: ${({ theme }) => theme.palette.divider};
|
|
40
|
+
overflow: hidden;
|
|
41
|
+
color: inherit;
|
|
42
|
+
border-radius: 4px;
|
|
43
|
+
text-decoration: none;
|
|
44
|
+
cursor: pointer;
|
|
45
|
+
|
|
46
|
+
:hover {
|
|
47
|
+
background: ${({ theme }) => theme.palette.grey[50]};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.be-bookmark-texts {
|
|
51
|
+
display: flex;
|
|
52
|
+
flex-direction: column;
|
|
53
|
+
min-width: 0;
|
|
54
|
+
padding: 16px;
|
|
55
|
+
font-size: 14px;
|
|
56
|
+
.be-bookmark-title {
|
|
57
|
+
}
|
|
58
|
+
.be-bookmark-description {
|
|
59
|
+
margin: 4px 0;
|
|
60
|
+
line-height: 1.2;
|
|
61
|
+
font-size: 12px;
|
|
62
|
+
color: ${({ theme }) => theme.palette.text.secondary};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.be-bookmark-url-content {
|
|
66
|
+
display: flex;
|
|
67
|
+
align-items: center;
|
|
68
|
+
margin-top: auto;
|
|
69
|
+
|
|
70
|
+
.be-bookmark-url {
|
|
71
|
+
font-size: 12px;
|
|
72
|
+
color: ${({ theme }) => theme.palette.text.secondary};
|
|
73
|
+
line-height: 1;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.be-bookmark-favicon {
|
|
77
|
+
width: 18px;
|
|
78
|
+
height: 18px;
|
|
79
|
+
border-radius: 100%;
|
|
80
|
+
margin-right: 8px;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.be-bookmark-image {
|
|
86
|
+
flex: 0 0 auto;
|
|
87
|
+
margin-left: auto;
|
|
88
|
+
// The recommended size for an Open Graph (OG) image is 1200 x 630 pixels with an aspect ratio of 1.91:1
|
|
89
|
+
width: 300px;
|
|
90
|
+
height: 158px;
|
|
91
|
+
background-size: cover;
|
|
92
|
+
background-position: center center;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@media (max-width: 768px) {
|
|
96
|
+
.be-bookmark-image {
|
|
97
|
+
width: 200px;
|
|
98
|
+
height: 105px;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@media (max-width: 500px) {
|
|
103
|
+
.be-bookmark-image {
|
|
104
|
+
display: none;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.be-bookmark-ellipsis {
|
|
109
|
+
overflow: hidden;
|
|
110
|
+
text-overflow: ellipsis;
|
|
111
|
+
white-space: nowrap;
|
|
112
|
+
}
|
|
113
|
+
.be-bookmark-clamp2 {
|
|
114
|
+
overflow: hidden;
|
|
115
|
+
text-overflow: ellipsis;
|
|
116
|
+
word-break: break-all;
|
|
117
|
+
display: -webkit-box;
|
|
118
|
+
-webkit-line-clamp: 2;
|
|
119
|
+
-webkit-box-orient: vertical;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
&.github-bookmark {
|
|
123
|
+
display: flex;
|
|
124
|
+
align-items: center;
|
|
125
|
+
padding: 16px;
|
|
126
|
+
border-radius: 4px;
|
|
127
|
+
|
|
128
|
+
.be-github-image-icon {
|
|
129
|
+
position: absolute;
|
|
130
|
+
bottom: 0;
|
|
131
|
+
right: 0;
|
|
132
|
+
background: ${({ theme }) => theme.palette.background.paper};
|
|
133
|
+
border-radius: 100%;
|
|
134
|
+
z-index: 1;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.be-github-image {
|
|
138
|
+
width: 40px;
|
|
139
|
+
min-height: 40px;
|
|
140
|
+
max-height: 40px;
|
|
141
|
+
position: relative;
|
|
142
|
+
border-radius: 100%;
|
|
143
|
+
margin-right: 12px;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.be-bookmark-texts {
|
|
147
|
+
padding: 0;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
`;
|
|
151
|
+
const Image = styled('img') `
|
|
152
|
+
width: 100%;
|
|
153
|
+
height: 100%;
|
|
154
|
+
border-radius: 100%;
|
|
155
|
+
position: absolute;
|
|
156
|
+
top: 0;
|
|
157
|
+
right: 0;
|
|
158
|
+
bottom: 0;
|
|
159
|
+
left: 0;
|
|
160
|
+
object-fit: cover;
|
|
161
|
+
`;
|
|
162
|
+
export function BookmarkLoader({ url, onLoaded }) {
|
|
163
|
+
const { openGraphEndpoint } = useEditorConfig();
|
|
164
|
+
const { data, loading } = useRequest(async () => {
|
|
165
|
+
if (!openGraphEndpoint) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
const openGraphInfo = await fetchOpenGraphInfo(openGraphEndpoint, url);
|
|
169
|
+
if (openGraphInfo) {
|
|
170
|
+
onLoaded(openGraphInfo);
|
|
171
|
+
}
|
|
172
|
+
return openGraphInfo;
|
|
173
|
+
});
|
|
174
|
+
return _jsx(Bookmark, { url: url, title: "", loading: loading || !data, ...data });
|
|
175
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { DOMConversionMap, DOMExportOutput, EditorConfig, ElementFormatType, LexicalEditor, LexicalNode, NodeKey, Spread } from 'lexical';
|
|
2
|
+
import { DecoratorBlockNode, SerializedDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode';
|
|
3
|
+
import type { JSX } from 'react';
|
|
4
|
+
export interface BookmarkInfo {
|
|
5
|
+
url: string;
|
|
6
|
+
title: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
image?: string;
|
|
9
|
+
favicon?: string;
|
|
10
|
+
loading?: boolean;
|
|
11
|
+
selfLoad?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export type SerializedBookmarkNode = Spread<{
|
|
14
|
+
bookmark: BookmarkInfo;
|
|
15
|
+
type: 'bookmark';
|
|
16
|
+
version: 1;
|
|
17
|
+
}, SerializedDecoratorBlockNode>;
|
|
18
|
+
export declare class BookmarkNode extends DecoratorBlockNode {
|
|
19
|
+
__bookmark: BookmarkInfo;
|
|
20
|
+
static getType(): string;
|
|
21
|
+
static clone(node: BookmarkNode): BookmarkNode;
|
|
22
|
+
static importJSON(serializedNode: SerializedBookmarkNode): BookmarkNode;
|
|
23
|
+
exportJSON(): SerializedBookmarkNode;
|
|
24
|
+
constructor(__bookmark: BookmarkInfo, format?: ElementFormatType, key?: NodeKey);
|
|
25
|
+
exportDOM(): DOMExportOutput;
|
|
26
|
+
static importDOM(): DOMConversionMap | null;
|
|
27
|
+
updateDOM(): false;
|
|
28
|
+
getId(): string;
|
|
29
|
+
getTextContent(_includeInert?: boolean | undefined, _includeDirectionless?: false | undefined): string;
|
|
30
|
+
setBookmark(bookmark: BookmarkInfo): void;
|
|
31
|
+
decorate(editor: LexicalEditor, config: EditorConfig): JSX.Element;
|
|
32
|
+
isInline(): false;
|
|
33
|
+
}
|
|
34
|
+
export declare function $createBookmarkNode(bookmark: BookmarkInfo | string): BookmarkNode;
|
|
35
|
+
export declare function $isBookmarkNode(node: BookmarkNode | LexicalNode | null | undefined): node is BookmarkNode;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { BlockWithAlignableContents } from '@lexical/react/LexicalBlockWithAlignableContents';
|
|
3
|
+
import { DecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode';
|
|
4
|
+
import { Bookmark, BookmarkLoader } from './Bookmark';
|
|
5
|
+
function BookmarkComponent({ className, format, nodeKey, bookmark, onLoaded }) {
|
|
6
|
+
if (bookmark.selfLoad) {
|
|
7
|
+
return (_jsx(BlockWithAlignableContents, { className: className, format: format, nodeKey: nodeKey, children: _jsx(BookmarkLoader, { url: bookmark.url, onLoaded: onLoaded }) }));
|
|
8
|
+
}
|
|
9
|
+
return (_jsx(BlockWithAlignableContents, { className: className, format: format, nodeKey: nodeKey, children: _jsx(Bookmark, { url: bookmark.url, title: bookmark.title, description: bookmark.description, image: bookmark.image, favicon: bookmark.favicon, loading: bookmark.loading }) }));
|
|
10
|
+
}
|
|
11
|
+
function convertBookmarkElement(domNode) {
|
|
12
|
+
const bookmarkStr = domNode.getAttribute('data-lexical-bookmark');
|
|
13
|
+
try {
|
|
14
|
+
const parsed = JSON.parse(bookmarkStr);
|
|
15
|
+
if (parsed) {
|
|
16
|
+
const node = $createBookmarkNode(parsed);
|
|
17
|
+
return { node };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
console.warn(`Failed to parse: ${bookmarkStr}`, e);
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
export class BookmarkNode extends DecoratorBlockNode {
|
|
26
|
+
__bookmark;
|
|
27
|
+
static getType() {
|
|
28
|
+
return 'bookmark';
|
|
29
|
+
}
|
|
30
|
+
static clone(node) {
|
|
31
|
+
return new BookmarkNode({ ...node.__bookmark }, node.__format, node.__key);
|
|
32
|
+
}
|
|
33
|
+
static importJSON(serializedNode) {
|
|
34
|
+
const node = $createBookmarkNode(serializedNode.bookmark);
|
|
35
|
+
node.setFormat(serializedNode.format);
|
|
36
|
+
return node;
|
|
37
|
+
}
|
|
38
|
+
exportJSON() {
|
|
39
|
+
return {
|
|
40
|
+
...super.exportJSON(),
|
|
41
|
+
type: 'bookmark',
|
|
42
|
+
version: 1,
|
|
43
|
+
bookmark: this.__bookmark,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
constructor(__bookmark, format, key) {
|
|
47
|
+
super(format, key);
|
|
48
|
+
this.__bookmark = __bookmark;
|
|
49
|
+
}
|
|
50
|
+
exportDOM() {
|
|
51
|
+
const element = document.createElement('iframe');
|
|
52
|
+
element.setAttribute('data-lexical-bookmark', JSON.stringify(this.__bookmark));
|
|
53
|
+
element.setAttribute('width', '100%');
|
|
54
|
+
// element.setAttribute('height', '315');
|
|
55
|
+
element.setAttribute('frameborder', '0');
|
|
56
|
+
element.setAttribute('src', this.__bookmark.url);
|
|
57
|
+
element.setAttribute('title', this.__bookmark.title);
|
|
58
|
+
return { element };
|
|
59
|
+
}
|
|
60
|
+
static importDOM() {
|
|
61
|
+
return {
|
|
62
|
+
iframe: (domNode) => {
|
|
63
|
+
if (!domNode.hasAttribute('data-lexical-bookmark')) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
conversion: convertBookmarkElement,
|
|
68
|
+
priority: 1,
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
updateDOM() {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
getId() {
|
|
77
|
+
return this.__bookmark.url;
|
|
78
|
+
}
|
|
79
|
+
getTextContent(_includeInert, _includeDirectionless) {
|
|
80
|
+
return this.__bookmark.url;
|
|
81
|
+
}
|
|
82
|
+
setBookmark(bookmark) {
|
|
83
|
+
const writable = this.getWritable();
|
|
84
|
+
writable.__bookmark = bookmark;
|
|
85
|
+
}
|
|
86
|
+
decorate(editor, config) {
|
|
87
|
+
const embedBlockTheme = config.theme.embedBlock || {};
|
|
88
|
+
const className = {
|
|
89
|
+
base: embedBlockTheme.base || '',
|
|
90
|
+
focus: embedBlockTheme.focus || '',
|
|
91
|
+
};
|
|
92
|
+
return (_jsx(BookmarkComponent, { className: className, format: this.__format, nodeKey: this.getKey(), bookmark: this.__bookmark, onLoaded: (bookmark) => {
|
|
93
|
+
editor.update(() => {
|
|
94
|
+
this.setBookmark({ ...bookmark, url: this.__bookmark.url, selfLoad: false });
|
|
95
|
+
});
|
|
96
|
+
} }));
|
|
97
|
+
}
|
|
98
|
+
isInline() {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export function $createBookmarkNode(bookmark) {
|
|
103
|
+
if (typeof bookmark === 'string') {
|
|
104
|
+
return new BookmarkNode({ url: bookmark, title: '', loading: true, selfLoad: true });
|
|
105
|
+
}
|
|
106
|
+
return new BookmarkNode(bookmark);
|
|
107
|
+
}
|
|
108
|
+
export function $isBookmarkNode(node) {
|
|
109
|
+
return node instanceof BookmarkNode;
|
|
110
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LexicalCommand, LexicalEditor } from 'lexical';
|
|
2
|
+
import { type JSX } from 'react';
|
|
3
|
+
import { AutoEmbedOption } from '@lexical/react/LexicalAutoEmbedPlugin';
|
|
4
|
+
import { BookmarkInfo } from './BookmarkNode';
|
|
5
|
+
import { EditorConfig } from '../../config';
|
|
6
|
+
export declare const INSERT_BOOKMARK_COMMAND: LexicalCommand<BookmarkInfo>;
|
|
7
|
+
/**
|
|
8
|
+
* 创建 "Create bookmark" AutoEmbedOption
|
|
9
|
+
*/
|
|
10
|
+
export declare const createBookmarkOption: (editor: LexicalEditor, editorConfig: EditorConfig) => AutoEmbedOption | null;
|
|
11
|
+
export default function BookmarkPlugin(): JSX.Element | null;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
2
|
+
import { $insertNodeToNearestRoot } from '@lexical/utils';
|
|
3
|
+
import { COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
|
|
4
|
+
import { useEffect } from 'react';
|
|
5
|
+
import { AutoEmbedOption } from '@lexical/react/LexicalAutoEmbedPlugin';
|
|
6
|
+
import { $createBookmarkNode, BookmarkNode } from './BookmarkNode';
|
|
7
|
+
import { $getLinkNode, fetchOpenGraphInfo } from '../utils';
|
|
8
|
+
export const INSERT_BOOKMARK_COMMAND = createCommand('INSERT_BOOKMARK_COMMAND');
|
|
9
|
+
/**
|
|
10
|
+
* 创建 "Create bookmark" AutoEmbedOption
|
|
11
|
+
*/
|
|
12
|
+
export const createBookmarkOption = (editor, editorConfig) => {
|
|
13
|
+
const linkNode = $getLinkNode(editor);
|
|
14
|
+
const url = linkNode?.__url;
|
|
15
|
+
if (editorConfig.openGraphEndpoint && url) {
|
|
16
|
+
return new AutoEmbedOption('Create bookmark', {
|
|
17
|
+
onSelect: async () => {
|
|
18
|
+
const bookmarkNode = $createBookmarkNode({ loading: true, title: '', url });
|
|
19
|
+
$insertNodeToNearestRoot(bookmarkNode);
|
|
20
|
+
editor.update(() => {
|
|
21
|
+
linkNode.remove();
|
|
22
|
+
});
|
|
23
|
+
const openGraphInfo = await fetchOpenGraphInfo(editorConfig.openGraphEndpoint, url);
|
|
24
|
+
editor.update(() => {
|
|
25
|
+
bookmarkNode.replace($createBookmarkNode({ ...openGraphInfo, title: openGraphInfo?.title || '', url }));
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
};
|
|
32
|
+
export default function BookmarkPlugin() {
|
|
33
|
+
const [editor] = useLexicalComposerContext();
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!editor.hasNodes([BookmarkNode])) {
|
|
36
|
+
throw new Error('BookmarkPlugin: BookmarkNode not registered on editor');
|
|
37
|
+
}
|
|
38
|
+
return editor.registerCommand(INSERT_BOOKMARK_COMMAND, (payload) => {
|
|
39
|
+
const bookmarkNode = $createBookmarkNode(payload);
|
|
40
|
+
$insertNodeToNearestRoot(bookmarkNode);
|
|
41
|
+
return true;
|
|
42
|
+
}, COMMAND_PRIORITY_EDITOR);
|
|
43
|
+
}, [editor]);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { LexicalCommand } from 'lexical';
|
|
2
|
+
interface Payload {
|
|
3
|
+
busy: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare const UPDATE_BUSY_COMMAND: LexicalCommand<Payload>;
|
|
6
|
+
export declare function BusyPlugin({ onChange }: {
|
|
7
|
+
onChange: (busy: boolean) => void;
|
|
8
|
+
}): null;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
|
|
4
|
+
import { mergeRegister } from '@lexical/utils';
|
|
5
|
+
export const UPDATE_BUSY_COMMAND = createCommand('UPDATE_BUSY_COMMAND');
|
|
6
|
+
export function BusyPlugin({ onChange }) {
|
|
7
|
+
const [editor] = useLexicalComposerContext();
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
if (editor.isEditable()) {
|
|
10
|
+
return mergeRegister(editor.registerCommand(UPDATE_BUSY_COMMAND, (payload) => {
|
|
11
|
+
onChange(payload.busy);
|
|
12
|
+
return true;
|
|
13
|
+
}, COMMAND_PRIORITY_EDITOR));
|
|
14
|
+
}
|
|
15
|
+
}, [editor]);
|
|
16
|
+
return null;
|
|
17
|
+
}
|