import React, { useState, useLayoutEffect } from 'react'; import { TypeSelector, DynamicValueInput } from '@flowgram.ai/form-materials'; import { Input, Button } from 'antd'; import { JsonSchema } from '../../typings'; import { LeftColumn, Row } from './styles'; import { DeleteOutlined } from '@ant-design/icons'; export interface PropertyEditProps { propertyKey: string; value: JsonSchema; useFx?: boolean; disabled?: boolean; onChange: (value: JsonSchema, propertyKey: string, newPropertyKey?: string) => void; onDelete?: () => void; } export const PropertyEdit: React.FC = (props) => { const { value, disabled } = props; const [inputKey, updateKey] = useState(props.propertyKey); const updateProperty = (key: keyof JsonSchema, val: any) => { value[key] = val; props.onChange(value, props.propertyKey); }; const partialUpdateProperty = (val?: Partial) => { props.onChange({ ...value, ...val }, props.propertyKey); }; useLayoutEffect(() => { updateKey(props.propertyKey); }, [props.propertyKey]); return ( partialUpdateProperty(val)} /> updateKey(v.trim())} onBlur={() => { if (inputKey !== '') { props.onChange(value, props.propertyKey, inputKey); } else { updateKey(props.propertyKey); } }} style={{ paddingLeft: 26 }} /> { updateProperty('default', val)} schema={value} style={{ flexGrow: 1 }} /> } {props.onDelete && !disabled && (