From 60f991c7ed10f62dd8fc3a65b838b7d30ecf3e1e Mon Sep 17 00:00:00 2001 From: mantou132 <709922234@qq.com> Date: Sat, 16 Dec 2023 21:20:09 +0800 Subject: [PATCH] Use esm.sh --- .vscode/settings.json | 2 +- .../duoyun-ui/docs/en/02-elements/code-block.md | 5 +++-- packages/duoyun-ui/docs/zh/02-elements/README.md | 2 +- .../duoyun-ui/docs/zh/02-elements/code-block.md | 5 +++-- packages/duoyun-ui/package.json | 16 ++++++++++++++-- packages/duoyun-ui/src/elements/code-block.ts | 9 +++++---- packages/gem-book/src/element/elements/plugin.ts | 6 +++--- packages/gem-book/src/element/elements/pre.ts | 4 ++-- packages/gem-book/src/element/store.ts | 6 +++--- packages/gem-book/src/plugins/api.ts | 9 +++++---- packages/gem-book/src/plugins/comment.ts | 7 ++++--- packages/gem-book/src/plugins/docsearch.ts | 4 ++-- packages/gem-examples/package.json | 2 +- packages/gem/docs/en/001-guide/README.md | 2 +- packages/gem/docs/zh/001-guide/README.md | 2 +- 15 files changed, 49 insertions(+), 32 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 2d83d16d..0c08b95b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,6 +16,6 @@ "editor.formatOnSave": false }, "editor.codeActionsOnSave": { - "source.fixAll": true + "source.fixAll": "explicit" } } diff --git a/packages/duoyun-ui/docs/en/02-elements/code-block.md b/packages/duoyun-ui/docs/en/02-elements/code-block.md index 37e69e72..b3dd6465 100644 --- a/packages/duoyun-ui/docs/en/02-elements/code-block.md +++ b/packages/duoyun-ui/docs/en/02-elements/code-block.md @@ -14,8 +14,9 @@ &lt;a&gt;The freeCodeCamp Contribution Page&lt;/a&gt; shows you how and where you can contribute to freeCodeCamps community and growth. &lt;/p&gt; &lt;/body&gt; -&lt;/html&gt;' - props='{"style": "width: 100%", "codelang": "html"}' +&lt;/html&gt; +Test' + props='{"style": "width: 100%", "codelang": "html", "range": "-11", "highlight": "8"}' src="https://jspm.dev/duoyun-ui/elements/code-block"> ## API diff --git a/packages/duoyun-ui/docs/zh/02-elements/README.md b/packages/duoyun-ui/docs/zh/02-elements/README.md index bf14a181..4bdd2d62 100644 --- a/packages/duoyun-ui/docs/zh/02-elements/README.md +++ b/packages/duoyun-ui/docs/zh/02-elements/README.md @@ -1,4 +1,4 @@ -# 索引 +# 元素索引 | DuoyunUI | AntD | Element Plus | | -------------------------------------------------- | ------------------------------------------- | ---------------------------------------- | diff --git a/packages/duoyun-ui/docs/zh/02-elements/code-block.md b/packages/duoyun-ui/docs/zh/02-elements/code-block.md index 37e69e72..b3dd6465 100644 --- a/packages/duoyun-ui/docs/zh/02-elements/code-block.md +++ b/packages/duoyun-ui/docs/zh/02-elements/code-block.md @@ -14,8 +14,9 @@ &lt;a&gt;The freeCodeCamp Contribution Page&lt;/a&gt; shows you how and where you can contribute to freeCodeCamps community and growth. &lt;/p&gt; &lt;/body&gt; -&lt;/html&gt;' - props='{"style": "width: 100%", "codelang": "html"}' +&lt;/html&gt; +Test' + props='{"style": "width: 100%", "codelang": "html", "range": "-11", "highlight": "8"}' src="https://jspm.dev/duoyun-ui/elements/code-block"> ## API diff --git a/packages/duoyun-ui/package.json b/packages/duoyun-ui/package.json index a6241668..b609e713 100644 --- a/packages/duoyun-ui/package.json +++ b/packages/duoyun-ui/package.json @@ -1,7 +1,19 @@ { "name": "duoyun-ui", - "version": "1.1.0", - "description": "WebComponts UI", + "version": "1.1.2", + "description": "A lightweight desktop UI component library, implemented using Gem", + "keywords": [ + "frontend", + "components", + "react", + "vue", + "svelte", + "gem", + "ui" + ], + "esm.sh": { + "bundle": false + }, "exports": { "./elements/*": "./elements/*.js", "./react/*": "./react/*.js", diff --git a/packages/duoyun-ui/src/elements/code-block.ts b/packages/duoyun-ui/src/elements/code-block.ts index df4a7523..373d53f8 100644 --- a/packages/duoyun-ui/src/elements/code-block.ts +++ b/packages/duoyun-ui/src/elements/code-block.ts @@ -5,6 +5,8 @@ import { createCSSSheet, css, styleMap } from '@mantou/gem/lib/utils'; import { theme } from '../lib/theme'; +const prismjs = 'https://esm.sh/prismjs@v1.26.0'; + // https://github.com/PrismJS/prism/blob/master/plugins/autoloader/prism-autoloader.js const langDependencies: Record = { javascript: 'clike', @@ -358,8 +360,7 @@ export class DuoyunCodeBlockElement extends GemElement { this.effect( async () => { if (!this.codeRef.element) return; - const esmHost = 'https://cdn.skypack.dev/prismjs@v1.26.0'; - await import(/* @vite-ignore */ /* webpackIgnore: true */ `${esmHost}?min`); + await import(/* @vite-ignore */ /* webpackIgnore: true */ prismjs); const { Prism } = window as any; if (this.codelang && !Prism.languages[this.codelang]) { const lang = langAliases[this.codelang] || this.codelang; @@ -369,12 +370,12 @@ export class DuoyunCodeBlockElement extends GemElement { langDeps.map((langDep) => { if (!Prism.languages[langDep]) { return import( - /* @vite-ignore */ /* webpackIgnore: true */ `${esmHost}/components/prism-${langDep}.min.js` + /* @vite-ignore */ /* webpackIgnore: true */ `${prismjs}/components/prism-${langDep}.min.js` ); } }), ); - await import(/* @vite-ignore */ /* webpackIgnore: true */ `${esmHost}/components/prism-${lang}.min.js`); + await import(/* @vite-ignore */ /* webpackIgnore: true */ `${prismjs}/components/prism-${lang}.min.js`); } catch { // } diff --git a/packages/gem-book/src/element/elements/plugin.ts b/packages/gem-book/src/element/elements/plugin.ts index 51369141..7a6f622d 100644 --- a/packages/gem-book/src/element/elements/plugin.ts +++ b/packages/gem-book/src/element/elements/plugin.ts @@ -23,9 +23,6 @@ export class GemBookPluginElement extends GemElement { }, }, ); - static get devMode() { - return bookStore.devMode; - } static get links() { return bookStore.links; } @@ -50,6 +47,9 @@ export class GemBookPluginElement extends GemElement { static get currentLinks() { return bookStore.currentLinks; } + static get devMode() { + return bookStore.isDevMode?.(); + } static get currentLink() { return bookStore.getCurrentLink?.(); } diff --git a/packages/gem-book/src/element/elements/pre.ts b/packages/gem-book/src/element/elements/pre.ts index 118b2c63..daf875b5 100644 --- a/packages/gem-book/src/element/elements/pre.ts +++ b/packages/gem-book/src/element/elements/pre.ts @@ -4,7 +4,7 @@ import { styleMap } from '@mantou/gem/lib/utils'; import { theme } from '../helper/theme'; -const prismjs = 'https://cdn.skypack.dev/prismjs@v1.26.0'; +const prismjs = 'https://esm.sh/prismjs@v1.26.0'; let contenteditableValue = 'true'; (() => { @@ -320,7 +320,7 @@ export class Pre extends GemElement { if (!this.getBoundingClientRect().width) return; if (this.status === 'hidden') return; if (!this.codeRef.element) return; - await import(/* @vite-ignore */ /* webpackIgnore: true */ `${prismjs}?min`); + await import(/* @vite-ignore */ /* webpackIgnore: true */ prismjs); const { Prism } = window as any; if (this.codelang && !Prism.languages[this.codelang]) { const lang = langAliases[this.codelang] || this.codelang; diff --git a/packages/gem-book/src/element/store.ts b/packages/gem-book/src/element/store.ts index d34ddca3..6972cd77 100644 --- a/packages/gem-book/src/element/store.ts +++ b/packages/gem-book/src/element/store.ts @@ -15,7 +15,6 @@ import './elements/main'; import './elements/404'; interface CurrentBookConfig { - devMode: boolean; config: BookConfig; links: NavItemWithLink[]; @@ -29,6 +28,7 @@ interface CurrentBookConfig { homePage: string; currentLinks: NavItemWithLink[]; getCurrentLink: () => NavItemWithLink; + isDevMode: () => boolean; } export const bookStore = createStore>({}); @@ -135,7 +135,7 @@ function getLinkRouters(links: NavItemWithLink[], title: string, lang: string, d async getContent() { const renderer = getRenderer({ lang, link: originLink, displayRank }); const content = await fetchDocument(originLink, lang, hash); - if (bookStore.devMode) await new Promise((res) => setTimeout(res, 500)); + if (bookStore.isDevMode?.()) await new Promise((res) => setTimeout(res, 500)); return html``; }, data: item, @@ -252,7 +252,7 @@ export function updateBookConfig(config?: BookConfig, gemBookElement?: GemBookEl }); if (gemBookElement) { updateStore(bookStore, { - devMode: gemBookElement.dev, + isDevMode: () => gemBookElement.dev, getCurrentLink: () => { return gemBookElement?.routeRef.element?.currentRoute?.data as NavItemWithLink; }, diff --git a/packages/gem-book/src/plugins/api.ts b/packages/gem-book/src/plugins/api.ts index 26bfda8d..ce38d329 100644 --- a/packages/gem-book/src/plugins/api.ts +++ b/packages/gem-book/src/plugins/api.ts @@ -7,7 +7,7 @@ import type { Main } from '../element/elements/main'; import type { GemBookElement } from '../element'; const tsMorph = 'https://esm.sh/ts-morph@13.0.3'; -const gemAnalyzer = 'https://jspm.dev/gem-analyzer'; +const gemAnalyzer = 'https://esm.sh/gem-analyzer'; type State = { elements?: ElementDetail[]; exports?: ExportDetail[]; error?: any }; @@ -73,9 +73,10 @@ customElements.whenDefined('gem-book').then(() => { #parseFile = async (text: string) => { const { Project } = (await import(/* webpackIgnore: true */ tsMorph)) as typeof import('ts-morph'); - const { getElements, getExports } = GemBookPluginElement.devMode - ? await import('gem-analyzer') - : ((await import(/* webpackIgnore: true */ gemAnalyzer)) as typeof import('gem-analyzer')); + const { getElements, getExports } = + config.github === 'https://github.com/mantou132/gem' + ? await import('gem-analyzer') + : ((await import(/* webpackIgnore: true */ gemAnalyzer)) as typeof import('gem-analyzer')); const project = new Project({ useInMemoryFileSystem: true }); const file = project.createSourceFile(this.src, text); return { elements: getElements(file), exports: getExports(file) }; diff --git a/packages/gem-book/src/plugins/comment.ts b/packages/gem-book/src/plugins/comment.ts index 8c119a7e..c1684111 100644 --- a/packages/gem-book/src/plugins/comment.ts +++ b/packages/gem-book/src/plugins/comment.ts @@ -1,6 +1,7 @@ import type { GemBookElement } from '../element'; -const url = 'https://jspm.dev/gitalk@1.7.2'; +const gitalkUrl = 'https://esm.sh/gitalk@1.7.2'; +const gitalkCSSUrl = 'https://esm.sh/gitalk@1.7.2/dist/gitalk.css'; customElements.whenDefined('gem-book').then(async () => { const { GemBookPluginElement } = customElements.get('gem-book') as typeof GemBookElement; @@ -17,7 +18,7 @@ customElements.whenDefined('gem-book').then(async () => { render() { return html` - +