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