How to make the widget store the value of a hidden field?

There is a requirement, after selecting a field, let it be displayed in the editor as a dom element. I have implemented this function with setbookmark, but I don’t know where to store the value of this field, because the name of the field is displayed. And there are quite a lot of such fields, all of which need to be done, but I don’t know what a good way is right now. Guys, please help me, thank you.
Below is the prototype

无标题

I also found two problems, that is, when the bookmark starts from the first character of the first line, it cannot be deleted by pressing the backspace key, and when multiple bookmarks are inserted continuously from other places, all the bookmarks will be deleted by pressing the backspace key, but I just want to To delete the one closest to the cursor, what should I do?

你这不应该是富文本编辑器吗和codemirror感觉关系不大呀

Maybe you can try the slatejs

但是我用的就是codemirror,看竞品上都是codemirror,不知道咋实现这功能