Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/trunk' into add/template-post-co…
Browse files Browse the repository at this point in the history
…ntext-switching
  • Loading branch information
noisysocks committed Jun 1, 2023
2 parents 97e8f23 + dde096e commit 46c4074
Show file tree
Hide file tree
Showing 260 changed files with 7,072 additions and 3,582 deletions.
294 changes: 281 additions & 13 deletions changelog.txt

Large diffs are not rendered by default.

17 changes: 6 additions & 11 deletions docs/contributors/code/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The editor provides several vendor and internal scripts to plugin developers. Script names, handles, and descriptions are documented in the table below.

## WP Scripts
## WordPress scripts

The editor includes a number of packages to enable various pieces of functionality. Plugin developers can utilize them to create blocks, editor plugins, or generic plugins.

Expand Down Expand Up @@ -40,7 +40,7 @@ The editor includes a number of packages to enable various pieces of functionali
| [Viewport](/packages/viewport/README.md) | wp-viewport | Module for responding to changes in the browser viewport size |
| [Wordcount](/packages/wordcount/README.md) | wp-wordcount | WordPress word count utility |

## Vendor Scripts
## Vendor scripts

The editor also uses some popular third-party packages and scripts. Plugin developers can use these scripts as well without bundling them in their code (and increasing file sizes).

Expand All @@ -51,9 +51,10 @@ The editor also uses some popular third-party packages and scripts. Plugin devel
| [Moment](https://momentjs.com/) | moment | Parse, validate, manipulate, and display dates and times in JavaScript |
| [Lodash](https://lodash.com) | lodash | Lodash is a JavaScript library which provides utility functions for common programming tasks |

## Polyfill Scripts
## Polyfill scripts

The editor also provides polyfills for certain features that may not be available in all modern browsers.

It is recommended to use the main `wp-polyfill` script handle which takes care of loading all the below mentioned polyfills.

| Script Name | Handle | Description |
Expand All @@ -67,12 +68,6 @@ It is recommended to use the main `wp-polyfill` script handle which takes care o

## Bundling and code sharing

When using a JavaScript bundler like [webpack](https://webpack.js.org/), the scripts mentioned here
can be excluded from the bundle and provided by WordPress in the form of script dependencies [see
`wp_enqueue_script`](https://developer.wordpress.org/reference/functions/wp_enqueue_script/#default-scripts-included-and-registered-by-wordpress).
When using a JavaScript bundler like [webpack](https://webpack.js.org/), the scripts mentioned here can be excluded from the bundle and provided by WordPress in the form of script dependencies see [`wp_enqueue_script`](https://developer.wordpress.org/reference/functions/wp_enqueue_script/#default-scripts-included-and-registered-by-wordpress).

The
[`@wordpress/dependency-extraction-webpack-plugin`](https://github.com/WordPress/gutenberg/tree/HEAD/packages/dependency-extraction-webpack-plugin)
provides a webpack plugin to help extract WordPress dependencies from bundles. `@wordpress/scripts`
[`build`](https://github.com/WordPress/gutenberg/tree/HEAD/packages/scripts#build) script includes
the plugin by default.
The [`@wordpress/dependency-extraction-webpack-plugin`](https://github.com/WordPress/gutenberg/tree/HEAD/packages/dependency-extraction-webpack-plugin) provides a webpack plugin to help extract WordPress dependencies from bundles. The `@wordpress/scripts` [`build`](https://github.com/WordPress/gutenberg/tree/HEAD/packages/scripts#build) script includes the plugin by default.
31 changes: 0 additions & 31 deletions docs/contributors/roadmap.md

This file was deleted.

1 change: 1 addition & 0 deletions docs/explanations/architecture/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Let’s look at the big picture and the architectural and UX principles of the b

- [Key concepts](/docs/explanations/architecture/key-concepts.md).
- [Data format and data flow](/docs/explanations/architecture/data-flow.md).
- [Entities and undo/redo](/docs/explanations/architecture/entities.md).
- [Site editing templates](/docs/explanations/architecture/full-site-editing-templates.md).
- [Styles in the editor](/docs/explanations/architecture/styles.md).
- [Performance](/docs/explanations/architecture/performance.md).
Expand Down
63 changes: 63 additions & 0 deletions docs/explanations/architecture/entities.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Entities and Undo/Redo.

The WordPress editors, whether it's the post or site editor, manipulate what we call entity records. These are objects that represent a post, a page, a user, a term, a template, etc. They are the data that is stored in the database and that is manipulated by the editor. Each editor can fetch, edit and save multiple entity records at the same time.

For instance, when opening a page in the site editor:
- you can edit properties of the page itself (title, content...)
- you can edit properties of the template of the page (content of the template, design...)
- you can edit properties of template parts (header, footer) used with the template.

The editor keeps track of all these modifications and orchestrates the saving of all these modified records. This happens within the `@wordpress/core-data` package.


## Editing entities

To be able to edit an entity, you need to first fetch it and load it into the `core-data` store. For example, the following code loads the post with ID 1 into the store. (The entity is the post, the post 1 is the entity record).

````js
wp.data.dispatch( 'core' ).getEntityRecord( 'postType', 'post', 1 );
````

Once the entity is loaded, you can edit it. For example, the following code sets the title of the post to "Hello World". For each fetched entity record, the `core-data` store keeps track of:
- the "persisted" record: The last state of the record as it was fetched from the backend.
- A list of "edits": Unsaved local modifications for one or several properties of the record.

The package also exposes a set of actions to manipulate the fetched entity records.

To edit an entity record, you can call `editEntityRecord`, which takes the entity type, the entity ID and the new entity record as parameters. The following example sets the title of the post with ID 1 to "Hello World".

````js
wp.data.dispatch( 'core' ).editEntityRecord( 'postType', 'post', 1, { title: 'Hello World' } );
````

Once you have edited an entity record, you can save it. The following code saves the post with ID 1.

````js
wp.data.dispatch( 'core' ).saveEditedEntityRecord( 'postType', 'post', 1 );
````

## Undo/Redo

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:

- 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.
- Property: The name of the modified property.
- From: The previous value of the property (needed to apply the undo operation).
- To: The new value of the property (needed to apply the redo operation).

For example, let's say a user edits the title of a post, followed by a modification to the post slug, and then a modification of the title of a reusable block used with the post. The following information is stored in the undo/redo stack:

- `[ { kind: 'postType', name: 'post', id: 1, property: 'title', from: '', to: 'Hello World' } ]`
- `[ { kind: 'postType', name: 'post', id: 1, property: 'slug', from: 'Previous slug', to: 'This is the slug of the hello world post' } ]`
- `[ { kind: 'postType', name: 'wp_block', id: 2, property: 'title', from: 'Reusable Block', to: 'Awesome Reusable Block' } ]`

The store also keep tracks of a "pointer" to the current "undo/redo" step. By default, the pointer always points to the last item in the stack. This pointer is updated when the user performs an undo or redo operation.

### Transient changes

The undo/redo core behavior also supports what we call "transient modifications". These are modifications that are not stored in the undo/redo stack right away. For instance, when a user starts typing in a text field, the value of the field is modified in the store, but this modification is not stored in the undo/redo stack until after the user moves to the next word or after a few milliseconds. This is done to avoid creating a new undo/redo step for each character typed by the user.

So by default, `core-data` store considers all modifications to properties that are marked as "transient" (like the `blocks` property in the post entity) as transient modifications. It keeps these modifications outside the undo/redo stack in what is called a "cache" of modifications and these modifications are only stored in the undo/redo stack when we explicitely call `__unstableCreateUndoLevel` or when the next non-transient modification is performed.
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ Like scripts, you can enqueue your block's styles using the `block.json` file.

Use the `editorStyle` property to a CSS file you want to load in the editor view, and use the `style` property for a CSS file you want to load on the frontend when the block is used.

It is worth noting that, if the editor content is iframed, both of these will
load in the iframe. `editorStyle` will also load outside the iframe, so it can
be used for editor content as well as UI.

For example:

```json
Expand Down
2 changes: 1 addition & 1 deletion docs/how-to-guides/curating-the-editor-experience.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ addFilter(
'blockEditor.useSetting.before',
'example/useSetting.before',
( settingValue, settingName, clientId, blockName ) => {
if ( blockName === Media & Text block'core/column' && settingName === 'spacing.units' ) {
if ( blockName === 'core/column' && settingName === 'spacing.units' ) {
return [ 'px' ];
}
return settingValue;
Expand Down
12 changes: 6 additions & 6 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2039,6 +2039,12 @@
"markdown_source": "../docs/explanations/architecture/data-flow.md",
"parent": "architecture"
},
{
"title": "Entities and Undo/Redo.",
"slug": "entities",
"markdown_source": "../docs/explanations/architecture/entities.md",
"parent": "architecture"
},
{
"title": "Modularity",
"slug": "modularity",
Expand Down Expand Up @@ -2308,11 +2314,5 @@
"slug": "versions-in-wordpress",
"markdown_source": "../docs/contributors/versions-in-wordpress.md",
"parent": "contributors"
},
{
"title": "Upcoming Projects & Roadmap",
"slug": "roadmap",
"markdown_source": "../docs/contributors/roadmap.md",
"parent": "contributors"
}
]
3 changes: 1 addition & 2 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ Add an image or video with a text overlay. ([Source](https://github.com/WordPres
Hide and show additional content. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/details))

- **Name:** core/details
- **Experimental:** true
- **Category:** text
- **Supports:** align (full, wide), color (background, gradients, link, text), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** showContent, summary
Expand Down Expand Up @@ -677,7 +676,7 @@ Displays a paginated navigation to next/previous set of posts, when applicable.
- **Category:** theme
- **Parent:** core/query
- **Supports:** align, anchor, color (background, gradients, link, text), typography (fontSize, lineHeight), ~~html~~, ~~reusable~~
- **Attributes:** paginationArrow
- **Attributes:** paginationArrow, showLabel

## Next Page

Expand Down
92 changes: 92 additions & 0 deletions docs/reference-guides/data/data-core-notices.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,53 @@ _Returns_

- `Object`: Action object.

### removeAllNotices

Removes all notices from a given context. Defaults to the default context.

_Usage_

```js
import { __ } from '@wordpress/i18n';
import { useDispatch, useSelect } from '@wordpress/data';
import { store as noticesStore } from '@wordpress/notices';
import { Button } from '@wordpress/components';

export const ExampleComponent = () => {
const notices = useSelect( ( select ) =>
select( noticesStore ).getNotices()
);
const { removeNotices } = useDispatch( noticesStore );
return (
<>
<ul>
{ notices.map( ( notice ) => (
<li key={ notice.id }>{ notice.content }</li>
) ) }
</ul>
<Button onClick={ () => removeAllNotices() }>
{ __( 'Clear all notices', 'woo-gutenberg-products-block' ) }
</Button>
<Button onClick={ () => removeAllNotices( 'snackbar' ) }>
{ __(
'Clear all snackbar notices',
'woo-gutenberg-products-block'
) }
</Button>
</>
);
};
```

_Parameters_

- _noticeType_ `string`: The context to remove all notices from.
- _context_ `string`: The context to remove all notices from.

_Returns_

- `Object`: Action object.

### removeNotice

Returns an action object used in signalling that a notice is to be removed.
Expand Down Expand Up @@ -309,4 +356,49 @@ _Returns_

- `Object`: Action object.

### removeNotices

Returns an action object used in signalling that several notices are to be removed.

_Usage_

```js
import { __ } from '@wordpress/i18n';
import { useDispatch, useSelect } from '@wordpress/data';
import { store as noticesStore } from '@wordpress/notices';
import { Button } from '@wordpress/components';

const ExampleComponent = () => {
const notices = useSelect( ( select ) =>
select( noticesStore ).getNotices()
);
const { removeNotices } = useDispatch( noticesStore );
return (
<>
<ul>
{ notices.map( ( notice ) => (
<li key={ notice.id }>{ notice.content }</li>
) ) }
</ul>
<Button
onClick={ () =>
removeNotices( notices.map( ( { id } ) => id ) )
}
>
{ __( 'Clear all notices' ) }
</Button>
</>
);
};
```

_Parameters_

- _ids_ `string[]`: List of unique notice identifiers.
- _context_ `[string]`: Optional context (grouping) in which the notices are intended to appear. Defaults to default context.

_Returns_

- `Object`: Action object.

<!-- END TOKEN(Autogenerated actions|../../../packages/notices/src/store/actions.js) -->
4 changes: 4 additions & 0 deletions docs/reference-guides/data/data-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ _Returns_

### getRedoEdit

> **Deprecated** since 6.3
Returns the next edit from the current undo offset for the entity records edits history, if any.

_Parameters_
Expand Down Expand Up @@ -401,6 +403,8 @@ _Returns_

### getUndoEdit

> **Deprecated** since 6.3
Returns the previous edit from the current undo offset for the entity records edits history, if any.

_Parameters_
Expand Down
4 changes: 2 additions & 2 deletions docs/toc.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
"docs/explanations/architecture/README.md": [
{ "docs/explanations/architecture/key-concepts.md": [] },
{ "docs/explanations/architecture/data-flow.md": [] },
{ "docs/explanations/architecture/entities.md": [] },
{ "docs/explanations/architecture/modularity.md": [] },
{ "docs/explanations/architecture/performance.md": [] },
{
Expand Down Expand Up @@ -399,8 +400,7 @@
{ "docs/contributors/accessibility-testing.md": [] },
{ "docs/contributors/repository-management.md": [] },
{ "docs/contributors/folder-structure.md": [] },
{ "docs/contributors/versions-in-wordpress.md": [] },
{ "docs/contributors/roadmap.md": [] }
{ "docs/contributors/versions-in-wordpress.md": [] }
]
}
]
2 changes: 1 addition & 1 deletion gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Printing since 1440. This is the development plugin for the block editor, site editor, and other future WordPress core functionality.
* Requires at least: 6.1
* Requires PHP: 5.6
* Version: 15.9.0-rc.1
* Version: 15.9.0
* Author: Gutenberg Team
* Text Domain: gutenberg
*
Expand Down
2 changes: 1 addition & 1 deletion lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ function gutenberg_restore_group_inner_container( $block_content, $block ) {
);
$updated_content = preg_replace_callback(
$replace_regex,
function( $matches ) {
static function( $matches ) {
return $matches[1] . '<div class="wp-block-group__inner-container">' . $matches[2] . '</div>' . $matches[3];
},
$block_content
Expand Down
Loading

0 comments on commit 46c4074

Please sign in to comment.