mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 04:26:30 +08:00
feat: support url highlight
This commit is contained in:
parent
8e3be982eb
commit
2dd2c8c358
@ -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<Props> = ({
|
||||||
|
isFocus,
|
||||||
|
onFocus,
|
||||||
|
children,
|
||||||
|
value,
|
||||||
|
wrapClassName,
|
||||||
|
textClassName,
|
||||||
|
readonly,
|
||||||
|
}) => {
|
||||||
|
const withHightContent = (value || '')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/\{\{([^}]+)\}\}/g, varHighlightHTML({ name: '$1' })) // `<span class="${highLightClassName}">{{$1}}</span>`
|
||||||
|
.replace(/\n/g, '<br />')
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={
|
||||||
|
cn(wrapClassName, 'w-full h-full')
|
||||||
|
} onClick={onFocus}
|
||||||
|
>
|
||||||
|
{(isFocus && !readonly)
|
||||||
|
? (
|
||||||
|
children
|
||||||
|
)
|
||||||
|
: (
|
||||||
|
<div
|
||||||
|
className={cn(textClassName, 'w-full h-full')}
|
||||||
|
dangerouslySetInnerHTML={{
|
||||||
|
__html: withHightContent,
|
||||||
|
}}></div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
export default React.memo(SupportVarInput)
|
||||||
@ -1,10 +1,13 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React, { useCallback } from 'react'
|
import React, { useCallback, useEffect, useRef } from 'react'
|
||||||
import cn from 'classnames'
|
import cn from 'classnames'
|
||||||
|
import { useBoolean } from 'ahooks'
|
||||||
import { Method } from '../types'
|
import { Method } from '../types'
|
||||||
import Selector from '../../_base/components/selector'
|
import Selector from '../../_base/components/selector'
|
||||||
import { ChevronDown } from '@/app/components/base/icons/src/vender/line/arrows'
|
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 = [
|
const MethodOptions = [
|
||||||
{ label: 'GET', value: Method.get },
|
{ label: 'GET', value: Method.get },
|
||||||
{ label: 'POST', value: Method.post },
|
{ label: 'POST', value: Method.post },
|
||||||
@ -31,6 +34,16 @@ const ApiInput: FC<Props> = ({
|
|||||||
const handleUrlChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleUrlChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
onUrlChange(e.target.value)
|
onUrlChange(e.target.value)
|
||||||
}, [onUrlChange])
|
}, [onUrlChange])
|
||||||
|
|
||||||
|
const inputRef = useRef<HTMLInputElement>(null)
|
||||||
|
const [isFocus, {
|
||||||
|
setTrue: onFocus,
|
||||||
|
setFalse: onBlur,
|
||||||
|
}] = useBoolean(false)
|
||||||
|
useEffect(() => {
|
||||||
|
if (isFocus)
|
||||||
|
inputRef.current?.focus()
|
||||||
|
}, [isFocus])
|
||||||
return (
|
return (
|
||||||
<div className='flex items-center h-8 rounded-lg bg-white border border-gray-200 shadow-xs'>
|
<div className='flex items-center h-8 rounded-lg bg-white border border-gray-200 shadow-xs'>
|
||||||
<Selector
|
<Selector
|
||||||
@ -47,13 +60,24 @@ const ApiInput: FC<Props> = ({
|
|||||||
showChecked
|
showChecked
|
||||||
readonly={readonly}
|
readonly={readonly}
|
||||||
/>
|
/>
|
||||||
<input
|
<SupportVarInput
|
||||||
type='text'
|
isFocus={isFocus}
|
||||||
readOnly={readonly}
|
onFocus={onFocus}
|
||||||
value={url}
|
value={url}
|
||||||
onChange={handleUrlChange}
|
wrapClassName='flex h-[30px] items-center'
|
||||||
className='w-0 grow h-6 leading-6 px-2.5 border-0 text-gray-900 text-[13px] placeholder:text-gray-400 focus:outline-none'
|
textClassName='!h-6 leading-6 px-2.5 text-gray-900 text-[13px]'
|
||||||
/>
|
>
|
||||||
|
<input
|
||||||
|
type='text'
|
||||||
|
readOnly={readonly}
|
||||||
|
value={url}
|
||||||
|
onChange={handleUrlChange}
|
||||||
|
onFocus={onFocus}
|
||||||
|
onBlur={onBlur}
|
||||||
|
className='w-full h-6 leading-6 px-2.5 border-0 text-gray-900 text-[13px] placeholder:text-gray-400 focus:outline-none'
|
||||||
|
ref={inputRef}
|
||||||
|
/>
|
||||||
|
</SupportVarInput>
|
||||||
</div >
|
</div >
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user