Skip to content

Commit

Permalink
Issue #27 - display block list for the selected block namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Feb 14, 2019
1 parent 9de6d04 commit 71c0120
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
34 changes: 30 additions & 4 deletions blocks/oik-blocklist/blocklist.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
/*
* Block info renderer - displays the fields for the block info block
* Block list renderer - displays the Block list for the selected namespace prefix
*
* @copyright (C) Copyright Bobbing Wide 2019
* @author Herb Miller @bobbingwide
*
*/

const { getBlockType } = wp.blocks;
const { getBlockType, getBlockTypes } = wp.blocks;
const { BlockIcon } = wp.editor;

import { BlockiconStyled } from '../oik-blockicon/blockicons.js';
import { getNameSpace} from './blockprefix.js';

function BlockListStyled( prefix, showBlockTypeName, showTitle, showDescription, ...props ) {
//var block = getBlockType( blockname ) ;
Expand All @@ -18,13 +20,37 @@ function BlockListStyled( prefix, showBlockTypeName, showTitle, showDescription,
//var blockDescription = showDescription ? <div> { block.description } </div> : null;

var prefix_array = prefix.split( '/' );
var namespace = prefix_array[0];
const namespace = prefix_array[0];

var block_types = getBlockTypes();
block_types = block_types.filter( namespaceFilter, namespace );
//console.log( block_types );
return(
<ul><li>Blocks for {namespace}</li></ul>
<ul>
<li>Blocks for {namespace}</li>
{ block_types.map ( ( block ) => BlockListItem( block ) )}
</ul>

);


}

function namespaceFilter( element, index, array ) {

var element_namespace = getNameSpace(element);
var filter_result = ( this == element_namespace);
return filter_result;
}


function BlockListItem( block ) {
/* { block.icon */
/* console.log( block ); */
return( <li>
<BlockIcon icon={block.icon.src} />
{block.name } {block.title }
</li> );
}

export { BlockListStyled };
8 changes: 4 additions & 4 deletions blocks/oik-blocklist/blockprefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function getOptions() {
var block_types = getBlockTypes();
const namespaces = getNameSpaces( block_types );
const options = namespaces.map ( ( namespace ) => getBlockPrefixOption( namespace ) );
console.log( options );
//console.log( options );
return options;
}

Expand All @@ -66,8 +66,8 @@ function getNameSpaces( block_types) {
var namespaces = block_types.map( ( block ) => getNameSpace( block ));
var unique_namespaces = namespaces.filter( onlyUnique );

console.log( namespaces );
console.log( unique_namespaces );
//console.log( namespaces );
//console.log( unique_namespaces );
return unique_namespaces;

}
Expand Down Expand Up @@ -95,4 +95,4 @@ function getOptionLabel( block ) {



export { BlockPrefixSelect };
export { BlockPrefixSelect, getNameSpace };
8 changes: 0 additions & 8 deletions blocks/oik-blocklist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,6 @@ export default registerBlockType(
<InspectorControls >
<PanelBody>

<PanelRow>
<TextControl
label="Prefix"
value={ props.attributes.prefix }
onChange={ onChangePrefix }
onFocus={ focus }
/>
</PanelRow>

<PanelRow>
<BlockPrefixSelect value={ props.attributes.prefix } onChange={ onChangePrefix } />
Expand Down

0 comments on commit 71c0120

Please sign in to comment.