Image uploading placeholder for multiple images

I’m building and editor that allows uploading multiple files at the same time. It’s based on: ProseMirror upload example However that example allows to upload only one image at a time. I found that I can not replace placeholders one by one, because after the first replacement all placeholders are gone. I managed to add uploaded images before placeholders list by doing:

              const found = this.props.findPlaceholder(view.state, id)
              if (!found) return
              const pos = found.from

              // Otherwise, insert it at the placeholder's position, and remove
              // the placeholder
                    pos - 1,
                      src: url,
                      file: response,
                  .setMeta(this, { remove: { id } })

However, when there’s a text right before insertion image will be inserted before the last letter of that text. How can I add an image right before placeholders but after any node that’s also before placeholders? Also how could I approach replacing the exact placeholder that was changed, so that for example images 1 and 3 are loaded and 2 is loading so it should show placeholder between two images?

Are you assigned the placeholders created for the images uploaded at the same time different ids? I can’t really say much about what might be going wrong from your description.

Each placeholder has different id generated by nanoid(). Now that I checked behaviour on ProseMirror upload example it pushes loaded files at the beginning of placeholders. In my case I hade to replace

.replaceWith(pos, pos, 


                    pos - 1,

because with replaceWith after first image loaded it replaced all placeholders. The only difference is that I use not inline images, unlike on that example. I made an example from that upload example that allows adding multiple files.

Now how to make it so that if image loads of which placeholder is inside of list it will be put in that exact position where placeholder was and not at the beginning of list?