Files
josh 9e09eb284a Add .shoegaze document type and rig/board sharing
Introduce a single shareable document type for rigs and boards:

- ShoeGazeDocument: versioned JSON envelope wrapping either a RigArchive
  (one or many rigs) or a BoardVersion, with a tolerant decoder that also
  reads the legacy bare-RigArchive and bare-ShoeGazeState shapes.
- Register the .shoegaze UTType (net.realizedsound.shoegaze, conforms to
  public.json) in all four demo app Info.plists.
- Migrate library export/import onto the envelope: exportDocumentData() and
  a decoder-tolerant importArchive(); RigFileDocument and the Builder
  exporter/importer now use .shoegaze. Internal per-rig and board-version
  files stay app-private JSON.
- Add OS share-sheet entries via SwiftUI ShareLink: Share per rig in the
  library sidebar, Share per version in the board editor, backed by the
  Transferable wrappers RigShareItem / BoardShareItem.

Tests: ShoeGazeDocument round-trip and legacy decode, library .shoegaze
export/import round-trip, and a board-document-imports-no-rigs case.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 17:49:20 -07:00

41 lines
1.3 KiB
Swift

// RigFileDocument.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import SwiftUI
import UniformTypeIdentifiers
/// A minimal `FileDocument` wrapping a ShoeGaze document's encoded bytes.
///
/// Used by ``ShoeGazeBuilderView``'s `.fileExporter` to write the result of
/// `RigLibraryStore.exportDocumentData()` (a `.shoegaze` ``ShoeGazeDocument``) to a user-chosen
/// location.
struct RigFileDocument: FileDocument {
/// Writes the `.shoegaze` document type.
static var writableContentTypes: [UTType] { [.shoeGaze] }
/// Reads `.shoegaze` documents and the legacy plain-JSON exports.
static var readableContentTypes: [UTType] { [.shoeGaze, .json] }
/// Encoded rig JSON.
let data: Data
/// Creates a document from already-encoded rig JSON.
init(data: Data) {
self.data = data
}
/// Decodes an existing document's bytes (required by `FileDocument`, unused by the exporter).
init(configuration: ReadConfiguration) throws {
self.data = configuration.file.regularFileContents ?? Data()
}
/// Writes the rig JSON into a file wrapper for export.
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
FileWrapper(regularFileWithContents: data)
}
}