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

Latest Posts block: remove columns-x class for list view #4017

Closed
wants to merge 134 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
b5d73e5
Add editor heading for screenreaders
Dec 12, 2017
e682f1e
Make post title contextual and translatable
Dec 12, 2017
98e560a
Remove NVDA hack.
Dec 12, 2017
683ecaf
Try block advanced settings dynamic menu item.
afercia Dec 13, 2017
12998a3
Fix blocks when useOnce is true
Rahmon Dec 14, 2017
fa71b71
Add speak messages.
afercia Dec 14, 2017
a329322
Add full coverage for REQUEST_POST_UPDATE_SUCCESS effect.
BE-Webdesign Dec 5, 2017
e6796f9
Updating effects to make use of matchers instead of explicit matching.
BE-Webdesign Dec 14, 2017
2a3e4a0
Block API: Refactor supportHTML as supports property
aduth Dec 14, 2017
a7dc698
Show column class only for grid
Soean Dec 14, 2017
2ec735c
Remove columns class for lists also in server-side rendering
Soean Dec 14, 2017
d82808e
Changes buttonProps to html attributes
Soean Dec 15, 2017
8a511f5
Fix when block hasn't been used yet in the post
Rahmon Dec 15, 2017
861c054
Try fainter disabled state
Dec 15, 2017
fb96084
Tests: Refactor tests for REQUEST_POST_UPDATE_SUCCESS effects
gziolo Dec 15, 2017
7f346ea
Merge pull request #3820 from WordPress/add/test/editor/effects/reque…
gziolo Dec 15, 2017
0f35fc6
Extensibility: Defer applying filters for component until it is about…
gziolo Dec 15, 2017
71a218f
Merge pull request #4033 from WordPress/try/fainter-disabled-state
Dec 15, 2017
5d81a0a
Merge pull request #3988 from Rahmon/fix/3968
aduth Dec 15, 2017
6fba36d
Components: Add withState higher-order component
aduth Dec 14, 2017
925acf9
Blocks: Port HTML block to use withState
aduth Dec 14, 2017
7cb404d
Merge pull request #4016 from WordPress/add/with-state
aduth Dec 15, 2017
bbf06e2
Merge pull request #4014 from WordPress/update/supports-html
aduth Dec 15, 2017
7fdf923
Minor refactoring: change from "find" to "some" function (#4052)
Rahmon Dec 16, 2017
3fc4d58
Merge pull request #3982 from WordPress/try/block-settings-menu-item-…
afercia Dec 18, 2017
7c917c9
Meta Boxes: Show the "advanced" metaboxes location
youknowriad Dec 13, 2017
5c33f6f
Framework: Introduce the data module (#3832)
youknowriad Dec 18, 2017
f718d8e
Blocks: Move logic for generating class name to BlockEdit component
gziolo Dec 14, 2017
1342736
Blocks: Add test for generated class name with BlockEdit
gziolo Dec 14, 2017
6e6356a
Editor: Move generatedClassName logic out of BlockListBlock
gziolo Dec 15, 2017
f2bcebb
Blocks: Make sure Reusable Blocks get class name apllied properly
gziolo Dec 18, 2017
3650811
Editor: Wrap invalid block preview with key
gziolo Dec 18, 2017
227a93f
Merge pull request #4009 from WordPress/update/generated-class-name-e…
gziolo Dec 18, 2017
1b35aac
Merge pull request #4029 from WordPress/update/block-audio-button-attr
Soean Dec 18, 2017
d9e1777
Implemented isInlineForTag mechanism
jorgefilipecosta Dec 12, 2017
ba6eb23
Added tag groups for headings and lists to the inlineWhitelistTagGrou…
jorgefilipecosta Dec 18, 2017
f181a08
Added test cases to isInlineContent to take into account the new isIn…
jorgefilipecosta Dec 18, 2017
6a287a4
Extensibility: Respect the 'enter_title_here' hook
youknowriad Dec 18, 2017
1effc72
Update Jest to v22.0.1
ntwb Dec 19, 2017
fcf70aa
Update Jest snapshots
ntwb Dec 19, 2017
af0773f
Update babel-jest to v22.0.1
ntwb Dec 19, 2017
ec3d7d5
Update eslint-plugin-jest to v21.5.0
ntwb Dec 19, 2017
d8db53a
Merge pull request #4073 from WordPress/update/jest
gziolo Dec 19, 2017
c43b3fa
Added querystringify npm dependency.
jorgefilipecosta Dec 18, 2017
c4c8e3d
Replaced getLatestPosts usage (wp.api.collections.Posts wrapper) with…
jorgefilipecosta Dec 15, 2017
e133c87
Recreate `package-lock.json` using Node.js 8.9.3 & npm 5.6.0 (#4075)
ntwb Dec 19, 2017
0257138
Move selectors and actions files to the store folder
youknowriad Dec 19, 2017
630fbde
Moved Categories Block edit to an external file.
jorgefilipecosta Dec 18, 2017
c1f7b19
Replaced getCategories usage (wp.api.collections.Categories wrapper) …
jorgefilipecosta Dec 19, 2017
64ac510
Add dynamic block documentation (#4067)
atimmer Dec 19, 2017
8f30966
3 column inserter
karmatosed Dec 19, 2017
1df0d52
Try improving mobile controls
Dec 20, 2017
ed74c1e
Blocks: Add the missing alignments classNames to the Cover Image Bloc…
youknowriad Dec 18, 2017
fb72e7f
Improve paragraph block description.
Dec 20, 2017
0645702
Rename "Classic Text" to "Classic".
Dec 20, 2017
34a13d3
Data Module: Restrict the state access to the module registering the …
youknowriad Dec 18, 2017
6a8b8f4
Widens the inserter
karmatosed Dec 20, 2017
5981cca
Left aligns the title
karmatosed Dec 20, 2017
14a046a
Move title to center again
karmatosed Dec 20, 2017
b0c9e6a
Remove references to obsolete class.
Dec 20, 2017
6b51d23
Block Mobile Toolbar: Extract as a separate component
youknowriad Dec 20, 2017
7c1cfae
Merge branch 'try/improved-mobile-tools' of github.com:WordPress/gute…
youknowriad Dec 20, 2017
6378974
Factory: Fix block creation with falsey default
aduth Dec 19, 2017
76ddebf
Merge pull request #4103 from WordPress/update/improve-paragraph-desc…
jasmussen Dec 20, 2017
c89e226
Merge pull request #4101 from WordPress/try/improved-mobile-tools
jasmussen Dec 20, 2017
e8ff9ec
Little polish to the top menu and inserter.
Dec 19, 2017
353ee9c
Make mobile scroll "normally".
Dec 19, 2017
d8a58ac
Fix regression with "fixed to block" toolbar
Dec 19, 2017
76f1527
Prevent Safari from zooming in when opening inserter
Dec 19, 2017
9721009
Define setAttributes before using it.
ryo-utsunomiya Dec 20, 2017
e5bafaa
Removed duplicate of buildTermsTree in HierarchicalTermSelector. (#4111)
jorgefilipecosta Dec 20, 2017
a510f3c
Merge pull request #4104 from WordPress/update/rename-classic-text
Dec 20, 2017
5b85f85
Merge pull request #4095 from WordPress/try/three-column-inserter
Dec 20, 2017
db193b6
Fix the radio control checked attribute
stevehenty Dec 1, 2017
293d90e
Polish permalink toolbar on mobile
Dec 21, 2017
af913fa
Merge pull request #4081 from WordPress/try/mobile-polish
jasmussen Dec 21, 2017
9c6143b
Use Post Type capabilities instead of All capabilities.
imath Dec 21, 2017
d980bdb
Added drag&drop upload to cover image. (#4061)
jorgefilipecosta Dec 21, 2017
5aabd70
Accessibility: Fix the accessibility of the menu items in the ellipsi…
youknowriad Dec 21, 2017
2bc1329
Refactor Reusable Blocks controller to use WP_REST_Posts_Controller
noisysocks Dec 15, 2017
ae17538
Add aria-label to code and HTML block textarea elements. #2027
tfrommen Oct 4, 2017
3220ce8
Update aria-label, and remove (superfluous) placeholder. #2027
tfrommen Oct 6, 2017
8cc8cbb
Code Block: Restore the placeholder
youknowriad Dec 22, 2017
c97ebf8
Allow for multi line text in button block
jahvi Aug 22, 2017
b614f03
Remove unnecessary line.
Dec 22, 2017
5c92e3d
Components: Allow explicitely overriding the ColorPalette colors per …
youknowriad Dec 22, 2017
b9d8f85
Heading <-> Cover Image transforms
mcsf Dec 21, 2017
99f5f1d
Merge pull request #4129 from WordPress/add/heading-cover-image-trans…
mcsf Dec 22, 2017
0c4457c
Remove unused variable from the_gutenberg_project function
gziolo Dec 22, 2017
f023754
Merge pull request #3937 from WordPress/try/edit-heading-round-2
gziolo Dec 22, 2017
2ee8fe4
Gallery Block: Drag and drop multiple images create a gallery block
youknowriad Dec 22, 2017
e109ff7
DropZone: Tweak its styling
youknowriad Dec 22, 2017
6f25976
Chrome: Replace the publish dropdown by a sidebar panel
youknowriad Dec 21, 2017
98414fe
Chrome: Allow multiple sidebars
youknowriad Dec 21, 2017
95457a6
Chrome: Slide in animation for the publish sidebar
youknowriad Dec 21, 2017
34d088d
Chrome: fix hasOpenSidebar selector
youknowriad Dec 21, 2017
21e5b26
Chrome: Fix animation speed of the publish sidebar
youknowriad Dec 21, 2017
2f27d54
Add tests for Editable.adaptFormatter()
BE-Webdesign Dec 9, 2017
204c6b8
Merge pull request #3894 from WordPress/add/test/editable/adapt-forma…
BE-Webdesign Dec 23, 2017
b393dbe
Add tests for Editable.getSettings()
BE-Webdesign Dec 9, 2017
06317d7
Merge pull request #3892 from WordPress/add/test/blocks/editable-2
BE-Webdesign Dec 23, 2017
22e5bbf
Add tests for ColorPalette component.
BE-Webdesign Dec 9, 2017
a99733d
Fix typo in comment. (#4154)
getsource Dec 23, 2017
79a74be
Merge pull request #3887 from WordPress/add/test/blocks/color-palette
BE-Webdesign Dec 23, 2017
e624d34
Try: Add toggle editor mode shortcut (#3755)
vladanost Dec 25, 2017
6a9ea01
Chrome: Hide the Excerpt Panel if the CPT doesn't support it
youknowriad Dec 25, 2017
ecee09e
Handle copy for single block selection
ellatrix Dec 25, 2017
c3be1b6
Meta Boxes: When the metaboxes are saving ensure the overlay covers t…
youknowriad Dec 26, 2017
0aaffae
Add 'No saved blocks' message to Inserter
noisysocks Dec 27, 2017
ebf841f
Taxonomiees: Improve Tags/Categories response size by limiting the re…
youknowriad Dec 26, 2017
daebcc3
Add text to meetup links
laras126 Dec 26, 2017
c5a8db5
Organization and intitial population of articles page
laras126 Dec 26, 2017
34c81b4
Latest posts: Only request required category fields. (#4179)
jorgefilipecosta Dec 27, 2017
9646747
Chrome: Hide The Taxonomies Panel if no taxonomy is available for the…
youknowriad Dec 26, 2017
45e9094
Blocks: Show the insertion point when the inserter is opened
youknowriad Dec 25, 2017
825eef6
Implemented editor-left&editor-right mixins.
jorgefilipecosta Dec 22, 2017
b24170a
Made notices always visible; Added sticky behaviour in notices for wi…
jorgefilipecosta Dec 21, 2017
e63deab
Used editor-left mixin for .editor-header styles.
jorgefilipecosta Dec 22, 2017
e3e849f
Refactor `PostSchedule` to make calendar/clock available as component…
travislopes Dec 27, 2017
40adaff
Merge pull request #4182 from WordPress/add/no-saved-blocks-message
noisysocks Dec 27, 2017
1ff0f5f
Merge pull request #4137 from WordPress/add/reusable-block-deletion-t…
noisysocks Dec 27, 2017
553ab2c
Blocks: Avoir reusable blocks styling
youknowriad Dec 26, 2017
3a3c3d5
UrlInput: Decode Post Title special chars
youknowriad Dec 26, 2017
003d533
Block API: Adding a description property to the block API
youknowriad Dec 25, 2017
b407ccc
Check if mac when displaying editor mode toggle shortcut (#4194)
vladanost Dec 28, 2017
67b12ea
Fix category in implementation of random image block
Rahmon Dec 28, 2017
5838037
Chrome: Hide the Featured Image Panel if the CPT doesn't support it
youknowriad Dec 25, 2017
beaa749
Chrome: Hide the discussion panel if no support for comments or track…
youknowriad Dec 25, 2017
ddfef35
Chrome: Hide the PostAuthor selector if the CPT doesn't support it
youknowriad Dec 25, 2017
2558f6e
Chrome: User the PostTypeSupportCheck to check Post Formats support
youknowriad Dec 25, 2017
c22bc9d
Chrome: Hide revisions if the CPT doesn't support it
youknowriad Dec 25, 2017
edf17df
Mobile: Enhance the redux mobile enhancer to use the MediaQueries API
youknowriad Dec 26, 2017
0a7d55a
Update node-sass to v4.7.2 (#4200)
ntwb Dec 29, 2017
d9dc680
Rebase
Soean Dec 29, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
"selector": "ImportDeclaration[source.value=/^i18n$/]",
"message": "Use @wordpress/i18n as import path instead."
},
{
"selector": "ImportDeclaration[source.value=/^data$/]",
"message": "Use @wordpress/data as import path instead."
},
{
"selector": "ImportDeclaration[source.value=/^utils$/]",
"message": "Use @wordpress/utils as import path instead."
Expand Down
1 change: 1 addition & 0 deletions bin/build-plugin-zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ zip -r gutenberg.zip \
element/build/*.{js,map} \
hooks/build/*.{js,map} \
i18n/build/*.{js,map} \
data/build/*.{js,map} \
utils/build/*.{js,map} \
blocks/build/*.css \
components/build/*.css \
Expand Down
2 changes: 1 addition & 1 deletion blocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ add_action( 'enqueue_block_editor_assets', 'random_image_enqueue_block_editor_as

icon: 'format-image',

category: 'media',
category: 'common',

attributes: {
category: {
Expand Down
4 changes: 2 additions & 2 deletions blocks/api/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function createBlock( name, blockAttributes = {} ) {
const value = blockAttributes[ key ];
if ( undefined !== value ) {
result[ key ] = value;
} else if ( source.default ) {
} else if ( source.hasOwnProperty( 'default' ) ) {
result[ key ] = source.default;
}

Expand Down Expand Up @@ -224,7 +224,7 @@ export function createReusableBlock( type, attributes ) {
return {
id: +uniqueId(), // Temorary id replaced when the block is saved server side
isTemporary: true,
name: __( 'Untitled block' ),
title: __( 'Untitled block' ),
type,
attributes,
};
Expand Down
7 changes: 6 additions & 1 deletion blocks/api/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
export { createBlock, getPossibleBlockTransformations, switchToBlockType, createReusableBlock } from './factory';
export { default as parse, getBlockAttributes } from './parser';
export { default as rawHandler } from './raw-handling';
export { default as serialize, getBlockDefaultClassname, getBlockContent } from './serializer';
export {
default as serialize,
getBlockContent,
getBlockDefaultClassname,
getSaveElement,
} from './serializer';
export { isValidBlock } from './validation';
export { getCategories } from './categories';
export {
Expand Down
7 changes: 4 additions & 3 deletions blocks/api/raw-handling/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ import shortcodeConverter from './shortcode-converter';
* * 'AUTO': Decide based on the content passed.
* * 'INLINE': Always handle as inline content, and return string.
* * 'BLOCKS': Always handle as blocks, and return array of blocks.
* @param {Array} [options.tagName] The tag into which content will be inserted.
* @return {Array|String} A list of blocks or a string, depending on `handlerMode`.
*/
export default function rawHandler( { HTML, plainText = '', mode = 'AUTO' } ) {
export default function rawHandler( { HTML, plainText = '', mode = 'AUTO', tagName } ) {
// First of all, strip any meta tags.
HTML = HTML.replace( /<meta[^>]+>/, '' );

Expand Down Expand Up @@ -65,7 +66,7 @@ export default function rawHandler( { HTML, plainText = '', mode = 'AUTO' } ) {
const hasShortcodes = pieces.length > 1;

// True if mode is auto, no shortcode is included and HTML verifies the isInlineContent condition
const isAutoModeInline = mode === 'AUTO' && isInlineContent( HTML ) && ! hasShortcodes;
const isAutoModeInline = mode === 'AUTO' && isInlineContent( HTML, tagName ) && ! hasShortcodes;

// Return filtered HTML if condition is true
if ( mode === 'INLINE' || isAutoModeInline ) {
Expand All @@ -74,7 +75,7 @@ export default function rawHandler( { HTML, plainText = '', mode = 'AUTO' } ) {
formattingTransformer,
stripAttributes,
commentRemover,
createUnwrapper( ( node ) => ! isInline( node ) ),
createUnwrapper( ( node ) => ! isInline( node, tagName ) ),
] );

// Allows us to ask for this information when we get a report.
Expand Down
10 changes: 5 additions & 5 deletions blocks/api/raw-handling/is-inline-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
*/
import { isInline, isDoubleBR } from './utils';

export default function( HTML ) {
export default function( HTML, tagName ) {
const doc = document.implementation.createHTMLDocument( '' );

doc.body.innerHTML = HTML;

const nodes = Array.from( doc.body.children );

return ! nodes.some( isDoubleBR ) && deepCheck( nodes );
return ! nodes.some( isDoubleBR ) && deepCheck( nodes, tagName );
}

function deepCheck( nodes ) {
function deepCheck( nodes, tagName ) {
return nodes.every( ( node ) => {
return ( 'SPAN' === node.nodeName || isInline( node ) ) &&
deepCheck( Array.from( node.children ) );
return ( 'SPAN' === node.nodeName || isInline( node, tagName ) ) &&
deepCheck( Array.from( node.children ), tagName );
} );
}
4 changes: 4 additions & 0 deletions blocks/api/raw-handling/test/is-inline-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ describe( 'stripWrappers', () => {
it( 'should be inline content', () => {
equal( isInlineContent( '<em>test</em>' ), true );
equal( isInlineContent( '<span>test</span>' ), true );
equal( isInlineContent( '<li>test</li>', 'ul' ), true );
} );

it( 'should not be inline content', () => {
equal( isInlineContent( '<div>test</div>' ), false );
equal( isInlineContent( '<em>test</em><div>test</div>' ), false );
equal( isInlineContent( 'test<br><br>test' ), false );
equal( isInlineContent( '<em><div>test</div></em>' ), false );
equal( isInlineContent( '<li>test</li>', 'p' ), false );
equal( isInlineContent( '<li>test</li>', 'h1' ), false );
equal( isInlineContent( '<h1>test</h1>', 'li' ), false );
} );
} );
37 changes: 35 additions & 2 deletions blocks/api/raw-handling/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
/**
* External dependencies
*/
import { includes } from 'lodash';

/**
* Browser dependencies
*/
const { ELEMENT_NODE, TEXT_NODE } = window.Node;

/**
* An array of tag groups used by isInlineForTag function.
* If tagName and nodeName are present in the same group, the node should be treated as inline.
* @type {Array}
*/
const inlineWhitelistTagGroups = [
[ 'ul', 'li', 'ol' ],
[ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ],
];

const inlineWhitelist = {
strong: {},
em: {},
Expand Down Expand Up @@ -63,8 +78,26 @@ export function isAttributeWhitelisted( tag, attribute ) {
);
}

export function isInline( node ) {
return !! inlineWhitelist[ node.nodeName.toLowerCase() ];
/**
* Checks if nodeName should be treated as inline when being added to tagName.
* This happens if nodeName and tagName are in the same group defined in inlineWhitelistTagGroups.
*
* @param {String} nodeName Node name.
* @param {String} tagName Tag name.
* @return {Boolean} True if nodeName is inline in the context of tagName and false otherwise.
*/
function isInlineForTag( nodeName, tagName ) {
if ( ! tagName || ! nodeName ) {
return false;
}
return inlineWhitelistTagGroups.some( tagGroup =>
includes( tagGroup, nodeName ) && includes( tagGroup, tagName )
);
}

export function isInline( node, tagName ) {
const nodeName = node.nodeName.toLowerCase();
return !! inlineWhitelist[ nodeName ] || isInlineForTag( nodeName, tagName );
}

export function isInlineWrapper( node ) {
Expand Down
39 changes: 29 additions & 10 deletions blocks/api/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,25 @@ export function getBlockDefaultClassname( blockName ) {

/**
* Given a block type containg a save render implementation and attributes, returns the
* static markup to be saved.
* enhanced element to be saved or string when raw HTML expected.
*
* @param {Object} blockType Block type
* @param {Object} attributes Block attributes
* @return {string} Save content
* @return {Object|string} Save content
*/
export function getSaveContent( blockType, attributes ) {
export function getSaveElement( blockType, attributes ) {
const { save } = blockType;
let saveContent;

let saveElement;

if ( save.prototype instanceof Component ) {
saveContent = createElement( save, { attributes } );
saveElement = createElement( save, { attributes } );
} else {
saveContent = save( { attributes } );
saveElement = save( { attributes } );

// Special-case function render implementation to allow raw HTML return
if ( 'string' === typeof saveContent ) {
return saveContent;
if ( 'string' === typeof saveElement ) {
return saveElement;
}
}

Expand All @@ -59,10 +60,28 @@ export function getSaveContent( blockType, attributes ) {

return cloneElement( element, props );
};
const contentWithExtraProps = Children.map( saveContent, addExtraContainerProps );

return Children.map( saveElement, addExtraContainerProps );
}

/**
* Given a block type containg a save render implementation and attributes, returns the
* static markup to be saved.
*
* @param {Object} blockType Block type
* @param {Object} attributes Block attributes
* @return {string} Save content
*/
export function getSaveContent( blockType, attributes ) {
const saveElement = getSaveElement( blockType, attributes );

// Special-case function render implementation to allow raw HTML return
if ( 'string' === typeof saveElement ) {
return saveElement;
}

// Otherwise, infer as element
return renderToString( contentWithExtraProps );
return renderToString( saveElement );
}

/**
Expand Down
7 changes: 6 additions & 1 deletion blocks/api/test/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ describe( 'block factory', () => {
type: 'boolean',
default: true,
},
includesFalseyDefault: {
type: 'number',
default: 0,
},
},
save: noop,
category: 'common',
Expand All @@ -56,6 +60,7 @@ describe( 'block factory', () => {
expect( block.name ).toEqual( 'core/test-block' );
expect( block.attributes ).toEqual( {
includesDefault: true,
includesFalseyDefault: 0,
align: 'left',
} );
expect( block.isValid ).toBe( true );
Expand Down Expand Up @@ -619,7 +624,7 @@ describe( 'block factory', () => {

expect( createReusableBlock( type, attributes ) ).toMatchObject( {
id: expect.any( Number ),
name: 'Untitled block',
title: 'Untitled block',
type,
attributes,
} );
Expand Down
27 changes: 21 additions & 6 deletions blocks/block-description/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
/**
* Internal dependencies
*/
import './style.scss';

export default function BlockDescription( { children } ) {
return (
<div className="components-block-description">
{ children }
</div>
);
class BlockDescription extends Component {
constructor() {
super( ...arguments );
// eslint-disable-next-line no-console
console.warn( 'The wp.blocks.BlockDescription component is deprecated. Use the "description" block property instead.' );
}

render() {
const { children } = this.props;
return (
<div className="components-block-description">
{ children }
</div>
);
}
}

export default BlockDescription;
8 changes: 8 additions & 0 deletions blocks/block-description/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ import { shallow } from 'enzyme';
*/
import BlockDescription from '../';

/* eslint-disable no-console */
function expectWarning() {
expect( console.warn ).toHaveBeenCalled();
console.warn.mockClear();
}
/* eslint-enable no-console */

describe( 'BlockDescription', () => {
describe( 'basic rendering', () => {
it( 'should render a <p> element with some content', () => {
const blockDescription = shallow( <BlockDescription><p>Hello World</p></BlockDescription> );
expect( blockDescription.hasClass( 'components-block-description' ) ).toBe( true );
expect( blockDescription.type() ).toBe( 'div' );
expect( blockDescription.text() ).toBe( 'Hello World' );
expectWarning();
} );
} );
} );
23 changes: 19 additions & 4 deletions blocks/block-edit/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
Expand All @@ -6,22 +11,32 @@ import { withFilters } from '@wordpress/components';
/**
* Internal dependencies
*/
import { getBlockType } from '../api';
import {
getBlockType,
getBlockDefaultClassname,
hasBlockSupport,
} from '../api';

function BlockEdit( props ) {
const { name, ...editProps } = props;
export function BlockEdit( props ) {
const { name, attributes = {} } = props;
const blockType = getBlockType( name );

if ( ! blockType ) {
return null;
}

// Generate a class name for the block's editable form
const generatedClassName = hasBlockSupport( blockType, 'className', true ) ?
getBlockDefaultClassname( name ) :
null;
const className = classnames( generatedClassName, attributes.className );

// `edit` and `save` are functions or components describing the markup
// with which a block is displayed. If `blockType` is valid, assign
// them preferencially as the render value for the block.
const Edit = blockType.edit || blockType.save;

return <Edit { ...editProps } />;
return <Edit { ...props } className={ className } />;
}

export default withFilters( 'blocks.BlockEdit' )( BlockEdit );
Loading