UNPKG

lib0

Version:

isomorphic utility functions

67 lines • 3.13 kB
/** * A single step of a {@link Pos} path: a `string` attribute key, or a `number` content index. * * @typedef {string|number} PosStep */ /** * A location in a delta tree. `path` descends from the node the position is relative to and ends in * the terminal (a trailing-number cursor gap, or a trailing-string attribute leaf). `assoc` is the * gravity at a boundary: `-1` binds to the preceding content, `1` to the following content. `attrs` is * optional immutable user data carried with the position (e.g. an RDT's clientID/user metadata); it is * stored on the {@link import('./delta.js').createMark mark} when the position is written with * {@link import('./delta.js').DeltaBuilder#addMark} and read back by {@link marksToPositions}. * * @typedef {{ path: Array<PosStep>, assoc: -1|1, attrs?: object|null }} Pos */ /** * A {@link Pos} tagged with the unique id of a stored {@link import('./delta.js').createMark mark} — * what {@link marksToPositions} returns (its `attrs` is the mark's stored metadata). Add marks with * {@link import('./delta.js').DeltaBuilder#addMark}. * * @typedef {{ id: string } & Pos} MarkPos */ /** * Schema for a {@link Pos}. * * @type {s.Schema<Pos>} */ export const $pos: s.Schema<Pos>; export function create(path: Array<PosStep>, assoc?: -1 | 1, attrs?: object | null): Pos; export function equals(a: Pos | MarkPos, b: Pos | MarkPos): boolean; /** * Schema for a {@link MarkPos}. * * @type {s.Schema<MarkPos>} */ export const $markPos: s.Schema<MarkPos>; export function marksToPositions(d: delta.DeltaAny): Array<MarkPos>; export function mapPositionsA(tr: import("./transformer/core.js").Transformer<any, any>, positions: Array<Pos>): Array<Pos | null>; export function mapPositionsB(tr: import("./transformer/core.js").Transformer<any, any>, positions: Array<Pos>): Array<Pos | null>; /** * A single step of a {@link Pos} path: a `string` attribute key, or a `number` content index. */ export type PosStep = string | number; /** * A location in a delta tree. `path` descends from the node the position is relative to and ends in * the terminal (a trailing-number cursor gap, or a trailing-string attribute leaf). `assoc` is the * gravity at a boundary: `-1` binds to the preceding content, `1` to the following content. `attrs` is * optional immutable user data carried with the position (e.g. an RDT's clientID/user metadata); it is * stored on the {@link import ('./delta.js').createMark mark} when the position is written with * {@link import ('./delta.js').DeltaBuilder#addMark} and read back by {@link marksToPositions}. */ export type Pos = { path: Array<PosStep>; assoc: -1 | 1; attrs?: object | null; }; /** * A {@link Pos} tagged with the unique id of a stored {@link import ('./delta.js').createMark mark} — * what {@link marksToPositions} returns (its `attrs` is the mark's stored metadata). Add marks with * {@link import ('./delta.js').DeltaBuilder#addMark}. */ export type MarkPos = { id: string; } & Pos; import * as s from '../schema.js'; import * as delta from './delta.js'; //# sourceMappingURL=position.d.ts.map