@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,16 @@
|
|
|
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 { LexicalEditor } from 'lexical';
|
|
9
|
+
import { OverflowNode } from '@lexical/overflow';
|
|
10
|
+
type OptionalProps = {
|
|
11
|
+
remainingCharacters?: (characters: number) => void;
|
|
12
|
+
strlen?: (input: string) => number;
|
|
13
|
+
};
|
|
14
|
+
export declare function useCharacterLimit(editor: LexicalEditor, maxCharacters: number, optional?: OptionalProps): void;
|
|
15
|
+
export declare function $mergePrevious(overflowNode: OverflowNode): void;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,208 @@
|
|
|
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 { $createOverflowNode, $isOverflowNode, OverflowNode } from '@lexical/overflow';
|
|
9
|
+
import { $rootTextContent } from '@lexical/text';
|
|
10
|
+
import { $dfs, $unwrapNode, mergeRegister } from '@lexical/utils';
|
|
11
|
+
import { $getSelection, $isElementNode, $isLeafNode, $isRangeSelection, $isTextNode, $setSelection, COMMAND_PRIORITY_LOW, DELETE_CHARACTER_COMMAND, } from 'lexical';
|
|
12
|
+
import { useEffect } from 'react';
|
|
13
|
+
import invariant from '../../shared/invariant';
|
|
14
|
+
export function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({})) {
|
|
15
|
+
const { strlen = (input) => input.length,
|
|
16
|
+
// UTF-16
|
|
17
|
+
remainingCharacters = () => { }, } = optional;
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!editor.hasNodes([OverflowNode])) {
|
|
20
|
+
invariant(false, 'useCharacterLimit: OverflowNode not registered on editor');
|
|
21
|
+
}
|
|
22
|
+
}, [editor]);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
let text = editor.getEditorState().read($rootTextContent);
|
|
25
|
+
let lastComputedTextLength = 0;
|
|
26
|
+
return mergeRegister(editor.registerTextContentListener((currentText) => {
|
|
27
|
+
text = currentText;
|
|
28
|
+
}), editor.registerUpdateListener((payload) => {
|
|
29
|
+
if (!payload)
|
|
30
|
+
return;
|
|
31
|
+
const { dirtyLeaves, dirtyElements } = payload;
|
|
32
|
+
const isComposing = editor.isComposing();
|
|
33
|
+
const hasContentChanges = dirtyLeaves.size > 0 || dirtyElements.size > 0;
|
|
34
|
+
if (isComposing || !hasContentChanges) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const textLength = strlen(text);
|
|
38
|
+
const textLengthAboveThreshold = textLength > maxCharacters || (lastComputedTextLength !== null && lastComputedTextLength > maxCharacters);
|
|
39
|
+
const diff = maxCharacters - textLength;
|
|
40
|
+
remainingCharacters(diff);
|
|
41
|
+
if (lastComputedTextLength === null || textLengthAboveThreshold) {
|
|
42
|
+
const offset = findOffset(text, maxCharacters, strlen);
|
|
43
|
+
editor.update(() => {
|
|
44
|
+
$wrapOverflowedNodes(offset);
|
|
45
|
+
}, {
|
|
46
|
+
tag: 'history-merge',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
lastComputedTextLength = textLength;
|
|
50
|
+
}), editor.registerCommand(DELETE_CHARACTER_COMMAND, (isBackward) => {
|
|
51
|
+
const selection = $getSelection();
|
|
52
|
+
if (!$isRangeSelection(selection)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
const anchorNode = selection.anchor.getNode();
|
|
56
|
+
const overflow = anchorNode.getParent();
|
|
57
|
+
const overflowParent = overflow ? overflow.getParent() : null;
|
|
58
|
+
const parentNext = overflowParent ? overflowParent.getNextSibling() : null;
|
|
59
|
+
selection.deleteCharacter(isBackward);
|
|
60
|
+
if (overflowParent && overflowParent.isEmpty()) {
|
|
61
|
+
overflowParent.remove();
|
|
62
|
+
}
|
|
63
|
+
else if ($isElementNode(parentNext) && parentNext.isEmpty()) {
|
|
64
|
+
parentNext.remove();
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}, COMMAND_PRIORITY_LOW));
|
|
68
|
+
}, [editor, maxCharacters, remainingCharacters, strlen]);
|
|
69
|
+
}
|
|
70
|
+
function findOffset(text, maxCharacters, strlen) {
|
|
71
|
+
const { Segmenter } = Intl;
|
|
72
|
+
let offsetUtf16 = 0;
|
|
73
|
+
let offset = 0;
|
|
74
|
+
if (typeof Segmenter === 'function') {
|
|
75
|
+
const segmenter = new Segmenter();
|
|
76
|
+
const graphemes = segmenter.segment(text);
|
|
77
|
+
for (const { segment: grapheme } of graphemes) {
|
|
78
|
+
const nextOffset = offset + strlen(grapheme);
|
|
79
|
+
if (nextOffset > maxCharacters) {
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
offset = nextOffset;
|
|
83
|
+
offsetUtf16 += grapheme.length;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
const codepoints = Array.from(text);
|
|
88
|
+
const codepointsLength = codepoints.length;
|
|
89
|
+
for (let i = 0; i < codepointsLength; i++) {
|
|
90
|
+
const codepoint = codepoints[i];
|
|
91
|
+
const nextOffset = offset + strlen(codepoint);
|
|
92
|
+
if (nextOffset > maxCharacters) {
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
offset = nextOffset;
|
|
96
|
+
offsetUtf16 += codepoint.length;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return offsetUtf16;
|
|
100
|
+
}
|
|
101
|
+
function $wrapOverflowedNodes(offset) {
|
|
102
|
+
const dfsNodes = $dfs().filter(Boolean);
|
|
103
|
+
const dfsNodesLength = dfsNodes.length;
|
|
104
|
+
let accumulatedLength = 0;
|
|
105
|
+
for (let i = 0; i < dfsNodesLength; i += 1) {
|
|
106
|
+
const { node } = dfsNodes[i];
|
|
107
|
+
if ($isOverflowNode(node)) {
|
|
108
|
+
const previousLength = accumulatedLength;
|
|
109
|
+
const nextLength = accumulatedLength + node.getTextContentSize();
|
|
110
|
+
if (nextLength <= offset) {
|
|
111
|
+
const parent = node.getParent();
|
|
112
|
+
const previousSibling = node.getPreviousSibling();
|
|
113
|
+
const nextSibling = node.getNextSibling();
|
|
114
|
+
$unwrapNode(node);
|
|
115
|
+
const selection = $getSelection();
|
|
116
|
+
// Restore selection when the overflow children are removed
|
|
117
|
+
if ($isRangeSelection(selection) &&
|
|
118
|
+
(!selection.anchor.getNode().isAttached() || !selection.focus.getNode().isAttached())) {
|
|
119
|
+
if ($isTextNode(previousSibling)) {
|
|
120
|
+
previousSibling.select();
|
|
121
|
+
}
|
|
122
|
+
else if ($isTextNode(nextSibling)) {
|
|
123
|
+
nextSibling.select();
|
|
124
|
+
}
|
|
125
|
+
else if (parent !== null) {
|
|
126
|
+
parent.select();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else if (previousLength < offset) {
|
|
131
|
+
const descendant = node.getFirstDescendant();
|
|
132
|
+
const descendantLength = descendant !== null ? descendant.getTextContentSize() : 0;
|
|
133
|
+
const previousPlusDescendantLength = previousLength + descendantLength;
|
|
134
|
+
// For simple text we can redimension the overflow into a smaller and more accurate
|
|
135
|
+
// container
|
|
136
|
+
const firstDescendantIsSimpleText = $isTextNode(descendant) && descendant.isSimpleText();
|
|
137
|
+
const firstDescendantDoesNotOverflow = previousPlusDescendantLength <= offset;
|
|
138
|
+
if (firstDescendantIsSimpleText || firstDescendantDoesNotOverflow) {
|
|
139
|
+
$unwrapNode(node);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else if ($isLeafNode(node)) {
|
|
144
|
+
const previousAccumulatedLength = accumulatedLength;
|
|
145
|
+
accumulatedLength += node.getTextContentSize();
|
|
146
|
+
if (accumulatedLength > offset && !$isOverflowNode(node.getParent())) {
|
|
147
|
+
const previousSelection = $getSelection();
|
|
148
|
+
let overflowNode;
|
|
149
|
+
// For simple text we can improve the limit accuracy by splitting the TextNode
|
|
150
|
+
// on the split point
|
|
151
|
+
if (previousAccumulatedLength < offset && $isTextNode(node) && node.isSimpleText()) {
|
|
152
|
+
const [, overflowedText] = node.splitText(offset - previousAccumulatedLength);
|
|
153
|
+
overflowNode = $wrapNode(overflowedText);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
overflowNode = $wrapNode(node);
|
|
157
|
+
}
|
|
158
|
+
if (previousSelection !== null) {
|
|
159
|
+
$setSelection(previousSelection);
|
|
160
|
+
}
|
|
161
|
+
$mergePrevious(overflowNode);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function $wrapNode(node) {
|
|
167
|
+
const overflowNode = $createOverflowNode();
|
|
168
|
+
node.replace(overflowNode);
|
|
169
|
+
overflowNode.append(node);
|
|
170
|
+
return overflowNode;
|
|
171
|
+
}
|
|
172
|
+
export function $mergePrevious(overflowNode) {
|
|
173
|
+
const previousNode = overflowNode.getPreviousSibling();
|
|
174
|
+
if (!$isOverflowNode(previousNode)) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const firstChild = overflowNode.getFirstChild();
|
|
178
|
+
const previousNodeChildren = previousNode.getChildren();
|
|
179
|
+
const previousNodeChildrenLength = previousNodeChildren.length;
|
|
180
|
+
if (firstChild === null) {
|
|
181
|
+
overflowNode.append(...previousNodeChildren);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
for (let i = 0; i < previousNodeChildrenLength; i++) {
|
|
185
|
+
firstChild.insertBefore(previousNodeChildren[i]);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const selection = $getSelection();
|
|
189
|
+
if ($isRangeSelection(selection)) {
|
|
190
|
+
const { anchor } = selection;
|
|
191
|
+
const anchorNode = anchor.getNode();
|
|
192
|
+
const { focus } = selection;
|
|
193
|
+
const focusNode = anchor.getNode();
|
|
194
|
+
if (anchorNode.is(previousNode)) {
|
|
195
|
+
anchor.set(overflowNode.getKey(), anchor.offset, 'element');
|
|
196
|
+
}
|
|
197
|
+
else if (anchorNode.is(overflowNode)) {
|
|
198
|
+
anchor.set(overflowNode.getKey(), previousNodeChildrenLength + anchor.offset, 'element');
|
|
199
|
+
}
|
|
200
|
+
if (focusNode.is(previousNode)) {
|
|
201
|
+
focus.set(overflowNode.getKey(), focus.offset, 'element');
|
|
202
|
+
}
|
|
203
|
+
else if (focusNode.is(overflowNode)) {
|
|
204
|
+
focus.set(overflowNode.getKey(), previousNodeChildrenLength + focus.offset, 'element');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
previousNode.remove();
|
|
208
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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 { HistoryState } from './history';
|
|
9
|
+
export { createEmptyHistoryState } from './history';
|
|
10
|
+
export type { HistoryState };
|
|
11
|
+
export declare function HistoryPlugin({ delay, externalHistoryState, }: {
|
|
12
|
+
delay?: number;
|
|
13
|
+
externalHistoryState?: HistoryState;
|
|
14
|
+
}): null;
|
|
@@ -0,0 +1,15 @@
|
|
|
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 { useHistory } from './useHistory';
|
|
10
|
+
export { createEmptyHistoryState } from './history';
|
|
11
|
+
export function HistoryPlugin({ delay, externalHistoryState, }) {
|
|
12
|
+
const [editor] = useLexicalComposerContext();
|
|
13
|
+
useHistory(editor, externalHistoryState, delay);
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
@@ -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 type { EditorState, LexicalEditor } from 'lexical';
|
|
9
|
+
import { ReadonlySignal } from '@lexical/extension';
|
|
10
|
+
export type HistoryStateEntry = {
|
|
11
|
+
editor: LexicalEditor;
|
|
12
|
+
editorState: EditorState;
|
|
13
|
+
};
|
|
14
|
+
export type HistoryState = {
|
|
15
|
+
current: null | HistoryStateEntry;
|
|
16
|
+
redoStack: Array<HistoryStateEntry>;
|
|
17
|
+
undoStack: Array<HistoryStateEntry>;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Registers necessary listeners to manage undo/redo history stack and related editor commands.
|
|
21
|
+
* It returns `unregister` callback that cleans up all listeners and should be called on editor unmount.
|
|
22
|
+
* @param editor - The lexical editor.
|
|
23
|
+
* @param historyState - The history state, containing the current state and the undo/redo stack.
|
|
24
|
+
* @param delay - The time (in milliseconds) the editor should delay generating a new history stack,
|
|
25
|
+
* instead of merging the current changes with the current stack.
|
|
26
|
+
* @returns The listeners cleanup callback function.
|
|
27
|
+
*/
|
|
28
|
+
export declare function registerHistory(editor: LexicalEditor, historyState: HistoryState, delay: number | ReadonlySignal<number>): () => void;
|
|
29
|
+
/**
|
|
30
|
+
* Creates an empty history state.
|
|
31
|
+
* @returns - The empty history state, as an object.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createEmptyHistoryState(): HistoryState;
|
|
34
|
+
export interface HistoryConfig {
|
|
35
|
+
/**
|
|
36
|
+
* The time (in milliseconds) the editor should delay generating a new history stack,
|
|
37
|
+
* instead of merging the current changes with the current stack. The default is 300ms.
|
|
38
|
+
*/
|
|
39
|
+
delay: number;
|
|
40
|
+
/**
|
|
41
|
+
* The initial history state, the default is {@link createEmptyHistoryState}.
|
|
42
|
+
*/
|
|
43
|
+
createInitialHistoryState: (editor: LexicalEditor) => HistoryState;
|
|
44
|
+
/**
|
|
45
|
+
* Whether history is disabled or not
|
|
46
|
+
*/
|
|
47
|
+
disabled: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Registers necessary listeners to manage undo/redo history stack and related
|
|
51
|
+
* editor commands, via the \@lexical/history module.
|
|
52
|
+
*/
|
|
53
|
+
export declare const HistoryExtension: import("lexical").LexicalExtension<HistoryConfig, "@lexical/history/History", import("@lexical/extension").NamedSignalsOutput<{
|
|
54
|
+
delay: number;
|
|
55
|
+
disabled: boolean;
|
|
56
|
+
historyState: HistoryState;
|
|
57
|
+
}>, unknown>;
|
|
58
|
+
/**
|
|
59
|
+
* Registers necessary listeners to manage undo/redo history stack and related
|
|
60
|
+
* editor commands, via the \@lexical/history module, only if the parent editor
|
|
61
|
+
* has a history plugin implementation.
|
|
62
|
+
*/
|
|
63
|
+
export declare const SharedHistoryExtension: import("lexical").LexicalExtension<import("lexical").ExtensionConfigBase, "@lexical/history/SharedHistory", unknown, unknown>;
|
|
@@ -0,0 +1,351 @@
|
|
|
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 { batch, effect, getPeerDependencyFromEditor, namedSignals } from '@lexical/extension';
|
|
9
|
+
import { mergeRegister } from '@lexical/utils';
|
|
10
|
+
import { $isRangeSelection, $isRootNode, $isTextNode, CAN_REDO_COMMAND, CAN_UNDO_COMMAND, CLEAR_EDITOR_COMMAND, CLEAR_HISTORY_COMMAND, COMMAND_PRIORITY_EDITOR, configExtension, defineExtension, HISTORIC_TAG, HISTORY_MERGE_TAG, HISTORY_PUSH_TAG, REDO_COMMAND, safeCast, UNDO_COMMAND, } from 'lexical';
|
|
11
|
+
const HISTORY_MERGE = 0;
|
|
12
|
+
const HISTORY_PUSH = 1;
|
|
13
|
+
const DISCARD_HISTORY_CANDIDATE = 2;
|
|
14
|
+
const OTHER = 0;
|
|
15
|
+
const COMPOSING_CHARACTER = 1;
|
|
16
|
+
const INSERT_CHARACTER_AFTER_SELECTION = 2;
|
|
17
|
+
const DELETE_CHARACTER_BEFORE_SELECTION = 3;
|
|
18
|
+
const DELETE_CHARACTER_AFTER_SELECTION = 4;
|
|
19
|
+
function getDirtyNodes(editorState, dirtyLeaves, dirtyElements) {
|
|
20
|
+
const nodeMap = editorState._nodeMap;
|
|
21
|
+
const nodes = [];
|
|
22
|
+
for (const dirtyLeafKey of dirtyLeaves) {
|
|
23
|
+
const dirtyLeaf = nodeMap.get(dirtyLeafKey);
|
|
24
|
+
if (dirtyLeaf !== undefined) {
|
|
25
|
+
nodes.push(dirtyLeaf);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
for (const [dirtyElementKey, intentionallyMarkedAsDirty] of dirtyElements) {
|
|
29
|
+
if (!intentionallyMarkedAsDirty) {
|
|
30
|
+
// eslint-disable-next-line no-continue
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const dirtyElement = nodeMap.get(dirtyElementKey);
|
|
34
|
+
if (dirtyElement !== undefined && !$isRootNode(dirtyElement)) {
|
|
35
|
+
nodes.push(dirtyElement);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return nodes;
|
|
39
|
+
}
|
|
40
|
+
function getChangeType(prevEditorState, nextEditorState, dirtyLeavesSet, dirtyElementsSet, isComposing) {
|
|
41
|
+
if (prevEditorState === null || (dirtyLeavesSet.size === 0 && dirtyElementsSet.size === 0 && !isComposing)) {
|
|
42
|
+
return OTHER;
|
|
43
|
+
}
|
|
44
|
+
const nextSelection = nextEditorState._selection;
|
|
45
|
+
const prevSelection = prevEditorState._selection;
|
|
46
|
+
if (isComposing) {
|
|
47
|
+
return COMPOSING_CHARACTER;
|
|
48
|
+
}
|
|
49
|
+
if (!$isRangeSelection(nextSelection) ||
|
|
50
|
+
!$isRangeSelection(prevSelection) ||
|
|
51
|
+
!prevSelection.isCollapsed() ||
|
|
52
|
+
!nextSelection.isCollapsed()) {
|
|
53
|
+
return OTHER;
|
|
54
|
+
}
|
|
55
|
+
const dirtyNodes = getDirtyNodes(nextEditorState, dirtyLeavesSet, dirtyElementsSet);
|
|
56
|
+
if (dirtyNodes.length === 0) {
|
|
57
|
+
return OTHER;
|
|
58
|
+
}
|
|
59
|
+
// Catching the case when inserting new text node into an element (e.g. first char in paragraph/list),
|
|
60
|
+
// or after existing node.
|
|
61
|
+
if (dirtyNodes.length > 1) {
|
|
62
|
+
const nextNodeMap = nextEditorState._nodeMap;
|
|
63
|
+
const nextAnchorNode = nextNodeMap.get(nextSelection.anchor.key);
|
|
64
|
+
const prevAnchorNode = nextNodeMap.get(prevSelection.anchor.key);
|
|
65
|
+
if (nextAnchorNode &&
|
|
66
|
+
prevAnchorNode &&
|
|
67
|
+
!prevEditorState._nodeMap.has(nextAnchorNode.__key) &&
|
|
68
|
+
$isTextNode(nextAnchorNode) &&
|
|
69
|
+
nextAnchorNode.__text.length === 1 &&
|
|
70
|
+
nextSelection.anchor.offset === 1) {
|
|
71
|
+
return INSERT_CHARACTER_AFTER_SELECTION;
|
|
72
|
+
}
|
|
73
|
+
return OTHER;
|
|
74
|
+
}
|
|
75
|
+
const nextDirtyNode = dirtyNodes[0];
|
|
76
|
+
const prevDirtyNode = prevEditorState._nodeMap.get(nextDirtyNode.__key);
|
|
77
|
+
if (!$isTextNode(prevDirtyNode) || !$isTextNode(nextDirtyNode) || prevDirtyNode.__mode !== nextDirtyNode.__mode) {
|
|
78
|
+
return OTHER;
|
|
79
|
+
}
|
|
80
|
+
const prevText = prevDirtyNode.__text;
|
|
81
|
+
const nextText = nextDirtyNode.__text;
|
|
82
|
+
if (prevText === nextText) {
|
|
83
|
+
return OTHER;
|
|
84
|
+
}
|
|
85
|
+
const nextAnchor = nextSelection.anchor;
|
|
86
|
+
const prevAnchor = prevSelection.anchor;
|
|
87
|
+
if (nextAnchor.key !== prevAnchor.key || nextAnchor.type !== 'text') {
|
|
88
|
+
return OTHER;
|
|
89
|
+
}
|
|
90
|
+
const nextAnchorOffset = nextAnchor.offset;
|
|
91
|
+
const prevAnchorOffset = prevAnchor.offset;
|
|
92
|
+
const textDiff = nextText.length - prevText.length;
|
|
93
|
+
if (textDiff === 1 && prevAnchorOffset === nextAnchorOffset - 1) {
|
|
94
|
+
return INSERT_CHARACTER_AFTER_SELECTION;
|
|
95
|
+
}
|
|
96
|
+
if (textDiff === -1 && prevAnchorOffset === nextAnchorOffset + 1) {
|
|
97
|
+
return DELETE_CHARACTER_BEFORE_SELECTION;
|
|
98
|
+
}
|
|
99
|
+
if (textDiff === -1 && prevAnchorOffset === nextAnchorOffset) {
|
|
100
|
+
return DELETE_CHARACTER_AFTER_SELECTION;
|
|
101
|
+
}
|
|
102
|
+
return OTHER;
|
|
103
|
+
}
|
|
104
|
+
function isTextNodeUnchanged(key, prevEditorState, nextEditorState) {
|
|
105
|
+
const prevNode = prevEditorState._nodeMap.get(key);
|
|
106
|
+
const nextNode = nextEditorState._nodeMap.get(key);
|
|
107
|
+
const prevSelection = prevEditorState._selection;
|
|
108
|
+
const nextSelection = nextEditorState._selection;
|
|
109
|
+
const isDeletingLine = $isRangeSelection(prevSelection) &&
|
|
110
|
+
$isRangeSelection(nextSelection) &&
|
|
111
|
+
prevSelection.anchor.type === 'element' &&
|
|
112
|
+
prevSelection.focus.type === 'element' &&
|
|
113
|
+
nextSelection.anchor.type === 'text' &&
|
|
114
|
+
nextSelection.focus.type === 'text';
|
|
115
|
+
if (!isDeletingLine && $isTextNode(prevNode) && $isTextNode(nextNode) && prevNode.__parent === nextNode.__parent) {
|
|
116
|
+
// This has the assumption that object key order won't change if the
|
|
117
|
+
// content did not change, which should normally be safe given
|
|
118
|
+
// the manner in which nodes and exportJSON are typically implemented.
|
|
119
|
+
return (JSON.stringify(prevEditorState.read(() => prevNode.exportJSON())) ===
|
|
120
|
+
JSON.stringify(nextEditorState.read(() => nextNode.exportJSON())));
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
function createMergeActionGetter(editor, delayOrStore) {
|
|
125
|
+
let prevChangeTime = Date.now();
|
|
126
|
+
let prevChangeType = OTHER;
|
|
127
|
+
return (prevEditorState, nextEditorState, currentHistoryEntry, dirtyLeaves, dirtyElements, tags) => {
|
|
128
|
+
const changeTime = Date.now();
|
|
129
|
+
// If applying changes from history stack there's no need
|
|
130
|
+
// to run history logic again, as history entries already calculated
|
|
131
|
+
if (tags.has(HISTORIC_TAG)) {
|
|
132
|
+
prevChangeType = OTHER;
|
|
133
|
+
prevChangeTime = changeTime;
|
|
134
|
+
return DISCARD_HISTORY_CANDIDATE;
|
|
135
|
+
}
|
|
136
|
+
const changeType = getChangeType(prevEditorState, nextEditorState, dirtyLeaves, dirtyElements, editor.isComposing());
|
|
137
|
+
const mergeAction = (() => {
|
|
138
|
+
const isSameEditor = currentHistoryEntry === null || currentHistoryEntry.editor === editor;
|
|
139
|
+
const shouldPushHistory = tags.has(HISTORY_PUSH_TAG);
|
|
140
|
+
const shouldMergeHistory = !shouldPushHistory && isSameEditor && tags.has(HISTORY_MERGE_TAG);
|
|
141
|
+
if (shouldMergeHistory) {
|
|
142
|
+
return HISTORY_MERGE;
|
|
143
|
+
}
|
|
144
|
+
if (prevEditorState === null) {
|
|
145
|
+
return HISTORY_PUSH;
|
|
146
|
+
}
|
|
147
|
+
const selection = nextEditorState._selection;
|
|
148
|
+
const hasDirtyNodes = dirtyLeaves.size > 0 || dirtyElements.size > 0;
|
|
149
|
+
if (!hasDirtyNodes) {
|
|
150
|
+
if (selection !== null) {
|
|
151
|
+
return HISTORY_MERGE;
|
|
152
|
+
}
|
|
153
|
+
return DISCARD_HISTORY_CANDIDATE;
|
|
154
|
+
}
|
|
155
|
+
const delay = typeof delayOrStore === 'number' ? delayOrStore : delayOrStore.peek();
|
|
156
|
+
if (shouldPushHistory === false &&
|
|
157
|
+
changeType !== OTHER &&
|
|
158
|
+
changeType === prevChangeType &&
|
|
159
|
+
changeTime < prevChangeTime + delay &&
|
|
160
|
+
isSameEditor) {
|
|
161
|
+
return HISTORY_MERGE;
|
|
162
|
+
}
|
|
163
|
+
// A single node might have been marked as dirty, but not have changed
|
|
164
|
+
// due to some node transform reverting the change.
|
|
165
|
+
if (dirtyLeaves.size === 1) {
|
|
166
|
+
const dirtyLeafKey = Array.from(dirtyLeaves)[0];
|
|
167
|
+
if (isTextNodeUnchanged(dirtyLeafKey, prevEditorState, nextEditorState)) {
|
|
168
|
+
return HISTORY_MERGE;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return HISTORY_PUSH;
|
|
172
|
+
})();
|
|
173
|
+
prevChangeTime = changeTime;
|
|
174
|
+
prevChangeType = changeType;
|
|
175
|
+
return mergeAction;
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function redo(editor, historyState) {
|
|
179
|
+
const { redoStack } = historyState;
|
|
180
|
+
const { undoStack } = historyState;
|
|
181
|
+
if (redoStack.length !== 0) {
|
|
182
|
+
const { current } = historyState;
|
|
183
|
+
if (current !== null) {
|
|
184
|
+
undoStack.push(current);
|
|
185
|
+
editor.dispatchCommand(CAN_UNDO_COMMAND, true);
|
|
186
|
+
}
|
|
187
|
+
const historyStateEntry = redoStack.pop();
|
|
188
|
+
if (redoStack.length === 0) {
|
|
189
|
+
editor.dispatchCommand(CAN_REDO_COMMAND, false);
|
|
190
|
+
}
|
|
191
|
+
historyState.current = historyStateEntry || null;
|
|
192
|
+
if (historyStateEntry) {
|
|
193
|
+
historyStateEntry.editor.setEditorState(historyStateEntry.editorState, {
|
|
194
|
+
tag: HISTORIC_TAG,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function undo(editor, historyState) {
|
|
200
|
+
const { redoStack } = historyState;
|
|
201
|
+
const { undoStack } = historyState;
|
|
202
|
+
const undoStackLength = undoStack.length;
|
|
203
|
+
if (undoStackLength !== 0) {
|
|
204
|
+
const { current } = historyState;
|
|
205
|
+
const historyStateEntry = undoStack.pop();
|
|
206
|
+
if (current !== null) {
|
|
207
|
+
redoStack.push(current);
|
|
208
|
+
editor.dispatchCommand(CAN_REDO_COMMAND, true);
|
|
209
|
+
}
|
|
210
|
+
if (undoStack.length === 0) {
|
|
211
|
+
editor.dispatchCommand(CAN_UNDO_COMMAND, false);
|
|
212
|
+
}
|
|
213
|
+
historyState.current = historyStateEntry || null;
|
|
214
|
+
if (historyStateEntry) {
|
|
215
|
+
historyStateEntry.editor.setEditorState(historyStateEntry.editorState, {
|
|
216
|
+
tag: HISTORIC_TAG,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function clearHistory(historyState) {
|
|
222
|
+
historyState.undoStack = [];
|
|
223
|
+
historyState.redoStack = [];
|
|
224
|
+
historyState.current = null;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Registers necessary listeners to manage undo/redo history stack and related editor commands.
|
|
228
|
+
* It returns `unregister` callback that cleans up all listeners and should be called on editor unmount.
|
|
229
|
+
* @param editor - The lexical editor.
|
|
230
|
+
* @param historyState - The history state, containing the current state and the undo/redo stack.
|
|
231
|
+
* @param delay - The time (in milliseconds) the editor should delay generating a new history stack,
|
|
232
|
+
* instead of merging the current changes with the current stack.
|
|
233
|
+
* @returns The listeners cleanup callback function.
|
|
234
|
+
*/
|
|
235
|
+
export function registerHistory(editor, historyState, delay) {
|
|
236
|
+
const getMergeAction = createMergeActionGetter(editor, delay);
|
|
237
|
+
const applyChange = (payload) => {
|
|
238
|
+
if (!payload)
|
|
239
|
+
return;
|
|
240
|
+
const { editorState, prevEditorState, dirtyLeaves, dirtyElements, tags } = payload;
|
|
241
|
+
const { current } = historyState;
|
|
242
|
+
const { redoStack } = historyState;
|
|
243
|
+
const { undoStack } = historyState;
|
|
244
|
+
const currentEditorState = current === null ? null : current.editorState;
|
|
245
|
+
if (current !== null && editorState === currentEditorState) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const mergeAction = getMergeAction(prevEditorState, editorState, current, dirtyLeaves, dirtyElements, tags);
|
|
249
|
+
if (mergeAction === HISTORY_PUSH) {
|
|
250
|
+
if (redoStack.length !== 0) {
|
|
251
|
+
historyState.redoStack = [];
|
|
252
|
+
editor.dispatchCommand(CAN_REDO_COMMAND, false);
|
|
253
|
+
}
|
|
254
|
+
if (current !== null) {
|
|
255
|
+
undoStack.push({
|
|
256
|
+
...current,
|
|
257
|
+
});
|
|
258
|
+
editor.dispatchCommand(CAN_UNDO_COMMAND, true);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
else if (mergeAction === DISCARD_HISTORY_CANDIDATE) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
// Else we merge
|
|
265
|
+
historyState.current = {
|
|
266
|
+
editor,
|
|
267
|
+
editorState,
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
const unregister = mergeRegister(editor.registerCommand(UNDO_COMMAND, () => {
|
|
271
|
+
undo(editor, historyState);
|
|
272
|
+
return true;
|
|
273
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(REDO_COMMAND, () => {
|
|
274
|
+
redo(editor, historyState);
|
|
275
|
+
return true;
|
|
276
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(CLEAR_EDITOR_COMMAND, () => {
|
|
277
|
+
clearHistory(historyState);
|
|
278
|
+
return false;
|
|
279
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(CLEAR_HISTORY_COMMAND, () => {
|
|
280
|
+
clearHistory(historyState);
|
|
281
|
+
editor.dispatchCommand(CAN_REDO_COMMAND, false);
|
|
282
|
+
editor.dispatchCommand(CAN_UNDO_COMMAND, false);
|
|
283
|
+
return true;
|
|
284
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerUpdateListener(applyChange));
|
|
285
|
+
return unregister;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Creates an empty history state.
|
|
289
|
+
* @returns - The empty history state, as an object.
|
|
290
|
+
*/
|
|
291
|
+
export function createEmptyHistoryState() {
|
|
292
|
+
return {
|
|
293
|
+
current: null,
|
|
294
|
+
redoStack: [],
|
|
295
|
+
undoStack: [],
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Registers necessary listeners to manage undo/redo history stack and related
|
|
300
|
+
* editor commands, via the \@lexical/history module.
|
|
301
|
+
*/
|
|
302
|
+
export const HistoryExtension = defineExtension({
|
|
303
|
+
build: (editor, { delay, createInitialHistoryState, disabled }) => namedSignals({
|
|
304
|
+
delay,
|
|
305
|
+
disabled,
|
|
306
|
+
historyState: createInitialHistoryState(editor),
|
|
307
|
+
}),
|
|
308
|
+
config: safeCast({
|
|
309
|
+
createInitialHistoryState: createEmptyHistoryState,
|
|
310
|
+
delay: 300,
|
|
311
|
+
disabled: typeof window === 'undefined',
|
|
312
|
+
}),
|
|
313
|
+
name: '@lexical/history/History',
|
|
314
|
+
register: (editor, config, state) => {
|
|
315
|
+
const stores = state.getOutput();
|
|
316
|
+
return effect(() => stores.disabled.value ? undefined : registerHistory(editor, stores.historyState.value, stores.delay));
|
|
317
|
+
},
|
|
318
|
+
});
|
|
319
|
+
function getHistoryPeer(editor) {
|
|
320
|
+
return editor ? getPeerDependencyFromEditor(editor, HistoryExtension.name) : null;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Registers necessary listeners to manage undo/redo history stack and related
|
|
324
|
+
* editor commands, via the \@lexical/history module, only if the parent editor
|
|
325
|
+
* has a history plugin implementation.
|
|
326
|
+
*/
|
|
327
|
+
export const SharedHistoryExtension = defineExtension({
|
|
328
|
+
dependencies: [
|
|
329
|
+
configExtension(HistoryExtension, {
|
|
330
|
+
createInitialHistoryState: () => {
|
|
331
|
+
throw new Error('SharedHistory did not inherit parent history');
|
|
332
|
+
},
|
|
333
|
+
disabled: true,
|
|
334
|
+
}),
|
|
335
|
+
],
|
|
336
|
+
name: '@lexical/history/SharedHistory',
|
|
337
|
+
register(editor, _config, state) {
|
|
338
|
+
const { output } = state.getDependency(HistoryExtension);
|
|
339
|
+
const parentPeer = getHistoryPeer(editor._parentEditor);
|
|
340
|
+
if (!parentPeer) {
|
|
341
|
+
return () => { };
|
|
342
|
+
}
|
|
343
|
+
const parentOutput = parentPeer.output;
|
|
344
|
+
return effect(() => batch(() => {
|
|
345
|
+
output.delay.value = parentOutput.delay.value;
|
|
346
|
+
output.historyState.value = parentOutput.historyState.value;
|
|
347
|
+
// Note that toggling the parent history will force this to be changed
|
|
348
|
+
output.disabled.value = parentOutput.disabled.value;
|
|
349
|
+
}));
|
|
350
|
+
},
|
|
351
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
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 { LexicalEditor } from 'lexical';
|
|
9
|
+
import type { HistoryState } from './history';
|
|
10
|
+
export declare function useHistory(editor: LexicalEditor, externalHistoryState?: HistoryState, delay?: number): void;
|