11'use client' ;
22
3- import React from 'react' ;
3+ import React , { useState , useEffect } from 'react' ;
44import { SchemaRenderer } from '@object-ui/react' ;
55import type { SchemaNode } from '@object-ui/core' ;
66import { Tabs , Tab } from 'fumadocs-ui/components/tabs' ;
@@ -9,6 +9,16 @@ import { CodeBlock, Pre } from 'fumadocs-ui/components/codeblock';
99// Re-export SchemaNode type for use in MDX files
1010export type { SchemaNode } from '@object-ui/core' ;
1111
12+ // Load plugins promise that we can await
13+ const pluginsLoading = typeof window !== 'undefined'
14+ ? Promise . all ( [
15+ import ( '@object-ui/plugin-editor' ) ,
16+ import ( '@object-ui/plugin-charts' ) ,
17+ import ( '@object-ui/plugin-kanban' ) ,
18+ import ( '@object-ui/plugin-markdown' ) ,
19+ ] )
20+ : Promise . resolve ( [ ] ) ;
21+
1222interface InteractiveDemoProps {
1323 schema : SchemaNode ;
1424 title ?: string ;
@@ -29,6 +39,15 @@ export function InteractiveDemo({
2939 description,
3040 examples
3141} : InteractiveDemoProps ) {
42+ const [ pluginsLoaded , setPluginsLoaded ] = useState ( false ) ;
43+
44+ useEffect ( ( ) => {
45+ // Wait for plugins to load before rendering
46+ pluginsLoading . then ( ( ) => {
47+ setPluginsLoaded ( true ) ;
48+ } ) ;
49+ } , [ ] ) ;
50+
3251 // If examples are provided, show a multi-example view
3352 if ( examples && examples . length > 0 ) {
3453 return (
@@ -41,23 +60,27 @@ export function InteractiveDemo({
4160 ) }
4261 < Tabs items = { [ 'Preview' , 'Code' ] } defaultIndex = { 0 } >
4362 < Tab value = "Preview" >
44- < div className = "space-y-6" >
45- { examples . map ( ( example , index ) => (
46- < div key = { index } className = "border rounded-lg overflow-hidden" >
47- { example . label && (
48- < div className = "border-b bg-muted px-4 py-2" >
49- < p className = "text-sm font-medium" > { example . label } </ p >
50- { example . description && (
51- < p className = "text-xs text-muted-foreground mt-0.5" > { example . description } </ p >
52- ) }
63+ { ! pluginsLoaded ? (
64+ < div className = "p-6 text-center text-muted-foreground" > Loading plugins...</ div >
65+ ) : (
66+ < div className = "space-y-6" >
67+ { examples . map ( ( example , index ) => (
68+ < div key = { index } className = "border rounded-lg overflow-hidden" >
69+ { example . label && (
70+ < div className = "border-b bg-muted px-4 py-2" >
71+ < p className = "text-sm font-medium" > { example . label } </ p >
72+ { example . description && (
73+ < p className = "text-xs text-muted-foreground mt-0.5" > { example . description } </ p >
74+ ) }
75+ </ div >
76+ ) }
77+ < div className = "p-6 bg-background" >
78+ < SchemaRenderer schema = { example . schema } />
5379 </ div >
54- ) }
55- < div className = "p-6 bg-background" >
56- < SchemaRenderer schema = { example . schema } />
5780 </ div >
58- </ div >
59- ) ) }
60- </ div >
81+ ) ) }
82+ </ div >
83+ ) }
6184 </ Tab >
6285 < Tab value = "Code" >
6386 < div className = "space-y-4" >
@@ -92,7 +115,11 @@ export function InteractiveDemo({
92115 < Tabs items = { [ 'Preview' , 'Code' ] } defaultIndex = { 0 } >
93116 < Tab value = "Preview" >
94117 < div className = "border rounded-lg p-6 bg-background" >
95- < SchemaRenderer schema = { schema } />
118+ { ! pluginsLoaded ? (
119+ < div className = "text-center text-muted-foreground" > Loading plugins...</ div >
120+ ) : (
121+ < SchemaRenderer schema = { schema } />
122+ ) }
96123 </ div >
97124 </ Tab >
98125 < Tab value = "Code" >
0 commit comments