Compare commits

..

5 Commits

Author SHA1 Message Date
Kevin Jahns
d6c1a11a9b v13.0.0-50 -- distribution files 2018-01-30 20:13:17 -08:00
Kevin Jahns
4b84541d76 13.0.0-50 2018-01-30 20:12:58 -08:00
Kevin Jahns
a3ab42c157 implemnt mutual exclude pattern directly in Persistence.js 2018-01-30 20:11:59 -08:00
Kevin Jahns
bbd3317d62 13.0.0-49 2018-01-30 15:53:33 -08:00
Kevin Jahns
5d3922cb64 fix undo-redo 2018-01-30 15:52:36 -08:00
15 changed files with 1033 additions and 95 deletions

914
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{ {
"name": "yjs", "name": "yjs",
"version": "13.0.0-48", "version": "13.0.0-50",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@@ -1039,6 +1039,7 @@
"requires": { "requires": {
"anymatch": "1.3.0", "anymatch": "1.3.0",
"async-each": "1.0.1", "async-each": "1.0.1",
"fsevents": "1.1.3",
"glob-parent": "2.0.0", "glob-parent": "2.0.0",
"inherits": "2.0.3", "inherits": "2.0.3",
"is-binary-path": "1.0.1", "is-binary-path": "1.0.1",
@@ -1990,6 +1991,910 @@
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
"dev": true "dev": true
}, },
"fsevents": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.1.3.tgz",
"integrity": "sha512-WIr7iDkdmdbxu/Gh6eKEZJL6KPE74/5MEsf2whTOFNxbIoIixogroLdKYqB6FDav4Wavh/lZdzzd3b2KxIXC5Q==",
"dev": true,
"optional": true,
"requires": {
"nan": "2.8.0",
"node-pre-gyp": "0.6.39"
},
"dependencies": {
"abbrev": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
},
"ajv": {
"version": "4.11.8",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"co": "4.6.0",
"json-stable-stringify": "1.0.1"
}
},
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"dev": true
},
"aproba": {
"version": "1.1.1",
"bundled": true,
"dev": true,
"optional": true
},
"are-we-there-yet": {
"version": "1.1.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"delegates": "1.0.0",
"readable-stream": "2.2.9"
}
},
"asn1": {
"version": "0.2.3",
"bundled": true,
"dev": true,
"optional": true
},
"assert-plus": {
"version": "0.2.0",
"bundled": true,
"dev": true,
"optional": true
},
"asynckit": {
"version": "0.4.0",
"bundled": true,
"dev": true,
"optional": true
},
"aws-sign2": {
"version": "0.6.0",
"bundled": true,
"dev": true,
"optional": true
},
"aws4": {
"version": "1.6.0",
"bundled": true,
"dev": true,
"optional": true
},
"balanced-match": {
"version": "0.4.2",
"bundled": true,
"dev": true
},
"bcrypt-pbkdf": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"tweetnacl": "0.14.5"
}
},
"block-stream": {
"version": "0.0.9",
"bundled": true,
"dev": true,
"requires": {
"inherits": "2.0.3"
}
},
"boom": {
"version": "2.10.1",
"bundled": true,
"dev": true,
"requires": {
"hoek": "2.16.3"
}
},
"brace-expansion": {
"version": "1.1.7",
"bundled": true,
"dev": true,
"requires": {
"balanced-match": "0.4.2",
"concat-map": "0.0.1"
}
},
"buffer-shims": {
"version": "1.0.0",
"bundled": true,
"dev": true
},
"caseless": {
"version": "0.12.0",
"bundled": true,
"dev": true,
"optional": true
},
"co": {
"version": "4.6.0",
"bundled": true,
"dev": true,
"optional": true
},
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true
},
"combined-stream": {
"version": "1.0.5",
"bundled": true,
"dev": true,
"requires": {
"delayed-stream": "1.0.0"
}
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true
},
"core-util-is": {
"version": "1.0.2",
"bundled": true,
"dev": true
},
"cryptiles": {
"version": "2.0.5",
"bundled": true,
"dev": true,
"requires": {
"boom": "2.10.1"
}
},
"dashdash": {
"version": "1.14.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"assert-plus": "1.0.0"
},
"dependencies": {
"assert-plus": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
}
}
},
"debug": {
"version": "2.6.8",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"ms": "2.0.0"
}
},
"deep-extend": {
"version": "0.4.2",
"bundled": true,
"dev": true,
"optional": true
},
"delayed-stream": {
"version": "1.0.0",
"bundled": true,
"dev": true
},
"delegates": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
},
"detect-libc": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true
},
"ecc-jsbn": {
"version": "0.1.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"jsbn": "0.1.1"
}
},
"extend": {
"version": "3.0.1",
"bundled": true,
"dev": true,
"optional": true
},
"extsprintf": {
"version": "1.0.2",
"bundled": true,
"dev": true
},
"forever-agent": {
"version": "0.6.1",
"bundled": true,
"dev": true,
"optional": true
},
"form-data": {
"version": "2.1.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"asynckit": "0.4.0",
"combined-stream": "1.0.5",
"mime-types": "2.1.15"
}
},
"fs.realpath": {
"version": "1.0.0",
"bundled": true,
"dev": true
},
"fstream": {
"version": "1.0.11",
"bundled": true,
"dev": true,
"requires": {
"graceful-fs": "4.1.11",
"inherits": "2.0.3",
"mkdirp": "0.5.1",
"rimraf": "2.6.1"
}
},
"fstream-ignore": {
"version": "1.0.5",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"fstream": "1.0.11",
"inherits": "2.0.3",
"minimatch": "3.0.4"
}
},
"gauge": {
"version": "2.7.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"aproba": "1.1.1",
"console-control-strings": "1.1.0",
"has-unicode": "2.0.1",
"object-assign": "4.1.1",
"signal-exit": "3.0.2",
"string-width": "1.0.2",
"strip-ansi": "3.0.1",
"wide-align": "1.1.2"
}
},
"getpass": {
"version": "0.1.7",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"assert-plus": "1.0.0"
},
"dependencies": {
"assert-plus": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
}
}
},
"glob": {
"version": "7.1.2",
"bundled": true,
"dev": true,
"requires": {
"fs.realpath": "1.0.0",
"inflight": "1.0.6",
"inherits": "2.0.3",
"minimatch": "3.0.4",
"once": "1.4.0",
"path-is-absolute": "1.0.1"
}
},
"graceful-fs": {
"version": "4.1.11",
"bundled": true,
"dev": true
},
"har-schema": {
"version": "1.0.5",
"bundled": true,
"dev": true,
"optional": true
},
"har-validator": {
"version": "4.2.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"ajv": "4.11.8",
"har-schema": "1.0.5"
}
},
"has-unicode": {
"version": "2.0.1",
"bundled": true,
"dev": true,
"optional": true
},
"hawk": {
"version": "3.1.3",
"bundled": true,
"dev": true,
"requires": {
"boom": "2.10.1",
"cryptiles": "2.0.5",
"hoek": "2.16.3",
"sntp": "1.0.9"
}
},
"hoek": {
"version": "2.16.3",
"bundled": true,
"dev": true
},
"http-signature": {
"version": "1.1.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"assert-plus": "0.2.0",
"jsprim": "1.4.0",
"sshpk": "1.13.0"
}
},
"inflight": {
"version": "1.0.6",
"bundled": true,
"dev": true,
"requires": {
"once": "1.4.0",
"wrappy": "1.0.2"
}
},
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true
},
"ini": {
"version": "1.3.4",
"bundled": true,
"dev": true,
"optional": true
},
"is-fullwidth-code-point": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"requires": {
"number-is-nan": "1.0.1"
}
},
"is-typedarray": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
},
"isarray": {
"version": "1.0.0",
"bundled": true,
"dev": true
},
"isstream": {
"version": "0.1.2",
"bundled": true,
"dev": true,
"optional": true
},
"jodid25519": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"jsbn": "0.1.1"
}
},
"jsbn": {
"version": "0.1.1",
"bundled": true,
"dev": true,
"optional": true
},
"json-schema": {
"version": "0.2.3",
"bundled": true,
"dev": true,
"optional": true
},
"json-stable-stringify": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"jsonify": "0.0.0"
}
},
"json-stringify-safe": {
"version": "5.0.1",
"bundled": true,
"dev": true,
"optional": true
},
"jsonify": {
"version": "0.0.0",
"bundled": true,
"dev": true,
"optional": true
},
"jsprim": {
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"assert-plus": "1.0.0",
"extsprintf": "1.0.2",
"json-schema": "0.2.3",
"verror": "1.3.6"
},
"dependencies": {
"assert-plus": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
}
}
},
"mime-db": {
"version": "1.27.0",
"bundled": true,
"dev": true
},
"mime-types": {
"version": "2.1.15",
"bundled": true,
"dev": true,
"requires": {
"mime-db": "1.27.0"
}
},
"minimatch": {
"version": "3.0.4",
"bundled": true,
"dev": true,
"requires": {
"brace-expansion": "1.1.7"
}
},
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true
},
"mkdirp": {
"version": "0.5.1",
"bundled": true,
"dev": true,
"requires": {
"minimist": "0.0.8"
}
},
"ms": {
"version": "2.0.0",
"bundled": true,
"dev": true,
"optional": true
},
"node-pre-gyp": {
"version": "0.6.39",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"detect-libc": "1.0.2",
"hawk": "3.1.3",
"mkdirp": "0.5.1",
"nopt": "4.0.1",
"npmlog": "4.1.0",
"rc": "1.2.1",
"request": "2.81.0",
"rimraf": "2.6.1",
"semver": "5.3.0",
"tar": "2.2.1",
"tar-pack": "3.4.0"
}
},
"nopt": {
"version": "4.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"abbrev": "1.1.0",
"osenv": "0.1.4"
}
},
"npmlog": {
"version": "4.1.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"are-we-there-yet": "1.1.4",
"console-control-strings": "1.1.0",
"gauge": "2.7.4",
"set-blocking": "2.0.0"
}
},
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true
},
"oauth-sign": {
"version": "0.8.2",
"bundled": true,
"dev": true,
"optional": true
},
"object-assign": {
"version": "4.1.1",
"bundled": true,
"dev": true,
"optional": true
},
"once": {
"version": "1.4.0",
"bundled": true,
"dev": true,
"requires": {
"wrappy": "1.0.2"
}
},
"os-homedir": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true
},
"os-tmpdir": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true
},
"osenv": {
"version": "0.1.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"os-homedir": "1.0.2",
"os-tmpdir": "1.0.2"
}
},
"path-is-absolute": {
"version": "1.0.1",
"bundled": true,
"dev": true
},
"performance-now": {
"version": "0.2.0",
"bundled": true,
"dev": true,
"optional": true
},
"process-nextick-args": {
"version": "1.0.7",
"bundled": true,
"dev": true
},
"punycode": {
"version": "1.4.1",
"bundled": true,
"dev": true,
"optional": true
},
"qs": {
"version": "6.4.0",
"bundled": true,
"dev": true,
"optional": true
},
"rc": {
"version": "1.2.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"deep-extend": "0.4.2",
"ini": "1.3.4",
"minimist": "1.2.0",
"strip-json-comments": "2.0.1"
},
"dependencies": {
"minimist": {
"version": "1.2.0",
"bundled": true,
"dev": true,
"optional": true
}
}
},
"readable-stream": {
"version": "2.2.9",
"bundled": true,
"dev": true,
"requires": {
"buffer-shims": "1.0.0",
"core-util-is": "1.0.2",
"inherits": "2.0.3",
"isarray": "1.0.0",
"process-nextick-args": "1.0.7",
"string_decoder": "1.0.1",
"util-deprecate": "1.0.2"
}
},
"request": {
"version": "2.81.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"aws-sign2": "0.6.0",
"aws4": "1.6.0",
"caseless": "0.12.0",
"combined-stream": "1.0.5",
"extend": "3.0.1",
"forever-agent": "0.6.1",
"form-data": "2.1.4",
"har-validator": "4.2.1",
"hawk": "3.1.3",
"http-signature": "1.1.1",
"is-typedarray": "1.0.0",
"isstream": "0.1.2",
"json-stringify-safe": "5.0.1",
"mime-types": "2.1.15",
"oauth-sign": "0.8.2",
"performance-now": "0.2.0",
"qs": "6.4.0",
"safe-buffer": "5.0.1",
"stringstream": "0.0.5",
"tough-cookie": "2.3.2",
"tunnel-agent": "0.6.0",
"uuid": "3.0.1"
}
},
"rimraf": {
"version": "2.6.1",
"bundled": true,
"dev": true,
"requires": {
"glob": "7.1.2"
}
},
"safe-buffer": {
"version": "5.0.1",
"bundled": true,
"dev": true
},
"semver": {
"version": "5.3.0",
"bundled": true,
"dev": true,
"optional": true
},
"set-blocking": {
"version": "2.0.0",
"bundled": true,
"dev": true,
"optional": true
},
"signal-exit": {
"version": "3.0.2",
"bundled": true,
"dev": true,
"optional": true
},
"sntp": {
"version": "1.0.9",
"bundled": true,
"dev": true,
"requires": {
"hoek": "2.16.3"
}
},
"sshpk": {
"version": "1.13.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"asn1": "0.2.3",
"assert-plus": "1.0.0",
"bcrypt-pbkdf": "1.0.1",
"dashdash": "1.14.1",
"ecc-jsbn": "0.1.1",
"getpass": "0.1.7",
"jodid25519": "1.0.2",
"jsbn": "0.1.1",
"tweetnacl": "0.14.5"
},
"dependencies": {
"assert-plus": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
}
}
},
"string-width": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"requires": {
"code-point-at": "1.1.0",
"is-fullwidth-code-point": "1.0.0",
"strip-ansi": "3.0.1"
}
},
"string_decoder": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"requires": {
"safe-buffer": "5.0.1"
}
},
"stringstream": {
"version": "0.0.5",
"bundled": true,
"dev": true,
"optional": true
},
"strip-ansi": {
"version": "3.0.1",
"bundled": true,
"dev": true,
"requires": {
"ansi-regex": "2.1.1"
}
},
"strip-json-comments": {
"version": "2.0.1",
"bundled": true,
"dev": true,
"optional": true
},
"tar": {
"version": "2.2.1",
"bundled": true,
"dev": true,
"requires": {
"block-stream": "0.0.9",
"fstream": "1.0.11",
"inherits": "2.0.3"
}
},
"tar-pack": {
"version": "3.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"debug": "2.6.8",
"fstream": "1.0.11",
"fstream-ignore": "1.0.5",
"once": "1.4.0",
"readable-stream": "2.2.9",
"rimraf": "2.6.1",
"tar": "2.2.1",
"uid-number": "0.0.6"
}
},
"tough-cookie": {
"version": "2.3.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"punycode": "1.4.1"
}
},
"tunnel-agent": {
"version": "0.6.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "5.0.1"
}
},
"tweetnacl": {
"version": "0.14.5",
"bundled": true,
"dev": true,
"optional": true
},
"uid-number": {
"version": "0.0.6",
"bundled": true,
"dev": true,
"optional": true
},
"util-deprecate": {
"version": "1.0.2",
"bundled": true,
"dev": true
},
"uuid": {
"version": "3.0.1",
"bundled": true,
"dev": true,
"optional": true
},
"verror": {
"version": "1.3.6",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"extsprintf": "1.0.2"
}
},
"wide-align": {
"version": "1.1.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"string-width": "1.0.2"
}
},
"wrappy": {
"version": "1.0.2",
"bundled": true,
"dev": true
}
}
},
"function-bind": { "function-bind": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.0.tgz", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.0.tgz",
@@ -2938,6 +3843,13 @@
"integrity": "sha1-j7+rsKmKJT0xhDMfno3rc3L6xsA=", "integrity": "sha1-j7+rsKmKJT0xhDMfno3rc3L6xsA=",
"dev": true "dev": true
}, },
"nan": {
"version": "2.8.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.8.0.tgz",
"integrity": "sha1-7XFfP+neArV6XmJS2QqWZ14fCFo=",
"dev": true,
"optional": true
},
"natural-compare": { "natural-compare": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",

View File

@@ -1,6 +1,6 @@
{ {
"name": "yjs", "name": "yjs",
"version": "13.0.0-48", "version": "13.0.0-50",
"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",

View File

@@ -17,13 +17,13 @@ export default class AbstractPersistence {
constructor (opts) { constructor (opts) {
this.opts = opts this.opts = opts
this.ys = new Map() this.ys = new Map()
this.mutualExclude = createMutualExclude()
} }
_init (y) { _init (y) {
let cnf = this.ys.get(y) let cnf = this.ys.get(y)
if (cnf === undefined) { if (cnf === undefined) {
cnf = getFreshCnf() cnf = getFreshCnf()
cnf.mutualExclude = createMutualExclude()
this.ys.set(y, cnf) this.ys.set(y, cnf)
return this.init(y).then(() => { return this.init(y).then(() => {
y.on('afterTransaction', (y, transaction) => { y.on('afterTransaction', (y, transaction) => {
@@ -85,7 +85,7 @@ export default class AbstractPersistence {
saveStruct (y, struct) { saveStruct (y, struct) {
let cnf = this.ys.get(y) let cnf = this.ys.get(y)
if (cnf !== undefined) { if (cnf !== undefined) {
this.mutualExclude(function () { cnf.mutualExclude(function () {
struct._toBinary(cnf.buffer) struct._toBinary(cnf.buffer)
cnf.len++ cnf.len++
}) })
@@ -94,19 +94,22 @@ export default class AbstractPersistence {
/* overwrite */ /* overwrite */
retrieve (y, model, updates) { retrieve (y, model, updates) {
this.mutualExclude(function () { let cnf = this.ys.get(y)
y.transact(function () { if (cnf !== undefined) {
if (model != null) { cnf.mutualExclude(function () {
fromBinary(y, new BinaryDecoder(new Uint8Array(model))) y.transact(function () {
} if (model != null) {
if (updates != null) { fromBinary(y, new BinaryDecoder(new Uint8Array(model)))
for (let i = 0; i < updates.length; i++) {
integrateRemoteStructs(y, new BinaryDecoder(new Uint8Array(updates[i])))
} }
} if (updates != null) {
for (let i = 0; i < updates.length; i++) {
integrateRemoteStructs(y, new BinaryDecoder(new Uint8Array(updates[i])))
}
}
})
y.emit('persistenceReady')
}) })
y.emit('persistenceReady') }
})
} }
/* overwrite */ /* overwrite */

View File

@@ -55,14 +55,16 @@ export default class Item {
/** /**
* Copy the effect of struct * Copy the effect of struct
*/ */
_copy () { _copy (undeleteChildren, copyPosition) {
let struct = new this.constructor() let struct = new this.constructor()
struct._origin = this._left if (copyPosition) {
struct._left = this._left struct._origin = this._left
struct._right = this struct._left = this._left
struct._right_origin = this struct._right = this
struct._parent = this._parent struct._right_origin = this
struct._parentSub = this._parentSub struct._parent = this._parent
struct._parentSub = this._parentSub
}
return struct return struct
} }
get _lastId () { get _lastId () {

View File

@@ -6,8 +6,8 @@ export default class ItemJSON extends Item {
super() super()
this._content = null this._content = null
} }
_copy () { _copy (undeleteChildren, copyPosition) {
let struct = super._copy() let struct = super._copy(undeleteChildren, copyPosition)
struct._content = this._content struct._content = this._content
return struct return struct
} }

View File

@@ -6,8 +6,8 @@ export default class ItemString extends Item {
super() super()
this._content = null this._content = null
} }
_copy () { _copy (undeleteChildren, copyPosition) {
let struct = super._copy() let struct = super._copy(undeleteChildren, copyPosition)
struct._content = this._content struct._content = this._content
return struct return struct
} }

View File

@@ -79,15 +79,16 @@ export default class Type extends Item {
type = type._parent type = type._parent
} }
} }
_copy (undeleteChildren) { _copy (undeleteChildren, copyPosition) {
let copy = super._copy() let copy = super._copy(undeleteChildren, copyPosition)
let map = new Map() let map = new Map()
copy._map = map copy._map = map
for (let [key, value] of this._map) { for (let [key, value] of this._map) {
if (undeleteChildren.has(value) || !value.deleted) { if (undeleteChildren.has(value) || !value.deleted) {
let _item = value._copy(undeleteChildren) let _item = value._copy(undeleteChildren, false)
_item._parent = copy _item._parent = copy
map.set(key, value._copy(undeleteChildren)) _item._parentSub = key
map.set(key, _item)
} }
} }
let prevUndeleted = null let prevUndeleted = null
@@ -95,7 +96,7 @@ export default class Type extends Item {
let item = this._start let item = this._start
while (item !== null) { while (item !== null) {
if (undeleteChildren.has(item) || !item.deleted) { if (undeleteChildren.has(item) || !item.deleted) {
let _item = item._copy(undeleteChildren) let _item = item._copy(undeleteChildren, false)
_item._left = prevUndeleted _item._left = prevUndeleted
_item._origin = prevUndeleted _item._origin = prevUndeleted
_item._right = null _item._right = null

View File

@@ -20,8 +20,8 @@ export default class YXmlElement extends YXmlFragment {
this._domFilter = arg2 this._domFilter = arg2
} }
} }
_copy (undeleteChildren) { _copy (undeleteChildren, copyPosition) {
let struct = super._copy(undeleteChildren) let struct = super._copy(undeleteChildren, copyPosition)
struct.nodeName = this.nodeName struct.nodeName = this.nodeName
return struct return struct
} }

View File

@@ -152,18 +152,20 @@ export default class YXmlFragment extends YArray {
attributes.set(key, attrs[key]) attributes.set(key, attrs[key])
} }
} }
let result = this._domFilter(this.nodeName, new Map(attributes)) this._y.transact(() => {
if (result === null) { let result = this._domFilter(this.nodeName, new Map(attributes))
this._delete(this._y) if (result === null) {
} else { this._delete(this._y)
attributes.forEach((value, key) => { } else {
if (!result.has(key)) { attributes.forEach((value, key) => {
this.removeAttribute(key) if (!result.has(key)) {
} this.removeAttribute(key)
}
})
}
this.forEach(xml => {
xml.setDomFilter(f)
}) })
}
this.forEach(xml => {
xml.setDomFilter(f)
}) })
} }
_callObserver (transaction, parentSubs, remote) { _callObserver (transaction, parentSubs, remote) {

View File

@@ -14,6 +14,11 @@ export default class YXmlHook extends YMap {
getHook(hookName).fillType(dom, this) getHook(hookName).fillType(dom, this)
} }
} }
_copy (undeleteChildren, copyPosition) {
const struct = super._copy(undeleteChildren, copyPosition)
struct.hookName = this.hookName
return struct
}
getDom (_document) { getDom (_document) {
_document = _document || document _document = _document || document
if (this._dom === null) { if (this._dom === null) {

View File

@@ -50,7 +50,7 @@ function applyReverseOperation (y, scope, reverseBuffer) {
) )
) { ) {
performedUndo = true performedUndo = true
op = op._copy(undoOp.deletedStructs) op = op._copy(undoOp.deletedStructs, true)
op._integrate(y) op._integrate(y)
} }
} }

8
y.js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

101
y.node.js
View File

@@ -1,7 +1,7 @@
/** /**
* yjs - A framework for real-time p2p shared editing on any data * yjs - A framework for real-time p2p shared editing on any data
* @version v13.0.0-48 * @version v13.0.0-50
* @license MIT * @license MIT
*/ */
@@ -1344,14 +1344,16 @@ class Item {
/** /**
* Copy the effect of struct * Copy the effect of struct
*/ */
_copy () { _copy (undeleteChildren, copyPosition) {
let struct = new this.constructor(); let struct = new this.constructor();
struct._origin = this._left; if (copyPosition) {
struct._left = this._left; struct._origin = this._left;
struct._right = this; struct._left = this._left;
struct._right_origin = this; struct._right = this;
struct._parent = this._parent; struct._right_origin = this;
struct._parentSub = this._parentSub; struct._parent = this._parent;
struct._parentSub = this._parentSub;
}
return struct return struct
} }
get _lastId () { get _lastId () {
@@ -1718,15 +1720,16 @@ class Type extends Item {
type = type._parent; type = type._parent;
} }
} }
_copy (undeleteChildren) { _copy (undeleteChildren, copyPosition) {
let copy = super._copy(); let copy = super._copy(undeleteChildren, copyPosition);
let map = new Map(); let map = new Map();
copy._map = map; copy._map = map;
for (let [key, value] of this._map) { for (let [key, value] of this._map) {
if (undeleteChildren.has(value) || !value.deleted) { if (undeleteChildren.has(value) || !value.deleted) {
let _item = value._copy(undeleteChildren); let _item = value._copy(undeleteChildren, false);
_item._parent = copy; _item._parent = copy;
map.set(key, value._copy(undeleteChildren)); _item._parentSub = key;
map.set(key, _item);
} }
} }
let prevUndeleted = null; let prevUndeleted = null;
@@ -1734,7 +1737,7 @@ class Type extends Item {
let item = this._start; let item = this._start;
while (item !== null) { while (item !== null) {
if (undeleteChildren.has(item) || !item.deleted) { if (undeleteChildren.has(item) || !item.deleted) {
let _item = item._copy(undeleteChildren); let _item = item._copy(undeleteChildren, false);
_item._left = prevUndeleted; _item._left = prevUndeleted;
_item._origin = prevUndeleted; _item._origin = prevUndeleted;
_item._right = null; _item._right = null;
@@ -1814,8 +1817,8 @@ class ItemJSON extends Item {
super(); super();
this._content = null; this._content = null;
} }
_copy () { _copy (undeleteChildren, copyPosition) {
let struct = super._copy(); let struct = super._copy(undeleteChildren, copyPosition);
struct._content = this._content; struct._content = this._content;
return struct return struct
} }
@@ -1876,8 +1879,8 @@ class ItemString extends Item {
super(); super();
this._content = null; this._content = null;
} }
_copy () { _copy (undeleteChildren, copyPosition) {
let struct = super._copy(); let struct = super._copy(undeleteChildren, copyPosition);
struct._content = this._content; struct._content = this._content;
return struct return struct
} }
@@ -2912,18 +2915,20 @@ class YXmlFragment extends YArray {
attributes.set(key, attrs[key]); attributes.set(key, attrs[key]);
} }
} }
let result = this._domFilter(this.nodeName, new Map(attributes)); this._y.transact(() => {
if (result === null) { let result = this._domFilter(this.nodeName, new Map(attributes));
this._delete(this._y); if (result === null) {
} else { this._delete(this._y);
attributes.forEach((value, key) => { } else {
if (!result.has(key)) { attributes.forEach((value, key) => {
this.removeAttribute(key); if (!result.has(key)) {
} this.removeAttribute(key);
}
});
}
this.forEach(xml => {
xml.setDomFilter(f);
}); });
}
this.forEach(xml => {
xml.setDomFilter(f);
}); });
} }
_callObserver (transaction, parentSubs, remote) { _callObserver (transaction, parentSubs, remote) {
@@ -3128,8 +3133,8 @@ class YXmlElement extends YXmlFragment {
this._domFilter = arg2; this._domFilter = arg2;
} }
} }
_copy (undeleteChildren) { _copy (undeleteChildren, copyPosition) {
let struct = super._copy(undeleteChildren); let struct = super._copy(undeleteChildren, copyPosition);
struct.nodeName = this.nodeName; struct.nodeName = this.nodeName;
return struct return struct
} }
@@ -3267,6 +3272,11 @@ class YXmlHook extends YMap {
getHook(hookName).fillType(dom, this); getHook(hookName).fillType(dom, this);
} }
} }
_copy (undeleteChildren, copyPosition) {
const struct = super._copy(undeleteChildren, copyPosition);
struct.hookName = this.hookName;
return struct
}
getDom (_document) { getDom (_document) {
_document = _document || document; _document = _document || document;
if (this._dom === null) { if (this._dom === null) {
@@ -3707,7 +3717,7 @@ function applyReverseOperation (y, scope, reverseBuffer) {
) )
) { ) {
performedUndo = true; performedUndo = true;
op = op._copy(undoOp.deletedStructs); op = op._copy(undoOp.deletedStructs, true);
op._integrate(y); op._integrate(y);
} }
} }
@@ -4655,13 +4665,13 @@ class AbstractPersistence {
constructor (opts) { constructor (opts) {
this.opts = opts; this.opts = opts;
this.ys = new Map(); this.ys = new Map();
this.mutualExclude = createMutualExclude();
} }
_init (y) { _init (y) {
let cnf = this.ys.get(y); let cnf = this.ys.get(y);
if (cnf === undefined) { if (cnf === undefined) {
cnf = getFreshCnf(); cnf = getFreshCnf();
cnf.mutualExclude = createMutualExclude();
this.ys.set(y, cnf); this.ys.set(y, cnf);
return this.init(y).then(() => { return this.init(y).then(() => {
y.on('afterTransaction', (y, transaction) => { y.on('afterTransaction', (y, transaction) => {
@@ -4723,7 +4733,7 @@ class AbstractPersistence {
saveStruct (y, struct) { saveStruct (y, struct) {
let cnf = this.ys.get(y); let cnf = this.ys.get(y);
if (cnf !== undefined) { if (cnf !== undefined) {
this.mutualExclude(function () { cnf.mutualExclude(function () {
struct._toBinary(cnf.buffer); struct._toBinary(cnf.buffer);
cnf.len++; cnf.len++;
}); });
@@ -4732,19 +4742,22 @@ class AbstractPersistence {
/* overwrite */ /* overwrite */
retrieve (y, model, updates) { retrieve (y, model, updates) {
this.mutualExclude(function () { let cnf = this.ys.get(y);
y.transact(function () { if (cnf !== undefined) {
if (model != null) { cnf.mutualExclude(function () {
fromBinary(y, new BinaryDecoder(new Uint8Array(model))); y.transact(function () {
} if (model != null) {
if (updates != null) { fromBinary(y, new BinaryDecoder(new Uint8Array(model)));
for (let i = 0; i < updates.length; i++) {
integrateRemoteStructs(y, new BinaryDecoder(new Uint8Array(updates[i])));
} }
} if (updates != null) {
for (let i = 0; i < updates.length; i++) {
integrateRemoteStructs(y, new BinaryDecoder(new Uint8Array(updates[i])));
}
}
});
y.emit('persistenceReady');
}); });
y.emit('persistenceReady'); }
});
} }
/* overwrite */ /* overwrite */

File diff suppressed because one or more lines are too long