Merge 7307fda6a01b93672001902dc1d2ee46cf8622c7 into bf4d33dba6a0e7de8f1a97efb8b5da446b28f81b

This commit is contained in:
Mansehej Singh 2024-04-17 13:43:16 +08:00 committed by GitHub
commit 8afa4e3ae8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 50 additions and 24 deletions

View File

@ -242,17 +242,17 @@ necessary.
</p> </p>
<pre>const yarray = new Y.Array()</pre> <pre>const yarray = new Y.Array()</pre>
<dl> <dl>
<b><code>insert(index:number, content:Array&lt;object|boolean|Array|string|number|Uint8Array|Y.Type&gt;)</code></b> <b><code>insert(index:number, content:Array&lt;object|boolean|Array|string|number|Uint8Array|Y.Type&gt;):Y.Array</code></b>
<dd> <dd>
Insert content at <var>index</var>. Note that content is an array of elements. Insert content at <var>index</var>. Note that content is an array of elements.
I.e. <code>array.insert(0, [1])</code> splices the list and inserts 1 at I.e. <code>array.insert(0, [1])</code> splices the list and inserts 1 at
position 0. position 0.
</dd> </dd>
<b><code>push(Array&lt;Object|boolean|Array|string|number|Uint8Array|Y.Type&gt;)</code></b> <b><code>push(Array&lt;Object|boolean|Array|string|number|Uint8Array|Y.Type&gt;):Y.Array</code></b>
<dd></dd> <dd></dd>
<b><code>unshift(Array&lt;Object|boolean|Array|string|number|Uint8Array|Y.Type&gt;)</code></b> <b><code>unshift(Array&lt;Object|boolean|Array|string|number|Uint8Array|Y.Type&gt;):Y.Array</code></b>
<dd></dd> <dd></dd>
<b><code>delete(index:number, length:number)</code></b> <b><code>delete(index:number, length:number):Y.Array</code></b>
<dd></dd> <dd></dd>
<b><code>get(index:number)</code></b> <b><code>get(index:number)</code></b>
<dd></dd> <dd></dd>
@ -313,9 +313,9 @@ or any of its children.
<dl> <dl>
<b><code>get(key:string):object|boolean|string|number|Uint8Array|Y.Type</code></b> <b><code>get(key:string):object|boolean|string|number|Uint8Array|Y.Type</code></b>
<dd></dd> <dd></dd>
<b><code>set(key:string, value:object|boolean|string|number|Uint8Array|Y.Type)</code></b> <b><code>set(key:string, value:object|boolean|string|number|Uint8Array|Y.Type):Y.Map</code></b>
<dd></dd> <dd></dd>
<b><code>delete(key:string)</code></b> <b><code>delete(key:string):Y.Map</code></b>
<dd></dd> <dd></dd>
<b><code>has(key:string):boolean</code></b> <b><code>has(key:string):boolean</code></b>
<dd></dd> <dd></dd>
@ -388,14 +388,14 @@ YTextEvents compute changes as deltas.
</p> </p>
<pre>const ytext = new Y.Text()</pre> <pre>const ytext = new Y.Text()</pre>
<dl> <dl>
<b><code>insert(index:number, content:string, [formattingAttributes:Object&lt;string,string&gt;])</code></b> <b><code>insert(index:number, content:string, [formattingAttributes:Object&lt;string,string&gt;]):Y.Text</code></b>
<dd> <dd>
Insert a string at <var>index</var> and assign formatting attributes to it. Insert a string at <var>index</var> and assign formatting attributes to it.
<pre>ytext.insert(0, 'bold text', { bold: true })</pre> <pre>ytext.insert(0, 'bold text', { bold: true })</pre>
</dd> </dd>
<b><code>delete(index:number, length:number)</code></b> <b><code>delete(index:number, length:number):Y.Text</code></b>
<dd></dd> <dd></dd>
<b><code>format(index:number, length:number, formattingAttributes:Object&lt;string,string&gt;)</code></b> <b><code>format(index:number, length:number, formattingAttributes:Object&lt;string,string&gt;):Y.Text</code></b>
<dd>Assign formatting attributes to a range in the text</dd> <dd>Assign formatting attributes to a range in the text</dd>
<b><code>applyDelta(delta, opts:Object&lt;string,any&gt;)</code></b> <b><code>applyDelta(delta, opts:Object&lt;string,any&gt;)</code></b>
<dd> <dd>
@ -446,9 +446,9 @@ or any of its children.
</p> </p>
<pre><code>const yxml = new Y.XmlFragment()</code></pre> <pre><code>const yxml = new Y.XmlFragment()</code></pre>
<dl> <dl>
<b><code>insert(index:number, content:Array&lt;Y.XmlElement|Y.XmlText&gt;)</code></b> <b><code>insert(index:number, content:Array&lt;Y.XmlElement|Y.XmlText&gt;):Y.XmlFragment</code></b>
<dd></dd> <dd></dd>
<b><code>delete(index:number, length:number)</code></b> <b><code>delete(index:number, length:number):Y.XmlFragment</code></b>
<dd></dd> <dd></dd>
<b><code>get(index:number)</code></b> <b><code>get(index:number)</code></b>
<dd></dd> <dd></dd>
@ -497,17 +497,17 @@ content and be actually XML compliant.
</p> </p>
<pre><code>const yxml = new Y.XmlElement()</code></pre> <pre><code>const yxml = new Y.XmlElement()</code></pre>
<dl> <dl>
<b><code>insert(index:number, content:Array&lt;Y.XmlElement|Y.XmlText&gt;)</code></b> <b><code>insert(index:number, content:Array&lt;Y.XmlElement|Y.XmlText&gt;):Y.XmlElement</code></b>
<dd></dd> <dd></dd>
<b><code>delete(index:number, length:number)</code></b> <b><code>delete(index:number, length:number):Y.XmlElement</code></b>
<dd></dd> <dd></dd>
<b><code>get(index:number)</code></b> <b><code>get(index:number)</code></b>
<dd></dd> <dd></dd>
<b><code>length:number</code></b> <b><code>length:number</code></b>
<dd></dd> <dd></dd>
<b><code>setAttribute(attributeName:string, attributeValue:string)</code></b> <b><code>setAttribute(attributeName:string, attributeValue:string):Y.XmlElement</code></b>
<dd></dd> <dd></dd>
<b><code>removeAttribute(attributeName:string)</code></b> <b><code>removeAttribute(attributeName:string):Y.XmlElement</code></b>
<dd></dd> <dd></dd>
<b><code>getAttribute(attributeName:string):string</code></b> <b><code>getAttribute(attributeName:string):string</code></b>
<dd></dd> <dd></dd>

View File

@ -101,6 +101,7 @@ export class YArray extends AbstractType {
* *
* @param {number} index The index to insert content at. * @param {number} index The index to insert content at.
* @param {Array<T>} content The array of content * @param {Array<T>} content The array of content
* @return {YArray<T>} Instance of the YArray
*/ */
insert (index, content) { insert (index, content) {
if (this.doc !== null) { if (this.doc !== null) {
@ -110,24 +111,27 @@ export class YArray extends AbstractType {
} else { } else {
/** @type {Array<any>} */ (this._prelimContent).splice(index, 0, ...content) /** @type {Array<any>} */ (this._prelimContent).splice(index, 0, ...content)
} }
return this
} }
/** /**
* Appends content to this YArray. * Appends content to this YArray.
* *
* @param {Array<T>} content Array of content to append. * @param {Array<T>} content Array of content to append.
* @return {YArray<T>} Instance of the YArray
*/ */
push (content) { push (content) {
this.insert(this.length, content) return this.insert(this.length, content)
} }
/** /**
* Preppends content to this YArray. * Preppends content to this YArray.
* *
* @param {Array<T>} content Array of content to preppend. * @param {Array<T>} content Array of content to preppend.
* @return {YArray<T>} Instance of the YArray
*/ */
unshift (content) { unshift (content) {
this.insert(0, content) return this.insert(0, content)
} }
/** /**
@ -135,6 +139,7 @@ export class YArray extends AbstractType {
* *
* @param {number} index Index at which to start deleting elements * @param {number} index Index at which to start deleting elements
* @param {number} length The number of elements to remove. Defaults to 1. * @param {number} length The number of elements to remove. Defaults to 1.
* @return {YArray<T>} Instance of the YArray
*/ */
delete (index, length = 1) { delete (index, length = 1) {
if (this.doc !== null) { if (this.doc !== null) {
@ -144,6 +149,7 @@ export class YArray extends AbstractType {
} else { } else {
/** @type {Array<any>} */ (this._prelimContent).splice(index, length) /** @type {Array<any>} */ (this._prelimContent).splice(index, length)
} }
return this
} }
/** /**

View File

@ -180,6 +180,7 @@ export class YMap extends AbstractType {
* Remove a specified element from this YMap. * Remove a specified element from this YMap.
* *
* @param {string} key The key of the element to remove. * @param {string} key The key of the element to remove.
* @return {YMap<T>} Instance of the YMap.
*/ */
delete (key) { delete (key) {
if (this.doc !== null) { if (this.doc !== null) {
@ -189,6 +190,7 @@ export class YMap extends AbstractType {
} else { } else {
/** @type {Map<string, any>} */ (this._prelimContent).delete(key) /** @type {Map<string, any>} */ (this._prelimContent).delete(key)
} }
return this
} }
/** /**
@ -196,6 +198,7 @@ export class YMap extends AbstractType {
* *
* @param {string} key The key of the element to add to this YMap * @param {string} key The key of the element to add to this YMap
* @param {T} value The value of the element to add * @param {T} value The value of the element to add
* @return {YMap<T>} Instance of the YMap
*/ */
set (key, value) { set (key, value) {
if (this.doc !== null) { if (this.doc !== null) {
@ -205,7 +208,7 @@ export class YMap extends AbstractType {
} else { } else {
/** @type {Map<string, any>} */ (this._prelimContent).set(key, value) /** @type {Map<string, any>} */ (this._prelimContent).set(key, value)
} }
return value return this
} }
/** /**

View File

@ -997,11 +997,12 @@ export class YText extends AbstractType {
* @param {TextAttributes} [attributes] Optionally define some formatting * @param {TextAttributes} [attributes] Optionally define some formatting
* information to apply on the inserted * information to apply on the inserted
* Text. * Text.
* @return {YText} Instance of the YText.
* @public * @public
*/ */
insert (index, text, attributes) { insert (index, text, attributes) {
if (text.length <= 0) { if (text.length <= 0) {
return return this
} }
const y = this.doc const y = this.doc
if (y !== null) { if (y !== null) {
@ -1017,6 +1018,7 @@ export class YText extends AbstractType {
} else { } else {
/** @type {Array<function>} */ (this._pending).push(() => this.insert(index, text, attributes)) /** @type {Array<function>} */ (this._pending).push(() => this.insert(index, text, attributes))
} }
return this
} }
/** /**
@ -1049,12 +1051,13 @@ export class YText extends AbstractType {
* *
* @param {number} index Index at which to start deleting. * @param {number} index Index at which to start deleting.
* @param {number} length The number of characters to remove. Defaults to 1. * @param {number} length The number of characters to remove. Defaults to 1.
* @return {YText} Instance of the YText.
* *
* @public * @public
*/ */
delete (index, length) { delete (index, length) {
if (length === 0) { if (length === 0) {
return return this
} }
const y = this.doc const y = this.doc
if (y !== null) { if (y !== null) {
@ -1065,6 +1068,7 @@ export class YText extends AbstractType {
} else { } else {
/** @type {Array<function>} */ (this._pending).push(() => this.delete(index, length)) /** @type {Array<function>} */ (this._pending).push(() => this.delete(index, length))
} }
return this
} }
/** /**
@ -1074,12 +1078,13 @@ export class YText extends AbstractType {
* @param {number} length The amount of characters to assign properties to. * @param {number} length The amount of characters to assign properties to.
* @param {TextAttributes} attributes Attribute information to apply on the * @param {TextAttributes} attributes Attribute information to apply on the
* text. * text.
* @return {YText} Instance of the YText.
* *
* @public * @public
*/ */
format (index, length, attributes) { format (index, length, attributes) {
if (length === 0) { if (length === 0) {
return return this
} }
const y = this.doc const y = this.doc
if (y !== null) { if (y !== null) {
@ -1093,6 +1098,7 @@ export class YText extends AbstractType {
} else { } else {
/** @type {Array<function>} */ (this._pending).push(() => this.format(index, length, attributes)) /** @type {Array<function>} */ (this._pending).push(() => this.format(index, length, attributes))
} }
return this
} }
/** /**

View File

@ -89,6 +89,7 @@ export class YXmlElement extends YXmlFragment {
* Removes an attribute from this YXmlElement. * Removes an attribute from this YXmlElement.
* *
* @param {String} attributeName The attribute name that is to be removed. * @param {String} attributeName The attribute name that is to be removed.
* @return {YXmlElement} Instance of the YXmlElement.
* *
* @public * @public
*/ */
@ -100,6 +101,7 @@ export class YXmlElement extends YXmlFragment {
} else { } else {
/** @type {Map<string,any>} */ (this._prelimAttrs).delete(attributeName) /** @type {Map<string,any>} */ (this._prelimAttrs).delete(attributeName)
} }
return this
} }
/** /**
@ -107,6 +109,7 @@ export class YXmlElement extends YXmlFragment {
* *
* @param {String} attributeName The attribute name that is to be set. * @param {String} attributeName The attribute name that is to be set.
* @param {String} attributeValue The attribute value that is to be set. * @param {String} attributeValue The attribute value that is to be set.
* @return {YXmlElement} Instance of the YXmlElement.
* *
* @public * @public
*/ */
@ -118,6 +121,7 @@ export class YXmlElement extends YXmlFragment {
} else { } else {
/** @type {Map<string, any>} */ (this._prelimAttrs).set(attributeName, attributeValue) /** @type {Map<string, any>} */ (this._prelimAttrs).set(attributeName, attributeValue)
} }
return this
} }
/** /**

View File

@ -281,6 +281,7 @@ export class YXmlFragment extends AbstractType {
* *
* @param {number} index The index to insert content at * @param {number} index The index to insert content at
* @param {Array<YXmlElement|YXmlText>} content The array of content * @param {Array<YXmlElement|YXmlText>} content The array of content
* @return {YXmlFragment} Instance of the YXmlFragment.
*/ */
insert (index, content) { insert (index, content) {
if (this.doc !== null) { if (this.doc !== null) {
@ -291,6 +292,7 @@ export class YXmlFragment extends AbstractType {
// @ts-ignore _prelimContent is defined because this is not yet integrated // @ts-ignore _prelimContent is defined because this is not yet integrated
this._prelimContent.splice(index, 0, ...content) this._prelimContent.splice(index, 0, ...content)
} }
return this
} }
/** /**
@ -298,6 +300,7 @@ export class YXmlFragment extends AbstractType {
* *
* @param {number} index Index at which to start deleting elements * @param {number} index Index at which to start deleting elements
* @param {number} [length=1] The number of elements to remove. Defaults to 1. * @param {number} [length=1] The number of elements to remove. Defaults to 1.
* @return {YXmlFragment} Instance of the YXmlFragment.
*/ */
delete (index, length = 1) { delete (index, length = 1) {
if (this.doc !== null) { if (this.doc !== null) {
@ -308,6 +311,7 @@ export class YXmlFragment extends AbstractType {
// @ts-ignore _prelimContent is defined because this is not yet integrated // @ts-ignore _prelimContent is defined because this is not yet integrated
this._prelimContent.splice(index, length) this._prelimContent.splice(index, length)
} }
return this
} }
/** /**

View File

@ -109,7 +109,8 @@ export const testGetAndSetOfMapProperty = tc => {
*/ */
export const testYmapSetsYmap = tc => { export const testYmapSetsYmap = tc => {
const { users, map0 } = init(tc, { users: 2 }) const { users, map0 } = init(tc, { users: 2 })
const map = map0.set('Map', new Y.Map()) const map = new Y.Map()
map0.set('Map', map)
t.assert(map0.get('Map') === map) t.assert(map0.get('Map') === map)
map.set('one', 1) map.set('one', 1)
t.compare(map.get('one'), 1) t.compare(map.get('one'), 1)
@ -121,7 +122,8 @@ export const testYmapSetsYmap = tc => {
*/ */
export const testYmapSetsYarray = tc => { export const testYmapSetsYarray = tc => {
const { users, map0 } = init(tc, { users: 2 }) const { users, map0 } = init(tc, { users: 2 })
const array = map0.set('Array', new Y.Array()) const array = new Y.Array()
map0.set('Array', array)
t.assert(array === map0.get('Array')) t.assert(array === map0.get('Array'))
array.insert(0, [1, 2, 3]) array.insert(0, [1, 2, 3])
// @ts-ignore // @ts-ignore
@ -234,7 +236,8 @@ export const testGetAndSetAndDeleteOfMapPropertyWithThreeConflicts = tc => {
*/ */
export const testObserveDeepProperties = tc => { export const testObserveDeepProperties = tc => {
const { testConnector, users, map1, map2, map3 } = init(tc, { users: 4 }) const { testConnector, users, map1, map2, map3 } = init(tc, { users: 4 })
const _map1 = map1.set('map', new Y.Map()) const _map1 = new Y.Map()
map1.set('map', _map1)
let calls = 0 let calls = 0
let dmapid let dmapid
map1.observeDeep(events => { map1.observeDeep(events => {