add link commands

This commit is contained in:
Philipp Kühn
2020-11-18 11:10:06 +01:00
parent 9d99e9c9d0
commit 56c8bb1bd0
3 changed files with 19 additions and 11 deletions

View File

@@ -47,14 +47,22 @@ const Link = Mark.create({
addCommands() {
return {
/**
* Toggle or update a link mark
* Add a link mark
*/
link: (options: { href?: string, target?: string } = {}): Command => ({ commands }) => {
if (!options.href) {
return commands.removeMark('link')
}
return commands.addMark('link', options)
addLink: (attributes: { href?: string, target?: string } = {}): Command => ({ commands }) => {
return commands.addMark('link', attributes)
},
/**
* Toggle a link mark
*/
toggleLink: (attributes: { href?: string, target?: string } = {}): Command => ({ commands }) => {
return commands.toggleMark('link', attributes)
},
/**
* Remove a link mark
*/
removeLink: (): Command => ({ commands }) => {
return commands.removeMark('link')
},
}
},