cbvirtua 1.0.14 → 1.0.16
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/binding.node +0 -0
- package/catch.js +89 -0
- package/package.json +1 -1
- package/IMG_8775.md +0 -18
- package/core/cache.js +0 -142
- package/core/environment.js +0 -36
- package/core/resizer.js +0 -226
- package/core/scroller.js +0 -273
- package/core/store.js +0 -345
- package/core/types.js +0 -1
- package/core/utils.js +0 -73
- package/pre/index.js +0 -93
- package/smoothscroll.js +0 -433
- package/vue2/ListItem.js +0 -46
- package/vue2/VList.js +0 -161
- package/vue2/ex.vue +0 -66
- package/vue2/exx.vue +0 -44
package/vue2/VList.js
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { SCROLL_IDLE, UPDATE_SCROLL_STATE, UPDATE_SCROLL_EVENT, UPDATE_SCROLL_END_EVENT, UPDATE_SIZE_STATE, overscanEndIndex, overscanStartIndex, createVirtualStore, ACTION_ITEMS_LENGTH_CHANGE, getScrollSize, getMinContainerSize, } from "../core/store"
|
|
2
|
-
import { createResizer } from "../core/resizer"
|
|
3
|
-
import { createScroller } from "../core/scroller"
|
|
4
|
-
import { default as ListItem } from "./ListItem"
|
|
5
|
-
import { exists } from "../core/utils"
|
|
6
|
-
const props = {
|
|
7
|
-
data: { type: Array, required: true },
|
|
8
|
-
overscan: { type: Number, default: 4 },
|
|
9
|
-
itemSize: Number,
|
|
10
|
-
shift: Boolean,
|
|
11
|
-
horizontal: Boolean,
|
|
12
|
-
}
|
|
13
|
-
export default {
|
|
14
|
-
props: props,
|
|
15
|
-
data() {
|
|
16
|
-
return {
|
|
17
|
-
store: {},
|
|
18
|
-
rerender: [],
|
|
19
|
-
JumpCount: 0,
|
|
20
|
-
range: []
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
watch: {
|
|
24
|
-
data(_data) {
|
|
25
|
-
const count = _data.length
|
|
26
|
-
this.store._update(ACTION_ITEMS_LENGTH_CHANGE, [count, this.shift])
|
|
27
|
-
},
|
|
28
|
-
JumpCount(count, prevCount) {
|
|
29
|
-
this.$nextTick(() => {
|
|
30
|
-
if (count === prevCount)
|
|
31
|
-
return
|
|
32
|
-
const jump = this.store._flushJump()
|
|
33
|
-
if (!jump)
|
|
34
|
-
return
|
|
35
|
-
this.scroller._fixScrollJump(jump)
|
|
36
|
-
})
|
|
37
|
-
},
|
|
38
|
-
range([start, end], [prevStart, prevEnd]) {
|
|
39
|
-
this.$nextTick(() => {
|
|
40
|
-
if (prevStart === start && prevEnd === end)
|
|
41
|
-
return
|
|
42
|
-
this.$emit("rangeChange", start, end)
|
|
43
|
-
})
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
},
|
|
47
|
-
created() {
|
|
48
|
-
const isHorizontal = this.horizontal
|
|
49
|
-
const store = this.store = createVirtualStore(
|
|
50
|
-
this.data.length,
|
|
51
|
-
this.itemSize ?? 40,
|
|
52
|
-
undefined,
|
|
53
|
-
undefined,
|
|
54
|
-
!this.itemSize
|
|
55
|
-
)
|
|
56
|
-
const resizer = this.resizer = createResizer(store, isHorizontal)
|
|
57
|
-
const scroller = this.scroller = createScroller(store, isHorizontal)
|
|
58
|
-
this.scrollToIndex = scroller._scrollToIndex
|
|
59
|
-
this.scrollTo = scroller._scrollTo
|
|
60
|
-
this.scrollBy = scroller._scrollBy
|
|
61
|
-
const rerender = store._getStateVersion()
|
|
62
|
-
const unsubscribeStore = this.unsubscribeStore = store._subscribe(UPDATE_SCROLL_STATE + UPDATE_SIZE_STATE, () => {
|
|
63
|
-
this.rerender = store._getStateVersion()
|
|
64
|
-
this.JumpCount = store._getJumpCount()
|
|
65
|
-
this.range = store._getRange()
|
|
66
|
-
})
|
|
67
|
-
const unsubscribeOnScroll = this.unsubscribeOnScroll = store._subscribe(UPDATE_SCROLL_EVENT, () => {
|
|
68
|
-
this.$emit("scroll", store._getScrollOffset())
|
|
69
|
-
})
|
|
70
|
-
const unsubscribeOnScrollEnd = this.unsubscribeOnScrollEnd = store._subscribe(UPDATE_SCROLL_END_EVENT, () => {
|
|
71
|
-
this.$emit("scrollEnd")
|
|
72
|
-
})
|
|
73
|
-
},
|
|
74
|
-
mounted() {
|
|
75
|
-
const root = this.$refs.root
|
|
76
|
-
if (!root)
|
|
77
|
-
return
|
|
78
|
-
this.resizer._observeRoot(root)
|
|
79
|
-
this.scroller._observe(root)
|
|
80
|
-
|
|
81
|
-
},
|
|
82
|
-
methods: {
|
|
83
|
-
scrollOffset() {
|
|
84
|
-
return this.store._getScrollOffset()
|
|
85
|
-
},
|
|
86
|
-
scrollSize() {
|
|
87
|
-
return this.getScrollSize(store)
|
|
88
|
-
},
|
|
89
|
-
viewportSize() {
|
|
90
|
-
return this.store._getViewportSize()
|
|
91
|
-
},
|
|
92
|
-
scrollToIndex() { },
|
|
93
|
-
scrollTo() { },
|
|
94
|
-
scrollBy() { }
|
|
95
|
-
},
|
|
96
|
-
render() {
|
|
97
|
-
this.rerender
|
|
98
|
-
const count = this.data.length
|
|
99
|
-
const store = this.store
|
|
100
|
-
const isHorizontal = this.horizontal
|
|
101
|
-
const [startIndex, endIndex] = this.store._getRange()
|
|
102
|
-
const scrollDirection = store._getScrollDirection()
|
|
103
|
-
const totalSize = store._getTotalSize()
|
|
104
|
-
const minSize = getMinContainerSize(store)
|
|
105
|
-
|
|
106
|
-
const items = []
|
|
107
|
-
for (let i = overscanStartIndex(startIndex, this.overscan, scrollDirection), j = overscanEndIndex(endIndex, this.overscan, scrollDirection, count); i <= j; i++) {
|
|
108
|
-
const e = this.$scopedSlots.default(this.data[i])[0]
|
|
109
|
-
const key = e.key
|
|
110
|
-
items.push(
|
|
111
|
-
<ListItem
|
|
112
|
-
key={exists(key) ? key : "_" + i}
|
|
113
|
-
resizer={this.resizer._observeItem}
|
|
114
|
-
index={i}
|
|
115
|
-
offset={store._getItemOffset(i)}
|
|
116
|
-
hide={store._isUnmeasuredItem(i)}
|
|
117
|
-
element="div"
|
|
118
|
-
children={e}
|
|
119
|
-
isHorizontal={isHorizontal}
|
|
120
|
-
/>
|
|
121
|
-
)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return (
|
|
125
|
-
<div
|
|
126
|
-
ref={"root"}
|
|
127
|
-
style={{
|
|
128
|
-
display: isHorizontal ? "inline-block" : "block",
|
|
129
|
-
[isHorizontal ? "overflowX" : "overflowY"]: "auto",
|
|
130
|
-
overflowAnchor: "none",
|
|
131
|
-
contain: "strict",
|
|
132
|
-
width: "100%",
|
|
133
|
-
height: "100%",
|
|
134
|
-
}}
|
|
135
|
-
>
|
|
136
|
-
<div
|
|
137
|
-
style={{
|
|
138
|
-
// contain: "content",
|
|
139
|
-
overflowAnchor: "none", // opt out browser's scroll anchoring because it will conflict to scroll anchoring of virtualizer
|
|
140
|
-
flex: "none", // flex style on parent can break layout
|
|
141
|
-
position: "relative",
|
|
142
|
-
visibility: "hidden",
|
|
143
|
-
width: isHorizontal ? totalSize + "px" : "100%",
|
|
144
|
-
height: isHorizontal ? "100%" : totalSize + "px",
|
|
145
|
-
[isHorizontal ? "minWidth" : "minHeight"]: minSize + "px",
|
|
146
|
-
pointerEvents: scrollDirection !== SCROLL_IDLE ? "none" : "auto",
|
|
147
|
-
}}
|
|
148
|
-
>
|
|
149
|
-
{items}
|
|
150
|
-
</div>
|
|
151
|
-
</div>
|
|
152
|
-
)
|
|
153
|
-
},
|
|
154
|
-
destoryed() {
|
|
155
|
-
this.unsubscribeStore()
|
|
156
|
-
this.unsubscribeOnScroll()
|
|
157
|
-
this.unsubscribeOnScrollEnd()
|
|
158
|
-
this.resizer._dispose()
|
|
159
|
-
this.scroller._dispose()
|
|
160
|
-
},
|
|
161
|
-
}
|
package/vue2/ex.vue
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div>
|
|
3
|
-
<p @click="exfun()" v-if="status">222</p>
|
|
4
|
-
<div v-if="refresh">
|
|
5
|
-
<exx v-show="hasData" />
|
|
6
|
-
</div>
|
|
7
|
-
</div>
|
|
8
|
-
</template>
|
|
9
|
-
<script>
|
|
10
|
-
import exx from './exx.vue'
|
|
11
|
-
let context = {}
|
|
12
|
-
const setContext = (vnode) => {
|
|
13
|
-
const p = new Promise((resolve, reject) => {
|
|
14
|
-
context.resolve = resolve
|
|
15
|
-
context.reject = reject
|
|
16
|
-
if (!vnode.context) {
|
|
17
|
-
vnode.context = context
|
|
18
|
-
}
|
|
19
|
-
})
|
|
20
|
-
return p
|
|
21
|
-
}
|
|
22
|
-
const initContext = () => {
|
|
23
|
-
setContext(exx) && context.resolve()
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
initContext()
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export default {
|
|
30
|
-
name: 'ex',
|
|
31
|
-
|
|
32
|
-
data() {
|
|
33
|
-
return {
|
|
34
|
-
refresh: false,
|
|
35
|
-
status: true,
|
|
36
|
-
hasData: false
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
async beforeCreated() {
|
|
40
|
-
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
async mounted() {
|
|
44
|
-
|
|
45
|
-
},
|
|
46
|
-
components: {
|
|
47
|
-
exx
|
|
48
|
-
},
|
|
49
|
-
methods: {
|
|
50
|
-
async exfun() {
|
|
51
|
-
let p = setContext(exx)
|
|
52
|
-
this.refresh = !this.refresh
|
|
53
|
-
if (this.refresh) {
|
|
54
|
-
let d = await p
|
|
55
|
-
if (d) {
|
|
56
|
-
this.hasData = true
|
|
57
|
-
this.status = false
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
</script>
|
|
64
|
-
|
|
65
|
-
<style></style>
|
|
66
|
-
|
package/vue2/exx.vue
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
const NOOP = () => { }
|
|
3
|
-
export function useContext() {
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
let i = 0
|
|
8
|
-
export default {
|
|
9
|
-
name: 'ex',
|
|
10
|
-
data() {
|
|
11
|
-
return {
|
|
12
|
-
exx: 'exx1'
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
created() {
|
|
16
|
-
console.log(122222)
|
|
17
|
-
this.test()
|
|
18
|
-
},
|
|
19
|
-
mounted() {
|
|
20
|
-
|
|
21
|
-
},
|
|
22
|
-
components: {
|
|
23
|
-
|
|
24
|
-
},
|
|
25
|
-
methods: {
|
|
26
|
-
test() {
|
|
27
|
-
setTimeout(() => {
|
|
28
|
-
this.exx = 'exx2'
|
|
29
|
-
const { resolve } = this.$options.context
|
|
30
|
-
console.log(resolve)
|
|
31
|
-
i++
|
|
32
|
-
resolve(i)
|
|
33
|
-
|
|
34
|
-
}, 3000)
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
render() {
|
|
38
|
-
return <div>{this.exx}</div>
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
</script>
|
|
42
|
-
|
|
43
|
-
<style></style>
|
|
44
|
-
|