@univerjs/sheets-drawing-ui 1.0.0-alpha.6 → 1.0.0-alpha.7

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/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import { BooleanNumber, BuildTextUtils, CommandType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Direction, Disposable, DisposableCollection, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, FOCUSING_PANEL_EDITOR, FOCUSING_SHAPE_TEXT_EDITOR, FOCUSING_SHEET, ICommandService, IConfigService, IContextService, IImageIoService, IPermissionService, IURLImageService, IUndoRedoService, IUniverInstanceService, ImageSourceType, ImageUploadStatusType, Inject, Injector, InterceptorEffectEnum, LifecycleService, LifecycleStages, LocaleService, ObjectMatrix, Optional, Plugin, PositionedObjectLayoutType, RANGE_TYPE, Rectangle, RxDisposable, Tools, UniverInstanceType, UserManagerService, WrapTextType, createDocumentModelWithStyle, createIdentifier, fromEventSubject, generateRandomId, merge, registerDependencies, sequenceExecute, toDisposable, touchDependencies } from "@univerjs/core";
1
+ import { BooleanNumber, BuildTextUtils, CommandType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Direction, Disposable, DisposableCollection, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, FOCUSING_PANEL_EDITOR, FOCUSING_SHAPE_TEXT_EDITOR, FOCUSING_SHEET, ICommandService, IConfigService, IContextService, IImageIoService, IPermissionService, IURLImageService, IUndoRedoService, IUniverInstanceService, ImageSourceType, ImageUploadStatusType, Inject, Injector, InterceptorEffectEnum, LifecycleService, LifecycleStages, LocaleService, ObjectMatrix, Optional, Plugin, PositionedObjectLayoutType, RxDisposable, Tools, UniverInstanceType, UserManagerService, WrapTextType, createDocumentModelWithStyle, createIdentifier, fromEventSubject, generateRandomId, merge, registerDependencies, sequenceExecute, toDisposable, touchDependencies } from "@univerjs/core";
2
2
  import { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SheetDrawingAnchorType, UniverSheetsDrawingPlugin, drawingPositionToTransform, transformToAxisAlignPosition, transformToDrawingPosition } from "@univerjs/sheets-drawing";
3
3
  import { CURSOR_TYPE, DRAWING_OBJECT_LAYER_INDEX, IRenderManagerService, Image, ObjectType, Rect, SHEET_VIEWPORT_KEY, Vector2, getCurrentTypeOfRenderer, getGroupState, transformObjectOutOfGroup } from "@univerjs/engine-render";
4
4
  import { Button, Checkbox, CheckboxGroup, FormLayout, MessageType, Radio, RadioGroup, Select, clsx, render, unmount } from "@univerjs/design";
5
5
  import { buildDocTransform, docDrawingPositionToTransform } from "@univerjs/docs";
6
6
  import { DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_WIDTH_LIMIT, IDrawingManagerService, SetDrawingSelectedOperation, UniverDrawingPlugin, getDrawingImageAllowSize, getDrawingShapeKeyByDrawingSearch, getImageSize } from "@univerjs/drawing";
7
- import { COMMAND_LISTENER_SKELETON_CHANGE, DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, DeltaColumnWidthCommand, DeltaRowHeightCommand, IAutoFillService, INTERCEPTOR_POINT, InsertColCommand, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, InsertRowCommand, InterceptCellContentPriority, MoveColsCommand, MoveRangeCommand, MoveRowsCommand, RangeProtectionPermissionEditPoint, RemoveColCommand, RemoveRowCommand, SetColHiddenCommand, SetColHiddenMutation, SetColVisibleMutation, SetColWidthCommand, SetFrozenMutation, SetRangeValuesCommand, SetRowHeightCommand, SetRowHiddenCommand, SetRowHiddenMutation, SetRowVisibleMutation, SetSelectionsOperation, SetSpecificColsVisibleCommand, SetSpecificRowsVisibleCommand, SetWorksheetActiveOperation, SetWorksheetColWidthMutation, SetWorksheetRowAutoHeightMutation, SetWorksheetRowHeightMutation, SetWorksheetRowIsAutoHeightMutation, SheetInterceptorService, SheetPermissionCheckController, SheetSkeletonService, SheetsSelectionsService, WorkbookEditablePermission, WorkbookViewPermission, WorksheetEditPermission, WorksheetViewPermission, attachRangeWithCoord, discreteRangeToRange, getSheetCommandTarget } from "@univerjs/sheets";
7
+ import { COMMAND_LISTENER_SKELETON_CHANGE, IAutoFillService, INTERCEPTOR_POINT, InterceptCellContentPriority, RangeProtectionPermissionEditPoint, SetFrozenMutation, SetRangeValuesCommand, SetSelectionsOperation, SetWorksheetActiveOperation, SetWorksheetRowAutoHeightMutation, SheetInterceptorService, SheetPermissionCheckController, SheetSkeletonService, SheetsSelectionsService, WorkbookEditablePermission, WorkbookViewPermission, WorksheetEditPermission, WorksheetViewPermission, attachRangeWithCoord, discreteRangeToRange, getSheetCommandTarget } from "@univerjs/sheets";
8
8
  import { COPY_TYPE, EditingRenderController, HoverManagerService, IEditorBridgeService, ISheetClipboardService, ISheetSelectionRenderService, PREDEFINED_HOOK_NAME_PASTE, SetCellEditVisibleOperation, SetScrollOperation, SetZoomRatioOperation, SheetCanvasPopManagerService, SheetPrintInterceptorService, SheetSkeletonManagerService, getCurrentRangeDisable$, useHighlightRange, virtualizeDiscreteRanges } from "@univerjs/sheets-ui";
9
9
  import { CanvasFloatDomPreviewService, CanvasFloatDomService, ComponentManager, ContextMenuGroup, ContextMenuPosition, IClipboardInterfaceService, IContextMenuService, IDialogService, ILocalFileService, IMenuManagerService, IMessageService, IShortcutService, ISidebarService, KeyCode, MenuItemType, PrintFloatDomSingle, RibbonInsertGroup, connectInjector, getMenuHiddenObservable, useDependency, useObservable } from "@univerjs/ui";
10
10
  import { COMPONENT_IMAGE_POPUP_MENU, DrawingCommonPanel, DrawingRenderService, ImageCropperObject, ImageResetSizeOperation, OpenImageCropOperation, UniverDrawingUIPlugin, disposeDrawingRenderObject, insertGroupObject } from "@univerjs/drawing-ui";
@@ -3436,6 +3436,12 @@ function SaveCellImagesMenuFactory(accessor) {
3436
3436
  const menuSchema = {
3437
3437
  [RibbonInsertGroup.MEDIA]: { [SHEETS_IMAGE_MENU_ID]: {
3438
3438
  order: 0,
3439
+ gridLayout: {
3440
+ row: 1,
3441
+ column: 1,
3442
+ rowSpan: 2,
3443
+ showLabel: true
3444
+ },
3439
3445
  menuItemFactory: ImageMenuFactory,
3440
3446
  [InsertFloatImageCommand.id]: {
3441
3447
  order: 0,
@@ -3463,7 +3469,7 @@ const menuSchema = {
3463
3469
  //#endregion
3464
3470
  //#region package.json
3465
3471
  var name = "@univerjs/sheets-drawing-ui";
3466
- var version = "1.0.0-alpha.6";
3472
+ var version = "1.0.0-alpha.7";
3467
3473
 
3468
3474
  //#endregion
3469
3475
  //#region src/config/config.ts
@@ -4122,6 +4128,86 @@ SheetCellImageCopyPasteController = __decorate([
4122
4128
  __decorateParam(4, Inject(LocaleService))
4123
4129
  ], SheetCellImageCopyPasteController);
4124
4130
 
4131
+ //#endregion
4132
+ //#region src/controllers/sheet-drawing-active-render.controller.ts
4133
+ let SheetDrawingActiveRenderController = class SheetDrawingActiveRenderController extends Disposable {
4134
+ constructor(_context, _commandService, _sheetSkeletonService, _sheetDrawingService, _drawingManagerService) {
4135
+ super();
4136
+ this._context = _context;
4137
+ this._commandService = _commandService;
4138
+ this._sheetSkeletonService = _sheetSkeletonService;
4139
+ this._sheetDrawingService = _sheetDrawingService;
4140
+ this._drawingManagerService = _drawingManagerService;
4141
+ this._commandListener();
4142
+ }
4143
+ _commandListener() {
4144
+ this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
4145
+ if (command.id === SetWorksheetActiveOperation.id) {
4146
+ const { unitId, subUnitId } = command.params;
4147
+ this._updateDrawings(unitId, subUnitId);
4148
+ }
4149
+ }));
4150
+ this.disposeWithMe(this._context.activated$.subscribe((activated) => {
4151
+ const { unit, unitId } = this._context;
4152
+ if (activated) this._updateDrawings(unitId, unit.getActiveSheet().getSheetId());
4153
+ else this._clearDrawings(unitId);
4154
+ }));
4155
+ }
4156
+ _clearDrawings(selfUnitId) {
4157
+ setTimeout(() => {
4158
+ const drawingMap = this._drawingManagerService.drawingManagerData;
4159
+ const removeDrawings = [];
4160
+ Object.keys(drawingMap !== null && drawingMap !== void 0 ? drawingMap : {}).forEach((unitId) => {
4161
+ var _drawingMap$unitId;
4162
+ const subUnitMap = (_drawingMap$unitId = drawingMap[unitId]) !== null && _drawingMap$unitId !== void 0 ? _drawingMap$unitId : {};
4163
+ Object.keys(subUnitMap).forEach((subUnitId) => {
4164
+ var _subUnitMap$subUnitId, _subUnitMap$subUnitId2;
4165
+ const drawingData = (_subUnitMap$subUnitId = (_subUnitMap$subUnitId2 = subUnitMap[subUnitId]) === null || _subUnitMap$subUnitId2 === void 0 ? void 0 : _subUnitMap$subUnitId2.data) !== null && _subUnitMap$subUnitId !== void 0 ? _subUnitMap$subUnitId : {};
4166
+ Object.keys(drawingData).forEach((drawingId) => {
4167
+ if (unitId === selfUnitId) removeDrawings.push(drawingData[drawingId]);
4168
+ });
4169
+ });
4170
+ });
4171
+ this._sheetDrawingService.removeNotification(removeDrawings);
4172
+ this._drawingManagerService.removeNotification(removeDrawings);
4173
+ });
4174
+ }
4175
+ _updateDrawings(showUnitId, showSubunitId) {
4176
+ setTimeout(() => {
4177
+ const sheetSkeletonParam = this._sheetSkeletonService.getSkeletonParam(showUnitId, showSubunitId);
4178
+ const drawingMap = this._drawingManagerService.drawingManagerData;
4179
+ const insertDrawings = [];
4180
+ const removeDrawings = [];
4181
+ Object.keys(drawingMap !== null && drawingMap !== void 0 ? drawingMap : {}).forEach((unitId) => {
4182
+ var _drawingMap$unitId2;
4183
+ if (unitId !== showUnitId) return;
4184
+ const subUnitMap = (_drawingMap$unitId2 = drawingMap[unitId]) !== null && _drawingMap$unitId2 !== void 0 ? _drawingMap$unitId2 : {};
4185
+ Object.keys(subUnitMap).forEach((subUnitId) => {
4186
+ var _subUnitMap$subUnitId3, _subUnitMap$subUnitId4;
4187
+ const drawingData = (_subUnitMap$subUnitId3 = (_subUnitMap$subUnitId4 = subUnitMap[subUnitId]) === null || _subUnitMap$subUnitId4 === void 0 ? void 0 : _subUnitMap$subUnitId4.data) !== null && _subUnitMap$subUnitId3 !== void 0 ? _subUnitMap$subUnitId3 : {};
4188
+ Object.keys(drawingData).forEach((drawingId) => {
4189
+ if (unitId === showUnitId && subUnitId === showSubunitId) {
4190
+ const drawing = drawingData[drawingId];
4191
+ if (drawing.sheetTransform) drawing.transform = drawingPositionToTransform(drawing.sheetTransform, sheetSkeletonParam);
4192
+ insertDrawings.push(drawingData[drawingId]);
4193
+ } else removeDrawings.push(drawingData[drawingId]);
4194
+ });
4195
+ });
4196
+ });
4197
+ this._sheetDrawingService.removeNotification(removeDrawings);
4198
+ this._sheetDrawingService.addNotification(insertDrawings);
4199
+ this._drawingManagerService.removeNotification(removeDrawings);
4200
+ this._drawingManagerService.addNotification(insertDrawings);
4201
+ }, 0);
4202
+ }
4203
+ };
4204
+ SheetDrawingActiveRenderController = __decorate([
4205
+ __decorateParam(1, ICommandService),
4206
+ __decorateParam(2, Inject(SheetSkeletonService)),
4207
+ __decorateParam(3, ISheetDrawingService),
4208
+ __decorateParam(4, IDrawingManagerService)
4209
+ ], SheetDrawingActiveRenderController);
4210
+
4125
4211
  //#endregion
4126
4212
  //#region src/controllers/sheet-drawing-copy-paste.controller.ts
4127
4213
  const IMAGE_PNG_MIME_TYPE = "image/png";
@@ -4913,1469 +4999,6 @@ SheetDrawingPrintingController = __decorate([
4913
4999
  __decorateParam(5, Inject(Injector))
4914
5000
  ], SheetDrawingPrintingController);
4915
5001
 
4916
- //#endregion
4917
- //#region src/controllers/sheet-drawing-transform-affected.controller.ts
4918
- const UPDATE_COMMANDS = [
4919
- InsertRowCommand.id,
4920
- InsertColCommand.id,
4921
- RemoveRowCommand.id,
4922
- RemoveColCommand.id,
4923
- DeleteRangeMoveLeftCommand.id,
4924
- DeleteRangeMoveUpCommand.id,
4925
- InsertRangeMoveDownCommand.id,
4926
- InsertRangeMoveRightCommand.id,
4927
- DeltaRowHeightCommand.id,
4928
- SetRowHeightCommand.id,
4929
- DeltaColumnWidthCommand.id,
4930
- SetColWidthCommand.id,
4931
- SetRowHiddenCommand.id,
4932
- SetSpecificRowsVisibleCommand.id,
4933
- SetSpecificColsVisibleCommand.id,
4934
- SetColHiddenCommand.id,
4935
- MoveColsCommand.id,
4936
- MoveRowsCommand.id,
4937
- MoveRangeCommand.id
4938
- ];
4939
- const REFRESH_MUTATIONS = [
4940
- SetRowVisibleMutation.id,
4941
- SetRowHiddenMutation.id,
4942
- SetColVisibleMutation.id,
4943
- SetColHiddenMutation.id,
4944
- SetWorksheetRowHeightMutation.id,
4945
- SetWorksheetRowAutoHeightMutation.id,
4946
- SetWorksheetRowIsAutoHeightMutation.id,
4947
- SetWorksheetColWidthMutation.id
4948
- ];
4949
- let SheetDrawingTransformAffectedController = class SheetDrawingTransformAffectedController extends Disposable {
4950
- constructor(_context, _commandService, _sheetSkeletonService, _selectionRenderService, _sheetInterceptorService, _selectionManagerService, _sheetDrawingService, _drawingManagerService, _univerInstanceService) {
4951
- super();
4952
- this._context = _context;
4953
- this._commandService = _commandService;
4954
- this._sheetSkeletonService = _sheetSkeletonService;
4955
- this._selectionRenderService = _selectionRenderService;
4956
- this._sheetInterceptorService = _sheetInterceptorService;
4957
- this._selectionManagerService = _selectionManagerService;
4958
- this._sheetDrawingService = _sheetDrawingService;
4959
- this._drawingManagerService = _drawingManagerService;
4960
- this._univerInstanceService = _univerInstanceService;
4961
- this._sheetInterceptorListener();
4962
- this._commandListener();
4963
- this._sheetRefreshListener();
4964
- }
4965
- _sheetInterceptorListener() {
4966
- this.disposeWithMe(this._sheetInterceptorService.interceptAfterCommand({ getMutations: (commandInfo) => {
4967
- const { id, params } = commandInfo;
4968
- if (!UPDATE_COMMANDS.includes(id) || !params) return {
4969
- redos: [],
4970
- undos: []
4971
- };
4972
- if (id === InsertRowCommand.id) return this._moveRowInterceptor(params, "insert");
4973
- else if ([
4974
- MoveColsCommand.id,
4975
- MoveRowsCommand.id,
4976
- MoveRangeCommand.id
4977
- ].includes(id)) {
4978
- let target;
4979
- if (id === MoveRangeCommand.id) {
4980
- const _params = params;
4981
- if (_params.toUnitId && _params.fromUnitId && _params.toUnitId !== _params.fromUnitId || _params.toSubUnitId && _params.fromSubUnitId && _params.toSubUnitId !== _params.fromSubUnitId) return {
4982
- redos: [],
4983
- undos: []
4984
- };
4985
- target = getSheetCommandTarget(this._univerInstanceService, {
4986
- unitId: _params.toUnitId,
4987
- subUnitId: _params.toSubUnitId
4988
- });
4989
- } else target = getSheetCommandTarget(this._univerInstanceService, params);
4990
- if (!target) return {
4991
- redos: [],
4992
- undos: []
4993
- };
4994
- const { unitId, subUnitId } = target;
4995
- const { fromRange, toRange } = params;
4996
- return this._moveRangeInterceptor(unitId, subUnitId, fromRange, toRange);
4997
- } else if (id === InsertColCommand.id) return this._moveColInterceptor(params, "insert");
4998
- else if (id === RemoveRowCommand.id) return this._moveRowInterceptor(params, "remove");
4999
- else if (id === RemoveColCommand.id) return this._moveColInterceptor(params, "remove");
5000
- else if (id === DeleteRangeMoveLeftCommand.id) {
5001
- const { range } = params;
5002
- return this._getRangeMoveUndo(range, 0);
5003
- } else if (id === DeleteRangeMoveUpCommand.id) {
5004
- const { range } = params;
5005
- return this._getRangeMoveUndo(range, 1);
5006
- } else if (id === InsertRangeMoveDownCommand.id) {
5007
- const { range } = params;
5008
- return this._getRangeMoveUndo(range, 2);
5009
- } else if (id === InsertRangeMoveRightCommand.id) {
5010
- const { range } = params;
5011
- return this._getRangeMoveUndo(range, 3);
5012
- } else if (id === SetRowHiddenCommand.id || id === SetSpecificRowsVisibleCommand.id) {
5013
- var _this$_selectionManag;
5014
- const _params = params;
5015
- const target = getSheetCommandTarget(this._univerInstanceService, _params);
5016
- if (!target) return {
5017
- redos: [],
5018
- undos: []
5019
- };
5020
- const { unitId, subUnitId } = target;
5021
- const ranges = _params.ranges || ((_this$_selectionManag = this._selectionManagerService.getCurrentSelections()) === null || _this$_selectionManag === void 0 ? void 0 : _this$_selectionManag.map((s) => s.range).filter((r) => r.rangeType === RANGE_TYPE.ROW));
5022
- if (!ranges || ranges.length === 0) return {
5023
- redos: [],
5024
- undos: []
5025
- };
5026
- return this._getDrawingUndoForRowVisible(unitId, subUnitId, ranges);
5027
- } else if (id === SetColHiddenCommand.id || id === SetSpecificColsVisibleCommand.id) {
5028
- var _this$_selectionManag2;
5029
- const _params = params;
5030
- const target = getSheetCommandTarget(this._univerInstanceService, _params);
5031
- if (!target) return {
5032
- redos: [],
5033
- undos: []
5034
- };
5035
- const { unitId, subUnitId } = target;
5036
- const ranges = _params.ranges || ((_this$_selectionManag2 = this._selectionManagerService.getCurrentSelections()) === null || _this$_selectionManag2 === void 0 ? void 0 : _this$_selectionManag2.map((s) => s.range).filter((r) => r.rangeType === RANGE_TYPE.COLUMN));
5037
- if (!ranges || ranges.length === 0) return {
5038
- redos: [],
5039
- undos: []
5040
- };
5041
- return this._getDrawingUndoForColVisible(unitId, subUnitId, ranges);
5042
- } else if (id === DeltaRowHeightCommand.id || id === DeltaColumnWidthCommand.id) {
5043
- const target = getSheetCommandTarget(this._univerInstanceService);
5044
- if (!target) return {
5045
- redos: [],
5046
- undos: []
5047
- };
5048
- const { unitId, subUnitId, worksheet } = target;
5049
- const ranges = [];
5050
- if (id === DeltaRowHeightCommand.id) ranges.push({
5051
- startRow: params.anchorRow,
5052
- endRow: params.anchorRow,
5053
- startColumn: 0,
5054
- endColumn: worksheet.getColumnCount() - 1
5055
- });
5056
- else ranges.push({
5057
- startRow: 0,
5058
- endRow: worksheet.getRowCount() - 1,
5059
- startColumn: params.anchorCol,
5060
- endColumn: params.anchorCol
5061
- });
5062
- return this._getDrawingUndoForRowAndColSize(unitId, subUnitId, ranges);
5063
- } else if (id === SetRowHeightCommand.id || id === SetColWidthCommand.id) {
5064
- var _this$_selectionManag3;
5065
- const _params = params;
5066
- const target = getSheetCommandTarget(this._univerInstanceService, _params);
5067
- if (!target) return {
5068
- redos: [],
5069
- undos: []
5070
- };
5071
- const { unitId, subUnitId } = target;
5072
- const ranges = _params.ranges || ((_this$_selectionManag3 = this._selectionManagerService.getCurrentSelections()) === null || _this$_selectionManag3 === void 0 ? void 0 : _this$_selectionManag3.map((s) => s.range));
5073
- if (!ranges || ranges.length === 0) return {
5074
- redos: [],
5075
- undos: []
5076
- };
5077
- return this._getDrawingUndoForRowAndColSize(unitId, subUnitId, ranges);
5078
- }
5079
- return {
5080
- redos: [],
5081
- undos: []
5082
- };
5083
- } }));
5084
- }
5085
- _getRangeMoveUndo(range, type) {
5086
- const target = getSheetCommandTarget(this._univerInstanceService);
5087
- if (!target) return {
5088
- redos: [],
5089
- undos: []
5090
- };
5091
- const { unitId, subUnitId } = target;
5092
- const drawingData = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
5093
- const redos = [];
5094
- const undos = [];
5095
- const updateDrawings = [];
5096
- const deleteDrawings = [];
5097
- Object.keys(drawingData).forEach((drawingId) => {
5098
- const drawing = drawingData[drawingId];
5099
- const { updateDrawings: updateDrawingsPart, deleteDrawings: deleteDrawingsPart } = this._getUpdateOrDeleteDrawings(range, type, drawing);
5100
- updateDrawings.push(...updateDrawingsPart);
5101
- deleteDrawings.push(...deleteDrawingsPart);
5102
- });
5103
- if (updateDrawings.length === 0 && deleteDrawings.length === 0) return {
5104
- redos: [],
5105
- undos: []
5106
- };
5107
- if (updateDrawings.length > 0) {
5108
- const { undo, redo, objects } = this._sheetDrawingService.getBatchUpdateOp(updateDrawings);
5109
- redos.push({
5110
- id: SetDrawingApplyMutation.id,
5111
- params: {
5112
- unitId,
5113
- subUnitId,
5114
- op: redo,
5115
- objects,
5116
- type: DrawingApplyType.UPDATE
5117
- }
5118
- });
5119
- undos.push({
5120
- id: SetDrawingApplyMutation.id,
5121
- params: {
5122
- unitId,
5123
- subUnitId,
5124
- op: undo,
5125
- objects,
5126
- type: DrawingApplyType.UPDATE
5127
- }
5128
- });
5129
- }
5130
- if (deleteDrawings.length > 0) {
5131
- const deleteJsonOp = this._sheetDrawingService.getBatchRemoveOp(deleteDrawings);
5132
- const deleteUndo = deleteJsonOp.undo;
5133
- const deleteRedo = deleteJsonOp.redo;
5134
- const deleteObjects = deleteJsonOp.objects;
5135
- redos.push({
5136
- id: SetDrawingApplyMutation.id,
5137
- params: {
5138
- unitId,
5139
- subUnitId,
5140
- op: deleteRedo,
5141
- objects: deleteObjects,
5142
- type: DrawingApplyType.REMOVE
5143
- }
5144
- });
5145
- undos.push({
5146
- id: SetDrawingApplyMutation.id,
5147
- params: {
5148
- unitId,
5149
- subUnitId,
5150
- op: deleteUndo,
5151
- objects: deleteObjects,
5152
- type: DrawingApplyType.INSERT
5153
- }
5154
- });
5155
- }
5156
- redos.push({
5157
- id: ClearSheetDrawingTransformerOperation.id,
5158
- params: [unitId]
5159
- });
5160
- undos.push({
5161
- id: ClearSheetDrawingTransformerOperation.id,
5162
- params: [unitId]
5163
- });
5164
- return {
5165
- redos,
5166
- undos
5167
- };
5168
- }
5169
- _getUpdateOrDeleteDrawings(range, type, drawing) {
5170
- const updateDrawings = [];
5171
- const deleteDrawings = [];
5172
- const { sheetTransform, anchorType = SheetDrawingAnchorType.Position, transform, unitId, subUnitId, drawingId } = drawing;
5173
- const sheetSkeletonParam = this._sheetSkeletonService.getSkeletonParam(unitId, subUnitId);
5174
- if (!sheetTransform || !transform || !sheetSkeletonParam) return {
5175
- updateDrawings,
5176
- deleteDrawings
5177
- };
5178
- const { from, to } = sheetTransform;
5179
- const { row: fromRow, column: fromColumn } = from;
5180
- const { row: toRow, column: toColumn } = to;
5181
- const { startRow, endRow, startColumn, endColumn } = range;
5182
- let newSheetTransform = null;
5183
- let newTransform = null;
5184
- let axisAlignSheetTransform;
5185
- if (type === 0 && fromRow >= startRow && toRow <= endRow) if (fromColumn >= startColumn && toColumn <= endColumn) deleteDrawings.push({
5186
- unitId,
5187
- subUnitId,
5188
- drawingId
5189
- });
5190
- else {
5191
- var _param$axisAlignSheet;
5192
- const param = this._shrinkCol(startColumn, endColumn, {
5193
- sheetSkeletonParam,
5194
- sheetTransform,
5195
- transform,
5196
- anchorType
5197
- });
5198
- newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
5199
- newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
5200
- axisAlignSheetTransform = (_param$axisAlignSheet = param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) !== null && _param$axisAlignSheet !== void 0 ? _param$axisAlignSheet : void 0;
5201
- }
5202
- else if (type === 1 && fromColumn >= startColumn && toColumn <= endColumn) if (fromRow >= startRow && toRow <= endRow) deleteDrawings.push({
5203
- unitId,
5204
- subUnitId,
5205
- drawingId
5206
- });
5207
- else {
5208
- var _param$axisAlignSheet2;
5209
- const param = this._shrinkRow(startRow, endRow, {
5210
- sheetSkeletonParam,
5211
- sheetTransform,
5212
- transform,
5213
- anchorType
5214
- });
5215
- newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
5216
- newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
5217
- axisAlignSheetTransform = (_param$axisAlignSheet2 = param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) !== null && _param$axisAlignSheet2 !== void 0 ? _param$axisAlignSheet2 : void 0;
5218
- }
5219
- else if (type === 2) {
5220
- var _param$axisAlignSheet3;
5221
- const param = this._expandRow(startRow, endRow, {
5222
- sheetSkeletonParam,
5223
- sheetTransform,
5224
- transform,
5225
- anchorType
5226
- });
5227
- newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
5228
- newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
5229
- axisAlignSheetTransform = (_param$axisAlignSheet3 = param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) !== null && _param$axisAlignSheet3 !== void 0 ? _param$axisAlignSheet3 : void 0;
5230
- } else if (type === 3) {
5231
- var _param$axisAlignSheet4;
5232
- const param = this._expandCol(startColumn, endColumn, {
5233
- sheetSkeletonParam,
5234
- sheetTransform,
5235
- transform,
5236
- anchorType
5237
- });
5238
- newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
5239
- newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
5240
- axisAlignSheetTransform = (_param$axisAlignSheet4 = param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) !== null && _param$axisAlignSheet4 !== void 0 ? _param$axisAlignSheet4 : void 0;
5241
- }
5242
- if (newSheetTransform && newTransform) {
5243
- const newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
5244
- updateDrawings.push({
5245
- ...drawing,
5246
- sheetTransform: newSheetTransform,
5247
- transform: newTransform,
5248
- axisAlignSheetTransform
5249
- });
5250
- }
5251
- return {
5252
- updateDrawings,
5253
- deleteDrawings
5254
- };
5255
- }
5256
- _remainDrawingSize(transform, updateDrawings, drawing, skeleton) {
5257
- const newSheetTransform = transformToDrawingPosition({ ...transform }, skeleton);
5258
- if (newSheetTransform) {
5259
- const axisAlignSheetTransform = transformToAxisAlignPosition({ ...transform }, skeleton);
5260
- updateDrawings.push({
5261
- ...drawing,
5262
- sheetTransform: newSheetTransform,
5263
- axisAlignSheetTransform
5264
- });
5265
- }
5266
- }
5267
- _getDrawingUndoForColVisible(unitId, subUnitId, ranges) {
5268
- const skeleton = this._sheetSkeletonService.getSkeleton(unitId, subUnitId);
5269
- if (!skeleton) return {
5270
- redos: [],
5271
- undos: []
5272
- };
5273
- const drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId);
5274
- const updateDrawings = [];
5275
- const preUpdateDrawings = [];
5276
- Object.keys(drawingData).forEach((drawingId) => {
5277
- const drawing = drawingData[drawingId];
5278
- const { sheetTransform, transform, anchorType = SheetDrawingAnchorType.Position } = drawing;
5279
- if (anchorType === SheetDrawingAnchorType.None) this._remainDrawingSize(transform, updateDrawings, drawing, skeleton);
5280
- else {
5281
- const { from, to } = sheetTransform;
5282
- const { row: fromRow, column: fromColumn } = from;
5283
- const { row: toRow, column: toColumn } = to;
5284
- for (let i = 0; i < ranges.length; i++) {
5285
- const { startColumn, endColumn } = ranges[i];
5286
- if (toColumn < startColumn) continue;
5287
- if (anchorType === SheetDrawingAnchorType.Position) {
5288
- let newSheetTransform = null;
5289
- let newTransform = null;
5290
- if (fromColumn >= startColumn && fromColumn <= endColumn) {
5291
- const selectionCell = attachRangeWithCoord(skeleton, {
5292
- startColumn: fromColumn,
5293
- endColumn,
5294
- startRow: fromRow,
5295
- endRow: toRow
5296
- });
5297
- newTransform = {
5298
- ...transform,
5299
- left: selectionCell.startX
5300
- };
5301
- }
5302
- if (newTransform) {
5303
- newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
5304
- const axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
5305
- if (newSheetTransform && newTransform) {
5306
- updateDrawings.push({
5307
- ...drawing,
5308
- sheetTransform: newSheetTransform,
5309
- transform: newTransform,
5310
- axisAlignSheetTransform
5311
- });
5312
- break;
5313
- }
5314
- }
5315
- continue;
5316
- }
5317
- if (fromColumn >= startColumn && toColumn <= endColumn) continue;
5318
- let newSheetTransform = null;
5319
- let newTransform = null;
5320
- if (fromColumn >= startColumn && fromColumn <= endColumn) {
5321
- const selectionCell = attachRangeWithCoord(skeleton, {
5322
- startColumn: fromColumn,
5323
- endColumn,
5324
- startRow: fromRow,
5325
- endRow: toRow
5326
- });
5327
- newTransform = {
5328
- ...transform,
5329
- left: (selectionCell === null || selectionCell === void 0 ? void 0 : selectionCell.startX) || 0,
5330
- width: ((transform === null || transform === void 0 ? void 0 : transform.width) || 0) - selectionCell.endX + selectionCell.startX
5331
- };
5332
- } else if (toColumn >= startColumn && toColumn <= endColumn) {
5333
- const selectionCell = attachRangeWithCoord(skeleton, {
5334
- startColumn,
5335
- endColumn: toColumn,
5336
- startRow: fromRow,
5337
- endRow: toRow
5338
- });
5339
- newTransform = {
5340
- ...transform,
5341
- left: selectionCell.startX - ((transform === null || transform === void 0 ? void 0 : transform.width) || 0)
5342
- };
5343
- } else {
5344
- const selectionCell = attachRangeWithCoord(skeleton, {
5345
- startColumn,
5346
- endColumn,
5347
- startRow: fromRow,
5348
- endRow: toRow
5349
- });
5350
- newTransform = {
5351
- ...transform,
5352
- width: ((transform === null || transform === void 0 ? void 0 : transform.width) || 0) - selectionCell.endX + selectionCell.startX
5353
- };
5354
- newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
5355
- if (newSheetTransform && newTransform) {
5356
- const axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
5357
- preUpdateDrawings.push({
5358
- ...drawing,
5359
- sheetTransform: newSheetTransform,
5360
- transform: newTransform,
5361
- axisAlignSheetTransform
5362
- });
5363
- break;
5364
- }
5365
- }
5366
- if (newTransform) newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
5367
- if (newTransform && newSheetTransform) {
5368
- const axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
5369
- updateDrawings.push({
5370
- ...drawing,
5371
- sheetTransform: newSheetTransform,
5372
- transform: newTransform,
5373
- axisAlignSheetTransform
5374
- });
5375
- break;
5376
- } else this._remainDrawingSize(transform, updateDrawings, drawing, skeleton);
5377
- }
5378
- }
5379
- });
5380
- if (updateDrawings.length === 0 && preUpdateDrawings.length === 0) return {
5381
- redos: [],
5382
- undos: []
5383
- };
5384
- const { redos, undos } = this._createUndoAndRedoMutation(unitId, subUnitId, updateDrawings);
5385
- const preRedos = [];
5386
- const preUndos = [];
5387
- if (preUpdateDrawings.length > 0) {
5388
- const { redos, undos } = this._createUndoAndRedoMutation(unitId, subUnitId, preUpdateDrawings);
5389
- preRedos.push(...redos);
5390
- preUndos.push(...undos);
5391
- }
5392
- return {
5393
- redos,
5394
- undos,
5395
- preRedos,
5396
- preUndos
5397
- };
5398
- }
5399
- _createUndoAndRedoMutation(unitId, subUnitId, updateDrawings) {
5400
- const { undo, redo, objects } = this._sheetDrawingService.getBatchUpdateOp(updateDrawings);
5401
- return {
5402
- redos: [{
5403
- id: SetDrawingApplyMutation.id,
5404
- params: {
5405
- unitId,
5406
- subUnitId,
5407
- op: redo,
5408
- objects,
5409
- type: DrawingApplyType.UPDATE
5410
- }
5411
- }, {
5412
- id: ClearSheetDrawingTransformerOperation.id,
5413
- params: [unitId]
5414
- }],
5415
- undos: [{
5416
- id: SetDrawingApplyMutation.id,
5417
- params: {
5418
- unitId,
5419
- subUnitId,
5420
- op: undo,
5421
- objects,
5422
- type: DrawingApplyType.UPDATE
5423
- }
5424
- }, {
5425
- id: ClearSheetDrawingTransformerOperation.id,
5426
- params: [unitId]
5427
- }]
5428
- };
5429
- }
5430
- _getDrawingUndoForRowVisible(unitId, subUnitId, ranges) {
5431
- const skeleton = this._sheetSkeletonService.getSkeleton(unitId, subUnitId);
5432
- if (!skeleton) return {
5433
- redos: [],
5434
- undos: []
5435
- };
5436
- const drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId);
5437
- const updateDrawings = [];
5438
- const preUpdateDrawings = [];
5439
- Object.keys(drawingData).forEach((drawingId) => {
5440
- const drawing = drawingData[drawingId];
5441
- const { sheetTransform, transform, anchorType = SheetDrawingAnchorType.Position } = drawing;
5442
- if (anchorType === SheetDrawingAnchorType.None) this._remainDrawingSize(transform, updateDrawings, drawing, skeleton);
5443
- else {
5444
- const { from, to } = sheetTransform;
5445
- const { row: fromRow, column: fromColumn } = from;
5446
- const { row: toRow, column: toColumn } = to;
5447
- for (let i = 0; i < ranges.length; i++) {
5448
- const { startRow, endRow } = ranges[i];
5449
- if (toRow < startRow) continue;
5450
- if (anchorType === SheetDrawingAnchorType.Position) {
5451
- let newSheetTransform = null;
5452
- let newTransform = null;
5453
- if (fromRow >= startRow && fromRow <= endRow) {
5454
- const selectionCell = attachRangeWithCoord(skeleton, {
5455
- startColumn: fromColumn,
5456
- endColumn: toColumn,
5457
- startRow: fromRow,
5458
- endRow
5459
- });
5460
- newTransform = {
5461
- ...transform,
5462
- top: selectionCell.startY
5463
- };
5464
- }
5465
- if (newTransform) {
5466
- newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
5467
- const axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
5468
- if (newSheetTransform && newTransform) {
5469
- updateDrawings.push({
5470
- ...drawing,
5471
- sheetTransform: newSheetTransform,
5472
- transform: newTransform,
5473
- axisAlignSheetTransform
5474
- });
5475
- break;
5476
- }
5477
- }
5478
- continue;
5479
- }
5480
- if (fromRow >= startRow && toRow <= endRow) continue;
5481
- let newSheetTransform = null;
5482
- let newTransform = null;
5483
- if (fromRow >= startRow && fromRow <= endRow) {
5484
- const selectionCell = attachRangeWithCoord(skeleton, {
5485
- startColumn: fromColumn,
5486
- endColumn: toColumn,
5487
- startRow: fromRow,
5488
- endRow
5489
- });
5490
- newTransform = {
5491
- ...transform,
5492
- top: (selectionCell === null || selectionCell === void 0 ? void 0 : selectionCell.startY) || 0,
5493
- height: ((transform === null || transform === void 0 ? void 0 : transform.height) || 0) - selectionCell.endY + selectionCell.startY
5494
- };
5495
- } else if (toRow >= startRow && toRow <= endRow) {
5496
- const selectionCell = attachRangeWithCoord(skeleton, {
5497
- startColumn: fromColumn,
5498
- endColumn: toColumn,
5499
- startRow,
5500
- endRow: toRow
5501
- });
5502
- newTransform = {
5503
- ...transform,
5504
- top: selectionCell.startY - ((transform === null || transform === void 0 ? void 0 : transform.height) || 0)
5505
- };
5506
- } else {
5507
- const selectionCell = attachRangeWithCoord(skeleton, {
5508
- startColumn: fromColumn,
5509
- endColumn: toColumn,
5510
- startRow,
5511
- endRow
5512
- });
5513
- newTransform = {
5514
- ...transform,
5515
- height: ((transform === null || transform === void 0 ? void 0 : transform.height) || 0) - selectionCell.endY + selectionCell.startY
5516
- };
5517
- newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
5518
- if (newSheetTransform && newTransform) {
5519
- const axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
5520
- preUpdateDrawings.push({
5521
- ...drawing,
5522
- sheetTransform: newSheetTransform,
5523
- transform: newTransform,
5524
- axisAlignSheetTransform
5525
- });
5526
- break;
5527
- }
5528
- }
5529
- if (newTransform) newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
5530
- if (newTransform && newSheetTransform) {
5531
- const axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
5532
- updateDrawings.push({
5533
- ...drawing,
5534
- sheetTransform: newSheetTransform,
5535
- transform: newTransform,
5536
- axisAlignSheetTransform
5537
- });
5538
- break;
5539
- } else this._remainDrawingSize(transform, updateDrawings, drawing, skeleton);
5540
- }
5541
- }
5542
- });
5543
- if (updateDrawings.length === 0 && preUpdateDrawings.length === 0) return {
5544
- redos: [],
5545
- undos: []
5546
- };
5547
- const { redos, undos } = this._createUndoAndRedoMutation(unitId, subUnitId, updateDrawings);
5548
- const preRedos = [];
5549
- const preUndos = [];
5550
- if (preUpdateDrawings.length > 0) {
5551
- const { redos, undos } = this._createUndoAndRedoMutation(unitId, subUnitId, preUpdateDrawings);
5552
- preRedos.push(...redos);
5553
- preUndos.push(...undos);
5554
- }
5555
- return {
5556
- redos,
5557
- undos,
5558
- preRedos,
5559
- preUndos
5560
- };
5561
- }
5562
- _getDrawingUndoForRowAndColSize(unitId, subUnitId, ranges) {
5563
- const sheetSkeletonParam = this._sheetSkeletonService.getSkeletonParam(unitId, subUnitId);
5564
- if (!sheetSkeletonParam) return {
5565
- redos: [],
5566
- undos: []
5567
- };
5568
- const { skeleton } = sheetSkeletonParam;
5569
- const drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId);
5570
- const updateDrawings = [];
5571
- Object.keys(drawingData).forEach((drawingId) => {
5572
- const drawing = drawingData[drawingId];
5573
- const { sheetTransform, transform, anchorType = SheetDrawingAnchorType.Position } = drawing;
5574
- if (anchorType === SheetDrawingAnchorType.None) this._remainDrawingSize(transform, updateDrawings, drawing, skeleton);
5575
- else {
5576
- const { from, to } = sheetTransform;
5577
- const { row: fromRow, column: fromColumn } = from;
5578
- const { row: toRow, column: toColumn } = to;
5579
- for (let i = 0; i < ranges.length; i++) {
5580
- const { startRow, endRow, startColumn, endColumn } = ranges[i];
5581
- if (toRow < startRow || toColumn < startColumn) continue;
5582
- if (anchorType === SheetDrawingAnchorType.Position) {
5583
- if (fromRow <= startRow && toRow >= endRow || fromColumn <= startColumn && toColumn >= endColumn) {
5584
- this._remainDrawingSize(transform, updateDrawings, drawing, skeleton);
5585
- continue;
5586
- }
5587
- }
5588
- const newTransform = drawingPositionToTransform({ ...sheetTransform }, sheetSkeletonParam);
5589
- if (newTransform) {
5590
- updateDrawings.push({
5591
- ...drawing,
5592
- transform: newTransform
5593
- });
5594
- break;
5595
- }
5596
- }
5597
- }
5598
- });
5599
- if (updateDrawings.length === 0) return {
5600
- redos: [],
5601
- undos: []
5602
- };
5603
- return this._createUndoAndRedoMutation(unitId, subUnitId, updateDrawings);
5604
- }
5605
- _getUnitIdAndSubUnitId(params, type) {
5606
- let target;
5607
- if (type === "insert") target = getSheetCommandTarget(this._univerInstanceService, params);
5608
- else target = getSheetCommandTarget(this._univerInstanceService);
5609
- if (!target) return;
5610
- const { unitId, subUnitId } = target;
5611
- return {
5612
- unitId,
5613
- subUnitId
5614
- };
5615
- }
5616
- _moveRangeInterceptor(unitId, subUnitId, fromRange, toRange) {
5617
- const sheetSkeletonParam = this._sheetSkeletonService.getSkeletonParam(unitId, subUnitId);
5618
- if (!sheetSkeletonParam) return {
5619
- redos: [],
5620
- undos: []
5621
- };
5622
- const { skeleton } = sheetSkeletonParam;
5623
- const selectionRect = attachRangeWithCoord(skeleton, fromRange);
5624
- if (!selectionRect) return {
5625
- redos: [],
5626
- undos: []
5627
- };
5628
- const { startX, endX, startY, endY } = selectionRect;
5629
- const drawings = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
5630
- const containedDrawings = [];
5631
- Object.keys(drawings).forEach((drawingId) => {
5632
- const drawing = drawings[drawingId];
5633
- if (drawing.anchorType !== SheetDrawingAnchorType.Both) return;
5634
- const { transform } = drawing;
5635
- if (!transform) return;
5636
- const { left = 0, top = 0, width = 0, height = 0 } = transform;
5637
- const { drawingStartX, drawingEndX, drawingStartY, drawingEndY } = {
5638
- drawingStartX: left,
5639
- drawingEndX: left + width,
5640
- drawingStartY: top,
5641
- drawingEndY: top + height
5642
- };
5643
- if (startX <= drawingStartX && drawingEndX <= endX && startY <= drawingStartY && drawingEndY <= endY) containedDrawings.push(drawing);
5644
- });
5645
- const redos = [];
5646
- const undos = [];
5647
- const rowOffset = toRange.startRow - fromRange.startRow;
5648
- const colOffset = toRange.startColumn - fromRange.startColumn;
5649
- const updateDrawings = containedDrawings.map((drawing) => {
5650
- const oldSheetTransform = drawing.sheetTransform;
5651
- const sheetTransform = {
5652
- to: {
5653
- ...oldSheetTransform.to,
5654
- row: oldSheetTransform.to.row + rowOffset,
5655
- column: oldSheetTransform.to.column + colOffset
5656
- },
5657
- from: {
5658
- ...oldSheetTransform.from,
5659
- row: oldSheetTransform.from.row + rowOffset,
5660
- column: oldSheetTransform.from.column + colOffset
5661
- }
5662
- };
5663
- const transform = drawingPositionToTransform(sheetTransform, sheetSkeletonParam);
5664
- return {
5665
- unitId,
5666
- subUnitId,
5667
- drawingId: drawing.drawingId,
5668
- transform,
5669
- sheetTransform
5670
- };
5671
- });
5672
- if (updateDrawings.length) {
5673
- const { undo, redo, objects } = this._sheetDrawingService.getBatchUpdateOp(updateDrawings);
5674
- redos.push({
5675
- id: SetDrawingApplyMutation.id,
5676
- params: {
5677
- unitId,
5678
- subUnitId,
5679
- op: redo,
5680
- objects,
5681
- type: DrawingApplyType.UPDATE
5682
- }
5683
- });
5684
- undos.push({
5685
- id: SetDrawingApplyMutation.id,
5686
- params: {
5687
- unitId,
5688
- subUnitId,
5689
- op: undo,
5690
- objects,
5691
- type: DrawingApplyType.UPDATE
5692
- }
5693
- });
5694
- }
5695
- return {
5696
- redos,
5697
- undos
5698
- };
5699
- }
5700
- _moveRowInterceptor(params, type) {
5701
- const target = this._getUnitIdAndSubUnitId(params, type);
5702
- if (!target) return {
5703
- redos: [],
5704
- undos: []
5705
- };
5706
- const { unitId, subUnitId } = target;
5707
- const sheetSkeletonParam = this._sheetSkeletonService.getSkeletonParam(unitId, subUnitId);
5708
- if (!sheetSkeletonParam) return {
5709
- redos: [],
5710
- undos: []
5711
- };
5712
- const { range } = params;
5713
- const rowStartIndex = range.startRow;
5714
- const rowEndIndex = range.endRow;
5715
- const redos = [];
5716
- const undos = [];
5717
- const data = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
5718
- const updateDrawings = [];
5719
- const deleteDrawings = [];
5720
- Object.keys(data).forEach((drawingId) => {
5721
- const { sheetTransform, transform, anchorType = SheetDrawingAnchorType.Position } = data[drawingId];
5722
- if (!sheetTransform || !transform) return;
5723
- let newSheetTransform;
5724
- let newTransform;
5725
- let axisAlignSheetTransform;
5726
- if (type === "insert") {
5727
- var _param$axisAlignSheet5;
5728
- const param = this._expandRow(rowStartIndex, rowEndIndex, {
5729
- sheetSkeletonParam,
5730
- sheetTransform,
5731
- transform,
5732
- anchorType
5733
- });
5734
- newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
5735
- newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
5736
- axisAlignSheetTransform = (_param$axisAlignSheet5 = param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) !== null && _param$axisAlignSheet5 !== void 0 ? _param$axisAlignSheet5 : void 0;
5737
- } else {
5738
- const { from, to } = sheetTransform;
5739
- const { row: fromRow } = from;
5740
- const { row: toRow } = to;
5741
- if (anchorType === SheetDrawingAnchorType.Both && fromRow >= rowStartIndex && toRow <= rowEndIndex) deleteDrawings.push({
5742
- unitId,
5743
- subUnitId,
5744
- drawingId
5745
- });
5746
- else {
5747
- var _param$axisAlignSheet6;
5748
- const param = this._shrinkRow(rowStartIndex, rowEndIndex, {
5749
- sheetSkeletonParam,
5750
- sheetTransform,
5751
- transform,
5752
- anchorType
5753
- });
5754
- newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
5755
- newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
5756
- axisAlignSheetTransform = (_param$axisAlignSheet6 = param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) !== null && _param$axisAlignSheet6 !== void 0 ? _param$axisAlignSheet6 : void 0;
5757
- }
5758
- }
5759
- if (!newSheetTransform || !newTransform) return;
5760
- const params = {
5761
- unitId,
5762
- subUnitId,
5763
- drawingId,
5764
- transform: newTransform,
5765
- sheetTransform: newSheetTransform,
5766
- axisAlignSheetTransform
5767
- };
5768
- updateDrawings.push(params);
5769
- });
5770
- if (updateDrawings.length === 0 && deleteDrawings.length === 0) return {
5771
- redos: [],
5772
- undos: []
5773
- };
5774
- if (updateDrawings.length > 0) {
5775
- const { undo, redo, objects } = this._sheetDrawingService.getBatchUpdateOp(updateDrawings);
5776
- redos.push({
5777
- id: SetDrawingApplyMutation.id,
5778
- params: {
5779
- unitId,
5780
- subUnitId,
5781
- op: redo,
5782
- objects,
5783
- type: DrawingApplyType.UPDATE
5784
- }
5785
- });
5786
- undos.push({
5787
- id: SetDrawingApplyMutation.id,
5788
- params: {
5789
- unitId,
5790
- subUnitId,
5791
- op: undo,
5792
- objects,
5793
- type: DrawingApplyType.UPDATE
5794
- }
5795
- });
5796
- }
5797
- if (deleteDrawings.length > 0) {
5798
- const deleteJsonOp = this._sheetDrawingService.getBatchRemoveOp(deleteDrawings);
5799
- const deleteUndo = deleteJsonOp.undo;
5800
- const deleteRedo = deleteJsonOp.redo;
5801
- const deleteObjects = deleteJsonOp.objects;
5802
- redos.push({
5803
- id: SetDrawingApplyMutation.id,
5804
- params: {
5805
- unitId,
5806
- subUnitId,
5807
- op: deleteRedo,
5808
- objects: deleteObjects,
5809
- type: DrawingApplyType.REMOVE
5810
- }
5811
- });
5812
- undos.push({
5813
- id: SetDrawingApplyMutation.id,
5814
- params: {
5815
- unitId,
5816
- subUnitId,
5817
- op: deleteUndo,
5818
- objects: deleteObjects,
5819
- type: DrawingApplyType.INSERT
5820
- }
5821
- });
5822
- }
5823
- redos.push({
5824
- id: ClearSheetDrawingTransformerOperation.id,
5825
- params: [unitId]
5826
- });
5827
- undos.push({
5828
- id: ClearSheetDrawingTransformerOperation.id,
5829
- params: [unitId]
5830
- });
5831
- return {
5832
- redos,
5833
- undos
5834
- };
5835
- }
5836
- _moveColInterceptor(params, type) {
5837
- const target = this._getUnitIdAndSubUnitId(params, type);
5838
- if (!target) return {
5839
- redos: [],
5840
- undos: []
5841
- };
5842
- const { unitId, subUnitId } = target;
5843
- const sheetSkeletonParam = this._sheetSkeletonService.getSkeletonParam(unitId, subUnitId);
5844
- if (!sheetSkeletonParam) return {
5845
- redos: [],
5846
- undos: []
5847
- };
5848
- const { range } = params;
5849
- const colStartIndex = range.startColumn;
5850
- const colEndIndex = range.endColumn;
5851
- const redos = [];
5852
- const undos = [];
5853
- const data = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
5854
- const updateDrawings = [];
5855
- const deleteDrawings = [];
5856
- Object.keys(data).forEach((drawingId) => {
5857
- const { sheetTransform, transform, anchorType = SheetDrawingAnchorType.Position } = data[drawingId];
5858
- if (!sheetTransform || !transform) return;
5859
- let newSheetTransform;
5860
- let newTransform;
5861
- let axisAlignSheetTransform;
5862
- if (type === "insert") {
5863
- var _param$axisAlignSheet7;
5864
- const param = this._expandCol(colStartIndex, colEndIndex, {
5865
- sheetSkeletonParam,
5866
- sheetTransform,
5867
- transform,
5868
- anchorType
5869
- });
5870
- newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
5871
- newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
5872
- axisAlignSheetTransform = (_param$axisAlignSheet7 = param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) !== null && _param$axisAlignSheet7 !== void 0 ? _param$axisAlignSheet7 : void 0;
5873
- } else {
5874
- const { from, to } = sheetTransform;
5875
- const { column: fromColumn } = from;
5876
- const { column: toColumn } = to;
5877
- if (anchorType === SheetDrawingAnchorType.Both && fromColumn >= colStartIndex && toColumn <= colEndIndex) deleteDrawings.push({
5878
- unitId,
5879
- subUnitId,
5880
- drawingId
5881
- });
5882
- else {
5883
- var _param$axisAlignSheet8;
5884
- const param = this._shrinkCol(colStartIndex, colEndIndex, {
5885
- sheetSkeletonParam,
5886
- sheetTransform,
5887
- transform,
5888
- anchorType
5889
- });
5890
- newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
5891
- newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
5892
- axisAlignSheetTransform = (_param$axisAlignSheet8 = param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) !== null && _param$axisAlignSheet8 !== void 0 ? _param$axisAlignSheet8 : void 0;
5893
- }
5894
- }
5895
- if (!newSheetTransform || !newTransform) return;
5896
- const params = {
5897
- unitId,
5898
- subUnitId,
5899
- drawingId,
5900
- transform: newTransform,
5901
- sheetTransform: newSheetTransform,
5902
- axisAlignSheetTransform
5903
- };
5904
- updateDrawings.push(params);
5905
- });
5906
- if (updateDrawings.length === 0 && deleteDrawings.length === 0) return {
5907
- redos: [],
5908
- undos: []
5909
- };
5910
- if (updateDrawings.length > 0) {
5911
- const { undo, redo, objects } = this._sheetDrawingService.getBatchUpdateOp(updateDrawings);
5912
- redos.push({
5913
- id: SetDrawingApplyMutation.id,
5914
- params: {
5915
- unitId,
5916
- subUnitId,
5917
- op: redo,
5918
- objects,
5919
- type: DrawingApplyType.UPDATE
5920
- }
5921
- });
5922
- undos.push({
5923
- id: SetDrawingApplyMutation.id,
5924
- params: {
5925
- unitId,
5926
- subUnitId,
5927
- op: undo,
5928
- objects,
5929
- type: DrawingApplyType.UPDATE
5930
- }
5931
- });
5932
- }
5933
- if (deleteDrawings.length > 0) {
5934
- const deleteJsonOp = this._sheetDrawingService.getBatchRemoveOp(deleteDrawings);
5935
- const deleteUndo = deleteJsonOp.undo;
5936
- const deleteRedo = deleteJsonOp.redo;
5937
- const deleteObjects = deleteJsonOp.objects;
5938
- redos.push({
5939
- id: SetDrawingApplyMutation.id,
5940
- params: {
5941
- unitId,
5942
- subUnitId,
5943
- op: deleteRedo,
5944
- objects: deleteObjects,
5945
- type: DrawingApplyType.REMOVE
5946
- }
5947
- });
5948
- undos.push({
5949
- id: SetDrawingApplyMutation.id,
5950
- params: {
5951
- unitId,
5952
- subUnitId,
5953
- op: deleteUndo,
5954
- objects: deleteObjects,
5955
- type: DrawingApplyType.INSERT
5956
- }
5957
- });
5958
- }
5959
- redos.push({
5960
- id: ClearSheetDrawingTransformerOperation.id,
5961
- params: [unitId]
5962
- });
5963
- undos.push({
5964
- id: ClearSheetDrawingTransformerOperation.id,
5965
- params: [unitId]
5966
- });
5967
- return {
5968
- redos,
5969
- undos
5970
- };
5971
- }
5972
- _expandCol(colStartIndex, colEndIndex, options) {
5973
- const { sheetSkeletonParam, sheetTransform, transform, anchorType = SheetDrawingAnchorType.Position } = options;
5974
- const { skeleton } = sheetSkeletonParam;
5975
- const colCount = colEndIndex - colStartIndex + 1;
5976
- const { from, to } = sheetTransform;
5977
- const { column: fromColumn } = from;
5978
- const { column: toColumn } = to;
5979
- if (anchorType === SheetDrawingAnchorType.None) return {
5980
- newSheetTransform: transformToDrawingPosition({ ...transform }, skeleton),
5981
- newTransform: transform,
5982
- axisAlignSheetTransform: transformToAxisAlignPosition({ ...transform }, skeleton)
5983
- };
5984
- let newSheetTransform = null;
5985
- let newTransform = null;
5986
- let axisAlignSheetTransform = null;
5987
- if (fromColumn >= colStartIndex) {
5988
- const selectionCell = attachRangeWithCoord(skeleton, {
5989
- startColumn: colStartIndex,
5990
- endColumn: colEndIndex,
5991
- startRow: from.row,
5992
- endRow: to.row
5993
- });
5994
- newTransform = {
5995
- ...transform,
5996
- left: (transform.left || 0) + selectionCell.endX - selectionCell.startX
5997
- };
5998
- newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
5999
- axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
6000
- } else if (toColumn >= colEndIndex) if (anchorType === SheetDrawingAnchorType.Both) {
6001
- newSheetTransform = {
6002
- from: { ...from },
6003
- to: {
6004
- ...to,
6005
- column: toColumn + colCount
6006
- }
6007
- };
6008
- newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
6009
- } else return {
6010
- newSheetTransform: transformToDrawingPosition({ ...transform }, skeleton),
6011
- newTransform: transform,
6012
- axisAlignSheetTransform: transformToAxisAlignPosition({ ...transform }, skeleton)
6013
- };
6014
- if (newSheetTransform && newTransform) return {
6015
- newSheetTransform,
6016
- newTransform,
6017
- axisAlignSheetTransform
6018
- };
6019
- return null;
6020
- }
6021
- _shrinkCol(colStartIndex, colEndIndex, options) {
6022
- const { sheetSkeletonParam, sheetTransform, transform, anchorType = SheetDrawingAnchorType.Position } = options;
6023
- const { skeleton } = sheetSkeletonParam;
6024
- const colCount = colEndIndex - colStartIndex + 1;
6025
- const { from, to } = sheetTransform;
6026
- const { column: fromColumn } = from;
6027
- const { column: toColumn } = to;
6028
- if (anchorType === SheetDrawingAnchorType.None) return {
6029
- newSheetTransform: transformToDrawingPosition({ ...transform }, skeleton),
6030
- newTransform: transform,
6031
- axisAlignSheetTransform: transformToAxisAlignPosition({ ...transform }, skeleton)
6032
- };
6033
- let newSheetTransform = null;
6034
- let newTransform = null;
6035
- let axisAlignSheetTransform = null;
6036
- if (fromColumn > colEndIndex) {
6037
- newSheetTransform = {
6038
- from: {
6039
- ...from,
6040
- column: fromColumn - colCount
6041
- },
6042
- to: {
6043
- ...to,
6044
- column: toColumn - colCount
6045
- }
6046
- };
6047
- newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
6048
- } else if (fromColumn >= colStartIndex && toColumn <= colEndIndex) return null;
6049
- else if (fromColumn < colStartIndex && toColumn > colEndIndex) if (anchorType === SheetDrawingAnchorType.Both) {
6050
- newSheetTransform = {
6051
- from: { ...from },
6052
- to: {
6053
- ...to,
6054
- column: toColumn - colCount
6055
- }
6056
- };
6057
- newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
6058
- } else return {
6059
- newSheetTransform: transformToDrawingPosition({ ...transform }, skeleton),
6060
- newTransform: transform,
6061
- axisAlignSheetTransform: transformToAxisAlignPosition({ ...transform }, skeleton)
6062
- };
6063
- else if (fromColumn >= colStartIndex && fromColumn <= colEndIndex) {
6064
- if (fromColumn === colStartIndex) newTransform = {
6065
- ...transform,
6066
- left: (transform.left || 0) - sheetTransform.from.columnOffset
6067
- };
6068
- else {
6069
- const selectionCell = attachRangeWithCoord(skeleton, {
6070
- startColumn: colStartIndex,
6071
- endColumn: fromColumn - 1,
6072
- startRow: from.row,
6073
- endRow: to.row
6074
- });
6075
- newTransform = {
6076
- ...transform,
6077
- left: (transform.left || 0) - selectionCell.endX + selectionCell.startX - sheetTransform.from.columnOffset
6078
- };
6079
- }
6080
- newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
6081
- axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
6082
- } else if (toColumn >= colStartIndex && toColumn <= colEndIndex && anchorType === SheetDrawingAnchorType.Both) {
6083
- const selectionCell = attachRangeWithCoord(skeleton, {
6084
- startColumn: colStartIndex - 1,
6085
- endColumn: colStartIndex - 1,
6086
- startRow: from.row,
6087
- endRow: to.row
6088
- });
6089
- newSheetTransform = {
6090
- from: { ...from },
6091
- to: {
6092
- ...to,
6093
- column: colStartIndex - 1,
6094
- columnOffset: selectionCell.endX - selectionCell.startX
6095
- }
6096
- };
6097
- newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
6098
- }
6099
- if (newSheetTransform && newTransform) return {
6100
- newSheetTransform,
6101
- newTransform,
6102
- axisAlignSheetTransform
6103
- };
6104
- return null;
6105
- }
6106
- _expandRow(rowStartIndex, rowEndIndex, options) {
6107
- const { sheetSkeletonParam, sheetTransform, transform, anchorType = SheetDrawingAnchorType.Position } = options;
6108
- const { skeleton } = sheetSkeletonParam;
6109
- const rowCount = rowEndIndex - rowStartIndex + 1;
6110
- const { from, to } = sheetTransform;
6111
- const { row: fromRow } = from;
6112
- const { row: toRow } = to;
6113
- if (anchorType === SheetDrawingAnchorType.None) return {
6114
- newSheetTransform: transformToDrawingPosition({ ...transform }, skeleton),
6115
- newTransform: transform,
6116
- axisAlignSheetTransform: transformToAxisAlignPosition({ ...transform }, skeleton)
6117
- };
6118
- let newSheetTransform = null;
6119
- let newTransform = null;
6120
- let axisAlignSheetTransform = null;
6121
- if (fromRow >= rowStartIndex) {
6122
- const selectionCell = attachRangeWithCoord(skeleton, {
6123
- startRow: rowStartIndex,
6124
- endRow: rowEndIndex,
6125
- startColumn: from.column,
6126
- endColumn: to.column
6127
- });
6128
- newTransform = {
6129
- ...transform,
6130
- top: (transform.top || 0) + selectionCell.endY - selectionCell.startY
6131
- };
6132
- newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
6133
- axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
6134
- } else if (toRow >= rowEndIndex) if (anchorType === SheetDrawingAnchorType.Both) {
6135
- newSheetTransform = {
6136
- from: { ...from },
6137
- to: {
6138
- ...to,
6139
- row: toRow + rowCount
6140
- }
6141
- };
6142
- newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
6143
- } else return {
6144
- newSheetTransform: transformToDrawingPosition({ ...transform }, skeleton),
6145
- newTransform: transform,
6146
- axisAlignSheetTransform: transformToAxisAlignPosition({ ...transform }, skeleton)
6147
- };
6148
- if (newSheetTransform && newTransform) return {
6149
- newSheetTransform,
6150
- newTransform,
6151
- axisAlignSheetTransform
6152
- };
6153
- return null;
6154
- }
6155
- _shrinkRow(rowStartIndex, rowEndIndex, options) {
6156
- const { sheetSkeletonParam, sheetTransform, transform, anchorType = SheetDrawingAnchorType.Position } = options;
6157
- const { skeleton } = sheetSkeletonParam;
6158
- const rowCount = rowEndIndex - rowStartIndex + 1;
6159
- const { from, to } = sheetTransform;
6160
- const { row: fromRow } = from;
6161
- const { row: toRow } = to;
6162
- if (anchorType === SheetDrawingAnchorType.None) return {
6163
- newSheetTransform: transformToDrawingPosition({ ...transform }, skeleton),
6164
- newTransform: transform,
6165
- axisAlignSheetTransform: transformToAxisAlignPosition({ ...transform }, skeleton)
6166
- };
6167
- let newSheetTransform = null;
6168
- let newTransform = null;
6169
- let axisAlignSheetTransform = null;
6170
- if (fromRow > rowEndIndex) {
6171
- newSheetTransform = {
6172
- from: {
6173
- ...from,
6174
- row: fromRow - rowCount
6175
- },
6176
- to: {
6177
- ...to,
6178
- row: toRow - rowCount
6179
- }
6180
- };
6181
- newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
6182
- } else if (fromRow >= rowStartIndex && toRow <= rowEndIndex) return null;
6183
- else if (fromRow < rowStartIndex && toRow > rowEndIndex) if (anchorType === SheetDrawingAnchorType.Both) {
6184
- newSheetTransform = {
6185
- from: { ...from },
6186
- to: {
6187
- ...to,
6188
- row: toRow - rowCount
6189
- }
6190
- };
6191
- newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
6192
- } else return {
6193
- newSheetTransform: transformToDrawingPosition({ ...transform }, skeleton),
6194
- newTransform: transform,
6195
- axisAlignSheetTransform: transformToAxisAlignPosition({ ...transform }, skeleton)
6196
- };
6197
- else if (fromRow >= rowStartIndex && fromRow <= rowEndIndex) {
6198
- if (fromRow === rowStartIndex) newTransform = {
6199
- ...transform,
6200
- top: (transform.top || 0) - sheetTransform.from.rowOffset
6201
- };
6202
- else {
6203
- const selectionCell = attachRangeWithCoord(skeleton, {
6204
- startRow: rowStartIndex,
6205
- endRow: fromRow - 1,
6206
- startColumn: from.column,
6207
- endColumn: to.column
6208
- });
6209
- newTransform = {
6210
- ...transform,
6211
- top: (transform.top || 0) - selectionCell.endY + selectionCell.startY - sheetTransform.from.rowOffset
6212
- };
6213
- }
6214
- newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
6215
- axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
6216
- } else if (toRow >= rowStartIndex && toRow <= rowEndIndex && anchorType === SheetDrawingAnchorType.Both) {
6217
- const selectionCell = attachRangeWithCoord(skeleton, {
6218
- startColumn: from.column,
6219
- endColumn: from.column,
6220
- startRow: rowStartIndex - 1,
6221
- endRow: rowStartIndex - 1
6222
- });
6223
- newSheetTransform = {
6224
- from: { ...from },
6225
- to: {
6226
- ...to,
6227
- row: rowStartIndex - 1,
6228
- rowOffset: selectionCell.endY - selectionCell.startY
6229
- }
6230
- };
6231
- newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
6232
- }
6233
- if (newSheetTransform && newTransform) return {
6234
- newSheetTransform,
6235
- newTransform,
6236
- axisAlignSheetTransform
6237
- };
6238
- return null;
6239
- }
6240
- _commandListener() {
6241
- this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
6242
- if (command.id === SetWorksheetActiveOperation.id) {
6243
- const { unitId, subUnitId } = command.params;
6244
- this._updateDrawings(unitId, subUnitId);
6245
- }
6246
- }));
6247
- this.disposeWithMe(this._context.activated$.subscribe((activated) => {
6248
- const { unit, unitId } = this._context;
6249
- if (activated) {
6250
- const subUnitId = unit.getActiveSheet().getSheetId();
6251
- this._updateDrawings(unitId, subUnitId);
6252
- } else this._clearDrawings(unitId);
6253
- }));
6254
- }
6255
- _clearDrawings(selfUnitId) {
6256
- setTimeout(() => {
6257
- const drawingMap = this._drawingManagerService.drawingManagerData;
6258
- const removeDrawings = [];
6259
- Object.keys(drawingMap !== null && drawingMap !== void 0 ? drawingMap : {}).forEach((unitId) => {
6260
- var _drawingMap$unitId;
6261
- const subUnitMap = (_drawingMap$unitId = drawingMap[unitId]) !== null && _drawingMap$unitId !== void 0 ? _drawingMap$unitId : {};
6262
- Object.keys(subUnitMap).forEach((subUnitId) => {
6263
- var _subUnitMap$subUnitId, _subUnitMap$subUnitId2;
6264
- const drawingData = (_subUnitMap$subUnitId = (_subUnitMap$subUnitId2 = subUnitMap[subUnitId]) === null || _subUnitMap$subUnitId2 === void 0 ? void 0 : _subUnitMap$subUnitId2.data) !== null && _subUnitMap$subUnitId !== void 0 ? _subUnitMap$subUnitId : {};
6265
- Object.keys(drawingData).forEach((drawingId) => {
6266
- if (unitId === selfUnitId) removeDrawings.push(drawingData[drawingId]);
6267
- });
6268
- });
6269
- });
6270
- this._sheetDrawingService.removeNotification(removeDrawings);
6271
- this._drawingManagerService.removeNotification(removeDrawings);
6272
- });
6273
- }
6274
- _updateDrawings(showUnitId, showSubunitId) {
6275
- setTimeout(() => {
6276
- const sheetSkeletonParam = this._sheetSkeletonService.getSkeletonParam(showUnitId, showSubunitId);
6277
- const drawingMap = this._drawingManagerService.drawingManagerData;
6278
- const insertDrawings = [];
6279
- const removeDrawings = [];
6280
- Object.keys(drawingMap !== null && drawingMap !== void 0 ? drawingMap : {}).forEach((unitId) => {
6281
- var _drawingMap$unitId2;
6282
- if (unitId !== showUnitId) return;
6283
- const subUnitMap = (_drawingMap$unitId2 = drawingMap[unitId]) !== null && _drawingMap$unitId2 !== void 0 ? _drawingMap$unitId2 : {};
6284
- Object.keys(subUnitMap).forEach((subUnitId) => {
6285
- var _subUnitMap$subUnitId3, _subUnitMap$subUnitId4;
6286
- const drawingData = (_subUnitMap$subUnitId3 = (_subUnitMap$subUnitId4 = subUnitMap[subUnitId]) === null || _subUnitMap$subUnitId4 === void 0 ? void 0 : _subUnitMap$subUnitId4.data) !== null && _subUnitMap$subUnitId3 !== void 0 ? _subUnitMap$subUnitId3 : {};
6287
- Object.keys(drawingData).forEach((drawingId) => {
6288
- if (unitId === showUnitId && subUnitId === showSubunitId) {
6289
- const drawing = drawingData[drawingId];
6290
- if (drawing.sheetTransform) drawing.transform = drawingPositionToTransform(drawing.sheetTransform, sheetSkeletonParam);
6291
- insertDrawings.push(drawingData[drawingId]);
6292
- } else removeDrawings.push(drawingData[drawingId]);
6293
- });
6294
- });
6295
- });
6296
- this._sheetDrawingService.removeNotification(removeDrawings);
6297
- this._sheetDrawingService.addNotification(insertDrawings);
6298
- this._drawingManagerService.removeNotification(removeDrawings);
6299
- this._drawingManagerService.addNotification(insertDrawings);
6300
- }, 0);
6301
- }
6302
- _sheetRefreshListener() {
6303
- this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
6304
- if (!REFRESH_MUTATIONS.includes(command.id)) return;
6305
- requestIdleCallback(() => {
6306
- const params = command.params;
6307
- const target = getSheetCommandTarget(this._univerInstanceService, params);
6308
- if (!target) return;
6309
- const { unitId, subUnitId, worksheet } = target;
6310
- let ranges = [];
6311
- if ("ranges" in params) ranges = params.ranges;
6312
- else if ("rowsAutoHeightInfo" in params) ranges = params.rowsAutoHeightInfo.map((info) => ({
6313
- startRow: info.row,
6314
- endRow: info.row,
6315
- startColumn: 0,
6316
- endColumn: worksheet.getColumnCount() - 1
6317
- }));
6318
- this._refreshDrawingTransform(unitId, subUnitId, ranges);
6319
- });
6320
- }));
6321
- }
6322
- _refreshDrawingTransform(unitId, subUnitId, ranges) {
6323
- var _this$_drawingManager;
6324
- const sheetSkeletonParam = this._sheetSkeletonService.getSkeletonParam(unitId, subUnitId);
6325
- const drawingData = (_this$_drawingManager = this._drawingManagerService.getDrawingData(unitId, subUnitId)) !== null && _this$_drawingManager !== void 0 ? _this$_drawingManager : {};
6326
- const updateDrawings = [];
6327
- Object.keys(drawingData).forEach((drawingId) => {
6328
- const drawing = drawingData[drawingId];
6329
- const { sheetTransform, transform, anchorType = SheetDrawingAnchorType.Position } = drawing;
6330
- if (anchorType === SheetDrawingAnchorType.None) return true;
6331
- if (!sheetTransform) return true;
6332
- const { from, to } = sheetTransform;
6333
- const { row: fromRow, column: fromColumn } = from;
6334
- const { row: toRow, column: toColumn } = to;
6335
- for (let i = 0; i < ranges.length; i++) {
6336
- const { startRow, endRow, startColumn, endColumn } = ranges[i];
6337
- if (Rectangle.intersects({
6338
- startRow,
6339
- endRow,
6340
- startColumn,
6341
- endColumn
6342
- }, {
6343
- startRow: fromRow,
6344
- endRow: toRow,
6345
- startColumn: fromColumn,
6346
- endColumn: toColumn
6347
- }) || fromRow > endRow || fromColumn > endColumn) {
6348
- const isPositionAnchor = anchorType === SheetDrawingAnchorType.Position;
6349
- const newTransform = drawingPositionToTransform(sheetTransform, sheetSkeletonParam);
6350
- updateDrawings.push({
6351
- ...drawing,
6352
- transform: {
6353
- ...newTransform,
6354
- width: isPositionAnchor ? transform === null || transform === void 0 ? void 0 : transform.width : newTransform === null || newTransform === void 0 ? void 0 : newTransform.width,
6355
- height: isPositionAnchor ? transform === null || transform === void 0 ? void 0 : transform.height : newTransform === null || newTransform === void 0 ? void 0 : newTransform.height
6356
- }
6357
- });
6358
- break;
6359
- }
6360
- }
6361
- });
6362
- if (updateDrawings.length === 0) return;
6363
- this._sheetDrawingService.refreshTransform(updateDrawings);
6364
- this._drawingManagerService.refreshTransform(updateDrawings);
6365
- this._commandService.syncExecuteCommand(ClearSheetDrawingTransformerOperation.id, [unitId]);
6366
- }
6367
- };
6368
- SheetDrawingTransformAffectedController = __decorate([
6369
- __decorateParam(1, ICommandService),
6370
- __decorateParam(2, Inject(SheetSkeletonService)),
6371
- __decorateParam(3, ISheetSelectionRenderService),
6372
- __decorateParam(4, Inject(SheetInterceptorService)),
6373
- __decorateParam(5, Inject(SheetsSelectionsService)),
6374
- __decorateParam(6, ISheetDrawingService),
6375
- __decorateParam(7, IDrawingManagerService),
6376
- __decorateParam(8, IUniverInstanceService)
6377
- ], SheetDrawingTransformAffectedController);
6378
-
6379
5002
  //#endregion
6380
5003
  //#region src/commands/commands/flip-drawings.command.ts
6381
5004
  /**
@@ -6991,7 +5614,7 @@ let UniverSheetsDrawingUIPlugin = class UniverSheetsDrawingUIPlugin extends Plug
6991
5614
  _registerRenderModules() {
6992
5615
  [
6993
5616
  [SheetDrawingUpdateController],
6994
- [SheetDrawingTransformAffectedController],
5617
+ [SheetDrawingActiveRenderController],
6995
5618
  [SheetsDrawingRenderController],
6996
5619
  [SheetCellImageHoverRenderController]
6997
5620
  ].forEach((m) => {