Files
Component-Builder/media/uikit-v3/js/Uploader.min.js
Robot 3b502eb09b Release of v5.1.1-alpha5
Refactor initialization flow to accommodate future scalability and integration with all designated areas. Refactor the Creator Builders class. Refactor the FieldString and FieldXML classes.
2025-05-13 13:39:32 +00:00

3 lines
15 KiB
JavaScript

/*! VDM Uikit Uploader v2.0.5 | https://git.vdm.dev/joomla/uikit | (c) 2020 - 2024 Llewellyn van der Merwe | MIT License */
!function(){"use strict";function t(t,e,n){if("function"==typeof t?t===e:t.has(e))return arguments.length<3?e:n;throw new TypeError("Private element is not present on this object")}function e(t,e,n,r,o,a,i){try{var c=t[a](i),u=c.value}catch(t){return void n(t)}c.done?e(u):Promise.resolve(u).then(r,o)}function n(t){return function(){var n=this,r=arguments;return new Promise((function(o,a){var i=t.apply(n,r);function c(t){e(i,o,a,c,u,"next",t)}function u(t){e(i,o,a,c,u,"throw",t)}c(void 0)}))}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(e,n){return e.get(t(e,n))}function a(t,e,n){(function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")})(t,e),e.set(t,n)}function i(e,n,r){return e.set(t(e,n),r),r}function c(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,f(r.key),r)}}function u(t,e,n){return e&&c(t.prototype,e),n&&c(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function s(t,e,n){return(e=f(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function l(){l=function(){return e};var t,e={},n=Object.prototype,r=n.hasOwnProperty,o=Object.defineProperty||function(t,e,n){t[e]=n.value},a="function"==typeof Symbol?Symbol:{},i=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",u=a.toStringTag||"@@toStringTag";function s(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,n){return t[e]=n}}function f(t,e,n,r){var a=e&&e.prototype instanceof g?e:g,i=Object.create(a.prototype),c=new S(r||[]);return o(i,"_invoke",{value:O(t,n,c)}),i}function d(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var h="suspendedStart",p="suspendedYield",v="executing",y="completed",m={};function g(){}function w(){}function b(){}var x={};s(x,i,(function(){return this}));var E=Object.getPrototypeOf,k=E&&E(E(A([])));k&&k!==n&&r.call(k,i)&&(x=k);var L=b.prototype=g.prototype=Object.create(x);function I(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function j(t,e){function n(o,a,i,c){var u=d(t[o],t,a);if("throw"!==u.type){var s=u.arg,l=s.value;return l&&"object"==typeof l&&r.call(l,"__await")?e.resolve(l.__await).then((function(t){n("next",t,i,c)}),(function(t){n("throw",t,i,c)})):e.resolve(l).then((function(t){s.value=t,i(s)}),(function(t){return n("throw",t,i,c)}))}c(u.arg)}var a;o(this,"_invoke",{value:function(t,r){function o(){return new e((function(e,o){n(t,r,e,o)}))}return a=a?a.then(o,o):o()}})}function O(e,n,r){var o=h;return function(a,i){if(o===v)throw Error("Generator is already running");if(o===y){if("throw"===a)throw i;return{value:t,done:!0}}for(r.method=a,r.arg=i;;){var c=r.delegate;if(c){var u=P(c,r);if(u){if(u===m)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===h)throw o=y,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=v;var s=d(e,n,r);if("normal"===s.type){if(o=r.done?y:p,s.arg===m)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(o=y,r.method="throw",r.arg=s.arg)}}}function P(e,n){var r=n.method,o=e.iterator[r];if(o===t)return n.delegate=null,"throw"===r&&e.iterator.return&&(n.method="return",n.arg=t,P(e,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),m;var a=d(o,e.iterator,n.arg);if("throw"===a.type)return n.method="throw",n.arg=a.arg,n.delegate=null,m;var i=a.arg;return i?i.done?(n[e.resultName]=i.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,m):i:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,m)}function _(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function T(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function A(e){if(e||""===e){var n=e[i];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,a=function n(){for(;++o<e.length;)if(r.call(e,o))return n.value=e[o],n.done=!1,n;return n.value=t,n.done=!0,n};return a.next=a}}throw new TypeError(typeof e+" is not iterable")}return w.prototype=b,o(L,"constructor",{value:b,configurable:!0}),o(b,"constructor",{value:w,configurable:!0}),w.displayName=s(b,u,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===w||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,s(t,u,"GeneratorFunction")),t.prototype=Object.create(L),t},e.awrap=function(t){return{__await:t}},I(j.prototype),s(j.prototype,c,(function(){return this})),e.AsyncIterator=j,e.async=function(t,n,r,o,a){void 0===a&&(a=Promise);var i=new j(f(t,n,r,o),a);return e.isGeneratorFunction(n)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},I(L),s(L,u,"Generator"),s(L,i,(function(){return this})),s(L,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),n=[];for(var r in e)n.push(r);return n.reverse(),function t(){for(;n.length;){var r=n.pop();if(r in e)return t.value=r,t.done=!1,t}return t.done=!0,t}},e.values=A,S.prototype={constructor:S,reset:function(e){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(T),!e)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var n=this;function o(r,o){return c.type="throw",c.arg=e,n.next=r,o&&(n.method="next",n.arg=t),!!o}for(var a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],c=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),s=r.call(i,"finallyLoc");if(u&&s){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,m):this.complete(i)},complete:function(t,e){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&&e&&(this.next=e),m},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),T(n),m}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var o=r.arg;T(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={iterator:A(e),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=t),m}},e}function f(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}function d(t){return d="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},d(t)}var h,p=new WeakMap,v=new WeakMap,y=new WeakMap,m=new WeakMap,g=u((function t(e){var c=this;r(this,t),a(this,p,void 0),a(this,v,{}),s(this,"set",(function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;o(v,c)[t]=o(v,c)[t]||{},"object"===d(e)?Object.assign(o(v,c)[t],e):o(v,c)[t][e]=n})),s(this,"get",(function(t){var e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=o(v,c)[t];return a?null===n?a:null!==(e=a[n])&&void 0!==e?e:r:r})),s(this,"init",function(){var t=n(l().mark((function t(e,n){var r,a,i,u,s=arguments;return l().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=s.length>2&&void 0!==s[2]&&s[2],!o(v,c)[e]||r){t.next=4;break}return t.abrupt("return");case 4:return t.prev=4,a=o(m,c).call(c,o(p,c),n),i=!1,t.next=9,o(y,c).call(c,a);case 9:if(u=t.sent,"true"===i&&console.log("Data fetched:",u),null==u||!u.data||"object"!==d(u.data)){t.next=15;break}c.set(e,u.data),t.next=17;break;case 15:if(null==u||!u.error){t.next=17;break}throw new Error(u.error||"An error occurred during the file type request.");case 17:t.next=22;break;case 19:t.prev=19,t.t0=t.catch(4),"true"===DEBUG&&console.error("Error during initialization:",t.t0);case 22:case"end":return t.stop()}}),t,null,[[4,19]])})));return function(e,n){return t.apply(this,arguments)}}()),a(this,y,function(){var t=n(l().mark((function t(e){var n;return l().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,fetch(e,{method:"GET",headers:{"Content-Type":"application/json"}});case 2:if((n=t.sent).ok){t.next=6;break}return t.abrupt("return");case 6:return t.next=8,n.json();case 8:return t.abrupt("return",t.sent);case 9:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()),s(this,"getParams",(function(t){var e={};return Array.isArray(t)&&0!==t.length?(t.forEach((function(t){var n=document.getElementById(t);n&&(e[t]=n.value)})),e):e})),a(this,m,(function(t,e){var n=t.includes("?")?"&":"?";return"".concat(t).concat(n,"guid=").concat(e)})),i(p,this,e)})),w=new WeakMap,b=u((function t(){var e=this;r(this,t),s(this,"set",function(){var t=n(l().mark((function t(n,r,a){var i,c,u;return l().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,i=o(w,e).call(e,n,a),t.next=4,fetch(i,{method:"GET",headers:{"Content-Type":"application/json"}});case 4:if((c=t.sent).ok){t.next=8;break}return t.abrupt("return");case 8:return t.next=10,c.json();case 10:(u=t.sent).data&&""!==u.data.trim()?r.innerHTML=u.data:r.innerHTML="",t.next=18;break;case 14:t.prev=14,t.t0=t.catch(0),r.innerHTML="";case 18:case"end":return t.stop()}}),t,null,[[0,14]])})));return function(e,n,r){return t.apply(this,arguments)}}()),a(this,w,(function(t,e){var n=t.includes("?")?"&":"?",r=new URLSearchParams(e);return"".concat(t).concat(n).concat(r.toString())}))})),x=new WeakMap,E=new WeakMap,k=new WeakMap,L=new WeakMap,I=new WeakMap,j=new WeakMap,O=new WeakMap,P=u((function t(e,c,u){var s=this;r(this,t),a(this,x,void 0),a(this,E,void 0),a(this,k,void 0),a(this,L,{}),a(this,I,(function(t,e){var r=e.bar,a=e.typeId,i=e.endpoint,c=e.successId,u=e.errorId,f=e.allowedFormatId,d=e.fileTypeId,h=e.displayId,p=e.displayEndpoint,v=document.getElementById(a),y={message:"error.message",status:"danger",timeout:7e3},m=function(){var e=n(l().mark((function e(n){return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(n&&n.length>1)){e.next=10;break}return e.prev=1,e.next=4,o(j,s).call(s,t,n,r,i,c,u,f,d,h,p);case 4:e.next=10;break;case 6:e.prev=6,e.t0=e.catch(1),y.message=e.t0.message,o(k,s).notification(y);case 10:case"end":return e.stop()}}),e,null,[[1,6]])})));return function(t){return e.apply(this,arguments)}}();v&&(v.addEventListener("change",n(l().mark((function t(){return l().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,m(v.value);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)})))),m(v.value).catch((function(t){y.message=t.message,o(k,s).notification(y)})))})),a(this,j,function(){var t=n(l().mark((function t(e,n,r,a,i,c,u,f,d,h){var p,v,y,m,g,w,b;return l().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,p=e+n,t.next=4,o(x,s).init(p,n);case 4:v=document.getElementById(r),y=document.getElementById(i),m=document.getElementById(c),g=document.getElementById(d),w=document.getElementById(u),b=document.getElementById(f),o(L,s)[e]&&o(L,s)[e].$destroy(!0),y&&y.setAttribute("hidden","hidden"),m&&m.setAttribute("hidden","hidden"),w&&(w.textContent=o(x,s).get(p,"allow_span","")),b&&(w.textContent=o(x,s).get(p,"file_type_span","file")),h&&g&&o(E,s).set(h,g,o(x,s).getParams(o(x,s).get(p,"display_fields"))),o(L,s)[e]=o(k,s).upload("#".concat(e),{url:o(O,s).call(s,a,n),multiple:!0,allow:function(){return o(x,s).get(p,"allow")||!1},name:function(){return o(x,s).get(p,"name")||"files"},beforeSend:function(t){t.data.params=o(x,s).getParams(o(x,s).get(p,"param_fields"))},beforeAll:function(){},load:function(){},error:function(t){m&&(m.removeAttribute("hidden"),m.textContent="Upload failed.")},complete:function(){y&&(y.removeAttribute("hidden"),y.textContent="Upload completed successfully.")},loadStart:function(t){v&&(v.removeAttribute("hidden"),v.max=t.total,v.value=t.loaded)},progress:function(t){v&&(v.max=t.total,v.value=t.loaded)},loadEnd:function(t){v&&(v.max=t.total,v.value=t.loaded)},completeAll:function(){v&&setTimeout((function(){v.setAttribute("hidden","hidden"),m&&y.setAttribute("hidden","hidden"),m&&m.setAttribute("hidden","hidden")}),1e3),h&&g&&o(E,s).set(h,g,o(x,s).getParams(o(x,s).get(p,"display_fields")))}}),t.next=22;break;case 19:throw t.prev=19,t.t0=t.catch(0),t.t0;case 22:case"end":return t.stop()}}),t,null,[[0,19]])})));return function(e,n,r,o,a,i,c,u,s,l){return t.apply(this,arguments)}}()),a(this,O,(function(t,e){var n=t.includes("?")?"&":"?";return"".concat(t).concat(n,"guid=").concat(e)})),i(x,this,new g(c)),i(E,this,new b),i(k,this,u),Object.keys(e).forEach((function(t){var n=e[t];o(I,s).call(s,t,n)}))})),_=["endpoint","targetClass"];h=window,document.addEventListener("DOMContentLoaded",(function(){var t;t=h.UIkit?h.UIkit:require("uikit").default;var e=h.vdmUploaderConfig||{},n=e.endpoint,r=e.targetClass;if(function(t,e){if(null==t)return{};var n,r,o=function(t,e){if(null==t)return{};var n={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(e.includes(r))continue;n[r]=t[r]}return n}(t,e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);for(r=0;r<a.length;r++)n=a[r],e.includes(n)||{}.propertyIsEnumerable.call(t,n)&&(o[n]=t[n])}}(e,_),n&&r){var o=document.querySelectorAll("."+r),a={};o.forEach((function(t){var e=t.getAttribute("id"),n=h.vdmUploaderConfig[e]?h.vdmUploaderConfig[e].endpoint:null;if(n){var r=t.dataset.progressbarId,o=t.dataset.typeId,i=h.vdmUploaderConfig[e]?h.vdmUploaderConfig[e].endpoint_diplay:null,c=t.dataset.displayId||null,u=t.dataset.successId||null,s=t.dataset.errorId||null,l=t.dataset.allowedFormatId||null,f=t.dataset.fileTypeId||null;a[e]={bar:r,typeId:o,endpoint:n,successId:u,errorId:s,allowedFormatId:l,fileTypeId:f,displayId:c,displayEndpoint:i}}})),Object.keys(a).length>0&&new P(a,n,t)}}))}();