M0-M11 狩夜人笔记初始实现:11里程碑+86测试

This commit is contained in:
hunter-dev
2026-08-24 20:35:22 +08:00
commit 3ebd33536b
106 changed files with 10490 additions and 0 deletions
@@ -0,0 +1,38 @@
import { useEffect, useRef, useState } from 'react';
import { Graph } from '@antv/g6';
import { invoke } from '../../ipc-client';
import { IPC } from '@hunter/shared';
import type { GraphData } from '@hunter/shared';
import { useStore } from '../../store';
export function GraphView() {
const containerRef = useRef<HTMLDivElement>(null);
const [graph, setGraph] = useState<Graph | null>(null);
const { openDoc } = useStore();
useEffect(() => {
if (!containerRef.current) return;
const g = new Graph({
container: containerRef.current,
width: containerRef.current.clientWidth,
height: containerRef.current.clientHeight,
layout: { type: 'force', preventOverlap: true, nodeStrength: -50, linkDistance: 120 } as any,
node: { style: { size: 20, fill: (d: any) => d.color || '#4a9eff', labelText: (d: any) => d.title, labelFill: '#ddd' } } as any,
edge: { style: { stroke: '#555' } } as any,
behaviors: ['zoom-canvas', 'drag-canvas', 'drag-element'],
});
setGraph(g);
return () => { g.destroy(); };
}, []);
useEffect(() => {
if (!graph) return;
invoke(IPC.graph, undefined as never).then((data: GraphData) => {
graph.setData({ nodes: data.nodes.map(n => ({ id: n.id, ...n })), edges: data.edges.map(e => ({ source: e.source, target: e.target })) } as any);
graph.render();
});
graph.on('node:click', (e: any) => { openDoc(e.target.id); });
}, [graph]);
return <div ref={containerRef} style={{ flex: 1, background: '#111' }} />;
}