/* eslint-disable @typescript-eslint/ban-ts-comment */
/**
* External dependencies
*/
import { store as blockEditorStore, Warning } from '@wordpress/block-editor';
import { useDispatch, useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { Icon, search } from '@wordpress/icons';
import { getSettingWithCoercion } from '@woocommerce/settings';
import { isBoolean } from '@woocommerce/types';
import { Button } from '@wordpress/components';
import {
// @ts-ignore waiting for @types/wordpress__blocks update
registerBlockVariation,
registerBlockType,
createBlock,
} from '@wordpress/blocks';
/**
* Internal dependencies
*/
import './style.scss';
import './editor.scss';
import Block from './block.js';
import Edit from './edit.js';
const isBlockVariationAvailable = getSettingWithCoercion(
'isBlockVariationAvailable',
false,
isBoolean
);
const attributes = {
/**
* Whether to show the field label.
*/
hasLabel: {
type: 'boolean',
default: true,
},
/**
* Search field label.
*/
label: {
type: 'string',
default: __( 'Search', 'woo-gutenberg-products-block' ),
},
/**
* Search field placeholder.
*/
placeholder: {
type: 'string',
default: __( 'Search products…', 'woo-gutenberg-products-block' ),
},
/**
* Store the instance ID.
*/
formId: {
type: 'string',
default: '',
},
};
const PRODUCT_SEARCH_ATTRIBUTES = {
label: attributes.label.default,
buttonText: attributes.label.default,
placeholder: attributes.placeholder.default,
query: {
post_type: 'product',
},
};
const DeprecatedBlockEdit = ( { clientId }: { clientId: string } ) => {
// @ts-ignore @wordpress/block-editor/store types not provided
const { replaceBlocks } = useDispatch( blockEditorStore );
const currentBlockAttributes = useSelect(
( select ) =>
select( 'core/block-editor' ).getBlockAttributes( clientId ),
[ clientId ]
);
const updateBlock = () => {
replaceBlocks(
clientId,
createBlock( 'core/search', {
label:
currentBlockAttributes?.label ||
PRODUCT_SEARCH_ATTRIBUTES.label,
buttonText: PRODUCT_SEARCH_ATTRIBUTES.buttonText,
placeholder:
currentBlockAttributes?.placeholder ||
PRODUCT_SEARCH_ATTRIBUTES.placeholder,
query: PRODUCT_SEARCH_ATTRIBUTES.query,
} )
);
};
const actions = [
,
];
return (