Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract Core Blocks to the npm packages folder #8287

Merged
merged 13 commits into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ module.exports = {
"message": "Use @wordpress/core-data as import path instead."
},
{
"selector": "ImportDeclaration[source.value=/^core-blocks$/]",
"message": "Use @wordpress/core-blocks as import path instead."
"selector": "ImportDeclaration[source.value=/^block-library$/]",
"message": "Use @wordpress/block-library as import path instead."
},
{
selector: 'CallExpression[callee.name="deprecated"] Property[key.name="version"][value.value=/' + majorMinorRegExp + '/]',
Expand Down
3 changes: 2 additions & 1 deletion bin/build-plugin-zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ status "Creating archive... 🎁"
zip -r gutenberg.zip \
gutenberg.php \
lib/*.php \
core-blocks/*/*.php \
block-library/*/*.php \
packages/block-library/src/*/*.php \
post-content.php \
$vendor_scripts \
$build_files \
Expand Down
5 changes: 4 additions & 1 deletion bin/get-server-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
require_once dirname( dirname( __FILE__ ) ) . '/lib/client-assets.php';

// Register server-side code for individual blocks.
foreach ( glob( dirname( dirname( __FILE__ ) ) . '/core-blocks/*/index.php' ) as $block_logic ) {
foreach ( glob( dirname( dirname( __FILE__ ) ) . '/block-library/*/index.php' ) as $block_logic ) {
require_once $block_logic;
}
foreach ( glob( dirname( dirname( __FILE__ ) ) . '/packages/block-library/src/*/index.php' ) as $block_logic ) {
require_once $block_logic;
}

Expand Down
17 changes: 9 additions & 8 deletions bin/packages/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,16 @@ function buildJsFile( file, silent ) {
* @param {string} packagePath The path to the package.
*/
function buildPackageScss( packagePath ) {
const styleFile = path.resolve( packagePath, SRC_DIR, 'style.scss' );
const srcDir = path.resolve( packagePath, SRC_DIR );
const scssFiles = glob.sync( `${ srcDir }/*.scss` );

// Return early if the package has no root style file.
if ( ! fs.existsSync( styleFile ) ) {
return;
}
// Build scss files individually.
scssFiles.forEach( buildScssFile );
}

const outputFile = path.resolve( packagePath, BUILD_DIR.style, 'style.css' );
const outputFileRTL = path.resolve( packagePath, BUILD_DIR.style, 'style-rtl.css' );
function buildScssFile( styleFile ) {
const outputFile = getBuildPath( styleFile.replace( '.scss', '.css' ), BUILD_DIR.style );
const outputFileRTL = getBuildPath( styleFile.replace( '.scss', '-rtl.css' ), BUILD_DIR.style );
mkdirp.sync( path.dirname( outputFile ) );
const builtSass = sass.renderSync( {
file: styleFile,
Expand Down Expand Up @@ -203,7 +204,7 @@ function buildPackage( packagePath ) {
// Build js files individually.
jsFiles.forEach( ( file ) => buildJsFile( file, true ) );

// Build entire package scss.
// Build package CSS files
buildPackageScss( packagePath );

process.stdout.write( `${ DONE }\n` );
Expand Down
1 change: 1 addition & 0 deletions block-library/editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "../packages/block-library/src/editor.scss";
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export default class FreeformEdit extends Component {
<div
key="editor"
id={ `editor-${ clientId }` }
className="wp-block-freeform core-blocks-rich-text__tinymce"
className="wp-block-freeform block-library-rich-text__tinymce"
/>,
];
/* eslint-enable jsx-a11y/no-static-element-interactions */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.wp-block-freeform.core-blocks-rich-text__tinymce {
.wp-block-freeform.block-library-rich-text__tinymce {
overflow: hidden;

p,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Array [
id="toolbar-undefined"
/>,
<div
class="wp-block-freeform core-blocks-rich-text__tinymce"
class="wp-block-freeform block-library-rich-text__tinymce"
id="editor-undefined"
/>,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Internal dependencies
*/
import { name, settings } from '../';
import { blockEditRender } from '../../test/helpers';
import { blockEditRender } from '../../../packages/block-library/src/test/helpers';

describe( 'core/freeform', () => {
test( 'block edit matches snapshot', () => {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Internal dependencies
*/
import { name, settings } from '../';
import { blockEditRender } from '../../test/helpers';
import { blockEditRender } from '../../../packages/block-library/src/test/helpers';

describe( 'core/html', () => {
test( 'block edit matches snapshot', () => {
Expand Down
101 changes: 101 additions & 0 deletions block-library/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* WordPress dependencies
*/
import {
registerBlockType,
setDefaultBlockName,
setUnknownTypeHandlerName,
} from '@wordpress/blocks';

/**
* Internal dependencies
*/
import './style.scss';
import './editor.scss';
import './theme.scss';
import * as paragraph from '../packages/block-library/src/paragraph';
import * as image from '../packages/block-library/src/image';
import * as heading from '../packages/block-library/src/heading';
import * as quote from '../packages/block-library/src/quote';
import * as gallery from '../packages/block-library/src/gallery';
import * as archives from '../packages/block-library/src/archives';
import * as audio from '../packages/block-library/src/audio';
import * as button from '../packages/block-library/src/button';
import * as categories from '../packages/block-library/src/categories';
import * as code from '../packages/block-library/src/code';
import * as columns from '../packages/block-library/src/columns';
import * as column from '../packages/block-library/src/columns/column';
import * as coverImage from '../packages/block-library/src/cover-image';
import * as embed from '../packages/block-library/src/embed';
import * as file from '../packages/block-library/src/file';
import * as latestComments from '../packages/block-library/src/latest-comments';
import * as latestPosts from '../packages/block-library/src/latest-posts';
import * as list from '../packages/block-library/src/list';
import * as more from '../packages/block-library/src/more';
import * as nextpage from '../packages/block-library/src/nextpage';
import * as preformatted from '../packages/block-library/src/preformatted';
import * as pullquote from '../packages/block-library/src/pullquote';
import * as reusableBlock from '../packages/block-library/src/block';
import * as separator from '../packages/block-library/src/separator';
import * as shortcode from '../packages/block-library/src/shortcode';
import * as spacer from '../packages/block-library/src/spacer';
import * as subhead from '../packages/block-library/src/subhead';
import * as table from '../packages/block-library/src/table';
import * as textColumns from '../packages/block-library/src/text-columns';
import * as verse from '../packages/block-library/src/verse';
import * as video from '../packages/block-library/src/video';

// The freeform block can't be moved to the "npm" packages folder because it requires the wp.oldEditor global.
import * as freeform from './freeform';

// The HTML block can't be moved to the "npm" packages folder because it requires the CodeEditor component.
import * as html from './html';

export const registerCoreBlocks = () => {
[
// Common blocks are grouped at the top to prioritize their display
// in various contexts — like the inserter and auto-complete components.
paragraph,
image,
heading,
gallery,
list,
quote,

// Register all remaining core blocks.
shortcode,
archives,
audio,
button,
categories,
code,
columns,
column,
coverImage,
embed,
...embed.common,
...embed.others,
file,
freeform,
html,
latestComments,
latestPosts,
more,
nextpage,
preformatted,
pullquote,
separator,
reusableBlock,
spacer,
subhead,
table,
textColumns,
verse,
video,
].forEach( ( { name, settings } ) => {
registerBlockType( name, settings );
} );

setDefaultBlockName( paragraph.name );
setUnknownTypeHandlerName( freeform.name );
};
4 changes: 4 additions & 0 deletions block-library/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Internal dependencies
*/
import '../packages/block-library/src';
1 change: 1 addition & 0 deletions block-library/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "../packages/block-library/src/style.scss";
1 change: 1 addition & 0 deletions block-library/theme.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "../packages/block-library/src/theme.scss";
95 changes: 7 additions & 88 deletions core-blocks/index.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,14 @@
/**
* WordPress dependencies
*/
import {
registerBlockType,
setDefaultBlockName,
setUnknownTypeHandlerName,
} from '@wordpress/blocks';
import { registerCoreBlocks as registerBlockLibrary } from '@wordpress/block-library';
import deprecated from '@wordpress/deprecated';

/**
* Internal dependencies
*/
import './style.scss';
import * as paragraph from './paragraph';
import * as image from './image';
import * as heading from './heading';
import * as quote from './quote';
import * as gallery from './gallery';
import * as archives from './archives';
import * as audio from './audio';
import * as button from './button';
import * as categories from './categories';
import * as code from './code';
import * as columns from './columns';
import * as column from './columns/column';
import * as coverImage from './cover-image';
import * as embed from './embed';
import * as file from './file';
import * as freeform from './freeform';
import * as html from './html';
import * as latestComments from './latest-comments';
import * as latestPosts from './latest-posts';
import * as list from './list';
import * as more from './more';
import * as nextpage from './nextpage';
import * as preformatted from './preformatted';
import * as pullquote from './pullquote';
import * as reusableBlock from './block';
import * as separator from './separator';
import * as shortcode from './shortcode';
import * as spacer from './spacer';
import * as subhead from './subhead';
import * as table from './table';
import * as textColumns from './text-columns';
import * as verse from './verse';
import * as video from './video';

export const registerCoreBlocks = () => {
[
// Common blocks are grouped at the top to prioritize their display
// in various contexts — like the inserter and auto-complete components.
paragraph,
image,
heading,
gallery,
list,
quote,

// Register all remaining core blocks.
shortcode,
archives,
audio,
button,
categories,
code,
columns,
column,
coverImage,
embed,
...embed.common,
...embed.others,
file,
freeform,
html,
latestComments,
latestPosts,
more,
nextpage,
preformatted,
pullquote,
separator,
reusableBlock,
spacer,
subhead,
table,
textColumns,
verse,
video,
].forEach( ( { name, settings } ) => {
registerBlockType( name, settings );
export const registerCoreBlocks = ( ...args ) => {
deprecated( 'wp.coreBlocks.registerCoreBlocks', {
version: 3.8,
alternative: 'wp.blockLibrary.registerCoreBlocks',
} );

setDefaultBlockName( paragraph.name );
setUnknownTypeHandlerName( freeform.name );
return registerBlockLibrary( ...args );
};
6 changes: 0 additions & 6 deletions core-blocks/list/editor.scss

This file was deleted.

2 changes: 1 addition & 1 deletion docs/blocks/generate-blocks-with-wp-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ It turns out that writing the simplest possible block which contains only static
- [zgordon/gutenberg-course](https://github.com/zgordon/gutenberg-course) - a repository for Zac Gordon's Gutenberg Development Course
- [ahmadawais/create-guten-block](https://github.com/ahmadawais/create-guten-block) - A zero-configuration developer toolkit for building WordPress Gutenberg block plugins

It might be also a good idea to browse the folder with [all core blocks](https://github.com/WordPress/gutenberg/tree/master/core-blocks) to see how they are implemented.
It might be also a good idea to browse the folder with [all core blocks](https://github.com/WordPress/gutenberg/tree/master/packages/block-library/src) to see how they are implemented.
Copy link
Member

Choose a reason for hiding this comment

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

While we're updating the name, calling these "built-in" or "default" blocks might be nicer than "core blocks". Thoughts?


## WP-CLI

Expand Down
25 changes: 25 additions & 0 deletions docs/data/data-core-edit-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ Returns true if the editor sidebar panel is open, or false otherwise.

Whether the sidebar panel is open.

### isModalActive

Returns true if a modal is active, or false otherwise.

*Parameters*

* state: Global application state.
* modalName: A string that uniquely identifies the modal.

*Returns*

Whether the modal is active.

### isFeatureActive

Returns whether the given feature is enabled or not.
Expand Down Expand Up @@ -173,6 +186,18 @@ Returns an action object used in signalling that the user opened an editor sideb

Returns an action object signalling that the user closed the sidebar.

### openModal

Returns an action object used in signalling that the user opened an editor sidebar.

*Parameters*

* name: A string that uniquely identifies the modal.

### closeModal

Returns an action object signalling that the user closed the sidebar.

### openPublishSidebar

Returns an action object used in signalling that the user opened the publish
Expand Down
5 changes: 2 additions & 3 deletions docs/data/data-core-editor.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# **core/editor**: The Editor’s Data

## Selectors
## Selectors
Copy link
Member

Choose a reason for hiding this comment

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

Trailing whitespace! 😱

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is generated, we might have an issue in the build tool


### hasEditorUndo

Expand Down Expand Up @@ -1422,5 +1422,4 @@ Returns an action object used in signalling that the editor settings have been u

*Parameters*

* settings: Updated settings

* settings: Updated settings
Loading