feat: add highlightPeak action-request for host-driven peak highlighting - #315
Conversation
Allow embedding hosts to highlight a peak by id or nucleus+ppm over the existing nmr-wrapper:action-request channel, without reloading spectrum state.
Avoid import() return types, fix import order, and stop updating refs during render.
|
Hi Hamed, thanks for looking at this, and agreed: I don't want this to rely on hacks either. Why it's needed: In qm-nmr-calc, the results page shows the molecule (2D and 3D) and the list of calculated shifts in the host page, next to the NMRium iframe. When a user clicks an atom or a shift row, the matching calculated peak should be highlighted in NMRium. NMRium's highlight context works well when the trigger happens inside NMRium (hover a peak or an atom in its own structure panel). Here the trigger is outside, in a different document behind a cross-origin iframe, so On the implementation: You're right that we should not hack around the private highlight context. The bridge didn't keep a separate copy of the state (it dispatched into NMRium's own provider), but it did that by redirecting a private NMRium module through Vite and using internal reducer actions — exactly the coupling we should avoid. I also merged this before your review, which I shouldn't have done. I'm reverting it on Proposal: Make highlight state controllable in NMRium itself, along these lines:
I'll open an issue on cheminfo/nmrium with the proposed API, and re-implement the wrapper actions once that lands. Happy to adjust the shape once you and the team agree. |
Summary
highlightPeakandclearHighlightactions on the existingnmr-wrapper:action-requestchannel so hosts can highlight a peak by id or by nucleus + ppm.resolveIdredirect so highlighting works without reloading spectrum state.Test plan
/#/demo), click Test load from json, then Test highlight peak — one peak marker should thicken; Clear highlight should clear it.postMessage{ type: 'nmr-wrapper:action-request', data: { type: 'highlightPeak', params: { nucleus: '13C', ppm: 77.95 } } }and confirm the matching peak highlights.clearHighlightand confirm the sticky highlight is removed.nmr-wrapper:erroris emitted without breaking later actions.npm run check-typesnpx playwright test --project chromium -g "should highlight a peak"