1- import { useContext } from "react" ;
1+ import { useContext , useEffect , useState } from "react" ;
22import Editor from "@monaco-editor/react" ;
33import { AppContext } from "../contexts/AppContext" ;
44import MetadataTable from "./MetadataTable" ;
55import DetailPanel from "./DetailPanel" ;
66import { defineMonacoTheme , ONE_UI_EDITOR_FONT_OPTIONS , ONE_UI_MONACO_THEME } from "../utils/monacoTheme" ;
77import IdleState from "./IdleState" ;
8+ import { getSchemaContent } from "../api/one" ;
89
910const InstanceEditor = ( ) => {
1011 const {
12+ registryUrl,
1113 selectedSchemaPath,
1214 schemaMetadata,
1315 metadataLoading,
@@ -21,9 +23,47 @@ const InstanceEditor = () => {
2123 setInstanceText,
2224 runEvaluate,
2325 runTrace,
26+ runRdf,
2427 resultLoading,
2528 } = useContext ( AppContext ) ;
2629
30+ // Bundled view is fetched separately from the plain schemaContent used
31+ // elsewhere (e.g. the Trace Debugger's highlighting, which relies on
32+ // /positions being computed against the unbundled text) so toggling it
33+ // here can't desync anything else that reads schemaContent.
34+ const [ bundled , setBundled ] = useState ( false ) ;
35+ const [ bundledContent , setBundledContent ] = useState < string | null > ( null ) ;
36+ const [ bundledLoading , setBundledLoading ] = useState ( false ) ;
37+ const [ bundledError , setBundledError ] = useState < string | null > ( null ) ;
38+
39+ useEffect ( ( ) => {
40+ setBundled ( false ) ;
41+ setBundledContent ( null ) ;
42+ setBundledError ( null ) ;
43+ } , [ selectedSchemaPath ] ) ;
44+
45+ useEffect ( ( ) => {
46+ if ( ! bundled || ! selectedSchemaPath ) return ;
47+ let cancelled = false ;
48+ setBundledLoading ( true ) ;
49+ setBundledError ( null ) ;
50+ getSchemaContent ( registryUrl , selectedSchemaPath , { bundle : true } )
51+ . then ( ( content ) => {
52+ if ( ! cancelled ) setBundledContent ( content ) ;
53+ } )
54+ . catch ( ( error : unknown ) => {
55+ if ( ! cancelled ) {
56+ setBundledError ( error instanceof Error ? error . message : String ( error ) ) ;
57+ }
58+ } )
59+ . finally ( ( ) => {
60+ if ( ! cancelled ) setBundledLoading ( false ) ;
61+ } ) ;
62+ return ( ) => {
63+ cancelled = true ;
64+ } ;
65+ } , [ bundled , registryUrl , selectedSchemaPath ] ) ;
66+
2767 if ( ! selectedSchemaPath ) {
2868 return < IdleState /> ;
2969 }
@@ -66,12 +106,19 @@ const InstanceEditor = () => {
66106 >
67107 Trace
68108 </ button >
109+ < button
110+ onClick = { runRdf }
111+ disabled = { resultLoading }
112+ className = "h-8 px-3 text-sm rounded-[var(--radius-sm)] border border-[var(--info)]/50 bg-[var(--info)]/12 text-[var(--info)] hover:bg-[var(--info)]/20 transition-colors disabled:opacity-40 disabled:cursor-not-allowed"
113+ >
114+ RDF
115+ </ button >
69116 </ div >
70117 </ div >
71118
72119 < MetadataTable />
73120
74- < div className = "flex border-b border-[var(--border)]" >
121+ < div className = "flex items-center border-b border-[var(--border)]" >
75122 < button
76123 onClick = { ( ) => setActiveTab ( "schema" ) }
77124 className = { `px-3 py-1.5 text-xs border-r border-[var(--border)] ${
@@ -92,10 +139,30 @@ const InstanceEditor = () => {
92139 >
93140 Instance
94141 </ button >
142+ { activeTab === "schema" && (
143+ < label
144+ title = "Show the schema with $ref keywords inlined via JSON Schema Bundling"
145+ className = "ml-auto mr-2 flex items-center gap-1.5 text-xs text-[var(--text-secondary)] cursor-pointer select-none"
146+ >
147+ < input
148+ type = "checkbox"
149+ checked = { bundled }
150+ onChange = { ( e ) => setBundled ( e . target . checked ) }
151+ className = "accent-[var(--accent)]"
152+ />
153+ Bundled
154+ </ label >
155+ ) }
95156 </ div >
96157
97158 < div className = "h-72 shrink-0 border-b border-[var(--border)]" >
98- { activeTab === "schema" && schemaContentLoading ? (
159+ { activeTab === "schema" && bundled && bundledLoading ? (
160+ < p className = "text-sm text-[var(--text-secondary)] p-3" >
161+ Bundling schema…
162+ </ p >
163+ ) : activeTab === "schema" && bundled && bundledError ? (
164+ < p className = "text-sm text-[var(--danger)] p-3" > { bundledError } </ p >
165+ ) : activeTab === "schema" && schemaContentLoading ? (
99166 < p className = "text-sm text-[var(--text-secondary)] p-3" >
100167 Loading schema…
101168 </ p >
@@ -105,11 +172,17 @@ const InstanceEditor = () => {
105172 </ p >
106173 ) : (
107174 < Editor
108- key = { activeTab }
175+ key = { activeTab === "schema" && bundled ? "schema-bundled" : activeTab }
109176 language = "json"
110177 theme = { ONE_UI_MONACO_THEME }
111178 beforeMount = { defineMonacoTheme }
112- value = { activeTab === "schema" ? schemaContent ?? "" : instanceText }
179+ value = {
180+ activeTab === "schema"
181+ ? bundled
182+ ? bundledContent ?? ""
183+ : schemaContent ?? ""
184+ : instanceText
185+ }
113186 onChange = {
114187 activeTab === "instance"
115188 ? ( value ) => setInstanceText ( value ?? "" )
0 commit comments