-
Notifications
You must be signed in to change notification settings - Fork 3
Add block inserter flag and initial infrastructure #193
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
3d859a6
2049952
f13b38a
d9c1786
19816f6
c0b3604
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 |
---|---|---|
@@ -1,32 +1,32 @@ | ||
import SwiftUI | ||
import GutenbergKit | ||
|
||
let editorURL: URL? = ProcessInfo.processInfo.environment["GUTENBERG_EDITOR_URL"].flatMap(URL.init) | ||
|
||
struct ContentView: View { | ||
private let remoteEditors: [RemoteEditorRow] = [ | ||
.init(id: "template", configuration: .template) | ||
] | ||
|
||
@State private var isDefaultEditorShown = false | ||
@State private var selectedRemoteEditor: RemoteEditorRow? | ||
|
||
let remoteEditorConfigurations: [EditorConfiguration] = [.template] | ||
@AppStorage("isNativeInserterEnabled") private var isNativeInserterEnabled = false | ||
|
||
var body: some View { | ||
List { | ||
Section { | ||
NavigationLink { | ||
EditorView(configuration: .default) | ||
} label: { | ||
Text("Bundled Editor") | ||
Button("Show Editor") { | ||
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. I suggest retaining "bundled" somewhere to differentiate from the remote editors and remain aligned with Android's demo app/project documentation. |
||
isDefaultEditorShown = true | ||
} | ||
} | ||
|
||
Section { | ||
ForEach(remoteEditorConfigurations, id: \.siteURL) { configuration in | ||
NavigationLink { | ||
EditorView(configuration: configuration) | ||
} label: { | ||
Text(URL(string: configuration.siteURL)?.host ?? configuration.siteURL) | ||
ForEach(remoteEditors) { editor in | ||
Button(editor.title) { | ||
selectedRemoteEditor = editor | ||
} | ||
} | ||
|
||
if remoteEditorConfigurations.isEmpty { | ||
if remoteEditors.isEmpty { | ||
Text("Add `EditorConfiguration` instances to the `remoteEditorConfigurations` array to launch remote editors here.") | ||
} | ||
} header: { | ||
|
@@ -38,18 +38,32 @@ struct ContentView: View { | |
Text("Note: The editor is backed by the compiled web app created by `make build`.") | ||
} | ||
} | ||
|
||
Section("Configuration") { | ||
Toggle("Native Inserter", isOn: $isNativeInserterEnabled) | ||
} | ||
} | ||
.fullScreenCover(isPresented: $isDefaultEditorShown) { | ||
NavigationView { | ||
EditorView(configuration: preconfigure(.default)) | ||
} | ||
} | ||
.fullScreenCover(item: $selectedRemoteEditor) { editor in | ||
NavigationView { | ||
EditorView(configuration: preconfigure(editor.configuration)) | ||
} | ||
} | ||
.toolbar { | ||
ToolbarItem(placement: .primaryAction) { | ||
Button { | ||
Task { | ||
NSLog("Start to fetch assets") | ||
for configuration in remoteEditorConfigurations { | ||
let library = EditorAssetsLibrary(configuration: configuration) | ||
for editor in remoteEditors { | ||
let library = EditorAssetsLibrary(configuration: editor.configuration) | ||
do { | ||
try await library.fetchAssets() | ||
} catch { | ||
NSLog("Failed to fetch assets for \(configuration.siteURL): \(error)") | ||
NSLog("Failed to fetch assets for \(editor.configuration.siteURL): \(error)") | ||
} | ||
} | ||
NSLog("Done fetching assets") | ||
|
@@ -61,13 +75,30 @@ struct ContentView: View { | |
} | ||
} | ||
} | ||
|
||
private func preconfigure(_ configuration: EditorConfiguration) -> EditorConfiguration { | ||
configuration | ||
.toBuilder() | ||
.setNativeInserterEnabled(isNativeInserterEnabled) | ||
.build() | ||
} | ||
} | ||
|
||
private struct RemoteEditorRow: Identifiable { | ||
let id: String | ||
let configuration: EditorConfiguration | ||
|
||
var title: String { | ||
URL(string: configuration.siteURL)?.host ?? configuration.siteURL | ||
} | ||
} | ||
|
||
private extension EditorConfiguration { | ||
|
||
static var template: Self { | ||
#warning("1. Update the siteURL and authHeader values below") | ||
#warning("2. Install the Jetpack plugin to the site") | ||
// Steps: | ||
// 1. Update the siteURL and authHeader values below | ||
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. These shouldn't be warnings. |
||
// 2. Install the Jetpack plugin to the site | ||
let siteUrl: String = "https://modify-me.com" | ||
let authHeader: String = "Insert the Authorization header value here" | ||
let siteApiRoot: String = "\(siteUrl)/wp-json/" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ struct EditorView: View { | |
private let configuration: EditorConfiguration | ||
|
||
@State private var viewModel = EditorViewModel() | ||
@State private var editorViewController: EditorViewController? | ||
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. Follow-up to the previous PR |
||
|
||
@Environment(\.dismiss) private var dismiss | ||
|
||
|
@@ -15,7 +14,6 @@ struct EditorView: View { | |
|
||
var body: some View { | ||
_EditorView(configuration: configuration, viewModel: viewModel) | ||
.navigationBarBackButtonHidden(true) | ||
.toolbar { toolbar } | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ import { | |
ToolbarButton, | ||
} from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { close, cog } from '@wordpress/icons'; | ||
import { close, cog, plus } from '@wordpress/icons'; | ||
import clsx from 'clsx'; | ||
import { store as editorStore } from '@wordpress/editor'; | ||
|
||
|
@@ -27,6 +27,7 @@ import { store as editorStore } from '@wordpress/editor'; | |
import './style.scss'; | ||
import { useModalize } from './use-modalize'; | ||
import { useModalDialogState } from '../editor/use-modal-dialog-state'; | ||
import { showBlockInserter, getGBKit } from '../../utils/bridge'; | ||
|
||
/** | ||
* Renders the editor toolbar containing block-related actions. | ||
|
@@ -36,6 +37,8 @@ import { useModalDialogState } from '../editor/use-modal-dialog-state'; | |
* @return {JSX.Element} The rendered editor toolbar component. | ||
*/ | ||
const EditorToolbar = ( { className } ) => { | ||
const { enableNativeBlockInserter } = getGBKit(); | ||
|
||
const [ isBlockInspectorShown, setBlockInspectorShown ] = useState( false ); | ||
const { isSelected } = useSelect( ( select ) => { | ||
const { getSelectedBlockClientId } = select( blockEditorStore ); | ||
|
@@ -77,23 +80,37 @@ const EditorToolbar = ( { className } ) => { | |
|
||
const classes = clsx( 'gutenberg-kit-editor-toolbar', className ); | ||
|
||
const addBlockButton = enableNativeBlockInserter ? ( | ||
<ToolbarButton | ||
title={ __( 'Add block' ) } | ||
icon={ plus } | ||
onClick={ () => { | ||
if ( isInserterOpened ) { | ||
setIsInserterOpened( false ); | ||
} | ||
Comment on lines
+88
to
+90
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. Is this achieving a specific outcome? |
||
showBlockInserter(); | ||
} } | ||
className="gutenberg-kit-add-block-button" | ||
/> | ||
) : ( | ||
<Inserter | ||
popoverProps={ { | ||
'aria-modal': true, | ||
role: 'dialog', | ||
} } | ||
open={ isInserterOpened } | ||
onToggle={ setIsInserterOpened } | ||
/> | ||
); | ||
|
||
return ( | ||
<> | ||
<Toolbar | ||
className={ classes } | ||
label="Editor toolbar" | ||
variant="unstyled" | ||
> | ||
<ToolbarGroup> | ||
<Inserter | ||
popoverProps={ { | ||
'aria-modal': true, | ||
role: 'dialog', | ||
} } | ||
open={ isInserterOpened } | ||
onToggle={ setIsInserterOpened } | ||
/> | ||
</ToolbarGroup> | ||
<ToolbarGroup>{ addBlockButton }</ToolbarGroup> | ||
|
||
{ isSelected && ( | ||
<ToolbarGroup> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,3 +71,19 @@ $min-touch-target-size: 46px; | |
left: 6px; | ||
right: 6px; | ||
} | ||
|
||
// Style the add block button with rounded black background | ||
.gutenberg-kit-editor-toolbar .gutenberg-kit-add-block-button { | ||
Contributor
Author
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. 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. I think this is fine for now. Eventually, we need to consideration Android design patterns. |
||
svg { | ||
background: #eae9ec; | ||
border-radius: 18px; | ||
color: wordpress.$black; | ||
padding: 1px; | ||
width: 32px; | ||
height: 32px; | ||
display: block; | ||
} | ||
Comment on lines
+77
to
+85
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. I suggest we place this after the attributes declared for |
||
|
||
// width: 50px; | ||
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. This commented code should likely be removed. |
||
margin-left: 8px; | ||
} |
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.
Since #191 (comment), should we enable
GUTENBERG_EDITOR_URL
by default? I keep doing this every time I work on the editor.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.
Sounds good to me. However, let's also enable the
GUTENBERG_EDITOR_REMOTE_URL
environment variable as well.We should also update the README documentation to match the new default settings. The README recently changed. I suggest rebasing this atop the latest
trunk
branch and applying the following diff