Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 08:26
    marijnh commented #476
  • 08:25
    marijnh commented #1319
  • 08:24
    marijnh closed #1319
  • 08:17
    eric-burel commented #1318
  • Oct 04 18:22
    fletchertyler914 opened #1319
  • Oct 04 16:46
    marijnh commented #1318
  • Oct 04 14:47
    eric-burel opened #1318
  • Oct 04 09:02
    roman-kulakov commented #476
  • Oct 02 17:32
    marijnh closed #1316
  • Oct 02 17:32
    marijnh commented #1316
  • Oct 02 17:27
    marijnh commented #1317
  • Oct 01 23:01
    xiaweiss commented #1317
  • Oct 01 15:54
    marijnh commented #1317
  • Oct 01 10:06
    xiaweiss edited #1317
  • Oct 01 10:06
    xiaweiss opened #1317
  • Oct 01 07:09
    mfissehaye opened #1316
  • Sep 30 10:43
    marijnh commented #476
  • Sep 29 09:06
    marijnh commented #1314
  • Sep 28 15:37
    wbharding commented #1314
  • Sep 28 15:36
    wbharding commented #1314
Zeljko Bulatovic
@zeljko-bulatovic
Thank you very much, i will check!
Sebastian Podgajny
@SebastianPodgajny
Awesome, thanks!
Zeljko Bulatovic
@zeljko-bulatovic

Hi @marijnh , i checked the collab demo from the ProseMirror docs, and i got similar situation like i had right now.. The use case is that two clients are working on the same doc, and then server is down during deploy, or clients got network issues, but they are not aware of it and they continue to type, but as soon as server is up or they come online, multiple new steps are sent, i am getting the following error (this is error from ProseMirror collab server)

Error: Invalid version 91
at Instance.checkVersion (/website/src/collab/server/instance.js:73:17)
at Instance.getEvents (/website/src/collab/server/instance.js:83:10)
at handle (/website/src/collab/server/server.js:140:19)
at finish (/website/src/collab/server/server.js:53:34)
at Object.router.add.args [as handler] (/website/src/collab/server/server.js:67:7)
at routes.some.route (/website/src/collab/server/route.js:47:13)
at Array.some (<anonymous>)
at Router.resolve (/website/src/collab/server/route.js:42:24)
at exports.handleCollabRequest (/website/src/collab/server/server.js:10:17)
at maybeCollab (/website/src/devserver.js:59:9)

Any suggestion how to handle multiple steps with higher version (db has version 10, and client is sending version 15 for example)
Marijn Haverbeke
@marijnh
Clients only roll forward their version when the server has confirmed that it's received the changes, so the scenario you describe shouldn't happen unless the server lost data on restart.
Zeljko Bulatovic
@zeljko-bulatovic
Bigger issue is because some clients has poor wifi connection, and while websockets reconnect and everything is synced, their local version is higher than server version and then i am receiving this error when they send all steps at once
Marijn Haverbeke
@marijnh
No, something else is going wrong, because, as I said, a proper client implementation does not increase its version until it receives the steps it submitted back from the server, to avoid exactly this problem.
Cris Ward
@crisward
Hey all, I'm trying to make the html in my prosemirror editable using codemirror. I have this working, but because I update the whole state on every key press I loose the prosemirror undo stack. I realise I probably need to do a state transform but have no idea where to start with this (eg identify the correct node, change etc). Is there anything in code/prosemirror I can use to map a change in one into a transform into the other?
Cris Ward
@crisward
Ended up doing this, which gives me my undos. Probably not ideal as I'm still replacing the whole doc, but seems performant enough for now.
function updateHTML(view,html){
    let domNode = document.createElement("div");
    domNode.innerHTML = html;
    let tr = view.state.tr;
    let node = DOMParser.fromSchema(schema).parse(domNode);
    tr.setSelection(new AllSelection(view.state.doc));
    tr.replaceSelectionWith(node);
    view.dispatch(tr);
}
Marijn Haverbeke
@marijnh
The example of CodeMirror integration on the website converts code changes to precise ProseMirror transactions. Does that help?
Cris Ward
@crisward
@marijnh thanks for link. I'll take another look. I didn't realise it update the prosemirror state.
Cris Ward
@crisward
It looks like the example updates plain text into a single node. So not exactly what I'm after. But thanks for the feedback. Prosemirror is an excellent library BTW, having fought with contenteditable in the past and working with other less stable abstractions over that it's a pleasure to use. Many thanks for all the work you've put into it.
Zeljko Bulatovic
@zeljko-bulatovic
Hmm, i will take a look, thank you!
Zeljko Bulatovic
@zeljko-bulatovic

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)?

Marijn Haverbeke
@marijnh
You should not be calling receiveTransaction when the user is offline, so I think that's where the problem lies.
Zeljko Bulatovic
@zeljko-bulatovic
Thank you!
ithil
@ithil

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?

ithil
@ithil

Ahh now I have found a solution:

tr = tr.insertText(label, start, end)
tr = tr.addMark(start, start+label.length, linkMark)

Though I'm not sure this is the most robust way?

Sebastian Podgajny
@SebastianPodgajny
Is there a way to render prosemirror state as plain html? (without event listeners)
Cris Ward
@crisward
I'm doing this...
let copy = slide.node.copy(start,end)
tr.delete(start,end)
tr.insert(insertPos, copy)
But sometimes the content of the copy is being added to multiple nodes. Specifically images. So the copy if a div wrapped around and image. There are muliple divs in a surrounding div. Not sure what I'm doing wrong. But insert should only effect one node.. correct?
(I'm guessing I'm screwing up somewhere else in my app)
Cris Ward
@crisward
Found the solution to my own problem. Before the above step I was doing a transform that was updating the attributes of a node, but setting the attributes to the same value as they already had. For some reason this caused the insert/delete to be performed on the wrong nodes, checking and skipping over the non changes fixed the issue.
Marijn Haverbeke
@marijnh
@SebastianPodgajny Look into the DOMSerializer class
Manuel Jacob
@manueljacob
Is there a plugin that implements nested sections, similar to what’s described in https://discuss.prosemirror.net/t/nested-sections-and-splitblock/2323 ?
Manuel Jacob
@manueljacob
Is it possible to get a stable identifier for some block element?
Manuel Jacob
@manueljacob
The background is: In a React application, I’m rendering the document structure (outline) next to the editor. Each node in the outline tree view component needs to have some ID, e.g. for tracking whether the node was expanded in the tree view or not.
Marijn Haverbeke
@marijnh
I'm not aware of a plugin that does the nested section structure. (But I know several people have implemented it in their proprietary systems.)
Assigning and deduplicating IDs is usually done in an appendTransaction hook.
andreas
@andreasvirkus
Hi everyone! I'm seeing a weird behaviour with a plugin where i return a handlePaste handler in my props. I'm trying to read multiple images/files from the clipboard but only get the very last one. Even though all file names are still pasted into the editor
Andrew Kirwin
@amk221

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?

Marijn Haverbeke
@marijnh
It would be rather expensive to check its entire content every time a node is created, so ProseMirror doesn't do that. Passing invalid content to NodeType.create is considered an error in the calling code.
Andrew Kirwin
@amk221

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.

Marijn Haverbeke
@marijnh
You can call .check() on a node if you want to assert that it has valid structure.
Andrew Kirwin
@amk221
Nice
Andrew Kirwin
@amk221
Yeh that's perfect, cheers
Andrew Kirwin
@amk221
Seems like a call to doc.check() couldn't harm. Because a doc is required.
Andrew Kirwin
@amk221
(and so it may as well be valid?)
André Drougge
@miphe
Hi all, I'm looking to implement "link" button on my editor. Can't really find an example on how to do that. It's not as straightforward as bold or italic, since I need a URL and link text as well.
Is there a good example around on how to achieve this?
Andrew Kirwin
@amk221
@miphe
const href = prompt('Link');
toggleMark(editor.state.schema.marks.link, { href })(editor.state, editor.dispatch)
Andrew Kirwin
@amk221

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);
}
André Drougge
@miphe
Thank you @amk221
I get missing value for href though, but this seems to get me further:
toggleMark(schema.marks.link, { href: { url: '...', title: '...' } })(state, dispatch);
I've just been trying things out, I don't know if that's correct.. because I don't know where to find this information in documentation :/
Andrew Kirwin
@amk221

@miphe The docs are clear:

toggleMark(markType: MarkType, attrs: ?⁠Object)

So that's

toggleMark(yourLinkMark, anyAttrsGoHere)

The way you have sent in your attrs is wrong
it should be as per my example above. You've confused href with url

André Drougge
@miphe
All right, so this would be it:
toggleMark(schema.marks.link, { href: 'http://example.com' })
And if I want a title attribute, I can add that there too.
Andrew Kirwin
@amk221
that's it