react-json-schema-ui-editor
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -137,2 +137,3 @@ import * as react_jsx_runtime from 'react/jsx-runtime'; | ||
type: (typeof jsonSchemaPossibleFieldType)[number]; | ||
errors?: string[]; | ||
} | ||
@@ -139,0 +140,0 @@ interface ButtonInputParams { |
@@ -8,2 +8,12 @@ // src/components/JsonSchemaContext.tsx | ||
import _ from "lodash"; | ||
// src/hooks/errors.ts | ||
var EmptyPropertyNameError = class extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = "EmptyPropertyName"; | ||
} | ||
}; | ||
// src/hooks/useJsonSchema.ts | ||
var useJsonSchema = (init = {}, onChange) => { | ||
@@ -14,2 +24,3 @@ const isFirstRender = useRef(true); | ||
}, []); | ||
const [errors, setErrors] = useState([]); | ||
const [schema, setSchema] = useState(init); | ||
@@ -65,2 +76,12 @@ useEffect(() => { | ||
const addPropertyToObject = (path, property) => { | ||
if (property.length === 0) { | ||
setErrors((prev) => [ | ||
...prev.filter((e) => e.path !== path), | ||
{ | ||
path, | ||
error: new EmptyPropertyNameError("Property name can't be empty") | ||
} | ||
]); | ||
return; | ||
} | ||
setSchema( | ||
@@ -74,2 +95,7 @@ (prev) => _.setWith( | ||
); | ||
setErrors( | ||
(prev) => prev.filter( | ||
(e) => e.path !== path && e.error instanceof EmptyPropertyNameError | ||
) | ||
); | ||
}; | ||
@@ -79,2 +105,3 @@ const getPathState = (path) => { | ||
}; | ||
const getPathErrors = (path) => errors.filter((e) => e.path === path).map((e) => e.error); | ||
return { | ||
@@ -90,3 +117,4 @@ schema, | ||
getPathState, | ||
getPropertyPath | ||
getPropertyPath, | ||
getPathErrors | ||
} | ||
@@ -137,3 +165,4 @@ }; | ||
const { | ||
actions: { addPropertyToObject } | ||
actions: { addPropertyToObject }, | ||
derived: { getPathErrors } | ||
} = useJsonSchemaContext(); | ||
@@ -148,3 +177,4 @@ const [propertyToBeAdded, setPropertyToBeAdded] = useState2(""); | ||
type: "string", | ||
value: propertyToBeAdded | ||
value: propertyToBeAdded, | ||
errors: getPathErrors(path || "").map((e) => e.message) | ||
}), | ||
@@ -151,0 +181,0 @@ renderAddPropertyButton({ |
{ | ||
"name": "react-json-schema-ui-editor", | ||
"version": "0.2.0", | ||
"version": "0.3.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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82695
897