I think the Transform.setNodeMarkup() method is how, but I don’t know how to get the position parameter from the current selection.
let { $from } = state.selection, index = $from.index();
let {attrs} = $from.parent;
tr.setNodeMarkup(position???, null, {...attrs, someValue });