@univerjs/sheets-drawing-ui 1.0.0-alpha.8 → 1.0.0-beta.1

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.
Files changed (89) hide show
  1. package/lib/cjs/facade.js +6 -10
  2. package/lib/cjs/index.js +202 -169
  3. package/lib/cjs/locale/ar-SA.js +1 -3
  4. package/lib/cjs/locale/ca-ES.js +1 -3
  5. package/lib/cjs/locale/de-DE.js +1 -3
  6. package/lib/cjs/locale/en-US.js +1 -3
  7. package/lib/cjs/locale/es-ES.js +1 -3
  8. package/lib/cjs/locale/fa-IR.js +1 -3
  9. package/lib/cjs/locale/fr-FR.js +1 -3
  10. package/lib/cjs/locale/id-ID.js +1 -3
  11. package/lib/cjs/locale/it-IT.js +1 -3
  12. package/lib/cjs/locale/ja-JP.js +1 -3
  13. package/lib/cjs/locale/ko-KR.js +1 -3
  14. package/lib/cjs/locale/pl-PL.js +1 -3
  15. package/lib/cjs/locale/pt-BR.js +1 -3
  16. package/lib/cjs/locale/ru-RU.js +1 -3
  17. package/lib/cjs/locale/sk-SK.js +1 -3
  18. package/lib/cjs/locale/vi-VN.js +1 -3
  19. package/lib/cjs/locale/zh-CN.js +1 -3
  20. package/lib/cjs/locale/zh-HK.js +1 -3
  21. package/lib/cjs/locale/zh-TW.js +1 -3
  22. package/lib/es/facade.js +6 -10
  23. package/lib/es/index.js +205 -172
  24. package/lib/es/locale/ar-SA.js +1 -3
  25. package/lib/es/locale/ca-ES.js +1 -3
  26. package/lib/es/locale/de-DE.js +1 -3
  27. package/lib/es/locale/en-US.js +1 -3
  28. package/lib/es/locale/es-ES.js +1 -3
  29. package/lib/es/locale/fa-IR.js +1 -3
  30. package/lib/es/locale/fr-FR.js +1 -3
  31. package/lib/es/locale/id-ID.js +1 -3
  32. package/lib/es/locale/it-IT.js +1 -3
  33. package/lib/es/locale/ja-JP.js +1 -3
  34. package/lib/es/locale/ko-KR.js +1 -3
  35. package/lib/es/locale/pl-PL.js +1 -3
  36. package/lib/es/locale/pt-BR.js +1 -3
  37. package/lib/es/locale/ru-RU.js +1 -3
  38. package/lib/es/locale/sk-SK.js +1 -3
  39. package/lib/es/locale/vi-VN.js +1 -3
  40. package/lib/es/locale/zh-CN.js +1 -3
  41. package/lib/es/locale/zh-HK.js +1 -3
  42. package/lib/es/locale/zh-TW.js +1 -3
  43. package/lib/facade.js +6 -10
  44. package/lib/index.js +205 -172
  45. package/lib/locale/ar-SA.js +1 -3
  46. package/lib/locale/ca-ES.js +1 -3
  47. package/lib/locale/de-DE.js +1 -3
  48. package/lib/locale/en-US.js +1 -3
  49. package/lib/locale/es-ES.js +1 -3
  50. package/lib/locale/fa-IR.js +1 -3
  51. package/lib/locale/fr-FR.js +1 -3
  52. package/lib/locale/id-ID.js +1 -3
  53. package/lib/locale/it-IT.js +1 -3
  54. package/lib/locale/ja-JP.js +1 -3
  55. package/lib/locale/ko-KR.js +1 -3
  56. package/lib/locale/pl-PL.js +1 -3
  57. package/lib/locale/pt-BR.js +1 -3
  58. package/lib/locale/ru-RU.js +1 -3
  59. package/lib/locale/sk-SK.js +1 -3
  60. package/lib/locale/vi-VN.js +1 -3
  61. package/lib/locale/zh-CN.js +1 -3
  62. package/lib/locale/zh-HK.js +1 -3
  63. package/lib/locale/zh-TW.js +1 -3
  64. package/lib/types/controllers/render-controllers/sheet-celll-image-hover.render-controller.d.ts +3 -1
  65. package/lib/types/controllers/ui.controller.d.ts +6 -2
  66. package/lib/types/locale/en-US.d.ts +0 -2
  67. package/lib/types/services/canvas-float-dom-manager.service.d.ts +1 -0
  68. package/lib/umd/facade.js +1 -1
  69. package/lib/umd/index.js +2 -2
  70. package/lib/umd/locale/ar-SA.js +1 -1
  71. package/lib/umd/locale/ca-ES.js +1 -1
  72. package/lib/umd/locale/de-DE.js +1 -1
  73. package/lib/umd/locale/en-US.js +1 -1
  74. package/lib/umd/locale/es-ES.js +1 -1
  75. package/lib/umd/locale/fa-IR.js +1 -1
  76. package/lib/umd/locale/fr-FR.js +1 -1
  77. package/lib/umd/locale/id-ID.js +1 -1
  78. package/lib/umd/locale/it-IT.js +1 -1
  79. package/lib/umd/locale/ja-JP.js +1 -1
  80. package/lib/umd/locale/ko-KR.js +1 -1
  81. package/lib/umd/locale/pl-PL.js +1 -1
  82. package/lib/umd/locale/pt-BR.js +1 -1
  83. package/lib/umd/locale/ru-RU.js +1 -1
  84. package/lib/umd/locale/sk-SK.js +1 -1
  85. package/lib/umd/locale/vi-VN.js +1 -1
  86. package/lib/umd/locale/zh-CN.js +1 -1
  87. package/lib/umd/locale/zh-HK.js +1 -1
  88. package/lib/umd/locale/zh-TW.js +1 -1
  89. package/package.json +15 -15
package/lib/cjs/index.js CHANGED
@@ -125,28 +125,23 @@ function cloneGroupParams(groupParams) {
125
125
  groupParams.groups.forEach((p) => idMap.set(p.drawingId, (0, _univerjs_core.generateRandomId)(10)));
126
126
  const clonedNestedIdRecord = {};
127
127
  for (const [oldGroupId, entry] of Object.entries(groupParams.nestedIdRecord)) {
128
- var _idMap$get, _entry$children;
129
- const newGroupId = (_idMap$get = idMap.get(oldGroupId)) !== null && _idMap$get !== void 0 ? _idMap$get : oldGroupId;
128
+ var _entry$children;
129
+ const newGroupId = idMap.get(oldGroupId) ?? oldGroupId;
130
130
  clonedNestedIdRecord[newGroupId] = {
131
131
  drawingId: newGroupId,
132
- children: (_entry$children = entry.children) === null || _entry$children === void 0 ? void 0 : _entry$children.map((id) => {
133
- var _idMap$get2;
134
- return (_idMap$get2 = idMap.get(id)) !== null && _idMap$get2 !== void 0 ? _idMap$get2 : id;
135
- })
132
+ children: (_entry$children = entry.children) === null || _entry$children === void 0 ? void 0 : _entry$children.map((id) => idMap.get(id) ?? id)
136
133
  };
137
134
  }
138
135
  const flatChildren = [];
139
136
  const groups = [];
140
137
  for (const group of groupParams.groups) {
141
- var _idMap$get3, _idMap$get4;
142
- const groupDrawingId = (_idMap$get3 = idMap.get(group.drawingId)) !== null && _idMap$get3 !== void 0 ? _idMap$get3 : group.drawingId;
143
- const parentGroupId = group.groupId ? (_idMap$get4 = idMap.get(group.groupId)) !== null && _idMap$get4 !== void 0 ? _idMap$get4 : group.groupId : void 0;
138
+ const groupDrawingId = idMap.get(group.drawingId) ?? group.drawingId;
139
+ const parentGroupId = group.groupId ? idMap.get(group.groupId) ?? group.groupId : void 0;
144
140
  groups.push(cloneDrawingParam(group, groupDrawingId, parentGroupId));
145
141
  }
146
142
  for (const child of groupParams.flatChildren || []) {
147
- var _idMap$get5, _idMap$get6;
148
- const childDrawingId = (_idMap$get5 = idMap.get(child.drawingId)) !== null && _idMap$get5 !== void 0 ? _idMap$get5 : child.drawingId;
149
- const parentGroupId = child.groupId ? (_idMap$get6 = idMap.get(child.groupId)) !== null && _idMap$get6 !== void 0 ? _idMap$get6 : child.groupId : void 0;
143
+ const childDrawingId = idMap.get(child.drawingId) ?? child.drawingId;
144
+ const parentGroupId = child.groupId ? idMap.get(child.groupId) ?? child.groupId : void 0;
150
145
  flatChildren.push(cloneDrawingParam(child, childDrawingId, parentGroupId));
151
146
  }
152
147
  return {
@@ -449,7 +444,6 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
449
444
  return this._insertCellImage(file, location);
450
445
  }
451
446
  async insertFloatImageByFile(file) {
452
- var _transformToAxisAlign;
453
447
  let imageParam;
454
448
  try {
455
449
  imageParam = await this._imageIoService.saveImage(file);
@@ -496,7 +490,7 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
496
490
  source,
497
491
  transform: newTransform,
498
492
  sheetTransform,
499
- axisAlignSheetTransform: (_transformToAxisAlign = (0, _univerjs_sheets_drawing.transformToAxisAlignPosition)(newTransform, skeleton)) !== null && _transformToAxisAlign !== void 0 ? _transformToAxisAlign : sheetTransform
493
+ axisAlignSheetTransform: (0, _univerjs_sheets_drawing.transformToAxisAlignPosition)(newTransform, skeleton) ?? sheetTransform
500
494
  };
501
495
  return this._commandService.executeCommand(_univerjs_sheets_drawing.InsertSheetDrawingCommand.id, {
502
496
  unitId,
@@ -572,10 +566,9 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
572
566
  }
573
567
  });
574
568
  if (jsonXActions) {
575
- var _location$row, _location$col;
576
569
  docDataModel.apply(jsonXActions);
577
570
  return this._commandService.syncExecuteCommand(_univerjs_sheets.SetRangeValuesCommand.id, {
578
- value: { [(_location$row = location === null || location === void 0 ? void 0 : location.row) !== null && _location$row !== void 0 ? _location$row : row]: { [(_location$col = location === null || location === void 0 ? void 0 : location.col) !== null && _location$col !== void 0 ? _location$col : col]: {
571
+ value: { [(location === null || location === void 0 ? void 0 : location.row) ?? row]: { [(location === null || location === void 0 ? void 0 : location.col) ?? col]: {
579
572
  p: docDataModel.getSnapshot(),
580
573
  t: 1
581
574
  } } },
@@ -634,10 +627,9 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
634
627
  }
635
628
  });
636
629
  if (jsonXActions) {
637
- var _location$row2, _location$col2;
638
630
  docDataModel.apply(jsonXActions);
639
631
  return this._commandService.syncExecuteCommand(_univerjs_sheets.SetRangeValuesCommand.id, {
640
- value: { [(_location$row2 = location === null || location === void 0 ? void 0 : location.row) !== null && _location$row2 !== void 0 ? _location$row2 : selection.primary.actualRow]: { [(_location$col2 = location === null || location === void 0 ? void 0 : location.col) !== null && _location$col2 !== void 0 ? _location$col2 : selection.primary.actualColumn]: {
632
+ value: { [(location === null || location === void 0 ? void 0 : location.row) ?? selection.primary.actualRow]: { [(location === null || location === void 0 ? void 0 : location.col) ?? selection.primary.actualColumn]: {
641
633
  p: docDataModel.getSnapshot(),
642
634
  t: 1
643
635
  } } },
@@ -889,20 +881,17 @@ const InsertFloatImageCommand = {
889
881
  if (files) {
890
882
  const awaitFiles = files.map((file) => sheetDrawingUpdateController.insertFloatImageByFile(file));
891
883
  return (await Promise.all(awaitFiles)).every((result) => result);
892
- } else {
893
- var _sheetDrawingUpdateCo;
894
- return (_sheetDrawingUpdateCo = sheetDrawingUpdateController.insertFloatImage()) !== null && _sheetDrawingUpdateCo !== void 0 ? _sheetDrawingUpdateCo : false;
895
- }
884
+ } else return sheetDrawingUpdateController.insertFloatImage() ?? false;
896
885
  }
897
886
  };
898
887
  const InsertCellImageCommand = {
899
888
  id: "sheet.command.insert-cell-image",
900
889
  type: _univerjs_core.CommandType.COMMAND,
901
890
  handler: (accessor) => {
902
- var _getCurrentTypeOfRend2, _getCurrentTypeOfRend3;
891
+ var _getCurrentTypeOfRend2;
903
892
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
904
893
  const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
905
- return (_getCurrentTypeOfRend2 = (_getCurrentTypeOfRend3 = (0, _univerjs_engine_render.getCurrentTypeOfRenderer)(_univerjs_core.UniverInstanceType.UNIVER_SHEET, univerInstanceService, renderManagerService)) === null || _getCurrentTypeOfRend3 === void 0 ? void 0 : _getCurrentTypeOfRend3.with(SheetDrawingUpdateController).insertCellImage()) !== null && _getCurrentTypeOfRend2 !== void 0 ? _getCurrentTypeOfRend2 : false;
894
+ return ((_getCurrentTypeOfRend2 = (0, _univerjs_engine_render.getCurrentTypeOfRenderer)(_univerjs_core.UniverInstanceType.UNIVER_SHEET, univerInstanceService, renderManagerService)) === null || _getCurrentTypeOfRend2 === void 0 ? void 0 : _getCurrentTypeOfRend2.with(SheetDrawingUpdateController).insertCellImage()) ?? false;
906
895
  }
907
896
  };
908
897
 
@@ -915,6 +904,7 @@ const MoveDrawingsCommand = {
915
904
  const commandService = accessor.get(_univerjs_core.ICommandService);
916
905
  const drawingManagerService = accessor.get(_univerjs_sheets_drawing.ISheetDrawingService);
917
906
  const sheetSkeletonService = accessor.get(_univerjs_sheets.SheetSkeletonService);
907
+ const undoRedoGroupService = accessor.get(_univerjs_ui.UndoRedoGroupService);
918
908
  const { direction } = params;
919
909
  const drawings = drawingManagerService.getFocusDrawings();
920
910
  if (drawings.length === 0) return false;
@@ -936,10 +926,10 @@ const MoveDrawingsCommand = {
936
926
  axisAlignSheetTransform: (0, _univerjs_sheets_drawing.transformToAxisAlignPosition)(newTransform, skeleton)
937
927
  };
938
928
  }).filter((drawing) => drawing != null);
939
- if (commandService.syncExecuteCommand(_univerjs_sheets_drawing.SetSheetDrawingCommand.id, {
929
+ if (undoRedoGroupService.runTimed(unitId, `sheet-drawing:nudge:${drawings[0].subUnitId}:${drawings.map((drawing) => drawing.drawingId).sort().join(",")}`, () => commandService.syncExecuteCommand(_univerjs_sheets_drawing.SetSheetDrawingCommand.id, {
940
930
  unitId,
941
931
  drawings: newDrawings
942
- })) {
932
+ }))) {
943
933
  commandService.syncExecuteCommand(_univerjs_sheets_drawing.ClearSheetDrawingTransformerOperation.id, [unitId]);
944
934
  return true;
945
935
  }
@@ -991,20 +981,14 @@ function rangeToA1Notation(range) {
991
981
  return start === end ? start : `${start}:${end}`;
992
982
  }
993
983
  /**
994
- * Check if a cell has image
995
- */
996
- function cellHasImage$1(cell) {
997
- var _cell$p, _cell$p2;
998
- return !!((cell === null || cell === void 0 || (_cell$p = cell.p) === null || _cell$p === void 0 || (_cell$p = _cell$p.drawingsOrder) === null || _cell$p === void 0 ? void 0 : _cell$p.length) && (cell === null || cell === void 0 || (_cell$p2 = cell.p) === null || _cell$p2 === void 0 || (_cell$p2 = _cell$p2.drawingsOrder) === null || _cell$p2 === void 0 ? void 0 : _cell$p2.length) > 0);
999
- }
1000
- /**
1001
984
  * Get image data from cell
1002
985
  */
1003
986
  function getCellImageData(cell) {
1004
- var _cell$p3, _cell$p4;
1005
- if (!((_cell$p3 = cell.p) === null || _cell$p3 === void 0 || (_cell$p3 = _cell$p3.drawingsOrder) === null || _cell$p3 === void 0 ? void 0 : _cell$p3.length) || !((_cell$p4 = cell.p) === null || _cell$p4 === void 0 ? void 0 : _cell$p4.drawings)) return null;
1006
- const drawingId = cell.p.drawingsOrder[0];
1007
- const drawing = cell.p.drawings[drawingId];
987
+ var _documentData$drawing;
988
+ const documentData = cell.p;
989
+ const drawingId = documentData === null || documentData === void 0 || (_documentData$drawing = documentData.drawingsOrder) === null || _documentData$drawing === void 0 ? void 0 : _documentData$drawing[0];
990
+ if (!(0, _univerjs_sheets.isCellImage)(documentData) || !drawingId || !(documentData === null || documentData === void 0 ? void 0 : documentData.drawings)) return null;
991
+ const drawing = documentData.drawings[drawingId];
1008
992
  if (!drawing || !("source" in drawing) || !("imageSourceType" in drawing)) return null;
1009
993
  return drawing;
1010
994
  }
@@ -1051,7 +1035,7 @@ let BatchSaveImagesService = class BatchSaveImagesService extends _univerjs_core
1051
1035
  const { startRow, endRow, startColumn, endColumn } = selection.range;
1052
1036
  for (let row = startRow; row <= endRow; row++) for (let col = startColumn; col <= endColumn; col++) {
1053
1037
  const cell = cellMatrix.getValue(row, col);
1054
- if (cellHasImage$1(cell)) {
1038
+ if ((0, _univerjs_sheets.isCellImage)(cell === null || cell === void 0 ? void 0 : cell.p)) {
1055
1039
  const imageData = getCellImageData(cell);
1056
1040
  if (imageData) images.push({
1057
1041
  row,
@@ -1077,7 +1061,7 @@ let BatchSaveImagesService = class BatchSaveImagesService extends _univerjs_core
1077
1061
  const { startRow, endRow, startColumn, endColumn } = range;
1078
1062
  for (let row = startRow; row <= endRow; row++) for (let col = startColumn; col <= endColumn; col++) {
1079
1063
  const cell = cellMatrix.getValue(row, col);
1080
- if (cellHasImage$1(cell)) {
1064
+ if ((0, _univerjs_sheets.isCellImage)(cell === null || cell === void 0 ? void 0 : cell.p)) {
1081
1065
  const imageData = getCellImageData(cell);
1082
1066
  if (imageData) images.push({
1083
1067
  row,
@@ -1115,8 +1099,8 @@ let BatchSaveImagesService = class BatchSaveImagesService extends _univerjs_core
1115
1099
  for (let row = minRow; row <= maxRow; row++) {
1116
1100
  const cell = cellMatrix.getValue(row, col);
1117
1101
  if (cell) {
1118
- var _cell$v, _cell$p5;
1119
- if (((_cell$v = cell.v) === null || _cell$v === void 0 ? void 0 : _cell$v.toString()) || ((_cell$p5 = cell.p) === null || _cell$p5 === void 0 || (_cell$p5 = _cell$p5.body) === null || _cell$p5 === void 0 || (_cell$p5 = _cell$p5.dataStream) === null || _cell$p5 === void 0 ? void 0 : _cell$p5.trim()) || "") {
1102
+ var _cell$v, _cell$p;
1103
+ if (((_cell$v = cell.v) === null || _cell$v === void 0 ? void 0 : _cell$v.toString()) || ((_cell$p = cell.p) === null || _cell$p === void 0 || (_cell$p = _cell$p.body) === null || _cell$p === void 0 || (_cell$p = _cell$p.dataStream) === null || _cell$p === void 0 ? void 0 : _cell$p.trim()) || "") {
1120
1104
  columnsWithData.add(col);
1121
1105
  break;
1122
1106
  }
@@ -1152,8 +1136,8 @@ let BatchSaveImagesService = class BatchSaveImagesService extends _univerjs_core
1152
1136
  for (let row = minRow; row <= maxRow; row++) {
1153
1137
  const cell = cellMatrix.getValue(row, col);
1154
1138
  if (cell) {
1155
- var _cell$v2, _cell$p6;
1156
- if (((_cell$v2 = cell.v) === null || _cell$v2 === void 0 ? void 0 : _cell$v2.toString()) || ((_cell$p6 = cell.p) === null || _cell$p6 === void 0 || (_cell$p6 = _cell$p6.body) === null || _cell$p6 === void 0 || (_cell$p6 = _cell$p6.dataStream) === null || _cell$p6 === void 0 ? void 0 : _cell$p6.trim()) || "") {
1139
+ var _cell$v2, _cell$p2;
1140
+ if (((_cell$v2 = cell.v) === null || _cell$v2 === void 0 ? void 0 : _cell$v2.toString()) || ((_cell$p2 = cell.p) === null || _cell$p2 === void 0 || (_cell$p2 = _cell$p2.body) === null || _cell$p2 === void 0 || (_cell$p2 = _cell$p2.dataStream) === null || _cell$p2 === void 0 ? void 0 : _cell$p2.trim()) || "") {
1157
1141
  columnsWithData.add(col);
1158
1142
  break;
1159
1143
  }
@@ -1204,8 +1188,8 @@ let BatchSaveImagesService = class BatchSaveImagesService extends _univerjs_core
1204
1188
  if (worksheet) {
1205
1189
  const cell = worksheet.getCellMatrix().getValue(imageInfo.row, config.columnIndex);
1206
1190
  if (cell) {
1207
- var _cell$v3, _cell$p7;
1208
- const value = ((_cell$v3 = cell.v) === null || _cell$v3 === void 0 ? void 0 : _cell$v3.toString()) || ((_cell$p7 = cell.p) === null || _cell$p7 === void 0 || (_cell$p7 = _cell$p7.body) === null || _cell$p7 === void 0 || (_cell$p7 = _cell$p7.dataStream) === null || _cell$p7 === void 0 ? void 0 : _cell$p7.trim()) || "";
1191
+ var _cell$v3, _cell$p3;
1192
+ const value = ((_cell$v3 = cell.v) === null || _cell$v3 === void 0 ? void 0 : _cell$v3.toString()) || ((_cell$p3 = cell.p) === null || _cell$p3 === void 0 || (_cell$p3 = _cell$p3.body) === null || _cell$p3 === void 0 || (_cell$p3 = _cell$p3.dataStream) === null || _cell$p3 === void 0 ? void 0 : _cell$p3.trim()) || "";
1209
1193
  if (value) {
1210
1194
  const sanitized = value.replace(/[<>:"/\\|?*]/g, "_").trim();
1211
1195
  if (sanitized) parts.push(sanitized);
@@ -1226,8 +1210,8 @@ let BatchSaveImagesService = class BatchSaveImagesService extends _univerjs_core
1226
1210
  if (worksheet) {
1227
1211
  const cell = worksheet.getCellMatrix().getValue(imageInfo.row, config.columnIndex);
1228
1212
  if (cell) {
1229
- var _cell$v4, _cell$p8;
1230
- const value = ((_cell$v4 = cell.v) === null || _cell$v4 === void 0 ? void 0 : _cell$v4.toString()) || ((_cell$p8 = cell.p) === null || _cell$p8 === void 0 || (_cell$p8 = _cell$p8.body) === null || _cell$p8 === void 0 || (_cell$p8 = _cell$p8.dataStream) === null || _cell$p8 === void 0 ? void 0 : _cell$p8.trim()) || "";
1213
+ var _cell$v4, _cell$p4;
1214
+ const value = ((_cell$v4 = cell.v) === null || _cell$v4 === void 0 ? void 0 : _cell$v4.toString()) || ((_cell$p4 = cell.p) === null || _cell$p4 === void 0 || (_cell$p4 = _cell$p4.body) === null || _cell$p4 === void 0 || (_cell$p4 = _cell$p4.dataStream) === null || _cell$p4 === void 0 ? void 0 : _cell$p4.trim()) || "";
1231
1215
  if (value) {
1232
1216
  const sanitized = value.replace(/[<>:"/\\|?*]/g, "_").trim();
1233
1217
  if (sanitized) parts.push(sanitized);
@@ -1392,21 +1376,24 @@ const SidebarSheetDrawingOperation = {
1392
1376
  const sidebarService = accessor.get(_univerjs_ui.ISidebarService);
1393
1377
  const localeService = accessor.get(_univerjs_core.LocaleService);
1394
1378
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
1379
+ const drawingManagerService = accessor.get(_univerjs_drawing.IDrawingManagerService);
1395
1380
  const commandService = accessor.get(_univerjs_core.ICommandService);
1396
1381
  if (!(0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService)) return false;
1397
1382
  switch (params.value) {
1398
1383
  case "open":
1399
1384
  sidebarService.open({
1385
+ id: COMPONENT_SHEET_DRAWING_PANEL,
1400
1386
  header: { title: localeService.t("sheets-drawing-ui.panel.title") },
1401
1387
  children: { label: COMPONENT_SHEET_DRAWING_PANEL },
1402
1388
  onClose: () => {
1403
- commandService.syncExecuteCommand(_univerjs_drawing.SetDrawingSelectedOperation.id, []);
1389
+ const focusedDrawings = drawingManagerService.getFocusDrawings();
1390
+ if (focusedDrawings.length === 1 && focusedDrawings[0].drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE) commandService.syncExecuteCommand(_univerjs_drawing.SetDrawingSelectedOperation.id, []);
1404
1391
  },
1405
1392
  width: 360
1406
1393
  });
1407
1394
  break;
1408
1395
  default:
1409
- sidebarService.close();
1396
+ sidebarService.close(COMPONENT_SHEET_DRAWING_PANEL);
1410
1397
  break;
1411
1398
  }
1412
1399
  return true;
@@ -1509,7 +1496,6 @@ let SheetsDrawingGroupCopyPasteController = class SheetsDrawingGroupCopyPasteCon
1509
1496
  };
1510
1497
  }
1511
1498
  _generateGroupPasteMutations(pasteTo) {
1512
- var _cloned$flatChildren;
1513
1499
  if (!this._copyInfo) return {
1514
1500
  redos: [],
1515
1501
  undos: []
@@ -1540,12 +1526,11 @@ let SheetsDrawingGroupCopyPasteController = class SheetsDrawingGroupCopyPasteCon
1540
1526
  left: pasteRect.startX,
1541
1527
  top: pasteRect.startY
1542
1528
  };
1543
- const allDrawings = [...((_cloned$flatChildren = cloned.flatChildren) !== null && _cloned$flatChildren !== void 0 ? _cloned$flatChildren : []).map((d) => ({
1529
+ const allDrawings = [...(cloned.flatChildren ?? []).map((d) => ({
1544
1530
  ...d,
1545
1531
  unitId,
1546
1532
  subUnitId
1547
1533
  })), ...cloned.groups.map((d) => {
1548
- var _transformToDrawingPo, _transformToAxisAlign;
1549
1534
  if (d.drawingId !== newRootGroupId) return {
1550
1535
  ...d,
1551
1536
  unitId,
@@ -1556,8 +1541,8 @@ let SheetsDrawingGroupCopyPasteController = class SheetsDrawingGroupCopyPasteCon
1556
1541
  unitId,
1557
1542
  subUnitId,
1558
1543
  transform: newTransform,
1559
- sheetTransform: (_transformToDrawingPo = (0, _univerjs_sheets_drawing.transformToDrawingPosition)(newTransform, pasteToSkeleton)) !== null && _transformToDrawingPo !== void 0 ? _transformToDrawingPo : origRootGroup.sheetTransform,
1560
- axisAlignSheetTransform: (_transformToAxisAlign = (0, _univerjs_sheets_drawing.transformToAxisAlignPosition)(newTransform, pasteToSkeleton)) !== null && _transformToAxisAlign !== void 0 ? _transformToAxisAlign : origRootGroup.sheetTransform
1544
+ sheetTransform: (0, _univerjs_sheets_drawing.transformToDrawingPosition)(newTransform, pasteToSkeleton) ?? origRootGroup.sheetTransform,
1545
+ axisAlignSheetTransform: (0, _univerjs_sheets_drawing.transformToAxisAlignPosition)(newTransform, pasteToSkeleton) ?? origRootGroup.sheetTransform
1561
1546
  };
1562
1547
  })];
1563
1548
  const { undo: removeOp, redo: insertOp, objects } = this._sheetDrawingService.getBatchAddOp(allDrawings);
@@ -1681,14 +1666,13 @@ function shouldStartFloatDomMoveFromHandle(info, detail) {
1681
1666
  return detail.hostAnchorId === info.id && (detail.hostUnitId == null || detail.hostUnitId === info.unitId) && (detail.button == null || detail.button === 0) && typeof detail.clientX === "number" && typeof detail.clientY === "number";
1682
1667
  }
1683
1668
  function createFloatDomMoveDragState(info, detail) {
1684
- var _info$rect$left, _info$rect$top;
1685
1669
  if (typeof detail.clientX !== "number" || typeof detail.clientY !== "number") return;
1686
1670
  return {
1687
1671
  pointerId: detail.pointerId,
1688
1672
  startClientX: detail.clientX,
1689
1673
  startClientY: detail.clientY,
1690
- startLeft: Number((_info$rect$left = info.rect.left) !== null && _info$rect$left !== void 0 ? _info$rect$left : 0),
1691
- startTop: Number((_info$rect$top = info.rect.top) !== null && _info$rect$top !== void 0 ? _info$rect$top : 0)
1674
+ startLeft: Number(info.rect.left ?? 0),
1675
+ startTop: Number(info.rect.top ?? 0)
1692
1676
  };
1693
1677
  }
1694
1678
  function resolveFloatDomMoveDragTransform(state, event, scene) {
@@ -1970,8 +1954,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
1970
1954
  * default {@link Rect} fallback.
1971
1955
  */
1972
1956
  registerRenderObjectFactory(drawingType, factory) {
1973
- var _this$_renderObjectFa;
1974
- const factories = (_this$_renderObjectFa = this._renderObjectFactories.get(drawingType)) !== null && _this$_renderObjectFa !== void 0 ? _this$_renderObjectFa : [];
1957
+ const factories = this._renderObjectFactories.get(drawingType) ?? [];
1975
1958
  factories.push(factory);
1976
1959
  this._renderObjectFactories.set(drawingType, factories);
1977
1960
  return { dispose: () => {
@@ -1983,10 +1966,9 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
1983
1966
  } };
1984
1967
  }
1985
1968
  _createRenderObject(context) {
1986
- var _factory;
1987
1969
  const factories = this._renderObjectFactories.get(context.drawingType);
1988
1970
  const factory = factories === null || factories === void 0 ? void 0 : factories[factories.length - 1];
1989
- return (_factory = factory === null || factory === void 0 ? void 0 : factory(context)) !== null && _factory !== void 0 ? _factory : new _univerjs_engine_render.Rect(context.key, context.config);
1971
+ return (factory === null || factory === void 0 ? void 0 : factory(context)) ?? new _univerjs_engine_render.Rect(context.key, context.config);
1990
1972
  }
1991
1973
  _bindScrollEvent() {
1992
1974
  this._lifecycleService.lifecycle$.pipe((0, rxjs.filter)((s) => s === _univerjs_core.LifecycleStages.Rendered), (0, rxjs.take)(1)).subscribe(() => {
@@ -2314,7 +2296,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2314
2296
  if (data && data.border) imageConfig.stroke = data.border;
2315
2297
  Object.assign(imageConfig, SHEET_CHART_RENDER_OBJECT_CONFIG);
2316
2298
  } else imageConfig.rotateEnabled = false;
2317
- const rect = rectShape !== null && rectShape !== void 0 ? rectShape : this._createRenderObject({
2299
+ const rect = rectShape ?? this._createRenderObject({
2318
2300
  key: rectShapeKey,
2319
2301
  config: imageConfig,
2320
2302
  unitId,
@@ -2464,6 +2446,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2464
2446
  if (previewObjectKey) scene.removeObject(previewObjectKey);
2465
2447
  });
2466
2448
  listener && disposableCollection.add(listener);
2449
+ this._bindFloatDomScroll(disposableCollection, info, renderObject.renderUnit.scene, skeleton.skeleton, target.worksheet);
2467
2450
  this._domLayerInfoMap.set(drawingId, info);
2468
2451
  });
2469
2452
  }));
@@ -2516,23 +2499,6 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2516
2499
  this._syncFloatDomVisibilityForActiveSheet(unitId, subUnitId);
2517
2500
  updateSheet(unitId, subUnitId);
2518
2501
  }));
2519
- this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs.switchMap)((workbook) => workbook ? workbook.activeSheet$ : (0, rxjs.of)(null)), (0, rxjs.map)((worksheet) => {
2520
- if (!worksheet) return null;
2521
- const unitId = worksheet.getUnitId();
2522
- const render = this._renderManagerService.getRenderUnitById(unitId);
2523
- return render ? {
2524
- render,
2525
- unitId,
2526
- subUnitId: worksheet.getSheetId()
2527
- } : null;
2528
- }), (0, rxjs.switchMap)((render) => render ? (0, _univerjs_core.fromEventSubject)(render.render.scene.getViewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe((0, rxjs.map)(() => ({
2529
- unitId: render.unitId,
2530
- subUnitId: render.subUnitId
2531
- }))) : (0, rxjs.of)(null))).subscribe((value) => {
2532
- if (!value) return;
2533
- const { unitId, subUnitId } = value;
2534
- updateSheet(unitId, subUnitId);
2535
- }));
2536
2502
  this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
2537
2503
  if (commandInfo.id === _univerjs_sheets_ui.SetZoomRatioOperation.id) {
2538
2504
  const { unitId } = commandInfo.params;
@@ -2548,6 +2514,13 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2548
2514
  }
2549
2515
  }));
2550
2516
  }
2517
+ _bindFloatDomScroll(disposableCollection, info, scene, skeleton, worksheet) {
2518
+ const viewport = scene.getViewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_MAIN);
2519
+ if (!viewport) return;
2520
+ disposableCollection.add((0, _univerjs_core.fromEventSubject)(viewport.onScrollAfter$).subscribe(() => {
2521
+ info.position$.next(calcSheetFloatDomPosition(info.rect, scene, skeleton, worksheet, info));
2522
+ }));
2523
+ }
2551
2524
  updateFloatDomProps(unitId, subUnitId, id, props) {
2552
2525
  const info = this._domLayerInfoMap.get(id);
2553
2526
  const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
@@ -2577,13 +2550,13 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2577
2550
  }
2578
2551
  }
2579
2552
  _getObjectIncludingGroup(scene, key, groupKey) {
2580
- var _ref, _ref2, _this$_getChildObject, _scene$getObjectInclu;
2581
- return (_ref = (_ref2 = (_this$_getChildObject = this._getChildObjectFromGroup(scene, key, groupKey)) !== null && _this$_getChildObject !== void 0 ? _this$_getChildObject : (_scene$getObjectInclu = scene.getObjectIncludeInGroup) === null || _scene$getObjectInclu === void 0 ? void 0 : _scene$getObjectInclu.call(scene, key)) !== null && _ref2 !== void 0 ? _ref2 : scene.getObject(key)) !== null && _ref !== void 0 ? _ref : null;
2553
+ var _scene$getObjectInclu;
2554
+ return this._getChildObjectFromGroup(scene, key, groupKey) ?? ((_scene$getObjectInclu = scene.getObjectIncludeInGroup) === null || _scene$getObjectInclu === void 0 ? void 0 : _scene$getObjectInclu.call(scene, key)) ?? scene.getObject(key) ?? null;
2582
2555
  }
2583
2556
  _getChildObjectFromGroup(scene, key, groupKey) {
2584
- var _scene$getObjectInclu2, _scene$getObjectInclu3;
2557
+ var _scene$getObjectInclu2;
2585
2558
  if (!groupKey) return null;
2586
- const groupObject = (_scene$getObjectInclu2 = (_scene$getObjectInclu3 = scene.getObjectIncludeInGroup) === null || _scene$getObjectInclu3 === void 0 ? void 0 : _scene$getObjectInclu3.call(scene, groupKey)) !== null && _scene$getObjectInclu2 !== void 0 ? _scene$getObjectInclu2 : scene.getObject(groupKey);
2559
+ const groupObject = ((_scene$getObjectInclu2 = scene.getObjectIncludeInGroup) === null || _scene$getObjectInclu2 === void 0 ? void 0 : _scene$getObjectInclu2.call(scene, groupKey)) ?? scene.getObject(groupKey);
2587
2560
  return this._findChildObject(groupObject, key);
2588
2561
  }
2589
2562
  _findChildObject(object, key) {
@@ -2607,10 +2580,9 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2607
2580
  if (info) info.rect = object;
2608
2581
  }
2609
2582
  _getChartDataBackground(data) {
2610
- var _record$backgroundCol;
2611
2583
  if (!data || typeof data !== "object" || Array.isArray(data)) return;
2612
2584
  const record = data;
2613
- const background = (_record$backgroundCol = record.backgroundColor) !== null && _record$backgroundCol !== void 0 ? _record$backgroundCol : record.background;
2585
+ const background = record.backgroundColor ?? record.background;
2614
2586
  return typeof background === "string" ? background : void 0;
2615
2587
  }
2616
2588
  _getPosition(position, unitId) {
@@ -2683,7 +2655,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2683
2655
  if (!target) throw new Error("cannot find current target!");
2684
2656
  const { unitId, subUnitId } = target;
2685
2657
  const { initPosition, componentKey, data, allowTransform = true } = layer;
2686
- const id = propId !== null && propId !== void 0 ? propId : (0, _univerjs_core.generateRandomId)();
2658
+ const id = propId ?? (0, _univerjs_core.generateRandomId)();
2687
2659
  const sheetTransform = this._getPosition(initPosition, unitId);
2688
2660
  if (sheetTransform == null) return;
2689
2661
  const sheetDrawingParam = {
@@ -2768,7 +2740,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2768
2740
  const skeletonParam = (_this$_renderManagerS5 = this._renderManagerService.getRenderUnitById(unitId)) === null || _this$_renderManagerS5 === void 0 ? void 0 : _this$_renderManagerS5.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId);
2769
2741
  if (!skeletonParam) return;
2770
2742
  const { componentKey, data, allowTransform = true } = config;
2771
- const id = propId !== null && propId !== void 0 ? propId : (0, _univerjs_core.generateRandomId)();
2743
+ const id = propId ?? (0, _univerjs_core.generateRandomId)();
2772
2744
  const { position: rangePosition, position$: rangePos$ } = this._createRangePositionObserver(range, currentRender, skeletonParam.skeleton);
2773
2745
  const sheetTransform = this._getPosition(rangePosition, unitId);
2774
2746
  if (sheetTransform == null) return;
@@ -2926,15 +2898,14 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2926
2898
  };
2927
2899
  this._canvasFloatDomService.addFloatDom(floatDomCfg);
2928
2900
  this.disposeWithMe(rangePos$.subscribe((newRangePos) => {
2929
- var _domAnchor$width, _domAnchor$height, _domAnchor$width2, _domAnchor$height2;
2930
2901
  const calcOffsetPos = calcDomPositionByAnchor({
2931
2902
  rotate: 0,
2932
2903
  startX: newRangePos.startX,
2933
2904
  startY: newRangePos.startY,
2934
2905
  endX: newRangePos.endX,
2935
2906
  endY: newRangePos.endY,
2936
- width: (_domAnchor$width = domAnchor.width) !== null && _domAnchor$width !== void 0 ? _domAnchor$width : newRangePos.width,
2937
- height: (_domAnchor$height = domAnchor.height) !== null && _domAnchor$height !== void 0 ? _domAnchor$height : newRangePos.height,
2907
+ width: domAnchor.width ?? newRangePos.width,
2908
+ height: domAnchor.height ?? newRangePos.height,
2938
2909
  absolute: {
2939
2910
  left: rangePosition.absolute.left,
2940
2911
  top: rangePosition.absolute.top
@@ -2947,8 +2918,8 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2947
2918
  }), {
2948
2919
  left: calcOffsetPos.startX,
2949
2920
  top: calcOffsetPos.startY,
2950
- width: (_domAnchor$width2 = domAnchor.width) !== null && _domAnchor$width2 !== void 0 ? _domAnchor$width2 : newRangePos.width,
2951
- height: (_domAnchor$height2 = domAnchor.height) !== null && _domAnchor$height2 !== void 0 ? _domAnchor$height2 : newRangePos.height,
2921
+ width: domAnchor.width ?? newRangePos.width,
2922
+ height: domAnchor.height ?? newRangePos.height,
2952
2923
  zIndex: this._drawingManagerService.getDrawingOrder(unitId, subUnitId).length - 1
2953
2924
  });
2954
2925
  const newPos = calcSheetFloatDomPosition(newRect, renderObject.renderUnit.scene, skeletonParam.skeleton, target.worksheet, floatDomInfo);
@@ -2968,6 +2939,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2968
2939
  this._canvasFloatDomService.removeFloatDom(drawingId);
2969
2940
  });
2970
2941
  listener && disposableCollection.add(listener);
2942
+ this._bindFloatDomScroll(disposableCollection, floatDomInfo, renderObject.renderUnit.scene, skeletonParam.skeleton, target.worksheet);
2971
2943
  this._domLayerInfoMap.set(drawingId, floatDomInfo);
2972
2944
  }
2973
2945
  return this._createFloatDomDisposable(id);
@@ -2986,7 +2958,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2986
2958
  const skeletonParam = (_this$_renderManagerS8 = this._renderManagerService.getRenderUnitById(unitId)) === null || _this$_renderManagerS8 === void 0 ? void 0 : _this$_renderManagerS8.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId);
2987
2959
  if (!skeletonParam) return;
2988
2960
  const { componentKey, data, allowTransform = true } = config;
2989
- const id = propId !== null && propId !== void 0 ? propId : (0, _univerjs_core.generateRandomId)();
2961
+ const id = propId ?? (0, _univerjs_core.generateRandomId)();
2990
2962
  const { position: rangePosition, position$: rangePos$ } = this._createRangePositionObserver({
2991
2963
  startRow: 0,
2992
2964
  endRow: 0,
@@ -3167,6 +3139,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
3167
3139
  this._canvasFloatDomService.removeFloatDom(drawingId);
3168
3140
  });
3169
3141
  listener && disposableCollection.add(listener);
3142
+ this._bindFloatDomScroll(disposableCollection, floatDomInfo, renderObject.renderUnit.scene, skeleton.skeleton, target.worksheet);
3170
3143
  this._domLayerInfoMap.set(drawingId, floatDomInfo);
3171
3144
  }
3172
3145
  return this._createFloatDomDisposable(id);
@@ -3282,12 +3255,11 @@ function calcCellPositionByCell(row, col, skeleton) {
3282
3255
  };
3283
3256
  }
3284
3257
  function calcDomPositionByAnchor(rangePosition, domAnchor, scale) {
3285
- var _scale, _domAnchor$width3, _domAnchor$height3;
3286
- scale = (_scale = scale) !== null && _scale !== void 0 ? _scale : 1;
3258
+ scale = scale ?? 1;
3287
3259
  const rangeWidth = rangePosition.endX - rangePosition.startX;
3288
3260
  const rangeHeight = rangePosition.endY - rangePosition.startY;
3289
- const domWidth = (_domAnchor$width3 = domAnchor === null || domAnchor === void 0 ? void 0 : domAnchor.width) !== null && _domAnchor$width3 !== void 0 ? _domAnchor$width3 : rangeWidth;
3290
- const domHeight = (_domAnchor$height3 = domAnchor === null || domAnchor === void 0 ? void 0 : domAnchor.height) !== null && _domAnchor$height3 !== void 0 ? _domAnchor$height3 : rangeHeight;
3261
+ const domWidth = (domAnchor === null || domAnchor === void 0 ? void 0 : domAnchor.width) ?? rangeWidth;
3262
+ const domHeight = (domAnchor === null || domAnchor === void 0 ? void 0 : domAnchor.height) ?? rangeHeight;
3291
3263
  let domLeft = 0;
3292
3264
  let domTop = 0;
3293
3265
  if (domAnchor) {
@@ -3382,13 +3354,6 @@ function UploadCellImageMenuFactory(accessor) {
3382
3354
  //#endregion
3383
3355
  //#region src/menu/save-images.menu.ts
3384
3356
  /**
3385
- * Check if a cell has image
3386
- */
3387
- function cellHasImage(cell) {
3388
- var _cell$p, _cell$p2;
3389
- return !!((cell === null || cell === void 0 || (_cell$p = cell.p) === null || _cell$p === void 0 || (_cell$p = _cell$p.drawingsOrder) === null || _cell$p === void 0 ? void 0 : _cell$p.length) && (cell === null || cell === void 0 || (_cell$p2 = cell.p) === null || _cell$p2 === void 0 || (_cell$p2 = _cell$p2.drawingsOrder) === null || _cell$p2 === void 0 ? void 0 : _cell$p2.length) > 0);
3390
- }
3391
- /**
3392
3357
  * Check if selection range has any images
3393
3358
  */
3394
3359
  function selectionHasImages(workbook, selection) {
@@ -3396,7 +3361,10 @@ function selectionHasImages(workbook, selection) {
3396
3361
  if (!worksheet) return false;
3397
3362
  const cellMatrix = worksheet.getCellMatrix();
3398
3363
  const { startRow, endRow, startColumn, endColumn } = selection;
3399
- for (let row = startRow; row <= endRow; row++) for (let col = startColumn; col <= endColumn; col++) if (cellHasImage(cellMatrix.getValue(row, col))) return true;
3364
+ for (let row = startRow; row <= endRow; row++) for (let col = startColumn; col <= endColumn; col++) {
3365
+ const cell = cellMatrix.getValue(row, col);
3366
+ if ((0, _univerjs_sheets.isCellImage)(cell === null || cell === void 0 ? void 0 : cell.p)) return true;
3367
+ }
3400
3368
  return false;
3401
3369
  }
3402
3370
  /**
@@ -3465,7 +3433,7 @@ const menuSchema = {
3465
3433
  //#endregion
3466
3434
  //#region package.json
3467
3435
  var name = "@univerjs/sheets-drawing-ui";
3468
- var version = "1.0.0-alpha.8";
3436
+ var version = "1.0.0-beta.1";
3469
3437
 
3470
3438
  //#endregion
3471
3439
  //#region src/config/config.ts
@@ -3600,18 +3568,17 @@ function BatchSaveImagesDialog() {
3600
3568
  //#endregion
3601
3569
  //#region src/views/sheet-image-panel/SheetDrawingAnchor.tsx
3602
3570
  const SheetDrawingAnchor = (props) => {
3603
- var _drawingParam$anchorT;
3604
3571
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
3605
3572
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
3606
3573
  const drawingManagerService = (0, _univerjs_ui.useDependency)(_univerjs_drawing.IDrawingManagerService);
3607
3574
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
3608
3575
  const { drawings } = props;
3609
- const drawingParam = drawings[0];
3576
+ const drawingParam = isSheetDrawing(drawings[0]) ? drawings[0] : void 0;
3610
3577
  const renderObject = drawingParam ? renderManagerService.getRenderUnitById(drawingParam.unitId) : void 0;
3611
3578
  const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
3612
3579
  const transformer = scene === null || scene === void 0 ? void 0 : scene.getTransformerByCreate();
3613
3580
  const [anchorShow, setAnchorShow] = (0, react.useState)(true);
3614
- const [value, setValue] = (0, react.useState)((_drawingParam$anchorT = drawingParam === null || drawingParam === void 0 ? void 0 : drawingParam.anchorType) !== null && _drawingParam$anchorT !== void 0 ? _drawingParam$anchorT : _univerjs_sheets_drawing.SheetDrawingAnchorType.Position);
3581
+ const [value, setValue] = (0, react.useState)(drawingParam ? (0, _univerjs_sheets_drawing.getSheetDrawingPlacement)(drawingParam).kind : _univerjs_sheets_drawing.SheetDrawingAnchorType.Position);
3615
3582
  function getUpdateParams(objects, drawingManagerService) {
3616
3583
  const params = [];
3617
3584
  objects.forEach((object) => {
@@ -3621,6 +3588,10 @@ const SheetDrawingAnchor = (props) => {
3621
3588
  params.push(null);
3622
3589
  return true;
3623
3590
  }
3591
+ if (!isSheetDrawing(searchParam)) {
3592
+ params.push(null);
3593
+ return true;
3594
+ }
3624
3595
  const { unitId, subUnitId, drawingId, drawingType, anchorType, sheetTransform, axisAlignSheetTransform } = searchParam;
3625
3596
  params.push({
3626
3597
  unitId,
@@ -3644,10 +3615,9 @@ const SheetDrawingAnchor = (props) => {
3644
3615
  const params = getUpdateParams(objects, drawingManagerService);
3645
3616
  if (params.length === 0) setAnchorShow(false);
3646
3617
  else if (params.length >= 1) {
3647
- var _params$;
3648
3618
  setAnchorShow(true);
3649
- const anchorType = ((_params$ = params[0]) === null || _params$ === void 0 ? void 0 : _params$.anchorType) || _univerjs_sheets_drawing.SheetDrawingAnchorType.Position;
3650
- setValue(anchorType);
3619
+ const drawing = params[0];
3620
+ setValue(drawing ? (0, _univerjs_sheets_drawing.getSheetDrawingPlacement)(drawing).kind : _univerjs_sheets_drawing.SheetDrawingAnchorType.Position);
3651
3621
  }
3652
3622
  });
3653
3623
  return () => {
@@ -3657,21 +3627,34 @@ const SheetDrawingAnchor = (props) => {
3657
3627
  }, [drawingManagerService, transformer]);
3658
3628
  if (!drawingParam || !transformer) return null;
3659
3629
  function handleChange(value) {
3660
- setValue(value);
3630
+ const kind = getAnchorKind(value);
3631
+ if (!kind) return;
3661
3632
  const focusDrawings = drawingManagerService.getFocusDrawings();
3662
- if (focusDrawings.length === 0) return;
3663
- const updateParams = focusDrawings.map((drawing) => {
3664
- return {
3665
- unitId: drawing.unitId,
3666
- subUnitId: drawing.subUnitId,
3633
+ if (!focusDrawings.length || !focusDrawings.every(isSheetDrawing)) return;
3634
+ const { unitId, subUnitId } = focusDrawings[0];
3635
+ const placementUpdates = [];
3636
+ for (const drawing of focusDrawings) {
3637
+ const { transform } = drawing;
3638
+ const { left, top, width, height } = transform ?? {};
3639
+ if (typeof left !== "number" || typeof top !== "number" || typeof width !== "number" || typeof height !== "number" || !Number.isFinite(left) || !Number.isFinite(top) || !Number.isFinite(width) || !Number.isFinite(height)) return;
3640
+ placementUpdates.push({
3667
3641
  drawingId: drawing.drawingId,
3668
- anchorType: value
3669
- };
3670
- });
3671
- commandService.executeCommand(_univerjs_sheets_drawing.SetSheetDrawingCommand.id, {
3672
- unitId: focusDrawings[0].unitId,
3673
- drawings: updateParams
3674
- });
3642
+ placement: {
3643
+ kind,
3644
+ bounds: {
3645
+ left,
3646
+ top,
3647
+ width,
3648
+ height
3649
+ }
3650
+ }
3651
+ });
3652
+ }
3653
+ if (commandService.syncExecuteCommand(_univerjs_sheets_drawing.SetSheetDrawingPlacementCommand.id, {
3654
+ unitId,
3655
+ subUnitId,
3656
+ drawings: placementUpdates
3657
+ })) setValue(kind);
3675
3658
  }
3676
3659
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3677
3660
  className: (0, _univerjs_design.clsx)("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": !anchorShow }),
@@ -3699,6 +3682,13 @@ const SheetDrawingAnchor = (props) => {
3699
3682
  }) })]
3700
3683
  });
3701
3684
  };
3685
+ function isSheetDrawing(drawing) {
3686
+ return Boolean(drawing && "sheetTransform" in drawing && "axisAlignSheetTransform" in drawing);
3687
+ }
3688
+ function getAnchorKind(value) {
3689
+ if (value === _univerjs_sheets_drawing.SheetDrawingAnchorType.Position || value === _univerjs_sheets_drawing.SheetDrawingAnchorType.Both || value === _univerjs_sheets_drawing.SheetDrawingAnchorType.None) return value;
3690
+ return null;
3691
+ }
3702
3692
 
3703
3693
  //#endregion
3704
3694
  //#region src/views/sheet-image-panel/SheetDrawingPanel.tsx
@@ -3814,16 +3804,15 @@ let DrawingContextMenuController = class DrawingContextMenuController extends _u
3814
3804
  }));
3815
3805
  }
3816
3806
  _getContextMenuPosition(drawings) {
3817
- var _this$_drawingContext;
3818
3807
  if (drawings.length !== 1) return _univerjs_ui.ContextMenuPosition.DRAWING;
3819
3808
  const [drawing] = drawings;
3820
- return (_this$_drawingContext = this._drawingContextMenuService.getContextMenuPosition({
3809
+ return this._drawingContextMenuService.getContextMenuPosition({
3821
3810
  unitId: drawing.unitId,
3822
3811
  subUnitId: drawing.subUnitId,
3823
3812
  drawingId: drawing.drawingId,
3824
3813
  drawingType: drawing.drawingType,
3825
3814
  drawing
3826
- })) !== null && _this$_drawingContext !== void 0 ? _this$_drawingContext : _univerjs_ui.ContextMenuPosition.DRAWING;
3815
+ }) ?? _univerjs_ui.ContextMenuPosition.DRAWING;
3827
3816
  }
3828
3817
  };
3829
3818
  DrawingContextMenuController = __decorate([
@@ -3836,6 +3825,7 @@ DrawingContextMenuController = __decorate([
3836
3825
 
3837
3826
  //#endregion
3838
3827
  //#region src/controllers/render-controllers/sheet-celll-image-hover.render-controller.ts
3828
+ const CELL_IMAGE_PREVIEW_KEY = "preview-cell-image";
3839
3829
  let SheetCellImageHoverRenderController = class SheetCellImageHoverRenderController extends _univerjs_core.Disposable {
3840
3830
  constructor(_context, _hoverManagerService, _selectionsService, _drawingRenderService, _sheetSkeletonManagerService) {
3841
3831
  super();
@@ -3874,15 +3864,31 @@ let SheetCellImageHoverRenderController = class SheetCellImageHoverRenderControl
3874
3864
  _initImageClick() {
3875
3865
  this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe((click) => {
3876
3866
  if ((click === null || click === void 0 ? void 0 : click.drawing) && this._isSetCursor) {
3877
- var _this$_sheetSkeletonM;
3878
3867
  const imageDrawing = click.drawing.drawing.drawingOrigin;
3879
- const imageEle = (_this$_sheetSkeletonM = this._sheetSkeletonManagerService.getCurrentSkeleton()) === null || _this$_sheetSkeletonM === void 0 ? void 0 : _this$_sheetSkeletonM.imageCacheMap.getImage(imageDrawing.imageSourceType, imageDrawing.source);
3880
- if (!imageEle) return;
3881
- this._drawingRenderService.previewImage("preview-cell-image", imageEle.src, imageEle.width, imageEle.height);
3882
- this._context.scene.resetCursor();
3883
- this._isSetCursor = false;
3868
+ this._previewImage(imageDrawing);
3884
3869
  }
3885
3870
  }));
3871
+ const currentDbClickedCell$ = this._hoverManagerService.currentDbClickedCell$;
3872
+ if (!currentDbClickedCell$) return;
3873
+ this.disposeWithMe(currentDbClickedCell$.subscribe(({ location }) => {
3874
+ var _worksheet$getCellRaw, _documentData$drawing, _documentData$drawing2;
3875
+ if (location.unitId !== this._context.unitId) return;
3876
+ const worksheet = this._context.unit.getSheetBySheetId(location.subUnitId);
3877
+ const documentData = worksheet === null || worksheet === void 0 || (_worksheet$getCellRaw = worksheet.getCellRaw(location.row, location.col)) === null || _worksheet$getCellRaw === void 0 ? void 0 : _worksheet$getCellRaw.p;
3878
+ const drawingId = documentData === null || documentData === void 0 || (_documentData$drawing = documentData.drawingsOrder) === null || _documentData$drawing === void 0 ? void 0 : _documentData$drawing[0];
3879
+ const imageDrawing = (0, _univerjs_sheets.isCellImage)(documentData) && drawingId ? (_documentData$drawing2 = documentData.drawings) === null || _documentData$drawing2 === void 0 ? void 0 : _documentData$drawing2[drawingId] : void 0;
3880
+ if (imageDrawing) this._previewImage(imageDrawing);
3881
+ }));
3882
+ }
3883
+ _previewImage(imageDrawing) {
3884
+ var _this$_sheetSkeletonM;
3885
+ if (this._disposed) return;
3886
+ const imageCacheMap = (_this$_sheetSkeletonM = this._sheetSkeletonManagerService.getCurrentSkeleton()) === null || _this$_sheetSkeletonM === void 0 ? void 0 : _this$_sheetSkeletonM.imageCacheMap;
3887
+ const imageEle = imageCacheMap === null || imageCacheMap === void 0 ? void 0 : imageCacheMap.getImage(imageDrawing.imageSourceType, imageDrawing.source, () => this._previewImage(imageDrawing));
3888
+ if (!imageEle) return;
3889
+ this._drawingRenderService.previewImage(CELL_IMAGE_PREVIEW_KEY, imageEle.src, imageEle.width, imageEle.height);
3890
+ this._context.scene.resetCursor();
3891
+ this._isSetCursor = false;
3886
3892
  }
3887
3893
  };
3888
3894
  SheetCellImageHoverRenderController = __decorate([
@@ -3915,7 +3921,14 @@ let SheetsDrawingRenderController = class SheetsDrawingRenderController extends
3915
3921
  const drawingData = subUnitData.data[drawingId];
3916
3922
  const { unitId, subUnitId } = drawingData;
3917
3923
  const skeletonParam = this._sheetSkeletonService.getSkeletonParam(unitId, subUnitId);
3918
- if (skeletonParam && drawingData.sheetTransform) drawingData.transform = (0, _univerjs_sheets_drawing.drawingPositionToTransform)(drawingData.sheetTransform, skeletonParam);
3924
+ if (skeletonParam && drawingData.sheetTransform && !drawingData.groupId) {
3925
+ const transform = (0, _univerjs_sheets_drawing.drawingPositionToTransform)(drawingData.sheetTransform, skeletonParam);
3926
+ drawingData.transform = transform && drawingData.drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_GROUP ? {
3927
+ ...transform,
3928
+ left: (transform.left ?? 0) - skeletonParam.skeleton.rowHeaderWidthAndMarginLeft,
3929
+ top: (transform.top ?? 0) - skeletonParam.skeleton.columnHeaderHeightAndMarginTop
3930
+ } : transform;
3931
+ }
3919
3932
  }
3920
3933
  }
3921
3934
  this._drawingManagerService.registerDrawingData(this._context.unitId, this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId));
@@ -3931,9 +3944,11 @@ SheetsDrawingRenderController = __decorate([
3931
3944
  //#endregion
3932
3945
  //#region src/controllers/sheet-cell-image.controller.ts
3933
3946
  function resizeImageByCell(injector, location, cell) {
3934
- var _cell$p, _cell$p2;
3935
- if ((cell === null || cell === void 0 || (_cell$p = cell.p) === null || _cell$p === void 0 || (_cell$p = _cell$p.body) === null || _cell$p === void 0 ? void 0 : _cell$p.dataStream.length) === 3 && ((_cell$p2 = cell.p) === null || _cell$p2 === void 0 || (_cell$p2 = _cell$p2.drawingsOrder) === null || _cell$p2 === void 0 ? void 0 : _cell$p2.length) === 1) {
3936
- const image = cell.p.drawings[cell.p.drawingsOrder[0]];
3947
+ var _documentData$drawing, _documentData$drawing2;
3948
+ const documentData = cell === null || cell === void 0 ? void 0 : cell.p;
3949
+ const drawingId = (0, _univerjs_sheets.isCellImage)(documentData) && (documentData === null || documentData === void 0 || (_documentData$drawing = documentData.drawingsOrder) === null || _documentData$drawing === void 0 ? void 0 : _documentData$drawing.length) === 1 ? documentData.drawingsOrder[0] : void 0;
3950
+ const image = drawingId ? documentData === null || documentData === void 0 || (_documentData$drawing2 = documentData.drawings) === null || _documentData$drawing2 === void 0 ? void 0 : _documentData$drawing2[drawingId] : void 0;
3951
+ if (image && documentData) {
3937
3952
  const imageSize = getDrawingSizeByCell(injector, {
3938
3953
  unitId: location.unitId,
3939
3954
  subUnitId: location.subUnitId,
@@ -3949,8 +3964,8 @@ function resizeImageByCell(injector, location, cell) {
3949
3964
  image.transform.top = 0;
3950
3965
  image.docTransform.positionH.posOffset = 0;
3951
3966
  image.docTransform.positionV.posOffset = 0;
3952
- cell.p.documentStyle.pageSize.width = Infinity;
3953
- cell.p.documentStyle.pageSize.height = Infinity;
3967
+ documentData.documentStyle.pageSize.width = Infinity;
3968
+ documentData.documentStyle.pageSize.height = Infinity;
3954
3969
  return true;
3955
3970
  }
3956
3971
  }
@@ -3982,8 +3997,7 @@ let SheetCellImageController = class SheetCellImageController extends _univerjs_
3982
3997
  effect: _univerjs_core.InterceptorEffectEnum.Style,
3983
3998
  priority: _univerjs_sheets.InterceptCellContentPriority.CELL_IMAGE,
3984
3999
  handler: (cell, pos, next) => {
3985
- var _cell$p$drawingsOrder;
3986
- if ((cell === null || cell === void 0 ? void 0 : cell.p) && ((_cell$p$drawingsOrder = cell.p.drawingsOrder) === null || _cell$p$drawingsOrder === void 0 ? void 0 : _cell$p$drawingsOrder.length)) {
4000
+ if (cell && (0, _univerjs_sheets.isCellImage)(cell.p)) {
3987
4001
  if (cell === pos.rawData) cell = { ...pos.rawData };
3988
4002
  if (!cell.interceptorStyle) cell.interceptorStyle = {};
3989
4003
  cell.interceptorStyle.tr = { a: 0 };
@@ -4083,10 +4097,9 @@ let SheetCellImageCopyPasteController = class SheetCellImageCopyPasteController
4083
4097
  _initDocImageCopyPasteHooks() {
4084
4098
  this.disposeWithMe(this._commandService.beforeCommandExecuted((commandInfo) => {
4085
4099
  if (commandInfo.id === _univerjs_docs_ui.InnerPasteCommand.id) {
4086
- var _doc$drawings;
4087
4100
  const { doc } = commandInfo.params;
4088
4101
  const currentDoc = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
4089
- if (currentDoc == null || !Object.keys((_doc$drawings = doc.drawings) !== null && _doc$drawings !== void 0 ? _doc$drawings : {}).length) return;
4102
+ if (currentDoc == null || !Object.keys(doc.drawings ?? {}).length) return;
4090
4103
  const docUnitId = currentDoc.getUnitId();
4091
4104
  if (DISABLE_UNITS.includes(docUnitId)) {
4092
4105
  var _currentDoc$getBody;
@@ -4153,12 +4166,11 @@ let SheetDrawingActiveRenderController = class SheetDrawingActiveRenderControlle
4153
4166
  setTimeout(() => {
4154
4167
  const drawingMap = this._drawingManagerService.drawingManagerData;
4155
4168
  const removeDrawings = [];
4156
- Object.keys(drawingMap !== null && drawingMap !== void 0 ? drawingMap : {}).forEach((unitId) => {
4157
- var _drawingMap$unitId;
4158
- const subUnitMap = (_drawingMap$unitId = drawingMap[unitId]) !== null && _drawingMap$unitId !== void 0 ? _drawingMap$unitId : {};
4169
+ Object.keys(drawingMap ?? {}).forEach((unitId) => {
4170
+ const subUnitMap = drawingMap[unitId] ?? {};
4159
4171
  Object.keys(subUnitMap).forEach((subUnitId) => {
4160
- var _subUnitMap$subUnitId, _subUnitMap$subUnitId2;
4161
- 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 : {};
4172
+ var _subUnitMap$subUnitId;
4173
+ const drawingData = ((_subUnitMap$subUnitId = subUnitMap[subUnitId]) === null || _subUnitMap$subUnitId === void 0 ? void 0 : _subUnitMap$subUnitId.data) ?? {};
4162
4174
  Object.keys(drawingData).forEach((drawingId) => {
4163
4175
  if (unitId === selfUnitId) removeDrawings.push(drawingData[drawingId]);
4164
4176
  });
@@ -4174,13 +4186,12 @@ let SheetDrawingActiveRenderController = class SheetDrawingActiveRenderControlle
4174
4186
  const drawingMap = this._drawingManagerService.drawingManagerData;
4175
4187
  const insertDrawings = [];
4176
4188
  const removeDrawings = [];
4177
- Object.keys(drawingMap !== null && drawingMap !== void 0 ? drawingMap : {}).forEach((unitId) => {
4178
- var _drawingMap$unitId2;
4189
+ Object.keys(drawingMap ?? {}).forEach((unitId) => {
4179
4190
  if (unitId !== showUnitId) return;
4180
- const subUnitMap = (_drawingMap$unitId2 = drawingMap[unitId]) !== null && _drawingMap$unitId2 !== void 0 ? _drawingMap$unitId2 : {};
4191
+ const subUnitMap = drawingMap[unitId] ?? {};
4181
4192
  Object.keys(subUnitMap).forEach((subUnitId) => {
4182
- var _subUnitMap$subUnitId3, _subUnitMap$subUnitId4;
4183
- 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 : {};
4193
+ var _subUnitMap$subUnitId2;
4194
+ const drawingData = ((_subUnitMap$subUnitId2 = subUnitMap[subUnitId]) === null || _subUnitMap$subUnitId2 === void 0 ? void 0 : _subUnitMap$subUnitId2.data) ?? {};
4184
4195
  Object.keys(drawingData).forEach((drawingId) => {
4185
4196
  if (unitId === showUnitId && subUnitId === showSubunitId) {
4186
4197
  const drawing = drawingData[drawingId];
@@ -4404,7 +4415,6 @@ let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController ex
4404
4415
  subUnitId,
4405
4416
  isCut: copyType === _univerjs_sheets_ui.COPY_TYPE.CUT,
4406
4417
  getTransform: (transform, sheetTransform) => {
4407
- var _transformToDrawingPo, _transformToAxisAlign;
4408
4418
  const pasteRect = (0, _univerjs_sheets.attachRangeWithCoord)(pasteToSkeleton, {
4409
4419
  startRow: pasteRange.startRow,
4410
4420
  endRow: pasteRange.endRow,
@@ -4418,8 +4428,8 @@ let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController ex
4418
4428
  };
4419
4429
  return {
4420
4430
  transform: newTransform,
4421
- sheetTransform: (_transformToDrawingPo = (0, _univerjs_sheets_drawing.transformToDrawingPosition)(newTransform, pasteToSkeleton)) !== null && _transformToDrawingPo !== void 0 ? _transformToDrawingPo : sheetTransform,
4422
- axisAlignSheetTransform: (_transformToAxisAlign = (0, _univerjs_sheets_drawing.transformToAxisAlignPosition)(newTransform, pasteToSkeleton)) !== null && _transformToAxisAlign !== void 0 ? _transformToAxisAlign : sheetTransform
4431
+ sheetTransform: (0, _univerjs_sheets_drawing.transformToDrawingPosition)(newTransform, pasteToSkeleton) ?? sheetTransform,
4432
+ axisAlignSheetTransform: (0, _univerjs_sheets_drawing.transformToAxisAlignPosition)(newTransform, pasteToSkeleton) ?? sheetTransform
4423
4433
  };
4424
4434
  }
4425
4435
  });
@@ -4550,11 +4560,10 @@ let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController ex
4550
4560
  unitId: toUnitId,
4551
4561
  subUnitId: toSubUnitId,
4552
4562
  getTransform: (transform, sheetTransform) => {
4553
- var _transform$left, _transform$top, _transformToAxisAlign2;
4554
4563
  const newTransform = {
4555
4564
  ...transform,
4556
- left: ((_transform$left = transform === null || transform === void 0 ? void 0 : transform.left) !== null && _transform$left !== void 0 ? _transform$left : 0) + leftOffset,
4557
- top: ((_transform$top = transform === null || transform === void 0 ? void 0 : transform.top) !== null && _transform$top !== void 0 ? _transform$top : 0) + topOffset
4565
+ left: ((transform === null || transform === void 0 ? void 0 : transform.left) ?? 0) + leftOffset,
4566
+ top: ((transform === null || transform === void 0 ? void 0 : transform.top) ?? 0) + topOffset
4558
4567
  };
4559
4568
  return {
4560
4569
  transform: newTransform,
@@ -4571,7 +4580,7 @@ let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController ex
4571
4580
  column: sheetTransform.from.column + columnOffset
4572
4581
  }
4573
4582
  },
4574
- axisAlignSheetTransform: (_transformToAxisAlign2 = (0, _univerjs_sheets_drawing.transformToAxisAlignPosition)(newTransform, toSkeleton)) !== null && _transformToAxisAlign2 !== void 0 ? _transformToAxisAlign2 : sheetTransform
4583
+ axisAlignSheetTransform: (0, _univerjs_sheets_drawing.transformToAxisAlignPosition)(newTransform, toSkeleton) ?? sheetTransform
4575
4584
  };
4576
4585
  },
4577
4586
  isCut: copyType === _univerjs_sheets_ui.COPY_TYPE.CUT
@@ -4795,6 +4804,10 @@ let SheetDrawingPermissionController = class SheetDrawingPermissionController ex
4795
4804
  const { drawings } = command.params;
4796
4805
  unitId = drawings === null || drawings === void 0 || (_drawings$ = drawings[0]) === null || _drawings$ === void 0 ? void 0 : _drawings$.unitId;
4797
4806
  subUnitId = drawings === null || drawings === void 0 || (_drawings$2 = drawings[0]) === null || _drawings$2 === void 0 ? void 0 : _drawings$2.subUnitId;
4807
+ } else if (command.id === _univerjs_sheets_drawing.SetSheetDrawingPlacementCommand.id) {
4808
+ const target = getPlacementCommandTarget(command.params);
4809
+ unitId = target.unitId;
4810
+ subUnitId = target.subUnitId;
4798
4811
  } else if (command.id === _univerjs_sheets_drawing.SetDrawingArrangeCommand.id) {
4799
4812
  const params = command.params;
4800
4813
  unitId = params.unitId;
@@ -4818,16 +4831,23 @@ SheetDrawingPermissionController = __decorate([
4818
4831
  __decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetPermissionCheckController)),
4819
4832
  __decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_sheets_drawing.ISheetDrawingService))
4820
4833
  ], SheetDrawingPermissionController);
4834
+ function getPlacementCommandTarget(params) {
4835
+ if (!params) return {};
4836
+ return {
4837
+ unitId: "unitId" in params && typeof params.unitId === "string" ? params.unitId : void 0,
4838
+ subUnitId: "subUnitId" in params && typeof params.subUnitId === "string" ? params.subUnitId : void 0
4839
+ };
4840
+ }
4821
4841
 
4822
4842
  //#endregion
4823
4843
  //#region src/views/PrintingFloatDom.tsx
4824
4844
  function createPrintingFloatDom(info, scene, skeleton, worksheet) {
4825
4845
  const { width, height, angle, left, top } = info.transform;
4826
4846
  const offsetBound = transformBound2DOMBound({
4827
- left: left !== null && left !== void 0 ? left : 0,
4828
- right: (left !== null && left !== void 0 ? left : 0) + (width !== null && width !== void 0 ? width : 0),
4829
- top: top !== null && top !== void 0 ? top : 0,
4830
- bottom: (top !== null && top !== void 0 ? top : 0) + (height !== null && height !== void 0 ? height : 0)
4847
+ left: left ?? 0,
4848
+ right: (left ?? 0) + (width ?? 0),
4849
+ top: top ?? 0,
4850
+ bottom: (top ?? 0) + (height ?? 0)
4831
4851
  }, scene, skeleton, worksheet, void 0, true);
4832
4852
  const { scaleX, scaleY } = scene.getAncestorScale();
4833
4853
  const domPos = {
@@ -5194,11 +5214,13 @@ const DeleteDrawingsShortcutItem = {
5194
5214
  * limitations under the License.
5195
5215
  */
5196
5216
  let SheetDrawingUIController = class SheetDrawingUIController extends _univerjs_core.Disposable {
5197
- constructor(_menuManagerService, _commandService, _shortcutService) {
5217
+ constructor(_menuManagerService, _commandService, _shortcutService, _drawingManagerService, _sidebarService) {
5198
5218
  super();
5199
5219
  this._menuManagerService = _menuManagerService;
5200
5220
  this._commandService = _commandService;
5201
5221
  this._shortcutService = _shortcutService;
5222
+ this._drawingManagerService = _drawingManagerService;
5223
+ this._sidebarService = _sidebarService;
5202
5224
  this._init();
5203
5225
  }
5204
5226
  _initCustomComponents() {}
@@ -5230,17 +5252,27 @@ let SheetDrawingUIController = class SheetDrawingUIController extends _univerjs_
5230
5252
  this.disposeWithMe(this._shortcutService.registerShortcut(item));
5231
5253
  });
5232
5254
  }
5255
+ _initImagePanel() {
5256
+ this.disposeWithMe(this._drawingManagerService.focus$.subscribe((drawings) => {
5257
+ if (!this._sidebarService.visible || this._sidebarService.options.id !== "COMPONENT_SHEET_DRAWING_PANEL") return;
5258
+ if (drawings.length === 1 && drawings[0].drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE) return;
5259
+ this._sidebarService.close(COMPONENT_SHEET_DRAWING_PANEL);
5260
+ }));
5261
+ }
5233
5262
  _init() {
5234
5263
  this._initCommands();
5235
5264
  this._initCustomComponents();
5236
5265
  this._initMenus();
5237
5266
  this._initShortcuts();
5267
+ this._initImagePanel();
5238
5268
  }
5239
5269
  };
5240
5270
  SheetDrawingUIController = __decorate([
5241
5271
  __decorateParam(0, _univerjs_ui.IMenuManagerService),
5242
5272
  __decorateParam(1, _univerjs_core.ICommandService),
5243
- __decorateParam(2, _univerjs_ui.IShortcutService)
5273
+ __decorateParam(2, _univerjs_ui.IShortcutService),
5274
+ __decorateParam(3, _univerjs_drawing.IDrawingManagerService),
5275
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_ui.ISidebarService))
5244
5276
  ], SheetDrawingUIController);
5245
5277
 
5246
5278
  //#endregion
@@ -5329,7 +5361,8 @@ let DrawingPopupMenuController = class DrawingPopupMenuController extends _unive
5329
5361
  const menus = this._canvasPopManagerService.getFeatureMenu(unitId, subUnitId, drawingId, drawingType);
5330
5362
  singletonPopupDisposer = this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(object, {
5331
5363
  componentKey: _univerjs_drawing_ui.COMPONENT_IMAGE_POPUP_MENU,
5332
- direction: "horizontal",
5364
+ constrainToCanvas: true,
5365
+ direction: this._localeService.getDirection() === "rtl" ? "left" : "horizontal",
5333
5366
  offset: [2, 0],
5334
5367
  extraProps: { menuItems: menus || this._getImageMenuItems(unitId, subUnitId, drawingId, drawingType) }
5335
5368
  }));
@@ -5623,7 +5656,7 @@ _defineProperty(UniverSheetsDrawingUIPlugin, "pluginName", "SHEET_IMAGE_UI_PLUGI
5623
5656
  _defineProperty(UniverSheetsDrawingUIPlugin, "packageName", name);
5624
5657
  _defineProperty(UniverSheetsDrawingUIPlugin, "version", version);
5625
5658
  UniverSheetsDrawingUIPlugin = __decorate([
5626
- (0, _univerjs_core.DependentOn)(_univerjs_drawing.UniverDrawingPlugin, _univerjs_engine_render.UniverRenderEnginePlugin, _univerjs_docs_drawing.UniverDocsDrawingPlugin, _univerjs_sheets.UniverSheetsPlugin, _univerjs_ui.UniverUIPlugin, _univerjs_sheets_drawing.UniverSheetsDrawingPlugin, _univerjs_drawing_ui.UniverDrawingUIPlugin, _univerjs_sheets_ui.UniverSheetsUIPlugin),
5659
+ (0, _univerjs_core.DependentOn)(_univerjs_drawing.UniverDrawingPlugin, _univerjs_engine_render.UniverRenderEnginePlugin, _univerjs_docs_drawing.UniverDocsDrawingPlugin, _univerjs_sheets.UniverSheetsPlugin, _univerjs_sheets_drawing.UniverSheetsDrawingPlugin, _univerjs_drawing_ui.UniverDrawingUIPlugin, _univerjs_sheets_ui.UniverSheetsUIPlugin),
5627
5660
  __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
5628
5661
  __decorateParam(2, _univerjs_engine_render.IRenderManagerService),
5629
5662
  __decorateParam(3, _univerjs_core.IConfigService)