@ui-schema/react
Version:
Schema-driven UI generator for React using JSON Schema. Build powerful form and interface generators with headless components and hooks.
44 lines • 1.44 kB
JavaScript
import * as React from 'react';
import { Translate } from '@ui-schema/react/Translate';
import { SchemaRootProvider, isRootSchema, useSchemaRoot } from '@ui-schema/react/SchemaRootProvider';
import { useSchemaRef } from '@ui-schema/react/ReferencingHandler';
import { getSchemaId } from '@ui-schema/ui-schema/Utils/getSchema';
import { jsx as _jsx } from "react/jsx-runtime";
export const ReferencingHandler = ({
rootContext,
Next,
...props
}) => {
const {
schema: baseSchema,
isVirtual
} = props;
const {
schema: maybeRootSchema,
definitions: maybeDefinitions,
...nestedRootProps
} = useSchemaRoot();
const isRoot = Boolean(isRootSchema(baseSchema) || rootContext || baseSchema.get('definitions') || baseSchema.get('$defs'));
const definitions = isRoot ? baseSchema.get('definitions') || baseSchema.get('$defs') : maybeDefinitions;
const {
schema,
refsPending
} = useSchemaRef(maybeRootSchema, definitions, isRoot, baseSchema);
return refsPending && refsPending.size > 0 ? isVirtual ? null : _jsx(Translate, {
text: 'labels.loading',
fallback: 'Loading'
}) : isRoot ? _jsx(SchemaRootProvider, {
...nestedRootProps,
...(rootContext || {}),
id: getSchemaId(schema),
schema: schema,
definitions: definitions,
children: _jsx(Next.Component, {
...props,
schema: schema
})
}) : _jsx(Next.Component, {
...props,
schema: schema
});
};