// A PICTURE DOOR (`create.doors[].pick`; Photos' Plus, 12 Nov 2026): Choose// photos opens the system's photo picker, as many as the person picks and of// the kinds the door names, and Take a photo opens the camera, which films// too when the door takes a clip. Neither reads the library: the picker runs// out of process and hands back only what was chosen, so Photos asks for no// library permission at all.//// What comes back is written to files (`capture.media` takes a path) and// handed to the share sheet's SAME intake, as a door's files are// (`DeckDoors.bring`): a picture or a clip is its branch 2, `capture.media`,// and lands on its photo or video, exactly where a share of it lands. The// written copies are this door's and go once the intake has staged them.importCottonKitimportPhotosUIimportSwiftUIimportUniformTypeIdentifiersextensionDeckDoors {/// The photo picker's filter for the kinds a door takes.staticfunc filter(_ kinds: [DefinitionPictureKind]) -> PHPickerFilter {let filters = kinds.map { kind -> PHPickerFilter inswitch kind {case .photo: .imagescase .video: .videos } }return filters.count == 1 ? filters[0] : .any(of: filters) }/// How many the photo picker lets the person choose: nil is no limit.staticfunc limit(_ pick: DefinitionCreatePick) -> Int? { pick.many ? nil : 1 }/// Whether the door's camera films as well as takes photographs.staticfunc films(_ pick: DefinitionCreatePick) -> Bool { pick.kinds.contains(.video) }/// One chosen item written to a file: a clip as the file the picker/// hands over (a film is too big to hold in memory), a photograph as its/// bytes in the type it was taken in (a HEIC stays a HEIC).staticfunc written(_ item: PhotosPickerItem) async -> URL? {if item.supportedContentTypes.contains(where: { $0.conforms(to: .movie) }) {returntry? await item.loadTransferable(type: PickedClip.self)?.url }returnawaitMediaStaging.stage(item)?.url }}/// A clip out of the photo picker, copied where this app may keep it until/// the intake has staged it.structPickedClip: Transferable {let url: URLstaticvar transferRepresentation: someTransferRepresentation {FileRepresentation(contentType: .movie) { clip inSentTransferredFile(clip.url) } importing: { received inlet ext = received.file.pathExtension.isEmpty ? "mov" : received.file.pathExtensionlet copy = FileManager.default.temporaryDirectory.appendingPathComponent("picked-clip-\(UUID().uuidString).\(ext)")tryFileManager.default.copyItem(at: received.file, to: copy)returnPickedClip(url: copy) } }}extensionView {/// A door's pictures (`create.doors[].pick`): while `picking` holds one,/// the photo picker or the camera, and what is chosen or taken handed to/// the share sheet's intake (`DeckDoors.bring`).func doorPictures(_ picking: Binding<DefinitionCreatePick?>, for table: String?) -> someView { modifier(DoorPictures(picking: picking, table: table)) }}structDoorPictures: ViewModifier { @Binding var picking: DefinitionCreatePick?/// The table whose door is open.let table: String? @State privatevar library = false @State privatevar limit: Int? = 1 @State privatevar filter: PHPickerFilter = .images @State privatevar chosen: [PhotosPickerItem] = [] @State privatevar camera = false @State privatevar films = false @Environment(\.shareIntake) privatevar shareIntake @Environment(\.cottonCore) privatevar core @Environment(\.cottonCapabilities) privatevar capabilities @Environment(ToastCenter.self) privatevar toasts: ToastCenter?func body(content: Content) -> someView { content .onChange(of: picking) { _, pick inguardlet pick else { return } picking = nilswitch pick.source {case .library: limit = DeckDoors.limit(pick) filter = DeckDoors.filter(pick.kinds) library = truecase .camera: films = DeckDoors.films(pick)Task { await openCamera() } } } .photosPicker(isPresented: $library, selection: $chosen, maxSelectionCount: limit, selectionBehavior: .ordered, matching: filter, preferredItemEncoding: .current) .onChange(of: chosen) { _, items in// Cleared first, so the same pictures chosen twice in a row still land.guard !items.isEmpty else { return } chosen = []Task { await bring(items) } } .fullScreenCover(isPresented: $camera) {CameraPicker(films: films, onTaken: { url in camera = falseTask { await bring([url]) } }, onCancelled: { camera = false }) } }/// The camera, or the sentence saying why not.privatefunc openCamera() async {iflet refusal = awaitCamera.refusal(capabilities) { toasts?.show(refusal, tone: .error)return } camera = true }privatefunc bring(_ items: [PhotosPickerItem]) async {var urls: [URL] = []for item in items {iflet url = awaitDeckDoors.written(item) { urls.append(url) } }if urls.count < items.count { toasts?.show(ShellLines.line("databases", "bring_in.unreadable"), tone: .error) }await bring(urls) }privatefunc bring(_ urls: [URL]) async {defer { for url in urls { try? FileManager.default.removeItem(at: url) } }awaitDeckDoors.bring(urls, for: table, through: shareIntake, toasts: toasts, core: core) }}