@leankylin-sheet/react 5.2.76 → 5.2.77

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.esm.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { defaultContext, defaultSettings, getSheetIndex, colLocationByIndex, fixPositionOnFrozenCells, colLocation, getFlowdata, isAllowEdit, handleColumnHeaderMouseDown, handleColSizeHandleMouseDown, handleColFreezeHandleMouseDown, handleContextMenu, selectTitlesMap, selectTitlesRange, fixColumnStyleOverflowInFreeze, rowLocationByIndex, rowLocation, handleRowHeaderMouseDown, handleRowSizeHandleMouseDown, handleRowFreezeHandleMouseDown, fixRowStyleOverflowInFreeze, functionHTMLGenerate, locale, getCellValue, createRangeHightlight, isInlineStringCell, getInlineStringHTML, valueShowEs, escapeHTMLTag, escapeScriptTag, isShowHidenCR, cancelNormalSelected, moveHighlightCell, updateCell, israngeseleciton, handleFormulaInput, onSearchDialogMoveStart, replaceAll, replace, searchAll, searchNext, changeSheet, normalizeSelection, scrollToHighlightCell, chatatABC, isLinkValid, getRangetxt, goToLink, replaceHtml, removeHyperlink, onRangeSelectionModalMoveStart, saveHyperlink, createFilterOptions, onImageMoveStart, onImageResizeStart, showComments, setEditingComment, onCommentBoxMoveStart, onCommentBoxResizeStart, confirmMessage, getRangeByTxt, getDropdownList, setCellValue, setConditionRules, mergeBorder, setDropcownValue, handleCellAreaMouseDown, handleCellAreaMouseMove, handleCellAreaDragOver, handleCellDrop, handleCellAreaDoubleClick, selectAll, showLinkCard, getCellRowColumn, getCellHyperlink, handleOverlayMouseMove, handleOverlayMouseUp, handleKeydownForZoom, handleOverlayTouchStart, handleOverlayTouchMove, handleOverlayTouchEnd, onCellsMoveStart, createDropCellRange, handleDropCellDoubleClick, updateContextWithSheetData, updateContextWithCanvas, initFreeze, Canvas, handleGlobalWheel, setCaretPosition, getDataArr, updateMoreCell, getRegStr, getOptionValue, getSelectRange, applyLocation, updateItem, update, normalizedCellAttr, updateFormat, handleTextSize, handleHorizontalAlign, handleVerticalAlign, handleScreenShot, showImgChooser, insertImage, editComment, deleteComment, showHideComment, showHideAllComments, newComment, handleSum, autoSelectionFormula, handleMerge, handleBorder, handleFreeze, handleSort, createFilter, clearFilter, toolbarItemSelectedFunc, toolbarItemClickHandler, handleTextColor, handleTextBackground, getDataBySelectionNoCopy, getInlineStringNoStyle, rangeHightlightselected, editSheetName, setNextSheet, MAX_ZOOM_RATIO, MIN_ZOOM_RATIO, addSheet, indexToColumnChar, sortSelection, handleCopy, insertRowCol, deleteRowCol, hideSelected, showSelected, api, removeActiveImage, deleteSelectedCellText, jfrefreshgrid, handleLink, deleteSheet, opToPatch, orderbydatafiler, getFilterColumnValues, getFilterColumnColors, saveFilter, cancelActiveImgItem, patchToOp, filterPatch, inverseRowColOptions, ensureSheetIndex, initSheetIndex, handleGlobalKeyDown, handlePasteByLeanklin, groupValuesRefresh } from '@leankylin-sheet/core';
2
- import { useInViewport, useMemoizedFn, useThrottleFn } from 'ahooks';
3
2
  import React, { useContext, useRef, useState, useMemo, useCallback, useEffect, useLayoutEffect, useImperativeHandle } from 'react';
4
3
  import produce, { applyPatches, enablePatches, produceWithPatches } from 'immer';
5
4
  import _ from 'lodash';
5
+ import { useInViewport, useMemoizedFn, useThrottleFn } from 'ahooks';
6
6
  import { createPortal } from 'react-dom';
7
7
 
8
8
  function _iterableToArrayLimit(r, l) {
@@ -11958,7 +11958,6 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
11958
11958
  _useState2 = _slicedToArray(_useState, 2),
11959
11959
  context = _useState2[0],
11960
11960
  setContext = _useState2[1];
11961
- var contextRef = useRef(context);
11962
11961
  var _useState3 = useState(null),
11963
11962
  _useState4 = _slicedToArray(_useState3, 2),
11964
11963
  moreToolbarItems = _useState4[0],
@@ -12063,116 +12062,116 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
12063
12062
  }
12064
12063
  return cellData;
12065
12064
  }
12066
- var setContextWithProduce = useMemoizedFn(function (recipe) {
12065
+ var setContextWithProduce = useCallback(function (recipe) {
12067
12066
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
12068
- var ctx_ = contextRef.current;
12069
- var _produceWithPatches = produceWithPatches(ctx_, concatProducer(recipe, triggerGroupValuesRefresh)),
12070
- _produceWithPatches2 = _slicedToArray(_produceWithPatches, 3),
12071
- result = _produceWithPatches2[0],
12072
- patches = _produceWithPatches2[1],
12073
- inversePatches = _produceWithPatches2[2];
12074
- if (patches.length > 0 && !options.noHistory) {
12075
- if (options.logPatch) {
12076
- console.info("patch", patches);
12077
- }
12078
- var filteredPatches = filterPatch(patches);
12079
- var filteredInversePatches = filterPatch(inversePatches);
12080
- if (filteredInversePatches.length > 0) {
12081
- options.id = ctx_.currentSheetId;
12082
- if (options.deleteSheetOp) {
12083
- var target = ctx_.luckysheetfile.filter(function (sheet) {
12084
- var _options$deleteSheetO;
12085
- return sheet.id === ((_options$deleteSheetO = options.deleteSheetOp) === null || _options$deleteSheetO === void 0 ? void 0 : _options$deleteSheetO.id);
12086
- });
12087
- if (target) {
12088
- var index = getSheetIndex(ctx_, options.deleteSheetOp.id);
12089
- options.deletedSheet = {
12090
- id: options.deleteSheetOp.id,
12091
- index: index,
12092
- value: _.cloneDeep(ctx_.luckysheetfile[index])
12093
- };
12094
- options.deletedSheet.value.celldata = dataToCelldata(options.deletedSheet.value.data);
12095
- delete options.deletedSheet.value.data;
12096
- options.deletedSheet.value.status = 0;
12097
- filteredInversePatches = [{
12098
- op: "add",
12099
- path: ["luckysheetfile", 0],
12100
- value: options.deletedSheet.value
12101
- }];
12067
+ setContext(function (ctx_) {
12068
+ var _produceWithPatches = produceWithPatches(ctx_, concatProducer(recipe, triggerGroupValuesRefresh)),
12069
+ _produceWithPatches2 = _slicedToArray(_produceWithPatches, 3),
12070
+ result = _produceWithPatches2[0],
12071
+ patches = _produceWithPatches2[1],
12072
+ inversePatches = _produceWithPatches2[2];
12073
+ if (patches.length > 0 && !options.noHistory) {
12074
+ if (options.logPatch) {
12075
+ console.info("patch", patches);
12076
+ }
12077
+ var filteredPatches = filterPatch(patches);
12078
+ var filteredInversePatches = filterPatch(inversePatches);
12079
+ if (filteredInversePatches.length > 0) {
12080
+ options.id = ctx_.currentSheetId;
12081
+ if (options.deleteSheetOp) {
12082
+ var target = ctx_.luckysheetfile.filter(function (sheet) {
12083
+ var _options$deleteSheetO;
12084
+ return sheet.id === ((_options$deleteSheetO = options.deleteSheetOp) === null || _options$deleteSheetO === void 0 ? void 0 : _options$deleteSheetO.id);
12085
+ });
12086
+ if (target) {
12087
+ var index = getSheetIndex(ctx_, options.deleteSheetOp.id);
12088
+ options.deletedSheet = {
12089
+ id: options.deleteSheetOp.id,
12090
+ index: index,
12091
+ value: _.cloneDeep(ctx_.luckysheetfile[index])
12092
+ };
12093
+ options.deletedSheet.value.celldata = dataToCelldata(options.deletedSheet.value.data);
12094
+ delete options.deletedSheet.value.data;
12095
+ options.deletedSheet.value.status = 0;
12096
+ filteredInversePatches = [{
12097
+ op: "add",
12098
+ path: ["luckysheetfile", 0],
12099
+ value: options.deletedSheet.value
12100
+ }];
12101
+ }
12102
+ } else if (options.addSheetOp) {
12103
+ options.addSheet = {};
12104
+ options.addSheet.id = result.luckysheetfile[result.luckysheetfile.length - 1].id;
12102
12105
  }
12103
- } else if (options.addSheetOp) {
12104
- options.addSheet = {};
12105
- options.addSheet.id = result.luckysheetfile[result.luckysheetfile.length - 1].id;
12106
+ globalCache.current.undoList.push({
12107
+ patches: filteredPatches,
12108
+ inversePatches: filteredInversePatches,
12109
+ options: options
12110
+ });
12111
+ globalCache.current.redoList = [];
12112
+ emitOp(result, filteredPatches, options);
12113
+ }
12114
+ } else {
12115
+ var _patches$, _patches$$value, _ctx_$luckysheetfile;
12116
+ if ((patches === null || patches === void 0 ? void 0 : (_patches$ = patches[0]) === null || _patches$ === void 0 ? void 0 : (_patches$$value = _patches$.value) === null || _patches$$value === void 0 ? void 0 : _patches$$value.length) < (ctx_ === null || ctx_ === void 0 ? void 0 : (_ctx_$luckysheetfile = ctx_.luckysheetfile) === null || _ctx_$luckysheetfile === void 0 ? void 0 : _ctx_$luckysheetfile.length)) {
12117
+ reduceUndoList(result, ctx_);
12106
12118
  }
12107
- globalCache.current.undoList.push({
12108
- patches: filteredPatches,
12109
- inversePatches: filteredInversePatches,
12110
- options: options
12111
- });
12112
- globalCache.current.redoList = [];
12113
- emitOp(result, filteredPatches, options);
12114
- }
12115
- } else {
12116
- var _patches$, _patches$$value, _ctx_$luckysheetfile;
12117
- if ((patches === null || patches === void 0 ? void 0 : (_patches$ = patches[0]) === null || _patches$ === void 0 ? void 0 : (_patches$$value = _patches$.value) === null || _patches$$value === void 0 ? void 0 : _patches$$value.length) < (ctx_ === null || ctx_ === void 0 ? void 0 : (_ctx_$luckysheetfile = ctx_.luckysheetfile) === null || _ctx_$luckysheetfile === void 0 ? void 0 : _ctx_$luckysheetfile.length)) {
12118
- reduceUndoList(result, ctx_);
12119
12119
  }
12120
- }
12121
- contextRef.current = result;
12122
- setContext(result);
12123
- });
12120
+ return result;
12121
+ });
12122
+ }, [emitOp]);
12124
12123
  var handleUndo = useCallback(function () {
12125
12124
  var history = globalCache.current.undoList.pop();
12126
12125
  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
12126
+ setContext(function (ctx_) {
12127
+ var _history$options, _history$options3;
12128
+ if ((_history$options = history.options) === null || _history$options === void 0 ? void 0 : _history$options.deleteSheetOp) {
12129
+ var _history$options$dele, _history$options$dele2;
12130
+ history.inversePatches[0].path[1] = ctx_.luckysheetfile.length;
12131
+ 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;
12132
+ var sheetsRight = ctx_.luckysheetfile.filter(function (sheet) {
12133
+ var _history$options2, _history$options2$del;
12134
+ 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
12135
  });
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);
12136
+ _.forEach(sheetsRight, function (sheet) {
12137
+ history.inversePatches.push({
12138
+ op: "replace",
12139
+ path: ["luckysheetfile", getSheetIndex(ctx_, sheet.id), "order"],
12140
+ value: (sheet === null || sheet === void 0 ? void 0 : sheet.order) + 1
12141
+ });
12142
+ });
12143
+ }
12144
+ var newContext = applyPatches(ctx_, history.inversePatches);
12145
+ globalCache.current.redoList.push(history);
12146
+ var inversedOptions = inverseRowColOptions(history.options);
12147
+ if (inversedOptions === null || inversedOptions === void 0 ? void 0 : inversedOptions.insertRowColOp) {
12148
+ inversedOptions.restoreDeletedCells = true;
12149
+ }
12150
+ if ((_history$options3 = history.options) === null || _history$options3 === void 0 ? void 0 : _history$options3.addSheetOp) {
12151
+ var _inversedOptions$addS;
12152
+ var index = getSheetIndex(ctx_, history.options.addSheet.id);
12153
+ inversedOptions.addSheet = {
12154
+ id: history.options.addSheet.id,
12155
+ index: index,
12156
+ value: _.cloneDeep(ctx_.luckysheetfile[index])
12157
+ };
12158
+ inversedOptions.addSheet.value.celldata = dataToCelldata((_inversedOptions$addS = inversedOptions.addSheet.value) === null || _inversedOptions$addS === void 0 ? void 0 : _inversedOptions$addS.data);
12159
+ delete inversedOptions.addSheet.value.data;
12160
+ }
12161
+ emitOp(newContext, history.inversePatches, inversedOptions, true);
12162
+ return newContext;
12163
+ });
12165
12164
  }
12166
12165
  }, [emitOp]);
12167
12166
  var handleRedo = useCallback(function () {
12168
12167
  var history = globalCache.current.redoList.pop();
12169
12168
  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);
12169
+ setContext(function (ctx_) {
12170
+ var newContext = applyPatches(ctx_, history.patches);
12171
+ globalCache.current.undoList.push(history);
12172
+ emitOp(newContext, history.patches, history.options);
12173
+ return newContext;
12174
+ });
12176
12175
  }
12177
12176
  }, [emitOp]);
12178
12177
  useEffect(function () {
package/dist/index.js CHANGED
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var core = require('@leankylin-sheet/core');
6
- var ahooks = require('ahooks');
7
6
  var React = require('react');
8
7
  var produce = require('immer');
9
8
  var _ = require('lodash');
9
+ var ahooks = require('ahooks');
10
10
  var reactDom = require('react-dom');
11
11
 
12
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -11968,7 +11968,6 @@ var Workbook = /*#__PURE__*/React__default['default'].forwardRef(function (_ref,
11968
11968
  _useState2 = _slicedToArray(_useState, 2),
11969
11969
  context = _useState2[0],
11970
11970
  setContext = _useState2[1];
11971
- var contextRef = React.useRef(context);
11972
11971
  var _useState3 = React.useState(null),
11973
11972
  _useState4 = _slicedToArray(_useState3, 2),
11974
11973
  moreToolbarItems = _useState4[0],
@@ -12073,116 +12072,116 @@ var Workbook = /*#__PURE__*/React__default['default'].forwardRef(function (_ref,
12073
12072
  }
12074
12073
  return cellData;
12075
12074
  }
12076
- var setContextWithProduce = ahooks.useMemoizedFn(function (recipe) {
12075
+ var setContextWithProduce = React.useCallback(function (recipe) {
12077
12076
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
12078
- var ctx_ = contextRef.current;
12079
- var _produceWithPatches = produce.produceWithPatches(ctx_, concatProducer(recipe, triggerGroupValuesRefresh)),
12080
- _produceWithPatches2 = _slicedToArray(_produceWithPatches, 3),
12081
- result = _produceWithPatches2[0],
12082
- patches = _produceWithPatches2[1],
12083
- inversePatches = _produceWithPatches2[2];
12084
- if (patches.length > 0 && !options.noHistory) {
12085
- if (options.logPatch) {
12086
- console.info("patch", patches);
12087
- }
12088
- var filteredPatches = core.filterPatch(patches);
12089
- var filteredInversePatches = core.filterPatch(inversePatches);
12090
- if (filteredInversePatches.length > 0) {
12091
- options.id = ctx_.currentSheetId;
12092
- if (options.deleteSheetOp) {
12093
- var target = ctx_.luckysheetfile.filter(function (sheet) {
12094
- var _options$deleteSheetO;
12095
- return sheet.id === ((_options$deleteSheetO = options.deleteSheetOp) === null || _options$deleteSheetO === void 0 ? void 0 : _options$deleteSheetO.id);
12096
- });
12097
- if (target) {
12098
- var index = core.getSheetIndex(ctx_, options.deleteSheetOp.id);
12099
- options.deletedSheet = {
12100
- id: options.deleteSheetOp.id,
12101
- index: index,
12102
- value: ___default['default'].cloneDeep(ctx_.luckysheetfile[index])
12103
- };
12104
- options.deletedSheet.value.celldata = dataToCelldata(options.deletedSheet.value.data);
12105
- delete options.deletedSheet.value.data;
12106
- options.deletedSheet.value.status = 0;
12107
- filteredInversePatches = [{
12108
- op: "add",
12109
- path: ["luckysheetfile", 0],
12110
- value: options.deletedSheet.value
12111
- }];
12077
+ setContext(function (ctx_) {
12078
+ var _produceWithPatches = produce.produceWithPatches(ctx_, concatProducer(recipe, triggerGroupValuesRefresh)),
12079
+ _produceWithPatches2 = _slicedToArray(_produceWithPatches, 3),
12080
+ result = _produceWithPatches2[0],
12081
+ patches = _produceWithPatches2[1],
12082
+ inversePatches = _produceWithPatches2[2];
12083
+ if (patches.length > 0 && !options.noHistory) {
12084
+ if (options.logPatch) {
12085
+ console.info("patch", patches);
12086
+ }
12087
+ var filteredPatches = core.filterPatch(patches);
12088
+ var filteredInversePatches = core.filterPatch(inversePatches);
12089
+ if (filteredInversePatches.length > 0) {
12090
+ options.id = ctx_.currentSheetId;
12091
+ if (options.deleteSheetOp) {
12092
+ var target = ctx_.luckysheetfile.filter(function (sheet) {
12093
+ var _options$deleteSheetO;
12094
+ return sheet.id === ((_options$deleteSheetO = options.deleteSheetOp) === null || _options$deleteSheetO === void 0 ? void 0 : _options$deleteSheetO.id);
12095
+ });
12096
+ if (target) {
12097
+ var index = core.getSheetIndex(ctx_, options.deleteSheetOp.id);
12098
+ options.deletedSheet = {
12099
+ id: options.deleteSheetOp.id,
12100
+ index: index,
12101
+ value: ___default['default'].cloneDeep(ctx_.luckysheetfile[index])
12102
+ };
12103
+ options.deletedSheet.value.celldata = dataToCelldata(options.deletedSheet.value.data);
12104
+ delete options.deletedSheet.value.data;
12105
+ options.deletedSheet.value.status = 0;
12106
+ filteredInversePatches = [{
12107
+ op: "add",
12108
+ path: ["luckysheetfile", 0],
12109
+ value: options.deletedSheet.value
12110
+ }];
12111
+ }
12112
+ } else if (options.addSheetOp) {
12113
+ options.addSheet = {};
12114
+ options.addSheet.id = result.luckysheetfile[result.luckysheetfile.length - 1].id;
12112
12115
  }
12113
- } else if (options.addSheetOp) {
12114
- options.addSheet = {};
12115
- options.addSheet.id = result.luckysheetfile[result.luckysheetfile.length - 1].id;
12116
+ globalCache.current.undoList.push({
12117
+ patches: filteredPatches,
12118
+ inversePatches: filteredInversePatches,
12119
+ options: options
12120
+ });
12121
+ globalCache.current.redoList = [];
12122
+ emitOp(result, filteredPatches, options);
12123
+ }
12124
+ } else {
12125
+ var _patches$, _patches$$value, _ctx_$luckysheetfile;
12126
+ if ((patches === null || patches === void 0 ? void 0 : (_patches$ = patches[0]) === null || _patches$ === void 0 ? void 0 : (_patches$$value = _patches$.value) === null || _patches$$value === void 0 ? void 0 : _patches$$value.length) < (ctx_ === null || ctx_ === void 0 ? void 0 : (_ctx_$luckysheetfile = ctx_.luckysheetfile) === null || _ctx_$luckysheetfile === void 0 ? void 0 : _ctx_$luckysheetfile.length)) {
12127
+ reduceUndoList(result, ctx_);
12116
12128
  }
12117
- globalCache.current.undoList.push({
12118
- patches: filteredPatches,
12119
- inversePatches: filteredInversePatches,
12120
- options: options
12121
- });
12122
- globalCache.current.redoList = [];
12123
- emitOp(result, filteredPatches, options);
12124
- }
12125
- } else {
12126
- var _patches$, _patches$$value, _ctx_$luckysheetfile;
12127
- if ((patches === null || patches === void 0 ? void 0 : (_patches$ = patches[0]) === null || _patches$ === void 0 ? void 0 : (_patches$$value = _patches$.value) === null || _patches$$value === void 0 ? void 0 : _patches$$value.length) < (ctx_ === null || ctx_ === void 0 ? void 0 : (_ctx_$luckysheetfile = ctx_.luckysheetfile) === null || _ctx_$luckysheetfile === void 0 ? void 0 : _ctx_$luckysheetfile.length)) {
12128
- reduceUndoList(result, ctx_);
12129
12129
  }
12130
- }
12131
- contextRef.current = result;
12132
- setContext(result);
12133
- });
12130
+ return result;
12131
+ });
12132
+ }, [emitOp]);
12134
12133
  var handleUndo = React.useCallback(function () {
12135
12134
  var history = globalCache.current.undoList.pop();
12136
12135
  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
12136
+ setContext(function (ctx_) {
12137
+ var _history$options, _history$options3;
12138
+ if ((_history$options = history.options) === null || _history$options === void 0 ? void 0 : _history$options.deleteSheetOp) {
12139
+ var _history$options$dele, _history$options$dele2;
12140
+ history.inversePatches[0].path[1] = ctx_.luckysheetfile.length;
12141
+ 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;
12142
+ var sheetsRight = ctx_.luckysheetfile.filter(function (sheet) {
12143
+ var _history$options2, _history$options2$del;
12144
+ 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
12145
  });
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);
12146
+ ___default['default'].forEach(sheetsRight, function (sheet) {
12147
+ history.inversePatches.push({
12148
+ op: "replace",
12149
+ path: ["luckysheetfile", core.getSheetIndex(ctx_, sheet.id), "order"],
12150
+ value: (sheet === null || sheet === void 0 ? void 0 : sheet.order) + 1
12151
+ });
12152
+ });
12153
+ }
12154
+ var newContext = produce.applyPatches(ctx_, history.inversePatches);
12155
+ globalCache.current.redoList.push(history);
12156
+ var inversedOptions = core.inverseRowColOptions(history.options);
12157
+ if (inversedOptions === null || inversedOptions === void 0 ? void 0 : inversedOptions.insertRowColOp) {
12158
+ inversedOptions.restoreDeletedCells = true;
12159
+ }
12160
+ if ((_history$options3 = history.options) === null || _history$options3 === void 0 ? void 0 : _history$options3.addSheetOp) {
12161
+ var _inversedOptions$addS;
12162
+ var index = core.getSheetIndex(ctx_, history.options.addSheet.id);
12163
+ inversedOptions.addSheet = {
12164
+ id: history.options.addSheet.id,
12165
+ index: index,
12166
+ value: ___default['default'].cloneDeep(ctx_.luckysheetfile[index])
12167
+ };
12168
+ inversedOptions.addSheet.value.celldata = dataToCelldata((_inversedOptions$addS = inversedOptions.addSheet.value) === null || _inversedOptions$addS === void 0 ? void 0 : _inversedOptions$addS.data);
12169
+ delete inversedOptions.addSheet.value.data;
12170
+ }
12171
+ emitOp(newContext, history.inversePatches, inversedOptions, true);
12172
+ return newContext;
12173
+ });
12175
12174
  }
12176
12175
  }, [emitOp]);
12177
12176
  var handleRedo = React.useCallback(function () {
12178
12177
  var history = globalCache.current.redoList.pop();
12179
12178
  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);
12179
+ setContext(function (ctx_) {
12180
+ var newContext = produce.applyPatches(ctx_, history.patches);
12181
+ globalCache.current.undoList.push(history);
12182
+ emitOp(newContext, history.patches, history.options);
12183
+ return newContext;
12184
+ });
12186
12185
  }
12187
12186
  }, [emitOp]);
12188
12187
  React.useEffect(function () {