mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-10-27 06:15:15 +00:00
feat(memory-graph): add onNodeSelect callback for selection changes (#1350)
This commit is contained in:
parent
d928490161
commit
3454a22554
3 changed files with 13 additions and 0 deletions
|
|
@ -66,6 +66,7 @@ function App() {
|
|||
| `error` | `Error \| null` | Error to display |
|
||||
| `loadMoreDocuments` | `() => Promise<void>` | Function to load more data |
|
||||
| `highlightDocumentIds` | `string[]` | IDs of documents to highlight |
|
||||
| `onNodeSelect` | `(nodeId: string \| null) => void` | Called when the selected node changes (click, keyboard, slideshow, or cleared) |
|
||||
|
||||
Console mode uses the supplied theme colors for its surface, 16px dot grid, document icons, and node fills and strokes. Consumer mode keeps its transparent surface and cluster colors.
|
||||
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ export function MemoryGraph({
|
|||
colors: colorOverrides,
|
||||
totalCount,
|
||||
onOpenDocument: externalOnOpenDocument,
|
||||
onNodeSelect,
|
||||
labels: labelOverrides,
|
||||
layering,
|
||||
appearance,
|
||||
|
|
@ -97,6 +98,15 @@ export function MemoryGraph({
|
|||
// React state only for things that affect DOM
|
||||
const [hoveredNode, setHoveredNode] = useState<string | null>(null)
|
||||
const [selectedNode, setSelectedNode] = useState<string | null>(null)
|
||||
const onNodeSelectRef = useRef(onNodeSelect)
|
||||
onNodeSelectRef.current = onNodeSelect
|
||||
const lastSelectedRef = useRef(selectedNode)
|
||||
// Compares against the last value so mount and StrictMode re-runs do not emit.
|
||||
useEffect(() => {
|
||||
if (lastSelectedRef.current === selectedNode) return
|
||||
lastSelectedRef.current = selectedNode
|
||||
onNodeSelectRef.current?.(selectedNode)
|
||||
}, [selectedNode])
|
||||
const [zoomDisplay, setZoomDisplay] = useState(50)
|
||||
// Monotonic counter that increments on any viewport change (pan or zoom)
|
||||
// Used as a dependency proxy to recalculate popover positions
|
||||
|
|
|
|||
|
|
@ -226,6 +226,8 @@ export interface MemoryGraphProps {
|
|||
totalCount?: number
|
||||
/** Callback when user wants to view full document content */
|
||||
onOpenDocument?: (documentId: string) => void
|
||||
/** Called when the selected node changes; null when cleared */
|
||||
onNodeSelect?: (nodeId: string | null) => void
|
||||
/** Custom user-facing labels (partial) - merged with defaults */
|
||||
labels?: MemoryGraphLabels
|
||||
/** Overlay layering controls */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue