For equations and flowcharts, I would argue that the rendering is more important than the textual "code", so a "preview block" with rendered output would be very useful already.
A much better UI would be something like what you described, such as
- https://github.com/benrbray/prosemirror-math?tab=readme-ov-f...