A React component library for validating and previewing job input schemas for the Masumi platform. This component provides a playground interface where you can write, validate, and preview how input schemas will render as forms.
- âś… Schema Validation: Real-time validation of JSON schemas against the Masumi Job Input Schema specification
- 🎨 Live Preview: See how your schema renders as a form in real-time
- 📝 Monaco Editor: Syntax-highlighted JSON editor with error detection
- 🔍 Detailed Error Messages: Clear validation errors with line numbers and helpful suggestions
- 🌓 Dark Mode Support: Automatic theme detection and support
- 📦 TypeScript: Fully typed with TypeScript definitions
- 🎯 Multiple Schema Formats: Supports wrapped format, array format, and single schema format
npm install masumi-schema-validator-componentThis package requires the following peer dependencies:
react>= 18react-dom>= 18tailwindcss>= 3
import { SchemaPlayground } from 'masumi-schema-validator-component';
function App() {
const examples = [
{
label: 'Simple Form',
value: JSON.stringify([
{
id: 'name',
type: 'text',
name: 'Full Name',
data: {
placeholder: 'Enter your name'
}
}
])
}
];
return (
<SchemaPlayground
initialSchema="[]"
examples={examples}
onSchemaChange={(schema, isValid) => {
console.log('Schema changed:', schema, 'Valid:', isValid);
}}
/>
);
}The main component that provides a split-pane interface with a schema editor on the left and form preview on the right.
interface SchemaPlaygroundProps {
initialSchema?: string; // Initial JSON schema string (default: '[]')
examples?: Array<{ // Array of example schemas to load
label: string;
value: string;
}>;
className?: string; // Additional CSS classes
onSchemaChange?: ( // Callback when schema changes
schema: string,
isValid: boolean
) => void;
}<SchemaPlayground
initialSchema={mySchema}
examples={[
{ label: 'Example 1', value: '[...]' },
{ label: 'Example 2', value: '[...]' }
]}
onSchemaChange={(schema, isValid) => {
if (isValid) {
// Save valid schema
}
}}
/>Renders a form based on validated job input schemas. This component is used internally by SchemaPlayground but can also be used standalone.
interface JobInputsFormRendererProps {
jobInputSchemas: JobInputSchemaType[];
onFormDataChange?: (
formData: Record<string, string | number | boolean | number[] | null>
) => void;
disabled?: boolean;
className?: string;
}import { JobInputsFormRenderer } from 'masumi-schema-validator-component';
<JobInputsFormRenderer
jobInputSchemas={validatedSchemas}
onFormDataChange={(data) => {
console.log('Form data:', data);
}}
/>The component validates schemas according to the Masumi Job Input Schema specification. Schemas can be provided in three formats:
{
"input_data": [
{
"id": "field1",
"type": "text",
"name": "Field 1"
}
]
}[
{
"id": "field1",
"type": "text",
"name": "Field 1"
}
]{
"id": "field1",
"type": "text",
"name": "Field 1"
}text- Single-line text inputtextarea- Multi-line text inputnumber- Number inputemail- Email input with validationpassword- Password inputtel- Telephone number inputurl- URL inputdate- Date pickerdatetime-local- Date and time pickertime- Time pickermonth- Month pickerweek- Week pickercolor- Color pickerrange- Range sliderfile- File uploadoption- Select dropdown (single or multi-select)checkbox- Checkbox inputradio- Radio button groupboolean- Boolean togglehidden- Hidden fieldsearch- Search inputnone- No input (display only)
Schemas can include validation rules:
{
"id": "email",
"type": "email",
"name": "Email",
"validations": [
{ "validation": "format", "value": "email" },
{ "validation": "min", "value": "5" },
{ "validation": "max", "value": "100" },
{ "validation": "optional" }
]
}min- Minimum length or valuemax- Maximum length or valueformat- Format validation (email, url, non-empty, integer)optional- Makes the field optionalaccept- File type acceptance (for file inputs)
Validates a JSON schema string and returns validation results.
import { validateSchemaWithZod } from 'masumi-schema-validator-component';
const result = validateSchemaWithZod(schemaString);
if (result.valid) {
console.log('Valid schemas:', result.parsedSchemas);
} else {
console.log('Errors:', result.errors);
// Errors include line numbers and helpful messages
}interface ValidationResult {
valid: boolean;
errors: { message: string; line?: number }[];
parsedSchemas?: JobInputSchemaType[];
}# Install dependencies
npm install
# Start development server
npm run dev
# Build library
npm run build
# Type check
npm run type-check
# Lint
npm run lintsrc/
components/
SchemaPlayground.tsx # Main playground component
JobInputsFormRenderer.tsx # Form renderer component
JobInputRenderer.tsx # Individual input renderer
lib/
validation.ts # Schema validation logic
job-input-schema.ts # Schema type definitions
dev/
main.tsx # Development app
examples.ts # Example schemas
styles.css # Global styles
index.ts # Main exports
This component uses Tailwind CSS for styling. Make sure Tailwind CSS is configured in your project. The component includes its own minimal UI components but relies on Tailwind for styling.
Important: To ensure all styles (including dark mode variants) are properly generated, you must configure Tailwind to scan the component's TypeScript/JavaScript files. Add the following to your CSS file (e.g., global.css or app.css):
@import 'tailwindcss';
/* Ensure Tailwind scans external schema validator classes (including dark variants) */
@source "../node_modules/masumi-schema-validator-component/dist/index.mjs";
@source "../node_modules/masumi-schema-validator-component/dist/index.js";This ensures that Tailwind generates all necessary utility classes used by the component, including dark mode variants like dark:bg-red-900/30, dark:text-red-200, etc.
Full TypeScript support is included. All components and functions are fully typed:
import type {
JobInputSchemaType,
ValidationResult,
SchemaPlaygroundProps,
JobInputsFormRendererProps
} from 'masumi-schema-validator-component';See LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.