UNPKG

@gravel-form/antd

Version:

A flexible middlewares driven json schema form with Ant Design

1 lines 1.1 kB
{"version":3,"sources":["middlewares/LiveValidateMw.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,eAAe,EAAY,MAAM,UAAU,CAAC;AAErD,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAkBpD,CAAC;AAEF,eAAe,cAAc,CAAC","file":"LiveValidateMw.d.ts","sourcesContent":["import React from 'react';\nimport { Alert } from 'antd';\nimport { MiddlewareProps, validate } from '../share';\n\nexport const LiveValidateMw: React.FC<MiddlewareProps> = (props) => {\n const { schema, data, next, parent } = props;\n const [errors, ajvException] = React.useMemo(() => {\n try {\n return [parent || typeof schema === 'boolean' ? null : validate(schema, data), null];\n } catch (err) {\n return [null, err];\n }\n }, [schema, data]);\n const newProps = React.useMemo(() => ({ ...props, errors }), [errors, props]);\n return ajvException ? (\n <>\n <Alert message=\"Ajv exception\" description={ajvException.message} type=\"error\" showIcon />\n {next(props)}\n </>\n ) : (\n next(errors ? newProps : props)\n );\n};\n\nexport default LiveValidateMw;\n"]}