tiptap: improve debug, fix paste html

pull/84/head
fantasticit 2022-06-17 22:37:55 +08:00
parent b8f174f482
commit 9a6c1c40e6
4 changed files with 28 additions and 18 deletions

View File

@ -5,6 +5,7 @@ import { Fragment, Schema } from 'prosemirror-model';
import { Plugin, PluginKey } from 'prosemirror-state'; import { Plugin, PluginKey } from 'prosemirror-state';
import { EXTENSION_PRIORITY_HIGHEST } from 'tiptap/core/constants'; import { EXTENSION_PRIORITY_HIGHEST } from 'tiptap/core/constants';
import { import {
debug,
handleFileEvent, handleFileEvent,
isInCode, isInCode,
isMarkdown, isMarkdown,
@ -83,19 +84,12 @@ export const Paste = Extension.create<IPasteOptions>({
const markdownText = event.clipboardData.getData('text/markdown'); const markdownText = event.clipboardData.getData('text/markdown');
const { state, dispatch } = view; const { state, dispatch } = view;
if (typeof window !== 'undefined') { debug(() => {
if (window.location.search.includes('dev=1')) { console.group('paste');
console.group(); console.log({ text, vscode, node, markdownText });
console.log('paste', {
text,
vscode,
node,
markdownText,
});
console.log(html); console.log(html);
console.groupEnd(); console.groupEnd();
} });
}
const { markdownToProsemirror } = extensionThis.options; const { markdownToProsemirror } = extensionThis.options;
@ -150,10 +144,6 @@ export const Paste = Extension.create<IPasteOptions>({
return true; return true;
} }
if (html?.includes('data-pm-slice')) {
return false;
}
// 处理 markdown // 处理 markdown
if (markdownText || isMarkdown(text) || html.length === 0 || pasteCodeLanguage === 'markdown') { if (markdownText || isMarkdown(text) || html.length === 0 || pasteCodeLanguage === 'markdown') {
event.preventDefault(); event.preventDefault();

View File

@ -3,6 +3,8 @@ import { copy } from 'helpers/copy';
import { safeJSONStringify } from 'helpers/json'; import { safeJSONStringify } from 'helpers/json';
import { Fragment, Node } from 'prosemirror-model'; import { Fragment, Node } from 'prosemirror-model';
import { debug } from './debug';
export function copyNode(nodeOrNodeName: Node | Fragment<any>); export function copyNode(nodeOrNodeName: Node | Fragment<any>);
export function copyNode(nodeOrNodeName: string, editor: Editor); export function copyNode(nodeOrNodeName: string, editor: Editor);
export function copyNode(nodeOrNodeName: string | Node | Fragment<any>, editor?: Editor) { export function copyNode(nodeOrNodeName: string | Node | Fragment<any>, editor?: Editor) {
@ -44,9 +46,19 @@ export function copyNode(nodeOrNodeName: string | Node | Fragment<any>, editor?:
const html = markdownToHTML(markdown); const html = markdownToHTML(markdown);
toCopy.push({ text: html, format: 'text/html' }); toCopy.push({ text: html, format: 'text/html' });
} catch (e) { } catch (e) {
// debug(() => {
console.group('copy');
console.error(e.message);
console.groupEnd();
});
} }
debug(() => {
console.group('copy');
console.log(toCopy);
console.groupEnd();
});
copy(toCopy); copy(toCopy);
} }

View File

@ -0,0 +1,7 @@
export function debug(run) {
if (typeof window !== 'undefined') {
if (window.location.search.includes('dev=1')) {
run();
}
}
}

View File

@ -3,6 +3,7 @@ export * from './clamp';
export * from './code'; export * from './code';
export * from './color'; export * from './color';
export * from './copy-node'; export * from './copy-node';
export * from './debug';
export * from './delete-node'; export * from './delete-node';
export * from './dom'; export * from './dom';
export * from './dom-dataset'; export * from './dom-dataset';