@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,228 @@
|
|
|
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 { mergeRegister } from '@lexical/utils';
|
|
10
|
+
import { COMMAND_PRIORITY_NORMAL, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND, KEY_TAB_COMMAND } from 'lexical';
|
|
11
|
+
import { Children, useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
12
|
+
import { useLexicalEditor } from "../../../editor-kernel/react";
|
|
13
|
+
import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
|
|
14
|
+
import { SlashPlugin } from "../plugin/index";
|
|
15
|
+
import { $splitNodeContainingQuery } from "../utils/utils";
|
|
16
|
+
import SlashMenu from "./components/SlashMenu";
|
|
17
|
+
import { setCancelablePromise } from "./utils";
|
|
18
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
|
+
var ReactSlashPlugin = function ReactSlashPlugin(_ref) {
|
|
20
|
+
var children = _ref.children,
|
|
21
|
+
anchorClassName = _ref.anchorClassName;
|
|
22
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
23
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
24
|
+
editor = _useLexicalComposerCo2[0];
|
|
25
|
+
var _useState = useState(false),
|
|
26
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
27
|
+
isOpen = _useState2[0],
|
|
28
|
+
setIsOpen = _useState2[1];
|
|
29
|
+
var _useState3 = useState(false),
|
|
30
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
31
|
+
loading = _useState4[0],
|
|
32
|
+
setLoading = _useState4[1];
|
|
33
|
+
var _useState5 = useState(null),
|
|
34
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
35
|
+
activeKey = _useState6[0],
|
|
36
|
+
setActiveKey = _useState6[1];
|
|
37
|
+
var _useState7 = useState(null),
|
|
38
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
39
|
+
resolution = _useState8[0],
|
|
40
|
+
setResolution = _useState8[1];
|
|
41
|
+
var _useState9 = useState([]),
|
|
42
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
43
|
+
options = _useState10[0],
|
|
44
|
+
setOptions = _useState10[1];
|
|
45
|
+
var _useState11 = useState({
|
|
46
|
+
x: 0,
|
|
47
|
+
y: 0
|
|
48
|
+
}),
|
|
49
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
50
|
+
dropdownPosition = _useState12[0],
|
|
51
|
+
setDropdownPosition = _useState12[1];
|
|
52
|
+
var cancelRef = useRef({
|
|
53
|
+
cancel: function cancel() {}
|
|
54
|
+
});
|
|
55
|
+
var triggerMapRef = useRef(new Map());
|
|
56
|
+
var close = useCallback(function () {
|
|
57
|
+
setIsOpen(false);
|
|
58
|
+
setOptions([]);
|
|
59
|
+
setResolution(null);
|
|
60
|
+
setActiveKey(null);
|
|
61
|
+
}, []);
|
|
62
|
+
var handleActiveKeyChange = useCallback(function (key) {
|
|
63
|
+
setActiveKey(key);
|
|
64
|
+
}, []);
|
|
65
|
+
useLayoutEffect(function () {
|
|
66
|
+
var _Children$map;
|
|
67
|
+
var options = ((_Children$map = Children.map(children, function (child) {
|
|
68
|
+
if (!child) return null;
|
|
69
|
+
var option = child.props;
|
|
70
|
+
triggerMapRef.current.set(option.trigger, option);
|
|
71
|
+
return option;
|
|
72
|
+
})) === null || _Children$map === void 0 ? void 0 : _Children$map.filter(Boolean)) || [];
|
|
73
|
+
editor.registerPlugin(SlashPlugin, {
|
|
74
|
+
slashOptions: options,
|
|
75
|
+
triggerClose: function triggerClose() {
|
|
76
|
+
close();
|
|
77
|
+
cancelRef.current.cancel();
|
|
78
|
+
},
|
|
79
|
+
triggerOpen: function triggerOpen(ctx) {
|
|
80
|
+
setResolution(ctx);
|
|
81
|
+
cancelRef.current.cancel();
|
|
82
|
+
if (Array.isArray(ctx.items)) {
|
|
83
|
+
setOptions(ctx.items);
|
|
84
|
+
if (!activeKey) {
|
|
85
|
+
var _ctx$items;
|
|
86
|
+
// @ts-ignore
|
|
87
|
+
setActiveKey((_ctx$items = ctx.items) === null || _ctx$items === void 0 || (_ctx$items = _ctx$items[0]) === null || _ctx$items === void 0 ? void 0 : _ctx$items.key);
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
setLoading(true);
|
|
91
|
+
var pr = setCancelablePromise(function (resolve, reject) {
|
|
92
|
+
ctx
|
|
93
|
+
// @ts-ignore
|
|
94
|
+
.items(ctx.match || null).then(resolve, reject).finally(function () {
|
|
95
|
+
return setLoading(false);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
pr.promise.then(function (items) {
|
|
99
|
+
var typedItems = items;
|
|
100
|
+
setOptions(typedItems);
|
|
101
|
+
if (!activeKey) {
|
|
102
|
+
var _typedItems$;
|
|
103
|
+
// @ts-ignore
|
|
104
|
+
setActiveKey(typedItems === null || typedItems === void 0 || (_typedItems$ = typedItems[0]) === null || _typedItems$ === void 0 ? void 0 : _typedItems$.key);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
cancelRef.current.cancel = function () {
|
|
108
|
+
pr.cancel();
|
|
109
|
+
setLoading(false);
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
var rect = ctx.getRect();
|
|
113
|
+
setDropdownPosition({
|
|
114
|
+
x: rect.left,
|
|
115
|
+
y: rect.bottom
|
|
116
|
+
});
|
|
117
|
+
setIsOpen(true);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}, [activeKey, editor, close]);
|
|
121
|
+
var handleMenuSelect = useCallback(function (option) {
|
|
122
|
+
// ISlashMenuOption should not have divider type, but adding check for safety
|
|
123
|
+
if ('type' in option && option.type === 'divider') {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
var lexicalEditor = editor.getLexicalEditor();
|
|
127
|
+
if (lexicalEditor && resolution) {
|
|
128
|
+
lexicalEditor.update(function () {
|
|
129
|
+
var _option$onSelect;
|
|
130
|
+
var textNodeContainingQuery = resolution.match ? $splitNodeContainingQuery(resolution.match) : null;
|
|
131
|
+
textNodeContainingQuery === null || textNodeContainingQuery === void 0 || textNodeContainingQuery.remove();
|
|
132
|
+
(_option$onSelect = option.onSelect) === null || _option$onSelect === void 0 || _option$onSelect.call(option, editor, resolution.match ? resolution.match.matchingString : '');
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
var currentTriggerProps = triggerMapRef.current.get((resolution === null || resolution === void 0 ? void 0 : resolution.trigger) || '');
|
|
136
|
+
|
|
137
|
+
// Call the external unified onSelect first if it exists
|
|
138
|
+
if (currentTriggerProps !== null && currentTriggerProps !== void 0 && currentTriggerProps.onSelect) {
|
|
139
|
+
currentTriggerProps.onSelect(editor, option);
|
|
140
|
+
}
|
|
141
|
+
close();
|
|
142
|
+
}, [editor, resolution, close]);
|
|
143
|
+
useLexicalEditor(function (editor) {
|
|
144
|
+
var pureOptions = options.filter(function (item) {
|
|
145
|
+
return !('type' in item && item.type === 'divider') && 'key' in item && Boolean(item.key);
|
|
146
|
+
});
|
|
147
|
+
return mergeRegister(editor.registerCommand(KEY_ARROW_DOWN_COMMAND, function (payload) {
|
|
148
|
+
var event = payload;
|
|
149
|
+
if (pureOptions !== null && pureOptions.length) {
|
|
150
|
+
var currentIndex = activeKey ? pureOptions.findIndex(function (opt) {
|
|
151
|
+
return opt.key === activeKey;
|
|
152
|
+
}) : -1;
|
|
153
|
+
var newIndex = currentIndex === -1 ? 0 : (currentIndex + 1) % pureOptions.length;
|
|
154
|
+
setActiveKey(String(pureOptions[newIndex].key));
|
|
155
|
+
event.preventDefault();
|
|
156
|
+
event.stopImmediatePropagation();
|
|
157
|
+
}
|
|
158
|
+
return true;
|
|
159
|
+
}, COMMAND_PRIORITY_NORMAL), editor.registerCommand(KEY_ARROW_UP_COMMAND, function (payload) {
|
|
160
|
+
var event = payload;
|
|
161
|
+
if (pureOptions !== null && pureOptions.length) {
|
|
162
|
+
var currentIndex = activeKey ? pureOptions.findIndex(function (opt) {
|
|
163
|
+
return opt.key === activeKey;
|
|
164
|
+
}) : -1;
|
|
165
|
+
var newIndex = currentIndex === -1 ? pureOptions.length - 1 : (currentIndex - 1 + pureOptions.length) % pureOptions.length;
|
|
166
|
+
setActiveKey(String(pureOptions[newIndex].key));
|
|
167
|
+
event.preventDefault();
|
|
168
|
+
event.stopImmediatePropagation();
|
|
169
|
+
}
|
|
170
|
+
return true;
|
|
171
|
+
}, COMMAND_PRIORITY_NORMAL), editor.registerCommand(KEY_ESCAPE_COMMAND, function (payload) {
|
|
172
|
+
var event = payload;
|
|
173
|
+
event.preventDefault();
|
|
174
|
+
event.stopImmediatePropagation();
|
|
175
|
+
close();
|
|
176
|
+
return true;
|
|
177
|
+
}, COMMAND_PRIORITY_NORMAL), editor.registerCommand(KEY_TAB_COMMAND, function (payload) {
|
|
178
|
+
var event = payload;
|
|
179
|
+
if (options === null || activeKey === null) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
var selectedOption = options.find(function (opt) {
|
|
183
|
+
return 'key' in opt && opt.key === activeKey;
|
|
184
|
+
});
|
|
185
|
+
if (!selectedOption) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
event.preventDefault();
|
|
189
|
+
event.stopImmediatePropagation();
|
|
190
|
+
handleMenuSelect(selectedOption);
|
|
191
|
+
return true;
|
|
192
|
+
}, COMMAND_PRIORITY_NORMAL), editor.registerCommand(KEY_ENTER_COMMAND, function (event) {
|
|
193
|
+
if (options === null || activeKey === null) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
var selectedOption = options.find(function (opt) {
|
|
197
|
+
return 'key' in opt && opt.key === activeKey;
|
|
198
|
+
});
|
|
199
|
+
if (!selectedOption) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
if (event !== null) {
|
|
203
|
+
event.preventDefault();
|
|
204
|
+
event.stopImmediatePropagation();
|
|
205
|
+
}
|
|
206
|
+
handleMenuSelect(selectedOption);
|
|
207
|
+
return true;
|
|
208
|
+
}, COMMAND_PRIORITY_NORMAL));
|
|
209
|
+
}, [options, activeKey, handleActiveKeyChange, handleMenuSelect]);
|
|
210
|
+
|
|
211
|
+
// Get custom render component if available
|
|
212
|
+
var _ref2 = triggerMapRef.current.get((resolution === null || resolution === void 0 ? void 0 : resolution.trigger) || '') || {},
|
|
213
|
+
CustomRender = _ref2.renderComp;
|
|
214
|
+
return /*#__PURE__*/_jsx(SlashMenu, {
|
|
215
|
+
activeKey: activeKey,
|
|
216
|
+
anchorClassName: anchorClassName,
|
|
217
|
+
customRender: CustomRender,
|
|
218
|
+
loading: loading,
|
|
219
|
+
onActiveKeyChange: handleActiveKeyChange,
|
|
220
|
+
onClose: close,
|
|
221
|
+
onSelect: handleMenuSelect,
|
|
222
|
+
open: isOpen,
|
|
223
|
+
options: options,
|
|
224
|
+
position: dropdownPosition
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
ReactSlashPlugin.displayName = 'ReactSlashPlugin';
|
|
228
|
+
export default ReactSlashPlugin;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type FC } from 'react';
|
|
2
|
+
import type { SlashMenuProps } from '../type';
|
|
3
|
+
/**
|
|
4
|
+
* SlashMenu component - Only responsible for rendering the menu UI
|
|
5
|
+
* All state management and plugin registration is handled by ReactSlashPlugin
|
|
6
|
+
*/
|
|
7
|
+
declare const SlashMenu: FC<SlashMenuProps>;
|
|
8
|
+
export default SlashMenu;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Dropdown } from '@lobehub/ui';
|
|
4
|
+
import { useCallback } from 'react';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
/**
|
|
7
|
+
* SlashMenu component - Only responsible for rendering the menu UI
|
|
8
|
+
* All state management and plugin registration is handled by ReactSlashPlugin
|
|
9
|
+
*/
|
|
10
|
+
var SlashMenu = function SlashMenu(_ref) {
|
|
11
|
+
var activeKey = _ref.activeKey,
|
|
12
|
+
anchorClassName = _ref.anchorClassName,
|
|
13
|
+
CustomRender = _ref.customRender,
|
|
14
|
+
loading = _ref.loading,
|
|
15
|
+
onActiveKeyChange = _ref.onActiveKeyChange,
|
|
16
|
+
onSelect = _ref.onSelect,
|
|
17
|
+
open = _ref.open,
|
|
18
|
+
options = _ref.options,
|
|
19
|
+
position = _ref.position,
|
|
20
|
+
_onClose = _ref.onClose;
|
|
21
|
+
// Adapter for custom render component onSelect
|
|
22
|
+
var customRenderOnSelect = useCallback(function (option) {
|
|
23
|
+
onSelect(option);
|
|
24
|
+
}, [onSelect]);
|
|
25
|
+
var handleMenuClick = useCallback(function (_ref2) {
|
|
26
|
+
var key = _ref2.key;
|
|
27
|
+
var option = options.find(function (item) {
|
|
28
|
+
return 'key' in item && item.key === key;
|
|
29
|
+
});
|
|
30
|
+
if (option) onSelect(option);
|
|
31
|
+
}, [options, onSelect]);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Render the custom component if it exists
|
|
35
|
+
*/
|
|
36
|
+
if (CustomRender) {
|
|
37
|
+
return /*#__PURE__*/_jsx(CustomRender, {
|
|
38
|
+
activeKey: activeKey,
|
|
39
|
+
loading: loading,
|
|
40
|
+
onSelect: customRenderOnSelect,
|
|
41
|
+
open: open,
|
|
42
|
+
options: options,
|
|
43
|
+
setActiveKey: onActiveKeyChange
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return /*#__PURE__*/_jsx("div", {
|
|
47
|
+
style: {
|
|
48
|
+
left: position.x,
|
|
49
|
+
position: 'fixed',
|
|
50
|
+
top: position.y,
|
|
51
|
+
zIndex: 1050
|
|
52
|
+
},
|
|
53
|
+
children: /*#__PURE__*/_jsx(Dropdown, {
|
|
54
|
+
menu: {
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
activeKey: activeKey,
|
|
57
|
+
items: loading ? [{
|
|
58
|
+
disabled: true,
|
|
59
|
+
key: 'loading',
|
|
60
|
+
label: 'Loading...'
|
|
61
|
+
}] : options,
|
|
62
|
+
onClick: handleMenuClick
|
|
63
|
+
},
|
|
64
|
+
open: open,
|
|
65
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
66
|
+
className: anchorClassName
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
SlashMenu.displayName = 'SlashMenu';
|
|
72
|
+
export default SlashMenu;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<import("antd-style").SerializedStyles>;
|
|
@@ -0,0 +1,9 @@
|
|
|
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 css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n background: ", ";\n "])), token.colorBgElevated);
|
|
9
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { FC, ReactElement } from 'react';
|
|
2
|
+
import type { SlashOptions } from "..";
|
|
3
|
+
import type { ISlashMenuOption, ISlashOption } from "../service/i-slash-service";
|
|
4
|
+
import type { IEditor } from "../../../types";
|
|
5
|
+
export interface ReactSlashOptionProps {
|
|
6
|
+
/**
|
|
7
|
+
* Searchable options
|
|
8
|
+
*/
|
|
9
|
+
items?: SlashOptions['items'];
|
|
10
|
+
/**
|
|
11
|
+
* Maximum search length
|
|
12
|
+
* Default is 75
|
|
13
|
+
*/
|
|
14
|
+
maxLength?: number;
|
|
15
|
+
onSelect?: (editor: IEditor, option: ISlashMenuOption) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Custom render component
|
|
18
|
+
*/
|
|
19
|
+
renderComp?: FC<MenuRenderProps>;
|
|
20
|
+
/**
|
|
21
|
+
* Trigger character
|
|
22
|
+
*/
|
|
23
|
+
trigger?: SlashOptions['trigger'];
|
|
24
|
+
}
|
|
25
|
+
export interface MenuRenderProps {
|
|
26
|
+
/**
|
|
27
|
+
* Current active option key
|
|
28
|
+
*/
|
|
29
|
+
activeKey: string | null;
|
|
30
|
+
/**
|
|
31
|
+
* Loading state
|
|
32
|
+
*/
|
|
33
|
+
loading?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Actively trigger selection
|
|
36
|
+
* @param option Currently selected element
|
|
37
|
+
*/
|
|
38
|
+
onSelect?: (option: ISlashMenuOption) => void;
|
|
39
|
+
open?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Currently searched options
|
|
42
|
+
*/
|
|
43
|
+
options: Array<ISlashOption>;
|
|
44
|
+
/**
|
|
45
|
+
* Actively set current active option key
|
|
46
|
+
* @param key
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
setActiveKey: (key: string | null) => void;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* SlashMenu component props - only responsible for rendering
|
|
53
|
+
*/
|
|
54
|
+
export interface SlashMenuProps {
|
|
55
|
+
/** Current active option key */
|
|
56
|
+
activeKey: string | null;
|
|
57
|
+
/** Anchor element className */
|
|
58
|
+
anchorClassName?: string;
|
|
59
|
+
/** Custom render component if provided */
|
|
60
|
+
customRender?: FC<MenuRenderProps>;
|
|
61
|
+
/** Loading state */
|
|
62
|
+
loading: boolean;
|
|
63
|
+
/** Callback to set active key */
|
|
64
|
+
onActiveKeyChange: (key: string | null) => void;
|
|
65
|
+
/** Callback when menu should close */
|
|
66
|
+
onClose: () => void;
|
|
67
|
+
/** Callback when an option is selected */
|
|
68
|
+
onSelect: (option: ISlashMenuOption) => void;
|
|
69
|
+
/** Whether the menu is open */
|
|
70
|
+
open: boolean;
|
|
71
|
+
/** Available options to display */
|
|
72
|
+
options: Array<ISlashOption>;
|
|
73
|
+
/** Menu position */
|
|
74
|
+
position: {
|
|
75
|
+
x: number;
|
|
76
|
+
y: number;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export interface ReactSlashPluginProps {
|
|
80
|
+
anchorClassName?: string;
|
|
81
|
+
children?: (ReactElement<ReactSlashOptionProps> | undefined) | (ReactElement<ReactSlashOptionProps> | undefined)[];
|
|
82
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function setCancelablePromise(executor) {
|
|
2
|
+
var isCancelled = false;
|
|
3
|
+
var promise = new Promise(function (resolve, reject) {
|
|
4
|
+
executor(function (value) {
|
|
5
|
+
if (!isCancelled) {
|
|
6
|
+
resolve(value);
|
|
7
|
+
}
|
|
8
|
+
}, function (reason) {
|
|
9
|
+
if (!isCancelled) {
|
|
10
|
+
reject(reason);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
return {
|
|
15
|
+
cancel: function cancel() {
|
|
16
|
+
isCancelled = true;
|
|
17
|
+
},
|
|
18
|
+
promise: promise
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { DropdownMenuItemType } from '@lobehub/ui';
|
|
2
|
+
import Fuse from 'fuse.js';
|
|
3
|
+
import type { IEditor, IEditorKernel, IServiceID } from "../../../types";
|
|
4
|
+
import { getBasicTypeaheadTriggerMatch } from '../utils/utils';
|
|
5
|
+
export type ISlashDividerOption = {
|
|
6
|
+
type: 'divider';
|
|
7
|
+
};
|
|
8
|
+
export interface ISlashMenuOption extends DropdownMenuItemType {
|
|
9
|
+
onSelect?: (editor: IEditor, matchingString: string) => void;
|
|
10
|
+
}
|
|
11
|
+
export type ISlashOption = ISlashMenuOption | ISlashDividerOption;
|
|
12
|
+
export interface SlashOptions {
|
|
13
|
+
allowWhitespace?: boolean;
|
|
14
|
+
items: Array<ISlashOption> | ((search: {
|
|
15
|
+
leadOffset: number;
|
|
16
|
+
matchingString: string;
|
|
17
|
+
replaceableString: string;
|
|
18
|
+
} | null) => Promise<Array<ISlashOption>>);
|
|
19
|
+
maxLength?: number;
|
|
20
|
+
minLength?: number;
|
|
21
|
+
punctuation?: string;
|
|
22
|
+
trigger: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ISlashService {
|
|
25
|
+
registerSlash(options: SlashOptions): void;
|
|
26
|
+
}
|
|
27
|
+
export declare const ISlashService: IServiceID<ISlashService>;
|
|
28
|
+
export declare class SlashService implements ISlashService {
|
|
29
|
+
private kernel;
|
|
30
|
+
private triggerMap;
|
|
31
|
+
private triggerFnMap;
|
|
32
|
+
private triggerFuseMap;
|
|
33
|
+
constructor(kernel: IEditorKernel);
|
|
34
|
+
registerSlash(options: SlashOptions): void;
|
|
35
|
+
getSlashOptions(trigger: string): SlashOptions | undefined;
|
|
36
|
+
getSlashTriggerFn(trigger: string): ReturnType<typeof getBasicTypeaheadTriggerMatch> | undefined;
|
|
37
|
+
getSlashFuse(trigger: string): Fuse<ISlashOption> | undefined;
|
|
38
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
function _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; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
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); }
|
|
8
|
+
/* eslint-disable no-redeclare */
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-redeclare */
|
|
10
|
+
|
|
11
|
+
import Fuse from 'fuse.js';
|
|
12
|
+
import { genServiceId } from "../../../editor-kernel";
|
|
13
|
+
import { getBasicTypeaheadTriggerMatch } from "../utils/utils";
|
|
14
|
+
export var ISlashService = genServiceId('SlashService');
|
|
15
|
+
export var SlashService = /*#__PURE__*/function () {
|
|
16
|
+
function SlashService(kernel) {
|
|
17
|
+
_classCallCheck(this, SlashService);
|
|
18
|
+
_defineProperty(this, "triggerMap", new Map());
|
|
19
|
+
_defineProperty(this, "triggerFnMap", new Map());
|
|
20
|
+
_defineProperty(this, "triggerFuseMap", new Map());
|
|
21
|
+
this.kernel = kernel;
|
|
22
|
+
}
|
|
23
|
+
// Specific service methods can be added here
|
|
24
|
+
_createClass(SlashService, [{
|
|
25
|
+
key: "registerSlash",
|
|
26
|
+
value: function registerSlash(options) {
|
|
27
|
+
if (this.triggerMap.has(options.trigger)) {
|
|
28
|
+
throw new Error("Slash trigger \"".concat(options.trigger, "\" is already registered."));
|
|
29
|
+
}
|
|
30
|
+
this.triggerMap.set(options.trigger, options);
|
|
31
|
+
this.triggerFnMap.set(options.trigger, getBasicTypeaheadTriggerMatch(options.trigger, {
|
|
32
|
+
allowWhitespace: options.allowWhitespace,
|
|
33
|
+
maxLength: options.maxLength,
|
|
34
|
+
minLength: options.minLength,
|
|
35
|
+
punctuation: options.punctuation
|
|
36
|
+
}));
|
|
37
|
+
if (Array.isArray(options.items)) {
|
|
38
|
+
// Filter out divider items for search functionality
|
|
39
|
+
var searchableItems = options.items.filter(function (item) {
|
|
40
|
+
return !('type' in item) || item.type !== 'divider';
|
|
41
|
+
});
|
|
42
|
+
this.triggerFuseMap.set(options.trigger, new Fuse(searchableItems, {
|
|
43
|
+
keys: ['label', 'value']
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}, {
|
|
48
|
+
key: "getSlashOptions",
|
|
49
|
+
value: function getSlashOptions(trigger) {
|
|
50
|
+
return this.triggerMap.get(trigger);
|
|
51
|
+
}
|
|
52
|
+
}, {
|
|
53
|
+
key: "getSlashTriggerFn",
|
|
54
|
+
value: function getSlashTriggerFn(trigger) {
|
|
55
|
+
return this.triggerFnMap.get(trigger);
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
key: "getSlashFuse",
|
|
59
|
+
value: function getSlashFuse(trigger) {
|
|
60
|
+
return this.triggerFuseMap.get(trigger);
|
|
61
|
+
}
|
|
62
|
+
}]);
|
|
63
|
+
return SlashService;
|
|
64
|
+
}();
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { LexicalEditor, RangeSelection, TextNode } from 'lexical';
|
|
2
|
+
/**
|
|
3
|
+
* Get the text content of the editor up to the anchor point of the selection.
|
|
4
|
+
* Get the text content before the anchor point of the selection
|
|
5
|
+
* @param selection Selection object from Lexical editor
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function getTextUpToAnchor(selection: RangeSelection): string | null;
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param editor Lexical editor instance
|
|
12
|
+
* Get the text content before the selection anchor point in the editor
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare function getQueryTextForSearch(editor: LexicalEditor): string | null;
|
|
16
|
+
export declare function tryToPositionRange(leadOffset: number, range: Range, editorWindow: Window): boolean;
|
|
17
|
+
export declare function getScrollParent(element: HTMLElement, includeHidden: boolean): HTMLElement | HTMLBodyElement;
|
|
18
|
+
export declare const scrollIntoViewIfNeeded: (target: HTMLElement) => void;
|
|
19
|
+
export declare const PUNCTUATION = "\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";
|
|
20
|
+
export declare function getBasicTypeaheadTriggerMatch(trigger: string, { minLength, maxLength, punctuation, allowWhitespace, }: {
|
|
21
|
+
allowWhitespace?: boolean;
|
|
22
|
+
maxLength?: number;
|
|
23
|
+
minLength?: number;
|
|
24
|
+
punctuation?: string;
|
|
25
|
+
}): (text: string) => {
|
|
26
|
+
leadOffset: number;
|
|
27
|
+
matchingString: string;
|
|
28
|
+
replaceableString: string;
|
|
29
|
+
} | null;
|
|
30
|
+
/**
|
|
31
|
+
* Split Lexical TextNode and return a new TextNode only containing matched text.
|
|
32
|
+
* Common use cases include: removing the node, replacing with a new node.
|
|
33
|
+
*/
|
|
34
|
+
export declare function $splitNodeContainingQuery(match: {
|
|
35
|
+
leadOffset: number;
|
|
36
|
+
matchingString: string;
|
|
37
|
+
replaceableString: string;
|
|
38
|
+
}): TextNode | null;
|