Skip to content

Commit

Permalink
Merge branch 'master' into rnmobile/372-add-title-to-gutenberg-mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoreymendez committed Jan 17, 2019
2 parents 7f05b9c + 5575b90 commit b94bede
Show file tree
Hide file tree
Showing 276 changed files with 2,169 additions and 467 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
build
build-module
node_modules
packages/tests-e2e/plugins
packages/e2e-tests/plugins
vendor
packages/block-serialization-spec-parser/parser.js
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ module.exports = {
},
overrides: [
{
files: [ 'packages/tests-e2e/**/*.js' ],
files: [ 'packages/e2e-test*/**/*.js' ],
env: {
browser: true,
},
Expand Down
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,29 @@ jobs:
install:
- ./bin/setup-local-env.sh
script:
- $( npm bin )/wp-scripts test-e2e --testPathPattern=/packages/tests-e2e/specs/ --listTests > ~/.jest-e2e-tests
- $( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests
- npm run test-e2e -- --ci --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % 2 == 0' < ~/.jest-e2e-tests )

- name: E2E tests (Admin with plugins) (2/2)
env: WP_VERSION=latest POPULAR_PLUGINS=true
install:
- ./bin/setup-local-env.sh
script:
- $( npm bin )/wp-scripts test-e2e --testPathPattern=/packages/tests-e2e/specs/ --listTests > ~/.jest-e2e-tests
- $( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests
- npm run test-e2e -- --ci --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % 2 == 1' < ~/.jest-e2e-tests )

- name: E2E tests (Author without plugins) (1/2)
env: WP_VERSION=latest E2E_ROLE=author
install:
- ./bin/setup-local-env.sh
script:
- $( npm bin )/wp-scripts test-e2e --testPathPattern=/packages/tests-e2e/specs/ --listTests > ~/.jest-e2e-tests
- $( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests
- npm run test-e2e -- --ci --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % 2 == 0' < ~/.jest-e2e-tests )

- name: E2E tests (Author without plugins) (2/2)
env: WP_VERSION=latest E2E_ROLE=author
install:
- ./bin/setup-local-env.sh
script:
- $( npm bin )/wp-scripts test-e2e --testPathPattern=/packages/tests-e2e/specs/ --listTests > ~/.jest-e2e-tests
- $( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests
- npm run test-e2e -- --ci --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % 2 == 1' < ~/.jest-e2e-tests )
4 changes: 1 addition & 3 deletions assets/stylesheets/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ $z-layers: (
// Active pill button
".components-button.is-button {:focus or .is-primary}": 1,

// Reusable blocks UI, needs to be above sibling inserter.
".editor-block-list__layout .reusable-block-edit-panel": 7,

// The draggable element should show up above the entire UI
".components-draggable__clone": 1000000000,

Expand Down Expand Up @@ -85,6 +82,7 @@ $z-layers: (

// Shows above edit post sidebar; Specificity needs to be higher than 3 classes.
".block-editor__container .components-popover.components-color-palette__picker.is-bottom": 100001,
".block-editor__container .components-popover.components-font-size-picker__dropdown-content.is-bottom": 100001,
".edit-post-post-visibility__dialog.components-popover.is-bottom": 100001,

".components-autocomplete__results": 1000000,
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ services:
volumes:
- wordpress:/var/www/html
- .:/var/www/html/wp-content/plugins/gutenberg
- ./packages/tests-e2e/plugins:/var/www/html/wp-content/plugins/gutenberg-test-plugins
- ./packages/tests-e2e/mu-plugins:/var/www/html/wp-content/mu-plugins
- ./packages/e2e-tests/plugins:/var/www/html/wp-content/plugins/gutenberg-test-plugins
- ./packages/e2e-tests/mu-plugins:/var/www/html/wp-content/mu-plugins
depends_on:
- mysql

Expand Down Expand Up @@ -59,8 +59,8 @@ services:
volumes:
- wordpress_e2e_tests:/var/www/html
- .:/var/www/html/wp-content/plugins/gutenberg
- ./packages/tests-e2e/plugins:/var/www/html/wp-content/plugins/gutenberg-test-plugins
- ./test/e2e/mu-plugins:/var/www/html/wp-content/mu-plugins
- ./packages/e2e-tests/plugins:/var/www/html/wp-content/plugins/gutenberg-test-plugins
- ./packages/e2e-tests/mu-plugins:/var/www/html/wp-content/mu-plugins

cli_e2e_tests:
image: wordpress:cli
Expand Down
12 changes: 6 additions & 6 deletions docs/contributors/testing-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ When writing tests consider the following:

## JavaScript Testing

Tests for JavaScript use [Jest](http://facebook.github.io/jest/) as the test runner and its API for [globals](https://facebook.github.io/jest/docs/en/api.html) (`describe`, `test`, `beforeEach` and so on) [assertions](http://facebook.github.io/jest/docs/en/expect.html), [mocks](http://facebook.github.io/jest/docs/en/mock-functions.html), [spies](http://facebook.github.io/jest/docs/en/jest-object.html#jestspyonobject-methodname) and [mock functions](https://facebook.github.io/jest/docs/en/mock-function-api.html). If needed, you can also use [Enzyme](https://github.com/airbnb/enzyme) for React component testing.
Tests for JavaScript use [Jest](https://jestjs.io/) as the test runner and its API for [globals](https://jestjs.io/docs/en/api.html) (`describe`, `test`, `beforeEach` and so on) [assertions](https://jestjs.io/docs/en/expect.html), [mocks](https://jestjs.io/docs/en/mock-functions.html), [spies](https://jestjs.io/docs/en/jest-object.html#jestspyonobject-methodname) and [mock functions](https://jestjs.io/docs/en/mock-function-api.html). If needed, you can also use [Enzyme](https://github.com/airbnb/enzyme) for React component testing.

Assuming you've followed the [instructions](https://github.com/WordPress/gutenberg/blob/master/CONTRIBUTING.md) to install Node and project dependencies, tests can be run from the command-line with NPM:

Expand Down Expand Up @@ -88,9 +88,9 @@ describe( 'CheckboxWithLabel', () => {

### Setup and Teardown methods

The Jest API includes some nifty [setup and teardown methods](https://facebook.github.io/jest/docs/en/setup-teardown.html) that allow you to perform tasks *before* and *after* each or all of your tests, or tests within a specific `describe` block.
The Jest API includes some nifty [setup and teardown methods](https://jestjs.io/docs/en/setup-teardown.html) that allow you to perform tasks *before* and *after* each or all of your tests, or tests within a specific `describe` block.

These methods can handle asynchronous code to allow setup that you normally cannot do inline. As with [individual test cases](https://facebook.github.io/jest/docs/en/asynchronous.html#promises), you can return a Promise and Jest will wait for it to resolve:
These methods can handle asynchronous code to allow setup that you normally cannot do inline. As with [individual test cases](https://jestjs.io/docs/en/asynchronous.html#promises), you can return a Promise and Jest will wait for it to resolve:

```javascript
// one-time setup for *all* tests
Expand Down Expand Up @@ -188,7 +188,7 @@ describe( 'The bilbo module', () => {

### Testing globals

We can use [Jest spies](http://facebook.github.io/jest/docs/en/jest-object.html#jestspyonobject-methodname) to test code that calls global methods.
We can use [Jest spies](https://jestjs.io/docs/en/jest-object.html#jestspyonobject-methodname) to test code that calls global methods.

```javascript
import { myModuleFunctionThatOpensANewWindow } from '../my-module';
Expand Down Expand Up @@ -374,5 +374,5 @@ Code style in PHP is enforced using [PHP_CodeSniffer](https://github.com/squizla
To run unit tests only, without the linter, use `npm run test-unit-php` instead.
[snapshot testing]: https://facebook.github.io/jest/docs/en/snapshot-testing.html
[update snapshots]: https://facebook.github.io/jest/docs/en/snapshot-testing.html#updating-snapshots
[snapshot testing]: https://jestjs.io/docs/en/snapshot-testing.html
[update snapshots]: https://jestjs.io/docs/en/snapshot-testing.html#updating-snapshots
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ transforms: {
{
type: 'block',
blocks: [ 'core/paragraph' ],
transform: function ( content ) {
transform: function ( attributes ) {
return createBlock( 'core/heading', {
content,
content: attributes.content,
} );
},
},
Expand Down Expand Up @@ -284,9 +284,9 @@ transforms: {
{
type: 'block',
blocks: [ 'core/paragraph' ],
transform: function( content ) {
transform: function( attributes ) {
return createBlock( 'core/paragraph', {
content,
content: attributes.content,
} );
},
},
Expand Down Expand Up @@ -321,12 +321,12 @@ transforms: {
{
type: 'block',
blocks: [ 'core/paragraph' ],
isMatch: function( attribute ) {
isMatch: function( attributes ) {
return attributes.isText;
},
transform: function( content ) {
transform: function( attributes ) {
return createBlock( 'core/paragraph', {
content,
content: attributes.content,
} );
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ registerBlockType( 'gutenberg-boilerplate-esnext/hello-world-step-01', {
```
{% end %}

Once a block is registered, you should immediately see that it becomes available as an option in the editor inserter dialog, using values from `title`, `icon`, and `category` to organize its display. You can choose an icon from any included in the built-in [Dashicons icon set](https://developer.wordpress.org/resource/dashicons/), or provide a [custom svg element](https://wordpress.org/gutenberg/handbook/block-api/#icon-optional).
Once a block is registered, you should immediately see that it becomes available as an option in the editor inserter dialog, using values from `title`, `icon`, and `category` to organize its display. You can choose an icon from any included in the built-in [Dashicons icon set](https://developer.wordpress.org/resource/dashicons/), or provide a [custom svg element](https://wordpress.org/gutenberg/handbook/designers-developers/developers/block-api/block-registration/#icon-optional).

A block name must be prefixed with a namespace specific to your plugin. This helps prevent conflicts when more than one plugin registers a block with the same name.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Register a new format

The first thing you're going to do in this tutorial is to register the new format that the plugin intends to apply. WordPress has the [`registerFormatType`](/packages/rich-text/README.md#registerFormatType) function to do so.

Let's prepare a minimal plugin to make this work. Create a new folder and a file named `my-custom-format.php` within it containing the necessary PHP code to register and enqueue the JavaScript assets:

```php
<?php
/**
* Plugin Name: My custom format
*/

function my_custom_format_script_register() {
wp_register_script(
'my-custom-format-js',
plugins_url( 'my-custom-format.js', __FILE__ ),
array( 'wp-rich-text' )
);
}
add_action( 'init', 'my_custom_format_script_register' );

function my_custom_format_enqueue_assets_editor() {
wp_enqueue_script( 'my-custom-format-js' );
}
add_action( 'enqueue_block_editor_assets', 'my_custom_format_enqueue_assets_editor' );
```

Then add a new file named `my-custom-format.js` with the following contents:

```js
( function( wp ) {
wp.richText.registerFormatType(
'my-custom-format/sample-output', {
title: 'Sample output',
tagName: 'samp',
className: null,
}
);
} )( window.wp );
```

Make that plugin available in your WordPress setup and activate it. Then, load a new page/post.

The list of available format types is maintained in the `core/rich-text` store. You can query the store to check that your custom format is now avaliable. To do so, run this code in your browser's console:

wp.data.select( 'core/rich-text' ).getFormatTypes();

It'll return an array containing the format types, including your own.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Add a button to the toolbar

Now that the format is avaible, the next step is to surface it to the UI. You can make use of the [`RichTextToolbarButton`](/packages/editor/src/components/rich-text/README.md#RichTextToolbarButton) component to extend the format toolbar.

Paste this code in `my-custom-format.js`:

```js
( function( wp ) {
var MyCustomButton = function( props ) {
return wp.element.createElement(
wp.editor.RichTextToolbarButton, {
icon: 'editor-code',
title: 'Sample output',
onClick: function() {
console.log( 'toggle format' );
},
}
);
}
wp.richText.registerFormatType(
'my-custom-format/sample-output', {
title: 'Sample output',
tagName: 'samp',
className: null,
edit: MyCustomButton,
}
);
} )( window.wp );
```

**Important**: note that this code is using two new utilities (`wp.element.createElement`, and `wp.editor.RichTextToolbarButton`) so don't forget adding the corresponding `wp-element` and `wp-editor` packages to the dependencies array in the PHP file along with the existing `wp-rich-text`.

Let's check that everything is working as expected. Reload the post/page and select a text block. Make sure that the new button was added to the format toolbar, it uses the [editor-code dashicon](https://developer.wordpress.org/resource/dashicons/#editor-code), and the hover text is what you set in the title:

![Toolbar with custom button](https://github.com/raw/WordPress/gutenberg/master/docs/designers-developers/assets/toolbar-with-custom-button.png)

You may also want to check that upon clicking the button the `toggle format` message is shown in your browser's console.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Apply the format when the button is clicked

So far, your custom button doesn't modify the text selected, it only renders a message in the console. Let's change that.

The [rich-text package](/packages/rich-text/README.md) offers a few utilities to work with formats: [applyFormat](/packages/rich-text/README.md#applyFormat), [removeFormat](/packages/rich-text/README.md#removeFormat), and [toggleFormat](/packages/rich-text/README.md#toggleFormat). In this particular example, the format you want to apply (the `<samp>` tag) may be considered binary - either a text selection has the tag or not. Taking that into account, the `toggleFormat` primitive seems more convenient.

Update `my-custom-format.js` with this new code:

```js
( function( wp ) {
var MyCustomButton = function( props ) {
return wp.element.createElement(
wp.editor.RichTextToolbarButton, {
icon: 'editor-code',
title: 'Sample output',
onClick: function() {
props.onChange( wp.richText.toggleFormat(
props.value,
{ type: 'my-custom-format/sample-output' }
) );
},
isActive: props.isActive,
}
);
}
wp.richText.registerFormatType(
'my-custom-format/sample-output', {
title: 'Sample output',
tagName: 'samp',
className: null,
edit: MyCustomButton,
}
);
} )( window.wp );
```

Now, let's check that is working as intended: reload the post/page, make a text selection, click the button, and then change to HTML view to confirm that the tag was effectively applied.

The expected behavior is that the format will be toggled, meaning that the text selected will be wrapped by a `<samp>` tag if it isn't yet, or the tag will be removed if the selection is already wrapped with the tag. Notice that the button renders a different style depending on whether the selection has the tag or not as well - this is controlled by the `isActive` property of the `RichTextToolbarButton` component.

Your browser may have already displayed the selection differently once the tag was applied, but you may want to use a special style of your own. You can use the `className` option in [`registerFormatType`](/packages/rich-text/README.md#registerFormatType) to target the new element by class name: if `className` is set, it'll be added to the new element.

That's it. This is all that is necessary to make a custom format available in the new editor. From here, you may want to check out other [tutorials](/docs/designers-developers/developers/tutorials/) or apply your new knowledge to your next plugin!
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Introduction to the Format API

The purpose of this tutorial is to introduce you to the Format API. The Format API makes it possible for developers to add custom buttons to the formatting toolbar and have them apply a _format_ to a text selection. Bold is an example of a standard button in the formatting toolbar.

In WordPress lingo, a _format_ is a [HTML tag with text-level semantics](https://www.w3.org/TR/html5/textlevel-semantics.html#text-level-semantics-usage-summary) used to give some special meaning to a text selection. For example, in this tutorial, the button to be hooked into the format toolbar will let users wrap a particular text selection with the [`<samp>` HTML tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/samp).

If you are unfamiliar with how to work with WordPress plugins and JavaScript, you may want to check the [JavaScript Tutorial](/docs/designers-developers/developers/tutorials/javascript/readme.md) first.

## Table of contents

1. [Register a new format](/docs/designers-developers/developers/tutorials/format-api/1-register-format.md)
2. [Add a button to the toolbar](/docs/designers-developers/developers/tutorials/format-api/2-toolbar-button.md)
3. [Apply the format when the button is clicked](/docs/designers-developers/developers/tutorials/format-api/3-apply-format.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Store Post Meta with a Block

Typically, blocks store their attribute values in the serialised block HTML. However, you can also create a block that saves its attribute values as post meta, which can be accessed programatically anywhere in your template.

In this short tutorial you will create one of these blocks, which will prompt a user for a single value, and save it as post meta.

For background around the thinking of blocks as the interface, please see the [Principles section](/docs/contributors/principles.md) of the handbook.

Before starting this tutorial, you will need a plugin to hold your code. Please take a look at the first two steps of [the JavaScript tutorial](/docs/designers-developers/developers/tutorials/javascript/readme.md) for information setting up a plugin.

## Table of Contents

1. [Register Meta Field](/docs/designers-developers/developers/tutorials/metabox/meta-block-2-register-meta.md)
2. [Add Meta Block](/docs/designers-developers/developers/tutorials/metabox/meta-block-3-add.md)
3. [Use Post Meta Data](/docs/designers-developers/developers/tutorials/metabox/meta-block-4-use-data.md)
4. [Finishing Touches](/docs/designers-developers/developers/tutorials/metabox/meta-block-5-finishing.md)

Loading

0 comments on commit b94bede

Please sign in to comment.