How to use the @wordpress/blocks.synchronizeBlocksWithTemplate function in @wordpress/blocks

To help you get started, we’ve selected a few @wordpress/blocks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / wordpress__blocks / wordpress__blocks-tests.tsx View on Github external
);

// $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');
github WordPress / gutenberg / packages / block-editor / src / components / inner-blocks / index.js View on Github external
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 );
		}
	}
github WordPress / gutenberg / packages / editor / src / store / effects.js View on Github external
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>
github WordPress / gutenberg / packages / editor / src / store / actions.js View on Github external
// 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 ] )
github WordPress / gutenberg / packages / block-editor / src / components / inner-blocks / index.js View on Github external
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 );
		}
	}
github WordPress / gutenberg / packages / block-editor / src / components / inner-blocks / index.native.js View on Github external
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 );
		}
	}
github WordPress / gutenberg / packages / block-editor / src / store / effects.js View on Github external
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 ) {
github WordPress / gutenberg / packages / editor / src / store / effects.js View on Github external
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 ) => {