@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,302 @@
|
|
|
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 { $createCodeNode, $isCodeNode } from '@lexical/code';
|
|
8
|
+
import { $isListNode, INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND, ListNode } from '@lexical/list';
|
|
9
|
+
import { $isHeadingNode } from '@lexical/rich-text';
|
|
10
|
+
import { $isAtNodeEnd, $setBlocksType } from '@lexical/selection';
|
|
11
|
+
import { $findMatchingParent, $getNearestNodeOfType, mergeRegister } from '@lexical/utils';
|
|
12
|
+
import { $createParagraphNode, $getSelection, $isRangeSelection, $isRootOrShadowRoot, CAN_REDO_COMMAND, CAN_UNDO_COMMAND, COMMAND_PRIORITY_LOW, FORMAT_TEXT_COMMAND, REDO_COMMAND, SELECTION_CHANGE_COMMAND, UNDO_COMMAND } from 'lexical';
|
|
13
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
14
|
+
import { UPDATE_CODEBLOCK_LANG } from "../../plugins/codeblock";
|
|
15
|
+
import { $isRootTextContentEmpty } from "../../plugins/common/utils";
|
|
16
|
+
import { $isLinkNode, TOGGLE_LINK_COMMAND } from "../../plugins/link/node/LinkNode";
|
|
17
|
+
import { sanitizeUrl } from "../../plugins/link/utils";
|
|
18
|
+
function $findTopLevelElement(node) {
|
|
19
|
+
var topLevelElement = node.getKey() === 'root' ? node : $findMatchingParent(node, function (e) {
|
|
20
|
+
var parent = e.getParent();
|
|
21
|
+
return parent !== null && $isRootOrShadowRoot(parent);
|
|
22
|
+
});
|
|
23
|
+
if (topLevelElement === null) {
|
|
24
|
+
topLevelElement = node.getTopLevelElementOrThrow();
|
|
25
|
+
}
|
|
26
|
+
return topLevelElement;
|
|
27
|
+
}
|
|
28
|
+
var formatParagraph = function formatParagraph(editor) {
|
|
29
|
+
editor === null || editor === void 0 || editor.update(function () {
|
|
30
|
+
var selection = $getSelection();
|
|
31
|
+
$setBlocksType(selection, function () {
|
|
32
|
+
return $createParagraphNode();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
function getSelectedNode(selection) {
|
|
37
|
+
var anchor = selection.anchor;
|
|
38
|
+
var focus = selection.focus;
|
|
39
|
+
var anchorNode = selection.anchor.getNode();
|
|
40
|
+
var focusNode = selection.focus.getNode();
|
|
41
|
+
if (anchorNode === focusNode) {
|
|
42
|
+
return anchorNode;
|
|
43
|
+
}
|
|
44
|
+
var isBackward = selection.isBackward();
|
|
45
|
+
if (isBackward) {
|
|
46
|
+
return $isAtNodeEnd(focus) ? anchorNode : focusNode;
|
|
47
|
+
} else {
|
|
48
|
+
return $isAtNodeEnd(anchor) ? anchorNode : focusNode;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Provide toolbar state and toolbar methods
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
export function useToolbarState(editorRef) {
|
|
57
|
+
var _useState = useState(false),
|
|
58
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
59
|
+
canUndo = _useState2[0],
|
|
60
|
+
setCanUndo = _useState2[1];
|
|
61
|
+
var _useState3 = useState(false),
|
|
62
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
63
|
+
canRedo = _useState4[0],
|
|
64
|
+
setCanRedo = _useState4[1];
|
|
65
|
+
var _useState5 = useState(false),
|
|
66
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
67
|
+
isBold = _useState6[0],
|
|
68
|
+
setIsBold = _useState6[1];
|
|
69
|
+
var _useState7 = useState(false),
|
|
70
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
71
|
+
isItalic = _useState8[0],
|
|
72
|
+
setIsItalic = _useState8[1];
|
|
73
|
+
var _useState9 = useState(false),
|
|
74
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
75
|
+
isUnderline = _useState10[0],
|
|
76
|
+
setIsUnderline = _useState10[1];
|
|
77
|
+
var _useState11 = useState(false),
|
|
78
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
79
|
+
isStrikethrough = _useState12[0],
|
|
80
|
+
setIsStrikethrough = _useState12[1];
|
|
81
|
+
var _useState13 = useState(false),
|
|
82
|
+
_useState14 = _slicedToArray(_useState13, 2),
|
|
83
|
+
isCode = _useState14[0],
|
|
84
|
+
setIsCode = _useState14[1];
|
|
85
|
+
var _useState15 = useState(false),
|
|
86
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
|
87
|
+
isLink = _useState16[0],
|
|
88
|
+
setIsLink = _useState16[1];
|
|
89
|
+
var _useState17 = useState(false),
|
|
90
|
+
_useState18 = _slicedToArray(_useState17, 2),
|
|
91
|
+
isInCodeblock = _useState18[0],
|
|
92
|
+
setIsInCodeblok = _useState18[1];
|
|
93
|
+
var _useState19 = useState(null),
|
|
94
|
+
_useState20 = _slicedToArray(_useState19, 2),
|
|
95
|
+
codeblockLang = _useState20[0],
|
|
96
|
+
setCodeblockLang = _useState20[1];
|
|
97
|
+
var _useState21 = useState(true),
|
|
98
|
+
_useState22 = _slicedToArray(_useState21, 2),
|
|
99
|
+
isEmpty = _useState22[0],
|
|
100
|
+
setIsEmpty = _useState22[1];
|
|
101
|
+
var _useState23 = useState(null),
|
|
102
|
+
_useState24 = _slicedToArray(_useState23, 2),
|
|
103
|
+
blockType = _useState24[0],
|
|
104
|
+
setBlockType = _useState24[1];
|
|
105
|
+
var $handleHeadingNode = useCallback(function (selectedElement) {
|
|
106
|
+
var type = $isHeadingNode(selectedElement) ? selectedElement.getTag() : selectedElement.getType();
|
|
107
|
+
setBlockType(type);
|
|
108
|
+
}, [setBlockType]);
|
|
109
|
+
var $updateToolbar = useCallback(function () {
|
|
110
|
+
var _editorRef$current;
|
|
111
|
+
var selection = $getSelection();
|
|
112
|
+
var editor = (_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 ? void 0 : _editorRef$current.getLexicalEditor();
|
|
113
|
+
if (editor) {
|
|
114
|
+
setIsEmpty($isRootTextContentEmpty(editor.isComposing(), false));
|
|
115
|
+
}
|
|
116
|
+
if ($isRangeSelection(selection)) {
|
|
117
|
+
var _editorRef$current2;
|
|
118
|
+
setIsBold(selection.hasFormat('bold'));
|
|
119
|
+
setIsItalic(selection.hasFormat('italic'));
|
|
120
|
+
setIsUnderline(selection.hasFormat('underline'));
|
|
121
|
+
setIsStrikethrough(selection.hasFormat('strikethrough'));
|
|
122
|
+
setIsCode(selection.hasFormat('code'));
|
|
123
|
+
var anchorNode = selection.anchor.getNode();
|
|
124
|
+
var focusNode = selection.focus.getNode();
|
|
125
|
+
var element = $findTopLevelElement(anchorNode);
|
|
126
|
+
var focusElement = $findTopLevelElement(focusNode);
|
|
127
|
+
var elementKey = element.getKey();
|
|
128
|
+
var elementDOM = (_editorRef$current2 = editorRef.current) === null || _editorRef$current2 === void 0 || (_editorRef$current2 = _editorRef$current2.getLexicalEditor()) === null || _editorRef$current2 === void 0 ? void 0 : _editorRef$current2.getElementByKey(elementKey);
|
|
129
|
+
var node = getSelectedNode(selection);
|
|
130
|
+
var parent = node.getParent();
|
|
131
|
+
setIsLink($isLinkNode(parent) || $isLinkNode(node));
|
|
132
|
+
var isCodeBlock = $isCodeNode(element) && $isCodeNode(focusElement) && elementKey === focusElement.getKey();
|
|
133
|
+
setIsInCodeblok(isCodeBlock);
|
|
134
|
+
setCodeblockLang(isCodeBlock ? element.getLanguage() : '');
|
|
135
|
+
if (elementDOM !== null) {
|
|
136
|
+
if ($isListNode(element)) {
|
|
137
|
+
var parentList = $getNearestNodeOfType(anchorNode, ListNode);
|
|
138
|
+
var type = parentList ? parentList.getListType() : element.getListType();
|
|
139
|
+
setBlockType(type);
|
|
140
|
+
} else {
|
|
141
|
+
$handleHeadingNode(element);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
} else if (!selection) {
|
|
145
|
+
setIsBold(false);
|
|
146
|
+
setIsItalic(false);
|
|
147
|
+
setIsUnderline(false);
|
|
148
|
+
setIsStrikethrough(false);
|
|
149
|
+
setIsCode(false);
|
|
150
|
+
setIsLink(false);
|
|
151
|
+
setIsInCodeblok(false);
|
|
152
|
+
setCodeblockLang(null);
|
|
153
|
+
setBlockType(null);
|
|
154
|
+
}
|
|
155
|
+
}, [editorRef.current]);
|
|
156
|
+
var undo = useCallback(function () {
|
|
157
|
+
var _editorRef$current3;
|
|
158
|
+
(_editorRef$current3 = editorRef.current) === null || _editorRef$current3 === void 0 || _editorRef$current3.dispatchCommand(UNDO_COMMAND, undefined);
|
|
159
|
+
}, [editorRef.current]);
|
|
160
|
+
var redo = useCallback(function () {
|
|
161
|
+
var _editorRef$current4;
|
|
162
|
+
(_editorRef$current4 = editorRef.current) === null || _editorRef$current4 === void 0 || _editorRef$current4.dispatchCommand(REDO_COMMAND, undefined);
|
|
163
|
+
}, [editorRef.current]);
|
|
164
|
+
var formatText = useCallback(function (type) {
|
|
165
|
+
var _editorRef$current5;
|
|
166
|
+
(_editorRef$current5 = editorRef.current) === null || _editorRef$current5 === void 0 || _editorRef$current5.dispatchCommand(FORMAT_TEXT_COMMAND, type);
|
|
167
|
+
}, [editorRef.current]);
|
|
168
|
+
var bold = useCallback(function () {
|
|
169
|
+
formatText('bold');
|
|
170
|
+
}, [formatText]);
|
|
171
|
+
var underline = useCallback(function () {
|
|
172
|
+
formatText('underline');
|
|
173
|
+
}, [formatText]);
|
|
174
|
+
var strikethrough = useCallback(function () {
|
|
175
|
+
formatText('strikethrough');
|
|
176
|
+
}, [formatText]);
|
|
177
|
+
var italic = useCallback(function () {
|
|
178
|
+
formatText('italic');
|
|
179
|
+
}, [formatText]);
|
|
180
|
+
var code = useCallback(function () {
|
|
181
|
+
formatText('code');
|
|
182
|
+
}, [formatText]);
|
|
183
|
+
var bulletList = useCallback(function () {
|
|
184
|
+
if (blockType !== 'bullet') {
|
|
185
|
+
var _editorRef$current6;
|
|
186
|
+
(_editorRef$current6 = editorRef.current) === null || _editorRef$current6 === void 0 || _editorRef$current6.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, undefined);
|
|
187
|
+
} else {
|
|
188
|
+
var _editorRef$current7;
|
|
189
|
+
formatParagraph((_editorRef$current7 = editorRef.current) === null || _editorRef$current7 === void 0 ? void 0 : _editorRef$current7.getLexicalEditor());
|
|
190
|
+
}
|
|
191
|
+
}, [blockType]);
|
|
192
|
+
var numberList = useCallback(function () {
|
|
193
|
+
if (blockType !== 'number') {
|
|
194
|
+
var _editorRef$current8;
|
|
195
|
+
(_editorRef$current8 = editorRef.current) === null || _editorRef$current8 === void 0 || _editorRef$current8.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, undefined);
|
|
196
|
+
} else {
|
|
197
|
+
var _editorRef$current9;
|
|
198
|
+
formatParagraph((_editorRef$current9 = editorRef.current) === null || _editorRef$current9 === void 0 ? void 0 : _editorRef$current9.getLexicalEditor());
|
|
199
|
+
}
|
|
200
|
+
}, [blockType]);
|
|
201
|
+
var formatCodeblock = useCallback(function () {
|
|
202
|
+
if (blockType !== 'code') {
|
|
203
|
+
var _editorRef$current10;
|
|
204
|
+
(_editorRef$current10 = editorRef.current) === null || _editorRef$current10 === void 0 || (_editorRef$current10 = _editorRef$current10.getLexicalEditor()) === null || _editorRef$current10 === void 0 || _editorRef$current10.update(function () {
|
|
205
|
+
var selection = $getSelection();
|
|
206
|
+
if (!selection) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (!$isRangeSelection(selection) || selection.isCollapsed()) {
|
|
210
|
+
$setBlocksType(selection, function () {
|
|
211
|
+
return $createCodeNode();
|
|
212
|
+
});
|
|
213
|
+
} else {
|
|
214
|
+
var textContent = selection.getTextContent();
|
|
215
|
+
var codeNode = $createCodeNode();
|
|
216
|
+
selection.insertNodes([codeNode]);
|
|
217
|
+
selection = $getSelection();
|
|
218
|
+
if ($isRangeSelection(selection)) {
|
|
219
|
+
selection.insertRawText(textContent);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}, [blockType]);
|
|
225
|
+
var updateCodeblockLang = useCallback(function (lang) {
|
|
226
|
+
var _editorRef$current11;
|
|
227
|
+
if (!isInCodeblock) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
(_editorRef$current11 = editorRef.current) === null || _editorRef$current11 === void 0 || _editorRef$current11.dispatchCommand(UPDATE_CODEBLOCK_LANG, {
|
|
231
|
+
lang: lang
|
|
232
|
+
});
|
|
233
|
+
}, [editorRef.current, isInCodeblock]);
|
|
234
|
+
var insertLink = useCallback(function () {
|
|
235
|
+
if (!isLink) {
|
|
236
|
+
var _editorRef$current12;
|
|
237
|
+
setIsLink(true);
|
|
238
|
+
(_editorRef$current12 = editorRef.current) === null || _editorRef$current12 === void 0 || (_editorRef$current12 = _editorRef$current12.getLexicalEditor()) === null || _editorRef$current12 === void 0 || _editorRef$current12.dispatchCommand(TOGGLE_LINK_COMMAND, sanitizeUrl('https://'));
|
|
239
|
+
} else {
|
|
240
|
+
var _editorRef$current13;
|
|
241
|
+
setIsLink(false);
|
|
242
|
+
(_editorRef$current13 = editorRef.current) === null || _editorRef$current13 === void 0 || (_editorRef$current13 = _editorRef$current13.getLexicalEditor()) === null || _editorRef$current13 === void 0 || _editorRef$current13.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
243
|
+
}
|
|
244
|
+
}, [editorRef.current, isLink]);
|
|
245
|
+
useEffect(function () {
|
|
246
|
+
if (!editorRef.current) return;
|
|
247
|
+
var editor = editorRef.current;
|
|
248
|
+
var lexicalEditor = editor.getLexicalEditor();
|
|
249
|
+
var cleanup = function cleanup() {};
|
|
250
|
+
var handleLeixcalEditor = function handleLeixcalEditor(editor) {
|
|
251
|
+
cleanup = mergeRegister(editor.registerUpdateListener(function (_ref) {
|
|
252
|
+
var editorState = _ref.editorState;
|
|
253
|
+
editorState.read(function () {
|
|
254
|
+
$updateToolbar();
|
|
255
|
+
});
|
|
256
|
+
}), editor.registerCommand(SELECTION_CHANGE_COMMAND, function () {
|
|
257
|
+
$updateToolbar();
|
|
258
|
+
return false;
|
|
259
|
+
}, COMMAND_PRIORITY_LOW), editor.registerCommand(CAN_UNDO_COMMAND, function (payload) {
|
|
260
|
+
setCanUndo(payload);
|
|
261
|
+
return false;
|
|
262
|
+
}, COMMAND_PRIORITY_LOW), editor.registerCommand(CAN_REDO_COMMAND, function (payload) {
|
|
263
|
+
setCanRedo(payload);
|
|
264
|
+
return false;
|
|
265
|
+
}, COMMAND_PRIORITY_LOW));
|
|
266
|
+
return cleanup;
|
|
267
|
+
};
|
|
268
|
+
if (!lexicalEditor) {
|
|
269
|
+
editor.on('initialized', handleLeixcalEditor);
|
|
270
|
+
return function () {
|
|
271
|
+
cleanup();
|
|
272
|
+
editor.off('initialized', handleLeixcalEditor);
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
return handleLeixcalEditor(lexicalEditor);
|
|
276
|
+
}, [editorRef.current]);
|
|
277
|
+
return {
|
|
278
|
+
blockType: blockType,
|
|
279
|
+
bold: bold,
|
|
280
|
+
bulletList: bulletList,
|
|
281
|
+
canRedo: canRedo,
|
|
282
|
+
canUndo: canUndo,
|
|
283
|
+
code: code,
|
|
284
|
+
codeblockLang: codeblockLang,
|
|
285
|
+
formatCodeblock: formatCodeblock,
|
|
286
|
+
insertLink: insertLink,
|
|
287
|
+
isBold: isBold,
|
|
288
|
+
isCode: isCode,
|
|
289
|
+
isEmpty: isEmpty,
|
|
290
|
+
isInCodeblock: isInCodeblock,
|
|
291
|
+
isItalic: isItalic,
|
|
292
|
+
isStrikethrough: isStrikethrough,
|
|
293
|
+
isUnderline: isUnderline,
|
|
294
|
+
italic: italic,
|
|
295
|
+
numberList: numberList,
|
|
296
|
+
redo: redo,
|
|
297
|
+
strikethrough: strikethrough,
|
|
298
|
+
underline: underline,
|
|
299
|
+
undo: undo,
|
|
300
|
+
updateCodeblockLang: updateCodeblockLang
|
|
301
|
+
};
|
|
302
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 { useCallback } from 'react';
|
|
8
|
+
import { useLexicalComposerContext } from "./react-context";
|
|
9
|
+
export function useTranslation() {
|
|
10
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
11
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
12
|
+
editor = _useLexicalComposerCo2[0];
|
|
13
|
+
return useCallback(function (key, options) {
|
|
14
|
+
return editor.t(key, options);
|
|
15
|
+
}, [editor]);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Maintain backward compatibility
|
|
19
|
+
export var useLocale = useTranslation;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import type { CommandPayloadType, DecoratorNode, LexicalCommand, LexicalEditor, LexicalNodeConfig } from 'lexical';
|
|
2
|
+
import type DataSource from './data-source';
|
|
3
|
+
/**
|
|
4
|
+
* Internationalization key type declaration, plugins can extend through declaration merging
|
|
5
|
+
*/
|
|
6
|
+
export type LocaleType = typeof import("../locale").default;
|
|
7
|
+
type FlattenKeys<T, Prefix extends string = ''> = {
|
|
8
|
+
[K in keyof T & string]: T[K] extends string ? Prefix extends '' ? K : `${Prefix}.${K}` : T[K] extends Record<string, any> ? FlattenKeys<T[K], Prefix extends '' ? K : `${Prefix}.${K}`> : never;
|
|
9
|
+
}[keyof T & string];
|
|
10
|
+
export type TFunction = <TKey extends FlattenKeys<LocaleType>>(key: TKey, options?: Record<string, string | number>) => string;
|
|
11
|
+
export type ILocaleKeys = Record<FlattenKeys<LocaleType>, string>;
|
|
12
|
+
/**
|
|
13
|
+
* Service ID type
|
|
14
|
+
*/
|
|
15
|
+
export type IServiceID<Service> = {
|
|
16
|
+
readonly __serviceId: string;
|
|
17
|
+
__serviceType?: Service;
|
|
18
|
+
};
|
|
19
|
+
export interface IKernelEventMap {
|
|
20
|
+
/**
|
|
21
|
+
* Editor error event
|
|
22
|
+
*/
|
|
23
|
+
error: (error: Error) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Initialization event
|
|
26
|
+
* @param editor Lexical editor instance
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
initialized: (editor: LexicalEditor) => void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* External API
|
|
33
|
+
*/
|
|
34
|
+
export interface IEditor {
|
|
35
|
+
/**
|
|
36
|
+
* Lose focus
|
|
37
|
+
*/
|
|
38
|
+
blur(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Destroy editor instance
|
|
41
|
+
*/
|
|
42
|
+
destroy(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Execute editor commands to manipulate editor content
|
|
45
|
+
* @param type
|
|
46
|
+
* @param payload
|
|
47
|
+
*/
|
|
48
|
+
dispatchCommand<TCommand extends LexicalCommand<unknown>>(type: TCommand, payload: CommandPayloadType<TCommand>): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Focus editor
|
|
51
|
+
*/
|
|
52
|
+
focus(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Get editor content of specified type
|
|
55
|
+
*/
|
|
56
|
+
getDocument(type: string): DataSource | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Get Lexical editor instance
|
|
59
|
+
*/
|
|
60
|
+
getLexicalEditor(): LexicalEditor | null;
|
|
61
|
+
/**
|
|
62
|
+
* Get document editor root node
|
|
63
|
+
*/
|
|
64
|
+
getRootElement(): HTMLElement | null;
|
|
65
|
+
/**
|
|
66
|
+
* Get editor theme
|
|
67
|
+
*/
|
|
68
|
+
getTheme(): Record<string, string | Record<string, string>>;
|
|
69
|
+
/**
|
|
70
|
+
* Remove editor event listener
|
|
71
|
+
* @param event
|
|
72
|
+
* @param listener
|
|
73
|
+
*/
|
|
74
|
+
off<T extends keyof IKernelEventMap>(event: T, listener: IKernelEventMap[T]): this;
|
|
75
|
+
/**
|
|
76
|
+
* Add editor event listener
|
|
77
|
+
* @param event
|
|
78
|
+
* @param listener
|
|
79
|
+
*/
|
|
80
|
+
on<T extends keyof IKernelEventMap>(event: T, listener: IKernelEventMap[T]): this;
|
|
81
|
+
/**
|
|
82
|
+
* Listen to event once, automatically remove listener after trigger
|
|
83
|
+
* @param event
|
|
84
|
+
* @param listener
|
|
85
|
+
*/
|
|
86
|
+
once<T extends keyof IKernelEventMap>(event: T, listener: IKernelEventMap[T]): this;
|
|
87
|
+
/**
|
|
88
|
+
* Register internationalization text
|
|
89
|
+
* @param locale Internationalization text object
|
|
90
|
+
*/
|
|
91
|
+
registerLocale(locale: Partial<Record<keyof ILocaleKeys, string>>): void;
|
|
92
|
+
/**
|
|
93
|
+
* Register editor plugin
|
|
94
|
+
*/
|
|
95
|
+
registerPlugin<T>(plugin: IEditorPluginConstructor<T>, config?: T): IEditor;
|
|
96
|
+
/**
|
|
97
|
+
* Register multiple editor plugins
|
|
98
|
+
*/
|
|
99
|
+
registerPlugins(plugins: Array<IPlugin>): IEditor;
|
|
100
|
+
/**
|
|
101
|
+
* Get editor Service, usually provided by plugins to extend certain functionalities
|
|
102
|
+
* @param serviceId
|
|
103
|
+
*/
|
|
104
|
+
requireService<T>(serviceId: IServiceID<T>): T | null;
|
|
105
|
+
/**
|
|
106
|
+
* Set editor content, type is content type, content is content data
|
|
107
|
+
* @param type
|
|
108
|
+
* @param content
|
|
109
|
+
*/
|
|
110
|
+
setDocument(type: string, content: any): void;
|
|
111
|
+
/**
|
|
112
|
+
* Set document editor root node
|
|
113
|
+
* @param dom
|
|
114
|
+
*/
|
|
115
|
+
setRootElement(dom: HTMLElement): LexicalEditor;
|
|
116
|
+
/**
|
|
117
|
+
* Get translation text
|
|
118
|
+
* @param key Translation key
|
|
119
|
+
* @param params Parameter replacement
|
|
120
|
+
*/
|
|
121
|
+
t<K extends keyof ILocaleKeys>(key: K, params?: Record<string, any>): string;
|
|
122
|
+
/**
|
|
123
|
+
* Update editor theme
|
|
124
|
+
* @param key
|
|
125
|
+
* @param value
|
|
126
|
+
*/
|
|
127
|
+
updateTheme(key: string, value: string | Record<string, string>): void;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* API provided to plugins
|
|
131
|
+
*/
|
|
132
|
+
export interface IEditorKernel extends IEditor {
|
|
133
|
+
/**
|
|
134
|
+
* Get editor Node decorator for specific Node rendering
|
|
135
|
+
* @param name
|
|
136
|
+
*/
|
|
137
|
+
getDecorator(name: string): ((_node: DecoratorNode<any>, _editor: LexicalEditor) => any) | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* Register data source for multi-format data conversion
|
|
140
|
+
* @param dataSource
|
|
141
|
+
*/
|
|
142
|
+
registerDataSource(dataSource: DataSource): void;
|
|
143
|
+
/**
|
|
144
|
+
* Register editor node decorator
|
|
145
|
+
* @param name
|
|
146
|
+
* @param decorator
|
|
147
|
+
*/
|
|
148
|
+
registerDecorator(name: string, decorator: (_node: DecoratorNode<any>, _editor: LexicalEditor) => any): void;
|
|
149
|
+
/**
|
|
150
|
+
* Register Lexical Node
|
|
151
|
+
* @param nodes
|
|
152
|
+
*/
|
|
153
|
+
registerNodes(nodes: Array<LexicalNodeConfig>): void;
|
|
154
|
+
/**
|
|
155
|
+
* Register service
|
|
156
|
+
* @param serviceId
|
|
157
|
+
* @param service
|
|
158
|
+
*/
|
|
159
|
+
registerService<T>(serviceId: IServiceID<T>, service: T): void;
|
|
160
|
+
/**
|
|
161
|
+
* Register theme
|
|
162
|
+
* @param themes
|
|
163
|
+
*/
|
|
164
|
+
registerThemes(themes: Record<string, any>): void;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Plugin interface
|
|
168
|
+
*/
|
|
169
|
+
export interface IEditorPlugin<IConfig> {
|
|
170
|
+
config?: IConfig;
|
|
171
|
+
/**
|
|
172
|
+
* Editor destruction
|
|
173
|
+
*/
|
|
174
|
+
destroy(): void;
|
|
175
|
+
/**
|
|
176
|
+
* After Lexical editor instantiation
|
|
177
|
+
* @param editor Lexical editor instance
|
|
178
|
+
*/
|
|
179
|
+
onInit?(editor: LexicalEditor): void;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Plugin class interface
|
|
183
|
+
*/
|
|
184
|
+
export interface IEditorPluginConstructor<IConfig> {
|
|
185
|
+
readonly pluginName: string;
|
|
186
|
+
new (kernel: IEditorKernel, config?: IConfig): IEditorPlugin<IConfig>;
|
|
187
|
+
}
|
|
188
|
+
export type IPlugin<T = any> = IEditorPluginConstructor<T> | [IEditorPluginConstructor<T>, T?];
|
|
189
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { EditorState, LexicalEditor, LexicalNode, NodeKey } from 'lexical';
|
|
2
|
+
import type { IEditorKernel, IServiceID } from "../types";
|
|
3
|
+
export declare const DOM_ELEMENT_TYPE = 1;
|
|
4
|
+
export declare const DOM_TEXT_TYPE = 3;
|
|
5
|
+
export declare const DOM_DOCUMENT_TYPE = 9;
|
|
6
|
+
export declare const DOM_DOCUMENT_FRAGMENT_TYPE = 11;
|
|
7
|
+
export declare function genServiceId<T>(name: string): IServiceID<T>;
|
|
8
|
+
export declare const noop: () => void;
|
|
9
|
+
export declare function createEmptyEditorState(): EditorState;
|
|
10
|
+
export declare function assert(cond?: boolean, message?: string): asserts cond;
|
|
11
|
+
export declare function getNodeKeyFromDOMNode(dom: Node, editor: LexicalEditor): NodeKey | undefined;
|
|
12
|
+
export declare function $getNodeFromDOMNode(dom: Node, editor: LexicalEditor, editorState?: EditorState): LexicalNode | null;
|
|
13
|
+
/**
|
|
14
|
+
* @param x - The element being tested
|
|
15
|
+
* @returns Returns true if x is a DOM Node, false otherwise.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isDOMNode(x: unknown): x is Node;
|
|
18
|
+
/**
|
|
19
|
+
* @param x - The element being testing
|
|
20
|
+
* @returns Returns true if x is a document fragment, false otherwise.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isDocumentFragment(x: unknown): x is DocumentFragment;
|
|
23
|
+
export declare function getParentElement(node: Node): HTMLElement | null;
|
|
24
|
+
export declare function $getNearestNodeFromDOMNode(startingDOM: Node, editor: LexicalEditor, editorState?: EditorState): LexicalNode | null;
|
|
25
|
+
export declare function getKernelFromEditor(editor: LexicalEditor): IEditorKernel;
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
import { $getNodeByKey, EditorState } from 'lexical';
|
|
3
|
+
// DOM
|
|
4
|
+
export var DOM_ELEMENT_TYPE = 1;
|
|
5
|
+
export var DOM_TEXT_TYPE = 3;
|
|
6
|
+
export var DOM_DOCUMENT_TYPE = 9;
|
|
7
|
+
export var DOM_DOCUMENT_FRAGMENT_TYPE = 11;
|
|
8
|
+
export function genServiceId(name) {
|
|
9
|
+
return {
|
|
10
|
+
__serviceId: name
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export var noop = function noop() {};
|
|
14
|
+
export function createEmptyEditorState() {
|
|
15
|
+
return new EditorState(new Map(), null);
|
|
16
|
+
}
|
|
17
|
+
export function assert(cond, message) {
|
|
18
|
+
if (cond) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
throw new Error(message);
|
|
22
|
+
}
|
|
23
|
+
export function getNodeKeyFromDOMNode(dom, editor) {
|
|
24
|
+
var prop = "__lexicalKey_".concat(editor._key);
|
|
25
|
+
return dom[prop];
|
|
26
|
+
}
|
|
27
|
+
export function $getNodeFromDOMNode(dom, editor, editorState) {
|
|
28
|
+
var key = getNodeKeyFromDOMNode(dom, editor);
|
|
29
|
+
if (key !== undefined) {
|
|
30
|
+
return $getNodeByKey(key, editorState);
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param x - The element being tested
|
|
37
|
+
* @returns Returns true if x is a DOM Node, false otherwise.
|
|
38
|
+
*/
|
|
39
|
+
export function isDOMNode(x) {
|
|
40
|
+
return _typeof(x) === 'object' && x !== null && 'nodeType' in x && typeof x.nodeType === 'number';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param x - The element being testing
|
|
45
|
+
* @returns Returns true if x is a document fragment, false otherwise.
|
|
46
|
+
*/
|
|
47
|
+
export function isDocumentFragment(x) {
|
|
48
|
+
return isDOMNode(x) && x.nodeType === DOM_DOCUMENT_FRAGMENT_TYPE;
|
|
49
|
+
}
|
|
50
|
+
export function getParentElement(node) {
|
|
51
|
+
var parentElement = node.assignedSlot || node.parentElement;
|
|
52
|
+
return isDocumentFragment(parentElement) ? parentElement.host : parentElement;
|
|
53
|
+
}
|
|
54
|
+
export function $getNearestNodeFromDOMNode(startingDOM, editor, editorState) {
|
|
55
|
+
var dom = startingDOM;
|
|
56
|
+
while (dom !== null) {
|
|
57
|
+
var node = $getNodeFromDOMNode(dom, editor, editorState);
|
|
58
|
+
if (node !== null) {
|
|
59
|
+
return node;
|
|
60
|
+
}
|
|
61
|
+
dom = getParentElement(dom);
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
export function getKernelFromEditor(editor) {
|
|
66
|
+
var _editor$_createEditor;
|
|
67
|
+
// @ts-expect-error __kernel is injected into the lexical editor instance
|
|
68
|
+
return ((_editor$_createEditor = editor._createEditorArgs) === null || _editor$_createEditor === void 0 ? void 0 : _editor$_createEditor.__kernel) || editor._kernel;
|
|
69
|
+
}
|
package/es/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './editor-kernel';
|
|
2
|
+
export * from './editor-kernel/react';
|
|
3
|
+
export * from './plugins/codeblock';
|
|
4
|
+
export * from './plugins/common';
|
|
5
|
+
export * from './plugins/file';
|
|
6
|
+
export * from './plugins/hr';
|
|
7
|
+
export * from './plugins/image';
|
|
8
|
+
export * from './plugins/link';
|
|
9
|
+
export * from './plugins/list';
|
|
10
|
+
export * from './plugins/mention';
|
|
11
|
+
export * from './plugins/slash';
|
|
12
|
+
export * from './plugins/table';
|
|
13
|
+
export * from './plugins/upload';
|
|
14
|
+
export type { IEditor } from './types';
|
package/es/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./editor-kernel";
|
|
2
|
+
export * from "./editor-kernel/react";
|
|
3
|
+
export * from "./plugins/codeblock";
|
|
4
|
+
export * from "./plugins/common";
|
|
5
|
+
export * from "./plugins/file";
|
|
6
|
+
export * from "./plugins/hr";
|
|
7
|
+
export * from "./plugins/image";
|
|
8
|
+
export * from "./plugins/link";
|
|
9
|
+
export * from "./plugins/list";
|
|
10
|
+
export * from "./plugins/mention";
|
|
11
|
+
export * from "./plugins/slash";
|
|
12
|
+
export * from "./plugins/table";
|
|
13
|
+
export * from "./plugins/upload";
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
file: {
|
|
3
|
+
error: string;
|
|
4
|
+
uploading: string;
|
|
5
|
+
};
|
|
6
|
+
image: {
|
|
7
|
+
broken: string;
|
|
8
|
+
};
|
|
9
|
+
link: {
|
|
10
|
+
edit: string;
|
|
11
|
+
open: string;
|
|
12
|
+
placeholder: string;
|
|
13
|
+
unlink: string;
|
|
14
|
+
};
|
|
15
|
+
table: {
|
|
16
|
+
delete: string;
|
|
17
|
+
deleteColumn: string;
|
|
18
|
+
deleteRow: string;
|
|
19
|
+
insertColumnLeft: string;
|
|
20
|
+
insertColumnRight: string;
|
|
21
|
+
insertRowAbove: string;
|
|
22
|
+
insertRowBelow: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export default _default;
|