json-joy
Version:
Collection of libraries for building collaborative editing apps.
56 lines (55 loc) • 2.01 kB
TypeScript
import { ObjApi, VecApi } from '../../../json-crdt/model';
import type { ConNode, ObjNode, VecNode } from '../../../json-crdt/nodes';
import type { NestedType } from './NestedType';
/**
* Represents a single nested tag in a slice type. For example, in a slice type
* like `['<blockquote>', 0, {author: 'Alice'}, ['<p>', 0, {indent: 2}]]`, there
* is a tag for the blockquote and a tag for the paragraph. Each tag can
* contain a discriminant and data.
*/
export declare class NestedTag<T = string> {
protected readonly type: NestedType<T>;
readonly index: number;
constructor(type: NestedType<T>, index: number);
/**
* Enforces current tag at `index` to be a "vec" node, which contains
* a tag, a discriminant and an object with data.
*/
asVec(): VecApi<VecNode<[ConNode<number | string>, ConNode<number>, ObjNode]>>;
/**
* Returns the tag name at the current index, which is either a string or a number.
* If the tag is not set, it returns `0`.
*
* @returns The tag value.
*/
name(): string | number;
/**
* Sets the tag name at the current index. If the tag is not a string or a number,
* it will be converted to a string.
*
* @param tag - The tag value to set.
*/
setName(tag: string | number): void;
/**
* Returns the discriminant of the tag at the current index.
* If the discriminant is not set, it returns `0`.
*
* @returns The discriminant value.
*/
discriminant(): number;
/**
* Sets the discriminant of the tag at the current index.
*
* @param value - The discriminant value to set.
*/
setDiscriminant(value: number): void;
/**
* Returns the data object of the tag at the current index.
* If the data is not set, it returns an empty object. Enforces the
* data to be a {@link ObjApi} node, use this API to manipulate the data
* object.
*
* @returns The data object.
*/
data(): ObjApi;
}