@friendofsvelte/django-kit
Advanced tools
Comparing version 0.0.1-dev.105 to 0.0.1-dev.106
import { redirect } from "@sveltejs/kit"; | ||
/* | ||
Set a flash message in the cookies; | ||
*/ | ||
export const put_flash = (cookies, messages) => { | ||
@@ -10,2 +13,5 @@ // set max age 1 second | ||
}; | ||
/* | ||
Set a flash message in the cookies and redirect to a new location | ||
*/ | ||
export const flash_redirect = (cookies, message, status, location) => { | ||
@@ -12,0 +18,0 @@ put_flash(cookies, { ...message, path: location.toString() }); |
import Flash from "./components/Flash.svelte"; | ||
export { via_route_name, via_route } from './actions.js'; | ||
export { django_fetch_handle } from './fetch_hook.js'; | ||
export { add_toast } from './notifier.svelte.js'; | ||
export { add_toast, notifier } from './notifier.svelte.js'; | ||
export { put_flash, flash_redirect } from './flash_message.js'; | ||
export { Flash }; |
import Flash from "./components/Flash.svelte"; | ||
export { via_route_name, via_route } from './actions.js'; | ||
export { django_fetch_handle } from './fetch_hook.js'; | ||
export { add_toast } from './notifier.svelte.js'; | ||
export { add_toast, notifier } from './notifier.svelte.js'; | ||
export { put_flash, flash_redirect } from './flash_message.js'; | ||
export { Flash }; |
import type { MessageOut, ToastNotification } from "./types.js"; | ||
export declare let error_triggered: boolean; | ||
export declare const toasts: ToastNotification[]; | ||
export declare let notifier: { | ||
toasts: ToastNotification[]; | ||
error_: boolean; | ||
}; | ||
export declare function add_toast(message: MessageOut, auto_dismiss_duration?: number): void; | ||
export declare function dismiss_toast(toastId: string): void; | ||
export declare function dismiss_all_toasts(): void; | ||
export declare function trigger_error(): void; |
@@ -1,17 +0,30 @@ | ||
const AUTO_DISMISS_DURATION = 7200; | ||
export let error_triggered = $state(false); | ||
export const toasts = $state([]); | ||
const AUTO_DISMISS_DURATION = 7777; | ||
/* | ||
Notifier is a global store that manages toast notifications | ||
- toasts: a list of toast notifications | ||
- error_: a flag to indicate if any error has occurred; implementation is up to the developer | ||
*/ | ||
export let notifier = $state({ | ||
toasts: [], | ||
error_: false, | ||
}); | ||
/* | ||
Add a toast to the notifier | ||
*/ | ||
export function add_toast(message, auto_dismiss_duration = AUTO_DISMISS_DURATION) { | ||
const toast = { ...message, auto_dismiss_duration, id: crypto.randomUUID(), }; | ||
toasts.push(toast); | ||
notifier.toasts.push(toast); | ||
} | ||
/* | ||
Dismiss a toast, given its id | ||
*/ | ||
export function dismiss_toast(toastId) { | ||
const index = toasts.findIndex((toast) => toast && toast.id === toastId); | ||
toasts.splice(index, 1); | ||
const index = notifier.toasts.findIndex((toast) => toast && toast.id === toastId); | ||
notifier.toasts.splice(index, 1); | ||
} | ||
/* | ||
Dismiss all toasts | ||
*/ | ||
export function dismiss_all_toasts() { | ||
toasts.splice(0, toasts.length); | ||
notifier.toasts.splice(0, notifier.toasts.length); | ||
} | ||
export function trigger_error() { | ||
// error_triggered = true; | ||
} |
{ | ||
"name": "@friendofsvelte/django-kit", | ||
"version": "0.0.1-dev.105", | ||
"version": "0.0.1-dev.106", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "dev": "vite dev", |
@@ -18,2 +18,7 @@ # Django Kit - For integrating SvelteKit with Django | ||
### Features | ||
- Use Django's forms and validation with SvelteKit. | ||
- Flash messages are automatically shown in SvelteKit. | ||
## Installation | ||
@@ -20,0 +25,0 @@ |
Sorry, the diff of this file is not supported yet
22296
434
97