@evergis/react 3.1.130 → 3.1.132

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.
@@ -1,4 +1,6 @@
1
1
  export * from './useAutoCompleteControl';
2
+ export * from './useFetchImageWithAuth';
3
+ export * from './useFetchWithAuth';
2
4
  export * from './useChartChange';
3
5
  export * from './useChartData';
4
6
  export * from './useDashboardHeader';
@@ -0,0 +1 @@
1
+ export declare const useFetchImageWithAuth: (url: string | null) => string | null;
@@ -0,0 +1 @@
1
+ export declare const useFetchWithAuth: <T>(url: string | null, transform: (res: Response) => Promise<T | null>, cleanup?: (value: T) => void) => T | null;
package/dist/index.js CHANGED
@@ -3923,6 +3923,40 @@ const useAutoCompleteControl = (items) => {
3923
3923
  };
3924
3924
  };
3925
3925
 
3926
+ const useFetchWithAuth = (url, transform, cleanup) => {
3927
+ const [data, setData] = React.useState(null);
3928
+ const loadingRef = React.useRef(false);
3929
+ const transformRef = React.useRef(transform);
3930
+ const cleanupRef = React.useRef(cleanup);
3931
+ transformRef.current = transform;
3932
+ cleanupRef.current = cleanup;
3933
+ const fetchData = React.useCallback(() => {
3934
+ if (!url || loadingRef.current)
3935
+ return;
3936
+ loadingRef.current = true;
3937
+ const token = window.localStorage.getItem(api.STORAGE_TOKEN_KEY);
3938
+ fetch(url, {
3939
+ headers: token ? { Authorization: `Bearer ${token}` } : {},
3940
+ })
3941
+ .then(res => (res.ok ? transformRef.current(res) : null))
3942
+ .then(setData)
3943
+ .finally(() => {
3944
+ loadingRef.current = false;
3945
+ });
3946
+ }, [url]);
3947
+ React.useEffect(() => {
3948
+ fetchData();
3949
+ }, [fetchData]);
3950
+ React.useEffect(() => () => {
3951
+ if (data !== null)
3952
+ cleanupRef.current?.(data);
3953
+ }, [data]);
3954
+ return data;
3955
+ };
3956
+
3957
+ const toObjectUrl = (res) => res.blob().then(blob => URL.createObjectURL(blob));
3958
+ const useFetchImageWithAuth = (url) => useFetchWithAuth(url, toObjectUrl, URL.revokeObjectURL);
3959
+
3926
3960
  const DashboardContext = React.createContext({});
3927
3961
  const DashboardProvider = React.memo(({ children, ...props }) => {
3928
3962
  return jsxRuntime.jsx(DashboardContext.Provider, { value: props, children: children });
@@ -7771,10 +7805,10 @@ const PageTitleContainer = styled(uilibGl.Flex) `
7771
7805
  `;
7772
7806
 
7773
7807
  const DashboardDefaultHeader = React.memo(() => {
7774
- const { title } = useDashboardHeader();
7808
+ const { title, pageId, image, icon, tooltip, themeName } = useDashboardHeader();
7775
7809
  const { toggleLayersVisibility, components: { ProjectPanelMenu, ProjectPagesMenu }, } = useWidgetContext();
7776
- const { pageId, image, icon, tooltip, themeName } = useDashboardHeader();
7777
- return (jsxRuntime.jsxs(DefaultHeaderContainer, { image: getResourceUrl(image), isDark: themeName === exports.ThemeName.Dark, children: [!pageId && jsxRuntime.jsx(uilibGl.LinearProgress, {}), jsxRuntime.jsxs(uilibGl.Flex, { column: true, gap: "1rem", children: [jsxRuntime.jsx(uilibGl.FlexSpan, { children: jsxRuntime.jsxs(TopContainer, { children: [jsxRuntime.jsx(LogoContainer, { children: icon }), jsxRuntime.jsx(TopContainerButtons, { children: jsxRuntime.jsx(ProjectPanelMenu, {}) })] }) }), jsxRuntime.jsx(uilibGl.FlexSpan, { children: jsxRuntime.jsx(uilibGl.Flex, { column: true, gap: "0.25rem", children: jsxRuntime.jsx(uilibGl.FlexSpan, { children: jsxRuntime.jsxs(uilibGl.Flex, { alignItems: "center", children: [jsxRuntime.jsxs(PageTitleContainer, { children: [jsxRuntime.jsx(uilibGl.Tooltip, { arrow: true, content: tooltip, children: ref => (jsxRuntime.jsx(PageTitle, { ref: ref, onClick: toggleLayersVisibility, children: title })) }), jsxRuntime.jsx(ProjectPagesMenu, {})] }), jsxRuntime.jsx(uilibGl.FlexSpan, { children: jsxRuntime.jsx(Pagination, {}) })] }) }) }) })] })] }));
7810
+ const backgroundImage = useFetchImageWithAuth(image ? getResourceUrl(image) : null);
7811
+ return (jsxRuntime.jsxs(DefaultHeaderContainer, { image: backgroundImage ?? undefined, isDark: themeName === exports.ThemeName.Dark, children: [!pageId && jsxRuntime.jsx(uilibGl.LinearProgress, {}), jsxRuntime.jsxs(uilibGl.Flex, { column: true, gap: "1rem", children: [jsxRuntime.jsx(uilibGl.FlexSpan, { children: jsxRuntime.jsxs(TopContainer, { children: [jsxRuntime.jsx(LogoContainer, { children: icon }), jsxRuntime.jsx(TopContainerButtons, { children: jsxRuntime.jsx(ProjectPanelMenu, {}) })] }) }), jsxRuntime.jsx(uilibGl.FlexSpan, { children: jsxRuntime.jsx(uilibGl.Flex, { column: true, gap: "0.25rem", children: jsxRuntime.jsx(uilibGl.FlexSpan, { children: jsxRuntime.jsxs(uilibGl.Flex, { alignItems: "center", children: [jsxRuntime.jsxs(PageTitleContainer, { children: [jsxRuntime.jsx(uilibGl.Tooltip, { arrow: true, content: tooltip, children: ref => (jsxRuntime.jsx(PageTitle, { ref: ref, onClick: toggleLayersVisibility, children: title })) }), jsxRuntime.jsx(ProjectPagesMenu, {})] }), jsxRuntime.jsx(uilibGl.FlexSpan, { children: jsxRuntime.jsx(Pagination, {}) })] }) }) }) })] })] }));
7778
7812
  });
7779
7813
 
7780
7814
  const HeaderFrontView = styled(uilibGl.Flex) `
@@ -8531,7 +8565,10 @@ const ElementImage = React.memo(({ type, elementConfig }) => {
8531
8565
  return null;
8532
8566
  return getResourceUrl(imageUrl);
8533
8567
  }, [attributeName, attributes, value]);
8534
- return firstImage ? jsxRuntime.jsx("img", { src: firstImage, alt: firstImage, width: width, style: style }) : null;
8568
+ const blobUrl = useFetchImageWithAuth(firstImage);
8569
+ if (!blobUrl)
8570
+ return null;
8571
+ return (jsxRuntime.jsx("img", { src: blobUrl, alt: firstImage ?? "", width: width, style: style }));
8535
8572
  });
8536
8573
 
8537
8574
  const ElementLegend = React.memo(({ type, element, elementConfig }) => {
@@ -11680,30 +11717,9 @@ const StyledSvg = styled(uilibGl.Flex) `
11680
11717
  `;
11681
11718
 
11682
11719
  const SvgImage = React.memo(({ url, width, height, fontColor }) => {
11683
- const [svg, setSvg] = React.useState(null);
11684
- const loadingRef = React.useRef(false);
11685
- const fetchSvg = React.useCallback(() => {
11686
- if (!url || loadingRef.current)
11687
- return;
11688
- loadingRef.current = true;
11689
- const token = window.localStorage.getItem(api.STORAGE_TOKEN_KEY);
11690
- fetch(url, {
11691
- headers: token ? { Authorization: `Bearer ${token}` } : {},
11692
- })
11693
- .then(res => (res.ok ? res.text() : null))
11694
- .then(setSvg)
11695
- .finally(() => {
11696
- loadingRef.current = false;
11697
- });
11698
- }, [url]);
11699
- React.useEffect(() => {
11700
- fetchSvg();
11701
- }, [fetchSvg]);
11702
- React.useEffect(() => () => {
11703
- setSvg(null);
11704
- }, []);
11720
+ const svg = useFetchWithAuth(url, res => res.text());
11705
11721
  const regexp = /<\/svg>\s*$/im;
11706
- if (!regexp.test(svg))
11722
+ if (!svg || !regexp.test(svg))
11707
11723
  return null;
11708
11724
  return (jsxRuntime.jsx(StyledSvg, { "$width": width, "$height": height, "$fontColor": fontColor, dangerouslySetInnerHTML: { __html: svg } }));
11709
11725
  });
@@ -12243,6 +12259,8 @@ exports.useDebouncedCallback = useDebouncedCallback;
12243
12259
  exports.useDiffPage = useDiffPage;
12244
12260
  exports.useExpandableContainers = useExpandableContainers;
12245
12261
  exports.useExportPdf = useExportPdf;
12262
+ exports.useFetchImageWithAuth = useFetchImageWithAuth;
12263
+ exports.useFetchWithAuth = useFetchWithAuth;
12246
12264
  exports.useGetConfigLayer = useGetConfigLayer;
12247
12265
  exports.useGlobalContext = useGlobalContext;
12248
12266
  exports.useHeaderRender = useHeaderRender;