@pixerate/editor-react 0.16.0 → 0.17.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 +2 -2
- package/dist/canvas/index.cjs +406 -142
- package/dist/canvas/index.cjs.map +1 -1
- package/dist/canvas/index.d.cts +66 -3
- package/dist/canvas/index.d.ts +66 -3
- package/dist/canvas/index.js +277 -0
- package/dist/canvas/index.js.map +1 -1
- package/dist/chunk-I3E4KSA2.js +515 -0
- package/dist/chunk-I3E4KSA2.js.map +1 -0
- package/dist/chunk-JR5ZBDR7.js +2012 -0
- package/dist/chunk-JR5ZBDR7.js.map +1 -0
- package/dist/{chunk-XTFR3IMK.js → chunk-ZU54BMDC.js} +473 -160
- package/dist/chunk-ZU54BMDC.js.map +1 -0
- package/dist/generation/index.cjs +290 -0
- package/dist/generation/index.cjs.map +1 -1
- package/dist/generation/index.d.cts +66 -2
- package/dist/generation/index.d.ts +66 -2
- package/dist/generation/index.js +7 -1
- package/dist/image-editor/index.cjs +490 -187
- package/dist/image-editor/index.cjs.map +1 -1
- package/dist/image-editor/index.d.cts +34 -2
- package/dist/image-editor/index.d.ts +34 -2
- package/dist/image-editor/index.js +5 -1
- package/dist/index.cjs +2372 -731
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -6
- package/dist/index.d.ts +88 -6
- package/dist/index.js +334 -96
- package/dist/index.js.map +1 -1
- package/dist/spreadsheet/index.cjs +943 -112
- package/dist/spreadsheet/index.cjs.map +1 -1
- package/dist/spreadsheet/index.d.cts +119 -7
- package/dist/spreadsheet/index.d.ts +119 -7
- package/dist/spreadsheet/index.js +11 -1
- package/dist/tokens/index.cjs +395 -0
- package/dist/tokens/index.cjs.map +1 -0
- package/dist/tokens/index.d.cts +54 -0
- package/dist/tokens/index.d.ts +54 -0
- package/dist/tokens/index.js +375 -0
- package/dist/tokens/index.js.map +1 -0
- package/package.json +10 -2
- package/dist/chunk-7SPRQZ6H.js +0 -216
- package/dist/chunk-7SPRQZ6H.js.map +0 -1
- package/dist/chunk-FYIPXHAE.js +0 -1169
- package/dist/chunk-FYIPXHAE.js.map +0 -1
- package/dist/chunk-XTFR3IMK.js.map +0 -1
package/dist/chunk-FYIPXHAE.js
DELETED
|
@@ -1,1169 +0,0 @@
|
|
|
1
|
-
// src/spreadsheet/useSpreadsheetEditor.ts
|
|
2
|
-
import { useState, useRef, useCallback, useMemo } from "react";
|
|
3
|
-
import {
|
|
4
|
-
SpreadsheetController,
|
|
5
|
-
bindSpreadsheetTableActions
|
|
6
|
-
} from "@pixerate/editor/spreadsheet";
|
|
7
|
-
function useSpreadsheetEditor(options = {}) {
|
|
8
|
-
const optionsRef = useRef(options);
|
|
9
|
-
optionsRef.current = options;
|
|
10
|
-
const settersRef = useRef({});
|
|
11
|
-
const [controller] = useState(
|
|
12
|
-
() => new SpreadsheetController({
|
|
13
|
-
...options,
|
|
14
|
-
onDocumentChange: (updated) => {
|
|
15
|
-
settersRef.current.setDoc?.({ ...updated });
|
|
16
|
-
optionsRef.current.onDocumentChange?.(updated);
|
|
17
|
-
},
|
|
18
|
-
onSelectionChange: (active, range) => {
|
|
19
|
-
settersRef.current.setActiveCell?.(active);
|
|
20
|
-
settersRef.current.setSelectedRange?.(range);
|
|
21
|
-
optionsRef.current.onSelectionChange?.(active, range);
|
|
22
|
-
},
|
|
23
|
-
onCellCommit: (rowId, colId, raw, value) => {
|
|
24
|
-
optionsRef.current.onCellCommit?.(rowId, colId, raw, value);
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
);
|
|
28
|
-
const [doc, setDoc] = useState(() => ({ ...controller.document }));
|
|
29
|
-
const [activeCell, setActiveCell] = useState(controller.activeCell);
|
|
30
|
-
const [selectedRange, setSelectedRange] = useState(controller.selectedRange);
|
|
31
|
-
const [editingCell, setEditingCell] = useState(null);
|
|
32
|
-
const [draftValue, setDraftState] = useState("");
|
|
33
|
-
settersRef.current = { setDoc, setActiveCell, setSelectedRange };
|
|
34
|
-
const setDraftValue = useCallback((value) => {
|
|
35
|
-
controller.draftValue = value;
|
|
36
|
-
setDraftState(value);
|
|
37
|
-
}, [controller]);
|
|
38
|
-
const setCellValue = useCallback((rowId, colId, raw) => {
|
|
39
|
-
controller.setCellValue(rowId, colId, raw);
|
|
40
|
-
setDoc({ ...controller.document });
|
|
41
|
-
}, [controller]);
|
|
42
|
-
const selectCell = useCallback((row, col, extendSelection = false) => {
|
|
43
|
-
controller.selectCell(row, col, extendSelection);
|
|
44
|
-
setActiveCell(controller.activeCell);
|
|
45
|
-
setSelectedRange(controller.selectedRange);
|
|
46
|
-
}, [controller]);
|
|
47
|
-
const selectRange = useCallback((range) => {
|
|
48
|
-
controller.selectRange(range);
|
|
49
|
-
setSelectedRange(controller.selectedRange);
|
|
50
|
-
}, [controller]);
|
|
51
|
-
const startEditing = useCallback((row, col, initialVal) => {
|
|
52
|
-
controller.startEditing(row, col, initialVal);
|
|
53
|
-
setActiveCell(controller.activeCell);
|
|
54
|
-
setEditingCell(controller.editingCell);
|
|
55
|
-
setDraftValue(controller.draftValue);
|
|
56
|
-
}, [controller]);
|
|
57
|
-
const commitEditing = useCallback((val) => {
|
|
58
|
-
controller.commitEditing(val);
|
|
59
|
-
setEditingCell(null);
|
|
60
|
-
setDraftValue("");
|
|
61
|
-
setDoc({ ...controller.document });
|
|
62
|
-
}, [controller]);
|
|
63
|
-
const cancelEditing = useCallback(() => {
|
|
64
|
-
controller.cancelEditing();
|
|
65
|
-
setEditingCell(null);
|
|
66
|
-
setDraftValue("");
|
|
67
|
-
}, [controller]);
|
|
68
|
-
const moveCursor = useCallback((dir, extend = false) => {
|
|
69
|
-
controller.moveCursor(dir, extend);
|
|
70
|
-
setActiveCell(controller.activeCell);
|
|
71
|
-
setSelectedRange(controller.selectedRange);
|
|
72
|
-
}, [controller]);
|
|
73
|
-
const insertColumn = useCallback((index, config) => {
|
|
74
|
-
controller.insertColumn(index, config);
|
|
75
|
-
setDoc({ ...controller.document });
|
|
76
|
-
}, [controller]);
|
|
77
|
-
const deleteColumn = useCallback((colId) => {
|
|
78
|
-
controller.deleteColumn(colId);
|
|
79
|
-
setDoc({ ...controller.document });
|
|
80
|
-
}, [controller]);
|
|
81
|
-
const insertRow = useCallback((index, config) => {
|
|
82
|
-
controller.insertRow(index, config);
|
|
83
|
-
setDoc({ ...controller.document });
|
|
84
|
-
}, [controller]);
|
|
85
|
-
const deleteRow = useCallback((rowId) => {
|
|
86
|
-
controller.deleteRow(rowId);
|
|
87
|
-
setDoc({ ...controller.document });
|
|
88
|
-
}, [controller]);
|
|
89
|
-
const setColumnWidth = useCallback((colId, width) => {
|
|
90
|
-
controller.setColumnWidth(colId, width);
|
|
91
|
-
setDoc({ ...controller.document });
|
|
92
|
-
}, [controller]);
|
|
93
|
-
const autoFitColumnWidth = useCallback((colId, customWidth) => {
|
|
94
|
-
controller.autoFitColumnWidth(colId, customWidth);
|
|
95
|
-
setDoc({ ...controller.document });
|
|
96
|
-
}, [controller]);
|
|
97
|
-
const registerDataSource = useCallback((ds) => {
|
|
98
|
-
controller.registerDataSource(ds);
|
|
99
|
-
setDoc({ ...controller.document });
|
|
100
|
-
}, [controller]);
|
|
101
|
-
const setPrimaryDataSource = useCallback((id) => {
|
|
102
|
-
controller.setPrimaryDataSource(id);
|
|
103
|
-
setDoc({ ...controller.document });
|
|
104
|
-
}, [controller]);
|
|
105
|
-
const recalculateAll = useCallback(() => {
|
|
106
|
-
controller.recalculateAll();
|
|
107
|
-
setDoc({ ...controller.document });
|
|
108
|
-
}, [controller]);
|
|
109
|
-
const undo = useCallback(() => {
|
|
110
|
-
controller.undo();
|
|
111
|
-
setDoc({ ...controller.document });
|
|
112
|
-
}, [controller]);
|
|
113
|
-
const redo = useCallback(() => {
|
|
114
|
-
controller.redo();
|
|
115
|
-
setDoc({ ...controller.document });
|
|
116
|
-
}, [controller]);
|
|
117
|
-
const tableActions = useMemo(() => bindSpreadsheetTableActions(controller), [controller]);
|
|
118
|
-
const viewModel = useMemo(() => controller.getViewModel(), [controller, doc]);
|
|
119
|
-
return {
|
|
120
|
-
document: doc,
|
|
121
|
-
activeCell,
|
|
122
|
-
selectedRange,
|
|
123
|
-
editingCell,
|
|
124
|
-
draftValue,
|
|
125
|
-
setDraftValue,
|
|
126
|
-
controller,
|
|
127
|
-
getCell: (rowId, colId) => controller.getCell(rowId, colId),
|
|
128
|
-
setCellValue,
|
|
129
|
-
selectCell,
|
|
130
|
-
selectRange,
|
|
131
|
-
startEditing,
|
|
132
|
-
commitEditing,
|
|
133
|
-
cancelEditing,
|
|
134
|
-
moveCursor,
|
|
135
|
-
insertColumn,
|
|
136
|
-
deleteColumn,
|
|
137
|
-
insertRow,
|
|
138
|
-
deleteRow,
|
|
139
|
-
setColumnWidth,
|
|
140
|
-
autoFitColumnWidth,
|
|
141
|
-
loadDocument: (document2) => {
|
|
142
|
-
controller.loadDocument(document2);
|
|
143
|
-
setDoc({ ...controller.document });
|
|
144
|
-
setActiveCell(null);
|
|
145
|
-
setSelectedRange(null);
|
|
146
|
-
setEditingCell(null);
|
|
147
|
-
setDraftValue("");
|
|
148
|
-
},
|
|
149
|
-
syncWithDataSource: () => {
|
|
150
|
-
controller.syncWithDataSource();
|
|
151
|
-
controller.recalculateAll();
|
|
152
|
-
setDoc({ ...controller.document });
|
|
153
|
-
},
|
|
154
|
-
registerDataSource,
|
|
155
|
-
setPrimaryDataSource,
|
|
156
|
-
recalculateAll,
|
|
157
|
-
exportToTsv: (range) => controller.exportToTsv(range),
|
|
158
|
-
importFromTsv: (data) => {
|
|
159
|
-
controller.importFromTsv(data);
|
|
160
|
-
setDoc({ ...controller.document });
|
|
161
|
-
},
|
|
162
|
-
...tableActions,
|
|
163
|
-
viewModel,
|
|
164
|
-
undo,
|
|
165
|
-
redo
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// src/spreadsheet/SpreadsheetEditor.tsx
|
|
170
|
-
import { useRef as useRef5, useState as useState5, useMemo as useMemo3, useEffect as useEffect4, useCallback as useCallback3 } from "react";
|
|
171
|
-
import {
|
|
172
|
-
indexToColName,
|
|
173
|
-
getSpreadsheetMenuItems,
|
|
174
|
-
normalizeRange as normalizeRange2,
|
|
175
|
-
rangeContains,
|
|
176
|
-
formatCellForDisplay,
|
|
177
|
-
numberFormatColorToCss
|
|
178
|
-
} from "@pixerate/editor/spreadsheet";
|
|
179
|
-
|
|
180
|
-
// src/spreadsheet/SpreadsheetContextMenu.tsx
|
|
181
|
-
import React, { useEffect, useLayoutEffect, useRef as useRef2, useState as useState2 } from "react";
|
|
182
|
-
import { clampMenuPosition, runSpreadsheetMenuItem } from "@pixerate/editor/spreadsheet";
|
|
183
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
184
|
-
var VIEWPORT_MARGIN = 4;
|
|
185
|
-
var SpreadsheetContextMenu = ({ items, x, y, onClose }) => {
|
|
186
|
-
const menuRef = useRef2(null);
|
|
187
|
-
const onCloseRef = useRef2(onClose);
|
|
188
|
-
onCloseRef.current = onClose;
|
|
189
|
-
const [position, setPosition] = useState2({ x, y });
|
|
190
|
-
useLayoutEffect(() => {
|
|
191
|
-
const menu = menuRef.current;
|
|
192
|
-
if (!menu || typeof window === "undefined") return;
|
|
193
|
-
const { width, height } = menu.getBoundingClientRect();
|
|
194
|
-
const next = clampMenuPosition(
|
|
195
|
-
{ x, y },
|
|
196
|
-
{ width, height },
|
|
197
|
-
{ width: window.innerWidth, height: window.innerHeight },
|
|
198
|
-
VIEWPORT_MARGIN
|
|
199
|
-
);
|
|
200
|
-
setPosition((prev) => prev.x === next.x && prev.y === next.y ? prev : next);
|
|
201
|
-
}, [x, y, items]);
|
|
202
|
-
useEffect(() => {
|
|
203
|
-
const handlePointer = (e) => {
|
|
204
|
-
if (!menuRef.current?.contains(e.target)) onCloseRef.current();
|
|
205
|
-
};
|
|
206
|
-
const handleKey = (e) => {
|
|
207
|
-
if (e.key === "Escape") onCloseRef.current();
|
|
208
|
-
};
|
|
209
|
-
window.addEventListener("mousedown", handlePointer);
|
|
210
|
-
window.addEventListener("keydown", handleKey);
|
|
211
|
-
return () => {
|
|
212
|
-
window.removeEventListener("mousedown", handlePointer);
|
|
213
|
-
window.removeEventListener("keydown", handleKey);
|
|
214
|
-
};
|
|
215
|
-
}, []);
|
|
216
|
-
return /* @__PURE__ */ jsx(
|
|
217
|
-
"div",
|
|
218
|
-
{
|
|
219
|
-
ref: menuRef,
|
|
220
|
-
role: "menu",
|
|
221
|
-
"aria-label": "Table actions",
|
|
222
|
-
className: "fixed z-50 min-w-[14rem] rounded-md border border-border bg-popover py-1 text-xs text-popover-foreground shadow-lg",
|
|
223
|
-
style: {
|
|
224
|
-
left: position.x,
|
|
225
|
-
top: position.y,
|
|
226
|
-
maxHeight: `calc(100vh - ${VIEWPORT_MARGIN * 2}px)`,
|
|
227
|
-
overflowY: "auto",
|
|
228
|
-
background: "var(--popover, var(--background, #fff))"
|
|
229
|
-
},
|
|
230
|
-
onContextMenu: (e) => e.preventDefault(),
|
|
231
|
-
onKeyDown: (e) => e.stopPropagation(),
|
|
232
|
-
children: items.map((item) => /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
|
233
|
-
item.separatorBefore && /* @__PURE__ */ jsx("div", { role: "separator", className: "my-1 h-px bg-border" }),
|
|
234
|
-
/* @__PURE__ */ jsx(
|
|
235
|
-
"button",
|
|
236
|
-
{
|
|
237
|
-
type: "button",
|
|
238
|
-
role: "menuitem",
|
|
239
|
-
"data-action": item.id,
|
|
240
|
-
"data-checked": item.checked ? "" : void 0,
|
|
241
|
-
disabled: item.disabled,
|
|
242
|
-
className: `block w-full px-3 py-1 text-left hover:bg-muted disabled:cursor-default disabled:opacity-40 disabled:hover:bg-transparent ${item.checked ? "font-semibold" : ""}`,
|
|
243
|
-
onClick: () => {
|
|
244
|
-
onClose();
|
|
245
|
-
runSpreadsheetMenuItem(item);
|
|
246
|
-
},
|
|
247
|
-
children: item.label
|
|
248
|
-
}
|
|
249
|
-
)
|
|
250
|
-
] }, item.id))
|
|
251
|
-
}
|
|
252
|
-
);
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
// src/spreadsheet/SpreadsheetGroupRow.tsx
|
|
256
|
-
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
257
|
-
var formatSummary = (value) => value === null ? "\u2013" : String(value);
|
|
258
|
-
var SpreadsheetGroupRow = ({
|
|
259
|
-
group,
|
|
260
|
-
columns,
|
|
261
|
-
groupColId,
|
|
262
|
-
onToggle,
|
|
263
|
-
trailingCell
|
|
264
|
-
}) => {
|
|
265
|
-
const labelColId = columns.some((c) => c.column.id === groupColId) ? groupColId : columns[0]?.column.id;
|
|
266
|
-
return /* @__PURE__ */ jsxs2("tr", { className: "border-b border-border bg-muted/40 font-semibold", "data-group-key": group.key, style: { height: 28 }, children: [
|
|
267
|
-
/* @__PURE__ */ jsx2("td", { className: "w-12 min-w-[3rem] sticky left-0 z-10 bg-muted border-r border-border text-center", children: /* @__PURE__ */ jsx2(
|
|
268
|
-
"button",
|
|
269
|
-
{
|
|
270
|
-
type: "button",
|
|
271
|
-
"aria-label": `${group.collapsed ? "Expand" : "Collapse"} group ${group.label}`,
|
|
272
|
-
"aria-expanded": !group.collapsed,
|
|
273
|
-
className: "h-5 w-5 rounded text-[10px] text-muted-foreground hover:bg-muted",
|
|
274
|
-
onClick: (e) => {
|
|
275
|
-
e.stopPropagation();
|
|
276
|
-
onToggle(group.key);
|
|
277
|
-
},
|
|
278
|
-
children: group.collapsed ? "\u25B8" : "\u25BE"
|
|
279
|
-
}
|
|
280
|
-
) }),
|
|
281
|
-
columns.map(({ column }) => {
|
|
282
|
-
const summary = group.summaries[column.id];
|
|
283
|
-
return /* @__PURE__ */ jsx2("td", { className: "border-r border-border px-2 py-1 truncate max-w-0 text-foreground", style: { maxWidth: 0, overflow: "hidden" }, children: column.id === labelColId ? /* @__PURE__ */ jsxs2("span", { className: "truncate", children: [
|
|
284
|
-
group.label,
|
|
285
|
-
" ",
|
|
286
|
-
/* @__PURE__ */ jsxs2("span", { className: "font-normal text-muted-foreground", children: [
|
|
287
|
-
"(",
|
|
288
|
-
group.rowIndices.length,
|
|
289
|
-
")"
|
|
290
|
-
] })
|
|
291
|
-
] }) : summary !== void 0 ? /* @__PURE__ */ jsx2("span", { className: "truncate", "data-summary": column.id, children: formatSummary(summary) }) : null }, column.id);
|
|
292
|
-
}),
|
|
293
|
-
trailingCell && /* @__PURE__ */ jsx2("td", { className: "w-10 min-w-[2.5rem] bg-muted/10 border-r border-border" })
|
|
294
|
-
] });
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
// src/spreadsheet/useSpreadsheetTableInteractions.ts
|
|
298
|
-
import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef3, useState as useState3 } from "react";
|
|
299
|
-
import {
|
|
300
|
-
computeFillTarget,
|
|
301
|
-
normalizeRange
|
|
302
|
-
} from "@pixerate/editor/spreadsheet";
|
|
303
|
-
function gridHasFocus(grid) {
|
|
304
|
-
if (!grid || typeof document === "undefined") return false;
|
|
305
|
-
const active = document.activeElement;
|
|
306
|
-
if (!active || !grid.contains(active)) return false;
|
|
307
|
-
return !(active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement);
|
|
308
|
-
}
|
|
309
|
-
function useSpreadsheetClipboard(gridRef, state, readOnly) {
|
|
310
|
-
const stateRef = useRef3(state);
|
|
311
|
-
stateRef.current = state;
|
|
312
|
-
const readOnlyRef = useRef3(readOnly);
|
|
313
|
-
readOnlyRef.current = readOnly;
|
|
314
|
-
const copiedRef = useRef3(false);
|
|
315
|
-
useEffect2(() => {
|
|
316
|
-
if (typeof document === "undefined") return;
|
|
317
|
-
const handleCopy = (e) => {
|
|
318
|
-
const s = stateRef.current;
|
|
319
|
-
if (!gridHasFocus(gridRef.current) || s.editingCell || !e.clipboardData || !s.selectedRange) return;
|
|
320
|
-
for (const [type, data] of Object.entries(s.copyToClipboardData(s.selectedRange))) {
|
|
321
|
-
e.clipboardData.setData(type, data);
|
|
322
|
-
}
|
|
323
|
-
copiedRef.current = true;
|
|
324
|
-
e.preventDefault();
|
|
325
|
-
};
|
|
326
|
-
const handlePaste = (e) => {
|
|
327
|
-
const s = stateRef.current;
|
|
328
|
-
if (readOnlyRef.current || !gridHasFocus(gridRef.current) || s.editingCell || !e.clipboardData) return;
|
|
329
|
-
if (s.pasteClipboardData(e.clipboardData)) e.preventDefault();
|
|
330
|
-
};
|
|
331
|
-
document.addEventListener("copy", handleCopy);
|
|
332
|
-
document.addEventListener("paste", handlePaste);
|
|
333
|
-
return () => {
|
|
334
|
-
document.removeEventListener("copy", handleCopy);
|
|
335
|
-
document.removeEventListener("paste", handlePaste);
|
|
336
|
-
};
|
|
337
|
-
}, [gridRef]);
|
|
338
|
-
const copyShortcutFallback = useCallback2(() => {
|
|
339
|
-
copiedRef.current = false;
|
|
340
|
-
setTimeout(() => {
|
|
341
|
-
if (copiedRef.current) return;
|
|
342
|
-
const s = stateRef.current;
|
|
343
|
-
Promise.resolve(navigator.clipboard?.writeText(s.exportToTsv(s.selectedRange))).catch(() => {
|
|
344
|
-
});
|
|
345
|
-
}, 0);
|
|
346
|
-
}, []);
|
|
347
|
-
return { copyShortcutFallback };
|
|
348
|
-
}
|
|
349
|
-
function useFillHandle(state) {
|
|
350
|
-
const [drag, setDrag] = useState3(null);
|
|
351
|
-
const dragRef = useRef3(drag);
|
|
352
|
-
dragRef.current = drag;
|
|
353
|
-
const stateRef = useRef3(state);
|
|
354
|
-
stateRef.current = state;
|
|
355
|
-
const dragging = drag !== null;
|
|
356
|
-
useEffect2(() => {
|
|
357
|
-
if (!dragging) return;
|
|
358
|
-
const handleMouseUp = () => {
|
|
359
|
-
const current = dragRef.current;
|
|
360
|
-
setDrag(null);
|
|
361
|
-
if (current?.target) stateRef.current.autofill(current.source, current.target);
|
|
362
|
-
};
|
|
363
|
-
window.addEventListener("mouseup", handleMouseUp);
|
|
364
|
-
return () => window.removeEventListener("mouseup", handleMouseUp);
|
|
365
|
-
}, [dragging]);
|
|
366
|
-
const startFill = useCallback2((e) => {
|
|
367
|
-
e.preventDefault();
|
|
368
|
-
e.stopPropagation();
|
|
369
|
-
const range = stateRef.current.selectedRange;
|
|
370
|
-
if (range) setDrag({ source: normalizeRange(range), target: null });
|
|
371
|
-
}, []);
|
|
372
|
-
const extendFill = useCallback2((row, col) => {
|
|
373
|
-
const current = dragRef.current;
|
|
374
|
-
if (!current) return;
|
|
375
|
-
setDrag({ source: current.source, target: computeFillTarget(current.source, { row, col }) });
|
|
376
|
-
}, []);
|
|
377
|
-
return { fillTarget: drag?.target ?? null, isFilling: dragging, startFill, extendFill };
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// src/spreadsheet/FormulaHints.tsx
|
|
381
|
-
import { useEffect as useEffect3, useLayoutEffect as useLayoutEffect2, useMemo as useMemo2, useRef as useRef4, useState as useState4 } from "react";
|
|
382
|
-
import { applyFormulaSuggestion, getFormulaHints } from "@pixerate/editor/spreadsheet";
|
|
383
|
-
import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
384
|
-
var FormulaHints = ({ inputRef, value, onAccept, limit = 8 }) => {
|
|
385
|
-
const [caret, setCaret] = useState4(null);
|
|
386
|
-
const [focused, setFocused] = useState4(false);
|
|
387
|
-
const [selected, setSelected] = useState4(0);
|
|
388
|
-
const [dismissed, setDismissed] = useState4(false);
|
|
389
|
-
const [position, setPosition] = useState4(null);
|
|
390
|
-
const pendingCaret = useRef4(null);
|
|
391
|
-
const hints = useMemo2(
|
|
392
|
-
() => getFormulaHints(value, caret ?? value.length, { limit }),
|
|
393
|
-
[value, caret, limit]
|
|
394
|
-
);
|
|
395
|
-
const suggestions = dismissed ? [] : hints.suggestions;
|
|
396
|
-
const selectedIndex = Math.max(0, Math.min(selected, suggestions.length - 1));
|
|
397
|
-
const visible = focused && value.trimStart().startsWith("=") && (suggestions.length > 0 || !!hints.activeCall);
|
|
398
|
-
const latest = useRef4({ suggestions, selected: selectedIndex, value, caret, onAccept });
|
|
399
|
-
latest.current = { suggestions, selected: selectedIndex, value, caret, onAccept };
|
|
400
|
-
const accept = (index) => {
|
|
401
|
-
const { suggestions: list, value: current, caret: at, onAccept: commit } = latest.current;
|
|
402
|
-
const suggestion = list[index];
|
|
403
|
-
if (!suggestion) return;
|
|
404
|
-
const next = applyFormulaSuggestion(current, at ?? current.length, suggestion.name);
|
|
405
|
-
pendingCaret.current = next.caret;
|
|
406
|
-
commit(next.value);
|
|
407
|
-
};
|
|
408
|
-
useEffect3(() => {
|
|
409
|
-
const input = inputRef.current;
|
|
410
|
-
if (!input) return;
|
|
411
|
-
const syncCaret = () => setCaret(input.selectionStart ?? input.value.length);
|
|
412
|
-
const onInput = () => {
|
|
413
|
-
setDismissed(false);
|
|
414
|
-
setSelected(0);
|
|
415
|
-
syncCaret();
|
|
416
|
-
};
|
|
417
|
-
const onFocus = () => {
|
|
418
|
-
setFocused(true);
|
|
419
|
-
syncCaret();
|
|
420
|
-
};
|
|
421
|
-
const onBlur = () => setFocused(false);
|
|
422
|
-
const onKeyDown = (e) => {
|
|
423
|
-
const { suggestions: list } = latest.current;
|
|
424
|
-
if (list.length === 0) return;
|
|
425
|
-
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
426
|
-
e.preventDefault();
|
|
427
|
-
e.stopPropagation();
|
|
428
|
-
const step = e.key === "ArrowDown" ? 1 : -1;
|
|
429
|
-
setSelected((i) => (i + step + list.length) % list.length);
|
|
430
|
-
} else if (e.key === "Tab" && !e.shiftKey) {
|
|
431
|
-
e.preventDefault();
|
|
432
|
-
e.stopPropagation();
|
|
433
|
-
accept(latest.current.selected);
|
|
434
|
-
} else if (e.key === "Escape") {
|
|
435
|
-
e.preventDefault();
|
|
436
|
-
e.stopPropagation();
|
|
437
|
-
setDismissed(true);
|
|
438
|
-
}
|
|
439
|
-
};
|
|
440
|
-
input.addEventListener("input", onInput);
|
|
441
|
-
input.addEventListener("keyup", syncCaret);
|
|
442
|
-
input.addEventListener("click", syncCaret);
|
|
443
|
-
input.addEventListener("select", syncCaret);
|
|
444
|
-
input.addEventListener("focus", onFocus);
|
|
445
|
-
input.addEventListener("blur", onBlur);
|
|
446
|
-
input.addEventListener("keydown", onKeyDown);
|
|
447
|
-
if (typeof document !== "undefined" && document.activeElement === input) onFocus();
|
|
448
|
-
return () => {
|
|
449
|
-
input.removeEventListener("input", onInput);
|
|
450
|
-
input.removeEventListener("keyup", syncCaret);
|
|
451
|
-
input.removeEventListener("click", syncCaret);
|
|
452
|
-
input.removeEventListener("select", syncCaret);
|
|
453
|
-
input.removeEventListener("focus", onFocus);
|
|
454
|
-
input.removeEventListener("blur", onBlur);
|
|
455
|
-
input.removeEventListener("keydown", onKeyDown);
|
|
456
|
-
};
|
|
457
|
-
}, [inputRef]);
|
|
458
|
-
useLayoutEffect2(() => {
|
|
459
|
-
const input = inputRef.current;
|
|
460
|
-
const at = pendingCaret.current;
|
|
461
|
-
if (!input || at === null || input.value !== value) return;
|
|
462
|
-
pendingCaret.current = null;
|
|
463
|
-
input.setSelectionRange(at, at);
|
|
464
|
-
setCaret(at);
|
|
465
|
-
setSelected(0);
|
|
466
|
-
}, [value, inputRef]);
|
|
467
|
-
useLayoutEffect2(() => {
|
|
468
|
-
const input = inputRef.current;
|
|
469
|
-
if (!visible || !input) return;
|
|
470
|
-
const rect = input.getBoundingClientRect();
|
|
471
|
-
setPosition({ top: rect.bottom + 2, left: rect.left, width: rect.width });
|
|
472
|
-
}, [visible, value, inputRef]);
|
|
473
|
-
if (!visible) return null;
|
|
474
|
-
const { activeCall } = hints;
|
|
475
|
-
return /* @__PURE__ */ jsxs3(
|
|
476
|
-
"div",
|
|
477
|
-
{
|
|
478
|
-
"data-formula-hints": "",
|
|
479
|
-
className: "rounded-md border border-border bg-popover text-popover-foreground shadow-md text-xs font-sans overflow-hidden",
|
|
480
|
-
style: {
|
|
481
|
-
position: "fixed",
|
|
482
|
-
top: position?.top ?? 0,
|
|
483
|
-
left: position?.left ?? 0,
|
|
484
|
-
minWidth: Math.max(260, position?.width ?? 0),
|
|
485
|
-
maxWidth: 440,
|
|
486
|
-
zIndex: 50,
|
|
487
|
-
visibility: position ? "visible" : "hidden"
|
|
488
|
-
},
|
|
489
|
-
onMouseDown: (e) => e.preventDefault(),
|
|
490
|
-
children: [
|
|
491
|
-
activeCall && /* @__PURE__ */ jsxs3("div", { "data-formula-signature": "", className: "px-2 py-1.5 border-b border-border bg-muted/30", children: [
|
|
492
|
-
/* @__PURE__ */ jsx3("div", { className: "font-mono", children: activeCall.parts.map((part, i) => /* @__PURE__ */ jsx3(
|
|
493
|
-
"span",
|
|
494
|
-
{
|
|
495
|
-
"data-active": part.active ? "" : void 0,
|
|
496
|
-
className: part.active ? "font-bold text-primary underline" : "",
|
|
497
|
-
children: part.text
|
|
498
|
-
},
|
|
499
|
-
i
|
|
500
|
-
)) }),
|
|
501
|
-
/* @__PURE__ */ jsx3("div", { className: "mt-0.5 text-muted-foreground", children: activeCall.argument ? /* @__PURE__ */ jsxs3(Fragment, { children: [
|
|
502
|
-
/* @__PURE__ */ jsx3("span", { className: "font-semibold", children: activeCall.argument.name }),
|
|
503
|
-
": ",
|
|
504
|
-
activeCall.argument.description
|
|
505
|
-
] }) : activeCall.description })
|
|
506
|
-
] }),
|
|
507
|
-
suggestions.length > 0 && /* @__PURE__ */ jsx3("ul", { role: "listbox", "aria-label": "Formula suggestions", className: "max-h-64 overflow-auto py-1 m-0 list-none p-0", children: suggestions.map((s, i) => /* @__PURE__ */ jsxs3(
|
|
508
|
-
"li",
|
|
509
|
-
{
|
|
510
|
-
role: "option",
|
|
511
|
-
"aria-selected": i === selectedIndex,
|
|
512
|
-
className: `cursor-pointer px-2 py-1 ${i === selectedIndex ? "bg-primary/10" : "hover:bg-muted/50"}`,
|
|
513
|
-
onMouseEnter: () => setSelected(i),
|
|
514
|
-
onMouseDown: (e) => {
|
|
515
|
-
e.preventDefault();
|
|
516
|
-
accept(i);
|
|
517
|
-
},
|
|
518
|
-
children: [
|
|
519
|
-
/* @__PURE__ */ jsx3("div", { className: "font-mono font-semibold text-foreground", children: s.signature }),
|
|
520
|
-
/* @__PURE__ */ jsx3("div", { className: "text-muted-foreground truncate", children: s.description })
|
|
521
|
-
]
|
|
522
|
-
},
|
|
523
|
-
s.name
|
|
524
|
-
)) })
|
|
525
|
-
]
|
|
526
|
-
}
|
|
527
|
-
);
|
|
528
|
-
};
|
|
529
|
-
|
|
530
|
-
// src/spreadsheet/SpreadsheetEditor.tsx
|
|
531
|
-
import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
532
|
-
var COLUMN_HEADER_HEIGHT = 28;
|
|
533
|
-
var ROW_HEADER_WIDTH = 48;
|
|
534
|
-
function frozenCellStyle(viewRow, viewCol) {
|
|
535
|
-
if (!viewRow.frozen && !viewCol.frozen) return void 0;
|
|
536
|
-
return {
|
|
537
|
-
position: "sticky",
|
|
538
|
-
...viewRow.frozen ? { top: COLUMN_HEADER_HEIGHT + viewRow.stickyTop } : {},
|
|
539
|
-
...viewCol.frozen ? { left: ROW_HEADER_WIDTH + viewCol.stickyLeft } : {},
|
|
540
|
-
zIndex: viewRow.frozen && viewCol.frozen ? 14 : viewRow.frozen ? 12 : 11,
|
|
541
|
-
background: "var(--background, #fff)"
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
var coordKey = (cell) => cell ? `${indexToColName(cell.col)}${cell.row + 1}` : "";
|
|
545
|
-
function spillBorderStyle(range, row, col) {
|
|
546
|
-
const line = "1px solid color-mix(in srgb, var(--primary, #6366f1) 60%, transparent)";
|
|
547
|
-
return {
|
|
548
|
-
position: "absolute",
|
|
549
|
-
inset: 0,
|
|
550
|
-
pointerEvents: "none",
|
|
551
|
-
zIndex: 5,
|
|
552
|
-
borderTop: row === range.startRow ? line : void 0,
|
|
553
|
-
borderBottom: row === range.endRow ? line : void 0,
|
|
554
|
-
borderLeft: col === range.startCol ? line : void 0,
|
|
555
|
-
borderRight: col === range.endCol ? line : void 0
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
function CellText({ cell }) {
|
|
559
|
-
const shown = formatCellForDisplay(cell);
|
|
560
|
-
return /* @__PURE__ */ jsx4(
|
|
561
|
-
"span",
|
|
562
|
-
{
|
|
563
|
-
className: `truncate block max-w-full ${cell.error ? "text-destructive font-semibold" : ""}`,
|
|
564
|
-
title: cell.error ? cell.errorMessage ?? cell.error : void 0,
|
|
565
|
-
"data-numeric": shown.numeric ? "" : void 0,
|
|
566
|
-
style: shown.numeric || shown.color ? { ...shown.numeric ? { textAlign: "right" } : {}, ...shown.color ? { color: numberFormatColorToCss(shown.color) } : {} } : void 0,
|
|
567
|
-
children: shown.text
|
|
568
|
-
}
|
|
569
|
-
);
|
|
570
|
-
}
|
|
571
|
-
var SpreadsheetEditor = ({
|
|
572
|
-
state: externalState,
|
|
573
|
-
readOnly = false,
|
|
574
|
-
customCellRenderer,
|
|
575
|
-
onAddColumnClick,
|
|
576
|
-
onColumnHeaderClick,
|
|
577
|
-
onColumnResize
|
|
578
|
-
}) => {
|
|
579
|
-
const defaultState = useSpreadsheetEditor();
|
|
580
|
-
const state = externalState || defaultState;
|
|
581
|
-
const gridRef = useRef5(null);
|
|
582
|
-
const formulaBarRef = useRef5(null);
|
|
583
|
-
const cellInputRef = useRef5(null);
|
|
584
|
-
const [resizingColId, setResizingColId] = useState5(null);
|
|
585
|
-
const [hoveredColId, setHoveredColId] = useState5(null);
|
|
586
|
-
const [resizeStartX, setResizeStartX] = useState5(0);
|
|
587
|
-
const [resizeStartWidth, setResizeStartWidth] = useState5(0);
|
|
588
|
-
const view = state.viewModel;
|
|
589
|
-
const { copyShortcutFallback } = useSpreadsheetClipboard(gridRef, state, readOnly);
|
|
590
|
-
const { fillTarget, startFill, extendFill } = useFillHandle(state);
|
|
591
|
-
const [menu, setMenu] = useState5(null);
|
|
592
|
-
const filter = state.document.table?.filter;
|
|
593
|
-
const filteredColIds = useMemo3(
|
|
594
|
-
() => new Set(filter?.enabled ? filter.rules.map((r) => r.colId) : []),
|
|
595
|
-
[filter]
|
|
596
|
-
);
|
|
597
|
-
const handleCellContextMenu = useCallback3((rIdx, cIdx, e) => {
|
|
598
|
-
if (readOnly) return;
|
|
599
|
-
e.preventDefault();
|
|
600
|
-
if (state.editingCell) state.commitEditing();
|
|
601
|
-
if (!state.selectedRange || !rangeContains(state.selectedRange, rIdx, cIdx)) {
|
|
602
|
-
state.selectCell(rIdx, cIdx);
|
|
603
|
-
}
|
|
604
|
-
setMenu({ x: e.clientX, y: e.clientY, items: getSpreadsheetMenuItems(state.controller, { row: rIdx, col: cIdx }) });
|
|
605
|
-
}, [readOnly, state]);
|
|
606
|
-
const activeRawValue = useMemo3(() => {
|
|
607
|
-
if (!state.activeCell) return "";
|
|
608
|
-
const row = state.document.rows[state.activeCell.row];
|
|
609
|
-
const col = state.document.columns[state.activeCell.col];
|
|
610
|
-
if (!row || !col) return "";
|
|
611
|
-
return state.getCell(row.id, col.id).raw;
|
|
612
|
-
}, [state.activeCell, state.document]);
|
|
613
|
-
const activeSpill = useMemo3(
|
|
614
|
-
() => state.activeCell ? state.controller.getSpillAt(state.activeCell.row, state.activeCell.col) : null,
|
|
615
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
616
|
-
[state.controller, state.activeCell, state.document]
|
|
617
|
-
);
|
|
618
|
-
const spillFormula = activeSpill && !activeRawValue && activeSpill.key !== coordKey(state.activeCell) ? activeSpill.formula : "";
|
|
619
|
-
const coordLabel = useMemo3(() => {
|
|
620
|
-
if (!state.activeCell) return "--";
|
|
621
|
-
const colName = indexToColName(state.activeCell.col);
|
|
622
|
-
return `${colName}${state.activeCell.row + 1}`;
|
|
623
|
-
}, [state.activeCell]);
|
|
624
|
-
const [formulaDraft, setFormulaDraft] = useState5(null);
|
|
625
|
-
const activeColumn = state.activeCell ? state.document.columns[state.activeCell.col] : void 0;
|
|
626
|
-
const formulaBarReadOnly = readOnly || !state.activeCell || !!activeColumn?.readOnly;
|
|
627
|
-
useEffect4(() => {
|
|
628
|
-
setFormulaDraft(null);
|
|
629
|
-
}, [state.activeCell?.row, state.activeCell?.col]);
|
|
630
|
-
const commitFormulaBar = () => {
|
|
631
|
-
if (state.editingCell) {
|
|
632
|
-
state.commitEditing();
|
|
633
|
-
return;
|
|
634
|
-
}
|
|
635
|
-
if (formulaDraft === null || !state.activeCell) return;
|
|
636
|
-
const row = state.document.rows[state.activeCell.row];
|
|
637
|
-
const col = state.document.columns[state.activeCell.col];
|
|
638
|
-
if (row && col && !formulaBarReadOnly && formulaDraft !== activeRawValue) {
|
|
639
|
-
state.setCellValue(row.id, col.id, formulaDraft);
|
|
640
|
-
}
|
|
641
|
-
setFormulaDraft(null);
|
|
642
|
-
};
|
|
643
|
-
const handleCellClick = useCallback3((rIdx, cIdx, e) => {
|
|
644
|
-
if (state.editingCell && (state.editingCell.row !== rIdx || state.editingCell.col !== cIdx)) {
|
|
645
|
-
state.commitEditing();
|
|
646
|
-
}
|
|
647
|
-
state.selectCell(rIdx, cIdx, e.shiftKey);
|
|
648
|
-
}, [state]);
|
|
649
|
-
const handleCellDblClick = useCallback3((rIdx, cIdx) => {
|
|
650
|
-
if (readOnly) return;
|
|
651
|
-
const col = state.document.columns[cIdx];
|
|
652
|
-
if (col?.readOnly) return;
|
|
653
|
-
state.startEditing(rIdx, cIdx);
|
|
654
|
-
}, [readOnly, state]);
|
|
655
|
-
const handleKeyDown = useCallback3((e) => {
|
|
656
|
-
if (state.editingCell) {
|
|
657
|
-
if (e.key === "Enter") {
|
|
658
|
-
e.preventDefault();
|
|
659
|
-
state.commitEditing();
|
|
660
|
-
state.moveCursor("down");
|
|
661
|
-
} else if (e.key === "Escape") {
|
|
662
|
-
e.preventDefault();
|
|
663
|
-
state.cancelEditing();
|
|
664
|
-
} else if (e.key === "Tab") {
|
|
665
|
-
e.preventDefault();
|
|
666
|
-
state.commitEditing();
|
|
667
|
-
state.moveCursor(e.shiftKey ? "left" : "right");
|
|
668
|
-
} else {
|
|
669
|
-
return;
|
|
670
|
-
}
|
|
671
|
-
gridRef.current?.focus();
|
|
672
|
-
return;
|
|
673
|
-
}
|
|
674
|
-
if (!state.activeCell) return;
|
|
675
|
-
if (e.key === "ArrowUp") {
|
|
676
|
-
e.preventDefault();
|
|
677
|
-
state.moveCursor("up", e.shiftKey);
|
|
678
|
-
} else if (e.key === "ArrowDown") {
|
|
679
|
-
e.preventDefault();
|
|
680
|
-
state.moveCursor("down", e.shiftKey);
|
|
681
|
-
} else if (e.key === "ArrowLeft") {
|
|
682
|
-
e.preventDefault();
|
|
683
|
-
state.moveCursor("left", e.shiftKey);
|
|
684
|
-
} else if (e.key === "ArrowRight") {
|
|
685
|
-
e.preventDefault();
|
|
686
|
-
state.moveCursor("right", e.shiftKey);
|
|
687
|
-
} else if (e.key === "Tab") {
|
|
688
|
-
e.preventDefault();
|
|
689
|
-
state.moveCursor(e.shiftKey ? "left" : "right");
|
|
690
|
-
} else if (e.key === "Enter") {
|
|
691
|
-
e.preventDefault();
|
|
692
|
-
const col = state.document.columns[state.activeCell.col];
|
|
693
|
-
if (!readOnly && !col?.readOnly) {
|
|
694
|
-
state.startEditing();
|
|
695
|
-
}
|
|
696
|
-
} else if (e.key === "Backspace" || e.key === "Delete") {
|
|
697
|
-
if (readOnly) return;
|
|
698
|
-
const row = state.document.rows[state.activeCell.row];
|
|
699
|
-
const col = state.document.columns[state.activeCell.col];
|
|
700
|
-
if (row && col && !col.readOnly) {
|
|
701
|
-
e.preventDefault();
|
|
702
|
-
state.setCellValue(row.id, col.id, "");
|
|
703
|
-
}
|
|
704
|
-
} else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "z") {
|
|
705
|
-
e.preventDefault();
|
|
706
|
-
if (e.shiftKey) {
|
|
707
|
-
state.redo();
|
|
708
|
-
} else {
|
|
709
|
-
state.undo();
|
|
710
|
-
}
|
|
711
|
-
} else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === "y") {
|
|
712
|
-
e.preventDefault();
|
|
713
|
-
state.redo();
|
|
714
|
-
} else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "c") {
|
|
715
|
-
copyShortcutFallback();
|
|
716
|
-
} else if (!readOnly && e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
717
|
-
const col = state.document.columns[state.activeCell.col];
|
|
718
|
-
if (!col?.readOnly) {
|
|
719
|
-
e.preventDefault();
|
|
720
|
-
state.startEditing(state.activeCell.row, state.activeCell.col, e.key);
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
}, [readOnly, state, copyShortcutFallback]);
|
|
724
|
-
const stateRef = useRef5(state);
|
|
725
|
-
stateRef.current = state;
|
|
726
|
-
const onColumnResizeRef = useRef5(onColumnResize);
|
|
727
|
-
onColumnResizeRef.current = onColumnResize;
|
|
728
|
-
useEffect4(() => {
|
|
729
|
-
if (!resizingColId) return;
|
|
730
|
-
if (typeof document !== "undefined") {
|
|
731
|
-
document.body.style.cursor = "col-resize";
|
|
732
|
-
document.body.style.userSelect = "none";
|
|
733
|
-
}
|
|
734
|
-
let rafId = null;
|
|
735
|
-
let pendingWidth = resizeStartWidth;
|
|
736
|
-
let hasDragged = false;
|
|
737
|
-
const handleMouseMove = (e) => {
|
|
738
|
-
const delta = e.clientX - resizeStartX;
|
|
739
|
-
if (Math.abs(delta) > 2) {
|
|
740
|
-
hasDragged = true;
|
|
741
|
-
}
|
|
742
|
-
pendingWidth = Math.max(30, resizeStartWidth + delta);
|
|
743
|
-
if (rafId === null) {
|
|
744
|
-
rafId = requestAnimationFrame(() => {
|
|
745
|
-
rafId = null;
|
|
746
|
-
stateRef.current.setColumnWidth(resizingColId, pendingWidth);
|
|
747
|
-
});
|
|
748
|
-
}
|
|
749
|
-
};
|
|
750
|
-
const handleMouseUp = () => {
|
|
751
|
-
if (rafId !== null) {
|
|
752
|
-
cancelAnimationFrame(rafId);
|
|
753
|
-
rafId = null;
|
|
754
|
-
}
|
|
755
|
-
if (hasDragged) {
|
|
756
|
-
stateRef.current.setColumnWidth(resizingColId, pendingWidth);
|
|
757
|
-
onColumnResizeRef.current?.(resizingColId, pendingWidth);
|
|
758
|
-
}
|
|
759
|
-
setResizingColId(null);
|
|
760
|
-
if (typeof document !== "undefined") {
|
|
761
|
-
document.body.style.cursor = "";
|
|
762
|
-
document.body.style.userSelect = "";
|
|
763
|
-
}
|
|
764
|
-
};
|
|
765
|
-
window.addEventListener("mousemove", handleMouseMove);
|
|
766
|
-
window.addEventListener("mouseup", handleMouseUp);
|
|
767
|
-
return () => {
|
|
768
|
-
if (rafId !== null) {
|
|
769
|
-
cancelAnimationFrame(rafId);
|
|
770
|
-
}
|
|
771
|
-
if (typeof document !== "undefined") {
|
|
772
|
-
document.body.style.cursor = "";
|
|
773
|
-
document.body.style.userSelect = "";
|
|
774
|
-
}
|
|
775
|
-
window.removeEventListener("mousemove", handleMouseMove);
|
|
776
|
-
window.removeEventListener("mouseup", handleMouseUp);
|
|
777
|
-
};
|
|
778
|
-
}, [resizingColId, resizeStartX, resizeStartWidth]);
|
|
779
|
-
const measureElementContentWidth = useCallback3((el, container) => {
|
|
780
|
-
if (typeof document === "undefined") return 0;
|
|
781
|
-
let maxW = el.scrollWidth || 0;
|
|
782
|
-
const firstChild = el.firstElementChild;
|
|
783
|
-
if (firstChild && firstChild.scrollWidth > maxW) {
|
|
784
|
-
maxW = firstChild.scrollWidth;
|
|
785
|
-
}
|
|
786
|
-
const truncated = el.querySelectorAll(".truncate, [title], span, div");
|
|
787
|
-
truncated.forEach((node) => {
|
|
788
|
-
if (node.scrollWidth > maxW) {
|
|
789
|
-
maxW = node.scrollWidth;
|
|
790
|
-
}
|
|
791
|
-
});
|
|
792
|
-
try {
|
|
793
|
-
const clone = firstChild ? firstChild.cloneNode(true) : el.cloneNode(true);
|
|
794
|
-
clone.style.cssText = `
|
|
795
|
-
position: absolute !important;
|
|
796
|
-
visibility: hidden !important;
|
|
797
|
-
width: max-content !important;
|
|
798
|
-
min-width: max-content !important;
|
|
799
|
-
max-width: none !important;
|
|
800
|
-
overflow: visible !important;
|
|
801
|
-
white-space: nowrap !important;
|
|
802
|
-
pointer-events: none !important;
|
|
803
|
-
top: -9999px !important;
|
|
804
|
-
left: -9999px !important;
|
|
805
|
-
`;
|
|
806
|
-
const allNodes = clone.querySelectorAll("*");
|
|
807
|
-
allNodes.forEach((node) => {
|
|
808
|
-
node.style.maxWidth = "none";
|
|
809
|
-
node.style.overflow = "visible";
|
|
810
|
-
node.style.textOverflow = "clip";
|
|
811
|
-
node.style.whiteSpace = "nowrap";
|
|
812
|
-
if (node.classList.contains("truncate") || node.classList.contains("min-w-0") || node.classList.contains("w-full") || node.classList.contains("max-w-0") || node.classList.contains("flex-1")) {
|
|
813
|
-
node.style.width = "max-content";
|
|
814
|
-
node.style.minWidth = "max-content";
|
|
815
|
-
}
|
|
816
|
-
});
|
|
817
|
-
container.appendChild(clone);
|
|
818
|
-
const rect = clone.getBoundingClientRect();
|
|
819
|
-
container.removeChild(clone);
|
|
820
|
-
if (rect.width > maxW) {
|
|
821
|
-
maxW = rect.width;
|
|
822
|
-
}
|
|
823
|
-
} catch {
|
|
824
|
-
}
|
|
825
|
-
return maxW;
|
|
826
|
-
}, []);
|
|
827
|
-
const autoFitColumn = useCallback3((colId, colIndex) => {
|
|
828
|
-
const col = state.document.columns.find((c) => c.id === colId);
|
|
829
|
-
if (!col) return;
|
|
830
|
-
let calculatedWidth = 0;
|
|
831
|
-
if (gridRef.current && typeof document !== "undefined") {
|
|
832
|
-
const table = gridRef.current.querySelector("table");
|
|
833
|
-
if (table) {
|
|
834
|
-
const th = table.querySelector(`thead th[data-col="${colIndex}"]`);
|
|
835
|
-
if (th) {
|
|
836
|
-
const headerInner = th.firstElementChild || th;
|
|
837
|
-
const headerW = measureElementContentWidth(headerInner, gridRef.current);
|
|
838
|
-
calculatedWidth = Math.max(calculatedWidth, headerW + 28);
|
|
839
|
-
}
|
|
840
|
-
const rows = table.querySelectorAll("tbody tr");
|
|
841
|
-
const sampleLimit = Math.min(rows.length, 150);
|
|
842
|
-
for (let r = 0; r < sampleLimit; r++) {
|
|
843
|
-
const tr = rows[r];
|
|
844
|
-
const td = tr.querySelector(`td[data-col="${colIndex}"][colspan="1"]`);
|
|
845
|
-
if (td) {
|
|
846
|
-
const cellW = measureElementContentWidth(td, gridRef.current);
|
|
847
|
-
calculatedWidth = Math.max(calculatedWidth, cellW + 20);
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
if (calculatedWidth > 0) {
|
|
853
|
-
const finalWidth = Math.min(600, Math.max(50, Math.ceil(calculatedWidth)));
|
|
854
|
-
state.setColumnWidth(colId, finalWidth);
|
|
855
|
-
} else {
|
|
856
|
-
state.autoFitColumnWidth?.(colId);
|
|
857
|
-
}
|
|
858
|
-
const updatedCol = state.document.columns.find((c) => c.id === colId);
|
|
859
|
-
if (updatedCol && onColumnResize) {
|
|
860
|
-
onColumnResize(updatedCol.id, updatedCol.width || 130);
|
|
861
|
-
}
|
|
862
|
-
}, [state, measureElementContentWidth, onColumnResize]);
|
|
863
|
-
const handleResizeDblClick = useCallback3((colId, colIndex, e) => {
|
|
864
|
-
e.preventDefault();
|
|
865
|
-
e.stopPropagation();
|
|
866
|
-
autoFitColumn(colId, colIndex);
|
|
867
|
-
}, [autoFitColumn]);
|
|
868
|
-
const handleHeaderDblClick = useCallback3((colId, colIndex, e) => {
|
|
869
|
-
const target = e.currentTarget;
|
|
870
|
-
if (target) {
|
|
871
|
-
const rect = target.getBoundingClientRect();
|
|
872
|
-
if (rect.right - e.clientX <= 12) {
|
|
873
|
-
e.preventDefault();
|
|
874
|
-
e.stopPropagation();
|
|
875
|
-
autoFitColumn(colId, colIndex);
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
}, [autoFitColumn]);
|
|
879
|
-
const isCellSelected = (rIdx, cIdx) => {
|
|
880
|
-
if (!state.selectedRange) return false;
|
|
881
|
-
const minR = Math.min(state.selectedRange.startRow, state.selectedRange.endRow);
|
|
882
|
-
const maxR = Math.max(state.selectedRange.startRow, state.selectedRange.endRow);
|
|
883
|
-
const minC = Math.min(state.selectedRange.startCol, state.selectedRange.endCol);
|
|
884
|
-
const maxC = Math.max(state.selectedRange.startCol, state.selectedRange.endCol);
|
|
885
|
-
return rIdx >= minR && rIdx <= maxR && cIdx >= minC && cIdx <= maxC;
|
|
886
|
-
};
|
|
887
|
-
const isActiveCell = (rIdx, cIdx) => {
|
|
888
|
-
return state.activeCell?.row === rIdx && state.activeCell?.col === cIdx;
|
|
889
|
-
};
|
|
890
|
-
return /* @__PURE__ */ jsxs4(
|
|
891
|
-
"div",
|
|
892
|
-
{
|
|
893
|
-
ref: gridRef,
|
|
894
|
-
className: "flex flex-col h-full w-full overflow-hidden border border-border bg-background select-none outline-none text-foreground font-sans text-xs",
|
|
895
|
-
tabIndex: 0,
|
|
896
|
-
onKeyDown: handleKeyDown,
|
|
897
|
-
role: "grid",
|
|
898
|
-
"aria-label": "Spreadsheet",
|
|
899
|
-
children: [
|
|
900
|
-
/* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-2 border-b border-border bg-muted/20 px-3 py-1.5 text-xs font-mono", children: [
|
|
901
|
-
/* @__PURE__ */ jsx4("div", { className: "flex h-6 min-w-[3rem] items-center justify-center rounded border border-border bg-background px-1.5 font-semibold text-foreground", children: coordLabel }),
|
|
902
|
-
/* @__PURE__ */ jsx4("div", { className: "flex items-center text-muted-foreground select-none", children: /* @__PURE__ */ jsx4("span", { className: "italic font-serif font-bold text-sm text-primary", children: "fx" }) }),
|
|
903
|
-
/* @__PURE__ */ jsx4(
|
|
904
|
-
"input",
|
|
905
|
-
{
|
|
906
|
-
ref: formulaBarRef,
|
|
907
|
-
type: "text",
|
|
908
|
-
className: "flex-1 bg-transparent px-2 py-0.5 outline-none font-sans text-xs text-foreground placeholder:text-muted-foreground/60 focus:bg-background focus:ring-1 focus:ring-primary rounded",
|
|
909
|
-
placeholder: "Enter a value or formula (e.g. =SUM(A1:A5))",
|
|
910
|
-
"aria-label": "Formula bar",
|
|
911
|
-
readOnly: formulaBarReadOnly,
|
|
912
|
-
"data-spill-formula": !state.editingCell && formulaDraft === null && spillFormula ? "true" : void 0,
|
|
913
|
-
style: !state.editingCell && formulaDraft === null && spillFormula ? { color: "var(--muted-foreground, #94a3b8)" } : void 0,
|
|
914
|
-
value: state.editingCell ? state.draftValue : formulaDraft ?? (activeRawValue || spillFormula),
|
|
915
|
-
onFocus: () => {
|
|
916
|
-
if (!state.editingCell) setFormulaDraft(activeRawValue);
|
|
917
|
-
},
|
|
918
|
-
onChange: (e) => {
|
|
919
|
-
if (state.editingCell) {
|
|
920
|
-
state.setDraftValue(e.target.value);
|
|
921
|
-
} else if (state.activeCell) {
|
|
922
|
-
setFormulaDraft(e.target.value);
|
|
923
|
-
}
|
|
924
|
-
},
|
|
925
|
-
onBlur: () => commitFormulaBar(),
|
|
926
|
-
onKeyDown: (e) => {
|
|
927
|
-
e.stopPropagation();
|
|
928
|
-
if (e.key === "Enter") {
|
|
929
|
-
e.preventDefault();
|
|
930
|
-
commitFormulaBar();
|
|
931
|
-
} else if (e.key === "Escape") {
|
|
932
|
-
e.preventDefault();
|
|
933
|
-
setFormulaDraft(null);
|
|
934
|
-
if (state.editingCell) state.cancelEditing();
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
),
|
|
939
|
-
!formulaBarReadOnly && /* @__PURE__ */ jsx4(
|
|
940
|
-
FormulaHints,
|
|
941
|
-
{
|
|
942
|
-
inputRef: formulaBarRef,
|
|
943
|
-
value: state.editingCell ? state.draftValue : formulaDraft ?? activeRawValue,
|
|
944
|
-
onAccept: (next) => state.editingCell ? state.setDraftValue(next) : setFormulaDraft(next)
|
|
945
|
-
}
|
|
946
|
-
)
|
|
947
|
-
] }),
|
|
948
|
-
/* @__PURE__ */ jsx4("div", { className: "relative flex-1 overflow-auto", children: /* @__PURE__ */ jsxs4("table", { className: "border-collapse table-fixed w-max min-w-full", children: [
|
|
949
|
-
/* @__PURE__ */ jsx4("thead", { children: /* @__PURE__ */ jsxs4("tr", { className: "h-7 bg-muted sticky top-0 z-20 border-b border-border shadow-xs", children: [
|
|
950
|
-
/* @__PURE__ */ jsx4("th", { className: "w-12 min-w-[3rem] sticky left-0 z-30 bg-muted border-r border-border text-center text-[10px] text-muted-foreground font-medium", children: "#" }),
|
|
951
|
-
view.columns.map(({ column: col, index: cIdx, frozen, stickyLeft }) => /* @__PURE__ */ jsxs4(
|
|
952
|
-
"th",
|
|
953
|
-
{
|
|
954
|
-
"data-col": cIdx,
|
|
955
|
-
className: `relative border-r border-border px-2 text-left font-medium text-muted-foreground hover:bg-muted/90 transition-colors group overflow-hidden max-w-0 ${onColumnHeaderClick ? "cursor-pointer" : "cursor-default"}`,
|
|
956
|
-
style: {
|
|
957
|
-
width: col.width || 130,
|
|
958
|
-
minWidth: col.width || 130,
|
|
959
|
-
maxWidth: col.width || 130,
|
|
960
|
-
overflow: "hidden",
|
|
961
|
-
...frozen ? { position: "sticky", left: ROW_HEADER_WIDTH + stickyLeft, zIndex: 25, background: "var(--muted, #f4f4f5)" } : {}
|
|
962
|
-
},
|
|
963
|
-
onClick: () => onColumnHeaderClick?.(col),
|
|
964
|
-
onDoubleClick: (e) => handleHeaderDblClick(col.id, cIdx, e),
|
|
965
|
-
children: [
|
|
966
|
-
/* @__PURE__ */ jsxs4("div", { className: "flex items-center justify-between gap-1 min-w-0 overflow-hidden truncate", children: [
|
|
967
|
-
/* @__PURE__ */ jsx4("span", { className: "truncate font-semibold text-foreground text-xs min-w-0", children: col.title }),
|
|
968
|
-
filteredColIds.has(col.id) && /* @__PURE__ */ jsx4("span", { className: "text-[10px] text-primary shrink-0", title: "Filtered", "data-filtered": "true", children: "\u23F7" }),
|
|
969
|
-
/* @__PURE__ */ jsxs4("span", { className: "text-[10px] text-muted-foreground/70 font-mono font-normal shrink-0", children: [
|
|
970
|
-
"(",
|
|
971
|
-
col.key,
|
|
972
|
-
")"
|
|
973
|
-
] })
|
|
974
|
-
] }),
|
|
975
|
-
/* @__PURE__ */ jsx4(
|
|
976
|
-
"div",
|
|
977
|
-
{
|
|
978
|
-
className: "col-resize-handle",
|
|
979
|
-
style: { position: "absolute", top: 0, bottom: 0, width: 12, right: -6, cursor: "col-resize", zIndex: 20, display: "flex", justifyContent: "center", touchAction: "none" },
|
|
980
|
-
onMouseEnter: () => setHoveredColId(col.id),
|
|
981
|
-
onMouseLeave: () => setHoveredColId((cur) => cur === col.id ? null : cur),
|
|
982
|
-
onMouseDown: (e) => {
|
|
983
|
-
e.preventDefault();
|
|
984
|
-
e.stopPropagation();
|
|
985
|
-
setResizingColId(col.id);
|
|
986
|
-
setResizeStartX(e.clientX);
|
|
987
|
-
setResizeStartWidth(col.width || 130);
|
|
988
|
-
},
|
|
989
|
-
onDoubleClick: (e) => handleResizeDblClick(col.id, cIdx, e),
|
|
990
|
-
role: "separator",
|
|
991
|
-
"aria-orientation": "vertical",
|
|
992
|
-
children: /* @__PURE__ */ jsx4(
|
|
993
|
-
"div",
|
|
994
|
-
{
|
|
995
|
-
className: "col-resize-handle-line",
|
|
996
|
-
style: {
|
|
997
|
-
width: 2,
|
|
998
|
-
height: "100%",
|
|
999
|
-
pointerEvents: "none",
|
|
1000
|
-
transition: "background-color 150ms ease",
|
|
1001
|
-
backgroundColor: resizingColId === col.id ? "var(--primary, #6366f1)" : hoveredColId === col.id ? "color-mix(in srgb, var(--primary, #6366f1) 75%, transparent)" : "transparent"
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
)
|
|
1005
|
-
}
|
|
1006
|
-
)
|
|
1007
|
-
]
|
|
1008
|
-
},
|
|
1009
|
-
col.id
|
|
1010
|
-
)),
|
|
1011
|
-
onAddColumnClick && /* @__PURE__ */ jsx4(
|
|
1012
|
-
"th",
|
|
1013
|
-
{
|
|
1014
|
-
className: "w-10 min-w-[2.5rem] px-1 text-center bg-muted/40 hover:bg-muted cursor-pointer transition-colors",
|
|
1015
|
-
onClick: onAddColumnClick,
|
|
1016
|
-
title: "Add Column",
|
|
1017
|
-
children: /* @__PURE__ */ jsx4("span", { className: "text-xs font-bold text-muted-foreground", children: "+" })
|
|
1018
|
-
}
|
|
1019
|
-
)
|
|
1020
|
-
] }) }),
|
|
1021
|
-
/* @__PURE__ */ jsx4("tbody", { children: view.rows.map((viewRow) => {
|
|
1022
|
-
if (viewRow.kind === "group") {
|
|
1023
|
-
return /* @__PURE__ */ jsx4(
|
|
1024
|
-
SpreadsheetGroupRow,
|
|
1025
|
-
{
|
|
1026
|
-
group: viewRow.group,
|
|
1027
|
-
columns: view.columns,
|
|
1028
|
-
groupColId: state.document.table?.grouping?.colId ?? "",
|
|
1029
|
-
onToggle: state.toggleGroupCollapsed,
|
|
1030
|
-
trailingCell: !!onAddColumnClick
|
|
1031
|
-
},
|
|
1032
|
-
`group:${viewRow.group.key}`
|
|
1033
|
-
);
|
|
1034
|
-
}
|
|
1035
|
-
const displayRowIndex = viewRow.index;
|
|
1036
|
-
const selection = state.selectedRange ? normalizeRange2(state.selectedRange) : null;
|
|
1037
|
-
return /* @__PURE__ */ jsxs4(
|
|
1038
|
-
"tr",
|
|
1039
|
-
{
|
|
1040
|
-
"data-row": displayRowIndex,
|
|
1041
|
-
className: `border-b border-border hover:bg-muted/10 transition-colors ${viewRow.section !== "body" ? "bg-muted/30 font-semibold" : ""}`,
|
|
1042
|
-
style: { height: viewRow.row.height || 32 },
|
|
1043
|
-
children: [
|
|
1044
|
-
/* @__PURE__ */ jsx4(
|
|
1045
|
-
"td",
|
|
1046
|
-
{
|
|
1047
|
-
className: "w-12 min-w-[3rem] sticky left-0 z-10 bg-muted border-r border-border text-center text-[10px] text-muted-foreground font-mono select-none",
|
|
1048
|
-
style: viewRow.frozen ? { top: COLUMN_HEADER_HEIGHT + viewRow.stickyTop, zIndex: 15 } : void 0,
|
|
1049
|
-
children: displayRowIndex + 1
|
|
1050
|
-
}
|
|
1051
|
-
),
|
|
1052
|
-
view.columns.map((viewCol) => {
|
|
1053
|
-
const span = view.getCellSpan(displayRowIndex, viewCol.index);
|
|
1054
|
-
if (!span) return null;
|
|
1055
|
-
const rIdx = span.source.row;
|
|
1056
|
-
const cIdx = span.source.col;
|
|
1057
|
-
const row = state.document.rows[rIdx];
|
|
1058
|
-
const col = state.document.columns[cIdx];
|
|
1059
|
-
const cell = state.getCell(row.id, col.id);
|
|
1060
|
-
const selected = isCellSelected(rIdx, cIdx);
|
|
1061
|
-
const active = isActiveCell(rIdx, cIdx);
|
|
1062
|
-
const isEditing = state.editingCell?.row === rIdx && state.editingCell?.col === cIdx;
|
|
1063
|
-
const inFillPreview = !!fillTarget && !selected && rangeContains(fillTarget, displayRowIndex, viewCol.index);
|
|
1064
|
-
const showFillHandle = !readOnly && !isEditing && !!selection && (span.merge ? rangeContains(span.merge, selection.endRow, selection.endCol) : selection.endRow === rIdx && selection.endCol === cIdx);
|
|
1065
|
-
return /* @__PURE__ */ jsxs4(
|
|
1066
|
-
"td",
|
|
1067
|
-
{
|
|
1068
|
-
"data-row": rIdx,
|
|
1069
|
-
"data-col": cIdx,
|
|
1070
|
-
rowSpan: span.rowSpan,
|
|
1071
|
-
colSpan: span.colSpan,
|
|
1072
|
-
className: `relative border-r border-border px-2 py-1 truncate max-w-0 text-foreground transition-colors ${selected ? "bg-primary/10" : ""} ${active ? "ring-2 ring-primary ring-inset z-10" : ""} ${viewCol.header ? "font-semibold" : ""}`,
|
|
1073
|
-
style: {
|
|
1074
|
-
maxWidth: 0,
|
|
1075
|
-
overflow: "hidden",
|
|
1076
|
-
...frozenCellStyle(viewRow, viewCol),
|
|
1077
|
-
...inFillPreview ? { outline: "1px dashed var(--primary, #6366f1)", outlineOffset: -1 } : {}
|
|
1078
|
-
},
|
|
1079
|
-
onClick: (e) => handleCellClick(rIdx, cIdx, e),
|
|
1080
|
-
onDoubleClick: () => handleCellDblClick(rIdx, cIdx),
|
|
1081
|
-
onContextMenu: (e) => handleCellContextMenu(rIdx, cIdx, e),
|
|
1082
|
-
onMouseOver: () => extendFill(displayRowIndex, viewCol.index),
|
|
1083
|
-
children: [
|
|
1084
|
-
isEditing ? /* @__PURE__ */ jsxs4(Fragment2, { children: [
|
|
1085
|
-
/* @__PURE__ */ jsx4(
|
|
1086
|
-
"input",
|
|
1087
|
-
{
|
|
1088
|
-
ref: cellInputRef,
|
|
1089
|
-
type: "text",
|
|
1090
|
-
className: "absolute inset-0 w-full h-full px-2 py-1 bg-background text-foreground outline-none font-sans text-xs border-2 border-primary z-20",
|
|
1091
|
-
value: state.draftValue,
|
|
1092
|
-
onChange: (e) => state.setDraftValue(e.target.value),
|
|
1093
|
-
onBlur: () => state.commitEditing(),
|
|
1094
|
-
onFocus: (e) => {
|
|
1095
|
-
const end = e.currentTarget.value.length;
|
|
1096
|
-
e.currentTarget.setSelectionRange(end, end);
|
|
1097
|
-
},
|
|
1098
|
-
autoFocus: true
|
|
1099
|
-
}
|
|
1100
|
-
),
|
|
1101
|
-
/* @__PURE__ */ jsx4(FormulaHints, { inputRef: cellInputRef, value: state.draftValue, onAccept: state.setDraftValue })
|
|
1102
|
-
] }) : customCellRenderer ? customCellRenderer({ row, col, cell }) : /* @__PURE__ */ jsx4(CellText, { cell }),
|
|
1103
|
-
activeSpill && rangeContains(activeSpill.range, rIdx, cIdx) && /* @__PURE__ */ jsx4("span", { "aria-hidden": "true", className: "spreadsheet-spill-border", style: spillBorderStyle(activeSpill.range, rIdx, cIdx) }),
|
|
1104
|
-
showFillHandle && /* @__PURE__ */ jsx4(
|
|
1105
|
-
"div",
|
|
1106
|
-
{
|
|
1107
|
-
className: "spreadsheet-fill-handle",
|
|
1108
|
-
"aria-label": "Fill handle",
|
|
1109
|
-
onMouseDown: startFill,
|
|
1110
|
-
onClick: (e) => e.stopPropagation(),
|
|
1111
|
-
style: { position: "absolute", right: 0, bottom: 0, width: 7, height: 7, background: "var(--primary, #6366f1)", cursor: "crosshair", zIndex: 25 }
|
|
1112
|
-
}
|
|
1113
|
-
)
|
|
1114
|
-
]
|
|
1115
|
-
},
|
|
1116
|
-
viewCol.column.id
|
|
1117
|
-
);
|
|
1118
|
-
}),
|
|
1119
|
-
onAddColumnClick && /* @__PURE__ */ jsx4("td", { className: "w-10 min-w-[2.5rem] bg-muted/10 border-r border-border" })
|
|
1120
|
-
]
|
|
1121
|
-
},
|
|
1122
|
-
viewRow.row.id
|
|
1123
|
-
);
|
|
1124
|
-
}) })
|
|
1125
|
-
] }) }),
|
|
1126
|
-
menu && /* @__PURE__ */ jsx4(
|
|
1127
|
-
SpreadsheetContextMenu,
|
|
1128
|
-
{
|
|
1129
|
-
items: menu.items,
|
|
1130
|
-
x: menu.x,
|
|
1131
|
-
y: menu.y,
|
|
1132
|
-
onClose: () => {
|
|
1133
|
-
setMenu(null);
|
|
1134
|
-
gridRef.current?.focus();
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
),
|
|
1138
|
-
/* @__PURE__ */ jsx4("style", { children: `
|
|
1139
|
-
.col-resize-handle:hover .col-resize-handle-line {
|
|
1140
|
-
background-color: var(--primary, #6366f1);
|
|
1141
|
-
opacity: 0.75;
|
|
1142
|
-
}
|
|
1143
|
-
.col-resize-handle.active .col-resize-handle-line {
|
|
1144
|
-
background-color: var(--primary, #6366f1);
|
|
1145
|
-
opacity: 1;
|
|
1146
|
-
}
|
|
1147
|
-
table.table-fixed th {
|
|
1148
|
-
overflow: hidden;
|
|
1149
|
-
}
|
|
1150
|
-
table.table-fixed td {
|
|
1151
|
-
max-width: 0;
|
|
1152
|
-
overflow: hidden;
|
|
1153
|
-
}
|
|
1154
|
-
` })
|
|
1155
|
-
]
|
|
1156
|
-
}
|
|
1157
|
-
);
|
|
1158
|
-
};
|
|
1159
|
-
|
|
1160
|
-
export {
|
|
1161
|
-
useSpreadsheetEditor,
|
|
1162
|
-
SpreadsheetContextMenu,
|
|
1163
|
-
SpreadsheetGroupRow,
|
|
1164
|
-
useSpreadsheetClipboard,
|
|
1165
|
-
useFillHandle,
|
|
1166
|
-
FormulaHints,
|
|
1167
|
-
SpreadsheetEditor
|
|
1168
|
-
};
|
|
1169
|
-
//# sourceMappingURL=chunk-FYIPXHAE.js.map
|