From 72f9bd5ef560be52528ecc1f105cce903a37a3c9 Mon Sep 17 00:00:00 2001 From: zernonia <59365435+zernonia@users.noreply.github.com> Date: Thu, 14 Mar 2024 18:28:13 +0800 Subject: [PATCH] refactor: code preview (#411) * feat: generate code dynamically * chore: cleanup and transform path on component * feat: create config sheet * feat: code wrapper * fix: not acting immediately * chore: add key to vnode * chore: add vue-sonner to demos dependencies, add placeholder for codeConfigs * chore: fix wrong icons * chore: improve crawling logic --------- Co-authored-by: Sadegh Barati --- apps/www/.vitepress/config.mts | 9 +- .../theme/components/CodeConfigCustomizer.vue | 98 +++++++++++++++++++ .../theme/components/CodeSandbox.vue | 11 ++- .../theme/components/CodeWrapper.ts | 46 +++++++++ .../theme/components/ComponentPreview.vue | 39 ++++++-- .../theme/components/Stackblitz.vue | 10 +- apps/www/.vitepress/theme/components/index.ts | 1 + apps/www/.vitepress/theme/config/shiki.ts | 6 ++ .../.vitepress/theme/layout/MainLayout.vue | 20 ++-- .../.vitepress/theme/plugins/codewrapper.ts | 20 ++++ .../www/.vitepress/theme/plugins/previewer.ts | 32 +----- apps/www/.vitepress/theme/plugins/utils.ts | 31 ------ apps/www/.vitepress/theme/utils/codeeditor.ts | 11 +-- apps/www/package.json | 1 + .../default/example/InputWithIcon.vue | 4 +- .../registry/new-york/example/DrawerDemo.vue | 6 +- apps/www/src/stores/config.ts | 31 +++++- apps/www/tsconfig.json | 2 +- pnpm-lock.yaml | 3 + 19 files changed, 278 insertions(+), 103 deletions(-) create mode 100644 apps/www/.vitepress/theme/components/CodeConfigCustomizer.vue create mode 100644 apps/www/.vitepress/theme/components/CodeWrapper.ts create mode 100644 apps/www/.vitepress/theme/config/shiki.ts create mode 100644 apps/www/.vitepress/theme/plugins/codewrapper.ts diff --git a/apps/www/.vitepress/config.mts b/apps/www/.vitepress/config.mts index 69ffd5f9..d729444e 100644 --- a/apps/www/.vitepress/config.mts +++ b/apps/www/.vitepress/config.mts @@ -3,16 +3,12 @@ import { defineConfig } from 'vitepress' import Icons from 'unplugin-icons/vite' import tailwind from 'tailwindcss' import autoprefixer from 'autoprefixer' -import { createCssVariablesTheme } from 'shiki' +import { cssVariables } from './theme/config/shiki' // import { transformerMetaWordHighlight, transformerNotationWordHighlight } from '@shikijs/transformers' import { siteConfig } from './theme/config/site' import ComponentPreviewPlugin from './theme/plugins/previewer' - -const cssVariables = createCssVariablesTheme({ - variablePrefix: '--shiki-', - variableDefaults: {}, -}) +import CodeWrapperPlugin from './theme/plugins/codewrapper' // https://vitepress.dev/reference/site-config export default defineConfig({ @@ -65,6 +61,7 @@ export default defineConfig({ ], config(md) { md.use(ComponentPreviewPlugin) + md.use(CodeWrapperPlugin) }, }, rewrites: { diff --git a/apps/www/.vitepress/theme/components/CodeConfigCustomizer.vue b/apps/www/.vitepress/theme/components/CodeConfigCustomizer.vue new file mode 100644 index 00000000..fa85049a --- /dev/null +++ b/apps/www/.vitepress/theme/components/CodeConfigCustomizer.vue @@ -0,0 +1,98 @@ + + + diff --git a/apps/www/.vitepress/theme/components/CodeSandbox.vue b/apps/www/.vitepress/theme/components/CodeSandbox.vue index 8b55d399..ce594013 100644 --- a/apps/www/.vitepress/theme/components/CodeSandbox.vue +++ b/apps/www/.vitepress/theme/components/CodeSandbox.vue @@ -1,10 +1,10 @@