@evergis/react 3.1.130 → 3.1.131
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.
|
@@ -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,37 @@ 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
|
+
|
|
3926
3957
|
const DashboardContext = React.createContext({});
|
|
3927
3958
|
const DashboardProvider = React.memo(({ children, ...props }) => {
|
|
3928
3959
|
return jsxRuntime.jsx(DashboardContext.Provider, { value: props, children: children });
|
|
@@ -8514,6 +8545,7 @@ const ElementIcon = React.memo(({ type, elementConfig }) => {
|
|
|
8514
8545
|
return jsxRuntime.jsx(StyledIcon, { kind: iconValue, fontSize: fontSize, fontColor: fontColor, style: style });
|
|
8515
8546
|
});
|
|
8516
8547
|
|
|
8548
|
+
const toObjectUrl = (res) => res.blob().then(blob => URL.createObjectURL(blob));
|
|
8517
8549
|
const ElementImage = React.memo(({ type, elementConfig }) => {
|
|
8518
8550
|
const { attributes } = useWidgetContext(type);
|
|
8519
8551
|
const { value, attributeName, options, style } = elementConfig || {};
|
|
@@ -8531,7 +8563,10 @@ const ElementImage = React.memo(({ type, elementConfig }) => {
|
|
|
8531
8563
|
return null;
|
|
8532
8564
|
return getResourceUrl(imageUrl);
|
|
8533
8565
|
}, [attributeName, attributes, value]);
|
|
8534
|
-
|
|
8566
|
+
const blobUrl = useFetchWithAuth(firstImage, toObjectUrl, URL.revokeObjectURL);
|
|
8567
|
+
if (!blobUrl)
|
|
8568
|
+
return null;
|
|
8569
|
+
return (jsxRuntime.jsx("img", { src: blobUrl, alt: firstImage ?? "", width: width, style: style }));
|
|
8535
8570
|
});
|
|
8536
8571
|
|
|
8537
8572
|
const ElementLegend = React.memo(({ type, element, elementConfig }) => {
|
|
@@ -11680,30 +11715,9 @@ const StyledSvg = styled(uilibGl.Flex) `
|
|
|
11680
11715
|
`;
|
|
11681
11716
|
|
|
11682
11717
|
const SvgImage = React.memo(({ url, width, height, fontColor }) => {
|
|
11683
|
-
const
|
|
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
|
-
}, []);
|
|
11718
|
+
const svg = useFetchWithAuth(url, res => res.text());
|
|
11705
11719
|
const regexp = /<\/svg>\s*$/im;
|
|
11706
|
-
if (!regexp.test(svg))
|
|
11720
|
+
if (!svg || !regexp.test(svg))
|
|
11707
11721
|
return null;
|
|
11708
11722
|
return (jsxRuntime.jsx(StyledSvg, { "$width": width, "$height": height, "$fontColor": fontColor, dangerouslySetInnerHTML: { __html: svg } }));
|
|
11709
11723
|
});
|
|
@@ -12243,6 +12257,7 @@ exports.useDebouncedCallback = useDebouncedCallback;
|
|
|
12243
12257
|
exports.useDiffPage = useDiffPage;
|
|
12244
12258
|
exports.useExpandableContainers = useExpandableContainers;
|
|
12245
12259
|
exports.useExportPdf = useExportPdf;
|
|
12260
|
+
exports.useFetchWithAuth = useFetchWithAuth;
|
|
12246
12261
|
exports.useGetConfigLayer = useGetConfigLayer;
|
|
12247
12262
|
exports.useGlobalContext = useGlobalContext;
|
|
12248
12263
|
exports.useHeaderRender = useHeaderRender;
|