mirror of https://github.com/fantasticit/think.git
tiptap: improve debug, fix paste html
This commit is contained in:
parent
b8f174f482
commit
9a6c1c40e6
|
@ -5,6 +5,7 @@ import { Fragment, Schema } from 'prosemirror-model';
|
|||
import { Plugin, PluginKey } from 'prosemirror-state';
|
||||
import { EXTENSION_PRIORITY_HIGHEST } from 'tiptap/core/constants';
|
||||
import {
|
||||
debug,
|
||||
handleFileEvent,
|
||||
isInCode,
|
||||
isMarkdown,
|
||||
|
@ -83,19 +84,12 @@ export const Paste = Extension.create<IPasteOptions>({
|
|||
const markdownText = event.clipboardData.getData('text/markdown');
|
||||
const { state, dispatch } = view;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
if (window.location.search.includes('dev=1')) {
|
||||
console.group();
|
||||
console.log('paste', {
|
||||
text,
|
||||
vscode,
|
||||
node,
|
||||
markdownText,
|
||||
});
|
||||
console.log(html);
|
||||
console.groupEnd();
|
||||
}
|
||||
}
|
||||
debug(() => {
|
||||
console.group('paste');
|
||||
console.log({ text, vscode, node, markdownText });
|
||||
console.log(html);
|
||||
console.groupEnd();
|
||||
});
|
||||
|
||||
const { markdownToProsemirror } = extensionThis.options;
|
||||
|
||||
|
@ -150,10 +144,6 @@ export const Paste = Extension.create<IPasteOptions>({
|
|||
return true;
|
||||
}
|
||||
|
||||
if (html?.includes('data-pm-slice')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 处理 markdown
|
||||
if (markdownText || isMarkdown(text) || html.length === 0 || pasteCodeLanguage === 'markdown') {
|
||||
event.preventDefault();
|
||||
|
|
|
@ -3,6 +3,8 @@ import { copy } from 'helpers/copy';
|
|||
import { safeJSONStringify } from 'helpers/json';
|
||||
import { Fragment, Node } from 'prosemirror-model';
|
||||
|
||||
import { debug } from './debug';
|
||||
|
||||
export function copyNode(nodeOrNodeName: Node | Fragment<any>);
|
||||
export function copyNode(nodeOrNodeName: string, 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);
|
||||
toCopy.push({ text: html, format: 'text/html' });
|
||||
} catch (e) {
|
||||
//
|
||||
debug(() => {
|
||||
console.group('copy');
|
||||
console.error(e.message);
|
||||
console.groupEnd();
|
||||
});
|
||||
}
|
||||
|
||||
debug(() => {
|
||||
console.group('copy');
|
||||
console.log(toCopy);
|
||||
console.groupEnd();
|
||||
});
|
||||
|
||||
copy(toCopy);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
export function debug(run) {
|
||||
if (typeof window !== 'undefined') {
|
||||
if (window.location.search.includes('dev=1')) {
|
||||
run();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ export * from './clamp';
|
|||
export * from './code';
|
||||
export * from './color';
|
||||
export * from './copy-node';
|
||||
export * from './debug';
|
||||
export * from './delete-node';
|
||||
export * from './dom';
|
||||
export * from './dom-dataset';
|
||||
|
|
Loading…
Reference in New Issue