dromo-uploader-js 2.9.0 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).DromoUploader=t()}(this,function(){"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};function t(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,c)}a((r=r.apply(e,t||[])).next())})}function n(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=c(0),s.throw=c(1),s.return=c(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,c[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=t.call(e,i)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}"function"==typeof SuppressedError&&SuppressedError;var r,o,i,s,c,a,u={IFRAME_URL:"https://widget.dromo.io/"}.IFRAME_URL;!function(e){e.INIT_IFRAME="INIT_IFRAME"}(r||(r={})),function(e){e.Call="call",e.Reply="reply",e.Syn="syn",e.SynAck="synAck",e.Ack="ack"}(o||(o={})),function(e){e.Fulfilled="fulfilled",e.Rejected="rejected"}(i||(i={})),function(e){e.ConnectionDestroyed="ConnectionDestroyed",e.ConnectionTimeout="ConnectionTimeout",e.NotInIframe="NotInIframe",e.NoIframeSrc="NoIframeSrc"}(s||(s={})),function(e){e.DataCloneError="DataCloneError"}(c||(c={})),function(e){e.Message="message"}(a||(a={}));const l={"http:":"80","https:":"443"},d=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,h=["file:","data:"];const f=({name:e,message:t,stack:n})=>({name:e,message:t,stack:n});let p=0;var m=()=>++p,v=(e,t,n,r,c)=>{const{localName:u,local:l,remote:d,originForSending:h,originForReceiving:f}=t;let p=!1;c(`${u}: Connecting call sender`);const v=e=>(...t)=>{let n;c(`${u}: Sending ${e}() call`);try{d.closed&&(n=!0)}catch(e){n=!0}if(n&&r(),p){const t=new Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=s.ConnectionDestroyed,t}return new Promise((n,r)=>{const s=m(),p=t=>{if(t.source!==d||t.data.penpal!==o.Reply||t.data.id!==s)return;if(t.origin!==f)return void c(`${u} received message from origin ${t.origin} which did not match expected origin ${f}`);const h=t.data;c(`${u}: Received ${e}() reply`),l.removeEventListener(a.Message,p);let m=h.returnValue;h.returnValueIsError&&(m=(e=>{const t=new Error;return Object.keys(e).forEach(n=>t[n]=e[n]),t})(m)),(h.resolution===i.Fulfilled?n:r)(m)};l.addEventListener(a.Message,p);const v={penpal:o.Call,id:s,methodName:e,args:t};d.postMessage(v,h)})};return n.reduce((e,t)=>(e[t]=v(t),e),e),()=>{p=!0}},w=(e,t,n,r,s)=>{const{destroy:u,onDestroy:l}=r;let d,h;const p={};return r=>{if(r.origin!==t)return void s(`Parent: Handshake - Received ACK message from origin ${r.origin} which did not match expected origin ${t}`);s("Parent: Handshake - Received ACK");const m={localName:"Parent",local:window,remote:r.source,originForSending:n,originForReceiving:t};d&&d(),d=((e,t,n)=>{const{localName:r,local:s,remote:u,originForSending:l,originForReceiving:d}=e;let h=!1;const p=e=>{if(e.source!==u||e.data.penpal!==o.Call)return;if(e.origin!==d)return void n(`${r} received message from origin ${e.origin} which did not match expected origin ${d}`);const s=e.data,{methodName:a,args:p,id:m}=s;n(`${r}: Received ${a}() call`);const v=e=>t=>{if(n(`${r}: Sending ${a}() reply`),h)return void n(`${r}: Unable to send ${a}() reply due to destroyed connection`);const s={penpal:o.Reply,id:m,resolution:e,returnValue:t};e===i.Rejected&&t instanceof Error&&(s.returnValue=f(t),s.returnValueIsError=!0);try{u.postMessage(s,l)}catch(e){if(e.name===c.DataCloneError){const t={penpal:o.Reply,id:m,resolution:i.Rejected,returnValue:f(e),returnValueIsError:!0};u.postMessage(t,l)}throw e}};new Promise(e=>e(t[a].apply(t,p))).then(v(i.Fulfilled),v(i.Rejected))};return s.addEventListener(a.Message,p),()=>{h=!0,s.removeEventListener(a.Message,p)}})(m,e,s),l(d),h&&h.forEach(e=>{delete p[e]}),h=r.data.methodNames;const w=v(p,m,h,u,s);return l(w),p}};var g=e=>{let{iframe:t,methods:n={},childOrigin:r,timeout:i,debug:c=!1}=e;const u=(e=>(...t)=>{e&&console.log("[Penpal]",...t)})(c),f=(()=>{const e=[];let t=!1;return{destroy(n){t=!0,e.forEach(e=>{e(n)})},onDestroy(n){t?n():e.push(n)}}})(),{onDestroy:p,destroy:m}=f;r||((e=>{if(!e.src&&!e.srcdoc){const e=new Error("Iframe must have src or srcdoc property defined.");throw e.code=s.NoIframeSrc,e}})(t),r=(e=>{if(e&&h.find(t=>e.startsWith(t)))return"null";const t=document.location,n=d.exec(e);let r,o,i;return n?(r=n[1]?n[1]:t.protocol,o=n[2],i=n[4]):(r=t.protocol,o=t.hostname,i=t.port),`${r}//${o}${i&&i!==l[r]?`:${i}`:""}`})(t.src));const v="null"===r?"*":r,g=((e,t,n,r)=>i=>{if(i.origin!==n)return void e(`Parent: Handshake - Received SYN message from origin ${i.origin} which did not match expected origin ${n}`);e("Parent: Handshake - Received SYN, responding with SYN-ACK");const s={penpal:o.SynAck,methodNames:Object.keys(t)};i.source.postMessage(s,r)})(u,n,r,v),y=w(n,r,v,f,u),b=new Promise((e,n)=>{const r=((e,t)=>{let n;return void 0!==e&&(n=window.setTimeout(()=>{const n=new Error(`Connection timed out after ${e}ms`);n.code=s.ConnectionTimeout,t(n)},e)),()=>{clearTimeout(n)}})(i,m),c=n=>{if(n.source===t.contentWindow&&n.data)if(n.data.penpal!==o.Syn){if(n.data.penpal===o.Ack){const t=y(n);return void(t&&(r(),e(t)))}}else g(n)};window.addEventListener(a.Message,c),u("Parent: Awaiting handshake"),((e,t)=>{const{destroy:n,onDestroy:r}=t,o=setInterval(()=>{e.isConnected||(clearInterval(o),n())},6e4);r(()=>{clearInterval(o)})})(t,f),p(e=>{window.removeEventListener(a.Message,c),e||((e=new Error("Connection destroyed")).code=s.ConnectionDestroyed),n(e)})});return{promise:b,destroy(){m()}}},y=function(e,t){return console.error("[Dromo-External-Error] There was an error running your ".concat(t,"."),e)},b=function(e){return setTimeout(function(){console.warn("[Dromo Error] Slow ".concat(e," detected (>10s). Long running hooks can degrade user experience and importer performance."))},1e4)},k=function(e){clearTimeout(e)},I=function(r,o,i){return t(void 0,void 0,void 0,function(){var s,c,a;return n(this,function(u){switch(u.label){case 0:return s=new Map,c=o.map(function(t){return e({},t)}),[4,r.reduce(function(e,r){return t(void 0,void 0,void 0,function(){return n(this,function(o){switch(o.label){case 0:return[4,e.then(function(){return t(void 0,void 0,void 0,function(){var e,t,o;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),e=b("column hook"),[4,r.callback(c)];case 1:return t=n.sent(),k(e),t.forEach(function(e){if(void 0!==e.value||void 0!==e.info){var t={};void 0!==e.value&&(t.value=e.value,c[e.index].value=e.value),void 0!==e.info&&(t.info=e.info),s.set(e.index,t)}}),[3,3];case 2:return o=n.sent(),i(o,"column hooks"),[3,3];case 3:return[2]}})})})];case 1:return o.sent(),[2]}})})},Promise.resolve())];case 1:return u.sent(),a=[],s.forEach(function(t,n){return a.push(e(e({},t),{index:n}))}),[2,a]}})})},E=function(e){return void 0===e.value&&void 0===e.info&&void 0===e.selectOptions&&void 0===e.manyToOne},C=function(e,r,o,i,s){return t(void 0,void 0,void 0,function(){var c,a,u,l,d,h,f,p,m,v,w,g,y;return n(this,function(I){switch(I.label){case 0:c=new Map,a=new Map(e.map(function(e){return[e.index,e]})),u=function(e,t){for(var n,r=a.get(e),o=function(t,o){if(E(o))return"continue";var i=r.row[t],s=Array.isArray(i.manyToOne),a="manyToOne"in o&&Array.isArray(o.manyToOne);if(s&&!a)throw new Error("".concat(t," should have manyToOne defined as an array."));if(s&&a&&i.manyToOne.length!==o.manyToOne.length)throw new Error("".concat(t," should be array of length ").concat(i.manyToOne.length));var u=c.get(e)||{},l=null!==(n=u[t])&&void 0!==n?n:{},d=[];a?(l.manyToOne=[],o.manyToOne.forEach(function(e,t){if(!E(e)){var n={};l.manyToOne.push(n),d.push({fieldOutput:e,rowDataField:i.manyToOne[t],cellChange:n})}})):d.push({fieldOutput:o,rowDataField:i,cellChange:l}),d.forEach(function(e){var t=e.fieldOutput,n=e.rowDataField,r=e.cellChange;void 0!==t.value&&(r.value=t.value,n.value=t.value),void 0!==t.info&&(r.info=t.info,n.info=t.info),void 0!==t.selectOptions&&(r.selectOptions=t.selectOptions,n.selectOptions=t.selectOptions)}),u[t]=l,c.set(e,u)},i=0,s=Object.entries(null!=t?t:{});i<s.length;i++){var u=s[i];o(u[0],u[1])}},l=0,d=i,I.label=1;case 1:if(!(l<d.length))return[3,6];h=d[l],I.label=2;case 2:return I.trys.push([2,4,,5]),f=b("bulk row hook"),[4,h(e,r)];case 3:for(p=I.sent(),k(f),m=0,v=p;m<v.length;m++)w=v[m],u(w.index,w.row);return[3,5];case 4:return g=I.sent(),s(g,"bulk row hooks"),[3,5];case 5:return l++,[3,1];case 6:return[4,Promise.all(e.map(function(e){return t(void 0,void 0,void 0,function(){var t,i,c,a,l,d;return n(this,function(n){switch(n.label){case 0:t=0,i=o,n.label=1;case 1:if(!(t<i.length))return[3,6];c=i[t],n.label=2;case 2:return n.trys.push([2,4,,5]),a=b("row hook"),[4,c(e,r)];case 3:return l=n.sent(),k(a),u(e.index,l.row),[3,5];case 4:return d=n.sent(),s(d,"row hooks"),[3,5];case 5:return t++,[3,1];case 6:return[2]}})})}))];case 7:return I.sent(),y=[],c.forEach(function(e,t){y.push({index:t,row:e})}),[2,y]}})})},R=function(e,r,o){return t(void 0,void 0,void 0,function(){return n(this,function(i){return[2,Promise.all(e.map(function(e){return t(void 0,void 0,void 0,function(){return n(this,function(i){return r.forEach(function(r){return t(void 0,void 0,void 0,function(){var t,i;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=b("row delete hook"),[4,r(e)];case 1:return n.sent(),k(t),[3,3];case 2:return i=n.sent(),o(i,"row delete hooks"),[3,3];case 3:return[2]}})})}),[2]})})}))]})})},H=function(e,r,o,i,s){return t(void 0,void 0,void 0,function(){return n(this,function(c){switch(c.label){case 0:return[4,Promise.all(o.map(function(o){return t(void 0,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:if(e!==o.type)return[2,Promise.resolve()];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,o.callback(i,r)];case 2:return[2,n.sent()];case 3:return t=n.sent(),s(t,"step hook ".concat(e)),[2,Promise.resolve()];case 4:return[2]}})})}))];case 1:return c.sent(),[2]}})})},D=function(e,r,o,i,s){return t(void 0,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,o(e,r,i)];case 1:return[2,n.sent()];case 2:return t=n.sent(),s(t,"before finish callback"),[3,3];case 3:return[2]}})})},x=function(e,r,o,i){return t(void 0,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,i(e,r)];case 1:return[2,n.sent()];case 2:return t=n.sent(),o(t,"custom file parser callback"),[3,3];case 3:return[2]}})})},O="dromo-container",F=function(t){var n=e({},t);return n.validators&&(n.validators=n.validators.map(function(t){return("regex_match"===t.validate||"regex_exclude"===t.validate)&&t.regex instanceof RegExp?e(e({},t),{regex:t.regex.source,regexOptions:{ignoreCase:t.regex.flags.includes("i"),dotAll:t.regex.flags.includes("s"),multiline:t.regex.flags.includes("m"),unicode:t.regex.flags.includes("u")}}):t})),n},S=function(){function r(r,o,i,s){var c=this;this.embedInline=!1,this.columnHooks=[],this.bulkRowHooks=[],this.rowHooks=[],this.stepHooks=[],this.rowDeleteHooks=[],this.customSteps=[],this.fileParsers=[],this.initChild=function(){return t(c,void 0,void 0,function(){var t,r,o,i,s;return n(this,function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:(console.error("shim cannot connect with Dromo service."),alert("There was en error opening the importer. Please contact support if this issue persists."),[2]);case 1:return t=n.sent(),r=Array.from(document.getElementsByTagName("script")).some(function(e){return"https://unpkg.com/dromo-uploader-js/dist/DromoUploader.js"===e.src||"https://cdn.jsdelivr.net/npm/dromo-uploader-js@latest/dist/DromoUploader.js"===e.src}),[4,t.setNumRegisteredRowHooks(this.totalNumRowHooks())];case 2:return n.sent(),[4,t.setNumRegisteredColHooks(this.columnHooks.length)];case 3:return n.sent(),[4,t.setNumRegisteredRowDeleteHooks(this.rowDeleteHooks.length)];case 4:return n.sent(),[4,t.setCustomParserFileExtensions(this.fileParsers.flatMap(function(e){return e.extensions.map(function(e){return e.toLowerCase()})}))];case 5:return n.sent(),[4,t.setEmbedInline(this.embedInline)];case 6:return n.sent(),this.customSteps.length>0?[4,t.setCustomSteps(this.customSteps.map(function(e){return{id:e.id,insertAfter:e.insertAfter,label:e.label,url:e.url}}))]:[3,8];case 7:n.sent(),n.label=8;case 8:return this.fields&&this.settings&&this.user?(o=e({},this.settings),r||(o.version=null!==(i=o.version)&&void 0!==i?i:"v2"),o.browserExcelParsing=null===(s=o.browserExcelParsing)||void 0===s||s,[4,t.init(this.licenseKey,this.fields,o,this.user,this.appHost)]):[3,10];case 9:return n.sent(),[3,13];case 10:return this.schemaId?[4,t.initFromSavedSchema(this.licenseKey,this.schemaId,this.appHost,{user:this.user,developmentMode:this.developmentMode,headerRowOverride:this.headerRowOverride})]:[3,12];case 11:return n.sent(),[3,13];case 12:console.error("Invalid Dromo configuration"),n.label=13;case 13:return[2]}})})},this.initIFrame=function(){var e,t,n,r,o;if(window.DROMO_WIDGET_OVERRIDE)o=window.DROMO_WIDGET_OVERRIDE;else if(null===(e=c.settings)||void 0===e?void 0:e.alternateDomain){var i=new URL(c.settings.alternateDomain);o=i.protocol+"//widget."+i.host}else o="v1"===(null===(t=c.settings)||void 0===t?void 0:t.version)?"https://widget-v1.dromo.io/":u;if(!document.getElementById(c.iframeId)){var s=document.createElement("iframe"),a=null!==(r=null===(n=c.settings)||void 0===n?void 0:n.importIdentifier)&&void 0!==r?r:c.schemaId;s.title=a?"Dromo Importer: ".concat(a):"Dromo Importer",s.src=o,s.id=c.iframeId,s.style.height="100%",s.style.width="100%",s.style.border="0",s.crossorigin="anonymous",c.iframe=s}},this.createConnection=function(){var r=c,o=c.iframe;o?c.connection=g({iframe:o,methods:{handleColumnHooks:function(e,o){return t(this,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:return t=r.columnHooks.filter(function(t){return t.fieldName===e}),[4,I(t,o,y)];case 1:return[2,n.sent()]}})})},handleRowHooks:function(e,o){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,C(e,o,r.rowHooks.map(function(e){return e.callback}),r.bulkRowHooks,y)];case 1:return[2,t.sent()]}})})},handleStepHook:function(e,o){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,H(e,o,r.stepHooks,r,y)];case 1:return[2,t.sent()]}})})},handleParseFileCallback:function(e,o){return t(this,void 0,void 0,function(){var t,i;return n(this,function(n){switch(n.label){case 0:return t=o.split(".").pop(),i=r.fileParsers.find(function(e){return-1!==e.extensions.map(function(e){return e.toLowerCase()}).indexOf(t.toLowerCase())}),[4,x(e,o,y,i.parseFile)];case 1:return[2,n.sent()]}})})},handleRowDeleteHooks:function(e){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,R(e,r.rowDeleteHooks,y)];case 1:return t.sent(),[2]}})})},handleBeforeFinishCallback:function(e,o){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return r.beforeFinishCallback?[4,D(e,o,r.beforeFinishCallback,r,y)]:[3,2];case 1:return[2,t.sent()];case 2:return[2]}})})},handleResults:function(e,o){return t(this,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:if(!r.resultsCallback)return[3,4];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,r.resultsCallback(e,o)];case 2:return n.sent(),[3,4];case 3:return t=n.sent(),console.error("[Dromo-External-Error] There was an error in your onResult callback.",t),[3,4];case 4:return r.close(),[2]}})})},handleCloseModal:function(){r.close()},handleCancel:function(){if(r.cancelCallback)try{r.cancelCallback()}catch(e){console.error("[Dromo-External-Error] There was an error in your cancel callback.",e)}r.close()},handleCustomStep:function(e){return t(this,void 0,void 0,function(){return n(this,function(e){return[2,void 0]})})},handleCustomStepMessage:function(o,i){return t(this,void 0,void 0,function(){var t,s,c,a;return n(this,function(n){switch(n.label){case 0:return(null==(t=r.customSteps.find(function(e){return e.id===o}))?void 0:t.onMessage)?[4,r.connection.promise]:[2];case 1:s=n.sent(),c=e(e({},r),{completeCustomStep:function(){return s.completeCustomStep()},goBackCustomStep:function(){return s.goBackCustomStep()}}),n.label=2;case 2:return n.trys.push([2,4,,5]),[4,t.onMessage(c,i)];case 3:return n.sent(),[3,5];case 4:return a=n.sent(),console.error("[Dromo-External-Error] There was an error in your custom step onMessage callback.",a),[3,5];case 5:return[2]}})})}}}):console.error("shim cannot connect to Dromo.")},this.mountIFrame=function(){if(!document.getElementById(c.iframeId)){var e=document.createElement("div");e.id=c.wrapperId,e.style.zIndex=Number.MAX_SAFE_INTEGER.toString(),e.style.visibility="hidden",e.style.width="0px",e.style.height="0px",e.style.position="fixed",e.style.top="0px",e.style.left="0px",e.style.right="0px",e.style.bottom="0px",e.appendChild(c.iframe),document.body.appendChild(e),c.wrapper=e}},this.addIFrameToWrapper=function(){c.wrapper&&c.iframe&&(c.iframe.style.visibility="hidden",c.wrapper.appendChild(c.iframe))},this.showIframe=function(){c.iframe&&(c.iframe.style.visibility="visible")},this.showWrapper=function(){c.wrapper&&(c.wrapper.style.visibility="visible",c.wrapper.style.width="100%",c.wrapper.style.height="100%",document.body.style.overflow="hidden")},this.registerColumnHook=function(e,t){c.columnHooks.push({fieldName:e,callback:t}),c.connection&&c.connection.promise.then(function(e){e.setNumRegisteredColHooks(c.columnHooks.length)})},this.totalNumRowHooks=function(){return c.rowHooks.length+c.bulkRowHooks.length},this.registerBulkRowHook=function(e){c.bulkRowHooks.push(e),c.connection&&c.connection.promise.then(function(e){e.setNumRegisteredRowHooks(c.totalNumRowHooks())})},this.registerRowHook=function(e){c.rowHooks.push({callback:e}),c.connection&&c.connection.promise.then(function(e){e.setNumRegisteredRowHooks(c.totalNumRowHooks())})},this.registerStepHook=function(e,t){c.stepHooks.push({type:e,callback:t})},this.registerCustomStep=function(e){c.customSteps.push(e)},this.registerRowDeleteHook=function(e){c.rowDeleteHooks.push(e),c.connection&&c.connection.promise.then(function(e){e.setNumRegisteredRowDeleteHooks(c.rowDeleteHooks.length)})},this.beforeFinish=function(e){c.beforeFinishCallback=e},this.registerFileParser=function(e){c.fileParsers.push(e),c.connection&&c.connection.promise.then(function(e){e.setCustomParserFileExtensions(c.fileParsers.flatMap(function(e){return e.extensions.map(function(e){return e.toLowerCase()})}))})},this.registerAllHooks=function(e){if(e.columnHooks)for(var t=0,n=e.columnHooks;t<n.length;t++){var r=n[t],o=r.fieldName,i=r.callback;c.registerColumnHook(o,i)}if(e.rowHooks)for(var s=0,a=e.rowHooks;s<a.length;s++){var u=a[s];c.registerRowHook(u)}if(e.bulkRowHooks)for(var l=0,d=e.bulkRowHooks;l<d.length;l++){var h=d[l];c.registerBulkRowHook(h)}if(e.rowDeleteHooks)for(var f=0,p=e.rowDeleteHooks;f<p.length;f++){var m=p[f];c.registerRowDeleteHook(m)}if(e.stepHooks)for(var v=0,w=e.stepHooks;v<w.length;v++){var g=w[v],y=g.type;i=g.callback;c.registerStepHook(y,i)}if(e.beforeFinishCallback&&c.beforeFinish(e.beforeFinishCallback),e.fileParsers)for(var b=0,k=e.fileParsers;b<k.length;b++){var I=k[b];c.registerFileParser(I)}},this.onResults=function(e){c.resultsCallback=e},this.onCancel=function(e){c.cancelCallback=e},this.setUser=function(e){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.user=e,this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,t.sent().setUser(this.user)];case 2:t.sent(),t.label=3;case 3:return[2]}})})},this.addField=function(e,r){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,t.sent().addField(F(e),r)];case 2:return t.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),t.label=4;case 4:return[2]}})})},this.removeField=function(e){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,t.sent().removeField(e)];case 2:return t.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),t.label=4;case 4:return[2]}})})},this.updateInfoMessages=function(e){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,t.sent().updateInfoMessages(e)];case 2:return t.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),t.label=4;case 4:return[2]}})})},this.setHeaderRowOverride=function(e){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.headerRowOverride=e,this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,t.sent().setHeaderRowOverride(e)];case 2:t.sent(),t.label=3;case 3:return[2]}})})},this.setConfirmationMessage=function(e,r){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,t.sent().setConfirmationMessage(e,r)];case 2:return t.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),t.label=4;case 4:return[2]}})})},this.open=function(){return t(c,void 0,void 0,function(){return n(this,function(e){switch(e.label){case 0:return this.wrapper||(this.initIFrame(),this.createConnection(),this.mountIFrame()),[4,this.initChild()];case 1:return e.sent(),this.showWrapper(),[2]}})})},this.initInline=function(e){return t(c,void 0,void 0,function(){var t,r;return n(this,function(n){switch(n.label){case 0:this.embedInline=!0,n.label=1;case 1:if(n.trys.push([1,3,,4]),e instanceof HTMLElement&&(this.wrapper=e,this.wrapperId=e.id,""!==this.wrapperId&&void 0!==this.wrapperId||(this.wrapperId=Math.random().toString(36).substring(7)+"-"+O)),"string"==typeof e){if(null===(t=document.getElementById(e)))throw new Error("WRAPPER_NOT_FOUND");this.wrapper=t,this.wrapperId=e}return this.iframe||(this.initIFrame(),this.createConnection(),this.addIFrameToWrapper()),[4,this.initChild()];case 2:return n.sent(),this.showIframe(),[3,4];case 3:throw"WRAPPER_NOT_FOUND"===(r=n.sent()).message&&console.error("[Dromo-Error] Could not find wrapper using provided ID."),r;case 4:return[2]}})})},this.addRows=function(e){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,t.sent().addRows(e)];case 2:return[2,t.sent()];case 3:return console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),[2,[]]}})})},this.removeRows=function(e){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,t.sent().removeRows(e)];case 2:return t.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),t.label=4;case 4:return[2]}})})},this.close=function(){c.wrapper&&(c.wrapper.style.visibility="hidden",c.wrapper.style.width="0px",c.wrapper.style.height="0px",document.body.style.overflow="inherit")},this.setDevelopmentMode=function(e){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.developmentMode=e,this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,t.sent().setDevelopmentMode(this.developmentMode)];case 2:t.sent(),t.label=3;case 3:return[2]}})})},this.rehydrate=function(e,r){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.wrapper||(this.initIFrame(),this.createConnection(),this.mountIFrame()),[4,this.initChild()];case 1:return t.sent(),[4,this.connection.promise];case 2:return[4,t.sent().rehydrate(e,r)];case 3:return t.sent(),this.showWrapper(),[2]}})})},this.iframeId=Math.random().toString(36).substring(7)+"-dromo-iframe-element",this.wrapperId=Math.random().toString(36).substring(7)+"-"+O,this.appHost=document.location.hostname,void 0!==i&&void 0!==s?(this.licenseKey=r,this.fields=o.map(F),this.settings=i,this.user=s,this.checkCloneable({licenseKey:this.licenseKey,fields:this.fields,settings:this.settings,user:this.user})):(this.licenseKey=r,this.schemaId=o,this.checkCloneable({licenseKey:this.licenseKey,schemaId:this.schemaId}))}var o;return r.prototype.checkCloneable=function(e){if("function"==typeof structuredClone){var t=Object.entries(e).filter(function(e){e[0];var t=e[1];try{return structuredClone(t),!1}catch(e){return!0}}).map(function(e){return e[0]});if(t.length>0){var n=t.join(", ");throw new Error("[Dromo-External-Error] The Dromo importer received non-cloneable parameters: ".concat(n,". See https://dromo.dev/err/clone"))}}},o=r,r.rehydrateHeadless=function(e){var i=e.licenseKey,s=e.headlessImportId,c=e.fields,a=e.settings,u=e.hooks,l=e.rehydrateState;return t(void 0,void 0,void 0,function(){var e;return n(o,function(t){switch(t.label){case 0:return(e=new r(i,c,a,{id:"headless-review"})).registerAllHooks(u),[4,e.rehydrate(l,s)];case 1:return t.sent(),e.open(),[2,e]}})})},r}();return S});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).DromoUploader=t()}(this,function(){"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};function t(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,c)}a((r=r.apply(e,t||[])).next())})}function n(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=c(0),s.throw=c(1),s.return=c(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,c[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=t.call(e,i)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}"function"==typeof SuppressedError&&SuppressedError;var r,o,i,s,c,a,u={IFRAME_URL:"https://widget.dromo.io/"}.IFRAME_URL;!function(e){e.INIT_IFRAME="INIT_IFRAME"}(r||(r={})),function(e){e.Call="call",e.Reply="reply",e.Syn="syn",e.SynAck="synAck",e.Ack="ack"}(o||(o={})),function(e){e.Fulfilled="fulfilled",e.Rejected="rejected"}(i||(i={})),function(e){e.ConnectionDestroyed="ConnectionDestroyed",e.ConnectionTimeout="ConnectionTimeout",e.NotInIframe="NotInIframe",e.NoIframeSrc="NoIframeSrc"}(s||(s={})),function(e){e.DataCloneError="DataCloneError"}(c||(c={})),function(e){e.Message="message"}(a||(a={}));const l={"http:":"80","https:":"443"},d=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,h=["file:","data:"];const f=({name:e,message:t,stack:n})=>({name:e,message:t,stack:n});let p=0;var m=()=>++p,v=(e,t,n,r,c)=>{const{localName:u,local:l,remote:d,originForSending:h,originForReceiving:f}=t;let p=!1;c(`${u}: Connecting call sender`);const v=e=>(...t)=>{let n;c(`${u}: Sending ${e}() call`);try{d.closed&&(n=!0)}catch(e){n=!0}if(n&&r(),p){const t=new Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=s.ConnectionDestroyed,t}return new Promise((n,r)=>{const s=m(),p=t=>{if(t.source!==d||t.data.penpal!==o.Reply||t.data.id!==s)return;if(t.origin!==f)return void c(`${u} received message from origin ${t.origin} which did not match expected origin ${f}`);const h=t.data;c(`${u}: Received ${e}() reply`),l.removeEventListener(a.Message,p);let m=h.returnValue;h.returnValueIsError&&(m=(e=>{const t=new Error;return Object.keys(e).forEach(n=>t[n]=e[n]),t})(m)),(h.resolution===i.Fulfilled?n:r)(m)};l.addEventListener(a.Message,p);const v={penpal:o.Call,id:s,methodName:e,args:t};d.postMessage(v,h)})};return n.reduce((e,t)=>(e[t]=v(t),e),e),()=>{p=!0}},w=(e,t,n,r,s)=>{const{destroy:u,onDestroy:l}=r;let d,h;const p={};return r=>{if(r.origin!==t)return void s(`Parent: Handshake - Received ACK message from origin ${r.origin} which did not match expected origin ${t}`);s("Parent: Handshake - Received ACK");const m={localName:"Parent",local:window,remote:r.source,originForSending:n,originForReceiving:t};d&&d(),d=((e,t,n)=>{const{localName:r,local:s,remote:u,originForSending:l,originForReceiving:d}=e;let h=!1;const p=e=>{if(e.source!==u||e.data.penpal!==o.Call)return;if(e.origin!==d)return void n(`${r} received message from origin ${e.origin} which did not match expected origin ${d}`);const s=e.data,{methodName:a,args:p,id:m}=s;n(`${r}: Received ${a}() call`);const v=e=>t=>{if(n(`${r}: Sending ${a}() reply`),h)return void n(`${r}: Unable to send ${a}() reply due to destroyed connection`);const s={penpal:o.Reply,id:m,resolution:e,returnValue:t};e===i.Rejected&&t instanceof Error&&(s.returnValue=f(t),s.returnValueIsError=!0);try{u.postMessage(s,l)}catch(e){if(e.name===c.DataCloneError){const t={penpal:o.Reply,id:m,resolution:i.Rejected,returnValue:f(e),returnValueIsError:!0};u.postMessage(t,l)}throw e}};new Promise(e=>e(t[a].apply(t,p))).then(v(i.Fulfilled),v(i.Rejected))};return s.addEventListener(a.Message,p),()=>{h=!0,s.removeEventListener(a.Message,p)}})(m,e,s),l(d),h&&h.forEach(e=>{delete p[e]}),h=r.data.methodNames;const w=v(p,m,h,u,s);return l(w),p}};var g=e=>{let{iframe:t,methods:n={},childOrigin:r,timeout:i,debug:c=!1}=e;const u=(e=>(...t)=>{e&&console.log("[Penpal]",...t)})(c),f=(()=>{const e=[];let t=!1;return{destroy(n){t=!0,e.forEach(e=>{e(n)})},onDestroy(n){t?n():e.push(n)}}})(),{onDestroy:p,destroy:m}=f;r||((e=>{if(!e.src&&!e.srcdoc){const e=new Error("Iframe must have src or srcdoc property defined.");throw e.code=s.NoIframeSrc,e}})(t),r=(e=>{if(e&&h.find(t=>e.startsWith(t)))return"null";const t=document.location,n=d.exec(e);let r,o,i;return n?(r=n[1]?n[1]:t.protocol,o=n[2],i=n[4]):(r=t.protocol,o=t.hostname,i=t.port),`${r}//${o}${i&&i!==l[r]?`:${i}`:""}`})(t.src));const v="null"===r?"*":r,g=((e,t,n,r)=>i=>{if(i.origin!==n)return void e(`Parent: Handshake - Received SYN message from origin ${i.origin} which did not match expected origin ${n}`);e("Parent: Handshake - Received SYN, responding with SYN-ACK");const s={penpal:o.SynAck,methodNames:Object.keys(t)};i.source.postMessage(s,r)})(u,n,r,v),b=w(n,r,v,f,u),y=new Promise((e,n)=>{const r=((e,t)=>{let n;return void 0!==e&&(n=window.setTimeout(()=>{const n=new Error(`Connection timed out after ${e}ms`);n.code=s.ConnectionTimeout,t(n)},e)),()=>{clearTimeout(n)}})(i,m),c=n=>{if(n.source===t.contentWindow&&n.data)if(n.data.penpal!==o.Syn){if(n.data.penpal===o.Ack){const t=b(n);return void(t&&(r(),e(t)))}}else g(n)};window.addEventListener(a.Message,c),u("Parent: Awaiting handshake"),((e,t)=>{const{destroy:n,onDestroy:r}=t,o=setInterval(()=>{e.isConnected||(clearInterval(o),n())},6e4);r(()=>{clearInterval(o)})})(t,f),p(e=>{window.removeEventListener(a.Message,c),e||((e=new Error("Connection destroyed")).code=s.ConnectionDestroyed),n(e)})});return{promise:y,destroy(){m()}}},b=function(e,t){return console.error("[Dromo-External-Error] There was an error running your ".concat(t,"."),e)},y=function(e){return setTimeout(function(){console.warn("[Dromo Error] Slow ".concat(e," detected (>10s). Long running hooks can degrade user experience and importer performance."))},1e4)},k=function(e){clearTimeout(e)},E=function(r,o,i){return t(void 0,void 0,void 0,function(){var s,c,a;return n(this,function(u){switch(u.label){case 0:return s=new Map,c=o.map(function(t){return e({},t)}),[4,r.reduce(function(e,r){return t(void 0,void 0,void 0,function(){return n(this,function(o){switch(o.label){case 0:return[4,e.then(function(){return t(void 0,void 0,void 0,function(){var e,t,o;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),e=y("column hook"),[4,r.callback(c)];case 1:return t=n.sent(),k(e),t.forEach(function(e){if(void 0!==e.value||void 0!==e.info){var t={};void 0!==e.value&&(t.value=e.value,c[e.index].value=e.value),void 0!==e.info&&(t.info=e.info),s.set(e.index,t)}}),[3,3];case 2:return o=n.sent(),i(o,"column hooks"),[3,3];case 3:return[2]}})})})];case 1:return o.sent(),[2]}})})},Promise.resolve())];case 1:return u.sent(),a=[],s.forEach(function(t,n){return a.push(e(e({},t),{index:n}))}),[2,a]}})})},C=function(e){return void 0===e.value&&void 0===e.info&&void 0===e.selectOptions&&void 0===e.manyToOne},I=function(e,r,o,i,s){return t(void 0,void 0,void 0,function(){var c,a,u,l,d,h,f,p,m,v,w,g,b;return n(this,function(E){switch(E.label){case 0:c=new Map,a=new Map(e.map(function(e){return[e.index,e]})),u=function(e,t){for(var n,r=a.get(e),o=function(t,o){if(C(o))return"continue";var i=r.row[t],s=Array.isArray(i.manyToOne),a="manyToOne"in o&&Array.isArray(o.manyToOne);if(s&&!a)throw new Error("".concat(t," should have manyToOne defined as an array."));if(s&&a&&i.manyToOne.length!==o.manyToOne.length)throw new Error("".concat(t," should be array of length ").concat(i.manyToOne.length));var u=c.get(e)||{},l=null!==(n=u[t])&&void 0!==n?n:{},d=[];a?(l.manyToOne=[],o.manyToOne.forEach(function(e,t){if(!C(e)){var n={};l.manyToOne.push(n),d.push({fieldOutput:e,rowDataField:i.manyToOne[t],cellChange:n})}})):d.push({fieldOutput:o,rowDataField:i,cellChange:l}),d.forEach(function(e){var t=e.fieldOutput,n=e.rowDataField,r=e.cellChange;void 0!==t.value&&(r.value=t.value,n.value=t.value),void 0!==t.info&&(r.info=t.info,n.info=t.info),void 0!==t.selectOptions&&(r.selectOptions=t.selectOptions,n.selectOptions=t.selectOptions)}),u[t]=l,c.set(e,u)},i=0,s=Object.entries(null!=t?t:{});i<s.length;i++){var u=s[i];o(u[0],u[1])}},l=0,d=i,E.label=1;case 1:if(!(l<d.length))return[3,6];h=d[l],E.label=2;case 2:return E.trys.push([2,4,,5]),f=y("bulk row hook"),[4,h(e,r)];case 3:for(p=E.sent(),k(f),m=0,v=p;m<v.length;m++)w=v[m],u(w.index,w.row);return[3,5];case 4:return g=E.sent(),s(g,"bulk row hooks"),[3,5];case 5:return l++,[3,1];case 6:return[4,Promise.all(e.map(function(e){return t(void 0,void 0,void 0,function(){var t,i,c,a,l,d;return n(this,function(n){switch(n.label){case 0:t=0,i=o,n.label=1;case 1:if(!(t<i.length))return[3,6];c=i[t],n.label=2;case 2:return n.trys.push([2,4,,5]),a=y("row hook"),[4,c(e,r)];case 3:return l=n.sent(),k(a),u(e.index,l.row),[3,5];case 4:return d=n.sent(),s(d,"row hooks"),[3,5];case 5:return t++,[3,1];case 6:return[2]}})})}))];case 7:return E.sent(),b=[],c.forEach(function(e,t){b.push({index:t,row:e})}),[2,b]}})})},R=function(e,r,o){return t(void 0,void 0,void 0,function(){return n(this,function(i){return[2,Promise.all(e.map(function(e){return t(void 0,void 0,void 0,function(){return n(this,function(i){return r.forEach(function(r){return t(void 0,void 0,void 0,function(){var t,i;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=y("row delete hook"),[4,r(e)];case 1:return n.sent(),k(t),[3,3];case 2:return i=n.sent(),o(i,"row delete hooks"),[3,3];case 3:return[2]}})})}),[2]})})}))]})})},H=function(e,r,o,i,s){return t(void 0,void 0,void 0,function(){return n(this,function(c){switch(c.label){case 0:return[4,Promise.all(o.map(function(o){return t(void 0,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:if(e!==o.type)return[2,Promise.resolve()];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,o.callback(i,r)];case 2:return[2,n.sent()];case 3:return t=n.sent(),s(t,"step hook ".concat(e)),[2,Promise.resolve()];case 4:return[2]}})})}))];case 1:return c.sent(),[2]}})})},D=function(e,r,o,i,s){return t(void 0,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,o(e,r,i)];case 1:return[2,n.sent()];case 2:return t=n.sent(),s(t,"before finish callback"),[3,3];case 3:return[2]}})})},x=function(e,r,o,i){return t(void 0,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,i(e,r)];case 1:return[2,n.sent()];case 2:return t=n.sent(),o(t,"custom file parser callback"),[3,3];case 3:return[2]}})})},O="dromo-container",F=function(t){var n=e({},t);return n.validators&&(n.validators=n.validators.map(function(t){return("regex_match"===t.validate||"regex_exclude"===t.validate)&&t.regex instanceof RegExp?e(e({},t),{regex:t.regex.source,regexOptions:{ignoreCase:t.regex.flags.includes("i"),dotAll:t.regex.flags.includes("s"),multiline:t.regex.flags.includes("m"),unicode:t.regex.flags.includes("u")}}):t})),n},S=function(){function r(r,o,i,s){var c=this;this.embedInline=!1,this.columnHooks=[],this.bulkRowHooks=[],this.rowHooks=[],this.stepHooks=[],this.rowDeleteHooks=[],this.customSteps=[],this.fileParsers=[],this.initChild=function(){return t(c,void 0,void 0,function(){var t,r,o,i,s;return n(this,function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:(console.error("shim cannot connect with Dromo service."),alert("There was en error opening the importer. Please contact support if this issue persists."),[2]);case 1:return t=n.sent(),r=Array.from(document.getElementsByTagName("script")).some(function(e){return"https://unpkg.com/dromo-uploader-js/dist/DromoUploader.js"===e.src||"https://cdn.jsdelivr.net/npm/dromo-uploader-js@latest/dist/DromoUploader.js"===e.src}),[4,t.setNumRegisteredRowHooks(this.totalNumRowHooks())];case 2:return n.sent(),[4,t.setNumRegisteredColHooks(this.columnHooks.length)];case 3:return n.sent(),[4,t.setNumRegisteredRowDeleteHooks(this.rowDeleteHooks.length)];case 4:return n.sent(),[4,t.setCustomParserFileExtensions(this.fileParsers.flatMap(function(e){return e.extensions.map(function(e){return e.toLowerCase()})}))];case 5:return n.sent(),[4,t.setEmbedInline(this.embedInline)];case 6:return n.sent(),this.customSteps.length>0?[4,t.setCustomSteps(this.customSteps.map(function(e){return{id:e.id,insertAfter:e.insertAfter,label:e.label,url:e.url}}))]:[3,8];case 7:n.sent(),n.label=8;case 8:return this.fields&&this.settings&&this.user?(o=e({},this.settings),r||(o.version=null!==(i=o.version)&&void 0!==i?i:"v2"),o.browserExcelParsing=null===(s=o.browserExcelParsing)||void 0===s||s,[4,t.init(this.licenseKey,this.fields,o,this.user,this.appHost)]):[3,10];case 9:return n.sent(),[3,13];case 10:return this.schemaId?[4,t.initFromSavedSchema(this.licenseKey,this.schemaId,this.appHost,{user:this.user,developmentMode:this.developmentMode,headerRowOverride:this.headerRowOverride})]:[3,12];case 11:return n.sent(),[3,13];case 12:console.error("Invalid Dromo configuration"),n.label=13;case 13:return[2]}})})},this.initIFrame=function(){var e,t,n,r,o;if(window.DROMO_WIDGET_OVERRIDE)o=window.DROMO_WIDGET_OVERRIDE;else if(null===(e=c.settings)||void 0===e?void 0:e.alternateDomain){var i=new URL(c.settings.alternateDomain);o=i.protocol+"//widget."+i.host}else o="v1"===(null===(t=c.settings)||void 0===t?void 0:t.version)?"https://widget-v1.dromo.io/":u;if(!document.getElementById(c.iframeId)){var s=document.createElement("iframe"),a=null!==(r=null===(n=c.settings)||void 0===n?void 0:n.importIdentifier)&&void 0!==r?r:c.schemaId;s.title=a?"Dromo Importer: ".concat(a):"Dromo Importer",s.src=o,s.id=c.iframeId,s.style.height="100%",s.style.width="100%",s.style.border="0",s.allow="clipboard-read; clipboard-write",s.crossorigin="anonymous",c.iframe=s}},this.createConnection=function(){var r=c,o=c.iframe;o?c.connection=g({iframe:o,methods:{handleColumnHooks:function(e,o){return t(this,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:return t=r.columnHooks.filter(function(t){return t.fieldName===e}),[4,E(t,o,b)];case 1:return[2,n.sent()]}})})},handleRowHooks:function(e,o){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,I(e,o,r.rowHooks.map(function(e){return e.callback}),r.bulkRowHooks,b)];case 1:return[2,t.sent()]}})})},handleStepHook:function(e,o){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,H(e,o,r.stepHooks,r,b)];case 1:return[2,t.sent()]}})})},handleParseFileCallback:function(e,o){return t(this,void 0,void 0,function(){var t,i;return n(this,function(n){switch(n.label){case 0:return t=o.split(".").pop(),i=r.fileParsers.find(function(e){return-1!==e.extensions.map(function(e){return e.toLowerCase()}).indexOf(t.toLowerCase())}),[4,x(e,o,b,i.parseFile)];case 1:return[2,n.sent()]}})})},handleRowDeleteHooks:function(e){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,R(e,r.rowDeleteHooks,b)];case 1:return t.sent(),[2]}})})},handleBeforeFinishCallback:function(e,o){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return r.beforeFinishCallback?[4,D(e,o,r.beforeFinishCallback,r,b)]:[3,2];case 1:return[2,t.sent()];case 2:return[2]}})})},handleResults:function(e,o){return t(this,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:if(!r.resultsCallback)return[3,4];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,r.resultsCallback(e,o)];case 2:return n.sent(),[3,4];case 3:return t=n.sent(),console.error("[Dromo-External-Error] There was an error in your onResult callback.",t),[3,4];case 4:return r.close(),[2]}})})},handleCloseModal:function(){r.close()},handleCancel:function(){if(r.cancelCallback)try{r.cancelCallback()}catch(e){console.error("[Dromo-External-Error] There was an error in your cancel callback.",e)}r.close()},handleCustomStep:function(e){return t(this,void 0,void 0,function(){return n(this,function(e){return[2,void 0]})})},handleCustomStepMessage:function(o,i){return t(this,void 0,void 0,function(){var t,s,c,a;return n(this,function(n){switch(n.label){case 0:return(null==(t=r.customSteps.find(function(e){return e.id===o}))?void 0:t.onMessage)?[4,r.connection.promise]:[2];case 1:s=n.sent(),c=e(e({},r),{completeCustomStep:function(){return s.completeCustomStep()},goBackCustomStep:function(){return s.goBackCustomStep()}}),n.label=2;case 2:return n.trys.push([2,4,,5]),[4,t.onMessage(c,i)];case 3:return n.sent(),[3,5];case 4:return a=n.sent(),console.error("[Dromo-External-Error] There was an error in your custom step onMessage callback.",a),[3,5];case 5:return[2]}})})},handleUserEvent:function(e){return t(this,void 0,void 0,function(){return n(this,function(t){if(r.onUserEventCallback)try{r.onUserEventCallback(e)}catch(e){console.warn("[Dromo-External-Error] There was an error in your onUserEvent callback.",e)}return[2]})})}}}):console.error("shim cannot connect to Dromo.")},this.mountIFrame=function(){if(!document.getElementById(c.iframeId)){var e=document.createElement("div");e.id=c.wrapperId,e.style.zIndex=Number.MAX_SAFE_INTEGER.toString(),e.style.visibility="hidden",e.style.width="0px",e.style.height="0px",e.style.position="fixed",e.style.top="0px",e.style.left="0px",e.style.right="0px",e.style.bottom="0px",e.appendChild(c.iframe),document.body.appendChild(e),c.wrapper=e}},this.addIFrameToWrapper=function(){c.wrapper&&c.iframe&&(c.iframe.style.visibility="hidden",c.wrapper.appendChild(c.iframe))},this.showIframe=function(){c.iframe&&(c.iframe.style.visibility="visible")},this.showWrapper=function(){c.wrapper&&(c.wrapper.style.visibility="visible",c.wrapper.style.width="100%",c.wrapper.style.height="100%",document.body.style.overflow="hidden")},this.registerColumnHook=function(e,t){c.columnHooks.push({fieldName:e,callback:t}),c.connection&&c.connection.promise.then(function(e){e.setNumRegisteredColHooks(c.columnHooks.length)})},this.totalNumRowHooks=function(){return c.rowHooks.length+c.bulkRowHooks.length},this.registerBulkRowHook=function(e){c.bulkRowHooks.push(e),c.connection&&c.connection.promise.then(function(e){e.setNumRegisteredRowHooks(c.totalNumRowHooks())})},this.registerRowHook=function(e){c.rowHooks.push({callback:e}),c.connection&&c.connection.promise.then(function(e){e.setNumRegisteredRowHooks(c.totalNumRowHooks())})},this.registerStepHook=function(e,t){c.stepHooks.push({type:e,callback:t})},this.registerCustomStep=function(e){c.customSteps.push(e)},this.registerRowDeleteHook=function(e){c.rowDeleteHooks.push(e),c.connection&&c.connection.promise.then(function(e){e.setNumRegisteredRowDeleteHooks(c.rowDeleteHooks.length)})},this.beforeFinish=function(e){c.beforeFinishCallback=e},this.registerFileParser=function(e){c.fileParsers.push(e),c.connection&&c.connection.promise.then(function(e){e.setCustomParserFileExtensions(c.fileParsers.flatMap(function(e){return e.extensions.map(function(e){return e.toLowerCase()})}))})},this.registerAllHooks=function(e){if(e.columnHooks)for(var t=0,n=e.columnHooks;t<n.length;t++){var r=n[t],o=r.fieldName,i=r.callback;c.registerColumnHook(o,i)}if(e.rowHooks)for(var s=0,a=e.rowHooks;s<a.length;s++){var u=a[s];c.registerRowHook(u)}if(e.bulkRowHooks)for(var l=0,d=e.bulkRowHooks;l<d.length;l++){var h=d[l];c.registerBulkRowHook(h)}if(e.rowDeleteHooks)for(var f=0,p=e.rowDeleteHooks;f<p.length;f++){var m=p[f];c.registerRowDeleteHook(m)}if(e.stepHooks)for(var v=0,w=e.stepHooks;v<w.length;v++){var g=w[v],b=g.type;i=g.callback;c.registerStepHook(b,i)}if(e.beforeFinishCallback&&c.beforeFinish(e.beforeFinishCallback),e.fileParsers)for(var y=0,k=e.fileParsers;y<k.length;y++){var E=k[y];c.registerFileParser(E)}},this.onResults=function(e){c.resultsCallback=e},this.onCancel=function(e){c.cancelCallback=e},this.onUserEvent=function(e){c.onUserEventCallback=e},this.setUser=function(e){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.user=e,this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,t.sent().setUser(this.user)];case 2:t.sent(),t.label=3;case 3:return[2]}})})},this.addField=function(e,r){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,t.sent().addField(F(e),r)];case 2:return t.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),t.label=4;case 4:return[2]}})})},this.removeField=function(e){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,t.sent().removeField(e)];case 2:return t.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),t.label=4;case 4:return[2]}})})},this.updateInfoMessages=function(e){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,t.sent().updateInfoMessages(e)];case 2:return t.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),t.label=4;case 4:return[2]}})})},this.setHeaderRowOverride=function(e){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.headerRowOverride=e,this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,t.sent().setHeaderRowOverride(e)];case 2:t.sent(),t.label=3;case 3:return[2]}})})},this.setConfirmationMessage=function(e,r){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,t.sent().setConfirmationMessage(e,r)];case 2:return t.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),t.label=4;case 4:return[2]}})})},this.open=function(){return t(c,void 0,void 0,function(){return n(this,function(e){switch(e.label){case 0:return this.wrapper||(this.initIFrame(),this.createConnection(),this.mountIFrame()),[4,this.initChild()];case 1:return e.sent(),this.showWrapper(),[2]}})})},this.initInline=function(e){return t(c,void 0,void 0,function(){var t,r;return n(this,function(n){switch(n.label){case 0:this.embedInline=!0,n.label=1;case 1:if(n.trys.push([1,3,,4]),e instanceof HTMLElement&&(this.wrapper=e,this.wrapperId=e.id,""!==this.wrapperId&&void 0!==this.wrapperId||(this.wrapperId=Math.random().toString(36).substring(7)+"-"+O)),"string"==typeof e){if(null===(t=document.getElementById(e)))throw new Error("WRAPPER_NOT_FOUND");this.wrapper=t,this.wrapperId=e}return this.iframe||(this.initIFrame(),this.createConnection(),this.addIFrameToWrapper()),[4,this.initChild()];case 2:return n.sent(),this.showIframe(),[3,4];case 3:throw"WRAPPER_NOT_FOUND"===(r=n.sent()).message&&console.error("[Dromo-Error] Could not find wrapper using provided ID."),r;case 4:return[2]}})})},this.addRows=function(e){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,t.sent().addRows(e)];case 2:return[2,t.sent()];case 3:return console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),[2,[]]}})})},this.removeRows=function(e){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,t.sent().removeRows(e)];case 2:return t.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),t.label=4;case 4:return[2]}})})},this.close=function(){c.wrapper&&(c.wrapper.style.visibility="hidden",c.wrapper.style.width="0px",c.wrapper.style.height="0px",document.body.style.overflow="inherit")},this.setDevelopmentMode=function(e){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.developmentMode=e,this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,t.sent().setDevelopmentMode(this.developmentMode)];case 2:t.sent(),t.label=3;case 3:return[2]}})})},this.rehydrate=function(e,r){return t(c,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return this.wrapper||(this.initIFrame(),this.createConnection(),this.mountIFrame()),[4,this.initChild()];case 1:return t.sent(),[4,this.connection.promise];case 2:return[4,t.sent().rehydrate(e,r)];case 3:return t.sent(),this.showWrapper(),[2]}})})},this.iframeId=Math.random().toString(36).substring(7)+"-dromo-iframe-element",this.wrapperId=Math.random().toString(36).substring(7)+"-"+O,this.appHost=document.location.hostname,void 0!==i&&void 0!==s?(this.licenseKey=r,this.fields=o.map(F),this.settings=i,this.user=s,this.checkCloneable({licenseKey:this.licenseKey,fields:this.fields,settings:this.settings,user:this.user})):(this.licenseKey=r,this.schemaId=o,this.checkCloneable({licenseKey:this.licenseKey,schemaId:this.schemaId}))}var o;return r.prototype.checkCloneable=function(e){if("function"==typeof structuredClone){var t=Object.entries(e).filter(function(e){e[0];var t=e[1];try{return structuredClone(t),!1}catch(e){return!0}}).map(function(e){return e[0]});if(t.length>0){var n=t.join(", ");throw new Error("[Dromo-External-Error] The Dromo importer received non-cloneable parameters: ".concat(n,". See https://dromo.dev/err/clone"))}}},o=r,r.rehydrateHeadless=function(e){var i=e.licenseKey,s=e.headlessImportId,c=e.fields,a=e.settings,u=e.hooks,l=e.rehydrateState;return t(void 0,void 0,void 0,function(){var e;return n(o,function(t){switch(t.label){case 0:return(e=new r(i,c,a,{id:"headless-review"})).registerAllHooks(u),[4,e.rehydrate(l,s)];case 1:return t.sent(),e.open(),[2,e]}})})},r}();return S});
2
2
  //# sourceMappingURL=index.js.map