vue3-pull-refresh 1.0.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Amir Rafati
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # vue3-pull-refresh
2
+
3
+ 一个基于 **Vue3** 的下拉刷新组件,支持鼠标拖拽 & 触摸手势,适用于移动端/PC。
4
+ 轻量、无依赖,支持自定义头部内容。
5
+
6
+ 🔹 安装
7
+
8
+ ```bash
9
+ npm install vue3-pull-refresh
10
+
11
+ # 或者
12
+
13
+ yarn add vue3-pull-refresh
14
+ ```
15
+
16
+ 🔹 基本使用
17
+
18
+ ```vue
19
+ <template>
20
+ <PullRefresh v-model="loading" @refresh="loadData">
21
+ <div v-for="item in list" :key="item.id">{{ item.text }}</div>
22
+ </PullRefresh>
23
+ </template>
24
+
25
+ <script setup>
26
+ import { ref } from 'vue';
27
+ import PullRefresh from 'vue3-pull-refresh';
28
+
29
+ const loading = ref(false);
30
+ const list = ref([{ id: 1, text: '数据 1' }]);
31
+
32
+ async function loadData() {
33
+ loading.value = true;
34
+ await new Promise((r) => setTimeout(r, 1000));
35
+ list.value.unshift({ id: Date.now(), text: '新数据' });
36
+ loading.value = false;
37
+ }
38
+ </script>
39
+ ```
40
+
41
+ 🔹 Props
42
+
43
+ | 属性 | 类型 | 默认值 | 说明 |
44
+ | ------------------- | --------- | ------------------- | --------------------------------- |
45
+ | `modelValue` | `Boolean` | `false` | 刷新状态,使用 `v-model` 双向绑定 |
46
+ | `pullingText` | `String` | `'下拉即可刷新...'` | 下拉状态文案 |
47
+ | `loosingText` | `String` | `'释放即可刷新...'` | 超过阈值松手文案 |
48
+ | `loadingText` | `String` | `'加载中...'` | 刷新中文案 |
49
+ | `headerHeight` | `Number` | `64` | 触发刷新所需拉动距离(px) |
50
+ | `animationDuration` | `Number` | `200` | 位移动画时间(ms) |
51
+ | `disabled` | `Boolean` | `false` | 禁用下拉刷新 |
52
+
53
+ 🔹 事件
54
+
55
+ | 事件 | 参数 | 说明 |
56
+ | ------------------- | --------- | ---------------------------------------------------- |
57
+ | `refresh` | 无 | 当下拉距离超过阈值并松手时触发,由父组件控制刷新逻辑 |
58
+ | `update:modelValue` | `Boolean` | 同步刷新状态,父组件通过 `v-model` 接收 |
59
+
60
+ 🔹 插槽
61
+
62
+ | 名称 | 说明 |
63
+ | --------- | ---------------------------------------------------------------------------------- |
64
+ | `default` | 内容区域,必须提供滚动内容 |
65
+ | header | 自定义头部,可以获取状态:`status`(`normal` / `pulling` / `loosing` / `loading`) |
66
+
67
+ 示例:
68
+
69
+ ```vue
70
+ <PullRefresh v-model="loading">
71
+ <template #header="{ status }">
72
+ <div v-if="status === 'loading'">刷新中...</div>
73
+ <div v-else-if="status === 'loosing'">松手刷新</div>
74
+ <div v-else>下拉刷新</div>
75
+ </template>
76
+
77
+ <div v-for="item in list" :key="item.id">{{ item.text }}</div>
78
+ </PullRefresh>
79
+ ```
80
+
81
+ 🔹 注意事项
82
+
83
+ 1. 组件依赖 Vue 3,请确保项目环境正确。
84
+ 2. 通过 v-model 控制刷新状态,父组件负责完成异步操作后将 modelValue 设置为 false,组件才会复位。
85
+ 3. 默认触发刷新距离为 64px,可通过 headerHeight 调整。
@@ -0,0 +1,73 @@
1
+ interface Props {
2
+ modelValue: boolean;
3
+ pullingText?: string;
4
+ loosingText?: string;
5
+ loadingText?: string;
6
+ headerHeight?: number;
7
+ animationDuration?: number;
8
+ disabled?: boolean;
9
+ }
10
+ declare function __VLS_template(): {
11
+ header?(_: {
12
+ status: "pulling" | "loosing" | "loading";
13
+ distance: number;
14
+ }): any;
15
+ default?(_: {}): any;
16
+ };
17
+ declare const __VLS_component: import('vue').DefineComponent<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Props>, {
18
+ modelValue: boolean;
19
+ pullingText: string;
20
+ loosingText: string;
21
+ loadingText: string;
22
+ headerHeight: number;
23
+ animationDuration: number;
24
+ disabled: boolean;
25
+ }>>, {
26
+ scroller: import('vue').Ref<HTMLDivElement | undefined, HTMLDivElement | undefined>;
27
+ }, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
28
+ "update:modelValue": (v: boolean) => void;
29
+ refresh: () => void;
30
+ }, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Props>, {
31
+ modelValue: boolean;
32
+ pullingText: string;
33
+ loosingText: string;
34
+ loadingText: string;
35
+ headerHeight: number;
36
+ animationDuration: number;
37
+ disabled: boolean;
38
+ }>>> & Readonly<{
39
+ "onUpdate:modelValue"?: ((v: boolean) => any) | undefined;
40
+ onRefresh?: (() => any) | undefined;
41
+ }>, {
42
+ modelValue: boolean;
43
+ pullingText: string;
44
+ loosingText: string;
45
+ loadingText: string;
46
+ headerHeight: number;
47
+ animationDuration: number;
48
+ disabled: boolean;
49
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
50
+ declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
51
+ export default _default;
52
+ type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
53
+ type __VLS_TypePropsToRuntimeProps<T> = {
54
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
55
+ type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
56
+ } : {
57
+ type: import('vue').PropType<T[K]>;
58
+ required: true;
59
+ };
60
+ };
61
+ type __VLS_WithDefaults<P, D> = {
62
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
63
+ default: D[K];
64
+ }> : P[K];
65
+ };
66
+ type __VLS_Prettify<T> = {
67
+ [K in keyof T]: T[K];
68
+ } & {};
69
+ type __VLS_WithTemplateSlots<T, S> = T & {
70
+ new (): {
71
+ $slots: S;
72
+ };
73
+ };
@@ -0,0 +1,3 @@
1
+ import { default as PullRefresh } from './PullRefresh.vue';
2
+
3
+ export default PullRefresh;
@@ -0,0 +1,123 @@
1
+ import { defineComponent as k, ref as w, reactive as T, computed as B, watch as R, createElementBlock as _, openBlock as v, createCommentVNode as b, createElementVNode as x, normalizeStyle as y, renderSlot as M, toDisplayString as E } from "vue";
2
+ const P = { class: "vpr-pull-refresh__header__txt" }, C = /* @__PURE__ */ k({
3
+ __name: "PullRefresh",
4
+ props: {
5
+ modelValue: { type: Boolean, default: !1 },
6
+ pullingText: { default: "下拉即可刷新..." },
7
+ loosingText: { default: "释放即可刷新..." },
8
+ loadingText: { default: "加载中..." },
9
+ headerHeight: { default: 64 },
10
+ animationDuration: { default: 200 },
11
+ disabled: { type: Boolean, default: !1 }
12
+ },
13
+ emits: ["update:modelValue", "refresh"],
14
+ setup(u, { expose: f, emit: c }) {
15
+ const l = w(), a = u, h = c, n = T({
16
+ scrollerTransition: "",
17
+ scrollerTranslate: "",
18
+ headerTransition: "",
19
+ headerTranslate: ""
20
+ }), t = T({
21
+ status: "normal",
22
+ startY: 0,
23
+ pulling: !1,
24
+ distance: 0
25
+ }), H = B(() => {
26
+ switch (t.status) {
27
+ case "loading":
28
+ return a.loadingText;
29
+ case "loosing":
30
+ return a.loosingText;
31
+ case "pulling":
32
+ return a.pullingText;
33
+ default:
34
+ return a.pullingText;
35
+ }
36
+ });
37
+ function Y(e) {
38
+ const s = a.headerHeight, o = Math.max(0, e);
39
+ return o <= s ? o : s + Math.log2(o - s + 1) * 5;
40
+ }
41
+ function r(e, s = !1) {
42
+ t.distance = Math.max(0, e), n.scrollerTransition = s ? `transform ${a.animationDuration}ms ease` : "none", n.scrollerTranslate = `translate3d(0, ${t.distance}px, 0)`, n.headerTransition = s ? `transform ${a.animationDuration}ms ease` : "none", n.headerTranslate = `translate3d(0, ${t.distance - a.headerHeight}px, 0)`;
43
+ }
44
+ function i(e, s) {
45
+ if (s) {
46
+ t.status = "loading";
47
+ return;
48
+ }
49
+ e >= a.headerHeight ? t.status = "loosing" : e > 0 ? t.status = "pulling" : t.status = "normal";
50
+ }
51
+ function p(e) {
52
+ a.disabled || l.value && l.value.scrollTop <= 0 && (t.pulling = !0, t.startY = e, r(0, !1), i(0, !1));
53
+ }
54
+ function m(e, s) {
55
+ if (!t.pulling) return;
56
+ const o = e - t.startY;
57
+ if (o > 0) {
58
+ const g = Y(o);
59
+ s == null || s.preventDefault(), r(g, !1), i(g, !1);
60
+ } else
61
+ r(0, !0), t.pulling = !1;
62
+ }
63
+ function d() {
64
+ t.pulling && (t.pulling = !1, t.distance >= a.headerHeight ? (r(a.headerHeight, !0), i(t.distance, !0), h("update:modelValue", !0), h("refresh")) : (r(0, !0), i(0, !1)));
65
+ }
66
+ R(
67
+ () => a.modelValue,
68
+ (e) => {
69
+ e || (r(0, !0), i(0, !1));
70
+ }
71
+ );
72
+ const D = (e) => p(e.clientY), S = (e) => m(e.clientY, e), V = (e) => p(e.touches[0].clientY), $ = (e) => m(e.touches[0].clientY, e);
73
+ return f({
74
+ scroller: l
75
+ }), (e, s) => (v(), _("div", {
76
+ class: "vpr-pull-refresh",
77
+ onMousedown: D,
78
+ onMousemove: S,
79
+ onMouseup: d,
80
+ onMouseleave: d,
81
+ onTouchstart: V,
82
+ onTouchmove: $,
83
+ onTouchend: d,
84
+ onTouchcancel: d
85
+ }, [
86
+ !a.disabled && t.status !== "normal" ? (v(), _("div", {
87
+ key: 0,
88
+ class: "vpr-pull-refresh__header",
89
+ style: y({
90
+ height: a.headerHeight + "px",
91
+ transform: n.headerTranslate,
92
+ transition: n.headerTransition
93
+ })
94
+ }, [
95
+ M(e.$slots, "header", {
96
+ status: t.status,
97
+ distance: t.distance
98
+ }, () => [
99
+ x("div", P, E(H.value), 1)
100
+ ], !0)
101
+ ], 4)) : b("", !0),
102
+ x("div", {
103
+ class: "vpr-pull-refresh__scroll",
104
+ ref_key: "scrollerRef",
105
+ ref: l,
106
+ style: y({
107
+ transform: n.scrollerTranslate,
108
+ transition: n.scrollerTransition
109
+ })
110
+ }, [
111
+ M(e.$slots, "default", {}, void 0, !0)
112
+ ], 4)
113
+ ], 32));
114
+ }
115
+ }), N = (u, f) => {
116
+ const c = u.__vccOpts || u;
117
+ for (const [l, a] of f)
118
+ c[l] = a;
119
+ return c;
120
+ }, z = /* @__PURE__ */ N(C, [["__scopeId", "data-v-9195ae68"]]);
121
+ export {
122
+ z as default
123
+ };
@@ -0,0 +1 @@
1
+ (function(t,u){typeof exports=="object"&&typeof module<"u"?module.exports=u(require("vue")):typeof define=="function"&&define.amd?define(["vue"],u):(t=typeof globalThis<"u"?globalThis:t||self,t.Vue3PullRefresh=u(t.Vue))})(this,function(t){"use strict";const u={class:"vpr-pull-refresh__header__txt"};return((d,p)=>{const f=d.__vccOpts||d;for(const[r,s]of p)f[r]=s;return f})(t.defineComponent({__name:"PullRefresh",props:{modelValue:{type:Boolean,default:!1},pullingText:{default:"下拉即可刷新..."},loosingText:{default:"释放即可刷新..."},loadingText:{default:"加载中..."},headerHeight:{default:64},animationDuration:{default:200},disabled:{type:Boolean,default:!1}},emits:["update:modelValue","refresh"],setup(d,{expose:p,emit:f}){const r=t.ref(),s=d,m=f,l=t.reactive({scrollerTransition:"",scrollerTranslate:"",headerTransition:"",headerTranslate:""}),n=t.reactive({status:"normal",startY:0,pulling:!1,distance:0}),x=t.computed(()=>{switch(n.status){case"loading":return s.loadingText;case"loosing":return s.loosingText;case"pulling":return s.pullingText;default:return s.pullingText}});function y(e){const a=s.headerHeight,i=Math.max(0,e);return i<=a?i:a+Math.log2(i-a+1)*5}function o(e,a=!1){n.distance=Math.max(0,e),l.scrollerTransition=a?`transform ${s.animationDuration}ms ease`:"none",l.scrollerTranslate=`translate3d(0, ${n.distance}px, 0)`,l.headerTransition=a?`transform ${s.animationDuration}ms ease`:"none",l.headerTranslate=`translate3d(0, ${n.distance-s.headerHeight}px, 0)`}function c(e,a){if(a){n.status="loading";return}e>=s.headerHeight?n.status="loosing":e>0?n.status="pulling":n.status="normal"}function g(e){s.disabled||r.value&&r.value.scrollTop<=0&&(n.pulling=!0,n.startY=e,o(0,!1),c(0,!1))}function T(e,a){if(!n.pulling)return;const i=e-n.startY;if(i>0){const _=y(i);a==null||a.preventDefault(),o(_,!1),c(_,!1)}else o(0,!0),n.pulling=!1}function h(){n.pulling&&(n.pulling=!1,n.distance>=s.headerHeight?(o(s.headerHeight,!0),c(n.distance,!0),m("update:modelValue",!0),m("refresh")):(o(0,!0),c(0,!1)))}t.watch(()=>s.modelValue,e=>{e||(o(0,!0),c(0,!1))});const M=e=>g(e.clientY),V=e=>T(e.clientY,e),H=e=>g(e.touches[0].clientY),S=e=>T(e.touches[0].clientY,e);return p({scroller:r}),(e,a)=>(t.openBlock(),t.createElementBlock("div",{class:"vpr-pull-refresh",onMousedown:M,onMousemove:V,onMouseup:h,onMouseleave:h,onTouchstart:H,onTouchmove:S,onTouchend:h,onTouchcancel:h},[!s.disabled&&n.status!=="normal"?(t.openBlock(),t.createElementBlock("div",{key:0,class:"vpr-pull-refresh__header",style:t.normalizeStyle({height:s.headerHeight+"px",transform:l.headerTranslate,transition:l.headerTransition})},[t.renderSlot(e.$slots,"header",{status:n.status,distance:n.distance},()=>[t.createElementVNode("div",u,t.toDisplayString(x.value),1)],!0)],4)):t.createCommentVNode("",!0),t.createElementVNode("div",{class:"vpr-pull-refresh__scroll",ref_key:"scrollerRef",ref:r,style:t.normalizeStyle({transform:l.scrollerTranslate,transition:l.scrollerTransition})},[t.renderSlot(e.$slots,"default",{},void 0,!0)],4)],32))}}),[["__scopeId","data-v-9195ae68"]])});
package/dist/style.css ADDED
@@ -0,0 +1 @@
1
+ .vpr-pull-refresh[data-v-9195ae68]{position:relative;height:100%;overflow:hidden;touch-action:pan-y}.vpr-pull-refresh__scroll[data-v-9195ae68]{position:relative;height:100%;overflow:auto;-webkit-overflow-scrolling:touch;overscroll-behavior:contain}.vpr-pull-refresh__header[data-v-9195ae68]{position:absolute;top:0;left:0;right:0;pointer-events:none;will-change:transform}.vpr-pull-refresh__header__txt[data-v-9195ae68]{width:100%;height:100%;display:flex;align-items:center;justify-content:center}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "vue3-pull-refresh",
3
+ "version": "1.0.2",
4
+ "description": "A Vue3 pull-to-refresh component",
5
+ "main": "dist/index.umd.js",
6
+ "module": "dist/index.es.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.es.js",
14
+ "require": "./dist/index.umd.js",
15
+ "types": "./dist/index.d.ts"
16
+ }
17
+ },
18
+ "scripts": {
19
+ "dev": "vite",
20
+ "build": "vite build",
21
+ "preview": "vite preview"
22
+ },
23
+ "keywords": [
24
+ "vue3",
25
+ "refresh",
26
+ "pull-refresh",
27
+ "pull-to-refresh",
28
+ "component"
29
+ ],
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/Matthew-Gu/vue3-pull-refresh.git"
33
+ },
34
+ "author": "MatthewGu",
35
+ "license": "MIT",
36
+ "peerDependencies": {
37
+ "vue": "^3.0.0"
38
+ },
39
+ "devDependencies": {
40
+ "vite": "^5.0.0",
41
+ "vue": "^3.4.0",
42
+ "@vitejs/plugin-vue": "^5.0.0",
43
+ "vite-plugin-dts": "^3.5.0",
44
+ "typescript": "^5.3.0"
45
+ }
46
+ }