Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patterns: removes the pattern experiment #51719

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ Show a block pattern. ([Source](https://github.com/WordPress/gutenberg/tree/trun
- **Name:** core/pattern
- **Category:** theme
- **Supports:** ~~html~~, ~~inserter~~
- **Attributes:** slug, syncStatus
- **Attributes:** slug

## Post Author

Expand Down
3 changes: 0 additions & 3 deletions lib/experimental/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ function gutenberg_enable_experiments() {
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-group-grid-variation', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableGroupGridVariation = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-pattern-enhancements', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnablePatternEnhancements = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-interactivity-api-core-blocks', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalInteractivityAPI = true', 'before' );
}
Expand Down
12 changes: 0 additions & 12 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@ function gutenberg_initialize_experiments_settings() {
)
);

add_settings_field(
'gutenberg-pattern-enhancements',
__( 'Pattern enhancements', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Test the Pattern block enhancements', 'gutenberg' ),
'id' => 'gutenberg-pattern-enhancements',
)
);

register_setting(
'gutenberg-experiments',
'gutenberg-experiments'
Expand Down
4 changes: 0 additions & 4 deletions packages/block-library/src/pattern/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
"attributes": {
"slug": {
"type": "string"
},
"syncStatus": {
"type": [ "string", "boolean" ],
"enum": [ "full", "partial" ]
}
}
}
54 changes: 14 additions & 40 deletions packages/block-library/src/pattern/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,26 @@ import { useEffect } from '@wordpress/element';
import {
store as blockEditorStore,
useBlockProps,
useInnerBlocksProps,
} from '@wordpress/block-editor';

const PatternEdit = ( { attributes, clientId } ) => {
const { slug, syncStatus } = attributes;
const { selectedPattern, innerBlocks } = useSelect(
( select ) => {
return {
selectedPattern:
select( blockEditorStore ).__experimentalGetParsedPattern(
slug
),
innerBlocks:
select( blockEditorStore ).getBlock( clientId )
?.innerBlocks,
};
},
[ slug, clientId ]
const selectedPattern = useSelect(
( select ) =>
select( blockEditorStore ).__experimentalGetParsedPattern(
attributes.slug
),
[ attributes.slug ]
);
const {
replaceBlocks,
replaceInnerBlocks,
__unstableMarkNextChangeAsNotPersistent,
} = useDispatch( blockEditorStore );

const { replaceBlocks, __unstableMarkNextChangeAsNotPersistent } =
useDispatch( blockEditorStore );

// Run this effect when the component loads.
// This adds the Pattern's contents to the post.
// This change won't be saved.
// It will continue to pull from the pattern file unless changes are made to its respective template part.
useEffect( () => {
if ( selectedPattern?.blocks && ! innerBlocks?.length ) {
if ( selectedPattern?.blocks ) {
// We batch updates to block list settings to avoid triggering cascading renders
// for each container block included in a tree and optimize initial render.
// Since the above uses microtasks, we need to use a microtask here as well,
Expand All @@ -48,36 +39,19 @@ const PatternEdit = ( { attributes, clientId } ) => {
cloneBlock( block )
);
__unstableMarkNextChangeAsNotPersistent();
if ( syncStatus === 'partial' ) {
replaceInnerBlocks( clientId, clonedBlocks );
return;
}
replaceBlocks( clientId, clonedBlocks );
} );
}
}, [
clientId,
selectedPattern?.blocks,
replaceInnerBlocks,
__unstableMarkNextChangeAsNotPersistent,
innerBlocks,
syncStatus,
replaceBlocks,
] );

const blockProps = useBlockProps( {
className: slug?.replace( '/', '-' ),
} );

const innerBlocksProps = useInnerBlocksProps( blockProps, {
templateLock: syncStatus === 'partial' ? 'contentOnly' : false,
} );

if ( syncStatus !== 'partial' ) {
return <div { ...blockProps } />;
}
const props = useBlockProps();

return <div { ...innerBlocksProps } />;
return <div { ...props } />;
};

export default PatternEdit;
9 changes: 4 additions & 5 deletions packages/block-library/src/pattern/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
*/
import initBlock from '../utils/init-block';
import metadata from './block.json';
import PatternEditV1 from './v1/edit';
import PatternEditV2 from './edit';
import PatternEdit from './edit';

const { name } = metadata;
export { metadata, name };

export const settings = window?.__experimentalEnablePatternEnhancements
? { edit: PatternEditV2 }
: { edit: PatternEditV1 };
export const settings = {
edit: PatternEdit,
};

export const init = () => initBlock( { name, metadata, settings } );
14 changes: 1 addition & 13 deletions packages/block-library/src/pattern/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,7 @@ function render_block_core_pattern( $attributes ) {
}

$pattern = $registry->get_registered( $slug );

// Currently all existing blocks should be returned here without a wp-block-pattern wrapper
// as the syncStatus attribute is only used if the gutenberg-pattern-enhancements experiment
// is enabled.
if ( ! isset( $attributes['syncStatus'] ) ) {
return do_blocks( $pattern['content'] );
}

$block_classnames = 'wp-block-pattern ' . str_replace( '/', '-', $attributes['slug'] );
$classnames = isset( $attributes['className'] ) ? $attributes['className'] . ' ' . $block_classnames : $block_classnames;
$wrapper = '<div class="' . esc_attr( $classnames ) . '">%s</div>';

return sprintf( $wrapper, do_blocks( $pattern['content'] ) );
return do_blocks( $pattern['content'] );
}

add_action( 'init', 'register_block_core_pattern' );
57 changes: 0 additions & 57 deletions packages/block-library/src/pattern/v1/edit.js

This file was deleted.