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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -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
 
@@ -991,20 +980,14 @@ function rangeToA1Notation(range) {
991
980
  return start === end ? start : `${start}:${end}`;
992
981
  }
993
982
  /**
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
983
  * Get image data from cell
1002
984
  */
1003
985
  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];
986
+ var _documentData$drawing;
987
+ const documentData = cell.p;
988
+ const drawingId = documentData === null || documentData === void 0 || (_documentData$drawing = documentData.drawingsOrder) === null || _documentData$drawing === void 0 ? void 0 : _documentData$drawing[0];
989
+ if (!(0, _univerjs_sheets.isCellImage)(documentData) || !drawingId || !(documentData === null || documentData === void 0 ? void 0 : documentData.drawings)) return null;
990
+ const drawing = documentData.drawings[drawingId];
1008
991
  if (!drawing || !("source" in drawing) || !("imageSourceType" in drawing)) return null;
1009
992
  return drawing;
1010
993
  }
@@ -1051,7 +1034,7 @@ let BatchSaveImagesService = class BatchSaveImagesService extends _univerjs_core
1051
1034
  const { startRow, endRow, startColumn, endColumn } = selection.range;
1052
1035
  for (let row = startRow; row <= endRow; row++) for (let col = startColumn; col <= endColumn; col++) {
1053
1036
  const cell = cellMatrix.getValue(row, col);
1054
- if (cellHasImage$1(cell)) {
1037
+ if ((0, _univerjs_sheets.isCellImage)(cell === null || cell === void 0 ? void 0 : cell.p)) {
1055
1038
  const imageData = getCellImageData(cell);
1056
1039
  if (imageData) images.push({
1057
1040
  row,
@@ -1077,7 +1060,7 @@ let BatchSaveImagesService = class BatchSaveImagesService extends _univerjs_core
1077
1060
  const { startRow, endRow, startColumn, endColumn } = range;
1078
1061
  for (let row = startRow; row <= endRow; row++) for (let col = startColumn; col <= endColumn; col++) {
1079
1062
  const cell = cellMatrix.getValue(row, col);
1080
- if (cellHasImage$1(cell)) {
1063
+ if ((0, _univerjs_sheets.isCellImage)(cell === null || cell === void 0 ? void 0 : cell.p)) {
1081
1064
  const imageData = getCellImageData(cell);
1082
1065
  if (imageData) images.push({
1083
1066
  row,
@@ -1115,8 +1098,8 @@ let BatchSaveImagesService = class BatchSaveImagesService extends _univerjs_core
1115
1098
  for (let row = minRow; row <= maxRow; row++) {
1116
1099
  const cell = cellMatrix.getValue(row, col);
1117
1100
  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()) || "") {
1101
+ var _cell$v, _cell$p;
1102
+ 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
1103
  columnsWithData.add(col);
1121
1104
  break;
1122
1105
  }
@@ -1152,8 +1135,8 @@ let BatchSaveImagesService = class BatchSaveImagesService extends _univerjs_core
1152
1135
  for (let row = minRow; row <= maxRow; row++) {
1153
1136
  const cell = cellMatrix.getValue(row, col);
1154
1137
  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()) || "") {
1138
+ var _cell$v2, _cell$p2;
1139
+ 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
1140
  columnsWithData.add(col);
1158
1141
  break;
1159
1142
  }
@@ -1204,8 +1187,8 @@ let BatchSaveImagesService = class BatchSaveImagesService extends _univerjs_core
1204
1187
  if (worksheet) {
1205
1188
  const cell = worksheet.getCellMatrix().getValue(imageInfo.row, config.columnIndex);
1206
1189
  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()) || "";
1190
+ var _cell$v3, _cell$p3;
1191
+ 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
1192
  if (value) {
1210
1193
  const sanitized = value.replace(/[<>:"/\\|?*]/g, "_").trim();
1211
1194
  if (sanitized) parts.push(sanitized);
@@ -1226,8 +1209,8 @@ let BatchSaveImagesService = class BatchSaveImagesService extends _univerjs_core
1226
1209
  if (worksheet) {
1227
1210
  const cell = worksheet.getCellMatrix().getValue(imageInfo.row, config.columnIndex);
1228
1211
  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()) || "";
1212
+ var _cell$v4, _cell$p4;
1213
+ 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
1214
  if (value) {
1232
1215
  const sanitized = value.replace(/[<>:"/\\|?*]/g, "_").trim();
1233
1216
  if (sanitized) parts.push(sanitized);
@@ -1509,7 +1492,6 @@ let SheetsDrawingGroupCopyPasteController = class SheetsDrawingGroupCopyPasteCon
1509
1492
  };
1510
1493
  }
1511
1494
  _generateGroupPasteMutations(pasteTo) {
1512
- var _cloned$flatChildren;
1513
1495
  if (!this._copyInfo) return {
1514
1496
  redos: [],
1515
1497
  undos: []
@@ -1540,12 +1522,11 @@ let SheetsDrawingGroupCopyPasteController = class SheetsDrawingGroupCopyPasteCon
1540
1522
  left: pasteRect.startX,
1541
1523
  top: pasteRect.startY
1542
1524
  };
1543
- const allDrawings = [...((_cloned$flatChildren = cloned.flatChildren) !== null && _cloned$flatChildren !== void 0 ? _cloned$flatChildren : []).map((d) => ({
1525
+ const allDrawings = [...(cloned.flatChildren ?? []).map((d) => ({
1544
1526
  ...d,
1545
1527
  unitId,
1546
1528
  subUnitId
1547
1529
  })), ...cloned.groups.map((d) => {
1548
- var _transformToDrawingPo, _transformToAxisAlign;
1549
1530
  if (d.drawingId !== newRootGroupId) return {
1550
1531
  ...d,
1551
1532
  unitId,
@@ -1556,8 +1537,8 @@ let SheetsDrawingGroupCopyPasteController = class SheetsDrawingGroupCopyPasteCon
1556
1537
  unitId,
1557
1538
  subUnitId,
1558
1539
  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
1540
+ sheetTransform: (0, _univerjs_sheets_drawing.transformToDrawingPosition)(newTransform, pasteToSkeleton) ?? origRootGroup.sheetTransform,
1541
+ axisAlignSheetTransform: (0, _univerjs_sheets_drawing.transformToAxisAlignPosition)(newTransform, pasteToSkeleton) ?? origRootGroup.sheetTransform
1561
1542
  };
1562
1543
  })];
1563
1544
  const { undo: removeOp, redo: insertOp, objects } = this._sheetDrawingService.getBatchAddOp(allDrawings);
@@ -1681,14 +1662,13 @@ function shouldStartFloatDomMoveFromHandle(info, detail) {
1681
1662
  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
1663
  }
1683
1664
  function createFloatDomMoveDragState(info, detail) {
1684
- var _info$rect$left, _info$rect$top;
1685
1665
  if (typeof detail.clientX !== "number" || typeof detail.clientY !== "number") return;
1686
1666
  return {
1687
1667
  pointerId: detail.pointerId,
1688
1668
  startClientX: detail.clientX,
1689
1669
  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)
1670
+ startLeft: Number(info.rect.left ?? 0),
1671
+ startTop: Number(info.rect.top ?? 0)
1692
1672
  };
1693
1673
  }
1694
1674
  function resolveFloatDomMoveDragTransform(state, event, scene) {
@@ -1970,8 +1950,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
1970
1950
  * default {@link Rect} fallback.
1971
1951
  */
1972
1952
  registerRenderObjectFactory(drawingType, factory) {
1973
- var _this$_renderObjectFa;
1974
- const factories = (_this$_renderObjectFa = this._renderObjectFactories.get(drawingType)) !== null && _this$_renderObjectFa !== void 0 ? _this$_renderObjectFa : [];
1953
+ const factories = this._renderObjectFactories.get(drawingType) ?? [];
1975
1954
  factories.push(factory);
1976
1955
  this._renderObjectFactories.set(drawingType, factories);
1977
1956
  return { dispose: () => {
@@ -1983,10 +1962,9 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
1983
1962
  } };
1984
1963
  }
1985
1964
  _createRenderObject(context) {
1986
- var _factory;
1987
1965
  const factories = this._renderObjectFactories.get(context.drawingType);
1988
1966
  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);
1967
+ return (factory === null || factory === void 0 ? void 0 : factory(context)) ?? new _univerjs_engine_render.Rect(context.key, context.config);
1990
1968
  }
1991
1969
  _bindScrollEvent() {
1992
1970
  this._lifecycleService.lifecycle$.pipe((0, rxjs.filter)((s) => s === _univerjs_core.LifecycleStages.Rendered), (0, rxjs.take)(1)).subscribe(() => {
@@ -2314,7 +2292,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2314
2292
  if (data && data.border) imageConfig.stroke = data.border;
2315
2293
  Object.assign(imageConfig, SHEET_CHART_RENDER_OBJECT_CONFIG);
2316
2294
  } else imageConfig.rotateEnabled = false;
2317
- const rect = rectShape !== null && rectShape !== void 0 ? rectShape : this._createRenderObject({
2295
+ const rect = rectShape ?? this._createRenderObject({
2318
2296
  key: rectShapeKey,
2319
2297
  config: imageConfig,
2320
2298
  unitId,
@@ -2464,6 +2442,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2464
2442
  if (previewObjectKey) scene.removeObject(previewObjectKey);
2465
2443
  });
2466
2444
  listener && disposableCollection.add(listener);
2445
+ this._bindFloatDomScroll(disposableCollection, info, renderObject.renderUnit.scene, skeleton.skeleton, target.worksheet);
2467
2446
  this._domLayerInfoMap.set(drawingId, info);
2468
2447
  });
2469
2448
  }));
@@ -2516,23 +2495,6 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2516
2495
  this._syncFloatDomVisibilityForActiveSheet(unitId, subUnitId);
2517
2496
  updateSheet(unitId, subUnitId);
2518
2497
  }));
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
2498
  this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
2537
2499
  if (commandInfo.id === _univerjs_sheets_ui.SetZoomRatioOperation.id) {
2538
2500
  const { unitId } = commandInfo.params;
@@ -2548,6 +2510,13 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2548
2510
  }
2549
2511
  }));
2550
2512
  }
2513
+ _bindFloatDomScroll(disposableCollection, info, scene, skeleton, worksheet) {
2514
+ const viewport = scene.getViewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_MAIN);
2515
+ if (!viewport) return;
2516
+ disposableCollection.add((0, _univerjs_core.fromEventSubject)(viewport.onScrollAfter$).subscribe(() => {
2517
+ info.position$.next(calcSheetFloatDomPosition(info.rect, scene, skeleton, worksheet, info));
2518
+ }));
2519
+ }
2551
2520
  updateFloatDomProps(unitId, subUnitId, id, props) {
2552
2521
  const info = this._domLayerInfoMap.get(id);
2553
2522
  const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
@@ -2577,13 +2546,13 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2577
2546
  }
2578
2547
  }
2579
2548
  _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;
2549
+ var _scene$getObjectInclu;
2550
+ 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
2551
  }
2583
2552
  _getChildObjectFromGroup(scene, key, groupKey) {
2584
- var _scene$getObjectInclu2, _scene$getObjectInclu3;
2553
+ var _scene$getObjectInclu2;
2585
2554
  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);
2555
+ const groupObject = ((_scene$getObjectInclu2 = scene.getObjectIncludeInGroup) === null || _scene$getObjectInclu2 === void 0 ? void 0 : _scene$getObjectInclu2.call(scene, groupKey)) ?? scene.getObject(groupKey);
2587
2556
  return this._findChildObject(groupObject, key);
2588
2557
  }
2589
2558
  _findChildObject(object, key) {
@@ -2607,10 +2576,9 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2607
2576
  if (info) info.rect = object;
2608
2577
  }
2609
2578
  _getChartDataBackground(data) {
2610
- var _record$backgroundCol;
2611
2579
  if (!data || typeof data !== "object" || Array.isArray(data)) return;
2612
2580
  const record = data;
2613
- const background = (_record$backgroundCol = record.backgroundColor) !== null && _record$backgroundCol !== void 0 ? _record$backgroundCol : record.background;
2581
+ const background = record.backgroundColor ?? record.background;
2614
2582
  return typeof background === "string" ? background : void 0;
2615
2583
  }
2616
2584
  _getPosition(position, unitId) {
@@ -2683,7 +2651,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2683
2651
  if (!target) throw new Error("cannot find current target!");
2684
2652
  const { unitId, subUnitId } = target;
2685
2653
  const { initPosition, componentKey, data, allowTransform = true } = layer;
2686
- const id = propId !== null && propId !== void 0 ? propId : (0, _univerjs_core.generateRandomId)();
2654
+ const id = propId ?? (0, _univerjs_core.generateRandomId)();
2687
2655
  const sheetTransform = this._getPosition(initPosition, unitId);
2688
2656
  if (sheetTransform == null) return;
2689
2657
  const sheetDrawingParam = {
@@ -2768,7 +2736,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2768
2736
  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
2737
  if (!skeletonParam) return;
2770
2738
  const { componentKey, data, allowTransform = true } = config;
2771
- const id = propId !== null && propId !== void 0 ? propId : (0, _univerjs_core.generateRandomId)();
2739
+ const id = propId ?? (0, _univerjs_core.generateRandomId)();
2772
2740
  const { position: rangePosition, position$: rangePos$ } = this._createRangePositionObserver(range, currentRender, skeletonParam.skeleton);
2773
2741
  const sheetTransform = this._getPosition(rangePosition, unitId);
2774
2742
  if (sheetTransform == null) return;
@@ -2926,15 +2894,14 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2926
2894
  };
2927
2895
  this._canvasFloatDomService.addFloatDom(floatDomCfg);
2928
2896
  this.disposeWithMe(rangePos$.subscribe((newRangePos) => {
2929
- var _domAnchor$width, _domAnchor$height, _domAnchor$width2, _domAnchor$height2;
2930
2897
  const calcOffsetPos = calcDomPositionByAnchor({
2931
2898
  rotate: 0,
2932
2899
  startX: newRangePos.startX,
2933
2900
  startY: newRangePos.startY,
2934
2901
  endX: newRangePos.endX,
2935
2902
  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,
2903
+ width: domAnchor.width ?? newRangePos.width,
2904
+ height: domAnchor.height ?? newRangePos.height,
2938
2905
  absolute: {
2939
2906
  left: rangePosition.absolute.left,
2940
2907
  top: rangePosition.absolute.top
@@ -2947,8 +2914,8 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2947
2914
  }), {
2948
2915
  left: calcOffsetPos.startX,
2949
2916
  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,
2917
+ width: domAnchor.width ?? newRangePos.width,
2918
+ height: domAnchor.height ?? newRangePos.height,
2952
2919
  zIndex: this._drawingManagerService.getDrawingOrder(unitId, subUnitId).length - 1
2953
2920
  });
2954
2921
  const newPos = calcSheetFloatDomPosition(newRect, renderObject.renderUnit.scene, skeletonParam.skeleton, target.worksheet, floatDomInfo);
@@ -2968,6 +2935,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2968
2935
  this._canvasFloatDomService.removeFloatDom(drawingId);
2969
2936
  });
2970
2937
  listener && disposableCollection.add(listener);
2938
+ this._bindFloatDomScroll(disposableCollection, floatDomInfo, renderObject.renderUnit.scene, skeletonParam.skeleton, target.worksheet);
2971
2939
  this._domLayerInfoMap.set(drawingId, floatDomInfo);
2972
2940
  }
2973
2941
  return this._createFloatDomDisposable(id);
@@ -2986,7 +2954,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2986
2954
  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
2955
  if (!skeletonParam) return;
2988
2956
  const { componentKey, data, allowTransform = true } = config;
2989
- const id = propId !== null && propId !== void 0 ? propId : (0, _univerjs_core.generateRandomId)();
2957
+ const id = propId ?? (0, _univerjs_core.generateRandomId)();
2990
2958
  const { position: rangePosition, position$: rangePos$ } = this._createRangePositionObserver({
2991
2959
  startRow: 0,
2992
2960
  endRow: 0,
@@ -3167,6 +3135,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
3167
3135
  this._canvasFloatDomService.removeFloatDom(drawingId);
3168
3136
  });
3169
3137
  listener && disposableCollection.add(listener);
3138
+ this._bindFloatDomScroll(disposableCollection, floatDomInfo, renderObject.renderUnit.scene, skeleton.skeleton, target.worksheet);
3170
3139
  this._domLayerInfoMap.set(drawingId, floatDomInfo);
3171
3140
  }
3172
3141
  return this._createFloatDomDisposable(id);
@@ -3282,12 +3251,11 @@ function calcCellPositionByCell(row, col, skeleton) {
3282
3251
  };
3283
3252
  }
3284
3253
  function calcDomPositionByAnchor(rangePosition, domAnchor, scale) {
3285
- var _scale, _domAnchor$width3, _domAnchor$height3;
3286
- scale = (_scale = scale) !== null && _scale !== void 0 ? _scale : 1;
3254
+ scale = scale ?? 1;
3287
3255
  const rangeWidth = rangePosition.endX - rangePosition.startX;
3288
3256
  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;
3257
+ const domWidth = (domAnchor === null || domAnchor === void 0 ? void 0 : domAnchor.width) ?? rangeWidth;
3258
+ const domHeight = (domAnchor === null || domAnchor === void 0 ? void 0 : domAnchor.height) ?? rangeHeight;
3291
3259
  let domLeft = 0;
3292
3260
  let domTop = 0;
3293
3261
  if (domAnchor) {
@@ -3382,13 +3350,6 @@ function UploadCellImageMenuFactory(accessor) {
3382
3350
  //#endregion
3383
3351
  //#region src/menu/save-images.menu.ts
3384
3352
  /**
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
3353
  * Check if selection range has any images
3393
3354
  */
3394
3355
  function selectionHasImages(workbook, selection) {
@@ -3396,7 +3357,10 @@ function selectionHasImages(workbook, selection) {
3396
3357
  if (!worksheet) return false;
3397
3358
  const cellMatrix = worksheet.getCellMatrix();
3398
3359
  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;
3360
+ for (let row = startRow; row <= endRow; row++) for (let col = startColumn; col <= endColumn; col++) {
3361
+ const cell = cellMatrix.getValue(row, col);
3362
+ if ((0, _univerjs_sheets.isCellImage)(cell === null || cell === void 0 ? void 0 : cell.p)) return true;
3363
+ }
3400
3364
  return false;
3401
3365
  }
3402
3366
  /**
@@ -3465,7 +3429,7 @@ const menuSchema = {
3465
3429
  //#endregion
3466
3430
  //#region package.json
3467
3431
  var name = "@univerjs/sheets-drawing-ui";
3468
- var version = "1.0.0-alpha.8";
3432
+ var version = "1.0.0-beta.0";
3469
3433
 
3470
3434
  //#endregion
3471
3435
  //#region src/config/config.ts
@@ -3600,18 +3564,17 @@ function BatchSaveImagesDialog() {
3600
3564
  //#endregion
3601
3565
  //#region src/views/sheet-image-panel/SheetDrawingAnchor.tsx
3602
3566
  const SheetDrawingAnchor = (props) => {
3603
- var _drawingParam$anchorT;
3604
3567
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
3605
3568
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
3606
3569
  const drawingManagerService = (0, _univerjs_ui.useDependency)(_univerjs_drawing.IDrawingManagerService);
3607
3570
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
3608
3571
  const { drawings } = props;
3609
- const drawingParam = drawings[0];
3572
+ const drawingParam = isSheetDrawing(drawings[0]) ? drawings[0] : void 0;
3610
3573
  const renderObject = drawingParam ? renderManagerService.getRenderUnitById(drawingParam.unitId) : void 0;
3611
3574
  const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
3612
3575
  const transformer = scene === null || scene === void 0 ? void 0 : scene.getTransformerByCreate();
3613
3576
  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);
3577
+ const [value, setValue] = (0, react.useState)(drawingParam ? (0, _univerjs_sheets_drawing.getSheetDrawingPlacement)(drawingParam).kind : _univerjs_sheets_drawing.SheetDrawingAnchorType.Position);
3615
3578
  function getUpdateParams(objects, drawingManagerService) {
3616
3579
  const params = [];
3617
3580
  objects.forEach((object) => {
@@ -3621,6 +3584,10 @@ const SheetDrawingAnchor = (props) => {
3621
3584
  params.push(null);
3622
3585
  return true;
3623
3586
  }
3587
+ if (!isSheetDrawing(searchParam)) {
3588
+ params.push(null);
3589
+ return true;
3590
+ }
3624
3591
  const { unitId, subUnitId, drawingId, drawingType, anchorType, sheetTransform, axisAlignSheetTransform } = searchParam;
3625
3592
  params.push({
3626
3593
  unitId,
@@ -3644,10 +3611,9 @@ const SheetDrawingAnchor = (props) => {
3644
3611
  const params = getUpdateParams(objects, drawingManagerService);
3645
3612
  if (params.length === 0) setAnchorShow(false);
3646
3613
  else if (params.length >= 1) {
3647
- var _params$;
3648
3614
  setAnchorShow(true);
3649
- const anchorType = ((_params$ = params[0]) === null || _params$ === void 0 ? void 0 : _params$.anchorType) || _univerjs_sheets_drawing.SheetDrawingAnchorType.Position;
3650
- setValue(anchorType);
3615
+ const drawing = params[0];
3616
+ setValue(drawing ? (0, _univerjs_sheets_drawing.getSheetDrawingPlacement)(drawing).kind : _univerjs_sheets_drawing.SheetDrawingAnchorType.Position);
3651
3617
  }
3652
3618
  });
3653
3619
  return () => {
@@ -3657,21 +3623,34 @@ const SheetDrawingAnchor = (props) => {
3657
3623
  }, [drawingManagerService, transformer]);
3658
3624
  if (!drawingParam || !transformer) return null;
3659
3625
  function handleChange(value) {
3660
- setValue(value);
3626
+ const kind = getAnchorKind(value);
3627
+ if (!kind) return;
3661
3628
  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,
3629
+ if (!focusDrawings.length || !focusDrawings.every(isSheetDrawing)) return;
3630
+ const { unitId, subUnitId } = focusDrawings[0];
3631
+ const placementUpdates = [];
3632
+ for (const drawing of focusDrawings) {
3633
+ const { transform } = drawing;
3634
+ const { left, top, width, height } = transform ?? {};
3635
+ 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;
3636
+ placementUpdates.push({
3667
3637
  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
- });
3638
+ placement: {
3639
+ kind,
3640
+ bounds: {
3641
+ left,
3642
+ top,
3643
+ width,
3644
+ height
3645
+ }
3646
+ }
3647
+ });
3648
+ }
3649
+ if (commandService.syncExecuteCommand(_univerjs_sheets_drawing.SetSheetDrawingPlacementCommand.id, {
3650
+ unitId,
3651
+ subUnitId,
3652
+ drawings: placementUpdates
3653
+ })) setValue(kind);
3675
3654
  }
3676
3655
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3677
3656
  className: (0, _univerjs_design.clsx)("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": !anchorShow }),
@@ -3699,6 +3678,13 @@ const SheetDrawingAnchor = (props) => {
3699
3678
  }) })]
3700
3679
  });
3701
3680
  };
3681
+ function isSheetDrawing(drawing) {
3682
+ return Boolean(drawing && "sheetTransform" in drawing && "axisAlignSheetTransform" in drawing);
3683
+ }
3684
+ function getAnchorKind(value) {
3685
+ if (value === _univerjs_sheets_drawing.SheetDrawingAnchorType.Position || value === _univerjs_sheets_drawing.SheetDrawingAnchorType.Both || value === _univerjs_sheets_drawing.SheetDrawingAnchorType.None) return value;
3686
+ return null;
3687
+ }
3702
3688
 
3703
3689
  //#endregion
3704
3690
  //#region src/views/sheet-image-panel/SheetDrawingPanel.tsx
@@ -3814,16 +3800,15 @@ let DrawingContextMenuController = class DrawingContextMenuController extends _u
3814
3800
  }));
3815
3801
  }
3816
3802
  _getContextMenuPosition(drawings) {
3817
- var _this$_drawingContext;
3818
3803
  if (drawings.length !== 1) return _univerjs_ui.ContextMenuPosition.DRAWING;
3819
3804
  const [drawing] = drawings;
3820
- return (_this$_drawingContext = this._drawingContextMenuService.getContextMenuPosition({
3805
+ return this._drawingContextMenuService.getContextMenuPosition({
3821
3806
  unitId: drawing.unitId,
3822
3807
  subUnitId: drawing.subUnitId,
3823
3808
  drawingId: drawing.drawingId,
3824
3809
  drawingType: drawing.drawingType,
3825
3810
  drawing
3826
- })) !== null && _this$_drawingContext !== void 0 ? _this$_drawingContext : _univerjs_ui.ContextMenuPosition.DRAWING;
3811
+ }) ?? _univerjs_ui.ContextMenuPosition.DRAWING;
3827
3812
  }
3828
3813
  };
3829
3814
  DrawingContextMenuController = __decorate([
@@ -3915,7 +3900,14 @@ let SheetsDrawingRenderController = class SheetsDrawingRenderController extends
3915
3900
  const drawingData = subUnitData.data[drawingId];
3916
3901
  const { unitId, subUnitId } = drawingData;
3917
3902
  const skeletonParam = this._sheetSkeletonService.getSkeletonParam(unitId, subUnitId);
3918
- if (skeletonParam && drawingData.sheetTransform) drawingData.transform = (0, _univerjs_sheets_drawing.drawingPositionToTransform)(drawingData.sheetTransform, skeletonParam);
3903
+ if (skeletonParam && drawingData.sheetTransform && !drawingData.groupId) {
3904
+ const transform = (0, _univerjs_sheets_drawing.drawingPositionToTransform)(drawingData.sheetTransform, skeletonParam);
3905
+ drawingData.transform = transform && drawingData.drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_GROUP ? {
3906
+ ...transform,
3907
+ left: (transform.left ?? 0) - skeletonParam.skeleton.rowHeaderWidthAndMarginLeft,
3908
+ top: (transform.top ?? 0) - skeletonParam.skeleton.columnHeaderHeightAndMarginTop
3909
+ } : transform;
3910
+ }
3919
3911
  }
3920
3912
  }
3921
3913
  this._drawingManagerService.registerDrawingData(this._context.unitId, this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId));
@@ -3931,9 +3923,11 @@ SheetsDrawingRenderController = __decorate([
3931
3923
  //#endregion
3932
3924
  //#region src/controllers/sheet-cell-image.controller.ts
3933
3925
  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]];
3926
+ var _documentData$drawing, _documentData$drawing2;
3927
+ const documentData = cell === null || cell === void 0 ? void 0 : cell.p;
3928
+ 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;
3929
+ const image = drawingId ? documentData === null || documentData === void 0 || (_documentData$drawing2 = documentData.drawings) === null || _documentData$drawing2 === void 0 ? void 0 : _documentData$drawing2[drawingId] : void 0;
3930
+ if (image && documentData) {
3937
3931
  const imageSize = getDrawingSizeByCell(injector, {
3938
3932
  unitId: location.unitId,
3939
3933
  subUnitId: location.subUnitId,
@@ -3949,8 +3943,8 @@ function resizeImageByCell(injector, location, cell) {
3949
3943
  image.transform.top = 0;
3950
3944
  image.docTransform.positionH.posOffset = 0;
3951
3945
  image.docTransform.positionV.posOffset = 0;
3952
- cell.p.documentStyle.pageSize.width = Infinity;
3953
- cell.p.documentStyle.pageSize.height = Infinity;
3946
+ documentData.documentStyle.pageSize.width = Infinity;
3947
+ documentData.documentStyle.pageSize.height = Infinity;
3954
3948
  return true;
3955
3949
  }
3956
3950
  }
@@ -3982,8 +3976,7 @@ let SheetCellImageController = class SheetCellImageController extends _univerjs_
3982
3976
  effect: _univerjs_core.InterceptorEffectEnum.Style,
3983
3977
  priority: _univerjs_sheets.InterceptCellContentPriority.CELL_IMAGE,
3984
3978
  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)) {
3979
+ if (cell && (0, _univerjs_sheets.isCellImage)(cell.p)) {
3987
3980
  if (cell === pos.rawData) cell = { ...pos.rawData };
3988
3981
  if (!cell.interceptorStyle) cell.interceptorStyle = {};
3989
3982
  cell.interceptorStyle.tr = { a: 0 };
@@ -4083,10 +4076,9 @@ let SheetCellImageCopyPasteController = class SheetCellImageCopyPasteController
4083
4076
  _initDocImageCopyPasteHooks() {
4084
4077
  this.disposeWithMe(this._commandService.beforeCommandExecuted((commandInfo) => {
4085
4078
  if (commandInfo.id === _univerjs_docs_ui.InnerPasteCommand.id) {
4086
- var _doc$drawings;
4087
4079
  const { doc } = commandInfo.params;
4088
4080
  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;
4081
+ if (currentDoc == null || !Object.keys(doc.drawings ?? {}).length) return;
4090
4082
  const docUnitId = currentDoc.getUnitId();
4091
4083
  if (DISABLE_UNITS.includes(docUnitId)) {
4092
4084
  var _currentDoc$getBody;
@@ -4153,12 +4145,11 @@ let SheetDrawingActiveRenderController = class SheetDrawingActiveRenderControlle
4153
4145
  setTimeout(() => {
4154
4146
  const drawingMap = this._drawingManagerService.drawingManagerData;
4155
4147
  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 : {};
4148
+ Object.keys(drawingMap ?? {}).forEach((unitId) => {
4149
+ const subUnitMap = drawingMap[unitId] ?? {};
4159
4150
  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 : {};
4151
+ var _subUnitMap$subUnitId;
4152
+ const drawingData = ((_subUnitMap$subUnitId = subUnitMap[subUnitId]) === null || _subUnitMap$subUnitId === void 0 ? void 0 : _subUnitMap$subUnitId.data) ?? {};
4162
4153
  Object.keys(drawingData).forEach((drawingId) => {
4163
4154
  if (unitId === selfUnitId) removeDrawings.push(drawingData[drawingId]);
4164
4155
  });
@@ -4174,13 +4165,12 @@ let SheetDrawingActiveRenderController = class SheetDrawingActiveRenderControlle
4174
4165
  const drawingMap = this._drawingManagerService.drawingManagerData;
4175
4166
  const insertDrawings = [];
4176
4167
  const removeDrawings = [];
4177
- Object.keys(drawingMap !== null && drawingMap !== void 0 ? drawingMap : {}).forEach((unitId) => {
4178
- var _drawingMap$unitId2;
4168
+ Object.keys(drawingMap ?? {}).forEach((unitId) => {
4179
4169
  if (unitId !== showUnitId) return;
4180
- const subUnitMap = (_drawingMap$unitId2 = drawingMap[unitId]) !== null && _drawingMap$unitId2 !== void 0 ? _drawingMap$unitId2 : {};
4170
+ const subUnitMap = drawingMap[unitId] ?? {};
4181
4171
  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 : {};
4172
+ var _subUnitMap$subUnitId2;
4173
+ const drawingData = ((_subUnitMap$subUnitId2 = subUnitMap[subUnitId]) === null || _subUnitMap$subUnitId2 === void 0 ? void 0 : _subUnitMap$subUnitId2.data) ?? {};
4184
4174
  Object.keys(drawingData).forEach((drawingId) => {
4185
4175
  if (unitId === showUnitId && subUnitId === showSubunitId) {
4186
4176
  const drawing = drawingData[drawingId];
@@ -4404,7 +4394,6 @@ let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController ex
4404
4394
  subUnitId,
4405
4395
  isCut: copyType === _univerjs_sheets_ui.COPY_TYPE.CUT,
4406
4396
  getTransform: (transform, sheetTransform) => {
4407
- var _transformToDrawingPo, _transformToAxisAlign;
4408
4397
  const pasteRect = (0, _univerjs_sheets.attachRangeWithCoord)(pasteToSkeleton, {
4409
4398
  startRow: pasteRange.startRow,
4410
4399
  endRow: pasteRange.endRow,
@@ -4418,8 +4407,8 @@ let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController ex
4418
4407
  };
4419
4408
  return {
4420
4409
  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
4410
+ sheetTransform: (0, _univerjs_sheets_drawing.transformToDrawingPosition)(newTransform, pasteToSkeleton) ?? sheetTransform,
4411
+ axisAlignSheetTransform: (0, _univerjs_sheets_drawing.transformToAxisAlignPosition)(newTransform, pasteToSkeleton) ?? sheetTransform
4423
4412
  };
4424
4413
  }
4425
4414
  });
@@ -4550,11 +4539,10 @@ let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController ex
4550
4539
  unitId: toUnitId,
4551
4540
  subUnitId: toSubUnitId,
4552
4541
  getTransform: (transform, sheetTransform) => {
4553
- var _transform$left, _transform$top, _transformToAxisAlign2;
4554
4542
  const newTransform = {
4555
4543
  ...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
4544
+ left: ((transform === null || transform === void 0 ? void 0 : transform.left) ?? 0) + leftOffset,
4545
+ top: ((transform === null || transform === void 0 ? void 0 : transform.top) ?? 0) + topOffset
4558
4546
  };
4559
4547
  return {
4560
4548
  transform: newTransform,
@@ -4571,7 +4559,7 @@ let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController ex
4571
4559
  column: sheetTransform.from.column + columnOffset
4572
4560
  }
4573
4561
  },
4574
- axisAlignSheetTransform: (_transformToAxisAlign2 = (0, _univerjs_sheets_drawing.transformToAxisAlignPosition)(newTransform, toSkeleton)) !== null && _transformToAxisAlign2 !== void 0 ? _transformToAxisAlign2 : sheetTransform
4562
+ axisAlignSheetTransform: (0, _univerjs_sheets_drawing.transformToAxisAlignPosition)(newTransform, toSkeleton) ?? sheetTransform
4575
4563
  };
4576
4564
  },
4577
4565
  isCut: copyType === _univerjs_sheets_ui.COPY_TYPE.CUT
@@ -4795,6 +4783,10 @@ let SheetDrawingPermissionController = class SheetDrawingPermissionController ex
4795
4783
  const { drawings } = command.params;
4796
4784
  unitId = drawings === null || drawings === void 0 || (_drawings$ = drawings[0]) === null || _drawings$ === void 0 ? void 0 : _drawings$.unitId;
4797
4785
  subUnitId = drawings === null || drawings === void 0 || (_drawings$2 = drawings[0]) === null || _drawings$2 === void 0 ? void 0 : _drawings$2.subUnitId;
4786
+ } else if (command.id === _univerjs_sheets_drawing.SetSheetDrawingPlacementCommand.id) {
4787
+ const target = getPlacementCommandTarget(command.params);
4788
+ unitId = target.unitId;
4789
+ subUnitId = target.subUnitId;
4798
4790
  } else if (command.id === _univerjs_sheets_drawing.SetDrawingArrangeCommand.id) {
4799
4791
  const params = command.params;
4800
4792
  unitId = params.unitId;
@@ -4818,16 +4810,23 @@ SheetDrawingPermissionController = __decorate([
4818
4810
  __decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetPermissionCheckController)),
4819
4811
  __decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_sheets_drawing.ISheetDrawingService))
4820
4812
  ], SheetDrawingPermissionController);
4813
+ function getPlacementCommandTarget(params) {
4814
+ if (!params) return {};
4815
+ return {
4816
+ unitId: "unitId" in params && typeof params.unitId === "string" ? params.unitId : void 0,
4817
+ subUnitId: "subUnitId" in params && typeof params.subUnitId === "string" ? params.subUnitId : void 0
4818
+ };
4819
+ }
4821
4820
 
4822
4821
  //#endregion
4823
4822
  //#region src/views/PrintingFloatDom.tsx
4824
4823
  function createPrintingFloatDom(info, scene, skeleton, worksheet) {
4825
4824
  const { width, height, angle, left, top } = info.transform;
4826
4825
  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)
4826
+ left: left ?? 0,
4827
+ right: (left ?? 0) + (width ?? 0),
4828
+ top: top ?? 0,
4829
+ bottom: (top ?? 0) + (height ?? 0)
4831
4830
  }, scene, skeleton, worksheet, void 0, true);
4832
4831
  const { scaleX, scaleY } = scene.getAncestorScale();
4833
4832
  const domPos = {
@@ -5329,7 +5328,7 @@ let DrawingPopupMenuController = class DrawingPopupMenuController extends _unive
5329
5328
  const menus = this._canvasPopManagerService.getFeatureMenu(unitId, subUnitId, drawingId, drawingType);
5330
5329
  singletonPopupDisposer = this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(object, {
5331
5330
  componentKey: _univerjs_drawing_ui.COMPONENT_IMAGE_POPUP_MENU,
5332
- direction: "horizontal",
5331
+ direction: this._localeService.getDirection() === "rtl" ? "left" : "horizontal",
5333
5332
  offset: [2, 0],
5334
5333
  extraProps: { menuItems: menus || this._getImageMenuItems(unitId, subUnitId, drawingId, drawingType) }
5335
5334
  }));
@@ -5623,7 +5622,7 @@ _defineProperty(UniverSheetsDrawingUIPlugin, "pluginName", "SHEET_IMAGE_UI_PLUGI
5623
5622
  _defineProperty(UniverSheetsDrawingUIPlugin, "packageName", name);
5624
5623
  _defineProperty(UniverSheetsDrawingUIPlugin, "version", version);
5625
5624
  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),
5625
+ (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
5626
  __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
5628
5627
  __decorateParam(2, _univerjs_engine_render.IRenderManagerService),
5629
5628
  __decorateParam(3, _univerjs_core.IConfigService)