@univerjs/docs-drawing-ui 0.25.1 → 1.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/lib/cjs/index.js +1864 -1522
  2. package/lib/cjs/locale/ar-SA.js +5 -0
  3. package/lib/cjs/locale/ca-ES.js +5 -0
  4. package/lib/cjs/locale/de-DE.js +5 -0
  5. package/lib/cjs/locale/en-US.js +5 -0
  6. package/lib/cjs/locale/es-ES.js +5 -0
  7. package/lib/cjs/locale/fa-IR.js +5 -0
  8. package/lib/cjs/locale/fr-FR.js +5 -0
  9. package/lib/cjs/locale/id-ID.js +5 -0
  10. package/lib/cjs/locale/it-IT.js +5 -0
  11. package/lib/cjs/locale/ja-JP.js +5 -0
  12. package/lib/cjs/locale/ko-KR.js +5 -0
  13. package/lib/cjs/locale/pl-PL.js +5 -0
  14. package/lib/cjs/locale/pt-BR.js +5 -0
  15. package/lib/cjs/locale/ru-RU.js +5 -0
  16. package/lib/cjs/locale/sk-SK.js +5 -0
  17. package/lib/cjs/locale/vi-VN.js +5 -0
  18. package/lib/cjs/locale/zh-CN.js +5 -0
  19. package/lib/cjs/locale/zh-HK.js +5 -0
  20. package/lib/cjs/locale/zh-TW.js +5 -0
  21. package/lib/es/index.js +1860 -1522
  22. package/lib/es/locale/ar-SA.js +5 -0
  23. package/lib/es/locale/ca-ES.js +5 -0
  24. package/lib/es/locale/de-DE.js +5 -0
  25. package/lib/es/locale/en-US.js +5 -0
  26. package/lib/es/locale/es-ES.js +5 -0
  27. package/lib/es/locale/fa-IR.js +5 -0
  28. package/lib/es/locale/fr-FR.js +5 -0
  29. package/lib/es/locale/id-ID.js +5 -0
  30. package/lib/es/locale/it-IT.js +5 -0
  31. package/lib/es/locale/ja-JP.js +5 -0
  32. package/lib/es/locale/ko-KR.js +5 -0
  33. package/lib/es/locale/pl-PL.js +5 -0
  34. package/lib/es/locale/pt-BR.js +5 -0
  35. package/lib/es/locale/ru-RU.js +5 -0
  36. package/lib/es/locale/sk-SK.js +5 -0
  37. package/lib/es/locale/vi-VN.js +5 -0
  38. package/lib/es/locale/zh-CN.js +5 -0
  39. package/lib/es/locale/zh-HK.js +5 -0
  40. package/lib/es/locale/zh-TW.js +5 -0
  41. package/lib/index.js +1860 -1522
  42. package/lib/locale/ar-SA.js +5 -0
  43. package/lib/locale/ca-ES.js +5 -0
  44. package/lib/locale/de-DE.js +5 -0
  45. package/lib/locale/en-US.js +5 -0
  46. package/lib/locale/es-ES.js +5 -0
  47. package/lib/locale/fa-IR.js +5 -0
  48. package/lib/locale/fr-FR.js +5 -0
  49. package/lib/locale/id-ID.js +5 -0
  50. package/lib/locale/it-IT.js +5 -0
  51. package/lib/locale/ja-JP.js +5 -0
  52. package/lib/locale/ko-KR.js +5 -0
  53. package/lib/locale/pl-PL.js +5 -0
  54. package/lib/locale/pt-BR.js +5 -0
  55. package/lib/locale/ru-RU.js +5 -0
  56. package/lib/locale/sk-SK.js +5 -0
  57. package/lib/locale/vi-VN.js +5 -0
  58. package/lib/locale/zh-CN.js +5 -0
  59. package/lib/locale/zh-HK.js +5 -0
  60. package/lib/locale/zh-TW.js +5 -0
  61. package/lib/types/commands/commands/insert-shape.command.d.ts +18 -0
  62. package/lib/types/controllers/components.controller.d.ts +22 -0
  63. package/lib/types/controllers/render-controllers/doc-drawing-transform-update.controller.d.ts +67 -3
  64. package/lib/types/controllers/{doc-drawing.controller.d.ts → ui.controller.d.ts} +2 -3
  65. package/lib/types/index.d.ts +2 -0
  66. package/lib/types/locale/en-US.d.ts +7 -0
  67. package/lib/types/locale/types.d.ts +18 -0
  68. package/lib/types/menu/image.menu.d.ts +4 -2
  69. package/lib/types/menu/shape.menu.d.ts +26 -0
  70. package/lib/types/views/{printing-float-dom/index.d.ts → DocPrintingFloatDom.d.ts} +3 -1
  71. package/lib/types/views/doc-image-panel/DocDrawingPanel.d.ts +1 -1
  72. package/lib/types/views/doc-image-panel/DocDrawingPosition.d.ts +1 -1
  73. package/lib/types/views/doc-image-panel/DocDrawingTextWrap.d.ts +1 -1
  74. package/lib/umd/index.js +1 -1
  75. package/lib/umd/locale/ar-SA.js +1 -1
  76. package/lib/umd/locale/ca-ES.js +1 -1
  77. package/lib/umd/locale/de-DE.js +1 -1
  78. package/lib/umd/locale/en-US.js +1 -1
  79. package/lib/umd/locale/es-ES.js +1 -1
  80. package/lib/umd/locale/fa-IR.js +1 -1
  81. package/lib/umd/locale/fr-FR.js +1 -1
  82. package/lib/umd/locale/id-ID.js +1 -1
  83. package/lib/umd/locale/it-IT.js +1 -1
  84. package/lib/umd/locale/ja-JP.js +1 -1
  85. package/lib/umd/locale/ko-KR.js +1 -1
  86. package/lib/umd/locale/pl-PL.js +1 -1
  87. package/lib/umd/locale/pt-BR.js +1 -1
  88. package/lib/umd/locale/ru-RU.js +1 -1
  89. package/lib/umd/locale/sk-SK.js +1 -1
  90. package/lib/umd/locale/vi-VN.js +1 -1
  91. package/lib/umd/locale/zh-CN.js +1 -1
  92. package/lib/umd/locale/zh-HK.js +1 -1
  93. package/lib/umd/locale/zh-TW.js +1 -1
  94. package/package.json +13 -12
package/lib/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import { ArrangeTypeEnum, BooleanNumber, BuildTextUtils, COLORS, CommandType, DOCS_ZEN_EDITOR_UNIT_ID_KEY, DOC_DRAWING_PRINTING_COMPONENT_KEY, DependentOn, Direction, Disposable, DisposableCollection, DocumentFlavor, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, FOCUSING_DOC, FOCUSING_UNIVER_EDITOR, ICommandService, IConfigService, IContextService, IUniverInstanceService, Inject, Injector, JSONX, LifecycleService, LifecycleStages, LocaleService, MemoryCursor, ObjectRelativeFromH, ObjectRelativeFromV, Plugin, PositionedObjectLayoutType, RedoCommand, RxDisposable, TextX, TextXActionType, Tools, UndoCommand, UniverInstanceType, WrapTextType, fromEventSubject, generateRandomId, isInternalEditorID, merge, throttle, toDisposable } from "@univerjs/core";
2
- import { IDocDrawingService, UniverDocsDrawingPlugin } from "@univerjs/docs-drawing";
3
- import { DocSelectionManagerService, DocSkeletonManagerService, RichTextEditingMutation } from "@univerjs/docs";
4
- import { DOC_CONTENT_INSERT_MENU_ID, DocCanvasPopManagerService, DocContentInsertService, DocPrintInterceptorService, DocSelectionRenderService, EMPTY_PARAGRAPH_MENU_ID, IEditorService, INSERT_BELLOW_MENU_ID, NodePositionConvertToCursor, SetDocZoomRatioOperation, TEXT_RANGE_LAYER_INDEX, VIEWPORT_KEY, docDrawingPositionToTransform, getAnchorBounding, getCustomBlockIdsInSelections, getDocObject, getOneTextSelectionRange, getRichTextEditPath } from "@univerjs/docs-ui";
1
+ import { AlignTypeH, AlignTypeV, ArrangeTypeEnum, BooleanNumber, BuildTextUtils, COLORS, CommandType, DOC_DRAWING_PRINTING_COMPONENT_KEY, DependentOn, Direction, Disposable, DisposableCollection, DocumentFlavor, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, FOCUSING_DOC, FOCUSING_UNIVER_EDITOR, ICommandService, IConfigService, IContextService, IUniverInstanceService, Inject, Injector, JSONX, LifecycleService, LifecycleStages, LocaleService, MemoryCursor, ObjectRelativeFromH, ObjectRelativeFromV, Plugin, PositionedObjectLayoutType, RedoCommand, RxDisposable, TextX, TextXActionType, Tools, UndoCommand, UniverInstanceType, WrapTextType, fromEventSubject, generateRandomId, getRichTextEditPath, isInternalEditorID, merge, throttle, toDisposable } from "@univerjs/core";
2
+ import { IDocDrawingService, UniverDocsDrawingPlugin, getDocDrawingRenderOrder } from "@univerjs/docs-drawing";
3
+ import { DocContentInsertService, DocSelectionManagerService, DocSkeletonManagerService, RichTextEditingMutation } from "@univerjs/docs";
4
+ import { DOC_CONTENT_INSERT_MENU_ID, DOC_PARAGRAPH_T_INSERT_BELOW_MENU_ID, DOC_PARAGRAPH_T_INSERT_MENU_ID, DocCanvasPopManagerService, DocPrintInterceptorService, DocSelectionRenderService, EMPTY_PARAGRAPH_MENU_ID, IEditorService, INSERT_BELLOW_MENU_ID, NodePositionConvertToCursor, SetDocZoomRatioOperation, TEXT_RANGE_LAYER_INDEX, VIEWPORT_KEY, docDrawingPositionToTransform, getAnchorBounding, getCustomBlockIdsInSelections, getDocObject, getOneTextSelectionRange } from "@univerjs/docs-ui";
5
5
  import { CURSOR_TYPE, DocumentEditArea, DocumentSkeletonPageType, IRenderManagerService, Liquid, PageLayoutType, Rect, TRANSFORM_CHANGE_OBSERVABLE_TYPE, Vector2, getColor, getCurrentTypeOfRenderer, getDocsTableRenderViewport, getTableIdAndSliceIndex } from "@univerjs/engine-render";
6
6
  import { Checkbox, InputNumber, MessageType, Radio, RadioGroup, Select, clsx, render, unmount } from "@univerjs/design";
7
- import { DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_WIDTH_LIMIT, IDrawingManagerService, IImageIoService, ImageUploadStatusType, UniverDrawingPlugin, getDrawingImageAllowSize, getDrawingShapeKeyByDrawingSearch, getImageSize } from "@univerjs/drawing";
7
+ import { DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_WIDTH_LIMIT, IDrawingManagerService, IImageIoService, ImageSourceType, ImageUploadStatusType, UniverDrawingPlugin, getDrawingImageAllowSize, getDrawingShapeKeyByDrawingSearch, getImageSize } from "@univerjs/drawing";
8
8
  import { CanvasFloatDomService, ComponentManager, ContextMenuGroup, ContextMenuPosition, ILocalFileService, IMenuManagerService, IMessageService, IShortcutService, ISidebarService, KeyCode, MenuItemType, PrintFloatDomSingle, RibbonInsertGroup, UniverUIPlugin, connectInjector, getMenuHiddenObservable, useDependency } from "@univerjs/ui";
9
9
  import { BehaviorSubject, Observable, debounceTime, filter, map, of, switchMap, takeUntil } from "rxjs";
10
10
  import { COMPONENT_IMAGE_POPUP_MENU, DrawingCommonPanel, DrawingRenderService, ImageCropperObject, ImageResetSizeOperation, OpenImageCropOperation, UniverDrawingUIPlugin } from "@univerjs/drawing-ui";
@@ -306,7 +306,7 @@ const UngroupDocDrawingCommand = {
306
306
  };
307
307
 
308
308
  //#endregion
309
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
309
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
310
310
  function _typeof(o) {
311
311
  "@babel/helpers - typeof";
312
312
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -317,7 +317,7 @@ function _typeof(o) {
317
317
  }
318
318
 
319
319
  //#endregion
320
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
320
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
321
321
  function toPrimitive(t, r) {
322
322
  if ("object" != _typeof(t) || !t) return t;
323
323
  var e = t[Symbol.toPrimitive];
@@ -330,14 +330,14 @@ function toPrimitive(t, r) {
330
330
  }
331
331
 
332
332
  //#endregion
333
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
333
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
334
334
  function toPropertyKey(t) {
335
335
  var i = toPrimitive(t, "string");
336
336
  return "symbol" == _typeof(i) ? i : i + "";
337
337
  }
338
338
 
339
339
  //#endregion
340
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
340
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
341
341
  function _defineProperty(e, r, t) {
342
342
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
343
343
  value: t,
@@ -360,7 +360,7 @@ var DocRefreshDrawingsService = class {
360
360
  };
361
361
 
362
362
  //#endregion
363
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
363
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
364
364
  function __decorateParam(paramIndex, decorator) {
365
365
  return function(target, key) {
366
366
  decorator(target, key, paramIndex);
@@ -368,7 +368,7 @@ function __decorateParam(paramIndex, decorator) {
368
368
  }
369
369
 
370
370
  //#endregion
371
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
371
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
372
372
  function __decorate(decorators, target, key, desc) {
373
373
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
374
374
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -593,6 +593,7 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
593
593
  zeroLeft: docsLeft
594
594
  });
595
595
  }
596
+ this._updateDrawingsEditStatus();
596
597
  }));
597
598
  }
598
599
  _findSegmentIdByDrawingId(drawingId) {
@@ -618,6 +619,7 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
618
619
  if (viewModel == null || docDataModel == null) return;
619
620
  const { drawings = {} } = docDataModel.getSnapshot();
620
621
  const isEditBody = viewModel.getEditArea() === DocumentEditArea.BODY;
622
+ const isDocInputFocusing = this._docSelectionRenderService.isFocusing;
621
623
  for (const key of Object.keys(drawings)) {
622
624
  const drawing = drawings[key];
623
625
  const objectKey = getDrawingShapeKeyByDrawingSearch({
@@ -629,8 +631,9 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
629
631
  if (drawingShapes.length) for (const shape of drawingShapes) {
630
632
  scene.detachTransformerFrom(shape);
631
633
  try {
632
- shape.setOpacity(.5);
634
+ shape.setOpacity(isDocInputFocusing ? .5 : 1);
633
635
  } catch (e) {}
636
+ if (!isDocInputFocusing) continue;
634
637
  if (isEditBody && drawing.isMultiTransform !== BooleanNumber.TRUE || !isEditBody && drawing.isMultiTransform === BooleanNumber.TRUE) {
635
638
  if (drawing.allowTransform !== false) scene.attachTransformerTo(shape);
636
639
  try {
@@ -649,6 +652,12 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
649
652
  this.disposeWithMe(viewModel.editAreaChange$.subscribe(() => {
650
653
  this._updateDrawingsEditStatus();
651
654
  }));
655
+ this.disposeWithMe(this._docSelectionRenderService.onFocus$.subscribe(() => {
656
+ this._updateDrawingsEditStatus();
657
+ }));
658
+ this.disposeWithMe(this._docSelectionRenderService.onBlur$.subscribe(() => {
659
+ this._updateDrawingsEditStatus();
660
+ }));
652
661
  this.disposeWithMe(this._docRefreshDrawingsService.refreshDrawings$.subscribe((skeleton) => {
653
662
  if (skeleton == null) return;
654
663
  queueMicrotask(() => {
@@ -705,6 +714,69 @@ const InsertDocImageCommand = {
705
714
  }
706
715
  };
707
716
 
717
+ //#endregion
718
+ //#region src/commands/commands/insert-shape.command.ts
719
+ const DOC_SHAPE_FILL = "#3A60F7";
720
+ const DOC_SHAPE_STROKE = "#1D3EA6";
721
+ function createShapeSvgSource(shape, width, height) {
722
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" fill="none">${shape === "ellipse" ? `<ellipse cx="${width / 2}" cy="${height / 2}" rx="${(width - 8) / 2}" ry="${(height - 8) / 2}" fill="${DOC_SHAPE_FILL}" stroke="${DOC_SHAPE_STROKE}" stroke-width="4" />` : `<rect x="4" y="4" width="${width - 8}" height="${height - 8}" rx="14" fill="${DOC_SHAPE_FILL}" stroke="${DOC_SHAPE_STROKE}" stroke-width="4" />`}</svg>`;
723
+ return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
724
+ }
725
+ function createDefaultDocTransform(width, height) {
726
+ return {
727
+ size: {
728
+ width,
729
+ height
730
+ },
731
+ positionH: {
732
+ relativeFrom: ObjectRelativeFromH.PAGE,
733
+ posOffset: 0
734
+ },
735
+ positionV: {
736
+ relativeFrom: ObjectRelativeFromV.PARAGRAPH,
737
+ posOffset: 0
738
+ },
739
+ angle: 0
740
+ };
741
+ }
742
+ function createShapeInsertCommand(shape, width, height, id) {
743
+ return {
744
+ id,
745
+ type: CommandType.COMMAND,
746
+ handler: async (accessor) => {
747
+ var _univerInstanceServic;
748
+ const commandService = accessor.get(ICommandService);
749
+ const unitId = (_univerInstanceServic = accessor.get(IUniverInstanceService).getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC)) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId();
750
+ if (!unitId) return false;
751
+ const docTransform = createDefaultDocTransform(width, height);
752
+ return commandService.executeCommand(InsertDocDrawingCommand.id, {
753
+ unitId,
754
+ drawings: [{
755
+ unitId,
756
+ subUnitId: unitId,
757
+ drawingId: generateRandomId(6),
758
+ drawingType: DrawingTypeEnum.DRAWING_IMAGE,
759
+ imageSourceType: ImageSourceType.BASE64,
760
+ source: createShapeSvgSource(shape, width, height),
761
+ transform: docDrawingPositionToTransform(docTransform),
762
+ docTransform,
763
+ behindDoc: BooleanNumber.FALSE,
764
+ title: "",
765
+ description: "",
766
+ layoutType: PositionedObjectLayoutType.INLINE,
767
+ wrapText: WrapTextType.BOTH_SIDES,
768
+ distB: 0,
769
+ distL: 0,
770
+ distR: 0,
771
+ distT: 0
772
+ }]
773
+ });
774
+ }
775
+ };
776
+ }
777
+ const InsertDocRectangleShapeCommand = createShapeInsertCommand("rectangle", 144, 96, "doc.command.insert-float-shape.rectangle");
778
+ const InsertDocEllipseShapeCommand = createShapeInsertCommand("ellipse", 112, 112, "doc.command.insert-float-shape.ellipse");
779
+
708
780
  //#endregion
709
781
  //#region src/commands/commands/update-doc-drawing.command.ts
710
782
  const WRAPPING_STYLE_TO_LAYOUT_TYPE = {
@@ -1624,23 +1696,95 @@ function ImageMenuFactory(accessor) {
1624
1696
  icon: "AddImageIcon",
1625
1697
  tooltip: "docs-drawing-ui.title",
1626
1698
  disabled$: getDisableWhenSelectionInTableObservable(accessor),
1627
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC, void 0, DOCS_ZEN_EDITOR_UNIT_ID_KEY)
1699
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1628
1700
  };
1629
1701
  }
1630
- function UploadFloatImageMenuFactory(_accessor) {
1702
+ function UploadFloatImageMenuFactory(accessor) {
1631
1703
  return {
1632
1704
  id: IMAGE_MENU_UPLOAD_FLOAT_ID,
1633
1705
  title: "docs-drawing-ui.upload.float",
1634
1706
  type: MenuItemType.BUTTON,
1635
1707
  icon: "AddImageIcon",
1636
- hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.UNIVER_DOC, void 0, DOCS_ZEN_EDITOR_UNIT_ID_KEY)
1708
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1709
+ };
1710
+ }
1711
+ function UploadFloatImageBelowMenuFactory(accessor) {
1712
+ return {
1713
+ id: `${IMAGE_MENU_UPLOAD_FLOAT_ID}.below`,
1714
+ commandId: IMAGE_MENU_UPLOAD_FLOAT_ID,
1715
+ title: "docs-drawing-ui.upload.float",
1716
+ type: MenuItemType.BUTTON,
1717
+ icon: "AddImageIcon",
1718
+ params: { paragraphMenuPlacement: "below" },
1719
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1720
+ };
1721
+ }
1722
+
1723
+ //#endregion
1724
+ //#region src/menu/shape.menu.ts
1725
+ const DOCS_SHAPE_MENU_ID = "doc.command.menu-insert-shape";
1726
+ const DOCS_SHAPE_BELOW_MENU_ID = "doc.command.menu-insert-shape.below";
1727
+ function ShapeMenuFactory(accessor) {
1728
+ return {
1729
+ id: DOCS_SHAPE_MENU_ID,
1730
+ type: MenuItemType.SUBITEMS,
1731
+ icon: "ShapeIcon",
1732
+ title: "docs-drawing-ui.shape.insert.title",
1733
+ tooltip: "docs-drawing-ui.shape.insert.title",
1734
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1735
+ };
1736
+ }
1737
+ function ShapeBelowMenuFactory(accessor) {
1738
+ return {
1739
+ id: DOCS_SHAPE_BELOW_MENU_ID,
1740
+ type: MenuItemType.SUBITEMS,
1741
+ icon: "ShapeIcon",
1742
+ title: "docs-drawing-ui.shape.insert.title",
1743
+ tooltip: "docs-drawing-ui.shape.insert.title",
1744
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1745
+ };
1746
+ }
1747
+ function InsertRectangleShapeMenuFactory(accessor) {
1748
+ return {
1749
+ id: InsertDocRectangleShapeCommand.id,
1750
+ title: "docs-drawing-ui.shape.insert.rectangle",
1751
+ type: MenuItemType.BUTTON,
1752
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1753
+ };
1754
+ }
1755
+ function InsertEllipseShapeMenuFactory(accessor) {
1756
+ return {
1757
+ id: InsertDocEllipseShapeCommand.id,
1758
+ title: "docs-drawing-ui.shape.insert.ellipse",
1759
+ type: MenuItemType.BUTTON,
1760
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1761
+ };
1762
+ }
1763
+ function InsertRectangleShapeBelowMenuFactory(accessor) {
1764
+ return {
1765
+ id: `${InsertDocRectangleShapeCommand.id}.below`,
1766
+ commandId: InsertDocRectangleShapeCommand.id,
1767
+ title: "docs-drawing-ui.shape.insert.rectangle",
1768
+ type: MenuItemType.BUTTON,
1769
+ params: { paragraphMenuPlacement: "below" },
1770
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1771
+ };
1772
+ }
1773
+ function InsertEllipseShapeBelowMenuFactory(accessor) {
1774
+ return {
1775
+ id: `${InsertDocEllipseShapeCommand.id}.below`,
1776
+ commandId: InsertDocEllipseShapeCommand.id,
1777
+ title: "docs-drawing-ui.shape.insert.ellipse",
1778
+ type: MenuItemType.BUTTON,
1779
+ params: { paragraphMenuPlacement: "below" },
1780
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1637
1781
  };
1638
1782
  }
1639
1783
 
1640
1784
  //#endregion
1641
1785
  //#region package.json
1642
1786
  var name = "@univerjs/docs-drawing-ui";
1643
- var version = "0.25.1";
1787
+ var version = "1.0.0-alpha.1";
1644
1788
 
1645
1789
  //#endregion
1646
1790
  //#region src/config/config.ts
@@ -1664,1587 +1808,1782 @@ const configSymbol = Symbol(DOCS_DRAWING_UI_PLUGIN_CONFIG_KEY);
1664
1808
  const defaultPluginConfig = {};
1665
1809
 
1666
1810
  //#endregion
1667
- //#region src/controllers/doc-drawing-notification.controller.ts
1668
- function getAddOrRemoveDrawings(actions) {
1669
- if (JSONX.isNoop(actions) || !Array.isArray(actions)) return null;
1670
- const drawingsOp = actions.find((action) => Array.isArray(action) && (action === null || action === void 0 ? void 0 : action[0]) === "drawings");
1671
- if (drawingsOp == null || !Array.isArray(drawingsOp) || drawingsOp.length < 3) return null;
1672
- if (typeof drawingsOp[1] === "string" && typeof drawingsOp[2] !== "object") return null;
1673
- if (Array.isArray(drawingsOp[1]) && typeof drawingsOp[1][1] !== "object") return null;
1674
- const drawings = [];
1675
- if (Array.isArray(drawingsOp === null || drawingsOp === void 0 ? void 0 : drawingsOp[1])) {
1676
- for (const op of drawingsOp) if (Array.isArray(op)) {
1677
- var _ref, _ref2;
1678
- drawings.push({
1679
- type: (op === null || op === void 0 || (_ref = op[1]) === null || _ref === void 0 ? void 0 : _ref.i) ? "add" : "remove",
1680
- drawingId: op === null || op === void 0 ? void 0 : op[0],
1681
- drawing: op === null || op === void 0 || (_ref2 = op[1]) === null || _ref2 === void 0 ? void 0 : _ref2.i
1682
- });
1811
+ //#region src/views/doc-image-panel/DocDrawingPosition.tsx
1812
+ const MIN_OFFSET = -1e3;
1813
+ const MAX_OFFSET = 1e3;
1814
+ const DocDrawingPosition = (props) => {
1815
+ const commandService = useDependency(ICommandService);
1816
+ const localeService = useDependency(LocaleService);
1817
+ const drawingManagerService = useDependency(IDrawingManagerService);
1818
+ const renderManagerService = useDependency(IRenderManagerService);
1819
+ const univerInstanceService = useDependency(IUniverInstanceService);
1820
+ const { drawings } = props;
1821
+ const drawingParam = drawings[0];
1822
+ if (drawingParam == null) return;
1823
+ const { unitId } = drawingParam;
1824
+ const documentDataModel = univerInstanceService.getUniverDocInstance(unitId);
1825
+ const documentFlavor = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getSnapshot().documentStyle.documentFlavor;
1826
+ const renderObject = renderManagerService.getRenderById(unitId);
1827
+ const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
1828
+ if (scene == null) return;
1829
+ const transformer = scene.getTransformerByCreate();
1830
+ const HORIZONTAL_RELATIVE_FROM = [
1831
+ {
1832
+ label: localeService.t("docs-drawing-ui.image-position.column"),
1833
+ value: String(ObjectRelativeFromH.COLUMN)
1834
+ },
1835
+ {
1836
+ label: localeService.t("docs-drawing-ui.image-position.page"),
1837
+ value: String(ObjectRelativeFromH.PAGE)
1838
+ },
1839
+ {
1840
+ label: localeService.t("docs-drawing-ui.image-position.margin"),
1841
+ value: String(ObjectRelativeFromH.MARGIN)
1683
1842
  }
1684
- } else {
1685
- var _drawingsOp$, _drawingsOp$2;
1686
- drawings.push({
1687
- type: ((_drawingsOp$ = drawingsOp[2]) === null || _drawingsOp$ === void 0 ? void 0 : _drawingsOp$.i) ? "add" : "remove",
1688
- drawingId: drawingsOp[1],
1689
- drawing: (_drawingsOp$2 = drawingsOp[2]) === null || _drawingsOp$2 === void 0 ? void 0 : _drawingsOp$2.i
1690
- });
1691
- }
1692
- return drawings;
1693
- }
1694
- function getReOrderedDrawings(actions) {
1695
- if (!Array.isArray(actions) || actions.length < 3 || actions[0] !== "drawingsOrder") return [];
1696
- const drawingIndexes = [];
1697
- for (let i = 1; i < actions.length; i++) {
1698
- const action = actions[i];
1699
- if (Array.isArray(action) && typeof action[0] === "number" && typeof action[1] === "object") drawingIndexes.push(action[0]);
1700
- else {
1701
- drawingIndexes.length = 0;
1702
- break;
1843
+ ];
1844
+ const VERTICAL_RELATIVE_FROM = [
1845
+ {
1846
+ label: localeService.t("docs-drawing-ui.image-position.line"),
1847
+ value: String(ObjectRelativeFromV.LINE),
1848
+ disabled: documentFlavor === DocumentFlavor.MODERN
1849
+ },
1850
+ {
1851
+ label: localeService.t("docs-drawing-ui.image-position.page"),
1852
+ value: String(ObjectRelativeFromV.PAGE),
1853
+ disabled: documentFlavor === DocumentFlavor.MODERN
1854
+ },
1855
+ {
1856
+ label: localeService.t("docs-drawing-ui.image-position.margin"),
1857
+ value: String(ObjectRelativeFromV.MARGIN),
1858
+ disabled: documentFlavor === DocumentFlavor.MODERN
1859
+ },
1860
+ {
1861
+ label: localeService.t("docs-drawing-ui.image-position.paragraph"),
1862
+ value: String(ObjectRelativeFromV.PARAGRAPH)
1703
1863
  }
1704
- }
1705
- return drawingIndexes;
1706
- }
1707
- let DocDrawingAddRemoveController = class DocDrawingAddRemoveController extends Disposable {
1708
- constructor(_univerInstanceService, _commandService, _drawingManagerService, _docDrawingService, _renderManagerService) {
1709
- super();
1710
- this._univerInstanceService = _univerInstanceService;
1711
- this._commandService = _commandService;
1712
- this._drawingManagerService = _drawingManagerService;
1713
- this._docDrawingService = _docDrawingService;
1714
- this._renderManagerService = _renderManagerService;
1715
- this._initialize();
1716
- }
1717
- _initialize() {
1718
- this._commandExecutedListener();
1719
- }
1720
- _commandExecutedListener() {
1721
- this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
1722
- if (command.id !== RichTextEditingMutation.id) return;
1723
- const { unitId, actions, isSync, syncer } = command.params;
1724
- const addOrRemoveDrawings = getAddOrRemoveDrawings(actions);
1725
- if (addOrRemoveDrawings != null) for (const { type, drawingId, drawing } of addOrRemoveDrawings) {
1726
- if (isSync && (drawing === null || drawing === void 0 ? void 0 : drawing.unitId) === syncer) continue;
1727
- if (type === "add") this._addDrawings(unitId, [drawing]);
1728
- else this._removeDrawings(unitId, [drawingId]);
1729
- }
1730
- }));
1731
- this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
1732
- if (command.id !== RichTextEditingMutation.id) return;
1733
- const { unitId, actions } = command.params;
1734
- if (getReOrderedDrawings(actions).length > 0) this._updateDrawingsOrder(unitId);
1735
- }));
1736
- this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
1737
- var _this$_univerInstance;
1738
- if (command.id !== UndoCommand.id && command.id !== RedoCommand.id) return;
1739
- const unitId = (_this$_univerInstance = this._univerInstanceService.getCurrentUniverDocInstance()) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getUnitId();
1740
- const focusedDrawings = this._drawingManagerService.getFocusDrawings();
1741
- if (unitId == null || focusedDrawings.length === 0) return;
1742
- const renderObject = this._renderManagerService.getRenderById(unitId);
1743
- const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
1744
- if (scene == null) return false;
1745
- scene.getTransformerByCreate().refreshControls();
1746
- }));
1747
- }
1748
- _addDrawings(unitId, drawings) {
1749
- const drawingManagerService = this._drawingManagerService;
1750
- const docDrawingService = this._docDrawingService;
1751
- const { subUnitId, redo: op, objects } = this._docDrawingService.getBatchAddOp(drawings);
1752
- drawingManagerService.applyJson1(unitId, subUnitId, op);
1753
- docDrawingService.applyJson1(unitId, subUnitId, op);
1754
- drawingManagerService.addNotification(objects);
1755
- docDrawingService.addNotification(objects);
1756
- }
1757
- _removeDrawings(unitId, drawingIds) {
1758
- const drawingManagerService = this._drawingManagerService;
1759
- const docDrawingService = this._docDrawingService;
1760
- const { subUnitId, redo: op, objects } = this._docDrawingService.getBatchRemoveOp(drawingIds.map((drawingId) => {
1864
+ ];
1865
+ const [disabled, setDisabled] = useState(true);
1866
+ const [hPosition, setHPosition] = useState({
1867
+ relativeFrom: ObjectRelativeFromH.PAGE,
1868
+ posOffset: 0
1869
+ });
1870
+ const [vPosition, setVPosition] = useState({
1871
+ relativeFrom: ObjectRelativeFromV.PAGE,
1872
+ posOffset: 0
1873
+ });
1874
+ const [followTextMove, setFollowTextMove] = useState(true);
1875
+ const [showPanel, setShowPanel] = useState(true);
1876
+ function handlePositionChange(direction, value) {
1877
+ var _renderManagerService;
1878
+ if (direction === "positionH") setHPosition(value);
1879
+ else setVPosition(value);
1880
+ const focusDrawings = drawingManagerService.getFocusDrawings();
1881
+ if (focusDrawings.length === 0) return;
1882
+ const drawings = focusDrawings.map((drawing) => {
1761
1883
  return {
1762
- unitId,
1763
- subUnitId: unitId,
1764
- drawingId
1884
+ unitId: drawing.unitId,
1885
+ subUnitId: drawing.subUnitId,
1886
+ drawingId: drawing.drawingId
1765
1887
  };
1766
- }));
1767
- drawingManagerService.applyJson1(unitId, subUnitId, op);
1768
- docDrawingService.applyJson1(unitId, subUnitId, op);
1769
- drawingManagerService.removeNotification(objects);
1770
- docDrawingService.removeNotification(objects);
1771
- }
1772
- _updateDrawingsOrder(unitId) {
1773
- const documentDataModel = this._univerInstanceService.getUniverDocInstance(unitId);
1774
- if (documentDataModel == null) return;
1775
- const drawingsOrder = documentDataModel.getSnapshot().drawingsOrder;
1776
- if (drawingsOrder == null) return;
1777
- const drawingManagerService = this._drawingManagerService;
1778
- const docDrawingService = this._docDrawingService;
1779
- drawingManagerService.setDrawingOrder(unitId, unitId, drawingsOrder);
1780
- docDrawingService.setDrawingOrder(unitId, unitId, drawingsOrder);
1781
- const objects = {
1782
- unitId,
1783
- subUnitId: unitId,
1784
- drawingIds: drawingsOrder
1785
- };
1786
- drawingManagerService.orderNotification(objects);
1787
- docDrawingService.orderNotification(objects);
1888
+ });
1889
+ commandService.executeCommand(UpdateDrawingDocTransformCommand.id, {
1890
+ unitId: focusDrawings[0].unitId,
1891
+ subUnitId: focusDrawings[0].unitId,
1892
+ drawings: drawings.map((drawing) => ({
1893
+ drawingId: drawing.drawingId,
1894
+ key: direction,
1895
+ value
1896
+ }))
1897
+ });
1898
+ const docSelectionRenderService = (_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(DocSelectionRenderService);
1899
+ if (docSelectionRenderService) docSelectionRenderService.blur();
1900
+ transformer.refreshControls();
1788
1901
  }
1789
- };
1790
- DocDrawingAddRemoveController = __decorate([
1791
- __decorateParam(0, IUniverInstanceService),
1792
- __decorateParam(1, ICommandService),
1793
- __decorateParam(2, IDrawingManagerService),
1794
- __decorateParam(3, IDocDrawingService),
1795
- __decorateParam(4, IRenderManagerService)
1796
- ], DocDrawingAddRemoveController);
1797
-
1798
- //#endregion
1799
- //#region src/views/printing-float-dom/index.tsx
1800
- const DocPrintingFloatDom = (props) => {
1801
- const { floatDomInfos, scene, offset, bound } = props;
1802
- const width = bound.right - bound.left;
1803
- const height = bound.bottom - bound.top;
1804
- return /* @__PURE__ */ jsx("div", {
1805
- className: "univer-absolute univer-left-0 univer-top-0",
1806
- children: useMemo(() => floatDomInfos.map((info) => {
1807
- const { width = 0, height = 0, left = 0, top = 0 } = info.transform;
1808
- const domPos = calcDocFloatDomPositionByRect({
1809
- left,
1810
- right: left + width,
1811
- top,
1812
- bottom: top + height
1813
- }, scene);
1814
- const floatDom = {
1815
- position$: new BehaviorSubject(domPos),
1816
- position: domPos,
1817
- id: info.drawingId,
1818
- componentKey: info.componentKey,
1819
- onPointerMove: () => {},
1820
- onPointerDown: () => {},
1821
- onPointerUp: () => {},
1822
- onWheel: () => {},
1823
- unitId: info.unitId,
1824
- data: info.data
1825
- };
1826
- return [info.drawingId, floatDom];
1827
- }).filter(([_, floatDom]) => !(floatDom.position.endX < 0 || floatDom.position.endY < 0 || floatDom.position.startX > width || floatDom.position.startY > height)), [
1828
- floatDomInfos,
1829
- scene,
1830
- offset,
1831
- width,
1832
- height
1833
- ]).map(([id, floatDom]) => /* @__PURE__ */ jsx(PrintFloatDomSingle, {
1834
- layer: floatDom,
1835
- id,
1836
- position: floatDom.position
1837
- }, id))
1838
- });
1839
- };
1840
-
1841
- //#endregion
1842
- //#region src/controllers/doc-drawing-printing.controller.tsx
1843
- let DocDrawingPrintingController = class DocDrawingPrintingController extends Disposable {
1844
- constructor(_docPrintInterceptorService, _drawingRenderService, _drawingManagerService, _componetManager, _injector) {
1845
- super();
1846
- this._docPrintInterceptorService = _docPrintInterceptorService;
1847
- this._drawingRenderService = _drawingRenderService;
1848
- this._drawingManagerService = _drawingManagerService;
1849
- this._componetManager = _componetManager;
1850
- this._injector = _injector;
1851
- this._initPrinting();
1852
- this._initPrintingDom();
1853
- }
1854
- _initPrinting() {
1855
- this.disposeWithMe(this._docPrintInterceptorService.interceptor.intercept(this._docPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT, { handler: (_param, pos, next) => {
1856
- const { unitId, scene } = pos;
1857
- const unitData = this._drawingManagerService.getDrawingDataForUnit(unitId);
1858
- const subUnitData = unitData === null || unitData === void 0 ? void 0 : unitData[unitId];
1859
- if (subUnitData) subUnitData.order.forEach((id) => {
1860
- const drawing = subUnitData.data[id];
1861
- if (drawing.drawingType !== DrawingTypeEnum.DRAWING_CHART && drawing.drawingType !== DrawingTypeEnum.DRAWING_DOM) this._drawingRenderService.renderDrawing(drawing, scene);
1862
- });
1863
- return next();
1864
- } }));
1865
- }
1866
- _initPrintingDom() {
1867
- this.disposeWithMe(this._docPrintInterceptorService.interceptor.intercept(this._docPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT, { handler: (disposableCollection, pos, next) => {
1868
- const { unitId } = pos;
1869
- const unitData = this._drawingManagerService.getDrawingDataForUnit(unitId);
1870
- const subUnitData = unitData === null || unitData === void 0 ? void 0 : unitData[unitId];
1871
- if (subUnitData) {
1872
- const floatDomInfos = subUnitData.order.map((id) => {
1873
- const drawing = subUnitData.data[id];
1874
- if (drawing.drawingType === DrawingTypeEnum.DRAWING_CHART) return {
1875
- ...drawing,
1876
- componentKey: this._componetManager.get(DOC_DRAWING_PRINTING_COMPONENT_KEY)
1877
- };
1878
- if (drawing.drawingType === DrawingTypeEnum.DRAWING_DOM) {
1879
- const printingComponentKey = this._docPrintInterceptorService.getPrintComponent(drawing.componentKey);
1880
- return {
1881
- ...drawing,
1882
- componentKey: this._componetManager.get(printingComponentKey || drawing.componentKey)
1883
- };
1884
- }
1885
- return null;
1886
- }).filter(Boolean);
1887
- render(/* @__PURE__ */ jsx(connectInjector(DocPrintingFloatDom, this._injector), {
1888
- unitId,
1889
- floatDomInfos,
1890
- scene: pos.scene,
1891
- skeleton: pos.skeleton,
1892
- offset: pos.offset,
1893
- bound: pos.bound
1894
- }), pos.root);
1895
- disposableCollection === null || disposableCollection === void 0 || disposableCollection.add(() => {
1896
- unmount(pos.root);
1897
- });
1898
- return next(disposableCollection);
1899
- }
1900
- } }));
1901
- }
1902
- };
1903
- DocDrawingPrintingController = __decorate([
1904
- __decorateParam(0, Inject(DocPrintInterceptorService)),
1905
- __decorateParam(1, Inject(DrawingRenderService)),
1906
- __decorateParam(2, IDrawingManagerService),
1907
- __decorateParam(3, Inject(ComponentManager)),
1908
- __decorateParam(4, Inject(Injector))
1909
- ], DocDrawingPrintingController);
1910
-
1911
- //#endregion
1912
- //#region src/controllers/render-controllers/doc-drawing-transform-update.controller.ts
1913
- function getDocsTableCellDrawingOffset(unitId, table, row, cell) {
1914
- const sourceTableId = getTableIdAndSliceIndex(table.tableId).tableId;
1915
- const viewport = getDocsTableRenderViewport(unitId, sourceTableId);
1916
- const scrollLeft = viewport && viewport.contentWidth > viewport.viewportWidth ? viewport.scrollLeft : 0;
1917
- return {
1918
- left: table.left + cell.left - scrollLeft + cell.marginLeft,
1919
- top: table.top + row.top + cell.marginTop
1920
- };
1921
- }
1922
- let DocDrawingTransformUpdateController = class DocDrawingTransformUpdateController extends Disposable {
1923
- constructor(_context, _docSkeletonManagerService, _commandService, _editorService, _drawingManagerService, _docRefreshDrawingsService, _univerInstanceService, _lifecycleService) {
1924
- super();
1925
- this._context = _context;
1926
- this._docSkeletonManagerService = _docSkeletonManagerService;
1927
- this._commandService = _commandService;
1928
- this._editorService = _editorService;
1929
- this._drawingManagerService = _drawingManagerService;
1930
- this._docRefreshDrawingsService = _docRefreshDrawingsService;
1931
- this._univerInstanceService = _univerInstanceService;
1932
- this._lifecycleService = _lifecycleService;
1933
- _defineProperty(this, "_liquid", new Liquid());
1934
- this._initialize();
1935
- this._commandExecutedListener();
1936
- }
1937
- _initialize() {
1938
- this._initialRenderRefresh();
1939
- this._drawingInitializeListener();
1940
- this._initResize();
1941
- }
1942
- _initialRenderRefresh() {
1943
- this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe((documentSkeleton) => {
1944
- if (documentSkeleton == null) return;
1945
- this._refreshDrawing(documentSkeleton);
1946
- }));
1947
- this.disposeWithMe(this._docRefreshDrawingsService.refreshDrawings$.subscribe((skeleton) => {
1948
- if (skeleton == null) return;
1949
- this._refreshDrawing(skeleton);
1950
- }));
1951
- }
1952
- _commandExecutedListener() {
1953
- const updateCommandList = [RichTextEditingMutation.id, SetDocZoomRatioOperation.id];
1954
- this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
1955
- if (updateCommandList.includes(command.id)) {
1956
- const { unitId: commandUnitId } = command.params;
1957
- const { unitId, mainComponent } = this._context;
1958
- if (commandUnitId !== unitId) return;
1959
- const skeleton = this._docSkeletonManagerService.getSkeleton();
1960
- if (skeleton == null) return;
1961
- if (this._editorService.isEditor(unitId) && unitId !== DOCS_ZEN_EDITOR_UNIT_ID_KEY) {
1962
- mainComponent === null || mainComponent === void 0 || mainComponent.makeDirty();
1963
- return;
1964
- }
1965
- this._refreshDrawing(skeleton);
1966
- }
1967
- }));
1968
- }
1969
- _initResize() {
1970
- this.disposeWithMe(fromEventSubject(this._context.engine.onTransformChange$).pipe(filter((evt) => evt.type === TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize), debounceTime(16)).subscribe(() => {
1971
- var _scene$getTransformer;
1972
- const skeleton = this._docSkeletonManagerService.getSkeleton();
1973
- const { scene } = this._context;
1974
- (_scene$getTransformer = scene.getTransformer()) === null || _scene$getTransformer === void 0 || _scene$getTransformer.refreshControls();
1975
- this._refreshDrawing(skeleton);
1976
- }));
1977
- }
1978
- _refreshDrawing(skeleton) {
1902
+ function handleHorizontalRelativeFromChange(value) {
1903
+ var _renderManagerService2;
1904
+ const prevRelativeFrom = hPosition.relativeFrom;
1905
+ const prevPosOffset = hPosition.posOffset;
1906
+ const relativeFrom = Number(value);
1907
+ if (prevRelativeFrom === relativeFrom) return;
1908
+ const focusDrawings = drawingManagerService.getFocusDrawings();
1909
+ if (focusDrawings.length === 0) return;
1910
+ const drawingId = focusDrawings[0].drawingId;
1911
+ const unitId = focusDrawings[0].unitId;
1912
+ let drawing = null;
1913
+ let pageMarginLeft = 0;
1914
+ const skeleton = (_renderManagerService2 = renderManagerService.getRenderById(unitId)) === null || _renderManagerService2 === void 0 ? void 0 : _renderManagerService2.with(DocSkeletonManagerService).getSkeleton();
1979
1915
  const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
1980
- const { mainComponent, unitId } = this._context;
1981
- const documentComponent = mainComponent;
1982
- if (!skeletonData) return;
1983
- const { left: docsLeft, top: docsTop, pageLayoutType, pageMarginLeft, pageMarginTop } = documentComponent;
1916
+ if (skeletonData == null) return;
1984
1917
  const { pages, skeHeaders, skeFooters } = skeletonData;
1985
- const updateDrawingMap = {};
1986
- this._liquid.reset();
1987
- /**
1988
- * TODO: @DR-Univer We should not refresh all floating elements, but instead make a diff.
1989
- */
1990
- for (let i = 0, len = pages.length; i < len; i++) {
1991
- const page = pages[i];
1992
- const { headerId, footerId, pageWidth } = page;
1993
- if (headerId) {
1994
- var _skeHeaders$get;
1995
- const headerPage = (_skeHeaders$get = skeHeaders.get(headerId)) === null || _skeHeaders$get === void 0 ? void 0 : _skeHeaders$get.get(pageWidth);
1996
- if (headerPage) {
1997
- this._calculateDrawingPosition(unitId, headerPage, docsLeft, docsTop, updateDrawingMap, headerPage.marginTop, page.marginLeft);
1998
- this._calculateTableCellDrawingPositions(unitId, headerPage, docsLeft, docsTop, updateDrawingMap, headerPage.marginTop, page.marginLeft);
1999
- }
1918
+ for (const page of pages) {
1919
+ var _skeHeaders$get, _skeFooters$get;
1920
+ const { marginLeft, skeDrawings, headerId, footerId, pageWidth } = page;
1921
+ if (skeDrawings.has(drawingId)) {
1922
+ drawing = skeDrawings.get(drawingId);
1923
+ pageMarginLeft = marginLeft;
1924
+ break;
2000
1925
  }
2001
- if (footerId) {
2002
- var _skeFooters$get;
2003
- const footerPage = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
2004
- if (footerPage) {
2005
- const footerTop = page.pageHeight - page.marginBottom + footerPage.marginTop;
2006
- this._calculateDrawingPosition(unitId, footerPage, docsLeft, docsTop, updateDrawingMap, footerTop, page.marginLeft);
2007
- this._calculateTableCellDrawingPositions(unitId, footerPage, docsLeft, docsTop, updateDrawingMap, footerTop, page.marginLeft);
2008
- }
1926
+ const headerPage = (_skeHeaders$get = skeHeaders.get(headerId)) === null || _skeHeaders$get === void 0 ? void 0 : _skeHeaders$get.get(pageWidth);
1927
+ if (headerPage === null || headerPage === void 0 ? void 0 : headerPage.skeDrawings.has(drawingId)) {
1928
+ drawing = headerPage === null || headerPage === void 0 ? void 0 : headerPage.skeDrawings.get(drawingId);
1929
+ pageMarginLeft = marginLeft;
1930
+ break;
1931
+ }
1932
+ const footerPage = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
1933
+ if (footerPage === null || footerPage === void 0 ? void 0 : footerPage.skeDrawings.has(drawingId)) {
1934
+ drawing = footerPage === null || footerPage === void 0 ? void 0 : footerPage.skeDrawings.get(drawingId);
1935
+ pageMarginLeft = marginLeft;
1936
+ break;
2009
1937
  }
2010
- this._calculateDrawingPosition(unitId, page, docsLeft, docsTop, updateDrawingMap, page.marginTop, page.marginLeft);
2011
- this._calculateTableCellDrawingPositions(unitId, page, docsLeft, docsTop, updateDrawingMap, page.marginTop, page.marginLeft);
2012
- this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
2013
1938
  }
2014
- const updateDrawings = Object.values(updateDrawingMap);
2015
- const nonMultiDrawings = updateDrawings.filter((drawing) => !drawing.isMultiTransform);
2016
- const multiDrawings = updateDrawings.filter((drawing) => drawing.isMultiTransform);
2017
- if (nonMultiDrawings.length > 0) this._drawingManagerService.refreshTransform(nonMultiDrawings);
2018
- this._handleMultiDrawingsTransform(multiDrawings);
2019
- }
2020
- _handleMultiDrawingsTransform(multiDrawings) {
2021
- const { scene, unitId } = this._context;
2022
- const transformer = scene.getTransformerByCreate();
2023
- multiDrawings.forEach((updateParam) => {
2024
- const param = this._drawingManagerService.getDrawingByParam(updateParam);
2025
- if (param == null) return;
2026
- param.transform = updateParam.transform;
2027
- param.transforms = updateParam.transforms;
2028
- param.isMultiTransform = updateParam.isMultiTransform;
1939
+ if (drawing == null) return;
1940
+ let delta = 0;
1941
+ if (prevRelativeFrom === ObjectRelativeFromH.COLUMN) delta -= drawing.columnLeft;
1942
+ else if (prevRelativeFrom === ObjectRelativeFromH.MARGIN) delta -= pageMarginLeft;
1943
+ if (relativeFrom === ObjectRelativeFromH.COLUMN) delta += drawing.columnLeft;
1944
+ else if (relativeFrom === ObjectRelativeFromH.MARGIN) delta += pageMarginLeft;
1945
+ else if (relativeFrom === ObjectRelativeFromH.PAGE) {}
1946
+ handlePositionChange("positionH", {
1947
+ relativeFrom,
1948
+ posOffset: (prevPosOffset !== null && prevPosOffset !== void 0 ? prevPosOffset : 0) - delta
2029
1949
  });
2030
- const selectedObjectKeys = [...transformer.getSelectedObjectMap().keys()];
2031
- const allMultiDrawings = Object.values(this._drawingManagerService.getDrawingData(unitId, unitId)).filter((drawing) => drawing.isMultiTransform === BooleanNumber.TRUE);
2032
- this._drawingManagerService.removeNotification(allMultiDrawings);
2033
- if (multiDrawings.length > 0) this._drawingManagerService.addNotification(multiDrawings);
2034
- for (const key of selectedObjectKeys) {
2035
- const drawingShape = scene.getObject(key);
2036
- if (drawingShape) transformer.setSelectedControl(drawingShape);
2037
- }
2038
1950
  }
2039
- _calculateDrawingPosition(unitId, page, docsLeft, docsTop, updateDrawingMap, marginTop, marginLeft) {
2040
- const { skeDrawings } = page;
2041
- this._liquid.translatePagePadding({
2042
- marginTop,
2043
- marginLeft
2044
- });
2045
- skeDrawings.forEach((drawing) => {
2046
- const { aLeft, aTop, height, width, angle, drawingId, drawingOrigin } = drawing;
2047
- const behindText = drawingOrigin.layoutType === PositionedObjectLayoutType.WRAP_NONE && drawingOrigin.behindDoc === BooleanNumber.TRUE;
2048
- const { isMultiTransform = BooleanNumber.FALSE } = drawingOrigin;
2049
- const transform = {
2050
- left: aLeft + docsLeft + this._liquid.x,
2051
- top: aTop + docsTop + this._liquid.y,
2052
- width,
2053
- height,
2054
- angle
2055
- };
2056
- if (updateDrawingMap[drawingId] == null) updateDrawingMap[drawingId] = {
2057
- unitId,
2058
- subUnitId: unitId,
2059
- drawingId,
2060
- behindText,
2061
- transform,
2062
- transforms: [transform],
2063
- isMultiTransform
2064
- };
2065
- else if (isMultiTransform === BooleanNumber.TRUE) updateDrawingMap[drawingId].transforms.push(transform);
2066
- });
2067
- this._liquid.restorePagePadding({
2068
- marginTop,
2069
- marginLeft
1951
+ function handleVerticalRelativeFromChange(value) {
1952
+ var _renderManagerService3, _renderManagerService4, _documentDataModel$ge, _glyph$parent, _column$parent;
1953
+ const prevRelativeFrom = vPosition.relativeFrom;
1954
+ const prevPosOffset = vPosition.posOffset;
1955
+ const relativeFrom = Number(value);
1956
+ if (prevRelativeFrom === relativeFrom) return;
1957
+ const focusDrawings = drawingManagerService.getFocusDrawings();
1958
+ if (focusDrawings.length === 0) return;
1959
+ const { drawingId, unitId } = focusDrawings[0];
1960
+ const documentDataModel = univerInstanceService.getUniverDocInstance(unitId);
1961
+ const skeleton = (_renderManagerService3 = renderManagerService.getRenderById(unitId)) === null || _renderManagerService3 === void 0 ? void 0 : _renderManagerService3.with(DocSkeletonManagerService).getSkeleton();
1962
+ const docSelectionRenderService = (_renderManagerService4 = renderManagerService.getRenderById(unitId)) === null || _renderManagerService4 === void 0 ? void 0 : _renderManagerService4.with(DocSelectionRenderService);
1963
+ const segmentId = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.getSegment();
1964
+ const segmentPage = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.getSegmentPage();
1965
+ const drawing = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) === null || _documentDataModel$ge === void 0 || (_documentDataModel$ge = _documentDataModel$ge.customBlocks) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.find((c) => c.blockId === drawingId);
1966
+ if (drawing == null || skeleton == null || docSelectionRenderService == null) return;
1967
+ const { startIndex } = drawing;
1968
+ const glyph = skeleton.findNodeByCharIndex(startIndex, segmentId, segmentPage);
1969
+ const line = glyph === null || glyph === void 0 || (_glyph$parent = glyph.parent) === null || _glyph$parent === void 0 ? void 0 : _glyph$parent.parent;
1970
+ const column = line === null || line === void 0 ? void 0 : line.parent;
1971
+ const paragraphStartLine = column === null || column === void 0 ? void 0 : column.lines.find((l) => l.paragraphIndex === (line === null || line === void 0 ? void 0 : line.paragraphIndex) && l.paragraphStart);
1972
+ const page = column === null || column === void 0 || (_column$parent = column.parent) === null || _column$parent === void 0 ? void 0 : _column$parent.parent;
1973
+ if (glyph == null || line == null || paragraphStartLine == null || column == null || page == null) return;
1974
+ let delta = 0;
1975
+ if (prevRelativeFrom === ObjectRelativeFromV.PARAGRAPH) delta -= paragraphStartLine.top;
1976
+ else if (prevRelativeFrom === ObjectRelativeFromV.LINE) delta -= line.top;
1977
+ else if (prevRelativeFrom === ObjectRelativeFromV.PAGE) delta += page.marginTop;
1978
+ if (relativeFrom === ObjectRelativeFromV.PARAGRAPH) delta += paragraphStartLine.top;
1979
+ else if (relativeFrom === ObjectRelativeFromV.LINE) delta += line.top;
1980
+ else if (relativeFrom === ObjectRelativeFromV.PAGE) delta -= page.marginTop;
1981
+ handlePositionChange("positionV", {
1982
+ relativeFrom,
1983
+ posOffset: (prevPosOffset !== null && prevPosOffset !== void 0 ? prevPosOffset : 0) - delta
2070
1984
  });
2071
1985
  }
2072
- _calculateTableCellDrawingPositions(unitId, page, docsLeft, docsTop, updateDrawingMap, baseMarginTop, baseMarginLeft) {
2073
- var _page$skeTables;
2074
- (_page$skeTables = page.skeTables) === null || _page$skeTables === void 0 || _page$skeTables.forEach((table) => {
2075
- table.rows.forEach((row) => {
2076
- row.cells.forEach((cell) => {
2077
- const cellOffset = getDocsTableCellDrawingOffset(unitId, table, row, cell);
2078
- const marginTop = baseMarginTop + cellOffset.top;
2079
- const marginLeft = baseMarginLeft + cellOffset.left;
2080
- this._calculateDrawingPosition(unitId, cell, docsLeft, docsTop, updateDrawingMap, marginTop, marginLeft);
2081
- this._calculateTableCellDrawingPositions(unitId, cell, docsLeft, docsTop, updateDrawingMap, marginTop, marginLeft);
2082
- });
2083
- });
2084
- });
1986
+ function updateState(drawingParam) {
1987
+ var _snapshot$drawings;
1988
+ const snapshot = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getSnapshot();
1989
+ const drawing = snapshot === null || snapshot === void 0 || (_snapshot$drawings = snapshot.drawings) === null || _snapshot$drawings === void 0 ? void 0 : _snapshot$drawings[drawingParam.drawingId];
1990
+ if (drawing == null) return;
1991
+ const { layoutType } = drawing;
1992
+ const { positionH, positionV } = drawing.docTransform;
1993
+ setHPosition(positionH);
1994
+ setVPosition(positionV);
1995
+ setDisabled(layoutType === PositionedObjectLayoutType.INLINE);
1996
+ setFollowTextMove(positionV.relativeFrom === ObjectRelativeFromV.PARAGRAPH || positionV.relativeFrom === ObjectRelativeFromV.LINE);
2085
1997
  }
2086
- _drawingInitializeListener() {
2087
- const init = () => {
2088
- const skeleton = this._docSkeletonManagerService.getSkeleton();
2089
- if (skeleton == null) return;
2090
- this._refreshDrawing(skeleton);
2091
- this._drawingManagerService.initializeNotification(this._context.unitId);
2092
- };
2093
- if (this._lifecycleService.stage >= LifecycleStages.Rendered) if (this._docSkeletonManagerService.getSkeleton()) init();
2094
- else setTimeout(init, 500);
2095
- else this.disposeWithMe(this._lifecycleService.lifecycle$.pipe(filter((stage) => stage === LifecycleStages.Rendered)).subscribe(init));
1998
+ function updateFocusDrawingState() {
1999
+ const focusDrawings = drawingManagerService.getFocusDrawings();
2000
+ if (focusDrawings.length === 0) return;
2001
+ updateState(focusDrawings[0]);
2002
+ }
2003
+ function handleFollowTextMoveCheck(val) {
2004
+ setFollowTextMove(val);
2005
+ handleVerticalRelativeFromChange(val ? String(ObjectRelativeFromV.PARAGRAPH) : String(ObjectRelativeFromV.PAGE));
2096
2006
  }
2007
+ useEffect(() => {
2008
+ updateFocusDrawingState();
2009
+ const subscription = drawingManagerService.focus$.subscribe((drawingParams) => {
2010
+ if (drawingParams.length === 0) {
2011
+ setShowPanel(false);
2012
+ return;
2013
+ }
2014
+ setShowPanel(true);
2015
+ updateState(drawingParams[0]);
2016
+ });
2017
+ const mutationListener = commandService.onCommandExecuted(async (command) => {
2018
+ if (command.id === RichTextEditingMutation.id) updateFocusDrawingState();
2019
+ });
2020
+ return () => {
2021
+ subscription.unsubscribe();
2022
+ mutationListener.dispose();
2023
+ };
2024
+ }, []);
2025
+ return /* @__PURE__ */ jsxs("div", {
2026
+ className: clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": !showPanel }),
2027
+ children: [
2028
+ /* @__PURE__ */ jsx("header", {
2029
+ className: "univer-text-gray-600 dark:!univer-text-gray-200",
2030
+ children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-position.title") })
2031
+ }),
2032
+ /* @__PURE__ */ jsx("div", {
2033
+ className: "univer-text-gray-600 dark:!univer-text-gray-200",
2034
+ children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-position.horizontal") })
2035
+ }),
2036
+ /* @__PURE__ */ jsxs("div", {
2037
+ className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
2038
+ children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-position.absolutePosition") }), /* @__PURE__ */ jsx(InputNumber, {
2039
+ min: MIN_OFFSET,
2040
+ max: MAX_OFFSET,
2041
+ precision: 1,
2042
+ disabled,
2043
+ value: hPosition.posOffset,
2044
+ onChange: (val) => {
2045
+ handlePositionChange("positionH", {
2046
+ relativeFrom: hPosition.relativeFrom,
2047
+ posOffset: val
2048
+ });
2049
+ }
2050
+ })] }), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-position.toTheRightOf") }), /* @__PURE__ */ jsx(Select, {
2051
+ value: String(hPosition.relativeFrom),
2052
+ disabled,
2053
+ options: HORIZONTAL_RELATIVE_FROM,
2054
+ onChange: handleHorizontalRelativeFromChange
2055
+ })] })]
2056
+ }),
2057
+ /* @__PURE__ */ jsx("div", {
2058
+ className: "univer-text-gray-600 dark:!univer-text-gray-200",
2059
+ children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-position.vertical") })
2060
+ }),
2061
+ /* @__PURE__ */ jsxs("div", {
2062
+ className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
2063
+ children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-position.absolutePosition") }), /* @__PURE__ */ jsx(InputNumber, {
2064
+ min: MIN_OFFSET,
2065
+ max: MAX_OFFSET,
2066
+ precision: 1,
2067
+ disabled,
2068
+ value: vPosition.posOffset,
2069
+ onChange: (val) => {
2070
+ handlePositionChange("positionV", {
2071
+ relativeFrom: vPosition.relativeFrom,
2072
+ posOffset: val
2073
+ });
2074
+ }
2075
+ })] }), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-position.bellow") }), /* @__PURE__ */ jsx(Select, {
2076
+ disabled,
2077
+ value: String(vPosition.relativeFrom),
2078
+ options: VERTICAL_RELATIVE_FROM,
2079
+ onChange: handleVerticalRelativeFromChange
2080
+ })] })]
2081
+ }),
2082
+ /* @__PURE__ */ jsx("div", {
2083
+ className: "univer-text-gray-600 dark:!univer-text-gray-200",
2084
+ children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-position.options") })
2085
+ }),
2086
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Checkbox, {
2087
+ disabled,
2088
+ checked: followTextMove,
2089
+ onChange: handleFollowTextMoveCheck,
2090
+ children: localeService.t("docs-drawing-ui.image-position.moveObjectWithText")
2091
+ }) })
2092
+ ]
2093
+ });
2097
2094
  };
2098
- DocDrawingTransformUpdateController = __decorate([
2099
- __decorateParam(1, Inject(DocSkeletonManagerService)),
2100
- __decorateParam(2, ICommandService),
2101
- __decorateParam(3, IEditorService),
2102
- __decorateParam(4, IDrawingManagerService),
2103
- __decorateParam(5, Inject(DocRefreshDrawingsService)),
2104
- __decorateParam(6, IUniverInstanceService),
2105
- __decorateParam(7, Inject(LifecycleService))
2106
- ], DocDrawingTransformUpdateController);
2107
2095
 
2108
2096
  //#endregion
2109
- //#region src/controllers/doc-drawing-transformer-update.controller.ts
2110
- const INLINE_DRAWING_ANCHOR_KEY_PREFIX = "__InlineDrawingAnchor__";
2111
- function getDocsTableCellAnchorContext(unitId, cell) {
2112
- var _row$cells;
2113
- const row = cell.parent;
2114
- const table = row === null || row === void 0 ? void 0 : row.parent;
2115
- const hostPage = table === null || table === void 0 ? void 0 : table.parent;
2116
- if (!row || !table || !hostPage || !((_row$cells = row.cells) === null || _row$cells === void 0 ? void 0 : _row$cells.includes(cell))) return null;
2117
- return {
2118
- cell,
2119
- hostPage,
2120
- offset: getDocsTableCellDrawingOffset(unitId, table, row, cell),
2121
- row,
2122
- table
2123
- };
2124
- }
2125
- let DocDrawingTransformerController = class DocDrawingTransformerController extends Disposable {
2126
- constructor(_commandService, _univerInstanceService, _drawingManagerService, _renderManagerService) {
2127
- super();
2128
- this._commandService = _commandService;
2129
- this._univerInstanceService = _univerInstanceService;
2130
- this._drawingManagerService = _drawingManagerService;
2131
- this._renderManagerService = _renderManagerService;
2132
- _defineProperty(this, "_liquid", new Liquid());
2133
- _defineProperty(this, "_listenerOnImageMap", /* @__PURE__ */ new Set());
2134
- _defineProperty(this, "_transformerCache", /* @__PURE__ */ new Map());
2135
- _defineProperty(this, "_anchorShape", void 0);
2136
- this._init();
2137
- }
2138
- _init() {
2139
- this._listenDrawingFocus();
2140
- }
2141
- _listenDrawingFocus() {
2142
- this.disposeWithMe(this._drawingManagerService.add$.subscribe((drawingParams) => {
2143
- if (drawingParams.length === 0) return;
2144
- for (const drawingParam of drawingParams) {
2145
- const { unitId } = drawingParam;
2146
- if (!this._listenerOnImageMap.has(unitId)) {
2147
- this._listenTransformerChange(unitId);
2148
- this._listenerOnImageMap.add(unitId);
2149
- }
2150
- }
2151
- }));
2152
- }
2153
- _listenTransformerChange(unitId) {
2154
- var _this$_getSceneAndTra;
2155
- const transformer = (_this$_getSceneAndTra = this._getSceneAndTransformerByDrawingSearch(unitId)) === null || _this$_getSceneAndTra === void 0 ? void 0 : _this$_getSceneAndTra.transformer;
2156
- if (transformer == null) return;
2157
- this.disposeWithMe(toDisposable(transformer.changeStart$.subscribe((state) => {
2158
- this._transformerCache.clear();
2159
- const { objects } = state;
2160
- for (const object of objects.values()) {
2161
- var _documentDataModel$ge;
2162
- const { oKey, width, height, left, top, angle } = object;
2163
- const drawing = this._drawingManagerService.getDrawingOKey(oKey);
2164
- if (drawing == null) continue;
2165
- const documentDataModel = this._univerInstanceService.getUniverDocInstance(drawing.unitId);
2166
- const drawingData = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSnapshot().drawings) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge[drawing.drawingId];
2167
- if ((drawingData === null || drawingData === void 0 ? void 0 : drawingData.layoutType) === PositionedObjectLayoutType.INLINE) try {
2168
- object.setOpacity(.2);
2169
- } catch (e) {}
2170
- if (drawingData != null) this._transformerCache.set(drawing.drawingId, {
2171
- drawing: drawingData,
2172
- top,
2173
- left,
2174
- width,
2175
- height,
2176
- angle
2177
- });
2178
- }
2179
- })));
2180
- const throttleMultipleDrawingUpdate = throttle(this._updateMultipleDrawingDocTransform.bind(this), 50);
2181
- throttle(this._nonInlineDrawingTransform.bind(this), 50);
2182
- this.disposeWithMe(toDisposable(transformer.changing$.subscribe((state) => {
2183
- const { objects, offsetX, offsetY } = state;
2184
- if (objects.size > 1) throttleMultipleDrawingUpdate(objects);
2185
- else if (objects.size === 1) {
2186
- const drawingCache = this._transformerCache.values().next().value;
2187
- const { width, height, top, left, angle } = objects.values().next().value;
2188
- if (drawingCache && width === drawingCache.width && height === drawingCache.height && top === drawingCache.top && left === drawingCache.left && angle === drawingCache.angle) return;
2189
- if (drawingCache && drawingCache.drawing.layoutType !== PositionedObjectLayoutType.INLINE) {}
2190
- if (drawingCache && drawingCache.drawing.layoutType === PositionedObjectLayoutType.INLINE && offsetX != null && offsetY != null) this._updateInlineDrawingAnchor(drawingCache.drawing, offsetX, offsetY);
2191
- }
2192
- })));
2193
- this.disposeWithMe(toDisposable(transformer.changeEnd$.subscribe((state) => {
2194
- const { objects, offsetX, offsetY } = state;
2195
- for (const object of objects.values()) {
2196
- const drawing = this._drawingManagerService.getDrawingOKey(object.oKey);
2197
- if (drawing == null) continue;
2198
- const drawingCache = this._transformerCache.get(drawing === null || drawing === void 0 ? void 0 : drawing.drawingId);
2199
- if ((drawingCache === null || drawingCache === void 0 ? void 0 : drawingCache.drawing.layoutType) === PositionedObjectLayoutType.INLINE) try {
2200
- object.setOpacity(1);
2201
- } catch (e) {}
2202
- }
2203
- if (this._anchorShape) this._anchorShape.hide();
2204
- if (objects.size > 1) this._updateMultipleDrawingDocTransform(objects);
2205
- else if (objects.size === 1) {
2206
- const drawingCache = this._transformerCache.values().next().value;
2207
- const object = objects.values().next().value;
2208
- const { width, height, top, left, angle } = object;
2209
- if (drawingCache && width === drawingCache.width && height === drawingCache.height && top === drawingCache.top && left === drawingCache.left && angle === drawingCache.angle) return;
2210
- if (drawingCache && drawingCache.drawing.layoutType === PositionedObjectLayoutType.INLINE) {
2211
- if (width !== drawingCache.width || height !== drawingCache.height || angle !== drawingCache.angle) this._updateDrawingSize(drawingCache, object);
2212
- else if (offsetX != null && offsetY != null) this._moveInlineDrawing(drawingCache.drawing, offsetX, offsetY);
2213
- } else if (drawingCache) this._nonInlineDrawingTransform(drawingCache.drawing, object);
2214
- }
2215
- this._transformerCache.clear();
2216
- })));
2217
- }
2218
- _updateMultipleDrawingDocTransform(objects) {
2219
- if (objects.size < 1) return;
2220
- const drawings = [];
2221
- let unitId;
2222
- let subUnitId;
2223
- for (const object of objects.values()) {
2224
- const { oKey, left, top, angle } = object;
2225
- let { width, height } = object;
2226
- const drawing = this._drawingManagerService.getDrawingOKey(oKey);
2227
- if (drawing == null) continue;
2228
- if (unitId == null) unitId = drawing.unitId;
2229
- if (subUnitId == null) subUnitId = drawing.subUnitId;
2230
- const drawingCache = this._transformerCache.get(drawing.drawingId);
2231
- if (drawingCache == null) continue;
2232
- const { drawing: drawingData, top: oldTop, left: oldLeft, width: oldWidth, height: oldHeight, angle: oldAngle } = drawingCache;
2233
- const { width: maxWidth, height: maxHeight } = this._getPageContentSize(drawingData);
2234
- width = Math.min(width, maxWidth);
2235
- height = Math.min(height, maxHeight);
2236
- if (oldWidth !== width || oldHeight !== height) drawings.push({
2237
- drawingId: drawing.drawingId,
2238
- key: "size",
2239
- value: {
2240
- width,
2241
- height
2242
- }
2243
- });
2244
- if (oldAngle !== angle) drawings.push({
2245
- drawingId: drawing.drawingId,
2246
- key: "angle",
2247
- value: angle
2248
- });
2249
- if (oldTop !== top || oldLeft !== left) {
2250
- const verticalDelta = top - oldTop;
2251
- const horizontalDelta = left - oldLeft;
2252
- if (verticalDelta !== 0) drawings.push({
2253
- drawingId: drawing.drawingId,
2254
- key: "positionV",
2255
- value: {
2256
- relativeFrom: drawingData.docTransform.positionV.relativeFrom,
2257
- posOffset: drawingData.docTransform.positionV.posOffset + verticalDelta
2258
- }
2259
- });
2260
- if (horizontalDelta !== 0) drawings.push({
2261
- drawingId: drawing.drawingId,
2262
- key: "positionH",
2263
- value: {
2264
- relativeFrom: drawingData.docTransform.positionH.relativeFrom,
2265
- posOffset: drawingData.docTransform.positionH.posOffset + horizontalDelta
2266
- }
2267
- });
2268
- }
2269
- }
2270
- if (drawings.length > 0 && unitId && subUnitId) this._commandService.executeCommand(UpdateDrawingDocTransformCommand.id, {
2097
+ //#region src/views/doc-image-panel/DocDrawingTextWrap.tsx
2098
+ const MIN_MARGIN = 0;
2099
+ const MAX_MARGIN = 100;
2100
+ const DocDrawingTextWrap = (props) => {
2101
+ const commandService = useDependency(ICommandService);
2102
+ const localeService = useDependency(LocaleService);
2103
+ const drawingManagerService = useDependency(IDrawingManagerService);
2104
+ const renderManagerService = useDependency(IRenderManagerService);
2105
+ const univerInstanceService = useDependency(IUniverInstanceService);
2106
+ const { drawings } = props;
2107
+ const drawingParam = drawings[0];
2108
+ if (drawingParam == null) return null;
2109
+ const { unitId } = drawingParam;
2110
+ const documentDataModel = univerInstanceService.getUniverDocInstance(unitId);
2111
+ const renderObject = renderManagerService.getRenderById(unitId);
2112
+ if ((renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene) == null) return null;
2113
+ const [disableWrapText, setDisableWrapText] = useState(true);
2114
+ const [disableDistTB, setDisableDistTB] = useState(true);
2115
+ const [disableDistLR, setDisableDistLR] = useState(true);
2116
+ const [wrappingStyle, setWrappingStyle] = useState("inline");
2117
+ const [wrapText, setWrapText] = useState("");
2118
+ const [distToText, setDistToText] = useState({
2119
+ distT: 0,
2120
+ distL: 0,
2121
+ distB: 0,
2122
+ distR: 0
2123
+ });
2124
+ const [showPanel, setShowPanel] = useState(true);
2125
+ function handleWrappingStyleChange(value) {
2126
+ setWrappingStyle(value);
2127
+ const focusDrawings = drawingManagerService.getFocusDrawings();
2128
+ if (focusDrawings.length === 0) return;
2129
+ const { unitId, subUnitId } = focusDrawings[0];
2130
+ const drawings = focusDrawings.map(({ unitId, subUnitId, drawingId }) => ({
2271
2131
  unitId,
2272
2132
  subUnitId,
2273
- drawings
2133
+ drawingId
2134
+ }));
2135
+ commandService.executeCommand(UpdateDocDrawingWrappingStyleCommand.id, {
2136
+ unitId,
2137
+ subUnitId,
2138
+ drawings,
2139
+ wrappingStyle: value
2274
2140
  });
2275
2141
  }
2276
- _updateDrawingAnchor(objects) {
2277
- if (this._transformerCache.size !== 1) return;
2278
- const drawingCache = this._transformerCache.values().next().value;
2279
- const object = objects.values().next().value;
2280
- this._getDrawingAnchor(drawingCache.drawing, object);
2281
- }
2282
- _updateInlineDrawingAnchor(drawing, offsetX, offsetY) {
2283
- var _this$_getInlineDrawi;
2284
- if (this._transformerCache.size !== 1) return;
2285
- const { contentBoxPointGroup } = (_this$_getInlineDrawi = this._getInlineDrawingAnchor(drawing, offsetX, offsetY)) !== null && _this$_getInlineDrawi !== void 0 ? _this$_getInlineDrawi : {};
2286
- if (contentBoxPointGroup == null) return;
2287
- this._createOrUpdateInlineAnchor(drawing.unitId, contentBoxPointGroup);
2142
+ function handleWrapTextChange(value) {
2143
+ setWrapText(value);
2144
+ const focusDrawings = drawingManagerService.getFocusDrawings();
2145
+ if (focusDrawings.length === 0) return;
2146
+ const drawings = focusDrawings.map((drawing) => {
2147
+ return {
2148
+ unitId: drawing.unitId,
2149
+ subUnitId: drawing.subUnitId,
2150
+ drawingId: drawing.drawingId
2151
+ };
2152
+ });
2153
+ commandService.executeCommand(UpdateDocDrawingWrapTextCommand.id, {
2154
+ unitId: focusDrawings[0].unitId,
2155
+ subUnitId: focusDrawings[0].unitId,
2156
+ drawings,
2157
+ wrapText: value
2158
+ });
2288
2159
  }
2289
- _getInlineDrawingAnchor(drawing, offsetX, offsetY) {
2290
- var _this$_renderManagerS, _getOneTextSelectionR;
2291
- const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
2292
- const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(DocSkeletonManagerService).getSkeleton();
2293
- if (currentRender == null) return;
2294
- const { mainComponent, scene } = currentRender;
2295
- const documentComponent = mainComponent;
2296
- const activeViewport = scene.getViewports()[0];
2297
- const { pageLayoutType = PageLayoutType.VERTICAL, pageMarginLeft, pageMarginTop } = documentComponent.getOffsetConfig();
2298
- let glyphAnchor = null;
2299
- let isBack = false;
2300
- let segmentPageIndex = -1;
2301
- let segmentId = "";
2302
- const HALF = .5;
2303
- const coord = this._getTransformCoordForDocumentOffset(documentComponent, activeViewport, offsetX, offsetY);
2304
- if (coord == null) return;
2305
- const docSelectionRenderService = (_this$_renderManagerS = this._renderManagerService.getRenderById(drawing.unitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.with(DocSelectionRenderService);
2306
- if (docSelectionRenderService == null) return;
2307
- const nodeInfo = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findNodeByCoord(coord, pageLayoutType, pageMarginLeft, pageMarginTop, {
2308
- strict: false,
2309
- segmentId: docSelectionRenderService.getSegment(),
2310
- segmentPage: docSelectionRenderService.getSegmentPage()
2160
+ function handleDistToTextChange(value, direction) {
2161
+ if (value == null) return;
2162
+ setDistToText({
2163
+ ...distToText,
2164
+ [direction]: value
2165
+ });
2166
+ const focusDrawings = drawingManagerService.getFocusDrawings();
2167
+ if (focusDrawings.length === 0) return;
2168
+ const drawings = focusDrawings.map((drawing) => {
2169
+ return {
2170
+ unitId: drawing.unitId,
2171
+ subUnitId: drawing.subUnitId,
2172
+ drawingId: drawing.drawingId
2173
+ };
2174
+ });
2175
+ commandService.executeCommand(UpdateDocDrawingDistanceCommand.id, {
2176
+ unitId: focusDrawings[0].unitId,
2177
+ subUnitId: focusDrawings[0].unitId,
2178
+ drawings,
2179
+ dist: { [direction]: value }
2311
2180
  });
2312
- if (nodeInfo) {
2313
- const { node, ratioX, segmentPage, segmentId: nodeSegmentId } = nodeInfo;
2314
- isBack = ratioX < HALF;
2315
- glyphAnchor = node;
2316
- segmentPageIndex = segmentPage;
2317
- segmentId = nodeSegmentId;
2318
- }
2319
- if (glyphAnchor == null) return;
2320
- const nodePosition = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findPositionByGlyph(glyphAnchor, segmentPageIndex);
2321
- const docObject = this._getDocObject();
2322
- if (nodePosition == null || skeleton == null || docObject == null) return;
2323
- const positionWithIsBack = {
2324
- ...nodePosition,
2325
- isBack
2326
- };
2327
- const { cursorList, contentBoxPointGroup } = new NodePositionConvertToCursor(docObject.document.getOffsetConfig(), skeleton).getRangePointData(positionWithIsBack, positionWithIsBack);
2328
- const { startOffset } = (_getOneTextSelectionR = getOneTextSelectionRange(cursorList)) !== null && _getOneTextSelectionR !== void 0 ? _getOneTextSelectionR : {};
2329
- if (startOffset == null) return;
2330
- return {
2331
- offset: startOffset,
2332
- contentBoxPointGroup,
2333
- segmentId,
2334
- segmentPage: segmentPageIndex
2335
- };
2336
2181
  }
2337
- _getDrawingAnchor(drawing, object) {
2338
- var _this$_renderManagerS2, _glyphAnchor$parent, _column$lines$find, _column$parent, _tableCellContext$hos, _getOneTextSelectionR2;
2339
- const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
2340
- const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(DocSkeletonManagerService).getSkeleton();
2341
- const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
2342
- if (skeletonData == null || currentRender == null) return;
2343
- const { pages, skeHeaders, skeFooters } = skeletonData;
2344
- const { mainComponent, scene } = currentRender;
2345
- const documentComponent = mainComponent;
2346
- const activeViewport = scene.getViewports()[0];
2347
- const { pageLayoutType = PageLayoutType.VERTICAL, pageMarginLeft, pageMarginTop, docsLeft, docsTop } = documentComponent.getOffsetConfig();
2348
- const { left, top, angle } = object;
2349
- let { width, height } = object;
2350
- const { positionV, positionH } = drawing.docTransform;
2351
- const { width: maxWidth, height: maxHeight } = this._getPageContentSize(drawing);
2352
- width = Math.min(width, maxWidth);
2353
- height = Math.min(height, maxHeight);
2354
- let glyphAnchor = null;
2355
- let segmentId = "";
2356
- let segmentPage = -1;
2357
- const isBack = false;
2358
- const docTransform = {
2359
- ...drawing.docTransform,
2360
- size: {
2361
- width,
2362
- height
2363
- },
2364
- angle
2365
- };
2366
- const { x, y } = scene.getViewportScrollXY(activeViewport);
2367
- const coord = this._getTransformCoordForDocumentOffset(documentComponent, activeViewport, left - x, top - y);
2368
- if (coord == null) return;
2369
- const docSelectionRenderService = (_this$_renderManagerS2 = this._renderManagerService.getRenderById(drawing.unitId)) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.with(DocSelectionRenderService);
2370
- if (docSelectionRenderService == null) return;
2371
- const nodeInfo = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findNodeByCoord(coord, pageLayoutType, pageMarginLeft, pageMarginTop, {
2372
- strict: false,
2373
- segmentId: docSelectionRenderService.getSegment(),
2374
- segmentPage: docSelectionRenderService.getSegmentPage()
2182
+ function updateFocusDrawingState() {
2183
+ const focusDrawings = drawingManagerService.getFocusDrawings();
2184
+ if (focusDrawings.length === 0) return;
2185
+ updateState(focusDrawings[0]);
2186
+ }
2187
+ function updateState(drawingParam) {
2188
+ var _documentDataModel$ge;
2189
+ const drawing = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSnapshot()) === null || _documentDataModel$ge === void 0 || (_documentDataModel$ge = _documentDataModel$ge.drawings) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge[drawingParam.drawingId];
2190
+ if (drawing == null) return;
2191
+ const { distT = 0, distL = 0, distB = 0, distR = 0, layoutType = PositionedObjectLayoutType.INLINE, behindDoc = BooleanNumber.FALSE, wrapText = WrapTextType.BOTH_SIDES } = drawing;
2192
+ setDistToText({
2193
+ distT,
2194
+ distL,
2195
+ distB,
2196
+ distR
2375
2197
  });
2376
- if (nodeInfo) {
2377
- const { node, segmentPage: segmentPageIndex, segmentId: nodeSegmentId } = nodeInfo;
2378
- glyphAnchor = node;
2379
- segmentPage = segmentPageIndex;
2380
- segmentId = nodeSegmentId;
2381
- }
2382
- if (glyphAnchor == null) return;
2383
- const line = (_glyphAnchor$parent = glyphAnchor.parent) === null || _glyphAnchor$parent === void 0 ? void 0 : _glyphAnchor$parent.parent;
2384
- const column = line === null || line === void 0 ? void 0 : line.parent;
2385
- const paragraphStartLine = (_column$lines$find = column === null || column === void 0 ? void 0 : column.lines.find((l) => l.paragraphIndex === (line === null || line === void 0 ? void 0 : line.paragraphIndex) && l.paragraphStart)) !== null && _column$lines$find !== void 0 ? _column$lines$find : column === null || column === void 0 ? void 0 : column.lines[0];
2386
- const page = column === null || column === void 0 || (_column$parent = column.parent) === null || _column$parent === void 0 ? void 0 : _column$parent.parent;
2387
- if (line == null || column == null || paragraphStartLine == null || page == null) return;
2388
- this._liquid.reset();
2389
- const tableCellContext = page.type === DocumentSkeletonPageType.CELL ? getDocsTableCellAnchorContext(drawing.unitId, page) : null;
2390
- const anchorPage = (_tableCellContext$hos = tableCellContext === null || tableCellContext === void 0 ? void 0 : tableCellContext.hostPage) !== null && _tableCellContext$hos !== void 0 ? _tableCellContext$hos : page;
2391
- const pageType = anchorPage.type;
2392
- for (const p of pages) {
2393
- const { headerId, footerId, pageHeight, pageWidth, marginLeft, marginBottom } = p;
2394
- const pIndex = pages.indexOf(p);
2395
- if (segmentPage > -1 && pIndex === segmentPage) {
2396
- switch (pageType) {
2397
- case DocumentSkeletonPageType.HEADER: {
2398
- var _skeHeaders$get;
2399
- const headerSke = (_skeHeaders$get = skeHeaders.get(headerId)) === null || _skeHeaders$get === void 0 ? void 0 : _skeHeaders$get.get(pageWidth);
2400
- if (headerSke) this._liquid.translatePagePadding({
2401
- marginTop: headerSke.marginTop,
2402
- marginLeft
2403
- });
2404
- else throw new Error("header skeleton not found");
2405
- break;
2406
- }
2407
- case DocumentSkeletonPageType.FOOTER: {
2408
- var _skeFooters$get;
2409
- const footerSke = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
2410
- if (footerSke) this._liquid.translatePagePadding({
2411
- marginTop: pageHeight - marginBottom + footerSke.marginTop,
2412
- marginLeft
2413
- });
2414
- else throw new Error("footer skeleton not found");
2415
- break;
2416
- }
2417
- default:
2418
- this._liquid.translatePagePadding(p);
2419
- break;
2420
- }
2421
- break;
2422
- }
2423
- this._liquid.translatePagePadding(p);
2424
- if (p === anchorPage) break;
2425
- this._liquid.restorePagePadding(p);
2426
- this._liquid.translatePage(p, pageLayoutType, pageMarginLeft, pageMarginTop);
2427
- }
2428
- if (tableCellContext) this._liquid.translate(tableCellContext.offset.left, tableCellContext.offset.top);
2429
- if (positionV.relativeFrom === ObjectRelativeFromV.LINE) glyphAnchor = line.divides[0].glyphGroup[0];
2430
- else {
2431
- var _paragraphStartLine$d, _paragraphStartLine$d2;
2432
- glyphAnchor = (_paragraphStartLine$d = (_paragraphStartLine$d2 = paragraphStartLine.divides) === null || _paragraphStartLine$d2 === void 0 || (_paragraphStartLine$d2 = _paragraphStartLine$d2[0]) === null || _paragraphStartLine$d2 === void 0 || (_paragraphStartLine$d2 = _paragraphStartLine$d2.glyphGroup) === null || _paragraphStartLine$d2 === void 0 ? void 0 : _paragraphStartLine$d2[0]) !== null && _paragraphStartLine$d !== void 0 ? _paragraphStartLine$d : glyphAnchor;
2433
- }
2434
- docTransform.positionH = {
2435
- relativeFrom: positionH.relativeFrom,
2436
- posOffset: left - this._liquid.x - docsLeft
2437
- };
2438
- switch (positionH.relativeFrom) {
2439
- case ObjectRelativeFromH.MARGIN:
2440
- docTransform.positionH.posOffset = left - this._liquid.x - docsLeft - page.marginLeft;
2441
- break;
2442
- case ObjectRelativeFromH.COLUMN:
2443
- docTransform.positionH.posOffset = left - this._liquid.x - docsLeft - column.left;
2444
- break;
2445
- }
2446
- docTransform.positionV = {
2447
- relativeFrom: positionV.relativeFrom,
2448
- posOffset: top - this._liquid.y - docsTop
2449
- };
2450
- switch (positionV.relativeFrom) {
2451
- case ObjectRelativeFromV.PAGE:
2452
- docTransform.positionV.posOffset = top - this._liquid.y - docsTop - page.marginTop;
2198
+ setWrapText(wrapText);
2199
+ setDisableWrapText(layoutType !== PositionedObjectLayoutType.WRAP_SQUARE);
2200
+ if (layoutType === PositionedObjectLayoutType.WRAP_NONE || layoutType === PositionedObjectLayoutType.INLINE) setDisableDistTB(true);
2201
+ else setDisableDistTB(false);
2202
+ if (layoutType === PositionedObjectLayoutType.WRAP_NONE || layoutType === PositionedObjectLayoutType.INLINE || layoutType === PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM) setDisableDistLR(true);
2203
+ else setDisableDistLR(false);
2204
+ if (layoutType === PositionedObjectLayoutType.WRAP_NONE) if (behindDoc === BooleanNumber.TRUE) setWrappingStyle("behindText");
2205
+ else setWrappingStyle("inFrontOfText");
2206
+ else switch (layoutType) {
2207
+ case PositionedObjectLayoutType.INLINE:
2208
+ setWrappingStyle("inline");
2453
2209
  break;
2454
- case ObjectRelativeFromV.LINE:
2455
- docTransform.positionV.posOffset = top - this._liquid.y - docsTop - line.top;
2210
+ case PositionedObjectLayoutType.WRAP_SQUARE:
2211
+ setWrappingStyle("wrapSquare");
2456
2212
  break;
2457
- case ObjectRelativeFromV.PARAGRAPH:
2458
- docTransform.positionV.posOffset = top - this._liquid.y - docsTop - paragraphStartLine.top;
2213
+ case PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM:
2214
+ setWrappingStyle("wrapTopAndBottom");
2459
2215
  break;
2216
+ default: throw new Error(`Unsupported layout type: ${layoutType}`);
2460
2217
  }
2461
- if (glyphAnchor == null) return;
2462
- const nodePosition = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findPositionByGlyph(glyphAnchor, segmentPage);
2463
- const docObject = this._getDocObject();
2464
- if (nodePosition == null || skeleton == null || docObject == null) return;
2465
- const positionWithIsBack = {
2466
- ...nodePosition,
2467
- isBack
2468
- };
2469
- const { cursorList } = new NodePositionConvertToCursor(docObject.document.getOffsetConfig(), skeleton).getRangePointData(positionWithIsBack, positionWithIsBack);
2470
- const { startOffset } = (_getOneTextSelectionR2 = getOneTextSelectionRange(cursorList)) !== null && _getOneTextSelectionR2 !== void 0 ? _getOneTextSelectionR2 : {};
2471
- if (startOffset == null) return;
2472
- return {
2473
- offset: startOffset,
2474
- docTransform,
2475
- segmentId,
2476
- segmentPage
2477
- };
2478
2218
  }
2479
- _updateDrawingSize(drawingCache, object) {
2480
- const drawings = [];
2481
- const { drawing, width: oldWidth, height: oldHeight, angle: oldAngle } = drawingCache;
2482
- const { unitId, subUnitId } = drawing;
2483
- let { width, height, angle } = object;
2484
- const { width: maxWidth, height: maxHeight } = this._getPageContentSize(drawing);
2485
- width = Math.min(maxWidth, width);
2486
- height = Math.min(maxHeight, height);
2487
- if (width !== oldWidth || height !== oldHeight) drawings.push({
2488
- drawingId: drawing.drawingId,
2489
- key: "size",
2490
- value: {
2491
- width,
2492
- height
2219
+ useEffect(() => {
2220
+ updateFocusDrawingState();
2221
+ const subscription = drawingManagerService.focus$.subscribe((drawingParams) => {
2222
+ if (drawingParams.length === 0) {
2223
+ setShowPanel(false);
2224
+ return;
2493
2225
  }
2226
+ setShowPanel(true);
2227
+ updateState(drawingParams[0]);
2494
2228
  });
2495
- if (angle !== oldAngle) drawings.push({
2496
- drawingId: drawing.drawingId,
2497
- key: "angle",
2498
- value: angle
2499
- });
2500
- if (drawings.length > 0 && unitId && subUnitId) this._commandService.executeCommand(UpdateDrawingDocTransformCommand.id, {
2501
- unitId,
2502
- subUnitId,
2503
- drawings
2504
- });
2505
- }
2506
- _moveInlineDrawing(drawing, offsetX, offsetY) {
2507
- const anchor = this._getInlineDrawingAnchor(drawing, offsetX, offsetY);
2508
- const { offset, segmentId, segmentPage } = anchor !== null && anchor !== void 0 ? anchor : {};
2509
- return this._commandService.executeCommand(IMoveInlineDrawingCommand.id, {
2510
- unitId: drawing.unitId,
2511
- subUnitId: drawing.unitId,
2512
- drawing,
2513
- offset,
2514
- segmentId,
2515
- segmentPage,
2516
- needRefreshDrawings: offset == null
2229
+ const mutationListener = commandService.onCommandExecuted(async (command) => {
2230
+ if (command.id === RichTextEditingMutation.id) updateFocusDrawingState();
2517
2231
  });
2518
- }
2519
- _limitDrawingInPage(drawing, object) {
2520
- const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
2521
- const { left, top, width, height, angle } = object;
2522
- const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(DocSkeletonManagerService).getSkeleton();
2523
- const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
2524
- const { pages } = skeletonData !== null && skeletonData !== void 0 ? skeletonData : {};
2525
- if (skeletonData == null || currentRender == null || pages == null) return {
2526
- left,
2527
- top,
2528
- width,
2529
- height,
2530
- angle
2531
- };
2532
- const { mainComponent } = currentRender;
2533
- const { top: docsTop, pageLayoutType, pageMarginLeft, pageMarginTop } = mainComponent;
2534
- let newTop = top;
2535
- this._liquid.reset();
2536
- for (const page of pages) {
2537
- const { marginBottom, pageHeight } = page;
2538
- const nextPage = pages[pages.indexOf(page) + 1];
2539
- if (nextPage == null) continue;
2540
- if (Tools.hasIntersectionBetweenTwoRanges(top, top + height, this._liquid.y + docsTop + pageHeight - marginBottom, this._liquid.y + docsTop + pageHeight + pageMarginTop + nextPage.marginTop)) if (top + height / 2 < this._liquid.y + docsTop + pageHeight + pageMarginTop / 2) newTop = Math.min(top, this._liquid.y + docsTop + pageHeight - marginBottom - height);
2541
- else newTop = Math.max(top, this._liquid.y + docsTop + pageHeight + pageMarginTop + nextPage.marginTop);
2542
- this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
2543
- }
2544
- return {
2545
- left,
2546
- top: newTop,
2547
- width,
2548
- height,
2549
- angle
2232
+ return () => {
2233
+ subscription.unsubscribe();
2234
+ mutationListener.dispose();
2550
2235
  };
2551
- }
2552
- _nonInlineDrawingTransform(drawing, object, isMoving = false) {
2553
- const objectPosition = drawing.isMultiTransform === BooleanNumber.TRUE ? object : this._limitDrawingInPage(drawing, object);
2554
- if (isMoving && objectPosition.top !== object.top) return;
2555
- const anchor = this._getDrawingAnchor(drawing, objectPosition);
2556
- const { offset, docTransform, segmentId, segmentPage } = anchor !== null && anchor !== void 0 ? anchor : {};
2557
- if (offset == null || docTransform == null) return this._updateMultipleDrawingDocTransform(new Map([[drawing.drawingId, object]]));
2558
- return this._commandService.executeCommand(ITransformNonInlineDrawingCommand.id, {
2559
- unitId: drawing.unitId,
2560
- subUnitId: drawing.unitId,
2561
- drawing,
2562
- offset,
2563
- docTransform,
2564
- segmentId,
2565
- segmentPage
2566
- });
2567
- }
2568
- _getSceneAndTransformerByDrawingSearch(unitId) {
2569
- if (unitId == null) return;
2570
- const renderObject = this._renderManagerService.getRenderById(unitId);
2571
- const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
2572
- if (scene == null) return;
2573
- return {
2574
- scene,
2575
- transformer: scene.getTransformerByCreate()
2236
+ }, []);
2237
+ return /* @__PURE__ */ jsxs("div", {
2238
+ className: clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": !showPanel }),
2239
+ children: [
2240
+ /* @__PURE__ */ jsx("header", {
2241
+ className: "univer-text-gray-600 dark:!univer-text-gray-200",
2242
+ children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-text-wrap.title") })
2243
+ }),
2244
+ /* @__PURE__ */ jsx("div", {
2245
+ className: "univer-text-gray-600 dark:!univer-text-gray-200",
2246
+ children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-text-wrap.wrappingStyle") })
2247
+ }),
2248
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(RadioGroup, {
2249
+ value: wrappingStyle,
2250
+ onChange: handleWrappingStyleChange,
2251
+ direction: "vertical",
2252
+ children: [
2253
+ /* @__PURE__ */ jsx(Radio, {
2254
+ value: "inline",
2255
+ children: localeService.t("docs-drawing-ui.image-text-wrap.inline")
2256
+ }),
2257
+ /* @__PURE__ */ jsx(Radio, {
2258
+ value: "wrapSquare",
2259
+ children: localeService.t("docs-drawing-ui.image-text-wrap.square")
2260
+ }),
2261
+ /* @__PURE__ */ jsx(Radio, {
2262
+ value: "wrapTopAndBottom",
2263
+ children: localeService.t("docs-drawing-ui.image-text-wrap.topAndBottom")
2264
+ }),
2265
+ /* @__PURE__ */ jsx(Radio, {
2266
+ value: "behindText",
2267
+ children: localeService.t("docs-drawing-ui.image-text-wrap.behindText")
2268
+ }),
2269
+ /* @__PURE__ */ jsx(Radio, {
2270
+ value: "inFrontOfText",
2271
+ children: localeService.t("docs-drawing-ui.image-text-wrap.inFrontText")
2272
+ })
2273
+ ]
2274
+ }) }),
2275
+ /* @__PURE__ */ jsx("div", {
2276
+ className: "univer-text-gray-600 dark:!univer-text-gray-200",
2277
+ children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-text-wrap.wrapText") })
2278
+ }),
2279
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(RadioGroup, {
2280
+ disabled: disableWrapText,
2281
+ value: wrapText,
2282
+ onChange: handleWrapTextChange,
2283
+ direction: "horizontal",
2284
+ children: [
2285
+ /* @__PURE__ */ jsx(Radio, {
2286
+ value: WrapTextType.BOTH_SIDES,
2287
+ children: localeService.t("docs-drawing-ui.image-text-wrap.bothSide")
2288
+ }),
2289
+ /* @__PURE__ */ jsx(Radio, {
2290
+ value: WrapTextType.LEFT,
2291
+ children: localeService.t("docs-drawing-ui.image-text-wrap.leftOnly")
2292
+ }),
2293
+ /* @__PURE__ */ jsx(Radio, {
2294
+ value: WrapTextType.RIGHT,
2295
+ children: localeService.t("docs-drawing-ui.image-text-wrap.rightOnly")
2296
+ })
2297
+ ]
2298
+ }) }),
2299
+ /* @__PURE__ */ jsx("div", {
2300
+ className: "univer-text-gray-600 dark:!univer-text-gray-200",
2301
+ children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-text-wrap.distanceFromText") })
2302
+ }),
2303
+ /* @__PURE__ */ jsxs("div", {
2304
+ className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
2305
+ children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-text-wrap.top") }), /* @__PURE__ */ jsx(InputNumber, {
2306
+ min: MIN_MARGIN,
2307
+ max: MAX_MARGIN,
2308
+ disabled: disableDistTB,
2309
+ precision: 1,
2310
+ value: distToText.distT,
2311
+ onChange: (val) => {
2312
+ handleDistToTextChange(val, "distT");
2313
+ }
2314
+ })] }), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-text-wrap.left") }), /* @__PURE__ */ jsx(InputNumber, {
2315
+ min: MIN_MARGIN,
2316
+ max: MAX_MARGIN,
2317
+ disabled: disableDistLR,
2318
+ precision: 1,
2319
+ value: distToText.distL,
2320
+ onChange: (val) => {
2321
+ handleDistToTextChange(val, "distL");
2322
+ }
2323
+ })] })]
2324
+ }),
2325
+ /* @__PURE__ */ jsxs("div", {
2326
+ className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
2327
+ children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-text-wrap.bottom") }), /* @__PURE__ */ jsx(InputNumber, {
2328
+ min: MIN_MARGIN,
2329
+ max: MAX_MARGIN,
2330
+ disabled: disableDistTB,
2331
+ precision: 1,
2332
+ value: distToText.distB,
2333
+ onChange: (val) => {
2334
+ handleDistToTextChange(val, "distB");
2335
+ }
2336
+ })] }), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-text-wrap.right") }), /* @__PURE__ */ jsx(InputNumber, {
2337
+ min: MIN_MARGIN,
2338
+ max: MAX_MARGIN,
2339
+ disabled: disableDistLR,
2340
+ precision: 1,
2341
+ value: distToText.distR,
2342
+ onChange: (val) => {
2343
+ handleDistToTextChange(val, "distR");
2344
+ }
2345
+ })] })]
2346
+ })
2347
+ ]
2348
+ });
2349
+ };
2350
+
2351
+ //#endregion
2352
+ //#region src/views/doc-image-panel/DocDrawingPanel.tsx
2353
+ const DocDrawingPanel = () => {
2354
+ const drawingManagerService = useDependency(IDrawingManagerService);
2355
+ const [drawings, setDrawings] = useState(drawingManagerService.getFocusDrawings());
2356
+ useEffect(() => {
2357
+ const focusDispose = drawingManagerService.focus$.subscribe((drawings) => {
2358
+ setDrawings(drawings);
2359
+ });
2360
+ return () => {
2361
+ focusDispose.unsubscribe();
2576
2362
  };
2363
+ }, []);
2364
+ return !!(drawings === null || drawings === void 0 ? void 0 : drawings.length) && /* @__PURE__ */ jsxs("div", {
2365
+ className: "univer-text-sm",
2366
+ children: [
2367
+ /* @__PURE__ */ jsx(DrawingCommonPanel, {
2368
+ drawings,
2369
+ hasAlign: false,
2370
+ hasCropper: true,
2371
+ hasGroup: false,
2372
+ hasTransform: false
2373
+ }),
2374
+ /* @__PURE__ */ jsx(DocDrawingTextWrap, { drawings }),
2375
+ /* @__PURE__ */ jsx(DocDrawingPosition, { drawings })
2376
+ ]
2377
+ });
2378
+ };
2379
+
2380
+ //#endregion
2381
+ //#region src/controllers/components.controller.ts
2382
+ /**
2383
+ * Copyright 2023-present DreamNum Co., Ltd.
2384
+ *
2385
+ * Licensed under the Apache License, Version 2.0 (the "License");
2386
+ * you may not use this file except in compliance with the License.
2387
+ * You may obtain a copy of the License at
2388
+ *
2389
+ * http://www.apache.org/licenses/LICENSE-2.0
2390
+ *
2391
+ * Unless required by applicable law or agreed to in writing, software
2392
+ * distributed under the License is distributed on an "AS IS" BASIS,
2393
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2394
+ * See the License for the specific language governing permissions and
2395
+ * limitations under the License.
2396
+ */
2397
+ let ComponentsController = class ComponentsController extends Disposable {
2398
+ constructor(_componentManager) {
2399
+ super();
2400
+ this._componentManager = _componentManager;
2401
+ this._registerComponents();
2577
2402
  }
2578
- _getTransformCoordForDocumentOffset(document, viewport, evtOffsetX, evtOffsetY) {
2579
- const { documentTransform } = document.getOffsetConfig();
2580
- const originCoord = viewport.transformVector2SceneCoord(Vector2.FromArray([evtOffsetX, evtOffsetY]));
2581
- if (!originCoord) return;
2582
- return documentTransform.clone().invert().applyPoint(originCoord);
2403
+ _registerComponents() {
2404
+ this.disposeWithMe(this._componentManager.register(COMPONENT_DOC_DRAWING_PANEL, DocDrawingPanel));
2583
2405
  }
2584
- _createOrUpdateInlineAnchor(unitId, pointsGroup) {
2585
- const currentRender = this._renderManagerService.getRenderById(unitId);
2586
- if (currentRender == null) return;
2587
- const { mainComponent, scene } = currentRender;
2588
- const { docsLeft, docsTop } = mainComponent.getOffsetConfig();
2589
- const { left: boundingLeft, top: boundingTop, height } = getAnchorBounding(pointsGroup);
2590
- const left = boundingLeft + docsLeft;
2591
- const top = boundingTop + docsTop;
2592
- if (this._anchorShape) {
2593
- this._anchorShape.transformByState({
2594
- left,
2595
- top,
2596
- height
2406
+ };
2407
+ ComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager))], ComponentsController);
2408
+
2409
+ //#endregion
2410
+ //#region src/controllers/doc-drawing-notification.controller.ts
2411
+ function getAddOrRemoveDrawings(actions) {
2412
+ if (JSONX.isNoop(actions) || !Array.isArray(actions)) return null;
2413
+ const drawingsOp = actions.find((action) => Array.isArray(action) && (action === null || action === void 0 ? void 0 : action[0]) === "drawings");
2414
+ if (drawingsOp == null || !Array.isArray(drawingsOp) || drawingsOp.length < 3) return null;
2415
+ if (typeof drawingsOp[1] === "string" && typeof drawingsOp[2] !== "object") return null;
2416
+ if (Array.isArray(drawingsOp[1]) && typeof drawingsOp[1][1] !== "object") return null;
2417
+ const drawings = [];
2418
+ if (Array.isArray(drawingsOp === null || drawingsOp === void 0 ? void 0 : drawingsOp[1])) {
2419
+ for (const op of drawingsOp) if (Array.isArray(op)) {
2420
+ var _ref, _ref2;
2421
+ drawings.push({
2422
+ type: (op === null || op === void 0 || (_ref = op[1]) === null || _ref === void 0 ? void 0 : _ref.i) ? "add" : "remove",
2423
+ drawingId: op === null || op === void 0 ? void 0 : op[0],
2424
+ drawing: op === null || op === void 0 || (_ref2 = op[1]) === null || _ref2 === void 0 ? void 0 : _ref2.i
2597
2425
  });
2598
- this._anchorShape.show();
2599
- return;
2600
2426
  }
2601
- const anchor = new Rect(INLINE_DRAWING_ANCHOR_KEY_PREFIX + generateRandomId(6), {
2602
- left,
2603
- top,
2604
- height,
2605
- strokeWidth: 2,
2606
- stroke: getColor(COLORS.darkgray, 1),
2607
- evented: false
2427
+ } else {
2428
+ var _drawingsOp$, _drawingsOp$2;
2429
+ drawings.push({
2430
+ type: ((_drawingsOp$ = drawingsOp[2]) === null || _drawingsOp$ === void 0 ? void 0 : _drawingsOp$.i) ? "add" : "remove",
2431
+ drawingId: drawingsOp[1],
2432
+ drawing: (_drawingsOp$2 = drawingsOp[2]) === null || _drawingsOp$2 === void 0 ? void 0 : _drawingsOp$2.i
2608
2433
  });
2609
- this._anchorShape = anchor;
2610
- scene.addObject(anchor, TEXT_RANGE_LAYER_INDEX);
2611
- }
2612
- _getDocObject() {
2613
- return getDocObject(this._univerInstanceService, this._renderManagerService);
2614
2434
  }
2615
- _getPageContentSize(drawing) {
2616
- const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
2617
- const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(DocSkeletonManagerService).getSkeleton();
2618
- const MAX_WIDTH = 500;
2619
- const MAX_HEIGHT = 500;
2620
- const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
2621
- if (skeletonData == null || currentRender == null) return {
2622
- width: MAX_WIDTH,
2623
- height: MAX_HEIGHT
2624
- };
2625
- const { pages } = skeletonData;
2626
- let page = null;
2627
- for (const p of pages) {
2628
- const { skeDrawings } = p;
2629
- if (skeDrawings.has(drawing.drawingId)) {
2630
- page = p;
2631
- break;
2632
- }
2435
+ return drawings;
2436
+ }
2437
+ function getReOrderedDrawings(actions) {
2438
+ if (!Array.isArray(actions) || actions.length < 3 || actions[0] !== "drawingsOrder") return [];
2439
+ const drawingIndexes = [];
2440
+ for (let i = 1; i < actions.length; i++) {
2441
+ const action = actions[i];
2442
+ if (Array.isArray(action) && typeof action[0] === "number" && typeof action[1] === "object") drawingIndexes.push(action[0]);
2443
+ else {
2444
+ drawingIndexes.length = 0;
2445
+ break;
2633
2446
  }
2634
- if (page) {
2635
- const { pageWidth, pageHeight, marginLeft, marginBottom, marginRight, marginTop } = page;
2636
- return {
2637
- width: Math.max(MAX_WIDTH, pageWidth - marginLeft - marginRight),
2638
- height: Math.max(MAX_HEIGHT, pageHeight - marginTop - marginBottom)
2447
+ }
2448
+ return drawingIndexes;
2449
+ }
2450
+ let DocDrawingAddRemoveController = class DocDrawingAddRemoveController extends Disposable {
2451
+ constructor(_univerInstanceService, _commandService, _drawingManagerService, _docDrawingService, _renderManagerService) {
2452
+ super();
2453
+ this._univerInstanceService = _univerInstanceService;
2454
+ this._commandService = _commandService;
2455
+ this._drawingManagerService = _drawingManagerService;
2456
+ this._docDrawingService = _docDrawingService;
2457
+ this._renderManagerService = _renderManagerService;
2458
+ this._initialize();
2459
+ }
2460
+ _initialize() {
2461
+ this._commandExecutedListener();
2462
+ }
2463
+ _commandExecutedListener() {
2464
+ this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
2465
+ if (command.id !== RichTextEditingMutation.id) return;
2466
+ const { unitId, actions, isSync, syncer } = command.params;
2467
+ const addOrRemoveDrawings = getAddOrRemoveDrawings(actions);
2468
+ if (addOrRemoveDrawings != null) for (const { type, drawingId, drawing } of addOrRemoveDrawings) {
2469
+ if (isSync && (drawing === null || drawing === void 0 ? void 0 : drawing.unitId) === syncer) continue;
2470
+ if (type === "add") this._addDrawings(unitId, [drawing]);
2471
+ else this._removeDrawings(unitId, [drawingId]);
2472
+ }
2473
+ }));
2474
+ this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
2475
+ if (command.id !== RichTextEditingMutation.id) return;
2476
+ const { unitId, actions } = command.params;
2477
+ if (getReOrderedDrawings(actions).length > 0) this._updateDrawingsOrder(unitId);
2478
+ }));
2479
+ this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
2480
+ var _this$_univerInstance;
2481
+ if (command.id !== UndoCommand.id && command.id !== RedoCommand.id) return;
2482
+ const unitId = (_this$_univerInstance = this._univerInstanceService.getCurrentUniverDocInstance()) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getUnitId();
2483
+ const focusedDrawings = this._drawingManagerService.getFocusDrawings();
2484
+ if (unitId == null || focusedDrawings.length === 0) return;
2485
+ const renderObject = this._renderManagerService.getRenderById(unitId);
2486
+ const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
2487
+ if (scene == null) return false;
2488
+ scene.getTransformerByCreate().refreshControls();
2489
+ }));
2490
+ }
2491
+ _addDrawings(unitId, drawings) {
2492
+ const drawingManagerService = this._drawingManagerService;
2493
+ const docDrawingService = this._docDrawingService;
2494
+ const { subUnitId, redo: op, objects } = this._docDrawingService.getBatchAddOp(drawings);
2495
+ drawingManagerService.applyJson1(unitId, subUnitId, op);
2496
+ docDrawingService.applyJson1(unitId, subUnitId, op);
2497
+ drawingManagerService.addNotification(objects);
2498
+ docDrawingService.addNotification(objects);
2499
+ }
2500
+ _removeDrawings(unitId, drawingIds) {
2501
+ const drawingManagerService = this._drawingManagerService;
2502
+ const docDrawingService = this._docDrawingService;
2503
+ const { subUnitId, redo: op, objects } = this._docDrawingService.getBatchRemoveOp(drawingIds.map((drawingId) => {
2504
+ return {
2505
+ unitId,
2506
+ subUnitId: unitId,
2507
+ drawingId
2639
2508
  };
2640
- } else return {
2641
- width: MAX_WIDTH,
2642
- height: MAX_HEIGHT
2509
+ }));
2510
+ drawingManagerService.applyJson1(unitId, subUnitId, op);
2511
+ docDrawingService.applyJson1(unitId, subUnitId, op);
2512
+ drawingManagerService.removeNotification(objects);
2513
+ docDrawingService.removeNotification(objects);
2514
+ }
2515
+ _updateDrawingsOrder(unitId) {
2516
+ const documentDataModel = this._univerInstanceService.getUniverDocInstance(unitId);
2517
+ if (documentDataModel == null) return;
2518
+ const { drawings, drawingsOrder } = documentDataModel.getSnapshot();
2519
+ if (drawingsOrder == null) return;
2520
+ const renderOrder = getDocDrawingRenderOrder(drawingsOrder, drawings);
2521
+ const drawingManagerService = this._drawingManagerService;
2522
+ const docDrawingService = this._docDrawingService;
2523
+ drawingManagerService.setDrawingOrder(unitId, unitId, renderOrder);
2524
+ docDrawingService.setDrawingOrder(unitId, unitId, drawingsOrder);
2525
+ const objects = {
2526
+ unitId,
2527
+ subUnitId: unitId,
2528
+ drawingIds: renderOrder
2643
2529
  };
2530
+ drawingManagerService.orderNotification(objects);
2531
+ docDrawingService.orderNotification({
2532
+ unitId,
2533
+ subUnitId: unitId,
2534
+ drawingIds: drawingsOrder
2535
+ });
2644
2536
  }
2645
2537
  };
2646
- DocDrawingTransformerController = __decorate([
2647
- __decorateParam(0, ICommandService),
2648
- __decorateParam(1, IUniverInstanceService),
2538
+ DocDrawingAddRemoveController = __decorate([
2539
+ __decorateParam(0, IUniverInstanceService),
2540
+ __decorateParam(1, ICommandService),
2649
2541
  __decorateParam(2, IDrawingManagerService),
2650
- __decorateParam(3, IRenderManagerService)
2651
- ], DocDrawingTransformerController);
2542
+ __decorateParam(3, IDocDrawingService),
2543
+ __decorateParam(4, IRenderManagerService)
2544
+ ], DocDrawingAddRemoveController);
2652
2545
 
2653
2546
  //#endregion
2654
- //#region src/menu/schema.ts
2655
- const menuSchema = {
2656
- [RibbonInsertGroup.MEDIA]: { [DOCS_IMAGE_MENU_ID]: {
2657
- order: 0,
2658
- menuItemFactory: ImageMenuFactory,
2659
- [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
2660
- order: 0,
2661
- menuItemFactory: UploadFloatImageMenuFactory
2662
- }
2663
- } },
2664
- [ContextMenuPosition.PARAGRAPH]: {
2665
- [ContextMenuGroup.LAYOUT]: { [INSERT_BELLOW_MENU_ID]: { [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
2666
- order: 5,
2667
- menuItemFactory: UploadFloatImageMenuFactory
2668
- } } },
2669
- [EMPTY_PARAGRAPH_MENU_ID]: { [ContextMenuGroup.LAYOUT]: { [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
2670
- order: 5,
2671
- menuItemFactory: UploadFloatImageMenuFactory
2672
- } } },
2673
- [DOC_CONTENT_INSERT_MENU_ID]: { [ContextMenuGroup.LAYOUT]: { [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
2674
- order: 5,
2675
- menuItemFactory: UploadFloatImageMenuFactory
2676
- } } }
2547
+ //#region src/views/DocPrintingFloatDom.tsx
2548
+ const DocPrintingFloatDom = (props) => {
2549
+ const { floatDomInfos, scene, offset, bound } = props;
2550
+ const width = bound.right - bound.left;
2551
+ const height = bound.bottom - bound.top;
2552
+ return /* @__PURE__ */ jsx("div", {
2553
+ className: "univer-absolute univer-left-0 univer-top-0",
2554
+ children: useMemo(() => floatDomInfos.map((info) => {
2555
+ const { width = 0, height = 0, left = 0, top = 0 } = info.transform;
2556
+ const domPos = calcDocFloatDomPositionByRect({
2557
+ left,
2558
+ right: left + width,
2559
+ top,
2560
+ bottom: top + height
2561
+ }, scene);
2562
+ const floatDom = {
2563
+ position$: new BehaviorSubject(domPos),
2564
+ position: domPos,
2565
+ id: info.drawingId,
2566
+ componentKey: info.componentKey,
2567
+ onPointerMove: () => {},
2568
+ onPointerDown: () => {},
2569
+ onPointerUp: () => {},
2570
+ onWheel: () => {},
2571
+ unitId: info.unitId,
2572
+ data: info.data
2573
+ };
2574
+ return [info.drawingId, floatDom];
2575
+ }).filter(([_, floatDom]) => !(floatDom.position.endX < 0 || floatDom.position.endY < 0 || floatDom.position.startX > width || floatDom.position.startY > height)), [
2576
+ floatDomInfos,
2577
+ scene,
2578
+ offset,
2579
+ width,
2580
+ height
2581
+ ]).map(([id, floatDom]) => /* @__PURE__ */ jsx(PrintFloatDomSingle, {
2582
+ layer: floatDom,
2583
+ id,
2584
+ position: floatDom.position
2585
+ }, id))
2586
+ });
2587
+ };
2588
+ function mountDocPrintingFloatDom(props, root, injector) {
2589
+ render(/* @__PURE__ */ jsx(connectInjector(DocPrintingFloatDom, injector), { ...props }), root);
2590
+ return () => unmount(root);
2591
+ }
2592
+
2593
+ //#endregion
2594
+ //#region src/controllers/doc-drawing-printing.controller.ts
2595
+ let DocDrawingPrintingController = class DocDrawingPrintingController extends Disposable {
2596
+ constructor(_docPrintInterceptorService, _drawingRenderService, _drawingManagerService, _componetManager, _injector) {
2597
+ super();
2598
+ this._docPrintInterceptorService = _docPrintInterceptorService;
2599
+ this._drawingRenderService = _drawingRenderService;
2600
+ this._drawingManagerService = _drawingManagerService;
2601
+ this._componetManager = _componetManager;
2602
+ this._injector = _injector;
2603
+ this._initPrinting();
2604
+ this._initPrintingDom();
2605
+ }
2606
+ _initPrinting() {
2607
+ this.disposeWithMe(this._docPrintInterceptorService.interceptor.intercept(this._docPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT, { handler: (_param, pos, next) => {
2608
+ const { unitId, scene } = pos;
2609
+ const unitData = this._drawingManagerService.getDrawingDataForUnit(unitId);
2610
+ const subUnitData = unitData === null || unitData === void 0 ? void 0 : unitData[unitId];
2611
+ if (subUnitData) subUnitData.order.forEach((id) => {
2612
+ const drawing = subUnitData.data[id];
2613
+ if (drawing.drawingType !== DrawingTypeEnum.DRAWING_CHART && drawing.drawingType !== DrawingTypeEnum.DRAWING_DOM) this._drawingRenderService.renderDrawing(drawing, scene);
2614
+ });
2615
+ return next();
2616
+ } }));
2617
+ }
2618
+ _initPrintingDom() {
2619
+ this.disposeWithMe(this._docPrintInterceptorService.interceptor.intercept(this._docPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT, { handler: (disposableCollection, pos, next) => {
2620
+ const { unitId } = pos;
2621
+ const unitData = this._drawingManagerService.getDrawingDataForUnit(unitId);
2622
+ const subUnitData = unitData === null || unitData === void 0 ? void 0 : unitData[unitId];
2623
+ if (subUnitData) {
2624
+ const unmountPrintingFloatDom = mountDocPrintingFloatDom({
2625
+ unitId,
2626
+ floatDomInfos: subUnitData.order.map((id) => {
2627
+ const drawing = subUnitData.data[id];
2628
+ if (drawing.drawingType === DrawingTypeEnum.DRAWING_CHART) return {
2629
+ ...drawing,
2630
+ componentKey: this._componetManager.get(DOC_DRAWING_PRINTING_COMPONENT_KEY)
2631
+ };
2632
+ if (drawing.drawingType === DrawingTypeEnum.DRAWING_DOM) {
2633
+ const printingComponentKey = this._docPrintInterceptorService.getPrintComponent(drawing.componentKey);
2634
+ return {
2635
+ ...drawing,
2636
+ componentKey: this._componetManager.get(printingComponentKey || drawing.componentKey)
2637
+ };
2638
+ }
2639
+ return null;
2640
+ }).filter(Boolean),
2641
+ scene: pos.scene,
2642
+ skeleton: pos.skeleton,
2643
+ offset: pos.offset,
2644
+ bound: pos.bound
2645
+ }, pos.root, this._injector);
2646
+ disposableCollection === null || disposableCollection === void 0 || disposableCollection.add(() => {
2647
+ unmountPrintingFloatDom();
2648
+ });
2649
+ return next(disposableCollection);
2650
+ }
2651
+ } }));
2677
2652
  }
2678
2653
  };
2654
+ DocDrawingPrintingController = __decorate([
2655
+ __decorateParam(0, Inject(DocPrintInterceptorService)),
2656
+ __decorateParam(1, Inject(DrawingRenderService)),
2657
+ __decorateParam(2, IDrawingManagerService),
2658
+ __decorateParam(3, Inject(ComponentManager)),
2659
+ __decorateParam(4, Inject(Injector))
2660
+ ], DocDrawingPrintingController);
2679
2661
 
2680
2662
  //#endregion
2681
- //#region src/views/doc-image-panel/DocDrawingPosition.tsx
2682
- const MIN_OFFSET = -1e3;
2683
- const MAX_OFFSET = 1e3;
2684
- const DocDrawingPosition = (props) => {
2685
- const commandService = useDependency(ICommandService);
2686
- const localeService = useDependency(LocaleService);
2687
- const drawingManagerService = useDependency(IDrawingManagerService);
2688
- const renderManagerService = useDependency(IRenderManagerService);
2689
- const univerInstanceService = useDependency(IUniverInstanceService);
2690
- const { drawings } = props;
2691
- const drawingParam = drawings[0];
2692
- if (drawingParam == null) return;
2693
- const { unitId } = drawingParam;
2694
- const documentDataModel = univerInstanceService.getUniverDocInstance(unitId);
2695
- const documentFlavor = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getSnapshot().documentStyle.documentFlavor;
2696
- const renderObject = renderManagerService.getRenderById(unitId);
2697
- const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
2698
- if (scene == null) return;
2699
- const transformer = scene.getTransformerByCreate();
2700
- const HORIZONTAL_RELATIVE_FROM = [
2701
- {
2702
- label: localeService.t("docs-drawing-ui.image-position.column"),
2703
- value: String(ObjectRelativeFromH.COLUMN)
2704
- },
2705
- {
2706
- label: localeService.t("docs-drawing-ui.image-position.page"),
2707
- value: String(ObjectRelativeFromH.PAGE)
2708
- },
2709
- {
2710
- label: localeService.t("docs-drawing-ui.image-position.margin"),
2711
- value: String(ObjectRelativeFromH.MARGIN)
2712
- }
2713
- ];
2714
- const VERTICAL_RELATIVE_FROM = [
2715
- {
2716
- label: localeService.t("docs-drawing-ui.image-position.line"),
2717
- value: String(ObjectRelativeFromV.LINE),
2718
- disabled: documentFlavor === DocumentFlavor.MODERN
2719
- },
2720
- {
2721
- label: localeService.t("docs-drawing-ui.image-position.page"),
2722
- value: String(ObjectRelativeFromV.PAGE),
2723
- disabled: documentFlavor === DocumentFlavor.MODERN
2724
- },
2725
- {
2726
- label: localeService.t("docs-drawing-ui.image-position.margin"),
2727
- value: String(ObjectRelativeFromV.MARGIN),
2728
- disabled: documentFlavor === DocumentFlavor.MODERN
2729
- },
2730
- {
2731
- label: localeService.t("docs-drawing-ui.image-position.paragraph"),
2732
- value: String(ObjectRelativeFromV.PARAGRAPH)
2663
+ //#region src/controllers/render-controllers/doc-drawing-transform-update.controller.ts
2664
+ function getDocsDrawingPageClipBounds(config) {
2665
+ const { docsLeft, docsTop, pageOffsetLeft, pageOffsetTop, clipOffsetLeft = 0, clipOffsetTop = 0, page } = config;
2666
+ const { pageWidth, pageHeight } = page;
2667
+ if (!Number.isFinite(pageWidth) || !Number.isFinite(pageHeight) || pageWidth <= 0 || pageHeight <= 0) return;
2668
+ return {
2669
+ left: docsLeft + pageOffsetLeft + clipOffsetLeft,
2670
+ top: docsTop + pageOffsetTop + clipOffsetTop,
2671
+ width: pageWidth,
2672
+ height: pageHeight
2673
+ };
2674
+ }
2675
+ function getDocsDrawingClipPage(config) {
2676
+ const { drawing, hostPage, page } = config;
2677
+ if (hostPage == null || drawing.behindText !== true || drawing.transform == null) return page;
2678
+ const { width, height } = drawing.transform;
2679
+ if (width == null || height == null) return page;
2680
+ if (width > page.pageWidth || height > page.pageHeight) return hostPage;
2681
+ const widthRatio = width / hostPage.pageWidth;
2682
+ const heightRatio = height / hostPage.pageHeight;
2683
+ if (widthRatio >= .8 && heightRatio >= .8) return hostPage;
2684
+ return page;
2685
+ }
2686
+ function getDocsPageRelativeDrawingLeft(config) {
2687
+ const { hostPage, positionH, width } = config;
2688
+ if (positionH.relativeFrom !== ObjectRelativeFromH.PAGE) return;
2689
+ if (positionH.align === AlignTypeH.RIGHT) return hostPage.pageWidth - width;
2690
+ if (positionH.align === AlignTypeH.CENTER) return hostPage.pageWidth / 2 - width / 2;
2691
+ if (positionH.posOffset != null) return positionH.posOffset;
2692
+ return 0;
2693
+ }
2694
+ function getDocsPageRelativeDrawingTop(config) {
2695
+ const { hostPage, positionV, height } = config;
2696
+ if (positionV.relativeFrom !== ObjectRelativeFromV.PAGE) return;
2697
+ if (positionV.align === AlignTypeV.BOTTOM) return hostPage.pageHeight - height;
2698
+ if (positionV.align === AlignTypeV.CENTER) return hostPage.pageHeight / 2 - height / 2;
2699
+ if (positionV.posOffset != null) return positionV.posOffset;
2700
+ return 0;
2701
+ }
2702
+ function getDocsPageRelativeDrawingAnchorPage(config) {
2703
+ const { page, clipPage, hostPage } = config;
2704
+ if (hostPage != null && hostPage === clipPage) return hostPage;
2705
+ if (hostPage == null && page === clipPage) return page;
2706
+ }
2707
+ function getDocsDrawingBehindText(config) {
2708
+ const { drawingOrigin, hostPage } = config;
2709
+ if (hostPage != null) return true;
2710
+ return drawingOrigin.layoutType === PositionedObjectLayoutType.WRAP_NONE && drawingOrigin.behindDoc === BooleanNumber.TRUE;
2711
+ }
2712
+ function getDocsTableCellDrawingOffset(unitId, table, row, cell) {
2713
+ const sourceTableId = getTableIdAndSliceIndex(table.tableId).tableId;
2714
+ const viewport = getDocsTableRenderViewport(unitId, sourceTableId);
2715
+ const scrollLeft = hasHorizontalTableViewport(viewport) ? viewport.scrollLeft : 0;
2716
+ return {
2717
+ left: table.left + cell.left - scrollLeft + cell.marginLeft,
2718
+ top: table.top + row.top + cell.marginTop
2719
+ };
2720
+ }
2721
+ function hasHorizontalTableViewport(viewport) {
2722
+ var _viewport$leadingInse, _viewport$trailingIns;
2723
+ return viewport != null && ((_viewport$leadingInse = viewport.leadingInsetLeft) !== null && _viewport$leadingInse !== void 0 ? _viewport$leadingInse : 0) + viewport.contentWidth + ((_viewport$trailingIns = viewport.trailingInsetRight) !== null && _viewport$trailingIns !== void 0 ? _viewport$trailingIns : 0) > viewport.viewportWidth;
2724
+ }
2725
+ let DocDrawingTransformUpdateController = class DocDrawingTransformUpdateController extends Disposable {
2726
+ constructor(_context, _docSkeletonManagerService, _commandService, _editorService, _drawingManagerService, _docRefreshDrawingsService, _univerInstanceService, _lifecycleService) {
2727
+ super();
2728
+ this._context = _context;
2729
+ this._docSkeletonManagerService = _docSkeletonManagerService;
2730
+ this._commandService = _commandService;
2731
+ this._editorService = _editorService;
2732
+ this._drawingManagerService = _drawingManagerService;
2733
+ this._docRefreshDrawingsService = _docRefreshDrawingsService;
2734
+ this._univerInstanceService = _univerInstanceService;
2735
+ this._lifecycleService = _lifecycleService;
2736
+ _defineProperty(this, "_liquid", new Liquid());
2737
+ this._initialize();
2738
+ this._commandExecutedListener();
2739
+ }
2740
+ _initialize() {
2741
+ this._initialRenderRefresh();
2742
+ this._drawingInitializeListener();
2743
+ this._initResize();
2744
+ }
2745
+ _initialRenderRefresh() {
2746
+ this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe((documentSkeleton) => {
2747
+ if (documentSkeleton == null) return;
2748
+ this._refreshDrawing(documentSkeleton);
2749
+ }));
2750
+ this.disposeWithMe(this._docRefreshDrawingsService.refreshDrawings$.subscribe((skeleton) => {
2751
+ if (skeleton == null) return;
2752
+ this._refreshDrawing(skeleton);
2753
+ }));
2754
+ }
2755
+ _commandExecutedListener() {
2756
+ const updateCommandList = [RichTextEditingMutation.id, SetDocZoomRatioOperation.id];
2757
+ this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
2758
+ if (updateCommandList.includes(command.id)) {
2759
+ const { unitId: commandUnitId } = command.params;
2760
+ const { unitId, mainComponent } = this._context;
2761
+ if (commandUnitId !== unitId) return;
2762
+ const skeleton = this._docSkeletonManagerService.getSkeleton();
2763
+ if (skeleton == null) return;
2764
+ if (this._editorService.isEditor(unitId)) {
2765
+ mainComponent === null || mainComponent === void 0 || mainComponent.makeDirty();
2766
+ return;
2767
+ }
2768
+ this._refreshDrawing(skeleton);
2769
+ }
2770
+ }));
2771
+ }
2772
+ _initResize() {
2773
+ this.disposeWithMe(fromEventSubject(this._context.engine.onTransformChange$).pipe(filter((evt) => evt.type === TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize), debounceTime(16)).subscribe(() => {
2774
+ var _scene$getTransformer;
2775
+ const skeleton = this._docSkeletonManagerService.getSkeleton();
2776
+ const { scene } = this._context;
2777
+ (_scene$getTransformer = scene.getTransformer()) === null || _scene$getTransformer === void 0 || _scene$getTransformer.refreshControls();
2778
+ this._refreshDrawing(skeleton);
2779
+ }));
2780
+ }
2781
+ _refreshDrawing(skeleton) {
2782
+ const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
2783
+ const { mainComponent, unitId } = this._context;
2784
+ const documentComponent = mainComponent;
2785
+ if (!skeletonData) return;
2786
+ const { left: docsLeft, top: docsTop, pageLayoutType, pageMarginLeft, pageMarginTop } = documentComponent;
2787
+ if (docsLeft <= -1e4 || docsTop <= -1e4) return;
2788
+ const { pages, skeHeaders, skeFooters } = skeletonData;
2789
+ const updateDrawingMap = {};
2790
+ this._liquid.reset();
2791
+ /**
2792
+ * TODO: @DR-Univer We should not refresh all floating elements, but instead make a diff.
2793
+ */
2794
+ for (let i = 0, len = pages.length; i < len; i++) {
2795
+ const page = pages[i];
2796
+ const { headerId, footerId, pageWidth } = page;
2797
+ if (headerId) {
2798
+ var _skeHeaders$get;
2799
+ const headerPage = (_skeHeaders$get = skeHeaders.get(headerId)) === null || _skeHeaders$get === void 0 ? void 0 : _skeHeaders$get.get(pageWidth);
2800
+ if (headerPage) {
2801
+ this._calculateDrawingPosition(unitId, headerPage, docsLeft, docsTop, updateDrawingMap, headerPage.marginTop, page.marginLeft, page);
2802
+ this._calculateTableCellDrawingPositions(unitId, headerPage, docsLeft, docsTop, updateDrawingMap, headerPage.marginTop, page.marginLeft);
2803
+ }
2804
+ }
2805
+ if (footerId) {
2806
+ var _skeFooters$get;
2807
+ const footerPage = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
2808
+ if (footerPage) {
2809
+ const footerTop = page.pageHeight - page.marginBottom + footerPage.marginTop;
2810
+ this._calculateDrawingPosition(unitId, footerPage, docsLeft, docsTop, updateDrawingMap, footerTop, page.marginLeft, page);
2811
+ this._calculateTableCellDrawingPositions(unitId, footerPage, docsLeft, docsTop, updateDrawingMap, footerTop, page.marginLeft);
2812
+ }
2813
+ }
2814
+ this._calculateDrawingPosition(unitId, page, docsLeft, docsTop, updateDrawingMap, page.marginTop, page.marginLeft);
2815
+ this._calculateTableCellDrawingPositions(unitId, page, docsLeft, docsTop, updateDrawingMap, page.marginTop, page.marginLeft);
2816
+ this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
2733
2817
  }
2734
- ];
2735
- const [disabled, setDisabled] = useState(true);
2736
- const [hPosition, setHPosition] = useState({
2737
- relativeFrom: ObjectRelativeFromH.PAGE,
2738
- posOffset: 0
2739
- });
2740
- const [vPosition, setVPosition] = useState({
2741
- relativeFrom: ObjectRelativeFromV.PAGE,
2742
- posOffset: 0
2743
- });
2744
- const [followTextMove, setFollowTextMove] = useState(true);
2745
- const [showPanel, setShowPanel] = useState(true);
2746
- function handlePositionChange(direction, value) {
2747
- var _renderManagerService;
2748
- if (direction === "positionH") setHPosition(value);
2749
- else setVPosition(value);
2750
- const focusDrawings = drawingManagerService.getFocusDrawings();
2751
- if (focusDrawings.length === 0) return;
2752
- const drawings = focusDrawings.map((drawing) => {
2818
+ const updateDrawings = Object.values(updateDrawingMap);
2819
+ for (const drawing of updateDrawings) drawing.hidden = false;
2820
+ const staleNonMultiDrawings = this._getStaleNonMultiDrawings(unitId, updateDrawingMap);
2821
+ const nonMultiDrawings = updateDrawings.filter((drawing) => !drawing.isMultiTransform).concat(staleNonMultiDrawings);
2822
+ const multiDrawings = updateDrawings.filter((drawing) => drawing.isMultiTransform);
2823
+ if (nonMultiDrawings.length > 0) this._drawingManagerService.refreshTransform(nonMultiDrawings);
2824
+ this._handleMultiDrawingsTransform(multiDrawings);
2825
+ }
2826
+ _getStaleNonMultiDrawings(unitId, updateDrawingMap) {
2827
+ var _this$_drawingManager;
2828
+ const drawingData = (_this$_drawingManager = this._drawingManagerService.getDrawingData(unitId, unitId)) !== null && _this$_drawingManager !== void 0 ? _this$_drawingManager : {};
2829
+ return Object.values(drawingData).filter((drawing) => drawing.isMultiTransform !== BooleanNumber.TRUE).filter((drawing) => updateDrawingMap[drawing.drawingId] == null).map((drawing) => {
2830
+ var _drawing$transforms, _drawing$isMultiTrans;
2753
2831
  return {
2754
- unitId: drawing.unitId,
2755
- subUnitId: drawing.subUnitId,
2756
- drawingId: drawing.drawingId
2832
+ unitId,
2833
+ subUnitId: unitId,
2834
+ drawingId: drawing.drawingId,
2835
+ behindText: false,
2836
+ hidden: true,
2837
+ transform: drawing.transform,
2838
+ transforms: (_drawing$transforms = drawing.transforms) !== null && _drawing$transforms !== void 0 ? _drawing$transforms : [],
2839
+ isMultiTransform: (_drawing$isMultiTrans = drawing.isMultiTransform) !== null && _drawing$isMultiTrans !== void 0 ? _drawing$isMultiTrans : BooleanNumber.FALSE
2757
2840
  };
2758
2841
  });
2759
- commandService.executeCommand(UpdateDrawingDocTransformCommand.id, {
2760
- unitId: focusDrawings[0].unitId,
2761
- subUnitId: focusDrawings[0].unitId,
2762
- drawings: drawings.map((drawing) => ({
2763
- drawingId: drawing.drawingId,
2764
- key: direction,
2765
- value
2766
- }))
2842
+ }
2843
+ _handleMultiDrawingsTransform(multiDrawings) {
2844
+ const { scene, unitId } = this._context;
2845
+ const transformer = scene.getTransformerByCreate();
2846
+ multiDrawings.forEach((updateParam) => {
2847
+ const param = this._drawingManagerService.getDrawingByParam(updateParam);
2848
+ if (param == null) return;
2849
+ param.transform = updateParam.transform;
2850
+ param.transforms = updateParam.transforms;
2851
+ param.isMultiTransform = updateParam.isMultiTransform;
2767
2852
  });
2768
- const docSelectionRenderService = (_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(DocSelectionRenderService);
2769
- if (docSelectionRenderService) docSelectionRenderService.blur();
2770
- transformer.refreshControls();
2853
+ const selectedObjectKeys = [...transformer.getSelectedObjectMap().keys()];
2854
+ const allMultiDrawings = Object.values(this._drawingManagerService.getDrawingData(unitId, unitId)).filter((drawing) => drawing.isMultiTransform === BooleanNumber.TRUE);
2855
+ this._drawingManagerService.removeNotification(allMultiDrawings);
2856
+ if (multiDrawings.length > 0) this._drawingManagerService.addNotification(multiDrawings);
2857
+ for (const key of selectedObjectKeys) {
2858
+ const drawingShape = scene.getObject(key);
2859
+ if (drawingShape) transformer.setSelectedControl(drawingShape);
2860
+ }
2771
2861
  }
2772
- function handleHorizontalRelativeFromChange(value) {
2773
- var _renderManagerService2;
2774
- const prevRelativeFrom = hPosition.relativeFrom;
2775
- const prevPosOffset = hPosition.posOffset;
2776
- const relativeFrom = Number(value);
2777
- if (prevRelativeFrom === relativeFrom) return;
2778
- const focusDrawings = drawingManagerService.getFocusDrawings();
2779
- if (focusDrawings.length === 0) return;
2780
- const drawingId = focusDrawings[0].drawingId;
2781
- const unitId = focusDrawings[0].unitId;
2782
- let drawing = null;
2783
- let pageMarginLeft = 0;
2784
- const skeleton = (_renderManagerService2 = renderManagerService.getRenderById(unitId)) === null || _renderManagerService2 === void 0 ? void 0 : _renderManagerService2.with(DocSkeletonManagerService).getSkeleton();
2785
- const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
2786
- if (skeletonData == null) return;
2787
- const { pages, skeHeaders, skeFooters } = skeletonData;
2788
- for (const page of pages) {
2789
- var _skeHeaders$get, _skeFooters$get;
2790
- const { marginLeft, skeDrawings, headerId, footerId, pageWidth } = page;
2791
- if (skeDrawings.has(drawingId)) {
2792
- drawing = skeDrawings.get(drawingId);
2793
- pageMarginLeft = marginLeft;
2794
- break;
2862
+ _calculateDrawingPosition(unitId, page, docsLeft, docsTop, updateDrawingMap, marginTop, marginLeft, hostPage, clipOffset) {
2863
+ const { skeDrawings } = page;
2864
+ const pageOffsetLeft = this._liquid.x;
2865
+ const pageOffsetTop = this._liquid.y;
2866
+ this._liquid.translatePagePadding({
2867
+ marginTop,
2868
+ marginLeft
2869
+ });
2870
+ skeDrawings.forEach((drawing) => {
2871
+ const { aLeft, aTop, height, width, angle, drawingId, drawingOrigin } = drawing;
2872
+ const behindText = getDocsDrawingBehindText({
2873
+ drawingOrigin,
2874
+ hostPage
2875
+ });
2876
+ const { isMultiTransform = BooleanNumber.FALSE } = drawingOrigin;
2877
+ const clipPage = getDocsDrawingClipPage({
2878
+ drawing: {
2879
+ behindText,
2880
+ transform: {
2881
+ width,
2882
+ height
2883
+ }
2884
+ },
2885
+ hostPage,
2886
+ page
2887
+ });
2888
+ const pageClipBounds = getDocsDrawingPageClipBounds({
2889
+ docsLeft,
2890
+ docsTop,
2891
+ pageOffsetLeft,
2892
+ pageOffsetTop,
2893
+ clipOffsetLeft: clipOffset === null || clipOffset === void 0 ? void 0 : clipOffset.left,
2894
+ clipOffsetTop: clipOffset === null || clipOffset === void 0 ? void 0 : clipOffset.top,
2895
+ page: clipPage
2896
+ });
2897
+ const pageRelativeAnchorPage = drawingOrigin.layoutType === PositionedObjectLayoutType.INLINE ? void 0 : getDocsPageRelativeDrawingAnchorPage({
2898
+ page,
2899
+ clipPage,
2900
+ hostPage
2901
+ });
2902
+ const pageRelativeLeft = pageRelativeAnchorPage != null ? getDocsPageRelativeDrawingLeft({
2903
+ hostPage: pageRelativeAnchorPage,
2904
+ positionH: drawingOrigin.docTransform.positionH,
2905
+ width
2906
+ }) : void 0;
2907
+ const pageRelativeTop = pageRelativeAnchorPage != null ? getDocsPageRelativeDrawingTop({
2908
+ hostPage: pageRelativeAnchorPage,
2909
+ positionV: drawingOrigin.docTransform.positionV,
2910
+ height
2911
+ }) : void 0;
2912
+ const transform = {
2913
+ left: (pageRelativeLeft !== null && pageRelativeLeft !== void 0 ? pageRelativeLeft : aLeft) + docsLeft + (pageRelativeLeft == null ? this._liquid.x : pageOffsetLeft),
2914
+ top: (pageRelativeTop !== null && pageRelativeTop !== void 0 ? pageRelativeTop : aTop) + docsTop + (pageRelativeTop == null ? this._liquid.y : pageOffsetTop),
2915
+ width,
2916
+ height,
2917
+ angle,
2918
+ clipBounds: pageClipBounds
2919
+ };
2920
+ if (updateDrawingMap[drawingId] == null) updateDrawingMap[drawingId] = {
2921
+ unitId,
2922
+ subUnitId: unitId,
2923
+ drawingId,
2924
+ behindText,
2925
+ transform,
2926
+ transforms: [transform],
2927
+ isMultiTransform
2928
+ };
2929
+ else if (isMultiTransform === BooleanNumber.TRUE) updateDrawingMap[drawingId].transforms.push(transform);
2930
+ });
2931
+ this._liquid.restorePagePadding({
2932
+ marginTop,
2933
+ marginLeft
2934
+ });
2935
+ }
2936
+ _calculateTableCellDrawingPositions(unitId, page, docsLeft, docsTop, updateDrawingMap, baseMarginTop, baseMarginLeft) {
2937
+ var _page$skeTables;
2938
+ (_page$skeTables = page.skeTables) === null || _page$skeTables === void 0 || _page$skeTables.forEach((table) => {
2939
+ table.rows.forEach((row) => {
2940
+ row.cells.forEach((cell) => {
2941
+ const cellOffset = getDocsTableCellDrawingOffset(unitId, table, row, cell);
2942
+ const marginTop = baseMarginTop + cellOffset.top;
2943
+ const marginLeft = baseMarginLeft + cellOffset.left;
2944
+ this._calculateDrawingPosition(unitId, cell, docsLeft, docsTop, updateDrawingMap, marginTop, marginLeft, void 0, {
2945
+ left: marginLeft,
2946
+ top: marginTop
2947
+ });
2948
+ this._calculateTableCellDrawingPositions(unitId, cell, docsLeft, docsTop, updateDrawingMap, marginTop, marginLeft);
2949
+ });
2950
+ });
2951
+ });
2952
+ }
2953
+ _drawingInitializeListener() {
2954
+ const init = () => {
2955
+ const skeleton = this._docSkeletonManagerService.getSkeleton();
2956
+ if (skeleton == null) return;
2957
+ this._drawingManagerService.initializeNotification(this._context.unitId);
2958
+ this._refreshDrawing(skeleton);
2959
+ };
2960
+ if (this._lifecycleService.stage >= LifecycleStages.Rendered) if (this._docSkeletonManagerService.getSkeleton()) init();
2961
+ else setTimeout(init, 500);
2962
+ else this.disposeWithMe(this._lifecycleService.lifecycle$.pipe(filter((stage) => stage === LifecycleStages.Rendered)).subscribe(init));
2963
+ }
2964
+ };
2965
+ DocDrawingTransformUpdateController = __decorate([
2966
+ __decorateParam(1, Inject(DocSkeletonManagerService)),
2967
+ __decorateParam(2, ICommandService),
2968
+ __decorateParam(3, IEditorService),
2969
+ __decorateParam(4, IDrawingManagerService),
2970
+ __decorateParam(5, Inject(DocRefreshDrawingsService)),
2971
+ __decorateParam(6, IUniverInstanceService),
2972
+ __decorateParam(7, Inject(LifecycleService))
2973
+ ], DocDrawingTransformUpdateController);
2974
+
2975
+ //#endregion
2976
+ //#region src/controllers/doc-drawing-transformer-update.controller.ts
2977
+ const INLINE_DRAWING_ANCHOR_KEY_PREFIX = "__InlineDrawingAnchor__";
2978
+ function getDocsTableCellAnchorContext(unitId, cell) {
2979
+ var _row$cells;
2980
+ const row = cell.parent;
2981
+ const table = row === null || row === void 0 ? void 0 : row.parent;
2982
+ const hostPage = table === null || table === void 0 ? void 0 : table.parent;
2983
+ if (!row || !table || !hostPage || !((_row$cells = row.cells) === null || _row$cells === void 0 ? void 0 : _row$cells.includes(cell))) return null;
2984
+ return {
2985
+ cell,
2986
+ hostPage,
2987
+ offset: getDocsTableCellDrawingOffset(unitId, table, row, cell),
2988
+ row,
2989
+ table
2990
+ };
2991
+ }
2992
+ let DocDrawingTransformerController = class DocDrawingTransformerController extends Disposable {
2993
+ constructor(_commandService, _univerInstanceService, _drawingManagerService, _renderManagerService) {
2994
+ super();
2995
+ this._commandService = _commandService;
2996
+ this._univerInstanceService = _univerInstanceService;
2997
+ this._drawingManagerService = _drawingManagerService;
2998
+ this._renderManagerService = _renderManagerService;
2999
+ _defineProperty(this, "_liquid", new Liquid());
3000
+ _defineProperty(this, "_listenerOnImageMap", /* @__PURE__ */ new Set());
3001
+ _defineProperty(this, "_transformerCache", /* @__PURE__ */ new Map());
3002
+ _defineProperty(this, "_anchorShape", void 0);
3003
+ this._init();
3004
+ }
3005
+ _init() {
3006
+ this._listenDrawingFocus();
3007
+ }
3008
+ _listenDrawingFocus() {
3009
+ this.disposeWithMe(this._drawingManagerService.add$.subscribe((drawingParams) => {
3010
+ if (drawingParams.length === 0) return;
3011
+ for (const drawingParam of drawingParams) {
3012
+ const { unitId } = drawingParam;
3013
+ if (!this._listenerOnImageMap.has(unitId)) {
3014
+ this._listenTransformerChange(unitId);
3015
+ this._listenerOnImageMap.add(unitId);
3016
+ }
2795
3017
  }
2796
- const headerPage = (_skeHeaders$get = skeHeaders.get(headerId)) === null || _skeHeaders$get === void 0 ? void 0 : _skeHeaders$get.get(pageWidth);
2797
- if (headerPage === null || headerPage === void 0 ? void 0 : headerPage.skeDrawings.has(drawingId)) {
2798
- drawing = headerPage === null || headerPage === void 0 ? void 0 : headerPage.skeDrawings.get(drawingId);
2799
- pageMarginLeft = marginLeft;
2800
- break;
3018
+ }));
3019
+ }
3020
+ _listenTransformerChange(unitId) {
3021
+ var _this$_getSceneAndTra;
3022
+ const transformer = (_this$_getSceneAndTra = this._getSceneAndTransformerByDrawingSearch(unitId)) === null || _this$_getSceneAndTra === void 0 ? void 0 : _this$_getSceneAndTra.transformer;
3023
+ if (transformer == null) return;
3024
+ this.disposeWithMe(toDisposable(transformer.changeStart$.subscribe((state) => {
3025
+ this._transformerCache.clear();
3026
+ const { objects } = state;
3027
+ for (const object of objects.values()) {
3028
+ var _documentDataModel$ge;
3029
+ const { oKey, width, height, left, top, angle } = object;
3030
+ const drawing = this._drawingManagerService.getDrawingOKey(oKey);
3031
+ if (drawing == null) continue;
3032
+ const documentDataModel = this._univerInstanceService.getUniverDocInstance(drawing.unitId);
3033
+ const drawingData = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSnapshot().drawings) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge[drawing.drawingId];
3034
+ if ((drawingData === null || drawingData === void 0 ? void 0 : drawingData.layoutType) === PositionedObjectLayoutType.INLINE) try {
3035
+ object.setOpacity(.2);
3036
+ } catch (e) {}
3037
+ if (drawingData != null) this._transformerCache.set(drawing.drawingId, {
3038
+ drawing: drawingData,
3039
+ top,
3040
+ left,
3041
+ width,
3042
+ height,
3043
+ angle
3044
+ });
2801
3045
  }
2802
- const footerPage = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
2803
- if (footerPage === null || footerPage === void 0 ? void 0 : footerPage.skeDrawings.has(drawingId)) {
2804
- drawing = footerPage === null || footerPage === void 0 ? void 0 : footerPage.skeDrawings.get(drawingId);
2805
- pageMarginLeft = marginLeft;
2806
- break;
3046
+ })));
3047
+ const throttleMultipleDrawingUpdate = throttle(this._updateMultipleDrawingDocTransform.bind(this), 50);
3048
+ throttle(this._nonInlineDrawingTransform.bind(this), 50);
3049
+ this.disposeWithMe(toDisposable(transformer.changing$.subscribe((state) => {
3050
+ const { objects, offsetX, offsetY } = state;
3051
+ if (objects.size > 1) throttleMultipleDrawingUpdate(objects);
3052
+ else if (objects.size === 1) {
3053
+ const drawingCache = this._transformerCache.values().next().value;
3054
+ const { width, height, top, left, angle } = objects.values().next().value;
3055
+ if (drawingCache && width === drawingCache.width && height === drawingCache.height && top === drawingCache.top && left === drawingCache.left && angle === drawingCache.angle) return;
3056
+ if (drawingCache && drawingCache.drawing.layoutType !== PositionedObjectLayoutType.INLINE) {}
3057
+ if (drawingCache && drawingCache.drawing.layoutType === PositionedObjectLayoutType.INLINE && offsetX != null && offsetY != null) this._updateInlineDrawingAnchor(drawingCache.drawing, offsetX, offsetY);
2807
3058
  }
2808
- }
2809
- if (drawing == null) return;
2810
- let delta = 0;
2811
- if (prevRelativeFrom === ObjectRelativeFromH.COLUMN) delta -= drawing.columnLeft;
2812
- else if (prevRelativeFrom === ObjectRelativeFromH.MARGIN) delta -= pageMarginLeft;
2813
- if (relativeFrom === ObjectRelativeFromH.COLUMN) delta += drawing.columnLeft;
2814
- else if (relativeFrom === ObjectRelativeFromH.MARGIN) delta += pageMarginLeft;
2815
- else if (relativeFrom === ObjectRelativeFromH.PAGE) {}
2816
- handlePositionChange("positionH", {
2817
- relativeFrom,
2818
- posOffset: (prevPosOffset !== null && prevPosOffset !== void 0 ? prevPosOffset : 0) - delta
2819
- });
3059
+ })));
3060
+ this.disposeWithMe(toDisposable(transformer.changeEnd$.subscribe((state) => {
3061
+ const { objects, offsetX, offsetY } = state;
3062
+ for (const object of objects.values()) {
3063
+ const drawing = this._drawingManagerService.getDrawingOKey(object.oKey);
3064
+ if (drawing == null) continue;
3065
+ const drawingCache = this._transformerCache.get(drawing === null || drawing === void 0 ? void 0 : drawing.drawingId);
3066
+ if ((drawingCache === null || drawingCache === void 0 ? void 0 : drawingCache.drawing.layoutType) === PositionedObjectLayoutType.INLINE) try {
3067
+ object.setOpacity(1);
3068
+ } catch (e) {}
3069
+ }
3070
+ if (this._anchorShape) this._anchorShape.hide();
3071
+ if (objects.size > 1) this._updateMultipleDrawingDocTransform(objects);
3072
+ else if (objects.size === 1) {
3073
+ const drawingCache = this._transformerCache.values().next().value;
3074
+ const object = objects.values().next().value;
3075
+ const { width, height, top, left, angle } = object;
3076
+ if (drawingCache && width === drawingCache.width && height === drawingCache.height && top === drawingCache.top && left === drawingCache.left && angle === drawingCache.angle) return;
3077
+ if (drawingCache && drawingCache.drawing.layoutType === PositionedObjectLayoutType.INLINE) {
3078
+ if (width !== drawingCache.width || height !== drawingCache.height || angle !== drawingCache.angle) this._updateDrawingSize(drawingCache, object);
3079
+ else if (offsetX != null && offsetY != null) this._moveInlineDrawing(drawingCache.drawing, offsetX, offsetY);
3080
+ } else if (drawingCache) this._nonInlineDrawingTransform(drawingCache.drawing, object);
3081
+ }
3082
+ this._transformerCache.clear();
3083
+ })));
2820
3084
  }
2821
- function handleVerticalRelativeFromChange(value) {
2822
- var _renderManagerService3, _renderManagerService4, _documentDataModel$ge, _glyph$parent, _column$parent;
2823
- const prevRelativeFrom = vPosition.relativeFrom;
2824
- const prevPosOffset = vPosition.posOffset;
2825
- const relativeFrom = Number(value);
2826
- if (prevRelativeFrom === relativeFrom) return;
2827
- const focusDrawings = drawingManagerService.getFocusDrawings();
2828
- if (focusDrawings.length === 0) return;
2829
- const { drawingId, unitId } = focusDrawings[0];
2830
- const documentDataModel = univerInstanceService.getUniverDocInstance(unitId);
2831
- const skeleton = (_renderManagerService3 = renderManagerService.getRenderById(unitId)) === null || _renderManagerService3 === void 0 ? void 0 : _renderManagerService3.with(DocSkeletonManagerService).getSkeleton();
2832
- const docSelectionRenderService = (_renderManagerService4 = renderManagerService.getRenderById(unitId)) === null || _renderManagerService4 === void 0 ? void 0 : _renderManagerService4.with(DocSelectionRenderService);
2833
- const segmentId = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.getSegment();
2834
- const segmentPage = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.getSegmentPage();
2835
- const drawing = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) === null || _documentDataModel$ge === void 0 || (_documentDataModel$ge = _documentDataModel$ge.customBlocks) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.find((c) => c.blockId === drawingId);
2836
- if (drawing == null || skeleton == null || docSelectionRenderService == null) return;
2837
- const { startIndex } = drawing;
2838
- const glyph = skeleton.findNodeByCharIndex(startIndex, segmentId, segmentPage);
2839
- const line = glyph === null || glyph === void 0 || (_glyph$parent = glyph.parent) === null || _glyph$parent === void 0 ? void 0 : _glyph$parent.parent;
2840
- const column = line === null || line === void 0 ? void 0 : line.parent;
2841
- const paragraphStartLine = column === null || column === void 0 ? void 0 : column.lines.find((l) => l.paragraphIndex === (line === null || line === void 0 ? void 0 : line.paragraphIndex) && l.paragraphStart);
2842
- const page = column === null || column === void 0 || (_column$parent = column.parent) === null || _column$parent === void 0 ? void 0 : _column$parent.parent;
2843
- if (glyph == null || line == null || paragraphStartLine == null || column == null || page == null) return;
2844
- let delta = 0;
2845
- if (prevRelativeFrom === ObjectRelativeFromV.PARAGRAPH) delta -= paragraphStartLine.top;
2846
- else if (prevRelativeFrom === ObjectRelativeFromV.LINE) delta -= line.top;
2847
- else if (prevRelativeFrom === ObjectRelativeFromV.PAGE) delta += page.marginTop;
2848
- if (relativeFrom === ObjectRelativeFromV.PARAGRAPH) delta += paragraphStartLine.top;
2849
- else if (relativeFrom === ObjectRelativeFromV.LINE) delta += line.top;
2850
- else if (relativeFrom === ObjectRelativeFromV.PAGE) delta -= page.marginTop;
2851
- handlePositionChange("positionV", {
2852
- relativeFrom,
2853
- posOffset: (prevPosOffset !== null && prevPosOffset !== void 0 ? prevPosOffset : 0) - delta
3085
+ _updateMultipleDrawingDocTransform(objects) {
3086
+ if (objects.size < 1) return;
3087
+ const drawings = [];
3088
+ let unitId;
3089
+ let subUnitId;
3090
+ for (const object of objects.values()) {
3091
+ const { oKey, left, top, angle } = object;
3092
+ let { width, height } = object;
3093
+ const drawing = this._drawingManagerService.getDrawingOKey(oKey);
3094
+ if (drawing == null) continue;
3095
+ if (unitId == null) unitId = drawing.unitId;
3096
+ if (subUnitId == null) subUnitId = drawing.subUnitId;
3097
+ const drawingCache = this._transformerCache.get(drawing.drawingId);
3098
+ if (drawingCache == null) continue;
3099
+ const { drawing: drawingData, top: oldTop, left: oldLeft, width: oldWidth, height: oldHeight, angle: oldAngle } = drawingCache;
3100
+ const { width: maxWidth, height: maxHeight } = this._getPageContentSize(drawingData);
3101
+ width = Math.min(width, maxWidth);
3102
+ height = Math.min(height, maxHeight);
3103
+ if (oldWidth !== width || oldHeight !== height) drawings.push({
3104
+ drawingId: drawing.drawingId,
3105
+ key: "size",
3106
+ value: {
3107
+ width,
3108
+ height
3109
+ }
3110
+ });
3111
+ if (oldAngle !== angle) drawings.push({
3112
+ drawingId: drawing.drawingId,
3113
+ key: "angle",
3114
+ value: angle
3115
+ });
3116
+ if (oldTop !== top || oldLeft !== left) {
3117
+ const verticalDelta = top - oldTop;
3118
+ const horizontalDelta = left - oldLeft;
3119
+ if (verticalDelta !== 0) drawings.push({
3120
+ drawingId: drawing.drawingId,
3121
+ key: "positionV",
3122
+ value: {
3123
+ relativeFrom: drawingData.docTransform.positionV.relativeFrom,
3124
+ posOffset: drawingData.docTransform.positionV.posOffset + verticalDelta
3125
+ }
3126
+ });
3127
+ if (horizontalDelta !== 0) drawings.push({
3128
+ drawingId: drawing.drawingId,
3129
+ key: "positionH",
3130
+ value: {
3131
+ relativeFrom: drawingData.docTransform.positionH.relativeFrom,
3132
+ posOffset: drawingData.docTransform.positionH.posOffset + horizontalDelta
3133
+ }
3134
+ });
3135
+ }
3136
+ }
3137
+ if (drawings.length > 0 && unitId && subUnitId) this._commandService.executeCommand(UpdateDrawingDocTransformCommand.id, {
3138
+ unitId,
3139
+ subUnitId,
3140
+ drawings
2854
3141
  });
2855
3142
  }
2856
- function updateState(drawingParam) {
2857
- var _snapshot$drawings;
2858
- const snapshot = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getSnapshot();
2859
- const drawing = snapshot === null || snapshot === void 0 || (_snapshot$drawings = snapshot.drawings) === null || _snapshot$drawings === void 0 ? void 0 : _snapshot$drawings[drawingParam.drawingId];
2860
- if (drawing == null) return;
2861
- const { layoutType } = drawing;
2862
- const { positionH, positionV } = drawing.docTransform;
2863
- setHPosition(positionH);
2864
- setVPosition(positionV);
2865
- setDisabled(layoutType === PositionedObjectLayoutType.INLINE);
2866
- setFollowTextMove(positionV.relativeFrom === ObjectRelativeFromV.PARAGRAPH || positionV.relativeFrom === ObjectRelativeFromV.LINE);
2867
- }
2868
- function updateFocusDrawingState() {
2869
- const focusDrawings = drawingManagerService.getFocusDrawings();
2870
- if (focusDrawings.length === 0) return;
2871
- updateState(focusDrawings[0]);
3143
+ _updateDrawingAnchor(objects) {
3144
+ if (this._transformerCache.size !== 1) return;
3145
+ const drawingCache = this._transformerCache.values().next().value;
3146
+ const object = objects.values().next().value;
3147
+ this._getDrawingAnchor(drawingCache.drawing, object);
2872
3148
  }
2873
- function handleFollowTextMoveCheck(val) {
2874
- setFollowTextMove(val);
2875
- handleVerticalRelativeFromChange(val ? String(ObjectRelativeFromV.PARAGRAPH) : String(ObjectRelativeFromV.PAGE));
3149
+ _updateInlineDrawingAnchor(drawing, offsetX, offsetY) {
3150
+ var _this$_getInlineDrawi;
3151
+ if (this._transformerCache.size !== 1) return;
3152
+ const { contentBoxPointGroup } = (_this$_getInlineDrawi = this._getInlineDrawingAnchor(drawing, offsetX, offsetY)) !== null && _this$_getInlineDrawi !== void 0 ? _this$_getInlineDrawi : {};
3153
+ if (contentBoxPointGroup == null) return;
3154
+ this._createOrUpdateInlineAnchor(drawing.unitId, contentBoxPointGroup);
2876
3155
  }
2877
- useEffect(() => {
2878
- updateFocusDrawingState();
2879
- const subscription = drawingManagerService.focus$.subscribe((drawingParams) => {
2880
- if (drawingParams.length === 0) {
2881
- setShowPanel(false);
2882
- return;
2883
- }
2884
- setShowPanel(true);
2885
- updateState(drawingParams[0]);
2886
- });
2887
- const mutationListener = commandService.onCommandExecuted(async (command) => {
2888
- if (command.id === RichTextEditingMutation.id) updateFocusDrawingState();
3156
+ _getInlineDrawingAnchor(drawing, offsetX, offsetY) {
3157
+ var _this$_renderManagerS, _getOneTextSelectionR;
3158
+ const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
3159
+ const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(DocSkeletonManagerService).getSkeleton();
3160
+ if (currentRender == null) return;
3161
+ const { mainComponent, scene } = currentRender;
3162
+ const documentComponent = mainComponent;
3163
+ const activeViewport = scene.getViewports()[0];
3164
+ const { pageLayoutType = PageLayoutType.VERTICAL, pageMarginLeft, pageMarginTop } = documentComponent.getOffsetConfig();
3165
+ let glyphAnchor = null;
3166
+ let isBack = false;
3167
+ let segmentPageIndex = -1;
3168
+ let segmentId = "";
3169
+ const HALF = .5;
3170
+ const coord = this._getTransformCoordForDocumentOffset(documentComponent, activeViewport, offsetX, offsetY);
3171
+ if (coord == null) return;
3172
+ const docSelectionRenderService = (_this$_renderManagerS = this._renderManagerService.getRenderById(drawing.unitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.with(DocSelectionRenderService);
3173
+ if (docSelectionRenderService == null) return;
3174
+ const nodeInfo = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findNodeByCoord(coord, pageLayoutType, pageMarginLeft, pageMarginTop, {
3175
+ strict: false,
3176
+ segmentId: docSelectionRenderService.getSegment(),
3177
+ segmentPage: docSelectionRenderService.getSegmentPage()
2889
3178
  });
2890
- return () => {
2891
- subscription.unsubscribe();
2892
- mutationListener.dispose();
3179
+ if (nodeInfo) {
3180
+ const { node, ratioX, segmentPage, segmentId: nodeSegmentId } = nodeInfo;
3181
+ isBack = ratioX < HALF;
3182
+ glyphAnchor = node;
3183
+ segmentPageIndex = segmentPage;
3184
+ segmentId = nodeSegmentId;
3185
+ }
3186
+ if (glyphAnchor == null) return;
3187
+ const nodePosition = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findPositionByGlyph(glyphAnchor, segmentPageIndex);
3188
+ const docObject = this._getDocObject();
3189
+ if (nodePosition == null || skeleton == null || docObject == null) return;
3190
+ const positionWithIsBack = {
3191
+ ...nodePosition,
3192
+ isBack
2893
3193
  };
2894
- }, []);
2895
- return /* @__PURE__ */ jsxs("div", {
2896
- className: clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": !showPanel }),
2897
- children: [
2898
- /* @__PURE__ */ jsx("header", {
2899
- className: "univer-text-gray-600 dark:!univer-text-gray-200",
2900
- children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-position.title") })
2901
- }),
2902
- /* @__PURE__ */ jsx("div", {
2903
- className: "univer-text-gray-600 dark:!univer-text-gray-200",
2904
- children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-position.horizontal") })
2905
- }),
2906
- /* @__PURE__ */ jsxs("div", {
2907
- className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
2908
- children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-position.absolutePosition") }), /* @__PURE__ */ jsx(InputNumber, {
2909
- min: MIN_OFFSET,
2910
- max: MAX_OFFSET,
2911
- precision: 1,
2912
- disabled,
2913
- value: hPosition.posOffset,
2914
- onChange: (val) => {
2915
- handlePositionChange("positionH", {
2916
- relativeFrom: hPosition.relativeFrom,
2917
- posOffset: val
2918
- });
2919
- }
2920
- })] }), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-position.toTheRightOf") }), /* @__PURE__ */ jsx(Select, {
2921
- value: String(hPosition.relativeFrom),
2922
- disabled,
2923
- options: HORIZONTAL_RELATIVE_FROM,
2924
- onChange: handleHorizontalRelativeFromChange
2925
- })] })]
2926
- }),
2927
- /* @__PURE__ */ jsx("div", {
2928
- className: "univer-text-gray-600 dark:!univer-text-gray-200",
2929
- children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-position.vertical") })
2930
- }),
2931
- /* @__PURE__ */ jsxs("div", {
2932
- className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
2933
- children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-position.absolutePosition") }), /* @__PURE__ */ jsx(InputNumber, {
2934
- min: MIN_OFFSET,
2935
- max: MAX_OFFSET,
2936
- precision: 1,
2937
- disabled,
2938
- value: vPosition.posOffset,
2939
- onChange: (val) => {
2940
- handlePositionChange("positionV", {
2941
- relativeFrom: vPosition.relativeFrom,
2942
- posOffset: val
2943
- });
2944
- }
2945
- })] }), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-position.bellow") }), /* @__PURE__ */ jsx(Select, {
2946
- disabled,
2947
- value: String(vPosition.relativeFrom),
2948
- options: VERTICAL_RELATIVE_FROM,
2949
- onChange: handleVerticalRelativeFromChange
2950
- })] })]
2951
- }),
2952
- /* @__PURE__ */ jsx("div", {
2953
- className: "univer-text-gray-600 dark:!univer-text-gray-200",
2954
- children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-position.options") })
2955
- }),
2956
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Checkbox, {
2957
- disabled,
2958
- checked: followTextMove,
2959
- onChange: handleFollowTextMoveCheck,
2960
- children: localeService.t("docs-drawing-ui.image-position.moveObjectWithText")
2961
- }) })
2962
- ]
2963
- });
2964
- };
2965
-
2966
- //#endregion
2967
- //#region src/views/doc-image-panel/DocDrawingTextWrap.tsx
2968
- const MIN_MARGIN = 0;
2969
- const MAX_MARGIN = 100;
2970
- const DocDrawingTextWrap = (props) => {
2971
- const commandService = useDependency(ICommandService);
2972
- const localeService = useDependency(LocaleService);
2973
- const drawingManagerService = useDependency(IDrawingManagerService);
2974
- const renderManagerService = useDependency(IRenderManagerService);
2975
- const univerInstanceService = useDependency(IUniverInstanceService);
2976
- const { drawings } = props;
2977
- const drawingParam = drawings[0];
2978
- if (drawingParam == null) return null;
2979
- const { unitId } = drawingParam;
2980
- const documentDataModel = univerInstanceService.getUniverDocInstance(unitId);
2981
- const renderObject = renderManagerService.getRenderById(unitId);
2982
- if ((renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene) == null) return null;
2983
- const [disableWrapText, setDisableWrapText] = useState(true);
2984
- const [disableDistTB, setDisableDistTB] = useState(true);
2985
- const [disableDistLR, setDisableDistLR] = useState(true);
2986
- const [wrappingStyle, setWrappingStyle] = useState("inline");
2987
- const [wrapText, setWrapText] = useState("");
2988
- const [distToText, setDistToText] = useState({
2989
- distT: 0,
2990
- distL: 0,
2991
- distB: 0,
2992
- distR: 0
2993
- });
2994
- const [showPanel, setShowPanel] = useState(true);
2995
- function handleWrappingStyleChange(value) {
2996
- setWrappingStyle(value);
2997
- const focusDrawings = drawingManagerService.getFocusDrawings();
2998
- if (focusDrawings.length === 0) return;
2999
- const { unitId, subUnitId } = focusDrawings[0];
3000
- const drawings = focusDrawings.map(({ unitId, subUnitId, drawingId }) => ({
3001
- unitId,
3002
- subUnitId,
3003
- drawingId
3004
- }));
3005
- commandService.executeCommand(UpdateDocDrawingWrappingStyleCommand.id, {
3194
+ const { cursorList, contentBoxPointGroup } = new NodePositionConvertToCursor(docObject.document.getOffsetConfig(), skeleton).getRangePointData(positionWithIsBack, positionWithIsBack);
3195
+ const { startOffset } = (_getOneTextSelectionR = getOneTextSelectionRange(cursorList)) !== null && _getOneTextSelectionR !== void 0 ? _getOneTextSelectionR : {};
3196
+ if (startOffset == null) return;
3197
+ return {
3198
+ offset: startOffset,
3199
+ contentBoxPointGroup,
3200
+ segmentId,
3201
+ segmentPage: segmentPageIndex
3202
+ };
3203
+ }
3204
+ _getDrawingAnchor(drawing, object) {
3205
+ var _this$_renderManagerS2, _glyphAnchor$parent, _column$lines$find, _column$parent, _tableCellContext$hos, _getOneTextSelectionR2;
3206
+ const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
3207
+ const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(DocSkeletonManagerService).getSkeleton();
3208
+ const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
3209
+ if (skeletonData == null || currentRender == null) return;
3210
+ const { pages, skeHeaders, skeFooters } = skeletonData;
3211
+ const { mainComponent, scene } = currentRender;
3212
+ const documentComponent = mainComponent;
3213
+ const activeViewport = scene.getViewports()[0];
3214
+ const { pageLayoutType = PageLayoutType.VERTICAL, pageMarginLeft, pageMarginTop, docsLeft, docsTop } = documentComponent.getOffsetConfig();
3215
+ const { left, top, angle } = object;
3216
+ let { width, height } = object;
3217
+ const { positionV, positionH } = drawing.docTransform;
3218
+ const { width: maxWidth, height: maxHeight } = this._getPageContentSize(drawing);
3219
+ width = Math.min(width, maxWidth);
3220
+ height = Math.min(height, maxHeight);
3221
+ let glyphAnchor = null;
3222
+ let segmentId = "";
3223
+ let segmentPage = -1;
3224
+ const isBack = false;
3225
+ const docTransform = {
3226
+ ...drawing.docTransform,
3227
+ size: {
3228
+ width,
3229
+ height
3230
+ },
3231
+ angle
3232
+ };
3233
+ const { x, y } = scene.getViewportScrollXY(activeViewport);
3234
+ const coord = this._getTransformCoordForDocumentOffset(documentComponent, activeViewport, left - x, top - y);
3235
+ if (coord == null) return;
3236
+ const docSelectionRenderService = (_this$_renderManagerS2 = this._renderManagerService.getRenderById(drawing.unitId)) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.with(DocSelectionRenderService);
3237
+ if (docSelectionRenderService == null) return;
3238
+ const nodeInfo = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findNodeByCoord(coord, pageLayoutType, pageMarginLeft, pageMarginTop, {
3239
+ strict: false,
3240
+ segmentId: docSelectionRenderService.getSegment(),
3241
+ segmentPage: docSelectionRenderService.getSegmentPage()
3242
+ });
3243
+ if (nodeInfo) {
3244
+ const { node, segmentPage: segmentPageIndex, segmentId: nodeSegmentId } = nodeInfo;
3245
+ glyphAnchor = node;
3246
+ segmentPage = segmentPageIndex;
3247
+ segmentId = nodeSegmentId;
3248
+ }
3249
+ if (glyphAnchor == null) return;
3250
+ const line = (_glyphAnchor$parent = glyphAnchor.parent) === null || _glyphAnchor$parent === void 0 ? void 0 : _glyphAnchor$parent.parent;
3251
+ const column = line === null || line === void 0 ? void 0 : line.parent;
3252
+ const paragraphStartLine = (_column$lines$find = column === null || column === void 0 ? void 0 : column.lines.find((l) => l.paragraphIndex === (line === null || line === void 0 ? void 0 : line.paragraphIndex) && l.paragraphStart)) !== null && _column$lines$find !== void 0 ? _column$lines$find : column === null || column === void 0 ? void 0 : column.lines[0];
3253
+ const page = column === null || column === void 0 || (_column$parent = column.parent) === null || _column$parent === void 0 ? void 0 : _column$parent.parent;
3254
+ if (line == null || column == null || paragraphStartLine == null || page == null) return;
3255
+ this._liquid.reset();
3256
+ const tableCellContext = page.type === DocumentSkeletonPageType.CELL ? getDocsTableCellAnchorContext(drawing.unitId, page) : null;
3257
+ const anchorPage = (_tableCellContext$hos = tableCellContext === null || tableCellContext === void 0 ? void 0 : tableCellContext.hostPage) !== null && _tableCellContext$hos !== void 0 ? _tableCellContext$hos : page;
3258
+ const pageType = anchorPage.type;
3259
+ for (const p of pages) {
3260
+ const { headerId, footerId, pageHeight, pageWidth, marginLeft, marginBottom } = p;
3261
+ const pIndex = pages.indexOf(p);
3262
+ if (segmentPage > -1 && pIndex === segmentPage) {
3263
+ switch (pageType) {
3264
+ case DocumentSkeletonPageType.HEADER: {
3265
+ var _skeHeaders$get;
3266
+ const headerSke = (_skeHeaders$get = skeHeaders.get(headerId)) === null || _skeHeaders$get === void 0 ? void 0 : _skeHeaders$get.get(pageWidth);
3267
+ if (headerSke) this._liquid.translatePagePadding({
3268
+ marginTop: headerSke.marginTop,
3269
+ marginLeft
3270
+ });
3271
+ else throw new Error("header skeleton not found");
3272
+ break;
3273
+ }
3274
+ case DocumentSkeletonPageType.FOOTER: {
3275
+ var _skeFooters$get;
3276
+ const footerSke = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
3277
+ if (footerSke) this._liquid.translatePagePadding({
3278
+ marginTop: pageHeight - marginBottom + footerSke.marginTop,
3279
+ marginLeft
3280
+ });
3281
+ else throw new Error("footer skeleton not found");
3282
+ break;
3283
+ }
3284
+ default:
3285
+ this._liquid.translatePagePadding(p);
3286
+ break;
3287
+ }
3288
+ break;
3289
+ }
3290
+ this._liquid.translatePagePadding(p);
3291
+ if (p === anchorPage) break;
3292
+ this._liquid.restorePagePadding(p);
3293
+ this._liquid.translatePage(p, pageLayoutType, pageMarginLeft, pageMarginTop);
3294
+ }
3295
+ if (tableCellContext) this._liquid.translate(tableCellContext.offset.left, tableCellContext.offset.top);
3296
+ if (positionV.relativeFrom === ObjectRelativeFromV.LINE) glyphAnchor = line.divides[0].glyphGroup[0];
3297
+ else {
3298
+ var _paragraphStartLine$d, _paragraphStartLine$d2;
3299
+ glyphAnchor = (_paragraphStartLine$d = (_paragraphStartLine$d2 = paragraphStartLine.divides) === null || _paragraphStartLine$d2 === void 0 || (_paragraphStartLine$d2 = _paragraphStartLine$d2[0]) === null || _paragraphStartLine$d2 === void 0 || (_paragraphStartLine$d2 = _paragraphStartLine$d2.glyphGroup) === null || _paragraphStartLine$d2 === void 0 ? void 0 : _paragraphStartLine$d2[0]) !== null && _paragraphStartLine$d !== void 0 ? _paragraphStartLine$d : glyphAnchor;
3300
+ }
3301
+ docTransform.positionH = {
3302
+ relativeFrom: positionH.relativeFrom,
3303
+ posOffset: left - this._liquid.x - docsLeft
3304
+ };
3305
+ switch (positionH.relativeFrom) {
3306
+ case ObjectRelativeFromH.MARGIN:
3307
+ docTransform.positionH.posOffset = left - this._liquid.x - docsLeft - page.marginLeft;
3308
+ break;
3309
+ case ObjectRelativeFromH.COLUMN:
3310
+ docTransform.positionH.posOffset = left - this._liquid.x - docsLeft - column.left;
3311
+ break;
3312
+ }
3313
+ docTransform.positionV = {
3314
+ relativeFrom: positionV.relativeFrom,
3315
+ posOffset: top - this._liquid.y - docsTop
3316
+ };
3317
+ switch (positionV.relativeFrom) {
3318
+ case ObjectRelativeFromV.PAGE:
3319
+ docTransform.positionV.posOffset = top - this._liquid.y - docsTop - page.marginTop;
3320
+ break;
3321
+ case ObjectRelativeFromV.LINE:
3322
+ docTransform.positionV.posOffset = top - this._liquid.y - docsTop - line.top;
3323
+ break;
3324
+ case ObjectRelativeFromV.PARAGRAPH:
3325
+ docTransform.positionV.posOffset = top - this._liquid.y - docsTop - paragraphStartLine.top;
3326
+ break;
3327
+ }
3328
+ if (glyphAnchor == null) return;
3329
+ const nodePosition = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findPositionByGlyph(glyphAnchor, segmentPage);
3330
+ const docObject = this._getDocObject();
3331
+ if (nodePosition == null || skeleton == null || docObject == null) return;
3332
+ const positionWithIsBack = {
3333
+ ...nodePosition,
3334
+ isBack
3335
+ };
3336
+ const { cursorList } = new NodePositionConvertToCursor(docObject.document.getOffsetConfig(), skeleton).getRangePointData(positionWithIsBack, positionWithIsBack);
3337
+ const { startOffset } = (_getOneTextSelectionR2 = getOneTextSelectionRange(cursorList)) !== null && _getOneTextSelectionR2 !== void 0 ? _getOneTextSelectionR2 : {};
3338
+ if (startOffset == null) return;
3339
+ return {
3340
+ offset: startOffset,
3341
+ docTransform,
3342
+ segmentId,
3343
+ segmentPage
3344
+ };
3345
+ }
3346
+ _updateDrawingSize(drawingCache, object) {
3347
+ const drawings = [];
3348
+ const { drawing, width: oldWidth, height: oldHeight, angle: oldAngle } = drawingCache;
3349
+ const { unitId, subUnitId } = drawing;
3350
+ let { width, height, angle } = object;
3351
+ const { width: maxWidth, height: maxHeight } = this._getPageContentSize(drawing);
3352
+ width = Math.min(maxWidth, width);
3353
+ height = Math.min(maxHeight, height);
3354
+ if (width !== oldWidth || height !== oldHeight) drawings.push({
3355
+ drawingId: drawing.drawingId,
3356
+ key: "size",
3357
+ value: {
3358
+ width,
3359
+ height
3360
+ }
3361
+ });
3362
+ if (angle !== oldAngle) drawings.push({
3363
+ drawingId: drawing.drawingId,
3364
+ key: "angle",
3365
+ value: angle
3366
+ });
3367
+ if (drawings.length > 0 && unitId && subUnitId) this._commandService.executeCommand(UpdateDrawingDocTransformCommand.id, {
3006
3368
  unitId,
3007
3369
  subUnitId,
3008
- drawings,
3009
- wrappingStyle: value
3370
+ drawings
3010
3371
  });
3011
3372
  }
3012
- function handleWrapTextChange(value) {
3013
- setWrapText(value);
3014
- const focusDrawings = drawingManagerService.getFocusDrawings();
3015
- if (focusDrawings.length === 0) return;
3016
- const drawings = focusDrawings.map((drawing) => {
3017
- return {
3018
- unitId: drawing.unitId,
3019
- subUnitId: drawing.subUnitId,
3020
- drawingId: drawing.drawingId
3021
- };
3022
- });
3023
- commandService.executeCommand(UpdateDocDrawingWrapTextCommand.id, {
3024
- unitId: focusDrawings[0].unitId,
3025
- subUnitId: focusDrawings[0].unitId,
3026
- drawings,
3027
- wrapText: value
3373
+ _moveInlineDrawing(drawing, offsetX, offsetY) {
3374
+ const anchor = this._getInlineDrawingAnchor(drawing, offsetX, offsetY);
3375
+ const { offset, segmentId, segmentPage } = anchor !== null && anchor !== void 0 ? anchor : {};
3376
+ return this._commandService.executeCommand(IMoveInlineDrawingCommand.id, {
3377
+ unitId: drawing.unitId,
3378
+ subUnitId: drawing.unitId,
3379
+ drawing,
3380
+ offset,
3381
+ segmentId,
3382
+ segmentPage,
3383
+ needRefreshDrawings: offset == null
3028
3384
  });
3029
3385
  }
3030
- function handleDistToTextChange(value, direction) {
3031
- if (value == null) return;
3032
- setDistToText({
3033
- ...distToText,
3034
- [direction]: value
3035
- });
3036
- const focusDrawings = drawingManagerService.getFocusDrawings();
3037
- if (focusDrawings.length === 0) return;
3038
- const drawings = focusDrawings.map((drawing) => {
3039
- return {
3040
- unitId: drawing.unitId,
3041
- subUnitId: drawing.subUnitId,
3042
- drawingId: drawing.drawingId
3043
- };
3044
- });
3045
- commandService.executeCommand(UpdateDocDrawingDistanceCommand.id, {
3046
- unitId: focusDrawings[0].unitId,
3047
- subUnitId: focusDrawings[0].unitId,
3048
- drawings,
3049
- dist: { [direction]: value }
3386
+ _limitDrawingInPage(drawing, object) {
3387
+ const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
3388
+ const { left, top, width, height, angle } = object;
3389
+ const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(DocSkeletonManagerService).getSkeleton();
3390
+ const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
3391
+ const { pages } = skeletonData !== null && skeletonData !== void 0 ? skeletonData : {};
3392
+ if (skeletonData == null || currentRender == null || pages == null) return {
3393
+ left,
3394
+ top,
3395
+ width,
3396
+ height,
3397
+ angle
3398
+ };
3399
+ const { mainComponent } = currentRender;
3400
+ const { top: docsTop, pageLayoutType, pageMarginLeft, pageMarginTop } = mainComponent;
3401
+ let newTop = top;
3402
+ this._liquid.reset();
3403
+ for (const page of pages) {
3404
+ const { marginBottom, pageHeight } = page;
3405
+ const nextPage = pages[pages.indexOf(page) + 1];
3406
+ if (nextPage == null) continue;
3407
+ if (Tools.hasIntersectionBetweenTwoRanges(top, top + height, this._liquid.y + docsTop + pageHeight - marginBottom, this._liquid.y + docsTop + pageHeight + pageMarginTop + nextPage.marginTop)) if (top + height / 2 < this._liquid.y + docsTop + pageHeight + pageMarginTop / 2) newTop = Math.min(top, this._liquid.y + docsTop + pageHeight - marginBottom - height);
3408
+ else newTop = Math.max(top, this._liquid.y + docsTop + pageHeight + pageMarginTop + nextPage.marginTop);
3409
+ this._liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
3410
+ }
3411
+ return {
3412
+ left,
3413
+ top: newTop,
3414
+ width,
3415
+ height,
3416
+ angle
3417
+ };
3418
+ }
3419
+ _nonInlineDrawingTransform(drawing, object, isMoving = false) {
3420
+ const objectPosition = drawing.isMultiTransform === BooleanNumber.TRUE ? object : this._limitDrawingInPage(drawing, object);
3421
+ if (isMoving && objectPosition.top !== object.top) return;
3422
+ const anchor = this._getDrawingAnchor(drawing, objectPosition);
3423
+ const { offset, docTransform, segmentId, segmentPage } = anchor !== null && anchor !== void 0 ? anchor : {};
3424
+ if (offset == null || docTransform == null) return this._updateMultipleDrawingDocTransform(/* @__PURE__ */ new Map([[drawing.drawingId, object]]));
3425
+ return this._commandService.executeCommand(ITransformNonInlineDrawingCommand.id, {
3426
+ unitId: drawing.unitId,
3427
+ subUnitId: drawing.unitId,
3428
+ drawing,
3429
+ offset,
3430
+ docTransform,
3431
+ segmentId,
3432
+ segmentPage
3050
3433
  });
3051
3434
  }
3052
- function updateFocusDrawingState() {
3053
- const focusDrawings = drawingManagerService.getFocusDrawings();
3054
- if (focusDrawings.length === 0) return;
3055
- updateState(focusDrawings[0]);
3435
+ _getSceneAndTransformerByDrawingSearch(unitId) {
3436
+ if (unitId == null) return;
3437
+ const renderObject = this._renderManagerService.getRenderById(unitId);
3438
+ const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
3439
+ if (scene == null) return;
3440
+ return {
3441
+ scene,
3442
+ transformer: scene.getTransformerByCreate()
3443
+ };
3056
3444
  }
3057
- function updateState(drawingParam) {
3058
- var _documentDataModel$ge;
3059
- const drawing = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSnapshot()) === null || _documentDataModel$ge === void 0 || (_documentDataModel$ge = _documentDataModel$ge.drawings) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge[drawingParam.drawingId];
3060
- if (drawing == null) return;
3061
- const { distT = 0, distL = 0, distB = 0, distR = 0, layoutType = PositionedObjectLayoutType.INLINE, behindDoc = BooleanNumber.FALSE, wrapText = WrapTextType.BOTH_SIDES } = drawing;
3062
- setDistToText({
3063
- distT,
3064
- distL,
3065
- distB,
3066
- distR
3067
- });
3068
- setWrapText(wrapText);
3069
- setDisableWrapText(layoutType !== PositionedObjectLayoutType.WRAP_SQUARE);
3070
- if (layoutType === PositionedObjectLayoutType.WRAP_NONE || layoutType === PositionedObjectLayoutType.INLINE) setDisableDistTB(true);
3071
- else setDisableDistTB(false);
3072
- if (layoutType === PositionedObjectLayoutType.WRAP_NONE || layoutType === PositionedObjectLayoutType.INLINE || layoutType === PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM) setDisableDistLR(true);
3073
- else setDisableDistLR(false);
3074
- if (layoutType === PositionedObjectLayoutType.WRAP_NONE) if (behindDoc === BooleanNumber.TRUE) setWrappingStyle("behindText");
3075
- else setWrappingStyle("inFrontOfText");
3076
- else switch (layoutType) {
3077
- case PositionedObjectLayoutType.INLINE:
3078
- setWrappingStyle("inline");
3079
- break;
3080
- case PositionedObjectLayoutType.WRAP_SQUARE:
3081
- setWrappingStyle("wrapSquare");
3082
- break;
3083
- case PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM:
3084
- setWrappingStyle("wrapTopAndBottom");
3085
- break;
3086
- default: throw new Error(`Unsupported layout type: ${layoutType}`);
3445
+ _getTransformCoordForDocumentOffset(document, viewport, evtOffsetX, evtOffsetY) {
3446
+ const { documentTransform } = document.getOffsetConfig();
3447
+ const originCoord = viewport.transformVector2SceneCoord(Vector2.FromArray([evtOffsetX, evtOffsetY]));
3448
+ if (!originCoord) return;
3449
+ return documentTransform.clone().invert().applyPoint(originCoord);
3450
+ }
3451
+ _createOrUpdateInlineAnchor(unitId, pointsGroup) {
3452
+ const currentRender = this._renderManagerService.getRenderById(unitId);
3453
+ if (currentRender == null) return;
3454
+ const { mainComponent, scene } = currentRender;
3455
+ const { docsLeft, docsTop } = mainComponent.getOffsetConfig();
3456
+ const { left: boundingLeft, top: boundingTop, height } = getAnchorBounding(pointsGroup);
3457
+ const left = boundingLeft + docsLeft;
3458
+ const top = boundingTop + docsTop;
3459
+ if (this._anchorShape) {
3460
+ this._anchorShape.transformByState({
3461
+ left,
3462
+ top,
3463
+ height
3464
+ });
3465
+ this._anchorShape.show();
3466
+ return;
3087
3467
  }
3468
+ const anchor = new Rect(INLINE_DRAWING_ANCHOR_KEY_PREFIX + generateRandomId(6), {
3469
+ left,
3470
+ top,
3471
+ height,
3472
+ strokeWidth: 2,
3473
+ stroke: getColor(COLORS.darkgray, 1),
3474
+ evented: false
3475
+ });
3476
+ this._anchorShape = anchor;
3477
+ scene.addObject(anchor, TEXT_RANGE_LAYER_INDEX);
3088
3478
  }
3089
- useEffect(() => {
3090
- updateFocusDrawingState();
3091
- const subscription = drawingManagerService.focus$.subscribe((drawingParams) => {
3092
- if (drawingParams.length === 0) {
3093
- setShowPanel(false);
3094
- return;
3479
+ _getDocObject() {
3480
+ return getDocObject(this._univerInstanceService, this._renderManagerService);
3481
+ }
3482
+ _getPageContentSize(drawing) {
3483
+ const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
3484
+ const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(DocSkeletonManagerService).getSkeleton();
3485
+ const MAX_WIDTH = 500;
3486
+ const MAX_HEIGHT = 500;
3487
+ const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
3488
+ if (skeletonData == null || currentRender == null) return {
3489
+ width: MAX_WIDTH,
3490
+ height: MAX_HEIGHT
3491
+ };
3492
+ const { pages } = skeletonData;
3493
+ let page = null;
3494
+ for (const p of pages) {
3495
+ const { skeDrawings } = p;
3496
+ if (skeDrawings.has(drawing.drawingId)) {
3497
+ page = p;
3498
+ break;
3095
3499
  }
3096
- setShowPanel(true);
3097
- updateState(drawingParams[0]);
3098
- });
3099
- const mutationListener = commandService.onCommandExecuted(async (command) => {
3100
- if (command.id === RichTextEditingMutation.id) updateFocusDrawingState();
3101
- });
3102
- return () => {
3103
- subscription.unsubscribe();
3104
- mutationListener.dispose();
3500
+ }
3501
+ if (page) {
3502
+ const { pageWidth, pageHeight, marginLeft, marginBottom, marginRight, marginTop } = page;
3503
+ return {
3504
+ width: Math.max(MAX_WIDTH, pageWidth - marginLeft - marginRight),
3505
+ height: Math.max(MAX_HEIGHT, pageHeight - marginTop - marginBottom)
3506
+ };
3507
+ } else return {
3508
+ width: MAX_WIDTH,
3509
+ height: MAX_HEIGHT
3105
3510
  };
3106
- }, []);
3107
- return /* @__PURE__ */ jsxs("div", {
3108
- className: clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": !showPanel }),
3109
- children: [
3110
- /* @__PURE__ */ jsx("header", {
3111
- className: "univer-text-gray-600 dark:!univer-text-gray-200",
3112
- children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-text-wrap.title") })
3113
- }),
3114
- /* @__PURE__ */ jsx("div", {
3115
- className: "univer-text-gray-600 dark:!univer-text-gray-200",
3116
- children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-text-wrap.wrappingStyle") })
3117
- }),
3118
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(RadioGroup, {
3119
- value: wrappingStyle,
3120
- onChange: handleWrappingStyleChange,
3121
- direction: "vertical",
3122
- children: [
3123
- /* @__PURE__ */ jsx(Radio, {
3124
- value: "inline",
3125
- children: localeService.t("docs-drawing-ui.image-text-wrap.inline")
3126
- }),
3127
- /* @__PURE__ */ jsx(Radio, {
3128
- value: "wrapSquare",
3129
- children: localeService.t("docs-drawing-ui.image-text-wrap.square")
3130
- }),
3131
- /* @__PURE__ */ jsx(Radio, {
3132
- value: "wrapTopAndBottom",
3133
- children: localeService.t("docs-drawing-ui.image-text-wrap.topAndBottom")
3134
- }),
3135
- /* @__PURE__ */ jsx(Radio, {
3136
- value: "behindText",
3137
- children: localeService.t("docs-drawing-ui.image-text-wrap.behindText")
3138
- }),
3139
- /* @__PURE__ */ jsx(Radio, {
3140
- value: "inFrontOfText",
3141
- children: localeService.t("docs-drawing-ui.image-text-wrap.inFrontText")
3142
- })
3143
- ]
3144
- }) }),
3145
- /* @__PURE__ */ jsx("div", {
3146
- className: "univer-text-gray-600 dark:!univer-text-gray-200",
3147
- children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-text-wrap.wrapText") })
3148
- }),
3149
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(RadioGroup, {
3150
- disabled: disableWrapText,
3151
- value: wrapText,
3152
- onChange: handleWrapTextChange,
3153
- direction: "horizontal",
3154
- children: [
3155
- /* @__PURE__ */ jsx(Radio, {
3156
- value: WrapTextType.BOTH_SIDES,
3157
- children: localeService.t("docs-drawing-ui.image-text-wrap.bothSide")
3158
- }),
3159
- /* @__PURE__ */ jsx(Radio, {
3160
- value: WrapTextType.LEFT,
3161
- children: localeService.t("docs-drawing-ui.image-text-wrap.leftOnly")
3162
- }),
3163
- /* @__PURE__ */ jsx(Radio, {
3164
- value: WrapTextType.RIGHT,
3165
- children: localeService.t("docs-drawing-ui.image-text-wrap.rightOnly")
3166
- })
3167
- ]
3168
- }) }),
3169
- /* @__PURE__ */ jsx("div", {
3170
- className: "univer-text-gray-600 dark:!univer-text-gray-200",
3171
- children: /* @__PURE__ */ jsx("div", { children: localeService.t("docs-drawing-ui.image-text-wrap.distanceFromText") })
3172
- }),
3173
- /* @__PURE__ */ jsxs("div", {
3174
- className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
3175
- children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-text-wrap.top") }), /* @__PURE__ */ jsx(InputNumber, {
3176
- min: MIN_MARGIN,
3177
- max: MAX_MARGIN,
3178
- disabled: disableDistTB,
3179
- precision: 1,
3180
- value: distToText.distT,
3181
- onChange: (val) => {
3182
- handleDistToTextChange(val, "distT");
3183
- }
3184
- })] }), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-text-wrap.left") }), /* @__PURE__ */ jsx(InputNumber, {
3185
- min: MIN_MARGIN,
3186
- max: MAX_MARGIN,
3187
- disabled: disableDistLR,
3188
- precision: 1,
3189
- value: distToText.distL,
3190
- onChange: (val) => {
3191
- handleDistToTextChange(val, "distL");
3192
- }
3193
- })] })]
3194
- }),
3195
- /* @__PURE__ */ jsxs("div", {
3196
- className: "univer-grid univer-grid-cols-2 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
3197
- children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-text-wrap.bottom") }), /* @__PURE__ */ jsx(InputNumber, {
3198
- min: MIN_MARGIN,
3199
- max: MAX_MARGIN,
3200
- disabled: disableDistTB,
3201
- precision: 1,
3202
- value: distToText.distB,
3203
- onChange: (val) => {
3204
- handleDistToTextChange(val, "distB");
3205
- }
3206
- })] }), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", { children: localeService.t("docs-drawing-ui.image-text-wrap.right") }), /* @__PURE__ */ jsx(InputNumber, {
3207
- min: MIN_MARGIN,
3208
- max: MAX_MARGIN,
3209
- disabled: disableDistLR,
3210
- precision: 1,
3211
- value: distToText.distR,
3212
- onChange: (val) => {
3213
- handleDistToTextChange(val, "distR");
3214
- }
3215
- })] })]
3216
- })
3217
- ]
3218
- });
3511
+ }
3219
3512
  };
3513
+ DocDrawingTransformerController = __decorate([
3514
+ __decorateParam(0, ICommandService),
3515
+ __decorateParam(1, IUniverInstanceService),
3516
+ __decorateParam(2, IDrawingManagerService),
3517
+ __decorateParam(3, IRenderManagerService)
3518
+ ], DocDrawingTransformerController);
3220
3519
 
3221
3520
  //#endregion
3222
- //#region src/views/doc-image-panel/DocDrawingPanel.tsx
3223
- const DocDrawingPanel = () => {
3224
- const drawingManagerService = useDependency(IDrawingManagerService);
3225
- const [drawings, setDrawings] = useState(drawingManagerService.getFocusDrawings());
3226
- useEffect(() => {
3227
- const focusDispose = drawingManagerService.focus$.subscribe((drawings) => {
3228
- setDrawings(drawings);
3229
- });
3230
- return () => {
3231
- focusDispose.unsubscribe();
3232
- };
3233
- }, []);
3234
- return !!(drawings === null || drawings === void 0 ? void 0 : drawings.length) && /* @__PURE__ */ jsxs("div", {
3235
- className: "univer-text-sm",
3236
- children: [
3237
- /* @__PURE__ */ jsx(DrawingCommonPanel, {
3238
- drawings,
3239
- hasAlign: false,
3240
- hasCropper: true,
3241
- hasGroup: false,
3242
- hasTransform: false
3243
- }),
3244
- /* @__PURE__ */ jsx(DocDrawingTextWrap, { drawings }),
3245
- /* @__PURE__ */ jsx(DocDrawingPosition, { drawings })
3246
- ]
3247
- });
3521
+ //#region src/menu/schema.ts
3522
+ const menuSchema = {
3523
+ [RibbonInsertGroup.MEDIA]: { [DOCS_IMAGE_MENU_ID]: {
3524
+ order: 0,
3525
+ menuItemFactory: ImageMenuFactory,
3526
+ [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
3527
+ order: 0,
3528
+ menuItemFactory: UploadFloatImageMenuFactory
3529
+ }
3530
+ } },
3531
+ [ContextMenuPosition.PARAGRAPH]: {
3532
+ [ContextMenuGroup.LAYOUT]: { [INSERT_BELLOW_MENU_ID]: { [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
3533
+ order: 5,
3534
+ menuItemFactory: UploadFloatImageMenuFactory
3535
+ } } },
3536
+ [EMPTY_PARAGRAPH_MENU_ID]: { [ContextMenuGroup.LAYOUT]: { [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
3537
+ order: 5,
3538
+ menuItemFactory: UploadFloatImageMenuFactory
3539
+ } } },
3540
+ [DOC_CONTENT_INSERT_MENU_ID]: { [ContextMenuGroup.LAYOUT]: { [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
3541
+ order: 5,
3542
+ menuItemFactory: UploadFloatImageMenuFactory
3543
+ } } },
3544
+ [DOC_PARAGRAPH_T_INSERT_MENU_ID]: { insert: {
3545
+ [IMAGE_MENU_UPLOAD_FLOAT_ID]: {
3546
+ order: 1,
3547
+ menuItemFactory: UploadFloatImageMenuFactory
3548
+ },
3549
+ [DOCS_SHAPE_MENU_ID]: {
3550
+ order: 2,
3551
+ menuItemFactory: ShapeMenuFactory
3552
+ }
3553
+ } },
3554
+ [DOC_PARAGRAPH_T_INSERT_BELOW_MENU_ID]: { insert: {
3555
+ [`${IMAGE_MENU_UPLOAD_FLOAT_ID}.below`]: {
3556
+ order: 1,
3557
+ menuItemFactory: UploadFloatImageBelowMenuFactory
3558
+ },
3559
+ [DOCS_SHAPE_BELOW_MENU_ID]: {
3560
+ order: 2,
3561
+ menuItemFactory: ShapeBelowMenuFactory
3562
+ }
3563
+ } },
3564
+ [DOCS_SHAPE_MENU_ID]: { shapes: {
3565
+ order: 0,
3566
+ [InsertDocRectangleShapeCommand.id]: {
3567
+ order: 0,
3568
+ menuItemFactory: InsertRectangleShapeMenuFactory
3569
+ },
3570
+ [InsertDocEllipseShapeCommand.id]: {
3571
+ order: 1,
3572
+ menuItemFactory: InsertEllipseShapeMenuFactory
3573
+ }
3574
+ } },
3575
+ [DOCS_SHAPE_BELOW_MENU_ID]: { shapes: {
3576
+ order: 0,
3577
+ [`${InsertDocRectangleShapeCommand.id}.below`]: {
3578
+ order: 0,
3579
+ menuItemFactory: InsertRectangleShapeBelowMenuFactory
3580
+ },
3581
+ [`${InsertDocEllipseShapeCommand.id}.below`]: {
3582
+ order: 1,
3583
+ menuItemFactory: InsertEllipseShapeBelowMenuFactory
3584
+ }
3585
+ } }
3586
+ }
3248
3587
  };
3249
3588
 
3250
3589
  //#endregion
@@ -3303,7 +3642,7 @@ const DeleteDrawingsShortcutItem = {
3303
3642
  };
3304
3643
 
3305
3644
  //#endregion
3306
- //#region src/controllers/doc-drawing.controller.ts
3645
+ //#region src/controllers/ui.controller.ts
3307
3646
  /**
3308
3647
  * Copyright 2023-present DreamNum Co., Ltd.
3309
3648
  *
@@ -3320,24 +3659,22 @@ const DeleteDrawingsShortcutItem = {
3320
3659
  * limitations under the License.
3321
3660
  */
3322
3661
  let DocDrawingUIController = class DocDrawingUIController extends Disposable {
3323
- constructor(_componentManager, _menuManagerService, _commandService, _shortcutService) {
3662
+ constructor(_menuManagerService, _commandService, _shortcutService) {
3324
3663
  super();
3325
- this._componentManager = _componentManager;
3326
3664
  this._menuManagerService = _menuManagerService;
3327
3665
  this._commandService = _commandService;
3328
3666
  this._shortcutService = _shortcutService;
3329
3667
  this._init();
3330
3668
  }
3331
- _initCustomComponents() {
3332
- const componentManager = this._componentManager;
3333
- this.disposeWithMe(componentManager.register(COMPONENT_DOC_DRAWING_PANEL, DocDrawingPanel));
3334
- }
3669
+ _initCustomComponents() {}
3335
3670
  _initMenus() {
3336
3671
  this._menuManagerService.mergeMenu(menuSchema);
3337
3672
  }
3338
3673
  _initCommands() {
3339
3674
  [
3340
3675
  InsertDocImageCommand,
3676
+ InsertDocRectangleShapeCommand,
3677
+ InsertDocEllipseShapeCommand,
3341
3678
  InsertDocDrawingCommand,
3342
3679
  UpdateDocDrawingWrappingStyleCommand,
3343
3680
  UpdateDocDrawingDistanceCommand,
@@ -3375,10 +3712,9 @@ let DocDrawingUIController = class DocDrawingUIController extends Disposable {
3375
3712
  }
3376
3713
  };
3377
3714
  DocDrawingUIController = __decorate([
3378
- __decorateParam(0, Inject(ComponentManager)),
3379
- __decorateParam(1, IMenuManagerService),
3380
- __decorateParam(2, ICommandService),
3381
- __decorateParam(3, IShortcutService)
3715
+ __decorateParam(0, IMenuManagerService),
3716
+ __decorateParam(1, ICommandService),
3717
+ __decorateParam(2, IShortcutService)
3382
3718
  ], DocDrawingUIController);
3383
3719
 
3384
3720
  //#endregion
@@ -3570,6 +3906,7 @@ let UniverDocsDrawingUIPlugin = class UniverDocsDrawingUIPlugin extends Plugin {
3570
3906
  }
3571
3907
  onStarting() {
3572
3908
  [
3909
+ [ComponentsController],
3573
3910
  [DocDrawingUIController],
3574
3911
  [DocDrawingPopupMenuController],
3575
3912
  [DocDrawingTransformerController],
@@ -3578,6 +3915,7 @@ let UniverDocsDrawingUIPlugin = class UniverDocsDrawingUIPlugin extends Plugin {
3578
3915
  [DocFloatDomController],
3579
3916
  [DocDrawingPrintingController]
3580
3917
  ].forEach((dependency) => this._injector.add(dependency));
3918
+ this._injector.get(ComponentsController);
3581
3919
  }
3582
3920
  onReady() {
3583
3921
  [[DocDrawingUpdateRenderController], [DocDrawingTransformUpdateController]].forEach((m) => this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_DOC, m));
@@ -3603,4 +3941,4 @@ UniverDocsDrawingUIPlugin = __decorate([
3603
3941
  ], UniverDocsDrawingUIPlugin);
3604
3942
 
3605
3943
  //#endregion
3606
- export { ClearDocDrawingTransformerOperation, DOCS_IMAGE_MENU_ID, DeleteDocDrawingsCommand, DocDrawingPosition, DocDrawingTextWrap, DocFloatDomController, EditDocDrawingOperation, GroupDocDrawingCommand, InsertDocDrawingCommand, InsertDocImageCommand, MoveDocDrawingsCommand, RemoveDocDrawingCommand, SetDocDrawingArrangeCommand, SidebarDocDrawingOperation, UngroupDocDrawingCommand, UniverDocsDrawingUIPlugin };
3944
+ export { ClearDocDrawingTransformerOperation, DOCS_IMAGE_MENU_ID, DOCS_SHAPE_BELOW_MENU_ID, DOCS_SHAPE_MENU_ID, DeleteDocDrawingsCommand, DocDrawingPosition, DocDrawingTextWrap, DocFloatDomController, EditDocDrawingOperation, GroupDocDrawingCommand, InsertDocDrawingCommand, InsertDocEllipseShapeCommand, InsertDocImageCommand, InsertDocRectangleShapeCommand, MoveDocDrawingsCommand, RemoveDocDrawingCommand, SetDocDrawingArrangeCommand, SidebarDocDrawingOperation, UngroupDocDrawingCommand, UniverDocsDrawingUIPlugin };