@osmandvc/react-upload-control
Version:
A completely free and open-source file uploader library designed for modern react applications. This package focuses on delivering a feature-rich experience while prioritizing an exceptional developer experience (DX). Whether you're handling simple upload
2 lines (1 loc) • 30.1 kB
JavaScript
import{jsx as t,jsxs as r,Fragment as e}from"react/jsx-runtime";import n,{useState as o,useCallback as i,createContext as a,useEffect as u}from"react";function c(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=Array(r);e<r;e++)n[e]=t[e];return n}function s(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=d(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,u=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return a=t.done,t},e:function(t){u=!0,i=t},f:function(){try{a||null==e.return||e.return()}finally{if(u)throw i}}}}function l(){l=function(){return r};var t,r={},e=Object.prototype,n=e.hasOwnProperty,o=Object.defineProperty||function(t,r,e){t[r]=e.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function s(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{s({},"")}catch(t){s=function(t,r,e){return t[r]=e}}function f(t,r,e,n){var i=r&&r.prototype instanceof g?r:g,a=Object.create(i.prototype),u=new j(n||[]);return o(a,"_invoke",{value:F(t,e,u)}),a}function p(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=f;var h="suspendedStart",d="suspendedYield",v="executing",m="completed",y={};function g(){}function b(){}function E(){}var w={};s(w,a,(function(){return this}));var x=Object.getPrototypeOf,I=x&&x(x(D([])));I&&I!==e&&n.call(I,a)&&(w=I);var L=E.prototype=g.prototype=Object.create(w);function S(t){["next","throw","return"].forEach((function(r){s(t,r,(function(t){return this._invoke(r,t)}))}))}function O(t,r){function e(o,i,a,u){var c=p(t[o],t,i);if("throw"!==c.type){var s=c.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?r.resolve(l.__await).then((function(t){e("next",t,a,u)}),(function(t){e("throw",t,a,u)})):r.resolve(l).then((function(t){s.value=t,a(s)}),(function(t){return e("throw",t,a,u)}))}u(c.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new r((function(r,o){e(t,n,r,o)}))}return i=i?i.then(o,o):o()}})}function F(r,e,n){var o=h;return function(i,a){if(o===v)throw Error("Generator is already running");if(o===m){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var c=A(u,n);if(c){if(c===y)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===h)throw o=m,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var s=p(r,e,n);if("normal"===s.type){if(o=n.done?m:d,s.arg===y)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=m,n.method="throw",n.arg=s.arg)}}}function A(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,A(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),y;var i=p(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,y;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,y):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,y)}function N(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function _(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function j(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(N,this),this.reset(!0)}function D(r){if(r||""===r){var e=r[a];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var o=-1,i=function e(){for(;++o<r.length;)if(n.call(r,o))return e.value=r[o],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" is not iterable")}return b.prototype=E,o(L,"constructor",{value:E,configurable:!0}),o(E,"constructor",{value:b,configurable:!0}),b.displayName=s(E,c,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===b||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,E):(t.__proto__=E,s(t,c,"GeneratorFunction")),t.prototype=Object.create(L),t},r.awrap=function(t){return{__await:t}},S(O.prototype),s(O.prototype,u,(function(){return this})),r.AsyncIterator=O,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new O(f(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},S(L),s(L,c,"Generator"),s(L,a,(function(){return this})),s(L,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=D,j.prototype={constructor:j,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(_),!r)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function o(n,o){return u.type="throw",u.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var o=this.tryEntries[e];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),y},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),_(e),y}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;_(e)}return o}}throw Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:D(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),y}},r}function f(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){var e=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=e){var n,o,i,a,u=[],c=!0,s=!1;try{if(i=(e=e.call(t)).next,0===r){if(Object(e)!==e)return;c=!1}else for(;!(c=(n=i.call(e)).done)&&(u.push(n.value),u.length!==r);c=!0);}catch(t){s=!0,o=t}finally{try{if(!c&&null!=e.return&&(a=e.return(),Object(a)!==a))return}finally{if(s)throw o}}return u}}(t,r)||d(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function p(t){return function(t){if(Array.isArray(t))return c(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||d(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function h(t){return h="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},h(t)}function d(t,r){if(t){if("string"==typeof t)return c(t,r);var e={}.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?c(t,r):void 0}}function v(t,r,e,n){return new(e||(e=Promise))((function(o,i){function a(t){try{c(n.next(t))}catch(t){i(t)}}function u(t){try{c(n.throw(t))}catch(t){i(t)}}function c(t){var r;t.done?o(t.value):(r=t.value,r instanceof e?r:new e((function(t){t(r)}))).then(a,u)}c((n=n.apply(t,r||[])).next())}))}function m(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=Array(r);e<r;e++)n[e]=t[e];return n}function y(){y=function(){return r};var t,r={},e=Object.prototype,n=e.hasOwnProperty,o=Object.defineProperty||function(t,r,e){t[r]=e.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function s(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{s({},"")}catch(t){s=function(t,r,e){return t[r]=e}}function l(t,r,e,n){var i=r&&r.prototype instanceof b?r:b,a=Object.create(i.prototype),u=new D(n||[]);return o(a,"_invoke",{value:A(t,e,u)}),a}function f(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=l;var p="suspendedStart",d="suspendedYield",v="executing",m="completed",g={};function b(){}function E(){}function w(){}var x={};s(x,a,(function(){return this}));var I=Object.getPrototypeOf,L=I&&I(I(k([])));L&&L!==e&&n.call(L,a)&&(x=L);var S=w.prototype=b.prototype=Object.create(x);function O(t){["next","throw","return"].forEach((function(r){s(t,r,(function(t){return this._invoke(r,t)}))}))}function F(t,r){function e(o,i,a,u){var c=f(t[o],t,i);if("throw"!==c.type){var s=c.arg,l=s.value;return l&&"object"==h(l)&&n.call(l,"__await")?r.resolve(l.__await).then((function(t){e("next",t,a,u)}),(function(t){e("throw",t,a,u)})):r.resolve(l).then((function(t){s.value=t,a(s)}),(function(t){return e("throw",t,a,u)}))}u(c.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new r((function(r,o){e(t,n,r,o)}))}return i=i?i.then(o,o):o()}})}function A(r,e,n){var o=p;return function(i,a){if(o===v)throw Error("Generator is already running");if(o===m){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var c=N(u,n);if(c){if(c===g)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=m,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var s=f(r,e,n);if("normal"===s.type){if(o=n.done?m:d,s.arg===g)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=m,n.method="throw",n.arg=s.arg)}}}function N(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,N(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),g;var i=f(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,g;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,g):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,g)}function _(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function j(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function D(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function k(r){if(r||""===r){var e=r[a];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var o=-1,i=function e(){for(;++o<r.length;)if(n.call(r,o))return e.value=r[o],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(h(r)+" is not iterable")}return E.prototype=w,o(S,"constructor",{value:w,configurable:!0}),o(w,"constructor",{value:E,configurable:!0}),E.displayName=s(w,c,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===E||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,s(t,c,"GeneratorFunction")),t.prototype=Object.create(S),t},r.awrap=function(t){return{__await:t}},O(F.prototype),s(F.prototype,u,(function(){return this})),r.AsyncIterator=F,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new F(l(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},O(S),s(S,c,"Generator"),s(S,a,(function(){return this})),s(S,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=k,D.prototype={constructor:D,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(j),!r)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function o(n,o){return u.type="throw",u.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var o=this.tryEntries[e];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,g):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),g},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),j(e),g}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;j(e)}return o}}throw Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:k(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),g}},r}function g(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){var e=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=e){var n,o,i,a,u=[],c=!0,s=!1;try{if(i=(e=e.call(t)).next,0===r){if(Object(e)!==e)return;c=!1}else for(;!(c=(n=i.call(e)).done)&&(u.push(n.value),u.length!==r);c=!0);}catch(t){s=!0,o=t}finally{try{if(!c&&null!=e.return&&(a=e.return(),Object(a)!==a))return}finally{if(s)throw o}}return u}}(t,r)||function(t,r){if(t){if("string"==typeof t)return m(t,r);var e={}.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?m(t,r):void 0}}(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function b(t){return b="function"==typeof Symbol&&"symbol"==h(Symbol.iterator)?function(t){return h(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":h(t)},b(t)}var E,w;"function"==typeof SuppressedError&&SuppressedError,(w=E||(E={})).IDLE="IDLE",w.LOADING="LOADING",w.PROCESSING="PROCESSING",w.ERROR="ERROR",w.READY="READY",w.PENDING="PENDING";var x,I,L=E.IDLE;function S(t){return null!=t&&"object"===b(t)&&"error"in t&&null!=t.error&&"object"===b(t.error)&&"text"in t.error&&"string"==typeof t.error.text&&"type"in t.error&&Object.values(x).includes(t.error.type)}function O(t){return function(t,r,e,n){return new(e||(e=Promise))((function(o,i){function a(t){try{c(n.next(t))}catch(t){i(t)}}function u(t){try{c(n.throw(t))}catch(t){i(t)}}function c(t){var r;t.done?o(t.value):(r=t.value,r instanceof e?r:new e((function(t){t(r)}))).then(a,u)}c((n=n.apply(t,r||[])).next())}))}(this,void 0,void 0,y().mark((function r(){return y().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",new Promise((function(r,e){if("undefined"!=typeof FileReader){var n=new FileReader;n.onloadend=function(){n.result?r(n.result):e(new Error("Failed to convert blob to base64"))},n.onerror=function(t){return e(t)},n.readAsDataURL(t)}else e(new Error("FileReader API is not supported in this environment"))})));case 1:case"end":return r.stop()}}),r)})))}"function"==typeof SuppressedError&&SuppressedError,function(t){t.INVALID_FILE="INVALID_FILE",t.MAXSIZE="OVER_SIZE_LIMIT",t.MULTIPLE_NOT_ALLOWED="MULTIPLE_NOT_ALLOWED",t.MAX_FILES_NUMBER="MAX_FILES_NUMBER"}(x||(x={})),function(t){t.IDLE="IDLE",t.FINISHED="FINISHED",t.FAILED="FAILED",t.UPLOADING="UPLOADING",t.REMOVING="REMOVING"}(I||(I={}));var F,A,N,_,j={".pdf":"application/pdf",".jpg":"image/jpeg",".jpeg":"image/jpeg",".png":"image/png",".doc":"application/msword",".dot":"application/msword",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".dotx":"application/vnd.openxmlformats-officedocument.wordprocessingml.template",".docm":"application/vnd.ms-word.document.macroEnabled.12",".dotm":"application/vnd.ms-word.template.macroEnabled.12",".xls":"application/vnd.ms-excel",".xlt":"application/vnd.ms-excel",".xla":"application/vnd.ms-excel",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",".xltx":"application/vnd.openxmlformats-officedocument.spreadsheetml.template",".xlsm":"application/vnd.ms-excel.sheet.macroEnabled.12",".xltm":"application/vnd.ms-excel.template.macroEnabled.12",".xlam":"application/vnd.ms-excel.addin.macroEnabled.12",".xlsb":"application/vnd.ms-excel.sheet.binary.macroEnabled.12",".ppt":"application/vnd.ms-powerpoint",".pot":"application/vnd.ms-powerpoint",".pps":"application/vnd.ms-powerpoint",".ppa":"application/vnd.ms-powerpoint",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation",".potx":"application/vnd.openxmlformats-officedocument.presentationml.template",".ppsx":"application/vnd.openxmlformats-officedocument.presentationml.slideshow",".ppam":"application/vnd.ms-powerpoint.addin.macroEnabled.12",".pptm":"application/vnd.ms-powerpoint.presentation.macroEnabled.12",".potm":"application/vnd.ms-powerpoint.template.macroEnabled.12",".ppsm":"application/vnd.ms-powerpoint.slideshow.macroEnabled.12"},D=Object.keys(j),k=(F=j,A={},Object.keys(F).forEach((function(t){var r=F[t];A.hasOwnProperty(r)?A[r].push(t):A[r]=[t]})),A),P=Object.keys(k);function R(){return"".concat(Date.now(),"-").concat(Math.random().toString(36).substr(2,9))}D.concat(P).join(","),function(t){t.INVALID_FILE="INVALID_FILE",t.MAXSIZE="OVER_SIZE_LIMIT",t.MULTIPLE_NOT_ALLOWED="MULTIPLE_NOT_ALLOWED",t.MAX_FILES_NUMBER="MAX_FILES_NUMBER"}(N||(N={})),function(t){t.IDLE="IDLE",t.FINISHED="FINISHED",t.FAILED="FAILED",t.UPLOADING="UPLOADING",t.REMOVING="REMOVING"}(_||(_={}));var M=a(void 0),G={mimeTypes:P.filter((function(t){return t.startsWith("image")})),multiple:!0,maxFileSizeMb:10,resetOnFinish:!1,disableSorting:!1},T=function(r){var e=r.children,n=r.config,a=void 0===n?G:n,u=r.handlers,c=r.initFiles,h=u.onUpload,d=u.onFinish,m=u.onAddFileError,y=u.onDelete,b=u.preProcessFiles,w=a.mimeTypes,x=void 0===w?G.mimeTypes:w,I=a.multiple,F=void 0===I?G.multiple:I,A=a.maxFileSizeMb,j=void 0===A?G.maxFileSizeMb:A,D=a.maxFiles,k=a.resetOnFinish,P=void 0===k?G.resetOnFinish:k,T=a.disableSorting,U=void 0===T?G.disableSorting:T,C=f(o(null!=c?c:[]),2),V=C[0],H=C[1],z=function(t,r){var e=g(o(null!=t?t:L),2),n=e[0],a=e[1],u=g(o(r),2),c=u[0],s=u[1],l=g(o(void 0),2),f=l[0],p=l[1],h=i((function(t){a(t||L),p(void 0),s(void 0)}),[]),d=i((function(t,r,e){a(t),r&&p(r),e&&s(e)}),[]);return{smStatus:n,smStatusIs:function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return r.some((function(t){return t===n}))},smStatusIsnt:function(){for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];return r.every((function(t){return t!==n}))},smIsError:!!f,smError:f,smErrorString:"string"==typeof f?f:(null==f?void 0:f.message)?f.message:JSON.stringify(f),smValue:c,smGetStatus:function(){return n},smSetStatus:d,smResetStatus:h,status:E}}("IDLE"),X=z.smStatus,B=z.smSetStatus,Y=z.smStatusIs,W=z.smStatusIsnt,Z=function(t){return v(void 0,void 0,void 0,l().mark((function r(){var e,n;return l().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(!m){r.next=4;break}m(t),r.next=15;break;case 4:return r.prev=4,r.next=7,import("sonner");case 7:e=r.sent,n=e.toast,S(t)?n.error(t.error.text):n.error("An unknown error occurred: ".concat(String(t))),r.next=15;break;case 12:r.prev=12,r.t0=r.catch(4),console.error("sonner is not installed. Please install sonner or provide an onAddFileError handler.",t);case 15:case"end":return r.stop()}}),r,null,[[4,12]])})))};function $(t){return!(!t.length||Y("PROCESSING"))&&t.every((function(t){return t.uploadStatus.stage===_.FINISHED}))}function J(t){var r=[],e=[],n=null!=m?m:Z;return!F&&t.length>1?(e.push({error:{type:N.MULTIPLE_NOT_ALLOWED,text:"Only one file is allowed"}}),n(e[0]),{validFiles:r,errors:e}):D&&(t.length>D||t.length+V.length>D)?(e.push({error:{text:"Maximum number of files exceeded. Maximum allowed is ".concat(D),type:N.MAX_FILES_NUMBER}}),n(e[0]),{validFiles:r,errors:e}):(t.forEach((function(t){if(x.includes(t.type))if(t.size*Math.pow(10,-6)>j){var o={error:{text:"File is too large. Maximum file size is ".concat(j,"MB"),type:N.MAXSIZE}};e.push(o),n(o)}else r.push(t);else{var i={error:{text:"Invalid file type. Supported types are: ".concat(x.map((function(t){return t.split("/")[1]})).join(", ")),type:N.INVALID_FILE}};e.push(i),n(i)}})),{validFiles:r,errors:e})}function q(t,r,e){return v(this,void 0,void 0,l().mark((function n(){var o,i,a,u,c;return l().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(i=p(e),void 0===(a=null==r?void 0:r[t.type])&&(a=null!==(o=null==r?void 0:r.other)&&void 0!==o?o:null),a){n.next=5;break}return n.abrupt("return",e);case 5:return n.next=7,a([t]);case 7:if(u=n.sent){n.next=11;break}return console.error("Preprocessing failed for file ".concat(t.name," of type ").concat(t.type,".")),n.abrupt("return",e);case 11:if(e&&t.id&&u){n.next=13;break}return n.abrupt("return");case 13:return c=i.findIndex((function(r){return r.id===t.id})),i.splice.apply(i,[c,1].concat(p(u.map((function(t){return Object.assign(Object.assign({},t),{id:R()})}))))),n.abrupt("return",i);case 16:case"end":return n.stop()}}),n)})))}function K(t){return v(this,void 0,void 0,l().mark((function r(){var e,n,o,i,a,u,c;return l().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:e=p(t),n=s(t),r.prev=2,n.s();case 4:if((o=n.n()).done){r.next=14;break}if(i=o.value,b){r.next=8;break}return r.abrupt("return");case 8:return r.next=10,q(i,b,e);case 10:a=r.sent,e=null!=a?a:e;case 12:r.next=4;break;case 14:r.next=19;break;case 16:r.prev=16,r.t0=r.catch(2),n.e(r.t0);case 19:return r.prev=19,n.f(),r.finish(19);case 22:if(u=J(e),c=u.validFiles,!u.errors.length||c.length){r.next=25;break}return r.abrupt("return");case 25:return r.abrupt("return",c);case 26:case"end":return r.stop()}}),r,null,[[2,16,19,22]])})))}function Q(t){return v(this,void 0,void 0,l().mark((function r(){var e,n,o,i,a,u=this;return l().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(e=J(t),n=e.validFiles,!e.errors.length||n.length){r.next=3;break}return r.abrupt("return");case 3:return o=V.reduce((function(t,r){return Math.max(t,r.order)}),0)+1,r.next=6,Promise.all(n.map((function(t){return v(u,void 0,void 0,l().mark((function r(){var e,n;return l().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(t instanceof File){r.next=2;break}throw new Error("Invalid file type");case 2:return r.next=4,O(t);case 4:return e=r.sent,n={id:R(),file:t,name:t.name,size:t.size,type:t.type,base64Uri:e,previewImg:{imgBase64Uri:t.type.includes("image")?e:""}},r.abrupt("return",n);case 7:case"end":return r.stop()}}),r)})))})));case 6:if(i=r.sent,!b){r.next=13;break}return r.next=10,K(i);case 10:r.t0=r.sent,r.next=14;break;case 13:r.t0=i;case 14:if(a=r.t0){r.next=17;break}return r.abrupt("return");case 17:return r.abrupt("return",a.map((function(t,r){return Object.assign(Object.assign({},t),{order:o+r,uploadStatus:{stage:_.IDLE,progress:0}})})).sort((function(t,r){return t.order-r.order})));case 18:case"end":return r.stop()}}),r)})))}function tt(t){return V.find((function(r){return r.id===t}))}function rt(t){return t.map((function(t,r){return Object.assign(Object.assign({},t),{order:r+1})}))}function et(t,r){H((function(e){return e.map((function(e){return e.id===t?Object.assign(Object.assign({},e),r):e}))}))}function nt(t){return V.filter((function(r){return r.id!==t}))}function ot(t,r,e){var n,o=null===(n=tt(t))||void 0===n?void 0:n.uploadStatus.stage;r>=0&&r<=100&&(e?o=_.FAILED:100===r?o=_.FINISHED:o!==_.FINISHED&&(o=_.UPLOADING),et(t,{uploadStatus:{progress:r,error:e,stage:o}}))}function it(t){var r=p(V),e=!0;return t.forEach((function(t){var n=t.fileId,o=t.success,i=t.error,a=t.metadata,u=r.find((function(t){return t.id===n}));u&&(o&&(u.uploadStatus={progress:100,stage:_.FINISHED,error:void 0}),o||(u.uploadStatus={progress:100,stage:_.FAILED,error:i},e=!1),u.metadata=null!=a?a:{})})),[e,r]}function at(t){d&&d(t),P?ut():B("FINISHED")}function ut(){B("IDLE"),H([])}return t(M.Provider,{value:{files:V,smStatus:X,updateFile:et,uploadAllFiles:function(){return v(this,void 0,void 0,l().mark((function t(){var r,e,n,o,i;return l().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(h){t.next=2;break}throw new Error("Provider has no onUpload function defined.");case 2:return Y("ERROR")?B("RETRY"):B("PROCESSING"),t.prev=3,t.next=6,h(V.filter((function(t){return t.uploadStatus.stage!==_.FINISHED})),ot);case 6:r=t.sent,e=it(r),n=f(e,2),o=n[0],i=n[1],o?(B("IDLE"),at(i)):B("ERROR"),t.next=14;break;case 11:t.prev=11,t.t0=t.catch(3),console.error(t.t0);case 14:case"end":return t.stop()}}),t,null,[[3,11]])})))},deleteFile:function(t){return v(this,void 0,void 0,l().mark((function r(){var e,n;return l().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(e=tt(t)){r.next=3;break}throw new Error("File with ID ".concat(t," not found."));case 3:e.uploadStatus.stage!==_.FINISHED&&(n=nt(e.id),y&&y([e]),$(n)&&(B("SUCCESS"),at(rt(n))),n.length||B("IDLE"),H(rt(n)));case 4:case"end":return r.stop()}}),r)})))},deleteAllFiles:function(){return v(this,void 0,void 0,l().mark((function t(){var r;return l().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:try{B("PROCESSING"),(r=V.filter((function(t){return t.uploadStatus.stage===_.FINISHED}))).length&&y&&y(r),H([]),B("IDLE")}catch(t){console.error(t)}case 1:case"end":return t.stop()}}),t)})))},addFiles:function(t){return v(this,void 0,void 0,l().mark((function r(){var e,n;return l().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return e=null!=m?m:Z,r.prev=1,B("PROCESSING"),r.next=5,Q(t);case 5:(n=r.sent)&&H((function(t){return[].concat(p(t),p(n))})),r.next=12;break;case 9:r.prev=9,r.t0=r.catch(1),e(r.t0);case 12:return r.prev=12,B("IDLE"),r.finish(12);case 15:case"end":return r.stop()}}),r,null,[[1,9,12,15]])})))},removeFile:nt,getFile:tt,smStatusIs:Y,smStatusIsnt:W,setFiles:H,resetControl:ut,getValidationInfo:function(){return{types:x.map((function(t){return t.split("/")[1]})),maxFileSizeMb:j}},disableSorting:U,moveFile:function(t,r){U||H((function(e){var n=e.findIndex((function(r){return r.id===t}));if(-1===n)return e;var o=n+r;if(o<0||o>=e.length)return e;var i=p(e),a=f(i.splice(n,1),1)[0];return i.splice(o,0,a),rt(i)}))}},children:e})};function U(){var t=n.useContext(M);if(void 0===t)throw new Error("useUploadFilesProvider must be used within a UploadFilesContext");return t}var C=function(n){var i=n.children,a=n.handlers,c=f(o(null),2),s=c[0],l=c[1];return u((function(){(null==a?void 0:a.onAddFileError)||import("sonner").then((function(t){l((function(){return t.Toaster}))})).catch((function(){console.error("sonner is not installed. Please install sonner or provide an onAddFileError handler.")}))}),[null==a?void 0:a.onAddFileError]),r(e,{children:[!(null==a?void 0:a.onAddFileError)&&s&&t(s,{expand:!0,visibleToasts:5,toastOptions:{duration:3500}}),t(T,Object.assign({},n,{children:i}))]})};export{N as FileDropErrorType,_ as UploadedFileItemStage,C as UploadedFilesProvider,U as useUploadFilesProvider};