react-json-schema-ui-editor
Advanced tools
Comparing version
@@ -151,5 +151,6 @@ import * as react_jsx_runtime from 'react/jsx-runtime'; | ||
renderPropertyName: (p: PropertyNameInputParams) => React.ReactNode; | ||
onChange?: (json: JSONSchema7) => any; | ||
} | ||
declare const JsonSchemaEditor: ({ initialSchema, renderInput, renderAddPropertyButton, renderRemovePropertyButton, renderPropertyName }: JsonSchemaEditorProps) => react_jsx_runtime.JSX.Element; | ||
declare const JsonSchemaEditor: ({ initialSchema, renderInput, renderAddPropertyButton, renderRemovePropertyButton, renderPropertyName, onChange, }: JsonSchemaEditorProps) => react_jsx_runtime.JSX.Element; | ||
export { type ButtonInputParams, type InputInputParams, type JSONSchema7, type JSONSchema7Array, type JSONSchema7Definition, type JSONSchema7Object, type JSONSchema7Type, type JSONSchema7TypeName, type JSONSchema7Version, JsonSchemaEditor, type JsonSchemaEditorProps, type PropertyNameInputParams, jsonSchemaAvailableTypes, jsonSchemaPossibleFieldType, jsonSchemaPossibleFields }; |
@@ -6,6 +6,15 @@ // src/components/JsonSchemaContext.tsx | ||
// src/hooks/useJsonSchema.ts | ||
import { useState } from "react"; | ||
import { useEffect, useRef, useState } from "react"; | ||
import _ from "lodash"; | ||
var useJsonSchema = (init = {}) => { | ||
var useJsonSchema = (init = {}, onChange) => { | ||
const isFirstRender = useRef(true); | ||
useEffect(() => { | ||
isFirstRender.current = false; | ||
}, []); | ||
const [schema, setSchema] = useState(init); | ||
useEffect(() => { | ||
if (onChange && !isFirstRender.current) { | ||
onChange(schema); | ||
} | ||
}, [schema]); | ||
const getPropertyPath = (path) => { | ||
@@ -85,7 +94,8 @@ return `${path ? `${path}.` : ""}`; | ||
getSchemaProperty: () => ({}), | ||
getPathState: () => ({}) | ||
getPathState: () => ({}), | ||
getPropertyPath: () => "." | ||
} | ||
}); | ||
var JsonSchemaContextProvider = ({ children, init }) => { | ||
const value = useJsonSchema(init); | ||
var JsonSchemaContextProvider = ({ children, init, onChange }) => { | ||
const value = useJsonSchema(init, onChange); | ||
return /* @__PURE__ */ jsx(JsonSchemaContext.Provider, { value, children }); | ||
@@ -286,5 +296,6 @@ }; | ||
renderRemovePropertyButton, | ||
renderPropertyName | ||
renderPropertyName, | ||
onChange | ||
}) => { | ||
return /* @__PURE__ */ jsx3(JsonSchemaContextProvider, { init: initialSchema, children: /* @__PURE__ */ jsx3( | ||
return /* @__PURE__ */ jsx3(JsonSchemaContextProvider, { init: initialSchema, onChange, children: /* @__PURE__ */ jsx3( | ||
JsonSchemaPropertyRow, | ||
@@ -291,0 +302,0 @@ { |
{ | ||
"name": "react-json-schema-ui-editor", | ||
"version": "0.0.9", | ||
"version": "0.1.0", | ||
"description": "React component to edit json schema in a UI.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
73105
3.12%798
2.97%