mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-13 09:29:01 +08:00
✨ Add CreateNodeFromContentOptions to insertContent
This commit is contained in:
parent
a3381f4992
commit
55d0e67422
@ -1,3 +1,4 @@
|
|||||||
|
import { CreateNodeFromContentOptions } from '../helpers/createNodeFromContent'
|
||||||
import { RawCommands, Content } from '../types'
|
import { RawCommands, Content } from '../types'
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
@ -6,11 +7,11 @@ declare module '@tiptap/core' {
|
|||||||
/**
|
/**
|
||||||
* Insert a node or string of HTML at the current position.
|
* Insert a node or string of HTML at the current position.
|
||||||
*/
|
*/
|
||||||
insertContent: (value: Content) => ReturnType,
|
insertContent: (value: Content, options?: CreateNodeFromContentOptions) => ReturnType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const insertContent: RawCommands['insertContent'] = value => ({ tr, commands }) => {
|
export const insertContent: RawCommands['insertContent'] = (value, options) => ({ tr, commands }) => {
|
||||||
return commands.insertContentAt({ from: tr.selection.from, to: tr.selection.to }, value)
|
return commands.insertContentAt({ from: tr.selection.from, to: tr.selection.to }, value, options)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import createNodeFromContent from '../helpers/createNodeFromContent'
|
import createNodeFromContent, { CreateNodeFromContentOptions } from '../helpers/createNodeFromContent'
|
||||||
import selectionToInsertionEnd from '../helpers/selectionToInsertionEnd'
|
import selectionToInsertionEnd from '../helpers/selectionToInsertionEnd'
|
||||||
import {
|
import {
|
||||||
RawCommands,
|
RawCommands,
|
||||||
@ -12,17 +12,18 @@ declare module '@tiptap/core' {
|
|||||||
/**
|
/**
|
||||||
* Insert a node or string of HTML at a specific position.
|
* Insert a node or string of HTML at a specific position.
|
||||||
*/
|
*/
|
||||||
insertContentAt: (position: number | Range, value: Content) => ReturnType,
|
insertContentAt: (position: number | Range, value: Content, options?: CreateNodeFromContentOptions) => ReturnType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const insertContentAt: RawCommands['insertContentAt'] = (position, value) => ({ tr, dispatch, editor }) => {
|
export const insertContentAt: RawCommands['insertContentAt'] = (position, value, options) => ({ tr, dispatch, editor }) => {
|
||||||
if (dispatch) {
|
if (dispatch) {
|
||||||
const content = createNodeFromContent(value, editor.schema, {
|
const content = createNodeFromContent(value, editor.schema, {
|
||||||
parseOptions: {
|
parseOptions: {
|
||||||
preserveWhitespace: 'full',
|
preserveWhitespace: 'full',
|
||||||
},
|
},
|
||||||
|
...(options || {})
|
||||||
})
|
})
|
||||||
|
|
||||||
// don’t dispatch an empty fragment because this can lead to strange errors
|
// don’t dispatch an empty fragment because this can lead to strange errors
|
||||||
|
Loading…
Reference in New Issue
Block a user