import { ControlElement , UISchemaElement } from '../models' ; import { coreReducer , errorAt , subErrorsAt , } from './core' ; import { defaultDataReducer } from './default-data' ; import { rendererReducer } from './renderers' ; import { JsonFormsState } from '../store' ; import type { JsonFormsUISchemaRegistryEntry } from './uischemas' ; import { findMatchingUISchema , uischemaRegistryReducer , } from './uischemas' ; import { fetchErrorTranslator , fetchLocale , i18nReducer , } from './i18n' ; import { Generate } from '../generators' ; import { JsonSchema } from '../models/jsonSchema' ; import { cellReducer } from './cells' ; import { configReducer } from './config' ; import get from 'lodash/get' ; import { fetchTranslator } from '.' ; import { ErrorTranslator , Translator } from '../i18n' ; export const jsonFormsReducerConfig = { core : coreReducer , renderers : rendererReducer , cells : cellReducer , config : configReducer , uischemas : uischemaRegistryReducer , defaultData : defaultDataReducer , i18n : i18nReducer , } ; param schema param schemaPath param path param fallbackLayoutType param control export const findUISchema = ( uischemas , schema , schemaPath , path , fallbackLayoutType = 'VerticalLayout' , control ? , rootSchema ? ) : UISchemaElement => { if ( control && control . options && control . options . detail ) { if ( typeof control . options . detail === 'string' ) { if ( control . options . detail . toUpperCase ( ) === 'GENERATE' ) { return Generate . uiSchema ( schema , fallbackLayoutType ) ; } } else if ( typeof control . options . detail === 'object' ) { if ( control . options . detail . type && typeof control . options . detail . type === 'string' ) { return control . options . detail as UISchemaElement ; } } } const uiSchema = findMatchingUISchema ( uischemas ) ( schema , schemaPath , path ) ; if ( uiSchema === undefined ) { return Generate . uiSchema ( schema , fallbackLayoutType , '#' , rootSchema ) ; } return uiSchema ; } ; export const getErrorAt = ( instancePath , schema ) => ( state ) => { return errorAt ( instancePath , schema ) ( state . jsonforms . core ) ; } ; export const getSubErrorsAt = ( instancePath , schema ) => ( state ) => subErrorsAt ( instancePath , schema ) ( state . jsonforms . core ) ; export const getConfig = ( state ) => state . jsonforms . config ; export const getLocale = ( state ) => fetchLocale ( get ( state , 'jsonforms.i18n' ) ) ; export const getTranslator = ( ) => ( state ) : Translator => fetchTranslator ( get ( state , 'jsonforms.i18n' ) ) ; export const getErrorTranslator = ( ) => ( state ) : ErrorTranslator => fetchErrorTranslator ( get ( state , 'jsonforms.i18n' ) ) ;