@@ -231,46 +231,6 @@ export function ConditionInput({
231231 }
232232 } , [ ] )
233233
234- // Update block value with trigger checks - handle both tag and env var triggers consistently
235- const updateBlockValue = (
236- blockId : string ,
237- newValue : string ,
238- textarea : HTMLTextAreaElement | null
239- ) => {
240- if ( isPreview || disabled ) return
241-
242- try {
243- setConditionalBlocks ( ( blocks ) =>
244- blocks . map ( ( block ) => {
245- if ( block . id === blockId ) {
246- const pos = textarea ?. selectionStart ?? 0
247- const tagTrigger = checkTagTrigger ( newValue , pos )
248- const envVarTrigger = checkEnvVarTrigger ( newValue , pos )
249-
250- // Check triggers for both tags and env vars
251- const lastCharTyped = newValue . charAt ( pos - 1 )
252- const shouldShowTags = tagTrigger . show || lastCharTyped === '<'
253- const shouldShowEnvVars = envVarTrigger . show || lastCharTyped === '$'
254-
255- return {
256- ...block ,
257- value : newValue ,
258- showTags : shouldShowTags ,
259- showEnvVars : shouldShowEnvVars ,
260- searchTerm : shouldShowEnvVars ? envVarTrigger . searchTerm : '' ,
261- cursorPosition : pos ,
262- // Maintain activeSourceBlockId only when tags are showing
263- activeSourceBlockId : shouldShowTags ? block . activeSourceBlockId : null ,
264- }
265- }
266- return block
267- } )
268- )
269- } catch ( error ) {
270- logger . error ( 'Error updating block value:' , { error, blockId, newValue } )
271- }
272- }
273-
274234 // Update the line counting logic to be block-specific
275235 useEffect ( ( ) => {
276236 if ( ! editorRef . current || conditionalBlocks . length === 0 ) return
@@ -541,9 +501,6 @@ export function ConditionInput({
541501 } )
542502 } , [ conditionalBlocks . length ] )
543503
544- // Use preview value when in preview mode, otherwise use store value
545- const value = isPreview ? previewValue : storeValue
546-
547504 // Show loading or empty state if not ready or no blocks
548505 if ( ! isReady || conditionalBlocks . length === 0 ) {
549506 return (
@@ -698,11 +655,33 @@ export function ConditionInput({
698655 < Editor
699656 value = { block . value }
700657 onValueChange = { ( newCode ) => {
701- if ( ! isPreview ) {
658+ if ( ! isPreview && ! disabled ) {
702659 const textarea = editorRef . current ?. querySelector (
703660 `[data-block-id="${ block . id } "] textarea`
704- )
705- updateBlockValue ( block . id , newCode , textarea as HTMLTextAreaElement | null )
661+ ) as HTMLTextAreaElement | null
662+ if ( textarea ) {
663+ const pos = textarea . selectionStart ?? 0
664+
665+ const tagTrigger = checkTagTrigger ( newCode , pos )
666+ const envVarTrigger = checkEnvVarTrigger ( newCode , pos )
667+
668+ setConditionalBlocks ( ( blocks ) =>
669+ blocks . map ( ( b ) => {
670+ if ( b . id === block . id ) {
671+ return {
672+ ...b ,
673+ value : newCode ,
674+ showTags : tagTrigger . show ,
675+ showEnvVars : envVarTrigger . show ,
676+ searchTerm : envVarTrigger . show ? envVarTrigger . searchTerm : '' ,
677+ cursorPosition : pos ,
678+ activeSourceBlockId : tagTrigger . show ? b . activeSourceBlockId : null ,
679+ }
680+ }
681+ return b
682+ } )
683+ )
684+ }
706685 }
707686 } }
708687 onKeyDown = { ( e ) => {
0 commit comments