Comparing version 13.5.2 to 13.5.3
@@ -45,9 +45,2 @@ export class ItemTextListPosition { | ||
/** | ||
* @typedef {Object} DeltaItem | ||
* @property {number|undefined} DeltaItem.delete | ||
* @property {number|undefined} DeltaItem.retain | ||
* @property {string|undefined} DeltaItem.insert | ||
* @property {Object<string,any>} DeltaItem.attributes | ||
*/ | ||
/** | ||
* Event that describes the changes on a YText type. | ||
@@ -63,6 +56,2 @@ */ | ||
/** | ||
* @type {Array<DeltaItem>|null} | ||
*/ | ||
_delta: Array<DeltaItem> | null; | ||
/** | ||
* Whether the children changed. | ||
@@ -78,11 +67,2 @@ * @type {Boolean} | ||
keysChanged: Set<string>; | ||
/** | ||
* Compute the changes in the delta format. | ||
* A {@link https://quilljs.com/docs/delta/|Quill Delta}) that represents the changes on the document. | ||
* | ||
* @type {Array<DeltaItem>} | ||
* | ||
* @public | ||
*/ | ||
public get delta(): DeltaItem[]; | ||
} | ||
@@ -232,10 +212,2 @@ /** | ||
export type TextAttributes = Object; | ||
export type DeltaItem = { | ||
delete: number | undefined; | ||
retain: number | undefined; | ||
insert: string | undefined; | ||
attributes: { | ||
[x: string]: any; | ||
}; | ||
}; | ||
import { Item } from "../structs/Item.js"; | ||
@@ -242,0 +214,0 @@ import { YEvent } from "../utils/YEvent.js"; |
@@ -30,2 +30,21 @@ /** | ||
/** | ||
* @type {null | Map<string, { action: 'add' | 'update' | 'delete', oldValue: any, newValue: any }>} | ||
*/ | ||
_keys: Map<string, { | ||
action: 'add' | 'update' | 'delete'; | ||
oldValue: any; | ||
newValue: any; | ||
}> | null; | ||
/** | ||
* @type {null | Array<{ insert?: string | Array<any>, retain?: number, delete?: number, attributes?: Object<string, any> }>} | ||
*/ | ||
_delta: { | ||
insert?: string | any[] | undefined; | ||
retain?: number | undefined; | ||
delete?: number | undefined; | ||
attributes?: { | ||
[x: string]: any; | ||
} | undefined; | ||
}[] | null; | ||
/** | ||
* Computes the path from `y` to the changed type. | ||
@@ -54,2 +73,21 @@ * | ||
/** | ||
* @type {Map<string, { action: 'add' | 'update' | 'delete', oldValue: any, newValue: any }>} | ||
*/ | ||
get keys(): Map<string, { | ||
action: 'add' | 'update' | 'delete'; | ||
oldValue: any; | ||
newValue: any; | ||
}>; | ||
/** | ||
* @type {Array<{insert?: string | Array<any>, retain?: number, delete?: number, attributes?: Object<string, any>}>} | ||
*/ | ||
get delta(): { | ||
insert?: string | any[] | undefined; | ||
retain?: number | undefined; | ||
delete?: number | undefined; | ||
attributes?: { | ||
[x: string]: any; | ||
} | undefined; | ||
}[]; | ||
/** | ||
* Check if a struct is added by this event. | ||
@@ -64,3 +102,3 @@ * | ||
/** | ||
* @return {{added:Set<Item>,deleted:Set<Item>,keys:Map<string,{action:'add'|'update'|'delete',oldValue:any}>,delta:Array<{insert:Array<any>}|{delete:number}|{retain:number}>}} | ||
* @type {{added:Set<Item>,deleted:Set<Item>,keys:Map<string,{action:'add'|'update'|'delete',oldValue:any}>,delta:Array<{insert?:Array<any>|string, delete?:number, retain?:number}>}} | ||
*/ | ||
@@ -75,7 +113,5 @@ get changes(): { | ||
delta: Array<{ | ||
insert: Array<any>; | ||
} | { | ||
delete: number; | ||
} | { | ||
retain: number; | ||
insert?: Array<any> | string; | ||
delete?: number; | ||
retain?: number; | ||
}>; | ||
@@ -82,0 +118,0 @@ }; |
{ | ||
"name": "yjs", | ||
"version": "13.5.2", | ||
"version": "13.5.3", | ||
"description": "Shared Editing Library", | ||
"main": "./dist/yjs.cjs", | ||
"module": "./dist/yjs.mjs", | ||
"unpkg": "./dist/yjs.mjs", | ||
"types": "./dist/src/index.d.ts", | ||
@@ -34,3 +33,4 @@ "sideEffects": false, | ||
"./src/index.js": "./src/index.js", | ||
"./tests/testHelper.js": "./tests/testHelper.js" | ||
"./tests/testHelper.js": "./tests/testHelper.js", | ||
"./package.json": "./package.json" | ||
}, | ||
@@ -37,0 +37,0 @@ "files": [ |
@@ -506,10 +506,2 @@ | ||
/** | ||
* @typedef {Object} DeltaItem | ||
* @property {number|undefined} DeltaItem.delete | ||
* @property {number|undefined} DeltaItem.retain | ||
* @property {string|undefined} DeltaItem.insert | ||
* @property {Object<string,any>} DeltaItem.attributes | ||
*/ | ||
/** | ||
* Event that describes the changes on a YText type. | ||
@@ -526,6 +518,2 @@ */ | ||
/** | ||
* @type {Array<DeltaItem>|null} | ||
*/ | ||
this._delta = null | ||
/** | ||
* Whether the children changed. | ||
@@ -551,6 +539,25 @@ * @type {Boolean} | ||
/** | ||
* @type {{added:Set<Item>,deleted:Set<Item>,keys:Map<string,{action:'add'|'update'|'delete',oldValue:any}>,delta:Array<{insert?:Array<any>|string, delete?:number, retain?:number}>}} | ||
*/ | ||
get changes () { | ||
if (this._changes === null) { | ||
/** | ||
* @type {{added:Set<Item>,deleted:Set<Item>,keys:Map<string,{action:'add'|'update'|'delete',oldValue:any}>,delta:Array<{insert?:Array<any>|string, delete?:number, retain?:number}>}} | ||
*/ | ||
const changes = { | ||
keys: this.keys, | ||
delta: this.delta, | ||
added: new Set(), | ||
deleted: new Set() | ||
} | ||
this._changes = changes | ||
} | ||
return /** @type {any} */ (this._changes) | ||
} | ||
/** | ||
* Compute the changes in the delta format. | ||
* A {@link https://quilljs.com/docs/delta/|Quill Delta}) that represents the changes on the document. | ||
* | ||
* @type {Array<DeltaItem>} | ||
* @type {Array<{insert?:string, delete?:number, retain?:number, attributes?: Object<string,any>}>} | ||
* | ||
@@ -562,5 +569,7 @@ * @public | ||
const y = /** @type {Doc} */ (this.target.doc) | ||
this._delta = [] | ||
/** | ||
* @type {Array<{insert?:string, delete?:number, retain?:number, attributes?: Object<string,any>}>} | ||
*/ | ||
const delta = [] | ||
transact(y, transaction => { | ||
const delta = /** @type {Array<DeltaItem>} */ (this._delta) | ||
const currentAttributes = new Map() // saves all current attributes for insert | ||
@@ -735,4 +744,5 @@ const oldAttributes = new Map() | ||
}) | ||
this._delta = delta | ||
} | ||
return this._delta | ||
return /** @type {any} */ (this._delta) | ||
} | ||
@@ -739,0 +749,0 @@ } |
@@ -38,2 +38,10 @@ | ||
this._changes = null | ||
/** | ||
* @type {null | Map<string, { action: 'add' | 'update' | 'delete', oldValue: any, newValue: any }>} | ||
*/ | ||
this._keys = null | ||
/** | ||
* @type {null | Array<{ insert?: string | Array<any>, retain?: number, delete?: number, attributes?: Object<string, any> }>} | ||
*/ | ||
this._delta = null | ||
} | ||
@@ -72,2 +80,62 @@ | ||
/** | ||
* @type {Map<string, { action: 'add' | 'update' | 'delete', oldValue: any, newValue: any }>} | ||
*/ | ||
get keys () { | ||
if (this._keys === null) { | ||
const keys = new Map() | ||
const target = this.target | ||
const changed = /** @type Set<string|null> */ (this.transaction.changed.get(target)) | ||
changed.forEach(key => { | ||
if (key !== null) { | ||
const item = /** @type {Item} */ (target._map.get(key)) | ||
/** | ||
* @type {'delete' | 'add' | 'update'} | ||
*/ | ||
let action | ||
let oldValue | ||
if (this.adds(item)) { | ||
let prev = item.left | ||
while (prev !== null && this.adds(prev)) { | ||
prev = prev.left | ||
} | ||
if (this.deletes(item)) { | ||
if (prev !== null && this.deletes(prev)) { | ||
action = 'delete' | ||
oldValue = array.last(prev.content.getContent()) | ||
} else { | ||
return | ||
} | ||
} else { | ||
if (prev !== null && this.deletes(prev)) { | ||
action = 'update' | ||
oldValue = array.last(prev.content.getContent()) | ||
} else { | ||
action = 'add' | ||
oldValue = undefined | ||
} | ||
} | ||
} else { | ||
if (this.deletes(item)) { | ||
action = 'delete' | ||
oldValue = array.last(/** @type {Item} */ item.content.getContent()) | ||
} else { | ||
return // nop | ||
} | ||
} | ||
keys.set(key, { action, oldValue }) | ||
} | ||
}) | ||
this._keys = keys | ||
} | ||
return this._keys | ||
} | ||
/** | ||
* @type {Array<{insert?: string | Array<any>, retain?: number, delete?: number, attributes?: Object<string, any>}>} | ||
*/ | ||
get delta () { | ||
return this.changes.delta | ||
} | ||
/** | ||
* Check if a struct is added by this event. | ||
@@ -85,3 +153,3 @@ * | ||
/** | ||
* @return {{added:Set<Item>,deleted:Set<Item>,keys:Map<string,{action:'add'|'update'|'delete',oldValue:any}>,delta:Array<{insert:Array<any>}|{delete:number}|{retain:number}>}} | ||
* @type {{added:Set<Item>,deleted:Set<Item>,keys:Map<string,{action:'add'|'update'|'delete',oldValue:any}>,delta:Array<{insert?:Array<any>|string, delete?:number, retain?:number}>}} | ||
*/ | ||
@@ -98,8 +166,7 @@ get changes () { | ||
const delta = [] | ||
/** | ||
* @type {Map<string,{ action: 'add' | 'update' | 'delete', oldValue: any}>} | ||
*/ | ||
const keys = new Map() | ||
changes = { | ||
added, deleted, delta, keys | ||
added, | ||
deleted, | ||
delta, | ||
keys: this.keys | ||
} | ||
@@ -148,42 +215,2 @@ const changed = /** @type Set<string|null> */ (this.transaction.changed.get(target)) | ||
} | ||
changed.forEach(key => { | ||
if (key !== null) { | ||
const item = /** @type {Item} */ (target._map.get(key)) | ||
/** | ||
* @type {'delete' | 'add' | 'update'} | ||
*/ | ||
let action | ||
let oldValue | ||
if (this.adds(item)) { | ||
let prev = item.left | ||
while (prev !== null && this.adds(prev)) { | ||
prev = prev.left | ||
} | ||
if (this.deletes(item)) { | ||
if (prev !== null && this.deletes(prev)) { | ||
action = 'delete' | ||
oldValue = array.last(prev.content.getContent()) | ||
} else { | ||
return | ||
} | ||
} else { | ||
if (prev !== null && this.deletes(prev)) { | ||
action = 'update' | ||
oldValue = array.last(prev.content.getContent()) | ||
} else { | ||
action = 'add' | ||
oldValue = undefined | ||
} | ||
} | ||
} else { | ||
if (this.deletes(item)) { | ||
action = 'delete' | ||
oldValue = array.last(/** @type {Item} */ item.content.getContent()) | ||
} else { | ||
return // nop | ||
} | ||
} | ||
keys.set(key, { action, oldValue }) | ||
} | ||
}) | ||
this._changes = changes | ||
@@ -190,0 +217,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
1990416
30906