tiptap: insert block node after current pos

pull/92/head
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;
return chain()
.insertContentAt(pos.before(), [
.insertContentAt(pos.after(), [
{
type: this.name,
attrs: options,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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);

View File

@ -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) {