@v-c/virtual-list 0.0.1 → 1.0.0
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/bump.config.ts +6 -0
- package/dist/Filler.cjs +51 -1
- package/dist/Filler.js +47 -56
- package/dist/Item.cjs +26 -1
- package/dist/Item.js +23 -26
- package/dist/List.cjs +408 -1
- package/dist/List.d.ts +45 -9
- package/dist/List.js +403 -274
- package/dist/ScrollBar.cjs +259 -1
- package/dist/ScrollBar.d.ts +3 -97
- package/dist/ScrollBar.js +254 -191
- package/dist/_virtual/rolldown_runtime.cjs +21 -0
- package/dist/hooks/useDiffItem.cjs +19 -1
- package/dist/hooks/useDiffItem.js +16 -20
- package/dist/hooks/useFrameWheel.cjs +63 -1
- package/dist/hooks/useFrameWheel.js +60 -51
- package/dist/hooks/useGetSize.cjs +29 -1
- package/dist/hooks/useGetSize.d.ts +2 -2
- package/dist/hooks/useGetSize.js +27 -23
- package/dist/hooks/useHeights.cjs +66 -1
- package/dist/hooks/useHeights.d.ts +1 -1
- package/dist/hooks/useHeights.js +62 -41
- package/dist/hooks/useMobileTouchMove.cjs +82 -1
- package/dist/hooks/useMobileTouchMove.js +79 -43
- package/dist/hooks/useOriginScroll.cjs +23 -1
- package/dist/hooks/useOriginScroll.js +20 -16
- package/dist/hooks/useScrollDrag.cjs +83 -1
- package/dist/hooks/useScrollDrag.js +77 -48
- package/dist/hooks/useScrollTo.cjs +97 -0
- package/dist/hooks/useScrollTo.d.ts +19 -0
- package/dist/hooks/useScrollTo.js +94 -0
- package/dist/index.cjs +4 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -4
- package/dist/interface.cjs +0 -1
- package/dist/interface.d.ts +1 -1
- package/dist/interface.js +0 -1
- package/dist/utils/CacheMap.cjs +25 -1
- package/dist/utils/CacheMap.d.ts +1 -1
- package/dist/utils/CacheMap.js +23 -28
- package/dist/utils/isFirefox.cjs +4 -1
- package/dist/utils/isFirefox.js +2 -4
- package/dist/utils/scrollbarUtil.cjs +8 -1
- package/dist/utils/scrollbarUtil.js +7 -6
- package/docs/animate.less +31 -0
- package/docs/animate.vue +159 -0
- package/docs/basic.vue +2 -1
- package/docs/nest.vue +1 -1
- package/docs/switch.vue +2 -1
- package/docs/virtual-list.stories.vue +4 -0
- package/package.json +16 -14
- package/src/Filler.tsx +2 -1
- package/src/Item.tsx +2 -1
- package/src/List.tsx +189 -124
- package/src/ScrollBar.tsx +33 -44
- package/src/hooks/useDiffItem.ts +3 -2
- package/src/hooks/useFrameWheel.ts +2 -1
- package/src/hooks/useGetSize.ts +5 -4
- package/src/hooks/useHeights.ts +7 -6
- package/src/hooks/useMobileTouchMove.ts +2 -1
- package/src/hooks/useOriginScroll.ts +2 -1
- package/src/hooks/useScrollDrag.ts +2 -1
- package/src/hooks/useScrollTo.tsx +184 -0
- package/src/index.ts +1 -1
- package/tsconfig.json +7 -0
- package/vitest.config.ts +1 -1
package/dist/ScrollBar.js
CHANGED
|
@@ -1,193 +1,256 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { computed, createVNode, defineComponent, onMounted, onUnmounted, ref, shallowRef, watch } from "vue";
|
|
2
|
+
import raf from "@v-c/util/dist/raf";
|
|
3
|
+
function getPageXY(e, horizontal) {
|
|
4
|
+
return ("touches" in e ? e.touches[0] : e)[horizontal ? "pageX" : "pageY"] - window[horizontal ? "scrollX" : "scrollY"];
|
|
4
5
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
6
|
+
var ScrollBar_default = /* @__PURE__ */ defineComponent({
|
|
7
|
+
props: {
|
|
8
|
+
prefixCls: {
|
|
9
|
+
type: String,
|
|
10
|
+
required: true,
|
|
11
|
+
default: void 0
|
|
12
|
+
},
|
|
13
|
+
scrollOffset: {
|
|
14
|
+
type: Number,
|
|
15
|
+
required: true,
|
|
16
|
+
default: void 0
|
|
17
|
+
},
|
|
18
|
+
scrollRange: {
|
|
19
|
+
type: Number,
|
|
20
|
+
required: true,
|
|
21
|
+
default: void 0
|
|
22
|
+
},
|
|
23
|
+
rtl: {
|
|
24
|
+
type: Boolean,
|
|
25
|
+
required: true,
|
|
26
|
+
default: void 0
|
|
27
|
+
},
|
|
28
|
+
onScroll: {
|
|
29
|
+
type: Function,
|
|
30
|
+
required: true,
|
|
31
|
+
default: void 0
|
|
32
|
+
},
|
|
33
|
+
onStartMove: {
|
|
34
|
+
type: Function,
|
|
35
|
+
required: true,
|
|
36
|
+
default: void 0
|
|
37
|
+
},
|
|
38
|
+
onStopMove: {
|
|
39
|
+
type: Function,
|
|
40
|
+
required: true,
|
|
41
|
+
default: void 0
|
|
42
|
+
},
|
|
43
|
+
horizontal: {
|
|
44
|
+
type: Boolean,
|
|
45
|
+
required: false,
|
|
46
|
+
default: void 0
|
|
47
|
+
},
|
|
48
|
+
style: {
|
|
49
|
+
type: Object,
|
|
50
|
+
required: false,
|
|
51
|
+
default: void 0
|
|
52
|
+
},
|
|
53
|
+
thumbStyle: {
|
|
54
|
+
type: Object,
|
|
55
|
+
required: false,
|
|
56
|
+
default: void 0
|
|
57
|
+
},
|
|
58
|
+
spinSize: {
|
|
59
|
+
type: Number,
|
|
60
|
+
required: true,
|
|
61
|
+
default: void 0
|
|
62
|
+
},
|
|
63
|
+
containerSize: {
|
|
64
|
+
type: Number,
|
|
65
|
+
required: true,
|
|
66
|
+
default: void 0
|
|
67
|
+
},
|
|
68
|
+
showScrollBar: {
|
|
69
|
+
type: [Boolean, String],
|
|
70
|
+
required: false,
|
|
71
|
+
default: void 0
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
name: "ScrollBar",
|
|
75
|
+
setup(props, { expose }) {
|
|
76
|
+
const dragging = ref(false);
|
|
77
|
+
const pageXY = ref(null);
|
|
78
|
+
const startTop = ref(null);
|
|
79
|
+
const isLTR = computed(() => !props.rtl);
|
|
80
|
+
const scrollbarRef = shallowRef();
|
|
81
|
+
const thumbRef = shallowRef();
|
|
82
|
+
const visible = ref(props.showScrollBar === "optional" ? true : props.showScrollBar);
|
|
83
|
+
let visibleTimeout = null;
|
|
84
|
+
const delayHidden = () => {
|
|
85
|
+
if (props.showScrollBar === true || props.showScrollBar === false) return;
|
|
86
|
+
if (visibleTimeout) clearTimeout(visibleTimeout);
|
|
87
|
+
visible.value = true;
|
|
88
|
+
visibleTimeout = setTimeout(() => {
|
|
89
|
+
visible.value = false;
|
|
90
|
+
}, 3e3);
|
|
91
|
+
};
|
|
92
|
+
const enableScrollRange = computed(() => props.scrollRange - props.containerSize || 0);
|
|
93
|
+
const enableOffsetRange = computed(() => props.containerSize - props.spinSize || 0);
|
|
94
|
+
const top = computed(() => {
|
|
95
|
+
if (props.scrollOffset === 0 || enableScrollRange.value === 0) return 0;
|
|
96
|
+
return props.scrollOffset / enableScrollRange.value * enableOffsetRange.value;
|
|
97
|
+
});
|
|
98
|
+
const stateRef = shallowRef({
|
|
99
|
+
top: top.value,
|
|
100
|
+
dragging: dragging.value,
|
|
101
|
+
pageY: pageXY.value,
|
|
102
|
+
startTop: startTop.value
|
|
103
|
+
});
|
|
104
|
+
watch([
|
|
105
|
+
top,
|
|
106
|
+
dragging,
|
|
107
|
+
pageXY,
|
|
108
|
+
startTop
|
|
109
|
+
], () => {
|
|
110
|
+
stateRef.value = {
|
|
111
|
+
top: top.value,
|
|
112
|
+
dragging: dragging.value,
|
|
113
|
+
pageY: pageXY.value,
|
|
114
|
+
startTop: startTop.value
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
const onContainerMouseDown = (e) => {
|
|
118
|
+
e.stopPropagation();
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
};
|
|
121
|
+
const onThumbMouseDown = (e) => {
|
|
122
|
+
dragging.value = true;
|
|
123
|
+
pageXY.value = getPageXY(e, props.horizontal || false);
|
|
124
|
+
startTop.value = stateRef.value.top;
|
|
125
|
+
props?.onStartMove?.();
|
|
126
|
+
e.stopPropagation();
|
|
127
|
+
e.preventDefault();
|
|
128
|
+
};
|
|
129
|
+
onMounted(() => {
|
|
130
|
+
const onScrollbarTouchStart = (e) => {
|
|
131
|
+
e.preventDefault();
|
|
132
|
+
};
|
|
133
|
+
const scrollbarEle = scrollbarRef.value;
|
|
134
|
+
const thumbEle = thumbRef.value;
|
|
135
|
+
if (scrollbarEle && thumbEle) {
|
|
136
|
+
scrollbarEle.addEventListener("touchstart", onScrollbarTouchStart, { passive: false });
|
|
137
|
+
thumbEle.addEventListener("touchstart", onThumbMouseDown, { passive: false });
|
|
138
|
+
onUnmounted(() => {
|
|
139
|
+
scrollbarEle.removeEventListener("touchstart", onScrollbarTouchStart);
|
|
140
|
+
thumbEle.removeEventListener("touchstart", onThumbMouseDown);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
watch(dragging, (isDragging, _O, onCleanup) => {
|
|
145
|
+
if (isDragging) {
|
|
146
|
+
let moveRafId = null;
|
|
147
|
+
const onMouseMove = (e) => {
|
|
148
|
+
const { dragging: stateDragging, pageY: statePageY, startTop: stateStartTop } = stateRef.value;
|
|
149
|
+
raf.cancel(moveRafId);
|
|
150
|
+
const rect = scrollbarRef.value.getBoundingClientRect();
|
|
151
|
+
const scale = props.containerSize / (props.horizontal ? rect.width : rect.height);
|
|
152
|
+
if (stateDragging) {
|
|
153
|
+
const offset = (getPageXY(e, props.horizontal || false) - (statePageY || 0)) * scale;
|
|
154
|
+
let newTop = stateStartTop || 0;
|
|
155
|
+
if (!isLTR.value && props.horizontal) newTop -= offset;
|
|
156
|
+
else newTop += offset;
|
|
157
|
+
const tmpEnableScrollRange = enableScrollRange.value;
|
|
158
|
+
const tmpEnableOffsetRange = enableOffsetRange.value;
|
|
159
|
+
const ptg = tmpEnableOffsetRange ? newTop / tmpEnableOffsetRange : 0;
|
|
160
|
+
let newScrollTop = Math.ceil(ptg * tmpEnableScrollRange);
|
|
161
|
+
newScrollTop = Math.max(newScrollTop, 0);
|
|
162
|
+
newScrollTop = Math.min(newScrollTop, tmpEnableScrollRange);
|
|
163
|
+
moveRafId = raf(() => {
|
|
164
|
+
props?.onScroll?.(newScrollTop, props.horizontal);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
const onMouseUp = () => {
|
|
169
|
+
dragging.value = false;
|
|
170
|
+
props.onStopMove();
|
|
171
|
+
};
|
|
172
|
+
window.addEventListener("mousemove", onMouseMove, { passive: true });
|
|
173
|
+
window.addEventListener("touchmove", onMouseMove, { passive: true });
|
|
174
|
+
window.addEventListener("mouseup", onMouseUp, { passive: true });
|
|
175
|
+
window.addEventListener("touchend", onMouseUp, { passive: true });
|
|
176
|
+
onCleanup(() => {
|
|
177
|
+
window.removeEventListener("mousemove", onMouseMove);
|
|
178
|
+
window.removeEventListener("touchmove", onMouseMove);
|
|
179
|
+
window.removeEventListener("mouseup", onMouseUp);
|
|
180
|
+
window.removeEventListener("touchend", onMouseUp);
|
|
181
|
+
raf.cancel(moveRafId);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
watch(() => props.scrollOffset, (_n, _o, onCleanup) => {
|
|
186
|
+
delayHidden();
|
|
187
|
+
onCleanup(() => {
|
|
188
|
+
if (visibleTimeout) clearTimeout(visibleTimeout);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
expose({ delayHidden });
|
|
192
|
+
return () => {
|
|
193
|
+
const { prefixCls, horizontal } = props;
|
|
194
|
+
const scrollbarPrefixCls = `${prefixCls}-scrollbar`;
|
|
195
|
+
const containerStyle = {
|
|
196
|
+
position: "absolute",
|
|
197
|
+
visibility: visible.value ? void 0 : "hidden"
|
|
198
|
+
};
|
|
199
|
+
const thumbStyle = {
|
|
200
|
+
position: "absolute",
|
|
201
|
+
borderRadius: "99px",
|
|
202
|
+
background: "var(--vc-virtual-list-scrollbar-bg, rgba(0, 0, 0, 0.5))",
|
|
203
|
+
cursor: "pointer",
|
|
204
|
+
userSelect: "none"
|
|
205
|
+
};
|
|
206
|
+
if (props.horizontal) {
|
|
207
|
+
Object.assign(containerStyle, {
|
|
208
|
+
height: "8px",
|
|
209
|
+
left: 0,
|
|
210
|
+
right: 0,
|
|
211
|
+
bottom: 0
|
|
212
|
+
});
|
|
213
|
+
Object.assign(thumbStyle, {
|
|
214
|
+
height: "100%",
|
|
215
|
+
width: `${props.spinSize}px`,
|
|
216
|
+
[isLTR.value ? "left" : "right"]: `${top.value}px`
|
|
217
|
+
});
|
|
218
|
+
} else {
|
|
219
|
+
Object.assign(containerStyle, {
|
|
220
|
+
width: "8px",
|
|
221
|
+
top: 0,
|
|
222
|
+
bottom: 0,
|
|
223
|
+
[isLTR.value ? "right" : "left"]: 0
|
|
224
|
+
});
|
|
225
|
+
Object.assign(thumbStyle, {
|
|
226
|
+
width: "100%",
|
|
227
|
+
height: `${props.spinSize}px`,
|
|
228
|
+
top: `${top.value}px`
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
return createVNode("div", {
|
|
232
|
+
"ref": scrollbarRef,
|
|
233
|
+
"class": [scrollbarPrefixCls, {
|
|
234
|
+
[`${scrollbarPrefixCls}-horizontal`]: horizontal,
|
|
235
|
+
[`${scrollbarPrefixCls}-vertical`]: !horizontal,
|
|
236
|
+
[`${scrollbarPrefixCls}-visible`]: visible.value
|
|
237
|
+
}],
|
|
238
|
+
"style": {
|
|
239
|
+
...containerStyle,
|
|
240
|
+
...props.style
|
|
241
|
+
},
|
|
242
|
+
"onMousedown": onContainerMouseDown,
|
|
243
|
+
"onMousemove": delayHidden
|
|
244
|
+
}, [createVNode("div", {
|
|
245
|
+
"ref": thumbRef,
|
|
246
|
+
"class": [`${scrollbarPrefixCls}-thumb`, { [`${scrollbarPrefixCls}-thumb-moving`]: dragging.value }],
|
|
247
|
+
"style": {
|
|
248
|
+
...thumbStyle,
|
|
249
|
+
...props.thumbStyle
|
|
250
|
+
},
|
|
251
|
+
"onMousedown": onThumbMouseDown
|
|
252
|
+
}, null)]);
|
|
253
|
+
};
|
|
254
|
+
}
|
|
190
255
|
});
|
|
191
|
-
export {
|
|
192
|
-
k as default
|
|
193
|
-
};
|
|
256
|
+
export { ScrollBar_default as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
9
|
+
key = keys[i];
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
11
|
+
get: ((k) => from[k]).bind(null, key),
|
|
12
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
18
|
+
value: mod,
|
|
19
|
+
enumerable: true
|
|
20
|
+
}) : target, mod));
|
|
21
|
+
exports.__toESM = __toESM;
|
|
@@ -1 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
function useDiffItem(data, getKey) {
|
|
5
|
+
const prevDataRef = (0, vue.ref)([]);
|
|
6
|
+
const diffItem = (0, vue.ref)();
|
|
7
|
+
(0, vue.watch)(data, (newData) => {
|
|
8
|
+
const prevData = prevDataRef.value;
|
|
9
|
+
if (newData !== prevData) {
|
|
10
|
+
diffItem.value = newData.find((item) => {
|
|
11
|
+
const key = getKey(item);
|
|
12
|
+
return !prevData.some((prevItem) => getKey(prevItem) === key);
|
|
13
|
+
});
|
|
14
|
+
prevDataRef.value = newData;
|
|
15
|
+
}
|
|
16
|
+
}, { immediate: true });
|
|
17
|
+
return diffItem;
|
|
18
|
+
}
|
|
19
|
+
exports.default = useDiffItem;
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
import { ref
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
{ immediate: !0 }
|
|
17
|
-
), r;
|
|
1
|
+
import { ref, watch } from "vue";
|
|
2
|
+
function useDiffItem(data, getKey) {
|
|
3
|
+
const prevDataRef = ref([]);
|
|
4
|
+
const diffItem = ref();
|
|
5
|
+
watch(data, (newData) => {
|
|
6
|
+
const prevData = prevDataRef.value;
|
|
7
|
+
if (newData !== prevData) {
|
|
8
|
+
diffItem.value = newData.find((item) => {
|
|
9
|
+
const key = getKey(item);
|
|
10
|
+
return !prevData.some((prevItem) => getKey(prevItem) === key);
|
|
11
|
+
});
|
|
12
|
+
prevDataRef.value = newData;
|
|
13
|
+
}
|
|
14
|
+
}, { immediate: true });
|
|
15
|
+
return diffItem;
|
|
18
16
|
}
|
|
19
|
-
export {
|
|
20
|
-
v as default
|
|
21
|
-
};
|
|
17
|
+
export { useDiffItem as default };
|
|
@@ -1 +1,63 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
|
+
const require_isFirefox = require("../utils/isFirefox.cjs");
|
|
4
|
+
const require_useOriginScroll = require("./useOriginScroll.cjs");
|
|
5
|
+
let vue = require("vue");
|
|
6
|
+
function useFrameWheel(inVirtual, isScrollAtTop, isScrollAtBottom, isScrollAtLeft, isScrollAtRight, horizontalScroll, onWheelDelta) {
|
|
7
|
+
const offsetRef = (0, vue.ref)(0);
|
|
8
|
+
let nextFrame = null;
|
|
9
|
+
const wheelValueRef = (0, vue.ref)(null);
|
|
10
|
+
const isMouseScrollRef = (0, vue.ref)(false);
|
|
11
|
+
const originScroll = require_useOriginScroll.default(isScrollAtTop, isScrollAtBottom, isScrollAtLeft, isScrollAtRight);
|
|
12
|
+
function onWheelY(e, deltaY) {
|
|
13
|
+
if (nextFrame) cancelAnimationFrame(nextFrame);
|
|
14
|
+
if (originScroll(false, deltaY)) return;
|
|
15
|
+
const event = e;
|
|
16
|
+
if (!event._virtualHandled) event._virtualHandled = true;
|
|
17
|
+
else return;
|
|
18
|
+
offsetRef.value += deltaY;
|
|
19
|
+
wheelValueRef.value = deltaY;
|
|
20
|
+
if (!require_isFirefox.default) event.preventDefault();
|
|
21
|
+
nextFrame = requestAnimationFrame(() => {
|
|
22
|
+
const patchMultiple = isMouseScrollRef.value ? 10 : 1;
|
|
23
|
+
onWheelDelta(offsetRef.value * patchMultiple, false);
|
|
24
|
+
offsetRef.value = 0;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function onWheelX(event, deltaX) {
|
|
28
|
+
onWheelDelta(deltaX, true);
|
|
29
|
+
if (!require_isFirefox.default) event.preventDefault();
|
|
30
|
+
}
|
|
31
|
+
const wheelDirectionRef = (0, vue.ref)(null);
|
|
32
|
+
let wheelDirectionClean = null;
|
|
33
|
+
function onWheel(event) {
|
|
34
|
+
if (!inVirtual.value) return;
|
|
35
|
+
if (wheelDirectionClean) cancelAnimationFrame(wheelDirectionClean);
|
|
36
|
+
wheelDirectionClean = requestAnimationFrame(() => {
|
|
37
|
+
wheelDirectionRef.value = null;
|
|
38
|
+
});
|
|
39
|
+
const { deltaX, deltaY, shiftKey } = event;
|
|
40
|
+
let mergedDeltaX = deltaX;
|
|
41
|
+
let mergedDeltaY = deltaY;
|
|
42
|
+
if (wheelDirectionRef.value === "sx" || !wheelDirectionRef.value && (shiftKey || false) && deltaY && !deltaX) {
|
|
43
|
+
mergedDeltaX = deltaY;
|
|
44
|
+
mergedDeltaY = 0;
|
|
45
|
+
wheelDirectionRef.value = "sx";
|
|
46
|
+
}
|
|
47
|
+
const absX = Math.abs(mergedDeltaX);
|
|
48
|
+
const absY = Math.abs(mergedDeltaY);
|
|
49
|
+
if (wheelDirectionRef.value === null) wheelDirectionRef.value = horizontalScroll && absX > absY ? "x" : "y";
|
|
50
|
+
if (wheelDirectionRef.value === "y") onWheelY(event, mergedDeltaY);
|
|
51
|
+
else onWheelX(event, mergedDeltaX);
|
|
52
|
+
}
|
|
53
|
+
function onFireFoxScroll(event) {
|
|
54
|
+
if (!inVirtual.value) return;
|
|
55
|
+
isMouseScrollRef.value = event.detail === wheelValueRef.value;
|
|
56
|
+
}
|
|
57
|
+
(0, vue.onUnmounted)(() => {
|
|
58
|
+
if (nextFrame) cancelAnimationFrame(nextFrame);
|
|
59
|
+
if (wheelDirectionClean) cancelAnimationFrame(wheelDirectionClean);
|
|
60
|
+
});
|
|
61
|
+
return [onWheel, onFireFoxScroll];
|
|
62
|
+
}
|
|
63
|
+
exports.default = useFrameWheel;
|