From 7fbfbf5e64be323ac35c7237954c22ce20f50f23 Mon Sep 17 00:00:00 2001 From: "X.Mo" Date: Mon, 28 Oct 2024 17:26:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vitepress/components/preview.vue | 41 +++++++ .vitepress/config.mts | 2 + .vitepress/plugins/previewPlugin.ts | 141 ++++++++++++++++++++++++ .vitepress/src/zh/sidebars.ts | 8 +- .vitepress/theme/index.ts | 5 + docs/demos/ma-dialog/index.vue | 11 ++ docs/demos/ma-echarts/index.vue | 11 ++ docs/demos/ma-form/index.vue | 11 ++ docs/demos/ma-pro-table/index.vue | 11 ++ docs/demos/ma-search/index.vue | 11 ++ docs/demos/ma-table/index.vue | 11 ++ docs/zh/front/component/ma-dialog.md | 1 + docs/zh/front/component/ma-echarts.md | 1 + docs/zh/front/component/ma-pro-table.md | 1 + docs/zh/front/component/ma-search.md | 1 + docs/zh/front/component/ma-table.md | 6 + package.json | 4 +- pnpm-lock.yaml | 24 ++-- 18 files changed, 283 insertions(+), 18 deletions(-) create mode 100644 .vitepress/components/preview.vue create mode 100644 .vitepress/plugins/previewPlugin.ts create mode 100644 docs/demos/ma-dialog/index.vue create mode 100644 docs/demos/ma-echarts/index.vue create mode 100644 docs/demos/ma-form/index.vue create mode 100644 docs/demos/ma-pro-table/index.vue create mode 100644 docs/demos/ma-search/index.vue create mode 100644 docs/demos/ma-table/index.vue create mode 100644 docs/zh/front/component/ma-dialog.md create mode 100644 docs/zh/front/component/ma-echarts.md create mode 100644 docs/zh/front/component/ma-pro-table.md create mode 100644 docs/zh/front/component/ma-search.md create mode 100644 docs/zh/front/component/ma-table.md diff --git a/.vitepress/components/preview.vue b/.vitepress/components/preview.vue new file mode 100644 index 0000000..74a87dc --- /dev/null +++ b/.vitepress/components/preview.vue @@ -0,0 +1,41 @@ + + + + + \ No newline at end of file diff --git a/.vitepress/config.mts b/.vitepress/config.mts index 435ce0e..b9e9039 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -7,6 +7,7 @@ import zhGetSidebar from "./src/zh/sidebars"; import enGetSidebar from "./src/en/sidebars"; import { AnnouncementPlugin } from 'vitepress-plugin-announcement' import { plantuml } from "@mdit/plugin-plantuml"; +import { previewPlugin } from './plugins/previewPlugin' import UnoCSS from 'unocss/vite' // https://vitepress.dev/reference/site-config @@ -122,6 +123,7 @@ export default defineConfigWithTheme ({ srcDir: 'docs', markdown:{ config:(md:MarkdownRenderer)=>{ + md.use(previewPlugin) md.use(plantuml,{ type:"fence", fence:"plantuml", diff --git a/.vitepress/plugins/previewPlugin.ts b/.vitepress/plugins/previewPlugin.ts new file mode 100644 index 0000000..82a4c6c --- /dev/null +++ b/.vitepress/plugins/previewPlugin.ts @@ -0,0 +1,141 @@ +import type { MarkdownEnv, MarkdownRenderer } from 'vitepress' + +import crypto from 'node:crypto' +import { readdirSync } from 'node:fs' +import { join } from 'node:path' + +export const rawPathRegexp = /^(.+?(?:\.([\da-z]+))?)(#[\w-]+)?(?: ?{(\d+(?:[,-]\d+)*)? ?(\S+)?})? ?(?:\[(.+)])?$/; + +function rawPathToToken(rawPath: string) { + const [ + filepath = '', + extension = '', + region = '', + lines = '', + lang = '', + rawTitle = '', + ] = (rawPathRegexp.exec(rawPath) || []).slice(1); + + const title = rawTitle || filepath.split('/').pop() || ''; + + return { extension, filepath, lang, lines, region, title }; +} + +export const previewPlugin = (md: MarkdownRenderer) => { + md.core.ruler.after('inline', 'preview', (state) => { + const insertComponentImport = (importString: string) => { + const index = state.tokens.findIndex( + (i) => i.type === 'html_block' && i.content.match(/\n`; + state.tokens.splice(0, 0, importComponent); + } else { + if (state.tokens[index]) { + const content = state.tokens[index].content; + state.tokens[index].content = content.replace( + '', + `${importString}\n`, + ); + } + } + }; + // Define the regular expression to match the desired pattern + const regex = /]*\sdir="([^"]*)"/g; + // Iterate through the Markdown content and replace the pattern + state.src = state.src.replaceAll(regex, (_match, dir) => { + const componentDir = join(process.cwd(), 'docs', dir).replaceAll( + '\\', + '/', + ); + + let childFiles: string[] = []; + let dirExists = true; + + try { + childFiles = + readdirSync(componentDir, { + encoding: 'utf8', + recursive: false, + withFileTypes: false, + }) || []; + } catch { + dirExists = false; + } + + if (!dirExists) { + return ''; + } + + const uniqueWord = generateContentHash(componentDir); + + const ComponentName = `DemoComponent_${uniqueWord}`; + insertComponentImport( + `import ${ComponentName} from '${componentDir}/index.vue'`, + ); + const { path: _path } = state.env as MarkdownEnv; + + const index = state.tokens.findIndex((i) => i.content.match(regex)); + + if (!state.tokens[index]) { + return ''; + } + const firstString = 'index.vue'; + childFiles = childFiles.sort((a, b) => { + if (a === firstString) return -1; + if (b === firstString) return 1; + return a.localeCompare(b, 'en', { sensitivity: 'base' }); + }); + state.tokens[index].content = + `<${ComponentName}/> + `; + + const _dummyToken = new state.Token('', '', 0); + const tokenArray: Array = []; + childFiles.forEach((filename) => { + // const slotName = filename.replace(extname(filename), ''); + + const templateStart = new state.Token('html_inline', '', 0); + templateStart.content = `'; + tokenArray.push(templateEnd); + }); + const endTag = new state.Token('html_inline', '', 0); + endTag.content = ''; + tokenArray.push(endTag); + + state.tokens.splice(index + 1, 0, ...tokenArray); + + // console.log( + // state.md.renderer.render(state.tokens, state?.options ?? [], state.env), + // ); + return ''; + }); + }); +}; + +function generateContentHash(input: string, length: number = 10): string { + // 使用 SHA-256 生成哈希值 + const hash = crypto.createHash('sha256').update(input).digest('hex'); + + // 将哈希值转换为 Base36 编码,并取指定长度的字符作为结果 + return Number.parseInt(hash, 16).toString(36).slice(0, length); +} \ No newline at end of file diff --git a/.vitepress/src/zh/sidebars.ts b/.vitepress/src/zh/sidebars.ts index 1f971c4..9a13d9f 100644 --- a/.vitepress/src/zh/sidebars.ts +++ b/.vitepress/src/zh/sidebars.ts @@ -161,14 +161,14 @@ const sidebar:DefaultTheme.Sidebar = { text: 'MaTable', link: '/zh/front/component/ma-table' }, - { - text: 'MaProTable', - link: '/zh/front/component/ma-pro-table' - }, { text: 'MaSearch', link: '/zh/front/component/ma-search' }, + { + text: 'MaProTable', + link: '/zh/front/component/ma-pro-table' + }, { text: 'MaEcharts', link: '/zh/front/component/ma-echarts' diff --git a/.vitepress/theme/index.ts b/.vitepress/theme/index.ts index 4dfc816..895cb51 100644 --- a/.vitepress/theme/index.ts +++ b/.vitepress/theme/index.ts @@ -40,6 +40,8 @@ import { baiduPlugin } from "./plugin/baidu"; import "virtual:uno.css"; +import Preview from '../components/preview.vue'; + export default { enhanceApp(ctx: EnhanceAppContext) { @@ -57,6 +59,9 @@ export default { }, app, }) + + app.component('Preview', Preview) + baiduPlugin() }, extends: DefaultTheme, diff --git a/docs/demos/ma-dialog/index.vue b/docs/demos/ma-dialog/index.vue new file mode 100644 index 0000000..96c0baf --- /dev/null +++ b/docs/demos/ma-dialog/index.vue @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/docs/demos/ma-echarts/index.vue b/docs/demos/ma-echarts/index.vue new file mode 100644 index 0000000..96c0baf --- /dev/null +++ b/docs/demos/ma-echarts/index.vue @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/docs/demos/ma-form/index.vue b/docs/demos/ma-form/index.vue new file mode 100644 index 0000000..96c0baf --- /dev/null +++ b/docs/demos/ma-form/index.vue @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/docs/demos/ma-pro-table/index.vue b/docs/demos/ma-pro-table/index.vue new file mode 100644 index 0000000..96c0baf --- /dev/null +++ b/docs/demos/ma-pro-table/index.vue @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/docs/demos/ma-search/index.vue b/docs/demos/ma-search/index.vue new file mode 100644 index 0000000..96c0baf --- /dev/null +++ b/docs/demos/ma-search/index.vue @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/docs/demos/ma-table/index.vue b/docs/demos/ma-table/index.vue new file mode 100644 index 0000000..96c0baf --- /dev/null +++ b/docs/demos/ma-table/index.vue @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/docs/zh/front/component/ma-dialog.md b/docs/zh/front/component/ma-dialog.md new file mode 100644 index 0000000..5f3400f --- /dev/null +++ b/docs/zh/front/component/ma-dialog.md @@ -0,0 +1 @@ +# MaDialog diff --git a/docs/zh/front/component/ma-echarts.md b/docs/zh/front/component/ma-echarts.md new file mode 100644 index 0000000..726b172 --- /dev/null +++ b/docs/zh/front/component/ma-echarts.md @@ -0,0 +1 @@ +# MaEcharts diff --git a/docs/zh/front/component/ma-pro-table.md b/docs/zh/front/component/ma-pro-table.md new file mode 100644 index 0000000..20ec03e --- /dev/null +++ b/docs/zh/front/component/ma-pro-table.md @@ -0,0 +1 @@ +# MaProTable diff --git a/docs/zh/front/component/ma-search.md b/docs/zh/front/component/ma-search.md new file mode 100644 index 0000000..30bb182 --- /dev/null +++ b/docs/zh/front/component/ma-search.md @@ -0,0 +1 @@ +# MaSearch diff --git a/docs/zh/front/component/ma-table.md b/docs/zh/front/component/ma-table.md new file mode 100644 index 0000000..0a6a714 --- /dev/null +++ b/docs/zh/front/component/ma-table.md @@ -0,0 +1,6 @@ +# MaTable + +二次封装的 `Table` 组件,非常好用。 + + + diff --git a/package.json b/package.json index 4e74c58..76b0eff 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,9 @@ "@imengyu/vue3-context-menu": "^1.4.2", "@mineadmin/echarts": "^1.0.1", "@mineadmin/form": "^1.0.20", - "@mineadmin/pro-table": "^1.0.19", + "@mineadmin/pro-table": "^1.0.22", "@mineadmin/search": "^1.0.19", - "@mineadmin/table": "^1.0.22", + "@mineadmin/table": "^1.0.23", "@vueuse/core": "^11.1.0", "@vueuse/integrations": "^11.1.0", "echarts": "^5.5.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b7b0ec8..6ed5d39 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,14 +18,14 @@ importers: specifier: ^1.0.20 version: 1.0.20(element-plus@2.8.3(vue@3.5.7)) '@mineadmin/pro-table': - specifier: ^1.0.19 - version: 1.0.19(element-plus@2.8.3(vue@3.5.7)) + specifier: ^1.0.22 + version: 1.0.22(element-plus@2.8.3(vue@3.5.7)) '@mineadmin/search': specifier: ^1.0.19 version: 1.0.19(element-plus@2.8.3(vue@3.5.7)) '@mineadmin/table': - specifier: ^1.0.22 - version: 1.0.22(element-plus@2.8.3(vue@3.5.7)) + specifier: ^1.0.23 + version: 1.0.23(element-plus@2.8.3(vue@3.5.7)) '@vueuse/core': specifier: ^11.1.0 version: 11.1.0(vue@3.5.7) @@ -564,8 +564,8 @@ packages: peerDependencies: element-plus: ^2.0.0 - '@mineadmin/pro-table@1.0.19': - resolution: {integrity: sha512-9QU5xISzT+c/+rrafHJb/5qtnvu2VteSWGwEGwR+wX3IuajSlaIq4iz72yOaN+GiYLOIJAf1Sq3RkV0BtfpFGw==} + '@mineadmin/pro-table@1.0.22': + resolution: {integrity: sha512-clx0VCW1uADnsFBGagUZydt/sFupJbzFRAWpig+wGF1Yi3tKaXiR5uMlgj5Ey+zRpRBBY7a+/WdWp4ucX8dSgw==} peerDependencies: element-plus: ^2.0.0 @@ -574,8 +574,8 @@ packages: peerDependencies: element-plus: ^2.0.0 - '@mineadmin/table@1.0.22': - resolution: {integrity: sha512-kfcHRJnHLJXc00TBruLlO86fFlaqL+Q3jqZRcThEOZY2PC3xXxIPYyc+LiQrAU6MBqNGjiL9xBx4WCQxZ8gXpQ==} + '@mineadmin/table@1.0.23': + resolution: {integrity: sha512-MgcUESYiBOfuT3H2WEIo0EENaTagMc9+zpg6g4GYKdxGiq2vHVO8ZWBerB+s7f1r3tQFMjHFqGbA91hzZlGqiw==} peerDependencies: element-plus: ^2.0.0 @@ -1978,10 +1978,10 @@ snapshots: transitivePeerDependencies: - typescript - '@mineadmin/pro-table@1.0.19(element-plus@2.8.3(vue@3.5.7))': + '@mineadmin/pro-table@1.0.22(element-plus@2.8.3(vue@3.5.7))': dependencies: element-plus: 2.8.3(vue@3.5.7) - vue: 3.5.7 + vue: 3.5.11 transitivePeerDependencies: - typescript @@ -1992,10 +1992,10 @@ snapshots: transitivePeerDependencies: - typescript - '@mineadmin/table@1.0.22(element-plus@2.8.3(vue@3.5.7))': + '@mineadmin/table@1.0.23(element-plus@2.8.3(vue@3.5.7))': dependencies: element-plus: 2.8.3(vue@3.5.7) - vue: 3.5.7 + vue: 3.5.11 transitivePeerDependencies: - typescript