@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/docs/animate.vue
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { ListRef } from '../src'
|
|
3
|
+
import { ref } from 'vue'
|
|
4
|
+
import VirtualList from '../src'
|
|
5
|
+
import './animate.less'
|
|
6
|
+
|
|
7
|
+
interface Item {
|
|
8
|
+
id: string
|
|
9
|
+
uuid: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let uuid = 0
|
|
13
|
+
function genItem(): Item {
|
|
14
|
+
const item = {
|
|
15
|
+
id: `key_${uuid}`,
|
|
16
|
+
uuid,
|
|
17
|
+
}
|
|
18
|
+
uuid += 1
|
|
19
|
+
return item
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const originData: Item[] = []
|
|
23
|
+
for (let i = 0; i < 1000; i += 1) {
|
|
24
|
+
originData.push(genItem())
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const data = ref([...originData])
|
|
28
|
+
const closeMap = ref<Record<string, boolean>>({})
|
|
29
|
+
const animating = ref(false)
|
|
30
|
+
const insertIndex = ref<number>()
|
|
31
|
+
|
|
32
|
+
const listRef = ref<ListRef>()
|
|
33
|
+
|
|
34
|
+
function onClose(id: string) {
|
|
35
|
+
closeMap.value = {
|
|
36
|
+
...closeMap.value,
|
|
37
|
+
[id]: true,
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function onLeave(id: string) {
|
|
42
|
+
data.value = data.value.filter(item => item.id !== id)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function onAppear(...args: any[]) {
|
|
46
|
+
console.log('Appear:', args)
|
|
47
|
+
animating.value = false
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function lockForAnimation() {
|
|
51
|
+
animating.value = true
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function onInsertBefore(id: string) {
|
|
55
|
+
const index = data.value.findIndex(item => item.id === id)
|
|
56
|
+
const newData = [...data.value.slice(0, index), genItem(), ...data.value.slice(index)]
|
|
57
|
+
insertIndex.value = index
|
|
58
|
+
data.value = newData
|
|
59
|
+
lockForAnimation()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function onInsertAfter(id: string) {
|
|
63
|
+
const index = data.value.findIndex(item => item.id === id) + 1
|
|
64
|
+
const newData = [...data.value.slice(0, index), genItem(), ...data.value.slice(index)]
|
|
65
|
+
insertIndex.value = index
|
|
66
|
+
data.value = newData
|
|
67
|
+
lockForAnimation()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function getCurrentHeight(el: Element) {
|
|
71
|
+
const node = el as HTMLElement
|
|
72
|
+
node.style.height = `${node.offsetHeight}px`
|
|
73
|
+
node.style.opacity = '1'
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function getMaxHeight(el: Element) {
|
|
77
|
+
const node = el as HTMLElement
|
|
78
|
+
node.style.height = `${node.scrollHeight}px`
|
|
79
|
+
node.style.opacity = '1'
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function getCollapsedHeight(el: Element) {
|
|
83
|
+
const node = el as HTMLElement
|
|
84
|
+
node.style.height = '0'
|
|
85
|
+
node.style.opacity = '0'
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function resetHeight(el: Element) {
|
|
89
|
+
const node = el as HTMLElement
|
|
90
|
+
node.style.height = ''
|
|
91
|
+
node.style.opacity = ''
|
|
92
|
+
onAppear()
|
|
93
|
+
}
|
|
94
|
+
</script>
|
|
95
|
+
|
|
96
|
+
<template>
|
|
97
|
+
<div>
|
|
98
|
+
<h2>Animate</h2>
|
|
99
|
+
<p>Current: {{ data.length }} records</p>
|
|
100
|
+
|
|
101
|
+
<VirtualList
|
|
102
|
+
ref="listRef"
|
|
103
|
+
:data="data"
|
|
104
|
+
data-id="list"
|
|
105
|
+
:height="200"
|
|
106
|
+
:item-height="20"
|
|
107
|
+
item-key="id"
|
|
108
|
+
:style="{
|
|
109
|
+
border: '1px solid red',
|
|
110
|
+
boxSizing: 'border-box',
|
|
111
|
+
}"
|
|
112
|
+
>
|
|
113
|
+
<template #default="{ item, index }">
|
|
114
|
+
<Transition
|
|
115
|
+
name="motion"
|
|
116
|
+
:appear="animating && insertIndex === index"
|
|
117
|
+
@before-enter="getCollapsedHeight"
|
|
118
|
+
@enter="getMaxHeight"
|
|
119
|
+
@after-enter="resetHeight"
|
|
120
|
+
@before-leave="getCurrentHeight"
|
|
121
|
+
@leave="getCollapsedHeight"
|
|
122
|
+
@after-leave="() => onLeave(item.id)"
|
|
123
|
+
>
|
|
124
|
+
<div
|
|
125
|
+
v-if="!(closeMap as any)[item.id]"
|
|
126
|
+
class="item"
|
|
127
|
+
:data-id="item.id"
|
|
128
|
+
>
|
|
129
|
+
<div :style="{ height: item.uuid % 2 ? '100px' : undefined }">
|
|
130
|
+
<button type="button" @click="onClose(item.id)">
|
|
131
|
+
Close
|
|
132
|
+
</button>
|
|
133
|
+
<button type="button" @click="onInsertBefore(item.id)">
|
|
134
|
+
Insert Before
|
|
135
|
+
</button>
|
|
136
|
+
<button type="button" @click="onInsertAfter(item.id)">
|
|
137
|
+
Insert After
|
|
138
|
+
</button>
|
|
139
|
+
{{ item.id }}
|
|
140
|
+
</div>
|
|
141
|
+
</div>
|
|
142
|
+
</Transition>
|
|
143
|
+
</template>
|
|
144
|
+
</VirtualList>
|
|
145
|
+
</div>
|
|
146
|
+
</template>
|
|
147
|
+
|
|
148
|
+
<style scoped>
|
|
149
|
+
.motion-enter-active,
|
|
150
|
+
.motion-leave-active {
|
|
151
|
+
transition: all 0.3s;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.motion-enter-from,
|
|
155
|
+
.motion-leave-to {
|
|
156
|
+
height: 0;
|
|
157
|
+
opacity: 0;
|
|
158
|
+
}
|
|
159
|
+
</style>
|
package/docs/basic.vue
CHANGED
package/docs/nest.vue
CHANGED
package/docs/switch.vue
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import Animate from './animate.vue'
|
|
2
3
|
import Basic from './basic.vue'
|
|
3
4
|
import Height from './height.vue'
|
|
4
5
|
import Nest from './nest.vue'
|
|
@@ -11,6 +12,9 @@ import Switch from './switch.vue'
|
|
|
11
12
|
<Variant title="Basic">
|
|
12
13
|
<Basic />
|
|
13
14
|
</Variant>
|
|
15
|
+
<Variant title="Animate">
|
|
16
|
+
<Animate />
|
|
17
|
+
</Variant>
|
|
14
18
|
|
|
15
19
|
<Variant title="Dynamic Height">
|
|
16
20
|
<Height />
|
package/package.json
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@v-c/virtual-list",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "Vue Virtual List Component",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"vue",
|
|
10
|
+
"virtual-list",
|
|
11
|
+
"vue-component"
|
|
12
|
+
],
|
|
5
13
|
"exports": {
|
|
6
14
|
".": {
|
|
7
15
|
"types": "./dist/index.d.ts",
|
|
@@ -11,15 +19,7 @@
|
|
|
11
19
|
"./dist/*": "./dist/*",
|
|
12
20
|
"./package.json": "./package.json"
|
|
13
21
|
},
|
|
14
|
-
"
|
|
15
|
-
"author": "",
|
|
16
|
-
"license": "MIT",
|
|
17
|
-
"keywords": [
|
|
18
|
-
"vue",
|
|
19
|
-
"virtual-list",
|
|
20
|
-
"vue-component"
|
|
21
|
-
],
|
|
22
|
-
"main": "index.js",
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
23
|
"publishConfig": {
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
@@ -27,12 +27,14 @@
|
|
|
27
27
|
"vue": "^3.0.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@v-c/resize-observer": "0.0
|
|
31
|
-
"@v-c/util": "
|
|
30
|
+
"@v-c/resize-observer": "^1.0.0",
|
|
31
|
+
"@v-c/util": "^1.0.1"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "vite build",
|
|
35
|
-
"test": "vitest",
|
|
36
|
-
"prepublish": "pnpm build"
|
|
35
|
+
"test": "vitest run",
|
|
36
|
+
"prepublish": "pnpm build",
|
|
37
|
+
"bump": "bumpp",
|
|
38
|
+
"patch": "bumpp --release patch"
|
|
37
39
|
}
|
|
38
40
|
}
|
package/src/Filler.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { CSSProperties, PropType, VNode } from 'vue'
|
|
1
2
|
import ResizeObserver from '@v-c/resize-observer'
|
|
2
|
-
import {
|
|
3
|
+
import { defineComponent } from 'vue'
|
|
3
4
|
|
|
4
5
|
export interface InnerProps {
|
|
5
6
|
role?: string
|
package/src/Item.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { PropType } from 'vue'
|
|
1
2
|
import { filterEmpty } from '@v-c/util/dist/props-util'
|
|
2
|
-
import { cloneVNode, defineComponent,
|
|
3
|
+
import { cloneVNode, defineComponent, shallowRef } from 'vue'
|
|
3
4
|
|
|
4
5
|
export interface ItemProps {
|
|
5
6
|
setRef: (element: HTMLElement | null) => void
|