@betteroffice/xlsx-react 0.0.6 → 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 +75 -25
- package/dist/index.d.ts +142 -3
- package/dist/index.js +1 -1
- package/package.json +6 -3
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
|
|
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
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
`
|
|
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
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
import { ReactNode } from 'react';
|
|
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}.
|
|
@@ -48,6 +50,143 @@ interface XlsxEditorProps {
|
|
|
48
50
|
*/
|
|
49
51
|
declare function XlsxEditor({ i18n, ...props }: XlsxEditorProps): react.JSX.Element;
|
|
50
52
|
|
|
53
|
+
type NumberFormat = 'automatic' | 'plainText' | 'number' | 'percent' | 'scientific' | 'currency' | 'date' | 'time' | 'custom';
|
|
54
|
+
type BorderPreset = 'all' | 'inner' | 'horizontal' | 'vertical' | 'outer' | 'left' | 'top' | 'right' | 'bottom' | 'none';
|
|
55
|
+
type BorderStyle = 'solid' | 'dashed' | 'dotted' | 'double';
|
|
56
|
+
type HorizontalAlignment = 'left' | 'center' | 'right';
|
|
57
|
+
type VerticalAlignment = 'top' | 'middle' | 'bottom';
|
|
58
|
+
type TextWrapping = 'overflow' | 'wrap' | 'clip';
|
|
59
|
+
type MergeAction = 'all' | 'horizontal' | 'vertical' | 'unmerge';
|
|
60
|
+
interface SelectionFormatting {
|
|
61
|
+
paintFormat?: boolean;
|
|
62
|
+
numberFormat?: NumberFormat;
|
|
63
|
+
numberFormatPattern?: string;
|
|
64
|
+
fontFamily?: string;
|
|
65
|
+
fontSize?: number;
|
|
66
|
+
bold?: boolean;
|
|
67
|
+
italic?: boolean;
|
|
68
|
+
strikethrough?: boolean;
|
|
69
|
+
textColor?: string;
|
|
70
|
+
fillColor?: string;
|
|
71
|
+
borderPreset?: BorderPreset;
|
|
72
|
+
borderStyle?: BorderStyle;
|
|
73
|
+
borderColor?: string;
|
|
74
|
+
horizontalAlignment?: HorizontalAlignment;
|
|
75
|
+
verticalAlignment?: VerticalAlignment;
|
|
76
|
+
textWrapping?: TextWrapping;
|
|
77
|
+
}
|
|
78
|
+
type FormattingAction = 'paintFormat' | 'currency' | 'percent' | 'decreaseDecimal' | 'increaseDecimal' | 'bold' | 'italic' | 'strikethrough' | {
|
|
79
|
+
type: 'numberFormat';
|
|
80
|
+
value: NumberFormat;
|
|
81
|
+
} | {
|
|
82
|
+
type: 'fontFamily';
|
|
83
|
+
value: string;
|
|
84
|
+
} | {
|
|
85
|
+
type: 'fontSize';
|
|
86
|
+
value: number;
|
|
87
|
+
} | {
|
|
88
|
+
type: 'textColor';
|
|
89
|
+
value: string;
|
|
90
|
+
} | {
|
|
91
|
+
type: 'fillColor';
|
|
92
|
+
value: string;
|
|
93
|
+
} | {
|
|
94
|
+
type: 'borderPreset';
|
|
95
|
+
value: BorderPreset;
|
|
96
|
+
} | {
|
|
97
|
+
type: 'borderStyle';
|
|
98
|
+
value: BorderStyle;
|
|
99
|
+
} | {
|
|
100
|
+
type: 'borderColor';
|
|
101
|
+
value: string;
|
|
102
|
+
} | {
|
|
103
|
+
type: 'horizontalAlignment';
|
|
104
|
+
value: HorizontalAlignment;
|
|
105
|
+
} | {
|
|
106
|
+
type: 'verticalAlignment';
|
|
107
|
+
value: VerticalAlignment;
|
|
108
|
+
} | {
|
|
109
|
+
type: 'textWrapping';
|
|
110
|
+
value: TextWrapping;
|
|
111
|
+
};
|
|
112
|
+
interface SelectionShape {
|
|
113
|
+
rows: number;
|
|
114
|
+
columns: number;
|
|
115
|
+
canUnmerge?: boolean;
|
|
116
|
+
}
|
|
117
|
+
interface ToolbarProps {
|
|
118
|
+
currentFormatting?: SelectionFormatting;
|
|
119
|
+
selectionShape?: SelectionShape;
|
|
120
|
+
onFormat?: (action: FormattingAction) => void;
|
|
121
|
+
onMerge?: (action: MergeAction) => void;
|
|
122
|
+
onSearchMenus?: () => void;
|
|
123
|
+
onUndo?: () => void;
|
|
124
|
+
onRedo?: () => void;
|
|
125
|
+
canUndo?: boolean;
|
|
126
|
+
canRedo?: boolean;
|
|
127
|
+
onPrint?: () => void;
|
|
128
|
+
zoom?: number;
|
|
129
|
+
onZoomChange?: (zoom: number) => void;
|
|
130
|
+
fontFamilies?: readonly string[];
|
|
131
|
+
fontSizes?: readonly number[];
|
|
132
|
+
disabled?: boolean;
|
|
133
|
+
className?: string;
|
|
134
|
+
style?: CSSProperties;
|
|
135
|
+
children?: ReactNode;
|
|
136
|
+
}
|
|
137
|
+
declare function Toolbar(explicitProps: ToolbarProps): react.JSX.Element;
|
|
138
|
+
|
|
139
|
+
type EditorToolbarProps = ToolbarProps;
|
|
140
|
+
declare const EditorToolbarContext: react.Context<ToolbarProps | null>;
|
|
141
|
+
declare function useEditorToolbar(): ToolbarProps;
|
|
142
|
+
|
|
143
|
+
interface EditorToolbarComponent {
|
|
144
|
+
(props: EditorToolbarProps & {
|
|
145
|
+
children: ReactNode;
|
|
146
|
+
}): React.JSX.Element;
|
|
147
|
+
Toolbar: typeof Toolbar;
|
|
148
|
+
}
|
|
149
|
+
declare const EditorToolbar: EditorToolbarComponent;
|
|
150
|
+
|
|
151
|
+
interface ToolbarButtonProps {
|
|
152
|
+
active?: boolean;
|
|
153
|
+
disabled?: boolean;
|
|
154
|
+
title: string;
|
|
155
|
+
onClick?: () => void;
|
|
156
|
+
children: ReactNode;
|
|
157
|
+
style?: CSSProperties;
|
|
158
|
+
testId?: string;
|
|
159
|
+
ariaExpanded?: boolean;
|
|
160
|
+
}
|
|
161
|
+
declare function ToolbarButton({ active, disabled, title, onClick, children, style, testId, ariaExpanded, }: ToolbarButtonProps): react.JSX.Element;
|
|
162
|
+
declare function ToolbarGroup({ label, children, style, }: {
|
|
163
|
+
label: string;
|
|
164
|
+
children: ReactNode;
|
|
165
|
+
style?: CSSProperties;
|
|
166
|
+
}): react.JSX.Element;
|
|
167
|
+
declare function ToolbarSeparator(): react.JSX.Element;
|
|
168
|
+
interface ToolbarDropdownProps {
|
|
169
|
+
title: string;
|
|
170
|
+
trigger: ReactNode;
|
|
171
|
+
children: (close: () => void) => ReactNode;
|
|
172
|
+
disabled?: boolean;
|
|
173
|
+
active?: boolean;
|
|
174
|
+
menuWidth?: number;
|
|
175
|
+
style?: CSSProperties;
|
|
176
|
+
testId?: string;
|
|
177
|
+
}
|
|
178
|
+
declare function ToolbarDropdown({ title, trigger, children, disabled, active, menuWidth, style, testId, }: ToolbarDropdownProps): react.JSX.Element;
|
|
179
|
+
interface ToolbarMenuItemProps {
|
|
180
|
+
label: string;
|
|
181
|
+
icon?: ReactNode;
|
|
182
|
+
selected?: boolean;
|
|
183
|
+
disabled?: boolean;
|
|
184
|
+
onClick?: () => void;
|
|
185
|
+
close?: () => void;
|
|
186
|
+
}
|
|
187
|
+
declare function ToolbarMenuItem({ label, icon, selected, disabled, onClick, close, }: ToolbarMenuItemProps): react.JSX.Element;
|
|
188
|
+
declare function ToolbarMenuSeparator(): react.JSX.Element;
|
|
189
|
+
|
|
51
190
|
interface LocaleProviderProps {
|
|
52
191
|
i18n?: Translations;
|
|
53
192
|
children: ReactNode;
|
|
@@ -57,4 +196,4 @@ declare function useTranslation(): {
|
|
|
57
196
|
t: TFunction;
|
|
58
197
|
};
|
|
59
198
|
|
|
60
|
-
export { LocaleProvider, type LocaleProviderProps, XlsxEditor, type XlsxEditorApi, type XlsxEditorCollaborationOptions, type XlsxEditorProps, useTranslation };
|
|
199
|
+
export { type BorderPreset, type BorderStyle, EditorToolbar, EditorToolbarContext, type EditorToolbarProps, type FormattingAction, type HorizontalAlignment, LocaleProvider, type LocaleProviderProps, type MergeAction, type NumberFormat, type SelectionFormatting, type SelectionShape, type TextWrapping, Toolbar, ToolbarButton, ToolbarDropdown, ToolbarGroup, ToolbarMenuItem, ToolbarMenuSeparator, type ToolbarProps, ToolbarSeparator, type VerticalAlignment, XlsxEditor, type XlsxEditorApi, type XlsxEditorCollaborationOptions, type XlsxEditorProps, Toolbar as XlsxToolbar, useEditorToolbar, useTranslation };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {createContext,useMemo,useContext,useRef,useState,useEffect,useCallback}from'react';import {isPngExportAvailable,isProposalsAvailable,initWasm,openWorkbook,selectionAt,paintDisplayList,buildA11yGrid,cellAtPoint,moveFocus,normalizeRange,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 Ye=createContext(en),Ve=createContext("en");function de({i18n:r,children:i}){let u=typeof r?._lang=="string"?r._lang:"en",f=useMemo(()=>deepMerge(en,r),[r]);return jsx(Ve.Provider,{value:u,children:jsx(Ye.Provider,{value:f,children:i})})}function N(){let r=useContext(Ye),i=useContext(Ve);return {t:useMemo(()=>createT(r,i),[r,i])}}function qe({rect:r,color:i,newText:u,agentId:f}){return jsxs("div",{"data-testid":"xlsx-proposal-decoration","aria-hidden":"true",style:{position:"absolute",left:r.x,top:r.y,width:r.w,height:r.h,boxSizing:"border-box",border:`1.5px dashed ${i}`,pointerEvents:"none",overflow:"hidden"},children:[jsx("span",{style:{position:"absolute",left:0,right:0,bottom:1,textAlign:"center",opacity:.6,color:i,font:"11px system-ui, sans-serif",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",padding:"0 2px"},children:u}),jsx("span",{title:`${f}: ${u}`,style:{position:"absolute",top:0,right:0,width:6,height:6,background:i,pointerEvents:"auto"}})]})}var Je=["#7c3aed","#0891b2","#c2410c","#4d7c0f","#be185d","#1d4ed8"];function Pt(r){let i=2166136261;for(let u=0;u<r.length;u++)i^=r.charCodeAt(u),i=Math.imul(i,16777619);return (i>>>0)%Je.length}function ue(r){return Je[Pt(r)]}function Qe({proposals:r,staleFor:i,onAccept:u,onReject:f,style:y}){let{t:x}=N();return jsx("div",{"data-testid":"xlsx-proposals-panel",role:"region","aria-label":x("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",...y},children:r.length===0?jsx("div",{style:{padding:12,color:"#707070",textAlign:"center"},children:x("proposals.empty")}):r.map(n=>{let w=ue(n.agentId),H=i[n.id];return jsxs("div",{"data-testid":"xlsx-proposal","data-proposal-id":n.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:n.agentId}),jsx("span",{style:{color:"#707070",fontSize:12},children:x("proposals.cellCount",{count:n.cells.length})})]}),n.note&&jsx("div",{style:{color:"#404040",margin:"4px 0"},children:n.note}),jsx("ul",{style:{listStyle:"none",margin:"6px 0",padding:0},children:n.cells.map(A=>jsxs("li",{"data-testid":"xlsx-proposal-cell",style:{fontVariantNumeric:"tabular-nums",lineHeight:1.5},children:[jsx("strong",{"data-testid":"xlsx-proposal-cell-a1",children:A.a1}),":"," ",jsx("span",{style:{color:"#909090"},children:A.oldText||"\u2205"})," ",x("proposals.changeArrow")," ",jsx("span",{"data-testid":"xlsx-proposal-cell-new",style:{color:w},children:A.newText})]},A.a1))}),H&&H.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:x("proposals.staleWarning",{cells:H.join(", ")})}),jsxs("div",{style:{display:"flex",gap:6,marginTop:4},children:[jsx("button",{"data-testid":"xlsx-proposal-accept",onClick:()=>u(n.id),style:{padding:"3px 10px",cursor:"pointer"},children:x("proposals.accept")}),H&&H.length>0&&jsx("button",{"data-testid":"xlsx-proposal-force",onClick:()=>u(n.id,true),style:{padding:"3px 10px",cursor:"pointer",color:"#b45309"},children:x("proposals.forceApply")}),jsx("button",{"data-testid":"xlsx-proposal-reject",onClick:()=>f(n.id),style:{padding:"3px 10px",cursor:"pointer"},children:x("proposals.reject")})]})]},n.id)})})}var K=96,O=24,be="#217346",lt=46,Ot="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";function zt(r,i,u){let f=[{op:"fillRect",x:0,y:0,w:r,h:i,color:"#ffffff"}],y=Math.ceil(r/K),x=Math.ceil(i/O);for(let n=0;n<=y;n++)f.push({op:"line",x1:n*K,y1:0,x2:n*K,y2:i,width:1,color:"#e0e0e0"});for(let n=0;n<=x;n++)f.push({op:"line",x1:0,y1:n*O,x2:r,y2:n*O,width:1,color:"#e0e0e0"});return f.push({op:"fillRect",x:0,y:0,w:r,h:O,color:"#f3f3f3"}),f.push({op:"fillRect",x:0,y:0,w:K,h:i,color:"#f3f3f3"}),f.push({op:"text",x:K+8,y:O+18,text:u,fontSize:14,color:"#202020",clip:{x:K,y:O,w:K*3,h:O},align:"left"}),{width:r,height:i,commands:f}}function ot(r,i){if(!r||r.length<2)return i;let u=[];for(let y=1;y<r.length;y++)u.push(r[y]-r[y-1]);u.sort((y,x)=>y-x);let f=u[u.length>>1];return f>0?f:i}function Ft(r,i,u){let f=ot(r?.grid?.rowOffsets,O),y=ot(r?.grid?.colOffsets,K),x=Math.max(1,Math.round(i.contentHeight/f))+1,n=Math.max(1,Math.round(i.contentWidth/y))+1,w=Math.max(1,Math.floor(u/f));return {rows:x,cols:n,rowsPerPage:w}}function nt(r,i,u){let f=new Blob([new Uint8Array(r)],{type:u}),y=URL.createObjectURL(f),x=document.createElement("a");x.href=y,x.download=i,document.body.appendChild(x),x.click(),x.remove(),URL.revokeObjectURL(y);}function $t(r){return `${(r??"workbook.xlsx").replace(/\.xlsx$/i,"")}.png`}var Ut={position:"absolute",width:1,height:1,margin:-1,padding:0,border:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap"},M={shell:{flex:"0 0 auto",minHeight:lt,padding:"4px 0 5px",borderBottom:"1px solid #e2e8f0",background:"#ffffff",color:"#0f172a",boxSizing:"border-box"},rail:{display:"flex",alignItems:"center",minHeight:36,margin:"0 8px",padding:"4px 8px",borderRadius:999,background:"#f1f5f9",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 q(r,i=false){return {appearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",gap:2,width:28,height:28,padding:0,border:0,borderRadius:6,background:i?"#0f172a":"transparent",color:r?i?"#ffffff":"#64748b":"#94a3b8",cursor:r?"pointer":"default",opacity:r?1:.32}}function J({name:r}){return jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",style:{flex:"0 0 auto"},children:[r==="save"&&jsx("path",{d:"M12 3v11m0 0 4-4m-4 4-4-4M5 19h14"}),r==="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"})]}),r==="undo"&&jsx("path",{d:"m9 7-5 5 5 5M5 12h9a6 6 0 0 1 6 6"}),r==="redo"&&jsx("path",{d:"m15 7 5 5-5 5m4-5h-9a6 6 0 0 0-6 6"}),r==="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"})]})]})}function Nt({i18n:r,...i}){return jsx(de,{i18n:r,children:jsx(_t,{...i})})}function _t({file:r,fileName:i,onSave:u,collaboration:f,onReady:y,className:x}){let{t:n}=N(),w=f!==void 0,H=f?.clientId,A=f?.initialUpdate,Q=f?.onReplica,De=useRef(null),z=useRef(null),xe=useRef(null),b=useRef(null),he=useRef(null),$=useRef(null),Te=useRef(null),me=useRef(false),ee=useRef(false),Ie=useRef(y);Ie.current=y;let[d,X]=useState(null),[ye,v]=useState(null),[te,at]=useState(null),[c,C]=useState(null),[E,U]=useState(null),[Me,ve]=useState(null),[oe,_]=useState(null),[He,it]=useState(lt),[Ae,Xe]=useState(0),[j,ne]=useState([]),[we,Be]=useState(false),[Le,We]=useState(null),[st,G]=useState({}),m=d?.activeSheet??0,Ke=useMemo(()=>isPngExportAvailable(),[]),Oe=useMemo(()=>isProposalsAvailable(),[]);useEffect(()=>{let e=De.current;if(!e)return;let t=()=>it(e.offsetHeight);t();let o=new ResizeObserver(t);return o.observe(e),()=>o.disconnect()},[]);let B=useCallback(()=>{let e=b.current;if(!e){ne([]);return}try{ne(e.listProposals());}catch{ne([]);}},[]);useEffect(()=>{if(U(null),_(null),ne([]),G({}),Be(false),We(null),!r){b.current=null,X(null),C(null),v(null);return}b.current=null,X(null),C(null);let e=null,t=()=>{},o=()=>{},l=false,a=()=>{let p=o;o=()=>{};try{p();}catch{}};return initWasm().then(()=>{if(!l)try{e=openWorkbook(r,{collaborative:w,clientId:H}),A&&e.applyUpdate(A.slice()),b.current=e,t=e.onUpdate(()=>{if(!(l||!e))try{X(e.sheetInfo()),Xe(h=>h+1),G({}),B(),v(null);}catch(h){v(h instanceof Error?h.message:String(h));}}),X(e.sheetInfo()),C(selectionAt({row:0,col:0})),We(e),v(null),B();let p=Ie.current?.({handle:e,refreshProposals:B});typeof p=="function"&&(o=p);}catch(p){a(),t(),t=()=>{},e?.dispose(),e=null,b.current=null,X(null),C(null),v(p instanceof Error?p.message:String(p));}},p=>{l||(b.current=null,X(null),C(null),v(p instanceof Error?p.message:String(p)));}),()=>{l=true,a(),t(),e?.dispose(),b.current=null;}},[r,w,H,A,B]),useEffect(()=>{if(!(!Q||!Le))return Q(Le),()=>Q(null)},[Q,Le]);let Se=useCallback(()=>{let e=z.current,t=xe.current;if(!e||!t)return;let o=t.getContext("2d");if(!o)return;let l=window.devicePixelRatio||1,a=e.clientWidth,p=e.clientHeight;if(a===0||p===0)return;t.width=Math.round(a*l),t.height=Math.round(p*l),t.style.width=`${a}px`,t.style.height=`${p}px`;let h=b.current,T;if(h)try{T=h.displayList({x:e.scrollLeft,y:e.scrollTop,width:a,height:p});}catch{return}else T=zt(a,p,n("editor.demoCellText"));paintDisplayList(o,T,l),he.current=T,at(T);},[n]);useEffect(()=>{let e=z.current;if(!e)return;let t=()=>{$.current==null&&($.current=requestAnimationFrame(()=>{$.current=null,Se();}));};Se(),e.addEventListener("scroll",t,{passive:true});let o=new ResizeObserver(t);return o.observe(e),()=>{e.removeEventListener("scroll",t),o.disconnect(),$.current!=null&&(cancelAnimationFrame($.current),$.current=null);}},[Se,d,ye,Ae]),useEffect(()=>{let e=b.current;if(!e||!c||!d){ve(null);return}try{ve(e.cell(m,c.focus.row,c.focus.col));}catch{ve(null);}},[c,d,m,Ae]),useEffect(()=>{let e=()=>{me.current=false;};return window.addEventListener("mouseup",e),()=>window.removeEventListener("mouseup",e)},[]);let re=useMemo(()=>!te||!d?null:buildA11yGrid(te,c,d.sheetNames[m]??"",{gridLabel:n("a11y.gridLabel"),rowHeaderLabel:n("a11y.rowHeaderLabel"),columnHeaderLabel:n("a11y.columnHeaderLabel"),cellLabel:n("a11y.cellLabel"),cellLabelSelected:n("a11y.cellLabelSelected"),emptyCellLabel:n("a11y.emptyCellLabel"),emptyCellLabelSelected:n("a11y.emptyCellLabelSelected")}),[te,c,d,m,n]),k=useCallback(()=>{z.current?.focus({preventScroll:true});},[]);useEffect(()=>{E&&Te.current?.focus({preventScroll:true});},[E]);let S=useCallback(e=>{X(e.sheetInfo),Xe(t=>t+1);},[]),D=useCallback(()=>Ft(he.current,d,z.current?.clientHeight??0),[d]),le=useCallback((e,t)=>{let o=xe.current,l=he.current?.grid;if(!o||!l)return null;let a=o.getBoundingClientRect();return cellAtPoint(l,e-a.left,t-a.top)},[]),ae=useCallback(e=>{let t=b.current;if(!t||!c)return;let{row:o,col:l}=c.focus,a=e??"";if(e===void 0)try{a=t.cell(m,o,l).input;}catch{a="";}U({row:o,col:l,value:a});},[c,m]),Ce=useCallback(e=>{let t=b.current;if(!t||!E)return;ee.current=true;let{row:o,col:l,value:a}=E;try{S(t.editCell(m,o,l,a));}catch(h){v(h instanceof Error?h.message:String(h));}U(null);let p=selectionAt({row:o,col:l});C(e?moveFocus(p,e,{limits:D()}):p),k();},[E,m,S,D,k]),ct=useCallback(()=>{ee.current=true,U(null),k();},[k]),ie=useCallback(()=>{let e=b.current;if(!e||!c)return;let t=normalizeRange(c),o=[];for(let l=t.top;l<=t.bottom;l++)for(let a=t.left;a<=t.right;a++)o.push({row:l,col:a,input:""});try{S(e.editCells(m,o));}catch(l){v(l instanceof Error?l.message:String(l));}},[c,m,S]),se=useCallback(async()=>{let e=b.current;if(!e||!c)return;let t=normalizeRange(c);try{let o=e.cell(m,t.top,t.left).a1,l=e.cell(m,t.bottom,t.right).a1,a=e.rangeCells(m,`${o}:${l}`),p=toTsv(a.map(h=>h.map(T=>({input:T.input,isFormula:T.isFormula}))));await navigator.clipboard.writeText(p);}catch{}},[c,m]),ze=useCallback(async()=>{await se(),ie();},[se,ie]),Fe=useCallback(async()=>{let e=b.current;if(!e||!c)return;let t;try{t=await navigator.clipboard.readText();}catch{return}let o=fromTsv(t);if(o.length===0)return;let l=normalizeRange(c),a=[],p=1;o.forEach((h,T)=>{p=Math.max(p,h.length),h.forEach((wt,Lt)=>a.push({row:l.top+T,col:l.left+Lt,input:wt}));});try{S(e.editCells(m,a));}catch(h){v(h instanceof Error?h.message:String(h));return}C({anchor:{row:l.top,col:l.left},focus:{row:l.top+o.length-1,col:l.left+p-1}});},[c,m,S]),Ee=useCallback(()=>{let e=b.current;if(!(!e||w))try{S(e.undo());}catch(t){v(t instanceof Error?t.message:String(t));}},[S,w]),ce=useCallback(()=>{let e=b.current;if(!(!e||w))try{S(e.redo());}catch(t){v(t instanceof Error?t.message:String(t));}},[S,w]),dt=useCallback((e,t)=>{let o=b.current;if(o)try{S(o.acceptProposal(e,{force:t})),G(({[e]:l,...a})=>a),B(),k();}catch(l){l instanceof StaleProposalError?G(a=>({...a,[e]:l.cells})):v(l instanceof Error?l.message:String(l));}},[S,B,k]),ut=useCallback(e=>{let t=b.current;if(t)try{t.rejectProposal(e),G(({[e]:o,...l})=>l),B();}catch(o){v(o instanceof Error?o.message:String(o));}},[B]),Pe=useCallback(()=>{let e=b.current;if(e)try{let t=e.save();u?u(t):nt(t,i??"workbook.xlsx",Ot);}catch(t){v(t instanceof Error?t.message:String(t));}},[u,i]),pt=useCallback(()=>{let e=b.current,t=z.current;if(!(!e||!t))try{let o=e.renderPng({x:t.scrollLeft,y:t.scrollTop,width:t.clientWidth,height:t.clientHeight});nt(o,$t(i),"image/png");}catch(o){v(o instanceof Error?o.message:String(o));}},[i]),$e=useCallback(e=>{let t=b.current;if(!t||!c||oe==null)return;let{row:o,col:l}=c.focus;try{S(t.editCell(m,o,l,oe));}catch(a){v(a instanceof Error?a.message:String(a));}_(null),e&&C(a=>a&&moveFocus(a,e,{limits:D()}));},[c,oe,m,S,D]),ft=useCallback(e=>{if(!b.current||!c||!d||E)return;let o=e.metaKey||e.ctrlKey,l=e.key.toLowerCase();if(o){if(l==="c"){se(),e.preventDefault();return}if(l==="v"){Fe(),e.preventDefault();return}if(l==="x"){ze(),e.preventDefault();return}if(l==="z"){e.shiftKey?ce():Ee(),e.preventDefault();return}if(l==="y"){ce(),e.preventDefault();return}if(l==="s"){Pe(),e.preventDefault();return}}let a=selectionKeyReducer(c,{key:e.key,shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey},D());switch(a.type){case "move":C(a.selection),e.preventDefault();break;case "startEdit":ae(a.initialInput),e.preventDefault();break;case "clear":ie(),e.preventDefault();break;}},[c,d,E,D,se,Fe,ze,Ee,ce,Pe,ae,ie]),gt=useCallback(e=>{if(!c)return;let t=le(e.clientX,e.clientY);t&&(e.shiftKey?C(o=>o&&extendTo(o,t,D())):C(selectionAt(t)),me.current=true,k());},[c,le,D,k]),bt=useCallback(e=>{if(!me.current)return;let t=le(e.clientX,e.clientY);t&&C(o=>o&&extendTo(o,t,D()));},[le,D]),xt=useCallback(()=>{c&&ae();},[c,ae]),W=te?.grid,Y=W&&c?rangeRect(W,normalizeRange(c)):null,V=W&&c?cellRect(W,c.focus.row,c.focus.col):null,Z=W&&E?cellRect(W,E.row,E.col):null,ht=d?d.contentWidth:void 0,mt=d?d.contentHeight:void 0,yt=oe??Me?.input??"",vt=e=>{let t=b.current;if(t)try{t.setActiveSheet(e);let o=z.current;o&&(o.scrollLeft=0,o.scrollTop=0),C(selectionAt({row:0,col:0})),U(null),_(null),X(t.sheetInfo());}catch(o){v(o instanceof Error?o.message:String(o));}};return jsxs("div",{className:x,role:"application","aria-label":n("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:De,"data-testid":"xlsx-toolbar",style:M.shell,children:jsxs("div",{style:M.rail,role:"group","aria-label":n("toolbar.actionsLabel"),children:[jsxs("div",{style:{...M.group,paddingLeft:0},role:"group","aria-label":n("toolbar.fileActionsLabel"),children:[jsx("button",{type:"button","data-testid":"xlsx-save",onClick:Pe,disabled:!d,"aria-label":n("toolbar.save"),title:n("toolbar.save"),style:q(!!d),children:jsx(J,{name:"save"})}),jsx("button",{type:"button","data-testid":"xlsx-export-png",onClick:pt,disabled:!d||!Ke,"aria-label":n("toolbar.exportPng"),title:n("toolbar.exportPng"),style:q(!!(d&&Ke)),children:jsx(J,{name:"image"})})]}),jsxs("div",{style:M.group,role:"group","aria-label":n("toolbar.historyLabel"),children:[jsx("button",{type:"button","data-testid":"xlsx-undo",onClick:Ee,disabled:!d||w,"aria-label":n("toolbar.undo"),title:n("toolbar.undo"),style:q(!!(d&&!w)),children:jsx(J,{name:"undo"})}),jsx("button",{type:"button","data-testid":"xlsx-redo",onClick:ce,disabled:!d||w,"aria-label":n("toolbar.redo"),title:n("toolbar.redo"),style:q(!!(d&&!w)),children:jsx(J,{name:"redo"})})]}),jsxs("div",{style:M.formulaGroup,role:"group","aria-label":n("toolbar.formulaBarLabel"),children:[jsx("input",{"data-testid":"xlsx-name-box",readOnly:true,value:Me?.a1??"",placeholder:n("toolbar.nameBoxPlaceholder"),"aria-label":n("toolbar.nameBoxPlaceholder"),style:M.nameBox}),jsx("span",{style:M.formulaMark,"aria-hidden":"true",children:"fx"}),jsx("input",{"data-testid":"xlsx-formula-input",value:yt,placeholder:n("toolbar.formulaPlaceholder"),"aria-label":n("toolbar.formulaPlaceholder"),disabled:!d,onChange:e=>_(e.target.value),onKeyDown:e=>{e.key==="Enter"?($e(e.shiftKey?"up":"down"),k(),e.preventDefault()):e.key==="Escape"&&(_(null),k(),e.preventDefault());},onBlur:()=>$e(),style:M.formulaInput})]}),Oe&&jsx("div",{style:M.proposals,children:jsxs("button",{type:"button","data-testid":"xlsx-proposals-button",onClick:()=>Be(e=>!e),disabled:!d,"aria-expanded":we,"aria-label":n("proposals.panelLabel"),title:n("proposals.panelLabel"),style:{...q(!!d,we),width:j.length>0?42:28},children:[jsx(J,{name:"proposals"}),j.length>0&&jsx("span",{"data-testid":"xlsx-proposals-count",style:M.count,children:j.length})]})})]})}),Oe&&we&&jsx(Qe,{proposals:j,staleFor:st,onAccept:dt,onReject:ut,style:{top:He+4,right:8,width:"min(320px, calc(100% - 16px))",maxHeight:`min(420px, calc(100% - ${He+12}px))`}}),jsxs("div",{ref:z,"data-testid":"xlsx-scroll",tabIndex:0,onKeyDown:ft,onMouseDown:gt,onMouseMove:bt,onDoubleClick:xt,style:{position:"relative",flex:1,overflow:"auto",minHeight:0,outline:"none"},children:[jsx("div",{style:{position:"absolute",top:0,left:0,width:ht??"100%",height:mt??"100%"}}),jsxs("div",{style:{position:"sticky",top:0,left:0,width:0,height:0},children:[jsx("canvas",{ref:xe,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:[Y&&jsx("div",{"data-testid":"xlsx-selection",style:{position:"absolute",left:Y.x,top:Y.y,width:Y.w,height:Y.h,boxSizing:"border-box",border:`1px solid ${be}`,background:"rgba(33, 115, 70, 0.12)"}}),V&&!E&&jsx("div",{style:{position:"absolute",left:V.x,top:V.y,width:V.w,height:V.h,boxSizing:"border-box",border:`2px solid ${be}`}}),W&&j.flatMap(e=>e.cells.map(t=>{if(t.sheet!==m)return null;let o=cellRect(W,t.row,t.col);return o?jsx(qe,{rect:o,color:ue(e.agentId),newText:t.newText,agentId:e.agentId},`${e.id}:${t.a1}`):null})),E&&Z&&jsx("input",{ref:Te,"data-testid":"xlsx-cell-editor",value:E.value,onChange:e=>U(t=>t&&{...t,value:e.target.value}),onKeyDown:e=>{e.stopPropagation(),e.key==="Enter"?(Ce(e.shiftKey?"up":"down"),e.preventDefault()):e.key==="Tab"?(Ce(e.shiftKey?"left":"right"),e.preventDefault()):e.key==="Escape"&&(ct(),e.preventDefault());},onBlur:()=>{if(ee.current){ee.current=false;return}Ce();},style:{position:"absolute",left:Z.x,top:Z.y,width:Z.w,height:Z.h,boxSizing:"border-box",border:`2px solid ${be}`,padding:"0 3px",font:"13px system-ui, sans-serif",background:"#ffffff",pointerEvents:"auto",outline:"none"}})]})]})]}),re&&jsxs("div",{style:Ut,role:"grid","aria-label":re.label,children:[jsxs("div",{role:"row",children:[jsx("span",{role:"columnheader"}),re.columnHeaders.map(e=>jsx("span",{role:"columnheader",children:e.label},e.col))]}),re.rows.map(e=>jsxs("div",{role:"row",children:[jsx("span",{role:"rowheader",children:e.header}),e.cells.map(t=>jsx("span",{role:"gridcell","aria-selected":t.selected,children:t.label},t.col))]},e.row))]}),ye&&jsxs("div",{"data-testid":"xlsx-error",role:"alert",style:{position:"absolute",inset:0,display:"grid",placeItems:"center",padding:16,textAlign:"center",color:"#b00020"},children:[n("editor.openError"),": ",ye]}),d&&d.sheetNames.length>0&&jsx("div",{"data-testid":"xlsx-sheet-tabs",role:"tablist","aria-label":n("editor.sheetTabsLabel"),style:{display:"flex",gap:2,padding:"4px 6px",borderTop:"1px solid #e0e0e0",background:"#fafafa",overflowX:"auto"},children:d.sheetNames.map((e,t)=>{let o=t===d.activeSheet;return jsx("button",{role:"tab","aria-selected":o,onClick:()=>vt(t),style:{border:"none",padding:"4px 12px",cursor:"pointer",borderBottom:o?`2px solid ${be}`:"2px solid transparent",fontWeight:o?600:400,background:o?"#ffffff":"transparent"},children:e},t)})})]})}export{de as LocaleProvider,Nt as XlsxEditor,N 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.
|
|
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.
|
|
37
|
-
"@betteroffice/xlsx-i18n": "0.0.
|
|
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",
|