Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Global Styles] Implement Global Styles endpoint #16411

Merged
merged 32 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d0065f8
Update Editor Theme to pull from WordPressKit Instead.
chipsnyder Apr 29, 2021
5a7b19d
Add Support For Global Styles endpoint
chipsnyder Apr 29, 2021
d16be0e
Merge branch 'develop' into gutenberg/issue/3163-gss
chipsnyder May 6, 2021
8fd4a92
Add New Data model changes for raw GSS settings
chipsnyder May 6, 2021
8f2bd96
Parse GSS setting and update Gutenberg event names
chipsnyder May 6, 2021
9a77ea5
Merge Develop
chipsnyder May 14, 2021
097fa9b
Update App for BlockEditor Settings API Changes
chipsnyder May 14, 2021
dc3e79b
Fix test error
chipsnyder May 19, 2021
bddbcf3
Fix Remaining test errors
chipsnyder May 19, 2021
6c2d9c8
Update Gutenberg ref
May 27, 2021
7cd8b3d
Merge branch 'develop' into gutenberg/issue/3163-gss
chipsnyder May 27, 2021
58ff3b0
Update native app for editor settings endpoint changes
chipsnyder May 27, 2021
0ed3999
Update Gutenberg ref
May 28, 2021
bf582e8
Merge branch 'develop' into gutenberg/issue/3163-gss
chipsnyder May 28, 2021
9cef9ae
Store and Sort the colors and gradients based on the API order
chipsnyder May 28, 2021
46fa5e5
Merge branch 'develop' into gutenberg/issue/3163-gss
chipsnyder Jun 16, 2021
68ea549
Merge branch 'develop' into gutenberg/issue/3163-gss
chipsnyder Jun 16, 2021
2061a1f
Migrate Core Data changes to 126 and re-add rawFeatures
chipsnyder Jun 16, 2021
861b49e
Update Gutenberg ref
Jun 17, 2021
d4dd098
Update Gutenberg ref
Jun 18, 2021
c338bae
Updates Gutenberg reference
Jun 25, 2021
f593a74
Merge branch 'develop' into gutenberg/issue/3163-gss
Jun 25, 2021
d39a26e
Merge branch 'develop' into gutenberg/issue/3163-gss
chipsnyder Jun 28, 2021
adcc570
Bump WPKit ref
chipsnyder Jun 28, 2021
e024fb9
Add WP version check to enabling GSS
chipsnyder Jun 28, 2021
1a03642
Merge remote-tracking branch 'origin/fix/kit_object_rename' into gute…
chipsnyder Jun 28, 2021
ab1ca8c
Update WP Version checks and tests
chipsnyder Jun 28, 2021
07d3246
Merge branch 'develop' into gutenberg/issue/3163-gss
chipsnyder Jun 28, 2021
3522f38
Merge branch 'develop' into gutenberg/issue/3163-gss
chipsnyder Jul 1, 2021
7805af3
Update Gutenberg Reference
chipsnyder Jul 1, 2021
fdf9a4e
Merge branch 'develop' into gutenberg/issue/3163-gss
chipsnyder Jul 1, 2021
e74e811
Bump WordPressKit Version
chipsnyder Jul 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions MIGRATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
This file documents changes in the data model. Please explain any changes to the
data model as well as any custom migrations.

## WordPress 127

@chipsnyder 2021-07-1

- `BlockEditorSettings`: added the attribute
- `rawStyles` (optional, no default, `String`)
- `rawFeatures` (optional, no default, `String`)

- `BlockEditorSettingElement`: added the attribute
- `order` (required, 0, `Int`)

## WordPress 126

@scoutharris 2021-06-28
Expand Down
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ abstract_target 'Apps' do
## Gutenberg (React Native)
## =====================
##
gutenberg :tag => 'v1.56.0'
gutenberg :tag => 'v1.57.0-alpha1'

## Third party libraries
## =====================
Expand Down
184 changes: 92 additions & 92 deletions Podfile.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ extension BlockEditorSettingElement {
///
@NSManaged public var name: String

/// Stores maintains the order as passed from the API
///
@NSManaged public var order: Int

/// Stores a reference back to the parent `BlockEditorSettings`.
///
@NSManaged public var settings: BlockEditorSettings
Expand All @@ -48,12 +52,13 @@ extension BlockEditorSettingElement: Identifiable {
]
}

convenience init(fromRawRepresentation rawObject: [String: String], type: BlockEditorSettingElementTypes, context: NSManagedObjectContext) {
convenience init(fromRawRepresentation rawObject: [String: String], type: BlockEditorSettingElementTypes, order: Int, context: NSManagedObjectContext) {
self.init(context: context)

self.type = type.rawValue
self.value = rawObject[type.valueKey] ?? ""
self.slug = rawObject[#keyPath(BlockEditorSettingElement.slug)] ?? ""
self.name = rawObject[ #keyPath(BlockEditorSettingElement.name)] ?? ""
self.order = order
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ extension BlockEditorSettings {
///
@NSManaged public var lastUpdated: Date

/// Stores the raw JSON string that comes from the Global Styles Setting Request.
///
@NSManaged public var rawStyles: String?

/// Stores the raw JSON string that comes from the Global Styles Setting Request.
///
@NSManaged public var rawFeatures: String?

/// Stores a set of attributes describing values that are represented with arrays in the API request.
/// Available types are defined in `BlockEditorSettingElementTypes`
///
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import Foundation
import WordPressKit
import Gutenberg

extension BlockEditorSettings: GutenbergEditorSettings {
public var colors: [[String: String]]? {
elementsByType(.color)
}

public var gradients: [[String: String]]? {
elementsByType(.gradient)
}

private func elementsByType(_ type: BlockEditorSettingElementTypes) -> [[String: String]]? {
return elements?.sorted(by: { (lhs, rhs) -> Bool in
return lhs.order >= rhs.order
}).compactMap({ (element) -> [String: String]? in
guard element.type == type.rawValue else { return nil }
return element.rawRepresentation
})
}
}

extension BlockEditorSettings {
convenience init?(editorTheme: RemoteEditorTheme, context: NSManagedObjectContext) {
self.init(context: context)
self.isFSETheme = false
self.lastUpdated = Date()
self.checksum = editorTheme.checksum

var parsedElements = Set<BlockEditorSettingElement>()
if let themeSupport = editorTheme.themeSupport {
themeSupport.colors?.enumerated().forEach({ (index, color) in
parsedElements.insert(BlockEditorSettingElement(fromRawRepresentation: color, type: .color, order: index, context: context))
})

themeSupport.gradients?.enumerated().forEach({ (index, gradient) in
parsedElements.insert(BlockEditorSettingElement(fromRawRepresentation: gradient, type: .gradient, order: index, context: context))
})
}

self.elements = parsedElements
}

convenience init?(remoteSettings: RemoteBlockEditorSettings, context: NSManagedObjectContext) {
self.init(context: context)
self.isFSETheme = remoteSettings.isFSETheme
self.lastUpdated = Date()
self.checksum = remoteSettings.checksum
self.rawStyles = remoteSettings.rawStyles
self.rawFeatures = remoteSettings.rawFeatures

var parsedElements = Set<BlockEditorSettingElement>()

remoteSettings.colors?.enumerated().forEach({ (index, color) in
parsedElements.insert(BlockEditorSettingElement(fromRawRepresentation: color, type: .color, order: index, context: context))
})

remoteSettings.gradients?.enumerated().forEach({ (index, gradient) in
parsedElements.insert(BlockEditorSettingElement(fromRawRepresentation: gradient, type: .gradient, order: index, context: context))
})

self.elements = parsedElements
}
}

This file was deleted.

6 changes: 6 additions & 0 deletions WordPress/Classes/Models/Blog+BlockEditorSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ extension Blog {
/// such as Global Styles and Full Site Editing settings and capabilities.
///
@NSManaged public var blockEditorSettings: BlockEditorSettings?

@objc
func supportsBlockEditorSettings() -> Bool {
guard FeatureFlag.globalStyleSettings.enabled else { return false }
return hasRequiredWordPressVersion("5.8")
}
}
5 changes: 5 additions & 0 deletions WordPress/Classes/Models/Blog.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ typedef NS_ENUM(NSUInteger, BlogFeature) {
BlogFeatureStories,
/// Does the blog support Jetpack contact info block?
BlogFeatureContactInfo,
BlogFeatureBlockEditorSettings,
/// Does the blog support the Layout grid block?
BlogFeatureLayoutGrid,
};
Expand Down Expand Up @@ -280,6 +281,10 @@ typedef NS_ENUM(NSInteger, SiteVisibility) {
*/
- (BOOL)isBasicAuthCredentialStored;

/// Checks the blogs installed WordPress version is more than or equal to the requiredVersion
/// @param requiredVersion The minimum version to check for
- (BOOL)hasRequiredWordPressVersion:(NSString *)requiredVersion;

@end

NS_ASSUME_NONNULL_END
2 changes: 2 additions & 0 deletions WordPress/Classes/Models/Blog.m
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,8 @@ - (BOOL)supports:(BlogFeature)feature
return [self supportsStories];
case BlogFeatureContactInfo:
return [self supportsContactInfo];
case BlogFeatureBlockEditorSettings:
return [self supportsBlockEditorSettings];
case BlogFeatureLayoutGrid:
return [self supportsLayoutGrid];
}
Expand Down
51 changes: 0 additions & 51 deletions WordPress/Classes/Models/EditorTheme.swift

This file was deleted.

Loading