import { FormLayout } from '@formily/antd'; import { createForm, Field, onFormInputChange } from '@formily/core'; import { FieldContext, FormContext, observer, RecursionField, useField, useFieldSchema } from '@formily/react'; import { uid } from '@nocobase/utils'; import { Spin } from 'antd'; import React, { useEffect, useMemo } from 'react'; import { useActionContext } from '..'; import { useAttach, useComponent } from '../..'; import { useProps } from '../../hooks/useProps'; export interface FormProps { [key: string]: any; } const FormComponent: React.FC = (props) => { const { form, children, ...others } = props; const field = useField(); const fieldSchema = useFieldSchema(); // TODO: component 里 useField 会与当前 field 存在偏差 const f = useAttach(form.createVoidField({ ...field.props, basePath: '' })); return ( ); }; const Def = (props: any) => props.children; const FormDecorator: React.FC = (props) => { const { form, children, ...others } = props; const field = useField(); const fieldSchema = useFieldSchema(); // TODO: component 里 useField 会与当前 field 存在偏差 const f = useAttach(form.createVoidField({ ...field.props, basePath: '' })); const Component = useComponent(fieldSchema['x-component'], Def); return ( {/* {children} */} ); }; const WithForm = (props) => { const { form } = props; const fieldSchema = useFieldSchema(); const { setFormValueChanged } = useActionContext(); useEffect(() => { const id = uid(); form.addEffects(id, () => { onFormInputChange((form) => { setFormValueChanged?.(true); }); }); return () => { form.removeEffects(id); }; }, []); return fieldSchema['x-decorator'] === 'Form' ? : ; }; const WithoutForm = (props) => { const fieldSchema = useFieldSchema(); const { setFormValueChanged } = useActionContext(); const form = useMemo( () => createForm({ effects() { onFormInputChange((form) => { setFormValueChanged(true); }); }, }), [], ); return fieldSchema['x-decorator'] === 'Form' ? ( ) : ( ); }; export const Form: React.FC & { Designer?: any; ReadPrettyDesigner?: any } = observer((props) => { const field = useField(); const { form, ...others } = useProps(props); return (
{form ? : }
); });