/** * BLOCK: in5-wp-embed * * Registering a basic block with Gutenberg. * Simple block, renders and saves the same content without any interactivity. */ // Import CSS. import './style.scss'; import './editor.scss'; const {RawHTML} = wp.element; const {__} = wp.i18n; // Import __() from wp.i18n const {registerBlockType} = wp.blocks; // Import registerBlockType() from wp.blocks const {BlockControls, PlainText} = wp.editor; const {withState} = wp.compose; const {Disabled, SandBox, SVG, Path, Button, DropdownMenu} = wp.components; /** * Register: aa Gutenberg Block. * * Registers a new block provided a unique name and an object defining its * behavior. Once registered, the block is made editor as an option to any * editor interface where blocks are implemented. * * @link https://wordpress.org/gutenberg/handbook/block-api/ * @param {string} name Block name. * @param {Object} settings Block settings. * @return {?WPBlock} The block, if it has been successfully * registered; otherwise `undefined`. */ registerBlockType('cgb/block-in5-wp-embed', { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. title: __('in5 Embed'), // Block title. icon: , // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/. category: 'embed', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed. keywords: [ __('in5 Embed'), __('create-guten-block'), ], supports: { html: false, }, attributes: { content: { type: 'string', selector: '.in5-embed-content' }, active: { type: 'string', source: 'attribute', attribute: 'active', }, mode: { type: 'string', selector: '.wp-block-cgb-block-in5-wp-embed', source: 'attribute', attribute: 'data-mode', default: 'edit', } }, /** * The edit function describes the structure of your block in the context of the editor. * This represents what the editor will render when the block is used. * * The "edit" property must be a valid function. * * @link https://wordpress.org/gutenberg/handbook/block-api/block-edit-save/ */ edit: (function ({attributes, className, setAttributes}) { const {content, active, mode} = attributes; const controls = [ { title: __('Edit visually'), icon: 'edit', onClick: () => setAttributes({mode: 'edit'}) }, { title: __('Edit as HTML'), icon: 'html', onClick: () => setAttributes({mode: 'html'}) }, { title: __('Preview'), icon: 'visibility', onClick: () => setAttributes({mode: 'preview'}) } ]; const onChangeContent = function (newContent) { setAttributes({content: newContent}); }; const in5Modal = function () { setAttributes({active: 'open'}); jQuery('.in5-embed-popup').show(); jQuery('.media-modal-backdrop').show(); if (jQuery('.in5-file-list li').length < 1) { jQuery('.in5-library.pane').hide(); jQuery('.in5-upload.pane').show(); jQuery('.tab-library').removeClass('active'); jQuery('.tab-upload').addClass('active'); } }; return (