@gravel-form/antd
Version:
A flexible middlewares driven json schema form with Ant Design
57 lines (54 loc) • 2.26 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LiveValidateMw = void 0;
var react_1 = __importDefault(require("react"));
var antd_1 = require("antd");
var share_1 = require("../share");
exports.LiveValidateMw = function (props) {
var schema = props.schema, data = props.data, next = props.next, parent = props.parent;
var _a = __read(react_1.default.useMemo(function () {
try {
return [parent || typeof schema === 'boolean' ? null : share_1.validate(schema, data), null];
}
catch (err) {
return [null, err];
}
}, [schema, data]), 2), errors = _a[0], ajvException = _a[1];
var newProps = react_1.default.useMemo(function () { return (__assign(__assign({}, props), { errors: errors })); }, [errors, props]);
return ajvException ? (react_1.default.createElement(react_1.default.Fragment, null,
react_1.default.createElement(antd_1.Alert, { message: "Ajv exception", description: ajvException.message, type: "error", showIcon: true }),
next(props))) : (next(errors ? newProps : props));
};
exports.default = exports.LiveValidateMw;
//# sourceMappingURL=LiveValidateMw.js.map
//# sourceMappingURL=LiveValidateMw.js.map