json-joy
Version:
Collection of libraries for building collaborative editing apps.
101 lines (100 loc) • 4.5 kB
TypeScript
import { Range } from '../rga/Range';
import { ChunkSlice } from '../util/ChunkSlice';
import { Cursor } from '../editor/Cursor';
import type { Point } from '../rga/Point';
import type { OverlayPoint } from '../overlay/OverlayPoint';
import type { Printable } from 'tree-dump/lib/types';
import type { Peritext } from '../Peritext';
import type { Slice } from '../slice/types';
import type { PeritextMlNode } from './types';
export declare abstract class AbstractInlineAttr<T = string> {
slice: Slice<T>;
constructor(slice: Slice<T>);
/** @returns Whether the attribute starts at the start of the inline. */
isStart(): boolean;
/** @returns Whether the attribute ends at the end of the inline. */
isEnd(): boolean;
/** @returns Whether the attribute is collapsed to a point. */
isCollapsed(): boolean;
}
/** The attribute started before this inline and ends after this inline. */
export declare class InlineAttrPassing<T = string> extends AbstractInlineAttr<T> {
}
/** The attribute starts at the beginning of this inline. */
export declare class InlineAttrStart<T = string> extends AbstractInlineAttr<T> {
isStart(): boolean;
}
/** The attribute ends at the end of this inline. */
export declare class InlineAttrEnd<T = string> extends AbstractInlineAttr<T> {
isEnd(): boolean;
}
/** The attribute starts and ends in this inline, exactly contains it. */
export declare class InlineAttrContained<T = string> extends AbstractInlineAttr<T> {
isStart(): boolean;
isEnd(): boolean;
}
/** The attribute is collapsed at start of this inline. */
export declare class InlineAttrStartPoint<T = string> extends AbstractInlineAttr<T> {
isStart(): boolean;
isCollapsed(): boolean;
}
/** The attribute is collapsed at end of this inline. */
export declare class InlineAttrEndPoint<T = string> extends AbstractInlineAttr<T> {
isEnd(): boolean;
isCollapsed(): boolean;
}
export type InlineAttr<T = string> = InlineAttrPassing<T> | InlineAttrStart<T> | InlineAttrEnd<T> | InlineAttrContained<T> | InlineAttrStartPoint<T> | InlineAttrEndPoint<T>;
export type InlineAttrStack<T = string> = InlineAttr<T>[];
export type InlineAttrs<T = string> = Record<string | number, InlineAttrStack<T>>;
/**
* The `Inline` class represents a range of inline text within a block, which
* has the same annotations and formatting for all of its text contents, i.e.
* its text contents can be rendered as a single (`<span>`) element. However,
* the text contents might still be composed of multiple {@link ChunkSlice}s,
* which are the smallest units of text and need to be concatenated to get the
* full text content of the inline.
*/
export declare class Inline<T = string> extends Range<T> implements Printable {
readonly txt: Peritext<T>;
readonly p1: OverlayPoint<T>;
readonly p2: OverlayPoint<T>;
constructor(txt: Peritext<T>, p1: OverlayPoint<T>, p2: OverlayPoint<T>, start: Point<T>, end: Point<T>);
/**
* @returns A stable unique identifier of this *inline* within a list of other
* inlines of the parent block. Can be used for UI libraries to track the
* identity of the inline across renders.
*/
key(): number;
/**
* @returns The position of the inline within the text.
*/
pos(): number;
protected createAttr(slice: Slice<T>): InlineAttr<T>;
private _attr;
/**
* @returns Returns the attributes of the inline, which are the slice
* annotations and formatting applied to the inline.
*
* @todo Rename to `.stat()`.
* @todo Create a more efficient way to compute inline stats, separate: (1)
* boolean flags, (2) cursor, (3) other attributes.
*/
attr(): InlineAttrs<T>;
hasCursor(): boolean;
/** @todo Make this return a list of cursors. */
cursorStart(): Cursor | undefined;
cursorEnd(): Cursor | undefined;
/**
* Returns a 2-tuple if this inline is part of a selection. The 2-tuple sides
* specify how selection ends on each side. Empty string means the selection
* continues past that edge, `focus` and `anchor` specify that the edge
* is either a focus caret or an anchor, respectively.
*
* @returns Selection state of this inline.
*/
selection(): undefined | [left: 'anchor' | 'focus' | '', right: 'anchor' | 'focus' | ''];
texts(limit?: number): ChunkSlice<T>[];
toJson(): PeritextMlNode;
toStringName(): string;
toString(tab?: string): string;
}