@betteroffice/xlsx-react 0.0.3 → 0.0.4

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/index.js CHANGED
@@ -1 +1 @@
1
- import {useRef,useState,useMemo,useCallback,useEffect}from'react';import {isPngExportAvailable,isProposalsAvailable,openWorkbook,selectionAt,paintDisplayList,buildA11yGrid,cellAtPoint,moveFocus,normalizeRange,toTsv,fromTsv,StaleProposalError,selectionKeyReducer,extendTo,rangeRect,cellRect}from'@betteroffice/xlsx';import {jsxs,jsx}from'react/jsx-runtime';var h={toolbar:{formulaPlaceholder:"Enter a value or formula",nameBoxPlaceholder:"Name box",undo:"Undo",redo:"Redo",save:"Save",exportPng:"Export PNG"},editor:{openError:"Couldn't open this workbook",sheetTabsLabel:"Sheets",appLabel:"Spreadsheet editor"},proposals:{toolbarButton:"Proposals",panelLabel:"Agent proposals",empty:"No pending proposals",cellCount:"{count} cells",cellCountOne:"1 cell",changeArrow:"\u2192",accept:"Accept",reject:"Reject",forceApply:"Force apply",staleWarning:"Cells changed since proposed: {cells}"},a11y:{gridLabel:"Spreadsheet grid",cellAnnouncement:"{address}, {value}",emptyCellAnnouncement:"{address}, empty",selectionAnnouncement:"Selected {count} cells",editingAnnouncement:"Editing {address}",rowHeaderLabel:"Row {row}",columnHeaderLabel:"Column {column}",cellLabel:"{address}, {value}",cellLabelSelected:"{address}, {value}, selected",emptyCellLabel:"{address}, empty",emptyCellLabelSelected:"{address}, empty, selected"}};function De({rect:r,color:a,newText:c,agentId:b}){return jsxs("div",{"data-testid":"xlsx-proposal-decoration","aria-hidden":"true",style:{position:"absolute",left:r.x,top:r.y,width:r.w,height:r.h,boxSizing:"border-box",border:`1.5px dashed ${a}`,pointerEvents:"none",overflow:"hidden"},children:[jsx("span",{style:{position:"absolute",left:0,right:0,bottom:1,textAlign:"center",opacity:.6,color:a,font:"11px system-ui, sans-serif",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",padding:"0 2px"},children:c}),jsx("span",{title:`${b}: ${c}`,style:{position:"absolute",top:0,right:0,width:6,height:6,background:a,pointerEvents:"auto"}})]})}var Ae=["#7c3aed","#0891b2","#c2410c","#4d7c0f","#be185d","#1d4ed8"];function nt(r){let a=2166136261;for(let c=0;c<r.length;c++)a^=r.charCodeAt(c),a=Math.imul(a,16777619);return (a>>>0)%Ae.length}function re(r){return Ae[nt(r)]}var M=h.proposals;function Me(r,a){return r.replace(/\{(\w+)\}/g,(c,b)=>String(a[b]??""))}function rt(r){return r===1?M.cellCountOne:Me(M.cellCount,{count:r})}function Ie({proposals:r,staleFor:a,onAccept:c,onReject:b}){return jsx("div",{"data-testid":"xlsx-proposals-panel",role:"region","aria-label":M.panelLabel,style:{position:"absolute",top:"100%",right:0,marginTop:4,width:320,maxHeight:420,overflowY:"auto",background:"#ffffff",border:"1px solid #d0d0d0",borderRadius:6,boxShadow:"0 6px 24px rgba(0, 0, 0, 0.16)",padding:8,zIndex:10,font:"13px system-ui, sans-serif",textAlign:"left"},children:r.length===0?jsx("div",{style:{padding:12,color:"#707070",textAlign:"center"},children:M.empty}):r.map(d=>{let i=re(d.agentId),k=a[d.id];return jsxs("div",{"data-testid":"xlsx-proposal","data-proposal-id":d.id,style:{borderLeft:`3px solid ${i}`,padding:"8px 10px",marginBottom:8,background:"#fafafa",borderRadius:4},children:[jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline"},children:[jsx("strong",{style:{color:i},children:d.agentId}),jsx("span",{style:{color:"#707070",fontSize:12},children:rt(d.cells.length)})]}),d.note&&jsx("div",{style:{color:"#404040",margin:"4px 0"},children:d.note}),jsx("ul",{style:{listStyle:"none",margin:"6px 0",padding:0},children:d.cells.map(u=>jsxs("li",{"data-testid":"xlsx-proposal-cell",style:{fontVariantNumeric:"tabular-nums",lineHeight:1.5},children:[jsx("strong",{"data-testid":"xlsx-proposal-cell-a1",children:u.a1}),":"," ",jsx("span",{style:{color:"#909090"},children:u.oldText||"\u2205"})," ",M.changeArrow," ",jsx("span",{"data-testid":"xlsx-proposal-cell-new",style:{color:i},children:u.newText})]},u.a1))}),k&&k.length>0&&jsx("div",{"data-testid":"xlsx-proposal-stale",role:"alert",style:{color:"#b45309",background:"#fef3c7",borderRadius:4,padding:"4px 6px",margin:"4px 0",fontSize:12},children:Me(M.staleWarning,{cells:k.join(", ")})}),jsxs("div",{style:{display:"flex",gap:6,marginTop:4},children:[jsx("button",{"data-testid":"xlsx-proposal-accept",onClick:()=>c(d.id),style:{padding:"3px 10px",cursor:"pointer"},children:M.accept}),k&&k.length>0&&jsx("button",{"data-testid":"xlsx-proposal-force",onClick:()=>c(d.id,true),style:{padding:"3px 10px",cursor:"pointer",color:"#b45309"},children:M.forceApply}),jsx("button",{"data-testid":"xlsx-proposal-reject",onClick:()=>b(d.id),style:{padding:"3px 10px",cursor:"pointer"},children:M.reject})]})]},d.id)})})}var H=96,K=24,U="#217346",xt="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";function bt(r,a){let c=[{op:"fillRect",x:0,y:0,w:r,h:a,color:"#ffffff"}],b=Math.ceil(r/H),d=Math.ceil(a/K);for(let i=0;i<=b;i++)c.push({op:"line",x1:i*H,y1:0,x2:i*H,y2:a,width:1,color:"#e0e0e0"});for(let i=0;i<=d;i++)c.push({op:"line",x1:0,y1:i*K,x2:r,y2:i*K,width:1,color:"#e0e0e0"});return c.push({op:"fillRect",x:0,y:0,w:r,h:K,color:"#f3f3f3"}),c.push({op:"fillRect",x:0,y:0,w:H,h:a,color:"#f3f3f3"}),c.push({op:"text",x:H+8,y:K+18,text:"OpenOOXML xlsx",fontSize:14,color:"#202020",clip:{x:H,y:K,w:H*3,h:K},align:"left"}),{width:r,height:a,commands:c}}function Ke(r,a){if(!r||r.length<2)return a;let c=[];for(let d=1;d<r.length;d++)c.push(r[d]-r[d-1]);c.sort((d,i)=>d-i);let b=c[c.length>>1];return b>0?b:a}function mt(r,a,c){let b=Ke(r?.grid?.rowOffsets,K),d=Ke(r?.grid?.colOffsets,H),i=Math.max(1,Math.round(a.contentHeight/b))+1,k=Math.max(1,Math.round(a.contentWidth/d))+1,u=Math.max(1,Math.floor(c/b));return {rows:i,cols:k,rowsPerPage:u}}function Be(r,a,c){let b=new Blob([new Uint8Array(r)],{type:c}),d=URL.createObjectURL(b),i=document.createElement("a");i.href=d,i.download=a,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(d);}function yt(r){return `${(r??"workbook.xlsx").replace(/\.xlsx$/i,"")}.png`}var vt={position:"absolute",width:1,height:1,margin:-1,padding:0,border:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap"};function wt({file:r,fileName:a,onSave:c,onReady:b,className:d}){let i=useRef(null),k=useRef(null),u=useRef(null),ie=useRef(null),W=useRef(null),me=useRef(null),ce=useRef(false),_=useRef(false),ye=useRef(b);ye.current=b;let[p,$]=useState(null),[de,y]=useState(null),[G,We]=useState(null),[s,P]=useState(null),[E,O]=useState(null),[ve,ue]=useState(null),[Y,X]=useState(null),[we,Oe]=useState(0),[V,q]=useState([]),[Ee,Se]=useState(false),[$e,J]=useState({}),x=p?.activeSheet??0,ke=useMemo(()=>isPngExportAvailable(),[]),Xe=useMemo(()=>isProposalsAvailable(),[]),B=useCallback(()=>{let e=u.current;if(!e){q([]);return}try{q(e.listProposals());}catch{q([]);}},[]);useEffect(()=>{if(O(null),X(null),q([]),J({}),Se(false),!r){u.current=null,$(null),P(null),y(null);return}let e=null;try{e=openWorkbook(r),u.current=e,$(e.sheetInfo()),P(selectionAt({row:0,col:0})),y(null),B(),ye.current?.({handle:e,refreshProposals:B});}catch(t){u.current=null,$(null),P(null),y(t instanceof Error?t.message:String(t));}return ()=>{e?.dispose(),u.current=null;}},[r,B]);let pe=useCallback(()=>{let e=i.current,t=k.current;if(!e||!t)return;let o=t.getContext("2d");if(!o)return;let n=window.devicePixelRatio||1,l=e.clientWidth,w=e.clientHeight;if(l===0||w===0)return;t.width=Math.round(l*n),t.height=Math.round(w*n),t.style.width=`${l}px`,t.style.height=`${w}px`;let m=u.current,A;if(m)try{A=m.displayList({x:e.scrollLeft,y:e.scrollTop,width:l,height:w});}catch{return}else A=bt(l,w);paintDisplayList(o,A,n),ie.current=A,We(A);},[]);useEffect(()=>{let e=i.current;if(!e)return;let t=()=>{W.current==null&&(W.current=requestAnimationFrame(()=>{W.current=null,pe();}));};pe(),e.addEventListener("scroll",t,{passive:true});let o=new ResizeObserver(t);return o.observe(e),()=>{e.removeEventListener("scroll",t),o.disconnect(),W.current!=null&&(cancelAnimationFrame(W.current),W.current=null);}},[pe,p,de,we]),useEffect(()=>{let e=u.current;if(!e||!s||!p){ue(null);return}try{ue(e.cell(x,s.focus.row,s.focus.col));}catch{ue(null);}},[s,p,x,we]),useEffect(()=>{let e=()=>{ce.current=false;};return window.addEventListener("mouseup",e),()=>window.removeEventListener("mouseup",e)},[]);let Q=useMemo(()=>!G||!p?null:buildA11yGrid(G,s,p.sheetNames[x]??"",h.a11y),[G,s,p,x]),L=useCallback(()=>{i.current?.focus({preventScroll:true});},[]);useEffect(()=>{E&&me.current?.focus({preventScroll:true});},[E]);let v=useCallback(e=>{$(e.sheetInfo),Oe(t=>t+1);},[]),D=useCallback(()=>mt(ie.current,p,i.current?.clientHeight??0),[p]),Z=useCallback((e,t)=>{let o=k.current,n=ie.current?.grid;if(!o||!n)return null;let l=o.getBoundingClientRect();return cellAtPoint(n,e-l.left,t-l.top)},[]),ee=useCallback(e=>{let t=u.current;if(!t||!s)return;let{row:o,col:n}=s.focus,l=e??"";if(e===void 0)try{l=t.cell(x,o,n).input;}catch{l="";}O({row:o,col:n,value:l});},[s,x]),fe=useCallback(e=>{let t=u.current;if(!t||!E)return;_.current=true;let{row:o,col:n,value:l}=E;try{v(t.editCell(x,o,n,l));}catch(m){y(m instanceof Error?m.message:String(m));}O(null);let w=selectionAt({row:o,col:n});P(e?moveFocus(w,e,{limits:D()}):w),L();},[E,x,v,D,L]),Fe=useCallback(()=>{_.current=true,O(null),L();},[L]),te=useCallback(()=>{let e=u.current;if(!e||!s)return;let t=normalizeRange(s),o=[];for(let n=t.top;n<=t.bottom;n++)for(let l=t.left;l<=t.right;l++)o.push({row:n,col:l,input:""});try{v(e.editCells(x,o));}catch(n){y(n instanceof Error?n.message:String(n));}},[s,x,v]),oe=useCallback(async()=>{let e=u.current;if(!e||!s)return;let t=normalizeRange(s);try{let o=e.cell(x,t.top,t.left).a1,n=e.cell(x,t.bottom,t.right).a1,l=e.rangeCells(x,`${o}:${n}`),w=toTsv(l.map(m=>m.map(A=>({input:A.input,isFormula:A.isFormula}))));await navigator.clipboard.writeText(w);}catch{}},[s,x]),Pe=useCallback(async()=>{await oe(),te();},[oe,te]),Ce=useCallback(async()=>{let e=u.current;if(!e||!s)return;let t;try{t=await navigator.clipboard.readText();}catch{return}let o=fromTsv(t);if(o.length===0)return;let n=normalizeRange(s),l=[],w=1;o.forEach((m,A)=>{w=Math.max(w,m.length),m.forEach((Ze,et)=>l.push({row:n.top+A,col:n.left+et,input:Ze}));});try{v(e.editCells(x,l));}catch(m){y(m instanceof Error?m.message:String(m));return}P({anchor:{row:n.top,col:n.left},focus:{row:n.top+o.length-1,col:n.left+w-1}});},[s,x,v]),he=useCallback(()=>{let e=u.current;if(e)try{v(e.undo());}catch(t){y(t instanceof Error?t.message:String(t));}},[v]),ne=useCallback(()=>{let e=u.current;if(e)try{v(e.redo());}catch(t){y(t instanceof Error?t.message:String(t));}},[v]),ze=useCallback((e,t)=>{let o=u.current;if(o)try{v(o.acceptProposal(e,{force:t})),J(({[e]:n,...l})=>l),B(),L();}catch(n){n instanceof StaleProposalError?J(l=>({...l,[e]:n.cells})):y(n instanceof Error?n.message:String(n));}},[v,B,L]),Ne=useCallback(e=>{let t=u.current;if(t)try{t.rejectProposal(e),J(({[e]:o,...n})=>n),B();}catch(o){y(o instanceof Error?o.message:String(o));}},[B]),ge=useCallback(()=>{let e=u.current;if(e)try{let t=e.save();c?c(t):Be(t,a??"workbook.xlsx",xt);}catch(t){y(t instanceof Error?t.message:String(t));}},[c,a]),je=useCallback(()=>{let e=u.current,t=i.current;if(!(!e||!t))try{let o=e.renderPng({x:t.scrollLeft,y:t.scrollTop,width:t.clientWidth,height:t.clientHeight});Be(o,yt(a),"image/png");}catch(o){y(o instanceof Error?o.message:String(o));}},[a]),Re=useCallback(e=>{let t=u.current;if(!t||!s||Y==null)return;let{row:o,col:n}=s.focus;try{v(t.editCell(x,o,n,Y));}catch(l){y(l instanceof Error?l.message:String(l));}X(null),e&&P(l=>l&&moveFocus(l,e,{limits:D()}));},[s,Y,x,v,D]),Ue=useCallback(e=>{if(!u.current||!s||!p||E)return;let o=e.metaKey||e.ctrlKey,n=e.key.toLowerCase();if(o){if(n==="c"){oe(),e.preventDefault();return}if(n==="v"){Ce(),e.preventDefault();return}if(n==="x"){Pe(),e.preventDefault();return}if(n==="z"){e.shiftKey?ne():he(),e.preventDefault();return}if(n==="y"){ne(),e.preventDefault();return}if(n==="s"){ge(),e.preventDefault();return}}let l=selectionKeyReducer(s,{key:e.key,shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey},D());switch(l.type){case "move":P(l.selection),e.preventDefault();break;case "startEdit":ee(l.initialInput),e.preventDefault();break;case "clear":te(),e.preventDefault();break;}},[s,p,E,D,oe,Ce,Pe,he,ne,ge,ee,te]),_e=useCallback(e=>{if(!s)return;let t=Z(e.clientX,e.clientY);t&&(e.shiftKey?P(o=>o&&extendTo(o,t,D())):P(selectionAt(t)),ce.current=true,L());},[s,Z,D,L]),Ge=useCallback(e=>{if(!ce.current)return;let t=Z(e.clientX,e.clientY);t&&P(o=>o&&extendTo(o,t,D()));},[Z,D]),Ye=useCallback(()=>{s&&ee();},[s,ee]),T=G?.grid,F=T&&s?rangeRect(T,normalizeRange(s)):null,z=T&&s?cellRect(T,s.focus.row,s.focus.col):null,N=T&&E?cellRect(T,E.row,E.col):null,Ve=p?p.contentWidth:void 0,qe=p?p.contentHeight:void 0,Je=Y??ve?.input??"",Qe=e=>{let t=u.current;if(t)try{t.setActiveSheet(e);let o=i.current;o&&(o.scrollLeft=0,o.scrollTop=0),P(selectionAt({row:0,col:0})),O(null),X(null),$(t.sheetInfo());}catch(o){y(o instanceof Error?o.message:String(o));}};return jsxs("div",{className:d,role:"application","aria-label":h.editor.appLabel,style:{position:"relative",display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:[jsxs("div",{"data-testid":"xlsx-toolbar",style:{display:"flex",gap:6,alignItems:"center",padding:"4px 6px",borderBottom:"1px solid #e0e0e0",background:"#fafafa"},children:[jsx("button",{"data-testid":"xlsx-save",onClick:ge,disabled:!p,style:{padding:"4px 12px",cursor:p?"pointer":"default"},children:h.toolbar.save}),jsx("button",{"data-testid":"xlsx-export-png",onClick:je,disabled:!p||!ke,title:h.toolbar.exportPng,style:{padding:"4px 12px",cursor:p&&ke?"pointer":"default"},children:h.toolbar.exportPng}),jsx("button",{"data-testid":"xlsx-undo",onClick:he,disabled:!p,"aria-label":h.toolbar.undo,title:h.toolbar.undo,style:{padding:"4px 10px"},children:"\u21B6"}),jsx("button",{"data-testid":"xlsx-redo",onClick:ne,disabled:!p,"aria-label":h.toolbar.redo,title:h.toolbar.redo,style:{padding:"4px 10px"},children:"\u21B7"}),jsx("input",{"data-testid":"xlsx-name-box",readOnly:true,value:ve?.a1??"",placeholder:h.toolbar.nameBoxPlaceholder,"aria-label":h.toolbar.nameBoxPlaceholder,style:{width:72,textAlign:"center"}}),jsx("input",{"data-testid":"xlsx-formula-input",value:Je,placeholder:h.toolbar.formulaPlaceholder,"aria-label":h.toolbar.formulaPlaceholder,disabled:!p,onChange:e=>X(e.target.value),onKeyDown:e=>{e.key==="Enter"?(Re(e.shiftKey?"up":"down"),L(),e.preventDefault()):e.key==="Escape"&&(X(null),L(),e.preventDefault());},onBlur:()=>Re(),style:{flex:1,minWidth:0}}),Xe&&jsxs("div",{style:{position:"relative"},children:[jsxs("button",{"data-testid":"xlsx-proposals-button",onClick:()=>Se(e=>!e),disabled:!p,"aria-expanded":Ee,"aria-label":h.proposals.panelLabel,style:{padding:"4px 12px",cursor:p?"pointer":"default"},children:[h.proposals.toolbarButton,V.length>0&&jsx("span",{"data-testid":"xlsx-proposals-count",style:{marginLeft:6,padding:"0 6px",borderRadius:8,background:U,color:"#ffffff",fontSize:12},children:V.length})]}),Ee&&jsx(Ie,{proposals:V,staleFor:$e,onAccept:ze,onReject:Ne})]})]}),jsxs("div",{ref:i,"data-testid":"xlsx-scroll",tabIndex:0,onKeyDown:Ue,onMouseDown:_e,onMouseMove:Ge,onDoubleClick:Ye,style:{position:"relative",flex:1,overflow:"auto",minHeight:0,outline:"none"},children:[jsx("div",{style:{position:"absolute",top:0,left:0,width:Ve??"100%",height:qe??"100%"}}),jsxs("div",{style:{position:"sticky",top:0,left:0,width:0,height:0},children:[jsx("canvas",{ref:k,style:{display:"block",position:"absolute",top:0,left:0}}),jsxs("div",{"data-testid":"xlsx-overlay-host",style:{position:"absolute",top:0,left:0,width:0,height:0,pointerEvents:"none"},children:[F&&jsx("div",{"data-testid":"xlsx-selection",style:{position:"absolute",left:F.x,top:F.y,width:F.w,height:F.h,boxSizing:"border-box",border:`1px solid ${U}`,background:"rgba(33, 115, 70, 0.12)"}}),z&&!E&&jsx("div",{style:{position:"absolute",left:z.x,top:z.y,width:z.w,height:z.h,boxSizing:"border-box",border:`2px solid ${U}`}}),T&&V.flatMap(e=>e.cells.map(t=>{if(t.sheet!==x)return null;let o=cellRect(T,t.row,t.col);return o?jsx(De,{rect:o,color:re(e.agentId),newText:t.newText,agentId:e.agentId},`${e.id}:${t.a1}`):null})),E&&N&&jsx("input",{ref:me,"data-testid":"xlsx-cell-editor",value:E.value,onChange:e=>O(t=>t&&{...t,value:e.target.value}),onKeyDown:e=>{e.stopPropagation(),e.key==="Enter"?(fe(e.shiftKey?"up":"down"),e.preventDefault()):e.key==="Tab"?(fe(e.shiftKey?"left":"right"),e.preventDefault()):e.key==="Escape"&&(Fe(),e.preventDefault());},onBlur:()=>{if(_.current){_.current=false;return}fe();},style:{position:"absolute",left:N.x,top:N.y,width:N.w,height:N.h,boxSizing:"border-box",border:`2px solid ${U}`,padding:"0 3px",font:"13px system-ui, sans-serif",background:"#ffffff",pointerEvents:"auto",outline:"none"}})]})]})]}),Q&&jsxs("div",{style:vt,role:"grid","aria-label":Q.label,children:[jsxs("div",{role:"row",children:[jsx("span",{role:"columnheader"}),Q.columnHeaders.map(e=>jsx("span",{role:"columnheader",children:e.label},e.col))]}),Q.rows.map(e=>jsxs("div",{role:"row",children:[jsx("span",{role:"rowheader",children:e.header}),e.cells.map(t=>jsx("span",{role:"gridcell","aria-selected":t.selected,children:t.label},t.col))]},e.row))]}),de&&jsxs("div",{"data-testid":"xlsx-error",role:"alert",style:{position:"absolute",inset:0,display:"grid",placeItems:"center",padding:16,textAlign:"center",color:"#b00020"},children:[h.editor.openError,": ",de]}),p&&p.sheetNames.length>0&&jsx("div",{"data-testid":"xlsx-sheet-tabs",role:"tablist","aria-label":h.editor.sheetTabsLabel,style:{display:"flex",gap:2,padding:"4px 6px",borderTop:"1px solid #e0e0e0",background:"#fafafa",overflowX:"auto"},children:p.sheetNames.map((e,t)=>{let o=t===p.activeSheet;return jsx("button",{role:"tab","aria-selected":o,onClick:()=>Qe(t),style:{border:"none",padding:"4px 12px",cursor:"pointer",borderBottom:o?`2px solid ${U}`:"2px solid transparent",fontWeight:o?600:400,background:o?"#ffffff":"transparent"},children:e},t)})})]})}export{wt as XlsxEditor};
1
+ import {useRef,useState,useMemo,useCallback,useEffect}from'react';import {isPngExportAvailable,isProposalsAvailable,initWasm,openWorkbook,selectionAt,paintDisplayList,buildA11yGrid,cellAtPoint,moveFocus,normalizeRange,toTsv,fromTsv,StaleProposalError,selectionKeyReducer,extendTo,rangeRect,cellRect}from'@betteroffice/xlsx';import {jsxs,jsx}from'react/jsx-runtime';var h={toolbar:{formulaPlaceholder:"Enter a value or formula",nameBoxPlaceholder:"Name box",undo:"Undo",redo:"Redo",save:"Save",exportPng:"Export PNG"},editor:{openError:"Couldn't open this workbook",sheetTabsLabel:"Sheets",appLabel:"Spreadsheet editor"},proposals:{toolbarButton:"Proposals",panelLabel:"Agent proposals",empty:"No pending proposals",cellCount:"{count} cells",cellCountOne:"1 cell",changeArrow:"\u2192",accept:"Accept",reject:"Reject",forceApply:"Force apply",staleWarning:"Cells changed since proposed: {cells}"},a11y:{gridLabel:"Spreadsheet grid",cellAnnouncement:"{address}, {value}",emptyCellAnnouncement:"{address}, empty",selectionAnnouncement:"Selected {count} cells",editingAnnouncement:"Editing {address}",rowHeaderLabel:"Row {row}",columnHeaderLabel:"Column {column}",cellLabel:"{address}, {value}",cellLabelSelected:"{address}, {value}, selected",emptyCellLabel:"{address}, empty",emptyCellLabelSelected:"{address}, empty, selected"}};function De({rect:r,color:a,newText:c,agentId:b}){return jsxs("div",{"data-testid":"xlsx-proposal-decoration","aria-hidden":"true",style:{position:"absolute",left:r.x,top:r.y,width:r.w,height:r.h,boxSizing:"border-box",border:`1.5px dashed ${a}`,pointerEvents:"none",overflow:"hidden"},children:[jsx("span",{style:{position:"absolute",left:0,right:0,bottom:1,textAlign:"center",opacity:.6,color:a,font:"11px system-ui, sans-serif",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",padding:"0 2px"},children:c}),jsx("span",{title:`${b}: ${c}`,style:{position:"absolute",top:0,right:0,width:6,height:6,background:a,pointerEvents:"auto"}})]})}var Ae=["#7c3aed","#0891b2","#c2410c","#4d7c0f","#be185d","#1d4ed8"];function nt(r){let a=2166136261;for(let c=0;c<r.length;c++)a^=r.charCodeAt(c),a=Math.imul(a,16777619);return (a>>>0)%Ae.length}function re(r){return Ae[nt(r)]}var M=h.proposals;function Me(r,a){return r.replace(/\{(\w+)\}/g,(c,b)=>String(a[b]??""))}function rt(r){return r===1?M.cellCountOne:Me(M.cellCount,{count:r})}function Ie({proposals:r,staleFor:a,onAccept:c,onReject:b}){return jsx("div",{"data-testid":"xlsx-proposals-panel",role:"region","aria-label":M.panelLabel,style:{position:"absolute",top:"100%",right:0,marginTop:4,width:320,maxHeight:420,overflowY:"auto",background:"#ffffff",border:"1px solid #d0d0d0",borderRadius:6,boxShadow:"0 6px 24px rgba(0, 0, 0, 0.16)",padding:8,zIndex:10,font:"13px system-ui, sans-serif",textAlign:"left"},children:r.length===0?jsx("div",{style:{padding:12,color:"#707070",textAlign:"center"},children:M.empty}):r.map(u=>{let i=re(u.agentId),P=a[u.id];return jsxs("div",{"data-testid":"xlsx-proposal","data-proposal-id":u.id,style:{borderLeft:`3px solid ${i}`,padding:"8px 10px",marginBottom:8,background:"#fafafa",borderRadius:4},children:[jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline"},children:[jsx("strong",{style:{color:i},children:u.agentId}),jsx("span",{style:{color:"#707070",fontSize:12},children:rt(u.cells.length)})]}),u.note&&jsx("div",{style:{color:"#404040",margin:"4px 0"},children:u.note}),jsx("ul",{style:{listStyle:"none",margin:"6px 0",padding:0},children:u.cells.map(d=>jsxs("li",{"data-testid":"xlsx-proposal-cell",style:{fontVariantNumeric:"tabular-nums",lineHeight:1.5},children:[jsx("strong",{"data-testid":"xlsx-proposal-cell-a1",children:d.a1}),":"," ",jsx("span",{style:{color:"#909090"},children:d.oldText||"\u2205"})," ",M.changeArrow," ",jsx("span",{"data-testid":"xlsx-proposal-cell-new",style:{color:i},children:d.newText})]},d.a1))}),P&&P.length>0&&jsx("div",{"data-testid":"xlsx-proposal-stale",role:"alert",style:{color:"#b45309",background:"#fef3c7",borderRadius:4,padding:"4px 6px",margin:"4px 0",fontSize:12},children:Me(M.staleWarning,{cells:P.join(", ")})}),jsxs("div",{style:{display:"flex",gap:6,marginTop:4},children:[jsx("button",{"data-testid":"xlsx-proposal-accept",onClick:()=>c(u.id),style:{padding:"3px 10px",cursor:"pointer"},children:M.accept}),P&&P.length>0&&jsx("button",{"data-testid":"xlsx-proposal-force",onClick:()=>c(u.id,true),style:{padding:"3px 10px",cursor:"pointer",color:"#b45309"},children:M.forceApply}),jsx("button",{"data-testid":"xlsx-proposal-reject",onClick:()=>b(u.id),style:{padding:"3px 10px",cursor:"pointer"},children:M.reject})]})]},u.id)})})}var H=96,K=24,U="#217346",bt="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";function mt(r,a){let c=[{op:"fillRect",x:0,y:0,w:r,h:a,color:"#ffffff"}],b=Math.ceil(r/H),u=Math.ceil(a/K);for(let i=0;i<=b;i++)c.push({op:"line",x1:i*H,y1:0,x2:i*H,y2:a,width:1,color:"#e0e0e0"});for(let i=0;i<=u;i++)c.push({op:"line",x1:0,y1:i*K,x2:r,y2:i*K,width:1,color:"#e0e0e0"});return c.push({op:"fillRect",x:0,y:0,w:r,h:K,color:"#f3f3f3"}),c.push({op:"fillRect",x:0,y:0,w:H,h:a,color:"#f3f3f3"}),c.push({op:"text",x:H+8,y:K+18,text:"OpenOOXML xlsx",fontSize:14,color:"#202020",clip:{x:H,y:K,w:H*3,h:K},align:"left"}),{width:r,height:a,commands:c}}function Ke(r,a){if(!r||r.length<2)return a;let c=[];for(let u=1;u<r.length;u++)c.push(r[u]-r[u-1]);c.sort((u,i)=>u-i);let b=c[c.length>>1];return b>0?b:a}function yt(r,a,c){let b=Ke(r?.grid?.rowOffsets,K),u=Ke(r?.grid?.colOffsets,H),i=Math.max(1,Math.round(a.contentHeight/b))+1,P=Math.max(1,Math.round(a.contentWidth/u))+1,d=Math.max(1,Math.floor(c/b));return {rows:i,cols:P,rowsPerPage:d}}function We(r,a,c){let b=new Blob([new Uint8Array(r)],{type:c}),u=URL.createObjectURL(b),i=document.createElement("a");i.href=u,i.download=a,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(u);}function vt(r){return `${(r??"workbook.xlsx").replace(/\.xlsx$/i,"")}.png`}var wt={position:"absolute",width:1,height:1,margin:-1,padding:0,border:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap"};function Et({file:r,fileName:a,onSave:c,onReady:b,className:u}){let i=useRef(null),P=useRef(null),d=useRef(null),ie=useRef(null),O=useRef(null),me=useRef(null),ce=useRef(false),_=useRef(false),ye=useRef(b);ye.current=b;let[p,W]=useState(null),[de,m]=useState(null),[G,Be]=useState(null),[s,E]=useState(null),[S,$]=useState(null),[ve,ue]=useState(null),[Y,X]=useState(null),[we,Oe]=useState(0),[V,q]=useState([]),[Ee,Se]=useState(false),[$e,J]=useState({}),x=p?.activeSheet??0,ke=useMemo(()=>isPngExportAvailable(),[]),Xe=useMemo(()=>isProposalsAvailable(),[]),B=useCallback(()=>{let e=d.current;if(!e){q([]);return}try{q(e.listProposals());}catch{q([]);}},[]);useEffect(()=>{if($(null),X(null),q([]),J({}),Se(false),!r){d.current=null,W(null),E(null),m(null);return}d.current=null,W(null),E(null);let e=null,t=false;return initWasm().then(()=>{if(!t)try{e=openWorkbook(r),d.current=e,W(e.sheetInfo()),E(selectionAt({row:0,col:0})),m(null),B(),ye.current?.({handle:e,refreshProposals:B});}catch(o){d.current=null,W(null),E(null),m(o instanceof Error?o.message:String(o));}},o=>{t||(d.current=null,W(null),E(null),m(o instanceof Error?o.message:String(o)));}),()=>{t=true,e?.dispose(),d.current=null;}},[r,B]);let pe=useCallback(()=>{let e=i.current,t=P.current;if(!e||!t)return;let o=t.getContext("2d");if(!o)return;let n=window.devicePixelRatio||1,l=e.clientWidth,w=e.clientHeight;if(l===0||w===0)return;t.width=Math.round(l*n),t.height=Math.round(w*n),t.style.width=`${l}px`,t.style.height=`${w}px`;let y=d.current,A;if(y)try{A=y.displayList({x:e.scrollLeft,y:e.scrollTop,width:l,height:w});}catch{return}else A=mt(l,w);paintDisplayList(o,A,n),ie.current=A,Be(A);},[]);useEffect(()=>{let e=i.current;if(!e)return;let t=()=>{O.current==null&&(O.current=requestAnimationFrame(()=>{O.current=null,pe();}));};pe(),e.addEventListener("scroll",t,{passive:true});let o=new ResizeObserver(t);return o.observe(e),()=>{e.removeEventListener("scroll",t),o.disconnect(),O.current!=null&&(cancelAnimationFrame(O.current),O.current=null);}},[pe,p,de,we]),useEffect(()=>{let e=d.current;if(!e||!s||!p){ue(null);return}try{ue(e.cell(x,s.focus.row,s.focus.col));}catch{ue(null);}},[s,p,x,we]),useEffect(()=>{let e=()=>{ce.current=false;};return window.addEventListener("mouseup",e),()=>window.removeEventListener("mouseup",e)},[]);let Q=useMemo(()=>!G||!p?null:buildA11yGrid(G,s,p.sheetNames[x]??"",h.a11y),[G,s,p,x]),L=useCallback(()=>{i.current?.focus({preventScroll:true});},[]);useEffect(()=>{S&&me.current?.focus({preventScroll:true});},[S]);let v=useCallback(e=>{W(e.sheetInfo),Oe(t=>t+1);},[]),D=useCallback(()=>yt(ie.current,p,i.current?.clientHeight??0),[p]),Z=useCallback((e,t)=>{let o=P.current,n=ie.current?.grid;if(!o||!n)return null;let l=o.getBoundingClientRect();return cellAtPoint(n,e-l.left,t-l.top)},[]),ee=useCallback(e=>{let t=d.current;if(!t||!s)return;let{row:o,col:n}=s.focus,l=e??"";if(e===void 0)try{l=t.cell(x,o,n).input;}catch{l="";}$({row:o,col:n,value:l});},[s,x]),fe=useCallback(e=>{let t=d.current;if(!t||!S)return;_.current=true;let{row:o,col:n,value:l}=S;try{v(t.editCell(x,o,n,l));}catch(y){m(y instanceof Error?y.message:String(y));}$(null);let w=selectionAt({row:o,col:n});E(e?moveFocus(w,e,{limits:D()}):w),L();},[S,x,v,D,L]),Fe=useCallback(()=>{_.current=true,$(null),L();},[L]),te=useCallback(()=>{let e=d.current;if(!e||!s)return;let t=normalizeRange(s),o=[];for(let n=t.top;n<=t.bottom;n++)for(let l=t.left;l<=t.right;l++)o.push({row:n,col:l,input:""});try{v(e.editCells(x,o));}catch(n){m(n instanceof Error?n.message:String(n));}},[s,x,v]),oe=useCallback(async()=>{let e=d.current;if(!e||!s)return;let t=normalizeRange(s);try{let o=e.cell(x,t.top,t.left).a1,n=e.cell(x,t.bottom,t.right).a1,l=e.rangeCells(x,`${o}:${n}`),w=toTsv(l.map(y=>y.map(A=>({input:A.input,isFormula:A.isFormula}))));await navigator.clipboard.writeText(w);}catch{}},[s,x]),Pe=useCallback(async()=>{await oe(),te();},[oe,te]),Ce=useCallback(async()=>{let e=d.current;if(!e||!s)return;let t;try{t=await navigator.clipboard.readText();}catch{return}let o=fromTsv(t);if(o.length===0)return;let n=normalizeRange(s),l=[],w=1;o.forEach((y,A)=>{w=Math.max(w,y.length),y.forEach((Ze,et)=>l.push({row:n.top+A,col:n.left+et,input:Ze}));});try{v(e.editCells(x,l));}catch(y){m(y instanceof Error?y.message:String(y));return}E({anchor:{row:n.top,col:n.left},focus:{row:n.top+o.length-1,col:n.left+w-1}});},[s,x,v]),he=useCallback(()=>{let e=d.current;if(e)try{v(e.undo());}catch(t){m(t instanceof Error?t.message:String(t));}},[v]),ne=useCallback(()=>{let e=d.current;if(e)try{v(e.redo());}catch(t){m(t instanceof Error?t.message:String(t));}},[v]),ze=useCallback((e,t)=>{let o=d.current;if(o)try{v(o.acceptProposal(e,{force:t})),J(({[e]:n,...l})=>l),B(),L();}catch(n){n instanceof StaleProposalError?J(l=>({...l,[e]:n.cells})):m(n instanceof Error?n.message:String(n));}},[v,B,L]),Ne=useCallback(e=>{let t=d.current;if(t)try{t.rejectProposal(e),J(({[e]:o,...n})=>n),B();}catch(o){m(o instanceof Error?o.message:String(o));}},[B]),ge=useCallback(()=>{let e=d.current;if(e)try{let t=e.save();c?c(t):We(t,a??"workbook.xlsx",bt);}catch(t){m(t instanceof Error?t.message:String(t));}},[c,a]),je=useCallback(()=>{let e=d.current,t=i.current;if(!(!e||!t))try{let o=e.renderPng({x:t.scrollLeft,y:t.scrollTop,width:t.clientWidth,height:t.clientHeight});We(o,vt(a),"image/png");}catch(o){m(o instanceof Error?o.message:String(o));}},[a]),Re=useCallback(e=>{let t=d.current;if(!t||!s||Y==null)return;let{row:o,col:n}=s.focus;try{v(t.editCell(x,o,n,Y));}catch(l){m(l instanceof Error?l.message:String(l));}X(null),e&&E(l=>l&&moveFocus(l,e,{limits:D()}));},[s,Y,x,v,D]),Ue=useCallback(e=>{if(!d.current||!s||!p||S)return;let o=e.metaKey||e.ctrlKey,n=e.key.toLowerCase();if(o){if(n==="c"){oe(),e.preventDefault();return}if(n==="v"){Ce(),e.preventDefault();return}if(n==="x"){Pe(),e.preventDefault();return}if(n==="z"){e.shiftKey?ne():he(),e.preventDefault();return}if(n==="y"){ne(),e.preventDefault();return}if(n==="s"){ge(),e.preventDefault();return}}let l=selectionKeyReducer(s,{key:e.key,shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey},D());switch(l.type){case "move":E(l.selection),e.preventDefault();break;case "startEdit":ee(l.initialInput),e.preventDefault();break;case "clear":te(),e.preventDefault();break;}},[s,p,S,D,oe,Ce,Pe,he,ne,ge,ee,te]),_e=useCallback(e=>{if(!s)return;let t=Z(e.clientX,e.clientY);t&&(e.shiftKey?E(o=>o&&extendTo(o,t,D())):E(selectionAt(t)),ce.current=true,L());},[s,Z,D,L]),Ge=useCallback(e=>{if(!ce.current)return;let t=Z(e.clientX,e.clientY);t&&E(o=>o&&extendTo(o,t,D()));},[Z,D]),Ye=useCallback(()=>{s&&ee();},[s,ee]),T=G?.grid,F=T&&s?rangeRect(T,normalizeRange(s)):null,z=T&&s?cellRect(T,s.focus.row,s.focus.col):null,N=T&&S?cellRect(T,S.row,S.col):null,Ve=p?p.contentWidth:void 0,qe=p?p.contentHeight:void 0,Je=Y??ve?.input??"",Qe=e=>{let t=d.current;if(t)try{t.setActiveSheet(e);let o=i.current;o&&(o.scrollLeft=0,o.scrollTop=0),E(selectionAt({row:0,col:0})),$(null),X(null),W(t.sheetInfo());}catch(o){m(o instanceof Error?o.message:String(o));}};return jsxs("div",{className:u,role:"application","aria-label":h.editor.appLabel,style:{position:"relative",display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:[jsxs("div",{"data-testid":"xlsx-toolbar",style:{display:"flex",gap:6,alignItems:"center",padding:"4px 6px",borderBottom:"1px solid #e0e0e0",background:"#fafafa"},children:[jsx("button",{"data-testid":"xlsx-save",onClick:ge,disabled:!p,style:{padding:"4px 12px",cursor:p?"pointer":"default"},children:h.toolbar.save}),jsx("button",{"data-testid":"xlsx-export-png",onClick:je,disabled:!p||!ke,title:h.toolbar.exportPng,style:{padding:"4px 12px",cursor:p&&ke?"pointer":"default"},children:h.toolbar.exportPng}),jsx("button",{"data-testid":"xlsx-undo",onClick:he,disabled:!p,"aria-label":h.toolbar.undo,title:h.toolbar.undo,style:{padding:"4px 10px"},children:"\u21B6"}),jsx("button",{"data-testid":"xlsx-redo",onClick:ne,disabled:!p,"aria-label":h.toolbar.redo,title:h.toolbar.redo,style:{padding:"4px 10px"},children:"\u21B7"}),jsx("input",{"data-testid":"xlsx-name-box",readOnly:true,value:ve?.a1??"",placeholder:h.toolbar.nameBoxPlaceholder,"aria-label":h.toolbar.nameBoxPlaceholder,style:{width:72,textAlign:"center"}}),jsx("input",{"data-testid":"xlsx-formula-input",value:Je,placeholder:h.toolbar.formulaPlaceholder,"aria-label":h.toolbar.formulaPlaceholder,disabled:!p,onChange:e=>X(e.target.value),onKeyDown:e=>{e.key==="Enter"?(Re(e.shiftKey?"up":"down"),L(),e.preventDefault()):e.key==="Escape"&&(X(null),L(),e.preventDefault());},onBlur:()=>Re(),style:{flex:1,minWidth:0}}),Xe&&jsxs("div",{style:{position:"relative"},children:[jsxs("button",{"data-testid":"xlsx-proposals-button",onClick:()=>Se(e=>!e),disabled:!p,"aria-expanded":Ee,"aria-label":h.proposals.panelLabel,style:{padding:"4px 12px",cursor:p?"pointer":"default"},children:[h.proposals.toolbarButton,V.length>0&&jsx("span",{"data-testid":"xlsx-proposals-count",style:{marginLeft:6,padding:"0 6px",borderRadius:8,background:U,color:"#ffffff",fontSize:12},children:V.length})]}),Ee&&jsx(Ie,{proposals:V,staleFor:$e,onAccept:ze,onReject:Ne})]})]}),jsxs("div",{ref:i,"data-testid":"xlsx-scroll",tabIndex:0,onKeyDown:Ue,onMouseDown:_e,onMouseMove:Ge,onDoubleClick:Ye,style:{position:"relative",flex:1,overflow:"auto",minHeight:0,outline:"none"},children:[jsx("div",{style:{position:"absolute",top:0,left:0,width:Ve??"100%",height:qe??"100%"}}),jsxs("div",{style:{position:"sticky",top:0,left:0,width:0,height:0},children:[jsx("canvas",{ref:P,style:{display:"block",position:"absolute",top:0,left:0}}),jsxs("div",{"data-testid":"xlsx-overlay-host",style:{position:"absolute",top:0,left:0,width:0,height:0,pointerEvents:"none"},children:[F&&jsx("div",{"data-testid":"xlsx-selection",style:{position:"absolute",left:F.x,top:F.y,width:F.w,height:F.h,boxSizing:"border-box",border:`1px solid ${U}`,background:"rgba(33, 115, 70, 0.12)"}}),z&&!S&&jsx("div",{style:{position:"absolute",left:z.x,top:z.y,width:z.w,height:z.h,boxSizing:"border-box",border:`2px solid ${U}`}}),T&&V.flatMap(e=>e.cells.map(t=>{if(t.sheet!==x)return null;let o=cellRect(T,t.row,t.col);return o?jsx(De,{rect:o,color:re(e.agentId),newText:t.newText,agentId:e.agentId},`${e.id}:${t.a1}`):null})),S&&N&&jsx("input",{ref:me,"data-testid":"xlsx-cell-editor",value:S.value,onChange:e=>$(t=>t&&{...t,value:e.target.value}),onKeyDown:e=>{e.stopPropagation(),e.key==="Enter"?(fe(e.shiftKey?"up":"down"),e.preventDefault()):e.key==="Tab"?(fe(e.shiftKey?"left":"right"),e.preventDefault()):e.key==="Escape"&&(Fe(),e.preventDefault());},onBlur:()=>{if(_.current){_.current=false;return}fe();},style:{position:"absolute",left:N.x,top:N.y,width:N.w,height:N.h,boxSizing:"border-box",border:`2px solid ${U}`,padding:"0 3px",font:"13px system-ui, sans-serif",background:"#ffffff",pointerEvents:"auto",outline:"none"}})]})]})]}),Q&&jsxs("div",{style:wt,role:"grid","aria-label":Q.label,children:[jsxs("div",{role:"row",children:[jsx("span",{role:"columnheader"}),Q.columnHeaders.map(e=>jsx("span",{role:"columnheader",children:e.label},e.col))]}),Q.rows.map(e=>jsxs("div",{role:"row",children:[jsx("span",{role:"rowheader",children:e.header}),e.cells.map(t=>jsx("span",{role:"gridcell","aria-selected":t.selected,children:t.label},t.col))]},e.row))]}),de&&jsxs("div",{"data-testid":"xlsx-error",role:"alert",style:{position:"absolute",inset:0,display:"grid",placeItems:"center",padding:16,textAlign:"center",color:"#b00020"},children:[h.editor.openError,": ",de]}),p&&p.sheetNames.length>0&&jsx("div",{"data-testid":"xlsx-sheet-tabs",role:"tablist","aria-label":h.editor.sheetTabsLabel,style:{display:"flex",gap:2,padding:"4px 6px",borderTop:"1px solid #e0e0e0",background:"#fafafa",overflowX:"auto"},children:p.sheetNames.map((e,t)=>{let o=t===p.activeSheet;return jsx("button",{role:"tab","aria-selected":o,onClick:()=>Qe(t),style:{border:"none",padding:"4px 12px",cursor:"pointer",borderBottom:o?`2px solid ${U}`:"2px solid transparent",fontWeight:o?600:400,background:o?"#ffffff":"transparent"},children:e},t)})})]})}export{Et as XlsxEditor};
package/package.json CHANGED
@@ -1,17 +1,16 @@
1
1
  {
2
2
  "name": "@betteroffice/xlsx-react",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "React chrome for the BetterOffice xlsx editor.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
- "main": "./dist/index.cjs",
7
+ "main": "./dist/index.js",
8
8
  "module": "./dist/index.js",
9
9
  "types": "./dist/index.d.ts",
10
10
  "exports": {
11
11
  ".": {
12
12
  "types": "./dist/index.d.ts",
13
- "import": "./dist/index.js",
14
- "require": "./dist/index.cjs"
13
+ "import": "./dist/index.js"
15
14
  }
16
15
  },
17
16
  "files": [
@@ -22,7 +21,7 @@
22
21
  "typecheck": "tsc --noEmit -p ."
23
22
  },
24
23
  "dependencies": {
25
- "@betteroffice/xlsx": "0.0.3"
24
+ "@betteroffice/xlsx": "0.0.4"
26
25
  },
27
26
  "peerDependencies": {
28
27
  "react": "^18.0.0 || ^19.0.0",
package/dist/index.cjs DELETED
@@ -1 +0,0 @@
1
- 'use strict';var react=require('react'),xlsx=require('@betteroffice/xlsx'),jsxRuntime=require('react/jsx-runtime');var h={toolbar:{formulaPlaceholder:"Enter a value or formula",nameBoxPlaceholder:"Name box",undo:"Undo",redo:"Redo",save:"Save",exportPng:"Export PNG"},editor:{openError:"Couldn't open this workbook",sheetTabsLabel:"Sheets",appLabel:"Spreadsheet editor"},proposals:{toolbarButton:"Proposals",panelLabel:"Agent proposals",empty:"No pending proposals",cellCount:"{count} cells",cellCountOne:"1 cell",changeArrow:"\u2192",accept:"Accept",reject:"Reject",forceApply:"Force apply",staleWarning:"Cells changed since proposed: {cells}"},a11y:{gridLabel:"Spreadsheet grid",cellAnnouncement:"{address}, {value}",emptyCellAnnouncement:"{address}, empty",selectionAnnouncement:"Selected {count} cells",editingAnnouncement:"Editing {address}",rowHeaderLabel:"Row {row}",columnHeaderLabel:"Column {column}",cellLabel:"{address}, {value}",cellLabelSelected:"{address}, {value}, selected",emptyCellLabel:"{address}, empty",emptyCellLabelSelected:"{address}, empty, selected"}};function De({rect:r,color:a,newText:c,agentId:b}){return jsxRuntime.jsxs("div",{"data-testid":"xlsx-proposal-decoration","aria-hidden":"true",style:{position:"absolute",left:r.x,top:r.y,width:r.w,height:r.h,boxSizing:"border-box",border:`1.5px dashed ${a}`,pointerEvents:"none",overflow:"hidden"},children:[jsxRuntime.jsx("span",{style:{position:"absolute",left:0,right:0,bottom:1,textAlign:"center",opacity:.6,color:a,font:"11px system-ui, sans-serif",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",padding:"0 2px"},children:c}),jsxRuntime.jsx("span",{title:`${b}: ${c}`,style:{position:"absolute",top:0,right:0,width:6,height:6,background:a,pointerEvents:"auto"}})]})}var Ae=["#7c3aed","#0891b2","#c2410c","#4d7c0f","#be185d","#1d4ed8"];function nt(r){let a=2166136261;for(let c=0;c<r.length;c++)a^=r.charCodeAt(c),a=Math.imul(a,16777619);return (a>>>0)%Ae.length}function re(r){return Ae[nt(r)]}var M=h.proposals;function Me(r,a){return r.replace(/\{(\w+)\}/g,(c,b)=>String(a[b]??""))}function rt(r){return r===1?M.cellCountOne:Me(M.cellCount,{count:r})}function Ie({proposals:r,staleFor:a,onAccept:c,onReject:b}){return jsxRuntime.jsx("div",{"data-testid":"xlsx-proposals-panel",role:"region","aria-label":M.panelLabel,style:{position:"absolute",top:"100%",right:0,marginTop:4,width:320,maxHeight:420,overflowY:"auto",background:"#ffffff",border:"1px solid #d0d0d0",borderRadius:6,boxShadow:"0 6px 24px rgba(0, 0, 0, 0.16)",padding:8,zIndex:10,font:"13px system-ui, sans-serif",textAlign:"left"},children:r.length===0?jsxRuntime.jsx("div",{style:{padding:12,color:"#707070",textAlign:"center"},children:M.empty}):r.map(d=>{let i=re(d.agentId),k=a[d.id];return jsxRuntime.jsxs("div",{"data-testid":"xlsx-proposal","data-proposal-id":d.id,style:{borderLeft:`3px solid ${i}`,padding:"8px 10px",marginBottom:8,background:"#fafafa",borderRadius:4},children:[jsxRuntime.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline"},children:[jsxRuntime.jsx("strong",{style:{color:i},children:d.agentId}),jsxRuntime.jsx("span",{style:{color:"#707070",fontSize:12},children:rt(d.cells.length)})]}),d.note&&jsxRuntime.jsx("div",{style:{color:"#404040",margin:"4px 0"},children:d.note}),jsxRuntime.jsx("ul",{style:{listStyle:"none",margin:"6px 0",padding:0},children:d.cells.map(u=>jsxRuntime.jsxs("li",{"data-testid":"xlsx-proposal-cell",style:{fontVariantNumeric:"tabular-nums",lineHeight:1.5},children:[jsxRuntime.jsx("strong",{"data-testid":"xlsx-proposal-cell-a1",children:u.a1}),":"," ",jsxRuntime.jsx("span",{style:{color:"#909090"},children:u.oldText||"\u2205"})," ",M.changeArrow," ",jsxRuntime.jsx("span",{"data-testid":"xlsx-proposal-cell-new",style:{color:i},children:u.newText})]},u.a1))}),k&&k.length>0&&jsxRuntime.jsx("div",{"data-testid":"xlsx-proposal-stale",role:"alert",style:{color:"#b45309",background:"#fef3c7",borderRadius:4,padding:"4px 6px",margin:"4px 0",fontSize:12},children:Me(M.staleWarning,{cells:k.join(", ")})}),jsxRuntime.jsxs("div",{style:{display:"flex",gap:6,marginTop:4},children:[jsxRuntime.jsx("button",{"data-testid":"xlsx-proposal-accept",onClick:()=>c(d.id),style:{padding:"3px 10px",cursor:"pointer"},children:M.accept}),k&&k.length>0&&jsxRuntime.jsx("button",{"data-testid":"xlsx-proposal-force",onClick:()=>c(d.id,true),style:{padding:"3px 10px",cursor:"pointer",color:"#b45309"},children:M.forceApply}),jsxRuntime.jsx("button",{"data-testid":"xlsx-proposal-reject",onClick:()=>b(d.id),style:{padding:"3px 10px",cursor:"pointer"},children:M.reject})]})]},d.id)})})}var H=96,K=24,U="#217346",xt="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";function bt(r,a){let c=[{op:"fillRect",x:0,y:0,w:r,h:a,color:"#ffffff"}],b=Math.ceil(r/H),d=Math.ceil(a/K);for(let i=0;i<=b;i++)c.push({op:"line",x1:i*H,y1:0,x2:i*H,y2:a,width:1,color:"#e0e0e0"});for(let i=0;i<=d;i++)c.push({op:"line",x1:0,y1:i*K,x2:r,y2:i*K,width:1,color:"#e0e0e0"});return c.push({op:"fillRect",x:0,y:0,w:r,h:K,color:"#f3f3f3"}),c.push({op:"fillRect",x:0,y:0,w:H,h:a,color:"#f3f3f3"}),c.push({op:"text",x:H+8,y:K+18,text:"OpenOOXML xlsx",fontSize:14,color:"#202020",clip:{x:H,y:K,w:H*3,h:K},align:"left"}),{width:r,height:a,commands:c}}function Ke(r,a){if(!r||r.length<2)return a;let c=[];for(let d=1;d<r.length;d++)c.push(r[d]-r[d-1]);c.sort((d,i)=>d-i);let b=c[c.length>>1];return b>0?b:a}function mt(r,a,c){let b=Ke(r?.grid?.rowOffsets,K),d=Ke(r?.grid?.colOffsets,H),i=Math.max(1,Math.round(a.contentHeight/b))+1,k=Math.max(1,Math.round(a.contentWidth/d))+1,u=Math.max(1,Math.floor(c/b));return {rows:i,cols:k,rowsPerPage:u}}function Be(r,a,c){let b=new Blob([new Uint8Array(r)],{type:c}),d=URL.createObjectURL(b),i=document.createElement("a");i.href=d,i.download=a,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(d);}function yt(r){return `${(r??"workbook.xlsx").replace(/\.xlsx$/i,"")}.png`}var vt={position:"absolute",width:1,height:1,margin:-1,padding:0,border:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap"};function wt({file:r,fileName:a,onSave:c,onReady:b,className:d}){let i=react.useRef(null),k=react.useRef(null),u=react.useRef(null),ie=react.useRef(null),W=react.useRef(null),me=react.useRef(null),ce=react.useRef(false),_=react.useRef(false),ye=react.useRef(b);ye.current=b;let[p,$]=react.useState(null),[de,y]=react.useState(null),[G,We]=react.useState(null),[s,P]=react.useState(null),[E,O]=react.useState(null),[ve,ue]=react.useState(null),[Y,X]=react.useState(null),[we,Oe]=react.useState(0),[V,q]=react.useState([]),[Ee,Se]=react.useState(false),[$e,J]=react.useState({}),x=p?.activeSheet??0,ke=react.useMemo(()=>xlsx.isPngExportAvailable(),[]),Xe=react.useMemo(()=>xlsx.isProposalsAvailable(),[]),B=react.useCallback(()=>{let e=u.current;if(!e){q([]);return}try{q(e.listProposals());}catch{q([]);}},[]);react.useEffect(()=>{if(O(null),X(null),q([]),J({}),Se(false),!r){u.current=null,$(null),P(null),y(null);return}let e=null;try{e=xlsx.openWorkbook(r),u.current=e,$(e.sheetInfo()),P(xlsx.selectionAt({row:0,col:0})),y(null),B(),ye.current?.({handle:e,refreshProposals:B});}catch(t){u.current=null,$(null),P(null),y(t instanceof Error?t.message:String(t));}return ()=>{e?.dispose(),u.current=null;}},[r,B]);let pe=react.useCallback(()=>{let e=i.current,t=k.current;if(!e||!t)return;let o=t.getContext("2d");if(!o)return;let n=window.devicePixelRatio||1,l=e.clientWidth,w=e.clientHeight;if(l===0||w===0)return;t.width=Math.round(l*n),t.height=Math.round(w*n),t.style.width=`${l}px`,t.style.height=`${w}px`;let m=u.current,A;if(m)try{A=m.displayList({x:e.scrollLeft,y:e.scrollTop,width:l,height:w});}catch{return}else A=bt(l,w);xlsx.paintDisplayList(o,A,n),ie.current=A,We(A);},[]);react.useEffect(()=>{let e=i.current;if(!e)return;let t=()=>{W.current==null&&(W.current=requestAnimationFrame(()=>{W.current=null,pe();}));};pe(),e.addEventListener("scroll",t,{passive:true});let o=new ResizeObserver(t);return o.observe(e),()=>{e.removeEventListener("scroll",t),o.disconnect(),W.current!=null&&(cancelAnimationFrame(W.current),W.current=null);}},[pe,p,de,we]),react.useEffect(()=>{let e=u.current;if(!e||!s||!p){ue(null);return}try{ue(e.cell(x,s.focus.row,s.focus.col));}catch{ue(null);}},[s,p,x,we]),react.useEffect(()=>{let e=()=>{ce.current=false;};return window.addEventListener("mouseup",e),()=>window.removeEventListener("mouseup",e)},[]);let Q=react.useMemo(()=>!G||!p?null:xlsx.buildA11yGrid(G,s,p.sheetNames[x]??"",h.a11y),[G,s,p,x]),L=react.useCallback(()=>{i.current?.focus({preventScroll:true});},[]);react.useEffect(()=>{E&&me.current?.focus({preventScroll:true});},[E]);let v=react.useCallback(e=>{$(e.sheetInfo),Oe(t=>t+1);},[]),D=react.useCallback(()=>mt(ie.current,p,i.current?.clientHeight??0),[p]),Z=react.useCallback((e,t)=>{let o=k.current,n=ie.current?.grid;if(!o||!n)return null;let l=o.getBoundingClientRect();return xlsx.cellAtPoint(n,e-l.left,t-l.top)},[]),ee=react.useCallback(e=>{let t=u.current;if(!t||!s)return;let{row:o,col:n}=s.focus,l=e??"";if(e===void 0)try{l=t.cell(x,o,n).input;}catch{l="";}O({row:o,col:n,value:l});},[s,x]),fe=react.useCallback(e=>{let t=u.current;if(!t||!E)return;_.current=true;let{row:o,col:n,value:l}=E;try{v(t.editCell(x,o,n,l));}catch(m){y(m instanceof Error?m.message:String(m));}O(null);let w=xlsx.selectionAt({row:o,col:n});P(e?xlsx.moveFocus(w,e,{limits:D()}):w),L();},[E,x,v,D,L]),Fe=react.useCallback(()=>{_.current=true,O(null),L();},[L]),te=react.useCallback(()=>{let e=u.current;if(!e||!s)return;let t=xlsx.normalizeRange(s),o=[];for(let n=t.top;n<=t.bottom;n++)for(let l=t.left;l<=t.right;l++)o.push({row:n,col:l,input:""});try{v(e.editCells(x,o));}catch(n){y(n instanceof Error?n.message:String(n));}},[s,x,v]),oe=react.useCallback(async()=>{let e=u.current;if(!e||!s)return;let t=xlsx.normalizeRange(s);try{let o=e.cell(x,t.top,t.left).a1,n=e.cell(x,t.bottom,t.right).a1,l=e.rangeCells(x,`${o}:${n}`),w=xlsx.toTsv(l.map(m=>m.map(A=>({input:A.input,isFormula:A.isFormula}))));await navigator.clipboard.writeText(w);}catch{}},[s,x]),Pe=react.useCallback(async()=>{await oe(),te();},[oe,te]),Ce=react.useCallback(async()=>{let e=u.current;if(!e||!s)return;let t;try{t=await navigator.clipboard.readText();}catch{return}let o=xlsx.fromTsv(t);if(o.length===0)return;let n=xlsx.normalizeRange(s),l=[],w=1;o.forEach((m,A)=>{w=Math.max(w,m.length),m.forEach((Ze,et)=>l.push({row:n.top+A,col:n.left+et,input:Ze}));});try{v(e.editCells(x,l));}catch(m){y(m instanceof Error?m.message:String(m));return}P({anchor:{row:n.top,col:n.left},focus:{row:n.top+o.length-1,col:n.left+w-1}});},[s,x,v]),he=react.useCallback(()=>{let e=u.current;if(e)try{v(e.undo());}catch(t){y(t instanceof Error?t.message:String(t));}},[v]),ne=react.useCallback(()=>{let e=u.current;if(e)try{v(e.redo());}catch(t){y(t instanceof Error?t.message:String(t));}},[v]),ze=react.useCallback((e,t)=>{let o=u.current;if(o)try{v(o.acceptProposal(e,{force:t})),J(({[e]:n,...l})=>l),B(),L();}catch(n){n instanceof xlsx.StaleProposalError?J(l=>({...l,[e]:n.cells})):y(n instanceof Error?n.message:String(n));}},[v,B,L]),Ne=react.useCallback(e=>{let t=u.current;if(t)try{t.rejectProposal(e),J(({[e]:o,...n})=>n),B();}catch(o){y(o instanceof Error?o.message:String(o));}},[B]),ge=react.useCallback(()=>{let e=u.current;if(e)try{let t=e.save();c?c(t):Be(t,a??"workbook.xlsx",xt);}catch(t){y(t instanceof Error?t.message:String(t));}},[c,a]),je=react.useCallback(()=>{let e=u.current,t=i.current;if(!(!e||!t))try{let o=e.renderPng({x:t.scrollLeft,y:t.scrollTop,width:t.clientWidth,height:t.clientHeight});Be(o,yt(a),"image/png");}catch(o){y(o instanceof Error?o.message:String(o));}},[a]),Re=react.useCallback(e=>{let t=u.current;if(!t||!s||Y==null)return;let{row:o,col:n}=s.focus;try{v(t.editCell(x,o,n,Y));}catch(l){y(l instanceof Error?l.message:String(l));}X(null),e&&P(l=>l&&xlsx.moveFocus(l,e,{limits:D()}));},[s,Y,x,v,D]),Ue=react.useCallback(e=>{if(!u.current||!s||!p||E)return;let o=e.metaKey||e.ctrlKey,n=e.key.toLowerCase();if(o){if(n==="c"){oe(),e.preventDefault();return}if(n==="v"){Ce(),e.preventDefault();return}if(n==="x"){Pe(),e.preventDefault();return}if(n==="z"){e.shiftKey?ne():he(),e.preventDefault();return}if(n==="y"){ne(),e.preventDefault();return}if(n==="s"){ge(),e.preventDefault();return}}let l=xlsx.selectionKeyReducer(s,{key:e.key,shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey},D());switch(l.type){case "move":P(l.selection),e.preventDefault();break;case "startEdit":ee(l.initialInput),e.preventDefault();break;case "clear":te(),e.preventDefault();break;}},[s,p,E,D,oe,Ce,Pe,he,ne,ge,ee,te]),_e=react.useCallback(e=>{if(!s)return;let t=Z(e.clientX,e.clientY);t&&(e.shiftKey?P(o=>o&&xlsx.extendTo(o,t,D())):P(xlsx.selectionAt(t)),ce.current=true,L());},[s,Z,D,L]),Ge=react.useCallback(e=>{if(!ce.current)return;let t=Z(e.clientX,e.clientY);t&&P(o=>o&&xlsx.extendTo(o,t,D()));},[Z,D]),Ye=react.useCallback(()=>{s&&ee();},[s,ee]),T=G?.grid,F=T&&s?xlsx.rangeRect(T,xlsx.normalizeRange(s)):null,z=T&&s?xlsx.cellRect(T,s.focus.row,s.focus.col):null,N=T&&E?xlsx.cellRect(T,E.row,E.col):null,Ve=p?p.contentWidth:void 0,qe=p?p.contentHeight:void 0,Je=Y??ve?.input??"",Qe=e=>{let t=u.current;if(t)try{t.setActiveSheet(e);let o=i.current;o&&(o.scrollLeft=0,o.scrollTop=0),P(xlsx.selectionAt({row:0,col:0})),O(null),X(null),$(t.sheetInfo());}catch(o){y(o instanceof Error?o.message:String(o));}};return jsxRuntime.jsxs("div",{className:d,role:"application","aria-label":h.editor.appLabel,style:{position:"relative",display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:[jsxRuntime.jsxs("div",{"data-testid":"xlsx-toolbar",style:{display:"flex",gap:6,alignItems:"center",padding:"4px 6px",borderBottom:"1px solid #e0e0e0",background:"#fafafa"},children:[jsxRuntime.jsx("button",{"data-testid":"xlsx-save",onClick:ge,disabled:!p,style:{padding:"4px 12px",cursor:p?"pointer":"default"},children:h.toolbar.save}),jsxRuntime.jsx("button",{"data-testid":"xlsx-export-png",onClick:je,disabled:!p||!ke,title:h.toolbar.exportPng,style:{padding:"4px 12px",cursor:p&&ke?"pointer":"default"},children:h.toolbar.exportPng}),jsxRuntime.jsx("button",{"data-testid":"xlsx-undo",onClick:he,disabled:!p,"aria-label":h.toolbar.undo,title:h.toolbar.undo,style:{padding:"4px 10px"},children:"\u21B6"}),jsxRuntime.jsx("button",{"data-testid":"xlsx-redo",onClick:ne,disabled:!p,"aria-label":h.toolbar.redo,title:h.toolbar.redo,style:{padding:"4px 10px"},children:"\u21B7"}),jsxRuntime.jsx("input",{"data-testid":"xlsx-name-box",readOnly:true,value:ve?.a1??"",placeholder:h.toolbar.nameBoxPlaceholder,"aria-label":h.toolbar.nameBoxPlaceholder,style:{width:72,textAlign:"center"}}),jsxRuntime.jsx("input",{"data-testid":"xlsx-formula-input",value:Je,placeholder:h.toolbar.formulaPlaceholder,"aria-label":h.toolbar.formulaPlaceholder,disabled:!p,onChange:e=>X(e.target.value),onKeyDown:e=>{e.key==="Enter"?(Re(e.shiftKey?"up":"down"),L(),e.preventDefault()):e.key==="Escape"&&(X(null),L(),e.preventDefault());},onBlur:()=>Re(),style:{flex:1,minWidth:0}}),Xe&&jsxRuntime.jsxs("div",{style:{position:"relative"},children:[jsxRuntime.jsxs("button",{"data-testid":"xlsx-proposals-button",onClick:()=>Se(e=>!e),disabled:!p,"aria-expanded":Ee,"aria-label":h.proposals.panelLabel,style:{padding:"4px 12px",cursor:p?"pointer":"default"},children:[h.proposals.toolbarButton,V.length>0&&jsxRuntime.jsx("span",{"data-testid":"xlsx-proposals-count",style:{marginLeft:6,padding:"0 6px",borderRadius:8,background:U,color:"#ffffff",fontSize:12},children:V.length})]}),Ee&&jsxRuntime.jsx(Ie,{proposals:V,staleFor:$e,onAccept:ze,onReject:Ne})]})]}),jsxRuntime.jsxs("div",{ref:i,"data-testid":"xlsx-scroll",tabIndex:0,onKeyDown:Ue,onMouseDown:_e,onMouseMove:Ge,onDoubleClick:Ye,style:{position:"relative",flex:1,overflow:"auto",minHeight:0,outline:"none"},children:[jsxRuntime.jsx("div",{style:{position:"absolute",top:0,left:0,width:Ve??"100%",height:qe??"100%"}}),jsxRuntime.jsxs("div",{style:{position:"sticky",top:0,left:0,width:0,height:0},children:[jsxRuntime.jsx("canvas",{ref:k,style:{display:"block",position:"absolute",top:0,left:0}}),jsxRuntime.jsxs("div",{"data-testid":"xlsx-overlay-host",style:{position:"absolute",top:0,left:0,width:0,height:0,pointerEvents:"none"},children:[F&&jsxRuntime.jsx("div",{"data-testid":"xlsx-selection",style:{position:"absolute",left:F.x,top:F.y,width:F.w,height:F.h,boxSizing:"border-box",border:`1px solid ${U}`,background:"rgba(33, 115, 70, 0.12)"}}),z&&!E&&jsxRuntime.jsx("div",{style:{position:"absolute",left:z.x,top:z.y,width:z.w,height:z.h,boxSizing:"border-box",border:`2px solid ${U}`}}),T&&V.flatMap(e=>e.cells.map(t=>{if(t.sheet!==x)return null;let o=xlsx.cellRect(T,t.row,t.col);return o?jsxRuntime.jsx(De,{rect:o,color:re(e.agentId),newText:t.newText,agentId:e.agentId},`${e.id}:${t.a1}`):null})),E&&N&&jsxRuntime.jsx("input",{ref:me,"data-testid":"xlsx-cell-editor",value:E.value,onChange:e=>O(t=>t&&{...t,value:e.target.value}),onKeyDown:e=>{e.stopPropagation(),e.key==="Enter"?(fe(e.shiftKey?"up":"down"),e.preventDefault()):e.key==="Tab"?(fe(e.shiftKey?"left":"right"),e.preventDefault()):e.key==="Escape"&&(Fe(),e.preventDefault());},onBlur:()=>{if(_.current){_.current=false;return}fe();},style:{position:"absolute",left:N.x,top:N.y,width:N.w,height:N.h,boxSizing:"border-box",border:`2px solid ${U}`,padding:"0 3px",font:"13px system-ui, sans-serif",background:"#ffffff",pointerEvents:"auto",outline:"none"}})]})]})]}),Q&&jsxRuntime.jsxs("div",{style:vt,role:"grid","aria-label":Q.label,children:[jsxRuntime.jsxs("div",{role:"row",children:[jsxRuntime.jsx("span",{role:"columnheader"}),Q.columnHeaders.map(e=>jsxRuntime.jsx("span",{role:"columnheader",children:e.label},e.col))]}),Q.rows.map(e=>jsxRuntime.jsxs("div",{role:"row",children:[jsxRuntime.jsx("span",{role:"rowheader",children:e.header}),e.cells.map(t=>jsxRuntime.jsx("span",{role:"gridcell","aria-selected":t.selected,children:t.label},t.col))]},e.row))]}),de&&jsxRuntime.jsxs("div",{"data-testid":"xlsx-error",role:"alert",style:{position:"absolute",inset:0,display:"grid",placeItems:"center",padding:16,textAlign:"center",color:"#b00020"},children:[h.editor.openError,": ",de]}),p&&p.sheetNames.length>0&&jsxRuntime.jsx("div",{"data-testid":"xlsx-sheet-tabs",role:"tablist","aria-label":h.editor.sheetTabsLabel,style:{display:"flex",gap:2,padding:"4px 6px",borderTop:"1px solid #e0e0e0",background:"#fafafa",overflowX:"auto"},children:p.sheetNames.map((e,t)=>{let o=t===p.activeSheet;return jsxRuntime.jsx("button",{role:"tab","aria-selected":o,onClick:()=>Qe(t),style:{border:"none",padding:"4px 12px",cursor:"pointer",borderBottom:o?`2px solid ${U}`:"2px solid transparent",fontWeight:o?600:400,background:o?"#ffffff":"transparent"},children:e},t)})})]})}exports.XlsxEditor=wt;
package/dist/index.d.cts DELETED
@@ -1,36 +0,0 @@
1
- import * as react from 'react';
2
- import { WorkbookHandle } from '@betteroffice/xlsx';
3
-
4
- /**
5
- * The imperative surface handed to {@link XlsxEditorProps.onReady}: the open
6
- * workbook handle plus a `refreshProposals` to re-read the pending list after an
7
- * external caller (e.g. a demo agent) stages proposals on the same handle.
8
- */
9
- interface XlsxEditorApi {
10
- handle: WorkbookHandle;
11
- refreshProposals: () => void;
12
- }
13
- /**
14
- * Props for {@link XlsxEditor}.
15
- */
16
- interface XlsxEditorProps {
17
- /** Raw .xlsx bytes to open. When omitted the shell paints a demo frame. */
18
- file?: Uint8Array;
19
- /** Download name for the save button; falls back to `workbook.xlsx`. */
20
- fileName?: string;
21
- /** Receive saved bytes instead of triggering a browser download. */
22
- onSave?: (bytes: Uint8Array) => void;
23
- /**
24
- * Called when a workbook opens, with a handle to stage agent proposals and a
25
- * way to refresh the panel afterward. Enables demo/host agents without
26
- * exposing the wasm object through the render tree.
27
- */
28
- onReady?: (api: XlsxEditorApi) => void;
29
- className?: string;
30
- }
31
- /**
32
- * The xlsx editor React component.
33
- */
34
- declare function XlsxEditor({ file, fileName, onSave, onReady, className }: XlsxEditorProps): react.JSX.Element;
35
-
36
- export { XlsxEditor, type XlsxEditorApi, type XlsxEditorProps };