2022-08-18 08:02:21 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2022-11-02 16:46:14 +00:00
|
|
|
import type { Block } from '@wordpress/blocks';
|
2022-08-18 08:02:21 +00:00
|
|
|
import { addFilter } from '@wordpress/hooks';
|
2023-01-05 21:23:34 +00:00
|
|
|
import { isWpVersion } from '@woocommerce/settings';
|
2022-08-18 08:02:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2022-12-05 15:56:53 +00:00
|
|
|
import { CORE_NAME as PRODUCT_TITLE_ID } from './variations/elements/product-title';
|
2022-12-05 16:25:13 +00:00
|
|
|
import { CORE_NAME as PRODUCT_SUMMARY_ID } from './variations/elements/product-summary';
|
2022-12-30 15:51:27 +00:00
|
|
|
import { CORE_NAME as PRODUCT_TEMPLATE_ID } from './variations/elements/product-template';
|
2022-08-18 08:02:21 +00:00
|
|
|
import './inspector-controls';
|
2022-12-05 12:46:50 +00:00
|
|
|
import './style.scss';
|
2022-08-18 08:02:21 +00:00
|
|
|
import './variations/product-query';
|
|
|
|
|
2022-12-30 15:51:27 +00:00
|
|
|
const EXTENDED_CORE_ELEMENTS = [
|
|
|
|
PRODUCT_SUMMARY_ID,
|
|
|
|
PRODUCT_TEMPLATE_ID,
|
|
|
|
PRODUCT_TITLE_ID,
|
|
|
|
];
|
2022-12-05 15:56:53 +00:00
|
|
|
|
|
|
|
function registerProductQueryElementsNamespace(
|
2022-08-18 08:02:21 +00:00
|
|
|
props: Block,
|
|
|
|
blockName: string
|
|
|
|
) {
|
2022-12-05 15:56:53 +00:00
|
|
|
if ( EXTENDED_CORE_ELEMENTS.includes( blockName ) ) {
|
2022-08-18 08:02:21 +00:00
|
|
|
// Gracefully handle if settings.attributes is undefined.
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
// @ts-ignore -- We need this because `attributes` is marked as `readonly`
|
|
|
|
props.attributes = {
|
|
|
|
...props.attributes,
|
2022-12-05 15:56:53 +00:00
|
|
|
__woocommerceNamespace: {
|
|
|
|
type: 'string',
|
2022-08-18 08:02:21 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2022-12-05 15:56:53 +00:00
|
|
|
|
2022-08-18 08:02:21 +00:00
|
|
|
return props;
|
|
|
|
}
|
|
|
|
|
2023-01-05 21:23:34 +00:00
|
|
|
if ( isWpVersion( '6.1', '>=' ) ) {
|
|
|
|
addFilter(
|
|
|
|
'blocks.registerBlockType',
|
|
|
|
'core/custom-class-name/attribute',
|
|
|
|
registerProductQueryElementsNamespace
|
|
|
|
);
|
|
|
|
}
|