feat(memory-graph): add onNodeSelect callback for selection changes#1350
Open
abhay-codes07 wants to merge 1 commit into
Open
feat(memory-graph): add onNodeSelect callback for selection changes#1350abhay-codes07 wants to merge 1 commit into
abhay-codes07 wants to merge 1 commit into
Conversation
Selection lived entirely inside MemoryGraph, so a host embedding the graph had no way to observe which node is selected outside of slideshow mode (onSlideshowNodeChange) or the open-document action (onOpenDocument). That makes common integrations awkward: driving a side panel, syncing selection to the URL, or firing analytics on select. Add an optional onNodeSelect(nodeId) prop that fires whenever the selection changes, regardless of source (click, keyboard navigation, slideshow, or clearing), with null when nothing is selected. It is emitted from an effect keyed on the selection state and reads the callback through a ref, so a changing callback identity does not re-fire it and the selection stays uncontrolled. The initial mount is skipped so a host does not receive a spurious null before any interaction. Purely additive and backward compatible.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
selectedNodelives entirely insideMemoryGraph. A host that embeds the graph currently has no way to observe which node is selected except throughonSlideshowNodeChange(slideshow mode only) oronOpenDocument(fires only on the explicit open-document action). So common integrations are awkward: showing details in the host's own side panel, syncing the selection into the URL, or firing analytics when a user selects a node.Change
Add an optional, backward-compatible
onNodeSelect?: (nodeId: string | null) => voidprop:It fires whenever the selection changes, regardless of source (click, keyboard navigation, slideshow, or clearing), with
nullwhen nothing is selected.Implementation notes:
onSlideshowNodeChangeRefpattern already used in this component.nullbefore any interaction.Verification
tsc --noEmitclean,vite buildsucceeds, and the full package suite (198 tests) passes. I did not add a unit test that drives a live selection because the fullMemoryGraphmount needs a real canvas/container size that happy-dom does not provide (the existingonSlideshowNodeChange/onOpenDocumentcallback props are untested for the same reason). Happy to wire this differently if you would prefer it emitted inline at the click/keyboard call sites instead of from the selection effect.