zent
Version:
一套前端设计语言和基于React的实现
1,633 lines (1,308 loc) • 324 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof define === 'function' && define.amd)
define(["react"], factory);
else if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("react"));
else if(typeof exports === 'object')
exports["zent-form"] = factory(require("react"));
else
root["zent-form"] = factory(root["React"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_3__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(1);
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _Form = __webpack_require__(2);
var _Form2 = _interopRequireDefault(_Form);
var _createForm = __webpack_require__(9);
var _createForm2 = _interopRequireDefault(_createForm);
var _Field = __webpack_require__(205);
var _Field2 = _interopRequireDefault(_Field);
var _Fieldset = __webpack_require__(207);
var _Fieldset2 = _interopRequireDefault(_Fieldset);
var _getControlGroup = __webpack_require__(208);
var _getControlGroup2 = _interopRequireDefault(_getControlGroup);
var _unknownProps = __webpack_require__(206);
var _unknownProps2 = _interopRequireDefault(_unknownProps);
var _SubmissionError = __webpack_require__(202);
var _SubmissionError2 = _interopRequireDefault(_SubmissionError);
var _InputField = __webpack_require__(209);
var _InputField2 = _interopRequireDefault(_InputField);
var _CheckboxField = __webpack_require__(212);
var _CheckboxField2 = _interopRequireDefault(_CheckboxField);
var _CheckboxGroupField = __webpack_require__(216);
var _CheckboxGroupField2 = _interopRequireDefault(_CheckboxGroupField);
var _RadioGroupField = __webpack_require__(217);
var _RadioGroupField2 = _interopRequireDefault(_RadioGroupField);
var _SelectField = __webpack_require__(221);
var _SelectField2 = _interopRequireDefault(_SelectField);
var _assign = __webpack_require__(183);
var _assign2 = _interopRequireDefault(_assign);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
exports['default'] = (0, _assign2['default'])(_Form2['default'], {
Form: _Form2['default'],
createForm: _createForm2['default'],
Field: _Field2['default'],
Fieldset: _Fieldset2['default'],
getControlGroup: _getControlGroup2['default'],
unknownProps: _unknownProps2['default'],
InputField: _InputField2['default'],
CheckboxField: _CheckboxField2['default'],
CheckboxGroupField: _CheckboxGroupField2['default'],
RadioGroupField: _RadioGroupField2['default'],
SelectField: _SelectField2['default'],
SubmissionError: _SubmissionError2['default']
});
module.exports = exports['default'];
/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _class, _temp;
var _react = __webpack_require__(3);
var _react2 = _interopRequireDefault(_react);
var _classnames = __webpack_require__(4);
var _classnames2 = _interopRequireDefault(_classnames);
var _noop = __webpack_require__(7);
var _noop2 = _interopRequireDefault(_noop);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Form = (_temp = _class = function (_Component) {
_inherits(Form, _Component);
function Form() {
_classCallCheck(this, Form);
return _possibleConstructorReturn(this, (Form.__proto__ || Object.getPrototypeOf(Form)).apply(this, arguments));
}
_createClass(Form, [{
key: 'render',
value: function render() {
var _classNames;
var _props = this.props,
prefix = _props.prefix,
className = _props.className,
style = _props.style,
horizontal = _props.horizontal,
inline = _props.inline,
onSubmit = _props.onSubmit;
var formClassName = (0, _classnames2['default'])((_classNames = {}, _defineProperty(_classNames, prefix + '-form', true), _defineProperty(_classNames, prefix + '-form--horizontal', horizontal), _defineProperty(_classNames, prefix + '-form--inline', inline), _defineProperty(_classNames, className, !!className), _classNames));
return _react2['default'].createElement(
'form',
{ className: formClassName, style: style, onSubmit: onSubmit },
this.props.children
);
}
}]);
return Form;
}(_react.Component), _class.propTypes = {
prefix: _react.PropTypes.string,
className: _react.PropTypes.string,
horizontal: _react.PropTypes.bool,
inline: _react.PropTypes.bool,
onSubmit: _react.PropTypes.func,
children: _react.PropTypes.any,
style: _react.PropTypes.object
}, _class.defaultProps = {
prefix: 'zent',
onSubmit: _noop2['default']
}, _temp);
exports['default'] = Form;
module.exports = exports['default'];
/***/ },
/* 3 */
/***/ function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_3__;
/***/ },
/* 4 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _classnames = __webpack_require__(5);
Object.defineProperty(exports, 'default', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_classnames)['default'];
}
});
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { 'default': obj };
}
module.exports = exports['default'];
/***/ },
/* 5 */
/***/ function(module, exports, __webpack_require__) {
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
/*!
Copyright (c) 2016 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/
/* global define */
(function () {
'use strict';
var hasOwn = {}.hasOwnProperty;
function classNames() {
var classes = [];
for (var i = 0; i < arguments.length; i++) {
var arg = arguments[i];
if (!arg) continue;
var argType = typeof arg === 'undefined' ? 'undefined' : _typeof(arg);
if (argType === 'string' || argType === 'number') {
classes.push(arg);
} else if (Array.isArray(arg)) {
classes.push(classNames.apply(null, arg));
} else if (argType === 'object') {
for (var key in arg) {
if (hasOwn.call(arg, key) && arg[key]) {
classes.push(key);
}
}
}
}
return classes.join(' ');
}
if (typeof module !== 'undefined' && module.exports) {
module.exports = classNames;
} else if ("function" === 'function' && _typeof(__webpack_require__(6)) === 'object' && __webpack_require__(6)) {
// register as 'classnames', consistent with npm package name
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function () {
return classNames;
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
} else {
window.classNames = classNames;
}
})();
/***/ },
/* 6 */
/***/ function(module, exports) {
/* WEBPACK VAR INJECTION */(function(__webpack_amd_options__) {module.exports = __webpack_amd_options__;
/* WEBPACK VAR INJECTION */}.call(exports, {}))
/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
/* DO NOT EDIT!! Auto genetated wrapper for lodash/noop. */
var noop = __webpack_require__(8);
module.exports = noop;
/***/ },
/* 8 */
/***/ function(module, exports) {
"use strict";
/**
* This method returns `undefined`.
*
* @static
* @memberOf _
* @since 2.3.0
* @category Util
* @example
*
* _.times(2, _.noop);
* // => [undefined, undefined]
*/
function noop() {
// No operation performed.
}
module.exports = noop;
/***/ },
/* 9 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = __webpack_require__(3);
var _omit = __webpack_require__(10);
var _omit2 = _interopRequireDefault(_omit);
var _find = __webpack_require__(151);
var _find2 = _interopRequireDefault(_find);
var _noop = __webpack_require__(7);
var _noop2 = _interopRequireDefault(_noop);
var _assign = __webpack_require__(183);
var _assign2 = _interopRequireDefault(_assign);
var _isEqual = __webpack_require__(188);
var _isEqual2 = _interopRequireDefault(_isEqual);
var _some = __webpack_require__(190);
var _some2 = _interopRequireDefault(_some);
var _isPromise = __webpack_require__(198);
var _isPromise2 = _interopRequireDefault(_isPromise);
var _utils = __webpack_require__(199);
var _validationRules = __webpack_require__(200);
var _validationRules2 = _interopRequireDefault(_validationRules);
var _handleSubmit = __webpack_require__(201);
var _handleSubmit2 = _interopRequireDefault(_handleSubmit);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /* eslint-disable no-underscore-dangle */
var emptyArray = [];
var checkSubmit = function checkSubmit(submit) {
if (!submit || typeof submit !== 'function') {
throw new Error('You must either pass handleSubmit() an onSubmit function or pass onSubmit as a prop');
}
return submit;
};
var createForm = function createForm() {
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var formValidations = config.formValidations;
var validationRules = (0, _assign2['default'])({}, _validationRules2['default'], formValidations);
return function (WrappedComponent) {
var _class, _temp;
return _temp = _class = function (_Component) {
_inherits(Form, _Component);
function Form(props) {
_classCallCheck(this, Form);
var _this = _possibleConstructorReturn(this, (Form.__proto__ || Object.getPrototypeOf(Form)).call(this, props));
_this.submitCompleted = function (result) {
delete _this.submitPromise;
return result;
};
_this.submitFailed = function (error) {
delete _this.submitPromise;
throw error;
};
_this.listenToSubmit = function (promise) {
if (!(0, _isPromise2['default'])(promise)) {
return promise;
}
// 当submit是一个promise时,需要一个标识表明正在提交,提交结束后删除标识
_this.submitPromise = promise;
return promise.then(_this.submitCompleted, _this.submitFailed);
};
_this.submit = function (submitOrEvent) {
var onSubmit = _this.props.onSubmit;
// 在表单中手动调用handleSubmit或者把handleSubmit赋值给表单的onSubmit回调
// handleSubmit赋值给表单的onSubmit时,submitOrEvent是一个event对象
// handleSubmit的参数必须是function
if (!submitOrEvent || (0, _utils.silenceEvent)(submitOrEvent)) {
if (!_this.submitPromise) {
// 调用props传入的onSubmit方法
return _this.listenToSubmit((0, _handleSubmit2['default'])(checkSubmit(onSubmit), _this));
}
} else {
// submitOrEvent是一个自定义submit函数,返回一个promise对象
return (0, _utils.silenceEvents)(function () {
return !_this.submitPromise && _this.listenToSubmit((0, _handleSubmit2['default'])(checkSubmit(submitOrEvent), _this));
});
}
};
_this.isSubmitting = function () {
return _this.state.isSubmitting;
};
_this.isValid = function () {
return _this.state.isFormValid;
};
_this.setFieldValidationErrors = function (errors) {
_this.fields.forEach(function (field) {
var name = field.props.name;
field.setState({
_isValid: !(name in errors),
_validationError: typeof errors[name] === 'string' ? [errors[name]] : errors[name]
});
});
};
_this.setFieldExternalErrors = function (errors) {
Object.keys(errors).forEach(function (name) {
var field = (0, _find2['default'])(_this.fields, function (component) {
return component.props.name === name;
});
if (!field) {
throw new Error('field ' + name + ' does not exits');
}
field.setState({
_isValid: false,
_externalError: typeof errors[name] === 'string' ? [errors[name]] : errors[name]
});
});
};
_this.setFormPristine = function (isPristine) {
_this.fields.forEach(function (field) {
field.setState({
_isPristine: isPristine
});
});
};
_this.resetFieldsValue = function (data) {
_this.fields.forEach(function (field) {
var name = field.props.name;
if (data && data.hasOwnProperty(name)) {
field.setValue(data[name]);
} else {
field.resetValue();
}
});
};
_this.reset = function (data) {
_this.setFormPristine(true);
_this.resetFieldsValue(data);
};
_this.isFieldTouched = function (name) {
var field = _this.fields.find(function (component) {
return component.props.name === name;
});
if (!field) return false;
return !field.isPristine();
};
_this.isFieldValidating = function (name) {
var field = _this.fields.find(function (component) {
return component.props.name === name;
});
if (!field) return false;
return field.isValidating();
};
_this.getFieldError = function (name) {
var field = _this.fields.find(function (component) {
return component.props.name === name;
});
if (!field) return '';
return field.getErrorMessage();
};
_this.getFormValues = function () {
return _this.fields.reduce(function (values, field) {
var name = field.props.name;
values[name] = field.getValue();
return values;
}, {});
};
_this.getValidationErrors = function () {
return _this.fields.reduce(function (errors, field) {
var name = field.props.name;
errors[name] = field.getErrorMessage();
return errors;
}, {});
};
_this.getPristineValues = function () {
return _this.fields.reduce(function (values, field) {
var name = field.props.name;
values[name] = field.getPristineValue();
return values;
}, {});
};
_this.isChanged = function () {
return !(0, _isEqual2['default'])(_this.getPristineValues(), _this.getFormValues());
};
_this.isValidating = function () {
return (0, _some2['default'])(_this.fields, function (field) {
return field.isValidating();
});
};
_this.isValidValue = function (field, value) {
return _this.runValidation(field, value).isValid;
};
_this.runValidation = function (field) {
var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : field.getValue();
var formValidationErrors = _this.props.validationErrors;
var _field$props = field.props,
name = _field$props.name,
validationError = _field$props.validationError,
validationErrors = _field$props.validationErrors;
var currentValues = _this.getFormValues();
var validationResults = _this.runRules(value, currentValues, field._validations);
var isValid = !validationResults.failed.length && !(formValidationErrors && formValidationErrors[field.props.name]);
return {
isValid: isValid,
error: function () {
if (isValid) {
return emptyArray;
}
if (validationResults.errors.length) {
return validationResults.errors;
}
if (formValidationErrors && formValidationErrors[name]) {
return typeof formValidationErrors[name] === 'string' ? [formValidationErrors[name]] : formValidationErrors[name];
}
if (validationResults.failed.length) {
return validationResults.failed.map(function (failed) {
return validationErrors[failed] ? validationErrors[failed] : validationError;
}).filter(function (x, pos, arr) {
// Remove duplicates
return arr.indexOf(x) === pos;
});
}
}()
};
};
_this.runRules = function (value, currentValues) {
var validations = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
var results = {
errors: [],
failed: []
};
function updateResults(validation, validationMethod) {
// validation方法可以直接返回错误信息,否则需要返回布尔值表明校验是否成功
if (typeof validation === 'string') {
results.errors.push(validation);
results.failed.push(validationMethod);
} else if (!validation) {
results.failed.push(validationMethod);
}
}
Object.keys(validations).forEach(function (validationMethod) {
// validations中不指定function则必须是内置的rule
if (!validationRules[validationMethod] && typeof validations[validationMethod] !== 'function') {
throw new Error('does not have the validation rule: ' + validationMethod);
}
// 使用自定义校验方法或内置校验方法(可以按需添加)
if (typeof validations[validationMethod] === 'function') {
var validation = validations[validationMethod](currentValues, value);
updateResults(validation, validationMethod);
} else if (typeof validations[validationMethod] !== 'function') {
var _validation = validationRules[validationMethod](currentValues, value, validations[validationMethod]);
updateResults(_validation, validationMethod);
}
});
return results;
};
_this.validate = function (field) {
// 初始化时调用validate不触发onChange
if (_this._isMounted) {
_this.props.onChange(_this.getFormValues(), _this.isChanged());
}
var validation = _this.runValidation(field);
field.setState({
_isValid: validation.isValid,
_validationError: validation.error,
_externalError: null
}, _this.validateForm);
};
_this.asyncValidate = function (field, value) {
var asyncValidation = field.props.asyncValidation;
var values = _this.getFormValues();
if (field.state._validationError.length) return;
field.setState({
_isValidating: true
});
var promise = asyncValidation(values, value);
if (!(0, _isPromise2['default'])(promise)) {
throw new Error('asyncValidation function must return a promise');
}
var handleResult = function handleResult(rejected) {
return function (error) {
field.setState({
_isValidating: false,
_isValid: !rejected,
_externalError: error ? [error] : null
});
if (rejected) {
_this.setState({
isFormValid: false
});
}
};
};
return promise.then(handleResult(false), handleResult(true));
};
_this.validateForm = function () {
var onValidationComplete = function onValidationComplete() {
var allIsValid = _this.fields.every(function (field) {
return field.isValid();
});
_this.setState({
isFormValid: allIsValid
});
if (allIsValid) {
_this.props.onValid();
} else {
_this.props.onInvalid();
}
};
_this.fields.forEach(function (field, index) {
var _externalError = field.state._externalError;
var validation = _this.runValidation(field);
if (validation.isValid && _externalError) {
validation.isValid = false;
}
field.setState({
_isValid: validation.isValid,
_validationError: validation.error,
_externalError: !validation.isValid && _externalError ? _externalError : null
}, index === _this.fields.length - 1 ? onValidationComplete : null);
});
};
_this.attachToForm = function (field) {
if (_this.fields.indexOf(field) < 0) {
_this.fields.push(field);
}
// form初始化时不校验,后续动态添加的元素再校验
_this._isMounted && _this.validate(field);
};
_this.detachFromForm = function (field) {
var fieldPos = _this.fields.indexOf(field);
if (fieldPos >= 0) {
_this.fields.splice(fieldPos, 1);
}
_this.validateForm();
};
_this.state = {
isFormValid: true,
isSubmitting: false
};
_this.fields = [];
_this._isMounted = false;
return _this;
}
_createClass(Form, [{
key: 'getChildContext',
value: function getChildContext() {
return {
zentForm: {
attachToForm: this.attachToForm,
detachFromForm: this.detachFromForm,
validate: this.validate,
asyncValidate: this.asyncValidate,
getFormValues: this.getFormValues,
getFieldError: this.getFieldError,
isValidValue: this.isValidValue,
setFieldExternalErrors: this.setFieldExternalErrors,
resetFieldsValue: this.resetFieldsValue,
setFormPristine: this.setFormPristine,
isValid: this.isValid,
isSubmitting: this.isSubmitting
}
};
}
}, {
key: 'componentDidMount',
value: function componentDidMount() {
this.validateForm();
this._isMounted = true;
}
}, {
key: 'componentWillUpdate',
value: function componentWillUpdate() {
this.prevFieldNames = this.fields.map(function (field) {
return field.props.name;
});
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate() {
var validationErrors = this.props.validationErrors;
if (validationErrors && (typeof validationErrors === 'undefined' ? 'undefined' : _typeof(validationErrors)) === 'object' && Object.keys(validationErrors).length > 0) {
this.setFieldValidationErrors(validationErrors);
}
var newFieldNames = this.fields.map(function (field) {
return field.props.name;
});
if (!(0, _isEqual2['default'])(this.prevFieldNames, newFieldNames)) {
this.validateForm();
}
}
// 设置服务端返回的错误信息
}, {
key: 'render',
value: function render() {
var passableProps = (0, _omit2['default'])(this.props, ['validationErrors', 'handleSubmit', 'onChange']);
return (0, _react.createElement)(WrappedComponent, _extends({}, passableProps, {
handleSubmit: this.submit,
zentForm: {
getFormValues: this.getFormValues,
getFieldError: this.getFieldError,
setFieldExternalErrors: this.setFieldExternalErrors,
resetFieldsValue: this.resetFieldsValue,
setFormPristine: this.setFormPristine,
isFieldTouched: this.isFieldTouched,
isFieldValidating: this.isFieldValidating,
isValid: this.isValid,
isValidating: this.isValidating,
isSubmitting: this.isSubmitting
}
}));
}
}]);
return Form;
}(_react.Component), _class.displayName = 'Form(' + (0, _utils.getDisplayName)(WrappedComponent) + ')', _class.WrappedComponent = WrappedComponent, _class.propTypes = {
onSubmit: _react.PropTypes.func,
onSubmitSuccess: _react.PropTypes.func,
onSubmitFail: _react.PropTypes.func,
onValid: _react.PropTypes.func,
onInvalid: _react.PropTypes.func,
onChange: _react.PropTypes.func,
validationErrors: _react.PropTypes.object
}, _class.defaultProps = {
onSubmit: _noop2['default'],
onSubmitSuccess: _noop2['default'],
onSubmitFail: _noop2['default'],
onValid: _noop2['default'],
onInvalid: _noop2['default'],
onChange: _noop2['default'],
validationErrors: null
}, _class.childContextTypes = {
zentForm: _react.PropTypes.object
}, _temp;
};
};
exports['default'] = createForm;
module.exports = exports['default'];
/***/ },
/* 10 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
/* DO NOT EDIT!! Auto genetated wrapper for lodash/omit. */
var omit = __webpack_require__(11);
module.exports = omit;
/***/ },
/* 11 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var arrayMap = __webpack_require__(12),
baseClone = __webpack_require__(13),
baseUnset = __webpack_require__(124),
castPath = __webpack_require__(125),
copyObject = __webpack_require__(63),
customOmitClone = __webpack_require__(138),
flatRest = __webpack_require__(140),
getAllKeysIn = __webpack_require__(101);
/** Used to compose bitmasks for cloning. */
var CLONE_DEEP_FLAG = 1,
CLONE_FLAT_FLAG = 2,
CLONE_SYMBOLS_FLAG = 4;
/**
* The opposite of `_.pick`; this method creates an object composed of the
* own and inherited enumerable property paths of `object` that are not omitted.
*
* **Note:** This method is considerably slower than `_.pick`.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Object
* @param {Object} object The source object.
* @param {...(string|string[])} [paths] The property paths to omit.
* @returns {Object} Returns the new object.
* @example
*
* var object = { 'a': 1, 'b': '2', 'c': 3 };
*
* _.omit(object, ['a', 'c']);
* // => { 'b': '2' }
*/
var omit = flatRest(function (object, paths) {
var result = {};
if (object == null) {
return result;
}
var isDeep = false;
paths = arrayMap(paths, function (path) {
path = castPath(path, object);
isDeep || (isDeep = path.length > 1);
return path;
});
copyObject(object, getAllKeysIn(object), result);
if (isDeep) {
result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
}
var length = paths.length;
while (length--) {
baseUnset(result, paths[length]);
}
return result;
});
module.exports = omit;
/***/ },
/* 12 */
/***/ function(module, exports) {
"use strict";
/**
* A specialized version of `_.map` for arrays without support for iteratee
* shorthands.
*
* @private
* @param {Array} [array] The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the new mapped array.
*/
function arrayMap(array, iteratee) {
var index = -1,
length = array == null ? 0 : array.length,
result = Array(length);
while (++index < length) {
result[index] = iteratee(array[index], index, array);
}
return result;
}
module.exports = arrayMap;
/***/ },
/* 13 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var Stack = __webpack_require__(14),
arrayEach = __webpack_require__(58),
assignValue = __webpack_require__(59),
baseAssign = __webpack_require__(62),
baseAssignIn = __webpack_require__(85),
cloneBuffer = __webpack_require__(89),
copyArray = __webpack_require__(90),
copySymbols = __webpack_require__(91),
copySymbolsIn = __webpack_require__(95),
getAllKeys = __webpack_require__(99),
getAllKeysIn = __webpack_require__(101),
getTag = __webpack_require__(102),
initCloneArray = __webpack_require__(107),
initCloneByTag = __webpack_require__(108),
initCloneObject = __webpack_require__(122),
isArray = __webpack_require__(70),
isBuffer = __webpack_require__(71),
isObject = __webpack_require__(38),
keys = __webpack_require__(64);
/** Used to compose bitmasks for cloning. */
var CLONE_DEEP_FLAG = 1,
CLONE_FLAT_FLAG = 2,
CLONE_SYMBOLS_FLAG = 4;
/** `Object#toString` result references. */
var argsTag = '[object Arguments]',
arrayTag = '[object Array]',
boolTag = '[object Boolean]',
dateTag = '[object Date]',
errorTag = '[object Error]',
funcTag = '[object Function]',
genTag = '[object GeneratorFunction]',
mapTag = '[object Map]',
numberTag = '[object Number]',
objectTag = '[object Object]',
regexpTag = '[object RegExp]',
setTag = '[object Set]',
stringTag = '[object String]',
symbolTag = '[object Symbol]',
weakMapTag = '[object WeakMap]';
var arrayBufferTag = '[object ArrayBuffer]',
dataViewTag = '[object DataView]',
float32Tag = '[object Float32Array]',
float64Tag = '[object Float64Array]',
int8Tag = '[object Int8Array]',
int16Tag = '[object Int16Array]',
int32Tag = '[object Int32Array]',
uint8Tag = '[object Uint8Array]',
uint8ClampedTag = '[object Uint8ClampedArray]',
uint16Tag = '[object Uint16Array]',
uint32Tag = '[object Uint32Array]';
/** Used to identify `toStringTag` values supported by `_.clone`. */
var cloneableTags = {};
cloneableTags[argsTag] = cloneableTags[arrayTag] = cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] = cloneableTags[boolTag] = cloneableTags[dateTag] = cloneableTags[float32Tag] = cloneableTags[float64Tag] = cloneableTags[int8Tag] = cloneableTags[int16Tag] = cloneableTags[int32Tag] = cloneableTags[mapTag] = cloneableTags[numberTag] = cloneableTags[objectTag] = cloneableTags[regexpTag] = cloneableTags[setTag] = cloneableTags[stringTag] = cloneableTags[symbolTag] = cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] = cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
cloneableTags[errorTag] = cloneableTags[funcTag] = cloneableTags[weakMapTag] = false;
/**
* The base implementation of `_.clone` and `_.cloneDeep` which tracks
* traversed objects.
*
* @private
* @param {*} value The value to clone.
* @param {boolean} bitmask The bitmask flags.
* 1 - Deep clone
* 2 - Flatten inherited properties
* 4 - Clone symbols
* @param {Function} [customizer] The function to customize cloning.
* @param {string} [key] The key of `value`.
* @param {Object} [object] The parent object of `value`.
* @param {Object} [stack] Tracks traversed objects and their clone counterparts.
* @returns {*} Returns the cloned value.
*/
function baseClone(value, bitmask, customizer, key, object, stack) {
var result,
isDeep = bitmask & CLONE_DEEP_FLAG,
isFlat = bitmask & CLONE_FLAT_FLAG,
isFull = bitmask & CLONE_SYMBOLS_FLAG;
if (customizer) {
result = object ? customizer(value, key, object, stack) : customizer(value);
}
if (result !== undefined) {
return result;
}
if (!isObject(value)) {
return value;
}
var isArr = isArray(value);
if (isArr) {
result = initCloneArray(value);
if (!isDeep) {
return copyArray(value, result);
}
} else {
var tag = getTag(value),
isFunc = tag == funcTag || tag == genTag;
if (isBuffer(value)) {
return cloneBuffer(value, isDeep);
}
if (tag == objectTag || tag == argsTag || isFunc && !object) {
result = isFlat || isFunc ? {} : initCloneObject(value);
if (!isDeep) {
return isFlat ? copySymbolsIn(value, baseAssignIn(result, value)) : copySymbols(value, baseAssign(result, value));
}
} else {
if (!cloneableTags[tag]) {
return object ? value : {};
}
result = initCloneByTag(value, tag, baseClone, isDeep);
}
}
// Check for circular references and return its corresponding clone.
stack || (stack = new Stack());
var stacked = stack.get(value);
if (stacked) {
return stacked;
}
stack.set(value, result);
var keysFunc = isFull ? isFlat ? getAllKeysIn : getAllKeys : isFlat ? keysIn : keys;
var props = isArr ? undefined : keysFunc(value);
arrayEach(props || value, function (subValue, key) {
if (props) {
key = subValue;
subValue = value[key];
}
// Recursively populate clone (susceptible to call stack limits).
assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
});
return result;
}
module.exports = baseClone;
/***/ },
/* 14 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var ListCache = __webpack_require__(15),
stackClear = __webpack_require__(23),
stackDelete = __webpack_require__(24),
stackGet = __webpack_require__(25),
stackHas = __webpack_require__(26),
stackSet = __webpack_require__(27);
/**
* Creates a stack cache object to store key-value pairs.
*
* @private
* @constructor
* @param {Array} [entries] The key-value pairs to cache.
*/
function Stack(entries) {
var data = this.__data__ = new ListCache(entries);
this.size = data.size;
}
// Add methods to `Stack`.
Stack.prototype.clear = stackClear;
Stack.prototype['delete'] = stackDelete;
Stack.prototype.get = stackGet;
Stack.prototype.has = stackHas;
Stack.prototype.set = stackSet;
module.exports = Stack;
/***/ },
/* 15 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var listCacheClear = __webpack_require__(16),
listCacheDelete = __webpack_require__(17),
listCacheGet = __webpack_require__(20),
listCacheHas = __webpack_require__(21),
listCacheSet = __webpack_require__(22);
/**
* Creates an list cache object.
*
* @private
* @constructor
* @param {Array} [entries] The key-value pairs to cache.
*/
function ListCache(entries) {
var index = -1,
length = entries == null ? 0 : entries.length;
this.clear();
while (++index < length) {
var entry = entries[index];
this.set(entry[0], entry[1]);
}
}
// Add methods to `ListCache`.
ListCache.prototype.clear = listCacheClear;
ListCache.prototype['delete'] = listCacheDelete;
ListCache.prototype.get = listCacheGet;
ListCache.prototype.has = listCacheHas;
ListCache.prototype.set = listCacheSet;
module.exports = ListCache;
/***/ },
/* 16 */
/***/ function(module, exports) {
"use strict";
/**
* Removes all key-value entries from the list cache.
*
* @private
* @name clear
* @memberOf ListCache
*/
function listCacheClear() {
this.__data__ = [];
this.size = 0;
}
module.exports = listCacheClear;
/***/ },
/* 17 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var assocIndexOf = __webpack_require__(18);
/** Used for built-in method references. */
var arrayProto = Array.prototype;
/** Built-in value references. */
var splice = arrayProto.splice;
/**
* Removes `key` and its value from the list cache.
*
* @private
* @name delete
* @memberOf ListCache
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/
function listCacheDelete(key) {
var data = this.__data__,
index = assocIndexOf(data, key);
if (index < 0) {
return false;
}
var lastIndex = data.length - 1;
if (index == lastIndex) {
data.pop();
} else {
splice.call(data, index, 1);
}
--this.size;
return true;
}
module.exports = listCacheDelete;
/***/ },
/* 18 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var eq = __webpack_require__(19);
/**
* Gets the index at which the `key` is found in `array` of key-value pairs.
*
* @private
* @param {Array} array The array to inspect.
* @param {*} key The key to search for.
* @returns {number} Returns the index of the matched value, else `-1`.
*/
function assocIndexOf(array, key) {
var length = array.length;
while (length--) {
if (eq(array[length][0], key)) {
return length;
}
}
return -1;
}
module.exports = assocIndexOf;
/***/ },
/* 19 */
/***/ function(module, exports) {
"use strict";
/**
* Performs a
* [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
* comparison between two values to determine if they are equivalent.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
* @example
*
* var object = { 'a': 1 };
* var other = { 'a': 1 };
*
* _.eq(object, object);
* // => true
*
* _.eq(object, other);
* // => false
*
* _.eq('a', 'a');
* // => true
*
* _.eq('a', Object('a'));
* // => false
*
* _.eq(NaN, NaN);
* // => true
*/
function eq(value, other) {
return value === other || value !== value && other !== other;
}
module.exports = eq;
/***/ },
/* 20 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var assocIndexOf = __webpack_require__(18);
/**
* Gets the list cache value for `key`.
*
* @private
* @name get
* @memberOf ListCache
* @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/
function listCacheGet(key) {
var data = this.__data__,
index = assocIndexOf(data, key);
return index < 0 ? undefined : data[index][1];
}
module.exports = listCacheGet;
/***/ },
/* 21 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var assocIndexOf = __webpack_require__(18);
/**
* Checks if a list cache value for `key` exists.
*
* @private
* @name has
* @memberOf ListCache
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/
function listCacheHas(key) {
return assocIndexOf(this.__data__, key) > -1;
}
module.exports = listCacheHas;
/***/ },
/* 22 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var assocIndexOf = __webpack_require__(18);
/**
* Sets the list cache `key` to `value`.
*
* @private
* @name set
* @memberOf ListCache
* @param {string} key The key of the value to set.
* @param {*} value The value to set.
* @returns {Object} Returns the list cache instance.
*/
function listCacheSet(key, value) {
var data = this.__data__,
index = assocIndexOf(data, key);
if (index < 0) {
++this.size;
data.push([key, value]);
} else {
data[index][1] = value;
}
return this;
}
module.exports = listCacheSet;
/***/ },
/* 23 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var ListCache = __webpack_require__(15);
/**
* Removes all key-value entries from the stack.
*
* @private
* @name clear
* @memberOf Stack
*/
function stackClear() {
this.__data__ = new ListCache();
this.size = 0;
}
module.exports = stackClear;
/***/ },
/* 24 */
/***/ function(module, exports) {
'use strict';
/**
* Removes `key` and its value from the stack.
*
* @private
* @name delete
* @memberOf Stack
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/
function stackDelete(key) {
var data = this.__data__,
result = data['delete'](key);
this.size = data.size;
return result;
}
module.exports = stackDelete;
/***/ },
/* 25 */
/***/ function(module, exports) {
"use strict";
/**
* Gets the stack value for `key`.
*
* @private
* @name get
* @memberOf Stack
* @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/
function stackGet(key) {
return this.__data__.get(key);
}
module.exports = stackGet;
/***/ },
/* 26 */
/***/ function(module, exports) {
"use strict";
/**
* Checks if a stack value for `key` exists.
*
* @private
* @name has
* @memberOf Stack
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/
function stackHas(key) {
return this.__data__.has(key);
}
module.exports = stackHas;
/***/ },
/* 27 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var ListCache = __webpack_require__(15),
Map = __webpack_require__(28),
MapCache = __webpack_require__(43);
/** Used as the size to enable large array optimizations. */
var LARGE_ARRAY_SIZE = 200;
/**
* Sets the stack `key` to `value`.
*
* @private
* @name set
* @memberOf Stack
* @param {string} key The key of the value to set.
* @param {*} value The value to set.
* @returns {Object} Returns the stack cache instance.
*/
function stackSet(key, value) {
var data = this.__data__;
if (data instanceof ListCache) {
var pairs = data.__data__;
if (!Map || pairs.length < LARGE_ARRAY_SIZE - 1) {
pairs.push([key, value]);
this.size = ++data.size;
return this;
}
data = this.__data__ = new MapCache(pairs);
}
data.set(key, value);
this.size = data.size;
return this;
}
module.exports = stackSet;
/***/ },
/* 28 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var getNative = __webpack_require__(29),
root = __webpack_require__(34);
/* Built-in method references that are verified to be native. */
var Map = getNative(root, 'Map');
module.exports = Map;
/***/ },
/* 29 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var baseIsNative = __webpack_require__(30),
getValue = __webpack_require__(42);
/**
* Gets the native function at `key` of `object`.
*
* @private
* @param {Object} object The object to query.
* @param {string} key The key of the method to get.
* @returns {*} Returns the function if it's native, else `undefined`.
*/
function getNative(object, key) {
var value = getValue(object, key);
return baseIsNative(value) ? value : undefined;
}
module.exports = getNative;
/***/ },
/* 30 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var isFunction = __webpack_require__(31),
isMasked = __webpack_require__(39),
isObject = __webpack_require__(38),
toSource = __webpack_require__(41);
/**
* Used to match `RegExp`
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
*/
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
/** Used to detect host constructors (Safari). */
var reIsHostCtor = /^\[object .+?Constructor\]$/;
/** Used for built-in method references. */
var funcProto = Function.prototype,
objectProto = Object.prototype;
/** Used to resolve the decompiled source of functions. */
var funcToString = funcProto.toString;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
/** Used to detect if a method is native. */
var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
/**
* The base implementation of `_.isNative` without bad shim checks.
*
* @private
* @param {*} value The value to check.
* @retu