You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: controllable highlight state for embedding hosts #4401
NMRium's highlight state is currently private to HighlightProvider / useHighlight. Embedding hosts (for example via nmrium-react-wrapper) sometimes need to drive that state from outside NMRium — typically across a cross-origin iframe with postMessage.
Proposed API
exportinterfaceNMRiumHighlightState{highlighted: string[];highlightedPermanently: string[];sourceData: HighlightEventSource|null;}interfaceNMRiumProps{// ...existing/** When provided, highlight state is controlled by the host. */highlight?: NMRiumHighlightState;/** Called for every highlight change, including internal hover/click. */onHighlightChange?: (state: NMRiumHighlightState)=>void;}
Leaving highlight out keeps today's behaviour unchanged (uncontrolled).
Implementation sketch
HighlightProvider accepts optional value / onChange.
In controlled mode, render from value; dispatch runs the existing reducer against a latest-state ref and calls onChange(next) instead of updating internal state.
Keep that ref in sync with each reduced value (not only with props), so consecutive dispatches such as the useHighlight unmount cleanup (HIDE then UNSET_PERMANENT) do not drop updates.
The internal highlights record can stay derived from highlighted and remain private.
Wire highlight / onHighlightChange from NMRiumProps through InnerNMRium into HighlightProvider.
Export NMRiumHighlightState (and HighlightEventSource if not already public).
Out of scope (separate discussion)
NMRium regenerates peak ids on load, so imported ids from a host never match. Hosts currently fall back to matching by nucleus + ppm. Keeping imported peak ids stable would let hosts highlight by id; that can be a follow-up.
Questions for the team
Is the controlled-prop shape preferred over an imperative NMRiumRefAPI.highlight(ids) / clearHighlight() method?
Any concern about onHighlightChange firing on every hover (performance for large spectra / embedding hosts)?
We would do it by adding a highlightedIds prop to highlight items in NMRium, and not follow the way you propose. I created a PR #4405 with the proper changes, and I would create a demo on nmrium.dev to show how to use it.
Activity
vcnainala commentedon Oct 4, 2026
Proposed implementation: #4402
vcnainala commentedon Oct 4, 2026
Also pushed a 2.8-line backport for React 18 hosts (nmrium-react-wrapper): branch
feat/controllable-highlight-v2.8on https://github.com/vcnainala/nmrium/tree/feat/controllable-highlight-v2.8 — same API as #4402.hamed-musallam commentedon Oct 5, 2026
We would do it by adding a
highlightedIdsprop to highlight items in NMRium, and not follow the way you propose. I created a PR #4405 with the proper changes, and I would create a demo on nmrium.dev to show how to use it.hamed-musallam commentedon Oct 6, 2026
closed #4405