diff --git a/src/structs/ContentFormat.js b/src/structs/ContentFormat.js index eb2bd0ee..631e7755 100644 --- a/src/structs/ContentFormat.js +++ b/src/structs/ContentFormat.js @@ -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} */ (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) } diff --git a/src/types/AbstractType.js b/src/types/AbstractType.js index b9b1b44f..ac81ec7e 100644 --- a/src/types/AbstractType.js +++ b/src/types/AbstractType.js @@ -22,10 +22,10 @@ import * as math from 'lib0/math' import * as log from 'lib0/logging' /** - * @typedef {delta.ArrayDelta|delta.TextDelta|{ children: delta.ArrayDelta> }|{ children: delta.ArrayDelta, attributes: {[key:string]:{ value: any, prevValue: any, attribution: import('../utils/AttributionManager.js').Attribution } } }} YXmlDeepContent + * @typedef {delta.ArrayDelta|delta.TextDelta|{ children: delta.ArrayDelta> }|{ children: delta.ArrayDelta, attributes: {[key:string]:{ value: any, prevValue: any, attribution: import('../utils/AttributionManager.js').Attribution } } }} YXmlDeepContent */ /** - * @typedef {delta.ArrayDelta|delta.TextDelta|{ children: delta.ArrayDelta> }|{ children: delta.ArrayDelta, attributes: {[key:string]:{ value: any, prevValue: any, attribution: import('../utils/AttributionManager.js').Attribution} } }} DeepContent + * @typedef {delta.ArrayDelta|delta.TextDelta|{ children: delta.ArrayDelta> }|{ children: delta.ArrayDelta, attributes: {[key:string]:{ value: any, prevValue: any, attribution: import('../utils/AttributionManager.js').Attribution} } }} DeepContent */ /** diff --git a/src/types/YText.js b/src/types/YText.js index 79491279..f556bcba 100644 --- a/src/types/YText.js +++ b/src/types/YText.js @@ -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 + * @template {{ [key:string]:any } | AbstractType} [Embeds={ [key:string]:any } | AbstractType] + * @extends AbstractType> */ export class YText extends AbstractType { /** @@ -804,6 +804,9 @@ export class YText extends AbstractType { this._pending = null } + /** + * @return {YText} + */ _copy () { return new YText() } @@ -816,6 +819,9 @@ export class YText extends AbstractType { * @return {YText} */ clone () { + /** + * @type {YText} + */ 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} + */ const d = delta.createTextDelta() /** * @type {Array>} diff --git a/src/utils/AttributionManager.js b/src/utils/AttributionManager.js index ecdf61e7..8f10ece0 100644 --- a/src/utils/AttributionManager.js +++ b/src/utils/AttributionManager.js @@ -11,8 +11,7 @@ import { diffIdMap, createIdMap, createAttributionItem, - mergeIdMaps, - AttributionItem + mergeIdMaps } from '../internals.js' import * as error from 'lib0/error' diff --git a/src/utils/Delta.js b/src/utils/Delta.js index f8ff0089..d7a9b8a5 100644 --- a/src/utils/Delta.js +++ b/src/utils/Delta.js @@ -5,17 +5,17 @@ import * as error from 'lib0/error' /** * @template {any} ArrayContent - * @template {{[key: string]: any}} Embeds + * @template {object} Embeds * @typedef {InsertStringOp|InsertEmbedOp|InsertArrayOp|RetainOp|DeleteOp} DeltaOp */ /** - * @template {{[key: string]: any}} Embeds + * @template {object} Embeds * @typedef {InsertStringOp|InsertEmbedOp|RetainOp|DeleteOp} TextDeltaOp */ /** - * @template {any} ArrayContent + * @template ArrayContent * @typedef {InsertArrayOp|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} [TDeltaOp=DeltaOp] + * @template {'array' | 'text' | 'custom'} Type + * @template {DeltaOp} TDeltaOp * @extends AbstractDelta */ export class DeltaBuilder extends AbstractDelta { @@ -353,7 +353,7 @@ export class DeltaBuilder extends AbstractDelta { } /** - * @param {(TDeltaOp extends TextDelta ? string | Embeds : never) | (TDeltaOp extends InsertArrayOp ? Array : never) } insert + * @param {(TDeltaOp extends InsertStringOp ? string : never) | (TDeltaOp extends InsertEmbedOp ? (Embeds) : never) | (TDeltaOp extends InsertArrayOp ? Array : 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} + * @template {object} Embeds + * @return {TextDelta} */ export const createTextDelta = () => new TextDelta() /** - * @return {ArrayDelta} + * @template [V=any] + * @return {ArrayDelta} */ export const createArrayDelta = () => new ArrayDelta() diff --git a/src/utils/YEvent.js b/src/utils/YEvent.js index 725ffb20..40000441 100644 --- a/src/utils/YEvent.js +++ b/src/utils/YEvent.js @@ -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} TextDelta */ /** @@ -50,7 +51,7 @@ export class YEvent { */ this._keys = null /** - * @type {TextDelta?} + * @type {TextDelta?} */ this._delta = null /** diff --git a/tests/y-array.tests.js b/tests/y-array.tests.js index faad66c4..4eaab5d2 100644 --- a/tests/y-array.tests.js +++ b/tests/y-array.tests.js @@ -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)) }) } diff --git a/tests/y-text.tests.js b/tests/y-text.tests.js index acd4f286..b0607279 100644 --- a/tests/y-text.tests.js +++ b/tests/y-text.tests.js @@ -1804,7 +1804,7 @@ export const testTypesAsEmbed = tc => { text0.applyDelta([{ insert: new Y.Map([['key', 'val']]) }]) - t.compare(/** @type {delta.InsertOp} */ (text0.getContent().ops[0]).insert.toJSON(), { key: 'val' }) + t.compare(/** @type {delta.InsertEmbedOp} */ (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} + * @type {Array>} */ 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) diff --git a/tests/y-xml.tests.js b/tests/y-xml.tests.js index 251a0c38..a0c0611c 100644 --- a/tests/y-xml.tests.js +++ b/tests/y-xml.tests.js @@ -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: [] } } })