@trackunit/react-core-hooks 1.3.79 → 1.3.81
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 +75 -0
- package/index.esm.js +74 -2
- package/package.json +5 -4
- package/src/index.d.ts +1 -0
- package/src/widgetConfig/WidgetConfigProvider.d.ts +50 -0
package/index.cjs.js
CHANGED
|
@@ -4,6 +4,7 @@ var react = require('react');
|
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
5
|
var irisAppRuntimeCore = require('@trackunit/iris-app-runtime-core');
|
|
6
6
|
var sharedUtils = require('@trackunit/shared-utils');
|
|
7
|
+
var reactRouter = require('@tanstack/react-router');
|
|
7
8
|
|
|
8
9
|
const AnalyticsContext = react.createContext(null);
|
|
9
10
|
const AnalyticsContextProvider = AnalyticsContext.Provider; // easy import
|
|
@@ -1064,6 +1065,77 @@ function useTextSearch(items, props) {
|
|
|
1064
1065
|
return [result, searchText, setSearchText];
|
|
1065
1066
|
}
|
|
1066
1067
|
|
|
1068
|
+
const WidgetConfigContext = react.createContext(null);
|
|
1069
|
+
/**
|
|
1070
|
+
* This is a hook to use the WidgetConfigProvider.
|
|
1071
|
+
*
|
|
1072
|
+
* @requires WidgetConfigProvider
|
|
1073
|
+
* @example
|
|
1074
|
+
* import { useWidgetConfigAsync } from "@trackunit/react-core-hooks";
|
|
1075
|
+
*
|
|
1076
|
+
* export const useWidgetConfigAsync = () => {
|
|
1077
|
+
* const { widgetConfig } = useWidgetConfigAsync();
|
|
1078
|
+
*
|
|
1079
|
+
* ...
|
|
1080
|
+
* };
|
|
1081
|
+
* @see {@link WidgetConfigContext}
|
|
1082
|
+
*/
|
|
1083
|
+
const useWidgetConfigAsync = () => {
|
|
1084
|
+
const context = react.useContext(WidgetConfigContext);
|
|
1085
|
+
if (!context) {
|
|
1086
|
+
throw new Error("useWidgetConfig must be used within the WidgetConfigContext");
|
|
1087
|
+
}
|
|
1088
|
+
return context;
|
|
1089
|
+
};
|
|
1090
|
+
/**
|
|
1091
|
+
* This is a provider for the WidgetConfigContext.
|
|
1092
|
+
*/
|
|
1093
|
+
const WidgetConfigProvider = (props) => jsxRuntime.jsx(WidgetConfigContext.Provider, { ...props });
|
|
1094
|
+
/**
|
|
1095
|
+
* This is a hook to use the WidgetConfigContext.
|
|
1096
|
+
*
|
|
1097
|
+
* @example
|
|
1098
|
+
* import { useWidgetConfig } from "@trackunit/react-core-hooks";
|
|
1099
|
+
*
|
|
1100
|
+
* export const useWidgetConfig = () => {
|
|
1101
|
+
* const { widgetConfig } = useWidgetConfig();
|
|
1102
|
+
*
|
|
1103
|
+
* ...
|
|
1104
|
+
* };
|
|
1105
|
+
* @see {@link WidgetConfigContext}
|
|
1106
|
+
*/
|
|
1107
|
+
const useWidgetConfig = () => {
|
|
1108
|
+
const [data, setData] = react.useState(null);
|
|
1109
|
+
const [dataVersion, setDataVersion] = react.useState(null);
|
|
1110
|
+
const [title, setTitle] = react.useState(null);
|
|
1111
|
+
const filters = useFilterBarContext();
|
|
1112
|
+
const { timeRange } = useTimeRange();
|
|
1113
|
+
const { edit } = reactRouter.useSearch({ from: "/", select: params => params });
|
|
1114
|
+
react.useEffect(() => {
|
|
1115
|
+
irisAppRuntimeCore.WidgetConfigRuntime.getData().then(d => setData(d));
|
|
1116
|
+
irisAppRuntimeCore.WidgetConfigRuntime.getDataVersion().then(dv => setDataVersion(dv));
|
|
1117
|
+
irisAppRuntimeCore.WidgetConfigRuntime.getTitle().then(t => setTitle(t));
|
|
1118
|
+
}, []);
|
|
1119
|
+
const result = react.useMemo(() => ({
|
|
1120
|
+
data,
|
|
1121
|
+
setData: async (newData, newDataVersion) => {
|
|
1122
|
+
await irisAppRuntimeCore.WidgetConfigRuntime.setData(newData, newDataVersion);
|
|
1123
|
+
setData(newData);
|
|
1124
|
+
setDataVersion(newDataVersion);
|
|
1125
|
+
},
|
|
1126
|
+
dataVersion,
|
|
1127
|
+
title,
|
|
1128
|
+
setTitle: async (newTitle) => {
|
|
1129
|
+
await irisAppRuntimeCore.WidgetConfigRuntime.setTitle(newTitle);
|
|
1130
|
+
setTitle(newTitle);
|
|
1131
|
+
},
|
|
1132
|
+
filters,
|
|
1133
|
+
timeRange,
|
|
1134
|
+
isEditMode: edit,
|
|
1135
|
+
}), [data, dataVersion, title, filters, timeRange, edit]);
|
|
1136
|
+
return result;
|
|
1137
|
+
};
|
|
1138
|
+
|
|
1067
1139
|
exports.AnalyticsContext = AnalyticsContext;
|
|
1068
1140
|
exports.AnalyticsContextProvider = AnalyticsContextProvider;
|
|
1069
1141
|
exports.AssetSortingProvider = AssetSortingProvider;
|
|
@@ -1081,6 +1153,7 @@ exports.TimeRangeProvider = TimeRangeProvider;
|
|
|
1081
1153
|
exports.ToastProvider = ToastProvider;
|
|
1082
1154
|
exports.TokenProvider = TokenProvider;
|
|
1083
1155
|
exports.UserSubscriptionProvider = UserSubscriptionProvider;
|
|
1156
|
+
exports.WidgetConfigProvider = WidgetConfigProvider;
|
|
1084
1157
|
exports.fetchAssetBlobUrl = fetchAssetBlobUrl;
|
|
1085
1158
|
exports.useAnalytics = useAnalytics;
|
|
1086
1159
|
exports.useAssetRuntime = useAssetRuntime;
|
|
@@ -1113,3 +1186,5 @@ exports.useTimeRange = useTimeRange;
|
|
|
1113
1186
|
exports.useToast = useToast;
|
|
1114
1187
|
exports.useToken = useToken;
|
|
1115
1188
|
exports.useUserSubscription = useUserSubscription;
|
|
1189
|
+
exports.useWidgetConfig = useWidgetConfig;
|
|
1190
|
+
exports.useWidgetConfigAsync = useWidgetConfigAsync;
|
package/index.esm.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createContext, useContext, useMemo, useState, useCallback, useRef, useEffect, useReducer } from 'react';
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { AssetRuntime, CustomerRuntime, EventRuntime, ParamsRuntime, SiteRuntime } from '@trackunit/iris-app-runtime-core';
|
|
3
|
+
import { AssetRuntime, CustomerRuntime, EventRuntime, ParamsRuntime, SiteRuntime, WidgetConfigRuntime } from '@trackunit/iris-app-runtime-core';
|
|
4
4
|
import { filterByMultiple } from '@trackunit/shared-utils';
|
|
5
|
+
import { useSearch } from '@tanstack/react-router';
|
|
5
6
|
|
|
6
7
|
const AnalyticsContext = createContext(null);
|
|
7
8
|
const AnalyticsContextProvider = AnalyticsContext.Provider; // easy import
|
|
@@ -1062,4 +1063,75 @@ function useTextSearch(items, props) {
|
|
|
1062
1063
|
return [result, searchText, setSearchText];
|
|
1063
1064
|
}
|
|
1064
1065
|
|
|
1065
|
-
|
|
1066
|
+
const WidgetConfigContext = createContext(null);
|
|
1067
|
+
/**
|
|
1068
|
+
* This is a hook to use the WidgetConfigProvider.
|
|
1069
|
+
*
|
|
1070
|
+
* @requires WidgetConfigProvider
|
|
1071
|
+
* @example
|
|
1072
|
+
* import { useWidgetConfigAsync } from "@trackunit/react-core-hooks";
|
|
1073
|
+
*
|
|
1074
|
+
* export const useWidgetConfigAsync = () => {
|
|
1075
|
+
* const { widgetConfig } = useWidgetConfigAsync();
|
|
1076
|
+
*
|
|
1077
|
+
* ...
|
|
1078
|
+
* };
|
|
1079
|
+
* @see {@link WidgetConfigContext}
|
|
1080
|
+
*/
|
|
1081
|
+
const useWidgetConfigAsync = () => {
|
|
1082
|
+
const context = useContext(WidgetConfigContext);
|
|
1083
|
+
if (!context) {
|
|
1084
|
+
throw new Error("useWidgetConfig must be used within the WidgetConfigContext");
|
|
1085
|
+
}
|
|
1086
|
+
return context;
|
|
1087
|
+
};
|
|
1088
|
+
/**
|
|
1089
|
+
* This is a provider for the WidgetConfigContext.
|
|
1090
|
+
*/
|
|
1091
|
+
const WidgetConfigProvider = (props) => jsx(WidgetConfigContext.Provider, { ...props });
|
|
1092
|
+
/**
|
|
1093
|
+
* This is a hook to use the WidgetConfigContext.
|
|
1094
|
+
*
|
|
1095
|
+
* @example
|
|
1096
|
+
* import { useWidgetConfig } from "@trackunit/react-core-hooks";
|
|
1097
|
+
*
|
|
1098
|
+
* export const useWidgetConfig = () => {
|
|
1099
|
+
* const { widgetConfig } = useWidgetConfig();
|
|
1100
|
+
*
|
|
1101
|
+
* ...
|
|
1102
|
+
* };
|
|
1103
|
+
* @see {@link WidgetConfigContext}
|
|
1104
|
+
*/
|
|
1105
|
+
const useWidgetConfig = () => {
|
|
1106
|
+
const [data, setData] = useState(null);
|
|
1107
|
+
const [dataVersion, setDataVersion] = useState(null);
|
|
1108
|
+
const [title, setTitle] = useState(null);
|
|
1109
|
+
const filters = useFilterBarContext();
|
|
1110
|
+
const { timeRange } = useTimeRange();
|
|
1111
|
+
const { edit } = useSearch({ from: "/", select: params => params });
|
|
1112
|
+
useEffect(() => {
|
|
1113
|
+
WidgetConfigRuntime.getData().then(d => setData(d));
|
|
1114
|
+
WidgetConfigRuntime.getDataVersion().then(dv => setDataVersion(dv));
|
|
1115
|
+
WidgetConfigRuntime.getTitle().then(t => setTitle(t));
|
|
1116
|
+
}, []);
|
|
1117
|
+
const result = useMemo(() => ({
|
|
1118
|
+
data,
|
|
1119
|
+
setData: async (newData, newDataVersion) => {
|
|
1120
|
+
await WidgetConfigRuntime.setData(newData, newDataVersion);
|
|
1121
|
+
setData(newData);
|
|
1122
|
+
setDataVersion(newDataVersion);
|
|
1123
|
+
},
|
|
1124
|
+
dataVersion,
|
|
1125
|
+
title,
|
|
1126
|
+
setTitle: async (newTitle) => {
|
|
1127
|
+
await WidgetConfigRuntime.setTitle(newTitle);
|
|
1128
|
+
setTitle(newTitle);
|
|
1129
|
+
},
|
|
1130
|
+
filters,
|
|
1131
|
+
timeRange,
|
|
1132
|
+
isEditMode: edit,
|
|
1133
|
+
}), [data, dataVersion, title, filters, timeRange, edit]);
|
|
1134
|
+
return result;
|
|
1135
|
+
};
|
|
1136
|
+
|
|
1137
|
+
export { AnalyticsContext, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, CurrentUserPreferenceProvider, CurrentUserProvider, EnvironmentContextProvider, ErrorHandlingContext, ErrorHandlingContextProvider, FilterBarProvider, ModalDialogContextProvider, NavigationContextProvider, OemBrandingContextProvider, TimeRangeProvider, ToastProvider, TokenProvider, UserSubscriptionProvider, WidgetConfigProvider, fetchAssetBlobUrl, useAnalytics, useAssetRuntime, useAssetSorting, useConfirmationDialog, useCurrentUser, useCurrentUserLanguage, useCurrentUserSystemOfMeasurement, useCurrentUserTimeZonePreference, useCustomerRuntime, useEnvironment, useErrorHandler, useEventRuntime, useFeatureBranchQueryString, useFilterBarContext, useHasAccessTo, useImageUploader, useIrisAppId, useIrisAppImage, useIrisAppName, useLocalStorage, useLocalStorageReducer, useModalDialogContext, useNavigateInHost, useOemBrandingContext, usePrevious, useSiteRuntime, useTextSearch, useTimeRange, useToast, useToken, useUserSubscription, useWidgetConfig, useWidgetConfigAsync };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-core-hooks",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.81",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -10,9 +10,10 @@
|
|
|
10
10
|
"react": "19.0.0",
|
|
11
11
|
"jest-fetch-mock": "^3.0.3",
|
|
12
12
|
"zod": "3.22.4",
|
|
13
|
-
"@trackunit/react-core-contexts-api": "1.4.
|
|
14
|
-
"@trackunit/iris-app-runtime-core": "1.4.
|
|
15
|
-
"@trackunit/shared-utils": "1.5.
|
|
13
|
+
"@trackunit/react-core-contexts-api": "1.4.79",
|
|
14
|
+
"@trackunit/iris-app-runtime-core": "1.4.80",
|
|
15
|
+
"@trackunit/shared-utils": "1.5.76",
|
|
16
|
+
"@tanstack/react-router": "1.114.29"
|
|
16
17
|
},
|
|
17
18
|
"module": "./index.esm.js",
|
|
18
19
|
"main": "./index.cjs.js",
|
package/src/index.d.ts
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { WidgetConfigRuntime } from "@trackunit/iris-app-runtime-core";
|
|
2
|
+
import { WidgetConfigContext as WidgetConfigContextType } from "@trackunit/react-core-contexts-api";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
/**
|
|
5
|
+
* This is a hook to use the WidgetConfigProvider.
|
|
6
|
+
*
|
|
7
|
+
* @requires WidgetConfigProvider
|
|
8
|
+
* @example
|
|
9
|
+
* import { useWidgetConfigAsync } from "@trackunit/react-core-hooks";
|
|
10
|
+
*
|
|
11
|
+
* export const useWidgetConfigAsync = () => {
|
|
12
|
+
* const { widgetConfig } = useWidgetConfigAsync();
|
|
13
|
+
*
|
|
14
|
+
* ...
|
|
15
|
+
* };
|
|
16
|
+
* @see {@link WidgetConfigContext}
|
|
17
|
+
*/
|
|
18
|
+
export declare const useWidgetConfigAsync: () => WidgetConfigContextType;
|
|
19
|
+
interface WidgetConfigContextProps {
|
|
20
|
+
value: typeof WidgetConfigRuntime;
|
|
21
|
+
children?: ReactNode;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* This is a provider for the WidgetConfigContext.
|
|
25
|
+
*/
|
|
26
|
+
export declare const WidgetConfigProvider: (props: WidgetConfigContextProps) => import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
/**
|
|
28
|
+
* This is a hook to use the WidgetConfigContext.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* import { useWidgetConfig } from "@trackunit/react-core-hooks";
|
|
32
|
+
*
|
|
33
|
+
* export const useWidgetConfig = () => {
|
|
34
|
+
* const { widgetConfig } = useWidgetConfig();
|
|
35
|
+
*
|
|
36
|
+
* ...
|
|
37
|
+
* };
|
|
38
|
+
* @see {@link WidgetConfigContext}
|
|
39
|
+
*/
|
|
40
|
+
export declare const useWidgetConfig: () => {
|
|
41
|
+
data: Record<string, unknown> | null;
|
|
42
|
+
setData: (newData: Record<string, unknown>, newDataVersion: number) => Promise<void>;
|
|
43
|
+
dataVersion: number | null;
|
|
44
|
+
title: string | null;
|
|
45
|
+
setTitle: (newTitle: string) => Promise<void>;
|
|
46
|
+
filters: import("@trackunit/react-core-contexts-api").FilterBarContext;
|
|
47
|
+
timeRange: import("@trackunit/react-core-contexts-api").TimeRange | null;
|
|
48
|
+
isEditMode: any;
|
|
49
|
+
};
|
|
50
|
+
export {};
|