In iOS SwiftUI Document-based apps, how to show window of already opened document when trying to open the document a second time?

In a Document-based app, in SwiftUI (iOS 17), how to bring to front the window that shows an already open document, when trying to open the same document from the file browser, instead of opening a new window?

This is to prevent opening the document twice and being able to edit it in 2 different editors.

The official demo [1] does not handle this case.

[1] https://developer.apple.com/documentation/swiftui/building_a_document-based_app_with_swiftui

The newer demo, with SwiftData [2] doesn't handle opening a document twice properly either.

[2] https://developer.apple.com/documentation/swiftui/building-a-document-based-app-using-swiftdata

In iOS SwiftUI Document-based apps, how to show window of already opened document when trying to open the document a second time?
 
 
Q