Skip to content

Commit

Permalink
🚑 Fix: Changing router view cause error in ResizeObserver.observe m…
Browse files Browse the repository at this point in the history
…ethod. Set lenis options to default in `destroy`.
  • Loading branch information
somespecialone committed Nov 17, 2023
1 parent 34b204e commit 3e75987
Show file tree
Hide file tree
Showing 15 changed files with 241 additions and 109 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Release

on:
push:
tags:
- v*

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
steps:
- uses: actions/checkout@v4

# it would be nice to be able to generate change logs there

- name: Create & publish release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[![Made in Ukraine](https://img.shields.io/badge/made_in-ukraine-ffd700.svg?labelColor=0057b7)](https://stand-with-ukraine.pp.ua)
[![license](https://img.shields.io/github/license/somespecialone/vuecomotive-scroll)](https://github.com/somespecialone/vuecomotive-scroll/blob/master/LICENSE)
[![npm](https://img.shields.io/npm/v/vuecomotive-scroll)](https://www.npmjs.com/package/vuecomotive-scroll)
![npm bundle size](https://img.shields.io/bundlephobia/minzip/vuecomotive-scroll)
[![Docs](https://github.com/somespecialone/vuecomotive-scroll/actions/workflows/docs.yml/badge.svg)](https://github.com/somespecialone/vuecomotive-scroll/actions/workflows/docs.yml)
[![Publish](https://github.com/somespecialone/vuecomotive-scroll/actions/workflows/publish.yml/badge.svg)](https://github.com/somespecialone/vuecomotive-scroll/actions/workflows/publish.yml)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat)](https://github.com/prettier/prettier)
Expand Down Expand Up @@ -51,7 +52,7 @@ yarn add vuecomotive-scroll
Specified version

```html
<script src="https://unpkg.com/vuecomotive-scroll@0.2.1"></script>
<script src="https://unpkg.com/vuecomotive-scroll@0.2.2"></script>
```

Latest
Expand Down
1 change: 1 addition & 0 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"dependencies": {
"vue": "^3.3.4",
"vue-router": "^4.2.5",
"vuecomotive-scroll": "latest"
},
"devDependencies": {
Expand Down
109 changes: 14 additions & 95 deletions demo/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,57 +1,15 @@
<script setup lang="ts">
// TODO make some more feature presentable and clean this
import { onMounted, ref, watch } from 'vue'
import { useScroll, ScrollView, ScrollComponent } from 'vuecomotive-scroll'
const flag = ref(true)
const duration = ref(1.4)
const { scrollTo, scroll, direction, isScrolling, isReady } = useScroll()
const zero = ref<InstanceType<typeof ScrollComponent> | null>(null)
const zero1 = ref<InstanceType<typeof ScrollComponent> | null>(null)
const blank = ref<HTMLElement>()
onMounted(() => {
document.addEventListener('click', (e) => {
const t = e.target as HTMLElement
if (t.tagName === 'A' && t.getAttribute('href').startsWith('#')) {
scrollTo(t.getAttribute('href'))
}
})
})
function handleMounted() {}
function handleInsersect(d) {}
//
</script>

<template>
<ScrollView :duration="duration" root css-direction>
<header>
<a href="#top">top</a>
<a href="#zero1">zero1</a>
<a href="#second">second</a>
<a href="#blank">blank</a>
</header>
<ScrollComponent @vue:mounted="handleMounted" id="top" is="section" class="zero" ref="zero">
Scroll comp text!!!
</ScrollComponent>
<ScrollComponent id="zero1" :class="{ flag }" :speed="0.2" is="section" class="zero1" ref="zero1">
Scroll !!1
</ScrollComponent>
<div class="first" @click="scrollTo(blank)">Main div</div>
<div id="second" class="second" data-scroll data-scroll-speed="0.2" :data-flag="flag">Child el!!!</div>
<div class="third" @click="$scrollTo(zero.el)">Main third div</div>
<div id="blank" class="blank" ref="blank" @click="scrollTo(zero.el)"></div>
<ScrollComponent
in-view-class="test-in-view-class"
repeat
:style="{ height: '25vh', background: 'blue' }"
@intersect="handleInsersect"
/>
</ScrollView>
<main>
<div class="nav-bar">
<RouterLink to="/">Home</RouterLink>
<RouterLink to="/lazy">Lazy</RouterLink>
</div>
<RouterView />
</main>
</template>

<style>
Expand All @@ -62,54 +20,15 @@ body {
background-color: mediumpurple;
}
header {
.nav-bar {
position: fixed;
top: 0;
z-index: 99;
width: 100%;
z-index: 100;
right: 0;
display: flex;
justify-content: center;
gap: 1em;
}
.zero {
height: 30vh;
background-color: coral;
}
.zero1 {
height: 25vh;
background-color: lightpink;
}
.zero1.flag {
display: none;
}
.first {
height: 35vh;
background-color: antiquewhite;
}
.second {
height: 15vh;
background-color: cadetblue;
}
.second[data-flag='true'] {
background-color: red;
}
.third {
height: 25vh;
background-color: black;
}
.blank {
height: 100vh;
gap: 1rem;
padding: 0 1rem;
background-color: aquamarine;
background: cadetblue;
}
</style>
20 changes: 19 additions & 1 deletion demo/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
import { createApp } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'

import 'vuecomotive-scroll/dist/lenis.css'

import createVuecomotiveScroll from 'vuecomotive-scroll'

import App from './App.vue'
import HomeRoute from '@/pages/HomeRoute.vue'

const app = createApp(App)

const router = createRouter({
history: createWebHistory(),
routes: [
{
path: '/lazy',
name: 'lazy',
component: () => import('@/pages/LazyRoute.vue')
},
{
path: '/',
name: 'home',
component: HomeRoute
}
]
})

app.use(createVuecomotiveScroll())
app.use(router)

app.mount('#app')
113 changes: 113 additions & 0 deletions demo/src/pages/HomeRoute.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<script setup lang="ts">
// TODO make some more feature presentable and clean this
import { onMounted, ref, watch } from 'vue'
import { useScroll, ScrollView, ScrollComponent } from 'vuecomotive-scroll'
const flag = ref(true)
const duration = ref(1.4)
const { scrollTo, scroll, direction, isScrolling, isReady } = useScroll()
const zero = ref<InstanceType<typeof ScrollComponent> | null>(null)
const zero1 = ref<InstanceType<typeof ScrollComponent> | null>(null)
const blank = ref<HTMLElement>()
onMounted(() => {
document.addEventListener('click', (e) => {
const t = e.target as HTMLElement
if (t.tagName === 'A' && t.getAttribute('href').startsWith('#')) {
scrollTo(t.getAttribute('href'))
}
})
})
function handleMounted() {}
function handleInsersect(d) {}
</script>

<template>
<ScrollView class="home-route" :duration="duration" css-direction>
<header>
<a href="#top">top</a>
<a href="#zero1">zero1</a>
<a href="#second">second</a>
<a href="#blank">blank</a>
</header>
<ScrollComponent @vue:mounted="handleMounted" id="top" is="section" class="zero" ref="zero">
Scroll comp text!!!
</ScrollComponent>
<ScrollComponent id="zero1" :class="{ flag }" :speed="0.2" is="section" class="zero1" ref="zero1">
Scroll !!1
</ScrollComponent>
<div class="first" @click="scrollTo(blank)">Main div</div>
<div id="second" class="second" data-scroll data-scroll-speed="0.2" :data-flag="flag">Child el!!!</div>
<div class="third" @click="$scrollTo(zero.el)">Main third div</div>
<div id="blank" class="blank" ref="blank" @click="scrollTo(zero.el)"></div>
<ScrollComponent
in-view-class="test-in-view-class"
repeat
:style="{ height: '25vh', background: 'blue' }"
@intersect="handleInsersect"
/>
</ScrollView>
</template>

<style>
header {
position: fixed;
top: 0;
z-index: 99;
width: 100%;
display: flex;
justify-content: center;
gap: 1em;
}
.home-route {
height: 100vh;
overflow: hidden;
}
.zero {
height: 30vh;
background-color: coral;
}
.zero1 {
height: 25vh;
background-color: lightpink;
}
.zero1.flag {
display: none;
}
.first {
height: 35vh;
background-color: antiquewhite;
}
.second {
height: 15vh;
background-color: cadetblue;
}
.second[data-flag='true'] {
background-color: red;
}
.third {
height: 25vh;
background-color: black;
}
.blank {
height: 100vh;
background-color: aquamarine;
}
</style>
42 changes: 42 additions & 0 deletions demo/src/pages/LazyRoute.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<script setup lang="ts">
import { useScroll, ScrollView, ScrollComponent } from 'vuecomotive-scroll'
</script>

<template>
<ScrollView class="lazy-route" horizontal>
<ScrollComponent class="scroll-el-1">Scroll element #1</ScrollComponent>
<ScrollComponent class="scroll-el-2" :speed="-0.5">Scroll element #2</ScrollComponent>
<ScrollComponent class="scroll-el-3">Scroll element #3</ScrollComponent>
</ScrollView>
</template>

<style>
.lazy-route {
height: 100vh;
overflow: hidden;
}
.lazy-route > div {
width: fit-content;
height: 100%;
display: flex;
}
.scroll-el-1 {
width: 20vw;
height: 100%;
background: rebeccapurple;
}
.scroll-el-2 {
width: 70vw;
height: 100%;
background: aquamarine;
}
.scroll-el-3 {
width: 40vw;
height: 100%;
background: darkorange;
}
</style>
1 change: 1 addition & 0 deletions docs/core/scroll-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ so don't use dynamic rendering or change width/height properties of elements ins
| cssDirection | boolean | + | *false* | Same as `cssProgress` ⬆️, but in `--scroll-direction` property. Possible values are -1 (up), 1 (down). |
| wrapperIs | string/Component | - | `div` | Specifies which component to render. Same as `is` prop on [component](https://vuejs.org/api/built-in-special-elements.html#component). |
| contentIs | string/Component | - | `div` | ⬆️ |
| horizontal | boolean | - | *false* | Scroll orientation. Default - `vertical` |

Other props are [options from Lenis](https://scroll.locomotive.ca/docs/#/options?id=lenisoptions) and non-reactive.

Expand Down
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vuecomotive-scroll",
"version": "0.2.1",
"version": "0.2.2",
"description": "Vue wrapper for precious Locomotive scroll",
"keywords": [
"typescript",
Expand Down
1 change: 0 additions & 1 deletion lib/src/components/ScrollComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export interface IComponentProps {
// TODO Do I need to handle css progress by myself?
// TODO Boolean prop to enable/disable progress event emitting is more sufficient than emitting progress event by default in each component
// @ts-ignore
const props = withDefaults(defineProps<IComponentProps & IScrollElementProps>(), {
is: 'div',
inViewClass: 'is-inview'
Expand Down

0 comments on commit 3e75987

Please sign in to comment.