import React from 'react';
const wp = window.wp
declare global {
interface Props {}
interface Window {
wp:any,
lodash:any
}
interface Math {
round:(x: number) => number
}
}
const CustomImage:React.FC<{
title:string,attrname:string,attrval:any,className?:any,bgimagesize?:string,setAttributes:any
}> = props => {
const {title,attrname,attrval={},className="",bgimagesize="large",setAttributes=()=>{}} = props;
return (
{attrval.length ? (
) : null}
{title}
{
return (
);
}}
onSelect={(val)=>{
let tempval=[];
if(val instanceof Array) tempval = val;
else tempval.push(val);
let attachment = wp.media.query({post__in:tempval});
let mediapromise = attachment.more();
mediapromise.done(function(){
let apuslides=[],largeslides=[];
if(attachment.props.attributes.post__in.length>0){
attachment.props.attributes.post__in.forEach(function(el){
if(el.sizes.hasOwnProperty('large'))
largeslides.push(el.sizes.large.url);
if(el.sizes.hasOwnProperty(bgimagesize))
apuslides.push(el.sizes[bgimagesize].url);
else apuslides.push(el.url);
});
}
else apuslides=["#"];
setAttributes({[attrname]:apuslides,bgimagearraylarge:largeslides});
});
}}
/>
);
}
export default CustomImage