Created
May 17, 2024 14:05
-
-
Save geriux/0dd48010d89171a7919496ddc0e45b24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Gutenberg | |
import Aztec | |
import React | |
class GutenbergView: UIViewController { | |
fileprivate lazy var gutenberg = Gutenberg(dataSource: self, extraModules: []) | |
fileprivate var htmlContent: String? | |
override func loadView() { | |
view = gutenberg.rootView | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
gutenberg.delegate = self | |
} | |
@objc public func requestHTML() { | |
gutenberg.requestHTML() | |
} | |
@objc public func getHTML() -> String { | |
return htmlContent ?? "" | |
} | |
} | |
extension GutenbergView: GutenbergBridgeDataSource { | |
func aztecAttachmentDelegate() -> (any Aztec.TextViewAttachmentDelegate)? { | |
return nil | |
} | |
class EditorSettings: GutenbergEditorSettings { | |
var isFSETheme: Bool = true | |
var galleryWithImageBlocks: Bool = true | |
var quoteBlockV2: Bool = true | |
var listBlockV2: Bool = true | |
var rawStyles: String? = nil | |
var rawFeatures: String? = nil | |
var colors: [[String: String]]? = nil | |
var gradients: [[String: String]]? = nil | |
} | |
func gutenbergInitialContent() -> String? { | |
return "" | |
} | |
func gutenbergInitialTitle() -> String? { | |
return "" | |
} | |
func gutenbergFeaturedImageId() -> NSNumber? { | |
return nil | |
} | |
func gutenbergPostType() -> String { | |
return "post" | |
} | |
func gutenbergHostAppNamespace() -> String { | |
return "Jetpack" | |
} | |
func gutenbergLocale() -> String? { | |
return "en-US" | |
} | |
func gutenbergTranslations() -> [String: [String]]? { | |
return [:] | |
} | |
func gutenbergMediaSources() -> [Gutenberg.MediaSource] { | |
return [] | |
} | |
func gutenbergCapabilities() -> [Capabilities: Any] { | |
return [ | |
.mentions: false, | |
.xposts: false, | |
.unsupportedBlockEditor: false, | |
.canEnableUnsupportedBlockEditor: false, | |
.tiledGalleryBlock: true, | |
.videoPressBlock: true, | |
.videoPressV5Support: true, | |
.isAudioBlockMediaUploadEnabled: true, | |
.reusableBlock: false, | |
.facebookEmbed: true, | |
.instagramEmbed: true, | |
.loomEmbed: true, | |
.smartframeEmbed: true, | |
.supportSection: true, | |
.supportedBlocks: ["core/paragraph", "core/list", "core/list-item", "core/quote", "core/missing", "core/embed", "core/image"], | |
.compactMode: true | |
] | |
} | |
func gutenbergEditorSettings() -> GutenbergEditorSettings? { | |
let settings = EditorSettings() | |
return settings | |
} | |
} | |
extension GutenbergView: GutenbergBridgeDelegate { | |
func gutenbergDidRequestLogException(_ exception: GutenbergJSException, with callback: @escaping () -> Void) { | |
print(#function) | |
} | |
func gutenbergDidRequestConnectionStatus() -> Bool { | |
return true | |
} | |
func gutenbergDidRequestMedia(from source: Gutenberg.MediaSource, filter: [Gutenberg.MediaType], allowMultipleSelection: Bool, with callback: @escaping MediaPickerDidPickMediaCallback) { | |
} | |
func gutenbergDidRequestImport(from url: URL, with callback: @escaping MediaImportCallback) { | |
} | |
func gutenbergDidRequestMediaUploadSync() { | |
} | |
func gutenbergDidRequestMediaUploadActionDialog(for mediaID: Int32) { | |
} | |
func gutenbergDidRequestMediaUploadCancelation(for mediaID: Int32) { | |
} | |
func gutenbergDidRequestToSetFeaturedImage(for mediaID: Int32) { | |
} | |
func gutenbergDidMount(unsupportedBlockNames: [String]) { | |
} | |
func gutenbergDidEmitLog(message: String, logLevel: LogLevel) { | |
} | |
func editorDidAutosave() { | |
} | |
func gutenbergDidGetRequestFetch(path: String, completion: @escaping (Result<Any, NSError>) -> Void) { | |
} | |
func gutenbergDidPostRequestFetch(path: String, data: [String : AnyObject]?, completion: @escaping (Result<Any, NSError>) -> Void) { | |
} | |
func gutenbergDidRequestImagePreview(with mediaUrl: URL, thumbUrl: URL?) { | |
} | |
func gutenbergDidRequestMediaEditor(with mediaUrl: URL, callback: @escaping MediaPickerDidPickMediaCallback) { | |
} | |
func gutenbergDidRequestMention(callback: @escaping (Result<String, NSError>) -> Void) { | |
} | |
func gutenbergDidRequestXpost(callback: @escaping (Result<String, NSError>) -> Void) { | |
} | |
func gutenbergDidRequestFocalPointPickerTooltipShown() -> Bool { | |
return false | |
} | |
func gutenbergDidRequestSetFocalPointPickerTooltipShown(_ tooltipShown: Bool) { | |
} | |
func gutenbergDidRequestPreview() { | |
} | |
func gutenbergDidRequestBlockTypeImpressions() -> [String : Int] { | |
return [:] | |
} | |
func gutenbergDidRequestSetBlockTypeImpressions(_ impressions: [String : Int]) { | |
} | |
func gutenbergDidRequestContactCustomerSupport() { | |
} | |
func gutenbergDidRequestGotoCustomerSupportOptions() { | |
} | |
func gutenbergDidRequestSendEventToHost(_ eventName: String, properties: [AnyHashable : Any]) { | |
} | |
func gutenbergDidRequestToggleUndoButton(_ isDisabled: Bool) { | |
} | |
func gutenbergDidRequestToggleRedoButton(_ isDisabled: Bool) { | |
} | |
func gutenbergDidProvideHTML(title: String, html: String, changed: Bool, contentInfo: ContentInfo?) { | |
} | |
func gutenbergDidLoad() { | |
print("Editor loaded") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment