import { DEFAULT_INITIAL_DATA, defaultInitialDataTs, fieldWrapperCss, fieldWrapperTs, } from '@flowgram.ai/demo-node-form'; import { Editor } from '../editor.tsx'; import { PreviewEditor } from '../../preview-editor.tsx'; import { nodeRegistry } from './node-registry.tsx'; const nodeRegistryFile = { code: `import { DataEvent, EffectFuncProps, Field, FieldRenderProps, FormMeta, ValidateTrigger, WorkflowNodeRegistry, FieldArray, FieldArrayRenderProps, } from '@flowgram.ai/free-layout-editor'; import { FieldWrapper } from '@flowgram.ai/demo-node-form'; import { Input, Button, Popover } from '@douyinfe/semi-ui'; import { IconPlus, IconCrossCircleStroked, IconArrowDown } from '@douyinfe/semi-icons'; import './index.css'; import '../index.css'; export const render = () => (
Array Examples
{({ field, fieldState }: FieldArrayRenderProps) => ( {field.map((child, index) => ( {({ field: childField, fieldState: childState }: FieldRenderProps) => (
{index < field.value!.length - 1 ? (
)}
))}
)}
); interface FormData { array: string[]; } const formMeta: FormMeta = { render, validateTrigger: ValidateTrigger.onChange, defaultValues: { array: ['default'], }, validate: { 'array.*': ({ value }) => value.length > 8 ? 'max length exceeded: current length is ' + value.length : undefined, }, effect: { 'array.*': [ { event: DataEvent.onValueInit, effect: ({ value, name }: EffectFuncProps) => { console.log(name + ' value init to ', value); }, }, { event: DataEvent.onValueChange, effect: ({ value, name }: EffectFuncProps) => { console.log(name + ' value changed to ', value); }, }, ], }, }; export const nodeRegistry: WorkflowNodeRegistry = { type: 'custom', meta: {}, defaultPorts: [{ type: 'output' }, { type: 'input' }], formMeta, }; `, active: true, }; export const NodeFormArrayPreview = () => { const files = { 'node-registry.tsx': nodeRegistryFile, 'initial-data.ts': { code: defaultInitialDataTs, active: true }, 'field-wrapper.tsx': { code: fieldWrapperTs, active: true }, 'field-wrapper.css': { code: fieldWrapperCss, active: true }, }; return ( ); };