var t = require; var e = module; var i = exports; e = (this && this.__decorate) || function(t, e, i, s) { var o, a = arguments.length, n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s; if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s); else for (var r = t.length - 1; 0 <= r; r--) (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n); return 3 < a && n && Object.defineProperty(e, i, n), n; }; Object.defineProperty(i, "__esModule", { value: !0 }); const s = t("App"), o = t("Draggable"), { ccclass: a, menu: n } = cc._decorator; (t = class extends cc.Component { constructor() { super(...arguments), (this.canDrop = !1), (this.delegate = { checkCanDrop: function() { return !0; }, onDragIn: function() { return null; }, onDragOut: function() { return null; }, onDrop: function() { return null; }, onDropCancel: function() { return null; }, onDropEnd: function() { return null; } }), (this.isDragingIn = !1); } start() {} onEnable() { s.default.ViewManager.uiRoot.on(o.DragEventType.DRAG_START, this.onDragStart, this), s.default.ViewManager.uiRoot.on(o.DragEventType.DRAG_END, this.onDragEnd, this); } onDisable() { s.default.ViewManager.uiRoot.off(o.DragEventType.DRAG_START, this.onDragStart, this), s.default.ViewManager.uiRoot.off(o.DragEventType.DRAG_END, this.onDragEnd, this); } setTouchNode(t) { s.default.ViewManager.uiRoot.off(o.DragEventType.DRAG_START, this.onDragStart, this), s.default.ViewManager.uiRoot.off(o.DragEventType.DRAG_END, this.onDragEnd, this), s.default.ViewManager.uiRoot.on(o.DragEventType.DRAG_START, this.onDragStart, this), s.default.ViewManager.uiRoot.on(o.DragEventType.DRAG_END, this.onDragEnd, this); } setDelegate(t) { this.delegate = t; } onDragStart(t, e) { t.node != this.node && ((this.dragingSource = t), (this.dragingData = e), s.default.ViewManager.uiRoot.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this, !0), (this.canDrop = this.delegate.checkCanDrop(this.dragingSource, this.dragingData))); } onDragEnd(t, e, i) { s.default.ViewManager.uiRoot.off(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this); i = this.node.getBoundingBoxToWorld().contains(i.getLocation()); i && this.isDragingIn && this.canDrop ? (this.delegate.onDrop && this.delegate.onDrop(this.dragingSource, this.dragingData), this.node.emit(o.DragEventType.DROP, this, this.dragingData), t.onDragDone(e, this)) : i || (this.delegate.onDropCancel && this.delegate.onDropCancel(this.dragingSource, this.dragingData), this.node.emit(o.DragEventType.CANCEL, this, this.dragingData)), this.canDrop && (this.delegate.onDropEnd && this.delegate.onDropEnd(this.dragingSource, this.dragingData), this.node.emit(o.DragEventType.DRAG_END, this, this.dragingData)), (this.isDragingIn = !1), (this.dragingData = null), (this.dragingSource = null), (this.canDrop = !1); } onTouchMove(t) { t = this.node.getBoundingBoxToWorld().contains(t.getLocation()); t ? this.canDrop && (this.isDragingIn ? this.node.emit(o.DragEventType.DRAGING, this, this.dragingData) : ((this.isDragingIn = !0), this.delegate.onDragIn && this.delegate.onDragIn(this.dragingSource, this.dragingData), this.node.emit(o.DragEventType.DRAGING_IN, this, this.dragingData))) : !t && this.isDragingIn && this.canDrop && ((this.isDragingIn = !1), this.delegate.onDragOut && this.delegate.onDragOut(this.dragingSource, this.dragingData), this.node.emit(o.DragEventType.DRAGING_OUT, this, this.dragingData)); } }), (t = e([a], t)); i.default = t;