sonner-vanilla 0.1.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/README.md +264 -0
- package/dist/assets.d.ts +9 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +49 -0
- package/dist/assets.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +7 -0
- package/dist/state.d.ts +60 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +212 -0
- package/dist/state.js.map +1 -0
- package/dist/stimulus.d.ts +171 -0
- package/dist/stimulus.d.ts.map +1 -0
- package/dist/stimulus.js +13 -0
- package/dist/stimulus.js.map +7 -0
- package/dist/styles.css +725 -0
- package/dist/toaster.d.ts +40 -0
- package/dist/toaster.d.ts.map +1 -0
- package/dist/toaster.js +702 -0
- package/dist/toaster.js.map +1 -0
- package/dist/types.d.ts +122 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +48 -0
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Toast state management - Observer pattern
|
|
3
|
+
* Vanilla JS port of sonner's state.ts
|
|
4
|
+
*/
|
|
5
|
+
import type { CustomContent, ExternalToast, PromiseData, PromiseT, ToastT, ToastToDismiss, ToastTypes } from './types';
|
|
6
|
+
type Subscriber = (toast: ToastT | ToastToDismiss) => void;
|
|
7
|
+
declare class Observer {
|
|
8
|
+
subscribers: Subscriber[];
|
|
9
|
+
toasts: ToastT[];
|
|
10
|
+
dismissedToasts: Set<string | number>;
|
|
11
|
+
subscribe(subscriber: Subscriber): () => void;
|
|
12
|
+
publish(data: ToastT | ToastToDismiss): void;
|
|
13
|
+
addToast(data: ToastT): void;
|
|
14
|
+
create(data: ExternalToast & {
|
|
15
|
+
message?: string;
|
|
16
|
+
type?: ToastTypes;
|
|
17
|
+
promise?: PromiseT;
|
|
18
|
+
}): number | string;
|
|
19
|
+
dismiss(id?: number | string): number | string | undefined;
|
|
20
|
+
message(message: string, data?: ExternalToast): number | string;
|
|
21
|
+
error(message: string, data?: ExternalToast): number | string;
|
|
22
|
+
success(message: string, data?: ExternalToast): number | string;
|
|
23
|
+
info(message: string, data?: ExternalToast): number | string;
|
|
24
|
+
warning(message: string, data?: ExternalToast): number | string;
|
|
25
|
+
loading(message: string, data?: ExternalToast): number | string;
|
|
26
|
+
withType(type: string, message: string, data?: ExternalToast): number | string;
|
|
27
|
+
promise<ToastData>(promise: PromiseT<ToastData>, data?: PromiseData<ToastData>): {
|
|
28
|
+
unwrap: () => Promise<ToastData>;
|
|
29
|
+
} | (number & {
|
|
30
|
+
unwrap: () => Promise<ToastData>;
|
|
31
|
+
}) | (string & {
|
|
32
|
+
unwrap: () => Promise<ToastData>;
|
|
33
|
+
}) | undefined;
|
|
34
|
+
custom(content: CustomContent, data?: ExternalToast): number | string;
|
|
35
|
+
getActiveToasts(): ToastT[];
|
|
36
|
+
}
|
|
37
|
+
export declare const ToastState: Observer;
|
|
38
|
+
export declare const toast: ((message: string, data?: ExternalToast) => number | string) & {
|
|
39
|
+
success: (message: string, data?: ExternalToast) => number | string;
|
|
40
|
+
info: (message: string, data?: ExternalToast) => number | string;
|
|
41
|
+
warning: (message: string, data?: ExternalToast) => number | string;
|
|
42
|
+
error: (message: string, data?: ExternalToast) => number | string;
|
|
43
|
+
message: (message: string, data?: ExternalToast) => number | string;
|
|
44
|
+
promise: <ToastData>(promise: PromiseT<ToastData>, data?: PromiseData<ToastData>) => {
|
|
45
|
+
unwrap: () => Promise<ToastData>;
|
|
46
|
+
} | (number & {
|
|
47
|
+
unwrap: () => Promise<ToastData>;
|
|
48
|
+
}) | (string & {
|
|
49
|
+
unwrap: () => Promise<ToastData>;
|
|
50
|
+
}) | undefined;
|
|
51
|
+
dismiss: (id?: number | string) => number | string | undefined;
|
|
52
|
+
loading: (message: string, data?: ExternalToast) => number | string;
|
|
53
|
+
custom: (content: CustomContent, data?: ExternalToast) => number | string;
|
|
54
|
+
withType: (type: string, message: string, data?: ExternalToast) => number | string;
|
|
55
|
+
} & {
|
|
56
|
+
getHistory: () => ToastT[];
|
|
57
|
+
getToasts: () => ToastT[];
|
|
58
|
+
};
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,WAAW,EACX,QAAQ,EACR,MAAM,EACN,cAAc,EACd,UAAU,EACX,MAAM,SAAS,CAAC;AAIjB,KAAK,UAAU,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,KAAK,IAAI,CAAC;AAE3D,cAAM,QAAQ;IACZ,WAAW,EAAE,UAAU,EAAE,CAAM;IAC/B,MAAM,EAAE,MAAM,EAAE,CAAM;IACtB,eAAe,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,CAAa;IAElD,SAAS,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,IAAI;IAQ7C,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI;IAI5C,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAK5B,MAAM,CACJ,IAAI,EAAE,aAAa,GAAG;QACpB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,CAAC,EAAE,UAAU,CAAC;QAClB,OAAO,CAAC,EAAE,QAAQ,CAAC;KACpB,GACA,MAAM,GAAG,MAAM;IAkClB,OAAO,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS;IAc1D,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,M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,aAAa,KAAG,MAAM,GAAG,MAAM;oBAIjD,MAAM,SAAS,aAAa,KAAG,MAAM,GAAG,MAAM;uBAI3C,MAAM,SAAS,aAAa,KAAG,MAAM,GAAG,MAAM;qBAZhD,MAAM,SAAS,aAAa,KAAG,MAAM,GAAG,MAAM;uBAJ5C,MAAM,SAAS,aAAa,KAAG,MAAM,GAAG,MAAM;cA6BvD,SAAS,WACN,QAAQ,CAAC,SAAS,CAAC,SACrB,WAAW,CAAC,SAAS,CAAC,KAC5B;QAAE,MAAM,EAAE,MAAM,OAAO,CAAC,SAAS,CAAC,CAAA;KAAE,GAAG,CAAC,MAAM,GAAG;QAAE,MAAM,EAAE,MAAM,OAAO,CAAC,SAAS,CAAC,CAAA;KAAE,CAAC,GAAG,CAAC,MAAM,GAAG;QAAE,MAAM,EAAE,MAAM,OAAO,CAAC,SAAS,CAAC,CAAA;KAAE,CAAC,GAAG,SAAS;mBA9C1I,MAAM,GAAG,MAAM,KAAG,MAAM,GAAG,MAAM,GAAG,SAAS;uBAkCzC,MAAM,SAAS,aAAa,KAAG,MAAM,GAAG,MAAM;sBAsG/C,aAAa,SAAS,aAAa,KAAG,MAAM,GAAG,MAAM;qBAjGtD,MAAM,WAAW,MAAM,SAAS,aAAa,KAAG,MAAM,GAAG,MAAM;;;;CA2J/E,CAAC"}
|
package/dist/state.js
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Toast state management - Observer pattern
|
|
3
|
+
* Vanilla JS port of sonner's state.ts
|
|
4
|
+
*/
|
|
5
|
+
let toastsCounter = 1;
|
|
6
|
+
class Observer {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.subscribers = [];
|
|
9
|
+
this.toasts = [];
|
|
10
|
+
this.dismissedToasts = new Set();
|
|
11
|
+
}
|
|
12
|
+
subscribe(subscriber) {
|
|
13
|
+
this.subscribers.push(subscriber);
|
|
14
|
+
return () => {
|
|
15
|
+
const index = this.subscribers.indexOf(subscriber);
|
|
16
|
+
this.subscribers.splice(index, 1);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
publish(data) {
|
|
20
|
+
this.subscribers.forEach((subscriber) => subscriber(data));
|
|
21
|
+
}
|
|
22
|
+
addToast(data) {
|
|
23
|
+
this.publish(data);
|
|
24
|
+
this.toasts = [...this.toasts, data];
|
|
25
|
+
}
|
|
26
|
+
create(data) {
|
|
27
|
+
const { message, ...rest } = data;
|
|
28
|
+
const id = typeof data?.id === 'number' || (data.id && String(data.id).length > 0)
|
|
29
|
+
? data.id
|
|
30
|
+
: toastsCounter++;
|
|
31
|
+
const alreadyExists = this.toasts.find((toast) => toast.id === id);
|
|
32
|
+
const dismissible = data.dismissible === undefined ? true : data.dismissible;
|
|
33
|
+
if (this.dismissedToasts.has(id)) {
|
|
34
|
+
this.dismissedToasts.delete(id);
|
|
35
|
+
}
|
|
36
|
+
if (alreadyExists) {
|
|
37
|
+
this.toasts = this.toasts.map((toast) => {
|
|
38
|
+
if (toast.id === id) {
|
|
39
|
+
this.publish({ ...toast, ...data, id, title: message });
|
|
40
|
+
return {
|
|
41
|
+
...toast,
|
|
42
|
+
...data,
|
|
43
|
+
id,
|
|
44
|
+
dismissible,
|
|
45
|
+
title: message,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return toast;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
this.addToast({ title: message, ...rest, dismissible, id });
|
|
53
|
+
}
|
|
54
|
+
return id;
|
|
55
|
+
}
|
|
56
|
+
dismiss(id) {
|
|
57
|
+
if (id) {
|
|
58
|
+
this.dismissedToasts.add(id);
|
|
59
|
+
requestAnimationFrame(() => this.subscribers.forEach((subscriber) => subscriber({ id, dismiss: true })));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
this.toasts.forEach((toast) => {
|
|
63
|
+
this.subscribers.forEach((subscriber) => subscriber({ id: toast.id, dismiss: true }));
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return id;
|
|
67
|
+
}
|
|
68
|
+
message(message, data) {
|
|
69
|
+
return this.create({ ...data, message });
|
|
70
|
+
}
|
|
71
|
+
error(message, data) {
|
|
72
|
+
return this.create({ ...data, message, type: 'error' });
|
|
73
|
+
}
|
|
74
|
+
success(message, data) {
|
|
75
|
+
return this.create({ ...data, type: 'success', message });
|
|
76
|
+
}
|
|
77
|
+
info(message, data) {
|
|
78
|
+
return this.create({ ...data, type: 'info', message });
|
|
79
|
+
}
|
|
80
|
+
warning(message, data) {
|
|
81
|
+
return this.create({ ...data, type: 'warning', message });
|
|
82
|
+
}
|
|
83
|
+
loading(message, data) {
|
|
84
|
+
return this.create({ ...data, type: 'loading', message });
|
|
85
|
+
}
|
|
86
|
+
// Create toast with any custom type (e.g., 'congrats', 'celebration')
|
|
87
|
+
withType(type, message, data) {
|
|
88
|
+
return this.create({ ...data, type, message });
|
|
89
|
+
}
|
|
90
|
+
promise(promise, data) {
|
|
91
|
+
if (!data)
|
|
92
|
+
return undefined;
|
|
93
|
+
let id = undefined;
|
|
94
|
+
if (data.loading !== undefined) {
|
|
95
|
+
id = this.create({
|
|
96
|
+
...data,
|
|
97
|
+
promise,
|
|
98
|
+
type: 'loading',
|
|
99
|
+
message: data.loading,
|
|
100
|
+
description: typeof data.description !== 'function' ? data.description : undefined,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const p = Promise.resolve(typeof promise === 'function' ? promise() : promise);
|
|
104
|
+
let shouldDismiss = id !== undefined;
|
|
105
|
+
let result;
|
|
106
|
+
const originalPromise = p
|
|
107
|
+
.then(async (response) => {
|
|
108
|
+
result = ['resolve', response];
|
|
109
|
+
// Check for HTTP error response
|
|
110
|
+
if (isHttpResponse(response) && !response.ok) {
|
|
111
|
+
shouldDismiss = false;
|
|
112
|
+
const promiseData = typeof data.error === 'function'
|
|
113
|
+
? await data.error(`HTTP error! status: ${response.status}`)
|
|
114
|
+
: data.error;
|
|
115
|
+
const description = typeof data.description === 'function'
|
|
116
|
+
? await data.description(`HTTP error! status: ${response.status}`)
|
|
117
|
+
: data.description;
|
|
118
|
+
this.create({ id, type: 'error', description, message: promiseData });
|
|
119
|
+
}
|
|
120
|
+
else if (response instanceof Error) {
|
|
121
|
+
shouldDismiss = false;
|
|
122
|
+
const promiseData = typeof data.error === 'function' ? await data.error(response) : data.error;
|
|
123
|
+
const description = typeof data.description === 'function'
|
|
124
|
+
? await data.description(response)
|
|
125
|
+
: data.description;
|
|
126
|
+
this.create({ id, type: 'error', description, message: promiseData });
|
|
127
|
+
}
|
|
128
|
+
else if (data.success !== undefined) {
|
|
129
|
+
shouldDismiss = false;
|
|
130
|
+
const promiseData = typeof data.success === 'function' ? await data.success(response) : data.success;
|
|
131
|
+
const description = typeof data.description === 'function'
|
|
132
|
+
? await data.description(response)
|
|
133
|
+
: data.description;
|
|
134
|
+
this.create({ id, type: 'success', description, message: promiseData });
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
.catch(async (error) => {
|
|
138
|
+
result = ['reject', error];
|
|
139
|
+
if (data.error !== undefined) {
|
|
140
|
+
shouldDismiss = false;
|
|
141
|
+
const promiseData = typeof data.error === 'function' ? await data.error(error) : data.error;
|
|
142
|
+
const description = typeof data.description === 'function'
|
|
143
|
+
? await data.description(error)
|
|
144
|
+
: data.description;
|
|
145
|
+
this.create({ id, type: 'error', description, message: promiseData });
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
.finally(() => {
|
|
149
|
+
if (shouldDismiss) {
|
|
150
|
+
this.dismiss(id);
|
|
151
|
+
id = undefined;
|
|
152
|
+
}
|
|
153
|
+
data.finally?.();
|
|
154
|
+
});
|
|
155
|
+
const unwrap = () => new Promise((resolve, reject) => originalPromise
|
|
156
|
+
.then(() => (result[0] === 'reject' ? reject(result[1]) : resolve(result[1])))
|
|
157
|
+
.catch(reject));
|
|
158
|
+
if (typeof id !== 'string' && typeof id !== 'number') {
|
|
159
|
+
return { unwrap };
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
return Object.assign(id, { unwrap });
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
custom(content, data) {
|
|
166
|
+
const id = data?.id ?? toastsCounter++;
|
|
167
|
+
this.addToast({
|
|
168
|
+
...data,
|
|
169
|
+
id,
|
|
170
|
+
custom: content,
|
|
171
|
+
});
|
|
172
|
+
return id;
|
|
173
|
+
}
|
|
174
|
+
getActiveToasts() {
|
|
175
|
+
return this.toasts.filter((toast) => !this.dismissedToasts.has(toast.id));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function isHttpResponse(data) {
|
|
179
|
+
return (data !== null &&
|
|
180
|
+
typeof data === 'object' &&
|
|
181
|
+
'ok' in data &&
|
|
182
|
+
typeof data.ok === 'boolean' &&
|
|
183
|
+
'status' in data &&
|
|
184
|
+
typeof data.status === 'number');
|
|
185
|
+
}
|
|
186
|
+
export const ToastState = new Observer();
|
|
187
|
+
// Main toast function
|
|
188
|
+
const toastFunction = (message, data) => {
|
|
189
|
+
const id = data?.id ?? toastsCounter++;
|
|
190
|
+
ToastState.addToast({
|
|
191
|
+
title: message,
|
|
192
|
+
...data,
|
|
193
|
+
id,
|
|
194
|
+
});
|
|
195
|
+
return id;
|
|
196
|
+
};
|
|
197
|
+
const getHistory = () => ToastState.toasts;
|
|
198
|
+
const getToasts = () => ToastState.getActiveToasts();
|
|
199
|
+
// Export toast API with all methods
|
|
200
|
+
export const toast = Object.assign(toastFunction, {
|
|
201
|
+
success: ToastState.success.bind(ToastState),
|
|
202
|
+
info: ToastState.info.bind(ToastState),
|
|
203
|
+
warning: ToastState.warning.bind(ToastState),
|
|
204
|
+
error: ToastState.error.bind(ToastState),
|
|
205
|
+
message: ToastState.message.bind(ToastState),
|
|
206
|
+
promise: ToastState.promise.bind(ToastState),
|
|
207
|
+
dismiss: ToastState.dismiss.bind(ToastState),
|
|
208
|
+
loading: ToastState.loading.bind(ToastState),
|
|
209
|
+
custom: ToastState.custom.bind(ToastState),
|
|
210
|
+
withType: ToastState.withType.bind(ToastState),
|
|
211
|
+
}, { getHistory, getToasts });
|
|
212
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,IAAI,aAAa,GAAG,CAAC,CAAC;AAItB,MAAM,QAAQ;IAAd;QACE,gBAAW,GAAiB,EAAE,CAAC;QAC/B,WAAM,GAAa,EAAE,CAAC;QACtB,oBAAe,GAAyB,IAAI,GAAG,EAAE,CAAC;IAgNpD,CAAC;IA9MC,SAAS,CAAC,UAAsB;QAC9B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAClC,OAAO,GAAG,EAAE;YACV,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YACnD,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACpC,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,IAA6B;QACnC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,QAAQ,CAAC,IAAY;QACnB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,CACJ,IAIC;QAED,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;QAClC,MAAM,EAAE,GACN,OAAO,IAAI,EAAE,EAAE,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,GAAG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,UAAU,CAAC;IAC5C,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;IAC5C,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;IAC1C,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC;CAC/C,EACD,EAAE,UAAU,EAAE,SAAS,EAAE,CAC1B,CAAC"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stimulus controller for Sonner Vanilla
|
|
3
|
+
* Use with Rails Hotwire to display flash messages as toasts
|
|
4
|
+
*/
|
|
5
|
+
import { Controller } from '@hotwired/stimulus';
|
|
6
|
+
import { toast } from './state';
|
|
7
|
+
/**
|
|
8
|
+
* Toaster Controller - Initializes the toast container
|
|
9
|
+
*
|
|
10
|
+
* Usage in your HTML:
|
|
11
|
+
* ```html
|
|
12
|
+
* <div data-controller="toaster"
|
|
13
|
+
* data-toaster-position-value="bottom-right"
|
|
14
|
+
* data-toaster-theme-value="light"
|
|
15
|
+
* data-toaster-rich-colors-value="true"
|
|
16
|
+
* data-toaster-close-button-value="true"
|
|
17
|
+
* data-toaster-expand-value="false"
|
|
18
|
+
* data-toaster-duration-value="4000">
|
|
19
|
+
* </div>
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class ToasterController extends Controller {
|
|
23
|
+
static values: {
|
|
24
|
+
position: {
|
|
25
|
+
type: StringConstructor;
|
|
26
|
+
default: string;
|
|
27
|
+
};
|
|
28
|
+
theme: {
|
|
29
|
+
type: StringConstructor;
|
|
30
|
+
default: string;
|
|
31
|
+
};
|
|
32
|
+
richColors: {
|
|
33
|
+
type: BooleanConstructor;
|
|
34
|
+
default: boolean;
|
|
35
|
+
};
|
|
36
|
+
closeButton: {
|
|
37
|
+
type: BooleanConstructor;
|
|
38
|
+
default: boolean;
|
|
39
|
+
};
|
|
40
|
+
expand: {
|
|
41
|
+
type: BooleanConstructor;
|
|
42
|
+
default: boolean;
|
|
43
|
+
};
|
|
44
|
+
duration: {
|
|
45
|
+
type: NumberConstructor;
|
|
46
|
+
default: number;
|
|
47
|
+
};
|
|
48
|
+
visibleToasts: {
|
|
49
|
+
type: NumberConstructor;
|
|
50
|
+
default: number;
|
|
51
|
+
};
|
|
52
|
+
gap: {
|
|
53
|
+
type: NumberConstructor;
|
|
54
|
+
default: number;
|
|
55
|
+
};
|
|
56
|
+
offset: {
|
|
57
|
+
type: StringConstructor;
|
|
58
|
+
default: string;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
positionValue: string;
|
|
62
|
+
themeValue: string;
|
|
63
|
+
richColorsValue: boolean;
|
|
64
|
+
closeButtonValue: boolean;
|
|
65
|
+
expandValue: boolean;
|
|
66
|
+
durationValue: number;
|
|
67
|
+
visibleToastsValue: number;
|
|
68
|
+
gapValue: number;
|
|
69
|
+
offsetValue: string;
|
|
70
|
+
private toaster;
|
|
71
|
+
connect(): void;
|
|
72
|
+
disconnect(): void;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Toast Controller - Displays a toast message
|
|
76
|
+
*
|
|
77
|
+
* Usage in your HTML (for flash messages):
|
|
78
|
+
* ```html
|
|
79
|
+
* <div data-controller="toast"
|
|
80
|
+
* data-toast-type-value="success"
|
|
81
|
+
* data-toast-message-value="Your changes have been saved!"
|
|
82
|
+
* data-toast-description-value="Optional description"
|
|
83
|
+
* data-toast-duration-value="5000"
|
|
84
|
+
* data-toast-dismissible-value="true">
|
|
85
|
+
* </div>
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* Or with Turbo Streams:
|
|
89
|
+
* ```erb
|
|
90
|
+
* <%= turbo_stream.append "flash" do %>
|
|
91
|
+
* <div data-controller="toast"
|
|
92
|
+
* data-toast-type-value="<%= notice ? 'success' : 'error' %>"
|
|
93
|
+
* data-toast-message-value="<%= notice || alert %>">
|
|
94
|
+
* </div>
|
|
95
|
+
* <% end %>
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare class ToastController extends Controller {
|
|
99
|
+
static values: {
|
|
100
|
+
type: {
|
|
101
|
+
type: StringConstructor;
|
|
102
|
+
default: string;
|
|
103
|
+
};
|
|
104
|
+
message: StringConstructor;
|
|
105
|
+
description: StringConstructor;
|
|
106
|
+
duration: NumberConstructor;
|
|
107
|
+
dismissible: {
|
|
108
|
+
type: BooleanConstructor;
|
|
109
|
+
default: boolean;
|
|
110
|
+
};
|
|
111
|
+
richColors: BooleanConstructor;
|
|
112
|
+
closeButton: BooleanConstructor;
|
|
113
|
+
position: StringConstructor;
|
|
114
|
+
id: StringConstructor;
|
|
115
|
+
};
|
|
116
|
+
typeValue: string;
|
|
117
|
+
messageValue: string;
|
|
118
|
+
descriptionValue: string;
|
|
119
|
+
durationValue: number;
|
|
120
|
+
dismissibleValue: boolean;
|
|
121
|
+
richColorsValue: boolean;
|
|
122
|
+
closeButtonValue: boolean;
|
|
123
|
+
positionValue: string;
|
|
124
|
+
idValue: string;
|
|
125
|
+
hasTypeValue: boolean;
|
|
126
|
+
hasMessageValue: boolean;
|
|
127
|
+
hasDescriptionValue: boolean;
|
|
128
|
+
hasDurationValue: boolean;
|
|
129
|
+
hasDismissibleValue: boolean;
|
|
130
|
+
hasRichColorsValue: boolean;
|
|
131
|
+
hasCloseButtonValue: boolean;
|
|
132
|
+
hasPositionValue: boolean;
|
|
133
|
+
hasIdValue: boolean;
|
|
134
|
+
connect(): void;
|
|
135
|
+
private showToast;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Dismiss Controller - Dismisses a specific toast or all toasts
|
|
139
|
+
*
|
|
140
|
+
* Usage:
|
|
141
|
+
* ```html
|
|
142
|
+
* <button data-controller="toast-dismiss"
|
|
143
|
+
* data-action="click->toast-dismiss#dismiss"
|
|
144
|
+
* data-toast-dismiss-id-value="my-toast-id">
|
|
145
|
+
* Dismiss
|
|
146
|
+
* </button>
|
|
147
|
+
*
|
|
148
|
+
* <!-- Dismiss all toasts -->
|
|
149
|
+
* <button data-controller="toast-dismiss"
|
|
150
|
+
* data-action="click->toast-dismiss#dismissAll">
|
|
151
|
+
* Dismiss All
|
|
152
|
+
* </button>
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export declare class ToastDismissController extends Controller {
|
|
156
|
+
static values: {
|
|
157
|
+
id: StringConstructor;
|
|
158
|
+
};
|
|
159
|
+
idValue: string;
|
|
160
|
+
hasIdValue: boolean;
|
|
161
|
+
dismiss(): void;
|
|
162
|
+
dismissAll(): void;
|
|
163
|
+
}
|
|
164
|
+
export { toast };
|
|
165
|
+
declare const _default: {
|
|
166
|
+
toaster: typeof ToasterController;
|
|
167
|
+
toast: typeof ToastController;
|
|
168
|
+
'toast-dismiss': typeof ToastDismissController;
|
|
169
|
+
};
|
|
170
|
+
export default _default;
|
|
171
|
+
//# sourceMappingURL=stimulus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stimulus.d.ts","sourceRoot":"","sources":["../src/stimulus.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAIhC;;;;;;;;;;;;;;GAcG;AACH,qBAAa,iBAAkB,SAAQ,UAAU;IAC/C,MAAM,CAAC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAUX;IAEM,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,OAAO,CAAC;IACzB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IAE5B,O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Toasts=new Set}subscribe(t){return this.subscribers.push(t),()=>{let e=this.subscribers.indexOf(t);this.subscribers.splice(e,1)}}publish(t){this.subscribers.forEach(e=>e(t))}addToast(t){this.publish(t),this.toasts=[...this.toasts,t]}create(t){let{message:e,...i}=t,r=typeof t?.id=="number"||t.id&&String(t.id).length>0?t.id:D++,a=this.toasts.find(s=>s.id===r),l=t.dismissible===void 0?!0:t.dismissible;return this.dismissedToasts.has(r)&&this.dismissedToasts.delete(r),a?this.toasts=this.toasts.map(s=>s.id===r?(this.publish({...s,...t,id:r,title:e}),{...s,...t,id:r,dismissible:l,title:e}):s):this.addToast({title:e,...i,dismissible:l,id:r}),r}dismiss(t){return t?(this.dismissedToasts.add(t),requestAnimationFrame(()=>this.subscribers.forEach(e=>e({id:t,dismiss:!0})))):this.toasts.forEach(e=>{this.subscribers.forEach(i=>i({id:e.id,dismiss:!0}))}),t}message(t,e){return this.create({...e,message:t})}error(t,e){return this.create({...e,message:t,type:"error"})}success(t,e){return this.create({...e,type:"success",message:t})}info(t,e){return this.create({...e,type:"info",message:t})}warning(t,e){return this.create({...e,type:"warning",message:t})}loading(t,e){return this.create({...e,type:"loading",message:t})}promise(t,e){if(!e)return;let i;e.loading!==void 0&&(i=this.create({...e,promise:t,type:"loading",message:e.loading,description:typeof e.description!="function"?e.description:void 0}));let r=Promise.resolve(typeof t=="function"?t():t),a=i!==void 0,l,s=r.then(async n=>{if(l=["resolve",n],N(n)&&!n.ok){a=!1;let c=typeof e.error=="function"?await e.error(`HTTP error! status: ${n.status}`):e.error,p=typeof e.description=="function"?await e.description(`HTTP error! status: ${n.status}`):e.description;this.create({id:i,type:"error",description:p,message:c})}else if(n instanceof Error){a=!1;let c=typeof e.error=="function"?await e.error(n):e.error,p=typeof e.description=="function"?await e.description(n):e.description;this.create({id:i,type:"error",description:p,message:c})}else if(e.success!==void 0){a=!1;let c=typeof e.success=="function"?await e.success(n):e.success,p=typeof e.description=="function"?await e.description(n):e.description;this.create({id:i,type:"success",description:p,message:c})}}).catch(async n=>{if(l=["reject",n],e.error!==void 0){a=!1;let c=typeof e.error=="function"?await e.error(n):e.error,p=typeof e.description=="function"?await e.description(n):e.description;this.create({id:i,type:"error",description:p,message:c})}}).finally(()=>{a&&(this.dismiss(i),i=void 0),e.finally?.()}),o=()=>new Promise((n,c)=>s.then(()=>l[0]==="reject"?c(l[1]):n(l[1])).catch(c));return typeof i!="string"&&typeof i!="number"?{unwrap:o}:Object.assign(i,{unwrap:o})}getActiveToasts(){return this.toasts.filter(t=>!this.dismissedToasts.has(t.id))}};function N(d){return d!==null&&typeof d=="object"&&"ok"in d&&typeof d.ok=="boolean"&&"status"in d&&typeof d.status=="number"}var u=new g,B=(d,t)=>{let e=t?.id??D++;return u.addToast({title:d,...t,id:e}),e},I=()=>u.toasts,H=()=>u.getActiveToasts(),m=Object.assign(B,{success:u.success.bind(u),info:u.info.bind(u),warning:u.warning.bind(u),error:u.error.bind(u),message:u.message.bind(u),promise:u.promise.bind(u),dismiss:u.dismiss.bind(u),loading:u.loading.bind(u)},{getHistory:I,getToasts:H});function b(d){switch(d){case"success":return k;case"info":return R;case"warning":return M;case"error":return $;default:return null}}function A(d,t){let e=document.createElement("div");e.className=["sonner-loading-wrapper",t].filter(Boolean).join(" "),e.dataset.visible=String(d);let i=document.createElement("div");i.className="sonner-spinner";for(let r=0;r<12;r++){let a=document.createElement("div");a.className="sonner-loading-bar",i.appendChild(a)}return e.appendChild(i),e}var k=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" height="20" width="20">
|
|
2
|
+
<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" />
|
|
3
|
+
</svg>`,M=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" height="20" width="20">
|
|
4
|
+
<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" />
|
|
5
|
+
</svg>`,R=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" height="20" width="20">
|
|
6
|
+
<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" />
|
|
7
|
+
</svg>`,$=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" height="20" width="20">
|
|
8
|
+
<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" />
|
|
9
|
+
</svg>`,C=`<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
|
10
|
+
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
11
|
+
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
12
|
+
</svg>`;function T(d){return typeof d=="object"&&d!==null&&"label"in d&&"onClick"in d}var j=3,O="24px",P="16px",z=4e3,F=356,_=14,q=45,K=200;function h(...d){return d.filter(Boolean).join(" ")}function U(d){let[t,e]=d.split("-"),i=[];return t&&i.push(t),e&&i.push(e),i}function L(){if(typeof window>"u"||typeof document>"u")return"ltr";let d=document.documentElement.getAttribute("dir");return d==="auto"||!d?window.getComputedStyle(document.documentElement).direction:d}function W(d,t){let e={};return[d,t].forEach((i,r)=>{let a=r===1,l=a?"--mobile-offset":"--offset",s=a?P:O;function o(n){["top","right","bottom","left"].forEach(c=>{e[`${l}-${c}`]=typeof n=="number"?`${n}px`:n})}typeof i=="number"||typeof i=="string"?o(i):typeof i=="object"&&i!==null?["top","right","bottom","left"].forEach(n=>{let c=n;i[c]===void 0?e[`${l}-${n}`]=s:e[`${l}-${n}`]=typeof i[c]=="number"?`${i[c]}px`:String(i[c])}):o(s)}),e}var y=class{constructor(t={}){this.container=null;this.listEl=null;this.toastInstances=new Map;this.heights=[];this.expanded=!1;this.interacting=!1;this.unsubscribe=null;this.boundListHandlers=null;this.actualTheme="light";this.isDocumentHidden=!1;this.handleKeyDown=t=>{let{hotkey:e}=this.options;e.length>0&&e.every(r=>t[r]||t.code===r)&&(this.setExpanded(!0),this.listEl?.focus()),t.code==="Escape"&&this.listEl?.contains(document.activeElement)&&this.setExpanded(!1)};this.handleVisibilityChange=()=>{this.isDocumentHidden=document.hidden,this.toastInstances.forEach(t=>{this.isDocumentHidden?this.pauseTimer(t):this.startTimer(t)})};this.options={id:t.id??"",invert:t.invert??!1,theme:t.theme??"light",position:t.position??"bottom-right",hotkey:t.hotkey??["altKey","KeyT"],richColors:t.richColors??!1,expand:t.expand??!1,duration:t.duration??z,gap:t.gap??_,visibleToasts:t.visibleToasts??j,closeButton:t.closeButton??!1,className:t.className??"",style:t.style??{},offset:t.offset??O,mobileOffset:t.mobileOffset??P,dir:t.dir??L(),swipeDirections:t.swipeDirections??void 0,containerAriaLabel:t.containerAriaLabel??"Notifications",toastOptions:t.toastOptions??{}}}mount(t=document.body){let e=typeof t=="string"?document.querySelector(t):t;if(!e){console.error("Toaster: target element not found");return}this.setupTheme(),this.createContainer(),e.appendChild(this.container),this.setupEventListeners(),this.subscribeToState()}unmount(){document.removeEventListener("keydown",this.handleKeyDown),document.removeEventListener("visibilitychange",this.handleVisibilityChange),this.listEl&&this.boundListHandlers&&(this.listEl.removeEventListener("mouseenter",this.boundListHandlers.mouseenter),this.listEl.removeEventListener("mousemove",this.boundListHandlers.mousemove),this.listEl.removeEventListener("mouseleave",this.boundListHandlers.mouseleave),this.listEl.removeEventListener("pointerdown",this.boundListHandlers.pointerdown),this.listEl.removeEventListener("pointerup",this.boundListHandlers.pointerup)),this.boundListHandlers=null,this.unsubscribe?.(),this.container?.remove(),this.container=null,this.listEl=null,this.toastInstances.clear()}setupTheme(){if(this.options.theme!=="system"){this.actualTheme=this.options.theme;return}if(typeof window<"u"&&window.matchMedia){let t=window.matchMedia("(prefers-color-scheme: dark)");this.actualTheme=t.matches?"dark":"light",t.addEventListener("change",e=>{this.actualTheme=e.matches?"dark":"light",this.listEl?.setAttribute("data-sonner-theme",this.actualTheme)})}}createContainer(){let[t,e]=this.options.position.split("-");this.container=document.createElement("section");let i=this.options.hotkey.join("+").replace(/Key/g,"").replace(/Digit/g,"");this.container.setAttribute("aria-label",`${this.options.containerAriaLabel} ${i}`),this.container.setAttribute("tabindex","-1"),this.container.setAttribute("aria-live","polite"),this.container.setAttribute("aria-relevant","additions text"),this.container.setAttribute("aria-atomic","false"),this.listEl=document.createElement("ol"),this.listEl.setAttribute("data-sonner-toaster",""),this.listEl.setAttribute("data-sonner-theme",this.actualTheme),this.listEl.setAttribute("data-y-position",t),this.listEl.setAttribute("data-x-position",e),this.listEl.setAttribute("dir",this.options.dir==="auto"?L():this.options.dir),this.listEl.setAttribute("tabindex","-1"),this.options.className&&(this.listEl.className=this.options.className);let r=W(this.options.offset,this.options.mobileOffset);Object.assign(this.listEl.style,{"--front-toast-height":"0px","--width":`${F}px`,"--gap":`${this.options.gap}px`,...r,...this.options.style}),this.container.appendChild(this.listEl)}setupEventListeners(){document.addEventListener("keydown",this.handleKeyDown),document.addEventListener("visibilitychange",this.handleVisibilityChange),this.boundListHandlers={mouseenter:()=>this.setExpanded(!0),mousemove:()=>this.setExpanded(!0),mouseleave:()=>{this.interacting||this.setExpanded(!1)},pointerdown:t=>{t.target.dataset.dismissible!=="false"&&(this.interacting=!0)},pointerup:()=>{this.interacting=!1}},this.listEl?.addEventListener("mouseenter",this.boundListHandlers.mouseenter),this.listEl?.addEventListener("mousemove",this.boundListHandlers.mousemove),this.listEl?.addEventListener("mouseleave",this.boundListHandlers.mouseleave),this.listEl?.addEventListener("pointerdown",this.boundListHandlers.pointerdown),this.listEl?.addEventListener("pointerup",this.boundListHandlers.pointerup)}setExpanded(t){this.expanded=t,this.toastInstances.forEach(e=>{e.element.dataset.expanded=String(t||this.options.expand)})}subscribeToState(){this.unsubscribe=u.subscribe(t=>{if(t.dismiss)this.dismissToast(t.id);else{let e=t;if(this.options.id){if(e.toasterId!==this.options.id)return}else if(e.toasterId)return;this.addOrUpdateToast(e)}})}addOrUpdateToast(t){let e=this.toastInstances.get(t.id);e?this.updateToastElement(e,t):this.createToast(t)}createToast(t){let[e,i]=(t.position||this.options.position).split("-"),r=t.duration??this.options.toastOptions?.duration??this.options.duration,a=t.dismissible!==!1,l=t.closeButton??this.options.toastOptions?.closeButton??this.options.closeButton,s=t.type,o=document.createElement("li");o.setAttribute("tabindex","0"),o.setAttribute("data-sonner-toast",""),o.setAttribute("data-styled",String(!t.unstyled&&!this.options.toastOptions?.unstyled)),o.setAttribute("data-mounted","false"),o.setAttribute("data-promise",String(!!t.promise)),o.setAttribute("data-swiped","false"),o.setAttribute("data-removed","false"),o.setAttribute("data-visible","true"),o.setAttribute("data-y-position",e),o.setAttribute("data-x-position",i),o.setAttribute("data-front","true"),o.setAttribute("data-swiping","false"),o.setAttribute("data-dismissible",String(a)),o.setAttribute("data-type",s||""),o.setAttribute("data-invert",String(t.invert??this.options.invert)),o.setAttribute("data-swipe-out","false"),o.setAttribute("data-expanded",String(this.expanded||this.options.expand)),o.setAttribute("data-rich-colors",String(t.richColors??this.options.richColors)),t.testId&&o.setAttribute("data-testid",t.testId),o.className=h(this.options.toastOptions?.className,t.className,this.options.toastOptions?.classNames?.toast,t.classNames?.toast,this.options.toastOptions?.classNames?.[s],t.classNames?.[s]),this.buildToastContent(o,t,l);let n={toast:t,element:o,mounted:!1,removed:!1,height:0,offset:0,remainingTime:r,closeTimerStart:0,swiping:!1,swipeDirection:null,pointerStart:null,dragStartTime:null,isSwiped:!1};this.setupSwipeHandlers(n,a),this.listEl?.prepend(o),this.toastInstances.set(t.id,n),requestAnimationFrame(()=>{let c=o.getBoundingClientRect().height;n.height=c,this.heights.unshift({toastId:t.id,height:c,position:t.position||this.options.position}),o.dataset.mounted="true",this.updatePositions(),s!=="loading"&&t.promise===void 0&&r!==1/0&&this.startTimer(n)})}buildToastContent(t,e,i){let r=e.type;if(i&&r!=="loading"){let s=document.createElement("button");s.setAttribute("aria-label","Close toast"),s.setAttribute("data-close-button",""),s.className=h(this.options.toastOptions?.classNames?.closeButton,e.classNames?.closeButton),s.innerHTML=C,s.addEventListener("click",()=>{e.dismissible!==!1&&(this.removeToast(e),e.onDismiss?.(e))}),t.appendChild(s)}if(r||e.icon){let s=document.createElement("div");if(s.setAttribute("data-icon",""),s.className=h(this.options.toastOptions?.classNames?.icon,e.classNames?.icon),e.type==="loading"&&!e.icon){let o=A(!0,h(this.options.toastOptions?.classNames?.loader,e.classNames?.loader));s.appendChild(o)}else if(e.icon)typeof e.icon=="string"?s.innerHTML=e.icon:s.appendChild(e.icon);else{let o=b(r);o&&(s.innerHTML=o)}t.appendChild(s)}let a=document.createElement("div");a.setAttribute("data-content",""),a.className=h(this.options.toastOptions?.classNames?.content,e.classNames?.content);let l=document.createElement("div");if(l.setAttribute("data-title",""),l.className=h(this.options.toastOptions?.classNames?.title,e.classNames?.title),l.textContent=e.title||"",a.appendChild(l),e.description){let s=document.createElement("div");s.setAttribute("data-description",""),s.className=h(this.options.toastOptions?.descriptionClassName,e.descriptionClassName,this.options.toastOptions?.classNames?.description,e.classNames?.description),s.textContent=e.description,a.appendChild(s)}if(t.appendChild(a),e.cancel&&T(e.cancel)){let s=document.createElement("button");s.setAttribute("data-button",""),s.setAttribute("data-cancel",""),s.className=h(this.options.toastOptions?.classNames?.cancelButton,e.classNames?.cancelButton),s.textContent=e.cancel.label,Object.assign(s.style,e.cancelButtonStyle||this.options.toastOptions?.cancelButtonStyle),s.addEventListener("click",o=>{e.dismissible!==!1&&(e.cancel.onClick(o),this.removeToast(e))}),t.appendChild(s)}if(e.action&&T(e.action)){let s=document.createElement("button");s.setAttribute("data-button",""),s.setAttribute("data-action",""),s.className=h(this.options.toastOptions?.classNames?.actionButton,e.classNames?.actionButton),s.textContent=e.action.label,Object.assign(s.style,e.actionButtonStyle||this.options.toastOptions?.actionButtonStyle),s.addEventListener("click",o=>{e.action.onClick(o),o.defaultPrevented||this.removeToast(e)}),t.appendChild(s)}}setupSwipeHandlers(t,e){let{element:i,toast:r}=t,a=r.position||this.options.position,l=this.options.swipeDirections??U(a);i.addEventListener("pointerdown",s=>{s.button!==2&&(r.type==="loading"||!e||(t.dragStartTime=new Date,t.pointerStart={x:s.clientX,y:s.clientY},s.target.setPointerCapture(s.pointerId),s.target.tagName!=="BUTTON"&&(t.swiping=!0,i.dataset.swiping="true")))}),i.addEventListener("pointermove",s=>{if(!t.pointerStart||!e||(window.getSelection()?.toString().length??0)>0)return;let n=s.clientY-t.pointerStart.y,c=s.clientX-t.pointerStart.x;!t.swipeDirection&&(Math.abs(c)>1||Math.abs(n)>1)&&(t.swipeDirection=Math.abs(c)>Math.abs(n)?"x":"y");let p={x:0,y:0},S=f=>1/(1.5+Math.abs(f)/20);if(t.swipeDirection==="y"){if(l.includes("top")||l.includes("bottom"))if(l.includes("top")&&n<0||l.includes("bottom")&&n>0)p.y=n;else{let f=n*S(n);p.y=Math.abs(f)<Math.abs(n)?f:n}}else if(t.swipeDirection==="x"&&(l.includes("left")||l.includes("right")))if(l.includes("left")&&c<0||l.includes("right")&&c>0)p.x=c;else{let f=c*S(c);p.x=Math.abs(f)<Math.abs(c)?f:c}(Math.abs(p.x)>0||Math.abs(p.y)>0)&&(t.isSwiped=!0,i.dataset.swiped="true"),i.style.setProperty("--swipe-amount-x",`${p.x}px`),i.style.setProperty("--swipe-amount-y",`${p.y}px`)}),i.addEventListener("pointerup",()=>{if(!e)return;let s=parseFloat(i.style.getPropertyValue("--swipe-amount-x")||"0"),o=parseFloat(i.style.getPropertyValue("--swipe-amount-y")||"0"),n=t.dragStartTime?new Date().getTime()-t.dragStartTime.getTime():1e3,c=t.swipeDirection==="x"?s:o,p=Math.abs(c)/n;Math.abs(c)>=q||p>.11?(r.onDismiss?.(r),t.swipeDirection==="x"?i.dataset.swipeDirection=s>0?"right":"left":i.dataset.swipeDirection=o>0?"down":"up",i.dataset.swipeOut="true",this.removeToast(r)):(i.style.setProperty("--swipe-amount-x","0px"),i.style.setProperty("--swipe-amount-y","0px")),t.isSwiped=!1,t.swiping=!1,t.swipeDirection=null,t.pointerStart=null,i.dataset.swiped="false",i.dataset.swiping="false"})}updateToastElement(t,e){let{element:i}=t;t.toast=e,i.dataset.type=e.type||"";let r=i.querySelector("[data-title]");r&&(r.textContent=e.title||"");let a=i.querySelector("[data-description]");e.description?(a||(a=document.createElement("div"),a.setAttribute("data-description",""),i.querySelector("[data-content]")?.appendChild(a)),a.textContent=e.description):a&&a.remove();let l=i.querySelector("[data-icon]");if(l&&e.type&&e.type!=="loading"){let s=b(e.type);s&&(l.innerHTML=s)}e.type!=="loading"&&(t.remainingTime=e.duration??this.options.duration,this.startTimer(t))}startTimer(t){let{toast:e}=t;e.promise&&e.type==="loading"||e.duration===1/0||e.type==="loading"||this.expanded||this.interacting||this.isDocumentHidden||(clearTimeout(t.closeTimeout),t.closeTimerStart=Date.now(),t.closeTimeout=setTimeout(()=>{e.onAutoClose?.(e),this.removeToast(e)},t.remainingTime))}pauseTimer(t){if(t.closeTimerStart>0){let e=Date.now()-t.closeTimerStart;t.remainingTime=Math.max(0,t.remainingTime-e)}clearTimeout(t.closeTimeout)}dismissToast(t){let e=this.toastInstances.get(t);e&&(e.element.dataset.removed="true",this.removeToast(e.toast))}removeToast(t){let e=this.toastInstances.get(t.id);!e||e.removed||(e.removed=!0,e.element.dataset.removed="true",clearTimeout(e.closeTimeout),this.heights=this.heights.filter(i=>i.toastId!==t.id),setTimeout(()=>{e.element.remove(),this.toastInstances.delete(t.id),u.dismiss(t.id),this.updatePositions()},K),this.updatePositions())}updatePositions(){let t=Array.from(this.toastInstances.values()).filter(a=>!a.removed),{visibleToasts:e,gap:i}=this.options,r=0;t.forEach((a,l)=>{let{element:s}=a,o=l===0,n=l<e;s.dataset.index=String(l),s.dataset.front=String(o),s.dataset.visible=String(n);let c=l*i+r;a.offset=c,s.style.setProperty("--index",String(l)),s.style.setProperty("--toasts-before",String(l)),s.style.setProperty("--z-index",String(t.length-l)),s.style.setProperty("--offset",`${c}px`),s.style.setProperty("--initial-height",`${a.height}px`),r+=a.height}),this.listEl&&t.length>0&&this.listEl.style.setProperty("--front-toast-height",`${t[0].height}px`)}};function V(d){return new y(d)}var v=class extends x{constructor(){super(...arguments);this.toaster=null}static{this.values={position:{type:String,default:"bottom-right"},theme:{type:String,default:"light"},richColors:{type:Boolean,default:!1},closeButton:{type:Boolean,default:!1},expand:{type:Boolean,default:!1},duration:{type:Number,default:4e3},visibleToasts:{type:Number,default:3},gap:{type:Number,default:14},offset:{type:String,default:"24px"}}}connect(){let e={position:this.positionValue,theme:this.themeValue,richColors:this.richColorsValue,closeButton:this.closeButtonValue,expand:this.expandValue,duration:this.durationValue,visibleToasts:this.visibleToastsValue,gap:this.gapValue,offset:this.offsetValue};this.toaster=V(e),this.toaster.mount(this.element)}disconnect(){this.toaster?.unmount(),this.toaster=null}},w=class extends x{static{this.values={type:{type:String,default:"default"},message:String,description:String,duration:Number,dismissible:{type:Boolean,default:!0},richColors:Boolean,closeButton:Boolean,position:String,id:String}}connect(){if(!this.hasMessageValue){console.warn("Toast controller: message value is required");return}this.showToast(),this.element.remove()}showToast(){let t={};this.hasDescriptionValue&&(t.description=this.descriptionValue),this.hasDurationValue&&(t.duration=this.durationValue),this.hasDismissibleValue&&(t.dismissible=this.dismissibleValue),this.hasRichColorsValue&&(t.richColors=this.richColorsValue),this.hasCloseButtonValue&&(t.closeButton=this.closeButtonValue),this.hasPositionValue&&(t.position=this.positionValue),this.hasIdValue&&(t.id=this.idValue);let e=this.typeValue,i=this.messageValue;switch(e){case"success":m.success(i,t);break;case"error":m.error(i,t);break;case"warning":m.warning(i,t);break;case"info":m.info(i,t);break;case"loading":m.loading(i,t);break;default:m.message(i,t)}}},E=class extends x{static{this.values={id:String}}dismiss(){this.hasIdValue&&m.dismiss(this.idValue)}dismissAll(){m.dismiss()}};var rt={toaster:v,toast:w,"toast-dismiss":E};export{w as ToastController,E as ToastDismissController,v as ToasterController,rt as default,m as toast};
|
|
13
|
+
//# sourceMappingURL=stimulus.js.map
|