Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getBlockDisplayName( blockType, attributes ) {
const displayNameAttribute = blockType.__experimentalDisplayName;
if ( ! displayNameAttribute || ! attributes[ displayNameAttribute ] ) {
return blockType.title;
}
// Strip any formatting.
const richTextValue = create( { html: attributes[ displayNameAttribute ] } );
const formatlessDisplayName = getTextContent( richTextValue );
return formatlessDisplayName;
}
( record ) => {
const BACKTICK = '`';
const { start } = record;
const text = getTextContent( record );
const characterBefore = text.slice( start - 1, start );
// Quick check the text for the necessary character.
if ( characterBefore !== BACKTICK ) {
return record;
}
const textBefore = text.slice( 0, start - 1 );
const indexBefore = textBefore.lastIndexOf( BACKTICK );
if ( indexBefore === -1 ) {
return record;
}
const startIndex = indexBefore;
const endIndex = start - 2;
return ( record, onReplace ) => {
const text = getTextContent( record );
const transformation = findTransform( transforms, ( item ) => {
return item.regExp.test( text );
} );
if ( ! transformation ) {
return record;
}
onReplace( [
transformation.transform( { content: text } ),
] );
};
}
( record, onReplace, valueToFormat ) => {
if ( ! onReplace ) {
return record;
}
const { start } = record;
const text = getTextContent( record );
const characterBefore = text.slice( start - 1, start );
if ( ! /\s/.test( characterBefore ) ) {
return record;
}
const trimmedTextBefore = text.slice( 0, start ).trim();
const transformation = findTransform( prefixTransforms, ( { prefix } ) => {
return trimmedTextBefore === prefix;
} );
if ( ! transformation ) {
return record;
}
const content = valueToFormat( slice( record, start, text.length ) );
componentDidUpdate( prevProps, prevState ) {
const { record, completers } = this.props;
const { record: prevRecord } = prevProps;
const { open: prevOpen } = prevState;
if ( ( ! this.state.open ) !== ( ! prevOpen ) ) {
this.toggleKeyEvents( ! ! this.state.open );
}
if ( isCollapsed( record ) ) {
const text = deburr( getTextContent( slice( record, 0 ) ) );
const prevText = deburr( getTextContent( slice( prevRecord, 0 ) ) );
if ( text !== prevText ) {
const textAfterSelection = getTextContent( slice( record, undefined, getTextContent( record ).length ) );
const allCompleters = map( completers, ( completer, idx ) => ( { ...completer, idx } ) );
const open = find( allCompleters, ( { triggerPrefix, allowContext } ) => {
const index = text.lastIndexOf( triggerPrefix );
if ( index === -1 ) {
return false;
}
if ( allowContext && ! allowContext( text.slice( 0, index ), textAfterSelection ) ) {
return false;
}
return /^\S*$/.test( text.slice( index + triggerPrefix.length ) );
} );
if ( ! open ) {