Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@liveblocks/yjs

Package Overview
Dependencies
Maintainers
6
Versions
212
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@liveblocks/yjs - npm Package Compare versions

Comparing version 1.1.1-dual1 to 1.1.1-dual2

241

dist/index.js

@@ -1,2 +0,239 @@

"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; } }var g=Object.defineProperty;var m=Object.getOwnPropertySymbols;var _=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var b=(n,s,e)=>s in n?g(n,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[s]=e,i=(n,s)=>{for(var e in s||(s={}))_.call(s,e)&&b(n,e,s[e]);if(m)for(var e of m(s))j.call(s,e)&&b(n,e,s[e]);return n};var _jsbase64 = require('js-base64');var p=()=>new Map;var y=(n,s,e)=>{let t=n.get(s);return t===void 0&&n.set(s,t=e()),t};var x=()=>new Set;var v=Array.from;var D=Array.isArray;var a=class{constructor(){this._observers=p()}on(s,e){y(this._observers,s,x).add(e)}once(s,e){let t=(...o)=>{this.off(s,t),e(...o)};this.on(s,t)}off(s,e){let t=this._observers.get(s);t!==void 0&&(t.delete(e),t.size===0&&this._observers.delete(s))}emit(s,e){return v((this._observers.get(s)||p()).values()).forEach(t=>t(...e))}destroy(){this._observers=p()}};var _yjs = require('yjs'); var u = _interopRequireWildcard(_yjs);var d="__yjs",h= exports.Awareness =class extends a{constructor(e,t){super();this.states=new Map;this.meta=new Map;this._checkInterval=0;this.doc=e,this.room=t,this.clientID=e.clientID,this.othersUnsub=this.room.events.others.subscribe(({event:o})=>{o.type==="leave"&&this.emit("change",[{added:[],updated:[],removed:[o.user.connectionId]},"local"]),o.type==="enter"&&this.emit("change",[{added:[o.user.connectionId],updated:[],removed:[]},"local"]),o.type==="update"&&this.emit("change",[{added:[],updated:[o.user.connectionId],removed:[]},"local"])})}destroy(){this.emit("destroy",[this]),this.othersUnsub(),this.setLocalState(null),super.destroy()}getLocalState(){let e=this.room.getPresence();return Object.keys(e).length===0||typeof e[d]=="undefined"?null:e[d]}setLocalState(e){var o;let t=(o=this.room.getSelf())==null?void 0:o.presence[d];this.room.updatePresence({__yjs:i(i({},t||{}),e||{})})}setLocalStateField(e,t){var c;let o=(c=this.room.getSelf())==null?void 0:c.presence[d],r={[e]:t};this.room.updatePresence({__yjs:i(i({},o||{}),r)})}getStates(){return this.room.getOthers().reduce((o,r)=>(r.connectionId&&o.set(r.connectionId,r.presence[d]||{}),o),new Map)}},f= exports.default =class extends a{constructor(e,t){var r;super();this.unsubscribers=[];this._synced=!1;this.syncDoc=()=>{var t;this.synced=!1,this.doc.clientID=((t=this.room.getSelf())==null?void 0:t.connectionId)||this.doc.clientID,this.awareness.clientID=this.doc.clientID;let e=_jsbase64.Base64.fromUint8Array(u.encodeStateVector(this.doc));this.room.fetchYDoc(e)};this.updateHandler=(e,t)=>{if(t!=="backend"){let o=_jsbase64.Base64.fromUint8Array(e);this.room.updateYDoc(o)}};this.doc=t,this.room=e;let o=(r=this.room.getSelf())==null?void 0:r.connectionId;o&&(this.doc.clientID=o),this.awareness=new h(this.doc,this.room),this.doc.on("update",this.updateHandler),this.unsubscribers.push(this.room.events.status.subscribe(c=>{c==="connected"&&this.syncDoc()})),this.unsubscribers.push(this.room.events.ydoc.subscribe(c=>{u.applyUpdate(this.doc,_jsbase64.Base64.toUint8Array(c),"backend"),this.synced=!0})),this.syncDoc()}get synced(){return this._synced}set synced(e){this._synced!==e&&(this._synced=e,this.emit("synced",[e]),this.emit("sync",[e]))}destroy(){this.doc.off("update",this.updateHandler),this.unsubscribers.forEach(e=>e()),this.awareness.destroy()}disconnect(){}connect(){}};exports.Awareness = h; exports.default = f;
//# sourceMappingURL=index.js.map
"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; } }var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
// src/index.ts
var _jsbase64 = require('js-base64');
// ../../node_modules/lib0/map.js
var create = () => /* @__PURE__ */ new Map();
var setIfUndefined = (map, key, createT) => {
let set = map.get(key);
if (set === void 0) {
map.set(key, set = createT());
}
return set;
};
// ../../node_modules/lib0/set.js
var create2 = () => /* @__PURE__ */ new Set();
// ../../node_modules/lib0/array.js
var from = Array.from;
var isArray = Array.isArray;
// ../../node_modules/lib0/observable.js
var Observable = class {
constructor() {
this._observers = create();
}
/**
* @param {N} name
* @param {function} f
*/
on(name, f) {
setIfUndefined(this._observers, name, create2).add(f);
}
/**
* @param {N} name
* @param {function} f
*/
once(name, f) {
const _f = (...args) => {
this.off(name, _f);
f(...args);
};
this.on(name, _f);
}
/**
* @param {N} name
* @param {function} f
*/
off(name, f) {
const observers = this._observers.get(name);
if (observers !== void 0) {
observers.delete(f);
if (observers.size === 0) {
this._observers.delete(name);
}
}
}
/**
* Emit a named event. All registered event listeners that listen to the
* specified name will receive the event.
*
* @todo This should catch exceptions
*
* @param {N} name The event name.
* @param {Array<any>} args The arguments that are applied to the event listener.
*/
emit(name, args) {
return from((this._observers.get(name) || create()).values()).forEach((f) => f(...args));
}
destroy() {
this._observers = create();
}
};
// src/index.ts
var _yjs = require('yjs'); var Y = _interopRequireWildcard(_yjs);
var Y_PRESENCE_KEY = "__yjs";
var Awareness = class extends Observable {
constructor(doc, room) {
super();
this.states = /* @__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;
this.doc = doc;
this.room = room;
this.clientID = doc.clientID;
this.othersUnsub = this.room.events.others.subscribe(({ event }) => {
if (event.type === "leave") {
this.emit("change", [
{ added: [], updated: [], removed: [event.user.connectionId] },
"local"
]);
}
if (event.type === "enter") {
this.emit("change", [
{ added: [event.user.connectionId], updated: [], removed: [] },
"local"
]);
}
if (event.type === "update") {
this.emit("change", [
{ added: [], updated: [event.user.connectionId], removed: [] },
"local"
]);
}
});
}
destroy() {
this.emit("destroy", [this]);
this.othersUnsub();
this.setLocalState(null);
super.destroy();
}
getLocalState() {
const presence = this.room.getPresence();
if (Object.keys(presence).length === 0 || typeof presence[Y_PRESENCE_KEY] === "undefined") {
return null;
}
return presence[Y_PRESENCE_KEY];
}
setLocalState(state) {
var _a;
const presence = (_a = this.room.getSelf()) == null ? void 0 : _a.presence[Y_PRESENCE_KEY];
this.room.updatePresence({
__yjs: __spreadValues(__spreadValues({}, presence || {}), state || {})
});
}
setLocalStateField(field, value) {
var _a;
const presence = (_a = this.room.getSelf()) == null ? void 0 : _a.presence[Y_PRESENCE_KEY];
const update = { [field]: value };
this.room.updatePresence({
__yjs: __spreadValues(__spreadValues({}, presence || {}), update)
});
}
// Translate liveblocks presence to yjs awareness
getStates() {
const others = this.room.getOthers();
const states = others.reduce((acc, currentValue) => {
if (currentValue.connectionId) {
acc.set(
currentValue.connectionId,
currentValue.presence[Y_PRESENCE_KEY] || {}
);
}
return acc;
}, /* @__PURE__ */ new Map());
return states;
}
};
var LiveblocksProvider = class extends Observable {
constructor(room, doc) {
var _a;
super();
this.unsubscribers = [];
this._synced = false;
this.syncDoc = () => {
var _a;
this.synced = false;
this.doc.clientID = ((_a = this.room.getSelf()) == null ? void 0 : _a.connectionId) || this.doc.clientID;
this.awareness.clientID = this.doc.clientID;
const encodedVector = _jsbase64.Base64.fromUint8Array(Y.encodeStateVector(this.doc));
this.room.fetchYDoc(encodedVector);
};
this.updateHandler = (update, origin) => {
if (origin !== "backend") {
const encodedUpdate = _jsbase64.Base64.fromUint8Array(update);
this.room.updateYDoc(encodedUpdate);
}
};
this.doc = doc;
this.room = room;
const connectionId = (_a = this.room.getSelf()) == null ? void 0 : _a.connectionId;
if (connectionId) {
this.doc.clientID = connectionId;
}
this.awareness = new Awareness(this.doc, this.room);
this.doc.on("update", this.updateHandler);
this.unsubscribers.push(
this.room.events.status.subscribe((status) => {
if (status === "connected") {
this.syncDoc();
}
})
);
this.unsubscribers.push(
this.room.events.ydoc.subscribe((update) => {
Y.applyUpdate(this.doc, _jsbase64.Base64.toUint8Array(update), "backend");
this.synced = true;
})
);
this.syncDoc();
}
// The sync'd property is required by some provider implementations
get synced() {
return this._synced;
}
set synced(state) {
if (this._synced !== state) {
this._synced = state;
this.emit("synced", [state]);
this.emit("sync", [state]);
}
}
destroy() {
this.doc.off("update", this.updateHandler);
this.unsubscribers.forEach((unsub) => unsub());
this.awareness.destroy();
}
// Some provider implementations expect to be able to call connect/disconnect, implement as noop
disconnect() {
}
connect() {
}
};
exports.Awareness = Awareness; exports.default = LiveblocksProvider;

6

package.json
{
"name": "@liveblocks/yjs",
"version": "1.1.1-dual1",
"version": "1.1.1-dual2",
"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": "1.1.1-dual1",
"@liveblocks/core": "1.1.1-dual1",
"@liveblocks/client": "1.1.1-dual2",
"@liveblocks/core": "1.1.1-dual2",
"js-base64": "^3.7.5"

@@ -40,0 +40,0 @@ },

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc