Direct editing of view schema JSON
import { JSONEditor } from '@repo/view-builder/json-editor/JSONEditor'; import { SchemaProvider } from '@repo/view-builder/hooks/useSchemaState'; function MyJSONEditor() { return ( <SchemaProvider> <JSONEditor /> </SchemaProvider> ); }
<JSONEditor theme="dark" readOnly={false} height="500px" showLineNumbers={true} formatOnPaste={true} />
import { JSONEditor } from '@repo/view-builder/json-editor/JSONEditor'; import { useSchemaState } from '@repo/view-builder/hooks/useSchemaState'; function SchemaEditor() { const { schema, setSchema } = useSchemaState(); const handleChange = (newSchema) => { setSchema(newSchema); }; return <JSONEditor value={schema} onChange={handleChange} />; }
import { JSONEditor } from '@repo/view-builder/json-editor/JSONEditor'; const customValidationRules = [ { rule: (schema) => schema.fields && Object.keys(schema.fields).length > 0, message: 'Schema must contain at least one field' }, { rule: (schema) => schema.type === 'form' || schema.type === 'table' || schema.type === 'detail', message: 'Schema type must be one of: form, table, detail' } ]; function ValidatedEditor() { return <JSONEditor validationRules={customValidationRules} />; }
import { JSONEditor } from '@repo/view-builder/json-editor/JSONEditor'; const schemaTemplates = { emptyForm: { type: 'form', schema: 'user', fields: {} }, emptyTable: { type: 'table', schema: 'user', columns: [] }, emptyDetail: { type: 'detail', schema: 'user', sections: [] } }; function TemplatedEditor() { return <JSONEditor templates={schemaTemplates} />; }
import { JSONEditor } from '@repo/view-builder/json-editor/JSONEditor'; const customActions = [ { label: 'Generate Types', icon: 'code', action: (schema) => { // Generate TypeScript types from schema console.log('Generating types for schema:', schema); } }, { label: 'Export to File', icon: 'download', action: (schema) => { // Export schema to file const blob = new Blob([JSON.stringify(schema, null, 2)], { type: 'application/json' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = 'schema.json'; a.click(); } } ]; function ActionableEditor() { return <JSONEditor customActions={customActions} />; }