Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
);
// $ExpectType BlockInstance<{ [k: string]: any; }>[]
blocks.synchronizeBlocksWithTemplate();
// $ExpectType BlockInstance<{ [k: string]: any; }>[]
blocks.synchronizeBlocksWithTemplate([BLOCK_INSTANCE, BLOCK_INSTANCE]);
// $ExpectType BlockInstance<{ [k: string]: any; }>[]
blocks.synchronizeBlocksWithTemplate(
[BLOCK_INSTANCE, BLOCK_INSTANCE],
[['my/foo', { foo: 'bar' }], ['my/foo', { foo: 'bar' }]]
);
// $ExpectType BlockInstance<{ [k: string]: any; }>[]
blocks.synchronizeBlocksWithTemplate(undefined, [['my/foo', { foo: 'bar' }], ['my/foo', { foo: 'bar' }]]);
//
// utils
// ----------------------------------------------------------------------------
// $ExpectType boolean
blocks.isUnmodifiedDefaultBlock(BLOCK_INSTANCE);
// $ExpectType boolean
blocks.isValidIcon(23);
// $ExpectType boolean
blocks.isValidIcon(() => null);
// $ExpectType boolean
blocks.isValidIcon('block-default');
synchronizeBlocksWithTemplate() {
const { template, block, replaceInnerBlocks } = this.props;
const { innerBlocks } = block;
// Synchronize with templates. If the next set differs, replace.
const nextBlocks = synchronizeBlocksWithTemplate( innerBlocks, template );
if ( ! isEqual( nextBlocks, innerBlocks ) ) {
replaceInnerBlocks( nextBlocks );
}
}
SETUP_EDITOR( action, store ) {
const { post, autosave } = action;
const state = store.getState();
// Parse content as blocks
let blocks = parse( post.content.raw );
// Apply a template for new posts only, if exists.
const isNewPost = post.status === 'auto-draft';
const template = getTemplate( state );
if ( isNewPost && template ) {
blocks = synchronizeBlocksWithTemplate( blocks, template );
}
// Include auto draft title in edits while not flagging post as dirty
const edits = {};
if ( isNewPost ) {
edits.title = post.title.raw;
}
// Check the auto-save status
let autosaveAction;
if ( autosave ) {
const noticeMessage = __( 'There is an autosave of this post that is more recent than the version below.' );
autosaveAction = createWarningNotice(
<p>
{ noticeMessage }
{ ' ' }</p>
// In order to ensure maximum of a single parse during setup, edits are
// included as part of editor setup action. Assume edited content as
// canonical if provided, falling back to post.
let content;
if ( has( edits, [ 'content' ] ) ) {
content = edits.content;
} else {
content = post.content.raw;
}
let blocks = parse( content );
// Apply a template for new posts only, if exists.
const isNewPost = post.status === 'auto-draft';
if ( isNewPost && template ) {
blocks = synchronizeBlocksWithTemplate( blocks, template );
}
yield resetPost( post );
yield {
type: 'SETUP_EDITOR',
post,
edits,
template,
};
yield resetEditorBlocks( blocks, { __unstableShouldCreateUndoLevel: false } );
yield setupEditorState( post );
if (
edits &&
Object.keys( edits ).some(
( key ) =>
edits[ key ] !== ( has( post, [ key, 'raw' ] ) ? post[ key ].raw : post[ key ] )
synchronizeBlocksWithTemplate() {
const { template, block, replaceInnerBlocks } = this.props;
const { innerBlocks } = block;
// Synchronize with templates. If the next set differs, replace.
const nextBlocks = synchronizeBlocksWithTemplate( innerBlocks, template );
if ( ! isEqual( nextBlocks, innerBlocks ) ) {
replaceInnerBlocks( nextBlocks );
}
}
synchronizeBlocksWithTemplate() {
const { template, block, replaceInnerBlocks } = this.props;
const { innerBlocks } = block;
// Synchronize with templates. If the next set differs, replace.
const nextBlocks = synchronizeBlocksWithTemplate( innerBlocks, template );
if ( ! isEqual( nextBlocks, innerBlocks ) ) {
replaceInnerBlocks( nextBlocks );
}
}
SYNCHRONIZE_TEMPLATE( action, { getState } ) {
const state = getState();
const blocks = getBlocks( state );
const template = getTemplate( state );
const updatedBlockList = synchronizeBlocksWithTemplate( blocks, template );
return resetBlocks( updatedBlockList );
},
MARK_AUTOMATIC_CHANGE( action, store ) {
SYNCHRONIZE_TEMPLATE( action, { getState } ) {
const state = getState();
const blocks = getBlocks( state );
const template = getTemplate( state );
const updatedBlockList = synchronizeBlocksWithTemplate( blocks, template );
return resetBlocks( updatedBlockList );
},
FETCH_REUSABLE_BLOCKS: ( action, store ) => {