@solid2-aria/sonner 0.0.0-stage → 0.0.1
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/NOTICE.txt +27 -0
- package/README.md +75 -2
- package/SOLID-SONNER-LICENSE.md +21 -0
- package/SONNER-LICENSE.md +21 -0
- package/dist/browser/index.d.ts +219 -0
- package/dist/browser/index.js +1375 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/server/index.js +1682 -0
- package/dist/server/index.js.map +1 -0
- package/dist/styles.css +784 -0
- package/package.json +69 -4
|
@@ -0,0 +1,1375 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Derived from solid-sonner (https://github.com/wobsoriano/solid-sonner), src/.
|
|
3
|
+
* Copyright (c) 2022 Robert Soriano <https://github.com/wobsoriano>
|
|
4
|
+
* Derived from Sonner (https://github.com/emilkowalski/sonner), src/.
|
|
5
|
+
* Copyright (c) 2023 Emil Kowalski
|
|
6
|
+
* Modified for Solid Aria: Solid 2 reactivity, rendering, lifecycle, and packaging.
|
|
7
|
+
* MIT licensed. See LICENSE, SOLID-SONNER-LICENSE.md, SONNER-LICENSE.md, and NOTICE.txt in the package root.
|
|
8
|
+
*/
|
|
9
|
+
import { className, createComponent, delegateEvents, effect, getNextElement, getNextMarker, insert, memo, readShallow, ref, runHydrationEvents, scope, setAttribute, style, template } from "@solidjs/web";
|
|
10
|
+
import { For, Show, createEffect, createMemo, createRenderEffect, createSignal, createStore, merge, onCleanup, onSettled, untrack } from "solid-js";
|
|
11
|
+
// src/assets.tsx
|
|
12
|
+
var _tmpl$$1 = /* @__PURE__ */ template(`<div><div class=sonner-spinner>`);
|
|
13
|
+
var _tmpl$2$1 = /* @__PURE__ */ template(`<div class=sonner-loading-bar>`);
|
|
14
|
+
var _tmpl$3$1 = /* @__PURE__ */ template(`<svg aria-hidden=true viewBox="0 0 20 20"fill=currentColor height=20 width=20><path fill-rule=evenodd d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z"clip-rule=evenodd>`);
|
|
15
|
+
var _tmpl$4$1 = /* @__PURE__ */ template(`<svg aria-hidden=true viewBox="0 0 24 24"fill=currentColor height=20 width=20><path fill-rule=evenodd d="M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003zM12 8.25a.75.75 0 01.75.75v3.75a.75.75 0 01-1.5 0V9a.75.75 0 01.75-.75zm0 8.25a.75.75 0 100-1.5.75.75 0 000 1.5z"clip-rule=evenodd>`);
|
|
16
|
+
var _tmpl$5$1 = /* @__PURE__ */ template(`<svg aria-hidden=true viewBox="0 0 20 20"fill=currentColor height=20 width=20><path fill-rule=evenodd d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z"clip-rule=evenodd>`);
|
|
17
|
+
var _tmpl$6$1 = /* @__PURE__ */ template(`<svg aria-hidden=true viewBox="0 0 20 20"fill=currentColor height=20 width=20><path fill-rule=evenodd d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z"clip-rule=evenodd>`);
|
|
18
|
+
var _tmpl$7$1 = /* @__PURE__ */ template(`<svg aria-hidden=true width=12 height=12 viewBox="0 0 24 24"fill=none stroke=currentColor stroke-width=1.5 stroke-linecap=round stroke-linejoin=round><line x1=18 y1=6 x2=6 y2=18></line><line x1=6 y1=6 x2=18 y2=18>`);
|
|
19
|
+
/*!
|
|
20
|
+
* Derived from solid-sonner (https://github.com/wobsoriano/solid-sonner), src/assets.tsx.
|
|
21
|
+
* Copyright (c) 2022 Robert Soriano <https://github.com/wobsoriano>
|
|
22
|
+
* Derived from Sonner (https://github.com/emilkowalski/sonner), src/assets.tsx.
|
|
23
|
+
* Copyright (c) 2023 Emil Kowalski
|
|
24
|
+
* Modified for Solid Aria: Solid 2 types, reactivity, lifecycle, and package integration.
|
|
25
|
+
* MIT licensed. See LICENSE, SOLID-SONNER-LICENSE.md, SONNER-LICENSE.md, and NOTICE.txt in the package root.
|
|
26
|
+
*/
|
|
27
|
+
const bars = Array.from({ length: 12 }, () => 0);
|
|
28
|
+
function Loader(props) {
|
|
29
|
+
var _el$ = getNextElement(_tmpl$$1);
|
|
30
|
+
var _el$2 = _el$.firstChild;
|
|
31
|
+
insert(_el$2, createComponent(For, {
|
|
32
|
+
each: bars,
|
|
33
|
+
keyed: false,
|
|
34
|
+
children: (_, i) => (() => {
|
|
35
|
+
var _el$3 = getNextElement(_tmpl$2$1);
|
|
36
|
+
setAttribute(_el$3, "data-index", i);
|
|
37
|
+
return _el$3;
|
|
38
|
+
})()
|
|
39
|
+
}));
|
|
40
|
+
effect(() => {
|
|
41
|
+
return {
|
|
42
|
+
e: readShallow(["sonner-loading-wrapper", props.class ?? props.className]),
|
|
43
|
+
t: String(props.visible)
|
|
44
|
+
};
|
|
45
|
+
}, ({ e, t }, _p$) => {
|
|
46
|
+
className(_el$, e, _p$?.e);
|
|
47
|
+
t !== _p$?.t && setAttribute(_el$, "data-visible", t);
|
|
48
|
+
});
|
|
49
|
+
return _el$;
|
|
50
|
+
}
|
|
51
|
+
function SuccessIcon() {
|
|
52
|
+
return getNextElement(_tmpl$3$1);
|
|
53
|
+
}
|
|
54
|
+
function WarningIcon() {
|
|
55
|
+
return getNextElement(_tmpl$4$1);
|
|
56
|
+
}
|
|
57
|
+
function InfoIcon() {
|
|
58
|
+
return getNextElement(_tmpl$5$1);
|
|
59
|
+
}
|
|
60
|
+
function ErrorIcon() {
|
|
61
|
+
return getNextElement(_tmpl$6$1);
|
|
62
|
+
}
|
|
63
|
+
function getAsset(type) {
|
|
64
|
+
switch (type) {
|
|
65
|
+
case "success": return createComponent(SuccessIcon, {});
|
|
66
|
+
case "info": return createComponent(InfoIcon, {});
|
|
67
|
+
case "warning": return createComponent(WarningIcon, {});
|
|
68
|
+
case "error": return createComponent(ErrorIcon, {});
|
|
69
|
+
case void 0:
|
|
70
|
+
case "action":
|
|
71
|
+
case "default":
|
|
72
|
+
case "loading":
|
|
73
|
+
case "normal": return null;
|
|
74
|
+
default: return type;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function CloseIcon() {
|
|
78
|
+
return getNextElement(_tmpl$7$1);
|
|
79
|
+
}
|
|
80
|
+
// src/primitives.ts
|
|
81
|
+
/*!
|
|
82
|
+
* Derived from solid-sonner (https://github.com/wobsoriano/solid-sonner), src/primitives.ts.
|
|
83
|
+
* Copyright (c) 2022 Robert Soriano <https://github.com/wobsoriano>
|
|
84
|
+
* Modified for Solid Aria: Solid 2 types, reactivity, lifecycle, and package integration.
|
|
85
|
+
* MIT licensed. See LICENSE, SOLID-SONNER-LICENSE.md, SONNER-LICENSE.md, and NOTICE.txt in the package root.
|
|
86
|
+
*/
|
|
87
|
+
function createIsDocumentHidden() {
|
|
88
|
+
const [isDocumentHidden, setIsDocumentHidden] = createSignal(globalThis.document?.hidden ?? false);
|
|
89
|
+
const callback = () => {
|
|
90
|
+
setIsDocumentHidden(document.hidden);
|
|
91
|
+
};
|
|
92
|
+
onSettled(() => {
|
|
93
|
+
document.addEventListener("visibilitychange", callback);
|
|
94
|
+
return () => {
|
|
95
|
+
document.removeEventListener("visibilitychange", callback);
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
return isDocumentHidden;
|
|
99
|
+
}
|
|
100
|
+
// src/state.ts
|
|
101
|
+
/*!
|
|
102
|
+
* Derived from solid-sonner (https://github.com/wobsoriano/solid-sonner), src/state.ts.
|
|
103
|
+
* Copyright (c) 2022 Robert Soriano <https://github.com/wobsoriano>
|
|
104
|
+
* Derived from Sonner (https://github.com/emilkowalski/sonner), src/state.ts.
|
|
105
|
+
* Copyright (c) 2023 Emil Kowalski
|
|
106
|
+
* Modified for Solid Aria: Solid 2 types, reactivity, lifecycle, and package integration.
|
|
107
|
+
* MIT licensed. See LICENSE, SOLID-SONNER-LICENSE.md, SONNER-LICENSE.md, and NOTICE.txt in the package root.
|
|
108
|
+
*/
|
|
109
|
+
let toastsCounter = 1;
|
|
110
|
+
const MAX_HISTORY_SIZE = 100;
|
|
111
|
+
function getToastId(data) {
|
|
112
|
+
if (data?.id !== void 0 && data.id !== "") return data.id;
|
|
113
|
+
const id = toastsCounter;
|
|
114
|
+
toastsCounter += 1;
|
|
115
|
+
return id;
|
|
116
|
+
}
|
|
117
|
+
function isHttpResponse(data) {
|
|
118
|
+
return typeof data === "object" && data !== null && "ok" in data && typeof data.ok === "boolean" && "status" in data && typeof data.status === "number";
|
|
119
|
+
}
|
|
120
|
+
function getPromiseSettings(value) {
|
|
121
|
+
return typeof value === "object" && value !== null && "message" in value ? value : { message: value };
|
|
122
|
+
}
|
|
123
|
+
function isValidElement(value) {
|
|
124
|
+
return globalThis.Node !== void 0 && value instanceof Node;
|
|
125
|
+
}
|
|
126
|
+
var Observer = class {
|
|
127
|
+
subscribers;
|
|
128
|
+
toasts;
|
|
129
|
+
dismissedToasts;
|
|
130
|
+
pendingDismissals;
|
|
131
|
+
constructor() {
|
|
132
|
+
this.subscribers = [];
|
|
133
|
+
this.toasts = [];
|
|
134
|
+
this.dismissedToasts = /* @__PURE__ */ new Set();
|
|
135
|
+
this.pendingDismissals = /* @__PURE__ */ new Map();
|
|
136
|
+
}
|
|
137
|
+
subscribe = (subscriber) => {
|
|
138
|
+
this.subscribers.push(subscriber);
|
|
139
|
+
for (const activeToast of this.getActiveToasts()) subscriber(activeToast);
|
|
140
|
+
return () => {
|
|
141
|
+
const index = this.subscribers.indexOf(subscriber);
|
|
142
|
+
this.subscribers.splice(index, 1);
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
publish = (data) => {
|
|
146
|
+
for (const subscriber of this.subscribers) subscriber(data);
|
|
147
|
+
};
|
|
148
|
+
addToast = (data) => {
|
|
149
|
+
this.publish(data);
|
|
150
|
+
this.toasts = [...this.toasts, data];
|
|
151
|
+
this.trimHistory();
|
|
152
|
+
};
|
|
153
|
+
trimHistory = () => {
|
|
154
|
+
let toRemove = this.toasts.length - MAX_HISTORY_SIZE;
|
|
155
|
+
if (toRemove <= 0) return;
|
|
156
|
+
this.toasts = this.toasts.filter((toast) => {
|
|
157
|
+
if (toRemove > 0 && this.dismissedToasts.has(toast.id)) {
|
|
158
|
+
this.dismissedToasts.delete(toast.id);
|
|
159
|
+
toRemove -= 1;
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
return true;
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
create = (data) => {
|
|
166
|
+
const { message, ...rest } = data;
|
|
167
|
+
const id = getToastId(data);
|
|
168
|
+
const pendingDismissal = this.pendingDismissals.get(id);
|
|
169
|
+
if (pendingDismissal !== void 0) {
|
|
170
|
+
cancelAnimationFrame(pendingDismissal);
|
|
171
|
+
this.pendingDismissals.delete(id);
|
|
172
|
+
this.dismissedToasts.delete(id);
|
|
173
|
+
}
|
|
174
|
+
const wasDismissed = this.dismissedToasts.has(id);
|
|
175
|
+
const dismissible = data.dismissible ?? true;
|
|
176
|
+
if (wasDismissed) {
|
|
177
|
+
this.dismissedToasts.delete(id);
|
|
178
|
+
this.toasts = this.toasts.filter((toast) => toast.id !== id);
|
|
179
|
+
}
|
|
180
|
+
if (wasDismissed ? void 0 : this.toasts.find((toast) => toast.id === id)) this.toasts = this.toasts.map((toast) => {
|
|
181
|
+
if (toast.id === id) {
|
|
182
|
+
this.publish({
|
|
183
|
+
...toast,
|
|
184
|
+
...data,
|
|
185
|
+
dismissible,
|
|
186
|
+
id,
|
|
187
|
+
title: message
|
|
188
|
+
});
|
|
189
|
+
return {
|
|
190
|
+
...toast,
|
|
191
|
+
...data,
|
|
192
|
+
dismissible,
|
|
193
|
+
id,
|
|
194
|
+
title: message
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
return toast;
|
|
198
|
+
});
|
|
199
|
+
else this.addToast({
|
|
200
|
+
title: message,
|
|
201
|
+
...rest,
|
|
202
|
+
dismissible,
|
|
203
|
+
id
|
|
204
|
+
});
|
|
205
|
+
return id;
|
|
206
|
+
};
|
|
207
|
+
dismiss = (id) => {
|
|
208
|
+
if (id === void 0 || id === null) {
|
|
209
|
+
for (const activeToast of this.getActiveToasts()) {
|
|
210
|
+
this.dismissedToasts.add(activeToast.id);
|
|
211
|
+
for (const subscriber of this.subscribers) subscriber({
|
|
212
|
+
dismiss: true,
|
|
213
|
+
id: activeToast.id
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
return id;
|
|
217
|
+
}
|
|
218
|
+
this.dismissedToasts.add(id);
|
|
219
|
+
const alreadyPending = this.pendingDismissals.get(id);
|
|
220
|
+
if (alreadyPending !== void 0) cancelAnimationFrame(alreadyPending);
|
|
221
|
+
this.pendingDismissals.set(id, requestAnimationFrame(() => {
|
|
222
|
+
this.pendingDismissals.delete(id);
|
|
223
|
+
for (const subscriber of this.subscribers) subscriber({
|
|
224
|
+
dismiss: true,
|
|
225
|
+
id
|
|
226
|
+
});
|
|
227
|
+
}));
|
|
228
|
+
return id;
|
|
229
|
+
};
|
|
230
|
+
message = (message, data) => this.create({
|
|
231
|
+
...data,
|
|
232
|
+
message,
|
|
233
|
+
type: void 0
|
|
234
|
+
});
|
|
235
|
+
error = (message, data) => this.create({
|
|
236
|
+
...data,
|
|
237
|
+
message,
|
|
238
|
+
type: "error"
|
|
239
|
+
});
|
|
240
|
+
success = (message, data) => this.create({
|
|
241
|
+
...data,
|
|
242
|
+
message,
|
|
243
|
+
type: "success"
|
|
244
|
+
});
|
|
245
|
+
info = (message, data) => this.create({
|
|
246
|
+
...data,
|
|
247
|
+
message,
|
|
248
|
+
type: "info"
|
|
249
|
+
});
|
|
250
|
+
warning = (message, data) => this.create({
|
|
251
|
+
...data,
|
|
252
|
+
message,
|
|
253
|
+
type: "warning"
|
|
254
|
+
});
|
|
255
|
+
loading = (message, data) => this.create({
|
|
256
|
+
...data,
|
|
257
|
+
message,
|
|
258
|
+
type: "loading"
|
|
259
|
+
});
|
|
260
|
+
promise = (promise, data) => {
|
|
261
|
+
if (!data) return;
|
|
262
|
+
let id;
|
|
263
|
+
if (data.loading !== void 0) id = this.create({
|
|
264
|
+
...data,
|
|
265
|
+
description: typeof data.description === "function" ? void 0 : data.description,
|
|
266
|
+
message: data.loading,
|
|
267
|
+
promise,
|
|
268
|
+
type: "loading"
|
|
269
|
+
});
|
|
270
|
+
const { finally: onFinally } = data;
|
|
271
|
+
const pending = Promise.resolve(typeof promise === "function" ? promise() : promise);
|
|
272
|
+
let shouldDismiss = id !== void 0;
|
|
273
|
+
const originalPromise = (async () => {
|
|
274
|
+
let result;
|
|
275
|
+
try {
|
|
276
|
+
const response = await pending;
|
|
277
|
+
result = ["resolve", response];
|
|
278
|
+
if (isValidElement(response)) {
|
|
279
|
+
shouldDismiss = false;
|
|
280
|
+
this.create({
|
|
281
|
+
id,
|
|
282
|
+
message: response,
|
|
283
|
+
type: "default"
|
|
284
|
+
});
|
|
285
|
+
} else if (isHttpResponse(response) && !response.ok) {
|
|
286
|
+
shouldDismiss = false;
|
|
287
|
+
const error = `HTTP error! status: ${response.status}`;
|
|
288
|
+
const message = typeof data.error === "function" ? await data.error(error) : data.error;
|
|
289
|
+
const description = typeof data.description === "function" ? await data.description(error) : data.description;
|
|
290
|
+
this.create({
|
|
291
|
+
description,
|
|
292
|
+
id,
|
|
293
|
+
type: "error",
|
|
294
|
+
...getPromiseSettings(message)
|
|
295
|
+
});
|
|
296
|
+
} else if (response instanceof Error) {
|
|
297
|
+
shouldDismiss = false;
|
|
298
|
+
const message = typeof data.error === "function" ? await data.error(response) : data.error;
|
|
299
|
+
const description = typeof data.description === "function" ? await data.description(response) : data.description;
|
|
300
|
+
this.create({
|
|
301
|
+
description,
|
|
302
|
+
id,
|
|
303
|
+
type: "error",
|
|
304
|
+
...getPromiseSettings(message)
|
|
305
|
+
});
|
|
306
|
+
} else if (data.success !== void 0) {
|
|
307
|
+
shouldDismiss = false;
|
|
308
|
+
const message = typeof data.success === "function" ? await data.success(response) : data.success;
|
|
309
|
+
const description = typeof data.description === "function" ? await data.description(response) : data.description;
|
|
310
|
+
this.create({
|
|
311
|
+
description,
|
|
312
|
+
id,
|
|
313
|
+
type: "success",
|
|
314
|
+
...getPromiseSettings(message)
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
} catch (error) {
|
|
318
|
+
result = ["reject", error];
|
|
319
|
+
if (data.error !== void 0) {
|
|
320
|
+
shouldDismiss = false;
|
|
321
|
+
const message = typeof data.error === "function" ? await data.error(error) : data.error;
|
|
322
|
+
const description = typeof data.description === "function" ? await data.description(error) : data.description;
|
|
323
|
+
this.create({
|
|
324
|
+
description,
|
|
325
|
+
id,
|
|
326
|
+
type: "error",
|
|
327
|
+
...getPromiseSettings(message)
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
} finally {
|
|
331
|
+
if (shouldDismiss) {
|
|
332
|
+
this.dismiss(id);
|
|
333
|
+
id = void 0;
|
|
334
|
+
}
|
|
335
|
+
onFinally?.();
|
|
336
|
+
}
|
|
337
|
+
return result;
|
|
338
|
+
})();
|
|
339
|
+
const unwrap = async () => {
|
|
340
|
+
const result = await originalPromise;
|
|
341
|
+
if (result[0] === "reject") throw result[1];
|
|
342
|
+
return result[1];
|
|
343
|
+
};
|
|
344
|
+
if (id === void 0) return { unwrap };
|
|
345
|
+
return Object.assign(id, { unwrap });
|
|
346
|
+
};
|
|
347
|
+
custom = (jsx, data) => {
|
|
348
|
+
const id = getToastId(data);
|
|
349
|
+
this.create({
|
|
350
|
+
...data,
|
|
351
|
+
id,
|
|
352
|
+
jsx: jsx(id),
|
|
353
|
+
type: void 0
|
|
354
|
+
});
|
|
355
|
+
return id;
|
|
356
|
+
};
|
|
357
|
+
getActiveToasts = () => this.toasts.filter((toast) => !this.dismissedToasts.has(toast.id));
|
|
358
|
+
};
|
|
359
|
+
const ToastState = new Observer();
|
|
360
|
+
function toastFunction(message, data) {
|
|
361
|
+
return ToastState.message(message, data);
|
|
362
|
+
}
|
|
363
|
+
const basicToast = toastFunction;
|
|
364
|
+
const getHistory = () => ToastState.toasts;
|
|
365
|
+
const getToasts = () => ToastState.getActiveToasts();
|
|
366
|
+
const toast = Object.assign(basicToast, {
|
|
367
|
+
custom: ToastState.custom,
|
|
368
|
+
dismiss: ToastState.dismiss,
|
|
369
|
+
error: ToastState.error,
|
|
370
|
+
info: ToastState.info,
|
|
371
|
+
loading: ToastState.loading,
|
|
372
|
+
message: ToastState.message,
|
|
373
|
+
promise: ToastState.promise,
|
|
374
|
+
success: ToastState.success,
|
|
375
|
+
warning: ToastState.warning
|
|
376
|
+
}, {
|
|
377
|
+
getHistory,
|
|
378
|
+
getToasts
|
|
379
|
+
});
|
|
380
|
+
// src/types.ts
|
|
381
|
+
/*!
|
|
382
|
+
* Derived from solid-sonner (https://github.com/wobsoriano/solid-sonner), src/types.ts.
|
|
383
|
+
* Copyright (c) 2022 Robert Soriano <https://github.com/wobsoriano>
|
|
384
|
+
* Derived from Sonner (https://github.com/emilkowalski/sonner), src/types.ts.
|
|
385
|
+
* Copyright (c) 2023 Emil Kowalski
|
|
386
|
+
* Modified for Solid Aria: Solid 2 types, reactivity, lifecycle, and package integration.
|
|
387
|
+
* MIT licensed. See LICENSE, SOLID-SONNER-LICENSE.md, SONNER-LICENSE.md, and NOTICE.txt in the package root.
|
|
388
|
+
*/
|
|
389
|
+
function isAction(action) {
|
|
390
|
+
return typeof action === "object" && action !== null && "label" in action;
|
|
391
|
+
}
|
|
392
|
+
// src/index.tsx
|
|
393
|
+
var _tmpl$ = /* @__PURE__ */ template(`<button data-button>`);
|
|
394
|
+
var _tmpl$2 = /* @__PURE__ */ template(`<button data-close-button>`);
|
|
395
|
+
var _tmpl$3 = /* @__PURE__ */ template(`<div data-icon><!$><!/><!$><!/>`);
|
|
396
|
+
var _tmpl$4 = /* @__PURE__ */ template(`<div data-description>`);
|
|
397
|
+
var _tmpl$5 = /* @__PURE__ */ template(`<div data-content><div data-title></div><!$><!/>`);
|
|
398
|
+
var _tmpl$6 = /* @__PURE__ */ template(`<div>`);
|
|
399
|
+
var _tmpl$7 = /* @__PURE__ */ template(`<li tabindex=0 data-sonner-toast>`);
|
|
400
|
+
var _tmpl$8 = /* @__PURE__ */ template(`<section tabindex=-1 aria-live=polite aria-relevant="additions text"aria-atomic=false data-react-aria-top-layer>`);
|
|
401
|
+
var _tmpl$9 = /* @__PURE__ */ template(`<ol tabindex=-1 data-sonner-toaster style=--width:356px>`);
|
|
402
|
+
/*!
|
|
403
|
+
* Derived from solid-sonner (https://github.com/wobsoriano/solid-sonner), src/index.tsx.
|
|
404
|
+
* Copyright (c) 2022 Robert Soriano <https://github.com/wobsoriano>
|
|
405
|
+
* Derived from Sonner (https://github.com/emilkowalski/sonner), src/index.tsx.
|
|
406
|
+
* Copyright (c) 2023 Emil Kowalski
|
|
407
|
+
* Modified for Solid Aria: Solid 2 types, reactivity, lifecycle, and package integration.
|
|
408
|
+
* MIT licensed. See LICENSE, SOLID-SONNER-LICENSE.md, SONNER-LICENSE.md, and NOTICE.txt in the package root.
|
|
409
|
+
*/
|
|
410
|
+
/*!
|
|
411
|
+
* Original code by Emil Kowalski
|
|
412
|
+
* MIT Licensed, Copyright 2023 Emil Kowalski, see https://github.com/emilkowalski/sonner/blob/main/LICENSE.md for details
|
|
413
|
+
*
|
|
414
|
+
* Credits:
|
|
415
|
+
* https://github.com/emilkowalski/sonner/blob/main/src/index.tsx
|
|
416
|
+
*/
|
|
417
|
+
const VISIBLE_TOASTS_AMOUNT = 3;
|
|
418
|
+
const VIEWPORT_OFFSET = "24px";
|
|
419
|
+
const MOBILE_VIEWPORT_OFFSET = "16px";
|
|
420
|
+
const TOAST_LIFETIME = 4e3;
|
|
421
|
+
const GAP = 14;
|
|
422
|
+
const SWIPE_THRESHOLD = 45;
|
|
423
|
+
const TIME_BEFORE_UNMOUNT = 200;
|
|
424
|
+
function cn(...classes) {
|
|
425
|
+
return classes;
|
|
426
|
+
}
|
|
427
|
+
function resolveContent(content) {
|
|
428
|
+
return typeof content === "function" ? content() : content;
|
|
429
|
+
}
|
|
430
|
+
function isSwipeDirection(direction) {
|
|
431
|
+
return direction === "top" || direction === "right" || direction === "bottom" || direction === "left";
|
|
432
|
+
}
|
|
433
|
+
function getDefaultSwipeDirections(position) {
|
|
434
|
+
return position.split("-").filter(isSwipeDirection);
|
|
435
|
+
}
|
|
436
|
+
function getDampening(delta) {
|
|
437
|
+
return 1 / (1.5 + Math.abs(delta) / 20);
|
|
438
|
+
}
|
|
439
|
+
function dampenMovement(delta, directionAllowed) {
|
|
440
|
+
return directionAllowed ? delta : delta * getDampening(delta);
|
|
441
|
+
}
|
|
442
|
+
function getSwipeAmount(direction, xDelta, yDelta, allowedDirections) {
|
|
443
|
+
if (direction === "y" && (allowedDirections.includes("top") || allowedDirections.includes("bottom"))) return {
|
|
444
|
+
x: 0,
|
|
445
|
+
y: dampenMovement(yDelta, allowedDirections.includes("top") && yDelta < 0 || allowedDirections.includes("bottom") && yDelta > 0)
|
|
446
|
+
};
|
|
447
|
+
if (direction === "x" && (allowedDirections.includes("left") || allowedDirections.includes("right"))) return {
|
|
448
|
+
x: dampenMovement(xDelta, allowedDirections.includes("left") && xDelta < 0 || allowedDirections.includes("right") && xDelta > 0),
|
|
449
|
+
y: 0
|
|
450
|
+
};
|
|
451
|
+
return {
|
|
452
|
+
x: 0,
|
|
453
|
+
y: 0
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
function getSwipeDismissDirection(direction, amountX, amountY, timeTaken, allowedDirections) {
|
|
457
|
+
if (!direction) return;
|
|
458
|
+
const amount = direction === "x" ? amountX : amountY;
|
|
459
|
+
let allowedDirection;
|
|
460
|
+
if (direction === "x") allowedDirection = amountX > 0 ? "right" : "left";
|
|
461
|
+
else allowedDirection = amountY > 0 ? "bottom" : "top";
|
|
462
|
+
if (!allowedDirections.includes(allowedDirection)) return;
|
|
463
|
+
if (Math.abs(amount) < SWIPE_THRESHOLD && Math.abs(amount) / timeTaken <= .11) return;
|
|
464
|
+
if (allowedDirection === "left" || allowedDirection === "right") return allowedDirection;
|
|
465
|
+
return allowedDirection === "bottom" ? "down" : "up";
|
|
466
|
+
}
|
|
467
|
+
function isToastIconType(type) {
|
|
468
|
+
return type === "success" || type === "info" || type === "warning" || type === "error" || type === "loading";
|
|
469
|
+
}
|
|
470
|
+
function isToastClassNameType(type) {
|
|
471
|
+
return type === "success" || type === "info" || type === "warning" || type === "error" || type === "loading" || type === "default";
|
|
472
|
+
}
|
|
473
|
+
function isDirection(value) {
|
|
474
|
+
return value === "ltr" || value === "rtl" || value === "auto";
|
|
475
|
+
}
|
|
476
|
+
function getNonActionContent(content) {
|
|
477
|
+
return isAction(content) ? null : content;
|
|
478
|
+
}
|
|
479
|
+
function ToastActionButton(props) {
|
|
480
|
+
return createComponent(Show, {
|
|
481
|
+
get when() {
|
|
482
|
+
return memo(() => {
|
|
483
|
+
return !!isAction(props.content);
|
|
484
|
+
})() ? props.content : false;
|
|
485
|
+
},
|
|
486
|
+
get fallback() {
|
|
487
|
+
return props.content;
|
|
488
|
+
},
|
|
489
|
+
children: (action) => (() => {
|
|
490
|
+
var _el$ = getNextElement(_tmpl$);
|
|
491
|
+
_el$._$$click = (event) => {
|
|
492
|
+
props.onClick(event);
|
|
493
|
+
};
|
|
494
|
+
insert(_el$, scope(() => {
|
|
495
|
+
return action().label;
|
|
496
|
+
}));
|
|
497
|
+
effect(() => {
|
|
498
|
+
return {
|
|
499
|
+
e: props.kind === "action" ? "" : void 0,
|
|
500
|
+
t: props.kind === "cancel" ? "" : void 0,
|
|
501
|
+
a: readShallow(props.style),
|
|
502
|
+
o: readShallow(props.class)
|
|
503
|
+
};
|
|
504
|
+
}, ({ e, t, a, o }, _p$) => {
|
|
505
|
+
e !== _p$?.e && setAttribute(_el$, "data-action", e);
|
|
506
|
+
t !== _p$?.t && setAttribute(_el$, "data-cancel", t);
|
|
507
|
+
style(_el$, a, _p$?.a);
|
|
508
|
+
className(_el$, o, _p$?.o);
|
|
509
|
+
});
|
|
510
|
+
runHydrationEvents();
|
|
511
|
+
return _el$;
|
|
512
|
+
})()
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
function getDocumentDirection() {
|
|
516
|
+
if (typeof window === "undefined") return "ltr";
|
|
517
|
+
if (typeof document === "undefined") return "ltr";
|
|
518
|
+
const dirAttribute = document.documentElement.getAttribute("dir");
|
|
519
|
+
if (dirAttribute !== null && isDirection(dirAttribute)) return dirAttribute;
|
|
520
|
+
const { direction } = window.getComputedStyle(document.documentElement);
|
|
521
|
+
return isDirection(direction) ? direction : "ltr";
|
|
522
|
+
}
|
|
523
|
+
function formatOffset(value) {
|
|
524
|
+
return typeof value === "number" ? `${value}px` : value;
|
|
525
|
+
}
|
|
526
|
+
function assignOffset(defaultOffset, mobileOffset) {
|
|
527
|
+
const styles = {};
|
|
528
|
+
for (const [index, offset] of [defaultOffset, mobileOffset].entries()) {
|
|
529
|
+
const isMobile = index === 1;
|
|
530
|
+
const prefix = isMobile ? "--mobile-offset" : "--offset";
|
|
531
|
+
const defaultValue = isMobile ? MOBILE_VIEWPORT_OFFSET : VIEWPORT_OFFSET;
|
|
532
|
+
const assignAll = (value) => {
|
|
533
|
+
for (const key of [
|
|
534
|
+
"top",
|
|
535
|
+
"right",
|
|
536
|
+
"bottom",
|
|
537
|
+
"left"
|
|
538
|
+
]) styles[`${prefix}-${key}`] = typeof value === "number" ? `${value}px` : value;
|
|
539
|
+
};
|
|
540
|
+
if (typeof offset === "number" || typeof offset === "string") {
|
|
541
|
+
assignAll(offset);
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
544
|
+
if (typeof offset === "object" && offset !== null) {
|
|
545
|
+
for (const key of [
|
|
546
|
+
"top",
|
|
547
|
+
"right",
|
|
548
|
+
"bottom",
|
|
549
|
+
"left"
|
|
550
|
+
]) {
|
|
551
|
+
const value = offset[key];
|
|
552
|
+
styles[`${prefix}-${key}`] = value === void 0 ? defaultValue : formatOffset(value);
|
|
553
|
+
}
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
assignAll(defaultValue);
|
|
557
|
+
}
|
|
558
|
+
return styles;
|
|
559
|
+
}
|
|
560
|
+
function mergeClassNames(classNames, legacy) {
|
|
561
|
+
return classNames ?? legacy;
|
|
562
|
+
}
|
|
563
|
+
function mergeDescriptionClassName(descriptionClassName, legacy) {
|
|
564
|
+
return descriptionClassName ?? legacy ?? "";
|
|
565
|
+
}
|
|
566
|
+
function mergeClassName(className, legacy) {
|
|
567
|
+
return className ?? legacy ?? "";
|
|
568
|
+
}
|
|
569
|
+
function useSonner() {
|
|
570
|
+
const [activeToasts, setActiveToasts] = createSignal([]);
|
|
571
|
+
onSettled(() => {
|
|
572
|
+
return ToastState.subscribe((toastItem) => {
|
|
573
|
+
if ("dismiss" in toastItem) {
|
|
574
|
+
setActiveToasts((toasts) => toasts.filter((t) => t.id !== toastItem.id));
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
setActiveToasts((toasts) => {
|
|
578
|
+
const indexOfExistingToast = toasts.findIndex((t) => t.id === toastItem.id);
|
|
579
|
+
if (indexOfExistingToast !== -1) return [
|
|
580
|
+
...toasts.slice(0, indexOfExistingToast),
|
|
581
|
+
{
|
|
582
|
+
...toasts[indexOfExistingToast],
|
|
583
|
+
...toastItem
|
|
584
|
+
},
|
|
585
|
+
...toasts.slice(indexOfExistingToast + 1)
|
|
586
|
+
];
|
|
587
|
+
return [toastItem, ...toasts];
|
|
588
|
+
});
|
|
589
|
+
});
|
|
590
|
+
});
|
|
591
|
+
return { toasts: activeToasts };
|
|
592
|
+
}
|
|
593
|
+
function createToastTheme(theme) {
|
|
594
|
+
if (theme !== "system") return theme;
|
|
595
|
+
return typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
596
|
+
}
|
|
597
|
+
function ToastBody(props) {
|
|
598
|
+
const classNames = () => props.classNames;
|
|
599
|
+
const toastClassNames = () => props.toastClassNames;
|
|
600
|
+
const toastType = () => props.toast.type;
|
|
601
|
+
const hasCustomContent = () => Boolean(props.toast.jsx);
|
|
602
|
+
const hasIcon = () => {
|
|
603
|
+
const type = toastType();
|
|
604
|
+
const typeIcon = isToastIconType(type) ? props.icons?.[type] : void 0;
|
|
605
|
+
return (type !== void 0 || Boolean(props.toast.icon) || props.toast.promise !== void 0) && props.toast.icon !== null && (typeIcon !== null || Boolean(props.toast.icon));
|
|
606
|
+
};
|
|
607
|
+
const loadingIconContent = () => {
|
|
608
|
+
if (toastType() === "loading") return props.toast.icon ?? props.getLoadingIcon();
|
|
609
|
+
if (props.toast.promise) return props.getLoadingIcon();
|
|
610
|
+
return null;
|
|
611
|
+
};
|
|
612
|
+
return [
|
|
613
|
+
createComponent(Show, {
|
|
614
|
+
get when() {
|
|
615
|
+
return memo(() => {
|
|
616
|
+
return !!(props.closeButton && !hasCustomContent());
|
|
617
|
+
})() ? toastType() !== "loading" : props.closeButton && !hasCustomContent();
|
|
618
|
+
},
|
|
619
|
+
get children() {
|
|
620
|
+
var _el$2 = getNextElement(_tmpl$2);
|
|
621
|
+
_el$2._$$click = () => {
|
|
622
|
+
if (props.disabled || !props.dismissible) return;
|
|
623
|
+
props.onDelete();
|
|
624
|
+
props.onDismiss();
|
|
625
|
+
};
|
|
626
|
+
_el$2._$$pointerup = (event) => {
|
|
627
|
+
event.stopPropagation();
|
|
628
|
+
};
|
|
629
|
+
_el$2._$$pointerdown = (event) => {
|
|
630
|
+
event.stopPropagation();
|
|
631
|
+
};
|
|
632
|
+
insert(_el$2, scope(() => {
|
|
633
|
+
return props.icons?.close ?? createComponent(CloseIcon, {});
|
|
634
|
+
}));
|
|
635
|
+
effect(() => {
|
|
636
|
+
return {
|
|
637
|
+
e: props.closeButtonAriaLabel ?? "Close toast",
|
|
638
|
+
t: String(props.disabled),
|
|
639
|
+
a: readShallow(cn(classNames()?.closeButton, toastClassNames()?.closeButton))
|
|
640
|
+
};
|
|
641
|
+
}, ({ e, t, a }, _p$) => {
|
|
642
|
+
e !== _p$?.e && setAttribute(_el$2, "aria-label", e);
|
|
643
|
+
t !== _p$?.t && setAttribute(_el$2, "data-disabled", t);
|
|
644
|
+
className(_el$2, a, _p$?.a);
|
|
645
|
+
});
|
|
646
|
+
runHydrationEvents();
|
|
647
|
+
return _el$2;
|
|
648
|
+
}
|
|
649
|
+
}),
|
|
650
|
+
createComponent(Show, {
|
|
651
|
+
get when() {
|
|
652
|
+
return hasIcon();
|
|
653
|
+
},
|
|
654
|
+
get children() {
|
|
655
|
+
var _el$3 = getNextElement(_tmpl$3);
|
|
656
|
+
var _el$4 = _el$3.firstChild;
|
|
657
|
+
var [_el$5, _el$6] = getNextMarker(_el$4.nextSibling);
|
|
658
|
+
var _el$7 = _el$5.nextSibling;
|
|
659
|
+
var [_el$8, _el$9] = getNextMarker(_el$7.nextSibling);
|
|
660
|
+
insert(_el$3, scope(() => {
|
|
661
|
+
return loadingIconContent();
|
|
662
|
+
}), _el$5, _el$6);
|
|
663
|
+
insert(_el$3, scope((() => {
|
|
664
|
+
var _c$ = memo(() => {
|
|
665
|
+
return toastType() === "loading";
|
|
666
|
+
});
|
|
667
|
+
return () => {
|
|
668
|
+
return _c$() ? null : props.getIcon();
|
|
669
|
+
};
|
|
670
|
+
})()), _el$8, _el$9);
|
|
671
|
+
effect(() => readShallow(cn(classNames()?.icon, toastClassNames()?.icon)), (_v$, _$p) => {
|
|
672
|
+
className(_el$3, _v$, _$p);
|
|
673
|
+
});
|
|
674
|
+
return _el$3;
|
|
675
|
+
}
|
|
676
|
+
}),
|
|
677
|
+
(() => {
|
|
678
|
+
var _el$10 = getNextElement(_tmpl$5);
|
|
679
|
+
var _el$11 = _el$10.firstChild;
|
|
680
|
+
var _el$13 = _el$11.nextSibling;
|
|
681
|
+
var [_el$14, _el$15] = getNextMarker(_el$13.nextSibling);
|
|
682
|
+
insert(_el$11, scope(() => {
|
|
683
|
+
return props.toast.jsx ?? resolveContent(props.toast.title);
|
|
684
|
+
}));
|
|
685
|
+
insert(_el$10, createComponent(Show, {
|
|
686
|
+
get when() {
|
|
687
|
+
return props.toast.description;
|
|
688
|
+
},
|
|
689
|
+
get children() {
|
|
690
|
+
var _el$12 = getNextElement(_tmpl$4);
|
|
691
|
+
insert(_el$12, scope(() => {
|
|
692
|
+
return resolveContent(props.toast.description);
|
|
693
|
+
}));
|
|
694
|
+
effect(() => readShallow(cn(props.descriptionClassName, props.toastDescriptionClassName, classNames()?.description, toastClassNames()?.description)), (_v$, _$p) => {
|
|
695
|
+
className(_el$12, _v$, _$p);
|
|
696
|
+
});
|
|
697
|
+
return _el$12;
|
|
698
|
+
}
|
|
699
|
+
}), _el$14, _el$15);
|
|
700
|
+
effect(() => {
|
|
701
|
+
return {
|
|
702
|
+
e: readShallow(cn(classNames()?.content, toastClassNames()?.content)),
|
|
703
|
+
t: readShallow(cn(classNames()?.title, toastClassNames()?.title))
|
|
704
|
+
};
|
|
705
|
+
}, ({ e, t }, _p$) => {
|
|
706
|
+
className(_el$10, e, _p$?.e);
|
|
707
|
+
className(_el$11, t, _p$?.t);
|
|
708
|
+
});
|
|
709
|
+
return _el$10;
|
|
710
|
+
})(),
|
|
711
|
+
createComponent(Show, {
|
|
712
|
+
get when() {
|
|
713
|
+
return props.toast.cancel;
|
|
714
|
+
},
|
|
715
|
+
children: (cancel) => createComponent(Show, {
|
|
716
|
+
get when() {
|
|
717
|
+
return !isAction(cancel());
|
|
718
|
+
},
|
|
719
|
+
get fallback() {
|
|
720
|
+
return createComponent(ToastActionButton, {
|
|
721
|
+
get content() {
|
|
722
|
+
return cancel();
|
|
723
|
+
},
|
|
724
|
+
kind: "cancel",
|
|
725
|
+
get style() {
|
|
726
|
+
return props.toast.cancelButtonStyle ?? props.cancelButtonStyle;
|
|
727
|
+
},
|
|
728
|
+
get "class"() {
|
|
729
|
+
return cn(classNames()?.cancelButton, toastClassNames()?.cancelButton);
|
|
730
|
+
},
|
|
731
|
+
onClick: (event) => {
|
|
732
|
+
if (!props.dismissible) return;
|
|
733
|
+
const currentCancel = cancel();
|
|
734
|
+
if (!isAction(currentCancel)) return;
|
|
735
|
+
currentCancel.onClick?.(event);
|
|
736
|
+
props.onDelete();
|
|
737
|
+
}
|
|
738
|
+
});
|
|
739
|
+
},
|
|
740
|
+
get children() {
|
|
741
|
+
return getNonActionContent(cancel());
|
|
742
|
+
}
|
|
743
|
+
})
|
|
744
|
+
}),
|
|
745
|
+
createComponent(Show, {
|
|
746
|
+
get when() {
|
|
747
|
+
return props.toast.action;
|
|
748
|
+
},
|
|
749
|
+
children: (action) => createComponent(Show, {
|
|
750
|
+
get when() {
|
|
751
|
+
return !isAction(action());
|
|
752
|
+
},
|
|
753
|
+
get fallback() {
|
|
754
|
+
return createComponent(ToastActionButton, {
|
|
755
|
+
get content() {
|
|
756
|
+
return action();
|
|
757
|
+
},
|
|
758
|
+
kind: "action",
|
|
759
|
+
get style() {
|
|
760
|
+
return props.toast.actionButtonStyle ?? props.actionButtonStyle;
|
|
761
|
+
},
|
|
762
|
+
get "class"() {
|
|
763
|
+
return cn(classNames()?.actionButton, toastClassNames()?.actionButton);
|
|
764
|
+
},
|
|
765
|
+
onClick: (event) => {
|
|
766
|
+
const currentAction = action();
|
|
767
|
+
if (!isAction(currentAction)) return;
|
|
768
|
+
currentAction.onClick?.(event);
|
|
769
|
+
if (event.defaultPrevented) return;
|
|
770
|
+
props.onDelete();
|
|
771
|
+
}
|
|
772
|
+
});
|
|
773
|
+
},
|
|
774
|
+
get children() {
|
|
775
|
+
return getNonActionContent(action());
|
|
776
|
+
}
|
|
777
|
+
})
|
|
778
|
+
})
|
|
779
|
+
];
|
|
780
|
+
}
|
|
781
|
+
function setupToastEffects({ props, mounted, getToastElement, isRemoving, isDocumentHidden, duration, removed, deleteToast, setInitialHeight }) {
|
|
782
|
+
let remainingTime = TOAST_LIFETIME;
|
|
783
|
+
createRenderEffect(() => ({
|
|
784
|
+
mounted: mounted(),
|
|
785
|
+
position: props.toast.position,
|
|
786
|
+
toastId: props.toast.id,
|
|
787
|
+
toasterId: props.toast.toasterId
|
|
788
|
+
}), (metadata) => {
|
|
789
|
+
const toastElement = getToastElement();
|
|
790
|
+
if (!metadata.mounted || !toastElement) return;
|
|
791
|
+
const measure = () => {
|
|
792
|
+
const currentElement = getToastElement();
|
|
793
|
+
if (!currentElement || isRemoving()) return;
|
|
794
|
+
const originalHeight = currentElement.style.height;
|
|
795
|
+
currentElement.style.height = "auto";
|
|
796
|
+
const { height } = currentElement.getBoundingClientRect();
|
|
797
|
+
currentElement.style.height = originalHeight;
|
|
798
|
+
setInitialHeight(height);
|
|
799
|
+
props.setHeights((heights) => {
|
|
800
|
+
const entry = {
|
|
801
|
+
height,
|
|
802
|
+
position: metadata.position,
|
|
803
|
+
toastId: metadata.toastId,
|
|
804
|
+
toasterId: metadata.toasterId
|
|
805
|
+
};
|
|
806
|
+
return heights.some((item) => item.toastId === entry.toastId) ? heights.map((item) => item.toastId === entry.toastId ? entry : item) : [entry, ...heights];
|
|
807
|
+
});
|
|
808
|
+
};
|
|
809
|
+
measure();
|
|
810
|
+
const observer = new ResizeObserver(measure);
|
|
811
|
+
observer.observe(toastElement);
|
|
812
|
+
return () => {
|
|
813
|
+
observer.disconnect();
|
|
814
|
+
};
|
|
815
|
+
});
|
|
816
|
+
createEffect(() => [
|
|
817
|
+
props.expanded,
|
|
818
|
+
props.interacting,
|
|
819
|
+
props.toast.type,
|
|
820
|
+
isDocumentHidden(),
|
|
821
|
+
duration(),
|
|
822
|
+
props.pauseWhenPageIsHidden ?? true,
|
|
823
|
+
props.toast.title,
|
|
824
|
+
removed()
|
|
825
|
+
], ([expanded, interacting, type, hidden, lifetime, pauseWhenHidden, title, isRemoved], previous) => {
|
|
826
|
+
if (isRemoved || type === "loading" || lifetime === Number.POSITIVE_INFINITY) return;
|
|
827
|
+
if (!previous || previous[2] !== type || previous[4] !== lifetime || previous[6] !== title) remainingTime = lifetime;
|
|
828
|
+
if (expanded || interacting || pauseWhenHidden && hidden) return;
|
|
829
|
+
const startedAt = Date.now();
|
|
830
|
+
const timer = setTimeout(() => {
|
|
831
|
+
props.toast.onAutoClose?.(props.toast);
|
|
832
|
+
deleteToast();
|
|
833
|
+
}, Math.max(0, remainingTime));
|
|
834
|
+
return () => {
|
|
835
|
+
clearTimeout(timer);
|
|
836
|
+
remainingTime -= Date.now() - startedAt;
|
|
837
|
+
};
|
|
838
|
+
});
|
|
839
|
+
createEffect(() => props.toast.delete, (shouldDelete) => {
|
|
840
|
+
if (shouldDelete !== true) return;
|
|
841
|
+
untrack(() => {
|
|
842
|
+
deleteToast();
|
|
843
|
+
props.toast.onDismiss?.(props.toast);
|
|
844
|
+
});
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
function Toast(props) {
|
|
848
|
+
const [mounted, setMounted] = createSignal(false);
|
|
849
|
+
const [removed, setRemoved] = createSignal(false);
|
|
850
|
+
const [swiping, setSwiping] = createSignal(false);
|
|
851
|
+
const [swipeOut, setSwipeOut] = createSignal(false);
|
|
852
|
+
const [isSwiped, setIsSwiped] = createSignal(false);
|
|
853
|
+
let swipeDirection = null;
|
|
854
|
+
const [swipeOutDirection, setSwipeOutDirection] = createSignal(null);
|
|
855
|
+
const [offsetBeforeRemove, setOffsetBeforeRemove] = createSignal(0);
|
|
856
|
+
const [initialHeight, setInitialHeight] = createSignal(0);
|
|
857
|
+
let toastRef;
|
|
858
|
+
let dragStartTime = 0;
|
|
859
|
+
let pointerStart = null;
|
|
860
|
+
let removalTimer;
|
|
861
|
+
onCleanup(() => {
|
|
862
|
+
clearTimeout(removalTimer);
|
|
863
|
+
});
|
|
864
|
+
const isFront = () => props.index === 0;
|
|
865
|
+
const isVisible = () => props.index + 1 <= props.visibleToasts;
|
|
866
|
+
const toastType = () => props.toast.type;
|
|
867
|
+
const dismissible = () => props.toast.dismissible !== false;
|
|
868
|
+
const classNames = () => mergeClassNames(props.classNames, props.classes);
|
|
869
|
+
const className$1 = () => mergeClassName(props.className, props.class);
|
|
870
|
+
const descriptionClassName = () => mergeDescriptionClassName(props.descriptionClassName, props.descriptionClass);
|
|
871
|
+
const toastClassName = () => mergeClassName(props.toast.className, props.toast.class);
|
|
872
|
+
const toastDescriptionClassName = () => mergeDescriptionClassName(props.toast.descriptionClassName, props.toast.descriptionClass);
|
|
873
|
+
const toastClassNames = () => mergeClassNames(props.toast.classNames, props.toast.classes);
|
|
874
|
+
const closeButton = () => props.toast.closeButton ?? props.closeButton;
|
|
875
|
+
const duration = () => props.toast.duration ?? props.duration ?? TOAST_LIFETIME;
|
|
876
|
+
const invert = () => props.toast.invert ?? props.invert;
|
|
877
|
+
const disabled = () => toastType() === "loading";
|
|
878
|
+
const toastTypeKey = () => {
|
|
879
|
+
const type = toastType();
|
|
880
|
+
return isToastClassNameType(type) ? type : "default";
|
|
881
|
+
};
|
|
882
|
+
const swipeDirections = () => props.swipeDirections ?? getDefaultSwipeDirections(props.position);
|
|
883
|
+
const y = createMemo(() => props.position.split("-")[0]);
|
|
884
|
+
const x = createMemo(() => props.position.split("-")[1]);
|
|
885
|
+
const heightIndex = createMemo(() => Math.max(0, props.heights.findIndex((height) => height.toastId === props.toast.id)));
|
|
886
|
+
const toastsHeightBefore = createMemo(() => {
|
|
887
|
+
let total = 0;
|
|
888
|
+
for (const [index, height] of props.heights.entries()) {
|
|
889
|
+
if (index >= heightIndex()) break;
|
|
890
|
+
total += height.height;
|
|
891
|
+
}
|
|
892
|
+
return total;
|
|
893
|
+
});
|
|
894
|
+
const offset = createMemo(() => heightIndex() * (props.gap ?? GAP) + toastsHeightBefore());
|
|
895
|
+
const isDocumentHidden = createIsDocumentHidden();
|
|
896
|
+
function deleteToast() {
|
|
897
|
+
if (removalTimer !== void 0) return;
|
|
898
|
+
setRemoved(true);
|
|
899
|
+
setOffsetBeforeRemove(offset());
|
|
900
|
+
props.setHeights((heights) => heights.filter((height) => height.toastId !== props.toast.id));
|
|
901
|
+
removalTimer = setTimeout(() => {
|
|
902
|
+
props.removeToast(props.toast);
|
|
903
|
+
}, TIME_BEFORE_UNMOUNT);
|
|
904
|
+
}
|
|
905
|
+
function getLoadingIcon() {
|
|
906
|
+
if (props.icons?.loading !== void 0 && props.icons.loading !== null && props.icons.loading !== false) {
|
|
907
|
+
var _el$16 = getNextElement(_tmpl$6);
|
|
908
|
+
insert(_el$16, scope(() => {
|
|
909
|
+
return props.icons.loading;
|
|
910
|
+
}));
|
|
911
|
+
effect(() => {
|
|
912
|
+
return {
|
|
913
|
+
e: readShallow(cn(classNames()?.loader, toastClassNames()?.loader, "sonner-loader")),
|
|
914
|
+
t: String(toastType() === "loading")
|
|
915
|
+
};
|
|
916
|
+
}, ({ e, t }, _p$) => {
|
|
917
|
+
className(_el$16, e, _p$?.e);
|
|
918
|
+
t !== _p$?.t && setAttribute(_el$16, "data-visible", t);
|
|
919
|
+
});
|
|
920
|
+
return _el$16;
|
|
921
|
+
}
|
|
922
|
+
return createComponent(Loader, {
|
|
923
|
+
get "class"() {
|
|
924
|
+
return cn(classNames()?.loader, toastClassNames()?.loader);
|
|
925
|
+
},
|
|
926
|
+
get visible() {
|
|
927
|
+
return toastType() === "loading";
|
|
928
|
+
}
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
const icon = () => {
|
|
932
|
+
const type = toastType();
|
|
933
|
+
return props.toast.icon ?? (isToastIconType(type) ? props.icons?.[type] : void 0) ?? getAsset(type);
|
|
934
|
+
};
|
|
935
|
+
onSettled(() => {
|
|
936
|
+
setMounted(true);
|
|
937
|
+
});
|
|
938
|
+
setupToastEffects({
|
|
939
|
+
deleteToast,
|
|
940
|
+
duration,
|
|
941
|
+
getToastElement: () => toastRef,
|
|
942
|
+
isDocumentHidden,
|
|
943
|
+
isRemoving: () => removalTimer !== void 0,
|
|
944
|
+
mounted,
|
|
945
|
+
props,
|
|
946
|
+
removed,
|
|
947
|
+
setInitialHeight
|
|
948
|
+
});
|
|
949
|
+
function handleDragEnd() {
|
|
950
|
+
setSwiping(false);
|
|
951
|
+
swipeDirection = null;
|
|
952
|
+
pointerStart = null;
|
|
953
|
+
}
|
|
954
|
+
function handlePointerDown(event) {
|
|
955
|
+
if (event.button === 2 || disabled() || !dismissible()) return;
|
|
956
|
+
if (event.target instanceof Element && event.target.closest("button")) return;
|
|
957
|
+
dragStartTime = Date.now();
|
|
958
|
+
setOffsetBeforeRemove(offset());
|
|
959
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
960
|
+
setSwiping(true);
|
|
961
|
+
pointerStart = {
|
|
962
|
+
x: event.clientX,
|
|
963
|
+
y: event.clientY
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
function handlePointerUp() {
|
|
967
|
+
if (swipeOut() || !dismissible()) return;
|
|
968
|
+
pointerStart = null;
|
|
969
|
+
const amountX = Number(toastRef?.style.getPropertyValue("--swipe-amount-x").replace("px", "") ?? 0);
|
|
970
|
+
const amountY = Number(toastRef?.style.getPropertyValue("--swipe-amount-y").replace("px", "") ?? 0);
|
|
971
|
+
const timeTaken = Math.max(1, Date.now() - dragStartTime);
|
|
972
|
+
const direction = getSwipeDismissDirection(swipeDirection, amountX, amountY, timeTaken, swipeDirections());
|
|
973
|
+
if (direction) {
|
|
974
|
+
setOffsetBeforeRemove(offset());
|
|
975
|
+
props.toast.onDismiss?.(props.toast);
|
|
976
|
+
setSwipeOutDirection(direction);
|
|
977
|
+
deleteToast();
|
|
978
|
+
setSwipeOut(true);
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
981
|
+
toastRef?.style.setProperty("--swipe-amount-x", "0px");
|
|
982
|
+
toastRef?.style.setProperty("--swipe-amount-y", "0px");
|
|
983
|
+
setIsSwiped(false);
|
|
984
|
+
setSwiping(false);
|
|
985
|
+
swipeDirection = null;
|
|
986
|
+
}
|
|
987
|
+
function handlePointerMove(event) {
|
|
988
|
+
const start = pointerStart;
|
|
989
|
+
if (!start || !dismissible() || Boolean(window.getSelection()?.toString())) return;
|
|
990
|
+
const xDelta = event.clientX - start.x;
|
|
991
|
+
const yDelta = event.clientY - start.y;
|
|
992
|
+
if (!swipeDirection && (Math.abs(xDelta) > 1 || Math.abs(yDelta) > 1)) swipeDirection = Math.abs(xDelta) > Math.abs(yDelta) ? "x" : "y";
|
|
993
|
+
const amount = getSwipeAmount(swipeDirection, xDelta, yDelta, swipeDirections());
|
|
994
|
+
if (amount.x !== 0 || amount.y !== 0) setIsSwiped(true);
|
|
995
|
+
toastRef?.style.setProperty("--swipe-amount-x", `${amount.x}px`);
|
|
996
|
+
toastRef?.style.setProperty("--swipe-amount-y", `${amount.y}px`);
|
|
997
|
+
}
|
|
998
|
+
var _el$17 = getNextElement(_tmpl$7);
|
|
999
|
+
_el$17._$$pointermove = handlePointerMove;
|
|
1000
|
+
_el$17._$$pointerup = handlePointerUp;
|
|
1001
|
+
_el$17._$$pointerdown = handlePointerDown;
|
|
1002
|
+
_el$17.addEventListener("dragend", handleDragEnd);
|
|
1003
|
+
ref(() => {
|
|
1004
|
+
return (element) => {
|
|
1005
|
+
toastRef = element;
|
|
1006
|
+
};
|
|
1007
|
+
}, _el$17);
|
|
1008
|
+
insert(_el$17, createComponent(ToastBody, {
|
|
1009
|
+
get actionButtonStyle() {
|
|
1010
|
+
return props.actionButtonStyle;
|
|
1011
|
+
},
|
|
1012
|
+
get cancelButtonStyle() {
|
|
1013
|
+
return props.cancelButtonStyle;
|
|
1014
|
+
},
|
|
1015
|
+
get classNames() {
|
|
1016
|
+
return classNames();
|
|
1017
|
+
},
|
|
1018
|
+
get closeButton() {
|
|
1019
|
+
return closeButton();
|
|
1020
|
+
},
|
|
1021
|
+
get closeButtonAriaLabel() {
|
|
1022
|
+
return props.closeButtonAriaLabel;
|
|
1023
|
+
},
|
|
1024
|
+
get descriptionClassName() {
|
|
1025
|
+
return descriptionClassName();
|
|
1026
|
+
},
|
|
1027
|
+
get disabled() {
|
|
1028
|
+
return disabled();
|
|
1029
|
+
},
|
|
1030
|
+
get dismissible() {
|
|
1031
|
+
return dismissible();
|
|
1032
|
+
},
|
|
1033
|
+
getIcon: icon,
|
|
1034
|
+
getLoadingIcon,
|
|
1035
|
+
get icons() {
|
|
1036
|
+
return props.icons;
|
|
1037
|
+
},
|
|
1038
|
+
onDelete: deleteToast,
|
|
1039
|
+
onDismiss: () => props.toast.onDismiss?.(props.toast),
|
|
1040
|
+
get toast() {
|
|
1041
|
+
return props.toast;
|
|
1042
|
+
},
|
|
1043
|
+
get toastClassNames() {
|
|
1044
|
+
return toastClassNames();
|
|
1045
|
+
},
|
|
1046
|
+
get toastDescriptionClassName() {
|
|
1047
|
+
return toastDescriptionClassName();
|
|
1048
|
+
}
|
|
1049
|
+
}));
|
|
1050
|
+
effect(() => {
|
|
1051
|
+
return {
|
|
1052
|
+
e: readShallow(cn(className$1(), toastClassName(), classNames()?.toast, toastClassNames()?.toast, classNames()?.[toastTypeKey()], toastClassNames()?.[toastTypeKey()])),
|
|
1053
|
+
t: String(Boolean(props.toast.richColors ?? props.defaultRichColors)),
|
|
1054
|
+
a: String((props.toast.jsx === void 0 || props.toast.jsx === null || props.toast.jsx === false || props.toast.jsx === 0 || props.toast.jsx === "") && props.toast.unstyled !== true && props.unstyled !== true),
|
|
1055
|
+
o: String(mounted()),
|
|
1056
|
+
i: String(Boolean(props.toast.promise)),
|
|
1057
|
+
n: String(isSwiped()),
|
|
1058
|
+
s: String(removed()),
|
|
1059
|
+
h: String(isVisible()),
|
|
1060
|
+
r: y(),
|
|
1061
|
+
d: x(),
|
|
1062
|
+
l: props.index,
|
|
1063
|
+
u: String(isFront()),
|
|
1064
|
+
c: String(swiping()),
|
|
1065
|
+
w: String(dismissible()),
|
|
1066
|
+
m: toastType(),
|
|
1067
|
+
f: String(invert()),
|
|
1068
|
+
y: String(swipeOut()),
|
|
1069
|
+
g: swipeOutDirection(),
|
|
1070
|
+
p: String(props.expanded || props.expandByDefault && mounted()),
|
|
1071
|
+
b: props.toast.testId,
|
|
1072
|
+
T: {
|
|
1073
|
+
"--index": props.index,
|
|
1074
|
+
"--initial-height": props.expandByDefault ? "auto" : `${initialHeight()}px`,
|
|
1075
|
+
"--offset": `${removed() ? offsetBeforeRemove() : offset()}px`,
|
|
1076
|
+
"--toasts-before": props.index,
|
|
1077
|
+
"--z-index": props.toasts.length - props.index,
|
|
1078
|
+
...props.style,
|
|
1079
|
+
...props.toast.style
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
}, ({ e, t, a, o, i, n, s, h, r, d, l, u, c, w, m, f, y, g, p, b, T }, _p$) => {
|
|
1083
|
+
className(_el$17, e, _p$?.e);
|
|
1084
|
+
t !== _p$?.t && setAttribute(_el$17, "data-rich-colors", t);
|
|
1085
|
+
a !== _p$?.a && setAttribute(_el$17, "data-styled", a);
|
|
1086
|
+
o !== _p$?.o && setAttribute(_el$17, "data-mounted", o);
|
|
1087
|
+
i !== _p$?.i && setAttribute(_el$17, "data-promise", i);
|
|
1088
|
+
n !== _p$?.n && setAttribute(_el$17, "data-swiped", n);
|
|
1089
|
+
s !== _p$?.s && setAttribute(_el$17, "data-removed", s);
|
|
1090
|
+
h !== _p$?.h && setAttribute(_el$17, "data-visible", h);
|
|
1091
|
+
r !== _p$?.r && setAttribute(_el$17, "data-y-position", r);
|
|
1092
|
+
d !== _p$?.d && setAttribute(_el$17, "data-x-position", d);
|
|
1093
|
+
l !== _p$?.l && setAttribute(_el$17, "data-index", l);
|
|
1094
|
+
u !== _p$?.u && setAttribute(_el$17, "data-front", u);
|
|
1095
|
+
c !== _p$?.c && setAttribute(_el$17, "data-swiping", c);
|
|
1096
|
+
w !== _p$?.w && setAttribute(_el$17, "data-dismissible", w);
|
|
1097
|
+
m !== _p$?.m && setAttribute(_el$17, "data-type", m);
|
|
1098
|
+
f !== _p$?.f && setAttribute(_el$17, "data-invert", f);
|
|
1099
|
+
y !== _p$?.y && setAttribute(_el$17, "data-swipe-out", y);
|
|
1100
|
+
g !== _p$?.g && setAttribute(_el$17, "data-swipe-direction", g);
|
|
1101
|
+
p !== _p$?.p && setAttribute(_el$17, "data-expanded", p);
|
|
1102
|
+
b !== _p$?.b && setAttribute(_el$17, "data-testid", b);
|
|
1103
|
+
style(_el$17, T, _p$?.T);
|
|
1104
|
+
});
|
|
1105
|
+
runHydrationEvents();
|
|
1106
|
+
return _el$17;
|
|
1107
|
+
}
|
|
1108
|
+
function Toaster(props) {
|
|
1109
|
+
const propsWithDefaults = merge({
|
|
1110
|
+
containerAriaLabel: "Notifications",
|
|
1111
|
+
dir: getDocumentDirection(),
|
|
1112
|
+
gap: GAP,
|
|
1113
|
+
hotkey: ["altKey", "KeyT"],
|
|
1114
|
+
position: "bottom-right",
|
|
1115
|
+
theme: "light",
|
|
1116
|
+
visibleToasts: VISIBLE_TOASTS_AMOUNT
|
|
1117
|
+
}, props);
|
|
1118
|
+
const initialTheme = untrack(() => createToastTheme(propsWithDefaults.theme));
|
|
1119
|
+
const [toastsStore, setToastsStore] = createStore({ toasts: [] });
|
|
1120
|
+
const filteredToasts = createMemo(() => {
|
|
1121
|
+
const { toasts } = toastsStore;
|
|
1122
|
+
if (propsWithDefaults.id !== void 0 && propsWithDefaults.id !== "") return toasts.filter((toast) => toast.toasterId === propsWithDefaults.id);
|
|
1123
|
+
return toasts.filter((toast) => toast.toasterId === void 0 || toast.toasterId === "");
|
|
1124
|
+
});
|
|
1125
|
+
const possiblePositions = createMemo(() => [.../* @__PURE__ */ new Set([propsWithDefaults.position, ...filteredToasts().filter((toast) => toast.position !== void 0).map((toast) => toast.position)])]);
|
|
1126
|
+
const [heights, setHeights] = createSignal([]);
|
|
1127
|
+
const [expanded, setExpanded] = createSignal(false);
|
|
1128
|
+
const [interacting, setInteracting] = createSignal(false);
|
|
1129
|
+
const [actualTheme, setActualTheme] = createSignal(initialTheme);
|
|
1130
|
+
const [lastFocusedElementRef, setLastFocusedElementRef] = createSignal(null);
|
|
1131
|
+
const [isFocusWithinRef, setIsFocusWithinRef] = createSignal(false);
|
|
1132
|
+
let listRef;
|
|
1133
|
+
const hotkeyLabel = () => propsWithDefaults.hotkey.join("+").replaceAll("Key", "").replaceAll("Digit", "");
|
|
1134
|
+
const className$2 = () => mergeClassName(propsWithDefaults.className, propsWithDefaults.class);
|
|
1135
|
+
const toastOptions = () => propsWithDefaults.toastOptions;
|
|
1136
|
+
const toastClassNames = () => mergeClassNames(toastOptions()?.classNames, toastOptions()?.classes);
|
|
1137
|
+
const toastDescriptionClassName = () => mergeDescriptionClassName(toastOptions()?.descriptionClassName, toastOptions()?.descriptionClass);
|
|
1138
|
+
const toastClassName = () => mergeClassName(toastOptions()?.className, toastOptions()?.class);
|
|
1139
|
+
const removeToast = (toastToRemove) => {
|
|
1140
|
+
if (!untrack(() => toastsStore.toasts.find((toast) => toast.id === toastToRemove.id)?.delete === true)) ToastState.dismiss(toastToRemove.id);
|
|
1141
|
+
setToastsStore((draft) => {
|
|
1142
|
+
draft.toasts = draft.toasts.filter(({ id }) => id !== toastToRemove.id);
|
|
1143
|
+
});
|
|
1144
|
+
};
|
|
1145
|
+
onSettled(() => ToastState.subscribe((toastItem) => {
|
|
1146
|
+
setToastsStore((draft) => {
|
|
1147
|
+
if ("dismiss" in toastItem) {
|
|
1148
|
+
const existing = draft.toasts.find((toast) => toast.id === toastItem.id);
|
|
1149
|
+
if (existing) existing.delete = true;
|
|
1150
|
+
return;
|
|
1151
|
+
}
|
|
1152
|
+
const index = draft.toasts.findIndex((toast) => toast.id === toastItem.id);
|
|
1153
|
+
const existing = draft.toasts[index];
|
|
1154
|
+
if (existing === void 0) draft.toasts.unshift(toastItem);
|
|
1155
|
+
else if (existing.delete === true) draft.toasts[index] = toastItem;
|
|
1156
|
+
else Object.assign(existing, toastItem);
|
|
1157
|
+
});
|
|
1158
|
+
}));
|
|
1159
|
+
createEffect(() => propsWithDefaults.theme, (theme) => {
|
|
1160
|
+
if (theme !== "system") {
|
|
1161
|
+
setActualTheme(theme);
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
if (typeof window === "undefined") return;
|
|
1165
|
+
const query = window.matchMedia("(prefers-color-scheme: dark)");
|
|
1166
|
+
const updateTheme = () => {
|
|
1167
|
+
setActualTheme(query.matches ? "dark" : "light");
|
|
1168
|
+
};
|
|
1169
|
+
updateTheme();
|
|
1170
|
+
query.addEventListener("change", updateTheme);
|
|
1171
|
+
return () => {
|
|
1172
|
+
query.removeEventListener("change", updateTheme);
|
|
1173
|
+
};
|
|
1174
|
+
});
|
|
1175
|
+
createEffect(() => filteredToasts().length, (length) => {
|
|
1176
|
+
if (length <= 1) setExpanded(false);
|
|
1177
|
+
});
|
|
1178
|
+
function handleKeyDown(event) {
|
|
1179
|
+
const modifierKeys = /* @__PURE__ */ new Map([
|
|
1180
|
+
["altKey", event.altKey],
|
|
1181
|
+
["ctrlKey", event.ctrlKey],
|
|
1182
|
+
["metaKey", event.metaKey],
|
|
1183
|
+
["shiftKey", event.shiftKey]
|
|
1184
|
+
]);
|
|
1185
|
+
if (propsWithDefaults.hotkey.length > 0 && propsWithDefaults.hotkey.every((key) => modifierKeys.get(key) === true || event.code === key)) {
|
|
1186
|
+
setExpanded(true);
|
|
1187
|
+
listRef?.focus();
|
|
1188
|
+
}
|
|
1189
|
+
if (event.code === "Escape" && (document.activeElement === listRef || listRef?.contains(document.activeElement) === true)) setExpanded(false);
|
|
1190
|
+
}
|
|
1191
|
+
onSettled(() => {
|
|
1192
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
1193
|
+
return () => {
|
|
1194
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
1195
|
+
};
|
|
1196
|
+
});
|
|
1197
|
+
onCleanup(() => {
|
|
1198
|
+
if (lastFocusedElementRef()) lastFocusedElementRef()?.focus({ preventScroll: true });
|
|
1199
|
+
});
|
|
1200
|
+
var _el$18 = getNextElement(_tmpl$8);
|
|
1201
|
+
insert(_el$18, createComponent(For, {
|
|
1202
|
+
get each() {
|
|
1203
|
+
return possiblePositions();
|
|
1204
|
+
},
|
|
1205
|
+
children: (position, index) => {
|
|
1206
|
+
const [y, x] = position.split("-");
|
|
1207
|
+
const toastsByPosition = createMemo(() => filteredToasts().filter((toast) => !toast.position && index() === 0 || toast.position === position));
|
|
1208
|
+
const heightsByPosition = createMemo(() => heights().filter((height) => index() === 0 && !height.position || height.position === position));
|
|
1209
|
+
return createComponent(Show, {
|
|
1210
|
+
get when() {
|
|
1211
|
+
return filteredToasts().length > 0;
|
|
1212
|
+
},
|
|
1213
|
+
get children() {
|
|
1214
|
+
var _el$19 = getNextElement(_tmpl$9);
|
|
1215
|
+
_el$19._$$pointerup = () => {
|
|
1216
|
+
setInteracting(false);
|
|
1217
|
+
};
|
|
1218
|
+
_el$19._$$pointerdown = (event) => {
|
|
1219
|
+
if (event.target instanceof HTMLElement && event.target.dataset.dismissible === "false") return;
|
|
1220
|
+
setInteracting(true);
|
|
1221
|
+
};
|
|
1222
|
+
_el$19.addEventListener("dragend", () => {
|
|
1223
|
+
setExpanded(false);
|
|
1224
|
+
});
|
|
1225
|
+
_el$19.addEventListener("mouseleave", () => {
|
|
1226
|
+
if (!interacting()) setExpanded(false);
|
|
1227
|
+
});
|
|
1228
|
+
_el$19._$$mousemove = () => {
|
|
1229
|
+
setExpanded(true);
|
|
1230
|
+
};
|
|
1231
|
+
_el$19.addEventListener("mouseenter", () => {
|
|
1232
|
+
setExpanded(true);
|
|
1233
|
+
});
|
|
1234
|
+
_el$19.addEventListener("focus", (event) => {
|
|
1235
|
+
if (event.target instanceof HTMLElement && event.target.dataset.dismissible === "false") return;
|
|
1236
|
+
if (!isFocusWithinRef()) {
|
|
1237
|
+
setIsFocusWithinRef(true);
|
|
1238
|
+
setLastFocusedElementRef(event.relatedTarget instanceof HTMLElement ? event.relatedTarget : null);
|
|
1239
|
+
}
|
|
1240
|
+
});
|
|
1241
|
+
_el$19.addEventListener("blur", (event) => {
|
|
1242
|
+
if (isFocusWithinRef() && (!(event.relatedTarget instanceof Node) || !event.currentTarget.contains(event.relatedTarget))) {
|
|
1243
|
+
setIsFocusWithinRef(false);
|
|
1244
|
+
if (lastFocusedElementRef()) {
|
|
1245
|
+
lastFocusedElementRef()?.focus({ preventScroll: true });
|
|
1246
|
+
setLastFocusedElementRef(null);
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
});
|
|
1250
|
+
setAttribute(_el$19, "data-y-position", y);
|
|
1251
|
+
setAttribute(_el$19, "data-x-position", x);
|
|
1252
|
+
ref(() => {
|
|
1253
|
+
return (element) => {
|
|
1254
|
+
listRef = element;
|
|
1255
|
+
};
|
|
1256
|
+
}, _el$19);
|
|
1257
|
+
insert(_el$19, createComponent(For, {
|
|
1258
|
+
get each() {
|
|
1259
|
+
return toastsByPosition();
|
|
1260
|
+
},
|
|
1261
|
+
children: (toastItem, toastIndex) => createComponent(Toast, {
|
|
1262
|
+
get icons() {
|
|
1263
|
+
return propsWithDefaults.icons;
|
|
1264
|
+
},
|
|
1265
|
+
get index() {
|
|
1266
|
+
return toastIndex();
|
|
1267
|
+
},
|
|
1268
|
+
toast: toastItem,
|
|
1269
|
+
get defaultRichColors() {
|
|
1270
|
+
return propsWithDefaults.richColors;
|
|
1271
|
+
},
|
|
1272
|
+
get duration() {
|
|
1273
|
+
return toastOptions()?.duration ?? propsWithDefaults.duration;
|
|
1274
|
+
},
|
|
1275
|
+
get "class"() {
|
|
1276
|
+
return toastClassName();
|
|
1277
|
+
},
|
|
1278
|
+
get descriptionClassName() {
|
|
1279
|
+
return toastDescriptionClassName();
|
|
1280
|
+
},
|
|
1281
|
+
get invert() {
|
|
1282
|
+
return Boolean(propsWithDefaults.invert);
|
|
1283
|
+
},
|
|
1284
|
+
get visibleToasts() {
|
|
1285
|
+
return propsWithDefaults.visibleToasts;
|
|
1286
|
+
},
|
|
1287
|
+
get closeButton() {
|
|
1288
|
+
return toastOptions()?.closeButton ?? propsWithDefaults.closeButton ?? false;
|
|
1289
|
+
},
|
|
1290
|
+
get interacting() {
|
|
1291
|
+
return interacting();
|
|
1292
|
+
},
|
|
1293
|
+
position,
|
|
1294
|
+
get style() {
|
|
1295
|
+
return toastOptions()?.style;
|
|
1296
|
+
},
|
|
1297
|
+
get unstyled() {
|
|
1298
|
+
return toastOptions()?.unstyled;
|
|
1299
|
+
},
|
|
1300
|
+
get classNames() {
|
|
1301
|
+
return toastClassNames();
|
|
1302
|
+
},
|
|
1303
|
+
get cancelButtonStyle() {
|
|
1304
|
+
return toastOptions()?.cancelButtonStyle;
|
|
1305
|
+
},
|
|
1306
|
+
get actionButtonStyle() {
|
|
1307
|
+
return toastOptions()?.actionButtonStyle;
|
|
1308
|
+
},
|
|
1309
|
+
get closeButtonAriaLabel() {
|
|
1310
|
+
return toastOptions()?.closeButtonAriaLabel;
|
|
1311
|
+
},
|
|
1312
|
+
removeToast,
|
|
1313
|
+
get toasts() {
|
|
1314
|
+
return toastsByPosition();
|
|
1315
|
+
},
|
|
1316
|
+
get heights() {
|
|
1317
|
+
return heightsByPosition();
|
|
1318
|
+
},
|
|
1319
|
+
setHeights,
|
|
1320
|
+
get expandByDefault() {
|
|
1321
|
+
return Boolean(propsWithDefaults.expand);
|
|
1322
|
+
},
|
|
1323
|
+
get gap() {
|
|
1324
|
+
return propsWithDefaults.gap;
|
|
1325
|
+
},
|
|
1326
|
+
get expanded() {
|
|
1327
|
+
return expanded();
|
|
1328
|
+
},
|
|
1329
|
+
get swipeDirections() {
|
|
1330
|
+
return propsWithDefaults.swipeDirections;
|
|
1331
|
+
},
|
|
1332
|
+
get pauseWhenPageIsHidden() {
|
|
1333
|
+
return propsWithDefaults.pauseWhenPageIsHidden;
|
|
1334
|
+
}
|
|
1335
|
+
})
|
|
1336
|
+
}));
|
|
1337
|
+
effect(() => {
|
|
1338
|
+
return {
|
|
1339
|
+
e: propsWithDefaults.dir === "auto" ? getDocumentDirection() : propsWithDefaults.dir,
|
|
1340
|
+
t: readShallow(className$2()),
|
|
1341
|
+
a: actualTheme(),
|
|
1342
|
+
o: {
|
|
1343
|
+
"--front-toast-height": `${heightsByPosition()[0]?.height ?? 0}px`,
|
|
1344
|
+
"--gap": `${propsWithDefaults.gap}px`,
|
|
1345
|
+
...propsWithDefaults.style,
|
|
1346
|
+
...assignOffset(propsWithDefaults.offset, propsWithDefaults.mobileOffset)
|
|
1347
|
+
}
|
|
1348
|
+
};
|
|
1349
|
+
}, ({ e, t, a, o }, _p$) => {
|
|
1350
|
+
e !== _p$?.e && setAttribute(_el$19, "dir", e);
|
|
1351
|
+
className(_el$19, t, _p$?.t);
|
|
1352
|
+
a !== _p$?.a && setAttribute(_el$19, "data-sonner-theme", a);
|
|
1353
|
+
style(_el$19, o, _p$?.o);
|
|
1354
|
+
});
|
|
1355
|
+
runHydrationEvents();
|
|
1356
|
+
return _el$19;
|
|
1357
|
+
}
|
|
1358
|
+
});
|
|
1359
|
+
}
|
|
1360
|
+
}));
|
|
1361
|
+
effect(() => propsWithDefaults.customAriaLabel ?? `${propsWithDefaults.containerAriaLabel} ${hotkeyLabel()}`, (_v$) => {
|
|
1362
|
+
setAttribute(_el$18, "aria-label", _v$);
|
|
1363
|
+
});
|
|
1364
|
+
return _el$18;
|
|
1365
|
+
}
|
|
1366
|
+
delegateEvents([
|
|
1367
|
+
"click",
|
|
1368
|
+
"pointerdown",
|
|
1369
|
+
"pointerup",
|
|
1370
|
+
"pointermove",
|
|
1371
|
+
"mousemove"
|
|
1372
|
+
]);
|
|
1373
|
+
export { Toaster, toast, useSonner };
|
|
1374
|
+
|
|
1375
|
+
//# sourceMappingURL=index.js.map
|