import { Field } from '@formily/core'; import { ISchema, useField, useFieldSchema } from '@formily/react'; import { GeneralSchemaDesigner, GeneralSchemaItems, SchemaSettings, isPatternDisabled, useCollection, useCollectionManager, useDesignable, useFormBlockContext, } from '@nocobase/client'; import set from 'lodash/set'; import React from 'react'; import { useMapTranslation } from '../locale'; const Designer = () => { const { getCollectionJoinField } = useCollectionManager(); const { getField } = useCollection(); const { form } = useFormBlockContext(); const field = useField(); const fieldSchema = useFieldSchema(); const { t } = useMapTranslation(); const { dn, refresh } = useDesignable(); const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']); const originalTitle = collectionField?.uiSchema?.title; const initialValue = { title: field.title === originalTitle ? undefined : field.title, }; if (!field.readPretty) { initialValue['required'] = field.required; } let readOnlyMode = 'editable'; if (fieldSchema['x-disabled'] === true) { readOnlyMode = 'readonly'; } if (fieldSchema['x-read-pretty'] === true) { readOnlyMode = 'read-pretty'; } return ( {form && !form?.readPretty && !isPatternDisabled(fieldSchema) && ( { const schema: ISchema = { ['x-uid']: fieldSchema['x-uid'], }; switch (v) { case 'readonly': { fieldSchema['x-read-pretty'] = false; fieldSchema['x-disabled'] = true; schema['x-read-pretty'] = false; schema['x-disabled'] = true; field.readPretty = false; field.disabled = true; break; } case 'read-pretty': { fieldSchema['x-read-pretty'] = true; fieldSchema['x-disabled'] = false; schema['x-read-pretty'] = true; schema['x-disabled'] = false; field.readPretty = true; break; } default: { fieldSchema['x-read-pretty'] = false; fieldSchema['x-disabled'] = false; schema['x-read-pretty'] = false; schema['x-disabled'] = false; field.readPretty = false; field.disabled = false; break; } } dn.emit('patch', { schema, }); dn.refresh(); }} /> )} { if (zoom) { set(fieldSchema, 'x-component-props.zoom', zoom); Object.assign(field.componentProps, fieldSchema['x-component-props']); dn.emit('patch', { schema: { 'x-uid': fieldSchema['x-uid'], 'x-component-props': field.componentProps, }, }); } dn.refresh(); }} /> ); }; export default Designer;