refactoring

This commit is contained in:
Philipp Kühn
2020-11-02 16:23:43 +01:00
parent eed82a57b6
commit 389937c32f
15 changed files with 61 additions and 40 deletions

View File

@@ -0,0 +1,36 @@
import { Command } from '../Editor'
import { createExtension } from '../Extension'
export const ResetNodeAttributes = createExtension({
addCommands() {
return {
resetNodeAttributes: (attributeNames: string[] = []): Command => ({ tr, state, dispatch }) => {
const { selection } = tr
const { from, to } = selection
state.doc.nodesBetween(from, to, (node, pos) => {
if (!node.type.isText) {
attributeNames.forEach(name => {
const attribute = node.type.spec.attrs?.[name]
const defaultValue = attribute?.default
if (attribute && defaultValue !== undefined && dispatch) {
tr.setNodeMarkup(pos, undefined, {
[name]: defaultValue,
})
}
})
}
})
return true
},
}
},
})
declare module '../Editor' {
interface AllExtensions {
ResetNodeAttributes: typeof ResetNodeAttributes,
}
}