@tamagui/toast 2.7.7 → 3.0.0-beta.643.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.
Files changed (303) hide show
  1. package/dist/cjs/ToastComposable.cjs +773 -882
  2. package/dist/cjs/ToastComposable.native.cjs +924 -0
  3. package/dist/cjs/ToastComposable.native.js +854 -966
  4. package/dist/cjs/ToastComposable.native.js.map +1 -1
  5. package/dist/cjs/ToastItemFrame.cjs +48 -119
  6. package/dist/cjs/ToastItemFrame.native.cjs +76 -0
  7. package/dist/cjs/ToastItemFrame.native.js +50 -120
  8. package/dist/cjs/ToastItemFrame.native.js.map +1 -1
  9. package/dist/cjs/ToastState.cjs +281 -290
  10. package/dist/cjs/ToastState.native.cjs +312 -0
  11. package/dist/cjs/ToastState.native.js +280 -290
  12. package/dist/cjs/ToastState.native.js.map +1 -1
  13. package/dist/cjs/createNativeToast.cjs +38 -44
  14. package/dist/cjs/createNativeToast.native.cjs +54 -0
  15. package/dist/cjs/createNativeToast.native.js +36 -40
  16. package/dist/cjs/createNativeToast.native.js.map +1 -1
  17. package/dist/cjs/dispatchNativeToast.cjs +32 -35
  18. package/dist/cjs/dispatchNativeToast.native.cjs +48 -0
  19. package/dist/cjs/dispatchNativeToast.native.js +34 -36
  20. package/dist/cjs/dispatchNativeToast.native.js.map +1 -1
  21. package/dist/cjs/index.cjs +25 -12
  22. package/dist/cjs/index.native.cjs +35 -0
  23. package/dist/cjs/index.native.js +26 -12
  24. package/dist/cjs/index.native.js.map +1 -1
  25. package/dist/cjs/types.cjs +10 -11
  26. package/dist/cjs/types.native.cjs +19 -0
  27. package/dist/cjs/types.native.js +10 -10
  28. package/dist/cjs/types.native.js.map +1 -1
  29. package/dist/cjs/useAnimatedDragGesture.cjs +197 -194
  30. package/dist/cjs/useAnimatedDragGesture.native.cjs +210 -0
  31. package/dist/cjs/useAnimatedDragGesture.native.js +179 -191
  32. package/dist/cjs/useAnimatedDragGesture.native.js.map +1 -1
  33. package/dist/cjs/useReducedMotion.cjs +47 -55
  34. package/dist/cjs/useReducedMotion.native.cjs +74 -0
  35. package/dist/cjs/useReducedMotion.native.js +53 -60
  36. package/dist/cjs/useReducedMotion.native.js.map +1 -1
  37. package/dist/cjs/useToastAnimations.cjs +198 -270
  38. package/dist/cjs/useToastAnimations.native.cjs +229 -0
  39. package/dist/cjs/useToastAnimations.native.js +205 -276
  40. package/dist/cjs/useToastAnimations.native.js.map +1 -1
  41. package/dist/esm/ToastComposable.mjs +752 -854
  42. package/dist/esm/ToastComposable.mjs.map +1 -1
  43. package/dist/esm/ToastComposable.native.js +834 -940
  44. package/dist/esm/ToastComposable.native.js.map +1 -1
  45. package/dist/esm/ToastItemFrame.mjs +31 -99
  46. package/dist/esm/ToastItemFrame.mjs.map +1 -1
  47. package/dist/esm/ToastItemFrame.native.js +34 -102
  48. package/dist/esm/ToastItemFrame.native.js.map +1 -1
  49. package/dist/esm/ToastState.mjs +266 -273
  50. package/dist/esm/ToastState.mjs.map +1 -1
  51. package/dist/esm/ToastState.native.js +265 -274
  52. package/dist/esm/ToastState.native.js.map +1 -1
  53. package/dist/esm/createNativeToast.mjs +22 -26
  54. package/dist/esm/createNativeToast.mjs.map +1 -1
  55. package/dist/esm/createNativeToast.native.js +21 -23
  56. package/dist/esm/createNativeToast.native.js.map +1 -1
  57. package/dist/esm/dispatchNativeToast.mjs +19 -17
  58. package/dist/esm/dispatchNativeToast.mjs.map +1 -1
  59. package/dist/esm/dispatchNativeToast.native.js +21 -19
  60. package/dist/esm/dispatchNativeToast.native.js.map +1 -1
  61. package/dist/esm/index.js +5 -2
  62. package/dist/esm/index.mjs +5 -2
  63. package/dist/esm/index.native.js +5 -2
  64. package/dist/esm/types.mjs +0 -2
  65. package/dist/esm/types.native.js +0 -2
  66. package/dist/esm/useAnimatedDragGesture.mjs +181 -168
  67. package/dist/esm/useAnimatedDragGesture.mjs.map +1 -1
  68. package/dist/esm/useAnimatedDragGesture.native.js +163 -166
  69. package/dist/esm/useAnimatedDragGesture.native.js.map +1 -1
  70. package/dist/esm/useReducedMotion.mjs +31 -29
  71. package/dist/esm/useReducedMotion.mjs.map +1 -1
  72. package/dist/esm/useReducedMotion.native.js +37 -35
  73. package/dist/esm/useReducedMotion.native.js.map +1 -1
  74. package/dist/esm/useToastAnimations.mjs +183 -245
  75. package/dist/esm/useToastAnimations.mjs.map +1 -1
  76. package/dist/esm/useToastAnimations.native.js +190 -252
  77. package/dist/esm/useToastAnimations.native.js.map +1 -1
  78. package/dist/jsx/ToastComposable.mjs +752 -854
  79. package/dist/jsx/ToastComposable.mjs.map +1 -1
  80. package/dist/jsx/ToastComposable.native.cjs +924 -0
  81. package/dist/jsx/ToastComposable.native.js +854 -966
  82. package/dist/jsx/ToastComposable.native.js.map +1 -1
  83. package/dist/jsx/ToastItemFrame.mjs +31 -99
  84. package/dist/jsx/ToastItemFrame.mjs.map +1 -1
  85. package/dist/jsx/ToastItemFrame.native.cjs +76 -0
  86. package/dist/jsx/ToastItemFrame.native.js +50 -120
  87. package/dist/jsx/ToastItemFrame.native.js.map +1 -1
  88. package/dist/jsx/ToastState.mjs +266 -273
  89. package/dist/jsx/ToastState.mjs.map +1 -1
  90. package/dist/jsx/ToastState.native.cjs +312 -0
  91. package/dist/jsx/ToastState.native.js +280 -290
  92. package/dist/jsx/ToastState.native.js.map +1 -1
  93. package/dist/jsx/createNativeToast.mjs +22 -26
  94. package/dist/jsx/createNativeToast.mjs.map +1 -1
  95. package/dist/jsx/createNativeToast.native.cjs +54 -0
  96. package/dist/jsx/createNativeToast.native.js +36 -40
  97. package/dist/jsx/createNativeToast.native.js.map +1 -1
  98. package/dist/jsx/dispatchNativeToast.mjs +19 -17
  99. package/dist/jsx/dispatchNativeToast.mjs.map +1 -1
  100. package/dist/jsx/dispatchNativeToast.native.cjs +48 -0
  101. package/dist/jsx/dispatchNativeToast.native.js +34 -36
  102. package/dist/jsx/dispatchNativeToast.native.js.map +1 -1
  103. package/dist/jsx/index.js +5 -2
  104. package/dist/jsx/index.mjs +5 -2
  105. package/dist/jsx/index.native.cjs +35 -0
  106. package/dist/jsx/index.native.js +26 -12
  107. package/dist/jsx/index.native.js.map +1 -1
  108. package/dist/jsx/types.mjs +0 -2
  109. package/dist/jsx/types.native.cjs +19 -0
  110. package/dist/jsx/types.native.js +10 -10
  111. package/dist/jsx/types.native.js.map +1 -1
  112. package/dist/jsx/useAnimatedDragGesture.mjs +181 -168
  113. package/dist/jsx/useAnimatedDragGesture.mjs.map +1 -1
  114. package/dist/jsx/useAnimatedDragGesture.native.cjs +210 -0
  115. package/dist/jsx/useAnimatedDragGesture.native.js +179 -191
  116. package/dist/jsx/useAnimatedDragGesture.native.js.map +1 -1
  117. package/dist/jsx/useReducedMotion.mjs +31 -29
  118. package/dist/jsx/useReducedMotion.mjs.map +1 -1
  119. package/dist/jsx/useReducedMotion.native.cjs +74 -0
  120. package/dist/jsx/useReducedMotion.native.js +53 -60
  121. package/dist/jsx/useReducedMotion.native.js.map +1 -1
  122. package/dist/jsx/useToastAnimations.mjs +183 -245
  123. package/dist/jsx/useToastAnimations.mjs.map +1 -1
  124. package/dist/jsx/useToastAnimations.native.cjs +229 -0
  125. package/dist/jsx/useToastAnimations.native.js +205 -276
  126. package/dist/jsx/useToastAnimations.native.js.map +1 -1
  127. package/package.json +20 -37
  128. package/src/ToastComposable.tsx +55 -97
  129. package/src/ToastItemFrame.tsx +22 -81
  130. package/src/ToastState.ts +1 -0
  131. package/src/index.ts +34 -2
  132. package/src/types.ts +11 -0
  133. package/src/useAnimatedDragGesture.native.ts +1 -1
  134. package/src/useAnimatedDragGesture.ts +1 -1
  135. package/src/useToastAnimations.ts +20 -36
  136. package/types/ToastComposable.d.ts +124 -47
  137. package/types/ToastComposable.d.ts.map +1 -1
  138. package/types/ToastItemFrame.d.ts +52 -21
  139. package/types/ToastItemFrame.d.ts.map +1 -1
  140. package/types/ToastState.d.ts +15 -11
  141. package/types/ToastState.d.ts.map +1 -1
  142. package/types/index.d.ts +6 -2
  143. package/types/index.d.ts.map +1 -1
  144. package/types/types.d.ts +1 -0
  145. package/types/types.d.ts.map +1 -1
  146. package/types/useAnimatedDragGesture.d.ts +1 -1
  147. package/types/useAnimatedDragGesture.d.ts.map +1 -1
  148. package/types/useAnimatedDragGesture.native.d.ts +1 -1
  149. package/types/useAnimatedDragGesture.native.d.ts.map +1 -1
  150. package/types/useToastAnimations.d.ts +2 -8
  151. package/types/useToastAnimations.d.ts.map +1 -1
  152. package/dist/cjs/Toast.cjs +0 -178
  153. package/dist/cjs/Toast.native.js +0 -181
  154. package/dist/cjs/Toast.native.js.map +0 -1
  155. package/dist/cjs/ToastAnnounce.cjs +0 -103
  156. package/dist/cjs/ToastAnnounce.native.js +0 -111
  157. package/dist/cjs/ToastAnnounce.native.js.map +0 -1
  158. package/dist/cjs/ToastImperative.cjs +0 -119
  159. package/dist/cjs/ToastImperative.native.js +0 -130
  160. package/dist/cjs/ToastImperative.native.js.map +0 -1
  161. package/dist/cjs/ToastImpl.cjs +0 -354
  162. package/dist/cjs/ToastImpl.native.js +0 -364
  163. package/dist/cjs/ToastImpl.native.js.map +0 -1
  164. package/dist/cjs/ToastPortal.cjs +0 -49
  165. package/dist/cjs/ToastPortal.native.js +0 -52
  166. package/dist/cjs/ToastPortal.native.js.map +0 -1
  167. package/dist/cjs/ToastProvider.cjs +0 -150
  168. package/dist/cjs/ToastProvider.native.js +0 -161
  169. package/dist/cjs/ToastProvider.native.js.map +0 -1
  170. package/dist/cjs/ToastViewport.cjs +0 -319
  171. package/dist/cjs/ToastViewport.native.js +0 -343
  172. package/dist/cjs/ToastViewport.native.js.map +0 -1
  173. package/dist/cjs/Toaster.cjs +0 -87
  174. package/dist/cjs/Toaster.native.js +0 -91
  175. package/dist/cjs/Toaster.native.js.map +0 -1
  176. package/dist/cjs/constants.cjs +0 -30
  177. package/dist/cjs/constants.native.js +0 -33
  178. package/dist/cjs/constants.native.js.map +0 -1
  179. package/dist/cjs/v2.cjs +0 -36
  180. package/dist/cjs/v2.native.js +0 -39
  181. package/dist/cjs/v2.native.js.map +0 -1
  182. package/dist/esm/Toast.mjs +0 -137
  183. package/dist/esm/Toast.mjs.map +0 -1
  184. package/dist/esm/Toast.native.js +0 -137
  185. package/dist/esm/Toast.native.js.map +0 -1
  186. package/dist/esm/ToastAnnounce.mjs +0 -66
  187. package/dist/esm/ToastAnnounce.mjs.map +0 -1
  188. package/dist/esm/ToastAnnounce.native.js +0 -71
  189. package/dist/esm/ToastAnnounce.native.js.map +0 -1
  190. package/dist/esm/ToastImperative.mjs +0 -80
  191. package/dist/esm/ToastImperative.mjs.map +0 -1
  192. package/dist/esm/ToastImperative.native.js +0 -88
  193. package/dist/esm/ToastImperative.native.js.map +0 -1
  194. package/dist/esm/ToastImpl.mjs +0 -316
  195. package/dist/esm/ToastImpl.mjs.map +0 -1
  196. package/dist/esm/ToastImpl.native.js +0 -329
  197. package/dist/esm/ToastImpl.native.js.map +0 -1
  198. package/dist/esm/ToastPortal.mjs +0 -24
  199. package/dist/esm/ToastPortal.mjs.map +0 -1
  200. package/dist/esm/ToastPortal.native.js +0 -24
  201. package/dist/esm/ToastPortal.native.js.map +0 -1
  202. package/dist/esm/ToastProvider.mjs +0 -110
  203. package/dist/esm/ToastProvider.mjs.map +0 -1
  204. package/dist/esm/ToastProvider.native.js +0 -118
  205. package/dist/esm/ToastProvider.native.js.map +0 -1
  206. package/dist/esm/ToastViewport.mjs +0 -280
  207. package/dist/esm/ToastViewport.mjs.map +0 -1
  208. package/dist/esm/ToastViewport.native.js +0 -301
  209. package/dist/esm/ToastViewport.native.js.map +0 -1
  210. package/dist/esm/Toaster.mjs +0 -51
  211. package/dist/esm/Toaster.mjs.map +0 -1
  212. package/dist/esm/Toaster.native.js +0 -52
  213. package/dist/esm/Toaster.native.js.map +0 -1
  214. package/dist/esm/constants.mjs +0 -4
  215. package/dist/esm/constants.mjs.map +0 -1
  216. package/dist/esm/constants.native.js +0 -4
  217. package/dist/esm/constants.native.js.map +0 -1
  218. package/dist/esm/index.js.map +0 -1
  219. package/dist/esm/index.mjs.map +0 -1
  220. package/dist/esm/index.native.js.map +0 -1
  221. package/dist/esm/types.mjs.map +0 -1
  222. package/dist/esm/types.native.js.map +0 -1
  223. package/dist/esm/v2.mjs +0 -6
  224. package/dist/esm/v2.mjs.map +0 -1
  225. package/dist/esm/v2.native.js +0 -6
  226. package/dist/esm/v2.native.js.map +0 -1
  227. package/dist/jsx/Toast.mjs +0 -137
  228. package/dist/jsx/Toast.mjs.map +0 -1
  229. package/dist/jsx/Toast.native.js +0 -181
  230. package/dist/jsx/Toast.native.js.map +0 -1
  231. package/dist/jsx/ToastAnnounce.mjs +0 -66
  232. package/dist/jsx/ToastAnnounce.mjs.map +0 -1
  233. package/dist/jsx/ToastAnnounce.native.js +0 -111
  234. package/dist/jsx/ToastAnnounce.native.js.map +0 -1
  235. package/dist/jsx/ToastImperative.mjs +0 -80
  236. package/dist/jsx/ToastImperative.mjs.map +0 -1
  237. package/dist/jsx/ToastImperative.native.js +0 -130
  238. package/dist/jsx/ToastImperative.native.js.map +0 -1
  239. package/dist/jsx/ToastImpl.mjs +0 -316
  240. package/dist/jsx/ToastImpl.mjs.map +0 -1
  241. package/dist/jsx/ToastImpl.native.js +0 -364
  242. package/dist/jsx/ToastImpl.native.js.map +0 -1
  243. package/dist/jsx/ToastPortal.mjs +0 -24
  244. package/dist/jsx/ToastPortal.mjs.map +0 -1
  245. package/dist/jsx/ToastPortal.native.js +0 -52
  246. package/dist/jsx/ToastPortal.native.js.map +0 -1
  247. package/dist/jsx/ToastProvider.mjs +0 -110
  248. package/dist/jsx/ToastProvider.mjs.map +0 -1
  249. package/dist/jsx/ToastProvider.native.js +0 -161
  250. package/dist/jsx/ToastProvider.native.js.map +0 -1
  251. package/dist/jsx/ToastViewport.mjs +0 -280
  252. package/dist/jsx/ToastViewport.mjs.map +0 -1
  253. package/dist/jsx/ToastViewport.native.js +0 -343
  254. package/dist/jsx/ToastViewport.native.js.map +0 -1
  255. package/dist/jsx/Toaster.mjs +0 -51
  256. package/dist/jsx/Toaster.mjs.map +0 -1
  257. package/dist/jsx/Toaster.native.js +0 -91
  258. package/dist/jsx/Toaster.native.js.map +0 -1
  259. package/dist/jsx/constants.mjs +0 -4
  260. package/dist/jsx/constants.mjs.map +0 -1
  261. package/dist/jsx/constants.native.js +0 -33
  262. package/dist/jsx/constants.native.js.map +0 -1
  263. package/dist/jsx/index.js.map +0 -1
  264. package/dist/jsx/index.mjs.map +0 -1
  265. package/dist/jsx/types.mjs.map +0 -1
  266. package/dist/jsx/v2.mjs +0 -6
  267. package/dist/jsx/v2.mjs.map +0 -1
  268. package/dist/jsx/v2.native.js +0 -39
  269. package/dist/jsx/v2.native.js.map +0 -1
  270. package/src/Toast.tsx +0 -219
  271. package/src/ToastAnnounce.tsx +0 -103
  272. package/src/ToastImperative.tsx +0 -192
  273. package/src/ToastImpl.tsx +0 -514
  274. package/src/ToastPortal.tsx +0 -19
  275. package/src/ToastProvider.tsx +0 -204
  276. package/src/ToastViewport.tsx +0 -430
  277. package/src/Toaster.tsx +0 -181
  278. package/src/constants.ts +0 -2
  279. package/src/v2.ts +0 -31
  280. package/types/Toast.d.ts +0 -84
  281. package/types/Toast.d.ts.map +0 -1
  282. package/types/ToastAnnounce.d.ts +0 -18
  283. package/types/ToastAnnounce.d.ts.map +0 -1
  284. package/types/ToastImperative.d.ts +0 -95
  285. package/types/ToastImperative.d.ts.map +0 -1
  286. package/types/ToastImpl.d.ts +0 -109
  287. package/types/ToastImpl.d.ts.map +0 -1
  288. package/types/ToastPortal.d.ts +0 -8
  289. package/types/ToastPortal.d.ts.map +0 -1
  290. package/types/ToastProvider.d.ts +0 -92
  291. package/types/ToastProvider.d.ts.map +0 -1
  292. package/types/ToastViewport.d.ts +0 -75
  293. package/types/ToastViewport.d.ts.map +0 -1
  294. package/types/Toaster.d.ts +0 -112
  295. package/types/Toaster.d.ts.map +0 -1
  296. package/types/constants.d.ts +0 -3
  297. package/types/constants.d.ts.map +0 -1
  298. package/types/v2.d.ts +0 -10
  299. package/types/v2.d.ts.map +0 -1
  300. package/v2/index.cjs +0 -2
  301. package/v2/index.js +0 -2
  302. package/v2/index.native.cjs +0 -2
  303. package/v2/index.native.js +0 -2
@@ -1,311 +1,302 @@
1
+
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
6
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
7
+ for (var name in all) __defProp(target, name, {
8
+ get: all[name],
9
+ enumerable: true
10
+ });
10
11
  };
11
12
  var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
- get: () => from[key],
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- return to;
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
19
20
  };
20
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: true
22
- }), mod);
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
22
  var ToastState_exports = {};
24
23
  __export(ToastState_exports, {
25
- ToastState: () => ToastState,
26
- toast: () => toast
24
+ ToastState: () => ToastState,
25
+ toast: () => toast
27
26
  });
28
27
  module.exports = __toCommonJS(ToastState_exports);
29
28
  let toastsCounter = 1;
30
- class Observer {
31
- subscribers = [];
32
- toasts = [];
33
- dismissedToasts = /* @__PURE__ */new Set();
34
- /**
35
- * Subscribe to toast state changes.
36
- * Returns an unsubscribe function.
37
- */
38
- subscribe = subscriber => {
39
- this.subscribers.push(subscriber);
40
- return () => {
41
- const index = this.subscribers.indexOf(subscriber);
42
- if (index > -1) {
43
- this.subscribers.splice(index, 1);
44
- }
45
- };
46
- };
47
- /**
48
- * Publish a toast to all subscribers
49
- */
50
- publish = data => {
51
- this.subscribers.forEach(subscriber => subscriber(data));
52
- };
53
- /**
54
- * Add a new toast to the internal array and publish to subscribers
55
- */
56
- addToast = data => {
57
- this.publish(data);
58
- this.toasts = [...this.toasts, data];
59
- };
60
- /**
61
- * Create or update a toast
62
- */
63
- create = data => {
64
- const {
65
- title,
66
- ...rest
67
- } = data;
68
- const id = typeof data?.id === "number" || typeof data?.id === "string" && data.id.length > 0 ? data.id : toastsCounter++;
69
- const alreadyExists = this.toasts.find(toast2 => toast2.id === id);
70
- const dismissible = data.dismissible ?? true;
71
- if (this.dismissedToasts.has(id)) {
72
- this.dismissedToasts.delete(id);
73
- }
74
- if (alreadyExists) {
75
- this.toasts = this.toasts.map(toast2 => {
76
- if (toast2.id === id) {
77
- this.publish({
78
- ...toast2,
79
- ...data,
80
- id,
81
- title,
82
- dismissible
83
- });
84
- return {
85
- ...toast2,
86
- ...data,
87
- id,
88
- title,
89
- dismissible
90
- };
91
- }
92
- return toast2;
93
- });
94
- } else {
95
- this.addToast({
96
- title,
97
- ...rest,
98
- dismissible,
99
- id
100
- });
101
- }
102
- return id;
103
- };
104
- /**
105
- * Dismiss a toast by id, or all toasts if no id provided
106
- */
107
- dismiss = id => {
108
- if (id !== void 0) {
109
- this.dismissedToasts.add(id);
110
- requestAnimationFrame(() => {
111
- this.subscribers.forEach(subscriber => subscriber({
112
- id,
113
- dismiss: true
114
- }));
115
- });
116
- } else {
117
- this.toasts.forEach(toast2 => {
118
- this.subscribers.forEach(subscriber => subscriber({
119
- id: toast2.id,
120
- dismiss: true
121
- }));
122
- });
123
- }
124
- return id;
125
- };
126
- /**
127
- * Show a basic toast message
128
- */
129
- message = (title, data) => {
130
- return this.create({
131
- ...data,
132
- title,
133
- type: "default"
134
- });
135
- };
136
- /**
137
- * Show a success toast
138
- */
139
- success = (title, data) => {
140
- return this.create({
141
- ...data,
142
- title,
143
- type: "success"
144
- });
145
- };
146
- /**
147
- * Show an error toast
148
- */
149
- error = (title, data) => {
150
- return this.create({
151
- ...data,
152
- title,
153
- type: "error"
154
- });
155
- };
156
- /**
157
- * Show a warning toast
158
- */
159
- warning = (title, data) => {
160
- return this.create({
161
- ...data,
162
- title,
163
- type: "warning"
164
- });
165
- };
166
- /**
167
- * Show an info toast
168
- */
169
- info = (title, data) => {
170
- return this.create({
171
- ...data,
172
- title,
173
- type: "info"
174
- });
175
- };
176
- /**
177
- * Show a loading toast
178
- */
179
- loading = (title, data) => {
180
- return this.create({
181
- ...data,
182
- title,
183
- type: "loading"
184
- });
185
- };
186
- /**
187
- * Show a toast for a promise, automatically transitioning through
188
- * loading -> success/error states
189
- */
190
- promise = (promise, data) => {
191
- if (!data) {
192
- return;
193
- }
194
- let id = void 0;
195
- if (data.loading !== void 0) {
196
- id = this.create({
197
- promise,
198
- type: "loading",
199
- title: data.loading,
200
- description: typeof data.description !== "function" ? data.description : void 0,
201
- // loading toasts shouldn't auto-dismiss
202
- duration: Number.POSITIVE_INFINITY
203
- });
204
- }
205
- const p = Promise.resolve(promise instanceof Function ? promise() : promise);
206
- let shouldDismiss = id !== void 0;
207
- let result;
208
- const originalPromise = p.then(async response => {
209
- result = ["resolve", response];
210
- if (isHttpResponse(response) && !response.ok) {
211
- shouldDismiss = false;
212
- const errorMsg = typeof data.error === "function" ? await data.error(`HTTP error! status: ${response.status}`) : data.error;
213
- const description = typeof data.description === "function" ? await data.description(`HTTP error! status: ${response.status}`) : data.description;
214
- this.create({
215
- id,
216
- type: "error",
217
- title: errorMsg,
218
- description
219
- });
220
- } else if (data.success !== void 0) {
221
- shouldDismiss = false;
222
- const successMsg = typeof data.success === "function" ? await data.success(response) : data.success;
223
- const description = typeof data.description === "function" ? await data.description(response) : data.description;
224
- this.create({
225
- id,
226
- type: "success",
227
- title: successMsg,
228
- description
229
- });
230
- }
231
- }).catch(async error => {
232
- result = ["reject", error];
233
- if (data.error !== void 0) {
234
- shouldDismiss = false;
235
- const errorMsg = typeof data.error === "function" ? await data.error(error) : data.error;
236
- const description = typeof data.description === "function" ? await data.description(error) : data.description;
237
- this.create({
238
- id,
239
- type: "error",
240
- title: errorMsg,
241
- description
242
- });
243
- }
244
- }).finally(() => {
245
- if (shouldDismiss) {
246
- this.dismiss(id);
247
- id = void 0;
248
- }
249
- data.finally?.();
250
- });
251
- const unwrap = () => new Promise((resolve, reject) => originalPromise.then(() => result[0] === "reject" ? reject(result[1]) : resolve(result[1])).catch(reject));
252
- if (typeof id !== "string" && typeof id !== "number") {
253
- return {
254
- unwrap
255
- };
256
- } else {
257
- return Object.assign(id, {
258
- unwrap
259
- });
260
- }
261
- };
262
- /**
263
- * Show a custom JSX toast
264
- */
265
- custom = (jsx, data) => {
266
- const id = data?.id ?? toastsCounter++;
267
- this.create({
268
- jsx: jsx(id),
269
- ...data,
270
- id
271
- });
272
- return id;
273
- };
274
- /**
275
- * Get all active (non-dismissed) toasts
276
- */
277
- getActiveToasts = () => {
278
- return this.toasts.filter(toast2 => !this.dismissedToasts.has(toast2.id));
279
- };
280
- /**
281
- * Get full toast history
282
- */
283
- getHistory = () => {
284
- return this.toasts;
285
- };
286
- }
29
+ var Observer = class {
30
+ subscribers = [];
31
+ toasts = [];
32
+ dismissedToasts = /* @__PURE__ */ new Set();
33
+ /**
34
+ * Subscribe to toast state changes.
35
+ * Returns an unsubscribe function.
36
+ */
37
+ subscribe = (subscriber) => {
38
+ this.subscribers.push(subscriber);
39
+ return () => {
40
+ const index = this.subscribers.indexOf(subscriber);
41
+ if (index > -1) {
42
+ this.subscribers.splice(index, 1);
43
+ }
44
+ };
45
+ };
46
+ /**
47
+ * Publish a toast to all subscribers
48
+ */
49
+ publish = (data) => {
50
+ this.subscribers.forEach((subscriber) => subscriber(data));
51
+ };
52
+ /**
53
+ * Add a new toast to the internal array and publish to subscribers
54
+ */
55
+ addToast = (data) => {
56
+ this.publish(data);
57
+ this.toasts = [...this.toasts, data];
58
+ };
59
+ /**
60
+ * Create or update a toast
61
+ */
62
+ create = (data) => {
63
+ const { title, ...rest } = data;
64
+ const id = typeof data?.id === "number" || typeof data?.id === "string" && data.id.length > 0 ? data.id : toastsCounter++;
65
+ const alreadyExists = this.toasts.find((toast2) => toast2.id === id);
66
+ const dismissible = data.dismissible ?? true;
67
+ if (this.dismissedToasts.has(id)) {
68
+ this.dismissedToasts.delete(id);
69
+ }
70
+ if (alreadyExists) {
71
+ this.toasts = this.toasts.map((toast2) => {
72
+ if (toast2.id === id) {
73
+ this.publish({
74
+ ...toast2,
75
+ ...data,
76
+ id,
77
+ title,
78
+ dismissible
79
+ });
80
+ return {
81
+ ...toast2,
82
+ ...data,
83
+ id,
84
+ title,
85
+ dismissible
86
+ };
87
+ }
88
+ return toast2;
89
+ });
90
+ } else {
91
+ this.addToast({
92
+ title,
93
+ ...rest,
94
+ dismissible,
95
+ id
96
+ });
97
+ }
98
+ return id;
99
+ };
100
+ /**
101
+ * Dismiss a toast by id, or all toasts if no id provided
102
+ */
103
+ dismiss = (id) => {
104
+ if (id !== void 0) {
105
+ this.dismissedToasts.add(id);
106
+ requestAnimationFrame(() => {
107
+ this.subscribers.forEach((subscriber) => subscriber({
108
+ id,
109
+ dismiss: true
110
+ }));
111
+ });
112
+ } else {
113
+ this.toasts.forEach((toast2) => {
114
+ this.subscribers.forEach((subscriber) => subscriber({
115
+ id: toast2.id,
116
+ dismiss: true
117
+ }));
118
+ });
119
+ }
120
+ return id;
121
+ };
122
+ /**
123
+ * Show a basic toast message
124
+ */
125
+ message = (title, data) => {
126
+ return this.create({
127
+ ...data,
128
+ title,
129
+ type: "default"
130
+ });
131
+ };
132
+ /**
133
+ * Show a success toast
134
+ */
135
+ success = (title, data) => {
136
+ return this.create({
137
+ ...data,
138
+ title,
139
+ type: "success"
140
+ });
141
+ };
142
+ /**
143
+ * Show an error toast
144
+ */
145
+ error = (title, data) => {
146
+ return this.create({
147
+ ...data,
148
+ title,
149
+ type: "error"
150
+ });
151
+ };
152
+ /**
153
+ * Show a warning toast
154
+ */
155
+ warning = (title, data) => {
156
+ return this.create({
157
+ ...data,
158
+ title,
159
+ type: "warning"
160
+ });
161
+ };
162
+ /**
163
+ * Show an info toast
164
+ */
165
+ info = (title, data) => {
166
+ return this.create({
167
+ ...data,
168
+ title,
169
+ type: "info"
170
+ });
171
+ };
172
+ /**
173
+ * Show a loading toast
174
+ */
175
+ loading = (title, data) => {
176
+ return this.create({
177
+ ...data,
178
+ title,
179
+ type: "loading"
180
+ });
181
+ };
182
+ /**
183
+ * Show a toast for a promise, automatically transitioning through
184
+ * loading -> success/error states
185
+ */
186
+ promise = (promise, data) => {
187
+ if (!data) {
188
+ return;
189
+ }
190
+ let id = void 0;
191
+ if (data.loading !== void 0) {
192
+ id = this.create({
193
+ promise,
194
+ type: "loading",
195
+ title: data.loading,
196
+ description: typeof data.description !== "function" ? data.description : void 0,
197
+ duration: Number.POSITIVE_INFINITY
198
+ });
199
+ }
200
+ const p = Promise.resolve(promise instanceof Function ? promise() : promise);
201
+ let shouldDismiss = id !== void 0;
202
+ let result;
203
+ const originalPromise = p.then(async (response) => {
204
+ result = ["resolve", response];
205
+ if (isHttpResponse(response) && !response.ok) {
206
+ shouldDismiss = false;
207
+ const errorMsg = typeof data.error === "function" ? await data.error(`HTTP error! status: ${response.status}`) : data.error;
208
+ const description = typeof data.description === "function" ? await data.description(`HTTP error! status: ${response.status}`) : data.description;
209
+ this.create({
210
+ id,
211
+ type: "error",
212
+ title: errorMsg,
213
+ description
214
+ });
215
+ } else if (data.success !== void 0) {
216
+ shouldDismiss = false;
217
+ const successMsg = typeof data.success === "function" ? await data.success(response) : data.success;
218
+ const description = typeof data.description === "function" ? await data.description(response) : data.description;
219
+ this.create({
220
+ id,
221
+ type: "success",
222
+ title: successMsg,
223
+ description
224
+ });
225
+ }
226
+ }).catch(async (error) => {
227
+ result = ["reject", error];
228
+ if (data.error !== void 0) {
229
+ shouldDismiss = false;
230
+ const errorMsg = typeof data.error === "function" ? await data.error(error) : data.error;
231
+ const description = typeof data.description === "function" ? await data.description(error) : data.description;
232
+ this.create({
233
+ id,
234
+ type: "error",
235
+ title: errorMsg,
236
+ description
237
+ });
238
+ }
239
+ }).finally(() => {
240
+ if (shouldDismiss) {
241
+ this.dismiss(id);
242
+ id = void 0;
243
+ }
244
+ data.finally?.();
245
+ });
246
+ const unwrap = () => new Promise((resolve, reject) => originalPromise.then(() => result[0] === "reject" ? reject(result[1]) : resolve(result[1])).catch(reject));
247
+ if (typeof id !== "string" && typeof id !== "number") {
248
+ return { unwrap };
249
+ } else {
250
+ return Object.assign(id, { unwrap });
251
+ }
252
+ };
253
+ /**
254
+ * Show a custom JSX toast
255
+ */
256
+ custom = (jsx, data) => {
257
+ const id = data?.id ?? toastsCounter++;
258
+ this.create({
259
+ jsx: jsx(id),
260
+ ...data,
261
+ id
262
+ });
263
+ return id;
264
+ };
265
+ /**
266
+ * Get all active (non-dismissed) toasts
267
+ */
268
+ getActiveToasts = () => {
269
+ return this.toasts.filter((toast2) => !this.dismissedToasts.has(toast2.id));
270
+ };
271
+ /**
272
+ * Get full toast history
273
+ */
274
+ getHistory = () => {
275
+ return this.toasts;
276
+ };
277
+ };
287
278
  function isHttpResponse(data) {
288
- return data && typeof data === "object" && "ok" in data && typeof data.ok === "boolean" && "status" in data && typeof data.status === "number";
279
+ return data && typeof data === "object" && "ok" in data && typeof data.ok === "boolean" && "status" in data && typeof data.status === "number";
289
280
  }
290
281
  const ToastState = new Observer();
291
282
  const toastFunction = (title, data) => {
292
- return ToastState.create({
293
- ...data,
294
- title
295
- });
283
+ return ToastState.create({
284
+ ...data,
285
+ title
286
+ });
296
287
  };
297
288
  const getHistory = () => ToastState.getHistory();
298
289
  const getToasts = () => ToastState.getActiveToasts();
299
290
  const toast = Object.assign(toastFunction, {
300
- success: ToastState.success,
301
- error: ToastState.error,
302
- warning: ToastState.warning,
303
- info: ToastState.info,
304
- loading: ToastState.loading,
305
- promise: ToastState.promise,
306
- custom: ToastState.custom,
307
- dismiss: ToastState.dismiss,
308
- message: ToastState.message,
309
- getHistory,
310
- getToasts
311
- });
291
+ success: ToastState.success,
292
+ error: ToastState.error,
293
+ warning: ToastState.warning,
294
+ info: ToastState.info,
295
+ loading: ToastState.loading,
296
+ promise: ToastState.promise,
297
+ custom: ToastState.custom,
298
+ dismiss: ToastState.dismiss,
299
+ message: ToastState.message,
300
+ getHistory,
301
+ getToasts
302
+ });