mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-07 17:43:49 +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)
|
const type = getNodeType(typeOrName, state.schema)
|
||||||
|
|
||||||
|
// 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 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