UNPKG

@taiga-ui/kit

Version:
16 lines (14 loc) 8.47 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/common"),require("@angular/core"),require("@taiga-ui/cdk"),require("@taiga-ui/core"),require("@taiga-ui/kit/utils/dom"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@taiga-ui/kit/directives/dropdown-selection",["exports","@angular/common","@angular/core","@taiga-ui/cdk","@taiga-ui/core","@taiga-ui/kit/utils/dom","rxjs","rxjs/operators"],t):t(((e=e||self)["taiga-ui"]=e["taiga-ui"]||{},e["taiga-ui"].kit=e["taiga-ui"].kit||{},e["taiga-ui"].kit.directives=e["taiga-ui"].kit.directives||{},e["taiga-ui"].kit.directives["dropdown-selection"]={}),e.ng.common,e.ng.core,e.cdk,e.core$1,e["taiga-ui"].kit.utils.dom,e.rxjs,e.rxjs.operators)}(this,(function(e,t,n,o,r,i,a,c){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */var s=function(e,t){return(s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function p(e,t,n,o){var r,i=arguments.length,a=i<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,o);else for(var c=e.length-1;c>=0;c--)(r=e[c])&&(a=(i<3?r(a):i>3?r(t,n,a):r(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function u(e,t){return function(n,o){t(n,o,e)}}var l=function(e){function l(t,n,r,i,s,p,u,l,d,g,f,y,m,v){var h=e.call(this,n,r,i,l||s,p)||this;h.refresh$=g,h.changeDetectorRef=f,h.ngZone=y,h.renderer=m,h.viewContainerRef=v,h.position="selection",h.visibilityHandler=o.ALWAYS_TRUE_HANDLER,h.documentRef=u||t,h.range=h.documentRef.createRange();var R=h.elementRef.nativeElement;return a.merge(o.typedFromEvent(h.documentRef,"mouseup"),o.typedFromEvent(R,"mousedown").pipe(c.switchMapTo(o.typedFromEvent(R,"mousemove").pipe(c.takeUntil(o.typedFromEvent(h.documentRef,"mouseup"))))),o.typedFromEvent(R,"keyup")).pipe(c.map((function(){var e=o.getNativeFocused(h.documentRef),t=h.documentRef.getSelection();return(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&R.contains(e)?h.veryVerySadInputFix(e):t&&t.rangeCount?t.getRangeAt(0):h.range})),c.takeUntil(d)).subscribe((function(e){var t=R.contains(e.commonAncestorContainer);h.range=t?e:h.range;var n=t&&(!h.visibilityHandler||h.visibilityHandler(h.range));h.toggleDropdownBox(n||h.inDropdown(e))})),h}var d;return function(e,t){function n(){this.constructor=e}s(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(l,e),d=l,Object.defineProperty(l.prototype,"tuiDropdownSelection",{set:function(e){if(e){var t=this.elementRef.nativeElement.contains(this.range.commonAncestorContainer)&&e(this.range);this.visibilityHandler=e,this.toggleDropdownBox(t)}},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"clientRect",{get:function(){var e=this.documentRef.defaultView,t=this.rangeRect,n=e?e.frameElement:null;if(!n)return t;var o=n.getBoundingClientRect();return{top:t.top+o.top,left:t.left+o.left,right:t.left+o.left+t.width,bottom:t.top+o.top+t.height,width:t.width,height:t.height}},enumerable:!0,configurable:!0}),l.prototype.ngOnDestroy=function(){this.closeDropdownBox(),this.ghost&&this.renderer.removeChild(this.viewContainerRef.element.nativeElement,this.ghost)},Object.defineProperty(l.prototype,"rangeRect",{get:function(){switch(this.position){case"tag":var e=this.range.commonAncestorContainer;return(e.nodeType===Node.ELEMENT_NODE?e:e.parentNode).getBoundingClientRect();case"word":return i.getWordRange(this.range).getBoundingClientRect();default:return this.range.getBoundingClientRect()}},enumerable:!0,configurable:!0}),l.prototype.toggleDropdownBox=function(e){var t=this;this.ngZone.run((function(){e?t.openDropdownBox():t.closeDropdownBox(),t.changeDetectorRef.markForCheck()}))},l.prototype.boxContains=function(e){return!!this.dropdownBoxRef&&this.dropdownBoxRef.location.nativeElement.contains(e)},l.prototype.inDropdown=function(e){var t=e.startContainer,n=e.endContainer,o=this.boxContains(e.commonAncestorContainer),r=this.boxContains(n)&&this.elementRef.nativeElement.contains(t),i=this.boxContains(t)&&this.elementRef.nativeElement.contains(n);return o||r||i},l.prototype.veryVerySadInputFix=function(e){var t=this.ghost,n=void 0===t?this.initGhost(e):t,r=e.getBoundingClientRect(),i=r.top,a=r.left,c=r.width,s=r.height,p=e.selectionStart,u=e.selectionEnd,l=this.documentRef.createRange(),d=this.elementRef.nativeElement.getBoundingClientRect();return n.style.top=o.px(i-d.top),n.style.left=o.px(a-d.left),n.style.width=o.px(c),n.style.height=o.px(s),n.textContent=o.CHAR_ZERO_WIDTH_SPACE+e.value+o.CHAR_NO_BREAK_SPACE,l.setStart(n.firstChild,p||0),l.setEnd(n.firstChild,u||0),l},l.prototype.initGhost=function(e){var t=this.renderer.createElement("div"),n=this.viewContainerRef.element.nativeElement,o=getComputedStyle(e),r=o.font,i=o.letterSpacing,a=o.textTransform,c=o.padding;return t.style.position="absolute",t.style.pointerEvents="none",t.style.opacity="0",t.style.whiteSpace="pre-wrap",t.style.font=r,t.style.letterSpacing=i,t.style.textTransform=a,t.style.padding=c,this.renderer.appendChild(n,t),this.ghost=t,t},l.ctorParameters=function(){return[{type:Document,decorators:[{type:n.Inject,args:[t.DOCUMENT]}]},{type:n.ComponentFactoryResolver,decorators:[{type:n.Inject,args:[n.ComponentFactoryResolver]}]},{type:n.Injector,decorators:[{type:n.Inject,args:[n.Injector]}]},{type:o.TuiPortalService,decorators:[{type:n.Inject,args:[o.TuiPortalService]}]},{type:n.ElementRef,decorators:[{type:n.Host},{type:n.Inject,args:[n.ElementRef]}]},{type:o.TuiActiveZoneDirective,decorators:[{type:n.Inject,args:[o.TuiActiveZoneDirective]},{type:n.Optional}]},{type:Document,decorators:[{type:n.Inject,args:[r.TUI_DOCUMENT_OR_SHADOW_ROOT]},{type:n.Optional}]},{type:n.ElementRef,decorators:[{type:n.Inject,args:[r.TUI_ELEMENT_REF]},{type:n.Optional}]},{type:o.TuiDestroyService,decorators:[{type:n.Inject,args:[o.TuiDestroyService]}]},{type:o.TuiParentsScrollService,decorators:[{type:n.Inject,args:[o.TuiParentsScrollService]}]},{type:n.ChangeDetectorRef,decorators:[{type:n.Inject,args:[n.ChangeDetectorRef]}]},{type:n.NgZone,decorators:[{type:n.Inject,args:[n.NgZone]}]},{type:n.Renderer2,decorators:[{type:n.Inject,args:[n.Renderer2]}]},{type:n.ViewContainerRef,decorators:[{type:n.Inject,args:[n.ViewContainerRef]}]}]},p([n.Input()],l.prototype,"tuiDropdownSelection",null),p([n.Input("tuiDropdownSelectionPosition")],l.prototype,"position",void 0),l=d=p([n.Directive({selector:"[tuiDropdownSelection]:not(ng-container)",providers:[{provide:r.TUI_DROPDOWN_DIRECTIVE,useExisting:n.forwardRef((function(){return d}))},o.TuiParentsScrollService,o.TuiDestroyService]}),u(0,n.Inject(t.DOCUMENT)),u(1,n.Inject(n.ComponentFactoryResolver)),u(2,n.Inject(n.Injector)),u(3,n.Inject(o.TuiPortalService)),u(4,n.Host()),u(4,n.Inject(n.ElementRef)),u(5,n.Inject(o.TuiActiveZoneDirective)),u(5,n.Optional()),u(6,n.Inject(r.TUI_DOCUMENT_OR_SHADOW_ROOT)),u(6,n.Optional()),u(7,n.Inject(r.TUI_ELEMENT_REF)),u(7,n.Optional()),u(8,n.Inject(o.TuiDestroyService)),u(9,n.Inject(o.TuiParentsScrollService)),u(10,n.Inject(n.ChangeDetectorRef)),u(11,n.Inject(n.NgZone)),u(12,n.Inject(n.Renderer2)),u(13,n.Inject(n.ViewContainerRef))],l)}(r.AbstractTuiDropdown),d=function(){function e(){}return e=p([n.NgModule({imports:[r.TuiDropdownBoxModule],declarations:[l],exports:[l]})],e)}();e.TuiDropdownSelectionDirective=l,e.TuiDropdownSelectionModule=d,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=taiga-ui-kit-directives-dropdown-selection.umd.min.js.map