Compare commits
11 Commits
v13.0.0-18
...
v13.0.0-22
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6badf98a2 | ||
|
|
d9ee67d2f3 | ||
|
|
791f6c12f0 | ||
|
|
23d019c244 | ||
|
|
c8ca80d15f | ||
|
|
be282c8338 | ||
|
|
829a094c6d | ||
|
|
725273167e | ||
|
|
581264c5e3 | ||
|
|
be537c9f8c | ||
|
|
4028eee39d |
@@ -7,9 +7,9 @@ Y({
|
|||||||
},
|
},
|
||||||
connector: {
|
connector: {
|
||||||
name: 'websockets-client',
|
name: 'websockets-client',
|
||||||
// url: 'http://127.0.0.1:1234',
|
url: 'http://127.0.0.1:1234',
|
||||||
url: 'http://192.168.178.81:1234',
|
|
||||||
room: 'html-editor-example6'
|
room: 'html-editor-example6'
|
||||||
|
// maxBufferLength: 100
|
||||||
},
|
},
|
||||||
share: {
|
share: {
|
||||||
xml: 'XmlFragment()' // y.share.xml is of type Y.Xml with tagname "p"
|
xml: 'XmlFragment()' // y.share.xml is of type Y.Xml with tagname "p"
|
||||||
|
|||||||
21
examples/indexeddb/index.html
Normal file
21
examples/indexeddb/index.html
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="codeMirrorContainer"></div>
|
||||||
|
<script src="../bower_components/codemirror/lib/codemirror.js"></script>
|
||||||
|
<script src="../bower_components/codemirror/mode/javascript/javascript.js"></script>
|
||||||
|
<link rel="stylesheet" href="../bower_components/codemirror/lib/codemirror.css">
|
||||||
|
<style>
|
||||||
|
.CodeMirror {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script type="module" src="./index.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
24
examples/indexeddb/index.js
Normal file
24
examples/indexeddb/index.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/* global Y, CodeMirror */
|
||||||
|
|
||||||
|
// initialize a shared object. This function call returns a promise!
|
||||||
|
Y({
|
||||||
|
db: {
|
||||||
|
name: 'memory'
|
||||||
|
},
|
||||||
|
connector: {
|
||||||
|
name: 'websockets-client',
|
||||||
|
room: 'codemirror-example'
|
||||||
|
},
|
||||||
|
sourceDir: '/bower_components',
|
||||||
|
share: {
|
||||||
|
codemirror: 'Text' // y.share.codemirror is of type Y.Text
|
||||||
|
}
|
||||||
|
}).then(function (y) {
|
||||||
|
window.yCodeMirror = y
|
||||||
|
|
||||||
|
var editor = CodeMirror(document.querySelector('#codeMirrorContainer'), {
|
||||||
|
mode: 'javascript',
|
||||||
|
lineNumbers: true
|
||||||
|
})
|
||||||
|
y.share.codemirror.bindCodeMirror(editor)
|
||||||
|
})
|
||||||
@@ -3,7 +3,7 @@ import Y from '../src/y.js'
|
|||||||
import yArray from '../../y-array/src/y-array.js'
|
import yArray from '../../y-array/src/y-array.js'
|
||||||
import yIndexedDB from '../../y-indexeddb/src/y-indexeddb.js'
|
import yIndexedDB from '../../y-indexeddb/src/y-indexeddb.js'
|
||||||
import yMap from '../../y-map/src/y-map.js'
|
import yMap from '../../y-map/src/y-map.js'
|
||||||
import yText from '../../y-text/src/Text.js'
|
import yText from '../../y-text/src/y-text.js'
|
||||||
import yXml from '../../y-xml/src/y-xml.js'
|
import yXml from '../../y-xml/src/y-xml.js'
|
||||||
import yWebsocketsClient from '../../y-websockets-client/src/y-websockets-client.js'
|
import yWebsocketsClient from '../../y-websockets-client/src/y-websockets-client.js'
|
||||||
|
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "yjs",
|
"name": "yjs",
|
||||||
"version": "13.0.0-17",
|
"version": "13.0.0-22",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "yjs",
|
"name": "yjs",
|
||||||
"version": "13.0.0-18",
|
"version": "13.0.0-22",
|
||||||
"description": "A framework for real-time p2p shared editing on any data",
|
"description": "A framework for real-time p2p shared editing on any data",
|
||||||
"main": "./y.node.js",
|
"main": "./y.node.js",
|
||||||
"browser": "./y.js",
|
"browser": "./y.js",
|
||||||
|
|||||||
@@ -42,6 +42,11 @@ export default function extendConnector (Y/* :any */) {
|
|||||||
if (opts.generateUserId !== false) {
|
if (opts.generateUserId !== false) {
|
||||||
this.setUserId(Y.utils.generateUserId())
|
this.setUserId(Y.utils.generateUserId())
|
||||||
}
|
}
|
||||||
|
if (opts.maxBufferLength == null) {
|
||||||
|
this.maxBufferLength = -1
|
||||||
|
} else {
|
||||||
|
this.maxBufferLength = opts.maxBufferLength
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reconnect () {
|
reconnect () {
|
||||||
@@ -197,14 +202,19 @@ export default function extendConnector (Y/* :any */) {
|
|||||||
encoder.writeVarString(self.opts.room)
|
encoder.writeVarString(self.opts.room)
|
||||||
encoder.writeVarString('update')
|
encoder.writeVarString('update')
|
||||||
let ops = self.broadcastOpBuffer
|
let ops = self.broadcastOpBuffer
|
||||||
self.broadcastOpBuffer = []
|
|
||||||
let length = ops.length
|
let length = ops.length
|
||||||
encoder.writeUint32(length)
|
let encoderPosLen = encoder.pos
|
||||||
for (var i = 0; i < length; i++) {
|
encoder.writeUint32(0)
|
||||||
|
for (var i = 0; i < length && (self.maxBufferLength < 0 || encoder.length < self.maxBufferLength); i++) {
|
||||||
let op = ops[i]
|
let op = ops[i]
|
||||||
Y.Struct[op.struct].binaryEncode(encoder, op)
|
Y.Struct[op.struct].binaryEncode(encoder, op)
|
||||||
}
|
}
|
||||||
|
encoder.setUint32(encoderPosLen, i)
|
||||||
|
self.broadcastOpBuffer = ops.slice(i)
|
||||||
self.broadcast(encoder.createBuffer())
|
self.broadcast(encoder.createBuffer())
|
||||||
|
if (i !== length) {
|
||||||
|
self.whenRemoteResponsive().then(broadcastOperations)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.broadcastOpBuffer.length === 0) {
|
if (this.broadcastOpBuffer.length === 0) {
|
||||||
@@ -215,6 +225,20 @@ export default function extendConnector (Y/* :any */) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Somehow check the responsiveness of the remote clients/server
|
||||||
|
* Default behavior:
|
||||||
|
* Wait 100ms before broadcasting the next batch of operations
|
||||||
|
*
|
||||||
|
* Only used when maxBufferLength is set
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
whenRemoteResponsive () {
|
||||||
|
return new Promise(function (resolve) {
|
||||||
|
setTimeout(resolve, 100)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
You received a raw message, and you know that it is intended for Yjs. Then call this function.
|
You received a raw message, and you know that it is intended for Yjs. Then call this function.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ export class BinaryEncoder {
|
|||||||
this.data = []
|
this.data = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get length () {
|
||||||
|
return this.data.length
|
||||||
|
}
|
||||||
|
|
||||||
get pos () {
|
get pos () {
|
||||||
return this.data.length
|
return this.data.length
|
||||||
}
|
}
|
||||||
|
|||||||
75
src/Utils.js
75
src/Utils.js
@@ -49,6 +49,51 @@ export default function Utils (Y) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Y.utils.getRelativePosition = function (type, offset) {
|
||||||
|
if (type == null) {
|
||||||
|
return null
|
||||||
|
} else {
|
||||||
|
if (type._content.length <= offset) {
|
||||||
|
return ['endof', type._model[0], type._model[1]]
|
||||||
|
} else {
|
||||||
|
return type._content[offset].id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Y.utils.fromRelativePosition = function (y, id) {
|
||||||
|
var offset = 0
|
||||||
|
var op
|
||||||
|
if (id[0] === 'endof') {
|
||||||
|
id = y.db.os.find(id.slice(1)).end
|
||||||
|
op = y.db.os.findNodeWithUpperBound(id).val
|
||||||
|
if (!op.deleted) {
|
||||||
|
offset = op.content != null ? op.content.length : 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
op = y.db.os.findNodeWithUpperBound(id).val
|
||||||
|
if (!op.deleted) {
|
||||||
|
offset = id[1] - op.id[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var type = y.db.getType(op.parent)
|
||||||
|
if (type == null || y.db.os.find(op.parent).deleted) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
while (op.left != null) {
|
||||||
|
op = y.db.os.findNodeWithUpperBound(op.left).val
|
||||||
|
if (!op.deleted) {
|
||||||
|
offset += op.content != null ? op.content.length : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
type: type,
|
||||||
|
offset: offset
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class NamedEventHandler {
|
class NamedEventHandler {
|
||||||
constructor () {
|
constructor () {
|
||||||
this._eventListener = {}
|
this._eventListener = {}
|
||||||
@@ -857,4 +902,34 @@ export default function Utils (Y) {
|
|||||||
}
|
}
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Y.utils.writeObjectToYMap = function writeObjectToYMap (object, type) {
|
||||||
|
for (var key in object) {
|
||||||
|
var val = object[key]
|
||||||
|
if (Array.isArray(val)) {
|
||||||
|
type.set(key, Y.Array)
|
||||||
|
Y.utils.writeArrayToYArray(val, type.get(key))
|
||||||
|
} else if (typeof val === 'object') {
|
||||||
|
type.set(key, Y.Map)
|
||||||
|
Y.utils.writeObjectToYMap(val, type.get(key))
|
||||||
|
} else {
|
||||||
|
type.set(key, val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Y.utils.writeArrayToYArray = function writeArrayToYArray (array, type) {
|
||||||
|
for (var i = array.length - 1; i >= 0; i--) {
|
||||||
|
var val = array[i]
|
||||||
|
if (Array.isArray(val)) {
|
||||||
|
type.insert(0, [Y.Array])
|
||||||
|
Y.utils.writeArrayToYArray(val, type.get(0))
|
||||||
|
} else if (typeof val === 'object') {
|
||||||
|
type.insert(0, [Y.Map])
|
||||||
|
Y.utils.writeObjectToYMap(val, type.get(0))
|
||||||
|
} else {
|
||||||
|
type.insert(0, [val])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
y.node.js.map
Normal file
1
y.node.js.map
Normal file
File diff suppressed because one or more lines are too long
1
y.test.js.map
Normal file
1
y.test.js.map
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user