import Moveable from "lit-moveable"; import { LitElement, html } from "lit"; import { customElement, property, state } from "lit/decorators.js"; import { ref, createRef } from "lit/directives/ref.js"; @customElement("lit-app") export default class App extends LitElement { containerScale: any = "$preview_containerScale"; throttleDrag: any = "$preview_throttleDrag"; edgeDraggable: any = "$preview_edgeDraggable"; startDragRotate: any = "$preview_startDragRotate"; throttleDragRotate: any = "$preview_throttleDragRotate"; xInputRef: Ref = createRef(null); yInputRef: Ref = createRef(null); moveableRef: Ref = createRef(null); @state() requestCallbacks: any = (() => { function request() { this.moveableRef.value!.request("draggable", { x: parseInt(this.xInputRef.value!.value), y: parseInt(this.yInputRef.value!.value) }, true); } return { onInput(e: any) { const ev = (e.nativeEvent || e) as InputEvent; if (typeof ev.data === "undefined") { request(); } }, onKeyUp(e: any) { e.stopPropagation(); if (e.keyCode === 13) { request(); } } }; })(); render() { return html `
X:   Y:
Target
`; } onDrag(e) { e.target.style.transform = e.transform; } onDragEnd(e) { requestAnimationFrame(() => { const rect = e.moveable.getRect(); this.xInputRef.value!.value = `${rect.left}`; this.yInputRef.value!.value = `${rect.top}`; }); } }