mirror of
https://github.com/yjs/yjs.git
synced 2025-12-16 19:57:45 +01:00
export createDelta
This commit is contained in:
@@ -19,6 +19,7 @@ export * from './utils/YEvent.js'
|
|||||||
export * from './utils/StructSet.js'
|
export * from './utils/StructSet.js'
|
||||||
export * from './utils/IdMap.js'
|
export * from './utils/IdMap.js'
|
||||||
export * from './utils/AttributionManager.js'
|
export * from './utils/AttributionManager.js'
|
||||||
|
export * from './utils/Delta.js'
|
||||||
|
|
||||||
export * from './types/AbstractType.js'
|
export * from './types/AbstractType.js'
|
||||||
export * from './types/YArray.js'
|
export * from './types/YArray.js'
|
||||||
|
|||||||
@@ -1090,7 +1090,7 @@ export class YText extends AbstractType {
|
|||||||
// # Update Attributions
|
// # Update Attributions
|
||||||
if (attribution != null || object.hasProperty(previousUnattributedAttributes, key)) {
|
if (attribution != null || object.hasProperty(previousUnattributedAttributes, key)) {
|
||||||
/**
|
/**
|
||||||
* @type {import('../utils/Delta.js').Attribution}
|
* @type {import('../utils/AttributionManager.js').Attribution}
|
||||||
*/
|
*/
|
||||||
const formattingAttribution = object.assign({}, d.usedAttribution)
|
const formattingAttribution = object.assign({}, d.usedAttribution)
|
||||||
const changedAttributedAttributes = /** @type {{ [key: string]: Array<any> }} */ (formattingAttribution.attributes = object.assign({}, formattingAttribution.attributes ?? {}))
|
const changedAttributedAttributes = /** @type {{ [key: string]: Array<any> }} */ (formattingAttribution.attributes = object.assign({}, formattingAttribution.attributes ?? {}))
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export const createAttributionFromAttributionItems = (attrs, deleted) => {
|
|||||||
// eslint-disable-next-line no-fallthrough
|
// eslint-disable-next-line no-fallthrough
|
||||||
case 'insert':
|
case 'insert':
|
||||||
case 'delete': {
|
case 'delete': {
|
||||||
const as = /** @type {import('../utils/Delta.js').Attribution} */ (attribution)
|
const as = /** @type {import('../utils/Delta.js').Attribution_} */ (attribution)
|
||||||
const ls = as[attr.name] = as[attr.name] ?? []
|
const ls = as[attr.name] = as[attr.name] ?? []
|
||||||
ls.push(attr.val)
|
ls.push(attr.val)
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import * as error from 'lib0/error'
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {import('./AttributionManager.js').Attribution} Attribution
|
* @typedef {import('./AttributionManager.js').Attribution} Attribution_
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,14 +32,14 @@ import * as error from 'lib0/error'
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{ insert: string|object, attributes?: { [key: string]: any }, attribution?: Attribution } | { delete: number } | { retain: number, attributes?: { [key:string]: any }, attribution?: Attribution }} DeltaJsonOp
|
* @typedef {{ insert: string|object, attributes?: { [key: string]: any }, attribution?: Attribution_ } | { delete: number } | { retain: number, attributes?: { [key:string]: any }, attribution?: Attribution_ }} DeltaJsonOp
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export class InsertStringOp {
|
export class InsertStringOp {
|
||||||
/**
|
/**
|
||||||
* @param {string} insert
|
* @param {string} insert
|
||||||
* @param {FormattingAttributes|null} attributes
|
* @param {FormattingAttributes|null} attributes
|
||||||
* @param {Attribution|null} attribution
|
* @param {Attribution_|null} attribution
|
||||||
*/
|
*/
|
||||||
constructor (insert, attributes, attribution) {
|
constructor (insert, attributes, attribution) {
|
||||||
this.insert = insert
|
this.insert = insert
|
||||||
@@ -73,7 +73,7 @@ export class InsertArrayOp {
|
|||||||
/**
|
/**
|
||||||
* @param {Array<ArrayContent>} insert
|
* @param {Array<ArrayContent>} insert
|
||||||
* @param {FormattingAttributes|null} attributes
|
* @param {FormattingAttributes|null} attributes
|
||||||
* @param {Attribution|null} attribution
|
* @param {Attribution_|null} attribution
|
||||||
*/
|
*/
|
||||||
constructor (insert, attributes, attribution) {
|
constructor (insert, attributes, attribution) {
|
||||||
this.insert = insert
|
this.insert = insert
|
||||||
@@ -107,7 +107,7 @@ export class InsertEmbedOp {
|
|||||||
/**
|
/**
|
||||||
* @param {Embeds} insert
|
* @param {Embeds} insert
|
||||||
* @param {FormattingAttributes|null} attributes
|
* @param {FormattingAttributes|null} attributes
|
||||||
* @param {Attribution|null} attribution
|
* @param {Attribution_|null} attribution
|
||||||
*/
|
*/
|
||||||
constructor (insert, attributes, attribution) {
|
constructor (insert, attributes, attribution) {
|
||||||
this.insert = insert
|
this.insert = insert
|
||||||
@@ -165,7 +165,7 @@ export class RetainOp {
|
|||||||
/**
|
/**
|
||||||
* @param {number} retain
|
* @param {number} retain
|
||||||
* @param {FormattingAttributes|null} attributes
|
* @param {FormattingAttributes|null} attributes
|
||||||
* @param {Attribution|null} attribution
|
* @param {Attribution_|null} attribution
|
||||||
*/
|
*/
|
||||||
constructor (retain, attributes, attribution) {
|
constructor (retain, attributes, attribution) {
|
||||||
this.retain = retain
|
this.retain = retain
|
||||||
@@ -286,7 +286,7 @@ export class DeltaBuilder extends AbstractDelta {
|
|||||||
*/
|
*/
|
||||||
this.usedAttributes = null
|
this.usedAttributes = null
|
||||||
/**
|
/**
|
||||||
* @type {Attribution?}
|
* @type {Attribution_?}
|
||||||
*/
|
*/
|
||||||
this.usedAttribution = null
|
this.usedAttribution = null
|
||||||
/**
|
/**
|
||||||
@@ -323,9 +323,9 @@ export class DeltaBuilder extends AbstractDelta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @template {keyof Attribution} NAME
|
* @template {keyof Attribution_} NAME
|
||||||
* @param {NAME} name
|
* @param {NAME} name
|
||||||
* @param {Attribution[NAME]?} value
|
* @param {Attribution_[NAME]?} value
|
||||||
*/
|
*/
|
||||||
updateUsedAttribution (name, value) {
|
updateUsedAttribution (name, value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
@@ -342,7 +342,7 @@ export class DeltaBuilder extends AbstractDelta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Attribution?} attribution
|
* @param {Attribution_?} attribution
|
||||||
*/
|
*/
|
||||||
useAttribution (attribution) {
|
useAttribution (attribution) {
|
||||||
this.usedAttribution = attribution
|
this.usedAttribution = attribution
|
||||||
@@ -352,7 +352,7 @@ export class DeltaBuilder extends AbstractDelta {
|
|||||||
/**
|
/**
|
||||||
* @param {(TDeltaOp extends InsertStringOp ? string : never) | (TDeltaOp extends InsertEmbedOp<infer Embeds> ? (Embeds) : never) | (TDeltaOp extends InsertArrayOp<infer Content> ? Array<Content> : never) } insert
|
* @param {(TDeltaOp extends InsertStringOp ? string : never) | (TDeltaOp extends InsertEmbedOp<infer Embeds> ? (Embeds) : never) | (TDeltaOp extends InsertArrayOp<infer Content> ? Array<Content> : never) } insert
|
||||||
* @param {FormattingAttributes?} attributes
|
* @param {FormattingAttributes?} attributes
|
||||||
* @param {Attribution?} attribution
|
* @param {Attribution_?} attribution
|
||||||
* @return {this}
|
* @return {this}
|
||||||
*/
|
*/
|
||||||
insert (insert, attributes = null, attribution = null) {
|
insert (insert, attributes = null, attribution = null) {
|
||||||
@@ -377,7 +377,7 @@ export class DeltaBuilder extends AbstractDelta {
|
|||||||
/**
|
/**
|
||||||
* @param {number} retain
|
* @param {number} retain
|
||||||
* @param {FormattingAttributes?} attributes
|
* @param {FormattingAttributes?} attributes
|
||||||
* @param {Attribution?} attribution
|
* @param {Attribution_?} attribution
|
||||||
* @return {this}
|
* @return {this}
|
||||||
*/
|
*/
|
||||||
retain (retain, attributes = null, attribution = null) {
|
retain (retain, attributes = null, attribution = null) {
|
||||||
|
|||||||
@@ -1,20 +1,11 @@
|
|||||||
import {
|
import {
|
||||||
Item, AbstractType, Transaction, AbstractStruct // eslint-disable-line
|
TextDelta, Item, AbstractType, Transaction, AbstractStruct // eslint-disable-line
|
||||||
} from '../internals.js'
|
} from '../internals.js'
|
||||||
|
|
||||||
import * as set from 'lib0/set'
|
import * as set from 'lib0/set'
|
||||||
import * as array from 'lib0/array'
|
import * as array from 'lib0/array'
|
||||||
import * as error from 'lib0/error'
|
import * as error from 'lib0/error'
|
||||||
|
|
||||||
/**
|
|
||||||
* @template {object} Embed
|
|
||||||
* @typedef {import('../utils/Delta.js').TextDelta<Embed>} TextDelta
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {import('../utils/Delta.js').Delta} Delta
|
|
||||||
*/
|
|
||||||
|
|
||||||
const errorComputeChanges = 'You must not compute changes after the event-handler fired.'
|
const errorComputeChanges = 'You must not compute changes after the event-handler fired.'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -151,7 +142,7 @@ export class YEvent {
|
|||||||
* unexpected behavior (incorrect computation of deltas). A safe way to collect changes
|
* unexpected behavior (incorrect computation of deltas). A safe way to collect changes
|
||||||
* is to store the `changes` or the `delta` object. Avoid storing the `transaction` object.
|
* is to store the `changes` or the `delta` object. Avoid storing the `transaction` object.
|
||||||
*
|
*
|
||||||
* @type {Delta}
|
* @type {import('./Delta.js').Delta}
|
||||||
*/
|
*/
|
||||||
get delta () {
|
get delta () {
|
||||||
return this.changes.delta
|
return this.changes.delta
|
||||||
@@ -175,7 +166,7 @@ export class YEvent {
|
|||||||
* unexpected behavior (incorrect computation of deltas). A safe way to collect changes
|
* unexpected behavior (incorrect computation of deltas). A safe way to collect changes
|
||||||
* is to store the `changes` or the `delta` object. Avoid storing the `transaction` object.
|
* is to store the `changes` or the `delta` object. Avoid storing the `transaction` object.
|
||||||
*
|
*
|
||||||
* @type {{added:Set<Item>,deleted:Set<Item>,keys:Map<string,{action:'add'|'update'|'delete',oldValue:any}>,delta:Delta}}
|
* @type {{added:Set<Item>,deleted:Set<Item>,keys:Map<string,{action:'add'|'update'|'delete',oldValue:any}>,delta:import('./Delta.js').Delta}}
|
||||||
*/
|
*/
|
||||||
get changes () {
|
get changes () {
|
||||||
let changes = this._changes
|
let changes = this._changes
|
||||||
|
|||||||
Reference in New Issue
Block a user