-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Core - Rename createSlices functions, remove enter animation class on end * Core - Add promise methods aliases, rename createPushSSR to createPushMock * Core - Move store watchers to dedicated file, add push export * Notivue, NotivueKeyboard - Rename imports to match new API * Tests - Edit tests to match new push API * Core - Deprecate `usePush`, remove `notivue` from v0, edit types * Nuxt Module - Add `push` to auto-imported modules * Astro - Add `notivue/astro` module * Demo - Edit demo to match new `push` API * Pkg - Edit README, up monorepo deps * Pkg - Cleanup * improve performance by directly accessing animationAttrs * Core - Improve updatePositions performance * Core - Depreacate `useNotivueConfig` alias, improve intellisense, improve astro module gen readability * Pkg - Edit README * Core - Fix add from queue bug
- Loading branch information
Showing
38 changed files
with
409 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export default defineNuxtRouteMiddleware(() => { | ||
const push = usePush() | ||
import { push } from 'notivue' | ||
|
||
export default defineNuxtRouteMiddleware(() => { | ||
push.info('Welcome to Notivue! Use the controls below to test it out.') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<script setup lang="ts"> | ||
import { onMounted, onBeforeUnmount } from 'vue' | ||
import { DEFAULT_PROPS } from '@/Notivue/constants' | ||
import { NotivueClientOnly } from '@/shared/ClientOnly' | ||
import { push } from '@/core/createPush' | ||
import NotivueImpl from '@/Notivue/NotivueImpl.vue' | ||
import type { NotivueComponentSlot, NotivueProps } from 'notivue' | ||
import type { PushAstroEvent } from './types' | ||
const props = withDefaults(defineProps<NotivueProps>(), DEFAULT_PROPS) | ||
defineSlots<NotivueComponentSlot>() | ||
function onPush(e: CustomEvent<PushAstroEvent>) { | ||
// Create the notification as usual | ||
const notification = push[e.detail.type](e.detail) | ||
// Dispatch the push result | ||
window.dispatchEvent( | ||
new CustomEvent(e.detail.resultEventName, { | ||
detail: notification, | ||
}) | ||
) | ||
} | ||
const onClearAll = () => push.clearAll() | ||
const onDestroyAll = () => push.destroyAll() | ||
// Listen for custom events | ||
const events = [ | ||
['notivue:push', onPush], | ||
['notivue:clear-all', onClearAll], | ||
['notivue:destroy-all', onDestroyAll], | ||
] as [keyof WindowEventMap, EventListener][] | ||
onMounted(() => { | ||
events.forEach(([e, handler]) => window.addEventListener(e, handler)) | ||
}) | ||
onBeforeUnmount(() => { | ||
events.forEach(([e, handler]) => window.removeEventListener(e, handler)) | ||
}) | ||
</script> | ||
|
||
<template> | ||
<NotivueClientOnly> | ||
<NotivueImpl v-bind="props" v-slot="item"> | ||
<slot v-bind="item" /> | ||
</NotivueImpl> | ||
</NotivueClientOnly> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { PushOptions } from 'notivue' | ||
import type { PushAstroEvent, MaybeAstroPushPromiseReturn } from './types' | ||
|
||
let eventId = 0 | ||
|
||
export function pushEvent<T extends Omit<PushAstroEvent, 'resultEventName'>>( | ||
detail: T | ||
): MaybeAstroPushPromiseReturn<T> { | ||
eventId++ | ||
|
||
// Listen for the result of the notification that will be created by the Notivue... | ||
let pushResult = {} as MaybeAstroPushPromiseReturn<T> | ||
const resultEventName = `notivue:id:${eventId}` | ||
|
||
// ...upon receival, save the result and remove the listener | ||
window.addEventListener(resultEventName, saveResult as EventListener, { | ||
once: true, | ||
}) | ||
|
||
function saveResult(e: CustomEvent<MaybeAstroPushPromiseReturn<T>>) { | ||
pushResult = e.detail | ||
} | ||
|
||
// Dispatch the incoming push options to the receiver to create the notification | ||
window.dispatchEvent( | ||
new CustomEvent('notivue:push', { | ||
detail: { | ||
...detail, | ||
type: detail.type, | ||
resultEventName, | ||
}, | ||
}) | ||
) | ||
|
||
return pushResult | ||
} | ||
|
||
export const push = { | ||
success: (options: PushOptions) => pushEvent({ ...options, type: 'success' }), | ||
info: (options: PushOptions) => pushEvent({ ...options, type: 'info' }), | ||
error: (options: PushOptions) => pushEvent({ ...options, type: 'error' }), | ||
warning: (options: PushOptions) => pushEvent({ ...options, type: 'warning' }), | ||
promise: (options: PushOptions) => pushEvent({ ...options, type: 'promise' }), | ||
load: (options: PushOptions) => pushEvent({ ...options, type: 'promise' }), | ||
clearAll() { | ||
window.dispatchEvent(new CustomEvent('notivue:clear-all')) | ||
}, | ||
destroyAll() { | ||
window.dispatchEvent(new CustomEvent('notivue:destroy-all')) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { ClearFunctions, PushPromiseReturn, NotificationType, PushOptions } from 'notivue' | ||
|
||
export type PushAstroEvent = PushOptions & { | ||
type: Exclude<NotificationType, 'promise-resolve' | 'promise-reject'> | ||
resultEventName: string | ||
} | ||
|
||
export type MaybeAstroPushPromiseReturn<T> = T extends PushOptions & { type: 'promise' } | ||
? PushPromiseReturn | ||
: T extends PushOptions | ||
? ClearFunctions | ||
: never | ||
|
||
interface CustomEventMap { | ||
'notivue:push': CustomEvent<PushAstroEvent> | ||
'notivue:clear-all': CustomEvent | ||
'notivue:destroy-all': CustomEvent | ||
} | ||
|
||
declare global { | ||
interface WindowEventMap extends CustomEventMap {} | ||
} |
Oops, something went wrong.