import React from "react" import {TbResize} from 'react-icons/tb' import {BiCube, BiRefresh} from 'react-icons/bi' import {BsTrash, BsArrowDownRightSquare} from 'react-icons/bs' import {CgLayoutGridSmall} from 'react-icons/cg' import '../../css/counter.css' const MINIMUM_HEIGHT = 600; const MINIMUM_WIDTH = 540; export default class CustomNodeIframe extends React.Component { constructor({id , data}){ super() this.myRef = React.createRef() this.original_width = 0; this.original_height = 0; this.original_x = 0; this.original_y = 0; this.original_mouse_x = 0; this.original_mouse_y = 0; this.state = { id : id, reachable : this.isFetchable(data.host), selected : true, data : data, width : 540, height : 600, size : true, iframe : 0, } } handelSelected = () => { this.setState({'selected' : !this.state.selected}) } handelSizeState = () => { this.setState({'size' : !this.state.size}) } isFetchable = async (host) => { fetch(host, {mode: 'no-cors'}).then((re) => { return true }).catch((err)=>{ return false }) return false } onNodeClick = (id) => { this.state.data.delete(id) } onRefresh(){ if(!this.isFetchable(this.state.data.host)){ this.onNodeClick(this.state.id) } else{ this.setState({'iframe' : this.state.iframe + 1}) } } handelOnChange(evt, type){ this.setState({[`${type}`] : parseInt(evt.target.value) }) type === "width" ? this.myRef.current.style.width = `${parseInt(evt.target.value)}px` : this.myRef.current.style.height = `${parseInt(evt.target.value)}px` } handelSize(evt, increment, change){ if (evt === "increment") { this.setState({[`${change}`] : change === "width" ? this.state.width + increment : this.state.height + increment }) change === "width" ? this.myRef.current.style.width = `${this.state.width + increment}px` : this.myRef.current.style.height = `${this.state.height + increment}px` } } //resize nodes by dragging initial = (e) => { this.original_width = this.myRef.current.offsetWidth this.original_height = this.myRef.current.offsetHeight this.original_x = this.myRef.current.getBoundingClientRect().left; this.original_y = this.myRef.current.getBoundingClientRect().top; this.original_mouse_x = e.clientX this.original_mouse_y = e.clientY } resize = (e, point) => { var height = 0; var width = 0; // e.dataTransfer.setDragImage(new Image(), 0, 0) if (point === 'bottom-right'){ width = this.original_width + (e.clientX - this.original_mouse_x); height = this.original_height + (e.clientY - this.original_mouse_y) if (width > MINIMUM_WIDTH) { this.myRef.current.style.width = `${width}px` this.setState({'width' : parseInt(width) , 'height' : parseInt(height)}) } if (height > MINIMUM_HEIGHT) { this.myRef.current.style.height = `${height}px` this.setState({'width' : parseInt(width) , 'height' : parseInt(height)}) } } } OnDragEnd = () => { this.setState({'width' : parseInt(this.myRef.current.offsetWidth), 'height' : parseInt(this.myRef.current.offsetHeight)}) } Counter(focus, size){ return (