//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 (
{videoSources.length} {__('desktop source(s)', 'jvb')}
{__('Configure video sources in the sidebar →', 'jvb')}