From eac43196d9cfff24244d1984c59f1e049ffd7aaf Mon Sep 17 00:00:00 2001 From: bqy_fe <1743369777@qq.com> Date: Fri, 24 Jun 2022 01:28:52 +0800 Subject: [PATCH] fix: some css style --- .../detail/extension-detail.component.html | 5 ++- .../detail/extension-detail.component.ts | 16 ++++++++++ .../pages/extension/extension.component.scss | 3 ++ .../components/setting/setting.component.html | 2 +- .../shadow-dom-encapsulation.component.ts | 32 ++++++++++++++----- 5 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/workbench/browser/src/app/pages/extension/detail/extension-detail.component.html b/src/workbench/browser/src/app/pages/extension/detail/extension-detail.component.html index 6a6eb06e1..120474f9b 100644 --- a/src/workbench/browser/src/app/pages/extension/detail/extension-detail.component.html +++ b/src/workbench/browser/src/app/pages/extension/detail/extension-detail.component.html @@ -1,5 +1,5 @@
-
+
diff --git a/src/workbench/browser/src/app/pages/extension/detail/extension-detail.component.ts b/src/workbench/browser/src/app/pages/extension/detail/extension-detail.component.ts index 68bec5305..1ce68dcbf 100644 --- a/src/workbench/browser/src/app/pages/extension/detail/extension-detail.component.ts +++ b/src/workbench/browser/src/app/pages/extension/detail/extension-detail.component.ts @@ -20,8 +20,21 @@ export class ExtensionDetailComponent implements OnInit { this.route.snapshot.queryParams.id, this.route.snapshot.queryParams.name ); + if (!this.extensionDetail?.introduction && !this.extensionDetail?.installed) { + await this.fetchReadme(); + } this.extensionDetail.introduction ||= 'This plugin has no documentation yet.'; } + + async fetchReadme() { + try { + const htmlText = await (await fetch(`https://www.npmjs.com/package/${this.extensionDetail.name}`)).text(); + const domParser = new DOMParser(); + const html = domParser.parseFromString(htmlText, 'text/html'); + this.extensionDetail.introduction = html.querySelector('#readme').innerHTML; + } catch (error) {} + } + manageExtension(operate: string, id) { this.isOperating = true; console.log(this.isOperating); @@ -34,10 +47,13 @@ export class ExtensionDetailComponent implements OnInit { switch (operate) { case 'install': { this.extensionDetail.installed = this.extensionService.install(id); + this.getDetail(); break; } case 'uninstall': { this.extensionDetail.installed = !this.extensionService.uninstall(id); + this.fetchReadme(); + break; } } this.isOperating = false; diff --git a/src/workbench/browser/src/app/pages/extension/extension.component.scss b/src/workbench/browser/src/app/pages/extension/extension.component.scss index 38bdfa4b8..6be9b9cd8 100644 --- a/src/workbench/browser/src/app/pages/extension/extension.component.scss +++ b/src/workbench/browser/src/app/pages/extension/extension.component.scss @@ -13,6 +13,9 @@ font-size: 0.9em; } } + .tree_node { + font-size: 12px; + } .ant-tree .ant-tree-node-content-wrapper.ant-tree-node-selected { opacity: .8; } diff --git a/src/workbench/browser/src/app/shared/components/setting/setting.component.html b/src/workbench/browser/src/app/shared/components/setting/setting.component.html index e116c5ae5..3cf2d2722 100644 --- a/src/workbench/browser/src/app/shared/components/setting/setting.component.html +++ b/src/workbench/browser/src/app/shared/components/setting/setting.component.html @@ -53,7 +53,7 @@

{{ module.title }}

- +
diff --git a/src/workbench/browser/src/app/shared/components/shadow/shadow-dom-encapsulation.component.ts b/src/workbench/browser/src/app/shared/components/shadow/shadow-dom-encapsulation.component.ts index 77fe00506..8d12d58a1 100644 --- a/src/workbench/browser/src/app/shared/components/shadow/shadow-dom-encapsulation.component.ts +++ b/src/workbench/browser/src/app/shared/components/shadow/shadow-dom-encapsulation.component.ts @@ -3,25 +3,41 @@ import MarkdownIt from 'markdown-it/dist/markdown-it'; @Component({ selector: 'eo-shadow-dom', - template: `
`, - styles: ['h2, .shadow-message { color: blue; }'], + template: `
`, + styles: [], encapsulation: ViewEncapsulation.ShadowDom, }) export class ShadowDomEncapsulationComponent implements OnInit { - md = new MarkdownIt(); + md: MarkdownIt; - @Input() html = ''; + @Input() text = ''; + @Input() options = { + html: false, + }; + + get content() { + const html = this.md.render(this.text || ''); + if (html && this.options.html) { + const domParser = new DOMParser(); + const doc = domParser.parseFromString(html, 'text/html'); + const a = doc.querySelectorAll('a'); + a.forEach((n) => n.setAttribute('target', '_blank')); + return doc.body.innerHTML; + } else { + return html; + } + } + + constructor() {} ngOnInit() { + this.md = new MarkdownIt(this.options); this.customLinkRender(); } customLinkRender() { const defaultRender = - this.md.renderer.rules.link_open || - function (tokens, idx, options, env, self) { - return self.renderToken(tokens, idx, options); - }; + this.md.renderer.rules.link_open || ((tokens, idx, options, env, self) => self.renderToken(tokens, idx, options)); this.md.renderer.rules.link_open = (tokens, idx, options, env, self) => { // If you are sure other plugins can't add `target` - drop check below