-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Block API: Normalize function arguments #10891
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
## 5.1.0 (Unreleased) | ||
|
||
### New feature | ||
|
||
- `isBlockContentValid` function has been added ([#10891](https://github.com/WordPress/gutenberg/pull/10891)). | ||
|
||
### Deprecation | ||
|
||
- `isValidBlock` function has been deprecated ([#10891](https://github.com/WordPress/gutenberg/pull/10891)). Use `isBlockContentValid` instead. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a hint to the changed argument order? |
||
|
||
## 5.0.0 (2018-10-29) | ||
|
||
### Breaking Changes | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,10 +174,10 @@ export function unregisterBlockType( name ) { | |
/** | ||
* Assigns name of block for handling non-block content. | ||
* | ||
* @param {string} name Block name. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why should we update this, but not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will revert. It's obvious here what the name is. Other examples where I changed bring more clarity as the function name isn't as specific. e.g.: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't understand your question properly, but I think I answered it anyway :)
|
||
* @param {string} blockName Block name. | ||
*/ | ||
export function setFreeformContentHandlerName( name ) { | ||
dispatch( 'core/blocks' ).setFreeformFallbackBlockName( name ); | ||
export function setFreeformContentHandlerName( blockName ) { | ||
dispatch( 'core/blocks' ).setFreeformFallbackBlockName( blockName ); | ||
} | ||
|
||
/** | ||
|
@@ -193,10 +193,10 @@ export function getFreeformContentHandlerName() { | |
/** | ||
* Assigns name of block handling unregistered block types. | ||
* | ||
* @param {string} name Block name. | ||
* @param {string} blockName Block name. | ||
*/ | ||
export function setUnregisteredTypeHandlerName( name ) { | ||
dispatch( 'core/blocks' ).setUnregisteredFallbackBlockName( name ); | ||
export function setUnregisteredTypeHandlerName( blockName ) { | ||
dispatch( 'core/blocks' ).setUnregisteredFallbackBlockName( blockName ); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,11 @@ | |
import { tokenize } from 'simple-html-tokenizer'; | ||
import { xor, fromPairs, isEqual, includes, stubTrue } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import deprecated from '@wordpress/deprecated'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
|
@@ -485,20 +490,30 @@ export function isEquivalentHTML( actual, expected ) { | |
return true; | ||
} | ||
|
||
export function isValidBlock( innerHTML, blockType, attributes ) { | ||
deprecated( 'isValidBlock', { | ||
plugin: 'Gutenberg', | ||
version: '4.3', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 4.4 now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, true. |
||
alternative: 'isBlockContentValid', | ||
} ); | ||
|
||
return isBlockContentValid( blockType, attributes, innerHTML ); | ||
} | ||
|
||
/** | ||
* Returns true if the parsed block is valid given the input content. A block | ||
* is considered valid if, when serialized with assumed attributes, the content | ||
* matches the original value. | ||
* | ||
* Logs to console in development environments when invalid. | ||
* | ||
* @param {string} innerHTML Original block content. | ||
* @param {string} blockType Block type. | ||
* @param {Object} attributes Parsed block attributes. | ||
* @param {string} innerHTML Original block content. | ||
* | ||
* @return {boolean} Whether block is valid. | ||
*/ | ||
export function isValidBlock( innerHTML, blockType, attributes ) { | ||
export function isBlockContentValid( blockType, attributes, innerHTML ) { | ||
let saveContent; | ||
try { | ||
saveContent = getSaveContent( blockType, attributes ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: We have some precedent of the adjective coming first in boolean "is" functions, e.g.
isReusableBlock
, so for consistency's sake,isValidBlockContent
might be the more consistent ordering.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see also
isValidElement
, let's rename. 👍