Skip to content

Commit 2cc47fc

Browse files
authored
Merge pull request #14 from FallingCeilingS/v0.1.4/api-playground
API playground
2 parents d86d080 + 66c0923 commit 2cc47fc

File tree

5 files changed

+68
-12
lines changed

5 files changed

+68
-12
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-virtualised",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"private": false,
55
"description": "Vue components developed by Vue.js 3.0 for efficiently rendering large scrollable lists and hierarchical data. vue-virtualised is able to render and update 1 million nodes within a few seconds in front-end.",
66
"author": {

src/components/Base/VirtualisedBaseScroller.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ import {
8080
GetNodeKey,
8181
CellRenderer,
8282
ConditionCallback,
83-
} from "../../types/types";
83+
} from "@/types/types";
8484
8585
export default defineComponent({
8686
name: "VirtualisedBaseScroller",
@@ -226,7 +226,7 @@ export default defineComponent({
226226
: initialScrollTop.value
227227
);
228228
229-
// Calculte total content height.
229+
// Calculate total content height.
230230
// TODO: Fix the content height limitation of 33554400px.
231231
const getTotalHeight = (
232232
nodes: Array<any>,
@@ -363,6 +363,7 @@ export default defineComponent({
363363
});
364364
};
365365
366+
// TODO: add parameter to set behaviour
366367
const getScrollTop = (): number => scrollTop.value;
367368
368369
const scrollToStart = (): void => {

src/examples/demo-example/DemoExample.vue

+55
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22
<div class="app-container">
33
<div class="list-container">
44
<div class="title">VirtualisedList</div>
5+
<div>
6+
<button @click="scrollListToStart">Scroll To Start</button>
7+
<button @click="scrollListToEnd">Scroll To End</button>
8+
<button @click="scrollListToIndex">Scroll To Index</button>
9+
<input v-model="listIndex" type="number" min="0" />
10+
<button @click="scrollListToHeight">Scroll To Height</button>
11+
<input v-model="listHeight" type="number" min="0" />
12+
</div>
513
<virtualised-list
14+
ref="listView"
615
:nodes="data"
716
:viewport-height="viewportHeight"
817
:initial-scroll-top="initialScrollTop"
@@ -20,6 +29,15 @@
2029
</div>
2130
<div class="tree-container">
2231
<div class="title">VirtualisedTree</div>
32+
<div>
33+
<button @click="scrollTreeToStart">Scroll To Start</button>
34+
<button @click="scrollTreeToEnd">Scroll To End</button>
35+
<button @click="scrollTreeToIndex">Scroll To Index</button>
36+
<input v-model="treeIndex" type="number" min="0" />
37+
<button @click="scrollTreeToHeight">Scroll To Height</button>
38+
<input v-model="treeHeight" type="number" min="0" />
39+
<button @click="forceUpdate">Force Refresh</button>
40+
</div>
2341
<virtualised-tree
2442
ref="treeView"
2543
:nodes="nodes"
@@ -60,8 +78,19 @@ export default defineComponent({
6078
VirtualisedTree,
6179
},
6280
setup() {
81+
const listView = ref<typeof VirtualisedList | null>(null);
6382
const treeView = ref<typeof VirtualisedTree | null>(null);
6483
84+
const listIndex = ref<number>(0);
85+
const listHeight = ref<number>(0);
86+
87+
const scrollListToStart = () => listView.value?.scrollToStart();
88+
const scrollListToEnd = () => listView.value?.scrollToEnd();
89+
const scrollListToIndex = () =>
90+
listView.value?.scrollToIndex(listIndex.value);
91+
const scrollListToHeight = () =>
92+
listView.value?.scrollToHeight(listHeight.value);
93+
6594
const nodes = constructFixedTree(6, 15, 5);
6695
6796
const onChange = (nodes: Array<Node | NodeModel>) =>
@@ -71,6 +100,18 @@ export default defineComponent({
71100
h("div", { class: "cell-container list-cell-container" }, node.label),
72101
];
73102
103+
const treeIndex = ref<number>(0);
104+
const treeHeight = ref<number>(0);
105+
106+
const scrollTreeToStart = () => treeView.value?.scrollToStart();
107+
const scrollTreeToEnd = () => treeView.value?.scrollToEnd();
108+
const scrollTreeToIndex = () =>
109+
treeView.value?.scrollToIndex(treeIndex.value);
110+
const scrollTreeToHeight = () =>
111+
treeView.value?.scrollToHeight(treeHeight.value);
112+
113+
const forceUpdate = async () => await treeView.value?.forceUpdate();
114+
74115
const treeCellRenderer = (node: NodeModel, index: number) => [
75116
h(
76117
"div",
@@ -175,11 +216,25 @@ export default defineComponent({
175216
};
176217
177218
return {
219+
listView,
178220
treeView,
221+
listIndex,
222+
listHeight,
223+
scrollListToStart,
224+
scrollListToEnd,
225+
scrollListToIndex,
226+
scrollListToHeight,
179227
nodes,
180228
onChange,
181229
listCellRenderer,
182230
treeCellRenderer,
231+
treeIndex,
232+
treeHeight,
233+
scrollTreeToStart,
234+
scrollTreeToEnd,
235+
scrollTreeToIndex,
236+
scrollTreeToHeight,
237+
forceUpdate,
183238
handleScroll,
184239
handleStartReached,
185240
handleEndReached,

src/examples/simple-example/SimpleExample.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@
6060
</template>
6161

6262
<script>
63-
import { ref, onMounted } from "vue";
64-
import VirtualisedList from "../../components/VirtualisedList";
65-
import VirtualisedTree from "../../components/VirtualisedTree";
63+
import { defineComponent, ref, onMounted } from "vue";
64+
import VirtualisedList from "@/components/VirtualisedList";
65+
import VirtualisedTree from "@/components/VirtualisedTree";
6666
67-
export default {
67+
export default defineComponent({
6868
name: "SimpleExample",
6969
components: { VirtualisedList, VirtualisedTree },
7070
setup() {
@@ -85,7 +85,7 @@ export default {
8585
onSelectedComponentChange,
8686
};
8787
},
88-
};
88+
});
8989
</script>
9090

9191
<style></style>

src/main.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createApp } from "vue";
2-
import SimpleExample from "./examples/simple-example/SimpleExample.vue";
3-
// import DemoExample from "./examples/demo-example/DemoExample.vue";
2+
// import SimpleExample from "./examples/simple-example/SimpleExample.vue";
3+
import DemoExample from "./examples/demo-example/DemoExample.vue";
44

5-
createApp(SimpleExample).mount("#app");
6-
// createApp(DemoExample).mount("#app");
5+
// createApp(SimpleExample).mount("#app");
6+
createApp(DemoExample).mount("#app");

0 commit comments

Comments
 (0)