-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Edit Site: Add package with barebones site editor screen. #19054
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
/** | ||
* Bootstraping the Gutenberg Edit Site Page. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* The main entry point for the Gutenberg Edit Site Page. | ||
* | ||
* @since 7.2.0 | ||
*/ | ||
function gutenberg_edit_site_page() { | ||
?> | ||
<div | ||
id="edit-site-editor" | ||
class="edit-site" | ||
> | ||
</div> | ||
<?php | ||
} | ||
|
||
/** | ||
* Initialize the Gutenberg Edit Site Page. | ||
* | ||
* @since 7.2.0 | ||
* | ||
* @param string $hook Page. | ||
*/ | ||
function gutenberg_edit_site_init( $hook ) { | ||
if ( 'gutenberg_page_gutenberg-edit-site' !== $hook ) { | ||
return; | ||
} | ||
|
||
// Get editor settings. | ||
$max_upload_size = wp_max_upload_size(); | ||
if ( ! $max_upload_size ) { | ||
$max_upload_size = 0; | ||
} | ||
|
||
// This filter is documented in wp-admin/includes/media.php. | ||
$image_size_names = apply_filters( | ||
'image_size_names_choose', | ||
array( | ||
'thumbnail' => __( 'Thumbnail', 'gutenberg' ), | ||
'medium' => __( 'Medium', 'gutenberg' ), | ||
'large' => __( 'Large', 'gutenberg' ), | ||
'full' => __( 'Full Size', 'gutenberg' ), | ||
) | ||
); | ||
$available_image_sizes = array(); | ||
foreach ( $image_size_names as $image_size_slug => $image_size_name ) { | ||
$available_image_sizes[] = array( | ||
'slug' => $image_size_slug, | ||
'name' => $image_size_name, | ||
); | ||
} | ||
|
||
$settings = array( | ||
'disableCustomColors' => get_theme_support( 'disable-custom-colors' ), | ||
'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ), | ||
'imageSizes' => $available_image_sizes, | ||
'isRTL' => is_rtl(), | ||
'maxUploadFileSize' => $max_upload_size, | ||
); | ||
|
||
list( $color_palette, ) = (array) get_theme_support( 'editor-color-palette' ); | ||
list( $font_sizes, ) = (array) get_theme_support( 'editor-font-sizes' ); | ||
if ( false !== $color_palette ) { | ||
$settings['colors'] = $color_palette; | ||
} | ||
if ( false !== $font_sizes ) { | ||
$settings['fontSizes'] = $font_sizes; | ||
} | ||
|
||
// Initialize editor. | ||
wp_add_inline_script( | ||
'wp-edit-site', | ||
sprintf( | ||
'wp.domReady( function() { | ||
wp.editSite.initialize( "edit-site-editor", %s ); | ||
} );', | ||
wp_json_encode( gutenberg_experiments_editor_settings( $settings ) ) | ||
) | ||
); | ||
|
||
// Preload server-registered block schemas. | ||
wp_add_inline_script( | ||
'wp-blocks', | ||
'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');' | ||
); | ||
|
||
wp_enqueue_script( 'wp-edit-site' ); | ||
wp_enqueue_script( 'wp-format-library' ); | ||
wp_enqueue_style( 'wp-edit-site' ); | ||
wp_enqueue_style( 'wp-format-library' ); | ||
} | ||
add_action( 'admin_enqueue_scripts', 'gutenberg_edit_site_init' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## Master | ||
|
||
### New Feature | ||
|
||
- Initial version of the module. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Edit Site | ||
|
||
Edit Site Page Module for WordPress. | ||
|
||
> This package is meant to be used only with WordPress core. Feel free to use it in your own project but please keep in mind that it might never get fully documented. | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install @wordpress/edit-site | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { initialize } from '@wordpress/edit-site'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import blockEditorSettings from './block-editor-settings'; | ||
|
||
initialize( '#editor-root', blockEditorSettings ); | ||
|
||
``` | ||
|
||
_This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using [core-js](https://github.com/zloirock/core-js) or [@babel/polyfill](https://babeljs.io/docs/en/next/babel-polyfill) will add support for these methods. Learn more about it in [Babel docs](https://babeljs.io/docs/en/next/caveats)._ | ||
|
||
<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "@wordpress/edit-site", | ||
"version": "1.0.0-beta.0", | ||
"private": true, | ||
"description": "Edit Site Page module for WordPress.", | ||
"author": "The WordPress Contributors", | ||
"license": "GPL-2.0-or-later", | ||
"keywords": [ | ||
"wordpress" | ||
], | ||
"homepage": "https://github.com/WordPress/gutenberg/tree/master/packages/edit-site/README.md", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/WordPress/gutenberg.git", | ||
"directory": "packages/edit-site" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/WordPress/gutenberg/issues" | ||
}, | ||
"main": "build/index.js", | ||
"module": "build-module/index.js", | ||
"react-native": "src/index", | ||
"dependencies": { | ||
"@babel/runtime": "^7.4.4", | ||
"@wordpress/block-editor": "file:../block-editor", | ||
"@wordpress/block-library": "file:../block-library", | ||
"@wordpress/components": "file:../components", | ||
"@wordpress/data": "file:../data", | ||
"@wordpress/element": "file:../element", | ||
"@wordpress/hooks": "file:../hooks", | ||
"@wordpress/i18n": "file:../i18n", | ||
"@wordpress/media-utils": "file:../media-utils", | ||
"@wordpress/notices": "file:../notices" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
import { useMemo, useState } from '@wordpress/element'; | ||
import { uploadMedia } from '@wordpress/media-utils'; | ||
import { | ||
BlockEditorProvider, | ||
BlockEditorKeyboardShortcuts, | ||
BlockInspector, | ||
WritingFlow, | ||
ObserveTyping, | ||
BlockList, | ||
ButtonBlockerAppender, | ||
} from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Sidebar from '../sidebar'; | ||
|
||
export default function BlockEditor( { settings: _settings } ) { | ||
const canUserCreateMedia = useSelect( ( select ) => { | ||
const _canUserCreateMedia = select( 'core' ).canUser( 'create', 'media' ); | ||
return _canUserCreateMedia || _canUserCreateMedia !== false; | ||
}, [] ); | ||
const settings = useMemo( () => { | ||
if ( ! canUserCreateMedia ) { | ||
return _settings; | ||
} | ||
return { | ||
..._settings, | ||
mediaUpload( { onError, ...rest } ) { | ||
uploadMedia( { | ||
wpAllowedMimeTypes: _settings.allowedMimeTypes, | ||
onError: ( { message } ) => onError( message ), | ||
...rest, | ||
} ); | ||
}, | ||
}; | ||
}, [ canUserCreateMedia, _settings ] ); | ||
const [ blocks, setBlocks ] = useState( [] ); | ||
return ( | ||
<BlockEditorProvider | ||
settings={ settings } | ||
value={ blocks } | ||
onInput={ setBlocks } | ||
onChange={ setBlocks } | ||
> | ||
<BlockEditorKeyboardShortcuts /> | ||
<Sidebar.InspectorFill> | ||
<BlockInspector /> | ||
</Sidebar.InspectorFill> | ||
<div className="editor-styles-wrapper"> | ||
<WritingFlow> | ||
<ObserveTyping> | ||
<BlockList | ||
className="edit-site-block-editor__block-list" | ||
renderAppender={ ButtonBlockerAppender } | ||
/> | ||
</ObserveTyping> | ||
</WritingFlow> | ||
</div> | ||
</BlockEditorProvider> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe this means this function should move out of lib/widgets.php
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.
Not yet, it's still only needed for widget blocks.