/** * External dependencies */ import { __ } from '@wordpress/i18n'; import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; import { createInterpolateElement, useEffect } from '@wordpress/element'; import { getAdminLink, getSettingWithCoercion } from '@woocommerce/settings'; import { isBoolean } from '@woocommerce/types'; import type { BlockEditProps } from '@wordpress/blocks'; import { ProductQueryContext as Context } from '@woocommerce/blocks/product-query/types'; import { Disabled, PanelBody, ToggleControl, // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Ignoring because `__experimentalToggleGroupControl` is not yet in the type definitions. // eslint-disable-next-line @wordpress/no-unsafe-wp-apis __experimentalToggleGroupControl as ToggleGroupControl, // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Ignoring because `__experimentalToggleGroupControl` is not yet in the type definitions. // eslint-disable-next-line @wordpress/no-unsafe-wp-apis __experimentalToggleGroupControlOption as ToggleGroupControlOption, } from '@wordpress/components'; /** * Internal dependencies */ import Block from './block'; import withProductSelector from '../shared/with-product-selector'; import { BLOCK_TITLE as label, BLOCK_ICON as icon, BLOCK_DESCRIPTION as description, } from './constants'; import { BlockAttributes, ImageSizing } from './types'; import { ImageSizeSettings } from './image-size-settings'; type SaleBadgeAlignProps = 'left' | 'center' | 'right'; const Edit = ( { attributes, setAttributes, context, }: BlockEditProps< BlockAttributes > & { context: Context } ): JSX.Element => { const { showProductLink, imageSizing, showSaleBadge, saleBadgeAlign, width, height, scale, } = attributes; const blockProps = useBlockProps( { style: { width, height } } ); const isDescendentOfQueryLoop = Number.isFinite( context.queryId ); const isBlockThemeEnabled = getSettingWithCoercion( 'isBlockThemeEnabled', false, isBoolean ); useEffect( () => setAttributes( { isDescendentOfQueryLoop } ), [ setAttributes, isDescendentOfQueryLoop ] ); return (