UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

16 lines (14 loc) 12.3 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/common"),require("@angular/core"),require("@angular/cdk/platform"),require("ng-zorro-antd/core/util"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("ng-zorro-antd/resizable",["exports","@angular/common","@angular/core","@angular/cdk/platform","ng-zorro-antd/core/util","rxjs","rxjs/operators"],t):t(((e=e||self)["ng-zorro-antd"]=e["ng-zorro-antd"]||{},e["ng-zorro-antd"].resizable={}),e.ng.common,e.ng.core,e.ng.cdk.platform,e["ng-zorro-antd"].core.util,e.rxjs,e.rxjs.operators)}(this,(function(e,t,n,i,o,s,r){"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 c=function(){return(c=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function h(e,t,n,i){var o,s=arguments.length,r=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,i);else for(var c=e.length-1;c>=0;c--)(o=e[c])&&(r=(s<3?o(r):s>3?o(t,n,r):o(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r}function a(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function u(e){return o.isTouchEvent(e)?e.touches[0]||e.changedTouches[0]:e}var l=function(){function e(e,t){this.ngZone=e,this.listeners=new Map,this.handleMouseDown$=new s.Subject,this.documentMouseUp$=new s.Subject,this.documentMouseMove$=new s.Subject,this.mouseEntered$=new s.Subject,this.document=t}return e.prototype.startResizing=function(e){var t=this,n=o.isTouchEvent(e);this.clearListeners();var i=n?"touchmove":"mousemove",s=n?"touchend":"mouseup";this.listeners.set(i,(function(e){t.documentMouseMove$.next(e)})),this.listeners.set(s,(function(e){t.documentMouseUp$.next(e),t.clearListeners()})),this.ngZone.runOutsideAngular((function(){t.listeners.forEach((function(e,n){t.document.addEventListener(n,e)}))}))},e.prototype.clearListeners=function(){var e=this;this.listeners.forEach((function(t,n){e.document.removeEventListener(n,t)})),this.listeners.clear()},e.prototype.ngOnDestroy=function(){this.handleMouseDown$.complete(),this.documentMouseUp$.complete(),this.documentMouseMove$.complete(),this.mouseEntered$.complete(),this.clearListeners()},e.decorators=[{type:n.Injectable}],e.ctorParameters=function(){return[{type:n.NgZone},{type:void 0,decorators:[{type:n.Inject,args:[t.DOCUMENT]}]}]},e}();var d=function(){function e(e,t,i,o,c){var h=this;this.elementRef=e,this.renderer=t,this.nzResizableService=i,this.platform=o,this.ngZone=c,this.nzBounds="parent",this.nzMinHeight=40,this.nzMinWidth=40,this.nzGridColumnCount=-1,this.nzMaxColumn=-1,this.nzMinColumn=-1,this.nzLockAspectRatio=!1,this.nzPreview=!1,this.nzResize=new n.EventEmitter,this.nzResizeEnd=new n.EventEmitter,this.nzResizeStart=new n.EventEmitter,this.resizing=!1,this.destroy$=new s.Subject,this.nzResizableService.handleMouseDown$.pipe(r.takeUntil(this.destroy$)).subscribe((function(e){h.resizing=!0,h.nzResizableService.startResizing(e.mouseEvent),h.currentHandleEvent=e,h.setCursor(),h.nzResizeStart.emit({mouseEvent:e.mouseEvent}),h.elRect=h.el.getBoundingClientRect()})),this.nzResizableService.documentMouseUp$.pipe(r.takeUntil(this.destroy$)).subscribe((function(e){h.resizing&&(h.resizing=!1,h.nzResizableService.documentMouseUp$.next(),h.endResize(e))})),this.nzResizableService.documentMouseMove$.pipe(r.takeUntil(this.destroy$)).subscribe((function(e){h.resizing&&h.resize(e)}))}return e.prototype.onMouseenter=function(){this.nzResizableService.mouseEntered$.next(!0)},e.prototype.onMouseleave=function(){this.nzResizableService.mouseEntered$.next(!1)},e.prototype.setPosition=function(){var e=getComputedStyle(this.el).position;"static"!==e&&e||this.renderer.setStyle(this.el,"position","relative")},e.prototype.calcSize=function(e,t,n){var i,s,r,c,h=0,a=0,u=this.nzMinWidth,l=1/0,d=1/0;if("parent"===this.nzBounds){var p=this.renderer.parentNode(this.el);if(p instanceof HTMLElement){var z=p.getBoundingClientRect();l=z.width,d=z.height}}else if("window"===this.nzBounds)"undefined"!=typeof window&&(l=window.innerWidth,d=window.innerHeight);else if(this.nzBounds&&this.nzBounds.nativeElement&&this.nzBounds.nativeElement instanceof HTMLElement){var m=this.nzBounds.nativeElement.getBoundingClientRect();l=m.width,d=m.height}return r=o.ensureInBounds(this.nzMaxWidth,l),c=o.ensureInBounds(this.nzMaxHeight,d),-1!==this.nzGridColumnCount&&(a=r/this.nzGridColumnCount,u=-1!==this.nzMinColumn?a*this.nzMinColumn:u,r=-1!==this.nzMaxColumn?a*this.nzMaxColumn:r),-1!==n?/(left|right)/i.test(this.currentHandleEvent.direction)?(i=Math.min(Math.max(e,u),r),((s=Math.min(Math.max(i/n,this.nzMinHeight),c))>=c||s<=this.nzMinHeight)&&(i=Math.min(Math.max(s*n,u),r))):(s=Math.min(Math.max(t,this.nzMinHeight),c),((i=Math.min(Math.max(s*n,u),r))>=r||i<=u)&&(s=Math.min(Math.max(i/n,this.nzMinHeight),c))):(i=Math.min(Math.max(e,u),r),s=Math.min(Math.max(t,this.nzMinHeight),c)),-1!==this.nzGridColumnCount&&(i=(h=Math.round(i/a))*a),{col:h,width:i,height:s}},e.prototype.setCursor=function(){switch(this.currentHandleEvent.direction){case"left":case"right":this.renderer.setStyle(document.body,"cursor","ew-resize");break;case"top":case"bottom":this.renderer.setStyle(document.body,"cursor","ns-resize");break;case"topLeft":case"bottomRight":this.renderer.setStyle(document.body,"cursor","nwse-resize");break;case"topRight":case"bottomLeft":this.renderer.setStyle(document.body,"cursor","nesw-resize")}this.renderer.setStyle(document.body,"user-select","none")},e.prototype.resize=function(e){var t=this,n=this.elRect,i=u(e),o=u(this.currentHandleEvent.mouseEvent),s=n.width,r=n.height,h=this.nzLockAspectRatio?s/r:-1;switch(this.currentHandleEvent.direction){case"bottomRight":s=i.clientX-n.left,r=i.clientY-n.top;break;case"bottomLeft":s=n.width+o.clientX-i.clientX,r=i.clientY-n.top;break;case"topRight":s=i.clientX-n.left,r=n.height+o.clientY-i.clientY;break;case"topLeft":s=n.width+o.clientX-i.clientX,r=n.height+o.clientY-i.clientY;break;case"top":r=n.height+o.clientY-i.clientY;break;case"right":s=i.clientX-n.left;break;case"bottom":r=i.clientY-n.top;break;case"left":s=n.width+o.clientX-i.clientX}var a=this.calcSize(s,r,h);this.sizeCache=c({},a),this.ngZone.run((function(){t.nzResize.emit(c(c({},a),{mouseEvent:e}))})),this.nzPreview&&this.previewResize(a)},e.prototype.endResize=function(e){var t=this;this.renderer.setStyle(document.body,"cursor",""),this.renderer.setStyle(document.body,"user-select",""),this.removeGhostElement();var n=this.sizeCache?c({},this.sizeCache):{width:this.elRect.width,height:this.elRect.height};this.ngZone.run((function(){t.nzResizeEnd.emit(c(c({},n),{mouseEvent:e}))})),this.sizeCache=null,this.currentHandleEvent=null},e.prototype.previewResize=function(e){var t=e.width,n=e.height;this.createGhostElement(),this.renderer.setStyle(this.ghostElement,"width",t+"px"),this.renderer.setStyle(this.ghostElement,"height",n+"px")},e.prototype.createGhostElement=function(){this.ghostElement||(this.ghostElement=this.renderer.createElement("div"),this.renderer.setAttribute(this.ghostElement,"class","nz-resizable-preview")),this.renderer.appendChild(this.el,this.ghostElement)},e.prototype.removeGhostElement=function(){this.ghostElement&&this.renderer.removeChild(this.el,this.ghostElement)},e.prototype.ngAfterViewInit=function(){this.platform.isBrowser&&(this.el=this.elementRef.nativeElement,this.setPosition())},e.prototype.ngOnDestroy=function(){this.ghostElement=null,this.sizeCache=null,this.destroy$.next(),this.destroy$.complete()},e.decorators=[{type:n.Directive,args:[{selector:"[nz-resizable]",exportAs:"nzResizable",providers:[l],host:{"[class.nz-resizable]":"true","[class.nz-resizable-resizing]":"resizing","(mouseenter)":"onMouseenter()","(mouseleave)":"onMouseleave()"}}]}],e.ctorParameters=function(){return[{type:n.ElementRef},{type:n.Renderer2},{type:l},{type:i.Platform},{type:n.NgZone}]},e.propDecorators={nzBounds:[{type:n.Input}],nzMaxHeight:[{type:n.Input}],nzMaxWidth:[{type:n.Input}],nzMinHeight:[{type:n.Input}],nzMinWidth:[{type:n.Input}],nzGridColumnCount:[{type:n.Input}],nzMaxColumn:[{type:n.Input}],nzMinColumn:[{type:n.Input}],nzLockAspectRatio:[{type:n.Input}],nzPreview:[{type:n.Input}],nzResize:[{type:n.Output}],nzResizeEnd:[{type:n.Output}],nzResizeStart:[{type:n.Output}]},h([o.InputBoolean(),a("design:type",Boolean)],e.prototype,"nzLockAspectRatio",void 0),h([o.InputBoolean(),a("design:type",Boolean)],e.prototype,"nzPreview",void 0),e}();var p=function(e,t){this.direction=e,this.mouseEvent=t};var z=function(){function e(e,t){this.nzResizableService=e,this.cdr=t,this.nzDirection="bottomRight",this.nzMouseDown=new n.EventEmitter,this.entered=!1,this.destroy$=new s.Subject}return e.prototype.ngOnInit=function(){var e=this;this.nzResizableService.mouseEntered$.pipe(r.takeUntil(this.destroy$)).subscribe((function(t){e.entered=t,e.cdr.markForCheck()}))},e.prototype.onMousedown=function(e){this.nzResizableService.handleMouseDown$.next(new p(this.nzDirection,e))},e.prototype.ngOnDestroy=function(){this.destroy$.next(),this.destroy$.complete()},e.decorators=[{type:n.Component,args:[{selector:"nz-resize-handle, [nz-resize-handle]",exportAs:"nzResizeHandle",template:" <ng-content></ng-content> ",changeDetection:n.ChangeDetectionStrategy.OnPush,host:{"[class.nz-resizable-handle]":"true","[class.nz-resizable-handle-top]":"nzDirection === 'top'","[class.nz-resizable-handle-right]":"nzDirection === 'right'","[class.nz-resizable-handle-bottom]":"nzDirection === 'bottom'","[class.nz-resizable-handle-left]":"nzDirection === 'left'","[class.nz-resizable-handle-topRight]":"nzDirection === 'topRight'","[class.nz-resizable-handle-bottomRight]":"nzDirection === 'bottomRight'","[class.nz-resizable-handle-bottomLeft]":"nzDirection === 'bottomLeft'","[class.nz-resizable-handle-topLeft]":"nzDirection === 'topLeft'","[class.nz-resizable-handle-box-hover]":"entered","(mousedown)":"onMousedown($event)","(touchstart)":"onMousedown($event)"}}]}],e.ctorParameters=function(){return[{type:l},{type:n.ChangeDetectorRef}]},e.propDecorators={nzDirection:[{type:n.Input}],nzMouseDown:[{type:n.Output}]},e}();var m=["bottomRight","topRight","bottomLeft","topLeft","bottom","right","top","left"],f=function(){function e(){this.nzDirections=m,this.directions=new Set(this.nzDirections)}return e.prototype.ngOnChanges=function(e){e.nzDirections&&(this.directions=new Set(e.nzDirections.currentValue))},e.decorators=[{type:n.Component,args:[{selector:"nz-resize-handles",exportAs:"nzResizeHandles",template:'\n <nz-resize-handle *ngFor="let dir of directions" [nzDirection]="dir"></nz-resize-handle>\n ',changeDetection:n.ChangeDetectionStrategy.OnPush}]}],e.ctorParameters=function(){return[]},e.propDecorators={nzDirections:[{type:n.Input}]},e}();var g=function(){function e(){}return e.decorators=[{type:n.NgModule,args:[{imports:[t.CommonModule],declarations:[d,z,f],exports:[d,z,f]}]}],e}();e.DEFAULT_RESIZE_DIRECTION=m,e.NzResizableDirective=d,e.NzResizableModule=g,e.NzResizableService=l,e.NzResizeHandleComponent=z,e.NzResizeHandleMouseDownEvent=p,e.NzResizeHandlesComponent=f,e.getEventWithPoint=u,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=ng-zorro-antd-resizable.umd.min.js.map