@ts-graphviz/react 0.10.2 → 0.10.3-next-a1de944c70af32f17428537ec0b096de2d68388d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/lib/components/Digraph.d.ts +6 -0
  3. package/lib/components/Digraph.spec.d.ts +1 -0
  4. package/lib/components/Edge.d.ts +6 -0
  5. package/lib/components/Graph.d.ts +6 -0
  6. package/lib/components/Graph.spec.d.ts +1 -0
  7. package/lib/components/GraphPortal.d.ts +6 -0
  8. package/lib/components/Node.d.ts +6 -0
  9. package/lib/components/Node.spec.d.ts +1 -0
  10. package/lib/components/Subgraph.d.ts +6 -0
  11. package/lib/contexts/CurrentGraph.d.ts +3 -0
  12. package/lib/contexts/GraphContainer.d.ts +3 -0
  13. package/lib/contexts/GraphMap.d.ts +3 -0
  14. package/lib/contexts/GraphvizContext.d.ts +6 -0
  15. package/lib/hooks/__tests__/wrapper.d.ts +19 -0
  16. package/lib/hooks/useCurrentGraph.d.ts +7 -0
  17. package/lib/hooks/useCurrentGraph.spec.d.ts +1 -0
  18. package/lib/hooks/useDigraph.d.ts +7 -0
  19. package/lib/hooks/useDigraph.spec.d.ts +1 -0
  20. package/lib/hooks/useEdge.d.ts +7 -0
  21. package/lib/hooks/useEdge.spec.d.ts +1 -0
  22. package/lib/hooks/useGraph.d.ts +7 -0
  23. package/lib/hooks/useGraph.spec.d.ts +1 -0
  24. package/lib/hooks/useGraphAttributes.d.ts +3 -0
  25. package/lib/hooks/useGraphContainer.d.ts +5 -0
  26. package/lib/hooks/useGraphContainer.spec.d.ts +1 -0
  27. package/lib/hooks/useGraphMap.d.ts +2 -0
  28. package/lib/hooks/useGraphvizContext.d.ts +3 -0
  29. package/lib/hooks/useGraphvizContext.spec.d.ts +1 -0
  30. package/lib/hooks/useHasAttributes.d.ts +2 -0
  31. package/lib/hooks/useHasComment.d.ts +2 -0
  32. package/lib/hooks/useNode.d.ts +7 -0
  33. package/lib/hooks/useNode.spec.d.ts +1 -0
  34. package/lib/hooks/useRenderedID.d.ts +2 -0
  35. package/lib/hooks/useRenderedID.spec.d.ts +1 -0
  36. package/lib/hooks/useSubgraph.d.ts +7 -0
  37. package/lib/hooks/useSubgraph.spec.d.ts +1 -0
  38. package/lib/react.d.ts +16 -230
  39. package/lib/reconciler.d.ts +71 -0
  40. package/lib/render.d.ts +68 -0
  41. package/lib/render.test.d.ts +1 -0
  42. package/lib/renderHTMLLike.d.ts +2 -0
  43. package/lib/renderId.d.ts +2 -0
  44. package/lib/types.d.ts +109 -0
  45. package/package.json +4 -4
  46. package/vite.config.ts +2 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ts-graphviz/react
2
2
 
3
+ ## 0.10.3-next-a1de944c70af32f17428537ec0b096de2d68388d
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1087](https://github.com/ts-graphviz/ts-graphviz/pull/1087) [`f808a2e`](https://github.com/ts-graphviz/ts-graphviz/commit/f808a2e93f52a97e3466afc37d5353b2d7d8c54c) Thanks [@kamiazya](https://github.com/kamiazya)! - Fix global JSX type
8
+
9
+ - [#1088](https://github.com/ts-graphviz/ts-graphviz/pull/1088) [`7d7352b`](https://github.com/ts-graphviz/ts-graphviz/commit/7d7352bb3819522ba16763503aa6bc923f550408) Thanks [@kamiazya](https://github.com/kamiazya)! - Update Snapshot release configuration
10
+
11
+ - Updated dependencies [[`883f7b3`](https://github.com/ts-graphviz/ts-graphviz/commit/883f7b3c65794b3ab2b01c422b6231079bb6c28d), [`7705b1d`](https://github.com/ts-graphviz/ts-graphviz/commit/7705b1d08612aef83e1c35bc3ee4ffc922247a27), [`7d7352b`](https://github.com/ts-graphviz/ts-graphviz/commit/7d7352bb3819522ba16763503aa6bc923f550408)]:
12
+ - @ts-graphviz/common@2.1.3-next-a1de944c70af32f17428537ec0b096de2d68388d
13
+ - ts-graphviz@2.1.3-next-a1de944c70af32f17428537ec0b096de2d68388d
14
+
3
15
  ## 0.10.2
4
16
 
5
17
  ### Patch Changes
@@ -0,0 +1,6 @@
1
+ import { type FC } from 'react';
2
+ import type { RootGraphProps } from '../types.js';
3
+ /**
4
+ * `Digraph` component.
5
+ */
6
+ export declare const Digraph: FC<RootGraphProps>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { FC } from 'react';
2
+ import type { EdgeProps } from '../types.js';
3
+ /**
4
+ * `Edge` component.
5
+ */
6
+ export declare const Edge: FC<EdgeProps>;
@@ -0,0 +1,6 @@
1
+ import { type FC } from 'react';
2
+ import type { RootGraphProps } from '../types.js';
3
+ /**
4
+ * `Graph` component.
5
+ */
6
+ export declare const Graph: FC<RootGraphProps>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import { type FC } from 'react';
2
+ import type { GraphPortalProps } from '../types.js';
3
+ /**
4
+ * GraphPortal component.
5
+ */
6
+ export declare const GraphPortal: FC<GraphPortalProps>;
@@ -0,0 +1,6 @@
1
+ import type { FC } from 'react';
2
+ import type { NodeProps } from '../types.js';
3
+ /**
4
+ * `Node` component.
5
+ */
6
+ export declare const Node: FC<NodeProps>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import { type FC } from 'react';
2
+ import type { SubgraphProps } from '../types.js';
3
+ /**
4
+ * `Subgraph` component.
5
+ */
6
+ export declare const Subgraph: FC<SubgraphProps>;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import type { GraphBaseModel } from 'ts-graphviz';
3
+ export declare const CurrentGraph: import("react").Context<GraphBaseModel<import("ts-graphviz").AttributeKey> | null>;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import type { GraphBaseModel } from 'ts-graphviz';
3
+ export declare const GraphContainer: import("react").Context<GraphBaseModel<import("ts-graphviz").AttributeKey> | null>;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import type { GraphBaseModel } from 'ts-graphviz';
3
+ export declare const GraphMap: import("react").Context<Map<string, GraphBaseModel<import("ts-graphviz").AttributeKey>>>;
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import type { GraphBaseModel } from 'ts-graphviz';
3
+ export interface Context<T extends GraphBaseModel = GraphBaseModel> {
4
+ container?: T;
5
+ }
6
+ export declare const GraphvizContext: import("react").Context<Context<GraphBaseModel<import("ts-graphviz").AttributeKey>>>;
@@ -0,0 +1,19 @@
1
+ import type { ComponentProps, FC, ReactNode } from 'react';
2
+ import { Digraph } from '../../components/Digraph.js';
3
+ import { Graph } from '../../components/Graph.js';
4
+ import { Subgraph } from '../../components/Subgraph.js';
5
+ export declare const context: () => FC<{
6
+ children: ReactNode;
7
+ }>;
8
+ export declare const digraph: (props?: ComponentProps<typeof Digraph>) => FC<{
9
+ children: ReactNode;
10
+ }>;
11
+ export declare const digraphInSubgraph: (props?: ComponentProps<typeof Subgraph>) => FC<{
12
+ children: ReactNode;
13
+ }>;
14
+ export declare const graph: (props?: ComponentProps<typeof Graph>) => FC<{
15
+ children: ReactNode;
16
+ }>;
17
+ export declare const graphInSubgraph: (props?: ComponentProps<typeof Subgraph>) => FC<{
18
+ children: ReactNode;
19
+ }>;
@@ -0,0 +1,7 @@
1
+ import type { GraphBaseModel } from 'ts-graphviz';
2
+ /**
3
+ * Hook to get the current cluster(Digraph, Graph or Subgraph).
4
+ *
5
+ * @throws If it is out of the context of Cluster, it throws an exception.
6
+ */
7
+ export declare function useCurrentGraph(): GraphBaseModel;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import { type RootGraphModel } from 'ts-graphviz';
2
+ import type { RootGraphOptions } from '../types.js';
3
+ /**
4
+ * `useDigraph` is a hook that creates an instance of Digraph
5
+ * according to the object given by props.
6
+ */
7
+ export declare function useDigraph(options?: RootGraphOptions): RootGraphModel;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { EdgeModel, EdgeTargetLikeTuple } from 'ts-graphviz';
2
+ import type { EdgeOptions } from '../types.js';
3
+ /**
4
+ * `useEdge` is a hook that creates an instance of Edge
5
+ * according to the object given by props.
6
+ */
7
+ export declare function useEdge(targets: EdgeTargetLikeTuple, props?: EdgeOptions): EdgeModel;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import { type RootGraphModel } from 'ts-graphviz';
2
+ import type { RootGraphOptions } from '../types.js';
3
+ /**
4
+ * `useGraph` is a hook that creates an instance of Graph
5
+ * according to the object given by props.
6
+ */
7
+ export declare function useGraph(options?: RootGraphOptions): RootGraphModel;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { AttributeKey, AttributesObject, GraphBaseModel } from 'ts-graphviz';
2
+ import type { GraphBaseAttributesProps } from '../types.js';
3
+ export declare function useGraphAttributes<T extends AttributeKey>(cluster: GraphBaseModel<T>, attributes: AttributesObject<T>, { edge, node, graph }: GraphBaseAttributesProps): void;
@@ -0,0 +1,5 @@
1
+ import type { GraphBaseModel } from 'ts-graphviz';
2
+ /**
3
+ * Return the cluster of container.
4
+ */
5
+ export declare function useGraphContainer(): GraphBaseModel | null;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { GraphBaseModel } from 'ts-graphviz';
2
+ export declare function useGraphMap(): Map<string, GraphBaseModel>;
@@ -0,0 +1,3 @@
1
+ import type { GraphBaseModel } from 'ts-graphviz';
2
+ import { type Context } from '../contexts/GraphvizContext.js';
3
+ export declare function useGraphvizContext<T extends GraphBaseModel>(): Context<T>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { AttributeKey, AttributesObject, HasAttributes } from 'ts-graphviz';
2
+ export declare function useHasAttributes<T extends AttributeKey>(target: HasAttributes<T>, attributes: AttributesObject<T>): void;
@@ -0,0 +1,2 @@
1
+ import type { HasComment } from 'ts-graphviz';
2
+ export declare function useHasComment(target: HasComment, comment?: string): void;
@@ -0,0 +1,7 @@
1
+ import type { NodeModel } from 'ts-graphviz';
2
+ import type { NodeOptions } from '../types.js';
3
+ /**
4
+ * `useNode` is a hook that creates an instance of Node
5
+ * according to the object given by props.
6
+ */
7
+ export declare function useNode(id: string, options?: NodeOptions): NodeModel;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { type ReactElement } from 'react';
2
+ export declare function useRenderedID(id?: ReactElement | string): string | undefined;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import { type SubgraphModel } from 'ts-graphviz';
2
+ import type { SubgraphOptions } from '../types.js';
3
+ /**
4
+ * `useSubgraph` is a hook that creates an instance of Subgraph
5
+ * according to the object given by props.
6
+ */
7
+ export declare function useSubgraph(props?: SubgraphOptions): SubgraphModel;
@@ -0,0 +1 @@
1
+ export {};
package/lib/react.d.ts CHANGED
@@ -1,230 +1,16 @@
1
- import type { EdgeAttributesObject } from '@ts-graphviz/common';
2
- import type { EdgeModel } from 'ts-graphviz';
3
- import type { EdgeTargetLikeTuple } from '@ts-graphviz/common';
4
- import type { EdgeTargetLikeTuple as EdgeTargetLikeTuple_2 } from 'ts-graphviz';
5
- import { FC } from 'react';
6
- import type { GraphAttributesObject } from '@ts-graphviz/common';
7
- import { GraphBaseModel } from 'ts-graphviz';
8
- import type { HasComment } from '@ts-graphviz/common';
9
- import type { NodeAttributesObject } from '@ts-graphviz/common';
10
- import type { NodeModel } from 'ts-graphviz';
11
- import { ReactElement } from 'react';
12
- import type { ReactNode } from 'react';
13
- import { RootGraphModel } from 'ts-graphviz';
14
- import type { SubgraphAttributesObject } from '@ts-graphviz/common';
15
- import { SubgraphModel } from 'ts-graphviz';
16
-
17
- /**
18
- * `Digraph` component.
19
- */
20
- export declare const Digraph: FC<RootGraphProps>;
21
-
22
- /**
23
- * `Edge` component.
24
- */
25
- export declare const Edge: FC<EdgeProps>;
26
-
27
- /** Options for Edge */
28
- export declare interface EdgeOptions extends EdgeAttributesObject {
29
- }
30
-
31
- /** Props for Edge component */
32
- export declare interface EdgeProps extends Omit<EdgeOptions, 'label'> {
33
- /** Edge targets */
34
- targets: EdgeTargetLikeTuple;
35
- /** Edge label */
36
- label?: ReactElement | string;
37
- }
38
-
39
- /**
40
- * `Graph` component.
41
- */
42
- export declare const Graph: FC<RootGraphProps>;
43
-
44
- /** Common attribute values of objects under cluster */
45
- export declare interface GraphBaseAttributesProps {
46
- /** Attribute value for Edges */
47
- edge?: EdgeAttributesObject;
48
- /** Attribute value for Nodes */
49
- node?: NodeAttributesObject;
50
- /** Attribute value for Graphs */
51
- graph?: SubgraphAttributesObject;
52
- }
53
-
54
- /**
55
- * GraphPortal component.
56
- */
57
- export declare const GraphPortal: FC<GraphPortalProps>;
58
-
59
- /** Props for GraphPortal component */
60
- export declare interface GraphPortalProps {
61
- /**
62
- * id of the cluster you want to target for the portal.
63
- * If not specified, target the cluster that is the container to the portal.
64
- */
65
- id?: string;
66
- children?: ReactNode;
67
- }
68
-
69
- /**
70
- * `Node` component.
71
- */
72
- export declare const Node: FC<NodeProps>;
73
-
74
- /** Options for Node */
75
- export declare interface NodeOptions extends NodeAttributesObject {
76
- }
77
-
78
- /** Props for Node component */
79
- export declare interface NodeProps extends Omit<NodeOptions, 'label' | 'xlabel'> {
80
- /** Node id */
81
- id: string;
82
- /** Node label */
83
- label?: ReactElement | string;
84
- /** Node xlabel */
85
- xlabel?: ReactElement | string;
86
- }
87
-
88
- /**
89
- * Convert the given element to Graphviz model.
90
- *
91
- * @example Example of giving a cluster as a container with the second argument.
92
- *
93
- * ```tsx
94
- * import React, { FC } from 'react';
95
- * import { digraph, toDot } from 'ts-graphviz';
96
- * import { Node, Subgraph, render, Edge } from '@ts-graphviz/react';
97
- *
98
- * const Example: FC = () => (
99
- * <>
100
- * <Node id="a" />
101
- *
102
- * <Subgraph id="my_cluster">
103
- * <Node id="b" />
104
- * </Subgraph>
105
- * <Edge targets={['b', 'a']} />
106
- * </>
107
- * );
108
- *
109
- * const G = digraph((g) => render(<Example />, g));
110
- * console.log(toDot(G));
111
- * // digraph {
112
- * // "a";
113
- * // subgraph "my_cluster" {
114
- * // "b";
115
- * // }
116
- * // "b" -> "a";
117
- * // }
118
- * ```
119
- */
120
- export declare function render<T extends GraphBaseModel>(element: ReactElement, container?: T): T;
121
-
122
- export declare function renderHTMLLike(label?: ReactElement): string;
123
-
124
- /**
125
- * Converts the given element to DOT language and returns it.
126
- *
127
- * @example
128
- *
129
- * ```tsx
130
- * import React, { FC } from 'react';
131
- * import { Digraph, Node, Subgraph, renderToDot, Edge } from '@ts-graphviz/react';
132
- *
133
- * const Example: FC = () => (
134
- * <Digraph>
135
- * <Node id="a" />
136
- * <Subgraph id="my_cluster">
137
- * <Node id="b" />
138
- * </Subgraph>
139
- * <Edge targets={['b', 'a']} />
140
- * </Digraph>
141
- * );
142
- *
143
- * const dot = renderToDot(<Example />);
144
- * console.log(dot);
145
- * // digraph {
146
- * // "a";
147
- * // subgraph "my_cluster" {
148
- * // "b";
149
- * // }
150
- * // "b" -> "a";
151
- * // }
152
- * ```
153
- *
154
- * @returns Rendered dot string
155
- */
156
- export declare function renderToDot(element: ReactElement, container?: RootGraphModel): string;
157
-
158
- /** Options for RootGraph */
159
- export declare interface RootGraphOptions extends GraphAttributesObject, GraphBaseAttributesProps {
160
- /** Cluster id */
161
- id?: string;
162
- }
163
-
164
- /** Props for RootGraph component */
165
- export declare interface RootGraphProps extends Omit<RootGraphOptions, 'label'> {
166
- label?: ReactElement | string;
167
- children?: ReactNode;
168
- }
169
-
170
- /**
171
- * `Subgraph` component.
172
- */
173
- export declare const Subgraph: FC<SubgraphProps>;
174
-
175
- /** Options for Subgraph */
176
- export declare interface SubgraphOptions extends SubgraphAttributesObject, GraphBaseAttributesProps, HasComment {
177
- /** Cluster id */
178
- id?: string;
179
- }
180
-
181
- /** Props for Subgraph component */
182
- export declare interface SubgraphProps extends Omit<SubgraphOptions, 'label'> {
183
- /** Subgraph label */
184
- label?: ReactElement | string;
185
- children?: ReactNode;
186
- }
187
-
188
- /**
189
- * Hook to get the current cluster(Digraph, Graph or Subgraph).
190
- *
191
- * @throws If it is out of the context of Cluster, it throws an exception.
192
- */
193
- export declare function useCurrentGraph(): GraphBaseModel;
194
-
195
- /**
196
- * `useDigraph` is a hook that creates an instance of Digraph
197
- * according to the object given by props.
198
- */
199
- export declare function useDigraph(options?: RootGraphOptions): RootGraphModel;
200
-
201
- /**
202
- * `useEdge` is a hook that creates an instance of Edge
203
- * according to the object given by props.
204
- */
205
- export declare function useEdge(targets: EdgeTargetLikeTuple_2, props?: EdgeOptions): EdgeModel;
206
-
207
- /**
208
- * `useGraph` is a hook that creates an instance of Graph
209
- * according to the object given by props.
210
- */
211
- export declare function useGraph(options?: RootGraphOptions): RootGraphModel;
212
-
213
- /**
214
- * Return the cluster of container.
215
- */
216
- export declare function useGraphContainer(): GraphBaseModel | null;
217
-
218
- /**
219
- * `useNode` is a hook that creates an instance of Node
220
- * according to the object given by props.
221
- */
222
- export declare function useNode(id: string, options?: NodeOptions): NodeModel;
223
-
224
- /**
225
- * `useSubgraph` is a hook that creates an instance of Subgraph
226
- * according to the object given by props.
227
- */
228
- export declare function useSubgraph(props?: SubgraphOptions): SubgraphModel;
229
-
230
- export { }
1
+ export * from './types.js';
2
+ export * from './hooks/useGraphContainer.js';
3
+ export * from './hooks/useCurrentGraph.js';
4
+ export * from './hooks/useDigraph.js';
5
+ export * from './hooks/useGraph.js';
6
+ export * from './hooks/useSubgraph.js';
7
+ export * from './hooks/useEdge.js';
8
+ export * from './hooks/useNode.js';
9
+ export * from './components/Graph.js';
10
+ export * from './components/Digraph.js';
11
+ export * from './components/Subgraph.js';
12
+ export * from './components/Node.js';
13
+ export * from './components/Edge.js';
14
+ export * from './components/GraphPortal.js';
15
+ export * from './renderHTMLLike.js';
16
+ export * from './render.js';
@@ -0,0 +1,71 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type { FC } from 'react';
3
+ import ReactReconciler from 'react-reconciler';
4
+ type Type = FC;
5
+ type Props = any;
6
+ type Container = Record<string, never>;
7
+ type Instance = any;
8
+ type TextInstance = any;
9
+ type SuspenseInstance = any;
10
+ type HydratableInstance = any;
11
+ type PublicInstance = any;
12
+ type HostContext = any;
13
+ type UpdatePayload = any;
14
+ type ChildSet = any;
15
+ type TimeoutHandle = any;
16
+ type NoTimeout = any;
17
+ type OpaqueHandle = ReactReconciler.Fiber;
18
+ export declare class HostConfig implements ReactReconciler.HostConfig<Type, Props, Container, Instance, TextInstance, SuspenseInstance, HydratableInstance, PublicInstance, HostContext, UpdatePayload, ChildSet, // TODO Placeholder for undocumented API
19
+ TimeoutHandle, NoTimeout> {
20
+ preparePortalMount(containerInfo: Container): void;
21
+ scheduleTimeout(fn: (...args: unknown[]) => unknown, delay?: number): void;
22
+ cancelTimeout(id: any): void;
23
+ queueMicrotask(fn: () => void): void;
24
+ cloneInstance?: any;
25
+ cloneFundamentalInstance?: any;
26
+ createContainerChildSet?: any;
27
+ appendChildToContainerChildSet?: any;
28
+ finalizeContainerChildren?: any;
29
+ replaceContainerChildren?: any;
30
+ cloneHiddenInstance?: any;
31
+ cloneHiddenTextInstance?: any;
32
+ now: () => number;
33
+ setTimeout: typeof setTimeout;
34
+ clearTimeout: typeof clearTimeout;
35
+ noTimeout: NoTimeout;
36
+ isPrimaryRenderer: boolean;
37
+ supportsMutation: boolean;
38
+ supportsPersistence: boolean;
39
+ supportsHydration: boolean;
40
+ getPublicInstance(instance: Instance | TextInstance): PublicInstance;
41
+ getRootHostContext(rootContainerInstance: Container): HostContext;
42
+ getChildHostContext(parentHostContext: HostContext, type: Type, rootContainerInstance: Container): HostContext;
43
+ prepareForCommit(containerInfo: Container): Record<string, any> | null;
44
+ resetAfterCommit(containerInfo: Container): void;
45
+ /**
46
+ * Create component instance
47
+ */
48
+ createInstance(type: Type, props: Props, rootContainerInstance: Container, hostContext: HostContext, internalInstanceHandle: OpaqueHandle): Instance;
49
+ appendInitialChild(parentInstance: Instance, child: Instance | TextInstance): void;
50
+ finalizeInitialChildren(parentInstance: Instance, type: Type, props: Props, rootContainerInstance: Container, hostContext: HostContext): boolean;
51
+ prepareUpdate(instance: Instance, type: Type, oldProps: Props, newProps: Props, rootContainerInstance: Container, hostContext: HostContext): null | UpdatePayload;
52
+ shouldSetTextContent(type: Type, props: Props): boolean;
53
+ shouldDeprioritizeSubtree(type: Type, props: Props): boolean;
54
+ createTextInstance(text: string, rootContainerInstance: Container, hostContext: HostContext, internalInstanceHandle: OpaqueHandle): TextInstance;
55
+ scheduleDeferredCallback(callback: () => any, options?: {
56
+ timeout: number;
57
+ }): any;
58
+ cancelDeferredCallback(callbackID: any): void;
59
+ appendChild(parentInstance: Instance, child: Instance | TextInstance): void;
60
+ appendChildToContainer(container: Container, child: Instance | TextInstance): void;
61
+ commitTextUpdate(textInstance: TextInstance, oldText: string, newText: string): void;
62
+ commitMount(instance: Instance, type: Type, newProps: Props, internalInstanceHandle: OpaqueHandle): void;
63
+ commitUpdate(instance: Instance, updatePayload: UpdatePayload, type: Type, oldProps: Props, newProps: Props, internalInstanceHandle: OpaqueHandle): void;
64
+ insertBefore(parentInstance: Instance, child: Instance | TextInstance, beforeChild: Instance | TextInstance): void;
65
+ insertInContainerBefore(container: Container, child: Instance | TextInstance, beforeChild: Instance | TextInstance): void;
66
+ removeChild(parentInstance: Instance, child: Instance | TextInstance): void;
67
+ removeChildFromContainer(container: Container, child: Instance | TextInstance): void;
68
+ resetTextContent(instance: Instance): void;
69
+ }
70
+ export declare const reconciler: ReactReconciler.Reconciler<Container, any, any, any, any>;
71
+ export {};
@@ -0,0 +1,68 @@
1
+ import { type ReactElement } from 'react';
2
+ import { type GraphBaseModel, type RootGraphModel } from 'ts-graphviz';
3
+ /**
4
+ * Convert the given element to Graphviz model.
5
+ *
6
+ * @example Example of giving a cluster as a container with the second argument.
7
+ *
8
+ * ```tsx
9
+ * import React, { FC } from 'react';
10
+ * import { digraph, toDot } from 'ts-graphviz';
11
+ * import { Node, Subgraph, render, Edge } from '@ts-graphviz/react';
12
+ *
13
+ * const Example: FC = () => (
14
+ * <>
15
+ * <Node id="a" />
16
+ *
17
+ * <Subgraph id="my_cluster">
18
+ * <Node id="b" />
19
+ * </Subgraph>
20
+ * <Edge targets={['b', 'a']} />
21
+ * </>
22
+ * );
23
+ *
24
+ * const G = digraph((g) => render(<Example />, g));
25
+ * console.log(toDot(G));
26
+ * // digraph {
27
+ * // "a";
28
+ * // subgraph "my_cluster" {
29
+ * // "b";
30
+ * // }
31
+ * // "b" -> "a";
32
+ * // }
33
+ * ```
34
+ */
35
+ export declare function render<T extends GraphBaseModel>(element: ReactElement, container?: T): T;
36
+ /**
37
+ * Converts the given element to DOT language and returns it.
38
+ *
39
+ * @example
40
+ *
41
+ * ```tsx
42
+ * import React, { FC } from 'react';
43
+ * import { Digraph, Node, Subgraph, renderToDot, Edge } from '@ts-graphviz/react';
44
+ *
45
+ * const Example: FC = () => (
46
+ * <Digraph>
47
+ * <Node id="a" />
48
+ * <Subgraph id="my_cluster">
49
+ * <Node id="b" />
50
+ * </Subgraph>
51
+ * <Edge targets={['b', 'a']} />
52
+ * </Digraph>
53
+ * );
54
+ *
55
+ * const dot = renderToDot(<Example />);
56
+ * console.log(dot);
57
+ * // digraph {
58
+ * // "a";
59
+ * // subgraph "my_cluster" {
60
+ * // "b";
61
+ * // }
62
+ * // "b" -> "a";
63
+ * // }
64
+ * ```
65
+ *
66
+ * @returns Rendered dot string
67
+ */
68
+ export declare function renderToDot(element: ReactElement, container?: RootGraphModel): string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { ReactElement } from 'react';
2
+ export declare function renderHTMLLike(label?: ReactElement): string;
@@ -0,0 +1,2 @@
1
+ import { type ReactElement } from 'react';
2
+ export declare function renderId<T>(id?: ReactElement<T> | string): string | undefined;
package/lib/types.d.ts ADDED
@@ -0,0 +1,109 @@
1
+ import type { EdgeAttributesObject, EdgeTargetLikeTuple, GraphAttributesObject, HTMLLikeLabel, HasComment, NodeAttributesObject, SubgraphAttributesObject } from '@ts-graphviz/common';
2
+ import type { ReactElement, ReactNode } from 'react';
3
+ /** Common attribute values of objects under cluster */
4
+ export interface GraphBaseAttributesProps {
5
+ /** Attribute value for Edges */
6
+ edge?: EdgeAttributesObject;
7
+ /** Attribute value for Nodes */
8
+ node?: NodeAttributesObject;
9
+ /** Attribute value for Graphs */
10
+ graph?: SubgraphAttributesObject;
11
+ }
12
+ /** Options for RootGraph */
13
+ export interface RootGraphOptions extends GraphAttributesObject, GraphBaseAttributesProps {
14
+ /** Cluster id */
15
+ id?: string;
16
+ }
17
+ /** Options for Subgraph */
18
+ export interface SubgraphOptions extends SubgraphAttributesObject, GraphBaseAttributesProps, HasComment {
19
+ /** Cluster id */
20
+ id?: string;
21
+ }
22
+ /** Options for Edge */
23
+ export interface EdgeOptions extends EdgeAttributesObject {
24
+ }
25
+ /** Options for Node */
26
+ export interface NodeOptions extends NodeAttributesObject {
27
+ }
28
+ /** Props for RootGraph component */
29
+ export interface RootGraphProps extends Omit<RootGraphOptions, 'label'> {
30
+ label?: ReactElement | string;
31
+ children?: ReactNode;
32
+ }
33
+ /** Props for Edge component */
34
+ export interface EdgeProps extends Omit<EdgeOptions, 'label'> {
35
+ /** Edge targets */
36
+ targets: EdgeTargetLikeTuple;
37
+ /** Edge label */
38
+ label?: ReactElement | string;
39
+ }
40
+ /** Props for Node component */
41
+ export interface NodeProps extends Omit<NodeOptions, 'label' | 'xlabel'> {
42
+ /** Node id */
43
+ id: string;
44
+ /** Node label */
45
+ label?: ReactElement | string;
46
+ /** Node xlabel */
47
+ xlabel?: ReactElement | string;
48
+ }
49
+ /** Props for Subgraph component */
50
+ export interface SubgraphProps extends Omit<SubgraphOptions, 'label'> {
51
+ /** Subgraph label */
52
+ label?: ReactElement | string;
53
+ children?: ReactNode;
54
+ }
55
+ /** Props for GraphPortal component */
56
+ export interface GraphPortalProps {
57
+ /**
58
+ * id of the cluster you want to target for the portal.
59
+ * If not specified, target the cluster that is the container to the portal.
60
+ */
61
+ id?: string;
62
+ children?: ReactNode;
63
+ }
64
+ declare global {
65
+ namespace JSX {
66
+ interface IntrinsicElements {
67
+ 'dot:port': {
68
+ children: string;
69
+ };
70
+ 'dot:table': HTMLLikeLabel.TableAttributes & {
71
+ children?: ReactNode;
72
+ };
73
+ 'dot:tr': HTMLLikeLabel.TrAttributes & {
74
+ children?: ReactNode;
75
+ };
76
+ 'dot:td': HTMLLikeLabel.TdAttributes & {
77
+ children?: ReactNode;
78
+ };
79
+ 'dot:font': HTMLLikeLabel.FontAttributes & {
80
+ children?: ReactNode;
81
+ };
82
+ 'dot:br': HTMLLikeLabel.BrAttributes;
83
+ 'dot:img': HTMLLikeLabel.ImgAttributes;
84
+ 'dot:i': HTMLLikeLabel.IAttributes & {
85
+ children?: ReactNode;
86
+ };
87
+ 'dot:b': HTMLLikeLabel.BAttributes & {
88
+ children?: ReactNode;
89
+ };
90
+ 'dot:u': HTMLLikeLabel.UAttributes & {
91
+ children?: ReactNode;
92
+ };
93
+ 'dot:o': HTMLLikeLabel.OAttributes & {
94
+ children?: ReactNode;
95
+ };
96
+ 'dot:sub': HTMLLikeLabel.SubAttributes & {
97
+ children?: ReactNode;
98
+ };
99
+ 'dot:sup': HTMLLikeLabel.SupAttributes & {
100
+ children?: ReactNode;
101
+ };
102
+ 'dot:s': HTMLLikeLabel.SAttributes & {
103
+ children?: ReactNode;
104
+ };
105
+ 'dot:hr': HTMLLikeLabel.HrAttributes;
106
+ 'dot:vr': HTMLLikeLabel.VrAttributes;
107
+ }
108
+ }
109
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-graphviz/react",
3
- "version": "0.10.2",
3
+ "version": "0.10.3-next-a1de944c70af32f17428537ec0b096de2d68388d",
4
4
  "description": "Graphviz-dot Renderer for React.",
5
5
  "keywords": [
6
6
  "graphviz",
@@ -41,8 +41,8 @@
41
41
  "types": "./lib/react.d.ts",
42
42
  "dependencies": {
43
43
  "react-reconciler": "^0.29.0",
44
- "@ts-graphviz/common": "^2.1.2",
45
- "ts-graphviz": "^2.1.2"
44
+ "@ts-graphviz/common": "^2.1.3-next-a1de944c70af32f17428537ec0b096de2d68388d",
45
+ "ts-graphviz": "^2.1.3-next-a1de944c70af32f17428537ec0b096de2d68388d"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@testing-library/react": "^14.2.1",
@@ -51,7 +51,7 @@
51
51
  "@types/react-reconciler": "^0.26.7",
52
52
  "react": "^18.2.0",
53
53
  "react-dom": "^18.2.0",
54
- "react-test-renderer": "^18.2.0",
54
+ "react-test-renderer": "^18.3.1",
55
55
  "typescript": "^5.4.5",
56
56
  "vite": "^5.2.8",
57
57
  "vite-plugin-dts": "^3.7.3"
package/vite.config.ts CHANGED
@@ -26,7 +26,8 @@ export default defineConfig({
26
26
  plugins: [
27
27
  // @ts-ignore
28
28
  dts({
29
- rollupTypes: true,
29
+ // NOTE: This is a workaround for global types exports.
30
+ rollupTypes: false,
30
31
  }),
31
32
  ],
32
33
  });