@buoy-gg/route-events 7.0.41 → 7.0.43

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.
Files changed (102) hide show
  1. package/README.md +11 -64
  2. package/lib/commonjs/RouteObserver.js +1 -54
  3. package/lib/commonjs/RouteParser.js +1 -314
  4. package/lib/commonjs/RouteTracker.js +1 -112
  5. package/lib/commonjs/RouteTracker.web.js +1 -12
  6. package/lib/commonjs/browserRouteRegistry.js +1 -30
  7. package/lib/commonjs/browserRoutes.js +1 -96
  8. package/lib/commonjs/components/NavigationStack.js +2 -572
  9. package/lib/commonjs/components/ReactNavigationRoutes.js +1 -836
  10. package/lib/commonjs/components/ReactNavigationRoutes.web.js +1 -12
  11. package/lib/commonjs/components/RouteEventDetail.js +1 -97
  12. package/lib/commonjs/components/RouteEventExpandedContent.js +1 -204
  13. package/lib/commonjs/components/RouteEventItemCompact.js +1 -191
  14. package/lib/commonjs/components/RouteEventsModalWithTabs.js +1 -734
  15. package/lib/commonjs/components/RouteEventsTimeline.js +1 -107
  16. package/lib/commonjs/components/RouteFilterViewV2.js +1 -42
  17. package/lib/commonjs/components/RoutesSitemap.js +2 -1035
  18. package/lib/commonjs/expoRouterStore.js +1 -121
  19. package/lib/commonjs/expoRouterStore.web.js +1 -44
  20. package/lib/commonjs/hooks/useRouteEvents.js +1 -57
  21. package/lib/commonjs/index.js +1 -168
  22. package/lib/commonjs/preset.js +1 -69
  23. package/lib/commonjs/stores/navigationStackStore.js +1 -45
  24. package/lib/commonjs/stores/routeEventStore.js +1 -136
  25. package/lib/commonjs/sync/routeEventsSyncAdapter.js +1 -275
  26. package/lib/commonjs/useNavigationStack.js +1 -408
  27. package/lib/commonjs/useNavigationStack.web.js +1 -32
  28. package/lib/commonjs/useRouteObserver.js +1 -73
  29. package/lib/commonjs/useRouteObserverReactNavigation.js +1 -109
  30. package/lib/commonjs/useRouteSitemap.js +1 -255
  31. package/lib/commonjs/utils/routeTemplate.js +1 -79
  32. package/lib/commonjs/utils/safeReactNavigation.js +1 -194
  33. package/lib/commonjs/utils/safeReactNavigation.web.js +1 -36
  34. package/lib/commonjs/utils/testIDs.js +1 -63
  35. package/lib/module/RouteObserver.js +1 -49
  36. package/lib/module/RouteParser.js +1 -309
  37. package/lib/module/RouteTracker.js +1 -109
  38. package/lib/module/RouteTracker.web.js +1 -8
  39. package/lib/module/browserRouteRegistry.js +1 -24
  40. package/lib/module/browserRoutes.js +1 -92
  41. package/lib/module/components/NavigationStack.js +2 -568
  42. package/lib/module/components/ReactNavigationRoutes.js +1 -832
  43. package/lib/module/components/ReactNavigationRoutes.web.js +1 -3
  44. package/lib/module/components/RouteEventDetail.js +1 -93
  45. package/lib/module/components/RouteEventExpandedContent.js +1 -200
  46. package/lib/module/components/RouteEventItemCompact.js +1 -187
  47. package/lib/module/components/RouteEventsModalWithTabs.js +1 -731
  48. package/lib/module/components/RouteEventsTimeline.js +1 -103
  49. package/lib/module/components/RouteFilterViewV2.js +1 -38
  50. package/lib/module/components/RoutesSitemap.js +2 -1033
  51. package/lib/module/expoRouterStore.js +1 -114
  52. package/lib/module/expoRouterStore.web.js +1 -37
  53. package/lib/module/hooks/useRouteEvents.js +1 -54
  54. package/lib/module/index.js +1 -70
  55. package/lib/module/preset.js +1 -66
  56. package/lib/module/stores/navigationStackStore.js +1 -41
  57. package/lib/module/stores/routeEventStore.js +1 -128
  58. package/lib/module/sync/routeEventsSyncAdapter.js +1 -273
  59. package/lib/module/useNavigationStack.js +1 -404
  60. package/lib/module/useNavigationStack.web.js +1 -28
  61. package/lib/module/useRouteObserver.js +1 -70
  62. package/lib/module/useRouteObserverReactNavigation.js +1 -106
  63. package/lib/module/useRouteSitemap.js +1 -250
  64. package/lib/module/utils/routeTemplate.js +1 -73
  65. package/lib/module/utils/safeReactNavigation.js +1 -185
  66. package/lib/module/utils/safeReactNavigation.web.js +1 -27
  67. package/lib/module/utils/testIDs.js +1 -55
  68. package/lib/web/index.mjs +4 -5
  69. package/package.json +6 -11
  70. package/lib/typescript/RouteObserver.d.ts.map +0 -1
  71. package/lib/typescript/RouteParser.d.ts.map +0 -1
  72. package/lib/typescript/RouteTracker.d.ts.map +0 -1
  73. package/lib/typescript/RouteTracker.web.d.ts.map +0 -1
  74. package/lib/typescript/browserRouteRegistry.d.ts.map +0 -1
  75. package/lib/typescript/browserRoutes.d.ts.map +0 -1
  76. package/lib/typescript/components/NavigationStack.d.ts.map +0 -1
  77. package/lib/typescript/components/ReactNavigationRoutes.d.ts.map +0 -1
  78. package/lib/typescript/components/ReactNavigationRoutes.web.d.ts.map +0 -1
  79. package/lib/typescript/components/RouteEventDetail.d.ts.map +0 -1
  80. package/lib/typescript/components/RouteEventExpandedContent.d.ts.map +0 -1
  81. package/lib/typescript/components/RouteEventItemCompact.d.ts.map +0 -1
  82. package/lib/typescript/components/RouteEventsModalWithTabs.d.ts.map +0 -1
  83. package/lib/typescript/components/RouteEventsTimeline.d.ts.map +0 -1
  84. package/lib/typescript/components/RouteFilterViewV2.d.ts.map +0 -1
  85. package/lib/typescript/components/RoutesSitemap.d.ts.map +0 -1
  86. package/lib/typescript/expoRouterStore.d.ts.map +0 -1
  87. package/lib/typescript/expoRouterStore.web.d.ts.map +0 -1
  88. package/lib/typescript/hooks/useRouteEvents.d.ts.map +0 -1
  89. package/lib/typescript/index.d.ts.map +0 -1
  90. package/lib/typescript/preset.d.ts.map +0 -1
  91. package/lib/typescript/stores/navigationStackStore.d.ts.map +0 -1
  92. package/lib/typescript/stores/routeEventStore.d.ts.map +0 -1
  93. package/lib/typescript/sync/routeEventsSyncAdapter.d.ts.map +0 -1
  94. package/lib/typescript/useNavigationStack.d.ts.map +0 -1
  95. package/lib/typescript/useNavigationStack.web.d.ts.map +0 -1
  96. package/lib/typescript/useRouteObserver.d.ts.map +0 -1
  97. package/lib/typescript/useRouteObserverReactNavigation.d.ts.map +0 -1
  98. package/lib/typescript/useRouteSitemap.d.ts.map +0 -1
  99. package/lib/typescript/utils/routeTemplate.d.ts.map +0 -1
  100. package/lib/typescript/utils/safeReactNavigation.d.ts.map +0 -1
  101. package/lib/typescript/utils/safeReactNavigation.web.d.ts.map +0 -1
  102. package/lib/typescript/utils/testIDs.d.ts.map +0 -1
@@ -1,408 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.buildStack = buildStack;
7
- exports.useNavigationStack = useNavigationStack;
8
- var _react = require("react");
9
- var _safeReactNavigation = require("./utils/safeReactNavigation");
10
- var _sharedUi = require("@buoy-gg/shared-ui");
11
- /**
12
- * useNavigationStack - Hook to access current navigation stack state
13
- *
14
- * Provides real-time access to the navigation stack,
15
- * showing what screens are currently mounted in memory and which is visible.
16
- *
17
- * Supports both Expo Router and React Navigation (RN CLI).
18
- *
19
- * - Expo Router: uses useNavigation/useNavigationState (inside navigator context)
20
- * - RN CLI: uses NavigationContainerRefContext (works as sibling of navigators)
21
- */
22
-
23
- // Resolved once at module load; null when React Navigation is absent
24
- // (useSafeNavigationContainerRef then yields undefined, so the dispatch
25
- // paths below never execute).
26
- const CommonActions = (0, _safeReactNavigation.getCommonActions)();
27
- const StackActions = (0, _safeReactNavigation.getStackActions)();
28
-
29
- // ============================================================================
30
- // Type Definitions
31
- // ============================================================================
32
-
33
- // ============================================================================
34
- // Nested Navigation Helpers
35
- // ============================================================================
36
-
37
- /**
38
- * Find the path from root navigation state to a screen by name.
39
- * Returns array of route names from root to the target, or null if not found.
40
- */
41
- function findScreenPath(state, screenName) {
42
- if (!state || !state.routes) return null;
43
- for (const route of state.routes) {
44
- if (route.name === screenName) {
45
- return [route.name];
46
- }
47
- if (route.state) {
48
- const nested = findScreenPath(route.state, screenName);
49
- if (nested) {
50
- return [route.name, ...nested];
51
- }
52
- }
53
- }
54
- return null;
55
- }
56
-
57
- /**
58
- * Build a nested CommonActions.navigate() from a path of screen names.
59
- * e.g. ["MainApp", "Settings", "SettingScreen"] becomes:
60
- * navigate("MainApp", { screen: "Settings", params: { screen: "SettingScreen" } })
61
- */
62
- function buildNestedNavigateAction(path) {
63
- if (path.length === 0) return null;
64
- if (path.length === 1) {
65
- return CommonActions.navigate({
66
- name: path[0]
67
- });
68
- }
69
- let params = {
70
- screen: path[path.length - 1]
71
- };
72
- for (let i = path.length - 2; i >= 1; i--) {
73
- params = {
74
- screen: path[i],
75
- params
76
- };
77
- }
78
- return CommonActions.navigate({
79
- name: path[0],
80
- params
81
- });
82
- }
83
-
84
- // ============================================================================
85
- // Main Hook
86
- // ============================================================================
87
-
88
- /**
89
- * Recursively collect the routes from the navigation state tree.
90
- *
91
- * FOCUS COMES FROM `state.index`, NEVER FROM POSITION. React Navigation names
92
- * the focused route by index within `routes`; the array's order is declaration
93
- * order. `buildStack` used to equate the two — "the last route in the collected
94
- * list is the focused one" — and a hidden tab declared last (`href: null` on an
95
- * expo-router `Tabs.Screen`) then became the reported current screen for the
96
- * whole session. Measured on a real app: Home and Rewards both reported as a
97
- * hidden Menu tab, in every turn of a 55-scenario QA run, because `menu` was
98
- * declared last.
99
- *
100
- * TAB AND DRAWER SIBLINGS ARE NOT A STACK. They are alternative destinations
101
- * that happen to be mounted at the same time; `canPop` and `popToIndex` never
102
- * meant anything for them. Only the focused branch of a tab/drawer is
103
- * collected, so what comes back is the stack you could actually pop.
104
- */
105
- function collectRoutesFromState(state, depth = 0, parentPath = "", onFocusedChain = true) {
106
- if (!state || !Array.isArray(state.routes) || state.routes.length === 0) {
107
- return [];
108
- }
109
- const routes = [];
110
-
111
- // An absent or out-of-range `index` is incomplete state (mid-rehydration, a
112
- // partially built child). Fall back to the last route — a stack's top — and
113
- // never to an arbitrary sibling.
114
- const declaredIndex = typeof state.index === "number" ? state.index : NaN;
115
- const focusedIndex = Number.isInteger(declaredIndex) && declaredIndex >= 0 && declaredIndex < state.routes.length ? declaredIndex : state.routes.length - 1;
116
- const navigatorType = typeof state.type === "string" ? state.type : undefined;
117
- const siblingsAreStack = navigatorType !== "tab" && navigatorType !== "drawer";
118
- for (let i = 0; i < state.routes.length; i++) {
119
- if (!siblingsAreStack && i !== focusedIndex) continue;
120
- const route = state.routes[i];
121
- const isFocused = i === focusedIndex;
122
-
123
- // Build the path
124
- let pathname = route.name;
125
- if (route.name === "index") {
126
- pathname = "/";
127
- } else if (!pathname.startsWith("/")) {
128
- pathname = `/${pathname}`;
129
- }
130
-
131
- // Add parent path
132
- if (parentPath && parentPath !== "/") {
133
- pathname = `${parentPath}${pathname}`;
134
- }
135
-
136
- // Add params to pathname for dynamic routes
137
- if (route.params) {
138
- const paramEntries = Object.entries(route.params);
139
- if (paramEntries.length > 0) {
140
- pathname = pathname.replace(/\[([^\]]+)\]/g, (match, param) => {
141
- return route.params[param] || match;
142
- });
143
- }
144
- }
145
-
146
- // Descend the focused branch first: whatever it yields owns the focus, and
147
- // this route only keeps it when nothing deeper claimed it.
148
- const onChain = onFocusedChain && isFocused;
149
- const nestedRoutes = onChain && route.state ? collectRoutesFromState(route.state, depth + 1, pathname, true) : [];
150
- routes.push({
151
- key: route.key,
152
- name: route.name,
153
- path: pathname,
154
- params: route.params || {},
155
- state: route.state,
156
- isFocused: onChain && nestedRoutes.length === 0
157
- });
158
- routes.push(...nestedRoutes);
159
- }
160
- return routes;
161
- }
162
-
163
- /**
164
- * Transform raw navigation state into display items.
165
- *
166
- * Exported for tests: the focus rule below is the one thing every route answer
167
- * in the product rests on, and it was previously only reachable by extracting
168
- * the function from source with the TypeScript AST.
169
- */
170
- function buildStack(navigationState, isExpo) {
171
- if (!navigationState) return [];
172
- try {
173
- const routes = collectRoutesFromState(navigationState);
174
-
175
- // Filter out internal Expo Router routes (layouts, __root, etc.)
176
- // These only exist in Expo Router; on RN CLI all routes are user-defined
177
- const filteredRoutes = isExpo ? routes.filter(route => {
178
- if (route.name.startsWith("__")) return false;
179
- if (route.name.includes("_layout")) return false;
180
- if (route.name.startsWith("+not-found")) return false;
181
- return true;
182
- }) : routes;
183
-
184
- // If we filtered everything out, just keep the last route
185
- const finalRoutes = filteredRoutes.length > 0 ? filteredRoutes : routes.slice(-1);
186
-
187
- /**
188
- * Focus survives filtering. It is decided in `collectRoutesFromState` from
189
- * `state.index`; the only case that falls back to the last item is one
190
- * where the filter dropped the focused route itself (an internal expo
191
- * layout), which is the one situation the old rule was ever right for.
192
- */
193
- const collectedFocus = finalRoutes.findIndex(route => route.isFocused);
194
- const focusIndex = collectedFocus >= 0 ? collectedFocus : finalRoutes.length - 1;
195
- return finalRoutes.map((route, index) => {
196
- let cleanPath = route.path || `/${route.name}`;
197
- // Clean up Expo Router internal /__root prefix
198
- if (isExpo) {
199
- cleanPath = cleanPath.replace(/^\/__root/, "");
200
- }
201
- // Ensure we always have at least a /
202
- if (!cleanPath || cleanPath === "") {
203
- cleanPath = "/";
204
- }
205
- return {
206
- key: route.key,
207
- name: route.name,
208
- pathname: cleanPath,
209
- params: route.params || {},
210
- isFocused: index === focusIndex,
211
- index,
212
- canPop: index > 0
213
- };
214
- });
215
- } catch (err) {
216
- console.error("Error transforming navigation state:", err);
217
- return [];
218
- }
219
- }
220
-
221
- /**
222
- * Access the current navigation stack.
223
- *
224
- * Works in both Expo Router and RN CLI apps. On RN CLI, uses the
225
- * NavigationContainer ref context so it works even as a sibling of navigators.
226
- *
227
- * @example
228
- * ```tsx
229
- * const { stack, focusedRoute, goBack, popToTop } = useNavigationStack();
230
- *
231
- * // Display stack
232
- * stack.map(item => (
233
- * <View key={item.key}>
234
- * <Text>{item.pathname}</Text>
235
- * {item.isFocused && <Text>VISIBLE</Text>}
236
- * </View>
237
- * ));
238
- * ```
239
- */
240
- function useNavigationStack() {
241
- const isExpo = (0, _sharedUi.isExpoRouterAvailable)();
242
- const containerRef = (0, _safeReactNavigation.useSafeNavigationContainerRef)();
243
- const [navigationState, setNavigationState] = (0, _react.useState)(() => containerRef?.getRootState?.() ?? null);
244
- const [isLoaded, setIsLoaded] = (0, _react.useState)(false);
245
- const [error, setError] = (0, _react.useState)(null);
246
-
247
- // Subscribe to navigation state changes via the container ref
248
- (0, _react.useEffect)(() => {
249
- if (!containerRef) return;
250
-
251
- // Get initial state
252
- const initialState = containerRef.getRootState?.();
253
- if (initialState) {
254
- setNavigationState(initialState);
255
- }
256
- setIsLoaded(true);
257
-
258
- // Listen for state changes
259
- const unsubscribe = containerRef.addListener?.("state", () => {
260
- const state = containerRef.getRootState?.();
261
- if (state) {
262
- setNavigationState(state);
263
- }
264
- });
265
- return () => {
266
- unsubscribe?.();
267
- };
268
- }, [containerRef]);
269
-
270
- // Transform navigation state into display items
271
- const stack = (0, _react.useMemo)(() => buildStack(navigationState, isExpo), [navigationState, isExpo]);
272
-
273
- // Get focused route
274
- const focusedRoute = (0, _react.useMemo)(() => {
275
- return stack.find(item => item.isFocused) || null;
276
- }, [stack]);
277
-
278
- // Helper properties
279
- const stackDepth = stack.length;
280
- const isAtRoot = stackDepth <= 1;
281
-
282
- // Manual refresh
283
- const refresh = (0, _react.useCallback)(() => {
284
- if (!containerRef) return;
285
- const state = containerRef.getRootState?.();
286
- if (state) {
287
- setNavigationState(state);
288
- }
289
- }, [containerRef]);
290
-
291
- // Navigation actions - use Expo Router when available, fall back to React Navigation
292
- const navigateToIndex = (0, _react.useCallback)(index => {
293
- if (index >= stack.length || index < 0) return;
294
- const targetRoute = stack[index];
295
- if (!targetRoute) return;
296
- try {
297
- const expoRouter = (0, _sharedUi.getSafeRouter)();
298
- if (expoRouter) {
299
- expoRouter.navigate(targetRoute.pathname);
300
- } else if (containerRef) {
301
- // Walk the state tree to build nested screen/params for deep navigation
302
- const rootState = containerRef.getRootState?.();
303
- if (rootState) {
304
- const path = findScreenPath(rootState, targetRoute.name);
305
- if (path) {
306
- const action = buildNestedNavigateAction(path);
307
- if (action) {
308
- containerRef.dispatch(action);
309
- return;
310
- }
311
- }
312
- }
313
- // Fallback: try direct navigation
314
- containerRef.dispatch(CommonActions.navigate({
315
- name: targetRoute.name,
316
- params: targetRoute.params
317
- }));
318
- }
319
- } catch (err) {
320
- console.error("Failed to navigate:", err);
321
- }
322
- }, [stack, containerRef]);
323
- const navigateToRoute = (0, _react.useCallback)((name, params) => {
324
- if (!containerRef) return false;
325
- try {
326
- // Deep path first, so screens inside nested navigators resolve even
327
- // when their navigator isn't mounted yet.
328
- const rootState = containerRef.getRootState?.();
329
- if (!params && rootState) {
330
- const path = findScreenPath(rootState, name);
331
- if (path) {
332
- const action = buildNestedNavigateAction(path);
333
- if (action) {
334
- containerRef.dispatch(action);
335
- return true;
336
- }
337
- }
338
- }
339
- containerRef.dispatch(CommonActions.navigate({
340
- name,
341
- params
342
- }));
343
- return true;
344
- } catch (err) {
345
- console.error("Failed to navigate:", err);
346
- return false;
347
- }
348
- }, [containerRef]);
349
- const popToIndex = (0, _react.useCallback)(index => {
350
- if (index >= stack.length || index < 0) return;
351
- const currentIndex = stack.length - 1;
352
- const popCount = currentIndex - index;
353
- if (popCount <= 0) return;
354
- try {
355
- const expoRouter = (0, _sharedUi.getSafeRouter)();
356
- if (expoRouter) {
357
- for (let i = 0; i < popCount; i++) {
358
- expoRouter.back();
359
- }
360
- } else if (containerRef) {
361
- containerRef.dispatch(StackActions.pop(popCount));
362
- }
363
- } catch (err) {
364
- console.error("Failed to pop:", err);
365
- }
366
- }, [stack, containerRef]);
367
- const goBack = (0, _react.useCallback)(() => {
368
- if (isAtRoot) return;
369
- try {
370
- const expoRouter = (0, _sharedUi.getSafeRouter)();
371
- if (expoRouter) {
372
- expoRouter.back();
373
- } else if (containerRef) {
374
- containerRef.goBack();
375
- }
376
- } catch (err) {
377
- console.error("Failed to go back:", err);
378
- }
379
- }, [isAtRoot, containerRef]);
380
- const popToTop = (0, _react.useCallback)(() => {
381
- if (isAtRoot) return;
382
- try {
383
- const expoRouter = (0, _sharedUi.getSafeRouter)();
384
- if (expoRouter) {
385
- // Pop to index 0 via expo-router
386
- popToIndex(0);
387
- } else if (containerRef) {
388
- containerRef.dispatch(StackActions.popToTop());
389
- }
390
- } catch (err) {
391
- console.error("Failed to pop to top:", err);
392
- }
393
- }, [isAtRoot, containerRef, popToIndex]);
394
- return {
395
- stack,
396
- focusedRoute,
397
- stackDepth,
398
- isAtRoot,
399
- isLoaded,
400
- error,
401
- refresh,
402
- navigateToIndex,
403
- navigateToRoute,
404
- popToIndex,
405
- goBack,
406
- popToTop
407
- };
408
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.buildStack=buildStack;exports.useNavigationStack=useNavigationStack;var _react=require("react");var _safeReactNavigation=require("./utils/safeReactNavigation");var _sharedUi=require("@buoy-gg/shared-ui");const CommonActions=(0,_safeReactNavigation.getCommonActions)();const StackActions=(0,_safeReactNavigation.getStackActions)();function findScreenPath(t,e){if(!t||!t.routes)return null;for(const o of t.routes){if(o.name===e){return[o.name]}if(o.state){const f=findScreenPath(o.state,e);if(f){return[o.name,...f]}}}return null}function buildNestedNavigateAction(t){if(t.length===0)return null;if(t.length===1){return CommonActions.navigate({name:t[0]})}let e={screen:t[t.length-1]};for(let o=t.length-2;o>=1;o--){e={screen:t[o],params:e}}return CommonActions.navigate({name:t[0],params:e})}function collectRoutesFromState(t,e=0,o="",f=true){if(!t||!Array.isArray(t.routes)||t.routes.length===0){return[]}const p=[];const d=typeof t.index==="number"?t.index:NaN;const R=Number.isInteger(d)&&d>=0&&d<t.routes.length?d:t.routes.length-1;const s=typeof t.type==="string"?t.type:void 0;const r=s!=="tab"&&s!=="drawer";for(let i=0;i<t.routes.length;i++){if(!r&&i!==R)continue;const c=t.routes[i];const h=i===R;let u=c.name;if(c.name==="index"){u="/"}else if(!u.startsWith("/")){u=`/${u}`}if(o&&o!=="/"){u=`${o}${u}`}if(c.params){const S=Object.entries(c.params);if(S.length>0){u=u.replace(/\[([^\]]+)\]/g,(b,y)=>{return c.params[y]||b})}}const k=f&&h;const v=k&&c.state?collectRoutesFromState(c.state,e+1,u,true):[];p.push({key:c.key,name:c.name,path:u,params:c.params||{},state:c.state,isFocused:k&&v.length===0});p.push(...v)}return p}function buildStack(t,e){if(!t)return[];try{const o=collectRoutesFromState(t);const f=e?o.filter(s=>{if(s.name.startsWith("__"))return false;if(s.name.includes("_layout"))return false;if(s.name.startsWith("+not-found"))return false;return true}):o;const p=f.length>0?f:o.slice(-1);const d=p.findIndex(s=>s.isFocused);const R=d>=0?d:p.length-1;return p.map((s,r)=>{let i=s.path||`/${s.name}`;if(e){i=i.replace(/^\/__root/,"")}if(!i||i===""){i="/"}return{key:s.key,name:s.name,pathname:i,params:s.params||{},isFocused:r===R,index:r,canPop:r>0}})}catch(o){console.error("Error transforming navigation state:",o);return[]}}function useNavigationStack(){const t=(0,_sharedUi.isExpoRouterAvailable)();const e=(0,_safeReactNavigation.useSafeNavigationContainerRef)();const[o,f]=(0,_react.useState)(()=>e?.getRootState?.()??null);const[p,d]=(0,_react.useState)(false);const[R,s]=(0,_react.useState)(null);(0,_react.useEffect)(()=>{if(!e)return;const n=e.getRootState?.();if(n){f(n)}d(true);const l=e.addListener?.("state",()=>{const a=e.getRootState?.();if(a){f(a)}});return()=>{l?.()}},[e]);const r=(0,_react.useMemo)(()=>buildStack(o,t),[o,t]);const i=(0,_react.useMemo)(()=>{return r.find(n=>n.isFocused)||null},[r]);const c=r.length;const h=c<=1;const u=(0,_react.useCallback)(()=>{if(!e)return;const n=e.getRootState?.();if(n){f(n)}},[e]);const k=(0,_react.useCallback)(n=>{if(n>=r.length||n<0)return;const l=r[n];if(!l)return;try{const a=(0,_sharedUi.getSafeRouter)();if(a){a.navigate(l.pathname)}else if(e){const g=e.getRootState?.();if(g){const m=findScreenPath(g,l.name);if(m){const x=buildNestedNavigateAction(m);if(x){e.dispatch(x);return}}}e.dispatch(CommonActions.navigate({name:l.name,params:l.params}))}}catch(a){console.error("Failed to navigate:",a)}},[r,e]);const v=(0,_react.useCallback)((n,l)=>{if(!e)return false;try{const a=e.getRootState?.();if(!l&&a){const g=findScreenPath(a,n);if(g){const m=buildNestedNavigateAction(g);if(m){e.dispatch(m);return true}}}e.dispatch(CommonActions.navigate({name:n,params:l}));return true}catch(a){console.error("Failed to navigate:",a);return false}},[e]);const S=(0,_react.useCallback)(n=>{if(n>=r.length||n<0)return;const l=r.length-1;const a=l-n;if(a<=0)return;try{const g=(0,_sharedUi.getSafeRouter)();if(g){for(let m=0;m<a;m++){g.back()}}else if(e){e.dispatch(StackActions.pop(a))}}catch(g){console.error("Failed to pop:",g)}},[r,e]);const b=(0,_react.useCallback)(()=>{if(h)return;try{const n=(0,_sharedUi.getSafeRouter)();if(n){n.back()}else if(e){e.goBack()}}catch(n){console.error("Failed to go back:",n)}},[h,e]);const y=(0,_react.useCallback)(()=>{if(h)return;try{const n=(0,_sharedUi.getSafeRouter)();if(n){S(0)}else if(e){e.dispatch(StackActions.popToTop())}}catch(n){console.error("Failed to pop to top:",n)}},[h,e,S]);return{stack:r,focusedRoute:i,stackDepth:c,isAtRoot:h,isLoaded:p,error:R,refresh:u,navigateToIndex:k,navigateToRoute:v,popToIndex:S,goBack:b,popToTop:y}}
@@ -1,32 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useNavigationStack = useNavigationStack;
7
- var _react = require("react");
8
- var _navigationStackStore = require("./stores/navigationStackStore");
9
- const empty = [];
10
- function useNavigationStack() {
11
- const stack = (0, _react.useSyncExternalStore)(callback => _navigationStackStore.navigationStackStore.subscribe(callback), () => _navigationStackStore.navigationStackStore.getStack(), () => empty);
12
- const focused = stack.find(item => item.isFocused) ?? null;
13
- const actions = () => {
14
- const current = _navigationStackStore.navigationStackStore.getActions();
15
- if (!current) throw new Error('Mount RouteTracker to capture browser navigation.');
16
- return current;
17
- };
18
- return {
19
- stack,
20
- focusedRoute: focused,
21
- stackDepth: stack.length,
22
- isAtRoot: !focused || focused.index === 0,
23
- isLoaded: stack.length > 0,
24
- error: null,
25
- refresh: () => {},
26
- navigateToIndex: index => actions().navigateToIndex(index),
27
- navigateToRoute: (name, params) => actions().navigateToRoute?.(name, params) ?? false,
28
- popToIndex: index => actions().popToIndex(index),
29
- goBack: () => actions().goBack(),
30
- popToTop: () => actions().popToTop()
31
- };
32
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.useNavigationStack=useNavigationStack;var _react=require("react");var _navigationStackStore=require("./stores/navigationStackStore");const empty=[];function useNavigationStack(){const o=(0,_react.useSyncExternalStore)(t=>_navigationStackStore.navigationStackStore.subscribe(t),()=>_navigationStackStore.navigationStackStore.getStack(),()=>empty);const a=o.find(t=>t.isFocused)??null;const e=()=>{const t=_navigationStackStore.navigationStackStore.getActions();if(!t)throw new Error("Mount RouteTracker to capture browser navigation.");return t};return{stack:o,focusedRoute:a,stackDepth:o.length,isAtRoot:!a||a.index===0,isLoaded:o.length>0,error:null,refresh:()=>{},navigateToIndex:t=>e().navigateToIndex(t),navigateToRoute:(t,n)=>e().navigateToRoute?.(t,n)??false,popToIndex:t=>e().popToIndex(t),goBack:()=>e().goBack(),popToTop:()=>e().popToTop()}}
@@ -1,73 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useRouteObserver = useRouteObserver;
7
- var _react = require("react");
8
- var _sharedUi = require("@buoy-gg/shared-ui");
9
- var _RouteObserver = require("./RouteObserver");
10
- /**
11
- * useRouteObserver - React hook for observing route changes
12
- *
13
- * Uses public Expo Router hooks to track route changes and emits them
14
- * to the global RouteObserver singleton.
15
- */
16
-
17
- /**
18
- * Hook to observe route changes in Expo Router
19
- * Automatically emits events to the global RouteObserver
20
- *
21
- * @param callback - Optional function to call on route changes (in addition to the observer)
22
- *
23
- * @example
24
- * ```tsx
25
- * // Just track routes (no custom callback)
26
- * useRouteObserver();
27
- *
28
- * // Track routes with custom callback
29
- * useRouteObserver((event) => {
30
- * // Handle route change
31
- * analytics.trackPageView(event.pathname);
32
- * });
33
- * ```
34
- */
35
- function useRouteObserver(callback) {
36
- const pathname = (0, _sharedUi.useSafePathname)();
37
- const segments = (0, _sharedUi.useSafeSegments)();
38
- const params = (0, _sharedUi.useSafeGlobalSearchParams)();
39
- const callbackRef = (0, _react.useRef)(callback);
40
- const previousPathnameRef = (0, _react.useRef)(undefined);
41
- const previousTimestampRef = (0, _react.useRef)(undefined);
42
-
43
- // Update ref when callback changes
44
- (0, _react.useEffect)(() => {
45
- callbackRef.current = callback;
46
- }, [callback]);
47
-
48
- // Trigger observer and callback whenever route changes
49
- (0, _react.useEffect)(() => {
50
- const now = Date.now();
51
- const timeSincePrevious = previousTimestampRef.current ? now - previousTimestampRef.current : undefined;
52
- const event = {
53
- pathname,
54
- params: params,
55
- segments: segments,
56
- timestamp: now,
57
- previousPathname: previousPathnameRef.current,
58
- timeSincePrevious
59
- };
60
-
61
- // Update refs for next navigation
62
- previousPathnameRef.current = pathname;
63
- previousTimestampRef.current = now;
64
-
65
- // Emit to the global observer (this notifies the modal)
66
- _RouteObserver.routeObserver.emit(event);
67
-
68
- // Also call the custom callback if provided
69
- if (callbackRef.current) {
70
- callbackRef.current(event);
71
- }
72
- }, [pathname, segments, params]);
73
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.useRouteObserver=useRouteObserver;var _react=require("react");var _sharedUi=require("@buoy-gg/shared-ui");var _RouteObserver=require("./RouteObserver");function useRouteObserver(e){const r=(0,_sharedUi.useSafePathname)();const n=(0,_sharedUi.useSafeSegments)();const a=(0,_sharedUi.useSafeGlobalSearchParams)();const t=(0,_react.useRef)(e);const o=(0,_react.useRef)(void 0);const s=(0,_react.useRef)(void 0);(0,_react.useEffect)(()=>{t.current=e},[e]);(0,_react.useEffect)(()=>{const u=Date.now();const i=s.current?u-s.current:void 0;const c={pathname:r,params:a,segments:n,timestamp:u,previousPathname:o.current,timeSincePrevious:i};o.current=r;s.current=u;_RouteObserver.routeObserver.emit(c);if(t.current){t.current(c)}},[r,n,a])}
@@ -1,109 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useRouteObserverReactNavigation = useRouteObserverReactNavigation;
7
- var _react = require("react");
8
- var _safeReactNavigation = require("./utils/safeReactNavigation");
9
- var _RouteObserver = require("./RouteObserver");
10
- /**
11
- * useRouteObserverReactNavigation - React hook for observing route changes
12
- * using @react-navigation/native APIs.
13
- *
14
- * This is the React Navigation (RN CLI) counterpart to useRouteObserver.ts
15
- * which uses Expo Router hooks. Both emit to the same routeObserver singleton.
16
- *
17
- * Uses NavigationContainerRefContext so it works anywhere inside
18
- * a NavigationContainer — does NOT need to be inside a navigator.
19
- */
20
-
21
- /**
22
- * Walk a React Navigation state tree to find the deepest focused route.
23
- * Returns the route object and the array of route names from root to leaf.
24
- */
25
- function getDeepestFocusedRoute(state) {
26
- if (!state || !state.routes || state.routes.length === 0) {
27
- return {
28
- route: null,
29
- segments: []
30
- };
31
- }
32
- const route = state.routes[state.index ?? 0];
33
- const segments = [route.name];
34
- if (route.state) {
35
- const nested = getDeepestFocusedRoute(route.state);
36
- if (nested.route) {
37
- return {
38
- route: nested.route,
39
- segments: [...segments, ...nested.segments]
40
- };
41
- }
42
- }
43
- return {
44
- route,
45
- segments
46
- };
47
- }
48
- function emitRouteEvent(state, previousPathnameRef, previousTimestampRef, callbackRef) {
49
- if (!state) return;
50
- const {
51
- route,
52
- segments
53
- } = getDeepestFocusedRoute(state);
54
- if (!route) return;
55
- const pathname = `/${route.name}`;
56
-
57
- // Skip if pathname hasn't changed
58
- if (pathname === previousPathnameRef.current) return;
59
- const now = Date.now();
60
- const timeSincePrevious = previousTimestampRef.current ? now - previousTimestampRef.current : undefined;
61
- const event = {
62
- pathname,
63
- params: route.params || {},
64
- segments,
65
- timestamp: now,
66
- previousPathname: previousPathnameRef.current,
67
- timeSincePrevious
68
- };
69
- previousPathnameRef.current = pathname;
70
- previousTimestampRef.current = now;
71
- _RouteObserver.routeObserver.emit(event);
72
- if (callbackRef.current) {
73
- callbackRef.current(event);
74
- }
75
- }
76
-
77
- /**
78
- * Hook to observe route changes via @react-navigation/native.
79
- * Automatically emits events to the global RouteObserver.
80
- *
81
- * Works anywhere inside a NavigationContainer (does not need to be inside a navigator).
82
- */
83
- function useRouteObserverReactNavigation(callback) {
84
- const containerRef = (0, _safeReactNavigation.useSafeNavigationContainerRef)();
85
- const callbackRef = (0, _react.useRef)(callback);
86
- const previousPathnameRef = (0, _react.useRef)(undefined);
87
- const previousTimestampRef = (0, _react.useRef)(undefined);
88
- (0, _react.useEffect)(() => {
89
- callbackRef.current = callback;
90
- }, [callback]);
91
- (0, _react.useEffect)(() => {
92
- if (!containerRef) return;
93
-
94
- // Emit for the initial state
95
- const initialState = containerRef.getRootState?.();
96
- if (initialState) {
97
- emitRouteEvent(initialState, previousPathnameRef, previousTimestampRef, callbackRef);
98
- }
99
-
100
- // Listen for state changes
101
- const unsubscribe = containerRef.addListener?.("state", () => {
102
- const state = containerRef.getRootState?.();
103
- emitRouteEvent(state, previousPathnameRef, previousTimestampRef, callbackRef);
104
- });
105
- return () => {
106
- unsubscribe?.();
107
- };
108
- }, [containerRef]);
109
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.useRouteObserverReactNavigation=useRouteObserverReactNavigation;var _react=require("react");var _safeReactNavigation=require("./utils/safeReactNavigation");var _RouteObserver=require("./RouteObserver");function getDeepestFocusedRoute(t){if(!t||!t.routes||t.routes.length===0){return{route:null,segments:[]}}const e=t.routes[t.index??0];const r=[e.name];if(e.state){const n=getDeepestFocusedRoute(e.state);if(n.route){return{route:n.route,segments:[...r,...n.segments]}}}return{route:e,segments:r}}function emitRouteEvent(t,e,r,n){if(!t)return;const{route:u,segments:i}=getDeepestFocusedRoute(t);if(!u)return;const s=`/${u.name}`;if(s===e.current)return;const o=Date.now();const a=r.current?o-r.current:void 0;const c={pathname:s,params:u.params||{},segments:i,timestamp:o,previousPathname:e.current,timeSincePrevious:a};e.current=s;r.current=o;_RouteObserver.routeObserver.emit(c);if(n.current){n.current(c)}}function useRouteObserverReactNavigation(t){const e=(0,_safeReactNavigation.useSafeNavigationContainerRef)();const r=(0,_react.useRef)(t);const n=(0,_react.useRef)(void 0);const u=(0,_react.useRef)(void 0);(0,_react.useEffect)(()=>{r.current=t},[t]);(0,_react.useEffect)(()=>{if(!e)return;const i=e.getRootState?.();if(i){emitRouteEvent(i,n,u,r)}const s=e.addListener?.("state",()=>{const o=e.getRootState?.();emitRouteEvent(o,n,u,r)});return()=>{s?.()}},[e])}