@satoshibits/react-json-schema-builder 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/index.cjs14.js +1 -1
  2. package/dist/index.cjs16.js +1 -1
  3. package/dist/index.cjs2.js +1 -1
  4. package/dist/index.cjs2.js.map +1 -1
  5. package/dist/index.cjs21.js +1 -1
  6. package/dist/index.cjs3.js +1 -1
  7. package/dist/index.cjs3.js.map +1 -1
  8. package/dist/index.cjs37.js +1 -1
  9. package/dist/index.cjs37.js.map +1 -1
  10. package/dist/index.cjs38.js +1 -6
  11. package/dist/index.cjs38.js.map +1 -1
  12. package/dist/index.cjs39.js +1 -6
  13. package/dist/index.cjs39.js.map +1 -1
  14. package/dist/index.cjs40.js +1 -6
  15. package/dist/index.cjs40.js.map +1 -1
  16. package/dist/index.cjs41.js +1 -1
  17. package/dist/index.cjs41.js.map +1 -1
  18. package/dist/index.cjs42.js +1 -1
  19. package/dist/index.cjs42.js.map +1 -1
  20. package/dist/index.cjs43.js +1 -1
  21. package/dist/index.cjs43.js.map +1 -1
  22. package/dist/index.cjs44.js +6 -1
  23. package/dist/index.cjs44.js.map +1 -1
  24. package/dist/index.cjs45.js +6 -1
  25. package/dist/index.cjs45.js.map +1 -1
  26. package/dist/index.cjs46.js +6 -1
  27. package/dist/index.cjs46.js.map +1 -1
  28. package/dist/index.es14.js +4 -4
  29. package/dist/index.es16.js +5 -5
  30. package/dist/index.es2.js +73 -71
  31. package/dist/index.es2.js.map +1 -1
  32. package/dist/index.es21.js +6 -6
  33. package/dist/index.es3.js +131 -134
  34. package/dist/index.es3.js.map +1 -1
  35. package/dist/index.es37.js +97 -815
  36. package/dist/index.es37.js.map +1 -1
  37. package/dist/index.es38.js +56 -10
  38. package/dist/index.es38.js.map +1 -1
  39. package/dist/index.es39.js +24 -10
  40. package/dist/index.es39.js.map +1 -1
  41. package/dist/index.es40.js +45 -10
  42. package/dist/index.es40.js.map +1 -1
  43. package/dist/index.es41.js +71 -99
  44. package/dist/index.es41.js.map +1 -1
  45. package/dist/index.es42.js +56 -52
  46. package/dist/index.es42.js.map +1 -1
  47. package/dist/index.es43.js +827 -19
  48. package/dist/index.es43.js.map +1 -1
  49. package/dist/index.es44.js +10 -45
  50. package/dist/index.es44.js.map +1 -1
  51. package/dist/index.es45.js +10 -86
  52. package/dist/index.es45.js.map +1 -1
  53. package/dist/index.es46.js +10 -60
  54. package/dist/index.es46.js.map +1 -1
  55. package/dist/packages/builder/context.d.ts +3 -1
  56. package/dist/packages/builder/context.d.ts.map +1 -1
  57. package/dist/packages/builder/schema-builder.d.ts.map +1 -1
  58. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"index.es2.js","sources":["../src/packages/builder/context.tsx"],"sourcesContent":["import { createContext, useContext, useState } from \"react\";\n\nimport type { PropsWithChildren, SetStateAction } from \"react\";\nimport type { JSONSchema7, JSONSchema7Definition } from \"json-schema\";\nimport { clone, isEmpty } from \"remeda\";\nimport type { OperationError } from \"./shared-types\";\n\ninterface ContextState<T extends JSONSchema7> {\n schema: T;\n setSchema: React.Dispatch<T>;\n path: string[];\n setPath: React.Dispatch<SetStateAction<string[]>>;\n}\n\nexport const SchemaContext = createContext<\n ContextState<JSONSchema7> | undefined\n>(undefined);\n\nconst defaultSchema: JSONSchema7 = {\n $schema: \"http://json-schema.org/draft-07/schema#\",\n type: \"object\",\n title: \"title\",\n description: \"\",\n properties: {},\n required: [],\n};\n\nfunction SchemaProvider({\n children,\n initialSchema,\n}: PropsWithChildren<{ initialSchema?: JSONSchema7 }>) {\n const [schema, setSchema] = useState<JSONSchema7>(\n initialSchema ?? defaultSchema,\n );\n\n /**\n * Path represents the path to a nested property in the schema.\n * It should only contain property keys.\n * An empty path means the current schema is the root schema since\n * the path only represents nested properties.\n */\n const [path, setPath] = useState<string[]>([]);\n\n // NOTE: you *might* need to memoize your values\n // Learn more in http://kcd.im/optimize-context\n\n return (\n <SchemaContext.Provider value={{ schema, setSchema, path, setPath }}>\n {children}\n </SchemaContext.Provider>\n );\n}\n\nexport type PropertyAddError = OperationError & {\n status: \"error\";\n};\n\nexport interface PropertyAddSuccess {\n status: \"success\";\n property: JSONSchema7;\n}\n\nexport interface PropertyChangeSuccess {\n status: \"success\";\n property: JSONSchema7Definition;\n}\n\nfunction useSchema() {\n const context = useContext(SchemaContext);\n\n if (context === undefined) {\n throw new Error(\"useSchema must be used within a SchemaProvider\");\n }\n\n const { path, schema, setSchema } = context;\n\n /**\n * Navigates to the correct property schema of the latest key in the provided path.\n *\n * It will traverse both \"properties\" and \"items\" to find the correct property schema.\n *\n * It will only return a property schema if the provided path is valid i.e. it\n * correctly follows the schema's nesting structure.\n *\n * It will only return a parent schema if the provided path is valid i.e. it\n * correctly follows the schema's nesting structure.\n */\n const navigateToCorrectNesting = (\n providedSchema: JSONSchema7,\n providedPath: string[],\n ) => {\n let current = providedSchema;\n let propertySchema: JSONSchema7 | null = null;\n // Should be the schema of type \"object\" containing the property in its properties key\n let parentSchema: JSONSchema7 | null = null;\n\n for (const p of providedPath) {\n if (\n current.type === \"array\" &&\n current.items &&\n !Array.isArray(current.items) &&\n typeof current.items === \"object\" &&\n current.items.type === \"object\" &&\n typeof current.items.properties?.[p] === \"object\"\n ) {\n parentSchema = current.items;\n propertySchema = current.items.properties[p];\n current = current.items;\n } else if (\n current.type === \"object\" &&\n current.properties &&\n !Array.isArray(current.properties) &&\n typeof current.properties[p] === \"object\"\n ) {\n parentSchema = current;\n propertySchema = current.properties[p];\n current = current.properties[p];\n }\n }\n\n return { propertySchema, parentSchema };\n };\n\n /**\n * Gets the current schema of the latest key in the path.\n * If path is empty, it will return the root schema.\n *\n * It should always return the \"object\" schema of the current path.\n */\n const getCurrentSchema = (initialSchema?: JSONSchema7) => {\n // Gets the correct object schema if under nesting\n // Otherwise, return the root schema\n const { propertySchema } = navigateToCorrectNesting(\n initialSchema ?? schema,\n path,\n );\n\n if (propertySchema) {\n if (propertySchema.type === \"array\") {\n return propertySchema.items as JSONSchema7;\n }\n\n return propertySchema;\n }\n\n return initialSchema ?? schema;\n };\n\n /**\n * Gets the correct property schema of the latest key in the path.\n * If no path is provided, it will return null.\n */\n const getCurrentProperty = () => {\n const { propertySchema } = navigateToCorrectNesting(schema, path);\n\n return propertySchema;\n };\n\n /**\n * Change the key of a property in the schema. It expects\n * the find the key at the current path.\n */\n const handleKeyChange = (key: string, newKey: string) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to change\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n if (current.properties?.[key]) {\n //Important: maintain order as to not confuse users\n const newProperties = Object.entries(current.properties).map(\n ([k, val]) => {\n return [k === key ? newKey : k, val];\n },\n );\n\n current.properties = Object.fromEntries(\n newProperties,\n ) as JSONSchema7[\"properties\"];\n }\n\n if (current.required?.includes(key)) {\n current.required = current.required.map((item) =>\n item === key ? newKey : item,\n );\n }\n\n setSchema(newSchema);\n };\n\n const handlePropertyChange = (\n key: string,\n updates: Partial<JSONSchema7Definition> & { isRequired?: boolean },\n ): PropertyChangeSuccess | undefined => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to change\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Handle required field updates\n if (typeof updates === \"object\" && \"isRequired\" in updates) {\n if (current.type === \"object\") {\n if (!current.required) {\n current.required = [];\n }\n if (updates.isRequired) {\n if (!current.required.includes(key)) {\n current.required.push(key);\n }\n } else {\n current.required = current.required.filter((item) => item !== key);\n }\n }\n delete updates.isRequired;\n }\n\n let isUpdated = false;\n\n // Update the property\n if (current.type === \"object\" && current.properties) {\n const originalProperty = current.properties[key];\n // Ensure the property exists and is not a boolean\n if (typeof originalProperty !== \"boolean\" && originalProperty) {\n if (typeof updates !== \"boolean\") {\n //if updates changes the type of the property,\n //only the title, description, and default properties should remain\n //from the original property\n if (updates.type && updates.type !== originalProperty.type) {\n updates = {\n title: originalProperty.title,\n description: originalProperty.description,\n default: originalProperty.default,\n ...updates,\n };\n } else if (updates.enum) {\n //if the property is an enum, only the title and description should remain\n //from the original property\n delete updates.type;\n delete updates.items;\n delete updates.properties;\n updates = {\n title: originalProperty.title,\n description: originalProperty.description,\n ...updates,\n };\n } else {\n updates = { ...originalProperty, ...updates };\n }\n\n current.properties[key] = updates;\n }\n }\n isUpdated = true;\n }\n\n setSchema(newSchema);\n\n if (isUpdated) {\n return { status: \"success\", property: current.properties![key]! };\n }\n };\n\n /**\n * Adds a sibling property to the current schema.\n */\n const handleAddProperty = (\n key: string,\n propertyToAdd: JSONSchema7,\n isRequired: boolean,\n ) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to add\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Ensure the current schema has a properties object\n if (current.type !== \"object\") {\n current.type = \"object\";\n }\n if (!current.properties) {\n current.properties = {};\n }\n\n //Ensure there's no existing property with the same key\n if (current.properties[key]) {\n return {\n status: \"error\",\n code: \"key-exists\" as const,\n message: `Property with key ${key} already exists`,\n } satisfies PropertyAddError;\n }\n\n if (propertyToAdd.enum) {\n //ensure that only the enum property is present\n delete propertyToAdd.type;\n delete propertyToAdd.items;\n delete propertyToAdd.properties;\n }\n\n // Add the new property\n current.properties[key] = propertyToAdd;\n\n // Handle required field\n if (isRequired) {\n if (!current.required) {\n current.required = [];\n }\n if (!current.required.includes(key)) {\n current.required.push(key);\n }\n }\n\n setSchema(newSchema);\n\n return {\n status: \"success\" as const,\n property: current.properties[key],\n } satisfies PropertyAddSuccess;\n };\n\n const handleDeleteProperty = (key: string) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to delete\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Handle required field updates\n if (current.type === \"object\") {\n if (current.required) {\n current.required = current.required.filter((item) => item !== key);\n }\n }\n\n // Delete the property\n if (current.type === \"object\" && current.properties) {\n delete current.properties[key];\n }\n\n setSchema(newSchema);\n };\n\n const handleDuplicateProperty = (key: string) => {\n const currentProperties = getCurrentSchema().properties;\n if (\n !currentProperties ||\n isEmpty(currentProperties) ||\n typeof currentProperties[key] === \"boolean\"\n ) {\n return;\n }\n\n const propertyToDuplicate = currentProperties[key]!;\n const newKey = `${key}_copy`;\n const newProperty = clone(propertyToDuplicate);\n\n // Add the duplicated property\n return handleAddProperty(newKey, newProperty, isPropertyRequired(key));\n };\n\n const isPropertyRequired = (key: string) => {\n if (path.length) {\n const { propertySchema } = navigateToCorrectNesting(schema, path);\n\n if (\n propertySchema?.type === \"array\" &&\n propertySchema.items &&\n typeof propertySchema.items !== \"boolean\" &&\n !Array.isArray(propertySchema.items) &&\n propertySchema.items?.type === \"object\"\n ) {\n return Boolean(propertySchema.items?.required?.includes(key));\n } else {\n return Boolean(propertySchema?.required?.includes(key));\n }\n }\n\n return Boolean(schema?.required?.includes(key));\n };\n\n /**\n * Programatically get the current schema value\n */\n const getValue = () => {\n return schema;\n };\n\n return {\n ...context,\n getCurrentSchema,\n getCurrentProperty,\n handlePropertyChange,\n handleAddProperty,\n handleKeyChange,\n navigateToCorrectNesting,\n handleDeleteProperty,\n isPropertyRequired,\n getValue,\n handleDuplicateProperty,\n };\n}\n\nexport { SchemaProvider, useSchema };\n"],"names":["SchemaContext","createContext","defaultSchema","SchemaProvider","children","initialSchema","schema","setSchema","useState","path","setPath","jsx","useSchema","context","useContext","navigateToCorrectNesting","providedSchema","providedPath","current","propertySchema","parentSchema","p","getCurrentSchema","getCurrentProperty","handleKeyChange","key","newKey","newSchema","clone","newProperties","k","val","item","handlePropertyChange","updates","isUpdated","originalProperty","handleAddProperty","propertyToAdd","isRequired","handleDeleteProperty","handleDuplicateProperty","currentProperties","isEmpty","propertyToDuplicate","newProperty","isPropertyRequired"],"mappings":";;;;AAca,MAAAA,IAAgBC,EAE3B,MAAS,GAELC,IAA6B;AAAA,EACjC,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,YAAY,CAAC;AAAA,EACb,UAAU,CAAA;AACZ;AAE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ACRxC;AAAA,IAcP,yBAAAmC;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"index.es2.js","sources":["../src/packages/builder/context.tsx"],"sourcesContent":["import { createContext, useContext, useState } from \"react\";\n\nimport type { PropsWithChildren, SetStateAction } from \"react\";\nimport type { JSONSchema7, JSONSchema7Definition } from \"json-schema\";\nimport { clone, isEmpty } from \"remeda\";\nimport type { OperationError } from \"./shared-types\";\n\ninterface ContextState<T extends JSONSchema7> {\n schema: T;\n setSchema: React.Dispatch<T>;\n path: string[];\n setPath: React.Dispatch<SetStateAction<string[]>>;\n}\n\nexport const SchemaContext = createContext<\n ContextState<JSONSchema7> | undefined\n>(undefined);\n\nconst defaultSchema: JSONSchema7 = {\n $schema: \"http://json-schema.org/draft-07/schema#\",\n type: \"object\",\n title: \"title\",\n description: \"\",\n properties: {},\n required: [],\n};\n\nfunction SchemaProvider({\n children,\n initialSchema,\n}: PropsWithChildren<{ initialSchema?: JSONSchema7 }>) {\n const [schema, setSchema] = useState<JSONSchema7>(\n initialSchema ?? defaultSchema,\n );\n\n /**\n * Path represents the path to a nested property in the schema.\n * It should only contain property keys.\n * An empty path means the current schema is the root schema since\n * the path only represents nested properties.\n */\n const [path, setPath] = useState<string[]>([]);\n\n // NOTE: you *might* need to memoize your values\n // Learn more in http://kcd.im/optimize-context\n\n return (\n <SchemaContext.Provider value={{ schema, setSchema, path, setPath }}>\n {children}\n </SchemaContext.Provider>\n );\n}\n\nexport type PropertyAddError = OperationError & {\n status: \"error\";\n};\n\nexport interface PropertyAddSuccess {\n status: \"success\";\n property: JSONSchema7;\n}\n\nexport interface PropertyChangeSuccess {\n status: \"success\";\n property: JSONSchema7Definition;\n}\n\nfunction useSchema({\n onSchemaChange,\n}: {\n onSchemaChange?: (schema: JSONSchema7) => void;\n} = {}) {\n const context = useContext(SchemaContext);\n\n if (context === undefined) {\n throw new Error(\"useSchema must be used within a SchemaProvider\");\n }\n\n const { path, schema, setSchema } = context;\n\n /**\n * Navigates to the correct property schema of the latest key in the provided path.\n *\n * It will traverse both \"properties\" and \"items\" to find the correct property schema.\n *\n * It will only return a property schema if the provided path is valid i.e. it\n * correctly follows the schema's nesting structure.\n *\n * It will only return a parent schema if the provided path is valid i.e. it\n * correctly follows the schema's nesting structure.\n */\n const navigateToCorrectNesting = (\n providedSchema: JSONSchema7,\n providedPath: string[],\n ) => {\n let current = providedSchema;\n let propertySchema: JSONSchema7 | null = null;\n // Should be the schema of type \"object\" containing the property in its properties key\n let parentSchema: JSONSchema7 | null = null;\n\n for (const p of providedPath) {\n if (\n current.type === \"array\" &&\n current.items &&\n !Array.isArray(current.items) &&\n typeof current.items === \"object\" &&\n current.items.type === \"object\" &&\n typeof current.items.properties?.[p] === \"object\"\n ) {\n parentSchema = current.items;\n propertySchema = current.items.properties[p];\n current = current.items;\n } else if (\n current.type === \"object\" &&\n current.properties &&\n !Array.isArray(current.properties) &&\n typeof current.properties[p] === \"object\"\n ) {\n parentSchema = current;\n propertySchema = current.properties[p];\n current = current.properties[p];\n }\n }\n\n return { propertySchema, parentSchema };\n };\n\n /**\n * Gets the current schema of the latest key in the path.\n * If path is empty, it will return the root schema.\n *\n * It should always return the \"object\" schema of the current path.\n */\n const getCurrentSchema = (initialSchema?: JSONSchema7) => {\n // Gets the correct object schema if under nesting\n // Otherwise, return the root schema\n const { propertySchema } = navigateToCorrectNesting(\n initialSchema ?? schema,\n path,\n );\n\n if (propertySchema) {\n if (propertySchema.type === \"array\") {\n return propertySchema.items as JSONSchema7;\n }\n\n return propertySchema;\n }\n\n return initialSchema ?? schema;\n };\n\n /**\n * Gets the correct property schema of the latest key in the path.\n * If no path is provided, it will return null.\n */\n const getCurrentProperty = () => {\n const { propertySchema } = navigateToCorrectNesting(schema, path);\n\n return propertySchema;\n };\n\n /**\n * Change the key of a property in the schema. It expects\n * the find the key at the current path.\n */\n const handleKeyChange = (key: string, newKey: string) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to change\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n if (current.properties?.[key]) {\n //Important: maintain order as to not confuse users\n const newProperties = Object.entries(current.properties).map(\n ([k, val]) => {\n return [k === key ? newKey : k, val];\n },\n );\n\n current.properties = Object.fromEntries(\n newProperties,\n ) as JSONSchema7[\"properties\"];\n }\n\n if (current.required?.includes(key)) {\n current.required = current.required.map((item) =>\n item === key ? newKey : item,\n );\n }\n\n setSchema(newSchema);\n onSchemaChange?.(newSchema);\n };\n\n const handlePropertyChange = (\n key: string,\n updates: Partial<JSONSchema7Definition> & { isRequired?: boolean },\n ): PropertyChangeSuccess | undefined => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to change\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Handle required field updates\n if (typeof updates === \"object\" && \"isRequired\" in updates) {\n if (current.type === \"object\") {\n if (!current.required) {\n current.required = [];\n }\n if (updates.isRequired) {\n if (!current.required.includes(key)) {\n current.required.push(key);\n }\n } else {\n current.required = current.required.filter((item) => item !== key);\n }\n }\n delete updates.isRequired;\n }\n\n let isUpdated = false;\n\n // Update the property\n if (current.type === \"object\" && current.properties) {\n const originalProperty = current.properties[key];\n // Ensure the property exists and is not a boolean\n if (typeof originalProperty !== \"boolean\" && originalProperty) {\n if (typeof updates !== \"boolean\") {\n //if updates changes the type of the property,\n //only the title, description, and default properties should remain\n //from the original property\n if (updates.type && updates.type !== originalProperty.type) {\n updates = {\n title: originalProperty.title,\n description: originalProperty.description,\n default: originalProperty.default,\n ...updates,\n };\n } else if (updates.enum) {\n //if the property is an enum, only the title and description should remain\n //from the original property\n delete updates.type;\n delete updates.items;\n delete updates.properties;\n updates = {\n title: originalProperty.title,\n description: originalProperty.description,\n ...updates,\n };\n } else {\n updates = { ...originalProperty, ...updates };\n }\n\n current.properties[key] = updates;\n }\n }\n isUpdated = true;\n }\n\n setSchema(newSchema);\n onSchemaChange?.(newSchema);\n\n if (isUpdated) {\n return { status: \"success\", property: current.properties![key]! };\n }\n };\n\n /**\n * Adds a sibling property to the current schema.\n */\n const handleAddProperty = (\n key: string,\n propertyToAdd: JSONSchema7,\n isRequired: boolean,\n ) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to add\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Ensure the current schema has a properties object\n if (current.type !== \"object\") {\n current.type = \"object\";\n }\n if (!current.properties) {\n current.properties = {};\n }\n\n //Ensure there's no existing property with the same key\n if (current.properties[key]) {\n return {\n status: \"error\",\n code: \"key-exists\" as const,\n message: `Property with key ${key} already exists`,\n } satisfies PropertyAddError;\n }\n\n if (propertyToAdd.enum) {\n //ensure that only the enum property is present\n delete propertyToAdd.type;\n delete propertyToAdd.items;\n delete propertyToAdd.properties;\n }\n\n // Add the new property\n current.properties[key] = propertyToAdd;\n\n // Handle required field\n if (isRequired) {\n if (!current.required) {\n current.required = [];\n }\n if (!current.required.includes(key)) {\n current.required.push(key);\n }\n }\n\n setSchema(newSchema);\n onSchemaChange?.(newSchema);\n\n return {\n status: \"success\" as const,\n property: current.properties[key],\n } satisfies PropertyAddSuccess;\n };\n\n const handleDeleteProperty = (key: string) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to delete\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Handle required field updates\n if (current.type === \"object\") {\n if (current.required) {\n current.required = current.required.filter((item) => item !== key);\n }\n }\n\n // Delete the property\n if (current.type === \"object\" && current.properties) {\n delete current.properties[key];\n }\n\n setSchema(newSchema);\n onSchemaChange?.(newSchema);\n };\n\n const handleDuplicateProperty = (key: string) => {\n const currentProperties = getCurrentSchema().properties;\n if (\n !currentProperties ||\n isEmpty(currentProperties) ||\n typeof currentProperties[key] === \"boolean\"\n ) {\n return;\n }\n\n const propertyToDuplicate = currentProperties[key]!;\n const newKey = `${key}_copy`;\n const newProperty = clone(propertyToDuplicate);\n\n // Add the duplicated property\n return handleAddProperty(newKey, newProperty, isPropertyRequired(key));\n };\n\n const isPropertyRequired = (key: string) => {\n if (path.length) {\n const { propertySchema } = navigateToCorrectNesting(schema, path);\n\n if (\n propertySchema?.type === \"array\" &&\n propertySchema.items &&\n typeof propertySchema.items !== \"boolean\" &&\n !Array.isArray(propertySchema.items) &&\n propertySchema.items?.type === \"object\"\n ) {\n return Boolean(propertySchema.items?.required?.includes(key));\n } else {\n return Boolean(propertySchema?.required?.includes(key));\n }\n }\n\n return Boolean(schema?.required?.includes(key));\n };\n\n /**\n * Programatically get the current schema value\n */\n const getValue = () => {\n return schema;\n };\n\n return {\n ...context,\n getCurrentSchema,\n getCurrentProperty,\n handlePropertyChange,\n handleAddProperty,\n handleKeyChange,\n navigateToCorrectNesting,\n handleDeleteProperty,\n isPropertyRequired,\n getValue,\n handleDuplicateProperty,\n };\n}\n\nexport { SchemaProvider, useSchema };\n"],"names":["SchemaContext","createContext","defaultSchema","SchemaProvider","children","initialSchema","schema","setSchema","useState","path","setPath","jsx","useSchema","onSchemaChange","context","useContext","navigateToCorrectNesting","providedSchema","providedPath","current","propertySchema","parentSchema","p","getCurrentSchema","getCurrentProperty","handleKeyChange","key","newKey","newSchema","clone","newProperties","k","val","item","handlePropertyChange","updates","isUpdated","originalProperty","handleAddProperty","propertyToAdd","isRequired","handleDeleteProperty","handleDuplicateProperty","currentProperties","isEmpty","propertyToDuplicate","newProperty","isPropertyRequired"],"mappings":";;;;AAca,MAAAA,IAAgBC,EAE3B,MAAS,GAELC,IAA6B;AAAA,EACjC,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,YAAY,CAAC;AAAA,EACb,UAAU,CAAA;AACZ;AAEA,SAASC,EAAe;AAAA,EACtB,UAAAC;AAAA,EACA,eAAAC;AACF,GAAuD;AAC/C,QAAA,CAACC,GAAQC,CAAS,IAAIC;AAAA,IAC1BH,KAAiBH;AAAA,EACnB,GAQM,CAACO,GAAMC,CAAO,IAAIF,EAAmB,CAAA,CAAE;AAM3C,SAAA,gBAAAG,EAACX,EAAc,UAAd,EAAuB,OAAO,EAAE,QAAAM,GAAQ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
- import { zodResolver as K } from "./index.es44.js";
4
- import { Dialog as M, DialogContent as _, DialogHeader as B, DialogTitle as H, DialogDescription as J, DialogFooter as G } from "./index.es41.js";
3
+ import { zodResolver as K } from "./index.es40.js";
4
+ import { Dialog as M, DialogContent as _, DialogHeader as B, DialogTitle as H, DialogDescription as J, DialogFooter as G } from "./index.es37.js";
5
5
  import { Input as O } from "./index.es28.js";
6
6
  import { Label as Q } from "./index.es15.js";
7
7
  import { Select as A, SelectTrigger as j, SelectValue as F, SelectContent as N, SelectItem as s } from "./index.es14.js";
8
8
  import { Switch as U } from "./index.es13.js";
9
9
  import { DebouncedInput as V } from "./index.es20.js";
10
10
  import { a as f } from "./index.es10.js";
11
- import W from "./index.es46.js";
11
+ import W from "./index.es42.js";
12
12
  import { useConstraints as X } from "./index.es4.js";
13
- import Y from "./index.es42.js";
14
- import { Separator as Z } from "./index.es43.js";
13
+ import Y from "./index.es38.js";
14
+ import { Separator as Z } from "./index.es39.js";
15
15
  import { z as t } from "zod";
16
16
  import { useForm as ee } from "react-hook-form";
17
- import { Form as re, FormField as u, FormItem as d, FormLabel as p, FormControl as h, FormMessage as y } from "./index.es45.js";
17
+ import { Form as re, FormField as u, FormItem as d, FormLabel as p, FormControl as h, FormMessage as y } from "./index.es41.js";
18
18
  const g = t.enum([
19
19
  "string",
20
20
  "number",
package/dist/index.es3.js CHANGED
@@ -1,83 +1,80 @@
1
1
  import { jsxs as i, jsx as e } from "react/jsx-runtime";
2
- import { useState as s, useEffect as V, Fragment as de } from "react";
3
- import { useSchema as me } from "./index.es2.js";
2
+ import { useState as s, useEffect as ce, Fragment as se } from "react";
3
+ import { useSchema as de } from "./index.es2.js";
4
4
  import { Button as d } from "./index.es11.js";
5
- import { Breadcrumb as he, BreadcrumbList as ue, BreadcrumbItem as $, BreadcrumbLink as F, BreadcrumbSeparator as fe } from "./index.es12.js";
6
- import { Switch as ge } from "./index.es13.js";
7
- import { Select as L, SelectTrigger as O, SelectValue as U, SelectContent as k, SelectItem as l } from "./index.es14.js";
8
- import { Label as H } from "./index.es15.js";
9
- import { a as pe } from "./index.es10.js";
10
- import { usePluginSystem as ve, useConstraints as ye } from "./index.es4.js";
11
- import { EditPropertyDialog as be } from "./index.es16.js";
12
- import { AlertDialog as Ce, AlertDialogContent as De, AlertDialogHeader as Se, AlertDialogTitle as Ae, AlertDialogDescription as Pe, AlertDialogFooter as Ne, AlertDialogCancel as je, AlertDialogAction as Ee } from "./index.es17.js";
13
- import { Alert as Be, AlertTitle as we, AlertDescription as xe } from "./index.es18.js";
14
- import { validateSchema as Te } from "./index.es19.js";
15
- import ze from "ajv";
16
- import { DebouncedInput as D } from "./index.es20.js";
17
- import { AddPropertyDialog as Ke } from "./index.es21.js";
18
- import { cn as S } from "./index.es22.js";
19
- import Re from "./index.es23.js";
20
- import Ie from "./index.es24.js";
21
- import qe from "./index.es25.js";
22
- import Ve from "./index.es26.js";
23
- import $e from "./index.es27.js";
24
- const ct = (a) => {
25
- const [G, h] = s(!1), [J, v] = s(!1), [M, u] = s(!1), [f, y] = s(), [A, P] = s(), [N, j] = s(), [g, p] = s(null);
26
- ve(a.plugins ?? []);
5
+ import { Breadcrumb as me, BreadcrumbList as he, BreadcrumbItem as q, BreadcrumbLink as V, BreadcrumbSeparator as ue } from "./index.es12.js";
6
+ import { Switch as fe } from "./index.es13.js";
7
+ import { Select as $, SelectTrigger as F, SelectValue as L, SelectContent as O, SelectItem as l } from "./index.es14.js";
8
+ import { Label as U } from "./index.es15.js";
9
+ import { a as ge } from "./index.es10.js";
10
+ import { usePluginSystem as pe, useConstraints as ve } from "./index.es4.js";
11
+ import { EditPropertyDialog as ye } from "./index.es16.js";
12
+ import { AlertDialog as be, AlertDialogContent as Ce, AlertDialogHeader as De, AlertDialogTitle as Ae, AlertDialogDescription as Pe, AlertDialogFooter as Se, AlertDialogCancel as Ne, AlertDialogAction as je } from "./index.es17.js";
13
+ import { Alert as Ee, AlertTitle as Be, AlertDescription as we } from "./index.es18.js";
14
+ import { validateSchema as xe } from "./index.es19.js";
15
+ import Te from "ajv";
16
+ import { DebouncedInput as C } from "./index.es20.js";
17
+ import { AddPropertyDialog as ze } from "./index.es21.js";
18
+ import { cn as D } from "./index.es22.js";
19
+ import Ke from "./index.es23.js";
20
+ import Re from "./index.es24.js";
21
+ import Ie from "./index.es25.js";
22
+ import qe from "./index.es26.js";
23
+ import Ve from "./index.es27.js";
24
+ const ot = (a) => {
25
+ const [k, h] = s(!1), [H, p] = s(!1), [G, u] = s(!1), [f, v] = s(), [A, P] = s(), [S, N] = s(), [j, g] = s(null);
26
+ pe(a.plugins ?? []);
27
27
  const {
28
- getCurrentSchema: Q,
28
+ getCurrentSchema: J,
29
29
  setPath: m,
30
30
  path: o,
31
- schema: E,
32
- handleAddProperty: W,
31
+ handleAddProperty: M,
33
32
  handlePropertyChange: c,
34
- handleKeyChange: B,
35
- handleDeleteProperty: X,
36
- setSchema: Y,
37
- isPropertyRequired: w,
38
- handleDuplicateProperty: Z
39
- } = me(), { getConstraintDefinitionsForType: _ } = ye();
40
- V(() => {
33
+ handleKeyChange: E,
34
+ handleDeleteProperty: Q,
35
+ setSchema: W,
36
+ isPropertyRequired: B,
37
+ handleDuplicateProperty: X
38
+ } = de({ onSchemaChange: a.onSchemaChange }), { getConstraintDefinitionsForType: Y } = ve();
39
+ ce(() => {
41
40
  if (a.initialSchema)
42
41
  try {
43
- Te(a.initialSchema), Y(pe(a.initialSchema)), p(null);
42
+ xe(a.initialSchema), W(ge(a.initialSchema)), g(null);
44
43
  } catch (t) {
45
- t instanceof Error ? p(t.message) : t instanceof ze.ValidationError ? p(`Schema validation error: ${t.message}`) : p("Unknown schema validation error");
44
+ t instanceof Error ? g(t.message) : t instanceof Te.ValidationError ? g(`Schema validation error: ${t.message}`) : g("Unknown schema validation error");
46
45
  }
47
- }, [a.initialSchema]), V(() => {
48
- !g && a.onSchemaChange && a.onSchemaChange(E);
49
- }, [E, g, a.onSchemaChange]);
50
- const ee = Q(), x = (t) => {
46
+ }, [a.initialSchema]);
47
+ const Z = J(), w = (t) => {
51
48
  m([...o, t]);
52
- }, T = () => {
49
+ }, x = () => {
53
50
  m(o.slice(0, -1));
54
- }, te = (t, r) => {
55
- P(t), j(r), v(!0);
51
+ }, _ = (t, r) => {
52
+ P(t), N(r), p(!0);
53
+ }, T = (t) => {
54
+ v(t), u(!0);
55
+ }, ee = () => {
56
+ f && (Q(f), v(void 0)), u(!1);
57
+ }, te = () => {
58
+ v(void 0), u(!1);
56
59
  }, z = (t) => {
57
- y(t), u(!0);
58
- }, re = () => {
59
- f && (X(f), y(void 0)), u(!1);
60
- }, ne = () => {
61
- y(void 0), u(!1);
62
- }, K = (t) => {
63
- const r = Z(t);
60
+ const r = X(t);
64
61
  r?.status === "error" ? a.onPropertyAddError?.(r) : r?.status === "success" && a.onPropertyAddSuccess?.(r);
65
- }, ie = (...t) => {
66
- const r = W(...t);
62
+ }, re = (...t) => {
63
+ const r = M(...t);
67
64
  r.status === "error" ? a.onPropertyAddError?.(r) : r.status === "success" && a.onPropertyAddSuccess?.(r), h(!1);
68
- }, R = a.propertyComponent, ae = (t, r) => R ? /* @__PURE__ */ e(
69
- R,
65
+ }, K = a.propertyComponent, ne = (t, r) => K ? /* @__PURE__ */ e(
66
+ K,
70
67
  {
71
68
  property: {
72
69
  key: t,
73
70
  schema: r,
74
- isRequired: w(t)
71
+ isRequired: B(t)
75
72
  },
76
73
  onPropertyChange: c,
77
- onKeyChange: B,
78
- onDelete: z,
79
- onDuplicate: K,
80
- onNavigate: r.type === "object" || r.type === "array" && typeof r.items == "object" && r.items.type === "object" ? x : void 0
74
+ onKeyChange: E,
75
+ onDelete: T,
76
+ onDuplicate: z,
77
+ onNavigate: r.type === "object" || r.type === "array" && typeof r.items == "object" && r.items.type === "object" ? w : void 0
81
78
  },
82
79
  t
83
80
  ) : /* @__PURE__ */ i(
@@ -86,10 +83,10 @@ const ct = (a) => {
86
83
  className: "flex flex-col md:grid grid-cols-(--my-autofit-grid) gap-4 md:items-center border p-2 rounded-md mb-2",
87
84
  children: [
88
85
  /* @__PURE__ */ e("div", { className: "", children: /* @__PURE__ */ e(
89
- D,
86
+ C,
90
87
  {
91
88
  value: t,
92
- onDebounce: (n) => B(t, n),
89
+ onDebounce: (n) => E(t, n),
93
90
  placeholder: "Property Key",
94
91
  "aria-label": `Property key for ${t}`,
95
92
  delay: 500
@@ -97,17 +94,17 @@ const ct = (a) => {
97
94
  ) }),
98
95
  /* @__PURE__ */ i("div", { className: "flex items-center gap-2", children: [
99
96
  /* @__PURE__ */ e(
100
- ge,
97
+ fe,
101
98
  {
102
- checked: w(t),
99
+ checked: B(t),
103
100
  onCheckedChange: (n) => c(t, { isRequired: n }),
104
101
  "aria-label": "Required"
105
102
  }
106
103
  ),
107
- /* @__PURE__ */ e(H, { htmlFor: `required-${t}`, children: "Required" })
104
+ /* @__PURE__ */ e(U, { htmlFor: `required-${t}`, children: "Required" })
108
105
  ] }),
109
106
  /* @__PURE__ */ e("div", { className: "", children: /* @__PURE__ */ i(
110
- L,
107
+ $,
111
108
  {
112
109
  value: typeof r == "object" && !Array.isArray(r.type) ? r.type : void 0,
113
110
  onValueChange: (n) => c(t, {
@@ -115,8 +112,8 @@ const ct = (a) => {
115
112
  }),
116
113
  "aria-label": "Type",
117
114
  children: [
118
- /* @__PURE__ */ e(O, { className: "w-full", "aria-label": "Select type", children: /* @__PURE__ */ e(U, {}) }),
119
- /* @__PURE__ */ i(k, { children: [
115
+ /* @__PURE__ */ e(F, { className: "w-full", "aria-label": "Select type", children: /* @__PURE__ */ e(L, {}) }),
116
+ /* @__PURE__ */ i(O, { children: [
120
117
  /* @__PURE__ */ e(l, { value: "string", children: "string" }),
121
118
  /* @__PURE__ */ e(l, { value: "number", children: "number" }),
122
119
  /* @__PURE__ */ e(l, { value: "integer", children: "integer" }),
@@ -130,7 +127,7 @@ const ct = (a) => {
130
127
  }
131
128
  ) }),
132
129
  /* @__PURE__ */ e("div", { className: "", children: /* @__PURE__ */ e(
133
- D,
130
+ C,
134
131
  {
135
132
  value: typeof r == "object" ? r.title : void 0,
136
133
  onDebounce: (n) => c(t, { title: n }),
@@ -138,7 +135,7 @@ const ct = (a) => {
138
135
  }
139
136
  ) }),
140
137
  /* @__PURE__ */ e("div", { className: "", children: /* @__PURE__ */ e(
141
- D,
138
+ C,
142
139
  {
143
140
  value: typeof r == "object" ? r.description : void 0,
144
141
  onDebounce: (n) => c(t, { description: n }),
@@ -151,10 +148,10 @@ const ct = (a) => {
151
148
  {
152
149
  variant: "outline",
153
150
  size: "sm",
154
- onClick: () => z(t),
151
+ onClick: () => T(t),
155
152
  "aria-label": "Delete",
156
153
  className: "block!",
157
- children: /* @__PURE__ */ e(Ie, { size: 16, className: "text-destructive" })
154
+ children: /* @__PURE__ */ e(Re, { size: 16, className: "text-destructive" })
158
155
  }
159
156
  ),
160
157
  /* @__PURE__ */ e(
@@ -162,46 +159,46 @@ const ct = (a) => {
162
159
  {
163
160
  variant: "outline",
164
161
  size: "sm",
165
- onClick: () => K(t),
162
+ onClick: () => z(t),
166
163
  "aria-label": "Duplicate",
167
164
  className: "block!",
168
- children: /* @__PURE__ */ e(qe, { size: 16 })
165
+ children: /* @__PURE__ */ e(Ie, { size: 16 })
169
166
  }
170
167
  ),
171
- oe(t, r),
172
- I(t, r)
168
+ ae(t, r),
169
+ R(t, r)
173
170
  ] }),
174
- le(t, r)
171
+ ie(t, r)
175
172
  ]
176
173
  },
177
174
  t
178
- ), le = (t, r) => {
175
+ ), ie = (t, r) => {
179
176
  if (typeof r != "object" || r.type !== "array")
180
177
  return null;
181
- const n = r.items, b = !Array.isArray(n) && typeof n == "object" && typeof n.type == "string" ? n?.type : "string";
178
+ const n = r.items, y = !Array.isArray(n) && typeof n == "object" && typeof n.type == "string" ? n?.type : "string";
182
179
  return /* @__PURE__ */ i("div", { className: "col-span-full flex items-center gap-4 pl-8 mt-2 bg-gray-50 p-2 rounded-md", children: [
183
- /* @__PURE__ */ e(H, { children: "Items of type:" }),
180
+ /* @__PURE__ */ e(U, { children: "Items of type:" }),
184
181
  /* @__PURE__ */ i(
185
- L,
182
+ $,
186
183
  {
187
- value: b,
188
- onValueChange: (q) => {
189
- const C = {
184
+ value: y,
185
+ onValueChange: (I) => {
186
+ const b = {
190
187
  ...typeof n == "object" ? n : {},
191
- type: q
188
+ type: I
192
189
  };
193
- q === "object" && (C.properties = C.properties ?? {}), c(t, { items: C });
190
+ I === "object" && (b.properties = b.properties ?? {}), c(t, { items: b });
194
191
  },
195
192
  children: [
196
193
  /* @__PURE__ */ e(
197
- O,
194
+ F,
198
195
  {
199
196
  className: "w-[200px]",
200
197
  "aria-label": "Select items of type",
201
- children: /* @__PURE__ */ e(U, {})
198
+ children: /* @__PURE__ */ e(L, {})
202
199
  }
203
200
  ),
204
- /* @__PURE__ */ i(k, { children: [
201
+ /* @__PURE__ */ i(O, { children: [
205
202
  /* @__PURE__ */ e(l, { value: "string", children: "string" }),
206
203
  /* @__PURE__ */ e(l, { value: "number", children: "number" }),
207
204
  /* @__PURE__ */ e(l, { value: "integer", children: "integer" }),
@@ -213,42 +210,42 @@ const ct = (a) => {
213
210
  ]
214
211
  }
215
212
  ),
216
- I(t, n)
213
+ R(t, n)
217
214
  ] });
218
- }, oe = (t, r) => {
215
+ }, ae = (t, r) => {
219
216
  if (typeof r != "object") return null;
220
- const n = _(
217
+ const n = Y(
221
218
  typeof r.type == "string" ? r.type : ""
222
- ), b = Array.isArray(r?.enum);
223
- return n.length || b ? /* @__PURE__ */ e(
219
+ ), y = Array.isArray(r?.enum);
220
+ return n.length || y ? /* @__PURE__ */ e(
224
221
  d,
225
222
  {
226
223
  variant: "outline",
227
224
  size: "sm",
228
- onClick: () => te(t, r),
225
+ onClick: () => _(t, r),
229
226
  "aria-label": "Edit constraints",
230
- children: /* @__PURE__ */ e(Ve, { size: 16 })
227
+ children: /* @__PURE__ */ e(qe, { size: 16 })
231
228
  }
232
229
  ) : null;
233
- }, I = (t, r) => !Array.isArray(r) && typeof r == "object" && r?.type === "object" ? /* @__PURE__ */ i(
230
+ }, R = (t, r) => !Array.isArray(r) && typeof r == "object" && r?.type === "object" ? /* @__PURE__ */ i(
234
231
  d,
235
232
  {
236
233
  variant: "outline",
237
234
  size: "sm",
238
- onClick: () => x(t),
235
+ onClick: () => w(t),
239
236
  "aria-label": "Navigate",
240
237
  children: [
241
238
  /* @__PURE__ */ e("span", { className: "sr-only", children: "Navigate" }),
242
- /* @__PURE__ */ e($e, { size: 16 })
239
+ /* @__PURE__ */ e(Ve, { size: 16 })
243
240
  ]
244
241
  }
245
- ) : null, ce = () => {
242
+ ) : null, le = () => {
246
243
  const t = a.navigationComponent;
247
244
  return t ? /* @__PURE__ */ e(
248
245
  t,
249
246
  {
250
247
  currentPath: o,
251
- onNavigateUp: T,
248
+ onNavigateUp: x,
252
249
  onNavigateTo: m,
253
250
  isRootPath: o.length === 0
254
251
  }
@@ -258,18 +255,18 @@ const ct = (a) => {
258
255
  {
259
256
  variant: "outline",
260
257
  size: "sm",
261
- onClick: T,
258
+ onClick: x,
262
259
  disabled: o.length === 0,
263
- className: S(a.backButtonClassName),
260
+ className: D(a.backButtonClassName),
264
261
  children: "Back"
265
262
  }
266
263
  ),
267
- /* @__PURE__ */ e(he, { children: /* @__PURE__ */ i(ue, { children: [
268
- /* @__PURE__ */ e($, { children: /* @__PURE__ */ e(F, { href: "#", onClick: () => m([]), children: "Root" }) }),
269
- o.map((r, n) => /* @__PURE__ */ i(de, { children: [
270
- /* @__PURE__ */ e(fe, {}),
271
- /* @__PURE__ */ e($, { children: /* @__PURE__ */ e(
272
- F,
264
+ /* @__PURE__ */ e(me, { children: /* @__PURE__ */ i(he, { children: [
265
+ /* @__PURE__ */ e(q, { children: /* @__PURE__ */ e(V, { href: "#", onClick: () => m([]), children: "Root" }) }),
266
+ o.map((r, n) => /* @__PURE__ */ i(se, { children: [
267
+ /* @__PURE__ */ e(ue, {}),
268
+ /* @__PURE__ */ e(q, { children: /* @__PURE__ */ e(
269
+ V,
273
270
  {
274
271
  href: "#",
275
272
  onClick: () => m(o.slice(0, n + 1)),
@@ -279,7 +276,7 @@ const ct = (a) => {
279
276
  ] }, `path-${n}`))
280
277
  ] }) })
281
278
  ] });
282
- }, se = () => {
279
+ }, oe = () => {
283
280
  const t = a.addPropertyButtonComponent;
284
281
  return t ? /* @__PURE__ */ e(
285
282
  t,
@@ -290,55 +287,55 @@ const ct = (a) => {
290
287
  d,
291
288
  {
292
289
  type: "button",
293
- className: S("self-center", a.addPropertyButtonClassName),
290
+ className: D("self-center", a.addPropertyButtonClassName),
294
291
  onClick: () => {
295
292
  h(!0);
296
293
  },
297
294
  children: [
298
- /* @__PURE__ */ e(Re, { className: "h-4 w-4 mr-2" }),
295
+ /* @__PURE__ */ e(Ke, { className: "h-4 w-4 mr-2" }),
299
296
  "Add Property"
300
297
  ]
301
298
  }
302
299
  );
303
300
  };
304
301
  return /* @__PURE__ */ i("div", { children: [
305
- g && /* @__PURE__ */ i(Be, { variant: "destructive", children: [
306
- /* @__PURE__ */ e(we, { children: "Schema Error" }),
307
- /* @__PURE__ */ e(xe, { children: g })
302
+ j && /* @__PURE__ */ i(Ee, { variant: "destructive", children: [
303
+ /* @__PURE__ */ e(Be, { children: "Schema Error" }),
304
+ /* @__PURE__ */ e(we, { children: j })
308
305
  ] }),
309
- ce(),
306
+ le(),
310
307
  /* @__PURE__ */ e(
311
308
  "div",
312
309
  {
313
- className: S("mt-6 overflow-x-hidden", a.propertiesListClassName),
314
- children: Object.entries(ee.properties ?? {}).map(
315
- ([t, r]) => typeof r == "boolean" ? null : ae(t, r)
310
+ className: D("mt-6 overflow-x-hidden", a.propertiesListClassName),
311
+ children: Object.entries(Z.properties ?? {}).map(
312
+ ([t, r]) => typeof r == "boolean" ? null : ne(t, r)
316
313
  )
317
314
  }
318
315
  ),
319
- se(),
316
+ oe(),
320
317
  /* @__PURE__ */ e(
321
- Ke,
318
+ ze,
322
319
  {
323
- open: G,
320
+ open: k,
324
321
  onOpenChange: h,
325
- onSubmit: ie
322
+ onSubmit: re
326
323
  }
327
324
  ),
328
- A && N && /* @__PURE__ */ e(
329
- be,
325
+ A && S && /* @__PURE__ */ e(
326
+ ye,
330
327
  {
331
328
  propertyKey: A,
332
- property: N,
333
- open: J,
334
- onOpenChange: v,
329
+ property: S,
330
+ open: H,
331
+ onOpenChange: p,
335
332
  onSubmit: (t) => {
336
- c(...t), P(void 0), j(void 0), v(!1);
333
+ c(...t), P(void 0), N(void 0), p(!1);
337
334
  }
338
335
  }
339
336
  ),
340
- /* @__PURE__ */ e(Ce, { open: M, onOpenChange: u, children: /* @__PURE__ */ i(De, { children: [
341
- /* @__PURE__ */ i(Se, { children: [
337
+ /* @__PURE__ */ e(be, { open: G, onOpenChange: u, children: /* @__PURE__ */ i(Ce, { children: [
338
+ /* @__PURE__ */ i(De, { children: [
342
339
  /* @__PURE__ */ e(Ae, { children: "Are you sure?" }),
343
340
  /* @__PURE__ */ i(Pe, { children: [
344
341
  "This action cannot be undone. This will permanently delete the property",
@@ -346,14 +343,14 @@ const ct = (a) => {
346
343
  " from the schema."
347
344
  ] })
348
345
  ] }),
349
- /* @__PURE__ */ i(Ne, { children: [
350
- /* @__PURE__ */ e(je, { onClick: ne, children: "Cancel" }),
351
- /* @__PURE__ */ e(Ee, { onClick: re, children: "Delete" })
346
+ /* @__PURE__ */ i(Se, { children: [
347
+ /* @__PURE__ */ e(Ne, { onClick: te, children: "Cancel" }),
348
+ /* @__PURE__ */ e(je, { onClick: ee, children: "Delete" })
352
349
  ] })
353
350
  ] }) })
354
351
  ] });
355
352
  };
356
353
  export {
357
- ct as SchemaBuilder
354
+ ot as SchemaBuilder
358
355
  };
359
356
  //# sourceMappingURL=index.es3.js.map