|
|
@ -1,4 +1,5 @@ |
|
|
|
import React, { useEffect, useState } from 'react' |
|
|
|
import { CustomTooltip } from '@remix-ui/helper' |
|
|
|
|
|
|
|
import React, { Fragment, useEffect, useState } from 'react' |
|
|
|
import { TransformComponent, TransformWrapper } from 'react-zoom-pan-pinch' |
|
|
|
import { TransformComponent, TransformWrapper } from 'react-zoom-pan-pinch' |
|
|
|
import { ISolidityUmlGen } from '../types' |
|
|
|
import { ISolidityUmlGen } from '../types' |
|
|
|
import './css/solidity-uml-gen.css' |
|
|
|
import './css/solidity-uml-gen.css' |
|
|
@ -6,12 +7,15 @@ export interface RemixUiSolidityUmlGenProps { |
|
|
|
plugin?: ISolidityUmlGen |
|
|
|
plugin?: ISolidityUmlGen |
|
|
|
updatedSvg?: string |
|
|
|
updatedSvg?: string |
|
|
|
loading?: boolean |
|
|
|
loading?: boolean |
|
|
|
|
|
|
|
themeSelected?: string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type ButtonAction = { |
|
|
|
type ButtonAction = { |
|
|
|
svgValid: () => boolean |
|
|
|
svgValid: () => boolean |
|
|
|
action: () => void |
|
|
|
action: () => void |
|
|
|
buttonText: string |
|
|
|
buttonText: string |
|
|
|
|
|
|
|
icon?: string |
|
|
|
|
|
|
|
customcss?: string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface ActionButtonsProps { |
|
|
|
interface ActionButtonsProps { |
|
|
@ -21,19 +25,26 @@ interface ActionButtonsProps { |
|
|
|
const ActionButtons = ({ buttons }: ActionButtonsProps) => ( |
|
|
|
const ActionButtons = ({ buttons }: ActionButtonsProps) => ( |
|
|
|
<> |
|
|
|
<> |
|
|
|
{buttons.map(btn => ( |
|
|
|
{buttons.map(btn => ( |
|
|
|
<button |
|
|
|
<CustomTooltip |
|
|
|
key={btn.buttonText} |
|
|
|
key={btn.buttonText} |
|
|
|
className="btn btn-primary btn-md ml-4 mt-4" |
|
|
|
placement="top" |
|
|
|
disabled={!btn.svgValid} |
|
|
|
tooltipText={btn.buttonText} |
|
|
|
onClick={btn.action} |
|
|
|
tooltipId={btn.buttonText} |
|
|
|
> |
|
|
|
> |
|
|
|
{btn.buttonText} |
|
|
|
<button |
|
|
|
</button> |
|
|
|
key={btn.buttonText} |
|
|
|
|
|
|
|
className={`btn btn-primary btn-sm rounded-circle ${btn.customcss}`} |
|
|
|
|
|
|
|
disabled={!btn.svgValid} |
|
|
|
|
|
|
|
onClick={btn.action} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<i className={btn.icon}></i> |
|
|
|
|
|
|
|
</button> |
|
|
|
|
|
|
|
</CustomTooltip> |
|
|
|
))} |
|
|
|
))} |
|
|
|
</> |
|
|
|
</> |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
export function RemixUiSolidityUmlGen ({ plugin, updatedSvg, loading }: RemixUiSolidityUmlGenProps) { |
|
|
|
export function RemixUiSolidityUmlGen ({ plugin, updatedSvg, loading, themeSelected }: RemixUiSolidityUmlGenProps) { |
|
|
|
const [showViewer, setShowViewer] = useState(false) |
|
|
|
const [showViewer, setShowViewer] = useState(false) |
|
|
|
const [svgPayload, setSVGPayload] = useState<string>('') |
|
|
|
const [svgPayload, setSVGPayload] = useState<string>('') |
|
|
|
const [validSvg, setValidSvg] = useState(false) |
|
|
|
const [validSvg, setValidSvg] = useState(false) |
|
|
@ -50,12 +61,14 @@ export function RemixUiSolidityUmlGen ({ plugin, updatedSvg, loading }: RemixUiS |
|
|
|
{
|
|
|
|
{
|
|
|
|
buttonText: 'Download as PDF', |
|
|
|
buttonText: 'Download as PDF', |
|
|
|
svgValid: () => validSvg, |
|
|
|
svgValid: () => validSvg, |
|
|
|
action: () => console.log('generated!!') |
|
|
|
action: () => console.log('generated!!'), |
|
|
|
|
|
|
|
icon: 'fa mr-1 pt-1 pb-1 fa-file' |
|
|
|
}, |
|
|
|
}, |
|
|
|
{
|
|
|
|
{
|
|
|
|
buttonText: 'Download as PNG', |
|
|
|
buttonText: 'Download as PNG', |
|
|
|
svgValid: () => validSvg, |
|
|
|
svgValid: () => validSvg, |
|
|
|
action: () => console.log('generated!!') |
|
|
|
action: () => console.log('generated!!'), |
|
|
|
|
|
|
|
icon: 'fa fa-picture-o' |
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
@ -66,28 +79,42 @@ export function RemixUiSolidityUmlGen ({ plugin, updatedSvg, loading }: RemixUiS |
|
|
|
<h3 className="h4 align-self-start"><p>Click on Generate UML</p></h3> |
|
|
|
<h3 className="h4 align-self-start"><p>Click on Generate UML</p></h3> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
) |
|
|
|
) |
|
|
|
const Display = () => ( |
|
|
|
const Display = () => { |
|
|
|
|
|
|
|
const invert = themeSelected === 'dark' ? 'invert(1)' : 'invert(0)' |
|
|
|
|
|
|
|
return ( |
|
|
|
<div className="d-flex flex-column justify-content-center align-items-center"> |
|
|
|
<div className="d-flex flex-column justify-content-center align-items-center"> |
|
|
|
<div className="d-flex justify-center align-content-center mb-5"> |
|
|
|
<div id="umlImageHolder"> |
|
|
|
{/* <ActionButtons buttons={buttons}/> */} |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
<div id="umlImageHolder" className="justify-content-center align-items-center d-flex w-100"> |
|
|
|
|
|
|
|
{ validSvg && showViewer ? ( |
|
|
|
{ validSvg && showViewer ? ( |
|
|
|
<TransformWrapper> |
|
|
|
<TransformWrapper |
|
|
|
<TransformComponent> |
|
|
|
initialScale={1} |
|
|
|
<img
|
|
|
|
> |
|
|
|
src={`data:image/svg+xml;base64,${btoa(plugin.updatedSvg ?? svgPayload)}`} |
|
|
|
{ |
|
|
|
width={900} |
|
|
|
({ zoomIn, zoomOut, resetTransform }) => ( |
|
|
|
height={'auto'} |
|
|
|
<Fragment> |
|
|
|
/> |
|
|
|
<div className="position-relative"> |
|
|
|
</TransformComponent> |
|
|
|
<button className="btn position-absolute top-0 end-100 translate-middle btn-sm mr-1 rounded-circle btn-success" onClick={() => zoomIn()}>+</button> |
|
|
|
|
|
|
|
<button className="btn position-absolute top-0 end-100 translate-middle btn-sm mr-1 rounded-circle btn-warning" onClick={() => zoomOut()}>-</button> |
|
|
|
|
|
|
|
<button className="btn position-absolute top-0 end-100 translate-middle btn-sm mr-1 rounded-circle btn-danger" onClick={() => resetTransform()}>X</button> |
|
|
|
|
|
|
|
<ActionButtons buttons={buttons}/> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
<TransformComponent> |
|
|
|
|
|
|
|
<img
|
|
|
|
|
|
|
|
src={`data:image/svg+xml;base64,${btoa(plugin.updatedSvg ?? svgPayload)}`} |
|
|
|
|
|
|
|
width={950} |
|
|
|
|
|
|
|
height={'auto'} |
|
|
|
|
|
|
|
style={{ filter: invert }} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
</TransformComponent> |
|
|
|
|
|
|
|
</Fragment> |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
</TransformWrapper> |
|
|
|
</TransformWrapper> |
|
|
|
) : loading ? <div className="justify-content-center align-items-center d-flex mx-auto my-auto"> |
|
|
|
) : loading ? <div className="justify-content-center align-items-center d-flex mx-auto my-auto"> |
|
|
|
<i className="fas fa-spinner fa-spin fa-4x"></i> |
|
|
|
<i className="fas fa-spinner fa-spin fa-4x"></i> |
|
|
|
</div> : <DefaultInfo />} |
|
|
|
</div> : <DefaultInfo />} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
) |
|
|
|
)} |
|
|
|
return (<> |
|
|
|
return (<> |
|
|
|
{ <Display /> } |
|
|
|
{ <Display /> } |
|
|
|
</> |
|
|
|
</> |
|
|
|