blob: b42f4288a44f4f2a282e4797650337528132099e [file] [log] [blame]
import{__decorate as e}from"../node_modules/tslib/tslib.es6.js";import{LitElement as t,html as i}from"https://cdn.jsdelivr.net/gh/lit/dist@2/core/lit-core.min.js";import{property as r,customElement as o}from"https://cdn.skypack.dev/pin/lit@v2.5.0-jYRq0AKQogjUdUh7SCAE/mode=imports/optimized/lit/decorators.js";import{DeviceDragZone as n}from"./device-dragzone.js";import{simulationState as d}from"./device-observer.js";var s;let l=s=class extends t{constructor(){super(),this.serial="",this.type="",this.addEventListener("drop",this.handleDrop),this.addEventListener("drag",this.handleDragOver),this.addEventListener("dragenter",s.handleDragEnter),this.addEventListener("dragleave",s.handleDragLeave),this.addEventListener("dragover",this.handleDragOver)}static handleDragEnter(e){e.preventDefault()}static handleDragLeave(e){e.preventDefault()}slottedDropZone(){var e;const t=null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector("slot");return null==t?void 0:t.assignedElements({flatten:!0})[0]}handleDrop(e){var t,i,r,o;e.preventDefault();const s=this.slottedDropZone();if(s){const l=n.dragged;"move"===(null===(t=e.dataTransfer)||void 0===t?void 0:t.effectAllowed)?(null===(i=l.parentNode)||void 0===i||i.removeChild(l),l.style.opacity="",s.appendChild(l)):s.appendChild(l.cloneNode(!0));const a=s.lastChild;if(a){const t=s.getBoundingClientRect();a.setAttribute("action","move"),a.style.position="absolute",a.style.left=e.clientX-t.left+"px",a.style.top=e.clientY-t.top+"px",a.style.opacity="1.0";let i=null===(r=a.getElementsByTagName("ns-cube-sprite").item(0))||void 0===r?void 0:r.getAttribute("id");void 0===i&&(i=null===(o=a.getElementsByTagName("ns-pyramid-sprite").item(0))||void 0===o?void 0:o.getAttribute("id")),null==i&&(i=""),d.handleDrop(i,(e.clientX-t.left)/100,(e.clientY-t.top)/100)}}}handleDragOver(e){e.preventDefault(),this.slottedDropZone()}render(){return i`<slot></slot>`}};e([r({type:String,attribute:"serial"})],l.prototype,"serial",void 0),e([r({type:String,attribute:"type"})],l.prototype,"type",void 0),l=s=e([o("ns-device-dropzone")],l);export{l as DeviceDropZone};