@beeblock/svelar 0.4.0
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/LICENSE +21 -0
- package/README.md +110 -0
- package/dist/actions/index.d.ts +101 -0
- package/dist/actions/index.js +1 -0
- package/dist/api-keys/index.d.ts +58 -0
- package/dist/api-keys/index.js +1 -0
- package/dist/audit/index.d.ts +52 -0
- package/dist/audit/index.js +1 -0
- package/dist/auth/Auth.d.ts +283 -0
- package/dist/auth/Gate.d.ts +166 -0
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.js +80 -0
- package/dist/broadcasting/client.d.ts +195 -0
- package/dist/broadcasting/client.js +1 -0
- package/dist/broadcasting/index.d.ts +318 -0
- package/dist/broadcasting/index.js +20 -0
- package/dist/cache/index.d.ts +77 -0
- package/dist/cache/index.js +1 -0
- package/dist/cli/Cli.d.ts +23 -0
- package/dist/cli/Command.d.ts +36 -0
- package/dist/cli/bin.d.ts +8 -0
- package/dist/cli/bin.js +5856 -0
- package/dist/cli/commands/KeyGenerateCommand.d.ts +16 -0
- package/dist/cli/commands/MakeActionCommand.d.ts +15 -0
- package/dist/cli/commands/MakeBroadcastingCommand.d.ts +29 -0
- package/dist/cli/commands/MakeChannelCommand.d.ts +18 -0
- package/dist/cli/commands/MakeCommandCommand.d.ts +16 -0
- package/dist/cli/commands/MakeConfigCommand.d.ts +13 -0
- package/dist/cli/commands/MakeControllerCommand.d.ts +28 -0
- package/dist/cli/commands/MakeDashboardCommand.d.ts +34 -0
- package/dist/cli/commands/MakeDockerCommand.d.ts +32 -0
- package/dist/cli/commands/MakeEventCommand.d.ts +11 -0
- package/dist/cli/commands/MakeJobCommand.d.ts +11 -0
- package/dist/cli/commands/MakeListenerCommand.d.ts +16 -0
- package/dist/cli/commands/MakeMiddlewareCommand.d.ts +11 -0
- package/dist/cli/commands/MakeMigrationCommand.d.ts +17 -0
- package/dist/cli/commands/MakeModelCommand.d.ts +25 -0
- package/dist/cli/commands/MakeObserverCommand.d.ts +23 -0
- package/dist/cli/commands/MakePluginCommand.d.ts +11 -0
- package/dist/cli/commands/MakeProviderCommand.d.ts +11 -0
- package/dist/cli/commands/MakeRepositoryCommand.d.ts +22 -0
- package/dist/cli/commands/MakeRequestCommand.d.ts +15 -0
- package/dist/cli/commands/MakeResourceCommand.d.ts +30 -0
- package/dist/cli/commands/MakeRouteCommand.d.ts +42 -0
- package/dist/cli/commands/MakeSchemaCommand.d.ts +20 -0
- package/dist/cli/commands/MakeSeederCommand.d.ts +11 -0
- package/dist/cli/commands/MakeServiceCommand.d.ts +28 -0
- package/dist/cli/commands/MakeTaskCommand.d.ts +12 -0
- package/dist/cli/commands/MigrateCommand.d.ts +26 -0
- package/dist/cli/commands/NewCommand.d.ts +21 -0
- package/dist/cli/commands/NewCommandTemplates.d.ts +123 -0
- package/dist/cli/commands/PluginInstallCommand.d.ts +16 -0
- package/dist/cli/commands/PluginListCommand.d.ts +11 -0
- package/dist/cli/commands/PluginPublishCommand.d.ts +22 -0
- package/dist/cli/commands/QueueFailedCommand.d.ts +9 -0
- package/dist/cli/commands/QueueFlushCommand.d.ts +9 -0
- package/dist/cli/commands/QueueRetryCommand.d.ts +16 -0
- package/dist/cli/commands/QueueWorkCommand.d.ts +25 -0
- package/dist/cli/commands/RoutesListCommand.d.ts +30 -0
- package/dist/cli/commands/ScheduleRunCommand.d.ts +15 -0
- package/dist/cli/commands/SeedCommand.d.ts +14 -0
- package/dist/cli/commands/TinkerCommand.d.ts +10 -0
- package/dist/cli/index.d.ts +36 -0
- package/dist/cli/index.js +1973 -0
- package/dist/cli/ts-resolve-hook.mjs +74 -0
- package/dist/cli/ts-resolver.mjs +8 -0
- package/dist/config/Config.d.ts +65 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +1 -0
- package/dist/container/Application.d.ts +33 -0
- package/dist/container/Container.d.ts +70 -0
- package/dist/container/ServiceProvider.d.ts +21 -0
- package/dist/container/index.d.ts +3 -0
- package/dist/container/index.js +1 -0
- package/dist/dashboard/index.d.ts +123 -0
- package/dist/dashboard/index.js +5 -0
- package/dist/database/Connection.d.ts +80 -0
- package/dist/database/Migration.d.ts +76 -0
- package/dist/database/SchemaBuilder.d.ts +91 -0
- package/dist/database/Seeder.d.ts +9 -0
- package/dist/database/index.d.ts +4 -0
- package/dist/database/index.js +4 -0
- package/dist/email-templates/index.d.ts +51 -0
- package/dist/email-templates/index.js +57 -0
- package/dist/errors/Handler.d.ts +100 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +5 -0
- package/dist/events/EventServiceProvider.d.ts +82 -0
- package/dist/events/Listener.d.ts +28 -0
- package/dist/events/index.d.ts +80 -0
- package/dist/events/index.js +1 -0
- package/dist/excel/index.d.ts +154 -0
- package/dist/excel/index.js +1 -0
- package/dist/feature-flags/index.d.ts +158 -0
- package/dist/feature-flags/index.js +59 -0
- package/dist/forms/index.d.ts +81 -0
- package/dist/forms/index.js +1 -0
- package/dist/hashing/Hash.d.ts +51 -0
- package/dist/hashing/index.d.ts +1 -0
- package/dist/hashing/index.js +1 -0
- package/dist/hooks/index.d.ts +135 -0
- package/dist/hooks/index.js +5 -0
- package/dist/http/index.d.ts +201 -0
- package/dist/http/index.js +2 -0
- package/dist/i18n/index.d.ts +81 -0
- package/dist/i18n/index.js +1 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +127 -0
- package/dist/logging/LogViewer.d.ts +95 -0
- package/dist/logging/LogViewer.js +1 -0
- package/dist/logging/index.d.ts +83 -0
- package/dist/logging/index.js +3 -0
- package/dist/mail/index.d.ts +149 -0
- package/dist/mail/index.js +1 -0
- package/dist/middleware/Middleware.d.ts +208 -0
- package/dist/middleware/index.d.ts +1 -0
- package/dist/middleware/index.js +1 -0
- package/dist/notifications/index.d.ts +85 -0
- package/dist/notifications/index.js +2 -0
- package/dist/orm/Model.d.ts +123 -0
- package/dist/orm/Observer.d.ts +34 -0
- package/dist/orm/QueryBuilder.d.ts +119 -0
- package/dist/orm/Relationship.d.ts +58 -0
- package/dist/orm/index.d.ts +4 -0
- package/dist/orm/index.js +1 -0
- package/dist/pagination/index.d.ts +8 -0
- package/dist/pagination/index.js +0 -0
- package/dist/pdf/GeneratePdfJob.d.ts +99 -0
- package/dist/pdf/GeneratePdfJob.js +41 -0
- package/dist/pdf/index.d.ts +328 -0
- package/dist/pdf/index.js +41 -0
- package/dist/permissions/index.d.ts +161 -0
- package/dist/permissions/index.js +60 -0
- package/dist/plugins/BootstrapPlugins.d.ts +11 -0
- package/dist/plugins/PluginInstaller.d.ts +30 -0
- package/dist/plugins/PluginInstaller.js +1 -0
- package/dist/plugins/PluginPublisher.d.ts +32 -0
- package/dist/plugins/PluginPublisher.js +1 -0
- package/dist/plugins/PluginRegistry.d.ts +55 -0
- package/dist/plugins/PluginRegistry.js +1 -0
- package/dist/plugins/index.d.ts +206 -0
- package/dist/plugins/index.js +1 -0
- package/dist/queue/JobMonitor.d.ts +109 -0
- package/dist/queue/JobMonitor.js +5 -0
- package/dist/queue/index.d.ts +279 -0
- package/dist/queue/index.js +5 -0
- package/dist/repositories/index.d.ts +147 -0
- package/dist/repositories/index.js +1 -0
- package/dist/routing/Controller.d.ts +115 -0
- package/dist/routing/FormRequest.d.ts +94 -0
- package/dist/routing/Resource.d.ts +213 -0
- package/dist/routing/Response.d.ts +138 -0
- package/dist/routing/index.d.ts +4 -0
- package/dist/routing/index.js +5 -0
- package/dist/scheduler/ScheduleMonitor.d.ts +141 -0
- package/dist/scheduler/ScheduleMonitor.js +1 -0
- package/dist/scheduler/SchedulerLock.d.ts +33 -0
- package/dist/scheduler/index.d.ts +208 -0
- package/dist/scheduler/index.js +34 -0
- package/dist/services/index.d.ts +79 -0
- package/dist/services/index.js +1 -0
- package/dist/session/Session.d.ts +166 -0
- package/dist/session/index.d.ts +1 -0
- package/dist/session/index.js +16 -0
- package/dist/storage/index.d.ts +154 -0
- package/dist/storage/index.js +1 -0
- package/dist/support/Pipeline.d.ts +65 -0
- package/dist/support/date.d.ts +136 -0
- package/dist/support/date.js +1 -0
- package/dist/support/index.d.ts +8 -0
- package/dist/support/index.js +1 -0
- package/dist/support/singleton.d.ts +10 -0
- package/dist/support/uuid.d.ts +40 -0
- package/dist/teams/index.d.ts +91 -0
- package/dist/teams/index.js +78 -0
- package/dist/uploads/index.d.ts +63 -0
- package/dist/uploads/index.js +2 -0
- package/dist/validation/index.d.ts +46 -0
- package/dist/validation/index.js +1 -0
- package/dist/webhooks/index.d.ts +66 -0
- package/dist/webhooks/index.js +1 -0
- package/package.json +338 -0
- package/src/i18n/LanguageSwitcher.svelte +47 -0
- package/src/i18n/index.ts +113 -0
- package/src/ui/Alert.svelte +22 -0
- package/src/ui/Avatar.svelte +18 -0
- package/src/ui/AvatarFallback.svelte +18 -0
- package/src/ui/AvatarImage.svelte +12 -0
- package/src/ui/Badge.svelte +27 -0
- package/src/ui/Button.svelte +51 -0
- package/src/ui/Card.svelte +15 -0
- package/src/ui/CardContent.svelte +15 -0
- package/src/ui/CardDescription.svelte +15 -0
- package/src/ui/CardFooter.svelte +15 -0
- package/src/ui/CardHeader.svelte +15 -0
- package/src/ui/CardTitle.svelte +15 -0
- package/src/ui/Icon.svelte +81 -0
- package/src/ui/Input.svelte +40 -0
- package/src/ui/Label.svelte +20 -0
- package/src/ui/Separator.svelte +10 -0
- package/src/ui/Tabs.svelte +23 -0
- package/src/ui/TabsContent.svelte +27 -0
- package/src/ui/TabsList.svelte +19 -0
- package/src/ui/TabsTrigger.svelte +28 -0
- package/src/ui/Toaster.svelte +279 -0
- package/src/ui/index.ts +31 -0
- package/src/ui/toast.ts +212 -0
package/src/ui/toast.ts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Svelar Toast Store & API
|
|
3
|
+
*
|
|
4
|
+
* Reactive toast notification system using a callback-based store
|
|
5
|
+
* that works across package boundaries (no Svelte compiler needed).
|
|
6
|
+
*
|
|
7
|
+
* Import { toast } anywhere to show notifications.
|
|
8
|
+
* Import { Toaster } in your layout to render them.
|
|
9
|
+
*
|
|
10
|
+
* @module svelar/ui
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { toast } from 'svelar/ui';
|
|
15
|
+
*
|
|
16
|
+
* toast('Hello');
|
|
17
|
+
* toast.success('Saved!');
|
|
18
|
+
* toast.error('Failed', { description: 'Network error' });
|
|
19
|
+
* toast.warning('Careful', { duration: 8000 });
|
|
20
|
+
* toast.info('Tip', { action: { label: 'Undo', onClick: () => undo() } });
|
|
21
|
+
* toast.dismiss(id);
|
|
22
|
+
* toast.dismissAll();
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
export type ToastVariant = 'default' | 'success' | 'error' | 'warning' | 'info';
|
|
27
|
+
|
|
28
|
+
export type ToastState = 'entering' | 'visible' | 'exiting';
|
|
29
|
+
|
|
30
|
+
export interface ToastItem {
|
|
31
|
+
id: string;
|
|
32
|
+
variant: ToastVariant;
|
|
33
|
+
title: string;
|
|
34
|
+
description?: string;
|
|
35
|
+
duration: number;
|
|
36
|
+
dismissible: boolean;
|
|
37
|
+
action?: { label: string; onClick: () => void };
|
|
38
|
+
createdAt: number;
|
|
39
|
+
state: ToastState;
|
|
40
|
+
pausedAt?: number;
|
|
41
|
+
remaining: number;
|
|
42
|
+
timeoutId?: ReturnType<typeof setTimeout>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface ToastOptions {
|
|
46
|
+
description?: string;
|
|
47
|
+
/** Auto-dismiss in ms. 0 = persistent. Default: 5000 (8000 for errors) */
|
|
48
|
+
duration?: number;
|
|
49
|
+
/** Show close button. Default: true */
|
|
50
|
+
dismissible?: boolean;
|
|
51
|
+
/** Action button */
|
|
52
|
+
action?: { label: string; onClick: () => void };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ── Callback-based Store ────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
let _toasts: ToastItem[] = [];
|
|
58
|
+
let _counter = 0;
|
|
59
|
+
let _listeners: Set<() => void> = new Set();
|
|
60
|
+
|
|
61
|
+
const ENTER_DURATION = 300;
|
|
62
|
+
const EXIT_DURATION = 200;
|
|
63
|
+
|
|
64
|
+
function notify() {
|
|
65
|
+
for (const listener of _listeners) {
|
|
66
|
+
listener();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Subscribe to toast state changes. Returns an unsubscribe function.
|
|
72
|
+
*/
|
|
73
|
+
export function subscribe(listener: () => void): () => void {
|
|
74
|
+
_listeners.add(listener);
|
|
75
|
+
return () => _listeners.delete(listener);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function getToasts(): ToastItem[] {
|
|
79
|
+
return _toasts;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function scheduleAutoDismiss(item: ToastItem) {
|
|
83
|
+
if (item.duration <= 0) return;
|
|
84
|
+
|
|
85
|
+
item.timeoutId = setTimeout(() => {
|
|
86
|
+
dismiss(item.id);
|
|
87
|
+
}, item.remaining);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function addToast(variant: ToastVariant, title: string, options: ToastOptions = {}): string {
|
|
91
|
+
const id = `toast-${++_counter}-${Date.now()}`;
|
|
92
|
+
const duration = options.duration ?? (variant === 'error' ? 8000 : 5000);
|
|
93
|
+
|
|
94
|
+
const item: ToastItem = {
|
|
95
|
+
id,
|
|
96
|
+
variant,
|
|
97
|
+
title,
|
|
98
|
+
description: options.description,
|
|
99
|
+
duration,
|
|
100
|
+
dismissible: options.dismissible ?? true,
|
|
101
|
+
action: options.action,
|
|
102
|
+
createdAt: Date.now(),
|
|
103
|
+
state: 'entering',
|
|
104
|
+
remaining: duration,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
_toasts = [..._toasts, item];
|
|
108
|
+
notify();
|
|
109
|
+
|
|
110
|
+
// Transition to visible after enter animation
|
|
111
|
+
setTimeout(() => {
|
|
112
|
+
_toasts = _toasts.map((t) => (t.id === id ? { ...t, state: 'visible' as ToastState } : t));
|
|
113
|
+
notify();
|
|
114
|
+
}, ENTER_DURATION);
|
|
115
|
+
|
|
116
|
+
// Start auto-dismiss timer
|
|
117
|
+
scheduleAutoDismiss(item);
|
|
118
|
+
|
|
119
|
+
return id;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function dismiss(id: string) {
|
|
123
|
+
const item = _toasts.find((t) => t.id === id);
|
|
124
|
+
if (!item || item.state === 'exiting') return;
|
|
125
|
+
|
|
126
|
+
if (item.timeoutId) clearTimeout(item.timeoutId);
|
|
127
|
+
|
|
128
|
+
_toasts = _toasts.map((t) => (t.id === id ? { ...t, state: 'exiting' as ToastState } : t));
|
|
129
|
+
notify();
|
|
130
|
+
|
|
131
|
+
setTimeout(() => {
|
|
132
|
+
_toasts = _toasts.filter((t) => t.id !== id);
|
|
133
|
+
notify();
|
|
134
|
+
}, EXIT_DURATION);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function dismissAll() {
|
|
138
|
+
_toasts = _toasts.map((t) => {
|
|
139
|
+
if (t.timeoutId) clearTimeout(t.timeoutId);
|
|
140
|
+
return { ...t, state: 'exiting' as ToastState };
|
|
141
|
+
});
|
|
142
|
+
notify();
|
|
143
|
+
|
|
144
|
+
setTimeout(() => {
|
|
145
|
+
_toasts = [];
|
|
146
|
+
notify();
|
|
147
|
+
}, EXIT_DURATION);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function pauseToast(id: string) {
|
|
151
|
+
_toasts = _toasts.map((t) => {
|
|
152
|
+
if (t.id !== id || t.duration <= 0) return t;
|
|
153
|
+
if (t.timeoutId) clearTimeout(t.timeoutId);
|
|
154
|
+
const elapsed = Date.now() - t.createdAt - (t.duration - t.remaining);
|
|
155
|
+
return { ...t, pausedAt: Date.now(), remaining: Math.max(t.remaining - elapsed, 1000), timeoutId: undefined };
|
|
156
|
+
});
|
|
157
|
+
notify();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function resumeToast(id: string) {
|
|
161
|
+
const item = _toasts.find((t) => t.id === id);
|
|
162
|
+
if (!item || !item.pausedAt || item.duration <= 0) return;
|
|
163
|
+
|
|
164
|
+
_toasts = _toasts.map((t) => {
|
|
165
|
+
if (t.id !== id) return t;
|
|
166
|
+
return { ...t, pausedAt: undefined };
|
|
167
|
+
});
|
|
168
|
+
notify();
|
|
169
|
+
|
|
170
|
+
scheduleAutoDismiss(item);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// ── Public API ────────────────────────────────────────────
|
|
174
|
+
|
|
175
|
+
function toastFn(title: string, options?: ToastOptions): string {
|
|
176
|
+
return addToast('default', title, options);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
toastFn.success = (title: string, options?: ToastOptions) => addToast('success', title, options);
|
|
180
|
+
toastFn.error = (title: string, options?: ToastOptions) => addToast('error', title, options);
|
|
181
|
+
toastFn.warning = (title: string, options?: ToastOptions) => addToast('warning', title, options);
|
|
182
|
+
toastFn.info = (title: string, options?: ToastOptions) => addToast('info', title, options);
|
|
183
|
+
toastFn.dismiss = dismiss;
|
|
184
|
+
toastFn.dismissAll = dismissAll;
|
|
185
|
+
|
|
186
|
+
toastFn.promise = <T>(
|
|
187
|
+
promise: Promise<T>,
|
|
188
|
+
messages: {
|
|
189
|
+
loading: string;
|
|
190
|
+
success: string | ((data: T) => string);
|
|
191
|
+
error: string | ((err: any) => string);
|
|
192
|
+
},
|
|
193
|
+
options?: ToastOptions,
|
|
194
|
+
): Promise<T> => {
|
|
195
|
+
const id = addToast('info', messages.loading, { ...options, duration: 0 });
|
|
196
|
+
|
|
197
|
+
promise
|
|
198
|
+
.then((data) => {
|
|
199
|
+
dismiss(id);
|
|
200
|
+
const msg = typeof messages.success === 'function' ? messages.success(data) : messages.success;
|
|
201
|
+
addToast('success', msg, options);
|
|
202
|
+
})
|
|
203
|
+
.catch((err) => {
|
|
204
|
+
dismiss(id);
|
|
205
|
+
const msg = typeof messages.error === 'function' ? messages.error(err) : messages.error;
|
|
206
|
+
addToast('error', msg, options);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
return promise;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
export const toast = toastFn;
|