Skip to content

Commit

Permalink
Adjust the remaining documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed Feb 16, 2024
1 parent fb7d7ec commit 931bfff
Show file tree
Hide file tree
Showing 47 changed files with 160 additions and 194 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ By deprecating these functions, we can simplify the library in 1.0, and focus mo
* `RichTextFormatToolbar` has new configuration and style types.
* `RichTextFormatSidebar` has new configuration and style types.
* `RichTextKeyboardToolbar` has a new config to always be shown.
* `RichTextStyle.Button` now supports using custom button styles.
* `RichTextView` has a new theme that lets you define its style.
* `RichTextViewComponent` has a new `hasRichTextStyle` function.
* `RichTextViewComponent` has a new `toggleRichTextStyle` function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2024 Daniel Saidi. All rights reserved.
//

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

public extension RichTextFormatToolbar {
Expand Down Expand Up @@ -53,3 +54,4 @@ public extension RichTextFormatToolbar.Configuration {
/// The standard rich text format toolbar configuration.
static var standard = Self.init()
}
#endif
2 changes: 2 additions & 0 deletions Sources/RichTextKit/Format/RichTextFormatToolbar+Style.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2024 Daniel Saidi. All rights reserved.
//

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

public extension RichTextFormatToolbar {
Expand Down Expand Up @@ -56,3 +57,4 @@ public extension EnvironmentValues {
set { self [RichTextFormatToolbar.StyleKey.self] = newValue }
}
}
#endif
2 changes: 2 additions & 0 deletions Sources/RichTextKit/Format/RichTextFormatToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

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

/**
Expand Down Expand Up @@ -208,3 +209,4 @@ struct RichTextFormatToolbar_Previews: PreviewProvider {
Preview()
}
}
#endif
2 changes: 2 additions & 0 deletions Sources/RichTextKit/Format/RichTextFormatToolbarBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2024 Daniel Saidi. All rights reserved.
//

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

/// This internal protocol is used to share code between the
Expand Down Expand Up @@ -167,3 +168,4 @@ extension RichTextFormatToolbarBase {
}
}
}
#endif
2 changes: 1 addition & 1 deletion Sources/RichTextKit/Images/Image+RichText.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-28.
// Copyright © 2022-2023 Daniel Saidi. All rights reserved.
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

import SwiftUI
Expand Down
12 changes: 3 additions & 9 deletions Sources/RichTextKit/Images/ImageRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
// RichTextKit
//
// Created by Daniel Saidi on 2022-05-28.
// Copyright © 2022-2023 Daniel Saidi. All rights reserved.
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

#if canImport(AppKit) && !targetEnvironment(macCatalyst)
import AppKit

/**
This typealias bridges platform-specific images to simplify
multi-platform support.
*/
/// This typealias bridges platform-specific image types.
public typealias ImageRepresentable = NSImage

public extension ImageRepresentable {
Expand All @@ -34,9 +31,6 @@ public extension ImageRepresentable {
#if canImport(UIKit)
import UIKit

/**
This typealias bridges platform-specific fonts, to simplify
multi-platform support.
*/
/// This typealias bridges platform-specific image types.
public typealias ImageRepresentable = UIImage
#endif
29 changes: 12 additions & 17 deletions Sources/RichTextKit/Images/RichTextImageAttachment.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-05.
// Copyright © 2022-2023 Daniel Saidi. All rights reserved.
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

#if iOS || os(tvOS) || os(visionOS)
Expand All @@ -27,37 +27,32 @@ import UniformTypeIdentifiers
overrides `image` on iOS and `attachmentCell` on macOS.

This is probably the wrong way to solve this problem, but I
haven't been able to find another way. If we set the `image`
property of a plain `NSTextAttachment`, it works to add and
load the attachment on the same platform, but trying to use
the attachment on other platforms will fail.
haven't been able to find another way. If we set `image` on
a plain `NSTextAttachment`, it can add and load attachments
on the same platform, but fails on other platforms.

Another problem with `NSTextAttachment`, is that it results
in large files, since it by default doesn't specify uniform
type identifier or compression, which makes it handle image
attachments as (potentially) huge png data. This attachment
allows you to easily use jpg with a custom compression rate
instead, which results in much smaller files.
attachments as huge png data. This attachment allows you to
easily use jpg with a custom compression rate instead.

# WARNING

If we use ``RichTextDataFormat/archivedData`` to persist an
image attachment in a string, we'll use an `NSKeyedArchiver`
to archive the data and an `NSKeyedUnarchiver` to unarchive
it. This requires that the attachment types that are stored
into the archive data exist when the data is unarchived. If
any type is missing, this unarchiving will fail. This means
that if you later decide to use another library to handle a
file that contains an ``RichTextImageAttachment``, you must
setup a custom class in the unarchiver, for instance:
image attachment, we'll use `NSKeyedArchiver` to archive it
and `NSKeyedUnarchiver` to unarchive it. This requires that
the types within the archive data still exist when the data
is unarchived. If any type is missing, you must register an
unarchiver class replacement like this:

```
let unarchiver = NSKeyedUnarchiver()
unarchiver.setClass(MyNewAttachment.self, forClassName: "...")`
```

You'll see the name of the missing class in the unarchiving
error, so just pop that name in as the class name.
error, so just use that name as the class name.
*/
open class RichTextImageAttachment: NSTextAttachment {

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-05.
// Copyright © 2022-2023 Daniel Saidi. All rights reserved.
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

import CoreGraphics
Expand All @@ -21,8 +21,8 @@ import AppKit
This protocol extends ``RichTextReader`` with functionality
for handling image attachments.

The protocol is implemented by `NSAttributedString` but can
be implemented by any `RichTextReader`.
The protocol is implemented by `NSAttributedString` and can
be implemented by any `RichTextReader` as well.
*/
public protocol RichTextImageAttachmentManager: RichTextReader {}

Expand Down
13 changes: 4 additions & 9 deletions Sources/RichTextKit/Images/RichTextImageAttachmentSize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
// 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 CoreGraphics

/**
This enum defines various ways to size images when they are
used in a rich text.
This enum defines various ways to size images in rich text.
*/
public enum RichTextImageAttachmentSize {

Expand All @@ -23,19 +22,15 @@ public enum RichTextImageAttachmentSize {

public extension RichTextImageAttachmentSize {

/**
The image's resulting height in a certain frame.
*/
/// The image's resulting height in a certain frame.
func height(in frame: CGRect) -> CGFloat {
switch self {
case .frame: frame.height
case .points(let points): points
}
}

/**
The image's resulting width in a certain frame.
*/
/// The image's resulting width in a certain frame.
func width(in frame: CGRect) -> CGFloat {
switch self {
case .frame: frame.width
Expand Down
14 changes: 10 additions & 4 deletions Sources/RichTextKit/Images/RichTextImageConfiguration.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 All @@ -14,7 +14,7 @@ import Foundation

The paste and drop configurations should be `.disabled` for
rich text formats that don't support inserting images, like
.txt and .rtf (where images must be added to a sub-folder).
`.txt` and `.rtf`.
*/
public struct RichTextImageConfiguration {

Expand All @@ -29,7 +29,10 @@ public struct RichTextImageConfiguration {
public init(
pasteConfiguration: RichTextImageInsertConfiguration,
dropConfiguration: RichTextImageInsertConfiguration,
maxImageSize: (width: RichTextImageAttachmentSize, height: RichTextImageAttachmentSize)
maxImageSize: (
width: RichTextImageAttachmentSize,
height: RichTextImageAttachmentSize
)
) {
self.pasteConfiguration = pasteConfiguration
self.dropConfiguration = dropConfiguration
Expand All @@ -40,7 +43,10 @@ public struct RichTextImageConfiguration {
public var dropConfiguration: RichTextImageInsertConfiguration

/// The max size to limit images in the text view to.
public var maxImageSize: (width: RichTextImageAttachmentSize, height: RichTextImageAttachmentSize)
public var maxImageSize: (
width: RichTextImageAttachmentSize,
height: RichTextImageAttachmentSize
)

/// The image configuration to use when pasting images.
public var pasteConfiguration: RichTextImageInsertConfiguration
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 @@ -14,8 +14,7 @@ import Foundation

The configuration is needed, since ``RichTextDataFormat/rtf``
and ``RichTextDataFormat/plainText`` doesn't support images
and a text view does not know the format of the string that
it contains.
and a text view doesn't know about the data format.
*/
public enum RichTextImageInsertConfiguration: Equatable {

Expand Down
30 changes: 14 additions & 16 deletions Sources/RichTextKit/Keyboard/RichTextKeyboardToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// RichTextKit
//
// Created by Daniel Saidi on 2022-12-14.
// Copyright © 2022-2023 Daniel Saidi. All rights reserved.
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

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

/**
Expand Down Expand Up @@ -47,7 +47,7 @@ public struct RichTextKeyboardToolbar<LeadingButtons: View, TrailingButtons: Vie
- leadingActions: The leading actions, by default `.undo`, `.redo` and `.copy`.
- trailingActions: The trailing actions, by default `.dismissKeyboard`.
- leadingButtons: The leading buttons to place after the leading actions.
- trailingButtons: The trailing buttons to place after the trailing actions.
- trailingButtons: The trailing buttons to place before the trailing actions.
- richTextFormatSheet: The rich text format sheet to use, given the default ``RichTextFormatToolbar``.
*/
public init(
Expand Down Expand Up @@ -124,10 +124,7 @@ public struct RichTextKeyboardToolbar<LeadingButtons: View, TrailingButtons: Vie

public var body: some View {
VStack(spacing: 0) {
HStack(spacing: style.itemSpacing) {
content
}
.padding(10)
content
}
.environment(\.sizeCategory, .medium)
.frame(height: style.toolbarHeight)
Expand All @@ -149,21 +146,19 @@ public struct RichTextKeyboardToolbar<LeadingButtons: View, TrailingButtons: Vie
}
}

extension UIApplication {
func endEditing() {
sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
}

private extension View {

@ViewBuilder
func prefersMediumSize() -> some View {
#if macOS
self
#else
if #available(iOS 16, *) {
self.presentationDetents([.medium])
} else {
self
}
#endif
}
}

Expand All @@ -176,9 +171,12 @@ private extension RichTextKeyboardToolbar {

@ViewBuilder
var content: some View {
leadingViews
Spacer()
trailingViews
HStack(spacing: style.itemSpacing) {
leadingViews
Spacer()
trailingViews
}
.padding(10)
}

var divider: some View {
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-12-13.
// Copyright © 2022 Dnaiel Saidi. All rights reserved.
// Copyright © 2022-2024 Dnaiel Saidi. All rights reserved.
//

#if iOS || os(visionOS)
Expand Down
6 changes: 2 additions & 4 deletions Sources/RichTextKit/Localization/RTKL10n.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
// KeyboardKit
//
// Created by Daniel Saidi on 2022-12-14.
// Copyright © 2022-2023 Daniel Saidi. All rights reserved.
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

import SwiftUI

/**
This enum defines RichTextKit-specific, localized texts.
*/
/// This enum defines RichTextKit-specific, localized texts.
public enum RTKL10n: String, CaseIterable, Identifiable {

case
Expand Down
2 changes: 1 addition & 1 deletion Sources/RichTextKit/Pasteboard/PasteboardImageReader.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-31.
// Copyright © 2022-2023 Daniel Saidi. All rights reserved.
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

import Foundation
Expand Down
Loading

0 comments on commit 931bfff

Please sign in to comment.