Draggable.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var s,
  5. e =
  6. (this && this.__decorate) ||
  7. function(t, e, i, s) {
  8. var o,
  9. a = arguments.length,
  10. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  11. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  12. else
  13. for (var r = t.length - 1; 0 <= r; r--)
  14. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  15. return 3 < a && n && Object.defineProperty(e, i, n), n;
  16. };
  17. Object.defineProperty(i, "__esModule", { value: !0 }), (i.DragEventType = void 0);
  18. const o = t("App"),
  19. { ccclass: a, menu: n } = cc._decorator;
  20. ((t = s = i.DragEventType || (i.DragEventType = {})).DRAG_START = "DRAG_START"),
  21. (t.DRAGING = "DRAGING"),
  22. (t.DRAGING_IN = "DRAGING_IN"),
  23. (t.DRAGING_OUT = "DRAGING_OUT"),
  24. (t.DROP = "DROP"),
  25. (t.CANCEL = "CANCEL"),
  26. (t.DRAG_END = "DRAG_END");
  27. (t = class extends cc.Component {
  28. constructor() {
  29. super(...arguments),
  30. (this.delegate = {
  31. onDragStart: function() {
  32. return null;
  33. },
  34. onDragEnd: function() {
  35. return null;
  36. },
  37. onDragDone: function() {
  38. return null;
  39. },
  40. prepareDrag: function() {
  41. return { dragingData: null, dragingNode: null };
  42. }
  43. });
  44. }
  45. start() {}
  46. onEnable() {
  47. this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
  48. }
  49. onDisable() {
  50. this.node.off(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
  51. }
  52. setDelegate(t) {
  53. this.delegate = t;
  54. }
  55. onDragDone(t, e) {
  56. this.delegate.onDragDone && this.delegate.onDragDone(this.dragingData, e);
  57. }
  58. onTouchStart(t) {
  59. var e = this.delegate.prepareDrag();
  60. e &&
  61. ((this.dragingData = e.dragingData),
  62. (this.dragingNode = e.dragingNode),
  63. this.node.emit(s.DRAG_START, this, this.dragingData),
  64. (e = o.default.ViewManager.uiRoot).emit(s.DRAG_START, this, this.dragingData),
  65. e.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this, !0),
  66. e.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this, !0),
  67. e.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchEnd, this, !0),
  68. this.delegate.onDragStart(this.dragingData),
  69. this.dragingNode &&
  70. ((this.dragingNode.position = e.convertToNodeSpaceAR(t.getLocation())), e.addChild(this.dragingNode)));
  71. }
  72. onTouchMove(t) {
  73. var e;
  74. this.node.emit(s.DRAGING, this, this.dragingData),
  75. this.dragingNode &&
  76. ((e = o.default.ViewManager.uiRoot),
  77. (this.dragingNode.position = e.convertToNodeSpaceAR(t.getLocation())));
  78. }
  79. onTouchEnd(t) {
  80. this.delegate.onDragEnd && this.delegate.onDragEnd(this.dragingData),
  81. this.dragingNode && this.dragingNode.removeFromParent(),
  82. this.node.emit(s.DRAG_END, this, this.dragingData),
  83. o.default.ViewManager.uiRoot.emit(s.DRAG_END, this, this.dragingData, t),
  84. o.default.ViewManager.uiRoot.targetOff(this);
  85. }
  86. }),
  87. (t = e([a], t));
  88. i.default = t;