diff --git a/web/app/components/workflow/nodes/_base/components/support-var-input/index.tsx b/web/app/components/workflow/nodes/_base/components/support-var-input/index.tsx new file mode 100644 index 0000000000..aadcf02de6 --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/support-var-input/index.tsx @@ -0,0 +1,51 @@ +'use client' +import type { FC } from 'react' +import React from 'react' +import cn from 'classnames' +import { varHighlightHTML } from '@/app/components/app/configuration/base/var-highlight' +type Props = { + isFocus: boolean + onFocus: () => void + value: string + children: React.ReactNode + wrapClassName?: string + textClassName?: string + readonly?: boolean +} + +const SupportVarInput: FC = ({ + isFocus, + onFocus, + children, + value, + wrapClassName, + textClassName, + readonly, +}) => { + const withHightContent = (value || '') + .replace(//g, '>') + .replace(/\{\{([^}]+)\}\}/g, varHighlightHTML({ name: '$1' })) // `{{$1}}` + .replace(/\n/g, '
') + + return ( +
+ {(isFocus && !readonly) + ? ( + children + ) + : ( +
+ )} +
+ ) +} +export default React.memo(SupportVarInput) diff --git a/web/app/components/workflow/nodes/http/components/api-input.tsx b/web/app/components/workflow/nodes/http/components/api-input.tsx index ab04226373..b2cd23dc06 100644 --- a/web/app/components/workflow/nodes/http/components/api-input.tsx +++ b/web/app/components/workflow/nodes/http/components/api-input.tsx @@ -1,10 +1,13 @@ 'use client' import type { FC } from 'react' -import React, { useCallback } from 'react' +import React, { useCallback, useEffect, useRef } from 'react' import cn from 'classnames' +import { useBoolean } from 'ahooks' import { Method } from '../types' import Selector from '../../_base/components/selector' import { ChevronDown } from '@/app/components/base/icons/src/vender/line/arrows' +import SupportVarInput from '@/app/components/workflow/nodes/_base/components/support-var-input' + const MethodOptions = [ { label: 'GET', value: Method.get }, { label: 'POST', value: Method.post }, @@ -31,6 +34,16 @@ const ApiInput: FC = ({ const handleUrlChange = useCallback((e: React.ChangeEvent) => { onUrlChange(e.target.value) }, [onUrlChange]) + + const inputRef = useRef(null) + const [isFocus, { + setTrue: onFocus, + setFalse: onBlur, + }] = useBoolean(false) + useEffect(() => { + if (isFocus) + inputRef.current?.focus() + }, [isFocus]) return (
= ({ showChecked readonly={readonly} /> - + wrapClassName='flex h-[30px] items-center' + textClassName='!h-6 leading-6 px-2.5 text-gray-900 text-[13px]' + > + +
) }