Skip to content

Commit

Permalink
Try extracting the block library into a separate module (#6351)
Browse files Browse the repository at this point in the history
* Try extracting the block library into a separate module

* Add a deprecation message

* Blocks: Do not expose default autocompleters

* Fix php unit tests

* Fix dependencies comment
  • Loading branch information
youknowriad authored Apr 25, 2018
1 parent 87db8ce commit eabf682
Show file tree
Hide file tree
Showing 454 changed files with 284 additions and 188 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ module.exports = {
"selector": "ImportDeclaration[source.value=/^core-data$/]",
"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: 'CallExpression[callee.name="deprecated"] Property[key.name="version"][value.value=/' + majorMinorRegExp + '/]',
message: 'Deprecated functions must be removed before releasing this version.',
Expand Down
2 changes: 1 addition & 1 deletion bin/build-plugin-zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ status "Creating archive..."
zip -r gutenberg.zip \
gutenberg.php \
lib/*.php \
blocks/library/*/*.php \
core-blocks/*/*.php \
post-content.js \
$vendor_scripts \
$build_files \
Expand Down
2 changes: 1 addition & 1 deletion bin/get-server-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
require_once dirname( dirname( __FILE__ ) ) . '/lib/client-assets.php';

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

Expand Down
2 changes: 1 addition & 1 deletion blocks/api/raw-handling/test/integration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import path from 'path';
/**
* Internal dependencies
*/
import { registerCoreBlocks } from '../../../../library';
import { registerCoreBlocks } from '../../../../../core-blocks';
import rawHandler from '../../index';
import serialize from '../../../serializer';

Expand Down
3 changes: 1 addition & 2 deletions blocks/hooks/default-autocompleters.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import { addFilter } from '@wordpress/hooks';
*/
import { userAutocompleter } from '../autocompleters';

// Exported for unit test.
export const defaultAutocompleters = [ userAutocompleter ];
const defaultAutocompleters = [ userAutocompleter ];

function setDefaultCompleters( completers ) {
if ( ! completers ) {
Expand Down
5 changes: 4 additions & 1 deletion blocks/hooks/test/default-autocompleters.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import { applyFilters } from '@wordpress/hooks';
/**
* Internal dependencies
*/
import { defaultAutocompleters } from '../default-autocompleters';
import '../default-autocompleters';
import { userAutocompleter } from '../../autocompleters';

describe( 'default-autocompleters', () => {
const defaultAutocompleters = [ userAutocompleter ];

it( 'provides default completers if none are provided', () => {
const result = applyFilters( 'blocks.Autocomplete.completers', null );
/*
Expand Down
5 changes: 4 additions & 1 deletion blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import './hooks';
// Blocks are inferred from the HTML source of a post through a parsing mechanism
// and then stored as objects in state, from which it is then rendered for editing.
export * from './api';
export { registerCoreBlocks } from './library';
export * from './autocompleters';

export { default as editorMediaUpload } from './editor-media-upload';
export { default as AlignmentToolbar } from './alignment-toolbar';
export { default as Autocomplete } from './autocomplete';
export { default as BlockAlignmentToolbar } from './block-alignment-toolbar';
Expand All @@ -22,6 +24,7 @@ export { default as BlockFormatControls } from './block-format-controls';
export { default as BlockEdit } from './block-edit';
export { default as BlockIcon } from './block-icon';
export { default as ColorPalette } from './color-palette';
export { default as ContrastChecker } from './contrast-checker';
export { default as ImagePlaceholder } from './image-placeholder';
export { default as InnerBlocks } from './inner-blocks';
export { default as InspectorControls } from './inspector-controls';
Expand Down
2 changes: 1 addition & 1 deletion blocks/inner-blocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ InnerBlocks

InnerBlocks exports a pair of components which can be used in block implementations to enable nested block content.

Refer to the [implementation of the Columns block](https://github.com/WordPress/gutenberg/tree/master/blocks/library/columns) as an example resource.
Refer to the [implementation of the Columns block](https://github.com/WordPress/gutenberg/tree/master/core-blocks/columns) as an example resource.

## Usage

Expand Down
File renamed without changes.
10 changes: 6 additions & 4 deletions blocks/library/audio/index.js → core-blocks/audio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ import {
Toolbar,
} from '@wordpress/components';
import { Component, Fragment } from '@wordpress/element';
import {
editorMediaUpload,
MediaUpload,
RichText,
BlockControls,
} from '@wordpress/blocks';

/**
* Internal dependencies
*/
import './style.scss';
import './editor.scss';
import editorMediaUpload from '../../editor-media-upload';
import MediaUpload from '../../media-upload';
import RichText from '../../rich-text';
import BlockControls from '../../block-controls';

export const name = 'core/audio';

Expand Down
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 'blocks/test/helpers';
import { blockEditRender } from '../../test/helpers';

describe( 'core/audio', () => {
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 @@ -10,11 +10,11 @@ import { Component, Fragment, compose } from '@wordpress/element';
import { Placeholder, Spinner, Disabled } from '@wordpress/components';
import { withSelect, withDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { BlockEdit } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import BlockEdit from '../../block-edit';
import SharedBlockEditPanel from './edit-panel';
import SharedBlockIndicator from './indicator';

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 9 additions & 7 deletions blocks/library/button/index.js → core-blocks/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ import {
ToggleControl,
withFallbackStyles,
} from '@wordpress/components';
import {
UrlInput,
RichText,
BlockControls,
BlockAlignmentToolbar,
ColorPalette,
ContrastChecker,
InspectorControls,
} from '@wordpress/blocks';

/**
* Internal dependencies
*/
import './editor.scss';
import './style.scss';
import RichText from '../../rich-text';
import UrlInput from '../../url-input';
import BlockControls from '../../block-controls';
import BlockAlignmentToolbar from '../../block-alignment-toolbar';
import ColorPalette from '../../color-palette';
import ContrastChecker from '../../contrast-checker';
import InspectorControls from '../../inspector-controls';

const { getComputedStyle } = window;

Expand Down
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 'blocks/test/helpers';
import { blockEditRender } from '../../test/helpers';

describe( 'core/button', () => {
test( 'block edit matches snapshot', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import { PanelBody, Placeholder, Spinner, ToggleControl } from '@wordpress/compo
import { withSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { times, unescape } from 'lodash';
import {
InspectorControls,
BlockControls,
BlockAlignmentToolbar,
} from '@wordpress/blocks';

/**
* Internal dependencies
*/
import './editor.scss';
import './style.scss';
import InspectorControls from '../../inspector-controls';
import BlockControls from '../../block-controls';
import BlockAlignmentToolbar from '../../block-alignment-toolbar';

class CategoriesBlock extends Component {
constructor() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions blocks/library/code/index.js → core-blocks/code/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import {
createBlock,
PlainText,
} from '@wordpress/blocks';

/**
* Internal dependencies
*/
import './editor.scss';
import PlainText from '../../plain-text';
import { createBlock } from '../../api';

export const name = 'core/code';

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 'blocks/test/helpers';
import { blockEditRender } from '../../test/helpers';

describe( 'core/code', () => {
test( 'block edit matches snapshot', () => {
Expand Down
File renamed without changes.
10 changes: 6 additions & 4 deletions blocks/library/columns/index.js → core-blocks/columns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ import memoize from 'memize';
import { __, sprintf } from '@wordpress/i18n';
import { PanelBody, RangeControl } from '@wordpress/components';
import { Fragment } from '@wordpress/element';
import {
BlockControls,
InspectorControls,
BlockAlignmentToolbar,
InnerBlocks,
} from '@wordpress/blocks';

/**
* Internal dependencies
*/
import './style.scss';
import './editor.scss';
import InspectorControls from '../../inspector-controls';
import BlockControls from '../../block-controls';
import BlockAlignmentToolbar from '../../block-alignment-toolbar';
import InnerBlocks from '../../inner-blocks';

/**
* Returns the layouts configuration for a given number of columns.
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ import { IconButton, PanelBody, RangeControl, ToggleControl, Toolbar } from '@wo
import { Fragment } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import classnames from 'classnames';
import {
createBlock,
BlockControls,
InspectorControls,
BlockAlignmentToolbar,
ImagePlaceholder,
MediaUpload,
AlignmentToolbar,
RichText,
} from '@wordpress/blocks';

/**
* Internal dependencies
*/
import './editor.scss';
import './style.scss';
import { createBlock } from '../../api';
import RichText from '../../rich-text';
import AlignmentToolbar from '../../alignment-toolbar';
import MediaUpload from '../../media-upload';
import ImagePlaceholder from '../../image-placeholder';
import BlockControls from '../../block-controls';
import BlockAlignmentToolbar from '../../block-alignment-toolbar';
import InspectorControls from '../../inspector-controls';

const validAlignments = [ 'left', 'center', 'right', 'wide', 'full' ];

Expand Down
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 'blocks/test/helpers';
import { blockEditRender } from '../../test/helpers';

describe( 'core/cover-image', () => {
test( 'block edit matches snapshot', () => {
Expand Down
File renamed without changes.
10 changes: 6 additions & 4 deletions blocks/library/embed/index.js → core-blocks/embed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ import { __, sprintf } from '@wordpress/i18n';
import { Component, Fragment, renderToString } from '@wordpress/element';
import { Button, Placeholder, Spinner, SandBox } from '@wordpress/components';
import classnames from 'classnames';
import {
createBlock,
BlockControls,
BlockAlignmentToolbar,
RichText,
} from '@wordpress/blocks';

/**
* Internal dependencies
*/
import './style.scss';
import './editor.scss';
import { createBlock } from '../../api';
import RichText from '../../rich-text';
import BlockControls from '../../block-controls';
import BlockAlignmentToolbar from '../../block-alignment-toolbar';

// These embeds do not work in sandboxes
const HOSTS_NO_PREVIEWS = [ 'facebook.com' ];
Expand Down
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 'blocks/test/helpers';
import { blockEditRender } from '../../test/helpers';

describe( 'core/embed', () => {
test( 'block edit matches snapshot', () => {
Expand Down
File renamed without changes.
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 'blocks/test/helpers';
import { blockEditRender } from '../../test/helpers';

describe( 'core/freeform', () => {
test( 'block edit matches snapshot', () => {
Expand Down
14 changes: 8 additions & 6 deletions blocks/library/gallery/block.js → core-blocks/gallery/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ import {
ToggleControl,
Toolbar,
} from '@wordpress/components';
import {
editorMediaUpload,
BlockControls,
BlockAlignmentToolbar,
MediaUpload,
ImagePlaceholder,
InspectorControls,
} from '@wordpress/blocks';

/**
* Internal dependencies
*/
import editorMediaUpload from '../../editor-media-upload';
import MediaUpload from '../../media-upload';
import ImagePlaceholder from '../../image-placeholder';
import InspectorControls from '../../inspector-controls';
import BlockControls from '../../block-controls';
import BlockAlignmentToolbar from '../../block-alignment-toolbar';
import GalleryImage from './gallery-image';

const MAX_COLUMNS = 8;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import { IconButton, Spinner } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { keycodes } from '@wordpress/utils';
import { withSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import RichText from '../../rich-text';
import { RichText } from '@wordpress/blocks';

/**
* Module constants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import { filter, every } from 'lodash';
*/
import { __ } from '@wordpress/i18n';
import { mediaUpload } from '@wordpress/utils';
import {
createBlock,
RichText,
} from '@wordpress/blocks';

/**
* Internal dependencies
*/
import './editor.scss';
import './style.scss';
import { createBlock } from '../../api';
import RichText from '../../rich-text';
import { default as GalleryBlock, defaultColumnsNumber } from './block';

const blockAttributes = {
Expand Down
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 'blocks/test/helpers';
import { blockEditRender } from '../../test/helpers';

describe( 'core/gallery', () => {
test( 'block edit matches snapshot', () => {
Expand Down
File renamed without changes.
Loading

0 comments on commit eabf682

Please sign in to comment.