json-joy
Version:
Collection of libraries for building collaborative editing apps.
99 lines (98 loc) • 3.1 kB
TypeScript
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);
length(): number;
/**
* 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): ITimestampStruct | undefined;
/**
* 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): Value[Index] | undefined;
/**
* @ignore
*/
put(index: number, id: ITimestampStruct): ITimestampStruct | undefined;
/**
* @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;
/** ------------------------------------------------------ {@link JsonNode} */
name(): string;
/** @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;
/** @ignore */
parent: JsonNode | undefined;
/**
* @ignore
*
* - `doc`: provided
* - `id`: shared, immutable
* - `elements`: shallow copy, elements are immutable
* - `__extNode`: not copied, will be lazily initialized
* - `_view`: not copied, will be lazily initialized
* - `api`: not copied
*/
clone(doc: Model<any>): VecNode<any>;
/** ----------------------------------------------------- {@link Printable} */
toString(tab?: string): string;
}