@lobehub/editor 1.0.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 +21 -0
- package/README.md +635 -0
- package/es/common/canUseDOM.d.ts +8 -0
- package/es/common/canUseDOM.js +9 -0
- package/es/common/sys.d.ts +17 -0
- package/es/common/sys.js +30 -0
- package/es/editor-kernel/data-source.d.ts +8 -0
- package/es/editor-kernel/data-source.js +30 -0
- package/es/editor-kernel/event.d.ts +3 -0
- package/es/editor-kernel/event.js +11 -0
- package/es/editor-kernel/index.d.ts +11 -0
- package/es/editor-kernel/index.js +14 -0
- package/es/editor-kernel/inode/helper.d.ts +11 -0
- package/es/editor-kernel/inode/helper.js +48 -0
- package/es/editor-kernel/inode/i-element-node.d.ts +5 -0
- package/es/editor-kernel/inode/i-element-node.js +1 -0
- package/es/editor-kernel/inode/i-node.d.ts +6 -0
- package/es/editor-kernel/inode/i-node.js +1 -0
- package/es/editor-kernel/inode/index.d.ts +5 -0
- package/es/editor-kernel/inode/index.js +5 -0
- package/es/editor-kernel/inode/paragraph-node.d.ts +6 -0
- package/es/editor-kernel/inode/paragraph-node.js +1 -0
- package/es/editor-kernel/inode/root-node.d.ts +7 -0
- package/es/editor-kernel/inode/root-node.js +1 -0
- package/es/editor-kernel/inode/text-node.d.ts +12 -0
- package/es/editor-kernel/inode/text-node.js +1 -0
- package/es/editor-kernel/kernel.d.ts +46 -0
- package/es/editor-kernel/kernel.js +273 -0
- package/es/editor-kernel/plugin.d.ts +7 -0
- package/es/editor-kernel/plugin.js +54 -0
- package/es/editor-kernel/react/LexicalErrorBoundary.d.ts +13 -0
- package/es/editor-kernel/react/LexicalErrorBoundary.js +26 -0
- package/es/editor-kernel/react/index.d.ts +5 -0
- package/es/editor-kernel/react/index.js +5 -0
- package/es/editor-kernel/react/react-context.d.ts +10 -0
- package/es/editor-kernel/react/react-context.js +25 -0
- package/es/editor-kernel/react/react-editor.d.ts +12 -0
- package/es/editor-kernel/react/react-editor.js +57 -0
- package/es/editor-kernel/react/useDecorators.d.ts +9 -0
- package/es/editor-kernel/react/useDecorators.js +69 -0
- package/es/editor-kernel/react/useLexicalEditor.d.ts +2 -0
- package/es/editor-kernel/react/useLexicalEditor.js +31 -0
- package/es/editor-kernel/react/useLexicalNodeSelection.d.ts +17 -0
- package/es/editor-kernel/react/useLexicalNodeSelection.js +99 -0
- package/es/editor-kernel/react/useToolbarState.d.ts +31 -0
- package/es/editor-kernel/react/useToolbarState.js +302 -0
- package/es/editor-kernel/react/useTranslation.d.ts +3 -0
- package/es/editor-kernel/react/useTranslation.js +19 -0
- package/es/editor-kernel/types.d.ts +189 -0
- package/es/editor-kernel/types.js +1 -0
- package/es/editor-kernel/utils.d.ts +25 -0
- package/es/editor-kernel/utils.js +69 -0
- package/es/index.d.ts +14 -0
- package/es/index.js +14 -0
- package/es/locale/index.d.ts +25 -0
- package/es/locale/index.js +24 -0
- package/es/plugins/codeblock/command/index.d.ts +20 -0
- package/es/plugins/codeblock/command/index.js +84 -0
- package/es/plugins/codeblock/index.d.ts +4 -0
- package/es/plugins/codeblock/index.js +4 -0
- package/es/plugins/codeblock/plugin/CodeHighlighterShiki.d.ts +24 -0
- package/es/plugins/codeblock/plugin/CodeHighlighterShiki.js +680 -0
- package/es/plugins/codeblock/plugin/FacadeShiki.d.ts +51 -0
- package/es/plugins/codeblock/plugin/FacadeShiki.js +348 -0
- package/es/plugins/codeblock/plugin/index.d.ts +18 -0
- package/es/plugins/codeblock/plugin/index.js +90 -0
- package/es/plugins/codeblock/plugin/invariant.d.ts +8 -0
- package/es/plugins/codeblock/plugin/invariant.js +17 -0
- package/es/plugins/codeblock/react/ReactCodeblockPlugin.d.ts +4 -0
- package/es/plugins/codeblock/react/ReactCodeblockPlugin.js +51 -0
- package/es/plugins/codeblock/react/index.d.ts +2 -0
- package/es/plugins/codeblock/react/index.js +1 -0
- package/es/plugins/codeblock/react/style.d.ts +6 -0
- package/es/plugins/codeblock/react/style.js +38 -0
- package/es/plugins/codeblock/react/type.d.ts +5 -0
- package/es/plugins/codeblock/react/type.js +1 -0
- package/es/plugins/codeblock/utils/language.d.ts +1 -0
- package/es/plugins/codeblock/utils/language.js +12 -0
- package/es/plugins/common/command/index.d.ts +7 -0
- package/es/plugins/common/command/index.js +31 -0
- package/es/plugins/common/data-source/json-data-source.d.ts +7 -0
- package/es/plugins/common/data-source/json-data-source.js +39 -0
- package/es/plugins/common/data-source/text-data-source.d.ts +6 -0
- package/es/plugins/common/data-source/text-data-source.js +54 -0
- package/es/plugins/common/index.d.ts +3 -0
- package/es/plugins/common/index.js +3 -0
- package/es/plugins/common/node/ElementDOMSlot.d.ts +5 -0
- package/es/plugins/common/node/ElementDOMSlot.js +59 -0
- package/es/plugins/common/node/LexicalLineBreakNode.d.ts +31 -0
- package/es/plugins/common/node/LexicalLineBreakNode.js +140 -0
- package/es/plugins/common/node/ParagraphNode.d.ts +7 -0
- package/es/plugins/common/node/ParagraphNode.js +47 -0
- package/es/plugins/common/plugin/index.d.ts +16 -0
- package/es/plugins/common/plugin/index.js +245 -0
- package/es/plugins/common/plugin/register.d.ts +4 -0
- package/es/plugins/common/plugin/register.js +230 -0
- package/es/plugins/common/react/Placeholder/index.d.ts +7 -0
- package/es/plugins/common/react/Placeholder/index.js +53 -0
- package/es/plugins/common/react/Placeholder/style.d.ts +4 -0
- package/es/plugins/common/react/Placeholder/style.js +12 -0
- package/es/plugins/common/react/ReactEditorContent.d.ts +4 -0
- package/es/plugins/common/react/ReactEditorContent.js +7 -0
- package/es/plugins/common/react/ReactPlainText.d.ts +4 -0
- package/es/plugins/common/react/ReactPlainText.js +100 -0
- package/es/plugins/common/react/index.d.ts +3 -0
- package/es/plugins/common/react/index.js +3 -0
- package/es/plugins/common/react/style.d.ts +18 -0
- package/es/plugins/common/react/style.js +38 -0
- package/es/plugins/common/react/type.d.ts +21 -0
- package/es/plugins/common/react/type.js +1 -0
- package/es/plugins/common/utils/index.d.ts +28 -0
- package/es/plugins/common/utils/index.js +96 -0
- package/es/plugins/file/command/index.d.ts +7 -0
- package/es/plugins/file/command/index.js +28 -0
- package/es/plugins/file/index.d.ts +3 -0
- package/es/plugins/file/index.js +3 -0
- package/es/plugins/file/node/FileNode.d.ts +36 -0
- package/es/plugins/file/node/FileNode.js +177 -0
- package/es/plugins/file/plugin/index.d.ts +14 -0
- package/es/plugins/file/plugin/index.js +116 -0
- package/es/plugins/file/react/ReactFilePlugin.d.ts +4 -0
- package/es/plugins/file/react/ReactFilePlugin.js +74 -0
- package/es/plugins/file/react/components/ReactFile.d.ts +10 -0
- package/es/plugins/file/react/components/ReactFile.js +65 -0
- package/es/plugins/file/react/index.d.ts +2 -0
- package/es/plugins/file/react/index.js +1 -0
- package/es/plugins/file/react/style.d.ts +3 -0
- package/es/plugins/file/react/style.js +11 -0
- package/es/plugins/file/react/type.d.ts +13 -0
- package/es/plugins/file/react/type.js +1 -0
- package/es/plugins/file/utils/index.d.ts +2 -0
- package/es/plugins/file/utils/index.js +45 -0
- package/es/plugins/hr/command/index.d.ts +3 -0
- package/es/plugins/hr/command/index.js +13 -0
- package/es/plugins/hr/index.d.ts +3 -0
- package/es/plugins/hr/index.js +3 -0
- package/es/plugins/hr/node/HorizontalRuleNode.d.ts +16 -0
- package/es/plugins/hr/node/HorizontalRuleNode.js +100 -0
- package/es/plugins/hr/plugin/index.d.ts +8 -0
- package/es/plugins/hr/plugin/index.js +70 -0
- package/es/plugins/hr/react/ReactHRPlugin.d.ts +4 -0
- package/es/plugins/hr/react/ReactHRPlugin.js +36 -0
- package/es/plugins/hr/react/components/HRNode.d.ts +10 -0
- package/es/plugins/hr/react/components/HRNode.js +45 -0
- package/es/plugins/hr/react/index.d.ts +2 -0
- package/es/plugins/hr/react/index.js +1 -0
- package/es/plugins/hr/react/style.d.ts +1 -0
- package/es/plugins/hr/react/style.js +8 -0
- package/es/plugins/hr/react/type.d.ts +3 -0
- package/es/plugins/hr/react/type.js +1 -0
- package/es/plugins/image/command/index.d.ts +8 -0
- package/es/plugins/image/command/index.js +46 -0
- package/es/plugins/image/index.d.ts +3 -0
- package/es/plugins/image/index.js +3 -0
- package/es/plugins/image/node/basie-image-node.d.ts +44 -0
- package/es/plugins/image/node/basie-image-node.js +151 -0
- package/es/plugins/image/node/image-node.d.ts +26 -0
- package/es/plugins/image/node/image-node.js +176 -0
- package/es/plugins/image/plugin/index.d.ts +13 -0
- package/es/plugins/image/plugin/index.js +74 -0
- package/es/plugins/image/react/ReactImagePlugin.d.ts +4 -0
- package/es/plugins/image/react/ReactImagePlugin.js +48 -0
- package/es/plugins/image/react/components/BrokenImage.d.ts +3 -0
- package/es/plugins/image/react/components/BrokenImage.js +18 -0
- package/es/plugins/image/react/components/Image.d.ts +7 -0
- package/es/plugins/image/react/components/Image.js +71 -0
- package/es/plugins/image/react/components/LazyImage.d.ts +8 -0
- package/es/plugins/image/react/components/LazyImage.js +99 -0
- package/es/plugins/image/react/components/useSupenseImage.d.ts +2 -0
- package/es/plugins/image/react/components/useSupenseImage.js +24 -0
- package/es/plugins/image/react/index.d.ts +2 -0
- package/es/plugins/image/react/index.js +1 -0
- package/es/plugins/image/react/style.d.ts +12 -0
- package/es/plugins/image/react/style.js +17 -0
- package/es/plugins/image/react/type.d.ts +6 -0
- package/es/plugins/image/react/type.js +1 -0
- package/es/plugins/link/command/index.d.ts +6 -0
- package/es/plugins/link/command/index.js +20 -0
- package/es/plugins/link/index.d.ts +3 -0
- package/es/plugins/link/index.js +3 -0
- package/es/plugins/link/node/LinkNode.d.ts +126 -0
- package/es/plugins/link/node/LinkNode.js +721 -0
- package/es/plugins/link/plugin/index.d.ts +8 -0
- package/es/plugins/link/plugin/index.js +94 -0
- package/es/plugins/link/react/ReactLinkPlugin.d.ts +4 -0
- package/es/plugins/link/react/ReactLinkPlugin.js +168 -0
- package/es/plugins/link/react/components/LinkEdit.d.ts +7 -0
- package/es/plugins/link/react/components/LinkEdit.js +138 -0
- package/es/plugins/link/react/components/Toolbar.d.ts +7 -0
- package/es/plugins/link/react/components/Toolbar.js +63 -0
- package/es/plugins/link/react/index.d.ts +2 -0
- package/es/plugins/link/react/index.js +1 -0
- package/es/plugins/link/react/style.d.ts +5 -0
- package/es/plugins/link/react/style.js +12 -0
- package/es/plugins/link/react/type.d.ts +9 -0
- package/es/plugins/link/react/type.js +1 -0
- package/es/plugins/link/utils/index.d.ts +4 -0
- package/es/plugins/link/utils/index.js +37 -0
- package/es/plugins/list/command/index.d.ts +1 -0
- package/es/plugins/list/command/index.js +1 -0
- package/es/plugins/list/index.d.ts +3 -0
- package/es/plugins/list/index.js +3 -0
- package/es/plugins/list/plugin/index.d.ts +5 -0
- package/es/plugins/list/plugin/index.js +193 -0
- package/es/plugins/list/react/ReactListPlugin.d.ts +4 -0
- package/es/plugins/list/react/ReactListPlugin.js +29 -0
- package/es/plugins/list/react/index.d.ts +2 -0
- package/es/plugins/list/react/index.js +1 -0
- package/es/plugins/list/react/style.d.ts +1 -0
- package/es/plugins/list/react/style.js +7 -0
- package/es/plugins/list/react/type.d.ts +3 -0
- package/es/plugins/list/react/type.js +1 -0
- package/es/plugins/list/utils/index.d.ts +5 -0
- package/es/plugins/list/utils/index.js +88 -0
- package/es/plugins/markdown/data-source/markdown-data-source.d.ts +10 -0
- package/es/plugins/markdown/data-source/markdown-data-source.js +64 -0
- package/es/plugins/markdown/data-source/markdown-writer-context.d.ts +12 -0
- package/es/plugins/markdown/data-source/markdown-writer-context.js +51 -0
- package/es/plugins/markdown/index.d.ts +2 -0
- package/es/plugins/markdown/index.js +2 -0
- package/es/plugins/markdown/plugin/index.d.ts +4 -0
- package/es/plugins/markdown/plugin/index.js +122 -0
- package/es/plugins/markdown/service/shortcut.d.ts +139 -0
- package/es/plugins/markdown/service/shortcut.js +401 -0
- package/es/plugins/markdown/utils/index.d.ts +12 -0
- package/es/plugins/markdown/utils/index.js +61 -0
- package/es/plugins/mention/command/index.d.ts +6 -0
- package/es/plugins/mention/command/index.js +19 -0
- package/es/plugins/mention/index.d.ts +3 -0
- package/es/plugins/mention/index.js +3 -0
- package/es/plugins/mention/node/MentionNode.d.ts +26 -0
- package/es/plugins/mention/node/MentionNode.js +143 -0
- package/es/plugins/mention/plugin/index.d.ts +11 -0
- package/es/plugins/mention/plugin/index.js +61 -0
- package/es/plugins/mention/plugin/register.d.ts +2 -0
- package/es/plugins/mention/plugin/register.js +46 -0
- package/es/plugins/mention/react/ReactMentionPlugin.d.ts +4 -0
- package/es/plugins/mention/react/ReactMentionPlugin.js +42 -0
- package/es/plugins/mention/react/components/Mention.d.ts +9 -0
- package/es/plugins/mention/react/components/Mention.js +39 -0
- package/es/plugins/mention/react/index.d.ts +2 -0
- package/es/plugins/mention/react/index.js +1 -0
- package/es/plugins/mention/react/style.d.ts +3 -0
- package/es/plugins/mention/react/style.js +11 -0
- package/es/plugins/mention/react/type.d.ts +8 -0
- package/es/plugins/mention/react/type.js +1 -0
- package/es/plugins/slash/index.d.ts +3 -0
- package/es/plugins/slash/index.js +3 -0
- package/es/plugins/slash/plugin/index.d.ts +23 -0
- package/es/plugins/slash/plugin/index.js +132 -0
- package/es/plugins/slash/react/ReactSlashOption.d.ts +4 -0
- package/es/plugins/slash/react/ReactSlashOption.js +7 -0
- package/es/plugins/slash/react/ReactSlashPlugin.d.ts +4 -0
- package/es/plugins/slash/react/ReactSlashPlugin.js +228 -0
- package/es/plugins/slash/react/components/SlashMenu.d.ts +8 -0
- package/es/plugins/slash/react/components/SlashMenu.js +72 -0
- package/es/plugins/slash/react/index.d.ts +4 -0
- package/es/plugins/slash/react/index.js +3 -0
- package/es/plugins/slash/react/style.d.ts +1 -0
- package/es/plugins/slash/react/style.js +9 -0
- package/es/plugins/slash/react/type.d.ts +82 -0
- package/es/plugins/slash/react/type.js +1 -0
- package/es/plugins/slash/react/utils.d.ts +5 -0
- package/es/plugins/slash/react/utils.js +20 -0
- package/es/plugins/slash/service/i-slash-service.d.ts +38 -0
- package/es/plugins/slash/service/i-slash-service.js +64 -0
- package/es/plugins/slash/utils/utils.d.ts +38 -0
- package/es/plugins/slash/utils/utils.js +192 -0
- package/es/plugins/table/command/index.d.ts +13 -0
- package/es/plugins/table/command/index.js +73 -0
- package/es/plugins/table/index.d.ts +3 -0
- package/es/plugins/table/index.js +3 -0
- package/es/plugins/table/node/index.d.ts +2 -0
- package/es/plugins/table/node/index.js +16 -0
- package/es/plugins/table/plugin/index.d.ts +5 -0
- package/es/plugins/table/plugin/index.js +85 -0
- package/es/plugins/table/react/TableActionMenu/index.d.ts +8 -0
- package/es/plugins/table/react/TableActionMenu/index.js +481 -0
- package/es/plugins/table/react/TableActionMenu/style.d.ts +1 -0
- package/es/plugins/table/react/TableActionMenu/style.js +7 -0
- package/es/plugins/table/react/TableActionMenu/utils.d.ts +9 -0
- package/es/plugins/table/react/TableActionMenu/utils.js +49 -0
- package/es/plugins/table/react/TableHoverActions/index.d.ts +7 -0
- package/es/plugins/table/react/TableHoverActions/index.js +268 -0
- package/es/plugins/table/react/TableHoverActions/style.d.ts +5 -0
- package/es/plugins/table/react/TableHoverActions/style.js +11 -0
- package/es/plugins/table/react/TableHoverActions/utils.d.ts +8 -0
- package/es/plugins/table/react/TableHoverActions/utils.js +43 -0
- package/es/plugins/table/react/TableResize/index.d.ts +10 -0
- package/es/plugins/table/react/TableResize/index.js +378 -0
- package/es/plugins/table/react/TableResize/style.d.ts +3 -0
- package/es/plugins/table/react/TableResize/style.js +10 -0
- package/es/plugins/table/react/TableResize/utils.d.ts +4 -0
- package/es/plugins/table/react/TableResize/utils.js +40 -0
- package/es/plugins/table/react/hooks.d.ts +1 -0
- package/es/plugins/table/react/hooks.js +22 -0
- package/es/plugins/table/react/index.d.ts +3 -0
- package/es/plugins/table/react/index.js +77 -0
- package/es/plugins/table/react/style.d.ts +1 -0
- package/es/plugins/table/react/style.js +8 -0
- package/es/plugins/table/react/type.d.ts +5 -0
- package/es/plugins/table/react/type.js +1 -0
- package/es/plugins/table/utils/index.d.ts +8 -0
- package/es/plugins/table/utils/index.js +83 -0
- package/es/plugins/upload/index.d.ts +3 -0
- package/es/plugins/upload/index.js +3 -0
- package/es/plugins/upload/plugin/index.d.ts +4 -0
- package/es/plugins/upload/plugin/index.js +82 -0
- package/es/plugins/upload/service/i-upload-service.d.ts +15 -0
- package/es/plugins/upload/service/i-upload-service.js +115 -0
- package/es/plugins/upload/utils/index.d.ts +1 -0
- package/es/plugins/upload/utils/index.js +20 -0
- package/es/react/ChatInput/ChatInput.d.ts +4 -0
- package/es/react/ChatInput/ChatInput.js +41 -0
- package/es/react/ChatInput/index.d.ts +2 -0
- package/es/react/ChatInput/index.js +2 -0
- package/es/react/ChatInput/style.d.ts +4 -0
- package/es/react/ChatInput/style.js +11 -0
- package/es/react/ChatInput/type.d.ts +10 -0
- package/es/react/ChatInput/type.js +1 -0
- package/es/react/ChatInputActionBar/ChatInputActionBar.d.ts +4 -0
- package/es/react/ChatInputActionBar/ChatInputActionBar.js +27 -0
- package/es/react/ChatInputActionBar/index.d.ts +2 -0
- package/es/react/ChatInputActionBar/index.js +2 -0
- package/es/react/ChatInputActionBar/style.d.ts +3 -0
- package/es/react/ChatInputActionBar/style.js +9 -0
- package/es/react/ChatInputActionBar/type.d.ts +7 -0
- package/es/react/ChatInputActionBar/type.js +1 -0
- package/es/react/ChatInputActions/ChatInputActions.d.ts +4 -0
- package/es/react/ChatInputActions/ChatInputActions.js +187 -0
- package/es/react/ChatInputActions/components/ChatInputActionsCollapse.d.ts +4 -0
- package/es/react/ChatInputActions/components/ChatInputActionsCollapse.js +97 -0
- package/es/react/ChatInputActions/index.d.ts +2 -0
- package/es/react/ChatInputActions/index.js +1 -0
- package/es/react/ChatInputActions/style.d.ts +4 -0
- package/es/react/ChatInputActions/style.js +10 -0
- package/es/react/ChatInputActions/type.d.ts +38 -0
- package/es/react/ChatInputActions/type.js +1 -0
- package/es/react/CodeLanguageSelect/CodeLanguageSelect.d.ts +4 -0
- package/es/react/CodeLanguageSelect/CodeLanguageSelect.js +96 -0
- package/es/react/CodeLanguageSelect/index.d.ts +2 -0
- package/es/react/CodeLanguageSelect/index.js +2 -0
- package/es/react/CodeLanguageSelect/style.d.ts +3 -0
- package/es/react/CodeLanguageSelect/style.js +9 -0
- package/es/react/CodeLanguageSelect/type.d.ts +2 -0
- package/es/react/CodeLanguageSelect/type.js +1 -0
- package/es/react/Editor/Editor.d.ts +4 -0
- package/es/react/Editor/Editor.js +78 -0
- package/es/react/Editor/index.d.ts +14 -0
- package/es/react/Editor/index.js +10 -0
- package/es/react/Editor/type.d.ts +24 -0
- package/es/react/Editor/type.js +1 -0
- package/es/react/Editor/useEditor.d.ts +3 -0
- package/es/react/Editor/useEditor.js +4 -0
- package/es/react/Editor/utils.d.ts +2 -0
- package/es/react/Editor/utils.js +3 -0
- package/es/react/EditorProvider/index.d.ts +20 -0
- package/es/react/EditorProvider/index.js +25 -0
- package/es/react/SendButton/SendButton.d.ts +4 -0
- package/es/react/SendButton/SendButton.js +77 -0
- package/es/react/SendButton/components/SendIcon.d.ts +6 -0
- package/es/react/SendButton/components/SendIcon.js +32 -0
- package/es/react/SendButton/components/StopIcon.d.ts +6 -0
- package/es/react/SendButton/components/StopIcon.js +61 -0
- package/es/react/SendButton/index.d.ts +2 -0
- package/es/react/SendButton/index.js +2 -0
- package/es/react/SendButton/style.d.ts +6 -0
- package/es/react/SendButton/style.js +15 -0
- package/es/react/SendButton/type.d.ts +6 -0
- package/es/react/SendButton/type.js +1 -0
- package/es/react/SlashMenu/SlashMenu.d.ts +4 -0
- package/es/react/SlashMenu/SlashMenu.js +68 -0
- package/es/react/SlashMenu/index.d.ts +2 -0
- package/es/react/SlashMenu/index.js +2 -0
- package/es/react/SlashMenu/style.d.ts +4 -0
- package/es/react/SlashMenu/style.js +11 -0
- package/es/react/SlashMenu/type.d.ts +8 -0
- package/es/react/SlashMenu/type.js +1 -0
- package/es/react/index.d.ts +8 -0
- package/es/react/index.js +8 -0
- package/es/types/global.d.ts +20 -0
- package/es/types/index.d.ts +2 -0
- package/es/types/index.js +2 -0
- package/es/types/kernel.d.ts +180 -0
- package/es/types/kernel.js +1 -0
- package/es/types/locale.d.ts +10 -0
- package/es/types/locale.js +1 -0
- package/package.json +66 -0
- package/patches/lexical+0.33.1.patch +88 -0
- package/react.d.ts +1 -0
- package/react.js +1 -0
- package/scripts/patch-lexical-package-json.js +20 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
var _class;
|
|
2
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
8
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
9
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
11
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
12
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
13
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
14
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
15
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
16
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
17
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
18
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
19
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
20
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
21
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
22
|
+
import { $createTextNode, COMMAND_PRIORITY_NORMAL, PASTE_COMMAND } from 'lexical';
|
|
23
|
+
import { KernelPlugin } from "../../../editor-kernel/plugin";
|
|
24
|
+
import { IMarkdownShortCutService } from "../../markdown";
|
|
25
|
+
import { INSERT_LINK_COMMAND, registerLinkCommand } from "../command";
|
|
26
|
+
import { $createLinkNode, $isLinkNode, AutoLinkNode, LinkNode } from "../node/LinkNode";
|
|
27
|
+
export var LinkPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
28
|
+
_inherits(LinkPlugin, _KernelPlugin);
|
|
29
|
+
var _super = _createSuper(LinkPlugin);
|
|
30
|
+
function LinkPlugin(kernel, config) {
|
|
31
|
+
var _kernel$requireServic, _kernel$requireServic2;
|
|
32
|
+
var _this;
|
|
33
|
+
_classCallCheck(this, LinkPlugin);
|
|
34
|
+
_this = _super.call(this);
|
|
35
|
+
// Register the link nodes
|
|
36
|
+
_defineProperty(_assertThisInitialized(_this), "linkRegex", /^https?:\/\/\S+$/);
|
|
37
|
+
_this.kernel = kernel;
|
|
38
|
+
kernel.registerNodes([LinkNode, AutoLinkNode]);
|
|
39
|
+
if (config !== null && config !== void 0 && config.theme) {
|
|
40
|
+
kernel.registerThemes(config.theme);
|
|
41
|
+
}
|
|
42
|
+
if (config !== null && config !== void 0 && config.linkRegex) {
|
|
43
|
+
_this.linkRegex = config.linkRegex;
|
|
44
|
+
}
|
|
45
|
+
(_kernel$requireServic = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic === void 0 || _kernel$requireServic.registerMarkdownShortCut({
|
|
46
|
+
regExp: /\[([^[]+)]\(([^\s()]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?\)\s?$/,
|
|
47
|
+
replace: function replace(textNode, match) {
|
|
48
|
+
var _match = _slicedToArray(match, 4),
|
|
49
|
+
linkText = _match[1],
|
|
50
|
+
linkUrl = _match[2],
|
|
51
|
+
linkTitle = _match[3];
|
|
52
|
+
var linkNode = $createLinkNode(linkUrl, {
|
|
53
|
+
title: linkTitle
|
|
54
|
+
});
|
|
55
|
+
var linkTextNode = $createTextNode(linkText);
|
|
56
|
+
linkTextNode.setFormat(textNode.getFormat());
|
|
57
|
+
linkNode.append(linkTextNode);
|
|
58
|
+
textNode.replace(linkNode);
|
|
59
|
+
return linkTextNode;
|
|
60
|
+
},
|
|
61
|
+
trigger: ')',
|
|
62
|
+
type: 'text-match'
|
|
63
|
+
});
|
|
64
|
+
(_kernel$requireServic2 = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic2 === void 0 || _kernel$requireServic2.registerMarkdownWriter(LinkNode.getType(), function (ctx, node) {
|
|
65
|
+
if ($isLinkNode(node)) {
|
|
66
|
+
ctx.wrap('[', "](".concat(node.getURL(), ")"));
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return _this;
|
|
70
|
+
}
|
|
71
|
+
_createClass(LinkPlugin, [{
|
|
72
|
+
key: "onInit",
|
|
73
|
+
value: function onInit(editor) {
|
|
74
|
+
var _this2 = this;
|
|
75
|
+
this.register(registerLinkCommand(editor));
|
|
76
|
+
this.register(editor.registerCommand(PASTE_COMMAND, function (payload) {
|
|
77
|
+
var clipboardData = payload.clipboardData;
|
|
78
|
+
if (clipboardData && clipboardData.types && clipboardData.types.length === 1 && clipboardData.types[0] === 'text/plain') {
|
|
79
|
+
var data = clipboardData.getData('text/plain').trim();
|
|
80
|
+
if (_this2.linkRegex.test(data)) {
|
|
81
|
+
payload.stopImmediatePropagation();
|
|
82
|
+
payload.preventDefault();
|
|
83
|
+
editor.dispatchCommand(INSERT_LINK_COMMAND, {
|
|
84
|
+
url: data
|
|
85
|
+
});
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}, COMMAND_PRIORITY_NORMAL));
|
|
91
|
+
}
|
|
92
|
+
}]);
|
|
93
|
+
return LinkPlugin;
|
|
94
|
+
}(KernelPlugin), _defineProperty(_class, "pluginName", 'LinkPlugin'), _class);
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
8
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
9
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
10
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
12
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
13
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
14
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
15
|
+
import { computePosition, flip, offset, shift } from '@floating-ui/dom';
|
|
16
|
+
import { mergeRegister } from '@lexical/utils';
|
|
17
|
+
import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_LOW, COMMAND_PRIORITY_NORMAL, KEY_DOWN_COMMAND, isModifierMatch } from 'lexical';
|
|
18
|
+
import { useLayoutEffect, useRef, useState } from 'react';
|
|
19
|
+
import { CONTROL_OR_META } from "../../../common/sys";
|
|
20
|
+
import { useLexicalEditor } from "../../../editor-kernel/react";
|
|
21
|
+
import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
|
|
22
|
+
import { MarkdownPlugin } from "../../markdown";
|
|
23
|
+
import { $isLinkNode, $toggleLink, HOVER_LINK_COMMAND, HOVER_OUT_LINK_COMMAND, TOGGLE_LINK_COMMAND } from "../node/LinkNode";
|
|
24
|
+
import { LinkPlugin } from "../plugin";
|
|
25
|
+
import { getSelectedNode, sanitizeUrl } from "../utils";
|
|
26
|
+
import { EDIT_LINK_COMMAND, LinkEdit } from "./components/LinkEdit";
|
|
27
|
+
import { Toolbar } from "./components/Toolbar";
|
|
28
|
+
import { useStyles } from "./style";
|
|
29
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
30
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
31
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
32
|
+
export var ReactLinkPlugin = function ReactLinkPlugin(_ref) {
|
|
33
|
+
var theme = _ref.theme,
|
|
34
|
+
validateUrl = _ref.validateUrl,
|
|
35
|
+
attributes = _ref.attributes;
|
|
36
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
37
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
38
|
+
editor = _useLexicalComposerCo2[0];
|
|
39
|
+
var _useState = useState(null),
|
|
40
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
41
|
+
linkNode = _useState2[0],
|
|
42
|
+
setLinkNode = _useState2[1];
|
|
43
|
+
var state = useRef({
|
|
44
|
+
isLink: false
|
|
45
|
+
});
|
|
46
|
+
var divRef = useRef(null);
|
|
47
|
+
var LinkRef = useRef(null);
|
|
48
|
+
var clearTimerRef = useRef(-1);
|
|
49
|
+
var _useStyles = useStyles(),
|
|
50
|
+
styles = _useStyles.styles;
|
|
51
|
+
useLayoutEffect(function () {
|
|
52
|
+
editor.registerPlugin(MarkdownPlugin);
|
|
53
|
+
editor.registerPlugin(LinkPlugin, {
|
|
54
|
+
theme: theme || styles
|
|
55
|
+
});
|
|
56
|
+
}, []);
|
|
57
|
+
useLexicalEditor(function (editor) {
|
|
58
|
+
return mergeRegister(editor.registerUpdateListener(function () {
|
|
59
|
+
var selection = editor.read(function () {
|
|
60
|
+
return $getSelection();
|
|
61
|
+
});
|
|
62
|
+
if (!selection) return;
|
|
63
|
+
if ($isRangeSelection(selection)) {
|
|
64
|
+
// Update links
|
|
65
|
+
editor.read(function () {
|
|
66
|
+
var node = getSelectedNode(selection);
|
|
67
|
+
var parent = node.getParent();
|
|
68
|
+
var isLink = $isLinkNode(parent) || $isLinkNode(node);
|
|
69
|
+
state.current.isLink = isLink;
|
|
70
|
+
if (isLink) {
|
|
71
|
+
var _linkNode = $isLinkNode(parent) ? parent : node;
|
|
72
|
+
editor.dispatchCommand(EDIT_LINK_COMMAND, {
|
|
73
|
+
linkNode: _linkNode,
|
|
74
|
+
linkNodeDOM: editor.getElementByKey(_linkNode.getKey())
|
|
75
|
+
});
|
|
76
|
+
} else {
|
|
77
|
+
editor.dispatchCommand(EDIT_LINK_COMMAND, {
|
|
78
|
+
linkNode: null,
|
|
79
|
+
linkNodeDOM: null
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
} else {
|
|
84
|
+
state.current.isLink = false;
|
|
85
|
+
}
|
|
86
|
+
if (divRef.current) {
|
|
87
|
+
divRef.current.style.left = '-9999px';
|
|
88
|
+
divRef.current.style.top = '-9999px';
|
|
89
|
+
}
|
|
90
|
+
}), editor.registerCommand(TOGGLE_LINK_COMMAND, function (payload) {
|
|
91
|
+
if (payload === null) {
|
|
92
|
+
$toggleLink(payload);
|
|
93
|
+
return true;
|
|
94
|
+
} else if (typeof payload === 'string') {
|
|
95
|
+
if (validateUrl === undefined || validateUrl(payload)) {
|
|
96
|
+
$toggleLink(payload, attributes);
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
} else {
|
|
101
|
+
var url = payload.url,
|
|
102
|
+
target = payload.target,
|
|
103
|
+
rel = payload.rel,
|
|
104
|
+
title = payload.title;
|
|
105
|
+
$toggleLink(url, _objectSpread(_objectSpread({}, attributes), {}, {
|
|
106
|
+
rel: rel,
|
|
107
|
+
target: target,
|
|
108
|
+
title: title
|
|
109
|
+
}));
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
}, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_DOWN_COMMAND, function (e) {
|
|
113
|
+
// ctrl + k / cmd + k
|
|
114
|
+
if (isModifierMatch(e, CONTROL_OR_META) && 'KeyK' === e.code) {
|
|
115
|
+
var isLink = state.current.isLink;
|
|
116
|
+
e.preventDefault();
|
|
117
|
+
e.stopPropagation();
|
|
118
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, isLink ? null : sanitizeUrl('https://'));
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(HOVER_LINK_COMMAND, function (payload) {
|
|
123
|
+
if (!payload.event.target || divRef.current === null) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
setLinkNode(payload.linkNode);
|
|
127
|
+
computePosition(payload.event.target, divRef.current, {
|
|
128
|
+
middleware: [offset(5), flip(), shift()],
|
|
129
|
+
placement: 'top-start'
|
|
130
|
+
}).then(function (_ref2) {
|
|
131
|
+
var x = _ref2.x,
|
|
132
|
+
y = _ref2.y;
|
|
133
|
+
if (!payload.event.target || divRef.current === null) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
LinkRef.current = payload.event.target;
|
|
137
|
+
// const url = editor.read(() => payload.linkNode.getURL());
|
|
138
|
+
divRef.current.style.left = "".concat(x, "px");
|
|
139
|
+
divRef.current.style.top = "".concat(y, "px");
|
|
140
|
+
});
|
|
141
|
+
return false;
|
|
142
|
+
}, COMMAND_PRIORITY_NORMAL), editor.registerCommand(HOVER_OUT_LINK_COMMAND, function () {
|
|
143
|
+
clearTimeout(clearTimerRef.current);
|
|
144
|
+
clearTimerRef.current = setTimeout(function () {
|
|
145
|
+
if (divRef.current) {
|
|
146
|
+
divRef.current.style.left = '-9999px';
|
|
147
|
+
divRef.current.style.top = '-9999px';
|
|
148
|
+
}
|
|
149
|
+
}, 300);
|
|
150
|
+
return true;
|
|
151
|
+
}, COMMAND_PRIORITY_NORMAL));
|
|
152
|
+
}, []);
|
|
153
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
154
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
155
|
+
className: styles.editor_linkPlugin,
|
|
156
|
+
onMouseEnter: function onMouseEnter() {
|
|
157
|
+
clearTimeout(clearTimerRef.current);
|
|
158
|
+
},
|
|
159
|
+
ref: divRef,
|
|
160
|
+
children: /*#__PURE__*/_jsx(Toolbar, {
|
|
161
|
+
editor: editor.getLexicalEditor(),
|
|
162
|
+
linkNode: linkNode
|
|
163
|
+
})
|
|
164
|
+
}), /*#__PURE__*/_jsx(LinkEdit, {})]
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
ReactLinkPlugin.displayName = 'ReactLinkPlugin';
|
|
168
|
+
export default ReactLinkPlugin;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { computePosition, flip, offset, shift } from '@floating-ui/dom';
|
|
8
|
+
import { mergeRegister } from '@lexical/utils';
|
|
9
|
+
import { Icon, Input } from '@lobehub/ui';
|
|
10
|
+
import { COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_NORMAL, KEY_ESCAPE_COMMAND, KEY_TAB_COMMAND, createCommand } from 'lexical';
|
|
11
|
+
import { LinkIcon } from 'lucide-react';
|
|
12
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
13
|
+
import { useLexicalComposerContext, useLexicalEditor } from "../../../../editor-kernel/react";
|
|
14
|
+
import { useStyles } from "../style";
|
|
15
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
|
+
export var EDIT_LINK_COMMAND = createCommand();
|
|
17
|
+
export var LinkEdit = function LinkEdit() {
|
|
18
|
+
var divRef = useRef(null);
|
|
19
|
+
var linkNodeRef = useRef(null);
|
|
20
|
+
var linkInputRef = useRef(null);
|
|
21
|
+
var _useState = useState(''),
|
|
22
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
23
|
+
linkUrl = _useState2[0],
|
|
24
|
+
setLinkUrl = _useState2[1];
|
|
25
|
+
var _useState3 = useState(null),
|
|
26
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
27
|
+
linkDom = _useState4[0],
|
|
28
|
+
setLinkDom = _useState4[1];
|
|
29
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
30
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
31
|
+
editor = _useLexicalComposerCo2[0];
|
|
32
|
+
var _useStyles = useStyles(),
|
|
33
|
+
styles = _useStyles.styles,
|
|
34
|
+
theme = _useStyles.theme;
|
|
35
|
+
useEffect(function () {
|
|
36
|
+
if (!linkDom || !divRef.current) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
computePosition(linkDom, divRef.current, {
|
|
40
|
+
middleware: [offset(8), flip(), shift()],
|
|
41
|
+
placement: 'bottom-start'
|
|
42
|
+
}).then(function (_ref) {
|
|
43
|
+
var x = _ref.x,
|
|
44
|
+
y = _ref.y;
|
|
45
|
+
if (divRef.current) {
|
|
46
|
+
divRef.current.style.left = "".concat(x, "px");
|
|
47
|
+
divRef.current.style.top = "".concat(y, "px");
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}, [linkDom]);
|
|
51
|
+
var handleKeyDown = useCallback(function (event) {
|
|
52
|
+
var lexicalEditor = editor.getLexicalEditor();
|
|
53
|
+
if (!linkNodeRef.current || !linkInputRef.current || !lexicalEditor) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
var linkNode = linkNodeRef.current;
|
|
57
|
+
var input = linkInputRef.current;
|
|
58
|
+
var inputDOM = input.input;
|
|
59
|
+
if (event.key === 'Enter') {
|
|
60
|
+
event.preventDefault();
|
|
61
|
+
var currentURL = lexicalEditor.read(function () {
|
|
62
|
+
return linkNode.getURL();
|
|
63
|
+
});
|
|
64
|
+
if (currentURL !== inputDOM.value) {
|
|
65
|
+
lexicalEditor.update(function () {
|
|
66
|
+
linkNode.setURL(inputDOM.value);
|
|
67
|
+
lexicalEditor.focus();
|
|
68
|
+
});
|
|
69
|
+
} else {
|
|
70
|
+
lexicalEditor.focus();
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
} else if (event.key === 'Escape' || event.key === 'Tab') {
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
lexicalEditor.focus();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
}, [linkNodeRef, linkInputRef]);
|
|
79
|
+
useLexicalEditor(function (editor) {
|
|
80
|
+
return mergeRegister(editor.registerCommand(EDIT_LINK_COMMAND, function (payload) {
|
|
81
|
+
if (!payload.linkNode || !payload.linkNodeDOM) {
|
|
82
|
+
setLinkDom(null);
|
|
83
|
+
setLinkUrl('');
|
|
84
|
+
if (divRef.current) {
|
|
85
|
+
divRef.current.style.left = '-9999px';
|
|
86
|
+
divRef.current.style.top = '-9999px';
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
linkNodeRef.current = payload.linkNode;
|
|
91
|
+
setLinkUrl(payload.linkNode.getURL());
|
|
92
|
+
setLinkDom(payload.linkNodeDOM);
|
|
93
|
+
return true;
|
|
94
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ESCAPE_COMMAND, function () {
|
|
95
|
+
if (divRef.current) {
|
|
96
|
+
divRef.current.style.left = '-9999px';
|
|
97
|
+
divRef.current.style.top = '-9999px';
|
|
98
|
+
}
|
|
99
|
+
linkNodeRef.current = null;
|
|
100
|
+
setLinkUrl('');
|
|
101
|
+
setLinkDom(null);
|
|
102
|
+
return true;
|
|
103
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_TAB_COMMAND, function (payload) {
|
|
104
|
+
if (linkNodeRef.current && linkInputRef.current) {
|
|
105
|
+
payload.stopImmediatePropagation();
|
|
106
|
+
payload.preventDefault();
|
|
107
|
+
linkInputRef.current.focus();
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
}, COMMAND_PRIORITY_NORMAL));
|
|
112
|
+
}, []);
|
|
113
|
+
return /*#__PURE__*/_jsx("div", {
|
|
114
|
+
className: styles.editor_linkEdit,
|
|
115
|
+
ref: divRef,
|
|
116
|
+
children: /*#__PURE__*/_jsx(Input, {
|
|
117
|
+
onChange: function onChange(e) {
|
|
118
|
+
// Handle link URL change
|
|
119
|
+
setLinkUrl(e.target.value);
|
|
120
|
+
},
|
|
121
|
+
onKeyDown: handleKeyDown,
|
|
122
|
+
placeholder: "https://enter-link-url",
|
|
123
|
+
prefix: /*#__PURE__*/_jsx(Icon, {
|
|
124
|
+
color: theme.colorTextDescription,
|
|
125
|
+
icon: LinkIcon
|
|
126
|
+
}),
|
|
127
|
+
ref: linkInputRef,
|
|
128
|
+
shadow: true,
|
|
129
|
+
style: {
|
|
130
|
+
background: theme.colorBgElevated,
|
|
131
|
+
maxWidth: '100%',
|
|
132
|
+
minWidth: 240
|
|
133
|
+
},
|
|
134
|
+
value: linkUrl,
|
|
135
|
+
variant: 'outlined'
|
|
136
|
+
})
|
|
137
|
+
});
|
|
138
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ActionIconGroup } from '@lobehub/ui';
|
|
2
|
+
import { EditIcon, ExternalLinkIcon, UnlinkIcon } from 'lucide-react';
|
|
3
|
+
import { useTranslation } from "../../../../editor-kernel/react/useTranslation";
|
|
4
|
+
import { TOGGLE_LINK_COMMAND } from "../../node/LinkNode";
|
|
5
|
+
import { useStyles } from "../style";
|
|
6
|
+
import { EDIT_LINK_COMMAND } from "./LinkEdit";
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
export var Toolbar = function Toolbar(_ref) {
|
|
9
|
+
var linkNode = _ref.linkNode,
|
|
10
|
+
editor = _ref.editor;
|
|
11
|
+
var _useStyles = useStyles(),
|
|
12
|
+
theme = _useStyles.theme;
|
|
13
|
+
var t = useTranslation();
|
|
14
|
+
var handleEdit = function handleEdit() {
|
|
15
|
+
// Edit link
|
|
16
|
+
if (linkNode) {
|
|
17
|
+
editor.dispatchCommand(EDIT_LINK_COMMAND, {
|
|
18
|
+
linkNode: linkNode,
|
|
19
|
+
linkNodeDOM: editor.getElementByKey(linkNode.getKey())
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var handleRemove = function handleRemove() {
|
|
24
|
+
// Remove link
|
|
25
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
26
|
+
};
|
|
27
|
+
var handleOpenLink = function handleOpenLink() {
|
|
28
|
+
// Open link in new window
|
|
29
|
+
if (linkNode) {
|
|
30
|
+
var url = editor.read(function () {
|
|
31
|
+
return linkNode.getURL();
|
|
32
|
+
});
|
|
33
|
+
window.open(url, '_blank');
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
return /*#__PURE__*/_jsx(ActionIconGroup, {
|
|
37
|
+
items: [{
|
|
38
|
+
icon: EditIcon,
|
|
39
|
+
key: 'edit',
|
|
40
|
+
label: t('link.edit'),
|
|
41
|
+
onClick: handleEdit
|
|
42
|
+
}, {
|
|
43
|
+
icon: ExternalLinkIcon,
|
|
44
|
+
key: 'openLink',
|
|
45
|
+
label: t('link.open'),
|
|
46
|
+
onClick: handleOpenLink
|
|
47
|
+
}, {
|
|
48
|
+
icon: UnlinkIcon,
|
|
49
|
+
key: 'unlink',
|
|
50
|
+
label: t('link.unlink'),
|
|
51
|
+
onClick: handleRemove
|
|
52
|
+
}],
|
|
53
|
+
shadow: true,
|
|
54
|
+
size: {
|
|
55
|
+
blockSize: 32,
|
|
56
|
+
size: 16
|
|
57
|
+
},
|
|
58
|
+
style: {
|
|
59
|
+
background: theme.colorBgElevated
|
|
60
|
+
},
|
|
61
|
+
variant: 'outlined'
|
|
62
|
+
});
|
|
63
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ReactLinkPlugin } from "./ReactLinkPlugin";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var _templateObject, _templateObject2;
|
|
2
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
3
|
+
import { createStyles } from 'antd-style';
|
|
4
|
+
export var useStyles = createStyles(function (_ref) {
|
|
5
|
+
var css = _ref.css;
|
|
6
|
+
var position = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: absolute;\n z-index: 999;\n inset-block-start: -9999px;\n inset-inline-start: -9999px;\n "])));
|
|
7
|
+
return {
|
|
8
|
+
editor_linkEdit: position,
|
|
9
|
+
editor_linkPlugin: position,
|
|
10
|
+
link: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n cursor: pointer;\n\n margin-block: 1em;\n margin-inline: 0;\n padding: 2px;\n border: none;\n "])))
|
|
11
|
+
};
|
|
12
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ElementNode, RangeSelection, TextNode } from 'lexical';
|
|
2
|
+
export declare function sanitizeUrl(url: string): string;
|
|
3
|
+
export declare function validateUrl(url: string): boolean;
|
|
4
|
+
export declare function getSelectedNode(selection: RangeSelection): TextNode | ElementNode;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { $isAtNodeEnd } from '@lexical/selection';
|
|
2
|
+
var SUPPORTED_URL_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'sms:', 'tel:']);
|
|
3
|
+
export function sanitizeUrl(url) {
|
|
4
|
+
try {
|
|
5
|
+
var parsedUrl = new URL(url);
|
|
6
|
+
// eslint-disable-next-line no-script-url
|
|
7
|
+
if (!SUPPORTED_URL_PROTOCOLS.has(parsedUrl.protocol)) {
|
|
8
|
+
return 'about:blank';
|
|
9
|
+
}
|
|
10
|
+
} catch (_unused) {
|
|
11
|
+
return url;
|
|
12
|
+
}
|
|
13
|
+
return url;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Source: https://stackoverflow.com/a/8234912/2013580
|
|
17
|
+
var urlRegExp = new RegExp(/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\w$&+,:;=-]+@)?[\d.A-Za-z-]+|(?:www.|[\w$&+,:;=-]+@)[\d.A-Za-z-]+)((?:\/[%+./~\w-_]*)?\??[\w%&+.;=@-]*#?\w*)?)/);
|
|
18
|
+
export function validateUrl(url) {
|
|
19
|
+
// TODO Fix UI for link insertion; it should never default to an invalid URL such as https://.
|
|
20
|
+
// Maybe show a dialog where they user can type the URL before inserting it.
|
|
21
|
+
return url === 'https://' || urlRegExp.test(url);
|
|
22
|
+
}
|
|
23
|
+
export function getSelectedNode(selection) {
|
|
24
|
+
var anchor = selection.anchor;
|
|
25
|
+
var focus = selection.focus;
|
|
26
|
+
var anchorNode = selection.anchor.getNode();
|
|
27
|
+
var focusNode = selection.focus.getNode();
|
|
28
|
+
if (anchorNode === focusNode) {
|
|
29
|
+
return anchorNode;
|
|
30
|
+
}
|
|
31
|
+
var isBackward = selection.isBackward();
|
|
32
|
+
if (isBackward) {
|
|
33
|
+
return $isAtNodeEnd(focus) ? anchorNode : focusNode;
|
|
34
|
+
} else {
|
|
35
|
+
return $isAtNodeEnd(anchor) ? anchorNode : focusNode;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND, REMOVE_LIST_COMMAND, UPDATE_LIST_START_COMMAND, } from '@lexical/list';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND, REMOVE_LIST_COMMAND, UPDATE_LIST_START_COMMAND } from '@lexical/list';
|