-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add iOS support for custom bundles #107
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import SwiftUI | ||
import GutenbergKit | ||
|
||
struct EditorDownloadView: View { | ||
|
||
class ViewModel: ObservableObject { | ||
@Published | ||
var downloadProgress: Double = 0 | ||
|
||
@Published | ||
var siteUrl: String = "http://localhost" | ||
|
||
@Published | ||
var error: Error? = nil | ||
|
||
func download() { | ||
Task { | ||
|
||
let url = URL(string: siteUrl)! | ||
.appendingPathComponent("wp-json") | ||
.appendingPathComponent("__experimental") | ||
.appendingPathComponent("wp-block-editor") | ||
.appendingPathComponent("v1") | ||
.appendingPathComponent( "editor-assets" ) | ||
|
||
print("Downloading from \(url)") | ||
|
||
do { | ||
self.error = nil | ||
|
||
try await EditorLibrary.shared.downloadManifest(from: url) { progress in | ||
self.downloadProgress = Double(progress.fractionCompleted) | ||
} | ||
} catch { | ||
self.error = error | ||
} | ||
} | ||
} | ||
} | ||
|
||
@StateObject | ||
var viewModel = ViewModel() | ||
|
||
var body: some View { | ||
Form { | ||
if let error = viewModel.error { | ||
Text("Error: \(error.localizedDescription)") | ||
} | ||
|
||
TextField(text: $viewModel.siteUrl, prompt: Text("Site URL")) { | ||
Text("Site URL") | ||
} | ||
.keyboardType(.URL) | ||
.autocapitalization(.none) | ||
|
||
Button("Download") { | ||
self.viewModel.download() | ||
} | ||
|
||
ProgressView(value: viewModel.downloadProgress).progressViewStyle(.linear) | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
EditorDownloadView() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
import SwiftUI | ||
import GutenbergKit | ||
|
||
@main | ||
struct GutenbergApp: App { | ||
var body: some Scene { | ||
WindowGroup { | ||
ContentView() | ||
NavigationStack { | ||
ContentView() | ||
} | ||
} | ||
} | ||
} | ||
|
||
// We don't really care about dependency injection for our demo app, so we'll just make a bunch of singletons | ||
extension EditorLibrary { | ||
static let shared = EditorLibrary() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,12 @@ public struct EditorConfiguration { | |
self.title = title | ||
self.content = content | ||
} | ||
|
||
var manifestURL: URL { | ||
URL(string: siteApiRoot)! | ||
.appendingPathComponent("__experimental") | ||
.appendingPathComponent("wp-block-editor") | ||
.appendingPathComponent("v1") | ||
.appendingPathComponent( "editor-assets" ) | ||
Comment on lines
+25
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To simplify using different endpoints—e.g., it varies based on environment—we might use this path as a default if a full URL is not provided. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be far better to inject this, I think. We already have it in the demo app, so I think it'd just be a matter of passing it in here? |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To simplify using different endpoints—e.g., it varies based on environment—we might use this path as a default if a full URL is not provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can/should be improved a bunch. Because it's the demo app, I just whipped up something quick.
In the real world, we'd probably use https://github.com/Automattic/wordpress-rs to find this endpoint in a programmatic way by scanning the
wp-json
endpoint for its entry. If it's not there, we'd assume the site doesn't support editor assets and default back to the bundled editor.I think ... LMK if this doesn't seem like a good plan?