@univerjs/sheets 1.0.0-alpha.7 → 1.0.0-alpha.8

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/lib/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { AUTO_HEIGHT_FOR_MERGED_CELLS, BORDER_KEYS, BORDER_STYLE_KEYS, BooleanNumber, BorderStyleTypes, BorderType, BuildTextUtils, COLOR_STYLE_KEYS, CellModeEnum, CellValueType, CommandType, CustomCommandExecutionError, DependentOn, Dimension, Direction, Disposable, DisposableCollection, DocumentDataModel, ErrorService, FontItalic, FontWeight, HorizontalAlign, IAuthzIoService, ICommandService, IConfigService, IConfirmService, IContextService, ILogService, IPermissionService, IResourceManagerService, IS_ROW_STYLE_PRECEDE_COLUMN_STYLE, IUndoRedoService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, InterceptorManager, LRUMap, LocaleService, MAX_COLUMN_COUNT, MAX_ROW_COUNT, ObjectMatrix, Optional, PADDING_KEYS, PermissionStatus, Plugin, RANGE_TYPE, RTree, Range, Rectangle, RxDisposable, STYLE_KEYS, TEXT_DECORATION_KEYS, TEXT_ROTATION_KEYS, TextX, Tools, UniverInstanceType, UserManagerService, cellToRange, cloneWorksheetData, composeInterceptors, concatMatrixArray, createIdentifier, createInterceptorKey, createRowColIter, generateRandomId, getArrayLength, isBooleanString, isDefaultFormat, isFormulaId, isFormulaString, isICellData, isRealNum, isSafeNumeric, isTextFormat, mapObjectMatrix, merge, mergeIntervals, mergeOverrideWithDependencies, mergeWorksheetSnapshotWithDefault, moveMatrixArray, normalizeTextRuns, numfmt, queryObjectMatrix, regexp, registerDependencies, remove, selectionToArray, sequenceExecute, sliceMatrixArray, spliceArray, throttle, toDisposable, touchDependencies, willLoseNumericPrecision } from "@univerjs/core";
1
+ import { AUTO_HEIGHT_FOR_MERGED_CELLS, BORDER_KEYS, BORDER_STYLE_KEYS, BooleanNumber, BorderStyleTypes, BorderType, BuildTextUtils, COLOR_STYLE_KEYS, CellModeEnum, CellValueType, CommandType, CustomCommandExecutionError, DependentOn, Dimension, Direction, Disposable, DisposableCollection, DocumentDataModel, ErrorService, FontItalic, FontWeight, HorizontalAlign, IAuthzIoService, ICommandService, IConfigService, IConfirmService, IContextService, ILogService, IPermissionService, IResourceManagerService, IS_ROW_STYLE_PRECEDE_COLUMN_STYLE, IUndoRedoService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, InterceptorManager, LRUMap, LocaleService, MAX_COLUMN_COUNT, MAX_ROW_COUNT, ObjectMatrix, Optional, PADDING_KEYS, PermissionStatus, Plugin, RANGE_TYPE, RTree, Range, Rectangle, RxDisposable, STYLE_KEYS, TEXT_DECORATION_KEYS, TEXT_ROTATION_KEYS, TextX, Tools, UniverInstanceType, UserManagerService, cellToRange, cloneWorksheetData, composeInterceptors, concatMatrixArray, createIdentifier, createInterceptorKey, createRowColIter, generateRandomId, getArrayLength, getIntersectRange, isBooleanString, isDefaultFormat, isFormulaId, isFormulaString, isICellData, isRealNum, isSafeNumeric, isTextFormat, mapObjectMatrix, merge, mergeIntervals, mergeOverrideWithDependencies, mergeWorksheetSnapshotWithDefault, moveMatrixArray, normalizeTextRuns, numfmt, queryObjectMatrix, regexp, registerDependencies, remove, selectionToArray, sequenceExecute, sliceMatrixArray, spliceArray, throttle, toDisposable, touchDependencies, willLoseNumericPrecision } from "@univerjs/core";
2
2
  import { BehaviorSubject, Subject, distinctUntilChanged, filter, first, map, merge as merge$1, of, share, shareReplay, skip, switchMap, takeUntil } from "rxjs";
3
3
  import { IDefinedNamesService, LexerTreeBuilder, RemoveDefinedNameMutation, SetDefinedNameMutation, SetDefinedNameMutationFactory, SetFormulaCalculationResultMutation, UniverFormulaEnginePlugin, deserializeRangeWithSheet, deserializeRangeWithSheetWithCache, handleNumfmtInCell, isReferenceStringWithEffectiveColumn, operatorToken, sequenceNodeType, stripErrorMargin } from "@univerjs/engine-formula";
4
4
  import { SpreadsheetSkeleton, cjk, precisionTo } from "@univerjs/engine-render";
@@ -158,7 +158,7 @@ const RangeThemeInterceptorId = "sheet.interceptor.range-theme-id";
158
158
  const IgnoreRangeThemeInterceptorKey = "sheet.interceptor.ignore-range-theme";
159
159
 
160
160
  //#endregion
161
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
161
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
162
162
  function _typeof(o) {
163
163
  "@babel/helpers - typeof";
164
164
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -169,7 +169,7 @@ function _typeof(o) {
169
169
  }
170
170
 
171
171
  //#endregion
172
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
172
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
173
173
  function toPrimitive(t, r) {
174
174
  if ("object" != _typeof(t) || !t) return t;
175
175
  var e = t[Symbol.toPrimitive];
@@ -182,14 +182,14 @@ function toPrimitive(t, r) {
182
182
  }
183
183
 
184
184
  //#endregion
185
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
185
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
186
186
  function toPropertyKey(t) {
187
187
  var i = toPrimitive(t, "string");
188
188
  return "symbol" == _typeof(i) ? i : i + "";
189
189
  }
190
190
 
191
191
  //#endregion
192
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
192
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
193
193
  function _defineProperty(e, r, t) {
194
194
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
195
195
  value: t,
@@ -200,7 +200,7 @@ function _defineProperty(e, r, t) {
200
200
  }
201
201
 
202
202
  //#endregion
203
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
203
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
204
204
  function __decorateParam(paramIndex, decorator) {
205
205
  return function(target, key) {
206
206
  decorator(target, key, paramIndex);
@@ -208,7 +208,7 @@ function __decorateParam(paramIndex, decorator) {
208
208
  }
209
209
 
210
210
  //#endregion
211
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
211
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
212
212
  function __decorate(decorators, target, key, desc) {
213
213
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
214
214
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1680,7 +1680,7 @@ const MoveRowsMutation = {
1680
1680
  type: CommandType.MUTATION,
1681
1681
  handler: (accessor, params) => {
1682
1682
  const { unitId, subUnitId, sourceRange, targetRange } = params;
1683
- const univerSheet = accessor.get(IUniverInstanceService).getUniverSheetInstance(unitId);
1683
+ const univerSheet = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
1684
1684
  if (!univerSheet) throw new Error("[MoveRowMutation] univerSheet is null!");
1685
1685
  const worksheet = univerSheet.getSheetBySheetId(subUnitId);
1686
1686
  if (!worksheet) throw new Error("[MoveRowMutation] worksheet is null!");
@@ -1722,7 +1722,7 @@ const MoveColsMutation = {
1722
1722
  type: CommandType.MUTATION,
1723
1723
  handler: (accessor, params) => {
1724
1724
  const { unitId, subUnitId, sourceRange, targetRange } = params;
1725
- const univerSheet = accessor.get(IUniverInstanceService).getUniverSheetInstance(unitId);
1725
+ const univerSheet = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
1726
1726
  if (!univerSheet) throw new Error("[MoveColumnMutation] univerSheet is null!");
1727
1727
  const worksheet = univerSheet.getSheetBySheetId(subUnitId);
1728
1728
  if (!worksheet) throw new Error("[MoveColumnMutation] worksheet is null!");
@@ -1753,7 +1753,7 @@ const RemoveRowMutation = {
1753
1753
  id: "sheet.mutation.remove-rows",
1754
1754
  type: CommandType.MUTATION,
1755
1755
  handler: (accessor, params) => {
1756
- const universheet = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);
1756
+ const universheet = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET);
1757
1757
  if (universheet == null) throw new Error("universheet is null error!");
1758
1758
  const worksheet = universheet.getSheetBySheetId(params.subUnitId);
1759
1759
  if (!worksheet) return false;
@@ -1769,7 +1769,7 @@ const RemoveRowMutation = {
1769
1769
  }
1770
1770
  };
1771
1771
  const RemoveColMutationFactory = (accessor, params) => {
1772
- const universheet = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);
1772
+ const universheet = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET);
1773
1773
  if (universheet == null) throw new Error("universheet is null error!");
1774
1774
  const worksheet = universheet.getSheetBySheetId(params.subUnitId);
1775
1775
  if (worksheet == null) throw new Error("worksheet is null error!");
@@ -1788,7 +1788,7 @@ const RemoveColMutation = {
1788
1788
  id: "sheet.mutation.remove-col",
1789
1789
  type: CommandType.MUTATION,
1790
1790
  handler: (accessor, params) => {
1791
- const universheet = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);
1791
+ const universheet = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET);
1792
1792
  if (universheet == null) throw new Error("universheet is null error!");
1793
1793
  const worksheet = universheet.getSheetBySheetId(params.subUnitId);
1794
1794
  if (!worksheet) return false;
@@ -1956,7 +1956,7 @@ const SetColDataMutation = {
1956
1956
  //#endregion
1957
1957
  //#region src/commands/mutations/set-col-visible.mutation.ts
1958
1958
  const SetColHiddenUndoMutationFactory = (accessor, params) => {
1959
- if (accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId) == null) throw new Error("universheet is null error!");
1959
+ if (accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET) == null) throw new Error("universheet is null error!");
1960
1960
  return {
1961
1961
  unitId: params.unitId,
1962
1962
  subUnitId: params.subUnitId,
@@ -1967,7 +1967,7 @@ const SetColHiddenMutation = {
1967
1967
  id: "sheet.mutation.set-col-hidden",
1968
1968
  type: CommandType.MUTATION,
1969
1969
  handler: (accessor, params) => {
1970
- const universheet = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);
1970
+ const universheet = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET);
1971
1971
  if (!universheet) return false;
1972
1972
  const manager = universheet.getSheetBySheetId(params.subUnitId).getColumnManager();
1973
1973
  for (let i = 0; i < params.ranges.length; i++) {
@@ -1981,7 +1981,7 @@ const SetColHiddenMutation = {
1981
1981
  }
1982
1982
  };
1983
1983
  const SetColVisibleUndoMutationFactory = (accessor, params) => {
1984
- if (accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId) == null) throw new Error("universheet is null error!");
1984
+ if (accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET) == null) throw new Error("universheet is null error!");
1985
1985
  return {
1986
1986
  unitId: params.unitId,
1987
1987
  subUnitId: params.subUnitId,
@@ -1992,7 +1992,7 @@ const SetColVisibleMutation = {
1992
1992
  id: "sheet.mutation.set-col-visible",
1993
1993
  type: CommandType.MUTATION,
1994
1994
  handler: (accessor, params) => {
1995
- const universheet = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);
1995
+ const universheet = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET);
1996
1996
  if (!universheet) return false;
1997
1997
  const manager = universheet.getSheetBySheetId(params.subUnitId).getColumnManager();
1998
1998
  for (let i = 0; i < params.ranges.length; i++) {
@@ -2342,7 +2342,7 @@ function setNull(value) {
2342
2342
  */
2343
2343
  const SetRangeValuesUndoMutationFactory = (accessor, params) => {
2344
2344
  const { unitId, subUnitId, cellValue, isOverrideStyle } = params;
2345
- const workbook = accessor.get(IUniverInstanceService).getUniverSheetInstance(unitId);
2345
+ const workbook = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
2346
2346
  if (workbook == null) throw new Error("workbook is null error!");
2347
2347
  const worksheet = workbook.getSheetBySheetId(subUnitId);
2348
2348
  if (worksheet == null) throw new Error("worksheet is null error!");
@@ -2472,7 +2472,7 @@ const SetRowDataMutation = {
2472
2472
  //#endregion
2473
2473
  //#region src/commands/mutations/set-row-visible.mutation.ts
2474
2474
  const SetRowVisibleUndoMutationFactory = (accessor, params) => {
2475
- if (accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId) == null) throw new Error("universheet is null error!");
2475
+ if (accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET) == null) throw new Error("universheet is null error!");
2476
2476
  return {
2477
2477
  unitId: params.unitId,
2478
2478
  subUnitId: params.subUnitId,
@@ -2483,7 +2483,7 @@ const SetRowVisibleMutation = {
2483
2483
  id: "sheet.mutation.set-row-visible",
2484
2484
  type: CommandType.MUTATION,
2485
2485
  handler: (accessor, params) => {
2486
- const universheet = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);
2486
+ const universheet = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET);
2487
2487
  if (universheet == null) throw new Error("universheet is null error!");
2488
2488
  const manager = universheet.getSheetBySheetId(params.subUnitId).getRowManager();
2489
2489
  for (let i = 0; i < params.ranges.length; i++) {
@@ -2497,7 +2497,7 @@ const SetRowVisibleMutation = {
2497
2497
  }
2498
2498
  };
2499
2499
  const SetRowHiddenUndoMutationFactory = (accessor, params) => {
2500
- if (accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId) == null) throw new Error("universheet is null error!");
2500
+ if (accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET) == null) throw new Error("universheet is null error!");
2501
2501
  return {
2502
2502
  unitId: params.unitId,
2503
2503
  subUnitId: params.subUnitId,
@@ -2508,7 +2508,7 @@ const SetRowHiddenMutation = {
2508
2508
  id: "sheet.mutation.set-row-hidden",
2509
2509
  type: CommandType.MUTATION,
2510
2510
  handler: (accessor, params) => {
2511
- const universheet = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);
2511
+ const universheet = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET);
2512
2512
  if (universheet == null) throw new Error("universheet is null error!");
2513
2513
  const manager = universheet.getSheetBySheetId(params.subUnitId).getRowManager();
2514
2514
  for (let i = 0; i < params.ranges.length; i++) {
@@ -3552,7 +3552,8 @@ const findAllRectangle = (topMatrix) => {
3552
3552
  * @returns {IRange[]}
3553
3553
  */
3554
3554
  const rangeMerge = (ranges) => {
3555
- return findAllRectangle(createTopMatrixFromRanges(ranges));
3555
+ const topMatrix = createTopMatrixFromRanges(ranges);
3556
+ return findAllRectangle(topMatrix);
3556
3557
  };
3557
3558
  var RangeMergeUtil = class {
3558
3559
  constructor() {
@@ -3575,7 +3576,8 @@ var RangeMergeUtil = class {
3575
3576
  return this;
3576
3577
  }
3577
3578
  merge() {
3578
- return findAllRectangle(createTopMatrixFromMatrix(this._matrix));
3579
+ const topMatrix = createTopMatrixFromMatrix(this._matrix);
3580
+ return findAllRectangle(topMatrix);
3579
3581
  }
3580
3582
  };
3581
3583
 
@@ -4245,14 +4247,6 @@ var WorkbookSelectionModel = class extends Disposable {
4245
4247
  getCurrentSelections() {
4246
4248
  return this._getCurrentSelections();
4247
4249
  }
4248
- /**
4249
- * @deprecated use `getSelectionsOfWorksheet` instead.
4250
- * @param sheetId
4251
- * @returns
4252
- */
4253
- getSelectionOfWorksheet(sheetId) {
4254
- return this.getSelectionsOfWorksheet(sheetId);
4255
- }
4256
4250
  getSelectionsOfWorksheet(sheetId) {
4257
4251
  if (!this._worksheetSelections.has(sheetId)) this._worksheetSelections.set(sheetId, []);
4258
4252
  return this._worksheetSelections.get(sheetId);
@@ -4429,19 +4423,6 @@ let SheetsSelectionsService = class SheetsSelectionsService extends RxDisposable
4429
4423
  clearCurrentSelections() {
4430
4424
  this._getCurrentSelections().splice(0);
4431
4425
  }
4432
- /**
4433
- * Determine whether multiple current selections overlap
4434
- *
4435
- * @deprecated this should be extracted to an pure function
4436
- */
4437
- isOverlapping() {
4438
- const selectionDataList = this.getCurrentSelections();
4439
- if (selectionDataList == null) return false;
4440
- return selectionDataList.some(({ range }, index) => selectionDataList.some(({ range: range2 }, index2) => {
4441
- if (index === index2) return false;
4442
- return range.startRow <= range2.endRow && range.endRow >= range2.startRow && range.startColumn <= range2.endColumn && range.endColumn >= range2.startColumn;
4443
- }));
4444
- }
4445
4426
  _getCurrentSelections() {
4446
4427
  const current = this._currentSelectionPos;
4447
4428
  if (!current) return [];
@@ -5056,6 +5037,9 @@ RefSelectionsService = __decorate([__decorateParam(0, IUniverInstanceService)],
5056
5037
 
5057
5038
  //#endregion
5058
5039
  //#region src/commands/utils/selection-command-util.ts
5040
+ function hasOverlappingRanges(ranges) {
5041
+ return ranges.some((range, index) => ranges.slice(index + 1).some((other) => Rectangle.simpleRangesIntersect(range, other)));
5042
+ }
5059
5043
  function getSelectionsService(accessor, fromCurrentSelection) {
5060
5044
  const isInRefSelectionMode = accessor.get(IContextService).getContextValue(REF_SELECTIONS_ENABLED);
5061
5045
  return accessor.get(isInRefSelectionMode && !fromCurrentSelection ? IRefSelectionsService : SheetsSelectionsService);
@@ -5138,7 +5122,7 @@ function _resolveMoveRangeContext(accessor, params) {
5138
5122
  const toSubUnitId = (_ref2 = (_params$toSubUnitId = params.toSubUnitId) !== null && _params$toSubUnitId !== void 0 ? _params$toSubUnitId : params.fromSubUnitId) !== null && _ref2 !== void 0 ? _ref2 : target === null || target === void 0 ? void 0 : target.subUnitId;
5139
5123
  if (!unitId || !fromSubUnitId || !toSubUnitId) return null;
5140
5124
  if (params.fromUnitId && params.toUnitId && params.fromUnitId !== params.toUnitId) return null;
5141
- const workbook = univerInstanceService.getUniverSheetInstance(unitId);
5125
+ const workbook = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
5142
5126
  const fromWorksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(fromSubUnitId);
5143
5127
  const toWorksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(toSubUnitId);
5144
5128
  if (!fromWorksheet || !toWorksheet) return null;
@@ -5413,7 +5397,7 @@ function getInsertRangeMutations(accessor, params) {
5413
5397
  const { unitId, subUnitId, range, shiftDimension, cellValue = {} } = params;
5414
5398
  const instanceService = accessor.get(IUniverInstanceService);
5415
5399
  const sheetInterceptorService = accessor.get(SheetInterceptorService);
5416
- const workbook = instanceService.getUniverSheetInstance(unitId);
5400
+ const workbook = instanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
5417
5401
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
5418
5402
  if (worksheet) {
5419
5403
  const cellMatrix = worksheet.getCellMatrix();
@@ -5510,7 +5494,7 @@ function getRemoveRangeMutations(accessor, params) {
5510
5494
  const { unitId, subUnitId, range, shiftDimension } = params;
5511
5495
  const instanceService = accessor.get(IUniverInstanceService);
5512
5496
  const sheetInterceptorService = accessor.get(SheetInterceptorService);
5513
- const workbook = instanceService.getUniverSheetInstance(unitId);
5497
+ const workbook = instanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
5514
5498
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
5515
5499
  if (worksheet) {
5516
5500
  const cellMatrix = worksheet.getCellMatrix();
@@ -5773,7 +5757,7 @@ const InsertRangeMoveDownCommand = {
5773
5757
  const sheetInterceptorService = accessor.get(SheetInterceptorService);
5774
5758
  const errorService = accessor.get(ErrorService);
5775
5759
  const localeService = accessor.get(LocaleService);
5776
- if (selectionManagerService.isOverlapping()) {
5760
+ if (hasOverlappingRanges(selectionManagerService.getCurrentSelections().map(({ range }) => range))) {
5777
5761
  errorService.emit(localeService.t("sheets.info.overlappingSelections"));
5778
5762
  return false;
5779
5763
  }
@@ -5881,7 +5865,7 @@ const InsertRangeMoveRightCommand = {
5881
5865
  const sheetInterceptorService = accessor.get(SheetInterceptorService);
5882
5866
  const errorService = accessor.get(ErrorService);
5883
5867
  const localeService = accessor.get(LocaleService);
5884
- if (selectionManagerService.isOverlapping()) {
5868
+ if (hasOverlappingRanges(selectionManagerService.getCurrentSelections().map(({ range }) => range))) {
5885
5869
  errorService.emit(localeService.t("sheets.info.overlappingSelections"));
5886
5870
  return false;
5887
5871
  }
@@ -6454,10 +6438,11 @@ const RemoveRowByRangeCommand = {
6454
6438
  range: visibleRange
6455
6439
  };
6456
6440
  const undoRemoveRowsParams = RemoveRowsUndoMutationFactory(removeRowsParams, worksheet);
6441
+ const removedRows = worksheet.getCellMatrix().getSlice(visibleRange.startRow, visibleRange.endRow, 0, worksheet.getColumnCount() - 1);
6457
6442
  const undoSetRangeValuesParams = {
6458
6443
  unitId,
6459
6444
  subUnitId,
6460
- cellValue: worksheet.getCellMatrix().getSlice(visibleRange.startRow, visibleRange.endRow, 0, worksheet.getColumnCount() - 1).getMatrix()
6445
+ cellValue: removedRows.getMatrix()
6461
6446
  };
6462
6447
  redos.push({
6463
6448
  id: RemoveRowMutation.id,
@@ -6474,9 +6459,10 @@ const RemoveRowByRangeCommand = {
6474
6459
  redoMutations.push(...redos);
6475
6460
  undoMutations.unshift(...undos);
6476
6461
  });
6462
+ const interceptorParams = params;
6477
6463
  const intercepted = sheetInterceptorService.onCommandExecute({
6478
6464
  id: RemoveRowCommandId,
6479
- params: { range }
6465
+ params: interceptorParams
6480
6466
  });
6481
6467
  const commandService = accessor.get(ICommandService);
6482
6468
  if (sequenceExecute([
@@ -6488,7 +6474,7 @@ const RemoveRowByRangeCommand = {
6488
6474
  setSelection(range, workbook, worksheet, commandService);
6489
6475
  const afterInterceptors = sheetInterceptorService.afterCommandExecute({
6490
6476
  id: RemoveRowCommandId,
6491
- params: { range }
6477
+ params: interceptorParams
6492
6478
  });
6493
6479
  sequenceExecute(afterInterceptors.redos, commandService);
6494
6480
  accessor.get(IUndoRedoService).pushUndoRedo({
@@ -6534,7 +6520,11 @@ const RemoveRowCommand = {
6534
6520
  };
6535
6521
  if (!await sheetInterceptorService.beforeCommandExecute({
6536
6522
  id: RemoveRowCommand.id,
6537
- params: { range }
6523
+ params: {
6524
+ range,
6525
+ unitId,
6526
+ subUnitId
6527
+ }
6538
6528
  })) return false;
6539
6529
  return commandService.syncExecuteCommand(RemoveRowByRangeCommand.id, {
6540
6530
  range,
@@ -6566,9 +6556,10 @@ const RemoveColByRangeCommand = {
6566
6556
  subUnitId,
6567
6557
  cellValue: worksheet.getCellMatrix().getSlice(0, worksheet.getRowCount() - 1, range.startColumn, range.endColumn).getMatrix()
6568
6558
  };
6559
+ const interceptorParams = params;
6569
6560
  const intercepted = sheetInterceptorService.onCommandExecute({
6570
6561
  id: RemoveColCommandId,
6571
- params: { range }
6562
+ params: interceptorParams
6572
6563
  });
6573
6564
  const commandService = accessor.get(ICommandService);
6574
6565
  if (sequenceExecute([
@@ -6583,7 +6574,7 @@ const RemoveColByRangeCommand = {
6583
6574
  setSelection(range, workbook, worksheet, commandService);
6584
6575
  const afterInterceptors = sheetInterceptorService.afterCommandExecute({
6585
6576
  id: RemoveColCommandId,
6586
- params: { range }
6577
+ params: interceptorParams
6587
6578
  });
6588
6579
  sequenceExecute(afterInterceptors.redos, commandService);
6589
6580
  accessor.get(IUndoRedoService).pushUndoRedo({
@@ -6630,7 +6621,7 @@ const RemoveColCommand = {
6630
6621
  let range = params === null || params === void 0 ? void 0 : params.range;
6631
6622
  if (!range) range = (_selectionManagerServ2 = selectionManagerService.getCurrentLastSelection()) === null || _selectionManagerServ2 === void 0 ? void 0 : _selectionManagerServ2.range;
6632
6623
  if (!range) return false;
6633
- const target = getSheetCommandTarget(accessor.get(IUniverInstanceService));
6624
+ const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), params);
6634
6625
  if (!target) return false;
6635
6626
  const { worksheet, subUnitId, unitId } = target;
6636
6627
  range = {
@@ -6640,7 +6631,11 @@ const RemoveColCommand = {
6640
6631
  };
6641
6632
  if (!await sheetInterceptorService.beforeCommandExecute({
6642
6633
  id: RemoveColCommand.id,
6643
- params: { range }
6634
+ params: {
6635
+ range,
6636
+ unitId,
6637
+ subUnitId
6638
+ }
6644
6639
  })) return false;
6645
6640
  return commandService.syncExecuteCommand(RemoveColByRangeCommand.id, {
6646
6641
  range,
@@ -6678,7 +6673,7 @@ const RemoveSheetMutation = {
6678
6673
  handler: (accessor, params) => {
6679
6674
  const univerInstanceService = accessor.get(IUniverInstanceService);
6680
6675
  const { subUnitId, unitId } = params;
6681
- const workbook = univerInstanceService.getUniverSheetInstance(unitId);
6676
+ const workbook = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
6682
6677
  if (!workbook) return false;
6683
6678
  return workbook.removeSheet(subUnitId);
6684
6679
  }
@@ -7259,7 +7254,7 @@ const handleMoveRangeCommon = (param, targetRange) => {
7259
7254
  matrix.setValue(row, col, 1);
7260
7255
  });
7261
7256
  const fromMatrix = new ObjectMatrix();
7262
- const loopFromRange = Rectangle.getIntersects(fromRange, targetRange);
7257
+ const loopFromRange = getIntersectRange(fromRange, targetRange);
7263
7258
  loopFromRange && Range.foreach(loopFromRange, (row, col) => {
7264
7259
  if (matrix.getValue(row, col)) {
7265
7260
  matrix.setValue(row, col, void 0);
@@ -7289,7 +7284,7 @@ const handleBaseRemoveRange = (_removeRange, _targetRange) => {
7289
7284
  const getRowLength = (range) => range.endRow - range.startRow + 1;
7290
7285
  if (removeRange.startRow <= targetRange.startRow && removeRange.endRow >= targetRange.endRow) {
7291
7286
  if (targetRange.startColumn < removeRange.startColumn && targetRange.endColumn >= removeRange.startColumn && targetRange.endColumn <= removeRange.endColumn || targetRange.startColumn < removeRange.startColumn && targetRange.endColumn >= removeRange.endColumn) {
7292
- const intersectedRange = Rectangle.getIntersects(targetRange, removeRange);
7287
+ const intersectedRange = getIntersectRange(targetRange, removeRange);
7293
7288
  if (intersectedRange) return {
7294
7289
  step: 0,
7295
7290
  length: -getLength(intersectedRange)
@@ -7297,7 +7292,7 @@ const handleBaseRemoveRange = (_removeRange, _targetRange) => {
7297
7292
  }
7298
7293
  if (targetRange.startColumn >= removeRange.startColumn && targetRange.endColumn <= removeRange.endColumn && getRowLength(removeRange) >= getRowLength(targetRange)) return null;
7299
7294
  if (targetRange.startColumn >= removeRange.startColumn && targetRange.startColumn <= removeRange.endColumn && targetRange.endColumn > removeRange.endColumn) {
7300
- const intersectedRange = Rectangle.getIntersects(targetRange, removeRange);
7295
+ const intersectedRange = getIntersectRange(targetRange, removeRange);
7301
7296
  if (intersectedRange) {
7302
7297
  const length = -getLength(intersectedRange);
7303
7298
  return {
@@ -7488,7 +7483,7 @@ const handleInsertRangeMoveDownCommon = (param, targetRange) => {
7488
7483
  endRow: Number.POSITIVE_INFINITY
7489
7484
  };
7490
7485
  const noMoveRanges = Rectangle.subtract(targetRange, bottomRange);
7491
- const targetMoveRange = Rectangle.getIntersects(bottomRange, targetRange);
7486
+ const targetMoveRange = getIntersectRange(bottomRange, targetRange);
7492
7487
  if (!targetMoveRange) return [targetRange];
7493
7488
  const matrix = new ObjectMatrix();
7494
7489
  noMoveRanges.forEach((noMoveRange) => {
@@ -7525,7 +7520,7 @@ const handleInsertRangeMoveRightCommon = (param, targetRange) => {
7525
7520
  endColumn: Number.POSITIVE_INFINITY
7526
7521
  };
7527
7522
  const noMoveRanges = Rectangle.subtract(targetRange, bottomRange);
7528
- const targetMoveRange = Rectangle.getIntersects(bottomRange, targetRange);
7523
+ const targetMoveRange = getIntersectRange(bottomRange, targetRange);
7529
7524
  if (!targetMoveRange) return [targetRange];
7530
7525
  const matrix = new ObjectMatrix();
7531
7526
  noMoveRanges.forEach((noMoveRange) => {
@@ -7566,9 +7561,9 @@ const handleDeleteRangeMoveLeftCommon = (param, targetRange) => {
7566
7561
  endColumn: Number.POSITIVE_INFINITY
7567
7562
  };
7568
7563
  const moveCount = range.endColumn - range.startColumn + 1;
7569
- const targetDeleteRange = Rectangle.getIntersects(range, targetRange);
7564
+ const targetDeleteRange = getIntersectRange(range, targetRange);
7570
7565
  const noMoveRanges = Rectangle.subtract(targetRange, rightRange);
7571
- const targetMoveRange = Rectangle.getIntersects(rightRange, targetRange);
7566
+ const targetMoveRange = getIntersectRange(rightRange, targetRange);
7572
7567
  if (!targetDeleteRange && !targetMoveRange) return [targetRange];
7573
7568
  const matrix = new ObjectMatrix();
7574
7569
  targetMoveRange && Range.foreach(targetMoveRange, (row, col) => {
@@ -7611,9 +7606,9 @@ const handleDeleteRangeMoveUpCommon = (param, targetRange) => {
7611
7606
  endRow: Number.POSITIVE_INFINITY
7612
7607
  };
7613
7608
  const moveCount = range.endRow - range.startRow + 1;
7614
- const targetDeleteRange = Rectangle.getIntersects(range, targetRange);
7609
+ const targetDeleteRange = getIntersectRange(range, targetRange);
7615
7610
  const noMoveRanges = Rectangle.subtract(targetRange, bottomRange);
7616
- const targetMoveRange = Rectangle.getIntersects(bottomRange, targetRange);
7611
+ const targetMoveRange = getIntersectRange(bottomRange, targetRange);
7617
7612
  if (!targetDeleteRange && !targetMoveRange) return [targetRange];
7618
7613
  const matrix = new ObjectMatrix();
7619
7614
  targetMoveRange && Range.foreach(targetMoveRange, (row, col) => {
@@ -8091,7 +8086,7 @@ function getSeparateEffectedRangesOnCommand(accessor, command) {
8091
8086
  }
8092
8087
  case EffectRefRangId.RemoveRowCommandId: {
8093
8088
  const params = command.params;
8094
- const target = getSheetCommandTarget(univerInstanceService);
8089
+ const target = getSheetCommandTarget(univerInstanceService, params);
8095
8090
  if (!target) return;
8096
8091
  const { worksheet, unitId, subUnitId } = target;
8097
8092
  const { range } = params;
@@ -8107,7 +8102,7 @@ function getSeparateEffectedRangesOnCommand(accessor, command) {
8107
8102
  }
8108
8103
  case EffectRefRangId.RemoveColCommandId: {
8109
8104
  const params = command.params;
8110
- const target = getSheetCommandTarget(univerInstanceService);
8105
+ const target = getSheetCommandTarget(univerInstanceService, params);
8111
8106
  if (!target) return;
8112
8107
  const { worksheet, unitId, subUnitId } = target;
8113
8108
  const { range } = params;
@@ -8300,7 +8295,7 @@ let RefRangeService = class RefRangeService extends Disposable {
8300
8295
  }
8301
8296
  case EffectRefRangId.RemoveRowCommandId: {
8302
8297
  const params = command.params;
8303
- const target = getSheetCommandTarget(this._univerInstanceService);
8298
+ const target = getSheetCommandTarget(this._univerInstanceService, params);
8304
8299
  if (!target) return [];
8305
8300
  const { worksheet, unitId, subUnitId } = target;
8306
8301
  const effectRange = {
@@ -8314,7 +8309,7 @@ let RefRangeService = class RefRangeService extends Disposable {
8314
8309
  }
8315
8310
  case EffectRefRangId.RemoveColCommandId: {
8316
8311
  const params = command.params;
8317
- const target = getSheetCommandTarget(this._univerInstanceService);
8312
+ const target = getSheetCommandTarget(this._univerInstanceService, params);
8318
8313
  if (!target) return [];
8319
8314
  const { worksheet, unitId, subUnitId } = target;
8320
8315
  const effectRange = {
@@ -8743,7 +8738,7 @@ let MergeCellController = class MergeCellController extends Disposable {
8743
8738
  }
8744
8739
  _onRefRangeChange() {
8745
8740
  const registerRefRange = (unitId, subUnitId) => {
8746
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
8741
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
8747
8742
  if (!workbook) return;
8748
8743
  const workSheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
8749
8744
  if (!workSheet) return;
@@ -9443,7 +9438,7 @@ let MergeCellController = class MergeCellController extends Disposable {
9443
9438
  this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
9444
9439
  if (mutationIdArrByMove$1.includes(command.id)) {
9445
9440
  if (!command.params) return;
9446
- const workbook = this._univerInstanceService.getUniverSheetInstance(command.params.unitId);
9441
+ const workbook = this._univerInstanceService.getUnit(command.params.unitId, UniverInstanceType.UNIVER_SHEET);
9447
9442
  if (!workbook) return;
9448
9443
  const worksheet = workbook.getSheetBySheetId(command.params.subUnitId);
9449
9444
  if (!worksheet) return;
@@ -9492,7 +9487,7 @@ let MergeCellController = class MergeCellController extends Disposable {
9492
9487
  });
9493
9488
  }
9494
9489
  if (mutationIdByRowCol$1.includes(command.id)) {
9495
- const workbook = this._univerInstanceService.getUniverSheetInstance(command.params.unitId);
9490
+ const workbook = this._univerInstanceService.getUnit(command.params.unitId, UniverInstanceType.UNIVER_SHEET);
9496
9491
  if (!workbook) return;
9497
9492
  const worksheet = workbook.getSheetBySheetId(command.params.subUnitId);
9498
9493
  if (!worksheet) return;
@@ -9557,7 +9552,7 @@ MergeCellController = __decorate([
9557
9552
  __decorateParam(5, Inject(SheetsSelectionsService))
9558
9553
  ], MergeCellController);
9559
9554
  function getWorkbook(univerInstanceService, unitId) {
9560
- if (unitId) return univerInstanceService.getUniverSheetInstance(unitId);
9555
+ if (unitId) return univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
9561
9556
  return univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
9562
9557
  }
9563
9558
  function getWorksheet(workbook, subUnitId) {
@@ -9773,10 +9768,11 @@ function getClearContentMutationParamsForRanges(accessor, unitId, worksheet, ran
9773
9768
  const redos = [];
9774
9769
  const subUnitId = worksheet.getSheetId();
9775
9770
  ranges.forEach((range) => {
9771
+ const redoMatrix = getClearContentMutationParamForRange(worksheet, range);
9776
9772
  const redoMutationParams = {
9777
9773
  unitId,
9778
9774
  subUnitId,
9779
- cellValue: getClearContentMutationParamForRange(worksheet, range).getData()
9775
+ cellValue: redoMatrix.clone()
9780
9776
  };
9781
9777
  const undoMutationParams = SetRangeValuesUndoMutationFactory(accessor, redoMutationParams);
9782
9778
  undos.push({
@@ -11564,7 +11560,8 @@ const AutoFillRules = {
11564
11560
  const dataNumArr = [];
11565
11561
  for (let i = 0; i < data.length; i++) {
11566
11562
  var _data$i;
11567
- const matchResult = matchExtendNumber(`${(_data$i = data[i]) === null || _data$i === void 0 ? void 0 : _data$i.v}`);
11563
+ const txt = `${(_data$i = data[i]) === null || _data$i === void 0 ? void 0 : _data$i.v}`;
11564
+ const matchResult = matchExtendNumber(txt);
11568
11565
  if (matchResult.isExtendNumber) dataNumArr.push(matchResult.matchNumber);
11569
11566
  }
11570
11567
  if (isReverse) {
@@ -11630,9 +11627,11 @@ const AutoFillRules = {
11630
11627
  if (isEqualDiff(dataNumArr)) {
11631
11628
  if (hasWeek || dataNumArr[dataNumArr.length - 1] < 6 && dataNumArr[0] > 0 || dataNumArr[0] < 6 && dataNumArr[dataNumArr.length - 1] > 0) {
11632
11629
  const dataLen = data.length;
11633
- return reverseIfNeed(fillChnWeek(data, len, dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2]), isReverse);
11630
+ const step = dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2];
11631
+ return reverseIfNeed(fillChnWeek(data, len, step), isReverse);
11634
11632
  }
11635
- return reverseIfNeed(fillChnNumber(data, len, dataNumArr[1] - dataNumArr[0]), isReverse);
11633
+ const step = dataNumArr[1] - dataNumArr[0];
11634
+ return reverseIfNeed(fillChnNumber(data, len, step), isReverse);
11636
11635
  }
11637
11636
  return fillCopy$1(data, len);
11638
11637
  } }
@@ -11673,7 +11672,8 @@ const AutoFillRules = {
11673
11672
  }
11674
11673
  if (isEqualDiff(dataNumArr)) {
11675
11674
  const dataLen = data.length;
11676
- return reverseIfNeed(fillChnWeek(data, len, dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2], 1), isReverse);
11675
+ const step = dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2];
11676
+ return reverseIfNeed(fillChnWeek(data, len, step, 1), isReverse);
11677
11677
  }
11678
11678
  return fillCopy$1(data, len);
11679
11679
  } }
@@ -11713,7 +11713,8 @@ const AutoFillRules = {
11713
11713
  }
11714
11714
  if (isEqualDiff(dataNumArr)) {
11715
11715
  const dataLen = data.length;
11716
- return reverseIfNeed(fillChnWeek(data, len, dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2], 2), isReverse);
11716
+ const step = dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2];
11717
+ return reverseIfNeed(fillChnWeek(data, len, step, 2), isReverse);
11717
11718
  }
11718
11719
  return fillCopy$1(data, len);
11719
11720
  } }
@@ -11758,7 +11759,8 @@ const AutoFillRules = {
11758
11759
  }
11759
11760
  if (isEqualDiff(dataNumArr)) {
11760
11761
  const dataLen = data.length;
11761
- return reverseIfNeed(fillLoopSeries(data, len, dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2], series), isReverse);
11762
+ const step = dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2];
11763
+ return reverseIfNeed(fillLoopSeries(data, len, step, series), isReverse);
11762
11764
  }
11763
11765
  return fillCopy$1(data, len);
11764
11766
  } }
@@ -12550,7 +12552,7 @@ const InsertSheetMutation = {
12550
12552
  handler: (accessor, params) => {
12551
12553
  const univerInstanceService = accessor.get(IUniverInstanceService);
12552
12554
  const { sheet, index, unitId, styles } = params;
12553
- const workbook = univerInstanceService.getUniverSheetInstance(unitId);
12555
+ const workbook = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
12554
12556
  if (!workbook) return false;
12555
12557
  if (styles) workbook.addStyles(styles);
12556
12558
  return workbook.addWorksheet(sheet.id, index, cloneWorksheetData(sheet));
@@ -13461,7 +13463,7 @@ const SetBorderCommand = {
13461
13463
  const setRangeValuesMutationParams = {
13462
13464
  unitId,
13463
13465
  subUnitId,
13464
- cellValue: mr.getData()
13466
+ cellValue: mr.clone()
13465
13467
  };
13466
13468
  const undoSetRangeValuesMutationParams = SetRangeValuesUndoMutationFactory(accessor, setRangeValuesMutationParams);
13467
13469
  if (commandService.syncExecuteCommand(SetRangeValuesMutation.id, setRangeValuesMutationParams)) {
@@ -13908,7 +13910,7 @@ const SetDefinedNameCommand = {
13908
13910
  //#endregion
13909
13911
  //#region src/commands/mutations/set-frozen.mutation.ts
13910
13912
  const SetFrozenMutationFactory = (accessor, params) => {
13911
- const universheet = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);
13913
+ const universheet = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET);
13912
13914
  if (universheet == null) throw new Error("universheet is null error!");
13913
13915
  const worksheet = universheet.getSheetBySheetId(params.subUnitId);
13914
13916
  if (worksheet == null) throw new Error("worksheet is null error!");
@@ -13923,7 +13925,7 @@ const SetFrozenMutation = {
13923
13925
  id: "sheet.mutation.set-frozen",
13924
13926
  type: CommandType.MUTATION,
13925
13927
  handler: (accessor, params) => {
13926
- const universheet = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);
13928
+ const universheet = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET);
13927
13929
  if (universheet == null) throw new Error("universheet is null error!");
13928
13930
  const worksheet = universheet.getSheetBySheetId(params.subUnitId);
13929
13931
  if (!worksheet) return false;
@@ -14583,7 +14585,7 @@ function mergeSelections(ranges) {
14583
14585
  //#endregion
14584
14586
  //#region src/commands/mutations/set-tab-color.mutation.ts
14585
14587
  const SetTabColorUndoMutationFactory = (accessor, params) => {
14586
- const oldTabColor = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId).getSheetBySheetId(params.subUnitId).getConfig().tabColor;
14588
+ const oldTabColor = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET).getSheetBySheetId(params.subUnitId).getConfig().tabColor;
14587
14589
  return {
14588
14590
  ...Tools.deepClone(params),
14589
14591
  color: oldTabColor
@@ -14593,7 +14595,7 @@ const SetTabColorMutation = {
14593
14595
  id: "sheet.mutation.set-tab-color",
14594
14596
  type: CommandType.MUTATION,
14595
14597
  handler: (accessor, params) => {
14596
- const workbook = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);
14598
+ const workbook = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET);
14597
14599
  if (!workbook) return false;
14598
14600
  const worksheet = workbook.getSheetBySheetId(params.subUnitId);
14599
14601
  if (!worksheet) return false;
@@ -14998,7 +15000,7 @@ const SetWorksheetHideMutation = {
14998
15000
  id: "sheet.mutation.set-worksheet-hidden",
14999
15001
  type: CommandType.MUTATION,
15000
15002
  handler: (accessor, params) => {
15001
- const universheet = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);
15003
+ const universheet = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET);
15002
15004
  if (universheet == null) return false;
15003
15005
  const worksheet = universheet.getSheetBySheetId(params.subUnitId);
15004
15006
  if (!worksheet) return false;
@@ -15065,7 +15067,7 @@ const SetWorksheetNameMutation = {
15065
15067
  id: "sheet.mutation.set-worksheet-name",
15066
15068
  type: CommandType.MUTATION,
15067
15069
  handler: (accessor, params) => {
15068
- const universheet = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);
15070
+ const universheet = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET);
15069
15071
  if (universheet == null) return false;
15070
15072
  const worksheet = universheet.getSheetBySheetId(params.subUnitId);
15071
15073
  if (!worksheet) return false;
@@ -15141,7 +15143,7 @@ const SetWorksheetOrderMutation = {
15141
15143
  id: "sheet.mutation.set-worksheet-order",
15142
15144
  type: CommandType.MUTATION,
15143
15145
  handler: (accessor, params) => {
15144
- const workbook = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);
15146
+ const workbook = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET);
15145
15147
  if (!workbook) return false;
15146
15148
  const config = workbook.getConfig();
15147
15149
  config.sheetOrder.splice(params.fromOrder, 1);
@@ -16378,7 +16380,7 @@ const SetWorksheetProtectionCommand = {
16378
16380
  //#endregion
16379
16381
  //#region src/commands/mutations/set-worksheet-right-to-left.mutation.ts
16380
16382
  const SetWorksheetRightToLeftUndoMutationFactory = (accessor, params) => {
16381
- const oldState = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId).getSheetBySheetId(params.subUnitId).getConfig().rightToLeft;
16383
+ const oldState = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET).getSheetBySheetId(params.subUnitId).getConfig().rightToLeft;
16382
16384
  return {
16383
16385
  ...Tools.deepClone(params),
16384
16386
  rightToLeft: oldState
@@ -16388,7 +16390,7 @@ const SetWorksheetRightToLeftMutation = {
16388
16390
  id: "sheet.mutation.set-worksheet-right-to-left",
16389
16391
  type: CommandType.MUTATION,
16390
16392
  handler: (accessor, params) => {
16391
- const workbook = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);
16393
+ const workbook = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET);
16392
16394
  if (!workbook) return false;
16393
16395
  const worksheet = workbook.getSheetBySheetId(params.subUnitId);
16394
16396
  if (!worksheet) return false;
@@ -17606,7 +17608,7 @@ let AutoFillController = class AutoFillController extends Disposable {
17606
17608
  if (hasStyle) {
17607
17609
  var _this$_univerInstance5;
17608
17610
  const deleteMergeRanges = [];
17609
- const mergeData = (_this$_univerInstance5 = this._univerInstanceService.getUniverSheetInstance(unitId)) === null || _this$_univerInstance5 === void 0 || (_this$_univerInstance5 = _this$_univerInstance5.getSheetBySheetId(subUnitId)) === null || _this$_univerInstance5 === void 0 ? void 0 : _this$_univerInstance5.getMergeData();
17611
+ const mergeData = (_this$_univerInstance5 = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance5 === void 0 || (_this$_univerInstance5 = _this$_univerInstance5.getSheetBySheetId(subUnitId)) === null || _this$_univerInstance5 === void 0 ? void 0 : _this$_univerInstance5.getMergeData();
17610
17612
  if (mergeData) mergeData.forEach((merge) => {
17611
17613
  if (Rectangle.intersects(merge, targetRange)) deleteMergeRanges.push(merge);
17612
17614
  });
@@ -17723,7 +17725,7 @@ let CalculateResultApplyController = class CalculateResultApplyController extend
17723
17725
  const redoMutationsInfo = [];
17724
17726
  for (let i = 0; i < unitIds.length; i++) {
17725
17727
  const unitId = unitIds[i];
17726
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
17728
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
17727
17729
  if (!workbook) continue;
17728
17730
  const sheetData = unitData[unitId];
17729
17731
  if (sheetData == null) continue;
@@ -17759,7 +17761,7 @@ let CalculateResultApplyController = class CalculateResultApplyController extend
17759
17761
  * @returns
17760
17762
  */
17761
17763
  _getMergedCellData(unitId, sheetId, cellData) {
17762
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
17764
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
17763
17765
  const styles = workbook === null || workbook === void 0 ? void 0 : workbook.getStyles();
17764
17766
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(sheetId);
17765
17767
  const oldCellDataMatrix = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getCellMatrix();
@@ -19033,15 +19035,16 @@ ZebraCrossingCacheController = __decorate([
19033
19035
 
19034
19036
  //#endregion
19035
19037
  //#region src/models/range-protection-render.model.ts
19036
- let RangeProtectionRenderModel = class RangeProtectionRenderModel {
19038
+ let RangeProtectionRenderModel = class RangeProtectionRenderModel extends Disposable {
19037
19039
  constructor(_selectionProtectionRuleModel, _permissionService) {
19040
+ super();
19038
19041
  this._selectionProtectionRuleModel = _selectionProtectionRuleModel;
19039
19042
  this._permissionService = _permissionService;
19040
19043
  _defineProperty(this, "_cache", new LRUMap(1e4));
19041
19044
  this._init();
19042
19045
  }
19043
19046
  _init() {
19044
- this._permissionService.permissionPointUpdate$.pipe(filter$1((permission) => permission.type === UnitObject.SelectRange), filter$1((permission) => getAllRangePermissionPoint().some((F) => permission instanceof F)), map$1((permission) => permission)).subscribe((permission) => {
19047
+ this.disposeWithMe(this._permissionService.permissionPointUpdate$.pipe(filter$1((permission) => permission.type === UnitObject.SelectRange), filter$1((permission) => getAllRangePermissionPoint().some((F) => permission instanceof F)), map$1((permission) => permission)).subscribe((permission) => {
19045
19048
  const ruleMap = this._selectionProtectionRuleModel.getSubunitRuleList(permission.unitId, permission.subUnitId);
19046
19049
  for (const rule of ruleMap) if (rule.permissionId === permission.permissionId) rule.ranges.forEach((range) => {
19047
19050
  Range.foreach(range, (row, col) => {
@@ -19049,8 +19052,8 @@ let RangeProtectionRenderModel = class RangeProtectionRenderModel {
19049
19052
  this._cache.delete(key);
19050
19053
  });
19051
19054
  });
19052
- });
19053
- this._selectionProtectionRuleModel.ruleChange$.subscribe((info) => {
19055
+ }));
19056
+ this.disposeWithMe(this._selectionProtectionRuleModel.ruleChange$.subscribe((info) => {
19054
19057
  info.rule.ranges.forEach((range) => {
19055
19058
  Range.foreach(range, (row, col) => {
19056
19059
  const key = this._createKey(info.unitId, info.subUnitId, row, col);
@@ -19066,7 +19069,7 @@ let RangeProtectionRenderModel = class RangeProtectionRenderModel {
19066
19069
  });
19067
19070
  });
19068
19071
  }
19069
- });
19072
+ }));
19070
19073
  }
19071
19074
  _createKey(unitId, subUnitId, row, col) {
19072
19075
  return `${unitId}_${subUnitId}_${row}_${col}`;
@@ -19099,6 +19102,10 @@ let RangeProtectionRenderModel = class RangeProtectionRenderModel {
19099
19102
  clear() {
19100
19103
  this._cache.clear();
19101
19104
  }
19105
+ dispose() {
19106
+ super.dispose();
19107
+ this._cache.clear();
19108
+ }
19102
19109
  };
19103
19110
  RangeProtectionRenderModel = __decorate([__decorateParam(0, Inject(RangeProtectionRuleModel)), __decorateParam(1, Inject(IPermissionService))], RangeProtectionRenderModel);
19104
19111
 
@@ -19388,7 +19395,7 @@ RangeProtectionCache = __decorate([
19388
19395
  //#endregion
19389
19396
  //#region package.json
19390
19397
  var name = "@univerjs/sheets";
19391
- var version = "1.0.0-alpha.7";
19398
+ var version = "1.0.0-alpha.8";
19392
19399
 
19393
19400
  //#endregion
19394
19401
  //#region src/controllers/active-worksheet.controller.ts
@@ -19413,7 +19420,7 @@ let ActiveWorksheetController = class ActiveWorksheetController extends Disposab
19413
19420
  _adjustActiveSheetOnHideSheet(mutation) {
19414
19421
  var _workbook$getActiveSh;
19415
19422
  const { unitId, subUnitId } = mutation.params;
19416
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
19423
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
19417
19424
  if (!workbook) return;
19418
19425
  if (((_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getSheetId()) !== subUnitId) return;
19419
19426
  const nextId = findTheNextUnhiddenSheet(workbook, workbook.getActiveSheetIndex());
@@ -19421,7 +19428,7 @@ let ActiveWorksheetController = class ActiveWorksheetController extends Disposab
19421
19428
  }
19422
19429
  _beforeAdjustActiveSheetOnRemoveSheet(mutation) {
19423
19430
  const { unitId, subUnitId } = mutation.params;
19424
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
19431
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
19425
19432
  if (!workbook) return;
19426
19433
  const worksheet = workbook.getSheetBySheetId(subUnitId);
19427
19434
  if (!worksheet) return;
@@ -19430,7 +19437,7 @@ let ActiveWorksheetController = class ActiveWorksheetController extends Disposab
19430
19437
  _adjustActiveSheetOnRemoveSheet(mutation) {
19431
19438
  if (this._previousSheetIndex === -1) return;
19432
19439
  const { unitId } = mutation.params;
19433
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
19440
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
19434
19441
  if (!workbook) return;
19435
19442
  if (workbook.getActiveSheet().getSheetId() === mutation.params.subUnitId) {
19436
19443
  const previousIndex = this._previousSheetIndex;
@@ -19897,7 +19904,7 @@ let NumfmtService = class NumfmtService extends Disposable {
19897
19904
  this._logService = _logService;
19898
19905
  }
19899
19906
  getValue(unitId, subUnitId, row, col) {
19900
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
19907
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
19901
19908
  if (!workbook) return;
19902
19909
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
19903
19910
  if (!worksheet) return;
@@ -19910,7 +19917,7 @@ let NumfmtService = class NumfmtService extends Disposable {
19910
19917
  return null;
19911
19918
  }
19912
19919
  deleteValues(unitId, subUnitId, values) {
19913
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
19920
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
19914
19921
  if (!workbook) return;
19915
19922
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
19916
19923
  if (!worksheet) return;
@@ -19927,7 +19934,7 @@ let NumfmtService = class NumfmtService extends Disposable {
19927
19934
  });
19928
19935
  }
19929
19936
  setValues(unitId, subUnitId, values) {
19930
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
19937
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
19931
19938
  if (!workbook) return;
19932
19939
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
19933
19940
  if (!worksheet) return;
@@ -20443,7 +20450,7 @@ let RangeProtectionRefRangeService = class RangeProtectionRefRangeService extend
20443
20450
  this._selectionProtectionRenderModel.clear();
20444
20451
  }
20445
20452
  if (mutationIdByRowCol.includes(command.id)) {
20446
- const workbook = this._univerInstanceService.getUniverSheetInstance(command.params.unitId);
20453
+ const workbook = this._univerInstanceService.getUnit(command.params.unitId, UniverInstanceType.UNIVER_SHEET);
20447
20454
  if (!workbook) return;
20448
20455
  const worksheet = workbook.getSheetBySheetId(command.params.subUnitId);
20449
20456
  if (!worksheet) return;
@@ -21039,11 +21046,14 @@ const getPrimaryCellUp = (scopeRange, worksheet, currentPrimary, step = 1, isFin
21039
21046
  startRow: next,
21040
21047
  endRow: next
21041
21048
  };
21042
- else if (isGoBack) return getPrimaryCellLeft(scopeRange, worksheet, {
21043
- ...currentPrimary,
21044
- startRow: endRow,
21045
- endRow
21046
- }, step, isFindNext, false);
21049
+ else if (isGoBack) {
21050
+ const newPrimary = {
21051
+ ...currentPrimary,
21052
+ startRow: endRow,
21053
+ endRow
21054
+ };
21055
+ return getPrimaryCellLeft(scopeRange, worksheet, newPrimary, step, isFindNext, false);
21056
+ }
21047
21057
  };
21048
21058
  const getPrimaryCellDown = (scopeRange, worksheet, currentPrimary, step = 1, isFindNext = true, isGoBack = true) => {
21049
21059
  const { startRow, endRow } = Range.transformRange(scopeRange, worksheet);
@@ -21060,11 +21070,14 @@ const getPrimaryCellDown = (scopeRange, worksheet, currentPrimary, step = 1, isF
21060
21070
  startRow: next,
21061
21071
  endRow: next
21062
21072
  };
21063
- else if (isGoBack) return getPrimaryCellRight(scopeRange, worksheet, {
21064
- ...currentPrimary,
21065
- startRow,
21066
- endRow: startRow
21067
- }, step, isFindNext, false);
21073
+ else if (isGoBack) {
21074
+ const newPrimary = {
21075
+ ...currentPrimary,
21076
+ startRow,
21077
+ endRow: startRow
21078
+ };
21079
+ return getPrimaryCellRight(scopeRange, worksheet, newPrimary, step, isFindNext, false);
21080
+ }
21068
21081
  };
21069
21082
  const getPrimaryCellLeft = (scopeRange, worksheet, currentPrimary, step = 1, isFindNext = true, isGoBack = true) => {
21070
21083
  const { startColumn, endColumn } = Range.transformRange(scopeRange, worksheet);
@@ -21081,11 +21094,14 @@ const getPrimaryCellLeft = (scopeRange, worksheet, currentPrimary, step = 1, isF
21081
21094
  startColumn: next,
21082
21095
  endColumn: next
21083
21096
  };
21084
- else if (isGoBack) return getPrimaryCellUp(scopeRange, worksheet, {
21085
- ...currentPrimary,
21086
- startColumn: endColumn,
21087
- endColumn
21088
- }, step, isFindNext, false);
21097
+ else if (isGoBack) {
21098
+ const newPrimary = {
21099
+ ...currentPrimary,
21100
+ startColumn: endColumn,
21101
+ endColumn
21102
+ };
21103
+ return getPrimaryCellUp(scopeRange, worksheet, newPrimary, step, isFindNext, false);
21104
+ }
21089
21105
  };
21090
21106
  const getPrimaryCellRight = (scopeRange, worksheet, currentPrimary, step = 1, isFindNext = true, isGoBack = true) => {
21091
21107
  const { startColumn, endColumn } = Range.transformRange(scopeRange, worksheet);
@@ -21102,11 +21118,14 @@ const getPrimaryCellRight = (scopeRange, worksheet, currentPrimary, step = 1, is
21102
21118
  endColumn: next,
21103
21119
  startColumn: next
21104
21120
  };
21105
- else if (isGoBack) return getPrimaryCellDown(scopeRange, worksheet, {
21106
- ...currentPrimary,
21107
- startColumn,
21108
- endColumn: startColumn
21109
- }, step, isFindNext, false);
21121
+ else if (isGoBack) {
21122
+ const newPrimary = {
21123
+ ...currentPrimary,
21124
+ startColumn,
21125
+ endColumn: startColumn
21126
+ };
21127
+ return getPrimaryCellDown(scopeRange, worksheet, newPrimary, step, isFindNext, false);
21128
+ }
21110
21129
  };
21111
21130
  function getCellAtRowCol$1(row, col, worksheet) {
21112
21131
  let destRange = null;