2021-08-25 15:42:55 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2022-07-29 19:40:03 +00:00
|
|
|
import { miniCartAlt } from '@woocommerce/icons';
|
2022-02-01 16:54:38 +00:00
|
|
|
import { Icon } from '@wordpress/icons';
|
2022-04-08 13:47:19 +00:00
|
|
|
import { registerBlockType } from '@wordpress/blocks';
|
2022-05-30 08:45:15 +00:00
|
|
|
import { isFeaturePluginBuild } from '@woocommerce/block-settings';
|
2023-06-20 20:28:16 +00:00
|
|
|
import { addFilter } from '@wordpress/hooks';
|
2021-08-25 15:42:55 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2023-07-12 14:20:19 +00:00
|
|
|
import metadata from './block.json';
|
2021-08-25 15:42:55 +00:00
|
|
|
import edit from './edit';
|
2023-07-12 14:20:19 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
const featurePluginSupport = {
|
|
|
|
...metadata.supports,
|
|
|
|
...( isFeaturePluginBuild() && {
|
|
|
|
typography: {
|
|
|
|
...metadata.supports.typography,
|
|
|
|
__experimentalFontFamily: true,
|
|
|
|
__experimentalFontWeight: true,
|
|
|
|
},
|
|
|
|
} ),
|
|
|
|
};
|
2021-08-25 15:42:55 +00:00
|
|
|
|
2023-07-12 14:20:19 +00:00
|
|
|
registerBlockType( metadata, {
|
2021-08-25 15:42:55 +00:00
|
|
|
icon: {
|
2021-12-10 14:32:44 +00:00
|
|
|
src: (
|
|
|
|
<Icon
|
2022-07-29 19:40:03 +00:00
|
|
|
icon={ miniCartAlt }
|
2023-06-05 13:36:57 +00:00
|
|
|
className="wc-block-editor-components-block-icon wc-block-editor-mini-cart__icon"
|
2021-12-10 14:32:44 +00:00
|
|
|
/>
|
|
|
|
),
|
2021-08-25 15:42:55 +00:00
|
|
|
},
|
|
|
|
supports: {
|
2023-07-12 14:20:19 +00:00
|
|
|
...featurePluginSupport,
|
2021-08-25 15:42:55 +00:00
|
|
|
},
|
|
|
|
example: {
|
2023-07-12 14:20:19 +00:00
|
|
|
...metadata.example,
|
2021-08-25 15:42:55 +00:00
|
|
|
},
|
|
|
|
attributes: {
|
2023-07-12 14:20:19 +00:00
|
|
|
...metadata.attributes,
|
2021-08-25 15:42:55 +00:00
|
|
|
},
|
|
|
|
edit,
|
|
|
|
save() {
|
|
|
|
return null;
|
|
|
|
},
|
2023-07-12 14:20:19 +00:00
|
|
|
} );
|
2023-06-20 20:28:16 +00:00
|
|
|
|
|
|
|
// Remove the Mini Cart template part from the block inserter.
|
|
|
|
addFilter(
|
|
|
|
'blocks.registerBlockType',
|
|
|
|
'woocommerce/mini-cart',
|
|
|
|
function ( blockSettings, blockName ) {
|
|
|
|
if ( blockName === 'core/template-part' ) {
|
|
|
|
return {
|
|
|
|
...blockSettings,
|
|
|
|
variations: blockSettings.variations.map(
|
|
|
|
( variation: { name: string } ) => {
|
2023-07-18 07:12:43 +00:00
|
|
|
if ( variation.name === 'mini-cart' ) {
|
2023-06-20 20:28:16 +00:00
|
|
|
return {
|
|
|
|
...variation,
|
|
|
|
scope: [],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return variation;
|
|
|
|
}
|
|
|
|
),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return blockSettings;
|
|
|
|
}
|
|
|
|
);
|