dromo-uploader-js
Advanced tools
Comparing version 2.1.2 to 2.1.3
@@ -15,3 +15,3 @@ var DromoUploader=function(){"use strict"; | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */var e=function(){return(e=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e}).apply(this,arguments)};function n(e,n,t,r){return new(t||(t=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 n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(s,c)}a((r=r.apply(e,n||[])).next())}))}function t(e,n){var t,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;s;)try{if(t=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=n.call(e,s)}catch(e){i=[6,e],r=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}var r,o,i,s,c,a,l={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 u={"http:":"80","https:":"443"},d=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,h=["file:","data:"];const f=({name:e,message:n,stack:t})=>({name:e,message:n,stack:t});let m=0;var p=()=>++m,v=(e,n,t,r,c)=>{const{localName:l,local:u,remote:d,originForSending:h,originForReceiving:f}=n;let m=!1;c(`${l}: Connecting call sender`);const v=e=>(...n)=>{let t;c(`${l}: Sending ${e}() call`);try{d.closed&&(t=!0)}catch(e){t=!0}if(t&&r(),m){const n=new Error(`Unable to send ${e}() call due to destroyed connection`);throw n.code=s.ConnectionDestroyed,n}return new Promise(((t,r)=>{const s=p(),m=n=>{if(n.source!==d||n.data.penpal!==o.Reply||n.data.id!==s)return;if(n.origin!==f)return void c(`${l} received message from origin ${n.origin} which did not match expected origin ${f}`);const h=n.data;c(`${l}: Received ${e}() reply`),u.removeEventListener(a.Message,m);let p=h.returnValue;h.returnValueIsError&&(p=(e=>{const n=new Error;return Object.keys(e).forEach((t=>n[t]=e[t])),n})(p)),(h.resolution===i.Fulfilled?t:r)(p)};u.addEventListener(a.Message,m);const v={penpal:o.Call,id:s,methodName:e,args:n};d.postMessage(v,h)}))};return t.reduce(((e,n)=>(e[n]=v(n),e)),e),()=>{m=!0}},w=(e,n,t,r,s)=>{const{destroy:l,onDestroy:u}=r;let d,h;const m={};return r=>{if(r.origin!==n)return void s(`Parent: Handshake - Received ACK message from origin ${r.origin} which did not match expected origin ${n}`);s("Parent: Handshake - Received ACK");const p={localName:"Parent",local:window,remote:r.source,originForSending:t,originForReceiving:n};d&&d(),d=((e,n,t)=>{const{localName:r,local:s,remote:l,originForSending:u,originForReceiving:d}=e;let h=!1;const m=e=>{if(e.source!==l||e.data.penpal!==o.Call)return;if(e.origin!==d)return void t(`${r} received message from origin ${e.origin} which did not match expected origin ${d}`);const s=e.data,{methodName:a,args:m,id:p}=s;t(`${r}: Received ${a}() call`);const v=e=>n=>{if(t(`${r}: Sending ${a}() reply`),h)return void t(`${r}: Unable to send ${a}() reply due to destroyed connection`);const s={penpal:o.Reply,id:p,resolution:e,returnValue:n};e===i.Rejected&&n instanceof Error&&(s.returnValue=f(n),s.returnValueIsError=!0);try{l.postMessage(s,u)}catch(e){if(e.name===c.DataCloneError){const n={penpal:o.Reply,id:p,resolution:i.Rejected,returnValue:f(e),returnValueIsError:!0};l.postMessage(n,u)}throw e}};new Promise((e=>e(n[a].apply(n,m)))).then(v(i.Fulfilled),v(i.Rejected))};return s.addEventListener(a.Message,m),()=>{h=!0,s.removeEventListener(a.Message,m)}})(p,e,s),u(d),h&&h.forEach((e=>{delete m[e]})),h=r.data.methodNames;const w=v(m,p,h,l,s);return u(w),m}};var g=e=>{let{iframe:n,methods:t={},childOrigin:r,timeout:i,debug:c=!1}=e;const l=(e=>(...n)=>{e&&console.log("[Penpal]",...n)})(c),f=(()=>{const e=[];let n=!1;return{destroy(t){n=!0,e.forEach((e=>{e(t)}))},onDestroy(t){n?t():e.push(t)}}})(),{onDestroy:m,destroy:p}=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}})(n),r=(e=>{if(e&&h.find((n=>e.startsWith(n))))return"null";const n=document.location,t=d.exec(e);let r,o,i;return t?(r=t[1]?t[1]:n.protocol,o=t[2],i=t[4]):(r=n.protocol,o=n.hostname,i=n.port),`${r}//${o}${i&&i!==u[r]?`:${i}`:""}`})(n.src));const v="null"===r?"*":r,g=((e,n,t,r)=>i=>{if(i.origin!==t)return void e(`Parent: Handshake - Received SYN message from origin ${i.origin} which did not match expected origin ${t}`);e("Parent: Handshake - Received SYN, responding with SYN-ACK");const s={penpal:o.SynAck,methodNames:Object.keys(n)};i.source.postMessage(s,r)})(l,t,r,v),y=w(t,r,v,f,l);return{promise:new Promise(((e,t)=>{const r=((e,n)=>{let t;return void 0!==e&&(t=window.setTimeout((()=>{const t=new Error(`Connection timed out after ${e}ms`);t.code=s.ConnectionTimeout,n(t)}),e)),()=>{clearTimeout(t)}})(i,p),c=t=>{if(t.source===n.contentWindow&&t.data)if(t.data.penpal!==o.Syn)if(t.data.penpal!==o.Ack);else{const n=y(t);n&&(r(),e(n))}else g(t)};window.addEventListener(a.Message,c),l("Parent: Awaiting handshake"),((e,n)=>{const{destroy:t,onDestroy:r}=n,o=setInterval((()=>{e.isConnected||(clearInterval(o),t())}),6e4);r((()=>{clearInterval(o)}))})(n,f),m((e=>{window.removeEventListener(a.Message,c),e||((e=new Error("Connection destroyed")).code=s.ConnectionDestroyed),t(e)}))})),destroy(){p()}}},y=function(e,n){return console.error("[Dromo-External-Error] There was an error running your ".concat(n,"."),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 n(void 0,void 0,void 0,(function(){var s,c,a;return t(this,(function(l){switch(l.label){case 0:return s=new Map,c=o.map((function(n){return e({},n)})),[4,r.reduce((function(e,r){return n(void 0,void 0,void 0,(function(){return t(this,(function(o){switch(o.label){case 0:return[4,e.then((function(){return n(void 0,void 0,void 0,(function(){var e,n,o;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),e=b("column hook"),[4,r.callback(c)];case 1:return n=t.sent(),k(e),n.forEach((function(e){if(void 0!==e.value||void 0!==e.info){var n={};void 0!==e.value&&(n.value=e.value,c[e.index].value=e.value),void 0!==e.info&&(n.info=e.info),s.set(e.index,n)}})),[3,3];case 2:return o=t.sent(),i(o,"column hooks"),[3,3];case 3:return[2]}}))}))}))];case 1:return o.sent(),[2]}}))}))}),Promise.resolve())];case 1:return l.sent(),a=[],s.forEach((function(n,t){return a.push(e(e({},n),{index:t}))})),[2,a]}}))}))},R=function(e){return void 0===e.value&&void 0===e.info&&void 0===e.selectOptions&&void 0===e.manyToOne},E=function(e,r,o,i,s){return n(void 0,void 0,void 0,(function(){var c,a,l,u,d,h,f,m,p,v,w,g,y;return t(this,(function(I){switch(I.label){case 0:c=new Map,a=new Map(e.map((function(e){return[e.index,e]}))),l=function(e,n){for(var t,r=a.get(e),o=function(n,o){if(R(o))return"continue";var i=r.row[n],s=Array.isArray(i.manyToOne),a="manyToOne"in o&&Array.isArray(o.manyToOne);if(s&&!a)throw new Error("".concat(n," should have manyToOne defined as an array."));if(s&&a&&i.manyToOne.length!==o.manyToOne.length)throw new Error("".concat(n," should be array of length ").concat(i.manyToOne.length));var l=c.get(e)||{},u=null!==(t=l[n])&&void 0!==t?t:{},d=[];a?(u.manyToOne=[],o.manyToOne.forEach((function(e,n){if(!R(e)){var t={};u.manyToOne.push(t),d.push({fieldOutput:e,rowDataField:i.manyToOne[n],cellChange:t})}}))):d.push({fieldOutput:o,rowDataField:i,cellChange:u}),d.forEach((function(e){var n=e.fieldOutput,t=e.rowDataField,r=e.cellChange;void 0!==n.value&&(r.value=n.value,t.value=n.value),void 0!==n.info&&(r.info=n.info,t.info=n.info),void 0!==n.selectOptions&&(r.selectOptions=n.selectOptions,t.selectOptions=n.selectOptions)})),l[n]=u,c.set(e,l)},i=0,s=Object.entries(null!=n?n:{});i<s.length;i++){var l=s[i];o(l[0],l[1])}},u=0,d=i,I.label=1;case 1:if(!(u<d.length))return[3,6];h=d[u],I.label=2;case 2:return I.trys.push([2,4,,5]),f=b("bulk row hook"),[4,h(e,r)];case 3:for(m=I.sent(),k(f),p=0,v=m;p<v.length;p++)w=v[p],l(w.index,w.row);return[3,5];case 4:return g=I.sent(),s(g,"bulk row hooks"),[3,5];case 5:return u++,[3,1];case 6:return[4,Promise.all(e.map((function(e){return n(void 0,void 0,void 0,(function(){var n,i,c,a,u,d;return t(this,(function(t){switch(t.label){case 0:n=0,i=o,t.label=1;case 1:if(!(n<i.length))return[3,6];c=i[n],t.label=2;case 2:return t.trys.push([2,4,,5]),a=b("row hook"),[4,c(e,r)];case 3:return u=t.sent(),k(a),l(e.index,u.row),[3,5];case 4:return d=t.sent(),s(d,"row hooks"),[3,5];case 5:return n++,[3,1];case 6:return[2]}}))}))})))];case 7:return I.sent(),y=[],c.forEach((function(e,n){y.push({index:n,row:e})})),[2,y]}}))}))},H=function(e,r,o){return n(void 0,void 0,void 0,(function(){return t(this,(function(i){return[2,Promise.all(e.map((function(e){return n(void 0,void 0,void 0,(function(){return t(this,(function(i){return r.forEach((function(r){return n(void 0,void 0,void 0,(function(){var n,i;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),n=b("row delete hook"),[4,r(e)];case 1:return t.sent(),k(n),[3,3];case 2:return i=t.sent(),o(i,"row delete hooks"),[3,3];case 3:return[2]}}))}))})),[2]}))}))})))]}))}))},D=function(e,r,o,i,s){return n(void 0,void 0,void 0,(function(){return t(this,(function(c){switch(c.label){case 0:return[4,Promise.all(o.map((function(o){return n(void 0,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:if(e!==o.type)return[2,Promise.resolve()];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,o.callback(i,r)];case 2:return[2,t.sent()];case 3:return n=t.sent(),s(n,"step hook ".concat(e)),[2,Promise.resolve()];case 4:return[2]}}))}))})))];case 1:return c.sent(),[2]}}))}))},C=function(e,r,o,i,s){return n(void 0,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,o(e,r,i)];case 1:return[2,t.sent()];case 2:return n=t.sent(),s(n,"before finish callback"),[3,3];case 3:return[2]}}))}))},x="dromo-container",O=function(n){var t=e({},n);return t.validators&&(t.validators=t.validators.map((function(n){return("regex_match"===n.validate||"regex_exclude"===n.validate)&&n.regex instanceof RegExp?e(e({},n),{regex:n.regex.source,regexOptions:{ignoreCase:n.regex.flags.includes("i"),dotAll:n.regex.flags.includes("s"),multiline:n.regex.flags.includes("m"),unicode:n.regex.flags.includes("u")}}):n}))),t};return function(){function r(r,o,i,s){var c=this;this.embedInline=!1,this.columnHooks=[],this.bulkRowHooks=[],this.rowHooks=[],this.stepHooks=[],this.rowDeleteHooks=[],this.initChild=function(){return n(c,void 0,void 0,(function(){var n,r,o,i,s;return t(this,(function(t){switch(t.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 n=t.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,n.setNumRegisteredRowHooks(this.totalNumRowHooks())];case 2:return t.sent(),[4,n.setNumRegisteredColHooks(this.columnHooks.length)];case 3:return t.sent(),[4,n.setNumRegisteredRowDeleteHooks(this.rowDeleteHooks.length)];case 4:return t.sent(),[4,n.setEmbedInline(this.embedInline)];case 5:return t.sent(),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,n.init(this.licenseKey,this.fields,o,this.user,this.appHost)]):[3,7];case 6:return t.sent(),[3,10];case 7:return this.schemaId?[4,n.initFromSavedSchema(this.licenseKey,this.schemaId,this.appHost,{user:this.user,developmentMode:this.developmentMode,headerRowOverride:this.headerRowOverride})]:[3,9];case 8:return t.sent(),[3,10];case 9:console.error("Invalid Dromo configuration"),t.label=10;case 10:return[2]}}))}))},this.initIFrame=function(){var e,n,t,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===(n=c.settings)||void 0===n?void 0:n.version)?"https://widget-v1.dromo.io/":l;if(!document.getElementById(c.iframeId)){var s=document.createElement("iframe"),a=null!==(r=null===(t=c.settings)||void 0===t?void 0:t.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 e=c,r=c.iframe;r?c.connection=g({iframe:r,methods:{handleColumnHooks:function(r,o){return n(this,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:return n=e.columnHooks.filter((function(e){return e.fieldName===r})),[4,I(n,o,y)];case 1:return[2,t.sent()]}}))}))},handleRowHooks:function(r,o){return n(this,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return[4,E(r,o,e.rowHooks.map((function(e){return e.callback})),e.bulkRowHooks,y)];case 1:return[2,n.sent()]}}))}))},handleStepHook:function(r,o){return n(this,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return[4,D(r,o,e.stepHooks,e,y)];case 1:return[2,n.sent()]}}))}))},handleRowDeleteHooks:function(r){return n(this,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return[4,H(r,e.rowDeleteHooks,y)];case 1:return n.sent(),[2]}}))}))},handleBeforeFinishCallback:function(r,o){return n(this,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return e.beforeFinishCallback?[4,C(r,o,e.beforeFinishCallback,e,y)]:[3,2];case 1:return[2,n.sent()];case 2:return[2]}}))}))},handleResults:function(r,o){return n(this,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:if(!e.resultsCallback)return[3,4];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,e.resultsCallback(r,o)];case 2:return t.sent(),[3,4];case 3:return n=t.sent(),console.error("[Dromo-External-Error] There was an error in your onResult callback.",n),[3,4];case 4:return e.close(),[2]}}))}))},handleCloseModal:function(){e.close()},handleCancel:function(){if(e.cancelCallback)try{e.cancelCallback()}catch(e){console.error("[Dromo-External-Error] There was an error in your cancel callback.",e)}e.close()}}}):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,n){c.columnHooks.push({fieldName:e,callback:n}),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,n){c.stepHooks.push({type:e,callback:n})},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.registerAllHooks=function(e){if(e.columnHooks)for(var n=0,t=e.columnHooks;n<t.length;n++){var r=t[n],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 l=a[s];c.registerRowHook(l)}if(e.bulkRowHooks)for(var u=0,d=e.bulkRowHooks;u<d.length;u++){var h=d[u];c.registerBulkRowHook(h)}if(e.rowDeleteHooks)for(var f=0,m=e.rowDeleteHooks;f<m.length;f++){var p=m[f];c.registerRowDeleteHook(p)}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)}e.beforeFinishCallback&&c.beforeFinish(e.beforeFinishCallback)},this.onResults=function(e){c.resultsCallback=e},this.onCancel=function(e){c.cancelCallback=e},this.setUser=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.user=e,this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().setUser(this.user)];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))},this.addField=function(e,r){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().addField(O(e),r)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.label=4;case 4:return[2]}}))}))},this.removeField=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().removeField(e)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.label=4;case 4:return[2]}}))}))},this.updateInfoMessages=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().updateInfoMessages(e)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.label=4;case 4:return[2]}}))}))},this.setHeaderRowOverride=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.headerRowOverride=e,this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().setHeaderRowOverride(e)];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))},this.open=function(){return n(c,void 0,void 0,(function(){return t(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 n(c,void 0,void 0,(function(){var n,r;return t(this,(function(t){switch(t.label){case 0:this.embedInline=!0,t.label=1;case 1:if(t.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)+"-"+x)),"string"==typeof e){if(null===(n=document.getElementById(e)))throw new Error("WRAPPER_NOT_FOUND");this.wrapper=n,this.wrapperId=e}return this.iframe||(this.initIFrame(),this.createConnection(),this.addIFrameToWrapper()),[4,this.initChild()];case 2:return t.sent(),this.showIframe(),[3,4];case 3:throw"WRAPPER_NOT_FOUND"===(r=t.sent()).message&&console.error("[Dromo-Error] Could not find wrapper using provided ID."),r;case 4:return[2]}}))}))},this.addRows=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().addRows(e)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.label=4;case 4:return[2]}}))}))},this.removeRows=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().removeRows(e)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.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 n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.developmentMode=e,this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().setDevelopmentMode(this.developmentMode)];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))},this.rehydrate=function(e,r){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.wrapper||(this.initIFrame(),this.createConnection(),this.mountIFrame()),[4,this.initChild()];case 1:return n.sent(),[4,this.connection.promise];case 2:return[4,n.sent().rehydrate(e,r)];case 3:return n.sent(),this.showWrapper(),[2]}}))}))},this.iframeId=Math.random().toString(36).substring(7)+"-dromo-iframe-element",this.wrapperId=Math.random().toString(36).substring(7)+"-"+x,this.appHost=document.location.hostname,void 0!==i&&void 0!==s?(this.licenseKey=r,this.fields=o.map(O),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 n=Object.entries(e).filter((function(e){e[0];var n=e[1];try{return structuredClone(n),!1}catch(e){return!0}})).map((function(e){return e[0]}));if(n.length>0){var t=n.join(", ");throw new Error("[Dromo-External-Error] The Dromo importer received non-cloneable parameters: ".concat(t,". 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,l=e.hooks,u=e.rehydrateState;return n(void 0,void 0,void 0,(function(){var e;return t(o,(function(n){switch(n.label){case 0:return(e=new r(i,c,a,{id:"headless-review"})).registerAllHooks(l),[4,e.rehydrate(u,s)];case 1:return n.sent(),e.open(),[2,e]}}))}))},r}()}(); | ||
***************************************************************************** */var e=function(){return(e=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e}).apply(this,arguments)};function n(e,n,t,r){return new(t||(t=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 n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(s,c)}a((r=r.apply(e,n||[])).next())}))}function t(e,n){var t,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;s;)try{if(t=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=n.call(e,s)}catch(e){i=[6,e],r=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}var r,o,i,s,c,a,l={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 u={"http:":"80","https:":"443"},d=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,h=["file:","data:"];const f=({name:e,message:n,stack:t})=>({name:e,message:n,stack:t});let m=0;var p=()=>++m,v=(e,n,t,r,c)=>{const{localName:l,local:u,remote:d,originForSending:h,originForReceiving:f}=n;let m=!1;c(`${l}: Connecting call sender`);const v=e=>(...n)=>{let t;c(`${l}: Sending ${e}() call`);try{d.closed&&(t=!0)}catch(e){t=!0}if(t&&r(),m){const n=new Error(`Unable to send ${e}() call due to destroyed connection`);throw n.code=s.ConnectionDestroyed,n}return new Promise(((t,r)=>{const s=p(),m=n=>{if(n.source!==d||n.data.penpal!==o.Reply||n.data.id!==s)return;if(n.origin!==f)return void c(`${l} received message from origin ${n.origin} which did not match expected origin ${f}`);const h=n.data;c(`${l}: Received ${e}() reply`),u.removeEventListener(a.Message,m);let p=h.returnValue;h.returnValueIsError&&(p=(e=>{const n=new Error;return Object.keys(e).forEach((t=>n[t]=e[t])),n})(p)),(h.resolution===i.Fulfilled?t:r)(p)};u.addEventListener(a.Message,m);const v={penpal:o.Call,id:s,methodName:e,args:n};d.postMessage(v,h)}))};return t.reduce(((e,n)=>(e[n]=v(n),e)),e),()=>{m=!0}},w=(e,n,t,r,s)=>{const{destroy:l,onDestroy:u}=r;let d,h;const m={};return r=>{if(r.origin!==n)return void s(`Parent: Handshake - Received ACK message from origin ${r.origin} which did not match expected origin ${n}`);s("Parent: Handshake - Received ACK");const p={localName:"Parent",local:window,remote:r.source,originForSending:t,originForReceiving:n};d&&d(),d=((e,n,t)=>{const{localName:r,local:s,remote:l,originForSending:u,originForReceiving:d}=e;let h=!1;const m=e=>{if(e.source!==l||e.data.penpal!==o.Call)return;if(e.origin!==d)return void t(`${r} received message from origin ${e.origin} which did not match expected origin ${d}`);const s=e.data,{methodName:a,args:m,id:p}=s;t(`${r}: Received ${a}() call`);const v=e=>n=>{if(t(`${r}: Sending ${a}() reply`),h)return void t(`${r}: Unable to send ${a}() reply due to destroyed connection`);const s={penpal:o.Reply,id:p,resolution:e,returnValue:n};e===i.Rejected&&n instanceof Error&&(s.returnValue=f(n),s.returnValueIsError=!0);try{l.postMessage(s,u)}catch(e){if(e.name===c.DataCloneError){const n={penpal:o.Reply,id:p,resolution:i.Rejected,returnValue:f(e),returnValueIsError:!0};l.postMessage(n,u)}throw e}};new Promise((e=>e(n[a].apply(n,m)))).then(v(i.Fulfilled),v(i.Rejected))};return s.addEventListener(a.Message,m),()=>{h=!0,s.removeEventListener(a.Message,m)}})(p,e,s),u(d),h&&h.forEach((e=>{delete m[e]})),h=r.data.methodNames;const w=v(m,p,h,l,s);return u(w),m}};var g=e=>{let{iframe:n,methods:t={},childOrigin:r,timeout:i,debug:c=!1}=e;const l=(e=>(...n)=>{e&&console.log("[Penpal]",...n)})(c),f=(()=>{const e=[];let n=!1;return{destroy(t){n=!0,e.forEach((e=>{e(t)}))},onDestroy(t){n?t():e.push(t)}}})(),{onDestroy:m,destroy:p}=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}})(n),r=(e=>{if(e&&h.find((n=>e.startsWith(n))))return"null";const n=document.location,t=d.exec(e);let r,o,i;return t?(r=t[1]?t[1]:n.protocol,o=t[2],i=t[4]):(r=n.protocol,o=n.hostname,i=n.port),`${r}//${o}${i&&i!==u[r]?`:${i}`:""}`})(n.src));const v="null"===r?"*":r,g=((e,n,t,r)=>i=>{if(i.origin!==t)return void e(`Parent: Handshake - Received SYN message from origin ${i.origin} which did not match expected origin ${t}`);e("Parent: Handshake - Received SYN, responding with SYN-ACK");const s={penpal:o.SynAck,methodNames:Object.keys(n)};i.source.postMessage(s,r)})(l,t,r,v),y=w(t,r,v,f,l);return{promise:new Promise(((e,t)=>{const r=((e,n)=>{let t;return void 0!==e&&(t=window.setTimeout((()=>{const t=new Error(`Connection timed out after ${e}ms`);t.code=s.ConnectionTimeout,n(t)}),e)),()=>{clearTimeout(t)}})(i,p),c=t=>{if(t.source===n.contentWindow&&t.data)if(t.data.penpal!==o.Syn)if(t.data.penpal!==o.Ack);else{const n=y(t);n&&(r(),e(n))}else g(t)};window.addEventListener(a.Message,c),l("Parent: Awaiting handshake"),((e,n)=>{const{destroy:t,onDestroy:r}=n,o=setInterval((()=>{e.isConnected||(clearInterval(o),t())}),6e4);r((()=>{clearInterval(o)}))})(n,f),m((e=>{window.removeEventListener(a.Message,c),e||((e=new Error("Connection destroyed")).code=s.ConnectionDestroyed),t(e)}))})),destroy(){p()}}},y=function(e,n){return console.error("[Dromo-External-Error] There was an error running your ".concat(n,"."),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 n(void 0,void 0,void 0,(function(){var s,c,a;return t(this,(function(l){switch(l.label){case 0:return s=new Map,c=o.map((function(n){return e({},n)})),[4,r.reduce((function(e,r){return n(void 0,void 0,void 0,(function(){return t(this,(function(o){switch(o.label){case 0:return[4,e.then((function(){return n(void 0,void 0,void 0,(function(){var e,n,o;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),e=b("column hook"),[4,r.callback(c)];case 1:return n=t.sent(),k(e),n.forEach((function(e){if(void 0!==e.value||void 0!==e.info){var n={};void 0!==e.value&&(n.value=e.value,c[e.index].value=e.value),void 0!==e.info&&(n.info=e.info),s.set(e.index,n)}})),[3,3];case 2:return o=t.sent(),i(o,"column hooks"),[3,3];case 3:return[2]}}))}))}))];case 1:return o.sent(),[2]}}))}))}),Promise.resolve())];case 1:return l.sent(),a=[],s.forEach((function(n,t){return a.push(e(e({},n),{index:t}))})),[2,a]}}))}))},R=function(e){return void 0===e.value&&void 0===e.info&&void 0===e.selectOptions&&void 0===e.manyToOne},E=function(e,r,o,i,s){return n(void 0,void 0,void 0,(function(){var c,a,l,u,d,h,f,m,p,v,w,g,y;return t(this,(function(I){switch(I.label){case 0:c=new Map,a=new Map(e.map((function(e){return[e.index,e]}))),l=function(e,n){for(var t,r=a.get(e),o=function(n,o){if(R(o))return"continue";var i=r.row[n],s=Array.isArray(i.manyToOne),a="manyToOne"in o&&Array.isArray(o.manyToOne);if(s&&!a)throw new Error("".concat(n," should have manyToOne defined as an array."));if(s&&a&&i.manyToOne.length!==o.manyToOne.length)throw new Error("".concat(n," should be array of length ").concat(i.manyToOne.length));var l=c.get(e)||{},u=null!==(t=l[n])&&void 0!==t?t:{},d=[];a?(u.manyToOne=[],o.manyToOne.forEach((function(e,n){if(!R(e)){var t={};u.manyToOne.push(t),d.push({fieldOutput:e,rowDataField:i.manyToOne[n],cellChange:t})}}))):d.push({fieldOutput:o,rowDataField:i,cellChange:u}),d.forEach((function(e){var n=e.fieldOutput,t=e.rowDataField,r=e.cellChange;void 0!==n.value&&(r.value=n.value,t.value=n.value),void 0!==n.info&&(r.info=n.info,t.info=n.info),void 0!==n.selectOptions&&(r.selectOptions=n.selectOptions,t.selectOptions=n.selectOptions)})),l[n]=u,c.set(e,l)},i=0,s=Object.entries(null!=n?n:{});i<s.length;i++){var l=s[i];o(l[0],l[1])}},u=0,d=i,I.label=1;case 1:if(!(u<d.length))return[3,6];h=d[u],I.label=2;case 2:return I.trys.push([2,4,,5]),f=b("bulk row hook"),[4,h(e,r)];case 3:for(m=I.sent(),k(f),p=0,v=m;p<v.length;p++)w=v[p],l(w.index,w.row);return[3,5];case 4:return g=I.sent(),s(g,"bulk row hooks"),[3,5];case 5:return u++,[3,1];case 6:return[4,Promise.all(e.map((function(e){return n(void 0,void 0,void 0,(function(){var n,i,c,a,u,d;return t(this,(function(t){switch(t.label){case 0:n=0,i=o,t.label=1;case 1:if(!(n<i.length))return[3,6];c=i[n],t.label=2;case 2:return t.trys.push([2,4,,5]),a=b("row hook"),[4,c(e,r)];case 3:return u=t.sent(),k(a),l(e.index,u.row),[3,5];case 4:return d=t.sent(),s(d,"row hooks"),[3,5];case 5:return n++,[3,1];case 6:return[2]}}))}))})))];case 7:return I.sent(),y=[],c.forEach((function(e,n){y.push({index:n,row:e})})),[2,y]}}))}))},H=function(e,r,o){return n(void 0,void 0,void 0,(function(){return t(this,(function(i){return[2,Promise.all(e.map((function(e){return n(void 0,void 0,void 0,(function(){return t(this,(function(i){return r.forEach((function(r){return n(void 0,void 0,void 0,(function(){var n,i;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),n=b("row delete hook"),[4,r(e)];case 1:return t.sent(),k(n),[3,3];case 2:return i=t.sent(),o(i,"row delete hooks"),[3,3];case 3:return[2]}}))}))})),[2]}))}))})))]}))}))},D=function(e,r,o,i,s){return n(void 0,void 0,void 0,(function(){return t(this,(function(c){switch(c.label){case 0:return[4,Promise.all(o.map((function(o){return n(void 0,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:if(e!==o.type)return[2,Promise.resolve()];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,o.callback(i,r)];case 2:return[2,t.sent()];case 3:return n=t.sent(),s(n,"step hook ".concat(e)),[2,Promise.resolve()];case 4:return[2]}}))}))})))];case 1:return c.sent(),[2]}}))}))},C=function(e,r,o,i,s){return n(void 0,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,o(e,r,i)];case 1:return[2,t.sent()];case 2:return n=t.sent(),s(n,"before finish callback"),[3,3];case 3:return[2]}}))}))},x="dromo-container",O=function(n){var t=e({},n);return t.validators&&(t.validators=t.validators.map((function(n){return("regex_match"===n.validate||"regex_exclude"===n.validate)&&n.regex instanceof RegExp?e(e({},n),{regex:n.regex.source,regexOptions:{ignoreCase:n.regex.flags.includes("i"),dotAll:n.regex.flags.includes("s"),multiline:n.regex.flags.includes("m"),unicode:n.regex.flags.includes("u")}}):n}))),t};return function(){function r(r,o,i,s){var c=this;this.embedInline=!1,this.columnHooks=[],this.bulkRowHooks=[],this.rowHooks=[],this.stepHooks=[],this.rowDeleteHooks=[],this.initChild=function(){return n(c,void 0,void 0,(function(){var n,r,o,i,s;return t(this,(function(t){switch(t.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 n=t.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,n.setNumRegisteredRowHooks(this.totalNumRowHooks())];case 2:return t.sent(),[4,n.setNumRegisteredColHooks(this.columnHooks.length)];case 3:return t.sent(),[4,n.setNumRegisteredRowDeleteHooks(this.rowDeleteHooks.length)];case 4:return t.sent(),[4,n.setEmbedInline(this.embedInline)];case 5:return t.sent(),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,n.init(this.licenseKey,this.fields,o,this.user,this.appHost)]):[3,7];case 6:return t.sent(),[3,10];case 7:return this.schemaId?[4,n.initFromSavedSchema(this.licenseKey,this.schemaId,this.appHost,{user:this.user,developmentMode:this.developmentMode,headerRowOverride:this.headerRowOverride})]:[3,9];case 8:return t.sent(),[3,10];case 9:console.error("Invalid Dromo configuration"),t.label=10;case 10:return[2]}}))}))},this.initIFrame=function(){var e,n,t,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===(n=c.settings)||void 0===n?void 0:n.version)?"https://widget-v1.dromo.io/":l;if(!document.getElementById(c.iframeId)){var s=document.createElement("iframe"),a=null!==(r=null===(t=c.settings)||void 0===t?void 0:t.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 e=c,r=c.iframe;r?c.connection=g({iframe:r,methods:{handleColumnHooks:function(r,o){return n(this,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:return n=e.columnHooks.filter((function(e){return e.fieldName===r})),[4,I(n,o,y)];case 1:return[2,t.sent()]}}))}))},handleRowHooks:function(r,o){return n(this,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return[4,E(r,o,e.rowHooks.map((function(e){return e.callback})),e.bulkRowHooks,y)];case 1:return[2,n.sent()]}}))}))},handleStepHook:function(r,o){return n(this,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return[4,D(r,o,e.stepHooks,e,y)];case 1:return[2,n.sent()]}}))}))},handleRowDeleteHooks:function(r){return n(this,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return[4,H(r,e.rowDeleteHooks,y)];case 1:return n.sent(),[2]}}))}))},handleBeforeFinishCallback:function(r,o){return n(this,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return e.beforeFinishCallback?[4,C(r,o,e.beforeFinishCallback,e,y)]:[3,2];case 1:return[2,n.sent()];case 2:return[2]}}))}))},handleResults:function(r,o){return n(this,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:if(!e.resultsCallback)return[3,4];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,e.resultsCallback(r,o)];case 2:return t.sent(),[3,4];case 3:return n=t.sent(),console.error("[Dromo-External-Error] There was an error in your onResult callback.",n),[3,4];case 4:return e.close(),[2]}}))}))},handleCloseModal:function(){e.close()},handleCancel:function(){if(e.cancelCallback)try{e.cancelCallback()}catch(e){console.error("[Dromo-External-Error] There was an error in your cancel callback.",e)}e.close()}}}):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,n){c.columnHooks.push({fieldName:e,callback:n}),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,n){c.stepHooks.push({type:e,callback:n})},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.registerAllHooks=function(e){if(e.columnHooks)for(var n=0,t=e.columnHooks;n<t.length;n++){var r=t[n],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 l=a[s];c.registerRowHook(l)}if(e.bulkRowHooks)for(var u=0,d=e.bulkRowHooks;u<d.length;u++){var h=d[u];c.registerBulkRowHook(h)}if(e.rowDeleteHooks)for(var f=0,m=e.rowDeleteHooks;f<m.length;f++){var p=m[f];c.registerRowDeleteHook(p)}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)}e.beforeFinishCallback&&c.beforeFinish(e.beforeFinishCallback)},this.onResults=function(e){c.resultsCallback=e},this.onCancel=function(e){c.cancelCallback=e},this.setUser=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.user=e,this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().setUser(this.user)];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))},this.addField=function(e,r){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().addField(O(e),r)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.label=4;case 4:return[2]}}))}))},this.removeField=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().removeField(e)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.label=4;case 4:return[2]}}))}))},this.updateInfoMessages=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().updateInfoMessages(e)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.label=4;case 4:return[2]}}))}))},this.setHeaderRowOverride=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.headerRowOverride=e,this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().setHeaderRowOverride(e)];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))},this.setConfirmationMessage=function(e,r){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().setConfirmationMessage(e,r)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.label=4;case 4:return[2]}}))}))},this.open=function(){return n(c,void 0,void 0,(function(){return t(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 n(c,void 0,void 0,(function(){var n,r;return t(this,(function(t){switch(t.label){case 0:this.embedInline=!0,t.label=1;case 1:if(t.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)+"-"+x)),"string"==typeof e){if(null===(n=document.getElementById(e)))throw new Error("WRAPPER_NOT_FOUND");this.wrapper=n,this.wrapperId=e}return this.iframe||(this.initIFrame(),this.createConnection(),this.addIFrameToWrapper()),[4,this.initChild()];case 2:return t.sent(),this.showIframe(),[3,4];case 3:throw"WRAPPER_NOT_FOUND"===(r=t.sent()).message&&console.error("[Dromo-Error] Could not find wrapper using provided ID."),r;case 4:return[2]}}))}))},this.addRows=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().addRows(e)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.label=4;case 4:return[2]}}))}))},this.removeRows=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().removeRows(e)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.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 n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.developmentMode=e,this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().setDevelopmentMode(this.developmentMode)];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))},this.rehydrate=function(e,r){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.wrapper||(this.initIFrame(),this.createConnection(),this.mountIFrame()),[4,this.initChild()];case 1:return n.sent(),[4,this.connection.promise];case 2:return[4,n.sent().rehydrate(e,r)];case 3:return n.sent(),this.showWrapper(),[2]}}))}))},this.iframeId=Math.random().toString(36).substring(7)+"-dromo-iframe-element",this.wrapperId=Math.random().toString(36).substring(7)+"-"+x,this.appHost=document.location.hostname,void 0!==i&&void 0!==s?(this.licenseKey=r,this.fields=o.map(O),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 n=Object.entries(e).filter((function(e){e[0];var n=e[1];try{return structuredClone(n),!1}catch(e){return!0}})).map((function(e){return e[0]}));if(n.length>0){var t=n.join(", ");throw new Error("[Dromo-External-Error] The Dromo importer received non-cloneable parameters: ".concat(t,". 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,l=e.hooks,u=e.rehydrateState;return n(void 0,void 0,void 0,(function(){var e;return t(o,(function(n){switch(n.label){case 0:return(e=new r(i,c,a,{id:"headless-review"})).registerAllHooks(l),[4,e.rehydrate(u,s)];case 1:return n.sent(),e.open(),[2,e]}}))}))},r}()}(); | ||
//# sourceMappingURL=DromoUploader.js.map |
@@ -102,2 +102,11 @@ import { ITableMessage, IMessagesForCell, IColumnHook, IColumnHookInput, IColumnHookOutput, IRowHook, IRowHookInput, IRowHookOutput, IDeveloperField, IDeveloperSettings, IDeveloperStyleOverrides, IUser, IValidatorField, IRowHookOutputInternal, IResultMetadata, IReviewStepData, IStepHook, IUploadStepData, IRowDeleteHook, IBulkRowHook, IBeforeFinishCallback, IBeforeFinishOutput, IPositionSpec, IConnectionMethods, ISelectField, IImporterOptions, IAllHooks, IRowToAdd } from "./interfaces"; | ||
/** | ||
* Function called by the developer to change the message displayed when the | ||
* user clicks 'Finish' on the review screen. Can optionally also override | ||
* the button text. | ||
*/ | ||
setConfirmationMessage: (messageHTML: string, options?: { | ||
submitButtonText?: string; | ||
cancelButtonText?: string; | ||
}) => Promise<void>; | ||
/** | ||
* Function called by developer called to open the iframe | ||
@@ -104,0 +113,0 @@ */ |
@@ -15,3 +15,3 @@ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).DromoUploader=n()}(this,(function(){"use strict"; | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */var e=function(){return(e=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e}).apply(this,arguments)};function n(e,n,t,r){return new(t||(t=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 n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(s,c)}a((r=r.apply(e,n||[])).next())}))}function t(e,n){var t,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;s;)try{if(t=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=n.call(e,s)}catch(e){i=[6,e],r=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}var r,o,i,s,c,a,l={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 u={"http:":"80","https:":"443"},d=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,h=["file:","data:"];const f=({name:e,message:n,stack:t})=>({name:e,message:n,stack:t});let p=0;var m=()=>++p,v=(e,n,t,r,c)=>{const{localName:l,local:u,remote:d,originForSending:h,originForReceiving:f}=n;let p=!1;c(`${l}: Connecting call sender`);const v=e=>(...n)=>{let t;c(`${l}: Sending ${e}() call`);try{d.closed&&(t=!0)}catch(e){t=!0}if(t&&r(),p){const n=new Error(`Unable to send ${e}() call due to destroyed connection`);throw n.code=s.ConnectionDestroyed,n}return new Promise(((t,r)=>{const s=m(),p=n=>{if(n.source!==d||n.data.penpal!==o.Reply||n.data.id!==s)return;if(n.origin!==f)return void c(`${l} received message from origin ${n.origin} which did not match expected origin ${f}`);const h=n.data;c(`${l}: Received ${e}() reply`),u.removeEventListener(a.Message,p);let m=h.returnValue;h.returnValueIsError&&(m=(e=>{const n=new Error;return Object.keys(e).forEach((t=>n[t]=e[t])),n})(m)),(h.resolution===i.Fulfilled?t:r)(m)};u.addEventListener(a.Message,p);const v={penpal:o.Call,id:s,methodName:e,args:n};d.postMessage(v,h)}))};return t.reduce(((e,n)=>(e[n]=v(n),e)),e),()=>{p=!0}},w=(e,n,t,r,s)=>{const{destroy:l,onDestroy:u}=r;let d,h;const p={};return r=>{if(r.origin!==n)return void s(`Parent: Handshake - Received ACK message from origin ${r.origin} which did not match expected origin ${n}`);s("Parent: Handshake - Received ACK");const m={localName:"Parent",local:window,remote:r.source,originForSending:t,originForReceiving:n};d&&d(),d=((e,n,t)=>{const{localName:r,local:s,remote:l,originForSending:u,originForReceiving:d}=e;let h=!1;const p=e=>{if(e.source!==l||e.data.penpal!==o.Call)return;if(e.origin!==d)return void t(`${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;t(`${r}: Received ${a}() call`);const v=e=>n=>{if(t(`${r}: Sending ${a}() reply`),h)return void t(`${r}: Unable to send ${a}() reply due to destroyed connection`);const s={penpal:o.Reply,id:m,resolution:e,returnValue:n};e===i.Rejected&&n instanceof Error&&(s.returnValue=f(n),s.returnValueIsError=!0);try{l.postMessage(s,u)}catch(e){if(e.name===c.DataCloneError){const n={penpal:o.Reply,id:m,resolution:i.Rejected,returnValue:f(e),returnValueIsError:!0};l.postMessage(n,u)}throw e}};new Promise((e=>e(n[a].apply(n,p)))).then(v(i.Fulfilled),v(i.Rejected))};return s.addEventListener(a.Message,p),()=>{h=!0,s.removeEventListener(a.Message,p)}})(m,e,s),u(d),h&&h.forEach((e=>{delete p[e]})),h=r.data.methodNames;const w=v(p,m,h,l,s);return u(w),p}};var g=e=>{let{iframe:n,methods:t={},childOrigin:r,timeout:i,debug:c=!1}=e;const l=(e=>(...n)=>{e&&console.log("[Penpal]",...n)})(c),f=(()=>{const e=[];let n=!1;return{destroy(t){n=!0,e.forEach((e=>{e(t)}))},onDestroy(t){n?t():e.push(t)}}})(),{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}})(n),r=(e=>{if(e&&h.find((n=>e.startsWith(n))))return"null";const n=document.location,t=d.exec(e);let r,o,i;return t?(r=t[1]?t[1]:n.protocol,o=t[2],i=t[4]):(r=n.protocol,o=n.hostname,i=n.port),`${r}//${o}${i&&i!==u[r]?`:${i}`:""}`})(n.src));const v="null"===r?"*":r,g=((e,n,t,r)=>i=>{if(i.origin!==t)return void e(`Parent: Handshake - Received SYN message from origin ${i.origin} which did not match expected origin ${t}`);e("Parent: Handshake - Received SYN, responding with SYN-ACK");const s={penpal:o.SynAck,methodNames:Object.keys(n)};i.source.postMessage(s,r)})(l,t,r,v),y=w(t,r,v,f,l);return{promise:new Promise(((e,t)=>{const r=((e,n)=>{let t;return void 0!==e&&(t=window.setTimeout((()=>{const t=new Error(`Connection timed out after ${e}ms`);t.code=s.ConnectionTimeout,n(t)}),e)),()=>{clearTimeout(t)}})(i,m),c=t=>{if(t.source===n.contentWindow&&t.data)if(t.data.penpal!==o.Syn)if(t.data.penpal!==o.Ack);else{const n=y(t);n&&(r(),e(n))}else g(t)};window.addEventListener(a.Message,c),l("Parent: Awaiting handshake"),((e,n)=>{const{destroy:t,onDestroy:r}=n,o=setInterval((()=>{e.isConnected||(clearInterval(o),t())}),6e4);r((()=>{clearInterval(o)}))})(n,f),p((e=>{window.removeEventListener(a.Message,c),e||((e=new Error("Connection destroyed")).code=s.ConnectionDestroyed),t(e)}))})),destroy(){m()}}},y=function(e,n){return console.error("[Dromo-External-Error] There was an error running your ".concat(n,"."),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 n(void 0,void 0,void 0,(function(){var s,c,a;return t(this,(function(l){switch(l.label){case 0:return s=new Map,c=o.map((function(n){return e({},n)})),[4,r.reduce((function(e,r){return n(void 0,void 0,void 0,(function(){return t(this,(function(o){switch(o.label){case 0:return[4,e.then((function(){return n(void 0,void 0,void 0,(function(){var e,n,o;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),e=b("column hook"),[4,r.callback(c)];case 1:return n=t.sent(),k(e),n.forEach((function(e){if(void 0!==e.value||void 0!==e.info){var n={};void 0!==e.value&&(n.value=e.value,c[e.index].value=e.value),void 0!==e.info&&(n.info=e.info),s.set(e.index,n)}})),[3,3];case 2:return o=t.sent(),i(o,"column hooks"),[3,3];case 3:return[2]}}))}))}))];case 1:return o.sent(),[2]}}))}))}),Promise.resolve())];case 1:return l.sent(),a=[],s.forEach((function(n,t){return a.push(e(e({},n),{index:t}))})),[2,a]}}))}))},R=function(e){return void 0===e.value&&void 0===e.info&&void 0===e.selectOptions&&void 0===e.manyToOne},E=function(e,r,o,i,s){return n(void 0,void 0,void 0,(function(){var c,a,l,u,d,h,f,p,m,v,w,g,y;return t(this,(function(I){switch(I.label){case 0:c=new Map,a=new Map(e.map((function(e){return[e.index,e]}))),l=function(e,n){for(var t,r=a.get(e),o=function(n,o){if(R(o))return"continue";var i=r.row[n],s=Array.isArray(i.manyToOne),a="manyToOne"in o&&Array.isArray(o.manyToOne);if(s&&!a)throw new Error("".concat(n," should have manyToOne defined as an array."));if(s&&a&&i.manyToOne.length!==o.manyToOne.length)throw new Error("".concat(n," should be array of length ").concat(i.manyToOne.length));var l=c.get(e)||{},u=null!==(t=l[n])&&void 0!==t?t:{},d=[];a?(u.manyToOne=[],o.manyToOne.forEach((function(e,n){if(!R(e)){var t={};u.manyToOne.push(t),d.push({fieldOutput:e,rowDataField:i.manyToOne[n],cellChange:t})}}))):d.push({fieldOutput:o,rowDataField:i,cellChange:u}),d.forEach((function(e){var n=e.fieldOutput,t=e.rowDataField,r=e.cellChange;void 0!==n.value&&(r.value=n.value,t.value=n.value),void 0!==n.info&&(r.info=n.info,t.info=n.info),void 0!==n.selectOptions&&(r.selectOptions=n.selectOptions,t.selectOptions=n.selectOptions)})),l[n]=u,c.set(e,l)},i=0,s=Object.entries(null!=n?n:{});i<s.length;i++){var l=s[i];o(l[0],l[1])}},u=0,d=i,I.label=1;case 1:if(!(u<d.length))return[3,6];h=d[u],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],l(w.index,w.row);return[3,5];case 4:return g=I.sent(),s(g,"bulk row hooks"),[3,5];case 5:return u++,[3,1];case 6:return[4,Promise.all(e.map((function(e){return n(void 0,void 0,void 0,(function(){var n,i,c,a,u,d;return t(this,(function(t){switch(t.label){case 0:n=0,i=o,t.label=1;case 1:if(!(n<i.length))return[3,6];c=i[n],t.label=2;case 2:return t.trys.push([2,4,,5]),a=b("row hook"),[4,c(e,r)];case 3:return u=t.sent(),k(a),l(e.index,u.row),[3,5];case 4:return d=t.sent(),s(d,"row hooks"),[3,5];case 5:return n++,[3,1];case 6:return[2]}}))}))})))];case 7:return I.sent(),y=[],c.forEach((function(e,n){y.push({index:n,row:e})})),[2,y]}}))}))},H=function(e,r,o){return n(void 0,void 0,void 0,(function(){return t(this,(function(i){return[2,Promise.all(e.map((function(e){return n(void 0,void 0,void 0,(function(){return t(this,(function(i){return r.forEach((function(r){return n(void 0,void 0,void 0,(function(){var n,i;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),n=b("row delete hook"),[4,r(e)];case 1:return t.sent(),k(n),[3,3];case 2:return i=t.sent(),o(i,"row delete hooks"),[3,3];case 3:return[2]}}))}))})),[2]}))}))})))]}))}))},D=function(e,r,o,i,s){return n(void 0,void 0,void 0,(function(){return t(this,(function(c){switch(c.label){case 0:return[4,Promise.all(o.map((function(o){return n(void 0,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:if(e!==o.type)return[2,Promise.resolve()];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,o.callback(i,r)];case 2:return[2,t.sent()];case 3:return n=t.sent(),s(n,"step hook ".concat(e)),[2,Promise.resolve()];case 4:return[2]}}))}))})))];case 1:return c.sent(),[2]}}))}))},C=function(e,r,o,i,s){return n(void 0,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,o(e,r,i)];case 1:return[2,t.sent()];case 2:return n=t.sent(),s(n,"before finish callback"),[3,3];case 3:return[2]}}))}))},x="dromo-container",O=function(n){var t=e({},n);return t.validators&&(t.validators=t.validators.map((function(n){return("regex_match"===n.validate||"regex_exclude"===n.validate)&&n.regex instanceof RegExp?e(e({},n),{regex:n.regex.source,regexOptions:{ignoreCase:n.regex.flags.includes("i"),dotAll:n.regex.flags.includes("s"),multiline:n.regex.flags.includes("m"),unicode:n.regex.flags.includes("u")}}):n}))),t};return function(){function r(r,o,i,s){var c=this;this.embedInline=!1,this.columnHooks=[],this.bulkRowHooks=[],this.rowHooks=[],this.stepHooks=[],this.rowDeleteHooks=[],this.initChild=function(){return n(c,void 0,void 0,(function(){var n,r,o,i,s;return t(this,(function(t){switch(t.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 n=t.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,n.setNumRegisteredRowHooks(this.totalNumRowHooks())];case 2:return t.sent(),[4,n.setNumRegisteredColHooks(this.columnHooks.length)];case 3:return t.sent(),[4,n.setNumRegisteredRowDeleteHooks(this.rowDeleteHooks.length)];case 4:return t.sent(),[4,n.setEmbedInline(this.embedInline)];case 5:return t.sent(),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,n.init(this.licenseKey,this.fields,o,this.user,this.appHost)]):[3,7];case 6:return t.sent(),[3,10];case 7:return this.schemaId?[4,n.initFromSavedSchema(this.licenseKey,this.schemaId,this.appHost,{user:this.user,developmentMode:this.developmentMode,headerRowOverride:this.headerRowOverride})]:[3,9];case 8:return t.sent(),[3,10];case 9:console.error("Invalid Dromo configuration"),t.label=10;case 10:return[2]}}))}))},this.initIFrame=function(){var e,n,t,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===(n=c.settings)||void 0===n?void 0:n.version)?"https://widget-v1.dromo.io/":l;if(!document.getElementById(c.iframeId)){var s=document.createElement("iframe"),a=null!==(r=null===(t=c.settings)||void 0===t?void 0:t.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 e=c,r=c.iframe;r?c.connection=g({iframe:r,methods:{handleColumnHooks:function(r,o){return n(this,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:return n=e.columnHooks.filter((function(e){return e.fieldName===r})),[4,I(n,o,y)];case 1:return[2,t.sent()]}}))}))},handleRowHooks:function(r,o){return n(this,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return[4,E(r,o,e.rowHooks.map((function(e){return e.callback})),e.bulkRowHooks,y)];case 1:return[2,n.sent()]}}))}))},handleStepHook:function(r,o){return n(this,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return[4,D(r,o,e.stepHooks,e,y)];case 1:return[2,n.sent()]}}))}))},handleRowDeleteHooks:function(r){return n(this,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return[4,H(r,e.rowDeleteHooks,y)];case 1:return n.sent(),[2]}}))}))},handleBeforeFinishCallback:function(r,o){return n(this,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return e.beforeFinishCallback?[4,C(r,o,e.beforeFinishCallback,e,y)]:[3,2];case 1:return[2,n.sent()];case 2:return[2]}}))}))},handleResults:function(r,o){return n(this,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:if(!e.resultsCallback)return[3,4];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,e.resultsCallback(r,o)];case 2:return t.sent(),[3,4];case 3:return n=t.sent(),console.error("[Dromo-External-Error] There was an error in your onResult callback.",n),[3,4];case 4:return e.close(),[2]}}))}))},handleCloseModal:function(){e.close()},handleCancel:function(){if(e.cancelCallback)try{e.cancelCallback()}catch(e){console.error("[Dromo-External-Error] There was an error in your cancel callback.",e)}e.close()}}}):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,n){c.columnHooks.push({fieldName:e,callback:n}),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,n){c.stepHooks.push({type:e,callback:n})},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.registerAllHooks=function(e){if(e.columnHooks)for(var n=0,t=e.columnHooks;n<t.length;n++){var r=t[n],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 l=a[s];c.registerRowHook(l)}if(e.bulkRowHooks)for(var u=0,d=e.bulkRowHooks;u<d.length;u++){var h=d[u];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)}e.beforeFinishCallback&&c.beforeFinish(e.beforeFinishCallback)},this.onResults=function(e){c.resultsCallback=e},this.onCancel=function(e){c.cancelCallback=e},this.setUser=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.user=e,this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().setUser(this.user)];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))},this.addField=function(e,r){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().addField(O(e),r)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.label=4;case 4:return[2]}}))}))},this.removeField=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().removeField(e)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.label=4;case 4:return[2]}}))}))},this.updateInfoMessages=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().updateInfoMessages(e)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.label=4;case 4:return[2]}}))}))},this.setHeaderRowOverride=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.headerRowOverride=e,this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().setHeaderRowOverride(e)];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))},this.open=function(){return n(c,void 0,void 0,(function(){return t(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 n(c,void 0,void 0,(function(){var n,r;return t(this,(function(t){switch(t.label){case 0:this.embedInline=!0,t.label=1;case 1:if(t.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)+"-"+x)),"string"==typeof e){if(null===(n=document.getElementById(e)))throw new Error("WRAPPER_NOT_FOUND");this.wrapper=n,this.wrapperId=e}return this.iframe||(this.initIFrame(),this.createConnection(),this.addIFrameToWrapper()),[4,this.initChild()];case 2:return t.sent(),this.showIframe(),[3,4];case 3:throw"WRAPPER_NOT_FOUND"===(r=t.sent()).message&&console.error("[Dromo-Error] Could not find wrapper using provided ID."),r;case 4:return[2]}}))}))},this.addRows=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().addRows(e)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.label=4;case 4:return[2]}}))}))},this.removeRows=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().removeRows(e)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.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 n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.developmentMode=e,this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().setDevelopmentMode(this.developmentMode)];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))},this.rehydrate=function(e,r){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.wrapper||(this.initIFrame(),this.createConnection(),this.mountIFrame()),[4,this.initChild()];case 1:return n.sent(),[4,this.connection.promise];case 2:return[4,n.sent().rehydrate(e,r)];case 3:return n.sent(),this.showWrapper(),[2]}}))}))},this.iframeId=Math.random().toString(36).substring(7)+"-dromo-iframe-element",this.wrapperId=Math.random().toString(36).substring(7)+"-"+x,this.appHost=document.location.hostname,void 0!==i&&void 0!==s?(this.licenseKey=r,this.fields=o.map(O),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 n=Object.entries(e).filter((function(e){e[0];var n=e[1];try{return structuredClone(n),!1}catch(e){return!0}})).map((function(e){return e[0]}));if(n.length>0){var t=n.join(", ");throw new Error("[Dromo-External-Error] The Dromo importer received non-cloneable parameters: ".concat(t,". 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,l=e.hooks,u=e.rehydrateState;return n(void 0,void 0,void 0,(function(){var e;return t(o,(function(n){switch(n.label){case 0:return(e=new r(i,c,a,{id:"headless-review"})).registerAllHooks(l),[4,e.rehydrate(u,s)];case 1:return n.sent(),e.open(),[2,e]}}))}))},r}()})); | ||
***************************************************************************** */var e=function(){return(e=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e}).apply(this,arguments)};function n(e,n,t,r){return new(t||(t=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 n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(s,c)}a((r=r.apply(e,n||[])).next())}))}function t(e,n){var t,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;s;)try{if(t=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=n.call(e,s)}catch(e){i=[6,e],r=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}var r,o,i,s,c,a,l={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 u={"http:":"80","https:":"443"},d=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,h=["file:","data:"];const f=({name:e,message:n,stack:t})=>({name:e,message:n,stack:t});let m=0;var p=()=>++m,v=(e,n,t,r,c)=>{const{localName:l,local:u,remote:d,originForSending:h,originForReceiving:f}=n;let m=!1;c(`${l}: Connecting call sender`);const v=e=>(...n)=>{let t;c(`${l}: Sending ${e}() call`);try{d.closed&&(t=!0)}catch(e){t=!0}if(t&&r(),m){const n=new Error(`Unable to send ${e}() call due to destroyed connection`);throw n.code=s.ConnectionDestroyed,n}return new Promise(((t,r)=>{const s=p(),m=n=>{if(n.source!==d||n.data.penpal!==o.Reply||n.data.id!==s)return;if(n.origin!==f)return void c(`${l} received message from origin ${n.origin} which did not match expected origin ${f}`);const h=n.data;c(`${l}: Received ${e}() reply`),u.removeEventListener(a.Message,m);let p=h.returnValue;h.returnValueIsError&&(p=(e=>{const n=new Error;return Object.keys(e).forEach((t=>n[t]=e[t])),n})(p)),(h.resolution===i.Fulfilled?t:r)(p)};u.addEventListener(a.Message,m);const v={penpal:o.Call,id:s,methodName:e,args:n};d.postMessage(v,h)}))};return t.reduce(((e,n)=>(e[n]=v(n),e)),e),()=>{m=!0}},w=(e,n,t,r,s)=>{const{destroy:l,onDestroy:u}=r;let d,h;const m={};return r=>{if(r.origin!==n)return void s(`Parent: Handshake - Received ACK message from origin ${r.origin} which did not match expected origin ${n}`);s("Parent: Handshake - Received ACK");const p={localName:"Parent",local:window,remote:r.source,originForSending:t,originForReceiving:n};d&&d(),d=((e,n,t)=>{const{localName:r,local:s,remote:l,originForSending:u,originForReceiving:d}=e;let h=!1;const m=e=>{if(e.source!==l||e.data.penpal!==o.Call)return;if(e.origin!==d)return void t(`${r} received message from origin ${e.origin} which did not match expected origin ${d}`);const s=e.data,{methodName:a,args:m,id:p}=s;t(`${r}: Received ${a}() call`);const v=e=>n=>{if(t(`${r}: Sending ${a}() reply`),h)return void t(`${r}: Unable to send ${a}() reply due to destroyed connection`);const s={penpal:o.Reply,id:p,resolution:e,returnValue:n};e===i.Rejected&&n instanceof Error&&(s.returnValue=f(n),s.returnValueIsError=!0);try{l.postMessage(s,u)}catch(e){if(e.name===c.DataCloneError){const n={penpal:o.Reply,id:p,resolution:i.Rejected,returnValue:f(e),returnValueIsError:!0};l.postMessage(n,u)}throw e}};new Promise((e=>e(n[a].apply(n,m)))).then(v(i.Fulfilled),v(i.Rejected))};return s.addEventListener(a.Message,m),()=>{h=!0,s.removeEventListener(a.Message,m)}})(p,e,s),u(d),h&&h.forEach((e=>{delete m[e]})),h=r.data.methodNames;const w=v(m,p,h,l,s);return u(w),m}};var g=e=>{let{iframe:n,methods:t={},childOrigin:r,timeout:i,debug:c=!1}=e;const l=(e=>(...n)=>{e&&console.log("[Penpal]",...n)})(c),f=(()=>{const e=[];let n=!1;return{destroy(t){n=!0,e.forEach((e=>{e(t)}))},onDestroy(t){n?t():e.push(t)}}})(),{onDestroy:m,destroy:p}=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}})(n),r=(e=>{if(e&&h.find((n=>e.startsWith(n))))return"null";const n=document.location,t=d.exec(e);let r,o,i;return t?(r=t[1]?t[1]:n.protocol,o=t[2],i=t[4]):(r=n.protocol,o=n.hostname,i=n.port),`${r}//${o}${i&&i!==u[r]?`:${i}`:""}`})(n.src));const v="null"===r?"*":r,g=((e,n,t,r)=>i=>{if(i.origin!==t)return void e(`Parent: Handshake - Received SYN message from origin ${i.origin} which did not match expected origin ${t}`);e("Parent: Handshake - Received SYN, responding with SYN-ACK");const s={penpal:o.SynAck,methodNames:Object.keys(n)};i.source.postMessage(s,r)})(l,t,r,v),y=w(t,r,v,f,l);return{promise:new Promise(((e,t)=>{const r=((e,n)=>{let t;return void 0!==e&&(t=window.setTimeout((()=>{const t=new Error(`Connection timed out after ${e}ms`);t.code=s.ConnectionTimeout,n(t)}),e)),()=>{clearTimeout(t)}})(i,p),c=t=>{if(t.source===n.contentWindow&&t.data)if(t.data.penpal!==o.Syn)if(t.data.penpal!==o.Ack);else{const n=y(t);n&&(r(),e(n))}else g(t)};window.addEventListener(a.Message,c),l("Parent: Awaiting handshake"),((e,n)=>{const{destroy:t,onDestroy:r}=n,o=setInterval((()=>{e.isConnected||(clearInterval(o),t())}),6e4);r((()=>{clearInterval(o)}))})(n,f),m((e=>{window.removeEventListener(a.Message,c),e||((e=new Error("Connection destroyed")).code=s.ConnectionDestroyed),t(e)}))})),destroy(){p()}}},y=function(e,n){return console.error("[Dromo-External-Error] There was an error running your ".concat(n,"."),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 n(void 0,void 0,void 0,(function(){var s,c,a;return t(this,(function(l){switch(l.label){case 0:return s=new Map,c=o.map((function(n){return e({},n)})),[4,r.reduce((function(e,r){return n(void 0,void 0,void 0,(function(){return t(this,(function(o){switch(o.label){case 0:return[4,e.then((function(){return n(void 0,void 0,void 0,(function(){var e,n,o;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),e=b("column hook"),[4,r.callback(c)];case 1:return n=t.sent(),k(e),n.forEach((function(e){if(void 0!==e.value||void 0!==e.info){var n={};void 0!==e.value&&(n.value=e.value,c[e.index].value=e.value),void 0!==e.info&&(n.info=e.info),s.set(e.index,n)}})),[3,3];case 2:return o=t.sent(),i(o,"column hooks"),[3,3];case 3:return[2]}}))}))}))];case 1:return o.sent(),[2]}}))}))}),Promise.resolve())];case 1:return l.sent(),a=[],s.forEach((function(n,t){return a.push(e(e({},n),{index:t}))})),[2,a]}}))}))},R=function(e){return void 0===e.value&&void 0===e.info&&void 0===e.selectOptions&&void 0===e.manyToOne},E=function(e,r,o,i,s){return n(void 0,void 0,void 0,(function(){var c,a,l,u,d,h,f,m,p,v,w,g,y;return t(this,(function(I){switch(I.label){case 0:c=new Map,a=new Map(e.map((function(e){return[e.index,e]}))),l=function(e,n){for(var t,r=a.get(e),o=function(n,o){if(R(o))return"continue";var i=r.row[n],s=Array.isArray(i.manyToOne),a="manyToOne"in o&&Array.isArray(o.manyToOne);if(s&&!a)throw new Error("".concat(n," should have manyToOne defined as an array."));if(s&&a&&i.manyToOne.length!==o.manyToOne.length)throw new Error("".concat(n," should be array of length ").concat(i.manyToOne.length));var l=c.get(e)||{},u=null!==(t=l[n])&&void 0!==t?t:{},d=[];a?(u.manyToOne=[],o.manyToOne.forEach((function(e,n){if(!R(e)){var t={};u.manyToOne.push(t),d.push({fieldOutput:e,rowDataField:i.manyToOne[n],cellChange:t})}}))):d.push({fieldOutput:o,rowDataField:i,cellChange:u}),d.forEach((function(e){var n=e.fieldOutput,t=e.rowDataField,r=e.cellChange;void 0!==n.value&&(r.value=n.value,t.value=n.value),void 0!==n.info&&(r.info=n.info,t.info=n.info),void 0!==n.selectOptions&&(r.selectOptions=n.selectOptions,t.selectOptions=n.selectOptions)})),l[n]=u,c.set(e,l)},i=0,s=Object.entries(null!=n?n:{});i<s.length;i++){var l=s[i];o(l[0],l[1])}},u=0,d=i,I.label=1;case 1:if(!(u<d.length))return[3,6];h=d[u],I.label=2;case 2:return I.trys.push([2,4,,5]),f=b("bulk row hook"),[4,h(e,r)];case 3:for(m=I.sent(),k(f),p=0,v=m;p<v.length;p++)w=v[p],l(w.index,w.row);return[3,5];case 4:return g=I.sent(),s(g,"bulk row hooks"),[3,5];case 5:return u++,[3,1];case 6:return[4,Promise.all(e.map((function(e){return n(void 0,void 0,void 0,(function(){var n,i,c,a,u,d;return t(this,(function(t){switch(t.label){case 0:n=0,i=o,t.label=1;case 1:if(!(n<i.length))return[3,6];c=i[n],t.label=2;case 2:return t.trys.push([2,4,,5]),a=b("row hook"),[4,c(e,r)];case 3:return u=t.sent(),k(a),l(e.index,u.row),[3,5];case 4:return d=t.sent(),s(d,"row hooks"),[3,5];case 5:return n++,[3,1];case 6:return[2]}}))}))})))];case 7:return I.sent(),y=[],c.forEach((function(e,n){y.push({index:n,row:e})})),[2,y]}}))}))},H=function(e,r,o){return n(void 0,void 0,void 0,(function(){return t(this,(function(i){return[2,Promise.all(e.map((function(e){return n(void 0,void 0,void 0,(function(){return t(this,(function(i){return r.forEach((function(r){return n(void 0,void 0,void 0,(function(){var n,i;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),n=b("row delete hook"),[4,r(e)];case 1:return t.sent(),k(n),[3,3];case 2:return i=t.sent(),o(i,"row delete hooks"),[3,3];case 3:return[2]}}))}))})),[2]}))}))})))]}))}))},D=function(e,r,o,i,s){return n(void 0,void 0,void 0,(function(){return t(this,(function(c){switch(c.label){case 0:return[4,Promise.all(o.map((function(o){return n(void 0,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:if(e!==o.type)return[2,Promise.resolve()];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,o.callback(i,r)];case 2:return[2,t.sent()];case 3:return n=t.sent(),s(n,"step hook ".concat(e)),[2,Promise.resolve()];case 4:return[2]}}))}))})))];case 1:return c.sent(),[2]}}))}))},C=function(e,r,o,i,s){return n(void 0,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,o(e,r,i)];case 1:return[2,t.sent()];case 2:return n=t.sent(),s(n,"before finish callback"),[3,3];case 3:return[2]}}))}))},x="dromo-container",O=function(n){var t=e({},n);return t.validators&&(t.validators=t.validators.map((function(n){return("regex_match"===n.validate||"regex_exclude"===n.validate)&&n.regex instanceof RegExp?e(e({},n),{regex:n.regex.source,regexOptions:{ignoreCase:n.regex.flags.includes("i"),dotAll:n.regex.flags.includes("s"),multiline:n.regex.flags.includes("m"),unicode:n.regex.flags.includes("u")}}):n}))),t};return function(){function r(r,o,i,s){var c=this;this.embedInline=!1,this.columnHooks=[],this.bulkRowHooks=[],this.rowHooks=[],this.stepHooks=[],this.rowDeleteHooks=[],this.initChild=function(){return n(c,void 0,void 0,(function(){var n,r,o,i,s;return t(this,(function(t){switch(t.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 n=t.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,n.setNumRegisteredRowHooks(this.totalNumRowHooks())];case 2:return t.sent(),[4,n.setNumRegisteredColHooks(this.columnHooks.length)];case 3:return t.sent(),[4,n.setNumRegisteredRowDeleteHooks(this.rowDeleteHooks.length)];case 4:return t.sent(),[4,n.setEmbedInline(this.embedInline)];case 5:return t.sent(),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,n.init(this.licenseKey,this.fields,o,this.user,this.appHost)]):[3,7];case 6:return t.sent(),[3,10];case 7:return this.schemaId?[4,n.initFromSavedSchema(this.licenseKey,this.schemaId,this.appHost,{user:this.user,developmentMode:this.developmentMode,headerRowOverride:this.headerRowOverride})]:[3,9];case 8:return t.sent(),[3,10];case 9:console.error("Invalid Dromo configuration"),t.label=10;case 10:return[2]}}))}))},this.initIFrame=function(){var e,n,t,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===(n=c.settings)||void 0===n?void 0:n.version)?"https://widget-v1.dromo.io/":l;if(!document.getElementById(c.iframeId)){var s=document.createElement("iframe"),a=null!==(r=null===(t=c.settings)||void 0===t?void 0:t.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 e=c,r=c.iframe;r?c.connection=g({iframe:r,methods:{handleColumnHooks:function(r,o){return n(this,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:return n=e.columnHooks.filter((function(e){return e.fieldName===r})),[4,I(n,o,y)];case 1:return[2,t.sent()]}}))}))},handleRowHooks:function(r,o){return n(this,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return[4,E(r,o,e.rowHooks.map((function(e){return e.callback})),e.bulkRowHooks,y)];case 1:return[2,n.sent()]}}))}))},handleStepHook:function(r,o){return n(this,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return[4,D(r,o,e.stepHooks,e,y)];case 1:return[2,n.sent()]}}))}))},handleRowDeleteHooks:function(r){return n(this,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return[4,H(r,e.rowDeleteHooks,y)];case 1:return n.sent(),[2]}}))}))},handleBeforeFinishCallback:function(r,o){return n(this,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return e.beforeFinishCallback?[4,C(r,o,e.beforeFinishCallback,e,y)]:[3,2];case 1:return[2,n.sent()];case 2:return[2]}}))}))},handleResults:function(r,o){return n(this,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:if(!e.resultsCallback)return[3,4];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,e.resultsCallback(r,o)];case 2:return t.sent(),[3,4];case 3:return n=t.sent(),console.error("[Dromo-External-Error] There was an error in your onResult callback.",n),[3,4];case 4:return e.close(),[2]}}))}))},handleCloseModal:function(){e.close()},handleCancel:function(){if(e.cancelCallback)try{e.cancelCallback()}catch(e){console.error("[Dromo-External-Error] There was an error in your cancel callback.",e)}e.close()}}}):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,n){c.columnHooks.push({fieldName:e,callback:n}),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,n){c.stepHooks.push({type:e,callback:n})},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.registerAllHooks=function(e){if(e.columnHooks)for(var n=0,t=e.columnHooks;n<t.length;n++){var r=t[n],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 l=a[s];c.registerRowHook(l)}if(e.bulkRowHooks)for(var u=0,d=e.bulkRowHooks;u<d.length;u++){var h=d[u];c.registerBulkRowHook(h)}if(e.rowDeleteHooks)for(var f=0,m=e.rowDeleteHooks;f<m.length;f++){var p=m[f];c.registerRowDeleteHook(p)}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)}e.beforeFinishCallback&&c.beforeFinish(e.beforeFinishCallback)},this.onResults=function(e){c.resultsCallback=e},this.onCancel=function(e){c.cancelCallback=e},this.setUser=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.user=e,this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().setUser(this.user)];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))},this.addField=function(e,r){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().addField(O(e),r)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.label=4;case 4:return[2]}}))}))},this.removeField=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().removeField(e)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.label=4;case 4:return[2]}}))}))},this.updateInfoMessages=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().updateInfoMessages(e)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.label=4;case 4:return[2]}}))}))},this.setHeaderRowOverride=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.headerRowOverride=e,this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().setHeaderRowOverride(e)];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))},this.setConfirmationMessage=function(e,r){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().setConfirmationMessage(e,r)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.label=4;case 4:return[2]}}))}))},this.open=function(){return n(c,void 0,void 0,(function(){return t(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 n(c,void 0,void 0,(function(){var n,r;return t(this,(function(t){switch(t.label){case 0:this.embedInline=!0,t.label=1;case 1:if(t.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)+"-"+x)),"string"==typeof e){if(null===(n=document.getElementById(e)))throw new Error("WRAPPER_NOT_FOUND");this.wrapper=n,this.wrapperId=e}return this.iframe||(this.initIFrame(),this.createConnection(),this.addIFrameToWrapper()),[4,this.initChild()];case 2:return t.sent(),this.showIframe(),[3,4];case 3:throw"WRAPPER_NOT_FOUND"===(r=t.sent()).message&&console.error("[Dromo-Error] Could not find wrapper using provided ID."),r;case 4:return[2]}}))}))},this.addRows=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().addRows(e)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.label=4;case 4:return[2]}}))}))},this.removeRows=function(e){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().removeRows(e)];case 2:return n.sent(),[3,4];case 3:console.error("[Dromo-Error] Invalid connection to Dromo Uploader."),n.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 n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.developmentMode=e,this.connection?[4,this.connection.promise]:[3,3];case 1:return[4,n.sent().setDevelopmentMode(this.developmentMode)];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))},this.rehydrate=function(e,r){return n(c,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return this.wrapper||(this.initIFrame(),this.createConnection(),this.mountIFrame()),[4,this.initChild()];case 1:return n.sent(),[4,this.connection.promise];case 2:return[4,n.sent().rehydrate(e,r)];case 3:return n.sent(),this.showWrapper(),[2]}}))}))},this.iframeId=Math.random().toString(36).substring(7)+"-dromo-iframe-element",this.wrapperId=Math.random().toString(36).substring(7)+"-"+x,this.appHost=document.location.hostname,void 0!==i&&void 0!==s?(this.licenseKey=r,this.fields=o.map(O),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 n=Object.entries(e).filter((function(e){e[0];var n=e[1];try{return structuredClone(n),!1}catch(e){return!0}})).map((function(e){return e[0]}));if(n.length>0){var t=n.join(", ");throw new Error("[Dromo-External-Error] The Dromo importer received non-cloneable parameters: ".concat(t,". 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,l=e.hooks,u=e.rehydrateState;return n(void 0,void 0,void 0,(function(){var e;return t(o,(function(n){switch(n.label){case 0:return(e=new r(i,c,a,{id:"headless-review"})).registerAllHooks(l),[4,e.rehydrate(u,s)];case 1:return n.sent(),e.open(),[2,e]}}))}))},r}()})); | ||
//# sourceMappingURL=index.js.map |
@@ -551,4 +551,8 @@ export type IRequiredValidator = { | ||
removeRows: (rowIds: string[]) => void; | ||
setConfirmationMessage: (messageHTML: string, options?: { | ||
submitButtonText?: string; | ||
cancelButtonText?: string; | ||
}) => void; | ||
} | ||
export type IPublicConnectionMethods = Pick<IConnectionMethods, "addField" | "updateInfoMessages" | "setHeaderRowOverride" | "setUser" | "removeField" | "setDevelopmentMode" | "addRows" | "removeRows">; | ||
export type IPublicConnectionMethods = Pick<IConnectionMethods, "addField" | "updateInfoMessages" | "setHeaderRowOverride" | "setUser" | "removeField" | "setDevelopmentMode" | "addRows" | "removeRows" | "setConfirmationMessage">; | ||
export type IDeveloperFieldType = "string" | "checkbox" | "select" | "number" | "domain" | "date" | "ssn" | "datetime" | "phone-number" | "time" | "url" | "us-zip-code" | "country" | "uuid" | "us-state-territory" | "email"; | ||
@@ -673,3 +677,4 @@ export interface ICellRef { | ||
REVIEW_STEP = "REVIEW_STEP", | ||
REVIEW_STEP_POST_HOOKS = "REVIEW_STEP_POST_HOOKS" | ||
REVIEW_STEP_POST_HOOKS = "REVIEW_STEP_POST_HOOKS", | ||
REVIEW_STEP_PRE_SUBMIT = "REVIEW_STEP_PRE_SUBMIT" | ||
} | ||
@@ -693,2 +698,8 @@ export interface IUploadStepData { | ||
} | ||
export interface IReviewStepPreSubmitData { | ||
headerMapping: { | ||
[header: string]: string | undefined; | ||
}; | ||
fields: IFieldMetadata; | ||
} | ||
export interface IStepHook { | ||
@@ -695,0 +706,0 @@ type: keyof typeof EStepHook; |
{ | ||
"name": "dromo-uploader-js", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"description": "Easy to use data (CSV, TSV, Excel) importer", | ||
@@ -5,0 +5,0 @@ "author": "ankitgoyal100", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
274086
1097