From a9f3de8ff04cd708508fb14601eecec1d1832d4f Mon Sep 17 00:00:00 2001 From: fantasticit Date: Tue, 21 Jun 2022 20:54:07 +0800 Subject: [PATCH] tiptap: insert block node after current pos --- packages/client/src/tiptap/core/extensions/countdown.ts | 2 +- packages/client/src/tiptap/core/extensions/flow.ts | 3 ++- packages/client/src/tiptap/core/extensions/iframe.ts | 2 +- packages/client/src/tiptap/core/extensions/mind.ts | 2 +- packages/client/src/tiptap/core/extensions/quick-insert.ts | 4 ++-- packages/client/src/tiptap/core/menus/commands.tsx | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/client/src/tiptap/core/extensions/countdown.ts b/packages/client/src/tiptap/core/extensions/countdown.ts index 8347d769..79f0792e 100644 --- a/packages/client/src/tiptap/core/extensions/countdown.ts +++ b/packages/client/src/tiptap/core/extensions/countdown.ts @@ -66,7 +66,7 @@ export const Countdown = Node.create({ const pos = selection.$head; return chain() - .insertContentAt(pos.before(), [ + .insertContentAt(pos.after(), [ { type: this.name, attrs: options, diff --git a/packages/client/src/tiptap/core/extensions/flow.ts b/packages/client/src/tiptap/core/extensions/flow.ts index 77edcdaf..c679bfcc 100644 --- a/packages/client/src/tiptap/core/extensions/flow.ts +++ b/packages/client/src/tiptap/core/extensions/flow.ts @@ -84,8 +84,9 @@ export const Flow = Node.create({ const { selection } = editor.state; const pos = selection.$head; + return chain() - .insertContentAt(pos.before(), [ + .insertContentAt(pos.after(), [ { type: this.name, attrs: options, diff --git a/packages/client/src/tiptap/core/extensions/iframe.ts b/packages/client/src/tiptap/core/extensions/iframe.ts index 6ab01f38..e05518f1 100644 --- a/packages/client/src/tiptap/core/extensions/iframe.ts +++ b/packages/client/src/tiptap/core/extensions/iframe.ts @@ -86,7 +86,7 @@ export const Iframe = Node.create({ const pos = selection.$head; return chain() - .insertContentAt(pos.before(), [ + .insertContentAt(pos.after(), [ { type: this.name, attrs, diff --git a/packages/client/src/tiptap/core/extensions/mind.ts b/packages/client/src/tiptap/core/extensions/mind.ts index bd820ebd..dfed62ef 100644 --- a/packages/client/src/tiptap/core/extensions/mind.ts +++ b/packages/client/src/tiptap/core/extensions/mind.ts @@ -96,7 +96,7 @@ export const Mind = Node.create({ const { selection } = editor.state; const pos = selection.$head; return chain() - .insertContentAt(pos.before(), [ + .insertContentAt(pos.after(), [ { type: this.name, attrs: options, diff --git a/packages/client/src/tiptap/core/extensions/quick-insert.ts b/packages/client/src/tiptap/core/extensions/quick-insert.ts index 3abe180c..00da72d1 100644 --- a/packages/client/src/tiptap/core/extensions/quick-insert.ts +++ b/packages/client/src/tiptap/core/extensions/quick-insert.ts @@ -6,7 +6,7 @@ import tippy from 'tippy.js'; import { EXTENSION_PRIORITY_HIGHEST } from 'tiptap/core/constants'; import { insertMenuLRUCache, QUICK_INSERT_COMMANDS, transformToCommands } from 'tiptap/core/menus/commands'; import { MenuList } from 'tiptap/core/wrappers/menu-list'; -import { createNewParagraphAbove } from 'tiptap/prose-utils'; +import { createNewParagraphBelow } from 'tiptap/prose-utils'; export const QuickInsertPluginKey = new PluginKey('quickInsert'); @@ -35,7 +35,7 @@ export const QuickInsert = Node.create({ dispatch(tr); if (props.isBlock) { - createNewParagraphAbove(state, dispatch); + createNewParagraphBelow(state, dispatch); } props?.action(editor, props.user); diff --git a/packages/client/src/tiptap/core/menus/commands.tsx b/packages/client/src/tiptap/core/menus/commands.tsx index e1c2be90..fb6a9201 100644 --- a/packages/client/src/tiptap/core/menus/commands.tsx +++ b/packages/client/src/tiptap/core/menus/commands.tsx @@ -181,7 +181,7 @@ export const QUICK_INSERT_COMMANDS = [ ]; export const transformToCommands = (commands, data: string[]) => { - return data + return (data || []) .map((label) => { return commands.find((command) => { if ('title' in command) {