@trackunit/react-core-hooks 1.0.7 → 1.0.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 +76 -95
- package/index.esm.js +13 -14
- package/package.json +4 -4
- package/src/confirmationDialog/ConfirmationDialogProvider.d.ts +2 -2
- package/src/filter-bar/FilterBarProvider.d.ts +2 -2
- package/src/modalDialog/ModalDialogProvider.d.ts +2 -2
- package/src/subscription/UserSubscriptionProvider.d.ts +2 -2
- package/src/toast/ToastProvider.d.ts +2 -2
- package/src/token/TokenProvider.d.ts +2 -2
package/index.cjs.js
CHANGED
|
@@ -1,30 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
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
7
|
|
|
8
|
-
|
|
9
|
-
var n = Object.create(null);
|
|
10
|
-
if (e) {
|
|
11
|
-
Object.keys(e).forEach(function (k) {
|
|
12
|
-
if (k !== 'default') {
|
|
13
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function () { return e[k]; }
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
n.default = e;
|
|
22
|
-
return Object.freeze(n);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
26
|
-
|
|
27
|
-
const AnalyticsContext = React.createContext(null);
|
|
8
|
+
const AnalyticsContext = react.createContext(null);
|
|
28
9
|
const AnalyticsContextProvider = AnalyticsContext.Provider; // easy import
|
|
29
10
|
/**
|
|
30
11
|
* Hook to get the analytics context.
|
|
@@ -43,12 +24,12 @@ const AnalyticsContextProvider = AnalyticsContext.Provider; // easy import
|
|
|
43
24
|
* @see {@link IAnalyticsContext}
|
|
44
25
|
*/
|
|
45
26
|
const useAnalytics = (events) => {
|
|
46
|
-
const context =
|
|
27
|
+
const context = react.useContext(AnalyticsContext);
|
|
47
28
|
if (!context) {
|
|
48
29
|
throw new Error("useAnalytics must be used within an AnalyticsProvider");
|
|
49
30
|
}
|
|
50
|
-
const logEvent =
|
|
51
|
-
return
|
|
31
|
+
const logEvent = react.useMemo(() => logEventWithDescription(context.logEvent, events), [context.logEvent, events]);
|
|
32
|
+
return react.useMemo(() => {
|
|
52
33
|
return {
|
|
53
34
|
...context,
|
|
54
35
|
logEvent,
|
|
@@ -74,7 +55,7 @@ const logEventWithDescription = (logEvent, events) => {
|
|
|
74
55
|
};
|
|
75
56
|
};
|
|
76
57
|
|
|
77
|
-
const AssetSortingContext =
|
|
58
|
+
const AssetSortingContext = react.createContext(null);
|
|
78
59
|
/**
|
|
79
60
|
* This is a provider for the AssetSortingContext.
|
|
80
61
|
*/
|
|
@@ -108,14 +89,14 @@ const AssetSortingProvider = AssetSortingContext.Provider;
|
|
|
108
89
|
* @see {@link AssetSortingContextValue}
|
|
109
90
|
*/
|
|
110
91
|
const useAssetSorting = () => {
|
|
111
|
-
const context =
|
|
92
|
+
const context = react.useContext(AssetSortingContext);
|
|
112
93
|
if (!context) {
|
|
113
94
|
throw new Error("useAssetSorting must be used within a AssetSortingProvider");
|
|
114
95
|
}
|
|
115
96
|
return context;
|
|
116
97
|
};
|
|
117
98
|
|
|
118
|
-
const ConfirmationDialogContext =
|
|
99
|
+
const ConfirmationDialogContext = react.createContext(null);
|
|
119
100
|
/**
|
|
120
101
|
* This is a provider for the ConfirmationDialogContext.
|
|
121
102
|
*/
|
|
@@ -124,14 +105,14 @@ const ConfirmationDialogProvider = (props) => (jsxRuntime.jsx(ConfirmationDialog
|
|
|
124
105
|
* This is a hook to use the ConfirmationDialogContext.
|
|
125
106
|
*/
|
|
126
107
|
const useConfirmationDialog = () => {
|
|
127
|
-
const confirmationDialogContext =
|
|
108
|
+
const confirmationDialogContext = react.useContext(ConfirmationDialogContext);
|
|
128
109
|
if (!confirmationDialogContext) {
|
|
129
110
|
throw new Error("useConfirmationDialog must be used within the ConfirmationDialogProvider");
|
|
130
111
|
}
|
|
131
112
|
return confirmationDialogContext;
|
|
132
113
|
};
|
|
133
114
|
|
|
134
|
-
const EnvironmentContext =
|
|
115
|
+
const EnvironmentContext = react.createContext(null);
|
|
135
116
|
/**
|
|
136
117
|
* This is a provider for the EnvironmentContext.
|
|
137
118
|
*/
|
|
@@ -149,14 +130,14 @@ const EnvironmentContextProvider = (props) => {
|
|
|
149
130
|
* @see (@link IEnvironmentContext)
|
|
150
131
|
*/
|
|
151
132
|
const useEnvironment = () => {
|
|
152
|
-
const context =
|
|
133
|
+
const context = react.useContext(EnvironmentContext);
|
|
153
134
|
if (!context) {
|
|
154
135
|
throw new Error("useEnvironment must be used within an EnvironmentContext");
|
|
155
136
|
}
|
|
156
137
|
return context;
|
|
157
138
|
};
|
|
158
139
|
|
|
159
|
-
const ErrorHandlingContext =
|
|
140
|
+
const ErrorHandlingContext = react.createContext(null);
|
|
160
141
|
const ErrorHandlingContextProvider = ErrorHandlingContext.Provider; // easy import
|
|
161
142
|
/**
|
|
162
143
|
* Hook to get the error handling context.
|
|
@@ -172,7 +153,7 @@ const ErrorHandlingContextProvider = ErrorHandlingContext.Provider; // easy impo
|
|
|
172
153
|
* @see {@link ErrorHandlingContext}
|
|
173
154
|
*/
|
|
174
155
|
const useErrorHandler = () => {
|
|
175
|
-
const context =
|
|
156
|
+
const context = react.useContext(ErrorHandlingContext);
|
|
176
157
|
if (!context) {
|
|
177
158
|
throw new Error("useErrorHandler must be used within an ErrorHandlingContextProvider");
|
|
178
159
|
}
|
|
@@ -198,7 +179,7 @@ const fetchAssetBlobUrl = async (fullUrl, headers) => {
|
|
|
198
179
|
}
|
|
199
180
|
};
|
|
200
181
|
|
|
201
|
-
const FilterBarContext =
|
|
182
|
+
const FilterBarContext = react.createContext(null);
|
|
202
183
|
/**
|
|
203
184
|
* This is a hook to use the FilterBarProvider.
|
|
204
185
|
*
|
|
@@ -214,7 +195,7 @@ const FilterBarContext = React__namespace.createContext(null);
|
|
|
214
195
|
* @see {@link IFilterBarContext}
|
|
215
196
|
*/
|
|
216
197
|
const useFilterBarContext = () => {
|
|
217
|
-
const context =
|
|
198
|
+
const context = react.useContext(FilterBarContext);
|
|
218
199
|
if (!context) {
|
|
219
200
|
throw new Error("useFilterBar must be used within the FilterBarContext");
|
|
220
201
|
}
|
|
@@ -225,7 +206,7 @@ const useFilterBarContext = () => {
|
|
|
225
206
|
*/
|
|
226
207
|
const FilterBarProvider = (props) => jsxRuntime.jsx(FilterBarContext.Provider, { ...props });
|
|
227
208
|
|
|
228
|
-
const TokenContext =
|
|
209
|
+
const TokenContext = react.createContext(null);
|
|
229
210
|
/**
|
|
230
211
|
* This is a hook to use the TokenContext.
|
|
231
212
|
*
|
|
@@ -236,7 +217,7 @@ const TokenContext = React__namespace.createContext(null);
|
|
|
236
217
|
* @see {@link ITokenContext}
|
|
237
218
|
*/
|
|
238
219
|
const useToken = () => {
|
|
239
|
-
const context =
|
|
220
|
+
const context = react.useContext(TokenContext);
|
|
240
221
|
if (!context) {
|
|
241
222
|
throw new Error("useToken must be used within the TokenContext");
|
|
242
223
|
}
|
|
@@ -277,8 +258,8 @@ const base64ToBlob = (base64, contentType = "") => {
|
|
|
277
258
|
*/
|
|
278
259
|
const useImageUploader = () => {
|
|
279
260
|
const { token } = useToken();
|
|
280
|
-
const [loading, setLoading] =
|
|
281
|
-
const uploadImage =
|
|
261
|
+
const [loading, setLoading] = react.useState(false);
|
|
262
|
+
const uploadImage = react.useCallback(({ postUrl, base64Image, type, authorize, }) => {
|
|
282
263
|
setLoading(true);
|
|
283
264
|
return new Promise((resolve, reject) => {
|
|
284
265
|
const formData = new FormData();
|
|
@@ -315,7 +296,7 @@ const useImageUploader = () => {
|
|
|
315
296
|
*/
|
|
316
297
|
const useFeatureBranchQueryString = () => {
|
|
317
298
|
const { publicUrl, buildVersion, isFeatureBranch } = useEnvironment();
|
|
318
|
-
const featureBranchQueryParam =
|
|
299
|
+
const featureBranchQueryParam = react.useMemo(() => (!publicUrl || !isFeatureBranch ? "" : `?fb_url=${encodeURIComponent(publicUrl)}&fb_version=${buildVersion}`), [publicUrl, buildVersion, isFeatureBranch]);
|
|
319
300
|
return { featureBranchQueryParam };
|
|
320
301
|
};
|
|
321
302
|
|
|
@@ -335,7 +316,7 @@ const useIrisAppImage = () => {
|
|
|
335
316
|
const { featureBranchQueryParam } = useFeatureBranchQueryString();
|
|
336
317
|
const { token } = useToken();
|
|
337
318
|
// Add Auth headers to all fetch requests
|
|
338
|
-
const headers =
|
|
319
|
+
const headers = react.useMemo(() => ({
|
|
339
320
|
...tracingHeaders,
|
|
340
321
|
"commit-number": `${tracingHeaders["commit-number"]}`,
|
|
341
322
|
"Content-Type": "application/json",
|
|
@@ -346,7 +327,7 @@ const useIrisAppImage = () => {
|
|
|
346
327
|
* If the APP is served from localhost or a Feature Branch, the URL will be part of the App Entry.
|
|
347
328
|
* In that case, do not use this function, but use the url from the App Entry instead.
|
|
348
329
|
*/
|
|
349
|
-
const getAppUrl =
|
|
330
|
+
const getAppUrl = react.useCallback(({ irisAppId, version }) => {
|
|
350
331
|
return `${irisAppSdkServerUrl}app/${irisAppId}@${version}/`;
|
|
351
332
|
}, [irisAppSdkServerUrl]);
|
|
352
333
|
/**
|
|
@@ -355,7 +336,7 @@ const useIrisAppImage = () => {
|
|
|
355
336
|
* If the APP is served from localhost or a Feature Branch, the URLs will be part of the App Entry.
|
|
356
337
|
* If the url does not exist in the App Entry, use the getIrisAppUrl function to get the URL.
|
|
357
338
|
*/
|
|
358
|
-
const getAppImage =
|
|
339
|
+
const getAppImage = react.useCallback(async ({ irisAppUrl, logoPath }) => {
|
|
359
340
|
if (!logoPath) {
|
|
360
341
|
return null;
|
|
361
342
|
}
|
|
@@ -369,7 +350,7 @@ const useIrisAppImage = () => {
|
|
|
369
350
|
};
|
|
370
351
|
};
|
|
371
352
|
|
|
372
|
-
const OEMBrandingService =
|
|
353
|
+
const OEMBrandingService = react.createContext(null);
|
|
373
354
|
/**
|
|
374
355
|
* This is a hook to use the OemBrandingContext.
|
|
375
356
|
*
|
|
@@ -382,7 +363,7 @@ const OEMBrandingService = React.createContext(null);
|
|
|
382
363
|
* @see {@link OemBrandingContext}
|
|
383
364
|
*/
|
|
384
365
|
const useOemBrandingContext = () => {
|
|
385
|
-
const context =
|
|
366
|
+
const context = react.useContext(OEMBrandingService);
|
|
386
367
|
if (!context) {
|
|
387
368
|
throw new Error("useOemBranding must be used within an OemBrandingContextProvider");
|
|
388
369
|
}
|
|
@@ -395,7 +376,7 @@ const OemBrandingContextProvider = (props) => {
|
|
|
395
376
|
return jsxRuntime.jsx(OEMBrandingService.Provider, { ...props });
|
|
396
377
|
};
|
|
397
378
|
|
|
398
|
-
const ModalDialogContext =
|
|
379
|
+
const ModalDialogContext = react.createContext(null);
|
|
399
380
|
/**
|
|
400
381
|
* This is a provider for the ModalDialogContext.
|
|
401
382
|
*/
|
|
@@ -404,14 +385,14 @@ const ModalDialogContextProvider = (props) => (jsxRuntime.jsx(ModalDialogContext
|
|
|
404
385
|
* This is a hook to use the useModalDialogContext.
|
|
405
386
|
*/
|
|
406
387
|
const useModalDialogContext = () => {
|
|
407
|
-
const modalDialogContext =
|
|
388
|
+
const modalDialogContext = react.useContext(ModalDialogContext);
|
|
408
389
|
if (!modalDialogContext) {
|
|
409
390
|
throw new Error("useModalDialogContext must be used within the ModalDialogContextProvider");
|
|
410
391
|
}
|
|
411
392
|
return modalDialogContext;
|
|
412
393
|
};
|
|
413
394
|
|
|
414
|
-
const NavigationContext =
|
|
395
|
+
const NavigationContext = react.createContext(null);
|
|
415
396
|
/**
|
|
416
397
|
* This is a provider for the NavigationContext.
|
|
417
398
|
*/
|
|
@@ -427,7 +408,7 @@ const NavigationContextProvider = (props) => {
|
|
|
427
408
|
* @see (@link INavigationContext)
|
|
428
409
|
*/
|
|
429
410
|
const useNavigateInHost = () => {
|
|
430
|
-
const context =
|
|
411
|
+
const context = react.useContext(NavigationContext);
|
|
431
412
|
if (!context) {
|
|
432
413
|
throw new Error("useNavigateInHost must be used within an NavigationContext");
|
|
433
414
|
}
|
|
@@ -449,12 +430,12 @@ const useNavigateInHost = () => {
|
|
|
449
430
|
* @see (@link INavigationContext)
|
|
450
431
|
*/
|
|
451
432
|
const useHasAccessTo = (options) => {
|
|
452
|
-
const context =
|
|
433
|
+
const context = react.useContext(NavigationContext);
|
|
453
434
|
if (!context) {
|
|
454
435
|
throw new Error("useHasAccessTo must be used within an NavigationContext");
|
|
455
436
|
}
|
|
456
|
-
const [hasAccess, setHasAccess] =
|
|
457
|
-
|
|
437
|
+
const [hasAccess, setHasAccess] = react.useState();
|
|
438
|
+
react.useEffect(() => {
|
|
458
439
|
async function checkAccess() {
|
|
459
440
|
if (options.assetId) {
|
|
460
441
|
const doHaveAccess = await context?.hasAccessTo(options);
|
|
@@ -483,10 +464,10 @@ const useHasAccessTo = (options) => {
|
|
|
483
464
|
* }, [assetInfo, getAssetLocation]);
|
|
484
465
|
*/
|
|
485
466
|
const useAssetRuntime = () => {
|
|
486
|
-
const [assetInfo, setAssetInfo] =
|
|
487
|
-
const [loading, setLoading] =
|
|
488
|
-
const [error, setError] =
|
|
489
|
-
|
|
467
|
+
const [assetInfo, setAssetInfo] = react.useState();
|
|
468
|
+
const [loading, setLoading] = react.useState(true);
|
|
469
|
+
const [error, setError] = react.useState();
|
|
470
|
+
react.useEffect(() => {
|
|
490
471
|
const getAssetInfo = async () => {
|
|
491
472
|
setLoading(true);
|
|
492
473
|
try {
|
|
@@ -522,10 +503,10 @@ const useAssetRuntime = () => {
|
|
|
522
503
|
* }, [customerInfo]);
|
|
523
504
|
*/
|
|
524
505
|
const useCustomerRuntime = () => {
|
|
525
|
-
const [customerInfo, setCustomerInfo] =
|
|
526
|
-
const [loading, setLoading] =
|
|
527
|
-
const [error, setError] =
|
|
528
|
-
|
|
506
|
+
const [customerInfo, setCustomerInfo] = react.useState();
|
|
507
|
+
const [loading, setLoading] = react.useState(true);
|
|
508
|
+
const [error, setError] = react.useState();
|
|
509
|
+
react.useEffect(() => {
|
|
529
510
|
const getCustomerInfo = async () => {
|
|
530
511
|
setLoading(true);
|
|
531
512
|
try {
|
|
@@ -561,10 +542,10 @@ const useCustomerRuntime = () => {
|
|
|
561
542
|
* }, [getEventQuery, eventInfo]);
|
|
562
543
|
*/
|
|
563
544
|
const useEventRuntime = () => {
|
|
564
|
-
const [eventInfo, setEventInfo] =
|
|
565
|
-
const [loading, setLoading] =
|
|
566
|
-
const [error, setError] =
|
|
567
|
-
|
|
545
|
+
const [eventInfo, setEventInfo] = react.useState();
|
|
546
|
+
const [loading, setLoading] = react.useState(true);
|
|
547
|
+
const [error, setError] = react.useState();
|
|
548
|
+
react.useEffect(() => {
|
|
568
549
|
const getEventInfo = async () => {
|
|
569
550
|
setLoading(true);
|
|
570
551
|
try {
|
|
@@ -599,10 +580,10 @@ const useEventRuntime = () => {
|
|
|
599
580
|
* }, [appName]);
|
|
600
581
|
*/
|
|
601
582
|
const useIrisAppName = () => {
|
|
602
|
-
const [appName, setAppName] =
|
|
603
|
-
const [loading, setLoading] =
|
|
604
|
-
const [error, setError] =
|
|
605
|
-
|
|
583
|
+
const [appName, setAppName] = react.useState();
|
|
584
|
+
const [loading, setLoading] = react.useState(true);
|
|
585
|
+
const [error, setError] = react.useState();
|
|
586
|
+
react.useEffect(() => {
|
|
606
587
|
const getAppName = async () => {
|
|
607
588
|
setLoading(true);
|
|
608
589
|
try {
|
|
@@ -636,10 +617,10 @@ const useIrisAppName = () => {
|
|
|
636
617
|
* }, [irisAppId]);
|
|
637
618
|
*/
|
|
638
619
|
const useIrisAppId = () => {
|
|
639
|
-
const [irisAppId, setIrisAppId] =
|
|
640
|
-
const [loading, setLoading] =
|
|
641
|
-
const [error, setError] =
|
|
642
|
-
|
|
620
|
+
const [irisAppId, setIrisAppId] = react.useState();
|
|
621
|
+
const [loading, setLoading] = react.useState(true);
|
|
622
|
+
const [error, setError] = react.useState();
|
|
623
|
+
react.useEffect(() => {
|
|
643
624
|
const getAppName = async () => {
|
|
644
625
|
setLoading(true);
|
|
645
626
|
try {
|
|
@@ -676,10 +657,10 @@ const useIrisAppId = () => {
|
|
|
676
657
|
* }, [getSiteAssets, siteInfo]);
|
|
677
658
|
*/
|
|
678
659
|
const useSiteRuntime = () => {
|
|
679
|
-
const [siteInfo, setSiteInfo] =
|
|
680
|
-
const [loading, setLoading] =
|
|
681
|
-
const [error, setError] =
|
|
682
|
-
|
|
660
|
+
const [siteInfo, setSiteInfo] = react.useState();
|
|
661
|
+
const [loading, setLoading] = react.useState(true);
|
|
662
|
+
const [error, setError] = react.useState();
|
|
663
|
+
react.useEffect(() => {
|
|
683
664
|
const getSiteInfo = async () => {
|
|
684
665
|
setLoading(true);
|
|
685
666
|
try {
|
|
@@ -697,7 +678,7 @@ const useSiteRuntime = () => {
|
|
|
697
678
|
return { siteInfo, loading, error };
|
|
698
679
|
};
|
|
699
680
|
|
|
700
|
-
const UserSubscriptionContext =
|
|
681
|
+
const UserSubscriptionContext = react.createContext(null);
|
|
701
682
|
/**
|
|
702
683
|
* This is a provider for the UserSubscriptionContext.
|
|
703
684
|
*/
|
|
@@ -716,14 +697,14 @@ const UserSubscriptionProvider = (props) => {
|
|
|
716
697
|
* @see {@link IUserSubscriptionContext}
|
|
717
698
|
*/
|
|
718
699
|
const useUserSubscription = () => {
|
|
719
|
-
const context =
|
|
700
|
+
const context = react.useContext(UserSubscriptionContext);
|
|
720
701
|
if (!context) {
|
|
721
702
|
throw new Error("Cannot use useUserSubscription outside UserSubscriptionProvider");
|
|
722
703
|
}
|
|
723
704
|
return context;
|
|
724
705
|
};
|
|
725
706
|
|
|
726
|
-
const ToastContext =
|
|
707
|
+
const ToastContext = react.createContext(null);
|
|
727
708
|
/**
|
|
728
709
|
* This is a provider for the ToastContext.
|
|
729
710
|
*/
|
|
@@ -746,7 +727,7 @@ const ToastProvider = (props) => jsxRuntime.jsx(ToastContext.Provider, { ...prop
|
|
|
746
727
|
* @see {@link IToastContext}
|
|
747
728
|
*/
|
|
748
729
|
const useToast = () => {
|
|
749
|
-
const toastContext =
|
|
730
|
+
const toastContext = react.useContext(ToastContext);
|
|
750
731
|
if (!toastContext) {
|
|
751
732
|
throw new Error("useToast must be used within the ToastProvider");
|
|
752
733
|
}
|
|
@@ -763,8 +744,8 @@ const useToast = () => {
|
|
|
763
744
|
* const [result, searchText, setSearchText] = useTextSearch(items, item => [item.name, item.description]);
|
|
764
745
|
*/
|
|
765
746
|
function useTextSearch(items, props) {
|
|
766
|
-
const [searchText, setSearchText] =
|
|
767
|
-
const result =
|
|
747
|
+
const [searchText, setSearchText] = react.useState("");
|
|
748
|
+
const result = react.useMemo(() => {
|
|
768
749
|
if (!searchText) {
|
|
769
750
|
return items;
|
|
770
751
|
}
|
|
@@ -773,7 +754,7 @@ function useTextSearch(items, props) {
|
|
|
773
754
|
return [result, searchText, setSearchText];
|
|
774
755
|
}
|
|
775
756
|
|
|
776
|
-
const CurrentUserPreferenceContext =
|
|
757
|
+
const CurrentUserPreferenceContext = react.createContext(null);
|
|
777
758
|
/**
|
|
778
759
|
*
|
|
779
760
|
*/
|
|
@@ -793,11 +774,11 @@ const CurrentUserPreferenceProvider = (props) => {
|
|
|
793
774
|
* @see {@link IUserPreferencesContext}
|
|
794
775
|
*/
|
|
795
776
|
const useCurrentUserLanguage = () => {
|
|
796
|
-
const context =
|
|
777
|
+
const context = react.useContext(CurrentUserPreferenceContext);
|
|
797
778
|
if (!context) {
|
|
798
779
|
throw new Error("useCurrentUserLanguage must be used within the CurrentUserPreferenceProvider");
|
|
799
780
|
}
|
|
800
|
-
return
|
|
781
|
+
return react.useMemo(() => {
|
|
801
782
|
// This is there to make sure that the language is set on the global object so Graphql can use it.
|
|
802
783
|
global.language = context.language;
|
|
803
784
|
return {
|
|
@@ -819,11 +800,11 @@ const useCurrentUserLanguage = () => {
|
|
|
819
800
|
* @see {@link IUserPreferencesContext}
|
|
820
801
|
*/
|
|
821
802
|
const useCurrentUserTimeZonePreference = () => {
|
|
822
|
-
const context =
|
|
803
|
+
const context = react.useContext(CurrentUserPreferenceContext);
|
|
823
804
|
if (!context) {
|
|
824
805
|
throw new Error("useCurrentUserTimeZone must be used within the CurrentUserPreferenceProvider");
|
|
825
806
|
}
|
|
826
|
-
return
|
|
807
|
+
return react.useMemo(() => {
|
|
827
808
|
return {
|
|
828
809
|
timeZonePreference: context.timeZonePreference,
|
|
829
810
|
setTimeZonePreference: context.setTimeZonePreference,
|
|
@@ -843,11 +824,11 @@ const useCurrentUserTimeZonePreference = () => {
|
|
|
843
824
|
* @see {@link IUserPreferencesContext}
|
|
844
825
|
*/
|
|
845
826
|
const useCurrentUserSystemOfMeasurement = () => {
|
|
846
|
-
const context =
|
|
827
|
+
const context = react.useContext(CurrentUserPreferenceContext);
|
|
847
828
|
if (!context) {
|
|
848
829
|
throw new Error("useCurrentUserSystemOfMeasurement must be used within the CurrentUserPreferenceProvider");
|
|
849
830
|
}
|
|
850
|
-
return
|
|
831
|
+
return react.useMemo(() => {
|
|
851
832
|
return {
|
|
852
833
|
systemOfMeasurement: context.systemOfMeasurement || null,
|
|
853
834
|
setSystemOfMeasurement: context.setSystemOfMeasurement,
|
|
@@ -855,7 +836,7 @@ const useCurrentUserSystemOfMeasurement = () => {
|
|
|
855
836
|
}, [context.systemOfMeasurement, context.setSystemOfMeasurement]);
|
|
856
837
|
};
|
|
857
838
|
|
|
858
|
-
const CurrentUserContext =
|
|
839
|
+
const CurrentUserContext = react.createContext(null);
|
|
859
840
|
/**
|
|
860
841
|
* This is a provider for the CurrentUserContext.
|
|
861
842
|
*/
|
|
@@ -877,7 +858,7 @@ const CurrentUserProvider = (props) => {
|
|
|
877
858
|
* @see {@link ICurrentUserContext}
|
|
878
859
|
*/
|
|
879
860
|
const useCurrentUser = () => {
|
|
880
|
-
const context =
|
|
861
|
+
const context = react.useContext(CurrentUserContext);
|
|
881
862
|
if (!context) {
|
|
882
863
|
throw new Error("useCurrentUser must be used within the CurrentUserProvider");
|
|
883
864
|
}
|
|
@@ -931,8 +912,8 @@ const initLocalStorageState = ({ key, defaultState, schema, }) => {
|
|
|
931
912
|
const previousColor = usePrevious(color);
|
|
932
913
|
*/
|
|
933
914
|
const usePrevious = (value) => {
|
|
934
|
-
const ref =
|
|
935
|
-
|
|
915
|
+
const ref = react.useRef();
|
|
916
|
+
react.useEffect(() => {
|
|
936
917
|
ref.current = value;
|
|
937
918
|
}, [value]);
|
|
938
919
|
return ref.current;
|
|
@@ -961,7 +942,7 @@ const setLocalStorage = (key, value) => {
|
|
|
961
942
|
*/
|
|
962
943
|
const useLocalStorageEffect = ({ key, state, defaultState, schema, onValidationFailed, onValidationSuccessful, }) => {
|
|
963
944
|
const prevState = usePrevious(state);
|
|
964
|
-
|
|
945
|
+
react.useEffect(() => {
|
|
965
946
|
if (JSON.stringify(prevState) === JSON.stringify(state)) {
|
|
966
947
|
return;
|
|
967
948
|
}
|
|
@@ -1000,7 +981,7 @@ const useLocalStorage = ({ key, defaultState, schema, onValidationFailed, onVali
|
|
|
1000
981
|
if (!key) {
|
|
1001
982
|
throw new Error("useLocalStorage key may not be falsy");
|
|
1002
983
|
}
|
|
1003
|
-
const [state, setState] =
|
|
984
|
+
const [state, setState] = react.useState(initLocalStorageState({ key, defaultState, schema }));
|
|
1004
985
|
useLocalStorageEffect({
|
|
1005
986
|
key,
|
|
1006
987
|
state,
|
|
@@ -1027,7 +1008,7 @@ const useLocalStorageReducer = ({ key, defaultState, reducer, schema, onValidati
|
|
|
1027
1008
|
if (!key) {
|
|
1028
1009
|
throw new Error("useLocalStorage key may not be falsy");
|
|
1029
1010
|
}
|
|
1030
|
-
const [state, dispatch] =
|
|
1011
|
+
const [state, dispatch] = react.useReducer(reducer, defaultState, () => initLocalStorageState({ key, defaultState, schema }));
|
|
1031
1012
|
useLocalStorageEffect({ key, state, defaultState, schema, onValidationFailed, onValidationSuccessful });
|
|
1032
1013
|
return [state, dispatch];
|
|
1033
1014
|
};
|
package/index.esm.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
1
|
import { createContext, useContext, useMemo, useState, useCallback, useEffect, useRef, useReducer } from 'react';
|
|
3
2
|
import { jsx } from 'react/jsx-runtime';
|
|
4
3
|
import { AssetRuntime, CustomerRuntime, EventRuntime, ParamsRuntime, SiteRuntime } from '@trackunit/iris-app-runtime-core';
|
|
@@ -95,7 +94,7 @@ const useAssetSorting = () => {
|
|
|
95
94
|
return context;
|
|
96
95
|
};
|
|
97
96
|
|
|
98
|
-
const ConfirmationDialogContext =
|
|
97
|
+
const ConfirmationDialogContext = createContext(null);
|
|
99
98
|
/**
|
|
100
99
|
* This is a provider for the ConfirmationDialogContext.
|
|
101
100
|
*/
|
|
@@ -104,7 +103,7 @@ const ConfirmationDialogProvider = (props) => (jsx(ConfirmationDialogContext.Pro
|
|
|
104
103
|
* This is a hook to use the ConfirmationDialogContext.
|
|
105
104
|
*/
|
|
106
105
|
const useConfirmationDialog = () => {
|
|
107
|
-
const confirmationDialogContext =
|
|
106
|
+
const confirmationDialogContext = useContext(ConfirmationDialogContext);
|
|
108
107
|
if (!confirmationDialogContext) {
|
|
109
108
|
throw new Error("useConfirmationDialog must be used within the ConfirmationDialogProvider");
|
|
110
109
|
}
|
|
@@ -178,7 +177,7 @@ const fetchAssetBlobUrl = async (fullUrl, headers) => {
|
|
|
178
177
|
}
|
|
179
178
|
};
|
|
180
179
|
|
|
181
|
-
const FilterBarContext =
|
|
180
|
+
const FilterBarContext = createContext(null);
|
|
182
181
|
/**
|
|
183
182
|
* This is a hook to use the FilterBarProvider.
|
|
184
183
|
*
|
|
@@ -194,7 +193,7 @@ const FilterBarContext = React.createContext(null);
|
|
|
194
193
|
* @see {@link IFilterBarContext}
|
|
195
194
|
*/
|
|
196
195
|
const useFilterBarContext = () => {
|
|
197
|
-
const context =
|
|
196
|
+
const context = useContext(FilterBarContext);
|
|
198
197
|
if (!context) {
|
|
199
198
|
throw new Error("useFilterBar must be used within the FilterBarContext");
|
|
200
199
|
}
|
|
@@ -205,7 +204,7 @@ const useFilterBarContext = () => {
|
|
|
205
204
|
*/
|
|
206
205
|
const FilterBarProvider = (props) => jsx(FilterBarContext.Provider, { ...props });
|
|
207
206
|
|
|
208
|
-
const TokenContext =
|
|
207
|
+
const TokenContext = createContext(null);
|
|
209
208
|
/**
|
|
210
209
|
* This is a hook to use the TokenContext.
|
|
211
210
|
*
|
|
@@ -216,7 +215,7 @@ const TokenContext = React.createContext(null);
|
|
|
216
215
|
* @see {@link ITokenContext}
|
|
217
216
|
*/
|
|
218
217
|
const useToken = () => {
|
|
219
|
-
const context =
|
|
218
|
+
const context = useContext(TokenContext);
|
|
220
219
|
if (!context) {
|
|
221
220
|
throw new Error("useToken must be used within the TokenContext");
|
|
222
221
|
}
|
|
@@ -375,7 +374,7 @@ const OemBrandingContextProvider = (props) => {
|
|
|
375
374
|
return jsx(OEMBrandingService.Provider, { ...props });
|
|
376
375
|
};
|
|
377
376
|
|
|
378
|
-
const ModalDialogContext =
|
|
377
|
+
const ModalDialogContext = createContext(null);
|
|
379
378
|
/**
|
|
380
379
|
* This is a provider for the ModalDialogContext.
|
|
381
380
|
*/
|
|
@@ -384,7 +383,7 @@ const ModalDialogContextProvider = (props) => (jsx(ModalDialogContext.Provider,
|
|
|
384
383
|
* This is a hook to use the useModalDialogContext.
|
|
385
384
|
*/
|
|
386
385
|
const useModalDialogContext = () => {
|
|
387
|
-
const modalDialogContext =
|
|
386
|
+
const modalDialogContext = useContext(ModalDialogContext);
|
|
388
387
|
if (!modalDialogContext) {
|
|
389
388
|
throw new Error("useModalDialogContext must be used within the ModalDialogContextProvider");
|
|
390
389
|
}
|
|
@@ -677,7 +676,7 @@ const useSiteRuntime = () => {
|
|
|
677
676
|
return { siteInfo, loading, error };
|
|
678
677
|
};
|
|
679
678
|
|
|
680
|
-
const UserSubscriptionContext =
|
|
679
|
+
const UserSubscriptionContext = createContext(null);
|
|
681
680
|
/**
|
|
682
681
|
* This is a provider for the UserSubscriptionContext.
|
|
683
682
|
*/
|
|
@@ -696,14 +695,14 @@ const UserSubscriptionProvider = (props) => {
|
|
|
696
695
|
* @see {@link IUserSubscriptionContext}
|
|
697
696
|
*/
|
|
698
697
|
const useUserSubscription = () => {
|
|
699
|
-
const context =
|
|
698
|
+
const context = useContext(UserSubscriptionContext);
|
|
700
699
|
if (!context) {
|
|
701
700
|
throw new Error("Cannot use useUserSubscription outside UserSubscriptionProvider");
|
|
702
701
|
}
|
|
703
702
|
return context;
|
|
704
703
|
};
|
|
705
704
|
|
|
706
|
-
const ToastContext =
|
|
705
|
+
const ToastContext = createContext(null);
|
|
707
706
|
/**
|
|
708
707
|
* This is a provider for the ToastContext.
|
|
709
708
|
*/
|
|
@@ -726,7 +725,7 @@ const ToastProvider = (props) => jsx(ToastContext.Provider, { ...props });
|
|
|
726
725
|
* @see {@link IToastContext}
|
|
727
726
|
*/
|
|
728
727
|
const useToast = () => {
|
|
729
|
-
const toastContext =
|
|
728
|
+
const toastContext = useContext(ToastContext);
|
|
730
729
|
if (!toastContext) {
|
|
731
730
|
throw new Error("useToast must be used within the ToastProvider");
|
|
732
731
|
}
|
|
@@ -857,7 +856,7 @@ const CurrentUserProvider = (props) => {
|
|
|
857
856
|
* @see {@link ICurrentUserContext}
|
|
858
857
|
*/
|
|
859
858
|
const useCurrentUser = () => {
|
|
860
|
-
const context =
|
|
859
|
+
const context = useContext(CurrentUserContext);
|
|
861
860
|
if (!context) {
|
|
862
861
|
throw new Error("useCurrentUser must be used within the CurrentUserProvider");
|
|
863
862
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-core-hooks",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"react": "18.3.1",
|
|
11
11
|
"jest-fetch-mock": "^3.0.3",
|
|
12
12
|
"zod": "3.22.4",
|
|
13
|
-
"@trackunit/react-core-contexts-api": "
|
|
14
|
-
"@trackunit/iris-app-runtime-core": "
|
|
15
|
-
"@trackunit/shared-utils": "
|
|
13
|
+
"@trackunit/react-core-contexts-api": "1.0.10",
|
|
14
|
+
"@trackunit/iris-app-runtime-core": "1.0.10",
|
|
15
|
+
"@trackunit/shared-utils": "1.2.2"
|
|
16
16
|
},
|
|
17
17
|
"module": "./index.esm.js",
|
|
18
18
|
"main": "./index.cjs.js",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ConfirmationDialogContextValue } from "@trackunit/react-core-contexts-api";
|
|
2
|
-
import
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
3
|
export interface ConfirmationDialogContextProviderProps {
|
|
4
4
|
value: ConfirmationDialogContextValue;
|
|
5
|
-
children:
|
|
5
|
+
children: ReactNode;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* This is a provider for the ConfirmationDialogContext.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IFilterBarContext } from "@trackunit/react-core-contexts-api";
|
|
2
|
-
import
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
3
|
/**
|
|
4
4
|
* This is a hook to use the FilterBarProvider.
|
|
5
5
|
*
|
|
@@ -17,7 +17,7 @@ import * as React from "react";
|
|
|
17
17
|
export declare const useFilterBarContext: () => IFilterBarContext;
|
|
18
18
|
interface IProps {
|
|
19
19
|
value: IFilterBarContext;
|
|
20
|
-
children?:
|
|
20
|
+
children?: ReactNode;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* This is a provider for the FilterBarContext.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ModalDialogContextValue } from "@trackunit/react-core-contexts-api";
|
|
2
|
-
import
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
3
|
export interface ModalDialogProviderProps {
|
|
4
4
|
value: ModalDialogContextValue;
|
|
5
|
-
children:
|
|
5
|
+
children: ReactNode;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* This is a provider for the ModalDialogContext.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IUserSubscriptionContext } from "@trackunit/react-core-contexts-api";
|
|
2
|
-
import
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
3
|
interface IProps {
|
|
4
4
|
value: IUserSubscriptionContext;
|
|
5
|
-
children?:
|
|
5
|
+
children?: ReactNode;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* This is a provider for the UserSubscriptionContext.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IToastContext } from "@trackunit/react-core-contexts-api";
|
|
2
|
-
import
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
3
|
export interface ToastContextProviderProps {
|
|
4
4
|
value: IToastContext;
|
|
5
|
-
children:
|
|
5
|
+
children: ReactNode;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* This is a provider for the ToastContext.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ITokenContext } from "@trackunit/react-core-contexts-api";
|
|
2
|
-
import
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
3
|
/**
|
|
4
4
|
* This is a hook to use the TokenContext.
|
|
5
5
|
*
|
|
@@ -12,7 +12,7 @@ import * as React from "react";
|
|
|
12
12
|
export declare const useToken: () => ITokenContext;
|
|
13
13
|
interface IProps {
|
|
14
14
|
value: ITokenContext;
|
|
15
|
-
children?:
|
|
15
|
+
children?: ReactNode;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* This is a provider for the TokenContext.
|