import { HeadlessEditorOptions, OnChangeListener } from 'headless-json-editor'; import { Editor } from './Editor'; import { WidgetPlugin } from './decorators'; export type UseEditorOptions = HeadlessEditorOptions & { /** * A function called after each update which that accepts three arguments: * * - `data` the latest data of the web form * - `root` the rootNode of the json-editor and * - `editor` the current editor instance * * _Only supported by useEditor_ */ onChange?: OnChangeListener; /** * The list of available widgets to render the JSON Schema tree. Each node in the tree should * have a matching widget to be rendered or the editor will either ignore or show an error * using an Error Widget if added. */ widgets?: WidgetPlugin[]; /** * A unique id that if changed, will recreate the editor * * _Only supported by useEditor_ */ cacheKey?: string | number; /** if all optional properties should be added when missing */ addOptionalProps?: boolean; /** set tpo true to validate while typing. Defaults to onBlur */ liveUpdate?: boolean; }; /** * Create an editor-instance containing a JSON Schema tree, registered widgets and plugins and the * overall state of the data. * * @example * import { useEditor } from '@sagold/react-json-editor'; * * function WebFormComponent() { * const editor = useEditor(options); * * // ... * * @caveat when running React.StrictMode the returned editor instance will be undefined on the first call * @caveat Each JSON Schema requires a valid JSON Schema type keyword * * @returns Returns an instance of `Editor`. For details on working with `editor` see Usage below or more in depth details in API Reference on [Editor#instance](/docs/api-editor--docs#instance) */ export declare function useEditor(options: UseEditorOptions): Editor | null;