Files
tiptap/packages/core/src/commands/replace.ts
2021-04-21 09:43:31 +02:00

21 lines
566 B
TypeScript

import { NodeType } from 'prosemirror-model'
import { Command, RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
replace: {
/**
* Replaces text with a node.
*/
replace: (typeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
}
}
}
export const replace: RawCommands['replace'] = (typeOrName, attributes = {}) => ({ state, commands }) => {
const { from, to } = state.selection
const range = { from, to }
return commands.replaceRange(range, typeOrName, attributes)
}