add type option to updateNodeAttributes
This commit is contained in:
@@ -1,11 +1,14 @@
|
|||||||
|
import { NodeType } from 'prosemirror-model'
|
||||||
|
import getNodeType from '../utils/getNodeType'
|
||||||
import { Command } from '../types'
|
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 { selection } = tr
|
||||||
const { from, to } = selection
|
const { from, to } = selection
|
||||||
|
|
||||||
state.doc.nodesBetween(from, to, (node, pos) => {
|
state.doc.nodesBetween(from, to, (node, pos) => {
|
||||||
if (!node.type.isText && dispatch) {
|
if (node.type === type && dispatch) {
|
||||||
tr.setNodeMarkup(pos, undefined, {
|
tr.setNodeMarkup(pos, undefined, {
|
||||||
...node.attrs,
|
...node.attrs,
|
||||||
...attributes,
|
...attributes,
|
||||||
|
|||||||
@@ -42,13 +42,13 @@ const TextAlign = Extension.create({
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return commands.updateNodeAttributes({ textAlign: alignment })
|
return this.options.types.every(type => commands.updateNodeAttributes(type, { textAlign: alignment }))
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Unset the text align attribute
|
* Unset the text align attribute
|
||||||
*/
|
*/
|
||||||
unsetTextAlign: (): Command => ({ commands }) => {
|
unsetTextAlign: (): Command => ({ commands }) => {
|
||||||
return commands.updateNodeAttributes({ textAlign: null })
|
return this.options.types.every(type => commands.updateNodeAttributes(type, { textAlign: null }))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user