| 12 |
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/papaparse.min-CR43Mv99.js","assets/chunk-aKtaBQYM.js"])))=>i.map(i=>d[i]);
- import{i as e}from"./chunk-aKtaBQYM.js";import{f as t,h as n,l as r,m as i,n as a,o,p as s,r as c,s as l,t as u}from"./index-wE5DdboK.js";var d=e(n(),1),f=t(),p=500,m=40;function h(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(65+n%26)+t,n=Math.floor(n/26)-1;return t}function g(e){let t=document.createElement(`canvas`);t.width=256,t.height=256;let n=t.getContext(`2d`);if(!n)return Promise.resolve(null);let r=256/5,i=256/9;n.fillStyle=`#1a1a1a`,n.fillRect(0,0,256,256),n.fillStyle=`rgba(0, 174, 66, 0.25)`,n.fillRect(0,0,256,i),n.strokeStyle=`#333333`,n.lineWidth=1;for(let e=1;e<5;e++)n.beginPath(),n.moveTo(e*r+.5,0),n.lineTo(e*r+.5,256),n.stroke();for(let e=1;e<9;e++)n.beginPath(),n.moveTo(0,e*i+.5),n.lineTo(256,e*i+.5),n.stroke();n.fillStyle=`#d4d4d4`,n.font=`11px sans-serif`,n.textBaseline=`middle`;for(let t=0;t<9;t++)for(let a=0;a<5;a++){let o=e[t]?.[a];o&&n.fillText(String(o),a*r+4,t*i+i/2,r-8)}return new Promise(e=>t.toBlob(e,`image/png`))}function _({libraryFileId:t,filename:n,fileType:_,fileSize:v,onClose:y,onSnapshot:b}){let{t:x}=i(),[S,C]=(0,d.useState)(null),[w,T]=(0,d.useState)(0),[E,D]=(0,d.useState)(null),O=(0,d.useRef)(!1),k=(0,d.useRef)(b);(0,d.useEffect)(()=>{k.current=b}),(0,d.useEffect)(()=>{let e=e=>{e.key===`Escape`&&y()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[y]),(0,d.useEffect)(()=>{let r=!1;if(C(null),D(null),T(0),v>20971520){D(x(`fileManager.preview.tooLarge`,{size:u(v)}));return}let i={},o=c();return o&&(i.Authorization=`Bearer ${o}`),(async()=>{let o=await fetch(a.getLibraryFileDownloadUrl(t),{headers:i});if(!o.ok)throw Error(`HTTP ${o.status}`);let c=await o.arrayBuffer(),l;if(_===`csv`){let t=(await s(async()=>{let{default:t}=await import(`./papaparse.min-CR43Mv99.js`).then(t=>e(t.default,1));return{default:t}},__vite__mapDeps([0,1]))).default,r=new TextDecoder().decode(c),i=t.parse(r,{skipEmptyLines:!1}).data.filter(e=>Array.isArray(e));for(;i.length>0&&i[i.length-1].every(e=>!e);)i.pop();let a=i.length,o=i.reduce((e,t)=>Math.max(e,t.length),0);l=[{name:n,rows:i.slice(0,p).map(e=>e.slice(0,m).map(e=>e??``)),totalRows:a,totalCols:o}]}else{let e=await s(()=>import(`./xlsx-CKkngM-o.js`),[]),t=e.read(c,{dense:!0});l=t.SheetNames.map(n=>{let r=t.Sheets[n],i=r?.[`!ref`];if(!r||!i)return{name:n,rows:[],totalRows:0,totalCols:0};let a=e.utils.decode_range(i),o=a.e.r-a.s.r+1,s=a.e.c-a.s.c+1,c={s:a.s,e:{r:Math.min(a.e.r,a.s.r+p-1),c:Math.min(a.e.c,a.s.c+m-1)}};return{name:n,rows:e.utils.sheet_to_json(r,{header:1,raw:!1,defval:``,range:e.utils.encode_range(c)}),totalRows:o,totalCols:s}})}if(!r&&(C(l),k.current&&!O.current)){let e=l.find(e=>e.rows.length>0);if(e){O.current=!0;let t=await g(e.rows);t&&!r&&k.current?.(t)}}})().catch(()=>{r||D(x(`fileManager.preview.error`))}),()=>{r=!0}},[t,_,v,n,x]);let A=S?.[w]??null,j=A!=null&&A.totalRows>A.rows.length,M=A!=null&&A.totalCols>m,N=A==null?0:Math.min(A.totalCols,m);return(0,f.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,f.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-6xl h-[85vh] border border-bambu-dark-tertiary flex flex-col`,children:[(0,f.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,f.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,f.jsx)(r,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,f.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:n})]}),(0,f.jsx)(`button`,{onClick:y,className:`p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors`,"aria-label":x(`common.close`),children:(0,f.jsx)(o,{className:`w-5 h-5`})})]}),S&&S.length>1&&(0,f.jsx)(`div`,{className:`flex gap-1 px-4 pt-2 overflow-x-auto flex-shrink-0`,children:S.map((e,t)=>(0,f.jsx)(`button`,{onClick:()=>T(t),className:`px-3 py-1.5 text-sm rounded-t whitespace-nowrap transition-colors ${t===w?`bg-bambu-dark text-white border border-b-0 border-bambu-dark-tertiary`:`text-bambu-gray hover:text-white hover:bg-bambu-dark/50`}`,children:e.name},`${e.name}-${t}`))}),(0,f.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto bg-bambu-dark rounded-b-lg`,children:E?(0,f.jsx)(`div`,{className:`h-full flex items-center justify-center p-6`,children:(0,f.jsx)(`p`,{className:`text-bambu-gray text-center`,children:E})}):S?!A||A.rows.length===0?(0,f.jsx)(`div`,{className:`h-full flex items-center justify-center p-6`,children:(0,f.jsx)(`p`,{className:`text-bambu-gray`,children:x(`fileManager.preview.emptySheet`)})}):(0,f.jsxs)(`table`,{className:`border-collapse text-xs`,children:[(0,f.jsx)(`thead`,{children:(0,f.jsxs)(`tr`,{children:[(0,f.jsx)(`th`,{className:`sticky top-0 bg-bambu-dark-secondary border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray font-medium w-10`}),Array.from({length:N},(e,t)=>(0,f.jsx)(`th`,{className:`sticky top-0 bg-bambu-dark-secondary border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray font-medium text-left min-w-[80px]`,children:h(t)},t))]})}),(0,f.jsx)(`tbody`,{children:A.rows.map((e,t)=>(0,f.jsxs)(`tr`,{children:[(0,f.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray text-right bg-bambu-dark-secondary/50`,children:t+1}),Array.from({length:N},(t,n)=>(0,f.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray-light whitespace-nowrap max-w-[280px] overflow-hidden text-ellipsis`,title:e[n]||void 0,children:e[n]??``},n))]},t))})]}):(0,f.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,f.jsx)(l,{className:`w-8 h-8 text-bambu-green animate-spin`})})}),(j||M)&&A&&(0,f.jsxs)(`div`,{className:`px-4 py-2 border-t border-bambu-dark-tertiary text-xs text-bambu-gray flex gap-4 flex-shrink-0`,children:[j&&(0,f.jsx)(`span`,{children:x(`fileManager.preview.truncatedRows`,{shown:A.rows.length,total:A.totalRows})}),M&&(0,f.jsx)(`span`,{children:x(`fileManager.preview.truncatedCols`,{shown:N,total:A.totalCols})})]})]})})}export{_ as SpreadsheetPreviewModal};
|