@deot/vc-components 1.0.64 → 1.0.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1705,6 +1705,19 @@ const Card = /* @__PURE__ */ vue.defineComponent({
1705
1705
 
1706
1706
  const MCard = Card;
1707
1707
 
1708
+ const DRAG_CLICK_SUPPRESS_PX = 5;
1709
+ const swallowNextClickFromDrag = () => {
1710
+ let invoked = false;
1711
+ const options = { capture: true, once: true };
1712
+ const swallow = (e) => {
1713
+ invoked = true;
1714
+ e.preventDefault();
1715
+ e.stopPropagation();
1716
+ e.stopImmediatePropagation();
1717
+ };
1718
+ document.addEventListener("click", swallow, options);
1719
+ setTimeout(() => !invoked && document.removeEventListener("click", swallow, options), 0);
1720
+ };
1708
1721
  const useCarousel = (wrapper, content, expose) => {
1709
1722
  const instance = vue.getCurrentInstance();
1710
1723
  const props = instance.props;
@@ -1717,6 +1730,7 @@ const useCarousel = (wrapper, content, expose) => {
1717
1730
  const start = vue.ref();
1718
1731
  const startX = vue.ref();
1719
1732
  const startY = vue.ref();
1733
+ const dragMovedPastThreshold = vue.ref(false);
1720
1734
  const allowTransition = vue.ref(false);
1721
1735
  const direction = vue.computed(() => {
1722
1736
  return props.vertical ? "vertical" : "horizontal";
@@ -1795,16 +1809,21 @@ const useCarousel = (wrapper, content, expose) => {
1795
1809
  if (!props.draggable) return;
1796
1810
  pauseTimer();
1797
1811
  start.value = true;
1812
+ dragMovedPastThreshold.value = false;
1798
1813
  startX.value = e.screenX;
1799
1814
  startY.value = e.screenY;
1800
1815
  };
1801
1816
  const handleMove = (e) => {
1802
1817
  if (!start.value || !props.draggable) return;
1803
1818
  offset.value = !props.vertical ? e.screenX - startX.value : e.screenY - startY.value;
1819
+ if (Math.abs(offset.value) > DRAG_CLICK_SUPPRESS_PX) {
1820
+ dragMovedPastThreshold.value = true;
1821
+ }
1804
1822
  resetItems();
1805
1823
  };
1806
1824
  const handleEnd = () => {
1807
1825
  if (!props.draggable) return;
1826
+ const shouldSwallowClick = dragMovedPastThreshold.value;
1808
1827
  start.value = false;
1809
1828
  startTimer();
1810
1829
  const $offset = Math.abs(offset.value);
@@ -1816,6 +1835,10 @@ const useCarousel = (wrapper, content, expose) => {
1816
1835
  } else {
1817
1836
  resetItems();
1818
1837
  }
1838
+ if (shouldSwallowClick) {
1839
+ swallowNextClickFromDrag();
1840
+ }
1841
+ dragMovedPastThreshold.value = false;
1819
1842
  };
1820
1843
  vue.watch(
1821
1844
  () => items.value,
@@ -2178,7 +2201,7 @@ const useCarouselItem = (expose) => {
2178
2201
  };
2179
2202
  const calcSlideOffset = (index, activeIndex, wrapperWidth) => {
2180
2203
  const { length } = carousel.items.value;
2181
- const offset = wrapperWidth - (instance.vnode?.el?.offsetWidth || 0);
2204
+ const offset = wrapperWidth - (carousel.wrapper?.value?.offsetWidth || 0);
2182
2205
  const gutter = itemGutter.value;
2183
2206
  if (!gutter || isVertical.value) return 0;
2184
2207
  let slideOffset = 0;
@@ -2211,7 +2234,7 @@ const useCarouselItem = (expose) => {
2211
2234
  return slideOffset;
2212
2235
  };
2213
2236
  const calcTranslate = (index, activeIndex) => {
2214
- const distance = carousel.vnode.el[isVertical.value ? "offsetHeight" : "offsetWidth"];
2237
+ const distance = carousel.wrapper.value[isVertical.value ? "offsetHeight" : "offsetWidth"];
2215
2238
  const slideOffset = calcSlideOffset(index, activeIndex, distance);
2216
2239
  return distance * (index - activeIndex) + carousel.offset.value + slideOffset;
2217
2240
  };
@@ -7110,6 +7110,19 @@ var VcComponents = (function (exports, vue) {
7110
7110
  }
7111
7111
  }
7112
7112
 
7113
+ const DRAG_CLICK_SUPPRESS_PX = 5;
7114
+ const swallowNextClickFromDrag = () => {
7115
+ let invoked = false;
7116
+ const options = { capture: true, once: true };
7117
+ const swallow = (e) => {
7118
+ invoked = true;
7119
+ e.preventDefault();
7120
+ e.stopPropagation();
7121
+ e.stopImmediatePropagation();
7122
+ };
7123
+ document.addEventListener("click", swallow, options);
7124
+ setTimeout(() => !invoked && document.removeEventListener("click", swallow, options), 0);
7125
+ };
7113
7126
  const useCarousel = (wrapper, content, expose) => {
7114
7127
  const instance = vue.getCurrentInstance();
7115
7128
  const props = instance.props;
@@ -7122,6 +7135,7 @@ var VcComponents = (function (exports, vue) {
7122
7135
  const start = vue.ref();
7123
7136
  const startX = vue.ref();
7124
7137
  const startY = vue.ref();
7138
+ const dragMovedPastThreshold = vue.ref(false);
7125
7139
  const allowTransition = vue.ref(false);
7126
7140
  const direction = vue.computed(() => {
7127
7141
  return props.vertical ? "vertical" : "horizontal";
@@ -7200,16 +7214,21 @@ var VcComponents = (function (exports, vue) {
7200
7214
  if (!props.draggable) return;
7201
7215
  pauseTimer();
7202
7216
  start.value = true;
7217
+ dragMovedPastThreshold.value = false;
7203
7218
  startX.value = e.screenX;
7204
7219
  startY.value = e.screenY;
7205
7220
  };
7206
7221
  const handleMove = (e) => {
7207
7222
  if (!start.value || !props.draggable) return;
7208
7223
  offset.value = !props.vertical ? e.screenX - startX.value : e.screenY - startY.value;
7224
+ if (Math.abs(offset.value) > DRAG_CLICK_SUPPRESS_PX) {
7225
+ dragMovedPastThreshold.value = true;
7226
+ }
7209
7227
  resetItems();
7210
7228
  };
7211
7229
  const handleEnd = () => {
7212
7230
  if (!props.draggable) return;
7231
+ const shouldSwallowClick = dragMovedPastThreshold.value;
7213
7232
  start.value = false;
7214
7233
  startTimer();
7215
7234
  const $offset = Math.abs(offset.value);
@@ -7221,6 +7240,10 @@ var VcComponents = (function (exports, vue) {
7221
7240
  } else {
7222
7241
  resetItems();
7223
7242
  }
7243
+ if (shouldSwallowClick) {
7244
+ swallowNextClickFromDrag();
7245
+ }
7246
+ dragMovedPastThreshold.value = false;
7224
7247
  };
7225
7248
  vue.watch(
7226
7249
  () => items.value,
@@ -7583,7 +7606,7 @@ var VcComponents = (function (exports, vue) {
7583
7606
  };
7584
7607
  const calcSlideOffset = (index, activeIndex, wrapperWidth) => {
7585
7608
  const { length } = carousel.items.value;
7586
- const offset = wrapperWidth - (instance.vnode?.el?.offsetWidth || 0);
7609
+ const offset = wrapperWidth - (carousel.wrapper?.value?.offsetWidth || 0);
7587
7610
  const gutter = itemGutter.value;
7588
7611
  if (!gutter || isVertical.value) return 0;
7589
7612
  let slideOffset = 0;
@@ -7616,7 +7639,7 @@ var VcComponents = (function (exports, vue) {
7616
7639
  return slideOffset;
7617
7640
  };
7618
7641
  const calcTranslate = (index, activeIndex) => {
7619
- const distance = carousel.vnode.el[isVertical.value ? "offsetHeight" : "offsetWidth"];
7642
+ const distance = carousel.wrapper.value[isVertical.value ? "offsetHeight" : "offsetWidth"];
7620
7643
  const slideOffset = calcSlideOffset(index, activeIndex, distance);
7621
7644
  return distance * (index - activeIndex) + carousel.offset.value + slideOffset;
7622
7645
  };
package/dist/index.js CHANGED
@@ -1683,6 +1683,19 @@ const Card = /* @__PURE__ */ defineComponent({
1683
1683
 
1684
1684
  const MCard = Card;
1685
1685
 
1686
+ const DRAG_CLICK_SUPPRESS_PX = 5;
1687
+ const swallowNextClickFromDrag = () => {
1688
+ let invoked = false;
1689
+ const options = { capture: true, once: true };
1690
+ const swallow = (e) => {
1691
+ invoked = true;
1692
+ e.preventDefault();
1693
+ e.stopPropagation();
1694
+ e.stopImmediatePropagation();
1695
+ };
1696
+ document.addEventListener("click", swallow, options);
1697
+ setTimeout(() => !invoked && document.removeEventListener("click", swallow, options), 0);
1698
+ };
1686
1699
  const useCarousel = (wrapper, content, expose) => {
1687
1700
  const instance = getCurrentInstance();
1688
1701
  const props = instance.props;
@@ -1695,6 +1708,7 @@ const useCarousel = (wrapper, content, expose) => {
1695
1708
  const start = ref();
1696
1709
  const startX = ref();
1697
1710
  const startY = ref();
1711
+ const dragMovedPastThreshold = ref(false);
1698
1712
  const allowTransition = ref(false);
1699
1713
  const direction = computed(() => {
1700
1714
  return props.vertical ? "vertical" : "horizontal";
@@ -1773,16 +1787,21 @@ const useCarousel = (wrapper, content, expose) => {
1773
1787
  if (!props.draggable) return;
1774
1788
  pauseTimer();
1775
1789
  start.value = true;
1790
+ dragMovedPastThreshold.value = false;
1776
1791
  startX.value = e.screenX;
1777
1792
  startY.value = e.screenY;
1778
1793
  };
1779
1794
  const handleMove = (e) => {
1780
1795
  if (!start.value || !props.draggable) return;
1781
1796
  offset.value = !props.vertical ? e.screenX - startX.value : e.screenY - startY.value;
1797
+ if (Math.abs(offset.value) > DRAG_CLICK_SUPPRESS_PX) {
1798
+ dragMovedPastThreshold.value = true;
1799
+ }
1782
1800
  resetItems();
1783
1801
  };
1784
1802
  const handleEnd = () => {
1785
1803
  if (!props.draggable) return;
1804
+ const shouldSwallowClick = dragMovedPastThreshold.value;
1786
1805
  start.value = false;
1787
1806
  startTimer();
1788
1807
  const $offset = Math.abs(offset.value);
@@ -1794,6 +1813,10 @@ const useCarousel = (wrapper, content, expose) => {
1794
1813
  } else {
1795
1814
  resetItems();
1796
1815
  }
1816
+ if (shouldSwallowClick) {
1817
+ swallowNextClickFromDrag();
1818
+ }
1819
+ dragMovedPastThreshold.value = false;
1797
1820
  };
1798
1821
  watch(
1799
1822
  () => items.value,
@@ -2156,7 +2179,7 @@ const useCarouselItem = (expose) => {
2156
2179
  };
2157
2180
  const calcSlideOffset = (index, activeIndex, wrapperWidth) => {
2158
2181
  const { length } = carousel.items.value;
2159
- const offset = wrapperWidth - (instance.vnode?.el?.offsetWidth || 0);
2182
+ const offset = wrapperWidth - (carousel.wrapper?.value?.offsetWidth || 0);
2160
2183
  const gutter = itemGutter.value;
2161
2184
  if (!gutter || isVertical.value) return 0;
2162
2185
  let slideOffset = 0;
@@ -2189,7 +2212,7 @@ const useCarouselItem = (expose) => {
2189
2212
  return slideOffset;
2190
2213
  };
2191
2214
  const calcTranslate = (index, activeIndex) => {
2192
- const distance = carousel.vnode.el[isVertical.value ? "offsetHeight" : "offsetWidth"];
2215
+ const distance = carousel.wrapper.value[isVertical.value ? "offsetHeight" : "offsetWidth"];
2193
2216
  const slideOffset = calcSlideOffset(index, activeIndex, distance);
2194
2217
  return distance * (index - activeIndex) + carousel.offset.value + slideOffset;
2195
2218
  };
@@ -7113,6 +7113,19 @@
7113
7113
  }
7114
7114
  }
7115
7115
 
7116
+ const DRAG_CLICK_SUPPRESS_PX = 5;
7117
+ const swallowNextClickFromDrag = () => {
7118
+ let invoked = false;
7119
+ const options = { capture: true, once: true };
7120
+ const swallow = (e) => {
7121
+ invoked = true;
7122
+ e.preventDefault();
7123
+ e.stopPropagation();
7124
+ e.stopImmediatePropagation();
7125
+ };
7126
+ document.addEventListener("click", swallow, options);
7127
+ setTimeout(() => !invoked && document.removeEventListener("click", swallow, options), 0);
7128
+ };
7116
7129
  const useCarousel = (wrapper, content, expose) => {
7117
7130
  const instance = vue.getCurrentInstance();
7118
7131
  const props = instance.props;
@@ -7125,6 +7138,7 @@
7125
7138
  const start = vue.ref();
7126
7139
  const startX = vue.ref();
7127
7140
  const startY = vue.ref();
7141
+ const dragMovedPastThreshold = vue.ref(false);
7128
7142
  const allowTransition = vue.ref(false);
7129
7143
  const direction = vue.computed(() => {
7130
7144
  return props.vertical ? "vertical" : "horizontal";
@@ -7203,16 +7217,21 @@
7203
7217
  if (!props.draggable) return;
7204
7218
  pauseTimer();
7205
7219
  start.value = true;
7220
+ dragMovedPastThreshold.value = false;
7206
7221
  startX.value = e.screenX;
7207
7222
  startY.value = e.screenY;
7208
7223
  };
7209
7224
  const handleMove = (e) => {
7210
7225
  if (!start.value || !props.draggable) return;
7211
7226
  offset.value = !props.vertical ? e.screenX - startX.value : e.screenY - startY.value;
7227
+ if (Math.abs(offset.value) > DRAG_CLICK_SUPPRESS_PX) {
7228
+ dragMovedPastThreshold.value = true;
7229
+ }
7212
7230
  resetItems();
7213
7231
  };
7214
7232
  const handleEnd = () => {
7215
7233
  if (!props.draggable) return;
7234
+ const shouldSwallowClick = dragMovedPastThreshold.value;
7216
7235
  start.value = false;
7217
7236
  startTimer();
7218
7237
  const $offset = Math.abs(offset.value);
@@ -7224,6 +7243,10 @@
7224
7243
  } else {
7225
7244
  resetItems();
7226
7245
  }
7246
+ if (shouldSwallowClick) {
7247
+ swallowNextClickFromDrag();
7248
+ }
7249
+ dragMovedPastThreshold.value = false;
7227
7250
  };
7228
7251
  vue.watch(
7229
7252
  () => items.value,
@@ -7586,7 +7609,7 @@
7586
7609
  };
7587
7610
  const calcSlideOffset = (index, activeIndex, wrapperWidth) => {
7588
7611
  const { length } = carousel.items.value;
7589
- const offset = wrapperWidth - (instance.vnode?.el?.offsetWidth || 0);
7612
+ const offset = wrapperWidth - (carousel.wrapper?.value?.offsetWidth || 0);
7590
7613
  const gutter = itemGutter.value;
7591
7614
  if (!gutter || isVertical.value) return 0;
7592
7615
  let slideOffset = 0;
@@ -7619,7 +7642,7 @@
7619
7642
  return slideOffset;
7620
7643
  };
7621
7644
  const calcTranslate = (index, activeIndex) => {
7622
- const distance = carousel.vnode.el[isVertical.value ? "offsetHeight" : "offsetWidth"];
7645
+ const distance = carousel.wrapper.value[isVertical.value ? "offsetHeight" : "offsetWidth"];
7623
7646
  const slideOffset = calcSlideOffset(index, activeIndex, distance);
7624
7647
  return distance * (index - activeIndex) + carousel.offset.value + slideOffset;
7625
7648
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deot/vc-components",
3
- "version": "1.0.64",
3
+ "version": "1.0.65",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",