@trackunit/react-core-hooks 1.3.46 → 1.3.49

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
@@ -252,9 +252,9 @@ const base64ToBlob = (base64, contentType = "") => {
252
252
  * useImageUploader
253
253
  *
254
254
  * @description Hook for uploading an image
255
- * @param {Function} uploadImage - function for uploading an image
256
- * @param {boolean} loading - loading state
257
- * @returns {object} uploadImage - function for uploading an image, loading - loading state
255
+ * @returns {object} An object containing:
256
+ * - uploadImage: Function for uploading an image
257
+ * - loading: Boolean indicating upload state
258
258
  */
259
259
  const useImageUploader = () => {
260
260
  const { token } = useToken();
@@ -304,8 +304,9 @@ const IRIS_APP_ASSET_PATH = "assets/";
304
304
  /**
305
305
  * Provides functions to get the Iris App URL and logo image.
306
306
  *
307
- * @requires EnvironmentContextProvider, TokenProvider
308
- * @returns {getAppUrl, getAppImage}
307
+ * @returns {object}
308
+ * - getAppUrl: returns the url of the Iris App
309
+ * - getAppImage: returns Iris App image as an data url
309
310
  * @example
310
311
  * const { getAppUrl, getAppImage } = useIrisAppImage();
311
312
  * const irisAppUrl = getAppUrl({ irisAppId, version });
@@ -737,9 +738,10 @@ const useToast = () => {
737
738
  /**
738
739
  * Hook for filtering a list of items by text search, client side search in a list.
739
740
  *
741
+ * @template TSearchableItem
740
742
  * @param items The list of items to filter.
741
743
  * @param props The properties to search in each item.
742
- * @returns { Maybe<string>[]): [T[], string, Dispatch<string>] } A tuple with the filtered items, the search text and a setter for the search text.
744
+ * @returns {[TSearchableItem[], string, Dispatch<string>]} A tuple with the filtered items, the search text and a setter for the search text.
743
745
  * @example
744
746
  * const [result, searchText, setSearchText] = useTextSearch(items, item => [item.name, item.description]);
745
747
  */
@@ -778,9 +780,11 @@ const useCurrentUserLanguage = () => {
778
780
  if (!context) {
779
781
  throw new Error("useCurrentUserLanguage must be used within the CurrentUserPreferenceProvider");
780
782
  }
781
- return react.useMemo(() => {
783
+ react.useEffect(() => {
782
784
  // This is there to make sure that the language is set on the global object so Graphql can use it.
783
- global.language = context.language;
785
+ setGlobalLanguage(context.language);
786
+ }, [context.language]);
787
+ return react.useMemo(() => {
784
788
  return {
785
789
  language: context.language,
786
790
  setLanguage: context.setLanguage,
@@ -835,6 +839,15 @@ const useCurrentUserSystemOfMeasurement = () => {
835
839
  };
836
840
  }, [context.systemOfMeasurement, context.setSystemOfMeasurement]);
837
841
  };
842
+ const setGlobalLanguage = (language) => {
843
+ if (typeof global !== "undefined") {
844
+ Object.defineProperty(global, "language", {
845
+ value: language,
846
+ configurable: true,
847
+ writable: true,
848
+ });
849
+ }
850
+ };
838
851
 
839
852
  const CurrentUserContext = react.createContext(null);
840
853
  /**
@@ -877,7 +890,12 @@ const usePrevious = (value) => {
877
890
  react.useEffect(() => {
878
891
  ref.current = value;
879
892
  }, [value]);
880
- return ref.current;
893
+ const wrapper = {
894
+ get previous() {
895
+ return ref.current;
896
+ },
897
+ };
898
+ return wrapper.previous;
881
899
  };
882
900
 
883
901
  /**
package/index.esm.js CHANGED
@@ -250,9 +250,9 @@ const base64ToBlob = (base64, contentType = "") => {
250
250
  * useImageUploader
251
251
  *
252
252
  * @description Hook for uploading an image
253
- * @param {Function} uploadImage - function for uploading an image
254
- * @param {boolean} loading - loading state
255
- * @returns {object} uploadImage - function for uploading an image, loading - loading state
253
+ * @returns {object} An object containing:
254
+ * - uploadImage: Function for uploading an image
255
+ * - loading: Boolean indicating upload state
256
256
  */
257
257
  const useImageUploader = () => {
258
258
  const { token } = useToken();
@@ -302,8 +302,9 @@ const IRIS_APP_ASSET_PATH = "assets/";
302
302
  /**
303
303
  * Provides functions to get the Iris App URL and logo image.
304
304
  *
305
- * @requires EnvironmentContextProvider, TokenProvider
306
- * @returns {getAppUrl, getAppImage}
305
+ * @returns {object}
306
+ * - getAppUrl: returns the url of the Iris App
307
+ * - getAppImage: returns Iris App image as an data url
307
308
  * @example
308
309
  * const { getAppUrl, getAppImage } = useIrisAppImage();
309
310
  * const irisAppUrl = getAppUrl({ irisAppId, version });
@@ -735,9 +736,10 @@ const useToast = () => {
735
736
  /**
736
737
  * Hook for filtering a list of items by text search, client side search in a list.
737
738
  *
739
+ * @template TSearchableItem
738
740
  * @param items The list of items to filter.
739
741
  * @param props The properties to search in each item.
740
- * @returns { Maybe<string>[]): [T[], string, Dispatch<string>] } A tuple with the filtered items, the search text and a setter for the search text.
742
+ * @returns {[TSearchableItem[], string, Dispatch<string>]} A tuple with the filtered items, the search text and a setter for the search text.
741
743
  * @example
742
744
  * const [result, searchText, setSearchText] = useTextSearch(items, item => [item.name, item.description]);
743
745
  */
@@ -776,9 +778,11 @@ const useCurrentUserLanguage = () => {
776
778
  if (!context) {
777
779
  throw new Error("useCurrentUserLanguage must be used within the CurrentUserPreferenceProvider");
778
780
  }
779
- return useMemo(() => {
781
+ useEffect(() => {
780
782
  // This is there to make sure that the language is set on the global object so Graphql can use it.
781
- global.language = context.language;
783
+ setGlobalLanguage(context.language);
784
+ }, [context.language]);
785
+ return useMemo(() => {
782
786
  return {
783
787
  language: context.language,
784
788
  setLanguage: context.setLanguage,
@@ -833,6 +837,15 @@ const useCurrentUserSystemOfMeasurement = () => {
833
837
  };
834
838
  }, [context.systemOfMeasurement, context.setSystemOfMeasurement]);
835
839
  };
840
+ const setGlobalLanguage = (language) => {
841
+ if (typeof global !== "undefined") {
842
+ Object.defineProperty(global, "language", {
843
+ value: language,
844
+ configurable: true,
845
+ writable: true,
846
+ });
847
+ }
848
+ };
836
849
 
837
850
  const CurrentUserContext = createContext(null);
838
851
  /**
@@ -875,7 +888,12 @@ const usePrevious = (value) => {
875
888
  useEffect(() => {
876
889
  ref.current = value;
877
890
  }, [value]);
878
- return ref.current;
891
+ const wrapper = {
892
+ get previous() {
893
+ return ref.current;
894
+ },
895
+ };
896
+ return wrapper.previous;
879
897
  };
880
898
 
881
899
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-hooks",
3
- "version": "1.3.46",
3
+ "version": "1.3.49",
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": "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.45",
14
- "@trackunit/iris-app-runtime-core": "1.4.46",
15
- "@trackunit/shared-utils": "1.5.44"
13
+ "@trackunit/react-core-contexts-api": "1.4.47",
14
+ "@trackunit/iris-app-runtime-core": "1.4.48",
15
+ "@trackunit/shared-utils": "1.5.46"
16
16
  },
17
17
  "module": "./index.esm.js",
18
18
  "main": "./index.cjs.js",
@@ -1,12 +1,12 @@
1
1
  import { IEnvironmentContext } from "@trackunit/react-core-contexts-api";
2
- interface IProps {
2
+ interface EnvironmentContextProviderProps {
3
3
  value: IEnvironmentContext;
4
4
  children?: React.ReactNode;
5
5
  }
6
6
  /**
7
7
  * This is a provider for the EnvironmentContext.
8
8
  */
9
- export declare const EnvironmentContextProvider: (props: IProps) => import("react/jsx-runtime").JSX.Element;
9
+ export declare const EnvironmentContextProvider: (props: EnvironmentContextProviderProps) => import("react/jsx-runtime").JSX.Element;
10
10
  /**
11
11
  * This is a hook to use the EnvironmentContext.
12
12
  *
@@ -15,12 +15,12 @@ import { ReactNode } from "react";
15
15
  * @see {@link IFilterBarContext}
16
16
  */
17
17
  export declare const useFilterBarContext: () => IFilterBarContext;
18
- interface IProps {
18
+ interface FilterBarContextProps {
19
19
  value: IFilterBarContext;
20
20
  children?: ReactNode;
21
21
  }
22
22
  /**
23
23
  * This is a provider for the FilterBarContext.
24
24
  */
25
- export declare const FilterBarProvider: (props: IProps) => import("react/jsx-runtime").JSX.Element;
25
+ export declare const FilterBarProvider: (props: FilterBarContextProps) => import("react/jsx-runtime").JSX.Element;
26
26
  export {};
@@ -7,9 +7,9 @@ export interface UploadedFile {
7
7
  * useImageUploader
8
8
  *
9
9
  * @description Hook for uploading an image
10
- * @param {Function} uploadImage - function for uploading an image
11
- * @param {boolean} loading - loading state
12
- * @returns {object} uploadImage - function for uploading an image, loading - loading state
10
+ * @returns {object} An object containing:
11
+ * - uploadImage: Function for uploading an image
12
+ * - loading: Boolean indicating upload state
13
13
  */
14
14
  export declare const useImageUploader: () => {
15
15
  uploadImage: ({ postUrl, base64Image, type, authorize, }: {
@@ -9,8 +9,9 @@ interface GetImageAssetsParams {
9
9
  /**
10
10
  * Provides functions to get the Iris App URL and logo image.
11
11
  *
12
- * @requires EnvironmentContextProvider, TokenProvider
13
- * @returns {getAppUrl, getAppImage}
12
+ * @returns {object}
13
+ * - getAppUrl: returns the url of the Iris App
14
+ * - getAppImage: returns Iris App image as an data url
14
15
  * @example
15
16
  * const { getAppUrl, getAppImage } = useIrisAppImage();
16
17
  * const irisAppUrl = getAppUrl({ irisAppId, version });
@@ -1,12 +1,12 @@
1
1
  import { HasAccessToOptions, INavigationContext } from "@trackunit/react-core-contexts-api";
2
- interface IProps {
2
+ interface NavigationContextProviderProps {
3
3
  value: INavigationContext;
4
4
  children?: React.ReactNode;
5
5
  }
6
6
  /**
7
7
  * This is a provider for the NavigationContext.
8
8
  */
9
- export declare const NavigationContextProvider: (props: IProps) => import("react/jsx-runtime").JSX.Element;
9
+ export declare const NavigationContextProvider: (props: NavigationContextProviderProps) => import("react/jsx-runtime").JSX.Element;
10
10
  /**
11
11
  * This is a hook to use the NavigationContext.
12
12
  *
@@ -1,13 +1,13 @@
1
1
  import { IUserSubscriptionContext } from "@trackunit/react-core-contexts-api";
2
2
  import { ReactNode } from "react";
3
- interface IProps {
3
+ interface UserSubscriptionProviderProps {
4
4
  value: IUserSubscriptionContext;
5
5
  children?: ReactNode;
6
6
  }
7
7
  /**
8
8
  * This is a provider for the UserSubscriptionContext.
9
9
  */
10
- export declare const UserSubscriptionProvider: (props: IProps) => import("react/jsx-runtime").JSX.Element;
10
+ export declare const UserSubscriptionProvider: (props: UserSubscriptionProviderProps) => import("react/jsx-runtime").JSX.Element;
11
11
  /**
12
12
  * This is a hook to use the UserSubscriptionContext.
13
13
  *
@@ -10,12 +10,12 @@ import { ReactNode } from "react";
10
10
  * @see {@link ITokenContext}
11
11
  */
12
12
  export declare const useToken: () => ITokenContext;
13
- interface IProps {
13
+ interface TokenProviderProps {
14
14
  value: ITokenContext;
15
15
  children?: ReactNode;
16
16
  }
17
17
  /**
18
18
  * This is a provider for the TokenContext.
19
19
  */
20
- export declare const TokenProvider: (props: IProps) => import("react/jsx-runtime").JSX.Element;
20
+ export declare const TokenProvider: (props: TokenProviderProps) => import("react/jsx-runtime").JSX.Element;
21
21
  export {};
@@ -3,10 +3,11 @@ import { Dispatch } from "react";
3
3
  /**
4
4
  * Hook for filtering a list of items by text search, client side search in a list.
5
5
  *
6
+ * @template TSearchableItem
6
7
  * @param items The list of items to filter.
7
8
  * @param props The properties to search in each item.
8
- * @returns { Maybe<string>[]): [T[], string, Dispatch<string>] } A tuple with the filtered items, the search text and a setter for the search text.
9
+ * @returns {[TSearchableItem[], string, Dispatch<string>]} A tuple with the filtered items, the search text and a setter for the search text.
9
10
  * @example
10
11
  * const [result, searchText, setSearchText] = useTextSearch(items, item => [item.name, item.description]);
11
12
  */
12
- export declare function useTextSearch<T>(items: T[], props: (item: T) => (Maybe<string> | undefined)[]): [T[], string, Dispatch<string>];
13
+ export declare function useTextSearch<TSearchableItem>(items: TSearchableItem[], props: (item: TSearchableItem) => (Maybe<string> | undefined)[]): [TSearchableItem[], string, Dispatch<string>];