add type option to updateNodeAttributes

This commit is contained in:
Philipp Kühn
2020-11-18 14:46:47 +01:00
parent b3798b7329
commit 4a78318a74
2 changed files with 7 additions and 4 deletions

View File

@@ -1,11 +1,14 @@
import { NodeType } from 'prosemirror-model'
import getNodeType from '../utils/getNodeType'
import { Command } from '../types'
export default (attributes: {}): Command => ({ tr, state, dispatch }) => {
export default (typeOrName: string | NodeType, attributes: {}): Command => ({ tr, state, dispatch }) => {
const type = getNodeType(typeOrName, state.schema)
const { selection } = tr
const { from, to } = selection
state.doc.nodesBetween(from, to, (node, pos) => {
if (!node.type.isText && dispatch) {
if (node.type === type && dispatch) {
tr.setNodeMarkup(pos, undefined, {
...node.attrs,
...attributes,