import * as React from 'react'; /* order might matter on these imports */ /* first core... */ import { utils as rjsfUtils, Field } from '@rjsf/core'; /* ...then lib imports */ import _ObjectField from '@rjsf/core/lib/components/fields/ObjectField'; import { UnControlled } from 'react-codemirror2'; import * as CodeMirror from 'codemirror'; import { JSONExt } from '@lumino/coreutils'; /** * This is a pretty nasty way to deal with the ObjectField being very hard * to reach at import time * * We use the upstream ObjectField at runtime to construct a private class. * This could likely be improved with a namespace or something. */ export function makeJSONObjectField(ObjectField: typeof _ObjectField): Field { /** * A raw JSON Object which can be stored/edited inside an RJSF */ class JSONObjectField extends ObjectField { protected _editor: CodeMirror.Editor; render(): JSX.Element { const { uiSchema, formData, idSchema, name, registry = rjsfUtils.getDefaultRegistry(), } = this.props; const { definitions } = registry; const schema = (rjsfUtils as any).retrieveSchema( this.props.schema, definitions, formData ); let title; if (this.state.wasPropertyKeyModified) { title = name; } else { title = schema.title === undefined ? name : schema.title; } const isLight = !!document.querySelector('body[data-jp-theme-light="true"]'); const description = uiSchema['ui:description'] || schema.description; const { canSave } = this; const options = { mode: 'application/json', theme: isLight ? 'default' : 'zenburn', matchBrackets: true, autoCloseBrackets: true, }; return ( <>
{description}