tiptap: insert block node after current pos

This commit is contained in:
fantasticit 2022-06-21 20:54:07 +08:00
parent 1687dc297c
commit a9f3de8ff0
6 changed files with 8 additions and 7 deletions

View File

@ -66,7 +66,7 @@ export const Countdown = Node.create({
const pos = selection.$head; const pos = selection.$head;
return chain() return chain()
.insertContentAt(pos.before(), [ .insertContentAt(pos.after(), [
{ {
type: this.name, type: this.name,
attrs: options, attrs: options,

View File

@ -84,8 +84,9 @@ export const Flow = Node.create({
const { selection } = editor.state; const { selection } = editor.state;
const pos = selection.$head; const pos = selection.$head;
return chain() return chain()
.insertContentAt(pos.before(), [ .insertContentAt(pos.after(), [
{ {
type: this.name, type: this.name,
attrs: options, attrs: options,

View File

@ -86,7 +86,7 @@ export const Iframe = Node.create({
const pos = selection.$head; const pos = selection.$head;
return chain() return chain()
.insertContentAt(pos.before(), [ .insertContentAt(pos.after(), [
{ {
type: this.name, type: this.name,
attrs, attrs,

View File

@ -96,7 +96,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.before(), [ .insertContentAt(pos.after(), [
{ {
type: this.name, type: this.name,
attrs: options, attrs: options,

View File

@ -6,7 +6,7 @@ import tippy from 'tippy.js';
import { EXTENSION_PRIORITY_HIGHEST } from 'tiptap/core/constants'; import { EXTENSION_PRIORITY_HIGHEST } from 'tiptap/core/constants';
import { insertMenuLRUCache, QUICK_INSERT_COMMANDS, transformToCommands } from 'tiptap/core/menus/commands'; import { insertMenuLRUCache, QUICK_INSERT_COMMANDS, transformToCommands } from 'tiptap/core/menus/commands';
import { MenuList } from 'tiptap/core/wrappers/menu-list'; 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'); export const QuickInsertPluginKey = new PluginKey('quickInsert');
@ -35,7 +35,7 @@ export const QuickInsert = Node.create({
dispatch(tr); dispatch(tr);
if (props.isBlock) { if (props.isBlock) {
createNewParagraphAbove(state, dispatch); createNewParagraphBelow(state, dispatch);
} }
props?.action(editor, props.user); props?.action(editor, props.user);

View File

@ -181,7 +181,7 @@ export const QUICK_INSERT_COMMANDS = [
]; ];
export const transformToCommands = (commands, data: string[]) => { export const transformToCommands = (commands, data: string[]) => {
return data return (data || [])
.map((label) => { .map((label) => {
return commands.find((command) => { return commands.find((command) => {
if ('title' in command) { if ('title' in command) {