Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fdf2063943 | ||
|
|
e81267d4df | ||
|
|
563c34f81a | ||
|
|
ba713983e3 | ||
|
|
bf2ee3680b | ||
|
|
b812a3dd6c | ||
|
|
7bac783490 | ||
|
|
1508c44f68 | ||
|
|
3dd843372f | ||
|
|
d6be4d9391 | ||
|
|
53f2344017 | ||
|
|
4c46ebfb45 | ||
|
|
9d0d63ead7 |
52
README.md
52
README.md
@@ -31,29 +31,29 @@ I'm currently looking for sponsors that allow me to be less dependent on
|
|||||||
contracting work. These awesome backers already fund further development of
|
contracting work. These awesome backers already fund further development of
|
||||||
Yjs:
|
Yjs:
|
||||||
|
|
||||||
[](https://github.com/vwall)
|
[](https://github.com/ifiokjr)
|
||||||
[<img src="https://user-images.githubusercontent.com/5553757/83337333-a7bcb380-a2ba-11ea-837b-e404eb35d318.png"
|
[](https://github.com/burke)
|
||||||
height="60px" />](https://input.com/)
|
[](https://github.com/cben)
|
||||||
[](https://github.com/canadaduane)
|
[](https://github.com/tommoor)
|
||||||
[](https://github.com/ISNIT0)
|
[](https://github.com/michaelemeyers)
|
||||||
[<img src="https://room.sh/img/icons/android-chrome-192x192.png" height="60px" />](https://room.sh/)
|
[](https://github.com/csbenjamin)
|
||||||
|
[](https://github.com/AdventureBeard)
|
||||||
|
[](https://github.com/nimbuswebinc)
|
||||||
[](https://github.com/journeyapps)
|
[](https://github.com/journeyapps)
|
||||||
[](https://github.com/adabru)
|
[](https://github.com/adabru)
|
||||||
[](https://github.com/NathanaelA)
|
[](https://github.com/NathanaelA)
|
||||||
[](https://github.com/gremloon)
|
[<img src="https://room.sh/img/icons/android-chrome-192x192.png" height="60px" />](https://room.sh/)
|
||||||
[](https://github.com/ifiokjr)
|
|
||||||
[](https://github.com/mrfambo)
|
|
||||||
|
|
||||||
Sponsorship also comes with special perks! [](https://github.com/sponsors/dmonad)
|
Sponsorship also comes with special perks! [](https://github.com/sponsors/dmonad)
|
||||||
|
|
||||||
## Who is using Yjs
|
## Who is using Yjs
|
||||||
|
|
||||||
* [Relm](http://www.relm.us/) A collaborative gameworld for teamwork and
|
* [Relm](https://www.relm.us/) A collaborative gameworld for teamwork and
|
||||||
community. :star2:
|
community. :star2:
|
||||||
* [Input](https://input.com/) A collaborative note taking app. :star2:
|
* [Input](https://input.com/) A collaborative note taking app. :star2:
|
||||||
* [Room.sh](https://room.sh/) A meeting application with integrated
|
* [Room.sh](https://room.sh/) A meeting application with integrated
|
||||||
collaborative drawing, editing, and coding tools. :star:
|
collaborative drawing, editing, and coding tools. :star:
|
||||||
* [http://coronavirustechhandbook.com/](https://coronavirustechhandbook.com/)
|
* [https://coronavirustechhandbook.com/](https://coronavirustechhandbook.com/)
|
||||||
A collaborative wiki that is edited by thousands of different people to work
|
A collaborative wiki that is edited by thousands of different people to work
|
||||||
on a rapid and sophisticated response to the coronavirus outbreak and
|
on a rapid and sophisticated response to the coronavirus outbreak and
|
||||||
subsequent impacts. :star:
|
subsequent impacts. :star:
|
||||||
@@ -90,10 +90,10 @@ are implemented in separate modules.
|
|||||||
|
|
||||||
| Name | Cursors | Binding | Demo |
|
| Name | Cursors | Binding | Demo |
|
||||||
|---|:-:|---|---|
|
|---|:-:|---|---|
|
||||||
| [ProseMirror](https://prosemirror.net/) | ✔ | [y-prosemirror](http://github.com/yjs/y-prosemirror) | [demo](https://demos.yjs.dev/prosemirror/prosemirror.html) |
|
| [ProseMirror](https://prosemirror.net/) | ✔ | [y-prosemirror](https://github.com/yjs/y-prosemirror) | [demo](https://demos.yjs.dev/prosemirror/prosemirror.html) |
|
||||||
| [Quill](https://quilljs.com/) | ✔ | [y-quill](http://github.com/yjs/y-quill) | [demo](https://demos.yjs.dev/quill/quill.html) |
|
| [Quill](https://quilljs.com/) | ✔ | [y-quill](https://github.com/yjs/y-quill) | [demo](https://demos.yjs.dev/quill/quill.html) |
|
||||||
| [CodeMirror](https://codemirror.net/) | ✔ | [y-codemirror](http://github.com/yjs/y-codemirror) | [demo](https://demos.yjs.dev/codemirror/codemirror.html) |
|
| [CodeMirror](https://codemirror.net/) | ✔ | [y-codemirror](https://github.com/yjs/y-codemirror) | [demo](https://demos.yjs.dev/codemirror/codemirror.html) |
|
||||||
| [Monaco](https://microsoft.github.io/monaco-editor/) | ✔ | [y-monaco](http://github.com/yjs/y-monaco) | [demo](https://demos.yjs.dev/monaco/monaco.html) |
|
| [Monaco](https://microsoft.github.io/monaco-editor/) | ✔ | [y-monaco](https://github.com/yjs/y-monaco) | [demo](https://demos.yjs.dev/monaco/monaco.html) |
|
||||||
|
|
||||||
### Providers
|
### Providers
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ manage all that for you and are the perfect starting point for your
|
|||||||
collaborative app.
|
collaborative app.
|
||||||
|
|
||||||
<dl>
|
<dl>
|
||||||
<dt><a href="http://github.com/yjs/y-webrtc">y-webrtc</a></dt>
|
<dt><a href="https://github.com/yjs/y-webrtc">y-webrtc</a></dt>
|
||||||
<dd>
|
<dd>
|
||||||
Propagates document updates peer-to-peer using WebRTC. The peers exchange
|
Propagates document updates peer-to-peer using WebRTC. The peers exchange
|
||||||
signaling data over signaling servers. Publically available signaling servers
|
signaling data over signaling servers. Publically available signaling servers
|
||||||
@@ -111,19 +111,19 @@ are available. Communication over the signaling servers can be encrypted by
|
|||||||
providing a shared secret, keeping the connection information and the shared
|
providing a shared secret, keeping the connection information and the shared
|
||||||
document private.
|
document private.
|
||||||
</dd>
|
</dd>
|
||||||
<dt><a href="http://github.com/yjs/y-websocket">y-websocket</a></dt>
|
<dt><a href="https://github.com/yjs/y-websocket">y-websocket</a></dt>
|
||||||
<dd>
|
<dd>
|
||||||
A module that contains a simple websocket backend and a websocket client that
|
A module that contains a simple websocket backend and a websocket client that
|
||||||
connects to that backend. The backend can be extended to persist updates in a
|
connects to that backend. The backend can be extended to persist updates in a
|
||||||
leveldb database.
|
leveldb database.
|
||||||
</dd>
|
</dd>
|
||||||
<dt><a href="http://github.com/yjs/y-indexeddb">y-indexeddb</a></dt>
|
<dt><a href="https://github.com/yjs/y-indexeddb">y-indexeddb</a></dt>
|
||||||
<dd>
|
<dd>
|
||||||
Efficiently persists document updates to the browsers indexeddb database.
|
Efficiently persists document updates to the browsers indexeddb database.
|
||||||
The document is immediately available and only diffs need to be synced through the
|
The document is immediately available and only diffs need to be synced through the
|
||||||
network provider.
|
network provider.
|
||||||
</dd>
|
</dd>
|
||||||
<dt><a href="http://github.com/yjs/y-dat">y-dat</a></dt>
|
<dt><a href="https://github.com/yjs/y-dat">y-dat</a></dt>
|
||||||
<dd>
|
<dd>
|
||||||
[WIP] Write document updates effinciently to the dat network using
|
[WIP] Write document updates effinciently to the dat network using
|
||||||
<a href="https://github.com/kappa-db/multifeed">multifeed</a>. Each client has
|
<a href="https://github.com/kappa-db/multifeed">multifeed</a>. Each client has
|
||||||
@@ -255,6 +255,8 @@ position 0.
|
|||||||
<dd></dd>
|
<dd></dd>
|
||||||
<b><code>get(index:number)</code></b>
|
<b><code>get(index:number)</code></b>
|
||||||
<dd></dd>
|
<dd></dd>
|
||||||
|
<b><code>slice(start:number, end:number):Array<Object|boolean|Array|string|number|Uint8Array|Y.Type></code></b>
|
||||||
|
<dd>Retrieve a range of content</dd>
|
||||||
<b><code>length:number</code></b>
|
<b><code>length:number</code></b>
|
||||||
<dd></dd>
|
<dd></dd>
|
||||||
<b>
|
<b>
|
||||||
@@ -320,6 +322,8 @@ or any of its children.
|
|||||||
<dd></dd>
|
<dd></dd>
|
||||||
<b><code>get(index:number)</code></b>
|
<b><code>get(index:number)</code></b>
|
||||||
<dd></dd>
|
<dd></dd>
|
||||||
|
<b><code>clone():Y.Map</code></b>
|
||||||
|
<dd>Clone this type into a fresh Yjs type.</dd>
|
||||||
<b><code>toJSON():Object<string, Object|boolean|Array|string|number|Uint8Array></code></b>
|
<b><code>toJSON():Object<string, Object|boolean|Array|string|number|Uint8Array></code></b>
|
||||||
<dd>
|
<dd>
|
||||||
Copies the <code>[key,value]</code> pairs of this YMap to a new Object.It
|
Copies the <code>[key,value]</code> pairs of this YMap to a new Object.It
|
||||||
@@ -451,8 +455,12 @@ or any of its children.
|
|||||||
<dd></dd>
|
<dd></dd>
|
||||||
<b><code>get(index:number)</code></b>
|
<b><code>get(index:number)</code></b>
|
||||||
<dd></dd>
|
<dd></dd>
|
||||||
|
<b><code>slice(start:number, end:number):Array<Y.XmlElement|Y.XmlText></code></b>
|
||||||
|
<dd>Retrieve a range of content</dd>
|
||||||
<b><code>length:number</code></b>
|
<b><code>length:number</code></b>
|
||||||
<dd></dd>
|
<dd></dd>
|
||||||
|
<b><code>clone():Y.XmlFragment</code></b>
|
||||||
|
<dd>Clone this type into a fresh Yjs type.</dd>
|
||||||
<b><code>toArray():Array<Y.XmlElement|Y.XmlText></code></b>
|
<b><code>toArray():Array<Y.XmlElement|Y.XmlText></code></b>
|
||||||
<dd>Copies the children to a new Array.</dd>
|
<dd>Copies the children to a new Array.</dd>
|
||||||
<b><code>toDOM():DocumentFragment</code></b>
|
<b><code>toDOM():DocumentFragment</code></b>
|
||||||
@@ -512,6 +520,12 @@ content and be actually XML compliant.
|
|||||||
<dd></dd>
|
<dd></dd>
|
||||||
<b><code>getAttributes(attributeName:string):Object<string,string></code></b>
|
<b><code>getAttributes(attributeName:string):Object<string,string></code></b>
|
||||||
<dd></dd>
|
<dd></dd>
|
||||||
|
<b><code>get(i:number):Y.XmlElement|Y.XmlText</code></b>
|
||||||
|
<dd>Retrieve the i-th element.</dd>
|
||||||
|
<b><code>slice(start:number, end:number):Array<Y.XmlElement|Y.XmlText></code></b>
|
||||||
|
<dd>Retrieve a range of content</dd>
|
||||||
|
<b><code>clone():Y.XmlElement</code></b>
|
||||||
|
<dd>Clone this type into a fresh Yjs type.</dd>
|
||||||
<b><code>toArray():Array<Y.XmlElement|Y.XmlText></code></b>
|
<b><code>toArray():Array<Y.XmlElement|Y.XmlText></code></b>
|
||||||
<dd>Copies the children to a new Array.</dd>
|
<dd>Copies the children to a new Array.</dd>
|
||||||
<b><code>toDOM():Element</code></b>
|
<b><code>toDOM():Element</code></b>
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "yjs",
|
"name": "yjs",
|
||||||
"version": "13.4.3",
|
"version": "13.4.6",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "yjs",
|
"name": "yjs",
|
||||||
"version": "13.4.3",
|
"version": "13.4.6",
|
||||||
"description": "Shared Editing Library",
|
"description": "Shared Editing Library",
|
||||||
"main": "./dist/yjs.cjs",
|
"main": "./dist/yjs.cjs",
|
||||||
"module": "./dist/yjs.mjs",
|
"module": "./dist/yjs.mjs",
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ export {
|
|||||||
snapshot,
|
snapshot,
|
||||||
emptySnapshot,
|
emptySnapshot,
|
||||||
findRootTypeKey,
|
findRootTypeKey,
|
||||||
|
getItem,
|
||||||
typeListToArraySnapshot,
|
typeListToArraySnapshot,
|
||||||
typeMapGetSnapshot,
|
typeMapGetSnapshot,
|
||||||
createDocFromSnapshot,
|
createDocFromSnapshot,
|
||||||
|
|||||||
@@ -309,6 +309,13 @@ export class AbstractType {
|
|||||||
throw error.methodUnimplemented()
|
throw error.methodUnimplemented()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {AbstractType<EventType>}
|
||||||
|
*/
|
||||||
|
clone () {
|
||||||
|
throw error.methodUnimplemented()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {AbstractUpdateEncoder} encoder
|
* @param {AbstractUpdateEncoder} encoder
|
||||||
*/
|
*/
|
||||||
@@ -381,6 +388,43 @@ export class AbstractType {
|
|||||||
toJSON () {}
|
toJSON () {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {AbstractType<any>} type
|
||||||
|
* @param {number} start
|
||||||
|
* @param {number} end
|
||||||
|
* @return {Array<any>}
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @function
|
||||||
|
*/
|
||||||
|
export const typeListSlice = (type, start, end) => {
|
||||||
|
if (start < 0) {
|
||||||
|
start = type._length + start
|
||||||
|
}
|
||||||
|
if (end < 0) {
|
||||||
|
end = type._length + end
|
||||||
|
}
|
||||||
|
let len = end - start
|
||||||
|
const cs = []
|
||||||
|
let n = type._start
|
||||||
|
while (n !== null && len > 0) {
|
||||||
|
if (n.countable && !n.deleted) {
|
||||||
|
const c = n.content.getContent()
|
||||||
|
if (c.length <= start) {
|
||||||
|
start -= c.length
|
||||||
|
} else {
|
||||||
|
for (let i = start; i < c.length && len > 0; i++) {
|
||||||
|
cs.push(c[i])
|
||||||
|
len--
|
||||||
|
}
|
||||||
|
start = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
n = n.right
|
||||||
|
}
|
||||||
|
return cs
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {AbstractType<any>} type
|
* @param {AbstractType<any>} type
|
||||||
* @return {Array<any>}
|
* @return {Array<any>}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
transact,
|
transact,
|
||||||
ArraySearchMarker, AbstractUpdateDecoder, AbstractUpdateEncoder, Doc, Transaction, Item // eslint-disable-line
|
ArraySearchMarker, AbstractUpdateDecoder, AbstractUpdateEncoder, Doc, Transaction, Item // eslint-disable-line
|
||||||
} from '../internals.js'
|
} from '../internals.js'
|
||||||
|
import { typeListSlice } from './AbstractType.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event that describes the changes on a YArray
|
* Event that describes the changes on a YArray
|
||||||
@@ -53,6 +54,18 @@ export class YArray extends AbstractType {
|
|||||||
this._searchMarker = []
|
this._searchMarker = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new YArray containing the specified items.
|
||||||
|
* @template T
|
||||||
|
* @param {Array<T>} items
|
||||||
|
* @return {YArray<T>}
|
||||||
|
*/
|
||||||
|
static from (items) {
|
||||||
|
const a = new YArray()
|
||||||
|
a.push(items)
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integrate this type into the Yjs instance.
|
* Integrate this type into the Yjs instance.
|
||||||
*
|
*
|
||||||
@@ -73,6 +86,17 @@ export class YArray extends AbstractType {
|
|||||||
return new YArray()
|
return new YArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {YArray<T>}
|
||||||
|
*/
|
||||||
|
clone () {
|
||||||
|
const arr = new YArray()
|
||||||
|
arr.insert(0, this.toArray().map(el =>
|
||||||
|
el instanceof AbstractType ? el.clone() : el
|
||||||
|
))
|
||||||
|
return arr
|
||||||
|
}
|
||||||
|
|
||||||
get length () {
|
get length () {
|
||||||
return this._prelimContent === null ? this._length : this._prelimContent.length
|
return this._prelimContent === null ? this._length : this._prelimContent.length
|
||||||
}
|
}
|
||||||
@@ -167,6 +191,17 @@ export class YArray extends AbstractType {
|
|||||||
return typeListToArray(this)
|
return typeListToArray(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms this YArray to a JavaScript Array.
|
||||||
|
*
|
||||||
|
* @param {number} [start]
|
||||||
|
* @param {number} [end]
|
||||||
|
* @return {Array<T>}
|
||||||
|
*/
|
||||||
|
slice (start = 0, end = this.length) {
|
||||||
|
return typeListSlice(this, start, end)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms this Shared Type to a JSON object.
|
* Transforms this Shared Type to a JSON object.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -84,6 +84,17 @@ export class YMap extends AbstractType {
|
|||||||
return new YMap()
|
return new YMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {YMap<T>}
|
||||||
|
*/
|
||||||
|
clone () {
|
||||||
|
const map = new YMap()
|
||||||
|
this.forEach((value, key) => {
|
||||||
|
map.set(key, value instanceof AbstractType ? value.clone() : value)
|
||||||
|
})
|
||||||
|
return map
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates YMapEvent and calls observers.
|
* Creates YMapEvent and calls observers.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -762,6 +762,15 @@ export class YText extends AbstractType {
|
|||||||
return new YText()
|
return new YText()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {YText}
|
||||||
|
*/
|
||||||
|
clone () {
|
||||||
|
const text = new YText()
|
||||||
|
text.applyDelta(this.toDelta())
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates YTextEvent and calls observers.
|
* Creates YTextEvent and calls observers.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
typeMapGetAll,
|
typeMapGetAll,
|
||||||
typeListForEach,
|
typeListForEach,
|
||||||
YXmlElementRefID,
|
YXmlElementRefID,
|
||||||
AbstractUpdateDecoder, AbstractUpdateEncoder, Snapshot, Doc, Item // eslint-disable-line
|
AbstractType, AbstractUpdateDecoder, AbstractUpdateEncoder, Snapshot, Doc, Item // eslint-disable-line
|
||||||
} from '../internals.js'
|
} from '../internals.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,6 +55,20 @@ export class YXmlElement extends YXmlFragment {
|
|||||||
return new YXmlElement(this.nodeName)
|
return new YXmlElement(this.nodeName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {YXmlElement}
|
||||||
|
*/
|
||||||
|
clone () {
|
||||||
|
const el = new YXmlElement(this.nodeName)
|
||||||
|
const attrs = this.getAttributes()
|
||||||
|
for (const key in attrs) {
|
||||||
|
el.setAttribute(key, attrs[key])
|
||||||
|
}
|
||||||
|
// @ts-ignore
|
||||||
|
el.insert(0, el.toArray().map(item => item instanceof AbstractType ? item.clone() : item))
|
||||||
|
return el
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the XML serialization of this YXmlElement.
|
* Returns the XML serialization of this YXmlElement.
|
||||||
* The attributes are ordered by attribute-name, so you can easily use this
|
* The attributes are ordered by attribute-name, so you can easily use this
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import {
|
|||||||
YXmlFragmentRefID,
|
YXmlFragmentRefID,
|
||||||
callTypeObservers,
|
callTypeObservers,
|
||||||
transact,
|
transact,
|
||||||
|
typeListGet,
|
||||||
|
typeListSlice,
|
||||||
AbstractUpdateDecoder, AbstractUpdateEncoder, Doc, ContentType, Transaction, Item, YXmlText, YXmlHook, Snapshot // eslint-disable-line
|
AbstractUpdateDecoder, AbstractUpdateEncoder, Doc, ContentType, Transaction, Item, YXmlText, YXmlHook, Snapshot // eslint-disable-line
|
||||||
} from '../internals.js'
|
} from '../internals.js'
|
||||||
|
|
||||||
@@ -148,6 +150,16 @@ export class YXmlFragment extends AbstractType {
|
|||||||
return new YXmlFragment()
|
return new YXmlFragment()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {YXmlFragment}
|
||||||
|
*/
|
||||||
|
clone () {
|
||||||
|
const el = new YXmlFragment()
|
||||||
|
// @ts-ignore
|
||||||
|
el.insert(0, el.toArray().map(item => item instanceof AbstractType ? item.clone() : item))
|
||||||
|
return el
|
||||||
|
}
|
||||||
|
|
||||||
get length () {
|
get length () {
|
||||||
return this._prelimContent === null ? this._length : this._prelimContent.length
|
return this._prelimContent === null ? this._length : this._prelimContent.length
|
||||||
}
|
}
|
||||||
@@ -316,6 +328,45 @@ export class YXmlFragment extends AbstractType {
|
|||||||
return typeListToArray(this)
|
return typeListToArray(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends content to this YArray.
|
||||||
|
*
|
||||||
|
* @param {Array<YXmlElement|YXmlText>} content Array of content to append.
|
||||||
|
*/
|
||||||
|
push (content) {
|
||||||
|
this.insert(this.length, content)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preppends content to this YArray.
|
||||||
|
*
|
||||||
|
* @param {Array<YXmlElement|YXmlText>} content Array of content to preppend.
|
||||||
|
*/
|
||||||
|
unshift (content) {
|
||||||
|
this.insert(0, content)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the i-th element from a YArray.
|
||||||
|
*
|
||||||
|
* @param {number} index The index of the element to return from the YArray
|
||||||
|
* @return {YXmlElement|YXmlText}
|
||||||
|
*/
|
||||||
|
get (index) {
|
||||||
|
return typeListGet(this, index)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms this YArray to a JavaScript Array.
|
||||||
|
*
|
||||||
|
* @param {number} [start]
|
||||||
|
* @param {number} [end]
|
||||||
|
* @return {Array<YXmlElement|YXmlText>}
|
||||||
|
*/
|
||||||
|
slice (start = 0, end = this.length) {
|
||||||
|
return typeListSlice(this, start, end)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transform the properties of this type to binary and write it to an
|
* Transform the properties of this type to binary and write it to an
|
||||||
* BinaryEncoder.
|
* BinaryEncoder.
|
||||||
|
|||||||
@@ -29,6 +29,17 @@ export class YXmlHook extends YMap {
|
|||||||
return new YXmlHook(this.hookName)
|
return new YXmlHook(this.hookName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {YXmlHook}
|
||||||
|
*/
|
||||||
|
clone () {
|
||||||
|
const el = new YXmlHook(this.hookName)
|
||||||
|
this.forEach((value, key) => {
|
||||||
|
el.set(key, value)
|
||||||
|
})
|
||||||
|
return el
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Dom Element that mirrors this YXmlElement.
|
* Creates a Dom Element that mirrors this YXmlElement.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -14,6 +14,15 @@ export class YXmlText extends YText {
|
|||||||
return new YXmlText()
|
return new YXmlText()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {YXmlText}
|
||||||
|
*/
|
||||||
|
clone () {
|
||||||
|
const text = new YXmlText()
|
||||||
|
text.applyDelta(this.toDelta())
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Dom Element that mirrors this YXmlText.
|
* Creates a Dom Element that mirrors this YXmlText.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -257,6 +257,7 @@ export class Doc extends Observable {
|
|||||||
}, null, true)
|
}, null, true)
|
||||||
}
|
}
|
||||||
this.emit('destroyed', [true])
|
this.emit('destroyed', [true])
|
||||||
|
this.emit('destroy', [this])
|
||||||
super.destroy()
|
super.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,21 @@ export const testBasicUpdate = tc => {
|
|||||||
t.compare(doc2.getArray('array').toArray(), ['hi'])
|
t.compare(doc2.getArray('array').toArray(), ['hi'])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {t.TestCase} tc
|
||||||
|
*/
|
||||||
|
export const testSlice = tc => {
|
||||||
|
const doc1 = new Y.Doc()
|
||||||
|
const arr = doc1.getArray('array')
|
||||||
|
arr.insert(0, [1, 2, 3])
|
||||||
|
t.compareArrays(arr.slice(0), [1, 2, 3])
|
||||||
|
t.compareArrays(arr.slice(1), [2, 3])
|
||||||
|
t.compareArrays(arr.slice(0, -1), [1, 2])
|
||||||
|
arr.insert(0, [0])
|
||||||
|
t.compareArrays(arr.slice(0), [0, 1, 2, 3])
|
||||||
|
t.compareArrays(arr.slice(0, 2), [0, 1])
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user