save flattened sol file

pull/5370/head
Joseph Izang 2 years ago committed by Aniket
parent fbc97cdd76
commit 27d323daac
  1. 24
      libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx
  2. 1
      package.json
  3. 12
      yarn.lock

@ -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 (

@ -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",

@ -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"

Loading…
Cancel
Save