11'use client'
22
33import { useEffect , useRef , useState } from 'react'
4- import { AlertTriangle , ChevronDown , Copy , MoreVertical , Plus , Trash } from 'lucide-react'
4+ import {
5+ AlertTriangle ,
6+ ChevronDown ,
7+ Copy ,
8+ Maximize2 ,
9+ Minimize2 ,
10+ MoreVertical ,
11+ Plus ,
12+ Trash ,
13+ } from 'lucide-react'
514import { highlight , languages } from 'prismjs'
615import 'prismjs/components/prism-javascript'
716import 'prismjs/themes/prism.css'
@@ -52,6 +61,16 @@ export function Variables() {
5261 // Track which variables are currently being edited
5362 const [ _activeEditors , setActiveEditors ] = useState < Record < string , boolean > > ( { } )
5463
64+ // Collapsed state per variable
65+ const [ collapsedById , setCollapsedById ] = useState < Record < string , boolean > > ( { } )
66+
67+ const toggleCollapsed = ( variableId : string ) => {
68+ setCollapsedById ( ( prev ) => ( {
69+ ...prev ,
70+ [ variableId ] : ! prev [ variableId ] ,
71+ } ) )
72+ }
73+
5574 // Handle variable name change with validation
5675 const handleVariableNameChange = ( variableId : string , newName : string ) => {
5776 const validatedName = validateName ( newName )
@@ -220,7 +239,7 @@ export function Variables() {
220239 </ Button >
221240 </ div >
222241 ) : (
223- < ScrollArea className = 'h-full' hideScrollbar = { true } >
242+ < ScrollArea className = 'h-full' hideScrollbar = { false } >
224243 < div className = 'space-y-4' >
225244 { workflowVariables . map ( ( variable ) => (
226245 < div key = { variable . id } className = 'space-y-2' >
@@ -298,6 +317,17 @@ export function Variables() {
298317 align = 'end'
299318 className = 'min-w-32 rounded-lg border-[#E5E5E5] bg-[#FFFFFF] shadow-xs dark:border-[#414141] dark:bg-[var(--surface-elevated)]'
300319 >
320+ < DropdownMenuItem
321+ onClick = { ( ) => toggleCollapsed ( variable . id ) }
322+ className = 'cursor-pointer rounded-md px-3 py-2 font-[380] text-card-foreground text-sm hover:bg-secondary/50 focus:bg-secondary/50'
323+ >
324+ { ( collapsedById [ variable . id ] ?? false ) ? (
325+ < Maximize2 className = 'mr-2 h-4 w-4 text-muted-foreground' />
326+ ) : (
327+ < Minimize2 className = 'mr-2 h-4 w-4 text-muted-foreground' />
328+ ) }
329+ { ( collapsedById [ variable . id ] ?? false ) ? 'Expand' : 'Collapse' }
330+ </ DropdownMenuItem >
301331 < DropdownMenuItem
302332 onClick = { ( ) => collaborativeDuplicateVariable ( variable . id ) }
303333 className = 'cursor-pointer rounded-md px-3 py-2 font-[380] text-card-foreground text-sm hover:bg-secondary/50 focus:bg-secondary/50'
@@ -317,71 +347,75 @@ export function Variables() {
317347 </ div >
318348
319349 { /* Value area */ }
320- < div className = 'relative rounded-lg bg-secondary/50' >
321- { /* Validation indicator */ }
322- { variable . value !== '' && getValidationStatus ( variable ) && (
323- < div className = 'absolute top-2 right-2 z-10' >
324- < Tooltip >
325- < TooltipTrigger asChild >
326- < div className = 'cursor-help' >
327- < AlertTriangle className = 'h-3 w-3 text-muted-foreground' />
328- </ div >
329- </ TooltipTrigger >
330- < TooltipContent side = 'bottom' className = 'max-w-xs' >
331- < p > { getValidationStatus ( variable ) } </ p >
332- </ TooltipContent >
333- </ Tooltip >
334- </ div >
335- ) }
336-
337- { /* Editor */ }
338- < div className = 'relative overflow-hidden' >
339- < div
340- className = 'relative min-h-[36px] w-full max-w-full px-3 py-2 font-normal text-sm'
341- ref = { ( el ) => {
342- editorRefs . current [ variable . id ] = el
343- } }
344- style = { { maxWidth : '100%' } }
345- >
346- { variable . value === '' && (
347- < div className = 'pointer-events-none absolute inset-0 flex select-none items-start justify-start px-3 py-2 font-[380] text-muted-foreground text-sm leading-normal' >
348- < div style = { { lineHeight : '20px' } } > { getPlaceholder ( variable . type ) } </ div >
349- </ div >
350- ) }
351- < Editor
352- key = { `editor-${ variable . id } -${ variable . type } ` }
353- value = { formatValue ( variable ) }
354- onValueChange = { handleEditorChange . bind ( null , variable ) }
355- onBlur = { ( ) => handleEditorBlur ( variable . id ) }
356- onFocus = { ( ) => handleEditorFocus ( variable . id ) }
357- highlight = { ( code ) =>
358- // Only apply syntax highlighting for non-basic text types
359- variable . type === 'plain' || variable . type === 'string'
360- ? code
361- : highlight (
362- code ,
363- languages [ getEditorLanguage ( variable . type ) ] ,
364- getEditorLanguage ( variable . type )
365- )
366- }
367- padding = { 0 }
368- style = { {
369- fontFamily : 'inherit' ,
370- lineHeight : '20px' ,
371- width : '100%' ,
372- maxWidth : '100%' ,
373- whiteSpace : 'pre-wrap' ,
374- wordBreak : 'break-all' ,
375- overflowWrap : 'break-word' ,
376- minHeight : '20px' ,
377- overflow : 'hidden' ,
350+ { ! ( collapsedById [ variable . id ] ?? false ) && (
351+ < div className = 'relative rounded-lg bg-secondary/50' >
352+ { /* Validation indicator */ }
353+ { variable . value !== '' && getValidationStatus ( variable ) && (
354+ < div className = 'absolute top-2 right-2 z-10' >
355+ < Tooltip >
356+ < TooltipTrigger asChild >
357+ < div className = 'cursor-help' >
358+ < AlertTriangle className = 'h-3 w-3 text-muted-foreground' />
359+ </ div >
360+ </ TooltipTrigger >
361+ < TooltipContent side = 'bottom' className = 'max-w-xs' >
362+ < p > { getValidationStatus ( variable ) } </ p >
363+ </ TooltipContent >
364+ </ Tooltip >
365+ </ div >
366+ ) }
367+
368+ { /* Editor */ }
369+ < div className = 'relative overflow-hidden' >
370+ < div
371+ className = 'relative min-h-[36px] w-full max-w-full px-3 py-2 font-normal text-sm'
372+ ref = { ( el ) => {
373+ editorRefs . current [ variable . id ] = el
378374 } }
379- className = '[&>pre]:!max-w-full [&>pre]:!overflow-hidden [&>pre]:!whitespace-pre-wrap [&>pre]:!break-all [&>pre]:!overflow-wrap-break-word [&>textarea]:!max-w-full [&>textarea]:!overflow-hidden [&>textarea]:!whitespace-pre-wrap [&>textarea]:!break-all [&>textarea]:!overflow-wrap-break-word font-[380] text-foreground text-sm leading-normal focus:outline-none'
380- textareaClassName = 'focus:outline-none focus:ring-0 bg-transparent resize-none w-full max-w-full whitespace-pre-wrap break-all overflow-wrap-break-word overflow-hidden font-[380] text-foreground'
381- />
375+ style = { { maxWidth : '100%' } }
376+ >
377+ { variable . value === '' && (
378+ < div className = 'pointer-events-none absolute inset-0 flex select-none items-start justify-start px-3 py-2 font-[380] text-muted-foreground text-sm leading-normal' >
379+ < div style = { { lineHeight : '20px' } } >
380+ { getPlaceholder ( variable . type ) }
381+ </ div >
382+ </ div >
383+ ) }
384+ < Editor
385+ key = { `editor-${ variable . id } -${ variable . type } ` }
386+ value = { formatValue ( variable ) }
387+ onValueChange = { handleEditorChange . bind ( null , variable ) }
388+ onBlur = { ( ) => handleEditorBlur ( variable . id ) }
389+ onFocus = { ( ) => handleEditorFocus ( variable . id ) }
390+ highlight = { ( code ) =>
391+ // Only apply syntax highlighting for non-basic text types
392+ variable . type === 'plain' || variable . type === 'string'
393+ ? code
394+ : highlight (
395+ code ,
396+ languages [ getEditorLanguage ( variable . type ) ] ,
397+ getEditorLanguage ( variable . type )
398+ )
399+ }
400+ padding = { 0 }
401+ style = { {
402+ fontFamily : 'inherit' ,
403+ lineHeight : '20px' ,
404+ width : '100%' ,
405+ maxWidth : '100%' ,
406+ whiteSpace : 'pre-wrap' ,
407+ wordBreak : 'break-all' ,
408+ overflowWrap : 'break-word' ,
409+ minHeight : '20px' ,
410+ overflow : 'hidden' ,
411+ } }
412+ className = '[&>pre]:!max-w-full [&>pre]:!overflow-hidden [&>pre]:!whitespace-pre-wrap [&>pre]:!break-all [&>pre]:!overflow-wrap-break-word [&>textarea]:!max-w-full [&>textarea]:!overflow-hidden [&>textarea]:!whitespace-pre-wrap [&>textarea]:!break-all [&>textarea]:!overflow-wrap-break-word font-[380] text-foreground text-sm leading-normal focus:outline-none'
413+ textareaClassName = 'focus:outline-none focus:ring-0 bg-transparent resize-none w-full max-w-full whitespace-pre-wrap break-all overflow-wrap-break-word overflow-hidden font-[380] text-foreground'
414+ />
415+ </ div >
382416 </ div >
383417 </ div >
384- </ div >
418+ ) }
385419 </ div >
386420 ) ) }
387421
0 commit comments