{
  "version": 3,
  "sources": ["../../../src/default-queue/default-queue-context.tsx"],
  "sourcesContent": ["import type { RunQueueOptions } from 'client-run-queue';\nimport { RunQueue } from 'client-run-queue';\nimport type { PropsWithChildren } from 'react';\nimport React, { useContext, useEffect, useMemo, useRef } from 'react';\n\nimport { useStableValue } from '../utility-hooks/use-stable-value.mjs';\n\nconst DefaultQueueContext = React.createContext<RunQueue>(new RunQueue('default'));\n\nexport const useDefaultQueue = () => useContext(DefaultQueueContext);\n\nexport interface DefaultQueueProviderProps extends RunQueueOptions {\n  /** A technical, but human-readable ID prefix, which isn't guaranteed to be unique.  This will be suffixed by `':default'` */\n  idPrefix: string;\n\n  /**\n   * If `true`, `cancelAll` is called on the associated queue whenever this component is unmounted or whenever the idPrefix or other\n   * options change.\n   *\n   * @defaultValue `false`\n   */\n  cancelAllOnUnmount?: boolean;\n}\n\n/** Provides a new default queue, which can be used in children using `useDefaultQueue` */\nexport const DefaultQueueProvider = ({\n  children,\n  idPrefix,\n  cancelAllOnUnmount = false,\n  ...options\n}: PropsWithChildren<DefaultQueueProviderProps>) => {\n  const stableOptions = useStableValue(options);\n  const queue = useMemo(() => new RunQueue(`${idPrefix}:default`, stableOptions), [idPrefix, stableOptions]);\n  const previousQueue = useRef<RunQueue>(queue);\n\n  useEffect(() => {\n    if (previousQueue.current !== queue) {\n      if (cancelAllOnUnmount) {\n        previousQueue.current?.cancelAll();\n      }\n      previousQueue.current = queue;\n    }\n\n    return cancelAllOnUnmount ? queue.cancelAll : undefined;\n  }, [cancelAllOnUnmount, queue]);\n\n  return <DefaultQueueContext.Provider value={queue}>{children}</DefaultQueueContext.Provider>;\n};\n"],
  "mappings": "AACA,SAAS,gBAAgB;AAEzB,OAAO,SAAS,YAAY,WAAW,SAAS,cAAc;AAE9D,SAAS,sBAAsB;AAE/B,MAAM,sBAAsB,MAAM,cAAwB,IAAI,SAAS,SAAS,CAAC;AAE1E,MAAM,kBAAkB,MAAM,WAAW,mBAAmB;AAgB5D,MAAM,uBAAuB,CAAC;AAAA,EACnC;AAAA,EACA;AAAA,EACA,qBAAqB;AAAA,EACrB,GAAG;AACL,MAAoD;AAClD,QAAM,gBAAgB,eAAe,OAAO;AAC5C,QAAM,QAAQ,QAAQ,MAAM,IAAI,SAAS,GAAG,QAAQ,YAAY,aAAa,GAAG,CAAC,UAAU,aAAa,CAAC;AACzG,QAAM,gBAAgB,OAAiB,KAAK;AAE5C,YAAU,MAAM;AACd,QAAI,cAAc,YAAY,OAAO;AACnC,UAAI,oBAAoB;AACtB,sBAAc,SAAS,UAAU;AAAA,MACnC;AACA,oBAAc,UAAU;AAAA,IAC1B;AAEA,WAAO,qBAAqB,MAAM,YAAY;AAAA,EAChD,GAAG,CAAC,oBAAoB,KAAK,CAAC;AAE9B,SAAO,oCAAC,oBAAoB,UAApB,EAA6B,OAAO,SAAQ,QAAS;AAC/D;",
  "names": []
}
