Skip to content

Commit

Permalink
Update coordinator and export documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed Feb 15, 2024
1 parent 61c7726 commit 14f96b4
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,17 @@ extension RichTextCoordinator {
func setIsEditing(to newValue: Bool) {
if newValue == textView.isFirstResponder { return }
if newValue {
#if iOS || os(visionOS)
#if iOS || os(visionOS)
textView.becomeFirstResponder()
#else
#else
print("macOS currently doesn't resign first responder.")
#endif
#endif
} else {
#if iOS || os(visionOS)
#if iOS || os(visionOS)
textView.resignFirstResponder()
#else
#else
print("macOS currently doesn't resign first responder.")
#endif
#endif
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ extension RichTextCoordinator {
}
guard let attribute = color.attribute else { return }
if let applyRange {
self.textView.setRichTextColor(color, to: val, at: applyRange)
textView.setRichTextColor(color, to: val, at: applyRange)
} else {
self.textView.setRichTextAttribute(attribute, to: val)
textView.setRichTextAttribute(attribute, to: val)
}
}
}
Expand Down
21 changes: 8 additions & 13 deletions Sources/RichTextKit/Coordinator/RichTextCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RichTextKit
//
// Created by Daniel Saidi on 2022-05-22.
// Copyright © 2022-2023 Daniel Saidi. All rights reserved.
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

#if iOS || macOS || os(tvOS) || os(visionOS)
Expand All @@ -13,14 +13,13 @@ import SwiftUI
/**
This coordinator is used to keep a ``RichTextView`` in sync
with a ``RichTextContext``.
This is used by ``RichTextEditor`` to coordinate changes in
its context and the underlying text view.
The coordinator sets itself as the text view's delegate and
updates the context when things change in the text view. It
also subscribes to context observable changes and keeps the
text view in sync with these changes.
You can inherit this class to customize the coordinator for
your own use cases.
The coordinator sets itself as the text view's delegate. It
updates the context when things change in the text view and
syncs to context changes to the text view.
*/
open class RichTextCoordinator: NSObject {

Expand Down Expand Up @@ -171,11 +170,7 @@ extension RichTextCoordinator {
}
}

/**
Sync the rich text context with the text view after the
dispatch queue delay above. The delay will silence some
purple alert warnings about how state is updated.
*/
/// Sync the rich text context with the text view.
func syncContextWithTextViewAfterDelay() {
let styles = textView.richTextStyles

Expand Down
29 changes: 5 additions & 24 deletions Sources/RichTextKit/Data/NSAttributedString+Init.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,7 @@ public extension NSAttributedString {

private extension NSAttributedString {

/**
Try to parse ``RichTextDataFormat/archivedData`` data.
The data must have been generated with `NSKeyedArchiver`
and will be unarchived with a `NSKeyedUnarchiver`.
- Parameters:
- data: The data to initialize the string with.
*/
/// Try to parse ``RichTextDataFormat/archivedData``.
convenience init(archivedData data: Data) throws {
let unarchived = try NSKeyedUnarchiver.unarchivedObject(
ofClass: NSAttributedString.self,
Expand All @@ -51,12 +43,7 @@ private extension NSAttributedString {
self.init(attributedString: string)
}

/**
Try to parse ``RichTextDataFormat/plainText`` data.
- Parameters:
- data: The data to initialize the string with.
*/
/// Try to parse ``RichTextDataFormat/plainText`` data.
convenience init(plainTextData data: Data) throws {
let decoded = String(data: data, encoding: .utf8)
guard let string = decoded else {
Expand All @@ -66,9 +53,7 @@ private extension NSAttributedString {
self.init(attributedString: attributed)
}

/**
Try to parse ``RichTextDataFormat/rtf`` data.
*/
/// Try to parse ``RichTextDataFormat/rtf`` data.
convenience init(rtfData data: Data) throws {
var attributes = Self.rtfDataAttributes as NSDictionary?
try self.init(
Expand All @@ -78,9 +63,7 @@ private extension NSAttributedString {
)
}

/**
Try to parse ``RichTextDataFormat/rtfd`` data.
*/
/// Try to parse ``RichTextDataFormat/rtfd`` data.
convenience init(rtfdData data: Data) throws {
var attributes = Self.rtfdDataAttributes as NSDictionary?
try self.init(
Expand All @@ -91,9 +74,7 @@ private extension NSAttributedString {
}

#if macOS
/**
Try to parse ``RichTextDataFormat/word`` data.
*/
/// Try to parse ``RichTextDataFormat/word`` data.
convenience init(wordData data: Data) throws {
var attributes = Self.wordDataAttributes as NSDictionary?
try self.init(
Expand Down
8 changes: 2 additions & 6 deletions Sources/RichTextKit/Export/NSAttributedString+Export.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
// RichTextKit
//
// Created by Daniel Saidi on 2022-04-05.
// Copyright © 2022-2023 Daniel Saidi. All rights reserved.
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

import Foundation

extension NSAttributedString {

/**
Make all text in the attributed string black to account
for dark mode, otherwise this text will not be adaptive
when switching to dark mode.
*/
/// Make all text black to account for dark mode.
func withBlackText() -> NSAttributedString {
let mutable = NSMutableAttributedString(attributedString: self)
let range = mutable.safeRange(for: NSRange(location: 0, length: mutable.length))
Expand Down
6 changes: 3 additions & 3 deletions Sources/RichTextKit/Export/RichTextExportError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
// RichTextKit
//
// Created by Daniel Saidi on 2022-06-02.
// Copyright © 2022-2023 Daniel Saidi. All rights reserved.
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

import Foundation

/**
This enum defines errors that can be thrown when a file
manager fails to perform export operations.
This enum defines errors that can be thrown when failing to
export rich text.
*/
public enum RichTextExportError: Error {

Expand Down
9 changes: 2 additions & 7 deletions Sources/RichTextKit/Export/RichTextExportMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RichTextKit
//
// Created by Daniel Saidi on 2022-12-19.
// Copyright © 2022-2023 Daniel Saidi. All rights reserved.
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

#if iOS || macOS || os(visionOS)
Expand All @@ -14,12 +14,7 @@ import SwiftUI
a list of ``RichTextDataFormat`` values.
This menu uses a ``RichTextDataFormat/Menu`` configured for
exporting. It has customizable actions, to make it possible
to use it in any custom way.
You can use a custom ``RichTextDataFormat`` you can use its
`convertibleFormats` as `formats` init parameter, to get an
export menu for all other formats.
exporting, with customizable actions and data formats.
*/
public struct RichTextExportMenu: View {

Expand Down
8 changes: 2 additions & 6 deletions Sources/RichTextKit/Export/RichTextExportService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
// RichTextKit
//
// Created by Daniel Saidi on 2022-06-02.
// Copyright © 2022-2023 Daniel Saidi. All rights reserved.
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

import Foundation

/**
This protocol can be implemented by any classes that can be
used to export rich text files.
Exporting a file can be used to convert a rich text between
various formats. To share or print the text, consider using
a ``RichTextShareService`` instead.
used to export rich text to files.
*/
public protocol RichTextExportService: AnyObject {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RichTextKit
//
// Created by Daniel Saidi on 2022-06-02.
// Copyright © 2022-2023 Daniel Saidi. All rights reserved.
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/RichTextKit/Export/RichTextExportUrlResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RichTextKit
//
// Created by Daniel Saidi on 2022-06-02.
// Copyright © 2022-2023 Daniel Saidi. All rights reserved.
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

import Foundation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RichTextKit
//
// Created by Daniel Saidi on 2022-06-02.
// Copyright © 2022-2023 Daniel Saidi. All rights reserved.
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

import Foundation
Expand All @@ -12,9 +12,9 @@ import Foundation
This export service can be used to export rich text content
to files with a certain format.
Exported files are by default written to the app's document
folder, since the intent should be to export rich text with
another data format.
Files are by default written to the app document folder. It
can be changed by providing another searchpath directory in
the initializer.
*/
public class StandardRichTextExportService: RichTextExportService {

Expand Down

0 comments on commit 14f96b4

Please sign in to comment.