Liferay.Loader.define("commerce-organization-web@5.0.37/js/utils/DndHandler",["module","exports","require","./constants"],(function(t,e,a){window;{Object.defineProperty(e,"__esModule",{value:!0}),e.hasPositionChanged=o,e.default=void 0;var s=a("./constants");function o(t,e){if(!e)return!1;return Math.max(Math.abs(t.x-e.x),Math.abs(t.y-e.y))>s.DRAGGING_THRESHOLD}class t{constructor(){this._mouseStartPositions=null,this._dragging=!1,this._chartItems=null,this._dragHandle=null}_handleMouseDown(t){this._mouseStartPositions={x:t.offsetX,y:t.offsetY}}_createDragHandle(t,e,a){this._dragHandle=a.append("g").attr("transform",t.attributes.transform.value).attr("class","dnd-handle");const s=this._dragHandle.append("g").attr("class","dnd-handle-content"),o=t.cloneNode(!0);o.classList.remove("highlighted"),o.removeAttribute("transform");const d=Math.min(3,e-1),n=o.querySelector("rect");for(let t=d;t>0;t--)s.append((()=>n.cloneNode())).attr("x",3*t).attr("y",3*t);s.append((()=>o))}_handleMouseMove(t,e,a,d,n,r,i){if(!this._dragging&&o(this._mouseStartPositions,{x:t.offsetX,y:t.offsetY})){this._dragging=!0;const t=new Map;this._chartItems=n.selectAll(".chart-item"),this._chartItems.each((e=>{if(["user","account","add"].includes(e.data.type)&&t.set(e.data.chartNodeId,e),d.has(e.data.chartNodeId)){t.set(e.data.chartNodeId,e),e.parent&&t.set(e.parent.data.chartNodeId,e.parent);e.descendants().forEach((e=>{t.set(e.data.chartNodeId,e)}))}})),this._createDragHandle(a,d.size,n),this._chartItems.each(((e,a,s)=>{t.has(e.data.chartNodeId)?s[a].classList.add("drop-not-allowed"):s[a].classList.add("drop-allowed")})),i.classList.add("dragging")}if(this._dragHandle){const a={x:(this._mouseStartPositions.x-t.offsetX)*(s.ZOOM_EXTENT[1]/r)*-1+e.y,y:(this._mouseStartPositions.y-t.offsetY)*(s.ZOOM_EXTENT[1]/r)*-1+e.x};this._dragHandle.attr("transform","translate(".concat(a.x,", ").concat(a.y,")")).classed("dragging",!0)}}_handleMouseUp(t,e,a,s,o){if(!this._dragging)return o({d:a,event:t,type:"click"});this._mouseStartPositions=null,this._dragging=!1,s.classList.remove("dragging");const d=e.target.closest(".drop-allowed");return this._chartItems.each(((t,e,a)=>{a[e].classList.remove("drop-not-allowed"),a[e].classList.remove("drop-allowed")})),this._dragHandle.remove(),o({d:a,event:t,target:null==d?void 0:d.__data__,type:"drop"})}handleMouseEvent(t,e,a,s,o,d){return new Promise((n=>{this._handleMouseDown(t);const r=a.has(e.data.chartNodeId)?a:new Set([e.data.chartNodeId]),i=t.currentTarget,l=t=>this._handleMouseMove(t,e,i,r,o,d,s);s.addEventListener("mousemove",l,this),window.addEventListener("mouseup",(a=>{s.removeEventListener("mousemove",l),this._handleMouseUp(t,a,e,s,n)}),{once:!0})}))}}e.default=t}}));
//# sourceMappingURL=DndHandler.js.map