@liveblocks/yjs
Advanced tools
Comparing version 2.13.3-emails2 to 2.14.0-v2encoding
@@ -39,3 +39,4 @@ import { JsonObject, LsonObject, BaseUserMeta, Json, BaseMetadata, Room, User } from '@liveblocks/client'; | ||
private fetchRoomDoc; | ||
constructor({ doc, isRoot, updateDoc, fetchDoc, }: { | ||
private useV2Updates; | ||
constructor({ doc, isRoot, updateDoc, fetchDoc, useV2Updates, }: { | ||
doc: Y.Doc; | ||
@@ -45,7 +46,9 @@ isRoot: boolean; | ||
fetchDoc: (vector: string, guid?: string) => void; | ||
useV2Updates: boolean; | ||
}); | ||
handleServerUpdate: ({ update, stateVector, readOnly, }: { | ||
handleServerUpdate: ({ update, stateVector, readOnly, v2, }: { | ||
update: Uint8Array; | ||
stateVector: string | null; | ||
readOnly: boolean; | ||
v2?: boolean | undefined; | ||
}) => void; | ||
@@ -62,2 +65,3 @@ syncDoc: () => void; | ||
offlineSupport_experimental?: boolean; | ||
useV2Updates_experimental?: boolean; | ||
}; | ||
@@ -82,2 +86,3 @@ 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> implements IYjsProvider { | ||
private syncDoc; | ||
get useV2Updates(): boolean; | ||
get synced(): boolean; | ||
@@ -84,0 +89,0 @@ getStatus(): YjsSyncStatus; |
@@ -1,2 +0,2 @@ | ||
"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 | ||
"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; } var _class; var _class2; var _class3;// src/index.ts | ||
var _core = require('@liveblocks/core'); | ||
@@ -82,14 +82,17 @@ var _jsbase64 = require('js-base64'); | ||
var Y_PRESENCE_ID_KEY = "__yjs_clientid"; | ||
var Awareness = class extends Observable { | ||
var Awareness = (_class = class extends Observable { | ||
__init() {this.states = /* @__PURE__ */ new Map()} | ||
// used to map liveblock's ActorId to Yjs ClientID, both unique numbers representing a client | ||
__init2() {this.actorToClientMap = /* @__PURE__ */ new Map()} | ||
// Meta is used to keep track and timeout users who disconnect. Liveblocks provides this for us, so we don't need to | ||
// manage it here. Unfortunately, it's expected to exist by various integrations, so it's an empty map. | ||
__init3() {this.meta = /* @__PURE__ */ new Map()} | ||
// _checkInterval this would hold a timer to remove users, but Liveblock's presence already handles this | ||
// unfortunately it's typed by various integrations | ||
__init4() {this._checkInterval = 0} | ||
constructor(doc, room) { | ||
super(); | ||
this.states = /* @__PURE__ */ new Map(); | ||
// used to map liveblock's ActorId to Yjs ClientID, both unique numbers representing a client | ||
this.actorToClientMap = /* @__PURE__ */ new Map(); | ||
// Meta is used to keep track and timeout users who disconnect. Liveblocks provides this for us, so we don't need to | ||
// manage it here. Unfortunately, it's expected to exist by various integrations, so it's an empty map. | ||
this.meta = /* @__PURE__ */ new Map(); | ||
// _checkInterval this would hold a timer to remove users, but Liveblock's presence already handles this | ||
// unfortunately it's typed by various integrations | ||
this._checkInterval = 0; | ||
super();_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);; | ||
this.doc = doc; | ||
@@ -205,3 +208,3 @@ this.room = room; | ||
} | ||
}; | ||
}, _class); | ||
@@ -212,3 +215,9 @@ // src/doc.ts | ||
var yDocHandler = class extends Observable { | ||
var yDocHandler = (_class2 = class extends Observable { | ||
__init5() {this.unsubscribers = []} | ||
__init6() {this._synced = false} | ||
constructor({ | ||
@@ -218,40 +227,8 @@ doc, | ||
updateDoc, | ||
fetchDoc | ||
fetchDoc, | ||
useV2Updates | ||
}) { | ||
super(); | ||
this.unsubscribers = []; | ||
this._synced = false; | ||
this.handleServerUpdate = ({ | ||
update, | ||
stateVector, | ||
readOnly | ||
}) => { | ||
Y.applyUpdate(this.doc, update, "backend"); | ||
if (stateVector) { | ||
if (!readOnly) { | ||
try { | ||
const localUpdate = Y.encodeStateAsUpdate( | ||
this.doc, | ||
_jsbase64.Base64.toUint8Array(stateVector) | ||
); | ||
this.updateRoomDoc(localUpdate); | ||
} catch (e) { | ||
console.warn(e); | ||
} | ||
} | ||
this.synced = true; | ||
} | ||
}; | ||
this.syncDoc = () => { | ||
this.synced = false; | ||
const encodedVector = _jsbase64.Base64.fromUint8Array(Y.encodeStateVector(this.doc)); | ||
this.fetchRoomDoc(encodedVector); | ||
}; | ||
this.updateHandler = (update, origin) => { | ||
const isFromLocal = origin instanceof _yindexeddb.IndexeddbPersistence; | ||
if (origin !== "backend" && !isFromLocal) { | ||
this.updateRoomDoc(update); | ||
} | ||
}; | ||
super();_class2.prototype.__init5.call(this);_class2.prototype.__init6.call(this);_class2.prototype.__init7.call(this);_class2.prototype.__init8.call(this);_class2.prototype.__init9.call(this);; | ||
this.doc = doc; | ||
this.useV2Updates = useV2Updates; | ||
this.doc.on("update", this.updateHandler); | ||
@@ -266,2 +243,31 @@ this.updateRoomDoc = (update) => { | ||
} | ||
__init7() {this.handleServerUpdate = ({ | ||
update, | ||
stateVector, | ||
readOnly, | ||
v2 | ||
}) => { | ||
const applyUpdate2 = v2 ? Y.applyUpdateV2 : Y.applyUpdate; | ||
applyUpdate2(this.doc, update, "backend"); | ||
if (stateVector) { | ||
if (!readOnly) { | ||
try { | ||
const encodeUpdate = this.useV2Updates ? Y.encodeStateAsUpdateV2 : Y.encodeStateAsUpdate; | ||
const localUpdate = encodeUpdate( | ||
this.doc, | ||
_jsbase64.Base64.toUint8Array(stateVector) | ||
); | ||
this.updateRoomDoc(localUpdate); | ||
} catch (e) { | ||
console.warn(e); | ||
} | ||
} | ||
this.synced = true; | ||
} | ||
}} | ||
__init8() {this.syncDoc = () => { | ||
this.synced = false; | ||
const encodedVector = _jsbase64.Base64.fromUint8Array(Y.encodeStateVector(this.doc)); | ||
this.fetchRoomDoc(encodedVector); | ||
}} | ||
// The sync'd property is required by some provider implementations | ||
@@ -278,2 +284,8 @@ get synced() { | ||
} | ||
__init9() {this.updateHandler = (update, origin) => { | ||
const isFromLocal = origin instanceof _yindexeddb.IndexeddbPersistence; | ||
if (origin !== "backend" && !isFromLocal) { | ||
this.updateRoomDoc(update); | ||
} | ||
}} | ||
destroy() { | ||
@@ -285,7 +297,7 @@ this.doc.off("update", this.updateHandler); | ||
} | ||
}; | ||
}, _class2); | ||
// src/version.ts | ||
var PKG_NAME = "@liveblocks/yjs"; | ||
var PKG_VERSION = "2.13.3-emails2"; | ||
var PKG_VERSION = "2.14.0-v2encoding"; | ||
var PKG_FORMAT = "cjs"; | ||
@@ -295,74 +307,14 @@ | ||
_core.detectDupes.call(void 0, PKG_NAME, PKG_VERSION, PKG_FORMAT); | ||
var LiveblocksYjsProvider = class extends Observable { | ||
var LiveblocksYjsProvider = (_class3 = class extends Observable { | ||
__init10() {this.indexeddbProvider = null} | ||
__init11() {this.unsubscribers = []} | ||
__init12() {this.subdocHandlers = /* @__PURE__ */ new Map()} | ||
__init13() {this.pending = []} | ||
constructor(room, doc, options = {}) { | ||
super(); | ||
this.indexeddbProvider = null; | ||
this.unsubscribers = []; | ||
this.subdocHandlers = /* @__PURE__ */ new Map(); | ||
this.pending = []; | ||
this.handleSubdocs = ({ | ||
loaded, | ||
removed, | ||
added | ||
}) => { | ||
loaded.forEach(this.createSubdocHandler); | ||
if (this.options.autoloadSubdocs) { | ||
for (const subdoc of added) { | ||
if (!this.subdocHandlers.has(subdoc.guid)) { | ||
subdoc.load(); | ||
} | ||
} | ||
} | ||
for (const subdoc of removed) { | ||
if (this.subdocHandlers.has(subdoc.guid)) { | ||
_optionalChain([this, 'access', _17 => _17.subdocHandlers, 'access', _18 => _18.get, 'call', _19 => _19(subdoc.guid), 'optionalAccess', _20 => _20.destroy, 'call', _21 => _21()]); | ||
this.subdocHandlers.delete(subdoc.guid); | ||
} | ||
} | ||
}; | ||
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) { | ||
const updateId = this.getUniqueUpdateId(update); | ||
this.pending.push(updateId); | ||
this.room.updateYDoc(_jsbase64.Base64.fromUint8Array(update), guid); | ||
this.emit("status", [this.getStatus()]); | ||
} | ||
}; | ||
this.fetchDoc = (vector, guid) => { | ||
this.room.fetchYDoc(vector, guid); | ||
}; | ||
this.createSubdocHandler = (subdoc) => { | ||
if (this.subdocHandlers.has(subdoc.guid)) { | ||
_optionalChain([this, 'access', _26 => _26.subdocHandlers, 'access', _27 => _27.get, 'call', _28 => _28(subdoc.guid), 'optionalAccess', _29 => _29.syncDoc, 'call', _30 => _30()]); | ||
return; | ||
} | ||
const handler = new yDocHandler({ | ||
doc: subdoc, | ||
isRoot: false, | ||
updateDoc: this.updateDoc, | ||
fetchDoc: this.fetchDoc | ||
}); | ||
this.subdocHandlers.set(subdoc.guid, handler); | ||
}; | ||
// attempt to load a subdoc of a given guid | ||
this.loadSubdoc = (guid) => { | ||
for (const subdoc of this.rootDoc.subdocs) { | ||
if (subdoc.guid === guid) { | ||
subdoc.load(); | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
this.syncDoc = () => { | ||
this.rootDocHandler.syncDoc(); | ||
for (const [_, handler] of this.subdocHandlers) { | ||
handler.syncDoc(); | ||
} | ||
}; | ||
super();_class3.prototype.__init10.call(this);_class3.prototype.__init11.call(this);_class3.prototype.__init12.call(this);_class3.prototype.__init13.call(this);_class3.prototype.__init14.call(this);_class3.prototype.__init15.call(this);_class3.prototype.__init16.call(this);_class3.prototype.__init17.call(this);_class3.prototype.__init18.call(this);_class3.prototype.__init19.call(this);_class3.prototype.__init20.call(this);; | ||
this.rootDoc = doc; | ||
@@ -375,3 +327,4 @@ this.room = room; | ||
updateDoc: this.updateDoc, | ||
fetchDoc: this.fetchDoc | ||
fetchDoc: this.fetchDoc, | ||
useV2Updates: _nullishCoalesce(this.options.useV2Updates_experimental, () => ( false)) | ||
}); | ||
@@ -396,3 +349,3 @@ room[_core.kInternal].setYjsProvider(this); | ||
} | ||
const { stateVector, update: updateStr, guid } = message; | ||
const { stateVector, update: updateStr, guid, v2 } = message; | ||
const canWrite = _nullishCoalesce(_optionalChain([this, 'access', _31 => _31.room, 'access', _32 => _32.getSelf, 'call', _33 => _33(), 'optionalAccess', _34 => _34.canWrite]), () => ( true)); | ||
@@ -414,3 +367,4 @@ const update = _jsbase64.Base64.toUint8Array(updateStr); | ||
stateVector, | ||
readOnly: !canWrite | ||
readOnly: !canWrite, | ||
v2 | ||
})]); | ||
@@ -421,3 +375,4 @@ } else { | ||
stateVector, | ||
readOnly: !canWrite | ||
readOnly: !canWrite, | ||
v2 | ||
}); | ||
@@ -451,2 +406,75 @@ } | ||
} | ||
__init14() {this.handleSubdocs = ({ | ||
loaded, | ||
removed, | ||
added | ||
}) => { | ||
loaded.forEach(this.createSubdocHandler); | ||
if (this.options.autoloadSubdocs) { | ||
for (const subdoc of added) { | ||
if (!this.subdocHandlers.has(subdoc.guid)) { | ||
subdoc.load(); | ||
} | ||
} | ||
} | ||
for (const subdoc of removed) { | ||
if (this.subdocHandlers.has(subdoc.guid)) { | ||
_optionalChain([this, 'access', _43 => _43.subdocHandlers, 'access', _44 => _44.get, 'call', _45 => _45(subdoc.guid), 'optionalAccess', _46 => _46.destroy, 'call', _47 => _47()]); | ||
this.subdocHandlers.delete(subdoc.guid); | ||
} | ||
} | ||
}} | ||
__init15() {this.getUniqueUpdateId = (update) => { | ||
const clock = _nullishCoalesce(Y2.parseUpdateMeta(update).to.get(this.rootDoc.clientID), () => ( "-1")); | ||
return this.rootDoc.clientID + ":" + clock; | ||
}} | ||
__init16() {this.updateDoc = (update, guid) => { | ||
const canWrite = _nullishCoalesce(_optionalChain([this, 'access', _48 => _48.room, 'access', _49 => _49.getSelf, 'call', _50 => _50(), 'optionalAccess', _51 => _51.canWrite]), () => ( true)); | ||
if (canWrite) { | ||
const updateId = this.getUniqueUpdateId(update); | ||
this.pending.push(updateId); | ||
this.room.updateYDoc( | ||
_jsbase64.Base64.fromUint8Array(update), | ||
guid, | ||
this.useV2Updates | ||
); | ||
this.emit("status", [this.getStatus()]); | ||
} | ||
}} | ||
__init17() {this.fetchDoc = (vector, guid) => { | ||
this.room.fetchYDoc(vector, guid, this.useV2Updates); | ||
}} | ||
__init18() {this.createSubdocHandler = (subdoc) => { | ||
if (this.subdocHandlers.has(subdoc.guid)) { | ||
_optionalChain([this, 'access', _52 => _52.subdocHandlers, 'access', _53 => _53.get, 'call', _54 => _54(subdoc.guid), 'optionalAccess', _55 => _55.syncDoc, 'call', _56 => _56()]); | ||
return; | ||
} | ||
const handler = new yDocHandler({ | ||
doc: subdoc, | ||
isRoot: false, | ||
updateDoc: this.updateDoc, | ||
fetchDoc: this.fetchDoc, | ||
useV2Updates: _nullishCoalesce(this.options.useV2Updates_experimental, () => ( false)) | ||
}); | ||
this.subdocHandlers.set(subdoc.guid, handler); | ||
}} | ||
// attempt to load a subdoc of a given guid | ||
__init19() {this.loadSubdoc = (guid) => { | ||
for (const subdoc of this.rootDoc.subdocs) { | ||
if (subdoc.guid === guid) { | ||
subdoc.load(); | ||
return true; | ||
} | ||
} | ||
return false; | ||
}} | ||
__init20() {this.syncDoc = () => { | ||
this.rootDocHandler.syncDoc(); | ||
for (const [_, handler] of this.subdocHandlers) { | ||
handler.syncDoc(); | ||
} | ||
}} | ||
get useV2Updates() { | ||
return _nullishCoalesce(this.options.useV2Updates_experimental, () => ( false)); | ||
} | ||
// The sync'd property is required by some provider implementations | ||
@@ -485,3 +513,3 @@ get synced() { | ||
} | ||
}; | ||
}, _class3); | ||
@@ -488,0 +516,0 @@ |
{ | ||
"name": "@liveblocks/yjs", | ||
"version": "2.13.3-emails2", | ||
"version": "2.14.0-v2encoding", | ||
"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.13.3-emails2", | ||
"@liveblocks/core": "2.13.3-emails2", | ||
"@liveblocks/client": "2.14.0-v2encoding", | ||
"@liveblocks/core": "2.14.0-v2encoding", | ||
"js-base64": "^3.7.7", | ||
@@ -40,0 +40,0 @@ "y-indexeddb": "^9.0.12" |
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
123857
1064
+ Added@liveblocks/client@2.14.0-v2encoding(transitive)
+ Added@liveblocks/core@2.14.0-v2encoding(transitive)
- Removed@liveblocks/client@2.13.3-emails2(transitive)
- Removed@liveblocks/core@2.13.3-emails2(transitive)