@tamagui/toast 1.9.0 → 1.9.2

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 (98) hide show
  1. package/dist/cjs/Toast.js +2 -4
  2. package/dist/cjs/Toast.js.map +2 -2
  3. package/dist/cjs/ToastImperative.js +119 -0
  4. package/dist/cjs/ToastImperative.js.map +7 -0
  5. package/dist/cjs/ToastImpl.js +0 -1
  6. package/dist/cjs/ToastImpl.js.map +2 -2
  7. package/dist/cjs/ToastViewport.js +2 -1
  8. package/dist/cjs/ToastViewport.js.map +2 -2
  9. package/dist/cjs/createNativeToast.js +30 -9
  10. package/dist/cjs/createNativeToast.js.map +2 -2
  11. package/dist/cjs/createNativeToast.native.js +13 -6
  12. package/dist/cjs/createNativeToast.native.js.map +2 -2
  13. package/dist/cjs/index.js +1 -0
  14. package/dist/cjs/index.js.map +2 -2
  15. package/dist/cjs/types.js.map +1 -1
  16. package/dist/esm/Toast.js +2 -3
  17. package/dist/esm/Toast.js.map +2 -2
  18. package/dist/esm/Toast.mjs +2 -3
  19. package/dist/esm/Toast.mjs.map +2 -2
  20. package/dist/esm/ToastImperative.js +84 -0
  21. package/dist/esm/ToastImperative.js.map +7 -0
  22. package/dist/esm/ToastImperative.mjs +84 -0
  23. package/dist/esm/ToastImperative.mjs.map +7 -0
  24. package/dist/esm/ToastImpl.js +0 -1
  25. package/dist/esm/ToastImpl.js.map +2 -2
  26. package/dist/esm/ToastImpl.mjs +0 -1
  27. package/dist/esm/ToastImpl.mjs.map +2 -2
  28. package/dist/esm/ToastViewport.js +2 -1
  29. package/dist/esm/ToastViewport.js.map +2 -2
  30. package/dist/esm/ToastViewport.mjs +2 -1
  31. package/dist/esm/ToastViewport.mjs.map +2 -2
  32. package/dist/esm/createNativeToast.js +28 -8
  33. package/dist/esm/createNativeToast.js.map +2 -2
  34. package/dist/esm/createNativeToast.mjs +28 -8
  35. package/dist/esm/createNativeToast.mjs.map +2 -2
  36. package/dist/esm/createNativeToast.native.js +11 -5
  37. package/dist/esm/createNativeToast.native.js.map +2 -2
  38. package/dist/esm/createNativeToast.native.mjs +11 -5
  39. package/dist/esm/createNativeToast.native.mjs.map +2 -2
  40. package/dist/esm/index.js +1 -0
  41. package/dist/esm/index.js.map +2 -2
  42. package/dist/esm/index.mjs +1 -0
  43. package/dist/esm/index.mjs.map +2 -2
  44. package/dist/jsx/Toast.js +2 -3
  45. package/dist/jsx/Toast.js.map +2 -2
  46. package/dist/jsx/Toast.mjs +2 -3
  47. package/dist/jsx/Toast.mjs.map +2 -2
  48. package/dist/jsx/ToastImperative.js +79 -0
  49. package/dist/jsx/ToastImperative.js.map +7 -0
  50. package/dist/jsx/ToastImperative.mjs +79 -0
  51. package/dist/jsx/ToastImperative.mjs.map +7 -0
  52. package/dist/jsx/ToastImpl.js +0 -1
  53. package/dist/jsx/ToastImpl.js.map +2 -2
  54. package/dist/jsx/ToastImpl.mjs +0 -1
  55. package/dist/jsx/ToastImpl.mjs.map +2 -2
  56. package/dist/jsx/ToastViewport.js +2 -1
  57. package/dist/jsx/ToastViewport.js.map +2 -2
  58. package/dist/jsx/ToastViewport.mjs +2 -1
  59. package/dist/jsx/ToastViewport.mjs.map +2 -2
  60. package/dist/jsx/createNativeToast.js +28 -8
  61. package/dist/jsx/createNativeToast.js.map +2 -2
  62. package/dist/jsx/createNativeToast.mjs +28 -8
  63. package/dist/jsx/createNativeToast.mjs.map +2 -2
  64. package/dist/jsx/createNativeToast.native.js +11 -5
  65. package/dist/jsx/createNativeToast.native.js.map +2 -2
  66. package/dist/jsx/createNativeToast.native.mjs +11 -5
  67. package/dist/jsx/createNativeToast.native.mjs.map +2 -2
  68. package/dist/jsx/index.js +1 -0
  69. package/dist/jsx/index.js.map +2 -2
  70. package/dist/jsx/index.mjs +1 -0
  71. package/dist/jsx/index.mjs.map +2 -2
  72. package/package.json +13 -13
  73. package/src/Toast.tsx +3 -5
  74. package/src/ToastImperative.tsx +150 -0
  75. package/src/ToastImpl.tsx +13 -10
  76. package/src/ToastViewport.tsx +10 -2
  77. package/src/createNativeToast.native.tsx +18 -7
  78. package/src/createNativeToast.tsx +32 -8
  79. package/src/index.ts +1 -0
  80. package/src/types.ts +31 -9
  81. package/types/Toast.d.ts +1 -2
  82. package/types/Toast.d.ts.map +1 -1
  83. package/types/ToastImperative.d.ts +57 -0
  84. package/types/ToastImperative.d.ts.map +1 -0
  85. package/types/ToastImpl.d.ts +8 -0
  86. package/types/ToastImpl.d.ts.map +1 -1
  87. package/types/ToastViewport.d.ts +12 -0
  88. package/types/ToastViewport.d.ts.map +1 -1
  89. package/types/createNativeToast.d.ts +3 -2
  90. package/types/createNativeToast.d.ts.map +1 -1
  91. package/types/createNativeToast.native.d.ts +3 -2
  92. package/types/createNativeToast.native.d.ts.map +1 -1
  93. package/types/index.d.ts +1 -0
  94. package/types/index.d.ts.map +1 -1
  95. package/types/types.d.ts +24 -7
  96. package/types/types.d.ts.map +1 -1
  97. package/src/createToast.tsx +0 -93
  98. package/types/createToast.d.ts +0 -42
package/dist/cjs/Toast.js CHANGED
@@ -31,7 +31,6 @@ __export(Toast_exports, {
31
31
  Toast: () => Toast,
32
32
  ToastProvider: () => import_ToastProvider.ToastProvider,
33
33
  ToastViewport: () => import_ToastViewport.ToastViewport,
34
- createToast: () => import_createToast.createToast,
35
34
  createToastScope: () => import_ToastProvider.createToastScope
36
35
  });
37
36
  module.exports = __toCommonJS(Toast_exports);
@@ -42,7 +41,6 @@ var import_text = require("@tamagui/text");
42
41
  var import_use_controllable_state = require("@tamagui/use-controllable-state");
43
42
  var React = __toESM(require("react"));
44
43
  var import_constants = require("./constants");
45
- var import_createToast = require("./createToast");
46
44
  var import_ToastAnnounce = require("./ToastAnnounce");
47
45
  var import_ToastImpl = require("./ToastImpl");
48
46
  var import_ToastProvider = require("./ToastProvider");
@@ -141,7 +139,8 @@ const ToastComponent = React.forwardRef(
141
139
  const id = (0, import_core.useId)();
142
140
  const onPause = (0, import_core.useEvent)(props.onPause);
143
141
  const onResume = (0, import_core.useEvent)(props.onResume);
144
- if (!forceMount && !open)
142
+ const shouldShow = forceMount || open;
143
+ if (!shouldShow)
145
144
  return null;
146
145
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
147
146
  import_ToastImpl.ToastImpl,
@@ -175,7 +174,6 @@ const Toast = (0, import_core.withStaticProperties)(
175
174
  Toast,
176
175
  ToastProvider,
177
176
  ToastViewport,
178
- createToast,
179
177
  createToastScope
180
178
  });
181
179
  //# sourceMappingURL=Toast.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Toast.tsx"],
4
- "sourcesContent": ["import {\n GetProps,\n TamaguiElement,\n composeEventHandlers,\n styled,\n themeable,\n useEvent,\n useId,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport { SizableText } from '@tamagui/text'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\n\nimport { TOAST_NAME } from './constants'\nimport { createToast } from './createToast'\nimport { ToastAnnounceExclude } from './ToastAnnounce'\nimport {\n ToastImpl,\n ToastImplFrame,\n ToastProps,\n useToastInteractiveContext,\n} from './ToastImpl'\nimport {\n ScopedProps,\n ToastProvider,\n ToastProviderProps,\n createToastScope,\n} from './ToastProvider'\nimport { ToastViewport, ToastViewportProps } from './ToastViewport'\n\n/* -------------------------------------------------------------------------------------------------\n * ToastTitle\n * -----------------------------------------------------------------------------------------------*/\n\nconst TITLE_NAME = 'ToastTitle'\n\nconst ToastTitleFrame = styled(SizableText, {\n name: TITLE_NAME,\n color: '$color',\n variants: {\n unstyled: {\n false: {\n size: '$4',\n },\n },\n },\n defaultVariants: {\n unstyled: false,\n },\n})\ntype PrimitiveDivProps = GetProps<typeof ToastTitleFrame>\ntype ToastTitleProps = PrimitiveDivProps & {}\n\nconst ToastTitle = React.forwardRef<TamaguiElement, ToastTitleProps>(\n (props: ScopedProps<ToastTitleProps>, forwardedRef) => {\n const { __scopeToast, ...titleProps } = props\n return <ToastTitleFrame {...titleProps} ref={forwardedRef} />\n }\n)\n\nToastTitle.displayName = TITLE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * ToastDescription\n * -----------------------------------------------------------------------------------------------*/\n\nconst DESCRIPTION_NAME = 'ToastDescription'\n\nconst ToastDescriptionFrame = styled(SizableText, {\n name: DESCRIPTION_NAME,\n color: '$color11',\n variants: {\n unstyled: {\n false: {\n size: '$1',\n },\n },\n },\n defaultVariants: {\n unstyled: false,\n },\n})\ntype ToastDescriptionFrameProps = GetProps<typeof ToastDescriptionFrame>\ntype ToastDescriptionProps = ToastDescriptionFrameProps & {}\n\nconst ToastDescription = React.forwardRef<TamaguiElement, ToastDescriptionProps>(\n (props: ScopedProps<ToastDescriptionProps>, forwardedRef) => {\n const { __scopeToast, ...descriptionProps } = props\n return <ToastDescriptionFrame {...descriptionProps} ref={forwardedRef} />\n }\n)\n\nToastDescription.displayName = DESCRIPTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * ToastAction\n * -----------------------------------------------------------------------------------------------*/\n\nconst ACTION_NAME = 'ToastAction'\n\ntype ToastActionProps = ToastCloseProps & {\n /**\n * A short description for an alternate way to carry out the action. For screen reader users\n * who will not be able to navigate to the button easily/quickly.\n * @example <ToastAction altText=\"Goto account settings to updgrade\">Upgrade</ToastAction>\n * @example <ToastAction altText=\"Undo (Alt+U)\">Undo</ToastAction>\n */\n altText: string\n}\n\nconst ToastAction = React.forwardRef<TamaguiElement, ToastActionProps>(\n (props: ScopedProps<ToastActionProps>, forwardedRef) => {\n const { altText, ...actionProps } = props\n if (!altText) return null\n return (\n <ToastAnnounceExclude altText={altText} asChild>\n <ToastClose {...actionProps} ref={forwardedRef} />\n </ToastAnnounceExclude>\n )\n }\n)\n\nToastAction.propTypes = {\n altText(props) {\n if (!props.altText) {\n return new Error(`Missing prop \\`altText\\` expected on \\`${ACTION_NAME}\\``)\n }\n return null\n },\n}\n\nToastAction.displayName = ACTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * ToastClose\n * -----------------------------------------------------------------------------------------------*/\n\nconst CLOSE_NAME = 'ToastClose'\n\nconst ToastCloseFrame = styled(ThemeableStack, {\n name: CLOSE_NAME,\n tag: 'button',\n})\ntype ToastCloseFrameProps = GetProps<typeof ToastCloseFrame>\ntype ToastCloseProps = ToastCloseFrameProps & {}\n\nconst ToastClose = React.forwardRef<TamaguiElement, ToastCloseProps>(\n (props: ScopedProps<ToastCloseProps>, forwardedRef) => {\n const { __scopeToast, ...closeProps } = props\n const interactiveContext = useToastInteractiveContext(CLOSE_NAME, __scopeToast)\n\n return (\n <ToastAnnounceExclude asChild>\n <ToastCloseFrame\n accessibilityLabel=\"Dialog Close\"\n {...closeProps}\n ref={forwardedRef}\n onPress={composeEventHandlers(props.onPress as any, interactiveContext.onClose)}\n />\n </ToastAnnounceExclude>\n )\n }\n)\n\nToastClose.displayName = CLOSE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * Toast\n * -----------------------------------------------------------------------------------------------*/\n\nconst ToastComponent = React.forwardRef<TamaguiElement, ToastProps>(\n ToastImplFrame.extractable((props: ScopedProps<ToastProps>, forwardedRef) => {\n const { forceMount, open: openProp, defaultOpen, onOpenChange, ...toastProps } = props\n const [open, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen ?? true,\n onChange: onOpenChange,\n })\n\n const id = useId()\n const onPause = useEvent(props.onPause)\n const onResume = useEvent(props.onResume)\n\n if (!forceMount && !open) return null\n\n return (\n <ToastImpl\n id={id}\n open={open}\n {...toastProps}\n ref={forwardedRef}\n onClose={() => setOpen(false)}\n onPause={onPause}\n onResume={onResume}\n onSwipeEnd={composeEventHandlers(props.onSwipeEnd, (event) => {\n setOpen(false)\n })}\n />\n )\n })\n)\n\nToastComponent.displayName = TOAST_NAME\n\nconst Toast = withStaticProperties(\n themeable(ToastComponent, ToastImplFrame.staticConfig),\n {\n Title: ToastTitle,\n Description: ToastDescription,\n Action: ToastAction,\n Close: ToastClose,\n }\n)\n\n/* ---------------------------------------------------------------------------------------------- */\n\nexport {\n Toast,\n ToastProvider,\n ToastViewport,\n //\n createToast,\n //\n createToastScope,\n}\nexport type {\n ToastActionProps,\n ToastCloseProps,\n ToastDescriptionProps,\n ToastProps,\n ToastProviderProps,\n ToastTitleProps,\n ToastViewportProps,\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0DW;AA1DX,kBASO;AACP,oBAA+B;AAC/B,kBAA4B;AAC5B,oCAAqC;AACrC,YAAuB;AAEvB,uBAA2B;AAC3B,yBAA4B;AAC5B,2BAAqC;AACrC,uBAKO;AACP,2BAKO;AACP,2BAAkD;AAMlD,MAAM,aAAa;AAEnB,MAAM,sBAAkB,oBAAO,yBAAa;AAAA,EAC1C,MAAM;AAAA,EACN,OAAO;AAAA,EACP,UAAU;AAAA,IACR,UAAU;AAAA,MACR,OAAO;AAAA,QACL,MAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAAA,EACA,iBAAiB;AAAA,IACf,UAAU;AAAA,EACZ;AACF,CAAC;AAID,MAAM,aAAa,MAAM;AAAA,EACvB,CAAC,OAAqC,iBAAiB;AACrD,UAAM,EAAE,cAAc,GAAG,WAAW,IAAI;AACxC,WAAO,4CAAC,mBAAiB,GAAG,YAAY,KAAK,cAAc;AAAA,EAC7D;AACF;AAEA,WAAW,cAAc;AAMzB,MAAM,mBAAmB;AAEzB,MAAM,4BAAwB,oBAAO,yBAAa;AAAA,EAChD,MAAM;AAAA,EACN,OAAO;AAAA,EACP,UAAU;AAAA,IACR,UAAU;AAAA,MACR,OAAO;AAAA,QACL,MAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAAA,EACA,iBAAiB;AAAA,IACf,UAAU;AAAA,EACZ;AACF,CAAC;AAID,MAAM,mBAAmB,MAAM;AAAA,EAC7B,CAAC,OAA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B;AAAA,MAC3C,MAAM;AAAA,MACN,aAAa,eAAe;AAAA,MAC5B,UAAU;AAAA,IACZ,CAAC;AAED,UAAM,SAAK,mBAAM;AACjB,UAAM,cAAU,sBAAS,MAAM,OAAO;AACtC,UAAM,eAAW,sBAAS,MAAM,QAAQ;AAExC,QAAI,CAAC,cAAc,CAAC;AAAM,aAAO;AAEjC,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACC,GAAG;AAAA,QACJ,KAAK;AAAA,QACL,SAAS,MAAM,QAAQ,KAAK;AAAA,QAC5B;AAAA,QACA;AAAA,QACA,gBAAY,kCAAqB,MAAM,YAAY,CAAC,UAAU;AAC5D,kBAAQ,KAAK;AAAA,QACf,CAAC;AAAA;AAAA,IACH;AAAA,EAEJ,CAAC;AACH;AAEA,eAAe,cAAc;AAE7B,MAAM,YAAQ;AAAA,MACZ,uBAAU,gBAAgB,gCAAe,YAAY;AAAA,EACrD;AAAA,IACE,OAAO;AAAA,IACP,aAAa;AAAA,IACb,QAAQ;AAAA,IACR,OAAO;AAAA,EACT;AACF;",
4
+ "sourcesContent": ["import {\n GetProps,\n TamaguiElement,\n composeEventHandlers,\n styled,\n themeable,\n useEvent,\n useId,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport { SizableText } from '@tamagui/text'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\n\nimport { TOAST_NAME } from './constants'\nimport { ToastAnnounceExclude } from './ToastAnnounce'\nimport {\n ToastImpl,\n ToastImplFrame,\n ToastProps,\n useToastInteractiveContext,\n} from './ToastImpl'\nimport {\n ScopedProps,\n ToastProvider,\n ToastProviderProps,\n createToastScope,\n} from './ToastProvider'\nimport { ToastViewport, ToastViewportProps } from './ToastViewport'\n\n/* -------------------------------------------------------------------------------------------------\n * ToastTitle\n * -----------------------------------------------------------------------------------------------*/\n\nconst TITLE_NAME = 'ToastTitle'\n\nconst ToastTitleFrame = styled(SizableText, {\n name: TITLE_NAME,\n color: '$color',\n variants: {\n unstyled: {\n false: {\n size: '$4',\n },\n },\n },\n defaultVariants: {\n unstyled: false,\n },\n})\ntype PrimitiveDivProps = GetProps<typeof ToastTitleFrame>\ntype ToastTitleProps = PrimitiveDivProps & {}\n\nconst ToastTitle = React.forwardRef<TamaguiElement, ToastTitleProps>(\n (props: ScopedProps<ToastTitleProps>, forwardedRef) => {\n const { __scopeToast, ...titleProps } = props\n return <ToastTitleFrame {...titleProps} ref={forwardedRef} />\n }\n)\n\nToastTitle.displayName = TITLE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * ToastDescription\n * -----------------------------------------------------------------------------------------------*/\n\nconst DESCRIPTION_NAME = 'ToastDescription'\n\nconst ToastDescriptionFrame = styled(SizableText, {\n name: DESCRIPTION_NAME,\n color: '$color11',\n variants: {\n unstyled: {\n false: {\n size: '$1',\n },\n },\n },\n defaultVariants: {\n unstyled: false,\n },\n})\ntype ToastDescriptionFrameProps = GetProps<typeof ToastDescriptionFrame>\ntype ToastDescriptionProps = ToastDescriptionFrameProps & {}\n\nconst ToastDescription = React.forwardRef<TamaguiElement, ToastDescriptionProps>(\n (props: ScopedProps<ToastDescriptionProps>, forwardedRef) => {\n const { __scopeToast, ...descriptionProps } = props\n return <ToastDescriptionFrame {...descriptionProps} ref={forwardedRef} />\n }\n)\n\nToastDescription.displayName = DESCRIPTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * ToastAction\n * -----------------------------------------------------------------------------------------------*/\n\nconst ACTION_NAME = 'ToastAction'\n\ntype ToastActionProps = ToastCloseProps & {\n /**\n * A short description for an alternate way to carry out the action. For screen reader users\n * who will not be able to navigate to the button easily/quickly.\n * @example <ToastAction altText=\"Goto account settings to updgrade\">Upgrade</ToastAction>\n * @example <ToastAction altText=\"Undo (Alt+U)\">Undo</ToastAction>\n */\n altText: string\n}\n\nconst ToastAction = React.forwardRef<TamaguiElement, ToastActionProps>(\n (props: ScopedProps<ToastActionProps>, forwardedRef) => {\n const { altText, ...actionProps } = props\n if (!altText) return null\n return (\n <ToastAnnounceExclude altText={altText} asChild>\n <ToastClose {...actionProps} ref={forwardedRef} />\n </ToastAnnounceExclude>\n )\n }\n)\n\nToastAction.propTypes = {\n altText(props) {\n if (!props.altText) {\n return new Error(`Missing prop \\`altText\\` expected on \\`${ACTION_NAME}\\``)\n }\n return null\n },\n}\n\nToastAction.displayName = ACTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * ToastClose\n * -----------------------------------------------------------------------------------------------*/\n\nconst CLOSE_NAME = 'ToastClose'\n\nconst ToastCloseFrame = styled(ThemeableStack, {\n name: CLOSE_NAME,\n tag: 'button',\n})\ntype ToastCloseFrameProps = GetProps<typeof ToastCloseFrame>\ntype ToastCloseProps = ToastCloseFrameProps & {}\n\nconst ToastClose = React.forwardRef<TamaguiElement, ToastCloseProps>(\n (props: ScopedProps<ToastCloseProps>, forwardedRef) => {\n const { __scopeToast, ...closeProps } = props\n const interactiveContext = useToastInteractiveContext(CLOSE_NAME, __scopeToast)\n\n return (\n <ToastAnnounceExclude asChild>\n <ToastCloseFrame\n accessibilityLabel=\"Dialog Close\"\n {...closeProps}\n ref={forwardedRef}\n onPress={composeEventHandlers(props.onPress as any, interactiveContext.onClose)}\n />\n </ToastAnnounceExclude>\n )\n }\n)\n\nToastClose.displayName = CLOSE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * Toast\n * -----------------------------------------------------------------------------------------------*/\n\nconst ToastComponent = React.forwardRef<TamaguiElement, ToastProps>(\n ToastImplFrame.extractable((props: ScopedProps<ToastProps>, forwardedRef) => {\n const { forceMount, open: openProp, defaultOpen, onOpenChange, ...toastProps } = props\n const [open, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen ?? true,\n onChange: onOpenChange,\n })\n\n const id = useId()\n const onPause = useEvent(props.onPause)\n const onResume = useEvent(props.onResume)\n const shouldShow = forceMount || open\n \n if (!shouldShow) return null\n\n return (\n <ToastImpl\n id={id}\n open={open}\n {...toastProps}\n ref={forwardedRef}\n onClose={() => setOpen(false)}\n onPause={onPause}\n onResume={onResume}\n onSwipeEnd={composeEventHandlers(props.onSwipeEnd, (event) => {\n setOpen(false)\n })}\n />\n )\n })\n)\n\nToastComponent.displayName = TOAST_NAME\n\nconst Toast = withStaticProperties(\n themeable(ToastComponent, ToastImplFrame.staticConfig),\n {\n Title: ToastTitle,\n Description: ToastDescription,\n Action: ToastAction,\n Close: ToastClose,\n }\n)\n\n/* ---------------------------------------------------------------------------------------------- */\n\nexport {\n Toast,\n ToastProvider,\n ToastViewport,\n //\n createToastScope,\n}\nexport type {\n ToastActionProps,\n ToastCloseProps,\n ToastDescriptionProps,\n ToastProps,\n ToastProviderProps,\n ToastTitleProps,\n ToastViewportProps,\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyDW;AAzDX,kBASO;AACP,oBAA+B;AAC/B,kBAA4B;AAC5B,oCAAqC;AACrC,YAAuB;AAEvB,uBAA2B;AAC3B,2BAAqC;AACrC,uBAKO;AACP,2BAKO;AACP,2BAAkD;AAMlD,MAAM,aAAa;AAEnB,MAAM,sBAAkB,oBAAO,yBAAa;AAAA,EAC1C,MAAM;AAAA,EACN,OAAO;AAAA,EACP,UAAU;AAAA,IACR,UAAU;AAAA,MACR,OAAO;AAAA,QACL,MAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAAA,EACA,iBAAiB;AAAA,IACf,UAAU;AAAA,EACZ;AACF,CAAC;AAID,MAAM,aAAa,MAAM;AAAA,EACvB,CAAC,OAAqC,iBAAiB;AACrD,UAAM,EAAE,cAAc,GAAG,WAAW,IAAI;AACxC,WAAO,4CAAC,mBAAiB,GAAG,YAAY,KAAK,cAAc;AAAA,EAC7D;AACF;AAEA,WAAW,cAAc;AAMzB,MAAM,mBAAmB;AAEzB,MAAM,4BAAwB,oBAAO,yBAAa;A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A;AAAA,IAChF,GACF;AAAA,EAEJ;AACF;AAEA,WAAW,cAAc;AAMzB,MAAM,iBAAiB,MAAM;AAAA,EAC3B,gCAAe,YAAY,CAAC,OAAgC,iBAAiB;AAC3E,UAAM,EAAE,YAAY,MAAM,UAAU,aAAa,cAAc,GAAG,WAAW,IAAI;AACjF,UAAM,CAAC,MAAM,OAAO,QAAI,oDAAqB;AAAA,MAC3C,MAAM;AAAA,MACN,aAAa,eAAe;AAAA,MAC5B,UAAU;AAAA,IACZ,CAAC;AAED,UAAM,SAAK,mBAAM;AACjB,UAAM,cAAU,sBAAS,MAAM,OAAO;AACtC,UAAM,eAAW,sBAAS,MAAM,QAAQ;AACxC,UAAM,aAAa,cAAc;AAEjC,QAAI,CAAC;AAAY,aAAO;AAExB,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACC,GAAG;AAAA,QACJ,KAAK;AAAA,QACL,SAAS,MAAM,QAAQ,KAAK;AAAA,QAC5B;AAAA,QACA;AAAA,QACA,gBAAY,kCAAqB,MAAM,YAAY,CAAC,UAAU;AAC5D,kBAAQ,KAAK;AAAA,QACf,CAAC;AAAA;AAAA,IACH;AAAA,EAEJ,CAAC;AACH;AAEA,eAAe,cAAc;AAE7B,MAAM,YAAQ;AAAA,MACZ,uBAAU,gBAAgB,gCAAe,YAAY;AAAA,EACrD;AAAA,IACE,OAAO;AAAA,IACP,aAAa;AAAA,IACb,QAAQ;AAAA,IACR,OAAO;AAAA,EACT;AACF;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var ToastImperative_exports = {};
30
+ __export(ToastImperative_exports, {
31
+ ToastImperativeProvider: () => ToastImperativeProvider,
32
+ useToast: () => useToast
33
+ });
34
+ module.exports = __toCommonJS(ToastImperative_exports);
35
+ var import_jsx_runtime = require("react/jsx-runtime");
36
+ var import_core = require("@tamagui/core");
37
+ var import_create_context = require("@tamagui/create-context");
38
+ var import_react = __toESM(require("react"));
39
+ var import_react_native = require("react-native");
40
+ var import_createNativeToast = require("./createNativeToast");
41
+ const [createImperativeToastContext, createImperativeToastScope] = (0, import_create_context.createContextScope)("ImperativeToast");
42
+ const [ToastImperativeProviderProvider, useToastProviderContext] = createImperativeToastContext("ToastImperativeProvider");
43
+ const useToast = () => {
44
+ const context = useToastProviderContext("useToast", void 0);
45
+ return {
46
+ /**
47
+ * The currently displaying toast
48
+ */
49
+ currentToast: context.currentToast,
50
+ /**
51
+ * Call it to show a new toast. If you're using native toasts, you can pass native options using \`burntOptions\` or \`notificationOptions\` depending on the native platform (mobile/web).
52
+ */
53
+ show: context.showToast,
54
+ /**
55
+ * Call it to hide the currently displayed toast.
56
+ *
57
+ * _NOTE_: does not work on Android native toasts
58
+ *
59
+ * _NOTE_: hides the last toast on web notification toasts
60
+ */
61
+ hide: context.hideToast
62
+ };
63
+ };
64
+ const ToastImperativeProvider = ({
65
+ children,
66
+ options,
67
+ __scopeToast
68
+ }) => {
69
+ const counterRef = (0, import_react.useRef)(0);
70
+ const [toast, setToast] = import_react.default.useState(null);
71
+ const [lastNativeToastRef, setLastNativeToastRef] = import_react.default.useState(null);
72
+ const showToast = import_react.default.useCallback(
73
+ (title, showToastOptions) => {
74
+ const native = (showToastOptions == null ? void 0 : showToastOptions.native) ?? options.native;
75
+ const isWebNative = Array.isArray(native) ? native.includes("web") : native === "web";
76
+ const isMobileNative = Array.isArray(native) ? native.includes("mobile") : native === "mobile";
77
+ const isAndroidNative = isMobileNative || (Array.isArray(native) ? native.includes("android") : native === "android");
78
+ const isIosNative = isMobileNative || (Array.isArray(native) ? native.includes("ios") : native === "ios");
79
+ const isHandledNatively = native === true || import_core.isWeb && isWebNative || !import_core.isWeb && isMobileNative || import_react_native.Platform.OS === "android" && isAndroidNative || import_react_native.Platform.OS === "ios" && isIosNative;
80
+ if (isHandledNatively) {
81
+ const nativeToastResult = (0, import_createNativeToast.createNativeToast)(title, showToastOptions ?? {});
82
+ if (typeof nativeToastResult === "object" && nativeToastResult.nativeToastRef) {
83
+ setLastNativeToastRef(nativeToastResult.nativeToastRef);
84
+ }
85
+ }
86
+ counterRef.current++;
87
+ setToast({
88
+ title,
89
+ id: counterRef.current.toString(),
90
+ ...showToastOptions,
91
+ isHandledNatively
92
+ });
93
+ return true;
94
+ },
95
+ [setToast, options.native]
96
+ );
97
+ const hideToast = import_react.default.useCallback(() => {
98
+ lastNativeToastRef == null ? void 0 : lastNativeToastRef.close();
99
+ setToast(null);
100
+ }, [setToast, lastNativeToastRef]);
101
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
102
+ ToastImperativeProviderProvider,
103
+ {
104
+ scope: __scopeToast,
105
+ showToast,
106
+ hideToast,
107
+ currentToast: toast,
108
+ nativeToast: lastNativeToastRef,
109
+ options,
110
+ children
111
+ }
112
+ );
113
+ };
114
+ // Annotate the CommonJS export names for ESM import in node:
115
+ 0 && (module.exports = {
116
+ ToastImperativeProvider,
117
+ useToast
118
+ });
119
+ //# sourceMappingURL=ToastImperative.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/ToastImperative.tsx"],
4
+ "sourcesContent": ["import { isWeb } from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport React, { useRef } from 'react'\nimport { Platform } from 'react-native'\n\nimport { createNativeToast } from './createNativeToast'\nimport {\n CreateNativeToastOptions,\n NativeToastRef,\n ToastNativePlatform,\n ToastNativeValue,\n} from './types'\n\ninterface ToastImperativeOptions extends Omit<CreateNativeToastOptions, \"message\"> {\n /**\n * Will show a native toast if is true or is set to the current platform. On iOS, it wraps `SPIndicator` and `SPAlert`. On Android, it wraps `ToastAndroid`. On web, it wraps Notification API. Mobile's native features are handled by `burnt`.\n */\n native?: ToastNativeValue\n}\ninterface ShowToastOptions extends CreateNativeToastOptions {\n /**\n * Used when need custom data\n */\n additionalInfo?: Record<string, any>\n /**\n * Overrides the native option on `ToastImperativeProvider`\n */\n native?: ToastNativeValue\n}\ntype ScopedProps<P> = P & { __scopeToast?: Scope }\n\ntype ToastData = { title: string; id: string } & CreateNativeToastOptions & {\n isHandledNatively: boolean\n }\n\ninterface ImperativeToastContextValue {\n currentToast: ToastData | null\n nativeToast: NativeToastRef | null\n showToast: (title: string, options?: ShowToastOptions) => boolean\n hideToast: () => void\n options?: ToastImperativeOptions\n}\n\nconst [createImperativeToastContext, createImperativeToastScope] =\n createContextScope('ImperativeToast')\n\nconst [ToastImperativeProviderProvider, useToastProviderContext] =\n createImperativeToastContext<ImperativeToastContextValue>('ToastImperativeProvider')\n\nconst useToast = () => {\n const context = useToastProviderContext('useToast', undefined)\n\n return {\n /**\n * The currently displaying toast\n */\n currentToast: context.currentToast,\n /**\n * Call it to show a new toast. If you're using native toasts, you can pass native options using \\`burntOptions\\` or \\`notificationOptions\\` depending on the native platform (mobile/web).\n */\n show: context.showToast,\n /**\n * Call it to hide the currently displayed toast.\n * \n * _NOTE_: does not work on Android native toasts\n * \n * _NOTE_: hides the last toast on web notification toasts\n */\n hide: context.hideToast,\n }\n}\n\ninterface ToastImperativeProviderProps {\n children: React.ReactNode\n /**\n * Used to provide defaults to imperative API. Options can be overwritten when calling `show()`.\n */\n options: ToastImperativeOptions\n}\nconst ToastImperativeProvider = ({\n children,\n options,\n __scopeToast,\n}: ScopedProps<ToastImperativeProviderProps>) => {\n const counterRef = useRef(0)\n const [toast, setToast] =\n React.useState<ImperativeToastContextValue['currentToast']>(null)\n const [lastNativeToastRef, setLastNativeToastRef] =\n React.useState<ImperativeToastContextValue['nativeToast']>(null)\n const showToast = React.useCallback<ImperativeToastContextValue['showToast']>(\n (title, showToastOptions) => {\n const native = showToastOptions?.native ?? options.native\n const isWebNative = Array.isArray(native)\n ? native.includes('web')\n : native === 'web'\n const isMobileNative = Array.isArray(native)\n ? native.includes('mobile')\n : native === 'mobile'\n const isAndroidNative =\n isMobileNative ||\n (Array.isArray(native) ? native.includes('android') : native === 'android')\n const isIosNative =\n isMobileNative ||\n (Array.isArray(native) ? native.includes('ios') : native === 'ios')\n\n const isHandledNatively =\n native === true ||\n (isWeb && isWebNative) ||\n (!isWeb && isMobileNative) ||\n (Platform.OS === 'android' && isAndroidNative) ||\n (Platform.OS === 'ios' && isIosNative)\n\n if (isHandledNatively) {\n const nativeToastResult = createNativeToast(title, showToastOptions ?? {})\n if (typeof nativeToastResult === 'object' && nativeToastResult.nativeToastRef) {\n setLastNativeToastRef(nativeToastResult.nativeToastRef)\n }\n }\n counterRef.current++\n setToast({\n title,\n id: counterRef.current.toString(),\n ...showToastOptions,\n isHandledNatively,\n })\n return true\n },\n [setToast, options.native]\n )\n const hideToast = React.useCallback(() => {\n lastNativeToastRef?.close()\n setToast(null)\n }, [setToast, lastNativeToastRef])\n\n return (\n <ToastImperativeProviderProvider\n scope={__scopeToast}\n showToast={showToast}\n hideToast={hideToast}\n currentToast={toast}\n nativeToast={lastNativeToastRef}\n options={options}\n >\n {children}\n </ToastImperativeProviderProvider>\n )\n}\n\nexport { ToastImperativeProvider, useToast }\nexport type { ToastImperativeProviderProps, ToastNativePlatform, ToastNativeValue }\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuII;AAvIJ,kBAAsB;AACtB,4BAA0C;AAC1C,mBAA8B;AAC9B,0BAAyB;AAEzB,+BAAkC;AAsClC,MAAM,CAAC,8BAA8B,0BAA0B,QAC7D,0CAAmB,iBAAiB;AAEtC,MAAM,CAAC,iCAAiC,uBAAuB,IAC7D,6BAA0D,yBAAyB;AAErF,MAAM,WAAW,MAAM;AACrB,QAAM,UAAU,wBAAwB,YAAY,MAAS;AAE7D,SAAO;AAAA;AAAA;AAAA;AAAA,IAIL,cAAc,QAAQ;AAAA;AAAA;AAAA;AAAA,IAItB,MAAM,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQd,MAAM,QAAQ;AAAA,EAChB;AACF;AASA,MAAM,0BAA0B,CAAC;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AACF,MAAiD;AAC/C,QAAM,iBAAa,qBAAO,CAAC;AAC3B,QAAM,CAAC,OAAO,QAAQ,IACpB,aAAAA,QAAM,SAAsD,IAAI;AAClE,QAAM,CAAC,oBAAoB,qBAAqB,IAC9C,aAAAA,QAAM,SAAqD,IAAI;AACjE,QAAM,YAAY,aAAAA,QAAM;AAAA,IACtB,CAAC,OAAO,qBAAqB;AAC3B,YAAM,UAAS,qDAAkB,WAAU,QAAQ;AACnD,YAAM,cAAc,MAAM,QAAQ,MAAM,IACpC,OAAO,SAAS,KAAK,IACrB,WAAW;AACf,YAAM,iBAAiB,MAAM,QAAQ,MAAM,IACvC,OAAO,SAAS,QAAQ,IACxB,WAAW;AACf,YAAM,kBACJ,mBACC,MAAM,QAAQ,MAAM,IAAI,OAAO,SAAS,SAAS,IAAI,WAAW;AACnE,YAAM,cACJ,mBACC,MAAM,QAAQ,MAAM,IAAI,OAAO,SAAS,KAAK,IAAI,WAAW;AAE/D,YAAM,oBACJ,WAAW,QACV,qBAAS,eACT,CAAC,qBAAS,kBACV,6BAAS,OAAO,aAAa,mBAC7B,6BAAS,OAAO,SAAS;AAE5B,UAAI,mBAAmB;AACrB,cAAM,wBAAoB,4CAAkB,OAAO,oBAAoB,CAAC,CAAC;AACzE,YAAI,OAAO,sBAAsB,YAAY,kBAAkB,gBAAgB;AAC7E,gCAAsB,kBAAkB,cAAc;AAAA,QACxD;AAAA,MACF;AACA,iBAAW;AACX,eAAS;AAAA,QACP;AAAA,QACA,IAAI,WAAW,QAAQ,SAAS;AAAA,QAChC,GAAG;AAAA,QACH;AAAA,MACF,CAAC;AACD,aAAO;AAAA,IACT;AAAA,IACA,CAAC,UAAU,QAAQ,MAAM;AAAA,EAC3B;AACA,QAAM,YAAY,aAAAA,QAAM,YAAY,MAAM;AACxC,6DAAoB;AACpB,aAAS,IAAI;AAAA,EACf,GAAG,CAAC,UAAU,kBAAkB,CAAC;AAEjC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO;AAAA,MACP;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd,aAAa;AAAA,MACb;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;",
6
+ "names": ["React"]
7
+ }
@@ -242,7 +242,6 @@ const ToastImpl = React.forwardRef(
242
242
  {
243
243
  scope: __scopeToast,
244
244
  onClose: () => {
245
- console.log("hellooow");
246
245
  handleClose();
247
246
  },
248
247
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/ToastImpl.tsx"],
4
- "sourcesContent": ["import { useIsPresent } from '@tamagui/animate-presence'\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n TamaguiElement,\n Theme,\n composeEventHandlers,\n getAnimationDriver,\n isWeb,\n styled,\n useEvent,\n useThemeName,\n} from '@tamagui/core'\nimport { Dismissable, DismissableProps } from '@tamagui/dismissable'\nimport { PortalItem } from '@tamagui/portal'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport * as React from 'react'\nimport { Animated, GestureResponderEvent, PanResponder } from 'react-native'\n\nimport { TOAST_NAME } from './constants'\nimport { ToastAnnounce } from './ToastAnnounce'\nimport {\n Collection,\n ScopedProps,\n SwipeDirection,\n createToastContext,\n useToastProviderContext,\n} from './ToastProvider'\nimport { VIEWPORT_PAUSE, VIEWPORT_RESUME } from './ToastViewport'\n\nconst ToastImplFrame = styled(ThemeableStack, {\n name: 'ToastImpl',\n variants: {\n backgrounded: {\n true: {\n backgroundColor: '$color6',\n },\n },\n unstyled: {\n false: {\n borderRadius: '$10',\n paddingHorizontal: '$5',\n paddingVertical: '$2',\n marginHorizontal: 'auto',\n marginVertical: '$1',\n },\n },\n },\n defaultVariants: {\n backgrounded: true,\n unstyled: false,\n },\n})\ninterface ToastProps extends Omit<ToastImplProps, keyof ToastImplPrivateProps> {\n /**\n * The controlled open state of the dialog. Must be used in conjunction with `onOpenChange`.\n */\n open?: boolean\n /**\n * The open state of the dialog when it is initially rendered. Use when you do not need to control its open state.\n */\n defaultOpen?: boolean\n /**\n * Event handler called when the open state of the dialog changes.\n */\n onOpenChange?(open: boolean): void\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true\n}\n\ntype SwipeEvent = GestureResponderEvent\n\nconst [ToastInteractiveProvider, useToastInteractiveContext] = createToastContext(\n TOAST_NAME,\n {\n onClose() {},\n }\n)\n\ntype ToastImplPrivateProps = { open: boolean; onClose(): void }\ntype ToastImplFrameProps = GetProps<typeof ToastImplFrame>\ntype ToastImplProps = ToastImplPrivateProps &\n ToastImplFrameProps & {\n /**\n * Control the sensitivity of the toast for accessibility purposes.\n * For toasts that are the result of a user action, choose foreground. Toasts generated from background tasks should use background.\n */\n type?: 'foreground' | 'background'\n /**\n * Time in milliseconds that toast should remain visible for. Overrides value given to `ToastProvider`.\n */\n duration?: number\n /**\n * Event handler called when the escape key is down. It can be prevented by calling `event.preventDefault`.\n */\n onEscapeKeyDown?: DismissableProps['onEscapeKeyDown']\n /**\n * Event handler called when the dismiss timer is paused.\n * On web, this occurs when the pointer is moved over the viewport, the viewport is focused or when the window is blurred.\n * On mobile, this occurs when the toast is touched.\n */\n onPause?(): void\n /**\n * Event handler called when the dismiss timer is resumed.\n * On web, this occurs when the pointer is moved away from the viewport, the viewport is blurred or when the window is focused.\n * On mobile, this occurs when the toast is released.\n */\n onResume?(): void\n /**\n * Event handler called when starting a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeStart?(event: SwipeEvent): void\n /**\n * Event handler called during a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeMove?(event: SwipeEvent): void\n /**\n * Event handler called at the cancellation of a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeCancel?(event: SwipeEvent): void\n /**\n * Event handler called at the end of a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeEnd?(event: SwipeEvent): void\n /**\n * The viewport's name to send the toast to. Used when using multiple viewports and want to forward toasts to different ones.\n *\n * @default \"default\"\n */\n viewportName?: string\n }\n\nconst ToastImpl = React.forwardRef<TamaguiElement, ToastImplProps>(\n (props: ScopedProps<ToastImplProps>, forwardedRef) => {\n const {\n __scopeToast,\n type = 'foreground',\n duration: durationProp,\n open,\n onClose,\n onEscapeKeyDown,\n onPause,\n onResume,\n onSwipeStart,\n onSwipeMove,\n onSwipeCancel,\n onSwipeEnd,\n viewportName,\n ...toastProps\n } = props\n const isPresent = useIsPresent()\n const context = useToastProviderContext(TOAST_NAME, __scopeToast)\n const [node, setNode] = React.useState<TamaguiElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) => setNode(node))\n const duration = durationProp || context.duration\n const closeTimerStartTimeRef = React.useRef(0)\n const closeTimerRemainingTimeRef = React.useRef(duration)\n const closeTimerRef = React.useRef(0)\n const { onToastAdd, onToastRemove } = context\n const handleClose = useEvent(() => {\n if (!isPresent) {\n // already removed from the react tree\n return\n }\n // focus viewport if focus is within toast to read the remaining toast\n // count to SR users and ensure focus isn't lost\n if (isWeb) {\n const isFocusInToast = (node as HTMLDivElement)?.contains(document.activeElement)\n if (isFocusInToast) context.viewport?.focus()\n }\n onClose()\n })\n\n const startTimer = React.useCallback(\n (duration: number) => {\n if (!duration || duration === Infinity) return\n clearTimeout(closeTimerRef.current)\n closeTimerStartTimeRef.current = new Date().getTime()\n closeTimerRef.current = setTimeout(handleClose, duration) as unknown as number\n },\n [handleClose]\n )\n const handleResume = React.useCallback(() => {\n startTimer(closeTimerRemainingTimeRef.current)\n onResume?.()\n }, [onResume, startTimer])\n const handlePause = React.useCallback(() => {\n const elapsedTime = new Date().getTime() - closeTimerStartTimeRef.current\n closeTimerRemainingTimeRef.current =\n closeTimerRemainingTimeRef.current - elapsedTime\n window.clearTimeout(closeTimerRef.current)\n onPause?.()\n }, [onPause])\n\n React.useEffect(() => {\n if (!isWeb) return\n const viewport = context.viewport as HTMLElement\n if (viewport) {\n viewport.addEventListener(VIEWPORT_PAUSE, handlePause)\n viewport.addEventListener(VIEWPORT_RESUME, handleResume)\n return () => {\n viewport.removeEventListener(VIEWPORT_PAUSE, handlePause)\n viewport.removeEventListener(VIEWPORT_RESUME, handleResume)\n }\n }\n }, [context.viewport, duration, onPause, onResume, startTimer])\n\n // start timer when toast opens or duration changes.\n // we include `open` in deps because closed !== unmounted when animating\n // so it could reopen before being completely unmounted\n React.useEffect(() => {\n if (open && !context.isClosePausedRef.current) {\n startTimer(duration)\n }\n }, [open, duration, context.isClosePausedRef, startTimer])\n\n React.useEffect(() => {\n onToastAdd()\n return () => onToastRemove()\n }, [onToastAdd, onToastRemove])\n\n const announceTextContent = React.useMemo(() => {\n if (!isWeb) return null\n return node ? getAnnounceTextContent(node as HTMLDivElement) : null\n }, [node])\n\n const isHorizontalSwipe = ['left', 'right', 'horizontal'].includes(\n context.swipeDirection\n )\n\n const driver = getAnimationDriver()\n if (!driver) {\n throw new Error('Must set animations in tamagui.config.ts')\n }\n\n const { useAnimatedNumber, useAnimatedNumberStyle } = driver\n\n const animatedNumber = useAnimatedNumber(0)\n\n // temp until reanimated useAnimatedNumber fix\n const AnimatedView = (driver['NumberView'] ?? driver.View) as typeof Animated.View\n\n const animatedStyles = useAnimatedNumberStyle(animatedNumber, (val) => {\n return {\n transform: [isHorizontalSwipe ? { translateX: val } : { translateY: val }],\n }\n })\n\n const panResponder = React.useMemo(() => {\n return PanResponder.create({\n onMoveShouldSetPanResponder: (e) => {\n onSwipeStart?.(e)\n return true\n },\n onPanResponderGrant: (e) => {\n if (!isWeb) {\n handlePause?.()\n }\n },\n onPanResponderMove: (e, { dy, dx }) => {\n let y = 0\n let x = 0\n if (context.swipeDirection === 'horizontal') x = dx\n else if (context.swipeDirection === 'left') x = Math.min(0, dx)\n else if (context.swipeDirection === 'right') x = Math.max(0, dx)\n else if (context.swipeDirection === 'vertical') y = dy\n else if (context.swipeDirection === 'up') y = Math.min(0, dy)\n else if (context.swipeDirection === 'down') y = Math.max(0, dy)\n\n onSwipeMove?.(e)\n\n const delta = { x, y }\n animatedNumber.setValue(isHorizontalSwipe ? x : y, { type: 'direct' })\n if (isDeltaInDirection(delta, context.swipeDirection, context.swipeThreshold)) {\n onSwipeEnd?.(e)\n }\n },\n onPanResponderEnd: (e, { dx, dy }) => {\n if (\n !isDeltaInDirection(\n { x: dx, y: dy },\n context.swipeDirection,\n context.swipeThreshold\n )\n ) {\n if (!isWeb) {\n handleResume?.()\n }\n onSwipeCancel?.(e)\n animatedNumber.setValue(0, { type: 'spring' })\n }\n },\n })\n }, [handlePause, handleResume])\n\n // need to get the theme name from context and apply it again since portals don't retain the theme\n const themeName = useThemeName()\n\n return (\n <>\n {announceTextContent && (\n <ToastAnnounce\n __scopeToast={__scopeToast}\n // Toasts are always role=status to avoid stuttering issues with role=alert in SRs.\n role=\"status\"\n aria-live={type === 'foreground' ? 'assertive' : 'polite'}\n aria-atomic\n >\n {announceTextContent}\n </ToastAnnounce>\n )}\n\n <PortalItem hostName={viewportName ?? 'default'}>\n <ToastInteractiveProvider\n key={props.id}\n scope={__scopeToast}\n onClose={() => {\n console.log('hellooow')\n handleClose()\n }}\n >\n <Dismissable\n // asChild\n onEscapeKeyDown={composeEventHandlers(onEscapeKeyDown, () => {\n if (!context.isFocusedToastEscapeKeyDownRef.current) {\n handleClose()\n }\n context.isFocusedToastEscapeKeyDownRef.current = false\n })}\n >\n <Theme forceClassName name={themeName}>\n <AnimatedView\n {...panResponder?.panHandlers}\n style={[{ margin: 'auto' }, animatedStyles]}\n >\n <Collection.ItemSlot scope={__scopeToast}>\n <ToastImplFrame\n // Ensure toasts are announced as status list or status when focused\n role=\"status\"\n aria-live=\"off\"\n aria-atomic\n tabIndex={0}\n data-state={open ? 'open' : 'closed'}\n data-swipe-direction={context.swipeDirection}\n pointerEvents=\"auto\"\n // touchAction=\"none\"\n userSelect=\"none\"\n {...toastProps}\n ref={composedRefs}\n {...(isWeb && {\n onKeyDown: composeEventHandlers(\n (props as any).onKeyDown,\n (event: KeyboardEvent) => {\n if (event.key !== 'Escape') return\n onEscapeKeyDown?.(event)\n onEscapeKeyDown?.(event)\n if (!event.defaultPrevented) {\n context.isFocusedToastEscapeKeyDownRef.current = true\n handleClose()\n }\n }\n ),\n })}\n />\n </Collection.ItemSlot>\n </AnimatedView>\n </Theme>\n </Dismissable>\n </ToastInteractiveProvider>\n </PortalItem>\n </>\n )\n }\n)\n\nToastImpl.propTypes = {\n type(props) {\n if (props.type && !['foreground', 'background'].includes(props.type)) {\n const error = `Invalid prop \\`type\\` supplied to \\`${TOAST_NAME}\\`. Expected \\`foreground | background\\`.`\n return new Error(error)\n }\n return null\n },\n}\n\n/* ---------------------------------------------------------------------------------------------- */\n\nconst isDeltaInDirection = (\n delta: { x: number; y: number },\n direction: SwipeDirection,\n threshold = 0\n) => {\n const deltaX = Math.abs(delta.x)\n const deltaY = Math.abs(delta.y)\n const isDeltaX = deltaX > deltaY\n if (direction === 'left' || direction === 'right' || direction === 'horizontal') {\n return isDeltaX && deltaX > threshold\n } else {\n return !isDeltaX && deltaY > threshold\n }\n}\n\nfunction getAnnounceTextContent(container: HTMLElement) {\n if (!isWeb) return ''\n const textContent: string[] = []\n const childNodes = Array.from(container.childNodes)\n\n childNodes.forEach((node) => {\n if (node.nodeType === node.TEXT_NODE && node.textContent)\n textContent.push(node.textContent)\n if (isHTMLElement(node)) {\n const isHidden = node.ariaHidden || node.hidden || node.style.display === 'none'\n const isExcluded = node.dataset.toastAnnounceExclude === ''\n\n if (!isHidden) {\n if (isExcluded) {\n const altText = node.dataset.toastAnnounceAlt\n if (altText) textContent.push(altText)\n } else {\n textContent.push(...getAnnounceTextContent(node))\n }\n }\n }\n })\n\n // We return a collection of text rather than a single concatenated string.\n // This allows SR VO to naturally pause break between nodes while announcing.\n return textContent\n}\n\nfunction isHTMLElement(node: any): node is HTMLElement {\n return node.nodeType === node.ELEMENT_NODE\n}\n\nexport { ToastImpl, ToastImplFrame, ToastImplProps, useToastInteractiveContext }\nexport type { ToastProps }\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8SM;AA9SN,8BAA6B;AAC7B,0BAAgC;AAChC,kBAUO;AACP,yBAA8C;AAC9C,oBAA2B;AAC3B,oBAA+B;AAC/B,YAAuB;AACvB,0BAA8D;AAE9D,uBAA2B;AAC3B,2BAA8B;AAC9B,2BAMO;AACP,2BAAgD;AAEhD,MAAM,qBAAiB,oBAAO,8BAAgB;AAAA,EAC5C,MAAM;AAAA,EACN,UAAU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C,YAAY,SAAS;AAAA,EAC/B;AACF;AAEA,SAAS,uBAAuB,WAAwB;AACtD,MAAI,CAAC;AAAO,WAAO;AACnB,QAAM,cAAwB,CAAC;AAC/B,QAAM,aAAa,MAAM,KAAK,UAAU,UAAU;AAElD,aAAW,QAAQ,CAAC,SAAS;AAC3B,QAAI,KAAK,aAAa,KAAK,aAAa,KAAK;AAC3C,kBAAY,KAAK,KAAK,WAAW;AACnC,QAAI,cAAc,IAAI,GAAG;AACvB,YAAM,WAAW,KAAK,cAAc,KAAK,UAAU,KAAK,MAAM,YAAY;AAC1E,YAAM,aAAa,KAAK,QAAQ,yBAAyB;AAEzD,UAAI,CAAC,UAAU;AACb,YAAI,YAAY;AACd,gBAAM,UAAU,KAAK,QAAQ;AAC7B,cAAI;AAAS,wBAAY,KAAK,OAAO;AAAA,QACvC,OAAO;AACL,sBAAY,KAAK,GAAG,uBAAuB,IAAI,CAAC;AAAA,QAClD;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AAID,SAAO;AACT;AAEA,SAAS,cAAc,MAAgC;AACrD,SAAO,KAAK,aAAa,KAAK;AAChC;",
4
+ "sourcesContent": ["import { useIsPresent } from '@tamagui/animate-presence'\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n TamaguiElement,\n Theme,\n composeEventHandlers,\n getAnimationDriver,\n isWeb,\n styled,\n useEvent,\n useThemeName,\n} from '@tamagui/core'\nimport { Dismissable, DismissableProps } from '@tamagui/dismissable'\nimport { PortalItem } from '@tamagui/portal'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport * as React from 'react'\nimport { Animated, GestureResponderEvent, PanResponder } from 'react-native'\n\nimport { TOAST_NAME } from './constants'\nimport { ToastAnnounce } from './ToastAnnounce'\nimport {\n Collection,\n ScopedProps,\n SwipeDirection,\n createToastContext,\n useToastProviderContext,\n} from './ToastProvider'\nimport { VIEWPORT_PAUSE, VIEWPORT_RESUME } from './ToastViewport'\n\nconst ToastImplFrame = styled(ThemeableStack, {\n name: 'ToastImpl',\n variants: {\n backgrounded: {\n true: {\n backgroundColor: '$color6',\n },\n },\n unstyled: {\n false: {\n borderRadius: '$10',\n paddingHorizontal: '$5',\n paddingVertical: '$2',\n marginHorizontal: 'auto',\n marginVertical: '$1',\n },\n },\n },\n defaultVariants: {\n backgrounded: true,\n unstyled: false,\n },\n})\ninterface ToastProps extends Omit<ToastImplProps, keyof ToastImplPrivateProps> {\n /**\n * The controlled open state of the dialog. Must be used in conjunction with `onOpenChange`.\n */\n open?: boolean\n /**\n * The open state of the dialog when it is initially rendered. Use when you do not need to control its open state.\n */\n defaultOpen?: boolean\n /**\n * Event handler called when the open state of the dialog changes.\n */\n onOpenChange?(open: boolean): void\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true\n}\n\ntype SwipeEvent = GestureResponderEvent\n\nconst [ToastInteractiveProvider, useToastInteractiveContext] = createToastContext(\n TOAST_NAME,\n {\n onClose() {},\n }\n)\n\ntype ToastImplPrivateProps = { open: boolean; onClose(): void }\ntype ToastImplFrameProps = GetProps<typeof ToastImplFrame>\ntype ToastImplProps = ToastImplPrivateProps &\n ToastImplFrameProps & {\n /**\n * Control the sensitivity of the toast for accessibility purposes.\n * For toasts that are the result of a user action, choose foreground. Toasts generated from background tasks should use background.\n */\n type?: 'foreground' | 'background'\n /**\n * Time in milliseconds that toast should remain visible for. Overrides value given to `ToastProvider`.\n */\n duration?: number\n /**\n * Event handler called when the escape key is down. It can be prevented by calling `event.preventDefault`.\n */\n onEscapeKeyDown?: DismissableProps['onEscapeKeyDown']\n /**\n * Event handler called when the dismiss timer is paused.\n * On web, this occurs when the pointer is moved over the viewport, the viewport is focused or when the window is blurred.\n * On mobile, this occurs when the toast is touched.\n */\n onPause?(): void\n /**\n * Event handler called when the dismiss timer is resumed.\n * On web, this occurs when the pointer is moved away from the viewport, the viewport is blurred or when the window is focused.\n * On mobile, this occurs when the toast is released.\n */\n onResume?(): void\n /**\n * Event handler called when starting a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeStart?(event: SwipeEvent): void\n /**\n * Event handler called during a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeMove?(event: SwipeEvent): void\n /**\n * Event handler called at the cancellation of a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeCancel?(event: SwipeEvent): void\n /**\n * Event handler called at the end of a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeEnd?(event: SwipeEvent): void\n /**\n * The viewport's name to send the toast to. Used when using multiple viewports and want to forward toasts to different ones.\n *\n * @default \"default\"\n */\n viewportName?: string\n /**\n * \n */\n id?: string\n }\n\nconst ToastImpl = React.forwardRef<TamaguiElement, ToastImplProps>(\n (props: ScopedProps<ToastImplProps>, forwardedRef) => {\n const {\n __scopeToast,\n type = 'foreground',\n duration: durationProp,\n open,\n onClose,\n onEscapeKeyDown,\n onPause,\n onResume,\n onSwipeStart,\n onSwipeMove,\n onSwipeCancel,\n onSwipeEnd,\n viewportName,\n ...toastProps\n } = props\n const isPresent = useIsPresent()\n const context = useToastProviderContext(TOAST_NAME, __scopeToast)\n const [node, setNode] = React.useState<TamaguiElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) => setNode(node))\n const duration = durationProp || context.duration\n const closeTimerStartTimeRef = React.useRef(0)\n const closeTimerRemainingTimeRef = React.useRef(duration)\n const closeTimerRef = React.useRef(0)\n const { onToastAdd, onToastRemove } = context\n const handleClose = useEvent(() => {\n if (!isPresent) {\n // already removed from the react tree\n return\n }\n // focus viewport if focus is within toast to read the remaining toast\n // count to SR users and ensure focus isn't lost\n if (isWeb) {\n const isFocusInToast = (node as HTMLDivElement)?.contains(document.activeElement)\n if (isFocusInToast) context.viewport?.focus()\n }\n onClose()\n })\n\n const startTimer = React.useCallback(\n (duration: number) => {\n if (!duration || duration === Infinity) return\n clearTimeout(closeTimerRef.current)\n closeTimerStartTimeRef.current = new Date().getTime()\n closeTimerRef.current = setTimeout(handleClose, duration) as unknown as number\n },\n [handleClose]\n )\n const handleResume = React.useCallback(() => {\n startTimer(closeTimerRemainingTimeRef.current)\n onResume?.()\n }, [onResume, startTimer])\n const handlePause = React.useCallback(() => {\n const elapsedTime = new Date().getTime() - closeTimerStartTimeRef.current\n closeTimerRemainingTimeRef.current =\n closeTimerRemainingTimeRef.current - elapsedTime\n window.clearTimeout(closeTimerRef.current)\n onPause?.()\n }, [onPause])\n\n React.useEffect(() => {\n if (!isWeb) return\n const viewport = context.viewport as HTMLElement\n if (viewport) {\n viewport.addEventListener(VIEWPORT_PAUSE, handlePause)\n viewport.addEventListener(VIEWPORT_RESUME, handleResume)\n return () => {\n viewport.removeEventListener(VIEWPORT_PAUSE, handlePause)\n viewport.removeEventListener(VIEWPORT_RESUME, handleResume)\n }\n }\n }, [context.viewport, duration, onPause, onResume, startTimer])\n\n // start timer when toast opens or duration changes.\n // we include `open` in deps because closed !== unmounted when animating\n // so it could reopen before being completely unmounted\n React.useEffect(() => {\n if (open && !context.isClosePausedRef.current) {\n startTimer(duration)\n }\n }, [open, duration, context.isClosePausedRef, startTimer])\n\n React.useEffect(() => {\n onToastAdd()\n return () => onToastRemove()\n }, [onToastAdd, onToastRemove])\n\n const announceTextContent = React.useMemo(() => {\n if (!isWeb) return null\n return node ? getAnnounceTextContent(node as HTMLDivElement) : null\n }, [node])\n\n const isHorizontalSwipe = ['left', 'right', 'horizontal'].includes(\n context.swipeDirection\n )\n\n const driver = getAnimationDriver()\n if (!driver) {\n throw new Error('Must set animations in tamagui.config.ts')\n }\n\n const { useAnimatedNumber, useAnimatedNumberStyle } = driver\n\n const animatedNumber = useAnimatedNumber(0)\n\n // temp until reanimated useAnimatedNumber fix\n const AnimatedView = (driver['NumberView'] ?? driver.View) as typeof Animated.View\n\n const animatedStyles = useAnimatedNumberStyle(animatedNumber, (val) => {\n return {\n transform: [isHorizontalSwipe ? { translateX: val } : { translateY: val }],\n }\n })\n\n const panResponder = React.useMemo(() => {\n return PanResponder.create({\n onMoveShouldSetPanResponder: (e) => {\n onSwipeStart?.(e)\n return true\n },\n onPanResponderGrant: (e) => {\n if (!isWeb) {\n handlePause?.()\n }\n },\n onPanResponderMove: (e, { dy, dx }) => {\n let y = 0\n let x = 0\n if (context.swipeDirection === 'horizontal') x = dx\n else if (context.swipeDirection === 'left') x = Math.min(0, dx)\n else if (context.swipeDirection === 'right') x = Math.max(0, dx)\n else if (context.swipeDirection === 'vertical') y = dy\n else if (context.swipeDirection === 'up') y = Math.min(0, dy)\n else if (context.swipeDirection === 'down') y = Math.max(0, dy)\n\n onSwipeMove?.(e)\n\n const delta = { x, y }\n animatedNumber.setValue(isHorizontalSwipe ? x : y, { type: 'direct' })\n if (isDeltaInDirection(delta, context.swipeDirection, context.swipeThreshold)) {\n onSwipeEnd?.(e)\n }\n },\n onPanResponderEnd: (e, { dx, dy }) => {\n if (\n !isDeltaInDirection(\n { x: dx, y: dy },\n context.swipeDirection,\n context.swipeThreshold\n )\n ) {\n if (!isWeb) {\n handleResume?.()\n }\n onSwipeCancel?.(e)\n animatedNumber.setValue(0, { type: 'spring' })\n }\n },\n })\n }, [handlePause, handleResume])\n\n // need to get the theme name from context and apply it again since portals don't retain the theme\n const themeName = useThemeName()\n\n return (\n <>\n {announceTextContent && (\n <ToastAnnounce\n __scopeToast={__scopeToast}\n // Toasts are always role=status to avoid stuttering issues with role=alert in SRs.\n role=\"status\"\n aria-live={type === 'foreground' ? 'assertive' : 'polite'}\n aria-atomic\n >\n {announceTextContent}\n </ToastAnnounce>\n )}\n\n <PortalItem hostName={viewportName ?? 'default'}>\n <ToastInteractiveProvider\n key={props.id}\n scope={__scopeToast}\n onClose={() => {\n handleClose()\n }}\n >\n <Dismissable\n // asChild\n onEscapeKeyDown={composeEventHandlers(onEscapeKeyDown, () => {\n if (!context.isFocusedToastEscapeKeyDownRef.current) {\n handleClose()\n }\n context.isFocusedToastEscapeKeyDownRef.current = false\n })}\n >\n <Theme forceClassName name={themeName}>\n <AnimatedView\n {...panResponder?.panHandlers}\n style={[{ margin: 'auto' }, animatedStyles]}\n >\n <Collection.ItemSlot scope={__scopeToast}>\n <ToastImplFrame\n // Ensure toasts are announced as status list or status when focused\n role=\"status\"\n aria-live=\"off\"\n aria-atomic\n tabIndex={0}\n data-state={open ? 'open' : 'closed'}\n data-swipe-direction={context.swipeDirection}\n pointerEvents=\"auto\"\n // touchAction=\"none\"\n userSelect=\"none\"\n {...toastProps}\n ref={composedRefs}\n {...(isWeb && {\n onKeyDown: composeEventHandlers(\n (props as any).onKeyDown,\n (event: KeyboardEvent) => {\n if (event.key !== 'Escape') return\n onEscapeKeyDown?.(event)\n onEscapeKeyDown?.(event)\n if (!event.defaultPrevented) {\n context.isFocusedToastEscapeKeyDownRef.current = true\n handleClose()\n }\n }\n ),\n })}\n />\n </Collection.ItemSlot>\n </AnimatedView>\n </Theme>\n </Dismissable>\n </ToastInteractiveProvider>\n </PortalItem>\n </>\n )\n }\n)\n\nToastImpl.propTypes = {\n type(props) {\n if (props.type && !['foreground', 'background'].includes(props.type)) {\n const error = `Invalid prop \\`type\\` supplied to \\`${TOAST_NAME}\\`. Expected \\`foreground | background\\`.`\n return new Error(error)\n }\n return null\n },\n}\n\n/* ---------------------------------------------------------------------------------------------- */\n\nconst isDeltaInDirection = (\n delta: { x: number; y: number },\n direction: SwipeDirection,\n threshold = 0\n) => {\n const deltaX = Math.abs(delta.x)\n const deltaY = Math.abs(delta.y)\n const isDeltaX = deltaX > deltaY\n if (direction === 'left' || direction === 'right' || direction === 'horizontal') {\n return isDeltaX && deltaX > threshold\n } else {\n return !isDeltaX && deltaY > threshold\n }\n}\n\nfunction getAnnounceTextContent(container: HTMLElement) {\n if (!isWeb) return ''\n const textContent: string[] = []\n const childNodes = Array.from(container.childNodes)\n\n childNodes.forEach((node) => {\n if (node.nodeType === node.TEXT_NODE && node.textContent)\n textContent.push(node.textContent)\n if (isHTMLElement(node)) {\n const isHidden = node.ariaHidden || node.hidden || node.style.display === 'none'\n const isExcluded = node.dataset.toastAnnounceExclude === ''\n\n if (!isHidden) {\n if (isExcluded) {\n const altText = node.dataset.toastAnnounceAlt\n if (altText) textContent.push(altText)\n } else {\n textContent.push(...getAnnounceTextContent(node))\n }\n }\n }\n })\n\n // We return a collection of text rather than a single concatenated string.\n // This allows SR VO to naturally pause break between nodes while announcing.\n return textContent\n}\n\nfunction isHTMLElement(node: any): node is HTMLElement {\n return node.nodeType === node.ELEMENT_NODE\n}\n\nexport { ToastImpl, ToastImplFrame, ToastImplProps, useToastInteractiveContext }\nexport type { ToastProps }\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkTM;AAlTN,8BAA6B;AAC7B,0BAAgC;AAChC,kBAUO;AACP,yBAA8C;AAC9C,oBAA2B;AAC3B,oBAA+B;AAC/B,YAAuB;AACvB,0BAA8D;AAE9D,uBAA2B;AAC3B,2BAA8B;AAC9B,2BAMO;AACP,2BAAgD;AAEhD,MAAM,qBAAiB,oBAAO,8BAAgB;AAAA,EAC5C,MAAM;AAAA,EACN,UAAU;AAAA,IACR,cAAc;AAAA,MACZ,MAAM;AAAA,QACJ,iBAAiB;AAAA,MACnB;AAAA,IACF;AAAA,IACA,UAAU;AAAA,MACR,OAAO;AAAA,QACL,cAAc;AAAA,QACd,mBAAmB;AAAA,QACnB,iBAAiB;AAAA,QACjB,kBAAkB;AAAA,QAClB,gBAAgB;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AAAA,EACA,iBAAiB;AAAA,IACf,cAAc;AAAA,IACd,UAAU;AAAA,EACZ;AACF,CAAC;AAuBD,MAAM,CAAC,0BAA0B,0BAA0B,QAAI;AAAA,EAC7D;AAAA,EACA;AAAA,IACE,UAAU;AAAA,IAAC;AAAA,EACb;AACF;AA2DA,MAAM,YAAY,MAAM;AAAA,EACtB,CAAC,OAAoC,iBAAiB;AACpD,UAAM;AAAA,MACJ;AAAA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,GAAG,uBAAuB,IAAI,CAAC;AAAA,QAClD;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AAID,SAAO;AACT;AAEA,SAAS,cAAc,MAAgC;AACrD,SAAO,KAAK,aAAa,KAAK;AAChC;",
6
6
  "names": ["node", "duration"]
7
7
  }
@@ -74,6 +74,7 @@ const ToastViewport = React.forwardRef(
74
74
  hotkey = VIEWPORT_DEFAULT_HOTKEY,
75
75
  label = "Notifications ({hotkey})",
76
76
  name,
77
+ multipleToasts,
77
78
  ...viewportProps
78
79
  } = props;
79
80
  const context = (0, import_ToastProvider.useToastProviderContext)(VIEWPORT_NAME, __scopeToast);
@@ -223,7 +224,7 @@ const ToastViewport = React.forwardRef(
223
224
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ToastProvider.Collection.Slot, { scope: __scopeToast, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToastViewportFrame, { ref: composedRefs, ...viewportProps, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
224
225
  import_portal.PortalHost,
225
226
  {
226
- render: (children) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_animate_presence.AnimatePresence, { children }),
227
+ render: (children) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_animate_presence.AnimatePresence, { exitBeforeEnter: !multipleToasts, children }),
227
228
  name: name ?? "default"
228
229
  }
229
230
  ) }) }),
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/ToastViewport.tsx"],
4
- "sourcesContent": ["import { AnimatePresence } from '@tamagui/animate-presence'\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport { GetProps, TamaguiElement, isWeb, styled } from '@tamagui/core'\nimport { PortalHost } from '@tamagui/portal'\nimport { YStack } from '@tamagui/stacks'\nimport { VisuallyHidden } from '@tamagui/visually-hidden'\nimport * as React from 'react'\n\nimport {\n Collection,\n ScopedProps,\n useCollection,\n useToastProviderContext,\n} from './ToastProvider'\n\nconst VIEWPORT_NAME = 'ToastViewport'\nconst VIEWPORT_DEFAULT_HOTKEY = ['F8']\nconst VIEWPORT_PAUSE = 'toast.viewportPause'\nconst VIEWPORT_RESUME = 'toast.viewportResume'\n\nconst ToastViewportWrapperFrame = styled(YStack, {\n name: 'ViewportWrapper',\n pointerEvents: 'box-none',\n top: 0,\n bottom: 0,\n left: 0,\n right: 0,\n // @ts-ignore\n position: isWeb ? 'fixed' : 'absolute',\n maxWidth: '100%',\n tabIndex: 0,\n zIndex: 100000,\n})\n\nconst ToastViewportFrame = styled(YStack, {\n name: VIEWPORT_NAME,\n pointerEvents: 'box-none',\n // @ts-ignore\n position: isWeb ? 'fixed' : 'absolute',\n maxWidth: '100%',\n})\ntype ToastViewportFrameProps = GetProps<typeof ToastViewportFrame>\ntype ToastViewportProps = ToastViewportFrameProps & {\n /**\n * The keys to use as the keyboard shortcut that will move focus to the toast viewport.\n * @defaultValue ['F8']\n */\n hotkey?: string[]\n /**\n * An author-localized label for the toast viewport to provide context for screen reader users\n * when navigating page landmarks. The available `{hotkey}` placeholder will be replaced for you.\n * @defaultValue 'Notifications ({hotkey})'\n */\n label?: string\n /**\n * Used to reference the viewport if you want to have multiple viewports in the same provider.\n */\n name?: string\n}\n\nconst ToastViewport = React.forwardRef<HTMLDivElement, ToastViewportProps>(\n (props: ScopedProps<ToastViewportProps>, forwardedRef) => {\n const {\n __scopeToast,\n hotkey = VIEWPORT_DEFAULT_HOTKEY,\n label = 'Notifications ({hotkey})',\n name,\n ...viewportProps\n } = props\n const context = useToastProviderContext(VIEWPORT_NAME, __scopeToast)\n const getItems = useCollection(__scopeToast)\n const headFocusProxyRef = React.useRef<FocusProxyElement>(null)\n const tailFocusProxyRef = React.useRef<FocusProxyElement>(null)\n const wrapperRef = React.useRef<HTMLDivElement>(null)\n const ref = React.useRef<HTMLDivElement>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref, context.onViewportChange)\n const hotkeyLabel = hotkey.join('+').replace(/Key/g, '').replace(/Digit/g, '')\n const hasToasts = context.toastCount > 0\n\n React.useEffect(() => {\n if (!isWeb) return\n if (context.toastCount === 0) return\n const handleKeyDown = (event: KeyboardEvent) => {\n // we use `event.code` as it is consistent regardless of meta keys that were pressed.\n // for example, `event.key` for `Control+Alt+t` is `\u2020` and `t !== \u2020`\n const isHotkeyPressed = hotkey.every(\n (key) => (event as any)[key] || event.code === key\n )\n if (isHotkeyPressed) ref.current?.focus()\n }\n document.addEventListener('keydown', handleKeyDown)\n return () => {\n document.removeEventListener('keydown', handleKeyDown)\n }\n }, [hotkey, context.toastCount])\n\n React.useEffect(() => {\n if (!isWeb) return\n if (context.toastCount === 0) return\n const wrapper = wrapperRef.current\n const viewport = ref.current\n if (hasToasts && wrapper && viewport) {\n const handlePause = () => {\n if (!context.isClosePausedRef.current) {\n const pauseEvent = new CustomEvent(VIEWPORT_PAUSE)\n viewport.dispatchEvent(pauseEvent)\n context.isClosePausedRef.current = true\n }\n }\n\n const handleResume = () => {\n if (context.isClosePausedRef.current) {\n const resumeEvent = new CustomEvent(VIEWPORT_RESUME)\n viewport.dispatchEvent(resumeEvent)\n context.isClosePausedRef.current = false\n }\n }\n\n const handleFocusOutResume = (event: FocusEvent) => {\n const isFocusMovingOutside = !wrapper.contains(\n event.relatedTarget as HTMLElement\n )\n if (isFocusMovingOutside) handleResume()\n }\n\n const handlePointerLeaveResume = () => {\n const isFocusInside = wrapper.contains(document.activeElement)\n if (!isFocusInside) handleResume()\n }\n // Toasts are not in the viewport React tree so we need to bind DOM events\n\n wrapper.addEventListener('focusin', handlePause)\n wrapper.addEventListener('focusout', handleFocusOutResume)\n wrapper.addEventListener('pointermove', handlePause)\n wrapper.addEventListener('pointerleave', handlePointerLeaveResume)\n window.addEventListener('blur', handlePause)\n window.addEventListener('focus', handleResume)\n return () => {\n wrapper.removeEventListener('focusin', handlePause)\n wrapper.removeEventListener('focusout', handleFocusOutResume)\n wrapper.removeEventListener('pointermove', handlePause)\n wrapper.removeEventListener('pointerleave', handlePointerLeaveResume)\n window.removeEventListener('blur', handlePause)\n window.removeEventListener('focus', handleResume)\n }\n }\n }, [hasToasts, context.isClosePausedRef, context.toastCount])\n\n const getSortedTabbableCandidates = React.useCallback(\n ({ tabbingDirection }: { tabbingDirection: 'forwards' | 'backwards' }) => {\n const toastItems = getItems()\n const tabbableCandidates = toastItems.map((toastItem) => {\n const toastNode = toastItem.ref.current!\n const toastTabbableCandidates = [toastNode, ...getTabbableCandidates(toastNode)]\n return tabbingDirection === 'forwards'\n ? toastTabbableCandidates\n : toastTabbableCandidates.reverse()\n })\n return (\n tabbingDirection === 'forwards'\n ? tabbableCandidates.reverse()\n : tabbableCandidates\n ).flat()\n },\n [getItems]\n )\n\n React.useEffect(() => {\n if (!isWeb) return\n if (context.toastCount === 0) return\n\n const viewport = ref.current\n // We programmatically manage tabbing as we are unable to influence\n // the source order with portals, this allows us to reverse the\n // tab order so that it runs from most recent toast to least\n if (viewport) {\n const handleKeyDown = (event: KeyboardEvent) => {\n const isMetaKey = event.altKey || event.ctrlKey || event.metaKey\n const isTabKey = event.key === 'Tab' && !isMetaKey\n\n if (isTabKey) {\n const focusedElement = document.activeElement\n const isTabbingBackwards = event.shiftKey\n const targetIsViewport = event.target === viewport\n\n // If we're back tabbing after jumping to the viewport then we simply\n // proxy focus out to the preceding document\n if (targetIsViewport && isTabbingBackwards) {\n headFocusProxyRef.current?.focus()\n return\n }\n\n const tabbingDirection = isTabbingBackwards ? 'backwards' : 'forwards'\n const sortedCandidates = getSortedTabbableCandidates({ tabbingDirection })\n const index = sortedCandidates.findIndex(\n (candidate) => candidate === focusedElement\n )\n if (focusFirst(sortedCandidates.slice(index + 1))) {\n event.preventDefault()\n } else {\n // If we can't focus that means we're at the edges so we\n // proxy to the corresponding exit point and let the browser handle\n // tab/shift+tab keypress and implicitly pass focus to the next valid element in the document\n isTabbingBackwards\n ? headFocusProxyRef.current?.focus()\n : tailFocusProxyRef.current?.focus()\n }\n }\n }\n\n // Toasts are not in the viewport React tree so we need to bind DOM events\n viewport.addEventListener('keydown', handleKeyDown)\n return () => viewport.removeEventListener('keydown', handleKeyDown)\n }\n }, [getItems, getSortedTabbableCandidates, context.toastCount])\n\n return (\n <ToastViewportWrapperFrame\n ref={wrapperRef}\n role=\"region\"\n aria-label={label.replace('{hotkey}', hotkeyLabel)}\n // // Ensure virtual cursor from landmarks menus triggers focus/blur for pause/resume\n tabIndex={-1}\n // // incase list has size when empty (e.g. padding), we remove pointer events so\n // // it doesn't prevent interactions with page elements that it overlays\n // pointerEvents={hasToasts ? undefined : 'none'}\n >\n {hasToasts && (\n <FocusProxy\n ref={headFocusProxyRef}\n onFocusFromOutsideViewport={() => {\n const tabbableCandidates = getSortedTabbableCandidates({\n tabbingDirection: 'forwards',\n })\n focusFirst(tabbableCandidates)\n }}\n />\n )}\n {/**\n * tabindex on the the list so that it can be focused when items are removed. we focus\n * the list instead of the viewport so it announces number of items remaining.\n */}\n <Collection.Slot scope={__scopeToast}>\n <ToastViewportFrame ref={composedRefs} {...viewportProps}>\n <PortalHost\n // TODO: user should be able to control this prop to customize AnimatePresence\n render={(children) => <AnimatePresence>{children}</AnimatePresence>}\n name={name ?? 'default'}\n />\n </ToastViewportFrame>\n </Collection.Slot>\n {hasToasts && (\n <FocusProxy\n ref={tailFocusProxyRef}\n onFocusFromOutsideViewport={() => {\n const tabbableCandidates = getSortedTabbableCandidates({\n tabbingDirection: 'backwards',\n })\n focusFirst(tabbableCandidates)\n }}\n />\n )}\n </ToastViewportWrapperFrame>\n )\n }\n)\n\nToastViewport.displayName = VIEWPORT_NAME\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst FOCUS_PROXY_NAME = 'ToastFocusProxy'\n\ntype FocusProxyElement = React.ElementRef<typeof VisuallyHidden>\ntype VisuallyHiddenProps = GetProps<typeof VisuallyHidden>\ninterface FocusProxyProps extends VisuallyHiddenProps {\n onFocusFromOutsideViewport(): void\n}\n\nconst FocusProxy = React.forwardRef<FocusProxyElement, ScopedProps<FocusProxyProps>>(\n (props, forwardedRef) => {\n const { __scopeToast, onFocusFromOutsideViewport, ...proxyProps } = props\n const context = useToastProviderContext(FOCUS_PROXY_NAME, __scopeToast)\n\n return (\n <VisuallyHidden\n aria-hidden\n tabIndex={0}\n {...proxyProps}\n ref={forwardedRef}\n // Avoid page scrolling when focus is on the focus proxy\n position={isWeb ? ('fixed' as any) : 'absolute'}\n onFocus={(event) => {\n if (!isWeb) return\n const prevFocusedElement = event.relatedTarget as HTMLElement | null\n const isFocusFromOutsideViewport = !(context.viewport as HTMLElement)?.contains(\n prevFocusedElement\n )\n if (isFocusFromOutsideViewport) onFocusFromOutsideViewport()\n }}\n />\n )\n }\n)\n\nFocusProxy.displayName = FOCUS_PROXY_NAME\n\n/* -----------------------------------------------------------------------------------------------*/\n\nfunction focusFirst(candidates: TamaguiElement[]) {\n if (!isWeb) return\n const previouslyFocusedElement = document.activeElement\n return candidates.some((candidate) => {\n // if focus is already where we want to go, we don't want to keep going through the candidates\n if (candidate === previouslyFocusedElement) return true\n candidate.focus()\n return document.activeElement !== previouslyFocusedElement\n })\n}\n\n/**\n * Returns a list of potential tabbable candidates.\n *\n * NOTE: This is only a close approximation. For example it doesn't take into account cases like when\n * elements are not visible. This cannot be worked out easily by just reading a property, but rather\n * necessitate runtime knowledge (computed styles, etc). We deal with these cases separately.\n *\n * See: https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker\n * Credit: https://github.com/discord/focus-layers/blob/master/src/util/wrapFocus.tsx#L1\n */\nfunction getTabbableCandidates(container: TamaguiElement) {\n if (!isWeb) return []\n const containerHtml = container as HTMLElement\n const nodes: HTMLElement[] = []\n const walker = document.createTreeWalker(containerHtml, NodeFilter.SHOW_ELEMENT, {\n acceptNode: (node: any) => {\n const isHiddenInput = node.tagName === 'INPUT' && node.type === 'hidden'\n if (node.disabled || node.hidden || isHiddenInput) return NodeFilter.FILTER_SKIP\n // `.tabIndex` is not the same as the `tabindex` attribute. It works on the\n // runtime's understanding of tabbability, so this automatically accounts\n // for any kind of element that could be tabbed to.\n return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP\n },\n })\n while (walker.nextNode()) nodes.push(walker.currentNode as HTMLElement)\n // we do not take into account the order of nodes with positive `tabIndex` as it\n // hinders accessibility to have tab order different from visual order.\n return nodes\n}\n\nexport {\n ToastViewport,\n ToastViewportProps,\n VIEWPORT_DEFAULT_HOTKEY,\n VIEWPORT_PAUSE,\n VIEWPORT_RESUME,\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyNM;AAzNN,8BAAgC;AAChC,0BAAgC;AAChC,kBAAwD;AACxD,oBAA2B;AAC3B,oBAAuB;AACvB,6BAA+B;AAC/B,YAAuB;AAEvB,2BAKO;AAEP,MAAM,gBAAgB;AACtB,MAAM,0BAA0B,CAAC,IAAI;AACrC,MAAM,iBAAiB;AACvB,MAAM,kBAAkB;AAExB,MAAM,gCAA4B,oBAAO,sBAAQ;AAAA,EAC/C,MAAM;AAAA,EACN,eAAe;AAAA,EACf,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AAAA;AAAA,EAEP,UAAU,oBAAQ,UAAU;AAAA,EAC5B,UAAU;AAAA,EACV,UAAU;AAAA,EACV,QAAQ;AACV,CAAC;AAED,MAAM,yBAAqB,oBAAO,sBAAQ;AAAA,EACxC,MAAM;AAAA,EACN,eAAe;AAAA;AAAA,EAEf,UAAU,oBAAQ,UAAU;AAAA,EAC5B,UAAU;AACZ,CAAC;AAoBD,MAAM,gBAAgB,MAAM;AAAA,EAC1B,CAAC,OAAwC,iBAAiB;AACxD,UAAM;AAAA,MACJ;AAAA,MACA,SAAS;AAAA,MACT,QAAQ;AAAA,MACR;AAAA,MACA,GAAG;AAAA,IACL,IAAI;AACJ,UAAM,cAAU,8CAAwB,eAAe,YAAY;AACnE,UAAM,eAAW,o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ACnD,cAAU,MAAM;AAChB,WAAO,SAAS,kBAAkB;AAAA,EACpC,CAAC;AACH;AAYA,SAAS,sBAAsB,WAA2B;AACxD,MAAI,CAAC;AAAO,WAAO,CAAC;AACpB,QAAM,gBAAgB;AACtB,QAAM,QAAuB,CAAC;AAC9B,QAAM,SAAS,SAAS,iBAAiB,eAAe,WAAW,cAAc;AAAA,IAC/E,YAAY,CAAC,SAAc;AACzB,YAAM,gBAAgB,KAAK,YAAY,WAAW,KAAK,SAAS;AAChE,UAAI,KAAK,YAAY,KAAK,UAAU;AAAe,eAAO,WAAW;AAIrE,aAAO,KAAK,YAAY,IAAI,WAAW,gBAAgB,WAAW;AAAA,IACpE;AAAA,EACF,CAAC;AACD,SAAO,OAAO,SAAS;AAAG,UAAM,KAAK,OAAO,WAA0B;AAGtE,SAAO;AACT;",
4
+ "sourcesContent": ["import { AnimatePresence } from '@tamagui/animate-presence'\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport { GetProps, TamaguiElement, isWeb, styled } from '@tamagui/core'\nimport { PortalHost } from '@tamagui/portal'\nimport { YStack } from '@tamagui/stacks'\nimport { VisuallyHidden } from '@tamagui/visually-hidden'\nimport * as React from 'react'\n\nimport {\n Collection,\n ScopedProps,\n useCollection,\n useToastProviderContext,\n} from './ToastProvider'\n\nconst VIEWPORT_NAME = 'ToastViewport'\nconst VIEWPORT_DEFAULT_HOTKEY = ['F8']\nconst VIEWPORT_PAUSE = 'toast.viewportPause'\nconst VIEWPORT_RESUME = 'toast.viewportResume'\n\nconst ToastViewportWrapperFrame = styled(YStack, {\n name: 'ViewportWrapper',\n pointerEvents: 'box-none',\n top: 0,\n bottom: 0,\n left: 0,\n right: 0,\n // @ts-ignore\n position: isWeb ? 'fixed' : 'absolute',\n maxWidth: '100%',\n tabIndex: 0,\n zIndex: 100000,\n})\n\nconst ToastViewportFrame = styled(YStack, {\n name: VIEWPORT_NAME,\n pointerEvents: 'box-none',\n // @ts-ignore\n position: isWeb ? 'fixed' : 'absolute',\n maxWidth: '100%',\n})\ntype ToastViewportFrameProps = GetProps<typeof ToastViewportFrame>\ntype ToastViewportProps = ToastViewportFrameProps & {\n /**\n * The keys to use as the keyboard shortcut that will move focus to the toast viewport.\n * @defaultValue ['F8']\n */\n hotkey?: string[]\n /**\n * An author-localized label for the toast viewport to provide context for screen reader users\n * when navigating page landmarks. The available `{hotkey}` placeholder will be replaced for you.\n * @defaultValue 'Notifications ({hotkey})'\n */\n label?: string\n /**\n * Used to reference the viewport if you want to have multiple viewports in the same provider.\n */\n name?: string\n /**\n * Pass this when you want to have multiple/duplicated toasts.\n */\n multipleToasts?: boolean\n}\n\nconst ToastViewport = React.forwardRef<HTMLDivElement, ToastViewportProps>(\n (props: ScopedProps<ToastViewportProps>, forwardedRef) => {\n const {\n __scopeToast,\n hotkey = VIEWPORT_DEFAULT_HOTKEY,\n label = 'Notifications ({hotkey})',\n name,\n multipleToasts,\n ...viewportProps\n } = props\n const context = useToastProviderContext(VIEWPORT_NAME, __scopeToast)\n const getItems = useCollection(__scopeToast)\n const headFocusProxyRef = React.useRef<FocusProxyElement>(null)\n const tailFocusProxyRef = React.useRef<FocusProxyElement>(null)\n const wrapperRef = React.useRef<HTMLDivElement>(null)\n const ref = React.useRef<HTMLDivElement>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref, context.onViewportChange)\n const hotkeyLabel = hotkey.join('+').replace(/Key/g, '').replace(/Digit/g, '')\n const hasToasts = context.toastCount > 0\n\n React.useEffect(() => {\n if (!isWeb) return\n if (context.toastCount === 0) return\n const handleKeyDown = (event: KeyboardEvent) => {\n // we use `event.code` as it is consistent regardless of meta keys that were pressed.\n // for example, `event.key` for `Control+Alt+t` is `\u2020` and `t !== \u2020`\n const isHotkeyPressed = hotkey.every(\n (key) => (event as any)[key] || event.code === key\n )\n if (isHotkeyPressed) ref.current?.focus()\n }\n document.addEventListener('keydown', handleKeyDown)\n return () => {\n document.removeEventListener('keydown', handleKeyDown)\n }\n }, [hotkey, context.toastCount])\n\n React.useEffect(() => {\n if (!isWeb) return\n if (context.toastCount === 0) return\n const wrapper = wrapperRef.current\n const viewport = ref.current\n if (hasToasts && wrapper && viewport) {\n const handlePause = () => {\n if (!context.isClosePausedRef.current) {\n const pauseEvent = new CustomEvent(VIEWPORT_PAUSE)\n viewport.dispatchEvent(pauseEvent)\n context.isClosePausedRef.current = true\n }\n }\n\n const handleResume = () => {\n if (context.isClosePausedRef.current) {\n const resumeEvent = new CustomEvent(VIEWPORT_RESUME)\n viewport.dispatchEvent(resumeEvent)\n context.isClosePausedRef.current = false\n }\n }\n\n const handleFocusOutResume = (event: FocusEvent) => {\n const isFocusMovingOutside = !wrapper.contains(\n event.relatedTarget as HTMLElement\n )\n if (isFocusMovingOutside) handleResume()\n }\n\n const handlePointerLeaveResume = () => {\n const isFocusInside = wrapper.contains(document.activeElement)\n if (!isFocusInside) handleResume()\n }\n // Toasts are not in the viewport React tree so we need to bind DOM events\n\n wrapper.addEventListener('focusin', handlePause)\n wrapper.addEventListener('focusout', handleFocusOutResume)\n wrapper.addEventListener('pointermove', handlePause)\n wrapper.addEventListener('pointerleave', handlePointerLeaveResume)\n window.addEventListener('blur', handlePause)\n window.addEventListener('focus', handleResume)\n return () => {\n wrapper.removeEventListener('focusin', handlePause)\n wrapper.removeEventListener('focusout', handleFocusOutResume)\n wrapper.removeEventListener('pointermove', handlePause)\n wrapper.removeEventListener('pointerleave', handlePointerLeaveResume)\n window.removeEventListener('blur', handlePause)\n window.removeEventListener('focus', handleResume)\n }\n }\n }, [hasToasts, context.isClosePausedRef, context.toastCount])\n\n const getSortedTabbableCandidates = React.useCallback(\n ({ tabbingDirection }: { tabbingDirection: 'forwards' | 'backwards' }) => {\n const toastItems = getItems()\n const tabbableCandidates = toastItems.map((toastItem) => {\n const toastNode = toastItem.ref.current!\n const toastTabbableCandidates = [toastNode, ...getTabbableCandidates(toastNode)]\n return tabbingDirection === 'forwards'\n ? toastTabbableCandidates\n : toastTabbableCandidates.reverse()\n })\n return (\n tabbingDirection === 'forwards'\n ? tabbableCandidates.reverse()\n : tabbableCandidates\n ).flat()\n },\n [getItems]\n )\n\n React.useEffect(() => {\n if (!isWeb) return\n if (context.toastCount === 0) return\n\n const viewport = ref.current\n // We programmatically manage tabbing as we are unable to influence\n // the source order with portals, this allows us to reverse the\n // tab order so that it runs from most recent toast to least\n if (viewport) {\n const handleKeyDown = (event: KeyboardEvent) => {\n const isMetaKey = event.altKey || event.ctrlKey || event.metaKey\n const isTabKey = event.key === 'Tab' && !isMetaKey\n\n if (isTabKey) {\n const focusedElement = document.activeElement\n const isTabbingBackwards = event.shiftKey\n const targetIsViewport = event.target === viewport\n\n // If we're back tabbing after jumping to the viewport then we simply\n // proxy focus out to the preceding document\n if (targetIsViewport && isTabbingBackwards) {\n headFocusProxyRef.current?.focus()\n return\n }\n\n const tabbingDirection = isTabbingBackwards ? 'backwards' : 'forwards'\n const sortedCandidates = getSortedTabbableCandidates({ tabbingDirection })\n const index = sortedCandidates.findIndex(\n (candidate) => candidate === focusedElement\n )\n if (focusFirst(sortedCandidates.slice(index + 1))) {\n event.preventDefault()\n } else {\n // If we can't focus that means we're at the edges so we\n // proxy to the corresponding exit point and let the browser handle\n // tab/shift+tab keypress and implicitly pass focus to the next valid element in the document\n isTabbingBackwards\n ? headFocusProxyRef.current?.focus()\n : tailFocusProxyRef.current?.focus()\n }\n }\n }\n\n // Toasts are not in the viewport React tree so we need to bind DOM events\n viewport.addEventListener('keydown', handleKeyDown)\n return () => viewport.removeEventListener('keydown', handleKeyDown)\n }\n }, [getItems, getSortedTabbableCandidates, context.toastCount])\n\n return (\n <ToastViewportWrapperFrame\n ref={wrapperRef}\n role=\"region\"\n aria-label={label.replace('{hotkey}', hotkeyLabel)}\n // // Ensure virtual cursor from landmarks menus triggers focus/blur for pause/resume\n tabIndex={-1}\n // // incase list has size when empty (e.g. padding), we remove pointer events so\n // // it doesn't prevent interactions with page elements that it overlays\n // pointerEvents={hasToasts ? undefined : 'none'}\n >\n {hasToasts && (\n <FocusProxy\n ref={headFocusProxyRef}\n onFocusFromOutsideViewport={() => {\n const tabbableCandidates = getSortedTabbableCandidates({\n tabbingDirection: 'forwards',\n })\n focusFirst(tabbableCandidates)\n }}\n />\n )}\n {/**\n * tabindex on the the list so that it can be focused when items are removed. we focus\n * the list instead of the viewport so it announces number of items remaining.\n */}\n <Collection.Slot scope={__scopeToast}>\n <ToastViewportFrame ref={composedRefs} {...viewportProps}>\n <PortalHost\n render={(children) => (\n <AnimatePresence exitBeforeEnter={!multipleToasts}>\n {children}\n </AnimatePresence>\n )}\n name={name ?? 'default'}\n />\n </ToastViewportFrame>\n </Collection.Slot>\n {hasToasts && (\n <FocusProxy\n ref={tailFocusProxyRef}\n onFocusFromOutsideViewport={() => {\n const tabbableCandidates = getSortedTabbableCandidates({\n tabbingDirection: 'backwards',\n })\n focusFirst(tabbableCandidates)\n }}\n />\n )}\n </ToastViewportWrapperFrame>\n )\n }\n)\n\nToastViewport.displayName = VIEWPORT_NAME\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst FOCUS_PROXY_NAME = 'ToastFocusProxy'\n\ntype FocusProxyElement = React.ElementRef<typeof VisuallyHidden>\ntype VisuallyHiddenProps = GetProps<typeof VisuallyHidden>\ninterface FocusProxyProps extends VisuallyHiddenProps {\n onFocusFromOutsideViewport(): void\n}\n\nconst FocusProxy = React.forwardRef<FocusProxyElement, ScopedProps<FocusProxyProps>>(\n (props, forwardedRef) => {\n const { __scopeToast, onFocusFromOutsideViewport, ...proxyProps } = props\n const context = useToastProviderContext(FOCUS_PROXY_NAME, __scopeToast)\n\n return (\n <VisuallyHidden\n aria-hidden\n tabIndex={0}\n {...proxyProps}\n ref={forwardedRef}\n // Avoid page scrolling when focus is on the focus proxy\n position={isWeb ? ('fixed' as any) : 'absolute'}\n onFocus={(event) => {\n if (!isWeb) return\n const prevFocusedElement = event.relatedTarget as HTMLElement | null\n const isFocusFromOutsideViewport = !(context.viewport as HTMLElement)?.contains(\n prevFocusedElement\n )\n if (isFocusFromOutsideViewport) onFocusFromOutsideViewport()\n }}\n />\n )\n }\n)\n\nFocusProxy.displayName = FOCUS_PROXY_NAME\n\n/* -----------------------------------------------------------------------------------------------*/\n\nfunction focusFirst(candidates: TamaguiElement[]) {\n if (!isWeb) return\n const previouslyFocusedElement = document.activeElement\n return candidates.some((candidate) => {\n // if focus is already where we want to go, we don't want to keep going through the candidates\n if (candidate === previouslyFocusedElement) return true\n candidate.focus()\n return document.activeElement !== previouslyFocusedElement\n })\n}\n\n/**\n * Returns a list of potential tabbable candidates.\n *\n * NOTE: This is only a close approximation. For example it doesn't take into account cases like when\n * elements are not visible. This cannot be worked out easily by just reading a property, but rather\n * necessitate runtime knowledge (computed styles, etc). We deal with these cases separately.\n *\n * See: https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker\n * Credit: https://github.com/discord/focus-layers/blob/master/src/util/wrapFocus.tsx#L1\n */\nfunction getTabbableCandidates(container: TamaguiElement) {\n if (!isWeb) return []\n const containerHtml = container as HTMLElement\n const nodes: HTMLElement[] = []\n const walker = document.createTreeWalker(containerHtml, NodeFilter.SHOW_ELEMENT, {\n acceptNode: (node: any) => {\n const isHiddenInput = node.tagName === 'INPUT' && node.type === 'hidden'\n if (node.disabled || node.hidden || isHiddenInput) return NodeFilter.FILTER_SKIP\n // `.tabIndex` is not the same as the `tabindex` attribute. It works on the\n // runtime's understanding of tabbability, so this automatically accounts\n // for any kind of element that could be tabbed to.\n return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP\n },\n })\n while (walker.nextNode()) nodes.push(walker.currentNode as HTMLElement)\n // we do not take into account the order of nodes with positive `tabIndex` as it\n // hinders accessibility to have tab order different from visual order.\n return nodes\n}\n\nexport {\n ToastViewport,\n ToastViewportProps,\n VIEWPORT_DEFAULT_HOTKEY,\n VIEWPORT_PAUSE,\n VIEWPORT_RESUME,\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;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AAK,YAAY,KAAK,UAAU;AAAe,eAAO,WAAW;AAIrE,aAAO,KAAK,YAAY,IAAI,WAAW,gBAAgB,WAAW;AAAA,IACpE;AAAA,EACF,CAAC;AACD,SAAO,OAAO,SAAS;AAAG,UAAM,KAAK,OAAO,WAA0B;AAGtE,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -18,32 +18,53 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var createNativeToast_exports = {};
20
20
  __export(createNativeToast_exports, {
21
- createNativeToast: () => createNativeToast
21
+ createNativeToast: () => createNativeToast,
22
+ hideNativeToast: () => hideNativeToast
22
23
  });
23
24
  module.exports = __toCommonJS(createNativeToast_exports);
24
- const createNativeToast = (title, { message }) => {
25
+ const createNativeToast = (title, { message, notificationOptions }) => {
25
26
  if (!("Notification" in window)) {
26
- throw Error("This browser does not support desktop notification");
27
+ console.error("This browser does not support notifications");
28
+ return false;
27
29
  }
28
30
  if (Notification.permission === "denied")
29
- return {};
31
+ false;
30
32
  const showNotification = () => {
31
- new Notification(title, {
32
- body: message
33
+ const notification = new Notification(title, {
34
+ body: message,
35
+ ...notificationOptions
33
36
  });
37
+ return notification;
34
38
  };
35
39
  if (Notification.permission === "granted") {
36
- showNotification();
40
+ const notification = showNotification();
41
+ return {
42
+ nativeToastRef: notification
43
+ };
37
44
  } else {
38
45
  Notification.requestPermission().then((permission) => {
39
46
  if (permission === "granted") {
40
- showNotification();
47
+ const notification = showNotification();
48
+ return {
49
+ nativeToastRef: notification
50
+ };
41
51
  }
42
52
  });
43
53
  }
54
+ return true;
55
+ };
56
+ const hideNativeToast = (ref) => {
57
+ if (!("Notification" in window)) {
58
+ console.error("This browser does not support notifications");
59
+ return;
60
+ }
61
+ if (ref) {
62
+ ref.close();
63
+ }
44
64
  };
45
65
  // Annotate the CommonJS export names for ESM import in node:
46
66
  0 && (module.exports = {
47
- createNativeToast
67
+ createNativeToast,
68
+ hideNativeToast
48
69
  });
49
70
  //# sourceMappingURL=createNativeToast.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/createNativeToast.tsx"],
4
- "sourcesContent": ["import { CreateNativeToastsOptionsFn } from './types'\n\nexport const createNativeToast: CreateNativeToastsOptionsFn = (title, { message }) => {\n if (!('Notification' in window)) {\n throw Error('This browser does not support desktop notification')\n }\n\n if (Notification.permission === 'denied') return {}\n\n const showNotification = () => {\n new Notification(title, {\n body: message,\n })\n }\n\n if (Notification.permission === 'granted') {\n showNotification()\n } else {\n Notification.requestPermission().then((permission) => {\n if (permission === 'granted') {\n showNotification()\n }\n })\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,oBAAiD,CAAC,OAAO,EAAE,QAAQ,MAAM;AACpF,MAAI,EAAE,kBAAkB,SAAS;AAC/B,UAAM,MAAM,oDAAoD;AAAA,EAClE;AAEA,MAAI,aAAa,eAAe;AAAU,WAAO,CAAC;AAElD,QAAM,mBAAmB,MAAM;AAC7B,QAAI,aAAa,OAAO;AAAA,MACtB,MAAM;AAAA,IACR,CAAC;AAAA,EACH;AAEA,MAAI,aAAa,eAAe,WAAW;AACzC,qBAAiB;AAAA,EACnB,OAAO;AACL,iBAAa,kBAAkB,EAAE,KAAK,CAAC,eAAe;AACpD,UAAI,eAAe,WAAW;AAC5B,yBAAiB;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,EACH;AACF;",
4
+ "sourcesContent": ["import { CreateNativeToastsFn, HideNativeToastsFn } from './types'\n\nexport const createNativeToast: CreateNativeToastsFn = (\n title,\n { message, notificationOptions }\n) => {\n if (!('Notification' in window)) {\n console.error('This browser does not support notifications')\n return false\n }\n\n if (Notification.permission === 'denied') false\n const showNotification = () => {\n const notification = new Notification(title, {\n body: message,\n ...notificationOptions,\n })\n\n return notification\n }\n\n if (Notification.permission === 'granted') {\n const notification = showNotification()\n return {\n nativeToastRef: notification,\n }\n } else {\n Notification.requestPermission().then((permission) => {\n if (permission === 'granted') {\n const notification = showNotification()\n return {\n nativeToastRef: notification,\n }\n }\n })\n }\n return true\n}\n\nexport const hideNativeToast: HideNativeToastsFn = (ref) => {\n if (!('Notification' in window)) {\n console.error('This browser does not support notifications')\n return\n }\n\n if (ref) {\n ref.close()\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,oBAA0C,CACrD,OACA,EAAE,SAAS,oBAAoB,MAC5B;AACH,MAAI,EAAE,kBAAkB,SAAS;AAC/B,YAAQ,MAAM,6CAA6C;AAC3D,WAAO;AAAA,EACT;AAEA,MAAI,aAAa,eAAe;AAAU;AAC1C,QAAM,mBAAmB,MAAM;AAC7B,UAAM,eAAe,IAAI,aAAa,OAAO;AAAA,MAC3C,MAAM;AAAA,MACN,GAAG;AAAA,IACL,CAAC;AAED,WAAO;AAAA,EACT;AAEA,MAAI,aAAa,eAAe,WAAW;AACzC,UAAM,eAAe,iBAAiB;AACtC,WAAO;AAAA,MACL,gBAAgB;AAAA,IAClB;AAAA,EACF,OAAO;AACL,iBAAa,kBAAkB,EAAE,KAAK,CAAC,eAAe;AACpD,UAAI,eAAe,WAAW;AAC5B,cAAM,eAAe,iBAAiB;AACtC,eAAO;AAAA,UACL,gBAAgB;AAAA,QAClB;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAEO,MAAM,kBAAsC,CAAC,QAAQ;AAC1D,MAAI,EAAE,kBAAkB,SAAS;AAC/B,YAAQ,MAAM,6CAA6C;AAC3D;AAAA,EACF;AAEA,MAAI,KAAK;AACP,QAAI,MAAM;AAAA,EACZ;AACF;",
6
6
  "names": []
7
7
  }
@@ -18,20 +18,27 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var createNativeToast_native_exports = {};
20
20
  __export(createNativeToast_native_exports, {
21
- createNativeToast: () => createNativeToast
21
+ createNativeToast: () => createNativeToast,
22
+ hideNativeToast: () => hideNativeToast
22
23
  });
23
24
  module.exports = __toCommonJS(createNativeToast_native_exports);
24
- const createNativeToast = (title, { message, duration, preset = "done" }) => {
25
+ const createNativeToast = (title, { message, duration, burntOptions }) => {
25
26
  const Burnt = require("burnt");
26
27
  Burnt.toast({
27
28
  title,
28
- message: message ?? "",
29
- preset,
30
- duration
29
+ message,
30
+ duration: duration ? duration * 1e3 : void 0,
31
+ ...burntOptions
31
32
  });
33
+ return true;
34
+ };
35
+ const hideNativeToast = () => {
36
+ const Burnt = require("burnt");
37
+ Burnt.dismissAllAlerts();
32
38
  };
33
39
  // Annotate the CommonJS export names for ESM import in node:
34
40
  0 && (module.exports = {
35
- createNativeToast
41
+ createNativeToast,
42
+ hideNativeToast
36
43
  });
37
44
  //# sourceMappingURL=createNativeToast.native.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/createNativeToast.native.tsx"],
4
- "sourcesContent": ["import { CreateNativeToastsOptions, CreateNativeToastsOptionsFn } from './types'\n\nexport const createNativeToast: CreateNativeToastsOptionsFn = (\n title,\n { message, duration, preset = 'done' }: CreateNativeToastsOptions\n) => {\n // import inline to allow lazy usage of native dependecy:\n const Burnt = require('burnt')\n\n Burnt.toast({\n title,\n message: message ?? '',\n preset,\n duration,\n })\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,oBAAiD,CAC5D,OACA,EAAE,SAAS,UAAU,SAAS,OAAO,MAClC;AAEH,QAAM,QAAQ,QAAQ,OAAO;AAE7B,QAAM,MAAM;AAAA,IACV;AAAA,IACA,SAAS,WAAW;AAAA,IACpB;AAAA,IACA;AAAA,EACF,CAAC;AACH;",
4
+ "sourcesContent": ["import { BaseToastOptions as BurntToastOptions } from 'burnt/build/types'\n\nimport {\n CreateNativeToastsFn,\n HideNativeToastsFn\n} from './types'\n\nexport const createNativeToast: CreateNativeToastsFn = (\n title,\n { message, duration, burntOptions }\n) => {\n // import inline to allow lazy usage of native dependecy:\n const Burnt: { toast: (options: BurntToastOptions) => any } = require('burnt')\n\n Burnt.toast({\n title,\n message,\n duration: duration ? duration * 1000 : undefined,\n ...burntOptions,\n })\n return true\n}\n\nexport const hideNativeToast: HideNativeToastsFn = () => {\n const Burnt: { dismissAllAlerts: () => any } = require('burnt')\n Burnt.dismissAllAlerts()\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,MAAM,oBAA0C,CACrD,OACA,EAAE,SAAS,UAAU,aAAa,MAC/B;AAEH,QAAM,QAAwD,QAAQ,OAAO;AAE7E,QAAM,MAAM;AAAA,IACV;AAAA,IACA;AAAA,IACA,UAAU,WAAW,WAAW,MAAO;AAAA,IACvC,GAAG;AAAA,EACL,CAAC;AACD,SAAO;AACT;AAEO,MAAM,kBAAsC,MAAM;AACvD,QAAM,QAAyC,QAAQ,OAAO;AAC9D,QAAM,iBAAiB;AACzB;",
6
6
  "names": []
7
7
  }
package/dist/cjs/index.js CHANGED
@@ -16,4 +16,5 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
16
16
  var src_exports = {};
17
17
  module.exports = __toCommonJS(src_exports);
18
18
  __reExport(src_exports, require("./Toast"), module.exports);
19
+ __reExport(src_exports, require("./ToastImperative"), module.exports);
19
20
  //# sourceMappingURL=index.js.map