auto-views
Advanced tools
Comparing version 0.0.31 to 0.0.32
@@ -16,4 +16,4 @@ /// <reference types="react" /> | ||
export declare function fieldLabelSelector(key: string): string; | ||
export declare function autoFormSelector(key: string): string; | ||
export declare class AutoForm extends React.Component<AutoFormProps, {}> { | ||
private validator; | ||
constructor(props: AutoFormProps); | ||
@@ -24,2 +24,2 @@ private onEntryChange; | ||
} | ||
export declare function makeFormEntry(formData: any, displayMode: DisplayMode, erroneousProps?: Array<SchemaProperty>, onEntryChange?: (key: string, e: React.FormEvent<HTMLDivElement>) => void): (property: SchemaProperty, key: string) => JSX.Element; | ||
export declare function makeFormEntry(formData: any, displayMode: DisplayMode, repo: SchemaRepository, erroneousProps?: Array<SchemaProperty>, onEntryChange?: (key: string, e: React.FormEvent<HTMLDivElement>) => void): (property: SchemaProperty, key: string) => JSX.Element; |
@@ -24,3 +24,2 @@ "use strict"; | ||
var form_entry_1 = require("./form-entry"); | ||
var jsonschema_1 = require("jsonschema"); | ||
function newSchemaRepository() { | ||
@@ -38,2 +37,6 @@ return new schema_repo_1.SchemaRepository(); | ||
exports.fieldLabelSelector = fieldLabelSelector; | ||
function autoFormSelector(key) { | ||
return "auto_form_" + key; | ||
} | ||
exports.autoFormSelector = autoFormSelector; | ||
var AutoForm = (function (_super) { | ||
@@ -43,3 +46,2 @@ __extends(AutoForm, _super); | ||
var _this = _super.call(this, props) || this; | ||
_this.validator = new jsonschema_1.Validator(); | ||
_this.onEntryChange = function (key, e) { | ||
@@ -63,6 +65,5 @@ if (e.target && _this.props.onChange) { | ||
else { | ||
var schema = this.props.repo.getSchema(this.props.schemaId); | ||
var validationErrors = this.validator.validate(this.props.formData, schema).errors; | ||
var validationErrors = this.props.repo.validate(this.props.formData, this.props.schemaId).errors; | ||
var erroneousProps = validationErrors.map(function (err) { return err.schema; }); | ||
return this.props.repo.mapOverProperties(this.props.schemaId, makeFormEntry(this.props.formData, this.props.displayMode, erroneousProps, this.onEntryChange)); | ||
return this.props.repo.mapOverProperties(this.props.schemaId, makeFormEntry(this.props.formData, this.props.displayMode, this.props.repo, erroneousProps, this.onEntryChange)); | ||
} | ||
@@ -77,3 +78,3 @@ }; | ||
exports.AutoForm = AutoForm; | ||
function makeFormEntry(formData, displayMode, erroneousProps, onEntryChange) { | ||
function makeFormEntry(formData, displayMode, repo, erroneousProps, onEntryChange) { | ||
if (erroneousProps === void 0) { erroneousProps = []; } | ||
@@ -84,2 +85,5 @@ return function (property, key) { | ||
})) == undefined; | ||
if (property.type == 'object') { | ||
return React.createElement(AutoForm, { repo: repo, schemaId: property['$ref'], displayMode: displayMode, formData: formData[key] || {}, "data-automation-id": autoFormSelector(key) }); | ||
} | ||
return React.createElement(form_entry_1.Entry, { "data-automation-id": form_entry_1.entrySelector(key), entryKey: key, title: property.title || "", displayMode: displayMode, type: property.type, value: formData[key], onChange: function (e) { return onEntryChange && onEntryChange(key, e); }, valid: isValid }); | ||
@@ -86,0 +90,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
export declare type Type = "string" | "number" | "boolean" | "array"; | ||
export declare type Type = "string" | "number" | "boolean" | "array" | "object"; | ||
export declare class SchemaProperty { | ||
@@ -6,3 +6,6 @@ type: Type; | ||
[key: string]: any; | ||
properties?: { | ||
[key: string]: SchemaProperty; | ||
}; | ||
constructor(type: Type, title?: string | undefined, additionalProps?: any); | ||
} |
/// <reference types="react" /> | ||
import * as React from 'react'; | ||
import { Validator, ValidatorResult } from 'jsonschema'; | ||
import { SchemaProperty } from "./schema-property"; | ||
@@ -17,2 +18,3 @@ export interface AutoFormSchema { | ||
}; | ||
validator: Validator; | ||
addSchema(schema: AutoFormSchema): void; | ||
@@ -25,2 +27,3 @@ addSchemas(schemas: AutoFormSchema[]): void; | ||
getController(controllerID: string): React.ComponentType | null; | ||
validate(formData: any, schemaId: string): ValidatorResult; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var jsonschema_1 = require("jsonschema"); | ||
var SchemaRepository = (function () { | ||
@@ -7,6 +8,7 @@ function SchemaRepository() { | ||
this.controllers = {}; | ||
this.validator = new jsonschema_1.Validator(); | ||
} | ||
// validator:Validator = new Validator(); | ||
SchemaRepository.prototype.addSchema = function (schema) { | ||
this.schemas[schema.id] = schema; | ||
this.validator.addSchema(schema); | ||
}; | ||
@@ -22,2 +24,3 @@ SchemaRepository.prototype.addSchemas = function (schemas) { | ||
this.schemas = {}; | ||
this.validator = new jsonschema_1.Validator(); | ||
}; | ||
@@ -35,2 +38,5 @@ SchemaRepository.prototype.mapOverProperties = function (id, propertyVisitor) { | ||
}; | ||
SchemaRepository.prototype.validate = function (formData, schemaId) { | ||
return this.validator.validate(formData, this.getSchema(schemaId)); | ||
}; | ||
return SchemaRepository; | ||
@@ -37,0 +43,0 @@ }()); |
/// <reference types="react" /> | ||
import * as React from "react"; | ||
export interface Skin { | ||
boolean: (childProps: {}) => JSX.Element; | ||
string: (childProps: {}) => JSX.Element; | ||
number: (childProps: {}) => JSX.Element; | ||
} | ||
import { Skin } from "./component-renderer"; | ||
export declare class ViewSkin implements Skin { | ||
@@ -26,2 +22,1 @@ private renderBooleanForView; | ||
} | ||
export declare function renderInnerComp(value: any, renderer: Skin): any; |
@@ -12,2 +12,3 @@ "use strict"; | ||
var React = require("react"); | ||
var component_renderer_1 = require("./component-renderer"); | ||
var ViewSkin = (function () { | ||
@@ -46,6 +47,6 @@ function ViewSkin() { | ||
this.renderArrayTypeForEdit = function (childProps) { | ||
var parentAutomationId = childProps['data-automation-id']; | ||
var comps = childProps.value.map(function (value, index) { | ||
var innerComp = renderInnerComp(value, _this); | ||
return React.createElement("li", { "data-automation-id": parentAutomationId + '_' + index }, innerComp); | ||
var newAutomationId = childProps['data-automation-id'] + '_' + index; | ||
var innerComp = component_renderer_1.renderInnerComp(value, _this, newAutomationId); | ||
return React.createElement("li", { "data-automation-id": newAutomationId + '_li' }, innerComp); | ||
}); | ||
@@ -62,7 +63,2 @@ return React.createElement("ol", __assign({}, childProps), comps); | ||
exports.EditSkin = EditSkin; | ||
function renderInnerComp(value, renderer) { | ||
var typeString = ("" + typeof value); | ||
return renderer[typeString]({ value: value }); | ||
} | ||
exports.renderInnerComp = renderInnerComp; | ||
//# sourceMappingURL=skin.js.map |
{ | ||
"name": "auto-views", | ||
"version": "0.0.31", | ||
"version": "0.0.32", | ||
"description": "Common, fully-tested, strictly-typed, Wix-styled, auto views library", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -489,1 +489,2 @@ # Auto-Views component family | ||
For watch mode, you can pass in the watch flag: `npm run test:node -- -w` | ||
export type Type ="string"|"number"|"boolean"|"array";//|"null";|"object"; | ||
export type Type ="string"|"number"|"boolean"|"array"|"object";//|"null"; | ||
export class SchemaProperty { | ||
[key:string]:any; | ||
properties?:{[key:string]:SchemaProperty}; | ||
constructor(public type: Type,public title?: string, additionalProps: any = {}){ | ||
@@ -7,0 +8,0 @@ for (let key in additionalProps){ |
import * as React from 'react'; | ||
import {Validator} from 'jsonschema'; | ||
import {Validator, ValidatorResult} from 'jsonschema'; | ||
import {SchemaProperty} from "./schema-property"; | ||
@@ -13,6 +13,7 @@ | ||
controllers: {[key:string]:React.ComponentType} = {}; | ||
// validator:Validator = new Validator(); | ||
validator:Validator = new Validator(); | ||
addSchema(schema:AutoFormSchema):void { | ||
this.schemas[schema.id] = schema; | ||
this.validator.addSchema(schema); | ||
} | ||
@@ -30,2 +31,3 @@ | ||
this.schemas = {}; | ||
this.validator = new Validator(); | ||
} | ||
@@ -46,2 +48,6 @@ | ||
} | ||
validate(formData: any, schemaId: string):ValidatorResult { | ||
return this.validator.validate(formData,this.getSchema(schemaId)); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66057
49
909
490