@trackunit/react-core-hooks 1.7.9 → 1.7.10
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 +24 -12
- package/index.esm.js +24 -12
- package/package.json +5 -6
- package/src/widgetConfig/WidgetConfigProvider.d.ts +5 -4
package/index.cjs.js
CHANGED
|
@@ -5,7 +5,6 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
5
5
|
var fflate = require('fflate');
|
|
6
6
|
var irisAppRuntimeCore = require('@trackunit/iris-app-runtime-core');
|
|
7
7
|
var sharedUtils = require('@trackunit/shared-utils');
|
|
8
|
-
var reactRouter = require('@tanstack/react-router');
|
|
9
8
|
|
|
10
9
|
const AnalyticsContext = react.createContext(null);
|
|
11
10
|
const AnalyticsContextProvider = AnalyticsContext.Provider; // easy import
|
|
@@ -1222,48 +1221,61 @@ const WidgetConfigProvider = (props) => jsxRuntime.jsx(WidgetConfigContext.Provi
|
|
|
1222
1221
|
* import { useWidgetConfig } from "@trackunit/react-core-hooks";
|
|
1223
1222
|
*
|
|
1224
1223
|
* export const useWidgetConfig = () => {
|
|
1225
|
-
* const {
|
|
1224
|
+
* const { ... } = useWidgetConfig();
|
|
1226
1225
|
*
|
|
1227
1226
|
* ...
|
|
1228
1227
|
* };
|
|
1229
1228
|
* @see { WidgetConfigContext}
|
|
1230
1229
|
*/
|
|
1231
1230
|
const useWidgetConfig = () => {
|
|
1231
|
+
const widgetConfigContext = useWidgetConfigAsync();
|
|
1232
1232
|
const [data, setData] = react.useState(null);
|
|
1233
1233
|
const [loadingData, setLoadingData] = react.useState(true);
|
|
1234
1234
|
const [dataVersion, setDataVersion] = react.useState(null);
|
|
1235
1235
|
const [title, setTitle] = react.useState(null);
|
|
1236
1236
|
const filters = useFilterBarContext();
|
|
1237
1237
|
const { timeRange } = useTimeRange();
|
|
1238
|
-
|
|
1239
|
-
const edit = react.
|
|
1238
|
+
// use window.location.hash directly to avoid depending on tanstack router in core-hooks
|
|
1239
|
+
const [edit, setEdit] = react.useState(() => window.location.hash.includes("edit=true"));
|
|
1240
1240
|
react.useEffect(() => {
|
|
1241
|
-
|
|
1241
|
+
const handleHashChange = () => {
|
|
1242
|
+
setEdit(window.location.hash.includes("edit=true"));
|
|
1243
|
+
};
|
|
1244
|
+
window.addEventListener("hashchange", handleHashChange);
|
|
1245
|
+
return () => window.removeEventListener("hashchange", handleHashChange);
|
|
1246
|
+
}, []);
|
|
1247
|
+
const widgetConfigContextRef = react.useRef(widgetConfigContext);
|
|
1248
|
+
react.useEffect(() => {
|
|
1249
|
+
void widgetConfigContextRef.current.getData().then(d => {
|
|
1242
1250
|
setData(d);
|
|
1243
1251
|
setLoadingData(false);
|
|
1244
1252
|
});
|
|
1245
|
-
|
|
1246
|
-
|
|
1253
|
+
void widgetConfigContextRef.current.getDataVersion().then(dv => setDataVersion(dv));
|
|
1254
|
+
void widgetConfigContextRef.current.getTitle().then(t => setTitle(t));
|
|
1247
1255
|
}, []);
|
|
1248
1256
|
const result = react.useMemo(() => ({
|
|
1249
1257
|
data,
|
|
1250
1258
|
setData: async (newData, newDataVersion) => {
|
|
1251
|
-
await
|
|
1259
|
+
await widgetConfigContext.setData(newData, newDataVersion);
|
|
1252
1260
|
setData(newData);
|
|
1253
1261
|
setDataVersion(newDataVersion);
|
|
1254
1262
|
},
|
|
1255
1263
|
dataVersion,
|
|
1256
1264
|
loadingData,
|
|
1265
|
+
setLoadingState: async (newLoadingState) => {
|
|
1266
|
+
await widgetConfigContext.setLoadingState(newLoadingState);
|
|
1267
|
+
},
|
|
1257
1268
|
title,
|
|
1258
1269
|
setTitle: async (newTitle) => {
|
|
1259
|
-
await
|
|
1270
|
+
await widgetConfigContext.setTitle(newTitle);
|
|
1260
1271
|
setTitle(newTitle);
|
|
1261
1272
|
},
|
|
1262
1273
|
filters,
|
|
1263
1274
|
timeRange,
|
|
1264
1275
|
isEditMode: edit,
|
|
1276
|
+
pollInterval: widgetConfigContext.pollInterval,
|
|
1265
1277
|
openEditMode: async () => {
|
|
1266
|
-
await
|
|
1278
|
+
await widgetConfigContext.openEditMode();
|
|
1267
1279
|
},
|
|
1268
1280
|
closeEditMode: async (props) => {
|
|
1269
1281
|
if (props) {
|
|
@@ -1273,9 +1285,9 @@ const useWidgetConfig = () => {
|
|
|
1273
1285
|
setDataVersion(props.newData.dataVersion ?? 1);
|
|
1274
1286
|
}
|
|
1275
1287
|
}
|
|
1276
|
-
await
|
|
1288
|
+
await widgetConfigContext.closeEditMode();
|
|
1277
1289
|
},
|
|
1278
|
-
}), [data, dataVersion, title, filters, timeRange, edit, loadingData]);
|
|
1290
|
+
}), [data, dataVersion, title, filters, timeRange, edit, loadingData, widgetConfigContext]);
|
|
1279
1291
|
return result;
|
|
1280
1292
|
};
|
|
1281
1293
|
|
package/index.esm.js
CHANGED
|
@@ -3,7 +3,6 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
3
3
|
import { gzipSync, gunzipSync } from 'fflate';
|
|
4
4
|
import { AssetRuntime, CustomerRuntime, EventRuntime, ParamsRuntime, SiteRuntime, WidgetConfigRuntime } from '@trackunit/iris-app-runtime-core';
|
|
5
5
|
import { filterByMultiple } from '@trackunit/shared-utils';
|
|
6
|
-
import { useLocation } from '@tanstack/react-router';
|
|
7
6
|
|
|
8
7
|
const AnalyticsContext = createContext(null);
|
|
9
8
|
const AnalyticsContextProvider = AnalyticsContext.Provider; // easy import
|
|
@@ -1220,48 +1219,61 @@ const WidgetConfigProvider = (props) => jsx(WidgetConfigContext.Provider, { ...p
|
|
|
1220
1219
|
* import { useWidgetConfig } from "@trackunit/react-core-hooks";
|
|
1221
1220
|
*
|
|
1222
1221
|
* export const useWidgetConfig = () => {
|
|
1223
|
-
* const {
|
|
1222
|
+
* const { ... } = useWidgetConfig();
|
|
1224
1223
|
*
|
|
1225
1224
|
* ...
|
|
1226
1225
|
* };
|
|
1227
1226
|
* @see { WidgetConfigContext}
|
|
1228
1227
|
*/
|
|
1229
1228
|
const useWidgetConfig = () => {
|
|
1229
|
+
const widgetConfigContext = useWidgetConfigAsync();
|
|
1230
1230
|
const [data, setData] = useState(null);
|
|
1231
1231
|
const [loadingData, setLoadingData] = useState(true);
|
|
1232
1232
|
const [dataVersion, setDataVersion] = useState(null);
|
|
1233
1233
|
const [title, setTitle] = useState(null);
|
|
1234
1234
|
const filters = useFilterBarContext();
|
|
1235
1235
|
const { timeRange } = useTimeRange();
|
|
1236
|
-
|
|
1237
|
-
const edit =
|
|
1236
|
+
// use window.location.hash directly to avoid depending on tanstack router in core-hooks
|
|
1237
|
+
const [edit, setEdit] = useState(() => window.location.hash.includes("edit=true"));
|
|
1238
1238
|
useEffect(() => {
|
|
1239
|
-
|
|
1239
|
+
const handleHashChange = () => {
|
|
1240
|
+
setEdit(window.location.hash.includes("edit=true"));
|
|
1241
|
+
};
|
|
1242
|
+
window.addEventListener("hashchange", handleHashChange);
|
|
1243
|
+
return () => window.removeEventListener("hashchange", handleHashChange);
|
|
1244
|
+
}, []);
|
|
1245
|
+
const widgetConfigContextRef = useRef(widgetConfigContext);
|
|
1246
|
+
useEffect(() => {
|
|
1247
|
+
void widgetConfigContextRef.current.getData().then(d => {
|
|
1240
1248
|
setData(d);
|
|
1241
1249
|
setLoadingData(false);
|
|
1242
1250
|
});
|
|
1243
|
-
|
|
1244
|
-
|
|
1251
|
+
void widgetConfigContextRef.current.getDataVersion().then(dv => setDataVersion(dv));
|
|
1252
|
+
void widgetConfigContextRef.current.getTitle().then(t => setTitle(t));
|
|
1245
1253
|
}, []);
|
|
1246
1254
|
const result = useMemo(() => ({
|
|
1247
1255
|
data,
|
|
1248
1256
|
setData: async (newData, newDataVersion) => {
|
|
1249
|
-
await
|
|
1257
|
+
await widgetConfigContext.setData(newData, newDataVersion);
|
|
1250
1258
|
setData(newData);
|
|
1251
1259
|
setDataVersion(newDataVersion);
|
|
1252
1260
|
},
|
|
1253
1261
|
dataVersion,
|
|
1254
1262
|
loadingData,
|
|
1263
|
+
setLoadingState: async (newLoadingState) => {
|
|
1264
|
+
await widgetConfigContext.setLoadingState(newLoadingState);
|
|
1265
|
+
},
|
|
1255
1266
|
title,
|
|
1256
1267
|
setTitle: async (newTitle) => {
|
|
1257
|
-
await
|
|
1268
|
+
await widgetConfigContext.setTitle(newTitle);
|
|
1258
1269
|
setTitle(newTitle);
|
|
1259
1270
|
},
|
|
1260
1271
|
filters,
|
|
1261
1272
|
timeRange,
|
|
1262
1273
|
isEditMode: edit,
|
|
1274
|
+
pollInterval: widgetConfigContext.pollInterval,
|
|
1263
1275
|
openEditMode: async () => {
|
|
1264
|
-
await
|
|
1276
|
+
await widgetConfigContext.openEditMode();
|
|
1265
1277
|
},
|
|
1266
1278
|
closeEditMode: async (props) => {
|
|
1267
1279
|
if (props) {
|
|
@@ -1271,9 +1283,9 @@ const useWidgetConfig = () => {
|
|
|
1271
1283
|
setDataVersion(props.newData.dataVersion ?? 1);
|
|
1272
1284
|
}
|
|
1273
1285
|
}
|
|
1274
|
-
await
|
|
1286
|
+
await widgetConfigContext.closeEditMode();
|
|
1275
1287
|
},
|
|
1276
|
-
}), [data, dataVersion, title, filters, timeRange, edit, loadingData]);
|
|
1288
|
+
}), [data, dataVersion, title, filters, timeRange, edit, loadingData, widgetConfigContext]);
|
|
1277
1289
|
return result;
|
|
1278
1290
|
};
|
|
1279
1291
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-core-hooks",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.10",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -10,11 +10,10 @@
|
|
|
10
10
|
"react": "19.0.0",
|
|
11
11
|
"jest-fetch-mock": "^3.0.3",
|
|
12
12
|
"zod": "^3.23.8",
|
|
13
|
-
"@trackunit/react-core-contexts-api": "1.8.
|
|
14
|
-
"@trackunit/iris-app-runtime-core": "1.8.
|
|
15
|
-
"@trackunit/shared-utils": "1.9.
|
|
16
|
-
"@
|
|
17
|
-
"@trackunit/react-test-setup": "1.4.7",
|
|
13
|
+
"@trackunit/react-core-contexts-api": "1.8.10",
|
|
14
|
+
"@trackunit/iris-app-runtime-core": "1.8.10",
|
|
15
|
+
"@trackunit/shared-utils": "1.9.8",
|
|
16
|
+
"@trackunit/react-test-setup": "1.4.8",
|
|
18
17
|
"fflate": "^0.8.2"
|
|
19
18
|
},
|
|
20
19
|
"module": "./index.esm.js",
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { WidgetConfigContext as WidgetConfigContextType } from "@trackunit/react-core-contexts-api";
|
|
1
|
+
import { LoadingState, WidgetConfigContext as WidgetConfigContextType } from "@trackunit/react-core-contexts-api";
|
|
3
2
|
import { ReactNode } from "react";
|
|
4
3
|
/**
|
|
5
4
|
* This is a hook to use the WidgetConfigProvider.
|
|
@@ -17,7 +16,7 @@ import { ReactNode } from "react";
|
|
|
17
16
|
*/
|
|
18
17
|
export declare const useWidgetConfigAsync: () => WidgetConfigContextType;
|
|
19
18
|
interface WidgetConfigContextProps {
|
|
20
|
-
value:
|
|
19
|
+
value: WidgetConfigContextType;
|
|
21
20
|
children?: ReactNode;
|
|
22
21
|
}
|
|
23
22
|
/**
|
|
@@ -31,7 +30,7 @@ export declare const WidgetConfigProvider: (props: WidgetConfigContextProps) =>
|
|
|
31
30
|
* import { useWidgetConfig } from "@trackunit/react-core-hooks";
|
|
32
31
|
*
|
|
33
32
|
* export const useWidgetConfig = () => {
|
|
34
|
-
* const {
|
|
33
|
+
* const { ... } = useWidgetConfig();
|
|
35
34
|
*
|
|
36
35
|
* ...
|
|
37
36
|
* };
|
|
@@ -42,11 +41,13 @@ export declare const useWidgetConfig: () => {
|
|
|
42
41
|
setData: (newData: Record<string, unknown>, newDataVersion: number) => Promise<void>;
|
|
43
42
|
dataVersion: number | null;
|
|
44
43
|
loadingData: boolean;
|
|
44
|
+
setLoadingState: (newLoadingState: LoadingState) => Promise<void>;
|
|
45
45
|
title: string | null;
|
|
46
46
|
setTitle: (newTitle: string) => Promise<void>;
|
|
47
47
|
filters: import("@trackunit/react-core-contexts-api").FilterBarContext;
|
|
48
48
|
timeRange: import("@trackunit/react-core-contexts-api").TimeRange | null;
|
|
49
49
|
isEditMode: boolean;
|
|
50
|
+
pollInterval: number | undefined;
|
|
50
51
|
openEditMode: () => Promise<void>;
|
|
51
52
|
closeEditMode: (props?: {
|
|
52
53
|
newTitle?: string | null;
|