{"ast":null,"code":"\"use strict\";\n\nimport _objectWithoutPropertiesLoose from \"@babel/runtime/helpers/objectWithoutPropertiesLoose\";\nconst _excluded = [\"emit\"];\nimport { CommonActions } from '@react-navigation/routers';\nimport * as React from 'react';\nimport { NavigationBuilderContext } from \"./NavigationBuilderContext.js\";\nexport function useNavigationCache({\n  state,\n  getState,\n  navigation,\n  setOptions,\n  router,\n  emitter\n}) {\n  const {\n    stackRef\n  } = React.useContext(NavigationBuilderContext);\n  const base = React.useMemo(() => {\n    const rest = _objectWithoutPropertiesLoose(navigation, _excluded);\n    const actions = Object.assign({}, router.actionCreators, CommonActions);\n    const dispatch = () => {\n      throw new Error('Actions cannot be dispatched from a placeholder screen.');\n    };\n    const helpers = Object.keys(actions).reduce((acc, name) => {\n      acc[name] = dispatch;\n      return acc;\n    }, {});\n    return Object.assign({}, rest, helpers, {\n      addListener: () => {\n        return () => {};\n      },\n      removeListener: () => {},\n      dispatch,\n      getParent: id => {\n        if (id !== undefined && id === rest.getId()) {\n          return base;\n        }\n        return rest.getParent(id);\n      },\n      setOptions: () => {\n        throw new Error('Options cannot be set from a placeholder screen.');\n      },\n      isFocused: () => false\n    });\n  }, [navigation, router.actionCreators]);\n  const cache = React.useMemo(() => ({\n    current: {}\n  }), [base, getState, navigation, setOptions, emitter]);\n  cache.current = state.routes.reduce((acc, route) => {\n    const previous = cache.current[route.key];\n    if (previous) {\n      acc[route.key] = previous;\n    } else {\n      const dispatch = thunk => {\n        const action = typeof thunk === 'function' ? thunk(getState()) : thunk;\n        if (action != null) {\n          navigation.dispatch(Object.assign({\n            source: route.key\n          }, action));\n        }\n      };\n      const withStack = callback => {\n        let isStackSet = false;\n        try {\n          if (process.env.NODE_ENV !== 'production' && stackRef && !stackRef.current) {\n            stackRef.current = new Error().stack;\n            isStackSet = true;\n          }\n          callback();\n        } finally {\n          if (isStackSet && stackRef) {\n            stackRef.current = undefined;\n          }\n        }\n      };\n      const actions = Object.assign({}, router.actionCreators, CommonActions);\n      const helpers = Object.keys(actions).reduce((acc, name) => {\n        acc[name] = (...args) => withStack(() => dispatch(actions[name](...args)));\n        return acc;\n      }, {});\n      acc[route.key] = Object.assign({}, base, helpers, emitter.create(route.key), {\n        dispatch: thunk => withStack(() => dispatch(thunk)),\n        getParent: id => {\n          if (id !== undefined && id === base.getId()) {\n            return acc[route.key];\n          }\n          return base.getParent(id);\n        },\n        setOptions: options => {\n          setOptions(o => Object.assign({}, o, {\n            [route.key]: Object.assign({}, o[route.key], options)\n          }));\n        },\n        isFocused: () => {\n          const state = base.getState();\n          if (state.routes[state.index].key !== route.key) {\n            return false;\n          }\n          return navigation ? navigation.isFocused() : true;\n        }\n      });\n    }\n    return acc;\n  }, {});\n  return {\n    base,\n    navigations: cache.current\n  };\n}","map":{"version":3,"names":["CommonActions","React","NavigationBuilderContext","useNavigationCache","state","getState","navigation","setOptions","router","emitter","stackRef","useContext","base","useMemo","rest","_objectWithoutPropertiesLoose","_excluded","actions","Object","assign","actionCreators","dispatch","Error","helpers","keys","reduce","acc","name","addListener","removeListener","getParent","id","undefined","getId","isFocused","cache","current","routes","route","previous","key","thunk","action","source","withStack","callback","isStackSet","process","env","NODE_ENV","stack","args","create","options","o","index","navigations"],"sources":["/Users/pmouli/Documents/GitHub.nosync/boots-strapper/mobile/node_modules/@react-navigation/core/src/useNavigationCache.tsx"],"sourcesContent":["import {\n  CommonActions,\n  type NavigationAction,\n  type NavigationState,\n  type ParamListBase,\n  type Router,\n} from '@react-navigation/routers';\nimport * as React from 'react';\n\nimport { NavigationBuilderContext } from './NavigationBuilderContext';\nimport type { NavigationHelpers, NavigationProp } from './types';\nimport type { NavigationEventEmitter } from './useEventEmitter';\n\ntype Options<\n  State extends NavigationState,\n  ScreenOptions extends {},\n  EventMap extends Record<string, any>,\n> = {\n  state: State;\n  getState: () => State;\n  navigation: NavigationHelpers<ParamListBase> &\n    Partial<NavigationProp<ParamListBase, string, any, any, any>>;\n  setOptions: (\n    cb: (\n      options: Record<string, ScreenOptions>\n    ) => Record<string, ScreenOptions>\n  ) => void;\n  router: Router<State, NavigationAction>;\n  emitter: NavigationEventEmitter<EventMap>;\n};\n\ntype NavigationItem<\n  State extends NavigationState,\n  ScreenOptions extends {},\n  EventMap extends Record<string, any>,\n> = NavigationProp<\n  ParamListBase,\n  string,\n  string | undefined,\n  State,\n  ScreenOptions,\n  EventMap\n>;\n\ntype NavigationCache<\n  State extends NavigationState,\n  ScreenOptions extends {},\n  EventMap extends Record<string, any>,\n> = Record<string, NavigationItem<State, ScreenOptions, EventMap>>;\n\n/**\n * Hook to cache navigation objects for each screen in the navigator.\n * It's important to cache them to make sure navigation objects don't change between renders.\n * This lets us apply optimizations like `React.memo` to minimize re-rendering screens.\n */\nexport function useNavigationCache<\n  State extends NavigationState,\n  ScreenOptions extends {},\n  EventMap extends Record<string, any>,\n  ActionHelpers extends Record<string, () => void>,\n>({\n  state,\n  getState,\n  navigation,\n  setOptions,\n  router,\n  emitter,\n}: Options<State, ScreenOptions, EventMap>) {\n  const { stackRef } = React.useContext(NavigationBuilderContext);\n\n  const base = React.useMemo((): NavigationItem<\n    State,\n    ScreenOptions,\n    EventMap\n  > &\n    ActionHelpers => {\n    // eslint-disable-next-line @typescript-eslint/no-unused-vars\n    const { emit, ...rest } = navigation;\n\n    const actions = {\n      ...router.actionCreators,\n      ...CommonActions,\n    };\n\n    const dispatch = () => {\n      throw new Error(\n        'Actions cannot be dispatched from a placeholder screen.'\n      );\n    };\n\n    const helpers = Object.keys(actions).reduce<Record<string, () => void>>(\n      (acc, name) => {\n        acc[name] = dispatch;\n\n        return acc;\n      },\n      {}\n    ) as ActionHelpers;\n\n    return {\n      ...rest,\n      ...helpers,\n      addListener: () => {\n        // Event listeners are not supported for placeholder screens\n\n        return () => {\n          // Empty function\n        };\n      },\n      removeListener: () => {\n        // Event listeners are not supported for placeholder screens\n      },\n      dispatch,\n      getParent: (id?: string) => {\n        if (id !== undefined && id === rest.getId()) {\n          return base;\n        }\n\n        return rest.getParent(id);\n      },\n      setOptions: () => {\n        throw new Error('Options cannot be set from a placeholder screen.');\n      },\n      isFocused: () => false,\n    };\n  }, [navigation, router.actionCreators]);\n\n  // Cache object which holds navigation objects for each screen\n  // We use `React.useMemo` instead of `React.useRef` coz we want to invalidate it when deps change\n  // In reality, these deps will rarely change, if ever\n  const cache = React.useMemo(\n    () => ({ current: {} as NavigationCache<State, ScreenOptions, EventMap> }),\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n    [base, getState, navigation, setOptions, emitter]\n  );\n\n  cache.current = state.routes.reduce<\n    NavigationCache<State, ScreenOptions, EventMap>\n  >((acc, route) => {\n    const previous = cache.current[route.key];\n\n    type Thunk =\n      | NavigationAction\n      | ((state: State) => NavigationAction | null | undefined);\n\n    if (previous) {\n      // If a cached navigation object already exists, reuse it\n      acc[route.key] = previous;\n    } else {\n      const dispatch = (thunk: Thunk) => {\n        const action = typeof thunk === 'function' ? thunk(getState()) : thunk;\n\n        if (action != null) {\n          navigation.dispatch({ source: route.key, ...action });\n        }\n      };\n\n      const withStack = (callback: () => void) => {\n        let isStackSet = false;\n\n        try {\n          if (\n            process.env.NODE_ENV !== 'production' &&\n            stackRef &&\n            !stackRef.current\n          ) {\n            // Capture the stack trace for devtools\n            stackRef.current = new Error().stack;\n            isStackSet = true;\n          }\n\n          callback();\n        } finally {\n          if (isStackSet && stackRef) {\n            stackRef.current = undefined;\n          }\n        }\n      };\n\n      const actions = {\n        ...router.actionCreators,\n        ...CommonActions,\n      };\n\n      const helpers = Object.keys(actions).reduce<Record<string, () => void>>(\n        (acc, name) => {\n          acc[name] = (...args: any) =>\n            withStack(() =>\n              // @ts-expect-error: name is a valid key, but TypeScript is dumb\n              dispatch(actions[name](...args))\n            );\n\n          return acc;\n        },\n        {}\n      );\n\n      acc[route.key] = {\n        ...base,\n        ...helpers,\n        // FIXME: too much work to fix the types for now\n        ...(emitter.create(route.key) as any),\n        dispatch: (thunk: Thunk) => withStack(() => dispatch(thunk)),\n        getParent: (id?: string) => {\n          if (id !== undefined && id === base.getId()) {\n            // If the passed id is the same as the current navigation id,\n            // we return the cached navigation object for the relevant route\n            return acc[route.key];\n          }\n\n          return base.getParent(id);\n        },\n        setOptions: (options: object) => {\n          setOptions((o) => ({\n            ...o,\n            [route.key]: { ...o[route.key], ...options },\n          }));\n        },\n        isFocused: () => {\n          const state = base.getState();\n\n          if (state.routes[state.index].key !== route.key) {\n            return false;\n          }\n\n          // If the current screen is focused, we also need to check if parent navigator is focused\n          // This makes sure that we return the focus state in the whole tree, not just this navigator\n          return navigation ? navigation.isFocused() : true;\n        },\n      };\n    }\n\n    return acc;\n  }, {});\n\n  return {\n    base,\n    navigations: cache.current,\n  };\n}\n"],"mappings":";;;;AAAA,SACEA,aAAa,QAKR,2BAA2B;AAClC,OAAO,KAAKC,KAAK,MAAM,OAAO;AAE9B,SAASC,wBAAwB;AA8CjC,OAAO,SAASC,kBAAkBA,CAKhC;EACAC,KAAK;EACLC,QAAQ;EACRC,UAAU;EACVC,UAAU;EACVC,MAAM;EACNC;AACuC,CAAC,EAAE;EAC1C,MAAM;IAAEC;EAAS,CAAC,GAAGT,KAAK,CAACU,UAAU,CAACT,wBAAwB,CAAC;EAE/D,MAAMU,IAAI,GAAGX,KAAK,CAACY,OAAO,CAAC,MAKR;IAEjB,MAAiBC,IAAA,GAAAC,6BAAA,CAAST,UAAU,EAAAU,SAAA;IAEpC,MAAMC,OAAO,GAAAC,MAAA,CAAAC,MAAA,KACRX,MAAM,CAACY,cAAc,EACrBpB,aAAA,CACJ;IAED,MAAMqB,QAAQ,GAAGA,CAAA,KAAM;MACrB,MAAM,IAAIC,KAAK,CACb,yDACF,CAAC;IACH,CAAC;IAED,MAAMC,OAAO,GAAGL,MAAM,CAACM,IAAI,CAACP,OAAO,CAAC,CAACQ,MAAM,CACzC,CAACC,GAAG,EAAEC,IAAI,KAAK;MACbD,GAAG,CAACC,IAAI,CAAC,GAAGN,QAAQ;MAEpB,OAAOK,GAAG;IACZ,CAAC,EACD,CA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