@trackunit/react-core-hooks 1.0.5 → 1.0.9

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
@@ -1,30 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var React = require('react');
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
- function _interopNamespaceDefault(e) {
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 = React.useContext(AnalyticsContext);
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 = React.useMemo(() => logEventWithDescription(context.logEvent, events), [context.logEvent, events]);
51
- return React.useMemo(() => {
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,
@@ -58,8 +39,8 @@ const useAnalytics = (events) => {
58
39
  // Automatically append the description from the event type
59
40
  const logEventWithDescription = (logEvent, events) => {
60
41
  return (eventName, details, nameSupplement) => {
61
- const event = events === null || events === void 0 ? void 0 : events[eventName];
62
- const eventDescription = event === null || event === void 0 ? void 0 : event.description;
42
+ const event = events?.[eventName];
43
+ const eventDescription = event?.description;
63
44
  // Include description in the details object.
64
45
  const detailsWithDescription = {
65
46
  eventDescription,
@@ -74,7 +55,7 @@ const logEventWithDescription = (logEvent, events) => {
74
55
  };
75
56
  };
76
57
 
77
- const AssetSortingContext = React.createContext(null);
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 = React.useContext(AssetSortingContext);
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 = React__namespace.createContext(null);
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 = React__namespace.useContext(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 = React.createContext(null);
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 = React.useContext(EnvironmentContext);
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 = React.createContext(null);
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 = React.useContext(ErrorHandlingContext);
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 = React__namespace.createContext(null);
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 = React__namespace.useContext(FilterBarContext);
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 = React__namespace.createContext(null);
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 = React__namespace.useContext(TokenContext);
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] = React.useState(false);
281
- const uploadImage = React.useCallback(({ postUrl, base64Image, type, authorize, }) => {
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 = React.useMemo(() => (!publicUrl || !isFeatureBranch ? "" : `?fb_url=${encodeURIComponent(publicUrl)}&fb_version=${buildVersion}`), [publicUrl, buildVersion, isFeatureBranch]);
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 = React.useMemo(() => ({
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 = React.useCallback(({ irisAppId, version }) => {
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 = React.useCallback(async ({ irisAppUrl, logoPath }) => {
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 = React.createContext(null);
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 = React.useContext(OEMBrandingService);
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 = React__namespace.createContext(null);
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 = React__namespace.useContext(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 = React.createContext(null);
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 = React.useContext(NavigationContext);
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,15 +430,15 @@ const useNavigateInHost = () => {
449
430
  * @see (@link INavigationContext)
450
431
  */
451
432
  const useHasAccessTo = (options) => {
452
- const context = React.useContext(NavigationContext);
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] = React.useState();
457
- React.useEffect(() => {
437
+ const [hasAccess, setHasAccess] = react.useState();
438
+ react.useEffect(() => {
458
439
  async function checkAccess() {
459
440
  if (options.assetId) {
460
- const doHaveAccess = await (context === null || context === void 0 ? void 0 : context.hasAccessTo(options));
441
+ const doHaveAccess = await context?.hasAccessTo(options);
461
442
  setHasAccess(() => doHaveAccess);
462
443
  }
463
444
  }
@@ -483,10 +464,10 @@ const useHasAccessTo = (options) => {
483
464
  * }, [assetInfo, getAssetLocation]);
484
465
  */
485
466
  const useAssetRuntime = () => {
486
- const [assetInfo, setAssetInfo] = React.useState();
487
- const [loading, setLoading] = React.useState(true);
488
- const [error, setError] = React.useState();
489
- React.useEffect(() => {
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] = React.useState();
526
- const [loading, setLoading] = React.useState(true);
527
- const [error, setError] = React.useState();
528
- React.useEffect(() => {
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] = React.useState();
565
- const [loading, setLoading] = React.useState(true);
566
- const [error, setError] = React.useState();
567
- React.useEffect(() => {
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] = React.useState();
603
- const [loading, setLoading] = React.useState(true);
604
- const [error, setError] = React.useState();
605
- React.useEffect(() => {
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] = React.useState();
640
- const [loading, setLoading] = React.useState(true);
641
- const [error, setError] = React.useState();
642
- React.useEffect(() => {
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] = React.useState();
680
- const [loading, setLoading] = React.useState(true);
681
- const [error, setError] = React.useState();
682
- React.useEffect(() => {
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 = React__namespace.createContext(null);
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 = React__namespace.useContext(UserSubscriptionContext);
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 = React__namespace.createContext(null);
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 = React__namespace.useContext(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] = React.useState("");
767
- const result = React.useMemo(() => {
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 = React.createContext(null);
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 = React.useContext(CurrentUserPreferenceContext);
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 React.useMemo(() => {
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 = React.useContext(CurrentUserPreferenceContext);
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 React.useMemo(() => {
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 = React.useContext(CurrentUserPreferenceContext);
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 React.useMemo(() => {
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 = React.createContext(null);
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 = React__namespace.useContext(CurrentUserContext);
861
+ const context = react.useContext(CurrentUserContext);
881
862
  if (!context) {
882
863
  throw new Error("useCurrentUser must be used within the CurrentUserProvider");
883
864
  }
@@ -893,13 +874,13 @@ const useCurrentUser = () => {
893
874
  const validateState = ({ state, schema, onValidationFailed, onValidationSuccessful, defaultState, }) => {
894
875
  try {
895
876
  const parsedState = schema.parse(state);
896
- onValidationSuccessful === null || onValidationSuccessful === void 0 ? void 0 : onValidationSuccessful(parsedState);
877
+ onValidationSuccessful?.(parsedState);
897
878
  return parsedState;
898
879
  }
899
880
  catch (error) {
900
881
  // eslint-disable-next-line no-console
901
882
  console.error("Failed to parse and validate the state from local storage.", error);
902
- onValidationFailed === null || onValidationFailed === void 0 ? void 0 : onValidationFailed(error);
883
+ onValidationFailed?.(error);
903
884
  return defaultState;
904
885
  }
905
886
  };
@@ -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 = React.useRef();
935
- React.useEffect(() => {
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
- React.useEffect(() => {
945
+ react.useEffect(() => {
965
946
  if (JSON.stringify(prevState) === JSON.stringify(state)) {
966
947
  return;
967
948
  }
@@ -974,11 +955,11 @@ const useLocalStorageEffect = ({ key, state, defaultState, schema, onValidationF
974
955
  // eslint-disable-next-line no-console
975
956
  console.error(`State validation failed. Resetting local storage to default state: ${defaultState}.`, error);
976
957
  localStorage.removeItem(key);
977
- onValidationFailed === null || onValidationFailed === void 0 ? void 0 : onValidationFailed(error);
958
+ onValidationFailed?.(error);
978
959
  },
979
960
  onValidationSuccessful: data => {
980
961
  setLocalStorage(key, data);
981
- onValidationSuccessful === null || onValidationSuccessful === void 0 ? void 0 : onValidationSuccessful(data);
962
+ onValidationSuccessful?.(data);
982
963
  },
983
964
  });
984
965
  }
@@ -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] = React.useState(initLocalStorageState({ key, defaultState, schema }));
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] = React.useReducer(reducer, defaultState, () => initLocalStorageState({ key, defaultState, schema }));
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';
@@ -38,8 +37,8 @@ const useAnalytics = (events) => {
38
37
  // Automatically append the description from the event type
39
38
  const logEventWithDescription = (logEvent, events) => {
40
39
  return (eventName, details, nameSupplement) => {
41
- const event = events === null || events === void 0 ? void 0 : events[eventName];
42
- const eventDescription = event === null || event === void 0 ? void 0 : event.description;
40
+ const event = events?.[eventName];
41
+ const eventDescription = event?.description;
43
42
  // Include description in the details object.
44
43
  const detailsWithDescription = {
45
44
  eventDescription,
@@ -95,7 +94,7 @@ const useAssetSorting = () => {
95
94
  return context;
96
95
  };
97
96
 
98
- const ConfirmationDialogContext = React.createContext(null);
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 = React.useContext(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 = React.createContext(null);
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 = React.useContext(FilterBarContext);
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 = React.createContext(null);
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 = React.useContext(TokenContext);
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 = React.createContext(null);
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 = React.useContext(ModalDialogContext);
386
+ const modalDialogContext = useContext(ModalDialogContext);
388
387
  if (!modalDialogContext) {
389
388
  throw new Error("useModalDialogContext must be used within the ModalDialogContextProvider");
390
389
  }
@@ -437,7 +436,7 @@ const useHasAccessTo = (options) => {
437
436
  useEffect(() => {
438
437
  async function checkAccess() {
439
438
  if (options.assetId) {
440
- const doHaveAccess = await (context === null || context === void 0 ? void 0 : context.hasAccessTo(options));
439
+ const doHaveAccess = await context?.hasAccessTo(options);
441
440
  setHasAccess(() => doHaveAccess);
442
441
  }
443
442
  }
@@ -677,7 +676,7 @@ const useSiteRuntime = () => {
677
676
  return { siteInfo, loading, error };
678
677
  };
679
678
 
680
- const UserSubscriptionContext = React.createContext(null);
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 = React.useContext(UserSubscriptionContext);
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 = React.createContext(null);
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 = React.useContext(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 = React.useContext(CurrentUserContext);
859
+ const context = useContext(CurrentUserContext);
861
860
  if (!context) {
862
861
  throw new Error("useCurrentUser must be used within the CurrentUserProvider");
863
862
  }
@@ -873,13 +872,13 @@ const useCurrentUser = () => {
873
872
  const validateState = ({ state, schema, onValidationFailed, onValidationSuccessful, defaultState, }) => {
874
873
  try {
875
874
  const parsedState = schema.parse(state);
876
- onValidationSuccessful === null || onValidationSuccessful === void 0 ? void 0 : onValidationSuccessful(parsedState);
875
+ onValidationSuccessful?.(parsedState);
877
876
  return parsedState;
878
877
  }
879
878
  catch (error) {
880
879
  // eslint-disable-next-line no-console
881
880
  console.error("Failed to parse and validate the state from local storage.", error);
882
- onValidationFailed === null || onValidationFailed === void 0 ? void 0 : onValidationFailed(error);
881
+ onValidationFailed?.(error);
883
882
  return defaultState;
884
883
  }
885
884
  };
@@ -954,11 +953,11 @@ const useLocalStorageEffect = ({ key, state, defaultState, schema, onValidationF
954
953
  // eslint-disable-next-line no-console
955
954
  console.error(`State validation failed. Resetting local storage to default state: ${defaultState}.`, error);
956
955
  localStorage.removeItem(key);
957
- onValidationFailed === null || onValidationFailed === void 0 ? void 0 : onValidationFailed(error);
956
+ onValidationFailed?.(error);
958
957
  },
959
958
  onValidationSuccessful: data => {
960
959
  setLocalStorage(key, data);
961
- onValidationSuccessful === null || onValidationSuccessful === void 0 ? void 0 : onValidationSuccessful(data);
960
+ onValidationSuccessful?.(data);
962
961
  },
963
962
  });
964
963
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-hooks",
3
- "version": "1.0.5",
3
+ "version": "1.0.9",
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": "^1.0.5",
14
- "@trackunit/iris-app-runtime-core": "^1.0.5",
15
- "@trackunit/shared-utils": "^1.0.3"
13
+ "@trackunit/react-core-contexts-api": "1.0.9",
14
+ "@trackunit/iris-app-runtime-core": "1.0.9",
15
+ "@trackunit/shared-utils": "1.2.1"
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 * as React from "react";
2
+ import { ReactNode } from "react";
3
3
  export interface ConfirmationDialogContextProviderProps {
4
4
  value: ConfirmationDialogContextValue;
5
- children: React.ReactNode;
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 * as React from "react";
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?: React.ReactNode;
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 * as React from "react";
2
+ import { ReactNode } from "react";
3
3
  export interface ModalDialogProviderProps {
4
4
  value: ModalDialogContextValue;
5
- children: React.ReactNode;
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 * as React from "react";
2
+ import { ReactNode } from "react";
3
3
  interface IProps {
4
4
  value: IUserSubscriptionContext;
5
- children?: React.ReactNode;
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 * as React from "react";
2
+ import { ReactNode } from "react";
3
3
  export interface ToastContextProviderProps {
4
4
  value: IToastContext;
5
- children: React.ReactNode;
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 * as React from "react";
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?: React.ReactNode;
15
+ children?: ReactNode;
16
16
  }
17
17
  /**
18
18
  * This is a provider for the TokenContext.