@trackunit/react-core-hooks 0.2.110 → 0.2.112-alpha-500b40a315.0

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/index.cjs.js CHANGED
@@ -203,6 +203,29 @@ const OemBrandingContextProvider = (props) => {
203
203
  return jsxRuntime.jsx(OemBrandingContext.Provider, Object.assign({}, props));
204
204
  };
205
205
 
206
+ const NavigationContext = React.createContext(null);
207
+ /**
208
+ * This is a provider for the NavigationContext.
209
+ */
210
+ const NavigationContextProvider = (props) => {
211
+ return jsxRuntime.jsx(NavigationContext.Provider, Object.assign({}, props));
212
+ };
213
+ /**
214
+ * This is a hook to use the NavigationContext.
215
+ *
216
+ * @requires NavigationContext
217
+ * @example
218
+ * import { useNavigateInHost } from "@trackunit/react-core-hooks";
219
+ * @see (@link INavigationContext)
220
+ */
221
+ const useNavigateInHost = () => {
222
+ const context = React.useContext(NavigationContext);
223
+ if (!context) {
224
+ throw new Error("useNavigateInHost must be used within an NavigationContext");
225
+ }
226
+ return context;
227
+ };
228
+
206
229
  /**
207
230
  * A react hook for notifying host about location changes
208
231
  */
@@ -219,23 +242,6 @@ const useURLSynchronization = () => {
219
242
  }, [location]);
220
243
  };
221
244
 
222
- /**
223
- * A hook to expose navigation runtime for React components
224
- *
225
- * @requires NavigationRuntime
226
- * @returns {UseNavigationRuntime} navigationRuntime
227
- * @example
228
- * import { useNavigationRuntime } from "@trackunit/react-core-hooks";
229
- * const { gotoAssetHome } = useNavigationRuntime();
230
- * // ...
231
- * <Link onClick={() => gotoAssetHome(asset.id)} to="">
232
- * {asset.name}
233
- * </Link>
234
- */
235
- const useNavigationRuntime = () => {
236
- return irisAppRuntimeCore.NavigationRuntime;
237
- };
238
-
239
245
  /******************************************************************************
240
246
  Copyright (c) Microsoft Corporation.
241
247
 
@@ -593,6 +599,7 @@ exports.CurrentUserProvider = CurrentUserProvider;
593
599
  exports.EnvironmentContextProvider = EnvironmentContextProvider;
594
600
  exports.FilterBarProvider = FilterBarProvider;
595
601
  exports.GlobalSelectionProvider = GlobalSelectionProvider;
602
+ exports.NavigationContextProvider = NavigationContextProvider;
596
603
  exports.OemBrandingContextProvider = OemBrandingContextProvider;
597
604
  exports.ToastProvider = ToastProvider;
598
605
  exports.TokenProvider = TokenProvider;
@@ -609,7 +616,7 @@ exports.useCustomFieldRuntimeForEntity = useCustomFieldRuntimeForEntity;
609
616
  exports.useEnvironment = useEnvironment;
610
617
  exports.useFilterBarContext = useFilterBarContext;
611
618
  exports.useGlobalSelection = useGlobalSelection;
612
- exports.useNavigationRuntime = useNavigationRuntime;
619
+ exports.useNavigateInHost = useNavigateInHost;
613
620
  exports.useOemBrandingContext = useOemBrandingContext;
614
621
  exports.useRestRuntime = useRestRuntime;
615
622
  exports.useSiteRuntime = useSiteRuntime;
package/index.esm.js CHANGED
@@ -177,6 +177,29 @@ const OemBrandingContextProvider = (props) => {
177
177
  return jsx(OemBrandingContext.Provider, Object.assign({}, props));
178
178
  };
179
179
 
180
+ const NavigationContext = createContext(null);
181
+ /**
182
+ * This is a provider for the NavigationContext.
183
+ */
184
+ const NavigationContextProvider = (props) => {
185
+ return jsx(NavigationContext.Provider, Object.assign({}, props));
186
+ };
187
+ /**
188
+ * This is a hook to use the NavigationContext.
189
+ *
190
+ * @requires NavigationContext
191
+ * @example
192
+ * import { useNavigateInHost } from "@trackunit/react-core-hooks";
193
+ * @see (@link INavigationContext)
194
+ */
195
+ const useNavigateInHost = () => {
196
+ const context = useContext(NavigationContext);
197
+ if (!context) {
198
+ throw new Error("useNavigateInHost must be used within an NavigationContext");
199
+ }
200
+ return context;
201
+ };
202
+
180
203
  /**
181
204
  * A react hook for notifying host about location changes
182
205
  */
@@ -193,23 +216,6 @@ const useURLSynchronization = () => {
193
216
  }, [location]);
194
217
  };
195
218
 
196
- /**
197
- * A hook to expose navigation runtime for React components
198
- *
199
- * @requires NavigationRuntime
200
- * @returns {UseNavigationRuntime} navigationRuntime
201
- * @example
202
- * import { useNavigationRuntime } from "@trackunit/react-core-hooks";
203
- * const { gotoAssetHome } = useNavigationRuntime();
204
- * // ...
205
- * <Link onClick={() => gotoAssetHome(asset.id)} to="">
206
- * {asset.name}
207
- * </Link>
208
- */
209
- const useNavigationRuntime = () => {
210
- return NavigationRuntime;
211
- };
212
-
213
219
  /******************************************************************************
214
220
  Copyright (c) Microsoft Corporation.
215
221
 
@@ -559,4 +565,4 @@ const useCurrentUser = () => {
559
565
  return context;
560
566
  };
561
567
 
562
- export { AnalyticsContext, AnalyticsContextProvider, AssetSortingProvider, CurrentUserPreferenceProvider, CurrentUserProvider, EnvironmentContextProvider, FilterBarProvider, GlobalSelectionProvider, OemBrandingContextProvider, ToastProvider, TokenProvider, UserSubscriptionProvider, useAnalytics, useAssetRuntime, useAssetSorting, useCurrentUser, useCurrentUserLanguage, useCurrentUserSystemOfMeasurement, useCurrentUserTimeZonePreference, useCustomFieldRuntime, useCustomFieldRuntimeForEntity, useEnvironment, useFilterBarContext, useGlobalSelection, useNavigationRuntime, useOemBrandingContext, useRestRuntime, useSiteRuntime, useTextSearch, useToast, useToken, useURLSynchronization, useUserSubscription };
568
+ export { AnalyticsContext, AnalyticsContextProvider, AssetSortingProvider, CurrentUserPreferenceProvider, CurrentUserProvider, EnvironmentContextProvider, FilterBarProvider, GlobalSelectionProvider, NavigationContextProvider, OemBrandingContextProvider, ToastProvider, TokenProvider, UserSubscriptionProvider, useAnalytics, useAssetRuntime, useAssetSorting, useCurrentUser, useCurrentUserLanguage, useCurrentUserSystemOfMeasurement, useCurrentUserTimeZonePreference, useCustomFieldRuntime, useCustomFieldRuntimeForEntity, useEnvironment, useFilterBarContext, useGlobalSelection, useNavigateInHost, useOemBrandingContext, useRestRuntime, useSiteRuntime, useTextSearch, useToast, useToken, useURLSynchronization, useUserSubscription };
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-hooks",
3
- "version": "0.2.110",
3
+ "version": "0.2.112-alpha-500b40a315.0",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
7
7
  "node": ">=18.x"
8
8
  },
9
- "module": "./index.esm.js",
10
- "main": "./index.cjs.js",
11
9
  "dependencies": {
12
- "@trackunit/iris-app-runtime-core": "0.3.91",
13
- "@trackunit/iris-app-runtime-core-api": "0.3.82",
14
- "@trackunit/react-core-contexts-api": "0.2.68",
15
- "@trackunit/shared-utils": "0.0.15",
16
- "react": "18.2.0",
17
- "react-router-dom": "6.11.2"
10
+ "@trackunit/react-core-contexts-api": "*",
11
+ "react": "^18.2.0",
12
+ "@trackunit/iris-app-runtime-core": "*",
13
+ "react-router-dom": "6.11.2",
14
+ "@trackunit/iris-app-runtime-core-api": "*",
15
+ "jest-fetch-mock": "^3.0.3",
16
+ "@trackunit/shared-utils": "*"
18
17
  },
19
- "peerDependencies": {}
18
+ "module": "./index.esm.js",
19
+ "main": "./index.cjs.js"
20
20
  }
package/src/index.d.ts CHANGED
@@ -4,8 +4,8 @@ export * from "./environment/EnvironmentContextProvider";
4
4
  export * from "./filter-bar/FilterBarProvider";
5
5
  export * from "./global-selection/GlobalSelectionProvider";
6
6
  export * from "./irisOemApp/IrisOemAppContextProvider";
7
- export * from "./runtimes/navigation";
8
- export * from "./runtimes/navigation/useNavigationRuntime";
7
+ export * from "./navigation/NavigationContextProvider";
8
+ export * from "./navigation/useURLSynchronization";
9
9
  export * from "./runtimes/useAssetRuntime";
10
10
  export * from "./runtimes/useCustomFieldRuntime";
11
11
  export * from "./runtimes/useCustomFieldRuntimeForEntity";
@@ -0,0 +1,20 @@
1
+ /// <reference types="react" />
2
+ import { INavigationContext } from "@trackunit/react-core-contexts-api";
3
+ interface IProps {
4
+ value: INavigationContext;
5
+ children?: React.ReactNode;
6
+ }
7
+ /**
8
+ * This is a provider for the NavigationContext.
9
+ */
10
+ export declare const NavigationContextProvider: (props: IProps) => JSX.Element;
11
+ /**
12
+ * This is a hook to use the NavigationContext.
13
+ *
14
+ * @requires NavigationContext
15
+ * @example
16
+ * import { useNavigateInHost } from "@trackunit/react-core-hooks";
17
+ * @see (@link INavigationContext)
18
+ */
19
+ export declare const useNavigateInHost: () => INavigationContext;
20
+ export {};
@@ -1 +0,0 @@
1
- export * from "./useURLSynchronization";
@@ -1,4 +0,0 @@
1
- export type DeepLink = {
2
- path: string;
3
- search: Location["search"];
4
- };
@@ -1,17 +0,0 @@
1
- import { INavigationRuntime } from "@trackunit/iris-app-runtime-core";
2
- export interface UseNavigationRuntime extends INavigationRuntime {
3
- }
4
- /**
5
- * A hook to expose navigation runtime for React components
6
- *
7
- * @requires NavigationRuntime
8
- * @returns {UseNavigationRuntime} navigationRuntime
9
- * @example
10
- * import { useNavigationRuntime } from "@trackunit/react-core-hooks";
11
- * const { gotoAssetHome } = useNavigationRuntime();
12
- * // ...
13
- * <Link onClick={() => gotoAssetHome(asset.id)} to="">
14
- * {asset.name}
15
- * </Link>
16
- */
17
- export declare const useNavigationRuntime: () => UseNavigationRuntime;