@impler/react
Version:
React library to show CSV Excel Importer in react applications
3 lines (2 loc) • 2.32 kB
JavaScript
import{__read as e,__awaiter as t,__generator as r}from"tslib";import{useState as a,useCallback as o,useEffect as n}from"react";import{EventTypes as i,logError as c,isObject as l}from"@impler/client";export{ColumnTypes,ValidationTypes}from"@impler/client";function s(s){var p=this,u=s.projectId,m=s.primaryColor,d=s.templateId,x=s.accessToken,w=s.authHeaderValue,f=s.title,E=s.texts,I=s.extra,h=s.config,R=s.appearance,D=s.onUploadComplete,v=s.onWidgetClose,T=s.onUploadStart,y=s.onDataImported,_=s.onUploadTerminate,O=s.onImportJobCreated,g=e(a("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=crypto.getRandomValues(new Uint8Array(1))[0]%16|0;return("x"===e?t:3&t|8).toString(16)}))),1)[0],b=e(a(!1),2),A=b[0],U=b[1],k=o((function(e){switch(e.type){case i.UPLOAD_STARTED:T&&T(e.value);break;case i.UPLOAD_TERMINATED:_&&_(e.value);break;case i.UPLOAD_COMPLETED:D&&D(e.value);break;case i.DATA_IMPORTED:y&&y(e.value);break;case i.CLOSE_WIDGET:v&&v();break;case i.IMPORT_JOB_CREATED:O&&O(e.value)}}),[D,T,_,v]);n((function(){var e=setInterval((function(){window.impler&&window.impler.isReady()&&(U(!0),clearInterval(e))}),1e3);return function(){clearInterval(e)}}),[]),n((function(){window.impler?(window.impler.init(g),window.impler.on("message",k,g)):c("IMPLER_UNDEFINED_ERROR")}),[]);return{isImplerInitiated:A,showWidget:function(e){var a=void 0===e?{}:e,o=a.colorScheme,n=a.data,i=a.sampleFile,s=a.schema,D=a.output;return t(p,void 0,void 0,(function(){var e,t,a;return r(this,(function(r){switch(r.label){case 0:return window.impler&&A?(e={uuid:g,templateId:d,host:"",projectId:u,accessToken:x,schema:s,data:n,sampleFile:i,output:D,title:f,extra:I,config:h,appearance:R,colorScheme:o,primaryColor:m},o||(t=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",e.colorScheme=t),l(E)&&(e.texts=JSON.stringify(E)),w?"function"!=typeof w||"AsyncFunction"!==w.constructor.name?[3,2]:(a=e,[4,w()]):[3,3]):[3,4];case 1:return a.authHeaderValue=r.sent(),[3,3];case 2:e.authHeaderValue="function"==typeof w?w():w,r.label=3;case 3:return window.impler.show(e),[3,5];case 4:c("IMPLER_UNDEFINED_ERROR"),r.label=5;case 5:return[2]}}))}))},closeWidget:function(){window.impler?window.impler.close():c("IMPLER_UNDEFINED_ERROR")}}}export{s as useImpler};
//# sourceMappingURL=index.js.map