HEX
Server: Apache/2.4.59 (Debian)
System: Linux skycube.cz 4.19.0-25-amd64 #1 SMP Debian 4.19.289-2 (2023-08-08) x86_64
User: ilya (534)
PHP: 7.3.31-1~deb10u7
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /var/www/ilya/data/www/rudomilov.ru/wp-content/plugins/widget-logic/block_widget/js/widget.js
const { registerBlockType } = wp.blocks;
const { Fragment: FragmentMy, createElement } = wp.element;
const { RichText, InnerBlocks, useBlockProps } = wp.blockEditor;
const { __: __My } = wp.i18n;

registerBlockType('widget-logic/widget-block', {
    attributes: {
        title: {
            type: 'string',
            source: 'text',
            selector: 'h2',
            default: 'Live Match'
        },
        imageUrl: {
            type: 'string',
            default: myPluginBlockImageUrl
        }
    },
    example: {
        attributes: {
            preview: true,
            title: 'Live Match',
            imageUrl: myPluginBlockImageUrl // this variable defined in PHP
        }
    },
    edit: props => {
        const blockProps = useBlockProps();
        if (props.isSelected === false) {
            return wp.element.createElement(
                'div',
                blockProps,
                wp.element.createElement('img', {
                    src: props.attributes.imageUrl,
                    alt: 'Preview',
                    style: { width: '100%', 'max-width':'350px', height: 'auto' }
                })
            );
        }

        return createElement(
            FragmentMy,
            null,
            createElement(
                'div',
                blockProps,
                createElement(RichText, {
                    tagName: 'h2',
                    value: props.attributes.title,
                    onChange: title => props.setAttributes({ title }),
                    placeholder: __My('Live Match title', 'widget-logic')
                }),
            ),
            createElement(
                'div',
                { className: 'widget-logic-widget-widget-content' },
                createElement(InnerBlocks, null)
            )
        );
    },
    save: props => {
        return createElement(
            'div',
            { className: 'wp-block-widget-logic-widget-block widget-logic-widget-widget-container' },
            createElement(RichText.Content, { tagName: 'h2', value: props.attributes.title }),
            createElement(
                'div',
                { className: 'widget-logic-widget-widget-content' },
                createElement(
                    'div',
                    { 'data-place': 'widget-live-match' },
                    __My('Live Match will be here', 'widget-logic')
                ),
                createElement(InnerBlocks.Content, null)
            )
        );
    }
});