@@ -10,6 +10,7 @@ import {
1010 setPathValue ,
1111} from "./utils.ts" ;
1212import Badge from "./gds/Badge.tsx" ;
13+ export { CopyBadge } from "./CopyBadge.tsx" ;
1314import Panel from "./gds/Panel.tsx" ;
1415import Tabs from "./gds/Tabs.tsx" ;
1516import type {
@@ -62,62 +63,6 @@ export function useHttpSchema(opts?: { workspaceId?: string | null }) {
6263 return { schemaResponse, loading, error, refresh } ;
6364}
6465
65- export function CopyBadge ( props : {
66- label : string ;
67- displayValue ?: string | null ;
68- copyValue ?: string | null ;
69- className ?: string ;
70- } ) {
71- const { label, displayValue, copyValue, className } = props ;
72- const [ copied , setCopied ] = useState ( false ) ;
73- const timeoutRef = useRef < number | undefined > ( undefined ) ;
74-
75- useEffect ( ( ) => {
76- return ( ) => {
77- if ( timeoutRef . current ) clearTimeout ( timeoutRef . current ) ;
78- } ;
79- } , [ ] ) ;
80-
81- const copyTarget = copyValue ?? displayValue ;
82- if ( ! copyTarget ) return null ;
83- const text = displayValue ?? copyTarget ;
84-
85- const handleCopy = useCallback ( async ( ) => {
86- try {
87- if ( navigator . clipboard ?. writeText ) {
88- await navigator . clipboard . writeText ( copyTarget ) ;
89- } else {
90- const temp = document . createElement ( "textarea" ) ;
91- temp . value = copyTarget ;
92- temp . style . position = "fixed" ;
93- temp . style . opacity = "0" ;
94- document . body . appendChild ( temp ) ;
95- temp . select ( ) ;
96- document . execCommand ( "copy" ) ;
97- document . body . removeChild ( temp ) ;
98- }
99- setCopied ( true ) ;
100- if ( timeoutRef . current ) clearTimeout ( timeoutRef . current ) ;
101- timeoutRef . current = globalThis . setTimeout ( ( ) => setCopied ( false ) , 1500 ) ;
102- } catch {
103- // ignore copy failures silently
104- }
105- } , [ copyTarget ] ) ;
106-
107- return (
108- < button
109- type = "button"
110- className = { classNames ( "copy-badge" , className , copied && "copied" ) }
111- onClick = { handleCopy }
112- title = { copied ? "Copied!" : `Click to copy ${ label } ` }
113- >
114- < span className = "copy-label" > { label } :</ span >
115- < code > { text } </ code >
116- { copied && < span className = "copy-feedback" > Copied</ span > }
117- </ button >
118- ) ;
119- }
120-
12166export function ConversationView ( props : {
12267 messages : Array < ConversationMessage > ;
12368 header ?: React . ReactNode ;
0 commit comments