fix iframe plugin api

pull/1342/head
yann300 3 years ago committed by davidzagi93@gmail.com
parent 9e3e0feac6
commit 02f1649462
  1. 113
      apps/remix-ide/src/app/tabs/compile-tab.js
  2. 22
      apps/solidity-compiler/src/app/compiler-api.ts
  3. 26
      apps/solidity-compiler/src/app/compiler.ts
  4. 3
      libs/remix-ui/solidity-compiler/src/index.ts
  5. 10
      libs/remix-ui/solidity-compiler/src/lib/actions/compiler.ts
  6. 2
      libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx
  7. 27
      libs/remix-ui/solidity-compiler/src/lib/icompiler-api.ts
  8. 6
      libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx
  9. 56
      libs/remix-ui/solidity-compiler/src/lib/types/index.ts

@ -48,119 +48,6 @@ class CompileTab extends CompilerApiMixin(ViewPlugin) {
this.renderComponent() this.renderComponent()
} }
/************
* EVENTS
*/
listenToEvents () {
this.data.eventHandlers.onContentChanged = () => {
this.emit('statusChanged', { key: 'edited', title: 'the content has changed, needs recompilation', type: 'info' })
}
this.editor.event.register('contentChanged', this.data.eventHandlers.onContentChanged)
this.data.eventHandlers.onLoadingCompiler = () => {
this.data.loading = true
this.emit('statusChanged', { key: 'loading', title: 'loading compiler...', type: 'info' })
}
this.compiler.event.register('loadingCompiler', this.data.eventHandlers.onLoadingCompiler)
this.data.eventHandlers.onCompilerLoaded = () => {
this.data.loading = false
this.emit('statusChanged', { key: 'none' })
}
this.compiler.event.register('compilerLoaded', this.data.eventHandlers.onCompilerLoaded)
this.data.eventHandlers.onStartingCompilation = () => {
this.emit('statusChanged', { key: 'loading', title: 'compiling...', type: 'info' })
}
this.data.eventHandlers.onRemoveAnnotations = () => {
this.call('editor', 'clearAnnotations')
}
const resetView = (isLocalhost) => {
this.compileTabLogic.isHardhatProject().then((result) => {
if (result && isLocalhost) this.isHardHatProject = true
else this.isHardHatProject = false
this.renderComponent()
})
this.resetResults()
}
this.on('filePanel', 'setWorkspace', (workspace) => {
resetView(workspace.isLocalhost)
})
this.on('remixd', 'rootFolderChanged', () => {
resetView(true)
})
this.compileTabLogic.event.on('startingCompilation', this.data.eventHandlers.onStartingCompilation)
this.compileTabLogic.event.on('removeAnnotations', this.data.eventHandlers.onRemoveAnnotations)
this.data.eventHandlers.onCurrentFileChanged = (name) => {
this.currentFile = name
this.renderComponent()
}
this.fileManager.events.on('currentFileChanged', this.data.eventHandlers.onCurrentFileChanged)
this.data.eventHandlers.onNoFileSelected = () => {
this.currentFile = ''
this.renderComponent()
}
this.fileManager.events.on('noFileSelected', this.data.eventHandlers.onNoFileSelected)
this.data.eventHandlers.onCompilationFinished = (success, data, source) => {
this.setCompileErrors(data)
if (success) {
// forwarding the event to the appManager infra
this.emit('compilationFinished', source.target, source, 'soljson', data)
if (data.errors && data.errors.length > 0) {
this.emit('statusChanged', {
key: data.errors.length,
title: `compilation finished successful with warning${data.errors.length > 1 ? 's' : ''}`,
type: 'warning'
})
} else this.emit('statusChanged', { key: 'succeed', title: 'compilation successful', type: 'success' })
// Store the contracts
this.contractsDetails = {}
this.compiler.visitContracts((contract) => {
this.contractsDetails[contract.name] = parseContracts(
contract.name,
contract.object,
this.compiler.getSource(contract.file)
)
})
} else {
const count = (data.errors ? data.errors.filter(error => error.severity === 'error').length : 0) + data.error ? 1 : 0
this.emit('statusChanged', { key: count, title: `compilation failed with ${count} error${count.length > 1 ? 's' : ''}`, type: 'error' })
}
// Update contract Selection
this.contractMap = {}
if (success) this.compiler.visitContracts((contract) => { this.contractMap[contract.name] = contract })
this.renderComponent()
}
this.compiler.event.register('compilationFinished', this.data.eventHandlers.onCompilationFinished)
this.data.eventHandlers.onThemeChanged = (theme) => {
const invert = theme.quality === 'dark' ? 1 : 0
const img = document.getElementById('swarmLogo')
if (img) {
img.style.filter = `invert(${invert})`
}
}
globalRegistry.get('themeModule').api.events.on('themeChanged', this.data.eventHandlers.onThemeChanged)
// Run the compiler instead of trying to save the website
$(window).keydown((e) => {
// ctrl+s or command+s
if ((e.metaKey || e.ctrlKey) && e.keyCode === 83) {
e.preventDefault()
this.compileTabLogic.runCompiler(this.hhCompilation)
}
})
}
onResetResults () { onResetResults () {
this.renderComponent() this.renderComponent()
} }

@ -123,8 +123,7 @@ export const CompilerApiMixin = (Base) => class extends Base {
'currentFile': () => this.currentFile, 'currentFile': () => this.currentFile,
'hideWarnings': () => false, 'hideWarnings': () => false,
'autoCompile': () => false, 'autoCompile': () => false,
'includeNightlies': () => false, 'includeNightlies': () => false
'optimise': () => false
} }
return conf[name]() return conf[name]()
} }
@ -186,7 +185,20 @@ export const CompilerApiMixin = (Base) => class extends Base {
this.on('filePanel', 'setWorkspace', (workspace) => { this.on('filePanel', 'setWorkspace', (workspace) => {
this.resetResults() this.resetResults()
if (this.onSetWorkspace) this.onSetWorkspace(workspace) if (this.onSetWorkspace) this.onSetWorkspace(workspace.isLocalhost)
})
this.on('remixd', 'rootFolderChanged', () => {
this.resetResults()
if (this.onSetWorkspace) this.onSetWorkspace(true)
})
this.on('editor', 'sessionSwitched', () => {
if (this.onSessionSwitched) this.onSessionSwitched()
})
this.on('editor', 'contentChanged', () => {
if (this.onContentChanged) this.onContentChanged()
}) })
this.compileTabLogic.event.on('startingCompilation', this.data.eventHandlers.onStartingCompilation) this.compileTabLogic.event.on('startingCompilation', this.data.eventHandlers.onStartingCompilation)
@ -226,8 +238,8 @@ export const CompilerApiMixin = (Base) => class extends Base {
) )
}) })
} else { } else {
const count = (data.errors ? data.errors.filter(error => error.severity === 'error').length : 0 + data.error ? 1 : 0) const count = (data.errors ? data.errors.filter(error => error.severity === 'error').length : 0) + data.error ? 1 : 0
this.emit('statusChanged', { key: count, title: `compilation failed with ${count} error${count.length > 1 ? 's' : ''}`, type: 'error' }) this.emit('statusChanged', { key: count, title: `compilation failed with ${count} error${count > 1 ? 's' : ''}`, type: 'error' })
} }
// Update contract Selection // Update contract Selection
this.contractMap = {} this.contractMap = {}

@ -24,26 +24,40 @@ export interface ConfigurationSettings {
} }
export class CompilerClientApi extends CompilerApiMixin(PluginClient) { export class CompilerClientApi extends CompilerApiMixin(PluginClient) {
// interface matches libs/remix-ui/solidity-compiler/types/index.ts : ICompilerApi
currentFile: string
contractMap: { contractMap: {
file: string file: string
} | Record<string, any> } | Record<string, any>
compileErrors: any compileErrors: any
compileTabLogic: any compileTabLogic: any
contractsDetails: Record<string, any> contractsDetails: Record<string, any>
contentImport: any
call: (...args) => void
on: (...args) => void
setSelectedVersion: (value: string) => void
configurationSettings: ConfigurationSettings configurationSettings: ConfigurationSettings
setHardHatCompilation: (value: boolean) => void
getParameters: () => ConfigurationSettings
setParameters: (params: Partial<ConfigurationSettings>) => void
setCompilerConfig: (settings: ConfigurationSettings) => void
getConfiguration: (value: string) => string getConfiguration: (value: string) => string
setConfiguration: (name: string, value: string) => void setConfiguration: (name: string, value: string) => void
currentFile: string getFileManagerMode: () => string
getCompilationResult: () => any
onCurrentFileChanged: (fileName: string) => void onCurrentFileChanged: (fileName: string) => void
onResetResults: () => void onResetResults: () => void
onSetWorkspace: (workspace: any) => void onSetWorkspace: (isLocalhost: boolean) => void
onNoFileSelected: () => void onNoFileSelected: () => void
onCompilationFinished: (contractsDetails: any, contractMap: any) => void onCompilationFinished: (contractsDetails: any, contractMap: any) => void
onSessionSwitched: () => void
onContentChanged: () => void
fileExists: (file: string) => Promise<boolean>
writeFile: (file: string, content: string) => Promise<void>
readFile: (file: string) => Promise<string>
open: (file: string) => void
constructor () { constructor () {
super() super()

@ -1,3 +1,2 @@
export * from './lib/solidity-compiler' export * from './lib/solidity-compiler'
export * from './lib/logic' export * from './lib/logic'
export * from './lib/icompiler-api'

@ -27,9 +27,9 @@ export const resetCompilerMode = () => (dispatch: React.Dispatch<any>) => {
} }
export const listenToEvents = (compileTabLogic, api) => (dispatch: React.Dispatch<any>) => { export const listenToEvents = (compileTabLogic, api) => (dispatch: React.Dispatch<any>) => {
api.on('editor', 'sessionSwitched', () => { api.onSessionSwitched = () => {
dispatch(setEditorMode('sessionSwitched')) dispatch(setEditorMode('sessionSwitched'))
}) }
compileTabLogic.event.on('startingCompilation', () => { compileTabLogic.event.on('startingCompilation', () => {
dispatch(setCompilerMode('startingCompilation')) dispatch(setCompilerMode('startingCompilation'))
@ -39,10 +39,10 @@ export const listenToEvents = (compileTabLogic, api) => (dispatch: React.Dispatc
dispatch(setCompilerMode('compilationDuration', speed)) dispatch(setCompilerMode('compilationDuration', speed))
}) })
api.on('editor', 'contentChanged', () => { api.onContentChanged = () => {
dispatch(setEditorMode('contentChanged')) dispatch(setEditorMode('contentChanged'))
}) }
compileTabLogic.compiler.event.register('loadingCompiler', () => { compileTabLogic.compiler.event.register('loadingCompiler', () => {
dispatch(setCompilerMode('loadingCompiler')) dispatch(setCompilerMode('loadingCompiler'))
}) })

@ -76,7 +76,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
hideWarnings: api.getConfiguration('hideWarnings') || false, hideWarnings: api.getConfiguration('hideWarnings') || false,
autoCompile: typeof autoCompile === 'boolean' ? autoCompile : api.getConfiguration('autoCompile') || false, autoCompile: typeof autoCompile === 'boolean' ? autoCompile : api.getConfiguration('autoCompile') || false,
includeNightlies: api.getConfiguration('includeNightlies') || false, includeNightlies: api.getConfiguration('includeNightlies') || false,
optimise: typeof optimize === 'boolean' ? optimize : api.getConfiguration('optimise') || false, optimize: (optimize !== null) && (optimize !== undefined) ? optimize : false,
runs: (runs !== null) && (runs !== 'null') && (runs !== undefined) && (runs !== 'undefined') ? runs : 200, runs: (runs !== null) && (runs !== 'null') && (runs !== undefined) && (runs !== 'undefined') ? runs : 200,
evmVersion: (evmVersion !== null) && (evmVersion !== 'null') && (evmVersion !== undefined) && (evmVersion !== 'undefined') ? evmVersion : 'default' evmVersion: (evmVersion !== null) && (evmVersion !== 'null') && (evmVersion !== undefined) && (evmVersion !== 'undefined') ? evmVersion : 'default'
} }

@ -1,27 +0,0 @@
export type onCurrentFileChanged = (fileName: string) => void
export interface ICompilerApi {
contractMap: {
file: string
} | Record<string, any>
compileErrors:any
currentFile: string
configurationSettings: any
setHardHatCompilation(value: boolean): void
setSelectedVersion(version: string): void
getCompilationResult(): any
setCompilerConfig: (settings: any) => void
getParameters: () => any
setParameters: (params) => void
getConfiguration: (name: string) => string
setConfiguration: (name: string, value: string) => void
fileProviderOf: (file: string) => string
getFileManagerMode: () => string
fileExists: (file: string) => Promise<boolean>
writeFile: (file: string, content: string) => Promise<void>
readFile: (file: string) => Promise<string>
open: (file: string) => void
onCurrentFileChanged: (listener: onCurrentFileChanged) => void
}

@ -44,8 +44,8 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
}) })
} }
plugin.onSetWorkspace = async (workspace: any) => { plugin.onSetWorkspace = async (isLocalhost: boolean) => {
const isHardhat = workspace.isLocalhost && await compileTabLogic.isHardhatProject() const isHardhat = isLocalhost && await compileTabLogic.isHardhatProject()
setState(prevState => { setState(prevState => {
return { ...prevState, currentFile, isHardhatProject: isHardhat } return { ...prevState, currentFile, isHardhatProject: isHardhat }
}) })
@ -71,7 +71,7 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
const updateCurrentVersion = (value) => { const updateCurrentVersion = (value) => {
setCurrentVersion(value) setCurrentVersion(value)
plugin.setSelectedVersion(value) plugin.setParameters({ version: value })
} }
const modal = async (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => { const modal = async (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => {

@ -1,27 +1,41 @@
export type onCurrentFileChanged = (fileName: string) => void export type onCurrentFileChanged = (fileName: string) => void
export interface SolidityCompilerProps { export interface SolidityCompilerProps {
plugin: { plugin: ICompilerApi
currentFile: string }
contractMap: {
file: string export interface ICompilerApi {
} | Record<string, any> currentFile: string
compileErrors: any, contractMap: {
compileTabLogic: any, file: string
contractsDetails: Record<string, any>, } | Record<string, any>
contentImport: any, compileErrors: any
call: (...args) => void compileTabLogic: any
on: (...args) => void, contractsDetails: Record<string, any>
setSelectedVersion: (value: string) => void, configurationSettings: ConfigurationSettings
configurationSettings: ConfigurationSettings,
getConfiguration: (value: string) => string, setHardHatCompilation: (value: boolean) => void
setConfiguration: (name: string, value: string) => void, getParameters: () => any
onCurrentFileChanged: (fileName: string) => void, setParameters: (params) => void
onResetResults: () => void, getConfiguration: (value: string) => string
onSetWorkspace: (workspace: any) => void, setConfiguration: (name: string, value: string) => void
onNoFileSelected: () => void, getFileManagerMode: () => string
onCompilationFinished: (contractsDetails: any, contractMap: any) => void setCompilerConfig: (settings: any) => void
},
getCompilationResult: () => any
onCurrentFileChanged: (fileName: string) => void
onResetResults: () => void,
onSetWorkspace: (isLocalhost: boolean) => void
onNoFileSelected: () => void
onCompilationFinished: (contractsDetails: any, contractMap: any) => void
onSessionSwitched: () => void
onContentChanged: () => void
fileExists: (file: string) => Promise<boolean>
writeFile: (file: string, content: string) => Promise<void>
readFile: (file: string) => Promise<string>
open: (file: string) => void
} }
export interface CompilerContainerProps { export interface CompilerContainerProps {

Loading…
Cancel
Save