/** * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates * SPDX-License-Identifier: MIT */ import React, { useMemo, useState } from 'react'; import { I18n } from '@flowgram.ai/editor'; import { IconButton, Input } from '@douyinfe/semi-ui'; import { IconChevronDown, IconChevronRight, IconDelete } from '@douyinfe/semi-icons'; import { IFlowConstantValue } from '@/shared'; import { ConstantInputStrategy } from '@/components/constant-input'; import { PropsType } from './types'; import './styles.css'; import { useChildList } from './hooks/use-child-list'; import { InjectDynamicValueInput } from '../dynamic-value-input'; import { BlurInput } from '../blur-input'; import { IconAddChildren } from './icon'; const AddObjectChildStrategy: ConstantInputStrategy = { hit: (schema) => schema.type === 'object', Renderer: () => ( ), }; export function InputValueRow( props: { keyName?: string; value?: any; onUpdateKey: (key: string) => void; onUpdateValue: (value: any) => void; onRemove?: () => void; $isLast?: boolean; $level?: number; } & Pick ) { const { keyName, value, $level = 0, onUpdateKey, onUpdateValue, $isLast, onRemove, constantProps, hasError, readonly, } = props; const [collapse, setCollapse] = useState(false); const { canAddField, hasChildren, list, add, updateKey, updateValue, remove } = useChildList( value, onUpdateValue ); const strategies = useMemo( () => [...(hasChildren ? [AddObjectChildStrategy] : []), ...(constantProps?.strategies || [])], [hasChildren, constantProps?.strategies] ); const flowDisplayValue = useMemo( () => hasChildren ? ({ type: 'constant', schema: { type: 'object' }, } as IFlowConstantValue) : value, [hasChildren, value] ); return ( <>
0 ? 'show-line' : ''} ${ $isLast ? 'is-last' : '' } ${hasChildren ? 'show-collapse' : ''}`} > {hasChildren && (
setCollapse((_collapse) => !_collapse)} > {collapse ? : }
)}
onUpdateKey?.(v)} placeholder={I18n.t('Input Key')} /> onUpdateValue(v)} hasError={hasError} constantProps={{ ...constantProps, strategies, }} />
{canAddField && ( } onClick={() => { add({ type: 'constant', content: '', schema: { type: 'string' }, }); setCollapse(true); }} /> )} } size="small" onClick={() => onRemove?.()} />
{hasChildren && (
{list.map((_item, index) => ( { updateValue(_item.id, _v); }} onUpdateKey={(k) => { updateKey(_item.id, k); }} onRemove={() => { remove(_item.id); }} $isLast={index === list.length - 1} /> ))}
)}
); }