{"version":3,"file":"toaster.cjs","sources":["../src/toaster.ts"],"sourcesContent":["import { OverlayToaster } from \"@blueprintjs/core\";\nimport h from \"@macrostrat/hyper\";\nimport { createContext, useState, useContext, RefObject } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport type { OverlayToasterProps } from \"@blueprintjs/core\";\n\n// We might want to refactor this\nfunction createAppToaster() {\n  return OverlayToaster.create();\n}\n\ntype ContextualToasterProps = Omit<\n  OverlayToasterProps,\n  \"ref\" | \"usePortal\"\n> & {};\n\nexport type ToasterContextProps = ContextualToasterProps & {\n  children?: React.ReactNode;\n  toasts?: React.ReactNode;\n  containerRef?: RefObject<HTMLElement>;\n};\n\nconst ToasterCtx = createContext<any>(null);\n\nexport function ContextualToaster({ containerRef, setToaster, ...rest }) {\n  const toaster = h(OverlayToaster, {\n    usePortal: false,\n    ref: (t) => setToaster(t),\n    ...rest,\n  });\n  if (containerRef?.current == null) {\n    return toaster;\n  }\n  return createPortal(toaster, containerRef.current);\n}\n\nfunction ToasterContext(props: ToasterContextProps) {\n  const { children, toasts, containerRef, ...rest } = props;\n  const [toaster, setToaster] = useState<any>(null);\n\n  return h(ToasterCtx.Provider, { value: toaster }, [\n    h(ContextualToaster, { containerRef, setToaster, ...rest }, toasts),\n    children,\n  ]);\n}\n\nfunction useToaster(): any | null {\n  return useContext(ToasterCtx);\n}\n\nexport { createAppToaster, ToasterContext, useToaster };\n"],"names":["OverlayToaster","createContext","h","createPortal","useState","useContext"],"mappings":";;;;;;;;AAOA,SAAS,mBAAmB;AAC1B,SAAOA,KAAAA,eAAe,OAAA;AACxB;AAaA,MAAM,aAAaC,MAAAA,cAAmB,IAAI;AAEnC,SAAS,kBAAkB,EAAE,cAAc,YAAY,GAAG,QAAQ;AACvE,QAAM,UAAUC,WAAAA,QAAEF,qBAAgB;AAAA,IAChC,WAAW;AAAA,IACX,KAAK,CAAC,MAAM,WAAW,CAAC;AAAA,IACxB,GAAG;AAAA,EAAA,CACJ;AACD,MAAI,cAAc,WAAW,MAAM;AACjC,WAAO;AAAA,EACT;AACA,SAAOG,sBAAa,SAAS,aAAa,OAAO;AACnD;AAEA,SAAS,eAAe,OAA4B;AAClD,QAAM,EAAE,UAAU,QAAQ,cAAc,GAAG,SAAS;AACpD,QAAM,CAAC,SAAS,UAAU,IAAIC,MAAAA,SAAc,IAAI;AAEhD,SAAOF,WAAAA,QAAE,WAAW,UAAU,EAAE,OAAO,WAAW;AAAA,IAChDA,WAAAA,QAAE,mBAAmB,EAAE,cAAc,YAAY,GAAG,KAAA,GAAQ,MAAM;AAAA,IAClE;AAAA,EAAA,CACD;AACH;AAEA,SAAS,aAAyB;AAChC,SAAOG,MAAAA,WAAW,UAAU;AAC9B;;;;;"}