Skip to content

How to save document to database #316

Answered by BitPhinix
karthikcodes6 asked this question in Q&A
Discussion options

You must be logged in to vote

You can convert the root Y.XmlText to a slate element using yTextToSlateElement.

Something along the lines of

const server = Server.configure({
  port: 1234,

  extensions: [new Logger()],
  onChange: async (data) => {
    const sharedRoot = data.document.get('content', Y.XmlText) as Y.XmlText
    const slateContents = yTextToSlateElement(sharedRoot).children

    // ....
  },

  async onLoadDocument(data) {
    if (data.document.isEmpty('content')) {
      const insertDelta = slateNodesToInsertDelta(initialValue)
      const sharedRoot = data.document.get('content', Y.XmlText) as Y.XmlText
      sharedRoot.applyDelta(insertDelta)
    }

    return data.document
  },
})

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@karthikcodes6
Comment options

Answer selected by BitPhinix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #315 on February 02, 2022 12:05.