From 81051835f48616b693e430d7beb38e1d61b8d718 Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Sat, 26 Sep 2020 14:30:09 +0200 Subject: [PATCH] add offline support to the collaboration example --- docs/package.json | 1 + docs/src/demos/Examples/Collaboration/index.vue | 8 +++++++- yarn.lock | 9 ++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/package.json b/docs/package.json index 2ad3f3ae6..7518bca0b 100644 --- a/docs/package.json +++ b/docs/package.json @@ -22,6 +22,7 @@ "remark-container": "^0.1.2", "typescript": "^4.0.3", "vue-github-button": "^1.1.2", + "y-indexeddb": "^9.0.5", "y-webrtc": "^10.1.6", "yjs": "^13.3.2" }, diff --git a/docs/src/demos/Examples/Collaboration/index.vue b/docs/src/demos/Examples/Collaboration/index.vue index 6874f4c54..92640baeb 100644 --- a/docs/src/demos/Examples/Collaboration/index.vue +++ b/docs/src/demos/Examples/Collaboration/index.vue @@ -17,6 +17,7 @@ import Collaboration from '@tiptap/extension-collaboration' import CollaborationCursor from '@tiptap/extension-collaboration-cursor' import * as Y from 'yjs' import { WebrtcProvider } from 'y-webrtc' +import { IndexeddbPersistence } from 'y-indexeddb' export default { components: { @@ -28,15 +29,20 @@ export default { ydoc: null, provider: null, type: null, + indexdb: null, numberOfConnectedUsers: 0, editor: null, } }, mounted() { + const name = 'example' + this.ydoc = new Y.Doc() - this.provider = new WebrtcProvider('example', this.ydoc) + this.provider = new WebrtcProvider(name, this.ydoc) this.type = this.ydoc.getXmlFragment('prosemirror') + this.indexdb = new IndexeddbPersistence(name, this.ydoc) + this.provider.on('peers', ({ bcPeers, webrtcPeers }) => { this.numberOfConnectedUsers = bcPeers.length + webrtcPeers.length }) diff --git a/yarn.lock b/yarn.lock index 9faa4a860..55bc5f451 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8617,7 +8617,7 @@ levn@~0.3.0: prelude-ls "~1.1.2" type-check "~0.3.2" -lib0@^0.2.28, lib0@^0.2.32, lib0@^0.2.33: +lib0@^0.2.12, lib0@^0.2.28, lib0@^0.2.32, lib0@^0.2.33: version "0.2.33" resolved "https://registry.yarnpkg.com/lib0/-/lib0-0.2.33.tgz#dd759c489d416344efe065c534bccf3ce4925d3e" integrity sha512-Pnm8FzjUr+aTYkEu2A20c1EfVHla8GbVX+GXn6poxx0gcmEuCs+XszjLmtEbI9xYOoI/83xVi7VOIoyHgOO87w== @@ -14771,6 +14771,13 @@ xtend@^4.0.0, xtend@^4.0.1, xtend@~4.0.1: resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54" integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ== +y-indexeddb@^9.0.5: + version "9.0.5" + resolved "https://registry.yarnpkg.com/y-indexeddb/-/y-indexeddb-9.0.5.tgz#a162526add738a456b7185a6a5626534609ee132" + integrity sha512-40VxkqPoK2VxE1vMosS5MfwlHQOvaeLEN89dIkjh7URjZny6bDQOl4yKldaDv9ZosZgYEPyWuWTF3Z92RZ1y+A== + dependencies: + lib0 "^0.2.12" + y-prosemirror@^0.3.7: version "0.3.7" resolved "https://registry.yarnpkg.com/y-prosemirror/-/y-prosemirror-0.3.7.tgz#df929ceacb3e35c568db9f1a5a36b0515b3732fc"