Skip to content

Commit

Permalink
Merge branch 'rnmobile/column-block' into rnmobile/column-block-with-…
Browse files Browse the repository at this point in the history
…support-inserter
  • Loading branch information
jbinda committed Mar 25, 2020
2 parents 01e35d6 + 3ec4b34 commit fbe2016
Show file tree
Hide file tree
Showing 156 changed files with 2,385 additions and 998 deletions.
19 changes: 1 addition & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ install:
fi
- |
if [[ "$INSTALL_COMPOSER" = "true" ]]; then
npm run env docker-run -- php composer install
npm run env docker-run -- php composer install --no-interaction
fi
- |
if [[ "$E2E_ROLE" = "author" ]]; then
Expand Down Expand Up @@ -209,22 +209,5 @@ jobs:
- $( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests
- $( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % 4 == 3' < ~/.jest-e2e-tests )

- stage: deploy
if: (NOT type IN (pull_request)) AND (branch = master)
name: Deploy Playground
env: INSTALL_WORDPRESS=false
install:
- npm ci
before_deploy:
- npm run storybook:build
deploy:
provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN
keep_history: true
local_dir: playground/dist
on:
branch: master

allow_failures:
# nothing is allowed to fail at the moment
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
== Changelog ==

= 7.8.0-rc.1 =

Changelog creation in progress.

= 7.7.1 =

### Bug Fixes
Expand Down
18 changes: 11 additions & 7 deletions docs/contributors/coding-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Custom types should be named as succinctly as possible, while still retaining cl
/**
* A block selection object.
*
* @typedef {Object} WPBlockSelection
* @typedef WPBlockSelection
*
* @property {string} clientId A block client ID.
* @property {string} attributeKey A block attribute key.
Expand All @@ -225,6 +225,8 @@ Custom types should be named as succinctly as possible, while still retaining cl
*/
```

Note that there is no `{Object}` between `@typedef` and the type name. As `@property`s below tells us that it is a type for objects, it is recommend to not use `{Object}` when you want to define types for your objects.

Custom types can also be used to describe a set of predefined options. While the [type union](https://jsdoc.app/tags-type.html) can be used with literal values as an inline type, it can be difficult to align tags while still respecting a maximum line length of 80 characters. Using a custom type to define a union type can afford the opportunity to describe the purpose of these options, and helps to avoid these line length issues.

```js
Expand Down Expand Up @@ -269,24 +271,26 @@ If you use a [TypeScript integration](https://github.com/Microsoft/TypeScript/wi

For packages which do not distribute their own TypeScript types, you are welcomed to install and use the [DefinitelyTyped](http://definitelytyped.org/) community-maintained types definitions, if one exists.

### Record Types
### Generic Types

When documenting a generic type such as `Object`, `Function`, `Promise`, etc., always include details about the expected record types.

```js
// Incorrect:
// Bad:

/** @type {Object} */
/** @type {Function} */
/** @type {Promise} */

// Correct:
// Good:

/** @type {Object<string,number>} */
/** @type {Record<string,number>} */ /* or */ /** @type {{[setting:string]:any}} */
/** @type {(key:string)=>boolean} */
/** @type {Promise<string>} */
```

When an object is used as a dictionary, you can define its type in 2 ways: indexable interface (`{[setting:string]:any}`) or `Record`. When the name of the key for an object provides hints for developers what to do like `setting`, use indexable interface. If not, use `Record`.

The function expression here uses TypeScript's syntax for function types, which can be useful in providing more detailed information about the names and types of the expected parameters. For more information, consult the [TypeScript `@type` tag function recommendations](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#type).

In more advanced cases, you may define your own custom types as a generic type using the [TypeScript `@template` tag](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#template).
Expand All @@ -312,7 +316,7 @@ Similar to the "Custom Types" advice concerning type unions and with literal val
/**
* Hash of breakpoint names with pixel width at which it becomes effective.
*
* @type {Object<WPBreakpoint,number>}
* @type {Record<WPBreakpoint,number>}
*/
const BREAKPOINTS = { huge: 1440 /* , ... */ };
```
Expand Down Expand Up @@ -409,7 +413,7 @@ When documenting an example, use the markdown <code>\`\`\`</code> code block to
* select( 'my-shop' ).getPrice( 'hammer' );
* ```
*
* @return {Object<string,WPDataSelector>} Object containing the store's
* @return {Record<string,WPDataSelector>} Object containing the store's
* selectors.
*/
````
Expand Down
2 changes: 2 additions & 0 deletions docs/contributors/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ npm run build

This will build Gutenberg, ready to be used as a WordPress plugin!

`npm run build` is intended for one-off compilations of the project. If you're planning to do continued development in the source files, using `npm run dev` will most often be the better option. This will configure the build to avoid minifying the generated output, rebuild files automatically as they are changed in your working directory, and configure dependencies as running in a development environment so that useful warnings and errors are logged to your browser's developer console.

If you don't have a local WordPress environment to load Gutenberg in, we can help get that up and running, too.

## Local Environment
Expand Down
37 changes: 37 additions & 0 deletions docs/designers-developers/developers/block-api/block-patterns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Patterns (Experimental)

Patterns are predefined block layouts, ready to insert and tweak.

**Note** Patterns are still under heavy development and the APIs are subject to change.

#### register_pattern

The editor comes with a list of built-in patterns. Theme and plugin authors can register addition custom patterns using the `register_pattern` function.

The `register_pattern` function receives the name of the pattern as the first argument and an array describing properties of the pattern as the second argument.

The properties of the style array must include `name` and `label`:
- `title`: A human-readable title for the pattern.
- `content`: Raw HTML content for the pattern.

```php
register_pattern(
'my-plugin/my-awesome-pattern',
array(
'title' => __( 'Two buttons', 'my-plugin' ),
'content' => "<!-- wp:buttons {\"align\":\"center\"} -->\n<div class=\"wp-block-buttons aligncenter\"><!-- wp:button {\"backgroundColor\":\"very-dark-gray\",\"borderRadius\":0} -->\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-background has-very-dark-gray-background-color no-border-radius\">" . esc_html__( 'Button One', 'my-plugin' ) . "</a></div>\n<!-- /wp:button -->\n\n<!-- wp:button {\"textColor\":\"very-dark-gray\",\"borderRadius\":0,\"className\":\"is-style-outline\"} -->\n<div class=\"wp-block-button is-style-outline\"><a class=\"wp-block-button__link has-text-color has-very-dark-gray-color no-border-radius\">" . esc_html__( 'Button Two', 'my-plugin' ) . "</a></div>\n<!-- /wp:button --></div>\n<!-- /wp:buttons -->",
)
);
```

#### unregister_pattern

`unregister_pattern` allows unregistering a pattern previously registered on the server using `register_pattern`.

The function's argument is the registered name of the pattern.

The following code sample unregisters the style named 'my-plugin/my-awesome-pattern':

```php
unregister_pattern( 'my-plugin/my-awesome-pattern' );
```
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,19 @@ _Returns_

- `boolean`: Whether an ancestor of the block is in multi-selection set.

<a name="isBlockHighlighted" href="#isBlockHighlighted">#</a> **isBlockHighlighted**

Returns true if the current highlighted block matches the block clientId.

_Parameters_

- _state_ `Object`: Global application state.
- _clientId_ `string`: The block to check.

_Returns_

- `boolean`: Whether the block is currently highlighted.

<a name="isBlockInsertionPointVisible" href="#isBlockInsertionPointVisible">#</a> **isBlockInsertionPointVisible**

Returns true if we should show the block insertion point.
Expand Down Expand Up @@ -1296,6 +1309,15 @@ _Returns_

- `Object`: Action object.

<a name="toggleBlockHighlight" href="#toggleBlockHighlight">#</a> **toggleBlockHighlight**

Returns an action object that toggles the highlighted block state.

_Parameters_

- _clientId_ `string`: The block's clientId.
- _isHighlighted_ `boolean`: The highlight state.

<a name="toggleBlockMode" href="#toggleBlockMode">#</a> **toggleBlockMode**

Returns an action object used to toggle the block editing mode between
Expand Down
6 changes: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@
"markdown_source": "../docs/designers-developers/developers/block-api/block-templates.md",
"parent": "block-api"
},
{
"title": "Patterns (Experimental)",
"slug": "block-patterns",
"markdown_source": "../docs/designers-developers/developers/block-api/block-patterns.md",
"parent": "block-api"
},
{
"title": "Annotations",
"slug": "block-annotations",
Expand Down
1 change: 1 addition & 0 deletions docs/toc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
{ "docs/designers-developers/developers/block-api/block-attributes.md": [] },
{"docs/designers-developers/developers/block-api/block-deprecation.md": [] },
{ "docs/designers-developers/developers/block-api/block-templates.md": [] },
{ "docs/designers-developers/developers/block-api/block-patterns.md": [] },
{ "docs/designers-developers/developers/block-api/block-annotations.md": [] }
] },
{ "docs/designers-developers/developers/filters/README.md": [
Expand Down
2 changes: 1 addition & 1 deletion gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Gutenberg
* Plugin URI: https://github.com/WordPress/gutenberg
* Description: Printing since 1440. This is the development plugin for the new block editor in core.
* Version: 7.7.1
* Version: 7.8.0-rc.1
* Author: Gutenberg Team
* Text Domain: gutenberg
*
Expand Down
137 changes: 137 additions & 0 deletions lib/class-wp-patterns-registry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php
/**
* Blocks API: WP_Patterns_Registry class
*
* @package Gutenberg
*/

/**
* Class used for interacting with patterns.
*/
final class WP_Patterns_Registry {
/**
* Registered patterns array.
*
* @var array
*/
private $registered_patterns = array();

/**
* Container for the main instance of the class.
*
* @var WP_Patterns_Registry|null
*/
private static $instance = null;

/**
* Registers a pattern.
*
* @param string $pattern_name Pattern name including namespace.
* @param array $pattern_properties Array containing the properties of the pattern: label, content.
* @return boolean True if the pattern was registered with success and false otherwise.
*/
public function register( $pattern_name, $pattern_properties ) {
if ( ! isset( $pattern_name ) || ! is_string( $pattern_name ) ) {
$message = __( 'Pattern name must be a string.', 'gutenberg' );
_doing_it_wrong( __METHOD__, $message, '7.8.0' );
return false;
}

$this->registered_patterns[ $pattern_name ] = $pattern_properties;

return true;
}

/**
* Unregisters a pattern.
*
* @param string $pattern_name Pattern name including namespace.
* @return boolean True if the pattern was unregistered with success and false otherwise.
*/
public function unregister( $pattern_name ) {
if ( ! $this->is_registered( $pattern_name ) ) {
/* translators: 1: Pattern name. */
$message = sprintf( __( 'Pattern "%1$s" not found.', 'gutenberg' ), $pattern_name );
_doing_it_wrong( __METHOD__, $message, '7.8.0' );
return false;
}

unset( $this->registered_patterns[ $pattern_name ] );

return true;
}

/**
* Retrieves an array containing the properties of a registered pattern.
*
* @param string $pattern_name Pattern name including namespace.
* @return array Registered pattern properties.
*/
public function get_registered( $pattern_name ) {
if ( ! $this->is_registered( $pattern_name ) ) {
return null;
}

return $this->registered_patterns[ $pattern_name ];
}

/**
* Retrieves all registered patterns.
*
* @return array Array of arrays containing the registered patterns properties,
* and per style.
*/
public function get_all_registered() {
return array_values( $this->registered_patterns );
}

/**
* Checks if a pattern is registered.
*
* @param string $pattern_name Pattern name including namespace.
* @return bool True if the pattern is registered, false otherwise.
*/
public function is_registered( $pattern_name ) {
return isset( $this->registered_patterns[ $pattern_name ] );
}

/**
* Utility method to retrieve the main instance of the class.
*
* The instance will be created if it does not exist yet.
*
* @since 5.3.0
*
* @return WP_Patterns_Registry The main instance.
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}

return self::$instance;
}
}

/**
* Registers a new pattern.
*
* @param string $pattern_name Pattern name including namespace.
* @param array $pattern_properties Array containing the properties of the pattern.
*
* @return boolean True if the pattern was registered with success and false otherwise.
*/
function register_pattern( $pattern_name, $pattern_properties ) {
return WP_Patterns_Registry::get_instance()->register( $pattern_name, $pattern_properties );
}

/**
* Unregisters a pattern.
*
* @param string $pattern_name Pattern name including namespace.
*
* @return boolean True if the pattern was unregistered with success and false otherwise.
*/
function unregister_pattern( $pattern_name ) {
return WP_Patterns_Registry::get_instance()->unregister( $pattern_name );
}
Loading

0 comments on commit fbe2016

Please sign in to comment.