@atlaskit/editor-plugin-block-controls
Version:
Block controls plugin for @atlaskit/editor-core
47 lines (46 loc) • 2.18 kB
TypeScript
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
import type { DecorationSet, EditorView } from '@atlaskit/editor-prosemirror/view';
import type { SurfaceDescriptor } from './block-controls-surface-descriptors';
export type SurfaceSnapshot = {
readonly forceVisibleOnMouseOut: boolean;
readonly left: readonly SurfaceDescriptor[];
readonly revision: number;
readonly right: readonly SurfaceDescriptor[];
};
/**
* Keeps anchor decorations in step with the block-control surfaces React renders.
* - An anchor stays until React has committed a tree that no longer uses it.
* - Surfaces whose anchor is gone (deleted block, drag, limited mode) are left out of the snapshot,
* so React removes them before the browser paints.
*/
export declare class SurfaceLifecycle {
private published;
private snapshot;
private committedRevision;
private revision;
private lastUsedRevision;
private listeners;
private availableAnchors;
private publishedAnchors;
private decorations;
private suppressed;
private onCommit;
getSnapshot: () => SurfaceSnapshot | undefined;
subscribe: (listener: () => void) => (() => void);
setOnCommit(onCommit: () => void): void;
publish(snapshot: Omit<SurfaceSnapshot, 'revision'>, anchors: ReadonlyMap<number, string>): void;
acknowledge: (revision: number) => void;
retainAnchors(doc: PMNode, desired: DecorationSet, previous: DecorationSet): DecorationSet;
/** Whether a reconcile would drop anchors that no committed or pending tree still uses. */
hasRetirableAnchors(decorations: DecorationSet): boolean;
private isRetained;
/**
* Records which anchors the browser can currently resolve. Removes surfaces for missing or
* suppressed anchors from the snapshot synchronously, ahead of the next reconcile.
*/
updateAnchors(decorations: DecorationSet, suppressed: boolean): void;
/** Derives the snapshot React reads, replacing it only when the rendered surfaces change. */
private updateSnapshot;
destroy(): void;
}
export declare const getSurfaceLifecycle: (view: EditorView) => SurfaceLifecycle;