Skip to content

Commit

Permalink
Merge changes published in the Gutenberg plugin "release/14.1" branch
Browse files Browse the repository at this point in the history
  • Loading branch information
gutenbergplugin committed Sep 13, 2022
1 parent 171b87c commit 7ef0628
Show file tree
Hide file tree
Showing 1,121 changed files with 26,641 additions and 14,847 deletions.
12 changes: 10 additions & 2 deletions .eslintrc.js
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
const { escapeRegExp } = require( 'lodash' );
const glob = require( 'glob' ).sync;
const { join } = require( 'path' );

Expand All @@ -17,7 +16,8 @@ const { version } = require( './package' );
* @type {string}
*/
const majorMinorRegExp =
escapeRegExp( version.replace( /\.\d+$/, '' ) ) + '(\\.\\d+)?';
version.replace( /\.\d+$/, '' ).replace( /[\\^$.*+?()[\]{}|]/g, '\\$&' ) +
'(\\.\\d+)?';

/**
* The list of patterns matching files used only for development purposes.
Expand Down Expand Up @@ -83,6 +83,7 @@ module.exports = {
'capitalize',
'chunk',
'clamp',
'cloneDeep',
'compact',
'concat',
'countBy',
Expand All @@ -94,14 +95,18 @@ module.exports = {
'differenceWith',
'dropRight',
'each',
'escapeRegExp',
'extend',
'findIndex',
'findKey',
'findLast',
'first',
'flatMap',
'flatten',
'flattenDeep',
'forEach',
'fromPairs',
'has',
'identity',
'invoke',
'isArray',
Expand All @@ -118,6 +123,7 @@ module.exports = {
'isUndefined',
'keyBy',
'keys',
'last',
'lowerCase',
'mapKeys',
'maxBy',
Expand All @@ -127,6 +133,7 @@ module.exports = {
'nth',
'once',
'overEvery',
'partial',
'partialRight',
'random',
'reject',
Expand All @@ -146,6 +153,7 @@ module.exports = {
'toString',
'trim',
'truncate',
'unionBy',
'uniq',
'uniqBy',
'uniqueId',
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/stale-issue-flaky-test.yml
@@ -0,0 +1,19 @@
name: 'Mark old flaky tests issues as stale'
on:
schedule:
- cron: '20 1 * * *'

jobs:
stale:
runs-on: ubuntu-latest
if: ${{ github.repository == 'WordPress/gutenberg' }}

steps:
- uses: actions/stale@996798eb71ef485dc4c7b4d3285842d714040c4a # v3.0.17
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue has gone 30 days without any activity.'
days-before-stale: 30
days-before-close: 1
only-labels: '[Type] Flaky Test'
stale-issue-label: '[Status] Stale'
2 changes: 1 addition & 1 deletion bin/api-docs/are-api-docs-unstaged.js
Expand Up @@ -35,7 +35,7 @@ const getUnstagedReadmes = () =>
'\n',
'Some API docs may be out of date:',
unstagedReadmes.toString(),
'Either build and stage them with npm run docs:blocks or continue with --no-verify.',
'Either build and stage them with npm run docs:build or continue with --no-verify.',
'\n'
)
);
Expand Down
13 changes: 12 additions & 1 deletion bin/plugin/commands/changelog.js
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
const { groupBy, escapeRegExp, flow } = require( 'lodash' );
const { groupBy, flow } = require( 'lodash' );
const Octokit = require( '@octokit/rest' );
const { sprintf } = require( 'sprintf-js' );
const semver = require( 'semver' );
Expand Down Expand Up @@ -185,6 +185,17 @@ const REWORD_TERMS = {
docs: 'documentation',
};

/**
* Escapes the RegExp special characters.
*
* @param {string} string Input string.
*
* @return {string} Regex-escaped string.
*/
function escapeRegExp( string ) {
return string.replace( /[\\^$.*+?()[\]{}|]/g, '\\$&' );
}

/**
* Returns candidates based on whether the given labels
* are part of the allowed list.
Expand Down
436 changes: 436 additions & 0 deletions changelog.txt

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions docs/contributors/documentation/README.md
Expand Up @@ -64,6 +64,25 @@ To add a new document requires a working JavaScript development environment to b

If you forget to run, `npm run docs:build` your PR will fail the static analysis check, since the `manifest.json` file is an uncommitted local change that must be committed.

### Documenting Packages

Package documentation is generated automatically by the documentation tool by pulling the contents of the README.md file located in the root of the package. Sometimes however, it is preferable to split the contents of the README out into smaller, easier to read portions.

This can be accomplished by creating a `docs` directory in the package and adding `toc.json` file that contains references other markdown files also contained in the `docs` directory. The `toc.json` file should contain an array of pages to be added as sub-pages of the main README file. The formatting follows the [`manifest.json`](https://github.com/WordPress/gutenberg/blob/HEAD/docs/manifest.json) file that is generated automatically.

In order for these pages to be nested under the main package name, be sure to set the `parent` property correctly. See the example below that adds child pages to the [`@wordpress/create-block` section](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/).

```json
[
{
"title": "@wordpress/create-block External Template",
"slug": "packages-create-block-external-template",
"markdown_source": "../packages/create-block/docs/external-template.md",
"parent": "packages-create-block"
}
]
```

### Using links

It's likely at some point you'll want to link to other internal documentation pages. It's worth emphasizing all documents can be browsed in different contexts:
Expand Down
2 changes: 1 addition & 1 deletion docs/how-to-guides/README.md
Expand Up @@ -30,7 +30,7 @@ Porting PHP meta boxes to blocks or sidebar plugins is highly encouraged, learn

By default, blocks provide their styles to enable basic support for blocks in themes without any change. Themes can add/override these styles, or rely on defaults.

There are some advanced block features which require opt-in support in the theme. See [theme support](/docs/how-to-guides/themes/theme-support.md).
There are some advanced block features which require opt-in support in the theme. See [theme support](/docs/how-to-guides/themes/theme-support.md) and [how to filter global styles](/docs/reference-guides/filters/global-styles-filters.md).

## Autocomplete

Expand Down
51 changes: 27 additions & 24 deletions docs/how-to-guides/data-basics/1-data-basics-setup.md
Expand Up @@ -163,29 +163,32 @@ add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_scripts' );

```json
{
"name": "05-recipe-card-esnext",
"version": "1.1.0",
"private": true,
"description": "Example: Recipe Card (ESNext).",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
"keywords": [ "WordPress", "block" ],
"homepage": "https://github.com/WordPress/gutenberg-examples/",
"repository": "git+https://github.com/WordPress/gutenberg-examples.git",
"bugs": {
"url": "https://github.com/WordPress/gutenberg-examples/issues"
},
"main": "build/index.js",
"devDependencies": {
"@wordpress/scripts": "^18.0.1"
},
"scripts": {
"build": "wp-scripts build",
"format": "wp-scripts format",
"lint:js": "wp-scripts lint-js",
"packages-update": "wp-scripts packages-update",
"start": "wp-scripts start"
}
"name": "09-code-data-basics-esnext",
"version": "1.1.0",
"private": true,
"description": "My first Gutenberg App",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
"keywords": [
"WordPress",
"block"
],
"homepage": "https://github.com/WordPress/gutenberg-examples/",
"repository": "git+https://github.com/WordPress/gutenberg-examples.git",
"bugs": {
"url": "https://github.com/WordPress/gutenberg-examples/issues"
},
"main": "build/index.js",
"devDependencies": {
"@wordpress/scripts": "^24.0.0"
},
"scripts": {
"build": "wp-scripts build",
"format": "wp-scripts format",
"lint:js": "wp-scripts lint-js",
"packages-update": "wp-scripts packages-update",
"start": "wp-scripts start"
}
}
```

Expand All @@ -209,4 +212,4 @@ Congratulations! You are now ready to start building the app!

- Previous part: [Introduction](/docs/how-to-guides/data-basics/README.md)
- Next part: [Building a basic list of pages](/docs/how-to-guides/data-basics/2-building-a-list-of-pages.md)
- (optional) Review the [finished app](https://github.com/WordPress/gutenberg-examples/tree/trunk/09-code-data-basics-esnext) in the gutenberg-examples repository
- (optional) Review the [finished app](https://github.com/WordPress/gutenberg-examples/tree/trunk/non-block-examples/09-code-data-basics-esnext) in the gutenberg-examples repository
15 changes: 13 additions & 2 deletions docs/how-to-guides/data-basics/2-building-a-list-of-pages.md
Expand Up @@ -43,7 +43,7 @@ Before we start, let’s confirm we actually have some pages to fetch. Within WP
If it doesn’t, go ahead and create a few pages – you can use the same titles as on the screenshot above. Be sure to _publish_ and not just _save_ them.
Now that we have the data to work with, let’s dive into the code. We will take advantage of the [`@wordpress/core-data` package](https://github.com/WordPress/gutenberg/tree/trunk/packages/core-data) package which provides resolvers, selectors, and actions to work with the WordPress core API. `@wordpress/core-data` builds on top of the [`@wordpress/data` package](https://github.com/WordPress/gutenberg/tree/trunk/packages/data).
Now that we have the data to work with, let’s dive into the code. We will take advantage of the [`@wordpress/core-data`](https://github.com/WordPress/gutenberg/tree/trunk/packages/core-data) package which provides resolvers, selectors, and actions to work with the WordPress core API. `@wordpress/core-data` builds on top of the [`@wordpress/data`](https://github.com/WordPress/gutenberg/tree/trunk/packages/data) package.
To fetch the list of pages, we will use the [`getEntityRecords`](/docs/reference-guides/data/data-core/#getentityrecords) selector. In broad strokes, it will issue the correct API request, cache the results, and return the list of the records we need. Here’s how to use it:
Expand All @@ -53,6 +53,8 @@ wp.data.select( 'core' ).getEntityRecords( 'postType', 'page' )
If you run that following snippet in your browser’s dev tools, you will see it returns `null`. Why? The pages are only requested by the `getEntityRecords` resolver after first running the _selector_. If you wait a moment and re-run it, it will return the list of all pages.
*Note: To run this type of command directly make sure your browser is displaying an instance of the block editor (any page will do). Otherwise the `select( 'core' )` function won't be available, and you'll get an error.*
Similarly, the `MyFirstApp` component needs to re-run the selector once the data is available. That’s exactly what the `useSelect` hook does:
```js
Expand All @@ -67,6 +69,14 @@ function MyFirstApp() {
);
// ...
}

function PagesList({ pages }) {
// ...
<li key={page.id}>
{page.title.rendered}
</li>
// ...
}
```
Note that we use an `import` statement inside index.js. This enables the plugin to automatically load the dependencies using `wp_enqueue_script`. Any references to `coreDataStore` are compiled to the same `wp.data` reference we use in browser's devtools.
Expand Down Expand Up @@ -353,6 +363,7 @@ import { SearchControl, Spinner } from '@wordpress/components';
import { useState, render } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { store as coreDataStore } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';

function MyFirstApp() {
const [ searchTerm, setSearchTerm ] = useState( '' );
Expand Down Expand Up @@ -431,4 +442,4 @@ All that’s left is to refresh the page and enjoy the brand new status indicato
* **Previous part:** [Setup](/docs/how-to-guides/data-basics/1-data-basics-setup.md)
* **Next part:** [Building an edit form](/docs/how-to-guides/data-basics/3-building-an-edit-form.md)
* (optional) Review the [finished app](https://github.com/WordPress/gutenberg-examples/tree/trunk/09-code-data-basics-esnext) in the gutenberg-examples repository
* (optional) Review the [finished app](https://github.com/WordPress/gutenberg-examples/tree/trunk/non-block-examples/09-code-data-basics-esnext) in the gutenberg-examples repository

0 comments on commit 7ef0628

Please sign in to comment.