index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. require('../../utils/index.js');
  4. var shared = require('@vue/shared');
  5. const REPEAT_INTERVAL = 100;
  6. const REPEAT_DELAY = 600;
  7. const vRepeatClick = {
  8. beforeMount(el, binding) {
  9. const value = binding.value;
  10. const { interval = REPEAT_INTERVAL, delay = REPEAT_DELAY } = shared.isFunction(value) ? {} : value;
  11. let intervalId;
  12. let delayId;
  13. const handler = () => shared.isFunction(value) ? value() : value.handler();
  14. const clear = () => {
  15. if (delayId) {
  16. clearTimeout(delayId);
  17. delayId = void 0;
  18. }
  19. if (intervalId) {
  20. clearInterval(intervalId);
  21. intervalId = void 0;
  22. }
  23. };
  24. el.addEventListener("mousedown", (evt) => {
  25. if (evt.button !== 0)
  26. return;
  27. clear();
  28. handler();
  29. document.addEventListener("mouseup", () => clear(), {
  30. once: true
  31. });
  32. delayId = setTimeout(() => {
  33. intervalId = setInterval(() => {
  34. handler();
  35. }, interval);
  36. }, delay);
  37. });
  38. }
  39. };
  40. exports.REPEAT_DELAY = REPEAT_DELAY;
  41. exports.REPEAT_INTERVAL = REPEAT_INTERVAL;
  42. exports.vRepeatClick = vRepeatClick;
  43. //# sourceMappingURL=index.js.map