@svadmin/core 0.19.2 → 0.19.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svadmin/core",
3
- "version": "0.19.2",
3
+ "version": "0.19.3",
4
4
  "author": "zuohuadong",
5
5
  "repository": {
6
6
  "type": "git",
@@ -61,7 +61,5 @@
61
61
  "sideEffects": false,
62
62
  "type": "module",
63
63
  "types": "src/index.ts",
64
- "dependencies": {
65
- "sonner-svelte": "^0.3.3"
66
- }
64
+ "dependencies": {}
67
65
  }
package/src/index.ts CHANGED
@@ -29,7 +29,7 @@ export { matchRoute, navigate, currentPath, setActiveRouterProvider } from './ro
29
29
  export { readURLState, writeURLState } from './url-sync';
30
30
  export { setAccessControlProvider, getAccessControlProvider, getAccessControlOptions, canAccessAsync } from './permissions';
31
31
  export { useLive, useSubscription, usePublish } from './live.svelte';
32
- export { toast } from './toast.svelte';
32
+ export { toast, getToastQueue, consumeToastQueue, getPromiseQueue, consumePromiseQueue } from './toast.svelte';
33
33
  export { notify, closeNotification, setNotificationProvider, getNotificationProvider } from './notification.svelte';
34
34
  export { t, setLocale, getLocale, getAvailableLocales, addTranslations, useTranslation } from './i18n.svelte';
35
35
  export { audit, setAuditHandler, setAuditLogProvider, getAuditLogProvider } from './audit';
@@ -1,40 +1,40 @@
1
- // Toast notification system — wraps sonner-svelte for consistent API
2
- // Maintains backward-compatible `toast.success()` / `toast.error()` etc.
3
-
4
- import { toast as sonner } from 'sonner-svelte';
5
-
6
1
  export type ToastType = 'success' | 'error' | 'info' | 'warning' | 'undoable';
7
2
 
8
- export interface Toast {
3
+ export interface ToastItem {
9
4
  id: number;
10
5
  type: ToastType;
11
6
  message: string;
12
- duration: number;
7
+ duration?: number;
13
8
  onUndo?: () => void;
14
9
  onTimeout?: () => void;
15
10
  }
16
11
 
17
- // Legacy compatibility — kept for existing consumers
18
12
  let nextId = 0;
19
- let toasts = $state<Toast[]>([]);
20
13
 
21
- export function getToasts(): Toast[] {
22
- return toasts;
23
- }
24
-
25
- export function addToast(type: ToastType, message: string, duration = 3000, options?: { onUndo?: () => void, onTimeout?: () => void }): void {
26
- // Use sonner-svelte for regular toasts
14
+ // Queue for simple toasts (consumed by UI Toast bridge)
15
+ let queue = $state<ToastItem[]>([]);
16
+ export function getToastQueue() { return queue; }
17
+ export function consumeToastQueue() { queue = []; }
18
+
19
+ // Promise Queue
20
+ let promiseQueue = $state<{ id: number; promise: Promise<any>; opts: { loading: string; success: string; error: string } }[]>([]);
21
+ export function getPromiseQueue() { return promiseQueue; }
22
+ export function consumePromiseQueue() { promiseQueue = []; }
23
+
24
+ // Legacy compatibility — kept for existing consumers (Undoable)
25
+ let toasts = $state<ToastItem[]>([]);
26
+ export function getToasts(): ToastItem[] { return toasts; }
27
+
28
+ export function addToast(
29
+ type: ToastType,
30
+ message: string,
31
+ duration = 3000,
32
+ options?: { onUndo?: () => void, onTimeout?: () => void }
33
+ ): void {
27
34
  if (type !== 'undoable') {
28
- switch (type) {
29
- case 'success': sonner.success(message, { duration }); break;
30
- case 'error': sonner.error(message, { duration }); break;
31
- case 'warning': sonner.warning(message, { duration }); break;
32
- case 'info': sonner.info(message, { duration }); break;
33
- }
35
+ queue.push({ id: nextId++, type, message, duration });
34
36
  return;
35
37
  }
36
-
37
- // Undoable toasts still use custom system
38
38
  const id = nextId++;
39
39
  toasts = [...toasts, { id, type, message, duration, ...options }];
40
40
  }
@@ -52,6 +52,8 @@ export const toast = {
52
52
  undoable: (msg: string, duration: number, onUndo: () => void, onTimeout: () => void) =>
53
53
  addToast('undoable', msg, duration, { onUndo, onTimeout }),
54
54
  /** Promise toast — shows loading → success/error automatically */
55
- promise: <T>(promise: Promise<T>, opts: { loading: string; success: string; error: string }) =>
56
- sonner.promise(promise, opts),
55
+ promise: <T>(promise: Promise<T>, opts: { loading: string; success: string; error: string }) => {
56
+ promiseQueue.push({ id: nextId++, promise, opts });
57
+ return promise;
58
+ },
57
59
  };