mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-21 00:13:58 +08:00
22 lines
684 B
TypeScript
22 lines
684 B
TypeScript
import { NodeType } from 'prosemirror-model'
|
|
import getNodeType from '../utils/getNodeType'
|
|
import deleteProps from '../utils/deleteProps'
|
|
import { Command } from '../types'
|
|
|
|
/**
|
|
* Resets node attributes to the default value.
|
|
*/
|
|
export const resetNodeAttributes = (typeOrName: string | NodeType, attributes: string | string[]): 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 === type && dispatch) {
|
|
tr.setNodeMarkup(pos, undefined, deleteProps(node.attrs, attributes))
|
|
}
|
|
})
|
|
|
|
return true
|
|
}
|