@idealyst/navigation 1.2.19 → 1.2.21

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idealyst/navigation",
3
- "version": "1.2.19",
3
+ "version": "1.2.21",
4
4
  "description": "Cross-platform navigation library for React and React Native",
5
5
  "readme": "README.md",
6
6
  "main": "src/index.ts",
@@ -44,9 +44,9 @@
44
44
  },
45
45
  "peerDependencies": {
46
46
  "@idealyst/camera": "^1.1.6",
47
- "@idealyst/components": "^1.2.19",
47
+ "@idealyst/components": "^1.2.21",
48
48
  "@idealyst/microphone": "^1.1.7",
49
- "@idealyst/theme": "^1.2.19",
49
+ "@idealyst/theme": "^1.2.21",
50
50
  "@react-navigation/bottom-tabs": ">=7.0.0",
51
51
  "@react-navigation/drawer": ">=7.0.0",
52
52
  "@react-navigation/native": ">=7.0.0",
@@ -71,11 +71,11 @@
71
71
  },
72
72
  "devDependencies": {
73
73
  "@idealyst/camera": "^1.1.6",
74
- "@idealyst/components": "^1.2.19",
74
+ "@idealyst/components": "^1.2.21",
75
75
  "@idealyst/datagrid": "^1.0.93",
76
76
  "@idealyst/datepicker": "^1.0.93",
77
77
  "@idealyst/microphone": "^1.1.7",
78
- "@idealyst/theme": "^1.2.19",
78
+ "@idealyst/theme": "^1.2.21",
79
79
  "@types/react": "^19.1.8",
80
80
  "@types/react-dom": "^19.1.6",
81
81
  "react": "^19.1.0",
@@ -1,3 +1,4 @@
1
1
  // Native-specific hook exports
2
2
  export * from './useParams.native';
3
- export * from './useNavigationState.native';
3
+ export * from './useNavigationState.native';
4
+ export * from './useCurrentPath.native';
@@ -1,3 +1,4 @@
1
1
  // Cross-platform hook exports
2
2
  export * from './useParams.web'; // This will be overridden by platform-specific exports
3
- export * from './useNavigationState.web'; // This will be overridden by platform-specific exports
3
+ export * from './useNavigationState.web'; // This will be overridden by platform-specific exports
4
+ export * from './useCurrentPath.web'; // This will be overridden by platform-specific exports
@@ -1,3 +1,4 @@
1
1
  // Web-specific hook exports
2
2
  export * from './useParams.web';
3
- export * from './useNavigationState.web';
3
+ export * from './useNavigationState.web';
4
+ export * from './useCurrentPath.web';
@@ -0,0 +1,16 @@
1
+ import { useRoute } from '@react-navigation/native';
2
+
3
+ /**
4
+ * Hook to get the current path the user is on.
5
+ * On native, returns the route name from React Navigation.
6
+ *
7
+ * @returns The current route path/name (e.g., '/users/123' or 'UserDetail')
8
+ *
9
+ * @example
10
+ * const currentPath = useCurrentPath();
11
+ * console.log(currentPath); // '/dashboard'
12
+ */
13
+ export const useCurrentPath = (): string => {
14
+ const route = useRoute();
15
+ return route.path ?? route.name ?? '';
16
+ };
@@ -0,0 +1,16 @@
1
+ import { useLocation } from '../router';
2
+
3
+ /**
4
+ * Hook to get the current path the user is on.
5
+ * On web, returns the current pathname from React Router.
6
+ *
7
+ * @returns The current pathname (e.g., '/users/123')
8
+ *
9
+ * @example
10
+ * const currentPath = useCurrentPath();
11
+ * console.log(currentPath); // '/dashboard'
12
+ */
13
+ export const useCurrentPath = (): string => {
14
+ const location = useLocation();
15
+ return location?.pathname ?? '/';
16
+ };
@@ -4,4 +4,7 @@ export * from './layouts';
4
4
  export * from './routing';
5
5
  export * from './hooks';
6
6
 
7
- // No React Router exports needed for native
7
+ // Outlet is a web-only concept (React Router).
8
+ // On native, we export a no-op component that renders nothing.
9
+ // This allows shared code to import Outlet without platform checks.
10
+ export { Outlet } from './router/index.native';
package/src/index.web.ts CHANGED
@@ -9,3 +9,6 @@ export { NavigatorProvider, useNavigator } from './context/NavigatorContext.web'
9
9
  // it doesn't apply .web extension priority for nested re-exports.
10
10
  // This explicit export ensures useParams is available from @idealyst/navigation.
11
11
  export { useParams } from './hooks/useParams.web';
12
+
13
+ // Re-export Outlet from React Router for web (no-op on native)
14
+ export { Outlet } from './router/index.web';
@@ -1,17 +1,43 @@
1
1
  // Native platforms don't use React Router
2
2
  // This is a stub to maintain cross-platform compatibility
3
3
 
4
+ import { useRoute } from '@react-navigation/native';
5
+ import type { Location } from './types';
6
+
7
+ export type { Location };
8
+
4
9
  export const BrowserRouter = null;
5
10
  export const HashRouter = null;
6
11
  export const MemoryRouter = null;
7
12
  export const Router = null;
8
13
  export const useNavigate = () => null;
9
- export const useLocation = () => null;
14
+
15
+ /**
16
+ * Cross-platform useLocation hook.
17
+ * On native, returns a location-like object derived from React Navigation's route.
18
+ */
19
+ export const useLocation = (): Location => {
20
+ const route = useRoute();
21
+ return {
22
+ pathname: route.path ?? route.name ?? '',
23
+ search: '',
24
+ hash: '',
25
+ state: route.params ?? null,
26
+ key: route.key,
27
+ };
28
+ };
29
+
10
30
  export const useParams = () => null;
11
31
  export const useSearchParams = () => null;
12
32
  export const Navigate = null;
13
- export const Outlet = null;
14
33
  export const Route = null;
15
34
  export const Routes = null;
16
35
  export const Link = null;
17
- export const NavLink = null;
36
+ export const NavLink = null;
37
+
38
+ /**
39
+ * Outlet is a web-only concept from React Router.
40
+ * On native, this is a no-op component that renders nothing.
41
+ * This allows shared code to import Outlet without platform checks.
42
+ */
43
+ export const Outlet = (): null => null;
@@ -18,10 +18,12 @@ import {
18
18
  Routes,
19
19
  Link,
20
20
  NavLink
21
- } from 'react-router-dom'
21
+ } from 'react-router-dom';
22
22
 
23
+ // Re-export our cross-platform Location type for consistency
24
+ export type { Location } from './types';
23
25
 
24
- export {
26
+ export {
25
27
  BrowserRouter,
26
28
  HashRouter,
27
29
  MemoryRouter,
@@ -18,10 +18,12 @@ import {
18
18
  Routes,
19
19
  Link,
20
20
  NavLink
21
- } from 'react-router-dom'
21
+ } from 'react-router-dom';
22
22
 
23
+ // Re-export our cross-platform Location type for consistency
24
+ export type { Location } from './types';
23
25
 
24
- export {
26
+ export {
25
27
  BrowserRouter,
26
28
  HashRouter,
27
29
  MemoryRouter,
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Cross-platform location type matching React Router's Location interface.
3
+ * Used by useLocation hook on both web and native.
4
+ */
5
+ export interface Location {
6
+ /** The current pathname (e.g., '/users/123') */
7
+ pathname: string;
8
+ /** The query string (e.g., '?foo=bar') - empty string on native */
9
+ search: string;
10
+ /** The URL hash (e.g., '#section') - empty string on native */
11
+ hash: string;
12
+ /** State passed during navigation */
13
+ state: unknown;
14
+ /** Unique key for this location */
15
+ key: string;
16
+ }