@liveblocks/yjs 1.1.0-yjs3 → 1.1.0-yjs5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +22 -15
- package/dist/index.mjs +22 -15
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ declare class LiveblocksProvider<P extends JsonObject, S extends LsonObject, U e
|
|
|
32
32
|
private unsubscribers;
|
|
33
33
|
awareness: Awareness;
|
|
34
34
|
constructor(room: Room<P, S, U, E>, doc: Y.Doc, config?: LiveblocksYjsOptions);
|
|
35
|
+
private syncDoc;
|
|
35
36
|
private updateHandler;
|
|
36
37
|
private resyncHttp;
|
|
37
38
|
destroy(): void;
|
package/dist/index.js
CHANGED
|
@@ -158,11 +158,19 @@ var Awareness = class extends Observable {
|
|
|
158
158
|
return presence["__yjs"];
|
|
159
159
|
}
|
|
160
160
|
setLocalState(state) {
|
|
161
|
-
|
|
161
|
+
var _a;
|
|
162
|
+
const presence = (_a = this.room.getSelf()) == null ? void 0 : _a.presence["__yjs"];
|
|
163
|
+
this.room.updatePresence({
|
|
164
|
+
__yjs: __spreadValues(__spreadValues({}, presence || {}), state || {})
|
|
165
|
+
});
|
|
162
166
|
}
|
|
163
167
|
setLocalStateField(field, value) {
|
|
168
|
+
var _a;
|
|
169
|
+
const presence = (_a = this.room.getSelf()) == null ? void 0 : _a.presence["__yjs"];
|
|
164
170
|
const update = { [field]: value };
|
|
165
|
-
this.room.updatePresence({
|
|
171
|
+
this.room.updatePresence({
|
|
172
|
+
__yjs: __spreadValues(__spreadValues({}, presence || {}), update)
|
|
173
|
+
});
|
|
166
174
|
}
|
|
167
175
|
// Translate liveblocks presence to yjs awareness
|
|
168
176
|
getStates() {
|
|
@@ -183,10 +191,17 @@ var LiveblocksProvider = class {
|
|
|
183
191
|
constructor(room, doc, config) {
|
|
184
192
|
this.lastUpdateDate = null;
|
|
185
193
|
this.unsubscribers = [];
|
|
194
|
+
this.syncDoc = () => {
|
|
195
|
+
var _a;
|
|
196
|
+
this.doc.clientID = ((_a = this.room.getSelf()) == null ? void 0 : _a.connectionId) || this.doc.clientID;
|
|
197
|
+
this.awareness.clientID = this.doc.clientID;
|
|
198
|
+
const encodedVector = _jsbase64.Base64.fromUint8Array(Y.encodeStateVector(this.doc));
|
|
199
|
+
this.room.getYDoc(encodedVector);
|
|
200
|
+
};
|
|
186
201
|
this.updateHandler = (update, origin) => __async(this, null, function* () {
|
|
187
202
|
if (origin !== "backend") {
|
|
188
203
|
const encodedUpdate = _jsbase64.Base64.fromUint8Array(update);
|
|
189
|
-
this.room.
|
|
204
|
+
this.room.updateYDoc(encodedUpdate);
|
|
190
205
|
if (this.httpEndpoint) {
|
|
191
206
|
yield fetch(this.httpEndpoint, {
|
|
192
207
|
method: "POST",
|
|
@@ -206,22 +221,14 @@ var LiveblocksProvider = class {
|
|
|
206
221
|
this.doc.on("update", this.updateHandler);
|
|
207
222
|
this.unsubscribers.push(
|
|
208
223
|
this.room.events.connection.subscribe((e) => {
|
|
209
|
-
var _a2;
|
|
210
224
|
if (e === "open") {
|
|
211
|
-
this.
|
|
212
|
-
this.awareness.clientID = this.doc.clientID;
|
|
213
|
-
const encodedVector = _jsbase64.Base64.fromUint8Array(
|
|
214
|
-
Y.encodeStateVector(this.doc)
|
|
215
|
-
);
|
|
216
|
-
this.room.getDoc(encodedVector);
|
|
225
|
+
this.syncDoc();
|
|
217
226
|
}
|
|
218
227
|
})
|
|
219
228
|
);
|
|
220
229
|
this.unsubscribers.push(
|
|
221
|
-
this.room.events.docUpdated.subscribe((
|
|
222
|
-
|
|
223
|
-
const update = Y.mergeUpdates(decodedUpdates);
|
|
224
|
-
Y.applyUpdate(this.doc, update, "backend");
|
|
230
|
+
this.room.events.docUpdated.subscribe((update) => {
|
|
231
|
+
Y.applyUpdate(this.doc, _jsbase64.Base64.toUint8Array(update), "backend");
|
|
225
232
|
})
|
|
226
233
|
);
|
|
227
234
|
if (config == null ? void 0 : config.httpEndpoint) {
|
|
@@ -235,7 +242,7 @@ var LiveblocksProvider = class {
|
|
|
235
242
|
);
|
|
236
243
|
void this.resyncHttp();
|
|
237
244
|
}
|
|
238
|
-
this.
|
|
245
|
+
this.syncDoc();
|
|
239
246
|
}
|
|
240
247
|
resyncHttp() {
|
|
241
248
|
return __async(this, null, function* () {
|
package/dist/index.mjs
CHANGED
|
@@ -158,11 +158,19 @@ var Awareness = class extends Observable {
|
|
|
158
158
|
return presence["__yjs"];
|
|
159
159
|
}
|
|
160
160
|
setLocalState(state) {
|
|
161
|
-
|
|
161
|
+
var _a;
|
|
162
|
+
const presence = (_a = this.room.getSelf()) == null ? void 0 : _a.presence["__yjs"];
|
|
163
|
+
this.room.updatePresence({
|
|
164
|
+
__yjs: __spreadValues(__spreadValues({}, presence || {}), state || {})
|
|
165
|
+
});
|
|
162
166
|
}
|
|
163
167
|
setLocalStateField(field, value) {
|
|
168
|
+
var _a;
|
|
169
|
+
const presence = (_a = this.room.getSelf()) == null ? void 0 : _a.presence["__yjs"];
|
|
164
170
|
const update = { [field]: value };
|
|
165
|
-
this.room.updatePresence({
|
|
171
|
+
this.room.updatePresence({
|
|
172
|
+
__yjs: __spreadValues(__spreadValues({}, presence || {}), update)
|
|
173
|
+
});
|
|
166
174
|
}
|
|
167
175
|
// Translate liveblocks presence to yjs awareness
|
|
168
176
|
getStates() {
|
|
@@ -183,10 +191,17 @@ var LiveblocksProvider = class {
|
|
|
183
191
|
constructor(room, doc, config) {
|
|
184
192
|
this.lastUpdateDate = null;
|
|
185
193
|
this.unsubscribers = [];
|
|
194
|
+
this.syncDoc = () => {
|
|
195
|
+
var _a;
|
|
196
|
+
this.doc.clientID = ((_a = this.room.getSelf()) == null ? void 0 : _a.connectionId) || this.doc.clientID;
|
|
197
|
+
this.awareness.clientID = this.doc.clientID;
|
|
198
|
+
const encodedVector = Base64.fromUint8Array(Y.encodeStateVector(this.doc));
|
|
199
|
+
this.room.getYDoc(encodedVector);
|
|
200
|
+
};
|
|
186
201
|
this.updateHandler = (update, origin) => __async(this, null, function* () {
|
|
187
202
|
if (origin !== "backend") {
|
|
188
203
|
const encodedUpdate = Base64.fromUint8Array(update);
|
|
189
|
-
this.room.
|
|
204
|
+
this.room.updateYDoc(encodedUpdate);
|
|
190
205
|
if (this.httpEndpoint) {
|
|
191
206
|
yield fetch(this.httpEndpoint, {
|
|
192
207
|
method: "POST",
|
|
@@ -206,22 +221,14 @@ var LiveblocksProvider = class {
|
|
|
206
221
|
this.doc.on("update", this.updateHandler);
|
|
207
222
|
this.unsubscribers.push(
|
|
208
223
|
this.room.events.connection.subscribe((e) => {
|
|
209
|
-
var _a2;
|
|
210
224
|
if (e === "open") {
|
|
211
|
-
this.
|
|
212
|
-
this.awareness.clientID = this.doc.clientID;
|
|
213
|
-
const encodedVector = Base64.fromUint8Array(
|
|
214
|
-
Y.encodeStateVector(this.doc)
|
|
215
|
-
);
|
|
216
|
-
this.room.getDoc(encodedVector);
|
|
225
|
+
this.syncDoc();
|
|
217
226
|
}
|
|
218
227
|
})
|
|
219
228
|
);
|
|
220
229
|
this.unsubscribers.push(
|
|
221
|
-
this.room.events.docUpdated.subscribe((
|
|
222
|
-
|
|
223
|
-
const update = Y.mergeUpdates(decodedUpdates);
|
|
224
|
-
Y.applyUpdate(this.doc, update, "backend");
|
|
230
|
+
this.room.events.docUpdated.subscribe((update) => {
|
|
231
|
+
Y.applyUpdate(this.doc, Base64.toUint8Array(update), "backend");
|
|
225
232
|
})
|
|
226
233
|
);
|
|
227
234
|
if (config == null ? void 0 : config.httpEndpoint) {
|
|
@@ -235,7 +242,7 @@ var LiveblocksProvider = class {
|
|
|
235
242
|
);
|
|
236
243
|
void this.resyncHttp();
|
|
237
244
|
}
|
|
238
|
-
this.
|
|
245
|
+
this.syncDoc();
|
|
239
246
|
}
|
|
240
247
|
resyncHttp() {
|
|
241
248
|
return __async(this, null, function* () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liveblocks/yjs",
|
|
3
|
-
"version": "1.1.0-
|
|
3
|
+
"version": "1.1.0-yjs5",
|
|
4
4
|
"description": "An integration with . Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@liveblocks/client": "1.1.0-
|
|
30
|
-
"@liveblocks/core": "1.1.0-
|
|
29
|
+
"@liveblocks/client": "1.1.0-yjs5",
|
|
30
|
+
"@liveblocks/core": "1.1.0-yjs5",
|
|
31
31
|
"js-base64": "^3.7.5"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|