UNPKG

angular-formly

Version:

AngularJS directive which takes JSON representing a form and renders to HTML

1,469 lines (1,224 loc) 101 kB
/*! * angular-formly JavaScript Library v8.4.1 * * @license MIT (http://license.angular-formly.com) * * built with ♥ by Astrism <astrisms@gmail.com>, Kent C. Dodds <kent@doddsfamily.us> * (ó ì_í)=óò=(ì_í ò) */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("angular"), require("api-check")); else if(typeof define === 'function' && define.amd) define(["angular", "api-check"], factory); else if(typeof exports === 'object') exports["ngFormly"] = factory(require("angular"), require("api-check")); else root["ngFormly"] = factory(root["angular"], root["apiCheck"]); })(this, function(__WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_5__) { 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__) { 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _indexCommon = __webpack_require__(1); var _indexCommon2 = _interopRequireDefault(_indexCommon); exports['default'] = _indexCommon2['default']; module.exports = exports['default']; /***/ }, /* 1 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _angularFix = __webpack_require__(2); var _angularFix2 = _interopRequireDefault(_angularFix); var _providersFormlyApiCheck = __webpack_require__(4); var _providersFormlyApiCheck2 = _interopRequireDefault(_providersFormlyApiCheck); var _otherDocsBaseUrl = __webpack_require__(6); var _otherDocsBaseUrl2 = _interopRequireDefault(_otherDocsBaseUrl); var _providersFormlyUsability = __webpack_require__(7); var _providersFormlyUsability2 = _interopRequireDefault(_providersFormlyUsability); var _providersFormlyConfig = __webpack_require__(8); var _providersFormlyConfig2 = _interopRequireDefault(_providersFormlyConfig); var _providersFormlyValidationMessages = __webpack_require__(10); var _providersFormlyValidationMessages2 = _interopRequireDefault(_providersFormlyValidationMessages); var _servicesFormlyUtil = __webpack_require__(11); var _servicesFormlyUtil2 = _interopRequireDefault(_servicesFormlyUtil); var _servicesFormlyWarn = __webpack_require__(12); var _servicesFormlyWarn2 = _interopRequireDefault(_servicesFormlyWarn); var _directivesFormlyCustomValidation = __webpack_require__(13); var _directivesFormlyCustomValidation2 = _interopRequireDefault(_directivesFormlyCustomValidation); var _directivesFormlyField = __webpack_require__(14); var _directivesFormlyField2 = _interopRequireDefault(_directivesFormlyField); var _directivesFormlyFocus = __webpack_require__(15); var _directivesFormlyFocus2 = _interopRequireDefault(_directivesFormlyFocus); var _directivesFormlyForm = __webpack_require__(16); var _directivesFormlyForm2 = _interopRequireDefault(_directivesFormlyForm); var _directivesFormlyFormController = __webpack_require__(17); var _directivesFormlyFormController2 = _interopRequireDefault(_directivesFormlyFormController); var _runFormlyNgModelAttrsManipulator = __webpack_require__(18); var _runFormlyNgModelAttrsManipulator2 = _interopRequireDefault(_runFormlyNgModelAttrsManipulator); var _runFormlyCustomTags = __webpack_require__(19); var _runFormlyCustomTags2 = _interopRequireDefault(_runFormlyCustomTags); var ngModuleName = 'formly'; exports['default'] = ngModuleName; var ngModule = _angularFix2['default'].module(ngModuleName, []); ngModule.constant('formlyApiCheck', _providersFormlyApiCheck2['default']); ngModule.constant('formlyErrorAndWarningsUrlPrefix', _otherDocsBaseUrl2['default']); ngModule.constant('formlyVersion', ("8.4.1")); // <-- webpack variable ngModule.provider('formlyUsability', _providersFormlyUsability2['default']); ngModule.provider('formlyConfig', _providersFormlyConfig2['default']); ngModule.factory('formlyValidationMessages', _providersFormlyValidationMessages2['default']); ngModule.factory('formlyUtil', _servicesFormlyUtil2['default']); ngModule.factory('formlyWarn', _servicesFormlyWarn2['default']); ngModule.directive('formlyCustomValidation', _directivesFormlyCustomValidation2['default']); ngModule.directive('formlyField', _directivesFormlyField2['default']); ngModule.directive('formlyFocus', _directivesFormlyFocus2['default']); ngModule.directive('formlyForm', _directivesFormlyForm2['default']); ngModule.controller('FormlyFormController', _directivesFormlyFormController2['default']); ngModule.run(_runFormlyNgModelAttrsManipulator2['default']); ngModule.run(_runFormlyCustomTags2['default']); module.exports = exports['default']; /***/ }, /* 2 */ /***/ function(module, exports, __webpack_require__) { // some versions of angular don't export the angular module properly, // so we get it from window in this case. 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var angular = __webpack_require__(3); /* istanbul ignore next */ if (!angular.version) { angular = window.angular; } exports['default'] = angular; 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 }); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _angularFix = __webpack_require__(2); var _angularFix2 = _interopRequireDefault(_angularFix); var _apiCheck = __webpack_require__(5); var _apiCheck2 = _interopRequireDefault(_apiCheck); var apiCheck = (0, _apiCheck2['default'])({ output: { prefix: 'angular-formly:', docsBaseUrl: __webpack_require__(6) } }); function shapeRequiredIfNot(otherProps, propChecker) { if (!_angularFix2['default'].isArray(otherProps)) { otherProps = [otherProps]; } var type = 'specified if these are not specified: `' + otherProps.join(', ') + '` (otherwise it\'s optional)'; function shapeRequiredIfNotDefinition(prop, propName, location, obj) { var propExists = obj && obj.hasOwnProperty(propName); var otherPropsExist = otherProps.some(function (otherProp) { return obj && obj.hasOwnProperty(otherProp); }); if (!otherPropsExist && !propExists) { return apiCheck.utils.getError(propName, location, type); } else if (propExists) { return propChecker(prop, propName, location, obj); } } shapeRequiredIfNotDefinition.type = type; return apiCheck.utils.checkerHelpers.setupChecker(shapeRequiredIfNotDefinition); } var formlyExpression = apiCheck.oneOfType([apiCheck.string, apiCheck.func]); var specifyWrapperType = apiCheck.typeOrArrayOf(apiCheck.string).nullable; var apiCheckProperty = apiCheck.func; var apiCheckInstanceProperty = apiCheck.shape.onlyIf('apiCheck', apiCheck.func.withProperties({ warn: apiCheck.func, 'throw': apiCheck.func, shape: apiCheck.func })); var apiCheckFunctionProperty = apiCheck.shape.onlyIf('apiCheck', apiCheck.oneOf(['throw', 'warn'])); var formlyWrapperType = apiCheck.shape({ name: shapeRequiredIfNot('types', apiCheck.string).optional, template: apiCheck.shape.ifNot('templateUrl', apiCheck.string).optional, templateUrl: apiCheck.shape.ifNot('template', apiCheck.string).optional, types: apiCheck.typeOrArrayOf(apiCheck.string).optional, overwriteOk: apiCheck.bool.optional, apiCheck: apiCheckProperty.optional, apiCheckInstance: apiCheckInstanceProperty.optional, apiCheckFunction: apiCheckFunctionProperty.optional, apiCheckOptions: apiCheck.object.optional }).strict; var expressionProperties = apiCheck.objectOf(apiCheck.oneOfType([formlyExpression, apiCheck.shape({ expression: formlyExpression, message: formlyExpression.optional }).strict])); var modelChecker = apiCheck.oneOfType([apiCheck.string, apiCheck.object]); var templateManipulators = apiCheck.shape({ preWrapper: apiCheck.arrayOf(apiCheck.func).nullable.optional, postWrapper: apiCheck.arrayOf(apiCheck.func).nullable.optional }).strict.nullable; var validatorChecker = apiCheck.objectOf(apiCheck.oneOfType([formlyExpression, apiCheck.shape({ expression: formlyExpression, message: formlyExpression.optional }).strict])); var watcherChecker = apiCheck.typeOrArrayOf(apiCheck.shape({ expression: formlyExpression.optional, listener: formlyExpression.optional, runFieldExpressions: apiCheck.bool.optional })); var fieldOptionsApiShape = { $$hashKey: apiCheck.any.optional, type: apiCheck.shape.ifNot(['template', 'templateUrl'], apiCheck.string).optional, template: apiCheck.shape.ifNot(['type', 'templateUrl'], apiCheck.oneOfType([apiCheck.string, apiCheck.func])).optional, templateUrl: apiCheck.shape.ifNot(['type', 'template'], apiCheck.oneOfType([apiCheck.string, apiCheck.func])).optional, key: apiCheck.oneOfType([apiCheck.string, apiCheck.number]).optional, model: modelChecker.optional, originalModel: modelChecker.optional, className: apiCheck.string.optional, id: apiCheck.string.optional, name: apiCheck.string.optional, expressionProperties: expressionProperties.optional, extras: apiCheck.shape({ validateOnModelChange: apiCheck.bool.optional, skipNgModelAttrsManipulator: apiCheck.oneOfType([apiCheck.string, apiCheck.bool]).optional }).strict.optional, data: apiCheck.object.optional, templateOptions: apiCheck.object.optional, wrapper: specifyWrapperType.optional, modelOptions: apiCheck.shape({ updateOn: apiCheck.string.optional, debounce: apiCheck.oneOfType([apiCheck.objectOf(apiCheck.number), apiCheck.number]).optional, allowInvalid: apiCheck.bool.optional, getterSetter: apiCheck.bool.optional, timezone: apiCheck.string.optional }).optional, watcher: watcherChecker.optional, validators: validatorChecker.optional, asyncValidators: validatorChecker.optional, parsers: apiCheck.arrayOf(formlyExpression).optional, formatters: apiCheck.arrayOf(formlyExpression).optional, noFormControl: apiCheck.bool.optional, hide: apiCheck.bool.optional, hideExpression: formlyExpression.optional, ngModelElAttrs: apiCheck.objectOf(apiCheck.string).optional, ngModelAttrs: apiCheck.objectOf(apiCheck.shape({ statement: apiCheck.shape.ifNot(['value', 'attribute', 'bound', 'boolean'], apiCheck.any).optional, value: apiCheck.shape.ifNot('statement', apiCheck.any).optional, attribute: apiCheck.shape.ifNot('statement', apiCheck.any).optional, bound: apiCheck.shape.ifNot('statement', apiCheck.any).optional, boolean: apiCheck.shape.ifNot('statement', apiCheck.any).optional }).strict).optional, elementAttributes: apiCheck.objectOf(apiCheck.string).optional, optionsTypes: apiCheck.typeOrArrayOf(apiCheck.string).optional, link: apiCheck.func.optional, controller: apiCheck.oneOfType([apiCheck.string, apiCheck.func, apiCheck.array]).optional, validation: apiCheck.shape({ show: apiCheck.bool.nullable.optional, messages: apiCheck.objectOf(formlyExpression).optional, errorExistsAndShouldBeVisible: apiCheck.bool.optional }).optional, formControl: apiCheck.typeOrArrayOf(apiCheck.object).optional, value: apiCheck.func.optional, runExpressions: apiCheck.func.optional, templateManipulators: templateManipulators.optional, resetModel: apiCheck.func.optional, updateInitialValue: apiCheck.func.optional, initialValue: apiCheck.any.optional, defaultValue: apiCheck.any.optional }; var formlyFieldOptions = apiCheck.shape(fieldOptionsApiShape).strict; var formOptionsApi = apiCheck.shape({ formState: apiCheck.object.optional, resetModel: apiCheck.func.optional, updateInitialValue: apiCheck.func.optional, removeChromeAutoComplete: apiCheck.bool.optional, parseKeyArrays: apiCheck.bool.optional, templateManipulators: templateManipulators.optional, manualModelWatcher: apiCheck.oneOfType([apiCheck.bool, apiCheck.func]).optional, watchAllExpressions: apiCheck.bool.optional, wrapper: specifyWrapperType.optional, fieldTransform: apiCheck.oneOfType([apiCheck.func, apiCheck.array]).optional, data: apiCheck.object.optional }).strict; var fieldGroup = apiCheck.shape({ $$hashKey: apiCheck.any.optional, key: apiCheck.oneOfType([apiCheck.string, apiCheck.number]).optional, // danger. Nested field groups wont get api-checked... fieldGroup: apiCheck.arrayOf(apiCheck.oneOfType([formlyFieldOptions, apiCheck.object])), className: apiCheck.string.optional, options: formOptionsApi.optional, templateOptions: apiCheck.object.optional, wrapper: specifyWrapperType.optional, watcher: watcherChecker.optional, hide: apiCheck.bool.optional, hideExpression: formlyExpression.optional, data: apiCheck.object.optional, model: modelChecker.optional, form: apiCheck.object.optional, elementAttributes: apiCheck.objectOf(apiCheck.string).optional }).strict; var typeOptionsDefaultOptions = _angularFix2['default'].copy(fieldOptionsApiShape); typeOptionsDefaultOptions.key = apiCheck.string.optional; var formlyTypeOptions = apiCheck.shape({ name: apiCheck.string, template: apiCheck.shape.ifNot('templateUrl', apiCheck.oneOfType([apiCheck.string, apiCheck.func])).optional, templateUrl: apiCheck.shape.ifNot('template', apiCheck.oneOfType([apiCheck.string, apiCheck.func])).optional, controller: apiCheck.oneOfType([apiCheck.func, apiCheck.string, apiCheck.array]).optional, link: apiCheck.func.optional, defaultOptions: apiCheck.oneOfType([apiCheck.func, apiCheck.shape(typeOptionsDefaultOptions)]).optional, 'extends': apiCheck.string.optional, wrapper: specifyWrapperType.optional, data: apiCheck.object.optional, apiCheck: apiCheckProperty.optional, apiCheckInstance: apiCheckInstanceProperty.optional, apiCheckFunction: apiCheckFunctionProperty.optional, apiCheckOptions: apiCheck.object.optional, overwriteOk: apiCheck.bool.optional }).strict; _angularFix2['default'].extend(apiCheck, { formlyTypeOptions: formlyTypeOptions, formlyFieldOptions: formlyFieldOptions, formlyExpression: formlyExpression, formlyWrapperType: formlyWrapperType, fieldGroup: fieldGroup, formOptionsApi: formOptionsApi }); exports['default'] = apiCheck; module.exports = exports['default']; /***/ }, /* 5 */ /***/ function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_5__; /***/ }, /* 6 */ /***/ function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = "https://github.com/formly-js/angular-formly/blob/" + ("8.4.1") + "/other/ERRORS_AND_WARNINGS.md#"; module.exports = exports["default"]; /***/ }, /* 7 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; formlyUsability.$inject = ["formlyApiCheck", "formlyErrorAndWarningsUrlPrefix"]; Object.defineProperty(exports, '__esModule', { value: true }); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _angularFix = __webpack_require__(2); var _angularFix2 = _interopRequireDefault(_angularFix); exports['default'] = formlyUsability; // @ngInject function formlyUsability(formlyApiCheck, formlyErrorAndWarningsUrlPrefix) { var _this = this; _angularFix2['default'].extend(this, { getFormlyError: getFormlyError, getFieldError: getFieldError, checkWrapper: checkWrapper, checkWrapperTemplate: checkWrapperTemplate, getErrorMessage: getErrorMessage, $get: function $get() { return _this; } }); function getFieldError(errorInfoSlug, message, field) { if (arguments.length < 3) { field = message; message = errorInfoSlug; errorInfoSlug = null; } return new Error(getErrorMessage(errorInfoSlug, message) + (' Field definition: ' + _angularFix2['default'].toJson(field))); } function getFormlyError(errorInfoSlug, message) { if (!message) { message = errorInfoSlug; errorInfoSlug = null; } return new Error(getErrorMessage(errorInfoSlug, message)); } function getErrorMessage(errorInfoSlug, message) { var url = ''; if (errorInfoSlug !== null) { url = '' + formlyErrorAndWarningsUrlPrefix + errorInfoSlug; } return 'Formly Error: ' + message + '. ' + url; } function checkWrapper(wrapper) { formlyApiCheck['throw'](formlyApiCheck.formlyWrapperType, wrapper, { prefix: 'formlyConfig.setWrapper', urlSuffix: 'setwrapper-validation-failed' }); } function checkWrapperTemplate(template, additionalInfo) { var formlyTransclude = '<formly-transclude></formly-transclude>'; if (template.indexOf(formlyTransclude) === -1) { throw getFormlyError('Template wrapper templates must use "' + formlyTransclude + '" somewhere in them. ' + ('This one does not have "<formly-transclude></formly-transclude>" in it: ' + template) + '\n' + ('Additional information: ' + JSON.stringify(additionalInfo))); } } } module.exports = exports['default']; /***/ }, /* 8 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; formlyConfig.$inject = ["formlyUsabilityProvider", "formlyErrorAndWarningsUrlPrefix", "formlyApiCheck"]; Object.defineProperty(exports, '__esModule', { value: true }); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } } var _angularFix = __webpack_require__(2); var _angularFix2 = _interopRequireDefault(_angularFix); var _otherUtils = __webpack_require__(9); var _otherUtils2 = _interopRequireDefault(_otherUtils); exports['default'] = formlyConfig; // @ngInject function formlyConfig(formlyUsabilityProvider, formlyErrorAndWarningsUrlPrefix, formlyApiCheck) { var _this2 = this; var typeMap = {}; var templateWrappersMap = {}; var defaultWrapperName = 'default'; var _this = this; var getError = formlyUsabilityProvider.getFormlyError; _angularFix2['default'].extend(this, { setType: setType, getType: getType, getTypes: getTypes, getTypeHeritage: getTypeHeritage, setWrapper: setWrapper, getWrapper: getWrapper, getWrapperByType: getWrapperByType, removeWrapperByName: removeWrapperByName, removeWrappersForType: removeWrappersForType, disableWarnings: false, extras: { disableNgModelAttrsManipulator: false, fieldTransform: [], ngModelAttrsManipulatorPreferUnbound: false, removeChromeAutoComplete: false, parseKeyArrays: false, defaultHideDirective: 'ng-if', getFieldId: null }, templateManipulators: { preWrapper: [], postWrapper: [] }, $get: function $get() { return _this2; } }); function setType(options) { if (_angularFix2['default'].isArray(options)) { var _ret = (function () { var allTypes = []; _angularFix2['default'].forEach(options, function (item) { allTypes.push(setType(item)); }); return { v: allTypes }; })(); if (typeof _ret === 'object') return _ret.v; } else if (_angularFix2['default'].isObject(options)) { checkType(options); if (options['extends']) { extendTypeOptions(options); } typeMap[options.name] = options; return typeMap[options.name]; } else { throw getError('You must provide an object or array for setType. You provided: ' + JSON.stringify(arguments)); } } function checkType(options) { formlyApiCheck['throw'](formlyApiCheck.formlyTypeOptions, options, { prefix: 'formlyConfig.setType', url: 'settype-validation-failed' }); if (!options.overwriteOk) { checkOverwrite(options.name, typeMap, options, 'types'); } else { options.overwriteOk = undefined; } } function extendTypeOptions(options) { var extendsType = getType(options['extends'], true, options); extendTypeControllerFunction(options, extendsType); extendTypeLinkFunction(options, extendsType); extendTypeDefaultOptions(options, extendsType); _otherUtils2['default'].reverseDeepMerge(options, extendsType); extendTemplate(options, extendsType); } function extendTemplate(options, extendsType) { if (options.template && extendsType.templateUrl) { delete options.templateUrl; } else if (options.templateUrl && extendsType.template) { delete options.template; } } function extendTypeControllerFunction(options, extendsType) { var extendsCtrl = extendsType.controller; if (!_angularFix2['default'].isDefined(extendsCtrl)) { return; } var optionsCtrl = options.controller; if (_angularFix2['default'].isDefined(optionsCtrl)) { options.controller = function ($scope, $controller) { $controller(extendsCtrl, { $scope: $scope }); $controller(optionsCtrl, { $scope: $scope }); }; options.controller.$inject = ['$scope', '$controller']; } else { options.controller = extendsCtrl; } } function extendTypeLinkFunction(options, extendsType) { var extendsFn = extendsType.link; if (!_angularFix2['default'].isDefined(extendsFn)) { return; } var optionsFn = options.link; if (_angularFix2['default'].isDefined(optionsFn)) { options.link = function () { extendsFn.apply(undefined, arguments); optionsFn.apply(undefined, arguments); }; } else { options.link = extendsFn; } } function extendTypeDefaultOptions(options, extendsType) { var extendsDO = extendsType.defaultOptions; if (!_angularFix2['default'].isDefined(extendsDO)) { return; } var optionsDO = options.defaultOptions || {}; var optionsDOIsFn = _angularFix2['default'].isFunction(optionsDO); var extendsDOIsFn = _angularFix2['default'].isFunction(extendsDO); if (extendsDOIsFn) { options.defaultOptions = function defaultOptions(opts, scope) { var extendsDefaultOptions = extendsDO(opts, scope); var mergedDefaultOptions = {}; _otherUtils2['default'].reverseDeepMerge(mergedDefaultOptions, opts, extendsDefaultOptions); var extenderOptionsDefaultOptions = optionsDO; if (optionsDOIsFn) { extenderOptionsDefaultOptions = extenderOptionsDefaultOptions(mergedDefaultOptions, scope); } _otherUtils2['default'].reverseDeepMerge(extenderOptionsDefaultOptions, extendsDefaultOptions); return extenderOptionsDefaultOptions; }; } else if (optionsDOIsFn) { options.defaultOptions = function defaultOptions(opts, scope) { var newDefaultOptions = {}; _otherUtils2['default'].reverseDeepMerge(newDefaultOptions, opts, extendsDO); return optionsDO(newDefaultOptions, scope); }; } } function getType(name, throwError, errorContext) { if (!name) { return undefined; } var type = typeMap[name]; if (!type && throwError === true) { throw getError('There is no type by the name of "' + name + '": ' + JSON.stringify(errorContext)); } else { return type; } } function getTypes() { return typeMap; } function getTypeHeritage(parent) { var heritage = []; var type = parent; if (_angularFix2['default'].isString(type)) { type = getType(parent); } parent = type['extends']; while (parent) { type = getType(parent); heritage.push(type); parent = type['extends']; } return heritage; } function setWrapper(_x, _x2) { var _again = true; _function: while (_again) { var options = _x, name = _x2; _again = false; if (_angularFix2['default'].isArray(options)) { return options.map(function (wrapperOptions) { return setWrapper(wrapperOptions); }); } else if (_angularFix2['default'].isObject(options)) { options.types = getOptionsTypes(options); options.name = getOptionsName(options, name); checkWrapperAPI(options); templateWrappersMap[options.name] = options; return options; } else if (_angularFix2['default'].isString(options)) { _x = { template: options, name: name }; _x2 = undefined; _again = true; continue _function; } } } function getOptionsTypes(options) { if (_angularFix2['default'].isString(options.types)) { return [options.types]; } if (!_angularFix2['default'].isDefined(options.types)) { return []; } else { return options.types; } } function getOptionsName(options, name) { return options.name || name || options.types.join(' ') || defaultWrapperName; } function checkWrapperAPI(options) { formlyUsabilityProvider.checkWrapper(options); if (options.template) { formlyUsabilityProvider.checkWrapperTemplate(options.template, options); } if (!options.overwriteOk) { checkOverwrite(options.name, templateWrappersMap, options, 'templateWrappers'); } else { delete options.overwriteOk; } checkWrapperTypes(options); } function checkWrapperTypes(options) { var shouldThrow = !_angularFix2['default'].isArray(options.types) || !options.types.every(_angularFix2['default'].isString); if (shouldThrow) { throw getError('Attempted to create a template wrapper with types that is not a string or an array of strings'); } } function checkOverwrite(property, object, newValue, objectName) { if (object.hasOwnProperty(property)) { warn('overwriting-types-or-wrappers', ['Attempting to overwrite ' + property + ' on ' + objectName + ' which is currently', JSON.stringify(object[property]) + ' with ' + JSON.stringify(newValue), 'To supress this warning, specify the property "overwriteOk: true"'].join(' ')); } } function getWrapper(name) { return templateWrappersMap[name || defaultWrapperName]; } function getWrapperByType(type) { /* eslint prefer-const:0 */ var wrappers = []; for (var _name in templateWrappersMap) { if (templateWrappersMap.hasOwnProperty(_name)) { if (templateWrappersMap[_name].types && templateWrappersMap[_name].types.indexOf(type) !== -1) { wrappers.push(templateWrappersMap[_name]); } } } return wrappers; } function removeWrapperByName(name) { var wrapper = templateWrappersMap[name]; delete templateWrappersMap[name]; return wrapper; } function removeWrappersForType(type) { var wrappers = getWrapperByType(type); if (!wrappers) { return undefined; } if (!_angularFix2['default'].isArray(wrappers)) { return removeWrapperByName(wrappers.name); } else { wrappers.forEach(function (wrapper) { return removeWrapperByName(wrapper.name); }); return wrappers; } } function warn() { if (!_this.disableWarnings && console.warn) { /* eslint no-console:0 */ var args = Array.prototype.slice.call(arguments); var warnInfoSlug = args.shift(); args.unshift('Formly Warning:'); args.push('' + formlyErrorAndWarningsUrlPrefix + warnInfoSlug); console.warn.apply(console, _toConsumableArray(args)); } } } module.exports = exports['default']; /***/ }, /* 9 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _angularFix = __webpack_require__(2); var _angularFix2 = _interopRequireDefault(_angularFix); exports['default'] = { containsSelector: containsSelector, containsSpecialChar: containsSpecialChar, formlyEval: formlyEval, getFieldId: getFieldId, reverseDeepMerge: reverseDeepMerge, findByNodeName: findByNodeName, arrayify: arrayify, extendFunction: extendFunction, extendArray: extendArray, startsWith: startsWith, contains: contains }; function containsSelector(string) { return containsSpecialChar(string, '.') || containsSpecialChar(string, '[') && containsSpecialChar(string, ']'); } function containsSpecialChar(a, b) { if (!a || !a.indexOf) { return false; } return a.indexOf(b) !== -1; } function formlyEval(scope, expression, $modelValue, $viewValue, extraLocals) { if (_angularFix2['default'].isFunction(expression)) { return expression($viewValue, $modelValue, scope, extraLocals); } else { return scope.$eval(expression, _angularFix2['default'].extend({ $viewValue: $viewValue, $modelValue: $modelValue }, extraLocals)); } } function getFieldId(formId, options, index) { if (options.id) { return options.id; } var type = options.type; if (!type && options.template) { type = 'template'; } else if (!type && options.templateUrl) { type = 'templateUrl'; } return [formId, type, options.key, index].join('_'); } function reverseDeepMerge(dest) { _angularFix2['default'].forEach(arguments, function (src, index) { if (!index) { return; } _angularFix2['default'].forEach(src, function (val, prop) { if (!_angularFix2['default'].isDefined(dest[prop])) { dest[prop] = _angularFix2['default'].copy(val); } else if (objAndSameType(dest[prop], val)) { reverseDeepMerge(dest[prop], val); } }); }); return dest; } function objAndSameType(obj1, obj2) { return _angularFix2['default'].isObject(obj1) && _angularFix2['default'].isObject(obj2) && Object.getPrototypeOf(obj1) === Object.getPrototypeOf(obj2); } // recurse down a node tree to find a node with matching nodeName, for custom tags jQuery.find doesn't work in IE8 function findByNodeName(el, nodeName) { if (!el.prop) { // not a jQuery or jqLite object -> wrap it el = _angularFix2['default'].element(el); } if (el.prop('nodeName') === nodeName.toUpperCase()) { return el; } var c = el.children(); for (var i = 0; c && i < c.length; i++) { var node = findByNodeName(c[i], nodeName); if (node) { return node; } } } function arrayify(obj) { if (obj && !_angularFix2['default'].isArray(obj)) { obj = [obj]; } else if (!obj) { obj = []; } return obj; } function extendFunction() { for (var _len = arguments.length, fns = Array(_len), _key = 0; _key < _len; _key++) { fns[_key] = arguments[_key]; } return function extendedFunction() { var args = arguments; fns.forEach(function (fn) { return fn.apply(null, args); }); }; } function extendArray(primary, secondary, property) { if (property) { primary = primary[property]; secondary = secondary[property]; } if (secondary && primary) { _angularFix2['default'].forEach(secondary, function (item) { if (primary.indexOf(item) === -1) { primary.push(item); } }); return primary; } else if (secondary) { return secondary; } else { return primary; } } function startsWith(str, search) { if (_angularFix2['default'].isString(str) && _angularFix2['default'].isString(search)) { return str.length >= search.length && str.substring(0, search.length) === search; } else { return false; } } function contains(str, search) { if (_angularFix2['default'].isString(str) && _angularFix2['default'].isString(search)) { return str.length >= search.length && str.indexOf(search) !== -1; } else { return false; } } module.exports = exports['default']; /***/ }, /* 10 */ /***/ function(module, exports) { 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); exports['default'] = formlyValidationMessages; // @ngInject function formlyValidationMessages() { var validationMessages = { addTemplateOptionValueMessage: addTemplateOptionValueMessage, addStringMessage: addStringMessage, messages: {} }; return validationMessages; function addTemplateOptionValueMessage(name, prop, prefix, suffix, alternate) { validationMessages.messages[name] = templateOptionValue(prop, prefix, suffix, alternate); } function addStringMessage(name, string) { validationMessages.messages[name] = function () { return string; }; } function templateOptionValue(prop, prefix, suffix, alternate) { return function getValidationMessage(viewValue, modelValue, scope) { if (typeof scope.options.templateOptions[prop] !== 'undefined') { return prefix + ' ' + scope.options.templateOptions[prop] + ' ' + suffix; } else { return alternate; } }; } } module.exports = exports['default']; /***/ }, /* 11 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _otherUtils = __webpack_require__(9); var _otherUtils2 = _interopRequireDefault(_otherUtils); exports['default'] = formlyUtil; // @ngInject function formlyUtil() { return _otherUtils2['default']; } module.exports = exports['default']; /***/ }, /* 12 */ /***/ function(module, exports) { 'use strict'; formlyWarn.$inject = ["formlyConfig", "formlyErrorAndWarningsUrlPrefix", "$log"]; Object.defineProperty(exports, '__esModule', { value: true }); function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } } exports['default'] = formlyWarn; // @ngInject function formlyWarn(formlyConfig, formlyErrorAndWarningsUrlPrefix, $log) { return function warn() { if (!formlyConfig.disableWarnings) { var args = Array.prototype.slice.call(arguments); var warnInfoSlug = args.shift(); args.unshift('Formly Warning:'); args.push('' + formlyErrorAndWarningsUrlPrefix + warnInfoSlug); $log.warn.apply($log, _toConsumableArray(args)); } }; } module.exports = exports['default']; /***/ }, /* 13 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; formlyCustomValidation.$inject = ["formlyUtil"]; Object.defineProperty(exports, '__esModule', { value: true }); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _angularFix = __webpack_require__(2); var _angularFix2 = _interopRequireDefault(_angularFix); exports['default'] = formlyCustomValidation; // @ngInject function formlyCustomValidation(formlyUtil) { return { restrict: 'A', require: 'ngModel', link: function formlyCustomValidationLink(scope, el, attrs, ctrl) { var opts = scope.options; opts.validation.messages = opts.validation.messages || {}; _angularFix2['default'].forEach(opts.validation.messages, function (message, key) { opts.validation.messages[key] = function () { return formlyUtil.formlyEval(scope, message, ctrl.$modelValue, ctrl.$viewValue); }; }); var useNewValidatorsApi = ctrl.hasOwnProperty('$validators') && !attrs.hasOwnProperty('useParsers'); _angularFix2['default'].forEach(opts.validators, _angularFix2['default'].bind(null, addValidatorToPipeline, false)); _angularFix2['default'].forEach(opts.asyncValidators, _angularFix2['default'].bind(null, addValidatorToPipeline, true)); function addValidatorToPipeline(isAsync, validator, name) { setupMessage(validator, name); validator = _angularFix2['default'].isObject(validator) ? validator.expression : validator; if (useNewValidatorsApi) { setupWithValidators(validator, name, isAsync); } else { setupWithParsers(validator, name, isAsync); } } function setupMessage(validator, name) { var message = validator.message; if (message) { opts.validation.messages[name] = function () { return formlyUtil.formlyEval(scope, message, ctrl.$modelValue, ctrl.$viewValue); }; } } function setupWithValidators(validator, name, isAsync) { var validatorCollection = isAsync ? '$asyncValidators' : '$validators'; ctrl[validatorCollection][name] = function evalValidity(modelValue, viewValue) { return formlyUtil.formlyEval(scope, validator, modelValue, viewValue); }; } function setupWithParsers(validator, name, isAsync) { var inFlightValidator = undefined; ctrl.$parsers.unshift(function evalValidityOfParser(viewValue) { var isValid = formlyUtil.formlyEval(scope, validator, ctrl.$modelValue, viewValue); if (isAsync) { ctrl.$pending = ctrl.$pending || {}; ctrl.$pending[name] = true; inFlightValidator = isValid; isValid.then(function () { if (inFlightValidator === isValid) { ctrl.$setValidity(name, true); } })['catch'](function () { if (inFlightValidator === isValid) { ctrl.$setValidity(name, false); } })['finally'](function () { var $pending = ctrl.$pending || {}; if (Object.keys($pending).length === 1) { delete ctrl.$pending; } else { delete ctrl.$pending[name]; } }); } else { ctrl.$setValidity(name, isValid); } return viewValue; }); } } }; } module.exports = exports['default']; /***/ }, /* 14 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; formlyField.$inject = ["$http", "$q", "$compile", "$templateCache", "$interpolate", "formlyConfig", "formlyApiCheck", "formlyUtil", "formlyUsability", "formlyWarn"]; Object.defineProperty(exports, '__esModule', { value: true }); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } } var _angularFix = __webpack_require__(2); var _angularFix2 = _interopRequireDefault(_angularFix); var _apiCheck = __webpack_require__(5); var _apiCheck2 = _interopRequireDefault(_apiCheck); exports['default'] = formlyField; /** * @ngdoc directive * @name formlyField * @restrict AE */ // @ngInject function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyConfig, formlyApiCheck, formlyUtil, formlyUsability, formlyWarn) { FormlyFieldController.$inject = ["$scope", "$timeout", "$parse", "$controller", "formlyValidationMessages"]; var arrayify = formlyUtil.arrayify; return { restrict: 'AE', transclude: true, require: '?^formlyForm', scope: { options: '=', model: '=', originalModel: '=?', formId: '@', // TODO remove formId in a breaking release index: '=?', fields: '=?', formState: '=?', formOptions: '=?', form: '=?' }, // TODO require form in a breaking release controller: FormlyFieldController, link: fieldLink }; // @ngInject function FormlyFieldController($scope, $timeout, $parse, $controller, formlyValidationMessages) { /* eslint max-statements:[2, 37] */ if ($scope.options.fieldGroup) { setupFieldGroup(); return; } var fieldType = getFieldType($scope.options); simplifyLife($scope.options); mergeFieldOptionsWithTypeDefaults($scope.options, fieldType); extendOptionsWithDefaults($scope.options, $scope.index); checkApi($scope.options); // set field id to link labels and fields // initalization setFieldIdAndName(); setDefaultValue(); setInitialValue(); runExpressions(); watchExpressions(); addValidationMessages($scope.options); invokeControllers($scope, $scope.options, fieldType); // function definitions function runExpressions() { var deferred = $q.defer(); // must run on next tick to make sure that the current value is correct. $timeout(function runExpressionsOnNextTick() { var promises = []; var field = $scope.options; var currentValue = valueGetterSetter(); _angularFix2['default'].forEach(field.expressionProperties, function runExpression(expression, prop) { var setter = $parse(prop).assign; var promise = $q.when(formlyUtil.formlyEval($scope, expression, currentValue, currentValue)).then(function setFieldValue(value) { setter(field, value); }); promises.push(promise); }); $q.all(promises).then(function () { deferred.resolve(); }); }, 0, false); return deferred.promise; } function watchExpressions() { if ($scope.formOptions.watchAllExpressions) { (function () { var field = $scope.options; var currentValue = valueGetterSetter(); _angularFix2['default'].forEach(field.expressionProperties, function watchExpression(expression, prop) { var setter = $parse(prop).assign; $scope.$watch(function expressionPropertyWatcher() { return formlyUtil.formlyEval($scope, expression, currentValue, currentValue); }, function expressionPropertyListener(value) { setter(field, value); }, true); }); })(); } } function valueGetterSetter(newVal) { if (!$scope.model || !$scope.options.key) { return undefined; } if (_angularFix2['default'].isDefined(newVal)) { parseSet($scope.options.key, $scope.model, newVal); } return parseGet($scope.options.key, $scope.model); } function shouldNotUseParseKey(key) { return _angularFix2['default'].isNumber(key) || !formlyUtil.containsSelector(key); } function keyContainsArrays(key) { return (/\[\d{1,}\]/.test(key) ); } function deepAssign(obj, prop, value) { if (_angularFix2['default'].isString(prop)) { prop = prop.replace(/\[(\w+)\]/g, '.$1').split('.'); } if (prop.length > 1) { var e = prop.shift(); obj[e] = obj[e] || isNaN(prop[0]) ? {} : []; deepAssign(obj[e], prop, value); } else { obj[prop[0]] = value; } } function parseSet(key, model, newVal) { // If either of these are null/undefined then just return undefined if (!key && key !== 0 || !model) { return; } // If we are working with a number then $parse wont work, default back to the old way for now if (shouldNotUseParseKey(key)) { // TODO: Fix this so we can get several levels instead of just one with properties that are numeric model[key] = newVal; } else if (formlyConfig.extras.parseKeyArrays && keyContainsArrays(key)) { deepAssign($scope.model, key, newVal); } else { var setter = $parse($scope.options.key).assign; if (setter) { setter($scope.model, newVal); } } } function parseGet(key, model) { // If either of these are null/undefined then just return undefined if (!key && key !== 0 || !model) { return undefined; } // If we are working with a number then $parse wont work, default back to the old way for now if (shouldNotUseParseKey(key)) { // TODO: Fix this so we can get several levels instead of just one with properties that are numeric return model[key]; } else { return $parse(key)(model); } } function simplifyLife(options) { // add a few empty objects (if they don't already exist) so you don't have to undefined check everywhere formlyUtil.reverseDeepMerge(options, { originalModel: options.model, extras: {}, data: {}, templateOptions: {}, validation: {} }); // create $scope.to so template authors can reference to instead of $scope.options.templateOptions $scope.to = $scope.options.templateOptions; $scope.formOptions = $scope.formOptions || {}; } function setFieldIdAndName() { if (_angularFix2['default'].isFunction(formlyConfig.extras.getFieldId)) { $scope.id = formlyConfig.extras.getFieldId($scope.options, $scope.model, $scope); } else { var formName = $scope.form && $scope.form.$name || $scope.formId; $scope.id = formlyUtil.getFieldId(formName, $scope.options, $scope.index); } $scope.options.id = $scope.id; $scope.name = $scope.options.name || $scope.options.id; $scope.options.name = $scope.name; } function setDefaultValue() { if (_angularFix2['default'].isDefined($scope.options.defaultValue) && !_angularFix2['default'].isDefined(parseGet($scope.options.key, $scope.model))) { parseSet($scope.options.key, $scope.model, $scope.options.defaultValue); } } function setInitialValue() { $scope.options.initialValue = $scope.model && parseGet($scope.options.key, $scope.model); } function mergeFieldOptionsWithTypeDefaults(options, type) { if (type) { mergeOptions(options, type.defaultOptions); } var properOrder = arrayify(options.optionsTypes).reverse(); // so the right things are overridden _angularFix2['default'].forEach(properOrder, function (typeName) { mergeOptions(options, formlyConfig.getType(typeName, true, options).defaultOptions); }); } function mergeOptions(options, extraOptions) { if (extraOptions) { if (_angularFix2['default'].isFunction(extraOptions)) { extraOptions = extraOptions(options, $scope); } formlyUtil.reverseDeepMerge(options, extraOptions); } } function extendOptionsWithDefaults(options, index) { var key = options.key || index || 0; _angularFix2['default'].extend(options, { // attach the key in case the formly-field directive is used directly key: key, value: options.value || valueGetterSetter, runExpressions: runExpressions, resetModel: resetModel, updateInitialValue: updateInitialValue }); } function resetModel() { parseSet($scope.options.key, $scope.model, $scope.options.initialValue); if ($scope.options.formControl) { if (_angularFix2['default'].isArray($scope.options.formControl)) { _angularFix2['default'].forEach($scope.options.formControl, function (formControl) { resetFormControl(formControl, true); }); } else { resetFormControl($scope.options.formControl); } } if ($scope.form) { $scope.form.$setUntouched && $scope.form.$setUntouched(); $scope.form.$setPristine(); } } function resetFormControl(formControl, isMultiNgModel) { if (!isMultiNgModel) { formControl.$setViewValue(parseGet($scope.options.key, $scope.model)); }