@@ -307,25 +307,18 @@ export function Code({
307307 ? getDefaultValueString ( )
308308 : storeValue
309309
310- const lastValidationStatus = useRef < boolean > ( true )
311-
312310 useEffect ( ( ) => {
313311 if ( ! onValidationChange ) return
314312
315- const nextStatus = shouldValidateJson ? isValidJson : true
316- if ( lastValidationStatus . current === nextStatus ) {
317- return
318- }
319-
320- lastValidationStatus . current = nextStatus
313+ const isValid = ! shouldValidateJson || isValidJson
321314
322- if ( ! shouldValidateJson ) {
323- onValidationChange ( nextStatus )
315+ if ( isValid ) {
316+ onValidationChange ( true )
324317 return
325318 }
326319
327320 const timeoutId = setTimeout ( ( ) => {
328- onValidationChange ( nextStatus )
321+ onValidationChange ( false )
329322 } , 150 )
330323
331324 return ( ) => clearTimeout ( timeoutId )
@@ -337,7 +330,7 @@ export function Code({
337330 }
338331
339332 handleStreamChunkRef . current = ( chunk : string ) => {
340- setCode ( ( prev ) => prev + chunk )
333+ setCode ( ( prev : string ) => prev + chunk )
341334 }
342335
343336 handleGeneratedContentRef . current = ( generatedCode : string ) => {
@@ -434,12 +427,12 @@ export function Code({
434427 `
435428 document . body . appendChild ( tempContainer )
436429
437- lines . forEach ( ( line ) => {
430+ lines . forEach ( ( line : string ) => {
438431 const lineDiv = document . createElement ( 'div' )
439432
440433 if ( line . includes ( '<' ) && line . includes ( '>' ) ) {
441434 const parts = line . split ( / ( < [ ^ > ] + > ) / g)
442- parts . forEach ( ( part ) => {
435+ parts . forEach ( ( part : string ) => {
443436 const span = document . createElement ( 'span' )
444437 span . textContent = part
445438 lineDiv . appendChild ( span )
@@ -472,7 +465,6 @@ export function Code({
472465 }
473466 } , [ code ] )
474467
475- // Event Handlers
476468 /**
477469 * Handles drag-and-drop events for inserting reference tags into the code editor.
478470 * @param e - The drag event
@@ -500,7 +492,6 @@ export function Code({
500492 textarea . selectionStart = newCursorPosition
501493 textarea . selectionEnd = newCursorPosition
502494
503- // Show tag dropdown after cursor is positioned
504495 setShowTags ( true )
505496 if ( data . connectionData ?. sourceBlockId ) {
506497 setActiveSourceBlockId ( data . connectionData . sourceBlockId )
@@ -559,7 +550,6 @@ export function Code({
559550 }
560551 }
561552
562- // Helper Functions
563553 /**
564554 * Determines whether a `<...>` segment should be highlighted as a reference.
565555 * @param part - The code segment to check
@@ -596,7 +586,6 @@ export function Code({
596586 return accessiblePrefixes . has ( normalizedPrefix )
597587 }
598588
599- // Expose wand control handlers to parent via ref
600589 useImperativeHandle (
601590 wandControlRef ,
602591 ( ) => ( {
@@ -617,7 +606,7 @@ export function Code({
617606 const numbers : ReactElement [ ] = [ ]
618607 let lineNumber = 1
619608
620- visualLineHeights . forEach ( ( height ) => {
609+ visualLineHeights . forEach ( ( height : number ) => {
621610 const isActive = lineNumber === activeLineNumber
622611 numbers . push (
623612 < div
@@ -724,7 +713,7 @@ export function Code({
724713
725714 < Editor
726715 value = { code }
727- onValueChange = { ( newCode ) => {
716+ onValueChange = { ( newCode : string ) => {
728717 if ( ! isAiStreaming && ! isPreview && ! disabled && ! readOnly ) {
729718 hasEditedSinceFocusRef . current = true
730719 setCode ( newCode )
@@ -761,7 +750,6 @@ export function Code({
761750 } }
762751 onFocus = { ( ) => {
763752 hasEditedSinceFocusRef . current = false
764- // Show tag dropdown on focus when code is empty
765753 if ( ! isPreview && ! disabled && ! readOnly && code . trim ( ) === '' ) {
766754 setShowTags ( true )
767755 setCursorPosition ( 0 )
0 commit comments