de1b5880ecd3a607b89cb559176915ec9a2151de1eff05a48797f868ff7ab62bf8d344d37b6e235c3e9aa53485f74da70e16d31213d4dbdee4d3441368830e 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var core = require('@vueuse/core');
  4. let isDragging = false;
  5. function draggable(element, options) {
  6. if (!core.isClient)
  7. return;
  8. const moveFn = function(event) {
  9. var _a;
  10. (_a = options.drag) == null ? void 0 : _a.call(options, event);
  11. };
  12. const upFn = function(event) {
  13. var _a;
  14. document.removeEventListener("mousemove", moveFn);
  15. document.removeEventListener("mouseup", upFn);
  16. document.removeEventListener("touchmove", moveFn);
  17. document.removeEventListener("touchend", upFn);
  18. document.onselectstart = null;
  19. document.ondragstart = null;
  20. isDragging = false;
  21. (_a = options.end) == null ? void 0 : _a.call(options, event);
  22. };
  23. const downFn = function(event) {
  24. var _a;
  25. if (isDragging)
  26. return;
  27. event.preventDefault();
  28. document.onselectstart = () => false;
  29. document.ondragstart = () => false;
  30. document.addEventListener("mousemove", moveFn);
  31. document.addEventListener("mouseup", upFn);
  32. document.addEventListener("touchmove", moveFn);
  33. document.addEventListener("touchend", upFn);
  34. isDragging = true;
  35. (_a = options.start) == null ? void 0 : _a.call(options, event);
  36. };
  37. element.addEventListener("mousedown", downFn);
  38. element.addEventListener("touchstart", downFn, { passive: false });
  39. }
  40. exports.draggable = draggable;
  41. //# sourceMappingURL=draggable.js.map