From 1541a6acb0b89c233db262d7518f358dbda68c6e Mon Sep 17 00:00:00 2001 From: fantasticit Date: Tue, 21 Jun 2022 23:21:37 +0800 Subject: [PATCH] tiptap: update node input rule --- .../client/src/tiptap/core/extensions/callout.ts | 2 +- .../client/src/tiptap/core/extensions/countdown.ts | 14 +++++++++++++- .../tiptap/core/extensions/document-children.ts | 13 +------------ .../tiptap/core/extensions/document-reference.ts | 13 +------------ packages/client/src/tiptap/core/extensions/flow.ts | 4 ++-- .../client/src/tiptap/core/extensions/iframe.ts | 14 +++++++++++++- .../client/src/tiptap/core/extensions/katex.ts | 7 +------ packages/client/src/tiptap/core/extensions/mind.ts | 5 +++-- 8 files changed, 35 insertions(+), 37 deletions(-) diff --git a/packages/client/src/tiptap/core/extensions/callout.ts b/packages/client/src/tiptap/core/extensions/callout.ts index 22020e63..d0f6f0df 100644 --- a/packages/client/src/tiptap/core/extensions/callout.ts +++ b/packages/client/src/tiptap/core/extensions/callout.ts @@ -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] }; diff --git a/packages/client/src/tiptap/core/extensions/countdown.ts b/packages/client/src/tiptap/core/extensions/countdown.ts index 79f0792e..016d187c 100644 --- a/packages/client/src/tiptap/core/extensions/countdown.ts +++ b/packages/client/src/tiptap/core/extensions/countdown.ts @@ -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); }, diff --git a/packages/client/src/tiptap/core/extensions/document-children.ts b/packages/client/src/tiptap/core/extensions/document-children.ts index 4acee279..f4aa420c 100644 --- a/packages/client/src/tiptap/core/extensions/document-children.ts +++ b/packages/client/src/tiptap/core/extensions/document-children.ts @@ -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); }, diff --git a/packages/client/src/tiptap/core/extensions/document-reference.ts b/packages/client/src/tiptap/core/extensions/document-reference.ts index 40e716aa..23f0fe6d 100644 --- a/packages/client/src/tiptap/core/extensions/document-reference.ts +++ b/packages/client/src/tiptap/core/extensions/document-reference.ts @@ -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); }, diff --git a/packages/client/src/tiptap/core/extensions/flow.ts b/packages/client/src/tiptap/core/extensions/flow.ts index c679bfcc..bd2f63fd 100644 --- a/packages/client/src/tiptap/core/extensions/flow.ts +++ b/packages/client/src/tiptap/core/extensions/flow.ts @@ -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%' }; }, }), ]; diff --git a/packages/client/src/tiptap/core/extensions/iframe.ts b/packages/client/src/tiptap/core/extensions/iframe.ts index e05518f1..fddfef45 100644 --- a/packages/client/src/tiptap/core/extensions/iframe.ts +++ b/packages/client/src/tiptap/core/extensions/iframe.ts @@ -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); }, diff --git a/packages/client/src/tiptap/core/extensions/katex.ts b/packages/client/src/tiptap/core/extensions/katex.ts index 0512642a..75127c7d 100644 --- a/packages/client/src/tiptap/core/extensions/katex.ts +++ b/packages/client/src/tiptap/core/extensions/katex.ts @@ -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] }; - }, }), ]; }, diff --git a/packages/client/src/tiptap/core/extensions/mind.ts b/packages/client/src/tiptap/core/extensions/mind.ts index dfed62ef..5ada9c47 100644 --- a/packages/client/src/tiptap/core/extensions/mind.ts +++ b/packages/client/src/tiptap/core/extensions/mind.ts @@ -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%' }; }, }), ];