refactoring abstract panel

AbstractPanel
davidzagi93@gmail.com 3 years ago committed by yann300
parent ab2da51276
commit 6a16d5f058
  1. 6
      apps/remix-ide/src/app/components/main-panel.js
  2. 70
      apps/remix-ide/src/app/components/panel.js
  3. 2
      apps/remix-ide/src/app/components/side-panel.js
  4. 16
      libs/remix-ui/abstract-panel/src/lib/abstract-panel-hoc.tsx
  5. 40
      libs/remix-ui/abstract-panel/src/lib/remix-ui-abstract-panel.module.css
  6. 47
      libs/remix-ui/abstract-panel/src/lib/remix-ui-abstract-panel.tsx
  7. 8
      libs/remix-ui/main-panel/src/lib/remix-ui-main-panel.module.css
  8. 2
      libs/remix-ui/main-panel/src/lib/remix-ui-main-panel.tsx

@ -16,13 +16,15 @@ const profile = {
export class MainPanel extends AbstractPanel { export class MainPanel extends AbstractPanel {
constructor (config) { constructor (config) {
super(profile) super(profile)
this.element = document.createElement('div') this.mainelement = document.createElement('div')
this.element.setAttribute('class', 'mainPanelPluginsContainer')
this.config = config this.config = config
} }
focus (name) { focus (name) {
this.emit('focusChanged', name) this.emit('focusChanged', name)
super.focus(name) super.focus(name)
this.renderComponent()
} }
onActivation () { onActivation () {
@ -38,7 +40,7 @@ export class MainPanel extends AbstractPanel {
<RemixUiMainPanel <RemixUiMainPanel
plugin={this} plugin={this}
/>, />,
this.element this.mainelement
) )
} }
} }

@ -4,31 +4,6 @@ import { RemixUiAbstractPanel } from '@remix-ui/abstract-panel' // eslint-disabl
import { EventEmitter } from 'events' import { EventEmitter } from 'events'
const EventManager = require('../../lib/events') const EventManager = require('../../lib/events')
import { HostPlugin } from '@remixproject/engine-web' // eslint-disable-line import { HostPlugin } from '@remixproject/engine-web' // eslint-disable-line
const csjs = require('csjs-inject')
const yo = require('yo-yo')
const css = csjs`
.plugins {
height: 100%;
}
.plugItIn {
display : none;
height : 100%;
}
.plugItIn > div {
overflow-y : auto;
overflow-x : hidden;
height : 100%;
width : 100%;
}
.plugItIn.active {
display : block;
}
.pluginsContainer {
height : 100%;
overflow-y : hidden;
}
`
/** Abstract class used for hosting the view of a plugin */ /** Abstract class used for hosting the view of a plugin */
export class AbstractPanel extends HostPlugin { export class AbstractPanel extends HostPlugin {
@ -41,51 +16,21 @@ export class AbstractPanel extends HostPlugin {
this.element = document.createElement('div') this.element = document.createElement('div')
this.element.setAttribute('id', 'plugins') this.element.setAttribute('id', 'plugins')
this.element.setAttribute('class', 'abstract-panel-plugins') this.element.setAttribute('class', 'abstract-panel-plugins')
// View where the plugin HTMLElement leaves
this.view = yo`<div id="plugins" class="${css.plugins}"></div>`
} }
onActivation () { onActivation () {
this.renderComponent() this.renderComponent()
} }
/** addView (profile, view) {
* Add the plugin to the panel if (this.contents[profile.name]) throw new Error(`Plugin ${profile.name} already rendered`)
* @param {String} name the name of the plugin
* @param {HTMLElement} content the HTMLContent of the plugin
*/
add (view, name) {
if (this.contents[name]) throw new Error(`Plugin ${name} already rendered`)
view.style.height = '100%' view.style.height = '100%'
view.style.width = '100%' view.style.width = '100%'
view.style.border = '0' view.style.border = '0'
this.contents[profile.name] = view
const isIframe = view.tagName === 'IFRAME' this.showContent(profile.name)
view.style.display = isIframe ? 'none' : 'block' this.element.appendChild(this.contents[profile.name])
const loading = isIframe ? yo` this.renderComponent()
<div class="d-flex justify-content-center align-items-center">
<div class="spinner-border" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
` : ''
this.contents[name] = yo`<div class="${css.plugItIn}" >${view}${loading}</div>`
if (view.tagName === 'IFRAME') {
view.addEventListener('load', () => {
if (this.contents[name].contains(loading)) {
this.contents[name].removeChild(loading)
}
view.style.display = 'block'
})
}
this.contents[name].style.display = 'none'
this.view.appendChild(this.contents[name])
}
addView (profile, view) {
this.add(view, profile.name)
} }
removeView (profile) { removeView (profile) {
@ -101,6 +46,7 @@ export class AbstractPanel extends HostPlugin {
delete this.contents[name] delete this.contents[name]
if (el) el.parentElement.removeChild(el) if (el) el.parentElement.removeChild(el)
if (name === this.active) this.active = undefined if (name === this.active) this.active = undefined
this.renderComponent()
} }
/** /**
@ -113,8 +59,10 @@ export class AbstractPanel extends HostPlugin {
if (this.active) { if (this.active) {
this.contents[this.active].style.display = 'none' this.contents[this.active].style.display = 'none'
} }
this.contents[name].style.display = 'flex' this.contents[name].style.display = 'flex'
this.active = name this.active = name
this.renderComponent()
} }
focus (name) { focus (name) {

@ -149,7 +149,7 @@ export class SidePanel extends AbstractPanel {
<section class="${css.panel} plugin-manager"> <section class="${css.panel} plugin-manager">
${this.header} ${this.header}
<div class="${css.pluginsContainer}"> <div class="${css.pluginsContainer}">
${this.view} ${this.element}
</div> </div>
</section>` </section>`
} }

@ -0,0 +1,16 @@
import React from 'react'
function AbstractPanelHOC (WrappedComponent: any) {
return (WrappedComponent: any) => {
const WithAbstractPanel = (props: any) => {
return (
<WrappedComponent
{...props}
/>
)
}
return WithAbstractPanel;
}
}
export default AbstractPanelHOC

@ -1,20 +1,20 @@
.abstract-panel-plugins { .plugins {
height: 100%; height: 100%;
} }
.abstract-panel-plugItIn { .plugItIn {
display : none; display : none;
height : 100%; height : 100%;
} }
.abstract-panel-plugItIn > div { .plugItIn > div {
overflow-y : auto; overflow-y : auto;
overflow-x : hidden; overflow-x : hidden;
height : 100%; height : 100%;
width : 100%; width : 100%;
} }
.abstract-panel-plugItIn.active { .plugItIn.active {
display : block; display : block;
} }
.abstract-panel-pluginsContainer { .pluginsContainer {
height : 100%; height : 100%;
overflow-y : hidden; overflow-y : hidden;
} }

@ -1,19 +1,56 @@
import React from 'react' // eslint-disable-line import React, { useEffect, useState } from 'react' // eslint-disable-line
import './remix-ui-abstract-panel.module.css'; import './remix-ui-abstract-panel.module.css';
import parse from 'html-react-parser'
/* eslint-disable-next-line */ /* eslint-disable-next-line */
export interface RemixUiAbstractPanelProps { export interface RemixUiAbstractPanelProps {
reactView: any reactView: any,
plugin: any plugin: any
} }
export function RemixUiAbstractPanel(props: RemixUiAbstractPanelProps) { export function RemixUiAbstractPanel(props: RemixUiAbstractPanelProps) {
const [loading, setLoading] = useState(false);
useEffect(() => {
console.log({ activePlugin: props.plugin.active })
},[props.plugin.active])
useEffect(() => {
Object.keys(props.plugin.contents).map((key: string) => {
const view = props.plugin.contents[key]
view.addEventListener('load', () => {
setLoading(true)
})
setLoading(false)
})
}
, [loading])
return ( return (
<div id="plugins" className="plugins"> <div id="plugins" className="plugins">
{console.log({ view: props.plugin })} {
good Object.keys(props.plugin.contents).map((key: string, index: number) => {
const plugin = props.plugin.contents[key]
const active = props.plugin.active === key
console.log({ plugin: plugin.id, active: props.plugin.active })
return (
<div className="plugItIn" key={ index }>
{loading && (
<div className="d-flex justify-content-center align-items-center">
<div className="spinner-border" role="status">
<span className="sr-only">Loading...</span>
</div>
</div>
)}
</div>
)
})
}
</div> </div>
); )
} }
export default RemixUiAbstractPanel; export default RemixUiAbstractPanel;

@ -14,7 +14,13 @@
.plugItIn.active { .plugItIn.active {
display : block; display : block;
} }
.pluginsContainer { /* .pluginsContainer {
height : 100%; height : 100%;
overflow-y : hidden; overflow-y : hidden;
} */
.pluginsContainer {
height: 100%;
display: flex;
overflow-y: hidden;
} }

@ -18,7 +18,7 @@ export const RemixUiMainPanel = (props: RemixUiMainPanelProps) => {
return ( return (
<div className="plugItIn_2byTty" style={{ display: "block" }} data-id="mainPanelPluginsContainer" id='mainPanelPluginsContainer-id'> <div className="plugItIn pluginsContainer" style={{ display: "block" }} data-id="mainPanelPluginsContainer" id='mainPanelPluginsContainer-id'>
<div data-id="landingPageHomeContainer" className="homeContainer d-flex" style={{ height: "100%", width: "100%", border: "0px", display: "block" }}> <div data-id="landingPageHomeContainer" className="homeContainer d-flex" style={{ height: "100%", width: "100%", border: "0px", display: "block" }}>
<div className="mainContent_2A2Ew bg-light"> <div className="mainContent_2A2Ew bg-light">
<div className="d-flex justify-content-between"> <div className="d-flex justify-content-between">

Loading…
Cancel
Save