From 087a1095c834749dc708cd8c1c6ab101235573fa Mon Sep 17 00:00:00 2001 From: Emir Karabeg Date: Thu, 30 Jan 2025 18:54:23 -0800 Subject: [PATCH] Tag works on long input --- .../sub-block/components/long-input.tsx | 95 +++++++++++++++++-- .../components/sub-block/sub-block.tsx | 1 + 2 files changed, 89 insertions(+), 7 deletions(-) diff --git a/app/w/components/workflow-block/components/sub-block/components/long-input.tsx b/app/w/components/workflow-block/components/sub-block/components/long-input.tsx index 60ed7c7857..385b256a5a 100644 --- a/app/w/components/workflow-block/components/sub-block/components/long-input.tsx +++ b/app/w/components/workflow-block/components/sub-block/components/long-input.tsx @@ -1,26 +1,107 @@ import { Textarea } from '@/components/ui/textarea' import { useSubBlockValue } from '../hooks/use-sub-block-value' +import { cn } from '@/lib/utils' +import { useState, useRef, useEffect } from 'react' interface LongInputProps { placeholder?: string blockId: string subBlockId: string + isConnecting: boolean } export function LongInput({ placeholder, blockId, subBlockId, + isConnecting, }: LongInputProps) { const [value, setValue] = useSubBlockValue(blockId, subBlockId) + const textareaRef = useRef(null) + const overlayRef = useRef(null) + + // Sync scroll position between textarea and overlay + const handleScroll = (e: React.UIEvent) => { + if (overlayRef.current) { + overlayRef.current.scrollTop = e.currentTarget.scrollTop + overlayRef.current.scrollLeft = e.currentTarget.scrollLeft + } + } + + // Drag and Drop handlers + const handleDrop = (e: React.DragEvent) => { + e.preventDefault() + try { + const data = JSON.parse(e.dataTransfer.getData('application/json')) + + const isValidConnectionBlock = + data.type === 'connectionBlock' && + data.connectionData.sourceBlockId === blockId + + if (!isValidConnectionBlock) return + + const currentValue = value?.toString() ?? '' + const connectionName = data.connectionData.name + .replace(/\s+/g, '') + .toLowerCase() + const outputSuffix = + data.connectionData.outputType === 'any' + ? 'res' + : data.connectionData.outputType + + const newValue = `${currentValue}<${connectionName}.${outputSuffix}>` + setValue(newValue) + } catch (error) { + console.error('Failed to parse drop data:', error) + } + } + + const handleDragOver = (e: React.DragEvent) => { + e.preventDefault() + } + + const formatDisplayText = (text: string) => { + if (!text) return null + + // Split the text by tag pattern + const parts = text.split(/(<[^>]+>)/g) + + return parts.map((part, index) => { + // Check if the part matches tag pattern + if (part.match(/^<[^>]+>$/)) { + return ( + + {part} + + ) + } + return {part} + }) + } return ( -