create-cloudinary-react 1.0.0-beta.1 → 1.0.0-beta.8

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.
@@ -16,6 +16,8 @@ dist-ssr
16
16
  .env
17
17
  .env.local
18
18
  .env.production
19
+ # Server-only env (for secure signed uploads); do not commit API secret
20
+ server/.env
19
21
 
20
22
  # Editor directories and files
21
23
  .vscode/*
@@ -60,16 +60,11 @@ function App() {
60
60
 
61
61
  <div className="ai-prompts-section">
62
62
  <h2>🤖 Try Asking Your AI Assistant</h2>
63
- <p className="prompts-intro">Here are some Cloudinary-related tasks you can try:</p>
63
+ <p className="prompts-intro">Ping your agent with one of these to get started:</p>
64
64
  <ul className="prompts-list">
65
- <li>"Add responsive image transformations with breakpoints"</li>
66
- <li>"Create a video player component with Cloudinary"</li>
67
- <li>"Add image effects like blur, grayscale, or sepia"</li>
68
- <li>"Implement automatic image cropping with face detection"</li>
69
- <li>"Add image overlays with text or logos"</li>
70
- <li>"Create an image gallery with lazy loading"</li>
71
- <li>"Add image optimization with format and quality auto"</li>
72
- <li>"Implement image transformations based on screen size"</li>
65
+ <li>Create an image gallery with lazy loading and responsive</li>
66
+ <li>Create a video player that plays a Cloudinary video</li>
67
+ <li>Add image overlays with text or logos</li>
73
68
  </ul>
74
69
  </div>
75
70
  </main>
@@ -22,24 +22,11 @@ export function UploadWidget({
22
22
  }: UploadWidgetProps) {
23
23
  const widgetRef = useRef<any>(null);
24
24
  const buttonRef = useRef<HTMLButtonElement>(null);
25
+ const clickHandlerRef = useRef<(() => void) | null>(null);
25
26
 
26
27
  useEffect(() => {
27
- // Load Cloudinary Upload Widget script
28
- if (!window.cloudinary) {
29
- const script = document.createElement('script');
30
- script.src = 'https://upload-widget.cloudinary.com/global/all.js';
31
- script.async = true;
32
- document.body.appendChild(script);
33
-
34
- script.onload = () => {
35
- initializeWidget();
36
- };
37
- } else {
38
- initializeWidget();
39
- }
40
-
41
28
  function initializeWidget() {
42
- if (!window.cloudinary || !buttonRef.current) return;
29
+ if (typeof window.cloudinary?.createUploadWidget !== 'function' || !buttonRef.current) return;
43
30
 
44
31
  if (!uploadPreset) {
45
32
  console.warn(
@@ -69,16 +56,45 @@ export function UploadWidget({
69
56
  }
70
57
  );
71
58
 
72
- buttonRef.current.addEventListener('click', () => {
73
- widgetRef.current?.open();
74
- });
59
+ const handler = () => widgetRef.current?.open();
60
+ clickHandlerRef.current = handler;
61
+ buttonRef.current.addEventListener('click', handler);
62
+ }
63
+
64
+ function waitThenInit() {
65
+ if (typeof window.cloudinary?.createUploadWidget === 'function') {
66
+ initializeWidget();
67
+ return true;
68
+ }
69
+ return false;
70
+ }
71
+
72
+ if (!window.cloudinary) {
73
+ const script = document.createElement('script');
74
+ script.src = 'https://upload-widget.cloudinary.com/global/all.js';
75
+ script.async = true;
76
+ document.body.appendChild(script);
77
+ script.onload = () => waitThenInit();
78
+ } else if (!waitThenInit()) {
79
+ const poll = setInterval(() => {
80
+ if (waitThenInit()) {
81
+ clearInterval(poll);
82
+ clearTimeout(timeout);
83
+ }
84
+ }, 100);
85
+ const timeout = setTimeout(() => clearInterval(poll), 10000);
86
+ return () => {
87
+ clearInterval(poll);
88
+ clearTimeout(timeout);
89
+ if (buttonRef.current && clickHandlerRef.current) {
90
+ buttonRef.current.removeEventListener('click', clickHandlerRef.current);
91
+ }
92
+ };
75
93
  }
76
94
 
77
95
  return () => {
78
- if (buttonRef.current && widgetRef.current) {
79
- buttonRef.current.removeEventListener('click', () => {
80
- widgetRef.current?.open();
81
- });
96
+ if (buttonRef.current && clickHandlerRef.current) {
97
+ buttonRef.current.removeEventListener('click', clickHandlerRef.current);
82
98
  }
83
99
  };
84
100
  }, [onUploadSuccess, onUploadError]);