@y/y
Version:
Shared Editing Library
521 lines • 22.4 kB
TypeScript
export function warnPrematureAccess(): void;
export function createAttributionFromAttributionItems(attrs: Array<ContentAttribute<any>> | null, deleted: boolean): Attribution | null;
export class ItemTextListPosition {
/**
* @param {Item|null} left
* @param {Item|null} right
* @param {number} index
* @param {Map<string,any>} currentAttributes
* @param {AbstractAttributionManager} am
*/
constructor(left: Item | null, right: Item | null, index: number, currentAttributes: Map<string, any>, am: AbstractAttributionManager);
left: Item | null;
right: Item | null;
index: number;
currentAttributes: Map<string, any>;
am: import("./utils/attribution-manager-helpers.js").AbstractAttributionManager;
/**
* Only call this if you know that this.right is defined
*/
forward(): void;
/**
* @param {Transaction} transaction
* @param {YType} parent
* @param {number} length
* @param {Object<string,any>} attributes
*
* @function
*/
formatText(transaction: Transaction, parent: YType, length: number, attributes: {
[x: string]: any;
}): void;
}
export function insertContent(transaction: Transaction, parent: YType, currPos: ItemTextListPosition, content: import("./structs/Item.js").AbstractContent, attributes: {
[x: string]: any;
}): void;
export function insertContentHelper(transaction: Transaction, parent: YType, currPos: ItemTextListPosition, insert: Array<any> | string, attributes: {
[x: string]: any;
}): void;
export function deleteText(transaction: Transaction, currPos: ItemTextListPosition, length: number): ItemTextListPosition;
export class ArraySearchMarker {
/**
* @param {Item} p
* @param {number} index
*/
constructor(p: Item, index: number);
p: Item;
index: number;
timestamp: number;
}
export function findMarker(yarray: YType, index: number): ArraySearchMarker | null;
export function updateMarkerChanges(searchMarker: Array<ArraySearchMarker>, index: number, len: number): void;
export function getTypeChildren(t: YType): Array<Item>;
export function callTypeObservers(type: YType, transaction: Transaction, event: YEvent<any>): void;
/**
* Abstract Yjs Type class
* @template {delta.DeltaConf} [DConf=any]
*/
export class YType<DConf extends delta.DeltaConf = any> {
/**
* @template {delta.DeltaConf} DC
* @param {delta.Delta<DC>} d
* @return {YType<DC>}
*/
static from<DC extends delta.DeltaConf>(d: delta.Delta<DC>): YType<DC>;
/**
* @param {delta.DeltaConfGetName<DConf>?} name
*/
constructor(name?: delta.DeltaConfGetName<DConf> | null);
/**
* @type {delta.DeltaConfGetName<DConf>}
*/
name: delta.DeltaConfGetName<DConf>;
/**
* @type {Item|null}
*/
_item: Item | null;
/**
* @type {Map<string,Item>}
*/
_map: Map<string, Item>;
/**
* @type {Item|null}
*/
_start: Item | null;
/**
* @type {Doc|null}
*/
doc: Doc | null;
_length: number;
/**
* Event handlers
* @type {EventHandler<YEvent<DeltaToYType<DConf>>,Transaction>}
*/
_eH: EventHandler<YEvent<DeltaToYType<DConf>>, Transaction>;
/**
* Deep event handlers
* @type {EventHandler<YEvent<DConf>,Transaction>}
*/
_dEH: EventHandler<YEvent<DConf>, Transaction>;
/**
* @type {null | Array<ArraySearchMarker>}
*/
_searchMarker: null | Array<ArraySearchMarker>;
/**
* @type {delta.DeltaBuilder<DConf>}
* @private
*/
private _content;
_legacyTypeRef: number;
/**
* Whether this YText contains formatting attributes.
* This flag is updated when a formatting item is integrated (see ContentFormat.integrate)
*/
_hasFormatting: boolean;
get length(): number;
/**
* Returns a fresh delta that can be used to change this YType.
* @type {delta.DeltaBuilder<DeltaToYType<DConf>>}
*/
get change(): delta.DeltaBuilder<DeltaToYType<DConf>>;
/**
* @return {YType<any>?}
*/
get parent(): YType<any> | null;
/**
* Integrate this type into the Yjs instance.
*
* * Save this struct in the os
* * This type is sent to other client
* * Observer functions are fired
*
* @param {Doc} y The Yjs instance
* @param {Item|null} item
*/
_integrate(y: Doc, item: Item | null): void;
_prelim: any;
/**
* @return {YType<DConf>}
*/
_copy(): YType<DConf>;
/**
* Creates YEvent and calls all type observers.
* Must be implemented by each type.
*
* @param {Transaction} transaction
* @param {Set<null|string>} parentSubs Keys changed on this type. `null` if list was modified.
*/
_callObserver(transaction: Transaction, parentSubs: Set<null | string>): void;
/**
* Observe all events that are created on this type.
*
* @template {(target: YEvent<DeltaToYType<DConf>>, tr: Transaction) => void} F
* @param {F} f Observer function
* @return {F}
*/
observe<F extends (target: YEvent<DeltaToYType<DConf>>, tr: Transaction) => void>(f: F): F;
/**
* Observe all events that are created by this type and its children.
*
* @template {function(YEvent<DConf>,Transaction):void} F
* @param {F} f Observer function
* @return {F}
*/
observeDeep<F extends (arg0: YEvent<DConf>, arg1: Transaction) => void>(f: F): F;
/**
* Unregister an observer function.
*
* @param {(type:YEvent<DeltaToYType<DConf>>,tr:Transaction)=>void} f Observer function
*/
unobserve(f: (type: YEvent<DeltaToYType<DConf>>, tr: Transaction) => void): void;
/**
* Unregister an observer function.
*
* @param {function(YEvent<DConf>,Transaction):void} f Observer function
*/
unobserveDeep(f: (arg0: YEvent<DConf>, arg1: Transaction) => void): void;
/**
* Render the difference to another ydoc (which can be empty) and highlight the differences with
* attributions.
*
* Note that deleted content that was not deleted in prevYdoc is rendered as an insertion with the
* attribution `{ isDeleted: true, .. }`.
*
* @template {boolean} [Deep=false]
*
* @param {AbstractAttributionManager} am
* @param {Object} [opts]
* @param {IdSet?} [opts.itemsToRender]
* @param {boolean} [opts.retainInserts] - if true, retain rendered inserts with attributions
* @param {boolean} [opts.retainDeletes] - if true, retain rendered+attributed deletes only
* @param {IdSet?} [opts.deletedItems] - used for computing prevItem in attributes
* @param {Map<YType,Set<string|null>>|null} [opts.modified] - set of types that should be rendered as modified children
* @param {Deep} [opts.deep] - render child types as delta
* @return {Deep extends true ? delta.Delta<DConf> : delta.Delta<DeltaConfDeltaToYType<DConf>>} The Delta representation of this type.
*
* @public
*/
public toDelta<Deep extends boolean = false>(am?: AbstractAttributionManager, opts?: {
itemsToRender?: import("./utils/ids.js").IdSet | null | undefined;
retainInserts?: boolean | undefined;
retainDeletes?: boolean | undefined;
deletedItems?: import("./utils/ids.js").IdSet | null | undefined;
modified?: Map<YType<any>, Set<string | null>> | null | undefined;
deep?: Deep | undefined;
}): Deep extends true ? delta.Delta<DConf> : delta.Delta<DeltaConfDeltaToYType<DConf>>;
/**
* Render the difference to another ydoc (which can be empty) and highlight the differences with
* attributions.
*
* @param {AbstractAttributionManager} am
* @return {delta.Delta<DConf>}
*/
toDeltaDeep(am?: AbstractAttributionManager): delta.Delta<DConf>;
/**
* Apply a {@link Delta} on this shared type.
*
* @param {delta.DeltaAny} d The changes to apply on this element.
* @param {AbstractAttributionManager} am
*
* @public
*/
public applyDelta(d: delta.DeltaAny, am?: AbstractAttributionManager): this;
/**
* Makes a copy of this data type that can be included somewhere else.
*
* Note that the content is only readable _after_ it has been included somewhere in the Ydoc.
*
* @return {YType<DConf>}
*/
clone(): YType<DConf>;
/**
* Removes all elements from this YMap.
*/
clearAttrs(): void;
/**
* Removes an attribute from this YXmlElement.
*
* @param {string} attributeName The attribute name that is to be removed.
*
* @public
*/
public deleteAttr(attributeName: string): void;
/**
* Sets or updates an attribute.
*
* @template {Exclude<keyof delta.DeltaConfGetAttrs<DConf>,symbol>} KEY
* @template {delta.DeltaConfGetAttrs<DConf>[KEY]} VAL
*
* @param {KEY} attributeName The attribute name that is to be set.
* @param {VAL} attributeValue The attribute value that is to be set.
* @return {VAL}
*
* @public
*/
public setAttr<KEY extends Exclude<keyof delta.DeltaConfGetAttrs<DConf>, symbol>, VAL extends delta.DeltaConfGetAttrs<DConf>[KEY]>(attributeName: KEY, attributeValue: VAL): VAL;
/**
* Returns an attribute value that belongs to the attribute name.
*
* @template {Exclude<keyof delta.DeltaConfGetAttrs<DConf>,symbol|number>} KEY
* @param {KEY} attributeName The attribute name that identifies the queried value.
* @return {delta.DeltaConfGetAttrs<DConf>[KEY]|undefined} The queried attribute value.
* @public
*/
public getAttr<KEY extends Exclude<keyof delta.DeltaConfGetAttrs<DConf>, symbol | number>>(attributeName: KEY): delta.DeltaConfGetAttrs<DConf>[KEY] | undefined;
/**
* Returns whether an attribute exists
*
* @param {string} attributeName The attribute name to check for existence.
* @return {boolean} whether the attribute exists.
*
* @public
*/
public hasAttr(attributeName: string): boolean;
/**
* Returns all attribute name/value pairs in a JSON Object.
*
* @param {Snapshot} [snapshot]
* @return {{ [Key in Extract<keyof delta.DeltaConfGetAttrs<DConf>,string>]?: delta.DeltaConfGetAttrs<DConf>[Key]}} A JSON Object that describes the attributes.
*
* @public
*/
public getAttrs(snapshot?: Snapshot): { [Key in Extract<keyof delta.DeltaConfGetAttrs<DConf>, string>]?: delta.DeltaConfGetAttrs<DConf>[Key]; };
/**
* Inserts new content at an index.
*
* Important: This function expects an array of content. Not just a content
* object. The reason for this "weirdness" is that inserting several elements
* is very efficient when it is done as a single operation.
*
* @example
* // Insert character 'a' at position 0
* yarray.insert(0, ['a'])
* // Insert numbers 1, 2 at position 1
* yarray.insert(1, [1, 2])
*
* @param {number} index The index to insert content at.
* @param {Array<delta.DeltaConfGetChildren<DConf>>|delta.DeltaConfGetText<DConf>} content Array of content to append.
* @param {delta.FormattingAttributes} [format]
*/
insert(index: number, content: Array<delta.DeltaConfGetChildren<DConf>> | delta.DeltaConfGetText<DConf>, format?: delta.FormattingAttributes): void;
/**
* Inserts new content at an index.
*
* Important: This function expects an array of content. Not just a content
* object. The reason for this "weirdness" is that inserting several elements
* is very efficient when it is done as a single operation.
*
* @example
* // Insert character 'a' at position 0
* yarray.insert(0, ['a'])
* // Insert numbers 1, 2 at position 1
* yarray.insert(1, [1, 2])
*
* @param {number} index The index to insert content at.
* @param {number} length The index to insert content at.
* @param {delta.FormattingAttributes} formats
*
*/
format(index: number, length: number, formats: delta.FormattingAttributes): void;
/**
* Appends content to this YArray.
*
* @param {Array<delta.DeltaConfGetChildren<DConf>>|delta.DeltaConfGetText<DConf>} content Array of content to append.
*
* @todo Use the following implementation in all types.
*/
push(content: Array<delta.DeltaConfGetChildren<DConf>> | delta.DeltaConfGetText<DConf>): void;
/**
* Prepends content to this YArray.
*
* @param {delta.DeltaConfGetText<DConf>} content Array of content to prepend.
*/
unshift(content: delta.DeltaConfGetText<DConf>): void;
/**
* Deletes elements starting from an index.
*
* @param {number} index Index at which to start deleting elements
* @param {number} length The number of elements to remove. Defaults to 1.
*/
delete(index: number, length?: number): void;
/**
* Returns the i-th element from a YArray.
*
* @param {number} index The index of the element to return from the YArray
* @return {delta.DeltaConfGetChildren<DConf>}
*/
get(index: number): delta.DeltaConfGetChildren<DConf>;
/**
* Returns a portion of this YXmlFragment into a JavaScript Array selected
* from start to end (end not included).
*
* @param {number} [start]
* @param {number} [end]
* @return {Array<delta.DeltaConfGetChildren<DConf>>}
*/
slice(start?: number, end?: number): Array<delta.DeltaConfGetChildren<DConf>>;
/**
* @todo refactor this, this should use getContent only!
*
* Transforms this YArray to a JavaScript Array.
*
* @return {Array<delta.DeltaConfGetChildren<DConf> | delta.DeltaConfGetText<DConf>>}
*/
toArray(): Array<delta.DeltaConfGetChildren<DConf> | delta.DeltaConfGetText<DConf>>;
/**
* Transforms this Shared Type to a JSON object.
* @return {{ name?: string, attrs?: { [K:string|number]: any }, children?: Array<any> }}
*/
toJSON(): {
name?: string;
attrs?: {
[K: string | number]: any;
};
children?: Array<any>;
};
/**
* @param {object} opts
* @param {boolean} [opts.forceTag] enforce creating a surrouning <name /> tag, even if it is null.
*/
toString({ forceTag }?: {
forceTag?: boolean | undefined;
}): string;
/**
* Returns an Array with the result of calling a provided function on every
* child-element.
*
* @template M
* @param {(child:delta.DeltaConfGetChildren<DConf>|delta.DeltaConfGetText<DConf>,index:number)=>M} f Function that produces an element of the new Array
* @return {Array<M>} A new array with each element being the result of the
* callback function
*/
map<M>(f: (child: delta.DeltaConfGetChildren<DConf> | delta.DeltaConfGetText<DConf>, index: number) => M): Array<M>;
/**
* Executes a provided function once on every element of this YArray.
*
* @param {(child:delta.DeltaConfGetChildren<DConf>|delta.DeltaConfGetText<DConf>,index:number)=>any} f Function that produces an element of the new Array
*/
forEach(f: (child: delta.DeltaConfGetChildren<DConf> | delta.DeltaConfGetText<DConf>, index: number) => any): void;
/**
* Executes a provided function on once on every key-value pair.
*
* @param {(val:delta.DeltaConfGetAttrs<DConf>[any],key:Exclude<keyof delta.DeltaConfGetAttrs<DConf>,symbol>,ytype:this)=>any} f
*/
forEachAttr(f: (val: delta.DeltaConfGetAttrs<DConf>[any], key: Exclude<keyof delta.DeltaConfGetAttrs<DConf>, symbol>, ytype: this) => any): void;
/**
* Returns the keys for each element in the YMap Type.
*
* @return {IterableIterator<import('lib0/ts').KeyOf<delta.DeltaConfGetAttrs<DConf>>>}
*/
attrKeys(): IterableIterator<import("lib0/ts").KeyOf<delta.DeltaConfGetAttrs<DConf>>>;
/**
* Returns the values for each element in the YMap Type.
*
* @return {IterableIterator<delta.DeltaConfGetAttrs<DConf>[any]>}
*/
attrValues(): IterableIterator<delta.DeltaConfGetAttrs<DConf>[any]>;
/**
* Returns an Iterator of [key, value] pairs
*
* @return {IterableIterator<{ [K in keyof delta.DeltaConfGetAttrs<DConf>]: [K,delta.DeltaConfGetAttrs<DConf>[K]] }[any]>}
*/
attrEntries(): IterableIterator<{ [K in keyof delta.DeltaConfGetAttrs<DConf>]: [K, delta.DeltaConfGetAttrs<DConf>[K]]; }[any]>;
/**
* Returns the number of stored attributes (count of key/value pairs)
*
* @return {number}
*/
get attrSize(): number;
/**
* @todo this doesn't need to live in a method.
*
* Transform the properties of this type to binary and write it to an
* BinaryEncoder.
*
* This is called when this Item is sent to a remote peer.
*
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to.
*/
_write(encoder: UpdateEncoderV1 | UpdateEncoderV2): void;
/**
* @param {this} other
*/
[traits.EqualityTraitSymbol](other: this): boolean;
}
export function $ytype<DConf extends import("lib0/delta").ReadableDeltaConf>(_dconf: DConf): s.Schema<YType<import("lib0/delta").ReadDeltaConf<DConf>>>;
export const $ytypeAny: s.Schema<YType<any>>;
export function equalAttrs(a: any, b: any): boolean;
export function typeListSlice(type: YType<any>, start: number, end: number): Array<any>;
export function typeListGet(type: YType, index: number): any;
export function typeListInsertGenericsAfter(transaction: Transaction, parent: YType, referenceItem: Item | null, content: Array<YValue>): void;
export function typeListInsertGenerics(transaction: Transaction, parent: YType, index: number, content: Array<{
[x: string]: any;
} | Array<any> | number | null | string | Uint8Array>): void;
export function typeListPushGenerics(transaction: Transaction, parent: YType, content: Array<{
[x: string]: any;
} | Array<any> | number | null | string | Uint8Array>): void;
export function typeListDelete(transaction: Transaction, parent: YType, index: number, length: number): void;
export function typeMapDelete(transaction: Transaction, parent: YType, key: string): void;
export function typeMapSet(transaction: Transaction, parent: YType, key: string, value: YValue): void;
export function typeMapGet(parent: YType<any>, key: string): {
[x: string]: any;
} | number | null | Array<any> | string | Uint8Array | YType<any> | undefined;
export function typeMapGetAll(parent: YType<any>): {
[x: string]: string | number | any[] | YType<any> | Uint8Array<ArrayBufferLike> | {
[x: string]: any;
} | null | undefined;
};
export function typeMapGetDelta<TypeDelta extends delta.DeltaBuilderAny>(d: TypeDelta, parent: YType, attrsToRender: Set<string | null> | null, am: AbstractAttributionManager, deep: boolean, modified?: Set<YType> | Map<YType, any> | null, deletedItems?: IdSet | null, itemsToRender?: IdSet | null, opts?: any, optsAll?: any): void;
export function typeMapHas(parent: YType<any>, key: string): boolean;
export function isVisible(item: Item, snapshot: Snapshot | undefined): boolean;
export function typeMapGetSnapshot(parent: YType<any>, key: string, snapshot: Snapshot): {
[x: string]: any;
} | number | null | Array<any> | string | Uint8Array | YType<any> | undefined;
export function typeMapGetAllSnapshot(parent: YType<any>, snapshot: Snapshot): {
[x: string]: string | number | any[] | YType<any> | Uint8Array<ArrayBufferLike> | {
[x: string]: any;
} | null | undefined;
};
export function createMapIterator(type: YType<any> & {
_map: Map<string, Item>;
}): IterableIterator<Array<any>>;
export function readContentType(decoder: UpdateDecoderV1 | UpdateDecoderV2): ContentType;
export function readContentString(decoder: UpdateDecoderV1 | UpdateDecoderV2): ContentString;
export function readContentJSON(decoder: UpdateDecoderV1 | UpdateDecoderV2): ContentJSON;
export function readContentFormat(decoder: UpdateDecoderV1 | UpdateDecoderV2): ContentFormat;
export function readContentEmbed(decoder: UpdateDecoderV1 | UpdateDecoderV2): ContentEmbed;
export function readContentDoc(decoder: UpdateDecoderV1 | UpdateDecoderV2): ContentDoc;
export function readContentAny(decoder: UpdateDecoderV1 | UpdateDecoderV2): ContentAny;
export function readContentBinary(decoder: UpdateDecoderV1 | UpdateDecoderV2): ContentBinary;
export function readContentDeleted(decoder: UpdateDecoderV1 | UpdateDecoderV2): ContentDeleted;
/**
* A lookup map for reading Item content.
*
* @type {Array<function(UpdateDecoderV1 | UpdateDecoderV2):AbstractContent>}
*/
export const contentRefs: Array<(arg0: UpdateDecoderV1 | UpdateDecoderV2) => AbstractContent>;
export function readItemContent(decoder: UpdateDecoderV1 | UpdateDecoderV2, info: number): import("./structs/Item.js").AbstractContent;
export function readYType(decoder: UpdateDecoderV1 | UpdateDecoderV2): YType;
export type YValue = {
[x: string]: any;
} | Array<any> | number | null | string | Uint8Array | bigint | YType<any>;
export type DeltaConfDeltaToYType<DConf extends delta.DeltaConf> = delta.DeltaConfOverwrite<DConf, {
attrs: { [K in keyof delta.DeltaConfGetAttrs<DConf>]: DeltaToYType<delta.DeltaConfGetAttrs<DConf>[K]>; };
children: DeltaToYType<delta.DeltaConfGetChildren<DConf>>;
}>;
export type DeltaToYType<Data extends unknown> = Exclude<Data, delta.DeltaAny> | (Extract<Data, delta.DeltaAny> extends delta.Delta<infer DConf> ? (unknown extends DConf ? YType<DConf> : never) : never);
import { Item } from './structs/Item.js';
import { YEvent } from './utils/YEvent.js';
import * as delta from 'lib0/delta';
import * as traits from 'lib0/traits';
import * as s from 'lib0/schema';
import { ContentType } from './structs/Item.js';
import { ContentString } from './structs/Item.js';
import { ContentJSON } from './structs/Item.js';
import { ContentFormat } from './structs/Item.js';
import { ContentEmbed } from './structs/Item.js';
import { ContentDoc } from './structs/Item.js';
import { ContentAny } from './structs/Item.js';
import { ContentBinary } from './structs/Item.js';
import { ContentDeleted } from './structs/Item.js';
//# sourceMappingURL=ytype.d.ts.map