mirror of https://github.com/fantasticit/think.git
tiptap: improve debug, fix paste html
parent
b8f174f482
commit
9a6c1c40e6
|
@ -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();
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 './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';
|
||||||
|
|
Loading…
Reference in New Issue