File tree Expand file tree Collapse file tree 4 files changed +71
-1
lines changed
Sources/RichEditorSwiftUI Expand file tree Collapse file tree 4 files changed +71
-1
lines changed Original file line number Diff line number Diff line change 1+ //
2+ // PasteboardImageReader.swift
3+ // RichEditorSwiftUI
4+ //
5+ // Created by Divyesh Vekariya on 23/12/24.
6+ //
7+
8+ import Foundation
9+
10+ /**
11+ This protocol can be implemented by types that can fetch an
12+ image or multiple images from the pasteboard.
13+
14+ The protocol is implemented by the UIKit `UIPasteboard`, as
15+ well as the AppKit `NSPasteboard`.
16+ */
17+ public protocol PasteboardImageReader {
18+
19+ /// Get the first image in the pasteboard, if any.
20+ var image : ImageRepresentable ? { get }
21+
22+ /// Get all images in the pasteboard.
23+ var images : [ ImageRepresentable ] ? { get }
24+ }
25+
26+ public extension PasteboardImageReader {
27+
28+ /// Check whether or not the pasteboard han any images.
29+ var hasImages : Bool {
30+ guard let images = images else { return false }
31+ return !images. isEmpty
32+ }
33+ }
34+
35+ #if iOS || os(visionOS)
36+ import UIKit
37+
38+ extension UIPasteboard : PasteboardImageReader { }
39+ #endif
40+
41+ #if macOS
42+ import AppKit
43+
44+ extension NSPasteboard : PasteboardImageReader { }
45+
46+ public extension NSPasteboard {
47+
48+ /// Get the first image in the pasteboard, if any.
49+ var image : ImageRepresentable ? {
50+ images? . first
51+ }
52+
53+ /// Get all images in the pasteboard.
54+ var images : [ ImageRepresentable ] ? {
55+ readObjects ( forClasses: [ NSImage . self] ) as? [ NSImage ]
56+ }
57+ }
58+ #endif
Original file line number Diff line number Diff line change 1515 _ format: RichTextDataFormat ?
1616 ) {
1717 attributedString = . empty
18+ if let format, !imageConfigurationWasSet {
19+ imageConfiguration = standardImageConfiguration ( for: format)
20+ }
1821 attributedString = text
1922
2023 setContentCompressionResistancePriority (
Original file line number Diff line number Diff line change 3636 public var highlightingStyle : RichTextHighlightingStyle = . standard
3737
3838 /// The image configuration to use by the rich text view.
39- // public var imageConfiguration: RichTextImageConfiguration = .disabled
39+ public var imageConfiguration : RichTextImageConfiguration = . disabled {
40+ didSet { imageConfigurationWasSet = true }
41+ }
42+
43+ /// The image configuration to use by the rich text view.
44+ var imageConfigurationWasSet = false
4045
4146 // MARK: - Overrides
4247
Original file line number Diff line number Diff line change 8181 didSet {
8282 #if os(iOS) || os(visionOS)
8383 refreshDropInteraction ( )
84+ imageConfigurationWasSet = true
8485 #endif
8586 }
8687 }
8788
89+ /// The image configuration to use by the rich text view.
90+ var imageConfigurationWasSet = false
91+
8892 #if os(iOS) || os(visionOS)
8993
9094 /// The image drop interaction to use.
You can’t perform that action at this time.
0 commit comments