How to use command.lift
?
#1836
-
We have an inline Node for links. A link as mark was not enough, since we need to have a way to edit some custom aspects of the link. After some try and error, we were able to add a link using the The problem we face now is how to remove the link. We tried with both Here is an extract of what we currently have: export default Node.create({
name: 'link',
group: 'inline',
inline: true,
content: 'text*',
addAttributes() {
return {
href: {
default: '#',
},
// ... other attrs
}
},
addCommands() {
return {
setLink: () => ({ commands, state }) => {
const isActive = isNodeActive(state, 'link')
if (isActive) {
return commands.lift('link') // <== HERE
} else {
return commands.insertContent({
type: 'link',
attrs: {
href: 'https://',
},
content: state.selection.content().toJSON().content[0].content,
})
}
},
removeLink: () => ({ commands }) => {
return commands.lift('link') // <== AND HERE
},
}
},
// ...
} PS: Really cool library, we are really excited as a team as it looks really promising and it will allow us to move from our existing solution (based on Slate.js) that has a lot of bugs. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I’d recommend to go with the mark-based approach. What "aspects" do you need to change? I bet you could do that with attributes. https://www.tiptap.dev/guide/custom-extensions#attributes |
Beta Was this translation helpful? Give feedback.
I’d recommend to go with the mark-based approach. What "aspects" do you need to change? I bet you could do that with attributes.
https://www.tiptap.dev/guide/custom-extensions#attributes
https://www.tiptap.dev/api/commands/update-attributes
https://www.tiptap.dev/api/commands/extend-mark-range