feat: input var ui

This commit is contained in:
Joel 2024-03-29 16:19:00 +08:00
parent b50e897aa0
commit 950a52f4fc
6 changed files with 20 additions and 17 deletions

View File

@ -61,6 +61,7 @@ import { useEventEmitterContextContext } from '@/context/event-emitter'
export type PromptEditorProps = { export type PromptEditorProps = {
className?: string className?: string
placeholder?: string placeholder?: string
placeholderClassName?: string
style?: React.CSSProperties style?: React.CSSProperties
value?: string value?: string
editable?: boolean editable?: boolean
@ -78,6 +79,7 @@ export type PromptEditorProps = {
const PromptEditor: FC<PromptEditorProps> = ({ const PromptEditor: FC<PromptEditorProps> = ({
className, className,
placeholder, placeholder,
placeholderClassName,
style, style,
value, value,
editable = true, editable = true,
@ -136,7 +138,7 @@ const PromptEditor: FC<PromptEditorProps> = ({
<div className='relative'> <div className='relative'>
<RichTextPlugin <RichTextPlugin
contentEditable={<ContentEditable className={`${className} outline-none text-sm text-gray-700 leading-6`} style={style || {}} />} contentEditable={<ContentEditable className={`${className} outline-none text-sm text-gray-700 leading-6`} style={style || {}} />}
placeholder={<Placeholder value={placeholder} />} placeholder={<Placeholder value={placeholder} className={placeholderClassName} />}
ErrorBoundary={LexicalErrorBoundary} ErrorBoundary={LexicalErrorBoundary}
/> />
<ComponentPickerBlock <ComponentPickerBlock

View File

@ -1,14 +1,17 @@
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import cn from 'classnames'
const Placeholder = ({ const Placeholder = ({
value, value,
className,
}: { }: {
value?: string value?: string
className?: string
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
return ( return (
<div className='absolute top-0 left-0 h-full w-full text-sm text-gray-300 select-none pointer-events-none leading-6'> <div className={cn(className, 'absolute top-0 left-0 h-full w-full text-sm text-gray-300 select-none pointer-events-none leading-6')}>
{value || t('common.promptEditor.placeholder')} {value || t('common.promptEditor.placeholder')}
</div> </div>
) )

View File

@ -9,6 +9,7 @@ import PromptEditor from '@/app/components/base/prompt-editor'
type Props = { type Props = {
className?: string className?: string
placeholder?: string placeholder?: string
placeholderClassName?: string
promptMinHeightClassName?: string promptMinHeightClassName?: string
value: string value: string
onChange: (value: string) => void onChange: (value: string) => void
@ -21,14 +22,14 @@ type Props = {
const Editor: FC<Props> = ({ const Editor: FC<Props> = ({
className, className,
placeholder, placeholder,
promptMinHeightClassName = 'min-h-[30px]', placeholderClassName,
promptMinHeightClassName = 'min-h-[20px]',
value, value,
onChange, onChange,
onFocusChange, onFocusChange,
readOnly, readOnly,
nodesOutputVars, nodesOutputVars,
}) => { }) => {
// const { t } = useTranslation()
const { getNode } = useWorkflow() const { getNode } = useWorkflow()
const [isFocus, { const [isFocus, {
@ -45,9 +46,9 @@ const Editor: FC<Props> = ({
<div className={cn(className, 'relative')}> <div className={cn(className, 'relative')}>
<> <>
<PromptEditor <PromptEditor
className={cn(promptMinHeightClassName)} className={cn(promptMinHeightClassName, '!leading-[18px]')}
// style={isExpand ? { height: editorExpandHeight - 5 } : {}}
placeholder={placeholder} placeholder={placeholder}
placeholderClassName={placeholderClassName}
value={value} value={value}
outToolDisabled outToolDisabled
canNotAddContext canNotAddContext

View File

@ -2,6 +2,7 @@
import type { FC } from 'react' import type { FC } from 'react'
import React, { useEffect, useRef, useState } from 'react' import React, { useEffect, useRef, useState } from 'react'
import cn from 'classnames' import cn from 'classnames'
import { useTranslation } from 'react-i18next'
import { Method } from '../types' import { Method } from '../types'
import Selector from '../../_base/components/selector' import Selector from '../../_base/components/selector'
import useAvailableVarList from '../../_base/hooks/use-available-var-list' import useAvailableVarList from '../../_base/hooks/use-available-var-list'
@ -35,6 +36,8 @@ const ApiInput: FC<Props> = ({
url, url,
onUrlChange, onUrlChange,
}) => { }) => {
const { t } = useTranslation()
const inputRef = useRef<HTMLInputElement>(null) const inputRef = useRef<HTMLInputElement>(null)
const [isFocus, setIsFocus] = useState(false) const [isFocus, setIsFocus] = useState(false)
const availableVarList = useAvailableVarList(nodeId, { const availableVarList = useAvailableVarList(nodeId, {
@ -65,23 +68,15 @@ const ApiInput: FC<Props> = ({
readonly={readonly} readonly={readonly}
/> />
{/* <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}
/> */}
<Input <Input
className='w-0 grow rounded-lg px-3 bg-white border border-gray-200 shadow-xs' className={cn(isFocus ? 'shadow-xs bg-gray-50 border-gray-300' : 'bg-gray-100 border-gray-100', 'w-0 grow rounded-lg px-3 py-[6px] border')}
value={url} value={url}
onChange={onUrlChange} onChange={onUrlChange}
readOnly={readonly} readOnly={readonly}
nodesOutputVars={availableVarList} nodesOutputVars={availableVarList}
onFocusChange={setIsFocus} onFocusChange={setIsFocus}
placeholder={t('workflow.nodes.http.apiPlaceholder')!}
placeholderClassName='!leading-[21px]'
/> />
</div > </div >
) )

View File

@ -203,6 +203,7 @@ const translation = {
http: { http: {
inputVars: 'Input Variables', inputVars: 'Input Variables',
api: 'API', api: 'API',
apiPlaceholder: 'Enter URL, type / insert variable',
notStartWithHttp: 'API should start with http:// or https://', notStartWithHttp: 'API should start with http:// or https://',
key: 'Key', key: 'Key',
value: 'Value', value: 'Value',

View File

@ -203,6 +203,7 @@ const translation = {
http: { http: {
inputVars: '输入变量', inputVars: '输入变量',
api: 'API', api: 'API',
apiPlaceholder: '输入 URL输入变量时请键入/',
notStartWithHttp: 'API 应该以 http:// 或 https:// 开头', notStartWithHttp: 'API 应该以 http:// 或 https:// 开头',
key: '键', key: '键',
value: '值', value: '值',