{"version":3,"file":"step_controller-BNCCeGw5.js","sources":["../../../app/javascript/controllers/journeys/step_controller.js"],"sourcesContent":["import { Controller } from \"@hotwired/stimulus\"\nimport interact from \"interactjs\"\n\nexport default class extends Controller {\n static targets = [\"draggable\"]\n static values = { url: String }\n\n static classes = [\"active\", \"inactive\"]\n\n initialize() {\n this.position = { x: 0, y: 0 }\n this.draggingEnabled = true\n }\n\n connect() {\n this.interactable = interact(this.draggableTarget).draggable({\n onstart: this.disablePanning.bind(this),\n onmove: this.onDrag.bind(this),\n onend: this.onDragEnd.bind(this),\n })\n\n const span = this.element.querySelector('span')\n\n // dragging from the span should move the draggable to the mouse position and let the drag start from there.\n\n this.spanInteractable = interact(span).draggable({\n onstart: (event) => {\n // Move the draggable to the mouse position immediately\n const rect = this.draggableTarget.getBoundingClientRect()\n const centerX = rect.width / 2\n const centerY = rect.height / 2\n\n // Calculate initial position to center draggable at cursor\n this.position.x = event.clientX - rect.left - centerX\n this.position.y = event.clientY - rect.top - centerY\n\n // Apply immediate positioning\n this.draggableTarget.style.transform = `translate(${this.position.x}px, ${this.position.y}px)`\n\n this.disablePanning(event)\n },\n onmove: this.onDrag.bind(this),\n onend: this.onDragEnd.bind(this),\n })\n }\n\n disablePanning(event) {\n this.dispatch('drag:start')\n }\n\n enableDragging() {\n this.draggingEnabled = true\n\n this.interactable.draggable(true)\n this.spanInteractable.draggable(true)\n\n this.draggableTarget.classList.remove(...this.inactiveClasses)\n this.draggableTarget.classList.add(...this.activeClasses)\n\n this.parent.classList.remove(\"grayscale\")\n\n this.element.classList.add('cursor-move')\n this.element.classList.remove('cursor-not-allowed')\n }\n\n disableDragging() {\n this.draggingEnabled = false\n\n this.interactable.draggable(false)\n this.spanInteractable.draggable(false)\n\n this.draggableTarget.classList.add(...this.inactiveClasses)\n this.draggableTarget.classList.remove(...this.activeClasses)\n\n this.parent.classList.add(\"grayscale\")\n\n this.element.classList.remove('cursor-move')\n this.element.classList.add('cursor-not-allowed')\n }\n\n // private\n\n onDrag(event) {\n if (this.draggingDisabled) return\n\n // Update position based on drag delta\n this.position.x += event.dx\n this.position.y += event.dy\n\n // Apply the transform to the draggable\n this.draggableTarget.style.transform = `translate(${this.position.x}px, ${this.position.y}px)`\n\n this.dispatch('drag:start')\n }\n\n onDragEnd(event) {\n if (event.relatedTarget?.id === \"dropzone\") {\n this.position = { x: 0, y: 0 }\n this.dispatch('drag:end')\n } else {\n this.position = { x: 0, y: 0 }\n }\n\n this.draggableTarget.style.removeProperty(\"transform\")\n\n const element = document.getElementById('journey--steps')\n\n if (!element.matches(':hover')) {\n this.dispatch('drag:end')\n }\n }\n\n get draggingDisabled() {\n return this.draggingEnabled === false\n }\n\n get parent() {\n return document.getElementById(this.element.dataset.parent)\n }\n}\n"],"names":["step_controller","Controller","interact","span","event","rect","centerX","centerY","_a","__publicField"],"mappings":"2PAGe,MAAKA,UAASC,CAAW,CAMtC,YAAa,CACX,KAAK,SAAW,CAAE,EAAG,EAAG,EAAG,CAAC,EAC5B,KAAK,gBAAkB,EAC3B,CAEE,SAAU,CACR,KAAK,aAAeC,EAAS,KAAK,eAAe,EAAE,UAAU,CAC3D,QAAS,KAAK,eAAe,KAAK,IAAI,EACtC,OAAQ,KAAK,OAAO,KAAK,IAAI,EAC7B,MAAO,KAAK,UAAU,KAAK,IAAI,CAChC,CAAA,EAED,MAAMC,EAAO,KAAK,QAAQ,cAAc,MAAM,EAI9C,KAAK,iBAAmBD,EAASC,CAAI,EAAE,UAAU,CAC/C,QAAUC,GAAU,CAElB,MAAMC,EAAO,KAAK,gBAAgB,sBAAqB,EACjDC,EAAUD,EAAK,MAAQ,EACvBE,EAAUF,EAAK,OAAS,EAG9B,KAAK,SAAS,EAAID,EAAM,QAAUC,EAAK,KAAOC,EAC9C,KAAK,SAAS,EAAIF,EAAM,QAAUC,EAAK,IAAME,EAG7C,KAAK,gBAAgB,MAAM,UAAY,aAAa,KAAK,SAAS,CAAC,OAAO,KAAK,SAAS,CAAC,MAEzF,KAAK,eA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