If I have a doc
schema of block+
, then I create some state:
EditorState.create({
doc: schema.nodeFromJSON({
type: 'doc',
content: []
})
});
I think this sets up prosemirror in a funny state, because it was expecting at least 1 block. But, we didn't give it 1 block.
(This leads to issues with decoration position)
Can/should prosemirror throw an error in this circumstance?
Thanks, that makes sense. How about not every time a node is created, but at the time the EditorState.create
is called?
If not, I'm just thinking about where/how I can guard for this in our app. As it will undoubtedly lead to issues when we render prosemirror with json from our backend api.
When using custom node views, generally its assumed you'd make your own dom nodes, thereby bypassing toDOM
from the node type spec...... but, what if you want the new view to just add a layer of behaviour (and not have to re-do all the work that toDOM
does?).
Is it possible in a new view to convert the node to dom, and just use it as it is, rather than assuming it will be entirely custom?
constructor(node, editor, getPos) {
this.node = node;
// this.dom = document.createElement('div') // not this
this.dom = node.toDOM(); // this?
this.dom.addEventListener('click', this._clickHandler);
}
toggleMark(schema.marks.link, { href: { url: '...', title: '...' } })(state, dispatch);
title
attribute, I can add that there too.
I'm aiming to use textBetween in order to create a link feature, seems it's not that straightforward.
I made a PoC in this code sandbox https://codesandbox.io/s/prosemirror-markdown-react-b4gfr?file=/src/RichEditor.js
Perhaps this illustrate my struggles more clearly? I'd appreciate any indications here..
I need to implement a 'toggle mode' feature (preview ↔ edit).
This could be done by adding a class, something like this:
.ProseMirror--edit-mode .my-node {
border: 1px solid red;
}
Hello <div class="my-node">World</div>
...but that means all the styles are 'trapped' inside the ProseMirror 'namespace'.
An alternative approach would be to iterate through certain nodes and remove them when in preview mode:
Hello World
I don't really know where to start with the latter. Can anybody guide me? Or is there a better way?