import { ComponentProps as ComponentProps_2 } from 'react'; import { DotObjectModel } from 'ts-graphviz'; import { EdgeAttributesObject } from '@ts-graphviz/common'; import { EdgeModel } from '@ts-graphviz/common'; import { EdgeModel as EdgeModel_2 } from 'ts-graphviz'; import { EdgeTargetLikeTuple } from '@ts-graphviz/common'; import { EdgeTargetLikeTuple as EdgeTargetLikeTuple_2 } from 'ts-graphviz'; import { FC } from 'react'; import { FilterableModel } from 'ts-graphviz'; import { GraphAttributesObject } from '@ts-graphviz/common'; import { GraphBaseModel } from '@ts-graphviz/common'; import { GraphBaseModel as GraphBaseModel_2 } from 'ts-graphviz'; import { HasComment } from '@ts-graphviz/common'; import { HTMLLikeLabel } from '@ts-graphviz/common'; import { isAttributeListModel } from 'ts-graphviz'; import { isEdgeModel } from 'ts-graphviz'; import { isNodeModel } from 'ts-graphviz'; import { isRootGraphModel } from 'ts-graphviz'; import { isSubgraphModel } from 'ts-graphviz'; import { NodeAttributesObject } from '@ts-graphviz/common'; import { NodeModel } from '@ts-graphviz/common'; import { NodeModel as NodeModel_2 } from 'ts-graphviz'; import { ReactElement } from 'react'; import { ReactNode } from 'react'; import { Ref } from 'react'; import { RootGraphModel } from 'ts-graphviz'; import { SubgraphAttributesObject } from '@ts-graphviz/common'; import { SubgraphModel } from 'ts-graphviz'; /** * Type that represents any graph-like container that can be used for rendering. * This includes both base interfaces (GraphBaseModel) and root graph interfaces (RootGraphModel). * Since Graph and Digraph implement RootGraphModel, they are covered by this union. */ export declare type AnyGraphContainer = GraphBaseModel_2 | RootGraphModel; /** * Props for Graphviz components */ export declare type ComponentProps = ComponentProps_2; /** * React component type for Graphviz elements */ export declare type ComponentType = FC; /** * Create a Graphviz root for rendering React elements to Graphviz models * @param options - Options for creating the root, including optional container */ export declare function createRoot(options?: CreateRootOptions): GraphvizRoot; /** * Options for creating a Graphviz root */ export declare interface CreateRootOptions { /** * Container graph for rendering components. * When provided, components will be rendered into this existing graph model. */ container?: Container; /** * Called when an error is not caught by any error boundary */ onUncaughtError?: (error: Error, errorInfo: ErrorInfo) => void; /** * Called when an error is caught by an error boundary */ onCaughtError?: (error: Error, errorInfo: ErrorInfo) => void; /** * Called when React automatically recovers from errors */ onRecoverableError?: (error: Error, errorInfo: ErrorInfo) => void; /** * Called when rendering completes successfully */ onRenderComplete?: (models: DotObjectModel[]) => void; /** * Timeout for async rendering in milliseconds * @default 5000 */ timeout?: number; } /** * `Digraph` component. */ export declare const Digraph: FC; /** * JSX intrinsic elements for dot:* HTML-like elements. * These type definitions are automatically available when importing @ts-graphviz/react. */ export declare interface DotJSXElements { 'dot:port': { children: string; }; 'dot:table': HTMLLikeLabel.TableAttributes & { children?: ReactNode; }; 'dot:tr': HTMLLikeLabel.TrAttributes & { children?: ReactNode; }; 'dot:td': HTMLLikeLabel.TdAttributes & { children?: ReactNode; }; 'dot:font': HTMLLikeLabel.FontAttributes & { children?: ReactNode; }; 'dot:br': HTMLLikeLabel.BrAttributes; 'dot:img': HTMLLikeLabel.ImgAttributes; 'dot:i': HTMLLikeLabel.IAttributes & { children?: ReactNode; }; 'dot:b': HTMLLikeLabel.BAttributes & { children?: ReactNode; }; 'dot:u': HTMLLikeLabel.UAttributes & { children?: ReactNode; }; 'dot:o': HTMLLikeLabel.OAttributes & { children?: ReactNode; }; 'dot:sub': HTMLLikeLabel.SubAttributes & { children?: ReactNode; }; 'dot:sup': HTMLLikeLabel.SupAttributes & { children?: ReactNode; }; 'dot:s': HTMLLikeLabel.SAttributes & { children?: ReactNode; }; 'dot:hr': HTMLLikeLabel.HrAttributes; 'dot:vr': HTMLLikeLabel.VrAttributes; } /** * `Edge` component. */ export declare const Edge: FC; /** Options for Edge */ export declare interface EdgeOptions extends EdgeAttributesObject { } /** Props for Edge component */ export declare interface EdgeProps extends Omit { /** Edge targets */ targets: EdgeTargetLikeTuple; /** Edge label */ label?: ReactElement | string; ref?: Ref; } /** * Error information for React error handling */ export declare interface ErrorInfo { componentStack?: string; } export { FilterableModel } /** * `Graph` component. */ export declare const Graph: FC; /** Common attribute values of objects under cluster */ export declare interface GraphBaseAttributesProps { /** Attribute value for Edges */ edge?: EdgeAttributesObject; /** Attribute value for Nodes */ node?: NodeAttributesObject; /** Attribute value for Graphs */ graph?: SubgraphAttributesObject; } /** * GraphPortal component. */ export declare const GraphPortal: FC; /** Props for GraphPortal component */ export declare interface GraphPortalProps { /** * id of the cluster you want to target for the portal. * If not specified, target the cluster that is the container to the portal. */ id?: string; children?: ReactNode; } /** * Graphviz root interface */ export declare interface GraphvizRoot { /** * Render a React element asynchronously */ render(element: ReactElement): Promise; /** * Unmount the root and cleanup resources */ unmount(): void; /** * Get all top-level models that were rendered (no type parameters) * @returns Array of rendered models. In container mode, returns all non-container models. * In non-container mode, returns top-level graph models. */ getTopLevelModels(): DotObjectModel[]; /** * Get top-level models with generic type casting or type guard filtering * * @overload@overload * When called with a type guard function, filters models by type using runtime type checking * @param typeGuard - Type guard function to filter models * @returns Array of models matching the specified type * * @overload@overload * When called with only a generic type parameter, casts all models to the specified type (trusted user assertion) * @returns Array of models cast to the specified type T * * @example * ```typescript * // Runtime type filtering with type guard * const nodes = root.getTopLevelModels(isNodeModel); * * // Direct type casting (user knows the type) * const nodes = root.getTopLevelModels(); * ``` */ getTopLevelModels(typeGuard?: (model: DotObjectModel) => model is T): T[]; } export { isAttributeListModel } export { isEdgeModel } export { isNodeModel } export { isRootGraphModel } export { isSubgraphModel } /** * `Node` component. */ export declare const Node: FC; /** Options for Node */ export declare interface NodeOptions extends NodeAttributesObject { } /** Props for Node component */ export declare interface NodeProps extends Omit { /** Node id */ id: string; /** Node label */ label?: ReactElement | string; /** Node xlabel */ xlabel?: ReactElement | string; ref?: Ref; } export { ReactNode } /** * Converts a React element into a custom HTML-like string representation. * * If no {@link label} is provided, returns the string '<>'. Otherwise, renders the React element to static markup, transforms any `dot:`-prefixed tags by removing the prefix, and wraps the result in angle brackets. * * @param label - Optional React element to render. * @param options - Optional rendering options. * @returns A string representing the transformed HTML-like markup. * * @example * ```ts * // Default behavior (max depth: 1000) * renderHTMLLike(
Hello
); * * // Custom max depth for deeply nested structures * renderHTMLLike(
...
, { maxDepth: 5000 }); * * // Lower max depth for strict validation * renderHTMLLike(
...
, { maxDepth: 100 }); * ``` */ export declare function renderHTMLLike(label?: ReactElement, options?: RenderHTMLLikeOptions): string; /** * Options for controlling the rendering behavior. */ export declare interface RenderHTMLLikeOptions { /** * Maximum allowed recursion depth to prevent stack overflow attacks. * @default 1000 */ maxDepth?: number; } /** * Converts the given React element to DOT language asynchronously. * * This function creates a Graphviz root, renders the element, and returns the DOT representation. * * @example Single top-level graph * ```tsx * const dot = await renderToDot( * * * * * * ); * console.log(dot); * // digraph "example" { * // "a"; * // "b"; * // "a" -> "b"; * // } * ``` * * @example With container * ```tsx * const container = new DigraphModel('main'); * const dot = await renderToDot( * <> * * * * * * , * { container } * ); * console.log(dot); * // digraph "main" { * // "a"; * // subgraph "cluster_sub" { * // "b"; * // } * // "a" -> "b"; * // } * ``` */ export declare function renderToDot(element: ReactElement, options?: RenderToDotOptions): Promise; /** * Rendering options for renderToDot */ export declare interface RenderToDotOptions extends CreateRootOptions { /** * Container graph to render into. When provided, the element will be rendered * as children of this container and the container's DOT will be returned. */ container?: Container; } /** Options for RootGraph */ export declare interface RootGraphOptions extends GraphAttributesObject, GraphBaseAttributesProps { /** Cluster id */ id?: string; } /** Props for RootGraph component */ export declare interface RootGraphProps extends Omit { label?: ReactElement | string; children?: ReactNode; ref?: Ref; } /** * `Subgraph` component. */ export declare const Subgraph: FC; /** Options for Subgraph */ export declare interface SubgraphOptions extends SubgraphAttributesObject, GraphBaseAttributesProps, HasComment { /** Cluster id */ id?: string; } /** Props for Subgraph component */ export declare interface SubgraphProps extends Omit { /** Subgraph label */ label?: ReactElement | string; children?: ReactNode; ref?: Ref; } export declare type TopLevelModel = FilterableModel; /** * Hook to get the current cluster(Digraph, Graph or Subgraph). * * @throws If it is out of the context of Cluster, it throws an exception. */ export declare function useCurrentGraph(): AnyGraphContainer; /** * `useDigraph` is a hook that creates an instance of Digraph * according to the object given by props. */ export declare function useDigraph(options?: RootGraphOptions): RootGraphModel; /** * `useEdge` is a hook that creates an instance of Edge * according to the object given by props. */ export declare function useEdge(targets: EdgeTargetLikeTuple_2, props?: EdgeOptions): EdgeModel_2; /** * `useGraph` is a hook that creates an instance of Graph * according to the object given by props. */ export declare function useGraph(options?: RootGraphOptions): RootGraphModel; /** * Return the cluster of container. */ export declare function useGraphContainer(): AnyGraphContainer | null; /** * `useNode` is a hook that creates an instance of Node * according to the object given by props. */ export declare function useNode(id: string, options?: NodeOptions): NodeModel_2; /** * `useSubgraph` is a hook that creates an instance of Subgraph * according to the object given by props. */ export declare function useSubgraph(props?: SubgraphOptions): SubgraphModel; export { } declare module 'react' { namespace JSX { interface IntrinsicElements extends DotJSXElements { } } } declare module 'react/jsx-runtime' { namespace JSX { interface IntrinsicElements extends DotJSXElements { } } }