Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskoster committed Oct 20, 2023
2 parents 623f754 + fb7c9c5 commit ad4eb65
Show file tree
Hide file tree
Showing 74 changed files with 3,345 additions and 372 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ To see a list of all of your available iOS devices, use `xcrun simctl list devic

### Customizing the Demo Editor

By default, the Demo editor renders most of the supported core blocks. This is helpful to showcase the editor's capabilities, but can be distracting when focusing on a specific block or feature. One can customize the editor's intial state by leveraging the `native.block_editor_props` hook in a `packages/react-native-editor/src/setup-local.js` file.
By default, the Demo editor renders most of the supported core blocks. This is helpful to showcase the editor's capabilities, but can be distracting when focusing on a specific block or feature. One can customize the editor's initial state by leveraging the `native.block_editor_props` hook in a `packages/react-native-editor/src/setup-local.js` file.

<details><summary>Example setup-local.js</summary>

Expand Down
2 changes: 1 addition & 1 deletion docs/explanations/architecture/entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ wp.data.dispatch( 'core' ).saveEditedEntityRecord( 'postType', 'post', 1 );

Since the WordPress editors allow multiple entity records to be edited at the same time, the `core-data` package keeps track of all the entity records that have been fetched and edited in a common undo/redo stack. Each step in the undo/redo stack contains a list of "edits" that should be undone or redone at the same time when calling the `undo` or `redo` action.

And to be able to perform both undo and redo operations propertly, each modification in the list of edits contains the following information:
And to be able to perform both undo and redo operations properly, each modification in the list of edits contains the following information:

- Entity kind and name: Each entity in core-data is identified by the pair _(kind, name)_. This corresponds to the identifier of the modified entity.
- Entity Record ID: The ID of the modified record.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ import { InspectorControls } from '@wordpress/block-editor';

export const withBookQueryControls = ( BlockEdit ) => ( props ) => {
// We only want to add these controls if it is our variation,
// so here we can implement a custom logic to check for that, similiar
// so here we can implement a custom logic to check for that, similar
// to the `isActive` function described above.
// The following assumes that you wrote a custom `isMyBooksVariation`
// function to handle that.
Expand Down
2 changes: 1 addition & 1 deletion docs/how-to-guides/enqueueing-assets-in-the-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Do you want to add styling or JavaScript to the user-generated content (blocks)

There are different hooks to use depending on the answers to these questions, and if you are building a block or a theme, there are additional approaches to consider. Refer to the designated sections below.

## Scenarios for enqueing assets
## Scenarios for enqueuing assets
### Editor scripts and styles

Whenever you need to enqueue assets for the Editor itself (i.e. not the user-generated content), you should use the [`enqueue_block_editor_assets`](https://developer.wordpress.org/reference/hooks/enqueue_block_editor_assets/) hook coupled with the standard [`wp_enqueue_script`](https://developer.wordpress.org/reference/functions/wp_enqueue_script/) and [`wp_enqueue_style`](https://developer.wordpress.org/reference/functions/wp_enqueue_style/) functions.
Expand Down
4 changes: 2 additions & 2 deletions docs/how-to-guides/platform/custom-block-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Here is a brief summary of what's going on:
- `src/` (directory) - This is where the JavaScript and CSS source files will live. These files are _not_ directly enqueued by the plugin.
- `webpack.config.js` - A custom Webpack config extending the defaults provided by the [`@wordpress/scripts`](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-scripts/) npm package to allow for custom CSS styles (via Sass).

The only item not shown above is the `build/` directory, which is where the _compiled_ JS and CSS files are outputted by `@wordpress/scripts`. These files are enqueued by the plugin seperately.
The only item not shown above is the `build/` directory, which is where the _compiled_ JS and CSS files are outputted by `@wordpress/scripts`. These files are enqueued by the plugin separately.

<div class="callout callout-info">
Throughout this guide, filename references will be placed in a comment at the top of each code snippet so you can follow along.
Expand Down Expand Up @@ -168,7 +168,7 @@ wp_enqueue_script( $script_handle, $script_url, $script_asset['dependencies'], $

To save time and space, the `$script_` variables assignment has been omitted. You can [review these here](https://github.com/getdave/standalone-block-editor/blob/974a59dcbc539a0595e8fa34670e75ec541853ab/init.php#L19).

Note the third arguement for script dependencies, `$script_asset['dependencies']`. These dependencies are
Note the third argument for script dependencies, `$script_asset['dependencies']`. These dependencies are
dynamically generated using [@wordpress/dependency-extraction-webpack-plugin](https://developer.wordpress.org/block-editor/packages/packages-dependency-extraction-webpack-plugin/) which will
[ensure that](https://developer.wordpress.org/block-editor/packages/packages-scripts/#default-webpack-config) WordPress provided scripts are not included in the built
bundle.
Expand Down
2 changes: 1 addition & 1 deletion docs/reference-guides/block-api/block-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ add_action( 'init', 'myplugin_register_template' );

_Options:_

- `contentOnly` — prevents all operations. Additionally, the block types that don't have content are hidden from the list view and can't gain focus within the block list. Unlike the other lock types, this is not overrideable by children.
- `contentOnly` — prevents all operations. Additionally, the block types that don't have content are hidden from the list view and can't gain focus within the block list. Unlike the other lock types, this is not overridable by children.
- `all` — prevents all operations. It is not possible to insert new blocks, move existing blocks, or delete blocks.
- `insert` — prevents inserting or removing blocks, but allows moving existing blocks.

Expand Down
6 changes: 3 additions & 3 deletions docs/reference-guides/block-api/block-transforms.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ A transformation of type `enter` is an object that takes the following parameter

**Example: from --- to Separator block**

To create a separator block when the user types the hypen three times and then hits the ENTER key we can use the following code:
To create a separator block when the user types the hyphen three times and then hits the ENTER key we can use the following code:

```js
transforms = {
Expand Down Expand Up @@ -162,7 +162,7 @@ This type of transformations support the _from_ direction, allowing blocks to be
A transformation of type `prefix` is an object that takes the following parameters:

- **type** _(string)_: the value `prefix`.
- **prefix** _(string)_: the character or sequence of characters that match this transfrom.
- **prefix** _(string)_: the character or sequence of characters that match this transform.
- **transform** _(function)_: a callback that receives the content introduced. It should return a block object or an array of block objects.
- **priority** _(number, optional)_: controls the priority with which a transform is applied, where a lower value will take precedence over higher values. This behaves much like a [WordPress hook](https://codex.wordpress.org/Plugin_API#Hook_to_WordPress). Like hooks, the default priority is `10` when not otherwise set.

Expand Down Expand Up @@ -260,7 +260,7 @@ schema = ({ phrasingContentSchema }) => {

When we successfully match this content every HTML attribute will be stripped away except for `data-post-id` and if we have other arrangements of HTML inside of a given `div` then it won't match our transformer. Likewise we'd fail to match if we found an `<h3>` in there instead of an `<h2>`.

Schemas are most-important when wanting to match HTML snippets containing non-phrasing content, such as `<details>` with a `<summary>`. Without declaring the custom schema the editor will skip over these other contructions before attempting to run them through any block transforms.
Schemas are most-important when wanting to match HTML snippets containing non-phrasing content, such as `<details>` with a `<summary>`. Without declaring the custom schema the editor will skip over these other constructions before attempting to run them through any block transforms.

### Shortcode

Expand Down
2 changes: 1 addition & 1 deletion docs/reference-guides/filters/editor-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ This is a PHP filter which is applied before sending settings to the WordPress b

You may find details about this filter [on its WordPress Code Reference page](https://developer.wordpress.org/reference/hooks/block_editor_settings_all/).

The filter will send any setting to the initialized Editor, which means any editor setting that is used to configure the editor at initialiation can be filtered by a PHP WordPress plugin before being sent.
The filter will send any setting to the initialized Editor, which means any editor setting that is used to configure the editor at initialization can be filtered by a PHP WordPress plugin before being sent.

_Example:_

Expand Down
1 change: 0 additions & 1 deletion lib/class-wp-duotone-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,6 @@ public static function render_duotone_support( $block_content, $block ) {
$has_global_styles_duotone = array_key_exists( $block['blockName'], self::$global_styles_block_names );

if (
empty( $block_content ) ||
! $duotone_selector ||
( ! $has_duotone_attribute && ! $has_global_styles_duotone )
) {
Expand Down
23 changes: 12 additions & 11 deletions lib/compat/wordpress-6.4/block-patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@
*/
function gutenberg_register_taxonomy_patterns() {
$args = array(
'public' => true,
'publicly_queryable' => false,
'hierarchical' => false,
'labels' => array(
'public' => true,
'publicly_queryable' => false,
'hierarchical' => false,
'labels' => array(
'name' => _x( 'Pattern Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Pattern Category', 'taxonomy singular name' ),
),
'query_var' => false,
'rewrite' => false,
'show_ui' => true,
'_builtin' => true,
'show_in_nav_menus' => false,
'show_in_rest' => true,
'show_admin_column' => true,
'query_var' => false,
'rewrite' => false,
'show_ui' => true,
'_builtin' => true,
'show_in_nav_menus' => false,
'show_in_rest' => true,
'show_admin_column' => true,
'rest_controller_class' => 'Gutenberg_REST_Pattern_Categories_Controller',
);
register_taxonomy( 'wp_pattern_category', array( 'wp_block' ), $args );
}
Expand Down
24 changes: 24 additions & 0 deletions lib/compat/wordpress-6.4/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,27 @@ function gutenberg_add_custom_capabilities_to_wp_block( $args ) {
return $args;
}
add_filter( 'register_wp_block_post_type_args', 'gutenberg_add_custom_capabilities_to_wp_block', 10, 1 );

/**
* Updates the wp_block REST enpoint in order to modify the wp_pattern_category action
* links that are returned because as although the taxonomy is flat Author level users
* are only allowed to assign categories.
*
* Note: This should be removed when the minimum required WP version is >= 6.4.
*
* @see https://github.com/WordPress/gutenberg/pull/55379
*
* @param array $args Register post type args.
* @param string $post_type The post type string.
*
* @return array Register post type args.
*/
function gutenberg_update_patterns_block_rest_controller_class( $args, $post_type ) {
if ( 'wp_block' === $post_type ) {
$args['rest_controller_class'] = 'Gutenberg_REST_Blocks_Controller_6_4';
}

return $args;
}

add_filter( 'register_post_type_args', 'gutenberg_update_patterns_block_rest_controller_class', 11, 2 );
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* Reusable blocks REST API: WP_REST_Blocks_Controller class
*
* @package WordPress
* @subpackage REST_API
* @since 5.0.0
*/

/**
* Controller which provides a REST endpoint for the editor to read, create,
* edit and delete reusable blocks. Blocks are stored as posts with the wp_block
* post type.
*
* @since 5.0.0
*
* @see WP_REST_Posts_Controller
* @see WP_REST_Controller
*/
class Gutenberg_REST_Blocks_Controller_6_4 extends Gutenberg_REST_Blocks_Controller {
/**
* Gets the link relations available for the post and current user.
*
* @since 6.4.0 Ensures that only users with `edit_terms` capability can add taxonomy terms.
*
* @param WP_Post $post Post object.
* @param WP_REST_Request $request Request object.
* @return array List of link relations.
*/
protected function get_available_actions( $post, $request ) {
if ( 'edit' !== $request['context'] ) {
return array();
}

$rels = array();

$post_type = get_post_type_object( $post->post_type );

if ( 'attachment' !== $this->post_type && current_user_can( $post_type->cap->publish_posts ) ) {
$rels[] = 'https://api.w.org/action-publish';
}

if ( current_user_can( 'unfiltered_html' ) ) {
$rels[] = 'https://api.w.org/action-unfiltered-html';
}

if ( 'post' === $post_type->name ) {
if ( current_user_can( $post_type->cap->edit_others_posts ) && current_user_can( $post_type->cap->publish_posts ) ) {
$rels[] = 'https://api.w.org/action-sticky';
}
}

if ( post_type_supports( $post_type->name, 'author' ) ) {
if ( current_user_can( $post_type->cap->edit_others_posts ) ) {
$rels[] = 'https://api.w.org/action-assign-author';
}
}

$taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );

foreach ( $taxonomies as $tax ) {
$tax_base = ! empty( $tax->rest_base ) ? $tax->rest_base : $tax->name;

if ( current_user_can( $tax->cap->edit_terms ) ) {
$rels[] = 'https://api.w.org/action-create-' . $tax_base;
}

if ( current_user_can( $tax->cap->assign_terms ) ) {
$rels[] = 'https://api.w.org/action-assign-' . $tax_base;
}
}

return $rels;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Gutenberg_REST_Pattern_Categories_Controller class
*
* Extends the WP_REST_Terms_Controller to handle permissions of pattern categories.
*
* @package Gutenberg
* @subpackage REST_API
* @since 6.4.0
*/

/**
* Extends the WP_REST_Terms_Controller to handle permissions of pattern categories.
*
* @access public
*/
class Gutenberg_REST_Pattern_Categories_Controller extends WP_REST_Terms_Controller {
/**
* Make pattern categories behave more like a hierarchical taxonomy in terms of permissions.
* Check the edit_terms cap to see whether term creation is possible.
*
* @since 6.4.0
*
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function create_item_permissions_check( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
if ( ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
return false;
}

$taxonomy_obj = get_taxonomy( $this->taxonomy );

// Patterns categories are a flat hierarchy (like tags), but work more like post categories in terms of permissions.
if ( ! current_user_can( $taxonomy_obj->cap->edit_terms ) ) {
return new WP_Error(
'rest_cannot_create',
__( 'Sorry, you are not allowed to create terms in this taxonomy.' ),
array( 'status' => rest_authorization_required_code() )
);
}

return true;
}
}
53 changes: 53 additions & 0 deletions lib/experimental/data-views.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Dataviews custom post type and taxonomy.
*
* @package gutenberg
*/

/**
* Registers the `wp_dataviews` post type and the `wp_dataviews_type` taxonomy.
*/
function _gutenberg_register_data_views_post_type() {
register_post_type(
'wp_dataviews',
array(
'label' => _x( 'Dataviews', 'post type general name', 'gutenberg' ),
'description' => __( 'Post which stores the different data views configurations', 'gutenberg' ),
'public' => false,
'show_ui' => false,
'show_in_rest' => true,
'rewrite' => false,
'capabilities' => array(
'read' => 'edit_published_posts',
// 'create_posts' => 'edit_published_posts',
// 'edit_posts' => 'edit_published_posts',
// 'edit_published_posts' => 'edit_published_posts',
// 'delete_published_posts' => 'delete_published_posts',
// 'edit_others_posts' => 'edit_others_posts',
// 'delete_others_posts' => 'edit_theme_options',
),
'map_meta_cap' => true,
'supports' => array( 'title', 'slug', 'editor' ),
)
);

register_taxonomy(
'wp_dataviews_type',
array( 'wp_dataviews' ),
array(
'public' => true,
'hierarchical' => false,
'labels' => array(
'name' => __( 'Dataview types', 'gutenberg' ),
'singular_name' => __( 'Dataview type', 'gutenberg' ),
),
'rewrite' => false,
'show_ui' => false,
'show_in_nav_menus' => false,
'show_in_rest' => true,
)
);
}

add_action( 'init', '_gutenberg_register_data_views_post_type' );
15 changes: 5 additions & 10 deletions lib/experimental/interactivity-api/directives/wp-context.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@ function gutenberg_interactivity_process_wp_context( $tags, $context ) {
}

$value = $tags->get_attribute( 'data-wp-context' );
if ( null === $value ) {
// No data-wp-context directive.
return;
}

$new_context = json_decode( $value, true );
if ( null === $new_context ) {
// If the JSON is not valid, we still add an empty array to the stack.
$new_context = array();
}
$new_context = json_decode(
is_string( $value ) && ! empty( $value ) ? $value : '{}',
true
);

$context->set_context( $new_context );
$context->set_context( $new_context ?? array() );
}
Loading

0 comments on commit ad4eb65

Please sign in to comment.