//edit.js import { __ } from '@wordpress/i18n'; import { useBlockProps, InspectorControls, MediaUpload, MediaUploadCheck, InnerBlocks, useInnerBlocksProps } from '@wordpress/block-editor'; import { PanelBody, Button, ToggleControl, BaseControl, RangeControl, SelectControl } from '@wordpress/components'; import './editor.scss'; const ALLOWED_VIDEO_TYPES = ['video']; const INNER_BLOCKS_TEMPLATE = [ ['core/heading', { level: 1, placeholder: 'Add heading...', textAlign: 'center' }], ['core/paragraph', { placeholder: 'Add description...', align: 'center' }], ['core/buttons', { layout: { type: 'flex', justifyContent: 'center' } }] ]; export default function Edit({ attributes, setAttributes }) { const { posterId, posterUrl, videoSources, fadeEffect, overlayOpacity, contentAlignment, minHeight } = attributes; const blockProps = useBlockProps({ className: 'video-cover-editor', style: { minHeight: minHeight ? `${minHeight}px` : undefined } }); const innerBlocksProps = useInnerBlocksProps( { className: 'video-cover-content' }, { template: INNER_BLOCKS_TEMPLATE, templateLock: false } ); const onSelectPoster = (media) => { setAttributes({ posterId: media.id, posterUrl: media.url }); }; const onSelectVideos = (mediaItems) => { // multiple=true returns an array const items = Array.isArray(mediaItems) ? mediaItems : [mediaItems]; const newSources = items .filter(media => !videoSources.some(s => s.id === media.id)) .map(media => ({ id: media.id, url: media.url, mime: media.mime })); if (newSources.length) { setAttributes({ videoSources: [...videoSources, ...newSources] }); } }; const removeVideoSource = (index) => { const updated = [...videoSources]; updated.splice(index, 1); setAttributes({ videoSources: updated }); }; const renderVideoSourceList = (sources, isMobile = false) => { if (sources.length === 0) return null; return ( ); }; return ( <> ( <> {posterUrl && ( {__('Poster )} {posterUrl && ( )} )} /> {videoSources.length > 0 && (
    {videoSources.map((source, index) => (
  • {source.mime}
  • ))}
)} ( )} />
setAttributes({ fadeEffect: value })} />
setAttributes({ overlayOpacity: value })} min={0} max={100} step={5} /> setAttributes({ contentAlignment: value })} /> setAttributes({ minHeight: value })} min={0} max={1000} step={50} />
{posterUrl || videoSources.length > 0 ? (
{posterUrl && ( <> {__('Video {overlayOpacity > 0 && (
)} )}

{videoSources.length} {__('desktop source(s)', 'jvb')}

) : (

{__('Configure video sources in the sidebar →', 'jvb')}

)}
); }