I've built a number of bidirectional editors, often with CodeMirror.
You could check out my bidirectional circuit design tool:
https://github.com/leomcelroy/svg-pcb
Paper on it here:
https://dl.acm.org/doi/abs/10.1145/3559400.3562004
Feel free to reach out if you have questions.