Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it( 'should be present for each block', () => {
const errors = [];
getBlockTypes()
.map( ( block ) => block.name )
// We don't want tests for each oembed provider, which all have the same
// `save` functions and attributes.
// The `core/template` is not worth testing here because it's never saved, it's covered better in e2e tests.
.filter( ( name ) => name.indexOf( 'core-embed' ) !== 0 && name !== 'core/template' )
.forEach( ( name ) => {
const nameToFilename = blockNameToFixtureBasename( name );
const foundFixtures = blockBasenames
.filter( ( basename ) => (
basename === nameToFilename ||
startsWith( basename, nameToFilename + '__' )
) )
.map( ( basename ) => {
const {
filename: htmlFixtureFileName,
} = getBlockFixtureHTML( basename );
domReady( () => {
// Ensure that the default block is page when no block is selected.
setDefaultBlockName( 'amp/amp-story-page' );
// Remove all blocks that aren't whitelisted.
const disallowedBlockTypes = getBlockTypes().filter( ( { name } ) => ! ALLOWED_BLOCKS.includes( name ) );
for ( const blockType of disallowedBlockTypes ) {
unregisterBlockType( blockType.name );
}
const allBlocks = getBlocksByClientId( getClientIdsWithDescendants() );
// Set initially shown page.
const firstPage = allBlocks.find( ( { name } ) => name === 'amp/amp-story-page' );
setCurrentPage( firstPage ? firstPage.clientId : undefined );
for ( const block of allBlocks ) {
// Load all needed fonts.
if ( block.attributes.ampFontFamily ) {
maybeEnqueueFontStyle( block.attributes.ampFontFamily );
}
options: once( function options() {
return Promise.resolve(
// Prioritize common category in block type options
sortBy(
getBlockTypes(),
( { category } ) => 'common' !== category
)
);
} ),
getOptionKeywords( blockSettings ) {
export default function allowedBlockTypes(disallowedTypes: string[] = defaultDisallowed): string[] {
return getBlockTypes()
.map((type) => type.name)
.filter((typeName) => disallowedTypes.indexOf(typeName) === -1);
}
const AccessControl = ( props ) => {
const { className, isIndividualControlForSchemaModeEnabled } = props;
/**
* Only allow blocks under the "Access Control" category, except for this self block
*/
const allowedBlocks = getBlockTypes().filter(
blockType => blockType.category == ACCESS_CONTROL_BLOCK_CATEGORY && blockType.name != ACCESS_CONTROL_BLOCK_NAME
).map(blockType => blockType.name)
/**
* Add component SchemaMode only if option "individual schema mode" is enabled
*/
return (
<>
{ isIndividualControlForSchemaModeEnabled &&
<div>
</div>
}
/**
* Internal dependencies
*/
import styles from './block-picker.scss';
type PropsType = {
style?: StyleSheet,
isReplacement: boolean,
onValueSelected: ( itemValue: string ) => void,
onDismiss: () => void,
addExtraBottomPadding: boolean,
};
export default class BlockPicker extends Component {
availableBlockTypes = getBlockTypes().filter( ( { name } ) => name !== getUnregisteredTypeHandlerName() );
render() {
const numberOfColumns = this.calculateNumberOfColumns();
const bottomPadding = this.props.addExtraBottomPadding && styles.contentBottomPadding;
return (
/**
* Internal dependencies
*/
import styles from './block-picker.scss';
type PropsType = {
style?: StyleSheet,
isReplacement: boolean,
onValueSelected: ( itemValue: string ) => void,
onDismiss: () => void,
addExtraBottomPadding: boolean,
};
export default class BlockPicker extends Component {
availableBlockTypes = getBlockTypes().filter( ( { name } ) => name !== getUnregisteredTypeHandlerName() );
render() {
const numberOfColumns = this.calculateNumberOfColumns();
const bottomPadding = this.props.addExtraBottomPadding && styles.contentBottomPadding;
return (
return {
id,
name: 'core/block',
initialAttributes: { ref: reusableBlock.id },
title: reusableBlock.title,
icon: referencedBlockType ? referencedBlockType.icon : templateIcon,
category: 'reusable',
keywords: [],
isDisabled: false,
utility,
frecency,
};
};
const blockTypeInserterItems = getBlockTypes()
.filter( ( blockType ) => canIncludeBlockTypeInInserter( state, blockType, rootClientId ) )
.map( buildBlockTypeInserterItem );
const reusableBlockInserterItems = canInsertBlockTypeUnmemoized( state, 'core/block', rootClientId ) ?
getReusableBlocks( state ).map( buildReusableBlockInserterItem ) :
[];
return orderBy(
[ ...blockTypeInserterItems, ...reusableBlockInserterItems ],
[ 'utility', 'frecency' ],
[ 'desc', 'desc' ]
);
},
( state, rootClientId ) => [
constructor() {
super( ...arguments );
//assign blocks per category
const blocksPerCategory = {};
{ map( getCategories(), ( category ) => {
blocksPerCategory[ category.slug ] = category;
blocksPerCategory[ category.slug ].blocks = {};
} ); }
{ map( getBlockTypes(), ( block ) => {
if ( ! [ 'core/paragraph' ].includes( block.name ) && ! block.parent ) {
blocksPerCategory[ block.category ].blocks[ block.name ] = block;
}
} ); }
this.state = {
settings: '',
isOpen: false,
isSaving: false,
isLoaded: false,
searchValue: '',
allBlocks: blocksPerCategory,
getBlockTypes: getBlockTypes(),
searchResults: {},
};
function BlockSwitcher( { blocks, onTransform } ) {
if ( ! blocks || ! blocks[ 0 ] ) {
return null;
}
const isMultiBlock = blocks.length > 1;
const sourceBlockName = blocks[ 0 ].name;
if ( isMultiBlock && ! every( blocks, ( block ) => ( block.name === sourceBlockName ) ) ) {
return null;
}
const blockType = getBlockType( sourceBlockName );
const blocksToBeTransformedFrom = reduce( getBlockTypes(), ( memo, type ) => {
const transformFrom = get( type, 'transforms.from', [] );
const transformation = find(
transformFrom,
t => t.type === 'block' && t.blocks.indexOf( sourceBlockName ) !== -1 &&
( ! isMultiBlock || t.isMultiBlock )
);
return transformation ? memo.concat( [ type.name ] ) : memo;
}, [] );
const blocksToBeTransformedTo = get( blockType, 'transforms.to', [] )
.reduce(
( memo, transformation ) =>
memo.concat( ! isMultiBlock || transformation.isMultiBlock ? transformation.blocks : [] ),
[]
);
const allowedBlocks = uniq( blocksToBeTransformedFrom.concat( blocksToBeTransformedTo ) )
.reduce( ( memo, name ) => {