@betteroffice/xlsx-react 0.0.7 → 0.0.8

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/README.md CHANGED
@@ -2,9 +2,16 @@
2
2
 
3
3
  React chrome for the BetterOffice XLSX editor — wraps
4
4
  [`@betteroffice/xlsx`](https://www.npmjs.com/package/@betteroffice/xlsx) in a
5
- drop-in `<XlsxEditor>` component with selection, keyboard, and clipboard wired up.
5
+ drop-in `<XlsxEditor>` component with the toolbar, selection, keyboard, and
6
+ clipboard wired up. Formula calculation and rendering run in the core's
7
+ Rust/WebAssembly engine; the grid is painted onto canvas.
6
8
 
7
- > **Experimental (`0.0.x`).** The API is unstable and may change in any release.
9
+ <!-- TODO(author): add a screenshot/GIF here once hosted; an <img> with an unresolvable src renders broken on npm -->
10
+
11
+ > **Early (`0.0.x`).** The core surfaces — opening/saving documents, the editor
12
+ > components, collaboration — are settling and unlikely to change shape. Smaller
13
+ > APIs may still move between releases; breaking changes are always listed in
14
+ > the changelog.
8
15
 
9
16
  ```bash
10
17
  bun add @betteroffice/xlsx-react @betteroffice/xlsx react react-dom
@@ -12,7 +19,17 @@ bun add @betteroffice/xlsx-react @betteroffice/xlsx react react-dom
12
19
 
13
20
  `react` and `react-dom` (18 or 19) are peer dependencies.
14
21
 
15
- ## Usage
22
+ ## Render a workbook
23
+
24
+ ```tsx
25
+ import { XlsxEditor } from "@betteroffice/xlsx-react";
26
+
27
+ <XlsxEditor file={bytes} fileName="report.xlsx" />;
28
+ ```
29
+
30
+ `file` is a `Uint8Array` of `.xlsx` bytes; omit it to render an empty frame.
31
+
32
+ ## Open and save
16
33
 
17
34
  ```tsx
18
35
  import { useState } from "react";
@@ -34,39 +51,72 @@ export function App() {
34
51
  <XlsxEditor
35
52
  file={file}
36
53
  fileName="workbook.xlsx"
37
- onSave={(bytes) => {
38
- // edited .xlsx bytes; without onSave the save button downloads them
39
- console.log(`saved ${bytes.length} bytes`);
40
- }}
54
+ onSave={(bytes) => console.log(`saved ${bytes.length} bytes`)}
41
55
  />
42
56
  </>
43
57
  );
44
58
  }
45
59
  ```
46
60
 
47
- Props: `file` (a `Uint8Array` of `.xlsx` bytes — omit it to render an empty
48
- frame), `fileName`, `onSave`, `onReady` (a handle for host/agent-driven edits),
49
- `collaboration` (opens a network-ready replica and repaints peer updates), and
50
- `className`.
61
+ Without `onSave`, the save button downloads the edited bytes.
62
+
63
+ Props: `file`, `fileName`, `onSave`, `onReady` (a handle for host/agent-driven
64
+ edits), `collaboration`, `i18n`, and `className`.
65
+
66
+ ## What works today
67
+
68
+ - Cell editing with formula recalculation of dependents on every edit
69
+ - Editing toolbar: number formats, fonts, colors, borders, alignment, merges
70
+ - Agent proposals: in-cell tracked-change ghosts plus an accept/reject panel
71
+ - TSV clipboard copy/paste
72
+ - Accessible grid mirroring the painted canvas for screen readers
73
+ - Localized UI via the `i18n` prop
74
+ ([`@betteroffice/xlsx-i18n`](https://www.npmjs.com/package/@betteroffice/xlsx-i18n))
75
+ - Real-time collaboration with people or agents; the workbook is a CRDT
76
+ - Live collaborator selections and presence chips, shown in each peer's color
77
+
78
+ ## AI agents
79
+
80
+ `onReady` hands you the open `WorkbookHandle`. An agent stages edits with
81
+ `propose()` instead of applying them; the editor paints per-cell ghosts and a
82
+ review panel where the human accepts or rejects. The full proposal API lives in
83
+ [`@betteroffice/xlsx`](https://www.npmjs.com/package/@betteroffice/xlsx).
84
+
85
+ ```tsx
86
+ import { isProposalsAvailable } from "@betteroffice/xlsx";
87
+ import type { XlsxEditorApi } from "@betteroffice/xlsx-react";
88
+
89
+ <XlsxEditor
90
+ file={file}
91
+ onReady={({ handle, refreshProposals }: XlsxEditorApi) => {
92
+ if (!isProposalsAvailable()) return;
93
+ handle.propose("copilot", "add totals", [
94
+ { sheet: 0, row: 9, col: 2, input: "=SUM(C1:C9)" },
95
+ ]);
96
+ refreshProposals();
97
+ }}
98
+ />;
99
+ ```
100
+
101
+ ## Collaboration
51
102
 
52
- Attach a transport provider from `onReady`:
103
+ Pass `collaboration` to open a network-ready replica, then attach a transport
104
+ provider from `onReady`:
53
105
 
54
106
  ```tsx
55
107
  import { CollaborationProvider } from "@betteroffice/xlsx/collaboration";
56
108
 
57
- export function CollaborativeWorkbook() {
58
- return (
59
- <XlsxEditor
60
- file={file}
61
- collaboration={{ clientId }}
62
- onReady={({ handle }) => {
63
- const provider = new CollaborationProvider(handle, transport);
64
- provider.connect();
65
- return () => provider.destroy();
66
- }}
67
- />
68
- );
69
- }
109
+ <XlsxEditor
110
+ file={file}
111
+ collaboration={{ clientId }}
112
+ onReady={({ handle }) => {
113
+ const provider = new CollaborationProvider(handle, transport, {
114
+ user: { name: "Ada" }, // shown on this peer's selection flag
115
+ });
116
+ provider.connect();
117
+ return () => provider.destroy();
118
+ }}
119
+ />;
70
120
  ```
71
121
 
72
122
  Docs: https://betteroffice.dev · Apache-2.0.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { CSSProperties, ReactNode } from 'react';
3
3
  import { WorkbookHandle } from '@betteroffice/xlsx';
4
- import { CollaborationReplica } from '@betteroffice/xlsx/collaboration';
4
+ import { CollaborationReplica, CollaborationAwareness } from '@betteroffice/xlsx/collaboration';
5
5
  import { Translations, TFunction } from '@betteroffice/xlsx-i18n';
6
6
 
7
7
  /**
@@ -20,6 +20,8 @@ interface XlsxEditorCollaborationOptions {
20
20
  initialUpdate?: Uint8Array;
21
21
  /** Receive the editor-owned collaboration replica. */
22
22
  onReplica?: (replica: CollaborationReplica | null) => void;
23
+ /** Presence-capable provider connected to the editor-owned replica. */
24
+ provider?: CollaborationAwareness | null;
23
25
  }
24
26
  /**
25
27
  * Props for {@link XlsxEditor}.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import {createContext,useMemo,useContext,useState,useRef,useCallback,useEffect}from'react';import {isPngExportAvailable,isProposalsAvailable,initWasm,openWorkbook,selectionAt,paintDisplayList,normalizeRange,buildA11yGrid,cellAtPoint,moveFocus,toTsv,fromTsv,StaleProposalError,selectionKeyReducer,extendTo,rangeRect,cellRect}from'@betteroffice/xlsx';import {en,deepMerge,createT}from'@betteroffice/xlsx-i18n';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Ut=createContext(en),Gt=createContext("en");function rt({i18n:t,children:r}){let i=typeof t?._lang=="string"?t._lang:"en",c=useMemo(()=>deepMerge(en,t),[t]);return jsx(Gt.Provider,{value:i,children:jsx(Ut.Provider,{value:c,children:r})})}function ye(){let t=useContext(Ut),r=useContext(Gt);return {t:useMemo(()=>createT(t,r),[t,r])}}var De=createContext(null);function Io(){let t=useContext(De);if(!t)throw new Error("useEditorToolbar must be used within an <EditorToolbar> component");return t}function k({name:t,size:r=20,style:i}){return jsxs("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",style:{display:"inline-flex",flexShrink:0,...i},children:[t==="search"&&jsxs(Fragment,{children:[jsx("circle",{cx:"10.5",cy:"10.5",r:"6"}),jsx("path",{d:"m15 15 4.5 4.5"})]}),t==="undo"&&jsx("path",{d:"m9 7-5 5 5 5M5 12h9a6 6 0 0 1 6 6"}),t==="redo"&&jsx("path",{d:"m15 7 5 5-5 5m4-5h-9a6 6 0 0 0-6 6"}),t==="print"&&jsxs(Fragment,{children:[jsx("path",{d:"M7 9V4h10v5M7 18H5a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"}),jsx("path",{d:"M7 14h10v6H7z"}),jsx("path",{d:"M17.5 12h.01"})]}),t==="formatPaint"&&jsxs(Fragment,{children:[jsx("path",{d:"M5 4h11v5H5zM8 9v3h5V9"}),jsx("path",{d:"M10.5 12v8"})]}),t==="decimalDecrease"&&jsxs(Fragment,{children:[jsx("path",{d:"M5 7h1M9 7h1M14 7h1M18 7h1"}),jsx("path",{d:"M5 16h1M9 16h1"}),jsx("path",{d:"m15 12-4 4 4 4M11 16h8"})]}),t==="decimalIncrease"&&jsxs(Fragment,{children:[jsx("path",{d:"M5 7h1M9 7h1"}),jsx("path",{d:"M5 16h1M9 16h1M14 16h1M18 16h1"}),jsx("path",{d:"m15 3 4 4-4 4M19 7h-8"})]}),t==="bold"&&jsx("path",{d:"M7 4h6a4 4 0 0 1 0 8H7zm0 8h7a4 4 0 0 1 0 8H7z"}),t==="italic"&&jsx("path",{d:"M10 4h8M6 20h8M14 4 10 20"}),t==="strikethrough"&&jsx(Fragment,{children:jsx("path",{d:"M5 12h14M8 7.5A4.5 4.5 0 0 1 12.5 4c2.2 0 3.7 1 4.5 2.5M8 16.5c.8 2.1 2.4 3.5 5 3.5 2.8 0 4.5-1.4 4.5-3.5 0-2.3-2-3.3-5.5-4.5"})}),t==="textColor"&&jsxs(Fragment,{children:[jsx("path",{d:"m7 16 5-12 5 12M9 11h6"}),jsx("path",{d:"M5 20h14",strokeWidth:"3"})]}),t==="fillColor"&&jsxs(Fragment,{children:[jsx("path",{d:"m7 4 10 10-6 6-7-7zM5 12h12"}),jsx("path",{d:"M18 17c0-1 1-2 1-2s1 1 1 2a1 1 0 0 1-2 0Z"})]}),t==="borders"&&jsx(Fragment,{children:jsx("path",{d:"M4 4h16v16H4zM12 4v16M4 12h16"})}),t==="merge"&&jsxs(Fragment,{children:[jsx("path",{d:"M4 5h16v14H4z"}),jsx("path",{d:"m8 9 3 3-3 3M16 9l-3 3 3 3"})]}),t==="alignLeft"&&jsx("path",{d:"M4 6h16M4 10h11M4 14h16M4 18h11"}),t==="verticalAlignCenter"&&jsxs(Fragment,{children:[jsx("path",{d:"M4 4h16M4 20h16M8 12h8"}),jsx("path",{d:"m10 9 2 3 2-3M10 15l2-3 2 3"})]}),t==="wrap"&&jsxs(Fragment,{children:[jsx("path",{d:"M4 6h16M4 11h12a3 3 0 0 1 0 6h-3"}),jsx("path",{d:"m15 14-3 3 3 3M4 17h5"})]}),t==="more"&&jsxs(Fragment,{children:[jsx("circle",{cx:"5",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),jsx("circle",{cx:"12",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),jsx("circle",{cx:"19",cy:"12",r:"1",fill:"currentColor",stroke:"none"})]}),t==="chevronDown"&&jsx("path",{d:"m7 10 5 5 5-5"}),t==="remove"&&jsx("path",{d:"M5 12h14"}),t==="add"&&jsx("path",{d:"M12 5v14M5 12h14"}),t==="check"&&jsx("path",{d:"m5 12 4 4L19 6"}),t==="save"&&jsx("path",{d:"M12 3v11m0 0 4-4m-4 4-4-4M5 19h14"}),t==="image"&&jsxs(Fragment,{children:[jsx("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),jsx("circle",{cx:"8.5",cy:"9.5",r:"1.25"}),jsx("path",{d:"m6 17 4.5-4.5 3.25 3.25L16 13.5l2 2"})]}),t==="proposals"&&jsxs(Fragment,{children:[jsx("path",{d:"m12 3 1.25 3.75L17 8l-3.75 1.25L12 13l-1.25-3.75L7 8l3.75-1.25L12 3Z"}),jsx("path",{d:"m18 14 .75 2.25L21 17l-2.25.75L18 20l-.75-2.25L15 17l2.25-.75L18 14Z"})]})]})}var T={text:"#3c4043",muted:"#5f6368",disabled:"#9aa0a6",hover:"#e2e7ef",active:"#d3e3fd",border:"#c7cacf",surface:"#ffffff",rail:"#edf2fa"},Ho={appearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",gap:2,minWidth:28,height:28,padding:"0 5px",border:0,borderRadius:4,color:T.text,font:"500 13px ui-sans-serif, system-ui, sans-serif",lineHeight:1,whiteSpace:"nowrap",boxSizing:"border-box"};function _t(t,r,i,c){return {...Ho,background:r?T.active:i&&!t?T.hover:"transparent",color:t?T.disabled:T.text,cursor:t?"default":"pointer",opacity:t?.48:1,...c}}function H({active:t=false,disabled:r=false,title:i,onClick:c,children:h,style:g,testId:s,ariaExpanded:F}){let[R,z]=useState(false);return jsx("button",{type:"button","data-testid":s,disabled:r,"aria-label":i,"aria-pressed":t||void 0,"aria-expanded":F,title:i,onMouseDown:O=>O.preventDefault(),onMouseEnter:()=>z(true),onMouseLeave:()=>z(false),onClick:r?void 0:c,style:_t(r,t,R,g),children:h})}function K({label:t,children:r,style:i}){return jsx("div",{role:"group","aria-label":t,style:{display:"inline-flex",alignItems:"center",gap:1,flex:"0 0 auto",...i},children:r})}function $e(){return jsx("div",{role:"separator",style:{width:1,height:24,margin:"0 5px",background:T.border,flex:"0 0 auto"}})}function ce({title:t,trigger:r,children:i,disabled:c=false,active:h=false,menuWidth:g=220,style:s,testId:F}){let[R,z]=useState(false),[O,q]=useState(false),[U,ae]=useState({top:0,left:0}),x=useRef(null),_=useRef(null),I=useCallback(()=>z(false),[]);return useEffect(()=>{if(!R||!x.current)return;let B=x.current.getBoundingClientRect(),J=Math.min(B.left,Math.max(8,window.innerWidth-g-8));ae({top:B.bottom+4,left:J});},[R,g]),useEffect(()=>{if(!R)return;let B=Y=>{let S=Y.target;!x.current?.contains(S)&&!_.current?.contains(S)&&I();},J=Y=>{Y.key==="Escape"&&I();},v=()=>I();return document.addEventListener("mousedown",B),document.addEventListener("keydown",J),window.addEventListener("scroll",v,true),()=>{document.removeEventListener("mousedown",B),document.removeEventListener("keydown",J),window.removeEventListener("scroll",v,true);}},[R,I]),jsxs("div",{style:{position:"relative",display:"inline-flex",flex:"0 0 auto"},children:[jsx("button",{ref:x,type:"button","data-testid":F,disabled:c,"aria-label":t,"aria-haspopup":"menu","aria-expanded":R,title:t,onMouseDown:B=>B.preventDefault(),onMouseEnter:()=>q(true),onMouseLeave:()=>q(false),onClick:()=>!c&&z(B=>!B),style:_t(c,h||R,O,s),children:r}),R&&jsx("div",{ref:_,role:"menu","aria-label":t,onMouseDown:B=>B.preventDefault(),style:{position:"fixed",top:U.top,left:U.left,zIndex:1e4,width:g,maxHeight:"min(440px, calc(100vh - 16px))",overflowY:"auto",padding:6,border:`1px solid ${T.border}`,borderRadius:8,background:T.surface,boxShadow:"0 4px 16px rgba(60, 64, 67, 0.24)",boxSizing:"border-box"},children:i(I)})]})}function te({label:t,icon:r,selected:i=false,disabled:c=false,onClick:h,close:g}){let[s,F]=useState(false);return jsxs("button",{type:"button",role:"menuitem",disabled:c,"aria-label":t,onMouseEnter:()=>F(true),onMouseLeave:()=>F(false),onClick:()=>{c||(h?.(),g?.());},style:{appearance:"none",display:"flex",alignItems:"center",gap:10,width:"100%",minHeight:32,padding:"5px 9px",border:0,borderRadius:4,background:s&&!c?T.hover:"transparent",color:c?T.disabled:T.text,cursor:c?"default":"pointer",opacity:c?.48:1,font:"400 13px ui-sans-serif, system-ui, sans-serif",textAlign:"left",boxSizing:"border-box"},children:[jsx("span",{style:{display:"inline-grid",placeItems:"center",width:20,flex:"0 0 auto"},children:r}),jsx("span",{style:{flex:1},children:t}),i&&jsx("span",{"aria-hidden":"true",children:"\u2713"})]})}function Oe(){return jsx("div",{role:"separator",style:{height:1,margin:"5px 2px",background:T.border}})}function xt({mode:t,value:r,label:i,onChange:c,disabled:h=false}){let[g,s]=useState(false);return jsxs("label",{title:i,"aria-label":i,style:{position:"relative",display:"inline-grid",placeItems:"center",width:28,height:28,borderRadius:4,background:g&&!h?T.hover:"transparent",color:h?T.disabled:T.text,cursor:h?"default":"pointer",opacity:h?.48:1,boxSizing:"border-box"},onMouseEnter:()=>s(true),onMouseLeave:()=>s(false),children:[jsx(k,{name:t==="text"?"textColor":"fillColor",size:20}),jsx("span",{"aria-hidden":"true",style:{position:"absolute",left:5,right:5,bottom:2,height:3,borderRadius:2,background:r}}),jsx("input",{type:"color",value:r,disabled:h,"aria-label":i,onChange:F=>c?.(F.target.value),style:{position:"absolute",inset:0,width:"100%",height:"100%",opacity:0}})]})}function Ct({value:t,options:r,label:i,onCommit:c,disabled:h=false,width:g=72,inputStyle:s,testId:F}){let[R,z]=useState(t),[O,q]=useState(false),[U,ae]=useState({top:0,left:0,width:g}),x=useRef(null),_=useRef(null),I=useRef(null);useEffect(()=>z(t),[t]);let B=useCallback(()=>q(false),[]);useEffect(()=>{if(!O||!x.current)return;let v=x.current.getBoundingClientRect();ae({top:v.bottom+4,left:v.left,width:Math.max(v.width,g)});},[O,g]),useEffect(()=>{if(!O)return;let v=S=>{let Q=S.target;!x.current?.contains(Q)&&!_.current?.contains(Q)&&B();},Y=S=>{S.key==="Escape"&&(z(t),B());};return document.addEventListener("mousedown",v),document.addEventListener("keydown",Y),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",Y);}},[O,B,t]);let J=useCallback(()=>{!h&&c&&R.trim()?c(R.trim()):z(t);},[h,c,R,t]);return jsxs("div",{ref:x,style:{display:"inline-flex",alignItems:"center",width:g,height:28,border:`1px solid ${T.border}`,borderRadius:4,background:h?"rgba(255,255,255,0.5)":T.surface,opacity:h?.48:1,boxSizing:"border-box",flex:"0 0 auto"},children:[jsx("input",{ref:I,"data-testid":F,role:"combobox","aria-label":i,"aria-autocomplete":"list","aria-expanded":O,disabled:h,value:R,onFocus:v=>{h||(q(true),v.currentTarget.select());},onChange:v=>z(v.target.value),onKeyDown:v=>{v.key==="Enter"?(J(),B(),v.currentTarget.blur()):v.key==="ArrowDown"&&(q(true),v.preventDefault());},onBlur:()=>{requestAnimationFrame(()=>{_.current?.contains(document.activeElement)||J();});},style:{appearance:"none",width:"calc(100% - 22px)",height:26,padding:"0 2px 0 7px",border:0,outline:0,background:"transparent",color:T.text,font:"500 13px ui-sans-serif, system-ui, sans-serif",boxSizing:"border-box",...s}}),jsx("button",{type:"button",disabled:h,tabIndex:-1,"aria-label":i,title:i,onMouseDown:v=>v.preventDefault(),onClick:()=>{h||(q(v=>!v),I.current?.focus());},style:{appearance:"none",display:"grid",placeItems:"center",width:21,height:26,padding:0,border:0,background:"transparent",color:T.muted,cursor:h?"default":"pointer"},children:jsx(k,{name:"chevronDown",size:14})}),O&&!h&&jsx("div",{ref:_,role:"listbox","aria-label":i,style:{position:"fixed",top:U.top,left:U.left,zIndex:1e4,width:U.width,maxHeight:260,overflowY:"auto",padding:4,border:`1px solid ${T.border}`,borderRadius:6,background:T.surface,boxShadow:"0 4px 16px rgba(60, 64, 67, 0.24)",boxSizing:"border-box"},children:r.map(v=>jsx("button",{type:"button",role:"option","aria-selected":v.value===t,onMouseDown:Y=>Y.preventDefault(),onClick:()=>{z(v.label),c?.(v.value),B();},style:{appearance:"none",display:"block",width:"100%",minHeight:28,padding:"4px 7px",border:0,borderRadius:3,background:v.value===t?T.active:"transparent",color:T.text,cursor:"pointer",font:"400 13px ui-sans-serif, system-ui, sans-serif",textAlign:"left"},children:v.label},v.value))})]})}var Xo=[.5,.75,.9,1,1.25,1.5,2],_o=["Arial","Calibri","Cambria","Georgia","Roboto","Times New Roman","Verdana"],Vo=[8,9,10,11,12,14,16,18,20,24,28,36,48,72],Zo=["automatic","plainText","number","percent","scientific","currency","date","time","custom"],Yo=["all","inner","horizontal","vertical","outer","left","top","right","bottom","none"],jo=["solid","dashed","dotted","double"],qo=["left","center","right"],Jo=["top","middle","bottom"],Qo=["overflow","wrap","clip"];function er(t){let r={};for(let i of Object.keys(t))t[i]!==void 0&&(r[i]=t[i]);return r}function tr(t){let r=useContext(De);return r?{...r,...er(t)}:t}function jt({preset:t}){let r=i=>t===i||t==="all"||t==="outer"?2:.6;return jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","aria-hidden":"true",children:[t!=="none"&&jsxs(Fragment,{children:[jsx("path",{d:"M3 3h14",strokeWidth:r("top")}),jsx("path",{d:"M17 3v14",strokeWidth:r("right")}),jsx("path",{d:"M3 17h14",strokeWidth:r("bottom")}),jsx("path",{d:"M3 3v14",strokeWidth:r("left")}),(t==="all"||t==="inner"||t==="horizontal")&&jsx("path",{d:"M3 10h14",strokeWidth:"1.5"}),(t==="all"||t==="inner"||t==="vertical")&&jsx("path",{d:"M10 3v14",strokeWidth:"1.5"})]}),t==="none"&&jsx("path",{d:"M4 4h12v12H4zM3 17 17 3",strokeWidth:"1.5"})]})}function qt({value:t}){let r=t==="left"?3:t==="center"?5:7,i=t==="left"?15:t==="center"?17:19;return jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6","aria-hidden":"true",children:[jsx("path",{d:"M3 4h14M3 10h14M3 16h14"}),jsx("path",{d:`M${r} 7h${i-r}M${r} 13h${i-r}`})]})}function Jt({value:t}){return jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6","aria-hidden":"true",children:[jsx("path",{d:"M3 3h14M3 17h14"}),jsx("path",{d:`M6 ${t==="top"?5:t==="middle"?10:15}h8`}),jsx("path",{d:t==="top"?"m8 8 2-3 2 3":t==="bottom"?"m8 12 2 3 2-3":"m8 7 2 3 2-3m-4 6 2-3 2 3"})]})}function or({value:t}){return jsx("svg",{width:"44",height:"12",viewBox:"0 0 44 12",fill:"none",stroke:"currentColor","aria-hidden":"true",children:t==="double"?jsx(Fragment,{children:jsx("path",{d:"M2 4h40M2 8h40"})}):jsx("path",{d:"M2 6h40",strokeWidth:"2",strokeDasharray:t==="dashed"?"7 4":t==="dotted"?"1 4":void 0})})}function Qt(t,r,i){return i>0?r.find(c=>c>t)??t+1:[...r].reverse().find(c=>c<t)??Math.max(1,t-1)}function nt(t){let{t:r}=ye(),{currentFormatting:i={},selectionShape:c,onFormat:h,onMerge:g,onSearchMenus:s,onUndo:F,onRedo:R,canUndo:z=false,canRedo:O=false,onPrint:q,zoom:U=1,onZoomChange:ae,fontFamilies:x=_o,fontSizes:_=Vo,disabled:I=false,className:B,style:J,children:v}=tr(t),Y=useRef(null),[S,Q]=useState(Number.POSITIVE_INFINITY),w=!I&&!!h,E=!I&&!!g,me=i.fontSize??10,Ke=(c?.rows??1)>1,f=(c?.columns??1)>1,G=Ke||f;useEffect(()=>{let b=Y.current;if(!b)return;let d=()=>Q(b.clientWidth);d();let we=new ResizeObserver(d);return we.observe(b),()=>we.disconnect()},[]);let V=useMemo(()=>Xo.map(b=>({value:`${b*100}%`,label:`${b*100}%`})),[]),he=useMemo(()=>_.map(b=>({value:String(b),label:String(b)})),[_]),D=b=>{w&&h?.(b);},Ae=b=>jsx(Fragment,{children:Zo.map(d=>jsx(te,{label:r(`toolbar.numberFormats.${d}`),selected:i.numberFormat===d,disabled:!w,onClick:()=>D({type:"numberFormat",value:d}),close:b},d))}),Ce=b=>jsxs(Fragment,{children:[Yo.map(d=>jsx(te,{icon:jsx(jt,{preset:d}),label:r(`toolbar.borderPresets.${d}`),selected:i.borderPreset===d,disabled:!w,onClick:()=>D({type:"borderPreset",value:d}),close:b},d)),jsx(Oe,{}),jo.map(d=>jsx(te,{icon:jsx(or,{value:d}),label:r(`toolbar.borderStyles.${d}`),selected:i.borderStyle===d,disabled:!w,onClick:()=>D({type:"borderStyle",value:d}),close:b},d)),jsx(Oe,{}),jsxs("label",{style:{position:"relative",display:"flex",alignItems:"center",gap:10,minHeight:32,padding:"5px 9px",color:T.text,font:"400 13px ui-sans-serif, system-ui, sans-serif",cursor:w?"pointer":"default"},children:[jsx("span",{style:{width:20,height:5,borderRadius:2,background:i.borderColor??"#000000"}}),jsx("span",{children:r("toolbar.borderColor")}),jsx("input",{type:"color",value:i.borderColor??"#000000",disabled:!w,"aria-label":r("toolbar.borderColor"),onChange:d=>D({type:"borderColor",value:d.target.value}),style:{position:"absolute",inset:0,width:"100%",height:"100%",opacity:0}})]})]}),Se=b=>jsxs(Fragment,{children:[jsx(te,{label:r("toolbar.merge.all"),disabled:!E||!G,onClick:()=>g?.("all"),close:b}),jsx(te,{label:r("toolbar.merge.horizontal"),disabled:!E||!f,onClick:()=>g?.("horizontal"),close:b}),jsx(te,{label:r("toolbar.merge.vertical"),disabled:!E||!Ke,onClick:()=>g?.("vertical"),close:b}),jsx(Oe,{}),jsx(te,{label:r("toolbar.merge.unmerge"),disabled:!E||!c?.canUnmerge,onClick:()=>g?.("unmerge"),close:b})]}),Xe=b=>jsx(Fragment,{children:qo.map(d=>jsx(te,{icon:jsx(qt,{value:d}),label:r(`toolbar.horizontalAlign.${d}`),selected:i.horizontalAlignment===d,disabled:!w,onClick:()=>D({type:"horizontalAlignment",value:d}),close:b},d))}),st=b=>jsx(Fragment,{children:Jo.map(d=>jsx(te,{icon:jsx(Jt,{value:d}),label:r(`toolbar.verticalAlign.${d}`),selected:i.verticalAlignment===d,disabled:!w,onClick:()=>D({type:"verticalAlignment",value:d}),close:b},d))}),L=b=>jsx(Fragment,{children:Qo.map(d=>jsx(te,{label:r(`toolbar.wrapping.${d}`),selected:i.textWrapping===d,disabled:!w,onClick:()=>D({type:"textWrapping",value:d}),close:b},d))}),ge=[{key:"search",width:29,node:jsx(K,{label:r("toolbar.groups.search"),children:jsx(H,{title:r("toolbar.searchMenus"),onClick:s,testId:"xlsx-search-menus",children:jsx(k,{name:"search"})})})},{key:"history",width:58,node:jsxs(K,{label:r("toolbar.groups.history"),children:[jsx(H,{title:r("toolbar.undo"),disabled:I||!z||!F,onClick:F,testId:"xlsx-undo",children:jsx(k,{name:"undo"})}),jsx(H,{title:r("toolbar.redo"),disabled:I||!O||!R,onClick:R,testId:"xlsx-redo",children:jsx(k,{name:"redo"})})]})},{key:"print",width:29,node:jsx(K,{label:r("toolbar.groups.print"),children:jsx(H,{title:r("toolbar.print"),disabled:I||!q,onClick:q,children:jsx(k,{name:"print"})})})},{key:"paint",width:29,node:jsx(K,{label:r("toolbar.groups.paintFormat"),children:jsx(H,{title:r("toolbar.paintFormat"),active:i.paintFormat,disabled:!w,onClick:()=>D("paintFormat"),children:jsx(k,{name:"formatPaint"})})})},{key:"zoom",width:82,node:jsx(K,{label:r("toolbar.groups.zoom"),children:jsx(Ct,{value:`${Math.round(U*100)}%`,options:V,label:r("toolbar.zoomValue",{value:`${Math.round(U*100)}%`}),disabled:I||!ae,onCommit:b=>{let d=Number.parseFloat(b.replace("%",""));Number.isFinite(d)&&d>=25&&d<=400&&ae?.(d/100);},width:76,testId:"xlsx-zoom"})})},{key:"number",width:202,node:jsxs(Fragment,{children:[jsx($e,{}),jsxs(K,{label:r("toolbar.groups.number"),children:[jsx(H,{title:r("toolbar.currency"),disabled:!w,onClick:()=>D("currency"),children:jsx("span",{style:{fontSize:16},children:r("toolbar.currencySymbol")})}),jsx(H,{title:r("toolbar.percent"),disabled:!w,onClick:()=>D("percent"),children:jsx("span",{style:{fontSize:15},children:"%"})}),jsx(H,{title:r("toolbar.decreaseDecimal"),disabled:!w,onClick:()=>D("decreaseDecimal"),children:jsx(k,{name:"decimalDecrease"})}),jsx(H,{title:r("toolbar.increaseDecimal"),disabled:!w,onClick:()=>D("increaseDecimal"),children:jsx(k,{name:"decimalIncrease"})}),jsx(ce,{title:r("toolbar.moreNumberFormats"),disabled:!w,trigger:jsxs(Fragment,{children:[jsx("span",{children:"123"}),jsx(k,{name:"chevronDown",size:13})]}),children:Ae})]})]})},{key:"font-family",width:137,node:jsxs(Fragment,{children:[jsx($e,{}),jsx(K,{label:r("toolbar.groups.font"),children:jsx(ce,{title:r("toolbar.fontFamily"),disabled:!w,menuWidth:210,style:{width:120,justifyContent:"space-between"},trigger:jsxs(Fragment,{children:[jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:i.fontFamily??"Calibri"}),jsx(k,{name:"chevronDown",size:13})]}),children:b=>jsx(Fragment,{children:x.map(d=>jsx(te,{label:d,selected:i.fontFamily===d,disabled:!w,onClick:()=>D({type:"fontFamily",value:d}),close:b},d))})})})]})},{key:"font-size",width:116,node:jsxs(K,{label:r("toolbar.groups.font"),children:[jsx(H,{title:r("toolbar.decreaseFontSize"),disabled:!w,onClick:()=>D({type:"fontSize",value:Qt(me,_,-1)}),children:jsx(k,{name:"remove"})}),jsx(Ct,{value:String(me),options:he,label:r("toolbar.fontSize"),disabled:!w,onCommit:b=>{let d=Number.parseFloat(b);Number.isFinite(d)&&d>=1&&d<=400&&D({type:"fontSize",value:d});},width:50,inputStyle:{textAlign:"center"}}),jsx(H,{title:r("toolbar.increaseFontSize"),disabled:!w,onClick:()=>D({type:"fontSize",value:Qt(me,_,1)}),children:jsx(k,{name:"add"})})]})},{key:"text",width:98,node:jsxs(Fragment,{children:[jsx($e,{}),jsxs(K,{label:r("toolbar.groups.text"),children:[jsx(H,{title:r("toolbar.bold"),active:i.bold,disabled:!w,onClick:()=>D("bold"),children:jsx(k,{name:"bold"})}),jsx(H,{title:r("toolbar.italic"),active:i.italic,disabled:!w,onClick:()=>D("italic"),children:jsx(k,{name:"italic"})}),jsx(H,{title:r("toolbar.strikethrough"),active:i.strikethrough,disabled:!w,onClick:()=>D("strikethrough"),children:jsx(k,{name:"strikethrough"})})]})]})},{key:"colors",width:58,node:jsxs(K,{label:r("toolbar.groups.colors"),children:[jsx(xt,{mode:"text",value:i.textColor??"#000000",label:r("toolbar.textColor"),disabled:!w,onChange:b=>D({type:"textColor",value:b})}),jsx(xt,{mode:"fill",value:i.fillColor??"#ffffff",label:r("toolbar.fillColor"),disabled:!w,onChange:b=>D({type:"fillColor",value:b})})]})},{key:"borders",width:36,node:jsx(K,{label:r("toolbar.groups.borders"),children:jsx(ce,{title:r("toolbar.borders"),disabled:!w,menuWidth:240,trigger:jsxs(Fragment,{children:[jsx(jt,{preset:i.borderPreset??"all"}),jsx(k,{name:"chevronDown",size:12})]}),children:Ce})})},{key:"merge",width:58,node:jsxs(K,{label:r("toolbar.groups.merge"),children:[jsx(H,{title:r("toolbar.merge.all"),disabled:!E||!G,onClick:()=>g?.("all"),style:{borderRadius:"4px 0 0 4px"},testId:"xlsx-merge-all",children:jsx(k,{name:"merge"})}),jsx(ce,{title:r("toolbar.mergeCells"),disabled:!E||!G&&!c?.canUnmerge,menuWidth:220,style:{minWidth:20,width:20,padding:0,borderRadius:"0 4px 4px 0"},trigger:jsx(k,{name:"chevronDown",size:13}),children:Se})]})},{key:"alignment",width:118,node:jsxs(K,{label:r("toolbar.groups.alignment"),children:[jsx(ce,{title:r("toolbar.horizontalAlignment"),disabled:!w,menuWidth:180,trigger:jsxs(Fragment,{children:[jsx(qt,{value:i.horizontalAlignment??"left"}),jsx(k,{name:"chevronDown",size:12})]}),children:Xe}),jsx(ce,{title:r("toolbar.verticalAlignment"),disabled:!w,menuWidth:180,trigger:jsxs(Fragment,{children:[jsx(Jt,{value:i.verticalAlignment??"middle"}),jsx(k,{name:"chevronDown",size:12})]}),children:st}),jsx(ce,{title:r("toolbar.textWrapping"),disabled:!w,menuWidth:180,trigger:jsxs(Fragment,{children:[jsx(k,{name:"wrap"}),jsx(k,{name:"chevronDown",size:12})]}),children:L})]})}];v&&ge.push({key:"custom",width:40,node:v});let Fe=Math.max(0,S-48),ke=0,Te=ge.length;for(let b=0;b<ge.length;b++)if(ke+=ge[b].width,ke>Fe){Te=b;break}let _e=ge.slice(0,Te),ee=ge.slice(Te);return jsxs("div",{ref:Y,className:B,role:"toolbar","aria-label":r("toolbar.actionsLabel"),"data-testid":"xlsx-formatting-toolbar",style:{display:"flex",alignItems:"center",minWidth:0,minHeight:36,margin:"0 8px 5px",padding:"4px 7px",borderRadius:18,background:T.rail,color:T.text,overflow:"hidden",boxSizing:"border-box",...J},children:[_e.map(b=>jsx("span",{style:{display:"contents"},children:b.node},b.key)),jsx("span",{style:{marginLeft:"auto",flex:"0 0 auto"},children:jsx(ce,{title:r("toolbar.more"),disabled:ee.length===0,menuWidth:390,testId:"xlsx-toolbar-more",trigger:jsx(k,{name:"more"}),children:()=>jsx("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:2},children:ee.map(b=>jsx("span",{style:{display:"contents"},children:b.node},b.key))})})})]})}function rr({children:t,className:r,style:i,...c}){return jsx(De.Provider,{value:c,children:jsx("div",{className:r,"data-testid":"xlsx-editor-toolbar",style:{display:"flex",flexDirection:"column",flex:"0 0 auto",...i},children:t})})}var Ge=rr;Ge.Toolbar=nt;var to=["#7c3aed","#0891b2","#c2410c","#4d7c0f","#be185d","#1d4ed8"];function nr(t){let r=2166136261;for(let i=0;i<t.length;i++)r^=t.charCodeAt(i),r=Math.imul(r,16777619);return (r>>>0)%to.length}function oo(t){return to[nr(t)]}function ro({proposals:t,staleFor:r,onAccept:i,onReject:c,style:h}){let{t:g}=ye();return jsx("div",{"data-testid":"xlsx-proposals-panel",role:"region","aria-label":g("proposals.panelLabel"),style:{position:"absolute",top:"100%",right:0,marginTop:4,width:320,maxHeight:420,overflowY:"auto",background:"#ffffff",border:"1px solid #d0d0d0",borderRadius:10,boxShadow:"0 6px 24px rgba(0, 0, 0, 0.16)",padding:8,zIndex:10,font:"13px system-ui, sans-serif",textAlign:"left",...h},children:t.length===0?jsx("div",{style:{padding:12,color:"#707070",textAlign:"center"},children:g("proposals.empty")}):t.map(s=>{let F=oo(s.agentId),R=r[s.id];return jsxs("div",{"data-testid":"xlsx-proposal","data-proposal-id":s.id,style:{borderLeft:`3px solid ${F}`,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:F},children:s.agentId}),jsx("span",{style:{color:"#707070",fontSize:12},children:g("proposals.cellCount",{count:s.cells.length})})]}),s.note&&jsx("div",{style:{color:"#404040",margin:"4px 0"},children:s.note}),jsx("ul",{style:{listStyle:"none",margin:"6px 0",padding:0},children:s.cells.map(z=>jsxs("li",{"data-testid":"xlsx-proposal-cell",style:{fontVariantNumeric:"tabular-nums",lineHeight:1.5},children:[jsx("strong",{"data-testid":"xlsx-proposal-cell-a1",children:z.a1}),":"," ",jsx("span",{style:{color:"#909090"},children:z.oldText||"\u2205"})," ",g("proposals.changeArrow")," ",jsx("span",{"data-testid":"xlsx-proposal-cell-new",style:{color:F},children:z.newText})]},z.a1))}),R&&R.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:g("proposals.staleWarning",{cells:R.join(", ")})}),jsxs("div",{style:{display:"flex",gap:6,marginTop:4},children:[jsx("button",{"data-testid":"xlsx-proposal-accept",onClick:()=>i(s.id),style:{padding:"3px 10px",cursor:"pointer"},children:g("proposals.accept")}),R&&R.length>0&&jsx("button",{"data-testid":"xlsx-proposal-force",onClick:()=>i(s.id,true),style:{padding:"3px 10px",cursor:"pointer",color:"#b45309"},children:g("proposals.forceApply")}),jsx("button",{"data-testid":"xlsx-proposal-reject",onClick:()=>c(s.id),style:{padding:"3px 10px",cursor:"pointer"},children:g("proposals.reject")})]})]},s.id)})})}var xe=96,ve=24,it="#217346",co=87,gr="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";function yr(t,r,i){let c=[{op:"fillRect",x:0,y:0,w:t,h:r,color:"#ffffff"}],h=Math.ceil(t/xe),g=Math.ceil(r/ve);for(let s=0;s<=h;s++)c.push({op:"line",x1:s*xe,y1:0,x2:s*xe,y2:r,width:1,color:"#e0e0e0"});for(let s=0;s<=g;s++)c.push({op:"line",x1:0,y1:s*ve,x2:t,y2:s*ve,width:1,color:"#e0e0e0"});return c.push({op:"fillRect",x:0,y:0,w:t,h:ve,color:"#f3f3f3"}),c.push({op:"fillRect",x:0,y:0,w:xe,h:r,color:"#f3f3f3"}),c.push({op:"text",x:xe+8,y:ve+18,text:i,fontSize:14,color:"#202020",clip:{x:xe,y:ve,w:xe*3,h:ve},align:"left"}),{width:t,height:r,commands:c}}function io(t,r){if(!t||t.length<2)return r;let i=[];for(let h=1;h<t.length;h++)i.push(t[h]-t[h-1]);i.sort((h,g)=>h-g);let c=i[i.length>>1];return c>0?c:r}function xr(t,r,i){let c=io(t?.grid?.rowOffsets,ve),h=io(t?.grid?.colOffsets,xe),g=Math.max(1,Math.round(r.contentHeight/c))+1,s=Math.max(1,Math.round(r.contentWidth/h))+1,F=Math.max(1,Math.floor(i/c));return {rows:g,cols:s,rowsPerPage:F}}function so(t,r,i){let c=new Blob([new Uint8Array(t)],{type:i}),h=URL.createObjectURL(c),g=document.createElement("a");g.href=h,g.download=r,document.body.appendChild(g),g.click(),g.remove(),URL.revokeObjectURL(h);}function vr(t){return `${(t??"workbook.xlsx").replace(/\.xlsx$/i,"")}.png`}function Tt(t,r){return {x:t.x*r,y:t.y*r,w:t.w*r,h:t.h*r}}var Sr={position:"absolute",width:1,height:1,margin:-1,padding:0,border:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap"},fe={shell:{flex:"0 0 auto",minHeight:co,padding:"4px 0 5px",borderBottom:"1px solid #e2e8f0",background:"#ffffff",color:"#0f172a",boxSizing:"border-box"},rail:{display:"flex",alignItems:"center",minHeight:32,margin:"0 8px",padding:"2px 8px",borderRadius:4,background:"#ffffff",boxSizing:"border-box",overflowX:"auto",overflowY:"hidden"},group:{display:"inline-flex",alignItems:"center",gap:1,padding:"0 6px",borderRight:"1px solid rgba(226, 232, 240, 0.9)",flex:"0 0 auto"},formulaGroup:{display:"flex",alignItems:"center",gap:4,flex:"1 1 320px",minWidth:240,padding:"0 6px",borderRight:"1px solid rgba(226, 232, 240, 0.9)"},nameBox:{appearance:"none",width:64,height:28,flex:"0 0 auto",boxSizing:"border-box",border:"1px solid #e2e8f0",borderRadius:6,background:"#f8fafc",color:"#0f172a",font:"600 12px ui-monospace, SFMono-Regular, Menlo, monospace",textAlign:"center",outlineColor:"#2563eb"},formulaMark:{display:"grid",placeItems:"center",width:20,height:28,flex:"0 0 auto",color:"#64748b",font:"italic 700 12px Georgia, serif",userSelect:"none"},formulaInput:{appearance:"none",flex:"1 1 260px",minWidth:140,height:28,boxSizing:"border-box",border:"1px solid #e2e8f0",borderRadius:6,padding:"0 8px",background:"#ffffff",color:"#0f172a",font:"13px ui-sans-serif, system-ui, sans-serif",outlineColor:"#2563eb"},proposals:{marginLeft:"auto",paddingLeft:6,flex:"0 0 auto"},count:{display:"inline-grid",placeItems:"center",minWidth:15,height:15,marginLeft:-3,padding:"0 4px",borderRadius:8,background:"#0f172a",color:"#ffffff",fontSize:10,fontWeight:700,lineHeight:1,boxSizing:"border-box"}};function wr({i18n:t,...r}){return jsx(rt,{i18n:t,children:jsx(Cr,{...r})})}function Cr({file:t,fileName:r,onSave:i,collaboration:c,onReady:h,className:g}){let{t:s}=ye(),F=c!==void 0,R=c?.clientId,z=c?.initialUpdate,O=c?.onReplica,q=useRef(null),U=useRef(null),ae=useRef(null),x=useRef(null),_=useRef(null),I=useRef(null),B=useRef(null),J=useRef(false),v=useRef(false),Y=useRef(h);Y.current=h;let[S,Q]=useState(null),[w,E]=useState(null),[me,Ke]=useState(null),[f,G]=useState(null),[V,he]=useState(null),[D,Ae]=useState(null),[Ce,Se]=useState(null),[Xe,st]=useState(co),[L,ge]=useState(1),[Fe,ke]=useState(0),[Te,_e]=useState(false),[ee,b]=useState({}),[d,we]=useState({canUndo:false,canRedo:false}),[ct,Ve]=useState([]),[dt,Mt]=useState(),[pt,Et]=useState(),[Me,ze]=useState(null),Ee=useRef(null),[Ze,Ye]=useState([]),[ut,Rt]=useState(false),[bt,Pt]=useState(null),[po,Ie]=useState({}),p=S?.activeSheet??0,uo=useMemo(()=>isPngExportAvailable(),[]),Lt=useMemo(()=>isProposalsAvailable(),[]);useEffect(()=>{let e=q.current;if(!e)return;let o=()=>st(e.offsetHeight);o();let n=new ResizeObserver(o);return n.observe(e),()=>n.disconnect()},[]);let ie=useCallback(()=>{let e=x.current;if(!e){Ye([]);return}try{Ye(e.listProposals());}catch{Ye([]);}ke(o=>o+1);},[]);useEffect(()=>{if(he(null),Se(null),Ye([]),Ie({}),Rt(false),Pt(null),b({}),we({canUndo:false,canRedo:false}),Ve([]),Mt(void 0),Et(void 0),ze(null),Ee.current=null,!t){x.current=null,Q(null),G(null),E(null);return}x.current=null,Q(null),G(null);let e=null,o=()=>{},n=()=>{},a=false,u=()=>{let C=n;n=()=>{};try{C();}catch{}};return initWasm().then(()=>{if(!a)try{e=openWorkbook(t,{collaborative:F,clientId:R}),z&&e.applyUpdate(z.slice()),x.current=e,o=e.onUpdate(()=>{if(!(a||!e))try{Q(e.sheetInfo()),ke(y=>y+1),Ie({}),ie(),E(null);}catch(y){E(y instanceof Error?y.message:String(y));}}),Q(e.sheetInfo()),G(selectionAt({row:0,col:0})),Pt(e),E(null),ie();let C=Y.current?.({handle:e,refreshProposals:ie});typeof C=="function"&&(n=C);}catch(C){u(),o(),o=()=>{},e?.dispose(),e=null,x.current=null,Q(null),G(null),E(C instanceof Error?C.message:String(C));}},C=>{a||(x.current=null,Q(null),G(null),E(C instanceof Error?C.message:String(C)));}),()=>{a=true,u(),o(),e?.dispose(),x.current=null;}},[t,F,R,z,ie]),useEffect(()=>{if(!(!O||!bt))return O(bt),()=>O(null)},[O,bt]);let ft=useCallback(()=>{let e=U.current,o=ae.current;if(!e||!o)return;let n=o.getContext("2d");if(!n)return;let a=window.devicePixelRatio||1,u=e.clientWidth,C=e.clientHeight;if(u===0||C===0)return;o.width=Math.round(u*a),o.height=Math.round(C*a),o.style.width=`${u}px`,o.style.height=`${C}px`;let y=u/L,ne=C/L,Le=x.current,pe;if(Le)try{pe=Le.displayList({x:e.scrollLeft/L,y:e.scrollTop/L,width:y,height:ne});}catch{return}else pe=yr(y,ne,s("editor.demoCellText"));paintDisplayList(n,pe,a*L),_.current=pe,Ke(pe);},[s,L]);useEffect(()=>{let e=U.current;if(!e)return;let o=()=>{I.current==null&&(I.current=requestAnimationFrame(()=>{I.current=null,ft();}));};ft(),e.addEventListener("scroll",o,{passive:true});let n=new ResizeObserver(o);return n.observe(e),()=>{e.removeEventListener("scroll",o),n.disconnect(),I.current!=null&&(cancelAnimationFrame(I.current),I.current=null);}},[ft,S,w,Fe]),useEffect(()=>{let e=x.current;if(!e||!f||!S){Ae(null);return}try{Ae(e.cell(p,f.focus.row,f.focus.col));}catch{Ae(null);}},[f,S,p,Fe]),useEffect(()=>{let e=()=>{J.current=false,_e(false);};return window.addEventListener("mouseup",e),()=>window.removeEventListener("mouseup",e)},[]),useEffect(()=>{let e=x.current;if(!e||!f||!S){b({}),we({canUndo:false,canRedo:false}),Ve([]);return}let o=normalizeRange(f);try{let n=e.cell(p,o.top,o.left).a1,a=e.cell(p,o.bottom,o.right).a1,u=`${n}:${a}`;b(e.selectionFormatting(p,u)),we(e.historyState()),Ve(e.mergedRanges(p,u));}catch{b({}),we({canUndo:false,canRedo:false}),Ve([]);}},[f,S,p,Fe]);let je=useMemo(()=>!me||!S?null:buildA11yGrid(me,f,S.sheetNames[p]??"",{gridLabel:s("a11y.gridLabel"),rowHeaderLabel:s("a11y.rowHeaderLabel"),columnHeaderLabel:s("a11y.columnHeaderLabel"),cellLabel:s("a11y.cellLabel"),cellLabelSelected:s("a11y.cellLabelSelected"),emptyCellLabel:s("a11y.emptyCellLabel"),emptyCellLabelSelected:s("a11y.emptyCellLabelSelected")}),[me,f,S,p,s]),X=useCallback(()=>{U.current?.focus({preventScroll:true});},[]);useEffect(()=>{V&&B.current?.focus({preventScroll:true});},[V]);let N=useCallback(e=>{Q(e.sheetInfo),ke(o=>o+1),ie();},[ie]),qe=useCallback(e=>{let o=x.current;if(!o)return null;let n=normalizeRange(e),a=o.cell(p,n.top,n.left).a1,u=o.cell(p,n.bottom,n.right).a1;return `${a}:${u}`},[p]),se=useCallback(()=>xr(_.current,S,(U.current?.clientHeight??0)/L),[S,L]),Je=useCallback((e,o)=>{let n=ae.current,a=_.current?.grid;if(!n||!a)return null;let u=n.getBoundingClientRect();return cellAtPoint(a,(e-u.left)/L,(o-u.top)/L)},[L]),Qe=useCallback(e=>{let o=x.current;if(!o||!f)return;let{row:n,col:a}=f.focus,u=e??"";if(e===void 0)try{u=o.cell(p,n,a).input;}catch{u="";}he({row:n,col:a,value:u});},[f,p]),mt=useCallback(e=>{let o=x.current;if(!o||!V)return;v.current=true;let{row:n,col:a,value:u}=V;try{N(o.editCell(p,n,a,u));}catch(y){E(y instanceof Error?y.message:String(y));}he(null);let C=selectionAt({row:n,col:a});G(e?moveFocus(C,e,{limits:se()}):C),X();},[V,p,N,se,X]),bo=useCallback(()=>{v.current=true,he(null),X();},[X]),et=useCallback(()=>{let e=x.current;if(!e||!f)return;let o=normalizeRange(f),n=[];for(let a=o.top;a<=o.bottom;a++)for(let u=o.left;u<=o.right;u++)n.push({row:a,col:u,input:""});try{N(e.editCells(p,n));}catch(a){E(a instanceof Error?a.message:String(a));}},[f,p,N]),tt=useCallback(async()=>{let e=x.current;if(!e||!f)return;let o=normalizeRange(f);try{let n=e.cell(p,o.top,o.left).a1,a=e.cell(p,o.bottom,o.right).a1,u=e.rangeCells(p,`${n}:${a}`),C=toTsv(u.map(y=>y.map(ne=>({input:ne.input,isFormula:ne.isFormula}))));await navigator.clipboard.writeText(C);}catch{}},[f,p]),Dt=useCallback(async()=>{await tt(),et();},[tt,et]),At=useCallback(async()=>{let e=x.current;if(!e||!f)return;let o;try{o=await navigator.clipboard.readText();}catch{return}let n=fromTsv(o);if(n.length===0)return;let a=normalizeRange(f),u=[],C=1;n.forEach((y,ne)=>{C=Math.max(C,y.length),y.forEach((Le,pe)=>u.push({row:a.top+ne,col:a.left+pe,input:Le}));});try{N(e.editCells(p,u));}catch(y){E(y instanceof Error?y.message:String(y));return}G({anchor:{row:a.top,col:a.left},focus:{row:a.top+n.length-1,col:a.left+C-1}});},[f,p,N]),fo=useCallback(e=>{let o=x.current;if(!o||!f)return;let n=qe(f);if(n){if(e==="paintFormat"){if(Me){ze(null),Ee.current=null;return}try{ze(o.captureFormat(p,n));let a=normalizeRange(f);Ee.current=`${p}:${a.top}:${a.left}:${a.bottom}:${a.right}`;}catch(a){E(a instanceof Error?a.message:String(a));}return}try{let a;e==="currency"?a=o.setNumberFormat(p,n,"currency"):e==="percent"?a=o.setNumberFormat(p,n,"percent"):e==="increaseDecimal"?a=o.setNumberFormat(p,n,"increaseDecimal"):e==="decreaseDecimal"?a=o.setNumberFormat(p,n,"decreaseDecimal"):e==="bold"?a=o.patchRangeStyle(p,n,{bold:!ee.bold}):e==="italic"?a=o.patchRangeStyle(p,n,{italic:!ee.italic}):e==="strikethrough"?a=o.patchRangeStyle(p,n,{strikethrough:!ee.strikethrough}):e.type==="numberFormat"?a=e.value==="custom"?o.setNumberFormat(p,n,{type:"custom",pattern:ee.numberFormatPattern??"0.00"}):o.setNumberFormat(p,n,e.value):e.type==="fontFamily"?a=o.patchRangeStyle(p,n,{fontFamily:e.value}):e.type==="fontSize"?a=o.patchRangeStyle(p,n,{fontSize:e.value}):e.type==="textColor"?a=o.patchRangeStyle(p,n,{textColor:e.value}):e.type==="fillColor"?a=o.patchRangeStyle(p,n,{fillColor:e.value}):e.type==="borderPreset"?a=o.patchRangeStyle(p,n,{border:{preset:e.value,style:dt??ee.borderStyle??"solid",color:pt??ee.borderColor??"#000000"}}):e.type==="borderStyle"?(Mt(e.value),a=o.patchRangeStyle(p,n,{border:{style:e.value}})):e.type==="borderColor"?(Et(e.value),a=o.patchRangeStyle(p,n,{border:{color:e.value}})):e.type==="horizontalAlignment"?a=o.patchRangeStyle(p,n,{horizontalAlignment:e.value}):e.type==="verticalAlignment"?a=o.patchRangeStyle(p,n,{verticalAlignment:e.value}):a=o.patchRangeStyle(p,n,{textWrapping:e.value}),N(a),X();}catch(a){E(a instanceof Error?a.message:String(a));}}},[f,qe,Me,p,ee,dt,pt,N,X]);useEffect(()=>{let e=x.current;if(!e||!f||!Me||Te)return;let o=normalizeRange(f);if(`${p}:${o.top}:${o.left}:${o.bottom}:${o.right}`===Ee.current)return;let a=qe(f);if(a)try{N(e.applyFormat(p,a,Me)),ze(null),Ee.current=null,X();}catch(u){E(u instanceof Error?u.message:String(u));}},[f,Me,Te,p,qe,N,X]);let ht=useCallback(()=>{let e=x.current;if(e)try{N(e.undo());}catch(o){E(o instanceof Error?o.message:String(o));}},[N]),ot=useCallback(()=>{let e=x.current;if(e)try{N(e.redo());}catch(o){E(o instanceof Error?o.message:String(o));}},[N]),mo=useCallback(()=>window.print(),[]),ho=useCallback(()=>{},[]),go=useCallback(e=>{let o=x.current;if(!o||!f)return;let n=normalizeRange(f),a=(y,ne)=>({row:y,col:ne}),u=(y,ne,Le,pe)=>({start:a(y,ne),end:a(Le,pe)}),C=[];if(e==="all")C.push({type:"mergeCells",sheet:p,range:u(n.top,n.left,n.bottom,n.right)});else if(e==="horizontal")for(let y=n.top;y<=n.bottom;y++)C.push({type:"mergeCells",sheet:p,range:u(y,n.left,y,n.right)});else if(e==="vertical")for(let y=n.left;y<=n.right;y++)C.push({type:"mergeCells",sheet:p,range:u(n.top,y,n.bottom,y)});else for(let y of ct)C.push({type:"unmergeCells",sheet:p,range:u(y.start.row,y.start.col,y.end.row,y.end.col)});if(C.length!==0)try{N(o.applyOps(C)),X();}catch(y){E(y instanceof Error?y.message:String(y));}},[f,p,ct,N,X]),yo=useCallback((e,o)=>{let n=x.current;if(n)try{N(n.acceptProposal(e,{force:o})),Ie(({[e]:a,...u})=>u),ie(),X();}catch(a){a instanceof StaleProposalError?Ie(u=>({...u,[e]:a.cells})):E(a instanceof Error?a.message:String(a));}},[N,ie,X]),xo=useCallback(e=>{let o=x.current;if(o)try{o.rejectProposal(e),Ie(({[e]:n,...a})=>a),ie();}catch(n){E(n instanceof Error?n.message:String(n));}},[ie]),gt=useCallback(()=>{let e=x.current;if(e)try{let o=e.save();i?i(o):so(o,r??"workbook.xlsx",gr);}catch(o){E(o instanceof Error?o.message:String(o));}},[i,r]),vo=useCallback(()=>{let e=x.current,o=U.current;if(!(!e||!o))try{let n=e.renderPng({x:o.scrollLeft/L,y:o.scrollTop/L,width:o.clientWidth/L,height:o.clientHeight/L});so(n,vr(r),"image/png");}catch(n){E(n instanceof Error?n.message:String(n));}},[r,L]),Ft=useCallback(e=>{let o=x.current;if(!o||!f||Ce==null)return;let{row:n,col:a}=f.focus;try{N(o.editCell(p,n,a,Ce));}catch(u){E(u instanceof Error?u.message:String(u));}Se(null),e&&G(u=>u&&moveFocus(u,e,{limits:se()}));},[f,Ce,p,N,se]),So=useCallback(e=>{if(!x.current||!f||!S||V)return;let n=e.metaKey||e.ctrlKey,a=e.key.toLowerCase();if(n){if(a==="c"){tt(),e.preventDefault();return}if(a==="v"){At(),e.preventDefault();return}if(a==="x"){Dt(),e.preventDefault();return}if(a==="z"){e.shiftKey?ot():ht(),e.preventDefault();return}if(a==="y"){ot(),e.preventDefault();return}if(a==="s"){gt(),e.preventDefault();return}}let u=selectionKeyReducer(f,{key:e.key,shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey},se());switch(u.type){case "move":G(u.selection),e.preventDefault();break;case "startEdit":Qe(u.initialInput),e.preventDefault();break;case "clear":et(),e.preventDefault();break;}},[f,S,V,se,tt,At,Dt,ht,ot,gt,Qe,et]),wo=useCallback(e=>{if(!f)return;let o=Je(e.clientX,e.clientY);o&&(e.shiftKey?G(n=>n&&extendTo(n,o,se())):G(selectionAt(o)),J.current=true,_e(true),X());},[f,Je,se,X]),Co=useCallback(e=>{if(!J.current)return;let o=Je(e.clientX,e.clientY);o&&G(n=>n&&extendTo(n,o,se()));},[Je,se]),ko=useCallback(()=>{f&&Qe();},[f,Qe]),Re=me?.grid,zt=Re&&f?rangeRect(Re,normalizeRange(f)):null,It=Re&&f?cellRect(Re,f.focus.row,f.focus.col):null,Bt=Re&&V?cellRect(Re,V.row,V.col):null,Be=zt?Tt(zt,L):null,He=It?Tt(It,L):null,We=Bt?Tt(Bt,L):null,To=S?S.contentWidth*L:void 0,Mo=S?S.contentHeight*L:void 0,Eo=Ce??D?.input??"",Pe=f?normalizeRange(f):null,Ro=Pe?Pe.bottom-Pe.top+1:1,Po=Pe?Pe.right-Pe.left+1:1,Lo=e=>{let o=x.current;if(o)try{o.setActiveSheet(e);let n=U.current;n&&(n.scrollLeft=0,n.scrollTop=0),G(selectionAt({row:0,col:0})),he(null),Se(null),ze(null),Ee.current=null,Q(o.sheetInfo());}catch(n){E(n instanceof Error?n.message:String(n));}};return jsxs("div",{className:g,role:"application","aria-label":s("editor.appLabel"),style:{position:"relative",display:"flex",flexDirection:"column",width:"100%",height:"100%",minWidth:0,color:"#202124",background:"#ffffff",fontFamily:"ui-sans-serif, system-ui, sans-serif"},children:[jsx("div",{ref:q,"data-testid":"xlsx-toolbar",style:fe.shell,children:jsxs(Ge,{currentFormatting:{...ee,borderStyle:dt??ee.borderStyle,borderColor:pt??ee.borderColor,paintFormat:Me!==null},selectionShape:{rows:Ro,columns:Po,canUnmerge:ct.length>0},onSearchMenus:ho,onUndo:ht,onRedo:ot,canUndo:d.canUndo,canRedo:d.canRedo,onPrint:mo,zoom:L,onZoomChange:ge,onFormat:fo,onMerge:go,children:[jsx(Ge.Toolbar,{}),jsxs("div",{style:fe.rail,role:"group","aria-label":s("toolbar.formulaBarLabel"),children:[jsxs(K,{style:{...fe.group,paddingLeft:0},label:s("toolbar.fileActionsLabel"),children:[jsx(H,{testId:"xlsx-save",onClick:gt,disabled:!S,title:s("toolbar.save"),children:jsx(k,{name:"save",size:18})}),jsx(H,{testId:"xlsx-export-png",onClick:vo,disabled:!S||!uo,title:s("toolbar.exportPng"),children:jsx(k,{name:"image",size:18})})]}),jsxs("div",{style:fe.formulaGroup,role:"group","aria-label":s("toolbar.formulaBarLabel"),children:[jsx("input",{"data-testid":"xlsx-name-box",readOnly:true,value:D?.a1??"",placeholder:s("toolbar.nameBoxPlaceholder"),"aria-label":s("toolbar.nameBoxPlaceholder"),style:fe.nameBox}),jsx("span",{style:fe.formulaMark,"aria-hidden":"true",children:"fx"}),jsx("input",{"data-testid":"xlsx-formula-input",value:Eo,placeholder:s("toolbar.formulaPlaceholder"),"aria-label":s("toolbar.formulaPlaceholder"),disabled:!S,onChange:e=>Se(e.target.value),onKeyDown:e=>{e.key==="Enter"?(Ft(e.shiftKey?"up":"down"),X(),e.preventDefault()):e.key==="Escape"&&(Se(null),X(),e.preventDefault());},onBlur:()=>Ft(),style:fe.formulaInput})]}),Lt&&jsx("div",{style:fe.proposals,children:jsxs(H,{testId:"xlsx-proposals-button",onClick:()=>Rt(e=>!e),disabled:!S,active:ut,ariaExpanded:ut,title:s("proposals.panelLabel"),style:{width:Ze.length>0?42:28},children:[jsx(k,{name:"proposals",size:18}),Ze.length>0&&jsx("span",{"data-testid":"xlsx-proposals-count",style:fe.count,children:Ze.length})]})})]})]})}),Lt&&ut&&jsx(ro,{proposals:Ze,staleFor:po,onAccept:yo,onReject:xo,style:{top:Xe+4,right:8,width:"min(320px, calc(100% - 16px))",maxHeight:`min(420px, calc(100% - ${Xe+12}px))`}}),jsxs("div",{ref:U,"data-testid":"xlsx-scroll",tabIndex:0,onKeyDown:So,onMouseDown:wo,onMouseMove:Co,onDoubleClick:ko,style:{position:"relative",flex:1,overflow:"auto",minHeight:0,outline:"none"},children:[jsx("div",{style:{position:"absolute",top:0,left:0,width:To??"100%",height:Mo??"100%"}}),jsxs("div",{style:{position:"sticky",top:0,left:0,width:0,height:0},children:[jsx("canvas",{ref:ae,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:[Be&&jsx("div",{"data-testid":"xlsx-selection",style:{position:"absolute",left:Be.x,top:Be.y,width:Be.w,height:Be.h,boxSizing:"border-box",border:`1px solid ${it}`,background:"rgba(33, 115, 70, 0.12)"}}),He&&!V&&jsx("div",{style:{position:"absolute",left:He.x,top:He.y,width:He.w,height:He.h,boxSizing:"border-box",border:`2px solid ${it}`}}),V&&We&&jsx("input",{ref:B,"data-testid":"xlsx-cell-editor",value:V.value,onChange:e=>he(o=>o&&{...o,value:e.target.value}),onKeyDown:e=>{e.stopPropagation(),e.key==="Enter"?(mt(e.shiftKey?"up":"down"),e.preventDefault()):e.key==="Tab"?(mt(e.shiftKey?"left":"right"),e.preventDefault()):e.key==="Escape"&&(bo(),e.preventDefault());},onBlur:()=>{if(v.current){v.current=false;return}mt();},style:{position:"absolute",left:We.x,top:We.y,width:We.w,height:We.h,boxSizing:"border-box",border:`2px solid ${it}`,padding:"0 3px",font:`${13*L}px system-ui, sans-serif`,background:"#ffffff",pointerEvents:"auto",outline:"none"}})]})]})]}),je&&jsxs("div",{style:Sr,role:"grid","aria-label":je.label,children:[jsxs("div",{role:"row",children:[jsx("span",{role:"columnheader"}),je.columnHeaders.map(e=>jsx("span",{role:"columnheader",children:e.label},e.col))]}),je.rows.map(e=>jsxs("div",{role:"row",children:[jsx("span",{role:"rowheader",children:e.header}),e.cells.map(o=>jsx("span",{role:"gridcell","aria-selected":o.selected,children:o.label},o.col))]},e.row))]}),w&&jsxs("div",{"data-testid":"xlsx-error",role:"alert",style:{position:"absolute",inset:0,display:"grid",placeItems:"center",padding:16,textAlign:"center",color:"#b00020"},children:[s("editor.openError"),": ",w]}),S&&S.sheetNames.length>0&&jsx("div",{"data-testid":"xlsx-sheet-tabs",role:"tablist","aria-label":s("editor.sheetTabsLabel"),style:{display:"flex",gap:2,padding:"4px 6px",borderTop:"1px solid #e0e0e0",background:"#fafafa",overflowX:"auto"},children:S.sheetNames.map((e,o)=>{let n=o===S.activeSheet;return jsx("button",{role:"tab","aria-selected":n,onClick:()=>Lo(o),style:{border:"none",padding:"4px 12px",cursor:"pointer",borderBottom:n?`2px solid ${it}`:"2px solid transparent",fontWeight:n?600:400,background:n?"#ffffff":"transparent"},children:e},o)})})]})}export{Ge as EditorToolbar,De as EditorToolbarContext,rt as LocaleProvider,nt as Toolbar,H as ToolbarButton,ce as ToolbarDropdown,K as ToolbarGroup,te as ToolbarMenuItem,Oe as ToolbarMenuSeparator,$e as ToolbarSeparator,wr as XlsxEditor,nt as XlsxToolbar,Io as useEditorToolbar,ye as useTranslation};
1
+ import {createContext,useMemo,useContext,useState,useRef,useCallback,useEffect}from'react';import {isPngExportAvailable,isProposalsAvailable,initWasm,openWorkbook,selectionAt,paintDisplayList,normalizeRange,buildA11yGrid,cellAtPoint,moveFocus,toTsv,fromTsv,StaleProposalError,selectionKeyReducer,extendTo,hyperlinkAtCell,safeExternalHyperlink,parseHyperlinkLocation,rangeRect,cellRect}from'@betteroffice/xlsx';import {en,deepMerge,createT}from'@betteroffice/xlsx-i18n';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {normalizeAwarenessColor,resolveAwarenessCursor,AWARENESS_LABEL_DURATION_MS}from'@betteroffice/xlsx/collaboration';var ao=createContext(en),io=createContext("en");function at({i18n:t,children:o}){let a=typeof t?._lang=="string"?t._lang:"en",c=useMemo(()=>deepMerge(en,t),[t]);return jsx(io.Provider,{value:a,children:jsx(ao.Provider,{value:c,children:o})})}function Se(){let t=useContext(ao),o=useContext(io);return {t:useMemo(()=>createT(t,o),[t,o])}}var Fe=createContext(null);function ir(){let t=useContext(Fe);if(!t)throw new Error("useEditorToolbar must be used within an <EditorToolbar> component");return t}function L({name:t,size:o=20,style:a}){return jsxs("svg",{width:o,height:o,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",style:{display:"inline-flex",flexShrink:0,...a},children:[t==="search"&&jsxs(Fragment,{children:[jsx("circle",{cx:"10.5",cy:"10.5",r:"6"}),jsx("path",{d:"m15 15 4.5 4.5"})]}),t==="undo"&&jsx("path",{d:"m9 7-5 5 5 5M5 12h9a6 6 0 0 1 6 6"}),t==="redo"&&jsx("path",{d:"m15 7 5 5-5 5m4-5h-9a6 6 0 0 0-6 6"}),t==="print"&&jsxs(Fragment,{children:[jsx("path",{d:"M7 9V4h10v5M7 18H5a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"}),jsx("path",{d:"M7 14h10v6H7z"}),jsx("path",{d:"M17.5 12h.01"})]}),t==="formatPaint"&&jsxs(Fragment,{children:[jsx("path",{d:"M5 4h11v5H5zM8 9v3h5V9"}),jsx("path",{d:"M10.5 12v8"})]}),t==="decimalDecrease"&&jsxs(Fragment,{children:[jsx("path",{d:"M5 7h1M9 7h1M14 7h1M18 7h1"}),jsx("path",{d:"M5 16h1M9 16h1"}),jsx("path",{d:"m15 12-4 4 4 4M11 16h8"})]}),t==="decimalIncrease"&&jsxs(Fragment,{children:[jsx("path",{d:"M5 7h1M9 7h1"}),jsx("path",{d:"M5 16h1M9 16h1M14 16h1M18 16h1"}),jsx("path",{d:"m15 3 4 4-4 4M19 7h-8"})]}),t==="bold"&&jsx("path",{d:"M7 4h6a4 4 0 0 1 0 8H7zm0 8h7a4 4 0 0 1 0 8H7z"}),t==="italic"&&jsx("path",{d:"M10 4h8M6 20h8M14 4 10 20"}),t==="strikethrough"&&jsx(Fragment,{children:jsx("path",{d:"M5 12h14M8 7.5A4.5 4.5 0 0 1 12.5 4c2.2 0 3.7 1 4.5 2.5M8 16.5c.8 2.1 2.4 3.5 5 3.5 2.8 0 4.5-1.4 4.5-3.5 0-2.3-2-3.3-5.5-4.5"})}),t==="textColor"&&jsxs(Fragment,{children:[jsx("path",{d:"m7 16 5-12 5 12M9 11h6"}),jsx("path",{d:"M5 20h14",strokeWidth:"3"})]}),t==="fillColor"&&jsxs(Fragment,{children:[jsx("path",{d:"m7 4 10 10-6 6-7-7zM5 12h12"}),jsx("path",{d:"M18 17c0-1 1-2 1-2s1 1 1 2a1 1 0 0 1-2 0Z"})]}),t==="borders"&&jsx(Fragment,{children:jsx("path",{d:"M4 4h16v16H4zM12 4v16M4 12h16"})}),t==="merge"&&jsxs(Fragment,{children:[jsx("path",{d:"M4 5h16v14H4z"}),jsx("path",{d:"m8 9 3 3-3 3M16 9l-3 3 3 3"})]}),t==="alignLeft"&&jsx("path",{d:"M4 6h16M4 10h11M4 14h16M4 18h11"}),t==="verticalAlignCenter"&&jsxs(Fragment,{children:[jsx("path",{d:"M4 4h16M4 20h16M8 12h8"}),jsx("path",{d:"m10 9 2 3 2-3M10 15l2-3 2 3"})]}),t==="wrap"&&jsxs(Fragment,{children:[jsx("path",{d:"M4 6h16M4 11h12a3 3 0 0 1 0 6h-3"}),jsx("path",{d:"m15 14-3 3 3 3M4 17h5"})]}),t==="more"&&jsxs(Fragment,{children:[jsx("circle",{cx:"5",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),jsx("circle",{cx:"12",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),jsx("circle",{cx:"19",cy:"12",r:"1",fill:"currentColor",stroke:"none"})]}),t==="chevronDown"&&jsx("path",{d:"m7 10 5 5 5-5"}),t==="remove"&&jsx("path",{d:"M5 12h14"}),t==="add"&&jsx("path",{d:"M12 5v14M5 12h14"}),t==="check"&&jsx("path",{d:"m5 12 4 4L19 6"}),t==="save"&&jsx("path",{d:"M12 3v11m0 0 4-4m-4 4-4-4M5 19h14"}),t==="image"&&jsxs(Fragment,{children:[jsx("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),jsx("circle",{cx:"8.5",cy:"9.5",r:"1.25"}),jsx("path",{d:"m6 17 4.5-4.5 3.25 3.25L16 13.5l2 2"})]}),t==="proposals"&&jsxs(Fragment,{children:[jsx("path",{d:"m12 3 1.25 3.75L17 8l-3.75 1.25L12 13l-1.25-3.75L7 8l3.75-1.25L12 3Z"}),jsx("path",{d:"m18 14 .75 2.25L21 17l-2.25.75L18 20l-.75-2.25L15 17l2.25-.75L18 14Z"})]})]})}var I={text:"#3c4043",muted:"#5f6368",disabled:"#9aa0a6",hover:"#e2e7ef",active:"#d3e3fd",border:"#c7cacf",surface:"#ffffff",rail:"#edf2fa"},cr={appearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",gap:2,minWidth:28,height:28,padding:"0 5px",border:0,borderRadius:4,color:I.text,font:"500 13px ui-sans-serif, system-ui, sans-serif",lineHeight:1,whiteSpace:"nowrap",boxSizing:"border-box"};function uo(t,o,a,c){return {...cr,background:o?I.active:a&&!t?I.hover:"transparent",color:t?I.disabled:I.text,cursor:t?"default":"pointer",opacity:t?.48:1,...c}}function U({active:t=false,disabled:o=false,title:a,onClick:c,children:u,style:p,testId:s,ariaExpanded:w}){let[M,S]=useState(false);return jsx("button",{type:"button","data-testid":s,disabled:o,"aria-label":a,"aria-pressed":t||void 0,"aria-expanded":w,title:a,onMouseDown:z=>z.preventDefault(),onMouseEnter:()=>S(true),onMouseLeave:()=>S(false),onClick:o?void 0:c,style:uo(o,t,M,p),children:u})}function Y({label:t,children:o,style:a}){return jsx("div",{role:"group","aria-label":t,style:{display:"inline-flex",alignItems:"center",gap:1,flex:"0 0 auto",...a},children:o})}function Ge(){return jsx("div",{role:"separator",style:{width:1,height:24,margin:"0 5px",background:I.border,flex:"0 0 auto"}})}function fe({title:t,trigger:o,children:a,disabled:c=false,active:u=false,menuWidth:p=220,style:s,testId:w}){let[M,S]=useState(false),[z,F]=useState(false),[K,_]=useState({top:0,left:0}),$=useRef(null),v=useRef(null),H=useCallback(()=>S(false),[]);return useEffect(()=>{if(!M||!$.current)return;let A=$.current.getBoundingClientRect(),Q=Math.min(A.left,Math.max(8,window.innerWidth-p-8));_({top:A.bottom+4,left:Q});},[M,p]),useEffect(()=>{if(!M)return;let A=Z=>{let oe=Z.target;!$.current?.contains(oe)&&!v.current?.contains(oe)&&H();},Q=Z=>{Z.key==="Escape"&&H();},C=()=>H();return document.addEventListener("mousedown",A),document.addEventListener("keydown",Q),window.addEventListener("scroll",C,true),()=>{document.removeEventListener("mousedown",A),document.removeEventListener("keydown",Q),window.removeEventListener("scroll",C,true);}},[M,H]),jsxs("div",{style:{position:"relative",display:"inline-flex",flex:"0 0 auto"},children:[jsx("button",{ref:$,type:"button","data-testid":w,disabled:c,"aria-label":t,"aria-haspopup":"menu","aria-expanded":M,title:t,onMouseDown:A=>A.preventDefault(),onMouseEnter:()=>F(true),onMouseLeave:()=>F(false),onClick:()=>!c&&S(A=>!A),style:uo(c,u||M,z,s),children:o}),M&&jsx("div",{ref:v,role:"menu","aria-label":t,onMouseDown:A=>A.preventDefault(),style:{position:"fixed",top:K.top,left:K.left,zIndex:1e4,width:p,maxHeight:"min(440px, calc(100vh - 16px))",overflowY:"auto",padding:6,border:`1px solid ${I.border}`,borderRadius:8,background:I.surface,boxShadow:"0 4px 16px rgba(60, 64, 67, 0.24)",boxSizing:"border-box"},children:a(H)})]})}function le({label:t,icon:o,selected:a=false,disabled:c=false,onClick:u,close:p}){let[s,w]=useState(false);return jsxs("button",{type:"button",role:"menuitem",disabled:c,"aria-label":t,onMouseEnter:()=>w(true),onMouseLeave:()=>w(false),onClick:()=>{c||(u?.(),p?.());},style:{appearance:"none",display:"flex",alignItems:"center",gap:10,width:"100%",minHeight:32,padding:"5px 9px",border:0,borderRadius:4,background:s&&!c?I.hover:"transparent",color:c?I.disabled:I.text,cursor:c?"default":"pointer",opacity:c?.48:1,font:"400 13px ui-sans-serif, system-ui, sans-serif",textAlign:"left",boxSizing:"border-box"},children:[jsx("span",{style:{display:"inline-grid",placeItems:"center",width:20,flex:"0 0 auto"},children:o}),jsx("span",{style:{flex:1},children:t}),a&&jsx("span",{"aria-hidden":"true",children:"\u2713"})]})}function _e(){return jsx("div",{role:"separator",style:{height:1,margin:"5px 2px",background:I.border}})}function Tt({mode:t,value:o,label:a,onChange:c,disabled:u=false}){let[p,s]=useState(false);return jsxs("label",{title:a,"aria-label":a,style:{position:"relative",display:"inline-grid",placeItems:"center",width:28,height:28,borderRadius:4,background:p&&!u?I.hover:"transparent",color:u?I.disabled:I.text,cursor:u?"default":"pointer",opacity:u?.48:1,boxSizing:"border-box"},onMouseEnter:()=>s(true),onMouseLeave:()=>s(false),children:[jsx(L,{name:t==="text"?"textColor":"fillColor",size:20}),jsx("span",{"aria-hidden":"true",style:{position:"absolute",left:5,right:5,bottom:2,height:3,borderRadius:2,background:o}}),jsx("input",{type:"color",value:o,disabled:u,"aria-label":a,onChange:w=>c?.(w.target.value),style:{position:"absolute",inset:0,width:"100%",height:"100%",opacity:0}})]})}function Pt({value:t,options:o,label:a,onCommit:c,disabled:u=false,width:p=72,inputStyle:s,testId:w}){let[M,S]=useState(t),[z,F]=useState(false),[K,_]=useState({top:0,left:0,width:p}),$=useRef(null),v=useRef(null),H=useRef(null);useEffect(()=>S(t),[t]);let A=useCallback(()=>F(false),[]);useEffect(()=>{if(!z||!$.current)return;let C=$.current.getBoundingClientRect();_({top:C.bottom+4,left:C.left,width:Math.max(C.width,p)});},[z,p]),useEffect(()=>{if(!z)return;let C=oe=>{let de=oe.target;!$.current?.contains(de)&&!v.current?.contains(de)&&A();},Z=oe=>{oe.key==="Escape"&&(S(t),A());};return document.addEventListener("mousedown",C),document.addEventListener("keydown",Z),()=>{document.removeEventListener("mousedown",C),document.removeEventListener("keydown",Z);}},[z,A,t]);let Q=useCallback(()=>{!u&&c&&M.trim()&&c(M.trim()),S(t);},[u,c,M,t]);return jsxs("div",{ref:$,style:{display:"inline-flex",alignItems:"center",width:p,height:28,border:`1px solid ${I.border}`,borderRadius:4,background:u?"rgba(255,255,255,0.5)":I.surface,opacity:u?.48:1,boxSizing:"border-box",flex:"0 0 auto"},children:[jsx("input",{ref:H,"data-testid":w,role:"combobox","aria-label":a,"aria-autocomplete":"list","aria-expanded":z,disabled:u,value:M,onFocus:C=>{u||(F(true),C.currentTarget.select());},onChange:C=>S(C.target.value),onKeyDown:C=>{C.key==="Enter"?(Q(),A(),C.currentTarget.blur()):C.key==="ArrowDown"&&(F(true),C.preventDefault());},onBlur:()=>{requestAnimationFrame(()=>{v.current?.contains(document.activeElement)||Q();});},style:{appearance:"none",width:"calc(100% - 22px)",height:26,padding:"0 2px 0 7px",border:0,outline:0,background:"transparent",color:I.text,font:"500 13px ui-sans-serif, system-ui, sans-serif",boxSizing:"border-box",...s}}),jsx("button",{type:"button",disabled:u,tabIndex:-1,"aria-label":a,title:a,onMouseDown:C=>C.preventDefault(),onClick:()=>{u||(F(C=>!C),H.current?.focus());},style:{appearance:"none",display:"grid",placeItems:"center",width:21,height:26,padding:0,border:0,background:"transparent",color:I.muted,cursor:u?"default":"pointer"},children:jsx(L,{name:"chevronDown",size:14})}),z&&!u&&jsx("div",{ref:v,role:"listbox","aria-label":a,style:{position:"fixed",top:K.top,left:K.left,zIndex:1e4,width:K.width,maxHeight:260,overflowY:"auto",padding:4,border:`1px solid ${I.border}`,borderRadius:6,background:I.surface,boxShadow:"0 4px 16px rgba(60, 64, 67, 0.24)",boxSizing:"border-box"},children:o.map(C=>jsx("button",{type:"button",role:"option","aria-selected":C.value===t,onMouseDown:Z=>Z.preventDefault(),onClick:()=>{S(C.label),c?.(C.value),A();},style:{appearance:"none",display:"block",width:"100%",minHeight:28,padding:"4px 7px",border:0,borderRadius:3,background:C.value===t?I.active:"transparent",color:I.text,cursor:"pointer",font:"400 13px ui-sans-serif, system-ui, sans-serif",textAlign:"left"},children:C.label},C.value))})]})}var gr=[.5,.75,.9,1,1.25,1.5,2],yr=["Arial","Calibri","Cambria","Georgia","Roboto","Times New Roman","Verdana"],xr=[8,9,10,11,12,14,16,18,20,24,28,36,48,72],vr=["automatic","plainText","number","percent","scientific","currency","date","time","custom"],wr=["all","inner","horizontal","vertical","outer","left","top","right","bottom","none"],Sr=["solid","dashed","dotted","double"],Cr=["left","center","right"],kr=["top","middle","bottom"],Tr=["overflow","wrap","clip"];function Mr(t){let o={};for(let a of Object.keys(t))t[a]!==void 0&&(o[a]=t[a]);return o}function Rr(t){let o=useContext(Fe);return o?{...o,...Mr(t)}:t}function mo({preset:t}){let o=a=>t===a||t==="all"||t==="outer"?2:.6;return jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","aria-hidden":"true",children:[t!=="none"&&jsxs(Fragment,{children:[jsx("path",{d:"M3 3h14",strokeWidth:o("top")}),jsx("path",{d:"M17 3v14",strokeWidth:o("right")}),jsx("path",{d:"M3 17h14",strokeWidth:o("bottom")}),jsx("path",{d:"M3 3v14",strokeWidth:o("left")}),(t==="all"||t==="inner"||t==="horizontal")&&jsx("path",{d:"M3 10h14",strokeWidth:"1.5"}),(t==="all"||t==="inner"||t==="vertical")&&jsx("path",{d:"M10 3v14",strokeWidth:"1.5"})]}),t==="none"&&jsx("path",{d:"M4 4h12v12H4zM3 17 17 3",strokeWidth:"1.5"})]})}function ho({value:t}){let o=t==="left"?3:t==="center"?5:7,a=t==="left"?15:t==="center"?17:19;return jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6","aria-hidden":"true",children:[jsx("path",{d:"M3 4h14M3 10h14M3 16h14"}),jsx("path",{d:`M${o} 7h${a-o}M${o} 13h${a-o}`})]})}function go({value:t}){return jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6","aria-hidden":"true",children:[jsx("path",{d:"M3 3h14M3 17h14"}),jsx("path",{d:`M6 ${t==="top"?5:t==="middle"?10:15}h8`}),jsx("path",{d:t==="top"?"m8 8 2-3 2 3":t==="bottom"?"m8 12 2 3 2-3":"m8 7 2 3 2-3m-4 6 2-3 2 3"})]})}function Er({value:t}){return jsx("svg",{width:"44",height:"12",viewBox:"0 0 44 12",fill:"none",stroke:"currentColor","aria-hidden":"true",children:t==="double"?jsx(Fragment,{children:jsx("path",{d:"M2 4h40M2 8h40"})}):jsx("path",{d:"M2 6h40",strokeWidth:"2",strokeDasharray:t==="dashed"?"7 4":t==="dotted"?"1 4":void 0})})}function yo(t,o,a){return a>0?o.find(c=>c>t)??t+1:[...o].reverse().find(c=>c<t)??Math.max(1,t-1)}function it(t){let{t:o}=Se(),{currentFormatting:a={},selectionShape:c,onFormat:u,onMerge:p,onSearchMenus:s,onUndo:w,onRedo:M,canUndo:S=false,canRedo:z=false,onPrint:F,zoom:K=1,onZoomChange:_,fontFamilies:$=yr,fontSizes:v=xr,disabled:H=false,className:A,style:Q,children:C}=Rr(t),Z=useRef(null),[oe,de]=useState(Number.POSITIVE_INFINITY),E=!H&&!!u,y=!H&&!!p,re=a.fontSize??10,Ee=(c?.rows??1)>1,B=(c?.columns??1)>1,xe=Ee||B;useEffect(()=>{let h=Z.current;if(!h)return;let m=()=>de(h.clientWidth);m();let ne=new ResizeObserver(m);return ne.observe(h),()=>ne.disconnect()},[]);let pt=useMemo(()=>gr.map(h=>({value:`${h*100}%`,label:`${h*100}%`})),[]),b=useMemo(()=>v.map(h=>({value:String(h),label:String(h)})),[v]),k=h=>{E&&u?.(h);},O=h=>jsx(Fragment,{children:vr.map(m=>jsx(le,{label:o(`toolbar.numberFormats.${m}`),selected:a.numberFormat===m,disabled:!E,onClick:()=>k({type:"numberFormat",value:m}),close:h},m))}),me=h=>jsxs(Fragment,{children:[wr.map(m=>jsx(le,{icon:jsx(mo,{preset:m}),label:o(`toolbar.borderPresets.${m}`),selected:a.borderPreset===m,disabled:!E,onClick:()=>k({type:"borderPreset",value:m}),close:h},m)),jsx(_e,{}),Sr.map(m=>jsx(le,{icon:jsx(Er,{value:m}),label:o(`toolbar.borderStyles.${m}`),selected:a.borderStyle===m,disabled:!E,onClick:()=>k({type:"borderStyle",value:m}),close:h},m)),jsx(_e,{}),jsxs("label",{style:{position:"relative",display:"flex",alignItems:"center",gap:10,minHeight:32,padding:"5px 9px",color:I.text,font:"400 13px ui-sans-serif, system-ui, sans-serif",cursor:E?"pointer":"default"},children:[jsx("span",{style:{width:20,height:5,borderRadius:2,background:a.borderColor??"#000000"}}),jsx("span",{children:o("toolbar.borderColor")}),jsx("input",{type:"color",value:a.borderColor??"#000000",disabled:!E,"aria-label":o("toolbar.borderColor"),onChange:m=>k({type:"borderColor",value:m.target.value}),style:{position:"absolute",inset:0,width:"100%",height:"100%",opacity:0}})]})]}),Ye=h=>jsxs(Fragment,{children:[jsx(le,{label:o("toolbar.merge.all"),disabled:!y||!xe,onClick:()=>p?.("all"),close:h}),jsx(le,{label:o("toolbar.merge.horizontal"),disabled:!y||!B,onClick:()=>p?.("horizontal"),close:h}),jsx(le,{label:o("toolbar.merge.vertical"),disabled:!y||!Ee,onClick:()=>p?.("vertical"),close:h}),jsx(_e,{}),jsx(le,{label:o("toolbar.merge.unmerge"),disabled:!y||!c?.canUnmerge,onClick:()=>p?.("unmerge"),close:h})]}),He=h=>jsx(Fragment,{children:Cr.map(m=>jsx(le,{icon:jsx(ho,{value:m}),label:o(`toolbar.horizontalAlign.${m}`),selected:a.horizontalAlignment===m,disabled:!E,onClick:()=>k({type:"horizontalAlignment",value:m}),close:h},m))}),Pe=h=>jsx(Fragment,{children:kr.map(m=>jsx(le,{icon:jsx(go,{value:m}),label:o(`toolbar.verticalAlign.${m}`),selected:a.verticalAlignment===m,disabled:!E,onClick:()=>k({type:"verticalAlignment",value:m}),close:h},m))}),ve=h=>jsx(Fragment,{children:Tr.map(m=>jsx(le,{label:o(`toolbar.wrapping.${m}`),selected:a.textWrapping===m,disabled:!E,onClick:()=>k({type:"textWrapping",value:m}),close:h},m))}),he=[{key:"search",width:29,node:jsx(Y,{label:o("toolbar.groups.search"),children:jsx(U,{title:o("toolbar.searchMenus"),onClick:s,testId:"xlsx-search-menus",children:jsx(L,{name:"search"})})})},{key:"history",width:58,node:jsxs(Y,{label:o("toolbar.groups.history"),children:[jsx(U,{title:o("toolbar.undo"),disabled:H||!S||!w,onClick:w,testId:"xlsx-undo",children:jsx(L,{name:"undo"})}),jsx(U,{title:o("toolbar.redo"),disabled:H||!z||!M,onClick:M,testId:"xlsx-redo",children:jsx(L,{name:"redo"})})]})},{key:"print",width:29,node:jsx(Y,{label:o("toolbar.groups.print"),children:jsx(U,{title:o("toolbar.print"),disabled:H||!F,onClick:F,children:jsx(L,{name:"print"})})})},{key:"paint",width:29,node:jsx(Y,{label:o("toolbar.groups.paintFormat"),children:jsx(U,{title:o("toolbar.paintFormat"),active:a.paintFormat,disabled:!E,onClick:()=>k("paintFormat"),children:jsx(L,{name:"formatPaint"})})})},{key:"zoom",width:82,node:jsx(Y,{label:o("toolbar.groups.zoom"),children:jsx(Pt,{value:`${Math.round(K*100)}%`,options:pt,label:o("toolbar.zoomValue",{value:`${Math.round(K*100)}%`}),disabled:H||!_,onCommit:h=>{let m=Number.parseFloat(h.replace("%",""));Number.isFinite(m)&&m>=25&&m<=400&&_?.(m/100);},width:76,testId:"xlsx-zoom"})})},{key:"number",width:202,node:jsxs(Fragment,{children:[jsx(Ge,{}),jsxs(Y,{label:o("toolbar.groups.number"),children:[jsx(U,{title:o("toolbar.currency"),disabled:!E,onClick:()=>k("currency"),children:jsx("span",{style:{fontSize:16},children:o("toolbar.currencySymbol")})}),jsx(U,{title:o("toolbar.percent"),disabled:!E,onClick:()=>k("percent"),children:jsx("span",{style:{fontSize:15},children:"%"})}),jsx(U,{title:o("toolbar.decreaseDecimal"),disabled:!E,onClick:()=>k("decreaseDecimal"),children:jsx(L,{name:"decimalDecrease"})}),jsx(U,{title:o("toolbar.increaseDecimal"),disabled:!E,onClick:()=>k("increaseDecimal"),children:jsx(L,{name:"decimalIncrease"})}),jsx(fe,{title:o("toolbar.moreNumberFormats"),disabled:!E,trigger:jsxs(Fragment,{children:[jsx("span",{children:"123"}),jsx(L,{name:"chevronDown",size:13})]}),children:O})]})]})},{key:"font-family",width:137,node:jsxs(Fragment,{children:[jsx(Ge,{}),jsx(Y,{label:o("toolbar.groups.font"),children:jsx(fe,{title:o("toolbar.fontFamily"),disabled:!E,menuWidth:210,style:{width:120,justifyContent:"space-between"},trigger:jsxs(Fragment,{children:[jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:a.fontFamily??"Calibri"}),jsx(L,{name:"chevronDown",size:13})]}),children:h=>jsx(Fragment,{children:$.map(m=>jsx(le,{label:m,selected:a.fontFamily===m,disabled:!E,onClick:()=>k({type:"fontFamily",value:m}),close:h},m))})})})]})},{key:"font-size",width:116,node:jsxs(Y,{label:o("toolbar.groups.font"),children:[jsx(U,{title:o("toolbar.decreaseFontSize"),disabled:!E,onClick:()=>k({type:"fontSize",value:yo(re,v,-1)}),children:jsx(L,{name:"remove"})}),jsx(Pt,{value:String(re),options:b,label:o("toolbar.fontSize"),disabled:!E,onCommit:h=>{let m=Number.parseFloat(h);Number.isFinite(m)&&m>=1&&m<=400&&k({type:"fontSize",value:m});},width:50,inputStyle:{textAlign:"center"}}),jsx(U,{title:o("toolbar.increaseFontSize"),disabled:!E,onClick:()=>k({type:"fontSize",value:yo(re,v,1)}),children:jsx(L,{name:"add"})})]})},{key:"text",width:98,node:jsxs(Fragment,{children:[jsx(Ge,{}),jsxs(Y,{label:o("toolbar.groups.text"),children:[jsx(U,{title:o("toolbar.bold"),active:a.bold,disabled:!E,onClick:()=>k("bold"),children:jsx(L,{name:"bold"})}),jsx(U,{title:o("toolbar.italic"),active:a.italic,disabled:!E,onClick:()=>k("italic"),children:jsx(L,{name:"italic"})}),jsx(U,{title:o("toolbar.strikethrough"),active:a.strikethrough,disabled:!E,onClick:()=>k("strikethrough"),children:jsx(L,{name:"strikethrough"})})]})]})},{key:"colors",width:58,node:jsxs(Y,{label:o("toolbar.groups.colors"),children:[jsx(Tt,{mode:"text",value:a.textColor??"#000000",label:o("toolbar.textColor"),disabled:!E,onChange:h=>k({type:"textColor",value:h})}),jsx(Tt,{mode:"fill",value:a.fillColor??"#ffffff",label:o("toolbar.fillColor"),disabled:!E,onChange:h=>k({type:"fillColor",value:h})})]})},{key:"borders",width:36,node:jsx(Y,{label:o("toolbar.groups.borders"),children:jsx(fe,{title:o("toolbar.borders"),disabled:!E,menuWidth:240,trigger:jsxs(Fragment,{children:[jsx(mo,{preset:a.borderPreset??"all"}),jsx(L,{name:"chevronDown",size:12})]}),children:me})})},{key:"merge",width:58,node:jsxs(Y,{label:o("toolbar.groups.merge"),children:[jsx(U,{title:o("toolbar.merge.all"),disabled:!y||!xe,onClick:()=>p?.("all"),style:{borderRadius:"4px 0 0 4px"},testId:"xlsx-merge-all",children:jsx(L,{name:"merge"})}),jsx(fe,{title:o("toolbar.mergeCells"),disabled:!y||!xe&&!c?.canUnmerge,menuWidth:220,style:{minWidth:20,width:20,padding:0,borderRadius:"0 4px 4px 0"},trigger:jsx(L,{name:"chevronDown",size:13}),children:Ye})]})},{key:"alignment",width:118,node:jsxs(Y,{label:o("toolbar.groups.alignment"),children:[jsx(fe,{title:o("toolbar.horizontalAlignment"),disabled:!E,menuWidth:180,trigger:jsxs(Fragment,{children:[jsx(ho,{value:a.horizontalAlignment??"left"}),jsx(L,{name:"chevronDown",size:12})]}),children:He}),jsx(fe,{title:o("toolbar.verticalAlignment"),disabled:!E,menuWidth:180,trigger:jsxs(Fragment,{children:[jsx(go,{value:a.verticalAlignment??"middle"}),jsx(L,{name:"chevronDown",size:12})]}),children:Pe}),jsx(fe,{title:o("toolbar.textWrapping"),disabled:!E,menuWidth:180,trigger:jsxs(Fragment,{children:[jsx(L,{name:"wrap"}),jsx(L,{name:"chevronDown",size:12})]}),children:ve})]})}];C&&he.push({key:"custom",width:40,node:C});let ft=Math.max(0,oe-48),R=0,Be=he.length;for(let h=0;h<he.length;h++)if(R+=he[h].width,R>ft){Be=h;break}let Le=he.slice(0,Be),Ae=he.slice(Be);return jsxs("div",{ref:Z,className:A,role:"toolbar","aria-label":o("toolbar.actionsLabel"),"data-testid":"xlsx-formatting-toolbar",style:{display:"flex",alignItems:"center",minWidth:0,minHeight:36,margin:"0 8px 5px",padding:"4px 7px",borderRadius:18,background:I.rail,color:I.text,overflow:"hidden",boxSizing:"border-box",...Q},children:[Le.map(h=>jsx("span",{style:{display:"contents"},children:h.node},h.key)),jsx("span",{style:{marginLeft:"auto",flex:"0 0 auto"},children:jsx(fe,{title:o("toolbar.more"),disabled:Ae.length===0,menuWidth:390,testId:"xlsx-toolbar-more",trigger:jsx(L,{name:"more"}),children:()=>jsx("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:2},children:Ae.map(h=>jsx("span",{style:{display:"contents"},children:h.node},h.key))})})})]})}function Pr({children:t,className:o,style:a,...c}){return jsx(Fe.Provider,{value:c,children:jsx("div",{className:o,"data-testid":"xlsx-editor-toolbar",style:{display:"flex",flexDirection:"column",flex:"0 0 auto",...a},children:t})})}var Ke=Pr;Ke.Toolbar=it;var Fr=8,Hr=32;function Br(t){let o=t.trim().split(/\s+/).filter(Boolean);return o.length===0?"?":o.slice(0,2).map(a=>a[0]).join("").toUpperCase()}function Nr(t){let o=Number.parseInt(t.slice(1,3),16),a=Number.parseInt(t.slice(3,5),16),c=Number.parseInt(t.slice(5,7),16);return `rgba(${o}, ${a}, ${c}, 0.1)`}function Wr(t,o){return t.left<=o.right&&t.right>=o.left&&t.top<=o.bottom&&t.bottom>=o.top}function ct(t,o){let a={...t},c=true;for(;c;){c=false;for(let u of o){let p={top:Math.min(u.start.row,u.end.row),left:Math.min(u.start.col,u.end.col),bottom:Math.max(u.start.row,u.end.row),right:Math.max(u.start.col,u.end.col)};if(!Wr(a,p))continue;let s=Math.min(a.top,p.top),w=Math.min(a.left,p.left),M=Math.max(a.bottom,p.bottom),S=Math.max(a.right,p.right);s===a.top&&w===a.left&&M===a.bottom&&S===a.right||(Object.assign(a,{top:s,left:w,bottom:M,right:S}),c=true);}}return a}function $r(t){let[o,a]=useState(()=>Date.now());return useEffect(()=>{let c=Date.now();a(c);let u=t.map(w=>w.cursorMovedAt+AWARENESS_LABEL_DURATION_MS).filter(w=>w>c);if(u.length===0)return;let p=setTimeout(()=>a(Date.now()),Math.min(...u)-c+1);return p.unref?.(),()=>clearTimeout(p)},[t]),o}function So({peers:t,sheetIds:o,sheetNames:a,activeSheet:c}){if(t.length===0)return null;let u=t.slice(0,Fr),p=t.length-u.length;return jsxs("div",{"data-testid":"xlsx-presence-strip","aria-label":"Collaborators",style:{display:"flex",alignItems:"center",gap:4,padding:"0 6px",flex:"0 0 auto"},children:[u.map(s=>{let w=s.cursor?o.indexOf(s.cursor.sheet):c,M=s.cursor!==null&&w!==c,S=normalizeAwarenessColor(s.user.color,s.clientId),z=w>=0?a[w]:s.cursor?"Unavailable sheet":void 0,F=M||w<0?`${s.user.name} \u2014 ${z}`:s.user.name;return jsx("span",{"data-testid":`xlsx-presence-chip-${s.clientId}`,title:F,"aria-label":F,style:{display:"inline-grid",placeItems:"center",width:24,height:24,borderRadius:"50%",backgroundColor:S,color:"#ffffff",boxShadow:"0 0 0 2px #ffffff",fontSize:9,fontWeight:700,lineHeight:1,letterSpacing:"-0.02em",opacity:M||w<0?.42:1,transition:"opacity 120ms ease"},children:Br(s.user.name)},s.clientId)}),p>0&&jsxs("span",{"data-testid":"xlsx-presence-overflow",title:`${p} more collaborators`,"aria-label":`${p} more collaborators`,style:{display:"inline-grid",placeItems:"center",minWidth:24,height:24,padding:"0 4px",borderRadius:12,backgroundColor:"#5f6368",color:"#ffffff",fontSize:9,fontWeight:700,lineHeight:1},children:["+",p]})]})}function Co({peers:t,grid:o,sheetIds:a,activeSheet:c,zoom:u,mergedRanges:p}){let s=useMemo(()=>t.slice(0,Hr),[t]),w=t.length-s.length,M=$r(s);return o?jsxs(Fragment,{children:[s.map(S=>{if(!S.cursor)return null;let z=resolveAwarenessCursor(S.cursor,a);if(!z||z.sheetIndex!==c)return null;let F=ct(z.range,p),K=rangeRect(o,F);if(!K)return null;let _=normalizeAwarenessColor(S.user.color,S.clientId),$={x:K.x*u,y:K.y*u,w:K.w*u,h:K.h*u},v=z.range.top!==z.range.bottom||z.range.left!==z.range.right,H=F.left<o.startCol,A=F.top<o.startRow||$.y<18,Q=S.cursorMovedAt>0&&M-S.cursorMovedAt<AWARENESS_LABEL_DURATION_MS;return jsx("div",{"data-testid":`xlsx-remote-selection-${S.clientId}`,style:{position:"absolute",left:$.x,top:$.y,width:$.w,height:$.h,boxSizing:"border-box",borderWidth:2,borderStyle:"solid",borderColor:_,backgroundColor:v?Nr(_):"transparent"},children:Q&&jsx("span",{"data-testid":`xlsx-remote-label-${S.clientId}`,style:{position:"absolute",top:A?0:-18,...H?{right:-2}:{left:-2},maxWidth:180,height:18,padding:"2px 6px",borderRadius:A?"0 0 3px 3px":"3px 3px 0 0",boxSizing:"border-box",overflow:"hidden",backgroundColor:_,color:"#ffffff",fontSize:10,fontWeight:600,lineHeight:"14px",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:S.user.name})},S.clientId)}),w>0&&jsxs("span",{"data-testid":"xlsx-remote-selection-overflow","aria-hidden":"true",style:{position:"absolute",left:4,top:4,padding:"2px 5px",borderWidth:1,borderStyle:"solid",borderColor:"#c7cacf",borderRadius:8,backgroundColor:"#ffffff",color:"#3c4043",fontSize:9,lineHeight:1},children:["+",w]})]}):null}var ko=["#7c3aed","#0891b2","#c2410c","#4d7c0f","#be185d","#1d4ed8"];function Ur(t){let o=2166136261;for(let a=0;a<t.length;a++)o^=t.charCodeAt(a),o=Math.imul(o,16777619);return (o>>>0)%ko.length}function To(t){return ko[Ur(t)]}function Mo({proposals:t,staleFor:o,onAccept:a,onReject:c,style:u}){let{t:p}=Se();return jsx("div",{"data-testid":"xlsx-proposals-panel",role:"region","aria-label":p("proposals.panelLabel"),style:{position:"absolute",top:"100%",right:0,marginTop:4,width:320,maxHeight:420,overflowY:"auto",background:"#ffffff",border:"1px solid #d0d0d0",borderRadius:10,boxShadow:"0 6px 24px rgba(0, 0, 0, 0.16)",padding:8,zIndex:10,font:"13px system-ui, sans-serif",textAlign:"left",...u},children:t.length===0?jsx("div",{style:{padding:12,color:"#707070",textAlign:"center"},children:p("proposals.empty")}):t.map(s=>{let w=To(s.agentId),M=o[s.id];return jsxs("div",{"data-testid":"xlsx-proposal","data-proposal-id":s.id,style:{borderLeft:`3px solid ${w}`,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:w},children:s.agentId}),jsx("span",{style:{color:"#707070",fontSize:12},children:p("proposals.cellCount",{count:s.cells.length})})]}),s.note&&jsx("div",{style:{color:"#404040",margin:"4px 0"},children:s.note}),jsx("ul",{style:{listStyle:"none",margin:"6px 0",padding:0},children:s.cells.map(S=>jsxs("li",{"data-testid":"xlsx-proposal-cell",style:{fontVariantNumeric:"tabular-nums",lineHeight:1.5},children:[jsx("strong",{"data-testid":"xlsx-proposal-cell-a1",children:S.a1}),":"," ",jsx("span",{style:{color:"#909090"},children:S.oldText||"\u2205"})," ",p("proposals.changeArrow")," ",jsx("span",{"data-testid":"xlsx-proposal-cell-new",style:{color:w},children:S.newText})]},S.a1))}),M&&M.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:p("proposals.staleWarning",{cells:M.join(", ")})}),jsxs("div",{style:{display:"flex",gap:6,marginTop:4},children:[jsx("button",{"data-testid":"xlsx-proposal-accept",onClick:()=>a(s.id),style:{padding:"3px 10px",cursor:"pointer"},children:p("proposals.accept")}),M&&M.length>0&&jsx("button",{"data-testid":"xlsx-proposal-force",onClick:()=>a(s.id,true),style:{padding:"3px 10px",cursor:"pointer",color:"#b45309"},children:p("proposals.forceApply")}),jsx("button",{"data-testid":"xlsx-proposal-reject",onClick:()=>c(s.id),style:{padding:"3px 10px",cursor:"pointer"},children:p("proposals.reject")})]})]},s.id)})})}var Ce=96,ke=24,ut="#217346",Io=87,rn=1024,nn="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";function ln(t,o,a){let c=[{op:"fillRect",x:0,y:0,w:t,h:o,color:"#ffffff"}],u=Math.ceil(t/Ce),p=Math.ceil(o/ke);for(let s=0;s<=u;s++)c.push({op:"line",x1:s*Ce,y1:0,x2:s*Ce,y2:o,width:1,color:"#e0e0e0"});for(let s=0;s<=p;s++)c.push({op:"line",x1:0,y1:s*ke,x2:t,y2:s*ke,width:1,color:"#e0e0e0"});return c.push({op:"fillRect",x:0,y:0,w:t,h:ke,color:"#f3f3f3"}),c.push({op:"fillRect",x:0,y:0,w:Ce,h:o,color:"#f3f3f3"}),c.push({op:"text",x:Ce+8,y:ke+18,text:a,fontSize:14,color:"#202020",clip:{x:Ce,y:ke,w:Ce*3,h:ke},align:"left"}),{width:t,height:o,commands:c}}function Lo(t,o){if(!t||t.length<2)return o;let a=[];for(let u=1;u<t.length;u++)a.push(t[u]-t[u-1]);a.sort((u,p)=>u-p);let c=a[a.length>>1];return c>0?c:o}function an(t,o,a){let c=Lo(t?.grid?.rowOffsets,ke),u=Lo(t?.grid?.colOffsets,Ce),p=Math.max(1,Math.round(o.contentHeight/c))+1,s=Math.max(1,Math.round(o.contentWidth/u))+1,w=Math.max(1,Math.floor(a/c));return {rows:p,cols:s,rowsPerPage:w}}function Ao(t,o,a){let c=new Blob([new Uint8Array(t)],{type:a}),u=URL.createObjectURL(c),p=document.createElement("a");p.href=u,p.download=o,document.body.appendChild(p),p.click(),p.remove(),URL.revokeObjectURL(u);}function sn(t){return `${(t??"workbook.xlsx").replace(/\.xlsx$/i,"")}.png`}function Dt(t,o){return {x:t.x*o,y:t.y*o,w:t.w*o,h:t.h*o}}var cn={position:"absolute",width:1,height:1,margin:-1,padding:0,border:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap"},ye={shell:{flex:"0 0 auto",minHeight:Io,padding:"4px 0 5px",borderBottom:"1px solid #e2e8f0",background:"#ffffff",color:"#0f172a",boxSizing:"border-box"},rail:{display:"flex",alignItems:"center",minHeight:32,margin:"0 8px",padding:"2px 8px",borderRadius:4,background:"#ffffff",boxSizing:"border-box",overflowX:"auto",overflowY:"hidden"},group:{display:"inline-flex",alignItems:"center",gap:1,padding:"0 6px",borderRight:"1px solid rgba(226, 232, 240, 0.9)",flex:"0 0 auto"},formulaGroup:{display:"flex",alignItems:"center",gap:4,flex:"1 1 320px",minWidth:240,padding:"0 6px",borderRight:"1px solid rgba(226, 232, 240, 0.9)"},nameBox:{appearance:"none",width:64,height:28,flex:"0 0 auto",boxSizing:"border-box",border:"1px solid #e2e8f0",borderRadius:6,background:"#f8fafc",color:"#0f172a",font:"600 12px ui-monospace, SFMono-Regular, Menlo, monospace",textAlign:"center",outlineColor:"#2563eb"},formulaMark:{display:"grid",placeItems:"center",width:20,height:28,flex:"0 0 auto",color:"#64748b",font:"italic 700 12px Georgia, serif",userSelect:"none"},formulaInput:{appearance:"none",flex:"1 1 260px",minWidth:140,height:28,boxSizing:"border-box",border:"1px solid #e2e8f0",borderRadius:6,padding:"0 8px",background:"#ffffff",color:"#0f172a",font:"13px ui-sans-serif, system-ui, sans-serif",outlineColor:"#2563eb"},proposals:{marginLeft:"auto",paddingLeft:6,flex:"0 0 auto"},count:{display:"inline-grid",placeItems:"center",minWidth:15,height:15,marginLeft:-3,padding:"0 4px",borderRadius:8,background:"#0f172a",color:"#ffffff",fontSize:10,fontWeight:700,lineHeight:1,boxSizing:"border-box"}};function dn({i18n:t,...o}){return jsx(at,{i18n:t,children:jsx(un,{...o})})}function un({file:t,fileName:o,onSave:a,collaboration:c,onReady:u,className:p}){let{t:s}=Se(),w=c!==void 0,M=c?.clientId,S=c?.initialUpdate,z=c?.onReplica,F=c?.provider,K=useRef(null),_=useRef(null),$=useRef(null),v=useRef(null),H=useRef(null),A=useRef(null),Q=useRef(null),C=useRef(false),Z=useRef(null),oe=useRef(false),de=useRef(false),E=useRef(u);E.current=u;let[y,re]=useState(null),[Ee,B]=useState(null),[xe,pt]=useState(null),[b,k]=useState(null),[O,me]=useState(null),[Ye,He]=useState(null),[Pe,ve]=useState(null),[he,ft]=useState(Io),[R,Be]=useState(1),[Le,Ae]=useState(0),[h,m]=useState(false),[ne,Ze]=useState({}),[zt,je]=useState({canUndo:false,canRedo:false}),[bt,qe]=useState([]),[mt,Ft]=useState([]),[ht,Ht]=useState(),[gt,Bt]=useState(),[Ie,De]=useState(null),Te=useRef(null),[Je,Qe]=useState([]),[yt,Nt]=useState(false),[xt,Wt]=useState(null),[$t,Ot]=useState([]),[Do,Ne]=useState({}),d=y?.activeSheet??0,zo=useMemo(()=>isPngExportAvailable(),[]),Ut=useMemo(()=>isProposalsAvailable(),[]);useEffect(()=>{let e=K.current;if(!e)return;let r=()=>ft(e.offsetHeight);r();let n=new ResizeObserver(r);return n.observe(e),()=>n.disconnect()},[]);let ue=useCallback(()=>{let e=v.current;if(!e){Qe([]);return}try{Qe(e.listProposals());}catch{Qe([]);}Ae(r=>r+1);},[]);useEffect(()=>{if(me(null),ve(null),Qe([]),Ne({}),Nt(false),Wt(null),Ze({}),je({canUndo:false,canRedo:false}),qe([]),Ft([]),Ht(void 0),Bt(void 0),De(null),Te.current=null,de.current=false,!t){v.current=null,re(null),k(null),B(null);return}v.current=null,re(null),k(null);let e=null,r=()=>{},n=()=>{},i=false,f=()=>{let T=n;n=()=>{};try{T();}catch{}};return initWasm().then(()=>{if(!i)try{e=openWorkbook(t,{collaborative:w,clientId:M}),S&&e.applyUpdate(S.slice()),v.current=e,r=e.onUpdate(()=>{if(!(i||!e))try{re(e.sheetInfo()),Ae(g=>g+1),Ne({}),ue(),B(null);}catch(g){B(g instanceof Error?g.message:String(g));}}),de.current=!0,re(e.sheetInfo()),k(selectionAt({row:0,col:0})),Wt(e),B(null),ue();let T=E.current?.({handle:e,refreshProposals:ue});typeof T=="function"&&(n=T);}catch(T){f(),r(),r=()=>{},e?.dispose(),e=null,v.current=null,re(null),k(null),B(T instanceof Error?T.message:String(T));}},T=>{i||(v.current=null,re(null),k(null),B(T instanceof Error?T.message:String(T)));}),()=>{i=true,f(),r(),e?.dispose(),v.current=null;}},[t,w,M,S,ue]),useEffect(()=>{if(!y||!de.current)return;let e=_.current;e&&(de.current=false,e.scrollLeft=y.initialScrollX*R,e.scrollTop=y.initialScrollY*R);},[y,R]),useEffect(()=>{if(!(!z||!xt))return z(xt),()=>z(null)},[z,xt]),useEffect(()=>{if(Ot([]),!!F)return F.onAwareness(e=>Ot([...e]))},[F]),useEffect(()=>()=>F?.setCursor(null),[F]),useEffect(()=>{if(!F)return;let e=y?.sheetIds[d];if(!b||!e){F.setCursor(null);return}F.setCursor({sheet:e,anchor:{...b.anchor},head:{...b.focus}});},[F,b,y,d,Le]);let vt=useCallback(()=>{let e=_.current,r=$.current;if(!e||!r)return;let n=r.getContext("2d");if(!n)return;let i=window.devicePixelRatio||1,f=e.clientWidth,T=e.clientHeight;if(f===0||T===0)return;r.width=Math.round(f*i),r.height=Math.round(T*i),r.style.width=`${f}px`,r.style.height=`${T}px`;let g=f/R,q=T/R,X=v.current,ee;if(X)try{ee=X.displayList({x:e.scrollLeft/R,y:e.scrollTop/R,width:g,height:q});}catch{return}else ee=ln(g,q,s("editor.demoCellText"));let Jt=[],Re=ee.grid,Qt=(Re?.rowOffsets.length??0)-1,eo=(Re?.colOffsets.length??0)-1;if(X&&Re&&Qt>0&&eo>0)try{let tr=X.cell(d,Re.startRow,Re.startCol).a1,or=X.cell(d,Re.startRow+Qt-1,Re.startCol+eo-1).a1;Jt=X.mergedRanges(d,`${tr}:${or}`).slice(0,rn);}catch{}paintDisplayList(n,ee,i*R),H.current=ee,Ft(Jt),pt(ee);},[d,s,R]);useEffect(()=>{let e=_.current;if(!e)return;let r=()=>{A.current==null&&(A.current=requestAnimationFrame(()=>{A.current=null,vt();}));};vt(),e.addEventListener("scroll",r,{passive:true});let n=new ResizeObserver(r);return n.observe(e),()=>{e.removeEventListener("scroll",r),n.disconnect(),A.current!=null&&(cancelAnimationFrame(A.current),A.current=null);}},[vt,y,Ee,Le]),useEffect(()=>{let e=v.current;if(!e||!b||!y){He(null);return}try{He(e.cell(d,b.focus.row,b.focus.col));}catch{He(null);}},[b,y,d,Le]),useEffect(()=>{let e=()=>{C.current=false,m(false);};return window.addEventListener("mouseup",e),()=>window.removeEventListener("mouseup",e)},[]),useEffect(()=>{let e=v.current;if(!e||!b||!y){Ze({}),je({canUndo:false,canRedo:false}),qe([]);return}let r=normalizeRange(b);try{let n=e.cell(d,r.top,r.left).a1,i=e.cell(d,r.bottom,r.right).a1,f=`${n}:${i}`;Ze(e.selectionFormatting(d,f)),je(e.historyState()),qe(e.mergedRanges(d,f));}catch{Ze({}),je({canUndo:false,canRedo:false}),qe([]);}},[b,y,d,Le]);let et=useMemo(()=>!xe||!y?null:buildA11yGrid(xe,b,y.sheetNames[d]??"",{gridLabel:s("a11y.gridLabel"),rowHeaderLabel:s("a11y.rowHeaderLabel"),columnHeaderLabel:s("a11y.columnHeaderLabel"),cellLabel:s("a11y.cellLabel"),cellLabelSelected:s("a11y.cellLabelSelected"),emptyCellLabel:s("a11y.emptyCellLabel"),emptyCellLabelSelected:s("a11y.emptyCellLabelSelected")}),[xe,b,y,d,s]),j=useCallback(()=>{_.current?.focus({preventScroll:true});},[]);useEffect(()=>{O&&Q.current?.focus({preventScroll:true});},[O]);let G=useCallback(e=>{re(e.sheetInfo),Ae(r=>r+1),ue();},[ue]),tt=useCallback(e=>{let r=v.current;if(!r)return null;let n=normalizeRange(e),i=r.cell(d,n.top,n.left).a1,f=r.cell(d,n.bottom,n.right).a1;return `${i}:${f}`},[d]),pe=useCallback(()=>an(H.current,y,(_.current?.clientHeight??0)/R),[y,R]),we=useCallback((e,r)=>{let n=$.current,i=H.current?.grid;if(!n||!i)return null;let f=n.getBoundingClientRect();return cellAtPoint(i,(e-f.left)/R,(r-f.top)/R)},[R]),ot=useCallback(e=>{let r=v.current;if(!r||!b)return;let{row:n,col:i}=b.focus,f=e??"";if(e===void 0)try{f=r.cell(d,n,i).input;}catch{f="";}me({row:n,col:i,value:f});},[b,d]),wt=useCallback(e=>{let r=v.current;if(!r||!O)return;oe.current=true;let{row:n,col:i,value:f}=O;try{G(r.editCell(d,n,i,f));}catch(g){B(g instanceof Error?g.message:String(g));}me(null);let T=selectionAt({row:n,col:i});k(e?moveFocus(T,e,{limits:pe()}):T),j();},[O,d,G,pe,j]),Fo=useCallback(()=>{oe.current=true,me(null),j();},[j]),rt=useCallback(()=>{let e=v.current;if(!e||!b)return;let r=normalizeRange(b),n=[];for(let i=r.top;i<=r.bottom;i++)for(let f=r.left;f<=r.right;f++)n.push({row:i,col:f,input:""});try{G(e.editCells(d,n));}catch(i){B(i instanceof Error?i.message:String(i));}},[b,d,G]),nt=useCallback(async()=>{let e=v.current;if(!e||!b)return;let r=normalizeRange(b);try{let n=e.cell(d,r.top,r.left).a1,i=e.cell(d,r.bottom,r.right).a1,f=e.rangeCells(d,`${n}:${i}`),T=toTsv(f.map(g=>g.map(q=>({input:q.input,isFormula:q.isFormula}))));await navigator.clipboard.writeText(T);}catch{}},[b,d]),Gt=useCallback(async()=>{await nt(),rt();},[nt,rt]),_t=useCallback(async()=>{let e=v.current;if(!e||!b)return;let r;try{r=await navigator.clipboard.readText();}catch{return}let n=fromTsv(r);if(n.length===0)return;let i=normalizeRange(b),f=[],T=1;n.forEach((g,q)=>{T=Math.max(T,g.length),g.forEach((X,ee)=>f.push({row:i.top+q,col:i.left+ee,input:X}));});try{G(e.editCells(d,f));}catch(g){B(g instanceof Error?g.message:String(g));return}k({anchor:{row:i.top,col:i.left},focus:{row:i.top+n.length-1,col:i.left+T-1}});},[b,d,G]),Ho=useCallback(e=>{let r=v.current;if(!r||!b)return;let n=tt(b);if(n){if(e==="paintFormat"){if(Ie){De(null),Te.current=null;return}try{De(r.captureFormat(d,n));let i=normalizeRange(b);Te.current=`${d}:${i.top}:${i.left}:${i.bottom}:${i.right}`;}catch(i){B(i instanceof Error?i.message:String(i));}return}try{let i;e==="currency"?i=r.setNumberFormat(d,n,"currency"):e==="percent"?i=r.setNumberFormat(d,n,"percent"):e==="increaseDecimal"?i=r.setNumberFormat(d,n,"increaseDecimal"):e==="decreaseDecimal"?i=r.setNumberFormat(d,n,"decreaseDecimal"):e==="bold"?i=r.patchRangeStyle(d,n,{bold:!ne.bold}):e==="italic"?i=r.patchRangeStyle(d,n,{italic:!ne.italic}):e==="strikethrough"?i=r.patchRangeStyle(d,n,{strikethrough:!ne.strikethrough}):e.type==="numberFormat"?i=e.value==="custom"?r.setNumberFormat(d,n,{type:"custom",pattern:ne.numberFormatPattern??"0.00"}):r.setNumberFormat(d,n,e.value):e.type==="fontFamily"?i=r.patchRangeStyle(d,n,{fontFamily:e.value}):e.type==="fontSize"?i=r.patchRangeStyle(d,n,{fontSize:e.value}):e.type==="textColor"?i=r.patchRangeStyle(d,n,{textColor:e.value}):e.type==="fillColor"?i=r.patchRangeStyle(d,n,{fillColor:e.value}):e.type==="borderPreset"?i=r.patchRangeStyle(d,n,{border:{preset:e.value,style:ht??ne.borderStyle??"solid",color:gt??ne.borderColor??"#000000"}}):e.type==="borderStyle"?(Ht(e.value),i=r.patchRangeStyle(d,n,{border:{style:e.value}})):e.type==="borderColor"?(Bt(e.value),i=r.patchRangeStyle(d,n,{border:{color:e.value}})):e.type==="horizontalAlignment"?i=r.patchRangeStyle(d,n,{horizontalAlignment:e.value}):e.type==="verticalAlignment"?i=r.patchRangeStyle(d,n,{verticalAlignment:e.value}):i=r.patchRangeStyle(d,n,{textWrapping:e.value}),G(i),j();}catch(i){B(i instanceof Error?i.message:String(i));}}},[b,tt,Ie,d,ne,ht,gt,G,j]);useEffect(()=>{let e=v.current;if(!e||!b||!Ie||h)return;let r=normalizeRange(b);if(`${d}:${r.top}:${r.left}:${r.bottom}:${r.right}`===Te.current)return;let i=tt(b);if(i)try{G(e.applyFormat(d,i,Ie)),De(null),Te.current=null,j();}catch(f){B(f instanceof Error?f.message:String(f));}},[b,Ie,h,d,tt,G,j]);let St=useCallback(()=>{let e=v.current;if(e)try{G(e.undo());}catch(r){B(r instanceof Error?r.message:String(r));}},[G]),lt=useCallback(()=>{let e=v.current;if(e)try{G(e.redo());}catch(r){B(r instanceof Error?r.message:String(r));}},[G]),Bo=useCallback(()=>window.print(),[]),No=useCallback(()=>{},[]),Wo=useCallback(e=>{let r=v.current;if(!r||!b)return;let n=normalizeRange(b),i=(g,q)=>({row:g,col:q}),f=(g,q,X,ee)=>({start:i(g,q),end:i(X,ee)}),T=[];if(e==="all")T.push({type:"mergeCells",sheet:d,range:f(n.top,n.left,n.bottom,n.right)});else if(e==="horizontal")for(let g=n.top;g<=n.bottom;g++)T.push({type:"mergeCells",sheet:d,range:f(g,n.left,g,n.right)});else if(e==="vertical")for(let g=n.left;g<=n.right;g++)T.push({type:"mergeCells",sheet:d,range:f(n.top,g,n.bottom,g)});else for(let g of bt)T.push({type:"unmergeCells",sheet:d,range:f(g.start.row,g.start.col,g.end.row,g.end.col)});if(T.length!==0)try{G(r.applyOps(T)),j();}catch(g){B(g instanceof Error?g.message:String(g));}},[b,d,bt,G,j]),$o=useCallback((e,r)=>{let n=v.current;if(n)try{G(n.acceptProposal(e,{force:r})),Ne(({[e]:i,...f})=>f),ue(),j();}catch(i){i instanceof StaleProposalError?Ne(f=>({...f,[e]:i.cells})):B(i instanceof Error?i.message:String(i));}},[G,ue,j]),Oo=useCallback(e=>{let r=v.current;if(r)try{r.rejectProposal(e),Ne(({[e]:n,...i})=>i),ue();}catch(n){B(n instanceof Error?n.message:String(n));}},[ue]),Ct=useCallback(()=>{let e=v.current;if(e)try{let r=e.save();a?a(r):Ao(r,o??"workbook.xlsx",nn);}catch(r){B(r instanceof Error?r.message:String(r));}},[a,o]),Uo=useCallback(()=>{let e=v.current,r=_.current;if(!(!e||!r))try{let n=e.renderPng({x:r.scrollLeft/R,y:r.scrollTop/R,width:r.clientWidth/R,height:r.clientHeight/R});Ao(n,sn(o),"image/png");}catch(n){B(n instanceof Error?n.message:String(n));}},[o,R]),Xt=useCallback(e=>{let r=v.current;if(!r||!b||Pe==null)return;let{row:n,col:i}=b.focus;try{G(r.editCell(d,n,i,Pe));}catch(f){B(f instanceof Error?f.message:String(f));}ve(null),e&&k(f=>f&&moveFocus(f,e,{limits:pe()}));},[b,Pe,d,G,pe]),Go=useCallback(e=>{if(!v.current||!b||!y||O)return;let n=e.metaKey||e.ctrlKey,i=e.key.toLowerCase();if(n){if(i==="c"){nt(),e.preventDefault();return}if(i==="v"){_t(),e.preventDefault();return}if(i==="x"){Gt(),e.preventDefault();return}if(i==="z"){e.shiftKey?lt():St(),e.preventDefault();return}if(i==="y"){lt(),e.preventDefault();return}if(i==="s"){Ct(),e.preventDefault();return}}let f=selectionKeyReducer(b,{key:e.key,shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey},pe());switch(f.type){case "move":k(f.selection),e.preventDefault();break;case "startEdit":ot(f.initialInput),e.preventDefault();break;case "clear":rt(),e.preventDefault();break;}},[b,y,O,pe,nt,_t,Gt,St,lt,Ct,ot,rt]),_o=useCallback(e=>{if(!b||O)return;let r=we(e.clientX,e.clientY);r&&(e.shiftKey?k(n=>n&&extendTo(n,r,pe())):k(selectionAt(r)),Z.current=r,C.current=true,m(true),j());},[O,b,we,pe,j]),Xo=useCallback(e=>{let r=we(e.clientX,e.clientY);if(!r){C.current||(e.currentTarget.style.cursor="default",e.currentTarget.title="");return}if(!C.current){let n=H.current?hyperlinkAtCell(H.current,r.row,r.col):null;e.currentTarget.style.cursor=n?"pointer":"default",e.currentTarget.title=n?.tooltip??"";return}k(n=>n&&extendTo(n,r,pe()));},[we,pe]),Kt=useCallback(e=>{let r=v.current,n=H.current;if(!r||!n||!y)return false;let i=hyperlinkAtCell(n,e.row,e.col);if(!i)return false;let f=safeExternalHyperlink(i);if(f)return window.open(f,"_blank","noopener,noreferrer"),true;if(!i.location)return true;let T=y.sheetNames[d]??"",g=parseHyperlinkLocation(i.location,T);if(!g)return true;let q=y.sheetNames.findIndex(X=>X.toLowerCase()===g.sheetName.toLowerCase());if(q<0)return true;try{r.setActiveSheet(q);let X=r.cellPosition(q,g.row,g.col);re(r.sheetInfo()),requestAnimationFrame(()=>{let ee=_.current;ee&&(ee.scrollLeft=X.x*R,ee.scrollTop=X.y*R);}),k(selectionAt({row:g.row,col:g.col})),me(null),ve(null),De(null),Te.current=null,B(null);}catch(X){B(X instanceof Error?X.message:String(X));}return true},[d,y,R]),Ko=useCallback(e=>{if(O){Z.current=null;return}let r=we(e.clientX,e.clientY),n=Z.current;Z.current=null,!(!r||!n||r.row!==n.row||r.col!==n.col)&&Kt(r);},[Kt,O,we]),Vo=useCallback(e=>{if(O)return;let r=we(e.clientX,e.clientY);r&&H.current&&hyperlinkAtCell(H.current,r.row,r.col)||b&&ot();},[O,ot,we,b]),Yo=useCallback(e=>{e.currentTarget.style.cursor="default",e.currentTarget.title="";},[]),Me=xe?.grid,Vt=b?ct(normalizeRange(b),mt):null,Yt=b?ct({top:b.focus.row,left:b.focus.col,bottom:b.focus.row,right:b.focus.col},mt):null,Zt=Me&&Vt?rangeRect(Me,Vt):null,jt=Me&&Yt?rangeRect(Me,Yt):null,qt=Me&&O?cellRect(Me,O.row,O.col):null,We=Zt?Dt(Zt,R):null,$e=jt?Dt(jt,R):null,Oe=qt?Dt(qt,R):null,Zo=y?y.contentWidth*R:void 0,jo=y?y.contentHeight*R:void 0,qo=Pe??Ye?.input??"",ze=b?normalizeRange(b):null,Jo=ze?ze.bottom-ze.top+1:1,Qo=ze?ze.right-ze.left+1:1,er=e=>{let r=v.current;if(r)try{r.setActiveSheet(e),de.current=!0,k(selectionAt({row:0,col:0})),me(null),ve(null),De(null),Te.current=null,re(r.sheetInfo());}catch(n){B(n instanceof Error?n.message:String(n));}};return jsxs("div",{className:p,role:"application","aria-label":s("editor.appLabel"),style:{position:"relative",display:"flex",flexDirection:"column",width:"100%",height:"100%",minWidth:0,color:"#202124",background:"#ffffff",fontFamily:"ui-sans-serif, system-ui, sans-serif"},children:[jsx("div",{ref:K,"data-testid":"xlsx-toolbar",style:ye.shell,children:jsxs(Ke,{currentFormatting:{...ne,borderStyle:ht??ne.borderStyle,borderColor:gt??ne.borderColor,paintFormat:Ie!==null},selectionShape:{rows:Jo,columns:Qo,canUnmerge:bt.length>0},onSearchMenus:No,onUndo:St,onRedo:lt,canUndo:zt.canUndo,canRedo:zt.canRedo,onPrint:Bo,zoom:R,onZoomChange:Be,onFormat:Ho,onMerge:Wo,children:[jsx(Ke.Toolbar,{}),jsxs("div",{style:ye.rail,role:"group","aria-label":s("toolbar.formulaBarLabel"),children:[jsxs(Y,{style:{...ye.group,paddingLeft:0},label:s("toolbar.fileActionsLabel"),children:[jsx(U,{testId:"xlsx-save",onClick:Ct,disabled:!y,title:s("toolbar.save"),children:jsx(L,{name:"save",size:18})}),jsx(U,{testId:"xlsx-export-png",onClick:Uo,disabled:!y||!zo,title:s("toolbar.exportPng"),children:jsx(L,{name:"image",size:18})})]}),jsxs("div",{style:ye.formulaGroup,role:"group","aria-label":s("toolbar.formulaBarLabel"),children:[jsx("input",{"data-testid":"xlsx-name-box",readOnly:true,value:Ye?.a1??"",placeholder:s("toolbar.nameBoxPlaceholder"),"aria-label":s("toolbar.nameBoxPlaceholder"),style:ye.nameBox}),jsx("span",{style:ye.formulaMark,"aria-hidden":"true",children:"fx"}),jsx("input",{"data-testid":"xlsx-formula-input",value:qo,placeholder:s("toolbar.formulaPlaceholder"),"aria-label":s("toolbar.formulaPlaceholder"),disabled:!y,onChange:e=>ve(e.target.value),onKeyDown:e=>{e.key==="Enter"?(Xt(e.shiftKey?"up":"down"),j(),e.preventDefault()):e.key==="Escape"&&(ve(null),j(),e.preventDefault());},onBlur:()=>Xt(),style:ye.formulaInput})]}),jsx(So,{peers:$t,sheetIds:y?.sheetIds??[],sheetNames:y?.sheetNames??[],activeSheet:d}),Ut&&jsx("div",{style:ye.proposals,children:jsxs(U,{testId:"xlsx-proposals-button",onClick:()=>Nt(e=>!e),disabled:!y,active:yt,ariaExpanded:yt,title:s("proposals.panelLabel"),style:{width:Je.length>0?42:28},children:[jsx(L,{name:"proposals",size:18}),Je.length>0&&jsx("span",{"data-testid":"xlsx-proposals-count",style:ye.count,children:Je.length})]})})]})]})}),Ut&&yt&&jsx(Mo,{proposals:Je,staleFor:Do,onAccept:$o,onReject:Oo,style:{top:he+4,right:8,width:"min(320px, calc(100% - 16px))",maxHeight:`min(420px, calc(100% - ${he+12}px))`}}),jsxs("div",{ref:_,"data-testid":"xlsx-scroll",tabIndex:0,onKeyDown:Go,onMouseDown:_o,onMouseMove:Xo,onMouseLeave:Yo,onClick:Ko,onDoubleClick:Vo,style:{position:"relative",flex:1,overflow:"auto",minHeight:0,outline:"none"},children:[jsx("div",{style:{position:"absolute",top:0,left:0,width:Zo??"100%",height:jo??"100%"}}),jsxs("div",{style:{position:"sticky",top:0,left:0,width:0,height:0},children:[jsx("canvas",{ref:$,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:[We&&jsx("div",{"data-testid":"xlsx-selection",style:{position:"absolute",left:We.x,top:We.y,width:We.w,height:We.h,boxSizing:"border-box",border:`1px solid ${ut}`,background:"rgba(33, 115, 70, 0.12)"}}),$e&&!O&&jsx("div",{style:{position:"absolute",left:$e.x,top:$e.y,width:$e.w,height:$e.h,boxSizing:"border-box",border:`2px solid ${ut}`}}),jsx(Co,{peers:$t,grid:Me,sheetIds:y?.sheetIds??[],activeSheet:d,zoom:R,mergedRanges:mt}),O&&Oe&&jsx("input",{ref:Q,"data-testid":"xlsx-cell-editor",value:O.value,onChange:e=>me(r=>r&&{...r,value:e.target.value}),onKeyDown:e=>{e.stopPropagation(),e.key==="Enter"?(wt(e.shiftKey?"up":"down"),e.preventDefault()):e.key==="Tab"?(wt(e.shiftKey?"left":"right"),e.preventDefault()):e.key==="Escape"&&(Fo(),e.preventDefault());},onBlur:()=>{if(oe.current){oe.current=false;return}wt();},style:{position:"absolute",left:Oe.x,top:Oe.y,width:Oe.w,height:Oe.h,boxSizing:"border-box",border:`2px solid ${ut}`,padding:"0 3px",font:`${13*R}px system-ui, sans-serif`,background:"#ffffff",pointerEvents:"auto",outline:"none"}})]})]})]}),et&&jsxs("div",{style:cn,role:"grid","aria-label":et.label,children:[jsxs("div",{role:"row",children:[jsx("span",{role:"columnheader"}),et.columnHeaders.map(e=>jsx("span",{role:"columnheader",children:e.label},e.col))]}),et.rows.map(e=>jsxs("div",{role:"row",children:[jsx("span",{role:"rowheader",children:e.header}),e.cells.map(r=>jsx("span",{role:"gridcell","aria-selected":r.selected,children:r.label},r.col))]},e.row))]}),Ee&&jsxs("div",{"data-testid":"xlsx-error",role:"alert",style:{position:"absolute",inset:0,display:"grid",placeItems:"center",padding:16,textAlign:"center",color:"#b00020"},children:[s("editor.openError"),": ",Ee]}),y&&y.sheetNames.length>0&&jsx("div",{"data-testid":"xlsx-sheet-tabs",role:"tablist","aria-label":s("editor.sheetTabsLabel"),style:{display:"flex",gap:2,padding:"4px 6px",borderTop:"1px solid #e0e0e0",background:"#fafafa",overflowX:"auto"},children:y.sheetNames.map((e,r)=>{let n=r===y.activeSheet;return jsx("button",{role:"tab","aria-selected":n,onClick:()=>er(r),style:{border:"none",padding:"4px 12px",cursor:"pointer",borderBottom:n?`2px solid ${ut}`:"2px solid transparent",fontWeight:n?600:400,background:n?"#ffffff":"transparent"},children:e},r)})})]})}export{Ke as EditorToolbar,Fe as EditorToolbarContext,at as LocaleProvider,it as Toolbar,U as ToolbarButton,fe as ToolbarDropdown,Y as ToolbarGroup,le as ToolbarMenuItem,_e as ToolbarMenuSeparator,Ge as ToolbarSeparator,dn as XlsxEditor,it as XlsxToolbar,ir as useEditorToolbar,Se as useTranslation};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betteroffice/xlsx-react",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Excel-faithful React XLSX spreadsheet editor and viewer — full OOXML fidelity, real-time human + AI agent collaboration.",
5
5
  "keywords": [
6
6
  "xlsx",
@@ -33,14 +33,17 @@
33
33
  "typecheck": "tsc --noEmit -p ."
34
34
  },
35
35
  "dependencies": {
36
- "@betteroffice/xlsx": "0.0.7",
37
- "@betteroffice/xlsx-i18n": "0.0.7"
36
+ "@betteroffice/xlsx": "0.0.8",
37
+ "@betteroffice/xlsx-i18n": "0.0.8"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "react": "^18.0.0 || ^19.0.0",
41
41
  "react-dom": "^18.0.0 || ^19.0.0"
42
42
  },
43
43
  "devDependencies": {
44
+ "@happy-dom/global-registrator": "^20.8.3",
45
+ "@testing-library/react": "^16.0.0",
46
+ "@types/bun": "^1.3.14",
44
47
  "@types/react": "^19.2.17",
45
48
  "@types/react-dom": "^19.2.3",
46
49
  "react": "^19.2.7",