mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-11-14 09:01:45 +00:00
Merge b569fe2075 into 4d8a4ebfdd
This commit is contained in:
commit
a68e1bd3b4
3 changed files with 24 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) |
|
||||
|
||||
## Documentation
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ export function MemoryGraph({
|
|||
colors: colorOverrides,
|
||||
totalCount,
|
||||
onOpenDocument,
|
||||
onNodeSelect,
|
||||
labels: labelOverrides,
|
||||
layering,
|
||||
}: MemoryGraphProps) {
|
||||
|
|
@ -73,6 +74,21 @@ export function MemoryGraph({
|
|||
// Used as a dependency proxy to recalculate popover positions
|
||||
const [viewportVersion, setViewportVersion] = useState(0)
|
||||
|
||||
// Surface selection changes to the host without making selection controlled.
|
||||
// Keyed on selectedNode only; the callback is read through a ref so a changing
|
||||
// callback identity does not re-fire it. The initial mount is skipped so a
|
||||
// host does not receive a spurious null before any interaction.
|
||||
const onNodeSelectRef = useRef(onNodeSelect)
|
||||
onNodeSelectRef.current = onNodeSelect
|
||||
const hasEmittedSelectionRef = useRef(false)
|
||||
useEffect(() => {
|
||||
if (!hasEmittedSelectionRef.current) {
|
||||
hasEmittedSelectionRef.current = true
|
||||
return
|
||||
}
|
||||
onNodeSelectRef.current?.(selectedNode)
|
||||
}, [selectedNode])
|
||||
|
||||
// Limit documents so total node count (documents + their memories) stays under maxNodes
|
||||
const limitedDocuments = useMemo(() => {
|
||||
if (!maxNodes || documents.length === 0) return documents
|
||||
|
|
|
|||
|
|
@ -216,6 +216,13 @@ export interface MemoryGraphProps {
|
|||
totalCount?: number
|
||||
/** Callback when user wants to view full document content */
|
||||
onOpenDocument?: (documentId: string) => void
|
||||
/**
|
||||
* Called whenever the selected node changes, by click, keyboard navigation,
|
||||
* slideshow, or clearing the selection (nodeId is null when nothing is
|
||||
* selected). Lets a host observe selection without owning the state, e.g. to
|
||||
* drive a side panel or sync the URL.
|
||||
*/
|
||||
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