Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { childBlocks, name, settings } = extension;
const { available } = getJetpackExtensionAvailability( name );
if ( has( settings, [ 'render' ] ) ) {
// If the extension has a `render` method, it's not a block but a plugin
const pluginName = `jetpack-${ name }`;
const registered = getPlugin( pluginName );
if ( available && ! registered ) {
registerPlugin( pluginName, settings );
} else if ( ! available && registered ) {
unregisterPlugin( pluginName );
}
} else {
const blockName = `jetpack/${ name }`;
const registered = getBlockType( blockName );
if ( available && ! registered ) {
registerBlockType( blockName, settings );
if ( childBlocks ) {
childBlocks.forEach( ( { name: childName, settings: childSettings } ) => {
// This might have been registered by another parent before
if ( ! getBlockType( `jetpack/${ childName }` ) ) {
registerBlockType( `jetpack/${ childName }`, childSettings );
}
} );
}
} else if ( ! available && registered ) {
if ( childBlocks ) {
childBlocks.forEach( ( { name: childName } ) => {
const childBlock = getBlockType( `jetpack/${ childName }` );
const otherParents = without( childBlock.parent, blockName );
function getOutboundType( blockName ) {
// Grab the first outbound transform
const transform = findTransform(
getBlockTransforms( 'to', blockName ),
( { type, blocks } ) => type === 'block' && blocks.length === 1 // What about when .length > 1?
);
if ( ! transform ) {
return null;
}
return getBlockType( transform.blocks[ 0 ] );
}
setAttributes (attributes) {
const { block, onChange } = this.props;
const type = getBlockType(block.name);
onChange(block.clientId, attributes);
const metaAttributes = reduce(attributes, (result, value, key) => {
if (get(type, [ 'attributes', key, 'source' ]) === 'meta') {
result[ type.attributes[ key ].meta ] = value;
}
return result;
}, {});
if (size(metaAttributes)) {
this.props.onMetaChange({
...this.props.meta,
...metaAttributes,
});
}
( state, { uid } ) => {
const block = getBlock( state, uid );
return {
mode: getBlockMode( state, uid ),
blockType: block ? getBlockType( block.name ) : null,
};
},
( dispatch, { onToggle = noop, uid } ) => ( {
const registerBlock = ( name, settings = {} ) => {
if ( getBlockType( name ) ) {
return
}
const blockName = name.replace( /^\w+\//g, '' )
const blockSettings = {
...settings,
category: supportsBlockCollections() ? settings.category : 'stackable',
modules: applyFilters( `stackable.${ blockName }.modules`, settings.modules || {} ),
deprecated: ( settings.deprecated || [] ).map( deprecated => {
return {
...deprecated,
save: withMainClassname( name )( deprecated.save ),
}
} ),
}
withSelect( ( select, { clientId } ) => {
const { getBlock, getBlockMode, getSettings } = select( 'core/block-editor' );
const block = getBlock( clientId );
const isCodeEditingEnabled = getSettings().codeEditingEnabled;
return {
mode: getBlockMode( clientId ),
blockType: block ? getBlockType( block.name ) : null,
isCodeEditingEnabled,
};
} ),
withDispatch( ( dispatch, { onToggle = noop, clientId } ) => ( {
const getFieldLabel = ( { attributes, name: blockName } ) => {
return null === attributes.label ? getBlockType( blockName ).title : attributes.label;
};
const getFieldLabel = ( { attributes, name: blockName } ) => {
return null === attributes.label ? getBlockType( blockName ).title : attributes.label;
};
export default withSelect( ( select, { block, label } ) => {
if ( ! block ) {
return {
content: label,
icon: null,
};
}
const { getEditedPostAttribute } = select( 'core/editor' );
const { getAuthors, getMedia } = select( 'core' );
const blockType = getBlockType( block.name );
label = blockType.title;
let content = '';
switch ( block.name ) {
case 'core/image':
if ( block.attributes.url ) {
content = block.attributes.url.slice( block.attributes.url.lastIndexOf( '/' ) ).slice( 1, 30 );
if ( content.length > 0 ) {
label = content;
}
}
if ( block.attributes.id ) {
const media = getMedia( block.attributes.id );
{ map( omitBy( blocks, isNil ), ( block ) => {
const blockType = getBlockType( block.name );
const isSelected = block.clientId === selectedBlockClientId;
return (
<li>
<div>
<button> selectBlock( block.clientId ) }
>
{ getBlockDisplayName( blockType, block.attributes ) }
{ isSelected && <span>{ __( '(selected block)' ) }</span> }
</button>
</div></li>