Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/WordPress/gutenberg into …
Browse files Browse the repository at this point in the history
…file-block

# Conflicts:
#	utils/mediaupload.js
  • Loading branch information
mirka committed Jun 3, 2018
2 parents f19973b + 23f8945 commit f07f213
Show file tree
Hide file tree
Showing 154 changed files with 4,210 additions and 1,527 deletions.
32 changes: 24 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ module.exports = {
selector: 'ImportDeclaration[source.value=/^@wordpress\\u002F.+\\u002F/]',
message: 'Path access on WordPress dependencies is not allowed.',
},
{
selector: 'ImportDeclaration[source.value=/^blob$/]',
message: 'Use @wordpress/blob as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^blocks$/]',
message: 'Use @wordpress/blocks as import path instead.',
Expand All @@ -46,25 +50,29 @@ module.exports = {
selector: 'ImportDeclaration[source.value=/^components$/]',
message: 'Use @wordpress/components as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^data$/]',
message: 'Use @wordpress/data as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^date$/]',
message: 'Use @wordpress/date as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^editor$/]',
message: 'Use @wordpress/editor as import path instead.',
selector: 'ImportDeclaration[source.value=/^deprecated$/]',
message: 'Use @wordpress/deprecated as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^element$/]',
message: 'Use @wordpress/element as import path instead.',
selector: 'ImportDeclaration[source.value=/^dom$/]',
message: 'Use @wordpress/dom as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^data$/]',
message: 'Use @wordpress/data as import path instead.',
selector: 'ImportDeclaration[source.value=/^editor$/]',
message: 'Use @wordpress/editor as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^dom$/]',
message: 'Use @wordpress/dom as import path instead.',
selector: 'ImportDeclaration[source.value=/^element$/]',
message: 'Use @wordpress/element as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^utils$/]',
Expand Down Expand Up @@ -102,6 +110,14 @@ module.exports = {
selector: 'CallExpression[callee.name=/^(__|_x|_n|_nx)$/] Literal[value=/\\.{3}/]',
message: 'Use ellipsis character (…) in place of three dots',
},
{
selector: 'ImportDeclaration[source.value="lodash"] Identifier.imported[name="memoize"]',
message: 'Use memize instead of Lodash\'s memoize',
},
{
selector: 'CallExpression[callee.object.name="page"][callee.property.name="waitFor"]',
message: 'Prefer page.waitForSelector instead.'
}
],
},
overrides: [
Expand Down
30 changes: 6 additions & 24 deletions bin/packages/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const mkdirp = require( 'mkdirp' );
* Internal dependencies
*/
const getPackages = require( './get-packages' );
const getBabelConfig = require( './get-babel-config' );

/**
* Module Constants
Expand All @@ -31,27 +32,6 @@ const BUILD_DIR = {
};
const DONE = chalk.reset.inverse.bold.green( ' DONE ' );

/**
* Babel Configuration
*/
const babelDefaultConfig = require( '@wordpress/babel-preset-default' );
babelDefaultConfig.babelrc = false;
const presetEnvConfig = babelDefaultConfig.presets[ 0 ][ 1 ];
const babelConfigs = {
main: Object.assign(
{},
babelDefaultConfig,
{ presets: [
[ 'env', Object.assign(
{},
presetEnvConfig,
{ modules: 'commonjs' },
) ],
] }
),
module: babelDefaultConfig,
};

/**
* Get the package name for a specified file
*
Expand Down Expand Up @@ -98,7 +78,7 @@ function buildFile( file, silent ) {
function buildFileFor( file, silent, environment ) {
const buildDir = BUILD_DIR[ environment ];
const destPath = getBuildPath( file, buildDir );
const babelOptions = babelConfigs[ environment ];
const babelOptions = getBabelConfig( environment );

mkdirp.sync( path.dirname( destPath ) );
const transformed = babel.transformFileSync( file, babelOptions ).code;
Expand All @@ -121,8 +101,10 @@ function buildFileFor( file, silent, environment ) {
*/
function buildPackage( packagePath ) {
const srcDir = path.resolve( packagePath, SRC_DIR );
const files = glob.sync( srcDir + '/**/*.js', { nodir: true } )
.filter( ( file ) => ! /\.test\.js/.test( file ) );
const files = glob.sync( `${ srcDir }/**/*.js`, {
ignore: `${ srcDir }/**/test/**/*.js`,
nodir: true,
} );

process.stdout.write( `${ path.basename( packagePath ) }\n` );

Expand Down
55 changes: 55 additions & 0 deletions bin/packages/get-babel-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* External dependencies
*/
const { isArray, map } = require( 'lodash' );
const babelPluginTransformReactJSX = require( 'babel-plugin-transform-react-jsx' );
const babelPresetEnv = require( 'babel-preset-env' );

/**
* WordPress dependencies
*/
const babelDefaultConfig = require( '@wordpress/babel-preset-default' );

const plugins = map( babelDefaultConfig.plugins, ( plugin ) => {
if ( isArray( plugin ) && plugin[ 0 ] === babelPluginTransformReactJSX ) {
// TODO: It should become the default value when all modules are moved to packages.
return [ babelPluginTransformReactJSX, { pragma: 'createElement' } ];
}

return plugin;
} );

const babelConfigs = {
main: Object.assign(
{},
babelDefaultConfig,
{
babelrc: false,
plugins,
presets: map( babelDefaultConfig.presets, ( preset ) => {
if ( isArray( preset ) && preset[ 0 ] === babelPresetEnv ) {
return [ babelPresetEnv, Object.assign(
{},
preset[ 1 ],
{ modules: 'commonjs' }
) ];
}
return preset;
} ),
}
),
module: Object.assign(
{},
babelDefaultConfig,
{
babelrc: false,
plugins,
}
),
};

function getBabelConfig( environment ) {
return babelConfigs[ environment ];
}

module.exports = getBabelConfig;
2 changes: 2 additions & 0 deletions blocks/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export {
getBlockSupport,
hasBlockSupport,
isSharedBlock,
getChildBlockNames,
hasChildBlocks,
} from './registration';
export {
isUnmodifiedDefaultBlock,
Expand Down
2 changes: 1 addition & 1 deletion blocks/api/raw-handling/image-corrector.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { createBlobURL } from '@wordpress/utils';
import { createBlobURL } from '@wordpress/blob';

/**
* Browser dependencies
Expand Down
5 changes: 4 additions & 1 deletion blocks/api/raw-handling/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ export default function rawHandler( { HTML = '', plainText = '', mode = 'AUTO',
}

// Normalize unicode to use composed characters.
// Unsupported in IE.
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize
// See https://core.trac.wordpress.org/ticket/30130
HTML = HTML.normalize();
if ( String.prototype.normalize ) {
HTML = HTML.normalize();
}

// Parse Markdown (and encoded HTML) if:
// * There is a plain text version.
Expand Down
24 changes: 23 additions & 1 deletion blocks/api/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { get, set, isFunction, some } from 'lodash';
*/
import { applyFilters } from '@wordpress/hooks';
import { select, dispatch } from '@wordpress/data';
import { deprecated } from '@wordpress/utils';
import deprecated from '@wordpress/deprecated';

/**
* Defined behavior of a block type.
Expand Down Expand Up @@ -288,3 +288,25 @@ export function hasBlockSupport( nameOrType, feature, defaultSupports ) {
export function isSharedBlock( blockOrType ) {
return blockOrType.name === 'core/block';
}

/**
* Returns an array with the child blocks of a given block.
*
* @param {string} blockName Block type name.
*
* @return {Array} Array of child block names.
*/
export const getChildBlockNames = ( blockName ) => {
return select( 'core/blocks' ).getChildBlockNames( blockName );
};

/**
* Returns a boolean indicating if a block has child blocks or not.
*
* @param {string} blockName Block type name.
*
* @return {boolean} True if a block contains child blocks and false otherwise.
*/
export const hasChildBlocks = ( blockName ) => {
return select( 'core/blocks' ).hasChildBlocks( blockName );
};
35 changes: 35 additions & 0 deletions blocks/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import createSelector from 'rememo';
import { filter, includes, map } from 'lodash';

/**
* Returns all the available block types.
Expand Down Expand Up @@ -61,3 +62,37 @@ export function getDefaultBlockName( state ) {
export function getFallbackBlockName( state ) {
return state.fallbackBlockName;
}

/**
* Returns an array with the child blocks of a given block.
*
* @param {Object} state Data state.
* @param {string} blockName Block type name.
*
* @return {Array} Array of child block names.
*/
export const getChildBlockNames = createSelector(
( state, blockName ) => {
return map(
filter( state.blockTypes, ( blockType ) => {
return includes( blockType.parent, blockName );
} ),
( { name } ) => name
);
},
( state ) => [
state.blockTypes,
]
);

/**
* Returns a boolean indicating if a block has child blocks or not.
*
* @param {Object} state Data state.
* @param {string} blockName Block type name.
*
* @return {boolean} True if a block contains child blocks and false otherwise.
*/
export const hasChildBlocks = ( state, blockName ) => {
return getChildBlockNames( state, blockName ).length > 0;
};
Loading

1 comment on commit f07f213

@nb
Copy link
Member

@nb nb commented on f07f213 Jun 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mirka we usually rebase the development branches off of master instead of merging - this way the history will be a lot cleaner

Please sign in to comment.