From 04517234a3dce525f1782953359354bbfb981b00 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Mon, 2 Jan 2023 13:57:56 +0100 Subject: [PATCH] save flattened sol file --- .../src/lib/contract-selection.tsx | 24 +++++++++++-------- package.json | 1 + yarn.lock | 12 ++++++++++ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx b/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx index 093b0f3d26..b24d55e0b2 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx @@ -8,12 +8,15 @@ import { convertAST2UmlClasses } from 'sol2uml/lib/converterAST2Classes' const parser = (window as any).SolidityParser import { convertUmlClasses2Dot } from 'sol2uml/lib/converterClasses2Dot' import vizRenderStringSync from '@aduh95/viz.js/sync' +import domToPdf from 'dom-to-pdf' import './css/style.css' import { CustomTooltip } from '@remix-ui/helper' import { concatSourceFiles, getDependencyGraph } from './logic/flattenerUtilities' import Viewer from 'react-viewer' +import { jsPDF } from 'jspdf' +const pdfBuilder = new jsPDF('portrait') export const ContractSelection = (props: ContractSelectionProps) => { const { api, compiledFileName, contractsDetails, contractList, compilerInput, modal } = props const [selectedContract, setSelectedContract] = useState('') @@ -209,6 +212,14 @@ export const ContractSelection = (props: ContractSelectionProps) => { const currentFile = api.currentFile const ast = content4AST.length > 1 ? parser.parse(content4AST) : parser.parse(api.getCompilationResult().source.sources[currentFile].content) const payload = vizRenderStringSync(convertUmlClasses2Dot(convertAST2UmlClasses(ast, currentFile))) + + const domParser = new DOMParser() + const element = domParser.parseFromString(payload, 'image/svg+xml').querySelector('svg') + const fileName = `${api.currentFile.split('/')[0]}/resources/${api.currentFile.split('/')[1]}.pdf` + // domToPdf(element, { filename: fileName}, function(pdf) { + // console.log({ pdf }) + // }); + pdfBuilder setSVGPayload(payload) setShowViewer(!showViewer) } catch (error) { @@ -230,16 +241,9 @@ export const ContractSelection = (props: ContractSelectionProps) => { ? [filePath] : dependencyGraph.sort().reverse() const sources = api.getCompilationResult().source.sources - setContent4AST(concatSourceFiles(sorted, sources)) - } - - const showFlattener = () => { - const confirmNodeType = api.getCompilationResult().data.sources[api.currentFile] - .ast && api.getCompilationResult().data.sources[api.currentFile] - .ast.nodes.some(x => x.nodeType === 'ImportDirective') - const currentFile = api.currentFile.split('/')[1] - const contractListConfirm = contractList.some(x => x.file === currentFile) - return confirmNodeType && contractListConfirm + const result = concatSourceFiles(sorted, sources) + api.writeFile(`${api.currentFile}_flattened.sol`, result) + setContent4AST(result) } return ( diff --git a/package.json b/package.json index 275ba85deb..3730cb8e77 100644 --- a/package.json +++ b/package.json @@ -151,6 +151,7 @@ "core-js": "^3.6.5", "deep-equal": "^1.0.1", "document-register-element": "1.13.1", + "dom-to-pdf": "^0.3.1", "eslint-config-prettier": "^8.5.0", "ethers": "^5.4.2", "ethjs-util": "^0.1.6", diff --git a/yarn.lock b/yarn.lock index a7ed6b983d..bf28827bcb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11924,6 +11924,18 @@ dom-serializer@^2.0.0: domhandler "^5.0.2" entities "^4.2.0" +"dom-to-image@git+https://github.com/dmapper/dom-to-image.git": + version "2.6.0" + resolved "git+https://github.com/dmapper/dom-to-image.git#a7c386a8ea813930f05449ac71ab4be0c262dff3" + +dom-to-pdf@^0.3.1: + version "0.3.1" + resolved "https://registry.yarnpkg.com/dom-to-pdf/-/dom-to-pdf-0.3.1.tgz#06db966acc73a7b81ce183202f7b6ff1f5f38578" + integrity sha512-2duxMNttyQr5XySV2t7gftCVhHr+zoE/f1h0nQDp/1KugAsk07EkZ9zcPFgZihcyj4dXBUWyVSxOik8czuFGDQ== + dependencies: + dom-to-image "https://github.com/dmapper/dom-to-image" + jspdf "^2.5.1" + dom-walk@^0.1.0: version "0.1.2" resolved "https://registry.yarnpkg.com/dom-walk/-/dom-walk-0.1.2.tgz#0c548bef048f4d1f2a97249002236060daa3fd84"