Skip to content

Commit d0a965a

Browse files
authored
feat: Allow remote editor for WPCOM Simple sites (#21773)
* feat: Expose experimental editor plugins feature * feat: Configure the editor using the plugins feature flag Allow toggling plugin support within the editor. * feat: Pass all siteApiNamespace options The editor needs both namespace patterns to accurately located their existence in network requests. * feat: Disable namespacing for select paths Some endpoints are global, not site specific. * refactor: Utilize GutenbergKit's EditorConfiguration class * feat: Set `_currentSiteType` global required by `jetpack-connection` Without this global, Jetpack blocks perceive a lack of an account connection. * feat: Feature config controls experimental editor plugin availability Allow disabling the plugin support as needed--e.g., while awaiting the REST API endpoint to deploy or due to a breakage. * build: Update GutenbergKit ref * build: Update GutenbergKit ref * feat: Limit GutenbergKit plugin support to Simple sites Application password authentication is required for non-Wordpress.com-hosted sites, as certain blocks attempt to make API requests to the site domain. * style: Address line length lint warning * build: Update GutenbergKit ref * build: Update GutenbergKit ref * refactor: Update remote feature flag key Match the latest server implementation. * feat: Remove remote feature flag This controlled the availability of the experimental feature toggle and also could override the feature flag status. This additional remote feature flag was deemed unnecessary for an experimental feature. wordpress-mobile/WordPress-iOS#24170 (comment) * build: Update GutenbergKit ref
1 parent 34292ad commit d0a965a

File tree

5 files changed

+44
-14
lines changed

5 files changed

+44
-14
lines changed

WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ import org.wordpress.aztec.util.AztecLog
255255
import org.wordpress.gutenberg.GutenbergJsException
256256
import org.wordpress.gutenberg.GutenbergView
257257
import org.wordpress.gutenberg.MediaType
258+
import org.wordpress.gutenberg.WebViewGlobal
259+
import org.wordpress.gutenberg.WebViewGlobalValue
258260
import java.io.File
259261
import java.util.Locale
260262
import java.util.regex.Matcher
@@ -413,6 +415,8 @@ class EditPostActivity : BaseAppCompatActivity(), EditorFragmentActivity, Editor
413415
private val gutenbergKitFeatureConfig: ExperimentalFeature = ExperimentalFeature.EXPERIMENTAL_BLOCK_EDITOR
414416
private val gutenbergKitThemeStylesConfig: ExperimentalFeature =
415417
ExperimentalFeature.EXPERIMENTAL_BLOCK_EDITOR_THEME_STYLES
418+
private val gutenbergKitPluginsConfig: ExperimentalFeature =
419+
ExperimentalFeature.EXPERIMENTAL_BLOCK_EDITOR_PLUGINS
416420

417421
@Inject lateinit var storePostViewModel: StorePostViewModel
418422
@Inject lateinit var storageUtilsViewModel: StorageUtilsViewModel
@@ -2500,20 +2504,32 @@ class EditPostActivity : BaseAppCompatActivity(), EditorFragmentActivity, Editor
25002504

25012505
val postType = if (editPostRepository.isPage) "page" else "post"
25022506
val siteApiRoot = if (isWpCom) "https://public-api.wordpress.com/" else ""
2503-
val siteId = site.siteId
25042507
val authToken = accountStore.accessToken
25052508
val authHeader = "Bearer $authToken"
2506-
val siteApiNamespace = "sites/$siteId"
2509+
val siteApiNamespace = arrayOf("sites/${site.siteId}", "sites/${UrlUtils.removeScheme(siteModel.url)}")
25072510

25082511
val settings = mutableMapOf<String, Any?>(
25092512
"postId" to editPostRepository.getPost()?.remotePostId?.toInt(),
25102513
"postType" to postType,
25112514
"postTitle" to editPostRepository.getPost()?.title,
25122515
"postContent" to editPostRepository.getPost()?.content,
25132516
"siteApiRoot" to siteApiRoot,
2517+
"namespaceExcludedPaths" to arrayOf("/wpcom/v2/following/recommendations", "/wpcom/v2/following/mine"),
25142518
"authHeader" to authHeader,
25152519
"siteApiNamespace" to siteApiNamespace,
2516-
"themeStyles" to gutenbergKitThemeStylesConfig.isEnabled()
2520+
"themeStyles" to gutenbergKitThemeStylesConfig.isEnabled(),
2521+
// Limited to Simple sites until application passwords are supported
2522+
"plugins" to (gutenbergKitPluginsConfig.isEnabled() && site.isWPCom),
2523+
"webViewGlobals" to listOf(
2524+
WebViewGlobal(
2525+
"_currentSiteType",
2526+
when {
2527+
siteModel.isWPComAtomic -> WebViewGlobalValue.StringValue("atomic")
2528+
siteModel.isWPCom -> WebViewGlobalValue.StringValue("simple")
2529+
else -> WebViewGlobalValue.NullValue
2530+
}
2531+
)
2532+
)
25172533
)
25182534

25192535
return GutenbergKitEditorFragment.newInstance(

WordPress/src/main/java/org/wordpress/android/ui/prefs/ExperimentalFeaturesActivity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ enum class ExperimentalFeature(val prefKey: String, val labelResId: Int) {
4848
EXPERIMENTAL_BLOCK_EDITOR_THEME_STYLES(
4949
"experimental_block_editor_theme_styles",
5050
R.string.experimental_block_editor_theme_styles
51+
),
52+
EXPERIMENTAL_BLOCK_EDITOR_PLUGINS(
53+
"experimental_block_editor_plugins",
54+
R.string.experimental_block_editor_plugins
5155
);
5256

5357
fun isEnabled() : Boolean {

WordPress/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,7 @@
959959
<string name="experimental_features_screen_title">Experimental Features</string>
960960
<string name="experimental_block_editor">Experimental block editor</string>
961961
<string name="experimental_block_editor_theme_styles">Experimental block editor styles</string>
962+
<string name="experimental_block_editor_plugins">Experimental block editor plugins</string>
962963
<string name="experimental_features_feedback_dialog_title">Share feedback</string>
963964
<string name="experimental_features_feedback_dialog_message">Are you willing to share feedback on the experimental editor?</string>
964965
<string name="experimental_features_feedback_dialog_decline">Not now</string>

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ google-play-services-auth = '20.4.1'
7272
google-services = '4.4.2'
7373
gravatar = '2.3.1'
7474
greenrobot-eventbus = '3.3.1'
75-
gutenberg-kit = 'trunk-947c5315198eea96e3e8c32fcc6afa59ef242638'
75+
gutenberg-kit = 'trunk-a03e0dae10a404c88c215bfcee3176df951302f5'
7676
gutenberg-mobile = 'v1.121.0'
7777
indexos-media-for-mobile = '43a9026f0973a2f0a74fa813132f6a16f7499c3a'
7878
jackson-databind = '2.12.7.1'

libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergKitEditorFragment.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@
5050
import org.wordpress.gutenberg.GutenbergView.OpenMediaLibraryListener;
5151
import org.wordpress.gutenberg.GutenbergView.TitleAndContentCallback;
5252
import org.wordpress.gutenberg.GutenbergWebViewPool;
53+
import org.wordpress.gutenberg.EditorConfiguration;
54+
import org.wordpress.gutenberg.WebViewGlobal;
5355

5456
import java.io.Serializable;
5557
import java.util.ArrayList;
58+
import java.util.List;
5659
import java.util.Map;
5760
import java.util.concurrent.CountDownLatch;
5861

@@ -155,16 +158,22 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
155158
if (postId != null && postId == 0) {
156159
postId = -1;
157160
}
158-
mGutenbergView.start(
159-
(String) mSettings.get("siteApiRoot"),
160-
(String) mSettings.get("siteApiNamespace"),
161-
(String) mSettings.get("authHeader"),
162-
(Boolean) mSettings.get("themeStyles"),
163-
postId,
164-
(String) mSettings.get("postType"),
165-
(String) mSettings.get("postTitle"),
166-
(String) mSettings.get("postContent")
167-
);
161+
162+
EditorConfiguration config = new EditorConfiguration.Builder()
163+
.setTitle((String) mSettings.get("postTitle"))
164+
.setContent((String) mSettings.get("postContent"))
165+
.setPostId(postId)
166+
.setPostType((String) mSettings.get("postType"))
167+
.setThemeStyles((Boolean) mSettings.get("themeStyles"))
168+
.setPlugins((Boolean) mSettings.get("plugins"))
169+
.setSiteApiRoot((String) mSettings.get("siteApiRoot"))
170+
.setSiteApiNamespace((String[]) mSettings.get("siteApiNamespace"))
171+
.setNamespaceExcludedPaths((String[]) mSettings.get("namespaceExcludedPaths"))
172+
.setAuthHeader((String) mSettings.get("authHeader"))
173+
.setWebViewGlobals((List<WebViewGlobal>) mSettings.get("webViewGlobals"))
174+
.build();
175+
176+
mGutenbergView.start(config);
168177

169178
return mGutenbergView;
170179
}

0 commit comments

Comments
 (0)