From 09cf6d56a83492c0270d34ac30bd108d4ed4bebb Mon Sep 17 00:00:00 2001 From: zernonia Date: Sat, 23 Mar 2024 14:38:22 +0800 Subject: [PATCH 1/7] chore: build registry --- apps/www/__registry__/index.ts | 14 ++++++++++++++ apps/www/src/lib/registry/registry.ts | 21 ++++++++++++--------- apps/www/src/lib/registry/schema.ts | 1 + 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/apps/www/__registry__/index.ts b/apps/www/__registry__/index.ts index 92472ada4..01ba753b2 100644 --- a/apps/www/__registry__/index.ts +++ b/apps/www/__registry__/index.ts @@ -1102,6 +1102,13 @@ export const Index = { component: () => import("../src/lib/registry/default/example/Cards/Metric.vue").then((m) => m.default), files: ["../src/lib/registry/default/example/Cards/Metric.vue"], }, + "Authentication01": { + name: "Authentication01", + type: "components:block", + registryDependencies: ["button","card","input","label"], + component: () => import("../src/lib/registry/default/block/Authentication01.vue").then((m) => m.default), + files: ["../src/lib/registry/default/block/Authentication01.vue"], + }, }, "new-york": { "AccordionDemo": { name: "AccordionDemo", @@ -2202,5 +2209,12 @@ export const Index = { component: () => import("../src/lib/registry/new-york/example/Cards/Metric.vue").then((m) => m.default), files: ["../src/lib/registry/new-york/example/Cards/Metric.vue"], }, + "Authentication01": { + name: "Authentication01", + type: "components:block", + registryDependencies: ["button","card","input","label"], + component: () => import("../src/lib/registry/new-york/block/Authentication01.vue").then((m) => m.default), + files: ["../src/lib/registry/new-york/block/Authentication01.vue"], + }, }, } diff --git a/apps/www/src/lib/registry/registry.ts b/apps/www/src/lib/registry/registry.ts index 2205d062c..5ad0acd9d 100644 --- a/apps/www/src/lib/registry/registry.ts +++ b/apps/www/src/lib/registry/registry.ts @@ -27,9 +27,12 @@ export async function buildRegistry() { const uiRegistry = await crawlUI(ui_path) const example_path = resolve('./src/lib/registry/default/example') - const exampleRegistry = await crawlExample(example_path) + const exampleRegistry = await crawlDirectory(example_path, 'example') - return uiRegistry.concat(exampleRegistry) + const block_path = resolve('./src/lib/registry/default/block') + const blockRegistry = await crawlDirectory(block_path, 'block') + + return uiRegistry.concat(exampleRegistry).concat(blockRegistry) } async function crawlUI(rootPath: string) { @@ -53,15 +56,15 @@ async function crawlUI(rootPath: string) { return uiRegistry } -async function crawlExample(rootPath: string) { - const type = 'components:example' +async function crawlDirectory(rootPath: string, typeName: 'example' | 'block') { + const type = `components:${typeName}` as const const dir = await readdir(rootPath, { recursive: true, withFileTypes: true, }) - const exampleRegistry: Registry = [] + const registry: Registry = [] for (const dirent of dir) { if (dirent.name === 'index.ts') @@ -69,11 +72,11 @@ async function crawlExample(rootPath: string) { if (dirent.isFile()) { const [name] = dirent.name.split('.vue') - const file_path = join('example', normalize(dirent.path).split('/example')[1], dirent.name) + const file_path = join(typeName, normalize(dirent.path).split(`/${typeName}`)[1], dirent.name) const { dependencies, registryDependencies } = await getDependencies(join(dirent.path, dirent.name)) - exampleRegistry.push({ + registry.push({ name, type, files: [file_path], @@ -87,14 +90,14 @@ async function crawlExample(rootPath: string) { // if (dirent.isDirectory()) { // const componentPath = resolve(rootPath, dirent.name); // const ui = await buildUIRegistry(componentPath, dirent.name); - // exampleRegistry.push({ + // registry.push({ // ...ui, // type // }); // } } - return exampleRegistry + return registry } async function buildUIRegistry(componentPath: string, componentName: string) { diff --git a/apps/www/src/lib/registry/schema.ts b/apps/www/src/lib/registry/schema.ts index 36b224541..94387a372 100644 --- a/apps/www/src/lib/registry/schema.ts +++ b/apps/www/src/lib/registry/schema.ts @@ -10,6 +10,7 @@ export const registrySchema = z.array( 'components:ui', 'components:component', 'components:example', + 'components:block', ]), }), ) From cb962888ab339306a40ca87d1a8168d75eae9479 Mon Sep 17 00:00:00 2001 From: zernonia Date: Sat, 23 Mar 2024 16:18:28 +0800 Subject: [PATCH 2/7] feat: block preview --- .../theme/components/BlockPreview.vue | 234 ++++++++++++++++++ .../.vitepress/theme/components/Blocks.vue | 63 +++++ .../theme/components/ComponentLoader.vue | 3 +- .../theme/components/ComponentPreview.vue | 2 +- apps/www/.vitepress/theme/config/docs.ts | 4 + apps/www/src/content/blocks.md | 9 + .../default/block/Authentication01.vue | 41 +++ .../new-york/block/Authentication01.vue | 41 +++ 8 files changed, 395 insertions(+), 2 deletions(-) create mode 100644 apps/www/.vitepress/theme/components/BlockPreview.vue create mode 100644 apps/www/.vitepress/theme/components/Blocks.vue create mode 100644 apps/www/src/content/blocks.md create mode 100644 apps/www/src/lib/registry/default/block/Authentication01.vue create mode 100644 apps/www/src/lib/registry/new-york/block/Authentication01.vue diff --git a/apps/www/.vitepress/theme/components/BlockPreview.vue b/apps/www/.vitepress/theme/components/BlockPreview.vue new file mode 100644 index 000000000..10352231d --- /dev/null +++ b/apps/www/.vitepress/theme/components/BlockPreview.vue @@ -0,0 +1,234 @@ + + + diff --git a/apps/www/.vitepress/theme/components/Blocks.vue b/apps/www/.vitepress/theme/components/Blocks.vue new file mode 100644 index 000000000..0b60c559e --- /dev/null +++ b/apps/www/.vitepress/theme/components/Blocks.vue @@ -0,0 +1,63 @@ + + + diff --git a/apps/www/.vitepress/theme/components/ComponentLoader.vue b/apps/www/.vitepress/theme/components/ComponentLoader.vue index fa3d533ec..b57c59d5c 100644 --- a/apps/www/.vitepress/theme/components/ComponentLoader.vue +++ b/apps/www/.vitepress/theme/components/ComponentLoader.vue @@ -5,12 +5,13 @@ import { useConfigStore } from '@/stores/config' const props = defineProps<{ name: string + typeName?: 'example' | 'block' }>() const { style } = useConfigStore() const Component = defineAsyncComponent({ loadingComponent: Spinner, - loader: () => import(`../../../src/lib/registry/${style.value}/example/${props.name}.vue`), + loader: () => import(`../../../src/lib/registry/${style.value}/${props.typeName}/${props.name}.vue`), timeout: 5000, }) diff --git a/apps/www/.vitepress/theme/components/ComponentPreview.vue b/apps/www/.vitepress/theme/components/ComponentPreview.vue index cc42bd56c..bcf9629bf 100644 --- a/apps/www/.vitepress/theme/components/ComponentPreview.vue +++ b/apps/www/.vitepress/theme/components/ComponentPreview.vue @@ -83,7 +83,7 @@ watch([style, codeConfig], async () => { 'items-end': align === 'end', })" > - + diff --git a/apps/www/.vitepress/theme/config/docs.ts b/apps/www/.vitepress/theme/config/docs.ts index 31187fdc7..a3056849a 100644 --- a/apps/www/.vitepress/theme/config/docs.ts +++ b/apps/www/.vitepress/theme/config/docs.ts @@ -38,6 +38,10 @@ export const docsConfig: DocsConfig = { title: 'Examples', href: '/examples/mail', }, + { + title: 'Blocks', + href: '/blocks', + }, { title: 'GitHub', href: 'https://github.com/radix-vue/shadcn-vue', diff --git a/apps/www/src/content/blocks.md b/apps/www/src/content/blocks.md new file mode 100644 index 000000000..82408799f --- /dev/null +++ b/apps/www/src/content/blocks.md @@ -0,0 +1,9 @@ +--- +title: Blocks - shadcn-vue +--- + + + + diff --git a/apps/www/src/lib/registry/default/block/Authentication01.vue b/apps/www/src/lib/registry/default/block/Authentication01.vue new file mode 100644 index 000000000..05760fe1b --- /dev/null +++ b/apps/www/src/lib/registry/default/block/Authentication01.vue @@ -0,0 +1,41 @@ + + + + + diff --git a/apps/www/src/lib/registry/new-york/block/Authentication01.vue b/apps/www/src/lib/registry/new-york/block/Authentication01.vue new file mode 100644 index 000000000..a679a45ff --- /dev/null +++ b/apps/www/src/lib/registry/new-york/block/Authentication01.vue @@ -0,0 +1,41 @@ + + + + + From 6c66e974e52492477f687d9253546aafb97d3cb6 Mon Sep 17 00:00:00 2001 From: zernonia Date: Sat, 23 Mar 2024 17:19:01 +0800 Subject: [PATCH 3/7] refactor: change to use iframe feat: add more blocks --- .../.vitepress/theme/components/BlockPage.vue | 12 +++ .../theme/components/BlockPreview.vue | 22 ++++-- .../.vitepress/theme/components/Blocks.vue | 2 +- .../.vitepress/theme/layout/MainLayout.vue | 7 +- apps/www/__registry__/index.ts | 42 +++++++++++ apps/www/src/content/blocks/renderer.md | 10 +++ .../default/block/Authentication01.vue | 2 +- .../default/block/Authentication02.vue | 60 +++++++++++++++ .../default/block/Authentication03.vue | 65 +++++++++++++++++ .../default/block/Authentication04.vue | 73 +++++++++++++++++++ .../new-york/block/Authentication01.vue | 2 +- .../new-york/block/Authentication02.vue | 60 +++++++++++++++ .../new-york/block/Authentication03.vue | 65 +++++++++++++++++ .../new-york/block/Authentication04.vue | 73 +++++++++++++++++++ apps/www/src/public/placeholder.svg | 1 + 15 files changed, 485 insertions(+), 11 deletions(-) create mode 100644 apps/www/.vitepress/theme/components/BlockPage.vue create mode 100644 apps/www/src/content/blocks/renderer.md create mode 100644 apps/www/src/lib/registry/default/block/Authentication02.vue create mode 100644 apps/www/src/lib/registry/default/block/Authentication03.vue create mode 100644 apps/www/src/lib/registry/default/block/Authentication04.vue create mode 100644 apps/www/src/lib/registry/new-york/block/Authentication02.vue create mode 100644 apps/www/src/lib/registry/new-york/block/Authentication03.vue create mode 100644 apps/www/src/lib/registry/new-york/block/Authentication04.vue create mode 100644 apps/www/src/public/placeholder.svg diff --git a/apps/www/.vitepress/theme/components/BlockPage.vue b/apps/www/.vitepress/theme/components/BlockPage.vue new file mode 100644 index 000000000..69e58caaa --- /dev/null +++ b/apps/www/.vitepress/theme/components/BlockPage.vue @@ -0,0 +1,12 @@ + + + diff --git a/apps/www/.vitepress/theme/components/BlockPreview.vue b/apps/www/.vitepress/theme/components/BlockPreview.vue index 10352231d..c1f6edc12 100644 --- a/apps/www/.vitepress/theme/components/BlockPreview.vue +++ b/apps/www/.vitepress/theme/components/BlockPreview.vue @@ -7,7 +7,6 @@ import MagicString from 'magic-string' import { cssVariables } from '../config/shiki' import StyleSwitcher from './StyleSwitcher.vue' import Spinner from './Spinner.vue' -import ComponentLoader from './ComponentLoader.vue' import { useConfigStore } from '@/stores/config' // import { BlockCopyCodeButton } from '@/components/block-copy-code-button' @@ -26,7 +25,10 @@ const props = defineProps<{ const { style, codeConfig } = useConfigStore() +const isLoading = ref(true) +const tabValue = ref('preview') const resizableRef = ref>() + const rawString = ref('') const codeHtml = ref('') const metadata = reactive({ @@ -90,10 +92,10 @@ watch([style, codeConfig], async () => {