Hi, I’m trying to add a node to the schema that would behave much like the dino example. The node is a non-editable piece of text. This is what I came up with for the spec:
{
content: "text*",
inline: true,
group: "inline",
draggable: true,
atom: true,
defining: true,
attrs: {
field: {default: 'personalisation'},
label: {default: 'personalisation'},
},
toDOM(node) {
return ['span', node.attrs, node.attrs.label]
},
parseDom: [
{
tag: 'span[field]',
getAttrs(dom){
return {
field: dom.getAttribute('field'),
label: dom.getAttribute('label'),
}
}
}
]
}
And this is the factory for inserting the node command:
function insertPersonalisationTag(field, label) {
return function(state, dispatch) {
let {$from} = state.selection, index = $from.index()
if (!$from.parent.canReplaceWith(index, index, editorSchema.nodes.personalisationTag))
return false
if (dispatch)
dispatch(state.tr.replaceSelectionWith(personalisationTag.create({field, label})))
return true
}
}
I am extending the basic schema. The code returns false for ‘canReplaceWith’ bit. What am I doing wrong? Thanks.