Skip to content

Commit b7c2705

Browse files
authored
2.4.1 (#51)
* Core - Allow passing a string ref as push parameter * Core - Streamline repositioning counters and store watchers * Demo - Improve nav controls and instance notices * Pkg - Bump 2.4.1 * Pkg - Edit nuxt/README * Pkg - Use `powerful` instead of `fully-featured` in any description * Pkg - Edit docs website url * Pkg - Fix crazy link in README * Pkg - Fix crazy link * Core - Edit comments
1 parent 9babafd commit b7c2705

15 files changed

+79
-94
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
### Powerful toast notification system for Vue and Nuxt
1010

11-
[Live Demo](https://notivue.smastrom.io) - [Documentation](https://notivuedocs.netlify.app)
11+
[Live Demo](https://notivue.smastrom.io) - [Documentation](https://docs.notivue.smastrom.io)
1212

1313
---
1414

demo/components/nav/Nav.vue

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ watch(isRunning, (newVal) => {
3030
dir="ltr"
3131
>
3232
<template v-if="isRunning">
33-
Notivue is now running again. This will be dismissed shortly.</template
33+
Notivue is now running again. This notice will be dismissed shortly.</template
3434
>
35-
<template v-else>
36-
Notivue instance has been stopped. Restart it to create notifications.
37-
</template>
35+
<template v-else> Notivue has been stopped. Restart it to create notifications. </template>
3836
</div>
3937

4038
<nav dir="ltr">

demo/components/nav/NavNotivueConfig.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ const btnProps = {
138138
.Select {
139139
text-align: center;
140140
display: flex;
141-
justify-items: center;
142141
padding-right: 1rem;
142+
cursor: pointer;
143143
144144
-webkit-appearance: none;
145145
appearance: none;

demo/components/nav/NavPushBuiltIn.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { state, messages } = useStore()
33
44
async function asyncRefMessagePush() {
55
const initialMessage = ref(state.rtl ? 'جاري تحميل الملفات...' : 'Preparing to upload files...')
6-
const notification = push.promise({ message: initialMessage })
6+
const notification = push.promise(initialMessage)
77
88
for (let n = 1; n < 4; n++) {
99
await new Promise((resolve) => setTimeout(resolve, getRandomInt(1000, 2000)))

demo/components/shared/Background.server.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<nav>
4242
<a href="https://github.com/smastrom/notivue" target="_blank">GitHub</a>
4343
<span>—</span>
44-
<a href="https://notivuedocs.netlify.app/" target="_blank">Docs</a>
44+
<a href="https://docs.notivue.smastrom.io/" target="_blank">Docs</a>
4545
</nav>
4646
</div>
4747
</div>

demo/utils/head.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const description = 'Notivue is a fully-featured toast notification system for Vue and Nuxt.'
1+
const description = 'Notivue is a powerful toast notification system for Vue and Nuxt.'
22

33
export function getHead() {
44
return {
5-
title: 'Notivue - Fully-featured toast notification system for Vue and Nuxt',
5+
title: 'Notivue - Powerful toast notification system for Vue and Nuxt',
66
link: [
77
{
88
rel: 'icon',

packages/notivue/core/createNotivue.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ function createInstance(startOnCreation: boolean) {
6262

6363
if (startOnCreation) setPush(push)
6464

65-
let unwatchStore = startOnCreation ? watchStore() : () => {}
65+
let unwatchStore = startOnCreation ? watchStore() : [() => {}]
6666

6767
const instance = {
6868
isRunning: isRunningReadonly,
6969
startInstance() {
7070
if (isRunning.value) return
7171

72-
unwatchStore = watchStore()
7372
setPush(push)
73+
unwatchStore = watchStore()
7474

7575
isRunning.value = true
7676
},
@@ -79,11 +79,11 @@ function createInstance(startOnCreation: boolean) {
7979

8080
store.items.clear()
8181
store.queue.clear()
82-
store.items.resetCount()
82+
store.items.clearEffects()
8383
store.animations.resetTransitionStyles()
8484

8585
setPush(createPushMock())
86-
unwatchStore()
86+
unwatchStore.forEach((unwatch) => unwatch())
8787

8888
isRunning.value = false
8989
},

packages/notivue/core/createPush.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { unref } from 'vue'
2+
13
import { NotificationTypeKeys as NType } from './constants'
24
import { createPushProxies } from './createStore'
35

4-
import type { NotificationType, Push, PushParameter } from 'notivue'
6+
import type { NotificationType, Push, PushOptions, PushParameter } from 'notivue'
57

68
export const push = createPushMock()
79

@@ -13,9 +15,11 @@ export function createPush(proxies: ReturnType<typeof createPushProxies>): Push
1315
let createCount = 0
1416

1517
function push(options: PushParameter, type: NotificationType, id = `${createCount++}`) {
16-
if (typeof options === 'string') options = { message: options }
18+
if (typeof unref(options) === 'string') {
19+
options = { message: options } as PushOptions
20+
}
1721

18-
proxies.push({ ...options, id, type })
22+
proxies.push({ ...(options as PushOptions), id, type })
1923

2024
return {
2125
id,

packages/notivue/core/createStore.ts

+12-22
Original file line numberDiff line numberDiff line change
@@ -84,31 +84,21 @@ export function createQueue() {
8484

8585
export function createItems(config: ConfigSlice, queue: QueueSlice) {
8686
return {
87-
createdCount: ref(0),
88-
addCreated() {
89-
this.createdCount.value++
90-
},
91-
clearedCount: ref(0),
92-
addCleared() {
93-
this.clearedCount.value++
94-
},
95-
destroyedCount: ref(0),
96-
addDestroyed() {
97-
this.destroyedCount.value++
98-
},
99-
resetCount() {
100-
this.createdCount.value = 0
101-
this.clearedCount.value = 0
102-
this.destroyedCount.value = 0
103-
},
10487
entries: shallowRef<StoreItem[]>([]),
10588
get length() {
10689
return this.entries.value.length
10790
},
91+
effectsCount: ref(0),
92+
addEffect() {
93+
this.effectsCount.value++
94+
},
95+
clearEffects() {
96+
this.effectsCount.value = 0
97+
},
10898
add(item: StoreItem) {
10999
this.entries.value.unshift(item)
110-
this.addCreated()
111100
this.triggerRef()
101+
this.addEffect()
112102
},
113103
addFromQueue() {
114104
const next = {
@@ -226,7 +216,7 @@ export function createAnimations(
226216
}
227217

228218
if (!item || !leave || isDestroy || this.isReducedMotion.value) {
229-
items.addDestroyed()
219+
items.addEffect()
230220
return onAnimationend()
231221
}
232222

@@ -241,7 +231,7 @@ export function createAnimations(
241231
},
242232
})
243233

244-
items.addCleared()
234+
items.addEffect()
245235
},
246236
playClearAll() {
247237
items.entries.value.forEach((e) => window.clearTimeout(e.timeout as number))
@@ -438,7 +428,7 @@ export function createPushProxies({
438428
duplicateCount: queueDupe.duplicateCount + 1,
439429
})
440430

441-
queue.triggerRef() // This is actually not needed...
431+
queue.triggerRef() // This is actually not needed in this context...
442432
}
443433

444434
if (queueDupe || dupe) return
@@ -449,7 +439,7 @@ export function createPushProxies({
449439
if (options.type === NType.PROMISE_RESOLVE || options.type === NType.PROMISE_REJECT) {
450440
if (queue.get(entry.id)) {
451441
queue.update(entry.id, { ...entry, createdAt, timeout: createTimeout })
452-
queue.triggerRef() // ...but we're exposing the queue `useNotifications` so this is needed
442+
queue.triggerRef() // ...but we're exposing the queue via `useNotifications` so consumers may need this
453443
} else {
454444
items.update(entry.id, { ...entry, createdAt, timeout: createTimeout() })
455445
items.triggerRef()

packages/notivue/core/createStoreWatchers.ts

+33-42
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,41 @@ import { watch } from 'vue'
33
import type { NotivueStore } from 'notivue'
44

55
export function createStoreWatchers(store: NotivueStore) {
6-
const unwatchCount = watch(
7-
() => [
8-
store.items.createdCount.value,
9-
store.items.clearedCount.value,
10-
store.items.destroyedCount.value,
11-
],
12-
() => {
13-
store.animations.updatePositions()
14-
},
15-
{ flush: 'post' }
16-
)
6+
return [
7+
watch(
8+
store.items.effectsCount,
9+
() => {
10+
store.animations.updatePositions()
11+
},
12+
{ flush: 'post' }
13+
),
1714

18-
const unwatchPosition = watch(
19-
store.config.position,
20-
() => {
21-
store.animations.updatePositions({ isImmediate: true })
22-
},
23-
{ flush: 'post' }
24-
)
15+
watch(
16+
store.config.position,
17+
() => {
18+
store.animations.updatePositions({ isImmediate: true })
19+
},
20+
{ flush: 'post' }
21+
),
2522

26-
const unwatchRoot = watch(
27-
() => store.items.length === 0 && store.queue.length === 0,
28-
(isReset) => {
29-
if (isReset) {
30-
store.timeouts.reset()
31-
store.elements.setRootAttrs({})
32-
}
33-
},
34-
{ flush: 'post' }
35-
)
23+
watch(
24+
() => store.items.length === 0 && store.queue.length === 0,
25+
(isReset) => {
26+
if (isReset) {
27+
store.timeouts.reset()
28+
store.elements.setRootAttrs({})
29+
}
30+
},
31+
{ flush: 'post' }
32+
),
3633

37-
const unwatchAnimations = watch(
38-
() => store.config.animations.value.enter,
39-
(newEnter, prevEnter) => {
40-
if (newEnter !== prevEnter) {
41-
store.animations.resetTransitionStyles()
34+
watch(
35+
() => store.config.animations.value.enter,
36+
(newEnter, prevEnter) => {
37+
if (newEnter !== prevEnter) {
38+
store.animations.resetTransitionStyles()
39+
}
4240
}
43-
}
44-
)
45-
46-
return () => {
47-
unwatchCount()
48-
unwatchPosition()
49-
unwatchRoot()
50-
unwatchAnimations()
51-
}
41+
),
42+
]
5243
}

packages/notivue/core/types.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ export type StoreItem<T extends Obj = Obj> = DeepRequired<NotificationOptions> &
150150
/** Portion of the store item exposed to slot */
151151
export type NotivueItem<T extends Obj = Obj> = Omit<StoreItem<T>, keyof HiddenInternalItemData>
152152

153-
export type PushParameter<T extends Obj = Obj> = PushOptions<T> | NotificationOptions['message']
153+
export type PushParameter<T extends Obj = Obj> =
154+
| PushOptions<T>
155+
| Exclude<NotificationOptions['message'], undefined> // NonNullable doesn't work?
154156

155157
export type PushStatic = <T extends Obj = Obj>(
156158
options: PushParameter<T>

packages/notivue/core/useStore.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function useStore() {
2525
* - `stopInstance` - Stops the Notivue instance.
2626
* - `isRunning` - Readonly ref to check if the Notivue instance is running.
2727
*
28-
* @docs https://notivuedocs.netlify.app/api/use-notivue-instance
28+
* @docs https://docs.notivue.smastrom.io/api/use-notivue-instance
2929
*/
3030
export function useNotivueInstance(): NotivueInstance {
3131
if (isSSR) {
@@ -44,11 +44,11 @@ export function useNotivueInstance(): NotivueInstance {
4444
*
4545
* @returns
4646
*
47-
* The current [configuration](https://notivuedocs.netlify.app/customization/configuration)
47+
* The current [configuration](https://docs.notivue.smastrom.io/customization/configuration)
4848
* where each property is a [ref](https://vuejs.org/guide/essentials/reactivity-fundamentals.html#ref)
4949
* that allows for reactive updates and side effects watching.
5050
*
51-
* @docs https://notivuedocs.netlify.app/api/use-notivue
51+
* @docs https://docs.notivue.smastrom.io/api/use-notivue
5252
*/
5353
export function useNotivue(): UseNotivueReturn {
5454
if (isSSR) {
@@ -92,7 +92,7 @@ export function usePush() {
9292
* - `entries` - read-only reactive array of all the current displayed notifications
9393
* - `queue` - read-only reactive array of all the notifications waiting to be displayed
9494
*
95-
* @docs https://notivuedocs.netlify.app/api/use-notifications
95+
* @docs https://docs.notivue.smastrom.io/api/use-notifications
9696
*/
9797
export function useNotifications(): NotivueComputedEntries {
9898
if (isSSR) {

packages/notivue/nuxt/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
### Powerful toast notification system for Vue and Nuxt
1010

11-
[Live Demo](https://notivue.smastrom.io) - [Documentation](https://notivuedocs.netlify.app)
11+
[Live Demo](https://notivue.smastrom.io) - [Documentation](https://docs.notivue.smastrom.io)
1212

1313
---
1414

@@ -67,8 +67,8 @@ pnpm add notivue
6767
export default defineNuxtConfig({
6868
modules: ['notivue/nuxt'],
6969
css: [
70-
'notivue/notification.css', // Only needed if using built-in notifications
71-
'notivue/animations.css' // Only needed if using built-in animations
70+
'notivue/notification.css', // Only needed if using built-in <Notification />
71+
'notivue/animations.css' // Only needed if using default animations
7272
],
7373
notivue: {
7474
// Options
@@ -78,7 +78,7 @@ export default defineNuxtConfig({
7878

7979
<blockquote>
8080

81-
:bulb: After installing the module, any function, object and component mentioned in the [documentation](https://notivuedocs.netlify.app) can be auto-imported except for types which must be imported manually if needed.
81+
:bulb: After installing the module, any function, object and component mentioned in the [documentation](https://docs.notivue.smastrom.io) can be auto-imported except for types which must be imported manually if needed.
8282

8383
```ts
8484
import type { NotivueConfig, NotivueItem /*, ... */ } from 'notivue'
@@ -135,7 +135,7 @@ import type { NotivueConfig, NotivueItem /*, ... */ } from 'notivue'
135135
</div>
136136
</Notivue>
137137
138-
<!-- RouterView, etc. -->
138+
<!-- NuxtLayout, NuxtPage, etc. -->
139139
</template>
140140
```
141141

packages/notivue/nuxt/module.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"name": "notivue/nuxt",
33
"configKey": "notivue",
4-
"version": "2.4.0"
4+
"version": "2.4.1"
55
}

packages/notivue/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "notivue",
3-
"version": "2.4.0",
3+
"version": "2.4.1",
44
"private": false,
5-
"description": "Fully-featured toast notification system for Vue and Nuxt",
5+
"description": "Powerful toast notification system for Vue and Nuxt",
66
"keywords": [
77
"vue",
88
"vuejs",

0 commit comments

Comments
 (0)