@trackunit/react-core-hooks 0.2.169 → 0.2.170
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 +39 -21
- package/index.esm.js +41 -20
- package/package.json +1 -2
- package/src/index.d.ts +1 -1
- package/src/runtimes/useParamsRuntime.d.ts +22 -0
- package/src/navigation/useURLSynchronization.d.ts +0 -4
package/index.cjs.js
CHANGED
|
@@ -5,11 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
var irisAppRuntimeCore = require('@trackunit/iris-app-runtime-core');
|
|
8
|
-
var reactRouterDom = require('react-router-dom');
|
|
9
8
|
var sharedUtils = require('@trackunit/shared-utils');
|
|
10
9
|
|
|
11
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
-
|
|
13
10
|
function _interopNamespace(e) {
|
|
14
11
|
if (e && e.__esModule) return e;
|
|
15
12
|
var n = Object.create(null);
|
|
@@ -29,7 +26,6 @@ function _interopNamespace(e) {
|
|
|
29
26
|
}
|
|
30
27
|
|
|
31
28
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
32
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
33
29
|
|
|
34
30
|
const AnalyticsContext = React.createContext(null);
|
|
35
31
|
const AnalyticsContextProvider = AnalyticsContext.Provider; // easy import
|
|
@@ -274,22 +270,6 @@ const useHasAccessTo = (options) => {
|
|
|
274
270
|
return { hasAccess };
|
|
275
271
|
};
|
|
276
272
|
|
|
277
|
-
/**
|
|
278
|
-
* A react hook for notifying host about location changes
|
|
279
|
-
*/
|
|
280
|
-
const useURLSynchronization = () => {
|
|
281
|
-
const location = reactRouterDom.useLocation();
|
|
282
|
-
React__default["default"].useEffect(() => {
|
|
283
|
-
const deepLink = {
|
|
284
|
-
path: location.pathname,
|
|
285
|
-
search: location.search,
|
|
286
|
-
hash: location.hash,
|
|
287
|
-
pathname: "",
|
|
288
|
-
};
|
|
289
|
-
irisAppRuntimeCore.NavigationRuntime.setDeepLink(deepLink);
|
|
290
|
-
}, [location]);
|
|
291
|
-
};
|
|
292
|
-
|
|
293
273
|
/**
|
|
294
274
|
* A hook to expose asset runtime for React components
|
|
295
275
|
*
|
|
@@ -422,6 +402,44 @@ const useEventRuntime = () => {
|
|
|
422
402
|
return { eventInfo, loading, error };
|
|
423
403
|
};
|
|
424
404
|
|
|
405
|
+
/**
|
|
406
|
+
* A hook to expose getIrisAppName for React components
|
|
407
|
+
*
|
|
408
|
+
* @requires ParamsRuntime
|
|
409
|
+
* @returns {UseIrisAppName} appName, loading, error
|
|
410
|
+
* @example
|
|
411
|
+
* import { useIrisAppName } from "@trackunit/react-core-hooks";
|
|
412
|
+
* const { appName } = useIrisAppName();
|
|
413
|
+
* useEffect(() => {
|
|
414
|
+
* (async () => {
|
|
415
|
+
* if (appName) {
|
|
416
|
+
* // do something with appName
|
|
417
|
+
* }
|
|
418
|
+
* })();
|
|
419
|
+
* }, [appName]);
|
|
420
|
+
*/
|
|
421
|
+
const useIrisAppName = () => {
|
|
422
|
+
const [appName, setAppName] = React.useState();
|
|
423
|
+
const [loading, setLoading] = React.useState(true);
|
|
424
|
+
const [error, setError] = React.useState();
|
|
425
|
+
React.useEffect(() => {
|
|
426
|
+
const getAppName = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
427
|
+
setLoading(true);
|
|
428
|
+
try {
|
|
429
|
+
const updatedAppName = yield irisAppRuntimeCore.ParamsRuntime.getAppName();
|
|
430
|
+
setLoading(false);
|
|
431
|
+
setAppName(updatedAppName);
|
|
432
|
+
}
|
|
433
|
+
catch (e) {
|
|
434
|
+
setLoading(false);
|
|
435
|
+
setError(new Error("Failed to get iris app name"));
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
getAppName();
|
|
439
|
+
}, []);
|
|
440
|
+
return { appName, loading, error };
|
|
441
|
+
};
|
|
442
|
+
|
|
425
443
|
/**
|
|
426
444
|
* A hook to expose site runtime for React components
|
|
427
445
|
*
|
|
@@ -699,11 +717,11 @@ exports.useEnvironment = useEnvironment;
|
|
|
699
717
|
exports.useEventRuntime = useEventRuntime;
|
|
700
718
|
exports.useFilterBarContext = useFilterBarContext;
|
|
701
719
|
exports.useHasAccessTo = useHasAccessTo;
|
|
720
|
+
exports.useIrisAppName = useIrisAppName;
|
|
702
721
|
exports.useNavigateInHost = useNavigateInHost;
|
|
703
722
|
exports.useOemBrandingContext = useOemBrandingContext;
|
|
704
723
|
exports.useSiteRuntime = useSiteRuntime;
|
|
705
724
|
exports.useTextSearch = useTextSearch;
|
|
706
725
|
exports.useToast = useToast;
|
|
707
726
|
exports.useToken = useToken;
|
|
708
|
-
exports.useURLSynchronization = useURLSynchronization;
|
|
709
727
|
exports.useUserSubscription = useUserSubscription;
|
package/index.esm.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { createContext, useContext, useState, useEffect, useMemo } from 'react';
|
|
3
3
|
import { jsx } from 'react/jsx-runtime';
|
|
4
|
-
import {
|
|
5
|
-
import { useLocation } from 'react-router-dom';
|
|
4
|
+
import { AssetRuntime, CustomFieldRuntime, EventRuntime, ParamsRuntime, SiteRuntime } from '@trackunit/iris-app-runtime-core';
|
|
6
5
|
import { filterByMultiple } from '@trackunit/shared-utils';
|
|
7
6
|
|
|
8
7
|
const AnalyticsContext = createContext(null);
|
|
@@ -248,22 +247,6 @@ const useHasAccessTo = (options) => {
|
|
|
248
247
|
return { hasAccess };
|
|
249
248
|
};
|
|
250
249
|
|
|
251
|
-
/**
|
|
252
|
-
* A react hook for notifying host about location changes
|
|
253
|
-
*/
|
|
254
|
-
const useURLSynchronization = () => {
|
|
255
|
-
const location = useLocation();
|
|
256
|
-
React__default.useEffect(() => {
|
|
257
|
-
const deepLink = {
|
|
258
|
-
path: location.pathname,
|
|
259
|
-
search: location.search,
|
|
260
|
-
hash: location.hash,
|
|
261
|
-
pathname: "",
|
|
262
|
-
};
|
|
263
|
-
NavigationRuntime.setDeepLink(deepLink);
|
|
264
|
-
}, [location]);
|
|
265
|
-
};
|
|
266
|
-
|
|
267
250
|
/**
|
|
268
251
|
* A hook to expose asset runtime for React components
|
|
269
252
|
*
|
|
@@ -396,6 +379,44 @@ const useEventRuntime = () => {
|
|
|
396
379
|
return { eventInfo, loading, error };
|
|
397
380
|
};
|
|
398
381
|
|
|
382
|
+
/**
|
|
383
|
+
* A hook to expose getIrisAppName for React components
|
|
384
|
+
*
|
|
385
|
+
* @requires ParamsRuntime
|
|
386
|
+
* @returns {UseIrisAppName} appName, loading, error
|
|
387
|
+
* @example
|
|
388
|
+
* import { useIrisAppName } from "@trackunit/react-core-hooks";
|
|
389
|
+
* const { appName } = useIrisAppName();
|
|
390
|
+
* useEffect(() => {
|
|
391
|
+
* (async () => {
|
|
392
|
+
* if (appName) {
|
|
393
|
+
* // do something with appName
|
|
394
|
+
* }
|
|
395
|
+
* })();
|
|
396
|
+
* }, [appName]);
|
|
397
|
+
*/
|
|
398
|
+
const useIrisAppName = () => {
|
|
399
|
+
const [appName, setAppName] = useState();
|
|
400
|
+
const [loading, setLoading] = useState(true);
|
|
401
|
+
const [error, setError] = useState();
|
|
402
|
+
useEffect(() => {
|
|
403
|
+
const getAppName = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
404
|
+
setLoading(true);
|
|
405
|
+
try {
|
|
406
|
+
const updatedAppName = yield ParamsRuntime.getAppName();
|
|
407
|
+
setLoading(false);
|
|
408
|
+
setAppName(updatedAppName);
|
|
409
|
+
}
|
|
410
|
+
catch (e) {
|
|
411
|
+
setLoading(false);
|
|
412
|
+
setError(new Error("Failed to get iris app name"));
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
getAppName();
|
|
416
|
+
}, []);
|
|
417
|
+
return { appName, loading, error };
|
|
418
|
+
};
|
|
419
|
+
|
|
399
420
|
/**
|
|
400
421
|
* A hook to expose site runtime for React components
|
|
401
422
|
*
|
|
@@ -646,4 +667,4 @@ const useCurrentUser = () => {
|
|
|
646
667
|
return context;
|
|
647
668
|
};
|
|
648
669
|
|
|
649
|
-
export { AnalyticsContext, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, CurrentUserPreferenceProvider, CurrentUserProvider, EnvironmentContextProvider, FilterBarProvider, NavigationContextProvider, OemBrandingContextProvider, ToastProvider, TokenProvider, UserSubscriptionProvider, useAnalytics, useAssetRuntime, useAssetSorting, useConfirmationDialog, useCurrentUser, useCurrentUserLanguage, useCurrentUserSystemOfMeasurement, useCurrentUserTimeZonePreference, useCustomFieldRuntime, useCustomFieldRuntimeForEntity, useEnvironment, useEventRuntime, useFilterBarContext, useHasAccessTo, useNavigateInHost, useOemBrandingContext, useSiteRuntime, useTextSearch, useToast, useToken,
|
|
670
|
+
export { AnalyticsContext, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, CurrentUserPreferenceProvider, CurrentUserProvider, EnvironmentContextProvider, FilterBarProvider, NavigationContextProvider, OemBrandingContextProvider, ToastProvider, TokenProvider, UserSubscriptionProvider, useAnalytics, useAssetRuntime, useAssetSorting, useConfirmationDialog, useCurrentUser, useCurrentUserLanguage, useCurrentUserSystemOfMeasurement, useCurrentUserTimeZonePreference, useCustomFieldRuntime, useCustomFieldRuntimeForEntity, useEnvironment, useEventRuntime, useFilterBarContext, useHasAccessTo, useIrisAppName, useNavigateInHost, useOemBrandingContext, useSiteRuntime, useTextSearch, useToast, useToken, useUserSubscription };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-core-hooks",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.170",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
"@trackunit/react-core-contexts-api": "*",
|
|
11
11
|
"react": "^18.2.0",
|
|
12
12
|
"@trackunit/iris-app-runtime-core": "*",
|
|
13
|
-
"react-router-dom": "6.18.0",
|
|
14
13
|
"@trackunit/iris-app-runtime-core-api": "*",
|
|
15
14
|
"jest-fetch-mock": "^3.0.3",
|
|
16
15
|
"@trackunit/shared-utils": "*"
|
package/src/index.d.ts
CHANGED
|
@@ -5,11 +5,11 @@ export * from "./environment/EnvironmentContextProvider";
|
|
|
5
5
|
export * from "./filter-bar/FilterBarProvider";
|
|
6
6
|
export * from "./irisOemApp/IrisOemAppContextProvider";
|
|
7
7
|
export * from "./navigation/NavigationContextProvider";
|
|
8
|
-
export * from "./navigation/useURLSynchronization";
|
|
9
8
|
export * from "./runtimes/useAssetRuntime";
|
|
10
9
|
export * from "./runtimes/useCustomFieldRuntime";
|
|
11
10
|
export * from "./runtimes/useCustomFieldRuntimeForEntity";
|
|
12
11
|
export * from "./runtimes/useEventRuntime";
|
|
12
|
+
export * from "./runtimes/useParamsRuntime";
|
|
13
13
|
export * from "./runtimes/useSiteRuntime";
|
|
14
14
|
export * from "./subscription/UserSubscriptionProvider";
|
|
15
15
|
export * from "./toast/ToastProvider";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface UseIrisAppName {
|
|
2
|
+
appName: string | undefined;
|
|
3
|
+
loading: boolean;
|
|
4
|
+
error: Error | undefined;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A hook to expose getIrisAppName for React components
|
|
8
|
+
*
|
|
9
|
+
* @requires ParamsRuntime
|
|
10
|
+
* @returns {UseIrisAppName} appName, loading, error
|
|
11
|
+
* @example
|
|
12
|
+
* import { useIrisAppName } from "@trackunit/react-core-hooks";
|
|
13
|
+
* const { appName } = useIrisAppName();
|
|
14
|
+
* useEffect(() => {
|
|
15
|
+
* (async () => {
|
|
16
|
+
* if (appName) {
|
|
17
|
+
* // do something with appName
|
|
18
|
+
* }
|
|
19
|
+
* })();
|
|
20
|
+
* }, [appName]);
|
|
21
|
+
*/
|
|
22
|
+
export declare const useIrisAppName: () => UseIrisAppName;
|