From d02e2f99c1cfba77c2f00a21dc1bbbbdfc7aabdb Mon Sep 17 00:00:00 2001 From: "davidzagi93@gmail.com" Date: Mon, 6 Dec 2021 09:30:43 +0100 Subject: [PATCH] adding side-panel --- .../src/app/components/main-panel.js | 4 +- apps/remix-ide/src/app/components/panel.js | 5 +- .../src/app/components/side-panel.js | 182 ++++++++++-------- .../lib/remix-ui-abstract-panel.module.css | 4 - .../src/lib/remix-ui-abstract-panel.tsx | 7 +- .../src/lib/remix-ui-main-panel.module.css | 8 +- .../src/lib/remix-ui-main-panel.tsx | 4 +- libs/remix-ui/side-panel/.babelrc | 12 ++ libs/remix-ui/side-panel/.eslintrc.json | 18 ++ libs/remix-ui/side-panel/README.md | 7 + libs/remix-ui/side-panel/src/index.ts | 1 + .../src/lib/remix-ui-side-panel.module.css | 43 +++++ .../src/lib/remix-ui-side-panel.tsx | 75 ++++++++ libs/remix-ui/side-panel/tsconfig.json | 20 ++ libs/remix-ui/side-panel/tsconfig.lib.json | 13 ++ nx.json | 3 + tsconfig.base.json | 1 + workspace.json | 20 +- 18 files changed, 327 insertions(+), 100 deletions(-) create mode 100644 libs/remix-ui/side-panel/.babelrc create mode 100644 libs/remix-ui/side-panel/.eslintrc.json create mode 100644 libs/remix-ui/side-panel/README.md create mode 100644 libs/remix-ui/side-panel/src/index.ts create mode 100644 libs/remix-ui/side-panel/src/lib/remix-ui-side-panel.module.css create mode 100644 libs/remix-ui/side-panel/src/lib/remix-ui-side-panel.tsx create mode 100644 libs/remix-ui/side-panel/tsconfig.json create mode 100644 libs/remix-ui/side-panel/tsconfig.lib.json diff --git a/apps/remix-ide/src/app/components/main-panel.js b/apps/remix-ide/src/app/components/main-panel.js index 707b36a776..8f16f6199f 100644 --- a/apps/remix-ide/src/app/components/main-panel.js +++ b/apps/remix-ide/src/app/components/main-panel.js @@ -17,7 +17,7 @@ export class MainPanel extends AbstractPanel { constructor (config) { super(profile) this.mainelement = document.createElement('div') - this.element.setAttribute('class', 'mainPanelPluginsContainer') + this.mainelement.setAttribute('class', 'mainPanelPluginsContainer') this.config = config } @@ -32,7 +32,7 @@ export class MainPanel extends AbstractPanel { } render () { - return this.element + return this.mainelement } renderComponent () { diff --git a/apps/remix-ide/src/app/components/panel.js b/apps/remix-ide/src/app/components/panel.js index 93d9937338..cba9fdc416 100644 --- a/apps/remix-ide/src/app/components/panel.js +++ b/apps/remix-ide/src/app/components/panel.js @@ -14,8 +14,7 @@ export class AbstractPanel extends HostPlugin { this.contents = {} this.active = undefined this.element = document.createElement('div') - this.element.setAttribute('id', 'plugins') - this.element.setAttribute('class', 'abstract-panel-plugins') + this.element.setAttribute('style', 'height: 100%; width: 100%; border: 0;') } onActivation () { @@ -24,7 +23,7 @@ export class AbstractPanel extends HostPlugin { addView (profile, view) { if (this.contents[profile.name]) throw new Error(`Plugin ${profile.name} already rendered`) - view.style.height = '100%' + // view.style.height = '90%' // makde external plugins full height view.style.width = '100%' view.style.border = '0' this.contents[profile.name] = view diff --git a/apps/remix-ide/src/app/components/side-panel.js b/apps/remix-ide/src/app/components/side-panel.js index 4d681f04c0..8ddaf52f70 100644 --- a/apps/remix-ide/src/app/components/side-panel.js +++ b/apps/remix-ide/src/app/components/side-panel.js @@ -1,53 +1,56 @@ +import React from 'react' // eslint-disable-line import { AbstractPanel } from './panel' +import ReactDOM from 'react-dom' // eslint-disable-line +import { RemixUiSidePanel } from '@remix-ui/side-panel' // eslint-disable-line import * as packageJson from '../../../../../package.json' -const csjs = require('csjs-inject') +// const csjs = require('csjs-inject') const yo = require('yo-yo') -const css = csjs` - .panel { - width: 100%; - height: 100%; - display: flex; - flex-direction: column; - flex: auto; - } - .swapitTitle { - margin: 0; - text-transform: uppercase; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - } - .swapitTitle i{ - padding-left: 6px; - font-size: 14px; - } - .swapitHeader { - display: flex; - align-items: center; - padding: 16px 24px 15px; - justify-content: space-between; - } - .icons i { - height: 80%; - cursor: pointer; - } - .pluginsContainer { - height: 100%; - overflow-y: auto; - } - .titleInfo { - padding-left: 10px; - } - .versionBadge { - background-color: var(--light); - padding: 0 7px; - font-weight: bolder; - margin-left: 5px; - text-transform: lowercase; - cursor: default; - } -` +// const css = csjs` +// .panel { +// width: 100%; +// height: 100%; +// display: flex; +// flex-direction: column; +// flex: auto; +// } +// .swapitTitle { +// margin: 0; +// text-transform: uppercase; +// white-space: nowrap; +// overflow: hidden; +// text-overflow: ellipsis; +// } +// .swapitTitle i{ +// padding-left: 6px; +// font-size: 14px; +// } +// .swapitHeader { +// display: flex; +// align-items: center; +// padding: 16px 24px 15px; +// justify-content: space-between; +// } +// .icons i { +// height: 80%; +// cursor: pointer; +// } +// .pluginsContainer { +// height: 100%; +// overflow-y: auto; +// } +// .titleInfo { +// padding-left: 10px; +// } +// .versionBadge { +// background-color: var(--light); +// padding: 0 7px; +// font-weight: bolder; +// margin-left: 5px; +// text-transform: lowercase; +// cursor: default; +// } +// ` const sidePanel = { name: 'sidePanel', @@ -63,7 +66,9 @@ export class SidePanel extends AbstractPanel { super(sidePanel) this.appManager = appManager this.header = yo`
` - this.renderHeader() + // this.renderHeader() + this.sideelement = document.createElement('div') + this.sideelement.setAttribute('class', 'plugins-container') this.verticalIcons = verticalIcons // Toggle content @@ -90,6 +95,10 @@ export class SidePanel extends AbstractPanel { }) } + onActivation () { + this.renderComponent() + } + focus (name) { this.emit('focusChanged', name) super.focus(name) @@ -104,6 +113,7 @@ export class SidePanel extends AbstractPanel { addView (profile, view) { super.addView(profile, view) this.verticalIcons.linkContent(profile) + this.renderComponent() } /** @@ -112,45 +122,57 @@ export class SidePanel extends AbstractPanel { */ async showContent (name) { super.showContent(name) - this.renderHeader() + // this.renderHeader() this.emit('focusChanged', name) + this.renderComponent() } /** The header of the side panel */ - async renderHeader () { - let name = ' - ' - let docLink = '' - let versionWarning - if (this.active) { - const profile = await this.appManager.getProfile(this.active) - name = profile.displayName ? profile.displayName : profile.name - docLink = profile.documentation ? yo`` : '' - if (profile.version && profile.version.match(/\b(\w*alpha\w*)\b/g)) { - versionWarning = yo`alpha` - } - // Beta - if (profile.version && profile.version.match(/\b(\w*beta\w*)\b/g)) { - versionWarning = yo`beta` - } - } + // async renderHeader () { + // let name = ' - ' + // let docLink = '' + // let versionWarning + // if (this.active) { + // const profile = await this.appManager.getProfile(this.active) + // name = profile.displayName ? profile.displayName : profile.name + // docLink = profile.documentation ? yo`` : '' + // if (profile.version && profile.version.match(/\b(\w*alpha\w*)\b/g)) { + // versionWarning = yo`alpha` + // } + // // Beta + // if (profile.version && profile.version.match(/\b(\w*beta\w*)\b/g)) { + // versionWarning = yo`beta` + // } + // } - const header = yo` -
-
${name}
- ${docLink} - ${versionWarning} -
- ` - yo.update(this.header, header) - } + // const header = yo` + //
+ //
${name}
+ // ${docLink} + // ${versionWarning} + //
+ // ` + // yo.update(this.header, header) + // this.renderComponent() + // } render () { - return yo` -
- ${this.header} -
- ${this.element} -
-
` + return this.element + // return yo` + //
+ // ${this.header} + //
+ // ${this.element} + //
+ //
` + } + + renderComponent () { + ReactDOM.render( + , + this.sideelement + ) } } diff --git a/libs/remix-ui/abstract-panel/src/lib/remix-ui-abstract-panel.module.css b/libs/remix-ui/abstract-panel/src/lib/remix-ui-abstract-panel.module.css index 9ab7f8557f..8ab5f0b1c8 100644 --- a/libs/remix-ui/abstract-panel/src/lib/remix-ui-abstract-panel.module.css +++ b/libs/remix-ui/abstract-panel/src/lib/remix-ui-abstract-panel.module.css @@ -13,8 +13,4 @@ } .plugItIn.active { display : block; -} -.pluginsContainer { - height : 100%; - overflow-y : hidden; } \ No newline at end of file diff --git a/libs/remix-ui/abstract-panel/src/lib/remix-ui-abstract-panel.tsx b/libs/remix-ui/abstract-panel/src/lib/remix-ui-abstract-panel.tsx index f8d4de503b..60beb915ac 100644 --- a/libs/remix-ui/abstract-panel/src/lib/remix-ui-abstract-panel.tsx +++ b/libs/remix-ui/abstract-panel/src/lib/remix-ui-abstract-panel.tsx @@ -22,13 +22,14 @@ export function RemixUiAbstractPanel(props: RemixUiAbstractPanelProps) { view.addEventListener('load', () => { setLoading(true) }) - setLoading(false) + }) + setLoading(false) } , [loading]) return ( -
+
{ Object.keys(props.plugin.contents).map((key: string, index: number) => { @@ -37,7 +38,7 @@ export function RemixUiAbstractPanel(props: RemixUiAbstractPanelProps) { console.log({ plugin: plugin.id, active: props.plugin.active }) return ( -
+
{loading && (
diff --git a/libs/remix-ui/main-panel/src/lib/remix-ui-main-panel.module.css b/libs/remix-ui/main-panel/src/lib/remix-ui-main-panel.module.css index bd9571c854..d5e4c7e6b2 100644 --- a/libs/remix-ui/main-panel/src/lib/remix-ui-main-panel.module.css +++ b/libs/remix-ui/main-panel/src/lib/remix-ui-main-panel.module.css @@ -14,13 +14,13 @@ .plugItIn.active { display : block; } - /* .pluginsContainer { + .pluginsContainer { height : 100%; overflow-y : hidden; - } */ + } - .pluginsContainer { + /* .pluginsContainer { height: 100%; display: flex; overflow-y: hidden; - } \ No newline at end of file + } */ \ No newline at end of file diff --git a/libs/remix-ui/main-panel/src/lib/remix-ui-main-panel.tsx b/libs/remix-ui/main-panel/src/lib/remix-ui-main-panel.tsx index b48f8a465c..376841d2f3 100644 --- a/libs/remix-ui/main-panel/src/lib/remix-ui-main-panel.tsx +++ b/libs/remix-ui/main-panel/src/lib/remix-ui-main-panel.tsx @@ -18,7 +18,6 @@ export const RemixUiMainPanel = (props: RemixUiMainPanelProps) => { return ( -
@@ -113,8 +112,7 @@ export const RemixUiMainPanel = (props: RemixUiMainPanelProps) => {
-
- ); + ) } export default RemixUiMainPanel; diff --git a/libs/remix-ui/side-panel/.babelrc b/libs/remix-ui/side-panel/.babelrc new file mode 100644 index 0000000000..ccae900be4 --- /dev/null +++ b/libs/remix-ui/side-panel/.babelrc @@ -0,0 +1,12 @@ +{ + "presets": [ + [ + "@nrwl/react/babel", + { + "runtime": "automatic", + "useBuiltIns": "usage" + } + ] + ], + "plugins": [] +} diff --git a/libs/remix-ui/side-panel/.eslintrc.json b/libs/remix-ui/side-panel/.eslintrc.json new file mode 100644 index 0000000000..50e59482cf --- /dev/null +++ b/libs/remix-ui/side-panel/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["plugin:@nrwl/nx/react", "../../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/libs/remix-ui/side-panel/README.md b/libs/remix-ui/side-panel/README.md new file mode 100644 index 0000000000..fa765fcb39 --- /dev/null +++ b/libs/remix-ui/side-panel/README.md @@ -0,0 +1,7 @@ +# remix-ui-side-panel + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test remix-ui-side-panel` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/remix-ui/side-panel/src/index.ts b/libs/remix-ui/side-panel/src/index.ts new file mode 100644 index 0000000000..d45ee2522b --- /dev/null +++ b/libs/remix-ui/side-panel/src/index.ts @@ -0,0 +1 @@ +export * from './lib/remix-ui-side-panel'; diff --git a/libs/remix-ui/side-panel/src/lib/remix-ui-side-panel.module.css b/libs/remix-ui/side-panel/src/lib/remix-ui-side-panel.module.css new file mode 100644 index 0000000000..b271bcc176 --- /dev/null +++ b/libs/remix-ui/side-panel/src/lib/remix-ui-side-panel.module.css @@ -0,0 +1,43 @@ +.panel { + width: 100%; + height: 100%; + display: flex; + flex-direction: column; + flex: auto; + } + .swapitTitle { + margin: 0; + text-transform: uppercase; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + .swapitTitle i{ + padding-left: 6px; + font-size: 14px; + } + .remix-ui-side-panel-swapitHeader { + display: flex; + align-items: center; + padding: 16px 24px 15px; + justify-content: space-between; + } + .icons i { + height: 80%; + cursor: pointer; + } + .pluginsContainer { + height: 100%; + overflow-y: auto; + } + .titleInfo { + padding-left: 10px; + } + .versionBadge { + background-color: var(--light); + padding: 0 7px; + font-weight: bolder; + margin-left: 5px; + text-transform: lowercase; + cursor: default; + } \ No newline at end of file diff --git a/libs/remix-ui/side-panel/src/lib/remix-ui-side-panel.tsx b/libs/remix-ui/side-panel/src/lib/remix-ui-side-panel.tsx new file mode 100644 index 0000000000..85187a83ba --- /dev/null +++ b/libs/remix-ui/side-panel/src/lib/remix-ui-side-panel.tsx @@ -0,0 +1,75 @@ +import React, { useEffect, useState } from 'react' // eslint-disable-line +import parse from 'html-react-parser' +import './remix-ui-side-panel.module.css'; + +/* eslint-disable-next-line */ +export interface RemixUiSidePanelProps { + plugin: any +} + +export function RemixUiSidePanel(props: RemixUiSidePanelProps) { + const [view, setView] = useState('') + const [dockLink, setDockLink] = useState(false) + const [versionWarning, setVersionWarning] = useState(false) + const [profile, setProfile] = useState('') + const [profileDocsLink, setProfileDocsLink] = useState('') + const [name, setName] = useState(' - ') + + useEffect(() => { + console.log({ props: props.plugin }) + Object.keys(props.plugin.contents).map((key: string, index: number) => { + console.log({ key }) + const active = props.plugin.active === key + if (active) { + const plugin = props.plugin.contents[key] + setView(plugin.innerHTML) + } + }) + }, [props.plugin.contents]) + + const getProfile = async () => { + if (props.plugin.active) { + const profile = await props.plugin.appManager.getProfile(props.plugin.active) + setProfileDocsLink(profile.documentation) + profile.displayName ? setName(profile.displayName) : setName(profile.name) + profile.documentation ? setDockLink(true) : setDockLink(false) + if (profile.version && profile.version.match(/\b(\w*alpha\w*)\b/g)) { + setVersionWarning(true) + } + // Beta + if (profile.version && profile.version.match(/\b(\w*beta\w*)\b/g)) { + setVersionWarning(true) + } + } + } + + const renderHeader = () => { + getProfile() + return ( +
+
{name}
+ {dockLink ? () : ''} + {/* {versionWarning ? (alpha) : (beta)} */} +
+ ) + } + + + return ( +
+ {renderHeader()} +
+
+
+ ); +} + +export default RemixUiSidePanel; diff --git a/libs/remix-ui/side-panel/tsconfig.json b/libs/remix-ui/side-panel/tsconfig.json new file mode 100644 index 0000000000..8bd701c578 --- /dev/null +++ b/libs/remix-ui/side-panel/tsconfig.json @@ -0,0 +1,20 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "jsx": "react-jsx", + "allowJs": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + } + ] +} diff --git a/libs/remix-ui/side-panel/tsconfig.lib.json b/libs/remix-ui/side-panel/tsconfig.lib.json new file mode 100644 index 0000000000..b560bc4dec --- /dev/null +++ b/libs/remix-ui/side-panel/tsconfig.lib.json @@ -0,0 +1,13 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "types": ["node"] + }, + "files": [ + "../../../node_modules/@nrwl/react/typings/cssmodule.d.ts", + "../../../node_modules/@nrwl/react/typings/image.d.ts" + ], + "exclude": ["**/*.spec.ts", "**/*.spec.tsx"], + "include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"] +} diff --git a/nx.json b/nx.json index 1ea0794c32..decbde03bd 100644 --- a/nx.json +++ b/nx.json @@ -144,6 +144,9 @@ }, "remix-ui-abstract-panel": { "tags": [] + }, + "remix-ui-side-panel": { + "tags": [] } }, "targetDependencies": { diff --git a/tsconfig.base.json b/tsconfig.base.json index dd7f9d7c37..8c956056c7 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -69,6 +69,7 @@ "@remix-ui/helper": ["libs/remix-ui/helper/src/index.ts"], "@remix-ui/vertical-icons-panel": ["libs/remix-ui/vertical-icons-panel/src/index.ts"], "@remix-ui/main-panel": ["libs/remix-ui/main-panel/src/index.ts"], + "@remix-ui/abstract-panel": ["libs/remix-ui/abstract-panel/src/index.ts"], "@remix-ui/side-panel": ["libs/remix-ui/side-panel/src/index.ts"] } }, diff --git a/workspace.json b/workspace.json index 1005bd21d2..c6b94ddad8 100644 --- a/workspace.json +++ b/workspace.json @@ -1160,7 +1160,25 @@ "options": { "linter": "eslint", "tsConfig": ["libs/remix-ui/abstract-panel/tsconfig.lib.json"], - "exclude": ["**/node_modules/**", "!libs/remix-ui/abstract-panel/**/*"] + "exclude": [ + "**/node_modules/**", + "!libs/remix-ui/abstract-panel/**/*" + ] + } + } + } + }, + "remix-ui-side-panel": { + "root": "libs/remix-ui/side-panel", + "sourceRoot": "libs/remix-ui/side-panel/src", + "projectType": "library", + "architect": { + "lint": { + "builder": "@nrwl/linter:eslint", + "options": { + "lintFilePatterns": [ + "libs/remix-ui/side-panel/**/*.{ts,tsx,js,jsx}" + ] } } }