smart-dropzone-react
Version:
🚀 A production-ready React dropzone component with smart defaults, drag & drop reordering, chunked uploads, resume functionality, and comprehensive provider support (Cloudinary, AWS S3, Supabase)
2 lines • 12.1 kB
JavaScript
import {a}from'./chunk-5XGN7UAV.js';var i=class i{constructor(e){a(this,"config");a(this,"currentLocale");a(this,"fallbackLocale");a(this,"translations",new Map);a(this,"loadedLocales",new Set);this.config=e,this.currentLocale=e.defaultLocale,this.fallbackLocale=e.fallbackLocale,this.loadLocale(e.defaultLocale);}static getInstance(e){if(!i.instance){let r={defaultLocale:"en-US",fallbackLocale:"en-US",supportedLocales:["en-US","es","es-ES","fr-FR","de-DE","ja-JP"],loadLocaleData:async a=>{let t={es:"es-ES",fr:"fr-FR",de:"de-DE",ja:"ja-JP"}[a]||a;return i.DEFAULT_TRANSLATIONS[t]||i.DEFAULT_TRANSLATIONS["en-US"]}};i.instance=new i(e||r);}return i.instance}async setLocale(e){if(!this.config.supportedLocales.includes(e))return false;if(e===this.currentLocale)return true;try{return await this.loadLocale(e),this.currentLocale=e,this.config.onLocaleChange?.(e),!0}catch{return false}}getCurrentLocale(){return this.currentLocale}getSupportedLocales(){return [...this.config.supportedLocales]}async loadLocale(e){if(!this.loadedLocales.has(e))try{let r;if(this.config.loadLocaleData?r=await this.config.loadLocaleData(e):r=i.DEFAULT_TRANSLATIONS[e]||i.DEFAULT_TRANSLATIONS[this.fallbackLocale],r)this.translations.set(e,r),this.loadedLocales.add(e);else throw new Error(`No translation data found for locale ${e}`)}catch{e!==this.fallbackLocale&&await this.loadLocale(this.fallbackLocale);}}translate(e,r){let a=e.split("."),o=this.translations.get(this.currentLocale);for(let t of a)if(o&&typeof o=="object"&&t in o)o=o[t];else {o=null;break}if(!o&&this.currentLocale!==this.fallbackLocale){o=this.translations.get(this.fallbackLocale);for(let t of a)if(o&&typeof o=="object"&&t in o)o=o[t];else {o=null;break}}return !o||typeof o!="string"?e:r?o.replace(/\{(\w+)\}/g,(t,n)=>r[n]!==void 0?String(r[n]):t):o}t(e,r){return this.translate(e,r)}formatFileSize(e,r){let a=r||this.currentLocale,o=["B","KB","MB","GB","TB"],t=e,n=0;for(;t>=1024&&n<o.length-1;)t/=1024,n++;return new Intl.NumberFormat(a,{maximumFractionDigits:2,minimumFractionDigits:0}).format(t)+" "+o[n]}translatePlural(e,r,a){let o=r===1?`${e}.singular`:`${e}.plural`;return this.translate(o,{...a,count:r})}formatNumber(e,r){let a=r||this.currentLocale;return new Intl.NumberFormat(a).format(e)}formatDate(e,r){let a=r||this.currentLocale;return new Intl.DateTimeFormat(a).format(e)}formatCurrency(e,r,a){let o=a||this.currentLocale;return new Intl.NumberFormat(o,{style:"currency",currency:r}).format(e)}getLocaleConfig(e){let r=["ar","he","fa","ur"].includes(e.split("-")[0]);return {code:e,name:new Intl.DisplayNames([e],{type:"language"}).of(e)||e,direction:r?"rtl":"ltr",dateFormat:"MM/DD/YYYY",numberFormat:{decimal:".",thousands:",",currency:"$"}}}isRTL(e){let r=e||this.currentLocale;return this.getLocaleConfig(r)?.direction==="rtl"}tPlural(e,r,a){return this.translatePlural(e,r,a)}getAllTranslations(e){let r={};for(let a of this.loadedLocales){let o=this.translate(e);o!==e&&(r[a]=o);}return r}hasTranslation(e){return this.translate(e)!==e}getTranslationKeys(e){let r=this.translations.get(e);if(!r)return [];let a=[];return this.extractKeys(r,"",a),a}extractKeys(e,r,a){for(let[o,t]of Object.entries(e)){let n=r?`${r}.${o}`:o;typeof t=="string"?a.push(n):typeof t=="object"&&t!==null&&this.extractKeys(t,n,a);}}};a(i,"instance"),a(i,"DEFAULT_TRANSLATIONS",{"en-US":{common:{upload:"Upload",cancel:"Cancel",retry:"Retry",remove:"Remove",clear:"Clear All",close:"Close",save:"Save",edit:"Edit",delete:"Delete",confirm:"Confirm",loading:"Loading...",error:"Error",success:"Success",warning:"Warning",info:"Information"},dropzone:{title:"Drag & Drop Files Here",subtitle:"or click to browse",description:"Drop your files here to upload them",maxFiles:"Maximum {count} files allowed",maxFileSize:"Maximum file size: {size}",allowedTypes:"Allowed file types: {types}",dragActive:"Drop files here to upload",dragInactive:"Drag files here or click to select",fileTooLarge:'File "{name}" is too large',fileTypeNotAllowed:'File type "{type}" is not allowed',tooManyFiles:"Too many files selected",uploadInProgress:"Upload in progress...",uploadComplete:"Upload complete!",uploadFailed:"Upload failed",processing:"Processing...",ready:"Ready to upload",dragAndDrop:"Drag and drop files here to upload"},fileItem:{uploading:"Uploading...",uploaded:"Uploaded",failed:"Failed",cancelled:"Cancelled",pending:"Pending",retryUpload:"Retry upload",cancelUpload:"Cancel upload",removeFile:"Remove file",viewFile:"View file",downloadFile:"Download file",fileSize:"File size: {size}",fileType:"File type: {type}",uploadProgress:"Upload progress: {progress}%",uploadSpeed:"Upload speed: {speed}",timeRemaining:"Time remaining: {time}",errorMessage:"Error: {message}"},validation:{required:"This field is required",invalidFormat:"Invalid format",fileTooLarge:"File is too large",fileTypeNotAllowed:"File type not allowed",tooManyFiles:"Too many files",invalidFile:"Invalid file",corruptedFile:"File appears to be corrupted",virusDetected:"Virus detected in file",passwordProtected:"File is password protected",unsupportedFormat:"Unsupported file format"},errors:{networkError:"Network connection error. Please check your internet connection.",serverError:"Server error. Please try again later.",timeoutError:"Request timed out. Please try again.",quotaExceeded:"Storage quota exceeded. Please remove some files.",unauthorized:"You are not authorized to perform this action.",forbidden:"Access denied. You do not have permission.",notFound:"Resource not found.",conflict:"Resource conflict. Please resolve and try again.",tooManyRequests:"Too many requests. Please wait and try again.",internalError:"Internal server error. Please contact support.",unknownError:"An unknown error occurred. Please try again."},accessibility:{dropzoneLabel:"File upload area",dropzoneDescription:"Drag and drop files here or click to browse. Supported formats: images, PDFs, and text files.",fileItemLabel:"File item",uploadButtonLabel:"Upload button",cancelButtonLabel:"Cancel button",retryButtonLabel:"Retry button",removeButtonLabel:"Remove button",progressBarLabel:"Upload progress",statusLabel:"File status",errorMessageLabel:"Error message",successMessageLabel:"Success message",loadingMessageLabel:"Loading message"},voice:{commands:{upload:"Upload files",cancel:"Cancel upload",clear:"Clear all",retry:"Retry failed",select:"Select files",help:"Voice help"},feedback:{listening:"Listening for voice commands...",commandRecognized:"Command recognized: {command}",commandExecuted:"Command executed: {action}",commandNotFound:"Command not found: {command}",listeningStopped:"Voice recognition stopped",error:"Voice recognition error: {error}"}}},"es-ES":{common:{upload:"Subir",cancel:"Cancelar",retry:"Reintentar",remove:"Eliminar",clear:"Limpiar Todo",close:"Cerrar",save:"Guardar",edit:"Editar",delete:"Eliminar",confirm:"Confirmar",loading:"Cargando...",error:"Error",success:"\xC9xito",warning:"Advertencia",info:"Informaci\xF3n"},dropzone:{title:"Arrastra y Suelta Archivos Aqu\xED",subtitle:"o haz clic para explorar",description:"Suelta tus archivos aqu\xED para subirlos",maxFiles:"M\xE1ximo {count} archivos permitidos",maxFileSize:"Tama\xF1o m\xE1ximo de archivo: {size}",allowedTypes:"Tipos de archivo permitidos: {types}",dragActive:"Suelta los archivos aqu\xED para subirlos",dragInactive:"Arrastra archivos aqu\xED o haz clic para seleccionar",fileTooLarge:'El archivo "{name}" es demasiado grande',fileTypeNotAllowed:'El tipo de archivo "{type}" no est\xE1 permitido',tooManyFiles:"Demasiados archivos seleccionados",uploadInProgress:"Subida en progreso...",uploadComplete:"\xA1Subida completada!",uploadFailed:"Subida fallida",processing:"Procesando...",ready:"Listo para subir",dragAndDrop:"Arrastra y suelta archivos aqu\xED"}},"fr-FR":{common:{upload:"T\xE9l\xE9charger",cancel:"Annuler",retry:"R\xE9essayer",remove:"Supprimer",clear:"Tout effacer",close:"Fermer",save:"Enregistrer",edit:"Modifier",delete:"Supprimer",confirm:"Confirmer",loading:"Chargement...",error:"Erreur",success:"Succ\xE8s",warning:"Avertissement",info:"Information"},dropzone:{title:"Glissez et D\xE9posez les Fichiers Ici",subtitle:"ou cliquez pour parcourir",description:"D\xE9posez vos fichiers ici pour les t\xE9l\xE9charger",maxFiles:"Maximum {count} fichiers autoris\xE9s",maxFileSize:"Taille maximale de fichier: {size}",allowedTypes:"Types de fichiers autoris\xE9s: {types}",dragActive:"D\xE9posez les fichiers ici pour les t\xE9l\xE9charger",dragInactive:"Glissez les fichiers ici ou cliquez pour s\xE9lectionner",fileTooLarge:'Le fichier "{name}" est trop volumineux',fileTypeNotAllowed:`Le type de fichier "{type}" n'est pas autoris\xE9`,tooManyFiles:"Trop de fichiers s\xE9lectionn\xE9s",uploadInProgress:"T\xE9l\xE9chargement en cours...",uploadComplete:"T\xE9l\xE9chargement termin\xE9 !",uploadFailed:"T\xE9l\xE9chargement \xE9chou\xE9",processing:"Traitement...",ready:"Pr\xEAt \xE0 t\xE9l\xE9charger"}},"de-DE":{common:{upload:"Hochladen",cancel:"Abbrechen",retry:"Wiederholen",remove:"Entfernen",clear:"Alle l\xF6schen",close:"Schlie\xDFen",save:"Speichern",edit:"Bearbeiten",delete:"L\xF6schen",confirm:"Best\xE4tigen",loading:"Wird geladen...",error:"Fehler",success:"Erfolg",warning:"Warnung",info:"Information"},dropzone:{title:"Dateien Hier Hineinziehen und Ablegen",subtitle:"oder klicken zum Durchsuchen",description:"Legen Sie Ihre Dateien hier ab, um sie hochzuladen",maxFiles:"Maximal {count} Dateien erlaubt",maxFileSize:"Maximale Dateigr\xF6\xDFe: {size}",allowedTypes:"Erlaubte Dateitypen: {types}",dragActive:"Dateien hier ablegen zum Hochladen",dragInactive:"Dateien hier hineinziehen oder klicken zum Ausw\xE4hlen",fileTooLarge:'Datei "{name}" ist zu gro\xDF',fileTypeNotAllowed:'Dateityp "{type}" ist nicht erlaubt',tooManyFiles:"Zu viele Dateien ausgew\xE4hlt",uploadInProgress:"Upload l\xE4uft...",uploadComplete:"Upload abgeschlossen!",uploadFailed:"Upload fehlgeschlagen",processing:"Wird verarbeitet...",ready:"Bereit zum Hochladen"}},"ja-JP":{common:{upload:"\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9",cancel:"\u30AD\u30E3\u30F3\u30BB\u30EB",retry:"\u518D\u8A66\u884C",remove:"\u524A\u9664",clear:"\u3059\u3079\u3066\u30AF\u30EA\u30A2",close:"\u9589\u3058\u308B",save:"\u4FDD\u5B58",edit:"\u7DE8\u96C6",delete:"\u524A\u9664",confirm:"\u78BA\u8A8D",loading:"\u8AAD\u307F\u8FBC\u307F\u4E2D...",error:"\u30A8\u30E9\u30FC",success:"\u6210\u529F",warning:"\u8B66\u544A",info:"\u60C5\u5831"},dropzone:{title:"\u3053\u3053\u306B\u30D5\u30A1\u30A4\u30EB\u3092\u30C9\u30E9\u30C3\u30B0\uFF06\u30C9\u30ED\u30C3\u30D7",subtitle:"\u307E\u305F\u306F\u30AF\u30EA\u30C3\u30AF\u3057\u3066\u53C2\u7167",description:"\u30D5\u30A1\u30A4\u30EB\u3092\u3053\u3053\u306B\u30C9\u30ED\u30C3\u30D7\u3057\u3066\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9",maxFiles:"\u6700\u5927{count}\u30D5\u30A1\u30A4\u30EB\u307E\u3067",maxFileSize:"\u6700\u5927\u30D5\u30A1\u30A4\u30EB\u30B5\u30A4\u30BA: {size}",allowedTypes:"\u8A31\u53EF\u3055\u308C\u305F\u30D5\u30A1\u30A4\u30EB\u30BF\u30A4\u30D7: {types}",dragActive:"\u3053\u3053\u306B\u30D5\u30A1\u30A4\u30EB\u3092\u30C9\u30ED\u30C3\u30D7\u3057\u3066\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9",dragInactive:"\u3053\u3053\u306B\u30D5\u30A1\u30A4\u30EB\u3092\u30C9\u30E9\u30C3\u30B0\u3059\u308B\u304B\u3001\u30AF\u30EA\u30C3\u30AF\u3057\u3066\u9078\u629E",fileTooLarge:"\u30D5\u30A1\u30A4\u30EB\u300C{name}\u300D\u304C\u5927\u304D\u3059\u304E\u307E\u3059",fileTypeNotAllowed:"\u30D5\u30A1\u30A4\u30EB\u30BF\u30A4\u30D7\u300C{type}\u300D\u306F\u8A31\u53EF\u3055\u308C\u3066\u3044\u307E\u305B\u3093",tooManyFiles:"\u30D5\u30A1\u30A4\u30EB\u304C\u591A\u3059\u304E\u307E\u3059",uploadInProgress:"\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u4E2D...",uploadComplete:"\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u5B8C\u4E86\uFF01",uploadFailed:"\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u5931\u6557",processing:"\u51E6\u7406\u4E2D...",ready:"\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u6E96\u5099\u5B8C\u4E86"}}});var s=i;export{s as a};//# sourceMappingURL=chunk-XN7RHD4E.js.map
//# sourceMappingURL=chunk-XN7RHD4E.js.map