UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

54 lines (53 loc) 2.59 kB
import { Model, ObjApi } from '../../../../json-crdt/model'; import type { Range } from '../../../../json-crdt-extensions/peritext/rga/Range'; import type { ToolbarSliceBehavior, ValidationResult } from '../types'; import type { SliceBehavior } from '../../../../json-crdt-extensions/peritext/registry/SliceBehavior'; import type { ObjNode } from '../../../../json-crdt/nodes'; import type { ToolbarState } from '.'; import type { PersistedSlice } from '../../../../json-crdt-extensions/peritext/slice/PersistedSlice'; export interface FormattingBase<B extends SliceBehavior<any, any, any, any>, R extends Range<string>> { behavior: B; range: R; } export interface FormattingWithConfig<Node extends ObjNode = ObjNode> { conf(): ObjApi<Node> | undefined; } export interface ToolbarFormatting<R extends Range<string> = Range<string>, Node extends ObjNode = ObjNode> extends FormattingBase<ToolbarSliceBehavior, R>, FormattingWithConfig<Node> { } export declare abstract class EditableFormatting<R extends Range<string> = Range<string>, Node extends ObjNode = ObjNode> implements ToolbarFormatting<R, Node> { readonly behavior: ToolbarSliceBehavior; readonly range: R; readonly state: ToolbarState; constructor(behavior: ToolbarSliceBehavior, range: R, state: ToolbarState); conf(): ObjApi<Node> | undefined; validate(): ValidationResult; } /** * Formatting is a specific application of known formatting option to a range of * text. Formatting is composed of a specific {@link Slice} which stores the * state (location, data) of the formatting and a {@link ToolbarSliceBehavior} * which defines the formatting behavior. */ export declare class SavedFormatting<Node extends ObjNode = ObjNode> extends EditableFormatting<PersistedSlice<string>, Node> { /** * @returns Unique key for this formatting. This is the hash of the slice. * This is used to identify the formatting in the UI. */ key(): number; conf(): ObjApi<Node> | undefined; } /** * New formatting which is being created. Once created, it will be promoted to * a {@link SavedFormatting} instance. */ export declare class NewFormatting<Node extends ObjNode = ObjNode> extends EditableFormatting<Range<string>, Node> { readonly behavior: ToolbarSliceBehavior; readonly range: Range<string>; readonly state: ToolbarState; readonly model: Model<ObjNode<{ conf: any; }>>; constructor(behavior: ToolbarSliceBehavior, range: Range<string>, state: ToolbarState); conf(): ObjApi<Node> | undefined; readonly save: () => void; }