Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rich text docs #99

Merged
merged 2 commits into from
Nov 15, 2024
Merged

Update rich text docs #99

merged 2 commits into from
Nov 15, 2024

Conversation

alexjg
Copy link
Contributor

@alexjg alexjg commented Nov 11, 2024

Update the rich text docs to match the simplified plugin API. This is a sketch, I still need to check the example code functions.

@c4lliope
Copy link
Contributor

This already is much more reliable! I can see the synchronization from one tab to another, and there are no more issues around the handle.whenReady() signal.

The one remaining issue I see: I can apply changes to a document, and then open the URL in a new tab and I see a blank page. The new editor does nothing to catch up on the change log.

From then on, any new synchronization occurs like normal, so the handle is solid. There is simply a missing phase: how to load the document from the docHandle into ProseMirror once the editor is rendered on screen.

I'll explore more once plugged in again.

@c4lliope
Copy link
Contributor

huh, do you think this could be an issue in the init() call?
I added some debugging assignments to the code, and came up with:

      const { doc, schema, plugin } = init(handle!, ["page"])
      window.doc = doc
      window.schema = schema
      window.plugin = plugin

browser console:

> doc
undefined

> schema
Object { linebreakReplacement: null, cached: {…}, spec: {…}, nodes: {…}, marks: {…}, nodeFromJSON: BoundFunctionObject, markFromJSON: BoundFunctionObject, topNodeType: {…} }

> plugin
Object { spec: {…}, props: {}, key: "automerge-sync$" }

@c4lliope
Copy link
Contributor

Meanwhile, window.handle.doc().then(console.log) seems to be populated like normal:

> handle.doc().then(console.log)
Object { page: "aaaaaabcdaabbaaaaaaBlank page.", … }

( I use page rather than text. Same idea; the doc is present in the repo and missing in the prosemirror callback.)

@c4lliope
Copy link
Contributor

Yep! A simple change in name; the guide should change doc to pmDoc in the init() return assignment:

  useEffect(() => {
    if (editorRoot.current != null && loaded) {
      const { pmDoc, schema, plugin } = init(handle!, ["text"])
      const plugins = exampleSetup({schema})
      plugins.push(plugin)

      setView(new EditorView(
        editorRoot.current,
        { state: EditorState.create({ schema, plugins, doc: pmDoc, }), }
      ))
    }
    return () => { if (view) { view.destroy(); setView(null) } }
  }, [editorRoot, loaded])

@c4lliope
Copy link
Contributor

You also have my 👍 to change the return signature to conform to prosemirror, seems sensible in this case.

c4lliope added a commit to c4lliope/automerge-prosemirror that referenced this pull request Nov 14, 2024
@c4lliope
Copy link
Contributor

Also see!
automerge/automerge-prosemirror#27

@alexjg alexjg marked this pull request as ready for review November 15, 2024 12:10
@alexjg alexjg merged commit 5234df2 into main Nov 15, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants