import { DynamicViewDisplayVariant, NodeNotation as ElementNotation, ViewChange } from '@likec4/core/types'; import { RefObject } from 'react'; import { PartialDeep } from 'type-fest'; import { FeatureName } from '../../context/DiagramFeatures'; import { OpenSourceParams } from '../../LikeC4Diagram.props'; import { OverlaysActorRef } from '../../overlays/overlaysActor'; import { Types } from '../types'; import { AlignmentMode } from './aligners'; import { DiagramActorRef, DiagramContext, DiagramEvents } from './types'; import type * as t from '@likec4/core/types'; type Any = t.aux.Any; type Unknown = t.aux.UnknownLayouted; type ViewId = t.aux.ViewId; type Fqn = t.aux.Fqn; type NodeId = t.aux.NodeId; type EdgeId = t.aux.EdgeId; export interface DiagramApi { /** * React ref to the diagram actor */ readonly ref: RefObject; /** * @warning Do not use in render phase */ readonly actor: DiagramActorRef; /** * @warning Do not use in render phase */ readonly currentView: t.DiagramView; overlays(): OverlaysActorRef; /** * Send event to diagram actor */ send(event: DiagramEvents): void; /** * Navigate to view * @param viewId - Target view ID * @param fromNode - Node from which navigation was triggered * @param focusOnElement - Element FQN to focus after navigation (from search) */ navigateTo(viewId: ViewId, fromNode?: NodeId, focusOnElement?: Fqn): void; /** * Navigate back or forward in history */ navigate(direction: 'back' | 'forward'): void; /** * Fit diagram to view */ fitDiagram(duration?: number): void; /** * Open relationships browser */ openRelationshipsBrowser(fqn: Fqn): void; /** * If running in editor, trigger opening source file */ openSource(params: OpenSourceParams): void; /** * Open element details card */ openElementDetails(fqn: Fqn, fromNode?: NodeId): void; openRelationshipDetails(...params: [edgeId: EdgeId] | [source: Fqn, target: Fqn]): void; updateNodeData(nodeId: NodeId, data: PartialDeep): void; updateEdgeData(edgeId: EdgeId, data: PartialDeep): void; highlightNode(nodeId: NodeId): void; highlightEdge(edgeId: EdgeId): void; unhighlightAll(): void; /** * Center viewport on a given node */ centerViewportOnNode(target: NodeId): void; /** * Center viewport on a given edge (centering on edge means including both source and target nodes in view) */ centerViewportOnEdge(target: EdgeId): void; /** * Start editing, either node or edge */ startEditing(subject: 'node' | 'edge'): void; /** * Stop editing * @param wasChanged - whether there were changes made during editing * @default false */ stopEditing(wasChanged?: boolean): void; /** * Undo last editing operation * @returns true if there was something to undo */ undoEditing(): boolean; /** * Align nodes */ align(mode: AlignmentMode): void; /** * Reset edge control points */ resetEdgeControlPoints(): void; /** * Focus node */ focusNode(nodeId: NodeId): void; /** * Focus on element by FQN (finds the node and focuses on it). * Used by search to highlight an element on the current view. */ focusOnElement(elementFqn: Fqn): void; /** * @warning Do not use in render phase */ getContext(): DiagramContext; /** * @warning Do not use in render phase */ findDiagramNode(xynodeId: string): t.DiagramNode | null; /** * @warning Do not use in render phase */ findEdge(xyedgeId: string): Types.Edge | null; /** * @warning Do not use in render phase */ findDiagramEdge(xyedgeId: string): t.DiagramEdge | null; startWalkthrough(): void; walkthroughStep(direction?: 'next' | 'previous'): void; stopWalkthrough(): void; toggleFeature(feature: FeatureName, forceValue?: boolean): void; highlightNotation(notation: ElementNotation, kind?: string): void; unhighlightNotation(): void; openSearch(searchValue?: string): void; triggerChange(viewChange: ViewChange): void; /** * Switch dynamic view display variant */ switchDynamicViewVariant(variant: DynamicViewDisplayVariant): void; } export declare function makeDiagramApi(actorRef: RefObject): DiagramApi; export {};