Skip to content
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
11 changes: 10 additions & 1 deletion packages/blocks/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,17 @@ export interface TypographyProps {
export interface SpacingProps {
/**
* Enable block gap control.
*
* The object form declares the sides the control applies to, and the gap
* value to fall back to when neither the theme nor the user has set one.
*/
blockGap: boolean | AxialDirection[];
blockGap:
| boolean
| AxialDirection[]
| {
__experimentalDefault?: string;
sides?: AxialDirection[];
};

/**
* Enable margin control UI for all or specified element directions.
Expand Down
10 changes: 8 additions & 2 deletions packages/components/src/icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export type IconType =
| ( ( props: { size?: number } ) => React.JSX.Element )
| React.JSX.Element;

/* The sizing props forwarded to an icon element that is not an `SVG` or a `Dashicon`. */
type SizeProps = {
size?: number;
width?: number | string;
height?: number | string;
};

type AdditionalProps< T > = T extends ComponentType< infer U >
? U
: T extends DashiconIconKey
Expand Down Expand Up @@ -103,9 +110,8 @@ function Icon( {
return <SVG { ...appliedProps } />;
}

if ( isValidElement( icon ) ) {
if ( isValidElement< SizeProps >( icon ) ) {
return cloneElement( icon, {
// @ts-expect-error `size` is forwarded but is not in the icon component overloads.
size,
width: size,
height: size,
Expand Down
3 changes: 1 addition & 2 deletions packages/components/src/input-control/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ export function useDragCursor(
if ( isDragging ) {
document.documentElement.style.cursor = dragCursor;
} else {
// @ts-expect-error `cursor` is typed as `string`, but `null` clears it.
document.documentElement.style.cursor = null;
document.documentElement.style.removeProperty( 'cursor' );
}
}, [ isDragging, dragCursor ] );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,15 @@ export function PropertiesSection( {
},
].filter( ( { field } ) => isDefined( field ) ) as Array< {
field: NormalizedField< any >;
isVisibleFlag: string;
isVisibleFlag: 'showTitle' | 'showMedia' | 'showDescription';
} >;
const visibleFieldIds = view.fields ?? [];
const visibleRegularFieldsCount = regularFields.filter( ( f ) =>
visibleFieldIds.includes( f.id )
).length;

const visibleLockedFields = lockedFields.filter(
( { isVisibleFlag } ) =>
// @ts-expect-error A string key cannot index `View`.
view[ isVisibleFlag ] ?? true
( { isVisibleFlag } ) => view[ isVisibleFlag ] ?? true
);

// If only one field (locked or regular) is visible, prevent it from being hidden
Expand All @@ -112,7 +110,6 @@ export function PropertiesSection( {
>
<ItemGroup isBordered isSeparated size="medium">
{ lockedFields.map( ( { field, isVisibleFlag } ) => {
// @ts-expect-error A string key cannot index `View`.
const isVisible = view[ isVisibleFlag ] ?? true;
const fieldToRender =
isSingleVisibleLockedField && isVisible
Expand Down
7 changes: 5 additions & 2 deletions packages/global-styles-engine/src/core/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1921,9 +1921,12 @@ export const getBlockSelectors = (
const hasLayoutSupport =
!! blockType?.supports?.layout ||
!! blockType?.supports?.__experimentalLayout;
const blockGapSupport = blockType?.supports?.spacing?.blockGap;
const fallbackGapValue =
// @ts-expect-error `blockGap` support is typed as `boolean | AxialDirection[]`.
blockType?.supports?.spacing?.blockGap?.__experimentalDefault;
typeof blockGapSupport === 'object' &&
! Array.isArray( blockGapSupport )
? blockGapSupport.__experimentalDefault
: undefined;

const blockStyleVariations = getBlockStyles( name );
const styleVariationSelectors: Record< string, string > = {};
Expand Down
22 changes: 20 additions & 2 deletions packages/global-styles-engine/src/utils/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,29 @@ export const BACKGROUND_BLOCK_DEFAULT_VALUES = {
backgroundPosition: '50% 50%', // used only when backgroundSize is 'contain'.
};

/**
* Whether a background image resolves to a URL, as opposed to a reference or an
* unresolved value.
*
* @param backgroundImage The background image value.
*
* @return Whether the value carries a URL.
*/
function hasImageUrl(
backgroundImage: BackgroundStyle[ 'backgroundImage' ]
): backgroundImage is { url: string } {
return (
typeof backgroundImage === 'object' &&
backgroundImage !== null &&
'url' in backgroundImage &&
!! backgroundImage.url
);
}

export function setBackgroundStyleDefaults( backgroundStyle: BackgroundStyle ) {
if (
! backgroundStyle ||
// @ts-expect-error `backgroundImage` is a union whose other members have no `url`.
! backgroundStyle?.backgroundImage?.url
! hasImageUrl( backgroundStyle.backgroundImage )
) {
return;
}
Expand Down
Loading