@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,26 @@
|
|
|
1
|
+
import { DOMConversionMap, DOMExportOutput, DecoratorNode, EditorConfig, LexicalEditor, LexicalNode, LexicalUpdateJSON, SerializedLexicalNode, Spread } from 'lexical';
|
|
2
|
+
export type SerializedMentionNode = Spread<{
|
|
3
|
+
extra?: Record<string, unknown>;
|
|
4
|
+
label?: string;
|
|
5
|
+
}, SerializedLexicalNode>;
|
|
6
|
+
export declare class MentionNode extends DecoratorNode<any> {
|
|
7
|
+
static getType(): string;
|
|
8
|
+
static clone(node: MentionNode): MentionNode;
|
|
9
|
+
static importJSON(serializedNode: SerializedMentionNode): MentionNode;
|
|
10
|
+
static importDOM(): DOMConversionMap | null;
|
|
11
|
+
__label: string;
|
|
12
|
+
__extra: Record<string, unknown>;
|
|
13
|
+
constructor(label?: string, extra?: Record<string, unknown>, key?: string);
|
|
14
|
+
get label(): string;
|
|
15
|
+
get extra(): Record<string, unknown>;
|
|
16
|
+
exportDOM(): DOMExportOutput;
|
|
17
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
18
|
+
getTextContent(): string;
|
|
19
|
+
isInline(): true;
|
|
20
|
+
updateDOM(): boolean;
|
|
21
|
+
exportJSON(): SerializedMentionNode;
|
|
22
|
+
updateFromJSON(serializedNode: LexicalUpdateJSON<SerializedMentionNode>): this;
|
|
23
|
+
decorate(editor: LexicalEditor): any;
|
|
24
|
+
}
|
|
25
|
+
export declare function $createMentionNode(label?: string, extra?: Record<string, unknown>): MentionNode;
|
|
26
|
+
export declare function $isMentionNode(node: LexicalNode): node is MentionNode;
|
|
@@ -0,0 +1,143 @@
|
|
|
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
|
+
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); } }
|
|
6
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
7
|
+
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
|
8
|
+
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
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
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
20
|
+
import { addClassNamesToElement } from '@lexical/utils';
|
|
21
|
+
import { $applyNodeReplacement, DecoratorNode } from 'lexical';
|
|
22
|
+
import { getKernelFromEditor } from "../../../editor-kernel/utils";
|
|
23
|
+
export var MentionNode = /*#__PURE__*/function (_DecoratorNode) {
|
|
24
|
+
_inherits(MentionNode, _DecoratorNode);
|
|
25
|
+
var _super = _createSuper(MentionNode);
|
|
26
|
+
function MentionNode() {
|
|
27
|
+
var _this;
|
|
28
|
+
var label = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
29
|
+
var extra = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
30
|
+
var key = arguments.length > 2 ? arguments[2] : undefined;
|
|
31
|
+
_classCallCheck(this, MentionNode);
|
|
32
|
+
_this = _super.call(this, key);
|
|
33
|
+
_defineProperty(_assertThisInitialized(_this), "__label", void 0);
|
|
34
|
+
_defineProperty(_assertThisInitialized(_this), "__extra", void 0);
|
|
35
|
+
_this.__label = label;
|
|
36
|
+
_this.__extra = extra;
|
|
37
|
+
return _this;
|
|
38
|
+
}
|
|
39
|
+
_createClass(MentionNode, [{
|
|
40
|
+
key: "label",
|
|
41
|
+
get: function get() {
|
|
42
|
+
return this.__label;
|
|
43
|
+
}
|
|
44
|
+
}, {
|
|
45
|
+
key: "extra",
|
|
46
|
+
get: function get() {
|
|
47
|
+
return this.__extra;
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
50
|
+
key: "exportDOM",
|
|
51
|
+
value: function exportDOM() {
|
|
52
|
+
return {
|
|
53
|
+
element: document.createElement('span')
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}, {
|
|
57
|
+
key: "createDOM",
|
|
58
|
+
value: function createDOM(config) {
|
|
59
|
+
var element = document.createElement('span');
|
|
60
|
+
addClassNamesToElement(element, config.theme.mention);
|
|
61
|
+
return element;
|
|
62
|
+
}
|
|
63
|
+
}, {
|
|
64
|
+
key: "getTextContent",
|
|
65
|
+
value: function getTextContent() {
|
|
66
|
+
return this.label;
|
|
67
|
+
}
|
|
68
|
+
}, {
|
|
69
|
+
key: "isInline",
|
|
70
|
+
value: function isInline() {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
}, {
|
|
74
|
+
key: "updateDOM",
|
|
75
|
+
value: function updateDOM() {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}, {
|
|
79
|
+
key: "exportJSON",
|
|
80
|
+
value: function exportJSON() {
|
|
81
|
+
return _objectSpread(_objectSpread({}, _get(_getPrototypeOf(MentionNode.prototype), "exportJSON", this).call(this)), {}, {
|
|
82
|
+
extra: this.extra,
|
|
83
|
+
label: this.label
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}, {
|
|
87
|
+
key: "updateFromJSON",
|
|
88
|
+
value: function updateFromJSON(serializedNode) {
|
|
89
|
+
var node = _get(_getPrototypeOf(MentionNode.prototype), "updateFromJSON", this).call(this, serializedNode);
|
|
90
|
+
this.__label = serializedNode.label || '';
|
|
91
|
+
this.__extra = serializedNode.extra || {};
|
|
92
|
+
return node;
|
|
93
|
+
}
|
|
94
|
+
}, {
|
|
95
|
+
key: "decorate",
|
|
96
|
+
value: function decorate(editor) {
|
|
97
|
+
var _getKernelFromEditor, _getKernelFromEditor$;
|
|
98
|
+
return ((_getKernelFromEditor = getKernelFromEditor(editor)) === null || _getKernelFromEditor === void 0 || (_getKernelFromEditor$ = _getKernelFromEditor.getDecorator('mention')) === null || _getKernelFromEditor$ === void 0 ? void 0 : _getKernelFromEditor$(this, editor)) || null;
|
|
99
|
+
}
|
|
100
|
+
}], [{
|
|
101
|
+
key: "getType",
|
|
102
|
+
value: function getType() {
|
|
103
|
+
return 'mention';
|
|
104
|
+
}
|
|
105
|
+
}, {
|
|
106
|
+
key: "clone",
|
|
107
|
+
value: function clone(node) {
|
|
108
|
+
return new MentionNode(node.__label, node.__extra, node.__key);
|
|
109
|
+
}
|
|
110
|
+
}, {
|
|
111
|
+
key: "importJSON",
|
|
112
|
+
value: function importJSON(serializedNode) {
|
|
113
|
+
return $createMentionNode().updateFromJSON(serializedNode);
|
|
114
|
+
}
|
|
115
|
+
}, {
|
|
116
|
+
key: "importDOM",
|
|
117
|
+
value: function importDOM() {
|
|
118
|
+
return {
|
|
119
|
+
span: function span(node) {
|
|
120
|
+
if (node.classList.contains('mention')) {
|
|
121
|
+
return {
|
|
122
|
+
conversion: $convertMentionElement,
|
|
123
|
+
priority: 0
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}]);
|
|
131
|
+
return MentionNode;
|
|
132
|
+
}(DecoratorNode);
|
|
133
|
+
export function $createMentionNode(label, extra) {
|
|
134
|
+
return $applyNodeReplacement(new MentionNode(label, extra));
|
|
135
|
+
}
|
|
136
|
+
function $convertMentionElement() {
|
|
137
|
+
return {
|
|
138
|
+
node: $createMentionNode()
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
export function $isMentionNode(node) {
|
|
142
|
+
return node.getType() === MentionNode.getType();
|
|
143
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LexicalEditor } from 'lexical';
|
|
2
|
+
import type { IEditorPluginConstructor } from "../../../types";
|
|
3
|
+
import { MentionNode } from '../node/MentionNode';
|
|
4
|
+
export interface MentionPluginOptions {
|
|
5
|
+
decorator: (node: MentionNode, editor: LexicalEditor) => any;
|
|
6
|
+
markdownWriter?: (file: MentionNode) => string;
|
|
7
|
+
theme?: {
|
|
8
|
+
mention?: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare const MentionPlugin: IEditorPluginConstructor<MentionPluginOptions>;
|
|
@@ -0,0 +1,61 @@
|
|
|
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
+
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); } }
|
|
5
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
+
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); }
|
|
7
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
8
|
+
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); }; }
|
|
9
|
+
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); }
|
|
10
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
11
|
+
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; } }
|
|
12
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
13
|
+
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; }
|
|
14
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
15
|
+
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); }
|
|
16
|
+
import { KernelPlugin } from "../../../editor-kernel/plugin";
|
|
17
|
+
import { IMarkdownShortCutService } from "../../markdown";
|
|
18
|
+
import { registerMentionCommand } from "../command";
|
|
19
|
+
import { $isMentionNode, MentionNode } from "../node/MentionNode";
|
|
20
|
+
import { registerMentionNodeSelectionObserver } from "./register";
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
23
|
+
|
|
24
|
+
export var MentionPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
25
|
+
_inherits(MentionPlugin, _KernelPlugin);
|
|
26
|
+
var _super = _createSuper(MentionPlugin);
|
|
27
|
+
function MentionPlugin(kernel, config) {
|
|
28
|
+
var _kernel$requireServic;
|
|
29
|
+
var _this;
|
|
30
|
+
_classCallCheck(this, MentionPlugin);
|
|
31
|
+
_this = _super.call(this);
|
|
32
|
+
// Register the file node
|
|
33
|
+
_this.kernel = kernel;
|
|
34
|
+
_this.config = config;
|
|
35
|
+
kernel.registerNodes([MentionNode]);
|
|
36
|
+
if (config !== null && config !== void 0 && config.theme) {
|
|
37
|
+
kernel.registerThemes(config === null || config === void 0 ? void 0 : config.theme);
|
|
38
|
+
}
|
|
39
|
+
kernel.registerDecorator(MentionNode.getType(), function (node, editor) {
|
|
40
|
+
return config !== null && config !== void 0 && config.decorator ? config.decorator(node, editor) : null;
|
|
41
|
+
});
|
|
42
|
+
(_kernel$requireServic = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic === void 0 || _kernel$requireServic.registerMarkdownWriter(MentionNode.getType(), function (ctx, node) {
|
|
43
|
+
if ($isMentionNode(node)) {
|
|
44
|
+
if (config !== null && config !== void 0 && config.markdownWriter) {
|
|
45
|
+
ctx.appendLine(config.markdownWriter(node));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
ctx.appendLine("".concat(node.label));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return _this;
|
|
52
|
+
}
|
|
53
|
+
_createClass(MentionPlugin, [{
|
|
54
|
+
key: "onInit",
|
|
55
|
+
value: function onInit(editor) {
|
|
56
|
+
this.register(registerMentionCommand(editor));
|
|
57
|
+
this.register(registerMentionNodeSelectionObserver(editor));
|
|
58
|
+
}
|
|
59
|
+
}]);
|
|
60
|
+
return MentionPlugin;
|
|
61
|
+
}(KernelPlugin), _defineProperty(_class, "pluginName", 'MentionPlugin'), _class);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { $getSelection, $isNodeSelection, $isRangeSelection } from 'lexical';
|
|
2
|
+
import { $isMentionNode } from "../node/MentionNode";
|
|
3
|
+
export function registerMentionNodeSelectionObserver(editor) {
|
|
4
|
+
var selectMentionKeys = [];
|
|
5
|
+
return editor.registerUpdateListener(function (_ref) {
|
|
6
|
+
var editorState = _ref.editorState;
|
|
7
|
+
var selection = editorState.read(function () {
|
|
8
|
+
return $getSelection();
|
|
9
|
+
});
|
|
10
|
+
var newSelectMentionKeys = [];
|
|
11
|
+
if ($isNodeSelection(selection)) {
|
|
12
|
+
var nodes = editorState.read(function () {
|
|
13
|
+
return selection.getNodes();
|
|
14
|
+
});
|
|
15
|
+
nodes.forEach(function (node) {
|
|
16
|
+
if (node.getType() === 'mention') {
|
|
17
|
+
newSelectMentionKeys.push(node.getKey());
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
} else if ($isRangeSelection(selection) && !selection.isCollapsed()) {
|
|
21
|
+
editorState.read(function () {
|
|
22
|
+
selection.getNodes().forEach(function (node) {
|
|
23
|
+
if ($isMentionNode(node)) {
|
|
24
|
+
newSelectMentionKeys.push(node.getKey());
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
var removeKeys = selectMentionKeys.filter(function (key) {
|
|
30
|
+
return !newSelectMentionKeys.includes(key);
|
|
31
|
+
});
|
|
32
|
+
var addKeys = newSelectMentionKeys.filter(function (key) {
|
|
33
|
+
return !selectMentionKeys.includes(key);
|
|
34
|
+
});
|
|
35
|
+
selectMentionKeys.length = 0;
|
|
36
|
+
selectMentionKeys.push.apply(selectMentionKeys, newSelectMentionKeys);
|
|
37
|
+
removeKeys.forEach(function (key) {
|
|
38
|
+
var _editor$getElementByK;
|
|
39
|
+
(_editor$getElementByK = editor.getElementByKey(key)) === null || _editor$getElementByK === void 0 || _editor$getElementByK.classList.remove('selected');
|
|
40
|
+
});
|
|
41
|
+
addKeys.forEach(function (key) {
|
|
42
|
+
var _editor$getElementByK2;
|
|
43
|
+
(_editor$getElementByK2 = editor.getElementByKey(key)) === null || _editor$getElementByK2 === void 0 || _editor$getElementByK2.classList.add('selected');
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
8
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
9
|
+
import { useLayoutEffect } from 'react';
|
|
10
|
+
import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
|
|
11
|
+
import { MarkdownPlugin } from "../../markdown";
|
|
12
|
+
import { MentionPlugin } from "../plugin";
|
|
13
|
+
import Mention from "./components/Mention";
|
|
14
|
+
import { useStyles } from "./style";
|
|
15
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
|
+
var ReactMentionPlugin = function ReactMentionPlugin(_ref) {
|
|
17
|
+
var className = _ref.className,
|
|
18
|
+
theme = _ref.theme,
|
|
19
|
+
markdownWriter = _ref.markdownWriter;
|
|
20
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
21
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
22
|
+
editor = _useLexicalComposerCo2[0];
|
|
23
|
+
var _useStyles = useStyles(),
|
|
24
|
+
styles = _useStyles.styles;
|
|
25
|
+
useLayoutEffect(function () {
|
|
26
|
+
editor.registerPlugin(MarkdownPlugin);
|
|
27
|
+
editor.registerPlugin(MentionPlugin, {
|
|
28
|
+
decorator: function decorator(node, editor) {
|
|
29
|
+
return /*#__PURE__*/_jsx(Mention, {
|
|
30
|
+
className: className,
|
|
31
|
+
editor: editor,
|
|
32
|
+
node: node
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
markdownWriter: markdownWriter,
|
|
36
|
+
theme: theme || styles
|
|
37
|
+
});
|
|
38
|
+
}, [editor]);
|
|
39
|
+
return null;
|
|
40
|
+
};
|
|
41
|
+
ReactMentionPlugin.displayName = 'ReactMentionPlugin';
|
|
42
|
+
export default ReactMentionPlugin;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { LexicalEditor } from 'lexical';
|
|
3
|
+
import { MentionNode } from '../../node/MentionNode';
|
|
4
|
+
declare const Mention: import("react").NamedExoticComponent<{
|
|
5
|
+
className?: string | undefined;
|
|
6
|
+
editor: LexicalEditor;
|
|
7
|
+
node: MentionNode;
|
|
8
|
+
}>;
|
|
9
|
+
export default Mention;
|
|
@@ -0,0 +1,39 @@
|
|
|
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 { CLICK_COMMAND, COMMAND_PRIORITY_LOW } from 'lexical';
|
|
8
|
+
import { memo, useCallback, useEffect, useRef } from 'react';
|
|
9
|
+
import { useLexicalNodeSelection } from "../../../../editor-kernel/react/useLexicalNodeSelection";
|
|
10
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
var Mention = /*#__PURE__*/memo(function (_ref) {
|
|
12
|
+
var node = _ref.node,
|
|
13
|
+
editor = _ref.editor,
|
|
14
|
+
className = _ref.className;
|
|
15
|
+
var spanRef = useRef(null);
|
|
16
|
+
var _useLexicalNodeSelect = useLexicalNodeSelection(node.getKey()),
|
|
17
|
+
_useLexicalNodeSelect2 = _slicedToArray(_useLexicalNodeSelect, 3),
|
|
18
|
+
setSelected = _useLexicalNodeSelect2[1],
|
|
19
|
+
clearSelection = _useLexicalNodeSelect2[2];
|
|
20
|
+
var onClick = useCallback(function (payload) {
|
|
21
|
+
if (payload.target === spanRef.current) {
|
|
22
|
+
clearSelection();
|
|
23
|
+
setSelected(true);
|
|
24
|
+
return true; // Indicate that the click was handled
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}, [clearSelection, setSelected]);
|
|
28
|
+
useEffect(function () {
|
|
29
|
+
// Perform any necessary side effects here
|
|
30
|
+
return editor.registerCommand(CLICK_COMMAND, onClick, COMMAND_PRIORITY_LOW);
|
|
31
|
+
}, [editor, node, onClick]);
|
|
32
|
+
return /*#__PURE__*/_jsxs("span", {
|
|
33
|
+
className: className,
|
|
34
|
+
ref: spanRef,
|
|
35
|
+
children: ["@", node.label]
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
Mention.displayName = 'Mention';
|
|
39
|
+
export default Mention;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ReactMentionPlugin } from "./ReactMentionPlugin";
|
|
@@ -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
|
+
mention: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n user-select: none;\n\n position: relative;\n\n display: inline;\n\n margin-inline: 0.25em;\n padding-block: 0.2em;\n padding-inline: 0.4em;\n border: 1px solid ", ";\n border-radius: 0.25em;\n\n font-size: 0.875em;\n line-height: 1;\n color: ", ";\n word-break: break-word;\n white-space: break-spaces;\n\n background: ", ";\n\n &.selected {\n color: #000;\n background: ", ";\n }\n "])), token.colorInfoFillTertiary, token.colorInfo, token.colorInfoFillTertiary, token.yellow)
|
|
10
|
+
};
|
|
11
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { IEditorPluginConstructor } from "../../../types";
|
|
2
|
+
import { ISlashOption, SlashOptions } from '../service/i-slash-service';
|
|
3
|
+
export interface ITriggerContext {
|
|
4
|
+
getRect: () => DOMRect;
|
|
5
|
+
items: Array<ISlashOption> | ((search: {
|
|
6
|
+
leadOffset: number;
|
|
7
|
+
matchingString: string;
|
|
8
|
+
replaceableString: string;
|
|
9
|
+
} | null) => Promise<Array<ISlashOption>>);
|
|
10
|
+
lastIndex: number;
|
|
11
|
+
match?: {
|
|
12
|
+
leadOffset: number;
|
|
13
|
+
matchingString: string;
|
|
14
|
+
replaceableString: string;
|
|
15
|
+
} | null;
|
|
16
|
+
trigger: SlashOptions['trigger'];
|
|
17
|
+
}
|
|
18
|
+
export interface SlashPluginOptions {
|
|
19
|
+
slashOptions?: SlashOptions[];
|
|
20
|
+
triggerClose: () => void;
|
|
21
|
+
triggerOpen: (ctx: ITriggerContext) => void;
|
|
22
|
+
}
|
|
23
|
+
export declare const SlashPlugin: IEditorPluginConstructor<SlashPluginOptions>;
|
|
@@ -0,0 +1,132 @@
|
|
|
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
+
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); } }
|
|
5
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
+
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
|
7
|
+
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
8
|
+
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); }
|
|
9
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
10
|
+
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); }; }
|
|
11
|
+
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); }
|
|
12
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
13
|
+
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; } }
|
|
14
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
15
|
+
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; }
|
|
16
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
17
|
+
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); }
|
|
18
|
+
import { $getSelection, $isRangeSelection } from 'lexical';
|
|
19
|
+
import { KernelPlugin } from "../../../editor-kernel/plugin";
|
|
20
|
+
import { ISlashService, SlashService } from "../service/i-slash-service";
|
|
21
|
+
import { getQueryTextForSearch, tryToPositionRange } from "../utils/utils";
|
|
22
|
+
export var SlashPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
23
|
+
_inherits(SlashPlugin, _KernelPlugin);
|
|
24
|
+
var _super = _createSuper(SlashPlugin);
|
|
25
|
+
function SlashPlugin(kernel, config) {
|
|
26
|
+
var _this;
|
|
27
|
+
_classCallCheck(this, SlashPlugin);
|
|
28
|
+
_this = _super.call(this);
|
|
29
|
+
_defineProperty(_assertThisInitialized(_this), "service", null);
|
|
30
|
+
_defineProperty(_assertThisInitialized(_this), "currentSlashTrigger", null);
|
|
31
|
+
_defineProperty(_assertThisInitialized(_this), "currentSlashTriggerIndex", -1);
|
|
32
|
+
_this.config = config;
|
|
33
|
+
_this.service = new SlashService(kernel);
|
|
34
|
+
kernel.registerService(ISlashService, _this.service);
|
|
35
|
+
if (config !== null && config !== void 0 && config.slashOptions) {
|
|
36
|
+
config.slashOptions.forEach(function (option) {
|
|
37
|
+
var _this$service;
|
|
38
|
+
(_this$service = _this.service) === null || _this$service === void 0 || _this$service.registerSlash(option);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return _this;
|
|
42
|
+
}
|
|
43
|
+
_createClass(SlashPlugin, [{
|
|
44
|
+
key: "triggerClose",
|
|
45
|
+
value: function triggerClose() {
|
|
46
|
+
var _this$config;
|
|
47
|
+
(_this$config = this.config) === null || _this$config === void 0 || _this$config.triggerClose();
|
|
48
|
+
this.currentSlashTrigger = null;
|
|
49
|
+
this.currentSlashTriggerIndex = -1;
|
|
50
|
+
}
|
|
51
|
+
}, {
|
|
52
|
+
key: "onInit",
|
|
53
|
+
value: function onInit(editor) {
|
|
54
|
+
var _this2 = this;
|
|
55
|
+
this.register(editor.registerUpdateListener(function () {
|
|
56
|
+
editor.getEditorState().read(function () {
|
|
57
|
+
var _this2$service, _this2$service2, _this2$service3;
|
|
58
|
+
if (!editor.isEditable()) {
|
|
59
|
+
// Trigger close
|
|
60
|
+
_this2.triggerClose();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
var isComposing = editor.isComposing();
|
|
64
|
+
if (isComposing) {
|
|
65
|
+
// Currently typing, do not handle
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
var editorWindow = editor._window || window;
|
|
69
|
+
// Skip on server side
|
|
70
|
+
if (editorWindow === undefined || !editorWindow.document) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
var range = editorWindow.document.createRange();
|
|
74
|
+
var selection = $getSelection();
|
|
75
|
+
var text = getQueryTextForSearch(editor);
|
|
76
|
+
if (!$isRangeSelection(selection) || !selection.isCollapsed() ||
|
|
77
|
+
// Do not trigger inside code
|
|
78
|
+
selection.hasFormat('code') || text === null || range === null || _this2.currentSlashTrigger === null && text.length > 1 && text.at(-2) !== ' ') {
|
|
79
|
+
_this2.triggerClose();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
var triggerText = _this2.currentSlashTrigger;
|
|
83
|
+
if (triggerText === null) {
|
|
84
|
+
triggerText = text.slice(-1);
|
|
85
|
+
_this2.currentSlashTriggerIndex = text.length - 1;
|
|
86
|
+
}
|
|
87
|
+
var lastIndex = text.lastIndexOf(triggerText);
|
|
88
|
+
if (lastIndex < _this2.currentSlashTriggerIndex) {
|
|
89
|
+
_this2.triggerClose();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
var slashOptions = (_this2$service = _this2.service) === null || _this2$service === void 0 ? void 0 : _this2$service.getSlashOptions(triggerText);
|
|
93
|
+
var maxLength = (slashOptions === null || slashOptions === void 0 ? void 0 : slashOptions.maxLength) || 75;
|
|
94
|
+
|
|
95
|
+
// Exceeds maximum length
|
|
96
|
+
if (text.length - lastIndex > maxLength || !slashOptions) {
|
|
97
|
+
_this2.triggerClose();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
var triggerFn = (_this2$service2 = _this2.service) === null || _this2$service2 === void 0 ? void 0 : _this2$service2.getSlashTriggerFn(triggerText);
|
|
101
|
+
var fuse = (_this2$service3 = _this2.service) === null || _this2$service3 === void 0 ? void 0 : _this2$service3.getSlashFuse(triggerText);
|
|
102
|
+
var isRangePositioned = tryToPositionRange(_this2.currentSlashTriggerIndex, range, editorWindow);
|
|
103
|
+
var match = triggerFn === null || triggerFn === void 0 ? void 0 : triggerFn(text.slice(_this2.currentSlashTriggerIndex));
|
|
104
|
+
var finalItems = fuse && match && match.matchingString.length > 0 ? fuse.search(match.matchingString).map(function (result) {
|
|
105
|
+
return result.item;
|
|
106
|
+
}) : slashOptions.items;
|
|
107
|
+
if (isRangePositioned !== null && finalItems.length > 0) {
|
|
108
|
+
var _this2$config;
|
|
109
|
+
_this2.currentSlashTrigger = triggerText;
|
|
110
|
+
(_this2$config = _this2.config) === null || _this2$config === void 0 || _this2$config.triggerOpen({
|
|
111
|
+
getRect: function getRect() {
|
|
112
|
+
return range.getBoundingClientRect();
|
|
113
|
+
},
|
|
114
|
+
items: finalItems,
|
|
115
|
+
lastIndex: lastIndex,
|
|
116
|
+
match: match,
|
|
117
|
+
trigger: slashOptions.trigger
|
|
118
|
+
});
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
_this2.triggerClose();
|
|
122
|
+
});
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
}, {
|
|
126
|
+
key: "destroy",
|
|
127
|
+
value: function destroy() {
|
|
128
|
+
_get(_getPrototypeOf(SlashPlugin.prototype), "destroy", this).call(this);
|
|
129
|
+
}
|
|
130
|
+
}]);
|
|
131
|
+
return SlashPlugin;
|
|
132
|
+
}(KernelPlugin), _defineProperty(_class, "pluginName", 'slash'), _class);
|