Generate prosemirror doc out of selection

Hi, I would like to Generate prosemirror doc out of selection. What would be the easiest day to do it ?

Creating an empty doc with createAndFill, and then inserting the selection content in it with a Transform and replace should work.