@univerjs/sheets 1.0.0-alpha.7 → 1.0.0-beta.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.
package/lib/cjs/index.js CHANGED
@@ -8,6 +8,10 @@ let rxjs_operators = require("rxjs/operators");
8
8
  let _univerjs_rpc = require("@univerjs/rpc");
9
9
 
10
10
  //#region src/basics/cell-type.ts
11
+ function isCellImage(documentData) {
12
+ var _documentData$drawing;
13
+ return !!(documentData === null || documentData === void 0 || (_documentData$drawing = documentData.drawingsOrder) === null || _documentData$drawing === void 0 ? void 0 : _documentData$drawing.length);
14
+ }
11
15
  /**
12
16
  * Get cell value type by style, new value and old value.
13
17
  * If the new value contains t, then take t directly. In other cases, we need to dynamically determine based on actual data and styles
@@ -159,7 +163,7 @@ const RangeThemeInterceptorId = "sheet.interceptor.range-theme-id";
159
163
  const IgnoreRangeThemeInterceptorKey = "sheet.interceptor.ignore-range-theme";
160
164
 
161
165
  //#endregion
162
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
166
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
163
167
  function _typeof(o) {
164
168
  "@babel/helpers - typeof";
165
169
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -170,7 +174,7 @@ function _typeof(o) {
170
174
  }
171
175
 
172
176
  //#endregion
173
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
177
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
174
178
  function toPrimitive(t, r) {
175
179
  if ("object" != _typeof(t) || !t) return t;
176
180
  var e = t[Symbol.toPrimitive];
@@ -183,14 +187,14 @@ function toPrimitive(t, r) {
183
187
  }
184
188
 
185
189
  //#endregion
186
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
190
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
187
191
  function toPropertyKey(t) {
188
192
  var i = toPrimitive(t, "string");
189
193
  return "symbol" == _typeof(i) ? i : i + "";
190
194
  }
191
195
 
192
196
  //#endregion
193
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
197
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
194
198
  function _defineProperty(e, r, t) {
195
199
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
196
200
  value: t,
@@ -201,7 +205,7 @@ function _defineProperty(e, r, t) {
201
205
  }
202
206
 
203
207
  //#endregion
204
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
208
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
205
209
  function __decorateParam(paramIndex, decorator) {
206
210
  return function(target, key) {
207
211
  decorator(target, key, paramIndex);
@@ -209,7 +213,7 @@ function __decorateParam(paramIndex, decorator) {
209
213
  }
210
214
 
211
215
  //#endregion
212
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
216
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
213
217
  function __decorate(decorators, target, key, desc) {
214
218
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
215
219
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -284,10 +288,7 @@ let SheetInterceptorService = class SheetInterceptorService extends _univerjs_co
284
288
  interceptCommand(interceptor) {
285
289
  if (this._commandInterceptors.includes(interceptor)) throw new Error("[SheetInterceptorService]: Interceptor already exists!");
286
290
  this._commandInterceptors.push(interceptor);
287
- this._commandInterceptors.sort((a, b) => {
288
- var _b$priority, _a$priority;
289
- return ((_b$priority = b.priority) !== null && _b$priority !== void 0 ? _b$priority : 0) - ((_a$priority = a.priority) !== null && _a$priority !== void 0 ? _a$priority : 0);
290
- });
291
+ this._commandInterceptors.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
291
292
  return this.disposeWithMe((0, _univerjs_core.toDisposable)(() => (0, _univerjs_core.remove)(this._commandInterceptors, interceptor)));
292
293
  }
293
294
  /**
@@ -298,25 +299,16 @@ let SheetInterceptorService = class SheetInterceptorService extends _univerjs_co
298
299
  onCommandExecute(info) {
299
300
  const infos = this._commandInterceptors.map((i) => i.getMutations(info));
300
301
  return {
301
- preUndos: infos.map((i) => {
302
- var _i$preUndos;
303
- return (_i$preUndos = i.preUndos) !== null && _i$preUndos !== void 0 ? _i$preUndos : [];
304
- }).flat(),
302
+ preUndos: infos.map((i) => i.preUndos ?? []).flat(),
305
303
  undos: infos.map((i) => i.undos).flat(),
306
- preRedos: infos.map((i) => {
307
- var _i$preRedos;
308
- return (_i$preRedos = i.preRedos) !== null && _i$preRedos !== void 0 ? _i$preRedos : [];
309
- }).flat(),
304
+ preRedos: infos.map((i) => i.preRedos ?? []).flat(),
310
305
  redos: infos.map((i) => i.redos).flat()
311
306
  };
312
307
  }
313
308
  interceptAfterCommand(interceptor) {
314
309
  if (this._afterCommandInterceptors.includes(interceptor)) throw new Error("[SheetInterceptorService]: Interceptor already exists!");
315
310
  this._afterCommandInterceptors.push(interceptor);
316
- this._afterCommandInterceptors.sort((a, b) => {
317
- var _b$priority2, _a$priority2;
318
- return ((_b$priority2 = b.priority) !== null && _b$priority2 !== void 0 ? _b$priority2 : 0) - ((_a$priority2 = a.priority) !== null && _a$priority2 !== void 0 ? _a$priority2 : 0);
319
- });
311
+ this._afterCommandInterceptors.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
320
312
  return this.disposeWithMe((0, _univerjs_core.toDisposable)(() => (0, _univerjs_core.remove)(this._afterCommandInterceptors, interceptor)));
321
313
  }
322
314
  afterCommandExecute(info) {
@@ -329,24 +321,15 @@ let SheetInterceptorService = class SheetInterceptorService extends _univerjs_co
329
321
  interceptAutoHeight(interceptor) {
330
322
  if (this._autoHeightInterceptors.includes(interceptor)) throw new Error("[SheetInterceptorService]: Interceptor already exists!");
331
323
  this._autoHeightInterceptors.push(interceptor);
332
- this._autoHeightInterceptors.sort((a, b) => {
333
- var _b$priority3, _a$priority3;
334
- return ((_b$priority3 = b.priority) !== null && _b$priority3 !== void 0 ? _b$priority3 : 0) - ((_a$priority3 = a.priority) !== null && _a$priority3 !== void 0 ? _a$priority3 : 0);
335
- });
324
+ this._autoHeightInterceptors.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
336
325
  return this.disposeWithMe((0, _univerjs_core.toDisposable)(() => (0, _univerjs_core.remove)(this._autoHeightInterceptors, interceptor)));
337
326
  }
338
327
  generateMutationsOfAutoHeight(ctx) {
339
328
  const infos = this._autoHeightInterceptors.map((i) => i.getMutations(ctx));
340
329
  return {
341
- preUndos: infos.map((i) => {
342
- var _i$preUndos2;
343
- return (_i$preUndos2 = i.preUndos) !== null && _i$preUndos2 !== void 0 ? _i$preUndos2 : [];
344
- }).flat(),
330
+ preUndos: infos.map((i) => i.preUndos ?? []).flat(),
345
331
  undos: infos.map((i) => i.undos).flat(),
346
- preRedos: infos.map((i) => {
347
- var _i$preRedos2;
348
- return (_i$preRedos2 = i.preRedos) !== null && _i$preRedos2 !== void 0 ? _i$preRedos2 : [];
349
- }).flat(),
332
+ preRedos: infos.map((i) => i.preRedos ?? []).flat(),
350
333
  redos: infos.map((i) => i.redos).flat()
351
334
  };
352
335
  }
@@ -362,10 +345,7 @@ let SheetInterceptorService = class SheetInterceptorService extends _univerjs_co
362
345
  interceptBeforeCommand(interceptor) {
363
346
  if (this._beforeCommandInterceptor.includes(interceptor)) throw new Error("[SheetInterceptorService]: Interceptor already exists!");
364
347
  this._beforeCommandInterceptor.push(interceptor);
365
- this._beforeCommandInterceptor.sort((a, b) => {
366
- var _b$priority4, _a$priority4;
367
- return ((_b$priority4 = b.priority) !== null && _b$priority4 !== void 0 ? _b$priority4 : 0) - ((_a$priority4 = a.priority) !== null && _a$priority4 !== void 0 ? _a$priority4 : 0);
368
- });
348
+ this._beforeCommandInterceptor.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
369
349
  return this.disposeWithMe((0, _univerjs_core.toDisposable)(() => (0, _univerjs_core.remove)(this._beforeCommandInterceptor, interceptor)));
370
350
  }
371
351
  /**
@@ -384,24 +364,15 @@ let SheetInterceptorService = class SheetInterceptorService extends _univerjs_co
384
364
  interceptRanges(interceptor) {
385
365
  if (this._rangeInterceptors.includes(interceptor)) throw new Error("[SheetInterceptorService]: Interceptor already exists!");
386
366
  this._rangeInterceptors.push(interceptor);
387
- this._rangeInterceptors.sort((a, b) => {
388
- var _b$priority5, _a$priority5;
389
- return ((_b$priority5 = b.priority) !== null && _b$priority5 !== void 0 ? _b$priority5 : 0) - ((_a$priority5 = a.priority) !== null && _a$priority5 !== void 0 ? _a$priority5 : 0);
390
- });
367
+ this._rangeInterceptors.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
391
368
  return this.disposeWithMe((0, _univerjs_core.toDisposable)(() => (0, _univerjs_core.remove)(this._rangeInterceptors, interceptor)));
392
369
  }
393
370
  generateMutationsByRanges(info) {
394
371
  const infos = this._rangeInterceptors.map((i) => i.getMutations(info));
395
372
  return {
396
- preUndos: infos.map((i) => {
397
- var _i$preUndos3;
398
- return (_i$preUndos3 = i.preUndos) !== null && _i$preUndos3 !== void 0 ? _i$preUndos3 : [];
399
- }).flat(),
373
+ preUndos: infos.map((i) => i.preUndos ?? []).flat(),
400
374
  undos: infos.map((i) => i.undos).flat(),
401
- preRedos: infos.map((i) => {
402
- var _i$preRedos3;
403
- return (_i$preRedos3 = i.preRedos) !== null && _i$preRedos3 !== void 0 ? _i$preRedos3 : [];
404
- }).flat(),
375
+ preRedos: infos.map((i) => i.preRedos ?? []).flat(),
405
376
  redos: infos.map((i) => i.redos).flat()
406
377
  };
407
378
  }
@@ -433,10 +404,7 @@ let SheetInterceptorService = class SheetInterceptorService extends _univerjs_co
433
404
  if (!this._interceptorsByName.has(key)) this._interceptorsByName.set(key, []);
434
405
  const interceptors = this._interceptorsByName.get(key);
435
406
  interceptors.push(interceptor);
436
- const sortedInterceptors = interceptors.sort((a, b) => {
437
- var _b$priority6, _a$priority6;
438
- return ((_b$priority6 = b.priority) !== null && _b$priority6 !== void 0 ? _b$priority6 : 0) - ((_a$priority6 = a.priority) !== null && _a$priority6 !== void 0 ? _a$priority6 : 0);
439
- });
407
+ const sortedInterceptors = interceptors.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
440
408
  this._invalidateComposedInterceptors();
441
409
  if (key === INTERCEPTOR_POINT.CELL_CONTENT) {
442
410
  const JOINED_EFFECT = _univerjs_core.InterceptorEffectEnum.Style | _univerjs_core.InterceptorEffectEnum.Value;
@@ -461,7 +429,7 @@ let SheetInterceptorService = class SheetInterceptorService extends _univerjs_co
461
429
  }
462
430
  fetchThroughInterceptors(name, effect, _key, filter) {
463
431
  const byNamesKey = effect === void 0 ? name : `${name}-${effect}`;
464
- const key = _key !== null && _key !== void 0 ? _key : byNamesKey;
432
+ const key = _key ?? byNamesKey;
465
433
  let composed = this._composedInterceptorByKey.get(key);
466
434
  if (!composed) {
467
435
  let interceptors = this._interceptorsByName.get(byNamesKey);
@@ -1681,7 +1649,7 @@ const MoveRowsMutation = {
1681
1649
  type: _univerjs_core.CommandType.MUTATION,
1682
1650
  handler: (accessor, params) => {
1683
1651
  const { unitId, subUnitId, sourceRange, targetRange } = params;
1684
- const univerSheet = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(unitId);
1652
+ const univerSheet = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
1685
1653
  if (!univerSheet) throw new Error("[MoveRowMutation] univerSheet is null!");
1686
1654
  const worksheet = univerSheet.getSheetBySheetId(subUnitId);
1687
1655
  if (!worksheet) throw new Error("[MoveRowMutation] worksheet is null!");
@@ -1723,7 +1691,7 @@ const MoveColsMutation = {
1723
1691
  type: _univerjs_core.CommandType.MUTATION,
1724
1692
  handler: (accessor, params) => {
1725
1693
  const { unitId, subUnitId, sourceRange, targetRange } = params;
1726
- const univerSheet = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(unitId);
1694
+ const univerSheet = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
1727
1695
  if (!univerSheet) throw new Error("[MoveColumnMutation] univerSheet is null!");
1728
1696
  const worksheet = univerSheet.getSheetBySheetId(subUnitId);
1729
1697
  if (!worksheet) throw new Error("[MoveColumnMutation] worksheet is null!");
@@ -1754,7 +1722,7 @@ const RemoveRowMutation = {
1754
1722
  id: "sheet.mutation.remove-rows",
1755
1723
  type: _univerjs_core.CommandType.MUTATION,
1756
1724
  handler: (accessor, params) => {
1757
- const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId);
1725
+ const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
1758
1726
  if (universheet == null) throw new Error("universheet is null error!");
1759
1727
  const worksheet = universheet.getSheetBySheetId(params.subUnitId);
1760
1728
  if (!worksheet) return false;
@@ -1770,7 +1738,7 @@ const RemoveRowMutation = {
1770
1738
  }
1771
1739
  };
1772
1740
  const RemoveColMutationFactory = (accessor, params) => {
1773
- const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId);
1741
+ const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
1774
1742
  if (universheet == null) throw new Error("universheet is null error!");
1775
1743
  const worksheet = universheet.getSheetBySheetId(params.subUnitId);
1776
1744
  if (worksheet == null) throw new Error("worksheet is null error!");
@@ -1789,7 +1757,7 @@ const RemoveColMutation = {
1789
1757
  id: "sheet.mutation.remove-col",
1790
1758
  type: _univerjs_core.CommandType.MUTATION,
1791
1759
  handler: (accessor, params) => {
1792
- const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId);
1760
+ const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
1793
1761
  if (universheet == null) throw new Error("universheet is null error!");
1794
1762
  const worksheet = universheet.getSheetBySheetId(params.subUnitId);
1795
1763
  if (!worksheet) return false;
@@ -1957,7 +1925,7 @@ const SetColDataMutation = {
1957
1925
  //#endregion
1958
1926
  //#region src/commands/mutations/set-col-visible.mutation.ts
1959
1927
  const SetColHiddenUndoMutationFactory = (accessor, params) => {
1960
- if (accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId) == null) throw new Error("universheet is null error!");
1928
+ if (accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET) == null) throw new Error("universheet is null error!");
1961
1929
  return {
1962
1930
  unitId: params.unitId,
1963
1931
  subUnitId: params.subUnitId,
@@ -1968,7 +1936,7 @@ const SetColHiddenMutation = {
1968
1936
  id: "sheet.mutation.set-col-hidden",
1969
1937
  type: _univerjs_core.CommandType.MUTATION,
1970
1938
  handler: (accessor, params) => {
1971
- const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId);
1939
+ const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
1972
1940
  if (!universheet) return false;
1973
1941
  const manager = universheet.getSheetBySheetId(params.subUnitId).getColumnManager();
1974
1942
  for (let i = 0; i < params.ranges.length; i++) {
@@ -1982,7 +1950,7 @@ const SetColHiddenMutation = {
1982
1950
  }
1983
1951
  };
1984
1952
  const SetColVisibleUndoMutationFactory = (accessor, params) => {
1985
- if (accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId) == null) throw new Error("universheet is null error!");
1953
+ if (accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET) == null) throw new Error("universheet is null error!");
1986
1954
  return {
1987
1955
  unitId: params.unitId,
1988
1956
  subUnitId: params.subUnitId,
@@ -1993,7 +1961,7 @@ const SetColVisibleMutation = {
1993
1961
  id: "sheet.mutation.set-col-visible",
1994
1962
  type: _univerjs_core.CommandType.MUTATION,
1995
1963
  handler: (accessor, params) => {
1996
- const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId);
1964
+ const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
1997
1965
  if (!universheet) return false;
1998
1966
  const manager = universheet.getSheetBySheetId(params.subUnitId).getColumnManager();
1999
1967
  for (let i = 0; i < params.ranges.length; i++) {
@@ -2170,7 +2138,7 @@ function handleStyle(styles, oldVal, newVal) {
2170
2138
  */
2171
2139
  function transformStyle(oldStyle, newStyle) {
2172
2140
  if (!newStyle || !Object.keys(newStyle).length) return oldStyle;
2173
- const backupStyle = _univerjs_core.Tools.deepClone(oldStyle !== null && oldStyle !== void 0 ? oldStyle : {}) || {};
2141
+ const backupStyle = _univerjs_core.Tools.deepClone(oldStyle ?? {}) || {};
2174
2142
  const styleRecord = newStyle;
2175
2143
  for (const key of _univerjs_core.STYLE_KEYS) {
2176
2144
  if (!Object.prototype.hasOwnProperty.call(styleRecord, key)) continue;
@@ -2343,7 +2311,7 @@ function setNull(value) {
2343
2311
  */
2344
2312
  const SetRangeValuesUndoMutationFactory = (accessor, params) => {
2345
2313
  const { unitId, subUnitId, cellValue, isOverrideStyle } = params;
2346
- const workbook = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(unitId);
2314
+ const workbook = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
2347
2315
  if (workbook == null) throw new Error("workbook is null error!");
2348
2316
  const worksheet = workbook.getSheetBySheetId(subUnitId);
2349
2317
  if (worksheet == null) throw new Error("worksheet is null error!");
@@ -2354,7 +2322,7 @@ const SetRangeValuesUndoMutationFactory = (accessor, params) => {
2354
2322
  const cell = _univerjs_core.Tools.deepClone(cellMatrix === null || cellMatrix === void 0 ? void 0 : cellMatrix.getValue(row, col)) || {};
2355
2323
  const oldStyle = styles.getStyleByCell(cell);
2356
2324
  const newStyle = styles.getStyleByCell(newVal);
2357
- cell.s = isOverrideStyle && Object.prototype.hasOwnProperty.call(newVal !== null && newVal !== void 0 ? newVal : {}, "s") ? oldStyle !== null && oldStyle !== void 0 ? oldStyle : null : transformStyle(oldStyle, newStyle);
2325
+ cell.s = isOverrideStyle && Object.prototype.hasOwnProperty.call(newVal ?? {}, "s") ? oldStyle ?? null : transformStyle(oldStyle, newStyle);
2358
2326
  undoData.setValue(row, col, setNull(cell));
2359
2327
  });
2360
2328
  return {
@@ -2473,7 +2441,7 @@ const SetRowDataMutation = {
2473
2441
  //#endregion
2474
2442
  //#region src/commands/mutations/set-row-visible.mutation.ts
2475
2443
  const SetRowVisibleUndoMutationFactory = (accessor, params) => {
2476
- if (accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId) == null) throw new Error("universheet is null error!");
2444
+ if (accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET) == null) throw new Error("universheet is null error!");
2477
2445
  return {
2478
2446
  unitId: params.unitId,
2479
2447
  subUnitId: params.subUnitId,
@@ -2484,7 +2452,7 @@ const SetRowVisibleMutation = {
2484
2452
  id: "sheet.mutation.set-row-visible",
2485
2453
  type: _univerjs_core.CommandType.MUTATION,
2486
2454
  handler: (accessor, params) => {
2487
- const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId);
2455
+ const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
2488
2456
  if (universheet == null) throw new Error("universheet is null error!");
2489
2457
  const manager = universheet.getSheetBySheetId(params.subUnitId).getRowManager();
2490
2458
  for (let i = 0; i < params.ranges.length; i++) {
@@ -2498,7 +2466,7 @@ const SetRowVisibleMutation = {
2498
2466
  }
2499
2467
  };
2500
2468
  const SetRowHiddenUndoMutationFactory = (accessor, params) => {
2501
- if (accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId) == null) throw new Error("universheet is null error!");
2469
+ if (accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET) == null) throw new Error("universheet is null error!");
2502
2470
  return {
2503
2471
  unitId: params.unitId,
2504
2472
  subUnitId: params.subUnitId,
@@ -2509,7 +2477,7 @@ const SetRowHiddenMutation = {
2509
2477
  id: "sheet.mutation.set-row-hidden",
2510
2478
  type: _univerjs_core.CommandType.MUTATION,
2511
2479
  handler: (accessor, params) => {
2512
- const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId);
2480
+ const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
2513
2481
  if (universheet == null) throw new Error("universheet is null error!");
2514
2482
  const manager = universheet.getSheetBySheetId(params.subUnitId).getRowManager();
2515
2483
  for (let i = 0; i < params.ranges.length; i++) {
@@ -2646,8 +2614,8 @@ const SetWorksheetRowHeightMutationFactory = (params, worksheet) => {
2646
2614
  const rowHeight = {};
2647
2615
  const manager = worksheet.getRowManager();
2648
2616
  for (const { startRow, endRow } of ranges) for (let rowIndex = startRow; rowIndex < endRow + 1; rowIndex++) {
2649
- var _manager$getRow$h, _manager$getRow;
2650
- rowHeight[rowIndex] = (_manager$getRow$h = (_manager$getRow = manager.getRow(rowIndex)) === null || _manager$getRow === void 0 ? void 0 : _manager$getRow.h) !== null && _manager$getRow$h !== void 0 ? _manager$getRow$h : worksheet.getConfig().defaultRowHeight;
2617
+ var _manager$getRow;
2618
+ rowHeight[rowIndex] = ((_manager$getRow = manager.getRow(rowIndex)) === null || _manager$getRow === void 0 ? void 0 : _manager$getRow.h) ?? worksheet.getConfig().defaultRowHeight;
2651
2619
  }
2652
2620
  return {
2653
2621
  unitId,
@@ -2676,11 +2644,11 @@ const SetWorksheetRowAutoHeightMutationFactory = (params, worksheet) => {
2676
2644
  const results = [];
2677
2645
  const manager = worksheet.getRowManager();
2678
2646
  for (const rowInfo of rowsAutoHeightInfo) {
2679
- var _manager$getRow$ah, _manager$getRow3;
2647
+ var _manager$getRow3;
2680
2648
  const { row } = rowInfo;
2681
2649
  results.push({
2682
2650
  row,
2683
- autoHeight: (_manager$getRow$ah = (_manager$getRow3 = manager.getRow(row)) === null || _manager$getRow3 === void 0 ? void 0 : _manager$getRow3.ah) !== null && _manager$getRow$ah !== void 0 ? _manager$getRow$ah : worksheet.getConfig().defaultRowHeight
2651
+ autoHeight: ((_manager$getRow3 = manager.getRow(row)) === null || _manager$getRow3 === void 0 ? void 0 : _manager$getRow3.ah) ?? worksheet.getConfig().defaultRowHeight
2684
2652
  });
2685
2653
  }
2686
2654
  return {
@@ -2714,10 +2682,7 @@ const SetWorksheetRowIsAutoHeightMutation = {
2714
2682
  for (const { startRow, endRow } of ranges) for (let rowIndex = startRow; rowIndex <= endRow; rowIndex++) {
2715
2683
  const row = manager.getRowOrCreate(rowIndex);
2716
2684
  if (typeof autoHeightInfo === "number") row.ia = autoHeightInfo;
2717
- else {
2718
- var _autoHeightInfo$rowIn;
2719
- row.ia = (_autoHeightInfo$rowIn = autoHeightInfo[rowIndex]) !== null && _autoHeightInfo$rowIn !== void 0 ? _autoHeightInfo$rowIn : void 0;
2720
- }
2685
+ else row.ia = autoHeightInfo[rowIndex] ?? void 0;
2721
2686
  }
2722
2687
  return true;
2723
2688
  }
@@ -3553,7 +3518,8 @@ const findAllRectangle = (topMatrix) => {
3553
3518
  * @returns {IRange[]}
3554
3519
  */
3555
3520
  const rangeMerge = (ranges) => {
3556
- return findAllRectangle(createTopMatrixFromRanges(ranges));
3521
+ const topMatrix = createTopMatrixFromRanges(ranges);
3522
+ return findAllRectangle(topMatrix);
3557
3523
  };
3558
3524
  var RangeMergeUtil = class {
3559
3525
  constructor() {
@@ -3576,7 +3542,8 @@ var RangeMergeUtil = class {
3576
3542
  return this;
3577
3543
  }
3578
3544
  merge() {
3579
- return findAllRectangle(createTopMatrixFromMatrix(this._matrix));
3545
+ const topMatrix = createTopMatrixFromMatrix(this._matrix);
3546
+ return findAllRectangle(topMatrix);
3580
3547
  }
3581
3548
  };
3582
3549
 
@@ -4246,21 +4213,12 @@ var WorkbookSelectionModel = class extends _univerjs_core.Disposable {
4246
4213
  getCurrentSelections() {
4247
4214
  return this._getCurrentSelections();
4248
4215
  }
4249
- /**
4250
- * @deprecated use `getSelectionsOfWorksheet` instead.
4251
- * @param sheetId
4252
- * @returns
4253
- */
4254
- getSelectionOfWorksheet(sheetId) {
4255
- return this.getSelectionsOfWorksheet(sheetId);
4256
- }
4257
4216
  getSelectionsOfWorksheet(sheetId) {
4258
4217
  if (!this._worksheetSelections.has(sheetId)) this._worksheetSelections.set(sheetId, []);
4259
4218
  return this._worksheetSelections.get(sheetId);
4260
4219
  }
4261
4220
  getLastSelectionPrimaryCellOfWorksheet(sheetId) {
4262
- var _this$_worksheetLastS;
4263
- return (_this$_worksheetLastS = this._worksheetLastSelectionPrimaryCell.get(sheetId)) !== null && _this$_worksheetLastS !== void 0 ? _this$_worksheetLastS : null;
4221
+ return this._worksheetLastSelectionPrimaryCell.get(sheetId) ?? null;
4264
4222
  }
4265
4223
  setSelectionsOfWorksheet(sheetId, selections) {
4266
4224
  this._worksheetSelections.set(sheetId, [...selections]);
@@ -4414,35 +4372,21 @@ let SheetsSelectionsService = class SheetsSelectionsService extends _univerjs_co
4414
4372
  setSelections(unitIdOrSelections, worksheetIdOrType, selectionDatas, type) {
4415
4373
  if (typeof unitIdOrSelections === "string" && typeof worksheetIdOrType === "string") {
4416
4374
  const unitId = unitIdOrSelections;
4417
- this._ensureWorkbookSelection(unitId).setSelections(worksheetIdOrType, selectionDatas || [], type !== null && type !== void 0 ? type : 3);
4375
+ this._ensureWorkbookSelection(unitId).setSelections(worksheetIdOrType, selectionDatas || [], type ?? 3);
4418
4376
  return;
4419
4377
  }
4420
4378
  const current = this._currentSelectionPos;
4421
4379
  if (!current) throw new Error("[SheetsSelectionsService]: cannot find current selection position!");
4422
4380
  const { unitId, sheetId } = current;
4423
4381
  if (typeof unitIdOrSelections === "object") {
4424
- var _ref;
4425
- const selectionData = unitIdOrSelections !== null && unitIdOrSelections !== void 0 ? unitIdOrSelections : selectionDatas;
4426
- const type = (_ref = worksheetIdOrType) !== null && _ref !== void 0 ? _ref : 3;
4382
+ const selectionData = unitIdOrSelections ?? selectionDatas;
4383
+ const type = worksheetIdOrType ?? 3;
4427
4384
  this._ensureWorkbookSelection(unitId).setSelections(sheetId, selectionData, type);
4428
4385
  }
4429
4386
  }
4430
4387
  clearCurrentSelections() {
4431
4388
  this._getCurrentSelections().splice(0);
4432
4389
  }
4433
- /**
4434
- * Determine whether multiple current selections overlap
4435
- *
4436
- * @deprecated this should be extracted to an pure function
4437
- */
4438
- isOverlapping() {
4439
- const selectionDataList = this.getCurrentSelections();
4440
- if (selectionDataList == null) return false;
4441
- return selectionDataList.some(({ range }, index) => selectionDataList.some(({ range: range2 }, index2) => {
4442
- if (index === index2) return false;
4443
- return range.startRow <= range2.endRow && range.endRow >= range2.startRow && range.startColumn <= range2.endColumn && range.endColumn >= range2.startColumn;
4444
- }));
4445
- }
4446
4390
  _getCurrentSelections() {
4447
4391
  const current = this._currentSelectionPos;
4448
4392
  if (!current) return [];
@@ -5057,6 +5001,9 @@ RefSelectionsService = __decorate([__decorateParam(0, _univerjs_core.IUniverInst
5057
5001
 
5058
5002
  //#endregion
5059
5003
  //#region src/commands/utils/selection-command-util.ts
5004
+ function hasOverlappingRanges(ranges) {
5005
+ return ranges.some((range, index) => ranges.slice(index + 1).some((other) => _univerjs_core.Rectangle.simpleRangesIntersect(range, other)));
5006
+ }
5060
5007
  function getSelectionsService(accessor, fromCurrentSelection) {
5061
5008
  const isInRefSelectionMode = accessor.get(_univerjs_core.IContextService).getContextValue(REF_SELECTIONS_ENABLED);
5062
5009
  return accessor.get(isInRefSelectionMode && !fromCurrentSelection ? IRefSelectionsService : SheetsSelectionsService);
@@ -5131,15 +5078,14 @@ const MoveRangeCommand = {
5131
5078
  }
5132
5079
  };
5133
5080
  function _resolveMoveRangeContext(accessor, params) {
5134
- var _ref, _params$toUnitId, _params$fromSubUnitId, _ref2, _params$toSubUnitId;
5135
5081
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
5136
5082
  const target = getSheetCommandTarget(univerInstanceService);
5137
- const unitId = (_ref = (_params$toUnitId = params.toUnitId) !== null && _params$toUnitId !== void 0 ? _params$toUnitId : params.fromUnitId) !== null && _ref !== void 0 ? _ref : target === null || target === void 0 ? void 0 : target.unitId;
5138
- const fromSubUnitId = (_params$fromSubUnitId = params.fromSubUnitId) !== null && _params$fromSubUnitId !== void 0 ? _params$fromSubUnitId : target === null || target === void 0 ? void 0 : target.subUnitId;
5139
- 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;
5083
+ const unitId = params.toUnitId ?? params.fromUnitId ?? (target === null || target === void 0 ? void 0 : target.unitId);
5084
+ const fromSubUnitId = params.fromSubUnitId ?? (target === null || target === void 0 ? void 0 : target.subUnitId);
5085
+ const toSubUnitId = params.toSubUnitId ?? params.fromSubUnitId ?? (target === null || target === void 0 ? void 0 : target.subUnitId);
5140
5086
  if (!unitId || !fromSubUnitId || !toSubUnitId) return null;
5141
5087
  if (params.fromUnitId && params.toUnitId && params.fromUnitId !== params.toUnitId) return null;
5142
- const workbook = univerInstanceService.getUniverSheetInstance(unitId);
5088
+ const workbook = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
5143
5089
  const fromWorksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(fromSubUnitId);
5144
5090
  const toWorksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(toSubUnitId);
5145
5091
  if (!fromWorksheet || !toWorksheet) return null;
@@ -5152,7 +5098,6 @@ function _resolveMoveRangeContext(accessor, params) {
5152
5098
  };
5153
5099
  }
5154
5100
  function getMoveRangeCommandMutations(accessor, params, options = {}) {
5155
- var _interceptorCommands$, _interceptorCommands$2;
5156
5101
  const { includeSelection = true, includeAfterCommand = true, includeAutoHeight = true } = options;
5157
5102
  const context = _resolveMoveRangeContext(accessor, params);
5158
5103
  if (!context) return null;
@@ -5174,12 +5119,12 @@ function getMoveRangeCommandMutations(accessor, params, options = {}) {
5174
5119
  };
5175
5120
  const interceptorCommands = sheetInterceptorService.onCommandExecute(commandInfo);
5176
5121
  const redos = [
5177
- ...(_interceptorCommands$ = interceptorCommands.preRedos) !== null && _interceptorCommands$ !== void 0 ? _interceptorCommands$ : [],
5122
+ ...interceptorCommands.preRedos ?? [],
5178
5123
  ...moveRangeMutations.redos,
5179
5124
  ...interceptorCommands.redos
5180
5125
  ];
5181
5126
  const undos = [
5182
- ...(_interceptorCommands$2 = interceptorCommands.preUndos) !== null && _interceptorCommands$2 !== void 0 ? _interceptorCommands$2 : [],
5127
+ ...interceptorCommands.preUndos ?? [],
5183
5128
  ...moveRangeMutations.undos,
5184
5129
  ...interceptorCommands.undos
5185
5130
  ];
@@ -5247,8 +5192,7 @@ function getMoveRangeUndoRedoMutations(accessor, from, to, ignoreMerge = false)
5247
5192
  const toRedoCellValue = new _univerjs_core.ObjectMatrix();
5248
5193
  const toUndoCellValue = new _univerjs_core.ObjectMatrix();
5249
5194
  _univerjs_core.Range.foreach(fromRange, (row, col) => {
5250
- var _Tools$deepClone;
5251
- const cellData = (_Tools$deepClone = _univerjs_core.Tools.deepClone(fromWorksheetCellMatrix.getValue(row, col))) !== null && _Tools$deepClone !== void 0 ? _Tools$deepClone : null;
5195
+ const cellData = _univerjs_core.Tools.deepClone(fromWorksheetCellMatrix.getValue(row, col)) ?? null;
5252
5196
  if (cellData === null || cellData === void 0 ? void 0 : cellData.s) cellData.s = workbook.getStyles().get(cellData.s);
5253
5197
  fromRedoCellValue.setValue(row, col, null);
5254
5198
  fromUndoCellValue.setValue(row, col, cellData);
@@ -5258,8 +5202,7 @@ function getMoveRangeUndoRedoMutations(accessor, from, to, ignoreMerge = false)
5258
5202
  toRedoCellValue.setValue(range.startRow, range.startColumn, _univerjs_core.Tools.deepClone(cellData));
5259
5203
  });
5260
5204
  _univerjs_core.Range.foreach(toRange, (row, col) => {
5261
- var _Tools$deepClone2;
5262
- const cellData = (_Tools$deepClone2 = _univerjs_core.Tools.deepClone(toWorksheetCellMatrix.getValue(row, col))) !== null && _Tools$deepClone2 !== void 0 ? _Tools$deepClone2 : null;
5205
+ const cellData = _univerjs_core.Tools.deepClone(toWorksheetCellMatrix.getValue(row, col)) ?? null;
5263
5206
  toUndoCellValue.setValue(row, col, cellData);
5264
5207
  });
5265
5208
  const redoMoveRangeMutationParams = {
@@ -5326,7 +5269,7 @@ const SetRangeValuesCommand = {
5326
5269
  id: "sheet.command.set-range-values",
5327
5270
  type: _univerjs_core.CommandType.COMMAND,
5328
5271
  handler: (accessor, params) => {
5329
- var _selectionManagerServ, _realCellValue;
5272
+ var _selectionManagerServ;
5330
5273
  const target = getSheetCommandTarget(accessor.get(_univerjs_core.IUniverInstanceService), params);
5331
5274
  if (!target) return false;
5332
5275
  const currentSelections = (_selectionManagerServ = accessor.get(SheetsSelectionsService).getCurrentSelections()) === null || _selectionManagerServ === void 0 ? void 0 : _selectionManagerServ.map((s) => s.range);
@@ -5354,7 +5297,7 @@ const SetRangeValuesCommand = {
5354
5297
  const setRangeValuesMutationRedoParams = {
5355
5298
  unitId,
5356
5299
  subUnitId,
5357
- cellValue: (_realCellValue = realCellValue) !== null && _realCellValue !== void 0 ? _realCellValue : cellValue.getMatrix()
5300
+ cellValue: realCellValue ?? cellValue.getMatrix()
5358
5301
  };
5359
5302
  const setRangeValuesMutationUndoParams = SetRangeValuesUndoMutationFactory(accessor, setRangeValuesMutationRedoParams);
5360
5303
  const cellHeights = (0, _univerjs_core.mapObjectMatrix)(setRangeValuesMutationRedoParams.cellValue, (row, col) => worksheet.getCellHeight(row, col) || void 0);
@@ -5414,7 +5357,7 @@ function getInsertRangeMutations(accessor, params) {
5414
5357
  const { unitId, subUnitId, range, shiftDimension, cellValue = {} } = params;
5415
5358
  const instanceService = accessor.get(_univerjs_core.IUniverInstanceService);
5416
5359
  const sheetInterceptorService = accessor.get(SheetInterceptorService);
5417
- const workbook = instanceService.getUniverSheetInstance(unitId);
5360
+ const workbook = instanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
5418
5361
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
5419
5362
  if (worksheet) {
5420
5363
  const cellMatrix = worksheet.getCellMatrix();
@@ -5511,7 +5454,7 @@ function getRemoveRangeMutations(accessor, params) {
5511
5454
  const { unitId, subUnitId, range, shiftDimension } = params;
5512
5455
  const instanceService = accessor.get(_univerjs_core.IUniverInstanceService);
5513
5456
  const sheetInterceptorService = accessor.get(SheetInterceptorService);
5514
- const workbook = instanceService.getUniverSheetInstance(unitId);
5457
+ const workbook = instanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
5515
5458
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
5516
5459
  if (worksheet) {
5517
5460
  const cellMatrix = worksheet.getCellMatrix();
@@ -5646,7 +5589,6 @@ const DeleteRangeMoveLeftCommand = {
5646
5589
  type: _univerjs_core.CommandType.COMMAND,
5647
5590
  id: DeleteRangeMoveLeftCommandId,
5648
5591
  handler: async (accessor, params) => {
5649
- var _sheetInterceptor$pre, _sheetInterceptor$pre2;
5650
5592
  const commandService = accessor.get(_univerjs_core.ICommandService);
5651
5593
  const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
5652
5594
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
@@ -5672,11 +5614,11 @@ const DeleteRangeMoveLeftCommand = {
5672
5614
  params: { range }
5673
5615
  });
5674
5616
  const { redo: removeRangeRedo, undo: removeRangeUndo } = getRemoveRangeMutations(accessor, deleteRangeMutationParams);
5675
- const redos = [...(_sheetInterceptor$pre = sheetInterceptor.preRedos) !== null && _sheetInterceptor$pre !== void 0 ? _sheetInterceptor$pre : [], ...removeRangeRedo];
5617
+ const redos = [...sheetInterceptor.preRedos ?? [], ...removeRangeRedo];
5676
5618
  const undos = [...sheetInterceptor.undos, ...removeRangeUndo];
5677
5619
  redos.push(...sheetInterceptor.redos);
5678
5620
  redos.push(followSelectionOperation(range, workbook, worksheet));
5679
- undos.push(...(_sheetInterceptor$pre2 = sheetInterceptor.preUndos) !== null && _sheetInterceptor$pre2 !== void 0 ? _sheetInterceptor$pre2 : []);
5621
+ undos.push(...sheetInterceptor.preUndos ?? []);
5680
5622
  if ((0, _univerjs_core.sequenceExecute)(redos, commandService).result) {
5681
5623
  const afterInterceptors = sheetInterceptorService.afterCommandExecute({
5682
5624
  id: DeleteRangeMoveLeftCommand.id,
@@ -5706,7 +5648,6 @@ const DeleteRangeMoveUpCommand = {
5706
5648
  type: _univerjs_core.CommandType.COMMAND,
5707
5649
  id: DeleteRangeMoveUpCommandId,
5708
5650
  handler: async (accessor, params) => {
5709
- var _sheetInterceptor$pre, _sheetInterceptor$pre2;
5710
5651
  const commandService = accessor.get(_univerjs_core.ICommandService);
5711
5652
  const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
5712
5653
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
@@ -5732,11 +5673,11 @@ const DeleteRangeMoveUpCommand = {
5732
5673
  params: { range }
5733
5674
  });
5734
5675
  const { redo: removeRangeRedo, undo: removeRangeUndo } = getRemoveRangeMutations(accessor, deleteRangeMutationParams);
5735
- const redos = [...(_sheetInterceptor$pre = sheetInterceptor.preRedos) !== null && _sheetInterceptor$pre !== void 0 ? _sheetInterceptor$pre : [], ...removeRangeRedo];
5676
+ const redos = [...sheetInterceptor.preRedos ?? [], ...removeRangeRedo];
5736
5677
  const undos = [...sheetInterceptor.undos, ...removeRangeUndo];
5737
5678
  redos.push(...sheetInterceptor.redos);
5738
5679
  redos.push(followSelectionOperation(range, workbook, worksheet));
5739
- undos.push(...(_sheetInterceptor$pre2 = sheetInterceptor.preUndos) !== null && _sheetInterceptor$pre2 !== void 0 ? _sheetInterceptor$pre2 : []);
5680
+ undos.push(...sheetInterceptor.preUndos ?? []);
5740
5681
  if ((0, _univerjs_core.sequenceExecute)(redos, commandService).result) {
5741
5682
  const afterInterceptors = sheetInterceptorService.afterCommandExecute({
5742
5683
  id: DeleteRangeMoveUpCommand.id,
@@ -5766,7 +5707,6 @@ const InsertRangeMoveDownCommand = {
5766
5707
  type: _univerjs_core.CommandType.COMMAND,
5767
5708
  id: InsertRangeMoveDownCommandId,
5768
5709
  handler: async (accessor, params) => {
5769
- var _sheetInterceptor$pre, _sheetInterceptor$pre2;
5770
5710
  const commandService = accessor.get(_univerjs_core.ICommandService);
5771
5711
  const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
5772
5712
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
@@ -5774,7 +5714,7 @@ const InsertRangeMoveDownCommand = {
5774
5714
  const sheetInterceptorService = accessor.get(SheetInterceptorService);
5775
5715
  const errorService = accessor.get(_univerjs_core.ErrorService);
5776
5716
  const localeService = accessor.get(_univerjs_core.LocaleService);
5777
- if (selectionManagerService.isOverlapping()) {
5717
+ if (hasOverlappingRanges(selectionManagerService.getCurrentSelections().map(({ range }) => range))) {
5778
5718
  errorService.emit(localeService.t("sheets.info.overlappingSelections"));
5779
5719
  return false;
5780
5720
  }
@@ -5842,8 +5782,8 @@ const InsertRangeMoveDownCommand = {
5842
5782
  });
5843
5783
  redoMutations.push(...sheetInterceptor.redos);
5844
5784
  redoMutations.push(followSelectionOperation(range, workbook, worksheet));
5845
- undoMutations.push(...(_sheetInterceptor$pre = sheetInterceptor.preUndos) !== null && _sheetInterceptor$pre !== void 0 ? _sheetInterceptor$pre : []);
5846
- redoMutations.unshift(...(_sheetInterceptor$pre2 = sheetInterceptor.preRedos) !== null && _sheetInterceptor$pre2 !== void 0 ? _sheetInterceptor$pre2 : []);
5785
+ undoMutations.push(...sheetInterceptor.preUndos ?? []);
5786
+ redoMutations.unshift(...sheetInterceptor.preRedos ?? []);
5847
5787
  undoMutations.unshift(...sheetInterceptor.undos);
5848
5788
  if ((0, _univerjs_core.sequenceExecute)(redoMutations, commandService).result) {
5849
5789
  const afterInterceptors = sheetInterceptorService.afterCommandExecute({
@@ -5874,7 +5814,6 @@ const InsertRangeMoveRightCommand = {
5874
5814
  type: _univerjs_core.CommandType.COMMAND,
5875
5815
  id: InsertRangeMoveRightCommandId,
5876
5816
  handler: async (accessor, params) => {
5877
- var _sheetInterceptor$pre, _sheetInterceptor$pre2;
5878
5817
  const commandService = accessor.get(_univerjs_core.ICommandService);
5879
5818
  const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
5880
5819
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
@@ -5882,7 +5821,7 @@ const InsertRangeMoveRightCommand = {
5882
5821
  const sheetInterceptorService = accessor.get(SheetInterceptorService);
5883
5822
  const errorService = accessor.get(_univerjs_core.ErrorService);
5884
5823
  const localeService = accessor.get(_univerjs_core.LocaleService);
5885
- if (selectionManagerService.isOverlapping()) {
5824
+ if (hasOverlappingRanges(selectionManagerService.getCurrentSelections().map(({ range }) => range))) {
5886
5825
  errorService.emit(localeService.t("sheets.info.overlappingSelections"));
5887
5826
  return false;
5888
5827
  }
@@ -5950,8 +5889,8 @@ const InsertRangeMoveRightCommand = {
5950
5889
  });
5951
5890
  redoMutations.push(...sheetInterceptor.redos);
5952
5891
  redoMutations.push(followSelectionOperation(range, workbook, worksheet));
5953
- undoMutations.push(...(_sheetInterceptor$pre = sheetInterceptor.preUndos) !== null && _sheetInterceptor$pre !== void 0 ? _sheetInterceptor$pre : []);
5954
- redoMutations.unshift(...(_sheetInterceptor$pre2 = sheetInterceptor.preRedos) !== null && _sheetInterceptor$pre2 !== void 0 ? _sheetInterceptor$pre2 : []);
5892
+ undoMutations.push(...sheetInterceptor.preUndos ?? []);
5893
+ redoMutations.unshift(...sheetInterceptor.preRedos ?? []);
5955
5894
  undoMutations.unshift(...sheetInterceptor.undos);
5956
5895
  if ((0, _univerjs_core.sequenceExecute)(redoMutations, commandService).result) {
5957
5896
  const afterInterceptors = sheetInterceptorService.afterCommandExecute({
@@ -6004,7 +5943,6 @@ const InsertRowByRangeCommand = {
6004
5943
  type: _univerjs_core.CommandType.COMMAND,
6005
5944
  id: "sheet.command.insert-row-by-range",
6006
5945
  handler: (accessor, params) => {
6007
- var _intercepted$preRedos, _intercepted$redos, _intercepted$preUndos, _intercepted$undos;
6008
5946
  const target = getSheetCommandTarget(accessor.get(_univerjs_core.IUniverInstanceService), params);
6009
5947
  if (!target) throw new Error("Workbook or Worksheet not found at InsertRowByRangeCommand");
6010
5948
  const { workbook, worksheet, unitId, subUnitId } = target;
@@ -6047,11 +5985,11 @@ const InsertRowByRangeCommand = {
6047
5985
  id: InsertRowCommand.id,
6048
5986
  params
6049
5987
  });
6050
- redos.unshift(...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : []);
6051
- redos.push(...(_intercepted$redos = intercepted.redos) !== null && _intercepted$redos !== void 0 ? _intercepted$redos : []);
5988
+ redos.unshift(...intercepted.preRedos ?? []);
5989
+ redos.push(...intercepted.redos ?? []);
6052
5990
  redos.push(followSelectionOperation(range, workbook, worksheet));
6053
- undos.unshift(...(_intercepted$preUndos = intercepted.preUndos) !== null && _intercepted$preUndos !== void 0 ? _intercepted$preUndos : []);
6054
- undos.push(...(_intercepted$undos = intercepted.undos) !== null && _intercepted$undos !== void 0 ? _intercepted$undos : []);
5991
+ undos.unshift(...intercepted.preUndos ?? []);
5992
+ undos.push(...intercepted.undos ?? []);
6055
5993
  if ((0, _univerjs_core.sequenceExecute)(redos, commandService).result) {
6056
5994
  const afterInterceptors = sheetInterceptorService.afterCommandExecute({
6057
5995
  id: InsertRowCommand.id,
@@ -6227,7 +6165,6 @@ const InsertColByRangeCommand = {
6227
6165
  type: _univerjs_core.CommandType.COMMAND,
6228
6166
  id: "sheet.command.insert-col-by-range",
6229
6167
  handler: (accessor, params) => {
6230
- var _intercepted$preRedos2, _intercepted$redos2, _intercepted$preUndos2, _intercepted$undos2;
6231
6168
  const target = getSheetCommandTarget(accessor.get(_univerjs_core.IUniverInstanceService), params);
6232
6169
  if (!target) throw new Error("Workbook or Worksheet not found at InsertColByRangeCommand");
6233
6170
  const { workbook, worksheet, unitId, subUnitId } = target;
@@ -6270,11 +6207,11 @@ const InsertColByRangeCommand = {
6270
6207
  id: InsertColCommand.id,
6271
6208
  params
6272
6209
  });
6273
- redos.unshift(...(_intercepted$preRedos2 = intercepted.preRedos) !== null && _intercepted$preRedos2 !== void 0 ? _intercepted$preRedos2 : []);
6274
- redos.push(...(_intercepted$redos2 = intercepted.redos) !== null && _intercepted$redos2 !== void 0 ? _intercepted$redos2 : []);
6210
+ redos.unshift(...intercepted.preRedos ?? []);
6211
+ redos.push(...intercepted.redos ?? []);
6275
6212
  redos.push(followSelectionOperation(range, workbook, worksheet));
6276
- undos.unshift(...(_intercepted$preUndos2 = intercepted.preUndos) !== null && _intercepted$preUndos2 !== void 0 ? _intercepted$preUndos2 : []);
6277
- undos.push(...(_intercepted$undos2 = intercepted.undos) !== null && _intercepted$undos2 !== void 0 ? _intercepted$undos2 : []);
6213
+ undos.unshift(...intercepted.preUndos ?? []);
6214
+ undos.push(...intercepted.undos ?? []);
6278
6215
  if ((0, _univerjs_core.sequenceExecute)(redos, commandService).result) {
6279
6216
  const afterInterceptors = sheetInterceptorService.afterCommandExecute({
6280
6217
  id: InsertColCommand.id,
@@ -6436,7 +6373,6 @@ const RemoveRowByRangeCommand = {
6436
6373
  type: _univerjs_core.CommandType.COMMAND,
6437
6374
  id: "sheet.command.remove-row-by-range",
6438
6375
  handler: (accessor, params) => {
6439
- var _intercepted$preRedos;
6440
6376
  if (!params) return false;
6441
6377
  const target = getSheetCommandTarget(accessor.get(_univerjs_core.IUniverInstanceService), params);
6442
6378
  if (!target) return false;
@@ -6455,10 +6391,11 @@ const RemoveRowByRangeCommand = {
6455
6391
  range: visibleRange
6456
6392
  };
6457
6393
  const undoRemoveRowsParams = RemoveRowsUndoMutationFactory(removeRowsParams, worksheet);
6394
+ const removedRows = worksheet.getCellMatrix().getSlice(visibleRange.startRow, visibleRange.endRow, 0, worksheet.getColumnCount() - 1);
6458
6395
  const undoSetRangeValuesParams = {
6459
6396
  unitId,
6460
6397
  subUnitId,
6461
- cellValue: worksheet.getCellMatrix().getSlice(visibleRange.startRow, visibleRange.endRow, 0, worksheet.getColumnCount() - 1).getMatrix()
6398
+ cellValue: removedRows.getMatrix()
6462
6399
  };
6463
6400
  redos.push({
6464
6401
  id: RemoveRowMutation.id,
@@ -6475,33 +6412,33 @@ const RemoveRowByRangeCommand = {
6475
6412
  redoMutations.push(...redos);
6476
6413
  undoMutations.unshift(...undos);
6477
6414
  });
6415
+ const interceptorParams = params;
6478
6416
  const intercepted = sheetInterceptorService.onCommandExecute({
6479
6417
  id: RemoveRowCommandId,
6480
- params: { range }
6418
+ params: interceptorParams
6481
6419
  });
6482
6420
  const commandService = accessor.get(_univerjs_core.ICommandService);
6483
6421
  if ((0, _univerjs_core.sequenceExecute)([
6484
- ...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : [],
6422
+ ...intercepted.preRedos ?? [],
6485
6423
  ...redoMutations,
6486
6424
  ...intercepted.redos
6487
6425
  ], commandService).result) {
6488
- var _intercepted$preUndos, _intercepted$preRedos2;
6489
6426
  setSelection(range, workbook, worksheet, commandService);
6490
6427
  const afterInterceptors = sheetInterceptorService.afterCommandExecute({
6491
6428
  id: RemoveRowCommandId,
6492
- params: { range }
6429
+ params: interceptorParams
6493
6430
  });
6494
6431
  (0, _univerjs_core.sequenceExecute)(afterInterceptors.redos, commandService);
6495
6432
  accessor.get(_univerjs_core.IUndoRedoService).pushUndoRedo({
6496
6433
  unitID: unitId,
6497
6434
  undoMutations: [
6498
- ...(_intercepted$preUndos = intercepted.preUndos) !== null && _intercepted$preUndos !== void 0 ? _intercepted$preUndos : [],
6435
+ ...intercepted.preUndos ?? [],
6499
6436
  ...undoMutations,
6500
6437
  ...intercepted.undos,
6501
6438
  ...afterInterceptors.undos
6502
6439
  ],
6503
6440
  redoMutations: [
6504
- ...(_intercepted$preRedos2 = intercepted.preRedos) !== null && _intercepted$preRedos2 !== void 0 ? _intercepted$preRedos2 : [],
6441
+ ...intercepted.preRedos ?? [],
6505
6442
  ...redoMutations,
6506
6443
  ...intercepted.redos,
6507
6444
  ...afterInterceptors.redos
@@ -6535,7 +6472,11 @@ const RemoveRowCommand = {
6535
6472
  };
6536
6473
  if (!await sheetInterceptorService.beforeCommandExecute({
6537
6474
  id: RemoveRowCommand.id,
6538
- params: { range }
6475
+ params: {
6476
+ range,
6477
+ unitId,
6478
+ subUnitId
6479
+ }
6539
6480
  })) return false;
6540
6481
  return commandService.syncExecuteCommand(RemoveRowByRangeCommand.id, {
6541
6482
  range,
@@ -6549,7 +6490,6 @@ const RemoveColByRangeCommand = {
6549
6490
  type: _univerjs_core.CommandType.COMMAND,
6550
6491
  id: "sheet.command.remove-col-by-range",
6551
6492
  handler: (accessor, params) => {
6552
- var _intercepted$preRedos3;
6553
6493
  if (!params) return false;
6554
6494
  const target = getSheetCommandTarget(accessor.get(_univerjs_core.IUniverInstanceService), params);
6555
6495
  if (!target) return false;
@@ -6567,30 +6507,30 @@ const RemoveColByRangeCommand = {
6567
6507
  subUnitId,
6568
6508
  cellValue: worksheet.getCellMatrix().getSlice(0, worksheet.getRowCount() - 1, range.startColumn, range.endColumn).getMatrix()
6569
6509
  };
6510
+ const interceptorParams = params;
6570
6511
  const intercepted = sheetInterceptorService.onCommandExecute({
6571
6512
  id: RemoveColCommandId,
6572
- params: { range }
6513
+ params: interceptorParams
6573
6514
  });
6574
6515
  const commandService = accessor.get(_univerjs_core.ICommandService);
6575
6516
  if ((0, _univerjs_core.sequenceExecute)([
6576
- ...(_intercepted$preRedos3 = intercepted.preRedos) !== null && _intercepted$preRedos3 !== void 0 ? _intercepted$preRedos3 : [],
6517
+ ...intercepted.preRedos ?? [],
6577
6518
  {
6578
6519
  id: RemoveColMutation.id,
6579
6520
  params: removeColParams
6580
6521
  },
6581
6522
  ...intercepted.redos
6582
6523
  ], commandService).result) {
6583
- var _intercepted$preUndos2, _intercepted$preRedos4;
6584
6524
  setSelection(range, workbook, worksheet, commandService);
6585
6525
  const afterInterceptors = sheetInterceptorService.afterCommandExecute({
6586
6526
  id: RemoveColCommandId,
6587
- params: { range }
6527
+ params: interceptorParams
6588
6528
  });
6589
6529
  (0, _univerjs_core.sequenceExecute)(afterInterceptors.redos, commandService);
6590
6530
  accessor.get(_univerjs_core.IUndoRedoService).pushUndoRedo({
6591
6531
  unitID: unitId,
6592
6532
  undoMutations: [
6593
- ...(_intercepted$preUndos2 = intercepted.preUndos) !== null && _intercepted$preUndos2 !== void 0 ? _intercepted$preUndos2 : [],
6533
+ ...intercepted.preUndos ?? [],
6594
6534
  {
6595
6535
  id: InsertColMutation.id,
6596
6536
  params: undoRemoveColParams
@@ -6603,7 +6543,7 @@ const RemoveColByRangeCommand = {
6603
6543
  ...afterInterceptors.undos
6604
6544
  ],
6605
6545
  redoMutations: [
6606
- ...(_intercepted$preRedos4 = intercepted.preRedos) !== null && _intercepted$preRedos4 !== void 0 ? _intercepted$preRedos4 : [],
6546
+ ...intercepted.preRedos ?? [],
6607
6547
  {
6608
6548
  id: RemoveColMutation.id,
6609
6549
  params: removeColParams
@@ -6631,7 +6571,7 @@ const RemoveColCommand = {
6631
6571
  let range = params === null || params === void 0 ? void 0 : params.range;
6632
6572
  if (!range) range = (_selectionManagerServ2 = selectionManagerService.getCurrentLastSelection()) === null || _selectionManagerServ2 === void 0 ? void 0 : _selectionManagerServ2.range;
6633
6573
  if (!range) return false;
6634
- const target = getSheetCommandTarget(accessor.get(_univerjs_core.IUniverInstanceService));
6574
+ const target = getSheetCommandTarget(accessor.get(_univerjs_core.IUniverInstanceService), params);
6635
6575
  if (!target) return false;
6636
6576
  const { worksheet, subUnitId, unitId } = target;
6637
6577
  range = {
@@ -6641,7 +6581,11 @@ const RemoveColCommand = {
6641
6581
  };
6642
6582
  if (!await sheetInterceptorService.beforeCommandExecute({
6643
6583
  id: RemoveColCommand.id,
6644
- params: { range }
6584
+ params: {
6585
+ range,
6586
+ unitId,
6587
+ subUnitId
6588
+ }
6645
6589
  })) return false;
6646
6590
  return commandService.syncExecuteCommand(RemoveColByRangeCommand.id, {
6647
6591
  range,
@@ -6679,7 +6623,7 @@ const RemoveSheetMutation = {
6679
6623
  handler: (accessor, params) => {
6680
6624
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
6681
6625
  const { subUnitId, unitId } = params;
6682
- const workbook = univerInstanceService.getUniverSheetInstance(unitId);
6626
+ const workbook = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
6683
6627
  if (!workbook) return false;
6684
6628
  return workbook.removeSheet(subUnitId);
6685
6629
  }
@@ -6701,7 +6645,6 @@ const MoveRowsCommand = {
6701
6645
  id: MoveRowsCommandId,
6702
6646
  type: _univerjs_core.CommandType.COMMAND,
6703
6647
  handler: (accessor, params) => {
6704
- var _interceptorCommands$, _interceptorCommands$2;
6705
6648
  const selectionManagerService = accessor.get(SheetsSelectionsService);
6706
6649
  const { fromRange: { startRow: fromRow }, toRange: { startRow: toRow }, range } = params;
6707
6650
  const selections = range ? [covertRangeToSelection(range)] : selectionManagerService.getCurrentSelections();
@@ -6743,11 +6686,11 @@ const MoveRowsCommand = {
6743
6686
  id: MoveRowsCommand.id,
6744
6687
  params
6745
6688
  });
6746
- const redos = [...(_interceptorCommands$ = interceptorCommands.preRedos) !== null && _interceptorCommands$ !== void 0 ? _interceptorCommands$ : [], {
6689
+ const redos = [...interceptorCommands.preRedos ?? [], {
6747
6690
  id: MoveRowsMutation.id,
6748
6691
  params: moveRowsParams
6749
6692
  }];
6750
- const undos = [...(_interceptorCommands$2 = interceptorCommands.preUndos) !== null && _interceptorCommands$2 !== void 0 ? _interceptorCommands$2 : [], {
6693
+ const undos = [...interceptorCommands.preUndos ?? [], {
6751
6694
  id: MoveRowsMutation.id,
6752
6695
  params: undoMoveRowsParams
6753
6696
  }];
@@ -6813,7 +6756,6 @@ const MoveColsCommand = {
6813
6756
  id: MoveColsCommandId,
6814
6757
  type: _univerjs_core.CommandType.COMMAND,
6815
6758
  handler: (accessor, params) => {
6816
- var _interceptorCommands$3, _interceptorCommands$4;
6817
6759
  const selectionManagerService = accessor.get(SheetsSelectionsService);
6818
6760
  const { fromRange: { startColumn: fromCol }, toRange: { startColumn: toCol }, range } = params;
6819
6761
  const selections = range ? [covertRangeToSelection(range)] : selectionManagerService.getCurrentSelections();
@@ -6855,11 +6797,11 @@ const MoveColsCommand = {
6855
6797
  id: MoveColsCommand.id,
6856
6798
  params
6857
6799
  });
6858
- const redos = [...(_interceptorCommands$3 = interceptorCommands.preRedos) !== null && _interceptorCommands$3 !== void 0 ? _interceptorCommands$3 : [], {
6800
+ const redos = [...interceptorCommands.preRedos ?? [], {
6859
6801
  id: MoveColsMutation.id,
6860
6802
  params: moveColsParams
6861
6803
  }];
6862
- const undos = [...(_interceptorCommands$4 = interceptorCommands.preUndos) !== null && _interceptorCommands$4 !== void 0 ? _interceptorCommands$4 : [], {
6804
+ const undos = [...interceptorCommands.preUndos ?? [], {
6863
6805
  id: MoveColsMutation.id,
6864
6806
  params: undoMoveColsParams
6865
6807
  }];
@@ -6934,7 +6876,6 @@ const ReorderRangeCommand = {
6934
6876
  id: ReorderRangeCommandId,
6935
6877
  type: _univerjs_core.CommandType.COMMAND,
6936
6878
  handler: (accessor, params) => {
6937
- var _interceptorCommands$, _interceptorCommands$2;
6938
6879
  const { subUnitId, unitId, range, order } = params;
6939
6880
  const commandService = accessor.get(_univerjs_core.ICommandService);
6940
6881
  const reorderMutation = {
@@ -6956,12 +6897,12 @@ const ReorderRangeCommand = {
6956
6897
  params
6957
6898
  });
6958
6899
  const redos = [
6959
- ...(_interceptorCommands$ = interceptorCommands.preRedos) !== null && _interceptorCommands$ !== void 0 ? _interceptorCommands$ : [],
6900
+ ...interceptorCommands.preRedos ?? [],
6960
6901
  reorderMutation,
6961
6902
  ...interceptorCommands.redos
6962
6903
  ];
6963
6904
  const undos = [
6964
- ...(_interceptorCommands$2 = interceptorCommands.preUndos) !== null && _interceptorCommands$2 !== void 0 ? _interceptorCommands$2 : [],
6905
+ ...interceptorCommands.preUndos ?? [],
6965
6906
  undoReorderMutation,
6966
6907
  ...interceptorCommands.undos
6967
6908
  ];
@@ -7180,9 +7121,8 @@ const handleReorderRangeCommon = (param, targetRange) => {
7180
7121
  const cacheMatrix = new _univerjs_core.ObjectMatrix();
7181
7122
  _univerjs_core.Range.foreach(range, (row, col) => {
7182
7123
  if (Object.prototype.hasOwnProperty.call(order, row)) {
7183
- var _matrix$getValue;
7184
7124
  const targetRow = order[row];
7185
- const cloneCell = (_matrix$getValue = matrix.getValue(targetRow, col)) !== null && _matrix$getValue !== void 0 ? _matrix$getValue : 0;
7125
+ const cloneCell = matrix.getValue(targetRow, col) ?? 0;
7186
7126
  cacheMatrix.setValue(row, col, cloneCell);
7187
7127
  }
7188
7128
  });
@@ -7260,7 +7200,7 @@ const handleMoveRangeCommon = (param, targetRange) => {
7260
7200
  matrix.setValue(row, col, 1);
7261
7201
  });
7262
7202
  const fromMatrix = new _univerjs_core.ObjectMatrix();
7263
- const loopFromRange = _univerjs_core.Rectangle.getIntersects(fromRange, targetRange);
7203
+ const loopFromRange = (0, _univerjs_core.getIntersectRange)(fromRange, targetRange);
7264
7204
  loopFromRange && _univerjs_core.Range.foreach(loopFromRange, (row, col) => {
7265
7205
  if (matrix.getValue(row, col)) {
7266
7206
  matrix.setValue(row, col, void 0);
@@ -7276,10 +7216,9 @@ const handleMoveRangeCommon = (param, targetRange) => {
7276
7216
  endRow: toRange.endRow - rowOffset
7277
7217
  };
7278
7218
  loopToRange && _univerjs_core.Range.foreach(loopToRange, (row, col) => {
7279
- var _fromMatrix$getValue;
7280
7219
  const targetRow = row + rowOffset;
7281
7220
  const targetCol = col + columnOffset;
7282
- matrix.setValue(targetRow, targetCol, (_fromMatrix$getValue = fromMatrix.getValue(row, col)) !== null && _fromMatrix$getValue !== void 0 ? _fromMatrix$getValue : 0);
7221
+ matrix.setValue(targetRow, targetCol, fromMatrix.getValue(row, col) ?? 0);
7283
7222
  });
7284
7223
  return (0, _univerjs_core.queryObjectMatrix)(matrix, (value) => value === 1);
7285
7224
  };
@@ -7290,7 +7229,7 @@ const handleBaseRemoveRange = (_removeRange, _targetRange) => {
7290
7229
  const getRowLength = (range) => range.endRow - range.startRow + 1;
7291
7230
  if (removeRange.startRow <= targetRange.startRow && removeRange.endRow >= targetRange.endRow) {
7292
7231
  if (targetRange.startColumn < removeRange.startColumn && targetRange.endColumn >= removeRange.startColumn && targetRange.endColumn <= removeRange.endColumn || targetRange.startColumn < removeRange.startColumn && targetRange.endColumn >= removeRange.endColumn) {
7293
- const intersectedRange = _univerjs_core.Rectangle.getIntersects(targetRange, removeRange);
7232
+ const intersectedRange = (0, _univerjs_core.getIntersectRange)(targetRange, removeRange);
7294
7233
  if (intersectedRange) return {
7295
7234
  step: 0,
7296
7235
  length: -getLength(intersectedRange)
@@ -7298,7 +7237,7 @@ const handleBaseRemoveRange = (_removeRange, _targetRange) => {
7298
7237
  }
7299
7238
  if (targetRange.startColumn >= removeRange.startColumn && targetRange.endColumn <= removeRange.endColumn && getRowLength(removeRange) >= getRowLength(targetRange)) return null;
7300
7239
  if (targetRange.startColumn >= removeRange.startColumn && targetRange.startColumn <= removeRange.endColumn && targetRange.endColumn > removeRange.endColumn) {
7301
- const intersectedRange = _univerjs_core.Rectangle.getIntersects(targetRange, removeRange);
7240
+ const intersectedRange = (0, _univerjs_core.getIntersectRange)(targetRange, removeRange);
7302
7241
  if (intersectedRange) {
7303
7242
  const length = -getLength(intersectedRange);
7304
7243
  return {
@@ -7489,7 +7428,7 @@ const handleInsertRangeMoveDownCommon = (param, targetRange) => {
7489
7428
  endRow: Number.POSITIVE_INFINITY
7490
7429
  };
7491
7430
  const noMoveRanges = _univerjs_core.Rectangle.subtract(targetRange, bottomRange);
7492
- const targetMoveRange = _univerjs_core.Rectangle.getIntersects(bottomRange, targetRange);
7431
+ const targetMoveRange = (0, _univerjs_core.getIntersectRange)(bottomRange, targetRange);
7493
7432
  if (!targetMoveRange) return [targetRange];
7494
7433
  const matrix = new _univerjs_core.ObjectMatrix();
7495
7434
  noMoveRanges.forEach((noMoveRange) => {
@@ -7526,7 +7465,7 @@ const handleInsertRangeMoveRightCommon = (param, targetRange) => {
7526
7465
  endColumn: Number.POSITIVE_INFINITY
7527
7466
  };
7528
7467
  const noMoveRanges = _univerjs_core.Rectangle.subtract(targetRange, bottomRange);
7529
- const targetMoveRange = _univerjs_core.Rectangle.getIntersects(bottomRange, targetRange);
7468
+ const targetMoveRange = (0, _univerjs_core.getIntersectRange)(bottomRange, targetRange);
7530
7469
  if (!targetMoveRange) return [targetRange];
7531
7470
  const matrix = new _univerjs_core.ObjectMatrix();
7532
7471
  noMoveRanges.forEach((noMoveRange) => {
@@ -7567,9 +7506,9 @@ const handleDeleteRangeMoveLeftCommon = (param, targetRange) => {
7567
7506
  endColumn: Number.POSITIVE_INFINITY
7568
7507
  };
7569
7508
  const moveCount = range.endColumn - range.startColumn + 1;
7570
- const targetDeleteRange = _univerjs_core.Rectangle.getIntersects(range, targetRange);
7509
+ const targetDeleteRange = (0, _univerjs_core.getIntersectRange)(range, targetRange);
7571
7510
  const noMoveRanges = _univerjs_core.Rectangle.subtract(targetRange, rightRange);
7572
- const targetMoveRange = _univerjs_core.Rectangle.getIntersects(rightRange, targetRange);
7511
+ const targetMoveRange = (0, _univerjs_core.getIntersectRange)(rightRange, targetRange);
7573
7512
  if (!targetDeleteRange && !targetMoveRange) return [targetRange];
7574
7513
  const matrix = new _univerjs_core.ObjectMatrix();
7575
7514
  targetMoveRange && _univerjs_core.Range.foreach(targetMoveRange, (row, col) => {
@@ -7612,9 +7551,9 @@ const handleDeleteRangeMoveUpCommon = (param, targetRange) => {
7612
7551
  endRow: Number.POSITIVE_INFINITY
7613
7552
  };
7614
7553
  const moveCount = range.endRow - range.startRow + 1;
7615
- const targetDeleteRange = _univerjs_core.Rectangle.getIntersects(range, targetRange);
7554
+ const targetDeleteRange = (0, _univerjs_core.getIntersectRange)(range, targetRange);
7616
7555
  const noMoveRanges = _univerjs_core.Rectangle.subtract(targetRange, bottomRange);
7617
- const targetMoveRange = _univerjs_core.Rectangle.getIntersects(bottomRange, targetRange);
7556
+ const targetMoveRange = (0, _univerjs_core.getIntersectRange)(bottomRange, targetRange);
7618
7557
  if (!targetDeleteRange && !targetMoveRange) return [targetRange];
7619
7558
  const matrix = new _univerjs_core.ObjectMatrix();
7620
7559
  targetMoveRange && _univerjs_core.Range.foreach(targetMoveRange, (row, col) => {
@@ -7631,8 +7570,7 @@ const handleDeleteRangeMoveUpCommon = (param, targetRange) => {
7631
7570
  return (0, _univerjs_core.queryObjectMatrix)(matrix, (v) => v === 1);
7632
7571
  };
7633
7572
  const handleRemoveRowCommon = (param, targetRange) => {
7634
- var _param$ranges;
7635
- const mergedRemoved = (0, _univerjs_core.mergeIntervals)(((_param$ranges = param.ranges) !== null && _param$ranges !== void 0 ? _param$ranges : [param.range]).map((range) => [range.startRow, range.endRow]));
7573
+ const mergedRemoved = (0, _univerjs_core.mergeIntervals)((param.ranges ?? [param.range]).map((range) => [range.startRow, range.endRow]));
7636
7574
  let targetStartRow = targetRange.startRow;
7637
7575
  let targetEndRow = targetRange.endRow;
7638
7576
  for (let i = mergedRemoved.length - 1; i >= 0; i--) {
@@ -8092,7 +8030,7 @@ function getSeparateEffectedRangesOnCommand(accessor, command) {
8092
8030
  }
8093
8031
  case EffectRefRangId.RemoveRowCommandId: {
8094
8032
  const params = command.params;
8095
- const target = getSheetCommandTarget(univerInstanceService);
8033
+ const target = getSheetCommandTarget(univerInstanceService, params);
8096
8034
  if (!target) return;
8097
8035
  const { worksheet, unitId, subUnitId } = target;
8098
8036
  const { range } = params;
@@ -8108,7 +8046,7 @@ function getSeparateEffectedRangesOnCommand(accessor, command) {
8108
8046
  }
8109
8047
  case EffectRefRangId.RemoveColCommandId: {
8110
8048
  const params = command.params;
8111
- const target = getSheetCommandTarget(univerInstanceService);
8049
+ const target = getSheetCommandTarget(univerInstanceService, params);
8112
8050
  if (!target) return;
8113
8051
  const { worksheet, unitId, subUnitId } = target;
8114
8052
  const { range } = params;
@@ -8183,8 +8121,9 @@ function getSeparateEffectedRangesOnCommand(accessor, command) {
8183
8121
  const MERGE_REDO = (0, _univerjs_core.createInterceptorKey)("MERGE_REDO");
8184
8122
  const MERGE_UNDO = (0, _univerjs_core.createInterceptorKey)("MERGE_UNDO");
8185
8123
  var WatchRange = class extends _univerjs_core.Disposable {
8186
- constructor(_unitId, _subUnitId, _range, _callback, _skipIntersects = false) {
8124
+ constructor(revision, _unitId, _subUnitId, _range, _callback, _skipIntersects = false) {
8187
8125
  super();
8126
+ this.revision = revision;
8188
8127
  this._unitId = _unitId;
8189
8128
  this._subUnitId = _subUnitId;
8190
8129
  this._range = _range;
@@ -8223,6 +8162,8 @@ let RefRangeService = class RefRangeService extends _univerjs_core.Disposable {
8223
8162
  MERGE_UNDO
8224
8163
  }));
8225
8164
  _defineProperty(this, "_watchRanges", /* @__PURE__ */ new Set());
8165
+ _defineProperty(this, "_watchRangesListener", null);
8166
+ _defineProperty(this, "_watchRangeRevision", 0);
8226
8167
  _defineProperty(this, "_refRangeManagerMap", /* @__PURE__ */ new Map());
8227
8168
  _defineProperty(this, "_serializer", createRangeSerializer());
8228
8169
  _defineProperty(this, "_onRefRangeChange", () => {
@@ -8254,15 +8195,14 @@ let RefRangeService = class RefRangeService extends _univerjs_core.Disposable {
8254
8195
  }], unitId, subUnitId);
8255
8196
  }
8256
8197
  case EffectRefRangId.MoveRangeCommandId: {
8257
- var _params$toUnitId, _params$toSubUnitId;
8258
8198
  const params = command.params;
8259
8199
  const sourceTarget = getSheetCommandTarget(this._univerInstanceService, {
8260
8200
  unitId: params.fromUnitId,
8261
8201
  subUnitId: params.fromSubUnitId
8262
8202
  });
8263
8203
  const destinationTarget = getSheetCommandTarget(this._univerInstanceService, {
8264
- unitId: (_params$toUnitId = params.toUnitId) !== null && _params$toUnitId !== void 0 ? _params$toUnitId : params.fromUnitId,
8265
- subUnitId: (_params$toSubUnitId = params.toSubUnitId) !== null && _params$toSubUnitId !== void 0 ? _params$toSubUnitId : params.fromSubUnitId
8204
+ unitId: params.toUnitId ?? params.fromUnitId,
8205
+ subUnitId: params.toSubUnitId ?? params.fromSubUnitId
8266
8206
  });
8267
8207
  if (!sourceTarget && !destinationTarget) return [];
8268
8208
  if (sourceTarget && destinationTarget && sourceTarget.unitId === destinationTarget.unitId && sourceTarget.subUnitId === destinationTarget.subUnitId) return this._checkRange([params.fromRange, params.toRange], sourceTarget.unitId, sourceTarget.subUnitId);
@@ -8301,7 +8241,7 @@ let RefRangeService = class RefRangeService extends _univerjs_core.Disposable {
8301
8241
  }
8302
8242
  case EffectRefRangId.RemoveRowCommandId: {
8303
8243
  const params = command.params;
8304
- const target = getSheetCommandTarget(this._univerInstanceService);
8244
+ const target = getSheetCommandTarget(this._univerInstanceService, params);
8305
8245
  if (!target) return [];
8306
8246
  const { worksheet, unitId, subUnitId } = target;
8307
8247
  const effectRange = {
@@ -8315,7 +8255,7 @@ let RefRangeService = class RefRangeService extends _univerjs_core.Disposable {
8315
8255
  }
8316
8256
  case EffectRefRangId.RemoveColCommandId: {
8317
8257
  const params = command.params;
8318
- const target = getSheetCommandTarget(this._univerInstanceService);
8258
+ const target = getSheetCommandTarget(this._univerInstanceService, params);
8319
8259
  if (!target) return [];
8320
8260
  const { worksheet, unitId, subUnitId } = target;
8321
8261
  const effectRange = {
@@ -8380,11 +8320,10 @@ let RefRangeService = class RefRangeService extends _univerjs_core.Disposable {
8380
8320
  result.push(v);
8381
8321
  return result;
8382
8322
  }, []).reduce((result, currentValue) => {
8383
- var _currentValue$preRedo, _currentValue$preUndo;
8384
8323
  result.redos.push(...currentValue.redos);
8385
8324
  result.undos.push(...currentValue.undos);
8386
- result.preRedos.push(...(_currentValue$preRedo = currentValue.preRedos) !== null && _currentValue$preRedo !== void 0 ? _currentValue$preRedo : []);
8387
- result.preUndos.push(...(_currentValue$preUndo = currentValue.preUndos) !== null && _currentValue$preUndo !== void 0 ? _currentValue$preUndo : []);
8325
+ result.preRedos.push(...currentValue.preRedos ?? []);
8326
+ result.preUndos.push(...currentValue.preUndos ?? []);
8388
8327
  return result;
8389
8328
  }, {
8390
8329
  redos: [],
@@ -8475,18 +8414,22 @@ let RefRangeService = class RefRangeService extends _univerjs_core.Disposable {
8475
8414
  });
8476
8415
  }
8477
8416
  watchRange(unitId, subUnitId, range, callback, skipIntersects) {
8478
- let watchRangesListener;
8479
- if (this._watchRanges.size === 0) watchRangesListener = this._commandService.onCommandExecuted((command) => {
8417
+ if (!this._watchRangesListener) this._watchRangesListener = this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
8480
8418
  if (command.type !== _univerjs_core.CommandType.MUTATION) return false;
8481
- for (const watchRange of this._watchRanges) watchRange.onMutation(command);
8482
- });
8483
- const watchRange = new WatchRange(unitId, subUnitId, range, callback, skipIntersects);
8419
+ const revision = this._watchRangeRevision;
8420
+ for (const watchRange of this._watchRanges) {
8421
+ if (watchRange.revision > revision) continue;
8422
+ watchRange.onMutation(command);
8423
+ }
8424
+ }));
8425
+ const watchRange = new WatchRange(++this._watchRangeRevision, unitId, subUnitId, range, callback, skipIntersects);
8484
8426
  this._watchRanges.add(watchRange);
8485
8427
  const teardownWatching = (0, _univerjs_core.toDisposable)(() => {
8486
8428
  this._watchRanges.delete(watchRange);
8487
8429
  if (this._watchRanges.size === 0) {
8488
- watchRangesListener === null || watchRangesListener === void 0 || watchRangesListener.dispose();
8489
- watchRangesListener = null;
8430
+ var _this$_watchRangesLis;
8431
+ (_this$_watchRangesLis = this._watchRangesListener) === null || _this$_watchRangesLis === void 0 || _this$_watchRangesLis.dispose();
8432
+ this._watchRangesListener = null;
8490
8433
  }
8491
8434
  });
8492
8435
  const registerToService = this.disposeWithMe(teardownWatching);
@@ -8744,7 +8687,7 @@ let MergeCellController = class MergeCellController extends _univerjs_core.Dispo
8744
8687
  }
8745
8688
  _onRefRangeChange() {
8746
8689
  const registerRefRange = (unitId, subUnitId) => {
8747
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
8690
+ const workbook = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
8748
8691
  if (!workbook) return;
8749
8692
  const workSheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
8750
8693
  if (!workSheet) return;
@@ -8880,11 +8823,10 @@ let MergeCellController = class MergeCellController extends _univerjs_core.Dispo
8880
8823
  };
8881
8824
  }
8882
8825
  _handleMoveRangeCommand(params, unitId, subUnitId) {
8883
- var _params$fromSubUnitId, _params$toSubUnitId;
8884
8826
  const workbook = getWorkbook(this._univerInstanceService, unitId);
8885
8827
  if (!workbook) return this._handleNull();
8886
- const sourceSubUnitId = (_params$fromSubUnitId = params.fromSubUnitId) !== null && _params$fromSubUnitId !== void 0 ? _params$fromSubUnitId : subUnitId;
8887
- const targetSubUnitId = (_params$toSubUnitId = params.toSubUnitId) !== null && _params$toSubUnitId !== void 0 ? _params$toSubUnitId : sourceSubUnitId;
8828
+ const sourceSubUnitId = params.fromSubUnitId ?? subUnitId;
8829
+ const targetSubUnitId = params.toSubUnitId ?? sourceSubUnitId;
8888
8830
  const sourceWorksheet = getWorksheet(workbook, sourceSubUnitId);
8889
8831
  const targetWorksheet = getWorksheet(workbook, targetSubUnitId);
8890
8832
  if (!sourceWorksheet || !targetWorksheet) return this._handleNull();
@@ -9444,7 +9386,7 @@ let MergeCellController = class MergeCellController extends _univerjs_core.Dispo
9444
9386
  this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
9445
9387
  if (mutationIdArrByMove$1.includes(command.id)) {
9446
9388
  if (!command.params) return;
9447
- const workbook = this._univerInstanceService.getUniverSheetInstance(command.params.unitId);
9389
+ const workbook = this._univerInstanceService.getUnit(command.params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
9448
9390
  if (!workbook) return;
9449
9391
  const worksheet = workbook.getSheetBySheetId(command.params.subUnitId);
9450
9392
  if (!worksheet) return;
@@ -9493,7 +9435,7 @@ let MergeCellController = class MergeCellController extends _univerjs_core.Dispo
9493
9435
  });
9494
9436
  }
9495
9437
  if (mutationIdByRowCol$1.includes(command.id)) {
9496
- const workbook = this._univerInstanceService.getUniverSheetInstance(command.params.unitId);
9438
+ const workbook = this._univerInstanceService.getUnit(command.params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
9497
9439
  if (!workbook) return;
9498
9440
  const worksheet = workbook.getSheetBySheetId(command.params.subUnitId);
9499
9441
  if (!worksheet) return;
@@ -9558,7 +9500,7 @@ MergeCellController = __decorate([
9558
9500
  __decorateParam(5, (0, _univerjs_core.Inject)(SheetsSelectionsService))
9559
9501
  ], MergeCellController);
9560
9502
  function getWorkbook(univerInstanceService, unitId) {
9561
- if (unitId) return univerInstanceService.getUniverSheetInstance(unitId);
9503
+ if (unitId) return univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
9562
9504
  return univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
9563
9505
  }
9564
9506
  function getWorksheet(workbook, subUnitId) {
@@ -9774,10 +9716,11 @@ function getClearContentMutationParamsForRanges(accessor, unitId, worksheet, ran
9774
9716
  const redos = [];
9775
9717
  const subUnitId = worksheet.getSheetId();
9776
9718
  ranges.forEach((range) => {
9719
+ const redoMatrix = getClearContentMutationParamForRange(worksheet, range);
9777
9720
  const redoMutationParams = {
9778
9721
  unitId,
9779
9722
  subUnitId,
9780
- cellValue: getClearContentMutationParamForRange(worksheet, range).getData()
9723
+ cellValue: redoMatrix.clone()
9781
9724
  };
9782
9725
  const undoMutationParams = SetRangeValuesUndoMutationFactory(accessor, redoMutationParams);
9783
9726
  undos.push({
@@ -9801,8 +9744,8 @@ function getClearContentMutationParamForRange(worksheet, range) {
9801
9744
  let leftTopCellValue = null;
9802
9745
  cellMatrix.forValue((row, col, cellData) => {
9803
9746
  if (cellData && row >= startRow && col >= startColumn) {
9804
- var _cellData$p$body$data, _cellData$p;
9805
- if (!leftTopCellValue && worksheet.cellHasValue(cellData) && (cellData.v !== "" || ((_cellData$p$body$data = (_cellData$p = cellData.p) === null || _cellData$p === void 0 || (_cellData$p = _cellData$p.body) === null || _cellData$p === void 0 || (_cellData$p = _cellData$p.dataStream) === null || _cellData$p === void 0 ? void 0 : _cellData$p.length) !== null && _cellData$p$body$data !== void 0 ? _cellData$p$body$data : 0) > 2)) leftTopCellValue = cellData;
9747
+ var _cellData$p;
9748
+ if (!leftTopCellValue && worksheet.cellHasValue(cellData) && (cellData.v !== "" || (((_cellData$p = cellData.p) === null || _cellData$p === void 0 || (_cellData$p = _cellData$p.body) === null || _cellData$p === void 0 || (_cellData$p = _cellData$p.dataStream) === null || _cellData$p === void 0 ? void 0 : _cellData$p.length) ?? 0) > 2)) leftTopCellValue = cellData;
9806
9749
  redoMatrix.setValue(row, col, cellData.s ? {
9807
9750
  v: null,
9808
9751
  t: null,
@@ -11565,7 +11508,8 @@ const AutoFillRules = {
11565
11508
  const dataNumArr = [];
11566
11509
  for (let i = 0; i < data.length; i++) {
11567
11510
  var _data$i;
11568
- const matchResult = matchExtendNumber(`${(_data$i = data[i]) === null || _data$i === void 0 ? void 0 : _data$i.v}`);
11511
+ const txt = `${(_data$i = data[i]) === null || _data$i === void 0 ? void 0 : _data$i.v}`;
11512
+ const matchResult = matchExtendNumber(txt);
11569
11513
  if (matchResult.isExtendNumber) dataNumArr.push(matchResult.matchNumber);
11570
11514
  }
11571
11515
  if (isReverse) {
@@ -11631,9 +11575,11 @@ const AutoFillRules = {
11631
11575
  if (isEqualDiff(dataNumArr)) {
11632
11576
  if (hasWeek || dataNumArr[dataNumArr.length - 1] < 6 && dataNumArr[0] > 0 || dataNumArr[0] < 6 && dataNumArr[dataNumArr.length - 1] > 0) {
11633
11577
  const dataLen = data.length;
11634
- return reverseIfNeed(fillChnWeek(data, len, dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2]), isReverse);
11578
+ const step = dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2];
11579
+ return reverseIfNeed(fillChnWeek(data, len, step), isReverse);
11635
11580
  }
11636
- return reverseIfNeed(fillChnNumber(data, len, dataNumArr[1] - dataNumArr[0]), isReverse);
11581
+ const step = dataNumArr[1] - dataNumArr[0];
11582
+ return reverseIfNeed(fillChnNumber(data, len, step), isReverse);
11637
11583
  }
11638
11584
  return fillCopy$1(data, len);
11639
11585
  } }
@@ -11674,7 +11620,8 @@ const AutoFillRules = {
11674
11620
  }
11675
11621
  if (isEqualDiff(dataNumArr)) {
11676
11622
  const dataLen = data.length;
11677
- return reverseIfNeed(fillChnWeek(data, len, dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2], 1), isReverse);
11623
+ const step = dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2];
11624
+ return reverseIfNeed(fillChnWeek(data, len, step, 1), isReverse);
11678
11625
  }
11679
11626
  return fillCopy$1(data, len);
11680
11627
  } }
@@ -11714,7 +11661,8 @@ const AutoFillRules = {
11714
11661
  }
11715
11662
  if (isEqualDiff(dataNumArr)) {
11716
11663
  const dataLen = data.length;
11717
- return reverseIfNeed(fillChnWeek(data, len, dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2], 2), isReverse);
11664
+ const step = dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2];
11665
+ return reverseIfNeed(fillChnWeek(data, len, step, 2), isReverse);
11718
11666
  }
11719
11667
  return fillCopy$1(data, len);
11720
11668
  } }
@@ -11759,7 +11707,8 @@ const AutoFillRules = {
11759
11707
  }
11760
11708
  if (isEqualDiff(dataNumArr)) {
11761
11709
  const dataLen = data.length;
11762
- return reverseIfNeed(fillLoopSeries(data, len, dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2], series), isReverse);
11710
+ const step = dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2];
11711
+ return reverseIfNeed(fillLoopSeries(data, len, step, series), isReverse);
11763
11712
  }
11764
11713
  return fillCopy$1(data, len);
11765
11714
  } }
@@ -12551,7 +12500,7 @@ const InsertSheetMutation = {
12551
12500
  handler: (accessor, params) => {
12552
12501
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
12553
12502
  const { sheet, index, unitId, styles } = params;
12554
- const workbook = univerInstanceService.getUniverSheetInstance(unitId);
12503
+ const workbook = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
12555
12504
  if (!workbook) return false;
12556
12505
  if (styles) workbook.addStyles(styles);
12557
12506
  return workbook.addWorksheet(sheet.id, index, (0, _univerjs_core.cloneWorksheetData)(sheet));
@@ -12619,7 +12568,6 @@ function splitCellDataIntoBatches(unitId, subUnitId, cellData, batchSize) {
12619
12568
  }
12620
12569
  const COPY_SHEET_COMMAND_ID = "sheet.command.copy-sheet";
12621
12570
  function buildCopySheetMutations(accessor, workbook, worksheet, unitId, subUnitId, localeService, sheetInterceptorService) {
12622
- var _intercepted$preRedos, _intercepted$preUndos;
12623
12571
  const pluginConfig = accessor.get(_univerjs_core.IConfigService).getConfig(SHEETS_PLUGIN_CONFIG_KEY);
12624
12572
  const largeSheetConfig = {
12625
12573
  ...defaultLargeSheetOperationConfig,
@@ -12664,7 +12612,7 @@ function buildCopySheetMutations(accessor, workbook, worksheet, unitId, subUnitI
12664
12612
  });
12665
12613
  return {
12666
12614
  redos: [
12667
- ...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : [],
12615
+ ...intercepted.preRedos ?? [],
12668
12616
  {
12669
12617
  id: InsertSheetMutation.id,
12670
12618
  params: insertSheetMutationParams
@@ -12672,7 +12620,7 @@ function buildCopySheetMutations(accessor, workbook, worksheet, unitId, subUnitI
12672
12620
  ...intercepted.redos
12673
12621
  ],
12674
12622
  undos: [
12675
- ...(_intercepted$preUndos = intercepted.preUndos) !== null && _intercepted$preUndos !== void 0 ? _intercepted$preUndos : [],
12623
+ ...intercepted.preUndos ?? [],
12676
12624
  {
12677
12625
  id: RemoveSheetMutation.id,
12678
12626
  params: removeSheetMutationParams
@@ -12887,8 +12835,7 @@ const InsertSheetCommand = {
12887
12835
  const sheetName = sheet === null || sheet === void 0 ? void 0 : sheet.name;
12888
12836
  const sheetConfig = (0, _univerjs_core.mergeWorksheetSnapshotWithDefault)(sheet || {});
12889
12837
  if (params) {
12890
- var _params$index;
12891
- index = (_params$index = params.index) !== null && _params$index !== void 0 ? _params$index : index;
12838
+ index = params.index ?? index;
12892
12839
  sheetConfig.id = sheetId || (0, _univerjs_core.generateRandomId)();
12893
12840
  sheetConfig.name = sheetName ? workbook.uniqueSheetName(sheetName) : workbook.generateNewSheetName(`${localeService.t("sheets.tabs.sheet")}`);
12894
12841
  } else {
@@ -13003,7 +12950,6 @@ const RemoveDefinedNameCommand = {
13003
12950
  id: "sheet.command.remove-defined-name",
13004
12951
  type: _univerjs_core.CommandType.COMMAND,
13005
12952
  handler: (accessor, params) => {
13006
- var _interceptorCommands$, _interceptorCommands$2;
13007
12953
  const commandService = accessor.get(_univerjs_core.ICommandService);
13008
12954
  const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
13009
12955
  const sheetInterceptorService = accessor.get(SheetInterceptorService);
@@ -13014,7 +12960,7 @@ const RemoveDefinedNameCommand = {
13014
12960
  params
13015
12961
  });
13016
12962
  const redos = [
13017
- ...(_interceptorCommands$ = interceptorCommands.preRedos) !== null && _interceptorCommands$ !== void 0 ? _interceptorCommands$ : [],
12963
+ ...interceptorCommands.preRedos ?? [],
13018
12964
  {
13019
12965
  id: _univerjs_engine_formula.RemoveDefinedNameMutation.id,
13020
12966
  params: removeSheetMutationParams
@@ -13022,7 +12968,7 @@ const RemoveDefinedNameCommand = {
13022
12968
  ...interceptorCommands.redos
13023
12969
  ];
13024
12970
  const undos = [
13025
- ...(_interceptorCommands$2 = interceptorCommands.preUndos) !== null && _interceptorCommands$2 !== void 0 ? _interceptorCommands$2 : [],
12971
+ ...interceptorCommands.preUndos ?? [],
13026
12972
  {
13027
12973
  id: _univerjs_engine_formula.SetDefinedNameMutation.id,
13028
12974
  params: removeSheetMutationParams
@@ -13050,7 +12996,6 @@ const RemoveSheetCommand = {
13050
12996
  id: "sheet.command.remove-sheet",
13051
12997
  type: _univerjs_core.CommandType.COMMAND,
13052
12998
  handler: (accessor, params) => {
13053
- var _intercepted$preRedos, _intercepted$preUndos;
13054
12999
  const commandService = accessor.get(_univerjs_core.ICommandService);
13055
13000
  const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
13056
13001
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
@@ -13080,7 +13025,7 @@ const RemoveSheetCommand = {
13080
13025
  }
13081
13026
  });
13082
13027
  const redos = [
13083
- ...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : [],
13028
+ ...intercepted.preRedos ?? [],
13084
13029
  {
13085
13030
  id: RemoveSheetMutation.id,
13086
13031
  params: RemoveSheetMutationParams
@@ -13088,7 +13033,7 @@ const RemoveSheetCommand = {
13088
13033
  ...intercepted.redos
13089
13034
  ];
13090
13035
  const undos = isLargeSheet ? [] : [
13091
- ...(_intercepted$preUndos = intercepted.preUndos) !== null && _intercepted$preUndos !== void 0 ? _intercepted$preUndos : [],
13036
+ ...intercepted.preUndos ?? [],
13092
13037
  {
13093
13038
  id: InsertSheetMutation.id,
13094
13039
  params: InsertSheetMutationParams
@@ -13462,7 +13407,7 @@ const SetBorderCommand = {
13462
13407
  const setRangeValuesMutationParams = {
13463
13408
  unitId,
13464
13409
  subUnitId,
13465
- cellValue: mr.getData()
13410
+ cellValue: mr.clone()
13466
13411
  };
13467
13412
  const undoSetRangeValuesMutationParams = SetRangeValuesUndoMutationFactory(accessor, setRangeValuesMutationParams);
13468
13413
  if (commandService.syncExecuteCommand(SetRangeValuesMutation.id, setRangeValuesMutationParams)) {
@@ -13618,7 +13563,6 @@ const SetSpecificColsVisibleCommand = {
13618
13563
  });
13619
13564
  const interceptedResult = (0, _univerjs_core.sequenceExecute)([...intercepted.redos], commandService);
13620
13565
  if (result.result && interceptedResult.result) {
13621
- var _intercepted$undos, _intercepted$preRedos;
13622
13566
  const afterInterceptors = sheetInterceptorService.afterCommandExecute({
13623
13567
  id: SetSpecificColsVisibleCommand.id,
13624
13568
  params
@@ -13635,11 +13579,11 @@ const SetSpecificColsVisibleCommand = {
13635
13579
  id: SetSelectionsOperation.id,
13636
13580
  params: undoSetSelectionsOperationParams
13637
13581
  },
13638
- ...(_intercepted$undos = intercepted.undos) !== null && _intercepted$undos !== void 0 ? _intercepted$undos : [],
13582
+ ...intercepted.undos ?? [],
13639
13583
  ...afterInterceptors.undos
13640
13584
  ],
13641
13585
  redoMutations: [
13642
- ...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : [],
13586
+ ...intercepted.preRedos ?? [],
13643
13587
  {
13644
13588
  id: SetColVisibleMutation.id,
13645
13589
  params: redoMutationParams
@@ -13729,7 +13673,6 @@ const SetColHiddenCommand = {
13729
13673
  });
13730
13674
  const interceptedResult = (0, _univerjs_core.sequenceExecute)([...intercepted.redos], commandService);
13731
13675
  if (result.result && interceptedResult.result) {
13732
- var _intercepted$undos2, _intercepted$preRedos2;
13733
13676
  const afterInterceptors = sheetInterceptorService.afterCommandExecute({
13734
13677
  id: SetColHiddenCommand.id,
13735
13678
  params: redoMutationParams
@@ -13746,11 +13689,11 @@ const SetColHiddenCommand = {
13746
13689
  id: SetSelectionsOperation.id,
13747
13690
  params: undoSetSelectionsOperationParams
13748
13691
  },
13749
- ...(_intercepted$undos2 = intercepted.undos) !== null && _intercepted$undos2 !== void 0 ? _intercepted$undos2 : [],
13692
+ ...intercepted.undos ?? [],
13750
13693
  ...afterInterceptors.undos
13751
13694
  ],
13752
13695
  redoMutations: [
13753
- ...(_intercepted$preRedos2 = intercepted.preRedos) !== null && _intercepted$preRedos2 !== void 0 ? _intercepted$preRedos2 : [],
13696
+ ...intercepted.preRedos ?? [],
13754
13697
  {
13755
13698
  id: SetColHiddenMutation.id,
13756
13699
  params: redoMutationParams
@@ -13859,7 +13802,6 @@ const SetDefinedNameCommand = {
13859
13802
  id: "sheet.command.set-defined-name",
13860
13803
  type: _univerjs_core.CommandType.COMMAND,
13861
13804
  handler: (accessor, params) => {
13862
- var _interceptorCommands$, _interceptorCommands$2;
13863
13805
  const commandService = accessor.get(_univerjs_core.ICommandService);
13864
13806
  const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
13865
13807
  const sheetInterceptorService = accessor.get(SheetInterceptorService);
@@ -13871,7 +13813,7 @@ const SetDefinedNameCommand = {
13871
13813
  params
13872
13814
  });
13873
13815
  const redos = [
13874
- ...(_interceptorCommands$ = interceptorCommands.preRedos) !== null && _interceptorCommands$ !== void 0 ? _interceptorCommands$ : [],
13816
+ ...interceptorCommands.preRedos ?? [],
13875
13817
  ...oldDefinedNameMutationParams ? [{
13876
13818
  id: _univerjs_engine_formula.RemoveDefinedNameMutation.id,
13877
13819
  params: oldDefinedNameMutationParams
@@ -13883,7 +13825,7 @@ const SetDefinedNameCommand = {
13883
13825
  ...interceptorCommands.redos
13884
13826
  ];
13885
13827
  const undos = [
13886
- ...(_interceptorCommands$2 = interceptorCommands.preUndos) !== null && _interceptorCommands$2 !== void 0 ? _interceptorCommands$2 : [],
13828
+ ...interceptorCommands.preUndos ?? [],
13887
13829
  {
13888
13830
  id: _univerjs_engine_formula.RemoveDefinedNameMutation.id,
13889
13831
  params: newDefinedNameMutationParams
@@ -13909,7 +13851,7 @@ const SetDefinedNameCommand = {
13909
13851
  //#endregion
13910
13852
  //#region src/commands/mutations/set-frozen.mutation.ts
13911
13853
  const SetFrozenMutationFactory = (accessor, params) => {
13912
- const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId);
13854
+ const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
13913
13855
  if (universheet == null) throw new Error("universheet is null error!");
13914
13856
  const worksheet = universheet.getSheetBySheetId(params.subUnitId);
13915
13857
  if (worksheet == null) throw new Error("worksheet is null error!");
@@ -13924,7 +13866,7 @@ const SetFrozenMutation = {
13924
13866
  id: "sheet.mutation.set-frozen",
13925
13867
  type: _univerjs_core.CommandType.MUTATION,
13926
13868
  handler: (accessor, params) => {
13927
- const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId);
13869
+ const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
13928
13870
  if (universheet == null) throw new Error("universheet is null error!");
13929
13871
  const worksheet = universheet.getSheetBySheetId(params.subUnitId);
13930
13872
  if (!worksheet) return false;
@@ -14349,7 +14291,6 @@ const SetSpecificRowsVisibleCommand = {
14349
14291
  });
14350
14292
  const interceptedResult = (0, _univerjs_core.sequenceExecute)([...intercepted.redos], commandService);
14351
14293
  if (result.result && interceptedResult.result) {
14352
- var _intercepted$preUndos, _intercepted$undos, _intercepted$preRedos;
14353
14294
  const afterInterceptors = sheetInterceptorService.afterCommandExecute({
14354
14295
  id: SetSpecificRowsVisibleCommand.id,
14355
14296
  params
@@ -14358,7 +14299,7 @@ const SetSpecificRowsVisibleCommand = {
14358
14299
  undoRedoService.pushUndoRedo({
14359
14300
  unitID: unitId,
14360
14301
  undoMutations: [
14361
- ...(_intercepted$preUndos = intercepted.preUndos) !== null && _intercepted$preUndos !== void 0 ? _intercepted$preUndos : [],
14302
+ ...intercepted.preUndos ?? [],
14362
14303
  {
14363
14304
  id: SetRowHiddenMutation.id,
14364
14305
  params: undoMutationParams
@@ -14367,11 +14308,11 @@ const SetSpecificRowsVisibleCommand = {
14367
14308
  id: SetSelectionsOperation.id,
14368
14309
  params: undoSetSelectionsOperationParams
14369
14310
  },
14370
- ...(_intercepted$undos = intercepted.undos) !== null && _intercepted$undos !== void 0 ? _intercepted$undos : [],
14311
+ ...intercepted.undos ?? [],
14371
14312
  ...afterInterceptors.undos
14372
14313
  ],
14373
14314
  redoMutations: [
14374
- ...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : [],
14315
+ ...intercepted.preRedos ?? [],
14375
14316
  {
14376
14317
  id: SetRowVisibleMutation.id,
14377
14318
  params: redoMutationParams
@@ -14413,7 +14354,7 @@ const SetRowHiddenCommand = {
14413
14354
  type: _univerjs_core.CommandType.COMMAND,
14414
14355
  id: "sheet.command.set-rows-hidden",
14415
14356
  handler: (accessor, params) => {
14416
- var _params$ranges, _intercepted$preRedos2;
14357
+ var _params$ranges;
14417
14358
  const selectionManagerService = accessor.get(SheetsSelectionsService);
14418
14359
  const commandService = accessor.get(_univerjs_core.ICommandService);
14419
14360
  const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
@@ -14455,7 +14396,7 @@ const SetRowHiddenCommand = {
14455
14396
  params: redoMutationParams
14456
14397
  });
14457
14398
  if ((0, _univerjs_core.sequenceExecute)([
14458
- ...(_intercepted$preRedos2 = intercepted.preRedos) !== null && _intercepted$preRedos2 !== void 0 ? _intercepted$preRedos2 : [],
14399
+ ...intercepted.preRedos ?? [],
14459
14400
  {
14460
14401
  id: SetRowHiddenMutation.id,
14461
14402
  params: redoMutationParams
@@ -14466,7 +14407,6 @@ const SetRowHiddenCommand = {
14466
14407
  },
14467
14408
  ...intercepted.redos
14468
14409
  ], commandService).result) {
14469
- var _intercepted$preUndos2, _intercepted$undos2, _intercepted$preRedos3;
14470
14410
  const afterInterceptors = sheetInterceptorService.afterCommandExecute({
14471
14411
  id: SetRowHiddenCommand.id,
14472
14412
  params: redoMutationParams
@@ -14475,7 +14415,7 @@ const SetRowHiddenCommand = {
14475
14415
  undoRedoService.pushUndoRedo({
14476
14416
  unitID: unitId,
14477
14417
  undoMutations: [
14478
- ...(_intercepted$preUndos2 = intercepted.preUndos) !== null && _intercepted$preUndos2 !== void 0 ? _intercepted$preUndos2 : [],
14418
+ ...intercepted.preUndos ?? [],
14479
14419
  {
14480
14420
  id: SetRowVisibleMutation.id,
14481
14421
  params: undoMutationParams
@@ -14484,11 +14424,11 @@ const SetRowHiddenCommand = {
14484
14424
  id: SetSelectionsOperation.id,
14485
14425
  params: undoSetSelectionsOperationParams
14486
14426
  },
14487
- ...(_intercepted$undos2 = intercepted.undos) !== null && _intercepted$undos2 !== void 0 ? _intercepted$undos2 : [],
14427
+ ...intercepted.undos ?? [],
14488
14428
  ...afterInterceptors.undos
14489
14429
  ],
14490
14430
  redoMutations: [
14491
- ...(_intercepted$preRedos3 = intercepted.preRedos) !== null && _intercepted$preRedos3 !== void 0 ? _intercepted$preRedos3 : [],
14431
+ ...intercepted.preRedos ?? [],
14492
14432
  {
14493
14433
  id: SetRowHiddenMutation.id,
14494
14434
  params: redoMutationParams
@@ -14584,7 +14524,7 @@ function mergeSelections(ranges) {
14584
14524
  //#endregion
14585
14525
  //#region src/commands/mutations/set-tab-color.mutation.ts
14586
14526
  const SetTabColorUndoMutationFactory = (accessor, params) => {
14587
- const oldTabColor = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId).getSheetBySheetId(params.subUnitId).getConfig().tabColor;
14527
+ const oldTabColor = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET).getSheetBySheetId(params.subUnitId).getConfig().tabColor;
14588
14528
  return {
14589
14529
  ..._univerjs_core.Tools.deepClone(params),
14590
14530
  color: oldTabColor
@@ -14594,7 +14534,7 @@ const SetTabColorMutation = {
14594
14534
  id: "sheet.mutation.set-tab-color",
14595
14535
  type: _univerjs_core.CommandType.MUTATION,
14596
14536
  handler: (accessor, params) => {
14597
- const workbook = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId);
14537
+ const workbook = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
14598
14538
  if (!workbook) return false;
14599
14539
  const worksheet = workbook.getSheetBySheetId(params.subUnitId);
14600
14540
  if (!worksheet) return false;
@@ -14660,7 +14600,6 @@ const SetWorkbookNameCommand = {
14660
14600
  type: _univerjs_core.CommandType.COMMAND,
14661
14601
  id: "sheet.command.set-workbook-name",
14662
14602
  handler: (accessor, params) => {
14663
- var _interceptedCommands$;
14664
14603
  const commandService = accessor.get(_univerjs_core.ICommandService);
14665
14604
  const sheetInterceptorService = accessor.get(SheetInterceptorService);
14666
14605
  if (!getSheetCommandTargetWorkbook(accessor.get(_univerjs_core.IUniverInstanceService), params)) return false;
@@ -14673,7 +14612,7 @@ const SetWorkbookNameCommand = {
14673
14612
  unitId: params.unitId
14674
14613
  };
14675
14614
  return (0, _univerjs_core.sequenceExecute)([
14676
- ...(_interceptedCommands$ = interceptedCommands.preRedos) !== null && _interceptedCommands$ !== void 0 ? _interceptedCommands$ : [],
14615
+ ...interceptedCommands.preRedos ?? [],
14677
14616
  {
14678
14617
  id: SetWorkbookNameMutation.id,
14679
14618
  params: redoMutationParams
@@ -14849,7 +14788,6 @@ const SetColWidthCommand = {
14849
14788
  });
14850
14789
  const result = (0, _univerjs_core.sequenceExecute)([...intercepted.redos, ...autoHeightRedos], commandService);
14851
14790
  if (setColWidthResult && result.result) {
14852
- var _intercepted$preUndos, _intercepted$preRedos;
14853
14791
  const afterInterceptors = sheetInterceptorService.afterCommandExecute({
14854
14792
  id: SetColWidthCommand.id,
14855
14793
  params: redoMutationParams
@@ -14858,7 +14796,7 @@ const SetColWidthCommand = {
14858
14796
  undoRedoService.pushUndoRedo({
14859
14797
  unitID: unitId,
14860
14798
  undoMutations: [
14861
- ...(_intercepted$preUndos = intercepted.preUndos) !== null && _intercepted$preUndos !== void 0 ? _intercepted$preUndos : [],
14799
+ ...intercepted.preUndos ?? [],
14862
14800
  {
14863
14801
  id: SetWorksheetColWidthMutation.id,
14864
14802
  params: undoMutationParams
@@ -14868,7 +14806,7 @@ const SetColWidthCommand = {
14868
14806
  ...autoHeightUndos
14869
14807
  ],
14870
14808
  redoMutations: [
14871
- ...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : [],
14809
+ ...intercepted.preRedos ?? [],
14872
14810
  {
14873
14811
  id: SetWorksheetColWidthMutation.id,
14874
14812
  params: redoMutationParams
@@ -14999,7 +14937,7 @@ const SetWorksheetHideMutation = {
14999
14937
  id: "sheet.mutation.set-worksheet-hidden",
15000
14938
  type: _univerjs_core.CommandType.MUTATION,
15001
14939
  handler: (accessor, params) => {
15002
- const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId);
14940
+ const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
15003
14941
  if (universheet == null) return false;
15004
14942
  const worksheet = universheet.getSheetBySheetId(params.subUnitId);
15005
14943
  if (!worksheet) return false;
@@ -15066,7 +15004,7 @@ const SetWorksheetNameMutation = {
15066
15004
  id: "sheet.mutation.set-worksheet-name",
15067
15005
  type: _univerjs_core.CommandType.MUTATION,
15068
15006
  handler: (accessor, params) => {
15069
- const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId);
15007
+ const universheet = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
15070
15008
  if (universheet == null) return false;
15071
15009
  const worksheet = universheet.getSheetBySheetId(params.subUnitId);
15072
15010
  if (!worksheet) return false;
@@ -15084,7 +15022,6 @@ const SetWorksheetNameCommand = {
15084
15022
  type: _univerjs_core.CommandType.COMMAND,
15085
15023
  id: "sheet.command.set-worksheet-name",
15086
15024
  handler: (accessor, params) => {
15087
- var _interceptorCommands$, _interceptorCommands$2;
15088
15025
  const commandService = accessor.get(_univerjs_core.ICommandService);
15089
15026
  const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
15090
15027
  const sheetInterceptorService = accessor.get(SheetInterceptorService);
@@ -15102,7 +15039,7 @@ const SetWorksheetNameCommand = {
15102
15039
  params
15103
15040
  });
15104
15041
  const redos = [
15105
- ...(_interceptorCommands$ = interceptorCommands.preRedos) !== null && _interceptorCommands$ !== void 0 ? _interceptorCommands$ : [],
15042
+ ...interceptorCommands.preRedos ?? [],
15106
15043
  {
15107
15044
  id: SetWorksheetNameMutation.id,
15108
15045
  params: redoMutationParams
@@ -15110,7 +15047,7 @@ const SetWorksheetNameCommand = {
15110
15047
  ...interceptorCommands.redos
15111
15048
  ];
15112
15049
  const undos = [
15113
- ...(_interceptorCommands$2 = interceptorCommands.preUndos) !== null && _interceptorCommands$2 !== void 0 ? _interceptorCommands$2 : [],
15050
+ ...interceptorCommands.preUndos ?? [],
15114
15051
  {
15115
15052
  id: SetWorksheetNameMutation.id,
15116
15053
  params: undoMutationParams
@@ -15142,7 +15079,7 @@ const SetWorksheetOrderMutation = {
15142
15079
  id: "sheet.mutation.set-worksheet-order",
15143
15080
  type: _univerjs_core.CommandType.MUTATION,
15144
15081
  handler: (accessor, params) => {
15145
- const workbook = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId);
15082
+ const workbook = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
15146
15083
  if (!workbook) return false;
15147
15084
  const config = workbook.getConfig();
15148
15085
  config.sheetOrder.splice(params.fromOrder, 1);
@@ -16379,7 +16316,7 @@ const SetWorksheetProtectionCommand = {
16379
16316
  //#endregion
16380
16317
  //#region src/commands/mutations/set-worksheet-right-to-left.mutation.ts
16381
16318
  const SetWorksheetRightToLeftUndoMutationFactory = (accessor, params) => {
16382
- const oldState = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId).getSheetBySheetId(params.subUnitId).getConfig().rightToLeft;
16319
+ const oldState = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET).getSheetBySheetId(params.subUnitId).getConfig().rightToLeft;
16383
16320
  return {
16384
16321
  ..._univerjs_core.Tools.deepClone(params),
16385
16322
  rightToLeft: oldState
@@ -16389,7 +16326,7 @@ const SetWorksheetRightToLeftMutation = {
16389
16326
  id: "sheet.mutation.set-worksheet-right-to-left",
16390
16327
  type: _univerjs_core.CommandType.MUTATION,
16391
16328
  handler: (accessor, params) => {
16392
- const workbook = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId);
16329
+ const workbook = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
16393
16330
  if (!workbook) return false;
16394
16331
  const worksheet = workbook.getSheetBySheetId(params.subUnitId);
16395
16332
  if (!worksheet) return false;
@@ -16411,10 +16348,7 @@ const SetWorksheetRightToLeftCommand = {
16411
16348
  if (!target) return false;
16412
16349
  const { unitId, subUnitId } = target;
16413
16350
  let rightToLeft = _univerjs_core.BooleanNumber.FALSE;
16414
- if (params) {
16415
- var _params$rightToLeft;
16416
- rightToLeft = (_params$rightToLeft = params.rightToLeft) !== null && _params$rightToLeft !== void 0 ? _params$rightToLeft : _univerjs_core.BooleanNumber.FALSE;
16417
- }
16351
+ if (params) rightToLeft = params.rightToLeft ?? _univerjs_core.BooleanNumber.FALSE;
16418
16352
  const setWorksheetRightToLeftMutationParams = {
16419
16353
  rightToLeft,
16420
16354
  unitId,
@@ -16547,7 +16481,6 @@ const DeltaRowHeightCommand = {
16547
16481
  }], commandService);
16548
16482
  const interceptedResult = (0, _univerjs_core.sequenceExecute)([...intercepted.redos], commandService);
16549
16483
  if (result.result && interceptedResult.result) {
16550
- var _intercepted$preUndos, _intercepted$preRedos;
16551
16484
  const afterInterceptors = sheetInterceptorService.afterCommandExecute({
16552
16485
  id: DeltaRowHeightCommand.id,
16553
16486
  params: redoMutationParams
@@ -16556,7 +16489,7 @@ const DeltaRowHeightCommand = {
16556
16489
  undoRedoService.pushUndoRedo({
16557
16490
  unitID: unitId,
16558
16491
  undoMutations: [
16559
- ...(_intercepted$preUndos = intercepted.preUndos) !== null && _intercepted$preUndos !== void 0 ? _intercepted$preUndos : [],
16492
+ ...intercepted.preUndos ?? [],
16560
16493
  {
16561
16494
  id: SetWorksheetRowHeightMutation.id,
16562
16495
  params: undoMutationParams
@@ -16569,7 +16502,7 @@ const DeltaRowHeightCommand = {
16569
16502
  ...afterInterceptors.undos
16570
16503
  ],
16571
16504
  redoMutations: [
16572
- ...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : [],
16505
+ ...intercepted.preRedos ?? [],
16573
16506
  {
16574
16507
  id: SetWorksheetRowHeightMutation.id,
16575
16508
  params: redoMutationParams
@@ -16629,7 +16562,6 @@ const SetRowHeightCommand = {
16629
16562
  });
16630
16563
  const sheetInterceptorResult = (0, _univerjs_core.sequenceExecute)([...intercepted.redos], commandService);
16631
16564
  if (result.result && sheetInterceptorResult.result) {
16632
- var _intercepted$preRedos2, _intercepted$preRedos3;
16633
16565
  const afterInterceptors = sheetInterceptorService.afterCommandExecute({
16634
16566
  id: SetRowHeightCommand.id,
16635
16567
  params: redoMutationParams
@@ -16638,7 +16570,7 @@ const SetRowHeightCommand = {
16638
16570
  undoRedoService.pushUndoRedo({
16639
16571
  unitID: unitId,
16640
16572
  undoMutations: [
16641
- ...(_intercepted$preRedos2 = intercepted.preRedos) !== null && _intercepted$preRedos2 !== void 0 ? _intercepted$preRedos2 : [],
16573
+ ...intercepted.preRedos ?? [],
16642
16574
  {
16643
16575
  id: SetWorksheetRowHeightMutation.id,
16644
16576
  params: undoMutationParams
@@ -16651,7 +16583,7 @@ const SetRowHeightCommand = {
16651
16583
  ...afterInterceptors.undos
16652
16584
  ],
16653
16585
  redoMutations: [
16654
- ...(_intercepted$preRedos3 = intercepted.preRedos) !== null && _intercepted$preRedos3 !== void 0 ? _intercepted$preRedos3 : [],
16586
+ ...intercepted.preRedos ?? [],
16655
16587
  {
16656
16588
  id: SetWorksheetRowHeightMutation.id,
16657
16589
  params: redoMutationParams
@@ -17607,7 +17539,7 @@ let AutoFillController = class AutoFillController extends _univerjs_core.Disposa
17607
17539
  if (hasStyle) {
17608
17540
  var _this$_univerInstance5;
17609
17541
  const deleteMergeRanges = [];
17610
- 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();
17542
+ const mergeData = (_this$_univerInstance5 = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance5 === void 0 || (_this$_univerInstance5 = _this$_univerInstance5.getSheetBySheetId(subUnitId)) === null || _this$_univerInstance5 === void 0 ? void 0 : _this$_univerInstance5.getMergeData();
17611
17543
  if (mergeData) mergeData.forEach((merge) => {
17612
17544
  if (_univerjs_core.Rectangle.intersects(merge, targetRange)) deleteMergeRanges.push(merge);
17613
17545
  });
@@ -17724,7 +17656,7 @@ let CalculateResultApplyController = class CalculateResultApplyController extend
17724
17656
  const redoMutationsInfo = [];
17725
17657
  for (let i = 0; i < unitIds.length; i++) {
17726
17658
  const unitId = unitIds[i];
17727
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
17659
+ const workbook = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
17728
17660
  if (!workbook) continue;
17729
17661
  const sheetData = unitData[unitId];
17730
17662
  if (sheetData == null) continue;
@@ -17760,7 +17692,7 @@ let CalculateResultApplyController = class CalculateResultApplyController extend
17760
17692
  * @returns
17761
17693
  */
17762
17694
  _getMergedCellData(unitId, sheetId, cellData) {
17763
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
17695
+ const workbook = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
17764
17696
  const styles = workbook === null || workbook === void 0 ? void 0 : workbook.getStyles();
17765
17697
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(sheetId);
17766
17698
  const oldCellDataMatrix = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getCellMatrix();
@@ -17851,14 +17783,14 @@ const effectedByOnlyLocalMutationIds = [
17851
17783
  ];
17852
17784
  let SheetsFreezeSyncController = class SheetsFreezeSyncController extends _univerjs_core.Disposable {
17853
17785
  constructor(_univerInstanceService, _commandService, _configService) {
17854
- var _this$_configService$, _this$_configService$2;
17786
+ var _this$_configService$;
17855
17787
  super();
17856
17788
  this._univerInstanceService = _univerInstanceService;
17857
17789
  this._commandService = _commandService;
17858
17790
  this._configService = _configService;
17859
17791
  _defineProperty(this, "_d", new _univerjs_core.DisposableCollection());
17860
17792
  _defineProperty(this, "_enabled", true);
17861
- const freezeSync = (_this$_configService$ = (_this$_configService$2 = this._configService.getConfig("sheets.config")) === null || _this$_configService$2 === void 0 ? void 0 : _this$_configService$2.freezeSync) !== null && _this$_configService$ !== void 0 ? _this$_configService$ : true;
17793
+ const freezeSync = ((_this$_configService$ = this._configService.getConfig("sheets.config")) === null || _this$_configService$ === void 0 ? void 0 : _this$_configService$.freezeSync) ?? true;
17862
17794
  this.setEnabled(freezeSync);
17863
17795
  }
17864
17796
  getEnabled() {
@@ -18278,7 +18210,7 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
18278
18210
  })) return false;
18279
18211
  if (rangeTypes && rangeTypes.length > 0) {
18280
18212
  var _this$_selectionManag;
18281
- const ranges = selectionRanges !== null && selectionRanges !== void 0 ? selectionRanges : (_this$_selectionManag = this._selectionManagerService.getCurrentSelections()) === null || _this$_selectionManag === void 0 ? void 0 : _this$_selectionManag.map((s) => s.range);
18213
+ const ranges = selectionRanges ?? ((_this$_selectionManag = this._selectionManagerService.getCurrentSelections()) === null || _this$_selectionManag === void 0 ? void 0 : _this$_selectionManag.map((s) => s.range));
18282
18214
  if (!ranges) return false;
18283
18215
  const rules = this._rangeProtectionRuleModel.getSubunitRuleList(_unitId, _subUnitId);
18284
18216
  if (rules.length === 0) return true;
@@ -18495,11 +18427,11 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
18495
18427
  return true;
18496
18428
  }
18497
18429
  _permissionCheckWithInsertOrDeleteMoveRange(direction, params) {
18498
- var _params$range, _this$_selectionManag3;
18430
+ var _this$_selectionManag3;
18499
18431
  const target = getSheetCommandTarget(this._univerInstanceService);
18500
18432
  if (!target) return false;
18501
18433
  const { worksheet, unitId, subUnitId } = target;
18502
- const range = (_params$range = params === null || params === void 0 ? void 0 : params.range) !== null && _params$range !== void 0 ? _params$range : (_this$_selectionManag3 = this._selectionManagerService.getCurrentLastSelection()) === null || _this$_selectionManag3 === void 0 ? void 0 : _this$_selectionManag3.range;
18434
+ const range = (params === null || params === void 0 ? void 0 : params.range) ?? ((_this$_selectionManag3 = this._selectionManagerService.getCurrentLastSelection()) === null || _this$_selectionManag3 === void 0 ? void 0 : _this$_selectionManag3.range);
18503
18435
  if (!range) return false;
18504
18436
  if (!this.permissionCheckWithRanges({
18505
18437
  workbookTypes: [WorkbookEditablePermission],
@@ -19034,15 +18966,16 @@ ZebraCrossingCacheController = __decorate([
19034
18966
 
19035
18967
  //#endregion
19036
18968
  //#region src/models/range-protection-render.model.ts
19037
- let RangeProtectionRenderModel = class RangeProtectionRenderModel {
18969
+ let RangeProtectionRenderModel = class RangeProtectionRenderModel extends _univerjs_core.Disposable {
19038
18970
  constructor(_selectionProtectionRuleModel, _permissionService) {
18971
+ super();
19039
18972
  this._selectionProtectionRuleModel = _selectionProtectionRuleModel;
19040
18973
  this._permissionService = _permissionService;
19041
18974
  _defineProperty(this, "_cache", new _univerjs_core.LRUMap(1e4));
19042
18975
  this._init();
19043
18976
  }
19044
18977
  _init() {
19045
- this._permissionService.permissionPointUpdate$.pipe((0, rxjs_operators.filter)((permission) => permission.type === _univerjs_protocol.UnitObject.SelectRange), (0, rxjs_operators.filter)((permission) => getAllRangePermissionPoint().some((F) => permission instanceof F)), (0, rxjs_operators.map)((permission) => permission)).subscribe((permission) => {
18978
+ this.disposeWithMe(this._permissionService.permissionPointUpdate$.pipe((0, rxjs_operators.filter)((permission) => permission.type === _univerjs_protocol.UnitObject.SelectRange), (0, rxjs_operators.filter)((permission) => getAllRangePermissionPoint().some((F) => permission instanceof F)), (0, rxjs_operators.map)((permission) => permission)).subscribe((permission) => {
19046
18979
  const ruleMap = this._selectionProtectionRuleModel.getSubunitRuleList(permission.unitId, permission.subUnitId);
19047
18980
  for (const rule of ruleMap) if (rule.permissionId === permission.permissionId) rule.ranges.forEach((range) => {
19048
18981
  _univerjs_core.Range.foreach(range, (row, col) => {
@@ -19050,8 +18983,8 @@ let RangeProtectionRenderModel = class RangeProtectionRenderModel {
19050
18983
  this._cache.delete(key);
19051
18984
  });
19052
18985
  });
19053
- });
19054
- this._selectionProtectionRuleModel.ruleChange$.subscribe((info) => {
18986
+ }));
18987
+ this.disposeWithMe(this._selectionProtectionRuleModel.ruleChange$.subscribe((info) => {
19055
18988
  info.rule.ranges.forEach((range) => {
19056
18989
  _univerjs_core.Range.foreach(range, (row, col) => {
19057
18990
  const key = this._createKey(info.unitId, info.subUnitId, row, col);
@@ -19067,7 +19000,7 @@ let RangeProtectionRenderModel = class RangeProtectionRenderModel {
19067
19000
  });
19068
19001
  });
19069
19002
  }
19070
- });
19003
+ }));
19071
19004
  }
19072
19005
  _createKey(unitId, subUnitId, row, col) {
19073
19006
  return `${unitId}_${subUnitId}_${row}_${col}`;
@@ -19082,10 +19015,9 @@ let RangeProtectionRenderModel = class RangeProtectionRenderModel {
19082
19015
  const result = [];
19083
19016
  for (const rule of ruleMap) if (rule.ranges.some((range) => range.startRow <= row && range.endRow >= row && range.startColumn <= col && range.endColumn >= col)) {
19084
19017
  const permissionMap = getAllRangePermissionPoint().reduce((result, F) => {
19085
- var _permission$value;
19086
19018
  const instance = new F(unitId, subUnitId, rule.permissionId);
19087
19019
  const permission = this._permissionService.getPermissionPoint(instance.id);
19088
- result[instance.subType] = (_permission$value = permission === null || permission === void 0 ? void 0 : permission.value) !== null && _permission$value !== void 0 ? _permission$value : instance.value;
19020
+ result[instance.subType] = (permission === null || permission === void 0 ? void 0 : permission.value) ?? instance.value;
19089
19021
  return result;
19090
19022
  }, {});
19091
19023
  result.push({
@@ -19100,6 +19032,10 @@ let RangeProtectionRenderModel = class RangeProtectionRenderModel {
19100
19032
  clear() {
19101
19033
  this._cache.clear();
19102
19034
  }
19035
+ dispose() {
19036
+ super.dispose();
19037
+ this._cache.clear();
19038
+ }
19103
19039
  };
19104
19040
  RangeProtectionRenderModel = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(RangeProtectionRuleModel)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.IPermissionService))], RangeProtectionRenderModel);
19105
19041
 
@@ -19237,11 +19173,11 @@ let RangeProtectionCache = class RangeProtectionCache extends _univerjs_core.Dis
19237
19173
  this._permissionIdCache.delete(rule.permissionId);
19238
19174
  }
19239
19175
  _getSelectionActions(unitId, subUnitId, rule) {
19240
- var _this$_permissionServ, _this$_permissionServ2, _RangeProtectionPermi, _this$_permissionServ3, _this$_permissionServ4, _RangeProtectionPermi2, _this$_permissionServ5, _this$_permissionServ6, _RangeProtectionPermi3, _this$_permissionServ7, _this$_permissionServ8, _RangeProtectionPermi4;
19241
- const edit = (_this$_permissionServ = (_this$_permissionServ2 = this._permissionService.getPermissionPoint((_RangeProtectionPermi = new RangeProtectionPermissionEditPoint(unitId, subUnitId, rule.permissionId)) === null || _RangeProtectionPermi === void 0 ? void 0 : _RangeProtectionPermi.id)) === null || _this$_permissionServ2 === void 0 ? void 0 : _this$_permissionServ2.value) !== null && _this$_permissionServ !== void 0 ? _this$_permissionServ : false;
19242
- const view = (_this$_permissionServ3 = (_this$_permissionServ4 = this._permissionService.getPermissionPoint((_RangeProtectionPermi2 = new RangeProtectionPermissionViewPoint(unitId, subUnitId, rule.permissionId)) === null || _RangeProtectionPermi2 === void 0 ? void 0 : _RangeProtectionPermi2.id)) === null || _this$_permissionServ4 === void 0 ? void 0 : _this$_permissionServ4.value) !== null && _this$_permissionServ3 !== void 0 ? _this$_permissionServ3 : false;
19243
- const manageProtection = (_this$_permissionServ5 = (_this$_permissionServ6 = this._permissionService.getPermissionPoint((_RangeProtectionPermi3 = new RangeProtectionPermissionManageCollaPoint(unitId, subUnitId, rule.permissionId)) === null || _RangeProtectionPermi3 === void 0 ? void 0 : _RangeProtectionPermi3.id)) === null || _this$_permissionServ6 === void 0 ? void 0 : _this$_permissionServ6.value) !== null && _this$_permissionServ5 !== void 0 ? _this$_permissionServ5 : false;
19244
- const deleteProtection = (_this$_permissionServ7 = (_this$_permissionServ8 = this._permissionService.getPermissionPoint((_RangeProtectionPermi4 = new RangeProtectionPermissionDeleteProtectionPoint(unitId, subUnitId, rule.permissionId)) === null || _RangeProtectionPermi4 === void 0 ? void 0 : _RangeProtectionPermi4.id)) === null || _this$_permissionServ8 === void 0 ? void 0 : _this$_permissionServ8.value) !== null && _this$_permissionServ7 !== void 0 ? _this$_permissionServ7 : false;
19176
+ var _this$_permissionServ, _RangeProtectionPermi, _this$_permissionServ2, _RangeProtectionPermi2, _this$_permissionServ3, _RangeProtectionPermi3, _this$_permissionServ4, _RangeProtectionPermi4;
19177
+ const edit = ((_this$_permissionServ = this._permissionService.getPermissionPoint((_RangeProtectionPermi = new RangeProtectionPermissionEditPoint(unitId, subUnitId, rule.permissionId)) === null || _RangeProtectionPermi === void 0 ? void 0 : _RangeProtectionPermi.id)) === null || _this$_permissionServ === void 0 ? void 0 : _this$_permissionServ.value) ?? false;
19178
+ const view = ((_this$_permissionServ2 = this._permissionService.getPermissionPoint((_RangeProtectionPermi2 = new RangeProtectionPermissionViewPoint(unitId, subUnitId, rule.permissionId)) === null || _RangeProtectionPermi2 === void 0 ? void 0 : _RangeProtectionPermi2.id)) === null || _this$_permissionServ2 === void 0 ? void 0 : _this$_permissionServ2.value) ?? false;
19179
+ const manageProtection = ((_this$_permissionServ3 = this._permissionService.getPermissionPoint((_RangeProtectionPermi3 = new RangeProtectionPermissionManageCollaPoint(unitId, subUnitId, rule.permissionId)) === null || _RangeProtectionPermi3 === void 0 ? void 0 : _RangeProtectionPermi3.id)) === null || _this$_permissionServ3 === void 0 ? void 0 : _this$_permissionServ3.value) ?? false;
19180
+ const deleteProtection = ((_this$_permissionServ4 = this._permissionService.getPermissionPoint((_RangeProtectionPermi4 = new RangeProtectionPermissionDeleteProtectionPoint(unitId, subUnitId, rule.permissionId)) === null || _RangeProtectionPermi4 === void 0 ? void 0 : _RangeProtectionPermi4.id)) === null || _this$_permissionServ4 === void 0 ? void 0 : _this$_permissionServ4.value) ?? false;
19245
19181
  return {
19246
19182
  [_univerjs_protocol.UnitAction.Edit]: edit,
19247
19183
  [_univerjs_protocol.UnitAction.View]: view,
@@ -19389,7 +19325,7 @@ RangeProtectionCache = __decorate([
19389
19325
  //#endregion
19390
19326
  //#region package.json
19391
19327
  var name = "@univerjs/sheets";
19392
- var version = "1.0.0-alpha.7";
19328
+ var version = "1.0.0-beta.0";
19393
19329
 
19394
19330
  //#endregion
19395
19331
  //#region src/controllers/active-worksheet.controller.ts
@@ -19414,7 +19350,7 @@ let ActiveWorksheetController = class ActiveWorksheetController extends _univerj
19414
19350
  _adjustActiveSheetOnHideSheet(mutation) {
19415
19351
  var _workbook$getActiveSh;
19416
19352
  const { unitId, subUnitId } = mutation.params;
19417
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
19353
+ const workbook = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
19418
19354
  if (!workbook) return;
19419
19355
  if (((_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getSheetId()) !== subUnitId) return;
19420
19356
  const nextId = findTheNextUnhiddenSheet(workbook, workbook.getActiveSheetIndex());
@@ -19422,7 +19358,7 @@ let ActiveWorksheetController = class ActiveWorksheetController extends _univerj
19422
19358
  }
19423
19359
  _beforeAdjustActiveSheetOnRemoveSheet(mutation) {
19424
19360
  const { unitId, subUnitId } = mutation.params;
19425
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
19361
+ const workbook = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
19426
19362
  if (!workbook) return;
19427
19363
  const worksheet = workbook.getSheetBySheetId(subUnitId);
19428
19364
  if (!worksheet) return;
@@ -19431,7 +19367,7 @@ let ActiveWorksheetController = class ActiveWorksheetController extends _univerj
19431
19367
  _adjustActiveSheetOnRemoveSheet(mutation) {
19432
19368
  if (this._previousSheetIndex === -1) return;
19433
19369
  const { unitId } = mutation.params;
19434
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
19370
+ const workbook = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
19435
19371
  if (!workbook) return;
19436
19372
  if (workbook.getActiveSheet().getSheetId() === mutation.params.subUnitId) {
19437
19373
  const previousIndex = this._previousSheetIndex;
@@ -19496,7 +19432,6 @@ const ONLY_REGISTER_FORMULA_RELATED_MUTATIONS_KEY = "ONLY_REGISTER_FORMULA_RELAT
19496
19432
  //#region src/controllers/basic-worksheet.controller.ts
19497
19433
  let BasicWorksheetController = class BasicWorksheetController extends _univerjs_core.Disposable {
19498
19434
  constructor(_commandService, _configService, _dataSyncPrimaryController) {
19499
- var _this$_configService$;
19500
19435
  super();
19501
19436
  this._commandService = _commandService;
19502
19437
  this._configService = _configService;
@@ -19538,7 +19473,7 @@ let BasicWorksheetController = class BasicWorksheetController extends _univerjs_
19538
19473
  this._commandService.registerCommand(mutation);
19539
19474
  (_this$_dataSyncPrimar = this._dataSyncPrimaryController) === null || _this$_dataSyncPrimar === void 0 || _this$_dataSyncPrimar.registerSyncingMutations(mutation);
19540
19475
  });
19541
- if (!((_this$_configService$ = this._configService.getConfig("ONLY_REGISTER_FORMULA_RELATED_MUTATIONS_KEY")) !== null && _this$_configService$ !== void 0 ? _this$_configService$ : false)) [
19476
+ if (!(this._configService.getConfig("ONLY_REGISTER_FORMULA_RELATED_MUTATIONS_KEY") ?? false)) [
19542
19477
  AddWorksheetMergeCommand,
19543
19478
  AddWorksheetMergeAllCommand,
19544
19479
  AddWorksheetMergeVerticalCommand,
@@ -19776,10 +19711,10 @@ let SheetPermissionViewModelController = class SheetPermissionViewModelControlle
19776
19711
  const { unitId, subUnitId } = context;
19777
19712
  const worksheetRule = this._worksheetProtectionRuleModel.getRule(unitId, subUnitId);
19778
19713
  if (worksheetRule === null || worksheetRule === void 0 ? void 0 : worksheetRule.permissionId) {
19779
- var _this$_permissionServ, _this$_permissionServ2, _this$_permissionServ3, _this$_permissionServ4, _selectionProtection$;
19714
+ var _this$_permissionServ, _this$_permissionServ2, _selectionProtection$;
19780
19715
  const selectionProtection = [{
19781
- [_univerjs_protocol.UnitAction.View]: (_this$_permissionServ = (_this$_permissionServ2 = this._permissionService.getPermissionPoint(new WorksheetViewPermission(unitId, subUnitId).id)) === null || _this$_permissionServ2 === void 0 ? void 0 : _this$_permissionServ2.value) !== null && _this$_permissionServ !== void 0 ? _this$_permissionServ : false,
19782
- [_univerjs_protocol.UnitAction.Edit]: (_this$_permissionServ3 = (_this$_permissionServ4 = this._permissionService.getPermissionPoint(new WorksheetEditPermission(unitId, subUnitId).id)) === null || _this$_permissionServ4 === void 0 ? void 0 : _this$_permissionServ4.value) !== null && _this$_permissionServ3 !== void 0 ? _this$_permissionServ3 : false
19716
+ [_univerjs_protocol.UnitAction.View]: ((_this$_permissionServ = this._permissionService.getPermissionPoint(new WorksheetViewPermission(unitId, subUnitId).id)) === null || _this$_permissionServ === void 0 ? void 0 : _this$_permissionServ.value) ?? false,
19717
+ [_univerjs_protocol.UnitAction.Edit]: ((_this$_permissionServ2 = this._permissionService.getPermissionPoint(new WorksheetEditPermission(unitId, subUnitId).id)) === null || _this$_permissionServ2 === void 0 ? void 0 : _this$_permissionServ2.value) ?? false
19783
19718
  }];
19784
19719
  const isSkipRender = !((_selectionProtection$ = selectionProtection[0]) === null || _selectionProtection$ === void 0 ? void 0 : _selectionProtection$[_univerjs_protocol.UnitAction.View]);
19785
19720
  const _cellData = !cell || cell === context.rawData ? { ...cell } : cell;
@@ -19898,7 +19833,7 @@ let NumfmtService = class NumfmtService extends _univerjs_core.Disposable {
19898
19833
  this._logService = _logService;
19899
19834
  }
19900
19835
  getValue(unitId, subUnitId, row, col) {
19901
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
19836
+ const workbook = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
19902
19837
  if (!workbook) return;
19903
19838
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
19904
19839
  if (!worksheet) return;
@@ -19911,7 +19846,7 @@ let NumfmtService = class NumfmtService extends _univerjs_core.Disposable {
19911
19846
  return null;
19912
19847
  }
19913
19848
  deleteValues(unitId, subUnitId, values) {
19914
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
19849
+ const workbook = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
19915
19850
  if (!workbook) return;
19916
19851
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
19917
19852
  if (!worksheet) return;
@@ -19928,7 +19863,7 @@ let NumfmtService = class NumfmtService extends _univerjs_core.Disposable {
19928
19863
  });
19929
19864
  }
19930
19865
  setValues(unitId, subUnitId, values) {
19931
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
19866
+ const workbook = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
19932
19867
  if (!workbook) return;
19933
19868
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
19934
19869
  if (!worksheet) return;
@@ -20444,7 +20379,7 @@ let RangeProtectionRefRangeService = class RangeProtectionRefRangeService extend
20444
20379
  this._selectionProtectionRenderModel.clear();
20445
20380
  }
20446
20381
  if (mutationIdByRowCol.includes(command.id)) {
20447
- const workbook = this._univerInstanceService.getUniverSheetInstance(command.params.unitId);
20382
+ const workbook = this._univerInstanceService.getUnit(command.params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
20448
20383
  if (!workbook) return;
20449
20384
  const worksheet = workbook.getSheetBySheetId(command.params.subUnitId);
20450
20385
  if (!worksheet) return;
@@ -21040,11 +20975,14 @@ const getPrimaryCellUp = (scopeRange, worksheet, currentPrimary, step = 1, isFin
21040
20975
  startRow: next,
21041
20976
  endRow: next
21042
20977
  };
21043
- else if (isGoBack) return getPrimaryCellLeft(scopeRange, worksheet, {
21044
- ...currentPrimary,
21045
- startRow: endRow,
21046
- endRow
21047
- }, step, isFindNext, false);
20978
+ else if (isGoBack) {
20979
+ const newPrimary = {
20980
+ ...currentPrimary,
20981
+ startRow: endRow,
20982
+ endRow
20983
+ };
20984
+ return getPrimaryCellLeft(scopeRange, worksheet, newPrimary, step, isFindNext, false);
20985
+ }
21048
20986
  };
21049
20987
  const getPrimaryCellDown = (scopeRange, worksheet, currentPrimary, step = 1, isFindNext = true, isGoBack = true) => {
21050
20988
  const { startRow, endRow } = _univerjs_core.Range.transformRange(scopeRange, worksheet);
@@ -21061,11 +20999,14 @@ const getPrimaryCellDown = (scopeRange, worksheet, currentPrimary, step = 1, isF
21061
20999
  startRow: next,
21062
21000
  endRow: next
21063
21001
  };
21064
- else if (isGoBack) return getPrimaryCellRight(scopeRange, worksheet, {
21065
- ...currentPrimary,
21066
- startRow,
21067
- endRow: startRow
21068
- }, step, isFindNext, false);
21002
+ else if (isGoBack) {
21003
+ const newPrimary = {
21004
+ ...currentPrimary,
21005
+ startRow,
21006
+ endRow: startRow
21007
+ };
21008
+ return getPrimaryCellRight(scopeRange, worksheet, newPrimary, step, isFindNext, false);
21009
+ }
21069
21010
  };
21070
21011
  const getPrimaryCellLeft = (scopeRange, worksheet, currentPrimary, step = 1, isFindNext = true, isGoBack = true) => {
21071
21012
  const { startColumn, endColumn } = _univerjs_core.Range.transformRange(scopeRange, worksheet);
@@ -21082,11 +21023,14 @@ const getPrimaryCellLeft = (scopeRange, worksheet, currentPrimary, step = 1, isF
21082
21023
  startColumn: next,
21083
21024
  endColumn: next
21084
21025
  };
21085
- else if (isGoBack) return getPrimaryCellUp(scopeRange, worksheet, {
21086
- ...currentPrimary,
21087
- startColumn: endColumn,
21088
- endColumn
21089
- }, step, isFindNext, false);
21026
+ else if (isGoBack) {
21027
+ const newPrimary = {
21028
+ ...currentPrimary,
21029
+ startColumn: endColumn,
21030
+ endColumn
21031
+ };
21032
+ return getPrimaryCellUp(scopeRange, worksheet, newPrimary, step, isFindNext, false);
21033
+ }
21090
21034
  };
21091
21035
  const getPrimaryCellRight = (scopeRange, worksheet, currentPrimary, step = 1, isFindNext = true, isGoBack = true) => {
21092
21036
  const { startColumn, endColumn } = _univerjs_core.Range.transformRange(scopeRange, worksheet);
@@ -21103,11 +21047,14 @@ const getPrimaryCellRight = (scopeRange, worksheet, currentPrimary, step = 1, is
21103
21047
  endColumn: next,
21104
21048
  startColumn: next
21105
21049
  };
21106
- else if (isGoBack) return getPrimaryCellDown(scopeRange, worksheet, {
21107
- ...currentPrimary,
21108
- startColumn,
21109
- endColumn: startColumn
21110
- }, step, isFindNext, false);
21050
+ else if (isGoBack) {
21051
+ const newPrimary = {
21052
+ ...currentPrimary,
21053
+ startColumn,
21054
+ endColumn: startColumn
21055
+ };
21056
+ return getPrimaryCellDown(scopeRange, worksheet, newPrimary, step, isFindNext, false);
21057
+ }
21111
21058
  };
21112
21059
  function getCellAtRowCol$1(row, col, worksheet) {
21113
21060
  let destRange = null;
@@ -21838,6 +21785,7 @@ exports.handleInsertRow = handleInsertRow;
21838
21785
  exports.handleMoveCols = handleMoveCols;
21839
21786
  exports.handleMoveRange = handleMoveRange;
21840
21787
  exports.handleMoveRows = handleMoveRows;
21788
+ exports.isCellImage = isCellImage;
21841
21789
  exports.isSingleCellSelection = isSingleCellSelection;
21842
21790
  exports.rangeMerge = rangeMerge;
21843
21791
  exports.rangeToDiscreteRange = rangeToDiscreteRange;