From 0b43dd39636aa1585664c13e3e2846a390e09dc8 Mon Sep 17 00:00:00 2001 From: Wesley de Groot Date: Thu, 6 Jun 2024 20:42:38 +0200 Subject: [PATCH] Improve documentation --- .gitignore | 3 ++ Sources/DynamicUI/AnyCodable.swift | 20 ++++++++++--- Sources/DynamicUI/DynamicUI.swift | 25 +++++++++++----- Sources/DynamicUI/UIComponent.swift | 24 +++++++-------- .../Views/DynamicDisclosureGroup.swift | 17 +++++++++-- Sources/DynamicUI/Views/DynamicDivider.swift | 15 +++++++++- Sources/DynamicUI/Views/DynamicForm.swift | 16 +++++++++- Sources/DynamicUI/Views/DynamicGauge.swift | 23 ++++++++++++-- Sources/DynamicUI/Views/DynamicGroupBox.swift | 18 +++++++++-- .../DynamicUI/Views/DynamicHSplitView.swift | 17 +++++++++-- Sources/DynamicUI/Views/DynamicHStack.swift | 18 +++++++++-- Sources/DynamicUI/Views/DynamicImage.swift | 20 +++++++++++-- Sources/DynamicUI/Views/DynamicLabel.swift | 18 +++++++++-- Sources/DynamicUI/Views/DynamicList.swift | 18 +++++++++-- .../Views/DynamicNavigationView.swift | 18 +++++++++-- Sources/DynamicUI/Views/DynamicPicker.swift | 22 ++++++++++++-- .../DynamicUI/Views/DynamicProgressView.swift | 25 ++++++++++++++-- .../DynamicUI/Views/DynamicScrollView.swift | 18 +++++++++-- .../Views/DynamicSecureTextField.swift | 29 ++++++++++++++++-- Sources/DynamicUI/Views/DynamicSlider.swift | 30 +++++++++++++++++-- Sources/DynamicUI/Views/DynamicSpacer.swift | 17 +++++++++-- Sources/DynamicUI/Views/DynamicTEMPLATE.swift | 21 +++++++++++-- Sources/DynamicUI/Views/DynamicText.swift | 19 ++++++++++-- .../DynamicUI/Views/DynamicTextEditor.swift | 29 ++++++++++++++++-- .../DynamicUI/Views/DynamicTextField.swift | 29 ++++++++++++++++-- Sources/DynamicUI/Views/DynamicToggle.swift | 27 +++++++++++++++-- .../DynamicUI/Views/DynamicVSplitView.swift | 18 +++++++++-- Sources/DynamicUI/Views/DynamicVStack.swift | 18 +++++++++-- Sources/DynamicUI/Views/DynamicZStack.swift | 18 +++++++++-- build_documentation.sh | 20 +++++++++++++ 30 files changed, 533 insertions(+), 77 deletions(-) create mode 100644 build_documentation.sh diff --git a/.gitignore b/.gitignore index fbd424d4ec..14ca66128a 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,6 @@ fastlane/test_output ### Code Injection iOSInjectionProject/ + +### Generated docs +docs/ \ No newline at end of file diff --git a/Sources/DynamicUI/AnyCodable.swift b/Sources/DynamicUI/AnyCodable.swift index 6d28d8876e..95f9e89e53 100644 --- a/Sources/DynamicUI/AnyCodable.swift +++ b/Sources/DynamicUI/AnyCodable.swift @@ -20,12 +20,18 @@ import Foundation /// let someOptionalCodable: AnyCodable? /// } /// ``` -enum AnyCodable { +public enum AnyCodable { + /// String value case string(String) + /// Integer value case int(Int) + /// Data value case data(Data) + /// Double value case double(Double) + /// Boolean value case bool(Bool) + /// No value case none enum AnyCodableError: Error { @@ -87,7 +93,7 @@ extension AnyCodable { /// Check if value is nil /// - Returns: nil if value is none/empty public func isNil() -> Bool { - if case let .none = self { + if case .none = self { return true } @@ -100,7 +106,10 @@ extension AnyCodable: Codable, Hashable { case string, int, data, double, bool } - init(from decoder: Decoder) throws { + /// Decode the values + /// + /// - Parameter decoder: + public init(from decoder: Decoder) throws { if let int = try? decoder.singleValueContainer().decode(Int.self) { self = .int(int) return @@ -131,7 +140,10 @@ extension AnyCodable: Codable, Hashable { self = .none } - func encode(to encoder: Encoder) throws { + /// Encode the values + /// + /// - Parameter encoder: Encoder + public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) switch self { case .string(let value): diff --git a/Sources/DynamicUI/DynamicUI.swift b/Sources/DynamicUI/DynamicUI.swift index e656603af5..a571cf6002 100644 --- a/Sources/DynamicUI/DynamicUI.swift +++ b/Sources/DynamicUI/DynamicUI.swift @@ -13,13 +13,22 @@ import SwiftUI /// DynamicUI /// /// DynamicUI is a SwiftUI View that can be used to display an interface based on JSON. -/// - Parameter json: JSON Data -/// - Returns: A SwiftUI View -public func DynamicUI(json: Data?) -> some View { - // swiftlint:disable:previous identifier_name - return AnyView( - InternalDynamicUI(json: json) - ) +public struct DynamicUI: View { + /// JSON data + public var json: Data? + + /// Initialize DynamicUI + /// - Parameter json: JSON data + public init(json: Data? = nil) { + self.json = json + } + + /// Generated body for SwiftUI + public var body: some View { + AnyView( + InternalDynamicUI(json: json) + ) + } } /// InternalDynamicUI (internal) @@ -38,7 +47,7 @@ struct InternalDynamicUI: View { /// This state is used to store the error message private var error: String? - /// Init + /// Initialize the InternalDynamicUI var body: some View { VStack { if let layout = layout { diff --git a/Sources/DynamicUI/UIComponent.swift b/Sources/DynamicUI/UIComponent.swift index b2c4af8817..76ee60c237 100644 --- a/Sources/DynamicUI/UIComponent.swift +++ b/Sources/DynamicUI/UIComponent.swift @@ -13,38 +13,38 @@ import SwiftUI /// This struct constructs a UI Component from JSON. public struct UIComponent: Codable, Hashable { /// Type of component - let type: String + public let type: String /// Text within component - let text: String? + public let text: String? /// Title of component - let title: String? + public let title: String? /// Default value of component - let defaultValue: AnyCodable? + public let defaultValue: AnyCodable? /// Styling of components (not yet used) - let styling: [[String: AnyCodable]]? + public let styling: [[String: AnyCodable]]? /// Parameters of component (not yet used) - let parameters: [[String: AnyCodable]]? + public let parameters: [[String: AnyCodable]]? /// Image URL - let imageURL: String? + public let imageURL: String? /// Children (used in VStack, HStack, ZStack) - let children: [UIComponent]? + public let children: [UIComponent]? /// Minumum value description - let minumum: String? + public let minumum: String? /// Minumum value - let minimumValue: Double? + public let minimumValue: Double? /// Maximum value description - let maximum: String? + public let maximum: String? /// Maximum value - let maximumValue: Double? + public let maximumValue: Double? } diff --git a/Sources/DynamicUI/Views/DynamicDisclosureGroup.swift b/Sources/DynamicUI/Views/DynamicDisclosureGroup.swift index 7a79e87fc4..c414630907 100644 --- a/Sources/DynamicUI/Views/DynamicDisclosureGroup.swift +++ b/Sources/DynamicUI/Views/DynamicDisclosureGroup.swift @@ -10,8 +10,20 @@ import SwiftUI -/// DynamicUI: DynamicDisclosureGroup +/// DynamicUI: DisclosureGroup +/// /// DynamicDisclosureGroup is a SwiftUI View that can be used to display an DisclosureGroup. +/// +/// JSON Example: +/// ```json +/// { +/// "type": "DisclosureGroup", +/// "children": [ ] +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. public struct DynamicDisclosureGroup: View { @Environment(\.internalDynamicUIEnvironment) /// Internal: dynamicUIEnvironment @@ -20,11 +32,12 @@ public struct DynamicDisclosureGroup: View { /// The component to display private let component: UIComponent - /// Init + /// Initialize the DynamicDisclosureGroup public init(_ component: UIComponent) { self.component = component } + /// Generated body for SwiftUI public var body: some View { DisclosureGroup("\(component.title ?? "")") { if let children = component.children { diff --git a/Sources/DynamicUI/Views/DynamicDivider.swift b/Sources/DynamicUI/Views/DynamicDivider.swift index 96031fd532..12823dc953 100644 --- a/Sources/DynamicUI/Views/DynamicDivider.swift +++ b/Sources/DynamicUI/Views/DynamicDivider.swift @@ -10,8 +10,19 @@ import SwiftUI -/// DynamicUI: DynamicDivider +/// DynamicUI: Divider +/// /// DynamicDivider is a SwiftUI View that can be used to display an Divider. +/// +/// JSON Example: +/// ```json +/// { +/// "type": "Divider" +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. public struct DynamicDivider: View { @Environment(\.internalDynamicUIEnvironment) /// Internal: dynamicUIEnvironment @@ -20,10 +31,12 @@ public struct DynamicDivider: View { /// The component to display private let component: UIComponent + /// Initialize the DynamicDivider init(_ component: UIComponent) { self.component = component } + /// Generated body for SwiftUI public var body: some View { Divider() } diff --git a/Sources/DynamicUI/Views/DynamicForm.swift b/Sources/DynamicUI/Views/DynamicForm.swift index a1557fd852..548ca4d267 100644 --- a/Sources/DynamicUI/Views/DynamicForm.swift +++ b/Sources/DynamicUI/Views/DynamicForm.swift @@ -10,8 +10,20 @@ import SwiftUI -/// DynamicUI: DynamicForm +/// DynamicUI: Form +/// /// DynamicForm is a SwiftUI View that can be used to display an Form. +/// +/// JSON Example: +/// ```json +/// { +/// "type": "Form", +/// "children": [ ] +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. public struct DynamicForm: View { @Environment(\.internalDynamicUIEnvironment) /// Internal: dynamicUIEnvironment @@ -20,10 +32,12 @@ public struct DynamicForm: View { /// The component to display private let component: UIComponent + /// Initialize the DynamicForm init(_ component: UIComponent) { self.component = component } + /// Generated body for SwiftUI public var body: some View { Form { if let children = component.children { diff --git a/Sources/DynamicUI/Views/DynamicGauge.swift b/Sources/DynamicUI/Views/DynamicGauge.swift index faa91fbccf..0f4bea5c89 100644 --- a/Sources/DynamicUI/Views/DynamicGauge.swift +++ b/Sources/DynamicUI/Views/DynamicGauge.swift @@ -10,9 +10,24 @@ import SwiftUI -/// DynamicUI: DynamicGauge -/// DynamicGauge is a SwiftUI View that can be used to display an Gauge. -struct DynamicGauge: View { +/// DynamicUI: Gauge +/// +/// ⚠ DynamicGauge is a SwiftUI View that can be used to display an Gauge. +/// +/// JSON Example: +/// ```json +/// { +/// "type": "Gauge", +/// "title": "Title", +/// "defaultValue": 0.5 +/// } +/// ``` +/// +/// - Warning: This component is not finished yet. +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicGauge: View { @Environment(\.internalDynamicUIEnvironment) /// Internal: dynamicUIEnvironment private var dynamicUIEnvironment @@ -24,11 +39,13 @@ struct DynamicGauge: View { /// The state of the Gauge private var state: Double + /// Initialize the DynamicGauge init(_ component: UIComponent) { self.state = component.defaultValue?.toDouble() ?? 0 self.component = component } + /// Generated body for SwiftUI public var body: some View { if #available(macOS 13.0, *) { Gauge(value: state) { diff --git a/Sources/DynamicUI/Views/DynamicGroupBox.swift b/Sources/DynamicUI/Views/DynamicGroupBox.swift index 07e07326fe..1cc48b1d56 100644 --- a/Sources/DynamicUI/Views/DynamicGroupBox.swift +++ b/Sources/DynamicUI/Views/DynamicGroupBox.swift @@ -10,9 +10,21 @@ import SwiftUI -/// DynamicUI: DynamicGroupBox +/// DynamicUI: GroupBox +/// /// DynamicGroupBox is a SwiftUI View that can be used to display an GroupBox. -struct DynamicGroupBox: View { +/// +/// JSON Example: +/// ```json +/// { +/// "type": "GroupBox", +/// "children": [ ] +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicGroupBox: View { @Environment(\.internalDynamicUIEnvironment) /// Internal: dynamicUIEnvironment private var dynamicUIEnvironment @@ -20,10 +32,12 @@ struct DynamicGroupBox: View { /// The component to display private let component: UIComponent + /// Initialize the DynamicGroupBox init(_ component: UIComponent) { self.component = component } + /// Generated body for SwiftUI public var body: some View { GroupBox { if let children = component.children { diff --git a/Sources/DynamicUI/Views/DynamicHSplitView.swift b/Sources/DynamicUI/Views/DynamicHSplitView.swift index 4ac1878c39..5bdae866c1 100644 --- a/Sources/DynamicUI/Views/DynamicHSplitView.swift +++ b/Sources/DynamicUI/Views/DynamicHSplitView.swift @@ -10,9 +10,20 @@ import SwiftUI -/// DynamicUI: DynamicHSplitView +/// DynamicUI: HSplitView +/// /// DynamicHSplitView is a SwiftUI View that can be used to display an HSplitView. -struct DynamicHSplitView: View { +/// JSON Example: +/// ```json +/// { +/// "type": "HSplitView", +/// "children": [ ] +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicHSplitView: View { @Environment(\.internalDynamicUIEnvironment) /// Internal: dynamicUIEnvironment private var dynamicUIEnvironment @@ -20,10 +31,12 @@ struct DynamicHSplitView: View { /// The component to display private let component: UIComponent + /// Initialize the DynamicHSplitView init(_ component: UIComponent) { self.component = component } + /// Generated body for SwiftUI public var body: some View { HSplitView { if let children = component.children { diff --git a/Sources/DynamicUI/Views/DynamicHStack.swift b/Sources/DynamicUI/Views/DynamicHStack.swift index d0d562d465..df037e0300 100644 --- a/Sources/DynamicUI/Views/DynamicHStack.swift +++ b/Sources/DynamicUI/Views/DynamicHStack.swift @@ -10,9 +10,21 @@ import SwiftUI -/// DynamicUI: DynamicHStack +/// DynamicUI: HStack +/// /// DynamicHStack is a SwiftUI View that can be used to display an HStack. -struct DynamicHStack: View { +/// +/// JSON Example: +/// ```json +/// { +/// "type": "HStack", +/// "children": [ ] +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicHStack: View { @Environment(\.internalDynamicUIEnvironment) /// Internal: dynamicUIEnvironment private var dynamicUIEnvironment @@ -20,10 +32,12 @@ struct DynamicHStack: View { /// The component to display private let component: UIComponent + /// Initialize the DynamicHStack init(_ component: UIComponent) { self.component = component } + /// Generated body for SwiftUI public var body: some View { HStack { if let children = component.children { diff --git a/Sources/DynamicUI/Views/DynamicImage.swift b/Sources/DynamicUI/Views/DynamicImage.swift index af1cf4c0b3..78b062f92d 100644 --- a/Sources/DynamicUI/Views/DynamicImage.swift +++ b/Sources/DynamicUI/Views/DynamicImage.swift @@ -10,9 +10,23 @@ import SwiftUI -/// DynamicUI: DynamicImage +/// DynamicUI: Image +/// /// DynamicImage is a SwiftUI View that can be used to display an image. -struct DynamicImage: View { +/// +/// JSON Example: +/// ```json +/// { +/// "type": "Image", +/// "imageURL": "systemName" +/// } +/// ``` +/// +/// - Note: The `imageURL` is the systemName of the image. +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicImage: View { @Environment(\.internalDynamicUIEnvironment) /// Internal: dynamicUIEnvironment private var dynamicUIEnvironment @@ -20,10 +34,12 @@ struct DynamicImage: View { /// The component to display private let component: UIComponent + /// Initialize the DynamicImage init(_ component: UIComponent) { self.component = component } + /// Generated body for SwiftUI public var body: some View { Image(systemName: component.imageURL ?? "") } diff --git a/Sources/DynamicUI/Views/DynamicLabel.swift b/Sources/DynamicUI/Views/DynamicLabel.swift index 7f5beb9199..13964330b1 100644 --- a/Sources/DynamicUI/Views/DynamicLabel.swift +++ b/Sources/DynamicUI/Views/DynamicLabel.swift @@ -10,9 +10,21 @@ import SwiftUI -/// DynamicUI: DynamicLabel +/// DynamicUI: Label +/// /// DynamicLabel is a SwiftUI View that can be used to display an Label. -struct DynamicLabel: View { +/// +/// JSON Example: +/// ```json +/// { +/// "type": "Label", +/// "title": "Title" +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicLabel: View { @Environment(\.internalDynamicUIEnvironment) /// Internal: dynamicUIEnvironment private var dynamicUIEnvironment @@ -20,10 +32,12 @@ struct DynamicLabel: View { /// The component to display private let component: UIComponent + /// Initialize the DynamicLabel init(_ component: UIComponent) { self.component = component } + /// Generated body for SwiftUI public var body: some View { Label(String("\(component.title)"), systemImage: component.imageURL ?? "") } diff --git a/Sources/DynamicUI/Views/DynamicList.swift b/Sources/DynamicUI/Views/DynamicList.swift index 3b8ea8f5cf..e43f2edad0 100644 --- a/Sources/DynamicUI/Views/DynamicList.swift +++ b/Sources/DynamicUI/Views/DynamicList.swift @@ -10,9 +10,21 @@ import SwiftUI -/// DynamicUI: DynamicList +/// DynamicUI: List +/// /// DynamicList is a SwiftUI View that can be used to display an List. -struct DynamicList: View { +/// +/// JSON Example: +/// ```json +/// { +/// "type": "List", +/// "children": [ ] +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicList: View { @Environment(\.internalDynamicUIEnvironment) /// Internal: dynamicUIEnvironment private var dynamicUIEnvironment @@ -20,10 +32,12 @@ struct DynamicList: View { /// The component to display private let component: UIComponent + /// Initialize the DynamicList init(_ component: UIComponent) { self.component = component } + /// Generated body for SwiftUI public var body: some View { List { if let children = component.children { diff --git a/Sources/DynamicUI/Views/DynamicNavigationView.swift b/Sources/DynamicUI/Views/DynamicNavigationView.swift index 0a4e2c526c..2d438f57a3 100644 --- a/Sources/DynamicUI/Views/DynamicNavigationView.swift +++ b/Sources/DynamicUI/Views/DynamicNavigationView.swift @@ -10,9 +10,21 @@ import SwiftUI -/// DynamicUI: DynamicNavigationView +/// DynamicUI: NavigationView +/// /// DynamicNavigationView is a SwiftUI View that can be used to display an NavigationView. -struct DynamicNavigationView: View { +/// +/// JSON Example: +/// ```json +/// { +/// "type": "Label", +/// "title": "Title" +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicNavigationView: View { @Environment(\.internalDynamicUIEnvironment) /// Internal: dynamicUIEnvironment private var dynamicUIEnvironment @@ -20,10 +32,12 @@ struct DynamicNavigationView: View { /// The component to display private let component: UIComponent + /// Initialize the DynamicNavigationView init(_ component: UIComponent) { self.component = component } + /// Generated body for SwiftUI public var body: some View { NavigationView { if let children = component.children { diff --git a/Sources/DynamicUI/Views/DynamicPicker.swift b/Sources/DynamicUI/Views/DynamicPicker.swift index acc88c5231..4a4f835012 100644 --- a/Sources/DynamicUI/Views/DynamicPicker.swift +++ b/Sources/DynamicUI/Views/DynamicPicker.swift @@ -10,22 +10,40 @@ import SwiftUI -/// DynamicUI: DynamicPicker +/// DynamicUI: Picker +/// /// DynamicPicker is a SwiftUI View that can be used to display an Picker. -struct DynamicPicker: View { +/// +/// JSON Example: +/// ```json +/// { +/// "type": "Picker", +/// "title": "Title", +/// "values": ["...", "...", ] +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicPicker: View { @Environment(\.internalDynamicUIEnvironment) + /// Internal: dynamicUIEnvironment private var dynamicUIEnvironment @State + /// The state of the picker private var state: Double + /// The component to display private let component: UIComponent + /// Initialize the DynamicPicker init(_ component: UIComponent) { self.state = component.defaultValue?.toDouble() ?? 0 self.component = component } + /// Generated body for SwiftUI public var body: some View { Picker(component.title ?? "", selection: $state) { if let children = component.children { diff --git a/Sources/DynamicUI/Views/DynamicProgressView.swift b/Sources/DynamicUI/Views/DynamicProgressView.swift index 585db27ce4..3cf38b3917 100644 --- a/Sources/DynamicUI/Views/DynamicProgressView.swift +++ b/Sources/DynamicUI/Views/DynamicProgressView.swift @@ -10,15 +10,36 @@ import SwiftUI -/// DynamicUI: DynamicProgressView +/// DynamicUI: ProgressView +/// /// DynamicProgressView is a SwiftUI View that can be used to display an progress view. -struct DynamicProgressView: View { +/// +/// JSON Example: +/// ```json +/// { +/// "type": "ProgressView", +/// "title": "Title", +/// "value": "50", +/// "total": "100" +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicProgressView: View { + @Environment(\.internalDynamicUIEnvironment) + /// Internal: dynamicUIEnvironment + private var dynamicUIEnvironment + + /// The component to display private let component: UIComponent + /// Initialize the DynamicProgressView init(_ component: UIComponent) { self.component = component } + /// Generated body for SwiftUI public var body: some View { ProgressView( "\(component.title ?? "")", diff --git a/Sources/DynamicUI/Views/DynamicScrollView.swift b/Sources/DynamicUI/Views/DynamicScrollView.swift index da495a1b98..4405b613f4 100644 --- a/Sources/DynamicUI/Views/DynamicScrollView.swift +++ b/Sources/DynamicUI/Views/DynamicScrollView.swift @@ -10,9 +10,21 @@ import SwiftUI -/// DynamicUI: DynamicScrollView +/// DynamicUI: ScrollView +/// /// DynamicScrollView is a SwiftUI View that can be used to display an ScrollView. -struct DynamicScrollView: View { +/// +/// JSON Example: +/// ```json +/// { +/// "type": "ScrollView", +/// "children": [ ] +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicScrollView: View { @Environment(\.internalDynamicUIEnvironment) /// Internal: dynamicUIEnvironment private var dynamicUIEnvironment @@ -20,10 +32,12 @@ struct DynamicScrollView: View { /// The component to display private let component: UIComponent + /// Initialize the DynamicScrollView init(_ component: UIComponent) { self.component = component } + /// Generated body for SwiftUI public var body: some View { ScrollView { if let children = component.children { diff --git a/Sources/DynamicUI/Views/DynamicSecureTextField.swift b/Sources/DynamicUI/Views/DynamicSecureTextField.swift index f9b30ddb82..be4e5bb093 100644 --- a/Sources/DynamicUI/Views/DynamicSecureTextField.swift +++ b/Sources/DynamicUI/Views/DynamicSecureTextField.swift @@ -10,17 +10,40 @@ import SwiftUI -/// DynamicUI: DynamicSecureField +/// DynamicUI: SecureField +/// /// DynamicSecureField is a SwiftUI View that can be used to display an SecureField. -struct DynamicSecureField: View { - @State private var state: String +/// +/// JSON Example: +/// ```json +/// { +/// "type": "SecureField", +/// "title": "Title", +/// "defaultValue": "Default Value" +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicSecureField: View { + @Environment(\.internalDynamicUIEnvironment) + /// Internal: dynamicUIEnvironment + var dynamicUIEnvironment + + @State + /// The state of the SecureField + private var state: String + + /// The component to display private let component: UIComponent + /// Initialize the DynamicSecureField init(_ component: UIComponent) { self.state = component.defaultValue?.toString() ?? "" self.component = component } + /// Generated body for SwiftUI public var body: some View { SecureField( "\(component.title ?? "")", diff --git a/Sources/DynamicUI/Views/DynamicSlider.swift b/Sources/DynamicUI/Views/DynamicSlider.swift index 41cc1b68f3..af35ee01c9 100644 --- a/Sources/DynamicUI/Views/DynamicSlider.swift +++ b/Sources/DynamicUI/Views/DynamicSlider.swift @@ -10,17 +10,41 @@ import SwiftUI -/// DynamicUI: DynamicSlider +/// DynamicUI: Slider +/// /// The DynamicSlider is a SwiftUI View that can be used to display a slider. -struct DynamicSlider: View { - @State private var state: Double +/// +/// JSON Example: +/// ```json +/// { +/// "type": "Slider", +/// "title": "Title", +/// "minLabel": "0", +/// "maxLabel": "100" +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicSlider: View { + @Environment(\.internalDynamicUIEnvironment) + /// Internal: dynamicUIEnvironment + private var dynamicUIEnvironment + + @State + /// The state of the Slider + private var state: Double + + /// The component to display private let component: UIComponent + /// Initialize the DynamicSlider init(_ component: UIComponent) { self.state = component.defaultValue?.toDouble() ?? 0 self.component = component } + /// Generated body for SwiftUI public var body: some View { Slider(value: $state) { Text("\(component.title ?? "")") diff --git a/Sources/DynamicUI/Views/DynamicSpacer.swift b/Sources/DynamicUI/Views/DynamicSpacer.swift index a8c1a9e8e8..4fe2fa3671 100644 --- a/Sources/DynamicUI/Views/DynamicSpacer.swift +++ b/Sources/DynamicUI/Views/DynamicSpacer.swift @@ -10,9 +10,20 @@ import SwiftUI -/// DynamicUI: DynamicSpacer +/// DynamicUI: Spacer +/// /// DynamicSpacer is a SwiftUI View that can be used to display an Spacer. -struct DynamicSpacer: View { +/// +/// JSON Example: +/// ```json +/// { +/// "type": "Spacer" +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicSpacer: View { @Environment(\.internalDynamicUIEnvironment) /// Internal: dynamicUIEnvironment private var dynamicUIEnvironment @@ -20,10 +31,12 @@ struct DynamicSpacer: View { /// The component to display private let component: UIComponent + /// Initialize the DynamicSpacer init(_ component: UIComponent) { self.component = component } + /// Generated body for SwiftUI public var body: some View { Spacer() } diff --git a/Sources/DynamicUI/Views/DynamicTEMPLATE.swift b/Sources/DynamicUI/Views/DynamicTEMPLATE.swift index 78533badb5..e02a8c366d 100644 --- a/Sources/DynamicUI/Views/DynamicTEMPLATE.swift +++ b/Sources/DynamicUI/Views/DynamicTEMPLATE.swift @@ -10,22 +10,39 @@ import SwiftUI -/// DynamicUI: DynamicTEMPLATE +/// DynamicUI: TEMPLATE +/// /// DynamicTEMPLATE is a SwiftUI View that can be used to display an TEMPLATE. -struct DynamicTEMPLATE: View { +/// +/// JSON Example: +/// ```json +/// { +/// "type": "TEMPLATE", +/// "title": "Title" +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicTEMPLATE: View { @Environment(\.internalDynamicUIEnvironment) + /// Internal: dynamicUIEnvironment private var dynamicUIEnvironment @State + /// The state of the TEMPLATE private var state: Double + /// The component to display private let component: UIComponent + /// Initialize the DynamicTEMPLATE init(_ component: UIComponent) { self.state = component.defaultValue?.toDouble() ?? 0 self.component = component } + /// Generated body for SwiftUI public var body: some View { EmptyView() } diff --git a/Sources/DynamicUI/Views/DynamicText.swift b/Sources/DynamicUI/Views/DynamicText.swift index 8221c9177b..b55c2e4ed6 100644 --- a/Sources/DynamicUI/Views/DynamicText.swift +++ b/Sources/DynamicUI/Views/DynamicText.swift @@ -10,9 +10,22 @@ import SwiftUI -/// DynamicUI: DynamicText +/// DynamicUI: Text +/// /// DynamicText is a SwiftUI View that can be used to display an Text. -struct DynamicText: View { +/// +/// +/// JSON Example: +/// ```json +/// { +/// "type": "Text", +/// "title": "Title" +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicText: View { @Environment(\.internalDynamicUIEnvironment) /// Internal: dynamicUIEnvironment private var dynamicUIEnvironment @@ -20,10 +33,12 @@ struct DynamicText: View { /// The component to display private let component: UIComponent + /// Initialize the DynamicText init(_ component: UIComponent) { self.component = component } + /// Generated body for SwiftUI public var body: some View { Text(component.title ?? "") } diff --git a/Sources/DynamicUI/Views/DynamicTextEditor.swift b/Sources/DynamicUI/Views/DynamicTextEditor.swift index 1d58e7fb20..3bba361914 100644 --- a/Sources/DynamicUI/Views/DynamicTextEditor.swift +++ b/Sources/DynamicUI/Views/DynamicTextEditor.swift @@ -10,17 +10,40 @@ import SwiftUI -/// DynamicUI: DynamicTextEditor +/// DynamicUI: TextEditor +/// /// DynamicTextEditor is a SwiftUI View that can be used to display an TextEditor. -struct DynamicTextEditor: View { - @State private var state: String +/// +/// JSON Example: +/// ```json +/// { +/// "type": "TextEditor", +/// "title": "Title", +/// "defaultValue": "Default Value" +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicTextEditor: View { + @Environment(\.internalDynamicUIEnvironment) + /// Internal: dynamicUIEnvironment + var dynamicUIEnvironment + + @State + /// The state of the TextEditor + private var state: String + + /// The component to display private let component: UIComponent + /// Initialize the DynamicTextEditor init(_ component: UIComponent) { self.state = component.defaultValue?.toString() ?? "" self.component = component } + /// Generated body for SwiftUI public var body: some View { TextEditor(text: $state) } diff --git a/Sources/DynamicUI/Views/DynamicTextField.swift b/Sources/DynamicUI/Views/DynamicTextField.swift index 4ef91435be..9fc3c9022d 100644 --- a/Sources/DynamicUI/Views/DynamicTextField.swift +++ b/Sources/DynamicUI/Views/DynamicTextField.swift @@ -10,17 +10,40 @@ import SwiftUI -/// DynamicUI: DynamicTextField +/// DynamicUI: TextField +/// /// DynamicTextField is a SwiftUI View that can be used to display an TextField. -struct DynamicTextField: View { - @State private var state: String +/// +/// JSON Example: +/// ```json +/// { +/// "type": "TextField", +/// "title": "Title", +/// "defaultValue": "Default Value" +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicTextField: View { + @Environment(\.internalDynamicUIEnvironment) + /// Internal: dynamicUIEnvironment + var dynamicUIEnvironment + + @State + /// The state of the TextField + private var state: String + + /// The component to display private let component: UIComponent + /// Initialize the DynamicTextField init(_ component: UIComponent) { self.state = component.defaultValue?.toString() ?? "" self.component = component } + /// Generated body for SwiftUI public var body: some View { TextField( "\(component.title ?? "")", diff --git a/Sources/DynamicUI/Views/DynamicToggle.swift b/Sources/DynamicUI/Views/DynamicToggle.swift index 780f4249e7..4a12acce38 100644 --- a/Sources/DynamicUI/Views/DynamicToggle.swift +++ b/Sources/DynamicUI/Views/DynamicToggle.swift @@ -10,18 +10,41 @@ import SwiftUI -/// DynamicUI: DynamicToggle +/// DynamicUI: Toggle +/// /// The DynamicToggle is a SwiftUI View that can be used to display a toggle. +/// +/// JSON Example: +/// ```json +/// { +/// "type": "Toggle", +/// "title": "Title", +/// "defaultValue": true +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. struct DynamicToggle: View { - @State private var state: Bool + @Environment(\.internalDynamicUIEnvironment) + /// Internal: dynamicUIEnvironment + var dynamicUIEnvironment + + @State + /// The state of the Toggle + private var state: Bool + + /// The title of the Toggle private let title: String + /// Initialize the DynamicToggle init(_ component: UIComponent) { self.title = component.title ?? "" self.state = component.defaultValue?.toBool() ?? false } + /// Generated body for SwiftUI public var body: some View { Toggle(isOn: $state) { Text(title) diff --git a/Sources/DynamicUI/Views/DynamicVSplitView.swift b/Sources/DynamicUI/Views/DynamicVSplitView.swift index cc67646994..d2c2a7442b 100644 --- a/Sources/DynamicUI/Views/DynamicVSplitView.swift +++ b/Sources/DynamicUI/Views/DynamicVSplitView.swift @@ -10,9 +10,21 @@ import SwiftUI -/// DynamicUI: DynamicVSplitView +/// DynamicUI: VSplitView +/// /// DynamicVSplitView is a SwiftUI View that can be used to display an VSplitView. -struct DynamicVSplitView: View { +/// +/// JSON Example: +/// ```json +/// { +/// "type": "VSplitView", +/// "children": [ ] +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicVSplitView: View { @Environment(\.internalDynamicUIEnvironment) /// Internal: dynamicUIEnvironment private var dynamicUIEnvironment @@ -20,10 +32,12 @@ struct DynamicVSplitView: View { /// The component to display private let component: UIComponent + /// Initialize the DynamicVSplitView init(_ component: UIComponent) { self.component = component } + /// Generated body for SwiftUI public var body: some View { VSplitView { if let children = component.children { diff --git a/Sources/DynamicUI/Views/DynamicVStack.swift b/Sources/DynamicUI/Views/DynamicVStack.swift index 09b46746e5..72b01dd84f 100644 --- a/Sources/DynamicUI/Views/DynamicVStack.swift +++ b/Sources/DynamicUI/Views/DynamicVStack.swift @@ -10,9 +10,21 @@ import SwiftUI -/// DynamicUI: DynamicVStack +/// DynamicUI: VStack +/// /// DynamicVStack is a SwiftUI View that can be used to display an VStack. -struct DynamicVStack: View { +/// +/// JSON Example: +/// ```json +/// { +/// "type": "VStack", +/// "children": [ ] +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicVStack: View { @Environment(\.internalDynamicUIEnvironment) /// Internal: dynamicUIEnvironment private var dynamicUIEnvironment @@ -20,10 +32,12 @@ struct DynamicVStack: View { /// The component to display private let component: UIComponent + /// Initialize the DynamicVStack init(_ component: UIComponent) { self.component = component } + /// Generated body for SwiftUI public var body: some View { VStack { if let children = component.children { diff --git a/Sources/DynamicUI/Views/DynamicZStack.swift b/Sources/DynamicUI/Views/DynamicZStack.swift index d08fa9f15a..cfbbd556cb 100644 --- a/Sources/DynamicUI/Views/DynamicZStack.swift +++ b/Sources/DynamicUI/Views/DynamicZStack.swift @@ -10,9 +10,21 @@ import SwiftUI -/// DynamicUI: DynamicZStack +/// DynamicUI: ZStack +/// /// DynamicZStack is a SwiftUI View that can be used to display an ZStack. -struct DynamicZStack: View { +/// +/// JSON Example: +/// ```json +/// { +/// "type": "ZStack", +/// "children": [ ] +/// } +/// ``` +/// +/// - Note: This is a internal view, you should not use this directly. \ +/// Use ``DynamicUI`` instead. this function is public to generate documentation. +public struct DynamicZStack: View { @Environment(\.internalDynamicUIEnvironment) /// Internal: dynamicUIEnvironment private var dynamicUIEnvironment @@ -20,10 +32,12 @@ struct DynamicZStack: View { /// The component to display private let component: UIComponent + /// Initialize the DynamicZStack init(_ component: UIComponent) { self.component = component } + /// Generated body for SwiftUI public var body: some View { ZStack { if let children = component.children { diff --git a/build_documentation.sh b/build_documentation.sh new file mode 100644 index 0000000000..c9fc6e1d8a --- /dev/null +++ b/build_documentation.sh @@ -0,0 +1,20 @@ +echo "package.dependencies.append(" >> Package.swift +echo " .package(url: \"https://github.com/apple/swift-docc-plugin\", from: \"1.0.0\")" >> Package.swift +echo ")" >> Package.swift + +swift package --allow-writing-to-directory docs \ + generate-documentation \ + --target `basename $PWD` \ + --disable-indexing \ + --output-path docs \ + --transform-for-static-hosting \ + --hosting-base-path . + +git stash -- Package.swift + +open http://localhost:8080/documentation/`basename $PWD` + +cd docs + +python3 -m http.server 8080 +