Skip to content

Commit

Permalink
2.4.2 (#52)
Browse files Browse the repository at this point in the history
* Core - Rename eventCount

* Core - Fine-tune syncTransitionStyles

* Demo - Edit NavActions

* Pkg - Bump 2.4.2

* Core - Edit comments

* Pkg - Disable output minification
  • Loading branch information
smastrom authored Apr 15, 2024
1 parent b7c2705 commit 6b29277
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 52 deletions.
16 changes: 2 additions & 14 deletions demo/components/nav/NavActions.vue
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
<script setup lang="ts">
const { entries } = useNotifications()
const { isRunning, startInstance, stopInstance } = useNotivueInstance()
</script>

<template>
<SharedButton
@click="push.clearAll()"
text="Dismiss All"
:isDisabled="entries.length === 0"
:key="entries.length"
>
<SharedButton @click="push.clearAll" text="Dismiss All">
<IconsDismissIcon />
</SharedButton>
<SharedButton
@click="push.destroyAll()"
text="Destroy All"
:isDisabled="entries.length === 0"
:key="entries.length"
>
<SharedButton @click="push.destroyAll" text="Destroy All">
<IconsDestroyIcon />
</SharedButton>

Expand Down
2 changes: 1 addition & 1 deletion packages/notivue/core/createNotivue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function createInstance(startOnCreation: boolean) {

store.items.clear()
store.queue.clear()
store.items.clearEffects()
store.items.clearLifecycleEvents()
store.animations.resetTransitionStyles()

setPush(createPushMock())
Expand Down
70 changes: 38 additions & 32 deletions packages/notivue/core/createStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ref, shallowRef, triggerRef, unref, isRef, type Ref } from 'vue'
import { ref, shallowRef, triggerRef, unref, isRef, type Ref, type CSSProperties } from 'vue'

import {
createConfigRefs,
Expand Down Expand Up @@ -88,17 +88,17 @@ export function createItems(config: ConfigSlice, queue: QueueSlice) {
get length() {
return this.entries.value.length
},
effectsCount: ref(0),
addEffect() {
this.effectsCount.value++
lifecycleEventsCount: ref(0),
addLifecycleEvent() {
this.lifecycleEventsCount.value++
},
clearEffects() {
this.effectsCount.value = 0
clearLifecycleEvents() {
this.lifecycleEventsCount.value = 0
},
add(item: StoreItem) {
this.entries.value.unshift(item)
this.triggerRef()
this.addEffect()
this.addLifecycleEvent()
},
addFromQueue() {
const next = {
Expand Down Expand Up @@ -167,40 +167,36 @@ export function createAnimations(
queue: QueueSlice,
elements: ElementsSlice
) {
type TransitionStyles = { transitionDuration: string; transitionTimingFunction: string }
let tStyles = ['0.35s', 'cubic-bezier(0.5, 1, 0.25, 1)']

return {
isReducedMotion: ref(false),
transitionStyles: null as null | TransitionStyles,
transitionStyles: null as null | Pick<CSSProperties, 'transitionDuration' | 'transitionTimingFunction'>, // prettier-ignore
setReducedMotion(newVal: boolean) {
this.isReducedMotion.value = newVal
},
getTransitionStyles() {
if (!this.transitionStyles) this.syncTransitionStyles()
return this.transitionStyles
},
resetTransitionStyles() {
this.transitionStyles = null
},
syncTransitionStyles() {
const mountedRoot = elements.root.value
if (!mountedRoot) return // If the root is not yet queryable, try to sync the next push

const enterClass = config.animations.value.enter
const animEl = enterClass ? mountedRoot.querySelector(`.${enterClass}`) : null

console.log('Syncing transition styles')
const { enter } = config.animations.value

if (!animEl) {
this.transitionStyles = { transitionDuration: '0s', transitionTimingFunction: 'ease' }
if (!enter) {
tStyles = ['0s', 'ease']
} else {
const styles = window.getComputedStyle(animEl)
const animEl = elements.root.value?.querySelector(`.${enter}`)
if (animEl) {
console.log('Syncing transition styles')

this.transitionStyles = {
transitionDuration: styles.animationDuration,
transitionTimingFunction: styles.animationTimingFunction,
const style = window.getComputedStyle(animEl)
tStyles = [style.animationDuration, style.animationTimingFunction]
}
}

this.transitionStyles = {
transitionDuration: tStyles[0],
transitionTimingFunction: tStyles[1],
}
},
playLeave(id: string, { isDestroy = false, isUserTriggered = false } = {}) {
const { leave = '' } = config.animations.value
Expand All @@ -216,7 +212,7 @@ export function createAnimations(
}

if (!item || !leave || isDestroy || this.isReducedMotion.value) {
items.addEffect()
items.addLifecycleEvent()
return onAnimationend()
}

Expand All @@ -231,7 +227,7 @@ export function createAnimations(
},
})

items.addEffect()
items.addLifecycleEvent()
},
playClearAll() {
items.entries.value.forEach((e) => window.clearTimeout(e.timeout as number))
Expand All @@ -251,9 +247,19 @@ export function createAnimations(
})
},
updatePositions({ isImmediate = false } = {}) {
const transitionStyles = this.getTransitionStyles()
if (!transitionStyles) return

if (!this.transitionStyles) {
// Runs the first time a notification is rendered
window.requestAnimationFrame(() => {
this.syncTransitionStyles()
window.requestAnimationFrame(() => {
this.updatePositionsImpl(isImmediate)
})
})
} else {
this.updatePositionsImpl(isImmediate)
}
},
updatePositionsImpl(isImmediate: boolean) {
console.log('Updating positions')

const isReduced = this.isReducedMotion.value || isImmediate
Expand All @@ -272,7 +278,7 @@ export function createAnimations(
positionStyles: {
willChange: 'transform',
transform: `translate3d(0, ${accPrevHeights}px, 0)`,
...(isReduced ? { transition: 'none' } : transitionStyles),
...(isReduced ? { transition: 'none' } : this.transitionStyles),
},
})

Expand Down
2 changes: 1 addition & 1 deletion packages/notivue/core/createStoreWatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { NotivueStore } from 'notivue'
export function createStoreWatchers(store: NotivueStore) {
return [
watch(
store.items.effectsCount,
store.items.lifecycleEventsCount,
() => {
store.animations.updatePositions()
},
Expand Down
2 changes: 1 addition & 1 deletion packages/notivue/nuxt/module.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "notivue/nuxt",
"configKey": "notivue",
"version": "2.4.1"
"version": "2.4.2"
}
2 changes: 1 addition & 1 deletion packages/notivue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "notivue",
"version": "2.4.1",
"version": "2.4.2",
"private": false,
"description": "Powerful toast notification system for Vue and Nuxt",
"keywords": [
Expand Down
5 changes: 3 additions & 2 deletions packages/notivue/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ export default defineConfig({
},
esbuild: {
drop: isFinalBundle ? ['console'] : [],
...(!isFinalBundle ? { minifyIdentifiers: false, minifySyntax: false } : {}),
minifyIdentifiers: false,
minifySyntax: false,
},
build: {
emptyOutDir: isFinalBundle,
target: 'es2015',
minify: isFinalBundle ? 'esbuild' : false,
minify: false,
lib: {
entry: 'index.ts',
fileName: 'index',
Expand Down

0 comments on commit 6b29277

Please sign in to comment.