@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,288 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
import './index.css';
|
|
10
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
11
|
+
import { eventFiles } from '@lexical/rich-text';
|
|
12
|
+
import { mergeRegister } from '@lexical/utils';
|
|
13
|
+
import { $getNearestNodeFromDOMNode, $getNodeByKey, $getRoot, COMMAND_PRIORITY_HIGH, COMMAND_PRIORITY_LOW, DRAGOVER_COMMAND, DROP_COMMAND, } from 'lexical';
|
|
14
|
+
import { useEffect, useRef, useState } from 'react';
|
|
15
|
+
import { createPortal } from 'react-dom';
|
|
16
|
+
import { isHTMLElement } from '../../utils/guard';
|
|
17
|
+
import { Point } from '../../utils/point';
|
|
18
|
+
import { Rect } from '../../utils/rect';
|
|
19
|
+
const SPACE = 4;
|
|
20
|
+
const TARGET_LINE_HALF_HEIGHT = 2;
|
|
21
|
+
const DRAGGABLE_BLOCK_MENU_CLASSNAME = 'draggable-block-menu';
|
|
22
|
+
const DRAG_DATA_FORMAT = 'application/x-lexical-drag-block';
|
|
23
|
+
const TEXT_BOX_HORIZONTAL_PADDING = 28;
|
|
24
|
+
const Downward = 1;
|
|
25
|
+
const Upward = -1;
|
|
26
|
+
const Indeterminate = 0;
|
|
27
|
+
let prevIndex = Infinity;
|
|
28
|
+
function getCurrentIndex(keysLength) {
|
|
29
|
+
if (keysLength === 0) {
|
|
30
|
+
return Infinity;
|
|
31
|
+
}
|
|
32
|
+
if (prevIndex >= 0 && prevIndex < keysLength) {
|
|
33
|
+
return prevIndex;
|
|
34
|
+
}
|
|
35
|
+
return Math.floor(keysLength / 2);
|
|
36
|
+
}
|
|
37
|
+
function getTopLevelNodeKeys(editor) {
|
|
38
|
+
return editor.getEditorState().read(() => $getRoot().getChildrenKeys());
|
|
39
|
+
}
|
|
40
|
+
function getCollapsedMargins(elem) {
|
|
41
|
+
const getMargin = (element, margin) => element ? parseFloat(window.getComputedStyle(element)[margin]) : 0;
|
|
42
|
+
const { marginTop, marginBottom } = window.getComputedStyle(elem);
|
|
43
|
+
const prevElemSiblingMarginBottom = getMargin(elem.previousElementSibling, 'marginBottom');
|
|
44
|
+
const nextElemSiblingMarginTop = getMargin(elem.nextElementSibling, 'marginTop');
|
|
45
|
+
const collapsedTopMargin = Math.max(parseFloat(marginTop), prevElemSiblingMarginBottom);
|
|
46
|
+
const collapsedBottomMargin = Math.max(parseFloat(marginBottom), nextElemSiblingMarginTop);
|
|
47
|
+
return { marginBottom: collapsedBottomMargin, marginTop: collapsedTopMargin };
|
|
48
|
+
}
|
|
49
|
+
function getBlockElement(anchorElem, editor, event, useEdgeAsDefault = false) {
|
|
50
|
+
const anchorElementRect = anchorElem.getBoundingClientRect();
|
|
51
|
+
const topLevelNodeKeys = getTopLevelNodeKeys(editor);
|
|
52
|
+
let blockElem = null;
|
|
53
|
+
editor.getEditorState().read(() => {
|
|
54
|
+
if (useEdgeAsDefault) {
|
|
55
|
+
const [firstNode, lastNode] = [
|
|
56
|
+
editor.getElementByKey(topLevelNodeKeys[0]),
|
|
57
|
+
editor.getElementByKey(topLevelNodeKeys[topLevelNodeKeys.length - 1]),
|
|
58
|
+
];
|
|
59
|
+
const [firstNodeRect, lastNodeRect] = [firstNode?.getBoundingClientRect(), lastNode?.getBoundingClientRect()];
|
|
60
|
+
if (firstNodeRect && lastNodeRect) {
|
|
61
|
+
if (event.y < firstNodeRect.top) {
|
|
62
|
+
blockElem = firstNode;
|
|
63
|
+
}
|
|
64
|
+
else if (event.y > lastNodeRect.bottom) {
|
|
65
|
+
blockElem = lastNode;
|
|
66
|
+
}
|
|
67
|
+
if (blockElem) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
let index = getCurrentIndex(topLevelNodeKeys.length);
|
|
73
|
+
let direction = Indeterminate;
|
|
74
|
+
while (index >= 0 && index < topLevelNodeKeys.length) {
|
|
75
|
+
const key = topLevelNodeKeys[index];
|
|
76
|
+
const elem = editor.getElementByKey(key);
|
|
77
|
+
if (elem === null) {
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
const point = new Point(event.x, event.y);
|
|
81
|
+
const domRect = Rect.fromDOM(elem);
|
|
82
|
+
const { marginTop, marginBottom } = getCollapsedMargins(elem);
|
|
83
|
+
const rect = domRect.generateNewRect({
|
|
84
|
+
bottom: domRect.bottom + marginBottom,
|
|
85
|
+
left: anchorElementRect.left,
|
|
86
|
+
right: anchorElementRect.right,
|
|
87
|
+
top: domRect.top - marginTop,
|
|
88
|
+
});
|
|
89
|
+
const { result, reason: { isOnTopSide, isOnBottomSide }, } = rect.contains(point);
|
|
90
|
+
if (result) {
|
|
91
|
+
blockElem = elem;
|
|
92
|
+
prevIndex = index;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
if (direction === Indeterminate) {
|
|
96
|
+
if (isOnTopSide) {
|
|
97
|
+
direction = Upward;
|
|
98
|
+
}
|
|
99
|
+
else if (isOnBottomSide) {
|
|
100
|
+
direction = Downward;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// stop search block element
|
|
104
|
+
direction = Infinity;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
index += direction;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
return blockElem;
|
|
111
|
+
}
|
|
112
|
+
function isOnMenu(element) {
|
|
113
|
+
return !!element.closest(`.${DRAGGABLE_BLOCK_MENU_CLASSNAME}`);
|
|
114
|
+
}
|
|
115
|
+
function setMenuPosition(targetElem, floatingElem, anchorElem) {
|
|
116
|
+
if (!targetElem) {
|
|
117
|
+
floatingElem.style.opacity = '0';
|
|
118
|
+
floatingElem.style.transform = 'translate(-10000px, -10000px)';
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const targetRect = targetElem.getBoundingClientRect();
|
|
122
|
+
const targetStyle = window.getComputedStyle(targetElem);
|
|
123
|
+
const floatingElemRect = floatingElem.getBoundingClientRect();
|
|
124
|
+
const anchorElementRect = anchorElem.getBoundingClientRect();
|
|
125
|
+
const top = targetRect.top + (parseInt(targetStyle.lineHeight, 10) - floatingElemRect.height) / 2 - anchorElementRect.top;
|
|
126
|
+
const left = SPACE;
|
|
127
|
+
floatingElem.style.opacity = '1';
|
|
128
|
+
floatingElem.style.transform = `translate(${left}px, ${top}px)`;
|
|
129
|
+
}
|
|
130
|
+
function setDragImage(dataTransfer, draggableBlockElem) {
|
|
131
|
+
const { transform } = draggableBlockElem.style;
|
|
132
|
+
// Remove dragImage borders
|
|
133
|
+
draggableBlockElem.style.transform = 'translateZ(0)';
|
|
134
|
+
dataTransfer.setDragImage(draggableBlockElem, 0, 0);
|
|
135
|
+
setTimeout(() => {
|
|
136
|
+
draggableBlockElem.style.transform = transform;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function setTargetLine(targetLineElem, targetBlockElem, mouseY, anchorElem) {
|
|
140
|
+
const { top: targetBlockElemTop, height: targetBlockElemHeight } = targetBlockElem.getBoundingClientRect();
|
|
141
|
+
const { top: anchorTop, width: anchorWidth } = anchorElem.getBoundingClientRect();
|
|
142
|
+
const { marginTop, marginBottom } = getCollapsedMargins(targetBlockElem);
|
|
143
|
+
let lineTop = targetBlockElemTop;
|
|
144
|
+
if (mouseY >= targetBlockElemTop) {
|
|
145
|
+
lineTop += targetBlockElemHeight + marginBottom / 2;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
lineTop -= marginTop / 2;
|
|
149
|
+
}
|
|
150
|
+
const top = lineTop - anchorTop - TARGET_LINE_HALF_HEIGHT;
|
|
151
|
+
const left = TEXT_BOX_HORIZONTAL_PADDING - SPACE;
|
|
152
|
+
targetLineElem.style.transform = `translate(${left}px, ${top}px)`;
|
|
153
|
+
targetLineElem.style.width = `${anchorWidth - (TEXT_BOX_HORIZONTAL_PADDING - SPACE) * 2}px`;
|
|
154
|
+
targetLineElem.style.opacity = '.4';
|
|
155
|
+
}
|
|
156
|
+
function hideTargetLine(targetLineElem) {
|
|
157
|
+
if (targetLineElem) {
|
|
158
|
+
targetLineElem.style.opacity = '0';
|
|
159
|
+
targetLineElem.style.transform = 'translate(-10000px, -10000px)';
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function useDraggableBlockMenu(editor, anchorElem, isEditable) {
|
|
163
|
+
const scrollerElem = anchorElem.parentElement;
|
|
164
|
+
const menuRef = useRef(null);
|
|
165
|
+
const targetLineRef = useRef(null);
|
|
166
|
+
const isDraggingBlockRef = useRef(false);
|
|
167
|
+
const [draggableBlockElem, setDraggableBlockElem] = useState(null);
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
function onMouseMove(event) {
|
|
170
|
+
const { target } = event;
|
|
171
|
+
if (!isHTMLElement(target)) {
|
|
172
|
+
setDraggableBlockElem(null);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (isOnMenu(target)) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const _draggableBlockElem = getBlockElement(anchorElem, editor, event);
|
|
179
|
+
setDraggableBlockElem(_draggableBlockElem);
|
|
180
|
+
}
|
|
181
|
+
function onMouseLeave() {
|
|
182
|
+
setDraggableBlockElem(null);
|
|
183
|
+
}
|
|
184
|
+
scrollerElem?.addEventListener('mousemove', onMouseMove);
|
|
185
|
+
scrollerElem?.addEventListener('mouseleave', onMouseLeave);
|
|
186
|
+
return () => {
|
|
187
|
+
scrollerElem?.removeEventListener('mousemove', onMouseMove);
|
|
188
|
+
scrollerElem?.removeEventListener('mouseleave', onMouseLeave);
|
|
189
|
+
};
|
|
190
|
+
}, [scrollerElem, anchorElem, editor]);
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
if (menuRef.current) {
|
|
193
|
+
setMenuPosition(draggableBlockElem, menuRef.current, anchorElem);
|
|
194
|
+
}
|
|
195
|
+
}, [anchorElem, draggableBlockElem]);
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
function onDragover(event) {
|
|
198
|
+
if (!isDraggingBlockRef.current) {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
const [isFileTransfer] = eventFiles(event);
|
|
202
|
+
if (isFileTransfer) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
const { pageY, target } = event;
|
|
206
|
+
if (!isHTMLElement(target)) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
const targetBlockElem = getBlockElement(anchorElem, editor, event, true);
|
|
210
|
+
const targetLineElem = targetLineRef.current;
|
|
211
|
+
if (targetBlockElem === null || targetLineElem === null) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
setTargetLine(targetLineElem, targetBlockElem, pageY, anchorElem);
|
|
215
|
+
// Prevent default event to be able to trigger onDrop events
|
|
216
|
+
event.preventDefault();
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
function onDrop(event) {
|
|
220
|
+
if (!isDraggingBlockRef.current) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
const [isFileTransfer] = eventFiles(event);
|
|
224
|
+
if (isFileTransfer) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
const { target, dataTransfer, pageY } = event;
|
|
228
|
+
const dragData = dataTransfer?.getData(DRAG_DATA_FORMAT) || '';
|
|
229
|
+
const draggedNode = $getNodeByKey(dragData);
|
|
230
|
+
if (!draggedNode) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
if (!isHTMLElement(target)) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
const targetBlockElem = getBlockElement(anchorElem, editor, event, true);
|
|
237
|
+
if (!targetBlockElem) {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
const targetNode = $getNearestNodeFromDOMNode(targetBlockElem);
|
|
241
|
+
if (!targetNode) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
if (targetNode === draggedNode) {
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
const targetBlockElemTop = targetBlockElem.getBoundingClientRect().top;
|
|
248
|
+
if (pageY >= targetBlockElemTop) {
|
|
249
|
+
targetNode.insertAfter(draggedNode);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
targetNode.insertBefore(draggedNode);
|
|
253
|
+
}
|
|
254
|
+
setDraggableBlockElem(null);
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
return mergeRegister(editor.registerCommand(DRAGOVER_COMMAND, (event) => {
|
|
258
|
+
return onDragover(event);
|
|
259
|
+
}, COMMAND_PRIORITY_LOW), editor.registerCommand(DROP_COMMAND, (event) => {
|
|
260
|
+
return onDrop(event);
|
|
261
|
+
}, COMMAND_PRIORITY_HIGH));
|
|
262
|
+
}, [anchorElem, editor]);
|
|
263
|
+
function onDragStart(event) {
|
|
264
|
+
const { dataTransfer } = event;
|
|
265
|
+
if (!dataTransfer || !draggableBlockElem) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
setDragImage(dataTransfer, draggableBlockElem);
|
|
269
|
+
let nodeKey = '';
|
|
270
|
+
editor.update(() => {
|
|
271
|
+
const node = $getNearestNodeFromDOMNode(draggableBlockElem);
|
|
272
|
+
if (node) {
|
|
273
|
+
nodeKey = node.getKey();
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
isDraggingBlockRef.current = true;
|
|
277
|
+
dataTransfer.setData(DRAG_DATA_FORMAT, nodeKey);
|
|
278
|
+
}
|
|
279
|
+
function onDragEnd() {
|
|
280
|
+
isDraggingBlockRef.current = false;
|
|
281
|
+
hideTargetLine(targetLineRef.current);
|
|
282
|
+
}
|
|
283
|
+
return createPortal(_jsxs(_Fragment, { children: [_jsx("div", { className: "icon draggable-block-menu", ref: menuRef, draggable: true, onDragStart: onDragStart, onDragEnd: onDragEnd, children: _jsx("div", { className: isEditable ? 'icon' : '' }) }), _jsx("div", { className: "draggable-block-target-line", ref: targetLineRef })] }), anchorElem);
|
|
284
|
+
}
|
|
285
|
+
export default function DraggableBlockPlugin({ anchorElem = document.body, }) {
|
|
286
|
+
const [editor] = useLexicalComposerContext();
|
|
287
|
+
return useDraggableBlockMenu(editor, anchorElem, editor._editable);
|
|
288
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { type JSX } from 'react';
|
|
9
|
+
export default function EmojisPlugin(): JSX.Element | null;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
9
|
+
import { TextNode } from 'lexical';
|
|
10
|
+
import { useEffect } from 'react';
|
|
11
|
+
import { $createEmojiNode, EmojiNode } from '../../nodes/EmojiNode';
|
|
12
|
+
const emojis = new Map([
|
|
13
|
+
[':)', ['emoji happysmile', '🙂']],
|
|
14
|
+
[':D', ['emoji veryhappysmile', '😀']],
|
|
15
|
+
[':(', ['emoji unhappysmile', '🙁']],
|
|
16
|
+
['<3', ['emoji heart', '❤']],
|
|
17
|
+
['🙂', ['emoji happysmile', '🙂']],
|
|
18
|
+
['😀', ['emoji veryhappysmile', '😀']],
|
|
19
|
+
['🙁', ['emoji unhappysmile', '🙁']],
|
|
20
|
+
['❤', ['emoji heart', '❤']],
|
|
21
|
+
]);
|
|
22
|
+
function findAndTransformEmoji(node) {
|
|
23
|
+
const text = node.getTextContent();
|
|
24
|
+
for (let i = 0; i < text.length; i++) {
|
|
25
|
+
const emojiData = emojis.get(text[i]) || emojis.get(text.slice(i, i + 2));
|
|
26
|
+
if (emojiData !== undefined) {
|
|
27
|
+
const [emojiStyle, emojiText] = emojiData;
|
|
28
|
+
let targetNode;
|
|
29
|
+
if (i === 0) {
|
|
30
|
+
[targetNode] = node.splitText(i + 2);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
[, targetNode] = node.splitText(i, i + 2);
|
|
34
|
+
}
|
|
35
|
+
const emojiNode = $createEmojiNode(emojiStyle, emojiText);
|
|
36
|
+
targetNode.replace(emojiNode);
|
|
37
|
+
return emojiNode;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
function textNodeTransform(node) {
|
|
43
|
+
let targetNode = node;
|
|
44
|
+
while (targetNode !== null) {
|
|
45
|
+
if (!targetNode.isSimpleText()) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
targetNode = findAndTransformEmoji(targetNode);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function useEmojis(editor) {
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (!editor.hasNodes([EmojiNode])) {
|
|
54
|
+
throw new Error('EmojisPlugin: EmojiNode not registered on editor');
|
|
55
|
+
}
|
|
56
|
+
return editor.registerNodeTransform(TextNode, textNodeTransform);
|
|
57
|
+
}, [editor]);
|
|
58
|
+
}
|
|
59
|
+
export default function EmojisPlugin() {
|
|
60
|
+
const [editor] = useLexicalComposerContext();
|
|
61
|
+
useEmojis(editor);
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
9
|
+
import { $wrapNodeInElement } from '@lexical/utils';
|
|
10
|
+
import { $createParagraphNode, $insertNodes, $isRootOrShadowRoot, COMMAND_PRIORITY_EDITOR, createCommand, } from 'lexical';
|
|
11
|
+
import { useEffect } from 'react';
|
|
12
|
+
import { $createExcalidrawNode, ExcalidrawNode } from '../../nodes/ExcalidrawNode';
|
|
13
|
+
export const INSERT_EXCALIDRAW_COMMAND = createCommand('INSERT_EXCALIDRAW_COMMAND');
|
|
14
|
+
export default function ExcalidrawPlugin() {
|
|
15
|
+
const [editor] = useLexicalComposerContext();
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!editor.hasNodes([ExcalidrawNode])) {
|
|
18
|
+
throw new Error('ExcalidrawPlugin: ExcalidrawNode not registered on editor');
|
|
19
|
+
}
|
|
20
|
+
return editor.registerCommand(INSERT_EXCALIDRAW_COMMAND, () => {
|
|
21
|
+
const excalidrawNode = $createExcalidrawNode();
|
|
22
|
+
$insertNodes([excalidrawNode]);
|
|
23
|
+
if ($isRootOrShadowRoot(excalidrawNode.getParentOrThrow())) {
|
|
24
|
+
$wrapNodeInElement(excalidrawNode, $createParagraphNode).selectEnd();
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}, COMMAND_PRIORITY_EDITOR);
|
|
28
|
+
}, [editor]);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { LexicalCommand } from 'lexical';
|
|
9
|
+
import { type JSX } from 'react';
|
|
10
|
+
export declare const INSERT_FIGMA_COMMAND: LexicalCommand<string>;
|
|
11
|
+
export default function FigmaPlugin(): JSX.Element | null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
9
|
+
import { $insertNodeToNearestRoot } from '@lexical/utils';
|
|
10
|
+
import { COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
|
|
11
|
+
import { useEffect } from 'react';
|
|
12
|
+
import { $createFigmaNode, FigmaNode } from '../../nodes/FigmaNode';
|
|
13
|
+
export const INSERT_FIGMA_COMMAND = createCommand('INSERT_FIGMA_COMMAND');
|
|
14
|
+
export default function FigmaPlugin() {
|
|
15
|
+
const [editor] = useLexicalComposerContext();
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!editor.hasNodes([FigmaNode])) {
|
|
18
|
+
throw new Error('FigmaPlugin: FigmaNode not registered on editor');
|
|
19
|
+
}
|
|
20
|
+
return editor.registerCommand(INSERT_FIGMA_COMMAND, (payload) => {
|
|
21
|
+
const figmaNode = $createFigmaNode(payload);
|
|
22
|
+
$insertNodeToNearestRoot(figmaNode);
|
|
23
|
+
return true;
|
|
24
|
+
}, COMMAND_PRIORITY_EDITOR);
|
|
25
|
+
}, [editor]);
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
.link-editor {
|
|
2
|
+
position: absolute;
|
|
3
|
+
top: 0;
|
|
4
|
+
left: 0;
|
|
5
|
+
z-index: 10;
|
|
6
|
+
max-width: 400px;
|
|
7
|
+
width: 100%;
|
|
8
|
+
opacity: 0;
|
|
9
|
+
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3);
|
|
10
|
+
border-radius: 8px;
|
|
11
|
+
transition: opacity 0.5s;
|
|
12
|
+
will-change: transform;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.link-editor .button {
|
|
16
|
+
width: 20px;
|
|
17
|
+
height: 20px;
|
|
18
|
+
display: inline-block;
|
|
19
|
+
padding: 6px;
|
|
20
|
+
border-radius: 8px;
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
margin: 0 2px;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.link-editor .button.hovered {
|
|
26
|
+
width: 20px;
|
|
27
|
+
height: 20px;
|
|
28
|
+
display: inline-block;
|
|
29
|
+
background-color: #eee;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.link-editor .button i,
|
|
33
|
+
.actions i {
|
|
34
|
+
background-size: contain;
|
|
35
|
+
display: inline-block;
|
|
36
|
+
height: 20px;
|
|
37
|
+
width: 20px;
|
|
38
|
+
vertical-align: -0.25em;
|
|
39
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import './index.css';
|
|
9
|
+
import { type JSX } from 'react';
|
|
10
|
+
export default function FloatingLinkEditorPlugin({ anchorElem, }: {
|
|
11
|
+
anchorElem?: HTMLElement;
|
|
12
|
+
}): JSX.Element | null;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
import './index.css';
|
|
10
|
+
import { $isAutoLinkNode, $isLinkNode, TOGGLE_LINK_COMMAND } from '@lexical/link';
|
|
11
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
12
|
+
import { $findMatchingParent, mergeRegister } from '@lexical/utils';
|
|
13
|
+
import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_LOW, SELECTION_CHANGE_COMMAND, } from 'lexical';
|
|
14
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
15
|
+
import { createPortal } from 'react-dom';
|
|
16
|
+
import { Box } from '@mui/material';
|
|
17
|
+
import { getSelectedNode } from '../../utils/getSelectedNode';
|
|
18
|
+
import { sanitizeUrl } from '../../utils/sanitizeUrl';
|
|
19
|
+
import { setFloatingElemPosition } from '../../utils/setFloatingElemPosition';
|
|
20
|
+
function FloatingLinkEditor({ editor, anchorElem }) {
|
|
21
|
+
const editorRef = useRef(null);
|
|
22
|
+
const inputRef = useRef(null);
|
|
23
|
+
const [linkUrl, setLinkUrl] = useState('');
|
|
24
|
+
const [isEditMode, setEditMode] = useState(false);
|
|
25
|
+
const [lastSelection, setLastSelection] = useState(null);
|
|
26
|
+
const updateLinkEditor = useCallback(() => {
|
|
27
|
+
const selection = $getSelection();
|
|
28
|
+
if ($isRangeSelection(selection)) {
|
|
29
|
+
const node = getSelectedNode(selection);
|
|
30
|
+
const parent = node.getParent();
|
|
31
|
+
if ($isLinkNode(parent)) {
|
|
32
|
+
setLinkUrl(parent.getURL());
|
|
33
|
+
}
|
|
34
|
+
else if ($isLinkNode(node)) {
|
|
35
|
+
setLinkUrl(node.getURL());
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
setLinkUrl('');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const editorElem = editorRef.current;
|
|
42
|
+
const nativeSelection = window.getSelection();
|
|
43
|
+
const { activeElement } = document;
|
|
44
|
+
if (editorElem === null) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const rootElement = editor.getRootElement();
|
|
48
|
+
if (selection !== null &&
|
|
49
|
+
nativeSelection !== null &&
|
|
50
|
+
rootElement !== null &&
|
|
51
|
+
rootElement.contains(nativeSelection.anchorNode)) {
|
|
52
|
+
const domRange = nativeSelection.getRangeAt(0);
|
|
53
|
+
let rect;
|
|
54
|
+
if (nativeSelection.anchorNode === rootElement) {
|
|
55
|
+
let inner = rootElement;
|
|
56
|
+
while (inner.firstElementChild != null) {
|
|
57
|
+
inner = inner.firstElementChild;
|
|
58
|
+
}
|
|
59
|
+
rect = inner.getBoundingClientRect();
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
rect = domRange.getBoundingClientRect();
|
|
63
|
+
}
|
|
64
|
+
setFloatingElemPosition(rect, editorElem, anchorElem);
|
|
65
|
+
setLastSelection(selection);
|
|
66
|
+
}
|
|
67
|
+
else if (!activeElement || activeElement.className !== 'link-input') {
|
|
68
|
+
if (rootElement !== null) {
|
|
69
|
+
setFloatingElemPosition(null, editorElem, anchorElem);
|
|
70
|
+
}
|
|
71
|
+
setLastSelection(null);
|
|
72
|
+
setEditMode(false);
|
|
73
|
+
setLinkUrl('');
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
}, [anchorElem, editor]);
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
const scrollerElem = anchorElem.parentElement;
|
|
79
|
+
const update = () => {
|
|
80
|
+
editor.getEditorState().read(() => {
|
|
81
|
+
updateLinkEditor();
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
window.addEventListener('resize', update);
|
|
85
|
+
if (scrollerElem) {
|
|
86
|
+
scrollerElem.addEventListener('scroll', update);
|
|
87
|
+
}
|
|
88
|
+
return () => {
|
|
89
|
+
window.removeEventListener('resize', update);
|
|
90
|
+
if (scrollerElem) {
|
|
91
|
+
scrollerElem.removeEventListener('scroll', update);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}, [anchorElem.parentElement, editor, updateLinkEditor]);
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
return mergeRegister(editor.registerUpdateListener((payload) => {
|
|
97
|
+
if (!payload)
|
|
98
|
+
return;
|
|
99
|
+
const { editorState } = payload;
|
|
100
|
+
editorState.read(() => {
|
|
101
|
+
updateLinkEditor();
|
|
102
|
+
});
|
|
103
|
+
}), editor.registerCommand(SELECTION_CHANGE_COMMAND, () => {
|
|
104
|
+
updateLinkEditor();
|
|
105
|
+
return true;
|
|
106
|
+
}, COMMAND_PRIORITY_LOW));
|
|
107
|
+
}, [editor, updateLinkEditor]);
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
editor.getEditorState().read(() => {
|
|
110
|
+
updateLinkEditor();
|
|
111
|
+
});
|
|
112
|
+
}, [editor, updateLinkEditor]);
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (isEditMode && inputRef.current) {
|
|
115
|
+
inputRef.current.focus();
|
|
116
|
+
}
|
|
117
|
+
}, [isEditMode]);
|
|
118
|
+
return (_jsx(Box, { ref: editorRef, className: "link-editor", sx: {
|
|
119
|
+
bgcolor: 'background.default',
|
|
120
|
+
color: 'text.primary',
|
|
121
|
+
border: 1,
|
|
122
|
+
borderColor: 'divider',
|
|
123
|
+
'& .link-input': {
|
|
124
|
+
minHeight: 32,
|
|
125
|
+
color: 'text.primary',
|
|
126
|
+
bgcolor: 'grey.100',
|
|
127
|
+
'& a': {
|
|
128
|
+
color: 'primary.main',
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
}, children: isEditMode ? (_jsx("input", { ref: inputRef, className: "link-input", value: linkUrl, onChange: (event) => {
|
|
132
|
+
setLinkUrl(event.target.value);
|
|
133
|
+
}, onKeyDown: (event) => {
|
|
134
|
+
if (event.key === 'Enter') {
|
|
135
|
+
event.preventDefault();
|
|
136
|
+
if (lastSelection !== null) {
|
|
137
|
+
if (linkUrl !== '') {
|
|
138
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, sanitizeUrl(linkUrl));
|
|
139
|
+
}
|
|
140
|
+
setEditMode(false);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else if (event.key === 'Escape') {
|
|
144
|
+
event.preventDefault();
|
|
145
|
+
setEditMode(false);
|
|
146
|
+
}
|
|
147
|
+
} })) : (_jsxs("div", { className: "link-input", children: [_jsx("a", { href: linkUrl, target: "_blank", rel: "noopener noreferrer", children: linkUrl }), _jsx("div", { className: "link-edit", role: "button", tabIndex: 0, onMouseDown: (event) => event.preventDefault(), onClick: () => {
|
|
148
|
+
setEditMode(true);
|
|
149
|
+
}, children: _jsx("i", { className: "iconify", "data-icon": "mdi:pencil" }) })] })) }));
|
|
150
|
+
}
|
|
151
|
+
function useFloatingLinkEditorToolbar(editor, anchorElem) {
|
|
152
|
+
const [activeEditor, setActiveEditor] = useState(editor);
|
|
153
|
+
const [isLink, setIsLink] = useState(false);
|
|
154
|
+
const updateToolbar = useCallback(() => {
|
|
155
|
+
const selection = $getSelection();
|
|
156
|
+
if ($isRangeSelection(selection)) {
|
|
157
|
+
const node = getSelectedNode(selection);
|
|
158
|
+
const linkParent = $findMatchingParent(node, $isLinkNode);
|
|
159
|
+
const autoLinkParent = $findMatchingParent(node, $isAutoLinkNode);
|
|
160
|
+
// We don't want this menu to open for auto links.
|
|
161
|
+
if (linkParent != null && autoLinkParent == null) {
|
|
162
|
+
setIsLink(true);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
setIsLink(false);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}, []);
|
|
169
|
+
useEffect(() => {
|
|
170
|
+
return editor.registerCommand(SELECTION_CHANGE_COMMAND, (_payload, newEditor) => {
|
|
171
|
+
updateToolbar();
|
|
172
|
+
setActiveEditor(newEditor);
|
|
173
|
+
return false;
|
|
174
|
+
}, COMMAND_PRIORITY_CRITICAL);
|
|
175
|
+
}, [editor, updateToolbar]);
|
|
176
|
+
return isLink ? createPortal(_jsx(FloatingLinkEditor, { editor: activeEditor, anchorElem: anchorElem }), anchorElem) : null;
|
|
177
|
+
}
|
|
178
|
+
export default function FloatingLinkEditorPlugin({ anchorElem = document.body, }) {
|
|
179
|
+
const [editor] = useLexicalComposerContext();
|
|
180
|
+
return useFloatingLinkEditorToolbar(editor, anchorElem);
|
|
181
|
+
}
|