@univerjs/sheets 0.21.0 → 0.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  let _univerjs_core = require("@univerjs/core");
3
3
  let rxjs = require("rxjs");
4
- let _univerjs_engine_render = require("@univerjs/engine-render");
5
4
  let _univerjs_engine_formula = require("@univerjs/engine-formula");
5
+ let _univerjs_engine_render = require("@univerjs/engine-render");
6
6
  let _univerjs_protocol = require("@univerjs/protocol");
7
7
  let rxjs_operators = require("rxjs/operators");
8
8
  let _univerjs_rpc = require("@univerjs/rpc");
@@ -243,8 +243,8 @@ let SheetInterceptorService = class SheetInterceptorService extends _univerjs_co
243
243
  AFTER_CELL_EDIT,
244
244
  VALIDATE_CELL
245
245
  }));
246
- this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {
247
- this._interceptWorkbook(workbook);
246
+ this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).subscribe((event) => {
247
+ this._interceptWorkbook(event.unit);
248
248
  }));
249
249
  this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => this._disposeWorkbookInterceptor(workbook)));
250
250
  this.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
@@ -2712,7 +2712,7 @@ const SetWorksheetActiveOperation = {
2712
2712
  id: "sheet.operation.set-worksheet-active",
2713
2713
  type: _univerjs_core.CommandType.OPERATION,
2714
2714
  handler: (accessor, params) => {
2715
- const workbook = accessor.get(_univerjs_core.IUniverInstanceService).getUniverSheetInstance(params.unitId);
2715
+ const workbook = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
2716
2716
  if (!workbook) return false;
2717
2717
  const worksheets = workbook.getWorksheets();
2718
2718
  for (const [, worksheet] of worksheets) if (worksheet.getSheetId() === params.subUnitId) {
@@ -3042,6 +3042,27 @@ function getSkeletonChangedEffectedRange(commandInfo, columnCount) {
3042
3042
  }
3043
3043
  }
3044
3044
 
3045
+ //#endregion
3046
+ //#region src/basics/defined-name-utils.ts
3047
+ function validateDefinedName(name, options) {
3048
+ if (name.length === 0) return "definedName.nameEmpty";
3049
+ const { unitId, formulaOrRefString, univerInstanceService, definedNamesService, superTableService, functionService, id } = options;
3050
+ /**
3051
+ * The defined name can't be duplicate with existing defined names.
3052
+ * If id is provided, it means we are updating an existing defined name. We should allow the name to be the same as itself.
3053
+ */
3054
+ const existingDefinedName = definedNamesService.getValueByName(unitId, name);
3055
+ if (existingDefinedName && (id === null || id === void 0 || id.length === 0 || existingDefinedName.id !== id)) return "definedName.nameDuplicate";
3056
+ if (superTableService.hasTable(unitId, name)) return "definedName.nameDuplicate";
3057
+ if (!_univerjs_core.Tools.isValidParameter(name) || (0, _univerjs_engine_formula.isReferenceStringWithEffectiveColumn)(name) || !_univerjs_core.Tools.isStartValidPosition(name) && !(0, _univerjs_engine_render.hasCJKText)(name.substring(0, 1))) return "definedName.nameInvalid";
3058
+ const workbook = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
3059
+ if (!workbook) throw new Error(`Workbook not found for unitId: ${unitId}`);
3060
+ if (workbook.getSheets().some((sheet) => sheet.getName() === name)) return "definedName.nameSheetConflict";
3061
+ if (formulaOrRefString.length === 0) return "definedName.formulaOrRefStringEmpty";
3062
+ if (functionService.hasExecutor(name.toUpperCase())) return "definedName.nameConflict";
3063
+ return true;
3064
+ }
3065
+
3045
3066
  //#endregion
3046
3067
  //#region src/basics/expand-range.ts
3047
3068
  function cellHasValue$1(cell) {
@@ -4440,19 +4461,18 @@ const ClearSelectionAllCommand = {
4440
4461
  type: _univerjs_core.CommandType.COMMAND,
4441
4462
  handler: (accessor, params) => {
4442
4463
  var _selectionManagerServ;
4443
- const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
4444
- const commandService = accessor.get(_univerjs_core.ICommandService);
4464
+ const target = getSheetCommandTarget(accessor.get(_univerjs_core.IUniverInstanceService), {
4465
+ unitId: params === null || params === void 0 ? void 0 : params.unitId,
4466
+ subUnitId: params === null || params === void 0 ? void 0 : params.subUnitId
4467
+ });
4468
+ if (!target) return false;
4445
4469
  const selectionManagerService = accessor.get(SheetsSelectionsService);
4446
- const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
4447
- const sheetInterceptorService = accessor.get(SheetInterceptorService);
4448
- const workbook = univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
4449
- if (!workbook) return false;
4450
- const unitId = (params === null || params === void 0 ? void 0 : params.unitId) || workbook.getUnitId();
4451
- const worksheet = workbook.getActiveSheet();
4452
- if (!worksheet) return false;
4453
- const subUnitId = (params === null || params === void 0 ? void 0 : params.subUnitId) || worksheet.getSheetId();
4470
+ const { unitId, subUnitId } = target;
4454
4471
  const selections = (params === null || params === void 0 ? void 0 : params.ranges) || ((_selectionManagerServ = selectionManagerService.getCurrentSelections()) === null || _selectionManagerServ === void 0 ? void 0 : _selectionManagerServ.map((s) => s.range));
4455
4472
  if (!(selections === null || selections === void 0 ? void 0 : selections.length)) return false;
4473
+ const commandService = accessor.get(_univerjs_core.ICommandService);
4474
+ const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
4475
+ const sheetInterceptorService = accessor.get(SheetInterceptorService);
4456
4476
  const visibleRanges = getVisibleRanges(selections, accessor, unitId, subUnitId);
4457
4477
  const sequenceExecuteList = [];
4458
4478
  const sequenceExecuteUndoList = [];
@@ -4470,7 +4490,10 @@ const ClearSelectionAllCommand = {
4470
4490
  id: SetRangeValuesMutation.id,
4471
4491
  params: undoClearMutationParams
4472
4492
  });
4473
- const intercepted = sheetInterceptorService.onCommandExecute({ id: ClearSelectionAllCommand.id });
4493
+ const intercepted = sheetInterceptorService.onCommandExecute({
4494
+ id: ClearSelectionAllCommand.id,
4495
+ params
4496
+ });
4474
4497
  sequenceExecuteList.push(...intercepted.redos);
4475
4498
  sequenceExecuteUndoList.unshift(...intercepted.undos);
4476
4499
  if ((0, _univerjs_core.sequenceExecute)(sequenceExecuteList, commandService)) {
@@ -4495,19 +4518,18 @@ const ClearSelectionFormatCommand = {
4495
4518
  type: _univerjs_core.CommandType.COMMAND,
4496
4519
  handler: (accessor, params) => {
4497
4520
  var _selectionManagerServ;
4498
- const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
4499
- const commandService = accessor.get(_univerjs_core.ICommandService);
4521
+ const target = getSheetCommandTarget(accessor.get(_univerjs_core.IUniverInstanceService), {
4522
+ unitId: params === null || params === void 0 ? void 0 : params.unitId,
4523
+ subUnitId: params === null || params === void 0 ? void 0 : params.subUnitId
4524
+ });
4525
+ if (!target) return false;
4500
4526
  const selectionManagerService = accessor.get(SheetsSelectionsService);
4501
- const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
4502
- const sheetInterceptorService = accessor.get(SheetInterceptorService);
4503
- const workbook = univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
4504
- if (!workbook) return false;
4505
- const unitId = (params === null || params === void 0 ? void 0 : params.unitId) || workbook.getUnitId();
4506
- const worksheet = workbook.getActiveSheet();
4507
- if (!worksheet) return false;
4508
- const subUnitId = (params === null || params === void 0 ? void 0 : params.subUnitId) || worksheet.getSheetId();
4527
+ const { unitId, subUnitId } = target;
4509
4528
  const ranges = (params === null || params === void 0 ? void 0 : params.ranges) || ((_selectionManagerServ = selectionManagerService.getCurrentSelections()) === null || _selectionManagerServ === void 0 ? void 0 : _selectionManagerServ.map((s) => s.range));
4510
4529
  if (!(ranges === null || ranges === void 0 ? void 0 : ranges.length)) return false;
4530
+ const commandService = accessor.get(_univerjs_core.ICommandService);
4531
+ const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
4532
+ const sheetInterceptorService = accessor.get(SheetInterceptorService);
4511
4533
  const visibleRanges = getVisibleRanges(ranges, accessor, unitId, subUnitId);
4512
4534
  const sequenceExecuteList = [];
4513
4535
  const sequenceExecuteUndoList = [];
@@ -4525,7 +4547,10 @@ const ClearSelectionFormatCommand = {
4525
4547
  id: SetRangeValuesMutation.id,
4526
4548
  params: undoClearMutationParams
4527
4549
  });
4528
- const intercepted = sheetInterceptorService.onCommandExecute({ id: ClearSelectionFormatCommand.id });
4550
+ const intercepted = sheetInterceptorService.onCommandExecute({
4551
+ id: ClearSelectionFormatCommand.id,
4552
+ params
4553
+ });
4529
4554
  sequenceExecuteList.push(...intercepted.redos);
4530
4555
  sequenceExecuteUndoList.unshift(...intercepted.undos);
4531
4556
  if ((0, _univerjs_core.sequenceExecute)(sequenceExecuteList, commandService)) {
@@ -4733,7 +4758,8 @@ let RefSelectionsService = class RefSelectionsService extends SheetsSelectionsSe
4733
4758
  const aliveWorkbooks = this._instanceSrv.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
4734
4759
  aliveWorkbooks.forEach((workbook) => this._ensureWorkbookSelection(workbook.getUnitId()));
4735
4760
  const workbooks$ = new rxjs.BehaviorSubject(aliveWorkbooks);
4736
- this.disposeWithMe(this._instanceSrv.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {
4761
+ this.disposeWithMe(this._instanceSrv.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).subscribe((event) => {
4762
+ const { unit: workbook } = event;
4737
4763
  this._ensureWorkbookSelection(workbook.getUnitId());
4738
4764
  workbooks$.next([...workbooks$.getValue(), workbook]);
4739
4765
  }));
@@ -6635,6 +6661,8 @@ let SheetSkeletonService = class SheetSkeletonService extends _univerjs_core.Dis
6635
6661
  this._univerInstanceService = _univerInstanceService;
6636
6662
  _defineProperty(this, "_sceneMap", /* @__PURE__ */ new Map());
6637
6663
  _defineProperty(this, "_sheetSkeletonParamStore", /* @__PURE__ */ new Map());
6664
+ _defineProperty(this, "_buildSkeleton$", new rxjs.Subject());
6665
+ _defineProperty(this, "buildSkeleton$", this._buildSkeleton$.asObservable());
6638
6666
  this._init();
6639
6667
  }
6640
6668
  dispose() {
@@ -6649,7 +6677,7 @@ let SheetSkeletonService = class SheetSkeletonService extends _univerjs_core.Dis
6649
6677
  this._sheetSkeletonParamStore.delete(unitId);
6650
6678
  }
6651
6679
  _init() {
6652
- this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => this._initWorkbookSkeleton(workbook)));
6680
+ this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).subscribe((event) => this._initWorkbookSkeleton(event.unit)));
6653
6681
  this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => this._disposeByUnitId(workbook.getUnitId())));
6654
6682
  }
6655
6683
  _initWorkbookSkeleton(workbook) {
@@ -6696,6 +6724,7 @@ let SheetSkeletonService = class SheetSkeletonService extends _univerjs_core.Dis
6696
6724
  const unitId = worksheet.getUnitId();
6697
6725
  const scene = this._sceneMap.get(unitId);
6698
6726
  if (scene) spreadsheetSkeleton.setScene(scene);
6727
+ this._buildSkeleton$.next(spreadsheetSkeleton);
6699
6728
  return spreadsheetSkeleton;
6700
6729
  }
6701
6730
  setScene(unitId, scene) {
@@ -6704,6 +6733,11 @@ let SheetSkeletonService = class SheetSkeletonService extends _univerjs_core.Dis
6704
6733
  if (!sheetSkeletonMap) return;
6705
6734
  sheetSkeletonMap.forEach((skeletonParam) => skeletonParam.skeleton.setScene(scene));
6706
6735
  }
6736
+ getSkeletonsByUnitId(unitId) {
6737
+ const sheetSkeletonMap = this._sheetSkeletonParamStore.get(unitId);
6738
+ if (!sheetSkeletonMap) return [];
6739
+ return Array.from(sheetSkeletonMap.values()).map((param) => param.skeleton);
6740
+ }
6707
6741
  getSkeleton(unitId, subUnitId) {
6708
6742
  var _this$getSkeletonPara;
6709
6743
  return (_this$getSkeletonPara = this.getSkeletonParam(unitId, subUnitId)) === null || _this$getSkeletonPara === void 0 ? void 0 : _this$getSkeletonPara.skeleton;
@@ -10691,25 +10725,20 @@ function isChnNumber$1(txt) {
10691
10725
  }
10692
10726
  function matchExtendNumber$1(txt) {
10693
10727
  if (!txt) return { isExtendNumber: false };
10694
- const reg = /0|([1-9]+[0-9]*)/g;
10695
- const isExtendNumber = reg.test(txt);
10696
- if (isExtendNumber) {
10697
- const match = txt.match(reg);
10698
- if (match && match.length > 0) {
10699
- const matchTxt = match[match.length - 1];
10700
- const matchIndex = txt.lastIndexOf(matchTxt);
10701
- const beforeTxt = txt.substr(0, matchIndex);
10702
- const afterTxt = txt.substr(matchIndex + matchTxt.length);
10703
- return {
10704
- isExtendNumber: true,
10705
- matchTxt: Number(matchTxt),
10706
- beforeTxt,
10707
- afterTxt
10708
- };
10709
- }
10710
- return { isExtendNumber: false };
10711
- }
10712
- return { isExtendNumber };
10728
+ const matches = [...txt.matchAll(/\d+/g)];
10729
+ if (!matches.length) return { isExtendNumber: false };
10730
+ const last = matches[matches.length - 1];
10731
+ const rawMatchTxt = last[0];
10732
+ const index = last.index;
10733
+ const beforeTxt = txt.substring(0, index);
10734
+ const afterTxt = txt.substring(index + rawMatchTxt.length);
10735
+ return {
10736
+ isExtendNumber: true,
10737
+ rawMatchTxt,
10738
+ matchNumber: Number(rawMatchTxt),
10739
+ beforeTxt,
10740
+ afterTxt
10741
+ };
10713
10742
  }
10714
10743
  function isChnWeek1(txt) {
10715
10744
  let isChnWeek1;
@@ -10742,13 +10771,19 @@ function getLenS$1(indexArr, rsd) {
10742
10771
  * equal diff
10743
10772
  */
10744
10773
  function isEqualDiff$1(arr) {
10745
- let diff = true;
10746
- const step = arr[1] - arr[0];
10747
- for (let i = 1; i < arr.length; i++) if (arr[i] - arr[i - 1] !== step) {
10748
- diff = false;
10749
- break;
10774
+ if (arr.length < 3) return true;
10775
+ let step = arr[1] - arr[0];
10776
+ let changeStep = false;
10777
+ for (let i = 2; i < arr.length; i++) {
10778
+ const currentStep = arr[i] - arr[i - 1];
10779
+ if (currentStep !== step) {
10780
+ if (changeStep) return false;
10781
+ if (currentStep !== -step) return false;
10782
+ step = currentStep;
10783
+ changeStep = true;
10784
+ }
10750
10785
  }
10751
- return diff;
10786
+ return true;
10752
10787
  }
10753
10788
  function getDataIndex$1(csLen, asLen, indexArr) {
10754
10789
  const obj = [];
@@ -10867,20 +10902,19 @@ function forecast(x, yArr, xArr, forward = true) {
10867
10902
  }
10868
10903
  function fillExtendNumber$1(data, len, step) {
10869
10904
  const applyData = [];
10870
- const reg = /0|([1-9]+[0-9]*)/g;
10905
+ const lastData = data[data.length - 1];
10906
+ const matchResult = matchExtendNumber$1(`${lastData === null || lastData === void 0 ? void 0 : lastData.v}`);
10907
+ if (!matchResult.isExtendNumber) return fillCopy$2(data, len);
10908
+ const { matchNumber, rawMatchTxt, beforeTxt, afterTxt } = matchResult;
10909
+ const width = rawMatchTxt.length;
10871
10910
  for (let i = 1; i <= len; i++) {
10872
- var _data2;
10873
10911
  const index = (i - 1) % data.length;
10874
10912
  const d = _univerjs_core.Tools.deepClone(data[index]);
10875
10913
  removeCellCustom(d);
10876
- const last = `${(_data2 = data[data.length - 1]) === null || _data2 === void 0 ? void 0 : _data2.v}`;
10877
- if (!last) continue;
10878
- const match = last === null || last === void 0 ? void 0 : last.match(reg);
10879
- const lastTxt = match === null || match === void 0 ? void 0 : match[match.length - 1];
10880
- if (!lastTxt) continue;
10881
- const num = Math.abs(Number(lastTxt) + step * i);
10882
- const lastIndex = last.lastIndexOf(lastTxt);
10883
- const valueTxt = last.substr(0, lastIndex) + num.toString() + last.substr(lastIndex + lastTxt.length);
10914
+ if (!d || !d.v) continue;
10915
+ let numStr = Math.abs(matchNumber + step * i).toString();
10916
+ if (numStr.length < width) numStr = numStr.padStart(width, "0");
10917
+ const valueTxt = `${beforeTxt}${numStr}${afterTxt}`;
10884
10918
  if (d) {
10885
10919
  d.v = valueTxt;
10886
10920
  applyData.push(d);
@@ -10935,15 +10969,15 @@ function fillChnWeek$1(data, len, step, weekType = 0) {
10935
10969
  const keyword = keywordMap[weekType];
10936
10970
  const applyData = [];
10937
10971
  for (let i = 1; i <= len; i++) {
10938
- var _data3;
10972
+ var _data2;
10939
10973
  const index = (i - 1) % data.length;
10940
10974
  const d = _univerjs_core.Tools.deepClone(data[index]);
10941
10975
  removeCellCustom(d);
10942
10976
  let num = 0;
10943
- if (((_data3 = data[data.length - 1]) === null || _data3 === void 0 ? void 0 : _data3.v) === keyword[0]) num = 7 + step * i;
10977
+ if (((_data2 = data[data.length - 1]) === null || _data2 === void 0 ? void 0 : _data2.v) === keyword[0]) num = 7 + step * i;
10944
10978
  else {
10945
- var _data4;
10946
- const last = `${(_data4 = data[data.length - 1]) === null || _data4 === void 0 ? void 0 : _data4.v}`;
10979
+ var _data3;
10980
+ const last = `${(_data3 = data[data.length - 1]) === null || _data3 === void 0 ? void 0 : _data3.v}`;
10947
10981
  if (last) num = chineseToNumber$1(last.substr(last.length - 1, 1)) + step * i;
10948
10982
  }
10949
10983
  if (num < 0) num = Math.ceil(Math.abs(num) / 7) * 7 + num;
@@ -10958,11 +10992,11 @@ function fillChnWeek$1(data, len, step, weekType = 0) {
10958
10992
  function fillChnNumber$1(data, len, step) {
10959
10993
  const applyData = [];
10960
10994
  for (let i = 1; i <= len; i++) {
10961
- var _data5;
10995
+ var _data4;
10962
10996
  const index = (i - 1) % data.length;
10963
10997
  const d = _univerjs_core.Tools.deepClone(data[index]);
10964
10998
  removeCellCustom(d);
10965
- const num = chineseToNumber$1(`${(_data5 = data[data.length - 1]) === null || _data5 === void 0 ? void 0 : _data5.v}`) + step * i;
10999
+ const num = chineseToNumber$1(`${(_data4 = data[data.length - 1]) === null || _data4 === void 0 ? void 0 : _data4.v}`) + step * i;
10966
11000
  let txt;
10967
11001
  if (num <= 0) txt = "零";
10968
11002
  else txt = numberToChinese(num);
@@ -11126,11 +11160,11 @@ function fillLoopSeries$1(data, len, step, series) {
11126
11160
  const seriesLen = series.length;
11127
11161
  const applyData = [];
11128
11162
  for (let i = 1; i <= len; i++) {
11129
- var _data6;
11163
+ var _data5;
11130
11164
  const index = (i - 1) % data.length;
11131
11165
  const d = _univerjs_core.Tools.deepClone(data[index]);
11132
11166
  removeCellCustom(d);
11133
- const last = `${(_data6 = data[data.length - 1]) === null || _data6 === void 0 ? void 0 : _data6.v}`;
11167
+ const last = `${(_data5 = data[data.length - 1]) === null || _data5 === void 0 ? void 0 : _data5.v}`;
11134
11168
  let num = series.indexOf(last) + step * i;
11135
11169
  if (num < 0) num += Math.abs(step) * seriesLen;
11136
11170
  const rsd = num % seriesLen;
@@ -11415,9 +11449,13 @@ const AutoFillRules = {
11415
11449
  isContinue: (prev, cur) => {
11416
11450
  if (prev.type === AUTO_FILL_DATA_TYPE.EXTEND_NUMBER) {
11417
11451
  var _prev$cellData;
11418
- const { beforeTxt, afterTxt } = matchExtendNumber(`${(_prev$cellData = prev.cellData) === null || _prev$cellData === void 0 ? void 0 : _prev$cellData.v}` || "");
11419
- const { beforeTxt: curBeforeTxt, afterTxt: curAfterTxt } = matchExtendNumber(`${cur === null || cur === void 0 ? void 0 : cur.v}` || "");
11420
- if (beforeTxt === curBeforeTxt && afterTxt === curAfterTxt) return true;
11452
+ const prevMatch = matchExtendNumber(`${(_prev$cellData = prev.cellData) === null || _prev$cellData === void 0 ? void 0 : _prev$cellData.v}` || "");
11453
+ const curMatch = matchExtendNumber(`${cur === null || cur === void 0 ? void 0 : cur.v}` || "");
11454
+ if (prevMatch.isExtendNumber && curMatch.isExtendNumber) {
11455
+ const { beforeTxt: prevBeforeTxt, afterTxt: prevAfterTxt } = prevMatch;
11456
+ const { beforeTxt: curBeforeTxt, afterTxt: curAfterTxt } = curMatch;
11457
+ if (prevBeforeTxt === curBeforeTxt && prevAfterTxt === curAfterTxt) return true;
11458
+ }
11421
11459
  }
11422
11460
  return false;
11423
11461
  },
@@ -11432,15 +11470,16 @@ const AutoFillRules = {
11432
11470
  const dataNumArr = [];
11433
11471
  for (let i = 0; i < data.length; i++) {
11434
11472
  var _data$i;
11435
- const txt = `${(_data$i = data[i]) === null || _data$i === void 0 ? void 0 : _data$i.v}`;
11436
- txt && dataNumArr.push(Number(matchExtendNumber(txt).matchTxt));
11473
+ const matchResult = matchExtendNumber(`${(_data$i = data[i]) === null || _data$i === void 0 ? void 0 : _data$i.v}`);
11474
+ if (matchResult.isExtendNumber) dataNumArr.push(matchResult.matchNumber);
11437
11475
  }
11438
11476
  if (isReverse) {
11439
11477
  data.reverse();
11440
11478
  dataNumArr.reverse();
11441
11479
  }
11442
11480
  if (isEqualDiff(dataNumArr)) {
11443
- step = dataNumArr[1] - dataNumArr[0];
11481
+ const dataLen = data.length;
11482
+ step = dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2];
11444
11483
  return reverseIfNeed(fillExtendNumber(data, len, step), isReverse);
11445
11484
  }
11446
11485
  return fillCopy$1(data, len);
@@ -11495,7 +11534,10 @@ const AutoFillRules = {
11495
11534
  dataNumArr.reverse();
11496
11535
  }
11497
11536
  if (isEqualDiff(dataNumArr)) {
11498
- if (hasWeek || dataNumArr[dataNumArr.length - 1] < 6 && dataNumArr[0] > 0 || dataNumArr[0] < 6 && dataNumArr[dataNumArr.length - 1] > 0) return reverseIfNeed(fillChnWeek(data, len, dataNumArr[1] - dataNumArr[0]), isReverse);
11537
+ if (hasWeek || dataNumArr[dataNumArr.length - 1] < 6 && dataNumArr[0] > 0 || dataNumArr[0] < 6 && dataNumArr[dataNumArr.length - 1] > 0) {
11538
+ const dataLen = data.length;
11539
+ return reverseIfNeed(fillChnWeek(data, len, dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2]), isReverse);
11540
+ }
11499
11541
  return reverseIfNeed(fillChnNumber(data, len, dataNumArr[1] - dataNumArr[0]), isReverse);
11500
11542
  }
11501
11543
  return fillCopy$1(data, len);
@@ -11535,7 +11577,10 @@ const AutoFillRules = {
11535
11577
  data.reverse();
11536
11578
  dataNumArr.reverse();
11537
11579
  }
11538
- if (isEqualDiff(dataNumArr)) return reverseIfNeed(fillChnWeek(data, len, dataNumArr[1] - dataNumArr[0], 1), isReverse);
11580
+ if (isEqualDiff(dataNumArr)) {
11581
+ const dataLen = data.length;
11582
+ return reverseIfNeed(fillChnWeek(data, len, dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2], 1), isReverse);
11583
+ }
11539
11584
  return fillCopy$1(data, len);
11540
11585
  } }
11541
11586
  },
@@ -11572,7 +11617,10 @@ const AutoFillRules = {
11572
11617
  data.reverse();
11573
11618
  dataNumArr.reverse();
11574
11619
  }
11575
- if (isEqualDiff(dataNumArr)) return reverseIfNeed(fillChnWeek(data, len, dataNumArr[1] - dataNumArr[0], 2), isReverse);
11620
+ if (isEqualDiff(dataNumArr)) {
11621
+ const dataLen = data.length;
11622
+ return reverseIfNeed(fillChnWeek(data, len, dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2], 2), isReverse);
11623
+ }
11576
11624
  return fillCopy$1(data, len);
11577
11625
  } }
11578
11626
  },
@@ -11614,7 +11662,10 @@ const AutoFillRules = {
11614
11662
  data.reverse();
11615
11663
  dataNumArr.reverse();
11616
11664
  }
11617
- if (isEqualDiff(dataNumArr)) return reverseIfNeed(fillLoopSeries(data, len, dataNumArr[1] - dataNumArr[0], series), isReverse);
11665
+ if (isEqualDiff(dataNumArr)) {
11666
+ const dataLen = data.length;
11667
+ return reverseIfNeed(fillLoopSeries(data, len, dataNumArr[dataLen - 1] - dataNumArr[dataLen - 2], series), isReverse);
11668
+ }
11618
11669
  return fillCopy$1(data, len);
11619
11670
  } }
11620
11671
  },
@@ -12172,26 +12223,28 @@ const ClearSelectionContentCommand = {
12172
12223
  type: _univerjs_core.CommandType.COMMAND,
12173
12224
  handler: (accessor, params) => {
12174
12225
  var _selectionManagerServ;
12175
- const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
12176
- const commandService = accessor.get(_univerjs_core.ICommandService);
12226
+ const target = getSheetCommandTarget(accessor.get(_univerjs_core.IUniverInstanceService), {
12227
+ unitId: params === null || params === void 0 ? void 0 : params.unitId,
12228
+ subUnitId: params === null || params === void 0 ? void 0 : params.subUnitId
12229
+ });
12230
+ if (!target) return false;
12177
12231
  const selectionManagerService = accessor.get(SheetsSelectionsService);
12178
- const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
12179
- const sheetInterceptorService = accessor.get(SheetInterceptorService);
12180
- const workbook = univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
12181
- if (!workbook) return false;
12182
- const unitId = (params === null || params === void 0 ? void 0 : params.unitId) || workbook.getUnitId();
12183
- const worksheet = workbook.getActiveSheet();
12184
- if (!worksheet) return false;
12185
- const subUnitId = (params === null || params === void 0 ? void 0 : params.subUnitId) || worksheet.getSheetId();
12232
+ const { unitId, subUnitId } = target;
12186
12233
  const ranges = (params === null || params === void 0 ? void 0 : params.ranges) || ((_selectionManagerServ = selectionManagerService.getCurrentSelections()) === null || _selectionManagerServ === void 0 ? void 0 : _selectionManagerServ.map((s) => s.range));
12187
12234
  if (!(ranges === null || ranges === void 0 ? void 0 : ranges.length)) return false;
12235
+ const commandService = accessor.get(_univerjs_core.ICommandService);
12236
+ const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
12237
+ const sheetInterceptorService = accessor.get(SheetInterceptorService);
12188
12238
  const clearMutationParams = {
12189
12239
  subUnitId,
12190
12240
  unitId,
12191
12241
  cellValue: generateNullCellValue(getVisibleRanges(ranges, accessor, unitId, subUnitId))
12192
12242
  };
12193
12243
  const undoClearMutationParams = SetRangeValuesUndoMutationFactory(accessor, clearMutationParams);
12194
- const intercepted = sheetInterceptorService.onCommandExecute({ id: ClearSelectionContentCommand.id });
12244
+ const intercepted = sheetInterceptorService.onCommandExecute({
12245
+ id: ClearSelectionContentCommand.id,
12246
+ params
12247
+ });
12195
12248
  const redos = [{
12196
12249
  id: SetRangeValuesMutation.id,
12197
12250
  params: clearMutationParams
@@ -13661,11 +13714,9 @@ function mergeSelections$1(ranges) {
13661
13714
  //#endregion
13662
13715
  //#region src/commands/commands/set-defined-name.command.ts
13663
13716
  /**
13664
- * The command to update defined name
13665
- *
13717
+ * The command to update defined name.
13666
13718
  * 1. The old defined name can be obtained through IDefinedNamesService, and does not need to be passed in from the outside, making the command input more concise
13667
-
13668
- 2. Unlike InsertDefinedNameCommand, the old defined name needs to be deleted here at the same time. Because the command interception in UpdateDefinedNameController will add SetDefinedNameMutation or RemoveDefinedNameMutation, it results in that in DefinedNameController, only mutations can be listened to to update Function Description (commands cannot be listened to), so it is necessary to ensure that each mutation triggered by the command has completed all work.
13719
+ * 2. Unlike InsertDefinedNameCommand, the old defined name needs to be deleted here at the same time. Because the command interception in UpdateDefinedNameController will add SetDefinedNameMutation or RemoveDefinedNameMutation, it results in that in DefinedNameController, only mutations can be listened to to update Function Description (commands cannot be listened to), so it is necessary to ensure that each mutation triggered by the command has completed all work.
13669
13720
  */
13670
13721
  const SetDefinedNameCommand = {
13671
13722
  id: "sheet.command.set-defined-name",
@@ -13684,10 +13735,10 @@ const SetDefinedNameCommand = {
13684
13735
  });
13685
13736
  const redos = [
13686
13737
  ...(_interceptorCommands$ = interceptorCommands.preRedos) !== null && _interceptorCommands$ !== void 0 ? _interceptorCommands$ : [],
13687
- {
13738
+ ...oldDefinedNameMutationParams ? [{
13688
13739
  id: _univerjs_engine_formula.RemoveDefinedNameMutation.id,
13689
13740
  params: oldDefinedNameMutationParams
13690
- },
13741
+ }] : [],
13691
13742
  {
13692
13743
  id: _univerjs_engine_formula.SetDefinedNameMutation.id,
13693
13744
  params: newDefinedNameMutationParams
@@ -13700,10 +13751,10 @@ const SetDefinedNameCommand = {
13700
13751
  id: _univerjs_engine_formula.RemoveDefinedNameMutation.id,
13701
13752
  params: newDefinedNameMutationParams
13702
13753
  },
13703
- {
13754
+ ...oldDefinedNameMutationParams ? [{
13704
13755
  id: _univerjs_engine_formula.SetDefinedNameMutation.id,
13705
13756
  params: oldDefinedNameMutationParams
13706
- },
13757
+ }] : [],
13707
13758
  ...interceptorCommands.undos
13708
13759
  ];
13709
13760
  if ((0, _univerjs_core.sequenceExecute)(redos, commandService)) {
@@ -15964,10 +16015,8 @@ let WorksheetPermissionService = class WorksheetPermissionService extends _unive
15964
16015
  });
15965
16016
  });
15966
16017
  };
15967
- this._univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).forEach((workbook) => {
15968
- handleWorkbook(workbook);
15969
- });
15970
- this._univerInstanceService.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs_operators.takeUntil)(this.dispose$)).subscribe(handleWorkbook);
16018
+ this._univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).forEach((workbook) => handleWorkbook(workbook));
16019
+ this._univerInstanceService.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs_operators.takeUntil)(this.dispose$)).subscribe((event) => handleWorkbook(event.unit));
15971
16020
  this._univerInstanceService.getTypeOfUnitDisposed$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs_operators.takeUntil)(this.dispose$)).subscribe((workbook) => {
15972
16021
  workbook.getSheets().forEach((worksheet) => {
15973
16022
  const unitId = workbook.getUnitId();
@@ -17804,7 +17853,7 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
17804
17853
  WorksheetEditPermission
17805
17854
  ],
17806
17855
  rangeTypes: [RangeProtectionPermissionEditPoint]
17807
- }, params.ranges, params.unitId, params.subUnitId);
17856
+ }, params === null || params === void 0 ? void 0 : params.ranges, params === null || params === void 0 ? void 0 : params.unitId, params === null || params === void 0 ? void 0 : params.subUnitId);
17808
17857
  errorMsg = this._localeService.t("permission.dialog.editErr");
17809
17858
  break;
17810
17859
  case ClearSelectionContentCommand.id:
@@ -17813,7 +17862,7 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
17813
17862
  workbookTypes: [WorkbookEditablePermission],
17814
17863
  worksheetTypes: [WorksheetSetCellValuePermission, WorksheetEditPermission],
17815
17864
  rangeTypes: [RangeProtectionPermissionEditPoint]
17816
- }, params.ranges, params.unitId, params.subUnitId);
17865
+ }, params === null || params === void 0 ? void 0 : params.ranges, params === null || params === void 0 ? void 0 : params.unitId, params === null || params === void 0 ? void 0 : params.subUnitId);
17817
17866
  errorMsg = this._localeService.t("permission.dialog.editErr");
17818
17867
  break;
17819
17868
  case ClearSelectionFormatCommand.id:
@@ -17822,7 +17871,7 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
17822
17871
  workbookTypes: [WorkbookEditablePermission],
17823
17872
  worksheetTypes: [WorksheetSetCellStylePermission, WorksheetEditPermission],
17824
17873
  rangeTypes: [RangeProtectionPermissionEditPoint]
17825
- }, params.ranges, params.unitId, params.subUnitId);
17874
+ }, params === null || params === void 0 ? void 0 : params.ranges, params === null || params === void 0 ? void 0 : params.unitId, params === null || params === void 0 ? void 0 : params.subUnitId);
17826
17875
  errorMsg = this._localeService.t("permission.dialog.setStyleErr");
17827
17876
  break;
17828
17877
  case DeltaColumnWidthCommand.id:
@@ -18244,12 +18293,8 @@ let WorkbookPermissionService = class WorkbookPermissionService extends _univerj
18244
18293
  this._permissionService.addPermissionPoint(instance);
18245
18294
  });
18246
18295
  };
18247
- this._univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).forEach((workbook) => {
18248
- handleWorkbook(workbook);
18249
- });
18250
- this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {
18251
- handleWorkbook(workbook);
18252
- }));
18296
+ this._univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).forEach((workbook) => handleWorkbook(workbook));
18297
+ this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).subscribe((event) => handleWorkbook(event.unit)));
18253
18298
  this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {
18254
18299
  const unitId = workbook.getUnitId();
18255
18300
  workbook.getSheets().forEach((worksheet) => {
@@ -19088,7 +19133,7 @@ RangeProtectionCache = __decorate([
19088
19133
  //#endregion
19089
19134
  //#region package.json
19090
19135
  var name = "@univerjs/sheets";
19091
- var version = "0.21.0";
19136
+ var version = "0.21.1";
19092
19137
 
19093
19138
  //#endregion
19094
19139
  //#region src/controllers/active-worksheet.controller.ts
@@ -21491,4 +21536,5 @@ exports.rotateRange = rotateRange;
21491
21536
  exports.runRefRangeMutations = runRefRangeMutations;
21492
21537
  exports.setEndForRange = setEndForRange;
21493
21538
  exports.splitRangeText = splitRangeText;
21494
- exports.transformCellsToRange = transformCellsToRange;
21539
+ exports.transformCellsToRange = transformCellsToRange;
21540
+ exports.validateDefinedName = validateDefinedName;