@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,10 @@
|
|
|
1
|
+
type Props = {
|
|
2
|
+
charset: 'UTF-8' | 'UTF-16';
|
|
3
|
+
onChange?: ({ words, textLength, readTime }: {
|
|
4
|
+
words: number;
|
|
5
|
+
textLength: number;
|
|
6
|
+
readTime: number;
|
|
7
|
+
}) => void;
|
|
8
|
+
};
|
|
9
|
+
export default function CharacterCountPlugin({ charset, onChange }: Props): null;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import useCharacterCount from './useCharacterCount';
|
|
4
|
+
let textEncoderInstance = null;
|
|
5
|
+
function textEncoder() {
|
|
6
|
+
if (window.TextEncoder === undefined) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
if (textEncoderInstance === null) {
|
|
10
|
+
textEncoderInstance = new window.TextEncoder();
|
|
11
|
+
}
|
|
12
|
+
return textEncoderInstance;
|
|
13
|
+
}
|
|
14
|
+
function utf8Length(text) {
|
|
15
|
+
const currentTextEncoder = textEncoder();
|
|
16
|
+
if (currentTextEncoder === null) {
|
|
17
|
+
// http://stackoverflow.com/a/5515960/210370
|
|
18
|
+
const m = encodeURIComponent(text).match(/%[89ABab]/g);
|
|
19
|
+
return text.length + (m ? m.length : 0);
|
|
20
|
+
}
|
|
21
|
+
return currentTextEncoder.encode(text).length;
|
|
22
|
+
}
|
|
23
|
+
export default function CharacterCountPlugin({ charset = 'UTF-8', onChange }) {
|
|
24
|
+
const [editor] = useLexicalComposerContext();
|
|
25
|
+
const characterCountProps = useMemo(() => ({
|
|
26
|
+
strlen: (text) => {
|
|
27
|
+
if (charset === 'UTF-8') {
|
|
28
|
+
return utf8Length(text);
|
|
29
|
+
}
|
|
30
|
+
if (charset === 'UTF-16') {
|
|
31
|
+
return text.length;
|
|
32
|
+
}
|
|
33
|
+
throw new Error('Unrecognized charset');
|
|
34
|
+
},
|
|
35
|
+
onChange,
|
|
36
|
+
}), [charset]);
|
|
37
|
+
useCharacterCount(editor, characterCountProps);
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LexicalEditor } from 'lexical';
|
|
2
|
+
type OptionalProps = {
|
|
3
|
+
strlen?: (input: string) => number;
|
|
4
|
+
onChange?: ({ words, textLength, readTime }: {
|
|
5
|
+
words: number;
|
|
6
|
+
textLength: number;
|
|
7
|
+
readTime: number;
|
|
8
|
+
}) => void;
|
|
9
|
+
};
|
|
10
|
+
export default function useCharacterCount(editor: LexicalEditor, optional?: OptionalProps): void;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { $rootTextContent } from '@lexical/text';
|
|
2
|
+
import { mergeRegister } from '@lexical/utils';
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
// 判断阅读时间,根据字节数判断
|
|
5
|
+
function estimateReadingTime(words) {
|
|
6
|
+
const readingSpeed = 200; // 200字/分钟
|
|
7
|
+
const readingTime = words / readingSpeed;
|
|
8
|
+
return parseInt(String(readingTime * 60), 10) || 1;
|
|
9
|
+
}
|
|
10
|
+
// 给出一个文本,判断单词个数,其中包括中文和英文
|
|
11
|
+
function countWords(text) {
|
|
12
|
+
const chineseWords = text.match(/[\u4e00-\u9fa5]/g);
|
|
13
|
+
const englishWords = text.match(/\w+/g);
|
|
14
|
+
const chineseWordsCount = chineseWords ? chineseWords.length : 0;
|
|
15
|
+
const englishWordsCount = englishWords ? englishWords.length : 0;
|
|
16
|
+
return chineseWordsCount + englishWordsCount;
|
|
17
|
+
}
|
|
18
|
+
// 获取文本节点的单词个数
|
|
19
|
+
const getTextWordsContent = (text) => {
|
|
20
|
+
return countWords(text);
|
|
21
|
+
};
|
|
22
|
+
export default function useCharacterCount(editor, optional = Object.freeze({})) {
|
|
23
|
+
const { strlen = (input) => input.length, onChange = () => { } } = optional;
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
let text = editor.getEditorState().read($rootTextContent);
|
|
26
|
+
return mergeRegister(editor.registerTextContentListener((currentText) => {
|
|
27
|
+
text = currentText;
|
|
28
|
+
}), editor.registerUpdateListener((payload) => {
|
|
29
|
+
if (!payload)
|
|
30
|
+
return;
|
|
31
|
+
const { dirtyLeaves } = payload;
|
|
32
|
+
const isComposing = editor.isComposing();
|
|
33
|
+
const hasDirtyLeaves = dirtyLeaves.size > 0;
|
|
34
|
+
if (isComposing || !hasDirtyLeaves) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
editor.getEditorState().read(() => {
|
|
38
|
+
const textLength = strlen(text);
|
|
39
|
+
const words = getTextWordsContent(text);
|
|
40
|
+
const readTime = estimateReadingTime(words);
|
|
41
|
+
onChange({
|
|
42
|
+
words,
|
|
43
|
+
textLength,
|
|
44
|
+
readTime,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}));
|
|
48
|
+
}, [editor, strlen]);
|
|
49
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SxProps } from '@mui/material';
|
|
2
|
+
import { type JSX } from 'react';
|
|
3
|
+
interface CharacterLimitPluginProps {
|
|
4
|
+
maxLength?: number;
|
|
5
|
+
charLimitIndicatorStyle?: SxProps;
|
|
6
|
+
alignLeft?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function CharacterLimitPlugin({ maxLength, charLimitIndicatorStyle, alignLeft, }: CharacterLimitPluginProps): JSX.Element | null;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { Box } from '@mui/material';
|
|
4
|
+
import { CharacterLimitPlugin as LexicalCharacterLimitPlugin } from '../../vendor/LexicalCharacterLimitPlugin';
|
|
5
|
+
import { MaxLengthPlugin } from '../../main/plugins/MaxLengthPlugin';
|
|
6
|
+
export function CharacterLimitPlugin({ maxLength, charLimitIndicatorStyle, alignLeft = false, }) {
|
|
7
|
+
const [editor] = useLexicalComposerContext();
|
|
8
|
+
if (!editor.isEditable()) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
if (!editor.isEditable() || !maxLength) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const mergedSx = Array.isArray(charLimitIndicatorStyle) ? charLimitIndicatorStyle : [charLimitIndicatorStyle];
|
|
15
|
+
if (alignLeft) {
|
|
16
|
+
const left = editor.getRootElement()?.getBoundingClientRect()?.left ?? 0;
|
|
17
|
+
mergedSx.push({ left: left + 24 });
|
|
18
|
+
}
|
|
19
|
+
return (_jsxs(_Fragment, { children: [_jsx(MaxLengthPlugin, { maxLength: maxLength }), _jsx(LexicalCharacterLimitPlugin, { charset: "UTF-16", maxLength: maxLength, renderer: ({ remainingCharacters }) => {
|
|
20
|
+
return (_jsx(CharLimitIndicator, { currentCount: maxLength - remainingCharacters, maxLength: maxLength, sx: mergedSx }));
|
|
21
|
+
} })] }));
|
|
22
|
+
}
|
|
23
|
+
function CharLimitIndicator({ currentCount, maxLength, sx }) {
|
|
24
|
+
const percentage = (currentCount / maxLength) * 100;
|
|
25
|
+
const isNearLimit = percentage >= 80;
|
|
26
|
+
const isOverLimit = currentCount > maxLength;
|
|
27
|
+
// Calculate the circumference for the circular progress
|
|
28
|
+
const radius = 8;
|
|
29
|
+
const circumference = 2 * Math.PI * radius;
|
|
30
|
+
const strokeDashoffset = circumference - (percentage / 100) * circumference;
|
|
31
|
+
if (percentage === 0) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const mergedSx = [
|
|
35
|
+
{ display: 'flex', alignItems: 'center', position: 'absolute', bottom: 6, left: 32 },
|
|
36
|
+
...(Array.isArray(sx) ? sx : [sx]),
|
|
37
|
+
];
|
|
38
|
+
return (_jsxs(Box, { sx: mergedSx, children: [_jsx(Box, { sx: { position: 'relative', width: 20, height: 20 }, children: _jsxs(Box, { component: "svg", sx: { width: 20, height: 20, transform: 'rotate(-90deg)' }, viewBox: "0 0 20 20", children: [_jsx(Box, { component: "circle", cx: "10", cy: "10", r: radius, stroke: "currentColor", strokeWidth: "2", fill: "none", sx: { opacity: 0.2 } }), _jsx(Box, { component: "circle", cx: "10", cy: "10", r: radius, stroke: "currentColor", strokeWidth: "2", fill: "none", strokeDasharray: circumference, strokeDashoffset: strokeDashoffset, strokeLinecap: "round", sx: {
|
|
39
|
+
transition: 'all 0.3s ease-out',
|
|
40
|
+
color: isOverLimit ? 'error.main' : isNearLimit ? 'warning.main' : 'primary.main',
|
|
41
|
+
} })] }) }), _jsxs(Box, { component: "span", sx: {
|
|
42
|
+
display: 'inline-block',
|
|
43
|
+
ml: 0.5,
|
|
44
|
+
fontSize: 13,
|
|
45
|
+
fontWeight: 500,
|
|
46
|
+
transition: 'all 0.3s ease-out',
|
|
47
|
+
color: isOverLimit ? 'error.main' : isNearLimit ? 'warning.main' : 'primary.main',
|
|
48
|
+
}, children: [currentCount.toLocaleString(), "/", maxLength.toLocaleString()] })] }));
|
|
49
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { $getNearestNodeFromDOMNode } from 'lexical';
|
|
4
|
+
import { $isListItemNode } from '@lexical/list';
|
|
5
|
+
import { minDelay } from './utils';
|
|
6
|
+
export default function CheckboxPlugin({ send }) {
|
|
7
|
+
const [editor] = useLexicalComposerContext();
|
|
8
|
+
const [busy, setBusy] = useState(false);
|
|
9
|
+
const content = useRef('');
|
|
10
|
+
const submit = async () => {
|
|
11
|
+
if (!send) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
setBusy(true);
|
|
16
|
+
await minDelay(send(JSON.stringify(editor.getEditorState())), 800);
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
const editorStateStr = editor.parseEditorState(content.current);
|
|
20
|
+
editor.setEditorState(editorStateStr);
|
|
21
|
+
console.error(e);
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
setBusy(false);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const onClick = (e) => {
|
|
28
|
+
const editable = editor.isEditable();
|
|
29
|
+
if (editable || busy)
|
|
30
|
+
return false;
|
|
31
|
+
const domNode = e.target;
|
|
32
|
+
editor.update(() => {
|
|
33
|
+
content.current = JSON.stringify(editor.getEditorState());
|
|
34
|
+
if (domNode.nodeName === 'LI' && domNode.getAttribute('role') === 'checkbox') {
|
|
35
|
+
try {
|
|
36
|
+
const node = $getNearestNodeFromDOMNode(domNode);
|
|
37
|
+
if ($isListItemNode(node)) {
|
|
38
|
+
// 判断鼠标点击的位置与当前元素左侧位置距离, 如果小于 20px 则认为点击了 checkbox
|
|
39
|
+
const left = domNode.getBoundingClientRect()?.left || 0;
|
|
40
|
+
const checkboxLeft = e.clientX - left;
|
|
41
|
+
const inCheckBox = checkboxLeft <= 20;
|
|
42
|
+
if (!inCheckBox)
|
|
43
|
+
return;
|
|
44
|
+
domNode.focus();
|
|
45
|
+
node.toggleChecked();
|
|
46
|
+
domNode.blur();
|
|
47
|
+
setTimeout(submit, 0);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.error(error);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
return editor.registerRootListener((rootElement, prevRootElement) => {
|
|
58
|
+
if (prevRootElement !== null) {
|
|
59
|
+
prevRootElement.removeEventListener('click', onClick);
|
|
60
|
+
}
|
|
61
|
+
if (rootElement !== null) {
|
|
62
|
+
rootElement.addEventListener('click', onClick);
|
|
63
|
+
}
|
|
64
|
+
if (rootElement) {
|
|
65
|
+
if (busy) {
|
|
66
|
+
rootElement.classList.add('blocklet-editor-busy');
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
rootElement.classList.remove('blocklet-editor-busy');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}, [editor, send, busy]);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { CodeNode } from '@lexical/code';
|
|
3
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
4
|
+
import { Box, IconButton } from '@mui/material';
|
|
5
|
+
import { $getNodeByKey } from 'lexical';
|
|
6
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
7
|
+
import { Icon } from '@iconify/react';
|
|
8
|
+
import { usePopper } from 'react-popper';
|
|
9
|
+
import './style.css';
|
|
10
|
+
function isPointInsideElement(point, element) {
|
|
11
|
+
if (!element) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const rect = element.getBoundingClientRect();
|
|
15
|
+
return point.x > rect.left && point.x < rect.right && point.y > rect.top && point.y < rect.bottom;
|
|
16
|
+
}
|
|
17
|
+
export function CodeCopyPlugin() {
|
|
18
|
+
const [editor] = useLexicalComposerContext();
|
|
19
|
+
const [codeNodes, setCodeNodes] = useState([]);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
return editor.registerMutationListener(CodeNode, (mutatedNodes) => {
|
|
22
|
+
const nodes = Array.from(mutatedNodes.keys())
|
|
23
|
+
.map((key) => $getNodeByKey(key, editor.getEditorState()))
|
|
24
|
+
.filter(Boolean);
|
|
25
|
+
setCodeNodes(nodes);
|
|
26
|
+
}, { skipInitialization: false });
|
|
27
|
+
}, [editor]);
|
|
28
|
+
return (_jsx(_Fragment, { children: codeNodes.map((codeNode) => (_jsx(CodeCopyButton, { editor: editor, codeNode: codeNode }, codeNode.getKey()))) }));
|
|
29
|
+
}
|
|
30
|
+
function CodeCopyButton({ editor, codeNode }) {
|
|
31
|
+
const [isCopied, setIsCopied] = useState(false);
|
|
32
|
+
const [buttonElement, setButtonElement] = useState(null);
|
|
33
|
+
const codeElement = useMemo(() => editor.getElementByKey(codeNode.getKey()), [editor, codeNode]);
|
|
34
|
+
const [isActivated, setIsActivated] = useState(false);
|
|
35
|
+
const popper = usePopper(codeElement, buttonElement, {
|
|
36
|
+
placement: 'right-start',
|
|
37
|
+
modifiers: [
|
|
38
|
+
{ name: 'flip', enabled: false },
|
|
39
|
+
{
|
|
40
|
+
name: 'offset',
|
|
41
|
+
options: {
|
|
42
|
+
offset: [8, -36],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
});
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
const handleMouseEnter = () => setIsActivated(true);
|
|
49
|
+
const handleMouseLeave = (e) => {
|
|
50
|
+
if (!isPointInsideElement(e, codeElement)) {
|
|
51
|
+
setIsActivated(false);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
if (codeElement) {
|
|
55
|
+
codeElement.addEventListener('mouseenter', handleMouseEnter);
|
|
56
|
+
codeElement.addEventListener('mouseleave', handleMouseLeave);
|
|
57
|
+
return () => {
|
|
58
|
+
codeElement.removeEventListener('mouseenter', handleMouseEnter);
|
|
59
|
+
codeElement.removeEventListener('mouseleave', handleMouseLeave);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}, [codeElement]);
|
|
63
|
+
if (!isActivated && !isCopied) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
return (_jsx(IconButton, { ref: setButtonElement, style: popper.styles.popper, ...popper.attributes.popper, sx: {
|
|
67
|
+
color: 'text.secondary',
|
|
68
|
+
fontSize: 18,
|
|
69
|
+
bgcolor: 'background.paper',
|
|
70
|
+
'&:hover': {
|
|
71
|
+
color: 'text.primary',
|
|
72
|
+
bgcolor: 'background.paper',
|
|
73
|
+
},
|
|
74
|
+
}, onClick: async () => {
|
|
75
|
+
let content = '';
|
|
76
|
+
editor.update(() => {
|
|
77
|
+
content = codeNode.getTextContent();
|
|
78
|
+
});
|
|
79
|
+
try {
|
|
80
|
+
await navigator.clipboard.writeText(content);
|
|
81
|
+
setIsCopied(true);
|
|
82
|
+
setTimeout(() => {
|
|
83
|
+
setIsCopied(false);
|
|
84
|
+
}, 1500);
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
console.error('Failed to copy: ', err);
|
|
88
|
+
}
|
|
89
|
+
}, children: isCopied ? (_jsx(Box, { component: Icon, icon: "tabler:check", sx: { color: 'success.main' } })) : (_jsx(Icon, { icon: "tabler:copy" })) }));
|
|
90
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><!-- Icon from Tabler Icons by Paweł Kuna - https://github.com/tabler/tabler-icons/blob/master/LICENSE --><g fill="none" stroke="#888888" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M7 9.667A2.667 2.667 0 0 1 9.667 7h8.666A2.667 2.667 0 0 1 21 9.667v8.666A2.667 2.667 0 0 1 18.333 21H9.667A2.667 2.667 0 0 1 7 18.333z"/><path d="M4.012 16.737A2 2 0 0 1 3 15V5c0-1.1.9-2 2-2h10c.75 0 1.158.385 1.5 1"/></g></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CodeCopyPlugin';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CodeCopyPlugin';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
interface ContextType {
|
|
3
|
+
locale: string;
|
|
4
|
+
}
|
|
5
|
+
export declare const useContentLocale: () => string;
|
|
6
|
+
export declare const ContentLocaleProvider: ({ locale, children }: PropsWithChildren & ContextType) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
3
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
4
|
+
const ContentLocaleContext = createContext(null);
|
|
5
|
+
// 该 hook 关注 editor content 的 locale, 区别于 LocaleContext
|
|
6
|
+
// (编辑 post 翻译版本时, 会切换 ContentLocaleContext)
|
|
7
|
+
export const useContentLocale = () => {
|
|
8
|
+
const { locale: contextLocale } = useLocaleContext();
|
|
9
|
+
const ctx = useContext(ContentLocaleContext);
|
|
10
|
+
return ctx?.locale || contextLocale;
|
|
11
|
+
};
|
|
12
|
+
export const ContentLocaleProvider = ({ locale, children }) => {
|
|
13
|
+
const value = useMemo(() => ({ locale }), [locale]);
|
|
14
|
+
return _jsx(ContentLocaleContext.Provider, { value: value, children: children });
|
|
15
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { mergeRegister } from '@lexical/utils';
|
|
4
|
+
import { setNodePlaceholderFromSelection, setNodePlaceholderFromState } from './utils';
|
|
5
|
+
export * from './utils';
|
|
6
|
+
export const CustomOnChangePlugin = ({ placeholder }) => {
|
|
7
|
+
const [editor] = useLexicalComposerContext();
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
return mergeRegister(editor.registerUpdateListener((_listener) => {
|
|
10
|
+
setNodePlaceholderFromSelection(editor, placeholder);
|
|
11
|
+
}));
|
|
12
|
+
}, [editor]);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
setNodePlaceholderFromState(editor, placeholder);
|
|
15
|
+
}, []);
|
|
16
|
+
return null;
|
|
17
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
.lexical-node-placeholder:has(br):not(:has(span))::before {
|
|
2
|
+
position: absolute;
|
|
3
|
+
content: attr(data-placeholder);
|
|
4
|
+
color: #999;
|
|
5
|
+
opacity: 0.4;
|
|
6
|
+
/* no wrap */
|
|
7
|
+
overflow-x: hidden;
|
|
8
|
+
white-space: nowrap;
|
|
9
|
+
width: -webkit-fill-available;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.lexical-node-template > *:not(:first-child) {
|
|
13
|
+
opacity: 0.4;
|
|
14
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { LexicalEditor, RangeSelection, LexicalNode } from 'lexical';
|
|
2
|
+
import './styles.css';
|
|
3
|
+
export declare const PLACEHOLDER_EMPTY_TEXT = "Press '/' for commands...";
|
|
4
|
+
export declare const PLACEHOLDER_CLASS_NAME = "lexical-node-placeholder";
|
|
5
|
+
export declare const TEMPLATE_CLASS_NAME = "lexical-node-template";
|
|
6
|
+
export declare const isHtmlHeadingElement: (el: HTMLElement) => el is HTMLHeadingElement;
|
|
7
|
+
export declare const getNodePlaceholder: (lexicalNode: LexicalNode, emptyPlaceholder: string) => string | undefined;
|
|
8
|
+
export declare const isFocusEditor: () => boolean;
|
|
9
|
+
export declare const removeHtmlElementPlaceholder: (htmlElement: HTMLElement) => void;
|
|
10
|
+
export declare const setPlaceholderOnSelection: ({ selection, editor, placeholder, }: {
|
|
11
|
+
selection: RangeSelection;
|
|
12
|
+
editor: LexicalEditor;
|
|
13
|
+
placeholder?: any;
|
|
14
|
+
}) => void;
|
|
15
|
+
export declare const tryToSetNodePlaceholder: ({ htmlElement, node, emptyPlaceholder, }: {
|
|
16
|
+
htmlElement: HTMLElement | null;
|
|
17
|
+
node: LexicalNode | null;
|
|
18
|
+
emptyPlaceholder?: string | undefined;
|
|
19
|
+
}) => void;
|
|
20
|
+
export declare const setNodePlaceholderFromSelection: (editor: LexicalEditor, placeholder: any) => void;
|
|
21
|
+
export declare const setNodePlaceholderFromState: (editor: LexicalEditor, placeholder: any) => void;
|
|
22
|
+
export declare const stopAddPlaceholder: ({ children, placeholder }: {
|
|
23
|
+
children: any[];
|
|
24
|
+
placeholder?: any;
|
|
25
|
+
}) => any;
|
|
26
|
+
export declare const getAllLexicalChildren: (editor: LexicalEditor) => {
|
|
27
|
+
key: string;
|
|
28
|
+
node: LexicalNode;
|
|
29
|
+
htmlElement: HTMLElement | null;
|
|
30
|
+
}[];
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { $getSelection, $isRangeSelection, $isParagraphNode, } from 'lexical';
|
|
2
|
+
import { $isHeadingNode } from '@lexical/rich-text';
|
|
3
|
+
import { $dfs } from '@lexical/utils';
|
|
4
|
+
import './styles.css';
|
|
5
|
+
export const PLACEHOLDER_EMPTY_TEXT = "Press '/' for commands...";
|
|
6
|
+
export const PLACEHOLDER_CLASS_NAME = 'lexical-node-placeholder';
|
|
7
|
+
export const TEMPLATE_CLASS_NAME = 'lexical-node-template';
|
|
8
|
+
export const isHtmlHeadingElement = (el) => {
|
|
9
|
+
return el instanceof HTMLHeadingElement;
|
|
10
|
+
};
|
|
11
|
+
export const getNodePlaceholder = (lexicalNode, emptyPlaceholder) => {
|
|
12
|
+
let placeholder;
|
|
13
|
+
if ($isHeadingNode(lexicalNode)) {
|
|
14
|
+
const tag = lexicalNode.getTag();
|
|
15
|
+
const headerTagMap = {
|
|
16
|
+
h1: '1',
|
|
17
|
+
h2: '2',
|
|
18
|
+
h3: '3',
|
|
19
|
+
h4: '4',
|
|
20
|
+
h5: '5',
|
|
21
|
+
h6: '6',
|
|
22
|
+
};
|
|
23
|
+
placeholder = `Heading ${headerTagMap[tag]}`;
|
|
24
|
+
}
|
|
25
|
+
if ($isParagraphNode(lexicalNode) && emptyPlaceholder) {
|
|
26
|
+
// Like in https://www.notion.so/
|
|
27
|
+
placeholder = emptyPlaceholder;
|
|
28
|
+
}
|
|
29
|
+
return placeholder;
|
|
30
|
+
};
|
|
31
|
+
export const isFocusEditor = () => {
|
|
32
|
+
return !!document.activeElement?.classList?.contains?.('be-editable');
|
|
33
|
+
};
|
|
34
|
+
export const removeHtmlElementPlaceholder = (htmlElement) => {
|
|
35
|
+
if (isHtmlHeadingElement(htmlElement)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const { classList } = htmlElement;
|
|
39
|
+
if (classList.length && classList.contains(PLACEHOLDER_CLASS_NAME)) {
|
|
40
|
+
classList.remove(PLACEHOLDER_CLASS_NAME);
|
|
41
|
+
htmlElement?.removeAttribute('data-placeholder');
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
export const setPlaceholderOnSelection = ({ selection, editor, placeholder, }) => {
|
|
45
|
+
/**
|
|
46
|
+
* 1. Get all lexical nodes as HTML elements
|
|
47
|
+
*/
|
|
48
|
+
const children = getAllLexicalChildren(editor);
|
|
49
|
+
/**
|
|
50
|
+
* 2. Remove "placeholder" class if it was added before
|
|
51
|
+
*/
|
|
52
|
+
children.forEach(({ htmlElement }) => {
|
|
53
|
+
if (!htmlElement)
|
|
54
|
+
return;
|
|
55
|
+
removeHtmlElementPlaceholder(htmlElement);
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* 3. Do nothing if there is only one lexical child,
|
|
59
|
+
* because we already have a placeholder
|
|
60
|
+
* in <RichTextPlugin/> component
|
|
61
|
+
* With on exception: If we converted default node to the "Heading"
|
|
62
|
+
*/
|
|
63
|
+
if (stopAddPlaceholder({
|
|
64
|
+
children,
|
|
65
|
+
placeholder,
|
|
66
|
+
})) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 4. Get "PointType" object, that contain Nodes data
|
|
71
|
+
* (that is selected)
|
|
72
|
+
* {
|
|
73
|
+
* key: "5", <- Node's key
|
|
74
|
+
* offset: 7,
|
|
75
|
+
* type: "text"
|
|
76
|
+
* }
|
|
77
|
+
*/
|
|
78
|
+
const { anchor } = selection;
|
|
79
|
+
/**
|
|
80
|
+
* 5. Get placeholder for type ('heading'/'paragraph'/etc...)
|
|
81
|
+
*/
|
|
82
|
+
tryToSetNodePlaceholder({
|
|
83
|
+
htmlElement: editor.getElementByKey(anchor.key),
|
|
84
|
+
node: anchor.getNode(),
|
|
85
|
+
emptyPlaceholder: PLACEHOLDER_EMPTY_TEXT,
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
export const tryToSetNodePlaceholder = ({ htmlElement, node, emptyPlaceholder = '', }) => {
|
|
89
|
+
if (htmlElement && node) {
|
|
90
|
+
removeHtmlElementPlaceholder(htmlElement);
|
|
91
|
+
const nodePlaceholder = getNodePlaceholder(node, emptyPlaceholder);
|
|
92
|
+
if (nodePlaceholder) {
|
|
93
|
+
htmlElement?.classList.add(PLACEHOLDER_CLASS_NAME);
|
|
94
|
+
htmlElement?.setAttribute('data-placeholder', nodePlaceholder);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
// only setting by selection
|
|
99
|
+
export const setNodePlaceholderFromSelection = (editor, placeholder) => {
|
|
100
|
+
if (!editor.isEditable()) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
editor.getEditorState().read(() => {
|
|
104
|
+
const selection = $getSelection();
|
|
105
|
+
if (!$isRangeSelection(selection)) {
|
|
106
|
+
// Do nothing if user selected a text fragment
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
setPlaceholderOnSelection({ selection, editor, placeholder });
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
// global setting by editor
|
|
113
|
+
export const setNodePlaceholderFromState = (editor, placeholder) => {
|
|
114
|
+
if (!editor.isEditable()) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
editor.getEditorState().read(() => {
|
|
118
|
+
const children = getAllLexicalChildren(editor);
|
|
119
|
+
children.forEach(({ htmlElement, node }) => {
|
|
120
|
+
tryToSetNodePlaceholder({
|
|
121
|
+
htmlElement,
|
|
122
|
+
node,
|
|
123
|
+
// not set emptyPlaceholder, avoid override placeholder
|
|
124
|
+
emptyPlaceholder: '',
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
// set current selection placeholder
|
|
128
|
+
setNodePlaceholderFromSelection(editor, placeholder);
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
export const stopAddPlaceholder = ({ children, placeholder }) => {
|
|
132
|
+
const [root, ...restChildren] = children;
|
|
133
|
+
const rootContentIsEmpty = root?.node?.getTextContent()?.length === 0;
|
|
134
|
+
const withoutHeading = !restChildren?.find(({ node }) => $isHeadingNode(node));
|
|
135
|
+
// if had placeholder and content is empty and without heading, do nothing
|
|
136
|
+
return placeholder && rootContentIsEmpty && withoutHeading;
|
|
137
|
+
};
|
|
138
|
+
export const getAllLexicalChildren = (editor) => {
|
|
139
|
+
const childrenKeys = editor.getEditorState().read(() => $dfs());
|
|
140
|
+
return childrenKeys?.map(({ node }) => {
|
|
141
|
+
const key = node.getKey();
|
|
142
|
+
return {
|
|
143
|
+
key,
|
|
144
|
+
node,
|
|
145
|
+
htmlElement: editor.getElementByKey(key),
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { LexicalEditor } from 'lexical';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
interface ContextValue {
|
|
4
|
+
editor: LexicalEditor | null;
|
|
5
|
+
setEditor: (editor: LexicalEditor | null) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare const EditorHolderContext: import("react").Context<ContextValue | null>;
|
|
8
|
+
export declare function useEditorHolder(): ContextValue | null;
|
|
9
|
+
export declare function EditorHolderProvider({ children }: {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export declare function useEditor(): LexicalEditor | null;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useMemo, useState } from 'react';
|
|
3
|
+
export const EditorHolderContext = createContext(null);
|
|
4
|
+
export function useEditorHolder() {
|
|
5
|
+
return useContext(EditorHolderContext);
|
|
6
|
+
}
|
|
7
|
+
export function EditorHolderProvider({ children }) {
|
|
8
|
+
const [editor, setEditor] = useState(null);
|
|
9
|
+
const value = useMemo(() => ({ editor, setEditor }), [editor]);
|
|
10
|
+
return _jsx(EditorHolderContext.Provider, { value: value, children: children });
|
|
11
|
+
}
|
|
12
|
+
export function useEditor() {
|
|
13
|
+
const holder = useEditorHolder();
|
|
14
|
+
return holder?.editor ?? null;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function EditorHolderPlugin(): null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { useEditorHolder } from './EditorHolderContext';
|
|
4
|
+
export function EditorHolderPlugin() {
|
|
5
|
+
const [editor] = useLexicalComposerContext();
|
|
6
|
+
const holder = useEditorHolder();
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
holder?.setEditor(editor);
|
|
9
|
+
}, [editor]);
|
|
10
|
+
return null;
|
|
11
|
+
}
|