tiptap: update node input rule

This commit is contained in:
fantasticit 2022-06-21 23:21:37 +08:00
parent db53cc576c
commit 1541a6acb0
8 changed files with 35 additions and 37 deletions

View File

@ -72,7 +72,7 @@ export const Callout = Node.create({
addInputRules() { addInputRules() {
return [ return [
wrappingInputRule({ wrappingInputRule({
find: /^:::callout $/, find: /^\$callout $/,
type: this.type, type: this.type,
getAttributes: (match) => { getAttributes: (match) => {
return { type: match[1] }; return { type: match[1] };

View File

@ -1,4 +1,4 @@
import { mergeAttributes, Node } from '@tiptap/core'; import { mergeAttributes, Node, nodeInputRule } from '@tiptap/core';
import { ReactNodeViewRenderer } from '@tiptap/react'; import { ReactNodeViewRenderer } from '@tiptap/react';
import { CountdownWrapper } from 'tiptap/core/wrappers/countdown'; import { CountdownWrapper } from 'tiptap/core/wrappers/countdown';
import { getDatasetAttribute } from 'tiptap/prose-utils'; import { getDatasetAttribute } from 'tiptap/prose-utils';
@ -77,6 +77,18 @@ export const Countdown = Node.create({
}; };
}, },
addInputRules() {
return [
nodeInputRule({
find: /^\$countdown $/,
type: this.type,
getAttributes: () => {
return { width: '100%' };
},
}),
];
},
addNodeView() { addNodeView() {
return ReactNodeViewRenderer(CountdownWrapper); return ReactNodeViewRenderer(CountdownWrapper);
}, },

View File

@ -1,4 +1,4 @@
import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'; import { mergeAttributes, Node } from '@tiptap/core';
import { ReactNodeViewRenderer } from '@tiptap/react'; import { ReactNodeViewRenderer } from '@tiptap/react';
import { DocumentChildrenWrapper } from 'tiptap/core/wrappers/document-children'; import { DocumentChildrenWrapper } from 'tiptap/core/wrappers/document-children';
import { getDatasetAttribute } from 'tiptap/prose-utils'; import { getDatasetAttribute } from 'tiptap/prose-utils';
@ -11,8 +11,6 @@ declare module '@tiptap/core' {
} }
} }
export const DocumentChildrenInputRegex = /^documentChildren\$$/;
export const DocumentChildren = Node.create({ export const DocumentChildren = Node.create({
name: 'documentChildren', name: 'documentChildren',
group: 'block', group: 'block',
@ -64,15 +62,6 @@ export const DocumentChildren = Node.create({
}; };
}, },
addInputRules() {
return [
wrappingInputRule({
find: DocumentChildrenInputRegex,
type: this.type,
}),
];
},
addNodeView() { addNodeView() {
return ReactNodeViewRenderer(DocumentChildrenWrapper); return ReactNodeViewRenderer(DocumentChildrenWrapper);
}, },

View File

@ -1,5 +1,5 @@
import { IUser } from '@think/domains'; import { IUser } from '@think/domains';
import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'; import { mergeAttributes, Node } from '@tiptap/core';
import { ReactNodeViewRenderer } from '@tiptap/react'; import { ReactNodeViewRenderer } from '@tiptap/react';
import { DocumentReferenceWrapper } from 'tiptap/core/wrappers/document-reference'; import { DocumentReferenceWrapper } from 'tiptap/core/wrappers/document-reference';
import { getDatasetAttribute } from 'tiptap/prose-utils'; import { getDatasetAttribute } from 'tiptap/prose-utils';
@ -17,8 +17,6 @@ declare module '@tiptap/core' {
} }
} }
export const DocumentReferenceInputRegex = /^documentReference\$$/;
export const DocumentReference = Node.create({ export const DocumentReference = Node.create({
name: 'documentReference', name: 'documentReference',
group: 'block', group: 'block',
@ -80,15 +78,6 @@ export const DocumentReference = Node.create({
}; };
}, },
addInputRules() {
return [
wrappingInputRule({
find: DocumentReferenceInputRegex,
type: this.type,
}),
];
},
addNodeView() { addNodeView() {
return ReactNodeViewRenderer(DocumentReferenceWrapper); return ReactNodeViewRenderer(DocumentReferenceWrapper);
}, },

View File

@ -106,8 +106,8 @@ export const Flow = Node.create({
nodeInputRule({ nodeInputRule({
find: /^\$flow $/, find: /^\$flow $/,
type: this.type, type: this.type,
getAttributes: (match) => { getAttributes: () => {
return { type: match[1] }; return { width: '100%' };
}, },
}), }),
]; ];

View File

@ -1,5 +1,5 @@
import { IUser } from '@think/domains'; import { IUser } from '@think/domains';
import { mergeAttributes, Node } from '@tiptap/core'; import { mergeAttributes, Node, nodeInputRule } from '@tiptap/core';
import { ReactNodeViewRenderer } from '@tiptap/react'; import { ReactNodeViewRenderer } from '@tiptap/react';
import { IframeWrapper } from 'tiptap/core/wrappers/iframe'; import { IframeWrapper } from 'tiptap/core/wrappers/iframe';
import { getDatasetAttribute } from 'tiptap/prose-utils'; import { getDatasetAttribute } from 'tiptap/prose-utils';
@ -97,6 +97,18 @@ export const Iframe = Node.create({
}; };
}, },
addInputRules() {
return [
nodeInputRule({
find: /^\$iframe $/,
type: this.type,
getAttributes: () => {
return { width: '100%' };
},
}),
];
},
addNodeView() { addNodeView() {
return ReactNodeViewRenderer(IframeWrapper); return ReactNodeViewRenderer(IframeWrapper);
}, },

View File

@ -17,8 +17,6 @@ declare module '@tiptap/core' {
} }
} }
export const KatexInputRegex = /^\$\$(.+)?\$\$$/;
export const Katex = Node.create({ export const Katex = Node.create({
name: 'katex', name: 'katex',
group: 'block', group: 'block',
@ -74,11 +72,8 @@ export const Katex = Node.create({
addInputRules() { addInputRules() {
return [ return [
nodeInputRule({ nodeInputRule({
find: KatexInputRegex, find: /^\$katex $/,
type: this.type, type: this.type,
getAttributes: (match) => {
return { text: match[1] };
},
}), }),
]; ];
}, },

View File

@ -95,6 +95,7 @@ export const Mind = Node.create({
const { selection } = editor.state; const { selection } = editor.state;
const pos = selection.$head; const pos = selection.$head;
return chain() return chain()
.insertContentAt(pos.after(), [ .insertContentAt(pos.after(), [
{ {
@ -116,8 +117,8 @@ export const Mind = Node.create({
nodeInputRule({ nodeInputRule({
find: /^\$mind $/, find: /^\$mind $/,
type: this.type, type: this.type,
getAttributes: (match) => { getAttributes: () => {
return { type: match[1] }; return { width: '100%' };
}, },
}), }),
]; ];