@ts-graphviz/react 0.10.6 → 0.11.0
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.
- package/CHANGELOG.md +487 -0
- package/README.md +630 -67
- package/example/example.tsx +1 -1
- package/lib/react.d.ts +198 -96
- package/lib/react.js +558 -215
- package/package.json +15 -20
- package/tsconfig.test.json +11 -0
- package/lib/react.cjs +0 -457
- package/src/components/Digraph.spec.tsx +0 -18
- package/src/components/Digraph.tsx +0 -41
- package/src/components/Edge.tsx +0 -17
- package/src/components/Graph.spec.tsx +0 -18
- package/src/components/Graph.tsx +0 -36
- package/src/components/GraphPortal.tsx +0 -22
- package/src/components/Node.spec.tsx +0 -101
- package/src/components/Node.tsx +0 -21
- package/src/components/Subgraph.tsx +0 -30
- package/src/contexts/CurrentGraph.ts +0 -5
- package/src/contexts/GraphContainer.ts +0 -5
- package/src/contexts/GraphMap.ts +0 -5
- package/src/contexts/GraphvizContext.ts +0 -11
- package/src/hooks/__tests__/wrapper.tsx +0 -58
- package/src/hooks/useCurrentGraph.spec.ts +0 -56
- package/src/hooks/useCurrentGraph.ts +0 -18
- package/src/hooks/useDigraph.spec.ts +0 -15
- package/src/hooks/useDigraph.ts +0 -33
- package/src/hooks/useEdge.spec.ts +0 -46
- package/src/hooks/useEdge.ts +0 -35
- package/src/hooks/useGraph.spec.ts +0 -15
- package/src/hooks/useGraph.ts +0 -33
- package/src/hooks/useGraphAttributes.ts +0 -32
- package/src/hooks/useGraphContainer.spec.ts +0 -45
- package/src/hooks/useGraphContainer.ts +0 -10
- package/src/hooks/useGraphMap.ts +0 -7
- package/src/hooks/useGraphvizContext.spec.ts +0 -26
- package/src/hooks/useGraphvizContext.ts +0 -16
- package/src/hooks/useHasAttributes.ts +0 -16
- package/src/hooks/useHasComment.ts +0 -8
- package/src/hooks/useNode.spec.ts +0 -16
- package/src/hooks/useNode.ts +0 -29
- package/src/hooks/useRenderedID.spec.tsx +0 -28
- package/src/hooks/useRenderedID.ts +0 -6
- package/src/hooks/useSubgraph.spec.ts +0 -41
- package/src/hooks/useSubgraph.ts +0 -39
- package/src/react.ts +0 -16
- package/src/reconciler.ts +0 -272
- package/src/render.test.tsx +0 -71
- package/src/render.ts +0 -142
- package/src/renderHTMLLike.ts +0 -9
- package/src/renderId.ts +0 -9
- package/src/types.ts +0 -107
- package/tsconfig.json +0 -8
- package/typedoc.json +0 -5
- package/vite.config.ts +0 -31
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,492 @@
|
|
|
1
1
|
# @ts-graphviz/react
|
|
2
2
|
|
|
3
|
+
## 0.11.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1363](https://github.com/ts-graphviz/ts-graphviz/pull/1363) [`9328563`](https://github.com/ts-graphviz/ts-graphviz/commit/932856396ed0dede1dfc6737344a628f9667d07c) Thanks [@kamiazya](https://github.com/kamiazya)! - 🚨 Breaking Changes: Drop Node.js 18 support
|
|
8
|
+
|
|
9
|
+
Minimum required version is now Node.js 20+
|
|
10
|
+
|
|
11
|
+
### ESM-Only Distribution
|
|
12
|
+
|
|
13
|
+
- **Remove CommonJS builds**: All packages now distribute only ESM (ECMAScript Modules)
|
|
14
|
+
- **Package exports**: Removed `require` fields from `package.json` exports
|
|
15
|
+
- **Module type**: All packages are now `"type": "module"`
|
|
16
|
+
|
|
17
|
+
## 🔄 Migration Guide
|
|
18
|
+
|
|
19
|
+
### For ESM Projects (Recommended)
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"type": "module"
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
// Import syntax remains unchanged
|
|
29
|
+
import { Digraph, Node, Edge, toDot } from "ts-graphviz";
|
|
30
|
+
import { toFile } from "ts-graphviz/adapter";
|
|
31
|
+
import { parse } from "ts-graphviz/ast";
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### For CommonJS Projects
|
|
35
|
+
|
|
36
|
+
If you are using CommonJS (CJS) and need to migrate to ESM, you will need to update your project to support dynamic imports. This is necessary because the packages no longer provide CommonJS builds.
|
|
37
|
+
|
|
38
|
+
### Before (CJS)
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
// JavaScript (CommonJS)
|
|
42
|
+
function createGraph() {
|
|
43
|
+
// Dynamic import is required because the packages no longer provide CommonJS builds.
|
|
44
|
+
const { Digraph, Node, Edge, toDot } = require("ts-graphviz");
|
|
45
|
+
const graph = new Digraph();
|
|
46
|
+
return toDot(graph);
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### After (ESM)
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
async function createGraph() {
|
|
54
|
+
const { Digraph, Node, Edge, toDot } = await import("ts-graphviz");
|
|
55
|
+
|
|
56
|
+
const graph = new Digraph();
|
|
57
|
+
// Create your graph...
|
|
58
|
+
return toDot(graph);
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
// TypeScript (CommonJS)
|
|
64
|
+
// Update tsconfig.json
|
|
65
|
+
{
|
|
66
|
+
"compilerOptions": {
|
|
67
|
+
"module": "Node16",
|
|
68
|
+
"moduleResolution": "Node16"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Use dynamic imports
|
|
73
|
+
async function createGraph() {
|
|
74
|
+
const tsGraphviz = await import('ts-graphviz');
|
|
75
|
+
const { Digraph, Node, Edge, toDot } = tsGraphviz;
|
|
76
|
+
|
|
77
|
+
const graph = new Digraph();
|
|
78
|
+
// Create your graph...
|
|
79
|
+
return toDot(graph);
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 🎯 Benefits
|
|
84
|
+
|
|
85
|
+
- **Modern JavaScript**: Leveraging native ES modules for better performance
|
|
86
|
+
- **Smaller bundle sizes**: ESM enables better tree-shaking
|
|
87
|
+
- **Future-proof**: Aligning with the JavaScript ecosystem direction
|
|
88
|
+
- **Better TypeScript support**: Enhanced module resolution
|
|
89
|
+
|
|
90
|
+
- [#1363](https://github.com/ts-graphviz/ts-graphviz/pull/1363) [`9328563`](https://github.com/ts-graphviz/ts-graphviz/commit/932856396ed0dede1dfc6737344a628f9667d07c) Thanks [@kamiazya](https://github.com/kamiazya)! - Define Supported environment and Support levels
|
|
91
|
+
|
|
92
|
+
To provide clarity on the environments in which ts-graphviz operates, we have categorized support levels:
|
|
93
|
+
|
|
94
|
+
## Support Levels
|
|
95
|
+
|
|
96
|
+
### Tier 1: Full Support
|
|
97
|
+
|
|
98
|
+
- **Definition**: Environments that are fully supported, with comprehensive automated testing and maintenance.
|
|
99
|
+
- **Environments**:
|
|
100
|
+
- **Node.js LTS versions**: All active Long-Term Support (LTS) versions.
|
|
101
|
+
- If a Node.js LTS version is released, we will ensure compatibility with it.
|
|
102
|
+
- If a Node.js LTS version is deprecated, we will drop support for it in the next major release.
|
|
103
|
+
- **Details**:
|
|
104
|
+
- We run automated tests on all LTS versions of Node.js.
|
|
105
|
+
- Full compatibility and performance are ensured.
|
|
106
|
+
- Critical issues are prioritized for fixes.
|
|
107
|
+
|
|
108
|
+
### Tier 2: Active Support
|
|
109
|
+
|
|
110
|
+
- **Definition**: Environments that receive active support with limited automated testing.
|
|
111
|
+
- **Environments**:
|
|
112
|
+
- **Deno Latest LTS version**: The latest Long-Term Support (LTS) version of Deno.
|
|
113
|
+
- If a new Deno LTS version is released, we will ensure compatibility with it.
|
|
114
|
+
- If a Deno LTS version is deprecated, we will drop support for it in the next minor release.
|
|
115
|
+
- **Node.js Current Release**: The latest Node.js release outside the LTS schedule.
|
|
116
|
+
- If a new Node.js current release is available, we will ensure compatibility with it.
|
|
117
|
+
- If a Node.js current release is deprecated, we will drop support for it in the next minor release.
|
|
118
|
+
- **Details**:
|
|
119
|
+
- Compatibility is maintained, and issues are addressed.
|
|
120
|
+
|
|
121
|
+
### Tier 3: Community Support
|
|
122
|
+
|
|
123
|
+
- **Definition**: Environments that are not officially tested but are supported on a best-effort basis.
|
|
124
|
+
- **Environments**:
|
|
125
|
+
- **Modern Browsers**: Latest versions of major browsers, including:
|
|
126
|
+
- Google Chrome
|
|
127
|
+
- Mozilla Firefox
|
|
128
|
+
- Microsoft Edge
|
|
129
|
+
- Apple Safari
|
|
130
|
+
- **Deno Current Release**: The latest Deno release outside the LTS schedule.
|
|
131
|
+
- **Details**:
|
|
132
|
+
- Installation methods are provided.
|
|
133
|
+
- No automated testing is performed.
|
|
134
|
+
- Issues reported by users will be addressed.
|
|
135
|
+
- Targeting the latest versions ensures compatibility with modern web standards.
|
|
136
|
+
- We will not actively test or maintain compatibility with older versions of browsers.
|
|
137
|
+
|
|
138
|
+
- [#1363](https://github.com/ts-graphviz/ts-graphviz/pull/1363) [`9328563`](https://github.com/ts-graphviz/ts-graphviz/commit/932856396ed0dede1dfc6737344a628f9667d07c) Thanks [@kamiazya](https://github.com/kamiazya)! - ## React 19 Support with Breaking Changes
|
|
139
|
+
|
|
140
|
+
## 🚨 BREAKING CHANGES
|
|
141
|
+
|
|
142
|
+
### React 18 Support Discontinued
|
|
143
|
+
|
|
144
|
+
- **React 19+ is now required** - React 18 and earlier versions are no longer supported
|
|
145
|
+
- Updated `peerDependencies` to require `react@>=19` (removed `react-dom` dependency)
|
|
146
|
+
|
|
147
|
+
### API Changes
|
|
148
|
+
|
|
149
|
+
**Migration Required:**
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
// Before
|
|
153
|
+
const graph = render(<Digraph>...</Digraph>, container);
|
|
154
|
+
const dotString = renderToDot(<Digraph>...</Digraph>, container);
|
|
155
|
+
|
|
156
|
+
// After - New createRoot API following React 19 patterns
|
|
157
|
+
const root = createRoot({ container });
|
|
158
|
+
await root.render(<Digraph>...</Digraph>);
|
|
159
|
+
const models = root.getTopLevelModels();
|
|
160
|
+
const dotString = await renderToDot(<Digraph>...</Digraph>, { container });
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Container Model Access Changes
|
|
164
|
+
|
|
165
|
+
**🚨 BREAKING CHANGE:** New createRoot API changes how you access rendered models
|
|
166
|
+
|
|
167
|
+
**Migration Required:**
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
// Before - result.model was the first rendered model
|
|
171
|
+
const container = new DigraphModel("parent");
|
|
172
|
+
const result = await render(<Node id="test" />, { container });
|
|
173
|
+
expect(result.model.$type).toBe("Node"); // ❌ Old API
|
|
174
|
+
|
|
175
|
+
// After - Use root.getTopLevelModels() to access models
|
|
176
|
+
const container = new DigraphModel("parent");
|
|
177
|
+
const root = createRoot({ container });
|
|
178
|
+
await root.render(<Node id="test" />);
|
|
179
|
+
const models = root.getTopLevelModels();
|
|
180
|
+
expect(models[0].$type).toBe("Node"); // ✅ New API
|
|
181
|
+
expect(models[0].id).toBe("test");
|
|
182
|
+
// Access container directly: container.nodes.length === 1
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## ✨ NEW FEATURES
|
|
186
|
+
|
|
187
|
+
### Modern createRoot API
|
|
188
|
+
|
|
189
|
+
- 🆕 `createRoot()` function following React 19's modern patterns
|
|
190
|
+
- 🆕 **Simplified API**: `createRoot(options)` - single options parameter for all configuration
|
|
191
|
+
- 🆕 **Container in options**: `createRoot({ container, onRenderComplete })` for cleaner code
|
|
192
|
+
- Better performance and memory management
|
|
193
|
+
- Cleaner API separation between rendering and model access
|
|
194
|
+
- Enhanced error handling with root-level configuration
|
|
195
|
+
|
|
196
|
+
### Advanced Error Handling
|
|
197
|
+
|
|
198
|
+
- 🆕 `onUncaughtError` callback with component stack traces
|
|
199
|
+
- 🆕 `onCaughtError` callback for error boundary integration
|
|
200
|
+
- Better debugging capabilities for rendering failures
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
// Create root with error handling
|
|
204
|
+
const root = createRoot({
|
|
205
|
+
onUncaughtError: (error, errorInfo) => {
|
|
206
|
+
console.error("Rendering error:", error);
|
|
207
|
+
console.log("Component stack:", errorInfo.componentStack);
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
await root.render(<Digraph>...</Digraph>);
|
|
212
|
+
const models = root.getTopLevelModels();
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Ref as Prop Support
|
|
216
|
+
|
|
217
|
+
- All components now support React 19's ref as prop pattern
|
|
218
|
+
- Direct access to graph models (`NodeModel`, `EdgeModel`, `RootGraphModel`) via refs
|
|
219
|
+
- Enhanced TypeScript support with proper model typing
|
|
220
|
+
|
|
221
|
+
### Reduced Dependencies
|
|
222
|
+
|
|
223
|
+
- 🆕 Removed `react-dom` dependency - now uses custom HTML rendering implementation
|
|
224
|
+
- Smaller bundle size and fewer peer dependencies required
|
|
225
|
+
- No longer dependent on React's server-side rendering APIs
|
|
226
|
+
|
|
227
|
+
## 🔧 TECHNICAL UPDATES
|
|
228
|
+
|
|
229
|
+
### React Reconciler Modernization
|
|
230
|
+
|
|
231
|
+
- Updated reconciler to use React 19's new `createContainer` API (8 arguments vs 10)
|
|
232
|
+
- Improved memory management and performance
|
|
233
|
+
- Simplified rendering by removing library-level concurrent control (users can wrap with startTransition if needed)
|
|
234
|
+
|
|
235
|
+
### TypeScript Improvements
|
|
236
|
+
|
|
237
|
+
- Updated JSX namespace declaration from global to module scope
|
|
238
|
+
- Fixed React 19 type compatibility issues
|
|
239
|
+
- Enhanced type safety for error handlers
|
|
240
|
+
|
|
241
|
+
### Type System Modernization
|
|
242
|
+
|
|
243
|
+
- 🆕 **Eliminated manual type assertions** with function overloads and type guards
|
|
244
|
+
- 🆕 **Runtime type filtering** using built-in type guards from `@ts-graphviz/common`
|
|
245
|
+
- 🆕 **Direct type casting** for performance when user knows exact types
|
|
246
|
+
- 🆕 **Type-safe model access** with automatic type narrowing
|
|
247
|
+
- 🆕 **Enhanced TypeScript developer experience** with precise type inference
|
|
248
|
+
- 🆕 **Flexible type handling** - choose between runtime validation or trusted assertions
|
|
249
|
+
- Enhanced debugging capabilities with strongly-typed error handling
|
|
250
|
+
|
|
251
|
+
**Two approaches for type-safe model access:**
|
|
252
|
+
|
|
253
|
+
1. **Runtime Type Filtering** (safe, validated):
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
const nodes = root.getTopLevelModels(isNodeModel); // Filters only NodeModel objects
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
- Uses type guard functions for runtime validation
|
|
260
|
+
- Guarantees type safety at runtime
|
|
261
|
+
- Filters out non-matching models
|
|
262
|
+
|
|
263
|
+
2. **Direct Type Casting** (fast, trusted):
|
|
264
|
+
```typescript
|
|
265
|
+
const nodes = root.getTopLevelModels<NodeModel>(); // Casts all models as NodeModel
|
|
266
|
+
```
|
|
267
|
+
- No runtime validation - trusts user assertion
|
|
268
|
+
- Higher performance for known scenarios
|
|
269
|
+
- User responsible for type correctness
|
|
270
|
+
|
|
271
|
+
### Model Collection Algorithm Improvements
|
|
272
|
+
|
|
273
|
+
- 🆕 **Container-aware collection** replaces priority-based system
|
|
274
|
+
- Fixed unpredictable behavior in nested component structures
|
|
275
|
+
- Consistent model return behavior regardless of component hierarchy depth
|
|
276
|
+
- Better handling of complex Subgraph and Edge combinations
|
|
277
|
+
|
|
278
|
+
### Test Infrastructure
|
|
279
|
+
|
|
280
|
+
- 100% test coverage maintained
|
|
281
|
+
- React 19 compatibility validated
|
|
282
|
+
|
|
283
|
+
## 📚 MIGRATION GUIDE
|
|
284
|
+
|
|
285
|
+
### Prerequisites
|
|
286
|
+
|
|
287
|
+
- **Upgrade to React 19+**: Install `react@^19.0.0` (required)
|
|
288
|
+
- **Note**: `react-dom` is no longer required as this package now uses a custom HTML rendering implementation
|
|
289
|
+
|
|
290
|
+
### Step-by-Step Migration
|
|
291
|
+
|
|
292
|
+
1. **Update React Dependency**
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
npm install react@^19.0.0
|
|
296
|
+
# or
|
|
297
|
+
pnpm add react@^19.0.0
|
|
298
|
+
# or
|
|
299
|
+
yarn add react@^19.0.0
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
**Note**: You can now remove `react-dom` from your dependencies if it was only needed for @ts-graphviz/react:
|
|
303
|
+
|
|
304
|
+
```bash
|
|
305
|
+
npm uninstall react-dom
|
|
306
|
+
# or
|
|
307
|
+
pnpm remove react-dom
|
|
308
|
+
# or
|
|
309
|
+
yarn remove react-dom
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
2. **Update to createRoot API**
|
|
313
|
+
Replace render function calls with createRoot pattern:
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
// Old API
|
|
317
|
+
- const result = await render(<MyGraph />, container);
|
|
318
|
+
- const dot = await renderToDot(<MyGraph />, container);
|
|
319
|
+
|
|
320
|
+
// New API
|
|
321
|
+
+ const root = createRoot({ container });
|
|
322
|
+
+ await root.render(<MyGraph />);
|
|
323
|
+
+ const models = root.getTopLevelModels();
|
|
324
|
+
+ const dot = await renderToDot(<MyGraph />, { container });
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
3. **Update Model Access Patterns**
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
// Old behavior - result.model was the first rendered model
|
|
331
|
+
- const result = await render(<Node id="test" />, { container });
|
|
332
|
+
- expect(result.model.$type).toBe('Node');
|
|
333
|
+
|
|
334
|
+
// New behavior - use root.getTopLevelModels()
|
|
335
|
+
+ const root = createRoot(container);
|
|
336
|
+
+ await root.render(<Node id="test" />);
|
|
337
|
+
+ const models = root.getTopLevelModels();
|
|
338
|
+
+ expect(models[0].$type).toBe('Node');
|
|
339
|
+
+ expect(models[0].id).toBe('test');
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
4. **Add Error Handling (Optional)**
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
const root = createRoot(undefined, {
|
|
346
|
+
onUncaughtError: (error, errorInfo) => {
|
|
347
|
+
console.error("Graph rendering failed:", error);
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
await root.render(<MyGraph />);
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
5. **Multiple Renders with Same Root**
|
|
354
|
+
```typescript
|
|
355
|
+
// Create root once, use multiple times
|
|
356
|
+
const root = createRoot();
|
|
357
|
+
await root.render(<GraphA />);
|
|
358
|
+
await root.render(<GraphB />); // Replaces previous render
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### API Reference
|
|
362
|
+
|
|
363
|
+
**Core Functions:**
|
|
364
|
+
|
|
365
|
+
- `createRoot(container?, options?)` - Creates a rendering root following React 19 patterns
|
|
366
|
+
- `renderToDot(element, options?)` - Primary DOT string generation
|
|
367
|
+
|
|
368
|
+
**createRoot Options:**
|
|
369
|
+
|
|
370
|
+
```typescript
|
|
371
|
+
interface CreateRootOptions<
|
|
372
|
+
Container extends AnyGraphContainer = AnyGraphContainer
|
|
373
|
+
> {
|
|
374
|
+
container?: Container; // Container graph for rendering components
|
|
375
|
+
onUncaughtError?: (error: Error, errorInfo: ErrorInfo) => void;
|
|
376
|
+
onCaughtError?: (error: Error, errorInfo: ErrorInfo) => void;
|
|
377
|
+
onRecoverableError?: (error: Error, errorInfo: ErrorInfo) => void;
|
|
378
|
+
onRenderComplete?: (models: DotObjectModel[]) => void;
|
|
379
|
+
timeout?: number; // Rendering timeout (default: 5000ms)
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
interface GraphvizRoot {
|
|
383
|
+
render(element: ReactElement): Promise<void>;
|
|
384
|
+
unmount(): void;
|
|
385
|
+
// Overloaded for type-safe filtering and direct type casting
|
|
386
|
+
getTopLevelModels(): DotObjectModel[];
|
|
387
|
+
getTopLevelModels<T extends DotObjectModel>(
|
|
388
|
+
typeGuard: (model: DotObjectModel) => model is T
|
|
389
|
+
): T[]; // Runtime type filtering with validation
|
|
390
|
+
getTopLevelModels<T extends DotObjectModel>(): T[]; // Direct type casting (trusted assertion)
|
|
391
|
+
}
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
**Type-Safe Model Access Examples:**
|
|
395
|
+
|
|
396
|
+
```typescript
|
|
397
|
+
// Import type guards for runtime type filtering
|
|
398
|
+
import {
|
|
399
|
+
isNodeModel,
|
|
400
|
+
isEdgeModel,
|
|
401
|
+
isRootGraphModel,
|
|
402
|
+
} from "@ts-graphviz/common";
|
|
403
|
+
|
|
404
|
+
const root = createRoot();
|
|
405
|
+
await root.render(<MyGraph />);
|
|
406
|
+
|
|
407
|
+
// === APPROACH 1: Runtime Type Filtering (Safe) ===
|
|
408
|
+
// Uses type guard functions - validates types at runtime
|
|
409
|
+
const validatedNodes = root.getTopLevelModels(isNodeModel); // Only actual NodeModel objects
|
|
410
|
+
const validatedEdges = root.getTopLevelModels(isEdgeModel); // Only actual EdgeModel objects
|
|
411
|
+
const validatedGraphs = root.getTopLevelModels(isRootGraphModel); // Only actual RootGraphModel objects
|
|
412
|
+
|
|
413
|
+
// Guaranteed type safety - filters out non-matching models
|
|
414
|
+
console.log(`Found ${validatedNodes.length} nodes`); // Could be 0 if no nodes exist
|
|
415
|
+
validatedNodes.forEach((node) => console.log(node.id)); // All items are definitely NodeModel
|
|
416
|
+
|
|
417
|
+
// === APPROACH 2: Direct Type Casting (Fast) ===
|
|
418
|
+
// User assertion - no runtime validation, trusts the user
|
|
419
|
+
const allAsNodes = root.getTopLevelModels<NodeModel>(); // ALL models cast as NodeModel[]
|
|
420
|
+
const allAsEdges = root.getTopLevelModels<EdgeModel>(); // ALL models cast as EdgeModel[]
|
|
421
|
+
|
|
422
|
+
// Higher performance but requires user knowledge
|
|
423
|
+
console.log(`Treating ${allAsNodes.length} models as nodes`); // Returns all models
|
|
424
|
+
// Warning: If models aren't actually NodeModel, runtime errors may occur
|
|
425
|
+
|
|
426
|
+
// === MIXED USAGE PATTERNS ===
|
|
427
|
+
// Get all models first, then decide approach
|
|
428
|
+
const allModels = root.getTopLevelModels();
|
|
429
|
+
if (allModels.every(isNodeModel)) {
|
|
430
|
+
// Safe to use direct casting since we validated
|
|
431
|
+
const nodes = root.getTopLevelModels<NodeModel>();
|
|
432
|
+
nodes.forEach((node) => console.log(`Node: ${node.id}`));
|
|
433
|
+
} else {
|
|
434
|
+
// Use filtering for mixed model types
|
|
435
|
+
const nodes = root.getTopLevelModels(isNodeModel);
|
|
436
|
+
const edges = root.getTopLevelModels(isEdgeModel);
|
|
437
|
+
console.log(`Found ${nodes.length} nodes and ${edges.length} edges`);
|
|
438
|
+
}
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
**renderToDot Options:**
|
|
442
|
+
|
|
443
|
+
```typescript
|
|
444
|
+
interface RenderToDotOptions<
|
|
445
|
+
T extends AnyGraphContainer = AnyGraphContainer
|
|
446
|
+
> {
|
|
447
|
+
container?: T; // Container graph for nested rendering
|
|
448
|
+
onUncaughtError?: (error: Error, errorInfo: ErrorInfo) => void;
|
|
449
|
+
onCaughtError?: (error: Error, errorInfo: ErrorInfo) => void;
|
|
450
|
+
timeout?: number; // Rendering timeout in milliseconds
|
|
451
|
+
}
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
## 📦 INSTALLATION
|
|
455
|
+
|
|
456
|
+
```bash
|
|
457
|
+
# Install React 19 (required)
|
|
458
|
+
npm install react@^19
|
|
459
|
+
|
|
460
|
+
# Update to latest @ts-graphviz/react
|
|
461
|
+
npm install @ts-graphviz/react@latest
|
|
462
|
+
|
|
463
|
+
# Note: react-dom is no longer required
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
This release represents a strategic modernization to ensure long-term compatibility with React's ecosystem while providing improved performance and developer experience.
|
|
467
|
+
|
|
468
|
+
- [#1363](https://github.com/ts-graphviz/ts-graphviz/pull/1363) [`9328563`](https://github.com/ts-graphviz/ts-graphviz/commit/932856396ed0dede1dfc6737344a628f9667d07c) Thanks [@kamiazya](https://github.com/kamiazya)! - Adjust HTML label AST handling for consistent behavior #1335
|
|
469
|
+
|
|
470
|
+
Improves the handling of HTML-like labels in the `fromDot` and `toDot` functions to ensure valid Dot output.
|
|
471
|
+
|
|
472
|
+
### Patch Changes
|
|
473
|
+
|
|
474
|
+
- [#1363](https://github.com/ts-graphviz/ts-graphviz/pull/1363) [`9328563`](https://github.com/ts-graphviz/ts-graphviz/commit/932856396ed0dede1dfc6737344a628f9667d07c) Thanks [@kamiazya](https://github.com/kamiazya)! - Update Develop Environment
|
|
475
|
+
|
|
476
|
+
- Drop turbo
|
|
477
|
+
- Upgrade biome to 2.0
|
|
478
|
+
- Upgrade TypeScript to 5.8
|
|
479
|
+
- Upgrade Vite to 7.0
|
|
480
|
+
- Upgrade Vitest to 3.2
|
|
481
|
+
- Upgrade Peggy to 5.0 and drop ts-pegjs
|
|
482
|
+
- Implement new E2E test workflow
|
|
483
|
+
|
|
484
|
+
- [#1363](https://github.com/ts-graphviz/ts-graphviz/pull/1363) [`9328563`](https://github.com/ts-graphviz/ts-graphviz/commit/932856396ed0dede1dfc6737344a628f9667d07c) Thanks [@kamiazya](https://github.com/kamiazya)! - New GitHub Action main workflow and tests
|
|
485
|
+
|
|
486
|
+
- Updated dependencies [[`9328563`](https://github.com/ts-graphviz/ts-graphviz/commit/932856396ed0dede1dfc6737344a628f9667d07c), [`9328563`](https://github.com/ts-graphviz/ts-graphviz/commit/932856396ed0dede1dfc6737344a628f9667d07c), [`9328563`](https://github.com/ts-graphviz/ts-graphviz/commit/932856396ed0dede1dfc6737344a628f9667d07c), [`9328563`](https://github.com/ts-graphviz/ts-graphviz/commit/932856396ed0dede1dfc6737344a628f9667d07c), [`9328563`](https://github.com/ts-graphviz/ts-graphviz/commit/932856396ed0dede1dfc6737344a628f9667d07c)]:
|
|
487
|
+
- ts-graphviz@3.0.0
|
|
488
|
+
- @ts-graphviz/common@3.0.0
|
|
489
|
+
|
|
3
490
|
## 0.10.6
|
|
4
491
|
|
|
5
492
|
### Patch Changes
|