import * as React from "react"; import {VideoUploader} from "./VideoUploader"; import {VideoControl} from "./VideoControl"; let Placeholder=wp.components.Placeholder; let InspectorControls=wp.blocks.InspectorControls; let CheckboxControl=wp.components.CheckboxControl; let BlockControls=wp.blocks.BlockControls; let BlockAlignment=wp.blocks.BlockAlignmentToolbar; let Toolbar=wp.components.Toolbar; export class AdvanceVideoDesign extends React.Component,AdvanceVideoDesignState>{ constructor(props:any){ super(props); this.ResetSize=this.ResetSize.bind(this); this.VideoSelected=this.VideoSelected.bind(this); this.state={ src:this.props.attributes.src, id:this.props.attributes.id, fileUrl:this.props.attributes.fileUrl } } async componentDidMount() { if (this.props.attributes.id==null&&this.props.attributes.fileUrl!=null && this.props.attributes.fileUrl.indexOf( 'blob:' ) === 0 ) { let file:any=await fetch(this.props.attributes.fileUrl); let blob=await file.blob(); // file=new File([blob],this.props.attributes.fileName); //file.type=blob.type; let media=await wp.utils.mediaUpload([blob],([video])=>{ if(video.id==null) return; this.props.setAttributes({ src: video.url, id:video.id }); },'video'); } } render(){ let element=null; if(this.props.attributes.id==null&&this.props.attributes.fileUrl!=null) { return (
); } if(this.props.attributes.src==null) element= ( ); else { let style:any={width:'100%',height:'100%'}; if(this.props.attributes.width>=0) style.width=this.props.attributes.width; if(this.props.attributes.height>=0) style.height=this.props.attributes.height; element = ( ); } return [ this.props.isSelected&& {this.props.setAttributes({showControls:e})}}> {this.props.setAttributes({autoPlay:e})}}> {this.props.setAttributes({loop:e})}}> , this.GetBlockControls(), element ] } private VideoSelected(media:MediaData) { this.setState({ src:this.props.attributes.src, id:this.props.attributes.id }) } private GetBlockControls() { if(this.props.attributes.width>=0||this.props.attributes.height>=0) { return ( {this.props.setAttributes({align:e})}}> ); } return null; } private ResetSize(){ this.props.setAttributes({ width:-1, height:-1, align:'' }); } } export interface AdvanceVideoDesignState{ }