@univerjs/sheets-drawing-ui 1.4.0 → 1.5.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/es/index.js CHANGED
@@ -1,14 +1,14 @@
1
- import { BooleanNumber, BuildTextUtils, CommandType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Direction, Disposable, DisposableCollection, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, FOCUSING_PANEL_EDITOR, FOCUSING_SHAPE_TEXT_EDITOR, FOCUSING_SHEET, ICommandService, IConfigService, IContextService, IImageIoService, ILogService, IPermissionService, IURLImageService, IUndoRedoService, IUniverInstanceService, ImageCacheMap, ImageSourceType, ImageUploadStatusType, Inject, Injector, InterceptorEffectEnum, LifecycleService, LifecycleStages, LocaleService, ObjectMatrix, Optional, Plugin, PositionedObjectLayoutType, RxDisposable, Tools, UniverInstanceType, UserManagerService, WrapTextType, createDocumentModelWithStyle, createIdentifier, fromEventSubject, generateRandomId, merge, mergeOverrideWithDependencies, registerDependencies, sequenceExecute, toDisposable, touchDependencies } from "@univerjs/core";
2
- import { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SetSheetDrawingPlacementCommand, SetWorksheetBackgroundImageCommand, SetWorksheetBackgroundImageMutation, SheetDrawingAnchorType, UniverSheetsDrawingPlugin, drawingPositionToTransform, getSheetDrawingPlacement, refreshSheetDrawingPlacement, transformToAxisAlignPosition, transformToDrawingPosition } from "@univerjs/sheets-drawing";
1
+ import { BooleanNumber, BuildTextUtils, CommandType, CustomCommandExecutionError, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Direction, Disposable, DisposableCollection, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, FOCUSING_PANEL_EDITOR, FOCUSING_SHAPE_TEXT_EDITOR, FOCUSING_SHEET, ICommandService, IConfigService, IContextService, IImageIoService, ILogService, IPermissionService, IURLImageService, IUndoRedoService, IUniverInstanceService, ImageCacheMap, ImageSourceType, ImageUploadStatusType, Inject, Injector, InterceptorEffectEnum, LifecycleService, LifecycleStages, LocaleService, ObjectMatrix, Optional, Plugin, PositionedObjectLayoutType, RxDisposable, SheetTypes, Tools, UniverInstanceType, UserManagerService, WrapTextType, createDocumentModelWithStyle, createIdentifier, fromEventSubject, generateRandomId, merge, mergeOverrideWithDependencies, registerDependencies, sequenceExecute, toDisposable, touchDependencies } from "@univerjs/core";
2
+ import { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SetSheetDrawingPlacementCommand, SetWorksheetBackgroundImageCommand, SetWorksheetBackgroundImageMutation, SheetDrawingAnchorType, UniverSheetsDrawingPlugin, applySheetDrawingPlacement, drawingPositionToTransform, getSheetDrawingPlacement, refreshSheetDrawingPlacement, transformDrawingsToChartSheet, transformToAxisAlignPosition, transformToDrawingPosition } from "@univerjs/sheets-drawing";
3
3
  import { CURSOR_TYPE, DEFAULT_TRANSFORMER_CONFIG, DRAWING_OBJECT_LAYER_INDEX, IRenderManagerService, Image, ObjectType, Rect, SHEET_EXTENSION_TYPE, SHEET_VIEWPORT_KEY, SheetExtension, UniverRenderEnginePlugin, Vector2, getCurrentTypeOfRenderer, getGroupState, transformObjectOutOfGroup } from "@univerjs/engine-render";
4
4
  import { Button, Checkbox, CheckboxGroup, DropdownMenu, FormLayout, Input, MessageType, MobileSelect, Radio, RadioGroup, Select, borderClassName, clsx, render, unmount } from "@univerjs/design";
5
5
  import { buildDocTransform, docDrawingPositionToTransform } from "@univerjs/docs";
6
6
  import { DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_WIDTH_LIMIT, IDrawingManagerService, SetDrawingSelectedOperation, UniverDrawingPlugin, getDrawingImageAllowSize, getDrawingShapeKeyByDrawingSearch, getImageSize, normalizeImageOpacity } from "@univerjs/drawing";
7
- import { COMMAND_LISTENER_SKELETON_CHANGE, IAutoFillService, INTERCEPTOR_POINT, InterceptCellContentPriority, RangeProtectionPermissionEditPoint, SetFrozenMutation, SetRangeValuesCommand, SetSelectionsOperation, SetWorksheetActiveOperation, SetWorksheetRowAutoHeightMutation, SheetInterceptorService, SheetPermissionCheckController, SheetSkeletonService, SheetsSelectionsService, UniverSheetsPlugin, WorkbookEditablePermission, WorkbookRenameSheetPermission, WorkbookViewPermission, WorksheetEditPermission, WorksheetViewPermission, attachRangeWithCoord, discreteRangeToRange, getSheetCommandTarget, isCellImage } from "@univerjs/sheets";
8
- import { COPY_TYPE, EditingRenderController, HoverManagerService, IEditorBridgeService, ISheetClipboardService, ISheetSelectionRenderService, PREDEFINED_HOOK_NAME_PASTE, SetCellEditVisibleOperation, SetScrollOperation, SetZoomRatioOperation, SheetCanvasPopManagerService, SheetPrintInterceptorService, SheetSkeletonManagerService, UniverSheetsMobileUIPlugin, UniverSheetsUIPlugin, getCurrentRangeDisable$, useHighlightRange, virtualizeDiscreteRanges } from "@univerjs/sheets-ui";
7
+ import { COMMAND_LISTENER_SKELETON_CHANGE, IAutoFillService, INTERCEPTOR_POINT, InterceptCellContentPriority, RangeProtectionPermissionEditPoint, SetFrozenMutation, SetRangeValuesCommand, SetSelectionsOperation, SetWorksheetActiveOperation, SetWorksheetRowAutoHeightMutation, SheetInterceptorService, SheetPermissionCheckController, SheetSkeletonService, SheetsSelectionsService, UniverSheetsPlugin, WorkbookCopyPermission, WorkbookEditablePermission, WorkbookRenameSheetPermission, WorkbookViewPermission, WorksheetCopyPermission, WorksheetEditPermission, WorksheetViewPermission, attachRangeWithCoord, discreteRangeToRange, getSheetCommandTarget, isCellImage } from "@univerjs/sheets";
8
+ import { COPY_TYPE, EditingRenderController, HoverManagerService, IEditorBridgeService, ISheetClipboardService, ISheetSelectionRenderService, PREDEFINED_HOOK_NAME_PASTE, SHEET_VIEW_KEY, SetCellEditVisibleOperation, SetScrollOperation, SetZoomRatioOperation, SheetCanvasPopManagerService, SheetPasteCommand, SheetPrintInterceptorService, SheetSkeletonManagerService, UniverSheetsMobileUIPlugin, UniverSheetsUIPlugin, deriveStateFromActiveSheet$, getCurrentRangeDisable$, useHighlightRange, virtualizeDiscreteRanges } from "@univerjs/sheets-ui";
9
9
  import { CanvasFloatDomPreviewService, CanvasFloatDomService, ComponentManager, ContextMenuGroup, ContextMenuPosition, FloatingObjectToolbarPosition, IClipboardInterfaceService, IContextMenuService, IDialogService, ILayoutService, ILocalFileService, IMenuManagerService, IMessageService, IShortcutService, ISidebarService, IconManager, KeyCode, MenuItemType, PrintFloatDomSingle, RibbonDataGroup, RibbonInsertGroup, RibbonPosition, RibbonViewGroup, UndoRedoGroupService, UniverMobileUIPlugin, connectInjector, getMenuHiddenObservable, useDependency, useObservable } from "@univerjs/ui";
10
10
  import { COMPONENT_IMAGE_POPUP_MENU, COMPONENT_MOBILE_IMAGE_POPUP_MENU, DrawingCommonPanel, DrawingRenderService, ImageCropperObject, ImageResetSizeOperation, OleUIService, OpenImageCropOperation, UniverDrawingMobileUIPlugin, UniverDrawingUIPlugin, createOlePreviewViewer, disposeDrawingRenderObject, insertGroupObject, registerOlePreviewRenderer } from "@univerjs/drawing-ui";
11
- import { BehaviorSubject, EMPTY, Observable, Subject, combineLatest, distinctUntilChanged, filter, map, of, switchMap, take, takeUntil, tap, throttleTime, timer } from "rxjs";
11
+ import { BehaviorSubject, EMPTY, Observable, Subject, combineLatest, distinctUntilChanged, filter, map, of, startWith, switchMap, take, takeUntil, tap, throttleTime, timer } from "rxjs";
12
12
  import { DocDrawingController, UniverDocsDrawingPlugin } from "@univerjs/docs-drawing";
13
13
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
14
14
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -422,7 +422,7 @@ function readUint32Be(bytes, offset) {
422
422
  return ((bytes[offset] ?? 0) << 24 >>> 0 | (bytes[offset + 1] ?? 0) << 16 | (bytes[offset + 2] ?? 0) << 8 | (bytes[offset + 3] ?? 0)) >>> 0;
423
423
  }
424
424
 
425
- // \0@oxc-project+runtime@0.156.0/helpers/esm/typeof.js
425
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
426
426
  function _typeof(o) {
427
427
  "@babel/helpers - typeof";
428
428
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -432,25 +432,25 @@ function _typeof(o) {
432
432
  }, _typeof(o);
433
433
  }
434
434
 
435
- // \0@oxc-project+runtime@0.156.0/helpers/esm/toPrimitive.js
436
- function toPrimitive(t, r) {
435
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
436
+ function toPrimitive(t, e) {
437
437
  if ("object" != _typeof(t) || !t) return t;
438
- var e = t[Symbol.toPrimitive];
439
- if (void 0 !== e) {
440
- var i = e.call(t, r || "default");
438
+ var r;
439
+ if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
440
+ var i = r.call(t, e || "default");
441
441
  if ("object" != _typeof(i)) return i;
442
442
  throw new TypeError("@@toPrimitive must return a primitive value.");
443
443
  }
444
- return ("string" === r ? String : Number)(t);
444
+ return ("string" === e ? String : Number)(t);
445
445
  }
446
446
 
447
- // \0@oxc-project+runtime@0.156.0/helpers/esm/toPropertyKey.js
447
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
448
448
  function toPropertyKey(t) {
449
449
  var i = toPrimitive(t, "string");
450
450
  return "symbol" == _typeof(i) ? i : i + "";
451
451
  }
452
452
 
453
- // \0@oxc-project+runtime@0.156.0/helpers/esm/defineProperty.js
453
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
454
454
  function _defineProperty(e, r, t) {
455
455
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
456
456
  value: t,
@@ -460,14 +460,14 @@ function _defineProperty(e, r, t) {
460
460
  }) : e[r] = t, e;
461
461
  }
462
462
 
463
- // \0@oxc-project+runtime@0.156.0/helpers/esm/decorateParam.js
463
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
464
464
  function __decorateParam(paramIndex, decorator) {
465
465
  return function(target, key) {
466
466
  decorator(target, key, paramIndex);
467
467
  };
468
468
  }
469
469
 
470
- // \0@oxc-project+runtime@0.156.0/helpers/esm/decorate.js
470
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
471
471
  function __decorate(decorators, target, key, desc) {
472
472
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
473
473
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -518,12 +518,11 @@ function getDrawingSizeByCell(accessor, location, originImageWidth, originImageH
518
518
  };
519
519
  }
520
520
  let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Disposable {
521
- constructor(_context, _commandService, _sheetInterceptorService, _selectionRenderService, _imageIoService, _fileOpenerService, _sheetDrawingService, _drawingManagerService, _contextService, _messageService, _localeService, selectionManagerService, _sheetSkeletonService, _injector, _urlImageService) {
521
+ constructor(_context, _commandService, _sheetInterceptorService, _imageIoService, _fileOpenerService, _sheetDrawingService, _drawingManagerService, _contextService, _messageService, _localeService, selectionManagerService, _sheetSkeletonService, _injector, _urlImageService) {
522
522
  super();
523
523
  this._context = _context;
524
524
  this._commandService = _commandService;
525
525
  this._sheetInterceptorService = _sheetInterceptorService;
526
- this._selectionRenderService = _selectionRenderService;
527
526
  this._imageIoService = _imageIoService;
528
527
  this._fileOpenerService = _fileOpenerService;
529
528
  this._sheetDrawingService = _sheetDrawingService;
@@ -542,6 +541,8 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Di
542
541
  this._focusDrawingListener();
543
542
  }
544
543
  async insertFloatImage() {
544
+ const target = this._captureImageTarget();
545
+ if (!target) return false;
545
546
  const files = await this._fileOpenerService.openFile({
546
547
  multiple: true,
547
548
  accept: DRAWING_IMAGE_ALLOW_IMAGE_LIST.map((image) => `.${image.replace("image/", "")}`).join(",")
@@ -554,18 +555,19 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Di
554
555
  });
555
556
  return false;
556
557
  } else if (fileLength === 0) return false;
557
- files.forEach(async (file) => await this.insertFloatImageByFile(file));
558
- return true;
558
+ return (await Promise.all(files.map((file) => this._insertFloatImage(file, target).catch((error) => {
559
+ this._injector.get(ILogService).error(error);
560
+ return false;
561
+ })))).every(Boolean);
559
562
  }
560
563
  async insertCellImage() {
564
+ const target = this._captureCellImageTarget();
565
+ if (!target) return false;
561
566
  const file = (await this._fileOpenerService.openFile({
562
567
  multiple: false,
563
568
  accept: DRAWING_IMAGE_ALLOW_IMAGE_LIST.map((image) => `.${image.replace("image/", "")}`).join(",")
564
569
  }))[0];
565
- if (file) {
566
- await this._insertCellImage(file);
567
- return true;
568
- }
570
+ if (file) return this._insertCellImage(file, void 0, target);
569
571
  return false;
570
572
  }
571
573
  async setWorksheetBackgroundImage(files) {
@@ -610,6 +612,15 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Di
610
612
  return this._insertCellImage(file, location);
611
613
  }
612
614
  async insertFloatImageByFile(file) {
615
+ const target = this._captureImageTarget();
616
+ if (!target) return false;
617
+ return this._insertFloatImage(file, target).catch((error) => {
618
+ this._injector.get(ILogService).error(error);
619
+ return false;
620
+ });
621
+ }
622
+ async _insertFloatImage(file, target) {
623
+ if (!this._isImageTargetValid(target)) return false;
613
624
  let imageParam;
614
625
  try {
615
626
  imageParam = await this._imageIoService.saveImage(file);
@@ -628,11 +639,14 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Di
628
639
  content: this._localeService.t("sheets-drawing-ui.update-status.invalidImage")
629
640
  });
630
641
  }
631
- if (imageParam == null) return;
632
- const { unitId, subUnitId } = this._getUnitInfo();
642
+ if (imageParam == null || !this._isImageTargetValid(target)) return false;
643
+ const { unitId, subUnitId } = target;
633
644
  const { imageId, imageSourceType, source, base64Cache } = imageParam;
634
- const { width, height, image } = await getImageSize(base64Cache || "");
635
- const { width: sceneWidth, height: sceneHeight } = this._context.scene;
645
+ const imageSize = await getImageSize(base64Cache || "").catch(() => null);
646
+ if (!imageSize) return false;
647
+ const { width, height, image } = imageSize;
648
+ if (!this._isImageTargetValid(target) || !Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0) return false;
649
+ const { sceneWidth, sceneHeight } = target;
636
650
  this._imageIoService.addImageSourceCache(source, imageSourceType, image);
637
651
  let scale = 1;
638
652
  if (width > DRAWING_IMAGE_WIDTH_LIMIT || height > DRAWING_IMAGE_HEIGHT_LIMIT) {
@@ -640,13 +654,51 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Di
640
654
  const scaleHeight = DRAWING_IMAGE_HEIGHT_LIMIT / height;
641
655
  scale = Math.min(scaleWidth, scaleHeight);
642
656
  }
657
+ if (target.worksheet.getConfig().type === SheetTypes.CHART) {
658
+ const bounds = this._getChartImageBounds(target.render);
659
+ if (!bounds) return false;
660
+ const marker = {
661
+ row: 0,
662
+ column: 0,
663
+ rowOffset: 0,
664
+ columnOffset: 0
665
+ };
666
+ const placed = transformDrawingsToChartSheet([{
667
+ unitId,
668
+ subUnitId,
669
+ drawingId: imageId,
670
+ drawingType: DrawingTypeEnum.DRAWING_IMAGE,
671
+ imageSourceType,
672
+ source,
673
+ transform: {
674
+ left: 0,
675
+ top: 0,
676
+ width: width * scale,
677
+ height: height * scale
678
+ },
679
+ sheetTransform: {
680
+ from: marker,
681
+ to: marker
682
+ },
683
+ axisAlignSheetTransform: {
684
+ from: marker,
685
+ to: marker
686
+ }
687
+ }], bounds, target.worksheet.getConfig().rightToLeft === BooleanNumber.TRUE);
688
+ if (!(placed === null || placed === void 0 ? void 0 : placed.length)) return false;
689
+ const [drawing] = placed;
690
+ return this._commandService.executeCommand(InsertSheetDrawingCommand.id, {
691
+ unitId,
692
+ drawings: [drawing]
693
+ });
694
+ }
643
695
  const sheetSkeletonParam = this._sheetSkeletonService.getSkeletonParam(unitId, subUnitId);
644
- if (!sheetSkeletonParam) return;
696
+ if (!sheetSkeletonParam) return false;
645
697
  const { skeleton } = sheetSkeletonParam;
646
- const sheetTransform = this._getImagePosition(width * scale, height * scale, sceneWidth, sceneHeight, skeleton);
647
- if (!sheetTransform) return;
698
+ const sheetTransform = this._getImagePosition(width * scale, height * scale, sceneWidth, sceneHeight, skeleton, target.range);
699
+ if (!sheetTransform) return false;
648
700
  const newTransform = drawingPositionToTransform(sheetTransform, sheetSkeletonParam);
649
- if (!newTransform) return;
701
+ if (!newTransform) return false;
650
702
  const sheetDrawingParam = {
651
703
  unitId,
652
704
  subUnitId,
@@ -663,7 +715,9 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Di
663
715
  drawings: [sheetDrawingParam]
664
716
  });
665
717
  }
666
- async _insertCellImage(file, location) {
718
+ async _insertCellImage(file, location, capturedTarget) {
719
+ const target = capturedTarget ?? this._captureCellImageTarget(location);
720
+ if (!target || !this._isImageTargetValid(target)) return false;
667
721
  let imageParam;
668
722
  try {
669
723
  imageParam = await this._imageIoService.saveImage(file);
@@ -686,21 +740,11 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Di
686
740
  const { imageId, imageSourceType, source, base64Cache } = imageParam;
687
741
  const { width, height, image } = await getImageSize(base64Cache || "");
688
742
  this._imageIoService.addImageSourceCache(source, imageSourceType, image);
689
- const selection = this._workbookSelections.getCurrentLastSelection();
690
- if (!selection) return false;
691
- let row = selection.primary.actualRow;
692
- let col = selection.primary.actualColumn;
693
- if (selection.primary.isMerged) {
694
- row = selection.primary.startRow;
695
- col = selection.primary.startColumn;
696
- }
743
+ if (!this._isImageTargetValid(target)) return false;
744
+ const cellLocation = target.location;
745
+ const { row, col } = cellLocation;
697
746
  const docDataModel = createDocumentModelWithStyle("", {});
698
- const imageSize = getDrawingSizeByCell(this._injector, {
699
- unitId: this._context.unitId,
700
- subUnitId: this._context.unit.getActiveSheet().getSheetId(),
701
- row,
702
- col
703
- }, width, height, 0);
747
+ const imageSize = getDrawingSizeByCell(this._injector, cellLocation, width, height, 0);
704
748
  if (!imageSize) return false;
705
749
  const docTransform = buildDocTransform(imageSize.width, imageSize.height);
706
750
  const docDrawingParam = {
@@ -734,17 +778,25 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Di
734
778
  if (jsonXActions) {
735
779
  docDataModel.apply(jsonXActions);
736
780
  return this._commandService.syncExecuteCommand(SetRangeValuesCommand.id, {
737
- value: { [(location === null || location === void 0 ? void 0 : location.row) ?? row]: { [(location === null || location === void 0 ? void 0 : location.col) ?? col]: {
781
+ value: { [row]: { [col]: {
738
782
  p: docDataModel.getSnapshot(),
739
783
  t: 1
740
784
  } } },
741
- unitId: location === null || location === void 0 ? void 0 : location.unitId,
742
- subUnitId: location === null || location === void 0 ? void 0 : location.subUnitId
785
+ unitId: target.unitId,
786
+ subUnitId: target.subUnitId,
787
+ range: {
788
+ startRow: row,
789
+ endRow: row,
790
+ startColumn: col,
791
+ endColumn: col
792
+ }
743
793
  });
744
794
  }
745
795
  return false;
746
796
  }
747
797
  async insertCellImageByUrl(url, location) {
798
+ const target = this._captureCellImageTarget(location);
799
+ if (!target) return false;
748
800
  let src = url;
749
801
  try {
750
802
  src = await this._urlImageService.getImage(url);
@@ -753,15 +805,10 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Di
753
805
  }
754
806
  const { width, height, image } = await getImageSize(src || "");
755
807
  this._imageIoService.addImageSourceCache(url, ImageSourceType.URL, image);
756
- const selection = this._workbookSelections.getCurrentLastSelection();
757
- if (!selection) return false;
808
+ if (!this._isImageTargetValid(target)) return false;
809
+ const cellLocation = target.location;
758
810
  const docDataModel = createDocumentModelWithStyle("", {});
759
- const imageSize = getDrawingSizeByCell(this._injector, {
760
- unitId: this._context.unitId,
761
- subUnitId: this._context.unit.getActiveSheet().getSheetId(),
762
- row: selection.primary.actualRow,
763
- col: selection.primary.actualColumn
764
- }, width, height, 0);
811
+ const imageSize = getDrawingSizeByCell(this._injector, cellLocation, width, height, 0);
765
812
  if (!imageSize) return false;
766
813
  const docTransform = buildDocTransform(imageSize.width, imageSize.height);
767
814
  const docDrawingParam = {
@@ -795,16 +842,87 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Di
795
842
  if (jsonXActions) {
796
843
  docDataModel.apply(jsonXActions);
797
844
  return this._commandService.syncExecuteCommand(SetRangeValuesCommand.id, {
798
- 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]: {
845
+ value: { [cellLocation.row]: { [cellLocation.col]: {
799
846
  p: docDataModel.getSnapshot(),
800
847
  t: 1
801
848
  } } },
802
- unitId: location === null || location === void 0 ? void 0 : location.unitId,
803
- subUnitId: location === null || location === void 0 ? void 0 : location.subUnitId
849
+ unitId: target.unitId,
850
+ subUnitId: target.subUnitId,
851
+ range: {
852
+ startRow: cellLocation.row,
853
+ endRow: cellLocation.row,
854
+ startColumn: cellLocation.col,
855
+ endColumn: cellLocation.col
856
+ }
804
857
  });
805
858
  }
806
859
  return false;
807
860
  }
861
+ _captureImageTarget(location) {
862
+ if (this._disposed) return null;
863
+ const instances = this._injector.get(IUniverInstanceService);
864
+ const host = getSheetCommandTarget(instances, location ?? { unitId: this._context.unitId });
865
+ const render = host && this._injector.get(IRenderManagerService).getRenderUnitById(host.unitId);
866
+ const sheetType = (host === null || host === void 0 ? void 0 : host.worksheet.getConfig().type) ?? SheetTypes.GRID;
867
+ if (!host || !render || sheetType !== SheetTypes.GRID && sheetType !== SheetTypes.CHART) return null;
868
+ const frame = render.components.get(SHEET_VIEW_KEY.CHART_PAGE);
869
+ const pageFrame = frame instanceof Rect ? frame : void 0;
870
+ const selections = this._workbookSelections.getCurrentSelections();
871
+ const range = (selections === null || selections === void 0 ? void 0 : selections.length) ? { ...selections[selections.length - 1].range } : {
872
+ startRow: 0,
873
+ endRow: 0,
874
+ startColumn: 0,
875
+ endColumn: 0
876
+ };
877
+ const target = {
878
+ ...host,
879
+ render,
880
+ location,
881
+ pageFrame,
882
+ range,
883
+ sceneWidth: render.scene.width,
884
+ sceneHeight: render.scene.height
885
+ };
886
+ return this._isImageTargetValid(target) ? target : null;
887
+ }
888
+ _captureCellImageTarget(location) {
889
+ const target = this._captureImageTarget(location);
890
+ if (!target || (target.worksheet.getConfig().type ?? SheetTypes.GRID) !== SheetTypes.GRID) return null;
891
+ if (!location) {
892
+ const selection = this._workbookSelections.getCurrentLastSelection();
893
+ if (!selection) return null;
894
+ const { primary } = selection;
895
+ target.location = {
896
+ unitId: target.unitId,
897
+ subUnitId: target.subUnitId,
898
+ row: primary.isMerged ? primary.startRow : primary.actualRow,
899
+ col: primary.isMerged ? primary.startColumn : primary.actualColumn
900
+ };
901
+ }
902
+ return target;
903
+ }
904
+ _isImageTargetValid(target) {
905
+ if (this._disposed) return false;
906
+ const instances = this._injector.get(IUniverInstanceService);
907
+ const { workbook, worksheet, unitId, subUnitId, render } = target;
908
+ if (instances.getUnit(unitId, UniverInstanceType.UNIVER_SHEET) !== workbook || workbook.getSheetBySheetId(subUnitId) !== worksheet || render.isDisposed() || this._injector.get(IRenderManagerService).getRenderUnitById(unitId) !== render) return false;
909
+ return worksheet.getConfig().type !== SheetTypes.CHART || target.pageFrame === render.components.get(SHEET_VIEW_KEY.CHART_PAGE) && Boolean(this._getChartImageBounds(render));
910
+ }
911
+ _getChartImageBounds(render) {
912
+ const frame = render.components.get(SHEET_VIEW_KEY.CHART_PAGE);
913
+ if (!frame || ![
914
+ frame.left,
915
+ frame.top,
916
+ frame.width,
917
+ frame.height
918
+ ].every(Number.isFinite) || frame.width <= 0 || frame.height <= 0) return null;
919
+ return {
920
+ left: frame.left,
921
+ top: frame.top,
922
+ width: frame.width,
923
+ height: frame.height
924
+ };
925
+ }
808
926
  _getUnitInfo() {
809
927
  const workbook = this._context.unit;
810
928
  const worksheet = workbook.getActiveSheet();
@@ -813,15 +931,7 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Di
813
931
  subUnitId: worksheet.getSheetId()
814
932
  };
815
933
  }
816
- _getImagePosition(imageWidth, imageHeight, sceneWidth, sceneHeight, skeleton) {
817
- const selections = this._workbookSelections.getCurrentSelections();
818
- let range = {
819
- startRow: 0,
820
- endRow: 0,
821
- startColumn: 0,
822
- endColumn: 0
823
- };
824
- if (selections && selections.length > 0) range = selections[selections.length - 1].range;
934
+ _getImagePosition(imageWidth, imageHeight, sceneWidth, sceneHeight, skeleton, range) {
825
935
  const rangeWithCoord = attachRangeWithCoord(skeleton, range);
826
936
  if (rangeWithCoord == null) return;
827
937
  let { startColumn, startRow, startX, startY } = rangeWithCoord;
@@ -843,7 +953,10 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Di
843
953
  isChangeStart = true;
844
954
  }
845
955
  if (isChangeStart) {
846
- const newCoord = this._selectionRenderService.getCellWithCoordByOffset(startX, startY);
956
+ const newCoord = skeleton.getCellWithCoordByOffset(startX, startY, 1, 1, {
957
+ x: 0,
958
+ y: 0
959
+ });
847
960
  if (newCoord == null) return;
848
961
  startX = newCoord.startX;
849
962
  startY = newCoord.startY;
@@ -856,7 +969,10 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Di
856
969
  row: startRow,
857
970
  rowOffset: 0
858
971
  };
859
- const endSelectionCell = this._selectionRenderService.getCellWithCoordByOffset(startX + imageWidth, startY + imageHeight);
972
+ const endSelectionCell = skeleton.getCellWithCoordByOffset(startX + imageWidth, startY + imageHeight, 1, 1, {
973
+ x: 0,
974
+ y: 0
975
+ });
860
976
  if (endSelectionCell == null) return;
861
977
  return {
862
978
  from,
@@ -886,14 +1002,27 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Di
886
1002
  params.forEach((param) => {
887
1003
  const { unitId, subUnitId, drawingId, transform } = param;
888
1004
  const sheetSkeletonParam = this._sheetSkeletonService.getSkeletonParam(unitId, subUnitId);
889
- if (!transform || !sheetSkeletonParam) return;
890
- const { skeleton } = sheetSkeletonParam;
1005
+ if (!transform) return;
891
1006
  const sheetDrawing = this._sheetDrawingService.getDrawingByParam({
892
1007
  unitId,
893
1008
  subUnitId,
894
1009
  drawingId
895
1010
  });
896
1011
  if (sheetDrawing == null || sheetDrawing.unitId !== this._context.unitId) return;
1012
+ if (sheetDrawing.anchorType === SheetDrawingAnchorType.None) {
1013
+ const next = {
1014
+ ...sheetDrawing,
1015
+ ...param,
1016
+ transform: {
1017
+ ...sheetDrawing.transform,
1018
+ ...transform
1019
+ }
1020
+ };
1021
+ drawings.push(applySheetDrawingPlacement(next, getSheetDrawingPlacement(next)));
1022
+ return;
1023
+ }
1024
+ if (!sheetSkeletonParam) return;
1025
+ const { skeleton } = sheetSkeletonParam;
897
1026
  const sheetTransform = transformToDrawingPosition({
898
1027
  ...sheetDrawing.transform,
899
1028
  ...transform
@@ -1018,18 +1147,17 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Di
1018
1147
  SheetDrawingUpdateController = __decorate([
1019
1148
  __decorateParam(1, ICommandService),
1020
1149
  __decorateParam(2, Inject(SheetInterceptorService)),
1021
- __decorateParam(3, ISheetSelectionRenderService),
1022
- __decorateParam(4, IImageIoService),
1023
- __decorateParam(5, ILocalFileService),
1024
- __decorateParam(6, ISheetDrawingService),
1025
- __decorateParam(7, IDrawingManagerService),
1026
- __decorateParam(8, IContextService),
1027
- __decorateParam(9, IMessageService),
1028
- __decorateParam(10, Inject(LocaleService)),
1029
- __decorateParam(11, Inject(SheetsSelectionsService)),
1030
- __decorateParam(12, Inject(SheetSkeletonService)),
1031
- __decorateParam(13, Inject(Injector)),
1032
- __decorateParam(14, IURLImageService)
1150
+ __decorateParam(3, IImageIoService),
1151
+ __decorateParam(4, ILocalFileService),
1152
+ __decorateParam(5, ISheetDrawingService),
1153
+ __decorateParam(6, IDrawingManagerService),
1154
+ __decorateParam(7, IContextService),
1155
+ __decorateParam(8, IMessageService),
1156
+ __decorateParam(9, Inject(LocaleService)),
1157
+ __decorateParam(10, Inject(SheetsSelectionsService)),
1158
+ __decorateParam(11, Inject(SheetSkeletonService)),
1159
+ __decorateParam(12, Inject(Injector)),
1160
+ __decorateParam(13, IURLImageService)
1033
1161
  ], SheetDrawingUpdateController);
1034
1162
 
1035
1163
  // src/commands/commands/insert-image.command.ts
@@ -1073,27 +1201,60 @@ const MoveDrawingsCommand = {
1073
1201
  const drawings = drawingManagerService.getFocusDrawings();
1074
1202
  if (drawings.length === 0) return false;
1075
1203
  const unitId = drawings[0].unitId;
1076
- const newDrawings = drawings.map((drawing) => {
1077
- const { transform, unitId, subUnitId } = drawing;
1078
- const skeleton = sheetSkeletonService.getSkeleton(unitId, subUnitId);
1079
- if (!transform || !skeleton) return null;
1080
- const newTransform = { ...transform };
1081
- const { left = 0, top = 0 } = transform;
1082
- if (direction === Direction.UP) newTransform.top = top - 1;
1083
- else if (direction === Direction.DOWN) newTransform.top = top + 1;
1084
- else if (direction === Direction.LEFT) newTransform.left = left - 1;
1085
- else if (direction === Direction.RIGHT) newTransform.left = left + 1;
1086
- return {
1087
- ...drawing,
1088
- transform: newTransform,
1089
- sheetTransform: transformToDrawingPosition(newTransform, skeleton),
1090
- axisAlignSheetTransform: transformToAxisAlignPosition(newTransform, skeleton)
1204
+ const movableDrawings = drawings.flatMap((drawing) => {
1205
+ const sheetDrawing = drawing;
1206
+ const { transform, anchorType = SheetDrawingAnchorType.Position } = sheetDrawing;
1207
+ if (!transform) return [];
1208
+ const skeleton = sheetSkeletonService.getSkeleton(drawing.unitId, drawing.subUnitId);
1209
+ if (anchorType !== SheetDrawingAnchorType.None && !skeleton) return [];
1210
+ return [{
1211
+ drawing: sheetDrawing,
1212
+ skeleton,
1213
+ anchorType
1214
+ }];
1215
+ });
1216
+ if (movableDrawings.length === 0) return false;
1217
+ let moveX = direction === Direction.LEFT ? -1 : direction === Direction.RIGHT ? 1 : 0;
1218
+ let moveY = direction === Direction.UP ? -1 : direction === Direction.DOWN ? 1 : 0;
1219
+ let minX = -Infinity;
1220
+ let minY = -Infinity;
1221
+ let maxX = Infinity;
1222
+ let maxY = Infinity;
1223
+ for (const { drawing, skeleton } of movableDrawings) {
1224
+ if (!skeleton) continue;
1225
+ const { left = 0, top = 0, width = 0, height = 0 } = drawing.transform;
1226
+ const { rowHeaderWidthAndMarginLeft, columnHeaderHeightAndMarginTop, columnTotalWidth, rowTotalHeight } = skeleton;
1227
+ minX = Math.max(minX, rowHeaderWidthAndMarginLeft - left);
1228
+ minY = Math.max(minY, columnHeaderHeightAndMarginTop - top);
1229
+ maxX = Math.min(maxX, rowHeaderWidthAndMarginLeft + columnTotalWidth - left - width);
1230
+ maxY = Math.min(maxY, columnHeaderHeightAndMarginTop + rowTotalHeight - top - height);
1231
+ }
1232
+ moveX = Math.max(minX, Math.min(moveX, maxX));
1233
+ moveY = Math.max(minY, Math.min(moveY, maxY));
1234
+ if (moveX === 0 && moveY === 0) return false;
1235
+ const newDrawings = movableDrawings.flatMap(({ drawing, skeleton, anchorType }) => {
1236
+ const { left = 0, top = 0, width = 0, height = 0 } = drawing.transform;
1237
+ const bounds = {
1238
+ left: left + moveX,
1239
+ top: top + moveY,
1240
+ width,
1241
+ height
1091
1242
  };
1092
- }).filter((drawing) => drawing != null);
1243
+ if (anchorType === SheetDrawingAnchorType.None) return [applySheetDrawingPlacement(drawing, {
1244
+ kind: anchorType,
1245
+ bounds
1246
+ })];
1247
+ if (!skeleton) return [];
1248
+ return [applySheetDrawingPlacement(drawing, {
1249
+ kind: anchorType,
1250
+ bounds
1251
+ }, skeleton)];
1252
+ });
1253
+ if (newDrawings.length === 0) return false;
1093
1254
  if (undoRedoGroupService.runTimed(unitId, `sheet-drawing:nudge:${drawings[0].subUnitId}:${drawings.map((drawing) => drawing.drawingId).sort().join(",")}`, () => commandService.syncExecuteCommand(SetSheetDrawingCommand.id, {
1094
1255
  unitId,
1095
1256
  drawings: newDrawings
1096
- }))) {
1257
+ }), "append")) {
1097
1258
  commandService.syncExecuteCommand(ClearSheetDrawingTransformerOperation.id, [unitId]);
1098
1259
  return true;
1099
1260
  }
@@ -1865,9 +2026,12 @@ function applyFloatDomTransformerConfig(rect, floatDomParam) {
1865
2026
  };
1866
2027
  }
1867
2028
  function applySheetChartTransformerConfig(rect) {
2029
+ var _rect$transformerConf, _rect$transformerConf2;
1868
2030
  rect.transformerConfig = {
1869
2031
  ...rect.transformerConfig,
1870
- ...SHEET_CHART_TRANSFORMER_CONFIG
2032
+ ...SHEET_CHART_TRANSFORMER_CONFIG,
2033
+ moveEnabled: ((_rect$transformerConf = rect.transformerConfig) === null || _rect$transformerConf === void 0 ? void 0 : _rect$transformerConf.moveEnabled) ?? SHEET_CHART_TRANSFORMER_CONFIG.moveEnabled,
2034
+ resizeEnabled: ((_rect$transformerConf2 = rect.transformerConfig) === null || _rect$transformerConf2 === void 0 ? void 0 : _rect$transformerConf2.resizeEnabled) ?? SHEET_CHART_TRANSFORMER_CONFIG.resizeEnabled
1871
2035
  };
1872
2036
  }
1873
2037
  function isStage2RuntimeEmbedFloatDom(floatDomParam) {
@@ -1996,8 +2160,8 @@ function transformBound2DOMBound(posOfFloatObject, scene, skeleton, worksheet, f
1996
2160
  const { boundsOfViewArea: specBoundsOfViewArea, scrollDirectionResponse } = floatDomInfo || {};
1997
2161
  const { rowHeaderWidth, columnHeaderHeight } = skeleton;
1998
2162
  const boundsOfViewArea = {
1999
- top: skipBoundsOfViewArea ? 0 : columnHeaderHeight,
2000
- left: skipBoundsOfViewArea ? 0 : rowHeaderWidth
2163
+ top: skipBoundsOfViewArea ? 0 : columnHeaderHeight * scaleY,
2164
+ left: skipBoundsOfViewArea ? 0 : rowHeaderWidth * scaleX
2001
2165
  };
2002
2166
  if (specBoundsOfViewArea) {
2003
2167
  if (Tools.isDefine(boundsOfViewArea.top)) boundsOfViewArea.top = specBoundsOfViewArea.top;
@@ -2095,6 +2259,10 @@ const calcSheetFloatDomPosition = (floatObject, scene, skeleton, worksheet, floa
2095
2259
  };
2096
2260
  };
2097
2261
  let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = class SheetCanvasFloatDomManagerService extends Disposable {
2262
+ registerMoveTransformConstraint(constraint) {
2263
+ this._moveTransformConstraints.add(constraint);
2264
+ return toDisposable(() => this._moveTransformConstraints.delete(constraint));
2265
+ }
2098
2266
  constructor(_renderManagerService, _univerInstanceService, _commandService, _drawingManagerService, _canvasFloatDomService, _sheetDrawingService, _lifecycleService, _canvasFloatDomPreviewService) {
2099
2267
  super();
2100
2268
  this._renderManagerService = _renderManagerService;
@@ -2112,12 +2280,29 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2112
2280
  _defineProperty(this, "add$", this._add$.asObservable());
2113
2281
  _defineProperty(this, "_remove$", new Subject());
2114
2282
  _defineProperty(this, "remove$", this._remove$.asObservable());
2283
+ _defineProperty(this, "_moveTransformConstraints", /* @__PURE__ */ new Set());
2284
+ _defineProperty(this, "_floatDomMoveDisposables", /* @__PURE__ */ new Map());
2115
2285
  _defineProperty(this, "_renderObjectFactories", /* @__PURE__ */ new Map());
2116
2286
  this._drawingAddListener();
2117
2287
  this._featureUpdateListener();
2118
2288
  this._deleteListener();
2119
2289
  this._bindScrollEvent();
2120
2290
  this._bindEmbedFloatDragHandleEvent();
2291
+ this.disposeWithMe(this._renderManagerService.disposed$.subscribe((unitId) => {
2292
+ for (const info of Array.from(this._domLayerInfoMap.values())) if (info.unitId === unitId) this._removeDom(info.id);
2293
+ }));
2294
+ this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe((unit) => {
2295
+ for (const info of Array.from(this._domLayerInfoMap.values())) if (info.unitId === unit.getUnitId()) this._removeDom(info.id);
2296
+ }));
2297
+ }
2298
+ dispose() {
2299
+ this._moveTransformConstraints.clear();
2300
+ for (const id of Array.from(this._domLayerInfoMap.keys())) this._removeDom(id);
2301
+ this._renderObjectFactories.clear();
2302
+ this._transformChange$.complete();
2303
+ this._add$.complete();
2304
+ this._remove$.complete();
2305
+ super.dispose();
2121
2306
  }
2122
2307
  /**
2123
2308
  * Register a factory that creates the canvas-side render object for a sheet
@@ -2142,14 +2327,26 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2142
2327
  const factory = factories === null || factories === void 0 ? void 0 : factories[factories.length - 1];
2143
2328
  return (factory === null || factory === void 0 ? void 0 : factory(context)) ?? new Rect(context.key, context.config);
2144
2329
  }
2330
+ _forwardWheelToCanvas(canvas, event) {
2331
+ if (!canvas.dispatchEvent(new WheelEvent(event.type, event))) event.preventDefault();
2332
+ }
2145
2333
  _bindScrollEvent() {
2146
- this._lifecycleService.lifecycle$.pipe(filter((s) => s === LifecycleStages.Rendered), take(1)).subscribe(() => {
2334
+ this.disposeWithMe(this._lifecycleService.lifecycle$.pipe(filter((s) => s === LifecycleStages.Rendered), take(1)).subscribe(() => {
2147
2335
  this._scrollUpdateListener();
2148
- });
2336
+ }));
2149
2337
  }
2150
2338
  getFloatDomInfo(id) {
2151
2339
  return this._domLayerInfoMap.get(id);
2152
2340
  }
2341
+ updateFloatDomEventOptions(id, eventOptions) {
2342
+ const info = this._domLayerInfoMap.get(id);
2343
+ if (!(info === null || info === void 0 ? void 0 : info.floatDomConfig)) return;
2344
+ info.floatDomConfig = {
2345
+ ...info.floatDomConfig,
2346
+ eventOptions
2347
+ };
2348
+ this._canvasFloatDomService.updateFloatDom(id, { eventOptions });
2349
+ }
2153
2350
  getFloatDomsBySubUnitId(unitId, subUnitId) {
2154
2351
  return Array.from(this._domLayerInfoMap.values()).filter((info) => info.subUnitId === subUnitId && info.unitId === unitId);
2155
2352
  }
@@ -2166,6 +2363,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2166
2363
  this.disposeWithMe(() => document.removeEventListener(EMBED_FLOAT_DRAG_HANDLE_POINTER_DOWN_EVENT, listener));
2167
2364
  }
2168
2365
  _handleEmbedFloatDragHandlePointerDown(event) {
2366
+ var _this$_floatDomMoveDi, _this$_univerInstance2;
2169
2367
  const detail = event.detail;
2170
2368
  if (!(detail === null || detail === void 0 ? void 0 : detail.hostAnchorId)) return;
2171
2369
  const info = this._domLayerInfoMap.get(detail.hostAnchorId);
@@ -2173,7 +2371,21 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2173
2371
  const dragState = createFloatDomMoveDragState(info, detail);
2174
2372
  const renderObject = this._getSceneAndTransformerByDrawingSearch(info.unitId);
2175
2373
  if (!dragState || !renderObject) return;
2176
- const { scene, transformer } = renderObject;
2374
+ (_this$_floatDomMoveDi = this._floatDomMoveDisposables.get(info.id)) === null || _this$_floatDomMoveDi === void 0 || _this$_floatDomMoveDi.dispose();
2375
+ const { scene, transformer, canvas } = renderObject;
2376
+ const isCurrentHost = () => {
2377
+ var _this$_getSceneAndTra, _this$_univerInstance;
2378
+ return this._domLayerInfoMap.get(info.id) === info && ((_this$_getSceneAndTra = this._getSceneAndTransformerByDrawingSearch(info.unitId)) === null || _this$_getSceneAndTra === void 0 ? void 0 : _this$_getSceneAndTra.scene) === scene && ((_this$_univerInstance = this._univerInstanceService.getUnit(info.unitId, UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getActiveSheet().getSheetId()) === info.subUnitId;
2379
+ };
2380
+ const isChartSheet = ((_this$_univerInstance2 = this._univerInstanceService.getUnit(info.unitId, UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance2 === void 0 || (_this$_univerInstance2 = _this$_univerInstance2.getSheetBySheetId(info.subUnitId)) === null || _this$_univerInstance2 === void 0 ? void 0 : _this$_univerInstance2.getConfig().type) === SheetTypes.CHART;
2381
+ const toScenePoint = (point) => {
2382
+ const bounds = canvas.getBoundingClientRect();
2383
+ return scene.getMainViewport().transformVector2SceneCoord(Vector2.FromArray([point.clientX - bounds.left, point.clientY - bounds.top]));
2384
+ };
2385
+ const startPoint = isChartSheet ? toScenePoint({
2386
+ clientX: dragState.startClientX,
2387
+ clientY: dragState.startClientY
2388
+ }) : void 0;
2177
2389
  if (info.rect.oKey) {
2178
2390
  var _scene$getTransformer;
2179
2391
  transformer.clearControlByIds([info.rect.oKey]);
@@ -2181,15 +2393,35 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2181
2393
  }
2182
2394
  const handlePointerMove = (pointerEvent) => {
2183
2395
  if (dragState.pointerId != null && pointerEvent.pointerId !== dragState.pointerId) return;
2396
+ if (!isCurrentHost()) return;
2184
2397
  pointerEvent.preventDefault();
2185
- const nextTransform = resolveFloatDomMoveDragTransform(dragState, pointerEvent, scene);
2186
- info.rect.transformByState(nextTransform);
2398
+ const point = startPoint && toScenePoint(pointerEvent);
2399
+ const nextTransform = point && startPoint ? {
2400
+ left: dragState.startLeft + point.x - startPoint.x,
2401
+ top: dragState.startTop + point.y - startPoint.y
2402
+ } : resolveFloatDomMoveDragTransform(dragState, pointerEvent, scene);
2403
+ const drawing = this._sheetDrawingService.getDrawingByParam({
2404
+ unitId: info.unitId,
2405
+ subUnitId: info.subUnitId,
2406
+ drawingId: info.id
2407
+ });
2408
+ if ((drawing === null || drawing === void 0 ? void 0 : drawing.anchorType) === SheetDrawingAnchorType.None) {
2409
+ const next = {
2410
+ ...drawing,
2411
+ transform: {
2412
+ ...drawing.transform,
2413
+ ...nextTransform
2414
+ }
2415
+ };
2416
+ let transform = applySheetDrawingPlacement(drawing, getSheetDrawingPlacement(next)).transform;
2417
+ for (const constraint of this._moveTransformConstraints) transform = constraint(drawing, transform);
2418
+ info.rect.transformByState(transform);
2419
+ } else info.rect.transformByState(nextTransform);
2187
2420
  };
2188
2421
  const handlePointerUp = (pointerEvent) => {
2189
2422
  if (dragState.pointerId != null && pointerEvent.pointerId !== dragState.pointerId) return;
2190
- window.removeEventListener("pointermove", handlePointerMove, true);
2191
- window.removeEventListener("pointerup", handlePointerUp, true);
2192
- window.removeEventListener("pointercancel", handlePointerCancel, true);
2423
+ cleanupDrag();
2424
+ if (!isCurrentHost()) return;
2193
2425
  pointerEvent.preventDefault();
2194
2426
  if (info.rect.left !== dragState.startLeft || info.rect.top !== dragState.startTop) this._commitFloatDomMove(info);
2195
2427
  if (info.runtimeStage === "stage1") {
@@ -2199,9 +2431,8 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2199
2431
  };
2200
2432
  const handlePointerCancel = (pointerEvent) => {
2201
2433
  if (dragState.pointerId != null && pointerEvent.pointerId !== dragState.pointerId) return;
2202
- window.removeEventListener("pointermove", handlePointerMove, true);
2203
- window.removeEventListener("pointerup", handlePointerUp, true);
2204
- window.removeEventListener("pointercancel", handlePointerCancel, true);
2434
+ cleanupDrag();
2435
+ if (!isCurrentHost()) return;
2205
2436
  info.rect.transformByState({
2206
2437
  left: dragState.startLeft,
2207
2438
  top: dragState.startTop
@@ -2211,6 +2442,13 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2211
2442
  (_scene$attachTransfor2 = scene.attachTransformerTo) === null || _scene$attachTransfor2 === void 0 || _scene$attachTransfor2.call(scene, info.rect);
2212
2443
  }
2213
2444
  };
2445
+ const cleanupDrag = () => {
2446
+ this._floatDomMoveDisposables.delete(info.id);
2447
+ window.removeEventListener("pointermove", handlePointerMove, true);
2448
+ window.removeEventListener("pointerup", handlePointerUp, true);
2449
+ window.removeEventListener("pointercancel", handlePointerCancel, true);
2450
+ };
2451
+ this._floatDomMoveDisposables.set(info.id, { dispose: cleanupDrag });
2214
2452
  window.addEventListener("pointermove", handlePointerMove, true);
2215
2453
  window.addEventListener("pointerup", handlePointerUp, true);
2216
2454
  window.addEventListener("pointercancel", handlePointerCancel, true);
@@ -2223,7 +2461,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2223
2461
  subUnitId: info.subUnitId,
2224
2462
  drawingId: info.id
2225
2463
  });
2226
- if (!skeletonParam || !(drawing === null || drawing === void 0 ? void 0 : drawing.transform)) return;
2464
+ if (!(drawing === null || drawing === void 0 ? void 0 : drawing.transform) || this._domLayerInfoMap.get(info.id) !== info) return;
2227
2465
  const transform = {
2228
2466
  ...drawing.transform,
2229
2467
  left: info.rect.left,
@@ -2236,6 +2474,18 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2236
2474
  skewX: info.rect.skewX,
2237
2475
  skewY: info.rect.skewY
2238
2476
  };
2477
+ if (drawing.anchorType === SheetDrawingAnchorType.None) {
2478
+ const next = {
2479
+ ...drawing,
2480
+ transform
2481
+ };
2482
+ this._commandService.syncExecuteCommand(SetSheetDrawingCommand.id, {
2483
+ unitId: info.unitId,
2484
+ drawings: [applySheetDrawingPlacement(drawing, getSheetDrawingPlacement(next))]
2485
+ });
2486
+ return;
2487
+ }
2488
+ if (!skeletonParam) return;
2239
2489
  const sheetTransform = transformToDrawingPosition(transform, skeletonParam.skeleton);
2240
2490
  const axisAlignSheetTransform = transformToAxisAlignPosition(transform, skeletonParam.skeleton);
2241
2491
  if (!sheetTransform || !axisAlignSheetTransform) return;
@@ -2416,7 +2666,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2416
2666
  const activeSheetId = workbook.getActiveSheet().getSheetId();
2417
2667
  if (!floatDomParam || !target) return;
2418
2668
  const skeleton = (_this$_renderManagerS2 = this._renderManagerService.getRenderUnitById(unitId)) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.with(SheetSkeletonManagerService).getSkeletonParam(subUnitId);
2419
- if (!skeleton) return;
2669
+ if (!skeleton && (target.worksheet.getConfig().type !== SheetTypes.CHART || floatDomParam.anchorType !== SheetDrawingAnchorType.None)) return;
2420
2670
  const { transform, drawingType, data, hidden, groupId } = floatDomParam;
2421
2671
  if (!isCanvasFloatDomDrawingType(drawingType)) return;
2422
2672
  const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
@@ -2464,6 +2714,11 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2464
2714
  top,
2465
2715
  width,
2466
2716
  height,
2717
+ angle,
2718
+ flipX,
2719
+ flipY,
2720
+ skewX,
2721
+ skewY,
2467
2722
  zIndex: this._getDrawingZIndex(unitId, subUnitId, drawingId)
2468
2723
  };
2469
2724
  const isChart = drawingType === DrawingTypeEnum.DRAWING_CHART;
@@ -2505,18 +2760,17 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2505
2760
  });
2506
2761
  previewSubscription && disposableCollection.add(previewSubscription);
2507
2762
  }
2508
- const initPosition = calcSheetFloatDomPosition(rect, renderObject.renderUnit.scene, skeleton.skeleton, target.worksheet);
2763
+ const initPosition = this._calculateFloatDomPosition(rect, renderObject.renderUnit.scene, target.worksheet, skeleton === null || skeleton === void 0 ? void 0 : skeleton.skeleton);
2509
2764
  const position$ = new BehaviorSubject(initPosition);
2510
2765
  const domId = `${SHEET_FLOAT_DOM_PREFIX}${generateRandomId(6)}`;
2511
2766
  const shouldAutoMountRuntime = shouldAutoMountFloatDomRuntime(floatDomParam);
2512
2767
  const shouldSyncEmbedRuntimeStage = isEmbedFloatDomData(floatDomParam);
2513
2768
  let info;
2514
2769
  const handleRuntimeStageEnter = (stage) => {
2515
- if (info) {
2516
- info.runtimeStage = stage;
2517
- info.runtimeMounted = shouldAutoMountRuntime || stage === "stage2";
2518
- if (shouldUpdateFloatDomLayerOnRuntimeStageChange(floatDomParam)) this._canvasFloatDomService.updateFloatDom(drawingId, { eventPassThrough: shouldPassThroughFloatDomRuntimeEvents(floatDomParam, stage) });
2519
- }
2770
+ if (!info || this._domLayerInfoMap.get(drawingId) !== info) return;
2771
+ info.runtimeStage = stage;
2772
+ info.runtimeMounted = shouldAutoMountRuntime || stage === "stage2";
2773
+ if (shouldUpdateFloatDomLayerOnRuntimeStageChange(floatDomParam)) this._canvasFloatDomService.updateFloatDom(drawingId, { eventPassThrough: shouldPassThroughFloatDomRuntimeEvents(floatDomParam, stage) });
2520
2774
  syncFloatDomHostSelectionOnStageEnter(stage, this._getSceneAndTransformerByDrawingSearch(unitId), rect);
2521
2775
  };
2522
2776
  const floatDomConfig = {
@@ -2525,6 +2779,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2525
2779
  domId,
2526
2780
  componentKey: floatDomParam.componentKey,
2527
2781
  eventPassThrough: shouldPassThroughFloatDomRuntimeEvents(floatDomParam, "inactive"),
2782
+ preventBrowserZoom: true,
2528
2783
  preserveOnFocusChange: shouldPreserveFloatDomOnFocusChange(floatDomParam),
2529
2784
  onPointerDown: (evt) => {
2530
2785
  if (shouldForwardSheetHostedEmbedFloatDomEvent(floatDomParam, evt)) canvas.dispatchEvent(new PointerEvent(evt.type, evt));
@@ -2536,7 +2791,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2536
2791
  if (shouldForwardSheetHostedEmbedFloatDomEvent(floatDomParam, evt)) canvas.dispatchEvent(new PointerEvent(evt.type, evt));
2537
2792
  },
2538
2793
  onWheel: (evt) => {
2539
- if (shouldForwardSheetHostedEmbedFloatDomEvent(floatDomParam, evt)) canvas.dispatchEvent(new WheelEvent(evt.type, evt));
2794
+ if (shouldForwardSheetHostedEmbedFloatDomEvent(floatDomParam, evt)) this._forwardWheelToCanvas(canvas, evt);
2540
2795
  },
2541
2796
  data,
2542
2797
  props: shouldSyncEmbedRuntimeStage ? { onRuntimeStageEnter: handleRuntimeStageEnter } : void 0,
@@ -2615,7 +2870,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2615
2870
  disposableCollection.add(sceneUpListener);
2616
2871
  }
2617
2872
  const listener = rect.onTransformChange$.subscribeEvent(() => {
2618
- const newPosition = calcSheetFloatDomPosition(rect, renderObject.renderUnit.scene, skeleton.skeleton, target.worksheet);
2873
+ const newPosition = this._calculateFloatDomPosition(rect, renderObject.renderUnit.scene, target.worksheet, skeleton === null || skeleton === void 0 ? void 0 : skeleton.skeleton);
2619
2874
  position$.next(newPosition);
2620
2875
  if (previewObjectKey) this._syncPreviewObjectTransform(scene.getObject(previewObjectKey), rect);
2621
2876
  });
@@ -2624,7 +2879,7 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2624
2879
  if (previewObjectKey) scene.removeObject(previewObjectKey);
2625
2880
  });
2626
2881
  listener && disposableCollection.add(listener);
2627
- this._bindFloatDomScroll(disposableCollection, info, renderObject.renderUnit.scene, skeleton.skeleton, target.worksheet);
2882
+ this._bindFloatDomScroll(disposableCollection, info, renderObject.renderUnit.scene, skeleton === null || skeleton === void 0 ? void 0 : skeleton.skeleton, target.worksheet);
2628
2883
  this._domLayerInfoMap.set(drawingId, info);
2629
2884
  });
2630
2885
  }));
@@ -2661,11 +2916,11 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2661
2916
  subUnitId
2662
2917
  });
2663
2918
  const skeleton = (_this$_renderManagerS3 = this._renderManagerService.getRenderUnitById(unitId)) === null || _this$_renderManagerS3 === void 0 ? void 0 : _this$_renderManagerS3.with(SheetSkeletonManagerService).getSkeletonParam(subUnitId);
2664
- if (!renderObject || !target || !skeleton) return;
2919
+ if (!renderObject || !target || !skeleton && target.worksheet.getConfig().type !== SheetTypes.CHART) return;
2665
2920
  ids.forEach((id) => {
2666
2921
  const floatDomInfo = this._domLayerInfoMap.get(id);
2667
2922
  if (floatDomInfo) {
2668
- const position = calcSheetFloatDomPosition(floatDomInfo.rect, renderObject.renderUnit.scene, skeleton.skeleton, target.worksheet, floatDomInfo);
2923
+ const position = this._calculateFloatDomPosition(floatDomInfo.rect, renderObject.renderUnit.scene, target.worksheet, skeleton === null || skeleton === void 0 ? void 0 : skeleton.skeleton, floatDomInfo);
2669
2924
  floatDomInfo.position$.next(position);
2670
2925
  }
2671
2926
  });
@@ -2695,9 +2950,35 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2695
2950
  _bindFloatDomScroll(disposableCollection, info, scene, skeleton, worksheet) {
2696
2951
  const viewport = scene.getViewport(SHEET_VIEWPORT_KEY.VIEW_MAIN);
2697
2952
  if (!viewport) return;
2698
- disposableCollection.add(fromEventSubject(viewport.onScrollAfter$).subscribe(() => {
2699
- info.position$.next(calcSheetFloatDomPosition(info.rect, scene, skeleton, worksheet, info));
2700
- }));
2953
+ const updatePosition = () => {
2954
+ if (this._domLayerInfoMap.get(info.id) !== info) return;
2955
+ info.position$.next(this._calculateFloatDomPosition(info.rect, scene, worksheet, skeleton, info));
2956
+ };
2957
+ disposableCollection.add(fromEventSubject(viewport.onScrollAfter$).subscribe(updatePosition));
2958
+ if (worksheet.getConfig().type === SheetTypes.CHART) {
2959
+ disposableCollection.add(scene.onTransformChange$.subscribeEvent(updatePosition));
2960
+ disposableCollection.add(viewport.onResized$.subscribe(updatePosition));
2961
+ }
2962
+ }
2963
+ _calculateFloatDomPosition(rect, scene, worksheet, skeleton, info) {
2964
+ if (skeleton) return calcSheetFloatDomPosition(rect, scene, skeleton, worksheet, info);
2965
+ const center = scene.getMainViewport().getAbsoluteVector(Vector2.FromArray([rect.left + rect.width / 2, rect.top + rect.height / 2]));
2966
+ const { scaleX, scaleY, angle } = scene.transform.decompose();
2967
+ const width = rect.width * scaleX;
2968
+ const height = rect.height * scaleY;
2969
+ return {
2970
+ startX: center.x - width / 2,
2971
+ startY: center.y - height / 2,
2972
+ endX: center.x + width / 2,
2973
+ endY: center.y + height / 2,
2974
+ width,
2975
+ height,
2976
+ rotate: rect.angle + angle,
2977
+ absolute: {
2978
+ left: false,
2979
+ top: false
2980
+ }
2981
+ };
2701
2982
  }
2702
2983
  updateFloatDomProps(unitId, subUnitId, id, props) {
2703
2984
  const info = this._domLayerInfoMap.get(id);
@@ -2867,9 +3148,11 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
2867
3148
  return this._createFloatDomDisposable(id);
2868
3149
  }
2869
3150
  _removeDom(id, removeDrawing = false) {
3151
+ var _this$_floatDomMoveDi2;
2870
3152
  const info = this._domLayerInfoMap.get(id);
2871
3153
  if (!info) return;
2872
3154
  const { unitId, subUnitId } = info;
3155
+ (_this$_floatDomMoveDi2 = this._floatDomMoveDisposables.get(id)) === null || _this$_floatDomMoveDi2 === void 0 || _this$_floatDomMoveDi2.dispose();
2873
3156
  this._domLayerInfoMap.delete(id);
2874
3157
  info.dispose.dispose();
2875
3158
  const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
@@ -3033,17 +3316,9 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
3033
3316
  subUnitId
3034
3317
  }, domRect, scene, this._drawingManagerService);
3035
3318
  const disposableCollection = new DisposableCollection();
3036
- const viewMain = scene.getMainViewport();
3037
- const { rowHeaderWidth, columnHeaderHeight } = skeletonParam.skeleton;
3038
3319
  const floatDomInfo = {
3039
3320
  dispose: disposableCollection,
3040
3321
  rect: domRect,
3041
- boundsOfViewArea: {
3042
- top: columnHeaderHeight,
3043
- left: rowHeaderWidth,
3044
- bottom: viewMain.bottom,
3045
- right: viewMain.right
3046
- },
3047
3322
  domAnchor,
3048
3323
  unitId,
3049
3324
  subUnitId,
@@ -3060,12 +3335,13 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
3060
3335
  let floatDomCfg = {
3061
3336
  position$,
3062
3337
  id: drawingId,
3338
+ preventBrowserZoom: true,
3063
3339
  componentKey: floatDomParam.componentKey,
3064
3340
  onPointerDown: () => {},
3065
3341
  onPointerMove: () => {},
3066
3342
  onPointerUp: () => {},
3067
3343
  onWheel: (evt) => {
3068
- canvas.dispatchEvent(new WheelEvent(evt.type, evt));
3344
+ this._forwardWheelToCanvas(canvas, evt);
3069
3345
  },
3070
3346
  data,
3071
3347
  unitId
@@ -3269,12 +3545,13 @@ let SheetCanvasFloatDomManagerService = _SheetCanvasFloatDomManagerService = cla
3269
3545
  let floatDomCfg = {
3270
3546
  position$,
3271
3547
  id: drawingId,
3548
+ preventBrowserZoom: true,
3272
3549
  componentKey: floatDomParam.componentKey,
3273
3550
  onPointerDown: () => {},
3274
3551
  onPointerMove: () => {},
3275
3552
  onPointerUp: () => {},
3276
3553
  onWheel: (evt) => {
3277
- canvas.dispatchEvent(new WheelEvent(evt.type, evt));
3554
+ this._forwardWheelToCanvas(canvas, evt);
3278
3555
  },
3279
3556
  data,
3280
3557
  unitId
@@ -3513,6 +3790,25 @@ function touchSheetsDrawingFloatingHostCapabilityWhenReady(injector) {
3513
3790
 
3514
3791
  // src/menu/image.menu.ts
3515
3792
  const SHEETS_IMAGE_MENU_ID = "sheet.menu.image";
3793
+ /** Chart Sheets have no cells; other sheet types retain the existing range-menu permission rules. */
3794
+ function getImageMenuDisabled$(accessor, floating) {
3795
+ return deriveStateFromActiveSheet$(accessor.get(IUniverInstanceService), true, ({ workbook, worksheet }) => {
3796
+ if (worksheet.getConfig().type === SheetTypes.CHART) {
3797
+ if (!floating) return of(true);
3798
+ const permissions = accessor.get(IPermissionService);
3799
+ const ids = [new WorkbookEditablePermission(workbook.getUnitId()).id, new WorksheetEditPermission(workbook.getUnitId(), worksheet.getSheetId()).id];
3800
+ return permissions.permissionPointUpdate$.pipe(startWith(null), map(() => ids.some((id) => {
3801
+ var _permissions$getPermi;
3802
+ return ((_permissions$getPermi = permissions.getPermissionPoint(id)) === null || _permissions$getPermi === void 0 ? void 0 : _permissions$getPermi.value) !== true;
3803
+ })), distinctUntilChanged());
3804
+ }
3805
+ return getCurrentRangeDisable$(accessor, {
3806
+ workbookTypes: [WorkbookEditablePermission],
3807
+ worksheetTypes: [WorksheetEditPermission],
3808
+ rangeTypes: [RangeProtectionPermissionEditPoint]
3809
+ });
3810
+ });
3811
+ }
3516
3812
  function ImageMenuFactory(accessor) {
3517
3813
  return {
3518
3814
  id: SHEETS_IMAGE_MENU_ID,
@@ -3520,17 +3816,14 @@ function ImageMenuFactory(accessor) {
3520
3816
  icon: "AddImageIcon",
3521
3817
  tooltip: "sheets-drawing-ui.title",
3522
3818
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
3523
- disabled$: getCurrentRangeDisable$(accessor, {
3524
- workbookTypes: [WorkbookEditablePermission],
3525
- worksheetTypes: [WorksheetEditPermission],
3526
- rangeTypes: [RangeProtectionPermissionEditPoint]
3527
- })
3819
+ disabled$: getImageMenuDisabled$(accessor, true)
3528
3820
  };
3529
3821
  }
3530
3822
  function UploadFloatImageMenuFactory(accessor) {
3531
3823
  return {
3532
3824
  id: InsertFloatImageCommand.id,
3533
3825
  title: "sheets-drawing-ui.upload.float",
3826
+ disabled$: getImageMenuDisabled$(accessor, true),
3534
3827
  type: MenuItemType.BUTTON,
3535
3828
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET)
3536
3829
  };
@@ -3539,6 +3832,7 @@ function UploadCellImageMenuFactory(accessor) {
3539
3832
  return {
3540
3833
  id: InsertCellImageCommand.id,
3541
3834
  title: "sheets-drawing-ui.upload.cell",
3835
+ disabled$: getImageMenuDisabled$(accessor, false),
3542
3836
  type: MenuItemType.BUTTON,
3543
3837
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET)
3544
3838
  };
@@ -3698,7 +3992,7 @@ const menuSchema = {
3698
3992
 
3699
3993
  // package.json
3700
3994
  var name = "@univerjs/sheets-drawing-ui";
3701
- var version = "1.4.0";
3995
+ var version = "1.5.0";
3702
3996
 
3703
3997
  // src/config/config.ts
3704
3998
  const SHEETS_DRAWING_UI_PLUGIN_CONFIG_KEY = "sheets-drawing-ui.config";
@@ -4622,10 +4916,11 @@ SheetsDrawingRenderController = __decorate([
4622
4916
 
4623
4917
  // src/views/background/worksheet-background-image.extension.ts
4624
4918
  const WORKSHEET_BACKGROUND_IMAGE_EXTENSION_KEY = "WorksheetBackgroundImageExtension";
4625
- var WorksheetBackgroundImageExtension = class extends SheetExtension {
4919
+ var WorksheetBackgroundImageExtension = class WorksheetBackgroundImageExtension extends SheetExtension {
4626
4920
  constructor(injector, _requestRender) {
4627
4921
  super();
4628
4922
  this._requestRender = _requestRender;
4923
+ _defineProperty(this, "viewportCacheReusable", this.constructor === WorksheetBackgroundImageExtension);
4629
4924
  _defineProperty(this, "uKey", WORKSHEET_BACKGROUND_IMAGE_EXTENSION_KEY);
4630
4925
  _defineProperty(this, "type", SHEET_EXTENSION_TYPE.BACKGROUND);
4631
4926
  _defineProperty(this, "_imageCache", void 0);
@@ -5043,7 +5338,11 @@ const specialPastes = [
5043
5338
  PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA
5044
5339
  ];
5045
5340
  let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController extends RxDisposable {
5046
- constructor(_sheetClipboardService, _renderManagerService, _sheetSkeletonService, _drawingService, _clipboardInterfaceService, _commandService) {
5341
+ dispose() {
5342
+ this._copyInfo = null;
5343
+ super.dispose();
5344
+ }
5345
+ constructor(_sheetClipboardService, _renderManagerService, _sheetSkeletonService, _drawingService, _clipboardInterfaceService, _commandService, _instanceService, _permissions) {
5047
5346
  super();
5048
5347
  this._sheetClipboardService = _sheetClipboardService;
5049
5348
  this._renderManagerService = _renderManagerService;
@@ -5051,6 +5350,8 @@ let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController ex
5051
5350
  this._drawingService = _drawingService;
5052
5351
  this._clipboardInterfaceService = _clipboardInterfaceService;
5053
5352
  this._commandService = _commandService;
5353
+ this._instanceService = _instanceService;
5354
+ this._permissions = _permissions;
5054
5355
  _defineProperty(this, "_copyInfo", void 0);
5055
5356
  this._initCopyPaste();
5056
5357
  }
@@ -5060,12 +5361,15 @@ let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController ex
5060
5361
  _initCopyPaste() {
5061
5362
  this.disposeWithMe(this._sheetClipboardService.addClipboardHook({
5062
5363
  id: "SHEET_IMAGE_UI_PLUGIN",
5063
- onBeforeCopyFocusedObject: (unitId, _subUnitId, copyType) => {
5364
+ onBeforeCopyFocusedObject: (unitId, subUnitId, copyType) => {
5064
5365
  this._copyInfo = null;
5065
5366
  const drawings = this._focusedDrawings.filter((drawing) => drawing.drawingType === DrawingTypeEnum.DRAWING_IMAGE);
5066
5367
  if (drawings.length === 0) return false;
5067
5368
  const [drawing] = drawings;
5068
5369
  if (copyType === COPY_TYPE.CUT) {
5370
+ var _this$_instanceServic;
5371
+ const worksheet = (_this$_instanceServic = this._instanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET)) === null || _this$_instanceServic === void 0 ? void 0 : _this$_instanceServic.getSheetBySheetId(subUnitId);
5372
+ if ((worksheet === null || worksheet === void 0 ? void 0 : worksheet.getConfig().type) === SheetTypes.CHART) return false;
5069
5373
  const params = {
5070
5374
  unitId,
5071
5375
  drawings
@@ -5195,12 +5499,15 @@ let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController ex
5195
5499
  };
5196
5500
  }
5197
5501
  _generateSingleDrawingPasteMutations(pasteContext, copyType) {
5502
+ var _this$_instanceServic2;
5198
5503
  const { pasteType, pasteTo } = pasteContext;
5199
5504
  if (specialPastes.includes(pasteType)) return {
5200
5505
  redos: [],
5201
5506
  undos: []
5202
5507
  };
5203
5508
  const { unitId, subUnitId, range } = pasteTo;
5509
+ const worksheet = (_this$_instanceServic2 = this._instanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET)) === null || _this$_instanceServic2 === void 0 ? void 0 : _this$_instanceServic2.getSheetBySheetId(subUnitId);
5510
+ if ((worksheet === null || worksheet === void 0 ? void 0 : worksheet.getConfig().type) === SheetTypes.CHART) return this._generateChartSheetImagePasteMutations(pasteTo);
5204
5511
  const pasteToSkeleton = this._sheetSkeletonService.getSkeleton(unitId, subUnitId);
5205
5512
  if (!pasteToSkeleton) return {
5206
5513
  redos: [],
@@ -5246,6 +5553,47 @@ let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController ex
5246
5553
  }
5247
5554
  });
5248
5555
  }
5556
+ _generateChartSheetImagePasteMutations(pasteTo) {
5557
+ var _this$_renderManagerS;
5558
+ const { unitId, subUnitId } = pasteTo;
5559
+ const worksheet = this._instanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET).getSheetBySheetId(subUnitId);
5560
+ if (!this._permissions.permissionCheckWithoutRange({
5561
+ workbookTypes: [WorkbookEditablePermission],
5562
+ worksheetTypes: [WorksheetEditPermission]
5563
+ }, unitId, subUnitId)) throw new CustomCommandExecutionError(SheetPasteCommand.id);
5564
+ const source = this._copyInfo;
5565
+ if (!this._permissions.permissionCheckWithoutRange({
5566
+ workbookTypes: [WorkbookCopyPermission],
5567
+ worksheetTypes: [WorksheetCopyPermission]
5568
+ }, source.unitId, source.subUnitId) || source.drawings.some((drawing) => !Tools.diffValue(drawing, this._drawingService.getDrawingByParam(drawing)))) throw new CustomCommandExecutionError(SheetPasteCommand.id);
5569
+ const frame = (_this$_renderManagerS = this._renderManagerService.getRenderUnitById(unitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.components.get(SHEET_VIEW_KEY.CHART_PAGE);
5570
+ const originals = this._copyInfo.drawings;
5571
+ const placed = frame && transformDrawingsToChartSheet(originals, {
5572
+ left: frame.left,
5573
+ top: frame.top,
5574
+ width: frame.width,
5575
+ height: frame.height
5576
+ }, worksheet.getConfig().rightToLeft === BooleanNumber.TRUE);
5577
+ if (!placed) return {
5578
+ redos: [],
5579
+ undos: []
5580
+ };
5581
+ const copies = new Map(placed.map((drawing) => [drawing.drawingId, drawing]));
5582
+ return this._generateMutations(originals, {
5583
+ unitId,
5584
+ subUnitId,
5585
+ isCut: false,
5586
+ getTransform: (_transform, _sheetTransform, drawing) => {
5587
+ const copy = copies.get(drawing.drawingId);
5588
+ return {
5589
+ anchorType: copy.anchorType,
5590
+ transform: copy.transform,
5591
+ sheetTransform: copy.sheetTransform,
5592
+ axisAlignSheetTransform: copy.axisAlignSheetTransform
5593
+ };
5594
+ }
5595
+ });
5596
+ }
5249
5597
  _generateMutations(drawings, payload) {
5250
5598
  const { unitId, subUnitId, getTransform, isCut } = payload;
5251
5599
  const redos = [];
@@ -5254,15 +5602,13 @@ let SheetsDrawingCopyPasteController = class SheetsDrawingCopyPasteController ex
5254
5602
  drawings.forEach((drawing) => {
5255
5603
  const { transform, sheetTransform } = drawing;
5256
5604
  if (!transform) return;
5257
- const transformContext = getTransform(transform, sheetTransform);
5605
+ const transformContext = getTransform(transform, sheetTransform, drawing);
5258
5606
  const drawingObject = {
5259
5607
  ...drawing,
5260
- unitId,
5261
- subUnitId,
5608
+ ...transformContext,
5262
5609
  drawingId: isCut ? drawing.drawingId : generateRandomId(),
5263
- transform: transformContext.transform,
5264
- sheetTransform: transformContext.sheetTransform,
5265
- axisAlignSheetTransform: transformContext.axisAlignSheetTransform
5610
+ unitId,
5611
+ subUnitId
5266
5612
  };
5267
5613
  if (isCut) {
5268
5614
  const { undo, redo, objects } = _drawingService.getBatchUpdateOp([drawingObject]);
@@ -5405,9 +5751,135 @@ SheetsDrawingCopyPasteController = __decorate([
5405
5751
  __decorateParam(2, Inject(SheetSkeletonService)),
5406
5752
  __decorateParam(3, IDrawingManagerService),
5407
5753
  __decorateParam(4, IClipboardInterfaceService),
5408
- __decorateParam(5, ICommandService)
5754
+ __decorateParam(5, ICommandService),
5755
+ __decorateParam(6, IUniverInstanceService),
5756
+ __decorateParam(7, Inject(SheetPermissionCheckController))
5409
5757
  ], SheetsDrawingCopyPasteController);
5410
5758
 
5759
+ // src/commands/commands/flip-drawings.command.ts
5760
+ /**
5761
+ * The command to flip sheet drawing elements
5762
+ */
5763
+ const FlipSheetDrawingCommand = {
5764
+ id: "sheet.command.toggle-flip-drawings",
5765
+ type: CommandType.COMMAND,
5766
+ handler: (accessor, params) => {
5767
+ if (!params) return false;
5768
+ const commandService = accessor.get(ICommandService);
5769
+ const undoRedoService = accessor.get(IUndoRedoService);
5770
+ const sheetDrawingService = accessor.get(ISheetDrawingService);
5771
+ const sheetSkeletonService = accessor.get(SheetSkeletonService);
5772
+ const { drawings } = params;
5773
+ const flipH = params.flipH;
5774
+ const flipV = params.flipV;
5775
+ const unitIds = [];
5776
+ const updateParams = [];
5777
+ for (const param of drawings) {
5778
+ const { unitId, subUnitId, drawingId } = param;
5779
+ unitIds.push(unitId);
5780
+ const drawingData = sheetDrawingService.getDrawingData(unitId, subUnitId);
5781
+ const existing = drawingData === null || drawingData === void 0 ? void 0 : drawingData[drawingId];
5782
+ if (!existing) continue;
5783
+ const skeleton = sheetSkeletonService.getSkeleton(unitId, subUnitId);
5784
+ if (!skeleton) continue;
5785
+ const transform = { ...existing.transform };
5786
+ if (flipH) transform.flipX = !transform.flipX;
5787
+ if (flipV) transform.flipY = !transform.flipY;
5788
+ const sheetTransform = transformToDrawingPosition(transform, skeleton);
5789
+ const axisAlignSheetTransform = transformToAxisAlignPosition(transform, skeleton);
5790
+ const updateParamItem = {
5791
+ unitId,
5792
+ subUnitId,
5793
+ drawingType: existing.drawingType,
5794
+ drawingId,
5795
+ transform,
5796
+ sheetTransform,
5797
+ axisAlignSheetTransform
5798
+ };
5799
+ if (existing.drawingType === DrawingTypeEnum.DRAWING_IMAGE) {
5800
+ const scene = getSceneByDrawingSearch(accessor, unitId);
5801
+ if (scene) {
5802
+ const drawingShapeKey = getDrawingShapeKeyByDrawingSearch({
5803
+ unitId,
5804
+ subUnitId,
5805
+ drawingId
5806
+ });
5807
+ const imageShape = scene.getObject(drawingShapeKey);
5808
+ if (imageShape) {
5809
+ const srcRect = imageShape.srcRect;
5810
+ if (srcRect) {
5811
+ let newSrcRect;
5812
+ const { left = 0, top = 0, right = 0, bottom = 0 } = srcRect;
5813
+ if (flipH) {
5814
+ const centerX = left + (right - left) / 2;
5815
+ newSrcRect = {
5816
+ left: centerX - (right - left) / 2,
5817
+ top,
5818
+ right: centerX + (right - left) / 2,
5819
+ bottom
5820
+ };
5821
+ }
5822
+ if (flipV) {
5823
+ const centerY = top + (bottom - top) / 2;
5824
+ newSrcRect = {
5825
+ left,
5826
+ top: centerY - (bottom - top) / 2,
5827
+ right,
5828
+ bottom: centerY + (bottom - top) / 2
5829
+ };
5830
+ }
5831
+ if (newSrcRect) updateParamItem.srcRect = newSrcRect;
5832
+ }
5833
+ }
5834
+ }
5835
+ }
5836
+ updateParams.push(updateParamItem);
5837
+ }
5838
+ if (updateParams.length === 0) return false;
5839
+ const { unitId: opUnitId, subUnitId: opSubUnitId, undo, redo, objects } = sheetDrawingService.getBatchUpdateOp(updateParams);
5840
+ const updateMutation = {
5841
+ id: SetDrawingApplyMutation.id,
5842
+ params: {
5843
+ unitId: opUnitId,
5844
+ subUnitId: opSubUnitId,
5845
+ op: redo,
5846
+ objects,
5847
+ type: DrawingApplyType.UPDATE
5848
+ }
5849
+ };
5850
+ const undoUpdateMutation = {
5851
+ id: SetDrawingApplyMutation.id,
5852
+ params: {
5853
+ unitId: opUnitId,
5854
+ subUnitId: opSubUnitId,
5855
+ op: undo,
5856
+ objects,
5857
+ type: DrawingApplyType.UPDATE
5858
+ }
5859
+ };
5860
+ if (sequenceExecute([updateMutation], commandService).result) {
5861
+ undoRedoService.pushUndoRedo({
5862
+ unitID: opUnitId,
5863
+ undoMutations: [undoUpdateMutation, {
5864
+ id: ClearSheetDrawingTransformerOperation.id,
5865
+ params: unitIds
5866
+ }],
5867
+ redoMutations: [updateMutation, {
5868
+ id: ClearSheetDrawingTransformerOperation.id,
5869
+ params: unitIds
5870
+ }]
5871
+ });
5872
+ return true;
5873
+ }
5874
+ return false;
5875
+ }
5876
+ };
5877
+ function getSceneByDrawingSearch(accessor, unitId) {
5878
+ const render = accessor.get(IRenderManagerService).getRenderUnitById(unitId);
5879
+ if (!render) return null;
5880
+ return render.scene;
5881
+ }
5882
+
5411
5883
  // src/controllers/sheet-drawing-permission.controller.ts
5412
5884
  const drawingObjectTypes = [
5413
5885
  ObjectType.IMAGE,
@@ -5431,6 +5903,7 @@ let SheetDrawingPermissionController = class SheetDrawingPermissionController ex
5431
5903
  this._initViewPermissionChange();
5432
5904
  this._initEditPermissionChange();
5433
5905
  this._initCommandPermissionCheck();
5906
+ this._initChartSheetCommandPermissionCheck();
5434
5907
  }
5435
5908
  _initDrawingVisible() {
5436
5909
  const workbook$ = this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET);
@@ -5606,6 +6079,30 @@ let SheetDrawingPermissionController = class SheetDrawingPermissionController ex
5606
6079
  }
5607
6080
  }));
5608
6081
  }
6082
+ _initChartSheetCommandPermissionCheck() {
6083
+ this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
6084
+ if (command.id === GroupSheetDrawingCommand.id || command.id === UngroupSheetDrawingCommand.id) {
6085
+ for (const group of command.params ?? []) {
6086
+ this._checkChartSheetEditPermission(group.parent.unitId, group.parent.subUnitId);
6087
+ for (const child of group.children) this._checkChartSheetEditPermission(child.unitId, child.subUnitId);
6088
+ }
6089
+ return;
6090
+ }
6091
+ if (command.id === FlipSheetDrawingCommand.id) {
6092
+ const params = command.params;
6093
+ for (const drawing of (params === null || params === void 0 ? void 0 : params.drawings) ?? []) this._checkChartSheetEditPermission(drawing.unitId, drawing.subUnitId);
6094
+ }
6095
+ }));
6096
+ }
6097
+ _checkChartSheetEditPermission(unitId, subUnitId) {
6098
+ var _this$_univerInstance;
6099
+ const worksheet = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(subUnitId);
6100
+ if ((worksheet === null || worksheet === void 0 ? void 0 : worksheet.getConfig().type) !== SheetTypes.CHART) return;
6101
+ if (!this._sheetPermissionCheckController.permissionCheckWithoutRange({
6102
+ workbookTypes: [WorkbookEditablePermission],
6103
+ worksheetTypes: [WorksheetEditPermission]
6104
+ }, unitId, subUnitId)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-drawing-ui.permission.dialog.editErr"));
6105
+ }
5609
6106
  _initCommandPermissionCheck() {
5610
6107
  this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
5611
6108
  let unitId;
@@ -5829,130 +6326,6 @@ SheetDrawingPrintingController = __decorate([
5829
6326
  __decorateParam(5, Inject(Injector))
5830
6327
  ], SheetDrawingPrintingController);
5831
6328
 
5832
- // src/commands/commands/flip-drawings.command.ts
5833
- /**
5834
- * The command to flip sheet drawing elements
5835
- */
5836
- const FlipSheetDrawingCommand = {
5837
- id: "sheet.command.toggle-flip-drawings",
5838
- type: CommandType.COMMAND,
5839
- handler: (accessor, params) => {
5840
- if (!params) return false;
5841
- const commandService = accessor.get(ICommandService);
5842
- const undoRedoService = accessor.get(IUndoRedoService);
5843
- const sheetDrawingService = accessor.get(ISheetDrawingService);
5844
- const sheetSkeletonService = accessor.get(SheetSkeletonService);
5845
- const { drawings } = params;
5846
- const flipH = params.flipH;
5847
- const flipV = params.flipV;
5848
- const unitIds = [];
5849
- const updateParams = [];
5850
- for (const param of drawings) {
5851
- const { unitId, subUnitId, drawingId } = param;
5852
- unitIds.push(unitId);
5853
- const drawingData = sheetDrawingService.getDrawingData(unitId, subUnitId);
5854
- const existing = drawingData === null || drawingData === void 0 ? void 0 : drawingData[drawingId];
5855
- if (!existing) continue;
5856
- const skeleton = sheetSkeletonService.getSkeleton(unitId, subUnitId);
5857
- if (!skeleton) continue;
5858
- const transform = { ...existing.transform };
5859
- if (flipH) transform.flipX = !transform.flipX;
5860
- if (flipV) transform.flipY = !transform.flipY;
5861
- const sheetTransform = transformToDrawingPosition(transform, skeleton);
5862
- const axisAlignSheetTransform = transformToAxisAlignPosition(transform, skeleton);
5863
- const updateParamItem = {
5864
- unitId,
5865
- subUnitId,
5866
- drawingType: existing.drawingType,
5867
- drawingId,
5868
- transform,
5869
- sheetTransform,
5870
- axisAlignSheetTransform
5871
- };
5872
- if (existing.drawingType === DrawingTypeEnum.DRAWING_IMAGE) {
5873
- const scene = getSceneByDrawingSearch(accessor, unitId);
5874
- if (scene) {
5875
- const drawingShapeKey = getDrawingShapeKeyByDrawingSearch({
5876
- unitId,
5877
- subUnitId,
5878
- drawingId
5879
- });
5880
- const imageShape = scene.getObject(drawingShapeKey);
5881
- if (imageShape) {
5882
- const srcRect = imageShape.srcRect;
5883
- if (srcRect) {
5884
- let newSrcRect;
5885
- const { left = 0, top = 0, right = 0, bottom = 0 } = srcRect;
5886
- if (flipH) {
5887
- const centerX = left + (right - left) / 2;
5888
- newSrcRect = {
5889
- left: centerX - (right - left) / 2,
5890
- top,
5891
- right: centerX + (right - left) / 2,
5892
- bottom
5893
- };
5894
- }
5895
- if (flipV) {
5896
- const centerY = top + (bottom - top) / 2;
5897
- newSrcRect = {
5898
- left,
5899
- top: centerY - (bottom - top) / 2,
5900
- right,
5901
- bottom: centerY + (bottom - top) / 2
5902
- };
5903
- }
5904
- if (newSrcRect) updateParamItem.srcRect = newSrcRect;
5905
- }
5906
- }
5907
- }
5908
- }
5909
- updateParams.push(updateParamItem);
5910
- }
5911
- if (updateParams.length === 0) return false;
5912
- const { unitId: opUnitId, subUnitId: opSubUnitId, undo, redo, objects } = sheetDrawingService.getBatchUpdateOp(updateParams);
5913
- const updateMutation = {
5914
- id: SetDrawingApplyMutation.id,
5915
- params: {
5916
- unitId: opUnitId,
5917
- subUnitId: opSubUnitId,
5918
- op: redo,
5919
- objects,
5920
- type: DrawingApplyType.UPDATE
5921
- }
5922
- };
5923
- const undoUpdateMutation = {
5924
- id: SetDrawingApplyMutation.id,
5925
- params: {
5926
- unitId: opUnitId,
5927
- subUnitId: opSubUnitId,
5928
- op: undo,
5929
- objects,
5930
- type: DrawingApplyType.UPDATE
5931
- }
5932
- };
5933
- if (sequenceExecute([updateMutation], commandService).result) {
5934
- undoRedoService.pushUndoRedo({
5935
- unitID: opUnitId,
5936
- undoMutations: [undoUpdateMutation, {
5937
- id: ClearSheetDrawingTransformerOperation.id,
5938
- params: unitIds
5939
- }],
5940
- redoMutations: [updateMutation, {
5941
- id: ClearSheetDrawingTransformerOperation.id,
5942
- params: unitIds
5943
- }]
5944
- });
5945
- return true;
5946
- }
5947
- return false;
5948
- }
5949
- };
5950
- function getSceneByDrawingSearch(accessor, unitId) {
5951
- const render = accessor.get(IRenderManagerService).getRenderUnitById(unitId);
5952
- if (!render) return null;
5953
- return render.scene;
5954
- }
5955
-
5956
6329
  // src/controllers/shortcuts/drawing.shortcut.ts
5957
6330
  function whenSheetDrawingFocused(contextService) {
5958
6331
  return contextService.getContextValue(FOCUSING_SHEET) && !contextService.getContextValue(FOCUSING_FX_BAR_EDITOR) && !contextService.getContextValue(FOCUSING_PANEL_EDITOR) && contextService.getContextValue(FOCUSING_COMMON_DRAWINGS) && !contextService.getContextValue(FOCUSING_SHAPE_TEXT_EDITOR);
@@ -6336,11 +6709,13 @@ let MobileDrawingPopupMenuController = class MobileDrawingPopupMenuController ex
6336
6709
  _getFloatingObjectMenuItems() {
6337
6710
  return this._menuManagerService.getFlatMenuByPositionKey(FloatingObjectToolbarPosition.SHEET).flatMap(({ item }, index) => {
6338
6711
  if (!item || item.type !== MenuItemType.BUTTON || !item.title) return [];
6712
+ const { icon, params } = item;
6339
6713
  return [{
6340
6714
  label: item.title,
6715
+ ...typeof icon === "string" ? { icon } : {},
6341
6716
  index: 100 + index,
6342
6717
  commandId: item.commandId ?? item.id,
6343
- commandParams: typeof item.params === "function" ? item.params() : item.params,
6718
+ commandParams: typeof params === "function" ? params.call(item) : params,
6344
6719
  disable: false
6345
6720
  }];
6346
6721
  });
@@ -6866,11 +7241,13 @@ let DrawingPopupMenuController = class DrawingPopupMenuController extends RxDisp
6866
7241
  _getFloatingObjectMenuItems() {
6867
7242
  return this._menuManagerService.getFlatMenuByPositionKey(FloatingObjectToolbarPosition.SHEET).flatMap(({ item }, index) => {
6868
7243
  if (!item || item.type !== MenuItemType.BUTTON || !item.title) return [];
7244
+ const { icon, params } = item;
6869
7245
  return [{
6870
7246
  label: item.title,
7247
+ ...typeof icon === "string" ? { icon } : {},
6871
7248
  index: 100 + index,
6872
7249
  commandId: item.commandId ?? item.id,
6873
- commandParams: typeof item.params === "function" ? item.params() : item.params,
7250
+ commandParams: typeof params === "function" ? params.call(item) : params,
6874
7251
  disable: false
6875
7252
  }];
6876
7253
  });