mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-07 01:12:56 +08:00
fix: improve setNode
behavior for list items, fix #2261
This commit is contained in:
parent
e09fd93e59
commit
f2ced6971d
@ -14,8 +14,26 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const setNode: RawCommands['setNode'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||
export const setNode: RawCommands['setNode'] = (typeOrName, attributes = {}) => ({ state, dispatch, chain }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
|
||||
return setBlockType(type, attributes)(state, dispatch)
|
||||
// TODO: use a fallback like insertContent?
|
||||
if (!type.isTextblock) {
|
||||
console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.')
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
const canSetBlock = setBlockType(type, attributes)(state)
|
||||
|
||||
if (canSetBlock) {
|
||||
return setBlockType(type, attributes)(state, dispatch)
|
||||
}
|
||||
|
||||
return chain()
|
||||
.clearNodes()
|
||||
.command(({ state: updatedState }) => {
|
||||
return setBlockType(type, attributes)(updatedState, dispatch)
|
||||
})
|
||||
.run()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user