Dear all,
I am checking prosemirror using ngx-editor and angular. So far, I could embed it nicely but I have two issues.
1/ Cursor position
I extended the basic schema to add a custom node :
const myCustomNode: NodeSpec = {
attrs: {
id: {},
source: {},
description: { default: null },
},
inline: true,
group: 'inline',
draggable: true,
atom: true,
selectable: true,
content: '',
toDOM: (node) => {
return [
'span',
{ class: 'my-custom-node', 'data-id': node.attrs['id'], 'data-source': node.attrs['source'] },
node.attrs['description'],
];
},
parseDOM: [
{
tag: 'span.my-custom-node',
getAttrs: (node) => {
if (typeof node === 'string') {
return false;
}
const element = node as HTMLElement;
return {
id: element.getAttribute('data-id'),
source: element.getAttribute('data-source'),
description: element.textContent || undefined,
};
},
},
],
};
and extended the schema like this :
const nodes = {
...basicNodes,
myCustomNode: myCustomNode,
};
export const extendedSchema = new Schema({
nodes,
marks,
});
I am building my editor using new Editor({plugins: [dropCursor()], schema: extendedSchema});
I add my custom node to the editor on drop using the code below :
// Create a transaction to insert the node
const transaction = editorView.state.tr.insert(coords.pos, customNode);
// Apply the transaction to the editor state
editorView.dispatch(transaction);
Everything works fine except the cursor position which appears under the custom node even though when I start typing the text goes next to it and not under (which is the expected behavior) it is really just a display issue.
2/ Spacing problem
If I don’t put any text near to my node, I have this two lines of code added after the insert and then an empty line after my node. I didn’t find any option to remove that.
<img class="ProseMirror-separator" alt="">
<br class="ProseMirror-trailingBreak">
Best,