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()
}
/************
* 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 () {
this.renderComponent()
}

@ -123,8 +123,7 @@ export const CompilerApiMixin = (Base) => class extends Base {
'currentFile': () => this.currentFile,
'hideWarnings': () => false,
'autoCompile': () => false,
'includeNightlies': () => false,
'optimise': () => false
'includeNightlies': () => false
}
return conf[name]()
}
@ -186,7 +185,20 @@ export const CompilerApiMixin = (Base) => class extends Base {
this.on('filePanel', 'setWorkspace', (workspace) => {
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)
@ -226,8 +238,8 @@ export const CompilerApiMixin = (Base) => class extends Base {
)
})
} 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' })
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 > 1 ? 's' : ''}`, type: 'error' })
}
// Update contract Selection
this.contractMap = {}

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

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

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

@ -76,7 +76,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
hideWarnings: api.getConfiguration('hideWarnings') || false,
autoCompile: typeof autoCompile === 'boolean' ? autoCompile : api.getConfiguration('autoCompile') || 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,
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) => {
const isHardhat = workspace.isLocalhost && await compileTabLogic.isHardhatProject()
plugin.onSetWorkspace = async (isLocalhost: boolean) => {
const isHardhat = isLocalhost && await compileTabLogic.isHardhatProject()
setState(prevState => {
return { ...prevState, currentFile, isHardhatProject: isHardhat }
})
@ -71,7 +71,7 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
const updateCurrentVersion = (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) => {

@ -1,27 +1,41 @@
export type onCurrentFileChanged = (fileName: string) => void
export interface SolidityCompilerProps {
plugin: {
currentFile: string
contractMap: {
file: string
} | Record<string, any>
compileErrors: any,
compileTabLogic: any,
contractsDetails: Record<string, any>,
contentImport: any,
call: (...args) => void
on: (...args) => void,
setSelectedVersion: (value: string) => void,
configurationSettings: ConfigurationSettings,
getConfiguration: (value: string) => string,
setConfiguration: (name: string, value: string) => void,
onCurrentFileChanged: (fileName: string) => void,
onResetResults: () => void,
onSetWorkspace: (workspace: any) => void,
onNoFileSelected: () => void,
onCompilationFinished: (contractsDetails: any, contractMap: any) => void
},
plugin: ICompilerApi
}
export interface ICompilerApi {
currentFile: string
contractMap: {
file: string
} | Record<string, any>
compileErrors: any
compileTabLogic: any
contractsDetails: Record<string, any>
configurationSettings: ConfigurationSettings
setHardHatCompilation: (value: boolean) => void
getParameters: () => any
setParameters: (params) => void
getConfiguration: (value: string) => string
setConfiguration: (name: string, value: string) => void
getFileManagerMode: () => string
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 {

Loading…
Cancel
Save