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AqB,QAAQ,mBAAmB;QAChD,GAAG,CAAA,GAAA,qBAAa,EAAE,QAAQ;IAC5B;IAEA,kFAAkF;IAClF,6EAA6E;IAC7E,iEAAiE;IACjE,IAAI,UAAU,QAAQ,OAAO,IAAI,CAAC,QAAQ,QAAQ,GAAG,KAAK,GAAG,CAAC,QAAQ,OAAO,EAAE,QAAQ;IACvF,IAAI,QAAQ;IACZ,IAAI,MAAM,MAAM,GAAG,CAAC,OAAO;iBAAC;QAAS,SAAS,QAAQ,OAAO;IAAA;IAC7D,OAAO,IAAM,MAAM,KAAK,CAAC;AAC3B;AAEA,MAAM,4CAAqB;IACzB,4BAA4B,GAC5B,SAAQ,QAAgB,EAAE,UAAgC,CAAC,CAAC;QAC1D,OAAO,+BAAS,UAAU,WAAW;IACvC;IACA,6BAA6B,GAC7B,UAAS,QAAgB,EAAE,UAAgC,CAAC,CAAC;QAC3D,OAAO,+BAAS,UAAU,YAAY;IACxC;IACA,6BAA6B,GAC7B,UAAS,QAAgB,EAAE,UAAgC,CAAC,CAAC;QAC3D,OAAO,+BAAS,UAAU,YAAY;IACxC;IACA,mCAAmC,GACnC,MAAK,QAAgB,EAAE,UAAgC,CAAC,CAAC;QACvD,OAAO,+BAAS,UAAU,QAAQ;IACpC;AACF","sources":["packages/@adobe/react-spectrum/src/toast/ToastContainer.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaToastRegionProps} from 'react-aria/useToast';\nimport {classNames} from '../utils/classNames';\nimport {DOMProps} from '@react-types/shared';\nimport {filterDOMProps} from 'react-aria/filterDOMProps';\nimport {flushSync} from 'react-dom';\nimport React, {ReactElement, useEffect, useMemo, useRef} from 'react';\nimport {SpectrumToastValue, Toast} from './Toast';\nimport toastContainerStyles from './toastContainer.css';\nimport {Toaster} from './Toaster';\nimport {ToastOptions, ToastQueue, useToastQueue} from 'react-stately/useToastState';\nimport {useSyncExternalStore} from 'use-sync-external-store/shim/index.js';\n\nexport type ToastPlacement = 'top' | 'top end' | 'bottom' | 'bottom end';\n\nexport interface SpectrumToastContainerProps extends AriaToastRegionProps {\n  placement?: ToastPlacement;\n}\n\nexport interface SpectrumToastOptions extends ToastOptions, DOMProps {\n  /** A label for the action button within the toast. */\n  actionLabel?: string;\n  /** Handler that is called when the action button is pressed. */\n  onAction?: () => void;\n  /** Whether the toast should automatically close when an action is performed. */\n  shouldCloseOnAction?: boolean;\n}\n\nexport type CloseFunction = () => void;\n\nfunction wrapInViewTransition(fn: () => void): void {\n  if ('startViewTransition' in document) {\n    document\n      .startViewTransition(() => {\n        flushSync(fn);\n      })\n      .ready.catch(() => {});\n  } else {\n    fn();\n  }\n}\n\n// There is a single global toast queue instance for the whole app, initialized lazily.\nlet globalToastQueue: ToastQueue<SpectrumToastValue> | null = null;\nfunction getGlobalToastQueue() {\n  if (!globalToastQueue) {\n    globalToastQueue = new ToastQueue({\n      maxVisibleToasts: Infinity,\n      wrapUpdate: wrapInViewTransition\n    });\n  }\n\n  return globalToastQueue;\n}\n\n// For testing. Not exported from the package index.\nexport function clearToastQueue(): void {\n  globalToastQueue = null;\n}\n\nlet toastProviders = new Set();\nlet subscriptions = new Set<() => void>();\nfunction subscribe(fn: () => void) {\n  subscriptions.add(fn);\n  return () => subscriptions.delete(fn);\n}\n\nfunction triggerSubscriptions() {\n  for (let fn of subscriptions) {\n    fn();\n  }\n}\n\nfunction getActiveToastContainer() {\n  return toastProviders.values().next().value;\n}\n\nfunction useActiveToastContainer() {\n  return useSyncExternalStore(subscribe, getActiveToastContainer, getActiveToastContainer);\n}\n\n/**\n * A ToastContainer renders the queued toasts in an application. It should be placed\n * at the root of the app.\n */\nexport function ToastContainer(props: SpectrumToastContainerProps): ReactElement | null {\n  // Track all toast provider instances in a set.\n  // Only the first one will actually render.\n  // We use a ref to do this, since it will have a stable identity\n  // over the lifetime of the component.\n  let ref = useRef(null);\n\n  useEffect(() => {\n    toastProviders.add(ref);\n    triggerSubscriptions();\n\n    return () => {\n      // Remove this toast provider, and call subscriptions.\n      // This will cause all other instances to re-render,\n      // and the first one to become the new active toast provider.\n      toastProviders.delete(ref);\n      triggerSubscriptions();\n    };\n  }, []);\n\n  // Only render if this is the active toast provider instance, and there are visible toasts.\n  let activeToastContainer = useActiveToastContainer();\n  let state = useToastQueue(getGlobalToastQueue());\n\n  let {placement, isCentered} = useMemo(() => {\n    let placements = (props.placement ?? 'bottom').split(' ');\n    let placement = placements[placements.length - 1];\n    let isCentered = placements.length === 1;\n    return {placement, isCentered};\n  }, [props.placement]);\n\n  if (ref === activeToastContainer && state.visibleToasts.length > 0) {\n    return (\n      <Toaster state={state} {...props}>\n        <ol className={classNames(toastContainerStyles, 'spectrum-ToastContainer-list')}>\n          {state.visibleToasts.map((toast, index) => {\n            let shouldFade = isCentered && index !== 0;\n            return (\n              <li\n                key={toast.key}\n                className={classNames(toastContainerStyles, 'spectrum-ToastContainer-listitem')}\n                style={{\n                  viewTransitionName: toast.key,\n                  viewTransitionClass: classNames(toastContainerStyles, 'toast', placement, {\n                    fadeOnly: shouldFade\n                  })\n                }}>\n                <Toast toast={toast} state={state} />\n              </li>\n            );\n          })}\n        </ol>\n      </Toaster>\n    );\n  }\n\n  return null;\n}\n\nfunction addToast(\n  children: string,\n  variant: SpectrumToastValue['variant'],\n  options: SpectrumToastOptions = {}\n) {\n  // Dispatch a custom event so that toasts can be intercepted and re-targeted, e.g. when inside an iframe.\n  if (typeof CustomEvent !== 'undefined' && typeof window !== 'undefined') {\n    let event = new CustomEvent('react-spectrum-toast', {\n      cancelable: true,\n      bubbles: true,\n      detail: {\n        children,\n        variant,\n        options\n      }\n    });\n\n    let shouldContinue = window.dispatchEvent(event);\n    if (!shouldContinue) {\n      return () => {};\n    }\n  }\n\n  let value = {\n    children,\n    variant,\n    actionLabel: options.actionLabel,\n    onAction: options.onAction,\n    shouldCloseOnAction: options.shouldCloseOnAction,\n    ...filterDOMProps(options)\n  };\n\n  // Minimum time of 5s from https://spectrum.adobe.com/page/toast/#Auto-dismissible\n  // Actionable toasts cannot be auto dismissed. That would fail WCAG SC 2.2.1.\n  // It is debatable whether non-actionable toasts would also fail.\n  let timeout = options.timeout && !options.onAction ? Math.max(options.timeout, 5000) : undefined;\n  let queue = getGlobalToastQueue();\n  let key = queue.add(value, {timeout, onClose: options.onClose});\n  return () => queue.close(key);\n}\n\nconst SpectrumToastQueue = {\n  /** Queues a neutral toast. */\n  neutral(children: string, options: SpectrumToastOptions = {}): CloseFunction {\n    return addToast(children, 'neutral', options);\n  },\n  /** Queues a positive toast. */\n  positive(children: string, options: SpectrumToastOptions = {}): CloseFunction {\n    return addToast(children, 'positive', options);\n  },\n  /** Queues a negative toast. */\n  negative(children: string, options: SpectrumToastOptions = {}): CloseFunction {\n    return addToast(children, 'negative', options);\n  },\n  /** Queues an informational toast. */\n  info(children: string, options: SpectrumToastOptions = {}): CloseFunction {\n    return addToast(children, 'info', options);\n  }\n};\n\nexport {SpectrumToastQueue as ToastQueue};\n"],"names":[],"version":3,"file":"ToastContainer.mjs.map"}