Skip to content

Commit

Permalink
prep build 12/01
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed Dec 1, 2023
2 parents f872e4f + 6a793de commit 5e9caa4
Show file tree
Hide file tree
Showing 61 changed files with 1,586 additions and 858 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/end2end-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ jobs:
npm run wp-env start
- name: Run the tests
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
run: |
xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test:e2e:playwright -- --shard=${{ matrix.part }}/${{ matrix.totalParts }}
Expand Down
1 change: 1 addition & 0 deletions bin/plugin/commands/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ async function runTestSuite( testSuite, testRunnerDir, runKey ) {
testRunnerDir,
{
...process.env,
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1',
WP_ARTIFACTS_PATH: ARTIFACTS_PATH,
RESULTS_ID: runKey,
}
Expand Down
4 changes: 0 additions & 4 deletions docs/reference-guides/data/data-core-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,6 @@ Returns state object prior to a specified optimist transaction ID, or `null` if

Returns a suggested post format for the current post, inferred only if there is a single block within the post and it is of a type known to match a default post format. Returns null if the format cannot be determined.

_Parameters_

- _state_ `Object`: Global application state.

_Returns_

- `?string`: Suggested post format.
Expand Down
36 changes: 36 additions & 0 deletions lib/block-supports/pattern.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Pattern block support flag.
*
* @package gutenberg
*/

$gutenberg_experiments = get_option( 'gutenberg-experiments' );
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-pattern-partial-syncing', $gutenberg_experiments ) ) {
/**
* Registers the overrides context for block types that support it.
*
* @param WP_Block_Type $block_type Block Type.
*/
function gutenberg_register_pattern_support( $block_type ) {
$pattern_support = property_exists( $block_type, 'supports' ) ? _wp_array_get( $block_type->supports, array( '__experimentalConnections' ), false ) : false;

if ( $pattern_support ) {
if ( ! $block_type->uses_context ) {
$block_type->uses_context = array();
}

if ( ! in_array( 'pattern/overrides', $block_type->uses_context, true ) ) {
$block_type->uses_context[] = 'pattern/overrides';
}
}
}

// Register the block support.
WP_Block_Supports::get_instance()->register(
'pattern',
array(
'register_attribute' => 'gutenberg_register_pattern_support',
)
);
}
39 changes: 27 additions & 12 deletions lib/experimental/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ function wp_enqueue_block_view_script( $block_name, $args ) {


$gutenberg_experiments = get_option( 'gutenberg-experiments' );
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-connections', $gutenberg_experiments ) ) {
if ( $gutenberg_experiments && (
array_key_exists( 'gutenberg-connections', $gutenberg_experiments ) ||
array_key_exists( 'gutenberg-pattern-partial-syncing', $gutenberg_experiments )
) ) {
/**
* Renders the block meta attributes.
*
Expand Down Expand Up @@ -132,9 +135,8 @@ function gutenberg_render_block_connections( $block_content, $block, $block_inst
continue;
}

// If the source value is not "meta_fields", skip it because the only supported
// connection source is meta (custom fields) for now.
if ( 'meta_fields' !== $attribute_value['source'] ) {
// Skip if the source value is not "meta_fields" or "pattern_attributes".
if ( 'meta_fields' !== $attribute_value['source'] && 'pattern_attributes' !== $attribute_value['source'] ) {
continue;
}

Expand All @@ -143,16 +145,28 @@ function gutenberg_render_block_connections( $block_content, $block, $block_inst
continue;
}

// If the attribute does not specify the name of the custom field, skip it.
if ( ! isset( $attribute_value['value'] ) ) {
continue;
if ( 'pattern_attributes' === $attribute_value['source'] ) {
if ( ! _wp_array_get( $block_instance->attributes, array( 'metadata', 'id' ), false ) ) {
continue;
}

$custom_value = $connection_sources[ $attribute_value['source'] ]( $block_instance );
} else {
// If the attribute does not specify the name of the custom field, skip it.
if ( ! isset( $attribute_value['value'] ) ) {
continue;
}

// Get the content from the connection source.
$custom_value = $connection_sources[ $attribute_value['source'] ](
$block_instance,
$attribute_value['value']
);
}

// Get the content from the connection source.
$custom_value = $connection_sources[ $attribute_value['source'] ](
$block_instance,
$attribute_value['value']
);
if ( false === $custom_value ) {
continue;
}

$tags = new WP_HTML_Tag_Processor( $block_content );
$found = $tags->next_tag(
Expand Down Expand Up @@ -181,5 +195,6 @@ function gutenberg_render_block_connections( $block_content, $block, $block_inst

return $block_content;
}

add_filter( 'render_block', 'gutenberg_render_block_connections', 10, 3 );
}
8 changes: 6 additions & 2 deletions lib/experimental/connection-sources/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
*/

return array(
'name' => 'meta',
'meta_fields' => function ( $block_instance, $meta_field ) {
'name' => 'meta',
'meta_fields' => function ( $block_instance, $meta_field ) {
// We should probably also check if the meta field exists but for now it's okay because
// if it doesn't, `get_post_meta()` will just return an empty string.
return get_post_meta( $block_instance->context['postId'], $meta_field, true );
},
'pattern_attributes' => function ( $block_instance ) {
$block_id = $block_instance->attributes['metadata']['id'];
return _wp_array_get( $block_instance->context, array( 'pattern/overrides', $block_id ), false );
},
);
4 changes: 4 additions & 0 deletions lib/experimental/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ function gutenberg_enable_experiments() {
if ( gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) ) {
wp_add_inline_script( 'wp-block-library', 'window.__experimentalDisableTinymce = true', 'before' );
}

if ( $gutenberg_experiments && array_key_exists( 'gutenberg-pattern-partial-syncing', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalPatternPartialSyncing = true', 'before' );
}
}

add_action( 'admin_init', 'gutenberg_enable_experiments' );
Expand Down
12 changes: 12 additions & 0 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ function gutenberg_initialize_experiments_settings() {
)
);

add_settings_field(
'gutenberg-pattern-partial-syncing',
__( 'Synced patterns partial syncing', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Test partial syncing of patterns', 'gutenberg' ),
'id' => 'gutenberg-pattern-partial-syncing',
)
);

register_setting(
'gutenberg-experiments',
'gutenberg-experiments'
Expand Down
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ function () {
require __DIR__ . '/block-supports/shadow.php';
require __DIR__ . '/block-supports/background.php';
require __DIR__ . '/block-supports/behaviors.php';
require __DIR__ . '/block-supports/pattern.php';

// Data views.
require_once __DIR__ . '/experimental/data-views.php';
12 changes: 7 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useCallback } from '@wordpress/element';
/**
* Internal dependencies
*/
import { mergeOrigins, hasMergedOrigins } from '../use-settings';
import FontFamilyControl from '../font-family';
import FontAppearanceControl from '../font-appearance-control';
import LineHeightControl from '../line-height-control';
Expand Down Expand Up @@ -51,44 +52,29 @@ export function useHasTypographyPanel( settings ) {
}

function useHasFontSizeControl( settings ) {
const disableCustomFontSizes = ! settings?.typography?.customFontSize;
const fontSizesPerOrigin = settings?.typography?.fontSizes ?? {};
const fontSizes = []
.concat( fontSizesPerOrigin?.custom ?? [] )
.concat( fontSizesPerOrigin?.theme ?? [] )
.concat( fontSizesPerOrigin.default ?? [] );
return !! fontSizes?.length || ! disableCustomFontSizes;
return (
hasMergedOrigins( settings?.typography?.fontSizes ) ||
settings?.typography?.customFontSize
);
}

function useHasFontFamilyControl( settings ) {
const fontFamiliesPerOrigin = settings?.typography?.fontFamilies;
const fontFamilies = []
.concat( fontFamiliesPerOrigin?.custom ?? [] )
.concat( fontFamiliesPerOrigin?.theme ?? [] )
.concat( fontFamiliesPerOrigin?.default ?? [] )
.sort( ( a, b ) =>
( a?.name || a?.slug )?.localeCompare( b?.name || a?.slug )
);
return !! fontFamilies?.length;
return hasMergedOrigins( settings?.typography?.fontFamilies );
}

function useHasLineHeightControl( settings ) {
return settings?.typography?.lineHeight;
}

function useHasAppearanceControl( settings ) {
const hasFontStyles = settings?.typography?.fontStyle;
const hasFontWeights = settings?.typography?.fontWeight;
return hasFontStyles || hasFontWeights;
return settings?.typography?.fontStyle || settings?.typography?.fontWeight;
}

function useAppearanceControlLabel( settings ) {
const hasFontStyles = settings?.typography?.fontStyle;
const hasFontWeights = settings?.typography?.fontWeight;
if ( ! hasFontStyles ) {
if ( ! settings?.typography?.fontStyle ) {
return __( 'Font weight' );
}
if ( ! hasFontWeights ) {
if ( ! settings?.typography?.fontWeight ) {
return __( 'Font style' );
}
return __( 'Appearance' );
Expand All @@ -115,18 +101,15 @@ function useHasTextColumnsControl( settings ) {
}

function getUniqueFontSizesBySlug( settings ) {
const fontSizesPerOrigin = settings?.typography?.fontSizes ?? {};
const fontSizes = []
.concat( fontSizesPerOrigin?.custom ?? [] )
.concat( fontSizesPerOrigin?.theme ?? [] )
.concat( fontSizesPerOrigin.default ?? [] );

return fontSizes.reduce( ( acc, currentSize ) => {
if ( ! acc.some( ( { slug } ) => slug === currentSize.slug ) ) {
acc.push( currentSize );
const fontSizes = settings?.typography?.fontSizes;
const mergedFontSizes = fontSizes ? mergeOrigins( fontSizes ) : [];
const uniqueSizes = [];
for ( const currentSize of mergedFontSizes ) {
if ( ! uniqueSizes.some( ( { slug } ) => slug === currentSize.slug ) ) {
uniqueSizes.push( currentSize );
}
return acc;
}, [] );
}
return uniqueSizes;
}

function TypographyToolsPanel( {
Expand Down Expand Up @@ -178,14 +161,11 @@ export default function TypographyPanel( {

// Font Family
const hasFontFamilyEnabled = useHasFontFamilyControl( settings );
const fontFamiliesPerOrigin = settings?.typography?.fontFamilies;
const fontFamilies = []
.concat( fontFamiliesPerOrigin?.custom ?? [] )
.concat( fontFamiliesPerOrigin?.theme ?? [] )
.concat( fontFamiliesPerOrigin?.default ?? [] );
const fontFamilies = settings?.typography?.fontFamilies;
const mergedFontFamilies = fontFamilies ? mergeOrigins( fontFamilies ) : [];
const fontFamily = decodeValue( inheritedValue?.typography?.fontFamily );
const setFontFamily = ( newValue ) => {
const slug = fontFamilies?.find(
const slug = mergedFontFamilies?.find(
( { fontFamily: f } ) => f === newValue
)?.slug;
onChange(
Expand All @@ -204,7 +184,7 @@ export default function TypographyPanel( {
// Font Size
const hasFontSizeEnabled = useHasFontSizeControl( settings );
const disableCustomFontSizes = ! settings?.typography?.customFontSize;
const fontSizes = getUniqueFontSizesBySlug( settings );
const mergedFontSizes = getUniqueFontSizesBySlug( settings );

const fontSize = decodeValue( inheritedValue?.typography?.fontSize );
const setFontSize = ( newValue, metadata ) => {
Expand Down Expand Up @@ -368,7 +348,7 @@ export default function TypographyPanel( {
panelId={ panelId }
>
<FontFamilyControl
fontFamilies={ fontFamilies }
fontFamilies={ mergedFontFamilies }
value={ fontFamily }
onChange={ setFontFamily }
size="__unstable-large"
Expand All @@ -387,7 +367,7 @@ export default function TypographyPanel( {
<FontSizePicker
value={ fontSize }
onChange={ setFontSize }
fontSizes={ fontSizes }
fontSizes={ mergedFontSizes }
disableCustomFontSizes={ disableCustomFontSizes }
withReset={ false }
withSlider
Expand Down
16 changes: 15 additions & 1 deletion packages/block-editor/src/components/use-settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const removeCustomPrefixes = ( path ) => {
* @param {Object} value Object to merge
* @return {Array} Array of merged items
*/
function mergeOrigins( value ) {
export function mergeOrigins( value ) {
let result = mergeCache.get( value );
if ( ! result ) {
result = [ 'default', 'theme', 'custom' ].flatMap(
Expand All @@ -115,6 +115,20 @@ function mergeOrigins( value ) {
}
const mergeCache = new WeakMap();

/**
* For settings like `color.palette`, which have a value that is an object
* with `default`, `theme`, `custom`, with field values that are arrays of
* items, see if any of the three origins have values.
*
* @param {Object} value Object to check
* @return {boolean} Whether the object has values in any of the three origins
*/
export function hasMergedOrigins( value ) {
return [ 'default', 'theme', 'custom' ].some(
( key ) => value?.[ key ]?.length
);
}

/**
* Hook that retrieves the given settings for the block instance in use.
*
Expand Down
Loading

0 comments on commit 5e9caa4

Please sign in to comment.