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