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

@cocreate/crdt

Package Overview
Dependencies
Maintainers
1
Versions
265
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cocreate/crdt - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

src/archive/core.1.js

7

CHANGELOG.md

@@ -0,1 +1,8 @@

## [1.2.2](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.2.1...v1.2.2) (2021-08-02)
### Bug Fixes
* refactor updateSelection ([6ee2fb0](https://github.com/CoCreate-app/CoCreate-crdt/commit/6ee2fb072a24cfedd8b69ea4d3afd83419776f29))
## [1.2.1](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.2.0...v1.2.1) (2021-08-02)

@@ -2,0 +9,0 @@

2

package.json
{
"name": "@cocreate/crdt",
"version": "1.2.1",
"version": "1.2.2",
"description": "CoCreate crdt",

@@ -5,0 +5,0 @@ "author": "CoCreate LLC",

import * as Y from 'yjs';
import { WebsocketProvider } from 'y-websocket';
import { IndexeddbPersistence } from 'y-indexeddb';
import * as awarenessProtocol from 'y-protocols/awareness.js';
import CoCreateCursors from '@cocreate/cursors';

@@ -15,4 +14,4 @@

let docName = this.generateDocName(info)
let typeName = this.generateTypeName(info)
let docName = this.generateDocName(info);
let typeName = this.generateTypeName(info);

@@ -22,3 +21,3 @@ if (this.docs[docName]) {

this.docs[docName].types.push(typeName);
this._registerUpdateEvent(this.docs[docName], typeName)
this._registerUpdateEvent(this.docs[docName], typeName);
}

@@ -28,9 +27,9 @@ return false;

const crdtDoc = this.doc
const crdtDoc = this.doc;
const url_socket = this.__getSocketUrl();
const shardType = crdtDoc.getText(typeName)
const shardType = crdtDoc.getText(typeName);
var socketProvider = new WebsocketProvider(url_socket, docName, crdtDoc);
const indexeddbProvider = new IndexeddbPersistence(docName, crdtDoc)
const indexeddbProvider = new IndexeddbPersistence(docName, crdtDoc);
indexeddbProvider.on('synced', () => {});

@@ -44,8 +43,8 @@

const f = clientId => {
this.updateSelection(crdtDoc, typeName, shardType, this._cursors, clientId, awareness)
}
event.added.forEach(f)
event.removed.forEach(f)
event.updated.forEach(f)
}
this.updateSelection(crdtDoc, typeName, shardType, this._cursors, clientId, awareness);
};
event.added.forEach(f);
event.removed.forEach(f);
event.updated.forEach(f);
};

@@ -61,4 +60,4 @@ awareness.on('update', this._awarenessListener);

indexeddb: indexeddbProvider
}
this._registerUpdateEvent(this.docs[docName], typeName)
};
this._registerUpdateEvent(this.docs[docName], typeName);

@@ -69,3 +68,2 @@ return true;

__getSocketUrl() {
console.log("get_socket url")
let w_location = window.location || window.parent.location;

@@ -96,3 +94,3 @@ let w_protocol = w_location.protocol;

const crdtDoc = docName.doc;
const shardType = crdtDoc.getText(typeName)
const shardType = crdtDoc.getText(typeName);
let self = this;

@@ -102,3 +100,3 @@

self._crdtUpdateEvent(event, typeName);
})
});
}

@@ -115,3 +113,3 @@

detail: {eventDelta,...info},
})
});

@@ -127,6 +125,6 @@ window.dispatchEvent(update_event);

if (info.start != null && info.end != null){
var anchor = Y.createRelativePositionFromTypeIndex(type, info.start)
var head = Y.createRelativePositionFromTypeIndex(type, info.end)
var anchor = Y.createRelativePositionFromTypeIndex(type, info.start);
var head = Y.createRelativePositionFromTypeIndex(type, info.end);
this.docs[docName].socket.awareness.setLocalStateField('cursor', {anchor, head})
this.docs[docName].socket.awareness.setLocalStateField('cursor', {anchor, head});
}

@@ -143,9 +141,9 @@ else {

const m = cursors.get(clientId)
const m = cursors.get(clientId);
if (m !== undefined) {
m.caret.clear()
m.caret.clear();
if (m.sel !== null) {
m.sel.clear()
m.sel.clear();
}
cursors.delete(clientId)
cursors.delete(clientId);
}

@@ -156,16 +154,16 @@

if (aw === undefined) {
CoCreateCursors.removeCursor(clientId)
return
CoCreateCursors.removeCursor(clientId);
return;
}
const user = aw.user || {}
const user = aw.user || {};
if (user.color == null) {
user.color = '#ffa500'
user.color = '#ffa500';
}
if (user.name == null) {
user.name = `User: ${clientId}`
user.name = `User: ${clientId}`;
}
const cursor = aw.cursor
const cursor = aw.cursor;
if (cursor == null || cursor.anchor == null || cursor.head == null) {
CoCreateCursors.removeCursor(clientId)
return
CoCreateCursors.removeCursor(clientId);
return;
}

@@ -175,30 +173,20 @@ // const start = cursor.anchor.item.clock;

const anchor = Y.createAbsolutePositionFromRelativePosition(Y.createRelativePositionFromJSON(cursor.anchor), y)
const head = Y.createAbsolutePositionFromRelativePosition(Y.createRelativePositionFromJSON(cursor.head), y)
const anchor = Y.createAbsolutePositionFromRelativePosition(Y.createRelativePositionFromJSON(cursor.anchor), y);
const head = Y.createAbsolutePositionFromRelativePosition(Y.createRelativePositionFromJSON(cursor.head), y);
if (anchor !== null && head !== null ) {
let start = anchor.index;
let end = head.index;
let info = this.parseName(cursor.anchor['tname']);
// Todo: pass json to cursors and let cursors query for its elements
let json = {};
let id_mirror = info.document_id + info.name+'--mirror-div';
let selector = '[collection="'+info.collection+'"][document_id="'+info.document_id+'"][name="'+info.name+'"]'
selector += ':not(.codemirror):not(.quill):not(.monaco)';
let elements = document.querySelectorAll(selector);
elements.forEach(function (element, index, array) {
json = {
element: element,
selector: selector,
start: start,
end: end,
clientId: clientId,
user:{
'color':user.color,
'name':user.name
},
}
CoCreateCursors.draw_cursor(json);
});
let selection = {
collection: info.collection,
document_id: info.document_id,
name: info.name,
start: anchor.index,
end: head.index,
clientId: clientId,
user:{
'color':user.color,
'name':user.name
},
};
CoCreateCursors.drawCursors(selection);
}

@@ -221,3 +209,3 @@ }

let data = JSON.parse(atob(id));
let name = {org: data.org, collection: data.collection, document_id: data.document_id}
let name = {org: data.org, collection: data.collection, document_id: data.document_id};
return {

@@ -228,3 +216,3 @@ id: btoa(JSON.stringify(name)),

name: data.name
}
};
}

@@ -243,2 +231,2 @@

export default CoCreateCrdtInit;
export default CoCreateCrdtInit;
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