Tinkering with rendering an inner block

This commit is contained in:
Sam Seay 2024-09-11 20:35:56 +08:00
parent f8a5c745ac
commit 6172ccb498
No known key found for this signature in database
GPG Key ID: 2223711A9151668A
2 changed files with 12 additions and 9 deletions

View File

@ -25,6 +25,8 @@ import {
getMiniCartTotalsFromServer, getMiniCartTotalsFromServer,
} from './utils/data'; } from './utils/data';
import setStyles from '../mini-cart/utils/set-styles'; import setStyles from '../mini-cart/utils/set-styles';
import { getMiniCartContentsBlockMap } from './render-mini-cart-contents';
import { FilledMiniCartContentsBlock } from './mini-cart-contents/inner-blocks/filled-mini-cart-contents-block/frontend';
interface dependencyData { interface dependencyData {
src: string; src: string;
@ -163,15 +165,12 @@ const { state } = store< Store >( 'woocommerce/mini-cart-interactivity', {
components: { components: {
BlockComponent: () => { BlockComponent: () => {
return ( { children, ...props } ) => { return ( { children, ...props } ) => {
const timems = Date.now(); console.log( 'props', props );
return h(
console.log( props ); FilledMiniCartContentsBlock,
{ className: props.class, ...props },
// manually add child text to children children
const childText = h( 'p', {}, 'MiniCartContents: ' + timems ); );
const newChildren = [ ...children, childText ];
return h( 'div', { ...props }, newChildren );
}; };
}, },
}, },

View File

@ -18,6 +18,10 @@ const generateUniqueId = () => {
); );
}; };
export const getMiniCartContentsBlockMap = () => {
return getRegisteredBlockComponents( 'woocommerce/mini-cart-contents' );
};
// We load this async so that we don't have to load the mini-cart block. // We load this async so that we don't have to load the mini-cart block.
export const renderMiniCartContents = ( templateElement: HTMLDivElement ) => { export const renderMiniCartContents = ( templateElement: HTMLDivElement ) => {
const clonedTemplateNode = templateElement.cloneNode( const clonedTemplateNode = templateElement.cloneNode(