Skip to content

Commit ebc9de8

Browse files
committed
pro view
1 parent 21f58bd commit ebc9de8

File tree

4 files changed

+25
-52
lines changed

4 files changed

+25
-52
lines changed

apps/www/content/docs/(plugins)/(ai)/ai.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ docs:
88

99

1010

11-
<BlockDisplay name="ai-demo" />
11+
{/* <BlockDisplay name="ai-demo" /> */}
1212

1313

14-
{/* <ComponentPreviewPro name="ai-pro" /> */}
14+
<ComponentPreviewPro name="ai-pro" />

apps/www/src/components/block-display.tsx

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,26 @@
11
import * as React from "react"
22

3-
import type { registryItemFileSchema } from "shadcn/registry"
3+
import type { RegistryItem, registryItemFileSchema } from "shadcn/registry"
44
import type { z } from "zod"
55

6-
import { Index } from "@/__registry__"
76
import { BlockViewer } from "@/components/block-viewer"
87
import { ComponentPreview } from "@/components/component-preview"
98
import { highlightCode } from "@/lib/highlight-code"
109
import { createFileTreeForRegistryItemFiles, getRegistryItem } from "@/lib/rehype-utils"
1110
import { cn } from "@/lib/utils"
1211

13-
import { Icons } from "./icons"
1412

15-
export async function BlockDisplay({ align, name, padding, ...props }: { id: string, name: string, align?: string, padding?: string, }) {
16-
const item = await getCachedRegistryItem(name)
13+
export async function BlockDisplay({ item: itemProp, name, ...props }: { id: string, item: RegistryItem; name: string, block?: boolean, }) {
14+
const item = itemProp ?? await getCachedRegistryItem(name)
1715

18-
19-
const Preview = () => {
20-
const Component = Index[name]?.component;
21-
22-
if (!Component) {
23-
return (
24-
<p className="text-sm text-muted-foreground">
25-
Component{' '}
26-
<code className="relative rounded bg-muted px-[0.3rem] py-[0.2rem] font-mono text-sm">
27-
{name}
28-
</code>{' '}
29-
not found in registry.
30-
</p>
31-
);
32-
}
33-
34-
// DIFF
35-
return <Component {...props} id={props.id ?? name.replace('-demo', '')} />;
36-
}
37-
38-
const loadingPreview = (
39-
<div className="preview flex size-full min-h-[350px] items-center justify-center p-0 text-sm text-muted-foreground">
40-
<Icons.spinner className="mr-2 size-4 animate-spin" />
41-
Loading...
42-
</div>
43-
);
44-
45-
46-
if (!item?.files) {
16+
if (!item?.files && !item.meta?.isPro) {
4717
return null
4818
}
4919

50-
const [tree, highlightedFiles] = await Promise.all([
20+
const [tree, highlightedFiles] = item.files ? await Promise.all([
5121
getCachedFileTree(item.files),
5222
getCachedHighlightedFiles(item.files),
53-
])
23+
]) : [null, null]
5424

5525
return (
5626
<BlockViewer highlightedFiles={highlightedFiles} item={item} tree={tree}

apps/www/src/components/block-viewer.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,19 @@ function BlockViewerToolbar() {
202202
)
203203
}
204204

205-
function BlockViewerIframe({ preview }: { preview?: React.ReactNode; }) {
205+
function BlockViewerIframe() {
206206
const { iframeKey, item } = useBlockViewer()
207207

208+
console.log("🚀 ~ BlockViewerIframe ~ item:", item)
209+
208210

209211
const Preview = React.useMemo(() => {
212+
213+
if(item.meta?.isPro) return null
214+
210215
const Component = Index[item.name]?.component;
211216

212-
if (!Component) {
217+
if (!Component ) {
213218
return (
214219
<p className="text-sm text-muted-foreground">
215220
Component{' '}
@@ -223,7 +228,7 @@ function BlockViewerIframe({ preview }: { preview?: React.ReactNode; }) {
223228

224229
// DIFF
225230
return <Component id={item.name.replace('-demo', '')} key={iframeKey} />;
226-
}, [item.name, iframeKey]);
231+
}, [item.name, item.meta?.isPro, iframeKey]);
227232

228233
return (
229234
Preview ?? <iframe
@@ -237,7 +242,7 @@ function BlockViewerIframe({ preview }: { preview?: React.ReactNode; }) {
237242
)
238243
}
239244

240-
function BlockViewerView({ preview }: { preview?: React.ReactNode; }) {
245+
function BlockViewerView() {
241246
const { resizablePanelRef } = useBlockViewer()
242247

243248
return (
@@ -254,7 +259,7 @@ function BlockViewerView({ preview }: { preview?: React.ReactNode; }) {
254259
defaultSize={100}
255260
minSize={30}
256261
>
257-
<BlockViewerIframe preview={preview} />
262+
<BlockViewerIframe />
258263
</ResizablePanel>
259264
<ResizableHandle className="after:bg-border relative hidden w-3 bg-transparent p-0 after:absolute after:top-1/2 after:right-0 after:h-8 after:w-[6px] after:translate-x-[-1px] after:-translate-y-1/2 after:rounded-full after:transition-all after:hover:h-10 md:block" />
260265
<ResizablePanel defaultSize={0} minSize={0} />
@@ -485,7 +490,7 @@ function BlockViewer({
485490
{...props}
486491
>
487492
<BlockViewerToolbar />
488-
<BlockViewerView preview={preview} />
493+
<BlockViewerView />
489494
<BlockViewerCode />
490495
<BlockViewerMobile>{children}</BlockViewerMobile>
491496
</BlockViewerProvider>

apps/www/src/components/component-preview-pro.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
'use client';
2-
31
import * as React from 'react';
42

5-
import { BlockViewer } from '@/components/block-viewer';
63
import { Markdown } from '@/components/markdown';
74
import { siteConfig } from '@/config/site';
85
import { cn } from '@/lib/utils';
96

7+
import { BlockDisplay } from './block-display';
8+
109
interface ComponentPreviewProps extends React.HTMLAttributes<HTMLDivElement> {
1110
id: string;
1211
description?: string;
@@ -31,11 +30,11 @@ export function ComponentPreviewPro({
3130
{...props}
3231
>
3332
{description && <Markdown>{description}</Markdown>}
34-
35-
<BlockViewer
33+
123
34+
<BlockDisplay
35+
id={id}
36+
name={name ?? ''}
3637
block={false}
37-
dependencies={[]}
38-
highlightedFiles={[]}
3938
item={{
4039
meta: {
4140
descriptionSrc: siteConfig.links.plateProExample(id),
@@ -45,7 +44,6 @@ export function ComponentPreviewPro({
4544
name: id,
4645
type: 'registry:example',
4746
}}
48-
tree={[]}
4947
/>
5048
</div>
5149
);

0 commit comments

Comments
 (0)