@extend-ai/react-xlsx 0.8.8 → 0.9.1

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 CHANGED
@@ -21579,6 +21579,9 @@ function XlsxGrid({
21579
21579
  const selectionCommitFrameRef = React4.useRef(null);
21580
21580
  const selectionRef = React4.useRef(null);
21581
21581
  const editingCellRef = React4.useRef(null);
21582
+ const commitEditingRef = React4.useRef(() => {
21583
+ });
21584
+ const editingInputRef = React4.useRef(null);
21582
21585
  const readOnlyRef = React4.useRef(readOnly);
21583
21586
  const committedZoomScaleRef = React4.useRef(zoomScale);
21584
21587
  const gestureZoomScaleRef = React4.useRef(zoomScale);
@@ -22456,6 +22459,18 @@ function XlsxGrid({
22456
22459
  React4.useEffect(() => {
22457
22460
  editingCellRef.current = editingCell;
22458
22461
  }, [editingCell]);
22462
+ React4.useLayoutEffect(() => {
22463
+ if (!editingCell) {
22464
+ return;
22465
+ }
22466
+ const input = editingInputRef.current;
22467
+ if (!input) {
22468
+ return;
22469
+ }
22470
+ input.focus();
22471
+ const caret = input.value.length;
22472
+ input.setSelectionRange(caret, caret);
22473
+ }, [editingCell]);
22459
22474
  React4.useEffect(() => {
22460
22475
  readOnlyRef.current = readOnly;
22461
22476
  }, [readOnly]);
@@ -23215,6 +23230,9 @@ function XlsxGrid({
23215
23230
  setEditingValue("");
23216
23231
  focusGrid();
23217
23232
  }, [focusGrid]);
23233
+ React4.useEffect(() => {
23234
+ commitEditingRef.current = commitEditing;
23235
+ }, [commitEditing]);
23218
23236
  const [, startBatchTransition] = React4.useTransition();
23219
23237
  const [, startSelectionTransition] = React4.useTransition();
23220
23238
  const [asyncViewportRowBatch, setAsyncViewportRowBatch] = React4.useState(null);
@@ -24517,6 +24535,9 @@ function XlsxGrid({
24517
24535
  const initialRange = normalizeRange2({ start: anchor, end: targetCell });
24518
24536
  const isActive = isSameCell(activeCellRef.current, targetCell);
24519
24537
  const committedOnPointerDown = !isActive || !editingCellRef.current;
24538
+ if (editingCellRef.current && !isActive) {
24539
+ commitEditingRef.current();
24540
+ }
24520
24541
  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);
24521
24542
  const originOverlayRect = targetCell.row === cell.row && targetCell.col === cell.col ? resolveMountedCellOverlayRect(event.currentTarget) : resolveOverlayRect(initialRange);
24522
24543
  if (!pointerOrigin) {
@@ -24872,6 +24893,9 @@ function XlsxGrid({
24872
24893
  const initialRange = normalizeRange2({ start: anchor, end: cell });
24873
24894
  const isActive = isSameCell(activeCellRef.current, cell);
24874
24895
  const committedOnPointerDown = !isActive || !editingCellRef.current;
24896
+ if (editingCellRef.current && !isActive) {
24897
+ commitEditingRef.current();
24898
+ }
24875
24899
  const rowIndex = rowIndexByActual.get(cell.row);
24876
24900
  const colIndex = colIndexByActual.get(cell.col);
24877
24901
  if (rowIndex === void 0 || colIndex === void 0) {
@@ -27833,52 +27857,62 @@ function XlsxGrid({
27833
27857
  ),
27834
27858
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("canvas", { ref: cornerHeaderCanvasRef, style: canvasCornerHeaderStyle })
27835
27859
  ] }),
27836
- editingCell && editingOverlayRect ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
27837
- "div",
27838
- {
27839
- style: {
27840
- left: editingOverlayRect.left,
27841
- position: "absolute",
27842
- top: editingOverlayRect.top,
27843
- width: editingOverlayRect.width,
27844
- height: editingOverlayRect.height,
27845
- zIndex: 28
27846
- },
27847
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
27848
- "input",
27849
- {
27850
- autoFocus: true,
27851
- onBlur: commitEditing,
27852
- onChange: (event) => setEditingValue(event.target.value),
27853
- onKeyDown: (event) => {
27854
- event.stopPropagation();
27855
- if (event.key === "Enter") {
27856
- event.preventDefault();
27857
- commitEditing();
27858
- return;
27859
- }
27860
- if (event.key === "Escape") {
27861
- event.preventDefault();
27862
- cancelEditing();
27863
- }
27864
- },
27865
- style: {
27866
- backgroundColor: resolveSheetSurface(activeSheet, palette),
27867
- border: 0,
27868
- boxShadow: `inset 0 0 0 ${selectionBorderWidth}px ${selectionStroke}`,
27869
- color: "#000000",
27870
- font: resolveCanvasFont(getCellData(editingCell.row, editingCell.col).style, 12 * zoomFactor),
27871
- height: "100%",
27872
- margin: 0,
27873
- outline: "none",
27874
- padding: scaleCssLengthExpression(DEFAULT_CELL_PADDING, zoomFactor),
27875
- width: "100%"
27876
- },
27877
- value: editingValue
27878
- }
27879
- )
27880
- }
27881
- ) : null,
27860
+ editingCell && editingOverlayRect ? (() => {
27861
+ const editingCellStyle = getCellData(editingCell.row, editingCell.col).style;
27862
+ const editingBackground = typeof editingCellStyle.backgroundColor === "string" ? editingCellStyle.backgroundColor : resolveSheetSurface(activeSheet, palette);
27863
+ const editingColor = typeof editingCellStyle.color === "string" ? editingCellStyle.color : resolveReadableTextColor(null, editingBackground, palette);
27864
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
27865
+ "div",
27866
+ {
27867
+ style: {
27868
+ left: editingOverlayRect.left,
27869
+ position: "absolute",
27870
+ top: editingOverlayRect.top,
27871
+ width: editingOverlayRect.width,
27872
+ height: editingOverlayRect.height,
27873
+ zIndex: 28
27874
+ },
27875
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
27876
+ "input",
27877
+ {
27878
+ ref: editingInputRef,
27879
+ autoFocus: true,
27880
+ onBlur: commitEditing,
27881
+ onChange: (event) => setEditingValue(event.target.value),
27882
+ onKeyDown: (event) => {
27883
+ event.stopPropagation();
27884
+ if (event.key === "Enter") {
27885
+ event.preventDefault();
27886
+ commitEditing();
27887
+ return;
27888
+ }
27889
+ if (event.key === "Escape") {
27890
+ event.preventDefault();
27891
+ cancelEditing();
27892
+ }
27893
+ },
27894
+ style: {
27895
+ backgroundColor: editingBackground,
27896
+ border: 0,
27897
+ boxShadow: `inset 0 0 0 ${selectionBorderWidth}px ${selectionStroke}`,
27898
+ boxSizing: "border-box",
27899
+ color: editingColor,
27900
+ display: "block",
27901
+ font: resolveCanvasFont(editingCellStyle, 12 * zoomFactor),
27902
+ height: "100%",
27903
+ margin: 0,
27904
+ minHeight: 0,
27905
+ outline: "none",
27906
+ overflow: "hidden",
27907
+ padding: scaleCssLengthExpression(DEFAULT_CELL_PADDING, zoomFactor),
27908
+ width: "100%"
27909
+ },
27910
+ value: editingValue
27911
+ }
27912
+ )
27913
+ }
27914
+ );
27915
+ })() : null,
27882
27916
  activeCellAdornment && activeCellAdornmentRect ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
27883
27917
  "div",
27884
27918
  {