From 5000fe58f92f24745c6a93125fffbed42afecdfe Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Mon, 23 Jun 2025 15:04:59 +0200 Subject: [PATCH] export createDelta --- src/internals.js | 1 + src/types/YText.js | 2 +- src/utils/AttributionManager.js | 2 +- src/utils/Delta.js | 24 ++++++++++++------------ src/utils/YEvent.js | 15 +++------------ 5 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/internals.js b/src/internals.js index 6d98c851..d487ce14 100644 --- a/src/internals.js +++ b/src/internals.js @@ -19,6 +19,7 @@ export * from './utils/YEvent.js' export * from './utils/StructSet.js' export * from './utils/IdMap.js' export * from './utils/AttributionManager.js' +export * from './utils/Delta.js' export * from './types/AbstractType.js' export * from './types/YArray.js' diff --git a/src/types/YText.js b/src/types/YText.js index 5ba588b8..45e34f74 100644 --- a/src/types/YText.js +++ b/src/types/YText.js @@ -1090,7 +1090,7 @@ export class YText extends AbstractType { // # Update Attributions 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 changedAttributedAttributes = /** @type {{ [key: string]: Array }} */ (formattingAttribution.attributes = object.assign({}, formattingAttribution.attributes ?? {})) diff --git a/src/utils/AttributionManager.js b/src/utils/AttributionManager.js index d75c1df9..a5bb81f2 100644 --- a/src/utils/AttributionManager.js +++ b/src/utils/AttributionManager.js @@ -77,7 +77,7 @@ export const createAttributionFromAttributionItems = (attrs, deleted) => { // eslint-disable-next-line no-fallthrough case 'insert': 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] ?? [] ls.push(attr.val) break diff --git a/src/utils/Delta.js b/src/utils/Delta.js index d5fc0dd1..cf9c5476 100644 --- a/src/utils/Delta.js +++ b/src/utils/Delta.js @@ -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 { /** * @param {string} insert * @param {FormattingAttributes|null} attributes - * @param {Attribution|null} attribution + * @param {Attribution_|null} attribution */ constructor (insert, attributes, attribution) { this.insert = insert @@ -73,7 +73,7 @@ export class InsertArrayOp { /** * @param {Array} insert * @param {FormattingAttributes|null} attributes - * @param {Attribution|null} attribution + * @param {Attribution_|null} attribution */ constructor (insert, attributes, attribution) { this.insert = insert @@ -107,7 +107,7 @@ export class InsertEmbedOp { /** * @param {Embeds} insert * @param {FormattingAttributes|null} attributes - * @param {Attribution|null} attribution + * @param {Attribution_|null} attribution */ constructor (insert, attributes, attribution) { this.insert = insert @@ -165,7 +165,7 @@ export class RetainOp { /** * @param {number} retain * @param {FormattingAttributes|null} attributes - * @param {Attribution|null} attribution + * @param {Attribution_|null} attribution */ constructor (retain, attributes, attribution) { this.retain = retain @@ -286,7 +286,7 @@ export class DeltaBuilder extends AbstractDelta { */ this.usedAttributes = null /** - * @type {Attribution?} + * @type {Attribution_?} */ this.usedAttribution = null /** @@ -323,9 +323,9 @@ export class DeltaBuilder extends AbstractDelta { } /** - * @template {keyof Attribution} NAME + * @template {keyof Attribution_} NAME * @param {NAME} name - * @param {Attribution[NAME]?} value + * @param {Attribution_[NAME]?} value */ updateUsedAttribution (name, value) { if (value == null) { @@ -342,7 +342,7 @@ export class DeltaBuilder extends AbstractDelta { } /** - * @param {Attribution?} attribution + * @param {Attribution_?} attribution */ useAttribution (attribution) { this.usedAttribution = attribution @@ -352,7 +352,7 @@ export class DeltaBuilder extends AbstractDelta { /** * @param {(TDeltaOp extends InsertStringOp ? string : never) | (TDeltaOp extends InsertEmbedOp ? (Embeds) : never) | (TDeltaOp extends InsertArrayOp ? Array : never) } insert * @param {FormattingAttributes?} attributes - * @param {Attribution?} attribution + * @param {Attribution_?} attribution * @return {this} */ insert (insert, attributes = null, attribution = null) { @@ -377,7 +377,7 @@ export class DeltaBuilder extends AbstractDelta { /** * @param {number} retain * @param {FormattingAttributes?} attributes - * @param {Attribution?} attribution + * @param {Attribution_?} attribution * @return {this} */ retain (retain, attributes = null, attribution = null) { diff --git a/src/utils/YEvent.js b/src/utils/YEvent.js index 4a49ec90..3827fb18 100644 --- a/src/utils/YEvent.js +++ b/src/utils/YEvent.js @@ -1,20 +1,11 @@ import { - Item, AbstractType, Transaction, AbstractStruct // eslint-disable-line + TextDelta, Item, AbstractType, Transaction, AbstractStruct // eslint-disable-line } from '../internals.js' import * as set from 'lib0/set' import * as array from 'lib0/array' import * as error from 'lib0/error' -/** - * @template {object} Embed - * @typedef {import('../utils/Delta.js').TextDelta} TextDelta - */ - -/** - * @typedef {import('../utils/Delta.js').Delta} Delta - */ - 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 * is to store the `changes` or the `delta` object. Avoid storing the `transaction` object. * - * @type {Delta} + * @type {import('./Delta.js').Delta} */ get delta () { return this.changes.delta @@ -175,7 +166,7 @@ export class YEvent { * 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. * - * @type {{added:Set,deleted:Set,keys:Map,delta:Delta}} + * @type {{added:Set,deleted:Set,keys:Map,delta:import('./Delta.js').Delta}} */ get changes () { let changes = this._changes