Skip to content

Commit

Permalink
Add a new document-based demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed Mar 4, 2024
1 parent f3ed533 commit 27e2f3b
Show file tree
Hide file tree
Showing 42 changed files with 438 additions and 1,239 deletions.
10 changes: 0 additions & 10 deletions Demo/Demo (iOS).entitlements

This file was deleted.

472 changes: 157 additions & 315 deletions Demo/Demo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

This file was deleted.

77 changes: 0 additions & 77 deletions Demo/Demo.xcodeproj/xcshareddata/xcschemes/Demo (iOS).xcscheme

This file was deleted.

77 changes: 0 additions & 77 deletions Demo/Demo.xcodeproj/xcshareddata/xcschemes/Demo (macOS).xcscheme

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,11 @@
<dict>
<key>SchemeUserState</key>
<dict>
<key>Demo (iOS).xcscheme_^#shared#^_</key>
<key>Demo.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>Demo (macOS).xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>2</integer>
</dict>
<key>RichTextKitTests.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>A9E50307283A23EE00BA5101</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>A9E5030D283A23EE00BA5101</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
19 changes: 12 additions & 7 deletions Demo/macOS/AboutCommand.swift → Demo/Demo/AboutCommand.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
//
// AboutCommand.swift
// Demo (macOS)
// Demo
//
// Created by Daniel Saidi on 2022-12-20.
// Copyright © 2022-2023 Daniel Saidi. All rights reserved.
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

#if os(macOS)
import SwiftUI

/**
This command customzies the system menu's about app option.
*/
/// This command customzies the app's About panel.
struct AboutCommand: Commands {

var body: some Commands {
Expand All @@ -31,11 +30,17 @@ extension Dictionary where Key == NSApplication.AboutPanelOptionKey, Value == An
[
.applicationName: "RichTextKit",
.credits: NSAttributedString(
string: "RichTextKit is an open-source tool for building rich text editor.",
string: "RichTextKit is an open-source SDK for working with rich text in Swift & SwiftUI.",
attributes: [
.font: NSFont.systemFont(ofSize: NSFont.smallSystemFontSize)
.font: NSFont.systemFont(ofSize: NSFont.smallSystemFontSize),
.paragraphStyle: {
let style = NSMutableParagraphStyle()
style.lineSpacing = 8
return style
}()
]
)
]
}
}
#endif
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
</dict>
</plist>
35 changes: 35 additions & 0 deletions Demo/Demo/DemoApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// DemoApp.swift
// Demo
//
// Created by Daniel Saidi on 2024-03-04.
// Copyright © 2024 Kankoda Sweden AB. All rights reserved.
//

import RichTextKit
import SwiftUI

@main
struct DemoApp: App {

var body: some Scene {

DocumentGroup(newDocument: DemoDocument()) { file in
DemoEditor(
document: file.$document
)
}
.commands {
SidebarCommands()
#if os(macOS)
AboutCommand()
#endif
RichTextCommand.FormatMenu()

CommandMenu("RichTextKit") {
DemoUrl.github.link
DemoUrl.documentation.link
}
}
}
}
41 changes: 41 additions & 0 deletions Demo/Demo/DemoDocument.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// DemoDocument.swift
// Demo
//
// Created by Daniel Saidi on 2024-03-04.
// Copyright © 2024 Kankoda Sweden AB. All rights reserved.
//

import SwiftUI
import RichTextKit
import UniformTypeIdentifiers

struct DemoDocument: FileDocument {

init(text: NSAttributedString = .empty) {
self.text = text
}

var text: NSAttributedString

static var readableContentTypes: [UTType] { [.archivedData] }

init(
configuration: ReadConfiguration
) throws {
guard
let data = configuration.file.regularFileContents
else {
throw CocoaError(.fileReadCorruptFile)
}
let text = try NSAttributedString(data: data, format: .archivedData)
self.text = text
}

func fileWrapper(
configuration: WriteConfiguration
) throws -> FileWrapper {
let data = try text.richTextData(for: .archivedData)
return .init(regularFileWithContents: data)
}
}
Loading

0 comments on commit 27e2f3b

Please sign in to comment.