import isPlainObject from 'lodash/isPlainObject'; import React from 'react'; import Alert from './components/Alert2'; import ImageGallery from './components/ImageGallery'; import {RendererEnv} from './env'; import {RendererProps} from './factory'; import {LocaleContext, TranslateFn} from './locale'; import {RootRenderer} from './RootRenderer'; import {SchemaRenderer} from './SchemaRenderer'; import Scoped from './Scoped'; import {IRendererStore} from './store'; import {ThemeContext} from './theme'; import {Schema, SchemaNode} from './types'; import getExprProperties from './utils/filter-schema'; import {autobind, createObject, isEmpty} from './utils/helper'; import {RootStoreContext} from './WithRootStore'; export interface RootRenderProps { location?: Location; theme?: string; [propName: string]: any; } export interface RootProps { schema: SchemaNode; rootStore: IRendererStore; env: RendererEnv; theme: string; pathPrefix?: string; locale?: string; translate?: TranslateFn; [propName: string]: any; } export class Root extends React.Component { @autobind resolveDefinitions(name: string) { const definitions = (this.props.schema as Schema).definitions; if (!name || isEmpty(definitions)) { return {}; } return definitions && definitions[name]; } render() { const { schema, rootStore, env, pathPrefix, location, data, locale, translate, ...rest } = this.props; const theme = env.theme; let themeName = this.props.theme || 'cxd'; if (themeName === 'default') { themeName = 'cxd'; } return ( ); } } export interface renderChildProps extends Partial { env: RendererEnv; } export type ReactElement = React.ReactNode[] | JSX.Element | null | false; export function renderChildren( prefix: string, node: SchemaNode, props: renderChildProps ): ReactElement { if (Array.isArray(node)) { return node.map((node, index) => renderChild(`${prefix}/${index}`, node, { ...props, key: `${props.key ? `${props.key}-` : ''}${index}` }) ); } return renderChild(prefix, node, props); } export function renderChild( prefix: string, node: SchemaNode, props: renderChildProps ): ReactElement { if (Array.isArray(node)) { return renderChildren(prefix, node, props); } const typeofnode = typeof node; if (typeofnode === 'undefined' || node === null) { return null; } let schema: Schema = typeofnode === 'string' || typeofnode === 'number' ? {type: 'tpl', tpl: String(node)} : (node as Schema); const transform = props.propsTransform; if (transform) { // @ts-ignore delete props.propsTransform; props = transform(props); } return ( ); } export default Scoped(Root);