ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
16 lines (14 loc) • 12.5 kB
JavaScript
!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="undefined"!=typeof globalThis?globalThis: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,s,o,r){"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.
***************************************************************************** */function a(e,t,n,i){var s,o=arguments.length,r=o<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 a=e.length-1;a>=0;a--)(s=e[a])&&(r=(o<3?s(r):o>3?s(t,n,r):s(t,n))||r);return o>3&&r&&Object.defineProperty(t,n,r),r}function c(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}Object.create;Object.create;function h(e){return s.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 o.Subject,this.documentMouseUp$=new o.Subject,this.documentMouseMove$=new o.Subject,this.mouseEntered$=new o.Subject,this.document=t}return e.prototype.startResizing=function(e){var t=this,n=s.isTouchEvent(e);this.clearListeners();var i=n?"touchmove":"mousemove",o=n?"touchend":"mouseup";this.listeners.set(i,(function(e){t.documentMouseMove$.next(e)})),this.listeners.set(o,(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}();l.decorators=[{type:n.Injectable}],l.ctorParameters=function(){return[{type:n.NgZone},{type:void 0,decorators:[{type:n.Inject,args:[t.DOCUMENT]}]}]};var u=function(){function e(e,t,i,s,a){var c=this;this.elementRef=e,this.renderer=t,this.nzResizableService=i,this.platform=s,this.ngZone=a,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.nzDisabled=!1,this.nzResize=new n.EventEmitter,this.nzResizeEnd=new n.EventEmitter,this.nzResizeStart=new n.EventEmitter,this.resizing=!1,this.currentHandleEvent=null,this.ghostElement=null,this.sizeCache=null,this.destroy$=new o.Subject,this.elementRef.nativeElement.classList.add("nz-resizable"),this.nzResizableService.handleMouseDown$.pipe(r.takeUntil(this.destroy$)).subscribe((function(e){c.nzDisabled||(c.resizing=!0,c.nzResizableService.startResizing(e.mouseEvent),c.currentHandleEvent=e,c.setCursor(),c.nzResizeStart.emit({mouseEvent:e.mouseEvent}),c.elRect=c.el.getBoundingClientRect())})),this.nzResizableService.documentMouseUp$.pipe(r.takeUntil(this.destroy$)).subscribe((function(e){c.resizing&&(c.resizing=!1,c.nzResizableService.documentMouseUp$.next(),c.endResize(e))})),this.nzResizableService.documentMouseMove$.pipe(r.takeUntil(this.destroy$)).subscribe((function(e){c.resizing&&c.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,o,r,a,c=0,h=0,l=this.nzMinWidth,u=1/0,d=1/0;if("parent"===this.nzBounds){var z=this.renderer.parentNode(this.el);if(z instanceof HTMLElement){var p=z.getBoundingClientRect();u=p.width,d=p.height}}else if("window"===this.nzBounds)"undefined"!=typeof window&&(u=window.innerWidth,d=window.innerHeight);else if(this.nzBounds&&this.nzBounds.nativeElement&&this.nzBounds.nativeElement instanceof HTMLElement){var m=this.nzBounds.nativeElement.getBoundingClientRect();u=m.width,d=m.height}return r=s.ensureInBounds(this.nzMaxWidth,u),a=s.ensureInBounds(this.nzMaxHeight,d),-1!==this.nzGridColumnCount&&(h=r/this.nzGridColumnCount,l=-1!==this.nzMinColumn?h*this.nzMinColumn:l,r=-1!==this.nzMaxColumn?h*this.nzMaxColumn:r),-1!==n?/(left|right)/i.test(this.currentHandleEvent.direction)?(i=Math.min(Math.max(e,l),r),((o=Math.min(Math.max(i/n,this.nzMinHeight),a))>=a||o<=this.nzMinHeight)&&(i=Math.min(Math.max(o*n,l),r))):(o=Math.min(Math.max(t,this.nzMinHeight),a),((i=Math.min(Math.max(o*n,l),r))>=r||i<=l)&&(o=Math.min(Math.max(i/n,this.nzMinHeight),a))):(i=Math.min(Math.max(e,l),r),o=Math.min(Math.max(t,this.nzMinHeight),a)),-1!==this.nzGridColumnCount&&(i=(c=Math.round(i/h))*h),{col:c,width:i,height:o}},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=h(e),s=h(this.currentHandleEvent.mouseEvent),o=n.width,r=n.height,a=this.nzLockAspectRatio?o/r:-1;switch(this.currentHandleEvent.direction){case"bottomRight":o=i.clientX-n.left,r=i.clientY-n.top;break;case"bottomLeft":o=n.width+s.clientX-i.clientX,r=i.clientY-n.top;break;case"topRight":o=i.clientX-n.left,r=n.height+s.clientY-i.clientY;break;case"topLeft":o=n.width+s.clientX-i.clientX,r=n.height+s.clientY-i.clientY;break;case"top":r=n.height+s.clientY-i.clientY;break;case"right":o=i.clientX-n.left;break;case"bottom":r=i.clientY-n.top;break;case"left":o=n.width+s.clientX-i.clientX}var c=this.calcSize(o,r,a);this.sizeCache=Object.assign({},c),this.ngZone.run((function(){t.nzResize.emit(Object.assign(Object.assign({},c),{mouseEvent:e}))})),this.nzPreview&&this.previewResize(c)},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?Object.assign({},this.sizeCache):{width:this.elRect.width,height:this.elRect.height};this.ngZone.run((function(){t.nzResizeEnd.emit(Object.assign(Object.assign({},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}();u.decorators=[{type:n.Directive,args:[{selector:"[nz-resizable]",exportAs:"nzResizable",providers:[l],host:{"[class.nz-resizable-resizing]":"resizing","[class.nz-resizable-disabled]":"nzDisabled","(mouseenter)":"onMouseenter()","(mouseleave)":"onMouseleave()"}}]}],u.ctorParameters=function(){return[{type:n.ElementRef},{type:n.Renderer2},{type:l},{type:i.Platform},{type:n.NgZone}]},u.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}],nzDisabled:[{type:n.Input}],nzResize:[{type:n.Output}],nzResizeEnd:[{type:n.Output}],nzResizeStart:[{type:n.Output}]},a([s.InputBoolean(),c("design:type",Boolean)],u.prototype,"nzLockAspectRatio",void 0),a([s.InputBoolean(),c("design:type",Boolean)],u.prototype,"nzPreview",void 0),a([s.InputBoolean(),c("design:type",Boolean)],u.prototype,"nzDisabled",void 0);var d=function(e,t){this.direction=e,this.mouseEvent=t},z=function(){function e(e,t,i){this.nzResizableService=e,this.cdr=t,this.elementRef=i,this.nzDirection="bottomRight",this.nzMouseDown=new n.EventEmitter,this.entered=!1,this.destroy$=new o.Subject,this.elementRef.nativeElement.classList.add("nz-resizable-handle")}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 d(this.nzDirection,e))},e.prototype.ngOnDestroy=function(){this.destroy$.next(),this.destroy$.complete()},e}();z.decorators=[{type:n.Component,args:[{selector:"nz-resize-handle, [nz-resize-handle]",exportAs:"nzResizeHandle",template:"\n <ng-content></ng-content>\n ",changeDetection:n.ChangeDetectionStrategy.OnPush,host:{"[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)"}}]}],z.ctorParameters=function(){return[{type:l},{type:n.ChangeDetectorRef},{type:n.ElementRef}]},z.propDecorators={nzDirection:[{type:n.Input}],nzMouseDown:[{type:n.Output}]};var p=["bottomRight","topRight","bottomLeft","topLeft","bottom","right","top","left"],m=function(){function e(){this.nzDirections=p,this.directions=new Set(this.nzDirections)}return e.prototype.ngOnChanges=function(e){e.nzDirections&&(this.directions=new Set(e.nzDirections.currentValue))},e}();m.decorators=[{type:n.Component,args:[{selector:"nz-resize-handles",exportAs:"nzResizeHandles",template:' <nz-resize-handle *ngFor="let dir of directions" [nzDirection]="dir"></nz-resize-handle> ',changeDetection:n.ChangeDetectionStrategy.OnPush}]}],m.ctorParameters=function(){return[]},m.propDecorators={nzDirections:[{type:n.Input}]};var g=function(){};g.decorators=[{type:n.NgModule,args:[{imports:[t.CommonModule],declarations:[u,z,m],exports:[u,z,m]}]}],e.DEFAULT_RESIZE_DIRECTION=p,e.NzResizableDirective=u,e.NzResizableModule=g,e.NzResizableService=l,e.NzResizeHandleComponent=z,e.NzResizeHandleMouseDownEvent=d,e.NzResizeHandlesComponent=m,e.getEventWithPoint=h,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=ng-zorro-antd-resizable.umd.min.js.map