{"version":3,"file":"FileUploadInput.DVSLH_Es.mjs","names":["useState","useRef","__esmMin","init_npm_react_18_3_1","ce","init_jsx_runtime","c","p","_e","de","motion","addPropertyControls","init_framer_BWFVvmND","ControlType","borderProp","fillProp","iconProp","Icon","createId","Border","init_FramerFormsShared","createBackground","HiddenInput","FileUploadInput","props","id","isVertical","focused","setFocused","invalid","setInvalid","fileName","setFileName","fileUploadUrl","setFileUploadUrl","inputRef","_props_invalidEvent","onFocus","_props_focusEvent","onBlur","_props_blurEvent","fileTypes","fileTypeStrings","fileType","onFileChange","file","event","result","uploadFile","onKeyDown","_inputRef_current","shadows","border","icon","layout","MAX_SIZE_LIMIT_MB","fetchPresignedURL","postToPresignedURL","presignedUrl","resolve","reject","presignedUrlApi","responseBody","response","removeURLParameters","url","urlString","init_FileUploadInput"],"sources":["https:/framerusercontent.com/modules/UXNWRabX0IeVTgbvsbAG/L8FV6c3bxSRcKG1QSrwj/FileUploadInput.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{useState,useEffect,useRef}from\"react\";import{motion}from\"framer\";import{createBackground,Border,borderProp,fillProp,createId,iconProp,Icon,HiddenInput}from\"https://framerusercontent.com/modules/DwWOdDzQZGCuvkNlbUjZ/RhTkfEJwV2NS1uN2FS3e/FramerFormsShared.js\";const presignedUrlApi=\"https://api.framerforms.com/s3/signed-url\";const MAX_SIZE_LIMIT_MB=25;const MAX_SIZE_LIMIT=MAX_SIZE_LIMIT_MB*1024*1024// 25MB in bytes\n;/**\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight any\n * @framerIntrinsicWidth 400\n */export default function FileUploadInput(props){const{shadows,border,layout,icon}=props;const id=createId();const isVertical=props.layout.direction==\"vertical\";const[focused,setFocused]=useState(false);const[invalid,setInvalid]=useState(false);const[fileName,setFileName]=useState(\"\");const[fileUploadUrl,setFileUploadUrl]=useState(\"\");const inputRef=useRef(null);useEffect(()=>{if(invalid){var _props_invalidEvent;(_props_invalidEvent=props.invalidEvent)===null||_props_invalidEvent===void 0?void 0:_props_invalidEvent.call(props);}},[invalid]);function onFocus(){var _props_focusEvent;setFocused(true);(_props_focusEvent=props.focusEvent)===null||_props_focusEvent===void 0?void 0:_props_focusEvent.call(props);if(invalid){setInvalid(false);}}function onBlur(){var _props_blurEvent;setFocused(false);(_props_blurEvent=props.blurEvent)===null||_props_blurEvent===void 0?void 0:_props_blurEvent.call(props);}let fileTypes=\"\";switch(props.fileTypes){case\"audio\":fileTypes=\"audio/*\";break;case\"video\":fileTypes=\"video/*\";break;case\"image\":fileTypes=\"image/*\";break;case\"custom\":const fileTypeStrings=[];for(const fileType of props.fileTypesCustom){if(fileType.startsWith(\".\")||fileType==\"audio/*\"||fileType==\"video/*\"||fileType==\"image/*\"){fileTypeStrings.push(fileType);}else{fileTypeStrings.push(`.${fileType}`);}}fileTypes=fileTypeStrings.join(\",\");break;}async function onFileChange(event){const file=event.target.files[0];setFileName(file?file.name:\"\");const result=await uploadFile(file);setFileUploadUrl((result===null||result===void 0?void 0:result.fileLocation)||\"\");}function onKeyDown(event){if(event.key==\"Enter\"){var _inputRef_current;(_inputRef_current=inputRef.current)===null||_inputRef_current===void 0?void 0:_inputRef_current.click();}}return /*#__PURE__*/_jsxs(motion.div,{onFocus:onFocus,onBlur:onBlur,onKeyDown:onKeyDown,animate:{...createBackground(props.fill,null,focused,invalid),boxShadow:invalid&&(shadows===null||shadows===void 0?void 0:shadows.invalid)||focused&&(shadows===null||shadows===void 0?void 0:shadows.focus)||(shadows===null||shadows===void 0?void 0:shadows.default),borderColor:invalid&&(border===null||border===void 0?void 0:border.colorInvalid)||focused&&(border===null||border===void 0?void 0:border.colorFocus)||(border===null||border===void 0?void 0:border.color)},style:{borderRadius:props.radius,padding:props.padding,color:props.color,display:\"flex\",flexDirection:`${isVertical?\"column\":\"row\"}${(icon===null||icon===void 0?void 0:icon.location)==\"end\"?\"-reverse\":\"\"}`,alignItems:isVertical?layout.alignH:\"center\",justifyContent:isVertical?\"center\":layout.alignH,gap:layout.gap,textAlign:\"center\",...props.font,...props.style},initial:false,transition:props.transition,children:[/*#__PURE__*/_jsx(HiddenInput,{name:props.name,required:props.required,value:fileUploadUrl,setInvalid:setInvalid,noPrefill:true}),/*#__PURE__*/_jsx(\"input\",{ref:inputRef,type:\"file\",accept:fileTypes,autoFocus:props.autoFocus,onChange:onFileChange,style:{position:\"absolute\",inset:0,opacity:0,cursor:\"pointer\"},\"data-framerforms-no-prefill\":true}),icon&&/*#__PURE__*/_jsx(Icon,{...icon,defaultImage:`url('data:image/svg+xml,${encodeURIComponent(`<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"28\" height=\"28\"><path d=\"M 9.366 18.419 C 8.284 18.422 7.242 18.009 6.456 17.266 C 5.69 16.541 5.254 15.535 5.25 14.481 C 5.25 13.437 5.684 12.436 6.456 11.697 C 7.242 10.953 8.284 10.54 9.366 10.544 C 9.624 9.395 10.378 8.385 11.463 7.738 C 12.009 7.413 12.61 7.191 13.235 7.082 C 13.869 6.971 14.518 6.973 15.152 7.088 C 15.783 7.202 16.383 7.429 16.919 7.753 C 17.445 8.068 17.903 8.483 18.269 8.975 C 18.626 9.458 18.873 10 18.997 10.57 C 19.121 11.139 19.12 11.725 18.992 12.294 L 19.867 12.294 C 21.558 12.294 22.929 13.665 22.929 15.356 C 22.929 17.048 21.558 18.419 19.867 18.419 L 18.992 18.419\" fill=\"transparent\" stroke-width=\"1.75\" stroke=\"white\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></path><path d=\"M 11.117 15.794 L 13.742 13.169 L 16.367 15.794 M 13.742 13.169 L 13.742 21.044\" fill=\"transparent\" stroke-width=\"1.75\" stroke=\"white\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></path><path d=\"M 0.6 5.85 C 0.6 2.951 2.951 0.6 5.85 0.6 L 22.15 0.6 C 25.049 0.6 27.4 2.951 27.4 5.85 L 27.4 22.15 C 27.4 25.049 25.049 27.4 22.15 27.4 L 5.85 27.4 C 2.951 27.4 0.6 25.049 0.6 22.15 Z\" fill=\"transparent\" stroke-width=\"1.2\" stroke=\"white\"></path></svg>`)}')`}),fileName.length?fileName:props.text.replace(\"##\",MAX_SIZE_LIMIT_MB.toString()),/*#__PURE__*/_jsx(Border,{...props.border}),/*#__PURE__*/_jsx(\"style\",{children:`\n            #${id} input:focus {\n                outline: none;\n            }`})]});}FileUploadInput.displayName=\"File Upload\";addPropertyControls(FileUploadInput,{userId:{type:ControlType.String,defaultValue:\"\",placeholder:\"FramerForms User ID\",title:\"User ID\",description:\"Get your user ID [here](https://app.framerforms.com/dashboard/account)\",hidden:props=>true},name:{type:ControlType.String,defaultValue:\"File\"},required:{type:ControlType.Boolean,defaultValue:false},autoFocus:{type:ControlType.Boolean,defaultValue:false,title:\"Auto-Focus\"},fileTypes:{type:ControlType.Enum,defaultValue:\"all\",options:[\"all\",\"audio\",\"video\",\"image\",\"custom\"],optionTitles:[\"Any File\",\"Any Audio File\",\"Any Video File\",\"Any Image File\",\"Custom\"]},fileTypesCustom:{type:ControlType.Array,defaultValue:[\".pdf\"],control:{type:ControlType.String,placeholder:\".pdf\"},title:\" \",hidden:props=>props.fileTypes!==\"custom\"},text:{type:ControlType.String,defaultValue:`Click to upload file or drag-and-drop. Max ##mb`,description:\"*##* → max size in MB\"},layout:{type:ControlType.Object,controls:{direction:{type:ControlType.Enum,defaultValue:\"vertical\",options:[\"horizontal\",\"vertical\"],optionTitles:[\"Horizontal\",\"Vertical\"],optionIcons:[\"direction-horizontal\",\"direction-vertical\"],displaySegmentedControl:true},alignH:{type:ControlType.Enum,defaultValue:\"center\",options:[\"start\",\"center\",\"end\"],optionTitles:[\"Left\",\"Center\",\"Right\"],displaySegmentedControl:true,title:\"Align\"},gap:{type:ControlType.Number,defaultValue:12,min:0,step:1}}},font:{type:\"font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:14,lineHeight:1.2}},color:{type:ControlType.Color,defaultValue:\"#999999\",title:\"Color\"},fill:fillProp({}),radius:{type:ControlType.BorderRadius,defaultValue:\"10px\"},padding:{type:ControlType.Padding,defaultValue:\"12px\"},icon:iconProp({size:28,controls:{location:{type:ControlType.Enum,options:[\"start\",\"end\"],optionTitles:[\"Start\",\"End\"],displaySegmentedControl:true}}}),border:borderProp({}),shadows:{type:ControlType.Object,buttonTitle:\"Shadows\",optional:true,controls:{default:{type:ControlType.BoxShadow},focus:{type:ControlType.BoxShadow}}},transition:{type:ControlType.Transition,defaultValue:{type:false}},focusEvent:{type:ControlType.EventHandler,title:\"Focus\"},blurEvent:{type:ControlType.EventHandler,title:\"Blur\"},invalidEvent:{type:ControlType.EventHandler,title:\"Invalid\"}});function uploadFile(file){return new Promise((resolve,reject)=>{fetchPresignedURL(file).then(({presignedUrl})=>postToPresignedURL(file,presignedUrl)).then(resolve).catch(reject);});}function fetchPresignedURL(file){var _file_name;return fetch(presignedUrlApi,{method:\"POST\",body:JSON.stringify({file_name:(_file_name=file.name)===null||_file_name===void 0?void 0:_file_name.replace(/\\s+/g,\"-\")}),headers:{\"Content-Type\":\"application/json\"}}).then(async response=>{const responseBody=await response.json();if(response.status>200){throw new Error(responseBody.errorMessage);}return responseBody;});}function postToPresignedURL(file,presignedUrl){return new Promise((resolve,reject)=>{fetch(presignedUrl,{method:\"PUT\",body:file}).then(()=>resolve({fileLocation:removeURLParameters(presignedUrl)})).catch(reject);});}function removeURLParameters(urlString){const url=new URL(urlString);url.search=\"\";return url.toString();}\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"FileUploadInput\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"fixed\",\"framerContractVersion\":\"1\",\"framerIntrinsicWidth\":\"400\",\"framerSupportedLayoutHeight\":\"any\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./FileUploadInput.map"],"mappings":"A,8UAKG,SAAwBuB,EAAgB,EAAM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