cbvirtua 1.0.3 → 1.0.5
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/floating/components/Popper.js +1011 -0
- package/floating/components/PopperMethods.js +17 -0
- package/floating/components/ThemeClass.js +9 -0
- package/floating/config.js +133 -0
- package/floating/demo/TestDropdown.vue +22 -0
- package/floating/demo/TestSubMenu.vue +87 -0
- package/floating/demo/TestTooltip.vue +19 -0
- package/floating/directives/v-close-popper.js +67 -0
- package/floating/directives/v-tooltip.js +116 -0
- package/floating/directives/v-tooltip.spec.js +28 -0
- package/floating/index.js +74 -0
- package/floating/util/assign-deep.js +12 -0
- package/floating/util/env.js +18 -0
- package/floating/util/events.js +12 -0
- package/floating/util/frame.js +5 -0
- package/floating/util/lang.js +6 -0
- package/floating/util/popper.js +5 -0
- package/package.json +1 -1
- package/vue2/ListItem.js +46 -0
- package/vue2/VList.js +161 -0
package/vue2/ListItem.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isRTLDocument } from "../core/environment";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
props: {
|
|
5
|
+
children: { type: Object, required: true },
|
|
6
|
+
resizer: { type: Function, required: true },
|
|
7
|
+
index: { type: Number, required: true },
|
|
8
|
+
offset: { type: Number, required: true },
|
|
9
|
+
hide: { type: Boolean },
|
|
10
|
+
isHorizontal: { type: Boolean },
|
|
11
|
+
element: { type: String, required: true },
|
|
12
|
+
},
|
|
13
|
+
watch: {
|
|
14
|
+
index(_index) {
|
|
15
|
+
this.$nextTick(() => {
|
|
16
|
+
this.cleanupObserver = null;
|
|
17
|
+
const root = this.$refs.root;
|
|
18
|
+
this.cleanupObserver = this.resizer(root, _index);
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
mounted() {
|
|
23
|
+
const root = this.$refs.root;
|
|
24
|
+
this.cleanupObserver = this.resizer(root, this.index);
|
|
25
|
+
},
|
|
26
|
+
render() {
|
|
27
|
+
const { children, offset, hide, element: Element, isHorizontal, } = this;
|
|
28
|
+
console.log(hide)
|
|
29
|
+
const style = {
|
|
30
|
+
margin: 0,
|
|
31
|
+
padding: 0,
|
|
32
|
+
position: "absolute",
|
|
33
|
+
[isHorizontal ? "height" : "width"]: "100%",
|
|
34
|
+
[isHorizontal ? "top" : "left"]: "0px",
|
|
35
|
+
[isHorizontal ? (isRTLDocument() ? "right" : "left") : "top"]: offset + "px",
|
|
36
|
+
visibility: hide ? "hidden" : "visible",
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
if (isHorizontal) {
|
|
40
|
+
style.display = "flex";
|
|
41
|
+
}
|
|
42
|
+
return (<Element ref={"root"} style={style}>
|
|
43
|
+
{children}
|
|
44
|
+
</Element>);
|
|
45
|
+
}
|
|
46
|
+
}
|
package/vue2/VList.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
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
|
+
}
|