From 9527b1656f550820bc9b0e607f7d1f3e158b1a3f Mon Sep 17 00:00:00 2001 From: Sadegh Barati Date: Sun, 22 Oct 2023 00:32:39 +0330 Subject: [PATCH] docs: fix DataTable repro links --- .../theme/components/CodeSandbox.vue | 8 +++++ .../theme/components/ComponentPreview.vue | 5 +-- .../theme/components/Stackblitz.vue | 8 +++++ apps/www/.vitepress/theme/utils/codeeditor.ts | 35 +++++++++++++++---- .../src/content/docs/components/data-table.md | 4 +-- 5 files changed, 49 insertions(+), 11 deletions(-) diff --git a/apps/www/.vitepress/theme/components/CodeSandbox.vue b/apps/www/.vitepress/theme/components/CodeSandbox.vue index 8b55d399..09a83e3a 100644 --- a/apps/www/.vitepress/theme/components/CodeSandbox.vue +++ b/apps/www/.vitepress/theme/components/CodeSandbox.vue @@ -10,12 +10,20 @@ const props = defineProps<{ name: string code: string style: Style + extraFiles?: string[] }>() const sources = ref>({}) onMounted(() => { sources.value['App.vue'] = props.code + if (props.extraFiles) { + props.extraFiles.forEach((file) => { + import(`../../../src/lib/registry/${props.style}/example/${file}.vue?raw`).then((module) => { + sources.value[`${file}.vue`] = module.default + }) + }) + } }) diff --git a/apps/www/.vitepress/theme/components/ComponentPreview.vue b/apps/www/.vitepress/theme/components/ComponentPreview.vue index ed37d250..852ce98c 100644 --- a/apps/www/.vitepress/theme/components/ComponentPreview.vue +++ b/apps/www/.vitepress/theme/components/ComponentPreview.vue @@ -12,6 +12,7 @@ const props = withDefaults(defineProps<{ align?: 'center' | 'start' | 'end' sfcTsCode?: string sfcTsHtml?: string + extraFiles?: string[] }>(), { align: 'center' }) const { style } = useConfigStore() @@ -43,8 +44,8 @@ const { style } = useConfigStore()
- - + +
() const sources = ref>({}) onMounted(() => { sources.value['App.vue'] = props.code + if (props.extraFiles) { + props.extraFiles.forEach((file) => { + import(`../../../src/lib/registry/${props.style}/example/${file}.vue?raw`).then((module) => { + sources.value[`${file}.vue`] = module.default + }) + }) + } }) function handleClick() { diff --git a/apps/www/.vitepress/theme/utils/codeeditor.ts b/apps/www/.vitepress/theme/utils/codeeditor.ts index fd3ffe11..9bad78f5 100644 --- a/apps/www/.vitepress/theme/utils/codeeditor.ts +++ b/apps/www/.vitepress/theme/utils/codeeditor.ts @@ -75,8 +75,10 @@ function constructFiles(componentName: string, style: Style, sources: Record>(updaterOrValue: T, ref: Ref) { + ref.value + = typeof updaterOrValue === 'function' + ? updaterOrValue(ref.value) + : updaterOrValue +}` + const transformImportPath = (code: string) => { let parsed = code parsed = parsed.replaceAll(`@/lib/registry/${style}`, '@/components') @@ -159,13 +186,7 @@ function constructFiles(componentName: string, style: Style, sources: Record + ## Introduction @@ -20,4 +20,4 @@ We'll start with the basic `` component and build a complex data table **Tip:** If you find yourself using the same table in multiple places in your app, you can always extract it into a reusable component. - \ No newline at end of file +