How to use the y-protocols/history.js.readHistorySnapshot function in y-protocols

To help you get started, we’ve selected a few y-protocols examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yjs / yjs / examples / prosemirror-history.js View on Github external
history.forEach(buf => {
      const decoder = decoding.createDecoder(buf)
      const snapshot = historyProtocol.readHistorySnapshot(decoder)
      const date = new Date(decoding.readUint32(decoder) * 1000)
      const restoreBtn = crel('button', { type: 'button' }, ['restore'])
      const a = crel('a', [
        '• ' + date.toUTCString(), restoreBtn
      ])
      const el = crel('div', [ a ])
      let prevSnapshot = _prevSnap // rebind to new variable
      restoreBtn.addEventListener('click', event => {
        if (prevSnapshot === null) {
          prevSnapshot = { ds: snapshot.ds, sm: new Map() }
        }
        this.editorView.dispatch(this.editorView.state.tr.setMeta(prosemirrorPluginKey, { snapshot, prevSnapshot, restore: true }))
        event.stopPropagation()
      })
      a.addEventListener('click', () => {
        console.log('setting snapshot')