@liveblocks/yjs
Advanced tools
Comparing version 2.14.0 to 2.15.0-debug1
@@ -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,8 @@ // src/doc.ts | ||
var yDocHandler = class extends Observable { | ||
var yDocHandler = (_class2 = class extends Observable { | ||
__init5() {this.unsubscribers = []} | ||
__init6() {this._synced = false} | ||
constructor({ | ||
@@ -220,37 +228,3 @@ doc, | ||
}) { | ||
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; | ||
@@ -266,2 +240,28 @@ this.doc.on("update", this.updateHandler); | ||
} | ||
__init7() {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; | ||
} | ||
}} | ||
__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 +278,8 @@ get synced() { | ||
} | ||
__init9() {this.updateHandler = (update, origin) => { | ||
const isFromLocal = origin instanceof _yindexeddb.IndexeddbPersistence; | ||
if (origin !== "backend" && !isFromLocal) { | ||
this.updateRoomDoc(update); | ||
} | ||
}} | ||
destroy() { | ||
@@ -285,7 +291,7 @@ this.doc.off("update", this.updateHandler); | ||
} | ||
}; | ||
}, _class2); | ||
// src/version.ts | ||
var PKG_NAME = "@liveblocks/yjs"; | ||
var PKG_VERSION = "2.14.0"; | ||
var PKG_VERSION = "2.15.0-debug1"; | ||
var PKG_FORMAT = "cjs"; | ||
@@ -295,74 +301,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; | ||
@@ -447,2 +393,67 @@ this.room = room; | ||
} | ||
__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.emit("status", [this.getStatus()]); | ||
} | ||
}} | ||
__init17() {this.fetchDoc = (vector, guid) => { | ||
this.room.fetchYDoc(vector, guid); | ||
}} | ||
__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 | ||
}); | ||
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(); | ||
} | ||
}} | ||
// The sync'd property is required by some provider implementations | ||
@@ -481,3 +492,3 @@ get synced() { | ||
} | ||
}; | ||
}, _class3); | ||
@@ -484,0 +495,0 @@ |
{ | ||
"name": "@liveblocks/yjs", | ||
"version": "2.14.0", | ||
"version": "2.15.0-debug1", | ||
"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.14.0", | ||
"@liveblocks/core": "2.14.0", | ||
"@liveblocks/client": "2.15.0-debug1", | ||
"@liveblocks/core": "2.15.0-debug1", | ||
"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
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
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
119999
1026
1
+ Added@liveblocks/client@2.15.0-debug1(transitive)
+ Added@liveblocks/core@2.15.0-debug1(transitive)
- Removed@liveblocks/client@2.14.0(transitive)
- Removed@liveblocks/core@2.14.0(transitive)