@univerjs/sheets 1.2.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;
@@ -13676,10 +13701,36 @@ const SetSpecificColsVisibleCommand = {
13676
13701
  });
13677
13702
  if (!target) return false;
13678
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
+ }
13679
13730
  const redoMutationParams = {
13680
13731
  unitId,
13681
13732
  subUnitId,
13682
- ranges
13733
+ ranges: visibilityRanges
13683
13734
  };
13684
13735
  const setSelectionOperationParams = {
13685
13736
  unitId,
@@ -13701,13 +13752,23 @@ const SetSpecificColsVisibleCommand = {
13701
13752
  style: null
13702
13753
  }))
13703
13754
  };
13704
- const result = (0, _univerjs_core.sequenceExecute)([{
13755
+ const visibilityRedos = visibilityRanges.length ? [{
13705
13756
  id: SetColVisibleMutation.id,
13706
13757
  params: redoMutationParams
13707
- }, {
13708
- id: SetSelectionsOperation.id,
13709
- params: setSelectionOperationParams
13710
- }], 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;
13711
13772
  const intercepted = sheetInterceptorService.onCommandExecute({
13712
13773
  id: SetSpecificColsVisibleCommand.id,
13713
13774
  params
@@ -13722,10 +13783,8 @@ const SetSpecificColsVisibleCommand = {
13722
13783
  accessor.get(_univerjs_core.IUndoRedoService).pushUndoRedo({
13723
13784
  unitID: unitId,
13724
13785
  undoMutations: [
13725
- {
13726
- id: SetColHiddenMutation.id,
13727
- params: undoMutationParams
13728
- },
13786
+ ...widthUndos,
13787
+ ...visibilityUndos,
13729
13788
  {
13730
13789
  id: SetSelectionsOperation.id,
13731
13790
  params: undoSetSelectionsOperationParams
@@ -13735,10 +13794,8 @@ const SetSpecificColsVisibleCommand = {
13735
13794
  ],
13736
13795
  redoMutations: [
13737
13796
  ...intercepted.preRedos ?? [],
13738
- {
13739
- id: SetColVisibleMutation.id,
13740
- params: redoMutationParams
13741
- },
13797
+ ...visibilityRedos,
13798
+ ...widthRedos,
13742
13799
  {
13743
13800
  id: SetSelectionsOperation.id,
13744
13801
  params: setSelectionOperationParams
@@ -14408,10 +14465,36 @@ const SetSpecificRowsVisibleCommand = {
14408
14465
  });
14409
14466
  if (!target) return false;
14410
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
+ }
14411
14494
  const redoMutationParams = {
14412
14495
  unitId,
14413
14496
  subUnitId,
14414
- ranges
14497
+ ranges: visibilityRanges
14415
14498
  };
14416
14499
  const setSelectionOperationParams = {
14417
14500
  unitId,
@@ -14433,13 +14516,23 @@ const SetSpecificRowsVisibleCommand = {
14433
14516
  style: null
14434
14517
  }))
14435
14518
  };
14436
- const result = (0, _univerjs_core.sequenceExecute)([{
14519
+ const visibilityRedos = visibilityRanges.length ? [{
14437
14520
  id: SetRowVisibleMutation.id,
14438
14521
  params: redoMutationParams
14439
- }, {
14440
- id: SetSelectionsOperation.id,
14441
- params: setSelectionOperationParams
14442
- }], 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;
14443
14536
  const intercepted = sheetInterceptorService.onCommandExecute({
14444
14537
  id: SetSpecificRowsVisibleCommand.id,
14445
14538
  params
@@ -14455,10 +14548,8 @@ const SetSpecificRowsVisibleCommand = {
14455
14548
  unitID: unitId,
14456
14549
  undoMutations: [
14457
14550
  ...intercepted.preUndos ?? [],
14458
- {
14459
- id: SetRowHiddenMutation.id,
14460
- params: undoMutationParams
14461
- },
14551
+ ...heightUndos,
14552
+ ...visibilityUndos,
14462
14553
  {
14463
14554
  id: SetSelectionsOperation.id,
14464
14555
  params: undoSetSelectionsOperationParams
@@ -14468,10 +14559,8 @@ const SetSpecificRowsVisibleCommand = {
14468
14559
  ],
14469
14560
  redoMutations: [
14470
14561
  ...intercepted.preRedos ?? [],
14471
- {
14472
- id: SetRowVisibleMutation.id,
14473
- params: redoMutationParams
14474
- },
14562
+ ...visibilityRedos,
14563
+ ...heightRedos,
14475
14564
  {
14476
14565
  id: SetSelectionsOperation.id,
14477
14566
  params: setSelectionOperationParams
@@ -14882,6 +14971,7 @@ const DeltaColumnWidthCommand = {
14882
14971
  const { worksheet, unitId, subUnitId } = target;
14883
14972
  const { anchorCol, deltaX } = params;
14884
14973
  const destColumnWidth = worksheet.getColumnWidth(anchorCol) + deltaX;
14974
+ if (!(0, _univerjs_core.isValidSheetDimension)(destColumnWidth)) return false;
14885
14975
  const isAllSheetRange = selections.length === 1 && selections[0].range.rangeType === _univerjs_core.RANGE_TYPE.ALL;
14886
14976
  const colSelections = selections.filter((s) => s.range.rangeType === _univerjs_core.RANGE_TYPE.COLUMN);
14887
14977
  const rangeType = isAllSheetRange ? _univerjs_core.RANGE_TYPE.ALL : colSelections.some(({ range }) => {
@@ -14977,6 +15067,7 @@ const SetColWidthCommand = {
14977
15067
  id: "sheet.command.set-worksheet-col-width",
14978
15068
  handler: (accessor, params) => {
14979
15069
  var _params$ranges, _selectionManagerServ;
15070
+ if (!(0, _univerjs_core.isValidSheetDimension)(params === null || params === void 0 ? void 0 : params.value)) return false;
14980
15071
  const selectionManagerService = accessor.get(SheetsSelectionsService);
14981
15072
  const commandService = accessor.get(_univerjs_core.ICommandService);
14982
15073
  const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
@@ -16637,6 +16728,7 @@ const DeltaRowHeightCommand = {
16637
16728
  const { worksheet, subUnitId, unitId } = target;
16638
16729
  const { anchorRow, deltaY } = params;
16639
16730
  const destRowHeight = worksheet.getRowHeight(anchorRow) + deltaY;
16731
+ if (!(0, _univerjs_core.isValidSheetDimension)(destRowHeight)) return false;
16640
16732
  const isAllSheetRange = selections.length === 1 && selections[0].range.rangeType === _univerjs_core.RANGE_TYPE.ALL;
16641
16733
  const rowSelections = selections.filter((s) => s.range.rangeType === _univerjs_core.RANGE_TYPE.ROW);
16642
16734
  const rangeType = isAllSheetRange ? _univerjs_core.RANGE_TYPE.ALL : rowSelections.some(({ range }) => {
@@ -16741,6 +16833,7 @@ const SetRowHeightCommand = {
16741
16833
  id: "sheet.command.set-row-height",
16742
16834
  handler: (accessor, params) => {
16743
16835
  var _params$ranges, _selectionManagerServ;
16836
+ if (!(0, _univerjs_core.isValidSheetDimension)(params === null || params === void 0 ? void 0 : params.value)) return false;
16744
16837
  const selectionManagerService = accessor.get(SheetsSelectionsService);
16745
16838
  const commandService = accessor.get(_univerjs_core.ICommandService);
16746
16839
  const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
@@ -19645,7 +19738,7 @@ RangeProtectionCache = __decorate([
19645
19738
  //#endregion
19646
19739
  //#region package.json
19647
19740
  var name = "@univerjs/sheets";
19648
- var version = "1.2.0";
19741
+ var version = "1.3.0";
19649
19742
 
19650
19743
  //#endregion
19651
19744
  //#region src/controllers/active-worksheet.controller.ts