@cocreate/crdt
Advanced tools
Comparing version 1.22.4 to 1.23.0
{ | ||
"name": "@cocreate/crdt", | ||
"version": "1.22.4", | ||
"version": "1.23.0", | ||
"description": "CoCreate crdt", | ||
@@ -43,7 +43,7 @@ "author": "CoCreate LLC", | ||
"dependencies": { | ||
"@cocreate/crud-client": "^1.28.3", | ||
"@cocreate/local-storage": "^1.10.4", | ||
"@cocreate/message-client": "^1.8.2", | ||
"@cocreate/utils": "^1.25.2" | ||
"@cocreate/crud-client": "^1.28.4", | ||
"@cocreate/local-storage": "^1.10.5", | ||
"@cocreate/message-client": "^1.8.3", | ||
"@cocreate/utils": "^1.25.3" | ||
} | ||
} |
@@ -30,3 +30,3 @@ /******************************************************************************** | ||
const docs = new Map(); | ||
const clientId = crud.socket.clientId || uuid.generate(12); | ||
const frameId = crud.socket.frameId || uuid.generate(12); | ||
const checkedDb = new Map(); | ||
@@ -39,3 +39,3 @@ const isInit = new Map(); | ||
data.start = 0; | ||
data['clientId'] = clientId; | ||
data['frameId'] = frameId; | ||
localChange(data); | ||
@@ -73,3 +73,4 @@ }); | ||
value: docName | ||
}] | ||
}], | ||
limit: 1 | ||
} | ||
@@ -85,9 +86,7 @@ } | ||
} | ||
} | ||
else if (!doc.has('text')) { | ||
} else if (!doc.has('text')) { | ||
await generateText(data, false); | ||
} | ||
return doc; | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
console.log('Invalid param', e); | ||
@@ -108,13 +107,14 @@ } | ||
for (let change of changeLog) { | ||
if (change || change !== null) { | ||
if (change) { | ||
string = string.customSplice(change.start, change.length, change.value); | ||
} | ||
} | ||
if (string === '' && data.read !== 'false') { | ||
string = await checkDb(data, flag); | ||
string = await checkDb(data, flag) || '' | ||
} | ||
doc.set('text', string); | ||
return; | ||
} | ||
catch (e) { | ||
return string; | ||
} catch (e) { | ||
console.error(e); | ||
@@ -136,2 +136,3 @@ } | ||
} | ||
if (string && typeof string !== 'string') | ||
@@ -142,6 +143,7 @@ string = "" | ||
data.start = 0; | ||
data.clientId = clientId; | ||
data.frameId = frameId; | ||
insertChange(data); | ||
} | ||
return string || ''; | ||
return string; | ||
} | ||
@@ -167,3 +169,3 @@ | ||
length: data.length || 0, | ||
clientId: data.clientId || clientId, | ||
frameId: data.frameId || frameId, | ||
user_id: data.user_id || localStorage.getItem("user_id"), | ||
@@ -216,13 +218,12 @@ type | ||
if (!data.clientId) { | ||
if (!data.frameId) { | ||
data['datetime'] = change.datetime; | ||
data['clientId'] = change.clientId; | ||
data['frameId'] = change.frameId; | ||
broadcastChange(data); | ||
localChange(data, string); | ||
} | ||
else | ||
} else | ||
localChange(data, string); | ||
if (data.clientId == clientId && data.save != "false") | ||
if (data.frameId == frameId && data.save != "false") | ||
persistChange(data); | ||
@@ -233,3 +234,2 @@ } | ||
message.send({ | ||
room: "", | ||
broadcastSender: false, | ||
@@ -273,2 +273,3 @@ broadcastBrowser: true, | ||
broadcastSender: data.broadcastSender, | ||
broadcastBrowser: false, | ||
metadata: 'crdt-change' | ||
@@ -286,3 +287,3 @@ } | ||
if (doc) { | ||
if (data.clientId !== clientId) { | ||
if (data.frameId !== frameId) { | ||
insertChange(data); | ||
@@ -297,2 +298,4 @@ } | ||
function sync(data) { | ||
if (data.frameId === frameId) | ||
return | ||
if (data.array.includes('crdt-transactions')) { | ||
@@ -304,2 +307,9 @@ if (data.object && data.object[0]) { | ||
if (doc && Data.crud) { | ||
// let text = doc.get('text') | ||
// if (!text && text !== '') { | ||
// setTimeout(function () { | ||
// console.log("text empty timout set"); | ||
// sync(data) | ||
// }, 1000); // Delayed action after 2 seconds | ||
// } else { | ||
Data.crud.value = Data.text | ||
@@ -314,2 +324,3 @@ Data.crud.start = 0 | ||
console.log('crdtSync') | ||
// } | ||
} | ||
@@ -334,8 +345,6 @@ } | ||
return value; | ||
} | ||
else { | ||
} else { | ||
console.log('undefined') | ||
} | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
console.error(e); | ||
@@ -371,4 +380,3 @@ return ""; | ||
} | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
console.error(e); | ||
@@ -427,5 +435,5 @@ } | ||
data = { ...data, ...change }; | ||
delete data.clientId | ||
delete data.frameId | ||
delete data.datetime | ||
delete change.clientId | ||
delete change.frameId | ||
delete change.datetime | ||
@@ -443,3 +451,3 @@ return { data, change } | ||
let change = Object.assign({}, changeLog[index]); | ||
if (change && change.clientId == clientId) { | ||
if (change && change.frameId == frameId) { | ||
let log = undoLog.get(index) | ||
@@ -497,4 +505,3 @@ if (!log) { | ||
return { ...data, ...string } | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
console.error(e); | ||
@@ -501,0 +508,0 @@ } |
Sorry, the diff of this file is too big to display
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
159291
578