Skip to content

Commit

Permalink
fixing organization
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed Sep 9, 2024
1 parent 57ca6c8 commit ce89626
Show file tree
Hide file tree
Showing 39 changed files with 210 additions and 163 deletions.
36 changes: 31 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ let swiftSettings: [SwiftSetting] = [
SwiftSetting.enableExperimentalFeature("RegionBasedIsolation"),
SwiftSetting.enableExperimentalFeature("TransferringArgsAndResults"),
SwiftSetting.enableExperimentalFeature("VariadicGenerics"),

SwiftSetting.enableUpcomingFeature("FullTypedThrows"),
SwiftSetting.enableUpcomingFeature("InternalImportsByDefault"),

SwiftSetting.unsafeFlags([
"-Xfrontend",
"-warn-long-function-bodies=100"
Expand All @@ -35,21 +35,47 @@ let package = Package(
.library(
name: "RadiantKit",
targets: ["RadiantKit"]
),
.library(
name: "RadiantDocs",
targets: ["RadiantDocs"]
),
.library(
name: "RadiantPaging",
targets: ["RadiantPaging"]
),
.library(
name: "RadiantProgress",
targets: ["RadiantProgress"]
)
],
dependencies: [
.package(url: "https://github.com/swiftlang/swift-testing.git", from: "0.12.0"),
.package(url: "https://github.com/swiftlang/swift-testing.git", from: "0.12.0"),
],
targets: [
.target(
name: "RadiantKit",
swiftSettings: swiftSettings
),
.target(
name: "RadiantDocs",
dependencies: ["RadiantKit"],
swiftSettings: swiftSettings
),
.target(
name: "RadiantPaging",
dependencies: ["RadiantKit"],
swiftSettings: swiftSettings
),
.target(
name: "RadiantProgress",
swiftSettings: swiftSettings
),
.testTarget(
name: "RadiantKitTests",
dependencies: [
"RadiantKit",
.product(name: "Testing", package: "swift-testing")
"RadiantKit",
.product(name: "Testing", package: "swift-testing")
]
)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
public import SwiftUI

import UniformTypeIdentifiers

public import RadiantKit
public struct OpenAnyFilePanel {
let fileTypes: [FileType]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// CodablePackage.swift
// BushelKit
// RadiantKit
//
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
Expand Down Expand Up @@ -28,6 +28,7 @@
//

public import Foundation
public import RadiantKit

public protocol CodablePackage: Sendable, Codable {
static var decoder: JSONDecoder { get }
Expand Down
79 changes: 79 additions & 0 deletions Sources/RadiantDocs/CodablePackageDocument.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// CodablePackageDocument.swift
// RadiantKit
//
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//

#if canImport(SwiftUI)
#if os(macOS) || os(iOS) || os(visionOS)
public import Foundation

public import SwiftUI

public import UniformTypeIdentifiers

public struct CodablePackageDocument<T: CodablePackage>: FileDocument {
internal enum ReadError: Error { case missingConfigurationAtKey(String) }

public static var readableContentTypes: [UTType] { T.readableContentTypes.map(UTType.init) }

let configuration: T

public init(configuration: T) { self.configuration = configuration }

public init(configuration: ReadConfiguration) throws {
let regularFileContents = configuration.file.fileWrappers?[T.configurationFileWrapperKey]?
.regularFileContents
guard let configJSONWrapperData = regularFileContents else {
throw ReadError.missingConfigurationAtKey(T.configurationFileWrapperKey)
}

let configuration = try T.decoder.decode(T.self, from: configJSONWrapperData)
self.init(configuration: configuration)
}

public func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
let rootFileWrapper =
configuration.existingFile ?? FileWrapper(directoryWithFileWrappers: [:])

if let oldConfigJSONWrapper = rootFileWrapper.fileWrappers?[T.configurationFileWrapperKey] {
rootFileWrapper.removeFileWrapper(oldConfigJSONWrapper)
}

let newConfigJSONData = try T.encoder.encode(self.configuration)
let newConfigJSONWrapper = FileWrapper(regularFileWithContents: newConfigJSONData)
newConfigJSONWrapper.preferredFilename = T.configurationFileWrapperKey
rootFileWrapper.addFileWrapper(newConfigJSONWrapper)

return rootFileWrapper
}
}

extension CodablePackageDocument where T: InitializablePackage {
public init() { self.init(configuration: .init()) }
}
#endif
#endif
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
//

import Foundation
public import RadiantKit

public protocol FileTypeSpecification: Sendable { static var fileType: FileType { get } }
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// InitializablePackage.swift
// BushelKit
// RadiantKit
//
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,38 @@
//

#if canImport(SwiftUI)
#if os(macOS) || os(iOS) || os(visionOS)
public import Foundation

public import Foundation
public import SwiftUI

public import SwiftUI
fileprivate struct OpenFileURLKey: EnvironmentKey, Sendable {
typealias Value = OpenFileURLAction

fileprivate struct OpenFileURLKey: EnvironmentKey, Sendable {
typealias Value = OpenFileURLAction

static let defaultValue: OpenFileURLAction = .default
}
static let defaultValue: OpenFileURLAction = .default
}

public typealias OpenWindowURLAction = OpenWindowWithValueAction<URL>
public typealias OpenWindowURLAction = OpenWindowWithValueAction<URL>

public typealias OpenFileURLAction = OpenWindowURLAction
public typealias OpenFileURLAction = OpenWindowURLAction

extension EnvironmentValues {
public var openFileURL: OpenFileURLAction {
get { self[OpenFileURLKey.self] }
set { self[OpenFileURLKey.self] = newValue }
extension EnvironmentValues {
public var openFileURL: OpenFileURLAction {
get { self[OpenFileURLKey.self] }
set { self[OpenFileURLKey.self] = newValue }
}
}
}

extension Scene {
public func openFileURL(
_ closure: @escaping @Sendable @MainActor (URL, OpenWindowAction) -> Void
) -> some Scene { self.environment(\.openFileURL, .init(closure: closure)) }
}
extension Scene {
public func openFileURL(
_ closure: @escaping @Sendable @MainActor (URL, OpenWindowAction) -> Void
) -> some Scene { self.environment(\.openFileURL, .init(closure: closure)) }
}

@available(*, deprecated, message: "Use on Scene only.") extension View {
public func openFileURL(
_ closure: @Sendable @escaping @MainActor (URL, OpenWindowAction) -> Void
) -> some View { self.environment(\.openFileURL, .init(closure: closure)) }
}
@available(*, deprecated, message: "Use on Scene only.") extension View {
public func openFileURL(
_ closure: @Sendable @escaping @MainActor (URL, OpenWindowAction) -> Void
) -> some View { self.environment(\.openFileURL, .init(closure: closure)) }
}
#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@
//

#if canImport(SwiftUI)
#if os(macOS) || os(iOS) || os(visionOS)
import Foundation

import Foundation
public import SwiftUI

public import SwiftUI
public typealias OpenWindowWithAction = OpenWindowWithValueAction<Void>

public typealias OpenWindowWithAction = OpenWindowWithValueAction<Void>
@MainActor extension OpenWindowWithAction {
public init(closure: @escaping @Sendable @MainActor (OpenWindowAction) -> Void) {
self.init { _, action in closure(action) }
}

@MainActor extension OpenWindowWithAction {
public init(closure: @escaping @Sendable @MainActor (OpenWindowAction) -> Void) {
self.init { _, action in closure(action) }
@MainActor public func callAsFunction(with openWidow: OpenWindowAction) {
closure((), openWidow)
}
}

@MainActor public func callAsFunction(with openWidow: OpenWindowAction) {
closure((), openWidow)
}
}
#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,28 @@
//

#if canImport(SwiftUI)
#if os(macOS) || os(iOS) || os(visionOS)
import Foundation

import Foundation
public import SwiftUI

public import SwiftUI
public struct OpenWindowWithValueAction<ValueType: Sendable>: Sendable {
public static var `default`: Self {
.init { value, action in defaultClosure(value, with: action) }
}

public struct OpenWindowWithValueAction<ValueType: Sendable>: Sendable {
public static var `default`: Self {
.init { value, action in defaultClosure(value, with: action) }
}

let closure: @Sendable @MainActor (ValueType, OpenWindowAction) -> Void
public init(closure: @escaping @MainActor @Sendable (ValueType, OpenWindowAction) -> Void) {
self.closure = closure
}
let closure: @Sendable @MainActor (ValueType, OpenWindowAction) -> Void
public init(closure: @escaping @MainActor @Sendable (ValueType, OpenWindowAction) -> Void) {
self.closure = closure
}

private static func defaultClosure(_: ValueType, with _: OpenWindowAction) {
assertionFailure()
}
private static func defaultClosure(_: ValueType, with _: OpenWindowAction) {
assertionFailure()
}

@MainActor public func callAsFunction(_ value: ValueType, with openWidow: OpenWindowAction) {
closure(value, openWidow)
@MainActor public func callAsFunction(_ value: ValueType, with openWidow: OpenWindowAction) {
closure(value, openWidow)
}
}
}
#endif
#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// UTType.swift
// BushelKit
// RadiantKit
//
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
Expand Down Expand Up @@ -29,14 +29,13 @@

#if canImport(UniformTypeIdentifiers)
public import UniformTypeIdentifiers

public import RadiantKit
extension UTType {
public init(fileType: FileType) {
if fileType.isOwned {
self.init(exportedAs: fileType.utIdentifier)
}
else {
// swiftlint:disable:next force_unwrapping
self.init(fileType.utIdentifier)!
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import Foundation
#if canImport(AppKit)
import AppKit

// swiftlint:disable strict_fileprivate
fileprivate struct NSWindowAdaptorHostingView: NSViewRepresentable {
#warning(
"""
Expand Down Expand Up @@ -79,5 +78,5 @@ import Foundation
public func nsWindowAdaptor(_: @escaping (Any?) -> Void) -> some View { self }
}
#endif
// swiftlint:enable strict_fileprivate

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

fileprivate struct NSWindowDelegateAdaptorModifier: ViewModifier {
@Binding var binding: (any NSWindowDelegate)?
// swiftlint:disable:next weak_delegate
let delegate: any NSWindowDelegate

init(
Expand All @@ -44,7 +43,6 @@
self._binding = binding
self.delegate = binding.wrappedValue ?? delegate()

// swiftlint:disable:next line_length
#warning(
"Issue 100 - We can't set binding here - Modifying state during view update, this will cause undefined behavior."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@

extension AppStorage where Value: ExpressibleByNilLiteral {
public init<AppStoredType: AppStored>(for type: AppStoredType.Type, store: UserDefaults? = nil)
where
AppStoredType.Value == Value,
// swiftlint:disable:next discouraged_optional_boolean
Value == Bool?
{ self.init(type.key, store: store) }
where AppStoredType.Value == Value, Value == Bool? { self.init(type.key, store: store) }

public init<AppStoredType: AppStored>(for type: AppStoredType.Type, store: UserDefaults? = nil)
where AppStoredType.Value == Value, Value == Int? { self.init(type.key, store: store) }
Expand Down
Loading

0 comments on commit ce89626

Please sign in to comment.