import { NgxMoveableComponent } from "ngx-moveable"; import { ViewChild, ElementRef, Component } from "@angular/core"; @Component({ selector: "ngx-app", templateUrl: "./App.component.html" }) export default class NgxAppComponent { resizable: any = "$preview_resizable"; keepRatio: any = "$preview_keepRatio"; throttleResize: any = "$preview_throttleResize"; renderDirections: any = "$preview_renderDirections"; minWidth: any = "$preview_minWidth"; minHeight: any = "$preview_minHeight"; maxWidth: any = "$preview_maxWidth"; maxHeight: any = "$preview_maxHeight"; @ViewChild("widthInputRef") widthInputRef!: ElementRef; @ViewChild("heightInputRef") heightInputRef!: ElementRef; @ViewChild("moveableRef") moveableRef!: NgxMoveableComponent; onInput: any = (e: any) => { const ev = (e.nativeEvent || e) as InputEvent; const horizontal = JSON.parse((ev.target as HTMLElement).getAttribute("data-horizontal")!); if (typeof ev.data === "undefined") { this.moveableRef!.request("resizable", { offsetWidth: parseFloat(this.widthInputRef!.value), offsetHeight: parseFloat(this.heightInputRef!.value), horizontal }, true); } }; onKeyUp: any = (e: any) => { const ev = (e.nativeEvent || e) as InputEvent; const horizontal = JSON.parse((ev.target as HTMLElement).getAttribute("data-horizontal")!); e.stopPropagation(); if (e.keyCode === 13) { this.moveableRef!.request("resizable", { offsetWidth: parseFloat(this.widthInputRef!.value), offsetHeight: parseFloat(this.heightInputRef!.value), horizontal }, true); } }; onResizeGroupStart({ setMin, setMax }) { setMin([this.minWidth, this.minHeight]); setMax([this.maxWidth, this.maxHeight]); } onResizeGroup({ events }) { events.forEach(ev => { ev.target.style.width = `${ev.boundingWidth}px`; ev.target.style.height = `${ev.boundingHeight}px`; ev.target.style.transform = `translate(${ev.drag.beforeTranslate[0]}px, ${ev.drag.beforeTranslate[1]}px)`; }); } onResizeGroupEnd(e) { requestAnimationFrame(() => { const rect = e.moveable.getRect(); this.widthInputRef!.value = `${rect.offsetWidth}`; this.heightInputRef!.value = `${rect.offsetHeight}`; }); } onDragGroup({ events }) { events.forEach(ev => { ev.target.style.transform = ev.transform; }); } }