@ailuracode/alpine-toast 0.1.1 → 2.0.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/README.md CHANGED
@@ -1,26 +1,22 @@
1
1
  # @ailuracode/alpine-toast
2
2
 
3
- Headless in-app toast queue for Alpine.js via the `$toast` magic.
4
-
5
- **CSS-framework agnostic** — no markup, no styles. Only `default`, `bottom-right`, and `promise` are built into the API; you declare variants and positions your UI needs.
6
-
7
- **[Full documentation →](../../docs/toast.md)**
3
+ Headless in-app toast queue for Alpine.js. Registers the `$toast` magic and an internal reactive store for UI integrators.
8
4
 
9
5
  ## Install
10
6
 
11
7
  ```bash
12
- npm install @ailuracode/alpine-toast alpinejs
8
+ pnpm add @ailuracode/alpine-toast @ailuracode/alpine-core alpinejs
13
9
  ```
14
10
 
15
- ## Quick example
11
+ ## Quick start
16
12
 
17
13
  ```js
18
14
  import Alpine from "alpinejs";
19
- import toast, { toastPositions, toastVariants } from "@ailuracode/alpine-toast";
15
+ import toast, { toastOptions, toastPositions, toastVariants } from "@ailuracode/alpine-toast";
20
16
 
21
17
  Alpine.plugin(
22
- toast({
23
- variants: toastVariants(["success", "error", "loading"] as const),
18
+ toastOptions({
19
+ variants: toastVariants(["success", "info", "warning", "error", "loading"] as const),
24
20
  positions: toastPositions(["top-center", "bottom-right"] as const),
25
21
  defaultPosition: "bottom-right",
26
22
  promise: {
@@ -33,34 +29,295 @@ Alpine.plugin(
33
29
  Alpine.start();
34
30
  ```
35
31
 
32
+ `toastOptions()`, `toastVariants()`, and `toastPositions()` preserve literal types for strongly typed payloads and `$toast.<variant>()` shortcuts.
33
+
34
+ ## CSS-framework agnostic
35
+
36
+ This plugin ships **no HTML, no CSS, and no design tokens**. Variant and position names are **not hardcoded** — you declare the sets your UI needs. The only built-in concepts are:
37
+
38
+ - **`default`** — `$toast('Message')` or `{ variant: 'default' }`
39
+ - **`bottom-right`** — default `position` when omitted
40
+ - **`promise`** — `$toast.promise(factoryOrPromise, messages?)`
41
+
42
+ Map `toast.variant` and `toast.position` to layout/CSS in your own renderer (e.g. `data-position`, Tailwind classes, coordinates).
43
+
44
+ ## Magic API
45
+
46
+ ```js
47
+ $toast("Hello")
48
+ $toast({ title: "Saved", variant: "success", position: "top-center" })
49
+ $toast.success("Saved") // only when "success" is in `variants`
50
+ $toast.dismiss(id)
51
+ $toast.dismissAt("top-center")
52
+ $toast.dismissAll()
53
+ $toast.fromPayload({ title: "Done", variant: "success" })
54
+ await $toast.promise(() => save(), {
55
+ loading: "Saving...",
56
+ success: "Saved",
57
+ error: "Could not save",
58
+ })
59
+ ```
60
+
61
+ | Method | Description |
62
+ |--------|-------------|
63
+ | `$toast(title, options?)` | Push a `default` toast. Returns the toast id. |
64
+ | `$toast(payload)` | Push with a full payload object. |
65
+ | `$toast.<variant>(title, options?)` | One shortcut per entry in `variants`. |
66
+ | `$toast.dismiss(id)` | Close one toast by id (returned from `$toast()`). |
67
+ | `$toast.update(id, patch)` | Patch the same toast in place (variant, title, content, action, …). |
68
+ | `$toast.dismissAt(position)` | Close every toast in one position stack. |
69
+ | `$toast.dismissAll()` | Close every toast in every stack. |
70
+ | `$toast.pushUnique(key, payload?)` | Dismiss active toasts with the same `key`, then push. |
71
+ | `$toast.fromPayload(payload)` | Push from a plain payload (events, session flash, etc.). |
72
+ | `$toast.promise(factoryOrPromise, messages?)` | `loading` → `success` / `error` on the same toast. |
73
+
74
+ ### Payload options
75
+
76
+ | Field | Type | Default |
77
+ |-------|------|---------|
78
+ | `content` | `TContent \| null` | `null` |
79
+ | `title` | `string \| null` | `null` |
80
+ | `description` | `string \| null` | `null` |
81
+ | `variant` | `default \| …your variants` | `default` |
82
+ | `position` | `bottom-right \| …your positions` | `bottom-right` (or `defaultPosition`) |
83
+ | `duration` | `number` (ms) | `4000` (`false` or `0` = no auto-dismiss; stored as `false`) |
84
+ | `action` | `{ label, onClick? }` | `null` |
85
+ | `key` | `string \| null` | `null` — use with `pushUnique` for single-slot toasts |
86
+
87
+ `title` / `description` are optional string shorthands. Use `content` for any shape your renderer understands (objects, arrays, HTML snippets, etc.). The plugin stores it as-is — rendering is up to your UI.
88
+
89
+ ```ts
90
+ type AppToastContent = { user: { name: string; avatar: string } } | { html: string };
91
+
92
+ type Item = ToastItem<typeof variants, typeof positions, AppToastContent>;
93
+
94
+ $toast({
95
+ content: { user: { name: "Ada", avatar: "/ada.png" } },
96
+ variant: "success",
97
+ });
98
+ ```
99
+
100
+ ```html
101
+ <template x-for="toast in $store.toast.itemsAt(position)" :key="toast.id">
102
+ <div x-show="toast.content?.user">
103
+ <img :src="toast.content.user.avatar" alt="" />
104
+ <span x-text="toast.content.user.name"></span>
105
+ </div>
106
+ <p x-show="toast.title" x-text="toast.title"></p>
107
+ </template>
108
+ ```
109
+
110
+ For `$toast.promise`, optional `loadingContent`, `successContent`, and `errorContent` update the same toast item.
111
+
112
+ ## Custom variants
113
+
114
+ ```ts
115
+ import toast, { toastOptions, toastVariants, type ToastMagic } from "@ailuracode/alpine-toast";
116
+
117
+ const variants = toastVariants(["queued", "published", "failed"] as const);
118
+
119
+ Alpine.plugin(toast({ variants }));
120
+
121
+ type AppToast = ToastMagic<typeof variants>;
122
+ // AppToast has .queued(), .published(), .failed()
123
+ ```
124
+
125
+ Without `variants`, only `$toast()`, `$toast.promise()`, `$toast.dismiss()`, and `$toast.fromPayload()` are available.
126
+
127
+ ## Custom positions
128
+
129
+ Each declared position gets its **own stack**. `maxToasts` and `maxVisible` apply **per position**, not globally.
130
+
131
+ ```ts
132
+ import toast, { toastPositions, type ToastPosition } from "@ailuracode/alpine-toast";
133
+
134
+ const positions = toastPositions(["top-center", "bottom-right"] as const);
135
+
136
+ Alpine.plugin(
137
+ toast({
138
+ positions,
139
+ defaultPosition: "bottom-right",
140
+ })
141
+ );
142
+
143
+ type AppPosition = ToastPosition<typeof positions>;
144
+ // "bottom-right" | "top-center"
145
+ ```
146
+
147
+ The plugin stores the position id on each toast. Render one stack per position in your UI:
148
+
149
+ ```html
150
+ <template x-for="position in $store.toast.stackPositions" :key="position">
151
+ <div
152
+ x-bind:data-position="position"
153
+ x-bind:class="{
154
+ 'fixed top-4 left-1/2 -translate-x-1/2': position === 'top-center',
155
+ 'fixed bottom-4 right-4': position === 'bottom-right',
156
+ }"
157
+ >
158
+ <template x-for="(toast, index) in $store.toast.itemsAt(position)" :key="toast.id">
159
+ <div x-show="!toast.removed && $store.toast.isVisibleAt(position, index)">
160
+ <p x-text="toast.title"></p>
161
+ </div>
162
+ </template>
163
+ </div>
164
+ </template>
165
+ ```
166
+
167
+ | Store API | Description |
168
+ |-----------|-------------|
169
+ | `stackPositions` | All stack keys (`defaultPosition` + `positions`) |
170
+ | `itemsAt(position)` | Toasts in that stack, newest first (includes exiting `removed` items) |
171
+ | `timedItemsAt(position)` | Auto-dismiss stack — same order, includes exiting items |
172
+ | `persistentItemsAt(position)` | Persistent stack (`duration: false`) — includes exiting items |
173
+ | `activeTimedItemsAt(position)` | Timed stack without `removed` items — preferred for simple `x-for` |
174
+ | `activePersistentItemsAt(position)` | Persistent stack without `removed` items |
175
+ | `isVisibleAt(position, index)` | Timed stack only — peek/limit visibility (`maxVisible`) |
176
+ | `pushUnique(key, payload?)` | Same as `$toast.pushUnique` |
177
+ | `destroy()` | Clear timers — call when tearing down the plugin |
178
+ | `dismiss(id)` | Close one toast (same as `$toast.dismiss`) |
179
+ | `dismissAt(position)` | Close one entire position (timed + persistent) |
180
+ | `dismissAll()` | Close all stacks |
181
+
182
+ ## Promise flow
183
+
184
+ Configure default promise variants in plugin options, or override per call:
185
+
186
+ ```js
187
+ Alpine.plugin(
188
+ toast({
189
+ variants: toastVariants(["loading", "success", "error"] as const),
190
+ promise: {
191
+ loading: "Loading...",
192
+ error: "Something went wrong",
193
+ loadingVariant: "loading",
194
+ successVariant: "success",
195
+ errorVariant: "error",
196
+ duration: 4000,
197
+ },
198
+ })
199
+ );
200
+ ```
201
+
202
+ ```js
203
+ await $toast.promise(() => save(), {
204
+ loading: "Saving...",
205
+ success: (data) => `Saved ${data.id}`,
206
+ error: "Could not save",
207
+ });
208
+ ```
209
+
210
+ If a named variant is missing from `variants`, promise states fall back to `default`.
211
+
212
+ On failure, the toast updates to the error state and the returned promise **rejects** with the original error so callers can still use `try/catch` or `.catch()`.
213
+
214
+ The **loading** state uses a long timed duration (`PROMISE_LOADING_DURATION`) so it stays in the **timed stack** (not perpetual). The timer is replaced when the promise settles to success or error.
215
+
216
+ Reserved variant names (`dismiss`, `update`, `dismissAt`, `dismissAll`, `fromPayload`, `promise`) cannot override core `$toast` methods.
217
+
218
+ In Alpine templates, wrap multi-argument calls in an arrow function:
219
+
36
220
  ```html
37
- <button @click="$toast('Hello')">Default</button>
38
- <button @click="$toast.success('Saved')">Success</button>
39
- <button @click="$toast('Notice', { position: 'top-center' })">Top</button>
40
- <button @click="() => $toast.promise(save, { loading: 'Saving...', success: 'Saved!' })">
221
+ <button
222
+ @click="() => $toast.promise(() => save(), { loading: 'Saving...', success: 'Saved!' })"
223
+ >
41
224
  Save
42
225
  </button>
43
226
  ```
44
227
 
228
+ ## Queue limits
229
+
230
+ Each **position** has two independent stacks:
231
+
232
+ 1. **Timed** — auto-dismiss toasts (`duration > 0`). `maxVisible` applies here (peek/stack UI).
233
+ 2. **Persistent** — `duration: false` (or `0` in payloads; normalized to `false`). Always fully visible in your UI.
234
+
235
+ `maxToasts` applies **per stack per position** (not globally). Example: `maxToasts: 5` allows up to 5 timed + 5 persistent toasts at `bottom-right`.
236
+
237
+ | Option | Default | Description |
238
+ |--------|---------|-------------|
239
+ | `maxToasts` | `5` | Maximum active toasts **per stack per position**. `0` = unlimited. |
240
+ | `maxVisible` | `maxToasts` | Maximum timed toasts shown at once per position (`isVisibleAt`). |
241
+
242
+ Use `activeTimedItemsAt` / `activePersistentItemsAt` when your renderer does not need exiting (`removed`) items. Keep `timedItemsAt` / `persistentItemsAt` when you animate dismiss (Sonner-style).
243
+
244
+ ## Window events
245
+
246
+ ```js
247
+ window.dispatchEvent(
248
+ new CustomEvent("toast", {
249
+ detail: { title: "From anywhere", variant: "success", position: "top-center" },
250
+ })
251
+ );
252
+ ```
253
+
254
+ Disable with `toast({ listenToWindowEvents: false })`.
255
+
256
+ ## Rendering UI
257
+
45
258
  ```html
46
- <button @click="$toast.dismiss(toast.id)" aria-label="Close">✕</button>
259
+ <template x-for="position in $store.toast.stackPositions" :key="position">
260
+ <div
261
+ role="region"
262
+ x-bind:aria-label="'Toasts ' + position"
263
+ x-bind:data-position="position"
264
+ >
265
+ <template x-for="(toast, index) in $store.toast.itemsAt(position)" :key="toast.id">
266
+ <div
267
+ role="status"
268
+ x-show="!toast.removed && $store.toast.isVisibleAt(position, index)"
269
+ x-bind:data-variant="toast.variant"
270
+ >
271
+ <p x-text="toast.title"></p>
272
+ </div>
273
+ </template>
274
+ </div>
275
+ </template>
47
276
  ```
48
277
 
49
- Also available on the store: `$store.toast.dismiss(id)`.
50
-
51
- ## API summary
52
-
53
- | | |
54
- |-|-|
55
- | **Content** | `content` on each toast — any type your UI renders |
56
- | **Magic** | `$toast(title, options?)` toast id (`default` variant, `bottom-right` position) |
57
- | **Close** | `$toast.dismiss(id)`, `$toast.dismissAt(position)`, `$toast.dismissAll()` |
58
- | **Dedupe** | `$toast.pushUnique(key, payload)` — one active toast per key (undo flows) |
59
- | **Promise** | `$toast.promise(factoryOrPromise, messages?)` |
60
- | **Variants** | `variants: toastVariants([...])` → `$toast.<name>()` |
61
- | **Positions** | `positions: toastPositions([...])` → one stack per position |
62
- | **Queue** | `maxToasts` / `maxVisible` per timed or persistent stack |
63
- | **UI** | Bring your own markup and CSS |
278
+ Style `[data-variant="…"]` and `[data-position="…"]` in your own CSS or component library.
279
+
280
+ ## Plugin options
281
+
282
+ ```js
283
+ Alpine.plugin(
284
+ toast({
285
+ variants: toastVariants(["success", "error"] as const),
286
+ positions: toastPositions(["top-center", "bottom-right"] as const),
287
+ defaultPosition: "bottom-right",
288
+ defaultDuration: 5000,
289
+ maxToasts: 5,
290
+ maxVisible: 3,
291
+ listenToWindowEvents: true,
292
+ storeKey: "toast",
293
+ magicKey: "toast",
294
+ promise: {
295
+ loadingVariant: "success",
296
+ successVariant: "success",
297
+ errorVariant: "error",
298
+ },
299
+ })
300
+ );
301
+ ```
302
+
303
+ ### Avoiding name collisions
304
+
305
+ If your application already owns a `$toast` store or magic — or another toolkit plugin registers on that name — rename the integration surface without touching the controller:
306
+
307
+ ```ts
308
+ Alpine.plugin(
309
+ toast({
310
+ storeKey: "alerts", // → $store.alerts
311
+ magicKey: "snack", // → $snack
312
+ }),
313
+ );
314
+ ```
315
+
316
+ The exposed constants `TOAST_STORE_KEY` and `TOAST_MAGIC_KEY` keep the renames discoverable from TypeScript.
317
+
318
+ ## Related packages
319
+
320
+ - [`@ailuracode/alpine-notify`](./notify.md) — OS-level Web Notifications (`$notify`)
64
321
 
65
322
  ## License
66
323
 
package/dist/global.d.ts CHANGED
@@ -1,266 +1,20 @@
1
- /// <reference types="@types/alpinejs" />
2
-
3
- export declare const TOAST_STORE_KEY: "toast";
4
-
5
- export type ToastStoreKey = typeof TOAST_STORE_KEY;
6
-
7
- export type DefaultToastPosition = "bottom-right";
8
-
9
- export type ToastPosition<TPositions extends readonly string[] = readonly []> =
10
- | DefaultToastPosition
11
- | TPositions[number];
12
-
13
- export type DefaultToastVariant = "default";
14
-
15
- /** Milliseconds before auto-dismiss, or `false` / `0` to keep the toast open. */
16
- export type ToastDuration = number | false;
17
-
18
- export type ToastVariant<TVariants extends readonly string[] = readonly []> =
19
- | DefaultToastVariant
20
- | TVariants[number];
21
-
22
- export interface ToastAction {
23
- label: string;
24
- onClick?: () => void;
25
- }
26
-
27
- export interface ToastPayload<
28
- TVariants extends readonly string[] = readonly [],
29
- TPositions extends readonly string[] = readonly [],
30
- TContent = unknown,
31
- > {
32
- content?: TContent | null;
33
- title?: string | null;
34
- description?: string | null;
35
- variant?: ToastVariant<TVariants>;
36
- position?: ToastPosition<TPositions>;
37
- duration?: ToastDuration;
38
- action?: ToastAction | null;
39
- key?: string | null;
40
- }
41
-
42
- export interface ToastItem<
43
- TVariants extends readonly string[] = readonly [],
44
- TPositions extends readonly string[] = readonly [],
45
- TContent = unknown,
46
- > {
47
- id: string;
48
- key: string | null;
49
- content: TContent | null;
50
- title: string | null;
51
- description: string | null;
52
- variant: ToastVariant<TVariants>;
53
- position: ToastPosition<TPositions>;
54
- duration: ToastDuration;
55
- action: ToastAction | null;
56
- removed: boolean;
57
- }
58
-
59
- export type ToastPayloadWithoutVariant<
60
- TVariants extends readonly string[] = readonly [],
61
- TPositions extends readonly string[] = readonly [],
62
- TContent = unknown,
63
- > = Omit<ToastPayload<TVariants, TPositions, TContent>, "variant">;
64
-
65
- export interface ToastPromiseOptions<TVariants extends readonly string[] = readonly []> {
66
- loading?: string;
67
- error?: string;
68
- duration?: ToastDuration;
69
- loadingVariant?: ToastVariant<TVariants>;
70
- successVariant?: ToastVariant<TVariants>;
71
- errorVariant?: ToastVariant<TVariants>;
72
- }
73
-
74
- export interface ToastPluginOptions<
75
- TVariants extends readonly string[] = readonly [],
76
- TPositions extends readonly string[] = readonly [],
77
- _TContent = unknown,
78
- > {
79
- variants?: TVariants;
80
- positions?: TPositions;
81
- defaultPosition?: ToastPosition<TPositions>;
82
- defaultDuration?: number;
83
- promise?: ToastPromiseOptions<TVariants>;
84
- maxToasts?: number;
85
- maxVisible?: number;
86
- listenToWindowEvents?: boolean;
87
- storeKey?: ToastStoreKey;
88
- }
89
-
90
- export interface ToastPromiseMessages<
91
- T = unknown,
92
- TVariant extends string = string,
93
- TContent = unknown,
94
- > {
95
- loading?: string;
96
- success?: string | ((data: T) => string);
97
- error?: string;
98
- loadingContent?: TContent;
99
- successContent?: TContent | ((data: T) => TContent);
100
- errorContent?: TContent;
101
- loadingVariant?: TVariant;
102
- successVariant?: TVariant;
103
- errorVariant?: TVariant;
104
- duration?: ToastDuration;
105
- }
106
-
107
- export type ToastPromiseInput<T> = (() => Promise<T> | T) | Promise<T>;
1
+ /**
2
+ * Ambient type surface for `@ailuracode/alpine-toast`.
3
+ *
4
+ * Re-exports the {@link ToastStore} shape so consumers can include
5
+ * this file via the global.d.ts triple-slash directive and
6
+ * typecheck `$store.toast` / `$toast` references without pulling
7
+ * the runtime entrypoint.
8
+ *
9
+ * Per core's `global.d.ts` convention, this package does NOT
10
+ * augment external modules. The `Alpine.Stores` / `Alpine.Magics<T>`
11
+ * augmentation that earlier drafts proposed has been removed —
12
+ * consumers that need typed `$store.toast` access should declare
13
+ * the augmentation in their own `*.d.ts` (or use the typed
14
+ * `Alpine<{ toast: ToastStore }>` view from
15
+ * `@ailuracode/alpine-core` directly).
16
+ */
108
17
 
109
- export type ToastEventPayload<
110
- TVariants extends readonly string[] = readonly [],
111
- TPositions extends readonly string[] = readonly [],
112
- TContent = unknown,
113
- > = ToastPayload<TVariants, TPositions, TContent>;
114
-
115
- export interface ToastStore<
116
- TVariants extends readonly string[] = readonly [],
117
- TPositions extends readonly string[] = readonly [],
118
- TContent = unknown,
119
- > {
120
- defaultPosition: ToastPosition<TPositions>;
121
- stackPositions: readonly ToastPosition<TPositions>[];
122
- maxToasts: number;
123
- maxVisible: number;
124
- items: ToastItem<TVariants, TPositions, TContent>[];
125
- push(payload?: ToastPayload<TVariants, TPositions, TContent>): string;
126
- pushUnique(key: string, payload?: ToastPayload<TVariants, TPositions, TContent>): string;
127
- update(id: string, payload?: Partial<ToastPayload<TVariants, TPositions, TContent>>): void;
128
- dismiss(id: string): void;
129
- dismissAt(position: ToastPosition<TPositions>): void;
130
- dismissAll(): void;
131
- destroy(): void;
132
- itemsAt(position: ToastPosition<TPositions>): ToastItem<TVariants, TPositions, TContent>[];
133
- timedItemsAt(position: ToastPosition<TPositions>): ToastItem<TVariants, TPositions, TContent>[];
134
- persistentItemsAt(
135
- position: ToastPosition<TPositions>
136
- ): ToastItem<TVariants, TPositions, TContent>[];
137
- activeTimedItemsAt(
138
- position: ToastPosition<TPositions>
139
- ): ToastItem<TVariants, TPositions, TContent>[];
140
- activePersistentItemsAt(
141
- position: ToastPosition<TPositions>
142
- ): ToastItem<TVariants, TPositions, TContent>[];
143
- isVisibleAt(position: ToastPosition<TPositions>, index: number): boolean;
144
- }
145
-
146
- export type ToastVariantMethods<
147
- TVariants extends readonly string[],
148
- TPositions extends readonly string[] = readonly [],
149
- TContent = unknown,
150
- > = {
151
- [K in TVariants[number]]: (
152
- titleOrPayload: string | ToastPayloadWithoutVariant<TVariants, TPositions, TContent>,
153
- options?: Omit<ToastPayloadWithoutVariant<TVariants, TPositions, TContent>, "title" | "content">
154
- ) => string;
155
- };
156
-
157
- export type ToastMagic<
158
- TVariants extends readonly string[] = readonly [],
159
- TPositions extends readonly string[] = readonly [],
160
- TContent = unknown,
161
- > = {
162
- (title: string, options?: Omit<ToastPayload<TVariants, TPositions, TContent>, "title">): string;
163
- (payload: ToastPayload<TVariants, TPositions, TContent>): string;
164
- promise<T>(
165
- factoryOrPromise: ToastPromiseInput<T>,
166
- messages?: ToastPromiseMessages<T, ToastVariant<TVariants>, TContent>
167
- ): Promise<T>;
168
- dismiss(id: string): void;
169
- update(id: string, payload?: Partial<ToastPayload<TVariants, TPositions, TContent>>): void;
170
- dismissAt(position: ToastPosition<TPositions>): void;
171
- dismissAll(): void;
172
- pushUnique(key: string, payload?: ToastPayload<TVariants, TPositions, TContent>): string;
173
- fromPayload(payload?: ToastEventPayload<TVariants, TPositions, TContent>): string;
174
- } & ToastVariantMethods<TVariants, TPositions, TContent>;
175
-
176
- export type ResolvedPromiseConfig<TVariants extends readonly string[] = readonly []> = {
177
- loading: string;
178
- error: string;
179
- duration: ToastDuration;
180
- loadingVariant: ToastVariant<TVariants>;
181
- successVariant: ToastVariant<TVariants>;
182
- errorVariant: ToastVariant<TVariants>;
183
- };
184
-
185
- export type ResolvedToastPluginConfig<
186
- TVariants extends readonly string[] = readonly [],
187
- TPositions extends readonly string[] = readonly [],
188
- > = {
189
- defaultPosition: ToastPosition<TPositions>;
190
- defaultDuration: number;
191
- maxToasts: number;
192
- maxVisible: number;
193
- listenToWindowEvents: boolean;
194
- storeKey: ToastStoreKey;
195
- variants: TVariants;
196
- positions: TPositions;
197
- promise: ResolvedPromiseConfig<TVariants>;
198
- };
199
-
200
- export declare function resolveToastPluginConfig<
201
- const TVariants extends readonly string[] = readonly [],
202
- const TPositions extends readonly string[] = readonly [],
203
- >(
204
- options?: ToastPluginOptions<TVariants, TPositions>
205
- ): ResolvedToastPluginConfig<TVariants, TPositions>;
206
-
207
- export declare function toastOptions<
208
- const TVariants extends readonly string[] = readonly [],
209
- const TPositions extends readonly string[] = readonly [],
210
- TContent = unknown,
211
- >(
212
- options: ToastPluginOptions<TVariants, TPositions, TContent>
213
- ): ToastPluginOptions<TVariants, TPositions, TContent>;
214
-
215
- export declare function toastVariants<const T extends readonly string[]>(variants: T): T;
216
-
217
- export declare function toastPositions<const T extends readonly string[]>(positions: T): T;
218
-
219
- export interface CreateToastStoreOptions<TPositions extends readonly string[] = readonly []> {
220
- defaultPosition?: ToastPosition<TPositions>;
221
- positions?: TPositions;
222
- defaultDuration?: number;
223
- maxToasts?: number;
224
- maxVisible?: number;
225
- }
226
-
227
- export declare function resolveStackPositions<TPositions extends readonly string[]>(
228
- defaultPosition: ToastPosition<TPositions>,
229
- positions?: TPositions
230
- ): readonly ToastPosition<TPositions>[];
231
-
232
- export declare function createToastStore<
233
- const TPositions extends readonly string[] = readonly [],
234
- TContent = unknown,
235
- >(options?: CreateToastStoreOptions<TPositions>): ToastStore<readonly [], TPositions, TContent>;
236
-
237
- export declare function createToastMagic<
238
- const TVariants extends readonly string[],
239
- const TPositions extends readonly string[] = readonly [],
240
- TContent = unknown,
241
- >(
242
- config: ResolvedToastPluginConfig<TVariants, TPositions>,
243
- getStore: () => ToastStore<TVariants, TPositions, TContent>
244
- ): ToastMagic<TVariants, TPositions, TContent>;
245
-
246
- declare function toastPlugin<
247
- const TVariants extends readonly string[] = readonly [],
248
- const TPositions extends readonly string[] = readonly [],
249
- TContent = unknown,
250
- >(
251
- options?: ToastPluginOptions<TVariants, TPositions, TContent>
252
- ): (Alpine: import("alpinejs").Alpine) => void;
253
- declare function toastPlugin(Alpine: import("alpinejs").Alpine): void;
254
-
255
- export default toastPlugin;
18
+ /// <reference types="@types/alpinejs" />
256
19
 
257
- declare global {
258
- namespace Alpine {
259
- interface Stores {
260
- toast: ToastStore;
261
- }
262
- interface Magics<T> {
263
- $toast: ToastMagic;
264
- }
265
- }
266
- }
20
+ export type { ToastStore };