UNPKG

wfw-ngx-formly

Version:

ngx-formly is an Angular 2 module which has a Components to help customize and render JavaScript/JSON configured forms. The formly-form Component and the FormlyConfig service are very powerful and bring unmatched maintainability to your application's form

3 lines (2 loc) 30.4 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("rxjs"),require("@angular/core"),require("@angular/forms"),require("rxjs/operators"),require("@angular/common")):"function"==typeof define&&define.amd?define("wfw-ngx-formly",["exports","rxjs","@angular/core","@angular/forms","rxjs/operators","@angular/common"],t):t(e["wfw-ngx-formly"]={},e.rxjs,e.ng.core,e.ng.forms,e.Rx.Observable.prototype,e.ng.common)}(this,function(e,o,s,p,n,t){"use strict";var r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)t.hasOwnProperty(o)&&(e[o]=t[o])};function i(e,t){function o(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}function a(e,t){var o="function"==typeof Symbol&&e[Symbol.iterator];if(!o)return e;var r,n,i=o.call(e),s=[];try{for(;(void 0===t||0<t--)&&!(r=i.next()).done;)s.push(r.value)}catch(a){n={error:a}}finally{try{r&&!r.done&&(o=i["return"])&&o.call(i)}finally{if(n)throw n.error}}return s}function l(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(a(arguments[t]));return e}function f(e){if(!e._formlyKeyPath||e._formlyKeyPath.key!==e.key){var t=[];if(e.key){var o="string"==typeof e.key?e.key.split("."):e.key;try{for(var r=function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],o=0;return t?t.call(e):{next:function(){return e&&o>=e.length&&(e=void 0),{value:e&&e[o++],done:!e}}}}(o),n=r.next();!n.done;n=r.next()){"string"==typeof(s=n.value)?(s=s.replace(/\[(\w+)\]/g,".$1"),t=t.concat(s.split("."))):t.push(s)}}catch(f){l={error:f}}finally{try{n&&!n.done&&(p=r["return"])&&p.call(r)}finally{if(l)throw l.error}}for(var i=0;i<t.length;i++){var s;"string"==typeof(s=t[i])&&(!m(a=s)&&/^\d+$/.test(a))&&(t[i]=parseInt(s))}}e._formlyKeyPath={key:e.key,path:t}}var a,l,p;return e._formlyKeyPath.path.slice(0)}var u=["required","pattern","minLength","maxLength","min","max"];function d(e,t,o){for(var r=f(t),n=e,i=0;i<r.length;i++){var s=r[i];if(m(n[s])&&o&&(i<r.length-1?n[s]="number"==typeof r[i+1]?[]:{}:t.fieldGroup&&!t.fieldArray?n[s]={}:t.fieldArray&&(n[s]=[])),!(n=n[s]))break}return n}function c(e,r){e.forEach(function(t,o){!g(t.defaultValue)&&g(function e(t,o){"string"==typeof o&&(o=f({key:o}));{if(1<o.length){var r=o.shift();return t[r]||(t[r]="string"==typeof o[0]?{}:[]),e(t[r],o)}return t[o[0]]}}(r,t.key))&&h(r,t.key,t.defaultValue),t.model=r,t.key&&(t.fieldGroup||t.fieldArray)&&(t.model=d(r,t,!0)),t.fieldGroup&&c(t.fieldGroup,t.model)})}function h(e,t,o){if("string"==typeof t&&(t=f({key:t})),1<t.length){var r=t.shift();e[r]&&C(e[r])||(e[r]="string"==typeof t[0]?{}:[]),h(e[r],t,o)}else e[t[0]]=o}function y(n){for(var e=[],t=1;t<arguments.length;t++)e[t-1]=arguments[t];return e.forEach(function(e){for(var t in e)m(n[t])||""===n[t]?v(e[t])?n[t]=e[t]:n[t]=b(e[t]):(o=n[t],r=e[t],C(o)&&C(r)&&Object.getPrototypeOf(o)===Object.getPrototypeOf(r)&&y(n[t],e[t]));var o,r}),n}function m(e){return e===undefined||null===e}function g(e){return e===undefined}function v(e){return"function"==typeof e}function C(e){return null!=e&&"object"==typeof e}function b(t){return!C(t)||t instanceof RegExp||t instanceof o.Observable?t:"[object Date]"===Object.prototype.toString.call(t)?new Date(t.getTime()):Array.isArray(t)?t.slice(0).map(function(e){return b(e)}):(t=Object.assign({},t),Object.keys(t).forEach(function(e){return t[e]=b(t[e])}),t)}function F(e,t){try{return Function.bind.apply(Function,[void 0].concat(t.concat("return "+e+";")))()}catch(o){console.error(o)}}function O(e,t){try{return Function.bind.apply(Function,[void 0].concat(t.concat(e+" = expressionValue;")))()}catch(o){console.error(o)}}function E(e,t,o){return e instanceof Function?e.apply(t,o):!!e}var V=new s.InjectionToken("FORMLY_CONFIG_TOKEN"),k=function(){function e(e){void 0===e&&(e=[]);var t=this;this.types={},this.validators={},this.wrappers={},this.messages={},this.templateManipulators={preWrapper:[],postWrapper:[]},this.extras={fieldTransform:undefined,showError:function(e){return e.formControl&&e.formControl.invalid&&(e.formControl.touched||e.options.parentForm&&e.options.parentForm.submitted||e.field.validation&&e.field.validation.show)}},e.forEach(function(e){return t.addConfig(e)})}return e.prototype.addConfig=function(e){var t=this;e.types&&e.types.forEach(function(e){return t.setType(e)}),e.validators&&e.validators.forEach(function(e){return t.setValidator(e)}),e.wrappers&&e.wrappers.forEach(function(e){return t.setWrapper(e)}),e.manipulators&&e.manipulators.forEach(function(e){return t.setManipulator(e)}),e.validationMessages&&e.validationMessages.forEach(function(e){return t.addValidatorMessage(e.name,e.message)}),e.extras&&(this.extras=Object.assign({},this.extras,e.extras))},e.prototype.setType=function(t){var o=this;Array.isArray(t)?t.forEach(function(e){return o.setType(e)}):(this.types[t.name]||(this.types[t.name]={}),this.types[t.name].component=t.component,this.types[t.name].name=t.name,this.types[t.name]["extends"]=t["extends"],this.types[t.name].defaultOptions=t.defaultOptions,t.wrappers&&t.wrappers.forEach(function(e){return o.setTypeWrapper(t.name,e)}))},e.prototype.getType=function(e){if(!this.types[e])throw new Error('[Formly Error] There is no type by the name of "'+e+'"');return this.mergeExtendedType(e),this.types[e]},e.prototype.getMergedField=function(o){var r=this;void 0===o&&(o={});var e=o.type;if(!this.types[e])throw new Error('[Formly Error] There is no type by the name of "'+e+'"');this.mergeExtendedType(e),this.types[e].defaultOptions&&y(o,this.types[e].defaultOptions);var t=this.types[e]["extends"]&&this.getType(this.types[e]["extends"]).defaultOptions;t&&y(o,t),o&&o.optionsTypes&&o.optionsTypes.forEach(function(e){var t=r.getType(e).defaultOptions;t&&y(o,t)}),o.component||(o.component=this.types[e].component),o.wrappers||(o.wrappers=this.types[e].wrappers)},e.prototype.setWrapper=function(t){var o=this;(this.wrappers[t.name]=t).types&&t.types.forEach(function(e){o.setTypeWrapper(e,t.name)})},e.prototype.getWrapper=function(e){if(!this.wrappers[e])throw new Error('[Formly Error] There is no wrapper by the name of "'+e+'"');return this.wrappers[e]},e.prototype.setTypeWrapper=function(e,t){this.types[e]||(this.types[e]={}),this.types[e].wrappers||(this.types[e].wrappers=[]),this.types[e].wrappers.push(t)},e.prototype.setValidator=function(e){this.validators[e.name]=e},e.prototype.getValidator=function(e){if(!this.validators[e])throw new Error('[Formly Error] There is no validator by the name of "'+e+'"');return this.validators[e]},e.prototype.addValidatorMessage=function(e,t){this.messages[e]=t},e.prototype.getValidatorMessage=function(e){return this.messages[e]},e.prototype.setManipulator=function(e){(new e["class"])[e.method](this)},e.prototype.mergeExtendedType=function(e){if(this.types[e]["extends"]){var t=this.getType(this.types[e]["extends"]);this.types[e].component||(this.types[e].component=t.component),this.types[e].wrappers||(this.types[e].wrappers=t.wrappers)}},e}();k.decorators=[{type:s.Injectable}],k.ctorParameters=function(){return[{type:Array,decorators:[{type:s.Inject,args:[V]}]}]};var x=function(){function e(){}return e.prototype.checkFields=function(e,t,o,r){void 0===t&&(t=[]),this._checkFields(e,t,o,r)},e.prototype._checkFields=function(t,e,o,r){var n=this;void 0===e&&(e=[]),e.forEach(function(e){n.checkFieldExpressionChange(t,e,n.getParentModel(o,e),r),n.checkFieldVisibilityChange(t,e,n.getParentModel(o,e),r),e.fieldGroup&&0<e.fieldGroup.length&&n._checkFields(e.formControl?e.formControl:t,e.fieldGroup,n.getParentModel(o,e),r)})},e.prototype.checkFieldExpressionChange=function(e,t,o,r){if(t&&t.expressionProperties){var n=t.expressionProperties,i=u.map(function(e){return"templateOptions."+e});for(var s in n){var a=E(n[s].expression,{field:t},[o,r.formState]);if(n[s].expressionValue!==a&&(!C(a)||JSON.stringify(a)!==JSON.stringify(n[s].expressionValue))){if(n[s].expressionValue=a,E(n[s].expressionValueSetter,{field:t},[a,o,t]),0===s.indexOf("model.")){var l=s.replace(/^model\./,""),p=t.key&&s===l?t.formControl:e.get(l);!p||m(p.value)&&m(a)||p.value===a||p.patchValue(a)}-1!==i.indexOf(s)&&t.formControl&&t.formControl.updateValueAndValidity({emitEvent:!1})}}}},e.prototype.checkFieldVisibilityChange=function(e,t,o,r){if(t&&!m(t.hideExpression)){var n=!!E(t.hideExpression,{field:t},[o,r.formState]);if(n!==t.hide){if(t.hide=n,t.templateOptions.hidden=n,t.formControl&&t.key){var i=this.fieldParentFormControl(e,t);i&&(!0===n&&i.get(this.fieldKey(t))?this.removeFieldControl(i,t):!1!==n||i.get(this.fieldKey(t))||this.addFieldControl(i,t,o))}r.fieldChanges&&r.fieldChanges.next({field:t,type:"hidden",value:n})}}},e.prototype.addFieldControl=function(e,t,o){var r=this.getFieldModel(o,t);m(t.formControl.value)&&m(r)||t.formControl.value===r||t.formControl.patchValue(r,{emitEvent:!1}),e instanceof p.FormArray?e.push(t.formControl):e instanceof p.FormGroup&&e.addControl(this.fieldKey(t),t.formControl)},e.prototype.getFieldModel=function(e,t){return t.fieldGroup||t.fieldArray?e:d(e,t,!1)},e.prototype.getParentModel=function(e,t){return t.key&&(t.fieldGroup||t.fieldArray)?d(e,t,!0):e},e.prototype.removeFieldControl=function(e,t){e instanceof p.FormArray?e.removeAt(this.fieldKey(t)):e instanceof p.FormGroup&&e.removeControl(this.fieldKey(t))},e.prototype.fieldParentFormControl=function(e,t){var o=f(t);return o.pop(),0<o.length?e.get(o):e},e.prototype.fieldKey=function(e){return f(e).pop()},e}();x.decorators=[{type:s.Injectable}];var w=function(){function e(e,t){this.formlyConfig=e,this.formlyFormExpression=t,this.formId=0}return e.prototype.buildForm=function(t,o,r,n){void 0===o&&(o=[]);var e=n&&n.fieldTransform||this.formlyConfig.extras.fieldTransform;Array.isArray(e)||(e=[e]),e.forEach(function(e){if(e&&!(o=e(o,r,t,n)))throw new Error("fieldTransform must return an array of fields")}),c(o,r),this._buildForm(t,o,n),this.formlyFormExpression.checkFields(t,o,r,n)},e.prototype._buildForm=function(e,t,o){void 0===t&&(t=[]),this.formId++,this.registerFormControls(e,t,o)},e.prototype.registerFormControls=function(o,e,r){var l=this;e.forEach(function(n,e){if(n.id=function(e,t,o){if(t.id)return t.id;var r=t.type;return!r&&t.template&&(r="template"),[e,r,t.key,o].join("_")}("formly_"+l.formId,n,e),l.initFieldOptions(n),l.initFieldExpression(n,r),l.initFieldValidation(n),l.initFieldWrappers(n),l.initFieldAsyncValidation(n),n.key&&n.type){var i=f({key:n.key}),s=o,a=n.model;i.forEach(function(e,t){var o=e.toString();if(t===i.length-1)l.addFormControl(s,n,a,o),n.fieldArray&&(n.fieldGroup=[],n.model.forEach(function(e,t){return n.fieldGroup.push(Object.assign({},b(n.fieldArray),{key:""+t}))}),c(n.fieldGroup,a));else{var r=s.get(o);r||(r=new p.FormGroup({}),l.addControl(s,o,r)),a[e]||(a[e]="string"==typeof e?{}:[]),s=r,a=a[e]}})}var t;n.fieldGroup&&(n.type||(n.type="formly-group"),n.key?(l.addFormControl(o,n,((t={})[n.key]=n.fieldArray?[]:{},t),n.key),l._buildForm(n.formControl,n.fieldGroup,r)):(n.hideExpression&&n.fieldGroup.forEach(function(e){var o=e.hideExpression||function(){return!1};"string"==typeof o&&(o=F(o,["model","formState"])),e.hideExpression=function(e,t){return n.hide||o(e,t)}}),l._buildForm(o,n.fieldGroup,r)))})},e.prototype.initFieldExpression=function(e,t){if(e.expressionProperties)for(var o in e.expressionProperties)("string"==typeof e.expressionProperties[o]||v(e.expressionProperties[o]))&&(e.expressionProperties[o]={expression:v(e.expressionProperties[o])?e.expressionProperties[o]:F(e.expressionProperties[o],["model","formState"]),expressionValueSetter:O("field."+o,["expressionValue","model","field"])});e.hideExpression&&(delete e.hide,"string"==typeof e.hideExpression&&(e.hideExpression=F(e.hideExpression,["model","formState"])))},e.prototype.initFieldOptions=function(e){e.templateOptions=e.templateOptions||{},e.type&&(this.formlyConfig.getMergedField(e),e.key&&(e.templateOptions=Object.assign({label:"",placeholder:"",focus:!1},e.templateOptions)))},e.prototype.initFieldAsyncValidation=function(n){var t=this,o=[];if(n.asyncValidators){var e=function(r){if("validation"!==r){var t=n.asyncValidators[r];C(t)&&(t=t.expression),o.push(function(e){return new Promise(function(o){return t(e,n).then(function(e){var t;o(e?null:((t={})[r]=!0,t))})})})}};for(var r in n.asyncValidators)e(r)}n.asyncValidators&&Array.isArray(n.asyncValidators.validation)&&n.asyncValidators.validation.forEach(function(e){return o.push(t.wrapNgValidatorFn(n,e))}),o.length&&(n.asyncValidators&&!Array.isArray(n.asyncValidators.validation)?n.asyncValidators.validation=p.Validators.composeAsync(l([n.asyncValidators.validation],o)):n.asyncValidators={validation:p.Validators.composeAsync(o)})},e.prototype.initFieldValidation=function(n){var o=this,i=[];if(u.filter(function(e){return n.templateOptions&&n.templateOptions.hasOwnProperty(e)||n.expressionProperties&&n.expressionProperties["templateOptions."+e]}).forEach(function(t){i.push(function(e){return!1===n.templateOptions[t]?null:o.getValidation(t,n.templateOptions[t])(e)})}),n.validators){var e=function(o){if("validation"!==o){var r=n.validators[o];C(r)&&(r=r.expression),i.push(function(e){return r(e,n)?null:((t={})[o]=!0,t);var t})}};for(var t in n.validators)e(t)}n.validators&&Array.isArray(n.validators.validation)&&n.validators.validation.forEach(function(e){return i.push(o.wrapNgValidatorFn(n,e))}),i.length&&(n.validators&&!Array.isArray(n.validators.validation)?n.validators.validation=p.Validators.compose(l([n.validators.validation],i)):n.validators={validation:p.Validators.compose(i)})},e.prototype.addFormControl=function(e,t,o,r){var n,i={validators:t.validators?t.validators.validation:undefined,asyncValidators:t.asyncValidators?t.asyncValidators.validation:undefined,updateOn:t.modelOptions&&t.modelOptions.updateOn?t.modelOptions.updateOn:undefined};t.formControl instanceof p.AbstractControl||e.get(r)?m((n=t.formControl||e.get(r)).value)&&m(o[r])||n.value===o[r]||!(n instanceof p.FormControl)||n.patchValue(o[r]):n=t.component&&t.component.createControl?t.component.createControl(o[r],t):t.fieldGroup&&t.key&&t.key===r&&!t.fieldArray?new p.FormGroup(o[r],i):t.fieldArray&&t.key&&t.key===r?new p.FormArray([],i):new p.FormControl(o[r],i),t.templateOptions.disabled&&n.disable(),delete t.templateOptions.disabled&&Object.defineProperty(t.templateOptions,"disabled",{get:function(){return!this.formControl.enabled}.bind(t),set:function(e){this.expressionProperties&&this.expressionProperties.hasOwnProperty("templateOptions.disabled")&&(this.expressionProperties["templateOptions.disabled"].expressionValue=e),e?this.formControl.disable():this.formControl.enable()}.bind(t),enumerable:!0,configurable:!0}),this.addControl(e,r,n,t)},e.prototype.addControl=function(e,t,o,r){r&&(r.formControl=o),e instanceof p.FormArray?e.at(t)!==o&&e.setControl(t,o):e.get(t)!==o&&e.setControl(t,o)},e.prototype.getValidation=function(e,t){switch(e){case"required":return p.Validators.required;case"pattern":return p.Validators.pattern(t);case"minLength":return p.Validators.minLength(t);case"maxLength":return p.Validators.maxLength(t);case"min":return p.Validators.min(t);case"max":return p.Validators.max(t)}},e.prototype.wrapNgValidatorFn=function(t,o){return o="string"==typeof o?this.formlyConfig.getValidator(o).validation:o,function(e){return o(e,t)}},e.prototype.initFieldWrappers=function(t){var e={preWrapper:[],postWrapper:[]};t.templateOptions&&this.mergeTemplateManipulators(e,t.templateOptions.templateManipulators),this.mergeTemplateManipulators(e,this.formlyConfig.templateManipulators);var o=e.preWrapper.map(function(e){return e(t)}).filter(function(e){return e}),r=e.postWrapper.map(function(e){return e(t)}).filter(function(e){return e});t.wrappers||(t.wrappers=[]),t.wrappers=l(o,t.wrappers||[],r)},e.prototype.mergeTemplateManipulators=function(e,t){return(t=t||{}).preWrapper&&(e.preWrapper=e.preWrapper.concat(t.preWrapper)),t.postWrapper&&(e.postWrapper=e.postWrapper.concat(t.postWrapper)),e},e}();w.decorators=[{type:s.Injectable}],w.ctorParameters=function(){return[{type:k},{type:x}]};var A=function(){function e(e,t,o,r,n,i){this.formlyBuilder=e,this.formlyExpression=t,this.formlyConfig=o,this.parentForm=r,this.parentFormGroup=n,this.parentFormlyForm=i,this.model={},this.form=new p.FormGroup({}),this.fields=[],this.modelChange=new s.EventEmitter,this.modelWillChange=new s.EventEmitter,this.modelDidChange=new s.EventEmitter,this.isRoot=!0,this.modelChangeSubs=[]}return e.prototype.ngDoCheck=function(){this.checkExpressionChange()},e.prototype.ngOnChanges=function(e){this.fields&&0!==this.fields.length&&this.isRoot&&(e.fields||e.form?(this.modelWillChange.emit(),this.model=this.model||{},this.form=this.form||new p.FormGroup({}),this.setOptions(),this.clearModelSubscriptions(),this.options.components=[],this.formlyBuilder.buildForm(this.form,this.fields,this.model,this.options),this.trackModelChanges(this.fields),this.updateInitialValue(),this.modelDidChange.emit()):e.model&&(this.modelWillChange.emit(),this.patchModel(this.model),this.modelDidChange.emit()))},e.prototype.ngOnDestroy=function(){this.clearModelSubscriptions()},e.prototype.changeModel=function(e){h(this.model,e.key,e.value),this.modelChange.emit(this.model),this.checkExpressionChange()},e.prototype.setOptions=function(){var e=this;this.options=this.options||{},this.options.formState=this.options.formState||{},this.options.showError||(this.options.showError=this.formlyConfig.extras.showError),this.options.fieldChanges||(this.options.fieldChanges=new o.Subject),this.options.resetModel||(this.options.resetModel=this.resetModel.bind(this)),this.options.parentForm||(this.options.parentForm=this.parentFormGroup||this.parentForm),this.options.updateInitialValue||(this.options.updateInitialValue=this.updateInitialValue.bind(this)),this.options.resetTrackModelChanges||(this.options.resetTrackModelChanges=function(){e.clearModelSubscriptions(),e.trackModelChanges(e.fields)})},e.prototype.checkExpressionChange=function(){this.isRoot&&this.formlyExpression.checkFields(this.form,this.fields,this.model,this.options)},e.prototype.trackModelChanges=function(e,t){var r=this;void 0===t&&(t=[]),e.forEach(function(o){if(o.key&&o.type&&!o.fieldGroup&&!o.fieldArray){var e=o.formControl.valueChanges.pipe(o.modelOptions&&o.modelOptions.debounce&&o.modelOptions.debounce["default"]?n.debounceTime(o.modelOptions.debounce["default"]):n.tap(function(){}),n.map(function(t){return o.parsers&&0<o.parsers.length&&o.parsers.forEach(function(e){return t=e(t)}),t}),n.tap(function(e){return r.changeModel({key:l(t,[o.key]).join("."),value:e})}));r.modelChangeSubs.push(e.subscribe())}o.fieldGroup&&0<o.fieldGroup.length&&r.trackModelChanges(o.fieldGroup,o.key?l(t,[o.key]):t)})},e.prototype.clearModelSubscriptions=function(){this.modelChangeSubs.forEach(function(e){return e.unsubscribe()}),this.modelChangeSubs=[]},e.prototype.patchModel=function(e){this.clearModelSubscriptions(),this.resetFieldArray(this.fields,e),this.initializeFormValue(this.form),this.form.patchValue(e,{onlySelf:!0}),this.trackModelChanges(this.fields)},e.prototype.resetModel=function(e){this.modelWillChange.emit(),this.options.components.forEach(function(e){e.onBeforePatchValue&&e.onBeforePatchValue()}),e=m(e)?this.initialModel:e,this.resetFieldArray(this.fields,e),!this.parentFormlyForm&&this.options.parentForm&&this.options.parentForm.control===this.form?this.options.parentForm.resetForm(e):this.form.reset(e),this.modelDidChange.emit()},e.prototype.resetFieldArray=function(e,t){var i=this;e.forEach(function(o){if(o.fieldGroup&&0<o.fieldGroup.length||o.fieldArray){var r=d(t,o,!0);if(o.fieldArray){o.fieldGroup=o.fieldGroup||[],o.fieldGroup.length=0,o.model!==r&&o.model&&(o.model.length=0);for(var n=o.formControl;0!==n.length;)n.removeAt(0);r.forEach(function(e,t){o.model[t]=e,o.fieldGroup.push(Object.assign({},b(o.fieldArray),{key:""+t})),i.formlyBuilder.buildForm(n,[o.fieldGroup[t]],r,i.options)})}else i.resetFieldArray(o.fieldGroup,r)}else o.key&&o.type&&o.formControl.reset(d(t,o,!1))})},e.prototype.initializeFormValue=function(t){var o=this;t instanceof p.FormControl?t.setValue(null):t instanceof p.FormGroup?Object.keys(t.controls).forEach(function(e){return o.initializeFormValue(t.controls[e])}):t instanceof p.FormArray&&t.controls.forEach(function(e){return o.initializeFormValue(e)})},e.prototype.updateInitialValue=function(){this.initialModel=y({},this.model)},e}();A.decorators=[{type:s.Component,args:[{selector:"formly-form",template:'\n <formly-field *ngFor="let field of fields"\n [model]="field.model" [form]="form"\n [field]="field"\n [ngClass]="field.className"\n [options]="options">\n </formly-field>\n <ng-content></ng-content>\n '}]}],A.ctorParameters=function(){return[{type:w},{type:x},{type:k},{type:p.NgForm,decorators:[{type:s.Optional}]},{type:p.FormGroupDirective,decorators:[{type:s.Optional}]},{type:A,decorators:[{type:s.Optional},{type:s.SkipSelf}]}]},A.propDecorators={model:[{type:s.Input}],form:[{type:s.Input}],fields:[{type:s.Input}],options:[{type:s.Input}],modelChange:[{type:s.Output}],modelWillChange:[{type:s.Output}],modelDidChange:[{type:s.Output}],isRoot:[{type:s.Input}]};var P=function(){function e(e,t){this.formlyConfig=e,this.componentFactoryResolver=t,this.options={},this.modelChange=new s.EventEmitter,this.componentRefs=[]}return e.prototype.ngAfterContentInit=function(){this.lifeCycleHooks(this.lifecycle.afterContentInit)},e.prototype.ngAfterContentChecked=function(){this.lifeCycleHooks(this.lifecycle.afterContentChecked)},e.prototype.ngAfterViewInit=function(){this.lifeCycleHooks(this.lifecycle.afterViewInit)},e.prototype.ngAfterViewChecked=function(){this.lifeCycleHooks(this.lifecycle.afterViewChecked)},e.prototype.ngDoCheck=function(){this.lifeCycleHooks(this.lifecycle.doCheck)},e.prototype.ngOnInit=function(){this.field.template||this.createFieldComponent(),this.lifeCycleHooks(this.lifecycle.onInit)},e.prototype.ngOnChanges=function(e){var t=this;this.lifeCycleHooks(this.lifecycle.onChanges),this.componentRefs.forEach(function(e){Object.assign(e.instance,{model:t.model,form:t.form,field:t.field,options:t.options})})},e.prototype.ngOnDestroy=function(){this.lifeCycleHooks(this.lifecycle.onDestroy),this.componentRefs.forEach(function(e){return e.destroy()}),this.componentRefs=[]},e.prototype.createFieldComponent=function(){var o=this,e=this.formlyConfig.getType(this.field.type),r=this.fieldComponent;return(this.field.wrappers||[]).forEach(function(e){var t=o.createComponent(r,o.formlyConfig.getWrapper(e).component);r=t.instance.fieldComponent}),this.createComponent(r,e.component)},e.prototype.createComponent=function(e,t){var o=this.componentFactoryResolver.resolveComponentFactory(t),r=e.createComponent(o);Object.assign(r.instance,{model:this.model,form:this.form,field:this.field,options:this.options});var n=this.options.components;return n&&n.push(r.instance),this.componentRefs.push(r),r},Object.defineProperty(e.prototype,"lifecycle",{get:function(){return this.field.lifecycle||{}},enumerable:!0,configurable:!0}),e.prototype.lifeCycleHooks=function(e){e&&e(this.form,this.field,this.model,this.options)},e}();P.decorators=[{type:s.Component,args:[{selector:"formly-field",template:'\n <ng-template #fieldComponent></ng-template>\n <div *ngIf="field.template && !field.fieldGroup" [innerHtml]="field.template"></div>\n ',host:{"[style.display]":'field.hide ? "none":""'}}]}],P.ctorParameters=function(){return[{type:k},{type:s.ComponentFactoryResolver}]},P.propDecorators={model:[{type:s.Input}],form:[{type:s.Input}],field:[{type:s.Input}],options:[{type:s.Input}],modelChange:[{type:s.Output}],fieldComponent:[{type:s.ViewChild,args:["fieldComponent",{read:s.ViewContainerRef}]}]};var M=function(){function e(e,t){this.renderer=e,this.elementRef=t,this.attributes=["id","name","placeholder","tabindex","step","readonly"],this.statements=["change","keydown","keyup","keypress","click","focus","blur"]}return e.prototype.onFocus=function(){this.field.focus=!0},e.prototype.onBlur=function(){this.field.focus=!1},e.prototype.ngOnChanges=function(e){var t=this;if(e.field){var o=e.field;if(this.attributes.filter(function(e){return t.canApplyRender(o,e)}).forEach(function(e){return t.renderer.setAttribute(t.elementRef.nativeElement,e,t.getPropValue(t.field,e))}),this.field.templateOptions&&this.field.templateOptions.attributes){var r=this.field.templateOptions.attributes;Object.keys(r).forEach(function(e){return t.renderer.setAttribute(t.elementRef.nativeElement,e,r[e])})}this.statements.filter(function(e){return t.canApplyRender(o,e)}).forEach(function(e){return t.renderer.listen(t.elementRef.nativeElement,e,t.getStatementValue(e))}),(o.previousValue||{}).focus!==(o.currentValue||{}).focus&&this.elementRef.nativeElement.focus&&this.elementRef.nativeElement[this.field.focus?"focus":"blur"]()}},e.prototype.getPropValue=function(e,t){return(e=e||{}).templateOptions&&e.templateOptions[t]?e.templateOptions[t]:e[t]||""},e.prototype.getStatementValue=function(e){var t=this,o=this.field.templateOptions[e];return function(e){return o(t.field,e)}},e.prototype.canApplyRender=function(e,t){var o=this.getPropValue(this.field,t);return this.getPropValue(e.previousValue,t)!==o&&(-1===this.statements.indexOf(t)||"function"==typeof o)},e}();M.decorators=[{type:s.Directive,args:[{selector:"[formlyAttributes]"}]}],M.ctorParameters=function(){return[{type:s.Renderer2},{type:s.ElementRef}]},M.propDecorators={field:[{type:s.Input,args:["formlyAttributes"]}],onFocus:[{type:s.HostListener,args:["focus"]}],onBlur:[{type:s.HostListener,args:["blur"]}]};var G=function(){function e(){}return Object.defineProperty(e.prototype,"key",{get:function(){return this.field.key},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"formControl",{get:function(){return this.field.formControl},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"to",{get:function(){return this.field.templateOptions},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"showError",{get:function(){return this.options.showError(this)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"id",{get:function(){return this.field.id},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"formState",{get:function(){return this.options.formState||{}},enumerable:!0,configurable:!0}),e.prototype.onBeforePatchValue=function(){},e}();G.propDecorators={form:[{type:s.Input}],field:[{type:s.Input}],model:[{type:s.Input}],options:[{type:s.Input}]};var j=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t.prototype.ngOnInit=function(){},t.prototype.ngOnChanges=function(e){},t.prototype.ngDoCheck=function(){},t.prototype.ngAfterContentInit=function(){},t.prototype.ngAfterContentChecked=function(){},t.prototype.ngAfterViewInit=function(){},t.prototype.ngAfterViewChecked=function(){},t.prototype.ngOnDestroy=function(){},t}(G),I=function(o){function e(e){var t=o.call(this)||this;return t.builder=e,t}return i(e,o),e.prototype.add=function(e,t){e=m(e)?this.field.fieldGroup.length:e,this.model.splice(e,0,t?b(t):undefined),this.field.fieldGroup.splice(e,0,Object.assign({},b(this.field.fieldArray))),this.field.fieldGroup.forEach(function(e,t){e.key=""+t});var o=new p.FormArray([]);this.builder.buildForm(o,[this.field.fieldGroup[e]],this.model,this.options),this.formControl.insert(e,o.at(0)),this.options.resetTrackModelChanges()},e.prototype.remove=function(e){this.formControl.removeAt(e),this.field.fieldGroup.splice(e,1),this.field.fieldGroup.forEach(function(e,t){return e.key=""+t}),this.model.splice(e,1),this.options.resetTrackModelChanges()},e}(j),T=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t}(G),S=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t}(j);S.decorators=[{type:s.Component,args:[{selector:"formly-group",template:'\n <formly-form\n [fields]="field.fieldGroup"\n [isRoot]="false"\n [model]="model"\n [form]="field.formControl || form"\n [options]="options"\n [ngClass]="field.fieldGroupClassName">\n <ng-content></ng-content>\n </formly-form>\n '}]}];var R=function(){function e(e){this.formlyConfig=e}return Object.defineProperty(e.prototype,"fieldForm",{set:function(e){console.warn("formly-validation-message: Passing 'fieldForm' input is deprecated and it will be removed in the 4.0 version.")},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"errorMessage",{get:function(){var e=this.field.formControl;for(var t in e.errors)if(e.errors.hasOwnProperty(t)){var o=this.formlyConfig.getValidatorMessage(t);return this.field.validation&&this.field.validation.messages&&this.field.validation.messages[t]&&(o=this.field.validation.messages[t]),this.field.validators&&this.field.validators[t]&&this.field.validators[t].message&&(o=this.field.validators[t].message),this.field.asyncValidators&&this.field.asyncValidators[t]&&this.field.asyncValidators[t].message&&(o=this.field.asyncValidators[t].message),"function"==typeof o?o(e.errors[t],this.field):o}},enumerable:!0,configurable:!0}),e}();R.decorators=[{type:s.Component,args:[{selector:"formly-validation-message",template:"{{ errorMessage }}"}]}],R.ctorParameters=function(){return[{type:k}]},R.propDecorators={field:[{type:s.Input}],fieldForm:[{type:s.Input}]};var _=function(){function t(){}return t.forRoot=function(e){return void 0===e&&(e={}),{ngModule:t,providers:[w,x,k,{provide:V,useValue:{types:[{name:"formly-group",component:S}]},multi:!0},{provide:V,useValue:e,multi:!0},{provide:s.ANALYZE_FOR_ENTRY_COMPONENTS,useValue:e,multi:!0}]}},t.forChild=function(e){return void 0===e&&(e={}),{ngModule:t,providers:[{provide:V,useValue:e,multi:!0},{provide:s.ANALYZE_FOR_ENTRY_COMPONENTS,useValue:e,multi:!0}]}},t}();_.decorators=[{type:s.NgModule,args:[{declarations:[A,P,M,S,R],entryComponents:[S],exports:[A,P,M,S,R],imports:[t.CommonModule,p.ReactiveFormsModule]}]}],e.FormlyForm=A,e.FormlyField=P,e.FormlyAttributes=M,e.FormlyConfig=k,e.FormlyFormBuilder=w,e.Field=G,e.FieldType=j,e.FieldArrayType=I,e.FieldWrapper=T,e.FormlyModule=_,e.ɵc=S,e.ɵa=V,e.ɵb=x,e.ɵd=R,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=wfw-ngx-formly.umd.min.js.map