From 4bab04611852792db6fb9f96d9a99159abed24b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=E1=BB=8Bnh=20Huy=20Nam?= <38585889+huynamboz@users.noreply.github.com> Date: Thu, 8 Aug 2024 19:17:45 +0700 Subject: [PATCH] fix: type definition (#39) --- dist/declarations/index.d.ts | 2 +- dist/vue-drag-scroller.es.js | 53 ++++++++++++++++++----------------- dist/vue-drag-scroller.umd.js | 2 +- example/main.ts | 2 +- package.json | 8 +++--- 5 files changed, 35 insertions(+), 32 deletions(-) diff --git a/dist/declarations/index.d.ts b/dist/declarations/index.d.ts index 58b12a4..872515a 100644 --- a/dist/declarations/index.d.ts +++ b/dist/declarations/index.d.ts @@ -1,4 +1,4 @@ -import { App, DirectiveBinding } from 'vue'; +import type { App, DirectiveBinding } from 'vue'; interface ICustomBinding extends DirectiveBinding { value: { startScroll?: (e: MouseEvent) => void; diff --git a/dist/vue-drag-scroller.es.js b/dist/vue-drag-scroller.es.js index 914de2c..16b5a47 100644 --- a/dist/vue-drag-scroller.es.js +++ b/dist/vue-drag-scroller.es.js @@ -1,42 +1,45 @@ -const g = "drag-scroller-disable", w = /* @__PURE__ */ (() => { - const s = /* @__PURE__ */ new WeakMap(); +const D = "drag-scroller-disable", w = /* @__PURE__ */ (() => { + const n = /* @__PURE__ */ new WeakMap(); return { - mounted(r, l) { + mounted(r, a) { let o = !1; - const { onlyX: n, onlyY: i, disablechild: E } = l.modifiers, e = l.value ?? {}, p = new Event("scrollStart", { bubbles: !0 }), b = new Event("scrollMoving", { bubbles: !0 }), D = new Event("scrollEnd", { bubbles: !0 }); - e.hideScrollbar === !0 && (r.style.overflow = "hidden"); - const L = (t) => { + const { onlyX: l, onlyY: c, disablechild: E } = a.modifiers, t = a.value ?? {}, p = new Event("scrollStart", { bubbles: !0 }), L = new Event("scrollMoving", { bubbles: !0 }), b = new Event("scrollEnd", { bubbles: !0 }); + t.hideScrollbar === !0 && (r.style.overflow = "hidden"); + const g = (e) => { if (E) - return t === r; - for (; t && t.parentNode; ) { - if (t && (t != null && t.hasAttribute(g))) + return e === r; + for (; e && e.parentNode; ) { + if (e && (e != null && e.hasAttribute(D))) return !1; - if (t === r) + if (e === r) return !0; - t = t.parentNode; + e = e.parentNode; } return !1; - }, c = (t) => { - o = L(t.target), r.dispatchEvent(p), o && (e != null && e.startScroll) && typeof (e == null ? void 0 : e.startScroll) == "function" && e.startScroll(t); - }, f = (t) => { - r.dispatchEvent(D), o && (e != null && e.endScroll) && typeof (e == null ? void 0 : e.endScroll) == "function" && e.endScroll(t), o = !1; - }, u = (t) => { - var S; + }, d = (e) => { + o = g(e.target), r.dispatchEvent(p), o && (t != null && t.startScroll) && typeof (t == null ? void 0 : t.startScroll) == "function" && t.startScroll(e); + }, u = (e) => { + r.dispatchEvent(b), o && (t != null && t.endScroll) && typeof (t == null ? void 0 : t.endScroll) == "function" && t.endScroll(e), o = !1; + }, v = (e) => { if (!o) return !1; - r.dispatchEvent(b), e != null && e.onScrolling && typeof (e == null ? void 0 : e.onScrolling) == "function" && e.onScrolling(t), t.stopPropagation && t.stopPropagation(), t.preventDefault && t.preventDefault(), (S = window.getSelection()) == null || S.removeAllRanges(), t.cancelBubble = !0, t.returnValue = !1; - const a = (e == null ? void 0 : e.speed) || 1, d = e.reverseDirection ? t.movementX * a : -t.movementX * a, v = e.reverseDirection ? t.movementY * a : -t.movementY * a; - n ? r.scrollLeft += d : (i || (r.scrollLeft += d), r.scrollTop += v); + r.dispatchEvent(L), t != null && t.onScrolling && typeof (t == null ? void 0 : t.onScrolling) == "function" && t.onScrolling(e); + const s = (t == null ? void 0 : t.speed) || 1, i = t.reverseDirection ? e.movementX * s : -e.movementX * s, S = t.reverseDirection ? e.movementY * s : -e.movementY * s; + return l ? r.scrollLeft += i : (c || (r.scrollLeft += i), r.scrollTop += S), f(e), !1; }; - s.set(r, { dragStart: c, dragEnd: f, drag: u }), r.addEventListener("pointerdown", c), addEventListener("pointerup", f), addEventListener("pointermove", u); + function f(e) { + var s; + (e == null ? void 0 : e.target) instanceof HTMLImageElement && e.preventDefault && e.preventDefault(), (s = window.getSelection()) == null || s.removeAllRanges(); + } + n.set(r, { dragStart: d, dragEnd: u, drag: v, preventSelection: f }), r.addEventListener("pointerdown", d), r.addEventListener("dragstart", f), addEventListener("pointerup", u), addEventListener("pointermove", v); }, unmounted(r) { - const { dragStart: l, dragEnd: o, drag: n } = s.get(r); - r.removeEventListener("pointerdown", l), removeEventListener("pointerup", o), removeEventListener("pointermove", n); + const { dragStart: a, dragEnd: o, drag: l, preventSelection: c } = n.get(r); + r.removeEventListener("pointerdown", a), r.removeEventListener("dragstart", c), removeEventListener("pointerup", o), removeEventListener("pointermove", l); } }; })(), h = { - install(s) { - s.directive("drag-scroller", w); + install(n) { + n.directive("drag-scroller", w); } }; export { diff --git a/dist/vue-drag-scroller.umd.js b/dist/vue-drag-scroller.umd.js index 5414f4f..92b216f 100644 --- a/dist/vue-drag-scroller.umd.js +++ b/dist/vue-drag-scroller.umd.js @@ -1 +1 @@ -(function(o,n){typeof exports=="object"&&typeof module<"u"?n(exports):typeof define=="function"&&define.amd?define(["exports"],n):(o=typeof globalThis<"u"?globalThis:o||self,n(o["vue-drag-scroller"]={}))})(this,function(o){"use strict";const n="drag-scroller-disable",u=(()=>{const l=new WeakMap;return{mounted(r,c){let s=!1;const{onlyX:f,onlyY:g,disablechild:h}=c.modifiers,e=c.value??{},D=new Event("scrollStart",{bubbles:!0}),L=new Event("scrollMoving",{bubbles:!0}),w=new Event("scrollEnd",{bubbles:!0});e.hideScrollbar===!0&&(r.style.overflow="hidden");const y=t=>{if(h)return t===r;for(;t&&t.parentNode;){if(t&&(t!=null&&t.hasAttribute(n)))return!1;if(t===r)return!0;t=t.parentNode}return!1},d=t=>{s=y(t.target),r.dispatchEvent(D),s&&(e!=null&&e.startScroll)&&typeof(e==null?void 0:e.startScroll)=="function"&&e.startScroll(t)},i=t=>{r.dispatchEvent(w),s&&(e!=null&&e.endScroll)&&typeof(e==null?void 0:e.endScroll)=="function"&&e.endScroll(t),s=!1},v=t=>{var b;if(!s)return!1;r.dispatchEvent(L),e!=null&&e.onScrolling&&typeof(e==null?void 0:e.onScrolling)=="function"&&e.onScrolling(t),t.stopPropagation&&t.stopPropagation(),t.preventDefault&&t.preventDefault(),(b=window.getSelection())==null||b.removeAllRanges(),t.cancelBubble=!0,t.returnValue=!1;const a=(e==null?void 0:e.speed)||1,S=e.reverseDirection?t.movementX*a:-t.movementX*a,p=e.reverseDirection?t.movementY*a:-t.movementY*a;f?r.scrollLeft+=S:(g||(r.scrollLeft+=S),r.scrollTop+=p)};l.set(r,{dragStart:d,dragEnd:i,drag:v}),r.addEventListener("pointerdown",d),addEventListener("pointerup",i),addEventListener("pointermove",v)},unmounted(r){const{dragStart:c,dragEnd:s,drag:f}=l.get(r);r.removeEventListener("pointerdown",c),removeEventListener("pointerup",s),removeEventListener("pointermove",f)}}})(),E={install(l){l.directive("drag-scroller",u)}};o.default=E,o.dragScroller=u,o.vDragScroller=u,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); +(function(o,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(o=typeof globalThis<"u"?globalThis:o||self,l(o["vue-drag-scroller"]={}))})(this,function(o){"use strict";const l="drag-scroller-disable",f=(()=>{const c=new WeakMap;return{mounted(r,a){let n=!1;const{onlyX:d,onlyY:u,disablechild:L}=a.modifiers,t=a.value??{},h=new Event("scrollStart",{bubbles:!0}),D=new Event("scrollMoving",{bubbles:!0}),w=new Event("scrollEnd",{bubbles:!0});t.hideScrollbar===!0&&(r.style.overflow="hidden");const m=e=>{if(L)return e===r;for(;e&&e.parentNode;){if(e&&(e!=null&&e.hasAttribute(l)))return!1;if(e===r)return!0;e=e.parentNode}return!1},v=e=>{n=m(e.target),r.dispatchEvent(h),n&&(t!=null&&t.startScroll)&&typeof(t==null?void 0:t.startScroll)=="function"&&t.startScroll(e)},S=e=>{r.dispatchEvent(w),n&&(t!=null&&t.endScroll)&&typeof(t==null?void 0:t.endScroll)=="function"&&t.endScroll(e),n=!1},E=e=>{if(!n)return!1;r.dispatchEvent(D),t!=null&&t.onScrolling&&typeof(t==null?void 0:t.onScrolling)=="function"&&t.onScrolling(e);const s=(t==null?void 0:t.speed)||1,p=t.reverseDirection?e.movementX*s:-e.movementX*s,b=t.reverseDirection?e.movementY*s:-e.movementY*s;return d?r.scrollLeft+=p:(u||(r.scrollLeft+=p),r.scrollTop+=b),i(e),!1};function i(e){var s;(e==null?void 0:e.target)instanceof HTMLImageElement&&e.preventDefault&&e.preventDefault(),(s=window.getSelection())==null||s.removeAllRanges()}c.set(r,{dragStart:v,dragEnd:S,drag:E,preventSelection:i}),r.addEventListener("pointerdown",v),r.addEventListener("dragstart",i),addEventListener("pointerup",S),addEventListener("pointermove",E)},unmounted(r){const{dragStart:a,dragEnd:n,drag:d,preventSelection:u}=c.get(r);r.removeEventListener("pointerdown",a),r.removeEventListener("dragstart",u),removeEventListener("pointerup",n),removeEventListener("pointermove",d)}}})(),g={install(c){c.directive("drag-scroller",f)}};o.default=g,o.dragScroller=f,o.vDragScroller=f,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); diff --git a/example/main.ts b/example/main.ts index f26f7f2..4012469 100644 --- a/example/main.ts +++ b/example/main.ts @@ -1,6 +1,6 @@ import './assets/main.css' import { createApp } from 'vue' -import VueDragScroller from "../src" +import VueDragScroller from "vue-drag-scroller" import App from './App.vue' const app = createApp(App) diff --git a/package.json b/package.json index 7137881..4c95cee 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,21 @@ { "name": "vue-drag-scroller", - "version": "1.8.4", + "version": "1.8.5", "type": "module", "license": "MIT", "description": "A vue directive that helps you scroll in a more natural way.", "module": "dist/vue-drag-scroller.es.js", "main": "dist/vue-drag-scroller.js", - "types": "src/types.d.ts", + "types": "dist/declarations/index.d.ts", "exports": { ".": { "import": "./dist/vue-drag-scroller.es.js", "require": "./dist/vue-drag-scroller.js", - "types": "./src/types.d.ts" + "types": "./dist/declarations/index.d.ts" }, "./package.json": "./package.json", "./dist/*": "./dist/*", - "./src/types.d.ts": "./src/types.d.ts" + "./dist/declarations/index.d.ts": "./dist/declarations/index.d.ts" }, "scripts": { "dev": "vite --mode app",