mirror of https://github.com/fantasticit/think.git
tiptap: update node input rule
This commit is contained in:
parent
db53cc576c
commit
1541a6acb0
|
@ -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] };
|
||||||
|
|
|
@ -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);
|
||||||
},
|
},
|
||||||
|
|
|
@ -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);
|
||||||
},
|
},
|
||||||
|
|
|
@ -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);
|
||||||
},
|
},
|
||||||
|
|
|
@ -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%' };
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
|
@ -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);
|
||||||
},
|
},
|
||||||
|
|
|
@ -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] };
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
|
|
@ -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%' };
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue