@extend-ai/react-xlsx 0.9.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +197 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +197 -69
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21547,6 +21547,9 @@ function XlsxGrid({
|
|
|
21547
21547
|
const selectionCommitFrameRef = React4.useRef(null);
|
|
21548
21548
|
const selectionRef = React4.useRef(null);
|
|
21549
21549
|
const editingCellRef = React4.useRef(null);
|
|
21550
|
+
const commitEditingRef = React4.useRef(() => {
|
|
21551
|
+
});
|
|
21552
|
+
const editingInputRef = React4.useRef(null);
|
|
21550
21553
|
const readOnlyRef = React4.useRef(readOnly);
|
|
21551
21554
|
const committedZoomScaleRef = React4.useRef(zoomScale);
|
|
21552
21555
|
const gestureZoomScaleRef = React4.useRef(zoomScale);
|
|
@@ -21570,8 +21573,10 @@ function XlsxGrid({
|
|
|
21570
21573
|
const resizeFrameRef = React4.useRef(null);
|
|
21571
21574
|
const pendingResizePreviewRef = React4.useRef(null);
|
|
21572
21575
|
const selectionDragRef = React4.useRef(null);
|
|
21576
|
+
const pendingSelectionDragRef = React4.useRef(null);
|
|
21573
21577
|
const fillDragRef = React4.useRef(null);
|
|
21574
21578
|
const selectionDragCleanupRef = React4.useRef(null);
|
|
21579
|
+
const pendingSelectionDragCleanupRef = React4.useRef(null);
|
|
21575
21580
|
const fillDragCleanupRef = React4.useRef(null);
|
|
21576
21581
|
const cachedScrollerRectRef = React4.useRef(null);
|
|
21577
21582
|
const imageInteractionCleanupRef = React4.useRef(null);
|
|
@@ -22424,6 +22429,18 @@ function XlsxGrid({
|
|
|
22424
22429
|
React4.useEffect(() => {
|
|
22425
22430
|
editingCellRef.current = editingCell;
|
|
22426
22431
|
}, [editingCell]);
|
|
22432
|
+
React4.useLayoutEffect(() => {
|
|
22433
|
+
if (!editingCell) {
|
|
22434
|
+
return;
|
|
22435
|
+
}
|
|
22436
|
+
const input = editingInputRef.current;
|
|
22437
|
+
if (!input) {
|
|
22438
|
+
return;
|
|
22439
|
+
}
|
|
22440
|
+
input.focus();
|
|
22441
|
+
const caret = input.value.length;
|
|
22442
|
+
input.setSelectionRange(caret, caret);
|
|
22443
|
+
}, [editingCell]);
|
|
22427
22444
|
React4.useEffect(() => {
|
|
22428
22445
|
readOnlyRef.current = readOnly;
|
|
22429
22446
|
}, [readOnly]);
|
|
@@ -22493,7 +22510,7 @@ function XlsxGrid({
|
|
|
22493
22510
|
}, [displayedSelection]);
|
|
22494
22511
|
React4.useEffect(() => {
|
|
22495
22512
|
const previewRange = selectionPreviewRangeRef.current;
|
|
22496
|
-
if (!previewRange || selectionDragRef.current || fillDragRef.current) {
|
|
22513
|
+
if (!previewRange || pendingSelectionDragRef.current || selectionDragRef.current || fillDragRef.current) {
|
|
22497
22514
|
return;
|
|
22498
22515
|
}
|
|
22499
22516
|
if (normalizedSelection && rangesEqual(previewRange, normalizedSelection)) {
|
|
@@ -23100,14 +23117,17 @@ function XlsxGrid({
|
|
|
23100
23117
|
}
|
|
23101
23118
|
}, []);
|
|
23102
23119
|
React4.useEffect(() => {
|
|
23120
|
+
pendingSelectionDragCleanupRef.current?.();
|
|
23103
23121
|
selectionDragCleanupRef.current?.();
|
|
23104
23122
|
fillDragCleanupRef.current?.();
|
|
23105
23123
|
chartInteractionCleanupRef.current?.();
|
|
23106
23124
|
imageInteractionCleanupRef.current?.();
|
|
23125
|
+
pendingSelectionDragCleanupRef.current = null;
|
|
23107
23126
|
selectionDragCleanupRef.current = null;
|
|
23108
23127
|
fillDragCleanupRef.current = null;
|
|
23109
23128
|
chartInteractionCleanupRef.current = null;
|
|
23110
23129
|
imageInteractionCleanupRef.current = null;
|
|
23130
|
+
pendingSelectionDragRef.current = null;
|
|
23111
23131
|
selectionDragRef.current = null;
|
|
23112
23132
|
fillDragRef.current = null;
|
|
23113
23133
|
chartInteractionRef.current = null;
|
|
@@ -23183,6 +23203,9 @@ function XlsxGrid({
|
|
|
23183
23203
|
setEditingValue("");
|
|
23184
23204
|
focusGrid();
|
|
23185
23205
|
}, [focusGrid]);
|
|
23206
|
+
React4.useEffect(() => {
|
|
23207
|
+
commitEditingRef.current = commitEditing;
|
|
23208
|
+
}, [commitEditing]);
|
|
23186
23209
|
const [, startBatchTransition] = React4.useTransition();
|
|
23187
23210
|
const [, startSelectionTransition] = React4.useTransition();
|
|
23188
23211
|
const [asyncViewportRowBatch, setAsyncViewportRowBatch] = React4.useState(null);
|
|
@@ -24295,6 +24318,101 @@ function XlsxGrid({
|
|
|
24295
24318
|
}
|
|
24296
24319
|
return normalizeRange2({ start: dragState.anchor, end: cell });
|
|
24297
24320
|
}
|
|
24321
|
+
function updateSelectionDragPreview(clientX, clientY) {
|
|
24322
|
+
const dragState = selectionDragRef.current;
|
|
24323
|
+
if (!dragState) {
|
|
24324
|
+
return;
|
|
24325
|
+
}
|
|
24326
|
+
const nextCell = resolveDraggedSelectionCell(dragState, clientX, clientY);
|
|
24327
|
+
if (!nextCell) {
|
|
24328
|
+
return;
|
|
24329
|
+
}
|
|
24330
|
+
const nextRange = buildDraggedSelectionRange(dragState, nextCell);
|
|
24331
|
+
if (!nextRange || rangesEqual(nextRange, dragState.previewRange)) {
|
|
24332
|
+
return;
|
|
24333
|
+
}
|
|
24334
|
+
dragState.previewRange = nextRange;
|
|
24335
|
+
selectionPreviewRangeRef.current = nextRange;
|
|
24336
|
+
displayedSelectionRef.current = nextRange;
|
|
24337
|
+
applyPreviewOverlay(nextRange);
|
|
24338
|
+
}
|
|
24339
|
+
function clearPendingSelectionDrag() {
|
|
24340
|
+
const cleanup = pendingSelectionDragCleanupRef.current;
|
|
24341
|
+
pendingSelectionDragCleanupRef.current = null;
|
|
24342
|
+
pendingSelectionDragRef.current = null;
|
|
24343
|
+
cleanup?.();
|
|
24344
|
+
}
|
|
24345
|
+
function finishPendingSelectionDrag() {
|
|
24346
|
+
const pendingState = pendingSelectionDragRef.current;
|
|
24347
|
+
clearPendingSelectionDrag();
|
|
24348
|
+
if (pendingState && !pendingState.committedOnPointerDown) {
|
|
24349
|
+
commitSelectionRange(pendingState.previewRange);
|
|
24350
|
+
}
|
|
24351
|
+
}
|
|
24352
|
+
function promotePendingSelectionDrag(clientX, clientY) {
|
|
24353
|
+
const pendingState = pendingSelectionDragRef.current;
|
|
24354
|
+
if (!pendingState) {
|
|
24355
|
+
return;
|
|
24356
|
+
}
|
|
24357
|
+
clearPendingSelectionDrag();
|
|
24358
|
+
cachedScrollerRectRef.current = scrollRef.current?.getBoundingClientRect() ?? null;
|
|
24359
|
+
pendingState.didDrag = true;
|
|
24360
|
+
selectionDragRef.current = pendingState;
|
|
24361
|
+
selectionPreviewRangeRef.current = pendingState.previewRange;
|
|
24362
|
+
displayedSelectionRef.current = pendingState.previewRange;
|
|
24363
|
+
setInteractionMode("select");
|
|
24364
|
+
document.body.style.userSelect = "none";
|
|
24365
|
+
installSelectionDragListeners(pendingState.pointerId);
|
|
24366
|
+
updateSelectionDragPreview(clientX, clientY);
|
|
24367
|
+
}
|
|
24368
|
+
function installPendingSelectionDragListeners(pointerId, target) {
|
|
24369
|
+
const existingCleanup = pendingSelectionDragCleanupRef.current;
|
|
24370
|
+
pendingSelectionDragCleanupRef.current = null;
|
|
24371
|
+
existingCleanup?.();
|
|
24372
|
+
const pointerTarget = target;
|
|
24373
|
+
try {
|
|
24374
|
+
pointerTarget.setPointerCapture?.(pointerId);
|
|
24375
|
+
} catch {
|
|
24376
|
+
}
|
|
24377
|
+
const handlePointerMove = (event) => {
|
|
24378
|
+
const pointerEvent = event;
|
|
24379
|
+
if (pointerEvent.pointerId !== pointerId) {
|
|
24380
|
+
return;
|
|
24381
|
+
}
|
|
24382
|
+
const pendingState = pendingSelectionDragRef.current;
|
|
24383
|
+
if (!pendingState) {
|
|
24384
|
+
return;
|
|
24385
|
+
}
|
|
24386
|
+
const deltaX = Math.abs(pointerEvent.clientX - pendingState.startClientX);
|
|
24387
|
+
const deltaY = Math.abs(pointerEvent.clientY - pendingState.startClientY);
|
|
24388
|
+
if (deltaX < SELECTION_DRAG_THRESHOLD_PX && deltaY < SELECTION_DRAG_THRESHOLD_PX) {
|
|
24389
|
+
return;
|
|
24390
|
+
}
|
|
24391
|
+
event.preventDefault();
|
|
24392
|
+
promotePendingSelectionDrag(pointerEvent.clientX, pointerEvent.clientY);
|
|
24393
|
+
};
|
|
24394
|
+
const handlePointerEnd = (event) => {
|
|
24395
|
+
const pointerEvent = event;
|
|
24396
|
+
if (pointerEvent.pointerId !== pointerId) {
|
|
24397
|
+
return;
|
|
24398
|
+
}
|
|
24399
|
+
finishPendingSelectionDrag();
|
|
24400
|
+
};
|
|
24401
|
+
target.addEventListener("pointermove", handlePointerMove);
|
|
24402
|
+
target.addEventListener("pointerup", handlePointerEnd);
|
|
24403
|
+
target.addEventListener("pointercancel", handlePointerEnd);
|
|
24404
|
+
pendingSelectionDragCleanupRef.current = () => {
|
|
24405
|
+
target.removeEventListener("pointermove", handlePointerMove);
|
|
24406
|
+
target.removeEventListener("pointerup", handlePointerEnd);
|
|
24407
|
+
target.removeEventListener("pointercancel", handlePointerEnd);
|
|
24408
|
+
try {
|
|
24409
|
+
if (pointerTarget.hasPointerCapture?.(pointerId)) {
|
|
24410
|
+
pointerTarget.releasePointerCapture?.(pointerId);
|
|
24411
|
+
}
|
|
24412
|
+
} catch {
|
|
24413
|
+
}
|
|
24414
|
+
};
|
|
24415
|
+
}
|
|
24298
24416
|
function installSelectionDragListeners(pointerId) {
|
|
24299
24417
|
selectionDragCleanupRef.current?.();
|
|
24300
24418
|
let pendingClientPoint = null;
|
|
@@ -24318,18 +24436,7 @@ function XlsxGrid({
|
|
|
24318
24436
|
}
|
|
24319
24437
|
dragState.didDrag = true;
|
|
24320
24438
|
}
|
|
24321
|
-
|
|
24322
|
-
if (!nextCell) {
|
|
24323
|
-
return;
|
|
24324
|
-
}
|
|
24325
|
-
const nextRange = buildDraggedSelectionRange(dragState, nextCell);
|
|
24326
|
-
if (!nextRange || rangesEqual(nextRange, dragState.previewRange)) {
|
|
24327
|
-
return;
|
|
24328
|
-
}
|
|
24329
|
-
dragState.previewRange = nextRange;
|
|
24330
|
-
selectionPreviewRangeRef.current = nextRange;
|
|
24331
|
-
displayedSelectionRef.current = nextRange;
|
|
24332
|
-
applyPreviewOverlay(nextRange);
|
|
24439
|
+
updateSelectionDragPreview(pendingPoint.x, pendingPoint.y);
|
|
24333
24440
|
};
|
|
24334
24441
|
const handlePointerMove = (event) => {
|
|
24335
24442
|
if (event.pointerId !== pointerId) {
|
|
@@ -24485,12 +24592,16 @@ function XlsxGrid({
|
|
|
24485
24592
|
const initialRange = normalizeRange2({ start: anchor, end: targetCell });
|
|
24486
24593
|
const isActive = isSameCell(activeCellRef.current, targetCell);
|
|
24487
24594
|
const committedOnPointerDown = !isActive || !editingCellRef.current;
|
|
24595
|
+
if (editingCellRef.current && !isActive) {
|
|
24596
|
+
commitEditingRef.current();
|
|
24597
|
+
}
|
|
24488
24598
|
const pointerOrigin = targetCell.row === cell.row && targetCell.col === cell.col ? resolveCellPointerOrigin(cell, event.currentTarget.getBoundingClientRect(), event.clientX, event.clientY) : resolveCellPointerOriginFromClient(targetCell, event.clientX, event.clientY);
|
|
24489
24599
|
const originOverlayRect = targetCell.row === cell.row && targetCell.col === cell.col ? resolveMountedCellOverlayRect(event.currentTarget) : resolveOverlayRect(initialRange);
|
|
24490
24600
|
if (!pointerOrigin) {
|
|
24491
24601
|
return;
|
|
24492
24602
|
}
|
|
24493
24603
|
startCellSelection(
|
|
24604
|
+
event.currentTarget,
|
|
24494
24605
|
event.pointerId,
|
|
24495
24606
|
anchor,
|
|
24496
24607
|
"cell",
|
|
@@ -24538,6 +24649,7 @@ function XlsxGrid({
|
|
|
24538
24649
|
return;
|
|
24539
24650
|
}
|
|
24540
24651
|
startCellSelection(
|
|
24652
|
+
event.currentTarget,
|
|
24541
24653
|
event.pointerId,
|
|
24542
24654
|
{ row: anchorRow, col: firstVisibleCol },
|
|
24543
24655
|
"row",
|
|
@@ -24568,6 +24680,7 @@ function XlsxGrid({
|
|
|
24568
24680
|
return;
|
|
24569
24681
|
}
|
|
24570
24682
|
startCellSelection(
|
|
24683
|
+
event.currentTarget,
|
|
24571
24684
|
event.pointerId,
|
|
24572
24685
|
{ row: firstVisibleRow, col: anchorCol },
|
|
24573
24686
|
"column",
|
|
@@ -24840,12 +24953,16 @@ function XlsxGrid({
|
|
|
24840
24953
|
const initialRange = normalizeRange2({ start: anchor, end: cell });
|
|
24841
24954
|
const isActive = isSameCell(activeCellRef.current, cell);
|
|
24842
24955
|
const committedOnPointerDown = !isActive || !editingCellRef.current;
|
|
24956
|
+
if (editingCellRef.current && !isActive) {
|
|
24957
|
+
commitEditingRef.current();
|
|
24958
|
+
}
|
|
24843
24959
|
const rowIndex = rowIndexByActual.get(cell.row);
|
|
24844
24960
|
const colIndex = colIndexByActual.get(cell.col);
|
|
24845
24961
|
if (rowIndex === void 0 || colIndex === void 0) {
|
|
24846
24962
|
return;
|
|
24847
24963
|
}
|
|
24848
24964
|
startCellSelection(
|
|
24965
|
+
event.currentTarget,
|
|
24849
24966
|
event.pointerId,
|
|
24850
24967
|
anchor,
|
|
24851
24968
|
"cell",
|
|
@@ -24923,6 +25040,7 @@ function XlsxGrid({
|
|
|
24923
25040
|
return;
|
|
24924
25041
|
}
|
|
24925
25042
|
startCellSelection(
|
|
25043
|
+
event.currentTarget,
|
|
24926
25044
|
event.pointerId,
|
|
24927
25045
|
{ row: firstVisibleRow, col: anchorCol },
|
|
24928
25046
|
"column",
|
|
@@ -24980,6 +25098,7 @@ function XlsxGrid({
|
|
|
24980
25098
|
return;
|
|
24981
25099
|
}
|
|
24982
25100
|
startCellSelection(
|
|
25101
|
+
event.currentTarget,
|
|
24983
25102
|
event.pointerId,
|
|
24984
25103
|
{ row: anchorRow, col: firstVisibleCol },
|
|
24985
25104
|
"row",
|
|
@@ -27222,9 +27341,10 @@ function XlsxGrid({
|
|
|
27222
27341
|
setGlobalCursor("row-resize");
|
|
27223
27342
|
document.body.style.userSelect = "none";
|
|
27224
27343
|
}
|
|
27225
|
-
function startCellSelection(pointerId, anchor, axis, originCell, pointerOrigin, originOverlayRect, committedOnPointerDown, initialRange, startClientX, startClientY) {
|
|
27226
|
-
|
|
27227
|
-
|
|
27344
|
+
function startCellSelection(target, pointerId, anchor, axis, originCell, pointerOrigin, originOverlayRect, committedOnPointerDown, initialRange, startClientX, startClientY) {
|
|
27345
|
+
clearPendingSelectionDrag();
|
|
27346
|
+
const previewRange = normalizeRange2(initialRange);
|
|
27347
|
+
pendingSelectionDragRef.current = {
|
|
27228
27348
|
anchor,
|
|
27229
27349
|
axis,
|
|
27230
27350
|
contentScaleX: pointerOrigin.contentScaleX,
|
|
@@ -27236,16 +27356,14 @@ function XlsxGrid({
|
|
|
27236
27356
|
originContentX: pointerOrigin.originContentX,
|
|
27237
27357
|
originContentY: pointerOrigin.originContentY,
|
|
27238
27358
|
pointerId,
|
|
27239
|
-
previewRange
|
|
27359
|
+
previewRange,
|
|
27240
27360
|
startClientX,
|
|
27241
27361
|
startClientY
|
|
27242
27362
|
};
|
|
27243
|
-
selectionPreviewRangeRef.current =
|
|
27244
|
-
displayedSelectionRef.current =
|
|
27245
|
-
applyPreviewOverlay(
|
|
27246
|
-
|
|
27247
|
-
document.body.style.userSelect = "none";
|
|
27248
|
-
installSelectionDragListeners(pointerId);
|
|
27363
|
+
selectionPreviewRangeRef.current = previewRange;
|
|
27364
|
+
displayedSelectionRef.current = previewRange;
|
|
27365
|
+
applyPreviewOverlay(previewRange);
|
|
27366
|
+
installPendingSelectionDragListeners(pointerId, target);
|
|
27249
27367
|
}
|
|
27250
27368
|
function resolveFillRange(sourceRange, cell) {
|
|
27251
27369
|
const normalizedSource = normalizeRange2(sourceRange);
|
|
@@ -27801,52 +27919,62 @@ function XlsxGrid({
|
|
|
27801
27919
|
),
|
|
27802
27920
|
/* @__PURE__ */ jsx3("canvas", { ref: cornerHeaderCanvasRef, style: canvasCornerHeaderStyle })
|
|
27803
27921
|
] }),
|
|
27804
|
-
editingCell && editingOverlayRect ?
|
|
27805
|
-
|
|
27806
|
-
|
|
27807
|
-
|
|
27808
|
-
|
|
27809
|
-
|
|
27810
|
-
|
|
27811
|
-
|
|
27812
|
-
|
|
27813
|
-
|
|
27814
|
-
|
|
27815
|
-
|
|
27816
|
-
|
|
27817
|
-
|
|
27818
|
-
|
|
27819
|
-
|
|
27820
|
-
|
|
27821
|
-
|
|
27822
|
-
|
|
27823
|
-
|
|
27824
|
-
|
|
27825
|
-
|
|
27826
|
-
|
|
27827
|
-
|
|
27828
|
-
|
|
27829
|
-
|
|
27830
|
-
|
|
27831
|
-
|
|
27832
|
-
|
|
27833
|
-
|
|
27834
|
-
|
|
27835
|
-
|
|
27836
|
-
|
|
27837
|
-
|
|
27838
|
-
|
|
27839
|
-
|
|
27840
|
-
|
|
27841
|
-
|
|
27842
|
-
|
|
27843
|
-
|
|
27844
|
-
|
|
27845
|
-
|
|
27846
|
-
|
|
27847
|
-
|
|
27848
|
-
|
|
27849
|
-
|
|
27922
|
+
editingCell && editingOverlayRect ? (() => {
|
|
27923
|
+
const editingCellStyle = getCellData(editingCell.row, editingCell.col).style;
|
|
27924
|
+
const editingBackground = typeof editingCellStyle.backgroundColor === "string" ? editingCellStyle.backgroundColor : resolveSheetSurface(activeSheet, palette);
|
|
27925
|
+
const editingColor = typeof editingCellStyle.color === "string" ? editingCellStyle.color : resolveReadableTextColor(null, editingBackground, palette);
|
|
27926
|
+
return /* @__PURE__ */ jsx3(
|
|
27927
|
+
"div",
|
|
27928
|
+
{
|
|
27929
|
+
style: {
|
|
27930
|
+
left: editingOverlayRect.left,
|
|
27931
|
+
position: "absolute",
|
|
27932
|
+
top: editingOverlayRect.top,
|
|
27933
|
+
width: editingOverlayRect.width,
|
|
27934
|
+
height: editingOverlayRect.height,
|
|
27935
|
+
zIndex: 28
|
|
27936
|
+
},
|
|
27937
|
+
children: /* @__PURE__ */ jsx3(
|
|
27938
|
+
"input",
|
|
27939
|
+
{
|
|
27940
|
+
ref: editingInputRef,
|
|
27941
|
+
autoFocus: true,
|
|
27942
|
+
onBlur: commitEditing,
|
|
27943
|
+
onChange: (event) => setEditingValue(event.target.value),
|
|
27944
|
+
onKeyDown: (event) => {
|
|
27945
|
+
event.stopPropagation();
|
|
27946
|
+
if (event.key === "Enter") {
|
|
27947
|
+
event.preventDefault();
|
|
27948
|
+
commitEditing();
|
|
27949
|
+
return;
|
|
27950
|
+
}
|
|
27951
|
+
if (event.key === "Escape") {
|
|
27952
|
+
event.preventDefault();
|
|
27953
|
+
cancelEditing();
|
|
27954
|
+
}
|
|
27955
|
+
},
|
|
27956
|
+
style: {
|
|
27957
|
+
backgroundColor: editingBackground,
|
|
27958
|
+
border: 0,
|
|
27959
|
+
boxShadow: `inset 0 0 0 ${selectionBorderWidth}px ${selectionStroke}`,
|
|
27960
|
+
boxSizing: "border-box",
|
|
27961
|
+
color: editingColor,
|
|
27962
|
+
display: "block",
|
|
27963
|
+
font: resolveCanvasFont(editingCellStyle, 12 * zoomFactor),
|
|
27964
|
+
height: "100%",
|
|
27965
|
+
margin: 0,
|
|
27966
|
+
minHeight: 0,
|
|
27967
|
+
outline: "none",
|
|
27968
|
+
overflow: "hidden",
|
|
27969
|
+
padding: scaleCssLengthExpression(DEFAULT_CELL_PADDING, zoomFactor),
|
|
27970
|
+
width: "100%"
|
|
27971
|
+
},
|
|
27972
|
+
value: editingValue
|
|
27973
|
+
}
|
|
27974
|
+
)
|
|
27975
|
+
}
|
|
27976
|
+
);
|
|
27977
|
+
})() : null,
|
|
27850
27978
|
activeCellAdornment && activeCellAdornmentRect ? /* @__PURE__ */ jsx3(
|
|
27851
27979
|
"div",
|
|
27852
27980
|
{
|