You can solve this problem exactly the same way you would if you were using the classic editor. Use the hyperlink href
attributes. Most lightbox libraries already do this out of the box
In order to do this, you’ll need to tell the gallery to link to the media files. You can do this in the sidebar like this:
You can also register your own gallery block, then deregister the original