RichTextKit

1.0.0

RichTextKit is a Swift SDK that helps you use rich text in Swift and SwiftUI.
danielsaidi/RichTextKit

What's New

2024-03-28T19:22:10Z

This release removes all deprecated code and cleans up the library.

✨ Features

  • There are new view style and config modifiers for components.
  • RichTextFormat is a new namespace with format types and views.
  • RichTextContext has more intuitive ways to paste text content.
  • RichTextContext has a new observable paragraphStyle property.
  • RichTextInsertion has new static convenience insertion builders.
  • RichTextViewer is a new SwiftUI view that can be used to view rich text.

🐛 Bug Fixes

  • RichTextView no longer resets font and styles when setting up the macOS text view.

💥 Breaking Changes

  • All previously deprecated code has been deleted.
  • Many localization keys have been renamed to be easier to use.
  • RichTextContextFocusedValueKey is renamed to RichTextContext.FocusedValueKey.
  • RichTextEditor is now configured and styled with modifiers instead of the init.
  • RichTextFont pickers are now configured with a shared modifier instead of the init.
  • RichTextFont size picker is now configured with a shared modifier instead of the init.
  • RichTextFormat components are now configured with a shared modifier instead of the init.
  • RichTextFormatSheet has been renamed to RichTextFormat.Sheet to trim SDK surface area.
  • RichTextFormatSidebar has been renamed to RichTextFormat.Sidebar to trim SDK surface area.
  • RichTextFormatToolbar has been renamed to RichTextFormat.Toolbar to trim SDK surface area.
  • RichTextLine.SpacingPicker is now configured with a shared view modifier instead of the init.
  • RichTextKeyboardToolbar is now configured and styled with two view modifiers instead of the init.

RichTextKit Logo

Version Swift 5.9 Swift UI MIT License Twitter: @danielsaidi Mastodon: @danielsaidi@mastodon.social

About RichTextKit

RichTextKit is a Swift SDK that helps you use rich text in Swift and SwiftUI. It has a multi-platform SwiftUI RichTextEditor that can be added to any app:

This editor supports text styles (bold, italic, underline, etc.), fonts, font sizes, colors, text alignments, image attachments, and much more.

The RichTextEditor is powered by a multi-platform RichTextView that bridges UITextView and NSTextView and adds APIs to make them work more alike on all platforms.

If you just want to view rich text, you can use the RichTextViewer SwiftUI view.

Installation

RichTextKit can be installed with the Swift Package Manager:

https://github.com/danielsaidi/RichTextKit.git

Getting started

RichTextKit has a SwiftUI RichTextEditor that takes a text binding and a RichTextContext:

struct MyView: View {

    @State
    private var text = NSAttributedString(string: "Type here...")
    
    @StateObject
    var context = RichTextContext()

    var body: some View {
        RichTextEditor(text: $text, context: context) {
            // You can customize the native text view here
        }
        .focusedValue(\.richTextContext, context)
    }
}

The editor uses a RichTextCoordinator to sync changes between the editor, context, and platform-specific view. You can use the context to change font, colors, alignment etc. and observe context changes to update the UI.

If you just want to display rich text, you can use the RichTextViewer instead:

struct MyView: View {

    private var text = NSAttributedString(...)

    var body: some View {
        RichTextViewer(text: text)
    }
}

RichTextKit comes with a bunch of UI components, keyboard shortcuts & menu commands that make it easy to build a rich text editor.

For more information, please see the getting started guide.

Documentation

The online documentation has more information, articles, code examples, etc.

Demo Application

The demo app lets you explore the library on iOS and macOS. To try it out, just open and run the Demo project.

Sponsor my work

You can sponsor me on GitHub Sponsors or reach out for paid support, to help support my open-source projects.

Your support makes it possible for me to put more work into these projects and make them the best they can be.

Contact

Feel free to reach out if you have questions or want to contribute in any way:

License

RichTextKit is available under the MIT license. See the LICENSE file for more info.

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Fri May 17 2024 01:16:42 GMT-0900 (Hawaii-Aleutian Daylight Time)