Skip to content

Commit

Permalink
prep build 1/23
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed Jan 23, 2025
2 parents 3236fb0 + 0d35e9f commit e3e67c4
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 275 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/upload-release-to-plugin-repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ jobs:
VERSION: ${{ github.event.release.name }}

steps:
- name: Install Subversion
run: |
apt-get update -y && apt-get install -y subversion
- name: Check out Gutenberg trunk from WP.org plugin repo
run: |
svn checkout "$PLUGIN_REPO_URL/trunk" --username "$SVN_USERNAME" --password "$SVN_PASSWORD"
Expand Down Expand Up @@ -222,6 +226,10 @@ jobs:
VERSION: ${{ github.event.release.name }}

steps:
- name: Install Subversion
run: |
apt-get update -y && apt-get install -y subversion
- name: Download and unzip Gutenberg plugin asset into tags folder
env:
PLUGIN_URL: ${{ github.event.release.assets[0].browser_download_url }}
Expand Down
5 changes: 3 additions & 2 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
== Changelog ==

= 20.1.0-rc.1 =

= 20.1.0 =

## Changelog

Expand Down Expand Up @@ -205,6 +204,8 @@ The following contributors merged PRs in this release:
@afercia @AhmarZaidi @atachibana @benazeer-ben @carolinan @ciampo @dhananjaykuber @ellatrix @geriux @himanipanchal @himanshupathak95 @im3dabasia @Infinite-Null @jeryj @jorgefilipecosta @juanfra @justlevine @karthick-murugan @luisherranz @Mamaduka @manzoorwanijk @mirka @ramonjd @SainathPoojary @shail-mehta @shimotmk @sirreal @stokesman @Sukhendu2002 @szepeviktor @t-hamano @vipul0425 @Vrishabhsk @yogeshbhutkar




= 20.0.0 =

## Changelog
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gutenberg",
"version": "20.1.0-rc.1",
"version": "20.1.0",
"private": true,
"description": "A new WordPress editor experience.",
"author": "The WordPress Contributors",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@
*/
import {
ALL_SIDES,
getAllRawValue,
getCustomValueFromPreset,
getInitialView,
getPresetValueFromCustomValue,
getSliderValueFromPreset,
getSpacingPresetCssVar,
getSpacingPresetSlug,
getSupportedMenuItems,
hasAxisSupport,
hasBalancedSidesSupport,
isValuesDefined,
isValuesMixed,
isValueSpacingPreset,
LABELS,
VIEWS,
} from '../utils';

Expand Down Expand Up @@ -114,88 +109,6 @@ describe( 'getSliderValueFromPreset', () => {
} );
} );

describe( 'getAllRawValue', () => {
const customValues = {
top: '5px',
bottom: '5px',
left: '6px',
right: '2px',
};
it( 'should return the most common custom value from the values object', () => {
expect( getAllRawValue( customValues ) ).toBe( '5px' );
} );
const presetValues = {
top: 'var:preset|spacing|30',
bottom: 'var:preset|spacing|20',
left: 'var:preset|spacing|10',
right: 'var:preset|spacing|30',
};
it( 'should return the most common preset value from the values object', () => {
expect( getAllRawValue( presetValues ) ).toBe(
'var:preset|spacing|30'
);
} );
} );

describe( 'isValuesMixed', () => {
const unmixedValues = {
top: '5px',
bottom: '5px',
left: '5px',
right: '5px',
};
it( 'should return false if all values are the same', () => {
expect( isValuesMixed( unmixedValues ) ).toBe( false );
} );
const mixedValues = {
top: 'var:preset|spacing|30',
bottom: 'var:preset|spacing|20',
left: 'var:preset|spacing|10',
right: 'var:preset|spacing|30',
};
it( 'should return true if all the values are not the same', () => {
expect( isValuesMixed( mixedValues ) ).toBe( true );
} );
const singleValue = {
top: 'var:preset|spacing|30',
};
it( 'should return true if only one side set', () => {
expect( isValuesMixed( singleValue ) ).toBe( true );
} );
const incompleteValues = {
top: 'var:preset|spacing|30',
bottom: 'var:preset|spacing|30',
left: 'var:preset|spacing|30',
};
it( 'should return true if all sides not set', () => {
expect( isValuesMixed( incompleteValues ) ).toBe( true );
} );
} );

describe( 'isValuesDefined', () => {
const undefinedValues = {
top: undefined,
bottom: undefined,
left: undefined,
right: undefined,
};
it( 'should return false if values are not defined', () => {
expect( isValuesDefined( undefinedValues ) ).toBe( false );
} );
it( 'should return false if values is passed in as null', () => {
expect( isValuesDefined( null ) ).toBe( false );
} );
const definedValues = {
top: 'var:preset|spacing|30',
bottom: 'var:preset|spacing|20',
left: 'var:preset|spacing|10',
right: 'var:preset|spacing|30',
};
it( 'should return true if all the values are not the same', () => {
expect( isValuesDefined( definedValues ) ).toBe( true );
} );
} );

describe( 'hasAxisSupport', () => {
it( 'should return true for horizontal support if it is in sides', () => {
expect( hasAxisSupport( [ 'horizontal' ], 'horizontal' ) ).toBe( true );
Expand Down Expand Up @@ -228,70 +141,6 @@ describe( 'hasAxisSupport', () => {
} );
} );

describe( 'getSupportedMenuItems', () => {
it( 'returns no items when sides are not configured', () => {
expect( getSupportedMenuItems( [] ) ).toEqual( {} );
expect( getSupportedMenuItems() ).toEqual( {} );
} );

const sideConfigs = [
[ LABELS.axial, [ 'horizontal', 'vertical' ] ],
[ LABELS.axial, [ 'top', 'right', 'bottom', 'left' ] ],
[ LABELS.horizontal, [ 'horizontal' ] ],
[ LABELS.horizontal, [ 'left', 'right' ] ],
[ LABELS.vertical, [ 'vertical' ] ],
[ LABELS.vertical, [ 'top', 'bottom' ] ],
[ LABELS.horizontal, [ 'horizontal' ] ],
];

test.each( sideConfigs )(
'should include %s axial menu with %s sides',
( label, sides ) => {
expect( getSupportedMenuItems( sides ) ).toHaveProperty(
'axial.label',
label
);
}
);

it( 'returns no axial item when not not supported', () => {
expect( getSupportedMenuItems( [ 'left', 'top' ] ) ).not.toHaveProperty(
'axial'
);
} );

it( 'should include the correct individual side options', () => {
expect( getSupportedMenuItems( [ 'top' ] ) ).toHaveProperty(
'top.label',
LABELS.top
);
expect( getSupportedMenuItems( [ 'right' ] ) ).toHaveProperty(
'right.label',
LABELS.right
);
expect( getSupportedMenuItems( [ 'bottom' ] ) ).toHaveProperty(
'bottom.label',
LABELS.bottom
);
expect( getSupportedMenuItems( [ 'left' ] ) ).toHaveProperty(
'left.label',
LABELS.left
);
} );
it( 'should include the custom option only when applicable', () => {
expect( getSupportedMenuItems( [ 'top', 'left' ] ) ).toHaveProperty(
'custom.label',
LABELS.custom
);
expect( getSupportedMenuItems( [ 'top' ] ) ).not.toHaveProperty(
'custom'
);
expect(
getSupportedMenuItems( [ 'horizontal', 'vertical' ] )
).not.toHaveProperty( 'custom.label' );
} );
} );

describe( 'hasBalancedSidesSupport', () => {
it( 'should determine balanced sides', () => {
expect( hasBalancedSidesSupport( ALL_SIDES ) ).toBe( true );
Expand Down
106 changes: 0 additions & 106 deletions packages/block-editor/src/components/spacing-sizes-control/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,64 +184,6 @@ export function getSliderValueFromPreset( presetValue, spacingSizes ) {
return sliderValue !== -1 ? sliderValue : NaN;
}

/**
* Gets an items with the most occurrence within an array
* https://stackoverflow.com/a/20762713
*
* @param {Array<any>} arr Array of items to check.
* @return {any} The item with the most occurrences.
*/
function mode( arr ) {
return arr
.sort(
( a, b ) =>
arr.filter( ( v ) => v === a ).length -
arr.filter( ( v ) => v === b ).length
)
.pop();
}

/**
* Gets the 'all' input value from values data.
*
* @param {Object} values Box spacing values
*
* @return {string} The most common value from all sides of box.
*/
export function getAllRawValue( values = {} ) {
return mode( Object.values( values ) );
}

/**
* Checks to determine if values are mixed.
*
* @param {Object} values Box values.
* @param {Array} sides Sides that values relate to.
*
* @return {boolean} Whether values are mixed.
*/
export function isValuesMixed( values = {}, sides = ALL_SIDES ) {
return (
( Object.values( values ).length >= 1 &&
Object.values( values ).length < sides.length ) ||
new Set( Object.values( values ) ).size > 1
);
}

/**
* Checks to determine if values are defined.
*
* @param {Object} values Box values.
*
* @return {boolean} Whether values are defined.
*/
export function isValuesDefined( values ) {
if ( values === undefined || values === null ) {
return false;
}
return Object.values( values ).filter( ( value ) => !! value ).length > 0;
}

/**
* Determines whether a particular axis has support. If no axis is
* specified, this function checks if either axis is supported.
Expand Down Expand Up @@ -275,54 +217,6 @@ export function hasAxisSupport( sides, axis ) {
return hasHorizontalSupport || hasVerticalSupport;
}

/**
* Determines which menu options should be included in the SidePicker.
*
* @param {Array} sides Supported sides.
*
* @return {Object} Menu options with each option containing label & icon.
*/
export function getSupportedMenuItems( sides ) {
if ( ! sides || ! sides.length ) {
return {};
}

const menuItems = {};

// Determine the primary "side" menu options.
const hasHorizontalSupport = hasAxisSupport( sides, 'horizontal' );
const hasVerticalSupport = hasAxisSupport( sides, 'vertical' );

if ( hasHorizontalSupport && hasVerticalSupport ) {
menuItems.axial = { label: LABELS.axial, icon: ICONS.axial };
} else if ( hasHorizontalSupport ) {
menuItems.axial = { label: LABELS.horizontal, icon: ICONS.horizontal };
} else if ( hasVerticalSupport ) {
menuItems.axial = { label: LABELS.vertical, icon: ICONS.vertical };
}

// Track whether we have any individual sides so we can omit the custom
// option if required.
let numberOfIndividualSides = 0;

ALL_SIDES.forEach( ( side ) => {
if ( sides.includes( side ) ) {
numberOfIndividualSides += 1;
menuItems[ side ] = {
label: LABELS[ side ],
icon: ICONS[ side ],
};
}
} );

// Add custom item if there are enough sides to warrant a separated view.
if ( numberOfIndividualSides > 1 ) {
menuItems.custom = { label: LABELS.custom, icon: ICONS.custom };
}

return menuItems;
}

/**
* Checks if the supported sides are balanced for each axis.
* - Horizontal - both left and right sides are supported.
Expand Down
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Internal

- `BoxControl`: Add runtime check for presets and presetKey ([#68385](https://github.com/WordPress/gutenberg/pull/68385)).

## 29.2.0 (2025-01-15)

### Internal
Expand Down
9 changes: 9 additions & 0 deletions packages/components/src/box-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { useInstanceId } from '@wordpress/compose';
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import warning from '@wordpress/warning';

/**
* Internal dependencies
Expand Down Expand Up @@ -166,6 +167,14 @@ function BoxControl( {
} );
const sidesToRender = getAllowedSides( sides );

if ( ( presets && ! presetKey ) || ( ! presets && presetKey ) ) {
const definedProp = presets ? 'presets' : 'presetKey';
const missingProp = presets ? 'presetKey' : 'presets';
warning(
`wp.components.BoxControl: the '${ missingProp }' prop is required when the '${ definedProp }' prop is defined.`
);
}

return (
<Grid
id={ id }
Expand Down
Loading

0 comments on commit e3e67c4

Please sign in to comment.