@nuptechs/nup-xlsx-preview 1.0.0
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 +226 -0
- package/dist/adapters/react.cjs +10 -0
- package/dist/adapters/react.cjs.map +1 -0
- package/dist/adapters/react.d.cts +307 -0
- package/dist/adapters/react.d.ts +307 -0
- package/dist/adapters/react.js +10 -0
- package/dist/adapters/react.js.map +1 -0
- package/dist/adapters/vanilla.cjs +55 -0
- package/dist/adapters/vanilla.cjs.map +1 -0
- package/dist/adapters/vanilla.d.cts +168 -0
- package/dist/adapters/vanilla.d.ts +168 -0
- package/dist/adapters/vanilla.js +55 -0
- package/dist/adapters/vanilla.js.map +1 -0
- package/dist/adapters/vue.cjs +10 -0
- package/dist/adapters/vue.cjs.map +1 -0
- package/dist/adapters/vue.d.cts +369 -0
- package/dist/adapters/vue.d.ts +369 -0
- package/dist/adapters/vue.js +10 -0
- package/dist/adapters/vue.js.map +1 -0
- package/dist/index.cjs +55 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +790 -0
- package/dist/index.d.ts +790 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/dist/styles/base.css +346 -0
- package/dist/styles/index.css +730 -0
- package/dist/styles/print.css +182 -0
- package/dist/styles/themes.css +202 -0
- package/package.json +131 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { CSSProperties } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @aspect/nup-xlsx-preview - Types
|
|
6
|
+
* Ultra-light Excel visualization component
|
|
7
|
+
*/
|
|
8
|
+
interface NupCell {
|
|
9
|
+
v?: string | number | boolean | null;
|
|
10
|
+
f?: string;
|
|
11
|
+
s?: number | string;
|
|
12
|
+
t?: 's' | 'n' | 'b' | 'e' | 'd';
|
|
13
|
+
}
|
|
14
|
+
interface NupRow {
|
|
15
|
+
h?: number;
|
|
16
|
+
hidden?: boolean;
|
|
17
|
+
}
|
|
18
|
+
interface NupCol {
|
|
19
|
+
w?: number;
|
|
20
|
+
hidden?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface NupWorksheet {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
cells: Record<string, NupCell>;
|
|
26
|
+
rows: Record<number, NupRow>;
|
|
27
|
+
cols: Record<number, NupCol>;
|
|
28
|
+
merges?: string[];
|
|
29
|
+
rowCount: number;
|
|
30
|
+
colCount: number;
|
|
31
|
+
}
|
|
32
|
+
interface NupThemeConfig {
|
|
33
|
+
name: string;
|
|
34
|
+
colors: {
|
|
35
|
+
background: string;
|
|
36
|
+
foreground: string;
|
|
37
|
+
grid: string;
|
|
38
|
+
headerBackground: string;
|
|
39
|
+
headerForeground: string;
|
|
40
|
+
selectionBorder: string;
|
|
41
|
+
selectionBackground: string;
|
|
42
|
+
frozenBorder: string;
|
|
43
|
+
};
|
|
44
|
+
fonts: {
|
|
45
|
+
family: string;
|
|
46
|
+
size: string;
|
|
47
|
+
headerSize: string;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
interface NupWorkbook {
|
|
51
|
+
sheets: NupWorksheet[];
|
|
52
|
+
activeSheet: number;
|
|
53
|
+
styles?: Record<string, unknown>;
|
|
54
|
+
theme?: NupThemeConfig;
|
|
55
|
+
}
|
|
56
|
+
interface PreviewConfig {
|
|
57
|
+
workbook: NupWorkbook;
|
|
58
|
+
activeSheet?: number;
|
|
59
|
+
theme?: NupThemeConfig;
|
|
60
|
+
width?: number | string;
|
|
61
|
+
height?: number | string;
|
|
62
|
+
minRowHeight?: number;
|
|
63
|
+
maxRowHeight?: number;
|
|
64
|
+
defaultRowHeight?: number;
|
|
65
|
+
defaultColWidth?: number;
|
|
66
|
+
showHeaders?: boolean;
|
|
67
|
+
showSheetTabs?: boolean;
|
|
68
|
+
showGridLines?: boolean;
|
|
69
|
+
showScrollbars?: boolean;
|
|
70
|
+
selectable?: boolean;
|
|
71
|
+
resizable?: boolean;
|
|
72
|
+
searchable?: boolean;
|
|
73
|
+
copyable?: boolean;
|
|
74
|
+
contextMenu?: boolean;
|
|
75
|
+
frozenRows?: number;
|
|
76
|
+
frozenCols?: number;
|
|
77
|
+
overscan?: number;
|
|
78
|
+
recycleNodes?: boolean;
|
|
79
|
+
ariaLabel?: string;
|
|
80
|
+
keyboardNavigation?: boolean;
|
|
81
|
+
}
|
|
82
|
+
interface CellClickEvent {
|
|
83
|
+
cell: NupCell | null;
|
|
84
|
+
row: number;
|
|
85
|
+
col: number;
|
|
86
|
+
cellRef: string;
|
|
87
|
+
originalEvent: MouseEvent;
|
|
88
|
+
}
|
|
89
|
+
interface SelectionRange {
|
|
90
|
+
start: {
|
|
91
|
+
row: number;
|
|
92
|
+
col: number;
|
|
93
|
+
};
|
|
94
|
+
end: {
|
|
95
|
+
row: number;
|
|
96
|
+
col: number;
|
|
97
|
+
};
|
|
98
|
+
cells: (NupCell | null)[][];
|
|
99
|
+
cellRefs: string[];
|
|
100
|
+
}
|
|
101
|
+
interface ScrollPosition {
|
|
102
|
+
scrollTop: number;
|
|
103
|
+
scrollLeft: number;
|
|
104
|
+
visibleRows: {
|
|
105
|
+
start: number;
|
|
106
|
+
end: number;
|
|
107
|
+
};
|
|
108
|
+
visibleCols: {
|
|
109
|
+
start: number;
|
|
110
|
+
end: number;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
interface SearchResult {
|
|
114
|
+
row: number;
|
|
115
|
+
col: number;
|
|
116
|
+
cellRef: string;
|
|
117
|
+
value: string;
|
|
118
|
+
matchStart: number;
|
|
119
|
+
matchEnd: number;
|
|
120
|
+
}
|
|
121
|
+
interface ClipboardData {
|
|
122
|
+
text: string;
|
|
123
|
+
html: string;
|
|
124
|
+
cells: (NupCell | null)[][];
|
|
125
|
+
}
|
|
126
|
+
interface PreviewEvents {
|
|
127
|
+
onCellClick?: (event: CellClickEvent) => void;
|
|
128
|
+
onCellDoubleClick?: (event: CellClickEvent) => void;
|
|
129
|
+
onCellRightClick?: (event: CellClickEvent) => void;
|
|
130
|
+
onSelectionChange?: (selection: SelectionRange | null) => void;
|
|
131
|
+
onSheetChange?: (sheetIndex: number) => void;
|
|
132
|
+
onColumnResize?: (colIndex: number, width: number) => void;
|
|
133
|
+
onScroll?: (scroll: ScrollPosition) => void;
|
|
134
|
+
onSearch?: (results: SearchResult[]) => void;
|
|
135
|
+
onCopy?: (data: ClipboardData) => void;
|
|
136
|
+
}
|
|
137
|
+
interface PreviewInstance {
|
|
138
|
+
scrollTo(row: number, col: number): void;
|
|
139
|
+
scrollToCell(cellRef: string): void;
|
|
140
|
+
select(range: SelectionRange): void;
|
|
141
|
+
selectCell(cellRef: string): void;
|
|
142
|
+
selectAll(): void;
|
|
143
|
+
clearSelection(): void;
|
|
144
|
+
getSelection(): SelectionRange | null;
|
|
145
|
+
setActiveSheet(index: number): void;
|
|
146
|
+
getActiveSheet(): number;
|
|
147
|
+
search(query: string): SearchResult[];
|
|
148
|
+
highlightResults(results: SearchResult[]): void;
|
|
149
|
+
clearHighlights(): void;
|
|
150
|
+
getWorkbook(): NupWorkbook;
|
|
151
|
+
getVisibleCells(): (NupCell | null)[][];
|
|
152
|
+
getCellAt(row: number, col: number): NupCell | null;
|
|
153
|
+
copySelection(): Promise<void>;
|
|
154
|
+
setColumnWidth(col: number, width: number): void;
|
|
155
|
+
autoFitColumn(col: number): void;
|
|
156
|
+
autoFitAllColumns(): void;
|
|
157
|
+
refresh(): void;
|
|
158
|
+
destroy(): void;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Theme Definitions (JS version)
|
|
163
|
+
* For programmatic theme access
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
declare const themes: {
|
|
167
|
+
readonly default: {
|
|
168
|
+
readonly name: "default";
|
|
169
|
+
readonly colors: {
|
|
170
|
+
readonly background: "#ffffff";
|
|
171
|
+
readonly foreground: "#202124";
|
|
172
|
+
readonly grid: "#e0e0e0";
|
|
173
|
+
readonly headerBackground: "#f8f9fa";
|
|
174
|
+
readonly headerForeground: "#5f6368";
|
|
175
|
+
readonly selectionBorder: "#1a73e8";
|
|
176
|
+
readonly selectionBackground: "rgba(26, 115, 232, 0.08)";
|
|
177
|
+
readonly frozenBorder: "#dadce0";
|
|
178
|
+
};
|
|
179
|
+
readonly fonts: {
|
|
180
|
+
readonly family: "'Google Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";
|
|
181
|
+
readonly size: "13px";
|
|
182
|
+
readonly headerSize: "11px";
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
readonly excel: {
|
|
186
|
+
readonly name: "excel";
|
|
187
|
+
readonly colors: {
|
|
188
|
+
readonly background: "#ffffff";
|
|
189
|
+
readonly foreground: "#000000";
|
|
190
|
+
readonly grid: "#d4d4d4";
|
|
191
|
+
readonly headerBackground: "#f0f0f0";
|
|
192
|
+
readonly headerForeground: "#000000";
|
|
193
|
+
readonly selectionBorder: "#217346";
|
|
194
|
+
readonly selectionBackground: "rgba(33, 115, 70, 0.1)";
|
|
195
|
+
readonly frozenBorder: "#9bc2e6";
|
|
196
|
+
};
|
|
197
|
+
readonly fonts: {
|
|
198
|
+
readonly family: "'Calibri', 'Segoe UI', sans-serif";
|
|
199
|
+
readonly size: "11px";
|
|
200
|
+
readonly headerSize: "11px";
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
readonly modern: {
|
|
204
|
+
readonly name: "modern";
|
|
205
|
+
readonly colors: {
|
|
206
|
+
readonly background: "#fafafa";
|
|
207
|
+
readonly foreground: "#18181b";
|
|
208
|
+
readonly grid: "#e4e4e7";
|
|
209
|
+
readonly headerBackground: "#f4f4f5";
|
|
210
|
+
readonly headerForeground: "#71717a";
|
|
211
|
+
readonly selectionBorder: "#3b82f6";
|
|
212
|
+
readonly selectionBackground: "rgba(59, 130, 246, 0.08)";
|
|
213
|
+
readonly frozenBorder: "#a1a1aa";
|
|
214
|
+
};
|
|
215
|
+
readonly fonts: {
|
|
216
|
+
readonly family: "'Inter', -apple-system, BlinkMacSystemFont, sans-serif";
|
|
217
|
+
readonly size: "13px";
|
|
218
|
+
readonly headerSize: "11px";
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
readonly minimal: {
|
|
222
|
+
readonly name: "minimal";
|
|
223
|
+
readonly colors: {
|
|
224
|
+
readonly background: "#ffffff";
|
|
225
|
+
readonly foreground: "#27272a";
|
|
226
|
+
readonly grid: "#f4f4f5";
|
|
227
|
+
readonly headerBackground: "#ffffff";
|
|
228
|
+
readonly headerForeground: "#a1a1aa";
|
|
229
|
+
readonly selectionBorder: "#18181b";
|
|
230
|
+
readonly selectionBackground: "rgba(24, 24, 27, 0.04)";
|
|
231
|
+
readonly frozenBorder: "#e4e4e7";
|
|
232
|
+
};
|
|
233
|
+
readonly fonts: {
|
|
234
|
+
readonly family: "'SF Pro Display', -apple-system, BlinkMacSystemFont, sans-serif";
|
|
235
|
+
readonly size: "13px";
|
|
236
|
+
readonly headerSize: "11px";
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
readonly dark: {
|
|
240
|
+
readonly name: "dark";
|
|
241
|
+
readonly colors: {
|
|
242
|
+
readonly background: "#1e1e1e";
|
|
243
|
+
readonly foreground: "#d4d4d4";
|
|
244
|
+
readonly grid: "#3c3c3c";
|
|
245
|
+
readonly headerBackground: "#252526";
|
|
246
|
+
readonly headerForeground: "#858585";
|
|
247
|
+
readonly selectionBorder: "#0078d4";
|
|
248
|
+
readonly selectionBackground: "rgba(0, 120, 212, 0.2)";
|
|
249
|
+
readonly frozenBorder: "#4a4a4a";
|
|
250
|
+
};
|
|
251
|
+
readonly fonts: {
|
|
252
|
+
readonly family: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";
|
|
253
|
+
readonly size: "13px";
|
|
254
|
+
readonly headerSize: "11px";
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
readonly midnight: {
|
|
258
|
+
readonly name: "midnight";
|
|
259
|
+
readonly colors: {
|
|
260
|
+
readonly background: "#0d1117";
|
|
261
|
+
readonly foreground: "#c9d1d9";
|
|
262
|
+
readonly grid: "#21262d";
|
|
263
|
+
readonly headerBackground: "#161b22";
|
|
264
|
+
readonly headerForeground: "#8b949e";
|
|
265
|
+
readonly selectionBorder: "#58a6ff";
|
|
266
|
+
readonly selectionBackground: "rgba(88, 166, 255, 0.15)";
|
|
267
|
+
readonly frozenBorder: "#30363d";
|
|
268
|
+
};
|
|
269
|
+
readonly fonts: {
|
|
270
|
+
readonly family: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";
|
|
271
|
+
readonly size: "13px";
|
|
272
|
+
readonly headerSize: "11px";
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
readonly accessible: {
|
|
276
|
+
readonly name: "accessible";
|
|
277
|
+
readonly colors: {
|
|
278
|
+
readonly background: "#ffffff";
|
|
279
|
+
readonly foreground: "#000000";
|
|
280
|
+
readonly grid: "#000000";
|
|
281
|
+
readonly headerBackground: "#e6e6e6";
|
|
282
|
+
readonly headerForeground: "#000000";
|
|
283
|
+
readonly selectionBorder: "#0000ff";
|
|
284
|
+
readonly selectionBackground: "rgba(0, 0, 255, 0.15)";
|
|
285
|
+
readonly frozenBorder: "#000000";
|
|
286
|
+
};
|
|
287
|
+
readonly fonts: {
|
|
288
|
+
readonly family: "Arial, Helvetica, sans-serif";
|
|
289
|
+
readonly size: "14px";
|
|
290
|
+
readonly headerSize: "12px";
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
type ThemeName = keyof typeof themes;
|
|
295
|
+
|
|
296
|
+
interface NupSpreadsheetPreviewProps extends Omit<Partial<PreviewConfig>, 'theme'>, PreviewEvents {
|
|
297
|
+
workbook: NupWorkbook;
|
|
298
|
+
activeSheet?: number;
|
|
299
|
+
theme?: NupThemeConfig | ThemeName;
|
|
300
|
+
width?: number | string;
|
|
301
|
+
height?: number | string;
|
|
302
|
+
className?: string;
|
|
303
|
+
style?: CSSProperties;
|
|
304
|
+
}
|
|
305
|
+
declare const NupSpreadsheetPreview: react.ForwardRefExoticComponent<NupSpreadsheetPreviewProps & react.RefAttributes<PreviewInstance>>;
|
|
306
|
+
|
|
307
|
+
export { NupSpreadsheetPreview, type NupSpreadsheetPreviewProps, NupSpreadsheetPreview as default };
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { CSSProperties } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @aspect/nup-xlsx-preview - Types
|
|
6
|
+
* Ultra-light Excel visualization component
|
|
7
|
+
*/
|
|
8
|
+
interface NupCell {
|
|
9
|
+
v?: string | number | boolean | null;
|
|
10
|
+
f?: string;
|
|
11
|
+
s?: number | string;
|
|
12
|
+
t?: 's' | 'n' | 'b' | 'e' | 'd';
|
|
13
|
+
}
|
|
14
|
+
interface NupRow {
|
|
15
|
+
h?: number;
|
|
16
|
+
hidden?: boolean;
|
|
17
|
+
}
|
|
18
|
+
interface NupCol {
|
|
19
|
+
w?: number;
|
|
20
|
+
hidden?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface NupWorksheet {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
cells: Record<string, NupCell>;
|
|
26
|
+
rows: Record<number, NupRow>;
|
|
27
|
+
cols: Record<number, NupCol>;
|
|
28
|
+
merges?: string[];
|
|
29
|
+
rowCount: number;
|
|
30
|
+
colCount: number;
|
|
31
|
+
}
|
|
32
|
+
interface NupThemeConfig {
|
|
33
|
+
name: string;
|
|
34
|
+
colors: {
|
|
35
|
+
background: string;
|
|
36
|
+
foreground: string;
|
|
37
|
+
grid: string;
|
|
38
|
+
headerBackground: string;
|
|
39
|
+
headerForeground: string;
|
|
40
|
+
selectionBorder: string;
|
|
41
|
+
selectionBackground: string;
|
|
42
|
+
frozenBorder: string;
|
|
43
|
+
};
|
|
44
|
+
fonts: {
|
|
45
|
+
family: string;
|
|
46
|
+
size: string;
|
|
47
|
+
headerSize: string;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
interface NupWorkbook {
|
|
51
|
+
sheets: NupWorksheet[];
|
|
52
|
+
activeSheet: number;
|
|
53
|
+
styles?: Record<string, unknown>;
|
|
54
|
+
theme?: NupThemeConfig;
|
|
55
|
+
}
|
|
56
|
+
interface PreviewConfig {
|
|
57
|
+
workbook: NupWorkbook;
|
|
58
|
+
activeSheet?: number;
|
|
59
|
+
theme?: NupThemeConfig;
|
|
60
|
+
width?: number | string;
|
|
61
|
+
height?: number | string;
|
|
62
|
+
minRowHeight?: number;
|
|
63
|
+
maxRowHeight?: number;
|
|
64
|
+
defaultRowHeight?: number;
|
|
65
|
+
defaultColWidth?: number;
|
|
66
|
+
showHeaders?: boolean;
|
|
67
|
+
showSheetTabs?: boolean;
|
|
68
|
+
showGridLines?: boolean;
|
|
69
|
+
showScrollbars?: boolean;
|
|
70
|
+
selectable?: boolean;
|
|
71
|
+
resizable?: boolean;
|
|
72
|
+
searchable?: boolean;
|
|
73
|
+
copyable?: boolean;
|
|
74
|
+
contextMenu?: boolean;
|
|
75
|
+
frozenRows?: number;
|
|
76
|
+
frozenCols?: number;
|
|
77
|
+
overscan?: number;
|
|
78
|
+
recycleNodes?: boolean;
|
|
79
|
+
ariaLabel?: string;
|
|
80
|
+
keyboardNavigation?: boolean;
|
|
81
|
+
}
|
|
82
|
+
interface CellClickEvent {
|
|
83
|
+
cell: NupCell | null;
|
|
84
|
+
row: number;
|
|
85
|
+
col: number;
|
|
86
|
+
cellRef: string;
|
|
87
|
+
originalEvent: MouseEvent;
|
|
88
|
+
}
|
|
89
|
+
interface SelectionRange {
|
|
90
|
+
start: {
|
|
91
|
+
row: number;
|
|
92
|
+
col: number;
|
|
93
|
+
};
|
|
94
|
+
end: {
|
|
95
|
+
row: number;
|
|
96
|
+
col: number;
|
|
97
|
+
};
|
|
98
|
+
cells: (NupCell | null)[][];
|
|
99
|
+
cellRefs: string[];
|
|
100
|
+
}
|
|
101
|
+
interface ScrollPosition {
|
|
102
|
+
scrollTop: number;
|
|
103
|
+
scrollLeft: number;
|
|
104
|
+
visibleRows: {
|
|
105
|
+
start: number;
|
|
106
|
+
end: number;
|
|
107
|
+
};
|
|
108
|
+
visibleCols: {
|
|
109
|
+
start: number;
|
|
110
|
+
end: number;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
interface SearchResult {
|
|
114
|
+
row: number;
|
|
115
|
+
col: number;
|
|
116
|
+
cellRef: string;
|
|
117
|
+
value: string;
|
|
118
|
+
matchStart: number;
|
|
119
|
+
matchEnd: number;
|
|
120
|
+
}
|
|
121
|
+
interface ClipboardData {
|
|
122
|
+
text: string;
|
|
123
|
+
html: string;
|
|
124
|
+
cells: (NupCell | null)[][];
|
|
125
|
+
}
|
|
126
|
+
interface PreviewEvents {
|
|
127
|
+
onCellClick?: (event: CellClickEvent) => void;
|
|
128
|
+
onCellDoubleClick?: (event: CellClickEvent) => void;
|
|
129
|
+
onCellRightClick?: (event: CellClickEvent) => void;
|
|
130
|
+
onSelectionChange?: (selection: SelectionRange | null) => void;
|
|
131
|
+
onSheetChange?: (sheetIndex: number) => void;
|
|
132
|
+
onColumnResize?: (colIndex: number, width: number) => void;
|
|
133
|
+
onScroll?: (scroll: ScrollPosition) => void;
|
|
134
|
+
onSearch?: (results: SearchResult[]) => void;
|
|
135
|
+
onCopy?: (data: ClipboardData) => void;
|
|
136
|
+
}
|
|
137
|
+
interface PreviewInstance {
|
|
138
|
+
scrollTo(row: number, col: number): void;
|
|
139
|
+
scrollToCell(cellRef: string): void;
|
|
140
|
+
select(range: SelectionRange): void;
|
|
141
|
+
selectCell(cellRef: string): void;
|
|
142
|
+
selectAll(): void;
|
|
143
|
+
clearSelection(): void;
|
|
144
|
+
getSelection(): SelectionRange | null;
|
|
145
|
+
setActiveSheet(index: number): void;
|
|
146
|
+
getActiveSheet(): number;
|
|
147
|
+
search(query: string): SearchResult[];
|
|
148
|
+
highlightResults(results: SearchResult[]): void;
|
|
149
|
+
clearHighlights(): void;
|
|
150
|
+
getWorkbook(): NupWorkbook;
|
|
151
|
+
getVisibleCells(): (NupCell | null)[][];
|
|
152
|
+
getCellAt(row: number, col: number): NupCell | null;
|
|
153
|
+
copySelection(): Promise<void>;
|
|
154
|
+
setColumnWidth(col: number, width: number): void;
|
|
155
|
+
autoFitColumn(col: number): void;
|
|
156
|
+
autoFitAllColumns(): void;
|
|
157
|
+
refresh(): void;
|
|
158
|
+
destroy(): void;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Theme Definitions (JS version)
|
|
163
|
+
* For programmatic theme access
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
declare const themes: {
|
|
167
|
+
readonly default: {
|
|
168
|
+
readonly name: "default";
|
|
169
|
+
readonly colors: {
|
|
170
|
+
readonly background: "#ffffff";
|
|
171
|
+
readonly foreground: "#202124";
|
|
172
|
+
readonly grid: "#e0e0e0";
|
|
173
|
+
readonly headerBackground: "#f8f9fa";
|
|
174
|
+
readonly headerForeground: "#5f6368";
|
|
175
|
+
readonly selectionBorder: "#1a73e8";
|
|
176
|
+
readonly selectionBackground: "rgba(26, 115, 232, 0.08)";
|
|
177
|
+
readonly frozenBorder: "#dadce0";
|
|
178
|
+
};
|
|
179
|
+
readonly fonts: {
|
|
180
|
+
readonly family: "'Google Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";
|
|
181
|
+
readonly size: "13px";
|
|
182
|
+
readonly headerSize: "11px";
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
readonly excel: {
|
|
186
|
+
readonly name: "excel";
|
|
187
|
+
readonly colors: {
|
|
188
|
+
readonly background: "#ffffff";
|
|
189
|
+
readonly foreground: "#000000";
|
|
190
|
+
readonly grid: "#d4d4d4";
|
|
191
|
+
readonly headerBackground: "#f0f0f0";
|
|
192
|
+
readonly headerForeground: "#000000";
|
|
193
|
+
readonly selectionBorder: "#217346";
|
|
194
|
+
readonly selectionBackground: "rgba(33, 115, 70, 0.1)";
|
|
195
|
+
readonly frozenBorder: "#9bc2e6";
|
|
196
|
+
};
|
|
197
|
+
readonly fonts: {
|
|
198
|
+
readonly family: "'Calibri', 'Segoe UI', sans-serif";
|
|
199
|
+
readonly size: "11px";
|
|
200
|
+
readonly headerSize: "11px";
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
readonly modern: {
|
|
204
|
+
readonly name: "modern";
|
|
205
|
+
readonly colors: {
|
|
206
|
+
readonly background: "#fafafa";
|
|
207
|
+
readonly foreground: "#18181b";
|
|
208
|
+
readonly grid: "#e4e4e7";
|
|
209
|
+
readonly headerBackground: "#f4f4f5";
|
|
210
|
+
readonly headerForeground: "#71717a";
|
|
211
|
+
readonly selectionBorder: "#3b82f6";
|
|
212
|
+
readonly selectionBackground: "rgba(59, 130, 246, 0.08)";
|
|
213
|
+
readonly frozenBorder: "#a1a1aa";
|
|
214
|
+
};
|
|
215
|
+
readonly fonts: {
|
|
216
|
+
readonly family: "'Inter', -apple-system, BlinkMacSystemFont, sans-serif";
|
|
217
|
+
readonly size: "13px";
|
|
218
|
+
readonly headerSize: "11px";
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
readonly minimal: {
|
|
222
|
+
readonly name: "minimal";
|
|
223
|
+
readonly colors: {
|
|
224
|
+
readonly background: "#ffffff";
|
|
225
|
+
readonly foreground: "#27272a";
|
|
226
|
+
readonly grid: "#f4f4f5";
|
|
227
|
+
readonly headerBackground: "#ffffff";
|
|
228
|
+
readonly headerForeground: "#a1a1aa";
|
|
229
|
+
readonly selectionBorder: "#18181b";
|
|
230
|
+
readonly selectionBackground: "rgba(24, 24, 27, 0.04)";
|
|
231
|
+
readonly frozenBorder: "#e4e4e7";
|
|
232
|
+
};
|
|
233
|
+
readonly fonts: {
|
|
234
|
+
readonly family: "'SF Pro Display', -apple-system, BlinkMacSystemFont, sans-serif";
|
|
235
|
+
readonly size: "13px";
|
|
236
|
+
readonly headerSize: "11px";
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
readonly dark: {
|
|
240
|
+
readonly name: "dark";
|
|
241
|
+
readonly colors: {
|
|
242
|
+
readonly background: "#1e1e1e";
|
|
243
|
+
readonly foreground: "#d4d4d4";
|
|
244
|
+
readonly grid: "#3c3c3c";
|
|
245
|
+
readonly headerBackground: "#252526";
|
|
246
|
+
readonly headerForeground: "#858585";
|
|
247
|
+
readonly selectionBorder: "#0078d4";
|
|
248
|
+
readonly selectionBackground: "rgba(0, 120, 212, 0.2)";
|
|
249
|
+
readonly frozenBorder: "#4a4a4a";
|
|
250
|
+
};
|
|
251
|
+
readonly fonts: {
|
|
252
|
+
readonly family: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";
|
|
253
|
+
readonly size: "13px";
|
|
254
|
+
readonly headerSize: "11px";
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
readonly midnight: {
|
|
258
|
+
readonly name: "midnight";
|
|
259
|
+
readonly colors: {
|
|
260
|
+
readonly background: "#0d1117";
|
|
261
|
+
readonly foreground: "#c9d1d9";
|
|
262
|
+
readonly grid: "#21262d";
|
|
263
|
+
readonly headerBackground: "#161b22";
|
|
264
|
+
readonly headerForeground: "#8b949e";
|
|
265
|
+
readonly selectionBorder: "#58a6ff";
|
|
266
|
+
readonly selectionBackground: "rgba(88, 166, 255, 0.15)";
|
|
267
|
+
readonly frozenBorder: "#30363d";
|
|
268
|
+
};
|
|
269
|
+
readonly fonts: {
|
|
270
|
+
readonly family: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";
|
|
271
|
+
readonly size: "13px";
|
|
272
|
+
readonly headerSize: "11px";
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
readonly accessible: {
|
|
276
|
+
readonly name: "accessible";
|
|
277
|
+
readonly colors: {
|
|
278
|
+
readonly background: "#ffffff";
|
|
279
|
+
readonly foreground: "#000000";
|
|
280
|
+
readonly grid: "#000000";
|
|
281
|
+
readonly headerBackground: "#e6e6e6";
|
|
282
|
+
readonly headerForeground: "#000000";
|
|
283
|
+
readonly selectionBorder: "#0000ff";
|
|
284
|
+
readonly selectionBackground: "rgba(0, 0, 255, 0.15)";
|
|
285
|
+
readonly frozenBorder: "#000000";
|
|
286
|
+
};
|
|
287
|
+
readonly fonts: {
|
|
288
|
+
readonly family: "Arial, Helvetica, sans-serif";
|
|
289
|
+
readonly size: "14px";
|
|
290
|
+
readonly headerSize: "12px";
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
type ThemeName = keyof typeof themes;
|
|
295
|
+
|
|
296
|
+
interface NupSpreadsheetPreviewProps extends Omit<Partial<PreviewConfig>, 'theme'>, PreviewEvents {
|
|
297
|
+
workbook: NupWorkbook;
|
|
298
|
+
activeSheet?: number;
|
|
299
|
+
theme?: NupThemeConfig | ThemeName;
|
|
300
|
+
width?: number | string;
|
|
301
|
+
height?: number | string;
|
|
302
|
+
className?: string;
|
|
303
|
+
style?: CSSProperties;
|
|
304
|
+
}
|
|
305
|
+
declare const NupSpreadsheetPreview: react.ForwardRefExoticComponent<NupSpreadsheetPreviewProps & react.RefAttributes<PreviewInstance>>;
|
|
306
|
+
|
|
307
|
+
export { NupSpreadsheetPreview, type NupSpreadsheetPreviewProps, NupSpreadsheetPreview as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {forwardRef,useRef,useState,useMemo,useLayoutEffect,useEffect,useCallback,useImperativeHandle}from'react';import {jsx,jsxs}from'react/jsx-runtime';var j=class{rowPositions;colPositions;rowHeightCache;colWidthCache;totalHeight;totalWidth;overscan;rowCount;colCount;frozenRows;frozenCols;frozenRowsHeight;frozenColsWidth;constructor(e){let{rows:t,cols:r,rowHeights:l,colWidths:s,defaultRowHeight:i=24,defaultColWidth:d=100,overscan:u=5,frozenRows:h=0,frozenCols:p=0}=e;this.frozenRows=h,this.frozenCols=p,this.rowCount=t,this.colCount=r,this.overscan=u,this.rowPositions=new Array(t+1),this.rowHeightCache=new Array(t),this.rowPositions[0]=0;for(let m=0;m<t;m++){let w=l[m]??i;this.rowHeightCache[m]=w,this.rowPositions[m+1]=this.rowPositions[m]+w;}this.totalHeight=this.rowPositions[t],this.frozenRowsHeight=h>0?this.rowPositions[h]??0:0,this.colPositions=new Array(r+1),this.colWidthCache=new Array(r),this.colPositions[0]=0;for(let m=0;m<r;m++){let w=s[m]??d;this.colWidthCache[m]=w,this.colPositions[m+1]=this.colPositions[m]+w;}this.totalWidth=this.colPositions[r],this.frozenColsWidth=p>0?this.colPositions[p]??0:0;}getFrozenInfo(){return {rows:this.frozenRows,cols:this.frozenCols,frozenRowsHeight:this.frozenRowsHeight,frozenColsWidth:this.frozenColsWidth}}binarySearch(e,t){let r=0,l=e.length-2;for(;r<=l;){let s=r+l>>>1,i=e[s],d=e[s+1];if(t>=i&&t<d)return s;t<i?l=s-1:r=s+1;}return Math.max(0,Math.min(r,e.length-2))}getVisibleRange(e,t,r,l){let s=e+this.frozenRowsHeight,i=t+this.frozenColsWidth,d=this.binarySearch(this.rowPositions,s),u=this.binarySearch(this.rowPositions,s+Math.max(0,r)),h=this.binarySearch(this.colPositions,i),p=this.binarySearch(this.colPositions,i+Math.max(0,l)),m=Math.max(this.frozenRows,d-this.overscan),w=Math.min(this.rowCount-1,u+this.overscan),L=Math.max(this.frozenCols,h-this.overscan),K=Math.min(this.colCount-1,p+this.overscan);return {startRow:m,endRow:w,startCol:L,endCol:K}}getFrozenRowsRange(){return this.frozenRows===0?null:{startRow:0,endRow:this.frozenRows-1}}getFrozenColsRange(){return this.frozenCols===0?null:{startCol:0,endCol:this.frozenCols-1}}getCellRect(e,t){return {top:this.rowPositions[e]??0,left:this.colPositions[t]??0,width:this.colWidthCache[t]??100,height:this.rowHeightCache[e]??24}}getRowHeight(e){return this.rowHeightCache[e]??24}getColWidth(e){return this.colWidthCache[e]??100}setColWidth(e,t){if(e<0||e>=this.colCount)return;let r=this.colWidthCache[e],l=t-r;this.colWidthCache[e]=t;for(let s=e+1;s<=this.colCount;s++)this.colPositions[s]+=l;this.totalWidth+=l;}getIndexAtPosition(e,t){return {row:this.binarySearch(this.rowPositions,e),col:this.binarySearch(this.colPositions,t)}}getScrollToPosition(e,t,r,l){let s=this.rowPositions[e]??0,i=this.colPositions[t]??0;return {scrollTop:Math.max(0,s-r/2),scrollLeft:Math.max(0,i-l/2)}}};function re(b){let e="",t=b;for(;t>=0;)e=String.fromCharCode(t%26+65)+e,t=Math.floor(t/26)-1;return e}function _e(b){let e=0,t=b.toUpperCase();for(let r=0;r<t.length;r++)e=e*26+(t.charCodeAt(r)-64);return e-1}function M(b,e){return `${re(e)}${b+1}`}function k(b){let e=b.match(/^([A-Z]+)(\d+)$/i);if(!e)return null;let t=_e(e[1]),r=parseInt(e[2],10)-1;return r<0||t<0?null:{row:r,col:t}}var O=class{state;sheet;onChange;constructor(e,t){this.sheet=e,this.onChange=t??null,this.state={anchor:null,focus:null,ranges:[]};}handleClick(e,t,r){let{shiftKey:l,ctrlKey:s,metaKey:i}=r;l&&this.state.anchor?(this.state.focus={row:e,col:t},this.updateRanges()):s||i?(this.state.anchor={row:e,col:t},this.state.focus={row:e,col:t},this.state.ranges.push(this.createRange(this.state.anchor,this.state.focus))):(this.state.anchor={row:e,col:t},this.state.focus={row:e,col:t},this.state.ranges=[this.createRange(this.state.anchor,this.state.focus)]),this.notifyChange();}handleDrag(e,t){this.state.anchor&&(this.state.focus={row:e,col:t},this.updateRanges(),this.notifyChange());}selectCell(e){let t=k(e);t&&(this.state.anchor=t,this.state.focus=t,this.state.ranges=[this.createRange(t,t)],this.notifyChange());}selectRange(e,t){let r=k(e),l=k(t);!r||!l||(this.state.anchor=r,this.state.focus=l,this.state.ranges=[this.createRange(r,l)],this.notifyChange());}selectAll(){this.state.anchor={row:0,col:0},this.state.focus={row:this.sheet.rowCount-1,col:this.sheet.colCount-1},this.state.ranges=[this.createRange(this.state.anchor,this.state.focus)],this.notifyChange();}clear(){this.state.anchor=null,this.state.focus=null,this.state.ranges=[],this.notifyChange();}getSelection(){return this.state.ranges.length===0?null:this.state.ranges[0]}getAllSelections(){return [...this.state.ranges]}isCellSelected(e,t){return this.state.ranges.some(r=>e>=r.start.row&&e<=r.end.row&&t>=r.start.col&&t<=r.end.col)}isAnchor(e,t){return this.state.anchor?.row===e&&this.state.anchor?.col===t}setSheet(e){this.sheet=e,this.clear();}updateRanges(){if(!this.state.anchor||!this.state.focus)return;let e=this.createRange(this.state.anchor,this.state.focus);this.state.ranges.length>0?this.state.ranges[this.state.ranges.length-1]=e:this.state.ranges.push(e);}createRange(e,t){let r=Math.min(e.row,t.row),l=Math.max(e.row,t.row),s=Math.min(e.col,t.col),i=Math.max(e.col,t.col),d=[],u=[];for(let h=r;h<=l;h++){let p=[];for(let m=s;m<=i;m++){let w=M(h,m);u.push(w),p.push(this.sheet.cells[w]??null);}d.push(p);}return {start:{row:r,col:s},end:{row:l,col:i},cells:d,cellRefs:u}}notifyChange(){this.onChange&&this.onChange(this.getSelection());}};var X=class{selection;virtualScroll;config;onScroll;onCopy;constructor(e,t,r,l){this.selection=e,this.virtualScroll=t,this.config=r,this.onScroll=l?.onScroll??null,this.onCopy=l?.onCopy??null;}handleKeyDown(e){if(!this.config.enabled)return false;let t=this.getAction(e);return t?(e.preventDefault(),this.executeAction(t),true):false}getAction(e){let{key:t,shiftKey:r,ctrlKey:l,metaKey:s}=e,i=l||s;if(i&&t==="c")return "copy";if(i&&t==="a")return "select-all";if(r)switch(t){case "ArrowUp":return "extend-up";case "ArrowDown":return "extend-down";case "ArrowLeft":return "extend-left";case "ArrowRight":return "extend-right"}if(i)switch(t){case "Home":return "move-ctrl-home";case "End":return "move-ctrl-end"}switch(t){case "ArrowUp":return "move-up";case "ArrowDown":return "move-down";case "ArrowLeft":return "move-left";case "ArrowRight":return "move-right";case "PageUp":return "move-page-up";case "PageDown":return "move-page-down";case "Home":return "move-home";case "End":return "move-end";case "Tab":return r?"move-left":"move-right";case "Enter":return r?"move-up":"move-down"}return null}executeAction(e){let t=this.selection.getSelection();if(!t&&!["select-all","move-ctrl-home"].includes(e)){this.selection.selectCell("A1"),this.scrollToSelection();return}let{row:r,col:l}=t?.start??{row:0,col:0},s=r,i=l;switch(e){case "move-up":s=Math.max(0,r-1);break;case "move-down":s=Math.min(this.virtualScroll.rowCount-1,r+1);break;case "move-left":i=Math.max(0,l-1);break;case "move-right":i=Math.min(this.virtualScroll.colCount-1,l+1);break;case "move-page-up":s=Math.max(0,r-20);break;case "move-page-down":s=Math.min(this.virtualScroll.rowCount-1,r+20);break;case "move-home":i=0;break;case "move-end":i=this.virtualScroll.colCount-1;break;case "move-ctrl-home":s=0,i=0;break;case "move-ctrl-end":s=this.virtualScroll.rowCount-1,i=this.virtualScroll.colCount-1;break;case "select-all":this.selection.selectAll();return;case "copy":this.onCopy?.();return;case "extend-up":case "extend-down":case "extend-left":case "extend-right":this.extendSelection(e);return}this.selection.handleClick(s,i,{shiftKey:false,ctrlKey:false,metaKey:false}),this.scrollToSelection();}extendSelection(e){let t=this.selection.getSelection();if(!t)return;let{row:r,col:l}=t.end;switch(e){case "extend-up":r=Math.max(0,r-1);break;case "extend-down":r=Math.min(this.virtualScroll.rowCount-1,r+1);break;case "extend-left":l=Math.max(0,l-1);break;case "extend-right":l=Math.min(this.virtualScroll.colCount-1,l+1);break}this.selection.handleDrag(r,l),this.scrollToSelection();}scrollToSelection(){let e=this.selection.getSelection();!e||!this.onScroll||this.onScroll(e.start.row,e.start.col);}setVirtualScroll(e){this.virtualScroll=e;}setSelection(e){this.selection=e;}};var G=class{merges;mergeMap;constructor(e=[]){this.merges=[],this.mergeMap=new Map,this.parseMerges(e);}parseMerges(e){for(let t of e){let[r,l]=t.split(":");if(!r||!l)continue;let s=k(r),i=k(l);if(!s||!i)continue;let d={startRow:Math.min(s.row,i.row),startCol:Math.min(s.col,i.col),endRow:Math.max(s.row,i.row),endCol:Math.max(s.col,i.col),cellRef:r};this.merges.push(d);for(let u=d.startRow;u<=d.endRow;u++)for(let h=d.startCol;h<=d.endCol;h++){let p=`${u},${h}`;this.mergeMap.set(p,d);}}}getMergeAt(e,t){return this.mergeMap.get(`${e},${t}`)??null}isMergeMaster(e,t){let r=this.getMergeAt(e,t);return r?r.startRow===e&&r.startCol===t:false}isMergeHidden(e,t){let r=this.getMergeAt(e,t);return r?!(r.startRow===e&&r.startCol===t):false}getMergeMaster(e,t){let r=this.getMergeAt(e,t);return r?{row:r.startRow,col:r.startCol}:null}getMergeRect(e,t,r){let l=this.getMergeAt(e,t);if(!l||!this.isMergeMaster(e,t))return null;let s=r(l.startRow,l.startCol),i=r(l.endRow,l.endCol);return {top:s.top,left:s.left,width:i.left+i.width-s.left,height:i.top+i.height-s.top}}getAllMerges(){return [...this.merges]}getVisibleMerges(e,t,r,l){return this.merges.filter(s=>s.endRow>=e&&s.startRow<=t&&s.endCol>=r&&s.startCol<=l)}update(e){this.merges=[],this.mergeMap.clear(),this.parseMerges(e);}};var Q=class{async copyToClipboard(e){let t=this.formatSelection(e);try{if(navigator.clipboard&&typeof ClipboardItem<"u"){let r=new Blob([t.html],{type:"text/html"}),l=new Blob([t.text],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/html":r,"text/plain":l})]);}else await this.copyWithExecCommand(t.text);}catch{await this.copyWithExecCommand(t.text);}return t}formatSelection(e){let{cells:t}=e,r=[];for(let d of t){let u=d.map(h=>this.getCellValue(h));r.push(u.join(" "));}let l=r.join(`
|
|
2
|
+
`),s=[];for(let d of t){let u=d.map(h=>{let p=this.escapeHtml(this.getCellValue(h));return `<td style="${this.getCellStyle(h)}">${p}</td>`});s.push(`<tr>${u.join("")}</tr>`);}let i=`
|
|
3
|
+
<table style="border-collapse: collapse; font-family: Arial, sans-serif; font-size: 12px;">
|
|
4
|
+
<tbody>
|
|
5
|
+
${s.join(`
|
|
6
|
+
`)}
|
|
7
|
+
</tbody>
|
|
8
|
+
</table>
|
|
9
|
+
`.trim();return {text:l,html:i,cells:t}}getCellValue(e){return !e||e.v===void 0||e.v===null?"":String(e.v)}getCellStyle(e){let t=["border: 1px solid #ccc","padding: 4px 8px"];return e?.t==="n"&&t.push("text-align: right"),t.join("; ")}escapeHtml(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}async copyWithExecCommand(e){let t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.left="-9999px",document.body.appendChild(t),t.select();try{document.execCommand("copy");}finally{document.body.removeChild(t);}}};var Z=class{sheet;results;currentIndex;constructor(e){this.sheet=e,this.results=[],this.currentIndex=-1;}search(e,t={}){if(!e)return this.results=[],this.currentIndex=-1,[];let{caseSensitive:r=false,regex:l=false,matchWholeCell:s=false}=t,i;try{if(l)i=new RegExp(e,r?"g":"gi");else {let u=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),h=s?`^${u}$`:u;i=new RegExp(h,r?"g":"gi");}}catch{let u=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");i=new RegExp(u,r?"g":"gi");}let d=[];for(let[u,h]of Object.entries(this.sheet.cells)){if(h.v===void 0||h.v===null)continue;let p=String(h.v);i.lastIndex=0;let m=i.exec(p);if(m){let w=this.parseCellRef(u);w&&d.push({row:w.row,col:w.col,cellRef:u,value:p,matchStart:m.index,matchEnd:m.index+m[0].length});}}return d.sort((u,h)=>u.row!==h.row?u.row-h.row:u.col-h.col),this.results=d,this.currentIndex=d.length>0?0:-1,d}next(){return this.results.length===0?null:(this.currentIndex=(this.currentIndex+1)%this.results.length,this.results[this.currentIndex])}previous(){return this.results.length===0?null:(this.currentIndex=(this.currentIndex-1+this.results.length)%this.results.length,this.results[this.currentIndex])}current(){return this.currentIndex<0||this.currentIndex>=this.results.length?null:this.results[this.currentIndex]}getResults(){return [...this.results]}getCount(){return this.results.length}getCurrentIndex(){return this.currentIndex+1}isResult(e,t){return this.results.some(r=>r.row===e&&r.col===t)}isCurrent(e,t){let r=this.current();return r?.row===e&&r?.col===t}clear(){this.results=[],this.currentIndex=-1;}setSheet(e){this.sheet=e,this.clear();}parseCellRef(e){let t=e.match(/^([A-Z]+)(\d+)$/i);if(!t)return null;let r=t[1].toUpperCase(),l=parseInt(t[2],10)-1,s=0;for(let i=0;i<r.length;i++)s=s*26+(r.charCodeAt(i)-64);return s-=1,{row:l,col:s}}};var Y=class{state=null;virtualScroll;onChange;minWidth;maxWidth;constructor(e,t,r=30,l=500){this.virtualScroll=e,this.onChange=t??null,this.minWidth=r,this.maxWidth=l;}startResize(e,t){let r=this.virtualScroll.getColWidth(e);this.state={isResizing:true,colIndex:e,startX:t,startWidth:r},document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp),document.body.style.cursor="col-resize",document.body.style.userSelect="none";}handleMouseMove=e=>{if(!this.state)return;let t=e.clientX-this.state.startX,r=Math.min(this.maxWidth,Math.max(this.minWidth,this.state.startWidth+t));this.virtualScroll.setColWidth(this.state.colIndex,r),this.onChange?.(this.state.colIndex,r);};handleMouseUp=()=>{this.cleanup();};isResizing(){return this.state?.isResizing??false}getResizeColumn(){return this.state?.colIndex??null}cancel(){this.state&&(this.virtualScroll.setColWidth(this.state.colIndex,this.state.startWidth),this.onChange?.(this.state.colIndex,this.state.startWidth)),this.cleanup();}cleanup(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp),document.body.style.cursor="",document.body.style.userSelect="",this.state=null;}setVirtualScroll(e){this.virtualScroll=e;}destroy(){this.cleanup();}};var ne={default:{name:"default",colors:{background:"#ffffff",foreground:"#202124",grid:"#e0e0e0",headerBackground:"#f8f9fa",headerForeground:"#5f6368",selectionBorder:"#1a73e8",selectionBackground:"rgba(26, 115, 232, 0.08)",frozenBorder:"#dadce0"},fonts:{family:"'Google Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",size:"13px",headerSize:"11px"}},excel:{name:"excel",colors:{background:"#ffffff",foreground:"#000000",grid:"#d4d4d4",headerBackground:"#f0f0f0",headerForeground:"#000000",selectionBorder:"#217346",selectionBackground:"rgba(33, 115, 70, 0.1)",frozenBorder:"#9bc2e6"},fonts:{family:"'Calibri', 'Segoe UI', sans-serif",size:"11px",headerSize:"11px"}},modern:{name:"modern",colors:{background:"#fafafa",foreground:"#18181b",grid:"#e4e4e7",headerBackground:"#f4f4f5",headerForeground:"#71717a",selectionBorder:"#3b82f6",selectionBackground:"rgba(59, 130, 246, 0.08)",frozenBorder:"#a1a1aa"},fonts:{family:"'Inter', -apple-system, BlinkMacSystemFont, sans-serif",size:"13px",headerSize:"11px"}},minimal:{name:"minimal",colors:{background:"#ffffff",foreground:"#27272a",grid:"#f4f4f5",headerBackground:"#ffffff",headerForeground:"#a1a1aa",selectionBorder:"#18181b",selectionBackground:"rgba(24, 24, 27, 0.04)",frozenBorder:"#e4e4e7"},fonts:{family:"'SF Pro Display', -apple-system, BlinkMacSystemFont, sans-serif",size:"13px",headerSize:"11px"}},dark:{name:"dark",colors:{background:"#1e1e1e",foreground:"#d4d4d4",grid:"#3c3c3c",headerBackground:"#252526",headerForeground:"#858585",selectionBorder:"#0078d4",selectionBackground:"rgba(0, 120, 212, 0.2)",frozenBorder:"#4a4a4a"},fonts:{family:"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",size:"13px",headerSize:"11px"}},midnight:{name:"midnight",colors:{background:"#0d1117",foreground:"#c9d1d9",grid:"#21262d",headerBackground:"#161b22",headerForeground:"#8b949e",selectionBorder:"#58a6ff",selectionBackground:"rgba(88, 166, 255, 0.15)",frozenBorder:"#30363d"},fonts:{family:"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",size:"13px",headerSize:"11px"}},accessible:{name:"accessible",colors:{background:"#ffffff",foreground:"#000000",grid:"#000000",headerBackground:"#e6e6e6",headerForeground:"#000000",selectionBorder:"#0000ff",selectionBackground:"rgba(0, 0, 255, 0.15)",frozenBorder:"#000000"},fonts:{family:"Arial, Helvetica, sans-serif",size:"14px",headerSize:"12px"}}};function Ie(b,e){let t=b.style;t.setProperty("--nup-background",e.colors.background),t.setProperty("--nup-foreground",e.colors.foreground),t.setProperty("--nup-grid",e.colors.grid),t.setProperty("--nup-header-bg",e.colors.headerBackground),t.setProperty("--nup-header-fg",e.colors.headerForeground),t.setProperty("--nup-selection-border",e.colors.selectionBorder),t.setProperty("--nup-selection-bg",e.colors.selectionBackground),t.setProperty("--nup-frozen-border",e.colors.frozenBorder),t.setProperty("--nup-font-family",e.fonts.family),t.setProperty("--nup-font-size",e.fonts.size);}function He(b){return `nup-theme-${b}`}var ot=forwardRef(function(e,t){let{workbook:r,activeSheet:l=0,theme:s="default",width:i="100%",height:d="400px",className:u="",style:h={},showHeaders:p=true,showGridLines:m=true,showSheetTabs:w=true,selectable:L=true,resizable:K=true,searchable:Ee=false,copyable:se=true,keyboardNavigation:le=true,frozenRows:ie=0,frozenCols:ae=0,overscan:ce=5,defaultRowHeight:he=24,defaultColWidth:ue=100,ariaLabel:Ke="Spreadsheet",onCellClick:de,onCellDoubleClick:me,onCellRightClick:fe,onSelectionChange:pe,onSheetChange:ge,onColumnResize:be,onScroll:we,onSearch:ve,onCopy:D}=e,J=useRef(null),H=useRef(null),[F,Ce]=useState(l),[W,$e]=useState({top:0,left:0}),[v,ye]=useState({width:0,height:0}),[S,Re]=useState(null),[_,q]=useState([]),[Le,Se]=useState(""),[De,ee]=useState(0),g=r.sheets[F]??r.sheets[0],xe=useMemo(()=>typeof s=="string"?ne[s]??ne.default:s,[s]),f=useMemo(()=>{let o={},n={};return Object.entries(g.rows).forEach(([a,c])=>{c.h&&(o[parseInt(a)]=c.h);}),Object.entries(g.cols).forEach(([a,c])=>{c.w&&(n[parseInt(a)]=c.w);}),new j({rows:g.rowCount,cols:g.colCount,rowHeights:o,colWidths:n,defaultRowHeight:he,defaultColWidth:ue,overscan:ce,frozenRows:ie,frozenCols:ae})},[g,he,ue,ce,ie,ae,De]),C=useMemo(()=>new O(g,o=>{Re(o),pe?.(o);}),[g,pe]),Me=useMemo(()=>new G(g.merges??[]),[g.merges]),T=useMemo(()=>new Z(g),[g]),V=useMemo(()=>new Q,[]),U=useMemo(()=>new Y(f,(o,n)=>{ee(a=>a+1),be?.(o,n);}),[f,be]),ke=useMemo(()=>new X(C,f,{enabled:le},{onScroll:(o,n)=>{let a=f.getScrollToPosition(o,n,v.height,v.width);H.current?.scrollTo({top:a.scrollTop,left:a.scrollLeft,behavior:"smooth"});},onCopy:async()=>{let o=C.getSelection();if(o&&se){let n=await V.copyToClipboard(o);D?.(n);}}}),[C,f,le,se,v,V,D]);useLayoutEffect(()=>{let o=H.current;if(!o)return;let n=new ResizeObserver(a=>{let c=a[0];c&&ye({width:c.contentRect.width,height:c.contentRect.height});});return n.observe(o),ye({width:o.clientWidth,height:o.clientHeight}),()=>n.disconnect()},[]),useEffect(()=>{J.current&&Ie(J.current,xe);},[xe]),useEffect(()=>{Ce(l);},[l]);let Fe=useCallback(o=>{let{scrollTop:n,scrollLeft:a}=o.currentTarget;$e({top:n,left:a});let c=f.getVisibleRange(n,a,v.height,v.width);we?.({scrollTop:n,scrollLeft:a,visibleRows:{start:c.startRow,end:c.endRow},visibleCols:{start:c.startCol,end:c.endCol}});},[f,v,we]),Ve=useCallback((o,n,a)=>{if(!L)return;let c=M(o,n),y=g.cells[c]??null;C.handleClick(o,n,{shiftKey:a.shiftKey,ctrlKey:a.ctrlKey,metaKey:a.metaKey}),de?.({cell:y,row:o,col:n,cellRef:c,originalEvent:a.nativeEvent});},[L,g,C,de]),Ue=useCallback((o,n,a)=>{let c=M(o,n),y=g.cells[c]??null;me?.({cell:y,row:o,col:n,cellRef:c,originalEvent:a.nativeEvent});},[g,me]),je=useCallback((o,n,a)=>{a.preventDefault();let c=M(o,n),y=g.cells[c]??null;fe?.({cell:y,row:o,col:n,cellRef:c,originalEvent:a.nativeEvent});},[g,fe]),Oe=useCallback(o=>{ke.handleKeyDown(o.nativeEvent);},[ke]),te=useCallback(o=>{Ce(o),C.clear(),ge?.(o);},[C,ge]),oe=useCallback(o=>{Se(o);let n=T.search(o);q(n),ve?.(n);},[T,ve]),Xe=useCallback((o,n)=>{K&&(n.preventDefault(),n.stopPropagation(),U.startResize(o,n.clientX));},[K,U]);useImperativeHandle(t,()=>({scrollTo:(o,n)=>{let a=f.getScrollToPosition(o,n,v.height,v.width);H.current?.scrollTo({top:a.scrollTop,left:a.scrollLeft,behavior:"smooth"});},scrollToCell:o=>{let n=k(o);if(n){let a=f.getScrollToPosition(n.row,n.col,v.height,v.width);H.current?.scrollTo({top:a.scrollTop,left:a.scrollLeft,behavior:"smooth"});}},select:o=>{Re(o);},selectCell:o=>{C.selectCell(o);},selectAll:()=>{C.selectAll();},clearSelection:()=>{C.clear();},getSelection:()=>S,setActiveSheet:te,getActiveSheet:()=>F,search:o=>(oe(o),T.getResults()),highlightResults:o=>{q(o);},clearHighlights:()=>{q([]),Se("");},getWorkbook:()=>r,getVisibleCells:()=>{let o=f.getVisibleRange(W.top,W.left,v.height,v.width),n=[];for(let a=o.startRow;a<=o.endRow;a++){let c=[];for(let y=o.startCol;y<=o.endCol;y++)c.push(g.cells[M(a,y)]??null);n.push(c);}return n},getCellAt:(o,n)=>g.cells[M(o,n)]??null,copySelection:async()=>{let o=C.getSelection();if(o){let n=await V.copyToClipboard(o);D?.(n);}},setColumnWidth:(o,n)=>{f.setColWidth(o,n),ee(a=>a+1);},autoFitColumn:()=>{},autoFitAllColumns:()=>{},refresh:()=>ee(o=>o+1),destroy:()=>{U.destroy();}}),[f,v,C,T,V,te,oe,F,S,r,g,W,U,D]);let A=p?24:0,B=p?40:0,z=f.getVisibleRange(W.top,W.left,v.height,v.width),ze=[];for(let o=z.startRow;o<=z.endRow;o++)for(let n=z.startCol;n<=z.endCol;n++){if(Me.isMergeHidden(o,n))continue;let a=Me.getMergeRect(o,n,(x,Je)=>f.getCellRect(x,Je))??f.getCellRect(o,n),c=M(o,n),y=g.cells[c],Qe=C.isCellSelected(o,n),Te=C.isAnchor(o,n),Ze=_.some(x=>x.row===o&&x.col===n),Ye=T.isCurrent(o,n),E="nup-cell";y?.t==="n"&&(E+=" nup-cell-number"),Qe&&(E+=" nup-cell-selected"),Te&&(E+=" nup-cell-anchor"),Ze&&(E+=" nup-cell-search-result"),Ye&&(E+=" nup-cell-search-current"),ze.push(jsx("div",{className:E,style:{top:a.top,left:a.left,width:a.width,height:a.height},onClick:x=>Ve(o,n,x),onDoubleClick:x=>Ue(o,n,x),onContextMenu:x=>je(o,n,x),"data-row":o,"data-col":n,"data-cell-ref":c,role:"gridcell","aria-rowindex":o+1,"aria-colindex":n+1,tabIndex:Te?0:-1,children:y?.v!==void 0&&y?.v!==null?String(y.v):""},`${o}-${n}`));}let Ne=[];if(p)for(let o=z.startCol;o<=z.endCol;o++){let n=f.getCellRect(0,o),a=S&&o>=S.start.col&&o<=S.end.col;Ne.push(jsxs("div",{className:`nup-header nup-header-col${a?" nup-header-selected":""}`,style:{left:n.left,width:n.width,height:A},children:[re(o),K&&jsx("div",{className:"nup-resize-handle",onMouseDown:c=>Xe(o,c)})]},`ch-${o}`));}let Pe=[];if(p)for(let o=z.startRow;o<=z.endRow;o++){let n=f.getCellRect(o,0),a=S&&o>=S.start.row&&o<=S.end.row;Pe.push(jsx("div",{className:`nup-header nup-header-row${a?" nup-header-selected":""}`,style:{top:n.top,width:B,height:n.height},children:o+1},`rh-${o}`));}let We=null;if(S){let o=f.getCellRect(S.start.row,S.start.col),n=f.getCellRect(S.end.row,S.end.col);We=jsx("div",{className:"nup-selection-border",style:{top:o.top,left:o.left,width:n.left+n.width-o.left,height:n.top+n.height-o.top}});}let Ge=typeof s=="string"?He(s):"";return jsxs("div",{ref:J,className:`nup-spreadsheet ${Ge} ${u} ${m?"":"nup-no-gridlines"}`,style:{width:i,height:d,...h},tabIndex:0,onKeyDown:Oe,role:"grid","aria-label":Ke,"aria-rowcount":g.rowCount,"aria-colcount":g.colCount,children:[Ee&&jsxs("div",{className:"nup-search-bar",children:[jsx("input",{type:"search",className:"nup-search-input",placeholder:"Search...",value:Le,onChange:o=>oe(o.target.value),"aria-label":"Search in spreadsheet"}),_.length>0&&jsxs("span",{className:"nup-search-count",children:[T.getCurrentIndex()," of ",_.length]}),jsx("button",{className:"nup-search-btn",onClick:()=>{let o=T.next();if(o){let n=f.getScrollToPosition(o.row,o.col,v.height,v.width);H.current?.scrollTo({top:n.scrollTop,left:n.scrollLeft,behavior:"smooth"});}},"aria-label":"Next result",children:"Next"})]}),p&&jsx("div",{className:"nup-corner",style:{width:B,height:A}}),p&&jsx("div",{className:"nup-header-row-container",style:{position:"absolute",top:0,left:B,right:0,height:A,overflow:"hidden"},children:jsx("div",{style:{position:"relative",width:f.totalWidth,height:A,transform:`translateX(${-W.left}px)`},children:Ne})}),p&&jsx("div",{className:"nup-header-col-container",style:{position:"absolute",top:A,left:0,bottom:w?32:0,width:B,overflow:"hidden"},children:jsx("div",{style:{position:"relative",width:B,height:f.totalHeight,transform:`translateY(${-W.top}px)`},children:Pe})}),jsx("div",{ref:H,className:"nup-scroll-container",style:{top:A,left:B,right:0,bottom:w?32:0},onScroll:Fe,children:jsxs("div",{className:"nup-content",style:{width:f.totalWidth,height:f.totalHeight},children:[ze,We]})}),w&&r.sheets.length>1&&jsx("div",{className:"nup-sheet-tabs",children:r.sheets.map((o,n)=>jsx("button",{className:`nup-sheet-tab${n===F?" nup-sheet-tab-active":""}`,onClick:()=>te(n),children:o.name},o.id))})]})}),xt=ot;export{ot as NupSpreadsheetPreview,xt as default};//# sourceMappingURL=react.js.map
|
|
10
|
+
//# sourceMappingURL=react.js.map
|