UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

95 lines (94 loc) 2.59 kB
import { type ITimestampStruct } from '../../../json-crdt-patch/clock'; import type { Model } from '../../model'; import type { JsonNode, JsonNodeView } from '..'; import type { Printable } from 'tree-dump/lib/types'; import type { ExtNode } from '../../extensions/ExtNode'; import type { VecNodeExtensionData } from '../../schema/types'; /** * Represents a `vec` JSON CRDT node, which is a LWW array. * * Vector is, usually a fixed length, last-write-wins array. Each element * in the array is a reference to another JSON CRDT node. The vector * can be extended by adding new elements to the end of the array. * * @category CRDT Node */ export declare class VecNode<Value extends JsonNode[] = JsonNode[]> implements JsonNode<JsonNodeView<Value>>, Printable { /** * @ignore */ readonly doc: Model<any>; readonly id: ITimestampStruct; /** * @ignore */ readonly elements: (ITimestampStruct | undefined)[]; constructor( /** * @ignore */ doc: Model<any>, id: ITimestampStruct); /** * Retrieves the ID of an element at the given index. * * @param index Index of the element to get. * @returns ID of the element at the given index, if any. */ val(index: number): undefined | ITimestampStruct; /** * Retrieves the JSON CRDT node at the given index. * * @param index Index of the element to get. * @returns JSON CRDT node at the given index, if any. */ get<Index extends number>(index: Index): undefined | Value[Index]; /** * @ignore */ put(index: number, id: ITimestampStruct): undefined | ITimestampStruct; /** * @ignore */ private __extNode; /** * @ignore * @returns Returns the extension data node if this is an extension node, * otherwise `undefined`. The node is cached after the first access. */ ext(): VecNodeExtensionData<Value>; /** * @ignore */ isExt(): boolean; /** * @ignore * @returns Returns extension ID if this is an extension node, otherwise -1. */ getExtId(): number; /** * @ignore */ child(): ExtNode<JsonNode> | undefined; /** * @ignore */ container(): JsonNode | undefined; /** * @ignore */ children(callback: (node: JsonNode) => void): void; /** * @ignore */ private _view; /** * @ignore */ view(): JsonNodeView<Value>; /** * @ignore */ api: undefined | unknown; name(): string; toString(tab?: string): string; }