{"version":3,"file":"UploadcareUploader.BfPBY0Uw.mjs","names":["useState","useRef"],"sources":["https:/framerusercontent.com/modules/tcLT3Zqz2JArEjaEk8dh/vsq7IerGNCqMRhKcQU6V/UploadcareUploader.js"],"sourcesContent":["// File upload field with Uploadcare integration\nimport{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useRef,useEffect,useState,startTransition}from\"react\";import{addPropertyControls,ControlType}from\"framer\";/**\n * File Upload Field (Uploadcare)\n *\n * @framerIntrinsicWidth 320\n * @framerIntrinsicHeight 60\n *\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight auto\n */export default function UploadcareUploader(props){const{publicKey,buttonText,uploadedUrl,style,buttonBg=\"#0099FF\",buttonTextColor=\"#fff\",buttonRadius=8,buttonFont={}}=props;const[fileUrl,setFileUrl]=useState(uploadedUrl);const[filename,setFilename]=useState(\"\");const inputRef=useRef(null);const[widgetLoaded,setWidgetLoaded]=useState(false);const[uploading,setUploading]=useState(false);const[progress,setProgress]=useState(0);const[error,setError]=useState(\"\");// Always show progress bar in canvas for customization\nconst isCanvas=typeof window!==\"undefined\"&&(window.location?.pathname?.includes(\"/canvas\")||window.location?.pathname?.includes(\"/editor\"));// Load Uploadcare widget script\nuseEffect(()=>{if(typeof window===\"undefined\")return;if(widgetLoaded)return;if(document.getElementById(\"uploadcare-widget-script\")){setWidgetLoaded(true);return;}const script=document.createElement(\"script\");script.src=\"https://ucarecdn.com/libs/widget/3.21.8/uploadcare.full.min.js\";script.async=true;script.id=\"uploadcare-widget-script\";script.onload=()=>setWidgetLoaded(true);document.body.appendChild(script);},[widgetLoaded]);// Open Uploadcare dialog\nfunction openDialog(){if(typeof window===\"undefined\"||!widgetLoaded)return;setError(\"\");// @ts-ignore\nconst dialog=window.uploadcare.openDialog(null,{publicKey:publicKey,imagesOnly:false,multiple:false,tabs:\"file url\",// No custom CSS or theme passed to widget\n...props.allowedFileTypes?{validators:[fileInfo=>{const allowed=props.allowedFileTypes.split(\",\").map(f=>f.trim().toLowerCase());const ext=fileInfo.name?.split(\".\").pop()?.toLowerCase();if(ext&&allowed.length&&!allowed.includes(ext)){setError(`File type .${ext} not allowed. Allowed: ${allowed.join(\", \")}`);throw new Error(`File type .${ext} not allowed`);}return fileInfo;},...props.maxFileSize?[fileInfo=>{if(fileInfo.size&&fileInfo.size>props.maxFileSize*1024*1024){setError(`File too large. Max size: ${props.maxFileSize}MB`);throw new Error(`File too large. Max size: ${props.maxFileSize}MB`);}return fileInfo;}]:[]]}:{}});dialog.progress(uploadInfo=>{setUploading(true);if(uploadInfo&&typeof uploadInfo.progress===\"number\"){setProgress(Math.round(uploadInfo.progress*100));}});dialog.done(filePromise=>{setUploading(true);setProgress(0);filePromise.progress(uploadInfo=>{setUploading(true);if(uploadInfo&&typeof uploadInfo.progress===\"number\"){setProgress(Math.round(uploadInfo.progress*100));}});filePromise.done(fileInfo=>{startTransition(()=>{setFileUrl(fileInfo.cdnUrl);setFilename(fileInfo.name||\"\");});setUploading(false);setProgress(100);});filePromise.fail(err=>{setUploading(false);setProgress(0);if(err&&err.message)setError(err.message);});});}// Expose uploaded file URL to Framer property controls\nuseEffect(()=>{if(fileUrl!==uploadedUrl){// @ts-ignore\nif(props.onUploadedUrlChange)props.onUploadedUrlChange(fileUrl);}},[fileUrl,uploadedUrl,props]);// If uploadedUrl changes externally, update fileUrl and clear filename\nuseEffect(()=>{setFileUrl(uploadedUrl);setFilename(\"\");},[uploadedUrl]);// Required validation: show error and block form submit if needed\nuseEffect(()=>{if(!props.required)return;if(typeof window===\"undefined\")return;// Find parent form\nlet form=null;if(inputRef.current){let el=inputRef.current;while(el&&el.parentElement){if(el.tagName===\"FORM\"){form=el;break;}el=el.parentElement;}}if(!form)return;const handleSubmit=e=>{if(props.required&&!fileUrl){setError(\"File is required.\");e.preventDefault();e.stopPropagation();}};form.addEventListener(\"submit\",handleSubmit);return()=>{form&&form.removeEventListener(\"submit\",handleSubmit);};},[props.required,fileUrl]);return /*#__PURE__*/_jsxs(\"div\",{style:{...style,display:\"flex\",flexDirection:\"column\",gap:0,width:\"100%\",alignItems:\"flex-start\"},children:[/*#__PURE__*/_jsxs(\"div\",{style:{display:\"flex\",alignItems:\"center\",gap:props.gap??12,width:\"100%\"},children:[/*#__PURE__*/_jsx(\"button\",{type:\"button\",style:{padding:props.buttonPadding,borderRadius:buttonRadius,border:\"none\",background:buttonBg,color:buttonTextColor,fontSize:buttonFont.fontSize,fontWeight:buttonFont.variant===\"Semibold\"?600:500,letterSpacing:buttonFont.letterSpacing,lineHeight:buttonFont.lineHeight,fontStyle:buttonFont.fontStyle,fontFamily:buttonFont.fontFamily,cursor:uploading?\"not-allowed\":\"pointer\",opacity:uploading?.7:1,transition:\"background 0.2s, color 0.2s\"},onClick:openDialog,disabled:!widgetLoaded||!publicKey||uploading,\"aria-label\":buttonText,children:uploading?\"Uploading...\":buttonText}),fileUrl&&!uploading&&/*#__PURE__*/_jsx(\"span\",{style:{fontSize:13,color:props.filenameColor,overflow:\"hidden\",textOverflow:\"ellipsis\",whiteSpace:\"nowrap\",maxWidth:180},children:filename||(()=>{try{const url=new URL(fileUrl);const parts=url.pathname.split(\"/\").filter(Boolean);const last=parts[parts.length-1];if(last&&last.includes(\".\"))return last;if(parts.length>0)return parts[parts.length-2]||last;return last||\"file\";}catch{return\"file\";}})()}),(uploading||isCanvas)&&/*#__PURE__*/_jsx(\"div\",{style:{flex:1,height:props.progressBarHeight,background:props.progressBarBg,borderRadius:props.progressBarRadius,overflow:\"hidden\",marginLeft:4,minWidth:40},children:/*#__PURE__*/_jsx(\"div\",{style:{width:`${uploading?progress:100}%`,height:props.progressBarHeight,background:props.progressBarColor,transition:\"width 0.5s cubic-bezier(0.4,0,0.2,1)\",boxShadow:uploading?\"0 1px 6px 0 rgba(0,153,255,0.15)\":undefined}})}),error&&/*#__PURE__*/_jsx(\"div\",{style:{color:\"#D32F2F\",fontSize:13,marginLeft:8,maxWidth:180,wordBreak:\"break-word\",whiteSpace:\"nowrap\",overflow:\"hidden\",textOverflow:\"ellipsis\"},children:error})]}),/*#__PURE__*/_jsx(\"input\",{ref:inputRef,type:\"hidden\",name:props.inputName||\"uploadcare_file\",value:fileUrl||\"\",required:props.required})]});}addPropertyControls(UploadcareUploader,{required:{type:ControlType.Boolean,title:\"Required\",defaultValue:false},publicKey:{type:ControlType.String,title:\"Uploadcare Key\",placeholder:\"demopublickey\",defaultValue:\"demopublickey\"},buttonText:{type:ControlType.String,title:\"Button Text\",defaultValue:\"Choose File\"},buttonBg:{type:ControlType.Color,title:\"Button BG\",defaultValue:\"#0099FF\"},buttonTextColor:{type:ControlType.Color,title:\"Button Text\",defaultValue:\"#222\"},buttonRadius:{type:ControlType.Number,title:\"Button Radius\",defaultValue:8,min:0,max:32},buttonPadding:{type:ControlType.Padding,title:\"Button Padding\",defaultValue:\"8px 18px\"},buttonFont:{type:ControlType.Font,title:\"Button Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:15,variant:\"Semibold\",letterSpacing:\"-0.01em\",lineHeight:\"1em\"}},uploadedUrl:{type:ControlType.String,title:\"Uploaded URL\",defaultValue:\"\",placeholder:\"(auto)\"},inputName:{type:ControlType.String,title:\"Input Name\",defaultValue:\"uploadcare_file\",placeholder:\"Field name for form\"},filenameColor:{type:ControlType.Color,title:\"Filename Color\",defaultValue:\"#222\"},progressBarColor:{type:ControlType.Color,title:\"Progress Color\",defaultValue:\"#0099FF\"},progressBarBg:{type:ControlType.Color,title:\"Progress BG\",defaultValue:\"#F5F5F5\"},progressBarHeight:{type:ControlType.Number,title:\"Progress Height\",defaultValue:6,min:2,max:24,unit:\"px\"},progressBarRadius:{type:ControlType.Number,title:\"Progress Radius\",defaultValue:3,min:0,max:24,unit:\"px\"},allowedFileTypes:{type:ControlType.String,title:\"Allowed Types\",defaultValue:\"\",placeholder:\"e.g. jpg,png,pdf\",description:\"Comma-separated list of allowed file extensions (e.g. jpg,png,pdf)\"},maxFileSize:{type:ControlType.Number,title:\"Max File Size (MB)\",defaultValue:0,min:0,max:1e3,step:1,description:\"Set to 0 for unlimited. Files larger than this will be rejected.\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"UploadcareUploader\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerContractVersion\":\"1\",\"framerIntrinsicWidth\":\"320\",\"framerSupportedLayoutHeight\":\"auto\",\"framerIntrinsicHeight\":\"60\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./UploadcareUploader.map"],"mappings":"gNASG,SAAwB,EAAmB,EAAM,CAAC,GAAK,CAAC,YAAU,aAAW,cAAY,QAAM,WAAS,UAAU,kBAAgB,OAAO,eAAa,EAAE,aAAW,EAAE,EAAE,EAAW,CAAC,EAAQ,GAAYA,EAAS,EAAY,CAAM,CAAC,EAAS,GAAaA,EAAS,GAAG,CAAO,EAASC,EAAO,KAAK,CAAM,CAAC,EAAa,GAAiBD,EAAS,GAAM,CAAM,CAAC,EAAU,GAAcA,EAAS,GAAM,CAAM,CAAC,EAAS,GAAaA,EAAS,EAAE,CAAM,CAAC,EAAM,GAAUA,EAAS,GAAG,CAC3c,EAAgB,IAAS,SAAc,EAAO,UAAU,UAAU,SAAS,UAAU,EAAE,EAAO,UAAU,UAAU,SAAS,UAAU,EAC3I,MAAc,CAAuC,GAA5B,IAAS,QAAsB,EAAa,OAAO,GAAG,SAAS,eAAe,2BAA2B,CAAC,CAAC,EAAgB,GAAK,CAAC,OAAQ,IAAM,EAAO,SAAS,cAAc,SAAS,CAAC,EAAO,IAAI,iEAAiE,EAAO,MAAM,GAAK,EAAO,GAAG,2BAA2B,EAAO,WAAW,EAAgB,GAAK,CAAC,SAAS,KAAK,YAAY,EAAO,EAAG,CAAC,EAAa,CAAC,CAC9a,SAAS,GAAY,CAAC,GAAU,IAAS,QAAa,CAAC,EAAa,OAAO,EAAS,GAAG,CACvF,IAAM,EA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