PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Shared / hooks / useStampedPreview.js

useStampedPreview.js in Extendify 3.2.1, at src/Shared/hooks/useStampedPreview.js

29 lines 751 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { stampImageBlob } from '@shared/lib/ai-label';
2 import { useEffect, useState } from '@wordpress/element';
3
4 // Reuses the importer's drawing so the preview can't drift from the import.
5 export const useStampedPreview = (url, disclose) => {
6 const [stamped, setStamped] = useState(null);
7
8 useEffect(() => {
9 setStamped(null);
10 if (!url || !disclose) return;
11
12 let objectUrl = null;
13 let cancelled = false;
14 stampImageBlob(url).then((blob) => {
15 if (!blob) return;
16 objectUrl = URL.createObjectURL(blob);
17 if (cancelled) return URL.revokeObjectURL(objectUrl);
18 setStamped(objectUrl);
19 });
20
21 return () => {
22 cancelled = true;
23 if (objectUrl) URL.revokeObjectURL(objectUrl);
24 };
25 }, [url, disclose]);
26
27 return stamped ?? url;
28 };
29