@codebakery/origami
Version:
Angular + Polymer
16 lines (14 loc) • 6.56 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/forms")):"function"==typeof define&&define.amd?define("@codebakery/origami/forms",["exports","@angular/core","@angular/forms"],t):t(((e=e||self).codebakery=e.codebakery||{},e.codebakery.origami=e.codebakery.origami||{},e.codebakery.origami.forms={}),e.ng.core,e.ng.forms)}(this,(function(e,t,i){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */var n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])})(e,t)};function r(e,t,i,n){var r,o=arguments.length,a=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var l=e.length-1;l>=0;l--)(r=e[l])&&(a=(o<3?r(a):o>3?r(t,i,a):r(t,i))||a);return o>3&&a&&Object.defineProperty(t,i,a),a}function o(e,t){return function(i,n){t(i,n,e)}}var a={provide:i.NG_VALUE_ACCESSOR,useExisting:t.forwardRef((function(){return l})),multi:!0},l=function(e){function l(t,i,n,r){var o=e.call(this,n,t,r)||this;return o.elementRef=t,o.injector=i,o.renderer=n,o.validationErrorsKey="validate",o.isWritingValue=!1,o.ignoreInvalidChanges=!1,o}return function(e,t){function i(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}(l,e),Object.defineProperty(l.prototype,"control",{get:function(){return this._control||(this._control=this.injector.get(i.NgControl).control),this._control},enumerable:!0,configurable:!0}),l.prototype.ngAfterViewInit=function(){var e=this,t=this.elementRef.nativeElement;if(this.isValidatable(t)){var n=this.control;this.statusSub=n.statusChanges.subscribe((function(){"function"==typeof e.isInvalid?t.invalid=e.isInvalid(n):t.invalid=!!n.invalid&&!!n.dirty})),this.shouldUseValidate(t)&&n.setValidators(i.Validators.compose([n.validator,function(){var i;return t.validate()?null:((i={})[e.validationErrorsKey]=!0,i)}]))}},l.prototype.ngOnDestroy=function(){this.statusSub&&this.statusSub.unsubscribe()},l.prototype.writeValue=function(t){this.isWritingValue=!0;var i=this.elementRef.nativeElement;if(this.isMultiSelectable(i)||this.isSelectable(i)){var n=this.getSelectableProperty(i,t);n&&(i[n]=t)}else this.isCheckedElement(i)?i.checked=Boolean(t):e.prototype.writeValue.call(this,t);this.isWritingValue=!1},l.prototype.onChangedEvent=function(e){if(!this.isWritingValue){var t=this.elementRef.nativeElement,i=!1;switch(e.type){case"selected-items-changed":case"selected-item-changed":i="selectedItems"===(n=this.getSelectableProperty(t))||"selectedItem"===n;break;case"selected-values-changed":case"selected-changed":i="selectedValues"===(n=this.getSelectableProperty(t))||"selected"===n;break;default:i=!0}if(i){var n=void 0;n=this.isMultiSelectable(t)||this.isSelectable(t)?this.getSelectableProperty(t):this.isCheckedElement(t)?"checked":"value",this.onChange(t[n])}}},l.prototype.onInvalidChanged=function(){if(!this.ignoreInvalidChanges){var e=this.elementRef.nativeElement;this.isValidatable(e)&&this.control&&this.control.invalid!==e.invalid&&(this.ignoreInvalidChanges=!0,this.control.updateValueAndValidity(),this.ignoreInvalidChanges=!1)}},l.prototype.isCheckedElement=function(e){return this.isPropertyDefined(e,"checked")},l.prototype.isSelectable=function(e){return this.isPropertyDefined(e,"selected")||this.isPropertyDefined(e,"selectedItem")},l.prototype.isMultiSelectable=function(e){return!(!e||!this.isPropertyDefined(e,"selectedValues")&&!this.isPropertyDefined(e,"selectedItems"))&&(!this.isSelectable(e)||!0===e.multi)},l.prototype.isValidatable=function(e){return this.isPropertyDefined(e,"invalid")},l.prototype.shouldUseValidate=function(e){if("function"==typeof e.validate){this.ignoreInvalidChanges=!0;var t=e.invalid;e.validate();var i=e.invalid;e.invalid=!e.invalid,e.validate();var n=e.invalid===i;return e.invalid=t,this.ignoreInvalidChanges=!1,n}return!1},l.prototype.isPropertyDefined=function(e,t){return!!e&&t in e},l.prototype.getSelectableProperty=function(e,t){var i=this.isMultiSelectable(e),n=i?"selectedItems":"selectedItem",r=i?"selectedValues":"selected";if("boolean"!=typeof this.useSelectableValueProp){var o=n in e,a=r in e;if(o&&!a)this.useSelectableValueProp=!0;else if(!o&&a)this.useSelectableValueProp=!1;else{if(null==t)return;var l=e[n];try{e[n]=t}catch(e){}this.useSelectableValueProp=e[n]===t,e[n]=l}}return e.itemValuePath?"value":this.useSelectableValueProp?n:r},l.ctorParameters=function(){return[{type:t.ElementRef},{type:t.Injector},{type:t.Renderer2},{type:Boolean,decorators:[{type:t.Optional},{type:t.Inject,args:[i.COMPOSITION_BUFFER_MODE]}]}]},r([t.Input()],l.prototype,"isInvalid",void 0),r([t.Input()],l.prototype,"validationErrorsKey",void 0),r([t.HostListener("selected-items-changed",["$event"]),t.HostListener("selected-item-changed",["$event"]),t.HostListener("selected-values-changed",["$event"]),t.HostListener("selected-changed",["$event"]),t.HostListener("checked-changed",["$event"]),t.HostListener("value-changed",["$event"])],l.prototype,"onChangedEvent",null),r([t.HostListener("invalid-changed")],l.prototype,"onInvalidChanged",null),l=r([t.Directive({selector:"[ngModel][origami],[formControlName][origami],[formControl][origami]",providers:[a]}),o(3,t.Optional()),o(3,t.Inject(i.COMPOSITION_BUFFER_MODE))],l)}(i.DefaultValueAccessor),s=function(){function e(){}return e=r([t.NgModule({declarations:[l],exports:[l]})],e)}();e.ORIGAMI_CONTROL_VALUE_ACCESSOR=a,e.OrigamiControlValueAccessor=l,e.OrigamiFormsModule=s,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=origami-forms.umd.min.js.map