sweetalert2.js 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180
  1. /*!
  2. * sweetalert2 v9.15.2
  3. * Released under the MIT License.
  4. */
  5. (function (global, factory) {
  6. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  7. typeof define === 'function' && define.amd ? define(factory) :
  8. (global = global || self, global.Sweetalert2 = factory());
  9. }(this, function () { 'use strict';
  10. function _typeof(obj) {
  11. "@babel/helpers - typeof";
  12. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  13. _typeof = function (obj) {
  14. return typeof obj;
  15. };
  16. } else {
  17. _typeof = function (obj) {
  18. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  19. };
  20. }
  21. return _typeof(obj);
  22. }
  23. function _classCallCheck(instance, Constructor) {
  24. if (!(instance instanceof Constructor)) {
  25. throw new TypeError("Cannot call a class as a function");
  26. }
  27. }
  28. function _defineProperties(target, props) {
  29. for (var i = 0; i < props.length; i++) {
  30. var descriptor = props[i];
  31. descriptor.enumerable = descriptor.enumerable || false;
  32. descriptor.configurable = true;
  33. if ("value" in descriptor) descriptor.writable = true;
  34. Object.defineProperty(target, descriptor.key, descriptor);
  35. }
  36. }
  37. function _createClass(Constructor, protoProps, staticProps) {
  38. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  39. if (staticProps) _defineProperties(Constructor, staticProps);
  40. return Constructor;
  41. }
  42. function _extends() {
  43. _extends = Object.assign || function (target) {
  44. for (var i = 1; i < arguments.length; i++) {
  45. var source = arguments[i];
  46. for (var key in source) {
  47. if (Object.prototype.hasOwnProperty.call(source, key)) {
  48. target[key] = source[key];
  49. }
  50. }
  51. }
  52. return target;
  53. };
  54. return _extends.apply(this, arguments);
  55. }
  56. function _inherits(subClass, superClass) {
  57. if (typeof superClass !== "function" && superClass !== null) {
  58. throw new TypeError("Super expression must either be null or a function");
  59. }
  60. subClass.prototype = Object.create(superClass && superClass.prototype, {
  61. constructor: {
  62. value: subClass,
  63. writable: true,
  64. configurable: true
  65. }
  66. });
  67. if (superClass) _setPrototypeOf(subClass, superClass);
  68. }
  69. function _getPrototypeOf(o) {
  70. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  71. return o.__proto__ || Object.getPrototypeOf(o);
  72. };
  73. return _getPrototypeOf(o);
  74. }
  75. function _setPrototypeOf(o, p) {
  76. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  77. o.__proto__ = p;
  78. return o;
  79. };
  80. return _setPrototypeOf(o, p);
  81. }
  82. function _isNativeReflectConstruct() {
  83. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  84. if (Reflect.construct.sham) return false;
  85. if (typeof Proxy === "function") return true;
  86. try {
  87. Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
  88. return true;
  89. } catch (e) {
  90. return false;
  91. }
  92. }
  93. function _construct(Parent, args, Class) {
  94. if (_isNativeReflectConstruct()) {
  95. _construct = Reflect.construct;
  96. } else {
  97. _construct = function _construct(Parent, args, Class) {
  98. var a = [null];
  99. a.push.apply(a, args);
  100. var Constructor = Function.bind.apply(Parent, a);
  101. var instance = new Constructor();
  102. if (Class) _setPrototypeOf(instance, Class.prototype);
  103. return instance;
  104. };
  105. }
  106. return _construct.apply(null, arguments);
  107. }
  108. function _assertThisInitialized(self) {
  109. if (self === void 0) {
  110. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  111. }
  112. return self;
  113. }
  114. function _possibleConstructorReturn(self, call) {
  115. if (call && (typeof call === "object" || typeof call === "function")) {
  116. return call;
  117. }
  118. return _assertThisInitialized(self);
  119. }
  120. function _createSuper(Derived) {
  121. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  122. return function _createSuperInternal() {
  123. var Super = _getPrototypeOf(Derived),
  124. result;
  125. if (hasNativeReflectConstruct) {
  126. var NewTarget = _getPrototypeOf(this).constructor;
  127. result = Reflect.construct(Super, arguments, NewTarget);
  128. } else {
  129. result = Super.apply(this, arguments);
  130. }
  131. return _possibleConstructorReturn(this, result);
  132. };
  133. }
  134. function _superPropBase(object, property) {
  135. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  136. object = _getPrototypeOf(object);
  137. if (object === null) break;
  138. }
  139. return object;
  140. }
  141. function _get(target, property, receiver) {
  142. if (typeof Reflect !== "undefined" && Reflect.get) {
  143. _get = Reflect.get;
  144. } else {
  145. _get = function _get(target, property, receiver) {
  146. var base = _superPropBase(target, property);
  147. if (!base) return;
  148. var desc = Object.getOwnPropertyDescriptor(base, property);
  149. if (desc.get) {
  150. return desc.get.call(receiver);
  151. }
  152. return desc.value;
  153. };
  154. }
  155. return _get(target, property, receiver || target);
  156. }
  157. var consolePrefix = 'SweetAlert2:';
  158. /**
  159. * Filter the unique values into a new array
  160. * @param arr
  161. */
  162. var uniqueArray = function uniqueArray(arr) {
  163. var result = [];
  164. for (var i = 0; i < arr.length; i++) {
  165. if (result.indexOf(arr[i]) === -1) {
  166. result.push(arr[i]);
  167. }
  168. }
  169. return result;
  170. };
  171. /**
  172. * Capitalize the first letter of a string
  173. * @param str
  174. */
  175. var capitalizeFirstLetter = function capitalizeFirstLetter(str) {
  176. return str.charAt(0).toUpperCase() + str.slice(1);
  177. };
  178. /**
  179. * Returns the array of object values (Object.values isn't supported in IE11)
  180. * @param obj
  181. */
  182. var objectValues = function objectValues(obj) {
  183. return Object.keys(obj).map(function (key) {
  184. return obj[key];
  185. });
  186. };
  187. /**
  188. * Convert NodeList to Array
  189. * @param nodeList
  190. */
  191. var toArray = function toArray(nodeList) {
  192. return Array.prototype.slice.call(nodeList);
  193. };
  194. /**
  195. * Standardise console warnings
  196. * @param message
  197. */
  198. var warn = function warn(message) {
  199. console.warn("".concat(consolePrefix, " ").concat(message));
  200. };
  201. /**
  202. * Standardise console errors
  203. * @param message
  204. */
  205. var error = function error(message) {
  206. console.error("".concat(consolePrefix, " ").concat(message));
  207. };
  208. /**
  209. * Private global state for `warnOnce`
  210. * @type {Array}
  211. * @private
  212. */
  213. var previousWarnOnceMessages = [];
  214. /**
  215. * Show a console warning, but only if it hasn't already been shown
  216. * @param message
  217. */
  218. var warnOnce = function warnOnce(message) {
  219. if (!(previousWarnOnceMessages.indexOf(message) !== -1)) {
  220. previousWarnOnceMessages.push(message);
  221. warn(message);
  222. }
  223. };
  224. /**
  225. * Show a one-time console warning about deprecated params/methods
  226. */
  227. var warnAboutDepreation = function warnAboutDepreation(deprecatedParam, useInstead) {
  228. warnOnce("\"".concat(deprecatedParam, "\" is deprecated and will be removed in the next major release. Please use \"").concat(useInstead, "\" instead."));
  229. };
  230. /**
  231. * If `arg` is a function, call it (with no arguments or context) and return the result.
  232. * Otherwise, just pass the value through
  233. * @param arg
  234. */
  235. var callIfFunction = function callIfFunction(arg) {
  236. return typeof arg === 'function' ? arg() : arg;
  237. };
  238. var hasToPromiseFn = function hasToPromiseFn(arg) {
  239. return arg && typeof arg.toPromise === 'function';
  240. };
  241. var asPromise = function asPromise(arg) {
  242. return hasToPromiseFn(arg) ? arg.toPromise() : Promise.resolve(arg);
  243. };
  244. var isPromise = function isPromise(arg) {
  245. return arg && Promise.resolve(arg) === arg;
  246. };
  247. var DismissReason = Object.freeze({
  248. cancel: 'cancel',
  249. backdrop: 'backdrop',
  250. close: 'close',
  251. esc: 'esc',
  252. timer: 'timer'
  253. });
  254. var isJqueryElement = function isJqueryElement(elem) {
  255. return _typeof(elem) === 'object' && elem.jquery;
  256. };
  257. var isElement = function isElement(elem) {
  258. return elem instanceof Element || isJqueryElement(elem);
  259. };
  260. var argsToParams = function argsToParams(args) {
  261. var params = {};
  262. if (_typeof(args[0]) === 'object' && !isElement(args[0])) {
  263. _extends(params, args[0]);
  264. } else {
  265. ['title', 'html', 'icon'].forEach(function (name, index) {
  266. var arg = args[index];
  267. if (typeof arg === 'string' || isElement(arg)) {
  268. params[name] = arg;
  269. } else if (arg !== undefined) {
  270. error("Unexpected type of ".concat(name, "! Expected \"string\" or \"Element\", got ").concat(_typeof(arg)));
  271. }
  272. });
  273. }
  274. return params;
  275. };
  276. var swalPrefix = 'swal2-';
  277. var prefix = function prefix(items) {
  278. var result = {};
  279. for (var i in items) {
  280. result[items[i]] = swalPrefix + items[i];
  281. }
  282. return result;
  283. };
  284. var swalClasses = prefix(['container', 'shown', 'height-auto', 'iosfix', 'popup', 'modal', 'no-backdrop', 'no-transition', 'toast', 'toast-shown', 'toast-column', 'show', 'hide', 'close', 'title', 'header', 'content', 'html-container', 'actions', 'confirm', 'cancel', 'footer', 'icon', 'icon-content', 'image', 'input', 'file', 'range', 'select', 'radio', 'checkbox', 'label', 'textarea', 'inputerror', 'validation-message', 'progress-steps', 'active-progress-step', 'progress-step', 'progress-step-line', 'loading', 'styled', 'top', 'top-start', 'top-end', 'top-left', 'top-right', 'center', 'center-start', 'center-end', 'center-left', 'center-right', 'bottom', 'bottom-start', 'bottom-end', 'bottom-left', 'bottom-right', 'grow-row', 'grow-column', 'grow-fullscreen', 'rtl', 'timer-progress-bar', 'timer-progress-bar-container', 'scrollbar-measure', 'icon-success', 'icon-warning', 'icon-info', 'icon-question', 'icon-error']);
  285. var iconTypes = prefix(['success', 'warning', 'info', 'question', 'error']);
  286. var getContainer = function getContainer() {
  287. return document.body.querySelector(".".concat(swalClasses.container));
  288. };
  289. var elementBySelector = function elementBySelector(selectorString) {
  290. var container = getContainer();
  291. return container ? container.querySelector(selectorString) : null;
  292. };
  293. var elementByClass = function elementByClass(className) {
  294. return elementBySelector(".".concat(className));
  295. };
  296. var getPopup = function getPopup() {
  297. return elementByClass(swalClasses.popup);
  298. };
  299. var getIcons = function getIcons() {
  300. var popup = getPopup();
  301. return toArray(popup.querySelectorAll(".".concat(swalClasses.icon)));
  302. };
  303. var getIcon = function getIcon() {
  304. var visibleIcon = getIcons().filter(function (icon) {
  305. return isVisible(icon);
  306. });
  307. return visibleIcon.length ? visibleIcon[0] : null;
  308. };
  309. var getTitle = function getTitle() {
  310. return elementByClass(swalClasses.title);
  311. };
  312. var getContent = function getContent() {
  313. return elementByClass(swalClasses.content);
  314. };
  315. var getHtmlContainer = function getHtmlContainer() {
  316. return elementByClass(swalClasses['html-container']);
  317. };
  318. var getImage = function getImage() {
  319. return elementByClass(swalClasses.image);
  320. };
  321. var getProgressSteps = function getProgressSteps() {
  322. return elementByClass(swalClasses['progress-steps']);
  323. };
  324. var getValidationMessage = function getValidationMessage() {
  325. return elementByClass(swalClasses['validation-message']);
  326. };
  327. var getConfirmButton = function getConfirmButton() {
  328. return elementBySelector(".".concat(swalClasses.actions, " .").concat(swalClasses.confirm));
  329. };
  330. var getCancelButton = function getCancelButton() {
  331. return elementBySelector(".".concat(swalClasses.actions, " .").concat(swalClasses.cancel));
  332. };
  333. var getActions = function getActions() {
  334. return elementByClass(swalClasses.actions);
  335. };
  336. var getHeader = function getHeader() {
  337. return elementByClass(swalClasses.header);
  338. };
  339. var getFooter = function getFooter() {
  340. return elementByClass(swalClasses.footer);
  341. };
  342. var getTimerProgressBar = function getTimerProgressBar() {
  343. return elementByClass(swalClasses['timer-progress-bar']);
  344. };
  345. var getCloseButton = function getCloseButton() {
  346. return elementByClass(swalClasses.close);
  347. }; // https://github.com/jkup/focusable/blob/master/index.js
  348. var focusable = "\n a[href],\n area[href],\n input:not([disabled]),\n select:not([disabled]),\n textarea:not([disabled]),\n button:not([disabled]),\n iframe,\n object,\n embed,\n [tabindex=\"0\"],\n [contenteditable],\n audio[controls],\n video[controls],\n summary\n";
  349. var getFocusableElements = function getFocusableElements() {
  350. var focusableElementsWithTabindex = toArray(getPopup().querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])')) // sort according to tabindex
  351. .sort(function (a, b) {
  352. a = parseInt(a.getAttribute('tabindex'));
  353. b = parseInt(b.getAttribute('tabindex'));
  354. if (a > b) {
  355. return 1;
  356. } else if (a < b) {
  357. return -1;
  358. }
  359. return 0;
  360. });
  361. var otherFocusableElements = toArray(getPopup().querySelectorAll(focusable)).filter(function (el) {
  362. return el.getAttribute('tabindex') !== '-1';
  363. });
  364. return uniqueArray(focusableElementsWithTabindex.concat(otherFocusableElements)).filter(function (el) {
  365. return isVisible(el);
  366. });
  367. };
  368. var isModal = function isModal() {
  369. return !isToast() && !document.body.classList.contains(swalClasses['no-backdrop']);
  370. };
  371. var isToast = function isToast() {
  372. return document.body.classList.contains(swalClasses['toast-shown']);
  373. };
  374. var isLoading = function isLoading() {
  375. return getPopup().hasAttribute('data-loading');
  376. };
  377. var states = {
  378. previousBodyPadding: null
  379. };
  380. var setInnerHtml = function setInnerHtml(elem, html) {
  381. // #1926
  382. elem.textContent = '';
  383. if (html) {
  384. var parser = new DOMParser();
  385. var parsed = parser.parseFromString(html, "text/html");
  386. toArray(parsed.querySelector('head').childNodes).forEach(function (child) {
  387. elem.appendChild(child);
  388. });
  389. toArray(parsed.querySelector('body').childNodes).forEach(function (child) {
  390. elem.appendChild(child);
  391. });
  392. }
  393. };
  394. var hasClass = function hasClass(elem, className) {
  395. if (!className) {
  396. return false;
  397. }
  398. var classList = className.split(/\s+/);
  399. for (var i = 0; i < classList.length; i++) {
  400. if (!elem.classList.contains(classList[i])) {
  401. return false;
  402. }
  403. }
  404. return true;
  405. };
  406. var removeCustomClasses = function removeCustomClasses(elem, params) {
  407. toArray(elem.classList).forEach(function (className) {
  408. if (!(objectValues(swalClasses).indexOf(className) !== -1) && !(objectValues(iconTypes).indexOf(className) !== -1) && !(objectValues(params.showClass).indexOf(className) !== -1)) {
  409. elem.classList.remove(className);
  410. }
  411. });
  412. };
  413. var applyCustomClass = function applyCustomClass(elem, params, className) {
  414. removeCustomClasses(elem, params);
  415. if (params.customClass && params.customClass[className]) {
  416. if (typeof params.customClass[className] !== 'string' && !params.customClass[className].forEach) {
  417. return warn("Invalid type of customClass.".concat(className, "! Expected string or iterable object, got \"").concat(_typeof(params.customClass[className]), "\""));
  418. }
  419. addClass(elem, params.customClass[className]);
  420. }
  421. };
  422. function getInput(content, inputType) {
  423. if (!inputType) {
  424. return null;
  425. }
  426. switch (inputType) {
  427. case 'select':
  428. case 'textarea':
  429. case 'file':
  430. return getChildByClass(content, swalClasses[inputType]);
  431. case 'checkbox':
  432. return content.querySelector(".".concat(swalClasses.checkbox, " input"));
  433. case 'radio':
  434. return content.querySelector(".".concat(swalClasses.radio, " input:checked")) || content.querySelector(".".concat(swalClasses.radio, " input:first-child"));
  435. case 'range':
  436. return content.querySelector(".".concat(swalClasses.range, " input"));
  437. default:
  438. return getChildByClass(content, swalClasses.input);
  439. }
  440. }
  441. var focusInput = function focusInput(input) {
  442. input.focus(); // place cursor at end of text in text input
  443. if (input.type !== 'file') {
  444. // http://stackoverflow.com/a/2345915
  445. var val = input.value;
  446. input.value = '';
  447. input.value = val;
  448. }
  449. };
  450. var toggleClass = function toggleClass(target, classList, condition) {
  451. if (!target || !classList) {
  452. return;
  453. }
  454. if (typeof classList === 'string') {
  455. classList = classList.split(/\s+/).filter(Boolean);
  456. }
  457. classList.forEach(function (className) {
  458. if (target.forEach) {
  459. target.forEach(function (elem) {
  460. condition ? elem.classList.add(className) : elem.classList.remove(className);
  461. });
  462. } else {
  463. condition ? target.classList.add(className) : target.classList.remove(className);
  464. }
  465. });
  466. };
  467. var addClass = function addClass(target, classList) {
  468. toggleClass(target, classList, true);
  469. };
  470. var removeClass = function removeClass(target, classList) {
  471. toggleClass(target, classList, false);
  472. };
  473. var getChildByClass = function getChildByClass(elem, className) {
  474. for (var i = 0; i < elem.childNodes.length; i++) {
  475. if (hasClass(elem.childNodes[i], className)) {
  476. return elem.childNodes[i];
  477. }
  478. }
  479. };
  480. var applyNumericalStyle = function applyNumericalStyle(elem, property, value) {
  481. if (value || parseInt(value) === 0) {
  482. elem.style[property] = typeof value === 'number' ? "".concat(value, "px") : value;
  483. } else {
  484. elem.style.removeProperty(property);
  485. }
  486. };
  487. var show = function show(elem) {
  488. var display = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'flex';
  489. elem.style.opacity = '';
  490. elem.style.display = display;
  491. };
  492. var hide = function hide(elem) {
  493. elem.style.opacity = '';
  494. elem.style.display = 'none';
  495. };
  496. var toggle = function toggle(elem, condition, display) {
  497. condition ? show(elem, display) : hide(elem);
  498. }; // borrowed from jquery $(elem).is(':visible') implementation
  499. var isVisible = function isVisible(elem) {
  500. return !!(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length));
  501. };
  502. /* istanbul ignore next */
  503. var isScrollable = function isScrollable(elem) {
  504. return !!(elem.scrollHeight > elem.clientHeight);
  505. }; // borrowed from https://stackoverflow.com/a/46352119
  506. var hasCssAnimation = function hasCssAnimation(elem) {
  507. var style = window.getComputedStyle(elem);
  508. var animDuration = parseFloat(style.getPropertyValue('animation-duration') || '0');
  509. var transDuration = parseFloat(style.getPropertyValue('transition-duration') || '0');
  510. return animDuration > 0 || transDuration > 0;
  511. };
  512. var contains = function contains(haystack, needle) {
  513. if (typeof haystack.contains === 'function') {
  514. return haystack.contains(needle);
  515. }
  516. };
  517. var animateTimerProgressBar = function animateTimerProgressBar(timer) {
  518. var reset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  519. var timerProgressBar = getTimerProgressBar();
  520. if (isVisible(timerProgressBar)) {
  521. if (reset) {
  522. timerProgressBar.style.transition = 'none';
  523. timerProgressBar.style.width = '100%';
  524. }
  525. setTimeout(function () {
  526. timerProgressBar.style.transition = "width ".concat(timer / 1000, "s linear");
  527. timerProgressBar.style.width = '0%';
  528. }, 10);
  529. }
  530. };
  531. var stopTimerProgressBar = function stopTimerProgressBar() {
  532. var timerProgressBar = getTimerProgressBar();
  533. var timerProgressBarWidth = parseInt(window.getComputedStyle(timerProgressBar).width);
  534. timerProgressBar.style.removeProperty('transition');
  535. timerProgressBar.style.width = '100%';
  536. var timerProgressBarFullWidth = parseInt(window.getComputedStyle(timerProgressBar).width);
  537. var timerProgressBarPercent = parseInt(timerProgressBarWidth / timerProgressBarFullWidth * 100);
  538. timerProgressBar.style.removeProperty('transition');
  539. timerProgressBar.style.width = "".concat(timerProgressBarPercent, "%");
  540. };
  541. // Detect Node env
  542. var isNodeEnv = function isNodeEnv() {
  543. return typeof window === 'undefined' || typeof document === 'undefined';
  544. };
  545. var sweetHTML = "\n <div aria-labelledby=\"".concat(swalClasses.title, "\" aria-describedby=\"").concat(swalClasses.content, "\" class=\"").concat(swalClasses.popup, "\" tabindex=\"-1\">\n <div class=\"").concat(swalClasses.header, "\">\n <ul class=\"").concat(swalClasses['progress-steps'], "\"></ul>\n <div class=\"").concat(swalClasses.icon, " ").concat(iconTypes.error, "\"></div>\n <div class=\"").concat(swalClasses.icon, " ").concat(iconTypes.question, "\"></div>\n <div class=\"").concat(swalClasses.icon, " ").concat(iconTypes.warning, "\"></div>\n <div class=\"").concat(swalClasses.icon, " ").concat(iconTypes.info, "\"></div>\n <div class=\"").concat(swalClasses.icon, " ").concat(iconTypes.success, "\"></div>\n <img class=\"").concat(swalClasses.image, "\" />\n <h2 class=\"").concat(swalClasses.title, "\" id=\"").concat(swalClasses.title, "\"></h2>\n <button type=\"button\" class=\"").concat(swalClasses.close, "\"></button>\n </div>\n <div class=\"").concat(swalClasses.content, "\">\n <div id=\"").concat(swalClasses.content, "\" class=\"").concat(swalClasses['html-container'], "\"></div>\n <input class=\"").concat(swalClasses.input, "\" />\n <input type=\"file\" class=\"").concat(swalClasses.file, "\" />\n <div class=\"").concat(swalClasses.range, "\">\n <input type=\"range\" />\n <output></output>\n </div>\n <select class=\"").concat(swalClasses.select, "\"></select>\n <div class=\"").concat(swalClasses.radio, "\"></div>\n <label for=\"").concat(swalClasses.checkbox, "\" class=\"").concat(swalClasses.checkbox, "\">\n <input type=\"checkbox\" />\n <span class=\"").concat(swalClasses.label, "\"></span>\n </label>\n <textarea class=\"").concat(swalClasses.textarea, "\"></textarea>\n <div class=\"").concat(swalClasses['validation-message'], "\" id=\"").concat(swalClasses['validation-message'], "\"></div>\n </div>\n <div class=\"").concat(swalClasses.actions, "\">\n <button type=\"button\" class=\"").concat(swalClasses.confirm, "\">OK</button>\n <button type=\"button\" class=\"").concat(swalClasses.cancel, "\">Cancel</button>\n </div>\n <div class=\"").concat(swalClasses.footer, "\"></div>\n <div class=\"").concat(swalClasses['timer-progress-bar-container'], "\">\n <div class=\"").concat(swalClasses['timer-progress-bar'], "\"></div>\n </div>\n </div>\n").replace(/(^|\n)\s*/g, '');
  546. var resetOldContainer = function resetOldContainer() {
  547. var oldContainer = getContainer();
  548. if (!oldContainer) {
  549. return false;
  550. }
  551. oldContainer.parentNode.removeChild(oldContainer);
  552. removeClass([document.documentElement, document.body], [swalClasses['no-backdrop'], swalClasses['toast-shown'], swalClasses['has-column']]);
  553. return true;
  554. };
  555. var oldInputVal; // IE11 workaround, see #1109 for details
  556. var resetValidationMessage = function resetValidationMessage(e) {
  557. if (Swal.isVisible() && oldInputVal !== e.target.value) {
  558. Swal.resetValidationMessage();
  559. }
  560. oldInputVal = e.target.value;
  561. };
  562. var addInputChangeListeners = function addInputChangeListeners() {
  563. var content = getContent();
  564. var input = getChildByClass(content, swalClasses.input);
  565. var file = getChildByClass(content, swalClasses.file);
  566. var range = content.querySelector(".".concat(swalClasses.range, " input"));
  567. var rangeOutput = content.querySelector(".".concat(swalClasses.range, " output"));
  568. var select = getChildByClass(content, swalClasses.select);
  569. var checkbox = content.querySelector(".".concat(swalClasses.checkbox, " input"));
  570. var textarea = getChildByClass(content, swalClasses.textarea);
  571. input.oninput = resetValidationMessage;
  572. file.onchange = resetValidationMessage;
  573. select.onchange = resetValidationMessage;
  574. checkbox.onchange = resetValidationMessage;
  575. textarea.oninput = resetValidationMessage;
  576. range.oninput = function (e) {
  577. resetValidationMessage(e);
  578. rangeOutput.value = range.value;
  579. };
  580. range.onchange = function (e) {
  581. resetValidationMessage(e);
  582. range.nextSibling.value = range.value;
  583. };
  584. };
  585. var getTarget = function getTarget(target) {
  586. return typeof target === 'string' ? document.querySelector(target) : target;
  587. };
  588. var setupAccessibility = function setupAccessibility(params) {
  589. var popup = getPopup();
  590. popup.setAttribute('role', params.toast ? 'alert' : 'dialog');
  591. popup.setAttribute('aria-live', params.toast ? 'polite' : 'assertive');
  592. if (!params.toast) {
  593. popup.setAttribute('aria-modal', 'true');
  594. }
  595. };
  596. var setupRTL = function setupRTL(targetElement) {
  597. if (window.getComputedStyle(targetElement).direction === 'rtl') {
  598. addClass(getContainer(), swalClasses.rtl);
  599. }
  600. };
  601. /*
  602. * Add modal + backdrop to DOM
  603. */
  604. var init = function init(params) {
  605. // Clean up the old popup container if it exists
  606. var oldContainerExisted = resetOldContainer();
  607. /* istanbul ignore if */
  608. if (isNodeEnv()) {
  609. error('SweetAlert2 requires document to initialize');
  610. return;
  611. }
  612. var container = document.createElement('div');
  613. container.className = swalClasses.container;
  614. if (oldContainerExisted) {
  615. addClass(container, swalClasses['no-transition']);
  616. }
  617. setInnerHtml(container, sweetHTML);
  618. var targetElement = getTarget(params.target);
  619. targetElement.appendChild(container);
  620. setupAccessibility(params);
  621. setupRTL(targetElement);
  622. addInputChangeListeners();
  623. };
  624. var parseHtmlToContainer = function parseHtmlToContainer(param, target) {
  625. // DOM element
  626. if (param instanceof HTMLElement) {
  627. target.appendChild(param); // Object
  628. } else if (_typeof(param) === 'object') {
  629. handleObject(param, target); // Plain string
  630. } else if (param) {
  631. setInnerHtml(target, param);
  632. }
  633. };
  634. var handleObject = function handleObject(param, target) {
  635. // JQuery element(s)
  636. if (param.jquery) {
  637. handleJqueryElem(target, param); // For other objects use their string representation
  638. } else {
  639. setInnerHtml(target, param.toString());
  640. }
  641. };
  642. var handleJqueryElem = function handleJqueryElem(target, elem) {
  643. target.textContent = '';
  644. if (0 in elem) {
  645. for (var i = 0; (i in elem); i++) {
  646. target.appendChild(elem[i].cloneNode(true));
  647. }
  648. } else {
  649. target.appendChild(elem.cloneNode(true));
  650. }
  651. };
  652. var animationEndEvent = function () {
  653. // Prevent run in Node env
  654. /* istanbul ignore if */
  655. if (isNodeEnv()) {
  656. return false;
  657. }
  658. var testEl = document.createElement('div');
  659. var transEndEventNames = {
  660. WebkitAnimation: 'webkitAnimationEnd',
  661. OAnimation: 'oAnimationEnd oanimationend',
  662. animation: 'animationend'
  663. };
  664. for (var i in transEndEventNames) {
  665. if (Object.prototype.hasOwnProperty.call(transEndEventNames, i) && typeof testEl.style[i] !== 'undefined') {
  666. return transEndEventNames[i];
  667. }
  668. }
  669. return false;
  670. }();
  671. // https://github.com/twbs/bootstrap/blob/master/js/src/modal.js
  672. var measureScrollbar = function measureScrollbar() {
  673. var scrollDiv = document.createElement('div');
  674. scrollDiv.className = swalClasses['scrollbar-measure'];
  675. document.body.appendChild(scrollDiv);
  676. var scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth;
  677. document.body.removeChild(scrollDiv);
  678. return scrollbarWidth;
  679. };
  680. var renderActions = function renderActions(instance, params) {
  681. var actions = getActions();
  682. var confirmButton = getConfirmButton();
  683. var cancelButton = getCancelButton(); // Actions (buttons) wrapper
  684. if (!params.showConfirmButton && !params.showCancelButton) {
  685. hide(actions);
  686. } // Custom class
  687. applyCustomClass(actions, params, 'actions'); // Render confirm button
  688. renderButton(confirmButton, 'confirm', params); // render Cancel Button
  689. renderButton(cancelButton, 'cancel', params);
  690. if (params.buttonsStyling) {
  691. handleButtonsStyling(confirmButton, cancelButton, params);
  692. } else {
  693. removeClass([confirmButton, cancelButton], swalClasses.styled);
  694. confirmButton.style.backgroundColor = confirmButton.style.borderLeftColor = confirmButton.style.borderRightColor = '';
  695. cancelButton.style.backgroundColor = cancelButton.style.borderLeftColor = cancelButton.style.borderRightColor = '';
  696. }
  697. if (params.reverseButtons) {
  698. confirmButton.parentNode.insertBefore(cancelButton, confirmButton);
  699. }
  700. };
  701. function handleButtonsStyling(confirmButton, cancelButton, params) {
  702. addClass([confirmButton, cancelButton], swalClasses.styled); // Buttons background colors
  703. if (params.confirmButtonColor) {
  704. confirmButton.style.backgroundColor = params.confirmButtonColor;
  705. }
  706. if (params.cancelButtonColor) {
  707. cancelButton.style.backgroundColor = params.cancelButtonColor;
  708. } // Loading state
  709. if (!isLoading()) {
  710. var confirmButtonBackgroundColor = window.getComputedStyle(confirmButton).getPropertyValue('background-color');
  711. confirmButton.style.borderLeftColor = confirmButtonBackgroundColor;
  712. confirmButton.style.borderRightColor = confirmButtonBackgroundColor;
  713. }
  714. }
  715. function renderButton(button, buttonType, params) {
  716. toggle(button, params["show".concat(capitalizeFirstLetter(buttonType), "Button")], 'inline-block');
  717. setInnerHtml(button, params["".concat(buttonType, "ButtonText")]); // Set caption text
  718. button.setAttribute('aria-label', params["".concat(buttonType, "ButtonAriaLabel")]); // ARIA label
  719. // Add buttons custom classes
  720. button.className = swalClasses[buttonType];
  721. applyCustomClass(button, params, "".concat(buttonType, "Button"));
  722. addClass(button, params["".concat(buttonType, "ButtonClass")]);
  723. }
  724. function handleBackdropParam(container, backdrop) {
  725. if (typeof backdrop === 'string') {
  726. container.style.background = backdrop;
  727. } else if (!backdrop) {
  728. addClass([document.documentElement, document.body], swalClasses['no-backdrop']);
  729. }
  730. }
  731. function handlePositionParam(container, position) {
  732. if (position in swalClasses) {
  733. addClass(container, swalClasses[position]);
  734. } else {
  735. warn('The "position" parameter is not valid, defaulting to "center"');
  736. addClass(container, swalClasses.center);
  737. }
  738. }
  739. function handleGrowParam(container, grow) {
  740. if (grow && typeof grow === 'string') {
  741. var growClass = "grow-".concat(grow);
  742. if (growClass in swalClasses) {
  743. addClass(container, swalClasses[growClass]);
  744. }
  745. }
  746. }
  747. var renderContainer = function renderContainer(instance, params) {
  748. var container = getContainer();
  749. if (!container) {
  750. return;
  751. }
  752. handleBackdropParam(container, params.backdrop);
  753. if (!params.backdrop && params.allowOutsideClick) {
  754. warn('"allowOutsideClick" parameter requires `backdrop` parameter to be set to `true`');
  755. }
  756. handlePositionParam(container, params.position);
  757. handleGrowParam(container, params.grow); // Custom class
  758. applyCustomClass(container, params, 'container'); // Set queue step attribute for getQueueStep() method
  759. var queueStep = document.body.getAttribute('data-swal2-queue-step');
  760. if (queueStep) {
  761. container.setAttribute('data-queue-step', queueStep);
  762. document.body.removeAttribute('data-swal2-queue-step');
  763. }
  764. };
  765. /**
  766. * This module containts `WeakMap`s for each effectively-"private property" that a `Swal` has.
  767. * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')`
  768. * This is the approach that Babel will probably take to implement private methods/fields
  769. * https://github.com/tc39/proposal-private-methods
  770. * https://github.com/babel/babel/pull/7555
  771. * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module*
  772. * then we can use that language feature.
  773. */
  774. var privateProps = {
  775. promise: new WeakMap(),
  776. innerParams: new WeakMap(),
  777. domCache: new WeakMap()
  778. };
  779. var inputTypes = ['input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea'];
  780. var renderInput = function renderInput(instance, params) {
  781. var content = getContent();
  782. var innerParams = privateProps.innerParams.get(instance);
  783. var rerender = !innerParams || params.input !== innerParams.input;
  784. inputTypes.forEach(function (inputType) {
  785. var inputClass = swalClasses[inputType];
  786. var inputContainer = getChildByClass(content, inputClass); // set attributes
  787. setAttributes(inputType, params.inputAttributes); // set class
  788. inputContainer.className = inputClass;
  789. if (rerender) {
  790. hide(inputContainer);
  791. }
  792. });
  793. if (params.input) {
  794. if (rerender) {
  795. showInput(params);
  796. } // set custom class
  797. setCustomClass(params);
  798. }
  799. };
  800. var showInput = function showInput(params) {
  801. if (!renderInputType[params.input]) {
  802. return error("Unexpected type of input! Expected \"text\", \"email\", \"password\", \"number\", \"tel\", \"select\", \"radio\", \"checkbox\", \"textarea\", \"file\" or \"url\", got \"".concat(params.input, "\""));
  803. }
  804. var inputContainer = getInputContainer(params.input);
  805. var input = renderInputType[params.input](inputContainer, params);
  806. show(input); // input autofocus
  807. setTimeout(function () {
  808. focusInput(input);
  809. });
  810. };
  811. var removeAttributes = function removeAttributes(input) {
  812. for (var i = 0; i < input.attributes.length; i++) {
  813. var attrName = input.attributes[i].name;
  814. if (!(['type', 'value', 'style'].indexOf(attrName) !== -1)) {
  815. input.removeAttribute(attrName);
  816. }
  817. }
  818. };
  819. var setAttributes = function setAttributes(inputType, inputAttributes) {
  820. var input = getInput(getContent(), inputType);
  821. if (!input) {
  822. return;
  823. }
  824. removeAttributes(input);
  825. for (var attr in inputAttributes) {
  826. // Do not set a placeholder for <input type="range">
  827. // it'll crash Edge, #1298
  828. if (inputType === 'range' && attr === 'placeholder') {
  829. continue;
  830. }
  831. input.setAttribute(attr, inputAttributes[attr]);
  832. }
  833. };
  834. var setCustomClass = function setCustomClass(params) {
  835. var inputContainer = getInputContainer(params.input);
  836. if (params.customClass) {
  837. addClass(inputContainer, params.customClass.input);
  838. }
  839. };
  840. var setInputPlaceholder = function setInputPlaceholder(input, params) {
  841. if (!input.placeholder || params.inputPlaceholder) {
  842. input.placeholder = params.inputPlaceholder;
  843. }
  844. };
  845. var getInputContainer = function getInputContainer(inputType) {
  846. var inputClass = swalClasses[inputType] ? swalClasses[inputType] : swalClasses.input;
  847. return getChildByClass(getContent(), inputClass);
  848. };
  849. var renderInputType = {};
  850. renderInputType.text = renderInputType.email = renderInputType.password = renderInputType.number = renderInputType.tel = renderInputType.url = function (input, params) {
  851. if (typeof params.inputValue === 'string' || typeof params.inputValue === 'number') {
  852. input.value = params.inputValue;
  853. } else if (!isPromise(params.inputValue)) {
  854. warn("Unexpected type of inputValue! Expected \"string\", \"number\" or \"Promise\", got \"".concat(_typeof(params.inputValue), "\""));
  855. }
  856. setInputPlaceholder(input, params);
  857. input.type = params.input;
  858. return input;
  859. };
  860. renderInputType.file = function (input, params) {
  861. setInputPlaceholder(input, params);
  862. return input;
  863. };
  864. renderInputType.range = function (range, params) {
  865. var rangeInput = range.querySelector('input');
  866. var rangeOutput = range.querySelector('output');
  867. rangeInput.value = params.inputValue;
  868. rangeInput.type = params.input;
  869. rangeOutput.value = params.inputValue;
  870. return range;
  871. };
  872. renderInputType.select = function (select, params) {
  873. select.textContent = '';
  874. if (params.inputPlaceholder) {
  875. var placeholder = document.createElement('option');
  876. setInnerHtml(placeholder, params.inputPlaceholder);
  877. placeholder.value = '';
  878. placeholder.disabled = true;
  879. placeholder.selected = true;
  880. select.appendChild(placeholder);
  881. }
  882. return select;
  883. };
  884. renderInputType.radio = function (radio) {
  885. radio.textContent = '';
  886. return radio;
  887. };
  888. renderInputType.checkbox = function (checkboxContainer, params) {
  889. var checkbox = getInput(getContent(), 'checkbox');
  890. checkbox.value = 1;
  891. checkbox.id = swalClasses.checkbox;
  892. checkbox.checked = Boolean(params.inputValue);
  893. var label = checkboxContainer.querySelector('span');
  894. setInnerHtml(label, params.inputPlaceholder);
  895. return checkboxContainer;
  896. };
  897. renderInputType.textarea = function (textarea, params) {
  898. textarea.value = params.inputValue;
  899. setInputPlaceholder(textarea, params);
  900. if ('MutationObserver' in window) {
  901. // #1699
  902. var initialPopupWidth = parseInt(window.getComputedStyle(getPopup()).width);
  903. var popupPadding = parseInt(window.getComputedStyle(getPopup()).paddingLeft) + parseInt(window.getComputedStyle(getPopup()).paddingRight);
  904. var outputsize = function outputsize() {
  905. var contentWidth = textarea.offsetWidth + popupPadding;
  906. if (contentWidth > initialPopupWidth) {
  907. getPopup().style.width = "".concat(contentWidth, "px");
  908. } else {
  909. getPopup().style.width = null;
  910. }
  911. };
  912. new MutationObserver(outputsize).observe(textarea, {
  913. attributes: true,
  914. attributeFilter: ['style']
  915. });
  916. }
  917. return textarea;
  918. };
  919. var renderContent = function renderContent(instance, params) {
  920. var content = getContent().querySelector("#".concat(swalClasses.content)); // Content as HTML
  921. if (params.html) {
  922. parseHtmlToContainer(params.html, content);
  923. show(content, 'block'); // Content as plain text
  924. } else if (params.text) {
  925. content.textContent = params.text;
  926. show(content, 'block'); // No content
  927. } else {
  928. hide(content);
  929. }
  930. renderInput(instance, params); // Custom class
  931. applyCustomClass(getContent(), params, 'content');
  932. };
  933. var renderFooter = function renderFooter(instance, params) {
  934. var footer = getFooter();
  935. toggle(footer, params.footer);
  936. if (params.footer) {
  937. parseHtmlToContainer(params.footer, footer);
  938. } // Custom class
  939. applyCustomClass(footer, params, 'footer');
  940. };
  941. var renderCloseButton = function renderCloseButton(instance, params) {
  942. var closeButton = getCloseButton();
  943. setInnerHtml(closeButton, params.closeButtonHtml); // Custom class
  944. applyCustomClass(closeButton, params, 'closeButton');
  945. toggle(closeButton, params.showCloseButton);
  946. closeButton.setAttribute('aria-label', params.closeButtonAriaLabel);
  947. };
  948. var renderIcon = function renderIcon(instance, params) {
  949. var innerParams = privateProps.innerParams.get(instance); // if the give icon already rendered, apply the custom class without re-rendering the icon
  950. if (innerParams && params.icon === innerParams.icon && getIcon()) {
  951. applyCustomClass(getIcon(), params, 'icon');
  952. return;
  953. }
  954. hideAllIcons();
  955. if (!params.icon) {
  956. return;
  957. }
  958. if (Object.keys(iconTypes).indexOf(params.icon) !== -1) {
  959. var icon = elementBySelector(".".concat(swalClasses.icon, ".").concat(iconTypes[params.icon]));
  960. show(icon); // Custom or default content
  961. setContent(icon, params);
  962. adjustSuccessIconBackgoundColor(); // Custom class
  963. applyCustomClass(icon, params, 'icon'); // Animate icon
  964. addClass(icon, params.showClass.icon);
  965. } else {
  966. error("Unknown icon! Expected \"success\", \"error\", \"warning\", \"info\" or \"question\", got \"".concat(params.icon, "\""));
  967. }
  968. };
  969. var hideAllIcons = function hideAllIcons() {
  970. var icons = getIcons();
  971. for (var i = 0; i < icons.length; i++) {
  972. hide(icons[i]);
  973. }
  974. }; // Adjust success icon background color to match the popup background color
  975. var adjustSuccessIconBackgoundColor = function adjustSuccessIconBackgoundColor() {
  976. var popup = getPopup();
  977. var popupBackgroundColor = window.getComputedStyle(popup).getPropertyValue('background-color');
  978. var successIconParts = popup.querySelectorAll('[class^=swal2-success-circular-line], .swal2-success-fix');
  979. for (var i = 0; i < successIconParts.length; i++) {
  980. successIconParts[i].style.backgroundColor = popupBackgroundColor;
  981. }
  982. };
  983. var setContent = function setContent(icon, params) {
  984. icon.textContent = '';
  985. if (params.iconHtml) {
  986. setInnerHtml(icon, iconContent(params.iconHtml));
  987. } else if (params.icon === 'success') {
  988. setInnerHtml(icon, "\n <div class=\"swal2-success-circular-line-left\"></div>\n <span class=\"swal2-success-line-tip\"></span> <span class=\"swal2-success-line-long\"></span>\n <div class=\"swal2-success-ring\"></div> <div class=\"swal2-success-fix\"></div>\n <div class=\"swal2-success-circular-line-right\"></div>\n ");
  989. } else if (params.icon === 'error') {
  990. setInnerHtml(icon, "\n <span class=\"swal2-x-mark\">\n <span class=\"swal2-x-mark-line-left\"></span>\n <span class=\"swal2-x-mark-line-right\"></span>\n </span>\n ");
  991. } else {
  992. var defaultIconHtml = {
  993. question: '?',
  994. warning: '!',
  995. info: 'i'
  996. };
  997. setInnerHtml(icon, iconContent(defaultIconHtml[params.icon]));
  998. }
  999. };
  1000. var iconContent = function iconContent(content) {
  1001. return "<div class=\"".concat(swalClasses['icon-content'], "\">").concat(content, "</div>");
  1002. };
  1003. var renderImage = function renderImage(instance, params) {
  1004. var image = getImage();
  1005. if (!params.imageUrl) {
  1006. return hide(image);
  1007. }
  1008. show(image, ''); // Src, alt
  1009. image.setAttribute('src', params.imageUrl);
  1010. image.setAttribute('alt', params.imageAlt); // Width, height
  1011. applyNumericalStyle(image, 'width', params.imageWidth);
  1012. applyNumericalStyle(image, 'height', params.imageHeight); // Class
  1013. image.className = swalClasses.image;
  1014. applyCustomClass(image, params, 'image');
  1015. };
  1016. var currentSteps = [];
  1017. /*
  1018. * Global function for chaining sweetAlert popups
  1019. */
  1020. var queue = function queue(steps) {
  1021. var Swal = this;
  1022. currentSteps = steps;
  1023. var resetAndResolve = function resetAndResolve(resolve, value) {
  1024. currentSteps = [];
  1025. resolve(value);
  1026. };
  1027. var queueResult = [];
  1028. return new Promise(function (resolve) {
  1029. (function step(i, callback) {
  1030. if (i < currentSteps.length) {
  1031. document.body.setAttribute('data-swal2-queue-step', i);
  1032. Swal.fire(currentSteps[i]).then(function (result) {
  1033. if (typeof result.value !== 'undefined') {
  1034. queueResult.push(result.value);
  1035. step(i + 1, callback);
  1036. } else {
  1037. resetAndResolve(resolve, {
  1038. dismiss: result.dismiss
  1039. });
  1040. }
  1041. });
  1042. } else {
  1043. resetAndResolve(resolve, {
  1044. value: queueResult
  1045. });
  1046. }
  1047. })(0);
  1048. });
  1049. };
  1050. /*
  1051. * Global function for getting the index of current popup in queue
  1052. */
  1053. var getQueueStep = function getQueueStep() {
  1054. return getContainer() && getContainer().getAttribute('data-queue-step');
  1055. };
  1056. /*
  1057. * Global function for inserting a popup to the queue
  1058. */
  1059. var insertQueueStep = function insertQueueStep(step, index) {
  1060. if (index && index < currentSteps.length) {
  1061. return currentSteps.splice(index, 0, step);
  1062. }
  1063. return currentSteps.push(step);
  1064. };
  1065. /*
  1066. * Global function for deleting a popup from the queue
  1067. */
  1068. var deleteQueueStep = function deleteQueueStep(index) {
  1069. if (typeof currentSteps[index] !== 'undefined') {
  1070. currentSteps.splice(index, 1);
  1071. }
  1072. };
  1073. var createStepElement = function createStepElement(step) {
  1074. var stepEl = document.createElement('li');
  1075. addClass(stepEl, swalClasses['progress-step']);
  1076. setInnerHtml(stepEl, step);
  1077. return stepEl;
  1078. };
  1079. var createLineElement = function createLineElement(params) {
  1080. var lineEl = document.createElement('li');
  1081. addClass(lineEl, swalClasses['progress-step-line']);
  1082. if (params.progressStepsDistance) {
  1083. lineEl.style.width = params.progressStepsDistance;
  1084. }
  1085. return lineEl;
  1086. };
  1087. var renderProgressSteps = function renderProgressSteps(instance, params) {
  1088. var progressStepsContainer = getProgressSteps();
  1089. if (!params.progressSteps || params.progressSteps.length === 0) {
  1090. return hide(progressStepsContainer);
  1091. }
  1092. show(progressStepsContainer);
  1093. progressStepsContainer.textContent = '';
  1094. var currentProgressStep = parseInt(params.currentProgressStep === undefined ? getQueueStep() : params.currentProgressStep);
  1095. if (currentProgressStep >= params.progressSteps.length) {
  1096. warn('Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)');
  1097. }
  1098. params.progressSteps.forEach(function (step, index) {
  1099. var stepEl = createStepElement(step);
  1100. progressStepsContainer.appendChild(stepEl);
  1101. if (index === currentProgressStep) {
  1102. addClass(stepEl, swalClasses['active-progress-step']);
  1103. }
  1104. if (index !== params.progressSteps.length - 1) {
  1105. var lineEl = createLineElement(params);
  1106. progressStepsContainer.appendChild(lineEl);
  1107. }
  1108. });
  1109. };
  1110. var renderTitle = function renderTitle(instance, params) {
  1111. var title = getTitle();
  1112. toggle(title, params.title || params.titleText);
  1113. if (params.title) {
  1114. parseHtmlToContainer(params.title, title);
  1115. }
  1116. if (params.titleText) {
  1117. title.innerText = params.titleText;
  1118. } // Custom class
  1119. applyCustomClass(title, params, 'title');
  1120. };
  1121. var renderHeader = function renderHeader(instance, params) {
  1122. var header = getHeader(); // Custom class
  1123. applyCustomClass(header, params, 'header'); // Progress steps
  1124. renderProgressSteps(instance, params); // Icon
  1125. renderIcon(instance, params); // Image
  1126. renderImage(instance, params); // Title
  1127. renderTitle(instance, params); // Close button
  1128. renderCloseButton(instance, params);
  1129. };
  1130. var renderPopup = function renderPopup(instance, params) {
  1131. var popup = getPopup(); // Width
  1132. applyNumericalStyle(popup, 'width', params.width); // Padding
  1133. applyNumericalStyle(popup, 'padding', params.padding); // Background
  1134. if (params.background) {
  1135. popup.style.background = params.background;
  1136. } // Classes
  1137. addClasses(popup, params);
  1138. };
  1139. var addClasses = function addClasses(popup, params) {
  1140. // Default Class + showClass when updating Swal.update({})
  1141. popup.className = "".concat(swalClasses.popup, " ").concat(isVisible(popup) ? params.showClass.popup : '');
  1142. if (params.toast) {
  1143. addClass([document.documentElement, document.body], swalClasses['toast-shown']);
  1144. addClass(popup, swalClasses.toast);
  1145. } else {
  1146. addClass(popup, swalClasses.modal);
  1147. } // Custom class
  1148. applyCustomClass(popup, params, 'popup');
  1149. if (typeof params.customClass === 'string') {
  1150. addClass(popup, params.customClass);
  1151. } // Icon class (#1842)
  1152. if (params.icon) {
  1153. addClass(popup, swalClasses["icon-".concat(params.icon)]);
  1154. }
  1155. };
  1156. var render = function render(instance, params) {
  1157. renderPopup(instance, params);
  1158. renderContainer(instance, params);
  1159. renderHeader(instance, params);
  1160. renderContent(instance, params);
  1161. renderActions(instance, params);
  1162. renderFooter(instance, params);
  1163. if (typeof params.onRender === 'function') {
  1164. params.onRender(getPopup());
  1165. }
  1166. };
  1167. /*
  1168. * Global function to determine if SweetAlert2 popup is shown
  1169. */
  1170. var isVisible$1 = function isVisible$$1() {
  1171. return isVisible(getPopup());
  1172. };
  1173. /*
  1174. * Global function to click 'Confirm' button
  1175. */
  1176. var clickConfirm = function clickConfirm() {
  1177. return getConfirmButton() && getConfirmButton().click();
  1178. };
  1179. /*
  1180. * Global function to click 'Cancel' button
  1181. */
  1182. var clickCancel = function clickCancel() {
  1183. return getCancelButton() && getCancelButton().click();
  1184. };
  1185. function fire() {
  1186. var Swal = this;
  1187. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  1188. args[_key] = arguments[_key];
  1189. }
  1190. return _construct(Swal, args);
  1191. }
  1192. /**
  1193. * Returns an extended version of `Swal` containing `params` as defaults.
  1194. * Useful for reusing Swal configuration.
  1195. *
  1196. * For example:
  1197. *
  1198. * Before:
  1199. * const textPromptOptions = { input: 'text', showCancelButton: true }
  1200. * const {value: firstName} = await Swal.fire({ ...textPromptOptions, title: 'What is your first name?' })
  1201. * const {value: lastName} = await Swal.fire({ ...textPromptOptions, title: 'What is your last name?' })
  1202. *
  1203. * After:
  1204. * const TextPrompt = Swal.mixin({ input: 'text', showCancelButton: true })
  1205. * const {value: firstName} = await TextPrompt('What is your first name?')
  1206. * const {value: lastName} = await TextPrompt('What is your last name?')
  1207. *
  1208. * @param mixinParams
  1209. */
  1210. function mixin(mixinParams) {
  1211. var MixinSwal = /*#__PURE__*/function (_this) {
  1212. _inherits(MixinSwal, _this);
  1213. var _super = _createSuper(MixinSwal);
  1214. function MixinSwal() {
  1215. _classCallCheck(this, MixinSwal);
  1216. return _super.apply(this, arguments);
  1217. }
  1218. _createClass(MixinSwal, [{
  1219. key: "_main",
  1220. value: function _main(params) {
  1221. return _get(_getPrototypeOf(MixinSwal.prototype), "_main", this).call(this, _extends({}, mixinParams, params));
  1222. }
  1223. }]);
  1224. return MixinSwal;
  1225. }(this);
  1226. return MixinSwal;
  1227. }
  1228. /**
  1229. * Show spinner instead of Confirm button
  1230. */
  1231. var showLoading = function showLoading() {
  1232. var popup = getPopup();
  1233. if (!popup) {
  1234. Swal.fire();
  1235. }
  1236. popup = getPopup();
  1237. var actions = getActions();
  1238. var confirmButton = getConfirmButton();
  1239. show(actions);
  1240. show(confirmButton, 'inline-block');
  1241. addClass([popup, actions], swalClasses.loading);
  1242. confirmButton.disabled = true;
  1243. popup.setAttribute('data-loading', true);
  1244. popup.setAttribute('aria-busy', true);
  1245. popup.focus();
  1246. };
  1247. var RESTORE_FOCUS_TIMEOUT = 100;
  1248. var globalState = {};
  1249. var focusPreviousActiveElement = function focusPreviousActiveElement() {
  1250. if (globalState.previousActiveElement && globalState.previousActiveElement.focus) {
  1251. globalState.previousActiveElement.focus();
  1252. globalState.previousActiveElement = null;
  1253. } else if (document.body) {
  1254. document.body.focus();
  1255. }
  1256. }; // Restore previous active (focused) element
  1257. var restoreActiveElement = function restoreActiveElement() {
  1258. return new Promise(function (resolve) {
  1259. var x = window.scrollX;
  1260. var y = window.scrollY;
  1261. globalState.restoreFocusTimeout = setTimeout(function () {
  1262. focusPreviousActiveElement();
  1263. resolve();
  1264. }, RESTORE_FOCUS_TIMEOUT); // issues/900
  1265. /* istanbul ignore if */
  1266. if (typeof x !== 'undefined' && typeof y !== 'undefined') {
  1267. // IE doesn't have scrollX/scrollY support
  1268. window.scrollTo(x, y);
  1269. }
  1270. });
  1271. };
  1272. /**
  1273. * If `timer` parameter is set, returns number of milliseconds of timer remained.
  1274. * Otherwise, returns undefined.
  1275. */
  1276. var getTimerLeft = function getTimerLeft() {
  1277. return globalState.timeout && globalState.timeout.getTimerLeft();
  1278. };
  1279. /**
  1280. * Stop timer. Returns number of milliseconds of timer remained.
  1281. * If `timer` parameter isn't set, returns undefined.
  1282. */
  1283. var stopTimer = function stopTimer() {
  1284. if (globalState.timeout) {
  1285. stopTimerProgressBar();
  1286. return globalState.timeout.stop();
  1287. }
  1288. };
  1289. /**
  1290. * Resume timer. Returns number of milliseconds of timer remained.
  1291. * If `timer` parameter isn't set, returns undefined.
  1292. */
  1293. var resumeTimer = function resumeTimer() {
  1294. if (globalState.timeout) {
  1295. var remaining = globalState.timeout.start();
  1296. animateTimerProgressBar(remaining);
  1297. return remaining;
  1298. }
  1299. };
  1300. /**
  1301. * Resume timer. Returns number of milliseconds of timer remained.
  1302. * If `timer` parameter isn't set, returns undefined.
  1303. */
  1304. var toggleTimer = function toggleTimer() {
  1305. var timer = globalState.timeout;
  1306. return timer && (timer.running ? stopTimer() : resumeTimer());
  1307. };
  1308. /**
  1309. * Increase timer. Returns number of milliseconds of an updated timer.
  1310. * If `timer` parameter isn't set, returns undefined.
  1311. */
  1312. var increaseTimer = function increaseTimer(n) {
  1313. if (globalState.timeout) {
  1314. var remaining = globalState.timeout.increase(n);
  1315. animateTimerProgressBar(remaining, true);
  1316. return remaining;
  1317. }
  1318. };
  1319. /**
  1320. * Check if timer is running. Returns true if timer is running
  1321. * or false if timer is paused or stopped.
  1322. * If `timer` parameter isn't set, returns undefined
  1323. */
  1324. var isTimerRunning = function isTimerRunning() {
  1325. return globalState.timeout && globalState.timeout.isRunning();
  1326. };
  1327. var defaultParams = {
  1328. title: '',
  1329. titleText: '',
  1330. text: '',
  1331. html: '',
  1332. footer: '',
  1333. icon: undefined,
  1334. iconHtml: undefined,
  1335. toast: false,
  1336. animation: true,
  1337. showClass: {
  1338. popup: 'swal2-show',
  1339. backdrop: 'swal2-backdrop-show',
  1340. icon: 'swal2-icon-show'
  1341. },
  1342. hideClass: {
  1343. popup: 'swal2-hide',
  1344. backdrop: 'swal2-backdrop-hide',
  1345. icon: 'swal2-icon-hide'
  1346. },
  1347. customClass: undefined,
  1348. target: 'body',
  1349. backdrop: true,
  1350. heightAuto: true,
  1351. allowOutsideClick: true,
  1352. allowEscapeKey: true,
  1353. allowEnterKey: true,
  1354. stopKeydownPropagation: true,
  1355. keydownListenerCapture: false,
  1356. showConfirmButton: true,
  1357. showCancelButton: false,
  1358. preConfirm: undefined,
  1359. confirmButtonText: 'OK',
  1360. confirmButtonAriaLabel: '',
  1361. confirmButtonColor: undefined,
  1362. cancelButtonText: 'Cancel',
  1363. cancelButtonAriaLabel: '',
  1364. cancelButtonColor: undefined,
  1365. buttonsStyling: true,
  1366. reverseButtons: false,
  1367. focusConfirm: true,
  1368. focusCancel: false,
  1369. showCloseButton: false,
  1370. closeButtonHtml: '&times;',
  1371. closeButtonAriaLabel: 'Close this dialog',
  1372. showLoaderOnConfirm: false,
  1373. imageUrl: undefined,
  1374. imageWidth: undefined,
  1375. imageHeight: undefined,
  1376. imageAlt: '',
  1377. timer: undefined,
  1378. timerProgressBar: false,
  1379. width: undefined,
  1380. padding: undefined,
  1381. background: undefined,
  1382. input: undefined,
  1383. inputPlaceholder: '',
  1384. inputValue: '',
  1385. inputOptions: {},
  1386. inputAutoTrim: true,
  1387. inputAttributes: {},
  1388. inputValidator: undefined,
  1389. validationMessage: undefined,
  1390. grow: false,
  1391. position: 'center',
  1392. progressSteps: [],
  1393. currentProgressStep: undefined,
  1394. progressStepsDistance: undefined,
  1395. onBeforeOpen: undefined,
  1396. onOpen: undefined,
  1397. onRender: undefined,
  1398. onClose: undefined,
  1399. onAfterClose: undefined,
  1400. onDestroy: undefined,
  1401. scrollbarPadding: true
  1402. };
  1403. var updatableParams = ['title', 'titleText', 'text', 'html', 'footer', 'icon', 'hideClass', 'customClass', 'allowOutsideClick', 'allowEscapeKey', 'showConfirmButton', 'showCancelButton', 'confirmButtonText', 'confirmButtonAriaLabel', 'confirmButtonColor', 'cancelButtonText', 'cancelButtonAriaLabel', 'cancelButtonColor', 'buttonsStyling', 'reverseButtons', 'imageUrl', 'imageWidth', 'imageHeight', 'imageAlt', 'progressSteps', 'currentProgressStep', 'onClose', 'onAfterClose', 'onDestroy'];
  1404. var deprecatedParams = {
  1405. animation: 'showClass" and "hideClass'
  1406. };
  1407. var toastIncompatibleParams = ['allowOutsideClick', 'allowEnterKey', 'backdrop', 'focusConfirm', 'focusCancel', 'heightAuto', 'keydownListenerCapture'];
  1408. /**
  1409. * Is valid parameter
  1410. * @param {String} paramName
  1411. */
  1412. var isValidParameter = function isValidParameter(paramName) {
  1413. return Object.prototype.hasOwnProperty.call(defaultParams, paramName);
  1414. };
  1415. /**
  1416. * Is valid parameter for Swal.update() method
  1417. * @param {String} paramName
  1418. */
  1419. var isUpdatableParameter = function isUpdatableParameter(paramName) {
  1420. return updatableParams.indexOf(paramName) !== -1;
  1421. };
  1422. /**
  1423. * Is deprecated parameter
  1424. * @param {String} paramName
  1425. */
  1426. var isDeprecatedParameter = function isDeprecatedParameter(paramName) {
  1427. return deprecatedParams[paramName];
  1428. };
  1429. var checkIfParamIsValid = function checkIfParamIsValid(param) {
  1430. if (!isValidParameter(param)) {
  1431. warn("Unknown parameter \"".concat(param, "\""));
  1432. }
  1433. };
  1434. var checkIfToastParamIsValid = function checkIfToastParamIsValid(param) {
  1435. if (toastIncompatibleParams.indexOf(param) !== -1) {
  1436. warn("The parameter \"".concat(param, "\" is incompatible with toasts"));
  1437. }
  1438. };
  1439. var checkIfParamIsDeprecated = function checkIfParamIsDeprecated(param) {
  1440. if (isDeprecatedParameter(param)) {
  1441. warnAboutDepreation(param, isDeprecatedParameter(param));
  1442. }
  1443. };
  1444. /**
  1445. * Show relevant warnings for given params
  1446. *
  1447. * @param params
  1448. */
  1449. var showWarningsForParams = function showWarningsForParams(params) {
  1450. for (var param in params) {
  1451. checkIfParamIsValid(param);
  1452. if (params.toast) {
  1453. checkIfToastParamIsValid(param);
  1454. }
  1455. checkIfParamIsDeprecated(param);
  1456. }
  1457. };
  1458. var staticMethods = /*#__PURE__*/Object.freeze({
  1459. isValidParameter: isValidParameter,
  1460. isUpdatableParameter: isUpdatableParameter,
  1461. isDeprecatedParameter: isDeprecatedParameter,
  1462. argsToParams: argsToParams,
  1463. isVisible: isVisible$1,
  1464. clickConfirm: clickConfirm,
  1465. clickCancel: clickCancel,
  1466. getContainer: getContainer,
  1467. getPopup: getPopup,
  1468. getTitle: getTitle,
  1469. getContent: getContent,
  1470. getHtmlContainer: getHtmlContainer,
  1471. getImage: getImage,
  1472. getIcon: getIcon,
  1473. getIcons: getIcons,
  1474. getCloseButton: getCloseButton,
  1475. getActions: getActions,
  1476. getConfirmButton: getConfirmButton,
  1477. getCancelButton: getCancelButton,
  1478. getHeader: getHeader,
  1479. getFooter: getFooter,
  1480. getTimerProgressBar: getTimerProgressBar,
  1481. getFocusableElements: getFocusableElements,
  1482. getValidationMessage: getValidationMessage,
  1483. isLoading: isLoading,
  1484. fire: fire,
  1485. mixin: mixin,
  1486. queue: queue,
  1487. getQueueStep: getQueueStep,
  1488. insertQueueStep: insertQueueStep,
  1489. deleteQueueStep: deleteQueueStep,
  1490. showLoading: showLoading,
  1491. enableLoading: showLoading,
  1492. getTimerLeft: getTimerLeft,
  1493. stopTimer: stopTimer,
  1494. resumeTimer: resumeTimer,
  1495. toggleTimer: toggleTimer,
  1496. increaseTimer: increaseTimer,
  1497. isTimerRunning: isTimerRunning
  1498. });
  1499. /**
  1500. * Enables buttons and hide loader.
  1501. */
  1502. function hideLoading() {
  1503. // do nothing if popup is closed
  1504. var innerParams = privateProps.innerParams.get(this);
  1505. if (!innerParams) {
  1506. return;
  1507. }
  1508. var domCache = privateProps.domCache.get(this);
  1509. if (!innerParams.showConfirmButton) {
  1510. hide(domCache.confirmButton);
  1511. if (!innerParams.showCancelButton) {
  1512. hide(domCache.actions);
  1513. }
  1514. }
  1515. removeClass([domCache.popup, domCache.actions], swalClasses.loading);
  1516. domCache.popup.removeAttribute('aria-busy');
  1517. domCache.popup.removeAttribute('data-loading');
  1518. domCache.confirmButton.disabled = false;
  1519. domCache.cancelButton.disabled = false;
  1520. }
  1521. function getInput$1(instance) {
  1522. var innerParams = privateProps.innerParams.get(instance || this);
  1523. var domCache = privateProps.domCache.get(instance || this);
  1524. if (!domCache) {
  1525. return null;
  1526. }
  1527. return getInput(domCache.content, innerParams.input);
  1528. }
  1529. var fixScrollbar = function fixScrollbar() {
  1530. // for queues, do not do this more than once
  1531. if (states.previousBodyPadding !== null) {
  1532. return;
  1533. } // if the body has overflow
  1534. if (document.body.scrollHeight > window.innerHeight) {
  1535. // add padding so the content doesn't shift after removal of scrollbar
  1536. states.previousBodyPadding = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right'));
  1537. document.body.style.paddingRight = "".concat(states.previousBodyPadding + measureScrollbar(), "px");
  1538. }
  1539. };
  1540. var undoScrollbar = function undoScrollbar() {
  1541. if (states.previousBodyPadding !== null) {
  1542. document.body.style.paddingRight = "".concat(states.previousBodyPadding, "px");
  1543. states.previousBodyPadding = null;
  1544. }
  1545. };
  1546. /* istanbul ignore file */
  1547. var iOSfix = function iOSfix() {
  1548. var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream || navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1;
  1549. if (iOS && !hasClass(document.body, swalClasses.iosfix)) {
  1550. var offset = document.body.scrollTop;
  1551. document.body.style.top = "".concat(offset * -1, "px");
  1552. addClass(document.body, swalClasses.iosfix);
  1553. lockBodyScroll();
  1554. addBottomPaddingForTallPopups(); // #1948
  1555. }
  1556. };
  1557. var addBottomPaddingForTallPopups = function addBottomPaddingForTallPopups() {
  1558. var safari = !navigator.userAgent.match(/(CriOS|FxiOS|EdgiOS|YaBrowser|UCBrowser)/i);
  1559. if (safari) {
  1560. var bottomPanelHeight = 44;
  1561. if (getPopup().scrollHeight > window.innerHeight - bottomPanelHeight) {
  1562. getContainer().style.paddingBottom = "".concat(bottomPanelHeight, "px");
  1563. }
  1564. }
  1565. };
  1566. var lockBodyScroll = function lockBodyScroll() {
  1567. // #1246
  1568. var container = getContainer();
  1569. var preventTouchMove;
  1570. container.ontouchstart = function (e) {
  1571. preventTouchMove = shouldPreventTouchMove(e.target);
  1572. };
  1573. container.ontouchmove = function (e) {
  1574. if (preventTouchMove) {
  1575. e.preventDefault();
  1576. e.stopPropagation();
  1577. }
  1578. };
  1579. };
  1580. var shouldPreventTouchMove = function shouldPreventTouchMove(target) {
  1581. var container = getContainer();
  1582. if (target === container) {
  1583. return true;
  1584. }
  1585. if (!isScrollable(container) && target.tagName !== 'INPUT' && // #1603
  1586. !(isScrollable(getContent()) && // #1944
  1587. getContent().contains(target))) {
  1588. return true;
  1589. }
  1590. return false;
  1591. };
  1592. var undoIOSfix = function undoIOSfix() {
  1593. if (hasClass(document.body, swalClasses.iosfix)) {
  1594. var offset = parseInt(document.body.style.top, 10);
  1595. removeClass(document.body, swalClasses.iosfix);
  1596. document.body.style.top = '';
  1597. document.body.scrollTop = offset * -1;
  1598. }
  1599. };
  1600. /* istanbul ignore file */
  1601. var isIE11 = function isIE11() {
  1602. return !!window.MSInputMethodContext && !!document.documentMode;
  1603. }; // Fix IE11 centering sweetalert2/issues/933
  1604. var fixVerticalPositionIE = function fixVerticalPositionIE() {
  1605. var container = getContainer();
  1606. var popup = getPopup();
  1607. container.style.removeProperty('align-items');
  1608. if (popup.offsetTop < 0) {
  1609. container.style.alignItems = 'flex-start';
  1610. }
  1611. };
  1612. var IEfix = function IEfix() {
  1613. if (typeof window !== 'undefined' && isIE11()) {
  1614. fixVerticalPositionIE();
  1615. window.addEventListener('resize', fixVerticalPositionIE);
  1616. }
  1617. };
  1618. var undoIEfix = function undoIEfix() {
  1619. if (typeof window !== 'undefined' && isIE11()) {
  1620. window.removeEventListener('resize', fixVerticalPositionIE);
  1621. }
  1622. };
  1623. // Adding aria-hidden="true" to elements outside of the active modal dialog ensures that
  1624. // elements not within the active modal dialog will not be surfaced if a user opens a screen
  1625. // reader’s list of elements (headings, form controls, landmarks, etc.) in the document.
  1626. var setAriaHidden = function setAriaHidden() {
  1627. var bodyChildren = toArray(document.body.children);
  1628. bodyChildren.forEach(function (el) {
  1629. if (el === getContainer() || contains(el, getContainer())) {
  1630. return;
  1631. }
  1632. if (el.hasAttribute('aria-hidden')) {
  1633. el.setAttribute('data-previous-aria-hidden', el.getAttribute('aria-hidden'));
  1634. }
  1635. el.setAttribute('aria-hidden', 'true');
  1636. });
  1637. };
  1638. var unsetAriaHidden = function unsetAriaHidden() {
  1639. var bodyChildren = toArray(document.body.children);
  1640. bodyChildren.forEach(function (el) {
  1641. if (el.hasAttribute('data-previous-aria-hidden')) {
  1642. el.setAttribute('aria-hidden', el.getAttribute('data-previous-aria-hidden'));
  1643. el.removeAttribute('data-previous-aria-hidden');
  1644. } else {
  1645. el.removeAttribute('aria-hidden');
  1646. }
  1647. });
  1648. };
  1649. /**
  1650. * This module containts `WeakMap`s for each effectively-"private property" that a `Swal` has.
  1651. * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')`
  1652. * This is the approach that Babel will probably take to implement private methods/fields
  1653. * https://github.com/tc39/proposal-private-methods
  1654. * https://github.com/babel/babel/pull/7555
  1655. * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module*
  1656. * then we can use that language feature.
  1657. */
  1658. var privateMethods = {
  1659. swalPromiseResolve: new WeakMap()
  1660. };
  1661. /*
  1662. * Instance method to close sweetAlert
  1663. */
  1664. function removePopupAndResetState(instance, container, isToast$$1, onAfterClose) {
  1665. if (isToast$$1) {
  1666. triggerOnAfterCloseAndDispose(instance, onAfterClose);
  1667. } else {
  1668. restoreActiveElement().then(function () {
  1669. return triggerOnAfterCloseAndDispose(instance, onAfterClose);
  1670. });
  1671. globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
  1672. capture: globalState.keydownListenerCapture
  1673. });
  1674. globalState.keydownHandlerAdded = false;
  1675. }
  1676. if (container.parentNode && !document.body.getAttribute('data-swal2-queue-step')) {
  1677. container.parentNode.removeChild(container);
  1678. }
  1679. if (isModal()) {
  1680. undoScrollbar();
  1681. undoIOSfix();
  1682. undoIEfix();
  1683. unsetAriaHidden();
  1684. }
  1685. removeBodyClasses();
  1686. }
  1687. function removeBodyClasses() {
  1688. removeClass([document.documentElement, document.body], [swalClasses.shown, swalClasses['height-auto'], swalClasses['no-backdrop'], swalClasses['toast-shown'], swalClasses['toast-column']]);
  1689. }
  1690. function close(resolveValue) {
  1691. var popup = getPopup();
  1692. if (!popup) {
  1693. return;
  1694. }
  1695. var innerParams = privateProps.innerParams.get(this);
  1696. if (!innerParams || hasClass(popup, innerParams.hideClass.popup)) {
  1697. return;
  1698. }
  1699. var swalPromiseResolve = privateMethods.swalPromiseResolve.get(this);
  1700. removeClass(popup, innerParams.showClass.popup);
  1701. addClass(popup, innerParams.hideClass.popup);
  1702. var backdrop = getContainer();
  1703. removeClass(backdrop, innerParams.showClass.backdrop);
  1704. addClass(backdrop, innerParams.hideClass.backdrop);
  1705. handlePopupAnimation(this, popup, innerParams);
  1706. if (typeof resolveValue !== 'undefined') {
  1707. resolveValue.isDismissed = typeof resolveValue.dismiss !== 'undefined';
  1708. resolveValue.isConfirmed = typeof resolveValue.dismiss === 'undefined';
  1709. } else {
  1710. resolveValue = {
  1711. isDismissed: true,
  1712. isConfirmed: false
  1713. };
  1714. } // Resolve Swal promise
  1715. swalPromiseResolve(resolveValue || {});
  1716. }
  1717. var handlePopupAnimation = function handlePopupAnimation(instance, popup, innerParams) {
  1718. var container = getContainer(); // If animation is supported, animate
  1719. var animationIsSupported = animationEndEvent && hasCssAnimation(popup);
  1720. var onClose = innerParams.onClose,
  1721. onAfterClose = innerParams.onAfterClose;
  1722. if (onClose !== null && typeof onClose === 'function') {
  1723. onClose(popup);
  1724. }
  1725. if (animationIsSupported) {
  1726. animatePopup(instance, popup, container, onAfterClose);
  1727. } else {
  1728. // Otherwise, remove immediately
  1729. removePopupAndResetState(instance, container, isToast(), onAfterClose);
  1730. }
  1731. };
  1732. var animatePopup = function animatePopup(instance, popup, container, onAfterClose) {
  1733. globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(null, instance, container, isToast(), onAfterClose);
  1734. popup.addEventListener(animationEndEvent, function (e) {
  1735. if (e.target === popup) {
  1736. globalState.swalCloseEventFinishedCallback();
  1737. delete globalState.swalCloseEventFinishedCallback;
  1738. }
  1739. });
  1740. };
  1741. var triggerOnAfterCloseAndDispose = function triggerOnAfterCloseAndDispose(instance, onAfterClose) {
  1742. setTimeout(function () {
  1743. if (typeof onAfterClose === 'function') {
  1744. onAfterClose();
  1745. }
  1746. instance._destroy();
  1747. });
  1748. };
  1749. function setButtonsDisabled(instance, buttons, disabled) {
  1750. var domCache = privateProps.domCache.get(instance);
  1751. buttons.forEach(function (button) {
  1752. domCache[button].disabled = disabled;
  1753. });
  1754. }
  1755. function setInputDisabled(input, disabled) {
  1756. if (!input) {
  1757. return false;
  1758. }
  1759. if (input.type === 'radio') {
  1760. var radiosContainer = input.parentNode.parentNode;
  1761. var radios = radiosContainer.querySelectorAll('input');
  1762. for (var i = 0; i < radios.length; i++) {
  1763. radios[i].disabled = disabled;
  1764. }
  1765. } else {
  1766. input.disabled = disabled;
  1767. }
  1768. }
  1769. function enableButtons() {
  1770. setButtonsDisabled(this, ['confirmButton', 'cancelButton'], false);
  1771. }
  1772. function disableButtons() {
  1773. setButtonsDisabled(this, ['confirmButton', 'cancelButton'], true);
  1774. }
  1775. function enableInput() {
  1776. return setInputDisabled(this.getInput(), false);
  1777. }
  1778. function disableInput() {
  1779. return setInputDisabled(this.getInput(), true);
  1780. }
  1781. function showValidationMessage(error) {
  1782. var domCache = privateProps.domCache.get(this);
  1783. setInnerHtml(domCache.validationMessage, error);
  1784. var popupComputedStyle = window.getComputedStyle(domCache.popup);
  1785. domCache.validationMessage.style.marginLeft = "-".concat(popupComputedStyle.getPropertyValue('padding-left'));
  1786. domCache.validationMessage.style.marginRight = "-".concat(popupComputedStyle.getPropertyValue('padding-right'));
  1787. show(domCache.validationMessage);
  1788. var input = this.getInput();
  1789. if (input) {
  1790. input.setAttribute('aria-invalid', true);
  1791. input.setAttribute('aria-describedBy', swalClasses['validation-message']);
  1792. focusInput(input);
  1793. addClass(input, swalClasses.inputerror);
  1794. }
  1795. } // Hide block with validation message
  1796. function resetValidationMessage$1() {
  1797. var domCache = privateProps.domCache.get(this);
  1798. if (domCache.validationMessage) {
  1799. hide(domCache.validationMessage);
  1800. }
  1801. var input = this.getInput();
  1802. if (input) {
  1803. input.removeAttribute('aria-invalid');
  1804. input.removeAttribute('aria-describedBy');
  1805. removeClass(input, swalClasses.inputerror);
  1806. }
  1807. }
  1808. function getProgressSteps$1() {
  1809. var domCache = privateProps.domCache.get(this);
  1810. return domCache.progressSteps;
  1811. }
  1812. var Timer = /*#__PURE__*/function () {
  1813. function Timer(callback, delay) {
  1814. _classCallCheck(this, Timer);
  1815. this.callback = callback;
  1816. this.remaining = delay;
  1817. this.running = false;
  1818. this.start();
  1819. }
  1820. _createClass(Timer, [{
  1821. key: "start",
  1822. value: function start() {
  1823. if (!this.running) {
  1824. this.running = true;
  1825. this.started = new Date();
  1826. this.id = setTimeout(this.callback, this.remaining);
  1827. }
  1828. return this.remaining;
  1829. }
  1830. }, {
  1831. key: "stop",
  1832. value: function stop() {
  1833. if (this.running) {
  1834. this.running = false;
  1835. clearTimeout(this.id);
  1836. this.remaining -= new Date() - this.started;
  1837. }
  1838. return this.remaining;
  1839. }
  1840. }, {
  1841. key: "increase",
  1842. value: function increase(n) {
  1843. var running = this.running;
  1844. if (running) {
  1845. this.stop();
  1846. }
  1847. this.remaining += n;
  1848. if (running) {
  1849. this.start();
  1850. }
  1851. return this.remaining;
  1852. }
  1853. }, {
  1854. key: "getTimerLeft",
  1855. value: function getTimerLeft() {
  1856. if (this.running) {
  1857. this.stop();
  1858. this.start();
  1859. }
  1860. return this.remaining;
  1861. }
  1862. }, {
  1863. key: "isRunning",
  1864. value: function isRunning() {
  1865. return this.running;
  1866. }
  1867. }]);
  1868. return Timer;
  1869. }();
  1870. var defaultInputValidators = {
  1871. email: function email(string, validationMessage) {
  1872. return /^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9-]{2,24}$/.test(string) ? Promise.resolve() : Promise.resolve(validationMessage || 'Invalid email address');
  1873. },
  1874. url: function url(string, validationMessage) {
  1875. // taken from https://stackoverflow.com/a/3809435 with a small change from #1306
  1876. return /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,63}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)$/.test(string) ? Promise.resolve() : Promise.resolve(validationMessage || 'Invalid URL');
  1877. }
  1878. };
  1879. function setDefaultInputValidators(params) {
  1880. // Use default `inputValidator` for supported input types if not provided
  1881. if (!params.inputValidator) {
  1882. Object.keys(defaultInputValidators).forEach(function (key) {
  1883. if (params.input === key) {
  1884. params.inputValidator = defaultInputValidators[key];
  1885. }
  1886. });
  1887. }
  1888. }
  1889. function validateCustomTargetElement(params) {
  1890. // Determine if the custom target element is valid
  1891. if (!params.target || typeof params.target === 'string' && !document.querySelector(params.target) || typeof params.target !== 'string' && !params.target.appendChild) {
  1892. warn('Target parameter is not valid, defaulting to "body"');
  1893. params.target = 'body';
  1894. }
  1895. }
  1896. /**
  1897. * Set type, text and actions on popup
  1898. *
  1899. * @param params
  1900. * @returns {boolean}
  1901. */
  1902. function setParameters(params) {
  1903. setDefaultInputValidators(params); // showLoaderOnConfirm && preConfirm
  1904. if (params.showLoaderOnConfirm && !params.preConfirm) {
  1905. warn('showLoaderOnConfirm is set to true, but preConfirm is not defined.\n' + 'showLoaderOnConfirm should be used together with preConfirm, see usage example:\n' + 'https://sweetalert2.github.io/#ajax-request');
  1906. } // params.animation will be actually used in renderPopup.js
  1907. // but in case when params.animation is a function, we need to call that function
  1908. // before popup (re)initialization, so it'll be possible to check Swal.isVisible()
  1909. // inside the params.animation function
  1910. params.animation = callIfFunction(params.animation);
  1911. validateCustomTargetElement(params); // Replace newlines with <br> in title
  1912. if (typeof params.title === 'string') {
  1913. params.title = params.title.split('\n').join('<br />');
  1914. }
  1915. init(params);
  1916. }
  1917. /**
  1918. * Open popup, add necessary classes and styles, fix scrollbar
  1919. *
  1920. * @param {Array} params
  1921. */
  1922. var openPopup = function openPopup(params) {
  1923. var container = getContainer();
  1924. var popup = getPopup();
  1925. if (typeof params.onBeforeOpen === 'function') {
  1926. params.onBeforeOpen(popup);
  1927. }
  1928. var bodyStyles = window.getComputedStyle(document.body);
  1929. var initialBodyOverflow = bodyStyles.overflowY;
  1930. addClasses$1(container, popup, params); // scrolling is 'hidden' until animation is done, after that 'auto'
  1931. setScrollingVisibility(container, popup);
  1932. if (isModal()) {
  1933. fixScrollContainer(container, params.scrollbarPadding, initialBodyOverflow);
  1934. setAriaHidden();
  1935. }
  1936. if (!isToast() && !globalState.previousActiveElement) {
  1937. globalState.previousActiveElement = document.activeElement;
  1938. }
  1939. if (typeof params.onOpen === 'function') {
  1940. setTimeout(function () {
  1941. return params.onOpen(popup);
  1942. });
  1943. }
  1944. removeClass(container, swalClasses['no-transition']);
  1945. };
  1946. function swalOpenAnimationFinished(event) {
  1947. var popup = getPopup();
  1948. if (event.target !== popup) {
  1949. return;
  1950. }
  1951. var container = getContainer();
  1952. popup.removeEventListener(animationEndEvent, swalOpenAnimationFinished);
  1953. container.style.overflowY = 'auto';
  1954. }
  1955. var setScrollingVisibility = function setScrollingVisibility(container, popup) {
  1956. if (animationEndEvent && hasCssAnimation(popup)) {
  1957. container.style.overflowY = 'hidden';
  1958. popup.addEventListener(animationEndEvent, swalOpenAnimationFinished);
  1959. } else {
  1960. container.style.overflowY = 'auto';
  1961. }
  1962. };
  1963. var fixScrollContainer = function fixScrollContainer(container, scrollbarPadding, initialBodyOverflow) {
  1964. iOSfix();
  1965. IEfix();
  1966. if (scrollbarPadding && initialBodyOverflow !== 'hidden') {
  1967. fixScrollbar();
  1968. } // sweetalert2/issues/1247
  1969. setTimeout(function () {
  1970. container.scrollTop = 0;
  1971. });
  1972. };
  1973. var addClasses$1 = function addClasses(container, popup, params) {
  1974. addClass(container, params.showClass.backdrop);
  1975. show(popup); // Animate popup right after showing it
  1976. addClass(popup, params.showClass.popup);
  1977. addClass([document.documentElement, document.body], swalClasses.shown);
  1978. if (params.heightAuto && params.backdrop && !params.toast) {
  1979. addClass([document.documentElement, document.body], swalClasses['height-auto']);
  1980. }
  1981. };
  1982. var handleInputOptionsAndValue = function handleInputOptionsAndValue(instance, params) {
  1983. if (params.input === 'select' || params.input === 'radio') {
  1984. handleInputOptions(instance, params);
  1985. } else if (['text', 'email', 'number', 'tel', 'textarea'].indexOf(params.input) !== -1 && (hasToPromiseFn(params.inputValue) || isPromise(params.inputValue))) {
  1986. handleInputValue(instance, params);
  1987. }
  1988. };
  1989. var getInputValue = function getInputValue(instance, innerParams) {
  1990. var input = instance.getInput();
  1991. if (!input) {
  1992. return null;
  1993. }
  1994. switch (innerParams.input) {
  1995. case 'checkbox':
  1996. return getCheckboxValue(input);
  1997. case 'radio':
  1998. return getRadioValue(input);
  1999. case 'file':
  2000. return getFileValue(input);
  2001. default:
  2002. return innerParams.inputAutoTrim ? input.value.trim() : input.value;
  2003. }
  2004. };
  2005. var getCheckboxValue = function getCheckboxValue(input) {
  2006. return input.checked ? 1 : 0;
  2007. };
  2008. var getRadioValue = function getRadioValue(input) {
  2009. return input.checked ? input.value : null;
  2010. };
  2011. var getFileValue = function getFileValue(input) {
  2012. return input.files.length ? input.getAttribute('multiple') !== null ? input.files : input.files[0] : null;
  2013. };
  2014. var handleInputOptions = function handleInputOptions(instance, params) {
  2015. var content = getContent();
  2016. var processInputOptions = function processInputOptions(inputOptions) {
  2017. return populateInputOptions[params.input](content, formatInputOptions(inputOptions), params);
  2018. };
  2019. if (hasToPromiseFn(params.inputOptions) || isPromise(params.inputOptions)) {
  2020. showLoading();
  2021. asPromise(params.inputOptions).then(function (inputOptions) {
  2022. instance.hideLoading();
  2023. processInputOptions(inputOptions);
  2024. });
  2025. } else if (_typeof(params.inputOptions) === 'object') {
  2026. processInputOptions(params.inputOptions);
  2027. } else {
  2028. error("Unexpected type of inputOptions! Expected object, Map or Promise, got ".concat(_typeof(params.inputOptions)));
  2029. }
  2030. };
  2031. var handleInputValue = function handleInputValue(instance, params) {
  2032. var input = instance.getInput();
  2033. hide(input);
  2034. asPromise(params.inputValue).then(function (inputValue) {
  2035. input.value = params.input === 'number' ? parseFloat(inputValue) || 0 : "".concat(inputValue);
  2036. show(input);
  2037. input.focus();
  2038. instance.hideLoading();
  2039. })["catch"](function (err) {
  2040. error("Error in inputValue promise: ".concat(err));
  2041. input.value = '';
  2042. show(input);
  2043. input.focus();
  2044. instance.hideLoading();
  2045. });
  2046. };
  2047. var populateInputOptions = {
  2048. select: function select(content, inputOptions, params) {
  2049. var select = getChildByClass(content, swalClasses.select);
  2050. var renderOption = function renderOption(parent, optionLabel, optionValue) {
  2051. var option = document.createElement('option');
  2052. option.value = optionValue;
  2053. setInnerHtml(option, optionLabel);
  2054. if (params.inputValue.toString() === optionValue.toString()) {
  2055. option.selected = true;
  2056. }
  2057. parent.appendChild(option);
  2058. };
  2059. inputOptions.forEach(function (inputOption) {
  2060. var optionValue = inputOption[0];
  2061. var optionLabel = inputOption[1]; // <optgroup> spec:
  2062. // https://www.w3.org/TR/html401/interact/forms.html#h-17.6
  2063. // "...all OPTGROUP elements must be specified directly within a SELECT element (i.e., groups may not be nested)..."
  2064. // check whether this is a <optgroup>
  2065. if (Array.isArray(optionLabel)) {
  2066. // if it is an array, then it is an <optgroup>
  2067. var optgroup = document.createElement('optgroup');
  2068. optgroup.label = optionValue;
  2069. optgroup.disabled = false; // not configurable for now
  2070. select.appendChild(optgroup);
  2071. optionLabel.forEach(function (o) {
  2072. return renderOption(optgroup, o[1], o[0]);
  2073. });
  2074. } else {
  2075. // case of <option>
  2076. renderOption(select, optionLabel, optionValue);
  2077. }
  2078. });
  2079. select.focus();
  2080. },
  2081. radio: function radio(content, inputOptions, params) {
  2082. var radio = getChildByClass(content, swalClasses.radio);
  2083. inputOptions.forEach(function (inputOption) {
  2084. var radioValue = inputOption[0];
  2085. var radioLabel = inputOption[1];
  2086. var radioInput = document.createElement('input');
  2087. var radioLabelElement = document.createElement('label');
  2088. radioInput.type = 'radio';
  2089. radioInput.name = swalClasses.radio;
  2090. radioInput.value = radioValue;
  2091. if (params.inputValue.toString() === radioValue.toString()) {
  2092. radioInput.checked = true;
  2093. }
  2094. var label = document.createElement('span');
  2095. setInnerHtml(label, radioLabel);
  2096. label.className = swalClasses.label;
  2097. radioLabelElement.appendChild(radioInput);
  2098. radioLabelElement.appendChild(label);
  2099. radio.appendChild(radioLabelElement);
  2100. });
  2101. var radios = radio.querySelectorAll('input');
  2102. if (radios.length) {
  2103. radios[0].focus();
  2104. }
  2105. }
  2106. };
  2107. /**
  2108. * Converts `inputOptions` into an array of `[value, label]`s
  2109. * @param inputOptions
  2110. */
  2111. var formatInputOptions = function formatInputOptions(inputOptions) {
  2112. var result = [];
  2113. if (typeof Map !== 'undefined' && inputOptions instanceof Map) {
  2114. inputOptions.forEach(function (value, key) {
  2115. var valueFormatted = value;
  2116. if (_typeof(valueFormatted) === 'object') {
  2117. // case of <optgroup>
  2118. valueFormatted = formatInputOptions(valueFormatted);
  2119. }
  2120. result.push([key, valueFormatted]);
  2121. });
  2122. } else {
  2123. Object.keys(inputOptions).forEach(function (key) {
  2124. var valueFormatted = inputOptions[key];
  2125. if (_typeof(valueFormatted) === 'object') {
  2126. // case of <optgroup>
  2127. valueFormatted = formatInputOptions(valueFormatted);
  2128. }
  2129. result.push([key, valueFormatted]);
  2130. });
  2131. }
  2132. return result;
  2133. };
  2134. var handleConfirmButtonClick = function handleConfirmButtonClick(instance, innerParams) {
  2135. instance.disableButtons();
  2136. if (innerParams.input) {
  2137. handleConfirmWithInput(instance, innerParams);
  2138. } else {
  2139. confirm(instance, innerParams, true);
  2140. }
  2141. };
  2142. var handleCancelButtonClick = function handleCancelButtonClick(instance, dismissWith) {
  2143. instance.disableButtons();
  2144. dismissWith(DismissReason.cancel);
  2145. };
  2146. var handleConfirmWithInput = function handleConfirmWithInput(instance, innerParams) {
  2147. var inputValue = getInputValue(instance, innerParams);
  2148. if (innerParams.inputValidator) {
  2149. instance.disableInput();
  2150. var validationPromise = Promise.resolve().then(function () {
  2151. return asPromise(innerParams.inputValidator(inputValue, innerParams.validationMessage));
  2152. });
  2153. validationPromise.then(function (validationMessage) {
  2154. instance.enableButtons();
  2155. instance.enableInput();
  2156. if (validationMessage) {
  2157. instance.showValidationMessage(validationMessage);
  2158. } else {
  2159. confirm(instance, innerParams, inputValue);
  2160. }
  2161. });
  2162. } else if (!instance.getInput().checkValidity()) {
  2163. instance.enableButtons();
  2164. instance.showValidationMessage(innerParams.validationMessage);
  2165. } else {
  2166. confirm(instance, innerParams, inputValue);
  2167. }
  2168. };
  2169. var succeedWith = function succeedWith(instance, value) {
  2170. instance.closePopup({
  2171. value: value
  2172. });
  2173. };
  2174. var confirm = function confirm(instance, innerParams, value) {
  2175. if (innerParams.showLoaderOnConfirm) {
  2176. showLoading(); // TODO: make showLoading an *instance* method
  2177. }
  2178. if (innerParams.preConfirm) {
  2179. instance.resetValidationMessage();
  2180. var preConfirmPromise = Promise.resolve().then(function () {
  2181. return asPromise(innerParams.preConfirm(value, innerParams.validationMessage));
  2182. });
  2183. preConfirmPromise.then(function (preConfirmValue) {
  2184. if (isVisible(getValidationMessage()) || preConfirmValue === false) {
  2185. instance.hideLoading();
  2186. } else {
  2187. succeedWith(instance, typeof preConfirmValue === 'undefined' ? value : preConfirmValue);
  2188. }
  2189. });
  2190. } else {
  2191. succeedWith(instance, value);
  2192. }
  2193. };
  2194. var addKeydownHandler = function addKeydownHandler(instance, globalState, innerParams, dismissWith) {
  2195. if (globalState.keydownTarget && globalState.keydownHandlerAdded) {
  2196. globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
  2197. capture: globalState.keydownListenerCapture
  2198. });
  2199. globalState.keydownHandlerAdded = false;
  2200. }
  2201. if (!innerParams.toast) {
  2202. globalState.keydownHandler = function (e) {
  2203. return keydownHandler(instance, e, dismissWith);
  2204. };
  2205. globalState.keydownTarget = innerParams.keydownListenerCapture ? window : getPopup();
  2206. globalState.keydownListenerCapture = innerParams.keydownListenerCapture;
  2207. globalState.keydownTarget.addEventListener('keydown', globalState.keydownHandler, {
  2208. capture: globalState.keydownListenerCapture
  2209. });
  2210. globalState.keydownHandlerAdded = true;
  2211. }
  2212. }; // Focus handling
  2213. var setFocus = function setFocus(innerParams, index, increment) {
  2214. var focusableElements = getFocusableElements(); // search for visible elements and select the next possible match
  2215. for (var i = 0; i < focusableElements.length; i++) {
  2216. index = index + increment; // rollover to first item
  2217. if (index === focusableElements.length) {
  2218. index = 0; // go to last item
  2219. } else if (index === -1) {
  2220. index = focusableElements.length - 1;
  2221. }
  2222. return focusableElements[index].focus();
  2223. } // no visible focusable elements, focus the popup
  2224. getPopup().focus();
  2225. };
  2226. var arrowKeys = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Left', 'Right', 'Up', 'Down' // IE11
  2227. ];
  2228. var escKeys = ['Escape', 'Esc' // IE11
  2229. ];
  2230. var keydownHandler = function keydownHandler(instance, e, dismissWith) {
  2231. var innerParams = privateProps.innerParams.get(instance);
  2232. if (innerParams.stopKeydownPropagation) {
  2233. e.stopPropagation();
  2234. } // ENTER
  2235. if (e.key === 'Enter') {
  2236. handleEnter(instance, e, innerParams); // TAB
  2237. } else if (e.key === 'Tab') {
  2238. handleTab(e, innerParams); // ARROWS - switch focus between buttons
  2239. } else if (arrowKeys.indexOf(e.key) !== -1) {
  2240. handleArrows(); // ESC
  2241. } else if (escKeys.indexOf(e.key) !== -1) {
  2242. handleEsc(e, innerParams, dismissWith);
  2243. }
  2244. };
  2245. var handleEnter = function handleEnter(instance, e, innerParams) {
  2246. // #720 #721
  2247. if (e.isComposing) {
  2248. return;
  2249. }
  2250. if (e.target && instance.getInput() && e.target.outerHTML === instance.getInput().outerHTML) {
  2251. if (['textarea', 'file'].indexOf(innerParams.input) !== -1) {
  2252. return; // do not submit
  2253. }
  2254. clickConfirm();
  2255. e.preventDefault();
  2256. }
  2257. };
  2258. var handleTab = function handleTab(e, innerParams) {
  2259. var targetElement = e.target;
  2260. var focusableElements = getFocusableElements();
  2261. var btnIndex = -1;
  2262. for (var i = 0; i < focusableElements.length; i++) {
  2263. if (targetElement === focusableElements[i]) {
  2264. btnIndex = i;
  2265. break;
  2266. }
  2267. }
  2268. if (!e.shiftKey) {
  2269. // Cycle to the next button
  2270. setFocus(innerParams, btnIndex, 1);
  2271. } else {
  2272. // Cycle to the prev button
  2273. setFocus(innerParams, btnIndex, -1);
  2274. }
  2275. e.stopPropagation();
  2276. e.preventDefault();
  2277. };
  2278. var handleArrows = function handleArrows() {
  2279. var confirmButton = getConfirmButton();
  2280. var cancelButton = getCancelButton(); // focus Cancel button if Confirm button is currently focused
  2281. if (document.activeElement === confirmButton && isVisible(cancelButton)) {
  2282. cancelButton.focus(); // and vice versa
  2283. } else if (document.activeElement === cancelButton && isVisible(confirmButton)) {
  2284. confirmButton.focus();
  2285. }
  2286. };
  2287. var handleEsc = function handleEsc(e, innerParams, dismissWith) {
  2288. if (callIfFunction(innerParams.allowEscapeKey)) {
  2289. e.preventDefault();
  2290. dismissWith(DismissReason.esc);
  2291. }
  2292. };
  2293. var handlePopupClick = function handlePopupClick(instance, domCache, dismissWith) {
  2294. var innerParams = privateProps.innerParams.get(instance);
  2295. if (innerParams.toast) {
  2296. handleToastClick(instance, domCache, dismissWith);
  2297. } else {
  2298. // Ignore click events that had mousedown on the popup but mouseup on the container
  2299. // This can happen when the user drags a slider
  2300. handleModalMousedown(domCache); // Ignore click events that had mousedown on the container but mouseup on the popup
  2301. handleContainerMousedown(domCache);
  2302. handleModalClick(instance, domCache, dismissWith);
  2303. }
  2304. };
  2305. var handleToastClick = function handleToastClick(instance, domCache, dismissWith) {
  2306. // Closing toast by internal click
  2307. domCache.popup.onclick = function () {
  2308. var innerParams = privateProps.innerParams.get(instance);
  2309. if (innerParams.showConfirmButton || innerParams.showCancelButton || innerParams.showCloseButton || innerParams.input) {
  2310. return;
  2311. }
  2312. dismissWith(DismissReason.close);
  2313. };
  2314. };
  2315. var ignoreOutsideClick = false;
  2316. var handleModalMousedown = function handleModalMousedown(domCache) {
  2317. domCache.popup.onmousedown = function () {
  2318. domCache.container.onmouseup = function (e) {
  2319. domCache.container.onmouseup = undefined; // We only check if the mouseup target is the container because usually it doesn't
  2320. // have any other direct children aside of the popup
  2321. if (e.target === domCache.container) {
  2322. ignoreOutsideClick = true;
  2323. }
  2324. };
  2325. };
  2326. };
  2327. var handleContainerMousedown = function handleContainerMousedown(domCache) {
  2328. domCache.container.onmousedown = function () {
  2329. domCache.popup.onmouseup = function (e) {
  2330. domCache.popup.onmouseup = undefined; // We also need to check if the mouseup target is a child of the popup
  2331. if (e.target === domCache.popup || domCache.popup.contains(e.target)) {
  2332. ignoreOutsideClick = true;
  2333. }
  2334. };
  2335. };
  2336. };
  2337. var handleModalClick = function handleModalClick(instance, domCache, dismissWith) {
  2338. domCache.container.onclick = function (e) {
  2339. var innerParams = privateProps.innerParams.get(instance);
  2340. if (ignoreOutsideClick) {
  2341. ignoreOutsideClick = false;
  2342. return;
  2343. }
  2344. if (e.target === domCache.container && callIfFunction(innerParams.allowOutsideClick)) {
  2345. dismissWith(DismissReason.backdrop);
  2346. }
  2347. };
  2348. };
  2349. function _main(userParams) {
  2350. showWarningsForParams(userParams);
  2351. if (globalState.currentInstance) {
  2352. globalState.currentInstance._destroy();
  2353. }
  2354. globalState.currentInstance = this;
  2355. var innerParams = prepareParams(userParams);
  2356. setParameters(innerParams);
  2357. Object.freeze(innerParams); // clear the previous timer
  2358. if (globalState.timeout) {
  2359. globalState.timeout.stop();
  2360. delete globalState.timeout;
  2361. } // clear the restore focus timeout
  2362. clearTimeout(globalState.restoreFocusTimeout);
  2363. var domCache = populateDomCache(this);
  2364. render(this, innerParams);
  2365. privateProps.innerParams.set(this, innerParams);
  2366. return swalPromise(this, domCache, innerParams);
  2367. }
  2368. var prepareParams = function prepareParams(userParams) {
  2369. var showClass = _extends({}, defaultParams.showClass, userParams.showClass);
  2370. var hideClass = _extends({}, defaultParams.hideClass, userParams.hideClass);
  2371. var params = _extends({}, defaultParams, userParams);
  2372. params.showClass = showClass;
  2373. params.hideClass = hideClass; // @deprecated
  2374. if (userParams.animation === false) {
  2375. params.showClass = {
  2376. popup: 'swal2-noanimation',
  2377. backdrop: 'swal2-noanimation'
  2378. };
  2379. params.hideClass = {};
  2380. }
  2381. return params;
  2382. };
  2383. var swalPromise = function swalPromise(instance, domCache, innerParams) {
  2384. return new Promise(function (resolve) {
  2385. // functions to handle all closings/dismissals
  2386. var dismissWith = function dismissWith(dismiss) {
  2387. instance.closePopup({
  2388. dismiss: dismiss
  2389. });
  2390. };
  2391. privateMethods.swalPromiseResolve.set(instance, resolve);
  2392. domCache.confirmButton.onclick = function () {
  2393. return handleConfirmButtonClick(instance, innerParams);
  2394. };
  2395. domCache.cancelButton.onclick = function () {
  2396. return handleCancelButtonClick(instance, dismissWith);
  2397. };
  2398. domCache.closeButton.onclick = function () {
  2399. return dismissWith(DismissReason.close);
  2400. };
  2401. handlePopupClick(instance, domCache, dismissWith);
  2402. addKeydownHandler(instance, globalState, innerParams, dismissWith);
  2403. if (innerParams.toast && (innerParams.input || innerParams.footer || innerParams.showCloseButton)) {
  2404. addClass(document.body, swalClasses['toast-column']);
  2405. } else {
  2406. removeClass(document.body, swalClasses['toast-column']);
  2407. }
  2408. handleInputOptionsAndValue(instance, innerParams);
  2409. openPopup(innerParams);
  2410. setupTimer(globalState, innerParams, dismissWith);
  2411. initFocus(domCache, innerParams); // Scroll container to top on open (#1247, #1946)
  2412. setTimeout(function () {
  2413. domCache.container.scrollTop = 0;
  2414. });
  2415. });
  2416. };
  2417. var populateDomCache = function populateDomCache(instance) {
  2418. var domCache = {
  2419. popup: getPopup(),
  2420. container: getContainer(),
  2421. content: getContent(),
  2422. actions: getActions(),
  2423. confirmButton: getConfirmButton(),
  2424. cancelButton: getCancelButton(),
  2425. closeButton: getCloseButton(),
  2426. validationMessage: getValidationMessage(),
  2427. progressSteps: getProgressSteps()
  2428. };
  2429. privateProps.domCache.set(instance, domCache);
  2430. return domCache;
  2431. };
  2432. var setupTimer = function setupTimer(globalState$$1, innerParams, dismissWith) {
  2433. var timerProgressBar = getTimerProgressBar();
  2434. hide(timerProgressBar);
  2435. if (innerParams.timer) {
  2436. globalState$$1.timeout = new Timer(function () {
  2437. dismissWith('timer');
  2438. delete globalState$$1.timeout;
  2439. }, innerParams.timer);
  2440. if (innerParams.timerProgressBar) {
  2441. show(timerProgressBar);
  2442. setTimeout(function () {
  2443. if (globalState$$1.timeout.running) {
  2444. // timer can be already stopped at this point
  2445. animateTimerProgressBar(innerParams.timer);
  2446. }
  2447. });
  2448. }
  2449. }
  2450. };
  2451. var initFocus = function initFocus(domCache, innerParams) {
  2452. if (innerParams.toast) {
  2453. return;
  2454. }
  2455. if (!callIfFunction(innerParams.allowEnterKey)) {
  2456. return blurActiveElement();
  2457. }
  2458. if (innerParams.focusCancel && isVisible(domCache.cancelButton)) {
  2459. return domCache.cancelButton.focus();
  2460. }
  2461. if (innerParams.focusConfirm && isVisible(domCache.confirmButton)) {
  2462. return domCache.confirmButton.focus();
  2463. }
  2464. setFocus(innerParams, -1, 1);
  2465. };
  2466. var blurActiveElement = function blurActiveElement() {
  2467. if (document.activeElement && typeof document.activeElement.blur === 'function') {
  2468. document.activeElement.blur();
  2469. }
  2470. };
  2471. /**
  2472. * Updates popup parameters.
  2473. */
  2474. function update(params) {
  2475. var popup = getPopup();
  2476. var innerParams = privateProps.innerParams.get(this);
  2477. if (!popup || hasClass(popup, innerParams.hideClass.popup)) {
  2478. return warn("You're trying to update the closed or closing popup, that won't work. Use the update() method in preConfirm parameter or show a new popup.");
  2479. }
  2480. var validUpdatableParams = {}; // assign valid params from `params` to `defaults`
  2481. Object.keys(params).forEach(function (param) {
  2482. if (Swal.isUpdatableParameter(param)) {
  2483. validUpdatableParams[param] = params[param];
  2484. } else {
  2485. warn("Invalid parameter to update: \"".concat(param, "\". Updatable params are listed here: https://github.com/sweetalert2/sweetalert2/blob/master/src/utils/params.js"));
  2486. }
  2487. });
  2488. var updatedParams = _extends({}, innerParams, validUpdatableParams);
  2489. render(this, updatedParams);
  2490. privateProps.innerParams.set(this, updatedParams);
  2491. Object.defineProperties(this, {
  2492. params: {
  2493. value: _extends({}, this.params, params),
  2494. writable: false,
  2495. enumerable: true
  2496. }
  2497. });
  2498. }
  2499. function _destroy() {
  2500. var domCache = privateProps.domCache.get(this);
  2501. var innerParams = privateProps.innerParams.get(this);
  2502. if (!innerParams) {
  2503. return; // This instance has already been destroyed
  2504. } // Check if there is another Swal closing
  2505. if (domCache.popup && globalState.swalCloseEventFinishedCallback) {
  2506. globalState.swalCloseEventFinishedCallback();
  2507. delete globalState.swalCloseEventFinishedCallback;
  2508. } // Check if there is a swal disposal defer timer
  2509. if (globalState.deferDisposalTimer) {
  2510. clearTimeout(globalState.deferDisposalTimer);
  2511. delete globalState.deferDisposalTimer;
  2512. }
  2513. if (typeof innerParams.onDestroy === 'function') {
  2514. innerParams.onDestroy();
  2515. }
  2516. disposeSwal(this);
  2517. }
  2518. var disposeSwal = function disposeSwal(instance) {
  2519. // Unset this.params so GC will dispose it (#1569)
  2520. delete instance.params; // Unset globalState props so GC will dispose globalState (#1569)
  2521. delete globalState.keydownHandler;
  2522. delete globalState.keydownTarget; // Unset WeakMaps so GC will be able to dispose them (#1569)
  2523. unsetWeakMaps(privateProps);
  2524. unsetWeakMaps(privateMethods);
  2525. };
  2526. var unsetWeakMaps = function unsetWeakMaps(obj) {
  2527. for (var i in obj) {
  2528. obj[i] = new WeakMap();
  2529. }
  2530. };
  2531. var instanceMethods = /*#__PURE__*/Object.freeze({
  2532. hideLoading: hideLoading,
  2533. disableLoading: hideLoading,
  2534. getInput: getInput$1,
  2535. close: close,
  2536. closePopup: close,
  2537. closeModal: close,
  2538. closeToast: close,
  2539. enableButtons: enableButtons,
  2540. disableButtons: disableButtons,
  2541. enableInput: enableInput,
  2542. disableInput: disableInput,
  2543. showValidationMessage: showValidationMessage,
  2544. resetValidationMessage: resetValidationMessage$1,
  2545. getProgressSteps: getProgressSteps$1,
  2546. _main: _main,
  2547. update: update,
  2548. _destroy: _destroy
  2549. });
  2550. var currentInstance;
  2551. var SweetAlert = /*#__PURE__*/function () {
  2552. function SweetAlert() {
  2553. _classCallCheck(this, SweetAlert);
  2554. // Prevent run in Node env
  2555. if (typeof window === 'undefined') {
  2556. return;
  2557. } // Check for the existence of Promise
  2558. if (typeof Promise === 'undefined') {
  2559. error('This package requires a Promise library, please include a shim to enable it in this browser (See: https://github.com/sweetalert2/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2#1-ie-support)');
  2560. }
  2561. currentInstance = this;
  2562. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  2563. args[_key] = arguments[_key];
  2564. }
  2565. var outerParams = Object.freeze(this.constructor.argsToParams(args));
  2566. Object.defineProperties(this, {
  2567. params: {
  2568. value: outerParams,
  2569. writable: false,
  2570. enumerable: true,
  2571. configurable: true
  2572. }
  2573. });
  2574. var promise = this._main(this.params);
  2575. privateProps.promise.set(this, promise);
  2576. } // `catch` cannot be the name of a module export, so we define our thenable methods here instead
  2577. _createClass(SweetAlert, [{
  2578. key: "then",
  2579. value: function then(onFulfilled) {
  2580. var promise = privateProps.promise.get(this);
  2581. return promise.then(onFulfilled);
  2582. }
  2583. }, {
  2584. key: "finally",
  2585. value: function _finally(onFinally) {
  2586. var promise = privateProps.promise.get(this);
  2587. return promise["finally"](onFinally);
  2588. }
  2589. }]);
  2590. return SweetAlert;
  2591. }(); // Assign instance methods from src/instanceMethods/*.js to prototype
  2592. _extends(SweetAlert.prototype, instanceMethods); // Assign static methods from src/staticMethods/*.js to constructor
  2593. _extends(SweetAlert, staticMethods); // Proxy to instance methods to constructor, for now, for backwards compatibility
  2594. Object.keys(instanceMethods).forEach(function (key) {
  2595. SweetAlert[key] = function () {
  2596. if (currentInstance) {
  2597. var _currentInstance;
  2598. return (_currentInstance = currentInstance)[key].apply(_currentInstance, arguments);
  2599. }
  2600. };
  2601. });
  2602. SweetAlert.DismissReason = DismissReason;
  2603. SweetAlert.version = '9.15.2';
  2604. var Swal = SweetAlert;
  2605. Swal["default"] = Swal;
  2606. return Swal;
  2607. }));
  2608. if (typeof this !== 'undefined' && this.Sweetalert2){ this.swal = this.sweetAlert = this.Swal = this.SweetAlert = this.Sweetalert2}