@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,139 @@
|
|
|
1
|
+
import { ElementNode, LexicalNode, TextFormatType, TextNode } from 'lexical';
|
|
2
|
+
import { IServiceID } from "../../../editor-kernel/types";
|
|
3
|
+
export type TextFormatTransformer = Readonly<{
|
|
4
|
+
format: ReadonlyArray<TextFormatType>;
|
|
5
|
+
intraword?: boolean;
|
|
6
|
+
tag: string;
|
|
7
|
+
type: 'text-format';
|
|
8
|
+
}>;
|
|
9
|
+
export type TextMatchTransformer = Readonly<{
|
|
10
|
+
/**
|
|
11
|
+
* For import operations, this function can be used to determine the end index of the match, after `importRegExp` has matched.
|
|
12
|
+
* Without this function, the end index will be determined by the length of the match from `importRegExp`. Manually determining the end index can be useful if
|
|
13
|
+
* the match from `importRegExp` is not the entire text content of the node. That way, `importRegExp` can be used to match only the start of the node, and `getEndIndex`
|
|
14
|
+
* can be used to match the end of the node.
|
|
15
|
+
*
|
|
16
|
+
* @returns The end index of the match, or false if the match was unsuccessful and a different transformer should be tried.
|
|
17
|
+
*/
|
|
18
|
+
getEndIndex?: (node: TextNode, match: RegExpMatchArray) => number | false;
|
|
19
|
+
/**
|
|
20
|
+
* This regex determines what text is matched during markdown imports
|
|
21
|
+
*/
|
|
22
|
+
importRegExp?: RegExp;
|
|
23
|
+
/**
|
|
24
|
+
* This regex determines what text is matched for markdown shortcuts while typing in the editor
|
|
25
|
+
*/
|
|
26
|
+
regExp: RegExp;
|
|
27
|
+
/**
|
|
28
|
+
* Determines how the matched markdown text should be transformed into a node during the markdown import process
|
|
29
|
+
*
|
|
30
|
+
* @returns nothing, or a TextNode that may be a child of the new node that is created.
|
|
31
|
+
* If a TextNode is returned, text format matching will be applied to it (e.g. bold, italic, etc.)
|
|
32
|
+
*/
|
|
33
|
+
replace?: (node: TextNode, match: RegExpMatchArray) => void | TextNode;
|
|
34
|
+
/**
|
|
35
|
+
* Single character that allows the transformer to trigger when typed in the editor. This does not affect markdown imports outside of the markdown shortcut plugin.
|
|
36
|
+
* If the trigger is matched, the `regExp` will be used to match the text in the second step.
|
|
37
|
+
*/
|
|
38
|
+
trigger?: string;
|
|
39
|
+
type: 'text-match';
|
|
40
|
+
}>;
|
|
41
|
+
export type ElementTransformer = {
|
|
42
|
+
regExp: RegExp;
|
|
43
|
+
/**
|
|
44
|
+
* `replace` is called when markdown is imported or typed in the editor
|
|
45
|
+
*
|
|
46
|
+
* @return return false to cancel the transform, even though the regex matched. Lexical will then search for the next transformer.
|
|
47
|
+
*/
|
|
48
|
+
replace: (parentNode: ElementNode, children: Array<LexicalNode>, match: Array<string>,
|
|
49
|
+
/**
|
|
50
|
+
* Whether the match is from an import operation (e.g. through `$convertFromMarkdownString`) or not (e.g. through typing in the editor).
|
|
51
|
+
*/
|
|
52
|
+
isImport: boolean) => boolean | void;
|
|
53
|
+
trigger?: 'enter';
|
|
54
|
+
type: 'element';
|
|
55
|
+
};
|
|
56
|
+
export type Transformer = ElementTransformer | TextFormatTransformer | TextMatchTransformer;
|
|
57
|
+
export interface IMarkdownWriterContext {
|
|
58
|
+
/**
|
|
59
|
+
* Add processor
|
|
60
|
+
* @param processor
|
|
61
|
+
*/
|
|
62
|
+
addProcessor(processor: (before: string, content: string, after: string) => string): void;
|
|
63
|
+
/**
|
|
64
|
+
* Direct output
|
|
65
|
+
* @param line
|
|
66
|
+
* @returns
|
|
67
|
+
*/
|
|
68
|
+
appendLine: (line: string) => void;
|
|
69
|
+
/**
|
|
70
|
+
* Wrap child elements
|
|
71
|
+
* @param before
|
|
72
|
+
* @param after
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
75
|
+
wrap: (before: string, after: string) => void;
|
|
76
|
+
}
|
|
77
|
+
export interface IMarkdownShortCutService {
|
|
78
|
+
registerMarkdownShortCut(transformer: Transformer): void;
|
|
79
|
+
registerMarkdownShortCuts(transformers: Transformer[]): void;
|
|
80
|
+
/**
|
|
81
|
+
* Register Markdown writer
|
|
82
|
+
* @param type Lexical Node type
|
|
83
|
+
* @param writer
|
|
84
|
+
*/
|
|
85
|
+
registerMarkdownWriter(type: string, writer: (ctx: IMarkdownWriterContext, node: LexicalNode) => void): void;
|
|
86
|
+
}
|
|
87
|
+
export declare const IMarkdownShortCutService: IServiceID<IMarkdownShortCutService>;
|
|
88
|
+
export declare class MarkdownShortCutService implements IMarkdownShortCutService {
|
|
89
|
+
private elementTransformers;
|
|
90
|
+
private textFormatTransformers;
|
|
91
|
+
private textMatchTransformers;
|
|
92
|
+
private _markdownWriters;
|
|
93
|
+
get markdownWriters(): Record<string, (ctx: IMarkdownWriterContext, node: LexicalNode) => void>;
|
|
94
|
+
private _textFormatTransformersByTrigger;
|
|
95
|
+
private _textMatchTransformersByTrigger;
|
|
96
|
+
get textMatchTransformersByTrigger(): Readonly<Record<string, Readonly<{
|
|
97
|
+
/**
|
|
98
|
+
* For import operations, this function can be used to determine the end index of the match, after `importRegExp` has matched.
|
|
99
|
+
* Without this function, the end index will be determined by the length of the match from `importRegExp`. Manually determining the end index can be useful if
|
|
100
|
+
* the match from `importRegExp` is not the entire text content of the node. That way, `importRegExp` can be used to match only the start of the node, and `getEndIndex`
|
|
101
|
+
* can be used to match the end of the node.
|
|
102
|
+
*
|
|
103
|
+
* @returns The end index of the match, or false if the match was unsuccessful and a different transformer should be tried.
|
|
104
|
+
*/
|
|
105
|
+
getEndIndex?: ((node: TextNode, match: RegExpMatchArray) => number | false) | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* This regex determines what text is matched during markdown imports
|
|
108
|
+
*/
|
|
109
|
+
importRegExp?: RegExp | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* This regex determines what text is matched for markdown shortcuts while typing in the editor
|
|
112
|
+
*/
|
|
113
|
+
regExp: RegExp;
|
|
114
|
+
/**
|
|
115
|
+
* Determines how the matched markdown text should be transformed into a node during the markdown import process
|
|
116
|
+
*
|
|
117
|
+
* @returns nothing, or a TextNode that may be a child of the new node that is created.
|
|
118
|
+
* If a TextNode is returned, text format matching will be applied to it (e.g. bold, italic, etc.)
|
|
119
|
+
*/
|
|
120
|
+
replace?: ((node: TextNode, match: RegExpMatchArray) => void | TextNode) | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* Single character that allows the transformer to trigger when typed in the editor. This does not affect markdown imports outside of the markdown shortcut plugin.
|
|
123
|
+
* If the trigger is matched, the `regExp` will be used to match the text in the second step.
|
|
124
|
+
*/
|
|
125
|
+
trigger?: string | undefined;
|
|
126
|
+
type: "text-match";
|
|
127
|
+
}>[]>>;
|
|
128
|
+
get textFormatTransformersByTrigger(): Readonly<Record<string, readonly Readonly<{
|
|
129
|
+
format: readonly TextFormatType[];
|
|
130
|
+
intraword?: boolean | undefined;
|
|
131
|
+
tag: string;
|
|
132
|
+
type: "text-format";
|
|
133
|
+
}>[]>>;
|
|
134
|
+
registerMarkdownShortCut(transformer: Transformer): void;
|
|
135
|
+
registerMarkdownShortCuts(transformers: Transformer[]): void;
|
|
136
|
+
testTransformers(parentNode: ElementNode, anchorNode: TextNode, anchorOffset: number, trigger?: 'enter'): boolean;
|
|
137
|
+
runTransformers(parentNode: ElementNode, anchorNode: TextNode, anchorOffset: number, trigger?: 'enter'): boolean;
|
|
138
|
+
registerMarkdownWriter(type: string, writer: (ctx: IMarkdownWriterContext, node: LexicalNode) => void): void;
|
|
139
|
+
}
|
|
@@ -0,0 +1,401 @@
|
|
|
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
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
11
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
13
|
+
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."); }
|
|
14
|
+
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; } }
|
|
15
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
16
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
17
|
+
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); }
|
|
18
|
+
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; }
|
|
19
|
+
/* eslint-disable no-redeclare */
|
|
20
|
+
/* eslint-disable @typescript-eslint/no-redeclare */
|
|
21
|
+
import { $createRangeSelection, $getSelection, $isLineBreakNode, $isRangeSelection, $isRootOrShadowRoot, $isTextNode, $setSelection } from 'lexical';
|
|
22
|
+
import { genServiceId } from "../../../editor-kernel";
|
|
23
|
+
import { PUNCTUATION_OR_SPACE, getOpenTagStartIndex, indexBy, isEqualSubString } from "../utils";
|
|
24
|
+
export var IMarkdownShortCutService = genServiceId('MarkdownShortCutService');
|
|
25
|
+
function testElementTransformers(parentNode, anchorNode, anchorOffset, elementTransformers, fromTrigger) {
|
|
26
|
+
var grandParentNode = parentNode.getParent();
|
|
27
|
+
if (!$isRootOrShadowRoot(grandParentNode) || parentNode.getFirstChild() !== anchorNode) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
var textContent = anchorNode.getTextContent();
|
|
31
|
+
|
|
32
|
+
// Checking for anchorOffset position to prevent any checks for cases when caret is too far
|
|
33
|
+
// from a line start to be a part of block-level markdown trigger.
|
|
34
|
+
//
|
|
35
|
+
// TODO:
|
|
36
|
+
// Can have a quick check if caret is close enough to the beginning of the string (e.g. offset less than 10-20)
|
|
37
|
+
// since otherwise it won't be a markdown shortcut, but tables are exception
|
|
38
|
+
if (fromTrigger !== 'enter' && textContent[anchorOffset - 1] !== ' ') {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
var _iterator = _createForOfIteratorHelper(elementTransformers),
|
|
42
|
+
_step;
|
|
43
|
+
try {
|
|
44
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
45
|
+
var _step$value = _step.value,
|
|
46
|
+
regExp = _step$value.regExp,
|
|
47
|
+
trigger = _step$value.trigger;
|
|
48
|
+
var _match = textContent.match(regExp);
|
|
49
|
+
if (fromTrigger === trigger && _match && _match[0].length === (fromTrigger === 'enter' || _match[0].endsWith(' ') ? anchorOffset : anchorOffset - 1)) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} catch (err) {
|
|
54
|
+
_iterator.e(err);
|
|
55
|
+
} finally {
|
|
56
|
+
_iterator.f();
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
function runElementTransformers(parentNode, anchorNode, anchorOffset, elementTransformers, fromTrigger) {
|
|
61
|
+
var grandParentNode = parentNode.getParent();
|
|
62
|
+
if (!$isRootOrShadowRoot(grandParentNode) || parentNode.getFirstChild() !== anchorNode) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
var textContent = anchorNode.getTextContent();
|
|
66
|
+
|
|
67
|
+
// Checking for anchorOffset position to prevent any checks for cases when caret is too far
|
|
68
|
+
// from a line start to be a part of block-level markdown trigger.
|
|
69
|
+
//
|
|
70
|
+
// TODO:
|
|
71
|
+
// Can have a quick check if caret is close enough to the beginning of the string (e.g. offset less than 10-20)
|
|
72
|
+
// since otherwise it won't be a markdown shortcut, but tables are exception
|
|
73
|
+
if (fromTrigger !== 'enter' && textContent[anchorOffset - 1] !== ' ') {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
var _iterator2 = _createForOfIteratorHelper(elementTransformers),
|
|
77
|
+
_step2;
|
|
78
|
+
try {
|
|
79
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
80
|
+
var _step2$value = _step2.value,
|
|
81
|
+
regExp = _step2$value.regExp,
|
|
82
|
+
replace = _step2$value.replace,
|
|
83
|
+
trigger = _step2$value.trigger;
|
|
84
|
+
var _match2 = textContent.match(regExp);
|
|
85
|
+
if (fromTrigger === trigger && _match2 && _match2[0].length === (fromTrigger === 'enter' || _match2[0].endsWith(' ') ? anchorOffset : anchorOffset - 1)) {
|
|
86
|
+
var nextSiblings = anchorNode.getNextSiblings();
|
|
87
|
+
var _anchorNode$splitText = anchorNode.splitText(anchorOffset),
|
|
88
|
+
_anchorNode$splitText2 = _slicedToArray(_anchorNode$splitText, 2),
|
|
89
|
+
leadingNode = _anchorNode$splitText2[0],
|
|
90
|
+
remainderNode = _anchorNode$splitText2[1];
|
|
91
|
+
var siblings = remainderNode ? [remainderNode].concat(_toConsumableArray(nextSiblings)) : nextSiblings;
|
|
92
|
+
if (replace(parentNode, siblings, _match2, false) !== false) {
|
|
93
|
+
leadingNode.remove();
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
} catch (err) {
|
|
99
|
+
_iterator2.e(err);
|
|
100
|
+
} finally {
|
|
101
|
+
_iterator2.f();
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
function runTextMatchTransformers(anchorNode, anchorOffset, transformersByTrigger) {
|
|
106
|
+
var textContent = anchorNode.getTextContent();
|
|
107
|
+
var lastChar = textContent[anchorOffset - 1];
|
|
108
|
+
var transformers = transformersByTrigger[lastChar];
|
|
109
|
+
if (!transformers) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// If typing in the middle of content, remove the tail to do
|
|
114
|
+
// reg exp match up to a string end (caret position)
|
|
115
|
+
if (anchorOffset < textContent.length) {
|
|
116
|
+
textContent = textContent.slice(0, anchorOffset);
|
|
117
|
+
}
|
|
118
|
+
var _iterator3 = _createForOfIteratorHelper(transformers),
|
|
119
|
+
_step3;
|
|
120
|
+
try {
|
|
121
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
122
|
+
var _transformer = _step3.value;
|
|
123
|
+
if (!_transformer.replace || !_transformer.regExp) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
var _match3 = textContent.match(_transformer.regExp);
|
|
127
|
+
if (_match3 === null) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
var startIndex = _match3.index || 0;
|
|
131
|
+
var endIndex = startIndex + _match3[0].length;
|
|
132
|
+
var replaceNode = void 0;
|
|
133
|
+
if (startIndex === 0) {
|
|
134
|
+
var _anchorNode$splitText3 = anchorNode.splitText(endIndex);
|
|
135
|
+
var _anchorNode$splitText4 = _slicedToArray(_anchorNode$splitText3, 1);
|
|
136
|
+
replaceNode = _anchorNode$splitText4[0];
|
|
137
|
+
} else {
|
|
138
|
+
var _anchorNode$splitText5 = anchorNode.splitText(startIndex, endIndex);
|
|
139
|
+
var _anchorNode$splitText6 = _slicedToArray(_anchorNode$splitText5, 2);
|
|
140
|
+
replaceNode = _anchorNode$splitText6[1];
|
|
141
|
+
}
|
|
142
|
+
replaceNode.selectNext(0, 0);
|
|
143
|
+
_transformer.replace(replaceNode, _match3);
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
} catch (err) {
|
|
147
|
+
_iterator3.e(err);
|
|
148
|
+
} finally {
|
|
149
|
+
_iterator3.f();
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
function $runTextFormatTransformers(anchorNode, anchorOffset, textFormatTransformers) {
|
|
154
|
+
var textContent = anchorNode.getTextContent();
|
|
155
|
+
var closeTagEndIndex = anchorOffset - 1;
|
|
156
|
+
var closeChar = textContent[closeTagEndIndex];
|
|
157
|
+
// Quick check if we're possibly at the end of inline markdown style
|
|
158
|
+
var matchers = textFormatTransformers[closeChar];
|
|
159
|
+
if (!matchers) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
var _iterator4 = _createForOfIteratorHelper(matchers),
|
|
163
|
+
_step4;
|
|
164
|
+
try {
|
|
165
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
166
|
+
var matcher = _step4.value;
|
|
167
|
+
var tag = matcher.tag;
|
|
168
|
+
var tagLength = tag.length;
|
|
169
|
+
var closeTagStartIndex = closeTagEndIndex - tagLength + 1;
|
|
170
|
+
|
|
171
|
+
// If tag is not single char check if rest of it matches with text content
|
|
172
|
+
if (tagLength > 1 && !isEqualSubString(textContent, closeTagStartIndex, tag, 0, tagLength)) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Space before closing tag cancels inline markdown
|
|
177
|
+
if (textContent[closeTagStartIndex - 1] === ' ') {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Some tags can not be used within words, hence should have newline/space/punctuation after it
|
|
182
|
+
var afterCloseTagChar = textContent[closeTagEndIndex + 1];
|
|
183
|
+
if (matcher.intraword === false && afterCloseTagChar && !PUNCTUATION_OR_SPACE.test(afterCloseTagChar)) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
var closeNode = anchorNode;
|
|
187
|
+
var openNode = closeNode;
|
|
188
|
+
var openTagStartIndex = getOpenTagStartIndex(textContent, closeTagStartIndex, tag);
|
|
189
|
+
|
|
190
|
+
// Go through text node siblings and search for opening tag
|
|
191
|
+
// if haven't found it within the same text node as closing tag
|
|
192
|
+
var sibling = openNode;
|
|
193
|
+
while (openTagStartIndex < 0 && (sibling = sibling.getPreviousSibling())) {
|
|
194
|
+
if ($isLineBreakNode(sibling)) {
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
if ($isTextNode(sibling)) {
|
|
198
|
+
if (sibling.hasFormat('code')) {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
var siblingTextContent = sibling.getTextContent();
|
|
202
|
+
openNode = sibling;
|
|
203
|
+
openTagStartIndex = getOpenTagStartIndex(siblingTextContent, siblingTextContent.length, tag);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Opening tag is not found
|
|
208
|
+
if (openTagStartIndex < 0) {
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// No content between opening and closing tag
|
|
213
|
+
if (openNode === closeNode && openTagStartIndex + tagLength === closeTagStartIndex) {
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Checking longer tags for repeating chars (e.g. *** vs **)
|
|
218
|
+
var prevOpenNodeText = openNode.getTextContent();
|
|
219
|
+
if (openTagStartIndex > 0 && prevOpenNodeText[openTagStartIndex - 1] === closeChar) {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Some tags can not be used within words, hence should have newline/space/punctuation before it
|
|
224
|
+
var beforeOpenTagChar = prevOpenNodeText[openTagStartIndex - 1];
|
|
225
|
+
if (matcher.intraword === false && beforeOpenTagChar && !PUNCTUATION_OR_SPACE.test(beforeOpenTagChar)) {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Clean text from opening and closing tags (starting from closing tag
|
|
230
|
+
// to prevent any offset shifts if we start from opening one)
|
|
231
|
+
var prevCloseNodeText = closeNode.getTextContent();
|
|
232
|
+
var closeNodeText = prevCloseNodeText.slice(0, closeTagStartIndex) + prevCloseNodeText.slice(closeTagEndIndex + 1);
|
|
233
|
+
closeNode.setTextContent(closeNodeText);
|
|
234
|
+
var openNodeText = openNode === closeNode ? closeNodeText : prevOpenNodeText;
|
|
235
|
+
openNode.setTextContent(openNodeText.slice(0, openTagStartIndex) + openNodeText.slice(openTagStartIndex + tagLength));
|
|
236
|
+
var selection = $getSelection();
|
|
237
|
+
var nextSelection = $createRangeSelection();
|
|
238
|
+
$setSelection(nextSelection);
|
|
239
|
+
// Adjust offset based on deleted chars
|
|
240
|
+
var newOffset = closeTagEndIndex - tagLength * (openNode === closeNode ? 2 : 1) + 1;
|
|
241
|
+
nextSelection.anchor.set(openNode.__key, openTagStartIndex, 'text');
|
|
242
|
+
nextSelection.focus.set(closeNode.__key, newOffset, 'text');
|
|
243
|
+
|
|
244
|
+
// Apply formatting to selected text
|
|
245
|
+
var _iterator5 = _createForOfIteratorHelper(matcher.format),
|
|
246
|
+
_step5;
|
|
247
|
+
try {
|
|
248
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
249
|
+
var format = _step5.value;
|
|
250
|
+
if (!nextSelection.hasFormat(format)) {
|
|
251
|
+
nextSelection.formatText(format);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Collapse selection up to the focus point
|
|
256
|
+
} catch (err) {
|
|
257
|
+
_iterator5.e(err);
|
|
258
|
+
} finally {
|
|
259
|
+
_iterator5.f();
|
|
260
|
+
}
|
|
261
|
+
nextSelection.anchor.set(nextSelection.focus.key, nextSelection.focus.offset, nextSelection.focus.type);
|
|
262
|
+
|
|
263
|
+
// Remove formatting from collapsed selection
|
|
264
|
+
var _iterator6 = _createForOfIteratorHelper(matcher.format),
|
|
265
|
+
_step6;
|
|
266
|
+
try {
|
|
267
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
268
|
+
var _format = _step6.value;
|
|
269
|
+
if (nextSelection.hasFormat(_format)) {
|
|
270
|
+
nextSelection.toggleFormat(_format);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
} catch (err) {
|
|
274
|
+
_iterator6.e(err);
|
|
275
|
+
} finally {
|
|
276
|
+
_iterator6.f();
|
|
277
|
+
}
|
|
278
|
+
if ($isRangeSelection(selection)) {
|
|
279
|
+
nextSelection.format = selection.format;
|
|
280
|
+
}
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
} catch (err) {
|
|
284
|
+
_iterator4.e(err);
|
|
285
|
+
} finally {
|
|
286
|
+
_iterator4.f();
|
|
287
|
+
}
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
export var MarkdownShortCutService = /*#__PURE__*/function () {
|
|
291
|
+
function MarkdownShortCutService() {
|
|
292
|
+
_classCallCheck(this, MarkdownShortCutService);
|
|
293
|
+
_defineProperty(this, "elementTransformers", []);
|
|
294
|
+
_defineProperty(this, "textFormatTransformers", []);
|
|
295
|
+
_defineProperty(this, "textMatchTransformers", []);
|
|
296
|
+
_defineProperty(this, "_markdownWriters", {});
|
|
297
|
+
_defineProperty(this, "_textFormatTransformersByTrigger", null);
|
|
298
|
+
_defineProperty(this, "_textMatchTransformersByTrigger", null);
|
|
299
|
+
}
|
|
300
|
+
_createClass(MarkdownShortCutService, [{
|
|
301
|
+
key: "markdownWriters",
|
|
302
|
+
get: function get() {
|
|
303
|
+
return this._markdownWriters;
|
|
304
|
+
}
|
|
305
|
+
}, {
|
|
306
|
+
key: "textMatchTransformersByTrigger",
|
|
307
|
+
get: function get() {
|
|
308
|
+
if (!this._textMatchTransformersByTrigger) {
|
|
309
|
+
this._textMatchTransformersByTrigger = indexBy(this.textMatchTransformers, function (_ref) {
|
|
310
|
+
var trigger = _ref.trigger;
|
|
311
|
+
return trigger;
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
return this._textMatchTransformersByTrigger;
|
|
315
|
+
}
|
|
316
|
+
}, {
|
|
317
|
+
key: "textFormatTransformersByTrigger",
|
|
318
|
+
get: function get() {
|
|
319
|
+
if (!this._textFormatTransformersByTrigger) {
|
|
320
|
+
this._textFormatTransformersByTrigger = indexBy(this.textFormatTransformers, function (_ref2) {
|
|
321
|
+
var tag = _ref2.tag;
|
|
322
|
+
return tag.at(-1);
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
return this._textFormatTransformersByTrigger;
|
|
326
|
+
}
|
|
327
|
+
}, {
|
|
328
|
+
key: "registerMarkdownShortCut",
|
|
329
|
+
value: function registerMarkdownShortCut(transformer) {
|
|
330
|
+
switch (transformer.type) {
|
|
331
|
+
case 'element':
|
|
332
|
+
{
|
|
333
|
+
this.elementTransformers.push(transformer);
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
case 'text-format':
|
|
337
|
+
{
|
|
338
|
+
this.textFormatTransformers.push(transformer);
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
case 'text-match':
|
|
342
|
+
{
|
|
343
|
+
this.textMatchTransformers.push(transformer);
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
default:
|
|
347
|
+
{
|
|
348
|
+
throw new Error("Unknown transformer type: ".concat(transformer));
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}, {
|
|
353
|
+
key: "registerMarkdownShortCuts",
|
|
354
|
+
value: function registerMarkdownShortCuts(transformers) {
|
|
355
|
+
var _iterator7 = _createForOfIteratorHelper(transformers),
|
|
356
|
+
_step7;
|
|
357
|
+
try {
|
|
358
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
359
|
+
var _transformer2 = _step7.value;
|
|
360
|
+
this.registerMarkdownShortCut(_transformer2);
|
|
361
|
+
}
|
|
362
|
+
} catch (err) {
|
|
363
|
+
_iterator7.e(err);
|
|
364
|
+
} finally {
|
|
365
|
+
_iterator7.f();
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}, {
|
|
369
|
+
key: "testTransformers",
|
|
370
|
+
value: function testTransformers(parentNode, anchorNode, anchorOffset, trigger) {
|
|
371
|
+
if (testElementTransformers(parentNode, anchorNode, anchorOffset, this.elementTransformers, trigger)) {
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
}, {
|
|
377
|
+
key: "runTransformers",
|
|
378
|
+
value: function runTransformers(parentNode, anchorNode, anchorOffset, trigger) {
|
|
379
|
+
if (runElementTransformers(parentNode, anchorNode, anchorOffset, this.elementTransformers, trigger)) {
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
if (runTextMatchTransformers(anchorNode, anchorOffset, this.textMatchTransformersByTrigger)) {
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
if ($runTextFormatTransformers(anchorNode, anchorOffset, this.textFormatTransformersByTrigger)) {
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
return false;
|
|
389
|
+
}
|
|
390
|
+
}, {
|
|
391
|
+
key: "registerMarkdownWriter",
|
|
392
|
+
value: function registerMarkdownWriter(type, writer) {
|
|
393
|
+
if (!this._markdownWriters[type]) {
|
|
394
|
+
this._markdownWriters[type] = writer;
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
throw new Error("Markdown writer for type \"".concat(type, "\" is already registered."));
|
|
398
|
+
}
|
|
399
|
+
}]);
|
|
400
|
+
return MarkdownShortCutService;
|
|
401
|
+
}();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LexicalNode, TextNode } from 'lexical';
|
|
2
|
+
/**
|
|
3
|
+
* Returns true if the node can contain transformable markdown.
|
|
4
|
+
* Code nodes cannot contain transformable markdown.
|
|
5
|
+
* For example, `code **bold**` should not be transformed to
|
|
6
|
+
* <code>code <strong>bold</strong></code>.
|
|
7
|
+
*/
|
|
8
|
+
export declare function canContainTransformableMarkdown(node: LexicalNode | undefined): node is TextNode;
|
|
9
|
+
export declare function isEqualSubString(stringA: string, aStart: number, stringB: string, bStart: number, length: number): boolean;
|
|
10
|
+
export declare const PUNCTUATION_OR_SPACE: RegExp;
|
|
11
|
+
export declare function getOpenTagStartIndex(string: string, maxIndex: number, tag: string): number;
|
|
12
|
+
export declare function indexBy<T>(list: Array<T>, callback: (arg0: T) => string | undefined): Readonly<Record<string, Array<T>>>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
|
+
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); }
|
|
3
|
+
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; }
|
|
4
|
+
import { $isTextNode } from 'lexical';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Returns true if the node can contain transformable markdown.
|
|
8
|
+
* Code nodes cannot contain transformable markdown.
|
|
9
|
+
* For example, `code **bold**` should not be transformed to
|
|
10
|
+
* <code>code <strong>bold</strong></code>.
|
|
11
|
+
*/
|
|
12
|
+
export function canContainTransformableMarkdown(node) {
|
|
13
|
+
return $isTextNode(node) && !node.hasFormat('code');
|
|
14
|
+
}
|
|
15
|
+
export function isEqualSubString(stringA, aStart, stringB, bStart, length) {
|
|
16
|
+
for (var i = 0; i < length; i++) {
|
|
17
|
+
if (stringA[aStart + i] !== stringB[bStart + i]) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// eslint-disable-next-line unicorn/better-regex
|
|
25
|
+
export var PUNCTUATION_OR_SPACE = /[!-/:-@[-`{-~\s]/;
|
|
26
|
+
export function getOpenTagStartIndex(string, maxIndex, tag) {
|
|
27
|
+
var tagLength = tag.length;
|
|
28
|
+
for (var i = maxIndex; i >= tagLength; i--) {
|
|
29
|
+
var startIndex = i - tagLength;
|
|
30
|
+
if (isEqualSubString(string, startIndex, tag, 0, tagLength) &&
|
|
31
|
+
// Space after opening tag cancels transformation
|
|
32
|
+
string[startIndex + tagLength] !== ' ') {
|
|
33
|
+
return startIndex;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return -1;
|
|
37
|
+
}
|
|
38
|
+
export function indexBy(list, callback) {
|
|
39
|
+
var index = {};
|
|
40
|
+
var _iterator = _createForOfIteratorHelper(list),
|
|
41
|
+
_step;
|
|
42
|
+
try {
|
|
43
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
44
|
+
var item = _step.value;
|
|
45
|
+
var key = callback(item);
|
|
46
|
+
if (!key) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (index[key]) {
|
|
50
|
+
index[key].push(item);
|
|
51
|
+
} else {
|
|
52
|
+
index[key] = [item];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
} catch (err) {
|
|
56
|
+
_iterator.e(err);
|
|
57
|
+
} finally {
|
|
58
|
+
_iterator.f();
|
|
59
|
+
}
|
|
60
|
+
return index;
|
|
61
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { LexicalEditor } from 'lexical';
|
|
2
|
+
export declare const INSERT_MENTION_COMMAND: import("lexical").LexicalCommand<{
|
|
3
|
+
extra?: Record<string, unknown> | undefined;
|
|
4
|
+
label: string;
|
|
5
|
+
}>;
|
|
6
|
+
export declare function registerMentionCommand(editor: LexicalEditor): () => void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { $wrapNodeInElement } from '@lexical/utils';
|
|
2
|
+
import { $createParagraphNode, $insertNodes, $isRootOrShadowRoot, COMMAND_PRIORITY_HIGH, createCommand } from 'lexical';
|
|
3
|
+
import { $createMentionNode } from "../node/MentionNode";
|
|
4
|
+
export var INSERT_MENTION_COMMAND = createCommand('INSERT_MENTION_COMMAND');
|
|
5
|
+
export function registerMentionCommand(editor) {
|
|
6
|
+
return editor.registerCommand(INSERT_MENTION_COMMAND, function (payload) {
|
|
7
|
+
var extra = payload.extra,
|
|
8
|
+
label = payload.label;
|
|
9
|
+
editor.update(function () {
|
|
10
|
+
var mentionNode = $createMentionNode(label, extra);
|
|
11
|
+
$insertNodes([mentionNode]); // Insert a zero-width space to ensure the image is not the last child
|
|
12
|
+
if ($isRootOrShadowRoot(mentionNode.getParentOrThrow())) {
|
|
13
|
+
$wrapNodeInElement(mentionNode, $createParagraphNode).selectEnd();
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return true;
|
|
17
|
+
}, COMMAND_PRIORITY_HIGH // Priority
|
|
18
|
+
);
|
|
19
|
+
}
|