Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
auto-views-with-ui-schema
Advanced tools
* [Example](#example) * [ComponentsRepo](#componentsrepo) * [UISchema](#uischema) * [Components API](#components-api) * [AutoView](#autoview) * [RepositoryProvider](#repositoryprovider) * [Types](#types)
import * as React from 'react';
import {
AutoView,
CoreSchemaMetaSchema,
RepositoryProvider
} from './src'; // TODO
import {getRepoWithDefaults} from './test/utils/component-repo';
function App() {
const components = getRepoWithDefaults('test');
const schema: CoreSchemaMetaSchema = {
type: 'object',
properties: {
firstName: {
type: 'string'
},
lastName: {
type: 'string'
}
}
};
const data = {
firstName: 'Obi-Wan',
lastName: 'Kenobi'
};
return (
<RepositoryProvider components={components}>
<AutoView schema={schema} data={value}/>
</RepositoryProvider>
);
}
First of all you have to create set of component which you want to use to render different types
of you json schema.
This could be done with ComponentsRepo
class:
import {ComponentsRepo} from './src';
import {Form} from './form';
import {Input} from './input';
import {MaterialInput} from './material-input';
const components = new ComponentsRepo();
components.register('string', {name: 'custom-string', component: Input}
components.register('string', {name: 'material-string', component: MaterialInput}
components.register('object', {name: 'custom-form', component: Form}
The signature of register
is
register(type: SimpleTypes, record: {name: string, component: React.ComponentType<AutoViewProps>})
AutoView
will use these components while rendering. Last registred component for specific type will be used for render that type (this could be overriten with uiSchema
)
Here is example of how components may looks like
Each component which is regstred should have the same API as AutoView
component (AutoViewProps
);
input.tsx
import {AutoViewProps, createChangeEventHandler} from './src';
export const input = (props: AutoViewProps) => {
return (
<input
type="number"
value={props.data}
onChange={createChangeEventHandler(props, e => e.currentTarget.value)}
/>
);
}
material-input.tsx
import TextField from 'material-ui/TextField';
import {AutoViewProps, createChangeEventHandler} from './src';
export const MaterialInput = (props: AutoViewProps) => {
return (
<TextField
value={props.data}
floatingLabelText={props.schema.title}
onChange={createChangeEventHandler(props, e => e.currentTarget.value)}
/>
);
}
form.tsx
import {AutoViewProps, renderObjectFields} from './src';
export const Form = (props: AutoViewProps) => {
return (
<form>
{renderObjectFields(props)}
</form>
);
}
Next step is to pass components
to RepositoryProvider
<RepositoryProvider components={components}>
<AutoView schema={schema} data={value}/>
</RepositoryProvider>
NOTE: you should wrapp AutoView
with RepositoryProvider
on top level, otherwise AutoView
will not be able to render.
uiSchema
allow to specify components for specific schema nodes.
Following code will register custom-string
component for rendering /properties/lastName
node. For others string nodes the default component will be used.
import {UISchema} from './src';
const uiSchema = new UISchema('test');
uiSchema.addOverride('/properties/lastName', {name: 'custom-string'});
Next you have to pass uiSchema
into AutoView
<RepositoryProvider components={components}>
<AutoView
schema={schema}
data={value}
uiSchema={uiSchema}
/>
</RepositoryProvider>
property | type | default | description |
---|---|---|---|
schema | CoreSchemaMetaSchema | json shcema | |
data | any? | data to represent | |
uiSchema | UISchema? | data to represent | |
validation | boolean? | true | enable of disable validation |
onChange | AutoEventHandler? | callen whenever data modified / added / moved |
property | type | default | description |
---|---|---|---|
components | ComponentsRepo | repository with components | |
validator | Djv? | new Djv() | json schema validator |
SimpleTypes = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null'
AutoEventHandler = (e: {pointer: string, schemaPointer: string, patch?: Operations})
FAQs
`AutoViews` is a set of utilities and abstractions which provides functionality to automatically build UI on top of `JSONSchema`.
We found that auto-views-with-ui-schema demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.