@univerjs/sheets 1.1.0 → 1.3.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
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  let _univerjs_core = require("@univerjs/core");
3
- let rxjs = require("rxjs");
4
3
  let _univerjs_engine_formula = require("@univerjs/engine-formula");
4
+ let rxjs = require("rxjs");
5
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");
@@ -1201,11 +1201,12 @@ var ZebraCrossingCache = class {
1201
1201
  //#region src/models/range-theme-model.ts
1202
1202
  const SHEET_RANGE_THEME_MODEL_PLUGIN = "SHEET_RANGE_THEME_MODEL_PLUGIN";
1203
1203
  let SheetRangeThemeModel = class SheetRangeThemeModel extends _univerjs_core.Disposable {
1204
- constructor(_sheetInterceptorService, _resourceManagerService, _univerInstanceService) {
1204
+ constructor(_sheetInterceptorService, _resourceManagerService, _univerInstanceService, _sheetRowFilteredService) {
1205
1205
  super();
1206
1206
  this._sheetInterceptorService = _sheetInterceptorService;
1207
1207
  this._resourceManagerService = _resourceManagerService;
1208
1208
  this._univerInstanceService = _univerInstanceService;
1209
+ this._sheetRowFilteredService = _sheetRowFilteredService;
1209
1210
  _defineProperty(this, "_rangeThemeStyleMap", /* @__PURE__ */ new Map());
1210
1211
  _defineProperty(this, "_rangeThemeStyleRuleMap", /* @__PURE__ */ new Map());
1211
1212
  _defineProperty(this, "_rTreeCollection", /* @__PURE__ */ new Map());
@@ -1260,8 +1261,11 @@ let SheetRangeThemeModel = class SheetRangeThemeModel extends _univerjs_core.Dis
1260
1261
  if (sheet) {
1261
1262
  const rowCount = sheet.getRowCount();
1262
1263
  const rowManager = sheet.getRowManager();
1263
- for (let i = 1; i <= rowCount; i++) if (!sheet.getRowVisible(i)) set.add(i);
1264
- else if (rowManager.getRowHeight(i) === 0) set.add(i);
1264
+ for (let i = 0; i < rowCount; i++) if (!sheet.getRowVisible(i)) set.add(i);
1265
+ else {
1266
+ var _this$_sheetRowFilter;
1267
+ if (rowManager.getRowHeight(i) === 0 || ((_this$_sheetRowFilter = this._sheetRowFilteredService) === null || _this$_sheetRowFilter === void 0 ? void 0 : _this$_sheetRowFilter.getRowFiltered(unitId, subUnitId, i))) set.add(i);
1268
+ }
1265
1269
  }
1266
1270
  }
1267
1271
  }
@@ -1427,8 +1431,11 @@ let SheetRangeThemeModel = class SheetRangeThemeModel extends _univerjs_core.Dis
1427
1431
  const offsetRow = row - rangeInfo.range.startRow;
1428
1432
  const offsetCol = col - rangeInfo.range.startColumn;
1429
1433
  const theme = this.getRangeThemeStyle(unitId, themeName);
1434
+ let lastVisibleRow = rangeInfo.range.endRow;
1435
+ const hiddenRows = this._getSheetRowVisibleFuncSet(unitId, subUnitId);
1436
+ while (lastVisibleRow >= rangeInfo.range.startRow && hiddenRows.has(lastVisibleRow)) lastVisibleRow--;
1430
1437
  const isToggled = this._ensureZebraCrossingCache(unitId, subUnitId, themes[0]).getIsToggled(row);
1431
- if (theme) return theme.getStyle(offsetRow, offsetCol, row === rangeInfo.range.endRow, col === rangeInfo.range.endColumn, isToggled);
1438
+ if (theme) return theme.getStyle(offsetRow, offsetCol, row === lastVisibleRow, col === rangeInfo.range.endColumn, isToggled);
1432
1439
  }
1433
1440
  }
1434
1441
  }
@@ -1527,7 +1534,8 @@ let SheetRangeThemeModel = class SheetRangeThemeModel extends _univerjs_core.Dis
1527
1534
  SheetRangeThemeModel = __decorate([
1528
1535
  __decorateParam(0, (0, _univerjs_core.Inject)(SheetInterceptorService)),
1529
1536
  __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.IResourceManagerService)),
1530
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService))
1537
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService)),
1538
+ __decorateParam(3, (0, _univerjs_core.Optional)(_univerjs_engine_formula.ISheetRowFilteredService))
1531
1539
  ], SheetRangeThemeModel);
1532
1540
 
1533
1541
  //#endregion
@@ -1607,6 +1615,7 @@ const InsertRowMutation = {
1607
1615
  const { worksheet } = target;
1608
1616
  const rowManager = worksheet.getRowManager();
1609
1617
  const { range, rowInfo } = params;
1618
+ if (rowInfo && !Object.values(rowInfo).every(_univerjs_core.isValidRowDimensions)) return false;
1610
1619
  const { startRow, endRow } = range;
1611
1620
  rowManager.insertRowsWithData(startRow, endRow, rowInfo);
1612
1621
  const insertedRowCount = endRow - startRow + 1;
@@ -1632,6 +1641,7 @@ const InsertColMutation = {
1632
1641
  const { worksheet } = target;
1633
1642
  const columnManager = worksheet.getColumnManager();
1634
1643
  const { range, colInfo } = params;
1644
+ if (colInfo && !Object.values(colInfo).every(_univerjs_core.isValidColumnDimensions)) return false;
1635
1645
  const { startColumn, endColumn } = range;
1636
1646
  columnManager.insertColumnsWithData(startColumn, endColumn, colInfo);
1637
1647
  const insertedColumnCount = endColumn - startColumn + 1;
@@ -1966,6 +1976,7 @@ const SetColDataMutation = {
1966
1976
  type: _univerjs_core.CommandType.MUTATION,
1967
1977
  handler: (accessor, params) => {
1968
1978
  const { columnData } = params;
1979
+ if (!Object.values(columnData).every(_univerjs_core.isValidColumnDimensions)) return false;
1969
1980
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
1970
1981
  const target = getSheetCommandTarget(univerInstanceService, params);
1971
1982
  if (!target) return false;
@@ -2407,7 +2418,10 @@ const overwriteCellPropertiesSet = /* @__PURE__ */ new Set([
2407
2418
  "fd"
2408
2419
  ]);
2409
2420
  function mergeCellData(newValue, oldValue, styles, isOverrideStyle = false) {
2410
- const type = getCellType(styles, newValue, oldValue);
2421
+ var _previousStyle$n, _styles$getStyleByCel;
2422
+ const canPreserveValue = newValue.v === void 0 && newValue.t === void 0 && oldValue.t != null;
2423
+ const previousStyle = canPreserveValue ? styles.getStyleByCell(oldValue) : void 0;
2424
+ const type = canPreserveValue ? oldValue.t : getCellType(styles, newValue, oldValue);
2411
2425
  Object.keys(newValue).forEach((key) => {
2412
2426
  const cellPropertyKey = key;
2413
2427
  if (overwriteCellPropertiesSet.has(cellPropertyKey)) {
@@ -2424,9 +2438,14 @@ function mergeCellData(newValue, oldValue, styles, isOverrideStyle = false) {
2424
2438
  delete oldValue.ft;
2425
2439
  delete oldValue.fd;
2426
2440
  }
2427
- if (oldValue.v !== void 0) {
2428
- oldValue.t = type;
2429
- oldValue.v = getCellValue(type, oldValue);
2441
+ const numberFormatChanged = canPreserveValue && (previousStyle === null || previousStyle === void 0 || (_previousStyle$n = previousStyle.n) === null || _previousStyle$n === void 0 ? void 0 : _previousStyle$n.pattern) !== ((_styles$getStyleByCel = styles.getStyleByCell(oldValue)) === null || _styles$getStyleByCel === void 0 || (_styles$getStyleByCel = _styles$getStyleByCel.n) === null || _styles$getStyleByCel === void 0 ? void 0 : _styles$getStyleByCel.pattern);
2442
+ if (oldValue.v !== void 0 && (!canPreserveValue || numberFormatChanged)) {
2443
+ const nextType = numberFormatChanged ? getCellType(styles, newValue, {
2444
+ ...oldValue,
2445
+ s: previousStyle
2446
+ }) : type;
2447
+ oldValue.t = nextType;
2448
+ oldValue.v = getCellValue(nextType, oldValue);
2430
2449
  }
2431
2450
  if (oldValue.v === null) {
2432
2451
  delete oldValue.t;
@@ -2473,6 +2492,7 @@ const SetRowDataMutation = {
2473
2492
  type: _univerjs_core.CommandType.MUTATION,
2474
2493
  handler: (accessor, params) => {
2475
2494
  const { rowData } = params;
2495
+ if (!Object.values(rowData).every(_univerjs_core.isValidRowDimensions)) return false;
2476
2496
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
2477
2497
  const target = getSheetCommandTarget(univerInstanceService, params);
2478
2498
  if (!target) return false;
@@ -2577,6 +2597,8 @@ const SetWorksheetColWidthMutation = {
2577
2597
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
2578
2598
  const target = getSheetCommandTarget(univerInstanceService, params);
2579
2599
  if (!target) return false;
2600
+ const dimensions = params.colWidth;
2601
+ if (typeof dimensions === "number" ? !(0, _univerjs_core.isValidSheetDimension)(dimensions) : dimensions == null || typeof dimensions !== "object" || Object.values(dimensions).some((value) => value != null && !(0, _univerjs_core.isValidSheetDimension)(value))) return false;
2580
2602
  const { worksheet } = target;
2581
2603
  const manager = worksheet.getColumnManager();
2582
2604
  const ranges = params.ranges;
@@ -2721,6 +2743,8 @@ const SetWorksheetRowHeightMutation = {
2721
2743
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
2722
2744
  const target = getSheetCommandTarget(univerInstanceService, params);
2723
2745
  if (!target) return false;
2746
+ const dimensions = params.rowHeight;
2747
+ if (typeof dimensions === "number" ? !(0, _univerjs_core.isValidSheetDimension)(dimensions) : dimensions == null || typeof dimensions !== "object" || Object.values(dimensions).some((value) => value != null && !(0, _univerjs_core.isValidSheetDimension)(value))) return false;
2724
2748
  const { worksheet } = target;
2725
2749
  const manager = worksheet.getRowManager();
2726
2750
  for (const { startRow, endRow } of ranges) for (let rowIndex = startRow; rowIndex <= endRow; rowIndex++) if (typeof rowHeight === "number") manager.setRowHeight(rowIndex, rowHeight);
@@ -2750,6 +2774,7 @@ const SetWorksheetRowAutoHeightMutation = {
2750
2774
  type: _univerjs_core.CommandType.MUTATION,
2751
2775
  handler: (accessor, params) => {
2752
2776
  const { rowsAutoHeightInfo } = params;
2777
+ if (rowsAutoHeightInfo.some(({ autoHeight }) => autoHeight != null && !(0, _univerjs_core.isValidSheetDimension)(autoHeight))) return false;
2753
2778
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
2754
2779
  const target = getSheetCommandTarget(univerInstanceService, params);
2755
2780
  if (!target) return false;
@@ -11972,6 +11997,7 @@ let AutoFillService = class AutoFillService extends _univerjs_core.Disposable {
11972
11997
  direction = _univerjs_core.Direction.RIGHT;
11973
11998
  target.startColumn = source.endColumn + 1;
11974
11999
  } else return false;
12000
+ this.setShowMenu(false);
11975
12001
  this.direction = direction;
11976
12002
  const autoFillSource = this._injector.invoke((accessor) => rangeToDiscreteRange(source, accessor, unitId, subUnitId));
11977
12003
  const autoFillTarget = this._injector.invoke((accessor) => rangeToDiscreteRange(target, accessor, unitId, subUnitId));
@@ -12024,7 +12050,7 @@ let AutoFillService = class AutoFillService extends _univerjs_core.Disposable {
12024
12050
  getAllHooks() {
12025
12051
  return this._hooks;
12026
12052
  }
12027
- getActiveHooks() {
12053
+ getActiveHooks(applyType = this.applyType) {
12028
12054
  const { source, target, unitId, subUnitId } = this.autoFillLocation || {};
12029
12055
  if (!source || !target || !unitId || !subUnitId) return [];
12030
12056
  const enabledHooks = this._hooks.filter((h) => {
@@ -12034,7 +12060,7 @@ let AutoFillService = class AutoFillService extends _univerjs_core.Disposable {
12034
12060
  target,
12035
12061
  unitId,
12036
12062
  subUnitId
12037
- }, this._direction, this.applyType)) === true;
12063
+ }, this._direction, applyType)) === true;
12038
12064
  });
12039
12065
  const onlyHooks = enabledHooks.filter((h) => h.type === "ONLY");
12040
12066
  if (onlyHooks.length > 0) return this._getOneByPriority(onlyHooks);
@@ -12083,7 +12109,6 @@ let AutoFillService = class AutoFillService extends _univerjs_core.Disposable {
12083
12109
  }
12084
12110
  fillData(applyType) {
12085
12111
  var _activeWorkbook$getAc;
12086
- this.applyType = applyType;
12087
12112
  const activeWorkbook = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
12088
12113
  const activeUnitId = activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId();
12089
12114
  const activeSubUnitId = activeWorkbook === null || activeWorkbook === void 0 || (_activeWorkbook$getAc = activeWorkbook.getActiveSheet()) === null || _activeWorkbook$getAc === void 0 ? void 0 : _activeWorkbook$getAc.getSheetId();
@@ -12094,12 +12119,30 @@ let AutoFillService = class AutoFillService extends _univerjs_core.Disposable {
12094
12119
  const worksheet = workbook.getSheetBySheetId(subUnitId);
12095
12120
  if (!worksheet) return false;
12096
12121
  const direction = this.direction;
12122
+ const activeHooks = this.getActiveHooks(applyType);
12123
+ const fillCallbacks = activeHooks.map((hook) => {
12124
+ var _hook$onPrepareFillDa;
12125
+ return ((_hook$onPrepareFillDa = hook.onPrepareFillData) === null || _hook$onPrepareFillDa === void 0 ? void 0 : _hook$onPrepareFillDa.call(hook, {
12126
+ source,
12127
+ target,
12128
+ unitId,
12129
+ subUnitId
12130
+ }, direction, applyType)) ?? (() => {
12131
+ var _hook$onFillData;
12132
+ return (_hook$onFillData = hook.onFillData) === null || _hook$onFillData === void 0 ? void 0 : _hook$onFillData.call(hook, {
12133
+ source,
12134
+ target,
12135
+ unitId,
12136
+ subUnitId
12137
+ }, direction, applyType);
12138
+ });
12139
+ });
12140
+ this.applyType = applyType;
12097
12141
  if (this._prevUndos.length > 0) this._prevUndos.forEach((undo) => {
12098
12142
  this._commandService.syncExecuteCommand(undo.id, undo.params);
12099
12143
  });
12100
12144
  this._prevUndos = [];
12101
12145
  const selection = _univerjs_core.Rectangle.union(discreteRangeToRange(source), discreteRangeToRange(target));
12102
- const activeHooks = this.getActiveHooks();
12103
12146
  if (unitId === activeUnitId && subUnitId === activeSubUnitId) this._commandService.syncExecuteCommand(SetSelectionsOperation.id, {
12104
12147
  selections: [{
12105
12148
  primary: getPrimaryForRange({
@@ -12118,14 +12161,8 @@ let AutoFillService = class AutoFillService extends _univerjs_core.Disposable {
12118
12161
  });
12119
12162
  const undos = [];
12120
12163
  const redos = [];
12121
- activeHooks.forEach((hook) => {
12122
- var _hook$onFillData;
12123
- const { undos: hookUndos, redos: hookRedos } = ((_hook$onFillData = hook.onFillData) === null || _hook$onFillData === void 0 ? void 0 : _hook$onFillData.call(hook, {
12124
- source,
12125
- target,
12126
- unitId,
12127
- subUnitId
12128
- }, direction, applyType)) || {};
12164
+ fillCallbacks.forEach((fill) => {
12165
+ const { undos: hookUndos, redos: hookRedos } = fill() || {};
12129
12166
  if (hookUndos) undos.push(...hookUndos);
12130
12167
  if (hookRedos) redos.push(...hookRedos);
12131
12168
  });
@@ -13664,10 +13701,36 @@ const SetSpecificColsVisibleCommand = {
13664
13701
  });
13665
13702
  if (!target) return false;
13666
13703
  const { worksheet } = target;
13704
+ const zeroWidthRanges = [];
13705
+ for (const range of ranges) for (let column = range.startColumn; column <= range.endColumn; column++) if (worksheet.getColVisible(column) && worksheet.getColumnWidth(column) === 0) zeroWidthRanges.push({
13706
+ ...range,
13707
+ startColumn: column,
13708
+ endColumn: column
13709
+ });
13710
+ const widthRanges = _univerjs_core.Rectangle.mergeRanges(zeroWidthRanges);
13711
+ const visibilityRanges = widthRanges.length ? getHiddenColRanges(worksheet, ranges) : ranges;
13712
+ const widthRedos = [];
13713
+ const widthUndos = [];
13714
+ if (widthRanges.length) {
13715
+ const widthParams = {
13716
+ unitId,
13717
+ subUnitId,
13718
+ ranges: widthRanges,
13719
+ colWidth: worksheet.getConfig().defaultColumnWidth
13720
+ };
13721
+ widthRedos.push({
13722
+ id: SetWorksheetColWidthMutation.id,
13723
+ params: widthParams
13724
+ });
13725
+ widthUndos.push({
13726
+ id: SetWorksheetColWidthMutation.id,
13727
+ params: SetWorksheetColWidthMutationFactory(widthParams, worksheet)
13728
+ });
13729
+ }
13667
13730
  const redoMutationParams = {
13668
13731
  unitId,
13669
13732
  subUnitId,
13670
- ranges
13733
+ ranges: visibilityRanges
13671
13734
  };
13672
13735
  const setSelectionOperationParams = {
13673
13736
  unitId,
@@ -13689,13 +13752,23 @@ const SetSpecificColsVisibleCommand = {
13689
13752
  style: null
13690
13753
  }))
13691
13754
  };
13692
- const result = (0, _univerjs_core.sequenceExecute)([{
13755
+ const visibilityRedos = visibilityRanges.length ? [{
13693
13756
  id: SetColVisibleMutation.id,
13694
13757
  params: redoMutationParams
13695
- }, {
13696
- id: SetSelectionsOperation.id,
13697
- params: setSelectionOperationParams
13698
- }], commandService);
13758
+ }] : [];
13759
+ const visibilityUndos = visibilityRanges.length ? [{
13760
+ id: SetColHiddenMutation.id,
13761
+ params: undoMutationParams
13762
+ }] : [];
13763
+ const result = (0, _univerjs_core.sequenceExecute)([
13764
+ ...visibilityRedos,
13765
+ ...widthRedos,
13766
+ {
13767
+ id: SetSelectionsOperation.id,
13768
+ params: setSelectionOperationParams
13769
+ }
13770
+ ], commandService);
13771
+ if (!result.result) return false;
13699
13772
  const intercepted = sheetInterceptorService.onCommandExecute({
13700
13773
  id: SetSpecificColsVisibleCommand.id,
13701
13774
  params
@@ -13710,10 +13783,8 @@ const SetSpecificColsVisibleCommand = {
13710
13783
  accessor.get(_univerjs_core.IUndoRedoService).pushUndoRedo({
13711
13784
  unitID: unitId,
13712
13785
  undoMutations: [
13713
- {
13714
- id: SetColHiddenMutation.id,
13715
- params: undoMutationParams
13716
- },
13786
+ ...widthUndos,
13787
+ ...visibilityUndos,
13717
13788
  {
13718
13789
  id: SetSelectionsOperation.id,
13719
13790
  params: undoSetSelectionsOperationParams
@@ -13723,10 +13794,8 @@ const SetSpecificColsVisibleCommand = {
13723
13794
  ],
13724
13795
  redoMutations: [
13725
13796
  ...intercepted.preRedos ?? [],
13726
- {
13727
- id: SetColVisibleMutation.id,
13728
- params: redoMutationParams
13729
- },
13797
+ ...visibilityRedos,
13798
+ ...widthRedos,
13730
13799
  {
13731
13800
  id: SetSelectionsOperation.id,
13732
13801
  params: setSelectionOperationParams
@@ -14396,10 +14465,36 @@ const SetSpecificRowsVisibleCommand = {
14396
14465
  });
14397
14466
  if (!target) return false;
14398
14467
  const { worksheet } = target;
14468
+ const zeroHeightRanges = [];
14469
+ for (const range of ranges) for (let row = range.startRow; row <= range.endRow; row++) if (worksheet.getRowVisible(row) && worksheet.getRowHeight(row) === 0) zeroHeightRanges.push({
14470
+ ...range,
14471
+ startRow: row,
14472
+ endRow: row
14473
+ });
14474
+ const heightRanges = _univerjs_core.Rectangle.mergeRanges(zeroHeightRanges);
14475
+ const visibilityRanges = heightRanges.length ? getHiddenRowRanges(worksheet, ranges) : ranges;
14476
+ const heightRedos = [];
14477
+ const heightUndos = [];
14478
+ if (heightRanges.length) {
14479
+ const heightParams = {
14480
+ unitId,
14481
+ subUnitId,
14482
+ ranges: heightRanges,
14483
+ rowHeight: worksheet.getConfig().defaultRowHeight
14484
+ };
14485
+ heightRedos.push({
14486
+ id: SetWorksheetRowHeightMutation.id,
14487
+ params: heightParams
14488
+ });
14489
+ heightUndos.push({
14490
+ id: SetWorksheetRowHeightMutation.id,
14491
+ params: SetWorksheetRowHeightMutationFactory(heightParams, worksheet)
14492
+ });
14493
+ }
14399
14494
  const redoMutationParams = {
14400
14495
  unitId,
14401
14496
  subUnitId,
14402
- ranges
14497
+ ranges: visibilityRanges
14403
14498
  };
14404
14499
  const setSelectionOperationParams = {
14405
14500
  unitId,
@@ -14421,13 +14516,23 @@ const SetSpecificRowsVisibleCommand = {
14421
14516
  style: null
14422
14517
  }))
14423
14518
  };
14424
- const result = (0, _univerjs_core.sequenceExecute)([{
14519
+ const visibilityRedos = visibilityRanges.length ? [{
14425
14520
  id: SetRowVisibleMutation.id,
14426
14521
  params: redoMutationParams
14427
- }, {
14428
- id: SetSelectionsOperation.id,
14429
- params: setSelectionOperationParams
14430
- }], commandService);
14522
+ }] : [];
14523
+ const visibilityUndos = visibilityRanges.length ? [{
14524
+ id: SetRowHiddenMutation.id,
14525
+ params: undoMutationParams
14526
+ }] : [];
14527
+ const result = (0, _univerjs_core.sequenceExecute)([
14528
+ ...visibilityRedos,
14529
+ ...heightRedos,
14530
+ {
14531
+ id: SetSelectionsOperation.id,
14532
+ params: setSelectionOperationParams
14533
+ }
14534
+ ], commandService);
14535
+ if (!result.result) return false;
14431
14536
  const intercepted = sheetInterceptorService.onCommandExecute({
14432
14537
  id: SetSpecificRowsVisibleCommand.id,
14433
14538
  params
@@ -14443,10 +14548,8 @@ const SetSpecificRowsVisibleCommand = {
14443
14548
  unitID: unitId,
14444
14549
  undoMutations: [
14445
14550
  ...intercepted.preUndos ?? [],
14446
- {
14447
- id: SetRowHiddenMutation.id,
14448
- params: undoMutationParams
14449
- },
14551
+ ...heightUndos,
14552
+ ...visibilityUndos,
14450
14553
  {
14451
14554
  id: SetSelectionsOperation.id,
14452
14555
  params: undoSetSelectionsOperationParams
@@ -14456,10 +14559,8 @@ const SetSpecificRowsVisibleCommand = {
14456
14559
  ],
14457
14560
  redoMutations: [
14458
14561
  ...intercepted.preRedos ?? [],
14459
- {
14460
- id: SetRowVisibleMutation.id,
14461
- params: redoMutationParams
14462
- },
14562
+ ...visibilityRedos,
14563
+ ...heightRedos,
14463
14564
  {
14464
14565
  id: SetSelectionsOperation.id,
14465
14566
  params: setSelectionOperationParams
@@ -14870,6 +14971,7 @@ const DeltaColumnWidthCommand = {
14870
14971
  const { worksheet, unitId, subUnitId } = target;
14871
14972
  const { anchorCol, deltaX } = params;
14872
14973
  const destColumnWidth = worksheet.getColumnWidth(anchorCol) + deltaX;
14974
+ if (!(0, _univerjs_core.isValidSheetDimension)(destColumnWidth)) return false;
14873
14975
  const isAllSheetRange = selections.length === 1 && selections[0].range.rangeType === _univerjs_core.RANGE_TYPE.ALL;
14874
14976
  const colSelections = selections.filter((s) => s.range.rangeType === _univerjs_core.RANGE_TYPE.COLUMN);
14875
14977
  const rangeType = isAllSheetRange ? _univerjs_core.RANGE_TYPE.ALL : colSelections.some(({ range }) => {
@@ -14965,6 +15067,7 @@ const SetColWidthCommand = {
14965
15067
  id: "sheet.command.set-worksheet-col-width",
14966
15068
  handler: (accessor, params) => {
14967
15069
  var _params$ranges, _selectionManagerServ;
15070
+ if (!(0, _univerjs_core.isValidSheetDimension)(params === null || params === void 0 ? void 0 : params.value)) return false;
14968
15071
  const selectionManagerService = accessor.get(SheetsSelectionsService);
14969
15072
  const commandService = accessor.get(_univerjs_core.ICommandService);
14970
15073
  const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
@@ -16625,6 +16728,7 @@ const DeltaRowHeightCommand = {
16625
16728
  const { worksheet, subUnitId, unitId } = target;
16626
16729
  const { anchorRow, deltaY } = params;
16627
16730
  const destRowHeight = worksheet.getRowHeight(anchorRow) + deltaY;
16731
+ if (!(0, _univerjs_core.isValidSheetDimension)(destRowHeight)) return false;
16628
16732
  const isAllSheetRange = selections.length === 1 && selections[0].range.rangeType === _univerjs_core.RANGE_TYPE.ALL;
16629
16733
  const rowSelections = selections.filter((s) => s.range.rangeType === _univerjs_core.RANGE_TYPE.ROW);
16630
16734
  const rangeType = isAllSheetRange ? _univerjs_core.RANGE_TYPE.ALL : rowSelections.some(({ range }) => {
@@ -16729,6 +16833,7 @@ const SetRowHeightCommand = {
16729
16833
  id: "sheet.command.set-row-height",
16730
16834
  handler: (accessor, params) => {
16731
16835
  var _params$ranges, _selectionManagerServ;
16836
+ if (!(0, _univerjs_core.isValidSheetDimension)(params === null || params === void 0 ? void 0 : params.value)) return false;
16732
16837
  const selectionManagerService = accessor.get(SheetsSelectionsService);
16733
16838
  const commandService = accessor.get(_univerjs_core.ICommandService);
16734
16839
  const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
@@ -17473,8 +17578,9 @@ let AutoFillController = class AutoFillController extends _univerjs_core.Disposa
17473
17578
  onBeforeFillData: (location, direction) => {
17474
17579
  return this._presetAndCacheData(location, direction);
17475
17580
  },
17476
- onFillData: (location, direction, applyType) => {
17477
- return this._fillData(location, direction, applyType);
17581
+ onPrepareFillData: (location, direction, applyType) => {
17582
+ const prepared = this._prepareFillData(location, direction, applyType);
17583
+ return () => this._fillData(location, direction, applyType, prepared);
17478
17584
  }
17479
17585
  }));
17480
17586
  }
@@ -17523,7 +17629,7 @@ let AutoFillController = class AutoFillController extends _univerjs_core.Disposa
17523
17629
  const arrData = this._applyFunctions(copySquad, len, direction, applyType, customApplyFunctions, copyDataPiece, location);
17524
17630
  const arrIndex = getDataIndex(csLen, asLen, copySquad.index);
17525
17631
  applyDataInTypes[type].push({
17526
- data: arrData,
17632
+ data: arrData ?? [],
17527
17633
  index: arrIndex
17528
17634
  });
17529
17635
  });
@@ -17682,28 +17788,9 @@ let AutoFillController = class AutoFillController extends _univerjs_core.Disposa
17682
17788
  }
17683
17789
  return applyMergeRanges;
17684
17790
  }
17685
- _fillData(location, direction, applyType) {
17686
- var _this$_univerInstance4;
17687
- const undos = [];
17688
- const redos = [];
17689
- let hasStyle = true;
17690
- if (applyType === "NO_FORMAT") {
17691
- hasStyle = false;
17692
- applyType = "SERIES";
17693
- }
17694
- const { source, target, unitId, subUnitId } = location;
17695
- if (!source || !target || direction == null) return {
17696
- undos,
17697
- redos
17698
- };
17699
- const sourceRange = discreteRangeToRange(source);
17700
- const targetRange = discreteRangeToRange(target);
17701
- const { cols: targetCols, rows: targetRows } = target;
17702
- const { cols: sourceCols, rows: sourceRows } = source;
17703
- const copyData = this._copyData;
17704
- let csLen;
17705
- if (direction === _univerjs_core.Direction.DOWN || direction === _univerjs_core.Direction.UP) csLen = sourceRows.length;
17706
- else csLen = sourceCols.length;
17791
+ _getFillCells(location, direction, applyType, hasStyle, csLen) {
17792
+ const { rows: targetRows, cols: targetCols } = location.target;
17793
+ const copyData = _univerjs_core.Tools.deepClone(this._copyData);
17707
17794
  const applyDatas = [];
17708
17795
  if (direction === _univerjs_core.Direction.DOWN || direction === _univerjs_core.Direction.UP) {
17709
17796
  const asLen = targetRows.length;
@@ -17734,20 +17821,26 @@ let AutoFillController = class AutoFillController extends _univerjs_core.Disposa
17734
17821
  applyDatas.push(row);
17735
17822
  });
17736
17823
  }
17737
- let applyMergeRanges = [];
17824
+ return applyDatas;
17825
+ }
17826
+ _prepareFillData(location, direction, applyType) {
17827
+ var _this$_univerInstance4;
17828
+ const hasStyle = applyType !== "NO_FORMAT";
17829
+ const effectiveApplyType = hasStyle ? applyType : "SERIES";
17830
+ const { source, target, unitId } = location;
17831
+ const sourceRange = discreteRangeToRange(source);
17832
+ const targetRange = discreteRangeToRange(target);
17833
+ const { cols: targetCols, rows: targetRows } = target;
17834
+ const { cols: sourceCols, rows: sourceRows } = source;
17835
+ let csLen;
17836
+ if (direction === _univerjs_core.Direction.DOWN || direction === _univerjs_core.Direction.UP) csLen = sourceRows.length;
17837
+ else csLen = sourceCols.length;
17838
+ const applyDatas = this._getFillCells(location, direction, effectiveApplyType, hasStyle, csLen);
17839
+ const applyMergeRanges = hasStyle ? this._getMergeApplyData(sourceRange, targetRange, direction, csLen, location) : [];
17738
17840
  const style = (_this$_univerInstance4 = this._univerInstanceService.getUnit(unitId)) === null || _this$_univerInstance4 === void 0 ? void 0 : _this$_univerInstance4.getStyles();
17739
- if (hasStyle) {
17740
- applyMergeRanges = this._getMergeApplyData(sourceRange, targetRange, direction, csLen, location);
17741
- applyDatas.forEach((row) => {
17742
- row.forEach((cellData) => {
17743
- if (cellData && style) {
17744
- if (style) cellData.s = style.getStyleByCell(cellData);
17745
- }
17746
- });
17747
- });
17748
- } else applyDatas.forEach((row, rowIndex) => {
17841
+ applyDatas.forEach((row, rowIndex) => {
17749
17842
  row.forEach((cellData, colIndex) => {
17750
- if (cellData && style) cellData.s = style.getStyleByCell(this._beforeApplyData[rowIndex][colIndex]) || null;
17843
+ if (cellData && style) cellData.s = hasStyle ? style.getStyleByCell(cellData) : style.getStyleByCell(this._beforeApplyData[rowIndex][colIndex]) || null;
17751
17844
  });
17752
17845
  });
17753
17846
  if (applyType === "ONLY_FORMAT") applyDatas.forEach((row, rowIndex) => {
@@ -17763,30 +17856,59 @@ let AutoFillController = class AutoFillController extends _univerjs_core.Disposa
17763
17856
  }
17764
17857
  });
17765
17858
  });
17766
- if (hasStyle) {
17767
- var _this$_univerInstance5;
17768
- const deleteMergeRanges = [];
17769
- 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();
17770
- if (mergeData) mergeData.forEach((merge) => {
17771
- if (_univerjs_core.Rectangle.intersects(merge, targetRange)) deleteMergeRanges.push(merge);
17859
+ const cellValue = new _univerjs_core.ObjectMatrix();
17860
+ targetRows.forEach((row, rowIndex) => {
17861
+ targetCols.forEach((col, colIndex) => {
17862
+ const cell = applyDatas[rowIndex][colIndex];
17863
+ if (cell) cellValue.setValue(row, col, cell);
17864
+ });
17865
+ });
17866
+ const cellValueMatrix = cellValue.getMatrix();
17867
+ this._autoFillService.getActiveHooks(applyType).forEach((hook) => {
17868
+ var _hook$onValidateFillD;
17869
+ (_hook$onValidateFillD = hook.onValidateFillData) === null || _hook$onValidateFillD === void 0 || _hook$onValidateFillD.call(hook, location, direction, applyType, cellValueMatrix);
17870
+ });
17871
+ return {
17872
+ cellValue: cellValueMatrix,
17873
+ applyMergeRanges,
17874
+ hasStyle
17875
+ };
17876
+ }
17877
+ _getRemoveMergeMutations(location) {
17878
+ var _this$_univerInstance5;
17879
+ const { unitId, subUnitId, target } = location;
17880
+ const targetRange = discreteRangeToRange(target);
17881
+ const undos = [];
17882
+ const redos = [];
17883
+ const deleteMergeRanges = ((_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().filter((merge) => _univerjs_core.Rectangle.intersects(merge, targetRange))) ?? [];
17884
+ if (deleteMergeRanges.length) {
17885
+ const removeMergeMutationParams = {
17886
+ unitId,
17887
+ subUnitId,
17888
+ ranges: deleteMergeRanges
17889
+ };
17890
+ const undoRemoveMergeMutationParams = this._injector.invoke(RemoveMergeUndoMutationFactory, removeMergeMutationParams);
17891
+ redos.push({
17892
+ id: RemoveWorksheetMergeMutation.id,
17893
+ params: removeMergeMutationParams
17894
+ });
17895
+ undos.unshift({
17896
+ id: AddWorksheetMergeMutation.id,
17897
+ params: undoRemoveMergeMutationParams
17772
17898
  });
17773
- if (deleteMergeRanges.length) {
17774
- const removeMergeMutationParams = {
17775
- unitId,
17776
- subUnitId,
17777
- ranges: deleteMergeRanges
17778
- };
17779
- const undoRemoveMergeMutationParams = this._injector.invoke(RemoveMergeUndoMutationFactory, removeMergeMutationParams);
17780
- redos.push({
17781
- id: RemoveWorksheetMergeMutation.id,
17782
- params: removeMergeMutationParams
17783
- });
17784
- undos.unshift({
17785
- id: AddWorksheetMergeMutation.id,
17786
- params: undoRemoveMergeMutationParams
17787
- });
17788
- }
17789
17899
  }
17900
+ return {
17901
+ undos,
17902
+ redos
17903
+ };
17904
+ }
17905
+ _fillData(location, direction, applyType, prepared) {
17906
+ const { target, unitId, subUnitId } = location;
17907
+ const { cellValue, applyMergeRanges, hasStyle } = prepared;
17908
+ const { undos, redos } = hasStyle ? this._getRemoveMergeMutations(location) : {
17909
+ undos: [],
17910
+ redos: []
17911
+ };
17790
17912
  const clearMutationParams = {
17791
17913
  subUnitId,
17792
17914
  unitId,
@@ -17801,22 +17923,15 @@ let AutoFillController = class AutoFillController extends _univerjs_core.Disposa
17801
17923
  id: SetRangeValuesMutation.id,
17802
17924
  params: undoClearMutationParams
17803
17925
  });
17804
- const cellValue = new _univerjs_core.ObjectMatrix();
17805
- targetRows.forEach((row, rowIndex) => {
17806
- targetCols.forEach((col, colIndex) => {
17807
- if (applyDatas[rowIndex][colIndex]) cellValue.setValue(row, col, applyDatas[rowIndex][colIndex]);
17808
- });
17809
- });
17810
- const cellValueMatrix = cellValue.getMatrix();
17811
17926
  const setRangeValuesMutationParams = {
17812
17927
  subUnitId,
17813
17928
  unitId,
17814
- cellValue: cellValueMatrix
17929
+ cellValue
17815
17930
  };
17816
17931
  const undoSetRangeValuesMutationParams = this._injector.invoke(SetRangeValuesUndoMutationFactory, setRangeValuesMutationParams);
17817
- this._autoFillService.getActiveHooks().forEach((hook) => {
17932
+ this._autoFillService.getActiveHooks(applyType).forEach((hook) => {
17818
17933
  var _hook$onBeforeSubmit;
17819
- (_hook$onBeforeSubmit = hook.onBeforeSubmit) === null || _hook$onBeforeSubmit === void 0 || _hook$onBeforeSubmit.call(hook, location, direction, applyType, cellValueMatrix);
17934
+ (_hook$onBeforeSubmit = hook.onBeforeSubmit) === null || _hook$onBeforeSubmit === void 0 || _hook$onBeforeSubmit.call(hook, location, direction, applyType, cellValue);
17820
17935
  });
17821
17936
  undos.unshift({
17822
17937
  id: SetRangeValuesMutation.id,
@@ -18173,7 +18288,7 @@ SheetsFreezeSyncController = __decorate([
18173
18288
  //#endregion
18174
18289
  //#region src/controllers/permission/sheet-permission-check.controller.ts
18175
18290
  let SheetPermissionCheckController = class SheetPermissionCheckController extends _univerjs_core.Disposable {
18176
- constructor(_commandService, _univerInstanceService, _permissionService, _selectionManagerService, _rangeProtectionRuleModel, _worksheetProtectionRuleModel, _localeService, _lexerTreeBuilder, _definedNamesService) {
18291
+ constructor(_commandService, _univerInstanceService, _permissionService, _selectionManagerService, _rangeProtectionRuleModel, _worksheetProtectionRuleModel, _localeService, _lexerTreeBuilder, _definedNamesService, _autoFillService, _formulaDataModel, _functionService) {
18177
18292
  super();
18178
18293
  this._commandService = _commandService;
18179
18294
  this._univerInstanceService = _univerInstanceService;
@@ -18184,6 +18299,9 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
18184
18299
  this._localeService = _localeService;
18185
18300
  this._lexerTreeBuilder = _lexerTreeBuilder;
18186
18301
  this._definedNamesService = _definedNamesService;
18302
+ this._autoFillService = _autoFillService;
18303
+ this._formulaDataModel = _formulaDataModel;
18304
+ this._functionService = _functionService;
18187
18305
  _defineProperty(this, "disposableCollection", new _univerjs_core.DisposableCollection());
18188
18306
  _defineProperty(this, "_triggerPermissionUIEvent$", new rxjs.Subject());
18189
18307
  _defineProperty(this, "triggerPermissionUIEvent$", this._triggerPermissionUIEvent$.asObservable());
@@ -18191,6 +18309,29 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
18191
18309
  }
18192
18310
  _initialize() {
18193
18311
  this._commandExecutedListener();
18312
+ this.disposeWithMe(this._autoFillService.addHook({
18313
+ id: "permission-check",
18314
+ onValidateFillData: ({ unitId, subUnitId }, _direction, applyType, cellValue) => {
18315
+ if (applyType === "ONLY_FORMAT") return;
18316
+ const formulas = new _univerjs_core.ObjectMatrix(this._formulaDataModel.updateFormulaData(unitId, subUnitId, cellValue));
18317
+ new _univerjs_core.ObjectMatrix(cellValue).forValue((row, column) => {
18318
+ const formula = formulas.getValue(row, column);
18319
+ if (!(formula === null || formula === void 0 ? void 0 : formula.f)) return;
18320
+ const formulaString = this._lexerTreeBuilder.moveFormulaRefOffset(formula.f, formula.x ?? 0, formula.y ?? 0);
18321
+ if (!this._permissionCheckWithFormula({
18322
+ unitId,
18323
+ subUnitId,
18324
+ range: {
18325
+ startRow: row,
18326
+ endRow: row,
18327
+ startColumn: column,
18328
+ endColumn: column
18329
+ },
18330
+ value: { f: formulaString }
18331
+ })) this.blockExecuteWithoutPermission(this._localeService.t("sheets.permission.dialog.formulaErr"));
18332
+ });
18333
+ }
18334
+ }));
18194
18335
  }
18195
18336
  _commandExecutedListener() {
18196
18337
  this.disposeWithMe(this._commandService.beforeCommandExecuted((commandInfo) => {
@@ -18515,61 +18656,18 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
18515
18656
  _permissionCheckWithFormula(params) {
18516
18657
  const target = getSheetCommandTarget(this._univerInstanceService, params);
18517
18658
  if (!target) return false;
18518
- const { workbook, unitId, subUnitId } = target;
18659
+ const { unitId, subUnitId } = target;
18519
18660
  const formulaString = params.value.f;
18520
18661
  if (formulaString) {
18521
- const definedNameStr = formulaString.substring(1);
18522
- const definedName = this._definedNamesService.getValueByName(unitId, definedNameStr);
18523
- if (definedName) {
18524
- let formulaOrRefString = definedName.formulaOrRefString;
18525
- if (formulaOrRefString.startsWith(_univerjs_engine_formula.operatorToken.EQUALS)) formulaOrRefString = formulaOrRefString.slice(1);
18526
- const refRangesArr = formulaOrRefString.split(",");
18527
- for (let i = 0; i < refRangesArr.length; i++) {
18528
- const refRange = refRangesArr[i];
18529
- const { sheetName, range } = (0, _univerjs_engine_formula.deserializeRangeWithSheet)(refRange);
18530
- if (sheetName) {
18531
- const targetSheet = workbook.getSheetBySheetName(sheetName);
18532
- if (!targetSheet) return true;
18533
- const { startRow, endRow, startColumn, endColumn } = range;
18534
- for (let r = startRow; r <= endRow; r++) for (let c = startColumn; c <= endColumn; c++) {
18535
- var _cell$selectionProtec2;
18536
- const cell = targetSheet.getCell(r, c);
18537
- const permission = cell === null || cell === void 0 || (_cell$selectionProtec2 = cell.selectionProtection) === null || _cell$selectionProtec2 === void 0 ? void 0 : _cell$selectionProtec2[0];
18538
- if ((permission === null || permission === void 0 ? void 0 : permission[_univerjs_protocol.UnitAction.View]) === false) return false;
18539
- }
18540
- }
18541
- }
18542
- return true;
18543
- } else {
18544
- const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaString);
18545
- if (!sequenceNodes) return true;
18546
- for (let i = 0; i < sequenceNodes.length; i++) {
18547
- const node = sequenceNodes[i];
18548
- if (typeof node === "string" || node.nodeType !== _univerjs_engine_formula.sequenceNodeType.REFERENCE) continue;
18549
- const { token } = node;
18550
- const { unitId: sequenceGridUnitId, sheetName, range } = (0, _univerjs_engine_formula.deserializeRangeWithSheetWithCache)(token);
18551
- let sequenceGridWorkbook = workbook;
18552
- if (sequenceGridUnitId && sequenceGridUnitId !== unitId) {
18553
- const _sequenceGridWorkbook = this._univerInstanceService.getUnit(sequenceGridUnitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
18554
- if (!_sequenceGridWorkbook) return true;
18555
- sequenceGridWorkbook = _sequenceGridWorkbook;
18556
- }
18557
- const sequenceGridWorksheet = sheetName ? sequenceGridWorkbook.getSheetBySheetName(sheetName) : sequenceGridWorkbook.getActiveSheet();
18558
- if (!sequenceGridWorksheet) return true;
18559
- if (sheetName) {
18560
- const viewPermission = this._permissionService.getPermissionPoint(new WorksheetViewPermission(sequenceGridWorkbook.getUnitId(), sequenceGridWorksheet.getSheetId()).id);
18561
- if (!viewPermission || viewPermission.value === false) return false;
18562
- }
18563
- const { startRow, endRow, startColumn, endColumn } = range;
18564
- for (let r = startRow; r <= endRow; r++) for (let c = startColumn; c <= endColumn; c++) {
18565
- var _cell$selectionProtec3;
18566
- const cell = sequenceGridWorksheet.getCell(r, c);
18567
- const permission = cell === null || cell === void 0 || (_cell$selectionProtec3 = cell.selectionProtection) === null || _cell$selectionProtec3 === void 0 ? void 0 : _cell$selectionProtec3[0];
18568
- if ((permission === null || permission === void 0 ? void 0 : permission[_univerjs_protocol.UnitAction.View]) === false) return false;
18569
- }
18570
- }
18571
- return true;
18572
- }
18662
+ var _this$_selectionManag3;
18663
+ const ranges = params.range ? [params.range] : ((_this$_selectionManag3 = this._selectionManagerService.getCurrentSelections()) === null || _this$_selectionManag3 === void 0 ? void 0 : _this$_selectionManag3.map((selection) => selection.range)) ?? [];
18664
+ for (const range of ranges) for (let row = range.startRow; row <= range.endRow; row++) for (let column = range.startColumn; column <= range.endColumn; column++) if (!this._permissionCheckFormulaReferences(formulaString, {
18665
+ unitId,
18666
+ subUnitId,
18667
+ row,
18668
+ column
18669
+ })) return false;
18670
+ return true;
18573
18671
  }
18574
18672
  const { range } = params;
18575
18673
  if (range) {
@@ -18580,6 +18678,73 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
18580
18678
  }
18581
18679
  return true;
18582
18680
  }
18681
+ _getFormulaReferenceWorkbook(unitId, qualifier) {
18682
+ const workbook = this._univerInstanceService.getUnit(qualifier || unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
18683
+ if (workbook || !qualifier) return workbook;
18684
+ const workbooks = this._univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).filter((item) => item.getSnapshot().name.length > 0);
18685
+ const exactMatches = workbooks.filter((item) => item.getSnapshot().name.toLowerCase() === qualifier.toLowerCase());
18686
+ const matches = exactMatches.length > 0 ? exactMatches : workbooks.filter((item) => (0, _univerjs_engine_formula.normalizeFormulaUnitName)(item.getSnapshot().name) === (0, _univerjs_engine_formula.normalizeFormulaUnitName)(qualifier));
18687
+ return matches.length === 1 ? matches[0] : null;
18688
+ }
18689
+ _permissionCheckFormulaReferences(formulaString, context, visitingNames = /* @__PURE__ */ new Set(), referenceOffset) {
18690
+ const { unitId, subUnitId, row, column } = context;
18691
+ const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaString) ?? [];
18692
+ for (let index = 0; index < sequenceNodes.length; index++) {
18693
+ const node = sequenceNodes[index];
18694
+ if (typeof node === "string" || node.nodeType !== _univerjs_engine_formula.sequenceNodeType.REFERENCE && node.nodeType !== _univerjs_engine_formula.sequenceNodeType.FUNCTION) continue;
18695
+ const nextNode = sequenceNodes[index + 1];
18696
+ if (node.nodeType === _univerjs_engine_formula.sequenceNodeType.FUNCTION && typeof nextNode === "string" && nextNode.trim() === _univerjs_engine_formula.matchToken.OPEN_BRACKET && this._functionService.hasExecutor(node.token.trim().toUpperCase())) continue;
18697
+ let nameToken = node.token.trim();
18698
+ if (node.nodeType === _univerjs_engine_formula.sequenceNodeType.FUNCTION) {
18699
+ const parts = nameToken.split("!");
18700
+ if (parts.length === 2) {
18701
+ var _this$_univerInstance;
18702
+ const unqualifiedName = parts[1].trim();
18703
+ const unscopedName = this._definedNamesService.getValueByName(unitId, unqualifiedName);
18704
+ const localSheetId = unscopedName === null || unscopedName === void 0 ? void 0 : unscopedName.localSheetId;
18705
+ const localSheet = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(localSheetId ?? "");
18706
+ if (unscopedName && (localSheetId == null || localSheetId === "AllDefaultWorkbook" || (localSheet === null || localSheet === void 0 ? void 0 : localSheet.getName()) === parts[0])) nameToken = unqualifiedName;
18707
+ }
18708
+ }
18709
+ const definedName = this._definedNamesService.getValueByName(unitId, nameToken, subUnitId);
18710
+ if (definedName) {
18711
+ const nameKey = `${unitId}:${definedName.id}`;
18712
+ if (visitingNames.has(nameKey)) continue;
18713
+ visitingNames.add(nameKey);
18714
+ const definition = definedName.formulaOrRefString;
18715
+ const isFormula = definition.startsWith(_univerjs_engine_formula.operatorToken.EQUALS);
18716
+ const offset = isFormula ? void 0 : {
18717
+ x: column - (definedName.localSheetId === "AllDefaultWorkbook" ? 1 : 0),
18718
+ y: row
18719
+ };
18720
+ const permitted = this._permissionCheckFormulaReferences(isFormula ? definition : `${_univerjs_engine_formula.operatorToken.EQUALS}${definition}`, context, visitingNames, offset);
18721
+ visitingNames.delete(nameKey);
18722
+ if (!permitted) return false;
18723
+ continue;
18724
+ }
18725
+ if (node.nodeType !== _univerjs_engine_formula.sequenceNodeType.REFERENCE) continue;
18726
+ const { unitQualifier, sheetName } = (0, _univerjs_engine_formula.handleRefStringInfo)(node.token.trim());
18727
+ const referenceWorkbook = this._getFormulaReferenceWorkbook(unitId, unitQualifier);
18728
+ const referenceWorksheet = sheetName ? referenceWorkbook === null || referenceWorkbook === void 0 ? void 0 : referenceWorkbook.getSheetBySheetName(sheetName) : referenceWorkbook === null || referenceWorkbook === void 0 ? void 0 : referenceWorkbook.getSheetBySheetId(subUnitId);
18729
+ if (!referenceWorkbook || !referenceWorksheet) continue;
18730
+ const referenceUnitId = referenceWorkbook.getUnitId();
18731
+ const referenceSheetId = referenceWorksheet.getSheetId();
18732
+ const { range } = (0, _univerjs_engine_formula.deserializeRangeWithSheetWithCache)(node.token);
18733
+ const referenceRange = referenceOffset ? (0, _univerjs_core.moveRangeByOffset)({ ...range }, referenceOffset.x, referenceOffset.y) : range;
18734
+ if (referenceOffset) {
18735
+ const wrap = (value, limit) => (value % limit + limit) % limit;
18736
+ referenceRange.startRow = wrap(referenceRange.startRow, _univerjs_core.MAX_ROW_COUNT);
18737
+ referenceRange.endRow = wrap(referenceRange.endRow, _univerjs_core.MAX_ROW_COUNT);
18738
+ referenceRange.startColumn = wrap(referenceRange.startColumn, _univerjs_core.MAX_COLUMN_COUNT);
18739
+ referenceRange.endColumn = wrap(referenceRange.endColumn, _univerjs_core.MAX_COLUMN_COUNT);
18740
+ }
18741
+ if (!this.permissionCheckWithRanges({
18742
+ worksheetTypes: [WorksheetViewPermission],
18743
+ rangeTypes: [RangeProtectionPermissionViewPoint]
18744
+ }, [referenceRange], referenceUnitId, referenceSheetId)) return false;
18745
+ }
18746
+ return true;
18747
+ }
18583
18748
  _permissionCheckBySetRangeValue(permissionTypes, params) {
18584
18749
  const { unitId, subUnitId, value, range } = params;
18585
18750
  let ranges = [];
@@ -18675,11 +18840,11 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
18675
18840
  return true;
18676
18841
  }
18677
18842
  _permissionCheckWithInsertOrDeleteMoveRange(direction, params) {
18678
- var _this$_selectionManag3;
18843
+ var _this$_selectionManag4;
18679
18844
  const target = getSheetCommandTarget(this._univerInstanceService);
18680
18845
  if (!target) return false;
18681
18846
  const { worksheet, unitId, subUnitId } = target;
18682
- 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);
18847
+ const range = (params === null || params === void 0 ? void 0 : params.range) ?? ((_this$_selectionManag4 = this._selectionManagerService.getCurrentLastSelection()) === null || _this$_selectionManag4 === void 0 ? void 0 : _this$_selectionManag4.range);
18683
18848
  if (!range) return false;
18684
18849
  if (!this.permissionCheckWithRanges({
18685
18850
  workbookTypes: [WorkbookEditablePermission],
@@ -18704,7 +18869,10 @@ SheetPermissionCheckController = __decorate([
18704
18869
  __decorateParam(5, (0, _univerjs_core.Inject)(WorksheetProtectionRuleModel)),
18705
18870
  __decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
18706
18871
  __decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_engine_formula.LexerTreeBuilder)),
18707
- __decorateParam(8, _univerjs_engine_formula.IDefinedNamesService)
18872
+ __decorateParam(8, _univerjs_engine_formula.IDefinedNamesService),
18873
+ __decorateParam(9, IAutoFillService),
18874
+ __decorateParam(10, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaDataModel)),
18875
+ __decorateParam(11, _univerjs_engine_formula.IFunctionService)
18708
18876
  ], SheetPermissionCheckController);
18709
18877
 
18710
18878
  //#endregion
@@ -19570,7 +19738,7 @@ RangeProtectionCache = __decorate([
19570
19738
  //#endregion
19571
19739
  //#region package.json
19572
19740
  var name = "@univerjs/sheets";
19573
- var version = "1.1.0";
19741
+ var version = "1.3.0";
19574
19742
 
19575
19743
  //#endregion
19576
19744
  //#region src/controllers/active-worksheet.controller.ts
@@ -21500,7 +21668,10 @@ function convertPositionCellToSheetOverGrid(unitId, subUnitId, cellOverGridPosit
21500
21668
  });
21501
21669
  const left = (0, _univerjs_engine_render.precisionTo)(startSelectionX + fromColumnOffset, 1);
21502
21670
  const top = (0, _univerjs_engine_render.precisionTo)(startSelectionY + fromRowOffset, 1);
21503
- const endSelectionCell = skeleton.getCellIndexAndOffsetByPosition(left + width, top + height);
21671
+ const endSelectionCell = skeleton.getCellIndexAndOffsetByPosition(left + width, top + height, 1, 1, {
21672
+ x: 0,
21673
+ y: 0
21674
+ });
21504
21675
  return {
21505
21676
  unitId,
21506
21677
  subUnitId,