tiptap/packages/core/src/commands/insertContent.ts
Arnau Gómez Farell 89bd9c7d29
Fix/enforce-type-imports-so-that-bundler-ignores-types (#6132)
* fix: enforce type imports so that the bundler ignores types

* chore: add changeset

* fix: export types with export type keyword
2025-03-03 15:15:30 +01:00

45 lines
1.3 KiB
TypeScript

import type { Fragment, Node as ProseMirrorNode, ParseOptions } from '@tiptap/pm/model'
import type { Content, RawCommands } from '../types.js'
declare module '@tiptap/core' {
interface Commands<ReturnType> {
insertContent: {
/**
* Insert a node or string of HTML at the current position.
* @example editor.commands.insertContent('<h1>Example</h1>')
* @example editor.commands.insertContent('<h1>Example</h1>', { updateSelection: false })
*/
insertContent: (
/**
* The ProseMirror content to insert.
*/
value: Content | ProseMirrorNode | Fragment,
/**
* Optional options
*/
options?: {
/**
* Options for parsing the content.
*/
parseOptions?: ParseOptions
/**
* Whether to update the selection after inserting the content.
*/
updateSelection?: boolean
applyInputRules?: boolean
applyPasteRules?: boolean
},
) => ReturnType
}
}
}
export const insertContent: RawCommands['insertContent'] =
(value, options) =>
({ tr, commands }) => {
return commands.insertContentAt({ from: tr.selection.from, to: tr.selection.to }, value, options)
}