@react-navigation/native 6.0.10 → 6.0.11

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["useLinking.tsx"],"names":["createMemoryHistory","index","items","pending","interrupt","forEach","it","cb","history","id","window","state","findIndex","item","get","backIndex","path","i","push","slice","length","pushState","replace","replaceState","go","n","Math","max","min","Promise","resolve","reject","done","interrupted","clearTimeout","timer","Error","title","document","ref","setTimeout","splice","onPopState","currentIndex","last","pop","removeEventListener","addEventListener","listen","listener","findMatchingState","a","b","undefined","key","aHistoryLength","routes","bHistoryLength","aRoute","bRoute","aChildState","bChildState","series","handling","queue","callback","unshift","linkingHandlers","useLinking","independent","enabled","config","getStateFromPath","getStateFromPathDefault","getPathFromState","getPathFromStateDefault","getActionFromState","getActionFromStateDefault","React","useEffect","process","env","NODE_ENV","console","error","join","trim","handler","Symbol","indexOf","useState","enabledRef","useRef","configRef","getStateFromPathRef","getPathFromStateRef","getActionFromStateRef","current","server","useContext","ServerContext","getInitialState","useCallback","value","location","pathname","search","thenable","then","onfulfilled","catch","previousIndexRef","previousStateRef","pendingPopStatePathRef","navigation","previousIndex","record","resetRoot","rootState","getRootState","some","r","routeNames","includes","name","warn","action","dispatch","e","message","getPathForRoute","route","stateForPath","focusedRoute","params","onStateChange","previousState","pendingPath","previousFocusedState","focusedState","historyDelta","nextIndex","addListener"],"mappings":";;;;;;;AAAA;;AASA;;AACA;;AACA;;AAEA;;;;;;;;AAcA,MAAMA,mBAAmB,GAAG,MAAM;AAChC,MAAIC,KAAK,GAAG,CAAZ;AACA,MAAIC,KAAsB,GAAG,EAA7B,CAFgC,CAIhC;AACA;;AACA,QAAMC,OAAgE,GAAG,EAAzE;;AAEA,QAAMC,SAAS,GAAG,MAAM;AACtB;AACA;AACA;AACAD,IAAAA,OAAO,CAACE,OAAR,CAAiBC,EAAD,IAAQ;AACtB,YAAMC,EAAE,GAAGD,EAAE,CA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;AACL;AACA;AACAH,QAAAA,OAAO,CAACc,OAAR,CAAgB;AAAEN,UAAAA,IAAF;AAAQL,UAAAA;AAAR,SAAhB;AACD;AACF,KAjFD,CAlDoB,CAqIpB;AACA;AACA;;;AACA,2BAAO4B,GAAG,CAAC0D,OAAX,iDAAO,aAAa6C,WAAb,CAAyB,OAAzB,EAAkChF,MAAM,CAACyE,aAAD,CAAxC,CAAP;AACD,GAzID;AA2IA,SAAO;AACLlC,IAAAA;AADK,GAAP;AAGD","sourcesContent":["import {\n findFocusedRoute,\n getActionFromState as getActionFromStateDefault,\n getPathFromState as getPathFromStateDefault,\n getStateFromPath as getStateFromPathDefault,\n NavigationContainerRef,\n NavigationState,\n ParamListBase,\n} from '@react-navigation/core';\nimport isEqual from 'fast-deep-equal';\nimport { nanoid } from 'nanoid/non-secure';\nimport * as React from 'react';\n\nimport ServerContext from './ServerContext';\nimport type { LinkingOptions } from './types';\n\ntype ResultState = ReturnType<typeof getStateFromPathDefault>;\n\ntype HistoryRecord = {\n // Unique identifier for this record to match it with window.history.state\n id: string;\n // Navigation state object for the history entry\n state: NavigationState;\n // Path of the history entry\n path: string;\n};\n\nconst createMemoryHistory = () => {\n let index = 0;\n let items: HistoryRecord[] = [];\n\n // Pending callbacks for `history.go(n)`\n // We might modify the callback stored if it was interrupted, so we have a ref to identify it\n const pending: { ref: unknown; cb: (interrupted?: boolean) => void }[] = [];\n\n const interrupt = () => {\n // If another history operation was performed we need to interrupt existing ones\n // This makes sure that calls such as `history.replace` after `history.go` don't happen\n // Since otherwise it won't be correct if something else has changed\n pending.forEach((it) => {\n const cb = it.cb;\n it.cb = () => cb(true);\n });\n };\n\n const history = {\n get index(): number {\n // We store an id in the state instead of an index\n // Index could get out of sync with in-memory values if page reloads\n const id = window.history.state?.id;\n\n if (id) {\n const index = items.findIndex((item) => item.id === id);\n\n return index > -1 ? index : 0;\n }\n\n return 0;\n },\n\n get(index: number) {\n return items[index];\n },\n\n backIndex({ path }: { path: string }) {\n // We need to find the index from the element before current to get closest path to go back to\n for (let i = index - 1; i >= 0; i--) {\n const item = items[i];\n\n if (item.path === path) {\n return i;\n }\n }\n\n return -1;\n },\n\n push({ path, state }: { path: string; state: NavigationState }) {\n interrupt();\n\n const id = nanoid();\n\n // When a new entry is pushed, all the existing entries after index will be inaccessible\n // So we remove any existing entries after the current index to clean them up\n items = items.slice(0, index + 1);\n\n items.push({ path, state, id });\n index = items.length - 1;\n\n // We pass empty string for title because it's ignored in all browsers except safari\n // We don't store state object in history.state because:\n // - browsers have limits on how big it can be, and we don't control the size\n // - while not recommended, there could be non-serializable data in state\n window.history.pushState({ id }, '', path);\n },\n\n replace({ path, state }: { path: string; state: NavigationState }) {\n interrupt();\n\n const id = window.history.state?.id ?? nanoid();\n\n if (!items.length || items.findIndex((item) => item.id === id) < 0) {\n // There are two scenarios for creating an array with only one history record:\n // - When loaded id not found in the items array, this function by default will replace\n // the first item. We need to keep only the new updated object, otherwise it will break\n // the page when navigating forward in history.\n // - This is the first time any state modifications are done\n // So we need to push the entry as there's nothing to replace\n items = [{ path, state, id }];\n index = 0;\n } else {\n items[index] = { path, state, id };\n }\n\n window.history.replaceState({ id }, '', path);\n },\n\n // `history.go(n)` is asynchronous, there are couple of things to keep in mind:\n // - it won't do anything if we can't go `n` steps, the `popstate` event won't fire.\n // - each `history.go(n)` call will trigger a separate `popstate` event with correct location.\n // - the `popstate` event fires before the next frame after calling `history.go(n)`.\n // This method differs from `history.go(n)` in the sense that it'll go back as many steps it can.\n go(n: number) {\n interrupt();\n\n if (n === 0) {\n return;\n }\n\n // We shouldn't go back more than the 0 index (otherwise we'll exit the page)\n // Or forward more than the available index (or the app will crash)\n index =\n n < 0 ? Math.max(index - n, 0) : Math.min(index + n, items.length - 1);\n\n // When we call `history.go`, `popstate` will fire when there's history to go back to\n // So we need to somehow handle following cases:\n // - There's history to go back, `history.go` is called, and `popstate` fires\n // - `history.go` is called multiple times, we need to resolve on respective `popstate`\n // - No history to go back, but `history.go` was called, browser has no API to detect it\n return new Promise<void>((resolve, reject) => {\n const done = (interrupted?: boolean) => {\n clearTimeout(timer);\n\n if (interrupted) {\n reject(new Error('History was changed during navigation.'));\n return;\n }\n\n // There seems to be a bug in Chrome regarding updating the title\n // If we set a title just before calling `history.go`, the title gets lost\n // However the value of `document.title` is still what we set it to\n // It's just not displayed in the tab bar\n // To update the tab bar, we need to reset the title to something else first (e.g. '')\n // And set the title to what it was before so it gets applied\n // It won't work without setting it to empty string coz otherwise title isn't changing\n // Which means that the browser won't do anything after setting the title\n const { title } = window.document;\n\n window.document.title = '';\n window.document.title = title;\n\n resolve();\n };\n\n pending.push({ ref: done, cb: done });\n\n // If navigation didn't happen within 100ms, assume that it won't happen\n // This may not be accurate, but hopefully it won't take so much time\n // In Chrome, navigation seems to happen instantly in next microtask\n // But on Firefox, it seems to take much longer, around 50ms from our testing\n // We're using a hacky timeout since there doesn't seem to be way to know for sure\n const timer = setTimeout(() => {\n const index = pending.findIndex((it) => it.ref === done);\n\n if (index > -1) {\n pending[index].cb();\n pending.splice(index, 1);\n }\n }, 100);\n\n const onPopState = () => {\n const id = window.history.state?.id;\n const currentIndex = items.findIndex((item) => item.id === id);\n\n // Fix createMemoryHistory.index variable's value\n // as it may go out of sync when navigating in the browser.\n index = Math.max(currentIndex, 0);\n\n const last = pending.pop();\n\n window.removeEventListener('popstate', onPopState);\n last?.cb();\n };\n\n window.addEventListener('popstate', onPopState);\n window.history.go(n);\n });\n },\n\n // The `popstate` event is triggered when history changes, except `pushState` and `replaceState`\n // If we call `history.go(n)` ourselves, we don't want it to trigger the listener\n // Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener\n listen(listener: () => void) {\n const onPopState = () => {\n if (pending.length) {\n // This was triggered by `history.go(n)`, we shouldn't call the listener\n return;\n }\n\n listener();\n };\n\n window.addEventListener('popstate', onPopState);\n\n return () => window.removeEventListener('popstate', onPopState);\n },\n };\n\n return history;\n};\n\n/**\n * Find the matching navigation state that changed between 2 navigation states\n * e.g.: a -> b -> c -> d and a -> b -> c -> e -> f, if history in b changed, b is the matching state\n */\nconst findMatchingState = <T extends NavigationState>(\n a: T | undefined,\n b: T | undefined\n): [T | undefined, T | undefined] => {\n if (a === undefined || b === undefined || a.key !== b.key) {\n return [undefined, undefined];\n }\n\n // Tab and drawer will have `history` property, but stack will have history in `routes`\n const aHistoryLength = a.history ? a.history.length : a.routes.length;\n const bHistoryLength = b.history ? b.history.length : b.routes.length;\n\n const aRoute = a.routes[a.index];\n const bRoute = b.routes[b.index];\n\n const aChildState = aRoute.state as T | undefined;\n const bChildState = bRoute.state as T | undefined;\n\n // Stop here if this is the state object that changed:\n // - history length is different\n // - focused routes are different\n // - one of them doesn't have child state\n // - child state keys are different\n if (\n aHistoryLength !== bHistoryLength ||\n aRoute.key !== bRoute.key ||\n aChildState === undefined ||\n bChildState === undefined ||\n aChildState.key !== bChildState.key\n ) {\n return [a, b];\n }\n\n return findMatchingState(aChildState, bChildState);\n};\n\n/**\n * Run async function in series as it's called.\n */\nconst series = (cb: () => Promise<void>) => {\n // Whether we're currently handling a callback\n let handling = false;\n let queue: (() => Promise<void>)[] = [];\n\n const callback = async () => {\n try {\n if (handling) {\n // If we're currently handling a previous event, wait before handling this one\n // Add the callback to the beginning of the queue\n queue.unshift(callback);\n return;\n }\n\n handling = true;\n\n await cb();\n } finally {\n handling = false;\n\n if (queue.length) {\n // If we have queued items, handle the last one\n const last = queue.pop();\n\n last?.();\n }\n }\n };\n\n return callback;\n};\n\nlet linkingHandlers: Symbol[] = [];\n\ntype Options = LinkingOptions<ParamListBase> & {\n independent?: boolean;\n};\n\nexport default function useLinking(\n ref: React.RefObject<NavigationContainerRef<ParamListBase>>,\n {\n independent,\n enabled = true,\n config,\n getStateFromPath = getStateFromPathDefault,\n getPathFromState = getPathFromStateDefault,\n getActionFromState = getActionFromStateDefault,\n }: Options\n) {\n React.useEffect(() => {\n if (process.env.NODE_ENV === 'production') {\n return undefined;\n }\n\n if (independent) {\n return undefined;\n }\n\n if (enabled !== false && linkingHandlers.length) {\n console.error(\n [\n 'Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:',\n \"- You don't have multiple NavigationContainers in the app each with 'linking' enabled\",\n '- Only a single instance of the root component is rendered',\n ]\n .join('\\n')\n .trim()\n );\n }\n\n const handler = Symbol();\n\n if (enabled !== false) {\n linkingHandlers.push(handler);\n }\n\n return () => {\n const index = linkingHandlers.indexOf(handler);\n\n if (index > -1) {\n linkingHandlers.splice(index, 1);\n }\n };\n }, [enabled, independent]);\n\n const [history] = React.useState(createMemoryHistory);\n\n // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners\n // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`\n // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect\n const enabledRef = React.useRef(enabled);\n const configRef = React.useRef(config);\n const getStateFromPathRef = React.useRef(getStateFromPath);\n const getPathFromStateRef = React.useRef(getPathFromState);\n const getActionFromStateRef = React.useRef(getActionFromState);\n\n React.useEffect(() => {\n enabledRef.current = enabled;\n configRef.current = config;\n getStateFromPathRef.current = getStateFromPath;\n getPathFromStateRef.current = getPathFromState;\n getActionFromStateRef.current = getActionFromState;\n });\n\n const server = React.useContext(ServerContext);\n\n const getInitialState = React.useCallback(() => {\n let value: ResultState | undefined;\n\n if (enabledRef.current) {\n const location =\n server?.location ??\n (typeof window !== 'undefined' ? window.location : undefined);\n\n const path = location ? location.pathname + location.search : undefined;\n\n if (path) {\n value = getStateFromPathRef.current(path, configRef.current);\n }\n }\n\n const thenable = {\n then(onfulfilled?: (state: ResultState | undefined) => void) {\n return Promise.resolve(onfulfilled ? onfulfilled(value) : value);\n },\n catch() {\n return thenable;\n },\n };\n\n return thenable as PromiseLike<ResultState | undefined>;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const previousIndexRef = React.useRef<number | undefined>(undefined);\n const previousStateRef = React.useRef<NavigationState | undefined>(undefined);\n const pendingPopStatePathRef = React.useRef<string | undefined>(undefined);\n\n React.useEffect(() => {\n previousIndexRef.current = history.index;\n\n return history.listen(() => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const path = location.pathname + location.search;\n const index = history.index;\n\n const previousIndex = previousIndexRef.current ?? 0;\n\n previousIndexRef.current = index;\n pendingPopStatePathRef.current = path;\n\n // When browser back/forward is clicked, we first need to check if state object for this index exists\n // If it does we'll reset to that state object\n // Otherwise, we'll handle it like a regular deep link\n const record = history.get(index);\n\n if (record?.path === path && record?.state) {\n navigation.resetRoot(record.state);\n return;\n }\n\n const state = getStateFromPathRef.current(path, configRef.current);\n\n // We should only dispatch an action when going forward\n // Otherwise the action will likely add items to history, which would mess things up\n if (state) {\n // Make sure that the routes in the state exist in the root navigator\n // Otherwise there's an error in the linking configuration\n const rootState = navigation.getRootState();\n\n if (state.routes.some((r) => !rootState?.routeNames.includes(r.name))) {\n console.warn(\n \"The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration.\"\n );\n return;\n }\n\n if (index > previousIndex) {\n const action = getActionFromStateRef.current(\n state,\n configRef.current\n );\n\n if (action !== undefined) {\n try {\n navigation.dispatch(action);\n } catch (e) {\n // Ignore any errors from deep linking.\n // This could happen in case of malformed links, navigation object not being initialized etc.\n console.warn(\n `An error occurred when trying to handle the link '${path}': ${\n typeof e === 'object' && e != null && 'message' in e\n ? // @ts-expect-error: we're already checking for this\n e.message\n : e\n }`\n );\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n // if current path didn't return any state, we should revert to initial state\n navigation.resetRoot(state);\n }\n });\n }, [enabled, history, ref]);\n\n React.useEffect(() => {\n if (!enabled) {\n return;\n }\n\n const getPathForRoute = (\n route: ReturnType<typeof findFocusedRoute>,\n state: NavigationState\n ): string => {\n // If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match\n // This makes sure that we preserve the original URL for wildcard routes\n if (route?.path) {\n const stateForPath = getStateFromPathRef.current(\n route.path,\n configRef.current\n );\n\n if (stateForPath) {\n const focusedRoute = findFocusedRoute(stateForPath);\n\n if (\n focusedRoute &&\n focusedRoute.name === route.name &&\n isEqual(focusedRoute.params, route.params)\n ) {\n return route.path;\n }\n }\n }\n\n return getPathFromStateRef.current(state, configRef.current);\n };\n\n if (ref.current) {\n // We need to record the current metadata on the first render if they aren't set\n // This will allow the initial state to be in the history entry\n const state = ref.current.getRootState();\n\n if (state) {\n const route = findFocusedRoute(state);\n const path = getPathForRoute(route, state);\n\n if (previousStateRef.current === undefined) {\n previousStateRef.current = state;\n }\n\n history.replace({ path, state });\n }\n }\n\n const onStateChange = async () => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const previousState = previousStateRef.current;\n const state = navigation.getRootState();\n\n // root state may not available, for example when root navigators switch inside the container\n if (!state) {\n return;\n }\n\n const pendingPath = pendingPopStatePathRef.current;\n const route = findFocusedRoute(state);\n const path = getPathForRoute(route, state);\n\n previousStateRef.current = state;\n pendingPopStatePathRef.current = undefined;\n\n // To detect the kind of state change, we need to:\n // - Find the common focused navigation state in previous and current state\n // - If only the route keys changed, compare history/routes.length to check if we go back/forward/replace\n // - If no common focused navigation state found, it's a replace\n const [previousFocusedState, focusedState] = findMatchingState(\n previousState,\n state\n );\n\n if (\n previousFocusedState &&\n focusedState &&\n // We should only handle push/pop if path changed from what was in last `popstate`\n // Otherwise it's likely a change triggered by `popstate`\n path !== pendingPath\n ) {\n const historyDelta =\n (focusedState.history\n ? focusedState.history.length\n : focusedState.routes.length) -\n (previousFocusedState.history\n ? previousFocusedState.history.length\n : previousFocusedState.routes.length);\n\n if (historyDelta > 0) {\n // If history length is increased, we should pushState\n // Note that path might not actually change here, for example, drawer open should pushState\n history.push({ path, state });\n } else if (historyDelta < 0) {\n // If history length is decreased, i.e. entries were removed, we want to go back\n\n const nextIndex = history.backIndex({ path });\n const currentIndex = history.index;\n\n try {\n if (nextIndex !== -1 && nextIndex < currentIndex) {\n // An existing entry for this path exists and it's less than current index, go back to that\n await history.go(nextIndex - currentIndex);\n } else {\n // We couldn't find an existing entry to go back to, so we'll go back by the delta\n // This won't be correct if multiple routes were pushed in one go before\n // Usually this shouldn't happen and this is a fallback for that\n await history.go(historyDelta);\n }\n\n // Store the updated state as well as fix the path if incorrect\n history.replace({ path, state });\n } catch (e) {\n // The navigation was interrupted\n }\n } else {\n // If history length is unchanged, we want to replaceState\n history.replace({ path, state });\n }\n } else {\n // If no common navigation state was found, assume it's a replace\n // This would happen if the user did a reset/conditionally changed navigators\n history.replace({ path, state });\n }\n };\n\n // We debounce onStateChange coz we don't want multiple state changes to be handled at one time\n // This could happen since `history.go(n)` is asynchronous\n // If `pushState` or `replaceState` were called before `history.go(n)` completes, it'll mess stuff up\n return ref.current?.addListener('state', series(onStateChange));\n });\n\n return {\n getInitialState,\n };\n}\n"]}
1
+ {"version":3,"sources":["useLinking.tsx"],"names":["findMatchingState","a","b","undefined","key","aHistoryLength","history","length","routes","bHistoryLength","aRoute","index","bRoute","aChildState","state","bChildState","series","cb","handling","queue","callback","unshift","last","pop","linkingHandlers","useLinking","ref","independent","enabled","config","getStateFromPath","getStateFromPathDefault","getPathFromState","getPathFromStateDefault","getActionFromState","getActionFromStateDefault","React","useEffect","process","env","NODE_ENV","console","error","join","trim","handler","Symbol","push","indexOf","splice","useState","createMemoryHistory","enabledRef","useRef","configRef","getStateFromPathRef","getPathFromStateRef","getActionFromStateRef","current","server","useContext","ServerContext","getInitialState","useCallback","value","location","window","path","pathname","search","thenable","then","onfulfilled","Promise","resolve","catch","previousIndexRef","previousStateRef","pendingPopStatePathRef","listen","navigation","previousIndex","record","get","resetRoot","rootState","getRootState","some","r","routeNames","includes","name","warn","action","dispatch","e","message","getPathForRoute","route","stateForPath","focusedRoute","params","replace","onStateChange","previousState","pendingPath","previousFocusedState","focusedState","historyDelta","nextIndex","backIndex","currentI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ACL;AACAzF,UAAAA,OAAO,CAACgG,OAAR,CAAgB;AAAEnC,YAAAA,IAAF;AAAQrD,YAAAA;AAAR,WAAhB;AACD;AACF,OA7CD,MA6CO;AACL;AACA;AACAR,QAAAA,OAAO,CAACgG,OAAR,CAAgB;AAAEnC,UAAAA,IAAF;AAAQrD,UAAAA;AAAR,SAAhB;AACD;AACF,KAjFD,CAlDoB,CAqIpB;AACA;AACA;;;AACA,2BAAOY,GAAG,CAACgC,OAAX,iDAAO,aAAauD,WAAb,CAAyB,OAAzB,EAAkCjG,MAAM,CAACuF,aAAD,CAAxC,CAAP;AACD,GAzID;AA2IA,SAAO;AACLzC,IAAAA;AADK,GAAP;AAGD","sourcesContent":["import {\n findFocusedRoute,\n getActionFromState as getActionFromStateDefault,\n getPathFromState as getPathFromStateDefault,\n getStateFromPath as getStateFromPathDefault,\n NavigationContainerRef,\n NavigationState,\n ParamListBase,\n} from '@react-navigation/core';\nimport isEqual from 'fast-deep-equal';\nimport * as React from 'react';\n\nimport createMemoryHistory from './createMemoryHistory';\nimport ServerContext from './ServerContext';\nimport type { LinkingOptions } from './types';\n\ntype ResultState = ReturnType<typeof getStateFromPathDefault>;\n\n/**\n * Find the matching navigation state that changed between 2 navigation states\n * e.g.: a -> b -> c -> d and a -> b -> c -> e -> f, if history in b changed, b is the matching state\n */\nconst findMatchingState = <T extends NavigationState>(\n a: T | undefined,\n b: T | undefined\n): [T | undefined, T | undefined] => {\n if (a === undefined || b === undefined || a.key !== b.key) {\n return [undefined, undefined];\n }\n\n // Tab and drawer will have `history` property, but stack will have history in `routes`\n const aHistoryLength = a.history ? a.history.length : a.routes.length;\n const bHistoryLength = b.history ? b.history.length : b.routes.length;\n\n const aRoute = a.routes[a.index];\n const bRoute = b.routes[b.index];\n\n const aChildState = aRoute.state as T | undefined;\n const bChildState = bRoute.state as T | undefined;\n\n // Stop here if this is the state object that changed:\n // - history length is different\n // - focused routes are different\n // - one of them doesn't have child state\n // - child state keys are different\n if (\n aHistoryLength !== bHistoryLength ||\n aRoute.key !== bRoute.key ||\n aChildState === undefined ||\n bChildState === undefined ||\n aChildState.key !== bChildState.key\n ) {\n return [a, b];\n }\n\n return findMatchingState(aChildState, bChildState);\n};\n\n/**\n * Run async function in series as it's called.\n */\nconst series = (cb: () => Promise<void>) => {\n // Whether we're currently handling a callback\n let handling = false;\n let queue: (() => Promise<void>)[] = [];\n\n const callback = async () => {\n try {\n if (handling) {\n // If we're currently handling a previous event, wait before handling this one\n // Add the callback to the beginning of the queue\n queue.unshift(callback);\n return;\n }\n\n handling = true;\n\n await cb();\n } finally {\n handling = false;\n\n if (queue.length) {\n // If we have queued items, handle the last one\n const last = queue.pop();\n\n last?.();\n }\n }\n };\n\n return callback;\n};\n\nlet linkingHandlers: Symbol[] = [];\n\ntype Options = LinkingOptions<ParamListBase> & {\n independent?: boolean;\n};\n\nexport default function useLinking(\n ref: React.RefObject<NavigationContainerRef<ParamListBase>>,\n {\n independent,\n enabled = true,\n config,\n getStateFromPath = getStateFromPathDefault,\n getPathFromState = getPathFromStateDefault,\n getActionFromState = getActionFromStateDefault,\n }: Options\n) {\n React.useEffect(() => {\n if (process.env.NODE_ENV === 'production') {\n return undefined;\n }\n\n if (independent) {\n return undefined;\n }\n\n if (enabled !== false && linkingHandlers.length) {\n console.error(\n [\n 'Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:',\n \"- You don't have multiple NavigationContainers in the app each with 'linking' enabled\",\n '- Only a single instance of the root component is rendered',\n ]\n .join('\\n')\n .trim()\n );\n }\n\n const handler = Symbol();\n\n if (enabled !== false) {\n linkingHandlers.push(handler);\n }\n\n return () => {\n const index = linkingHandlers.indexOf(handler);\n\n if (index > -1) {\n linkingHandlers.splice(index, 1);\n }\n };\n }, [enabled, independent]);\n\n const [history] = React.useState(createMemoryHistory);\n\n // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners\n // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`\n // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect\n const enabledRef = React.useRef(enabled);\n const configRef = React.useRef(config);\n const getStateFromPathRef = React.useRef(getStateFromPath);\n const getPathFromStateRef = React.useRef(getPathFromState);\n const getActionFromStateRef = React.useRef(getActionFromState);\n\n React.useEffect(() => {\n enabledRef.current = enabled;\n configRef.current = config;\n getStateFromPathRef.current = getStateFromPath;\n getPathFromStateRef.current = getPathFromState;\n getActionFromStateRef.current = getActionFromState;\n });\n\n const server = React.useContext(ServerContext);\n\n const getInitialState = React.useCallback(() => {\n let value: ResultState | undefined;\n\n if (enabledRef.current) {\n const location =\n server?.location ??\n (typeof window !== 'undefined' ? window.location : undefined);\n\n const path = location ? location.pathname + location.search : undefined;\n\n if (path) {\n value = getStateFromPathRef.current(path, configRef.current);\n }\n }\n\n const thenable = {\n then(onfulfilled?: (state: ResultState | undefined) => void) {\n return Promise.resolve(onfulfilled ? onfulfilled(value) : value);\n },\n catch() {\n return thenable;\n },\n };\n\n return thenable as PromiseLike<ResultState | undefined>;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const previousIndexRef = React.useRef<number | undefined>(undefined);\n const previousStateRef = React.useRef<NavigationState | undefined>(undefined);\n const pendingPopStatePathRef = React.useRef<string | undefined>(undefined);\n\n React.useEffect(() => {\n previousIndexRef.current = history.index;\n\n return history.listen(() => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const path = location.pathname + location.search;\n const index = history.index;\n\n const previousIndex = previousIndexRef.current ?? 0;\n\n previousIndexRef.current = index;\n pendingPopStatePathRef.current = path;\n\n // When browser back/forward is clicked, we first need to check if state object for this index exists\n // If it does we'll reset to that state object\n // Otherwise, we'll handle it like a regular deep link\n const record = history.get(index);\n\n if (record?.path === path && record?.state) {\n navigation.resetRoot(record.state);\n return;\n }\n\n const state = getStateFromPathRef.current(path, configRef.current);\n\n // We should only dispatch an action when going forward\n // Otherwise the action will likely add items to history, which would mess things up\n if (state) {\n // Make sure that the routes in the state exist in the root navigator\n // Otherwise there's an error in the linking configuration\n const rootState = navigation.getRootState();\n\n if (state.routes.some((r) => !rootState?.routeNames.includes(r.name))) {\n console.warn(\n \"The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration.\"\n );\n return;\n }\n\n if (index > previousIndex) {\n const action = getActionFromStateRef.current(\n state,\n configRef.current\n );\n\n if (action !== undefined) {\n try {\n navigation.dispatch(action);\n } catch (e) {\n // Ignore any errors from deep linking.\n // This could happen in case of malformed links, navigation object not being initialized etc.\n console.warn(\n `An error occurred when trying to handle the link '${path}': ${\n typeof e === 'object' && e != null && 'message' in e\n ? // @ts-expect-error: we're already checking for this\n e.message\n : e\n }`\n );\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n // if current path didn't return any state, we should revert to initial state\n navigation.resetRoot(state);\n }\n });\n }, [enabled, history, ref]);\n\n React.useEffect(() => {\n if (!enabled) {\n return;\n }\n\n const getPathForRoute = (\n route: ReturnType<typeof findFocusedRoute>,\n state: NavigationState\n ): string => {\n // If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match\n // This makes sure that we preserve the original URL for wildcard routes\n if (route?.path) {\n const stateForPath = getStateFromPathRef.current(\n route.path,\n configRef.current\n );\n\n if (stateForPath) {\n const focusedRoute = findFocusedRoute(stateForPath);\n\n if (\n focusedRoute &&\n focusedRoute.name === route.name &&\n isEqual(focusedRoute.params, route.params)\n ) {\n return route.path;\n }\n }\n }\n\n return getPathFromStateRef.current(state, configRef.current);\n };\n\n if (ref.current) {\n // We need to record the current metadata on the first render if they aren't set\n // This will allow the initial state to be in the history entry\n const state = ref.current.getRootState();\n\n if (state) {\n const route = findFocusedRoute(state);\n const path = getPathForRoute(route, state);\n\n if (previousStateRef.current === undefined) {\n previousStateRef.current = state;\n }\n\n history.replace({ path, state });\n }\n }\n\n const onStateChange = async () => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const previousState = previousStateRef.current;\n const state = navigation.getRootState();\n\n // root state may not available, for example when root navigators switch inside the container\n if (!state) {\n return;\n }\n\n const pendingPath = pendingPopStatePathRef.current;\n const route = findFocusedRoute(state);\n const path = getPathForRoute(route, state);\n\n previousStateRef.current = state;\n pendingPopStatePathRef.current = undefined;\n\n // To detect the kind of state change, we need to:\n // - Find the common focused navigation state in previous and current state\n // - If only the route keys changed, compare history/routes.length to check if we go back/forward/replace\n // - If no common focused navigation state found, it's a replace\n const [previousFocusedState, focusedState] = findMatchingState(\n previousState,\n state\n );\n\n if (\n previousFocusedState &&\n focusedState &&\n // We should only handle push/pop if path changed from what was in last `popstate`\n // Otherwise it's likely a change triggered by `popstate`\n path !== pendingPath\n ) {\n const historyDelta =\n (focusedState.history\n ? focusedState.history.length\n : focusedState.routes.length) -\n (previousFocusedState.history\n ? previousFocusedState.history.length\n : previousFocusedState.routes.length);\n\n if (historyDelta > 0) {\n // If history length is increased, we should pushState\n // Note that path might not actually change here, for example, drawer open should pushState\n history.push({ path, state });\n } else if (historyDelta < 0) {\n // If history length is decreased, i.e. entries were removed, we want to go back\n\n const nextIndex = history.backIndex({ path });\n const currentIndex = history.index;\n\n try {\n if (nextIndex !== -1 && nextIndex < currentIndex) {\n // An existing entry for this path exists and it's less than current index, go back to that\n await history.go(nextIndex - currentIndex);\n } else {\n // We couldn't find an existing entry to go back to, so we'll go back by the delta\n // This won't be correct if multiple routes were pushed in one go before\n // Usually this shouldn't happen and this is a fallback for that\n await history.go(historyDelta);\n }\n\n // Store the updated state as well as fix the path if incorrect\n history.replace({ path, state });\n } catch (e) {\n // The navigation was interrupted\n }\n } else {\n // If history length is unchanged, we want to replaceState\n history.replace({ path, state });\n }\n } else {\n // If no common navigation state was found, assume it's a replace\n // This would happen if the user did a reset/conditionally changed navigators\n history.replace({ path, state });\n }\n };\n\n // We debounce onStateChange coz we don't want multiple state changes to be handled at one time\n // This could happen since `history.go(n)` is asynchronous\n // If `pushState` or `replaceState` were called before `history.go(n)` completes, it'll mess stuff up\n return ref.current?.addListener('state', series(onStateChange));\n });\n\n return {\n getInitialState,\n };\n}\n"]}
@@ -0,0 +1,232 @@
1
+ import { nanoid } from 'nanoid/non-secure';
2
+ export default function createMemoryHistory() {
3
+ let index = 0;
4
+ let items = []; // Pending callbacks for `history.go(n)`
5
+ // We might modify the callback stored if it was interrupted, so we have a ref to identify it
6
+
7
+ const pending = [];
8
+
9
+ const interrupt = () => {
10
+ // If another history operation was performed we need to interrupt existing ones
11
+ // This makes sure that calls such as `history.replace` after `history.go` don't happen
12
+ // Since otherwise it won't be correct if something else has changed
13
+ pending.forEach(it => {
14
+ const cb = it.cb;
15
+
16
+ it.cb = () => cb(true);
17
+ });
18
+ };
19
+
20
+ const history = {
21
+ get index() {
22
+ var _window$history$state;
23
+
24
+ // We store an id in the state instead of an index
25
+ // Index could get out of sync with in-memory values if page reloads
26
+ const id = (_window$history$state = window.history.state) === null || _window$history$state === void 0 ? void 0 : _window$history$state.id;
27
+
28
+ if (id) {
29
+ const index = items.findIndex(item => item.id === id);
30
+ return index > -1 ? index : 0;
31
+ }
32
+
33
+ return 0;
34
+ },
35
+
36
+ get(index) {
37
+ return items[index];
38
+ },
39
+
40
+ backIndex(_ref) {
41
+ let {
42
+ path
43
+ } = _ref;
44
+
45
+ // We need to find the index from the element before current to get closest path to go back to
46
+ for (let i = index - 1; i >= 0; i--) {
47
+ const item = items[i];
48
+
49
+ if (item.path === path) {
50
+ return i;
51
+ }
52
+ }
53
+
54
+ return -1;
55
+ },
56
+
57
+ push(_ref2) {
58
+ let {
59
+ path,
60
+ state
61
+ } = _ref2;
62
+ interrupt();
63
+ const id = nanoid(); // When a new entry is pushed, all the existing entries after index will be inaccessible
64
+ // So we remove any existing entries after the current index to clean them up
65
+
66
+ items = items.slice(0, index + 1);
67
+ items.push({
68
+ path,
69
+ state,
70
+ id
71
+ });
72
+ index = items.length - 1; // We pass empty string for title because it's ignored in all browsers except safari
73
+ // We don't store state object in history.state because:
74
+ // - browsers have limits on how big it can be, and we don't control the size
75
+ // - while not recommended, there could be non-serializable data in state
76
+
77
+ window.history.pushState({
78
+ id
79
+ }, '', path);
80
+ },
81
+
82
+ replace(_ref3) {
83
+ var _window$history$state2, _window$history$state3;
84
+
85
+ let {
86
+ path,
87
+ state
88
+ } = _ref3;
89
+ interrupt();
90
+ const id = (_window$history$state2 = (_window$history$state3 = window.history.state) === null || _window$history$state3 === void 0 ? void 0 : _window$history$state3.id) !== null && _window$history$state2 !== void 0 ? _window$history$state2 : nanoid();
91
+
92
+ if (!items.length || items.findIndex(item => item.id === id) < 0) {
93
+ // There are two scenarios for creating an array with only one history record:
94
+ // - When loaded id not found in the items array, this function by default will replace
95
+ // the first item. We need to keep only the new updated object, otherwise it will break
96
+ // the page when navigating forward in history.
97
+ // - This is the first time any state modifications are done
98
+ // So we need to push the entry as there's nothing to replace
99
+ items = [{
100
+ path,
101
+ state,
102
+ id
103
+ }];
104
+ index = 0;
105
+ } else {
106
+ items[index] = {
107
+ path,
108
+ state,
109
+ id
110
+ };
111
+ }
112
+
113
+ window.history.replaceState({
114
+ id
115
+ }, '', path);
116
+ },
117
+
118
+ // `history.go(n)` is asynchronous, there are couple of things to keep in mind:
119
+ // - it won't do anything if we can't go `n` steps, the `popstate` event won't fire.
120
+ // - each `history.go(n)` call will trigger a separate `popstate` event with correct location.
121
+ // - the `popstate` event fires before the next frame after calling `history.go(n)`.
122
+ // This method differs from `history.go(n)` in the sense that it'll go back as many steps it can.
123
+ go(n) {
124
+ interrupt(); // To guard against unexpected navigation out of the app we will assume that browser history is only as deep as the length of our memory
125
+ // history. If we don't have an item to navigate to then update our index and navigate as far as we can without taking the user out of the app.
126
+
127
+ const nextIndex = index + n;
128
+ const lastItemIndex = items.length - 1;
129
+
130
+ if (n < 0 && !items[nextIndex]) {
131
+ // Attempted to navigate beyond the first index. Negating the current index will align the browser history with the first item.
132
+ n = -index;
133
+ index = 0;
134
+ } else if (n > 0 && nextIndex > lastItemIndex) {
135
+ // Attempted to navigate past the last index. Calculate how many indices away from the last index and go there.
136
+ n = lastItemIndex - index;
137
+ index = lastItemIndex;
138
+ } else {
139
+ index = nextIndex;
140
+ }
141
+
142
+ if (n === 0) {
143
+ return;
144
+ } // When we call `history.go`, `popstate` will fire when there's history to go back to
145
+ // So we need to somehow handle following cases:
146
+ // - There's history to go back, `history.go` is called, and `popstate` fires
147
+ // - `history.go` is called multiple times, we need to resolve on respective `popstate`
148
+ // - No history to go back, but `history.go` was called, browser has no API to detect it
149
+
150
+
151
+ return new Promise((resolve, reject) => {
152
+ const done = interrupted => {
153
+ clearTimeout(timer);
154
+
155
+ if (interrupted) {
156
+ reject(new Error('History was changed during navigation.'));
157
+ return;
158
+ } // There seems to be a bug in Chrome regarding updating the title
159
+ // If we set a title just before calling `history.go`, the title gets lost
160
+ // However the value of `document.title` is still what we set it to
161
+ // It's just not displayed in the tab bar
162
+ // To update the tab bar, we need to reset the title to something else first (e.g. '')
163
+ // And set the title to what it was before so it gets applied
164
+ // It won't work without setting it to empty string coz otherwise title isn't changing
165
+ // Which means that the browser won't do anything after setting the title
166
+
167
+
168
+ const {
169
+ title
170
+ } = window.document;
171
+ window.document.title = '';
172
+ window.document.title = title;
173
+ resolve();
174
+ };
175
+
176
+ pending.push({
177
+ ref: done,
178
+ cb: done
179
+ }); // If navigation didn't happen within 100ms, assume that it won't happen
180
+ // This may not be accurate, but hopefully it won't take so much time
181
+ // In Chrome, navigation seems to happen instantly in next microtask
182
+ // But on Firefox, it seems to take much longer, around 50ms from our testing
183
+ // We're using a hacky timeout since there doesn't seem to be way to know for sure
184
+
185
+ const timer = setTimeout(() => {
186
+ const index = pending.findIndex(it => it.ref === done);
187
+
188
+ if (index > -1) {
189
+ pending[index].cb();
190
+ pending.splice(index, 1);
191
+ }
192
+ }, 100);
193
+
194
+ const onPopState = () => {
195
+ var _window$history$state4;
196
+
197
+ const id = (_window$history$state4 = window.history.state) === null || _window$history$state4 === void 0 ? void 0 : _window$history$state4.id;
198
+ const currentIndex = items.findIndex(item => item.id === id); // Fix createMemoryHistory.index variable's value
199
+ // as it may go out of sync when navigating in the browser.
200
+
201
+ index = Math.max(currentIndex, 0);
202
+ const last = pending.pop();
203
+ window.removeEventListener('popstate', onPopState);
204
+ last === null || last === void 0 ? void 0 : last.cb();
205
+ };
206
+
207
+ window.addEventListener('popstate', onPopState);
208
+ window.history.go(n);
209
+ });
210
+ },
211
+
212
+ // The `popstate` event is triggered when history changes, except `pushState` and `replaceState`
213
+ // If we call `history.go(n)` ourselves, we don't want it to trigger the listener
214
+ // Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener
215
+ listen(listener) {
216
+ const onPopState = () => {
217
+ if (pending.length) {
218
+ // This was triggered by `history.go(n)`, we shouldn't call the listener
219
+ return;
220
+ }
221
+
222
+ listener();
223
+ };
224
+
225
+ window.addEventListener('popstate', onPopState);
226
+ return () => window.removeEventListener('popstate', onPopState);
227
+ }
228
+
229
+ };
230
+ return history;
231
+ }
232
+ //# sourceMappingURL=createMemoryHistory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["createMemoryHistory.tsx"],"names":["nanoid","createMemoryHistory","index","items","pending","interrupt","forEach","it","cb","history","id","window","state","findIndex","item","get","backIndex","path","i","push","slice","length","pushState","replace","replaceState","go","n","nextIndex","lastItemIndex","Promise","resolve","reject","done","interrupted","clearTimeout","timer","Error","title","document","ref","setTimeout","splice","onPopState","currentIndex","Math","max","last","pop","removeEventListener","addEventListener","listen","listener"],"mappings":"AACA,SAASA,MAAT,QAAuB,mBAAvB;AAWA,eAAe,SAASC,mBAAT,GAA+B;AAC5C,MAAIC,KAAK,GAAG,CAAZ;AACA,MAAIC,KAAsB,GAAG,EAA7B,CAF4C,CAI5C;AACA;;AACA,QAAMC,OAAgE,GAAG,EAAzE;;AAEA,QAAMC,SAAS,GAAG,MAAM;AACtB;AACA;AACA;AACAD,IAAAA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D;;AAED8B,QAAAA,QAAQ;AACT,OAPD;;AASAxC,MAAAA,MAAM,CAACsC,gBAAP,CAAwB,UAAxB,EAAoCP,UAApC;AAEA,aAAO,MAAM/B,MAAM,CAACqC,mBAAP,CAA2B,UAA3B,EAAuCN,UAAvC,CAAb;AACD;;AArLa,GAAhB;AAwLA,SAAOjC,OAAP;AACD","sourcesContent":["import type { NavigationState } from '@react-navigation/core';\nimport { nanoid } from 'nanoid/non-secure';\n\ntype HistoryRecord = {\n // Unique identifier for this record to match it with window.history.state\n id: string;\n // Navigation state object for the history entry\n state: NavigationState;\n // Path of the history entry\n path: string;\n};\n\nexport default function createMemoryHistory() {\n let index = 0;\n let items: HistoryRecord[] = [];\n\n // Pending callbacks for `history.go(n)`\n // We might modify the callback stored if it was interrupted, so we have a ref to identify it\n const pending: { ref: unknown; cb: (interrupted?: boolean) => void }[] = [];\n\n const interrupt = () => {\n // If another history operation was performed we need to interrupt existing ones\n // This makes sure that calls such as `history.replace` after `history.go` don't happen\n // Since otherwise it won't be correct if something else has changed\n pending.forEach((it) => {\n const cb = it.cb;\n it.cb = () => cb(true);\n });\n };\n\n const history = {\n get index(): number {\n // We store an id in the state instead of an index\n // Index could get out of sync with in-memory values if page reloads\n const id = window.history.state?.id;\n\n if (id) {\n const index = items.findIndex((item) => item.id === id);\n\n return index > -1 ? index : 0;\n }\n\n return 0;\n },\n\n get(index: number) {\n return items[index];\n },\n\n backIndex({ path }: { path: string }) {\n // We need to find the index from the element before current to get closest path to go back to\n for (let i = index - 1; i >= 0; i--) {\n const item = items[i];\n\n if (item.path === path) {\n return i;\n }\n }\n\n return -1;\n },\n\n push({ path, state }: { path: string; state: NavigationState }) {\n interrupt();\n\n const id = nanoid();\n\n // When a new entry is pushed, all the existing entries after index will be inaccessible\n // So we remove any existing entries after the current index to clean them up\n items = items.slice(0, index + 1);\n\n items.push({ path, state, id });\n index = items.length - 1;\n\n // We pass empty string for title because it's ignored in all browsers except safari\n // We don't store state object in history.state because:\n // - browsers have limits on how big it can be, and we don't control the size\n // - while not recommended, there could be non-serializable data in state\n window.history.pushState({ id }, '', path);\n },\n\n replace({ path, state }: { path: string; state: NavigationState }) {\n interrupt();\n\n const id = window.history.state?.id ?? nanoid();\n\n if (!items.length || items.findIndex((item) => item.id === id) < 0) {\n // There are two scenarios for creating an array with only one history record:\n // - When loaded id not found in the items array, this function by default will replace\n // the first item. We need to keep only the new updated object, otherwise it will break\n // the page when navigating forward in history.\n // - This is the first time any state modifications are done\n // So we need to push the entry as there's nothing to replace\n items = [{ path, state, id }];\n index = 0;\n } else {\n items[index] = { path, state, id };\n }\n\n window.history.replaceState({ id }, '', path);\n },\n\n // `history.go(n)` is asynchronous, there are couple of things to keep in mind:\n // - it won't do anything if we can't go `n` steps, the `popstate` event won't fire.\n // - each `history.go(n)` call will trigger a separate `popstate` event with correct location.\n // - the `popstate` event fires before the next frame after calling `history.go(n)`.\n // This method differs from `history.go(n)` in the sense that it'll go back as many steps it can.\n go(n: number) {\n interrupt();\n\n // To guard against unexpected navigation out of the app we will assume that browser history is only as deep as the length of our memory\n // history. If we don't have an item to navigate to then update our index and navigate as far as we can without taking the user out of the app.\n const nextIndex = index + n;\n const lastItemIndex = items.length - 1;\n if (n < 0 && !items[nextIndex]) {\n // Attempted to navigate beyond the first index. Negating the current index will align the browser history with the first item.\n n = -index;\n index = 0;\n } else if (n > 0 && nextIndex > lastItemIndex) {\n // Attempted to navigate past the last index. Calculate how many indices away from the last index and go there.\n n = lastItemIndex - index;\n index = lastItemIndex;\n } else {\n index = nextIndex;\n }\n\n if (n === 0) {\n return;\n }\n\n // When we call `history.go`, `popstate` will fire when there's history to go back to\n // So we need to somehow handle following cases:\n // - There's history to go back, `history.go` is called, and `popstate` fires\n // - `history.go` is called multiple times, we need to resolve on respective `popstate`\n // - No history to go back, but `history.go` was called, browser has no API to detect it\n return new Promise<void>((resolve, reject) => {\n const done = (interrupted?: boolean) => {\n clearTimeout(timer);\n\n if (interrupted) {\n reject(new Error('History was changed during navigation.'));\n return;\n }\n\n // There seems to be a bug in Chrome regarding updating the title\n // If we set a title just before calling `history.go`, the title gets lost\n // However the value of `document.title` is still what we set it to\n // It's just not displayed in the tab bar\n // To update the tab bar, we need to reset the title to something else first (e.g. '')\n // And set the title to what it was before so it gets applied\n // It won't work without setting it to empty string coz otherwise title isn't changing\n // Which means that the browser won't do anything after setting the title\n const { title } = window.document;\n\n window.document.title = '';\n window.document.title = title;\n\n resolve();\n };\n\n pending.push({ ref: done, cb: done });\n\n // If navigation didn't happen within 100ms, assume that it won't happen\n // This may not be accurate, but hopefully it won't take so much time\n // In Chrome, navigation seems to happen instantly in next microtask\n // But on Firefox, it seems to take much longer, around 50ms from our testing\n // We're using a hacky timeout since there doesn't seem to be way to know for sure\n const timer = setTimeout(() => {\n const index = pending.findIndex((it) => it.ref === done);\n\n if (index > -1) {\n pending[index].cb();\n pending.splice(index, 1);\n }\n }, 100);\n\n const onPopState = () => {\n const id = window.history.state?.id;\n const currentIndex = items.findIndex((item) => item.id === id);\n\n // Fix createMemoryHistory.index variable's value\n // as it may go out of sync when navigating in the browser.\n index = Math.max(currentIndex, 0);\n\n const last = pending.pop();\n\n window.removeEventListener('popstate', onPopState);\n last?.cb();\n };\n\n window.addEventListener('popstate', onPopState);\n window.history.go(n);\n });\n },\n\n // The `popstate` event is triggered when history changes, except `pushState` and `replaceState`\n // If we call `history.go(n)` ourselves, we don't want it to trigger the listener\n // Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener\n listen(listener: () => void) {\n const onPopState = () => {\n if (pending.length) {\n // This was triggered by `history.go(n)`, we shouldn't call the listener\n return;\n }\n\n listener();\n };\n\n window.addEventListener('popstate', onPopState);\n\n return () => window.removeEventListener('popstate', onPopState);\n },\n };\n\n return history;\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  export { default as Link } from './Link';
2
+ export { default as LinkingContext } from './LinkingContext';
2
3
  export { default as NavigationContainer } from './NavigationContainer';
3
4
  export { default as ServerContainer } from './ServerContainer';
4
5
  export { default as DarkTheme } from './theming/DarkTheme';
@@ -1 +1 @@
1
- {"version":3,"sources":["index.tsx"],"names":["default","Link","NavigationContainer","ServerContainer","DarkTheme","DefaultTheme","ThemeProvider","useTheme","useLinkBuilder","useLinkProps","useLinkTo","useScrollToTop"],"mappings":"AAAA,SAASA,OAAO,IAAIC,IAApB,QAAgC,QAAhC;AACA,SAASD,OAAO,IAAIE,mBAApB,QAA+C,uBAA/C;AACA,SAASF,OAAO,IAAIG,eAApB,QAA2C,mBAA3C;AACA,SAASH,OAAO,IAAII,SAApB,QAAqC,qBAArC;AACA,SAASJ,OAAO,IAAIK,YAApB,QAAwC,wBAAxC;AACA,SAASL,OAAO,IAAIM,aAApB,QAAyC,yBAAzC;AACA,SAASN,OAAO,IAAIO,QAApB,QAAoC,oBAApC;AACA,cAAc,SAAd;AACA,SAASP,OAAO,IAAIQ,cAApB,QAA0C,kBAA1C;AACA,SAASR,OAAO,IAAIS,YAApB,QAAwC,gBAAxC;AACA,SAAST,OAAO,IAAIU,SAApB,QAAqC,aAArC;AACA,SAASV,OAAO,IAAIW,cAApB,QAA0C,kBAA1C;AACA,cAAc,wBAAd","sourcesContent":["export { default as Link } from './Link';\nexport { default as NavigationContainer } from './NavigationContainer';\nexport { default as ServerContainer } from './ServerContainer';\nexport { default as DarkTheme } from './theming/DarkTheme';\nexport { default as DefaultTheme } from './theming/DefaultTheme';\nexport { default as ThemeProvider } from './theming/ThemeProvider';\nexport { default as useTheme } from './theming/useTheme';\nexport * from './types';\nexport { default as useLinkBuilder } from './useLinkBuilder';\nexport { default as useLinkProps } from './useLinkProps';\nexport { default as useLinkTo } from './useLinkTo';\nexport { default as useScrollToTop } from './useScrollToTop';\nexport * from '@react-navigation/core';\n"]}
1
+ {"version":3,"sources":["index.tsx"],"names":["default","Link","LinkingContext","NavigationContainer","ServerContainer","DarkTheme","DefaultTheme","ThemeProvider","useTheme","useLinkBuilder","useLinkProps","useLinkTo","useScrollToTop"],"mappings":"AAAA,SAASA,OAAO,IAAIC,IAApB,QAAgC,QAAhC;AACA,SAASD,OAAO,IAAIE,cAApB,QAA0C,kBAA1C;AACA,SAASF,OAAO,IAAIG,mBAApB,QAA+C,uBAA/C;AACA,SAASH,OAAO,IAAII,eAApB,QAA2C,mBAA3C;AACA,SAASJ,OAAO,IAAIK,SAApB,QAAqC,qBAArC;AACA,SAASL,OAAO,IAAIM,YAApB,QAAwC,wBAAxC;AACA,SAASN,OAAO,IAAIO,aAApB,QAAyC,yBAAzC;AACA,SAASP,OAAO,IAAIQ,QAApB,QAAoC,oBAApC;AACA,cAAc,SAAd;AACA,SAASR,OAAO,IAAIS,cAApB,QAA0C,kBAA1C;AACA,SAAST,OAAO,IAAIU,YAApB,QAAwC,gBAAxC;AACA,SAASV,OAAO,IAAIW,SAApB,QAAqC,aAArC;AACA,SAASX,OAAO,IAAIY,cAApB,QAA0C,kBAA1C;AACA,cAAc,wBAAd","sourcesContent":["export { default as Link } from './Link';\nexport { default as LinkingContext } from './LinkingContext';\nexport { default as NavigationContainer } from './NavigationContainer';\nexport { default as ServerContainer } from './ServerContainer';\nexport { default as DarkTheme } from './theming/DarkTheme';\nexport { default as DefaultTheme } from './theming/DefaultTheme';\nexport { default as ThemeProvider } from './theming/ThemeProvider';\nexport { default as useTheme } from './theming/useTheme';\nexport * from './types';\nexport { default as useLinkBuilder } from './useLinkBuilder';\nexport { default as useLinkProps } from './useLinkProps';\nexport { default as useLinkTo } from './useLinkTo';\nexport { default as useScrollToTop } from './useScrollToTop';\nexport * from '@react-navigation/core';\n"]}