mirror of
https://gitee.com/ByteDance/flowgram.ai.git
synced 2025-07-07 17:43:29 +08:00
* feat: init prompt editor * feat: simple prompt editor * feat: split prompt editor * feat: fix-layout prompt editor
71 lines
2.4 KiB
TypeScript
71 lines
2.4 KiB
TypeScript
/**
|
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
import { Field } from '@flowgram.ai/free-layout-editor';
|
|
import { DynamicValueInput, PromptEditorWithVariables } from '@flowgram.ai/form-materials';
|
|
|
|
import { FormItem } from '../form-item';
|
|
import { Feedback } from '../feedback';
|
|
import { JsonSchema } from '../../typings';
|
|
import { useNodeRenderContext } from '../../hooks';
|
|
|
|
export function FormInputs() {
|
|
const { readonly } = useNodeRenderContext();
|
|
|
|
return (
|
|
<Field<JsonSchema> name="inputs">
|
|
{({ field: inputsField }) => {
|
|
const required = inputsField.value?.required || [];
|
|
const properties = inputsField.value?.properties;
|
|
if (!properties) {
|
|
return <></>;
|
|
}
|
|
const content = Object.keys(properties).map((key) => {
|
|
const property = properties[key];
|
|
|
|
const formComponent = property.extra?.formComponent;
|
|
|
|
const vertical = ['prompt-editor'].includes(formComponent || '');
|
|
|
|
return (
|
|
<Field key={key} name={`inputsValues.${key}`} defaultValue={property.default}>
|
|
{({ field, fieldState }) => (
|
|
<FormItem
|
|
name={key}
|
|
vertical={vertical}
|
|
type={property.type as string}
|
|
required={required.includes(key)}
|
|
>
|
|
{formComponent === 'prompt-editor' && (
|
|
<PromptEditorWithVariables
|
|
value={field.value}
|
|
onChange={field.onChange}
|
|
readonly={readonly}
|
|
hasError={Object.keys(fieldState?.errors || {}).length > 0}
|
|
/>
|
|
)}
|
|
{!formComponent && (
|
|
<DynamicValueInput
|
|
value={field.value}
|
|
onChange={field.onChange}
|
|
readonly={readonly}
|
|
hasError={Object.keys(fieldState?.errors || {}).length > 0}
|
|
constantProps={{
|
|
schema: property,
|
|
}}
|
|
/>
|
|
)}
|
|
<Feedback errors={fieldState?.errors} warnings={fieldState?.warnings} />
|
|
</FormItem>
|
|
)}
|
|
</Field>
|
|
);
|
|
});
|
|
return <>{content}</>;
|
|
}}
|
|
</Field>
|
|
);
|
|
}
|