Skip to content

Conversation

@adamrdrew
Copy link
Owner

Motivation

  • Add first-class image support stored in SwiftData (CloudKit-backed) and addressable via takenote://image/<UUID> URLs for markdown preview and sharing.
  • Support user workflow of dragging an OS-supported image into a note to ingest it and insert a markdown image link, and ensure images are removed when no notes reference them.

Description

  • Introduce new SwiftData models NoteImage and NoteImageLink where NoteImage stores image bytes with @Attribute(.externalStorage), a mimeType, a uuid, and a referenceCount for simple garbage collection. (TakeNote/Models/NoteImage.swift, TakeNote/Models/NoteImageLink.swift).
  • Add @Relationship var imageLinks: [NoteImageLink]? to Note to track references from notes (model changes added to the app ModelContainer). (TakeNote/Models/Note.swift, TakeNote/TakeNoteApp.swift).
  • Implement NoteImageManager with ingestImage(from:note:), updateImageLinks(for:), and removeImageLinks(for:) to ingest files, parse takenote://image/<UUID> links, maintain reference counts, and delete unreferenced images. (TakeNote/Library/NoteImageManager.swift).
  • Register a custom URL protocol TakeNoteImageURLProtocol that serves image bytes for takenote://image/<UUID> requests by fetching the NoteImage from the SwiftData container; hook registration into app init via TakeNoteImageURLProtocolRegistrar.registerIfNeeded(container:). (TakeNote/Library/TakeNoteImageURLProtocol.swift, TakeNote/TakeNoteApp.swift).
  • Wire drag-and-drop image handling into the editor by adding a dropDestination(for: URL.self) and handleImageDrop which calls NoteImageManager.ingestImage and inserts ![](<takenote://image/UUID>) markdown links at caret or appended in preview. (TakeNote/Views/NoteEditor/NoteEditor.swift).
  • Ensure image link bookkeeping is updated when notes are processed (e.g. selection changes) via NoteImageManager.updateImageLinks and when notes are emptied from trash via NoteImageManager.removeImageLinks. (TakeNote/Views/NoteList/NoteList.swift, TakeNote/TakeNoteVM.swift).
  • Include the new models in the dev CloudKit bootstrap configuration and bump ckBootstrapVersionCurrent so the Dev schema can be updated. (TakeNote/TakeNoteApp.swift).

Testing

  • No automated tests were run against these changes.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant