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() {
return [
wrappingInputRule({
find: /^:::callout $/,
find: /^\$callout $/,
type: this.type,
getAttributes: (match) => {
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 { CountdownWrapper } from 'tiptap/core/wrappers/countdown';
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() {
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 { DocumentChildrenWrapper } from 'tiptap/core/wrappers/document-children';
import { getDatasetAttribute } from 'tiptap/prose-utils';
@ -11,8 +11,6 @@ declare module '@tiptap/core' {
}
}
export const DocumentChildrenInputRegex = /^documentChildren\$$/;
export const DocumentChildren = Node.create({
name: 'documentChildren',
group: 'block',
@ -64,15 +62,6 @@ export const DocumentChildren = Node.create({
};
},
addInputRules() {
return [
wrappingInputRule({
find: DocumentChildrenInputRegex,
type: this.type,
}),
];
},
addNodeView() {
return ReactNodeViewRenderer(DocumentChildrenWrapper);
},

View File

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

View File

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

View File

@ -1,5 +1,5 @@
import { IUser } from '@think/domains';
import { mergeAttributes, Node } from '@tiptap/core';
import { mergeAttributes, Node, nodeInputRule } from '@tiptap/core';
import { ReactNodeViewRenderer } from '@tiptap/react';
import { IframeWrapper } from 'tiptap/core/wrappers/iframe';
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() {
return ReactNodeViewRenderer(IframeWrapper);
},

View File

@ -17,8 +17,6 @@ declare module '@tiptap/core' {
}
}
export const KatexInputRegex = /^\$\$(.+)?\$\$$/;
export const Katex = Node.create({
name: 'katex',
group: 'block',
@ -74,11 +72,8 @@ export const Katex = Node.create({
addInputRules() {
return [
nodeInputRule({
find: KatexInputRegex,
find: /^\$katex $/,
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 pos = selection.$head;
return chain()
.insertContentAt(pos.after(), [
{
@ -116,8 +117,8 @@ export const Mind = Node.create({
nodeInputRule({
find: /^\$mind $/,
type: this.type,
getAttributes: (match) => {
return { type: match[1] };
getAttributes: () => {
return { width: '100%' };
},
}),
];