@fluentui/react-toast 0.0.0-nightly-20230704-0416.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 (310) hide show
  1. package/CHANGELOG.json +161 -0
  2. package/CHANGELOG.md +56 -0
  3. package/LICENSE +15 -0
  4. package/README.md +5 -0
  5. package/dist/index.d.ts +485 -0
  6. package/lib/AriaLive.js +1 -0
  7. package/lib/AriaLive.js.map +1 -0
  8. package/lib/Toast.js +1 -0
  9. package/lib/Toast.js.map +1 -0
  10. package/lib/ToastBody.js +1 -0
  11. package/lib/ToastBody.js.map +1 -0
  12. package/lib/ToastContainer.js +1 -0
  13. package/lib/ToastContainer.js.map +1 -0
  14. package/lib/ToastFooter.js +1 -0
  15. package/lib/ToastFooter.js.map +1 -0
  16. package/lib/ToastTitle.js +1 -0
  17. package/lib/ToastTitle.js.map +1 -0
  18. package/lib/ToastTrigger.js +1 -0
  19. package/lib/ToastTrigger.js.map +1 -0
  20. package/lib/Toaster.js +1 -0
  21. package/lib/Toaster.js.map +1 -0
  22. package/lib/components/AriaLive/AriaLive.js +12 -0
  23. package/lib/components/AriaLive/AriaLive.js.map +1 -0
  24. package/lib/components/AriaLive/AriaLive.types.js +1 -0
  25. package/lib/components/AriaLive/AriaLive.types.js.map +1 -0
  26. package/lib/components/AriaLive/index.js +5 -0
  27. package/lib/components/AriaLive/index.js.map +1 -0
  28. package/lib/components/AriaLive/renderAriaLive.js +8 -0
  29. package/lib/components/AriaLive/renderAriaLive.js.map +1 -0
  30. package/lib/components/AriaLive/useAriaLive.js +73 -0
  31. package/lib/components/AriaLive/useAriaLive.js.map +1 -0
  32. package/lib/components/AriaLive/useAriaLiveStyles.styles.js +19 -0
  33. package/lib/components/AriaLive/useAriaLiveStyles.styles.js.map +1 -0
  34. package/lib/components/Timer/Timer.js +21 -0
  35. package/lib/components/Timer/Timer.js.map +1 -0
  36. package/lib/components/Timer/index.js +1 -0
  37. package/lib/components/Timer/index.js.map +1 -0
  38. package/lib/components/Timer/useTimerStyles.styles.js +3 -0
  39. package/lib/components/Timer/useTimerStyles.styles.js.map +1 -0
  40. package/lib/components/Toast/Toast.js +13 -0
  41. package/lib/components/Toast/Toast.js.map +1 -0
  42. package/lib/components/Toast/Toast.types.js +1 -0
  43. package/lib/components/Toast/Toast.types.js.map +1 -0
  44. package/lib/components/Toast/index.js +5 -0
  45. package/lib/components/Toast/index.js.map +1 -0
  46. package/lib/components/Toast/renderToast.js +11 -0
  47. package/lib/components/Toast/renderToast.js.map +1 -0
  48. package/lib/components/Toast/useToast.js +22 -0
  49. package/lib/components/Toast/useToast.js.map +1 -0
  50. package/lib/components/Toast/useToastContextValues.js +6 -0
  51. package/lib/components/Toast/useToastContextValues.js.map +1 -0
  52. package/lib/components/Toast/useToastStyles.styles.js +24 -0
  53. package/lib/components/Toast/useToastStyles.styles.js.map +1 -0
  54. package/lib/components/ToastBody/ToastBody.js +12 -0
  55. package/lib/components/ToastBody/ToastBody.js.map +1 -0
  56. package/lib/components/ToastBody/ToastBody.types.js +1 -0
  57. package/lib/components/ToastBody/ToastBody.types.js.map +1 -0
  58. package/lib/components/ToastBody/index.js +5 -0
  59. package/lib/components/ToastBody/index.js.map +1 -0
  60. package/lib/components/ToastBody/renderToastBody.js +8 -0
  61. package/lib/components/ToastBody/renderToastBody.js.map +1 -0
  62. package/lib/components/ToastBody/useToastBody.js +29 -0
  63. package/lib/components/ToastBody/useToastBody.js.map +1 -0
  64. package/lib/components/ToastBody/useToastBodyStyles.styles.js +32 -0
  65. package/lib/components/ToastBody/useToastBodyStyles.styles.js.map +1 -0
  66. package/lib/components/ToastContainer/ToastContainer.js +13 -0
  67. package/lib/components/ToastContainer/ToastContainer.js.map +1 -0
  68. package/lib/components/ToastContainer/ToastContainer.types.js +1 -0
  69. package/lib/components/ToastContainer/ToastContainer.types.js.map +1 -0
  70. package/lib/components/ToastContainer/index.js +6 -0
  71. package/lib/components/ToastContainer/index.js.map +1 -0
  72. package/lib/components/ToastContainer/renderToastContainer.js +21 -0
  73. package/lib/components/ToastContainer/renderToastContainer.js.map +1 -0
  74. package/lib/components/ToastContainer/useToastContainer.js +219 -0
  75. package/lib/components/ToastContainer/useToastContainer.js.map +1 -0
  76. package/lib/components/ToastContainer/useToastContainerContextValues.js +18 -0
  77. package/lib/components/ToastContainer/useToastContainerContextValues.js.map +1 -0
  78. package/lib/components/ToastContainer/useToastContainerStyles.styles.js +36 -0
  79. package/lib/components/ToastContainer/useToastContainerStyles.styles.js.map +1 -0
  80. package/lib/components/ToastFooter/ToastFooter.js +12 -0
  81. package/lib/components/ToastFooter/ToastFooter.js.map +1 -0
  82. package/lib/components/ToastFooter/ToastFooter.types.js +1 -0
  83. package/lib/components/ToastFooter/ToastFooter.types.js.map +1 -0
  84. package/lib/components/ToastFooter/index.js +5 -0
  85. package/lib/components/ToastFooter/index.js.map +1 -0
  86. package/lib/components/ToastFooter/renderToastFooter.js +8 -0
  87. package/lib/components/ToastFooter/renderToastFooter.js.map +1 -0
  88. package/lib/components/ToastFooter/useToastFooter.js +21 -0
  89. package/lib/components/ToastFooter/useToastFooter.js.map +1 -0
  90. package/lib/components/ToastFooter/useToastFooterStyles.styles.js +17 -0
  91. package/lib/components/ToastFooter/useToastFooterStyles.styles.js.map +1 -0
  92. package/lib/components/ToastTitle/ToastTitle.js +12 -0
  93. package/lib/components/ToastTitle/ToastTitle.js.map +1 -0
  94. package/lib/components/ToastTitle/ToastTitle.types.js +1 -0
  95. package/lib/components/ToastTitle/ToastTitle.types.js.map +1 -0
  96. package/lib/components/ToastTitle/index.js +5 -0
  97. package/lib/components/ToastTitle/index.js.map +1 -0
  98. package/lib/components/ToastTitle/renderToastTitle.js +8 -0
  99. package/lib/components/ToastTitle/renderToastTitle.js.map +1 -0
  100. package/lib/components/ToastTitle/useToastTitle.js +54 -0
  101. package/lib/components/ToastTitle/useToastTitle.js.map +1 -0
  102. package/lib/components/ToastTitle/useToastTitleStyles.styles.js +78 -0
  103. package/lib/components/ToastTitle/useToastTitleStyles.styles.js.map +1 -0
  104. package/lib/components/ToastTrigger/ToastTrigger.js +10 -0
  105. package/lib/components/ToastTrigger/ToastTrigger.js.map +1 -0
  106. package/lib/components/ToastTrigger/ToastTrigger.types.js +1 -0
  107. package/lib/components/ToastTrigger/ToastTrigger.types.js.map +1 -0
  108. package/lib/components/ToastTrigger/index.js +4 -0
  109. package/lib/components/ToastTrigger/index.js.map +1 -0
  110. package/lib/components/ToastTrigger/renderToastTrigger.js +5 -0
  111. package/lib/components/ToastTrigger/renderToastTrigger.js.map +1 -0
  112. package/lib/components/ToastTrigger/useToastTrigger.js +36 -0
  113. package/lib/components/ToastTrigger/useToastTrigger.js.map +1 -0
  114. package/lib/components/Toaster/Toaster.js +12 -0
  115. package/lib/components/Toaster/Toaster.js.map +1 -0
  116. package/lib/components/Toaster/Toaster.types.js +1 -0
  117. package/lib/components/Toaster/Toaster.types.js.map +1 -0
  118. package/lib/components/Toaster/index.js +5 -0
  119. package/lib/components/Toaster/index.js.map +1 -0
  120. package/lib/components/Toaster/renderToaster.js +14 -0
  121. package/lib/components/Toaster/renderToaster.js.map +1 -0
  122. package/lib/components/Toaster/useToaster.js +76 -0
  123. package/lib/components/Toaster/useToaster.js.map +1 -0
  124. package/lib/components/Toaster/useToasterStyles.styles.js +43 -0
  125. package/lib/components/Toaster/useToasterStyles.styles.js.map +1 -0
  126. package/lib/contexts/toastContainerContext.js +11 -0
  127. package/lib/contexts/toastContainerContext.js.map +1 -0
  128. package/lib/index.js +7 -0
  129. package/lib/index.js.map +1 -0
  130. package/lib/state/constants.js +14 -0
  131. package/lib/state/constants.js.map +1 -0
  132. package/lib/state/index.js +5 -0
  133. package/lib/state/index.js.map +1 -0
  134. package/lib/state/types.js +1 -0
  135. package/lib/state/types.js.map +1 -0
  136. package/lib/state/useToastController.js +57 -0
  137. package/lib/state/useToastController.js.map +1 -0
  138. package/lib/state/useToaster.js +162 -0
  139. package/lib/state/useToaster.js.map +1 -0
  140. package/lib/state/vanilla/createToaster.js +137 -0
  141. package/lib/state/vanilla/createToaster.js.map +1 -0
  142. package/lib/state/vanilla/dismissAllToasts.js +11 -0
  143. package/lib/state/vanilla/dismissAllToasts.js.map +1 -0
  144. package/lib/state/vanilla/dismissToast.js +12 -0
  145. package/lib/state/vanilla/dismissToast.js.map +1 -0
  146. package/lib/state/vanilla/dispatchToast.js +16 -0
  147. package/lib/state/vanilla/dispatchToast.js.map +1 -0
  148. package/lib/state/vanilla/getPositionStyles.js +40 -0
  149. package/lib/state/vanilla/getPositionStyles.js.map +1 -0
  150. package/lib/state/vanilla/index.js +8 -0
  151. package/lib/state/vanilla/index.js.map +1 -0
  152. package/lib/state/vanilla/pauseToast.js +12 -0
  153. package/lib/state/vanilla/pauseToast.js.map +1 -0
  154. package/lib/state/vanilla/playToast.js +12 -0
  155. package/lib/state/vanilla/playToast.js.map +1 -0
  156. package/lib/state/vanilla/updateToast.js +9 -0
  157. package/lib/state/vanilla/updateToast.js.map +1 -0
  158. package/lib-commonjs/AriaLive.js +6 -0
  159. package/lib-commonjs/AriaLive.js.map +1 -0
  160. package/lib-commonjs/Toast.js +6 -0
  161. package/lib-commonjs/Toast.js.map +1 -0
  162. package/lib-commonjs/ToastBody.js +6 -0
  163. package/lib-commonjs/ToastBody.js.map +1 -0
  164. package/lib-commonjs/ToastContainer.js +6 -0
  165. package/lib-commonjs/ToastContainer.js.map +1 -0
  166. package/lib-commonjs/ToastFooter.js +6 -0
  167. package/lib-commonjs/ToastFooter.js.map +1 -0
  168. package/lib-commonjs/ToastTitle.js +6 -0
  169. package/lib-commonjs/ToastTitle.js.map +1 -0
  170. package/lib-commonjs/ToastTrigger.js +6 -0
  171. package/lib-commonjs/ToastTrigger.js.map +1 -0
  172. package/lib-commonjs/Toaster.js +6 -0
  173. package/lib-commonjs/Toaster.js.map +1 -0
  174. package/lib-commonjs/components/AriaLive/AriaLive.js +19 -0
  175. package/lib-commonjs/components/AriaLive/AriaLive.js.map +1 -0
  176. package/lib-commonjs/components/AriaLive/AriaLive.types.js +6 -0
  177. package/lib-commonjs/components/AriaLive/AriaLive.types.js.map +1 -0
  178. package/lib-commonjs/components/AriaLive/index.js +10 -0
  179. package/lib-commonjs/components/AriaLive/index.js.map +1 -0
  180. package/lib-commonjs/components/AriaLive/renderAriaLive.js +14 -0
  181. package/lib-commonjs/components/AriaLive/renderAriaLive.js.map +1 -0
  182. package/lib-commonjs/components/AriaLive/useAriaLive.js +75 -0
  183. package/lib-commonjs/components/AriaLive/useAriaLive.js.map +1 -0
  184. package/lib-commonjs/components/AriaLive/useAriaLiveStyles.styles.js +31 -0
  185. package/lib-commonjs/components/AriaLive/useAriaLiveStyles.styles.js.map +1 -0
  186. package/lib-commonjs/components/Timer/Timer.js +30 -0
  187. package/lib-commonjs/components/Timer/Timer.js.map +1 -0
  188. package/lib-commonjs/components/Timer/index.js +6 -0
  189. package/lib-commonjs/components/Timer/index.js.map +1 -0
  190. package/lib-commonjs/components/Timer/useTimerStyles.styles.js +16 -0
  191. package/lib-commonjs/components/Timer/useTimerStyles.styles.js.map +1 -0
  192. package/lib-commonjs/components/Toast/Toast.js +20 -0
  193. package/lib-commonjs/components/Toast/Toast.js.map +1 -0
  194. package/lib-commonjs/components/Toast/Toast.types.js +4 -0
  195. package/lib-commonjs/components/Toast/Toast.types.js.map +1 -0
  196. package/lib-commonjs/components/Toast/index.js +10 -0
  197. package/lib-commonjs/components/Toast/index.js.map +1 -0
  198. package/lib-commonjs/components/Toast/renderToast.js +17 -0
  199. package/lib-commonjs/components/Toast/renderToast.js.map +1 -0
  200. package/lib-commonjs/components/Toast/useToast.js +23 -0
  201. package/lib-commonjs/components/Toast/useToast.js.map +1 -0
  202. package/lib-commonjs/components/Toast/useToastContextValues.js +14 -0
  203. package/lib-commonjs/components/Toast/useToastContextValues.js.map +1 -0
  204. package/lib-commonjs/components/Toast/useToastStyles.styles.js +39 -0
  205. package/lib-commonjs/components/Toast/useToastStyles.styles.js.map +1 -0
  206. package/lib-commonjs/components/ToastBody/ToastBody.js +19 -0
  207. package/lib-commonjs/components/ToastBody/ToastBody.js.map +1 -0
  208. package/lib-commonjs/components/ToastBody/ToastBody.types.js +4 -0
  209. package/lib-commonjs/components/ToastBody/ToastBody.types.js.map +1 -0
  210. package/lib-commonjs/components/ToastBody/index.js +10 -0
  211. package/lib-commonjs/components/ToastBody/index.js.map +1 -0
  212. package/lib-commonjs/components/ToastBody/renderToastBody.js +14 -0
  213. package/lib-commonjs/components/ToastBody/renderToastBody.js.map +1 -0
  214. package/lib-commonjs/components/ToastBody/useToastBody.js +30 -0
  215. package/lib-commonjs/components/ToastBody/useToastBody.js.map +1 -0
  216. package/lib-commonjs/components/ToastBody/useToastBodyStyles.styles.js +47 -0
  217. package/lib-commonjs/components/ToastBody/useToastBodyStyles.styles.js.map +1 -0
  218. package/lib-commonjs/components/ToastContainer/ToastContainer.js +20 -0
  219. package/lib-commonjs/components/ToastContainer/ToastContainer.js.map +1 -0
  220. package/lib-commonjs/components/ToastContainer/ToastContainer.types.js +6 -0
  221. package/lib-commonjs/components/ToastContainer/ToastContainer.types.js.map +1 -0
  222. package/lib-commonjs/components/ToastContainer/index.js +11 -0
  223. package/lib-commonjs/components/ToastContainer/index.js.map +1 -0
  224. package/lib-commonjs/components/ToastContainer/renderToastContainer.js +27 -0
  225. package/lib-commonjs/components/ToastContainer/renderToastContainer.js.map +1 -0
  226. package/lib-commonjs/components/ToastContainer/useToastContainer.js +220 -0
  227. package/lib-commonjs/components/ToastContainer/useToastContainer.js.map +1 -0
  228. package/lib-commonjs/components/ToastContainer/useToastContainerContextValues.js +27 -0
  229. package/lib-commonjs/components/ToastContainer/useToastContainerContextValues.js.map +1 -0
  230. package/lib-commonjs/components/ToastContainer/useToastContainerStyles.styles.js +64 -0
  231. package/lib-commonjs/components/ToastContainer/useToastContainerStyles.styles.js.map +1 -0
  232. package/lib-commonjs/components/ToastFooter/ToastFooter.js +19 -0
  233. package/lib-commonjs/components/ToastFooter/ToastFooter.js.map +1 -0
  234. package/lib-commonjs/components/ToastFooter/ToastFooter.types.js +4 -0
  235. package/lib-commonjs/components/ToastFooter/ToastFooter.types.js.map +1 -0
  236. package/lib-commonjs/components/ToastFooter/index.js +10 -0
  237. package/lib-commonjs/components/ToastFooter/index.js.map +1 -0
  238. package/lib-commonjs/components/ToastFooter/renderToastFooter.js +14 -0
  239. package/lib-commonjs/components/ToastFooter/renderToastFooter.js.map +1 -0
  240. package/lib-commonjs/components/ToastFooter/useToastFooter.js +22 -0
  241. package/lib-commonjs/components/ToastFooter/useToastFooter.js.map +1 -0
  242. package/lib-commonjs/components/ToastFooter/useToastFooterStyles.styles.js +28 -0
  243. package/lib-commonjs/components/ToastFooter/useToastFooterStyles.styles.js.map +1 -0
  244. package/lib-commonjs/components/ToastTitle/ToastTitle.js +19 -0
  245. package/lib-commonjs/components/ToastTitle/ToastTitle.js.map +1 -0
  246. package/lib-commonjs/components/ToastTitle/ToastTitle.types.js +4 -0
  247. package/lib-commonjs/components/ToastTitle/ToastTitle.types.js.map +1 -0
  248. package/lib-commonjs/components/ToastTitle/index.js +10 -0
  249. package/lib-commonjs/components/ToastTitle/index.js.map +1 -0
  250. package/lib-commonjs/components/ToastTitle/renderToastTitle.js +14 -0
  251. package/lib-commonjs/components/ToastTitle/renderToastTitle.js.map +1 -0
  252. package/lib-commonjs/components/ToastTitle/useToastTitle.js +55 -0
  253. package/lib-commonjs/components/ToastTitle/useToastTitle.js.map +1 -0
  254. package/lib-commonjs/components/ToastTitle/useToastTitleStyles.styles.js +107 -0
  255. package/lib-commonjs/components/ToastTitle/useToastTitleStyles.styles.js.map +1 -0
  256. package/lib-commonjs/components/ToastTrigger/ToastTrigger.js +17 -0
  257. package/lib-commonjs/components/ToastTrigger/ToastTrigger.js.map +1 -0
  258. package/lib-commonjs/components/ToastTrigger/ToastTrigger.types.js +6 -0
  259. package/lib-commonjs/components/ToastTrigger/ToastTrigger.types.js.map +1 -0
  260. package/lib-commonjs/components/ToastTrigger/index.js +9 -0
  261. package/lib-commonjs/components/ToastTrigger/index.js.map +1 -0
  262. package/lib-commonjs/components/ToastTrigger/renderToastTrigger.js +13 -0
  263. package/lib-commonjs/components/ToastTrigger/renderToastTrigger.js.map +1 -0
  264. package/lib-commonjs/components/ToastTrigger/useToastTrigger.js +37 -0
  265. package/lib-commonjs/components/ToastTrigger/useToastTrigger.js.map +1 -0
  266. package/lib-commonjs/components/Toaster/Toaster.js +19 -0
  267. package/lib-commonjs/components/Toaster/Toaster.js.map +1 -0
  268. package/lib-commonjs/components/Toaster/Toaster.types.js +4 -0
  269. package/lib-commonjs/components/Toaster/Toaster.types.js.map +1 -0
  270. package/lib-commonjs/components/Toaster/index.js +10 -0
  271. package/lib-commonjs/components/Toaster/index.js.map +1 -0
  272. package/lib-commonjs/components/Toaster/renderToaster.js +20 -0
  273. package/lib-commonjs/components/Toaster/renderToaster.js.map +1 -0
  274. package/lib-commonjs/components/Toaster/useToaster.js +81 -0
  275. package/lib-commonjs/components/Toaster/useToaster.js.map +1 -0
  276. package/lib-commonjs/components/Toaster/useToasterStyles.styles.js +54 -0
  277. package/lib-commonjs/components/Toaster/useToasterStyles.styles.js.map +1 -0
  278. package/lib-commonjs/contexts/toastContainerContext.js +26 -0
  279. package/lib-commonjs/contexts/toastContainerContext.js.map +1 -0
  280. package/lib-commonjs/index.js +48 -0
  281. package/lib-commonjs/index.js.map +1 -0
  282. package/lib-commonjs/state/constants.js +28 -0
  283. package/lib-commonjs/state/constants.js.map +1 -0
  284. package/lib-commonjs/state/index.js +20 -0
  285. package/lib-commonjs/state/index.js.map +1 -0
  286. package/lib-commonjs/state/types.js +6 -0
  287. package/lib-commonjs/state/types.js.map +1 -0
  288. package/lib-commonjs/state/useToastController.js +63 -0
  289. package/lib-commonjs/state/useToastController.js.map +1 -0
  290. package/lib-commonjs/state/useToaster.js +171 -0
  291. package/lib-commonjs/state/useToaster.js.map +1 -0
  292. package/lib-commonjs/state/vanilla/createToaster.js +142 -0
  293. package/lib-commonjs/state/vanilla/createToaster.js.map +1 -0
  294. package/lib-commonjs/state/vanilla/dismissAllToasts.js +19 -0
  295. package/lib-commonjs/state/vanilla/dismissAllToasts.js.map +1 -0
  296. package/lib-commonjs/state/vanilla/dismissToast.js +20 -0
  297. package/lib-commonjs/state/vanilla/dismissToast.js.map +1 -0
  298. package/lib-commonjs/state/vanilla/dispatchToast.js +24 -0
  299. package/lib-commonjs/state/vanilla/dispatchToast.js.map +1 -0
  300. package/lib-commonjs/state/vanilla/getPositionStyles.js +48 -0
  301. package/lib-commonjs/state/vanilla/getPositionStyles.js.map +1 -0
  302. package/lib-commonjs/state/vanilla/index.js +13 -0
  303. package/lib-commonjs/state/vanilla/index.js.map +1 -0
  304. package/lib-commonjs/state/vanilla/pauseToast.js +20 -0
  305. package/lib-commonjs/state/vanilla/pauseToast.js.map +1 -0
  306. package/lib-commonjs/state/vanilla/playToast.js +20 -0
  307. package/lib-commonjs/state/vanilla/playToast.js.map +1 -0
  308. package/lib-commonjs/state/vanilla/updateToast.js +17 -0
  309. package/lib-commonjs/state/vanilla/updateToast.js.map +1 -0
  310. package/package.json +66 -0
@@ -0,0 +1,162 @@
1
+ import * as React from 'react';
2
+ import { isHTMLElement, useEventCallback, useForceUpdate } from '@fluentui/react-utilities';
3
+ import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
4
+ import { createToaster } from './vanilla';
5
+ import { EVENTS } from './constants';
6
+ export function useToaster(options = {}) {
7
+ const forceUpdate = useForceUpdate();
8
+ const { toasterId: userToasterId , shortcuts } = options;
9
+ // Currently the toaster options can never be changed at runtime
10
+ const [toaster] = React.useState(()=>createToaster(options));
11
+ const { targetDocument } = useFluent();
12
+ const lastActiveElementRef = React.useRef(null);
13
+ const isCorrectToaster = useEventCallback((toasterId)=>{
14
+ return toasterId === userToasterId;
15
+ });
16
+ const isFocusShortcut = useEventCallback((e)=>{
17
+ if (shortcuts === null || shortcuts === void 0 ? void 0 : shortcuts.focus) {
18
+ return shortcuts.focus(e);
19
+ }
20
+ });
21
+ const tryRestoreFocus = React.useCallback(()=>{
22
+ var _lastActiveElementRef_current;
23
+ (_lastActiveElementRef_current = lastActiveElementRef.current) === null || _lastActiveElementRef_current === void 0 ? void 0 : _lastActiveElementRef_current.focus();
24
+ lastActiveElementRef.current = null;
25
+ }, []);
26
+ const pauseAllToasts = React.useCallback(()=>{
27
+ toaster.visibleToasts.forEach((toastId)=>{
28
+ var _toast_imperativeRef_current;
29
+ const toast = toaster.toasts.get(toastId);
30
+ (_toast_imperativeRef_current = toast === null || toast === void 0 ? void 0 : toast.imperativeRef.current) === null || _toast_imperativeRef_current === void 0 ? void 0 : _toast_imperativeRef_current.pause();
31
+ });
32
+ }, [
33
+ toaster
34
+ ]);
35
+ const playAllToasts = React.useCallback(()=>{
36
+ toaster.visibleToasts.forEach((toastId)=>{
37
+ var _toast_imperativeRef_current;
38
+ const toast = toaster.toasts.get(toastId);
39
+ (_toast_imperativeRef_current = toast === null || toast === void 0 ? void 0 : toast.imperativeRef.current) === null || _toast_imperativeRef_current === void 0 ? void 0 : _toast_imperativeRef_current.play();
40
+ });
41
+ }, [
42
+ toaster
43
+ ]);
44
+ const getMostRecentVisibleToast = React.useCallback(()=>{
45
+ return Array.from(toaster.visibleToasts).reduce((cur, next)=>{
46
+ const toast = toaster.toasts.get(next);
47
+ if (!toast) {
48
+ return cur;
49
+ }
50
+ if (!cur) {
51
+ return toast;
52
+ }
53
+ if (cur.order < (toast === null || toast === void 0 ? void 0 : toast.order)) {
54
+ return toast;
55
+ }
56
+ return cur;
57
+ }, undefined);
58
+ }, [
59
+ toaster
60
+ ]);
61
+ React.useEffect(()=>{
62
+ if (!targetDocument) {
63
+ return;
64
+ }
65
+ const addToastListener = (eventType, callback)=>{
66
+ const listener = (e)=>{
67
+ if (!isCorrectToaster(e.detail.toasterId)) {
68
+ return;
69
+ }
70
+ callback(e);
71
+ forceUpdate();
72
+ };
73
+ targetDocument.addEventListener(eventType, listener);
74
+ return ()=>targetDocument.removeEventListener(eventType, listener);
75
+ };
76
+ const buildToast = (e)=>{
77
+ toaster.buildToast(e.detail, forceUpdate);
78
+ };
79
+ const dismissToast = (e)=>{
80
+ toaster.dismissToast(e.detail.toastId);
81
+ };
82
+ const updateToast = (e)=>{
83
+ toaster.updateToast(e.detail);
84
+ };
85
+ const dismissAllToasts = (e)=>{
86
+ toaster.dismissAllToasts();
87
+ };
88
+ const pauseToast = (e)=>{
89
+ const toast = toaster.toasts.get(e.detail.toastId);
90
+ if (toast) {
91
+ var _toast_imperativeRef_current;
92
+ (_toast_imperativeRef_current = toast.imperativeRef.current) === null || _toast_imperativeRef_current === void 0 ? void 0 : _toast_imperativeRef_current.pause();
93
+ }
94
+ };
95
+ const playToast = (e)=>{
96
+ const toast = toaster.toasts.get(e.detail.toastId);
97
+ if (toast) {
98
+ var _toast_imperativeRef_current;
99
+ (_toast_imperativeRef_current = toast.imperativeRef.current) === null || _toast_imperativeRef_current === void 0 ? void 0 : _toast_imperativeRef_current.play();
100
+ }
101
+ };
102
+ const cleanupBuildListener = addToastListener(EVENTS.show, buildToast);
103
+ const cleanupUpdateListener = addToastListener(EVENTS.update, updateToast);
104
+ const cleanupDismissListener = addToastListener(EVENTS.dismiss, dismissToast);
105
+ const cleanupDismissAllListener = addToastListener(EVENTS.dismissAll, dismissAllToasts);
106
+ const cleanupPauseListener = addToastListener(EVENTS.pause, pauseToast);
107
+ const cleanupPlayListener = addToastListener(EVENTS.play, playToast);
108
+ const focusShortcutListener = (e)=>{
109
+ if (isFocusShortcut(e)) {
110
+ pauseAllToasts();
111
+ const mostRecentToast = getMostRecentVisibleToast();
112
+ if (mostRecentToast) {
113
+ var _mostRecentToast_imperativeRef_current;
114
+ lastActiveElementRef.current = isHTMLElement(targetDocument.activeElement) ? targetDocument.activeElement : null;
115
+ (_mostRecentToast_imperativeRef_current = mostRecentToast.imperativeRef.current) === null || _mostRecentToast_imperativeRef_current === void 0 ? void 0 : _mostRecentToast_imperativeRef_current.focus();
116
+ }
117
+ }
118
+ };
119
+ targetDocument.addEventListener('keydown', focusShortcutListener);
120
+ return ()=>{
121
+ cleanupBuildListener();
122
+ cleanupDismissAllListener();
123
+ cleanupUpdateListener();
124
+ cleanupDismissListener();
125
+ cleanupPauseListener();
126
+ cleanupPlayListener();
127
+ targetDocument.removeEventListener('keydown', focusShortcutListener);
128
+ };
129
+ }, [
130
+ toaster,
131
+ forceUpdate,
132
+ targetDocument,
133
+ isCorrectToaster,
134
+ pauseAllToasts,
135
+ getMostRecentVisibleToast,
136
+ isFocusShortcut
137
+ ]);
138
+ const toastsToRender = (()=>{
139
+ if (!toaster) {
140
+ return new Map();
141
+ }
142
+ const toRender = new Map();
143
+ const toasts = Array.from(toaster.toasts.values());
144
+ toasts.forEach((toast)=>{
145
+ const { position } = toast;
146
+ toRender.has(position) || toRender.set(position, []);
147
+ if (position.startsWith('bottom')) {
148
+ toRender.get(position).push(toast);
149
+ } else {
150
+ toRender.get(position).unshift(toast);
151
+ }
152
+ });
153
+ return toRender;
154
+ })();
155
+ return {
156
+ isToastVisible: toaster.isToastVisible,
157
+ toastsToRender,
158
+ pauseAllToasts,
159
+ playAllToasts,
160
+ tryRestoreFocus
161
+ };
162
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useToaster.ts"],"sourcesContent":["import * as React from 'react';\nimport { isHTMLElement, useEventCallback, useForceUpdate } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { createToaster } from './vanilla';\nimport type {\n CommonToastDetail,\n ShowToastEventDetail,\n Toast,\n ToastListenerMap,\n ToastPosition,\n ToasterId,\n ToasterOptions,\n} from './types';\nimport { EVENTS } from './constants';\n\nexport function useToaster<TElement extends HTMLElement = HTMLDivElement>(options: Partial<ToasterOptions> = {}) {\n const forceUpdate = useForceUpdate();\n const { toasterId: userToasterId, shortcuts } = options;\n // Currently the toaster options can never be changed at runtime\n const [toaster] = React.useState(() => createToaster(options));\n const { targetDocument } = useFluent();\n\n const lastActiveElementRef = React.useRef<HTMLElement | null>(null);\n\n const isCorrectToaster = useEventCallback((toasterId: ToasterId | undefined) => {\n return toasterId === userToasterId;\n });\n\n const isFocusShortcut = useEventCallback((e: KeyboardEvent) => {\n if (shortcuts?.focus) {\n return shortcuts.focus(e);\n }\n });\n\n const tryRestoreFocus = React.useCallback(() => {\n lastActiveElementRef.current?.focus();\n lastActiveElementRef.current = null;\n }, []);\n\n const pauseAllToasts = React.useCallback(() => {\n toaster.visibleToasts.forEach(toastId => {\n const toast = toaster.toasts.get(toastId);\n toast?.imperativeRef.current?.pause();\n });\n }, [toaster]);\n\n const playAllToasts = React.useCallback(() => {\n toaster.visibleToasts.forEach(toastId => {\n const toast = toaster.toasts.get(toastId);\n toast?.imperativeRef.current?.play();\n });\n }, [toaster]);\n\n const getMostRecentVisibleToast = React.useCallback(() => {\n return Array.from(toaster.visibleToasts).reduce((cur, next) => {\n const toast = toaster.toasts.get(next);\n if (!toast) {\n return cur;\n }\n\n if (!cur) {\n return toast;\n }\n\n if (cur.order < toast?.order) {\n return toast;\n }\n\n return cur;\n }, undefined as Toast | undefined);\n }, [toaster]);\n\n React.useEffect(() => {\n if (!targetDocument) {\n return;\n }\n\n const addToastListener = <TType extends keyof ToastListenerMap>(\n eventType: TType,\n callback: ToastListenerMap[TType],\n ) => {\n const listener: ToastListenerMap[TType] = (e: CustomEvent<CommonToastDetail>) => {\n if (!isCorrectToaster(e.detail.toasterId)) {\n return;\n }\n\n callback(e as CustomEvent<ShowToastEventDetail>);\n forceUpdate();\n };\n\n targetDocument.addEventListener(eventType, listener as () => void);\n return () => targetDocument.removeEventListener(eventType, listener as () => void);\n };\n\n const buildToast: ToastListenerMap[typeof EVENTS.show] = e => {\n toaster.buildToast(e.detail, forceUpdate);\n };\n\n const dismissToast: ToastListenerMap[typeof EVENTS.dismiss] = e => {\n toaster.dismissToast(e.detail.toastId);\n };\n\n const updateToast: ToastListenerMap[typeof EVENTS.update] = e => {\n toaster.updateToast(e.detail);\n };\n\n const dismissAllToasts: ToastListenerMap[typeof EVENTS.dismissAll] = e => {\n toaster.dismissAllToasts();\n };\n\n const pauseToast: ToastListenerMap[typeof EVENTS.pause] = e => {\n const toast = toaster.toasts.get(e.detail.toastId);\n if (toast) {\n toast.imperativeRef.current?.pause();\n }\n };\n\n const playToast: ToastListenerMap[typeof EVENTS.play] = e => {\n const toast = toaster.toasts.get(e.detail.toastId);\n if (toast) {\n toast.imperativeRef.current?.play();\n }\n };\n\n const cleanupBuildListener = addToastListener(EVENTS.show, buildToast);\n const cleanupUpdateListener = addToastListener(EVENTS.update, updateToast);\n const cleanupDismissListener = addToastListener(EVENTS.dismiss, dismissToast);\n const cleanupDismissAllListener = addToastListener(EVENTS.dismissAll, dismissAllToasts);\n const cleanupPauseListener = addToastListener(EVENTS.pause, pauseToast);\n const cleanupPlayListener = addToastListener(EVENTS.play, playToast);\n\n const focusShortcutListener = (e: KeyboardEvent) => {\n if (isFocusShortcut(e)) {\n pauseAllToasts();\n const mostRecentToast = getMostRecentVisibleToast();\n\n if (mostRecentToast) {\n lastActiveElementRef.current = isHTMLElement(targetDocument.activeElement)\n ? targetDocument.activeElement\n : null;\n mostRecentToast.imperativeRef.current?.focus();\n }\n }\n };\n\n targetDocument.addEventListener('keydown', focusShortcutListener);\n\n return () => {\n cleanupBuildListener();\n cleanupDismissAllListener();\n cleanupUpdateListener();\n cleanupDismissListener();\n cleanupPauseListener();\n cleanupPlayListener();\n\n targetDocument.removeEventListener('keydown', focusShortcutListener);\n };\n }, [\n toaster,\n forceUpdate,\n targetDocument,\n isCorrectToaster,\n pauseAllToasts,\n getMostRecentVisibleToast,\n isFocusShortcut,\n ]);\n\n const toastsToRender = (() => {\n if (!toaster) {\n return new Map<ToastPosition, Toast[]>();\n }\n\n const toRender = new Map<ToastPosition, Toast[]>();\n const toasts = Array.from(toaster.toasts.values());\n\n toasts.forEach(toast => {\n const { position } = toast;\n toRender.has(position) || toRender.set(position, []);\n if (position.startsWith('bottom')) {\n toRender.get(position)!.push(toast);\n } else {\n toRender.get(position)!.unshift(toast);\n }\n });\n\n return toRender;\n })();\n\n return {\n isToastVisible: toaster.isToastVisible,\n toastsToRender,\n pauseAllToasts,\n playAllToasts,\n tryRestoreFocus,\n };\n}\n"],"names":["React","isHTMLElement","useEventCallback","useForceUpdate","useFluent_unstable","useFluent","createToaster","EVENTS","useToaster","options","forceUpdate","toasterId","userToasterId","shortcuts","toaster","useState","targetDocument","lastActiveElementRef","useRef","isCorrectToaster","isFocusShortcut","e","focus","tryRestoreFocus","useCallback","current","pauseAllToasts","visibleToasts","forEach","toastId","toast","toasts","get","imperativeRef","pause","playAllToasts","play","getMostRecentVisibleToast","Array","from","reduce","cur","next","order","undefined","useEffect","addToastListener","eventType","callback","listener","detail","addEventListener","removeEventListener","buildToast","dismissToast","updateToast","dismissAllToasts","pauseToast","playToast","cleanupBuildListener","show","cleanupUpdateListener","update","cleanupDismissListener","dismiss","cleanupDismissAllListener","dismissAll","cleanupPauseListener","cleanupPlayListener","focusShortcutListener","mostRecentToast","activeElement","toastsToRender","Map","toRender","values","position","has","set","startsWith","push","unshift","isToastVisible"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,aAAa,EAAEC,gBAAgB,EAAEC,cAAc,QAAQ,4BAA4B;AAC5F,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,aAAa,QAAQ,YAAY;AAU1C,SAASC,MAAM,QAAQ,cAAc;AAErC,OAAO,SAASC,WAA0DC,UAAmC,CAAC,CAAC,EAAE;IAC/G,MAAMC,cAAcP;IACpB,MAAM,EAAEQ,WAAWC,cAAa,EAAEC,UAAS,EAAE,GAAGJ;IAChD,gEAAgE;IAChE,MAAM,CAACK,QAAQ,GAAGd,MAAMe,QAAQ,CAAC,IAAMT,cAAcG;IACrD,MAAM,EAAEO,eAAc,EAAE,GAAGX;IAE3B,MAAMY,uBAAuBjB,MAAMkB,MAAM,CAAqB,IAAI;IAElE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AAC1D,SAAS;YACZ,OAAO,IAAI2D;QACb,CAAC;QAED,MAAMC,WAAW,IAAID;QACrB,MAAM1C,SAASO,MAAMC,IAAI,CAACzB,QAAQiB,MAAM,CAAC4C,MAAM;QAE/C5C,OAAOH,OAAO,CAACE,CAAAA,QAAS;YACtB,MAAM,EAAE8C,SAAQ,EAAE,GAAG9C;YACrB4C,SAASG,GAAG,CAACD,aAAaF,SAASI,GAAG,CAACF,UAAU,EAAE;YACnD,IAAIA,SAASG,UAAU,CAAC,WAAW;gBACjCL,SAAS1C,GAAG,CAAC4C,UAAWI,IAAI,CAAClD;YAC/B,OAAO;gBACL4C,SAAS1C,GAAG,CAAC4C,UAAWK,OAAO,CAACnD;YAClC,CAAC;QACH;QAEA,OAAO4C;IACT,CAAA;IAEA,OAAO;QACLQ,gBAAgBpE,QAAQoE,cAAc;QACtCV;QACA9C;QACAS;QACAZ;IACF;AACF,CAAC"}
@@ -0,0 +1,137 @@
1
+ import * as React from 'react';
2
+ import { createPriorityQueue } from '@fluentui/react-utilities';
3
+ function assignDefined(a, b) {
4
+ // This cast is required, as Object.entries will return string as key which is not indexable
5
+ for (const [key, prop] of Object.entries(b)){
6
+ // eslint-disable-next-line eqeqeq
7
+ if (prop != undefined) {
8
+ a[key] = prop;
9
+ }
10
+ }
11
+ }
12
+ const defaulToastOptions = {
13
+ onStatusChange: undefined,
14
+ priority: 0,
15
+ pauseOnHover: false,
16
+ pauseOnWindowBlur: false,
17
+ position: 'bottom-end',
18
+ timeout: 3000
19
+ };
20
+ // Multiple toasts can be dispatched in a single tick, use counter to prevent collisions
21
+ let counter = 0;
22
+ /**
23
+ * Toast are managed outside of the react lifecycle because they can be
24
+ * dispatched imperatively. Therefore the state of toast visibility can't
25
+ * really be managed properly by a declarative lifecycle.
26
+ */ export function createToaster(options) {
27
+ const { limit =Number.POSITIVE_INFINITY } = options;
28
+ const visibleToasts = new Set();
29
+ const toasts = new Map();
30
+ const queue = createPriorityQueue((ta, tb)=>{
31
+ const a = toasts.get(ta);
32
+ const b = toasts.get(tb);
33
+ if (!a || !b) {
34
+ return 0;
35
+ }
36
+ if (a.priority === b.priority) {
37
+ return a.order - b.order;
38
+ }
39
+ return a.priority - b.priority;
40
+ });
41
+ const isToastVisible = (toastId)=>{
42
+ return visibleToasts.has(toastId);
43
+ };
44
+ /**
45
+ * Updates an existing toast with any available option
46
+ */ const updateToast = (toastOptions)=>{
47
+ const { toastId } = toastOptions;
48
+ const toastToUpdate = toasts.get(toastId);
49
+ if (!toastToUpdate) {
50
+ return;
51
+ }
52
+ Object.assign(toastToUpdate, toastOptions);
53
+ toastToUpdate.updateId++;
54
+ };
55
+ /**
56
+ * Dismisses a toast with a specific id
57
+ */ const dismissToast = (toastId)=>{
58
+ visibleToasts.delete(toastId);
59
+ };
60
+ /**
61
+ * Dismisses all toasts and clears the queue
62
+ */ const dismissAllToasts = ()=>{
63
+ visibleToasts.clear();
64
+ queue.clear();
65
+ };
66
+ /**
67
+ * @param toastOptions user configured options
68
+ * @param onUpdate Some toast methods can result in UI changes (i.e. close) use this to dispatch callbacks
69
+ */ const buildToast = (toastOptions, onUpdate)=>{
70
+ var _toast_onStatusChange;
71
+ const { toastId , content , toasterId } = toastOptions;
72
+ if (toasts.has(toastId)) {
73
+ return;
74
+ }
75
+ const close = ()=>{
76
+ var _toast_onStatusChange;
77
+ const toast = toasts.get(toastId);
78
+ if (!toast) {
79
+ return;
80
+ }
81
+ visibleToasts.delete(toastId);
82
+ onUpdate();
83
+ (_toast_onStatusChange = toast.onStatusChange) === null || _toast_onStatusChange === void 0 ? void 0 : _toast_onStatusChange.call(toast, null, {
84
+ status: 'dismissed',
85
+ ...toast
86
+ });
87
+ };
88
+ const remove = ()=>{
89
+ const toast = toasts.get(toastId);
90
+ if (!toast) {
91
+ return;
92
+ }
93
+ toasts.delete(toastId);
94
+ if (visibleToasts.size < limit && queue.peek()) {
95
+ const nextToast = toasts.get(queue.dequeue());
96
+ if (!nextToast) {
97
+ return;
98
+ }
99
+ visibleToasts.add(nextToast.toastId);
100
+ }
101
+ onUpdate();
102
+ };
103
+ const toast = {
104
+ ...defaulToastOptions,
105
+ close,
106
+ remove,
107
+ toastId,
108
+ content,
109
+ updateId: 0,
110
+ toasterId,
111
+ order: counter++,
112
+ data: {},
113
+ imperativeRef: React.createRef()
114
+ };
115
+ assignDefined(toast, options);
116
+ assignDefined(toast, toastOptions);
117
+ toasts.set(toastId, toast);
118
+ (_toast_onStatusChange = toast.onStatusChange) === null || _toast_onStatusChange === void 0 ? void 0 : _toast_onStatusChange.call(toast, null, {
119
+ status: 'queued',
120
+ ...toast
121
+ });
122
+ if (visibleToasts.size >= limit) {
123
+ queue.enqueue(toastId);
124
+ } else {
125
+ visibleToasts.add(toastId);
126
+ }
127
+ };
128
+ return {
129
+ buildToast,
130
+ dismissAllToasts,
131
+ dismissToast,
132
+ isToastVisible,
133
+ updateToast,
134
+ visibleToasts,
135
+ toasts
136
+ };
137
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["createToaster.ts"],"sourcesContent":["import * as React from 'react';\nimport { createPriorityQueue } from '@fluentui/react-utilities';\nimport { Toast, ToasterOptions, ToastId, ToastImperativeRef, ToastOptions, UpdateToastEventDetail } from '../types';\n\nfunction assignDefined<T extends object>(a: Partial<T>, b: Partial<T>) {\n // This cast is required, as Object.entries will return string as key which is not indexable\n for (const [key, prop] of Object.entries(b) as [keyof T, T[keyof T]][]) {\n // eslint-disable-next-line eqeqeq\n if (prop != undefined) {\n a[key] = prop;\n }\n }\n}\nconst defaulToastOptions: Pick<\n ToastOptions,\n 'priority' | 'pauseOnHover' | 'pauseOnWindowBlur' | 'position' | 'timeout' | 'politeness' | 'onStatusChange'\n> = {\n onStatusChange: undefined,\n priority: 0,\n pauseOnHover: false,\n pauseOnWindowBlur: false,\n position: 'bottom-end',\n timeout: 3000,\n};\n\n// Multiple toasts can be dispatched in a single tick, use counter to prevent collisions\nlet counter = 0;\n\n/**\n * Toast are managed outside of the react lifecycle because they can be\n * dispatched imperatively. Therefore the state of toast visibility can't\n * really be managed properly by a declarative lifecycle.\n */\nexport function createToaster(options: Partial<ToasterOptions>) {\n const { limit = Number.POSITIVE_INFINITY } = options;\n const visibleToasts = new Set<ToastId>();\n const toasts = new Map<ToastId, Toast>();\n\n const queue = createPriorityQueue<ToastId>((ta, tb) => {\n const a = toasts.get(ta);\n const b = toasts.get(tb);\n if (!a || !b) {\n return 0;\n }\n\n if (a.priority === b.priority) {\n return a.order - b.order;\n }\n\n return a.priority - b.priority;\n });\n\n const isToastVisible = (toastId: ToastId) => {\n return visibleToasts.has(toastId);\n };\n\n /**\n * Updates an existing toast with any available option\n */\n const updateToast = (toastOptions: UpdateToastEventDetail) => {\n const { toastId } = toastOptions;\n const toastToUpdate = toasts.get(toastId);\n if (!toastToUpdate) {\n return;\n }\n\n Object.assign(toastToUpdate, toastOptions);\n toastToUpdate.updateId++;\n };\n\n /**\n * Dismisses a toast with a specific id\n */\n const dismissToast = (toastId: ToastId) => {\n visibleToasts.delete(toastId);\n };\n\n /**\n * Dismisses all toasts and clears the queue\n */\n const dismissAllToasts = () => {\n visibleToasts.clear();\n queue.clear();\n };\n\n /**\n * @param toastOptions user configured options\n * @param onUpdate Some toast methods can result in UI changes (i.e. close) use this to dispatch callbacks\n */\n const buildToast = (toastOptions: Partial<ToastOptions> & { toastId: ToastId }, onUpdate: () => void) => {\n const { toastId, content, toasterId } = toastOptions;\n\n if (toasts.has(toastId)) {\n return;\n }\n\n const close = () => {\n const toast = toasts.get(toastId);\n if (!toast) {\n return;\n }\n\n visibleToasts.delete(toastId);\n onUpdate();\n toast.onStatusChange?.(null, { status: 'dismissed', ...toast });\n };\n\n const remove = () => {\n const toast = toasts.get(toastId);\n if (!toast) {\n return;\n }\n\n toasts.delete(toastId);\n\n if (visibleToasts.size < limit && queue.peek()) {\n const nextToast = toasts.get(queue.dequeue());\n if (!nextToast) {\n return;\n }\n\n visibleToasts.add(nextToast.toastId);\n }\n\n onUpdate();\n };\n\n const toast: Toast = {\n ...defaulToastOptions,\n close,\n remove,\n toastId,\n content,\n updateId: 0,\n toasterId,\n order: counter++,\n data: {},\n imperativeRef: React.createRef<ToastImperativeRef>(),\n };\n\n assignDefined(toast, options);\n assignDefined(toast, toastOptions);\n\n toasts.set(toastId, toast);\n toast.onStatusChange?.(null, { status: 'queued', ...toast });\n if (visibleToasts.size >= limit) {\n queue.enqueue(toastId);\n } else {\n visibleToasts.add(toastId);\n }\n };\n\n return {\n buildToast,\n dismissAllToasts,\n dismissToast,\n isToastVisible,\n updateToast,\n visibleToasts,\n toasts,\n };\n}\n"],"names":["React","createPriorityQueue","assignDefined","a","b","key","prop","Object","entries","undefined","defaulToastOptions","onStatusChange","priority","pauseOnHover","pauseOnWindowBlur","position","timeout","counter","createToaster","options","limit","Number","POSITIVE_INFINITY","visibleToasts","Set","toasts","Map","queue","ta","tb","get","order","isToastVisible","toastId","has","updateToast","toastOptions","toastToUpdate","assign","updateId","dismissToast","delete","dismissAllToasts","clear","buildToast","onUpdate","toast","content","toasterId","close","status","remove","size","peek","nextToast","dequeue","add","data","imperativeRef","createRef","set","enqueue"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,mBAAmB,QAAQ,4BAA4B;AAGhE,SAASC,cAAgCC,CAAa,EAAEC,CAAa,EAAE;IACrE,4FAA4F;IAC5F,KAAK,MAAM,CAACC,KAAKC,KAAK,IAAIC,OAAOC,OAAO,CAACJ,GAA+B;QACtE,kCAAkC;QAClC,IAAIE,QAAQG,WAAW;YACrBN,CAAC,CAACE,IAAI,GAAGC;QACX,CAAC;IACH;AACF;AACA,MAAMI,qBAGF;IACFC,gBAAgBF;IAChBG,UAAU;IACVC,cAAc,KAAK;IACnBC,mBAAmB,KAAK;IACxBC,UAAU;IACVC,SAAS;AACX;AAEA,wFAAwF;AACxF,IAAIC,UAAU;AAEd;;;;CAIC,GACD,OAAO,SAASC,cAAcC,OAAgC,EAAE;IAC9D,MAAM,EAAEC,OAAQC,OA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;YACF,CAAC;YAEDvB,cAAckB,MAAM,CAACR;YACrBY;YACAC,CAAAA,wBAAAA,MAAMnC,cAAc,cAApBmC,mCAAAA,KAAAA,IAAAA,sBAAAA,KAAAA,OAAuB,IAAI,EAAE;gBAAEI,QAAQ;gBAAa,GAAGJ,KAAK;YAAC;QAC/D;QAEA,MAAMK,SAAS,IAAM;YACnB,MAAML,QAAQrB,OAAOK,GAAG,CAACG;YACzB,IAAI,CAACa,OAAO;gBACV;YACF,CAAC;YAEDrB,OAAOgB,MAAM,CAACR;YAEd,IAAIV,cAAc6B,IAAI,GAAGhC,SAASO,MAAM0B,IAAI,IAAI;gBAC9C,MAAMC,YAAY7B,OAAOK,GAAG,CAACH,MAAM4B,OAAO;gBAC1C,IAAI,CAACD,WAAW;oBACd;gBACF,CAAC;gBAED/B,cAAciC,GAAG,CAACF,UAAUrB,OAAO;YACrC,CAAC;YAEDY;QACF;QAEA,MAAMC,QAAe;YACnB,GAAGpC,kBAAkB;YACrBuC;YACAE;YACAlB;YACAc;YACAR,UAAU;YACVS;YACAjB,OAAOd;YACPwC,MAAM,CAAC;YACPC,eAAe1D,MAAM2D,SAAS;QAChC;QAEAzD,cAAc4C,OAAO3B;QACrBjB,cAAc4C,OAAOV;QAErBX,OAAOmC,GAAG,CAAC3B,SAASa;QACpBA,CAAAA,wBAAAA,MAAMnC,cAAc,cAApBmC,mCAAAA,KAAAA,IAAAA,sBAAAA,KAAAA,OAAuB,IAAI,EAAE;YAAEI,QAAQ;YAAU,GAAGJ,KAAK;QAAC;QAC1D,IAAIvB,cAAc6B,IAAI,IAAIhC,OAAO;YAC/BO,MAAMkC,OAAO,CAAC5B;QAChB,OAAO;YACLV,cAAciC,GAAG,CAACvB;QACpB,CAAC;IACH;IAEA,OAAO;QACLW;QACAF;QACAF;QACAR;QACAG;QACAZ;QACAE;IACF;AACF,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { EVENTS } from '../constants';
2
+ export function dismissAllToasts(toasterId = undefined, targetDocument) {
3
+ const event = new CustomEvent(EVENTS.dismissAll, {
4
+ bubbles: false,
5
+ cancelable: false,
6
+ detail: {
7
+ toasterId
8
+ }
9
+ });
10
+ targetDocument.dispatchEvent(event);
11
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["dismissAllToasts.ts"],"sourcesContent":["import { EVENTS } from '../constants';\nimport { DismissAllToastsEventDetail, ToasterId } from '../types';\n\nexport function dismissAllToasts(toasterId: ToasterId | undefined = undefined, targetDocument: Document) {\n const event = new CustomEvent<DismissAllToastsEventDetail>(EVENTS.dismissAll, {\n bubbles: false,\n cancelable: false,\n detail: { toasterId },\n });\n targetDocument.dispatchEvent(event);\n}\n"],"names":["EVENTS","dismissAllToasts","toasterId","undefined","targetDocument","event","CustomEvent","dismissAll","bubbles","cancelable","detail","dispatchEvent"],"mappings":"AAAA,SAASA,MAAM,QAAQ,eAAe;AAGtC,OAAO,SAASC,iBAAiBC,YAAmCC,SAAS,EAAEC,cAAwB,EAAE;IACvG,MAAMC,QAAQ,IAAIC,YAAyCN,OAAOO,UAAU,EAAE;QAC5EC,SAAS,KAAK;QACdC,YAAY,KAAK;QACjBC,QAAQ;YAAER;QAAU;IACtB;IACAE,eAAeO,aAAa,CAACN;AAC/B,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { EVENTS } from '../constants';
2
+ export function dismissToast(toastId, toasterId = undefined, targetDocument) {
3
+ const event = new CustomEvent(EVENTS.dismiss, {
4
+ bubbles: false,
5
+ cancelable: false,
6
+ detail: {
7
+ toastId,
8
+ toasterId
9
+ }
10
+ });
11
+ targetDocument.dispatchEvent(event);
12
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["dismissToast.ts"],"sourcesContent":["import { EVENTS } from '../constants';\nimport { DismissToastEventDetail, ToastId, ToasterId } from '../types';\n\nexport function dismissToast(toastId: ToastId, toasterId: ToasterId | undefined = undefined, targetDocument: Document) {\n const event = new CustomEvent<DismissToastEventDetail>(EVENTS.dismiss, {\n bubbles: false,\n cancelable: false,\n detail: { toastId, toasterId },\n });\n targetDocument.dispatchEvent(event);\n}\n"],"names":["EVENTS","dismissToast","toastId","toasterId","undefined","targetDocument","event","CustomEvent","dismiss","bubbles","cancelable","detail","dispatchEvent"],"mappings":"AAAA,SAASA,MAAM,QAAQ,eAAe;AAGtC,OAAO,SAASC,aAAaC,OAAgB,EAAEC,YAAmCC,SAAS,EAAEC,cAAwB,EAAE;IACrH,MAAMC,QAAQ,IAAIC,YAAqCP,OAAOQ,OAAO,EAAE;QACrEC,SAAS,KAAK;QACdC,YAAY,KAAK;QACjBC,QAAQ;YAAET;YAASC;QAAU;IAC/B;IACAE,eAAeO,aAAa,CAACN;AAC/B,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { EVENTS } from '../constants';
2
+ let counter = 0;
3
+ export function dispatchToast(content, options = {}, targetDocument) {
4
+ var _options_toastId;
5
+ const detail = {
6
+ ...options,
7
+ content,
8
+ toastId: (_options_toastId = options.toastId) !== null && _options_toastId !== void 0 ? _options_toastId : (counter++).toString()
9
+ };
10
+ const event = new CustomEvent(EVENTS.show, {
11
+ bubbles: false,
12
+ cancelable: false,
13
+ detail
14
+ });
15
+ targetDocument.dispatchEvent(event);
16
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["dispatchToast.ts"],"sourcesContent":["import { ShowToastEventDetail, ToastOptions } from '../types';\nimport { EVENTS } from '../constants';\n\nlet counter = 0;\n\nexport function dispatchToast(content: unknown, options: Partial<ToastOptions> = {}, targetDocument: Document) {\n const detail: ShowToastEventDetail = {\n ...options,\n content,\n toastId: options.toastId ?? (counter++).toString(),\n };\n const event = new CustomEvent<ShowToastEventDetail>(EVENTS.show, {\n bubbles: false,\n cancelable: false,\n detail,\n });\n targetDocument.dispatchEvent(event);\n}\n"],"names":["EVENTS","counter","dispatchToast","content","options","targetDocument","detail","toastId","toString","event","CustomEvent","show","bubbles","cancelable","dispatchEvent"],"mappings":"AACA,SAASA,MAAM,QAAQ,eAAe;AAEtC,IAAIC,UAAU;AAEd,OAAO,SAASC,cAAcC,OAAgB,EAAEC,UAAiC,CAAC,CAAC,EAAEC,cAAwB,EAAE;QAIlGD;IAHX,MAAME,SAA+B;QACnC,GAAGF,OAAO;QACVD;QACAI,SAASH,CAAAA,mBAAAA,QAAQG,OAAO,cAAfH,8BAAAA,mBAAmB,AAACH,CAAAA,SAAQ,EAAGO,QAAQ,EAAE;IACpD;IACA,MAAMC,QAAQ,IAAIC,YAAkCV,OAAOW,IAAI,EAAE;QAC/DC,SAAS,KAAK;QACdC,YAAY,KAAK;QACjBP;IACF;IACAD,eAAeS,aAAa,CAACL;AAC/B,CAAC"}
@@ -0,0 +1,40 @@
1
+ export const getPositionStyles = (position, dir, offset)=>{
2
+ const positionStyles = {
3
+ position: 'fixed'
4
+ };
5
+ var _offset_position;
6
+ const offsetStyles = offset ? isShorthandOffset(offset) ? offset : (_offset_position = offset[position]) !== null && _offset_position !== void 0 ? _offset_position : {} : {};
7
+ const { horizontal =20 , vertical =16 } = offsetStyles;
8
+ const start = dir === 'ltr' ? 'left' : 'right';
9
+ const end = dir === 'ltr' ? 'right' : 'left';
10
+ switch(position){
11
+ case 'top-start':
12
+ Object.assign(positionStyles, {
13
+ top: vertical,
14
+ [start]: horizontal
15
+ });
16
+ break;
17
+ case 'top-end':
18
+ Object.assign(positionStyles, {
19
+ top: vertical,
20
+ [end]: horizontal
21
+ });
22
+ break;
23
+ case 'bottom-start':
24
+ Object.assign(positionStyles, {
25
+ bottom: vertical,
26
+ [start]: horizontal
27
+ });
28
+ break;
29
+ case 'bottom-end':
30
+ Object.assign(positionStyles, {
31
+ bottom: vertical,
32
+ [end]: horizontal
33
+ });
34
+ break;
35
+ }
36
+ return positionStyles;
37
+ };
38
+ function isShorthandOffset(offset) {
39
+ return 'horizontal' in offset || 'vertical' in offset;
40
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["getPositionStyles.ts"],"sourcesContent":["import { ToastOffsetObject, ToastOffset, ToastPosition } from '../types';\n\ninterface PositionStyles {\n position: 'fixed';\n top?: number;\n left?: number;\n right?: number;\n bottom?: number;\n}\n\nexport const getPositionStyles = (position: ToastPosition, dir: 'rtl' | 'ltr', offset?: ToastOffset) => {\n const positionStyles: PositionStyles = {\n position: 'fixed',\n };\n\n const offsetStyles: ToastOffsetObject = offset ? (isShorthandOffset(offset) ? offset : offset[position] ?? {}) : {};\n\n const { horizontal = 20, vertical = 16 } = offsetStyles;\n const start = dir === 'ltr' ? 'left' : 'right';\n const end = dir === 'ltr' ? 'right' : 'left';\n\n switch (position) {\n case 'top-start':\n Object.assign(positionStyles, {\n top: vertical,\n [start]: horizontal,\n });\n break;\n case 'top-end':\n Object.assign(positionStyles, {\n top: vertical,\n [end]: horizontal,\n });\n break;\n case 'bottom-start':\n Object.assign(positionStyles, {\n bottom: vertical,\n [start]: horizontal,\n });\n break;\n case 'bottom-end':\n Object.assign(positionStyles, {\n bottom: vertical,\n [end]: horizontal,\n });\n break;\n }\n\n return positionStyles;\n};\n\nfunction isShorthandOffset(offset: ToastOffset): offset is ToastOffsetObject {\n return 'horizontal' in offset || 'vertical' in offset;\n}\n"],"names":["getPositionStyles","position","dir","offset","positionStyles","offsetStyles","isShorthandOffset","horizontal","vertical","start","end","Object","assign","top","bottom"],"mappings":"AAUA,OAAO,MAAMA,oBAAoB,CAACC,UAAyBC,KAAoBC,SAAyB;IACtG,MAAMC,iBAAiC;QACrCH,UAAU;IACZ;QAEuFE;IAAvF,MAAME,eAAkCF,SAAUG,kBAAkBH,UAAUA,SAASA,CAAAA,mBAAAA,MAAM,CAACF,SAAS,cAAhBE,8BAAAA,mBAAoB,CAAC,CAAC,GAAI,CAAC,CAAC;IAEnH,MAAM,EAAEI,YAAa,GAAE,EAAEC,UAAW,GAAE,EAAE,GAAGH;IAC3C,MAAMI,QAAQP,QAAQ,QAAQ,SAAS,OAAO;IAC9C,MAAMQ,MAAMR,QAAQ,QAAQ,UAAU,MAAM;IAE5C,OAAQD;QACN,KAAK;YACHU,OAAOC,MAAM,CAACR,gBAAgB;gBAC5BS,KAAKL;gBACL,CAACC,MAAM,EAAEF;YACX;YACA,KAAM;QACR,KAAK;YACHI,OAAOC,MAAM,CAACR,gBAAgB;gBAC5BS,KAAKL;gBACL,CAACE,IAAI,EAAEH;YACT;YACA,KAAM;QACR,KAAK;YACHI,OAAOC,MAAM,CAACR,gBAAgB;gBAC5BU,QAAQN;gBACR,CAACC,MAAM,EAAEF;YACX;YACA,KAAM;QACR,KAAK;YACHI,OAAOC,MAAM,CAACR,gBAAgB;gBAC5BU,QAAQN;gBACR,CAACE,IAAI,EAAEH;YACT;YACA,KAAM;IACV;IAEA,OAAOH;AACT,EAAE;AAEF,SAASE,kBAAkBH,MAAmB,EAA+B;IAC3E,OAAO,gBAAgBA,UAAU,cAAcA;AACjD"}
@@ -0,0 +1,8 @@
1
+ export * from './dispatchToast';
2
+ export * from './dismissToast';
3
+ export * from './dismissAllToasts';
4
+ export * from './updateToast';
5
+ export * from './pauseToast';
6
+ export * from './playToast';
7
+ export * from './createToaster';
8
+ export * from './getPositionStyles';
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"sourcesContent":["export * from './dispatchToast';\nexport * from './dismissToast';\nexport * from './dismissAllToasts';\nexport * from './updateToast';\nexport * from './pauseToast';\nexport * from './playToast';\nexport * from './createToaster';\nexport * from './getPositionStyles';\n"],"names":[],"mappings":"AAAA,cAAc,kBAAkB;AAChC,cAAc,iBAAiB;AAC/B,cAAc,qBAAqB;AACnC,cAAc,gBAAgB;AAC9B,cAAc,eAAe;AAC7B,cAAc,cAAc;AAC5B,cAAc,kBAAkB;AAChC,cAAc,sBAAsB"}
@@ -0,0 +1,12 @@
1
+ import { EVENTS } from '../constants';
2
+ export function pauseToast(toastId, toasterId = undefined, targetDocument) {
3
+ const event = new CustomEvent(EVENTS.pause, {
4
+ bubbles: false,
5
+ cancelable: false,
6
+ detail: {
7
+ toastId,
8
+ toasterId
9
+ }
10
+ });
11
+ targetDocument.dispatchEvent(event);
12
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["pauseToast.ts"],"sourcesContent":["import { EVENTS } from '../constants';\nimport { PauseToastEventDetail, ToastId, ToasterId } from '../types';\n\nexport function pauseToast(toastId: ToastId, toasterId: ToasterId | undefined = undefined, targetDocument: Document) {\n const event = new CustomEvent<PauseToastEventDetail>(EVENTS.pause, {\n bubbles: false,\n cancelable: false,\n detail: { toastId, toasterId },\n });\n targetDocument.dispatchEvent(event);\n}\n"],"names":["EVENTS","pauseToast","toastId","toasterId","undefined","targetDocument","event","CustomEvent","pause","bubbles","cancelable","detail","dispatchEvent"],"mappings":"AAAA,SAASA,MAAM,QAAQ,eAAe;AAGtC,OAAO,SAASC,WAAWC,OAAgB,EAAEC,YAAmCC,SAAS,EAAEC,cAAwB,EAAE;IACnH,MAAMC,QAAQ,IAAIC,YAAmCP,OAAOQ,KAAK,EAAE;QACjEC,SAAS,KAAK;QACdC,YAAY,KAAK;QACjBC,QAAQ;YAAET;YAASC;QAAU;IAC/B;IACAE,eAAeO,aAAa,CAACN;AAC/B,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { EVENTS } from '../constants';
2
+ export function playToast(toastId, toasterId = undefined, targetDocument) {
3
+ const event = new CustomEvent(EVENTS.play, {
4
+ bubbles: false,
5
+ cancelable: false,
6
+ detail: {
7
+ toastId,
8
+ toasterId
9
+ }
10
+ });
11
+ targetDocument.dispatchEvent(event);
12
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["playToast.ts"],"sourcesContent":["import { EVENTS } from '../constants';\nimport { PlayToastEventDetail, ToastId, ToasterId } from '../types';\n\nexport function playToast(toastId: ToastId, toasterId: ToasterId | undefined = undefined, targetDocument: Document) {\n const event = new CustomEvent<PlayToastEventDetail>(EVENTS.play, {\n bubbles: false,\n cancelable: false,\n detail: { toastId, toasterId },\n });\n targetDocument.dispatchEvent(event);\n}\n"],"names":["EVENTS","playToast","toastId","toasterId","undefined","targetDocument","event","CustomEvent","play","bubbles","cancelable","detail","dispatchEvent"],"mappings":"AAAA,SAASA,MAAM,QAAQ,eAAe;AAGtC,OAAO,SAASC,UAAUC,OAAgB,EAAEC,YAAmCC,SAAS,EAAEC,cAAwB,EAAE;IAClH,MAAMC,QAAQ,IAAIC,YAAkCP,OAAOQ,IAAI,EAAE;QAC/DC,SAAS,KAAK;QACdC,YAAY,KAAK;QACjBC,QAAQ;YAAET;YAASC;QAAU;IAC/B;IACAE,eAAeO,aAAa,CAACN;AAC/B,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { EVENTS } from '../constants';
2
+ export function updateToast(options, targetDocument) {
3
+ const event = new CustomEvent(EVENTS.update, {
4
+ bubbles: false,
5
+ cancelable: false,
6
+ detail: options
7
+ });
8
+ targetDocument.dispatchEvent(event);
9
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["updateToast.ts"],"sourcesContent":["import { UpdateToastEventDetail } from '../types';\nimport { EVENTS } from '../constants';\n\nexport function updateToast(options: UpdateToastEventDetail, targetDocument: Document) {\n const event = new CustomEvent<UpdateToastEventDetail>(EVENTS.update, {\n bubbles: false,\n cancelable: false,\n detail: options,\n });\n\n targetDocument.dispatchEvent(event);\n}\n"],"names":["EVENTS","updateToast","options","targetDocument","event","CustomEvent","update","bubbles","cancelable","detail","dispatchEvent"],"mappings":"AACA,SAASA,MAAM,QAAQ,eAAe;AAEtC,OAAO,SAASC,YAAYC,OAA+B,EAAEC,cAAwB,EAAE;IACrF,MAAMC,QAAQ,IAAIC,YAAoCL,OAAOM,MAAM,EAAE;QACnEC,SAAS,KAAK;QACdC,YAAY,KAAK;QACjBC,QAAQP;IACV;IAEAC,eAAeO,aAAa,CAACN;AAC/B,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _exportStar = require("@swc/helpers/lib/_export_star.js").default;
6
+ _exportStar(require("./components/AriaLive/index"), exports);
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["AriaLive.js"],"sourcesContent":["export * from './components/AriaLive/index';\n"],"names":[],"mappings":";;;;;oBAAc"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _exportStar = require("@swc/helpers/lib/_export_star.js").default;
6
+ _exportStar(require("./components/Toast/index"), exports);
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["Toast.js"],"sourcesContent":["export * from './components/Toast/index';\n"],"names":[],"mappings":";;;;;oBAAc"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _exportStar = require("@swc/helpers/lib/_export_star.js").default;
6
+ _exportStar(require("./components/ToastBody/index"), exports);
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["ToastBody.js"],"sourcesContent":["export * from './components/ToastBody/index';\n"],"names":[],"mappings":";;;;;oBAAc"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _exportStar = require("@swc/helpers/lib/_export_star.js").default;
6
+ _exportStar(require("./components/ToastContainer/index"), exports);
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["ToastContainer.js"],"sourcesContent":["export * from './components/ToastContainer/index';\n"],"names":[],"mappings":";;;;;oBAAc"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _exportStar = require("@swc/helpers/lib/_export_star.js").default;
6
+ _exportStar(require("./components/ToastFooter/index"), exports);
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["ToastFooter.js"],"sourcesContent":["export * from './components/ToastFooter/index';\n"],"names":[],"mappings":";;;;;oBAAc"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _exportStar = require("@swc/helpers/lib/_export_star.js").default;
6
+ _exportStar(require("./components/ToastTitle/index"), exports);
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["ToastTitle.js"],"sourcesContent":["export * from './components/ToastTitle/index';\n"],"names":[],"mappings":";;;;;oBAAc"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _exportStar = require("@swc/helpers/lib/_export_star.js").default;
6
+ _exportStar(require("./components/ToastTrigger/index"), exports);
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["ToastTrigger.js"],"sourcesContent":["export * from './components/ToastTrigger/index';\n"],"names":[],"mappings":";;;;;oBAAc"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _exportStar = require("@swc/helpers/lib/_export_star.js").default;
6
+ _exportStar(require("./components/Toaster/index"), exports);
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["Toaster.js"],"sourcesContent":["export * from './components/Toaster/index';\n"],"names":[],"mappings":";;;;;oBAAc"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "AriaLive", {
6
+ enumerable: true,
7
+ get: ()=>AriaLive
8
+ });
9
+ const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
10
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
11
+ const _useAriaLive = require("./useAriaLive");
12
+ const _renderAriaLive = require("./renderAriaLive");
13
+ const _useAriaLiveStylesStyles = require("./useAriaLiveStyles.styles");
14
+ const AriaLive = (props)=>{
15
+ const state = (0, _useAriaLive.useAriaLive_unstable)(props);
16
+ (0, _useAriaLiveStylesStyles.useAriaLiveStyles_unstable)(state);
17
+ return (0, _renderAriaLive.renderAriaLive_unstable)(state);
18
+ };
19
+ AriaLive.displayName = 'AriaLive';