UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

89 lines (88 loc) 3.83 kB
import { Point } from '../rga/Point'; import { Range } from '../rga/Range'; import { SliceStacking } from './constants'; import { type Model, type NodeApi, ObjApi, VecApi } from '../../../json-crdt/model'; import { type ObjNode, type VecNode } from '../../../json-crdt/nodes'; import { NestedType } from './NestedType'; import type { ITimestampStruct } from '../../../json-crdt-patch/clock'; import type { ArrChunk, JsonNode } from '../../../json-crdt/nodes'; import type { MutableSlice, SliceType, SliceUpdateParams, SliceTypeSteps } from './types'; import type { Stateful } from '../types'; import type { Printable } from 'tree-dump/lib/types'; import type { AbstractRga } from '../../../json-crdt/nodes/rga'; import type { Peritext } from '../Peritext'; import type { Slices } from './Slices'; /** * A persisted slice is a slice that is stored in a {@link Model}. It is used for * rich-text formatting and annotations. * * @todo Maybe rename to "saved", "stored", "mutable". */ export declare class PersistedSlice<T = string> extends Range<T> implements MutableSlice<T>, Stateful, Printable { /** The `Model` where the slice is stored. */ protected readonly model: Model; /** The Peritext context. */ protected readonly txt: Peritext<T>; /** The `arr` chunk of `arr` where the slice is stored. */ protected readonly chunk: ArrChunk; /** The `vec` node which stores the serialized contents of this slice. */ readonly tuple: VecNode; start: Point<T>; end: Point<T>; static deserialize<T>(model: Model, txt: Peritext<T>, chunk: ArrChunk, tuple: VecNode): PersistedSlice<T>; /** @todo Use API node here. */ protected readonly rga: AbstractRga<T>; constructor( /** The `Model` where the slice is stored. */ model: Model, /** The Peritext context. */ txt: Peritext<T>, /** The `arr` chunk of `arr` where the slice is stored. */ chunk: ArrChunk, /** The `vec` node which stores the serialized contents of this slice. */ tuple: VecNode, stacking: SliceStacking, start: Point<T>, end: Point<T>); isSplit(): boolean; protected tupleApi(): VecApi<VecNode<any>>; set(start: Point<T>, end?: Point<T>): void; /** * Expand range left and right to contain all invisible space: (1) tombstones, * (2) anchors of non-deleted adjacent chunks. */ expand(): void; /** -------------------------------------------------- {@link MutableSlice} */ readonly id: ITimestampStruct; stacking: SliceStacking; update(params: SliceUpdateParams<T>): void; getStore(): Slices<T> | undefined; del(): void; isDel(): boolean; typeNode(): JsonNode<unknown> | undefined; typeApi(): NodeApi<JsonNode<unknown>> | undefined; nestedType(): NestedType<T>; type(): SliceType; typeSteps(): SliceTypeSteps; data(): unknown | undefined; dataNode(): NodeApi<JsonNode<unknown>> | undefined; dataAsObj(): ObjApi<ObjNode>; /** * Overwrites the data of this slice with the given data. * * @param data Data to set for this slice. The data can be any JSON value, but * it is recommended to use an object. */ setData(data: unknown): void; /** * Merges object data into the slice's data using JSON CRDT diffing. * * @param data Data to merge into the slice. If the data is an object, it will be * merged with the existing data of the slice using JSON CRDT diffing. */ mergeData(data: unknown): void; /** ------------------------------------------------------ {@link Stateful} */ hash: number; refresh(): number; /** ----------------------------------------------------- {@link Printable} */ toStringName(): string; protected toStringHeaderName(): string; toStringHeader(tab?: string): string; }