@univerjs/sheets-drawing 1.0.0-alpha.5 → 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/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { CopySheetCommand, RemoveSheetCommand, SheetInterceptorService, convertPositionSheetOverGridToAbsolute } from "@univerjs/sheets";
2
- import { ArrangeTypeEnum, CommandType, DependentOn, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, Plugin, UniverInstanceType, createIdentifier, merge, sequenceExecute } from "@univerjs/core";
1
+ import { CopySheetCommand, DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, DeltaColumnWidthCommand, DeltaRowHeightCommand, InsertColCommand, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, InsertRowCommand, MoveColsCommand, MoveRangeCommand, MoveRowsCommand, RemoveColCommand, RemoveRowCommand, RemoveSheetCommand, SetColHiddenCommand, SetColHiddenMutation, SetColVisibleMutation, SetColWidthCommand, SetRowHeightCommand, SetRowHiddenCommand, SetRowHiddenMutation, SetRowVisibleMutation, SetSpecificColsVisibleCommand, SetSpecificRowsVisibleCommand, SetWorksheetColWidthMutation, SetWorksheetRowAutoHeightMutation, SetWorksheetRowHeightMutation, SetWorksheetRowIsAutoHeightMutation, SheetInterceptorService, SheetSkeletonService, SheetsSelectionsService, attachRangeWithCoord, convertPositionSheetOverGridToAbsolute, getSheetCommandTarget } from "@univerjs/sheets";
2
+ import { ArrangeTypeEnum, CommandType, DependentOn, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, Plugin, RANGE_TYPE, Rectangle, UniverInstanceType, createIdentifier, merge, sequenceExecute, toDisposable } from "@univerjs/core";
3
3
  import { IDrawingManagerService, UnitDrawingService, UniverDrawingPlugin, getOrCreateDrawingCopyPlan, resolveDrawingRotateEnabled } from "@univerjs/drawing";
4
4
  import { IRenderManagerService } from "@univerjs/engine-render";
5
5
 
@@ -652,7 +652,7 @@ SheetsDrawingLoadController = __decorate([
652
652
  //#endregion
653
653
  //#region package.json
654
654
  var name = "@univerjs/sheets-drawing";
655
- var version = "1.0.0-alpha.5";
655
+ var version = "1.0.0-alpha.7";
656
656
 
657
657
  //#endregion
658
658
  //#region src/config/config.ts
@@ -717,6 +717,1327 @@ function _defineProperty(e, r, t) {
717
717
  }) : e[r] = t, e;
718
718
  }
719
719
 
720
+ //#endregion
721
+ //#region src/services/sheet-drawing-transform-plan.service.ts
722
+ function createEmptyResult() {
723
+ return {
724
+ preRedos: [],
725
+ redos: [],
726
+ preUndos: [],
727
+ undos: []
728
+ };
729
+ }
730
+ var SheetDrawingTransformPlanService = class {
731
+ constructor() {
732
+ _defineProperty(this, "_extensions", []);
733
+ }
734
+ register(extension) {
735
+ this._extensions.push(extension);
736
+ this._extensions.sort((a, b) => {
737
+ var _b$priority, _a$priority;
738
+ return ((_b$priority = b.priority) !== null && _b$priority !== void 0 ? _b$priority : 0) - ((_a$priority = a.priority) !== null && _a$priority !== void 0 ? _a$priority : 0);
739
+ });
740
+ return toDisposable(() => {
741
+ const index = this._extensions.indexOf(extension);
742
+ if (index >= 0) this._extensions.splice(index, 1);
743
+ });
744
+ }
745
+ transform(plan) {
746
+ return this._extensions.reduce((all, extension) => {
747
+ var _next$preRedos, _next$redos, _next$preUndos, _next$undos;
748
+ const next = extension.transform(plan);
749
+ if (!next) return all;
750
+ all.preRedos.push(...(_next$preRedos = next.preRedos) !== null && _next$preRedos !== void 0 ? _next$preRedos : []);
751
+ all.redos.push(...(_next$redos = next.redos) !== null && _next$redos !== void 0 ? _next$redos : []);
752
+ all.preUndos.push(...(_next$preUndos = next.preUndos) !== null && _next$preUndos !== void 0 ? _next$preUndos : []);
753
+ all.undos.push(...(_next$undos = next.undos) !== null && _next$undos !== void 0 ? _next$undos : []);
754
+ return all;
755
+ }, createEmptyResult());
756
+ }
757
+ };
758
+
759
+ //#endregion
760
+ //#region src/controllers/sheet-drawing-transform-affected.controller.ts
761
+ const UPDATE_COMMANDS = [
762
+ InsertRowCommand.id,
763
+ InsertColCommand.id,
764
+ RemoveRowCommand.id,
765
+ RemoveColCommand.id,
766
+ DeleteRangeMoveLeftCommand.id,
767
+ DeleteRangeMoveUpCommand.id,
768
+ InsertRangeMoveDownCommand.id,
769
+ InsertRangeMoveRightCommand.id,
770
+ DeltaRowHeightCommand.id,
771
+ SetRowHeightCommand.id,
772
+ DeltaColumnWidthCommand.id,
773
+ SetColWidthCommand.id,
774
+ SetRowHiddenCommand.id,
775
+ SetSpecificRowsVisibleCommand.id,
776
+ SetSpecificColsVisibleCommand.id,
777
+ SetColHiddenCommand.id,
778
+ MoveColsCommand.id,
779
+ MoveRowsCommand.id,
780
+ MoveRangeCommand.id
781
+ ];
782
+ const REFRESH_MUTATIONS = [
783
+ SetRowVisibleMutation.id,
784
+ SetRowHiddenMutation.id,
785
+ SetColVisibleMutation.id,
786
+ SetColHiddenMutation.id,
787
+ SetWorksheetRowHeightMutation.id,
788
+ SetWorksheetRowAutoHeightMutation.id,
789
+ SetWorksheetRowIsAutoHeightMutation.id,
790
+ SetWorksheetColWidthMutation.id
791
+ ];
792
+ let SheetDrawingTransformAffectedController = class SheetDrawingTransformAffectedController extends Disposable {
793
+ constructor(_commandService, _sheetSkeletonService, _sheetInterceptorService, _selectionManagerService, _sheetDrawingService, _drawingManagerService, _univerInstanceService, _transformPlanService) {
794
+ super();
795
+ this._commandService = _commandService;
796
+ this._sheetSkeletonService = _sheetSkeletonService;
797
+ this._sheetInterceptorService = _sheetInterceptorService;
798
+ this._selectionManagerService = _selectionManagerService;
799
+ this._sheetDrawingService = _sheetDrawingService;
800
+ this._drawingManagerService = _drawingManagerService;
801
+ this._univerInstanceService = _univerInstanceService;
802
+ this._transformPlanService = _transformPlanService;
803
+ _defineProperty(this, "_currentCommand", {
804
+ id: "",
805
+ params: {}
806
+ });
807
+ this._sheetInterceptorListener();
808
+ this._sheetRefreshListener();
809
+ }
810
+ _sheetInterceptorListener() {
811
+ this.disposeWithMe(this._sheetInterceptorService.interceptAfterCommand({ getMutations: (commandInfo) => {
812
+ const { id, params } = commandInfo;
813
+ if (!UPDATE_COMMANDS.includes(id) || !params) return {
814
+ redos: [],
815
+ undos: []
816
+ };
817
+ this._currentCommand = commandInfo;
818
+ if (id === InsertRowCommand.id) return this._moveRowInterceptor(params, "insert");
819
+ else if ([
820
+ MoveColsCommand.id,
821
+ MoveRowsCommand.id,
822
+ MoveRangeCommand.id
823
+ ].includes(id)) {
824
+ let target;
825
+ if (id === MoveRangeCommand.id) {
826
+ const _params = params;
827
+ if (_params.toUnitId && _params.fromUnitId && _params.toUnitId !== _params.fromUnitId || _params.toSubUnitId && _params.fromSubUnitId && _params.toSubUnitId !== _params.fromSubUnitId) return {
828
+ redos: [],
829
+ undos: []
830
+ };
831
+ target = getSheetCommandTarget(this._univerInstanceService, {
832
+ unitId: _params.toUnitId,
833
+ subUnitId: _params.toSubUnitId
834
+ });
835
+ } else target = getSheetCommandTarget(this._univerInstanceService, params);
836
+ if (!target) return {
837
+ redos: [],
838
+ undos: []
839
+ };
840
+ const { unitId, subUnitId } = target;
841
+ const { fromRange, toRange } = params;
842
+ return this._moveRangeInterceptor(unitId, subUnitId, fromRange, toRange);
843
+ } else if (id === InsertColCommand.id) return this._moveColInterceptor(params, "insert");
844
+ else if (id === RemoveRowCommand.id) return this._moveRowInterceptor(params, "remove");
845
+ else if (id === RemoveColCommand.id) return this._moveColInterceptor(params, "remove");
846
+ else if (id === DeleteRangeMoveLeftCommand.id) {
847
+ const { range } = params;
848
+ return this._getRangeMoveUndo(range, 0);
849
+ } else if (id === DeleteRangeMoveUpCommand.id) {
850
+ const { range } = params;
851
+ return this._getRangeMoveUndo(range, 1);
852
+ } else if (id === InsertRangeMoveDownCommand.id) {
853
+ const { range } = params;
854
+ return this._getRangeMoveUndo(range, 2);
855
+ } else if (id === InsertRangeMoveRightCommand.id) {
856
+ const { range } = params;
857
+ return this._getRangeMoveUndo(range, 3);
858
+ } else if (id === SetRowHiddenCommand.id || id === SetSpecificRowsVisibleCommand.id) {
859
+ var _this$_selectionManag;
860
+ const _params = params;
861
+ const target = getSheetCommandTarget(this._univerInstanceService, _params);
862
+ if (!target) return {
863
+ redos: [],
864
+ undos: []
865
+ };
866
+ const { unitId, subUnitId } = target;
867
+ 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));
868
+ if (!ranges || ranges.length === 0) return {
869
+ redos: [],
870
+ undos: []
871
+ };
872
+ return this._getDrawingUndoForRowVisible(unitId, subUnitId, ranges);
873
+ } else if (id === SetColHiddenCommand.id || id === SetSpecificColsVisibleCommand.id) {
874
+ var _this$_selectionManag2;
875
+ const _params = params;
876
+ const target = getSheetCommandTarget(this._univerInstanceService, _params);
877
+ if (!target) return {
878
+ redos: [],
879
+ undos: []
880
+ };
881
+ const { unitId, subUnitId } = target;
882
+ 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));
883
+ if (!ranges || ranges.length === 0) return {
884
+ redos: [],
885
+ undos: []
886
+ };
887
+ return this._getDrawingUndoForColVisible(unitId, subUnitId, ranges);
888
+ } else if (id === DeltaRowHeightCommand.id || id === DeltaColumnWidthCommand.id) {
889
+ const target = getSheetCommandTarget(this._univerInstanceService);
890
+ if (!target) return {
891
+ redos: [],
892
+ undos: []
893
+ };
894
+ const { unitId, subUnitId, worksheet } = target;
895
+ const ranges = [];
896
+ if (id === DeltaRowHeightCommand.id) ranges.push({
897
+ startRow: params.anchorRow,
898
+ endRow: params.anchorRow,
899
+ startColumn: 0,
900
+ endColumn: worksheet.getColumnCount() - 1
901
+ });
902
+ else ranges.push({
903
+ startRow: 0,
904
+ endRow: worksheet.getRowCount() - 1,
905
+ startColumn: params.anchorCol,
906
+ endColumn: params.anchorCol
907
+ });
908
+ return this._getDrawingUndoForRowAndColSize(unitId, subUnitId, ranges);
909
+ } else if (id === SetRowHeightCommand.id || id === SetColWidthCommand.id) {
910
+ var _this$_selectionManag3;
911
+ const _params = params;
912
+ const target = getSheetCommandTarget(this._univerInstanceService, _params);
913
+ if (!target) return {
914
+ redos: [],
915
+ undos: []
916
+ };
917
+ const { unitId, subUnitId } = target;
918
+ const ranges = _params.ranges || ((_this$_selectionManag3 = this._selectionManagerService.getCurrentSelections()) === null || _this$_selectionManag3 === void 0 ? void 0 : _this$_selectionManag3.map((s) => s.range));
919
+ if (!ranges || ranges.length === 0) return {
920
+ redos: [],
921
+ undos: []
922
+ };
923
+ return this._getDrawingUndoForRowAndColSize(unitId, subUnitId, ranges);
924
+ }
925
+ return {
926
+ redos: [],
927
+ undos: []
928
+ };
929
+ } }));
930
+ }
931
+ _finalizePlan(unitId, subUnitId, updates, deletes = [], mode = "command", command = this._currentCommand) {
932
+ const skeleton = this._sheetSkeletonService.getSkeleton(unitId, subUnitId);
933
+ if (!skeleton) return {
934
+ redos: [],
935
+ undos: []
936
+ };
937
+ const data = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
938
+ const originals = new Map(Object.entries(data));
939
+ const plan = {
940
+ command,
941
+ mode,
942
+ unitId,
943
+ subUnitId,
944
+ skeleton,
945
+ originals,
946
+ updates: /* @__PURE__ */ new Map(),
947
+ deletes: new Set(deletes.map(({ drawingId }) => drawingId).filter((drawingId) => Boolean(drawingId)))
948
+ };
949
+ updates.forEach((patch) => {
950
+ var _patch$sheetTransform, _patch$axisAlignSheet;
951
+ if (!patch.drawingId) return;
952
+ const original = originals.get(patch.drawingId);
953
+ if (!original) return;
954
+ plan.updates.set(patch.drawingId, {
955
+ ...original,
956
+ ...patch,
957
+ transform: {
958
+ ...original.transform,
959
+ ...patch.transform
960
+ },
961
+ sheetTransform: (_patch$sheetTransform = patch.sheetTransform) !== null && _patch$sheetTransform !== void 0 ? _patch$sheetTransform : original.sheetTransform,
962
+ axisAlignSheetTransform: (_patch$axisAlignSheet = patch.axisAlignSheetTransform) !== null && _patch$axisAlignSheet !== void 0 ? _patch$axisAlignSheet : original.axisAlignSheetTransform
963
+ });
964
+ });
965
+ const feature = this._transformPlanService.transform(plan);
966
+ if (mode === "refresh") {
967
+ const changed = [...plan.updates.values()].filter((drawing) => JSON.stringify(originals.get(drawing.drawingId)) !== JSON.stringify(drawing));
968
+ if (changed.length) {
969
+ this._sheetDrawingService.refreshTransform(changed);
970
+ this._drawingManagerService.refreshTransform(changed);
971
+ this._commandService.syncExecuteCommand(ClearSheetDrawingTransformerOperation.id, [unitId]);
972
+ }
973
+ return {
974
+ redos: [],
975
+ undos: []
976
+ };
977
+ }
978
+ return this._createPlanMutations(plan, feature);
979
+ }
980
+ _getCalculatedSkeletonParam(unitId, subUnitId) {
981
+ const skeletonParam = this._sheetSkeletonService.getSkeletonParam(unitId, subUnitId);
982
+ if (!skeletonParam) return;
983
+ skeletonParam.skeleton.makeDirty(true);
984
+ skeletonParam.skeleton.calculate();
985
+ return skeletonParam;
986
+ }
987
+ _createPlanMutations(plan, feature) {
988
+ const { unitId, subUnitId } = plan;
989
+ const redos = [...feature.preRedos];
990
+ const undos = [...feature.preUndos];
991
+ const updates = [...plan.updates.values()].filter(({ drawingId }) => !plan.deletes.has(drawingId));
992
+ if (updates.length) {
993
+ const { undo, redo, objects } = this._sheetDrawingService.getBatchUpdateOp(updates);
994
+ redos.push({
995
+ id: SetDrawingApplyMutation.id,
996
+ params: {
997
+ unitId,
998
+ subUnitId,
999
+ op: redo,
1000
+ objects,
1001
+ type: 2
1002
+ }
1003
+ });
1004
+ undos.push({
1005
+ id: SetDrawingApplyMutation.id,
1006
+ params: {
1007
+ unitId,
1008
+ subUnitId,
1009
+ op: undo,
1010
+ objects,
1011
+ type: 2
1012
+ }
1013
+ });
1014
+ }
1015
+ if (plan.deletes.size) {
1016
+ const drawings = [...plan.deletes].map((drawingId) => ({
1017
+ unitId,
1018
+ subUnitId,
1019
+ drawingId
1020
+ }));
1021
+ const { undo, redo, objects } = this._sheetDrawingService.getBatchRemoveOp(drawings);
1022
+ redos.push({
1023
+ id: SetDrawingApplyMutation.id,
1024
+ params: {
1025
+ unitId,
1026
+ subUnitId,
1027
+ op: redo,
1028
+ objects,
1029
+ type: 1
1030
+ }
1031
+ });
1032
+ undos.push({
1033
+ id: SetDrawingApplyMutation.id,
1034
+ params: {
1035
+ unitId,
1036
+ subUnitId,
1037
+ op: undo,
1038
+ objects,
1039
+ type: 0
1040
+ }
1041
+ });
1042
+ }
1043
+ redos.push(...feature.redos);
1044
+ undos.push(...feature.undos);
1045
+ if (redos.length || undos.length) {
1046
+ redos.push({
1047
+ id: ClearSheetDrawingTransformerOperation.id,
1048
+ params: [unitId]
1049
+ });
1050
+ undos.push({
1051
+ id: ClearSheetDrawingTransformerOperation.id,
1052
+ params: [unitId]
1053
+ });
1054
+ }
1055
+ return {
1056
+ redos,
1057
+ undos
1058
+ };
1059
+ }
1060
+ _getRangeMoveUndo(range, type) {
1061
+ const target = getSheetCommandTarget(this._univerInstanceService);
1062
+ if (!target) return {
1063
+ redos: [],
1064
+ undos: []
1065
+ };
1066
+ const { unitId, subUnitId } = target;
1067
+ if (!this._getCalculatedSkeletonParam(unitId, subUnitId)) return {
1068
+ redos: [],
1069
+ undos: []
1070
+ };
1071
+ const drawingData = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
1072
+ const updateDrawings = [];
1073
+ const deleteDrawings = [];
1074
+ Object.keys(drawingData).forEach((drawingId) => {
1075
+ const drawing = drawingData[drawingId];
1076
+ const { updateDrawings: updateDrawingsPart, deleteDrawings: deleteDrawingsPart } = this._getUpdateOrDeleteDrawings(range, type, drawing);
1077
+ updateDrawings.push(...updateDrawingsPart);
1078
+ deleteDrawings.push(...deleteDrawingsPart);
1079
+ });
1080
+ return this._finalizePlan(unitId, subUnitId, updateDrawings, deleteDrawings);
1081
+ }
1082
+ _getUpdateOrDeleteDrawings(range, type, drawing) {
1083
+ const updateDrawings = [];
1084
+ const deleteDrawings = [];
1085
+ const { sheetTransform, anchorType = "0", transform, unitId, subUnitId, drawingId } = drawing;
1086
+ const sheetSkeletonParam = this._sheetSkeletonService.getSkeletonParam(unitId, subUnitId);
1087
+ if (!sheetTransform || !transform || !sheetSkeletonParam) return {
1088
+ updateDrawings,
1089
+ deleteDrawings
1090
+ };
1091
+ const { from, to } = sheetTransform;
1092
+ const { row: fromRow, column: fromColumn } = from;
1093
+ const { row: toRow, column: toColumn } = to;
1094
+ const { startRow, endRow, startColumn, endColumn } = range;
1095
+ let newSheetTransform = null;
1096
+ let newTransform = null;
1097
+ let axisAlignSheetTransform;
1098
+ if (type === 0 && fromRow >= startRow && toRow <= endRow) if (fromColumn >= startColumn && toColumn <= endColumn) deleteDrawings.push({
1099
+ unitId,
1100
+ subUnitId,
1101
+ drawingId
1102
+ });
1103
+ else {
1104
+ var _param$axisAlignSheet;
1105
+ const param = this._shrinkCol(startColumn, endColumn, {
1106
+ sheetSkeletonParam,
1107
+ sheetTransform,
1108
+ transform,
1109
+ anchorType
1110
+ });
1111
+ newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
1112
+ newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
1113
+ axisAlignSheetTransform = (_param$axisAlignSheet = param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) !== null && _param$axisAlignSheet !== void 0 ? _param$axisAlignSheet : void 0;
1114
+ }
1115
+ else if (type === 1 && fromColumn >= startColumn && toColumn <= endColumn) if (fromRow >= startRow && toRow <= endRow) deleteDrawings.push({
1116
+ unitId,
1117
+ subUnitId,
1118
+ drawingId
1119
+ });
1120
+ else {
1121
+ var _param$axisAlignSheet2;
1122
+ const param = this._shrinkRow(startRow, endRow, {
1123
+ sheetSkeletonParam,
1124
+ sheetTransform,
1125
+ transform,
1126
+ anchorType
1127
+ });
1128
+ newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
1129
+ newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
1130
+ axisAlignSheetTransform = (_param$axisAlignSheet2 = param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) !== null && _param$axisAlignSheet2 !== void 0 ? _param$axisAlignSheet2 : void 0;
1131
+ }
1132
+ else if (type === 2) {
1133
+ var _param$axisAlignSheet3;
1134
+ const param = this._expandRow(startRow, endRow, {
1135
+ sheetSkeletonParam,
1136
+ sheetTransform,
1137
+ transform,
1138
+ anchorType
1139
+ });
1140
+ newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
1141
+ newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
1142
+ axisAlignSheetTransform = (_param$axisAlignSheet3 = param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) !== null && _param$axisAlignSheet3 !== void 0 ? _param$axisAlignSheet3 : void 0;
1143
+ } else if (type === 3) {
1144
+ var _param$axisAlignSheet4;
1145
+ const param = this._expandCol(startColumn, endColumn, {
1146
+ sheetSkeletonParam,
1147
+ sheetTransform,
1148
+ transform,
1149
+ anchorType
1150
+ });
1151
+ newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
1152
+ newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
1153
+ axisAlignSheetTransform = (_param$axisAlignSheet4 = param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) !== null && _param$axisAlignSheet4 !== void 0 ? _param$axisAlignSheet4 : void 0;
1154
+ }
1155
+ if (newSheetTransform && newTransform) {
1156
+ const newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
1157
+ updateDrawings.push({
1158
+ ...drawing,
1159
+ sheetTransform: newSheetTransform,
1160
+ transform: newTransform,
1161
+ axisAlignSheetTransform
1162
+ });
1163
+ }
1164
+ return {
1165
+ updateDrawings,
1166
+ deleteDrawings
1167
+ };
1168
+ }
1169
+ _remainDrawingSize(transform, updateDrawings, drawing, skeleton) {
1170
+ const newSheetTransform = transformToDrawingPosition({ ...transform }, skeleton);
1171
+ if (newSheetTransform) {
1172
+ const axisAlignSheetTransform = transformToAxisAlignPosition({ ...transform }, skeleton);
1173
+ updateDrawings.push({
1174
+ ...drawing,
1175
+ sheetTransform: newSheetTransform,
1176
+ axisAlignSheetTransform
1177
+ });
1178
+ }
1179
+ }
1180
+ _getDrawingUndoForColVisible(unitId, subUnitId, ranges) {
1181
+ const sheetSkeletonParam = this._getCalculatedSkeletonParam(unitId, subUnitId);
1182
+ if (!sheetSkeletonParam) return {
1183
+ redos: [],
1184
+ undos: []
1185
+ };
1186
+ const { skeleton } = sheetSkeletonParam;
1187
+ const drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId);
1188
+ const updateDrawings = [];
1189
+ const preUpdateDrawings = [];
1190
+ Object.keys(drawingData).forEach((drawingId) => {
1191
+ const drawing = drawingData[drawingId];
1192
+ const { sheetTransform, transform, anchorType = "0" } = drawing;
1193
+ if (anchorType === "2") this._remainDrawingSize(transform, updateDrawings, drawing, skeleton);
1194
+ else {
1195
+ const { from, to } = sheetTransform;
1196
+ const { row: fromRow, column: fromColumn } = from;
1197
+ const { row: toRow, column: toColumn } = to;
1198
+ for (let i = 0; i < ranges.length; i++) {
1199
+ const { startColumn, endColumn } = ranges[i];
1200
+ if (toColumn < startColumn) continue;
1201
+ if (anchorType === "0") {
1202
+ let newSheetTransform = null;
1203
+ let newTransform = null;
1204
+ if (fromColumn >= startColumn && fromColumn <= endColumn) {
1205
+ const selectionCell = attachRangeWithCoord(skeleton, {
1206
+ startColumn: fromColumn,
1207
+ endColumn,
1208
+ startRow: fromRow,
1209
+ endRow: toRow
1210
+ });
1211
+ newTransform = {
1212
+ ...transform,
1213
+ left: selectionCell.startX
1214
+ };
1215
+ }
1216
+ if (newTransform) {
1217
+ newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
1218
+ const axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
1219
+ if (newSheetTransform && newTransform) {
1220
+ updateDrawings.push({
1221
+ ...drawing,
1222
+ sheetTransform: newSheetTransform,
1223
+ transform: newTransform,
1224
+ axisAlignSheetTransform
1225
+ });
1226
+ break;
1227
+ }
1228
+ }
1229
+ continue;
1230
+ }
1231
+ if (fromColumn >= startColumn && toColumn <= endColumn) continue;
1232
+ let newSheetTransform = null;
1233
+ let newTransform = null;
1234
+ if (fromColumn >= startColumn && fromColumn <= endColumn) {
1235
+ const selectionCell = attachRangeWithCoord(skeleton, {
1236
+ startColumn: fromColumn,
1237
+ endColumn,
1238
+ startRow: fromRow,
1239
+ endRow: toRow
1240
+ });
1241
+ newTransform = {
1242
+ ...transform,
1243
+ left: (selectionCell === null || selectionCell === void 0 ? void 0 : selectionCell.startX) || 0,
1244
+ width: ((transform === null || transform === void 0 ? void 0 : transform.width) || 0) - selectionCell.endX + selectionCell.startX
1245
+ };
1246
+ } else if (toColumn >= startColumn && toColumn <= endColumn) {
1247
+ const selectionCell = attachRangeWithCoord(skeleton, {
1248
+ startColumn,
1249
+ endColumn: toColumn,
1250
+ startRow: fromRow,
1251
+ endRow: toRow
1252
+ });
1253
+ newTransform = {
1254
+ ...transform,
1255
+ left: selectionCell.startX - ((transform === null || transform === void 0 ? void 0 : transform.width) || 0)
1256
+ };
1257
+ } else {
1258
+ const selectionCell = attachRangeWithCoord(skeleton, {
1259
+ startColumn,
1260
+ endColumn,
1261
+ startRow: fromRow,
1262
+ endRow: toRow
1263
+ });
1264
+ newTransform = {
1265
+ ...transform,
1266
+ width: ((transform === null || transform === void 0 ? void 0 : transform.width) || 0) - selectionCell.endX + selectionCell.startX
1267
+ };
1268
+ newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
1269
+ if (newSheetTransform && newTransform) {
1270
+ const axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
1271
+ preUpdateDrawings.push({
1272
+ ...drawing,
1273
+ sheetTransform: newSheetTransform,
1274
+ transform: newTransform,
1275
+ axisAlignSheetTransform
1276
+ });
1277
+ break;
1278
+ }
1279
+ }
1280
+ if (newTransform) newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
1281
+ if (newTransform && newSheetTransform) {
1282
+ const axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
1283
+ updateDrawings.push({
1284
+ ...drawing,
1285
+ sheetTransform: newSheetTransform,
1286
+ transform: newTransform,
1287
+ axisAlignSheetTransform
1288
+ });
1289
+ break;
1290
+ } else this._remainDrawingSize(transform, updateDrawings, drawing, skeleton);
1291
+ }
1292
+ }
1293
+ });
1294
+ return this._finalizePlan(unitId, subUnitId, [...preUpdateDrawings, ...updateDrawings]);
1295
+ }
1296
+ _createUndoAndRedoMutation(unitId, subUnitId, updateDrawings) {
1297
+ return this._finalizePlan(unitId, subUnitId, updateDrawings);
1298
+ }
1299
+ _getDrawingUndoForRowVisible(unitId, subUnitId, ranges) {
1300
+ const sheetSkeletonParam = this._getCalculatedSkeletonParam(unitId, subUnitId);
1301
+ if (!sheetSkeletonParam) return {
1302
+ redos: [],
1303
+ undos: []
1304
+ };
1305
+ const { skeleton } = sheetSkeletonParam;
1306
+ const drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId);
1307
+ const updateDrawings = [];
1308
+ const preUpdateDrawings = [];
1309
+ Object.keys(drawingData).forEach((drawingId) => {
1310
+ const drawing = drawingData[drawingId];
1311
+ const { sheetTransform, transform, anchorType = "0" } = drawing;
1312
+ if (anchorType === "2") this._remainDrawingSize(transform, updateDrawings, drawing, skeleton);
1313
+ else {
1314
+ const { from, to } = sheetTransform;
1315
+ const { row: fromRow, column: fromColumn } = from;
1316
+ const { row: toRow, column: toColumn } = to;
1317
+ for (let i = 0; i < ranges.length; i++) {
1318
+ const { startRow, endRow } = ranges[i];
1319
+ if (toRow < startRow) continue;
1320
+ if (anchorType === "0") {
1321
+ let newSheetTransform = null;
1322
+ let newTransform = null;
1323
+ if (fromRow >= startRow && fromRow <= endRow) {
1324
+ const selectionCell = attachRangeWithCoord(skeleton, {
1325
+ startColumn: fromColumn,
1326
+ endColumn: toColumn,
1327
+ startRow: fromRow,
1328
+ endRow
1329
+ });
1330
+ newTransform = {
1331
+ ...transform,
1332
+ top: selectionCell.startY
1333
+ };
1334
+ }
1335
+ if (newTransform) {
1336
+ newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
1337
+ const axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
1338
+ if (newSheetTransform && newTransform) {
1339
+ updateDrawings.push({
1340
+ ...drawing,
1341
+ sheetTransform: newSheetTransform,
1342
+ transform: newTransform,
1343
+ axisAlignSheetTransform
1344
+ });
1345
+ break;
1346
+ }
1347
+ }
1348
+ continue;
1349
+ }
1350
+ if (fromRow >= startRow && toRow <= endRow) continue;
1351
+ let newSheetTransform = null;
1352
+ let newTransform = null;
1353
+ if (fromRow >= startRow && fromRow <= endRow) {
1354
+ const selectionCell = attachRangeWithCoord(skeleton, {
1355
+ startColumn: fromColumn,
1356
+ endColumn: toColumn,
1357
+ startRow: fromRow,
1358
+ endRow
1359
+ });
1360
+ newTransform = {
1361
+ ...transform,
1362
+ top: (selectionCell === null || selectionCell === void 0 ? void 0 : selectionCell.startY) || 0,
1363
+ height: ((transform === null || transform === void 0 ? void 0 : transform.height) || 0) - selectionCell.endY + selectionCell.startY
1364
+ };
1365
+ } else if (toRow >= startRow && toRow <= endRow) {
1366
+ const selectionCell = attachRangeWithCoord(skeleton, {
1367
+ startColumn: fromColumn,
1368
+ endColumn: toColumn,
1369
+ startRow,
1370
+ endRow: toRow
1371
+ });
1372
+ newTransform = {
1373
+ ...transform,
1374
+ top: selectionCell.startY - ((transform === null || transform === void 0 ? void 0 : transform.height) || 0)
1375
+ };
1376
+ } else {
1377
+ const selectionCell = attachRangeWithCoord(skeleton, {
1378
+ startColumn: fromColumn,
1379
+ endColumn: toColumn,
1380
+ startRow,
1381
+ endRow
1382
+ });
1383
+ newTransform = {
1384
+ ...transform,
1385
+ height: ((transform === null || transform === void 0 ? void 0 : transform.height) || 0) - selectionCell.endY + selectionCell.startY
1386
+ };
1387
+ newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
1388
+ if (newSheetTransform && newTransform) {
1389
+ const axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
1390
+ preUpdateDrawings.push({
1391
+ ...drawing,
1392
+ sheetTransform: newSheetTransform,
1393
+ transform: newTransform,
1394
+ axisAlignSheetTransform
1395
+ });
1396
+ break;
1397
+ }
1398
+ }
1399
+ if (newTransform) newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
1400
+ if (newTransform && newSheetTransform) {
1401
+ const axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
1402
+ updateDrawings.push({
1403
+ ...drawing,
1404
+ sheetTransform: newSheetTransform,
1405
+ transform: newTransform,
1406
+ axisAlignSheetTransform
1407
+ });
1408
+ break;
1409
+ } else this._remainDrawingSize(transform, updateDrawings, drawing, skeleton);
1410
+ }
1411
+ }
1412
+ });
1413
+ return this._finalizePlan(unitId, subUnitId, [...preUpdateDrawings, ...updateDrawings]);
1414
+ }
1415
+ _getDrawingUndoForRowAndColSize(unitId, subUnitId, ranges) {
1416
+ const sheetSkeletonParam = this._getCalculatedSkeletonParam(unitId, subUnitId);
1417
+ if (!sheetSkeletonParam) return {
1418
+ redos: [],
1419
+ undos: []
1420
+ };
1421
+ const { skeleton } = sheetSkeletonParam;
1422
+ const drawingData = this._drawingManagerService.getDrawingData(unitId, subUnitId);
1423
+ const updateDrawings = [];
1424
+ Object.keys(drawingData).forEach((drawingId) => {
1425
+ const drawing = drawingData[drawingId];
1426
+ const { sheetTransform, transform, anchorType = "0" } = drawing;
1427
+ if (anchorType === "2") this._remainDrawingSize(transform, updateDrawings, drawing, skeleton);
1428
+ else {
1429
+ const { from, to } = sheetTransform;
1430
+ const { row: fromRow, column: fromColumn } = from;
1431
+ const { row: toRow, column: toColumn } = to;
1432
+ for (let i = 0; i < ranges.length; i++) {
1433
+ const { startRow, endRow, startColumn, endColumn } = ranges[i];
1434
+ if (toRow < startRow || toColumn < startColumn) continue;
1435
+ if (anchorType === "0") {
1436
+ if (fromRow <= startRow && toRow >= endRow || fromColumn <= startColumn && toColumn >= endColumn) {
1437
+ this._remainDrawingSize(transform, updateDrawings, drawing, skeleton);
1438
+ continue;
1439
+ }
1440
+ }
1441
+ const newTransform = drawingPositionToTransform({ ...sheetTransform }, sheetSkeletonParam);
1442
+ if (newTransform) {
1443
+ updateDrawings.push({
1444
+ ...drawing,
1445
+ transform: newTransform
1446
+ });
1447
+ break;
1448
+ }
1449
+ }
1450
+ }
1451
+ });
1452
+ if (updateDrawings.length === 0) return {
1453
+ redos: [],
1454
+ undos: []
1455
+ };
1456
+ return this._createUndoAndRedoMutation(unitId, subUnitId, updateDrawings);
1457
+ }
1458
+ _getUnitIdAndSubUnitId(params, type) {
1459
+ let target;
1460
+ if (type === "insert") target = getSheetCommandTarget(this._univerInstanceService, params);
1461
+ else target = getSheetCommandTarget(this._univerInstanceService);
1462
+ if (!target) return;
1463
+ const { unitId, subUnitId } = target;
1464
+ return {
1465
+ unitId,
1466
+ subUnitId
1467
+ };
1468
+ }
1469
+ _moveRangeInterceptor(unitId, subUnitId, fromRange, toRange) {
1470
+ const sheetSkeletonParam = this._getCalculatedSkeletonParam(unitId, subUnitId);
1471
+ if (!sheetSkeletonParam) return {
1472
+ redos: [],
1473
+ undos: []
1474
+ };
1475
+ const { skeleton } = sheetSkeletonParam;
1476
+ const selectionRect = attachRangeWithCoord(skeleton, fromRange);
1477
+ if (!selectionRect) return {
1478
+ redos: [],
1479
+ undos: []
1480
+ };
1481
+ const { startX, endX, startY, endY } = selectionRect;
1482
+ const drawings = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
1483
+ const containedDrawings = [];
1484
+ Object.keys(drawings).forEach((drawingId) => {
1485
+ const drawing = drawings[drawingId];
1486
+ if (drawing.anchorType !== "1") return;
1487
+ const { transform } = drawing;
1488
+ if (!transform) return;
1489
+ const { left = 0, top = 0, width = 0, height = 0 } = transform;
1490
+ const { drawingStartX, drawingEndX, drawingStartY, drawingEndY } = {
1491
+ drawingStartX: left,
1492
+ drawingEndX: left + width,
1493
+ drawingStartY: top,
1494
+ drawingEndY: top + height
1495
+ };
1496
+ if (startX <= drawingStartX && drawingEndX <= endX && startY <= drawingStartY && drawingEndY <= endY) containedDrawings.push(drawing);
1497
+ });
1498
+ const rowOffset = toRange.startRow - fromRange.startRow;
1499
+ const colOffset = toRange.startColumn - fromRange.startColumn;
1500
+ const updateDrawings = containedDrawings.map((drawing) => {
1501
+ const oldSheetTransform = drawing.sheetTransform;
1502
+ const sheetTransform = {
1503
+ to: {
1504
+ ...oldSheetTransform.to,
1505
+ row: oldSheetTransform.to.row + rowOffset,
1506
+ column: oldSheetTransform.to.column + colOffset
1507
+ },
1508
+ from: {
1509
+ ...oldSheetTransform.from,
1510
+ row: oldSheetTransform.from.row + rowOffset,
1511
+ column: oldSheetTransform.from.column + colOffset
1512
+ }
1513
+ };
1514
+ const transform = drawingPositionToTransform(sheetTransform, sheetSkeletonParam);
1515
+ return {
1516
+ unitId,
1517
+ subUnitId,
1518
+ drawingId: drawing.drawingId,
1519
+ transform,
1520
+ sheetTransform
1521
+ };
1522
+ });
1523
+ return this._finalizePlan(unitId, subUnitId, updateDrawings);
1524
+ }
1525
+ _moveRowInterceptor(params, type) {
1526
+ const target = this._getUnitIdAndSubUnitId(params, type);
1527
+ if (!target) return {
1528
+ redos: [],
1529
+ undos: []
1530
+ };
1531
+ const { unitId, subUnitId } = target;
1532
+ const sheetSkeletonParam = this._getCalculatedSkeletonParam(unitId, subUnitId);
1533
+ if (!sheetSkeletonParam) return {
1534
+ redos: [],
1535
+ undos: []
1536
+ };
1537
+ const { range } = params;
1538
+ const rowStartIndex = range.startRow;
1539
+ const rowEndIndex = range.endRow;
1540
+ const data = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
1541
+ const updateDrawings = [];
1542
+ const deleteDrawings = [];
1543
+ Object.keys(data).forEach((drawingId) => {
1544
+ const { sheetTransform, transform, anchorType = "0" } = data[drawingId];
1545
+ if (!sheetTransform || !transform) return;
1546
+ let newSheetTransform;
1547
+ let newTransform;
1548
+ let axisAlignSheetTransform;
1549
+ if (type === "insert") {
1550
+ var _param$axisAlignSheet5;
1551
+ const param = this._expandRow(rowStartIndex, rowEndIndex, {
1552
+ sheetSkeletonParam,
1553
+ sheetTransform,
1554
+ transform,
1555
+ anchorType
1556
+ });
1557
+ newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
1558
+ newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
1559
+ axisAlignSheetTransform = (_param$axisAlignSheet5 = param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) !== null && _param$axisAlignSheet5 !== void 0 ? _param$axisAlignSheet5 : void 0;
1560
+ } else {
1561
+ const { from, to } = sheetTransform;
1562
+ const { row: fromRow } = from;
1563
+ const { row: toRow } = to;
1564
+ if (anchorType === "1" && fromRow >= rowStartIndex && toRow <= rowEndIndex) deleteDrawings.push({
1565
+ unitId,
1566
+ subUnitId,
1567
+ drawingId
1568
+ });
1569
+ else {
1570
+ var _param$axisAlignSheet6;
1571
+ const param = this._shrinkRow(rowStartIndex, rowEndIndex, {
1572
+ sheetSkeletonParam,
1573
+ sheetTransform,
1574
+ transform,
1575
+ anchorType
1576
+ });
1577
+ newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
1578
+ newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
1579
+ axisAlignSheetTransform = (_param$axisAlignSheet6 = param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) !== null && _param$axisAlignSheet6 !== void 0 ? _param$axisAlignSheet6 : void 0;
1580
+ }
1581
+ }
1582
+ if (!newSheetTransform || !newTransform) return;
1583
+ const params = {
1584
+ unitId,
1585
+ subUnitId,
1586
+ drawingId,
1587
+ transform: newTransform,
1588
+ sheetTransform: newSheetTransform,
1589
+ axisAlignSheetTransform
1590
+ };
1591
+ updateDrawings.push(params);
1592
+ });
1593
+ return this._finalizePlan(unitId, subUnitId, updateDrawings, deleteDrawings);
1594
+ }
1595
+ _moveColInterceptor(params, type) {
1596
+ const target = this._getUnitIdAndSubUnitId(params, type);
1597
+ if (!target) return {
1598
+ redos: [],
1599
+ undos: []
1600
+ };
1601
+ const { unitId, subUnitId } = target;
1602
+ const sheetSkeletonParam = this._getCalculatedSkeletonParam(unitId, subUnitId);
1603
+ if (!sheetSkeletonParam) return {
1604
+ redos: [],
1605
+ undos: []
1606
+ };
1607
+ const { range } = params;
1608
+ const colStartIndex = range.startColumn;
1609
+ const colEndIndex = range.endColumn;
1610
+ const data = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
1611
+ const updateDrawings = [];
1612
+ const deleteDrawings = [];
1613
+ Object.keys(data).forEach((drawingId) => {
1614
+ const { sheetTransform, transform, anchorType = "0" } = data[drawingId];
1615
+ if (!sheetTransform || !transform) return;
1616
+ let newSheetTransform;
1617
+ let newTransform;
1618
+ let axisAlignSheetTransform;
1619
+ if (type === "insert") {
1620
+ var _param$axisAlignSheet7;
1621
+ const param = this._expandCol(colStartIndex, colEndIndex, {
1622
+ sheetSkeletonParam,
1623
+ sheetTransform,
1624
+ transform,
1625
+ anchorType
1626
+ });
1627
+ newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
1628
+ newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
1629
+ axisAlignSheetTransform = (_param$axisAlignSheet7 = param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) !== null && _param$axisAlignSheet7 !== void 0 ? _param$axisAlignSheet7 : void 0;
1630
+ } else {
1631
+ const { from, to } = sheetTransform;
1632
+ const { column: fromColumn } = from;
1633
+ const { column: toColumn } = to;
1634
+ if (anchorType === "1" && fromColumn >= colStartIndex && toColumn <= colEndIndex) deleteDrawings.push({
1635
+ unitId,
1636
+ subUnitId,
1637
+ drawingId
1638
+ });
1639
+ else {
1640
+ var _param$axisAlignSheet8;
1641
+ const param = this._shrinkCol(colStartIndex, colEndIndex, {
1642
+ sheetSkeletonParam,
1643
+ sheetTransform,
1644
+ transform,
1645
+ anchorType
1646
+ });
1647
+ newSheetTransform = param === null || param === void 0 ? void 0 : param.newSheetTransform;
1648
+ newTransform = param === null || param === void 0 ? void 0 : param.newTransform;
1649
+ axisAlignSheetTransform = (_param$axisAlignSheet8 = param === null || param === void 0 ? void 0 : param.axisAlignSheetTransform) !== null && _param$axisAlignSheet8 !== void 0 ? _param$axisAlignSheet8 : void 0;
1650
+ }
1651
+ }
1652
+ if (!newSheetTransform || !newTransform) return;
1653
+ const params = {
1654
+ unitId,
1655
+ subUnitId,
1656
+ drawingId,
1657
+ transform: newTransform,
1658
+ sheetTransform: newSheetTransform,
1659
+ axisAlignSheetTransform
1660
+ };
1661
+ updateDrawings.push(params);
1662
+ });
1663
+ return this._finalizePlan(unitId, subUnitId, updateDrawings, deleteDrawings);
1664
+ }
1665
+ _expandCol(colStartIndex, colEndIndex, options) {
1666
+ const { sheetSkeletonParam, sheetTransform, transform, anchorType = "0" } = options;
1667
+ const { skeleton } = sheetSkeletonParam;
1668
+ const colCount = colEndIndex - colStartIndex + 1;
1669
+ const { from, to } = sheetTransform;
1670
+ const { column: fromColumn } = from;
1671
+ const { column: toColumn } = to;
1672
+ if (anchorType === "2") return {
1673
+ newSheetTransform: transformToDrawingPosition({ ...transform }, skeleton),
1674
+ newTransform: transform,
1675
+ axisAlignSheetTransform: transformToAxisAlignPosition({ ...transform }, skeleton)
1676
+ };
1677
+ let newSheetTransform = null;
1678
+ let newTransform = null;
1679
+ let axisAlignSheetTransform = null;
1680
+ if (fromColumn >= colStartIndex) {
1681
+ const selectionCell = attachRangeWithCoord(skeleton, {
1682
+ startColumn: colStartIndex,
1683
+ endColumn: colEndIndex,
1684
+ startRow: from.row,
1685
+ endRow: to.row
1686
+ });
1687
+ newTransform = {
1688
+ ...transform,
1689
+ left: (transform.left || 0) + selectionCell.endX - selectionCell.startX
1690
+ };
1691
+ newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
1692
+ axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
1693
+ } else if (toColumn >= colEndIndex) if (anchorType === "1") {
1694
+ newSheetTransform = {
1695
+ from: { ...from },
1696
+ to: {
1697
+ ...to,
1698
+ column: toColumn + colCount
1699
+ }
1700
+ };
1701
+ newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
1702
+ } else return {
1703
+ newSheetTransform: transformToDrawingPosition({ ...transform }, skeleton),
1704
+ newTransform: transform,
1705
+ axisAlignSheetTransform: transformToAxisAlignPosition({ ...transform }, skeleton)
1706
+ };
1707
+ if (newSheetTransform && newTransform) return {
1708
+ newSheetTransform,
1709
+ newTransform,
1710
+ axisAlignSheetTransform
1711
+ };
1712
+ return null;
1713
+ }
1714
+ _shrinkCol(colStartIndex, colEndIndex, options) {
1715
+ const { sheetSkeletonParam, sheetTransform, transform, anchorType = "0" } = options;
1716
+ const { skeleton } = sheetSkeletonParam;
1717
+ const colCount = colEndIndex - colStartIndex + 1;
1718
+ const { from, to } = sheetTransform;
1719
+ const { column: fromColumn } = from;
1720
+ const { column: toColumn } = to;
1721
+ if (anchorType === "2") return {
1722
+ newSheetTransform: transformToDrawingPosition({ ...transform }, skeleton),
1723
+ newTransform: transform,
1724
+ axisAlignSheetTransform: transformToAxisAlignPosition({ ...transform }, skeleton)
1725
+ };
1726
+ let newSheetTransform = null;
1727
+ let newTransform = null;
1728
+ let axisAlignSheetTransform = null;
1729
+ if (fromColumn > colEndIndex) {
1730
+ newSheetTransform = {
1731
+ from: {
1732
+ ...from,
1733
+ column: fromColumn - colCount
1734
+ },
1735
+ to: {
1736
+ ...to,
1737
+ column: toColumn - colCount
1738
+ }
1739
+ };
1740
+ newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
1741
+ } else if (fromColumn >= colStartIndex && toColumn <= colEndIndex) return null;
1742
+ else if (fromColumn < colStartIndex && toColumn > colEndIndex) if (anchorType === "1") {
1743
+ newSheetTransform = {
1744
+ from: { ...from },
1745
+ to: {
1746
+ ...to,
1747
+ column: toColumn - colCount
1748
+ }
1749
+ };
1750
+ newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
1751
+ } else return {
1752
+ newSheetTransform: transformToDrawingPosition({ ...transform }, skeleton),
1753
+ newTransform: transform,
1754
+ axisAlignSheetTransform: transformToAxisAlignPosition({ ...transform }, skeleton)
1755
+ };
1756
+ else if (fromColumn >= colStartIndex && fromColumn <= colEndIndex) {
1757
+ if (anchorType === "1") {
1758
+ newSheetTransform = {
1759
+ from: {
1760
+ ...from,
1761
+ column: colStartIndex,
1762
+ columnOffset: 0
1763
+ },
1764
+ to: {
1765
+ ...to,
1766
+ column: toColumn - colCount
1767
+ }
1768
+ };
1769
+ newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
1770
+ axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
1771
+ } else if (fromColumn === colStartIndex) newTransform = {
1772
+ ...transform,
1773
+ left: (transform.left || 0) - sheetTransform.from.columnOffset
1774
+ };
1775
+ else {
1776
+ const selectionCell = attachRangeWithCoord(skeleton, {
1777
+ startColumn: colStartIndex,
1778
+ endColumn: fromColumn - 1,
1779
+ startRow: from.row,
1780
+ endRow: to.row
1781
+ });
1782
+ newTransform = {
1783
+ ...transform,
1784
+ left: (transform.left || 0) - selectionCell.endX + selectionCell.startX - sheetTransform.from.columnOffset
1785
+ };
1786
+ }
1787
+ if (!newSheetTransform) {
1788
+ newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
1789
+ axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
1790
+ }
1791
+ } else if (toColumn >= colStartIndex && toColumn <= colEndIndex && anchorType === "1") {
1792
+ const selectionCell = attachRangeWithCoord(skeleton, {
1793
+ startColumn: colStartIndex - 1,
1794
+ endColumn: colStartIndex - 1,
1795
+ startRow: from.row,
1796
+ endRow: to.row
1797
+ });
1798
+ newSheetTransform = {
1799
+ from: { ...from },
1800
+ to: {
1801
+ ...to,
1802
+ column: colStartIndex - 1,
1803
+ columnOffset: selectionCell.endX - selectionCell.startX
1804
+ }
1805
+ };
1806
+ newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
1807
+ }
1808
+ if (newSheetTransform && newTransform) return {
1809
+ newSheetTransform,
1810
+ newTransform,
1811
+ axisAlignSheetTransform
1812
+ };
1813
+ return null;
1814
+ }
1815
+ _expandRow(rowStartIndex, rowEndIndex, options) {
1816
+ const { sheetSkeletonParam, sheetTransform, transform, anchorType = "0" } = options;
1817
+ const { skeleton } = sheetSkeletonParam;
1818
+ const rowCount = rowEndIndex - rowStartIndex + 1;
1819
+ const { from, to } = sheetTransform;
1820
+ const { row: fromRow } = from;
1821
+ const { row: toRow } = to;
1822
+ if (anchorType === "2") return {
1823
+ newSheetTransform: transformToDrawingPosition({ ...transform }, skeleton),
1824
+ newTransform: transform,
1825
+ axisAlignSheetTransform: transformToAxisAlignPosition({ ...transform }, skeleton)
1826
+ };
1827
+ let newSheetTransform = null;
1828
+ let newTransform = null;
1829
+ let axisAlignSheetTransform = null;
1830
+ if (fromRow >= rowStartIndex) {
1831
+ const selectionCell = attachRangeWithCoord(skeleton, {
1832
+ startRow: rowStartIndex,
1833
+ endRow: rowEndIndex,
1834
+ startColumn: from.column,
1835
+ endColumn: to.column
1836
+ });
1837
+ newTransform = {
1838
+ ...transform,
1839
+ top: (transform.top || 0) + selectionCell.endY - selectionCell.startY
1840
+ };
1841
+ newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
1842
+ axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
1843
+ } else if (toRow >= rowEndIndex) if (anchorType === "1") {
1844
+ newSheetTransform = {
1845
+ from: { ...from },
1846
+ to: {
1847
+ ...to,
1848
+ row: toRow + rowCount
1849
+ }
1850
+ };
1851
+ newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
1852
+ } else return {
1853
+ newSheetTransform: transformToDrawingPosition({ ...transform }, skeleton),
1854
+ newTransform: transform,
1855
+ axisAlignSheetTransform: transformToAxisAlignPosition({ ...transform }, skeleton)
1856
+ };
1857
+ if (newSheetTransform && newTransform) return {
1858
+ newSheetTransform,
1859
+ newTransform,
1860
+ axisAlignSheetTransform
1861
+ };
1862
+ return null;
1863
+ }
1864
+ _shrinkRow(rowStartIndex, rowEndIndex, options) {
1865
+ const { sheetSkeletonParam, sheetTransform, transform, anchorType = "0" } = options;
1866
+ const { skeleton } = sheetSkeletonParam;
1867
+ const rowCount = rowEndIndex - rowStartIndex + 1;
1868
+ const { from, to } = sheetTransform;
1869
+ const { row: fromRow } = from;
1870
+ const { row: toRow } = to;
1871
+ if (anchorType === "2") return {
1872
+ newSheetTransform: transformToDrawingPosition({ ...transform }, skeleton),
1873
+ newTransform: transform,
1874
+ axisAlignSheetTransform: transformToAxisAlignPosition({ ...transform }, skeleton)
1875
+ };
1876
+ let newSheetTransform = null;
1877
+ let newTransform = null;
1878
+ let axisAlignSheetTransform = null;
1879
+ if (fromRow > rowEndIndex) {
1880
+ newSheetTransform = {
1881
+ from: {
1882
+ ...from,
1883
+ row: fromRow - rowCount
1884
+ },
1885
+ to: {
1886
+ ...to,
1887
+ row: toRow - rowCount
1888
+ }
1889
+ };
1890
+ newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
1891
+ } else if (fromRow >= rowStartIndex && toRow <= rowEndIndex) return null;
1892
+ else if (fromRow < rowStartIndex && toRow > rowEndIndex) if (anchorType === "1") {
1893
+ newSheetTransform = {
1894
+ from: { ...from },
1895
+ to: {
1896
+ ...to,
1897
+ row: toRow - rowCount
1898
+ }
1899
+ };
1900
+ newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
1901
+ } else return {
1902
+ newSheetTransform: transformToDrawingPosition({ ...transform }, skeleton),
1903
+ newTransform: transform,
1904
+ axisAlignSheetTransform: transformToAxisAlignPosition({ ...transform }, skeleton)
1905
+ };
1906
+ else if (fromRow >= rowStartIndex && fromRow <= rowEndIndex) {
1907
+ if (anchorType === "1") {
1908
+ newSheetTransform = {
1909
+ from: {
1910
+ ...from,
1911
+ row: rowStartIndex,
1912
+ rowOffset: 0
1913
+ },
1914
+ to: {
1915
+ ...to,
1916
+ row: toRow - rowCount
1917
+ }
1918
+ };
1919
+ newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
1920
+ axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
1921
+ } else if (fromRow === rowStartIndex) newTransform = {
1922
+ ...transform,
1923
+ top: (transform.top || 0) - sheetTransform.from.rowOffset
1924
+ };
1925
+ else {
1926
+ const selectionCell = attachRangeWithCoord(skeleton, {
1927
+ startRow: rowStartIndex,
1928
+ endRow: fromRow - 1,
1929
+ startColumn: from.column,
1930
+ endColumn: to.column
1931
+ });
1932
+ newTransform = {
1933
+ ...transform,
1934
+ top: (transform.top || 0) - selectionCell.endY + selectionCell.startY - sheetTransform.from.rowOffset
1935
+ };
1936
+ }
1937
+ if (!newSheetTransform) {
1938
+ newSheetTransform = transformToDrawingPosition(newTransform, skeleton);
1939
+ axisAlignSheetTransform = transformToAxisAlignPosition(newTransform, skeleton);
1940
+ }
1941
+ } else if (toRow >= rowStartIndex && toRow <= rowEndIndex && anchorType === "1") {
1942
+ const selectionCell = attachRangeWithCoord(skeleton, {
1943
+ startColumn: from.column,
1944
+ endColumn: from.column,
1945
+ startRow: rowStartIndex - 1,
1946
+ endRow: rowStartIndex - 1
1947
+ });
1948
+ newSheetTransform = {
1949
+ from: { ...from },
1950
+ to: {
1951
+ ...to,
1952
+ row: rowStartIndex - 1,
1953
+ rowOffset: selectionCell.endY - selectionCell.startY
1954
+ }
1955
+ };
1956
+ newTransform = drawingPositionToTransform(newSheetTransform, sheetSkeletonParam);
1957
+ }
1958
+ if (newSheetTransform && newTransform) return {
1959
+ newSheetTransform,
1960
+ newTransform,
1961
+ axisAlignSheetTransform
1962
+ };
1963
+ return null;
1964
+ }
1965
+ _sheetRefreshListener() {
1966
+ this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
1967
+ if (!REFRESH_MUTATIONS.includes(command.id)) return;
1968
+ queueMicrotask(() => {
1969
+ const params = command.params;
1970
+ const target = getSheetCommandTarget(this._univerInstanceService, params);
1971
+ if (!target) return;
1972
+ const { unitId, subUnitId, worksheet } = target;
1973
+ let ranges = [];
1974
+ if ("ranges" in params) ranges = params.ranges;
1975
+ else if ("rowsAutoHeightInfo" in params) ranges = params.rowsAutoHeightInfo.map((info) => ({
1976
+ startRow: info.row,
1977
+ endRow: info.row,
1978
+ startColumn: 0,
1979
+ endColumn: worksheet.getColumnCount() - 1
1980
+ }));
1981
+ this._refreshDrawingTransform(command, unitId, subUnitId, ranges);
1982
+ });
1983
+ }));
1984
+ }
1985
+ _refreshDrawingTransform(command, unitId, subUnitId, ranges) {
1986
+ var _this$_drawingManager;
1987
+ const sheetSkeletonParam = this._getCalculatedSkeletonParam(unitId, subUnitId);
1988
+ const drawingData = (_this$_drawingManager = this._drawingManagerService.getDrawingData(unitId, subUnitId)) !== null && _this$_drawingManager !== void 0 ? _this$_drawingManager : {};
1989
+ const updateDrawings = [];
1990
+ Object.keys(drawingData).forEach((drawingId) => {
1991
+ const drawing = drawingData[drawingId];
1992
+ const { sheetTransform, transform, anchorType = "0" } = drawing;
1993
+ if (anchorType === "2") return true;
1994
+ if (!sheetTransform) return true;
1995
+ const { from, to } = sheetTransform;
1996
+ const { row: fromRow, column: fromColumn } = from;
1997
+ const { row: toRow, column: toColumn } = to;
1998
+ for (let i = 0; i < ranges.length; i++) {
1999
+ const { startRow, endRow, startColumn, endColumn } = ranges[i];
2000
+ if (Rectangle.intersects({
2001
+ startRow,
2002
+ endRow,
2003
+ startColumn,
2004
+ endColumn
2005
+ }, {
2006
+ startRow: fromRow,
2007
+ endRow: toRow,
2008
+ startColumn: fromColumn,
2009
+ endColumn: toColumn
2010
+ }) || fromRow > endRow || fromColumn > endColumn) {
2011
+ const isPositionAnchor = anchorType === "0";
2012
+ const newTransform = drawingPositionToTransform(sheetTransform, sheetSkeletonParam);
2013
+ updateDrawings.push({
2014
+ ...drawing,
2015
+ transform: {
2016
+ ...transform,
2017
+ left: newTransform === null || newTransform === void 0 ? void 0 : newTransform.left,
2018
+ top: newTransform === null || newTransform === void 0 ? void 0 : newTransform.top,
2019
+ width: isPositionAnchor ? transform === null || transform === void 0 ? void 0 : transform.width : newTransform === null || newTransform === void 0 ? void 0 : newTransform.width,
2020
+ height: isPositionAnchor ? transform === null || transform === void 0 ? void 0 : transform.height : newTransform === null || newTransform === void 0 ? void 0 : newTransform.height
2021
+ }
2022
+ });
2023
+ break;
2024
+ }
2025
+ }
2026
+ });
2027
+ this._finalizePlan(unitId, subUnitId, updateDrawings, [], "refresh", command);
2028
+ }
2029
+ };
2030
+ SheetDrawingTransformAffectedController = __decorate([
2031
+ __decorateParam(0, ICommandService),
2032
+ __decorateParam(1, Inject(SheetSkeletonService)),
2033
+ __decorateParam(2, Inject(SheetInterceptorService)),
2034
+ __decorateParam(3, Inject(SheetsSelectionsService)),
2035
+ __decorateParam(4, ISheetDrawingService),
2036
+ __decorateParam(5, IDrawingManagerService),
2037
+ __decorateParam(6, IUniverInstanceService),
2038
+ __decorateParam(7, Inject(SheetDrawingTransformPlanService))
2039
+ ], SheetDrawingTransformAffectedController);
2040
+
720
2041
  //#endregion
721
2042
  //#region src/plugin.ts
722
2043
  let UniverSheetsDrawingPlugin = class UniverSheetsDrawingPlugin extends Plugin {
@@ -729,8 +2050,14 @@ let UniverSheetsDrawingPlugin = class UniverSheetsDrawingPlugin extends Plugin {
729
2050
  this._configService.setConfig(SHEETS_DRAWING_PLUGIN_CONFIG_KEY, rest);
730
2051
  }
731
2052
  onStarting() {
732
- [[SheetsDrawingLoadController], [ISheetDrawingService, { useClass: SheetDrawingService }]].forEach((dependency) => this._injector.add(dependency));
2053
+ [
2054
+ [SheetsDrawingLoadController],
2055
+ [SheetDrawingTransformPlanService],
2056
+ [SheetDrawingTransformAffectedController],
2057
+ [ISheetDrawingService, { useClass: SheetDrawingService }]
2058
+ ].forEach((dependency) => this._injector.add(dependency));
733
2059
  this._injector.get(SheetsDrawingLoadController);
2060
+ this._injector.get(SheetDrawingTransformAffectedController);
734
2061
  }
735
2062
  };
736
2063
  _defineProperty(UniverSheetsDrawingPlugin, "pluginName", SHEET_DRAWING_PLUGIN);
@@ -744,4 +2071,4 @@ UniverSheetsDrawingPlugin = __decorate([
744
2071
  ], UniverSheetsDrawingPlugin);
745
2072
 
746
2073
  //#endregion
747
- export { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SHEET_DRAWING_PLUGIN, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SheetDrawingAnchorType, SheetDrawingService, UniverSheetsDrawingPlugin, drawingPositionToTransform, isKnownSheetNonRotatableDrawingType, resolveSheetDrawingRotateEnabled, transformToAxisAlignPosition, transformToDrawingPosition };
2074
+ export { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SHEET_DRAWING_PLUGIN, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SheetDrawingAnchorType, SheetDrawingService, SheetDrawingTransformPlanService, UniverSheetsDrawingPlugin, drawingPositionToTransform, isKnownSheetNonRotatableDrawingType, resolveSheetDrawingRotateEnabled, transformToAxisAlignPosition, transformToDrawingPosition };