Who is responsible for increasing version on the front-end (i am using tiptap v1). As far as i found, 'prosemirror-collab' is the main, and here is the line 122:
let version = collabState.version + steps.length
any chance to tell this module not to increase version when user is offline (i have flag for dettecting it)?
I'm feeling really stupid but I just don't get it to work: in an input rule I want to replace a text with another text that has a mark applied to it. I tried the following:
this.inputRules.push(new InputRule(/...../,
(state, match, start, end) => {
var label = match[0]
var linkMarkSchema = state.schema.marks.link
var linkMark = linkMarkSchema.create()
linkMark.attrs.href = `/note/${label}`
var tr = state.tr
tr = tr.addMark(start, end, linkMark)
tr = tr.insertText(label, start, end)
return tr
}))
What happens is that the text gets replaced with the new text but the mark is lost. If I switch addMark
and insertText
around I simply get Cannot read property 'nodeSize' of undefined
. So I figured maybe I have to insert the text first and then get the range of the transaction so I can use it in addMark
, but... how do I do that?
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..