diff --git a/packages/client/src/tiptap/core/extensions/paste.ts b/packages/client/src/tiptap/core/extensions/paste.ts index 254c7774..04963e5e 100644 --- a/packages/client/src/tiptap/core/extensions/paste.ts +++ b/packages/client/src/tiptap/core/extensions/paste.ts @@ -1,4 +1,4 @@ -import { Extension } from '@tiptap/core'; +import { Editor as CoreEditor, Extension } from '@tiptap/core'; import { safeJSONParse } from 'helpers/json'; import { toggleMark } from 'prosemirror-commands'; import { DOMParser, Fragment, Node, Schema } from 'prosemirror-model'; @@ -53,7 +53,13 @@ interface IPasteOptions { * * 将 html 转换为 prosemirror */ - htmlToProsemirror: (arg: { schema: Schema; html: string; needTitle: boolean; defaultTitle?: string }) => Node; + htmlToProsemirror: (arg: { + editor: CoreEditor; + schema: Schema; + html: string; + needTitle: boolean; + defaultTitle?: string; + }) => Node; /** * 将 markdown 转换为 html @@ -63,7 +69,7 @@ interface IPasteOptions { /** * 将 markdown 转换为 prosemirror 节点 */ - markdownToProsemirror: (arg: { schema: Schema; content: string; needTitle: boolean }) => Node; + markdownToProsemirror: (arg: { editor: CoreEditor; schema: Schema; content: string; needTitle: boolean }) => Node; /** * 将 prosemirror 转换为 markdown @@ -119,12 +125,6 @@ export const Paste = Extension.create({ console.groupEnd(); }); - if (isInTitle(view.state)) { - if (text.length) { - return insertText(view, text); - } - } - // 直接复制节点 if (node) { const json = safeJSONParse(node); @@ -157,6 +157,7 @@ export const Paste = Extension.create({ // TODO:各家 office 套件标准不一样,是否需要做成用户自行选择粘贴 html 或者 图片? if (html?.includes('urn:schemas-microsoft-com:office') || html?.includes('')) { const doc = htmlToProsemirror({ + editor, schema: editor.schema, html, needTitle: hasTitleExtension && !hasTitle, @@ -221,9 +222,11 @@ export const Paste = Extension.create({ // 处理 markdown if (markdownText || isMarkdown(text)) { + console.log(text); event.preventDefault(); const schema = view.props.state.schema; const doc = markdownToProsemirror({ + editor, schema, content: normalizeMarkdown(markdownText || text), needTitle: hasTitleExtension && !hasTitle, @@ -239,6 +242,12 @@ export const Paste = Extension.create({ return true; } + if (isInTitle(view.state)) { + if (text.length) { + return insertText(view, text); + } + } + return false; }, handleDrop: (view, event: any) => {