2021-09-21 10:18:27 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { useBlockProps, InnerBlocks } from '@wordpress/block-editor';
|
|
|
|
import { Main } from '@woocommerce/base-components/sidebar-layout';
|
|
|
|
import { innerBlockAreas } from '@woocommerce/blocks-checkout';
|
2021-10-15 09:48:57 +00:00
|
|
|
import type { TemplateArray } from '@wordpress/blocks';
|
2021-09-21 10:18:27 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2022-04-05 10:14:32 +00:00
|
|
|
import {
|
|
|
|
useForcedLayout,
|
|
|
|
getAllowedBlocks,
|
2022-04-07 13:47:58 +00:00
|
|
|
} from '../../../cart-checkout-shared';
|
2021-09-21 10:18:27 +00:00
|
|
|
|
|
|
|
export const Edit = ( { clientId }: { clientId: string } ): JSX.Element => {
|
2021-10-25 15:31:22 +00:00
|
|
|
const blockProps = useBlockProps( { className: 'wc-block-cart__main' } );
|
2021-09-21 10:18:27 +00:00
|
|
|
const allowedBlocks = getAllowedBlocks( innerBlockAreas.CART_ITEMS );
|
2021-10-15 09:48:57 +00:00
|
|
|
const defaultTemplate = [
|
|
|
|
[ 'woocommerce/cart-line-items-block', {}, [] ],
|
|
|
|
] as TemplateArray;
|
2021-09-21 10:18:27 +00:00
|
|
|
|
|
|
|
useForcedLayout( {
|
|
|
|
clientId,
|
2021-10-15 09:48:57 +00:00
|
|
|
registeredBlocks: allowedBlocks,
|
|
|
|
defaultTemplate,
|
2021-09-21 10:18:27 +00:00
|
|
|
} );
|
|
|
|
return (
|
2021-10-25 15:31:22 +00:00
|
|
|
<Main { ...blockProps }>
|
|
|
|
<InnerBlocks
|
|
|
|
allowedBlocks={ allowedBlocks }
|
|
|
|
template={ defaultTemplate }
|
|
|
|
templateLock={ false }
|
|
|
|
renderAppender={ InnerBlocks.ButtonBlockAppender }
|
|
|
|
/>
|
2021-09-21 10:18:27 +00:00
|
|
|
</Main>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Save = (): JSX.Element => {
|
|
|
|
return (
|
|
|
|
<div { ...useBlockProps.save() }>
|
|
|
|
<InnerBlocks.Content />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|