inertia-bootstrap-forms 1.0.63 → 1.0.65

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.
@@ -1,4 +1,4 @@
1
- import { A as n, C as s, a as u, b as p, c as o, _ as e, d as I, E as i, F as r, f as l, m as c, G as m, L as b, M as S, h as C, g as d, P as x, Q as g, R as h, j as k, l as y, S as F, k as P, i as T, n as A, o as B, p as E, e as L } from "./index-BON97lSo.js";
1
+ import { A as n, C as s, a as u, b as p, c as o, _ as e, d as I, E as i, F as r, f as l, m as c, G as m, L as b, M as S, h as C, g as d, P as x, Q as g, R as h, j as k, l as y, S as F, k as P, i as T, n as A, o as B, p as E, e as L } from "./index-Z78XhfO_.js";
2
2
  export {
3
3
  n as AmountInput,
4
4
  s as CaptchaInput,
@@ -16,4 +16,4 @@
16
16
  * ${l.message}`}),this.info({message:this.i18n("addBulkFilesFailed",{smart_count:o.length}),details:a},"error",this.opts.infoTimeout),typeof AggregateError=="function")throw new AggregateError(o,a);{const l=new Error(a);throw l.errors=o,l}}this.setState({files:n}),i.forEach(a=>{this.emit("file-added",a)}),this.emit("files-added",i),i.length>5?this.log(`Added batch of ${i.length} files`):Object.values(i).forEach(a=>{this.log(`Added file: ${a.name}
17
17
  id: ${a.id}
18
18
  type: ${a.type}`)}),i.length>0&&V(this,L,Fs).call(this)}removeFiles(e){const{files:n,currentUploads:i}=this.getState(),r={...n},s={...i},o=Object.create(null);e.forEach(d=>{n[d]&&(o[d]=n[d],delete r[d])});function a(d){return o[d]===void 0}Object.keys(s).forEach(d=>{const f=i[d].fileIDs.filter(a);if(f.length===0){delete s[d];return}const{capabilities:h}=this.getState();if(f.length!==i[d].fileIDs.length&&!h.individualCancellation)throw new Error("The installed uploader plugin does not allow removing files during an upload.");s[d]={...i[d],fileIDs:f}});const l={currentUploads:s,files:r};Object.keys(r).length===0&&(l.allowNewUpload=!0,l.error=null,l.recoveredState=null),this.setState(l),E(this,Yt).call(this);const c=Object.keys(o);c.forEach(d=>{this.emit("file-removed",o[d])}),c.length>5?this.log(`Removed ${c.length} files`):this.log(`Removed files: ${c.join(", ")}`)}removeFile(e){this.removeFiles([e])}pauseResume(e){if(!this.getState().capabilities.resumableUploads||this.getFile(e).progress.uploadComplete)return;const n=this.getFile(e),r=!(n.isPaused||!1);return this.setFileState(e,{isPaused:r}),this.emit("upload-pause",n,r),r}pauseAll(){const e={...this.getState().files};Object.keys(e).filter(i=>!e[i].progress.uploadComplete&&e[i].progress.uploadStarted).forEach(i=>{const r={...e[i],isPaused:!0};e[i]=r}),this.setState({files:e}),this.emit("pause-all")}resumeAll(){const e={...this.getState().files};Object.keys(e).filter(i=>!e[i].progress.uploadComplete&&e[i].progress.uploadStarted).forEach(i=>{const r={...e[i],isPaused:!1,error:null};e[i]=r}),this.setState({files:e}),this.emit("resume-all")}async retryAll(){const e=await V(this,L,Ms).call(this);return this.emit("complete",e),e}cancelAll(){this.emit("cancel-all");const{files:e}=this.getState(),n=Object.keys(e);n.length&&this.removeFiles(n),this.setState(Yi)}retryUpload(e){this.setFileState(e,{error:null,isPaused:!1}),this.emit("upload-retry",this.getFile(e));const n=V(this,L,ui).call(this,[e],{forceAllowNewUpload:!0});return V(this,L,di).call(this,n)}logout(){this.iteratePlugins(e=>{var n,i;(i=(n=e.provider)==null?void 0:n.logout)==null||i.call(n)})}[Symbol.for("uppy test: updateTotalProgress")](){return V(this,L,Ds).call(this)}updateOnlineStatus(){window.navigator.onLine??!0?(this.emit("is-online"),this.wasOffline&&(this.emit("back-online"),this.info(this.i18n("connectedToInternet"),"success",3e3),this.wasOffline=!1)):(this.emit("is-offline"),this.info(this.i18n("noInternetConnection"),"error",0),this.wasOffline=!0)}getID(){return this.opts.id}use(e,...n){if(typeof e!="function"){const o=`Expected a plugin class, but got ${e===null?"null":typeof e}. Please verify that the plugin was imported and spelled correctly.`;throw new TypeError(o)}const i=new e(this,...n),r=i.id;if(!r)throw new Error("Your plugin must have an id");if(!i.type)throw new Error("Your plugin must have a type");const s=this.getPlugin(r);if(s){const o=`Already found a plugin named '${s.id}'. Tried to use: '${r}'.
19
- Uppy plugins must have unique \`id\` options.`;throw new Error(o)}return e.VERSION&&this.log(`Using ${r} v${e.VERSION}`),i.type in E(this,ze)?E(this,ze)[i.type].push(i):E(this,ze)[i.type]=[i],i.install(),this.emit("plugin-added",i),this}getPlugin(e){for(const n of Object.values(E(this,ze))){const i=n.find(r=>r.id===e);if(i!=null)return i}}[Symbol.for("uppy test: getPlugins")](e){return E(this,ze)[e]}iteratePlugins(e){Object.values(E(this,ze)).flat(1).forEach(e)}removePlugin(e){this.log(`Removing plugin ${e.id}`),this.emit("plugin-remove",e),e.uninstall&&e.uninstall();const n=E(this,ze)[e.type],i=n.findIndex(o=>o.id===e.id);i!==-1&&n.splice(i,1);const s={plugins:{...this.getState().plugins,[e.id]:void 0}};this.setState(s)}destroy(){this.log(`Closing Uppy instance ${this.opts.id}: removing all files and uninstalling plugins`),this.cancelAll(),E(this,Qn).call(this),this.iteratePlugins(e=>{this.removePlugin(e)}),typeof window<"u"&&window.removeEventListener&&(window.removeEventListener("online",E(this,kt)),window.removeEventListener("offline",E(this,kt)))}hideInfo(){const{info:e}=this.getState();this.setState({info:e.slice(1)}),this.emit("info-hidden")}info(e,n="info",i=3e3){const r=typeof e=="object";this.setState({info:[...this.getState().info,{type:n,message:r?e.message:e,details:r?e.details:null}]}),setTimeout(()=>this.hideInfo(),i),this.emit("info-visible")}log(e,n){const{logger:i}=this.opts;switch(n){case"error":i.error(e);break;case"warning":i.warn(e);break;default:i.debug(e);break}}registerRequestClient(e,n){E(this,Zn).set(e,n)}getRequestClientForFile(e){if(!("remote"in e&&e.remote))throw new Error(`Tried to get RequestClient for a non-remote file ${e.id}`);const n=E(this,Zn).get(e.remote.requestClientId);if(n==null)throw new Error(`requestClientId "${e.remote.requestClientId}" not registered for file "${e.id}"`);return n}async restore(e){this.log(`Core: Running restored upload "${e}"`);const n=await V(this,L,di).call(this,e);return this.emit("complete",n),n}[Symbol.for("uppy test: createUpload")](...e){return V(this,L,ui).call(this,...e)}addResultData(e,n){if(!V(this,L,nu).call(this,e)){this.log(`Not setting result for an upload that has been removed: ${e}`);return}const{currentUploads:i}=this.getState(),r={...i[e],result:{...i[e].result,...n}};this.setState({currentUploads:{...i,[e]:r}})}async upload(){var r;(r=E(this,ze).uploader)!=null&&r.length||this.log("No uploader type plugins are used","warning");let{files:e}=this.getState();if(V(this,L,Ps).call(this).length>0){const s=await V(this,L,Ms).call(this);if(!(this.getFiles().filter(a=>a.progress.uploadStarted==null).length>0))return this.emit("complete",s),s;({files:e}=this.getState())}const i=this.opts.onBeforeUpload(e);if(i===!1)throw new Error("Not starting the upload because onBeforeUpload returned false");i&&typeof i=="object"&&(e=i,this.setState({files:e}));try{if(E(this,qe).validateMinNumberOfFiles(e),!V(this,L,Qc).call(this,e))throw new xe(this.i18n("missingRequiredMetaField"));const{currentUploads:s}=this.getState(),o=Object.values(s).flatMap(d=>d.fileIDs),a=Object.keys(e).filter(d=>{const f=this.getFile(d);return f&&!f.progress.uploadStarted&&!o.includes(d)}),l=V(this,L,ui).call(this,a),c=await V(this,L,di).call(this,l);return this.emit("complete",c),c}catch(s){throw V(this,L,Zt).call(this,[s]),s}}};ze=new WeakMap,qe=new WeakMap,Qn=new WeakMap,Wt=new WeakMap,Tn=new WeakMap,Fn=new WeakMap,Gt=new WeakMap,L=new WeakSet,Zt=function(e){for(const o of e)o.isRestriction?this.emit("restriction-failed",o.file,o):this.emit("error",o,o.file),this.log(o,"warning");const n=e.filter(o=>o.isUserFacing),i=4,r=n.slice(0,i),s=n.slice(i);r.forEach(({message:o,details:a=""})=>{this.info({message:o,details:a},"error",this.opts.infoTimeout)}),s.length>0&&this.info({message:this.i18n("additionalRestrictionsFailed",{count:s.length})})},Ts=function(e){const{missingFields:n,error:i}=E(this,qe).getMissingRequiredMetaFields(e);return n.length>0?(this.setFileState(e.id,{missingRequiredMetaFields:n,error:i.message}),this.log(i.message),this.emit("restriction-failed",e,i),!1):(n.length===0&&e.missingRequiredMetaFields&&this.setFileState(e.id,{missingRequiredMetaFields:[]}),!0)},Qc=function(e){let n=!0;for(const i of Object.values(e))V(this,L,Ts).call(this,i)||(n=!1);return n},Zc=function(e){const{allowNewUpload:n}=this.getState();if(n===!1){const i=new xe(this.i18n("noMoreFilesAllowed"),{file:e});throw V(this,L,Zt).call(this,[i]),i}},Jc=function(e){const n=e instanceof File?{name:e.name,type:e.type,size:e.size,data:e,meta:{},isRemote:!1,source:void 0,preview:void 0}:e,i=Sc(n),r=Y0(i,n),s=wc(r).extension,o=v_(n,this.getID()),a={...n.meta,name:r,type:i},l=Number.isFinite(n.data.size)?n.data.size:null;return{source:n.source||"",id:o,name:r,extension:s||"",meta:{...this.getState().meta,...a},type:i,progress:{percentage:0,bytesUploaded:!1,bytesTotal:l,uploadComplete:!1,uploadStarted:null},size:l,isGhost:!1,...n.isRemote?{isRemote:!0,remote:n.remote,data:n.data}:{isRemote:!1,data:n.data},preview:n.preview}},Fs=function(){this.opts.autoProceed&&!this.scheduledAutoProceed&&(this.scheduledAutoProceed=setTimeout(()=>{this.scheduledAutoProceed=null,this.upload().catch(e=>{e.isRestriction||this.log(e.stack||e.message||e)})},4))},Ns=function(e){let{files:n}=this.getState(),i={...n};const r=[],s=[];for(const o of e)try{let a=V(this,L,Jc).call(this,o);V(this,L,Zc).call(this,a);const l=n[a.id],c=l==null?void 0:l.isGhost;if(c&&!a.isRemote){if(a.data==null)throw new Error("File data is missing");a={...l,isGhost:!1,data:a.data},this.log(`Replaced the blob in the restored ghost file: ${a.name}, ${a.id}`)}const d=this.opts.onBeforeFileAdded(a,i);if(n=this.getState().files,i={...n,...i},!d&&this.checkIfFileAlreadyExists(a.id))throw new xe(this.i18n("noDuplicates",{fileName:a.name??this.i18n("unnamed")}),{file:a});if(d===!1&&!c)throw new xe("Cannot add the file because onBeforeFileAdded returned false.",{isUserFacing:!1,file:a});typeof d=="object"&&d!==null&&(a=d),E(this,qe).validateSingleFile(a),i[a.id]=a,r.push(a)}catch(a){s.push(a)}try{E(this,qe).validateAggregateRestrictions(Object.values(n),r)}catch(o){return s.push(o),{nextFilesState:n,validFilesToAdd:[],errors:s}}return{nextFilesState:i,validFilesToAdd:r,errors:s}},Ps=function(){const{files:e}=this.getState();return Object.keys(e).filter(n=>{const i=e[n];return i.error&&(!i.missingRequiredMetaFields||i.missingRequiredMetaFields.length===0)})},Ms=async function(){const e=V(this,L,Ps).call(this),n={...this.getState().files};if(e.forEach(r=>{n[r]={...n[r],isPaused:!1,error:null}}),this.setState({files:n,error:null}),this.emit("retry-all",this.getFilesByIds(e)),e.length===0)return{successful:[],failed:[]};const i=V(this,L,ui).call(this,e,{forceAllowNewUpload:!0});return V(this,L,di).call(this,i)},Zi=new WeakMap,Ds=function(){const e=V(this,L,eu).call(this);let n=null;e!=null&&(n=Math.round(e*100),n>100?n=100:n<0&&(n=0)),this.emit("progress",n??0),this.setState({totalProgress:n??0})},Yt=new WeakMap,eu=function(){const n=this.getFiles().filter(l=>l.progress.uploadStarted||l.progress.preprocess||l.progress.postprocess);if(n.length===0)return 0;if(n.every(l=>l.progress.uploadComplete))return 1;const i=l=>l.progress.bytesTotal!=null&&l.progress.bytesTotal!==0,r=n.filter(i),s=n.filter(l=>!i(l));if(r.every(l=>l.progress.uploadComplete)&&s.length>0&&!s.every(l=>l.progress.uploadComplete))return null;const o=r.reduce((l,c)=>l+(c.progress.bytesTotal??0),0),a=r.reduce((l,c)=>l+(c.progress.bytesUploaded||0),0);return o===0?0:a/o},tu=function(){const e=(r,s,o)=>{let a=r.message||"Unknown error";r.details&&(a+=` ${r.details}`),this.setState({error:a}),s!=null&&s.id in this.getState().files&&this.setFileState(s.id,{error:a,response:o})};this.on("error",e),this.on("upload-error",(r,s,o)=>{if(e(s,r,o),typeof s=="object"&&s.message){this.log(s.message,"error");const a=new Error(this.i18n("failedToUpload",{file:(r==null?void 0:r.name)??""}));a.isUserFacing=!0,a.details=s.message,s.details&&(a.details+=` ${s.details}`),V(this,L,Zt).call(this,[a])}else V(this,L,Zt).call(this,[s])});let n=null;this.on("upload-stalled",(r,s)=>{const{message:o}=r,a=s.map(l=>l.meta.name).join(", ");n||(this.info({message:o,details:a},"warning",this.opts.infoTimeout),n=setTimeout(()=>{n=null},this.opts.infoTimeout)),this.log(`${o} ${a}`.trim(),"warning")}),this.on("upload",()=>{this.setState({error:null})});const i=r=>{const s=r.filter(a=>{const l=a!=null&&this.getFile(a.id);return l||this.log(`Not setting progress for a file that has been removed: ${a==null?void 0:a.id}`),l}),o=Object.fromEntries(s.map(a=>[a.id,{progress:{uploadStarted:Date.now(),uploadComplete:!1,bytesUploaded:0,bytesTotal:a.size}}]));this.patchFilesState(o)};this.on("upload-start",i),this.on("upload-progress",E(this,Zi)),this.on("upload-success",(r,s)=>{if(r==null||!this.getFile(r.id)){this.log(`Not setting progress for a file that has been removed: ${r==null?void 0:r.id}`);return}const o=this.getFile(r.id).progress,a=E(this,Gt).size>0;this.setFileState(r.id,{progress:{...o,postprocess:a?{mode:"indeterminate"}:void 0,uploadComplete:!0,...!a&&{complete:!0},percentage:100,bytesUploaded:o.bytesTotal},response:s,uploadURL:s.uploadURL,isPaused:!1}),r.size==null&&this.setFileState(r.id,{size:s.bytesUploaded||o.bytesTotal}),E(this,Yt).call(this)}),this.on("preprocess-progress",(r,s)=>{if(r==null||!this.getFile(r.id)){this.log(`Not setting progress for a file that has been removed: ${r==null?void 0:r.id}`);return}this.setFileState(r.id,{progress:{...this.getFile(r.id).progress,preprocess:s}})}),this.on("preprocess-complete",r=>{if(r==null||!this.getFile(r.id)){this.log(`Not setting progress for a file that has been removed: ${r==null?void 0:r.id}`);return}const s={...this.getState().files};s[r.id]={...s[r.id],progress:{...s[r.id].progress}},delete s[r.id].progress.preprocess,this.setState({files:s})}),this.on("postprocess-progress",(r,s)=>{if(r==null||!this.getFile(r.id)){this.log(`Not setting progress for a file that has been removed: ${r==null?void 0:r.id}`);return}this.setFileState(r.id,{progress:{...this.getState().files[r.id].progress,postprocess:s}})}),this.on("postprocess-complete",r=>{const s=r&&this.getFile(r.id);if(s==null){this.log(`Not setting progress for a file that has been removed: ${r==null?void 0:r.id}`);return}const{postprocess:o,...a}=s.progress;this.patchFilesState({[s.id]:{progress:{...a,complete:!0}}})}),this.on("restored",()=>{E(this,Yt).call(this)}),this.on("dashboard:file-edit-complete",r=>{r&&V(this,L,Ts).call(this,r)}),typeof window<"u"&&window.addEventListener&&(window.addEventListener("online",E(this,kt)),window.addEventListener("offline",E(this,kt)),setTimeout(E(this,kt),3e3))},kt=new WeakMap,Zn=new WeakMap,ui=function(e,n={}){const{forceAllowNewUpload:i=!1}=n,{allowNewUpload:r,currentUploads:s}=this.getState();if(!r&&!i)throw new Error("Cannot create a new upload: already uploading.");const o=W0();return this.emit("upload",o,this.getFilesByIds(e)),this.setState({allowNewUpload:this.opts.allowMultipleUploadBatches!==!1&&this.opts.allowMultipleUploads!==!1,currentUploads:{...s,[o]:{fileIDs:e,step:0,result:{}}}}),o},nu=function(e){const{currentUploads:n}=this.getState();return n[e]},$s=function(e){const{[e]:n,...i}=this.getState().currentUploads;this.setState({currentUploads:i})},di=async function(e){const n=()=>{const{currentUploads:o}=this.getState();return o[e]};let i=n();if(!i)throw new Error("Nonexistent upload");const r=[...E(this,Tn),...E(this,Fn),...E(this,Gt)];try{for(let o=i.step||0;o<r.length;o++){const a=r[o];this.setState({currentUploads:{...this.getState().currentUploads,[e]:{...i,step:o}}});const{fileIDs:l}=i;if(await a(l,e),i=n(),!i)break}}catch(o){throw V(this,L,$s).call(this,e),o}if(i){i.fileIDs.forEach(c=>{const d=this.getFile(c);d!=null&&d.progress.postprocess&&this.emit("postprocess-complete",d)});const o=i.fileIDs.map(c=>this.getFile(c)),a=o.filter(c=>!c.error),l=o.filter(c=>c.error);this.addResultData(e,{successful:a,failed:l,uploadID:e}),i=n()}let s;return i&&(s=i.result,V(this,L,$s).call(this,e)),s==null&&(this.log(`Not setting result for an upload that has been removed: ${e}`),s={successful:[],failed:[],uploadID:e}),s},j(Ji,"VERSION",G0.version);let Ss=Ji;const Z0={__name:"UppyInput",props:{name:{type:String,required:!0},multiple:{type:Boolean,default:!1},useXHR:{type:Boolean,default:!0},XHRConfig:{type:Object,default:{}},url:{type:String,default:"/upload"},config:{type:Object,default:()=>({})},errorHandler:{type:Function,default:null}},emits:["update:modelValue","file-added","file-removed","beforeUpload","progress","upload","upload-progress","upload-error","upload-success","upload-pause","complete","error","upload-retry","upload-stalled","retry-all","cancel-all","restriction-failed"],setup(t,{emit:e}){var d;const n=t,i=e,r=u.ref(null),s=u.shallowRef(null),o=u.inject("form",{value:{},errors:{},getID:f=>f}),a=u.inject("group",null),l=u.computed({get(){var f;return(f=a==null?void 0:a.value)!=null&&f.name?a.value.getData(n.name):o.value[n.name]},set(f){var h;(h=a==null?void 0:a.value)!=null&&h.name?a.value.setData(n.name,f):o.value[n.name]=f,i("update:modelValue",f)}});s.value=new Ss({id:n.name,autoProceed:!0,...n.config,restrictions:{maxNumberOfFiles:n.multiple?10:1,...((d=n.config)==null?void 0:d.restrictions)||{}}}),s.value.on("before-upload",f=>{i("beforeUpload",f)}),s.value.on("upload-success",(f,h)=>{const g=h.body??h;if(n.multiple){const m=Array.isArray(l.value)?l.value:[];l.value=[...m,g]}else l.value=g;i("upload-success",f,h)}),s.value.on("file-added",f=>i("file-added",f)),s.value.on("file-removed",f=>{var h;if(n.multiple&&Array.isArray(l.value)){const g=((h=f.response)==null?void 0:h.body)??f.response;l.value=l.value.filter(m=>JSON.stringify(m)!==JSON.stringify(g))}else l.value=null;f.response&&fetch(n.url,{method:"DELETE",headers:{"X-Requested-With":"XMLHttpRequest","Content-Type":"application/json"},body:JSON.stringify(f.response.body??f.response)}),i("file-removed",f)}),s.value.on("complete",f=>i("complete",f)),s.value.on("error",f=>i("error",f)),s.value.on("restriction-failed",(f,h)=>{n.errorHandler?n.errorHandler(h):c(h.message),i("restriction-failed",f,h)}),u.onMounted(()=>{let f;n.useXHR&&Promise.resolve().then(()=>ib).then(h=>{f=h.default,s.value.use(f,{endpoint:n.url,formData:!0,headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest"},...n.XHRConfig})})}),u.onBeforeUnmount(()=>{s.value&&s.value.destroy()});function c(f){const h=document.createElement("div");h.textContent=f,h.className="uppy-error",r.value&&(r.value.prepend(h),setTimeout(()=>h.remove(),3e3))}return(f,h)=>s.value?(u.openBlock(),u.createElementBlock("div",{key:0,class:"uppy-input-area",ref_key:"inputEl",ref:r},[u.createVNode(u.unref(l_),{name:"uu"+t.name,uppy:s.value},{default:u.withCtx(()=>[u.renderSlot(f.$slots,"default",{uppy:s.value},()=>[u.createVNode(u.unref(u_),{class:"uppy-file-lists"}),u.createVNode(u.unref(c_))])]),_:3},8,["name","uppy"])],512)):u.createCommentVNode("",!0)}},J0={version:"5.1.1"},eb={strings:{uploadStalled:"Upload has not made any progress for %{seconds} seconds. You may want to retry it."}};function tb(t,e){let n=e;return n||(n=new Error("Upload error")),typeof n=="string"&&(n=new Error(n)),n instanceof Error||(n=Object.assign(new Error("Upload error"),{data:n})),w_(t)?(n=new bs(n,t),n):(n.request=t,n)}function Rc(t){return t.data.slice(0,t.data.size,t.meta.type)}const nb={formData:!0,fieldName:"file",method:"post",allowedMetaFields:!0,bundle:!1,headers:{},timeout:30*1e3,limit:5,withCredentials:!1,responseType:""};class Hc extends A_{constructor(n,i){super(n,{...nb,fieldName:i.bundle?"files[]":"file",...i});K(this,it);K(this,Nn);j(this,"requests");j(this,"uploaderEvents");K(this,Jn,async n=>{if(n.length===0){this.uppy.log("[XHRUpload] No files to upload!");return}this.opts.limit===0&&!this.opts[vs]&&this.uppy.log("[XHRUpload] When uploading multiple files at once, consider setting the `limit` option (to `10` for example), to limit the number of concurrent uploads, which helps prevent memory and network issues: https://uppy.io/docs/xhr-upload/#limit-0","warning"),this.uppy.log("[XHRUpload] Uploading...");const i=this.uppy.getFilesByIds(n),r=m_(i),s=g_(r);if(this.uppy.emit("upload-start",s),this.opts.bundle){if(r.some(a=>a.isRemote))throw new Error("Can’t upload remote files when the `bundle: true` option is set");if(typeof this.opts.headers=="function")throw new TypeError("`headers` may not be a function when the `bundle: true` option is set");await V(this,it,ru).call(this,r)}else await V(this,it,ou).call(this,r)});if(this.type="uploader",this.id=this.opts.id||"XHRUpload",this.defaultLocale=eb,this.i18nInit(),vs in this.opts?this.requests=this.opts[vs]:this.requests=new S_(this.opts.limit),this.opts.bundle&&!this.opts.formData)throw new Error("`opts.formData` must be true when `opts.bundle` is enabled.");if(this.opts.bundle&&typeof this.opts.headers=="function")throw new Error("`opts.headers` can not be a function when the `bundle: true` option is set.");if((i==null?void 0:i.allowedMetaFields)===void 0&&"metaFields"in this.opts)throw new Error("The `metaFields` option has been renamed to `allowedMetaFields`.");this.uploaderEvents=Object.create(null),re(this,Nn,r=>async(s,o)=>{var a,l;try{const c=await f_(s,{...o,onBeforeRequest:(h,g)=>{var m,p;return(p=(m=this.opts).onBeforeRequest)==null?void 0:p.call(m,h,g,r)},shouldRetry:this.opts.shouldRetry,onAfterResponse:this.opts.onAfterResponse,onTimeout:h=>{const g=Math.ceil(h/1e3),m=new Error(this.i18n("uploadStalled",{seconds:g}));this.uppy.emit("upload-stalled",m,r)},onUploadProgress:h=>{if(h.lengthComputable)for(const{id:g}of r){const m=this.uppy.getFile(g);m!=null&&this.uppy.emit("upload-progress",m,{uploadStarted:m.progress.uploadStarted??0,bytesUploaded:h.loaded/h.total*m.size,bytesTotal:m.size})}}});let d=await((l=(a=this.opts).getResponseData)==null?void 0:l.call(a,c));if(c.responseType==="json")d??(d=c.response);else try{d??(d=JSON.parse(c.responseText))}catch(h){throw new Error("@uppy/xhr-upload expects a JSON response (with a `url` property). To parse non-JSON responses, use `getResponseData` to turn your response into JSON.",{cause:h})}const f=typeof(d==null?void 0:d.url)=="string"?d.url:void 0;for(const{id:h}of r)this.uppy.emit("upload-success",this.uppy.getFile(h),{status:c.status,body:d,uploadURL:f});return c}catch(c){if(c.name==="AbortError")return;const d=c.request;for(const f of r)this.uppy.emit("upload-error",this.uppy.getFile(f.id),tb(d,c),d);throw c}})}getOptions(n){const i=this.uppy.getState().xhrUpload,{headers:r}=this.opts,s={...this.opts,...i||{},...n.xhrUpload||{},headers:{}};return typeof r=="function"?s.headers=r(n):Object.assign(s.headers,this.opts.headers),i&&Object.assign(s.headers,i.headers),n.xhrUpload&&Object.assign(s.headers,n.xhrUpload.headers),s}addMetadata(n,i,r){kc(r.allowedMetaFields,i).forEach(o=>{const a=i[o];Array.isArray(a)?a.forEach(l=>n.append(o,l)):n.append(o,a)})}createFormDataUpload(n,i){const r=new FormData;this.addMetadata(r,n.meta,i);const s=Rc(n);return n.name?r.append(i.fieldName,s,n.meta.name):r.append(i.fieldName,s),r}createBundledUpload(n,i){const r=new FormData,{meta:s}=this.uppy.getState();return this.addMetadata(r,s,i),n.forEach(o=>{const a=this.getOptions(o),l=Rc(o);o.name?r.append(a.fieldName,l,o.name):r.append(a.fieldName,l)}),r}install(){if(this.opts.bundle){const{capabilities:n}=this.uppy.getState();this.uppy.setState({capabilities:{...n,individualCancellation:!1}})}this.uppy.addUploader(E(this,Jn))}uninstall(){if(this.opts.bundle){const{capabilities:n}=this.uppy.getState();this.uppy.setState({capabilities:{...n,individualCancellation:!0}})}this.uppy.removeUploader(E(this,Jn))}}Nn=new WeakMap,it=new WeakSet,iu=async function(n){const i=new I_(this.uppy),r=new AbortController,s=this.requests.wrapPromiseFunction(async()=>{const o=this.getOptions(n),a=E(this,Nn).call(this,[n]),l=o.formData?this.createFormDataUpload(n,o):n.data,c=typeof o.endpoint=="string"?o.endpoint:await o.endpoint(n);return a(c,{...o,body:l,signal:r.signal})});i.onFileRemove(n.id,()=>r.abort()),i.onCancelAll(n.id,()=>{r.abort()});try{await s()}catch(o){if(o.message!=="Cancelled")throw o}finally{i.remove()}},ru=async function(n){const i=new AbortController,r=this.requests.wrapPromiseFunction(async()=>{const o=this.uppy.getState().xhrUpload??{},a=E(this,Nn).call(this,n),l=this.createBundledUpload(n,{...this.opts,...o}),c=typeof this.opts.endpoint=="string"?this.opts.endpoint:await this.opts.endpoint(n);return a(c,{...this.opts,body:l,signal:i.signal})});function s(){i.abort()}this.uppy.once("cancel-all",s);try{await r()}catch(o){if(o.message!=="Cancelled")throw o}finally{this.uppy.off("cancel-all",s)}},su=function(n){var s;const i=this.getOptions(n),r=kc(i.allowedMetaFields,n.meta);return{...(s=n.remote)==null?void 0:s.body,protocol:"multipart",endpoint:i.endpoint,size:n.data.size,fieldname:i.fieldName,metadata:Object.fromEntries(r.map(o=>[o,n.meta[o]])),httpMethod:i.method,useFormData:i.formData,headers:i.headers}},ou=async function(n){await Promise.allSettled(n.map(i=>{if(i.isRemote){const r=()=>this.requests,s=new AbortController,o=l=>{l.id===i.id&&s.abort()};this.uppy.on("file-removed",o);const a=this.uppy.getRequestClientForFile(i).uploadRemoteFile(i,V(this,it,su).call(this,i),{signal:s.signal,getQueue:r});return this.requests.wrapSyncFunction(()=>{this.uppy.off("file-removed",o)},{priority:-1})(),a}return V(this,it,iu).call(this,i)}))},Jn=new WeakMap,j(Hc,"VERSION",J0.version);const ib=Object.freeze(Object.defineProperty({__proto__:null,default:Hc},Symbol.toStringTag,{value:"Module"}));T.AmountInput=bh,T.CaptchaInput=Oh,T.CheckboxButtonInput=Mh,T.CheckboxInput=jh,T.CheckboxToggle=zh,T.DropzoneInput=zg,T.EditorInput=Zh,T.EmailInput=pp,T.FileInput=dp,T.FormContainer=Ep,T.FormLabel=Ip,T.GroupControl=ua,T.LocationInput=Fp,T.MobileInput=Mp,T.MultiQuantityInput=Kp,T.PasswordInput=Lp,T.PersianDatePickerInput=Yh,T.QuantityInput=da,T.RangeSliderInput=H1,T.SecondarySubmitButton=Xp,T.Select2Input=Ag,T.SimpleUploader=i1,T.StarRatingInput=Ng,T.SubmitButton=$g,T.TelInput=jg,T.TextAreaInput=xg,T.TextInput=Ln,T.UppyInput=Z0,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
19
+ Uppy plugins must have unique \`id\` options.`;throw new Error(o)}return e.VERSION&&this.log(`Using ${r} v${e.VERSION}`),i.type in E(this,ze)?E(this,ze)[i.type].push(i):E(this,ze)[i.type]=[i],i.install(),this.emit("plugin-added",i),this}getPlugin(e){for(const n of Object.values(E(this,ze))){const i=n.find(r=>r.id===e);if(i!=null)return i}}[Symbol.for("uppy test: getPlugins")](e){return E(this,ze)[e]}iteratePlugins(e){Object.values(E(this,ze)).flat(1).forEach(e)}removePlugin(e){this.log(`Removing plugin ${e.id}`),this.emit("plugin-remove",e),e.uninstall&&e.uninstall();const n=E(this,ze)[e.type],i=n.findIndex(o=>o.id===e.id);i!==-1&&n.splice(i,1);const s={plugins:{...this.getState().plugins,[e.id]:void 0}};this.setState(s)}destroy(){this.log(`Closing Uppy instance ${this.opts.id}: removing all files and uninstalling plugins`),this.cancelAll(),E(this,Qn).call(this),this.iteratePlugins(e=>{this.removePlugin(e)}),typeof window<"u"&&window.removeEventListener&&(window.removeEventListener("online",E(this,kt)),window.removeEventListener("offline",E(this,kt)))}hideInfo(){const{info:e}=this.getState();this.setState({info:e.slice(1)}),this.emit("info-hidden")}info(e,n="info",i=3e3){const r=typeof e=="object";this.setState({info:[...this.getState().info,{type:n,message:r?e.message:e,details:r?e.details:null}]}),setTimeout(()=>this.hideInfo(),i),this.emit("info-visible")}log(e,n){const{logger:i}=this.opts;switch(n){case"error":i.error(e);break;case"warning":i.warn(e);break;default:i.debug(e);break}}registerRequestClient(e,n){E(this,Zn).set(e,n)}getRequestClientForFile(e){if(!("remote"in e&&e.remote))throw new Error(`Tried to get RequestClient for a non-remote file ${e.id}`);const n=E(this,Zn).get(e.remote.requestClientId);if(n==null)throw new Error(`requestClientId "${e.remote.requestClientId}" not registered for file "${e.id}"`);return n}async restore(e){this.log(`Core: Running restored upload "${e}"`);const n=await V(this,L,di).call(this,e);return this.emit("complete",n),n}[Symbol.for("uppy test: createUpload")](...e){return V(this,L,ui).call(this,...e)}addResultData(e,n){if(!V(this,L,nu).call(this,e)){this.log(`Not setting result for an upload that has been removed: ${e}`);return}const{currentUploads:i}=this.getState(),r={...i[e],result:{...i[e].result,...n}};this.setState({currentUploads:{...i,[e]:r}})}async upload(){var r;(r=E(this,ze).uploader)!=null&&r.length||this.log("No uploader type plugins are used","warning");let{files:e}=this.getState();if(V(this,L,Ps).call(this).length>0){const s=await V(this,L,Ms).call(this);if(!(this.getFiles().filter(a=>a.progress.uploadStarted==null).length>0))return this.emit("complete",s),s;({files:e}=this.getState())}const i=this.opts.onBeforeUpload(e);if(i===!1)throw new Error("Not starting the upload because onBeforeUpload returned false");i&&typeof i=="object"&&(e=i,this.setState({files:e}));try{if(E(this,qe).validateMinNumberOfFiles(e),!V(this,L,Qc).call(this,e))throw new xe(this.i18n("missingRequiredMetaField"));const{currentUploads:s}=this.getState(),o=Object.values(s).flatMap(d=>d.fileIDs),a=Object.keys(e).filter(d=>{const f=this.getFile(d);return f&&!f.progress.uploadStarted&&!o.includes(d)}),l=V(this,L,ui).call(this,a),c=await V(this,L,di).call(this,l);return this.emit("complete",c),c}catch(s){throw V(this,L,Zt).call(this,[s]),s}}};ze=new WeakMap,qe=new WeakMap,Qn=new WeakMap,Wt=new WeakMap,Tn=new WeakMap,Fn=new WeakMap,Gt=new WeakMap,L=new WeakSet,Zt=function(e){for(const o of e)o.isRestriction?this.emit("restriction-failed",o.file,o):this.emit("error",o,o.file),this.log(o,"warning");const n=e.filter(o=>o.isUserFacing),i=4,r=n.slice(0,i),s=n.slice(i);r.forEach(({message:o,details:a=""})=>{this.info({message:o,details:a},"error",this.opts.infoTimeout)}),s.length>0&&this.info({message:this.i18n("additionalRestrictionsFailed",{count:s.length})})},Ts=function(e){const{missingFields:n,error:i}=E(this,qe).getMissingRequiredMetaFields(e);return n.length>0?(this.setFileState(e.id,{missingRequiredMetaFields:n,error:i.message}),this.log(i.message),this.emit("restriction-failed",e,i),!1):(n.length===0&&e.missingRequiredMetaFields&&this.setFileState(e.id,{missingRequiredMetaFields:[]}),!0)},Qc=function(e){let n=!0;for(const i of Object.values(e))V(this,L,Ts).call(this,i)||(n=!1);return n},Zc=function(e){const{allowNewUpload:n}=this.getState();if(n===!1){const i=new xe(this.i18n("noMoreFilesAllowed"),{file:e});throw V(this,L,Zt).call(this,[i]),i}},Jc=function(e){const n=e instanceof File?{name:e.name,type:e.type,size:e.size,data:e,meta:{},isRemote:!1,source:void 0,preview:void 0}:e,i=Sc(n),r=Y0(i,n),s=wc(r).extension,o=v_(n,this.getID()),a={...n.meta,name:r,type:i},l=Number.isFinite(n.data.size)?n.data.size:null;return{source:n.source||"",id:o,name:r,extension:s||"",meta:{...this.getState().meta,...a},type:i,progress:{percentage:0,bytesUploaded:!1,bytesTotal:l,uploadComplete:!1,uploadStarted:null},size:l,isGhost:!1,...n.isRemote?{isRemote:!0,remote:n.remote,data:n.data}:{isRemote:!1,data:n.data},preview:n.preview}},Fs=function(){this.opts.autoProceed&&!this.scheduledAutoProceed&&(this.scheduledAutoProceed=setTimeout(()=>{this.scheduledAutoProceed=null,this.upload().catch(e=>{e.isRestriction||this.log(e.stack||e.message||e)})},4))},Ns=function(e){let{files:n}=this.getState(),i={...n};const r=[],s=[];for(const o of e)try{let a=V(this,L,Jc).call(this,o);V(this,L,Zc).call(this,a);const l=n[a.id],c=l==null?void 0:l.isGhost;if(c&&!a.isRemote){if(a.data==null)throw new Error("File data is missing");a={...l,isGhost:!1,data:a.data},this.log(`Replaced the blob in the restored ghost file: ${a.name}, ${a.id}`)}const d=this.opts.onBeforeFileAdded(a,i);if(n=this.getState().files,i={...n,...i},!d&&this.checkIfFileAlreadyExists(a.id))throw new xe(this.i18n("noDuplicates",{fileName:a.name??this.i18n("unnamed")}),{file:a});if(d===!1&&!c)throw new xe("Cannot add the file because onBeforeFileAdded returned false.",{isUserFacing:!1,file:a});typeof d=="object"&&d!==null&&(a=d),E(this,qe).validateSingleFile(a),i[a.id]=a,r.push(a)}catch(a){s.push(a)}try{E(this,qe).validateAggregateRestrictions(Object.values(n),r)}catch(o){return s.push(o),{nextFilesState:n,validFilesToAdd:[],errors:s}}return{nextFilesState:i,validFilesToAdd:r,errors:s}},Ps=function(){const{files:e}=this.getState();return Object.keys(e).filter(n=>{const i=e[n];return i.error&&(!i.missingRequiredMetaFields||i.missingRequiredMetaFields.length===0)})},Ms=async function(){const e=V(this,L,Ps).call(this),n={...this.getState().files};if(e.forEach(r=>{n[r]={...n[r],isPaused:!1,error:null}}),this.setState({files:n,error:null}),this.emit("retry-all",this.getFilesByIds(e)),e.length===0)return{successful:[],failed:[]};const i=V(this,L,ui).call(this,e,{forceAllowNewUpload:!0});return V(this,L,di).call(this,i)},Zi=new WeakMap,Ds=function(){const e=V(this,L,eu).call(this);let n=null;e!=null&&(n=Math.round(e*100),n>100?n=100:n<0&&(n=0)),this.emit("progress",n??0),this.setState({totalProgress:n??0})},Yt=new WeakMap,eu=function(){const n=this.getFiles().filter(l=>l.progress.uploadStarted||l.progress.preprocess||l.progress.postprocess);if(n.length===0)return 0;if(n.every(l=>l.progress.uploadComplete))return 1;const i=l=>l.progress.bytesTotal!=null&&l.progress.bytesTotal!==0,r=n.filter(i),s=n.filter(l=>!i(l));if(r.every(l=>l.progress.uploadComplete)&&s.length>0&&!s.every(l=>l.progress.uploadComplete))return null;const o=r.reduce((l,c)=>l+(c.progress.bytesTotal??0),0),a=r.reduce((l,c)=>l+(c.progress.bytesUploaded||0),0);return o===0?0:a/o},tu=function(){const e=(r,s,o)=>{let a=r.message||"Unknown error";r.details&&(a+=` ${r.details}`),this.setState({error:a}),s!=null&&s.id in this.getState().files&&this.setFileState(s.id,{error:a,response:o})};this.on("error",e),this.on("upload-error",(r,s,o)=>{if(e(s,r,o),typeof s=="object"&&s.message){this.log(s.message,"error");const a=new Error(this.i18n("failedToUpload",{file:(r==null?void 0:r.name)??""}));a.isUserFacing=!0,a.details=s.message,s.details&&(a.details+=` ${s.details}`),V(this,L,Zt).call(this,[a])}else V(this,L,Zt).call(this,[s])});let n=null;this.on("upload-stalled",(r,s)=>{const{message:o}=r,a=s.map(l=>l.meta.name).join(", ");n||(this.info({message:o,details:a},"warning",this.opts.infoTimeout),n=setTimeout(()=>{n=null},this.opts.infoTimeout)),this.log(`${o} ${a}`.trim(),"warning")}),this.on("upload",()=>{this.setState({error:null})});const i=r=>{const s=r.filter(a=>{const l=a!=null&&this.getFile(a.id);return l||this.log(`Not setting progress for a file that has been removed: ${a==null?void 0:a.id}`),l}),o=Object.fromEntries(s.map(a=>[a.id,{progress:{uploadStarted:Date.now(),uploadComplete:!1,bytesUploaded:0,bytesTotal:a.size}}]));this.patchFilesState(o)};this.on("upload-start",i),this.on("upload-progress",E(this,Zi)),this.on("upload-success",(r,s)=>{if(r==null||!this.getFile(r.id)){this.log(`Not setting progress for a file that has been removed: ${r==null?void 0:r.id}`);return}const o=this.getFile(r.id).progress,a=E(this,Gt).size>0;this.setFileState(r.id,{progress:{...o,postprocess:a?{mode:"indeterminate"}:void 0,uploadComplete:!0,...!a&&{complete:!0},percentage:100,bytesUploaded:o.bytesTotal},response:s,uploadURL:s.uploadURL,isPaused:!1}),r.size==null&&this.setFileState(r.id,{size:s.bytesUploaded||o.bytesTotal}),E(this,Yt).call(this)}),this.on("preprocess-progress",(r,s)=>{if(r==null||!this.getFile(r.id)){this.log(`Not setting progress for a file that has been removed: ${r==null?void 0:r.id}`);return}this.setFileState(r.id,{progress:{...this.getFile(r.id).progress,preprocess:s}})}),this.on("preprocess-complete",r=>{if(r==null||!this.getFile(r.id)){this.log(`Not setting progress for a file that has been removed: ${r==null?void 0:r.id}`);return}const s={...this.getState().files};s[r.id]={...s[r.id],progress:{...s[r.id].progress}},delete s[r.id].progress.preprocess,this.setState({files:s})}),this.on("postprocess-progress",(r,s)=>{if(r==null||!this.getFile(r.id)){this.log(`Not setting progress for a file that has been removed: ${r==null?void 0:r.id}`);return}this.setFileState(r.id,{progress:{...this.getState().files[r.id].progress,postprocess:s}})}),this.on("postprocess-complete",r=>{const s=r&&this.getFile(r.id);if(s==null){this.log(`Not setting progress for a file that has been removed: ${r==null?void 0:r.id}`);return}const{postprocess:o,...a}=s.progress;this.patchFilesState({[s.id]:{progress:{...a,complete:!0}}})}),this.on("restored",()=>{E(this,Yt).call(this)}),this.on("dashboard:file-edit-complete",r=>{r&&V(this,L,Ts).call(this,r)}),typeof window<"u"&&window.addEventListener&&(window.addEventListener("online",E(this,kt)),window.addEventListener("offline",E(this,kt)),setTimeout(E(this,kt),3e3))},kt=new WeakMap,Zn=new WeakMap,ui=function(e,n={}){const{forceAllowNewUpload:i=!1}=n,{allowNewUpload:r,currentUploads:s}=this.getState();if(!r&&!i)throw new Error("Cannot create a new upload: already uploading.");const o=W0();return this.emit("upload",o,this.getFilesByIds(e)),this.setState({allowNewUpload:this.opts.allowMultipleUploadBatches!==!1&&this.opts.allowMultipleUploads!==!1,currentUploads:{...s,[o]:{fileIDs:e,step:0,result:{}}}}),o},nu=function(e){const{currentUploads:n}=this.getState();return n[e]},$s=function(e){const{[e]:n,...i}=this.getState().currentUploads;this.setState({currentUploads:i})},di=async function(e){const n=()=>{const{currentUploads:o}=this.getState();return o[e]};let i=n();if(!i)throw new Error("Nonexistent upload");const r=[...E(this,Tn),...E(this,Fn),...E(this,Gt)];try{for(let o=i.step||0;o<r.length;o++){const a=r[o];this.setState({currentUploads:{...this.getState().currentUploads,[e]:{...i,step:o}}});const{fileIDs:l}=i;if(await a(l,e),i=n(),!i)break}}catch(o){throw V(this,L,$s).call(this,e),o}if(i){i.fileIDs.forEach(c=>{const d=this.getFile(c);d!=null&&d.progress.postprocess&&this.emit("postprocess-complete",d)});const o=i.fileIDs.map(c=>this.getFile(c)),a=o.filter(c=>!c.error),l=o.filter(c=>c.error);this.addResultData(e,{successful:a,failed:l,uploadID:e}),i=n()}let s;return i&&(s=i.result,V(this,L,$s).call(this,e)),s==null&&(this.log(`Not setting result for an upload that has been removed: ${e}`),s={successful:[],failed:[],uploadID:e}),s},j(Ji,"VERSION",G0.version);let Ss=Ji;const Z0={__name:"UppyInput",props:{name:{type:String,required:!0},multiple:{type:Boolean,default:!1},useXHR:{type:Boolean,default:!0},XHRConfig:{type:Object,default:{}},url:{type:String,default:"/upload"},config:{type:Object,default:()=>({})},errorHandler:{type:Function,default:null}},emits:["update:modelValue","file-added","file-removed","beforeUpload","progress","upload","upload-progress","upload-error","upload-success","upload-pause","complete","error","upload-retry","upload-stalled","retry-all","cancel-all","restriction-failed"],setup(t,{emit:e}){var f;const n=t,i=e,r=u.ref(null),s=u.shallowRef(null),o=u.inject("form",{value:{},errors:{},getID:h=>h}),a=u.inject("group",null),l=u.computed({get(){var h;return(h=a==null?void 0:a.value)!=null&&h.name?a.value.getData(n.name):o.value[n.name]},set(h){var g;(g=a==null?void 0:a.value)!=null&&g.name?a.value.setData(n.name,h):o.value[n.name]=h,i("update:modelValue",h)}});s.value=new Ss({id:n.name,autoProceed:!0,...n.config,restrictions:{maxNumberOfFiles:n.multiple?10:1,...((f=n.config)==null?void 0:f.restrictions)||{}}}),s.value.on("before-upload",h=>{i("beforeUpload",h)}),s.value.on("upload-success",(h,g)=>{const m=g.body??g;if(n.multiple){const p=Array.isArray(l.value)?l.value:[];l.value=[...p,m]}else l.value=m;i("upload-success",h,g)}),s.value.on("file-added",h=>i("file-added",h)),s.value.on("file-removed",h=>{var m;const g=((m=h.response)==null?void 0:m.body)??h.response;n.multiple&&Array.isArray(l.value)?l.value=l.value.filter(p=>JSON.stringify(p)!==JSON.stringify(g)):l.value=null,g&&fetch(n.url,{method:"DELETE",headers:{"X-Requested-With":"XMLHttpRequest","Content-Type":"application/json"},body:JSON.stringify(g)}),i("file-removed",h)}),s.value.on("progress",h=>i("progress",h)),s.value.on("upload-progress",(h,g)=>i("upload-progress",h,g)),s.value.on("upload-pause",(h,g)=>i("upload-pause",h,g)),s.value.on("cancel-all",()=>i("cancel-all")),s.value.on("retry-all",()=>i("retry-all")),s.value.on("upload-stalled",(h,g)=>i("upload-stalled",h,g)),s.value.on("upload-retry",h=>i("upload-retry",h)),s.value.on("complete",h=>i("complete",h)),s.value.on("error",h=>{i("error",h)}),s.value.on("upload-error",(h,g,m)=>{var y;const p=((y=JSON.parse(m.response))==null?void 0:y.message)??g;c(p),i("upload-error",h,g,m,p)}),s.value.on("restriction-failed",(h,g)=>{c(g.message),i("restriction-failed",h,g)}),u.onMounted(()=>{let h;n.useXHR&&Promise.resolve().then(()=>ib).then(g=>{h=g.default,s.value.use(h,{method:"POST",endpoint:n.url,headers:{accept:"application/json"},...n.XHRConfig})})}),u.onBeforeUnmount(()=>{s.value&&s.value.destroy()});function c(h){n.errorHandler?n.errorHandler(h):h&&d(h)}function d(h){const g=document.createElement("div");g.textContent=h,g.className="uppy-error",r.value&&(r.value.prepend(g),setTimeout(()=>g.remove(),3e3))}return(h,g)=>s.value?(u.openBlock(),u.createElementBlock("div",{key:0,class:"uppy-input-area",ref_key:"inputEl",ref:r},[u.createVNode(u.unref(l_),{name:"uu"+t.name,uppy:s.value},{default:u.withCtx(()=>[u.renderSlot(h.$slots,"default",{uppy:s.value},()=>[u.createVNode(u.unref(u_),{class:"uppy-file-lists"}),u.createVNode(u.unref(c_))])]),_:3},8,["name","uppy"])],512)):u.createCommentVNode("",!0)}},J0={version:"5.1.1"},eb={strings:{uploadStalled:"Upload has not made any progress for %{seconds} seconds. You may want to retry it."}};function tb(t,e){let n=e;return n||(n=new Error("Upload error")),typeof n=="string"&&(n=new Error(n)),n instanceof Error||(n=Object.assign(new Error("Upload error"),{data:n})),w_(t)?(n=new bs(n,t),n):(n.request=t,n)}function Rc(t){return t.data.slice(0,t.data.size,t.meta.type)}const nb={formData:!0,fieldName:"file",method:"post",allowedMetaFields:!0,bundle:!1,headers:{},timeout:30*1e3,limit:5,withCredentials:!1,responseType:""};class Hc extends A_{constructor(n,i){super(n,{...nb,fieldName:i.bundle?"files[]":"file",...i});K(this,it);K(this,Nn);j(this,"requests");j(this,"uploaderEvents");K(this,Jn,async n=>{if(n.length===0){this.uppy.log("[XHRUpload] No files to upload!");return}this.opts.limit===0&&!this.opts[vs]&&this.uppy.log("[XHRUpload] When uploading multiple files at once, consider setting the `limit` option (to `10` for example), to limit the number of concurrent uploads, which helps prevent memory and network issues: https://uppy.io/docs/xhr-upload/#limit-0","warning"),this.uppy.log("[XHRUpload] Uploading...");const i=this.uppy.getFilesByIds(n),r=m_(i),s=g_(r);if(this.uppy.emit("upload-start",s),this.opts.bundle){if(r.some(a=>a.isRemote))throw new Error("Can’t upload remote files when the `bundle: true` option is set");if(typeof this.opts.headers=="function")throw new TypeError("`headers` may not be a function when the `bundle: true` option is set");await V(this,it,ru).call(this,r)}else await V(this,it,ou).call(this,r)});if(this.type="uploader",this.id=this.opts.id||"XHRUpload",this.defaultLocale=eb,this.i18nInit(),vs in this.opts?this.requests=this.opts[vs]:this.requests=new S_(this.opts.limit),this.opts.bundle&&!this.opts.formData)throw new Error("`opts.formData` must be true when `opts.bundle` is enabled.");if(this.opts.bundle&&typeof this.opts.headers=="function")throw new Error("`opts.headers` can not be a function when the `bundle: true` option is set.");if((i==null?void 0:i.allowedMetaFields)===void 0&&"metaFields"in this.opts)throw new Error("The `metaFields` option has been renamed to `allowedMetaFields`.");this.uploaderEvents=Object.create(null),re(this,Nn,r=>async(s,o)=>{var a,l;try{const c=await f_(s,{...o,onBeforeRequest:(h,g)=>{var m,p;return(p=(m=this.opts).onBeforeRequest)==null?void 0:p.call(m,h,g,r)},shouldRetry:this.opts.shouldRetry,onAfterResponse:this.opts.onAfterResponse,onTimeout:h=>{const g=Math.ceil(h/1e3),m=new Error(this.i18n("uploadStalled",{seconds:g}));this.uppy.emit("upload-stalled",m,r)},onUploadProgress:h=>{if(h.lengthComputable)for(const{id:g}of r){const m=this.uppy.getFile(g);m!=null&&this.uppy.emit("upload-progress",m,{uploadStarted:m.progress.uploadStarted??0,bytesUploaded:h.loaded/h.total*m.size,bytesTotal:m.size})}}});let d=await((l=(a=this.opts).getResponseData)==null?void 0:l.call(a,c));if(c.responseType==="json")d??(d=c.response);else try{d??(d=JSON.parse(c.responseText))}catch(h){throw new Error("@uppy/xhr-upload expects a JSON response (with a `url` property). To parse non-JSON responses, use `getResponseData` to turn your response into JSON.",{cause:h})}const f=typeof(d==null?void 0:d.url)=="string"?d.url:void 0;for(const{id:h}of r)this.uppy.emit("upload-success",this.uppy.getFile(h),{status:c.status,body:d,uploadURL:f});return c}catch(c){if(c.name==="AbortError")return;const d=c.request;for(const f of r)this.uppy.emit("upload-error",this.uppy.getFile(f.id),tb(d,c),d);throw c}})}getOptions(n){const i=this.uppy.getState().xhrUpload,{headers:r}=this.opts,s={...this.opts,...i||{},...n.xhrUpload||{},headers:{}};return typeof r=="function"?s.headers=r(n):Object.assign(s.headers,this.opts.headers),i&&Object.assign(s.headers,i.headers),n.xhrUpload&&Object.assign(s.headers,n.xhrUpload.headers),s}addMetadata(n,i,r){kc(r.allowedMetaFields,i).forEach(o=>{const a=i[o];Array.isArray(a)?a.forEach(l=>n.append(o,l)):n.append(o,a)})}createFormDataUpload(n,i){const r=new FormData;this.addMetadata(r,n.meta,i);const s=Rc(n);return n.name?r.append(i.fieldName,s,n.meta.name):r.append(i.fieldName,s),r}createBundledUpload(n,i){const r=new FormData,{meta:s}=this.uppy.getState();return this.addMetadata(r,s,i),n.forEach(o=>{const a=this.getOptions(o),l=Rc(o);o.name?r.append(a.fieldName,l,o.name):r.append(a.fieldName,l)}),r}install(){if(this.opts.bundle){const{capabilities:n}=this.uppy.getState();this.uppy.setState({capabilities:{...n,individualCancellation:!1}})}this.uppy.addUploader(E(this,Jn))}uninstall(){if(this.opts.bundle){const{capabilities:n}=this.uppy.getState();this.uppy.setState({capabilities:{...n,individualCancellation:!0}})}this.uppy.removeUploader(E(this,Jn))}}Nn=new WeakMap,it=new WeakSet,iu=async function(n){const i=new I_(this.uppy),r=new AbortController,s=this.requests.wrapPromiseFunction(async()=>{const o=this.getOptions(n),a=E(this,Nn).call(this,[n]),l=o.formData?this.createFormDataUpload(n,o):n.data,c=typeof o.endpoint=="string"?o.endpoint:await o.endpoint(n);return a(c,{...o,body:l,signal:r.signal})});i.onFileRemove(n.id,()=>r.abort()),i.onCancelAll(n.id,()=>{r.abort()});try{await s()}catch(o){if(o.message!=="Cancelled")throw o}finally{i.remove()}},ru=async function(n){const i=new AbortController,r=this.requests.wrapPromiseFunction(async()=>{const o=this.uppy.getState().xhrUpload??{},a=E(this,Nn).call(this,n),l=this.createBundledUpload(n,{...this.opts,...o}),c=typeof this.opts.endpoint=="string"?this.opts.endpoint:await this.opts.endpoint(n);return a(c,{...this.opts,body:l,signal:i.signal})});function s(){i.abort()}this.uppy.once("cancel-all",s);try{await r()}catch(o){if(o.message!=="Cancelled")throw o}finally{this.uppy.off("cancel-all",s)}},su=function(n){var s;const i=this.getOptions(n),r=kc(i.allowedMetaFields,n.meta);return{...(s=n.remote)==null?void 0:s.body,protocol:"multipart",endpoint:i.endpoint,size:n.data.size,fieldname:i.fieldName,metadata:Object.fromEntries(r.map(o=>[o,n.meta[o]])),httpMethod:i.method,useFormData:i.formData,headers:i.headers}},ou=async function(n){await Promise.allSettled(n.map(i=>{if(i.isRemote){const r=()=>this.requests,s=new AbortController,o=l=>{l.id===i.id&&s.abort()};this.uppy.on("file-removed",o);const a=this.uppy.getRequestClientForFile(i).uploadRemoteFile(i,V(this,it,su).call(this,i),{signal:s.signal,getQueue:r});return this.requests.wrapSyncFunction(()=>{this.uppy.off("file-removed",o)},{priority:-1})(),a}return V(this,it,iu).call(this,i)}))},Jn=new WeakMap,j(Hc,"VERSION",J0.version);const ib=Object.freeze(Object.defineProperty({__proto__:null,default:Hc},Symbol.toStringTag,{value:"Module"}));T.AmountInput=bh,T.CaptchaInput=Oh,T.CheckboxButtonInput=Mh,T.CheckboxInput=jh,T.CheckboxToggle=zh,T.DropzoneInput=zg,T.EditorInput=Zh,T.EmailInput=pp,T.FileInput=dp,T.FormContainer=Ep,T.FormLabel=Ip,T.GroupControl=ua,T.LocationInput=Fp,T.MobileInput=Mp,T.MultiQuantityInput=Kp,T.PasswordInput=Lp,T.PersianDatePickerInput=Yh,T.QuantityInput=da,T.RangeSliderInput=H1,T.SecondarySubmitButton=Xp,T.Select2Input=Ag,T.SimpleUploader=i1,T.StarRatingInput=Ng,T.SubmitButton=$g,T.TelInput=jg,T.TextAreaInput=xg,T.TextInput=Ln,T.UppyInput=Z0,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inertia-bootstrap-forms",
3
- "version": "1.0.63",
3
+ "version": "1.0.65",
4
4
  "description": "Create bootstrap forms with inertia and twitter bootstrap",
5
5
  "main": "dist/inertia-bootstrap-forms.cjs.js",
6
6
  "module": "dist/inertia-bootstrap-forms.es.js",
package/src/UppyInput.vue CHANGED
@@ -89,8 +89,9 @@ uppy.value.on('upload-success', (file, response) => {
89
89
 
90
90
  uppy.value.on('file-added', (file) => emits('file-added', file));
91
91
  uppy.value.on('file-removed', (file) => {
92
+ const serverResponse = file.response?.body ?? file.response;
93
+
92
94
  if (props.multiple && Array.isArray(modelValue.value)) {
93
- const serverResponse = file.response?.body ?? file.response;
94
95
  modelValue.value = modelValue.value.filter(item => {
95
96
  // مقایسه بر اساس شناسه یا کل آبجکت (بسته به ساختار ارسالی سرور شما)
96
97
  // اگر سرور ID برمی‌گرداند: return item.id !== serverResponse.id;
@@ -101,30 +102,42 @@ uppy.value.on('file-removed', (file) => {
101
102
  modelValue.value = null;
102
103
  }
103
104
 
104
- // بخش حذف از سرور
105
- if (file.response) {
105
+ if (serverResponse) {
106
106
  fetch(props.url, {
107
107
  method: 'DELETE',
108
108
  headers: {
109
109
  'X-Requested-With': 'XMLHttpRequest',
110
110
  'Content-Type': 'application/json',
111
111
  },
112
- body: JSON.stringify(file.response.body ?? file.response),
112
+ body: JSON.stringify(serverResponse),
113
113
  });
114
114
  }
115
115
 
116
116
  emits('file-removed', file);
117
117
  });
118
118
 
119
+ uppy.value.on('progress', (progress) => emits('progress', progress));
120
+ uppy.value.on('upload-progress', (file, progress) => emits('upload-progress', file, progress));
121
+ uppy.value.on('upload-pause', (file, progress) => emits('upload-pause', file, progress));
122
+ uppy.value.on('cancel-all', () => emits('cancel-all'));
123
+ uppy.value.on('retry-all', () => emits('retry-all', ));
124
+ uppy.value.on('upload-stalled', (error, files) => emits('upload-stalled', error, files));
125
+ uppy.value.on('upload-retry', (file) => emits('upload-retry', file));
126
+
119
127
  uppy.value.on('complete', (result) => emits('complete', result));
120
- uppy.value.on('error', (error) => emits('error', error));
128
+
129
+ uppy.value.on('error', (error) => {
130
+ emits('error', error)
131
+ });
132
+
133
+ uppy.value.on('upload-error', (file, error, response) => {
134
+ const errorMessage = JSON.parse(response.response)?.message ?? error;
135
+ handleError(errorMessage);
136
+ emits('upload-error', file, error, response, errorMessage)
137
+ });
121
138
 
122
139
  uppy.value.on('restriction-failed', (file, error) => {
123
- if (props.errorHandler) {
124
- props.errorHandler(error);
125
- } else {
126
- showError(error.message);
127
- }
140
+ handleError(error.message);
128
141
  emits('restriction-failed', file, error);
129
142
  });
130
143
 
@@ -134,11 +147,10 @@ onMounted(() => {
134
147
  import('@uppy/xhr-upload').then(module => {
135
148
  XHR = module.default; // چون اکثر پکیج‌ها default export دارند
136
149
  uppy.value.use(XHR, {
150
+ method: 'POST',
137
151
  endpoint: props.url,
138
- formData: true,
139
152
  headers: {
140
- 'Accept': 'application/json',
141
- 'X-Requested-With': 'XMLHttpRequest' // این هدر به لاراول کمک میکند درخواست را AJAX تشخیص دهد
153
+ 'accept': 'application/json',
142
154
  },
143
155
  ...props.XHRConfig
144
156
  });
@@ -152,6 +164,14 @@ onBeforeUnmount(() => {
152
164
  }
153
165
  });
154
166
 
167
+ function handleError(error) {
168
+ if (props.errorHandler) {
169
+ props.errorHandler(error);
170
+ } else if (error) {
171
+ showError(error);
172
+ }
173
+ }
174
+
155
175
  function showError(message) {
156
176
  const errorEl = document.createElement('div');
157
177
  errorEl.textContent = message;