@@ -128,13 +128,14 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
128128 self . editorSession = PostEditorAnalyticsSession ( editor: . gutenbergKit, post: post)
129129 self . navigationBarManager = navigationBarManager ?? PostEditorNavigationBarManager ( )
130130
131- var conf = EditorConfiguration ( blog: post. blog)
132- conf. title = post. postTitle ?? " "
133- conf. content = post. content ?? " "
134- conf. postID = post. postID? . intValue != - 1 ? post. postID? . intValue : nil
135- conf. postType = post is Page ? " page " : " post "
131+ let configuration = EditorConfigurationBuilder ( blog: post. blog)
132+ . setTitle ( post. postTitle ?? " " )
133+ . setContent ( post. content ?? " " )
134+ . setPostID ( post. postID? . intValue != - 1 ? post. postID? . intValue : nil )
135+ . setPostType ( post is Page ? " page " : " post " )
136+ . build ( )
136137
137- self . editorViewController = GutenbergKit . EditorViewController ( configuration: conf )
138+ self . editorViewController = GutenbergKit . EditorViewController ( configuration: configuration )
138139
139140 super. init ( nibName: nil , bundle: nil )
140141
@@ -367,8 +368,12 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
367368 hasEditorStarted = true
368369
369370 if let settings {
370- var updatedConfig = self . editorViewController. configuration
371- updatedConfig. updateEditorSettings ( settings)
371+ // TODO: `setEditorSettings` throws due to incompatibility between `[String: Any]`
372+ // and `[String: Encodable]`. The latter is now expected by
373+ // `GutenbergKitConfiguration.EditorSettings`. How should we reconcile this?
374+ let updatedConfig = self . editorViewController. configuration. toBuilder ( )
375+ . setEditorSettings ( settings)
376+ . build ( )
372377 self . editorViewController. updateConfiguration ( updatedConfig)
373378 }
374379 self . editorViewController. startEditorSetup ( )
@@ -855,71 +860,24 @@ private extension NewGutenbergViewController {
855860 }
856861}
857862
858- extension EditorConfiguration {
859- init ( blog: Blog ) {
860- let selfHostedApiUrl = blog. restApiRootURL ?? blog. url ( withPath: " wp-json/ " )
861- let isWPComSite = blog. isHostedAtWPcom || blog. isAtomic ( )
862- let siteApiRoot = blog. isAccessibleThroughWPCom ( ) && isWPComSite ? blog. wordPressComRestApi? . baseURL. absoluteString : selfHostedApiUrl
863- let siteId = blog. dotComID? . stringValue
864- let siteDomain = blog. primaryDomainAddress
865- let authToken = blog. authToken ?? " "
866- var authHeader = " Bearer \( authToken) "
867-
868- let applicationPassword = try ? blog. getApplicationToken ( )
869-
870- if let appPassword = applicationPassword, let username = blog. username {
871- let credentials = " \( username) : \( appPassword) "
872- if let credentialsData = credentials. data ( using: . utf8) {
873- let base64Credentials = credentialsData. base64EncodedString ( )
874- authHeader = " Basic \( base64Credentials) "
875- }
876- }
863+ // Block Editor Settings
864+ extension NewGutenbergViewController {
877865
878- // Must provide both namespace forms to detect usages of both forms in third-party code
879- var siteApiNamespace : [ String ] = [ ]
880- if isWPComSite {
881- if let siteId {
882- siteApiNamespace. append ( " sites/ \( siteId) / " )
883- }
884- siteApiNamespace. append ( " sites/ \( siteDomain) / " )
866+ private func fetchBlockSettings( ) {
867+ guard let service = editorSettingsService else {
868+ return // TODO: when can it happen?
885869 }
886-
887- self = EditorConfiguration ( )
888-
889- self . siteURL = blog. url ?? " "
890- self . siteApiRoot = siteApiRoot ?? " "
891- self . siteApiNamespace = siteApiNamespace
892- self . namespaceExcludedPaths = [ " /wpcom/v2/following/recommendations " , " /wpcom/v2/following/mine " ]
893- self . authHeader = authHeader
894-
895- self . themeStyles = FeatureFlag . newGutenbergThemeStyles. enabled
896- // Limited to Simple sites until application password auth is supported
897- if RemoteFeatureFlag . newGutenbergPlugins. enabled ( ) && blog. isHostedAtWPcom {
898- self . plugins = true
899- if var editorAssetsEndpoint = blog. wordPressComRestApi? . baseURL {
900- editorAssetsEndpoint. appendPathComponent ( " wpcom/v2/sites " )
901- if let siteId {
902- editorAssetsEndpoint. appendPathComponent ( siteId)
903- } else {
904- editorAssetsEndpoint. appendPathComponent ( siteDomain)
870+ service. fetchSettings ( { [ weak self] result in
871+ switch result {
872+ case . success( let response) :
873+ if response. hasChanges {
874+ // TODO: inject in hte editor
875+ // self.gutenberg.updateEditorSettings(response.blockEditorSettings)
905876 }
906- editorAssetsEndpoint . appendPathComponent ( " editor-assets " )
907- self . editorAssetsEndpoint = editorAssetsEndpoint
877+ case . failure ( let err ) :
878+ DDLogError ( " Error fetching settings: \( err ) " )
908879 }
909- }
910- self . locale = WordPressComLanguageDatabase ( ) . deviceLanguage. slug
911-
912- if !blog. isSelfHosted {
913- let siteType : String = blog. isHostedAtWPcom ? " simple " : " atomic "
914- do {
915- self . webViewGlobals = [
916- try WebViewGlobal ( name: " _currentSiteType " , value: . string( siteType) )
917- ]
918- } catch {
919- wpAssertionFailure ( " Failed to create WebViewGlobal " , userInfo: [ " error " : " \( error) " ] )
920- self . webViewGlobals = [ ]
921- }
922- }
880+ } )
923881 }
924882}
925883
0 commit comments