json-joy
Version:
Collection of libraries for building collaborative editing apps.
57 lines (56 loc) • 2.96 kB
TypeScript
import { ValueSyncStore } from '../../../../util/events/sync-store';
import { type LeafBlock, type Peritext } from '../../../../json-crdt-extensions';
import { BehaviorSubject } from 'rxjs';
import { type ITimestampStruct } from '../../../../json-crdt-patch';
import { SliceTypeCon } from '../../../../json-crdt-extensions/peritext/slice/constants';
import { NewFormatting } from './formattings';
import type { UiLifeCycles } from '../../../web/types';
import type { PeritextSurfaceState } from '../../../web';
import type { MenuItem } from '../types';
import type { ToolbarPluginOpts } from '../ToolbarPlugin';
import type { BufferDetail, PeritextEventDetailMap } from '../../../../json-crdt-extensions/peritext/events';
export declare class ToolbarState implements UiLifeCycles {
readonly surface: PeritextSurfaceState;
readonly opts: ToolbarPluginOpts;
readonly txt: Peritext;
lastEvent: PeritextEventDetailMap['change']['ev'] | undefined;
lastEventTs: number;
readonly showInlineToolbar: ValueSyncStore<[show: boolean, time: number]>;
/**
* New slice configuration. This is used for new slices which are not yet
* applied to the text as they need to be configured first.
*/
readonly newSlice: ValueSyncStore<NewFormatting<import("../../../..").ObjNode<Record<string, import("../../../..").JsonNode<unknown>>>> | undefined>;
/**
* The ID of the active (where the main cursor or focus is placed) leaf block.
*/
readonly activeLeafBlockId$: BehaviorSubject<ITimestampStruct | null>;
constructor(surface: PeritextSurfaceState, opts: ToolbarPluginOpts);
private _setActiveLeafBlockId;
private setLastEv;
startSliceConfig(tag: SliceTypeCon | string | number, menu?: MenuItem): NewFormatting | undefined;
/** ------------------------------------------- {@link UiLifeCycles} */
start(): () => void;
readonly getFormattingMenu: () => MenuItem;
readonly colorMenuItem: () => MenuItem;
readonly linkMenuItem: () => MenuItem;
readonly annotationsMenu: () => MenuItem;
readonly modifyMenu: () => MenuItem;
readonly copyAsMenu: (action: "copy" | "cut", ctx?: ClipboardMenuCtx) => MenuItem;
readonly pasteAsMenu: (ctx?: ClipboardMenuCtx) => MenuItem;
readonly copyMenu: (ctx?: ClipboardMenuCtx) => MenuItem;
readonly cutMenu: (ctx?: ClipboardMenuCtx) => MenuItem;
readonly pasteMenu: (ctx?: ClipboardMenuCtx) => MenuItem;
readonly clipboardMenu: (ctx?: ClipboardMenuCtx) => MenuItem;
readonly getCaretMenu: () => MenuItem;
readonly getSelectionMenu: () => MenuItem;
readonly blockTypeMenu: () => MenuItem;
readonly leafBlockSmallMenu: (ctx: LeafBlockMenuCtx) => MenuItem;
}
export interface LeafBlockMenuCtx {
block: LeafBlock<string>;
}
export interface ClipboardMenuCtx {
hideStyleActions?: boolean;
onBeforeAction?: (item: MenuItem, action: 'cut' | 'copy' | 'paste') => void | Partial<BufferDetail>;
}