editor.BlockListBlock筛选器未将BlockListBlock传递给Function

时间:2019-07-19 14:26:59

标签: wordpress reactjs wordpress-gutenberg gutenberg-blocks create-guten-block

当我在define( 'SCRIPT_DEBUG', true );中有wp-config.php时,通过调用此钩子editor.BlockListBlock可以收到正确的对象。当我有define( 'SCRIPT_DEBUG', false );或未定义时,我收到错误的对象。

const { createHigherOrderComponent } = wp.compose;

const withClientIdClassName = createHigherOrderComponent( ( BlockListBlock ) => {
// BlockListBlock returns as "WithSelect" with debug off
// and returns as the correct component with debug on
    console.log(BlockListBlock);
    return ( props ) => {
    const {attributes, name} = props;
        if(name === 'project/block-name'){
            return <BlockListBlock { ...props } className={'classes-i-want-on-this'} />;
        } else {
            return <BlockListBlock { ...props } />;
        }

    };
}, 'withClientIdClassName' );

wp.hooks.addFilter( 'editor.BlockListBlock', 'classNames-for-cells', withClientIdClassName );

未定义SCRIPT_DEBUG或为假

enter image description here

SCRIPT_DEBUG为真

enter image description here

我用它来启动我的项目 https://github.com/ahmadawais/create-guten-block

0 个答案:

没有答案