@liveblocks/yjs
Advanced tools
Comparing version 2.4.1-test4 to 2.5.0
@@ -42,7 +42,7 @@ import { JsonObject, LsonObject, BaseUserMeta, Json, BaseMetadata, Room, User } from '@liveblocks/client'; | ||
isRoot: boolean; | ||
updateDoc: (update: string, guid?: string) => void; | ||
updateDoc: (update: Uint8Array, guid?: string) => void; | ||
fetchDoc: (vector: string, guid?: string) => void; | ||
}); | ||
handleServerUpdate: ({ update, stateVector, readOnly, }: { | ||
update: string; | ||
update: Uint8Array; | ||
stateVector: string | null; | ||
@@ -61,2 +61,7 @@ readOnly: boolean; | ||
}; | ||
declare enum SyncStatus { | ||
Loading = "loading", | ||
Synchronizing = "synchronizing", | ||
Synchronized = "synchronized" | ||
} | ||
declare class LiveblocksYjsProvider<P extends JsonObject = DP, S extends LsonObject = DS, U extends BaseUserMeta = DU, E extends Json = DE, M extends BaseMetadata$1 = DM> extends Observable<unknown> { | ||
@@ -70,4 +75,6 @@ private room; | ||
subdocHandlers: Map<string, yDocHandler>; | ||
private pending; | ||
constructor(room: Room<P, S, U, E, M>, doc: Y.Doc, options?: ProviderOptions | undefined); | ||
private handleSubdocs; | ||
private getUniqueUpdateId; | ||
private updateDoc; | ||
@@ -79,2 +86,3 @@ private fetchDoc; | ||
get synced(): boolean; | ||
getStatus(): SyncStatus; | ||
destroy(): void; | ||
@@ -81,0 +89,0 @@ disconnect(): void; |
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/index.ts | ||
var _core = require('@liveblocks/core'); | ||
var _jsbase64 = require('js-base64'); | ||
@@ -74,2 +75,5 @@ // ../../node_modules/lib0/map.js | ||
// src/index.ts | ||
var _yjs = require('yjs'); var Y2 = _interopRequireWildcard(_yjs); var Y = _interopRequireWildcard(_yjs); | ||
// src/awareness.ts | ||
@@ -201,4 +205,4 @@ var Y_PRESENCE_KEY = "__yjs"; | ||
// src/doc.ts | ||
var _jsbase64 = require('js-base64'); | ||
var _yjs = require('yjs'); var Y = _interopRequireWildcard(_yjs); | ||
var yDocHandler = class extends Observable { | ||
@@ -219,3 +223,3 @@ constructor({ | ||
}) => { | ||
Y.applyUpdate(this.doc, _jsbase64.Base64.toUint8Array(update), "backend"); | ||
Y.applyUpdate(this.doc, update, "backend"); | ||
if (stateVector) { | ||
@@ -228,3 +232,3 @@ if (!readOnly) { | ||
); | ||
this.updateRoomDoc(_jsbase64.Base64.fromUint8Array(localUpdate)); | ||
this.updateRoomDoc(localUpdate); | ||
} catch (e) { | ||
@@ -244,4 +248,3 @@ console.warn(e); | ||
if (origin !== "backend") { | ||
const encodedUpdate = _jsbase64.Base64.fromUint8Array(update); | ||
this.updateRoomDoc(encodedUpdate); | ||
this.updateRoomDoc(update); | ||
} | ||
@@ -280,3 +283,3 @@ }; | ||
var PKG_NAME = "@liveblocks/yjs"; | ||
var PKG_VERSION = "2.4.1-test4"; | ||
var PKG_VERSION = "2.5.0"; | ||
var PKG_FORMAT = "cjs"; | ||
@@ -291,2 +294,3 @@ | ||
this.subdocHandlers = /* @__PURE__ */ new Map(); | ||
this.pending = []; | ||
this.handleSubdocs = ({ | ||
@@ -312,6 +316,13 @@ loaded, | ||
}; | ||
this.getUniqueUpdateId = (update) => { | ||
const clock = _nullishCoalesce(Y2.parseUpdateMeta(update).to.get(this.rootDoc.clientID), () => ( "-1")); | ||
return this.rootDoc.clientID + ":" + clock; | ||
}; | ||
this.updateDoc = (update, guid) => { | ||
const canWrite = _nullishCoalesce(_optionalChain([this, 'access', _22 => _22.room, 'access', _23 => _23.getSelf, 'call', _24 => _24(), 'optionalAccess', _25 => _25.canWrite]), () => ( true)); | ||
if (canWrite) { | ||
this.room.updateYDoc(update, guid); | ||
const updateId = this.getUniqueUpdateId(update); | ||
this.pending.push(updateId); | ||
this.room.updateYDoc(_jsbase64.Base64.fromUint8Array(update), guid); | ||
this.emit("status", [this.getStatus()]); | ||
} | ||
@@ -369,2 +380,3 @@ }; | ||
} | ||
this.emit("status", [this.getStatus()]); | ||
}) | ||
@@ -378,17 +390,30 @@ ); | ||
} | ||
const { stateVector, update, guid } = message; | ||
const { stateVector, update: updateStr, guid } = message; | ||
const canWrite = _nullishCoalesce(_optionalChain([this, 'access', _31 => _31.room, 'access', _32 => _32.getSelf, 'call', _33 => _33(), 'optionalAccess', _34 => _34.canWrite]), () => ( true)); | ||
if (guid !== void 0) { | ||
_optionalChain([this, 'access', _35 => _35.subdocHandlers, 'access', _36 => _36.get, 'call', _37 => _37(guid), 'optionalAccess', _38 => _38.handleServerUpdate, 'call', _39 => _39({ | ||
update, | ||
stateVector, | ||
readOnly: !canWrite | ||
})]); | ||
} else { | ||
this.rootDocHandler.handleServerUpdate({ | ||
update, | ||
stateVector, | ||
readOnly: !canWrite | ||
}); | ||
const update = _jsbase64.Base64.toUint8Array(updateStr); | ||
let foundPendingUpdate = false; | ||
const updateId = this.getUniqueUpdateId(update); | ||
this.pending = this.pending.filter((pendingUpdate) => { | ||
if (pendingUpdate === updateId) { | ||
foundPendingUpdate = true; | ||
return false; | ||
} | ||
return true; | ||
}); | ||
if (!foundPendingUpdate) { | ||
if (guid !== void 0) { | ||
_optionalChain([this, 'access', _35 => _35.subdocHandlers, 'access', _36 => _36.get, 'call', _37 => _37(guid), 'optionalAccess', _38 => _38.handleServerUpdate, 'call', _39 => _39({ | ||
update, | ||
stateVector, | ||
readOnly: !canWrite | ||
})]); | ||
} else { | ||
this.rootDocHandler.handleServerUpdate({ | ||
update, | ||
stateVector, | ||
readOnly: !canWrite | ||
}); | ||
} | ||
} | ||
this.emit("status", [this.getStatus()]); | ||
}) | ||
@@ -403,2 +428,3 @@ ); | ||
this.emit("sync", [state]); | ||
this.emit("status", [this.getStatus()]); | ||
}); | ||
@@ -412,2 +438,8 @@ this.rootDoc.on("subdocs", this.handleSubdocs); | ||
} | ||
getStatus() { | ||
if (!this.synced) { | ||
return "loading" /* Loading */; | ||
} | ||
return this.pending.length === 0 ? "synchronized" /* Synchronized */ : "synchronizing" /* Synchronizing */; | ||
} | ||
destroy() { | ||
@@ -414,0 +446,0 @@ this.unsubscribers.forEach((unsub) => unsub()); |
{ | ||
"name": "@liveblocks/yjs", | ||
"version": "2.4.1-test4", | ||
"version": "2.5.0", | ||
"description": "An integration with . Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.", | ||
@@ -36,4 +36,4 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"@liveblocks/client": "2.4.1-test4", | ||
"@liveblocks/core": "2.4.1-test4", | ||
"@liveblocks/client": "2.5.0", | ||
"@liveblocks/core": "2.5.0", | ||
"js-base64": "^3.7.7" | ||
@@ -40,0 +40,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
114163
970
0
+ Added@liveblocks/client@2.5.0(transitive)
+ Added@liveblocks/core@2.5.0(transitive)
- Removed@liveblocks/client@2.4.1-test4(transitive)
- Removed@liveblocks/core@2.4.1-test4(transitive)
Updated@liveblocks/client@2.5.0
Updated@liveblocks/core@2.5.0