json-schema-builder-react 0.0.1 → 0.0.2

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.
@@ -0,0 +1,5 @@
1
+ interface JsonOutputProps {
2
+ schema: any;
3
+ }
4
+ export default function JsonOutput({ schema }: JsonOutputProps): import("react/jsx-runtime").JSX.Element;
5
+ export {};
@@ -0,0 +1,64 @@
1
+ import { type TypeLabels } from "@/contexts/TypeLabelsContext";
2
+ export interface JsonSchemaBuilderProps {
3
+ /**
4
+ * Initial schema to load into the builder
5
+ */
6
+ initialSchema?: any;
7
+ /**
8
+ * Callback fired when the schema changes
9
+ */
10
+ onSchemaChange?: (schema: any) => void;
11
+ /**
12
+ * Whether to show metadata fields (title, description, version)
13
+ * @default false
14
+ */
15
+ showMetadata?: boolean;
16
+ /**
17
+ * Whether to show the import button
18
+ * @default true
19
+ */
20
+ showImport?: boolean;
21
+ /**
22
+ * Whether to show the clear all button
23
+ * @default true
24
+ */
25
+ showClear?: boolean;
26
+ /**
27
+ * Whether to show the JSON output panel
28
+ * @default true
29
+ */
30
+ showOutput?: boolean;
31
+ /**
32
+ * Custom class name for the container
33
+ */
34
+ className?: string;
35
+ showHeader?: boolean;
36
+ /**
37
+ * Custom labels for property types
38
+ * @example { string: 'Text', boolean: 'Yes/No', object: 'Form', array: 'List' }
39
+ */
40
+ typeLabels?: TypeLabels;
41
+ /**
42
+ * Whether to show summary in the bottom of the document area
43
+ * @default true
44
+ */
45
+ showSummary?: boolean;
46
+ /**
47
+ * Custom label for top-level properties
48
+ * @example { singular: 'input', plural: 'inputs' }
49
+ * @default { singular: 'property', plural: 'properties' }
50
+ */
51
+ propertyLabel?: {
52
+ singular: string;
53
+ plural: string;
54
+ };
55
+ /**
56
+ * Whether to show the regex pattern field in string constraints
57
+ * @default false
58
+ */
59
+ showRegex?: boolean;
60
+ }
61
+ /**
62
+ * A visual JSON Schema builder component that allows building JSON schemas interactively
63
+ */
64
+ export declare function JsonSchemaBuilder({ initialSchema, onSchemaChange, showMetadata, showImport, showClear, showOutput, showHeader, className, showSummary, typeLabels, propertyLabel, showRegex, }: JsonSchemaBuilderProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import type { PropertyData } from "@/types/schema";
2
+ interface PropertyDocumentProps {
3
+ property: PropertyData;
4
+ onUpdate: (property: PropertyData) => void;
5
+ onDelete: () => void;
6
+ level?: number;
7
+ isArrayItem?: boolean;
8
+ showRegex?: boolean;
9
+ }
10
+ export default function PropertyDocument({ property, onUpdate, onDelete, level, isArrayItem, showRegex, }: PropertyDocumentProps): import("react/jsx-runtime").JSX.Element;
11
+ export {};
@@ -0,0 +1,16 @@
1
+ import type { PropertyData } from "@/types/schema";
2
+ interface PropertyEditDialogProps {
3
+ property: PropertyData;
4
+ open: boolean;
5
+ onOpenChange: (open: boolean) => void;
6
+ onUpdate: (property: PropertyData) => void;
7
+ isArrayItem?: boolean;
8
+ isNewProperty?: boolean;
9
+ propertyLabel?: {
10
+ singular: string;
11
+ plural: string;
12
+ };
13
+ showRegex?: boolean;
14
+ }
15
+ export default function PropertyEditDialog({ property, open, onOpenChange, onUpdate, isArrayItem, isNewProperty, propertyLabel, showRegex, }: PropertyEditDialogProps): import("react/jsx-runtime").JSX.Element;
16
+ export {};
@@ -0,0 +1,8 @@
1
+ interface SchemaMetadataProps {
2
+ title: string;
3
+ description: string;
4
+ version: string;
5
+ onUpdate: (field: string, value: string) => void;
6
+ }
7
+ export default function SchemaMetadata({ title, description, version, onUpdate, }: SchemaMetadataProps): import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1 @@
1
+ export default function ThemeToggle(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import * as React from "react";
2
+ import { type VariantProps } from "class-variance-authority";
3
+ declare const buttonVariants: (props?: ({
4
+ variant?: "default" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined;
5
+ size?: "default" | "sm" | "lg" | "icon" | null | undefined;
6
+ } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
7
+ export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
8
+ asChild?: boolean;
9
+ }
10
+ declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
11
+ export { Button, buttonVariants };
@@ -0,0 +1,8 @@
1
+ import * as React from "react";
2
+ declare const Card: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
3
+ declare const CardHeader: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
4
+ declare const CardTitle: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
5
+ declare const CardDescription: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
6
+ declare const CardContent: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
7
+ declare const CardFooter: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
8
+ export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent, };
@@ -0,0 +1,4 @@
1
+ import * as React from "react";
2
+ import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
3
+ declare const Checkbox: React.ForwardRefExoticComponent<Omit<CheckboxPrimitive.CheckboxProps & React.RefAttributes<HTMLButtonElement>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
4
+ export { Checkbox };
@@ -0,0 +1,19 @@
1
+ import * as React from "react";
2
+ import * as DialogPrimitive from "@radix-ui/react-dialog";
3
+ declare const Dialog: React.FC<DialogPrimitive.DialogProps>;
4
+ declare const DialogTrigger: React.ForwardRefExoticComponent<DialogPrimitive.DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>;
5
+ declare const DialogPortal: React.FC<DialogPrimitive.DialogPortalProps>;
6
+ declare const DialogClose: React.ForwardRefExoticComponent<DialogPrimitive.DialogCloseProps & React.RefAttributes<HTMLButtonElement>>;
7
+ declare const DialogOverlay: React.ForwardRefExoticComponent<Omit<DialogPrimitive.DialogOverlayProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
8
+ declare const DialogContent: React.ForwardRefExoticComponent<Omit<DialogPrimitive.DialogContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
9
+ declare const DialogHeader: {
10
+ ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
11
+ displayName: string;
12
+ };
13
+ declare const DialogFooter: {
14
+ ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
15
+ displayName: string;
16
+ };
17
+ declare const DialogTitle: React.ForwardRefExoticComponent<Omit<DialogPrimitive.DialogTitleProps & React.RefAttributes<HTMLHeadingElement>, "ref"> & React.RefAttributes<HTMLHeadingElement>>;
18
+ declare const DialogDescription: React.ForwardRefExoticComponent<Omit<DialogPrimitive.DialogDescriptionProps & React.RefAttributes<HTMLParagraphElement>, "ref"> & React.RefAttributes<HTMLParagraphElement>>;
19
+ export { Dialog, DialogPortal, DialogOverlay, DialogClose, DialogTrigger, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription, };
@@ -0,0 +1,3 @@
1
+ import * as React from "react";
2
+ declare const Input: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref"> & React.RefAttributes<HTMLInputElement>>;
3
+ export { Input };
@@ -0,0 +1,5 @@
1
+ import * as React from "react";
2
+ import * as LabelPrimitive from "@radix-ui/react-label";
3
+ import { type VariantProps } from "class-variance-authority";
4
+ declare const Label: React.ForwardRefExoticComponent<Omit<LabelPrimitive.LabelProps & React.RefAttributes<HTMLLabelElement>, "ref"> & VariantProps<(props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string> & React.RefAttributes<HTMLLabelElement>>;
5
+ export { Label };
@@ -0,0 +1,13 @@
1
+ import * as React from "react";
2
+ import * as SelectPrimitive from "@radix-ui/react-select";
3
+ declare const Select: React.FC<SelectPrimitive.SelectProps>;
4
+ declare const SelectGroup: React.ForwardRefExoticComponent<SelectPrimitive.SelectGroupProps & React.RefAttributes<HTMLDivElement>>;
5
+ declare const SelectValue: React.ForwardRefExoticComponent<SelectPrimitive.SelectValueProps & React.RefAttributes<HTMLSpanElement>>;
6
+ declare const SelectTrigger: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectTriggerProps & React.RefAttributes<HTMLButtonElement>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
7
+ declare const SelectScrollUpButton: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectScrollUpButtonProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
8
+ declare const SelectScrollDownButton: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectScrollDownButtonProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
9
+ declare const SelectContent: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
10
+ declare const SelectLabel: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectLabelProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
11
+ declare const SelectItem: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectItemProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
12
+ declare const SelectSeparator: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectSeparatorProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
13
+ export { Select, SelectGroup, SelectValue, SelectTrigger, SelectContent, SelectLabel, SelectItem, SelectSeparator, SelectScrollUpButton, SelectScrollDownButton, };
@@ -0,0 +1,3 @@
1
+ import * as React from "react";
2
+ declare const Textarea: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, "ref"> & React.RefAttributes<HTMLTextAreaElement>>;
3
+ export { Textarea };
@@ -0,0 +1,7 @@
1
+ import * as React from "react";
2
+ import * as TooltipPrimitive from "@radix-ui/react-tooltip";
3
+ declare const TooltipProvider: React.FC<TooltipPrimitive.TooltipProviderProps>;
4
+ declare const Tooltip: React.FC<TooltipPrimitive.TooltipProps>;
5
+ declare const TooltipTrigger: React.ForwardRefExoticComponent<TooltipPrimitive.TooltipTriggerProps & React.RefAttributes<HTMLButtonElement>>;
6
+ declare const TooltipContent: React.ForwardRefExoticComponent<Omit<TooltipPrimitive.TooltipContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
7
+ export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
@@ -0,0 +1,12 @@
1
+ import type { PropertyType } from "@/types/schema";
2
+ export type TypeLabels = Partial<Record<PropertyType, string>>;
3
+ interface TypeLabelsContextValue {
4
+ getTypeLabel: (type: PropertyType) => string;
5
+ typeLabels: Record<PropertyType, string>;
6
+ }
7
+ export declare function TypeLabelsProvider({ children, customLabels, }: {
8
+ children: React.ReactNode;
9
+ customLabels?: TypeLabels;
10
+ }): import("react/jsx-runtime").JSX.Element;
11
+ export declare function useTypeLabels(): TypeLabelsContextValue;
12
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { PropertyData } from "@/types/schema";
2
+ export interface UsePropertyEditorReturn {
3
+ handleTitleChange: (title: string) => void;
4
+ handleTitleBlur: () => void;
5
+ handleKeyChange: (key: string) => void;
6
+ handleFieldChange: (field: keyof PropertyData, value: any) => void;
7
+ handleConstraintChange: (field: string, value: any) => void;
8
+ }
9
+ export declare const usePropertyEditor: (property: PropertyData, onUpdate: (property: PropertyData) => void, isNewProperty?: boolean) => UsePropertyEditorReturn;
@@ -0,0 +1,15 @@
1
+ import type { PropertyData, SchemaMetadata } from "@/types/schema";
2
+ export interface UseSchemaBuilderReturn {
3
+ properties: PropertyData[];
4
+ metadata: SchemaMetadata;
5
+ schema: any;
6
+ addProperty: () => PropertyData;
7
+ updateProperty: (id: string, updated: PropertyData) => void;
8
+ deleteProperty: (id: string) => void;
9
+ clearAll: () => void;
10
+ updateMetadata: (field: keyof SchemaMetadata, value: string) => void;
11
+ importSchema: () => Promise<void>;
12
+ downloadSchema: () => void;
13
+ loadSchema: (schema: any) => void;
14
+ }
15
+ export declare const useSchemaBuilder: (includeMetadata?: boolean) => UseSchemaBuilderReturn;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * JSON Schema Builder - A React component library for building JSON schemas visually
4
+ */
5
+ export { JsonSchemaBuilder } from "./components/JsonSchemaBuilder";
6
+ export type { JsonSchemaBuilderProps } from "./components/JsonSchemaBuilder";
7
+ export type { TypeLabels } from "./contexts/TypeLabelsContext";
8
+ export { useSchemaBuilder } from "./hooks/useSchemaBuilder";
9
+ export type { UseSchemaBuilderReturn } from "./hooks/useSchemaBuilder";
10
+ export { usePropertyEditor } from "./hooks/usePropertyEditor";
11
+ export { generateSchema } from "./lib/schema-generator";
12
+ export { parseSchema } from "./lib/schema-parser";
13
+ export { downloadJsonFile, importJsonFile } from "./lib/file-utils";
14
+ export type { PropertyData, PropertyType, SchemaMetadata, } from "./types/schema";
15
+ export { default as PropertyDocument } from "./components/PropertyDocument";
16
+ export { default as PropertyEditDialog } from "./components/PropertyEditDialog";
17
+ export { default as JsonOutput } from "./components/JsonOutput";
18
+ export { default as SchemaMetadataComponent } from "./components/SchemaMetadata";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Open a file picker and read a JSON file
3
+ */
4
+ export declare const importJsonFile: () => Promise<any>;
5
+ /**
6
+ * Download a JSON object as a file
7
+ */
8
+ export declare const downloadJsonFile: (data: any, filename?: string) => void;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generate a unique ID for properties
3
+ * Uses timestamp and random number for uniqueness
4
+ *
5
+ * @example
6
+ * generatePropertyId() // "1699632000000-0.123456789"
7
+ */
8
+ export declare const generatePropertyId: () => string;
@@ -0,0 +1,6 @@
1
+ import type { PropertyData, SchemaMetadata } from "@/types/schema";
2
+ import { JSONSchema7 } from "json-schema";
3
+ /**
4
+ * Generate a JSON Schema from property definitions
5
+ */
6
+ export declare const generateSchema: (properties: PropertyData[], metadata?: SchemaMetadata, includeMetadata?: boolean) => JSONSchema7;
@@ -0,0 +1,14 @@
1
+ import { JSONSchema7 } from "json-schema";
2
+ import type { PropertyData, SchemaMetadata } from "@/types/schema";
3
+ export interface ParsedSchema {
4
+ properties: PropertyData[];
5
+ metadata?: SchemaMetadata;
6
+ }
7
+ /**
8
+ * Parse a JSON Schema into PropertyData array
9
+ */
10
+ export declare const parseSchema: (schema: JSONSchema7) => ParsedSchema;
11
+ /**
12
+ * Recursively parse properties from a JSON Schema
13
+ */
14
+ export declare const parseProperties: (props: Record<string, JSONSchema7 | boolean>, requiredList?: string[]) => PropertyData[];
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Convert a string to snake_case format
3
+ * Removes special characters and replaces spaces with underscores
4
+ *
5
+ * @example
6
+ * toSnakeCase("User Name") // "user_name"
7
+ * toSnakeCase("First Name!") // "first_name"
8
+ */
9
+ export declare const toSnakeCase: (str: string) => string;
@@ -0,0 +1,2 @@
1
+ import { type ClassValue } from "clsx";
2
+ export declare function cn(...inputs: ClassValue[]): string;
@@ -0,0 +1,30 @@
1
+ import type { JSONSchema7TypeName } from "json-schema";
2
+ export type PropertyType = JSONSchema7TypeName | "file";
3
+ /**
4
+ * Internal UI representation of a JSON Schema property
5
+ * This extends JSONSchema7 with additional metadata needed for the builder UI
6
+ */
7
+ export interface PropertyData {
8
+ id: string;
9
+ key: string;
10
+ required: boolean;
11
+ type: PropertyType;
12
+ title?: string;
13
+ description?: string;
14
+ minLength?: number;
15
+ maxLength?: number;
16
+ pattern?: string;
17
+ enum?: string[];
18
+ minimum?: number;
19
+ maximum?: number;
20
+ minItems?: number;
21
+ maxItems?: number;
22
+ uniqueItems?: boolean;
23
+ items?: PropertyData;
24
+ children?: PropertyData[];
25
+ }
26
+ export interface SchemaMetadata {
27
+ title: string;
28
+ description: string;
29
+ version: string;
30
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-schema-builder-react",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "A React component library for building and editing JSON schemas visually",
5
5
  "type": "module",
6
6
  "license": "MIT",