Skip to content

LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。

TypeScript

fix: graph layout stays stable on node click — CameraStabilizer

nash_su73bd4db8c7de
diff --git a/src/components/graph/graph-view.tsx b/src/components/graph/graph-view.tsx
index 4e9c7571..721a008a 100644
--- a/src/components/graph/graph-view.tsx
+++ b/src/components/graph/graph-view.tsx
@@ -169,6 +169,46 @@ function EventHandler({ onNodeClick }: { onNodeClick: (nodeId: string) => void }
return null
}
+/**
+ * Prevents sigma from shifting the graph when the container resizes
+ * (e.g., when the right preview panel opens/closes).
+ * Saves camera state before resize and restores it after.
+ */
+function CameraStabilizer() {
+ const sigma = useSigma()
+ const cameraState = useRef<{ x: number; y: number; ratio: number } | null>(null)
+
+ useEffect(() => {
+ const container = sigma.getContainer()
+ if (!container) return
+
+ const observer = new ResizeObserver(() => {
+ // On resize, restore the previous camera state
+ if (cameraState.current) {
+ const cam = sigma.getCamera()
+ cam.setState(cameraState.current)
+ }
+ })
+
+ observer.observe(container)
+
+ // Continuously save camera state on any camera update
+ const handler = () => {
+ const cam = sigma.getCamera()
+ const state = cam.getState()
+ cameraState.current = { x: state.x, y: state.y, ratio: state.ratio }
+ }
+ sigma.getCamera().on("updated", handler)
+
+ return () => {
+ observer.disconnect()
+ sigma.getCamera().removeListener("updated", handler)
+ }
+ }, [sigma])
+
+ return null
+}
+
function ZoomControls() {
const sigma = useSigma()
@@ -224,7 +264,6 @@ export function GraphView() {
const [loading, setLoading] = useState(false)
const [error, setError] = useState<string | null>(null)
const [hoveredType, setHoveredType] = useState<string | null>(null)
- const [selectedNode, setSelectedNode] = useState<{ title: string; path: string; type: string; content: string } | null>(null)
const lastLoadedVersion = useRef(-1)
const loadGraph = useCallback(async () => {
@@ -256,13 +295,13 @@ export function GraphView() {
if (!node) return
try {
const content = await readFile(node.path)
- // Show inline preview instead of triggering right panel (avoids layout shift)
- setSelectedNode({ title: node.label, path: node.path, type: node.type, content })
+ setSelectedFile(node.path)
+ setFileContent(content)
} catch (err) {
console.error("Failed to open wiki page:", err)
}
},
- [nodes],
+ [nodes, setSelectedFile, setFileContent],
)
// Count nodes by type for legend
@@ -377,6 +416,7 @@ export function GraphView() {
>
<GraphLoader nodes={nodes} edges={edges} />
<EventHandler onNodeClick={handleNodeClick} />
+ <CameraStabilizer />
<ZoomControls />
</SigmaContainer>
@@ -410,44 +450,6 @@ export function GraphView() {
</div>
</div>
- {/* Inline node preview (avoids triggering right panel resize) */}
- {selectedNode && (
- <div className="shrink-0 border-t bg-background max-h-[40%] overflow-hidden flex flex-col">
- <div className="flex items-center justify-between px-3 py-1.5 border-b bg-muted/30">
- <div className="flex items-center gap-2 min-w-0">
- <span
- className="inline-block h-2.5 w-2.5 rounded-full shrink-0"
- style={{ backgroundColor: NODE_TYPE_COLORS[selectedNode.type] ?? NODE_TYPE_COLORS.other }}
- />
- <span className="text-sm font-medium truncate">{selectedNode.title}</span>
- <span className="text-[10px] text-muted-foreground shrink-0">{selectedNode.type}</span>
- </div>
- <div className="flex items-center gap-1 shrink-0">
- <button
- type="button"
- onClick={() => {
- setSelectedFile(selectedNode.path)
- setFileContent(selectedNode.content)
- }}
- className="rounded px-2 py-0.5 text-[11px] text-primary hover:bg-accent transition-colors"
- >
- Open in Preview
- </button>
- <button
- type="button"
- onClick={() => setSelectedNode(null)}
- className="rounded p-0.5 text-muted-foreground hover:bg-accent"
- >
- <span className="text-xs">✕</span>
- </button>
- </div>
- </div>
- <div className="flex-1 overflow-y-auto px-3 py-2 text-xs text-muted-foreground whitespace-pre-wrap font-mono leading-relaxed">
- {selectedNode.content.slice(0, 3000)}
- {selectedNode.content.length > 3000 && "\n\n[...click 'Open in Preview' for full content...]"}
- </div>
- </div>
- )}
</div>
)
}