@stemy/ngx-dynamic-form 10.2.26 → 10.2.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/stemy-ngx-dynamic-form.umd.js +4 -2
- package/bundles/stemy-ngx-dynamic-form.umd.js.map +1 -1
- package/bundles/stemy-ngx-dynamic-form.umd.min.js +1 -1
- package/bundles/stemy-ngx-dynamic-form.umd.min.js.map +1 -1
- package/esm2015/ngx-dynamic-form/services/dynamic-form.service.js +5 -3
- package/fesm2015/stemy-ngx-dynamic-form.js +4 -2
- package/fesm2015/stemy-ngx-dynamic-form.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@stemy/ngx-utils"),require("rxjs"),require("@angular/core"),require("@angular/forms"),require("@ng-dynamic-forms/core"),require("rxjs/operators"),require("@angular/common")):"function"==typeof define&&define.amd?define("@stemy/ngx-dynamic-form",["exports","@stemy/ngx-utils","rxjs","@angular/core","@angular/forms","@ng-dynamic-forms/core","rxjs/operators","@angular/common"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).stemy=e.stemy||{},e.stemy["ngx-dynamic-form"]={}),e.ngxUtils,e.rxjs,e.ng.core,e.ng.forms,e.core,e.rxjs.operators,e.ng.common)}(this,(function(e,t,r,n,o,i,a,s){"use strict";var u=[],l=function(){return Promise.resolve(!1)};function c(e,t){var r=t.get(e);return r?r.value:null}function p(e,r,n){t.ReflectUtils.defineMetadata("dynamicFormControl",n,e,r)}function m(e){return t.ReflectUtils.getMetadata("dynamicFormFieldSets",e)||{}}function f(e,r,n){return(n=n||{}).label=t.ObjectUtils.isNullOrUndefined(n.label)?e:n.label,n.labelAlign=n.labelAlign||"left",n.fieldSet=n.fieldSet||t.UniqueUtils.uuid(),n.classes=n.classes||"",n.readonly=n.readonly||l,n.hidden=n.hidden||l,n.validators=n.validators||u,{id:e,type:r,data:n}}function h(e,t,r){void 0===r&&(r="text");var n=f(e,"input",t);return(t=n.data).type=t.type||r,t.classes=t.classes?t.classes+" form-group-"+t.type:"form-group-"+t.type,t.placeholder=t.placeholder||("mask"==t.type?"_":""),t.step=t.step||1,t.mask=t.mask||[/\w*/gi],n}function d(e,t){var r=f(e,"select",t);(t=r.data).options=t.options||[],t.type=t.type||"select";var n="select"==t.type?"select":"select-"+t.type;return t.classes=t.classes?t.classes+" form-group-"+n:"form-group-"+n,r}function y(e,t){var r=f(e,"static",t);return(t=r.data).style=t.style||"table",r}function g(e,t){var r=f(e,"model",t);return(t=r.data).name=t.name||"",r}function v(e){var t=e.value;if(!t)return null;try{return JSON.parse(t),null}catch(e){return{json:!0}}}function b(e){var t=e.value;return t&&0!=t.length&&t.findIndex((function(e){return("de"==e.lang||"en"==e.lang)&&!e.translation}))<0?null:{requiredTranslation:!0}}function C(e){var t=e.value;if(!t)return Promise.resolve(null);return/^(?:\d){10,12}$/.test(t)?null:{phone:!0}}function S(e){return function(t){var r=t.value;return Array.isArray(r)&&r.every((function(t){return"string"==typeof t&&t.length>=e}))?null:{itemsMinLength:e}}}function F(e){return function(t){var r=t.value;return Array.isArray(r)&&r.every((function(t){return"string"==typeof t&&t.length<=e}))?null:{itemsMaxLength:e}}}function O(e){return function(t){var r=t.value;return Array.isArray(r)&&r.every((function(t){return"number"==typeof t&&t>=e}))?null:{itemsMinValue:e}}}function D(e){return function(t){var r=t.value;return Array.isArray(r)&&r.every((function(t){return"number"==typeof t&&t<=e}))?null:{itemsMaxValue:e}}}var A=function(e,t){return A=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},A(e,t)};function w(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}A(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function x(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))}function M(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}Object.create;function E(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function j(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a}function N(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(j(arguments[t]));return e}Object.create;var R=function(e){function t(t){var r=e.call(this)||this;return r.notifyCallback=t,r}return w(t,e),t.prototype.handleNotifiedValue=function(e,t,r){var n=this;r.then((function(e){return n.next(e)}))},t.prototype.notify=function(e,t){for(var r=e;r&&isNaN(r.index);)r=r.parent;var n=this.notifyCallback(e,t,null==r?void 0:r.index);n instanceof Promise||(n=Promise.resolve(n)),this.handleNotifiedValue(e,t,n)},t}(r.Subject),V=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return w(t,e),t.prototype.handleNotifiedValue=function(e,t,r){var n=this;r.then((function(r){var o,i;n.next(r);var a=t.value;if(e.multiple){var s=(a||[]).filter((function(e){return r.findIndex((function(t){return t.value==e}))>=0}));s.length!==(null==a?void 0:a.length)&&t.setValue(s,{onlySelf:!0,emitEvent:!1})}else{r.find((function(e){return e.value==a}))||t.setValue(null!==(i=null===(o=r[0])||void 0===o?void 0:o.value)&&void 0!==i?i:null,{onlySelf:!0,emitEvent:!1})}}))},t}(R);function I(e){return"string"==typeof e&&e.length>0}var T=function(e){function t(t,r){var n=e.call(this,t,r)||this;return n.additional=t.additional||{},n}return w(t,e),t}(i.DynamicFormArrayModel),U=function(e){function a(t,r,o){var i=e.call(this,t,r)||this;return i.openApi=o,i.onDetectChanges=new n.EventEmitter,i}return w(a,e),Object.defineProperty(a.prototype,"api",{get:function(){return this.openApi.api},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"language",{get:function(){return this.api.language},enumerable:!1,configurable:!0}),a.prototype.patchGroup=function(e,r,n){this.patchValueRecursive(e,r,n),this.detectChanges(),n.patchValue(t.ObjectUtils.copy(e))},a.prototype.patchForm=function(e,t){this.patchValueRecursive(e,t.model,t.group),this.detectChanges(t),t.group.patchValue(e)},a.prototype.serialize=function(e,t){return this.serializeRecursive(e,t)},a.prototype.notifyChanges=function(e,t){this.notifyChangesRecursive(e,t)},a.prototype.updateSelectOptions=function(e,t){if(e instanceof i.DynamicSelectModel){var n=e.options$;if(n instanceof R)return void n.notify(e,t);for(;n instanceof r.Subject&&n.source;)(n=n.source)instanceof R&&n.notify(e,t)}},a.prototype.showErrors=function(e){this.showErrorsForGroup(e.group),this.detectChanges(e)},a.prototype.detectChanges=function(t){e.prototype.detectChanges.call(this,t),this.onDetectChanges.emit(t)},a.prototype.patchValueRecursive=function(e,r,n){var o=this;Object.keys(e).forEach((function(a){var s=o.findModelById(a,r),u=e[a];if(s){var l=o.findControlByModel(s,n);if(s instanceof i.DynamicSelectModel&&t.ObjectUtils.isObject(u))e[a]=u.id||u._id||u;else if(s instanceof i.DynamicFormArrayModel){for(var c=Array.isArray(u)?u.length:0,p=l;s.size>c;)o.removeFormArrayGroup(0,p,s);for(;s.size<c;)o.insertFormArrayGroup(s.size,p,s);for(var m=0;m<c;m++){var f=s.get(m);o.patchValueRecursive(u[m],f.group,p.at(m))}}else s instanceof i.DynamicFormGroupModel&&o.patchValueRecursive(u,s.group,l)}}))},a.prototype.serializeRecursive=function(e,r){var n,o;return x(this,void 0,void 0,(function(){var a,s,u,l,c,p,m,f,h,d,y,g,v,b,C,S,F,O,D;return M(this,(function(A){switch(A.label){case 0:if(a={},!e||!r||!r.value)return[2,a];for(u in s=[],e)s.push(u);l=0,A.label=1;case 1:return l<s.length?(c=s[l],p=e[c],m=this.findControlByModel(p,r),f=null===(n=p.additional)||void 0===n?void 0:n.serializer,t.ObjectUtils.isFunction(f)?(h=a,d=p.id,[4,f(p,m)]):[3,3]):[3,12];case 2:return h[d]=A.sent(),[3,11];case 3:if(!(p instanceof i.DynamicFormArrayModel))return[3,8];y=Array.isArray(m.value)?m.value.length:0,g=m,v=[],b=0,A.label=4;case 4:return b<y?(C=p.get(b),F=(S=v).push,[4,this.serializeRecursive(C.group,g.at(b))]):[3,7];case 5:F.apply(S,[A.sent()]),A.label=6;case 6:return b++,[3,4];case 7:return a[p.id]=v,[3,11];case 8:return p instanceof i.DynamicFormGroupModel?(O=a,D=p.id,[4,this.serializeRecursive(p.group,m)]):[3,10];case 9:return O[D]=A.sent(),[3,11];case 10:if(p instanceof i.DynamicInputModel&&!t.ObjectUtils.isNullOrUndefined(m.value))return a[p.id]="number"==p.inputType?null!==(o=parseFloat((""+m.value||"0").replace(/,/gi,".")))&&void 0!==o?o:null:m.value,[3,11];a[p.id]=m.value,A.label=11;case 11:return l++,[3,1];case 12:return[2,a]}}))}))},a.prototype.notifyChangesRecursive=function(e,t){if(e&&t)for(var r in e){var n=e[r],o=this.findControlByModel(n,t);if(n instanceof i.DynamicFormArrayModel)for(var a=Array.isArray(o.value)?o.value.length:0,s=o,u=0;u<a;u++){var l=n.get(u);this.notifyChangesRecursive(l.group,s.at(u))}else n instanceof i.DynamicFormGroupModel?this.notifyChangesRecursive(n.group,o):this.updateSelectOptions(n,o)}},a.prototype.showErrorsForGroup=function(e){if(e){e.markAsTouched({onlySelf:!0});var t=Object.keys(e.controls).map((function(t){return e.controls[t]}));this.showErrorsForControls(t)}},a.prototype.showErrorsForControls=function(e){var t=this;e.forEach((function(e){e instanceof o.FormGroup?t.showErrorsForGroup(e):(e.markAsTouched({onlySelf:!0}),e instanceof o.FormArray&&t.showErrorsForControls(e.controls))}))},a.prototype.getFormModelForSchema=function(e){return x(this,void 0,void 0,(function(){var t;return M(this,(function(r){switch(r.label){case 0:return this.api.cache={},t=this,[4,this.openApi.getSchemas()];case 1:return t.schemas=r.sent(),[2,this.getFormModelForSchemaDef(this.schemas[e])]}}))}))},a.prototype.getFormModelForSchemaDef=function(e){var t=this;return e?Object.keys(e.properties||{}).map((function(r){var n=e.properties[r];return t.getFormControlModel(n,e)})).filter((function(e){return null!==e})):[]},a.prototype.getFormControlModel=function(e,t){var r,n,o=(null===(r=e.items)||void 0===r?void 0:r.enum)||e.enum;if(Array.isArray(o)||I(e.optionsPath)||I(e.endpoint))return new i.DynamicSelectModel(this.getFormSelectConfig(e,t));switch(e.type){case"string":case"number":case"integer":return new i.DynamicInputModel(this.getFormInputConfig(e,t));case"textarea":return new i.DynamicTextAreaModel(this.getFormTextareaConfig(e,t));case"boolean":return new i.DynamicCheckboxModel(this.getFormCheckboxConfig(e,t));case"array":return(null===(n=e.items)||void 0===n?void 0:n.$ref)||e.$ref?new T(this.getFormArrayConfig(e,t)):new i.DynamicInputModel(this.getFormInputConfig(e,t));case"file":return new i.DynamicFileUploadModel(this.getFormUploadConfig(e,t))}return e.$ref?new i.DynamicFormGroupModel(this.getFormGroupConfig(e,t)):null},a.prototype.getFormControlConfig=function(e,r){var n=this.getValidators(e,r),o=Object.keys(n).reduce((function(e,t){return e[t]="error."+t,e}),{});return{id:e.id,label:t.ObjectUtils.isString(e.label)?e.label:e.id,hidden:e.hidden,disabled:e.disabled,validators:n,errorMessages:o,additional:Object.assign({},e)}},a.prototype.getFormArrayConfig=function(e,t){var r,n=this,o=(null===(r=e.items)||void 0===r?void 0:r.$ref)||e.$ref||"",i=this.schemas[o.split("/").pop()];return Object.assign(this.getFormControlConfig(e,t),{groupFactory:function(){return n.getFormModelForSchemaDef(i)}})},a.prototype.getFormGroupConfig=function(e,t){var r=e.$ref||"",n=this.schemas[r.split("/").pop()];return Object.assign(this.getFormControlConfig(e,t),{group:this.getFormModelForSchemaDef(n)})},a.prototype.getFormInputConfig=function(e,r){var n,o=t.StringUtils.has(e.id,"password","Password")?"password":(null===(n=e.items)||void 0===n?void 0:n.type)||e.type;switch(o){case"boolean":o="checkbox";break;case"textarea":o="textarea";break;case"integer":o="number"}var i="array"==e.type&&e.items||e;return Object.assign(this.getFormControlConfig(e,r),{inputType:o,autoComplete:e.autoComplete||"off",multiple:"array"==e.type,accept:t.ObjectUtils.isString(e.accept)?e.accept:null,mask:t.ObjectUtils.isString(e.mask)?e.mask:null,pattern:t.ObjectUtils.isString(e.pattern)?e.pattern:null,step:isNaN(i.step)?isNaN(e.step)?1:e.step:i.step,min:isNaN(i.minimum)?isNaN(i.minLength)?Number.MIN_SAFE_INTEGER:i.minLength:i.minimum,max:isNaN(i.maximum)?isNaN(i.maxLength)?Number.MAX_SAFE_INTEGER:i.maxLength:i.maximum})},a.prototype.getFormTextareaConfig=function(e,t){return Object.assign(this.getFormControlConfig(e,t),{cols:e.cols||null,rows:e.rows||10,wrap:e.wrap||!1,autoComplete:e.autoComplete||"off",multiple:"array"==e.type})},a.prototype.getFormSelectConfig=function(e,t){return Object.assign(this.getFormControlConfig(e,t),{options:this.getFormSelectOptions(e,t),multiple:"array"==e.type})},a.prototype.getFormCheckboxConfig=function(e,t){return Object.assign(this.getFormControlConfig(e,t),{indeterminate:!0===e.indeterminate})},a.prototype.translateOptions=function(e){return x(this,void 0,void 0,(function(){var t,r,n,o,i,a,s;return M(this,(function(u){switch(u.label){case 0:if(!e)return[2,[]];u.label=1;case 1:u.trys.push([1,6,7,8]),t=E(e),r=t.next(),u.label=2;case 2:return r.done?[3,5]:(n=r.value,o=n,[4,this.language.getTranslation(n.label)]);case 3:o.label=u.sent(),u.label=4;case 4:return r=t.next(),[3,2];case 5:return[3,8];case 6:return i=u.sent(),a={error:i},[3,8];case 7:try{r&&!r.done&&(s=t.return)&&s.call(t)}finally{if(a)throw a.error}return[7];case 8:return[2,e]}}))}))},a.prototype.getFormSelectOptions=function(e,r){var n,o=this,i=(null===(n=e.items)||void 0===n?void 0:n.enum)||e.enum;return Array.isArray(i)?new V((function(){var t=i.map((function(t){return{value:t,label:e.translatable?e.id+"."+t:t}}));return o.translateOptions(t)})):I(e.optionsPath)?new V((function(r,n,i){var a=e.optionsPath,s=n;if(a.startsWith("$root"))for(a=a.substr(5);s.parent;)s=s.parent;for(;a.startsWith(".");)a=a.substr(1),s.parent&&(s=s.parent);var u=t.ObjectUtils.getValue(s.value,a.replace(/\$ix/gi,i)),l=(t.ObjectUtils.isArray(u)?u:[]).map((function(e){return{value:e,label:e}}));return o.translateOptions(l)})):new V((function(){return x(o,void 0,void 0,(function(){var t;return M(this,(function(r){switch(r.label){case 0:return this.api.cache[e.endpoint]=this.api.cache[e.endpoint]||this.api.list(e.endpoint,this.api.makeListParams(1,-1)).then((function(t){return t.items.map((function(t){return{value:t.id||t._id,label:t[e.labelField]||t.label||t.id||t._id}}))})),[4,this.api.cache[e.endpoint]];case 1:return t=r.sent().map((function(e){return Object.assign({},e)})),[2,this.translateOptions(t)]}}))}))}))},a.prototype.getFormUploadConfig=function(e,t){var r=this.api.url(e.url||"assets"),n=e.accept,o=e.autoUpload,i=e.maxSize,a=e.minSize,s=e.removeUrl,u=e.showFileList;return Object.assign(this.getFormControlConfig(e,t),{url:r,accept:n,autoUpload:o,maxSize:i,minSize:a,removeUrl:s,showFileList:u})},a.prototype.getValidators=function(e,r){var n={};return t.ObjectUtils.isArray(r.required)&&r.required.indexOf(e.id)>=0&&(n.required=null),this.addPropertyValidators(n,e),this.addItemsValidators(n,e.items),n},a.prototype.addPropertyValidators=function(e,t){if(t&&(isNaN(t.minLength)||(e.minLength=t.minLength),isNaN(t.maxLength)||(e.maxLength=t.maxLength),isNaN(t.minimum)||(e.min=t.minimum),isNaN(t.maximum)||(e.max=t.maximum),"email"===t.format))e.email=null},a.prototype.addItemsValidators=function(e,t){t&&(isNaN(t.minLength)||(e.itemsMinLength=t.minLength),isNaN(t.maxLength)||(e.itemsMaxLength=t.maxLength),isNaN(t.minimum)||(e.itemsMinValue=t.minimum),isNaN(t.maximum)||(e.itemsMaxValue=t.maximum))},a}(i.DynamicFormService);U.decorators=[{type:n.Injectable}],U.ctorParameters=function(){return[{type:i.DynamicFormComponentService},{type:i.DynamicFormValidationService},{type:t.OpenApiService}]};var L=function(){function e(e,t,r,o){this.toaster=e,this.cdr=t,this.elem=r,this.renderer=o,this.onSuccess=new n.EventEmitter,this.onError=new n.EventEmitter,"BUTTON"===r.nativeElement.tagName&&o.setAttribute(r.nativeElement,"type","button")}return Object.defineProperty(e.prototype,"isDisabled",{get:function(){return this.disabled},set:function(e){this.disabled=e,e?this.renderer.setAttribute(this.elem.nativeElement,"disabled","disabled"):this.renderer.removeAttribute(this.elem.nativeElement,"disabled")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isLoading",{get:function(){return this.loading},enumerable:!1,configurable:!0}),e.prototype.ngOnInit=function(){var e=this;this.form&&(this.isDisabled="VALID"!==this.form.status,this.cdr.detectChanges(),this.onStatusChange=this.form.onStatusChange.subscribe((function(){e.isDisabled="VALID"!==e.form.status,e.cdr.detectChanges(),e.callback&&"PENDING"!=e.form.status&&(e.disabled||e.callback(),e.callback=null)})),this.onSubmit=this.form.onSubmit.subscribe((function(){return e.callMethod()})))},e.prototype.ngOnDestroy=function(){this.onStatusChange&&this.onStatusChange.unsubscribe(),this.onSubmit&&this.onSubmit.unsubscribe()},e.prototype.click=function(){var e=this;this.callback=function(){return e.callMethod()},"VALID"!==this.form.status&&"INVALID"!==this.form.status||(this.callback(),this.callback=null)},e.prototype.callMethod=function(){var e=this;this.loading||(this.loading=!0,this.method(this.form,this.context).then((function(t){e.loading=!1,t&&(e.onSuccess.emit(t),e.toaster.success(t.message,t.context))}),(function(t){if(!t||!t.message)throw new Error("Reason must implement IAsyncMessage interface");e.loading=!1,e.onError.emit(t),e.toaster.error(t.message,t.context)})))},e}();L.decorators=[{type:n.Directive,args:[{selector:"[async-submit]",exportAs:"async-submit"}]}],L.ctorParameters=function(){return[{type:void 0,decorators:[{type:n.Inject,args:[t.TOASTER_SERVICE]}]},{type:n.ChangeDetectorRef},{type:n.ElementRef},{type:n.Renderer2}]},L.propDecorators={method:[{type:n.Input,args:["async-submit"]}],form:[{type:n.Input}],context:[{type:n.Input}],onSuccess:[{type:n.Output}],onError:[{type:n.Output}],isDisabled:[{type:n.HostBinding,args:["class.disabled"]}],isLoading:[{type:n.HostBinding,args:["class.loading"]}],click:[{type:n.HostListener,args:["click"]}]};var k=function(e){function o(t,o,i,a){var s=e.call(this,i,a)||this;return s.formService=t,s.events=o,s.blur=new n.EventEmitter,s.change=new n.EventEmitter,s.focus=new n.EventEmitter,s.onStatusChange=new n.EventEmitter,s.onValueChange=new n.EventEmitter,s.onSubmit=new n.EventEmitter,s.templates=new n.QueryList,s.subscription=new r.Subscription,s.groupSubscription=new r.Subscription,s.labelPrefix="label",s}return w(o,e),Object.defineProperty(o.prototype,"status",{get:function(){return this.group?this.group.status:null},enumerable:!1,configurable:!0}),o.prototype.ngOnChanges=function(e){var r=this;this.groupSubscription.unsubscribe(),this.group&&(this.groupSubscription=t.ObservableUtils.multiSubscription(this.group.statusChanges.subscribe((function(){r.onStatusChange.emit(r)})),this.group.valueChanges.subscribe((function(){r.onValueChange.emit(r),r.formService.notifyChanges(r.model,r.group)}))))},o.prototype.ngAfterViewInit=function(){var e=this;this.subscription=t.ObservableUtils.multiSubscription(t.ObservableUtils.subscribe({subjects:[this.contentTemplates.changes,this.viewTemplates.changes],cb:function(){var t=e.contentTemplates.toArray().concat(e.viewTemplates.toArray());e.templates.reset(t)}}),this.events.languageChanged.subscribe((function(){e.formService.detectChanges(e)})),this.ngForm.ngSubmit.subscribe((function(){e.onSubmit.emit(e)})))},o.prototype.ngOnDestroy=function(){e.prototype.ngOnDestroy.call(this),this.subscription.unsubscribe(),this.groupSubscription.unsubscribe()},o.prototype.insertFormArrayGroup=function(e,t,r){this.formService.insertFormArrayGroup(e,t,r),this.changeDetectorRef.detectChanges()},o.prototype.removeFormArrayGroup=function(e,t,r){this.formService.removeFormArrayGroup(e,t,r),this.changeDetectorRef.detectChanges()},o.prototype.moveFormArrayGroup=function(e,t,r,n){this.formService.moveFormArrayGroup(e,t,r,n),this.changeDetectorRef.detectChanges()},o.prototype.clearFormArray=function(e,t){this.formService.clearFormArray(e,t),this.changeDetectorRef.detectChanges()},o.prototype.validate=function(e){var t=this;return void 0===e&&(e=!0),this.group?new Promise((function(r,n){t.group.statusChanges.pipe(a.first((function(e){return"VALID"==e||"INVALID"==e}))).subscribe((function(o){e&&t.formService.showErrors(t),"VALID"!=o?n(null):r(null)})),t.group.updateValueAndValidity()})):Promise.resolve()},o.prototype.serialize=function(e){return x(this,void 0,void 0,(function(){return M(this,(function(t){switch(t.label){case 0:return this.group?e?[4,this.validate()]:[3,2]:[2,null];case 1:t.sent(),t.label=2;case 2:return[4,this.formService.serialize(this.model,this.group)];case 3:return[2,t.sent()]}}))}))},o}(i.DynamicFormComponent);k.decorators=[{type:n.Component,args:[{selector:"dynamic-base-form",template:"",changeDetection:n.ChangeDetectionStrategy.Default}]}],k.ctorParameters=function(){return[{type:U,decorators:[{type:n.Inject,args:[U]}]},{type:t.EventsService,decorators:[{type:n.Inject,args:[t.EventsService]}]},{type:n.ChangeDetectorRef},{type:i.DynamicFormComponentService}]},k.propDecorators={group:[{type:n.Input}],model:[{type:n.Input}],layout:[{type:n.Input}],labelPrefix:[{type:n.Input}],blur:[{type:n.Output}],change:[{type:n.Output}],focus:[{type:n.Output}],contentTemplates:[{type:n.ContentChildren,args:[i.DynamicTemplateDirective]}],viewTemplates:[{type:n.ViewChildren,args:[i.DynamicTemplateDirective]}],onStatusChange:[{type:n.Output}],onValueChange:[{type:n.Output}],onSubmit:[{type:n.Output}],ngForm:[{type:n.ViewChild,args:[o.NgForm]}]};var P=function(e){function r(t,r,o,i,a,s,u){var l=e.call(this,r,o,i,a,s,u)||this;return l.form=t,l.changeDetectorRef=r,l.componentFactoryResolver=o,l.layoutService=i,l.validationService=a,l.componentService=s,l.relationService=u,l.context=null,l.blur=new n.EventEmitter,l.change=new n.EventEmitter,l.focus=new n.EventEmitter,l}return w(r,e),Object.defineProperty(r.prototype,"componentType",{get:function(){var e;return null!==(e=this.componentService.getCustomComponentType(this.model))&&void 0!==e?e:this.getComponentType(this.model)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"startTemplate",{get:function(){return this.model.type==i.DYNAMIC_FORM_CONTROL_TYPE_ARRAY?this.layoutService.getAlignedTemplate(this.model,this.templates,"ARRAY_START"):this.layoutService.getStartTemplate(this.model,this.templates)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"endTemplate",{get:function(){return this.model.type==i.DYNAMIC_FORM_CONTROL_TYPE_ARRAY?this.layoutService.getAlignedTemplate(this.model,this.templates,"ARRAY_END"):this.layoutService.getEndTemplate(this.model,this.templates)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"formService",{get:function(){return this.form.formService},enumerable:!1,configurable:!0}),r.prototype.ngOnInit=function(){var e=this;this.onDetectChanges=this.formService.onDetectChanges.subscribe((function(t){t===e.form&&(e.changeDetectorRef.detectChanges(),e.formService.updateSelectOptions(e.model,e.control))}))},r.prototype.ngOnDestroy=function(){e.prototype.ngOnDestroy.call(this),this.onDetectChanges.unsubscribe()},r.prototype.createFormControlComponent=function(){var r;e.prototype.createFormControlComponent.call(this);var n=null===(r=this.componentRef)||void 0===r?void 0:r.instance;n&&t.ObjectUtils.isFunction(n.onCreated)&&n.onCreated()},r.prototype.getComponentType=function(e){return null},r}(i.DynamicFormControlContainerComponent);P.decorators=[{type:n.Component,args:[{selector:"dynamic-base-form-control",template:"",changeDetection:n.ChangeDetectionStrategy.OnPush}]}],P.ctorParameters=function(){return[{type:k},{type:n.ChangeDetectorRef},{type:n.ComponentFactoryResolver},{type:i.DynamicFormLayoutService},{type:i.DynamicFormValidationService},{type:i.DynamicFormComponentService},{type:i.DynamicFormRelationService}]},P.propDecorators={contentTemplateList:[{type:n.ContentChildren,args:[i.DynamicTemplateDirective]}],klass:[{type:n.HostBinding,args:["class"]}],context:[{type:n.Input}],group:[{type:n.Input}],hostClass:[{type:n.Input}],inputTemplateList:[{type:n.Input,args:["templates"]}],layout:[{type:n.Input}],model:[{type:n.Input}],blur:[{type:n.Output}],change:[{type:n.Output}],focus:[{type:n.Output}],componentViewContainerRef:[{type:n.ViewChild,args:["componentViewContainer",{read:n.ViewContainerRef,static:!0}]}]};var _=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return w(t,e),t.prototype.showErrorMessages=function(t,r,n){return e.prototype.showErrorMessages.call(this,t,r,n)},t}(i.DynamicFormValidationService);_.decorators=[{type:n.Injectable}];var G=[k,P],z=[L],q=[],B=v,$=b,Y=S,H=F,J=O,W=D,Q=new Map([["json",v],["requiredTranslation",b],["phone",C],["itemsMinLength",S],["itemsMaxLength",F],["itemsMinValue",O],["itemsMaxValue",D]]),X=function(){function e(){}return e.forRoot=function(){return{ngModule:e,providers:[U,_,{provide:i.DynamicFormService,useExisting:U},{provide:i.DynamicFormValidationService,useExisting:_}]}},e}();X.decorators=[{type:n.NgModule,args:[{declarations:N(G,z,q),imports:[s.CommonModule,o.FormsModule,o.ReactiveFormsModule,t.NgxUtilsModule],exports:N(G,z,q,[o.FormsModule,o.ReactiveFormsModule,t.NgxUtilsModule]),entryComponents:G,providers:N(q,[{provide:o.NG_VALIDATORS,useValue:B,multi:!0},{provide:o.NG_VALIDATORS,useValue:$,multi:!0},{provide:o.NG_VALIDATORS,useValue:Y,multi:!0},{provide:o.NG_VALIDATORS,useValue:H,multi:!0},{provide:o.NG_VALIDATORS,useValue:J,multi:!0},{provide:o.NG_VALIDATORS,useValue:W,multi:!0},{provide:i.DYNAMIC_VALIDATORS,useValue:Q}])}]}],e.AsyncSubmitDirective=L,e.DynamicBaseFormComponent=k,e.DynamicBaseFormControlContainerComponent=P,e.DynamicFormService=U,e.FormFieldSet=function(e){return function(r){var n=m(r);e.classes=e.classes||"",n[e.id]=e,t.ReflectUtils.defineMetadata("dynamicFormFieldSets",n,r)}},e.FormFile=function(e){return function(r,n){p(r,n,function(e,r){var n=f(e,"file",r);return(r=n.data).accept=r.accept||".jpg,.jpeg,.png",r.multi=r.multi||!1,r.baseUrl=t.ObjectUtils.isString(r.baseUrl)?r.baseUrl:"assets/",r.uploadUrl=t.ObjectUtils.isString(r.uploadUrl)?r.uploadUrl:"assets",r.createUploadData=r.createUploadData||function(e){var t=new FormData;return t.append("file",e),t},n}(n,e))}},e.FormInput=function(e){return function(r,n){var o=t.ReflectUtils.getOwnMetadata("design:type",r,n),i=o?o.name:"",a=n.indexOf("password")<0?"text":"password";switch(i){case"Number":a="number";break;case"Boolean":a="checkbox"}p(r,n,h(n,e,a))}},e.FormModel=function(e){return function(t,r){p(t,r,g(r,e))}},e.FormSelect=function(e){return function(t,r){p(t,r,d(r,e))}},e.FormSelectSubject=V,e.FormSerializable=function(e){return function(r,n){t.ReflectUtils.defineMetadata("dynamicFormSerializer",e||c,r,n)}},e.FormStatic=function(e){return function(t,r){p(t,r,y(r,e))}},e.FormSubject=R,e.NgxDynamicFormModule=X,e.createFormControl=f,e.createFormInput=h,e.createFormModel=g,e.createFormSelect=d,e.createFormStatic=y,e.defaultSerializer=c,e.defineFormControl=p,e.getFormControl=function(e,r){return t.ReflectUtils.getMetadata("dynamicFormControl",e,r)},e.getFormFieldSets=m,e.getFormSerializer=function(e,r){return t.ReflectUtils.getMetadata("dynamicFormSerializer",e,r)},e.validateItemsMaxLength=F,e.validateItemsMaxValue=D,e.validateItemsMinLength=S,e.validateItemsMinValue=O,e.validateJSON=v,e.validatePhone=C,e.validateRequiredTranslation=b,e.ɵa=G,e.ɵb=z,e.ɵc=q,e.ɵd=_,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@stemy/ngx-utils"),require("rxjs"),require("@angular/core"),require("@angular/forms"),require("@ng-dynamic-forms/core"),require("rxjs/operators"),require("@angular/common")):"function"==typeof define&&define.amd?define("@stemy/ngx-dynamic-form",["exports","@stemy/ngx-utils","rxjs","@angular/core","@angular/forms","@ng-dynamic-forms/core","rxjs/operators","@angular/common"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).stemy=e.stemy||{},e.stemy["ngx-dynamic-form"]={}),e.ngxUtils,e.rxjs,e.ng.core,e.ng.forms,e.core,e.rxjs.operators,e.ng.common)}(this,(function(e,t,r,n,o,i,a,s){"use strict";var u=[],l=function(){return Promise.resolve(!1)};function c(e,t){var r=t.get(e);return r?r.value:null}function p(e,r,n){t.ReflectUtils.defineMetadata("dynamicFormControl",n,e,r)}function m(e){return t.ReflectUtils.getMetadata("dynamicFormFieldSets",e)||{}}function f(e,r,n){return(n=n||{}).label=t.ObjectUtils.isNullOrUndefined(n.label)?e:n.label,n.labelAlign=n.labelAlign||"left",n.fieldSet=n.fieldSet||t.UniqueUtils.uuid(),n.classes=n.classes||"",n.readonly=n.readonly||l,n.hidden=n.hidden||l,n.validators=n.validators||u,{id:e,type:r,data:n}}function h(e,t,r){void 0===r&&(r="text");var n=f(e,"input",t);return(t=n.data).type=t.type||r,t.classes=t.classes?t.classes+" form-group-"+t.type:"form-group-"+t.type,t.placeholder=t.placeholder||("mask"==t.type?"_":""),t.step=t.step||1,t.mask=t.mask||[/\w*/gi],n}function d(e,t){var r=f(e,"select",t);(t=r.data).options=t.options||[],t.type=t.type||"select";var n="select"==t.type?"select":"select-"+t.type;return t.classes=t.classes?t.classes+" form-group-"+n:"form-group-"+n,r}function y(e,t){var r=f(e,"static",t);return(t=r.data).style=t.style||"table",r}function g(e,t){var r=f(e,"model",t);return(t=r.data).name=t.name||"",r}function v(e){var t=e.value;if(!t)return null;try{return JSON.parse(t),null}catch(e){return{json:!0}}}function b(e){var t=e.value;return t&&0!=t.length&&t.findIndex((function(e){return("de"==e.lang||"en"==e.lang)&&!e.translation}))<0?null:{requiredTranslation:!0}}function S(e){var t=e.value;if(!t)return Promise.resolve(null);return/^(?:\d){10,12}$/.test(t)?null:{phone:!0}}function C(e){return function(t){var r=t.value;return Array.isArray(r)&&r.every((function(t){return"string"==typeof t&&t.length>=e}))?null:{itemsMinLength:e}}}function F(e){return function(t){var r=t.value;return Array.isArray(r)&&r.every((function(t){return"string"==typeof t&&t.length<=e}))?null:{itemsMaxLength:e}}}function O(e){return function(t){var r=t.value;return Array.isArray(r)&&r.every((function(t){return"number"==typeof t&&t>=e}))?null:{itemsMinValue:e}}}function A(e){return function(t){var r=t.value;return Array.isArray(r)&&r.every((function(t){return"number"==typeof t&&t<=e}))?null:{itemsMaxValue:e}}}var D=function(e,t){return D=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},D(e,t)};function w(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}D(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function x(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))}function M(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}Object.create;function E(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function N(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a}function R(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(N(arguments[t]));return e}Object.create;var j=function(e){function t(t){var r=e.call(this)||this;return r.notifyCallback=t,r}return w(t,e),t.prototype.handleNotifiedValue=function(e,t,r){var n=this;r.then((function(e){return n.next(e)}))},t.prototype.notify=function(e,t){for(var r=e;r&&isNaN(r.index);)r=r.parent;var n=this.notifyCallback(e,t,null==r?void 0:r.index);n instanceof Promise||(n=Promise.resolve(n)),this.handleNotifiedValue(e,t,n)},t}(r.Subject),I=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return w(t,e),t.prototype.handleNotifiedValue=function(e,t,r){var n=this;r.then((function(r){var o,i;n.next(r);var a=t.value;if(e.multiple){var s=(a||[]).filter((function(e){return r.findIndex((function(t){return t.value==e}))>=0}));s.length!==(null==a?void 0:a.length)&&t.setValue(s,{onlySelf:!0,emitEvent:!1})}else{r.find((function(e){return e.value==a}))||t.setValue(null!==(i=null===(o=r[0])||void 0===o?void 0:o.value)&&void 0!==i?i:null,{onlySelf:!0,emitEvent:!1})}}))},t}(j);function V(e){return"string"==typeof e&&e.length>0}var T=function(e){function t(t,r){var n=e.call(this,t,r)||this;return n.additional=t.additional||{},n}return w(t,e),t}(i.DynamicFormArrayModel),L=function(e){function a(t,r,o){var i=e.call(this,t,r)||this;return i.openApi=o,i.onDetectChanges=new n.EventEmitter,i}return w(a,e),Object.defineProperty(a.prototype,"api",{get:function(){return this.openApi.api},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"language",{get:function(){return this.api.language},enumerable:!1,configurable:!0}),a.prototype.patchGroup=function(e,r,n){this.patchValueRecursive(e,r,n),this.detectChanges(),n.patchValue(t.ObjectUtils.copy(e))},a.prototype.patchForm=function(e,t){this.patchValueRecursive(e,t.model,t.group),this.detectChanges(t),t.group.patchValue(e)},a.prototype.serialize=function(e,t){return this.serializeRecursive(e,t)},a.prototype.notifyChanges=function(e,t){this.notifyChangesRecursive(e,t)},a.prototype.updateSelectOptions=function(e,t){if(e instanceof i.DynamicSelectModel){var n=e.options$;if(n instanceof j)return void n.notify(e,t);for(;n instanceof r.Subject&&n.source;)(n=n.source)instanceof j&&n.notify(e,t)}},a.prototype.showErrors=function(e){this.showErrorsForGroup(e.group),this.detectChanges(e)},a.prototype.detectChanges=function(t){e.prototype.detectChanges.call(this,t),this.onDetectChanges.emit(t)},a.prototype.patchValueRecursive=function(e,r,n){var o=this;Object.keys(e).forEach((function(a){var s=o.findModelById(a,r),u=e[a];if(s){var l=o.findControlByModel(s,n);if(s instanceof i.DynamicSelectModel&&t.ObjectUtils.isObject(u))e[a]=u.id||u._id||u;else if(s instanceof i.DynamicFormArrayModel){for(var c=Array.isArray(u)?u.length:0,p=l;s.size>c;)o.removeFormArrayGroup(0,p,s);for(;s.size<c;)o.insertFormArrayGroup(s.size,p,s);for(var m=0;m<c;m++){var f=s.get(m);o.patchValueRecursive(u[m],f.group,p.at(m))}}else s instanceof i.DynamicFormGroupModel&&o.patchValueRecursive(u,s.group,l)}}))},a.prototype.serializeRecursive=function(e,r){var n,o;return x(this,void 0,void 0,(function(){var a,s,u,l,c,p,m,f,h,d,y,g,v,b,S,C,F,O,A;return M(this,(function(D){switch(D.label){case 0:if(a={},!e||!r||!r.value)return[2,a];for(u in s=[],e)s.push(u);l=0,D.label=1;case 1:return l<s.length?(c=s[l],p=e[c],m=this.findControlByModel(p,r),f=null===(n=p.additional)||void 0===n?void 0:n.serializer,t.ObjectUtils.isFunction(f)?(h=a,d=p.id,[4,f(p,m)]):[3,3]):[3,12];case 2:return h[d]=D.sent(),[3,11];case 3:if(!(p instanceof i.DynamicFormArrayModel))return[3,8];y=Array.isArray(m.value)?m.value.length:0,g=m,v=[],b=0,D.label=4;case 4:return b<y?(S=p.get(b),F=(C=v).push,[4,this.serializeRecursive(S.group,g.at(b))]):[3,7];case 5:F.apply(C,[D.sent()]),D.label=6;case 6:return b++,[3,4];case 7:return a[p.id]=v,[3,11];case 8:return p instanceof i.DynamicFormGroupModel?(O=a,A=p.id,[4,this.serializeRecursive(p.group,m)]):[3,10];case 9:return O[A]=D.sent(),[3,11];case 10:if(p instanceof i.DynamicInputModel&&!t.ObjectUtils.isNullOrUndefined(m.value))return a[p.id]="number"==p.inputType?null!==(o=parseFloat((""+m.value||"0").replace(/,/gi,".")))&&void 0!==o?o:null:m.value,[3,11];a[p.id]=m.value,D.label=11;case 11:return l++,[3,1];case 12:return[2,a]}}))}))},a.prototype.notifyChangesRecursive=function(e,t){if(e&&t)for(var r in e){var n=e[r],o=this.findControlByModel(n,t);if(n instanceof i.DynamicFormArrayModel)for(var a=Array.isArray(o.value)?o.value.length:0,s=o,u=0;u<a;u++){var l=n.get(u);this.notifyChangesRecursive(l.group,s.at(u))}else n instanceof i.DynamicFormGroupModel?this.notifyChangesRecursive(n.group,o):this.updateSelectOptions(n,o)}},a.prototype.showErrorsForGroup=function(e){if(e){e.markAsTouched({onlySelf:!0});var t=Object.keys(e.controls).map((function(t){return e.controls[t]}));this.showErrorsForControls(t)}},a.prototype.showErrorsForControls=function(e){var t=this;e.forEach((function(e){e instanceof o.FormGroup?t.showErrorsForGroup(e):(e.markAsTouched({onlySelf:!0}),e instanceof o.FormArray&&t.showErrorsForControls(e.controls))}))},a.prototype.getFormModelForSchema=function(e){return x(this,void 0,void 0,(function(){var t;return M(this,(function(r){switch(r.label){case 0:return this.api.cache={},t=this,[4,this.openApi.getSchemas()];case 1:return t.schemas=r.sent(),[2,this.getFormModelForSchemaDef(this.schemas[e])]}}))}))},a.prototype.getFormModelForSchemaDef=function(e){var t=this;return e?Object.keys(e.properties||{}).map((function(r){var n=e.properties[r];return t.getFormControlModel(n,e)})).filter((function(e){return null!==e})):[]},a.prototype.getFormControlModel=function(e,t){var r,n,o=(null===(r=e.items)||void 0===r?void 0:r.enum)||e.enum;if(Array.isArray(o)||V(e.optionsPath)||V(e.endpoint))return new i.DynamicSelectModel(this.getFormSelectConfig(e,t));switch(e.type){case"string":case"number":case"integer":return new i.DynamicInputModel(this.getFormInputConfig(e,t));case"textarea":return new i.DynamicTextAreaModel(this.getFormTextareaConfig(e,t));case"boolean":return new i.DynamicCheckboxModel(this.getFormCheckboxConfig(e,t));case"array":return(null===(n=e.items)||void 0===n?void 0:n.$ref)||e.$ref?new T(this.getFormArrayConfig(e,t)):new i.DynamicInputModel(this.getFormInputConfig(e,t));case"file":return new i.DynamicFileUploadModel(this.getFormUploadConfig(e,t))}return e.$ref?new i.DynamicFormGroupModel(this.getFormGroupConfig(e,t)):null},a.prototype.getFormControlConfig=function(e,r){var n=this.getValidators(e,r),o=Object.keys(n).reduce((function(e,t){return e[t]="error."+t,e}),{});return{id:e.id,label:t.ObjectUtils.isString(e.label)?e.label:e.id,hidden:e.hidden,disabled:e.disabled,validators:n,errorMessages:o,additional:Object.assign({},e)}},a.prototype.getFormArrayConfig=function(e,t){var r,n=this,o=(null===(r=e.items)||void 0===r?void 0:r.$ref)||e.$ref||"",i=this.schemas[o.split("/").pop()];return Object.assign(this.getFormControlConfig(e,t),{groupFactory:function(){return n.getFormModelForSchemaDef(i)}})},a.prototype.getFormGroupConfig=function(e,t){var r=e.$ref||"",n=this.schemas[r.split("/").pop()];return Object.assign(this.getFormControlConfig(e,t),{group:this.getFormModelForSchemaDef(n)})},a.prototype.getFormInputConfig=function(e,r){var n,o=t.StringUtils.has(e.id,"password","Password")?"password":(null===(n=e.items)||void 0===n?void 0:n.type)||e.type;switch(o){case"boolean":o="checkbox";break;case"textarea":o="textarea";break;case"integer":o="number"}var i="array"==e.type&&e.items||e;return Object.assign(this.getFormControlConfig(e,r),{inputType:o,autoComplete:e.autoComplete||"off",multiple:"array"==e.type,accept:t.ObjectUtils.isString(e.accept)?e.accept:null,mask:t.ObjectUtils.isString(e.mask)?e.mask:null,pattern:t.ObjectUtils.isString(e.pattern)?e.pattern:null,step:isNaN(i.step)?isNaN(e.step)?1:e.step:i.step,min:isNaN(i.minimum)?Number.MIN_SAFE_INTEGER:i.minimum,max:isNaN(i.maximum)?Number.MAX_SAFE_INTEGER:i.maximum,minLength:isNaN(i.minLength)?Number.MIN_SAFE_INTEGER:i.minLength,maxLength:isNaN(i.maxLength)?Number.MAX_SAFE_INTEGER:i.maxLength})},a.prototype.getFormTextareaConfig=function(e,t){return Object.assign(this.getFormControlConfig(e,t),{cols:e.cols||null,rows:e.rows||10,wrap:e.wrap||!1,autoComplete:e.autoComplete||"off",multiple:"array"==e.type})},a.prototype.getFormSelectConfig=function(e,t){return Object.assign(this.getFormControlConfig(e,t),{options:this.getFormSelectOptions(e,t),multiple:"array"==e.type})},a.prototype.getFormCheckboxConfig=function(e,t){return Object.assign(this.getFormControlConfig(e,t),{indeterminate:!0===e.indeterminate})},a.prototype.translateOptions=function(e){return x(this,void 0,void 0,(function(){var t,r,n,o,i,a,s;return M(this,(function(u){switch(u.label){case 0:if(!e)return[2,[]];u.label=1;case 1:u.trys.push([1,6,7,8]),t=E(e),r=t.next(),u.label=2;case 2:return r.done?[3,5]:(n=r.value,o=n,[4,this.language.getTranslation(n.label)]);case 3:o.label=u.sent(),u.label=4;case 4:return r=t.next(),[3,2];case 5:return[3,8];case 6:return i=u.sent(),a={error:i},[3,8];case 7:try{r&&!r.done&&(s=t.return)&&s.call(t)}finally{if(a)throw a.error}return[7];case 8:return[2,e]}}))}))},a.prototype.getFormSelectOptions=function(e,r){var n,o=this,i=(null===(n=e.items)||void 0===n?void 0:n.enum)||e.enum;return Array.isArray(i)?new I((function(){var t=i.map((function(t){return{value:t,label:e.translatable?e.id+"."+t:t}}));return o.translateOptions(t)})):V(e.optionsPath)?new I((function(r,n,i){var a=e.optionsPath,s=n;if(a.startsWith("$root"))for(a=a.substr(5);s.parent;)s=s.parent;for(;a.startsWith(".");)a=a.substr(1),s.parent&&(s=s.parent);var u=t.ObjectUtils.getValue(s.value,a.replace(/\$ix/gi,i)),l=(t.ObjectUtils.isArray(u)?u:[]).map((function(e){return{value:e,label:e}}));return o.translateOptions(l)})):new I((function(){return x(o,void 0,void 0,(function(){var t;return M(this,(function(r){switch(r.label){case 0:return this.api.cache[e.endpoint]=this.api.cache[e.endpoint]||this.api.list(e.endpoint,this.api.makeListParams(1,-1)).then((function(t){return t.items.map((function(t){return{value:t.id||t._id,label:t[e.labelField]||t.label||t.id||t._id}}))})),[4,this.api.cache[e.endpoint]];case 1:return t=r.sent().map((function(e){return Object.assign({},e)})),[2,this.translateOptions(t)]}}))}))}))},a.prototype.getFormUploadConfig=function(e,t){var r=this.api.url(e.url||"assets"),n=e.accept,o=e.autoUpload,i=e.maxSize,a=e.minSize,s=e.removeUrl,u=e.showFileList;return Object.assign(this.getFormControlConfig(e,t),{url:r,accept:n,autoUpload:o,maxSize:i,minSize:a,removeUrl:s,showFileList:u})},a.prototype.getValidators=function(e,r){var n={};return t.ObjectUtils.isArray(r.required)&&r.required.indexOf(e.id)>=0&&(n.required=null),this.addPropertyValidators(n,e),this.addItemsValidators(n,e.items),n},a.prototype.addPropertyValidators=function(e,t){if(t&&(isNaN(t.minLength)||(e.minLength=t.minLength),isNaN(t.maxLength)||(e.maxLength=t.maxLength),isNaN(t.minimum)||(e.min=t.minimum),isNaN(t.maximum)||(e.max=t.maximum),"email"===t.format))e.email=null},a.prototype.addItemsValidators=function(e,t){t&&(isNaN(t.minLength)||(e.itemsMinLength=t.minLength),isNaN(t.maxLength)||(e.itemsMaxLength=t.maxLength),isNaN(t.minimum)||(e.itemsMinValue=t.minimum),isNaN(t.maximum)||(e.itemsMaxValue=t.maximum))},a}(i.DynamicFormService);L.decorators=[{type:n.Injectable}],L.ctorParameters=function(){return[{type:i.DynamicFormComponentService},{type:i.DynamicFormValidationService},{type:t.OpenApiService}]};var U=function(){function e(e,t,r,o){this.toaster=e,this.cdr=t,this.elem=r,this.renderer=o,this.onSuccess=new n.EventEmitter,this.onError=new n.EventEmitter,"BUTTON"===r.nativeElement.tagName&&o.setAttribute(r.nativeElement,"type","button")}return Object.defineProperty(e.prototype,"isDisabled",{get:function(){return this.disabled},set:function(e){this.disabled=e,e?this.renderer.setAttribute(this.elem.nativeElement,"disabled","disabled"):this.renderer.removeAttribute(this.elem.nativeElement,"disabled")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isLoading",{get:function(){return this.loading},enumerable:!1,configurable:!0}),e.prototype.ngOnInit=function(){var e=this;this.form&&(this.isDisabled="VALID"!==this.form.status,this.cdr.detectChanges(),this.onStatusChange=this.form.onStatusChange.subscribe((function(){e.isDisabled="VALID"!==e.form.status,e.cdr.detectChanges(),e.callback&&"PENDING"!=e.form.status&&(e.disabled||e.callback(),e.callback=null)})),this.onSubmit=this.form.onSubmit.subscribe((function(){return e.callMethod()})))},e.prototype.ngOnDestroy=function(){this.onStatusChange&&this.onStatusChange.unsubscribe(),this.onSubmit&&this.onSubmit.unsubscribe()},e.prototype.click=function(){var e=this;this.callback=function(){return e.callMethod()},"VALID"!==this.form.status&&"INVALID"!==this.form.status||(this.callback(),this.callback=null)},e.prototype.callMethod=function(){var e=this;this.loading||(this.loading=!0,this.method(this.form,this.context).then((function(t){e.loading=!1,t&&(e.onSuccess.emit(t),e.toaster.success(t.message,t.context))}),(function(t){if(!t||!t.message)throw new Error("Reason must implement IAsyncMessage interface");e.loading=!1,e.onError.emit(t),e.toaster.error(t.message,t.context)})))},e}();U.decorators=[{type:n.Directive,args:[{selector:"[async-submit]",exportAs:"async-submit"}]}],U.ctorParameters=function(){return[{type:void 0,decorators:[{type:n.Inject,args:[t.TOASTER_SERVICE]}]},{type:n.ChangeDetectorRef},{type:n.ElementRef},{type:n.Renderer2}]},U.propDecorators={method:[{type:n.Input,args:["async-submit"]}],form:[{type:n.Input}],context:[{type:n.Input}],onSuccess:[{type:n.Output}],onError:[{type:n.Output}],isDisabled:[{type:n.HostBinding,args:["class.disabled"]}],isLoading:[{type:n.HostBinding,args:["class.loading"]}],click:[{type:n.HostListener,args:["click"]}]};var _=function(e){function o(t,o,i,a){var s=e.call(this,i,a)||this;return s.formService=t,s.events=o,s.blur=new n.EventEmitter,s.change=new n.EventEmitter,s.focus=new n.EventEmitter,s.onStatusChange=new n.EventEmitter,s.onValueChange=new n.EventEmitter,s.onSubmit=new n.EventEmitter,s.templates=new n.QueryList,s.subscription=new r.Subscription,s.groupSubscription=new r.Subscription,s.labelPrefix="label",s}return w(o,e),Object.defineProperty(o.prototype,"status",{get:function(){return this.group?this.group.status:null},enumerable:!1,configurable:!0}),o.prototype.ngOnChanges=function(e){var r=this;this.groupSubscription.unsubscribe(),this.group&&(this.groupSubscription=t.ObservableUtils.multiSubscription(this.group.statusChanges.subscribe((function(){r.onStatusChange.emit(r)})),this.group.valueChanges.subscribe((function(){r.onValueChange.emit(r),r.formService.notifyChanges(r.model,r.group)}))))},o.prototype.ngAfterViewInit=function(){var e=this;this.subscription=t.ObservableUtils.multiSubscription(t.ObservableUtils.subscribe({subjects:[this.contentTemplates.changes,this.viewTemplates.changes],cb:function(){var t=e.contentTemplates.toArray().concat(e.viewTemplates.toArray());e.templates.reset(t)}}),this.events.languageChanged.subscribe((function(){e.formService.detectChanges(e)})),this.ngForm.ngSubmit.subscribe((function(){e.onSubmit.emit(e)})))},o.prototype.ngOnDestroy=function(){e.prototype.ngOnDestroy.call(this),this.subscription.unsubscribe(),this.groupSubscription.unsubscribe()},o.prototype.insertFormArrayGroup=function(e,t,r){this.formService.insertFormArrayGroup(e,t,r),this.changeDetectorRef.detectChanges()},o.prototype.removeFormArrayGroup=function(e,t,r){this.formService.removeFormArrayGroup(e,t,r),this.changeDetectorRef.detectChanges()},o.prototype.moveFormArrayGroup=function(e,t,r,n){this.formService.moveFormArrayGroup(e,t,r,n),this.changeDetectorRef.detectChanges()},o.prototype.clearFormArray=function(e,t){this.formService.clearFormArray(e,t),this.changeDetectorRef.detectChanges()},o.prototype.validate=function(e){var t=this;return void 0===e&&(e=!0),this.group?new Promise((function(r,n){t.group.statusChanges.pipe(a.first((function(e){return"VALID"==e||"INVALID"==e}))).subscribe((function(o){e&&t.formService.showErrors(t),"VALID"!=o?n(null):r(null)})),t.group.updateValueAndValidity()})):Promise.resolve()},o.prototype.serialize=function(e){return x(this,void 0,void 0,(function(){return M(this,(function(t){switch(t.label){case 0:return this.group?e?[4,this.validate()]:[3,2]:[2,null];case 1:t.sent(),t.label=2;case 2:return[4,this.formService.serialize(this.model,this.group)];case 3:return[2,t.sent()]}}))}))},o}(i.DynamicFormComponent);_.decorators=[{type:n.Component,args:[{selector:"dynamic-base-form",template:"",changeDetection:n.ChangeDetectionStrategy.Default}]}],_.ctorParameters=function(){return[{type:L,decorators:[{type:n.Inject,args:[L]}]},{type:t.EventsService,decorators:[{type:n.Inject,args:[t.EventsService]}]},{type:n.ChangeDetectorRef},{type:i.DynamicFormComponentService}]},_.propDecorators={group:[{type:n.Input}],model:[{type:n.Input}],layout:[{type:n.Input}],labelPrefix:[{type:n.Input}],blur:[{type:n.Output}],change:[{type:n.Output}],focus:[{type:n.Output}],contentTemplates:[{type:n.ContentChildren,args:[i.DynamicTemplateDirective]}],viewTemplates:[{type:n.ViewChildren,args:[i.DynamicTemplateDirective]}],onStatusChange:[{type:n.Output}],onValueChange:[{type:n.Output}],onSubmit:[{type:n.Output}],ngForm:[{type:n.ViewChild,args:[o.NgForm]}]};var k=function(e){function r(t,r,o,i,a,s,u){var l=e.call(this,r,o,i,a,s,u)||this;return l.form=t,l.changeDetectorRef=r,l.componentFactoryResolver=o,l.layoutService=i,l.validationService=a,l.componentService=s,l.relationService=u,l.context=null,l.blur=new n.EventEmitter,l.change=new n.EventEmitter,l.focus=new n.EventEmitter,l}return w(r,e),Object.defineProperty(r.prototype,"componentType",{get:function(){var e;return null!==(e=this.componentService.getCustomComponentType(this.model))&&void 0!==e?e:this.getComponentType(this.model)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"startTemplate",{get:function(){return this.model.type==i.DYNAMIC_FORM_CONTROL_TYPE_ARRAY?this.layoutService.getAlignedTemplate(this.model,this.templates,"ARRAY_START"):this.layoutService.getStartTemplate(this.model,this.templates)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"endTemplate",{get:function(){return this.model.type==i.DYNAMIC_FORM_CONTROL_TYPE_ARRAY?this.layoutService.getAlignedTemplate(this.model,this.templates,"ARRAY_END"):this.layoutService.getEndTemplate(this.model,this.templates)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"formService",{get:function(){return this.form.formService},enumerable:!1,configurable:!0}),r.prototype.ngOnInit=function(){var e=this;this.onDetectChanges=this.formService.onDetectChanges.subscribe((function(t){t===e.form&&(e.changeDetectorRef.detectChanges(),e.formService.updateSelectOptions(e.model,e.control))}))},r.prototype.ngOnDestroy=function(){e.prototype.ngOnDestroy.call(this),this.onDetectChanges.unsubscribe()},r.prototype.createFormControlComponent=function(){var r;e.prototype.createFormControlComponent.call(this);var n=null===(r=this.componentRef)||void 0===r?void 0:r.instance;n&&t.ObjectUtils.isFunction(n.onCreated)&&n.onCreated()},r.prototype.getComponentType=function(e){return null},r}(i.DynamicFormControlContainerComponent);k.decorators=[{type:n.Component,args:[{selector:"dynamic-base-form-control",template:"",changeDetection:n.ChangeDetectionStrategy.OnPush}]}],k.ctorParameters=function(){return[{type:_},{type:n.ChangeDetectorRef},{type:n.ComponentFactoryResolver},{type:i.DynamicFormLayoutService},{type:i.DynamicFormValidationService},{type:i.DynamicFormComponentService},{type:i.DynamicFormRelationService}]},k.propDecorators={contentTemplateList:[{type:n.ContentChildren,args:[i.DynamicTemplateDirective]}],klass:[{type:n.HostBinding,args:["class"]}],context:[{type:n.Input}],group:[{type:n.Input}],hostClass:[{type:n.Input}],inputTemplateList:[{type:n.Input,args:["templates"]}],layout:[{type:n.Input}],model:[{type:n.Input}],blur:[{type:n.Output}],change:[{type:n.Output}],focus:[{type:n.Output}],componentViewContainerRef:[{type:n.ViewChild,args:["componentViewContainer",{read:n.ViewContainerRef,static:!0}]}]};var P=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return w(t,e),t.prototype.showErrorMessages=function(t,r,n){return e.prototype.showErrorMessages.call(this,t,r,n)},t}(i.DynamicFormValidationService);P.decorators=[{type:n.Injectable}];var G=[_,k],z=[U],q=[],B=v,$=b,Y=C,H=F,J=O,W=A,X=new Map([["json",v],["requiredTranslation",b],["phone",S],["itemsMinLength",C],["itemsMaxLength",F],["itemsMinValue",O],["itemsMaxValue",A]]),Q=function(){function e(){}return e.forRoot=function(){return{ngModule:e,providers:[L,P,{provide:i.DynamicFormService,useExisting:L},{provide:i.DynamicFormValidationService,useExisting:P}]}},e}();Q.decorators=[{type:n.NgModule,args:[{declarations:R(G,z,q),imports:[s.CommonModule,o.FormsModule,o.ReactiveFormsModule,t.NgxUtilsModule],exports:R(G,z,q,[o.FormsModule,o.ReactiveFormsModule,t.NgxUtilsModule]),entryComponents:G,providers:R(q,[{provide:o.NG_VALIDATORS,useValue:B,multi:!0},{provide:o.NG_VALIDATORS,useValue:$,multi:!0},{provide:o.NG_VALIDATORS,useValue:Y,multi:!0},{provide:o.NG_VALIDATORS,useValue:H,multi:!0},{provide:o.NG_VALIDATORS,useValue:J,multi:!0},{provide:o.NG_VALIDATORS,useValue:W,multi:!0},{provide:i.DYNAMIC_VALIDATORS,useValue:X}])}]}],e.AsyncSubmitDirective=U,e.DynamicBaseFormComponent=_,e.DynamicBaseFormControlContainerComponent=k,e.DynamicFormService=L,e.FormFieldSet=function(e){return function(r){var n=m(r);e.classes=e.classes||"",n[e.id]=e,t.ReflectUtils.defineMetadata("dynamicFormFieldSets",n,r)}},e.FormFile=function(e){return function(r,n){p(r,n,function(e,r){var n=f(e,"file",r);return(r=n.data).accept=r.accept||".jpg,.jpeg,.png",r.multi=r.multi||!1,r.baseUrl=t.ObjectUtils.isString(r.baseUrl)?r.baseUrl:"assets/",r.uploadUrl=t.ObjectUtils.isString(r.uploadUrl)?r.uploadUrl:"assets",r.createUploadData=r.createUploadData||function(e){var t=new FormData;return t.append("file",e),t},n}(n,e))}},e.FormInput=function(e){return function(r,n){var o=t.ReflectUtils.getOwnMetadata("design:type",r,n),i=o?o.name:"",a=n.indexOf("password")<0?"text":"password";switch(i){case"Number":a="number";break;case"Boolean":a="checkbox"}p(r,n,h(n,e,a))}},e.FormModel=function(e){return function(t,r){p(t,r,g(r,e))}},e.FormSelect=function(e){return function(t,r){p(t,r,d(r,e))}},e.FormSelectSubject=I,e.FormSerializable=function(e){return function(r,n){t.ReflectUtils.defineMetadata("dynamicFormSerializer",e||c,r,n)}},e.FormStatic=function(e){return function(t,r){p(t,r,y(r,e))}},e.FormSubject=j,e.NgxDynamicFormModule=Q,e.createFormControl=f,e.createFormInput=h,e.createFormModel=g,e.createFormSelect=d,e.createFormStatic=y,e.defaultSerializer=c,e.defineFormControl=p,e.getFormControl=function(e,r){return t.ReflectUtils.getMetadata("dynamicFormControl",e,r)},e.getFormFieldSets=m,e.getFormSerializer=function(e,r){return t.ReflectUtils.getMetadata("dynamicFormSerializer",e,r)},e.validateItemsMaxLength=F,e.validateItemsMaxValue=A,e.validateItemsMinLength=C,e.validateItemsMinValue=O,e.validateJSON=v,e.validatePhone=S,e.validateRequiredTranslation=b,e.ɵa=G,e.ɵb=z,e.ɵc=q,e.ɵd=P,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=stemy-ngx-dynamic-form.umd.min.js.map
|