Skip to content

Commit 868ebfe

Browse files
authored
Add link support (#70)
* Added link support * removed unused logs * Fix removal of link
1 parent d907b44 commit 868ebfe

File tree

130 files changed

+5196
-4049
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+5196
-4049
lines changed

RichEditorDemo/RichEditorDemo/ContentView.swift

+56-53
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ struct ContentView: View {
4646

4747
}
4848
)
49-
.background(colorScheme == .dark ? .gray.opacity(0.3) : Color.white)
49+
.background(
50+
colorScheme == .dark ? .gray.opacity(0.3) : Color.white
51+
)
5052
.cornerRadius(10)
5153

5254
#if os(iOS)
@@ -58,21 +60,22 @@ struct ContentView: View {
5860
)
5961
#endif
6062
}
61-
#if iOS || macOS
62-
.inspector(isPresented: $isInspectorPresented) {
63-
RichTextFormat.Sidebar(context: state)
64-
#if os(macOS)
65-
.inspectorColumnWidth(min: 200, ideal: 200, max: 315)
66-
#endif
67-
}
63+
#if os(iOS) || os(macOS)
64+
.inspector(isPresented: $isInspectorPresented) {
65+
RichTextFormat.Sidebar(context: state)
66+
#if os(macOS)
67+
.inspectorColumnWidth(
68+
min: 200, ideal: 200, max: 315)
69+
#endif
70+
}
6871
#endif
6972
.padding(10)
70-
#if iOS || os(macOS)
71-
.toolbar {
72-
ToolbarItemGroup(placement: .automatic) {
73-
toolBarGroup
73+
#if os(iOS) || os(macOS)
74+
.toolbar {
75+
ToolbarItemGroup(placement: .automatic) {
76+
toolBarGroup
77+
}
7478
}
75-
}
7679
#endif
7780
.background(colorScheme == .dark ? .black : .gray.opacity(0.07))
7881
.navigationTitle("Rich Editor")
@@ -84,54 +87,54 @@ struct ContentView: View {
8487
}
8588
.focusedValue(\.richEditorState, state)
8689
.toolbarRole(.automatic)
87-
#if iOS || macOS || os(visionOS)
88-
.richTextFormatSheetConfig(.init(colorPickers: colorPickers))
89-
.richTextFormatSidebarConfig(
90-
.init(
91-
colorPickers: colorPickers,
92-
fontPicker: isMac
90+
#if os(iOS) || os(macOS) || os(visionOS)
91+
.richTextFormatSheetConfig(.init(colorPickers: colorPickers))
92+
.richTextFormatSidebarConfig(
93+
.init(
94+
colorPickers: colorPickers,
95+
fontPicker: isMac
96+
)
9397
)
94-
)
95-
.richTextFormatToolbarConfig(.init(colorPickers: []))
98+
.richTextFormatToolbarConfig(.init(colorPickers: []))
9699
#endif
97100
}
98101
}
99102

100-
#if iOS || os(macOS)
101-
var toolBarGroup: some View {
102-
return Group {
103-
RichTextExportMenu.init(
104-
formatAction: { format in
105-
exportFormat = format
106-
},
107-
otherOptionAction: { format in
108-
otherExportFormat = format
109-
}
110-
)
111-
#if !os(macOS)
112-
.frame(width: 25, alignment: .center)
113-
#endif
114-
Button(
115-
action: {
116-
print("Exported JSON == \(state.outputAsString())")
117-
},
118-
label: {
119-
Image(systemName: "printer.inverse")
103+
#if os(iOS) || os(macOS)
104+
var toolBarGroup: some View {
105+
return Group {
106+
RichTextExportMenu.init(
107+
formatAction: { format in
108+
exportFormat = format
109+
},
110+
otherOptionAction: { format in
111+
otherExportFormat = format
112+
}
113+
)
114+
#if !os(macOS)
115+
.frame(width: 25, alignment: .center)
116+
#endif
117+
Button(
118+
action: {
119+
print("Exported JSON == \(state.outputAsString())")
120+
},
121+
label: {
122+
Image(systemName: "printer.inverse")
123+
}
124+
)
125+
#if !os(macOS)
126+
.frame(width: 25, alignment: .center)
127+
#endif
128+
Toggle(isOn: $isInspectorPresented) {
129+
Image.richTextFormatBrush
130+
.resizable()
131+
.aspectRatio(1, contentMode: .fit)
120132
}
121-
)
122-
#if !os(macOS)
123-
.frame(width: 25, alignment: .center)
124-
#endif
125-
Toggle(isOn: $isInspectorPresented) {
126-
Image.richTextFormatBrush
127-
.resizable()
128-
.aspectRatio(1, contentMode: .fit)
133+
#if !os(macOS)
134+
.frame(width: 25, alignment: .center)
135+
#endif
129136
}
130-
#if !os(macOS)
131-
.frame(width: 25, alignment: .center)
132-
#endif
133137
}
134-
}
135138
#endif
136139

137140
func getBindingAlert() -> Binding<Bool> {

RichEditorDemo/RichEditorDemo/JsonUtils.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77

88
import Foundation
99

10-
11-
internal func readJSONFromFile<T: Decodable>(fileName: String,
12-
type: T.Type,
13-
bundle: Bundle? = nil) -> T? {
10+
internal func readJSONFromFile<T: Decodable>(
11+
fileName: String,
12+
type: T.Type,
13+
bundle: Bundle? = nil
14+
) -> T? {
1415
if let url = (bundle ?? Bundle.main)
15-
.url(forResource: fileName, withExtension: "json") {
16+
.url(forResource: fileName, withExtension: "json")
17+
{
1618
do {
1719
let data = try Data(contentsOf: url)
1820
let decoder = JSONDecoder()
@@ -25,16 +27,14 @@ internal func readJSONFromFile<T: Decodable>(fileName: String,
2527
return nil
2628
}
2729

28-
2930
internal class RichBundleFakeClass {}
3031

31-
internal extension Bundle {
32+
extension Bundle {
3233
static var richBundle: Bundle {
3334
return Bundle(for: RichBundleFakeClass.self)
3435
}
3536
}
3637

37-
3838
func encode<T: Encodable>(model: T?) throws -> String? {
3939
guard let model else { return nil }
4040
do {

RichEditorDemo/RichEditorDemo/RichEditorDemoApp.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import SwiftUI
1111
struct RichEditorDemoApp: App {
1212
var body: some Scene {
1313
WindowGroup {
14-
ContentView()
14+
ContentView()
1515
}
1616
}
1717
}

Sources/RichEditorSwiftUI/Actions/RichTextAction+KeyboardShortcutModifier.swift

+24-22
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import SwiftUI
99

10-
public extension RichTextAction {
10+
extension RichTextAction {
1111

1212
/**
1313
This view modifier can apply keyboard shortcuts for any
@@ -16,7 +16,7 @@ public extension RichTextAction {
1616
You can also apply it with the `.keyboardShortcut(for:)`
1717
view modifier.
1818
*/
19-
struct KeyboardShortcutModifier: ViewModifier {
19+
public struct KeyboardShortcutModifier: ViewModifier {
2020

2121
public init(_ action: RichTextAction) {
2222
self.action = action
@@ -30,28 +30,30 @@ public extension RichTextAction {
3030
}
3131
}
3232

33-
public extension View {
33+
extension View {
3434

3535
/// Apply a ``RichTextAction/KeyboardShortcutModifier``.
3636
@ViewBuilder
37-
func keyboardShortcut(for action: RichTextAction) -> some View {
38-
#if iOS || macOS || os(visionOS)
39-
switch action {
40-
case .copy: keyboardShortcut("c", modifiers: .command)
41-
case .dismissKeyboard: self
42-
case .print: keyboardShortcut("p", modifiers: .command)
43-
case .redoLatestChange: keyboardShortcut("z", modifiers: [.command, .shift])
44-
// case .setAlignment(let align): keyboardShortcut(for: align)
45-
case .stepFontSize(let points): keyboardShortcut(points < 0 ? "-" : "+", modifiers: .command)
46-
case .stepIndent(let steps): keyboardShortcut(steps < 0 ? "Ö" : "Ä", modifiers: .command)
47-
case .stepSuperscript: self
48-
// case .toggleStyle(let style): keyboardShortcut(for: style)
49-
case .undoLatestChange: keyboardShortcut("z", modifiers: .command)
50-
default: self // TODO: Probably not defined, object to discuss.
51-
}
52-
#else
53-
self
54-
#endif
37+
public func keyboardShortcut(for action: RichTextAction) -> some View {
38+
#if os(iOS) || os(macOS) || os(visionOS)
39+
switch action {
40+
case .copy: keyboardShortcut("c", modifiers: .command)
41+
case .dismissKeyboard: self
42+
case .print: keyboardShortcut("p", modifiers: .command)
43+
case .redoLatestChange:
44+
keyboardShortcut("z", modifiers: [.command, .shift])
45+
// case .setAlignment(let align): keyboardShortcut(for: align)
46+
case .stepFontSize(let points):
47+
keyboardShortcut(points < 0 ? "-" : "+", modifiers: .command)
48+
case .stepIndent(let steps):
49+
keyboardShortcut(steps < 0 ? "Ö" : "Ä", modifiers: .command)
50+
case .stepSuperscript: self
51+
// case .toggleStyle(let style): keyboardShortcut(for: style)
52+
case .undoLatestChange: keyboardShortcut("z", modifiers: .command)
53+
default: self // TODO: Probably not defined, object to discuss.
54+
}
55+
#else
56+
self
57+
#endif
5558
}
5659
}
57-

0 commit comments

Comments
 (0)