Skip to content

Commit

Permalink
Add link support (#70)
Browse files Browse the repository at this point in the history
* Added link support

* removed unused logs

* Fix removal of link
  • Loading branch information
cp-divyesh-v authored Dec 23, 2024
1 parent d907b44 commit 868ebfe
Show file tree
Hide file tree
Showing 130 changed files with 5,196 additions and 4,049 deletions.
109 changes: 56 additions & 53 deletions RichEditorDemo/RichEditorDemo/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ struct ContentView: View {

}
)
.background(colorScheme == .dark ? .gray.opacity(0.3) : Color.white)
.background(
colorScheme == .dark ? .gray.opacity(0.3) : Color.white
)
.cornerRadius(10)

#if os(iOS)
Expand All @@ -58,21 +60,22 @@ struct ContentView: View {
)
#endif
}
#if iOS || macOS
.inspector(isPresented: $isInspectorPresented) {
RichTextFormat.Sidebar(context: state)
#if os(macOS)
.inspectorColumnWidth(min: 200, ideal: 200, max: 315)
#endif
}
#if os(iOS) || os(macOS)
.inspector(isPresented: $isInspectorPresented) {
RichTextFormat.Sidebar(context: state)
#if os(macOS)
.inspectorColumnWidth(
min: 200, ideal: 200, max: 315)
#endif
}
#endif
.padding(10)
#if iOS || os(macOS)
.toolbar {
ToolbarItemGroup(placement: .automatic) {
toolBarGroup
#if os(iOS) || os(macOS)
.toolbar {
ToolbarItemGroup(placement: .automatic) {
toolBarGroup
}
}
}
#endif
.background(colorScheme == .dark ? .black : .gray.opacity(0.07))
.navigationTitle("Rich Editor")
Expand All @@ -84,54 +87,54 @@ struct ContentView: View {
}
.focusedValue(\.richEditorState, state)
.toolbarRole(.automatic)
#if iOS || macOS || os(visionOS)
.richTextFormatSheetConfig(.init(colorPickers: colorPickers))
.richTextFormatSidebarConfig(
.init(
colorPickers: colorPickers,
fontPicker: isMac
#if os(iOS) || os(macOS) || os(visionOS)
.richTextFormatSheetConfig(.init(colorPickers: colorPickers))
.richTextFormatSidebarConfig(
.init(
colorPickers: colorPickers,
fontPicker: isMac
)
)
)
.richTextFormatToolbarConfig(.init(colorPickers: []))
.richTextFormatToolbarConfig(.init(colorPickers: []))
#endif
}
}

#if iOS || os(macOS)
var toolBarGroup: some View {
return Group {
RichTextExportMenu.init(
formatAction: { format in
exportFormat = format
},
otherOptionAction: { format in
otherExportFormat = format
}
)
#if !os(macOS)
.frame(width: 25, alignment: .center)
#endif
Button(
action: {
print("Exported JSON == \(state.outputAsString())")
},
label: {
Image(systemName: "printer.inverse")
#if os(iOS) || os(macOS)
var toolBarGroup: some View {
return Group {
RichTextExportMenu.init(
formatAction: { format in
exportFormat = format
},
otherOptionAction: { format in
otherExportFormat = format
}
)
#if !os(macOS)
.frame(width: 25, alignment: .center)
#endif
Button(
action: {
print("Exported JSON == \(state.outputAsString())")
},
label: {
Image(systemName: "printer.inverse")
}
)
#if !os(macOS)
.frame(width: 25, alignment: .center)
#endif
Toggle(isOn: $isInspectorPresented) {
Image.richTextFormatBrush
.resizable()
.aspectRatio(1, contentMode: .fit)
}
)
#if !os(macOS)
.frame(width: 25, alignment: .center)
#endif
Toggle(isOn: $isInspectorPresented) {
Image.richTextFormatBrush
.resizable()
.aspectRatio(1, contentMode: .fit)
#if !os(macOS)
.frame(width: 25, alignment: .center)
#endif
}
#if !os(macOS)
.frame(width: 25, alignment: .center)
#endif
}
}
#endif

func getBindingAlert() -> Binding<Bool> {
Expand Down
16 changes: 8 additions & 8 deletions RichEditorDemo/RichEditorDemo/JsonUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

import Foundation


internal func readJSONFromFile<T: Decodable>(fileName: String,
type: T.Type,
bundle: Bundle? = nil) -> T? {
internal func readJSONFromFile<T: Decodable>(
fileName: String,
type: T.Type,
bundle: Bundle? = nil
) -> T? {
if let url = (bundle ?? Bundle.main)
.url(forResource: fileName, withExtension: "json") {
.url(forResource: fileName, withExtension: "json")
{
do {
let data = try Data(contentsOf: url)
let decoder = JSONDecoder()
Expand All @@ -25,16 +27,14 @@ internal func readJSONFromFile<T: Decodable>(fileName: String,
return nil
}


internal class RichBundleFakeClass {}

internal extension Bundle {
extension Bundle {
static var richBundle: Bundle {
return Bundle(for: RichBundleFakeClass.self)
}
}


func encode<T: Encodable>(model: T?) throws -> String? {
guard let model else { return nil }
do {
Expand Down
2 changes: 1 addition & 1 deletion RichEditorDemo/RichEditorDemo/RichEditorDemoApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI
struct RichEditorDemoApp: App {
var body: some Scene {
WindowGroup {
ContentView()
ContentView()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import SwiftUI

public extension RichTextAction {
extension RichTextAction {

/**
This view modifier can apply keyboard shortcuts for any
Expand All @@ -16,7 +16,7 @@ public extension RichTextAction {
You can also apply it with the `.keyboardShortcut(for:)`
view modifier.
*/
struct KeyboardShortcutModifier: ViewModifier {
public struct KeyboardShortcutModifier: ViewModifier {

public init(_ action: RichTextAction) {
self.action = action
Expand All @@ -30,28 +30,30 @@ public extension RichTextAction {
}
}

public extension View {
extension View {

/// Apply a ``RichTextAction/KeyboardShortcutModifier``.
@ViewBuilder
func keyboardShortcut(for action: RichTextAction) -> some View {
#if iOS || macOS || os(visionOS)
switch action {
case .copy: keyboardShortcut("c", modifiers: .command)
case .dismissKeyboard: self
case .print: keyboardShortcut("p", modifiers: .command)
case .redoLatestChange: keyboardShortcut("z", modifiers: [.command, .shift])
// case .setAlignment(let align): keyboardShortcut(for: align)
case .stepFontSize(let points): keyboardShortcut(points < 0 ? "-" : "+", modifiers: .command)
case .stepIndent(let steps): keyboardShortcut(steps < 0 ? "Ö" : "Ä", modifiers: .command)
case .stepSuperscript: self
// case .toggleStyle(let style): keyboardShortcut(for: style)
case .undoLatestChange: keyboardShortcut("z", modifiers: .command)
default: self // TODO: Probably not defined, object to discuss.
}
#else
self
#endif
public func keyboardShortcut(for action: RichTextAction) -> some View {
#if os(iOS) || os(macOS) || os(visionOS)
switch action {
case .copy: keyboardShortcut("c", modifiers: .command)
case .dismissKeyboard: self
case .print: keyboardShortcut("p", modifiers: .command)
case .redoLatestChange:
keyboardShortcut("z", modifiers: [.command, .shift])
// case .setAlignment(let align): keyboardShortcut(for: align)
case .stepFontSize(let points):
keyboardShortcut(points < 0 ? "-" : "+", modifiers: .command)
case .stepIndent(let steps):
keyboardShortcut(steps < 0 ? "Ö" : "Ä", modifiers: .command)
case .stepSuperscript: self
// case .toggleStyle(let style): keyboardShortcut(for: style)
case .undoLatestChange: keyboardShortcut("z", modifiers: .command)
default: self // TODO: Probably not defined, object to discuss.
}
#else
self
#endif
}
}

Loading

0 comments on commit 868ebfe

Please sign in to comment.