@univerjs/sheets 0.2.13 → 0.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/es/index.js CHANGED
@@ -87,7 +87,7 @@ let SheetsSelectionsService = (_a = class extends RxDisposable {
87
87
  const { unitId, sheetId } = current;
88
88
  this._ensureWorkbookSelection(unitId).setSelections(
89
89
  sheetId,
90
- unitIdOrSelections,
90
+ unitIdOrSelections != null ? unitIdOrSelections : selectionDatas,
91
91
  worksheetIdOrType != null ? worksheetIdOrType : 2
92
92
  /* MOVE_END */
93
93
  );
@@ -385,24 +385,6 @@ function getWorksheetDisposableID(unitId, worksheet) {
385
385
  return `${unitId}|${worksheet.getSheetId()}`;
386
386
  }
387
387
  __name(getWorksheetDisposableID, "getWorksheetDisposableID");
388
- function handleCustom(oldVal, newVal) {
389
- const merge2 = mergeCustom(oldVal.custom, newVal.custom);
390
- merge2 && Tools.removeNull(merge2), Tools.isEmptyObject(merge2) ? delete oldVal.custom : oldVal.custom = merge2;
391
- }
392
- __name(handleCustom, "handleCustom");
393
- function mergeCustom(oldCustom, newCustom) {
394
- return newCustom === null ? newCustom : newCustom === void 0 ? oldCustom : { ...oldCustom, ...newCustom };
395
- }
396
- __name(mergeCustom, "mergeCustom");
397
- function transformCustom(oldCustom, newCustom) {
398
- if (!newCustom || !Object.keys(newCustom).length)
399
- return oldCustom;
400
- const backupCustom = oldCustom || {};
401
- for (const k in newCustom)
402
- k in backupCustom || (backupCustom[k] = null);
403
- return backupCustom;
404
- }
405
- __name(transformCustom, "transformCustom");
406
388
  function handleStyle(styles, oldVal, newVal) {
407
389
  var _a20;
408
390
  const oldStyle = styles.getStyleByCell(oldVal);
@@ -553,7 +535,7 @@ const SetRangeValuesUndoMutationFactory = /* @__PURE__ */ __name((accessor, para
553
535
  const cellMatrix = worksheet.getCellMatrix(), styles = workbook.getStyles(), undoData = new ObjectMatrix();
554
536
  return new ObjectMatrix(cellValue).forValue((row, col, newVal) => {
555
537
  const cell = Tools.deepClone(cellMatrix == null ? void 0 : cellMatrix.getValue(row, col)) || {}, oldStyle = styles.getStyleByCell(cell), newStyle = styles.getStyleByCell(newVal);
556
- cell.s = transformStyle(oldStyle, newStyle), cell.custom = transformCustom(cell.custom, newVal == null ? void 0 : newVal.custom), undoData.setValue(row, col, setNull(cell));
538
+ cell.s = transformStyle(oldStyle, newStyle), undoData.setValue(row, col, setNull(cell));
557
539
  }), {
558
540
  ...params,
559
541
  options: {},
@@ -575,7 +557,7 @@ const SetRangeValuesUndoMutationFactory = /* @__PURE__ */ __name((accessor, para
575
557
  cellMatrix == null || cellMatrix.setValue(row, col, {});
576
558
  else {
577
559
  const oldVal = cellMatrix.getValue(row, col) || {}, type = getCellType(styles, newVal, oldVal);
578
- newVal.f !== void 0 && (oldVal.f = newVal.f), newVal.si !== void 0 && (oldVal.si = newVal.si), newVal.p !== void 0 && (oldVal.p = newVal.p), newVal.v !== void 0 && (oldVal.v = getCellValue(type, newVal)), oldVal.v !== void 0 && (oldVal.t = type, oldVal.v = getCellValue(type, oldVal)), newVal.s !== void 0 && handleStyle(styles, oldVal, newVal), newVal.custom !== void 0 && handleCustom(oldVal, newVal), cellMatrix.setValue(row, col, Tools.removeNull(oldVal));
560
+ newVal.f !== void 0 && (oldVal.f = newVal.f), newVal.si !== void 0 && (oldVal.si = newVal.si), newVal.p !== void 0 && (oldVal.p = newVal.p), newVal.v !== void 0 && (oldVal.v = getCellValue(type, newVal)), oldVal.v !== void 0 && (oldVal.t = type, oldVal.v = getCellValue(type, oldVal)), newVal.s !== void 0 && handleStyle(styles, oldVal, newVal), newVal.custom !== void 0 && (oldVal.custom = newVal.custom), cellMatrix.setValue(row, col, Tools.removeNull(oldVal));
579
561
  }
580
562
  }), !0;
581
563
  }, "handler")
@@ -2737,7 +2719,7 @@ const RemoveRowCommandId = "sheet.command.remove-row", RemoveRowCommand = {
2737
2719
  const mergeConfigData = worksheet.getConfig().mergeData, mergeAppendData = params.ranges;
2738
2720
  for (let i = 0; i < mergeAppendData.length; i++)
2739
2721
  mergeConfigData.push(mergeAppendData[i]);
2740
- return !0;
2722
+ return worksheet.getSpanModel().rebuild(mergeConfigData), !0;
2741
2723
  }, "handler")
2742
2724
  }, RemoveMergeUndoMutationFactory = /* @__PURE__ */ __name((accessor, params) => {
2743
2725
  const universheet = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);
@@ -2772,7 +2754,7 @@ const RemoveRowCommandId = "sheet.command.remove-row", RemoveRowCommand = {
2772
2754
  const configMerge = mergeConfigData[i], removeMerge = mergeRemoveData[j];
2773
2755
  Rectangle.intersects(configMerge, removeMerge) && mergeConfigData.splice(i, 1);
2774
2756
  }
2775
- return !0;
2757
+ return worksheet.getSpanModel().rebuild(mergeConfigData), !0;
2776
2758
  }, "handler")
2777
2759
  }, RemoveWorksheetMergeCommand = {
2778
2760
  type: CommandType.COMMAND,
@@ -2925,7 +2907,7 @@ const SetBorderBasicCommand = {
2925
2907
  var _a20;
2926
2908
  const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), univerInstanceService = accessor.get(IUniverInstanceService), selectionManagerService = accessor.get(SheetsSelectionsService), borderStyleManagerService = accessor.get(BorderStyleManagerService), target = getSheetCommandTarget(univerInstanceService, params);
2927
2909
  if (!target) return !1;
2928
- const { worksheet, unitId, subUnitId } = target, selections = (_a20 = selectionManagerService.getCurrentSelections()) == null ? void 0 : _a20.map((s) => s.range), mergeData = worksheet.getConfig().mergeData;
2910
+ const { worksheet, unitId, subUnitId } = target, selections = (_a20 = selectionManagerService.getCurrentSelections()) == null ? void 0 : _a20.map((s) => s.range);
2929
2911
  if (!(selections != null && selections.length))
2930
2912
  return !1;
2931
2913
  const { style, color, type, activeBorderType } = borderStyleManagerService.getBorderInfo();
@@ -2975,21 +2957,11 @@ const SetBorderBasicCommand = {
2975
2957
  cl: {
2976
2958
  rgb: color
2977
2959
  }
2978
- }, hasMerge = /* @__PURE__ */ __name((row, column) => {
2979
- let res = null;
2980
- return mergeData.forEach((merge2) => {
2981
- Rectangle.intersects(merge2, {
2982
- startColumn: column,
2983
- endColumn: column,
2984
- startRow: row,
2985
- endRow: row
2986
- }) && (res = merge2);
2987
- }), res;
2988
- }, "hasMerge");
2960
+ };
2989
2961
  function setBorderStyle(range2, defaultStyle, reserve) {
2990
2962
  range2.startRow < 0 || range2.startColumn < 0 || forEach(range2, (row, column) => {
2991
2963
  var _a21, _b;
2992
- const rectangle = hasMerge(row, column);
2964
+ const rectangle = worksheet.getMergedCell(row, column);
2993
2965
  let bdStyle = defaultStyle;
2994
2966
  if (rectangle && (defaultStyle.bc_tr || defaultStyle.ml_tr || defaultStyle.bl_tr || defaultStyle.tl_mr || defaultStyle.tl_bc || defaultStyle.tl_br)) {
2995
2967
  if (reserve) {
@@ -3014,7 +2986,7 @@ const SetBorderBasicCommand = {
3014
2986
  }
3015
2987
  __name(setBorderStyle, "setBorderStyle"), top && (setBorderStyle(topRangeOut, { b: null }), setBorderStyle(topRange, { t: Tools.deepClone(border) }, !0)), bottom && (setBorderStyle(bottomRangeOut, { t: null }), setBorderStyle(bottomRange, { b: Tools.deepClone(border) }, !0)), left && (setBorderStyle(leftRangeOut, { r: null }), setBorderStyle(leftRange, { l: Tools.deepClone(border) }, !0)), right && (setBorderStyle(rightRangeOut, { l: null }), setBorderStyle(rightRange, { r: Tools.deepClone(border) }, !0)), tl_br && setBorderStyle(range, { tl_br: Tools.deepClone(border) }, !0), tl_bc && setBorderStyle(range, { tl_bc: Tools.deepClone(border) }, !0), tl_mr && setBorderStyle(range, { tl_mr: Tools.deepClone(border) }, !0), bl_tr && setBorderStyle(range, { bl_tr: Tools.deepClone(border) }, !0), ml_tr && setBorderStyle(range, { ml_tr: Tools.deepClone(border) }, !0), bc_tr && setBorderStyle(range, { bc_tr: Tools.deepClone(border) }, !0), vertical && forEach(range, (row, column) => {
3016
2988
  var _a21, _b, _c, _d;
3017
- const rectangle = hasMerge(row, column);
2989
+ const rectangle = worksheet.getMergedCell(row, column);
3018
2990
  if (rectangle) {
3019
2991
  if (rectangle.endColumn !== range.endColumn) {
3020
2992
  const style2 = (_a21 = mr.getValue(rectangle.startRow, rectangle.startColumn)) == null ? void 0 : _a21.s;
@@ -3052,7 +3024,7 @@ const SetBorderBasicCommand = {
3052
3024
  }
3053
3025
  }), horizontal && forEach(range, (row, column) => {
3054
3026
  var _a21, _b, _c, _d;
3055
- const rectangle = hasMerge(row, column);
3027
+ const rectangle = worksheet.getMergedCell(row, column);
3056
3028
  if (rectangle) {
3057
3029
  if (rectangle.endRow !== range.endRow) {
3058
3030
  const style2 = (_a21 = mr.getValue(rectangle.startRow, rectangle.startColumn)) == null ? void 0 : _a21.s;
@@ -3090,7 +3062,7 @@ const SetBorderBasicCommand = {
3090
3062
  }
3091
3063
  }), !top && !bottom && !left && !right && !vertical && !horizontal && !tl_br && !tl_bc && !tl_mr && !bl_tr && !ml_tr && !bc_tr && (setBorderStyle(topRangeOut, { b: null }), setBorderStyle(topRange, { t: null }, !0), setBorderStyle(bottomRangeOut, { t: null }), setBorderStyle(bottomRange, { b: null }, !0), setBorderStyle(leftRangeOut, { r: null }), setBorderStyle(leftRange, { l: null }, !0), setBorderStyle(rightRangeOut, { l: null }), setBorderStyle(rightRange, { r: null }, !0), setBorderStyle(range, { tl_br: null }, !0), setBorderStyle(range, { tl_bc: null }, !0), setBorderStyle(range, { tl_mr: null }, !0), setBorderStyle(range, { bl_tr: null }, !0), setBorderStyle(range, { ml_tr: null }, !0), setBorderStyle(range, { bc_tr: null }, !0), forEach(range, (row, column) => {
3092
3064
  var _a21, _b, _c, _d, _e, _f, _g, _h;
3093
- const rectangle = hasMerge(row, column);
3065
+ const rectangle = worksheet.getMergedCell(row, column);
3094
3066
  if (rectangle) {
3095
3067
  if (rectangle.endColumn !== range.endColumn) {
3096
3068
  const style2 = (_a21 = mr.getValue(rectangle.startRow, rectangle.startColumn)) == null ? void 0 : _a21.s;
@@ -3237,6 +3209,7 @@ const SetBorderBasicCommand = {
3237
3209
  }, setSelectionOperationParams = {
3238
3210
  unitId,
3239
3211
  subUnitId,
3212
+ reveal: !0,
3240
3213
  selections: ranges.map((r) => ({ range: r, primary: getPrimaryForRange(r, worksheet), style: null }))
3241
3214
  }, undoMutationParams = SetColVisibleUndoMutationFactory(accessor, redoMutationParams), undoSetSelectionsOperationParams = {
3242
3215
  unitId,
@@ -3307,6 +3280,7 @@ const SetBorderBasicCommand = {
3307
3280
  }, undoMutationParams = SetColHiddenUndoMutationFactory(accessor, redoMutationParams), undoSetSelectionsOperationParams = {
3308
3281
  unitId,
3309
3282
  subUnitId,
3283
+ reveal: !0,
3310
3284
  selections: ranges.map((range) => ({
3311
3285
  range,
3312
3286
  primary: getPrimaryForRange(range, worksheet),
@@ -3497,6 +3471,7 @@ const SetFrozenMutationFactory = /* @__PURE__ */ __name((accessor, params) => {
3497
3471
  const { worksheet } = target, redoMutationParams = { unitId, subUnitId, ranges }, setSelectionOperationParams = {
3498
3472
  unitId,
3499
3473
  subUnitId,
3474
+ reveal: !0,
3500
3475
  selections: ranges.map((range) => ({
3501
3476
  range,
3502
3477
  primary: getPrimaryForRange(range, worksheet),
@@ -3574,6 +3549,7 @@ const SetFrozenMutationFactory = /* @__PURE__ */ __name((accessor, params) => {
3574
3549
  }, undoMutationParams = SetRowHiddenUndoMutationFactory(accessor, redoMutationParams), undoSetSelectionsOperationParams = {
3575
3550
  unitId,
3576
3551
  subUnitId,
3552
+ reveal: !0,
3577
3553
  selections: ranges.map((range) => ({
3578
3554
  range,
3579
3555
  primary: getPrimaryForRange(range, worksheet),
@@ -4287,7 +4263,7 @@ const SetStyleCommand = {
4287
4263
  var _a20;
4288
4264
  const { ranges, rowHeight } = params, univerInstanceService = accessor.get(IUniverInstanceService), target = getSheetCommandTarget(univerInstanceService, params);
4289
4265
  if (!target) return !1;
4290
- const { worksheet } = target, defaultRowHeight = worksheet.getConfig().defaultRowHeight, manager = worksheet.getRowManager();
4266
+ const { worksheet } = target, manager = worksheet.getRowManager(), defaultRowHeight = worksheet.getConfig().defaultRowHeight;
4291
4267
  for (const { startRow, endRow } of ranges)
4292
4268
  for (let rowIndex = startRow; rowIndex <= endRow; rowIndex++) {
4293
4269
  const row = manager.getRowOrCreate(rowIndex);
@@ -7388,17 +7364,11 @@ let MergeCellController = (_a11 = class extends Disposable {
7388
7364
  unitId,
7389
7365
  subUnitId,
7390
7366
  ranges: removeMergeData
7391
- }, undoRemoveMergeParams = RemoveMergeUndoMutationFactory(
7392
- this._injector,
7393
- removeMergeParams
7394
- ), addMergeParams = {
7367
+ }, undoRemoveMergeParams = RemoveMergeUndoMutationFactory(this._injector, removeMergeParams), addMergeParams = {
7395
7368
  unitId,
7396
7369
  subUnitId,
7397
7370
  ranges: addMergeData
7398
- }, undoAddMergeParams = AddMergeUndoMutationFactory(
7399
- this._injector,
7400
- addMergeParams
7401
- );
7371
+ }, undoAddMergeParams = AddMergeUndoMutationFactory(this._injector, addMergeParams);
7402
7372
  return {
7403
7373
  redos: [
7404
7374
  { id: RemoveWorksheetMergeMutation.id, params: removeMergeParams },
@@ -7434,7 +7404,7 @@ let MergeCellController = (_a11 = class extends Disposable {
7434
7404
  mergeData.forEach((merge2) => {
7435
7405
  let { startRow, endRow, startColumn, endColumn, rangeType } = merge2;
7436
7406
  Rectangle.intersects(merge2, sourceRange) || (isRowMove ? sourceStart < startRow && targetStart > endRow ? (startRow -= moveLength, endRow -= moveLength) : sourceStart > endRow && targetStart <= startRow && (startRow += moveLength, endRow += moveLength) : sourceStart < startColumn && targetStart > endColumn ? (startColumn -= moveLength, endColumn -= moveLength) : sourceStart > endColumn && targetStart <= startColumn && (startColumn += moveLength, endColumn += moveLength)), merge2.startRow === merge2.endRow && merge2.startColumn === merge2.endColumn || adjustedMergedCells.push({ startRow, endRow, startColumn, endColumn, rangeType });
7437
- }), worksheet.getConfig().mergeData = adjustedMergedCells, this.disposableCollection.dispose();
7407
+ }), worksheet.setMergeData(adjustedMergedCells), this.disposableCollection.dispose();
7438
7408
  const { unitId, subUnitId } = command.params, handler = /* @__PURE__ */ __name((config) => this.refRangeHandle(config, unitId, subUnitId), "handler");
7439
7409
  adjustedMergedCells.forEach((range) => {
7440
7410
  this.disposableCollection.add(this._refRangeService.registerRefRange(range, handler, unitId, subUnitId));
@@ -7451,7 +7421,7 @@ let MergeCellController = (_a11 = class extends Disposable {
7451
7421
  mergeData.forEach((merge2) => {
7452
7422
  let { startRow, endRow, startColumn, endColumn, rangeType } = merge2;
7453
7423
  isAddOperation ? isRowOperation ? operationStart <= startRow && (startRow += operationCount, endRow += operationCount) : operationStart <= startColumn && (startColumn += operationCount, endColumn += operationCount) : isRowOperation ? operationEnd < startRow && (startRow -= operationCount, endRow -= operationCount) : operationEnd < startColumn && (startColumn -= operationCount, endColumn -= operationCount), merge2.startRow === merge2.endRow && merge2.startColumn === merge2.endColumn || adjustedMergedCells.push({ startRow, endRow, startColumn, endColumn, rangeType });
7454
- }), worksheet.getConfig().mergeData = adjustedMergedCells, this.disposableCollection.dispose();
7424
+ }), worksheet.setMergeData(adjustedMergedCells), this.disposableCollection.dispose();
7455
7425
  const { unitId, subUnitId } = command.params, handler = /* @__PURE__ */ __name((config) => this.refRangeHandle(config, unitId, subUnitId), "handler");
7456
7426
  adjustedMergedCells.forEach((range2) => {
7457
7427
  this.disposableCollection.add(this._refRangeService.registerRefRange(range2, handler, unitId, subUnitId));
@@ -8370,9 +8340,7 @@ function hasValueFromMatrixWithSpanInfo(cell, matrix) {
8370
8340
  }
8371
8341
  __name(hasValueFromMatrixWithSpanInfo, "hasValueFromMatrixWithSpanInfo");
8372
8342
  function getMatrixWithSpanInfo(worksheet, startRow, startColumn, endRow, endColumn) {
8373
- const matrix = worksheet.getCellMatrix(), mergedCellsInRange = worksheet.getSnapshot().mergeData.filter(
8374
- (rect) => Rectangle.intersects({ startRow, startColumn, endRow, endColumn }, rect)
8375
- ), returnCellMatrix = new ObjectMatrix();
8343
+ const matrix = worksheet.getCellMatrix(), mergedCellsInRange = worksheet.getSpanModel().getMergedCellRange(startRow, startColumn, endRow, endColumn), returnCellMatrix = new ObjectMatrix();
8376
8344
  return matrix.forValue((row, col) => {
8377
8345
  const v = matrix.getValue(row, col);
8378
8346
  v && returnCellMatrix.setValue(row, col, v);
@@ -136,6 +136,7 @@ export declare function convertPrimaryWithCoordToPrimary(primaryWithCoord: ISele
136
136
  endColumn: number;
137
137
  };
138
138
  /**
139
+ * @deprecated Use worksheet.getCellInfoInMergeData or SpreadsheetSkeleton.getCellByIndex instead
139
140
  * Convert the coordinates of a single cell into a selection data.
140
141
  * @param row Specified Row Coordinate
141
142
  * @param column Specified Column Coordinate
@@ -1,4 +1,4 @@
1
- import { BorderStyleTypes, ICommand, BorderType } from '@univerjs/core';
1
+ import { BorderType, BorderStyleTypes, ICommand } from '@univerjs/core';
2
2
  import { IBorderInfo } from '../../services/border-style-manager.service';
3
3
  export interface ISetBorderBasicCommandParams {
4
4
  unitId?: string;
@@ -6,5 +6,7 @@ export interface ISetSelectionsOperationParams {
6
6
  subUnitId: string;
7
7
  selections: ISelectionWithStyle[];
8
8
  type?: SelectionMoveType;
9
+ /** If should scroll to the selected range. */
10
+ reveal?: boolean;
9
11
  }
10
12
  export declare const SetSelectionsOperation: IOperation<ISetSelectionsOperationParams>;
@@ -1,9 +1,9 @@
1
- import { IRange, Dimension, Disposable, DisposableCollection, ICommandService, Injector, InterceptorManager, IUniverInstanceService } from '@univerjs/core';
2
- import { IRemoveWorksheetMergeMutationParams } from '../basics/interfaces/mutation-interface';
1
+ import { Dimension, Disposable, DisposableCollection, ICommandService, Injector, InterceptorManager, IUniverInstanceService, IRange } from '@univerjs/core';
3
2
  import { RefRangeService } from '../services/ref-range/ref-range.service';
4
- import { EffectRefRangeParams } from '../services/ref-range/type';
5
3
  import { SheetsSelectionsService } from '../services/selections/selection-manager.service';
6
4
  import { SheetInterceptorService } from '../services/sheet-interceptor/sheet-interceptor.service';
5
+ import { IRemoveWorksheetMergeMutationParams } from '../basics/interfaces/mutation-interface';
6
+ import { EffectRefRangeParams } from '../services/ref-range/type';
7
7
  /**
8
8
  * calculates the selection based on the merged cell type
9
9
  * @param {IRange[]} selection
@@ -109,6 +109,7 @@ export { SetWorksheetPermissionPointsCommand } from './commands/commands/set-wor
109
109
  export { SetWorksheetRightToLeftCommand } from './commands/commands/set-worksheet-right-to-left.command';
110
110
  export { DeltaRowHeightCommand, SetRowHeightCommand, SetWorksheetRowIsAutoHeightCommand, type IDeltaRowHeightCommand, type ISetWorksheetRowIsAutoHeightCommandParams, } from './commands/commands/set-worksheet-row-height.command';
111
111
  export { SetWorksheetShowCommand } from './commands/commands/set-worksheet-show.command';
112
+ export type { ISetWorksheetShowCommandParams } from './commands/commands/set-worksheet-show.command';
112
113
  export { AddRangeProtectionMutation, FactoryAddRangeProtectionMutation, type IAddRangeProtectionMutationParams } from './commands/mutations/add-range-protection.mutation';
113
114
  export { AddWorksheetMergeMutation, AddMergeUndoMutationFactory } from './commands/mutations/add-worksheet-merge.mutation';
114
115
  export { AddWorksheetProtectionMutation, type IAddWorksheetProtectionParams } from './commands/mutations/add-worksheet-protection.mutation';