Skip to content

Commit 4d9380a

Browse files
authored
Merge pull request #35 from oumoussa98/feat/intersection-observer
Feat/intersection observer
2 parents d704a5b + f7705fd commit 4d9380a

32 files changed

+759
-363
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

example/package.json renamed to demo/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
{
2-
"name": "vu3-infinite-loading-example",
2+
"name": "vu3-infinite-loading-demo",
33
"version": "0.0.0",
44
"scripts": {
55
"dev": "vite",
66
"build": "vite build",
77
"serve": "vite preview"
88
},
99
"dependencies": {
10-
"v3-infinite-loading": "^1.1.4",
1110
"vue": "^3.2.13"
1211
},
1312
"devDependencies": {
File renamed without changes.

example/src/App.vue renamed to demo/src/App.vue

+21-13
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,32 @@ import { ref, nextTick } from "vue";
33
import Top from "./components/Top.vue";
44
import Bottom from "./components/Bottom.vue";
55
import Checkbox from "./components/Checkbox.vue";
6-
76
let page = 0;
87
let mount = ref(true);
98
let resetData = ref(false);
109
let target = ref(".bottom-results");
11-
let distance = ref(100);
10+
let distance = ref(0);
1211
let top = ref(false);
1312
let comments = ref([]);
1413
let mountname = ref("Unmount");
15-
1614
const refresh = () => {
1715
page = 0;
1816
comments.value.length = 0;
1917
resetData.value = !resetData.value;
2018
};
21-
2219
const reset = () => {
2320
target.value = ".bottom-results";
24-
distance.value = 100;
21+
distance.value = 0;
2522
top.value = false;
2623
mount.value = true;
2724
mountname.value = "Unmount";
2825
refresh();
2926
};
30-
3127
const mountToggler = async () => {
3228
mount.value = !mount.value;
3329
if (!mount.value) mountname.value = "Mount";
3430
else mountname.value = "Unmount";
3531
};
36-
3732
const targetToggler = async () => {
3833
top.value = false;
3934
if (target.value) target.value = false;
@@ -44,18 +39,21 @@ const targetToggler = async () => {
4439
mountToggler();
4540
refresh();
4641
};
47-
4842
const topToggler = async () => {
4943
top.value = !top.value;
5044
if (top.value) target.value = ".top-results";
5145
else target.value = ".bottom-results";
46+
mountToggler();
47+
await nextTick();
48+
mountToggler();
5249
refresh();
5350
};
54-
5551
const distanceHandler = async () => {
52+
mountToggler();
53+
await nextTick();
54+
mountToggler();
5655
refresh();
5756
};
58-
5957
const load = async $state => {
6058
console.log("loading more...");
6159
page++;
@@ -78,12 +76,19 @@ const load = async $state => {
7876

7977
<template>
8078
<div class="settings">
81-
<a target="_blank" href="https://github.com/oumoussa98/vue3-infinite-loading/tree/main/example">
79+
<a
80+
target="_blank"
81+
href="https://github.com/oumoussa98/vue3-infinite-loading/tree/main/example"
82+
>
8283
<img src="./assets/github.svg" alt="github icon" />
8384
</a>
8485
<span class="props">
85-
<Checkbox :checked="top" :disabled="!target" label="top" @click="topToggler"> Top </Checkbox>
86-
<Checkbox :checked="target" label="target" @click="targetToggler"> Target </Checkbox>
86+
<Checkbox :checked="top" :disabled="!target" label="top" @click="topToggler">
87+
Top
88+
</Checkbox>
89+
<Checkbox :checked="target" label="target" @click="targetToggler">
90+
Target
91+
</Checkbox>
8792
<div>
8893
Distance:
8994
<input
@@ -226,6 +231,9 @@ body {
226231
background: #101011;
227232
border-radius: 10px;
228233
}
234+
.loader {
235+
padding: 10px;
236+
}
229237
.results::-webkit-scrollbar-track {
230238
border-radius: 4px;
231239
background: #333536;
File renamed without changes.
File renamed without changes.

example/src/components/Bottom.vue renamed to demo/src/components/Bottom.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const { comments } = toRefs(props);
1414
<div>{{ comment.email }}</div>
1515
<div>{{ comment.id }}</div>
1616
</div>
17-
<infinite-loading v-bind="$attrs" />
17+
<infinite-loading class="loader" v-bind="$attrs" />
1818
</div>
1919
</div>
2020
</template>

example/src/components/Top.vue renamed to demo/src/components/Top.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const { comments } = toRefs(props);
1010
<template>
1111
<div v-bind="$attrs">
1212
<div class="results" :class="{ 'top-results': $attrs.target }">
13-
<infinite-loading top v-bind="$attrs" />
13+
<infinite-loading class="loader" top v-bind="$attrs" />
1414
<div class="result" v-for="comment in comments" :key="comment.id">
1515
<div>{{ comment.email }}</div>
1616
<div>{{ comment.id }}</div>

demo/src/main.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { createApp } from "vue";
2+
import App from "./App.vue";
3+
import "../lib/style.css";
4+
5+
import InfiniteLoading from "../../src/components/InfiniteLoading.vue";
6+
7+
const app = createApp(App);
8+
9+
if (import.meta.env.MODE === "production") {
10+
const modules = import.meta.glob("../lib/v3-infinite-loading.mjs", { eager: true });
11+
const InfiniteLoadingProd = modules["../lib/v3-infinite-loading.mjs"].default;
12+
app.component("infinite-loading", InfiniteLoadingProd);
13+
} else app.component("infinite-loading", InfiniteLoading);
14+
15+
app.mount("#app");

example/vite.config.js renamed to demo/vite.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ import vue from "@vitejs/plugin-vue";
44
// https://vitejs.dev/config/
55
export default defineConfig({
66
plugins: [vue()],
7+
alias: {
8+
"@parent/": require("path").resolve(__dirname, "../../"),
9+
},
710
});

docs/.github/scripts/tag-alert-blocks.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ async function isUsingAlertBlock(base = 'origin/master') {
2424
result
2525
.trim()
2626
.split(/\r?\n/)
27-
.map(file =>
27+
.map((file) =>
2828
run(`git diff ${base} -- ${file}`)
29-
.then(diff => ALERT_BLOCK.test(diff))
30-
.then(usesAlertBlock => (usesAlertBlock ? file : ''))
29+
.then((diff) => ALERT_BLOCK.test(diff))
30+
.then((usesAlertBlock) => (usesAlertBlock ? file : ''))
3131
)
3232
)
3333
).filter(Boolean)

docs/.vitepress/config.ts

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { defineConfigWithTheme } from 'vitepress'
32
import baseConfig from '@vue/theme/config'
43
import type { Config } from '@vue/theme'
@@ -9,7 +8,7 @@ const nav = [
98
text: 'Docs',
109
activeMatch: `^/(guide)/`,
1110
link: '/guide/introduction'
12-
},
11+
}
1312
]
1413

1514
export const sidebar = {
@@ -39,18 +38,19 @@ export const sidebar = {
3938
{
4039
text: 'Slots',
4140
link: '/guide/api/slots'
42-
},
43-
],
44-
},
45-
],
41+
}
42+
]
43+
}
44+
]
4645
}
4746

4847
export default defineConfigWithTheme<Config>({
4948
extends: baseConfig as () => UserConfig<Config>,
5049

5150
lang: 'en-US',
5251
title: 'infinite scroll',
53-
description: 'An infinite scroll component compatible with vue.js 3 and vite',
52+
description:
53+
'An infinite scroll component compatible with vue.js 3 and vite',
5454
srcDir: 'src',
5555
scrollOffset: 'header',
5656

@@ -63,7 +63,7 @@ export default defineConfigWithTheme<Config>({
6363
name: 'twitter:image',
6464
content: 'https://vuejs.org/images/logo.png'
6565
}
66-
],
66+
]
6767
],
6868

6969
themeConfig: {
@@ -85,14 +85,17 @@ export default defineConfigWithTheme<Config>({
8585
// },
8686

8787
socialLinks: [
88-
{ icon: 'github', link: 'https://github.com/oumoussa98/vue3-infinite-loading' },
88+
{
89+
icon: 'github',
90+
link: 'https://github.com/oumoussa98/vue3-infinite-loading'
91+
}
8992
],
9093

9194
footer: {
9295
license: {
9396
text: 'MIT License',
9497
link: 'https://opensource.org/licenses/MIT'
95-
},
98+
}
9699
}
97100
},
98101

docs/.vitepress/theme/components/Home.vue

+41-31
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
<script setup>
2-
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms))
2+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
33
const displayHint = async (text) => {
4-
const el = document.querySelector("div.install .inner-text");
5-
el.innerText = text;
6-
el.parentElement.style.color = "#00c96f";
4+
const el = document.querySelector('div.install .inner-text')
5+
el.innerText = text
6+
el.parentElement.style.color = '#00c96f'
77
await sleep(1500)
8-
el.parentElement.style.color = "#aac8e4"
9-
el.innerText = "npm i v3-infinite-loading";
10-
};
8+
el.parentElement.style.color = '#aac8e4'
9+
el.innerText = 'npm i v3-infinite-loading'
10+
}
1111
1212
const copyText = () => {
1313
navigator.clipboard
14-
.writeText("npm i v3-infinite-loading")
15-
.then(() => {
16-
displayHint("Copied to clipboard");
17-
})
18-
.catch(() => {
19-
displayHint("Failed to copy 😞");
20-
});
21-
};
22-
14+
.writeText('npm i v3-infinite-loading')
15+
.then(() => {
16+
displayHint('Copied to clipboard')
17+
})
18+
.catch(() => {
19+
displayHint('Failed to copy 😞')
20+
})
21+
}
2322
</script>
2423

2524
<template>
2625
<section id="hero">
2726
<h1 class="tagline">
28-
Vue.js 3
27+
Vue.js 3
2928
<span class="accent">Infinite</span>
3029
<br />loading Component
3130
</h1>
@@ -52,36 +51,47 @@ const copyText = () => {
5251
<div @click="copyText" class="install">
5352
<span class="inner-text">npm i v3-infinite-loading</span>
5453
<svg width="16" height="19" xmlns="http://www.w3.org/2000/svg">
55-
<g>
56-
<title>Layer 1</title>
57-
<path fill="#666666" stroke="null" id="svg_1" opacity="0.35" d="m2.50926,14.0668l0,-11.0873c0,-1.53097 1.24085,-2.77183 2.77182,-2.77183l4.61971,0l5.54365,5.54365l0,8.31548c0,1.53097 -1.24085,2.77182 -2.77182,2.77182l-7.39154,0c-1.53097,0 -2.77182,-1.24085 -2.77182,-2.77182z"/>
58-
<path stroke="null" fill="#666666" id="svg_2" d="m9.84788,3.95635l0,-3.69577l5.54365,5.54365l-3.69577,0c-1.02096,0 -1.84788,-0.82693 -1.84788,-1.84788z"/>
59-
<path stroke="null" fill="#757575" id="svg_3" d="m5.22817,16.89153c-1.53097,0 -2.77183,-1.24085 -2.77183,-2.77183l0,-11.0873c-1.02096,0 -1.84788,0.82693 -1.84788,1.84788l0,11.0873c0,1.53097 1.24085,2.77183 2.77183,2.77183l7.39153,0c1.02096,0 1.84788,-0.82693 1.84788,-1.84788l-7.39153,0z"/>
60-
</g>
54+
<g>
55+
<title>Layer 1</title>
56+
<path
57+
fill="#666666"
58+
stroke="null"
59+
id="svg_1"
60+
opacity="0.35"
61+
d="m2.50926,14.0668l0,-11.0873c0,-1.53097 1.24085,-2.77183 2.77182,-2.77183l4.61971,0l5.54365,5.54365l0,8.31548c0,1.53097 -1.24085,2.77182 -2.77182,2.77182l-7.39154,0c-1.53097,0 -2.77182,-1.24085 -2.77182,-2.77182z"
62+
/>
63+
<path
64+
stroke="null"
65+
fill="#666666"
66+
id="svg_2"
67+
d="m9.84788,3.95635l0,-3.69577l5.54365,5.54365l-3.69577,0c-1.02096,0 -1.84788,-0.82693 -1.84788,-1.84788z"
68+
/>
69+
<path
70+
stroke="null"
71+
fill="#757575"
72+
id="svg_3"
73+
d="m5.22817,16.89153c-1.53097,0 -2.77183,-1.24085 -2.77183,-2.77183l0,-11.0873c-1.02096,0 -1.84788,0.82693 -1.84788,1.84788l0,11.0873c0,1.53097 1.24085,2.77183 2.77183,2.77183l7.39153,0c1.02096,0 1.84788,-0.82693 1.84788,-1.84788l-7.39153,0z"
74+
/>
75+
</g>
6176
</svg>
6277
</div>
6378
</div>
6479
</section>
6580

66-
6781
<section id="highlights" class="vt-box-container">
6882
<div class="vt-box text-center">
6983
<h2>Light and Simple</h2>
7084
<p>
71-
Light weight, Simple and easy to use api and a built in spinner
85+
Light weight, Simple and easy to use api and a built in spinner
7286
</p>
7387
</div>
7488
<div class="vt-box text-center">
7589
<h2>2-directions support</h2>
76-
<p>
77-
Support top and bottom directions
78-
</p>
90+
<p>Support top and bottom directions</p>
7991
</div>
8092
<div class="vt-box text-center">
8193
<h2>Result display</h2>
82-
<p>
83-
Fully configurable load result display
84-
</p>
94+
<p>Fully configurable load result display</p>
8595
</div>
8696
</section>
8797
</template>

docs/.vitepress/theme/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import './styles/index.css'
22
import { h, App } from 'vue'
33
import { VPTheme } from '@vue/theme'
44

5-
65
export default Object.assign({}, VPTheme, {
76
Layout: () => {
87
// @ts-ignore
98
return h(VPTheme.Layout, null)
10-
},
9+
}
1110
})
+7-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
@import "./pages.css";
2-
@import "./badges.css";
3-
@import "./options-boxes.css";
4-
@import "./inline-demo.css";
5-
@import "./utilities.css";
6-
@import "./style-guide.css";
7-
@import "./overrides.css";
8-
1+
@import './pages.css';
2+
@import './badges.css';
3+
@import './options-boxes.css';
4+
@import './inline-demo.css';
5+
@import './utilities.css';
6+
@import './style-guide.css';
7+
@import './overrides.css';

docs/.vitepress/theme/styles/inline-demo.css

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
.vt-doc a[href^="https://sfc.vuejs.org"]:before {
2-
content: "▶";
1+
.vt-doc a[href^="https://sfc.vuejs.org"]:before
2+
{
3+
content: '▶';
34
width: 20px;
45
height: 20px;
56
display: inline-block;

0 commit comments

Comments
 (0)