@leankylin-sheet/react 5.2.76 → 6.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.
@@ -17,6 +17,7 @@ export type SetContextOptions = {
17
17
  declare const WorkbookContext: React.Context<{
18
18
  context: Context;
19
19
  setContext: (recipe: (ctx: Context) => void, options?: SetContextOptions) => void;
20
+ setScrollContext: (recipe: (ctx: Context) => void) => void;
20
21
  settings: Required<Settings>;
21
22
  refs: RefValues;
22
23
  handleUndo: () => void;
package/dist/index.esm.js CHANGED
@@ -556,6 +556,7 @@ var defaultRefs = {
556
556
  var WorkbookContext = /*#__PURE__*/React.createContext({
557
557
  context: defaultContext(defaultRefs),
558
558
  setContext: function setContext() {},
559
+ setScrollContext: function setScrollContext() {},
559
560
  settings: defaultSettings,
560
561
  handleUndo: function handleUndo() {},
561
562
  handleRedo: function handleRedo() {},
@@ -1670,7 +1671,7 @@ var ScrollBar = function ScrollBar(_ref) {
1670
1671
  var _useContext = useContext(WorkbookContext),
1671
1672
  context = _useContext.context,
1672
1673
  refs = _useContext.refs,
1673
- setContext = _useContext.setContext;
1674
+ setScrollContext = _useContext.setScrollContext;
1674
1675
  var ref = axis === "x" ? refs.scrollbarX : refs.scrollbarY;
1675
1676
  var _useInViewport = useInViewport(ref),
1676
1677
  _useInViewport2 = _slicedToArray(_useInViewport, 1),
@@ -1703,11 +1704,11 @@ var ScrollBar = function ScrollBar(_ref) {
1703
1704
  className: "luckysheet-scrollbars luckysheet-scrollbar-ltr luckysheet-scrollbar-".concat(axis),
1704
1705
  onScroll: function onScroll() {
1705
1706
  if (axis === "x") {
1706
- setContext(function (draftCtx) {
1707
+ setScrollContext(function (draftCtx) {
1707
1708
  draftCtx.scrollLeft = refs.scrollbarX.current.scrollLeft;
1708
1709
  });
1709
1710
  } else {
1710
- setContext(function (draftCtx) {
1711
+ setScrollContext(function (draftCtx) {
1711
1712
  draftCtx.scrollTop = refs.scrollbarY.current.scrollTop;
1712
1713
  });
1713
1714
  }
@@ -4350,9 +4351,7 @@ var SheetOverlay = function SheetOverlay() {
4350
4351
  }, [setContext, refs.globalCache, refs.cellInput, refs.cellArea, refs.fxInput, refs.canvas]);
4351
4352
  var debounceMouseMove = useMemoizedFn(function (e) {
4352
4353
  var nativeEvent = e.nativeEvent;
4353
- setContext(function (draftCtx) {
4354
- handleCellAreaMouseMove(draftCtx, refs.globalCache, nativeEvent, refs.cellArea.current);
4355
- });
4354
+ handleCellAreaMouseMove(context, refs.globalCache, nativeEvent, refs.cellArea.current);
4356
4355
  });
4357
4356
  var debounceDragOver = useMemoizedFn(function (e) {
4358
4357
  var nativeEvent = e.nativeEvent;
@@ -4422,12 +4421,29 @@ var SheetOverlay = function SheetOverlay() {
4422
4421
  debouncedShowLinkCard(globalCache, rc.r, rc.c, false, true);
4423
4422
  }
4424
4423
  }, [debouncedShowLinkCard]);
4424
+ var lastHoverCellRef = useRef(null);
4425
4425
  var onMouseMove = useCallback(function (nativeEvent) {
4426
+ var _gc$commentBox, _gc$commentBox2, _gc$searchDialog, _gc$linkCard;
4427
+ var container = containerRef.current;
4428
+ var scrollX = refs.scrollbarX.current;
4429
+ var scrollY = refs.scrollbarY.current;
4430
+ if (!container || !scrollX || !scrollY) return;
4431
+ var gc = refs.globalCache;
4432
+ var isInteracting = !!context.luckysheet_scroll_status || !!context.luckysheet_select_status || !!context.luckysheet_rows_selected_status || !!context.luckysheet_cols_selected_status || !!context.luckysheet_cell_selected_move || !!context.luckysheet_cell_selected_extend || !!context.luckysheet_cols_change_size || !!context.luckysheet_rows_change_size || ((_gc$commentBox = gc.commentBox) === null || _gc$commentBox === void 0 ? void 0 : _gc$commentBox.movingId) != null || ((_gc$commentBox2 = gc.commentBox) === null || _gc$commentBox2 === void 0 ? void 0 : _gc$commentBox2.resizingId) != null || gc.image != null || ((_gc$searchDialog = gc.searchDialog) === null || _gc$searchDialog === void 0 ? void 0 : _gc$searchDialog.moveProps) != null || ((_gc$linkCard = gc.linkCard) === null || _gc$linkCard === void 0 ? void 0 : _gc$linkCard.rangeSelectionModal) != null;
4433
+ if (!isInteracting) {
4434
+ var rc = getCellRowColumn(context, nativeEvent, container, scrollX, scrollY);
4435
+ var last = lastHoverCellRef.current;
4436
+ var hoverChanged = rc == null ? last != null : last == null || last.r !== rc.r || last.c !== rc.c;
4437
+ if (!hoverChanged) {
4438
+ return;
4439
+ }
4440
+ lastHoverCellRef.current = rc !== null && rc !== void 0 ? rc : null;
4441
+ }
4426
4442
  setContext(function (draftCtx) {
4427
- overShowLinkCard(draftCtx, refs.globalCache, nativeEvent, containerRef.current, refs.scrollbarX.current, refs.scrollbarY.current);
4428
- handleOverlayMouseMove(draftCtx, refs.globalCache, nativeEvent, refs.cellInput.current, refs.scrollbarX.current, refs.scrollbarY.current, containerRef.current, refs.fxInput.current);
4443
+ overShowLinkCard(draftCtx, refs.globalCache, nativeEvent, container, scrollX, scrollY);
4444
+ handleOverlayMouseMove(draftCtx, refs.globalCache, nativeEvent, refs.cellInput.current, scrollX, scrollY, container, refs.fxInput.current);
4429
4445
  });
4430
- }, [overShowLinkCard, refs.cellInput, refs.fxInput, refs.globalCache, refs.scrollbarX, refs.scrollbarY, setContext]);
4446
+ }, [overShowLinkCard, context, refs.cellInput, refs.fxInput, refs.globalCache, refs.scrollbarX, refs.scrollbarY, setContext]);
4431
4447
  var onMouseUp = useCallback(function (nativeEvent) {
4432
4448
  setContext(function (draftCtx) {
4433
4449
  try {
@@ -5014,9 +5030,7 @@ var Sheet = function Sheet(_ref) {
5014
5030
  return false;
5015
5031
  }
5016
5032
  var onWheel = useCallback(function (e) {
5017
- setContext(function (draftCtx) {
5018
- handleGlobalWheel(draftCtx, e, refs.globalCache, refs.scrollbarX.current, refs.scrollbarY.current);
5019
- });
5033
+ handleGlobalWheel(context, e, refs.globalCache, refs.scrollbarX.current, refs.scrollbarY.current);
5020
5034
  if (e.deltaY === 0 && e.deltaX === 0) {
5021
5035
  return;
5022
5036
  }
@@ -5037,7 +5051,7 @@ var Sheet = function Sheet(_ref) {
5037
5051
  e.preventDefault();
5038
5052
  }
5039
5053
  }
5040
- }, [refs.globalCache, refs.scrollbarX, refs.scrollbarY, setContext]);
5054
+ }, [context, refs.globalCache, refs.scrollbarX, refs.scrollbarY]);
5041
5055
  useEffect(function () {
5042
5056
  var container = containerRef.current;
5043
5057
  container === null || container === void 0 ? void 0 : container.addEventListener("wheel", onWheel);
@@ -12119,60 +12133,77 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
12119
12133
  }
12120
12134
  }
12121
12135
  contextRef.current = result;
12122
- setContext(result);
12136
+ setContext(function (prev) {
12137
+ if (prev === ctx_) {
12138
+ return result;
12139
+ }
12140
+ var merged = applyPatches(prev, patches);
12141
+ contextRef.current = merged;
12142
+ return merged;
12143
+ });
12144
+ });
12145
+ var setScrollContext = useMemoizedFn(function (recipe) {
12146
+ setContext(function (ctx_) {
12147
+ var result = produce(ctx_, recipe);
12148
+ if (result === ctx_) {
12149
+ return ctx_;
12150
+ }
12151
+ contextRef.current = result;
12152
+ return result;
12153
+ });
12123
12154
  });
12124
12155
  var handleUndo = useCallback(function () {
12125
12156
  var history = globalCache.current.undoList.pop();
12126
12157
  if (history) {
12127
- var _history$options, _history$options3;
12128
- var ctx_ = contextRef.current;
12129
- if ((_history$options = history.options) === null || _history$options === void 0 ? void 0 : _history$options.deleteSheetOp) {
12130
- var _history$options$dele, _history$options$dele2;
12131
- history.inversePatches[0].path[1] = ctx_.luckysheetfile.length;
12132
- var order = (_history$options$dele = history.options.deletedSheet) === null || _history$options$dele === void 0 ? void 0 : (_history$options$dele2 = _history$options$dele.value) === null || _history$options$dele2 === void 0 ? void 0 : _history$options$dele2.order;
12133
- var sheetsRight = ctx_.luckysheetfile.filter(function (sheet) {
12134
- var _history$options2, _history$options2$del;
12135
- return (sheet === null || sheet === void 0 ? void 0 : sheet.order) >= order && sheet.id !== (history === null || history === void 0 ? void 0 : (_history$options2 = history.options) === null || _history$options2 === void 0 ? void 0 : (_history$options2$del = _history$options2.deleteSheetOp) === null || _history$options2$del === void 0 ? void 0 : _history$options2$del.id);
12136
- });
12137
- _.forEach(sheetsRight, function (sheet) {
12138
- history.inversePatches.push({
12139
- op: "replace",
12140
- path: ["luckysheetfile", getSheetIndex(ctx_, sheet.id), "order"],
12141
- value: (sheet === null || sheet === void 0 ? void 0 : sheet.order) + 1
12158
+ setContext(function (ctx_) {
12159
+ var _history$options, _history$options3;
12160
+ if ((_history$options = history.options) === null || _history$options === void 0 ? void 0 : _history$options.deleteSheetOp) {
12161
+ var _history$options$dele, _history$options$dele2;
12162
+ history.inversePatches[0].path[1] = ctx_.luckysheetfile.length;
12163
+ var order = (_history$options$dele = history.options.deletedSheet) === null || _history$options$dele === void 0 ? void 0 : (_history$options$dele2 = _history$options$dele.value) === null || _history$options$dele2 === void 0 ? void 0 : _history$options$dele2.order;
12164
+ var sheetsRight = ctx_.luckysheetfile.filter(function (sheet) {
12165
+ var _history$options2, _history$options2$del;
12166
+ return (sheet === null || sheet === void 0 ? void 0 : sheet.order) >= order && sheet.id !== (history === null || history === void 0 ? void 0 : (_history$options2 = history.options) === null || _history$options2 === void 0 ? void 0 : (_history$options2$del = _history$options2.deleteSheetOp) === null || _history$options2$del === void 0 ? void 0 : _history$options2$del.id);
12142
12167
  });
12143
- });
12144
- }
12145
- var newContext = applyPatches(ctx_, history.inversePatches);
12146
- globalCache.current.redoList.push(history);
12147
- var inversedOptions = inverseRowColOptions(history.options);
12148
- if (inversedOptions === null || inversedOptions === void 0 ? void 0 : inversedOptions.insertRowColOp) {
12149
- inversedOptions.restoreDeletedCells = true;
12150
- }
12151
- if ((_history$options3 = history.options) === null || _history$options3 === void 0 ? void 0 : _history$options3.addSheetOp) {
12152
- var _inversedOptions$addS;
12153
- var index = getSheetIndex(ctx_, history.options.addSheet.id);
12154
- inversedOptions.addSheet = {
12155
- id: history.options.addSheet.id,
12156
- index: index,
12157
- value: _.cloneDeep(ctx_.luckysheetfile[index])
12158
- };
12159
- inversedOptions.addSheet.value.celldata = dataToCelldata((_inversedOptions$addS = inversedOptions.addSheet.value) === null || _inversedOptions$addS === void 0 ? void 0 : _inversedOptions$addS.data);
12160
- delete inversedOptions.addSheet.value.data;
12161
- }
12162
- emitOp(newContext, history.inversePatches, inversedOptions, true);
12163
- contextRef.current = newContext;
12164
- setContext(newContext);
12168
+ _.forEach(sheetsRight, function (sheet) {
12169
+ history.inversePatches.push({
12170
+ op: "replace",
12171
+ path: ["luckysheetfile", getSheetIndex(ctx_, sheet.id), "order"],
12172
+ value: (sheet === null || sheet === void 0 ? void 0 : sheet.order) + 1
12173
+ });
12174
+ });
12175
+ }
12176
+ var newContext = applyPatches(ctx_, history.inversePatches);
12177
+ globalCache.current.redoList.push(history);
12178
+ var inversedOptions = inverseRowColOptions(history.options);
12179
+ if (inversedOptions === null || inversedOptions === void 0 ? void 0 : inversedOptions.insertRowColOp) {
12180
+ inversedOptions.restoreDeletedCells = true;
12181
+ }
12182
+ if ((_history$options3 = history.options) === null || _history$options3 === void 0 ? void 0 : _history$options3.addSheetOp) {
12183
+ var _inversedOptions$addS;
12184
+ var index = getSheetIndex(ctx_, history.options.addSheet.id);
12185
+ inversedOptions.addSheet = {
12186
+ id: history.options.addSheet.id,
12187
+ index: index,
12188
+ value: _.cloneDeep(ctx_.luckysheetfile[index])
12189
+ };
12190
+ inversedOptions.addSheet.value.celldata = dataToCelldata((_inversedOptions$addS = inversedOptions.addSheet.value) === null || _inversedOptions$addS === void 0 ? void 0 : _inversedOptions$addS.data);
12191
+ delete inversedOptions.addSheet.value.data;
12192
+ }
12193
+ emitOp(newContext, history.inversePatches, inversedOptions, true);
12194
+ return newContext;
12195
+ });
12165
12196
  }
12166
12197
  }, [emitOp]);
12167
12198
  var handleRedo = useCallback(function () {
12168
12199
  var history = globalCache.current.redoList.pop();
12169
12200
  if (history) {
12170
- var ctx_ = contextRef.current;
12171
- var newContext = applyPatches(ctx_, history.patches);
12172
- globalCache.current.undoList.push(history);
12173
- emitOp(newContext, history.patches, history.options);
12174
- contextRef.current = newContext;
12175
- setContext(newContext);
12201
+ setContext(function (ctx_) {
12202
+ var newContext = applyPatches(ctx_, history.patches);
12203
+ globalCache.current.undoList.push(history);
12204
+ emitOp(newContext, history.patches, history.options);
12205
+ return newContext;
12206
+ });
12176
12207
  }
12177
12208
  }, [emitOp]);
12178
12209
  useEffect(function () {
@@ -12193,12 +12224,13 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
12193
12224
  return {
12194
12225
  context: context,
12195
12226
  setContext: setContextWithProduce,
12227
+ setScrollContext: setScrollContext,
12196
12228
  settings: mergedSettings,
12197
12229
  handleUndo: handleUndo,
12198
12230
  handleRedo: handleRedo,
12199
12231
  refs: refs
12200
12232
  };
12201
- }, [context, handleRedo, handleUndo, mergedSettings, refs, setContextWithProduce]);
12233
+ }, [context, handleRedo, handleUndo, mergedSettings, refs, setContextWithProduce, setScrollContext]);
12202
12234
  useEffect(function () {
12203
12235
  if (!_.isEmpty(context.luckysheetfile)) {
12204
12236
  onChange === null || onChange === void 0 ? void 0 : onChange(context.luckysheetfile);
package/dist/index.js CHANGED
@@ -566,6 +566,7 @@ var defaultRefs = {
566
566
  var WorkbookContext = /*#__PURE__*/React__default['default'].createContext({
567
567
  context: core.defaultContext(defaultRefs),
568
568
  setContext: function setContext() {},
569
+ setScrollContext: function setScrollContext() {},
569
570
  settings: core.defaultSettings,
570
571
  handleUndo: function handleUndo() {},
571
572
  handleRedo: function handleRedo() {},
@@ -1680,7 +1681,7 @@ var ScrollBar = function ScrollBar(_ref) {
1680
1681
  var _useContext = React.useContext(WorkbookContext),
1681
1682
  context = _useContext.context,
1682
1683
  refs = _useContext.refs,
1683
- setContext = _useContext.setContext;
1684
+ setScrollContext = _useContext.setScrollContext;
1684
1685
  var ref = axis === "x" ? refs.scrollbarX : refs.scrollbarY;
1685
1686
  var _useInViewport = ahooks.useInViewport(ref),
1686
1687
  _useInViewport2 = _slicedToArray(_useInViewport, 1),
@@ -1713,11 +1714,11 @@ var ScrollBar = function ScrollBar(_ref) {
1713
1714
  className: "luckysheet-scrollbars luckysheet-scrollbar-ltr luckysheet-scrollbar-".concat(axis),
1714
1715
  onScroll: function onScroll() {
1715
1716
  if (axis === "x") {
1716
- setContext(function (draftCtx) {
1717
+ setScrollContext(function (draftCtx) {
1717
1718
  draftCtx.scrollLeft = refs.scrollbarX.current.scrollLeft;
1718
1719
  });
1719
1720
  } else {
1720
- setContext(function (draftCtx) {
1721
+ setScrollContext(function (draftCtx) {
1721
1722
  draftCtx.scrollTop = refs.scrollbarY.current.scrollTop;
1722
1723
  });
1723
1724
  }
@@ -4360,9 +4361,7 @@ var SheetOverlay = function SheetOverlay() {
4360
4361
  }, [setContext, refs.globalCache, refs.cellInput, refs.cellArea, refs.fxInput, refs.canvas]);
4361
4362
  var debounceMouseMove = ahooks.useMemoizedFn(function (e) {
4362
4363
  var nativeEvent = e.nativeEvent;
4363
- setContext(function (draftCtx) {
4364
- core.handleCellAreaMouseMove(draftCtx, refs.globalCache, nativeEvent, refs.cellArea.current);
4365
- });
4364
+ core.handleCellAreaMouseMove(context, refs.globalCache, nativeEvent, refs.cellArea.current);
4366
4365
  });
4367
4366
  var debounceDragOver = ahooks.useMemoizedFn(function (e) {
4368
4367
  var nativeEvent = e.nativeEvent;
@@ -4432,12 +4431,29 @@ var SheetOverlay = function SheetOverlay() {
4432
4431
  debouncedShowLinkCard(globalCache, rc.r, rc.c, false, true);
4433
4432
  }
4434
4433
  }, [debouncedShowLinkCard]);
4434
+ var lastHoverCellRef = React.useRef(null);
4435
4435
  var onMouseMove = React.useCallback(function (nativeEvent) {
4436
+ var _gc$commentBox, _gc$commentBox2, _gc$searchDialog, _gc$linkCard;
4437
+ var container = containerRef.current;
4438
+ var scrollX = refs.scrollbarX.current;
4439
+ var scrollY = refs.scrollbarY.current;
4440
+ if (!container || !scrollX || !scrollY) return;
4441
+ var gc = refs.globalCache;
4442
+ var isInteracting = !!context.luckysheet_scroll_status || !!context.luckysheet_select_status || !!context.luckysheet_rows_selected_status || !!context.luckysheet_cols_selected_status || !!context.luckysheet_cell_selected_move || !!context.luckysheet_cell_selected_extend || !!context.luckysheet_cols_change_size || !!context.luckysheet_rows_change_size || ((_gc$commentBox = gc.commentBox) === null || _gc$commentBox === void 0 ? void 0 : _gc$commentBox.movingId) != null || ((_gc$commentBox2 = gc.commentBox) === null || _gc$commentBox2 === void 0 ? void 0 : _gc$commentBox2.resizingId) != null || gc.image != null || ((_gc$searchDialog = gc.searchDialog) === null || _gc$searchDialog === void 0 ? void 0 : _gc$searchDialog.moveProps) != null || ((_gc$linkCard = gc.linkCard) === null || _gc$linkCard === void 0 ? void 0 : _gc$linkCard.rangeSelectionModal) != null;
4443
+ if (!isInteracting) {
4444
+ var rc = core.getCellRowColumn(context, nativeEvent, container, scrollX, scrollY);
4445
+ var last = lastHoverCellRef.current;
4446
+ var hoverChanged = rc == null ? last != null : last == null || last.r !== rc.r || last.c !== rc.c;
4447
+ if (!hoverChanged) {
4448
+ return;
4449
+ }
4450
+ lastHoverCellRef.current = rc !== null && rc !== void 0 ? rc : null;
4451
+ }
4436
4452
  setContext(function (draftCtx) {
4437
- overShowLinkCard(draftCtx, refs.globalCache, nativeEvent, containerRef.current, refs.scrollbarX.current, refs.scrollbarY.current);
4438
- core.handleOverlayMouseMove(draftCtx, refs.globalCache, nativeEvent, refs.cellInput.current, refs.scrollbarX.current, refs.scrollbarY.current, containerRef.current, refs.fxInput.current);
4453
+ overShowLinkCard(draftCtx, refs.globalCache, nativeEvent, container, scrollX, scrollY);
4454
+ core.handleOverlayMouseMove(draftCtx, refs.globalCache, nativeEvent, refs.cellInput.current, scrollX, scrollY, container, refs.fxInput.current);
4439
4455
  });
4440
- }, [overShowLinkCard, refs.cellInput, refs.fxInput, refs.globalCache, refs.scrollbarX, refs.scrollbarY, setContext]);
4456
+ }, [overShowLinkCard, context, refs.cellInput, refs.fxInput, refs.globalCache, refs.scrollbarX, refs.scrollbarY, setContext]);
4441
4457
  var onMouseUp = React.useCallback(function (nativeEvent) {
4442
4458
  setContext(function (draftCtx) {
4443
4459
  try {
@@ -5024,9 +5040,7 @@ var Sheet = function Sheet(_ref) {
5024
5040
  return false;
5025
5041
  }
5026
5042
  var onWheel = React.useCallback(function (e) {
5027
- setContext(function (draftCtx) {
5028
- core.handleGlobalWheel(draftCtx, e, refs.globalCache, refs.scrollbarX.current, refs.scrollbarY.current);
5029
- });
5043
+ core.handleGlobalWheel(context, e, refs.globalCache, refs.scrollbarX.current, refs.scrollbarY.current);
5030
5044
  if (e.deltaY === 0 && e.deltaX === 0) {
5031
5045
  return;
5032
5046
  }
@@ -5047,7 +5061,7 @@ var Sheet = function Sheet(_ref) {
5047
5061
  e.preventDefault();
5048
5062
  }
5049
5063
  }
5050
- }, [refs.globalCache, refs.scrollbarX, refs.scrollbarY, setContext]);
5064
+ }, [context, refs.globalCache, refs.scrollbarX, refs.scrollbarY]);
5051
5065
  React.useEffect(function () {
5052
5066
  var container = containerRef.current;
5053
5067
  container === null || container === void 0 ? void 0 : container.addEventListener("wheel", onWheel);
@@ -12129,60 +12143,77 @@ var Workbook = /*#__PURE__*/React__default['default'].forwardRef(function (_ref,
12129
12143
  }
12130
12144
  }
12131
12145
  contextRef.current = result;
12132
- setContext(result);
12146
+ setContext(function (prev) {
12147
+ if (prev === ctx_) {
12148
+ return result;
12149
+ }
12150
+ var merged = produce.applyPatches(prev, patches);
12151
+ contextRef.current = merged;
12152
+ return merged;
12153
+ });
12154
+ });
12155
+ var setScrollContext = ahooks.useMemoizedFn(function (recipe) {
12156
+ setContext(function (ctx_) {
12157
+ var result = produce__default['default'](ctx_, recipe);
12158
+ if (result === ctx_) {
12159
+ return ctx_;
12160
+ }
12161
+ contextRef.current = result;
12162
+ return result;
12163
+ });
12133
12164
  });
12134
12165
  var handleUndo = React.useCallback(function () {
12135
12166
  var history = globalCache.current.undoList.pop();
12136
12167
  if (history) {
12137
- var _history$options, _history$options3;
12138
- var ctx_ = contextRef.current;
12139
- if ((_history$options = history.options) === null || _history$options === void 0 ? void 0 : _history$options.deleteSheetOp) {
12140
- var _history$options$dele, _history$options$dele2;
12141
- history.inversePatches[0].path[1] = ctx_.luckysheetfile.length;
12142
- var order = (_history$options$dele = history.options.deletedSheet) === null || _history$options$dele === void 0 ? void 0 : (_history$options$dele2 = _history$options$dele.value) === null || _history$options$dele2 === void 0 ? void 0 : _history$options$dele2.order;
12143
- var sheetsRight = ctx_.luckysheetfile.filter(function (sheet) {
12144
- var _history$options2, _history$options2$del;
12145
- return (sheet === null || sheet === void 0 ? void 0 : sheet.order) >= order && sheet.id !== (history === null || history === void 0 ? void 0 : (_history$options2 = history.options) === null || _history$options2 === void 0 ? void 0 : (_history$options2$del = _history$options2.deleteSheetOp) === null || _history$options2$del === void 0 ? void 0 : _history$options2$del.id);
12146
- });
12147
- ___default['default'].forEach(sheetsRight, function (sheet) {
12148
- history.inversePatches.push({
12149
- op: "replace",
12150
- path: ["luckysheetfile", core.getSheetIndex(ctx_, sheet.id), "order"],
12151
- value: (sheet === null || sheet === void 0 ? void 0 : sheet.order) + 1
12168
+ setContext(function (ctx_) {
12169
+ var _history$options, _history$options3;
12170
+ if ((_history$options = history.options) === null || _history$options === void 0 ? void 0 : _history$options.deleteSheetOp) {
12171
+ var _history$options$dele, _history$options$dele2;
12172
+ history.inversePatches[0].path[1] = ctx_.luckysheetfile.length;
12173
+ var order = (_history$options$dele = history.options.deletedSheet) === null || _history$options$dele === void 0 ? void 0 : (_history$options$dele2 = _history$options$dele.value) === null || _history$options$dele2 === void 0 ? void 0 : _history$options$dele2.order;
12174
+ var sheetsRight = ctx_.luckysheetfile.filter(function (sheet) {
12175
+ var _history$options2, _history$options2$del;
12176
+ return (sheet === null || sheet === void 0 ? void 0 : sheet.order) >= order && sheet.id !== (history === null || history === void 0 ? void 0 : (_history$options2 = history.options) === null || _history$options2 === void 0 ? void 0 : (_history$options2$del = _history$options2.deleteSheetOp) === null || _history$options2$del === void 0 ? void 0 : _history$options2$del.id);
12152
12177
  });
12153
- });
12154
- }
12155
- var newContext = produce.applyPatches(ctx_, history.inversePatches);
12156
- globalCache.current.redoList.push(history);
12157
- var inversedOptions = core.inverseRowColOptions(history.options);
12158
- if (inversedOptions === null || inversedOptions === void 0 ? void 0 : inversedOptions.insertRowColOp) {
12159
- inversedOptions.restoreDeletedCells = true;
12160
- }
12161
- if ((_history$options3 = history.options) === null || _history$options3 === void 0 ? void 0 : _history$options3.addSheetOp) {
12162
- var _inversedOptions$addS;
12163
- var index = core.getSheetIndex(ctx_, history.options.addSheet.id);
12164
- inversedOptions.addSheet = {
12165
- id: history.options.addSheet.id,
12166
- index: index,
12167
- value: ___default['default'].cloneDeep(ctx_.luckysheetfile[index])
12168
- };
12169
- inversedOptions.addSheet.value.celldata = dataToCelldata((_inversedOptions$addS = inversedOptions.addSheet.value) === null || _inversedOptions$addS === void 0 ? void 0 : _inversedOptions$addS.data);
12170
- delete inversedOptions.addSheet.value.data;
12171
- }
12172
- emitOp(newContext, history.inversePatches, inversedOptions, true);
12173
- contextRef.current = newContext;
12174
- setContext(newContext);
12178
+ ___default['default'].forEach(sheetsRight, function (sheet) {
12179
+ history.inversePatches.push({
12180
+ op: "replace",
12181
+ path: ["luckysheetfile", core.getSheetIndex(ctx_, sheet.id), "order"],
12182
+ value: (sheet === null || sheet === void 0 ? void 0 : sheet.order) + 1
12183
+ });
12184
+ });
12185
+ }
12186
+ var newContext = produce.applyPatches(ctx_, history.inversePatches);
12187
+ globalCache.current.redoList.push(history);
12188
+ var inversedOptions = core.inverseRowColOptions(history.options);
12189
+ if (inversedOptions === null || inversedOptions === void 0 ? void 0 : inversedOptions.insertRowColOp) {
12190
+ inversedOptions.restoreDeletedCells = true;
12191
+ }
12192
+ if ((_history$options3 = history.options) === null || _history$options3 === void 0 ? void 0 : _history$options3.addSheetOp) {
12193
+ var _inversedOptions$addS;
12194
+ var index = core.getSheetIndex(ctx_, history.options.addSheet.id);
12195
+ inversedOptions.addSheet = {
12196
+ id: history.options.addSheet.id,
12197
+ index: index,
12198
+ value: ___default['default'].cloneDeep(ctx_.luckysheetfile[index])
12199
+ };
12200
+ inversedOptions.addSheet.value.celldata = dataToCelldata((_inversedOptions$addS = inversedOptions.addSheet.value) === null || _inversedOptions$addS === void 0 ? void 0 : _inversedOptions$addS.data);
12201
+ delete inversedOptions.addSheet.value.data;
12202
+ }
12203
+ emitOp(newContext, history.inversePatches, inversedOptions, true);
12204
+ return newContext;
12205
+ });
12175
12206
  }
12176
12207
  }, [emitOp]);
12177
12208
  var handleRedo = React.useCallback(function () {
12178
12209
  var history = globalCache.current.redoList.pop();
12179
12210
  if (history) {
12180
- var ctx_ = contextRef.current;
12181
- var newContext = produce.applyPatches(ctx_, history.patches);
12182
- globalCache.current.undoList.push(history);
12183
- emitOp(newContext, history.patches, history.options);
12184
- contextRef.current = newContext;
12185
- setContext(newContext);
12211
+ setContext(function (ctx_) {
12212
+ var newContext = produce.applyPatches(ctx_, history.patches);
12213
+ globalCache.current.undoList.push(history);
12214
+ emitOp(newContext, history.patches, history.options);
12215
+ return newContext;
12216
+ });
12186
12217
  }
12187
12218
  }, [emitOp]);
12188
12219
  React.useEffect(function () {
@@ -12203,12 +12234,13 @@ var Workbook = /*#__PURE__*/React__default['default'].forwardRef(function (_ref,
12203
12234
  return {
12204
12235
  context: context,
12205
12236
  setContext: setContextWithProduce,
12237
+ setScrollContext: setScrollContext,
12206
12238
  settings: mergedSettings,
12207
12239
  handleUndo: handleUndo,
12208
12240
  handleRedo: handleRedo,
12209
12241
  refs: refs
12210
12242
  };
12211
- }, [context, handleRedo, handleUndo, mergedSettings, refs, setContextWithProduce]);
12243
+ }, [context, handleRedo, handleUndo, mergedSettings, refs, setContextWithProduce, setScrollContext]);
12212
12244
  React.useEffect(function () {
12213
12245
  if (!___default['default'].isEmpty(context.luckysheetfile)) {
12214
12246
  onChange === null || onChange === void 0 ? void 0 : onChange(context.luckysheetfile);