From e236acdf286a3d9ed1229b94e5cf7639278e1155 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Mon, 30 Jan 2023 14:44:30 +0100 Subject: [PATCH] add types and defaults. --- .../src/app/plugins/solidity-umlgen.tsx | 41 +++++++++- apps/remix-ide/src/app/tabs/theme-module.js | 4 +- .../src/lib/solidity-uml-gen.tsx | 75 +++++++++++++------ .../theme-module/types/theme-module.ts | 2 +- 4 files changed, 94 insertions(+), 28 deletions(-) diff --git a/apps/remix-ide/src/app/plugins/solidity-umlgen.tsx b/apps/remix-ide/src/app/plugins/solidity-umlgen.tsx index aaf8ac96e0..b5380c4c33 100644 --- a/apps/remix-ide/src/app/plugins/solidity-umlgen.tsx +++ b/apps/remix-ide/src/app/plugins/solidity-umlgen.tsx @@ -27,7 +27,9 @@ export class SolidityUmlGen extends ViewPlugin implements ISolidityUmlGen { currentFile: string svgPayload: string updatedSvg: string + currentlySelectedTheme: string loading: boolean + appManager: RemixAppManager dispatch: React.Dispatch = () => {} constructor(appManager: RemixAppManager) { @@ -36,6 +38,7 @@ export class SolidityUmlGen extends ViewPlugin implements ISolidityUmlGen { this.svgPayload = '' this.updatedSvg = '' this.loading = false + this.currentlySelectedTheme = 'dark' this.appManager = appManager this.element = document.createElement('div') this.element.setAttribute('id', 'sol-uml-gen') @@ -50,13 +53,42 @@ export class SolidityUmlGen extends ViewPlugin implements ISolidityUmlGen { result = await this.flattenContract(source, this.currentFile, data) } const ast = result.length > 1 ? parser.parse(result) : parser.parse(source.sources[this.currentFile].content) - const payload = vizRenderStringSync(convertUmlClasses2Dot(convertAST2UmlClasses(ast, this.currentFile))) + const umlClasses = convertAST2UmlClasses(ast, this.currentFile) + const umlDot = convertUmlClasses2Dot(umlClasses) + const payload = vizRenderStringSync(umlDot) + // const splitArtifact = payload.split('\n') + // const modified = splitArtifact[1].replace(/ { + console.log('theme changed', {theme}) + this.currentlySelectedTheme = theme.quality + this.renderComponent() + }) + } + + async mangleSvgPayload(svgPayload: string) : Promise { + const parser = new DOMParser() + const themeQuality = await this.call('theme', 'currentTheme') + const parsedDocument = parser.parseFromString(svgPayload, 'image/svg+xml') + // const svgElement = parsedDocument.getElementsByTagName('polygon')[0] + // svgElement.style.filter = themeQuality.quality === 'dark' ? 'invert(1)' : 'invert(0)' + const res = parsedDocument.documentElement + parsedDocument.bgColor = '#cccabc' + res.style.filter = themeQuality.quality === 'dark' ? 'invert(1)' : 'invert(0)' + const stringifiedSvg = new XMLSerializer().serializeToString(parsedDocument) + // themeQuality.quality === 'dark' ? svgElement.style.background = '#cccabc' : 'invert(0)' + console.log({ parsedDocument, themeQuality, stringifiedSvg }) + return stringifiedSvg } onDeactivation(): void { @@ -115,7 +147,12 @@ export class SolidityUmlGen extends ViewPlugin implements ISolidityUmlGen { } renderComponent () { - this.dispatch({...this, updatedSvg: this.updatedSvg, loading: this.loading }) + this.dispatch({ + ...this, + updatedSvg: this.updatedSvg, + loading: this.loading, + themeSelected: this.currentlySelectedTheme + }) } updateComponent(state: any) { diff --git a/apps/remix-ide/src/app/tabs/theme-module.js b/apps/remix-ide/src/app/tabs/theme-module.js index 2f163a7ea4..698e8956fc 100644 --- a/apps/remix-ide/src/app/tabs/theme-module.js +++ b/apps/remix-ide/src/app/tabs/theme-module.js @@ -53,7 +53,9 @@ export class ThemeModule extends Plugin { this.forced = !!queryTheme } - /** Return the active theme */ + /** Return the active theme + * @return {{ name: string, quality: string, url: string }} - The active theme + */ currentTheme () { return this.themes[this.active] } diff --git a/libs/remix-ui/solidity-uml-gen/src/lib/solidity-uml-gen.tsx b/libs/remix-ui/solidity-uml-gen/src/lib/solidity-uml-gen.tsx index 480f6ded26..2c16167d4c 100644 --- a/libs/remix-ui/solidity-uml-gen/src/lib/solidity-uml-gen.tsx +++ b/libs/remix-ui/solidity-uml-gen/src/lib/solidity-uml-gen.tsx @@ -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 { ISolidityUmlGen } from '../types' import './css/solidity-uml-gen.css' @@ -6,12 +7,15 @@ export interface RemixUiSolidityUmlGenProps { plugin?: ISolidityUmlGen updatedSvg?: string loading?: boolean + themeSelected?: string } type ButtonAction = { svgValid: () => boolean action: () => void buttonText: string + icon?: string + customcss?: string } interface ActionButtonsProps { @@ -21,19 +25,26 @@ interface ActionButtonsProps { const ActionButtons = ({ buttons }: ActionButtonsProps) => ( <> {buttons.map(btn => ( - + + + ))} ) -export function RemixUiSolidityUmlGen ({ plugin, updatedSvg, loading }: RemixUiSolidityUmlGenProps) { +export function RemixUiSolidityUmlGen ({ plugin, updatedSvg, loading, themeSelected }: RemixUiSolidityUmlGenProps) { const [showViewer, setShowViewer] = useState(false) const [svgPayload, setSVGPayload] = useState('') const [validSvg, setValidSvg] = useState(false) @@ -50,12 +61,14 @@ export function RemixUiSolidityUmlGen ({ plugin, updatedSvg, loading }: RemixUiS { buttonText: 'Download as PDF', svgValid: () => validSvg, - action: () => console.log('generated!!') + action: () => console.log('generated!!'), + icon: 'fa mr-1 pt-1 pb-1 fa-file' }, { buttonText: 'Download as PNG', 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

Click on Generate UML

) - const Display = () => ( + const Display = () => { + const invert = themeSelected === 'dark' ? 'invert(1)' : 'invert(0)' + return (
-
- {/* */} -
-
+
{ validSvg && showViewer ? ( - - - - + + { + ({ zoomIn, zoomOut, resetTransform }) => ( + +
+ + + + +
+ + + +
+ ) + }
) : loading ?
: }
- ) + )} return (<> { } diff --git a/libs/remix-ui/theme-module/types/theme-module.ts b/libs/remix-ui/theme-module/types/theme-module.ts index 5b465a72a7..bc3b903a42 100644 --- a/libs/remix-ui/theme-module/types/theme-module.ts +++ b/libs/remix-ui/theme-module/types/theme-module.ts @@ -43,4 +43,4 @@ export interface ThemeModule extends Plugin { fixInvert(image?: any): void; } -interface Theme { name: string, quality: string, url: string } +export interface Theme { name: string, quality: string, url: string }