@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,116 @@
|
|
|
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 _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
4
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
5
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
6
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
7
|
+
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); } }
|
|
8
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
9
|
+
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); }
|
|
10
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
11
|
+
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); }; }
|
|
12
|
+
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); }
|
|
13
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
14
|
+
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; } }
|
|
15
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
16
|
+
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; }
|
|
17
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
18
|
+
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); }
|
|
19
|
+
import { $wrapNodeInElement } from '@lexical/utils';
|
|
20
|
+
import { $createParagraphNode, $createRangeSelection, $insertNodes, $isRootOrShadowRoot, $setSelection } from 'lexical';
|
|
21
|
+
import { KernelPlugin } from "../../../editor-kernel/plugin";
|
|
22
|
+
import { IMarkdownShortCutService } from "../../markdown";
|
|
23
|
+
import { IUploadService } from "../../upload";
|
|
24
|
+
import { registerFileCommand } from "../command";
|
|
25
|
+
import { $createFileNode, $isFileNode, FileNode } from "../node/FileNode";
|
|
26
|
+
import { registerFileNodeSelectionObserver } from "../utils";
|
|
27
|
+
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
29
|
+
|
|
30
|
+
export var FilePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
31
|
+
_inherits(FilePlugin, _KernelPlugin);
|
|
32
|
+
var _super = _createSuper(FilePlugin);
|
|
33
|
+
function FilePlugin(kernel, config) {
|
|
34
|
+
var _kernel$requireServic;
|
|
35
|
+
var _this;
|
|
36
|
+
_classCallCheck(this, FilePlugin);
|
|
37
|
+
_this = _super.call(this);
|
|
38
|
+
// Register the file node
|
|
39
|
+
_this.kernel = kernel;
|
|
40
|
+
_this.config = config;
|
|
41
|
+
kernel.registerNodes([FileNode]);
|
|
42
|
+
if (config !== null && config !== void 0 && config.theme) {
|
|
43
|
+
kernel.registerThemes(config === null || config === void 0 ? void 0 : config.theme);
|
|
44
|
+
}
|
|
45
|
+
kernel.registerDecorator(FileNode.getType(), function (node, editor) {
|
|
46
|
+
return config !== null && config !== void 0 && config.decorator ? config.decorator(node, editor) : null;
|
|
47
|
+
});
|
|
48
|
+
(_kernel$requireServic = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic === void 0 || _kernel$requireServic.registerMarkdownWriter(FileNode.getType(), function (ctx, node) {
|
|
49
|
+
if ($isFileNode(node)) {
|
|
50
|
+
if (config !== null && config !== void 0 && config.markdownWriter) {
|
|
51
|
+
ctx.appendLine(config.markdownWriter(node));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (node.status === 'pending') {
|
|
55
|
+
ctx.appendLine("Uploading ".concat(node.name, "..."));
|
|
56
|
+
} else if (node.status === 'error') {
|
|
57
|
+
ctx.appendLine("Failed to upload ".concat(node.name, ": ").concat(node.message));
|
|
58
|
+
} else {
|
|
59
|
+
ctx.appendLine("[".concat(node.name, "](").concat(node.fileUrl, ")"));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return _this;
|
|
64
|
+
}
|
|
65
|
+
_createClass(FilePlugin, [{
|
|
66
|
+
key: "onInit",
|
|
67
|
+
value: function onInit(editor) {
|
|
68
|
+
var _this$kernel$requireS,
|
|
69
|
+
_this2 = this;
|
|
70
|
+
// Register the upload handler if provided
|
|
71
|
+
(_this$kernel$requireS = this.kernel.requireService(IUploadService)) === null || _this$kernel$requireS === void 0 || _this$kernel$requireS.registerUpload( /*#__PURE__*/function () {
|
|
72
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(file, from, range) {
|
|
73
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
74
|
+
while (1) switch (_context.prev = _context.next) {
|
|
75
|
+
case 0:
|
|
76
|
+
editor.update(function () {
|
|
77
|
+
if (range) {
|
|
78
|
+
var rangeSelection = $createRangeSelection();
|
|
79
|
+
if (range !== null && range !== undefined) {
|
|
80
|
+
rangeSelection.applyDOMRange(range);
|
|
81
|
+
}
|
|
82
|
+
$setSelection(rangeSelection);
|
|
83
|
+
}
|
|
84
|
+
var fileNode = $createFileNode(file.name);
|
|
85
|
+
$insertNodes([fileNode]); // Insert a zero-width space to ensure the image is not the last child
|
|
86
|
+
if ($isRootOrShadowRoot(fileNode.getParentOrThrow())) {
|
|
87
|
+
$wrapNodeInElement(fileNode, $createParagraphNode).selectEnd();
|
|
88
|
+
}
|
|
89
|
+
_this2.config.handleUpload(file).then(function (url) {
|
|
90
|
+
editor.update(function () {
|
|
91
|
+
fileNode.setUploaded(url.url);
|
|
92
|
+
});
|
|
93
|
+
}).catch(function (error) {
|
|
94
|
+
console.error('File upload failed:', error);
|
|
95
|
+
editor.update(function () {
|
|
96
|
+
fileNode.setError('File upload failed : ' + error.message);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
return _context.abrupt("return", null);
|
|
101
|
+
case 2:
|
|
102
|
+
case "end":
|
|
103
|
+
return _context.stop();
|
|
104
|
+
}
|
|
105
|
+
}, _callee);
|
|
106
|
+
}));
|
|
107
|
+
return function (_x, _x2, _x3) {
|
|
108
|
+
return _ref.apply(this, arguments);
|
|
109
|
+
};
|
|
110
|
+
}());
|
|
111
|
+
this.register(registerFileCommand(editor, this.config.handleUpload));
|
|
112
|
+
this.register(registerFileNodeSelectionObserver(editor));
|
|
113
|
+
}
|
|
114
|
+
}]);
|
|
115
|
+
return FilePlugin;
|
|
116
|
+
}(KernelPlugin), _defineProperty(_class, "pluginName", 'FilePlugin'), _class);
|
|
@@ -0,0 +1,74 @@
|
|
|
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 _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
5
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
6
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
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."); }
|
|
9
|
+
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); }
|
|
10
|
+
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; }
|
|
11
|
+
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; } }
|
|
12
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
+
import { useLayoutEffect } from 'react';
|
|
14
|
+
import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
|
|
15
|
+
import { UploadPlugin } from "../../upload";
|
|
16
|
+
import { FilePlugin } from "../plugin";
|
|
17
|
+
import ReactFile from "./components/ReactFile";
|
|
18
|
+
import { useStyles } from "./style";
|
|
19
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
|
+
var ReactFilePlugin = function ReactFilePlugin(_ref) {
|
|
21
|
+
var className = _ref.className,
|
|
22
|
+
locale = _ref.locale,
|
|
23
|
+
_handleUpload = _ref.handleUpload,
|
|
24
|
+
markdownWriter = _ref.markdownWriter,
|
|
25
|
+
theme = _ref.theme;
|
|
26
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
27
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
28
|
+
editor = _useLexicalComposerCo2[0];
|
|
29
|
+
var _useStyles = useStyles(),
|
|
30
|
+
styles = _useStyles.styles;
|
|
31
|
+
useLayoutEffect(function () {
|
|
32
|
+
if (locale) {
|
|
33
|
+
editor.registerLocale(locale);
|
|
34
|
+
}
|
|
35
|
+
editor.registerPlugin(UploadPlugin);
|
|
36
|
+
editor.registerPlugin(FilePlugin, {
|
|
37
|
+
decorator: function decorator(node, editor) {
|
|
38
|
+
return /*#__PURE__*/_jsx(ReactFile, {
|
|
39
|
+
className: className,
|
|
40
|
+
editor: editor,
|
|
41
|
+
node: node
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
handleUpload: function () {
|
|
45
|
+
var _handleUpload2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(file) {
|
|
46
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
47
|
+
while (1) switch (_context.prev = _context.next) {
|
|
48
|
+
case 0:
|
|
49
|
+
if (!_handleUpload) {
|
|
50
|
+
_context.next = 2;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
return _context.abrupt("return", _handleUpload(file));
|
|
54
|
+
case 2:
|
|
55
|
+
throw new Error('No upload handler provided');
|
|
56
|
+
case 3:
|
|
57
|
+
case "end":
|
|
58
|
+
return _context.stop();
|
|
59
|
+
}
|
|
60
|
+
}, _callee);
|
|
61
|
+
}));
|
|
62
|
+
function handleUpload(_x) {
|
|
63
|
+
return _handleUpload2.apply(this, arguments);
|
|
64
|
+
}
|
|
65
|
+
return handleUpload;
|
|
66
|
+
}(),
|
|
67
|
+
markdownWriter: markdownWriter,
|
|
68
|
+
theme: theme || styles
|
|
69
|
+
});
|
|
70
|
+
}, [editor]);
|
|
71
|
+
return null;
|
|
72
|
+
};
|
|
73
|
+
ReactFilePlugin.displayName = 'ReactFilePlugin';
|
|
74
|
+
export default ReactFilePlugin;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { LexicalEditor } from 'lexical';
|
|
3
|
+
import { FileNode } from '../../node/FileNode';
|
|
4
|
+
interface ReactFileProps {
|
|
5
|
+
className?: string;
|
|
6
|
+
editor: LexicalEditor;
|
|
7
|
+
node: FileNode;
|
|
8
|
+
}
|
|
9
|
+
declare const ReactFile: import("react").NamedExoticComponent<ReactFileProps>;
|
|
10
|
+
export default ReactFile;
|
|
@@ -0,0 +1,65 @@
|
|
|
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 { MaterialFileTypeIcon } from '@lobehub/ui';
|
|
8
|
+
import { CLICK_COMMAND, COMMAND_PRIORITY_LOW } from 'lexical';
|
|
9
|
+
import { memo, useCallback, useEffect, useRef } from 'react';
|
|
10
|
+
import { Center } from 'react-layout-kit';
|
|
11
|
+
import { useLexicalNodeSelection } from "../../../../editor-kernel/react/useLexicalNodeSelection";
|
|
12
|
+
import { useTranslation } from "../../../../editor-kernel/react/useTranslation";
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
+
var ReactFile = /*#__PURE__*/memo(function (_ref) {
|
|
16
|
+
var className = _ref.className,
|
|
17
|
+
editor = _ref.editor,
|
|
18
|
+
node = _ref.node;
|
|
19
|
+
var spanRef = useRef(null);
|
|
20
|
+
var t = useTranslation();
|
|
21
|
+
var _useLexicalNodeSelect = useLexicalNodeSelection(node.getKey()),
|
|
22
|
+
_useLexicalNodeSelect2 = _slicedToArray(_useLexicalNodeSelect, 3),
|
|
23
|
+
setSelected = _useLexicalNodeSelect2[1],
|
|
24
|
+
clearSelection = _useLexicalNodeSelect2[2];
|
|
25
|
+
var onClick = useCallback(function (payload) {
|
|
26
|
+
if (payload.target === spanRef.current) {
|
|
27
|
+
clearSelection();
|
|
28
|
+
setSelected(true);
|
|
29
|
+
return true; // Indicate that the click was handled
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}, [clearSelection, setSelected]);
|
|
33
|
+
useEffect(function () {
|
|
34
|
+
// Perform any necessary side effects here
|
|
35
|
+
return editor.registerCommand(CLICK_COMMAND, onClick, COMMAND_PRIORITY_LOW);
|
|
36
|
+
}, [editor, node, onClick]);
|
|
37
|
+
if (node.status === 'pending') {
|
|
38
|
+
return /*#__PURE__*/_jsx("div", {
|
|
39
|
+
className: className,
|
|
40
|
+
children: t('file.uploading')
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (node.status === 'error') {
|
|
44
|
+
return /*#__PURE__*/_jsx("div", {
|
|
45
|
+
className: className,
|
|
46
|
+
children: t('file.error', {
|
|
47
|
+
message: node.message || 'Unknown error'
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return /*#__PURE__*/_jsxs(Center, {
|
|
52
|
+
className: className,
|
|
53
|
+
gap: '.2em',
|
|
54
|
+
horizontal: true,
|
|
55
|
+
ref: spanRef,
|
|
56
|
+
children: [/*#__PURE__*/_jsx(MaterialFileTypeIcon, {
|
|
57
|
+
filename: node.name,
|
|
58
|
+
size: 18,
|
|
59
|
+
type: 'file',
|
|
60
|
+
variant: 'raw'
|
|
61
|
+
}), node.name]
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
ReactFile.displayName = 'ReactFile';
|
|
65
|
+
export default ReactFile;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ReactFilePlugin } from "./ReactFilePlugin";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var _templateObject;
|
|
2
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
3
|
+
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
4
|
+
import { createStyles } from 'antd-style';
|
|
5
|
+
export var useStyles = createStyles(function (_ref) {
|
|
6
|
+
var css = _ref.css,
|
|
7
|
+
token = _ref.token;
|
|
8
|
+
return {
|
|
9
|
+
file: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n user-select: none;\n\n display: inline-block;\n\n margin-inline: 0.25em;\n padding-block: 0.2em;\n padding-inline: 0.4em;\n border: 1px solid var(--lobe-markdown-border-color);\n border-radius: 0.25em;\n\n font-family: ", ";\n font-size: 0.875em;\n line-height: 1;\n word-break: break-word;\n white-space: break-spaces;\n\n background: ", ";\n\n span {\n user-select: none;\n }\n\n &.selected {\n color: #000;\n background: ", ";\n }\n "])), token.fontFamilyCode, token.colorFillSecondary, token.yellow)
|
|
10
|
+
};
|
|
11
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FileNode } from "../node/FileNode";
|
|
2
|
+
import type { ILocaleKeys } from "../../../types";
|
|
3
|
+
export interface ReactFilePluginProps {
|
|
4
|
+
className?: string;
|
|
5
|
+
handleUpload: (file: File) => Promise<{
|
|
6
|
+
url: string;
|
|
7
|
+
}>;
|
|
8
|
+
locale?: Partial<Record<keyof ILocaleKeys, string>>;
|
|
9
|
+
markdownWriter?: (file: FileNode) => string;
|
|
10
|
+
theme?: {
|
|
11
|
+
file?: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { $getSelection, $isNodeSelection, $isRangeSelection } from 'lexical';
|
|
2
|
+
export function registerFileNodeSelectionObserver(editor) {
|
|
3
|
+
var selectFileKeys = [];
|
|
4
|
+
return editor.registerUpdateListener(function (_ref) {
|
|
5
|
+
var editorState = _ref.editorState;
|
|
6
|
+
var selection = editorState.read(function () {
|
|
7
|
+
return $getSelection();
|
|
8
|
+
});
|
|
9
|
+
var newSelectFileKeys = [];
|
|
10
|
+
if ($isNodeSelection(selection)) {
|
|
11
|
+
var nodes = editorState.read(function () {
|
|
12
|
+
return selection.getNodes();
|
|
13
|
+
});
|
|
14
|
+
nodes.forEach(function (node) {
|
|
15
|
+
if (node.getType() === 'file') {
|
|
16
|
+
newSelectFileKeys.push(node.getKey());
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
} else if ($isRangeSelection(selection) && !selection.isCollapsed()) {
|
|
20
|
+
editorState.read(function () {
|
|
21
|
+
selection.getNodes().forEach(function (node) {
|
|
22
|
+
if (node.getType() === 'file') {
|
|
23
|
+
newSelectFileKeys.push(node.getKey());
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
var removeKeys = selectFileKeys.filter(function (key) {
|
|
29
|
+
return !newSelectFileKeys.includes(key);
|
|
30
|
+
});
|
|
31
|
+
var addKeys = newSelectFileKeys.filter(function (key) {
|
|
32
|
+
return !selectFileKeys.includes(key);
|
|
33
|
+
});
|
|
34
|
+
selectFileKeys.length = 0;
|
|
35
|
+
selectFileKeys.push.apply(selectFileKeys, newSelectFileKeys);
|
|
36
|
+
removeKeys.forEach(function (key) {
|
|
37
|
+
var _editor$getElementByK;
|
|
38
|
+
(_editor$getElementByK = editor.getElementByKey(key)) === null || _editor$getElementByK === void 0 || _editor$getElementByK.classList.remove('selected');
|
|
39
|
+
});
|
|
40
|
+
addKeys.forEach(function (key) {
|
|
41
|
+
var _editor$getElementByK2;
|
|
42
|
+
(_editor$getElementByK2 = editor.getElementByKey(key)) === null || _editor$getElementByK2 === void 0 || _editor$getElementByK2.classList.add('selected');
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { $insertNodes, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
|
|
2
|
+
import { $createHorizontalRuleNode } from "../node/HorizontalRuleNode";
|
|
3
|
+
export var INSERT_HORIZONTAL_RULE_COMMAND = createCommand('INSERT_HORIZONTAL_RULE_COMMAND');
|
|
4
|
+
export function registerHorizontalRuleCommand(editor) {
|
|
5
|
+
return editor.registerCommand(INSERT_HORIZONTAL_RULE_COMMAND, function () {
|
|
6
|
+
editor.update(function () {
|
|
7
|
+
var hrNode = $createHorizontalRuleNode();
|
|
8
|
+
$insertNodes([hrNode]);
|
|
9
|
+
});
|
|
10
|
+
return true;
|
|
11
|
+
}, COMMAND_PRIORITY_EDITOR // Priority
|
|
12
|
+
);
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DOMConversionMap, DOMExportOutput, DecoratorNode, EditorConfig, LexicalEditor, LexicalNode, SerializedLexicalNode } from 'lexical';
|
|
2
|
+
export type SerializedHorizontalRuleNode = SerializedLexicalNode;
|
|
3
|
+
export declare class HorizontalRuleNode extends DecoratorNode<any> {
|
|
4
|
+
static getType(): string;
|
|
5
|
+
static clone(node: HorizontalRuleNode): HorizontalRuleNode;
|
|
6
|
+
static importJSON(serializedNode: SerializedHorizontalRuleNode): HorizontalRuleNode;
|
|
7
|
+
static importDOM(): DOMConversionMap | null;
|
|
8
|
+
exportDOM(): DOMExportOutput;
|
|
9
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
10
|
+
getTextContent(): string;
|
|
11
|
+
isInline(): false;
|
|
12
|
+
updateDOM(): boolean;
|
|
13
|
+
decorate(editor: LexicalEditor): any;
|
|
14
|
+
}
|
|
15
|
+
export declare function $createHorizontalRuleNode(): HorizontalRuleNode;
|
|
16
|
+
export declare function $isHorizontalRuleNode(node: LexicalNode): node is HorizontalRuleNode;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
|
+
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); } }
|
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
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); }
|
|
7
|
+
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); }
|
|
8
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
9
|
+
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); }; }
|
|
10
|
+
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); }
|
|
11
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
12
|
+
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; } }
|
|
13
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
14
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
15
|
+
import { addClassNamesToElement } from '@lexical/utils';
|
|
16
|
+
import { $applyNodeReplacement, DecoratorNode } from 'lexical';
|
|
17
|
+
import { getKernelFromEditor } from "../../../editor-kernel/utils";
|
|
18
|
+
export var HorizontalRuleNode = /*#__PURE__*/function (_DecoratorNode) {
|
|
19
|
+
_inherits(HorizontalRuleNode, _DecoratorNode);
|
|
20
|
+
var _super = _createSuper(HorizontalRuleNode);
|
|
21
|
+
function HorizontalRuleNode() {
|
|
22
|
+
_classCallCheck(this, HorizontalRuleNode);
|
|
23
|
+
return _super.apply(this, arguments);
|
|
24
|
+
}
|
|
25
|
+
_createClass(HorizontalRuleNode, [{
|
|
26
|
+
key: "exportDOM",
|
|
27
|
+
value: function exportDOM() {
|
|
28
|
+
return {
|
|
29
|
+
element: document.createElement('hr')
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}, {
|
|
33
|
+
key: "createDOM",
|
|
34
|
+
value: function createDOM(config) {
|
|
35
|
+
var element = document.createElement('div');
|
|
36
|
+
addClassNamesToElement(element, config.theme.hr);
|
|
37
|
+
return element;
|
|
38
|
+
}
|
|
39
|
+
}, {
|
|
40
|
+
key: "getTextContent",
|
|
41
|
+
value: function getTextContent() {
|
|
42
|
+
return '\n';
|
|
43
|
+
}
|
|
44
|
+
}, {
|
|
45
|
+
key: "isInline",
|
|
46
|
+
value: function isInline() {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
50
|
+
key: "updateDOM",
|
|
51
|
+
value: function updateDOM() {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
key: "decorate",
|
|
56
|
+
value: function decorate(editor) {
|
|
57
|
+
var _getKernelFromEditor, _getKernelFromEditor$;
|
|
58
|
+
return ((_getKernelFromEditor = getKernelFromEditor(editor)) === null || _getKernelFromEditor === void 0 || (_getKernelFromEditor$ = _getKernelFromEditor.getDecorator('horizontalrule')) === null || _getKernelFromEditor$ === void 0 ? void 0 : _getKernelFromEditor$(this, editor)) || null;
|
|
59
|
+
}
|
|
60
|
+
}], [{
|
|
61
|
+
key: "getType",
|
|
62
|
+
value: function getType() {
|
|
63
|
+
return 'horizontalrule';
|
|
64
|
+
}
|
|
65
|
+
}, {
|
|
66
|
+
key: "clone",
|
|
67
|
+
value: function clone(node) {
|
|
68
|
+
return new HorizontalRuleNode(node.__key);
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
71
|
+
key: "importJSON",
|
|
72
|
+
value: function importJSON(serializedNode) {
|
|
73
|
+
return $createHorizontalRuleNode().updateFromJSON(serializedNode);
|
|
74
|
+
}
|
|
75
|
+
}, {
|
|
76
|
+
key: "importDOM",
|
|
77
|
+
value: function importDOM() {
|
|
78
|
+
return {
|
|
79
|
+
hr: function hr() {
|
|
80
|
+
return {
|
|
81
|
+
conversion: $convertHorizontalRuleElement,
|
|
82
|
+
priority: 0
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}]);
|
|
88
|
+
return HorizontalRuleNode;
|
|
89
|
+
}(DecoratorNode);
|
|
90
|
+
export function $createHorizontalRuleNode() {
|
|
91
|
+
return $applyNodeReplacement(new HorizontalRuleNode());
|
|
92
|
+
}
|
|
93
|
+
function $convertHorizontalRuleElement() {
|
|
94
|
+
return {
|
|
95
|
+
node: $createHorizontalRuleNode()
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export function $isHorizontalRuleNode(node) {
|
|
99
|
+
return node.getType() === HorizontalRuleNode.getType();
|
|
100
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LexicalEditor } from 'lexical';
|
|
2
|
+
import { IEditorPluginConstructor } from "../../../types";
|
|
3
|
+
import { HorizontalRuleNode } from '../node/HorizontalRuleNode';
|
|
4
|
+
export interface HRPluginOptions {
|
|
5
|
+
decorator: (node: HorizontalRuleNode, editor: LexicalEditor) => any;
|
|
6
|
+
theme?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const HRPlugin: IEditorPluginConstructor<HRPluginOptions>;
|