-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Framework: Extract the block API to a generic blocks-core module with…
…out global registration
- Loading branch information
1 parent
c8c8078
commit 1f23e41
Showing
67 changed files
with
771 additions
and
486 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { find } from 'lodash'; | ||
|
||
/** | ||
* Retrieves the blockType from the block types config | ||
* | ||
* @param {String} name Block name | ||
* @param {Object} config The block types config | ||
* | ||
* @return {?Object} Block type | ||
*/ | ||
export function getBlockType( name, config ) { | ||
return find( config.blockTypes, ( blockType ) => blockType.name === name ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import * as source from './source'; | ||
|
||
export { source }; | ||
export { createBlock, switchToBlockType } from './factory'; | ||
export { default as parse } from './parser'; | ||
export { default as pasteHandler } from './paste'; | ||
export { default as serialize, getBlockDefaultClassname } from './serializer'; | ||
export { parse as grammarParse } from './post.pegjs'; | ||
export { getBlockType } from './config'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { getBlockType } from '../config'; | ||
|
||
describe( 'block types config', () => { | ||
describe( 'getBlockType', () => { | ||
it( 'should return undefined if the block type was not found', () => { | ||
const blockTypes = [ | ||
{ name: 'core/text' }, | ||
]; | ||
const blockType = getBlockType( 'core/image', { blockTypes } ); | ||
|
||
expect( blockType ).toBeUndefined(); | ||
} ); | ||
|
||
it( 'should return the correponding blockType', () => { | ||
const textBlockType = { name: 'core/text' }; | ||
const blockTypes = [ textBlockType ]; | ||
const blockType = getBlockType( 'core/text', { blockTypes } ); | ||
|
||
expect( blockType ).toBe( textBlockType ); | ||
} ); | ||
} ); | ||
} ); |
Oops, something went wrong.