Skip to content

Commit

Permalink
Merge branch 'master' into rnmobile/try/image-block-link-picker
Browse files Browse the repository at this point in the history
  • Loading branch information
mkevins committed Dec 17, 2020
2 parents 281d46f + 995a112 commit 99d8724
Show file tree
Hide file tree
Showing 167 changed files with 670 additions and 541 deletions.
2 changes: 1 addition & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"plugins": [
"."
],
"themes": [ "WordPress/theme-experiments/twentytwentyone-blocks" ],
"themes": [ "WordPress/theme-experiments/tt1-blocks" ],
"env": {
"tests": {
"mappings": {
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/a11y/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/a11y",
"version": "2.13.0",
"version": "2.14.0",
"description": "Accessibility (a11y) utilities for WordPress.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 2 additions & 0 deletions packages/annotations/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

## 1.24.0 (2020-12-17)

### New Feature

- Added a store definition `store` for the annotations namespace to use with `@wordpress/data` API ([#26655](https://github.com/WordPress/gutenberg/pull/26655)).
Expand Down
2 changes: 1 addition & 1 deletion packages/annotations/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/annotations",
"version": "1.23.0",
"version": "1.24.0",
"description": "Annotate content in the Gutenberg editor.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion packages/api-fetch/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/api-fetch",
"version": "3.20.0",
"version": "3.21.0",
"description": "Utility to make WordPress REST API requests.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion packages/autop/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/autop",
"version": "2.10.0",
"version": "2.11.0",
"description": "WordPress's automatic paragraph functions `autop` and `removep`.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-makepot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/babel-plugin-makepot",
"version": "3.9.0",
"version": "3.10.0",
"description": "WordPress Babel internationalization (i18n) plugin.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 2 additions & 0 deletions packages/babel-preset-default/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

## 4.20.0 (2020-12-17)

### New Features

- The bundled `@babel/core` dependency has been updated from requiring `^7.11.6` to requiring `^7.12.9`. All other Babel plugins were updated to the latest version (see [Highlights](https://babeljs.io/blog/2020/10/15/7.12.0)).
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-preset-default/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/babel-preset-default",
"version": "4.19.0",
"version": "4.20.0",
"description": "Default Babel preset for WordPress development.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion packages/base-styles/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/base-styles",
"version": "3.2.0",
"version": "3.3.0",
"description": "Base SCSS utilities and variables for WordPress.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion packages/blob/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/blob",
"version": "2.11.0",
"version": "2.12.0",
"description": "Blob utilities for WordPress.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 2 additions & 0 deletions packages/block-directory/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

## 1.18.0 (2020-12-17)

### New Feature

- Added a store definition `store` for the block directory namespace to use with `@wordpress/data` API ([#26655](https://github.com/WordPress/gutenberg/pull/26655)).
Expand Down
2 changes: 1 addition & 1 deletion packages/block-directory/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/block-directory",
"version": "1.17.5",
"version": "1.18.0",
"description": "Extend editor with block directory features to search, download and install blocks.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { noop } from 'lodash';
* WordPress dependencies
*/
import { useDispatch } from '@wordpress/data';
import { store as editPostStore } from '@wordpress/edit-post';

/**
* Internal dependencies
Expand All @@ -16,7 +17,7 @@ import { store as blockDirectoryStore } from '../../store';

function DownloadableBlocksList( { items, onHover = noop, onSelect } ) {
const { installBlockType } = useDispatch( blockDirectoryStore );
const { setIsInserterOpened } = useDispatch( 'core/edit-post' );
const { setIsInserterOpened } = useDispatch( editPostStore );

if ( ! items.length ) {
return null;
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

## 5.2.0 (2020-12-17)

### New Feature

- Added a store definition `store` for the block editor namespace to use with `@wordpress/data` API ([#26655](https://github.com/WordPress/gutenberg/pull/26655)).
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/block-editor",
"version": "5.1.4",
"version": "5.2.0",
"description": "Generic block editor.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

## 2.27.0 (2020-12-17)

### Enhancement

- File Block: Copy url button is moved to Block toolbar.
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/block-library",
"version": "2.26.5",
"version": "2.27.0",
"description": "Block library for the WordPress editor.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ function GalleryEdit( props ) {
};
} );

setAttributes( { images: updatedImages, newSizeSlug } );
setAttributes( { images: updatedImages, sizeSlug: newSizeSlug } );
}

useEffect( () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/block-serialization-default-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/block-serialization-default-parser",
"version": "3.8.0",
"version": "3.9.0",
"description": "Block serialization specification parser for WordPress posts.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 2 additions & 0 deletions packages/blocks/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

## 6.25.0 (2020-12-17)

### New Feature

- Added a store definition `store` for the blocks namespace to use with `@wordpress/data` API ([#26655](https://github.com/WordPress/gutenberg/pull/26655)).
Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wordpress/blocks",
"version": "6.24.2",
"version": "6.25.0",
"description": "Block API for WordPress.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
Expand Down
24 changes: 24 additions & 0 deletions packages/blocks/src/api/raw-handling/get-raw-transforms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* External dependencies
*/
import { filter } from 'lodash';

/**
* Internal dependencies
*/
import { getBlockTransforms } from '../factory';

export function getRawTransforms() {
return filter( getBlockTransforms( 'from' ), { type: 'raw' } ).map(
( transform ) => {
return transform.isMatch
? transform
: {
...transform,
isMatch: ( node ) =>
transform.selector &&
node.matches( transform.selector ),
};
}
);
}
47 changes: 47 additions & 0 deletions packages/blocks/src/api/raw-handling/html-to-blocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Internal dependencies
*/
import { createBlock, findTransform } from '../factory';
import { getBlockAttributes } from '../parser';
import { getRawTransforms } from './get-raw-transforms';

/**
* Converts HTML directly to blocks. Looks for a matching transform for each
* top-level tag. The HTML should be filtered to not have any text between
* top-level tags and formatted in a way that blocks can handle the HTML.
*
* @param {string} html HTML to convert.
*
* @return {Array} An array of blocks.
*/
export function htmlToBlocks( html ) {
const doc = document.implementation.createHTMLDocument( '' );

doc.body.innerHTML = html;

return Array.from( doc.body.children ).map( ( node ) => {
const rawTransform = findTransform(
getRawTransforms(),
( { isMatch } ) => isMatch( node )
);

if ( ! rawTransform ) {
return createBlock(
// Should not be hardcoded.
'core/html',
getBlockAttributes( 'core/html', node.outerHTML )
);
}

const { transform, blockName } = rawTransform;

if ( transform ) {
return transform( node );
}

return createBlock(
blockName,
getBlockAttributes( blockName, node.outerHTML )
);
} );
}
72 changes: 5 additions & 67 deletions packages/blocks/src/api/raw-handling/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { flatMap, filter, compact } from 'lodash';
import { flatMap, compact } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -12,8 +12,8 @@ import { getPhrasingContentSchema } from '@wordpress/dom';
/**
* Internal dependencies
*/
import { createBlock, getBlockTransforms, findTransform } from '../factory';
import { getBlockAttributes, parseWithGrammar } from '../parser';
import { htmlToBlocks } from './html-to-blocks';
import { parseWithGrammar } from '../parser';
import normaliseBlocks from './normalise-blocks';
import specialCommentConverter from './special-comment-converter';
import listReducer from './list-reducer';
Expand All @@ -31,63 +31,6 @@ export function deprecatedGetPhrasingContentSchema( context ) {
return getPhrasingContentSchema( context );
}

function getRawTransformations() {
return filter( getBlockTransforms( 'from' ), { type: 'raw' } ).map(
( transform ) => {
return transform.isMatch
? transform
: {
...transform,
isMatch: ( node ) =>
transform.selector &&
node.matches( transform.selector ),
};
}
);
}

/**
* Converts HTML directly to blocks. Looks for a matching transform for each
* top-level tag. The HTML should be filtered to not have any text between
* top-level tags and formatted in a way that blocks can handle the HTML.
*
* @param {Object} $1 Named parameters.
* @param {string} $1.html HTML to convert.
* @param {Array} $1.rawTransforms Transforms that can be used.
*
* @return {Array} An array of blocks.
*/
function htmlToBlocks( { html, rawTransforms } ) {
const doc = document.implementation.createHTMLDocument( '' );

doc.body.innerHTML = html;

return Array.from( doc.body.children ).map( ( node ) => {
const rawTransform = findTransform( rawTransforms, ( { isMatch } ) =>
isMatch( node )
);

if ( ! rawTransform ) {
return createBlock(
// Should not be hardcoded.
'core/html',
getBlockAttributes( 'core/html', node.outerHTML )
);
}

const { transform, blockName } = rawTransform;

if ( transform ) {
return transform( node );
}

return createBlock(
blockName,
getBlockAttributes( blockName, node.outerHTML )
);
} );
}

/**
* Converts an HTML string to known blocks.
*
Expand All @@ -105,12 +48,7 @@ export function rawHandler( { HTML = '' } ) {
// An array of HTML strings and block objects. The blocks replace matched
// shortcodes.
const pieces = shortcodeConverter( HTML );
const rawTransforms = getRawTransformations();
const phrasingContentSchema = getPhrasingContentSchema();
const blockContentSchema = getBlockContentSchema(
rawTransforms,
phrasingContentSchema
);
const blockContentSchema = getBlockContentSchema();

return compact(
flatMap( pieces, ( piece ) => {
Expand All @@ -137,7 +75,7 @@ export function rawHandler( { HTML = '' } ) {
piece = deepFilterHTML( piece, filters, blockContentSchema );
piece = normaliseBlocks( piece );

return htmlToBlocks( { html: piece, rawTransforms } );
return htmlToBlocks( piece );
} )
);
}
Loading

0 comments on commit 99d8724

Please sign in to comment.