InputExcel-BvdbL_ay.js 6.3 KB

12
  1. const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/exceljs.min-BRk7F3PI.js","assets/index-DT8qTvyx.js","assets/index-We5Babj5.css"])))=>i.map(i=>d[i]);
  2. import{s as R,ao as F,aC as D,cp as w,cg as W,aE as P,cq as B,E as _,G as I,o as T,bx as O,aF as z,f as y,cr as N,y as S,z as C,P as A,Q as E,a1 as j,ah as U}from"./index-DT8qTvyx.js";var M=function(g){R(c,g);function c(){var t=g!==null&&g.apply(this,arguments)||this;return t.state={filename:""},t}return c.prototype.componentDidUpdate=function(t){t.value!==this.props.value&&!this.props.value&&this.setState({filename:""})},c.prototype.syncAutoFill=function(t){var n=this.props,i=n.autoFill,o=n.onBulkChange,l=n.data,p=n.name;if(!(i!=null&&i.hasOwnProperty("api")||!F(i))){var e=p?D(i,p):i;if(!w(e)&&o){var a=W(e,{filename:t});Object.keys(a).forEach(function(r){P(a[r])&&P(l[r])&&(a[r]=B({},l[r],a[r]))}),o(a)}}},c.prototype.handleDrop=function(t){var n=this,i=t[0],o=i.name,l=new FileReader;l.readAsArrayBuffer(i),l.onload=function(){return _(n,void 0,void 0,function(){var p=this;return I(this,function(e){return l.result&&(o.toLowerCase().endsWith(".xls")?T(()=>import("./xlsx-B6sNpj_1.js"),[]).then(function(a){var r=a.read(new Uint8Array(l.result),{cellDates:!0}),h=a.writeXLSX(r,{type:"array"});p.processExcelFile(h,o)}):this.processExcelFile(l.result,o)),[2]})})}},c.prototype.processExcelFile=function(t,n){var i=this,o=this.props,l=o.allSheets,p=o.onChange,e=o.parseImage,a=o.autoFill;T(()=>import("./exceljs.min-BRk7F3PI.js").then(r=>r.e),__vite__mapDeps([0,1,2])).then(function(r){return _(i,void 0,void 0,function(){var h,d,s,u,x,v,f=this;return I(this,function(b){switch(b.label){case 0:return h=r.default||r,this.ExcelJS=h,d=new h.Workbook,[4,d.xlsx.load(t)];case 1:return b.sent(),s=[],l?d.eachSheet(function(m){var k=m.state||"visible";k!=="hidden"&&(e?s.push({sheetName:m.name,data:f.readWorksheet(m),images:f.readImages(m,d)}):s.push({sheetName:m.name,data:f.readWorksheet(m)}))}):(u=d.worksheets.find(function(m){return m.state!=="hidden"}),e?(x=this.readImages(u,d),s={data:this.readWorksheet(u),images:x}):s=this.readWorksheet(u)),[4,this.dispatchEvent("change",s)];case 2:return v=b.sent(),v!=null&&v.prevented?[2]:(p(s),a&&this.syncAutoFill(n),this.setState({filename:n}),[2])}})})})},c.prototype.readImages=function(t,n){var i,o,l=this.props.imageDataURI,p=t.getImages(),e=[];try{for(var a=O(p),r=a.next();!r.done;r=a.next()){var h=r.value,d=n.getImage(+h.imageId),s=this.encodeBase64Bytes(d.buffer);if(l){var u=d.extension||"png";e.push("data:image/".concat(u,";base64,")+s)}else e.push(s)}}catch(x){i={error:x}}finally{try{r&&!r.done&&(o=a.return)&&o.call(a)}finally{if(i)throw i.error}}return e},c.prototype.encodeBase64Bytes=function(t){return btoa(t.reduce(function(n,i){return n+String.fromCharCode(i)},""))},c.prototype.dispatchEvent=function(t,n){return _(this,void 0,void 0,function(){var i,o;return I(this,function(l){switch(l.label){case 0:return i=this.props,o=i.dispatchEvent,i.data,[4,o(t,U(this.props,{value:n}))];case 1:return[2,l.sent()]}})})},c.prototype.isRichTextValue=function(t){return!!(t&&F(t)&&t.hasOwnProperty("richText")&&Array.isArray(t==null?void 0:t.richText))},c.prototype.richText2PlainString=function(t,n){n===void 0&&(n=!1);var i=t.richText.map(function(o){var l=o.text,p=o.font,e=p===void 0?{}:p,a=l;if(n){var r="",h=e!=null&&e.bold?"strong":e!=null&&e.italic?"em":(e==null?void 0:e.vertAlign)==="superscript"?"sup":(e==null?void 0:e.vertAlign)==="subscript"?"sub":"span";e!=null&&e.strike?r+="text-decoration: line-through;":e!=null&&e.underline&&(r+="text-decoration: underline;"),e!=null&&e.outline&&(r+="outline: solid;"),e!=null&&e.size&&(r+="font-size: ".concat(e.size,"px;")),a="<".concat(h," ").concat(r?"style=".concat(r):"",">").concat(l,"</").concat(h,">")}return a});return i.join("")},c.prototype.readWorksheet=function(t){var n=this,i=[],o=this.props,l=o.parseMode,p=o.plainText,e=o.includeEmpty;if(l==="array")return t.eachRow(function(r,h){var d=r.values;d.shift(),p&&(d=d.map(function(s){if(s instanceof Object){if(s.hyperlink)return s.hyperlink.startsWith("mailto:")?s.hyperlink.substring(7):s.hyperlink;if(s.result)return s.result;if(s.richText)return n.richText2PlainString(s)}return s})),i.push(d)}),i;var a=[];return t.eachRow(function(r,h){var d;if(h==1)a=((d=r.values)!==null&&d!==void 0?d:[]).map(function(u){return n.isRichTextValue(u)?n.richText2PlainString(u):u});else{var s={};e&&a.forEach(function(u){s[u]=""}),r.eachCell(function(u,x){if(a[x]){var v=u.value;if(p){var f=n.ExcelJS.ValueType;u.type===f.Hyperlink?(v=u.value.hyperlink,v.startsWith("mailto:")&&(v=v.substring(7))):u.type===f.Formula?v=u.value.result:u.type===f.RichText?v=n.richText2PlainString(u.value):u.type===f.Error&&(v="")}s[a[x]]=v}}),i.push(s)}}),i},c.prototype.doAction=function(t,n,i){var o,l,p=t==null?void 0:t.actionType,e=this.props,a=e.onChange,r=e.resetValue,h=e.formStore,d=e.store,s=e.name;if(p==="clear")a("");else if(p==="reset"){var u=(l=z((o=h==null?void 0:h.pristine)!==null&&o!==void 0?o:d==null?void 0:d.pristine,s))!==null&&l!==void 0?l:r;a(u??"")}},c.prototype.render=function(){var t=this,n=this.props,i=n.className,o=n.classnames;n.classPrefix;var l=n.disabled,p=n.translate,e=n.placeholder,a=n.testIdBuilder;return y.createElement("div",{className:o("ExcelControl",i)},y.createElement(N,{key:"drop-zone",onDrop:this.handleDrop,accept:".xlsx,.xls",multiple:!1,disabled:l},function(r){var h=r.getRootProps,d=r.getInputProps;return y.createElement("section",{className:o("ExcelControl-container",i)},y.createElement("div",S({},h({className:o("ExcelControl-dropzone")}),a==null?void 0:a.getTestId()),y.createElement("input",S({},d(),a==null?void 0:a.getChild("input").getTestId())),t.state.filename?p("Excel.parsed",{filename:t.state.filename}):y.createElement("p",null,e??p("Excel.placeholder"))))}))},c.defaultProps={allSheets:!1,parseMode:"object",includeEmpty:!0,plainText:!0,parseImage:!1,imageDataURI:!0},C([A,E("design:type",Function),E("design:paramtypes",[String]),E("design:returntype",void 0)],c.prototype,"syncAutoFill",null),C([A,E("design:type",Function),E("design:paramtypes",[Array]),E("design:returntype",void 0)],c.prototype,"handleDrop",null),c}(y.PureComponent),L=function(g){R(c,g);function c(){return g!==null&&g.apply(this,arguments)||this}return c=C([j({type:"input-excel"})],c),c}(M);export{L as ExcelControlRenderer,M as default};