Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed Mar 4, 2024
1 parent 2ba2b51 commit e8aa17f
Show file tree
Hide file tree
Showing 22 changed files with 113 additions and 94 deletions.
9 changes: 5 additions & 4 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ This release removes all deprecated code and cleans up the library.

### ✨ Features

* There are new `richTextEditor` config and style view extensions.
* There are new `richTextKeyboardToolbar` config and style view extensions.
* There are new `richTextEditor` config and style view modifiers.
* There are new `richTextKeyboardToolbar` config and style view modifiers.

### 💥 Breaking Changes

* All previously deprecated code has been deleted.

* `RichTextEditor` is configured with view extensions instead of the initializer.
* `RichTextKeyboardToolbar` is configured with view extensions instead of the initializer.
* `RichTextContextFocusedValueKey` is renamed to `RichTextContext.FocusedValueKey`
* `RichTextEditor` is configured with view modifiers instead of the initializer.
* `RichTextKeyboardToolbar` is configured with view modifiers instead of the initializer.



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public extension RichTextAction {
``RichTextAction`` to any view.
You can also apply it with the `.keyboardShortcut(for:)`
view extension.
view modifier.
*/
struct KeyboardShortcutModifier: ViewModifier {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public extension RichTextAlignment {
``RichTextAlignment`` to any view.
You can also apply it with the `.keyboardShortcut(for:)`
view extension.
view modifier.
*/
struct KeyboardShortcutModifier: ViewModifier {

Expand Down
13 changes: 5 additions & 8 deletions Sources/RichTextKit/Alignment/RichTextAlignment+Picker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,11 @@ struct RichTextAlignment_Picker_Previews: PreviewProvider {
private var alignment = RichTextAlignment.left

var body: some View {
VStack(spacing: 10) {
RichTextAlignment.Picker(
selection: $alignment,
values: .all
)
.withPreviewPickerStyles()
}
.padding()
RichTextAlignment.Picker(
selection: $alignment,
values: .all
)
.withPreviewPickerStyles()
}
}

Expand Down
9 changes: 4 additions & 5 deletions Sources/RichTextKit/Context/RichTextContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ import Combine

/**
This observable context can be used to affect and observe a
``RichTextEditor`` and its content.
``RichTextEditor`` and its native text view.
Use ``handle(_:)`` to trigger actions, e.g. to change fonts,
text styles, text alignments, select a text range, etc.
You can observe the various published properties to keep an
app up to date with the current state. The ``RichTextEditor``
uses this with a ``RichTextCoordinator`` to keep it updated.
You can use ``RichTextContext/FocusedValueKey`` to handle a
context with focus in a multi-windowed app.
*/
public class RichTextContext: ObservableObject {

Expand Down
43 changes: 43 additions & 0 deletions Sources/RichTextKit/Context/RichTextContextFocusedValueKey.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// RichTextContextFocusedValueKey.swift
// RichTextKit
//
// Created by Daniel Saidi on 2022-12-19.
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

import SwiftUI

public extension RichTextContext {

/// This key can be used to keep track of a context in a
/// multi-windowed app.
struct FocusedValueKey: SwiftUI.FocusedValueKey {

public typealias Value = RichTextContext
}
}

public extension FocusedValues {

/// This value can be used to keep track of a context in
/// a multi-windowed app.
///
/// You can bind a context to a view with `focusedValue`:
///
/// ```swift
/// RichTextEditor(...)
/// .focusedValue(\.richTextContext, richTextContext)
/// ```
///
/// You can then access the context as a `@FocusedValue`:
///
/// ```swift
/// @FocusedValue(\.richTextContext)
/// var richTextContext: RichTextContext?
/// ```
var richTextContext: RichTextContext.FocusedValueKey.Value? {
get { self[RichTextContext.FocusedValueKey.self] }
set { self[RichTextContext.FocusedValueKey.self] = newValue }
}
}
14 changes: 6 additions & 8 deletions Sources/RichTextKit/Data/RichTextDataFormat+Menu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ public extension RichTextDataFormat {
struct RichTextData_FormatMenu_Previews: PreviewProvider {

static var previews: some View {
VStack {
RichTextDataFormat.Menu(
title: "Export...",
icon: .richTextExport,
formatAction: { _ in },
pdfAction: {}
)
}
RichTextDataFormat.Menu(
title: "Export...",
icon: .richTextExport,
formatAction: { _ in },
pdfAction: {}
)
}
}
#endif
2 changes: 1 addition & 1 deletion Sources/RichTextKit/Editor/RichTextEditor+Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2024 Daniel Saidi. All rights reserved.
//

#if iOS || macOS || os(visionOS)
#if iOS || macOS || os(tvOS) || os(visionOS)
import SwiftUI

/// This struct be used to configure a ``RichTextEditor``.
Expand Down
3 changes: 1 addition & 2 deletions Sources/RichTextKit/Editor/RichTextEditor+Style.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//


#if iOS || macOS || os(visionOS)
#if iOS || macOS || os(tvOS) || os(visionOS)
import SwiftUI

/// This struct can be used to style a ``RichTextEditor``.
Expand Down Expand Up @@ -37,5 +37,4 @@ public extension EnvironmentValues {
set { self [RichTextEditorStyle.Key.self] = newValue }
}
}

#endif
4 changes: 2 additions & 2 deletions Sources/RichTextKit/Editor/RichTextEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import SwiftUI
This will not show anything. To work around this limitation,
use a ``RichTextKeyboardToolbar`` instead.
You can configure and style the view by applying config and
style view extensions to your view hierarchy:
You can configure and style the view by applying its config
and style view modifiers to your view hierarchy:
```swift
VStack {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//
// RichTextView+Config_AppKit.swift
// RichTextKit
//
// Created by Dominik Bucher on 13.02.2024.
// Created by Daniel Saidi on 2024-01-16.
// Copyright © 2024 Daniel Saidi. All rights reserved.
//

#if macOS
Expand Down
46 changes: 0 additions & 46 deletions Sources/RichTextKit/Focus/RichTextContextFocusedValueKey.swift

This file was deleted.

42 changes: 35 additions & 7 deletions Sources/RichTextKit/Fonts/RichTextFont+Picker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,42 @@ struct RichTextFont_Picker_Previews: PreviewProvider {
extension View {

func withPreviewPickerStyles() -> some View {
VStack(spacing: 10) {
NavigationView {
VStack(spacing: 10) {
self.label("Default")
self.pickerStyle(.automatic).label(".automatic")
self.pickerStyle(.inline).label(".inline")
#if iOS || macOS
self.pickerStyle(.menu).label(".menu")
#endif
if #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) {
pickerStyle(.navigationLink).label(".navigationLink")
}
#if iOS || macOS
if #available(iOS 17.0, macOS 14.0, watchOS 10.0, *) {
pickerStyle(.palette).label(".palette")
}
#endif
#if iOS || macOS || os(tvOS) || os(visionOS)
self.pickerStyle(.segmented).label(".segmented")
#endif
#if iOS || macOS
pickerStyle(.wheel).label(".wheel")
#endif
}
}
}
}

private extension View {

func label(_ title: String) -> some View {
VStack {
Text(title)
.font(.footnote)
.foregroundStyle(.secondary)
self
self.pickerStyle(.inline)
#if iOS || macOS
self.pickerStyle(.menu)
#elseif iOS || macOS || os(tvOS) || os(visionOS)
self.pickerStyle(.segmented)
#endif
Divider()
}
}
}
4 changes: 3 additions & 1 deletion Sources/RichTextKit/Fonts/RichTextFont+PickerFont.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public extension RichTextFont {
*/
struct PickerFont: Identifiable, Equatable {

public init(fontName: String) {
public init(
fontName: String
) {
let fontName = fontName.capitalized
self.fontName = fontName
self.fontDisplayName = ""
Expand Down
4 changes: 2 additions & 2 deletions Sources/RichTextKit/Keyboard/RichTextKeyboardToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ import SwiftUI
`$0` to use these standard views, or return any custom view
that you want to use instead.
You can configure and style the view by applying config and
style view extensions to your view hierarchy:
You can configure and style the view by applying its config
and style view modifiers to your view hierarchy:
```swift
VStack {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Bundle+RichTextKit.swift
// Bundle+Locale.swift
// RichTextKit
//
// Created by Daniel Saidi on 2022-08-21.
Expand Down
4 changes: 0 additions & 4 deletions Sources/RichTextKit/RichTextKit.docc/RichTextKit.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ RichTextKit is available under the MIT license. See the [LICENSE][License] file
- ``StandardRichTextExportService``
- ``StandardRichTextExportUrlResolver``

### Focus

- ``RichTextContextFocusedValueKey``

### Fonts

- ``FontRepresentable``
Expand Down

0 comments on commit e8aa17f

Please sign in to comment.