febf1a9c278822befa2bd2ae511e6f7efb5bf36816e1ac06260bd5bda82fcd0e1a6897e99e95511380aa678aba319e94c499047ad58062552fccea9d85925a 1.3 KB

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