lint & fix tests

This commit is contained in:
Kevin Jahns
2025-05-07 22:43:23 +02:00
parent cb191e744e
commit fc620617df
9 changed files with 51 additions and 39 deletions

View File

@@ -67,24 +67,24 @@ export class ContentFormat {
*/
integrate (_transaction, item) {
// @todo searchmarker are currently unsupported for rich text documents
const p = /** @type {YText} */ (item.parent)
const p = /** @type {YText<any>} */ (item.parent)
p._searchMarker = null
p._hasFormatting = true
}
/**
* @param {Transaction} transaction
* @param {Transaction} _transaction
*/
delete (transaction) {}
delete (_transaction) {}
/**
* @param {StructStore} store
* @param {StructStore} _store
*/
gc (store) {}
gc (_store) {}
/**
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
* @param {number} offset
* @param {number} _offset
*/
write (encoder, offset) {
write (encoder, _offset) {
encoder.writeKey(this.key)
encoder.writeJSON(this.value)
}

View File

@@ -22,10 +22,10 @@ import * as math from 'lib0/math'
import * as log from 'lib0/logging'
/**
* @typedef {delta.ArrayDelta|delta.TextDelta|{ children: delta.ArrayDelta<Array<YXmlDeepContent>> }|{ children: delta.ArrayDelta, attributes: {[key:string]:{ value: any, prevValue: any, attribution: import('../utils/AttributionManager.js').Attribution } } }} YXmlDeepContent
* @typedef {delta.ArrayDelta<any>|delta.TextDelta<any>|{ children: delta.ArrayDelta<Array<YXmlDeepContent>> }|{ children: delta.ArrayDelta<any>, attributes: {[key:string]:{ value: any, prevValue: any, attribution: import('../utils/AttributionManager.js').Attribution } } }} YXmlDeepContent
*/
/**
* @typedef {delta.ArrayDelta|delta.TextDelta|{ children: delta.ArrayDelta<Array<DeepContent>> }|{ children: delta.ArrayDelta, attributes: {[key:string]:{ value: any, prevValue: any, attribution: import('../utils/AttributionManager.js').Attribution} } }} DeepContent
* @typedef {delta.ArrayDelta<any>|delta.TextDelta<any>|{ children: delta.ArrayDelta<Array<DeepContent>> }|{ children: delta.ArrayDelta<any>, attributes: {[key:string]:{ value: any, prevValue: any, attribution: import('../utils/AttributionManager.js').Attribution} } }} DeepContent
*/
/**

View File

@@ -755,8 +755,8 @@ export class YTextEvent extends YEvent {
* block formats (format information on a paragraph), embeds (complex elements
* like pictures and videos), and text formats (**bold**, *italic*).
*
* @template {any} Embeds
* @extends AbstractType<YTextEvent>
* @template {{ [key:string]:any } | AbstractType<any>} [Embeds={ [key:string]:any } | AbstractType<any>]
* @extends AbstractType<YTextEvent<Embeds>>
*/
export class YText extends AbstractType {
/**
@@ -804,6 +804,9 @@ export class YText extends AbstractType {
this._pending = null
}
/**
* @return {YText<Embeds>}
*/
_copy () {
return new YText()
}
@@ -816,6 +819,9 @@ export class YText extends AbstractType {
* @return {YText<Embeds>}
*/
clone () {
/**
* @type {YText<Embeds>}
*/
const text = new YText()
text.applyDelta(this.getContent())
return text
@@ -944,6 +950,9 @@ export class YText extends AbstractType {
*/
getContent (am = noAttributionsManager) {
this.doc ?? warnPrematureAccess()
/**
* @type {delta.TextDelta<Embeds>}
*/
const d = delta.createTextDelta()
/**
* @type {Array<import('../internals.js').AttributedContent<any>>}

View File

@@ -11,8 +11,7 @@ import {
diffIdMap,
createIdMap,
createAttributionItem,
mergeIdMaps,
AttributionItem
mergeIdMaps
} from '../internals.js'
import * as error from 'lib0/error'

View File

@@ -5,17 +5,17 @@ import * as error from 'lib0/error'
/**
* @template {any} ArrayContent
* @template {{[key: string]: any}} Embeds
* @template {object} Embeds
* @typedef {InsertStringOp|InsertEmbedOp<Embeds>|InsertArrayOp<ArrayContent>|RetainOp|DeleteOp} DeltaOp
*/
/**
* @template {{[key: string]: any}} Embeds
* @template {object} Embeds
* @typedef {InsertStringOp|InsertEmbedOp<Embeds>|RetainOp|DeleteOp} TextDeltaOp
*/
/**
* @template {any} ArrayContent
* @template ArrayContent
* @typedef {InsertArrayOp<ArrayContent>|RetainOp|DeleteOp} ArrayDeltaOp
*/
@@ -101,7 +101,7 @@ export class InsertArrayOp {
}
/**
* @template {{[key: string]: any}} Embeds
* @template {object} Embeds
*/
export class InsertEmbedOp {
/**
@@ -274,8 +274,8 @@ const mergeAttrs = (a, b) => {
}
/**
* @template {'array' | 'text' | 'custom'} [Type='custom']
* @template {DeltaOp<any,any>} [TDeltaOp=DeltaOp<any,any>]
* @template {'array' | 'text' | 'custom'} Type
* @template {DeltaOp<any,any>} TDeltaOp
* @extends AbstractDelta<Type,TDeltaOp>
*/
export class DeltaBuilder extends AbstractDelta {
@@ -353,7 +353,7 @@ export class DeltaBuilder extends AbstractDelta {
}
/**
* @param {(TDeltaOp extends TextDelta<infer Embeds> ? string | 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 {Attribution?} attribution
* @return {this}
@@ -362,6 +362,7 @@ export class DeltaBuilder extends AbstractDelta {
const mergedAttributes = mergeAttrs(this.usedAttributes, attributes)
const mergedAttribution = mergeAttrs(this.usedAttribution, attribution)
if (((this.lastOp instanceof InsertStringOp && insert.constructor === String) || (this.lastOp instanceof InsertArrayOp && insert.constructor === Array)) && (mergedAttributes === this.lastOp.attributes || fun.equalityDeep(mergedAttributes, this.lastOp.attributes)) && (mergedAttribution === this.lastOp.attribution || fun.equalityDeep(mergedAttribution, this.lastOp.attribution))) {
// @ts-ignore
if (insert.constructor === String) {
// @ts-ignore
this.lastOp.insert += insert
@@ -441,12 +442,14 @@ export class TextDelta extends DeltaBuilder {
}
/**
* @return {TextDelta<TextDeltaContent>}
* @template {object} Embeds
* @return {TextDelta<Embeds>}
*/
export const createTextDelta = () => new TextDelta()
/**
* @return {ArrayDelta<any>}
* @template [V=any]
* @return {ArrayDelta<V>}
*/
export const createArrayDelta = () => new ArrayDelta()

View File

@@ -7,7 +7,8 @@ import * as array from 'lib0/array'
import * as error from 'lib0/error'
/**
* @typedef {import('../utils/Delta.js').TextDelta} TextDelta
* @template {object} Embed
* @typedef {import('../utils/Delta.js').TextDelta<Embed>} TextDelta
*/
/**
@@ -50,7 +51,7 @@ export class YEvent {
*/
this._keys = null
/**
* @type {TextDelta?}
* @type {TextDelta<any>?}
*/
this._delta = null
/**

View File

@@ -530,7 +530,7 @@ export const testAttributedContent = _tc => {
})
const expectedContent = delta.createArrayDelta().insert([1], null, { delete: [] }).insert([2]).insert([42], null, { insert: [] })
const attributedContent = yarray.getContent(attributionManager)
console.log(attributedContent.toJSON().ops)
console.log(attributedContent.toJSON())
t.assert(attributedContent.equals(expectedContent))
})
}

View File

@@ -1804,7 +1804,7 @@ export const testTypesAsEmbed = tc => {
text0.applyDelta([{
insert: new Y.Map([['key', 'val']])
}])
t.compare(/** @type {delta.InsertOp<any>} */ (text0.getContent().ops[0]).insert.toJSON(), { key: 'val' })
t.compare(/** @type {delta.InsertEmbedOp<any>} */ (text0.getContent().ops[0]).insert.toJSON(), { key: 'val' })
let firedEvent = false
text1.observe(event => {
const d = event.delta
@@ -1944,7 +1944,7 @@ export const testFormattingDeltaUnnecessaryAttributeChange = tc => {
})
testConnector.flushAllMessages()
/**
* @type {Array<delta.TextDelta>}
* @type {Array<delta.TextDelta<any>>}
*/
const deltas = []
text0.observe(event => {
@@ -2262,14 +2262,14 @@ export const testAttributedContent = _tc => {
ytext.applyDelta([{ retain: 4, attributes: { italic: true } }, { retain: 2 }, { delete: 5 }, { insert: 'attributions' }])
const expectedContent = delta.createTextDelta().insert('Hell', { italic: true }, { attributes: { italic: [] } }).insert('o ').insert('World', {}, { delete: [] }).insert('attributions', {}, { insert: [] }).insert('!')
const attributedContent = ytext.getContent(attributionManager)
console.log(attributedContent.toJSON().ops)
console.log(attributedContent.toJSON())
t.assert(attributedContent.equals(expectedContent))
})
t.group('unformat', () => {
ytext.applyDelta([{ retain: 5, attributes: { italic: null } }])
const expectedContent = delta.createTextDelta().insert('Hell', null, { attributes: { italic: [] } }).insert('o attributions!')
const attributedContent = ytext.getContent(attributionManager)
console.log(attributedContent.toJSON().ops)
console.log(attributedContent.toJSON())
t.assert(attributedContent.equals(expectedContent))
})
}
@@ -2300,7 +2300,7 @@ export const testAttributedDiffing = _tc => {
const attributionManager = new TwosetAttributionManager(attributedInsertions, attributedDeletions)
// we render the attributed content with the attributionManager
const attributedContent = ytext.getContent(attributionManager)
console.log(JSON.stringify(attributedContent.toJSON().ops, null, 2))
console.log(JSON.stringify(attributedContent.toJSON(), null, 2))
const expectedContent = delta.createTextDelta().insert('Hell', { italic: true }, { attributes: { italic: ['Bob'] } }).insert('o ').insert('World', {}, { delete: ['Bob'] }).insert('attributions', {}, { insert: ['Bob'] }).insert('!')
t.assert(attributedContent.equals(expectedContent))
console.log(Y.encodeIdMap(attributedInsertions).length)

View File

@@ -245,7 +245,7 @@ export const testFragmentAttributedContent = _tc => {
})
const expectedContent = delta.createArrayDelta().insert([elem1], null, { delete: [] }).insert([elem2]).insert([elem3], null, { insert: [] })
const attributedContent = yfragment.getContent(attributionManager)
console.log(attributedContent.children.toJSON().ops)
console.log(attributedContent.children.toJSON())
t.assert(attributedContent.children.equals(expectedContent))
t.compare(elem1.getContent(attributionManager).toJSON(), delta.createTextDelta().insert('hello', null, { delete: [] }).done().toJSON())
})
@@ -274,7 +274,7 @@ export const testElementAttributedContent = _tc => {
})
const expectedContent = delta.createArrayDelta().insert([elem1], null, { delete: [] }).insert([elem2]).insert([elem3], null, { insert: [] })
const attributedContent = yelement.getContent(attributionManager)
console.log('children', attributedContent.children.toJSON().ops)
console.log('children', attributedContent.children.toJSON())
console.log('attributes', attributedContent.attributes)
t.assert(attributedContent.children.equals(expectedContent))
t.compare(attributedContent.attributes, { key: { prevValue: undefined, value: '42', attribution: { insert: [] } } })
@@ -288,8 +288,8 @@ export const testElementAttributedContent = _tc => {
delta.createTextDelta().insert('world', null, { insert: [] })
], null, { insert: [] })
const attributedContent = yelement.getContentDeep(attributionManager)
console.log('children', JSON.stringify(attributedContent.children.toJSON().ops, null, 2))
console.log('cs expec', JSON.stringify(expectedContent.toJSON().ops, null, 2))
console.log('children', JSON.stringify(attributedContent.children.toJSON(), null, 2))
console.log('cs expec', JSON.stringify(expectedContent.toJSON(), null, 2))
console.log('attributes', attributedContent.attributes)
t.assert(attributedContent.children.equals(expectedContent))
t.compare(attributedContent.attributes, { key: { prevValue: undefined, value: '42', attribution: { insert: [] } } })
@@ -317,7 +317,7 @@ export const testElementAttributedContentViaDiffer = _tc => {
const attributionManager = Y.createAttributionManagerFromDiff(ydocV1, ydoc)
const expectedContent = delta.createArrayDelta().insert([delta.createTextDelta().insert('hello', null, { delete: [] })], null, { delete: [] }).insert([elem2.getContentDeep()]).insert([delta.createTextDelta().insert('world', null, { insert: [] })], null, { insert: [] })
const attributedContent = yelement.getContentDeep(attributionManager)
console.log('children', attributedContent.children.toJSON().ops)
console.log('children', attributedContent.children.toJSON())
console.log('attributes', attributedContent.attributes)
t.assert(attributedContent.children.equals(expectedContent))
t.compare(attributedContent.attributes, { key: { prevValue: undefined, value: '42', attribution: { insert: [] } } })
@@ -331,8 +331,8 @@ export const testElementAttributedContentViaDiffer = _tc => {
delta.createTextDelta().insert('world', null, { insert: [] })
], null, { insert: [] })
const attributedContent = yelement.getContentDeep(attributionManager)
console.log('children', JSON.stringify(attributedContent.children.toJSON().ops, null, 2))
console.log('cs expec', JSON.stringify(expectedContent.toJSON().ops, null, 2))
console.log('children', JSON.stringify(attributedContent.children.toJSON(), null, 2))
console.log('cs expec', JSON.stringify(expectedContent.toJSON(), null, 2))
console.log('attributes', attributedContent.attributes)
t.assert(attributedContent.children.equals(expectedContent))
t.compare(attributedContent.attributes, { key: { prevValue: undefined, value: '42', attribution: { insert: [] } } })
@@ -352,8 +352,8 @@ export const testElementAttributedContentViaDiffer = _tc => {
delta.createTextDelta().insert('bigworld', null, { insert: [] })
], null, { insert: [] })
const attributedContent = yelement.getContentDeep(attributionManager)
console.log('children', JSON.stringify(attributedContent.children.toJSON().ops, null, 2))
console.log('cs expec', JSON.stringify(expectedContent.toJSON().ops, null, 2))
console.log('children', JSON.stringify(attributedContent.children.toJSON(), null, 2))
console.log('cs expec', JSON.stringify(expectedContent.toJSON(), null, 2))
console.log('attributes', attributedContent.attributes)
t.assert(attributedContent.children.equals(expectedContent))
t.compare(attributedContent.attributes, { key: { prevValue: undefined, value: '42', attribution: { insert: [] } } })