@wangeditor-next/core 1.8.4 → 1.9.0
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.
- package/dist/core/src/config/interface.d.ts +8 -2
- package/dist/core/src/editor/interface.d.ts +2 -0
- package/dist/core/src/editor/plugins/with-history.d.ts +7 -0
- package/dist/core/src/to-html/elem2html.d.ts +2 -1
- package/dist/core/src/to-html/node2html.d.ts +6 -2
- package/dist/core/src/to-html/text2html.d.ts +2 -1
- package/dist/core/src/upload/createUploader.d.ts +4 -2
- package/dist/index.js +1 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -12
- package/dist/index.mjs.map +1 -1
- package/dist/upload.js +1 -12
- package/dist/upload.js.map +1 -1
- package/dist/upload.mjs +1 -12
- package/dist/upload.mjs.map +1 -1
- package/package.json +4 -2
package/dist/upload.mjs
CHANGED
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
/**
|
|
3
|
-
* Takes a string with placeholder variables like `%{smart_count} file selected`
|
|
4
|
-
* and replaces it with values from options `{smart_count: 5}`
|
|
5
|
-
*
|
|
6
|
-
* @license https://github.com/airbnb/polyglot.js/blob/master/LICENSE
|
|
7
|
-
* taken from https://github.com/airbnb/polyglot.js/blob/master/lib/polyglot.js#L299
|
|
8
|
-
*
|
|
9
|
-
* @param {string} phrase that needs interpolation, with placeholders
|
|
10
|
-
* @param {object} options with values that will be used to replace placeholders
|
|
11
|
-
* @returns {any[]} interpolated
|
|
12
|
-
*/function o(e,t){const r=/\$/g;let i=[e];if(null==t)return i;for(const e of Object.keys(t))if("_"!==e){let o=t[e];"string"==typeof o&&(o=r[Symbol.replace](o,"$$$$")),i=s(i,new RegExp(`%\\{${e}\\}`,"g"),o)}return i}var n=r("apply");function l(e){if(null==e||!e.strings)return;const t=this.locale;this.locale={...t,strings:{...t.strings,...e.strings}},this.locale.pluralize=e.pluralize||t.pluralize}return w=class{constructor(t){Object.defineProperty(this,n,{value:l}),this.locale={strings:{},pluralize:e=>1===e?0:1},Array.isArray(t)?t.forEach(e(this,n)[n],this):e(this,n)[n](t)}translate(e,t){return this.translateArray(e,t).join("")}translateArray(e,t){if(!i(this.locale.strings,e))throw new Error(`missing string: ${e}`);const r=this.locale.strings[e];if("object"==typeof r){if(t&&void 0!==t.smart_count){return o(r[this.locale.pluralize(t.smart_count)],t)}throw new Error("Attempted to use a string with plural forms, but no value was given for %{smart_count}")}return o(r,t)}},w}function Y(){return O||(O=1,S=function(){var e={},t=e._fns={};return e.emit=function(e,r,i,s,o,n,l){var a=function(e){var r=t[e]?t[e]:[],i=e.indexOf(":"),s=-1===i?[e]:[e.substring(0,i),e.substring(i+1)],o=Object.keys(t),n=0,l=o.length;for(;n<l;n++){var a=o[n];if("*"===a&&(r=r.concat(t[a])),2===s.length&&s[0]===a){r=r.concat(t[a]);break}}return r}(e);a.length&&function(e,t,r){var i=0,s=t.length;for(;i<s&&t[i];i++)t[i].event=e,t[i].apply(t[i],r)}(e,a,[r,i,s,o,n,l])},e.on=function(e,r){t[e]||(t[e]=[]),t[e].push(r)},e.once=function(t,r){this.on(t,function i(){r.apply(this,arguments),e.off(t,i)})},e.off=function(e,t){var r=[];if(e&&t)for(var i=this._fns[e],s=0,o=i?i.length:0;s<o;s++)i[s]!==t&&r.push(i[s]);r.length?this._fns[e]=r:delete this._fns[e]},e}),S}function Q(){if(x)return E;x=1;var e=0;function t(t){return"__private_"+e+++"_"+t}var r=t("publish");class i{constructor(){Object.defineProperty(this,r,{value:s}),this.state={},this.callbacks=[]}getState(){return this.state}setState(e){const t={...this.state},i={...this.state,...e};this.state=i,function(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}(this,r)[r](t,i,e)}subscribe(e){return this.callbacks.push(e),()=>{this.callbacks.splice(this.callbacks.indexOf(e),1)}}}function s(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];this.callbacks.forEach(e=>{e(...t)})}return i.VERSION="2.1.1",E=function(){return new i}}function J(){if(F)return U;return F=1,U=function(e){const t=e.lastIndexOf(".");return-1===t||t===e.length-1?{name:e,extension:void 0}:{name:e.slice(0,t),extension:e.slice(t+1)}}}function Z(){return j?k:(j=1,k={md:"text/markdown",markdown:"text/markdown",mp4:"video/mp4",mp3:"audio/mp3",svg:"image/svg+xml",jpg:"image/jpeg",png:"image/png",gif:"image/gif",heic:"image/heic",heif:"image/heif",yaml:"text/yaml",yml:"text/yaml",csv:"text/csv",tsv:"text/tab-separated-values",tab:"text/tab-separated-values",avi:"video/x-msvideo",mks:"video/x-matroska",mkv:"video/x-matroska",mov:"video/quicktime",dicom:"application/dicom",doc:"application/msword",docm:"application/vnd.ms-word.document.macroenabled.12",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",dot:"application/msword",dotm:"application/vnd.ms-word.template.macroenabled.12",dotx:"application/vnd.openxmlformats-officedocument.wordprocessingml.template",xla:"application/vnd.ms-excel",xlam:"application/vnd.ms-excel.addin.macroenabled.12",xlc:"application/vnd.ms-excel",xlf:"application/x-xliff+xml",xlm:"application/vnd.ms-excel",xls:"application/vnd.ms-excel",xlsb:"application/vnd.ms-excel.sheet.binary.macroenabled.12",xlsm:"application/vnd.ms-excel.sheet.macroenabled.12",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",xlt:"application/vnd.ms-excel",xltm:"application/vnd.ms-excel.template.macroenabled.12",xltx:"application/vnd.openxmlformats-officedocument.spreadsheetml.template",xlw:"application/vnd.ms-excel",txt:"text/plain",text:"text/plain",conf:"text/plain",log:"text/plain",pdf:"application/pdf",zip:"application/zip","7z":"application/x-7z-compressed",rar:"application/x-rar-compressed",tar:"application/x-tar",gz:"application/gzip",dmg:"application/x-apple-diskimage"})}function ee(){if(q)return D;q=1;var e=H,r=d(),i=K();let s,o;function n(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}var l=0;function a(e){return"__private_"+l+++"_"+e}const u=V(),p=Y(),h=t,c=Q(),f=function(){if($)return T;$=1;const e=J(),t=Z();return T=function(r){var i;if(r.type)return r.type;const s=r.name?null==(i=e(r.name).extension)?void 0:i.toLowerCase():null;return s&&s in t?t[s]:"application/octet-stream"}}(),g=J(),m=function(){if(A)return R;function e(e){let t="";return e.replace(/[^A-Z0-9]/gi,e=>(t+=`-${function(e){return e.charCodeAt(0).toString(32)}(e)}`,"/"))+t}return A=1,R=function(t){let r="uppy";return"string"==typeof t.name&&(r+=`-${e(t.name.toLowerCase())}`),void 0!==t.type&&(r+=`-${t.type}`),t.meta&&"string"==typeof t.meta.relativePath&&(r+=`-${e(t.meta.relativePath.toLowerCase())}`),void 0!==t.data.size&&(r+=`-${t.data.size}`),void 0!==t.data.lastModified&&(r+=`-${t.data.lastModified}`),r}}(),y=(N||(N=1,C=function(e){if(null==e&&"undefined"!=typeof navigator&&(e=navigator.userAgent),!e)return!0;const t=/Edge\/(\d+\.\d+)/.exec(e);if(!t)return!0;const r=t[1];let[i,s]=r.split(".");return i=parseInt(i,10),s=parseInt(s,10),i<15||15===i&&s<15063||i>18||18===i&&s>=18218}),C),_=M?I:(M=1,I=function(e,t){return t.name?t.name:"image"===e.split("/")[0]?`${e.split("/")[0]}.${e.split("/")[1]}`:"noname"}),v=z?L:(z=1,L={strings:{addBulkFilesFailed:{0:"Failed to add %{smart_count} file due to an internal error",1:"Failed to add %{smart_count} files due to internal errors"},youCanOnlyUploadX:{0:"You can only upload %{smart_count} file",1:"You can only upload %{smart_count} files"},youHaveToAtLeastSelectX:{0:"You have to select at least %{smart_count} file",1:"You have to select at least %{smart_count} files"},exceedsSize:"%{file} exceeds maximum allowed size of %{size}",missingRequiredMetaField:"Missing required meta fields",missingRequiredMetaFieldOnFile:"Missing required meta fields in %{fileName}",inferiorSize:"This file is smaller than the allowed size of %{size}",youCanOnlyUploadFileTypes:"You can only upload: %{types}",noMoreFilesAllowed:"Cannot add more files",noDuplicates:"Cannot add the duplicate file '%{fileName}', it already exists",companionError:"Connection with Companion failed",authAborted:"Authentication aborted",companionUnauthorizeHint:"To unauthorize to your %{provider} account, please go to %{url}",failedToUpload:"Failed to upload %{file}",noInternetConnection:"No Internet connection",connectedToInternet:"Connected to the Internet",noFilesFound:"You have no files or folders here",selectX:{0:"Select %{smart_count}",1:"Select %{smart_count}"},allFilesFromFolderNamed:"All files from folder %{name}",openFolderNamed:"Open folder %{name}",cancel:"Cancel",logOut:"Log out",filter:"Filter",resetFilter:"Reset filter",loading:"Loading...",authenticateWithTitle:"Please authenticate with %{pluginName} to select files",authenticateWith:"Connect to %{pluginName}",signInWithGoogle:"Sign in with Google",searchImages:"Search for images",enterTextToSearch:"Enter text to search for images",search:"Search",emptyFolderAdded:"No files were added from empty folder",folderAlreadyAdded:'The folder "%{folder}" was already added',folderAdded:{0:"Added %{smart_count} file from %{folder}",1:"Added %{smart_count} files from %{folder}"}}});var b=a("plugins"),w=a("restricter"),P=a("storeUnsubscribe"),S=a("emitter"),O=a("preProcessors"),E=a("uploaders"),x=a("postProcessors"),U=a("informAndEmit"),F=a("checkRequiredMetaFieldsOnFile"),k=a("checkRequiredMetaFields"),j=a("assertNewUploadAllowed"),B=a("checkAndCreateFileStateObject"),W=a("startIfAutoProceed"),X=a("addListeners"),G=a("updateOnlineStatus"),ee=a("createUpload"),te=a("getUpload"),re=a("removeUpload"),ie=a("runUpload");s=Symbol.for("uppy test: getPlugins"),o=Symbol.for("uppy test: createUpload");class se{constructor(e){Object.defineProperty(this,ie,{value:ge}),Object.defineProperty(this,re,{value:fe}),Object.defineProperty(this,te,{value:ce}),Object.defineProperty(this,ee,{value:he}),Object.defineProperty(this,X,{value:de}),Object.defineProperty(this,W,{value:pe}),Object.defineProperty(this,B,{value:ue}),Object.defineProperty(this,j,{value:ae}),Object.defineProperty(this,k,{value:le}),Object.defineProperty(this,F,{value:ne}),Object.defineProperty(this,U,{value:oe}),Object.defineProperty(this,b,{writable:!0,value:Object.create(null)}),Object.defineProperty(this,w,{writable:!0,value:void 0}),Object.defineProperty(this,P,{writable:!0,value:void 0}),Object.defineProperty(this,S,{writable:!0,value:p()}),Object.defineProperty(this,O,{writable:!0,value:new Set}),Object.defineProperty(this,E,{writable:!0,value:new Set}),Object.defineProperty(this,x,{writable:!0,value:new Set}),Object.defineProperty(this,G,{writable:!0,value:this.updateOnlineStatus.bind(this)}),this.defaultLocale=v;const t={id:"uppy",autoProceed:!1,allowMultipleUploads:!0,allowMultipleUploadBatches:!0,debug:!1,restrictions:i.defaultOptions,meta:{},onBeforeFileAdded:e=>e,onBeforeUpload:e=>e,store:c(),logger:r.justErrorsLogger,infoTimeout:5e3};this.opts={...t,...e,restrictions:{...t.restrictions,...e&&e.restrictions}},e&&e.logger&&e.debug?this.log("You are using a custom `logger`, but also set `debug: true`, which uses built-in logger to output logs to console. Ignoring `debug: true` and using your custom `logger`.","warning"):e&&e.debug&&(this.opts.logger=r.debugLogger),this.log(`Using Core v${this.constructor.VERSION}`),this.i18nInit(),this.calculateProgress=h(this.calculateProgress.bind(this),500,{leading:!0,trailing:!0}),this.store=this.opts.store,this.setState({plugins:{},files:{},currentUploads:{},allowNewUpload:!0,capabilities:{uploadProgress:y(),individualCancellation:!0,resumableUploads:!1},totalProgress:0,meta:{...this.opts.meta},info:[],recoveredState:null}),n(this,w)[w]=new i.Restricter(()=>this.opts,this.i18n),n(this,P)[P]=this.store.subscribe((e,t,r)=>{this.emit("state-update",e,t,r),this.updateAll(t)}),this.opts.debug&&"undefined"!=typeof window&&(window[this.opts.id]=this),n(this,X)[X]()}emit(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),i=1;i<t;i++)r[i-1]=arguments[i];n(this,S)[S].emit(e,...r)}on(e,t){return n(this,S)[S].on(e,t),this}once(e,t){return n(this,S)[S].once(e,t),this}off(e,t){return n(this,S)[S].off(e,t),this}updateAll(e){this.iteratePlugins(t=>{t.update(e)})}setState(e){this.store.setState(e)}getState(){return this.store.getState()}get state(){return this.getState()}setFileState(e,t){if(!this.getState().files[e])throw new Error(`Can’t set state for ${e} (the file could have been removed)`);this.setState({files:{...this.getState().files,[e]:{...this.getState().files[e],...t}}})}i18nInit(){const e=new u([this.defaultLocale,this.opts.locale]);this.i18n=e.translate.bind(e),this.i18nArray=e.translateArray.bind(e),this.locale=e.locale}setOptions(e){this.opts={...this.opts,...e,restrictions:{...this.opts.restrictions,...e&&e.restrictions}},e.meta&&this.setMeta(e.meta),this.i18nInit(),e.locale&&this.iteratePlugins(e=>{e.setOptions()}),this.setState()}resetProgress(){const e={percentage:0,bytesUploaded:0,uploadComplete:!1,uploadStarted:null},t={...this.getState().files},r={};Object.keys(t).forEach(i=>{const s={...t[i]};s.progress={...s.progress,...e},r[i]=s}),this.setState({files:r,totalProgress:0}),this.emit("reset-progress")}addPreProcessor(e){n(this,O)[O].add(e)}removePreProcessor(e){return n(this,O)[O].delete(e)}addPostProcessor(e){n(this,x)[x].add(e)}removePostProcessor(e){return n(this,x)[x].delete(e)}addUploader(e){n(this,E)[E].add(e)}removeUploader(e){return n(this,E)[E].delete(e)}setMeta(e){const t={...this.getState().meta,...e},r={...this.getState().files};Object.keys(r).forEach(t=>{r[t]={...r[t],meta:{...r[t].meta,...e}}}),this.log("Adding metadata:"),this.log(e),this.setState({meta:t,files:r})}setFileMeta(e,t){const r={...this.getState().files};if(!r[e])return void this.log("Was trying to set metadata for a file that has been removed: ",e);const i={...r[e].meta,...t};r[e]={...r[e],meta:i},this.setState({files:r})}getFile(e){return this.getState().files[e]}getFiles(){const{files:e}=this.getState();return Object.values(e)}getObjectOfFilesPerState(){const{files:e,totalProgress:t,error:r}=this.getState(),i=Object.values(e),s=i.filter(e=>{let{progress:t}=e;return!t.uploadComplete&&t.uploadStarted}),o=i.filter(e=>!e.progress.uploadStarted),n=i.filter(e=>e.progress.uploadStarted||e.progress.preprocess||e.progress.postprocess),l=i.filter(e=>e.progress.uploadStarted),a=i.filter(e=>e.isPaused),u=i.filter(e=>e.progress.uploadComplete),p=i.filter(e=>e.error),d=s.filter(e=>!e.isPaused),h=i.filter(e=>e.progress.preprocess||e.progress.postprocess);return{newFiles:o,startedFiles:n,uploadStartedFiles:l,pausedFiles:a,completeFiles:u,erroredFiles:p,inProgressFiles:s,inProgressNotPausedFiles:d,processingFiles:h,isUploadStarted:l.length>0,isAllComplete:100===t&&u.length===i.length&&0===h.length,isAllErrored:!!r&&p.length===i.length,isAllPaused:0!==s.length&&a.length===s.length,isUploadInProgress:s.length>0,isSomeGhost:i.some(e=>e.isGhost)}}validateRestrictions(e,t){void 0===t&&(t=this.getFiles());try{return n(this,w)[w].validate(e,t),{result:!0}}catch(e){return{result:!1,reason:e.message}}}checkIfFileAlreadyExists(e){const{files:t}=this.getState();return!(!t[e]||t[e].isGhost)}addFile(e){n(this,j)[j](e);const{files:t}=this.getState();let r=n(this,B)[B](t,e);return t[r.id]&&t[r.id].isGhost&&(r={...t[r.id],data:e.data,isGhost:!1},this.log(`Replaced the blob in the restored ghost file: ${r.name}, ${r.id}`)),this.setState({files:{...t,[r.id]:r}}),this.emit("file-added",r),this.emit("files-added",[r]),this.log(`Added file: ${r.name}, ${r.id}, mime type: ${r.type}`),n(this,W)[W](),r.id}addFiles(e){n(this,j)[j]();const t={...this.getState().files},r=[],i=[];for(let s=0;s<e.length;s++)try{let i=n(this,B)[B](t,e[s]);t[i.id]&&t[i.id].isGhost&&(i={...t[i.id],data:e[s].data,isGhost:!1},this.log(`Replaced blob in a ghost file: ${i.name}, ${i.id}`)),t[i.id]=i,r.push(i)}catch(e){e.isRestriction||i.push(e)}if(this.setState({files:t}),r.forEach(e=>{this.emit("file-added",e)}),this.emit("files-added",r),r.length>5?this.log(`Added batch of ${r.length} files`):Object.keys(r).forEach(e=>{this.log(`Added file: ${r[e].name}\n id: ${r[e].id}\n type: ${r[e].type}`)}),r.length>0&&n(this,W)[W](),i.length>0){let e="Multiple errors occurred while adding files:\n";if(i.forEach(t=>{e+=`\n * ${t.message}`}),this.info({message:this.i18n("addBulkFilesFailed",{smart_count:i.length}),details:e},"error",this.opts.infoTimeout),"function"==typeof AggregateError)throw new AggregateError(i,e);{const t=new Error(e);throw t.errors=i,t}}}removeFiles(e,t){const{files:r,currentUploads:i}=this.getState(),s={...r},o={...i},n=Object.create(null);function l(e){return void 0===n[e]}e.forEach(e=>{r[e]&&(n[e]=r[e],delete s[e])}),Object.keys(o).forEach(e=>{const t=i[e].fileIDs.filter(l);if(0===t.length)return void delete o[e];const{capabilities:r}=this.getState();if(t.length!==i[e].fileIDs.length&&!r.individualCancellation)throw new Error("individualCancellation is disabled");o[e]={...i[e],fileIDs:t}});const a={currentUploads:o,files:s};0===Object.keys(s).length&&(a.allowNewUpload=!0,a.error=null,a.recoveredState=null),this.setState(a),this.calculateTotalProgress();const u=Object.keys(n);u.forEach(e=>{this.emit("file-removed",n[e],t)}),u.length>5?this.log(`Removed ${u.length} files`):this.log(`Removed files: ${u.join(", ")}`)}removeFile(e,t){void 0===t&&(t=null),this.removeFiles([e],t)}pauseResume(e){if(!this.getState().capabilities.resumableUploads||this.getFile(e).uploadComplete)return;const t=!(this.getFile(e).isPaused||!1);return this.setFileState(e,{isPaused:t}),this.emit("upload-pause",e,t),t}pauseAll(){const e={...this.getState().files};Object.keys(e).filter(t=>!e[t].progress.uploadComplete&&e[t].progress.uploadStarted).forEach(t=>{const r={...e[t],isPaused:!0};e[t]=r}),this.setState({files:e}),this.emit("pause-all")}resumeAll(){const e={...this.getState().files};Object.keys(e).filter(t=>!e[t].progress.uploadComplete&&e[t].progress.uploadStarted).forEach(t=>{const r={...e[t],isPaused:!1,error:null};e[t]=r}),this.setState({files:e}),this.emit("resume-all")}retryAll(){const e={...this.getState().files},t=Object.keys(e).filter(t=>e[t].error);if(t.forEach(t=>{const r={...e[t],isPaused:!1,error:null};e[t]=r}),this.setState({files:e,error:null}),this.emit("retry-all",t),0===t.length)return Promise.resolve({successful:[],failed:[]});const r=n(this,ee)[ee](t,{forceAllowNewUpload:!0});return n(this,ie)[ie](r)}cancelAll(e){let{reason:t="user"}=void 0===e?{}:e;if(this.emit("cancel-all",{reason:t}),"user"===t){const{files:e}=this.getState(),t=Object.keys(e);t.length&&this.removeFiles(t,"cancel-all"),this.setState({totalProgress:0,error:null,recoveredState:null})}}retryUpload(e){this.setFileState(e,{error:null,isPaused:!1}),this.emit("upload-retry",e);const t=n(this,ee)[ee]([e],{forceAllowNewUpload:!0});return n(this,ie)[ie](t)}reset(){this.cancelAll(...arguments)}logout(){this.iteratePlugins(e=>{e.provider&&e.provider.logout&&e.provider.logout()})}calculateProgress(e,t){if(null==e||!this.getFile(e.id))return void this.log(`Not setting progress for a file that has been removed: ${null==e?void 0:e.id}`);const r=Number.isFinite(t.bytesTotal)&&t.bytesTotal>0;this.setFileState(e.id,{progress:{...this.getFile(e.id).progress,bytesUploaded:t.bytesUploaded,bytesTotal:t.bytesTotal,percentage:r?Math.round(t.bytesUploaded/t.bytesTotal*100):0}}),this.calculateTotalProgress()}calculateTotalProgress(){const e=this.getFiles().filter(e=>e.progress.uploadStarted||e.progress.preprocess||e.progress.postprocess);if(0===e.length)return this.emit("progress",0),void this.setState({totalProgress:0});const t=e.filter(e=>null!=e.progress.bytesTotal),r=e.filter(e=>null==e.progress.bytesTotal);if(0===t.length){const t=100*e.length,i=r.reduce((e,t)=>e+t.progress.percentage,0),s=Math.round(i/t*100);return void this.setState({totalProgress:s})}let i=t.reduce((e,t)=>e+t.progress.bytesTotal,0);const s=i/t.length;i+=s*r.length;let o=0;t.forEach(e=>{o+=e.progress.bytesUploaded}),r.forEach(e=>{o+=s*(e.progress.percentage||0)/100});let n=0===i?0:Math.round(o/i*100);n>100&&(n=100),this.setState({totalProgress:n}),this.emit("progress",n)}updateOnlineStatus(){void 0===window.navigator.onLine||window.navigator.onLine?(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,t){if("function"!=typeof e){throw new TypeError(`Expected a plugin class, but got ${null===e?"null":typeof e}. Please verify that the plugin was imported and spelled correctly.`)}const r=new e(this,t),i=r.id;if(!i)throw new Error("Your plugin must have an id");if(!r.type)throw new Error("Your plugin must have a type");const s=this.getPlugin(i);if(s){const e=`Already found a plugin named '${s.id}'. Tried to use: '${i}'.\nUppy plugins must have unique \`id\` options. See https://uppy.io/docs/plugins/#id.`;throw new Error(e)}return e.VERSION&&this.log(`Using ${i} v${e.VERSION}`),r.type in n(this,b)[b]?n(this,b)[b][r.type].push(r):n(this,b)[b][r.type]=[r],r.install(),this}getPlugin(e){for(const t of Object.values(n(this,b)[b])){const r=t.find(t=>t.id===e);if(null!=r)return r}}[s](e){return n(this,b)[b][e]}iteratePlugins(e){Object.values(n(this,b)[b]).flat(1).forEach(e)}removePlugin(e){this.log(`Removing plugin ${e.id}`),this.emit("plugin-remove",e),e.uninstall&&e.uninstall();const t=n(this,b)[b][e.type],r=t.findIndex(t=>t.id===e.id);-1!==r&&t.splice(r,1);const i={plugins:{...this.getState().plugins,[e.id]:void 0}};this.setState(i)}close(e){let{reason:t}=void 0===e?{}:e;this.log(`Closing Uppy instance ${this.opts.id}: removing all files and uninstalling plugins`),this.cancelAll({reason:t}),n(this,P)[P](),this.iteratePlugins(e=>{this.removePlugin(e)}),"undefined"!=typeof window&&window.removeEventListener&&(window.removeEventListener("online",n(this,G)[G]),window.removeEventListener("offline",n(this,G)[G]))}hideInfo(){const{info:e}=this.getState();this.setState({info:e.slice(1)}),this.emit("info-hidden")}info(e,t,r){void 0===t&&(t="info"),void 0===r&&(r=3e3);const i="object"==typeof e;this.setState({info:[...this.getState().info,{type:t,message:i?e.message:e,details:i?e.details:null}]}),setTimeout(()=>this.hideInfo(),r),this.emit("info-visible")}log(e,t){const{logger:r}=this.opts;switch(t){case"error":r.error(e);break;case"warning":r.warn(e);break;default:r.debug(e)}}restore(e){return this.log(`Core: attempting to restore upload "${e}"`),this.getState().currentUploads[e]?n(this,ie)[ie](e):(n(this,re)[re](e),Promise.reject(new Error("Nonexistent upload")))}[o](){return n(this,ee)[ee](...arguments)}addResultData(e,t){if(!n(this,te)[te](e))return void this.log(`Not setting result for an upload that has been removed: ${e}`);const{currentUploads:r}=this.getState(),i={...r[e],result:{...r[e].result,...t}};this.setState({currentUploads:{...r,[e]:i}})}upload(){var e;null!=(e=n(this,b)[b].uploader)&&e.length||this.log("No uploader type plugins are used","warning");let{files:t}=this.getState();const r=this.opts.onBeforeUpload(t);return!1===r?Promise.reject(new Error("Not starting the upload because onBeforeUpload returned false")):(r&&"object"==typeof r&&(t=r,this.setState({files:t})),Promise.resolve().then(()=>n(this,w)[w].validateMinNumberOfFiles(t)).catch(e=>{throw n(this,U)[U](e),e}).then(()=>{if(!n(this,k)[k](t))throw new i.RestrictionError(this.i18n("missingRequiredMetaField"))}).catch(e=>{throw e}).then(()=>{const{currentUploads:e}=this.getState(),r=Object.values(e).flatMap(e=>e.fileIDs),i=[];Object.keys(t).forEach(e=>{const t=this.getFile(e);t.progress.uploadStarted||-1!==r.indexOf(e)||i.push(t.id)});const s=n(this,ee)[ee](i);return n(this,ie)[ie](s)}).catch(e=>{throw this.emit("error",e),this.log(e,"error"),e}))}}function oe(e,t){const{message:r,details:i=""}=e;e.isRestriction?this.emit("restriction-failed",t,e):this.emit("error",e),this.info({message:r,details:i},"error",this.opts.infoTimeout),this.log(`${r} ${i}`.trim(),"error")}function ne(e){const{missingFields:t,error:r}=n(this,w)[w].getMissingRequiredMetaFields(e);return!(t.length>0)||(this.setFileState(e.id,{missingRequiredMetaFields:t}),this.log(r.message),this.emit("restriction-failed",e,r),!1)}function le(e){let t=!0;for(const r of Object.values(e))n(this,F)[F](r)||(t=!1);return t}function ae(e){const{allowNewUpload:t}=this.getState();if(!1===t){const t=new i.RestrictionError(this.i18n("noMoreFilesAllowed"));throw n(this,U)[U](t,e),t}}function ue(e,t){const r=f(t),s=_(r,t),o=g(s).extension,l=Boolean(t.isRemote),a=m({...t,type:r});if(this.checkIfFileAlreadyExists(a)){const e=new i.RestrictionError(this.i18n("noDuplicates",{fileName:s}));throw n(this,U)[U](e,t),e}const u=t.meta||{};u.name=s,u.type=r;const p=Number.isFinite(t.data.size)?t.data.size:null;let d={source:t.source||"",id:a,name:s,extension:o||"",meta:{...this.getState().meta,...u},type:r,data:t.data,progress:{percentage:0,bytesUploaded:0,bytesTotal:p,uploadComplete:!1,uploadStarted:null},size:p,isRemote:l,remote:t.remote||"",preview:t.preview};const h=this.opts.onBeforeFileAdded(d,e);if(!1===h){const e=new i.RestrictionError("Cannot add the file because onBeforeFileAdded returned false.");throw this.emit("restriction-failed",t,e),e}"object"==typeof h&&null!==h&&(d=h);try{const t=Object.keys(e).map(t=>e[t]);n(this,w)[w].validate(d,t)}catch(e){throw n(this,U)[U](e,d),e}return d}function pe(){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))}function de(){const e=(e,t,r)=>{let i=e.message||"Unknown error";e.details&&(i+=` ${e.details}`),this.setState({error:i}),null!=t&&t.id in this.getState().files&&this.setFileState(t.id,{error:i,response:r})};this.on("error",e),this.on("upload-error",(t,r,i)=>{if(e(r,t,i),"object"==typeof r&&r.message){const e=new Error(r.message);e.details=r.message,r.details&&(e.details+=` ${r.details}`),e.message=this.i18n("failedToUpload",{file:null==t?void 0:t.name}),n(this,U)[U](e)}else n(this,U)[U](r)}),this.on("upload",()=>{this.setState({error:null})}),this.on("upload-started",e=>{null!=e&&this.getFile(e.id)?this.setFileState(e.id,{progress:{uploadStarted:Date.now(),uploadComplete:!1,percentage:0,bytesUploaded:0,bytesTotal:e.size}}):this.log(`Not setting progress for a file that has been removed: ${null==e?void 0:e.id}`)}),this.on("upload-progress",this.calculateProgress),this.on("upload-success",(e,t)=>{if(null==e||!this.getFile(e.id))return void this.log(`Not setting progress for a file that has been removed: ${null==e?void 0:e.id}`);const r=this.getFile(e.id).progress;this.setFileState(e.id,{progress:{...r,postprocess:n(this,x)[x].size>0?{mode:"indeterminate"}:null,uploadComplete:!0,percentage:100,bytesUploaded:r.bytesTotal},response:t,uploadURL:t.uploadURL,isPaused:!1}),null==e.size&&this.setFileState(e.id,{size:t.bytesUploaded||r.bytesTotal}),this.calculateTotalProgress()}),this.on("preprocess-progress",(e,t)=>{null!=e&&this.getFile(e.id)?this.setFileState(e.id,{progress:{...this.getFile(e.id).progress,preprocess:t}}):this.log(`Not setting progress for a file that has been removed: ${null==e?void 0:e.id}`)}),this.on("preprocess-complete",e=>{if(null==e||!this.getFile(e.id))return void this.log(`Not setting progress for a file that has been removed: ${null==e?void 0:e.id}`);const t={...this.getState().files};t[e.id]={...t[e.id],progress:{...t[e.id].progress}},delete t[e.id].progress.preprocess,this.setState({files:t})}),this.on("postprocess-progress",(e,t)=>{null!=e&&this.getFile(e.id)?this.setFileState(e.id,{progress:{...this.getState().files[e.id].progress,postprocess:t}}):this.log(`Not setting progress for a file that has been removed: ${null==e?void 0:e.id}`)}),this.on("postprocess-complete",e=>{if(null==e||!this.getFile(e.id))return void this.log(`Not setting progress for a file that has been removed: ${null==e?void 0:e.id}`);const t={...this.getState().files};t[e.id]={...t[e.id],progress:{...t[e.id].progress}},delete t[e.id].progress.postprocess,this.setState({files:t})}),this.on("restored",()=>{this.calculateTotalProgress()}),this.on("dashboard:file-edit-complete",e=>{e&&n(this,F)[F](e)}),"undefined"!=typeof window&&window.addEventListener&&(window.addEventListener("online",n(this,G)[G]),window.addEventListener("offline",n(this,G)[G]),setTimeout(n(this,G)[G],3e3))}function he(t,r){void 0===r&&(r={});const{forceAllowNewUpload:i=!1}=r,{allowNewUpload:s,currentUploads:o}=this.getState();if(!s&&!i)throw new Error("Cannot create a new upload: already uploading.");const n=(0,e.nanoid)();return this.emit("upload",{id:n,fileIDs:t}),this.setState({allowNewUpload:!1!==this.opts.allowMultipleUploadBatches&&!1!==this.opts.allowMultipleUploads,currentUploads:{...o,[n]:{fileIDs:t,step:0,result:{}}}}),n}function ce(e){const{currentUploads:t}=this.getState();return t[e]}function fe(e){const t={...this.getState().currentUploads};delete t[e],this.setState({currentUploads:t})}async function ge(e){let{currentUploads:t}=this.getState(),r=t[e];const i=r.step||0,s=[...n(this,O)[O],...n(this,E)[E],...n(this,x)[x]];try{for(let o=i;o<s.length&&r;o++){const i=s[o],n={...r,step:o};this.setState({currentUploads:{...t,[e]:n}}),await i(n.fileIDs,e),t=this.getState().currentUploads,r=t[e]}}catch(t){throw n(this,re)[re](e),t}if(r){r.fileIDs.forEach(e=>{const t=this.getFile(e);t&&t.progress.postprocess&&this.emit("postprocess-complete",t)});const i=r.fileIDs.map(e=>this.getFile(e)),s=i.filter(e=>!e.error),o=i.filter(e=>e.error);await this.addResultData(e,{successful:s,failed:o,uploadID:e}),t=this.getState().currentUploads,r=t[e]}let o;return r&&(o=r.result,this.emit("complete",o),n(this,re)[re](e)),null==o&&this.log(`Not setting result for an upload that has been removed: ${e}`),o}return se.VERSION="2.3.4",D=se}var te,re,ie,se,oe,ne,le,ae,ue,pe,de,he,ce,fe={},ge=[],me=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,ye=Array.isArray;function _e(e,t){for(var r in t)e[r]=t[r];return e}function ve(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function be(e,t,r){var i,s,o,n={};for(o in t)"key"==o?i=t[o]:"ref"==o?s=t[o]:n[o]=t[o];if(arguments.length>2&&(n.children=arguments.length>3?te.call(arguments,2):r),"function"==typeof e&&null!=e.defaultProps)for(o in e.defaultProps)void 0===n[o]&&(n[o]=e.defaultProps[o]);return we(e,n,i,s,null)}function we(e,t,r,i,s){var o={type:e,props:t,key:r,ref:i,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:null==s?++ie:s,__i:-1,__u:0};return null==s&&null!=re.vnode&&re.vnode(o),o}function Pe(e){return e.children}function Se(e,t){this.props=e,this.context=t}function Oe(e,t){if(null==t)return e.__?Oe(e.__,e.__i+1):null;for(var r;t<e.__k.length;t++)if(null!=(r=e.__k[t])&&null!=r.__e)return r.__e;return"function"==typeof e.type?Oe(e):null}function Ee(e){var t,r;if(null!=(e=e.__)&&null!=e.__c){for(e.__e=e.__c.base=null,t=0;t<e.__k.length;t++)if(null!=(r=e.__k[t])&&null!=r.__e){e.__e=e.__c.base=r.__e;break}return Ee(e)}}function xe(e){(!e.__d&&(e.__d=!0)&&oe.push(e)&&!Ue.__r++||ne!=re.debounceRendering)&&((ne=re.debounceRendering)||le)(Ue)}function Ue(){for(var e,t,r,i,s,o,n,l=1;oe.length;)oe.length>l&&oe.sort(ae),e=oe.shift(),l=oe.length,e.__d&&(r=void 0,i=void 0,s=(i=(t=e).__v).__e,o=[],n=[],t.__P&&((r=_e({},i)).__v=i.__v+1,re.vnode&&re.vnode(r),Ce(t.__P,r,i,t.__n,t.__P.namespaceURI,32&i.__u?[s]:null,o,null==s?Oe(i):s,!!(32&i.__u),n),r.__v=i.__v,r.__.__k[r.__i]=r,Ie(o,r,n),i.__e=i.__=null,r.__e!=s&&Ee(r)));Ue.__r=0}function Fe(e,t,r,i,s,o,n,l,a,u,p){var d,h,c,f,g,m,y,_=i&&i.__k||ge,v=t.length;for(a=ke(r,t,_,a,v),d=0;d<v;d++)null!=(c=r.__k[d])&&(h=-1==c.__i?fe:_[c.__i]||fe,c.__i=d,m=Ce(e,c,h,s,o,n,l,a,u,p),f=c.__e,c.ref&&h.ref!=c.ref&&(h.ref&&ze(h.ref,null,c),p.push(c.ref,c.__c||f,c)),null==g&&null!=f&&(g=f),(y=!!(4&c.__u))||h.__k===c.__k?a=je(c,a,e,y):"function"==typeof c.type&&void 0!==m?a=m:f&&(a=f.nextSibling),c.__u&=-7);return r.__e=g,a}function ke(e,t,r,i,s){var o,n,l,a,u,p=r.length,d=p,h=0;for(e.__k=new Array(s),o=0;o<s;o++)null!=(n=t[o])&&"boolean"!=typeof n&&"function"!=typeof n?(a=o+h,(n=e.__k[o]="string"==typeof n||"number"==typeof n||"bigint"==typeof n||n.constructor==String?we(null,n,null,null,null):ye(n)?we(Pe,{children:n},null,null,null):null==n.constructor&&n.__b>0?we(n.type,n.props,n.key,n.ref?n.ref:null,n.__v):n).__=e,n.__b=e.__b+1,l=null,-1!=(u=n.__i=Te(n,r,a,d))&&(d--,(l=r[u])&&(l.__u|=2)),null==l||null==l.__v?(-1==u&&(s>p?h--:s<p&&h++),"function"!=typeof n.type&&(n.__u|=4)):u!=a&&(u==a-1?h--:u==a+1?h++:(u>a?h--:h++,n.__u|=4))):e.__k[o]=null;if(d)for(o=0;o<p;o++)null!=(l=r[o])&&!(2&l.__u)&&(l.__e==i&&(i=Oe(l)),De(l,l));return i}function je(e,t,r,i){var s,o;if("function"==typeof e.type){for(s=e.__k,o=0;s&&o<s.length;o++)s[o]&&(s[o].__=e,t=je(s[o],t,r,i));return t}e.__e!=t&&(i&&(t&&e.type&&!t.parentNode&&(t=Oe(e)),r.insertBefore(e.__e,t||null)),t=e.__e);do{t=t&&t.nextSibling}while(null!=t&&8==t.nodeType);return t}function Te(e,t,r,i){var s,o,n,l=e.key,a=e.type,u=t[r],p=null!=u&&!(2&u.__u);if(null===u&&null==e.key||p&&l==u.key&&a==u.type)return r;if(i>(p?1:0))for(s=r-1,o=r+1;s>=0||o<t.length;)if(null!=(u=t[n=s>=0?s--:o++])&&!(2&u.__u)&&l==u.key&&a==u.type)return n;return-1}function $e(e,t,r){"-"==t[0]?e.setProperty(t,null==r?"":r):e[t]=null==r?"":"number"!=typeof r||me.test(t)?r:r+"px"}function Re(e,t,r,i,s){var o,n;e:if("style"==t)if("string"==typeof r)e.style.cssText=r;else{if("string"==typeof i&&(e.style.cssText=i=""),i)for(t in i)r&&t in r||$e(e.style,t,"");if(r)for(t in r)i&&r[t]==i[t]||$e(e.style,t,r[t])}else if("o"==t[0]&&"n"==t[1])o=t!=(t=t.replace(ue,"$1")),n=t.toLowerCase(),t=n in e||"onFocusOut"==t||"onFocusIn"==t?n.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+o]=r,r?i?r.u=i.u:(r.u=pe,e.addEventListener(t,o?he:de,o)):e.removeEventListener(t,o?he:de,o);else{if("http://www.w3.org/2000/svg"==s)t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if("width"!=t&&"height"!=t&&"href"!=t&&"list"!=t&&"form"!=t&&"tabIndex"!=t&&"download"!=t&&"rowSpan"!=t&&"colSpan"!=t&&"role"!=t&&"popover"!=t&&t in e)try{e[t]=null==r?"":r;break e}catch(e){}"function"==typeof r||(null==r||!1===r&&"-"!=t[4]?e.removeAttribute(t):e.setAttribute(t,"popover"==t&&1==r?"":r))}}function Ae(e){return function(t){if(this.l){var r=this.l[t.type+e];if(null==t.t)t.t=pe++;else if(t.t<r.u)return;return r(re.event?re.event(t):t)}}}function Ce(e,t,r,i,s,o,n,l,a,u){var p,d,h,c,f,g,m,y,_,v,b,w,P,S,O,E,x,U=t.type;if(null!=t.constructor)return null;128&r.__u&&(a=!!(32&r.__u),o=[l=t.__e=r.__e]),(p=re.__b)&&p(t);e:if("function"==typeof U)try{if(y=t.props,_="prototype"in U&&U.prototype.render,v=(p=U.contextType)&&i[p.__c],b=p?v?v.props.value:p.__:i,r.__c?m=(d=t.__c=r.__c).__=d.__E:(_?t.__c=d=new U(y,b):(t.__c=d=new Se(y,b),d.constructor=U,d.render=qe),v&&v.sub(d),d.props=y,d.state||(d.state={}),d.context=b,d.__n=i,h=d.__d=!0,d.__h=[],d._sb=[]),_&&null==d.__s&&(d.__s=d.state),_&&null!=U.getDerivedStateFromProps&&(d.__s==d.state&&(d.__s=_e({},d.__s)),_e(d.__s,U.getDerivedStateFromProps(y,d.__s))),c=d.props,f=d.state,d.__v=t,h)_&&null==U.getDerivedStateFromProps&&null!=d.componentWillMount&&d.componentWillMount(),_&&null!=d.componentDidMount&&d.__h.push(d.componentDidMount);else{if(_&&null==U.getDerivedStateFromProps&&y!==c&&null!=d.componentWillReceiveProps&&d.componentWillReceiveProps(y,b),!d.__e&&null!=d.shouldComponentUpdate&&!1===d.shouldComponentUpdate(y,d.__s,b)||t.__v==r.__v){for(t.__v!=r.__v&&(d.props=y,d.state=d.__s,d.__d=!1),t.__e=r.__e,t.__k=r.__k,t.__k.some(function(e){e&&(e.__=t)}),w=0;w<d._sb.length;w++)d.__h.push(d._sb[w]);d._sb=[],d.__h.length&&n.push(d);break e}null!=d.componentWillUpdate&&d.componentWillUpdate(y,d.__s,b),_&&null!=d.componentDidUpdate&&d.__h.push(function(){d.componentDidUpdate(c,f,g)})}if(d.context=b,d.props=y,d.__P=e,d.__e=!1,P=re.__r,S=0,_){for(d.state=d.__s,d.__d=!1,P&&P(t),p=d.render(d.props,d.state,d.context),O=0;O<d._sb.length;O++)d.__h.push(d._sb[O]);d._sb=[]}else do{d.__d=!1,P&&P(t),p=d.render(d.props,d.state,d.context),d.state=d.__s}while(d.__d&&++S<25);d.state=d.__s,null!=d.getChildContext&&(i=_e(_e({},i),d.getChildContext())),_&&!h&&null!=d.getSnapshotBeforeUpdate&&(g=d.getSnapshotBeforeUpdate(c,f)),E=p,null!=p&&p.type===Pe&&null==p.key&&(E=Me(p.props.children)),l=Fe(e,ye(E)?E:[E],t,r,i,s,o,n,l,a,u),d.base=t.__e,t.__u&=-161,d.__h.length&&n.push(d),m&&(d.__E=d.__=null)}catch(e){if(t.__v=null,a||null!=o)if(e.then){for(t.__u|=a?160:128;l&&8==l.nodeType&&l.nextSibling;)l=l.nextSibling;o[o.indexOf(l)]=null,t.__e=l}else{for(x=o.length;x--;)ve(o[x]);Ne(t)}else t.__e=r.__e,t.__k=r.__k,e.then||Ne(t);re.__e(e,t,r)}else null==o&&t.__v==r.__v?(t.__k=r.__k,t.__e=r.__e):l=t.__e=Le(r.__e,t,r,i,s,o,n,a,u);return(p=re.diffed)&&p(t),128&t.__u?void 0:l}function Ne(e){e&&e.__c&&(e.__c.__e=!0),e&&e.__k&&e.__k.forEach(Ne)}function Ie(e,t,r){for(var i=0;i<r.length;i++)ze(r[i],r[++i],r[++i]);re.__c&&re.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){re.__e(e,t.__v)}})}function Me(e){return"object"!=typeof e||null==e||e.__b&&e.__b>0?e:ye(e)?e.map(Me):_e({},e)}function Le(e,t,r,i,s,o,n,l,a){var u,p,d,h,c,f,g,m=r.props,y=t.props,_=t.type;if("svg"==_?s="http://www.w3.org/2000/svg":"math"==_?s="http://www.w3.org/1998/Math/MathML":s||(s="http://www.w3.org/1999/xhtml"),null!=o)for(u=0;u<o.length;u++)if((c=o[u])&&"setAttribute"in c==!!_&&(_?c.localName==_:3==c.nodeType)){e=c,o[u]=null;break}if(null==e){if(null==_)return document.createTextNode(y);e=document.createElementNS(s,_,y.is&&y),l&&(re.__m&&re.__m(t,o),l=!1),o=null}if(null==_)m===y||l&&e.data==y||(e.data=y);else{if(o=o&&te.call(e.childNodes),m=r.props||fe,!l&&null!=o)for(m={},u=0;u<e.attributes.length;u++)m[(c=e.attributes[u]).name]=c.value;for(u in m)if(c=m[u],"children"==u);else if("dangerouslySetInnerHTML"==u)d=c;else if(!(u in y)){if("value"==u&&"defaultValue"in y||"checked"==u&&"defaultChecked"in y)continue;Re(e,u,null,c,s)}for(u in y)c=y[u],"children"==u?h=c:"dangerouslySetInnerHTML"==u?p=c:"value"==u?f=c:"checked"==u?g=c:l&&"function"!=typeof c||m[u]===c||Re(e,u,c,m[u],s);if(p)l||d&&(p.__html==d.__html||p.__html==e.innerHTML)||(e.innerHTML=p.__html),t.__k=[];else if(d&&(e.innerHTML=""),Fe("template"==t.type?e.content:e,ye(h)?h:[h],t,r,i,"foreignObject"==_?"http://www.w3.org/1999/xhtml":s,o,n,o?o[0]:r.__k&&Oe(r,0),l,a),null!=o)for(u=o.length;u--;)ve(o[u]);l||(u="value","progress"==_&&null==f?e.removeAttribute("value"):null!=f&&(f!==e[u]||"progress"==_&&!f||"option"==_&&f!=m[u])&&Re(e,u,f,m[u],s),u="checked",null!=g&&g!=e[u]&&Re(e,u,g,m[u],s))}return e}function ze(e,t,r){try{if("function"==typeof e){var i="function"==typeof e.__u;i&&e.__u(),i&&null==t||(e.__u=e(t))}else e.current=t}catch(e){re.__e(e,r)}}function De(e,t,r){var i,s;if(re.unmount&&re.unmount(e),(i=e.ref)&&(i.current&&i.current!=e.__e||ze(i,null,t)),null!=(i=e.__c)){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(e){re.__e(e,t)}i.base=i.__P=null}if(i=e.__k)for(s=0;s<i.length;s++)i[s]&&De(i[s],t,r||"function"!=typeof e.type);r||ve(e.__e),e.__c=e.__=e.__e=void 0}function qe(e,t,r){return this.constructor(e,r)}function He(e,t,r){var i,s,o,n;t==document&&(t=document.documentElement),re.__&&re.__(e,t),s=(i="function"==typeof r)?null:r&&r.__k||t.__k,o=[],n=[],Ce(t,e=(!i&&r||t).__k=be(Pe,null,[e]),s||fe,fe,t.namespaceURI,!i&&r?[r]:s?null:t.firstChild?te.call(t.childNodes):null,o,!i&&r?r:s?s.__e:t.firstChild,i,n),Ie(o,e,n)}te=ge.slice,re={__e:function(e,t,r,i){for(var s,o,n;t=t.__;)if((s=t.__c)&&!s.__)try{if((o=s.constructor)&&null!=o.getDerivedStateFromError&&(s.setState(o.getDerivedStateFromError(e)),n=s.__d),null!=s.componentDidCatch&&(s.componentDidCatch(e,i||{}),n=s.__d),n)return s.__E=s}catch(t){e=t}throw e}},ie=0,se=function(e){return null!=e&&null==e.constructor},Se.prototype.setState=function(e,t){var r;r=null!=this.__s&&this.__s!=this.state?this.__s:this.__s=_e({},this.state),"function"==typeof e&&(e=e(_e({},r),this.props)),e&&_e(r,e),null!=e&&this.__v&&(t&&this._sb.push(t),xe(this))},Se.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),xe(this))},Se.prototype.render=Pe,oe=[],le="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,ae=function(e,t){return e.__v.__b-t.__v.__b},Ue.__r=0,ue=/(PointerCapture)$|Capture$/i,pe=0,de=Ae(!1),he=Ae(!0),ce=0;var Be,We,Xe,Ke,Ge,Ve,Ye,Qe,Je,Ze,et,tt=Object.freeze({__proto__:null,Component:Se,Fragment:Pe,cloneElement:function(e,t,r){var i,s,o,n,l=_e({},e.props);for(o in e.type&&e.type.defaultProps&&(n=e.type.defaultProps),t)"key"==o?i=t[o]:"ref"==o?s=t[o]:l[o]=void 0===t[o]&&null!=n?n[o]:t[o];return arguments.length>2&&(l.children=arguments.length>3?te.call(arguments,2):r),we(e.type,l,i||e.key,s||e.ref,null)},createContext:function(e){function t(e){var r,i;return this.getChildContext||(r=new Set,(i={})[t.__c]=this,this.getChildContext=function(){return i},this.componentWillUnmount=function(){r=null},this.shouldComponentUpdate=function(e){this.props.value!=e.value&&r.forEach(function(e){e.__e=!0,xe(e)})},this.sub=function(e){r.add(e);var t=e.componentWillUnmount;e.componentWillUnmount=function(){r&&r.delete(e),t&&t.call(e)}}),e.children}return t.__c="__cC"+ce++,t.__=e,t.Provider=t.__l=(t.Consumer=function(e,t){return e.children(t)}).contextType=t,t},createElement:be,createRef:function(){return{current:null}},h:be,hydrate:function e(t,r){He(t,r,e)},get isValidElement(){return se},get options(){return re},render:He,toChildArray:function e(t,r){return r=r||[],null==t||"boolean"==typeof t||(ye(t)?t.some(function(t){e(t,r)}):r.push(t)),r}}),rt=o(tt);function it(){if(Ke)return Xe;Ke=1;const e=We?Be:(We=1,Be=function(e){return(null==e?void 0:e.nodeType)===Node.ELEMENT_NODE});return Xe=function(t,r){return void 0===r&&(r=document),"string"==typeof t?r.querySelector(t):e(t)?t:null}}function st(){if(Qe)return Ye;Qe=1;const e=V();return Ye=class{constructor(e,t){void 0===t&&(t={}),this.uppy=e,this.opts=t}getPluginState(){const{plugins:e}=this.uppy.getState();return e[this.id]||{}}setPluginState(e){const{plugins:t}=this.uppy.getState();this.uppy.setState({plugins:{...t,[this.id]:{...t[this.id],...e}}})}setOptions(e){this.opts={...this.opts,...e},this.setPluginState(),this.i18nInit()}i18nInit(){const t=new e([this.defaultLocale,this.uppy.locale,this.opts.locale]);this.i18n=t.translate.bind(t),this.i18nArray=t.translateArray.bind(t),this.setPluginState()}addTarget(){throw new Error("Extend the addTarget method to add your plugin to another plugin's target")}install(){}uninstall(){}render(){throw new Error("Extend the render method to add your plugin to a DOM element")}update(){}afterUpdate(){}}}function ot(){if(Ze)return Je;Ze=1;var e=rt;function t(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}var r=0;function i(e){return"__private_"+r+++"_"+e}const s=it(),o=Ve?Ge:(Ve=1,Ge=function(e){for(var t;e&&!e.dir;)e=e.parentNode;return null==(t=e)?void 0:t.dir}),n=st();var l=i("updateUI");class a extends n{constructor(){super(...arguments),Object.defineProperty(this,l,{writable:!0,value:void 0})}mount(r,i){const n=i.id,u=s(r);if(u){this.isTargetDOMEl=!0;const i=document.createElement("div");return i.classList.add("uppy-Root"),t(this,l)[l]=function(e){let t=null,r=null;return function(){for(var i=arguments.length,s=new Array(i),o=0;o<i;o++)s[o]=arguments[o];return r=s,t||(t=Promise.resolve().then(()=>(t=null,e(...r)))),t}}(t=>{this.uppy.getPlugin(this.id)&&((0,e.render)(this.render(t),i),this.afterUpdate())}),this.uppy.log(`Installing ${n} to a DOM element '${r}'`),this.opts.replaceTargetContent&&(u.innerHTML=""),(0,e.render)(this.render(this.uppy.getState()),i),this.el=i,u.appendChild(i),i.dir=this.opts.direction||o(i)||"ltr",this.onMount(),this.el}let p;if("object"==typeof r&&r instanceof a)p=r;else if("function"==typeof r){const e=r;this.uppy.iteratePlugins(t=>{t instanceof e&&(p=t)})}if(p)return this.uppy.log(`Installing ${n} to ${p.id}`),this.parent=p,this.el=p.addTarget(i),this.onMount(),this.el;this.uppy.log(`Not installing ${n}`);let d=`Invalid target option given to ${n}.`;throw d+="function"==typeof r?" The given target is not a Plugin class. Please check that you're not specifying a React Component instead of a plugin. If you are using @uppy/* packages directly, make sure you have only 1 version of @uppy/core installed: run `npm ls @uppy/core` on the command line and verify that all the versions match and are deduped correctly.":"If you meant to target an HTML element, please make sure that the element exists. Check that the <script> tag initializing Uppy is right before the closing </body> tag at the end of the page. (see https://github.com/transloadit/uppy/issues/1042)\n\nIf you meant to target a plugin, please confirm that your `import` statements or `require` calls are correct.",new Error(d)}update(e){var r,i;null!=this.el&&(null==(r=(i=t(this,l))[l])||r.call(i,e))}unmount(){var e;this.isTargetDOMEl&&(null==(e=this.el)||e.remove());this.onUnmount()}onMount(){}onUnmount(){}}return Je=a}var nt,lt,at,ut,pt,dt,ht,ct,ft,gt,mt=(et||(et=1,function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.Uppy=t.UIPlugin=t.BasePlugin=void 0,Object.defineProperty(t,"debugLogger",{enumerable:!0,get:function(){return r.debugLogger}});var r=d();e.exports=ee();const i=ot();t.UIPlugin=i;const s=st();t.BasePlugin=s;const o=ee();t.Uppy=o;const n=ot(),l=st();o.Uppy=o,o.UIPlugin=n,o.BasePlugin=l,o.debugLogger=r.debugLogger}(u,u.exports)),u.exports),yt=s(mt),_t={};function vt(){if(lt)return nt;lt=1;class e extends Error{constructor(e,t){void 0===t&&(t=null),super("This looks like a network error, the endpoint might be blocked by an internet provider or a firewall."),this.cause=e,this.isNetworkError=!0,this.request=t}}return nt=e}function bt(){if(gt)return ft;let e;function t(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}gt=1;var r=0;function i(e){return"__private_"+r+++"_"+e}const s=function(){if(ut)return at;ut=1;const e=vt();return at=function(){return fetch(...arguments).catch(t=>{throw"AbortError"===t.name?t:new e(t)})},at}(),o=function(){if(dt)return pt;dt=1;const e=G();class t extends Error{constructor(t,r){void 0===r&&(r={}),super(t),this.cause=r.cause,this.cause&&e(this.cause,"isNetworkError")&&(this.isNetworkError=this.cause.isNetworkError)}}return pt=t}(),n=function(){if(ct)return ht;ct=1;class e extends Error{constructor(){super("Authorization required"),this.name="AuthError",this.isAuthError=!0}}return ht=e}();async function l(e){if(401===e.status)throw new n;const t=e.json();if(e.status<200||e.status>300){let r=`Failed request with status: ${e.status}. ${e.statusText}`;try{const e=await t;r=e.message?`${r} message: ${e.message}`:r,r=e.requestId?`${r} request-Id: ${e.requestId}`:r}finally{throw new Error(r)}}return t}var a=i("companionHeaders"),u=i("getPostResponseFunc"),p=i("getUrl"),d=i("errorHandler");e=Symbol.for("uppy test: getCompanionHeaders");class h{constructor(e,r){Object.defineProperty(this,d,{value:f}),Object.defineProperty(this,p,{value:c}),Object.defineProperty(this,a,{writable:!0,value:void 0}),Object.defineProperty(this,u,{writable:!0,value:e=>t=>e?t:this.onReceiveResponse(t)}),this.uppy=e,this.opts=r,this.onReceiveResponse=this.onReceiveResponse.bind(this),this.allowedHeaders=["accept","content-type","uppy-auth-token"],this.preflightDone=!1,t(this,a)[a]=null==r?void 0:r.companionHeaders}setCompanionHeaders(e){t(this,a)[a]=e}[e](){return t(this,a)[a]}get hostname(){const{companion:e}=this.uppy.getState(),t=this.opts.companionUrl;return(e&&e[t]?e[t]:t).replace(/\/$/,"")}headers(){return Promise.resolve({...h.defaultHeaders,...t(this,a)[a]})}onReceiveResponse(e){const t=this.uppy.getState().companion||{},r=this.opts.companionUrl,{headers:i}=e;return i.has("i-am")&&i.get("i-am")!==t[r]&&this.uppy.setState({companion:{...t,[r]:i.get("i-am")}}),e}preflight(e){return this.preflightDone?Promise.resolve(this.allowedHeaders.slice()):fetch(t(this,p)[p](e),{method:"OPTIONS"}).then(e=>(e.headers.has("access-control-allow-headers")&&(this.allowedHeaders=e.headers.get("access-control-allow-headers").split(",").map(e=>e.trim().toLowerCase())),this.preflightDone=!0,this.allowedHeaders.slice())).catch(e=>(this.uppy.log(`[CompanionClient] unable to make preflight request ${e}`,"warning"),this.preflightDone=!0,this.allowedHeaders.slice()))}preflightAndHeaders(e){return Promise.all([this.preflight(e),this.headers()]).then(e=>{let[t,r]=e;return Object.keys(r).forEach(e=>{t.includes(e.toLowerCase())||(this.uppy.log(`[CompanionClient] excluding disallowed header ${e}`),delete r[e])}),r})}get(e,r){return this.preflightAndHeaders(e).then(r=>s(t(this,p)[p](e),{method:"get",headers:r,credentials:this.opts.companionCookiesRule||"same-origin"})).then(t(this,u)[u](r)).then(l).catch(t(this,d)[d]("get",e))}post(e,r,i){const o="post";return this.preflightAndHeaders(e).then(i=>s(t(this,p)[p](e),{method:o,headers:i,credentials:this.opts.companionCookiesRule||"same-origin",body:JSON.stringify(r)})).then(t(this,u)[u](i)).then(l).catch(t(this,d)[d](o,e))}delete(e,r,i){const o="delete";return this.preflightAndHeaders(e).then(t=>s(`${this.hostname}/${e}`,{method:o,headers:t,credentials:this.opts.companionCookiesRule||"same-origin",body:r?JSON.stringify(r):null})).then(t(this,u)[u](i)).then(l).catch(t(this,d)[d](o,e))}}function c(e){return/^(https?:|)\/\//.test(e)?e:`${this.hostname}/${e}`}function f(e,r){return i=>{var s;return null!=(s=i)&&s.isAuthError||(i=new o(`Could not ${e} ${t(this,p)[p](r)}`,{cause:i})),Promise.reject(i)}}return h.VERSION="2.2.2",h.defaultHeaders={Accept:"application/json","Content-Type":"application/json","Uppy-Versions":`@uppy/companion-client=${h.VERSION}`},ft=h}var wt,Pt,St,Ot,Et,xt,Ut,Ft,kt={};function jt(){if(wt)return kt;return wt=1,Object.defineProperty(kt,"__esModule",{value:!0}),kt.getItem=function(e){return Promise.resolve(localStorage.getItem(e))},kt.removeItem=function(e){return new Promise(t=>{localStorage.removeItem(e),t()})},kt.setItem=function(e,t){return new Promise(r=>{localStorage.setItem(e,t),r()})},kt}function Tt(){if(Ft)return _t;Ft=1,Object.defineProperty(_t,"__esModule",{value:!0}),_t.Socket=_t.SearchProvider=_t.RequestClient=_t.Provider=void 0;const e=bt();_t.RequestClient=e;const t=function(){if(St)return Pt;St=1;var e=jt();const t=bt();return Pt=class extends t{constructor(e,t){super(e,t),this.provider=t.provider,this.id=this.provider,this.name=this.opts.name||this.id.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),this.pluginId=this.opts.pluginId,this.tokenKey=`companion-${this.pluginId}-auth-token`,this.companionKeysParams=this.opts.companionKeysParams,this.preAuthToken=null}headers(){return Promise.all([super.headers(),this.getAuthToken()]).then(e=>{let[t,r]=e;const i={};return r&&(i["uppy-auth-token"]=r),this.companionKeysParams&&(i["uppy-credentials-params"]=btoa(JSON.stringify({params:this.companionKeysParams}))),{...t,...i}})}onReceiveResponse(e){e=super.onReceiveResponse(e);const t=this.uppy.getPlugin(this.pluginId),r=t.getPluginState().authenticated?401!==e.status:e.status<400;return t.setPluginState({authenticated:r}),e}setAuthToken(e){return this.uppy.getPlugin(this.pluginId).storage.setItem(this.tokenKey,e)}getAuthToken(){return this.uppy.getPlugin(this.pluginId).storage.getItem(this.tokenKey)}async ensurePreAuth(){if(this.companionKeysParams&&!this.preAuthToken&&(await this.fetchPreAuthToken(),!this.preAuthToken))throw new Error("Could not load authentication data required for third-party login. Please try again later.")}authUrl(e){void 0===e&&(e={});const t=new URLSearchParams(e);return this.preAuthToken&&t.set("uppyPreAuthToken",this.preAuthToken),`${this.hostname}/${this.id}/connect?${t}`}fileUrl(e){return`${this.hostname}/${this.id}/get/${e}`}async fetchPreAuthToken(){if(this.companionKeysParams)try{const e=await this.post(`${this.id}/preauth/`,{params:this.companionKeysParams});this.preAuthToken=e.token}catch(e){this.uppy.log(`[CompanionClient] unable to fetch preAuthToken ${e}`,"warning")}}list(e){return this.get(`${this.id}/list/${e||""}`)}logout(){return this.get(`${this.id}/logout`).then(e=>Promise.all([e,this.uppy.getPlugin(this.pluginId).storage.removeItem(this.tokenKey)])).then(e=>{let[t]=e;return t})}static initPlugin(t,r,i){if(t.type="acquirer",t.files=[],i&&(t.opts={...i,...r}),r.serverUrl||r.serverPattern)throw new Error("`serverUrl` and `serverPattern` have been renamed to `companionUrl` and `companionAllowedHosts` respectively in the 0.30.5 release. Please consult the docs (for example, https://uppy.io/docs/instagram/ for the Instagram plugin) and use the updated options.`");if(r.companionAllowedHosts){const e=r.companionAllowedHosts;if(!("string"==typeof e||Array.isArray(e)||e instanceof RegExp))throw new TypeError(`${t.id}: the option "companionAllowedHosts" must be one of string, Array, RegExp`);t.opts.companionAllowedHosts=e}else/^(?!https?:\/\/).*$/i.test(r.companionUrl)?t.opts.companionAllowedHosts=`https://${r.companionUrl.replace(/^\/\//,"")}`:t.opts.companionAllowedHosts=new URL(r.companionUrl).origin;t.storage=t.opts.storage||e}},Pt}();_t.Provider=t;const r=function(){if(Et)return Ot;Et=1;const e=bt();return Ot=class extends e{constructor(e,t){super(e,t),this.provider=t.provider,this.id=this.provider,this.name=this.opts.name||this.id.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),this.pluginId=this.opts.pluginId}fileUrl(e){return`${this.hostname}/search/${this.id}/get/${e}`}search(e,t){return this.get(`search/${this.id}/list?q=${encodeURIComponent(e)}${t?`&${t}`:""}`)}},Ot}();_t.SearchProvider=r;const i=function(){if(Ut)return xt;let e,t;function r(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}Ut=1;var i=0;function s(e){return"__private_"+i+++"_"+e}const o=Y();var n=s("queued"),l=s("emitter"),a=s("isOpen"),u=s("socket"),p=s("handleMessage");return e=Symbol.for("uppy test: getSocket"),t=Symbol.for("uppy test: getQueued"),xt=class{constructor(e){Object.defineProperty(this,n,{writable:!0,value:[]}),Object.defineProperty(this,l,{writable:!0,value:o()}),Object.defineProperty(this,a,{writable:!0,value:!1}),Object.defineProperty(this,u,{writable:!0,value:void 0}),Object.defineProperty(this,p,{writable:!0,value:e=>{try{const t=JSON.parse(e.data);this.emit(t.action,t.payload)}catch(e){console.log(e)}}}),this.opts=e,e&&!1===e.autoOpen||this.open()}get isOpen(){return r(this,a)[a]}[e](){return r(this,u)[u]}[t](){return r(this,n)[n]}open(){r(this,u)[u]=new WebSocket(this.opts.target),r(this,u)[u].onopen=()=>{for(r(this,a)[a]=!0;r(this,n)[n].length>0&&r(this,a)[a];){const e=r(this,n)[n].shift();this.send(e.action,e.payload)}},r(this,u)[u].onclose=()=>{r(this,a)[a]=!1},r(this,u)[u].onmessage=r(this,p)[p]}close(){var e;null==(e=r(this,u)[u])||e.close()}send(e,t){r(this,a)[a]?r(this,u)[u].send(JSON.stringify({action:e,payload:t})):r(this,n)[n].push({action:e,payload:t})}on(e,t){r(this,l)[l].on(e,t)}emit(e,t){r(this,l)[l].emit(e,t)}once(e,t){r(this,l)[l].once(e,t)}},xt}();return _t.Socket=i,_t}var $t,Rt,At,Ct,Nt,It,Mt,Lt,zt,Dt,qt,Ht,Bt,Wt,Xt,Kt,Gt,Vt={};function Yt(){if($t)return Vt;function e(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}$t=1,Object.defineProperty(Vt,"__esModule",{value:!0}),Vt.internalRateLimitedQueue=Vt.RateLimitedQueue=void 0;var t=0;function r(e){return"__private_"+t+++"_"+e}var i=r("activeRequests"),s=r("queuedHandlers"),o=r("paused"),n=r("pauseTimer"),l=r("downLimit"),a=r("upperLimit"),u=r("rateLimitingTimer"),p=r("call"),d=r("queueNext"),h=r("next"),c=r("queue"),f=r("dequeue"),g=r("resume"),m=r("increaseLimit");function y(t){e(this,i)[i]+=1;let r,s=!1;try{r=t()}catch(t){throw e(this,i)[i]-=1,t}return{abort:()=>{s||(s=!0,e(this,i)[i]-=1,r(),e(this,d)[d]())},done:()=>{s||(s=!0,e(this,i)[i]-=1,e(this,d)[d]())}}}function _(){queueMicrotask(()=>e(this,h)[h]())}function v(){if(e(this,o)[o]||e(this,i)[i]>=this.limit)return;if(0===e(this,s)[s].length)return;const t=e(this,s)[s].shift(),r=e(this,p)[p](t.fn);t.abort=r.abort,t.done=r.done}function b(t,r){void 0===r&&(r={});const i={fn:t,priority:r.priority||0,abort:()=>{e(this,f)[f](i)},done:()=>{throw new Error("Cannot mark a queued request as done: this indicates a bug")}},o=e(this,s)[s].findIndex(e=>i.priority>e.priority);return-1===o?e(this,s)[s].push(i):e(this,s)[s].splice(o,0,i),i}function w(t){const r=e(this,s)[s].indexOf(t);-1!==r&&e(this,s)[s].splice(r,1)}Vt.RateLimitedQueue=class{constructor(t){Object.defineProperty(this,f,{value:w}),Object.defineProperty(this,c,{value:b}),Object.defineProperty(this,h,{value:v}),Object.defineProperty(this,d,{value:_}),Object.defineProperty(this,p,{value:y}),Object.defineProperty(this,i,{writable:!0,value:0}),Object.defineProperty(this,s,{writable:!0,value:[]}),Object.defineProperty(this,o,{writable:!0,value:!1}),Object.defineProperty(this,n,{writable:!0,value:void 0}),Object.defineProperty(this,l,{writable:!0,value:1}),Object.defineProperty(this,a,{writable:!0,value:void 0}),Object.defineProperty(this,u,{writable:!0,value:void 0}),Object.defineProperty(this,g,{writable:!0,value:()=>this.resume()}),Object.defineProperty(this,m,{writable:!0,value:()=>{if(e(this,o)[o])e(this,u)[u]=setTimeout(e(this,m)[m],0);else{e(this,l)[l]=this.limit,this.limit=Math.ceil((e(this,a)[a]+e(this,l)[l])/2);for(let t=e(this,l)[l];t<=this.limit;t++)e(this,d)[d]();e(this,a)[a]-e(this,l)[l]>3?e(this,u)[u]=setTimeout(e(this,m)[m],2e3):e(this,l)[l]=Math.floor(e(this,l)[l]/2)}}}),this.limit="number"!=typeof t||0===t?1/0:t}run(t,r){return!e(this,o)[o]&&e(this,i)[i]<this.limit?e(this,p)[p](t):e(this,c)[c](t,r)}wrapPromiseFunction(e,t){var r=this;return function(){for(var i=arguments.length,s=new Array(i),o=0;o<i;o++)s[o]=arguments[o];let n;const l=new Promise((i,o)=>{n=r.run(()=>{let t,r;try{r=Promise.resolve(e(...s))}catch(e){r=Promise.reject(e)}return r.then(e=>{t?o(t):(n.done(),i(e))},e=>{t?o(t):(n.done(),o(e))}),()=>{t=new Error("Cancelled")}},t)});return l.abort=()=>{n.abort()},l}}resume(){e(this,o)[o]=!1,clearTimeout(e(this,n)[n]);for(let t=0;t<this.limit;t++)e(this,d)[d]()}pause(t){void 0===t&&(t=null),e(this,o)[o]=!0,clearTimeout(e(this,n)[n]),null!=t&&(e(this,n)[n]=setTimeout(e(this,g)[g],t))}rateLimit(t){clearTimeout(e(this,u)[u]),this.pause(t),this.limit>1&&Number.isFinite(this.limit)&&(e(this,a)[a]=this.limit-1,this.limit=e(this,l)[l],e(this,u)[u]=setTimeout(e(this,m)[m],t))}get isPaused(){return e(this,o)[o]}};const P=Symbol("__queue");return Vt.internalRateLimitedQueue=P,Vt}function Qt(){return Xt?Wt:(Xt=1,Wt={strings:{timedOut:"Upload stalled for %{seconds} seconds, aborting."}})}var Jt=function(){if(Gt)return Kt;Gt=1;var e=H,r=Tt(),i=Yt();const s=st(),o=At?Rt:(At=1,Rt=t(function(e,t,r){const{progress:i,bytesUploaded:s,bytesTotal:o}=t;i&&(e.uppy.log(`Upload progress: ${i}`),e.uppy.emit("upload-progress",r,{uploader:e,bytesUploaded:s,bytesTotal:o}))},300,{leading:!0,trailing:!0})),n=Nt?Ct:(Nt=1,Ct=function(e){const t=/^(?:https?:\/\/|\/\/)?(?:[^@\n]+@)?(?:www\.)?([^\n]+)/i.exec(e)[1];return`${/^http:\/\//i.test(e)?"ws":"wss"}://${t}`}),l=Mt?It:(Mt=1,It=function(e){const t=[],r=[];function i(e){t.push(e)}function s(e){r.push(e)}return Promise.all(e.map(e=>e.then(i,s))).then(()=>({successful:t,failed:r}))}),a=function(){if(zt)return Lt;function e(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}zt=1;var t=0;function r(e){return"__private_"+t+++"_"+e}var i=r("emitter"),s=r("events");return Lt=class{constructor(t){Object.defineProperty(this,i,{writable:!0,value:void 0}),Object.defineProperty(this,s,{writable:!0,value:[]}),e(this,i)[i]=t}on(t,r){return e(this,s)[s].push([t,r]),e(this,i)[i].on(t,r)}remove(){for(const[t,r]of e(this,s)[s].splice(0))e(this,i)[i].off(t,r)}}}(),u=function(){if(qt)return Dt;function e(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}qt=1;var t=0;function r(e){return"__private_"+t+++"_"+e}var i=r("aliveTimer"),s=r("isDone"),o=r("onTimedOut"),n=r("timeout");return Dt=class{constructor(t,r){Object.defineProperty(this,i,{writable:!0,value:void 0}),Object.defineProperty(this,s,{writable:!0,value:!1}),Object.defineProperty(this,o,{writable:!0,value:void 0}),Object.defineProperty(this,n,{writable:!0,value:void 0}),e(this,n)[n]=t,e(this,o)[o]=r}progress(){e(this,s)[s]||e(this,n)[n]>0&&(clearTimeout(e(this,i)[i]),e(this,i)[i]=setTimeout(e(this,o)[o],e(this,n)[n]))}done(){e(this,s)[s]||(clearTimeout(e(this,i)[i]),e(this,i)[i]=null,e(this,s)[s]=!0)}}}(),p=vt(),d=Bt?Ht:(Bt=1,Ht=function(e){return!!e&&(0!==e.readyState&&4!==e.readyState||0===e.status)}),h=Qt();function c(e,t){let r=t;return r||(r=new Error("Upload error")),"string"==typeof r&&(r=new Error(r)),r instanceof Error||(r=Object.assign(new Error("Upload error"),{data:r})),d(e)?(r=new p(r,e),r):(r.request=e,r)}function f(e){return e.data.slice(0,e.data.size,e.meta.type)}class g extends s{constructor(e,t){super(e,t),this.type="uploader",this.id=this.opts.id||"XHRUpload",this.title="XHRUpload",this.defaultLocale=h;const r={formData:!0,fieldName:t.bundle?"files[]":"file",method:"post",metaFields:null,responseUrlFieldName:"url",bundle:!1,headers:{},timeout:3e4,limit:5,withCredentials:!1,responseType:"",getResponseData(t){let r={};try{r=JSON.parse(t)}catch(t){e.log(t)}return r},getResponseError(e,t){let r=new Error("Upload error");return d(t)&&(r=new p(r,t)),r},validateStatus:e=>e>=200&&e<300};if(this.opts={...r,...t},this.i18nInit(),this.handleUpload=this.handleUpload.bind(this),i.internalRateLimitedQueue in this.opts?this.requests=this.opts[i.internalRateLimitedQueue]:this.requests=new i.RateLimitedQueue(this.opts.limit),this.opts.bundle&&!this.opts.formData)throw new Error("`opts.formData` must be true when `opts.bundle` is enabled.");this.uploaderEvents=Object.create(null)}getOptions(e){const t=this.uppy.getState().xhrUpload,{headers:r}=this.opts,i={...this.opts,...t||{},...e.xhrUpload||{},headers:{}};return"function"==typeof r?i.headers=r(e):Object.assign(i.headers,this.opts.headers),t&&Object.assign(i.headers,t.headers),e.xhrUpload&&Object.assign(i.headers,e.xhrUpload.headers),i}addMetadata(e,t,r){(Array.isArray(r.metaFields)?r.metaFields:Object.keys(t)).forEach(r=>{e.append(r,t[r])})}createFormDataUpload(e,t){const r=new FormData;this.addMetadata(r,e.meta,t);const i=f(e);return e.name?r.append(t.fieldName,i,e.meta.name):r.append(t.fieldName,i),r}createBundledUpload(e,t){const r=new FormData,{meta:i}=this.uppy.getState();return this.addMetadata(r,i,t),e.forEach(e=>{const t=this.getOptions(e),i=f(e);e.name?r.append(t.fieldName,i,e.name):r.append(t.fieldName,i)}),r}upload(t,r,i){const s=this.getOptions(t);return this.uppy.log(`uploading ${r} of ${i}`),new Promise((r,i)=>{this.uppy.emit("upload-started",t);const o=s.formData?this.createFormDataUpload(t,s):t.data,n=new XMLHttpRequest;let l;this.uploaderEvents[t.id]=new a(this.uppy);const p=new u(s.timeout,()=>{n.abort(),l.done();const e=new Error(this.i18n("timedOut",{seconds:Math.ceil(s.timeout/1e3)}));this.uppy.emit("upload-error",t,e),i(e)}),d=(0,e.nanoid)();n.upload.addEventListener("loadstart",()=>{this.uppy.log(`[XHRUpload] ${d} started`)}),n.upload.addEventListener("progress",e=>{this.uppy.log(`[XHRUpload] ${d} progress: ${e.loaded} / ${e.total}`),p.progress(),e.lengthComputable&&this.uppy.emit("upload-progress",t,{uploader:this,bytesUploaded:e.loaded,bytesTotal:e.total})}),n.addEventListener("load",()=>{if(this.uppy.log(`[XHRUpload] ${d} finished`),p.done(),l.done(),this.uploaderEvents[t.id]&&(this.uploaderEvents[t.id].remove(),this.uploaderEvents[t.id]=null),s.validateStatus(n.status,n.responseText,n)){const e=s.getResponseData(n.responseText,n),i=e[s.responseUrlFieldName],o={status:n.status,body:e,uploadURL:i};return this.uppy.emit("upload-success",t,o),i&&this.uppy.log(`Download ${t.name} from ${i}`),r(t)}const e=s.getResponseData(n.responseText,n),o=c(n,s.getResponseError(n.responseText,n)),a={status:n.status,body:e};return this.uppy.emit("upload-error",t,o,a),i(o)}),n.addEventListener("error",()=>{this.uppy.log(`[XHRUpload] ${d} errored`),p.done(),l.done(),this.uploaderEvents[t.id]&&(this.uploaderEvents[t.id].remove(),this.uploaderEvents[t.id]=null);const e=c(n,s.getResponseError(n.responseText,n));return this.uppy.emit("upload-error",t,e),i(e)}),n.open(s.method.toUpperCase(),s.endpoint,!0),n.withCredentials=s.withCredentials,""!==s.responseType&&(n.responseType=s.responseType),l=this.requests.run(()=>{this.uppy.emit("upload-started",t);const e=this.getOptions(t);return Object.keys(e.headers).forEach(t=>{n.setRequestHeader(t,e.headers[t])}),n.send(o),()=>{p.done(),n.abort()}}),this.onFileRemove(t.id,()=>{l.abort(),i(new Error("File removed"))}),this.onCancelAll(t.id,e=>{let{reason:t}=e;"user"===t&&l.abort(),i(new Error("Upload cancelled"))})})}uploadRemote(e){const t=this.getOptions(e);return new Promise((i,s)=>{this.uppy.emit("upload-started",e);const l={};(Array.isArray(t.metaFields)?t.metaFields:Object.keys(e.meta)).forEach(t=>{l[t]=e.meta[t]});new(e.remote.providerOptions.provider?r.Provider:r.RequestClient)(this.uppy,e.remote.providerOptions).post(e.remote.url,{...e.remote.body,endpoint:t.endpoint,size:e.data.size,fieldname:t.fieldName,metadata:l,httpMethod:t.method,useFormData:t.formData,headers:t.headers}).then(l=>{const{token:u}=l,p=n(e.remote.companionUrl),d=new r.Socket({target:`${p}/api/${u}`,autoOpen:!1});let h;this.uploaderEvents[e.id]=new a(this.uppy),this.onFileRemove(e.id,()=>{d.send("cancel",{}),h.abort(),i(`upload ${e.id} was removed`)}),this.onCancelAll(e.id,function(t){let{reason:r}=void 0===t?{}:t;"user"===r&&(d.send("cancel",{}),h.abort()),i(`upload ${e.id} was canceled`)}),this.onRetry(e.id,()=>{d.send("pause",{}),d.send("resume",{})}),this.onRetryAll(e.id,()=>{d.send("pause",{}),d.send("resume",{})}),d.on("progress",t=>o(this,t,e)),d.on("success",r=>{const s=t.getResponseData(r.response.responseText,r.response),o=s[t.responseUrlFieldName],n={status:r.response.status,body:s,uploadURL:o};return this.uppy.emit("upload-success",e,n),h.done(),this.uploaderEvents[e.id]&&(this.uploaderEvents[e.id].remove(),this.uploaderEvents[e.id]=null),i()}),d.on("error",r=>{const i=r.response,o=i?t.getResponseError(i.responseText,i):Object.assign(new Error(r.error.message),{cause:r.error});this.uppy.emit("upload-error",e,o),h.done(),this.uploaderEvents[e.id]&&(this.uploaderEvents[e.id].remove(),this.uploaderEvents[e.id]=null),s(o)}),h=this.requests.run(()=>(d.open(),e.isPaused&&d.send("pause",{}),()=>d.close()))}).catch(t=>{this.uppy.emit("upload-error",e,t),s(t)})})}uploadBundle(e){return new Promise((t,r)=>{const{endpoint:i}=this.opts,{method:s}=this.opts,o=this.uppy.getState().xhrUpload,n=this.createBundledUpload(e,{...this.opts,...o||{}}),l=new XMLHttpRequest,a=t=>{e.forEach(e=>{this.uppy.emit("upload-error",e,t)})},p=new u(this.opts.timeout,()=>{l.abort();const e=new Error(this.i18n("timedOut",{seconds:Math.ceil(this.opts.timeout/1e3)}));a(e),r(e)});l.upload.addEventListener("loadstart",()=>{this.uppy.log("[XHRUpload] started uploading bundle"),p.progress()}),l.upload.addEventListener("progress",t=>{p.progress(),t.lengthComputable&&e.forEach(e=>{this.uppy.emit("upload-progress",e,{uploader:this,bytesUploaded:t.loaded/t.total*e.size,bytesTotal:e.size})})}),l.addEventListener("load",i=>{if(p.done(),this.opts.validateStatus(i.target.status,l.responseText,l)){const r=this.opts.getResponseData(l.responseText,l),s={status:i.target.status,body:r};return e.forEach(e=>{this.uppy.emit("upload-success",e,s)}),t()}const s=this.opts.getResponseError(l.responseText,l)||new Error("Upload error");return s.request=l,a(s),r(s)}),l.addEventListener("error",()=>{p.done();const e=this.opts.getResponseError(l.responseText,l)||new Error("Upload error");return a(e),r(e)}),this.uppy.on("cancel-all",function(e){let{reason:t}=void 0===e?{}:e;"user"===t&&(p.done(),l.abort())}),l.open(s.toUpperCase(),i,!0),l.withCredentials=this.opts.withCredentials,""!==this.opts.responseType&&(l.responseType=this.opts.responseType),Object.keys(this.opts.headers).forEach(e=>{l.setRequestHeader(e,this.opts.headers[e])}),l.send(n),e.forEach(e=>{this.uppy.emit("upload-started",e)})})}uploadFiles(e){const t=e.map((t,r)=>{const i=parseInt(r,10)+1,s=e.length;return t.error?Promise.reject(new Error(t.error)):t.isRemote?this.uploadRemote(t,i,s):this.upload(t,i,s)});return l(t)}onFileRemove(e,t){this.uploaderEvents[e].on("file-removed",r=>{e===r.id&&t(r.id)})}onRetry(e,t){this.uploaderEvents[e].on("upload-retry",r=>{e===r&&t()})}onRetryAll(e,t){this.uploaderEvents[e].on("retry-all",()=>{this.uppy.getFile(e)&&t()})}onCancelAll(e,t){var r=this;this.uploaderEvents[e].on("cancel-all",function(){r.uppy.getFile(e)&&t(...arguments)})}handleUpload(e){if(0===e.length)return this.uppy.log("[XHRUpload] No files to upload!"),Promise.resolve();0!==this.opts.limit||this.opts[i.internalRateLimitedQueue]||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 t=e.map(e=>this.uppy.getFile(e));if(this.opts.bundle){if(t.some(e=>e.isRemote))throw new Error("Can’t upload remote files when the `bundle: true` option is set");if("function"==typeof this.opts.headers)throw new TypeError("`headers` may not be a function when the `bundle: true` option is set");return this.uploadBundle(t)}return this.uploadFiles(t).then(()=>null)}install(){if(this.opts.bundle){const{capabilities:e}=this.uppy.getState();this.uppy.setState({capabilities:{...e,individualCancellation:!1}})}this.uppy.addUploader(this.handleUpload)}uninstall(){if(this.opts.bundle){const{capabilities:e}=this.uppy.getState();this.uppy.setState({capabilities:{...e,individualCancellation:!0}})}this.uppy.removeUploader(this.handleUpload)}}return g.VERSION="2.1.3",Kt=g}(),Zt=s(Jt);function er(e,t){var i=function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var i,s,o=r.call(e),n=[];try{for(;(void 0===t||t-- >0)&&!(i=o.next()).done;)n.push(i.value)}catch(e){s={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(s)throw s.error}}return n}(e.split("#"),2),s=i[0],o=i[1],n=[];r(t,function(e,t){n.push("".concat(t,"=").concat(e))});var l=n.join("&");return s=s.indexOf("?")>0?"".concat(s,"&").concat(l):"".concat(s,"?").concat(l),o?"".concat(s,"#").concat(o):s}function tr(e){return e||{name:""}}function rr(e){var t=e.server,r=void 0===t?"":t,s=e.fieldName,o=void 0===s?"":s,n=e.maxFileSize,l=void 0===n?10485760:n,a=e.maxNumberOfFiles,u=void 0===a?100:a,p=e.meta,d=void 0===p?{}:p,h=e.metaWithUrl,c=void 0!==h&&h,f=e.headers,g=void 0===f?{}:f,m=e.withCredentials,y=void 0!==m&&m,_=e.timeout,v=void 0===_?1e4:_,b=e.onBeforeUpload,w=void 0===b?function(e){return e}:b,P=e.onSuccess,S=void 0===P?function(e,t){}:P,O=e.onError,E=void 0===O?function(e,t,r){console.error("".concat(e.name," upload error"),t,r)}:O,x=e.onProgress,U=void 0===x?function(e){}:x;if(!r)throw new Error("Cannot get upload server address\n没有配置上传地址");if(!o)throw new Error("Cannot get fieldName\n没有配置 fieldName");var F=r;c&&(F=er(F,d));var k=new yt(i({onBeforeUpload:function(e){return w(e)},restrictions:{maxFileSize:l,maxNumberOfFiles:u},meta:d},e.uppyConfig)).use(Zt,i({endpoint:F,headers:g,formData:!0,fieldName:o,bundle:!1,withCredentials:y,timeout:v},e.xhrConfig));return k.on("upload-success",function(e,t){var r=(null!=t?t:{}).body,i=void 0===r?{}:r,s=tr(e);try{S(s,i)}catch(e){console.error("wangEditor upload file - onSuccess error",e)}}),k.on("progress",function(e){e<1||U(e)}),k.on("upload-error",function(e,t,r){var i=tr(e);try{E(i,t,r)}catch(e){console.error("wangEditor upload file - onError error",e)}}),k.on("restriction-failed",function(e,t){var r=tr(e);try{E(r,t,void 0)}catch(e){console.error("wangEditor upload file - onError error",e)}}),k}function ir(e,t){return e.uploadAdapter?e.uploadAdapter({config:e,editor:t}):rr(e)}export{ir as createUploader,rr as createUppyUploader};
|
|
1
|
+
import r from"@uppy/core";import o from"@uppy/xhr-upload";import n from"lodash.foreach";import"nanoid";var e=function(){return e=Object.assign||function(r){for(var o,n=1,e=arguments.length;n<e;n++)for(var t in o=arguments[n])Object.prototype.hasOwnProperty.call(o,t)&&(r[t]=o[t]);return r},e.apply(this,arguments)};function t(r,o){var e=function(r,o){var n="function"==typeof Symbol&&r[Symbol.iterator];if(!n)return r;var e,t,i=n.call(r),a=[];try{for(;(void 0===o||o-- >0)&&!(e=i.next()).done;)a.push(e.value)}catch(r){t={error:r}}finally{try{e&&!e.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}return a}(r.split("#"),2),t=e[0],i=e[1],a=[];n(o,function(r,o){a.push("".concat(o,"=").concat(r))});var c=a.join("&");return t=t.indexOf("?")>0?"".concat(t,"&").concat(c):"".concat(t,"?").concat(c),i?"".concat(t,"#").concat(i):t}function i(r){return r||{name:""}}function a(r){return Object.keys(r).reduce(function(o,n){return o[n]=String(r[n]),o},{})}function c(){if("undefined"!=typeof AbortSignal){var r=AbortSignal;"function"!=typeof r.any&&(r.any=function(r){var o,n,e=new AbortController,t=function(o){r.forEach(function(r){return r.removeEventListener("abort",t)});var n=o.target.reason;e.abort(n)};try{for(var i=function(r){var o="function"==typeof Symbol&&Symbol.iterator,n=o&&r[o],e=0;if(n)return n.call(r);if(r&&"number"==typeof r.length)return{next:function(){return r&&e>=r.length&&(r=void 0),{value:r&&r[e++],done:!r}}};throw new TypeError(o?"Object is not iterable.":"Symbol.iterator is not defined.")}(r),a=i.next();!a.done;a=i.next()){var c=a.value;if(c.aborted){var u=c.reason;return e.abort(u),e.signal}c.addEventListener("abort",t,{once:!0})}}catch(r){o={error:r}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return e.signal})}}function u(n){var u=n.server,f=void 0===u?"":u,l=n.fieldName,d=void 0===l?"":l,s=n.maxFileSize,p=void 0===s?10485760:s,v=n.maxNumberOfFiles,y=void 0===v?100:v,m=n.meta,h=void 0===m?{}:m,b=n.metaWithUrl,g=void 0!==b&&b,w=n.headers,E=void 0===w?{}:w,S=n.withCredentials,x=void 0!==S&&S,O=n.timeout,C=void 0===O?1e4:O,N=n.onBeforeUpload,j=void 0===N?function(r){return r}:N,A=n.onSuccess,F=void 0===A?function(r,o){}:A,U=n.onError,z=void 0===U?function(r,o,n){console.error("".concat(r.name," upload error"),o,n)}:U,B=n.onProgress,L=void 0===B?function(r){}:B;if(!f)throw new Error("Cannot get upload server address\n没有配置上传地址");if(!d)throw new Error("Cannot get fieldName\n没有配置 fieldName");var P=f;g&&(P=t(P,h)),c();var k=function(r){if(r)return"function"==typeof r?function(o){return a(r(o))}:a(r)}(E),D=new r(e({onBeforeUpload:function(r){return j(r)},restrictions:{maxFileSize:p,maxNumberOfFiles:y},meta:h},n.uppyConfig)).use(o,e({endpoint:P,headers:k,formData:!0,fieldName:d,bundle:!1,withCredentials:x,timeout:C},n.xhrConfig));return D.on("upload-success",function(r,o){var n=(null!=o?o:{}).body,e=void 0===n?{}:n,t=i(r);try{F(t,e)}catch(r){console.error("wangEditor upload file - onSuccess error",r)}}),D.on("progress",function(r){r<1||L(r)}),D.on("upload-error",function(r,o,n){var e=i(r);try{z(e,o,n)}catch(r){console.error("wangEditor upload file - onError error",r)}}),D.on("restriction-failed",function(r,o){var n=i(r);try{z(n,o,void 0)}catch(r){console.error("wangEditor upload file - onError error",r)}}),D}function f(r,o){return r.uploadAdapter?r.uploadAdapter({config:r,editor:o}):u(r)}"function"==typeof SuppressedError&&SuppressedError;export{f as createUploader,u as createUppyUploader};
|
|
13
2
|
//# sourceMappingURL=upload.mjs.map
|